[KMTESTS:CC]
[reactos.git] / rostests / kmtests / kernel32 / FindFile_user.c
1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for FindFirstFile's wildcard substitution
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8 #include <kmt_test.h>
9
10 #include "FindFile.h"
11
12 START_TEST(FindFile)
13 {
14 HANDLE FindHandle;
15 WIN32_FIND_DATAW FindData;
16 struct
17 {
18 PCWSTR Expression;
19 PCWSTR ExpectedExpression;
20 } Tests[] =
21 {
22 { L"Hello", L"Hello" },
23
24 { L"*", L"*" },
25 { L"a*", L"a*" },
26 { L"*a", L"*a" },
27 { L"a*a", L"a*a" },
28 { L"**", L"**" },
29 { L"*a*", L"*a*" },
30 { L"a*a*a", L"a*a*a" },
31
32 { L"*.*", L"*" },
33 { L"a*.*", L"a<\"*" },
34 { L"*.*a", L"<\"*a" },
35 { L"a*.*a", L"a<\"*a" },
36 { L"*.**.*", L"<\"*<\"*" },
37 { L"*.*a*.*", L"<\"*a<\"*" },
38 { L"a*.*a*.*a", L"a<\"*a<\"*a" },
39
40 { L".*", L"\"*" },
41 { L"a.*", L"a\"*" },
42 { L".*a", L"\"*a" },
43 { L"a.*a", L"a\"*a" },
44 { L".*.*", L"\"<\"*" },
45 { L".*a.*", L"\"*a\"*" },
46 { L"a.*a.*a", L"a\"*a\"*a" },
47
48 { L"*.", L"<" },
49 { L"a*.", L"a<" },
50 { L"*.a", L"<.a" },
51 { L"a*.a", L"a<.a" },
52 { L"*.*.", L"*" },
53 { L"*.a*.", L"<.a<" },
54 { L"a*.a*.a", L"a<.a<.a" },
55
56 { L"?", L">" },
57 { L"a?", L"a>" },
58 { L"?a", L">a" },
59 { L"a?a", L"a>a" },
60 { L"??", L">>" },
61 { L"?a?", L">a>" },
62 { L"a?a?a", L"a>a>a" },
63
64 { L"?.?", L">\">" },
65 { L"a?.?", L"a>\">" },
66 { L"?.?a", L">\">a" },
67 { L"a?.?a", L"a>\">a" },
68 { L"?.??.?", L">\">>\">" },
69 { L"?.?a?.?", L">\">a>\">" },
70 { L"a?.?a?.?a", L"a>\">a>\">a" },
71
72 { L".?", L"\">" },
73 { L"a.?", L"a\">" },
74 { L".?a", L"\">a" },
75 { L"a.?a", L"a\">a" },
76 { L".?.?", L"\">\">" },
77 { L".?a.?", L"\">a\">" },
78 { L"a.?a.?a", L"a\">a\">a" },
79
80 { L"?.", L">" },
81 { L"a?.", L"a>" },
82 { L"?.a", L">.a" },
83 { L"a?.a", L"a>.a" },
84 { L"?.?.", L">\">" },
85 { L"?.a?.", L">.a>" },
86 { L"a?.a?.a", L"a>.a>.a" },
87
88 { L"f*.", L"f<" },
89 { L"f.*", L"f\"*" },
90 { L"f*.*", L"f<\"*" },
91 { L"f*.f*", L"f<.f*" },
92 { L"f*f.*", L"f*f\"*" },
93 { L"f*.*f", L"f<\"*f" },
94
95 /* TODO: add more. Have fun */
96 };
97 const INT TestCount = sizeof(Tests) / sizeof(Tests[0]);
98 INT i;
99 WCHAR ExpressionBuffer[MAX_PATH];
100
101 KmtLoadDriver(L"FindFile", FALSE);
102 KmtOpenDriver();
103
104 for (i = 0; i < TestCount; i++)
105 {
106 trace("[%d] '%ls', '%ls'\n", i, Tests[i].Expression, Tests[i].ExpectedExpression);
107 KmtSendWStringToDriver(IOCTL_EXPECT, Tests[i].ExpectedExpression);
108 wcscpy(ExpressionBuffer, L"\\\\.\\Global\\GLOBALROOT\\Device\\Kmtest-FindFile\\");
109 wcscat(ExpressionBuffer, Tests[i].Expression);
110 FindHandle = FindFirstFileW(ExpressionBuffer, &FindData);
111 ok(FindHandle != NULL && FindHandle != INVALID_HANDLE_VALUE, "Handle: %p, error=%lu\n", (PVOID)FindHandle, GetLastError());
112 if (FindHandle != INVALID_HANDLE_VALUE)
113 FindClose(FindHandle);
114 }
115
116 KmtCloseDriver();
117 KmtUnloadDriver();
118 }