[COMMENTS]
[reactos.git] / rostests / kmtests / kernel32 / FindFile_drv.c
1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test driver for FindFirstFile's wildcard substitution
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8 #include <kmt_test.h>
9
10 #define NDEBUG
11 #include <debug.h>
12
13 #include "FindFile.h"
14
15 static KMT_MESSAGE_HANDLER TestMessageHandler;
16 static KMT_IRP_HANDLER TestIrpHandler;
17
18 static UNICODE_STRING ExpectedExpression = RTL_CONSTANT_STRING(L"<not set>");
19 static WCHAR ExpressionBuffer[MAX_PATH];
20
21 NTSTATUS
22 TestEntry(
23 IN PDRIVER_OBJECT DriverObject,
24 IN PCUNICODE_STRING RegistryPath,
25 OUT PCWSTR *DeviceName,
26 IN OUT INT *Flags)
27 {
28 NTSTATUS Status = STATUS_SUCCESS;
29
30 PAGED_CODE();
31
32 UNREFERENCED_PARAMETER(RegistryPath);
33
34 *DeviceName = L"FindFile";
35 *Flags = TESTENTRY_NO_EXCLUSIVE_DEVICE;
36
37 KmtRegisterIrpHandler(IRP_MJ_DIRECTORY_CONTROL, NULL, TestIrpHandler);
38 KmtRegisterMessageHandler(0, NULL, TestMessageHandler);
39
40 return Status;
41 }
42
43 VOID
44 TestUnload(
45 IN PDRIVER_OBJECT DriverObject)
46 {
47 PAGED_CODE();
48 }
49
50 static
51 NTSTATUS
52 TestMessageHandler(
53 IN PDEVICE_OBJECT DeviceObject,
54 IN ULONG ControlCode,
55 IN PVOID Buffer OPTIONAL,
56 IN SIZE_T InLength,
57 IN OUT PSIZE_T OutLength)
58 {
59 NTSTATUS Status = STATUS_SUCCESS;
60
61 PAGED_CODE();
62
63 switch (ControlCode)
64 {
65 case IOCTL_EXPECT:
66 {
67 C_ASSERT(sizeof(ExpressionBuffer) <= UNICODE_STRING_MAX_BYTES);
68 DPRINT("IOCTL_EXPECT, InLength = %lu\n", InLength);
69 if (InLength > sizeof(ExpressionBuffer))
70 return STATUS_BUFFER_OVERFLOW;
71
72 if (InLength % sizeof(WCHAR) != 0)
73 return STATUS_INVALID_PARAMETER;
74
75 RtlInitEmptyUnicodeString(&ExpectedExpression, ExpressionBuffer, sizeof(ExpressionBuffer));
76 RtlCopyMemory(ExpressionBuffer, Buffer, InLength);
77 ExpectedExpression.Length = (USHORT)InLength;
78 DPRINT("IOCTL_EXPECT: %wZ\n", &ExpectedExpression);
79
80 break;
81 }
82 default:
83 return STATUS_NOT_SUPPORTED;
84 }
85
86 return Status;
87 }
88
89 static
90 NTSTATUS
91 TestIrpHandler(
92 IN PDEVICE_OBJECT DeviceObject,
93 IN PIRP Irp,
94 IN PIO_STACK_LOCATION IoStackLocation)
95 {
96 NTSTATUS Status = STATUS_NOT_SUPPORTED;
97
98 PAGED_CODE();
99
100 DPRINT("IRP %x/%x\n", IoStackLocation->MajorFunction, IoStackLocation->MinorFunction);
101 ASSERT(IoStackLocation->MajorFunction == IRP_MJ_DIRECTORY_CONTROL);
102
103 ok(IoStackLocation->MinorFunction == IRP_MN_QUERY_DIRECTORY, "Minor function: %u\n", IoStackLocation->MinorFunction);
104 if (IoStackLocation->MinorFunction == IRP_MN_QUERY_DIRECTORY)
105 {
106 ok(IoStackLocation->Parameters.QueryDirectory.FileInformationClass == FileBothDirectoryInformation,
107 "FileInformationClass: %d\n", IoStackLocation->Parameters.QueryDirectory.FileInformationClass);
108 if (IoStackLocation->Parameters.QueryDirectory.FileInformationClass == FileBothDirectoryInformation)
109 {
110 ok(RtlEqualUnicodeString(IoStackLocation->Parameters.QueryDirectory.FileName, &ExpectedExpression, FALSE),
111 "Expression is '%wZ', expected '%wZ'\n", IoStackLocation->Parameters.QueryDirectory.FileName, &ExpectedExpression);
112 RtlZeroMemory(Irp->UserBuffer, IoStackLocation->Parameters.QueryDirectory.Length);
113 Status = STATUS_SUCCESS;
114 }
115 }
116
117 Irp->IoStatus.Status = Status;
118 Irp->IoStatus.Information = 0;
119
120 IoCompleteRequest(Irp, IO_NO_INCREMENT);
121
122 return Status;
123 }