Skip to content

Commit aa18c78

Browse files
committed
Update Dup test to check that duplicated handles have the same seek offset
1 parent a9c59dc commit aa18c78

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

tests/pass-dep/shims/windows-fs.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
//@compile-flags: -Zmiri-disable-isolation
33
#![allow(nonstandard_style)]
44

5-
use std::io::{ErrorKind, Read, Write};
5+
use std::io::{ErrorKind, Read, Seek, SeekFrom, Write};
66
use std::os::windows::ffi::OsStrExt;
7-
use std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle};
7+
use std::os::windows::io::{AsRawHandle, FromRawHandle};
88
use std::path::Path;
99
use std::{fs, mem, ptr};
1010

@@ -277,7 +277,13 @@ unsafe fn test_file_read_write() {
277277

278278
unsafe fn test_dup_handle() {
279279
let temp = utils::tmp().join("test_dup.txt");
280-
let first_handle = fs::File::create(&temp).unwrap().into_raw_handle();
280+
281+
let mut file1 = fs::File::options().read(true).write(true).create(true).open(&temp).unwrap();
282+
283+
file1.write_all(b"Hello, World!\n").unwrap();
284+
file1.seek(SeekFrom::Start(0)).unwrap();
285+
286+
let first_handle = file1.as_raw_handle();
281287

282288
let cur_proc = GetCurrentProcess();
283289
let mut second_handle = mem::zeroed();
@@ -291,11 +297,15 @@ unsafe fn test_dup_handle() {
291297
DUPLICATE_SAME_ACCESS,
292298
);
293299
assert!(res != 0);
294-
let mut file = fs::File::from_raw_handle(second_handle);
295-
file.write(b"Test").unwrap();
296-
// Duplicated permissions, so reading fails on the second file
297-
let err = file.read(&mut [0]).unwrap_err();
298-
assert_eq!(err.kind(), ErrorKind::PermissionDenied, "I/O Error wrong kind: {:?}", err);
300+
301+
let mut buf1 = [0; 5];
302+
file1.read(&mut buf1).unwrap();
303+
assert_eq!(&buf1, b"Hello");
304+
305+
let mut file2 = fs::File::from_raw_handle(second_handle);
306+
let mut buf2 = [0; 5];
307+
file2.read(&mut buf2).unwrap();
308+
assert_eq!(&buf2, b", Wor");
299309
}
300310

301311
unsafe fn test_file_seek() {

0 commit comments

Comments
 (0)