[MMIXER] Fix additional data size initialization for different audio formats (#6753)
[reactos.git] / modules / rostests / apitests / ntdll / RtlDosApplyFileIsolationRedirection_Ustr.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for RtlDosApplyFileIsolationRedirection_Ustr
5 * PROGRAMMER: Giannis Adamopoulos
6 */
7
8 #include "precomp.h"
9
10 #define ok_eq_hex(value, expected) ok((value) == (expected), #value " = 0x%lx, expected 0x%lx\n", value, expected)
11 #define ok_eq_pointer(value, expected) ok((value) == (expected), #value " = %p, expected %p\n", value, expected)
12
13 #define EXPECT_IN_SAME_DIR (WCHAR*)0xdead
14
15 UNICODE_STRING DotDll = RTL_CONSTANT_STRING(L".DLL");
16
17 struct test_data
18 {
19 int testline;
20 NTSTATUS ExpectedStatus;
21 WCHAR* Param;
22 WCHAR* ExpectedSubString;
23 };
24
25 struct test_data Tests[] =
26 {
27 /* Not redirected file */
28 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"somefilesomefile", NULL},
29 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"ntdll.dll", NULL},
30 /* Files redirected with sxs */
31 {__LINE__, STATUS_SUCCESS, L"GDIPLUS", L"\\winsxs\\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1."},
32 {__LINE__, STATUS_SUCCESS, L"GDIPLUS.DLL", L"\\winsxs\\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1."},
33 {__LINE__, STATUS_SUCCESS, L"COMCTL32.DLL", L"\\winsxs\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82"},
34 {__LINE__, STATUS_SUCCESS, L"comctl32.DLL", L"\\winsxs\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82"},
35 {__LINE__, STATUS_SUCCESS, L"c:\\windows\\system32\\comctl32.DLL", L"\\winsxs\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82"},
36 /* Files not redirected with sxs */
37 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"MSVCR90.DLL", NULL},
38 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"c:\\windows\\system32\\MSVCR90.DLL", NULL},
39 /* Files defined in the manifest, one exists, one doesn't */
40 {__LINE__, STATUS_SUCCESS, L"deptest.dll", EXPECT_IN_SAME_DIR},
41 {__LINE__, STATUS_SUCCESS, L"adllfile.dll", EXPECT_IN_SAME_DIR},
42 /* A file that exists in the same dir but isn't mentioned in the manifest */
43 {__LINE__, STATUS_SUCCESS, L"fil1.txt", EXPECT_IN_SAME_DIR},
44 /* This is a weird case; the source doesn't exist but does get redirected */
45 {__LINE__, STATUS_SUCCESS, L"c:\\windows\\system32\\gdiplus.DLL", L"\\winsxs\\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1."},
46 /* But redirecting gdiplus from a different directory doesn't work */
47 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"c:\\GDIPLUS.DLL", NULL},
48 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"c:\\comctl32.DLL", NULL},
49 /* Redirection based on .local */
50 {__LINE__, STATUS_SUCCESS, L"test", EXPECT_IN_SAME_DIR},
51 {__LINE__, STATUS_SUCCESS, L"test.dll", EXPECT_IN_SAME_DIR},
52 {__LINE__, STATUS_SUCCESS, L"c:\\test.dll", EXPECT_IN_SAME_DIR},
53 /* known dlls are also covered */
54 {__LINE__, STATUS_SUCCESS, L"shell32", EXPECT_IN_SAME_DIR},
55 {__LINE__, STATUS_SUCCESS, L"shell32.dll", EXPECT_IN_SAME_DIR},
56 {__LINE__, STATUS_SUCCESS, L"c:\\shell32.dll", EXPECT_IN_SAME_DIR}
57 };
58
59 HANDLE _CreateActCtxFromFile(LPCWSTR FileName, int line)
60 {
61 ACTCTXW ActCtx = {sizeof(ACTCTX)};
62 HANDLE h;
63 WCHAR buffer[MAX_PATH] , *separator;
64
65 ok (GetModuleFileNameW(NULL, buffer, MAX_PATH), "GetModuleFileName failed\n");
66 separator = wcsrchr(buffer, L'\\');
67 if (separator)
68 wcscpy(separator + 1, FileName);
69
70 ActCtx.lpSource = buffer;
71
72 SetLastError(0xdeaddead);
73 h = CreateActCtxW(&ActCtx);
74 ok_(__FILE__, line)(h != INVALID_HANDLE_VALUE, "CreateActCtx failed for %S\n", FileName);
75 // In win10 last error is unchanged and in win2k3 it is ERROR_BAD_EXE_FORMAT
76 ok_(__FILE__, line)(GetLastError() == ERROR_BAD_EXE_FORMAT || GetLastError() == 0xdeaddead, "Wrong last error %lu\n", GetLastError());
77
78 return h;
79 }
80
81 void TestRedirection(void)
82 {
83 WCHAR SystemDir[MAX_PATH];
84 WCHAR TestPath[MAX_PATH];
85 WCHAR ParameterBuffer[MAX_PATH];
86 WCHAR* separator;
87 NTSTATUS Status;
88 int i;
89
90 GetSystemDirectoryW(SystemDir, MAX_PATH);
91 GetModuleFileNameW(NULL, TestPath, MAX_PATH);
92 separator = wcsrchr(TestPath, L'\\');
93 separator++;
94 *separator = 0;
95
96 for (i = 0; i < _countof(Tests); i ++)
97 {
98 UNICODE_STRING OriginalName, DynamicString;
99 PUNICODE_STRING StringUsed = NULL;
100
101 if (memcmp(Tests[i].Param, L"c:\\windows\\system32", 38) == 0)
102 {
103 wcscpy(ParameterBuffer, SystemDir);
104 wcscat(ParameterBuffer, &Tests[i].Param[19]);
105 }
106 else
107 {
108 wcscpy(ParameterBuffer, Tests[i].Param);
109 }
110
111 RtlInitUnicodeString(&OriginalName, ParameterBuffer);
112 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
113
114 Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
115 &OriginalName,
116 &DotDll,
117 NULL,
118 &DynamicString,
119 &StringUsed,
120 NULL,
121 NULL,
122 NULL);
123 ok(Status == Tests[i].ExpectedStatus, "%d: Status 0x%lx, expected 0x%lx\n", Tests[i].testline, Status, Tests[i].ExpectedStatus);
124
125 if(Tests[i].ExpectedSubString && DynamicString.Buffer == NULL)
126 {
127 ok(0, "%d: Expected a returned string\n", Tests[i].testline);
128 }
129
130 if (Tests[i].ExpectedSubString && DynamicString.Buffer != NULL)
131 {
132 if (Tests[i].ExpectedSubString == EXPECT_IN_SAME_DIR)
133 {
134 ok(wcsstr(DynamicString.Buffer, TestPath) != 0, "%d: Expected string %S in %S\n", Tests[i].testline, TestPath, DynamicString.Buffer);
135 }
136 else
137 {
138 RtlDowncaseUnicodeString(&DynamicString, &DynamicString, FALSE);
139 ok(wcsstr(DynamicString.Buffer, Tests[i].ExpectedSubString) != 0, "%d: Expected string %S in %S\n", Tests[i].testline, Tests[i].ExpectedSubString, DynamicString.Buffer);
140 }
141 }
142 }
143 }
144
145 void TestBuffers()
146 {
147 UNICODE_STRING Param, DynamicString, StaticString;
148 PUNICODE_STRING StringUsed = NULL;
149 NTSTATUS Status;
150 WCHAR buffer[MAX_PATH];
151
152 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
153 Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
154 NULL,
155 NULL,
156 NULL,
157 &DynamicString,
158 &StringUsed,
159 NULL,
160 NULL,
161 NULL);
162 ok(Status ==STATUS_INVALID_PARAMETER, "0x%lx\n", Status);
163
164 RtlInitEmptyUnicodeString(&Param, NULL, 0);
165 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
166 Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
167 &Param,
168 NULL,
169 NULL,
170 &DynamicString,
171 &StringUsed,
172 NULL,
173 NULL,
174 NULL);
175 ok(Status ==STATUS_SXS_KEY_NOT_FOUND, "0x%lx\n", Status);
176
177 /* Tests for NULL termination of OriginalName */
178 Param.MaximumLength = Param.Length = 12 * sizeof(WCHAR);
179 Param.Buffer = L"comctl32.dllcrapcrap";
180 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
181 Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
182 &Param,
183 NULL,
184 NULL,
185 &DynamicString,
186 &StringUsed,
187 NULL,
188 NULL,
189 NULL);
190 ok(Status ==STATUS_SUCCESS, "\n");
191
192 /* Tests for the Extension parameter */
193 RtlInitUnicodeString(&Param, L"comctl32.dll");
194 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
195 Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
196 &Param,
197 NULL,
198 NULL,
199 &DynamicString,
200 &StringUsed,
201 NULL,
202 NULL,
203 NULL);
204 ok(Status ==STATUS_SUCCESS, "\n");
205
206 RtlInitUnicodeString(&Param, L"comctl32");
207 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
208 Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
209 &Param,
210 NULL,
211 NULL,
212 &DynamicString,
213 &StringUsed,
214 NULL,
215 NULL,
216 NULL);
217 ok(Status ==STATUS_SXS_KEY_NOT_FOUND, "0x%lx\n", Status);
218
219 RtlInitUnicodeString(&Param, L"comctl32");
220 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
221 Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
222 &Param,
223 &DotDll,
224 NULL,
225 &DynamicString,
226 &StringUsed,
227 NULL,
228 NULL,
229 NULL);
230 ok(Status ==STATUS_SUCCESS, "\n");
231
232 /* Tests for the DynamicString parameter */
233 RtlInitUnicodeString(&Param, L"comctl32.dll");
234 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
235 Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
236 &Param,
237 NULL,
238 NULL,
239 &DynamicString,
240 &StringUsed,
241 NULL,
242 NULL,
243 NULL);
244 ok(Status ==STATUS_SUCCESS, "\n");
245 ok(DynamicString.Length >0 , "\n");
246 ok(DynamicString.MaximumLength == DynamicString.Length + sizeof(WCHAR) , "\n");
247 if (DynamicString.Buffer && DynamicString.Length)
248 ok(wcslen(DynamicString.Buffer) * sizeof(WCHAR) == DynamicString.Length, "got %d and %d\n", wcslen(DynamicString.Buffer) * sizeof(WCHAR) , DynamicString.Length);
249 else
250 ok(DynamicString.Buffer != NULL, "Expected non NULL buffer\n");
251 ok(StringUsed == &DynamicString, "\n");
252
253 /* Tests for the StaticString parameter */
254 wcscpy(buffer, L"comctl32.dll");
255 StaticString.Buffer = buffer;
256 StaticString.Length = sizeof(L"comctl32.dll");
257 StaticString.MaximumLength = sizeof(buffer);
258 Param = StaticString;
259 Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
260 &Param,
261 NULL,
262 &StaticString,
263 NULL,
264 &StringUsed,
265 NULL,
266 NULL,
267 NULL);
268 ok(Status ==STATUS_SXS_KEY_NOT_FOUND, "0x%lx\n", Status);
269
270 wcscpy(buffer, L"comctl32.dll");
271 StaticString.Buffer = buffer;
272 StaticString.Length = sizeof(L"comctl32.dll");
273 StaticString.MaximumLength = sizeof(buffer);
274 Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
275 &StaticString,
276 NULL,
277 &StaticString,
278 NULL,
279 &StringUsed,
280 NULL,
281 NULL,
282 NULL);
283 ok(Status ==STATUS_SXS_KEY_NOT_FOUND, "0x%lx\n", Status);
284
285 RtlInitUnicodeString(&Param, L"comctl32.dll");
286 RtlInitEmptyUnicodeString(&StaticString, buffer, sizeof(buffer));
287 Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
288 &Param,
289 NULL,
290 &StaticString,
291 NULL,
292 &StringUsed,
293 NULL,
294 NULL,
295 NULL);
296 ok(Status ==STATUS_SUCCESS, "\n");
297 ok(StaticString.Length >0 , "\n");
298 ok(StaticString.MaximumLength == sizeof(buffer) , "\n");
299 if (StaticString.Buffer && StaticString.Length)
300 ok(wcslen(StaticString.Buffer) * sizeof(WCHAR) == StaticString.Length, "got %d and %d\n", wcslen(StaticString.Buffer) * sizeof(WCHAR) , StaticString.Length);
301 else
302 ok(StaticString.Length != 0, "Expected non 0 lenght\n");
303 ok(StringUsed == &StaticString, "\n");
304
305 RtlInitEmptyUnicodeString(&StaticString, buffer, 5 * sizeof(WCHAR));
306 Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
307 &Param,
308 NULL,
309 &StaticString,
310 NULL,
311 &StringUsed,
312 NULL,
313 NULL,
314 NULL);
315 ok(Status == STATUS_BUFFER_TOO_SMALL, "0x%lx\n", Status);
316
317 RtlInitUnicodeString(&Param, L"comctl32.dll");
318 RtlInitEmptyUnicodeString(&StaticString, buffer, sizeof(buffer));
319 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
320 Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
321 &Param,
322 NULL,
323 &StaticString,
324 &DynamicString,
325 &StringUsed,
326 NULL,
327 NULL,
328 NULL);
329 ok(Status ==STATUS_SUCCESS, "\n");
330 ok(StaticString.Length >0 , "\n");
331 ok(StaticString.MaximumLength == sizeof(buffer) , "\n");
332 if (StaticString.Buffer && StaticString.Length)
333 ok(wcslen(StaticString.Buffer) * sizeof(WCHAR) == StaticString.Length, "got %d and %d\n", wcslen(StaticString.Buffer) * sizeof(WCHAR) , StaticString.Length);
334 else
335 ok(StaticString.Length != 0, "Expected non 0 lenght\n");
336 ok(DynamicString.Buffer == NULL, "\n");
337 ok(DynamicString.Length == 0, "\n");
338 ok(DynamicString.MaximumLength == 0, "\n");
339 ok(StringUsed == &StaticString, "\n");
340
341 /* Test a small buffer and a dynamic buffer */
342 RtlInitUnicodeString(&Param, L"comctl32.dll");
343 RtlInitEmptyUnicodeString(&StaticString, buffer, 5 * sizeof(WCHAR));
344 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
345 StaticString.Buffer[0] = 1;
346 Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
347 &Param,
348 NULL,
349 &StaticString,
350 &DynamicString,
351 &StringUsed,
352 NULL,
353 NULL,
354 NULL);
355 ok(Status ==STATUS_SUCCESS, "\n");
356 ok(StaticString.Buffer == buffer, "\n");
357 ok(StaticString.Length == 0 , "%d\n", StaticString.Length);
358 ok(StaticString.Buffer[0] == 0, "\n");
359 ok(StaticString.MaximumLength == 5 * sizeof(WCHAR) , "%d\n", StaticString.MaximumLength);
360 ok(DynamicString.Length >0 , "\n");
361 ok(DynamicString.MaximumLength == DynamicString.Length + sizeof(WCHAR) , "\n");
362 if (DynamicString.Buffer && DynamicString.Length)
363 ok(wcslen(DynamicString.Buffer) * sizeof(WCHAR) == DynamicString.Length, "got %d and %d\n", wcslen(DynamicString.Buffer) * sizeof(WCHAR) , DynamicString.Length);
364 else
365 ok(DynamicString.Length != 0, "Expected non 0 lenght\n");
366
367 ok(StringUsed == &DynamicString, "\n");
368 }
369
370 START_TEST(RtlDosApplyFileIsolationRedirection_Ustr)
371 {
372 int argc;
373 char **test_argv;
374 argc = winetest_get_mainargs( &test_argv );
375 if (argc >= 3)
376 {
377 HANDLE h = _CreateActCtxFromFile(L"ntdlltest.manifest", __LINE__);
378 BOOL bactivated = FALSE;
379 ULONG_PTR cookie;
380
381 if (h != INVALID_HANDLE_VALUE)
382 bactivated = ActivateActCtx(h, &cookie);
383
384 TestRedirection();
385 TestBuffers();
386
387 if (bactivated)
388 DeactivateActCtx(0, cookie);
389 }
390 else
391 {
392 WCHAR TestPath[MAX_PATH];
393 WCHAR* separator;
394 STARTUPINFOW si = { sizeof(si) };
395 PROCESS_INFORMATION pi;
396 BOOL created;
397
398 GetModuleFileNameW(NULL, TestPath, MAX_PATH);
399 separator = wcsrchr(TestPath, L'\\');
400 separator++;
401 wcscpy(separator, L"testdata\\ntdll_apitest.exe RtlDosApplyFileIsolationRedirection_Ustr DoTest");
402
403 created = CreateProcessW(NULL, TestPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
404 ok(created, "Expected CreateProcess to succeed\n");
405 if (created)
406 {
407 winetest_wait_child_process(pi.hProcess);
408 CloseHandle(pi.hThread);
409 CloseHandle(pi.hProcess);
410 }
411 }
412 }