[KMTESTS:OB]
[reactos.git] / rostests / kmtests / ntos_fsrtl / FsRtlExpression.c
1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for FsRtlIsNameInExpression/FsRtlIsDbcsInExpression
5 * PROGRAMMER: Pierre Schweitzer <pierre.schweitzer@reactos.org>
6 * Víctor Martínez Calvo <vmartinez@reactos.org>
7 */
8
9 #include <kmt_test.h>
10
11 #define NDEBUG
12 #include <debug.h>
13
14 struct
15 { /* API parameters */
16 PCWSTR Expression;
17 PCWSTR Name;
18 BOOLEAN IgnoreCase;
19 /* Flag for tests which shouldn't be tested in checked builds */
20 BOOLEAN AssertsInChecked;
21 /* Expected test result */
22 BOOLEAN Expected;
23 } Tests[] =
24 {
25 /* TODO: reorganize AssertsInChecked. This needs to be separate for *Name* and *Dbcs* or something.
26 * We currently fail a lot of them in Windows despite AssertsInChecked.
27 * E.g. *Dbcs* asserts !islower(Expression[i]) and FsRtlDoesDbcsContainWildCards(Expression) for some reason.
28 */
29 { L"", L"", FALSE, TRUE, TRUE },
30 { L"", L"a", FALSE, TRUE, FALSE },
31 { L"*", L"a", FALSE, TRUE, TRUE },
32 { L"*", L"", FALSE, TRUE, FALSE },
33 { L"**", L"", FALSE, TRUE, FALSE },
34 { L"**", L"a", FALSE, FALSE, TRUE },
35 { L"ntdll.dll", L".", FALSE, TRUE, FALSE },
36 { L"ntdll.dll", L"~1", FALSE, TRUE, FALSE },
37 { L"ntdll.dll", L"..", FALSE, TRUE, FALSE },
38 { L"ntdll.dll", L"ntdll.dll", FALSE, TRUE, TRUE },
39 { L"smss.exe", L".", FALSE, TRUE, FALSE },
40 { L"smss.exe", L"~1", FALSE, TRUE, FALSE },
41 { L"smss.exe", L"..", FALSE, TRUE, FALSE },
42 { L"smss.exe", L"ntdll.dll", FALSE, TRUE, FALSE },
43 { L"smss.exe", L"NTDLL.DLL", FALSE, TRUE, FALSE },
44 { L"nt??krnl.???", L"ntoskrnl.exe", FALSE, FALSE, TRUE },
45 { L"he*o", L"hello", FALSE, FALSE, TRUE },
46 { L"he*o", L"helo", FALSE, FALSE, TRUE },
47 { L"he*o", L"hella", FALSE, FALSE, FALSE },
48 { L"he*", L"hello", FALSE, FALSE, TRUE },
49 { L"he*", L"helo", FALSE, FALSE, TRUE },
50 { L"he*", L"hella", FALSE, FALSE, TRUE },
51 { L"*.cpl", L"kdcom.dll", FALSE, FALSE, FALSE },
52 { L"*.cpl", L"bootvid.dll", FALSE, FALSE, FALSE },
53 { L"*.cpl", L"ntoskrnl.exe", FALSE, FALSE, FALSE },
54 { L".", L"NTDLL.DLL", FALSE, FALSE, FALSE },
55 { L"F0_*.*", L".", FALSE, FALSE, FALSE },
56 { L"F0_*.*", L"..", FALSE, FALSE, FALSE },
57 { L"F0_*.*", L"SETUP.EXE", FALSE, FALSE, FALSE },
58 { L"F0_*.*", L"f0_", FALSE, FALSE, FALSE },
59 { L"F0_*.*", L"f0_", TRUE, FALSE, FALSE },
60 { L"F0_*.*", L"F0_", FALSE, FALSE, FALSE },
61 { L"F0_*.*", L"f0_.", FALSE, FALSE, FALSE },
62 { L"F0_*.*", L"f0_.", TRUE, FALSE, TRUE },
63 { L"F0_*.*", L"F0_.", FALSE, FALSE, TRUE },
64 { L"F0_*.*", L"F0_001", FALSE, FALSE, FALSE },
65 { L"F0_*.*", L"F0_001", TRUE, FALSE, FALSE },
66 { L"F0_*.*", L"f0_001", FALSE, FALSE, FALSE },
67 { L"F0_*.*", L"f0_001", TRUE, FALSE, FALSE },
68 { L"F0_*.*", L"F0_001.", FALSE, FALSE, TRUE },
69 { L"F0_*.*", L"f0_001.txt", FALSE, FALSE, FALSE },
70 { L"F0_*.*", L"f0_001.txt", TRUE, FALSE, TRUE },
71 { L"F0_*.*", L"F0_001.txt", FALSE, FALSE, TRUE },
72 { L"F0_*.*", L"F0_001.txt", TRUE, FALSE, TRUE },
73 { L"F0_*.", L".", FALSE, FALSE, FALSE },
74 { L"F0_*.", L"..", FALSE, FALSE, FALSE },
75 { L"F0_*.", L"SETUP.EXE", FALSE, FALSE, FALSE },
76 { L"F0_*.", L"f0_", FALSE, FALSE, FALSE },
77 { L"F0_*.", L"f0_", TRUE, FALSE, FALSE },
78 { L"F0_*.", L"F0_", FALSE, FALSE, FALSE },
79 { L"F0_*.", L"f0_.", FALSE, FALSE, FALSE },
80 { L"F0_*.", L"f0_.", TRUE, FALSE, TRUE },
81 { L"F0_*.", L"F0_.", FALSE, FALSE, TRUE },
82 { L"F0_*.", L"F0_001", FALSE, FALSE, FALSE },
83 { L"F0_*.", L"F0_001", TRUE, FALSE, FALSE },
84 { L"F0_*.", L"f0_001", FALSE, FALSE, FALSE },
85 { L"F0_*.", L"f0_001", TRUE, FALSE, FALSE },
86 { L"F0_*.", L"F0_001.", FALSE, FALSE, TRUE },
87 { L"F0_*.", L"f0_001.txt", FALSE, FALSE, FALSE },
88 { L"F0_*.", L"f0_001.txt", TRUE, FALSE, FALSE },
89 { L"F0_*.", L"F0_001.txt", FALSE, FALSE, FALSE },
90 { L"F0_*.", L"F0_001.txt", TRUE, FALSE, FALSE },
91 { L"F0_<\"*", L".", FALSE, FALSE, FALSE },
92 { L"F0_<\"*", L"..", FALSE, FALSE, FALSE },
93 { L"F0_<\"*", L"SETUP.EXE", FALSE, FALSE, FALSE },
94 { L"F0_<\"*", L"f0_", TRUE, FALSE, TRUE },
95 { L"F0_<\"*", L"F0_", FALSE, FALSE, TRUE },
96 { L"F0_<\"*", L"f0_.", FALSE, FALSE, FALSE },
97 { L"F0_<\"*", L"f0_.", TRUE, FALSE, TRUE },
98 { L"F0_<\"*", L"F0_.", FALSE, FALSE, TRUE },
99 { L"F0_<\"*", L"F0_001", FALSE, FALSE, TRUE },
100 { L"F0_<\"*", L"F0_001", TRUE, FALSE, TRUE },
101 { L"F0_<\"*", L"f0_001", FALSE, FALSE, FALSE },
102 { L"F0_<\"*", L"f0_001", TRUE, FALSE, TRUE },
103 { L"F0_<\"*", L"F0_001.", FALSE, FALSE, TRUE },
104 { L"F0_<\"*", L"f0_001.txt", FALSE, FALSE, FALSE },
105 { L"F0_<\"*", L"f0_001.txt", TRUE, FALSE, TRUE },
106 { L"F0_<\"*", L"F0_001.txt", FALSE, FALSE, TRUE },
107 { L"F0_<\"*", L"F0_001.txt", TRUE, FALSE, TRUE },
108 { L"*.TTF", L".", FALSE, FALSE, FALSE },
109 { L"*.TTF", L"..", FALSE, FALSE, FALSE },
110 { L"*.TTF", L"SETUP.INI", FALSE, FALSE, FALSE },
111 { L"*", L".", FALSE, FALSE, TRUE },
112 { L"*", L"..", FALSE, FALSE, TRUE },
113 { L"*", L"SETUP.INI", FALSE, FALSE, TRUE },
114 { L".*", L"1", FALSE, FALSE, FALSE },
115 { L".*", L"01", FALSE, FALSE, FALSE },
116 { L".*", L" ", FALSE, FALSE, FALSE },
117 { L".*", L"", FALSE, TRUE, FALSE },
118 { L".*", L".", FALSE, FALSE, TRUE },
119 { L".*", L"1.txt", FALSE, FALSE, FALSE },
120 { L".*", L" .txt", FALSE, FALSE, FALSE },
121 { L".*", L".txt", FALSE, FALSE, TRUE },
122 { L"\"ntoskrnl.exe", L"ntoskrnl.exe", FALSE, FALSE, FALSE },
123 { L"ntoskrnl\"exe", L"ntoskrnl.exe", FALSE, FALSE, TRUE },
124 { L"ntoskrn\".exe", L"ntoskrnl.exe", FALSE, FALSE, FALSE },
125 { L"ntoskrn\"\"exe", L"ntoskrnl.exe", FALSE, FALSE, FALSE },
126 { L"ntoskrnl.\"exe", L"ntoskrnl.exe", FALSE, FALSE, FALSE },
127 { L"ntoskrnl.exe\"", L"ntoskrnl.exe", FALSE, FALSE, TRUE },
128 { L"ntoskrnl.exe", L"ntoskrnl.exe", FALSE, FALSE, TRUE },
129 { L"*.c.d", L"a.b.c.d", FALSE, FALSE, TRUE },
130 { L"*.?.c.d", L"a.b.c.d", FALSE, FALSE, TRUE },
131 { L"**.?.c.d", L"a.b.c.d", FALSE, FALSE, TRUE },
132 { L"a.**.c.d", L"a.b.c.d", FALSE, FALSE, TRUE },
133 { L"a.b.??.d", L"a.b.c1.d", FALSE, FALSE, TRUE },
134 { L"a.b.??.d", L"a.b.c.d", FALSE, FALSE, FALSE },
135 { L"a.b.*?.d", L"a.b.c.d", FALSE, FALSE, TRUE },
136 { L"a.b.*??.d", L"a.b.ccc.d", FALSE, FALSE, TRUE },
137 { L"a.b.*??.d", L"a.b.cc.d", FALSE, FALSE, TRUE },
138 { L"a.b.*??.d", L"a.b.c.d", FALSE, FALSE, FALSE },
139 { L"a.b.*?*.d", L"a.b.c.d", FALSE, FALSE, TRUE },
140 { L"*?", L"", FALSE, TRUE, FALSE },
141 { L"*?", L"a", FALSE, FALSE, TRUE },
142 { L"*?", L"aa", FALSE, FALSE, TRUE },
143 { L"*?", L"aaa", FALSE, FALSE, TRUE },
144 { L"?*?", L"", FALSE, TRUE, FALSE },
145 { L"?*?", L"a", FALSE, FALSE, FALSE },
146 { L"?*?", L"aa", FALSE, FALSE, TRUE },
147 { L"?*?", L"aaa", FALSE, FALSE, TRUE },
148 { L"?*?", L"aaaa", FALSE, FALSE, TRUE },
149 { L"C:\\ReactOS\\**", L"C:\\ReactOS\\dings.bmp", FALSE, FALSE, TRUE },
150 { L"C:\\ReactOS\\***", L"C:\\ReactOS\\dings.bmp", FALSE, FALSE, TRUE },
151 { L"C:\\Windows\\*a*", L"C:\\ReactOS\\dings.bmp", FALSE, FALSE, FALSE },
152 { L"C:\\ReactOS\\*.bmp", L"C:\\Windows\\explorer.exe", FALSE, FALSE, FALSE },
153 { L"*.bmp;*.dib", L"winhlp32.exe", FALSE, FALSE, FALSE },
154 { L"*.*.*.*", L"127.0.0.1", FALSE, FALSE, TRUE },
155 { L"*?*?*?*", L"1.0.0.1", FALSE, FALSE, TRUE },
156 { L"?*?*?*?", L"1.0.0.1", FALSE, FALSE, TRUE },
157 { L"?.?.?.?", L"1.0.0.1", FALSE, FALSE, TRUE },
158 { L"*a*ab*abc", L"aabaabcdadabdabc", FALSE, FALSE, TRUE },
159 { L"ab<exe", L"abcd.exe", FALSE, FALSE, TRUE },
160 { L"ab<exe", L"ab.exe", FALSE, FALSE, TRUE },
161 { L"ab<exe", L"abcdexe", FALSE, FALSE, TRUE },
162 { L"ab<exe", L"acd.exe", FALSE, FALSE, FALSE },
163 { L"a.b<exe", L"a.bcd.exe", FALSE, FALSE, TRUE },
164 { L"a<b.exe", L"a.bcd.exe", FALSE, FALSE, FALSE },
165 { L"a.b.exe", L"a.bcd.exe", FALSE, FALSE, FALSE },
166 { L"abc.exe", L"abc.exe", FALSE, FALSE, TRUE },
167 { L"abc.exe", L"abc.exe.", FALSE, FALSE, FALSE },
168 { L"abc.exe", L"abc.exe.back", FALSE, FALSE, FALSE },
169 { L"abc.exe", L"abc.exes", FALSE, FALSE, FALSE },
170 { L"a>c.exe", L"abc.exe", FALSE, FALSE, TRUE },
171 { L"a>c.exe", L"ac.exe", FALSE, FALSE, FALSE },
172 { L"a>>>exe", L"abc.exe", FALSE, FALSE, FALSE },
173 { L"a>>>exe", L"ac.exe", FALSE, FALSE, FALSE },
174 { L"<.exe", L"test.exe", FALSE, FALSE, TRUE },
175 { L"<.EXE", L"test.exe", TRUE, FALSE, TRUE },
176 };
177
178 static VOID FsRtlIsNameInExpressionTest()
179 {
180 ULONG i;
181 for (i = 0; i < sizeof(Tests) / sizeof(Tests[0]); i++)
182 {
183 BOOLEAN TestResult;
184 UNICODE_STRING Expression;
185 UNICODE_STRING Name;
186
187 RtlInitUnicodeString(&Expression, Tests[i].Expression);
188 RtlInitUnicodeString(&Name, Tests[i].Name);
189
190 TestResult = FsRtlIsNameInExpression(&Expression, &Name, Tests[i].IgnoreCase, NULL);
191
192 ok(TestResult == Tests[i].Expected, "FsRtlIsNameInExpression(%wZ,%wZ,%s,NULL): Expected %s, got %s\n",
193 &Expression, &Name, Tests[i].IgnoreCase ? "TRUE" : "FALSE", Tests[i].Expected ? "TRUE" : "FALSE", TestResult ? "TRUE" : "FALSE");
194 }
195
196 /* TODO: test UpcaseTable */
197 }
198
199 static VOID FsRtlIsDbcsInExpressionTest()
200 {
201 ULONG i;
202 for (i = 0; i < sizeof(Tests) / sizeof(Tests[0]); i++)
203 {
204 BOOLEAN TestResult;
205 UNICODE_STRING UExpression;
206 UNICODE_STRING UName;
207 ANSI_STRING Expression;
208 ANSI_STRING Name;
209
210 /* Don't run Tests which are known to assert in checked builds */
211 if (KmtIsCheckedBuild && Tests[i].AssertsInChecked)
212 continue;
213
214 /* Ignore Tests flagged IgnoreCase==TRUE to avoid duplicated testing */
215 if (Tests[i].IgnoreCase)
216 continue;
217
218 RtlInitUnicodeString(&UExpression, Tests[i].Expression);
219 RtlInitUnicodeString(&UName, Tests[i].Name);
220
221 RtlUnicodeStringToAnsiString(&Expression, &UExpression, TRUE);
222 RtlUnicodeStringToAnsiString(&Name, &UName, TRUE);
223
224 TestResult = FsRtlIsDbcsInExpression(&Expression, &Name);
225
226 ok(TestResult == Tests[i].Expected, "FsRtlIsDbcsInExpression(%Z,%Z): Expected %s, got %s\n",
227 &Expression, &Name, Tests[i].Expected ? "TRUE" : "FALSE", TestResult ? "TRUE" : "FALSE");
228
229 RtlFreeAnsiString(&Expression);
230 RtlFreeAnsiString(&Name);
231 }
232 }
233
234 START_TEST(FsRtlExpression)
235 {
236 FsRtlIsNameInExpressionTest();
237 FsRtlIsDbcsInExpressionTest();
238 }