b149a1f2f311a28af2e617dacad8cbe99535b901
[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
21 KmtLoadDriver(L"CcCopyRead", FALSE);
22 KmtOpenDriver();
23
24 InitializeObjectAttributes(&ObjectAttributes, &SmallAlignmentTest, OBJ_CASE_INSENSITIVE, NULL, NULL);
25 Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT);
26 ok_eq_hex(Status, STATUS_SUCCESS);
27
28 ByteOffset.QuadPart = 3;
29 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 3, &ByteOffset, NULL);
30 ok_eq_hex(Status, STATUS_SUCCESS);
31 ok_eq_hex(((USHORT *)Buffer)[0], 0xBABA);
32
33 ByteOffset.QuadPart = 514;
34 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 514, &ByteOffset, NULL);
35 ok_eq_hex(Status, STATUS_SUCCESS);
36 ok_eq_hex(((USHORT *)Buffer)[242], 0xBABA);
37 ok_eq_hex(((USHORT *)Buffer)[243], 0xFFFF);
38
39 ByteOffset.QuadPart = 1000;
40 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 2, &ByteOffset, NULL);
41 ok_eq_hex(Status, STATUS_SUCCESS);
42 ok_eq_hex(((USHORT *)Buffer)[0], 0xFFFF);
43 ok_eq_hex(((USHORT *)Buffer)[1], 0xBABA);
44
45 NtClose(Handle);
46
47 InitializeObjectAttributes(&ObjectAttributes, &BigAlignmentTest, OBJ_CASE_INSENSITIVE, NULL, NULL);
48 Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT);
49 ok_eq_hex(Status, STATUS_SUCCESS);
50
51 ByteOffset.QuadPart = 3;
52 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 3, &ByteOffset, NULL);
53 ok_eq_hex(Status, STATUS_SUCCESS);
54 ok_eq_hex(((USHORT *)Buffer)[0], 0xBABA);
55
56 ByteOffset.QuadPart = 514;
57 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 514, &ByteOffset, NULL);
58 ok_eq_hex(Status, STATUS_SUCCESS);
59 ok_eq_hex(((USHORT *)Buffer)[242], 0xBABA);
60 ok_eq_hex(((USHORT *)Buffer)[243], 0xFFFF);
61
62 ByteOffset.QuadPart = 300000;
63 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 10, &ByteOffset, NULL);
64 ok_eq_hex(Status, STATUS_SUCCESS);
65 ok_eq_hex(((USHORT *)Buffer)[0], 0xBABA);
66
67 ByteOffset.QuadPart = 1000;
68 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 2, &ByteOffset, NULL);
69 ok_eq_hex(Status, STATUS_SUCCESS);
70 ok_eq_hex(((USHORT *)Buffer)[0], 0xFFFF);
71 ok_eq_hex(((USHORT *)Buffer)[1], 0xBABA);
72
73 NtClose(Handle);
74
75 RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
76 KmtCloseDriver();
77 KmtUnloadDriver();
78 }