Signed-off-by: Paul Gofman <gofmanp(a)gmail.com>
---
dlls/kernel32/tests/file.c | 65 ++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c
index b47b2b9c41..c9c2dd24e7 100644
--- a/dlls/kernel32/tests/file.c
+++ b/dlls/kernel32/tests/file.c
@@ -5140,6 +5140,70 @@ static void test_post_completion(void)
CloseHandle( port );
}
+#define TEST_OVERLAPPED_READ_SIZE 4096
+
+static void test_overlapped_read(void)
+{
+ DECLSPEC_ALIGN(TEST_OVERLAPPED_READ_SIZE) static unsigned char buffer[TEST_OVERLAPPED_READ_SIZE];
+ static const char prefix[] = "pfx";
+ char temp_path[MAX_PATH];
+ char file_name[MAX_PATH];
+ DWORD bytes_count;
+ OVERLAPPED ov;
+ HANDLE hfile;
+ DWORD err;
+ DWORD ret;
+
+ ret = GetTempPathA(MAX_PATH, temp_path);
+ ok(ret, "Unexpect error %u.\n", GetLastError());
+ ret = GetTempFileNameA(temp_path, prefix, 0, file_name);
+ ok(ret, "Unexpected error %u.\n", GetLastError());
+
+ hfile = CreateFileA(file_name, GENERIC_WRITE, 0,
+ NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING, NULL);
+ ok(hfile != INVALID_HANDLE_VALUE, "Failed to create file, GetLastError() %u.\n", GetLastError());
+ memset(buffer, 0x55, sizeof(buffer));
+ ret = WriteFile(hfile, buffer, TEST_OVERLAPPED_READ_SIZE, &bytes_count, NULL);
+ ok(ret && bytes_count == TEST_OVERLAPPED_READ_SIZE,
+ "Unexpected WriteFile result, ret %#x, bytes_count %u, GetLastError() %u.\n",
+ ret, bytes_count, GetLastError());
+ CloseHandle(hfile);
+
+ hfile = CreateFileA(file_name, GENERIC_READ, FILE_SHARE_READ,
+ NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING, NULL);
+ ok(hfile != INVALID_HANDLE_VALUE, "Failed to create file, GetLastError() %u.\n", GetLastError());
+
+ memset(&ov, 0, sizeof(ov));
+
+ bytes_count = 0xffffffff;
+ ret = ReadFile(hfile, buffer, TEST_OVERLAPPED_READ_SIZE, &bytes_count, &ov);
+ todo_wine ok(!ret && GetLastError() == ERROR_IO_PENDING,
+ "Unexpected ReadFile result, ret %#x, GetLastError() %u.\n", ret, GetLastError());
+ todo_wine ok(!bytes_count, "Unexpected read size %u.\n", bytes_count);
+ ret = GetOverlappedResult(hfile, &ov, &bytes_count, TRUE);
+ ok(ret, "Unexpected error %u.\n", GetLastError());
+ ok(bytes_count == TEST_OVERLAPPED_READ_SIZE, "Unexpected read size %u.\n", bytes_count);
+
+ S(U(ov)).Offset = bytes_count;
+ ret = ReadFile(hfile, buffer, TEST_OVERLAPPED_READ_SIZE, &bytes_count, &ov);
+ err = GetLastError();
+ /* Win8+ return ERROR_IO_PENDING like stated in MSDN, while older ones
+ * return ERROR_HANDLE_EOF right away. */
+ ok(!ret && (err == ERROR_HANDLE_EOF || err == ERROR_IO_PENDING),
+ "Unexpected ReadFile result, ret %#x, GetLastError() %u.\n", ret, GetLastError());
+ if (err == ERROR_IO_PENDING)
+ {
+ ret = GetOverlappedResult(hfile, &ov, &bytes_count, TRUE);
+ ok(!ret && GetLastError() == ERROR_HANDLE_EOF, "Unexpected result %#x, GetLasttError() %u.\n",
+ ret, GetLastError());
+ }
+ ok(!bytes_count, "Unexpected read size %u.\n", bytes_count);
+
+ CloseHandle(hfile);
+ ret = DeleteFileA(file_name);
+ ok(ret, "Unexpected error %u.\n", GetLastError());
+}
+
START_TEST(file)
{
char temp_path[MAX_PATH];
@@ -5209,4 +5273,5 @@ START_TEST(file)
test_SetFileInformationByHandle();
test_GetFileAttributesExW();
test_post_completion();
+ test_overlapped_read();
}
--
2.20.1