[KMTESTS:NPFS] Fix 2 Clang-Cl warnings about ShareAccess
[reactos.git] / modules / rostests / kmtests / npfs / NpfsFileInfo.c
1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite NPFS file information test
5 * PROGRAMMER: Pierre Schweitzer <pierre@reactos.org>
6 */
7
8 #include <kmt_test.h>
9 #include "npfs.h"
10
11 #define MAX_INSTANCES 1
12 #define IN_QUOTA 4096
13 #define OUT_QUOTA 4096
14 #define PIPE_NAME L"\\KmtestNpfsFileInfoTestPipe"
15
16 static
17 VOID
18 TestFileInfo(
19 IN HANDLE ServerHandle)
20 {
21 NTSTATUS Status;
22 IO_STATUS_BLOCK IoStatusBlock;
23
24 struct {
25 FILE_ALL_INFORMATION;
26 WCHAR PartialName[50];
27 } FileAllInfo;
28
29 RtlFillMemory(&FileAllInfo, sizeof(FileAllInfo), 0xFF);
30 Status = ZwQueryInformationFile(ServerHandle,
31 &IoStatusBlock,
32 &FileAllInfo,
33 sizeof(FileAllInfo),
34 FileAllInformation);
35 ok_eq_hex(Status, STATUS_SUCCESS);
36 ok_eq_hex(IoStatusBlock.Status, STATUS_SUCCESS);
37 ok_eq_longlong(FileAllInfo.BasicInformation.CreationTime.QuadPart, 0);
38 ok_eq_longlong(FileAllInfo.BasicInformation.LastAccessTime.QuadPart, 0);
39 ok_eq_longlong(FileAllInfo.BasicInformation.LastWriteTime.QuadPart, 0);
40 ok_eq_longlong(FileAllInfo.BasicInformation.ChangeTime.QuadPart, 0);
41 ok_eq_ulong(FileAllInfo.BasicInformation.FileAttributes, FILE_ATTRIBUTE_NORMAL);
42 ok_eq_longlong(FileAllInfo.StandardInformation.AllocationSize.QuadPart, 8192);
43 ok_eq_longlong(FileAllInfo.StandardInformation.EndOfFile.QuadPart, 0);
44 ok_eq_ulong(FileAllInfo.StandardInformation.NumberOfLinks, 1);
45 ok_bool_true(FileAllInfo.StandardInformation.DeletePending, "DeletePending");
46 ok_bool_false(FileAllInfo.StandardInformation.Directory, "Directory");
47 ok(FileAllInfo.InternalInformation.IndexNumber.QuadPart != 0xFFFFFFFFFFFFFFFF, "FileAllInfo.InternalInformation.IndexNumber = 0xFFFFFFFFFFFFFFFF, whereas it shouldn't\n");
48 ok(FileAllInfo.InternalInformation.IndexNumber.QuadPart != 0, "FileAllInfo.InternalInformation.IndexNumber = 0, whereas it shouldn't\n");
49 ok_eq_ulong(FileAllInfo.EaInformation.EaSize, 0);
50 ok_eq_ulong(FileAllInfo.AccessInformation.AccessFlags, (FILE_GENERIC_READ | FILE_GENERIC_WRITE));
51 ok_eq_longlong(FileAllInfo.PositionInformation.CurrentByteOffset.QuadPart, 0);
52 ok_eq_ulong(FileAllInfo.ModeInformation.Mode, FILE_SYNCHRONOUS_IO_NONALERT);
53 ok_eq_ulong(FileAllInfo.AlignmentInformation.AlignmentRequirement, 0);
54 ok_eq_ulong(FileAllInfo.NameInformation.FileNameLength, sizeof(PIPE_NAME) - sizeof(WCHAR));
55 ok_eq_size(RtlCompareMemory(FileAllInfo.NameInformation.FileName, PIPE_NAME, sizeof(PIPE_NAME) - sizeof(WCHAR)), (sizeof(PIPE_NAME) - sizeof(WCHAR)));
56 ok_eq_wchar(FileAllInfo.NameInformation.FileName[sizeof(PIPE_NAME) / sizeof(WCHAR) - 1], 0xFFFF);
57 ok_eq_ulong(IoStatusBlock.Information, (FIELD_OFFSET(FILE_ALL_INFORMATION, NameInformation.FileName) + sizeof(PIPE_NAME) - sizeof(WCHAR)));
58
59 RtlFillMemory(&FileAllInfo, sizeof(FileAllInfo), 0xFF);
60 Status = ZwQueryInformationFile(ServerHandle,
61 &IoStatusBlock,
62 &FileAllInfo,
63 sizeof(FILE_ALL_INFORMATION) + 4 * sizeof(WCHAR),
64 FileAllInformation);
65 ok_eq_hex(Status, STATUS_BUFFER_OVERFLOW);
66 ok_eq_hex(IoStatusBlock.Status, STATUS_BUFFER_OVERFLOW);
67 ok_eq_longlong(FileAllInfo.BasicInformation.CreationTime.QuadPart, 0);
68 ok_eq_longlong(FileAllInfo.BasicInformation.LastAccessTime.QuadPart, 0);
69 ok_eq_longlong(FileAllInfo.BasicInformation.LastWriteTime.QuadPart, 0);
70 ok_eq_longlong(FileAllInfo.BasicInformation.ChangeTime.QuadPart, 0);
71 ok_eq_ulong(FileAllInfo.BasicInformation.FileAttributes, FILE_ATTRIBUTE_NORMAL);
72 ok_eq_longlong(FileAllInfo.StandardInformation.AllocationSize.QuadPart, 8192);
73 ok_eq_longlong(FileAllInfo.StandardInformation.EndOfFile.QuadPart, 0);
74 ok_eq_ulong(FileAllInfo.StandardInformation.NumberOfLinks, 1);
75 ok_bool_true(FileAllInfo.StandardInformation.DeletePending, "DeletePending");
76 ok_bool_false(FileAllInfo.StandardInformation.Directory, "Directory");
77 ok(FileAllInfo.InternalInformation.IndexNumber.QuadPart != 0xFFFFFFFFFFFFFFFF, "FileAllInfo.InternalInformation.IndexNumber = 0xFFFFFFFFFFFFFFFF, whereas it shouldn't\n");
78 ok(FileAllInfo.InternalInformation.IndexNumber.QuadPart != 0, "FileAllInfo.InternalInformation.IndexNumber = 0, whereas it shouldn't\n");
79 ok_eq_ulong(FileAllInfo.EaInformation.EaSize, 0);
80 ok_eq_ulong(FileAllInfo.AccessInformation.AccessFlags, (FILE_GENERIC_READ | FILE_GENERIC_WRITE));
81 ok_eq_longlong(FileAllInfo.PositionInformation.CurrentByteOffset.QuadPart, 0);
82 ok_eq_ulong(FileAllInfo.ModeInformation.Mode, FILE_SYNCHRONOUS_IO_NONALERT);
83 ok_eq_ulong(FileAllInfo.AlignmentInformation.AlignmentRequirement, 0);
84 ok_eq_ulong(FileAllInfo.NameInformation.FileNameLength, sizeof(PIPE_NAME) - sizeof(WCHAR));
85 ok_eq_size(RtlCompareMemory(FileAllInfo.NameInformation.FileName, PIPE_NAME, 6 * sizeof(WCHAR)), (6 * sizeof(WCHAR)));
86 ok_eq_wchar(FileAllInfo.NameInformation.FileName[6], 0xFFFF);
87 ok_eq_ulong(IoStatusBlock.Information, (FIELD_OFFSET(FILE_ALL_INFORMATION, NameInformation.FileName) + 6 * sizeof(WCHAR)));
88
89 RtlFillMemory(&FileAllInfo, sizeof(FileAllInfo), 0xFF);
90 Status = ZwQueryInformationFile(ServerHandle,
91 &IoStatusBlock,
92 &FileAllInfo,
93 sizeof(FILE_ALL_INFORMATION) - 4,
94 FileAllInformation);
95 ok_eq_hex(Status, STATUS_BUFFER_OVERFLOW);
96 ok_eq_hex(IoStatusBlock.Status, STATUS_BUFFER_OVERFLOW);
97 ok_eq_longlong(FileAllInfo.BasicInformation.CreationTime.QuadPart, 0);
98 ok_eq_longlong(FileAllInfo.BasicInformation.LastAccessTime.QuadPart, 0);
99 ok_eq_longlong(FileAllInfo.BasicInformation.LastWriteTime.QuadPart, 0);
100 ok_eq_longlong(FileAllInfo.BasicInformation.ChangeTime.QuadPart, 0);
101 ok_eq_ulong(FileAllInfo.BasicInformation.FileAttributes, FILE_ATTRIBUTE_NORMAL);
102 ok_eq_longlong(FileAllInfo.StandardInformation.AllocationSize.QuadPart, 8192);
103 ok_eq_longlong(FileAllInfo.StandardInformation.EndOfFile.QuadPart, 0);
104 ok_eq_ulong(FileAllInfo.StandardInformation.NumberOfLinks, 1);
105 ok_bool_true(FileAllInfo.StandardInformation.DeletePending, "DeletePending");
106 ok_bool_false(FileAllInfo.StandardInformation.Directory, "Directory");
107 ok(FileAllInfo.InternalInformation.IndexNumber.QuadPart != 0xFFFFFFFFFFFFFFFF, "FileAllInfo.InternalInformation.IndexNumber = 0xFFFFFFFFFFFFFFFF, whereas it shouldn't\n");
108 ok(FileAllInfo.InternalInformation.IndexNumber.QuadPart != 0, "FileAllInfo.InternalInformation.IndexNumber = 0, whereas it shouldn't\n");
109 ok_eq_ulong(FileAllInfo.EaInformation.EaSize, 0);
110 ok_eq_ulong(FileAllInfo.AccessInformation.AccessFlags, (FILE_GENERIC_READ | FILE_GENERIC_WRITE));
111 ok_eq_longlong(FileAllInfo.PositionInformation.CurrentByteOffset.QuadPart, 0);
112 ok_eq_ulong(FileAllInfo.ModeInformation.Mode, FILE_SYNCHRONOUS_IO_NONALERT);
113 ok_eq_ulong(FileAllInfo.AlignmentInformation.AlignmentRequirement, 0);
114 ok_eq_ulong(FileAllInfo.NameInformation.FileNameLength, sizeof(PIPE_NAME) - sizeof(WCHAR));
115 ok_eq_wchar(FileAllInfo.NameInformation.FileName[0], 0xFFFF);
116 ok_eq_ulong(IoStatusBlock.Information, (sizeof(FILE_ALL_INFORMATION) - 4));
117 }
118
119 static KSTART_ROUTINE RunTest;
120 static
121 VOID
122 NTAPI
123 RunTest(
124 IN PVOID Context)
125 {
126 NTSTATUS Status;
127 HANDLE ServerHandle;
128
129 UNREFERENCED_PARAMETER(Context);
130
131 ServerHandle = INVALID_HANDLE_VALUE;
132 Status = NpCreatePipe(&ServerHandle,
133 DEVICE_NAMED_PIPE PIPE_NAME,
134 BYTE_STREAM, QUEUE, BYTE_STREAM, DUPLEX,
135 MAX_INSTANCES,
136 IN_QUOTA,
137 OUT_QUOTA);
138 ok_eq_hex(Status, STATUS_SUCCESS);
139 ok(ServerHandle != NULL && ServerHandle != INVALID_HANDLE_VALUE, "ServerHandle = %p\n", ServerHandle);
140 if (!skip(NT_SUCCESS(Status) && ServerHandle != NULL && ServerHandle != INVALID_HANDLE_VALUE, "No pipe\n"))
141 {
142 TestFileInfo(ServerHandle);
143 ObCloseHandle(ServerHandle, KernelMode);
144 }
145 }
146
147 START_TEST(NpfsFileInfo)
148 {
149 PKTHREAD Thread;
150
151 Thread = KmtStartThread(RunTest, NULL);
152 KmtFinishThread(Thread, NULL);
153 }