[KMTESTS]
[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 <thfabba@gmx.de>
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"f*.", L"f<" },
65 { L"f.*", L"f\"*" },
66 { L"f*.*", L"f<\"*" },
67 { L"f*.f*", L"f<.f*" },
68 { L"f*f.*", L"f*f\"*" },
69 { L"f*.*f", L"f<\"*f" },
70
71 /* TODO: add more. Have fun */
72 };
73 const INT TestCount = sizeof(Tests) / sizeof(Tests[0]);
74 INT i;
75 WCHAR ExpressionBuffer[MAX_PATH];
76
77 KmtLoadDriver(L"FindFile", FALSE);
78 KmtOpenDriver();
79
80 for (i = 0; i < TestCount; i++)
81 {
82 trace("[%d] '%ls', '%ls'\n", i, Tests[i].Expression, Tests[i].ExpectedExpression);
83 KmtSendWStringToDriver(IOCTL_EXPECT, Tests[i].ExpectedExpression);
84 wcscpy(ExpressionBuffer, L"\\\\.\\Global\\GLOBALROOT\\Device\\Kmtest-FindFile\\");
85 wcscat(ExpressionBuffer, Tests[i].Expression);
86 FindHandle = FindFirstFileW(ExpressionBuffer, &FindData);
87 ok(FindHandle != NULL && FindHandle != INVALID_HANDLE_VALUE, "Handle: %p, error=%lu\n", (PVOID)FindHandle, GetLastError());
88 if (FindHandle != INVALID_HANDLE_VALUE)
89 FindClose(FindHandle);
90 }
91
92 KmtCloseDriver();
93 KmtUnloadDriver();
94 }