2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test driver for kernel32 filesystem tests
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
13 #include "kernel32_test.h"
15 static KMT_MESSAGE_HANDLER TestMessageHandler
;
16 static KMT_IRP_HANDLER TestDirectoryControl
;
17 static KMT_IRP_HANDLER TestQueryInformation
;
18 static KMT_IRP_HANDLER TestSetInformation
;
20 static UNICODE_STRING ExpectedExpression
= RTL_CONSTANT_STRING(L
"<not set>");
21 static WCHAR ExpressionBuffer
[MAX_PATH
];
22 static ULONG ExpectedSetAttributes
= -1;
23 static ULONG ReturnQueryAttributes
= -1;
27 IN PDRIVER_OBJECT DriverObject
,
28 IN PCUNICODE_STRING RegistryPath
,
29 OUT PCWSTR
*DeviceName
,
32 NTSTATUS Status
= STATUS_SUCCESS
;
36 UNREFERENCED_PARAMETER(RegistryPath
);
38 *DeviceName
= L
"kernel32";
39 *Flags
= TESTENTRY_NO_EXCLUSIVE_DEVICE
;
41 KmtRegisterIrpHandler(IRP_MJ_DIRECTORY_CONTROL
, NULL
, TestDirectoryControl
);
42 KmtRegisterIrpHandler(IRP_MJ_QUERY_INFORMATION
, NULL
, TestQueryInformation
);
43 KmtRegisterIrpHandler(IRP_MJ_SET_INFORMATION
, NULL
, TestSetInformation
);
44 KmtRegisterMessageHandler(0, NULL
, TestMessageHandler
);
51 IN PDRIVER_OBJECT DriverObject
)
59 IN PDEVICE_OBJECT DeviceObject
,
61 IN PVOID Buffer OPTIONAL
,
63 IN OUT PSIZE_T OutLength
)
65 NTSTATUS Status
= STATUS_SUCCESS
;
71 case IOCTL_EXPECT_EXPRESSION
:
73 C_ASSERT(sizeof(ExpressionBuffer
) <= UNICODE_STRING_MAX_BYTES
);
74 DPRINT("IOCTL_EXPECT_EXPRESSION, InLength = %lu\n", InLength
);
75 if (InLength
> sizeof(ExpressionBuffer
))
76 return STATUS_BUFFER_OVERFLOW
;
78 if (InLength
% sizeof(WCHAR
) != 0)
79 return STATUS_INVALID_PARAMETER
;
81 RtlInitEmptyUnicodeString(&ExpectedExpression
, ExpressionBuffer
, sizeof(ExpressionBuffer
));
82 RtlCopyMemory(ExpressionBuffer
, Buffer
, InLength
);
83 ExpectedExpression
.Length
= (USHORT
)InLength
;
84 DPRINT("IOCTL_EXPECT_EXPRESSION: %wZ\n", &ExpectedExpression
);
88 case IOCTL_RETURN_QUERY_ATTRIBUTES
:
90 DPRINT("IOCTL_RETURN_QUERY_ATTRIBUTES, InLength = %lu\n", InLength
);
91 if (InLength
!= sizeof(ULONG
))
92 return STATUS_INVALID_PARAMETER
;
94 ReturnQueryAttributes
= *(PULONG
)Buffer
;
95 DPRINT("IOCTL_RETURN_QUERY_ATTRIBUTES: %lu\n", ReturnQueryAttributes
);
98 case IOCTL_EXPECT_SET_ATTRIBUTES
:
100 DPRINT("IOCTL_EXPECT_SET_ATTRIBUTES, InLength = %lu\n", InLength
);
101 if (InLength
!= sizeof(ULONG
))
102 return STATUS_INVALID_PARAMETER
;
104 ExpectedSetAttributes
= *(PULONG
)Buffer
;
105 DPRINT("IOCTL_EXPECT_SET_ATTRIBUTES: %lu\n", ExpectedSetAttributes
);
109 return STATUS_NOT_SUPPORTED
;
117 TestDirectoryControl(
118 IN PDEVICE_OBJECT DeviceObject
,
120 IN PIO_STACK_LOCATION IoStackLocation
)
122 NTSTATUS Status
= STATUS_NOT_SUPPORTED
;
126 DPRINT("IRP %x/%x\n", IoStackLocation
->MajorFunction
, IoStackLocation
->MinorFunction
);
127 ASSERT(IoStackLocation
->MajorFunction
== IRP_MJ_DIRECTORY_CONTROL
);
129 ok(IoStackLocation
->MinorFunction
== IRP_MN_QUERY_DIRECTORY
, "Minor function: %u\n", IoStackLocation
->MinorFunction
);
130 if (IoStackLocation
->MinorFunction
== IRP_MN_QUERY_DIRECTORY
)
132 ok(IoStackLocation
->Parameters
.QueryDirectory
.FileInformationClass
== FileBothDirectoryInformation
,
133 "FileInformationClass: %d\n", IoStackLocation
->Parameters
.QueryDirectory
.FileInformationClass
);
134 if (IoStackLocation
->Parameters
.QueryDirectory
.FileInformationClass
== FileBothDirectoryInformation
)
136 ok(RtlEqualUnicodeString(IoStackLocation
->Parameters
.QueryDirectory
.FileName
, &ExpectedExpression
, FALSE
),
137 "Expression is '%wZ', expected '%wZ'\n", IoStackLocation
->Parameters
.QueryDirectory
.FileName
, &ExpectedExpression
);
138 RtlZeroMemory(Irp
->UserBuffer
, IoStackLocation
->Parameters
.QueryDirectory
.Length
);
139 Status
= STATUS_SUCCESS
;
143 Irp
->IoStatus
.Status
= Status
;
144 Irp
->IoStatus
.Information
= 0;
146 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
153 TestQueryInformation(
154 IN PDEVICE_OBJECT DeviceObject
,
156 IN PIO_STACK_LOCATION IoStackLocation
)
158 NTSTATUS Status
= STATUS_NOT_SUPPORTED
;
159 PFILE_BASIC_INFORMATION BasicInfo
;
163 DPRINT("IRP %x/%x\n", IoStackLocation
->MajorFunction
, IoStackLocation
->MinorFunction
);
164 ASSERT(IoStackLocation
->MajorFunction
== IRP_MJ_QUERY_INFORMATION
);
166 Irp
->IoStatus
.Information
= 0;
168 ok_eq_ulong(IoStackLocation
->Parameters
.QueryFile
.FileInformationClass
, FileBasicInformation
);
169 if (IoStackLocation
->Parameters
.QueryFile
.FileInformationClass
== FileBasicInformation
)
171 ok(ReturnQueryAttributes
!= (ULONG
)-1, "Unexpected QUERY_INFORMATION call\n");
172 BasicInfo
= Irp
->AssociatedIrp
.SystemBuffer
;
173 BasicInfo
->CreationTime
.QuadPart
= 126011664000000000;
174 BasicInfo
->LastAccessTime
.QuadPart
= 130899112800000000;
175 BasicInfo
->LastWriteTime
.QuadPart
= 130899112800000000;
176 BasicInfo
->ChangeTime
.QuadPart
= 130899112800000000;
177 BasicInfo
->FileAttributes
= ReturnQueryAttributes
;
178 ReturnQueryAttributes
= -1;
179 Status
= STATUS_SUCCESS
;
180 Irp
->IoStatus
.Information
= sizeof(*BasicInfo
);
183 Irp
->IoStatus
.Status
= Status
;
185 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
193 IN PDEVICE_OBJECT DeviceObject
,
195 IN PIO_STACK_LOCATION IoStackLocation
)
197 NTSTATUS Status
= STATUS_NOT_SUPPORTED
;
198 PFILE_BASIC_INFORMATION BasicInfo
;
202 DPRINT("IRP %x/%x\n", IoStackLocation
->MajorFunction
, IoStackLocation
->MinorFunction
);
203 ASSERT(IoStackLocation
->MajorFunction
== IRP_MJ_SET_INFORMATION
);
205 ok_eq_ulong(IoStackLocation
->Parameters
.SetFile
.FileInformationClass
, FileBasicInformation
);
206 if (IoStackLocation
->Parameters
.SetFile
.FileInformationClass
== FileBasicInformation
)
208 ok(ExpectedSetAttributes
!= (ULONG
)-1, "Unexpected SET_INFORMATION call\n");
209 BasicInfo
= Irp
->AssociatedIrp
.SystemBuffer
;
210 ok_eq_longlong(BasicInfo
->CreationTime
.QuadPart
, 0LL);
211 ok_eq_longlong(BasicInfo
->LastAccessTime
.QuadPart
, 0LL);
212 ok_eq_longlong(BasicInfo
->LastWriteTime
.QuadPart
, 0LL);
213 ok_eq_longlong(BasicInfo
->ChangeTime
.QuadPart
, 0LL);
214 ok_eq_ulong(BasicInfo
->FileAttributes
, ExpectedSetAttributes
);
215 ExpectedSetAttributes
= -1;
216 Status
= STATUS_SUCCESS
;
219 Irp
->IoStatus
.Status
= Status
;
220 Irp
->IoStatus
.Information
= 0;
222 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);