[USP10_WINETEST] Sync with Wine Staging 2.9. CORE-13362
[reactos.git] / rostests / kmtests / ntos_cc / CcCopyRead_user.c
1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite CcCopyRead test user-mode part
5 * PROGRAMMER: Pierre Schweitzer <pierre@reactos.org>
6 */
7
8 #include <kmt_test.h>
9
10 START_TEST(CcCopyRead)
11 {
12 HANDLE Handle;
13 NTSTATUS Status;
14 LARGE_INTEGER ByteOffset;
15 IO_STATUS_BLOCK IoStatusBlock;
16 OBJECT_ATTRIBUTES ObjectAttributes;
17 PVOID Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, 1024);
18 UNICODE_STRING BigAlignmentTest = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\BigAlignmentTest");
19 UNICODE_STRING SmallAlignmentTest = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\SmallAlignmentTest");
20 UNICODE_STRING ReallySmallAlignmentTest = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\ReallySmallAlignmentTest");
21
22 KmtLoadDriver(L"CcCopyRead", FALSE);
23 KmtOpenDriver();
24
25 InitializeObjectAttributes(&ObjectAttributes, &SmallAlignmentTest, OBJ_CASE_INSENSITIVE, NULL, NULL);
26 Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT);
27 ok_eq_hex(Status, STATUS_SUCCESS);
28
29 ByteOffset.QuadPart = 3;
30 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 3, &ByteOffset, NULL);
31 ok_eq_hex(Status, STATUS_SUCCESS);
32 ok_eq_hex(((USHORT *)Buffer)[0], 0xBABA);
33
34 ByteOffset.QuadPart = 514;
35 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 514, &ByteOffset, NULL);
36 ok_eq_hex(Status, STATUS_SUCCESS);
37 ok_eq_hex(((USHORT *)Buffer)[242], 0xBABA);
38 ok_eq_hex(((USHORT *)Buffer)[243], 0xFFFF);
39
40 ByteOffset.QuadPart = 1000;
41 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 2, &ByteOffset, NULL);
42 ok_eq_hex(Status, STATUS_SUCCESS);
43 ok_eq_hex(((USHORT *)Buffer)[0], 0xFFFF);
44 ok_eq_hex(((USHORT *)Buffer)[1], 0xBABA);
45
46 NtClose(Handle);
47
48 InitializeObjectAttributes(&ObjectAttributes, &BigAlignmentTest, OBJ_CASE_INSENSITIVE, NULL, NULL);
49 Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT);
50 ok_eq_hex(Status, STATUS_SUCCESS);
51
52 ByteOffset.QuadPart = 3;
53 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 3, &ByteOffset, NULL);
54 ok_eq_hex(Status, STATUS_SUCCESS);
55 ok_eq_hex(((USHORT *)Buffer)[0], 0xBABA);
56
57 ByteOffset.QuadPart = 514;
58 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 514, &ByteOffset, NULL);
59 ok_eq_hex(Status, STATUS_SUCCESS);
60 ok_eq_hex(((USHORT *)Buffer)[242], 0xBABA);
61 ok_eq_hex(((USHORT *)Buffer)[243], 0xFFFF);
62
63 ByteOffset.QuadPart = 300000;
64 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 10, &ByteOffset, NULL);
65 ok_eq_hex(Status, STATUS_SUCCESS);
66 ok_eq_hex(((USHORT *)Buffer)[0], 0xBABA);
67
68 ByteOffset.QuadPart = 999990;
69 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 10, &ByteOffset, NULL);
70 ok_eq_hex(Status, STATUS_SUCCESS);
71 ok_eq_hex(((USHORT *)Buffer)[0], 0xBABA);
72
73 ByteOffset.QuadPart = 1000;
74 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 2, &ByteOffset, NULL);
75 ok_eq_hex(Status, STATUS_SUCCESS);
76 ok_eq_hex(((USHORT *)Buffer)[0], 0xFFFF);
77 ok_eq_hex(((USHORT *)Buffer)[1], 0xBABA);
78
79 NtClose(Handle);
80
81 InitializeObjectAttributes(&ObjectAttributes, &ReallySmallAlignmentTest, OBJ_CASE_INSENSITIVE, NULL, NULL);
82 Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT);
83 ok_eq_hex(Status, STATUS_SUCCESS);
84
85 ByteOffset.QuadPart = 1;
86 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 61, &ByteOffset, NULL);
87 ok_eq_hex(Status, STATUS_SUCCESS);
88 ok_eq_hex(((USHORT *)Buffer)[0], 0xBABA);
89
90 NtClose(Handle);
91
92 RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
93 KmtCloseDriver();
94 KmtUnloadDriver();
95 }