[NTDLL_APITEST] -Create a copy of the test in testdata and add along three empty...
[reactos.git] / 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 <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #include <ndk/rtlfuncs.h>
12
13 #define ok_eq_hex(value, expected) ok((value) == (expected), #value " = 0x%lx, expected 0x%lx\n", value, expected)
14 #define ok_eq_pointer(value, expected) ok((value) == (expected), #value " = %p, expected %p\n", value, expected)
15
16 #define EXPECT_IN_SAME_DIR (WCHAR*)0xdead
17
18 UNICODE_STRING DotDll = RTL_CONSTANT_STRING(L".DLL");
19
20 struct test_data
21 {
22 int testline;
23 NTSTATUS ExpectedStatus;
24 WCHAR* Param;
25 WCHAR* ExpectedSubString;
26 };
27
28 struct test_data Tests[] =
29 {
30 /* Not redirected file */
31 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"somefilesomefile", NULL},
32 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"ntdll.dll", NULL},
33 /* Files redirected with sxs */
34 {__LINE__, STATUS_SUCCESS, L"GDIPLUS", L"\\winsxs\\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1."},
35 {__LINE__, STATUS_SUCCESS, L"GDIPLUS.DLL", L"\\winsxs\\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1."},
36 {__LINE__, STATUS_SUCCESS, L"COMCTL32.DLL", L"\\winsxs\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82"},
37 {__LINE__, STATUS_SUCCESS, L"comctl32.DLL", L"\\winsxs\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82"},
38 {__LINE__, STATUS_SUCCESS, L"c:\\windows\\system32\\comctl32.DLL", L"\\winsxs\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82"},
39 /* This is a weird case; the source doesn't exist but does get redirected */
40 {__LINE__, STATUS_SUCCESS, L"c:\\windows\\system32\\gdiplus.DLL", L"\\winsxs\\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1."},
41 /* But redirecting gdiplus from a different directory doesn't work */
42 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"c:\\GDIPLUS.DLL", NULL},
43 {__LINE__, STATUS_SXS_KEY_NOT_FOUND, L"c:\\comctl32.DLL", NULL},
44 /* Redirection based on .local */
45 {__LINE__, STATUS_SUCCESS, L"test", EXPECT_IN_SAME_DIR},
46 {__LINE__, STATUS_SUCCESS, L"test.dll", EXPECT_IN_SAME_DIR},
47 {__LINE__, STATUS_SUCCESS, L"c:\\test.dll", EXPECT_IN_SAME_DIR},
48 /* known dlls are also covered */
49 {__LINE__, STATUS_SUCCESS, L"shell32", EXPECT_IN_SAME_DIR},
50 {__LINE__, STATUS_SUCCESS, L"shell32.dll", EXPECT_IN_SAME_DIR},
51 {__LINE__, STATUS_SUCCESS, L"c:\\shell32.dll", EXPECT_IN_SAME_DIR}
52 };
53
54 void TestRedirection(void)
55 {
56 WCHAR SystemDir[MAX_PATH];
57 WCHAR TestPath[MAX_PATH];
58 WCHAR ParameterBuffer[MAX_PATH];
59 WCHAR* separator;
60 NTSTATUS Status;
61 int i;
62
63 GetSystemDirectoryW(SystemDir, MAX_PATH);
64 GetModuleFileNameW(NULL, TestPath, MAX_PATH);
65 separator = wcsrchr(TestPath, L'\\');
66 separator++;
67 *separator = 0;
68
69 for (i = 0; i < _countof(Tests); i ++)
70 {
71 UNICODE_STRING OriginalName, DynamicString;
72 PUNICODE_STRING StringUsed = NULL;
73
74 if (memcmp(Tests[i].Param, L"c:\\windows\\system32", 38) == 0)
75 {
76 wcscpy(ParameterBuffer, SystemDir);
77 wcscat(ParameterBuffer, &Tests[i].Param[19]);
78 }
79 else
80 {
81 wcscpy(ParameterBuffer, Tests[i].Param);
82 }
83
84 RtlInitUnicodeString(&OriginalName, ParameterBuffer);
85 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
86
87 Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
88 &OriginalName,
89 &DotDll,
90 NULL,
91 &DynamicString,
92 &StringUsed,
93 NULL,
94 NULL,
95 NULL);
96 ok(Status == Tests[i].ExpectedStatus, "%d: Status 0x%lx, expected 0x%lx\n", Tests[i].testline, Status, Tests[i].ExpectedStatus);
97
98 if (DynamicString.Buffer)
99 {
100 BOOL exists = RtlDoesFileExists_U(DynamicString.Buffer);
101 ok(exists, "%d: Expected file %S to exist!\n", Tests[i].testline, DynamicString.Buffer);
102 }
103
104 if(Tests[i].ExpectedSubString && DynamicString.Buffer == NULL)
105 {
106 ok(0, "%d: Expected a returned string\n", Tests[i].testline);
107 }
108
109 if (Tests[i].ExpectedSubString && DynamicString.Buffer != NULL)
110 {
111 if (Tests[i].ExpectedSubString == EXPECT_IN_SAME_DIR)
112 {
113 ok(wcsstr(DynamicString.Buffer, TestPath) != 0, "%d: Expected string %S in %S\n", Tests[i].testline, TestPath, DynamicString.Buffer);
114 }
115 else
116 {
117 RtlDowncaseUnicodeString(&DynamicString, &DynamicString, FALSE);
118 ok(wcsstr(DynamicString.Buffer, Tests[i].ExpectedSubString) != 0, "%d: Expected string %S in %S\n", Tests[i].testline, Tests[i].ExpectedSubString, DynamicString.Buffer);
119 }
120 }
121 }
122 }
123
124 START_TEST(RtlDosApplyFileIsolationRedirection_Ustr)
125 {
126 int argc;
127 char **test_argv;
128 argc = winetest_get_mainargs( &test_argv );
129 if (argc >= 3)
130 {
131 TestRedirection();
132 }
133 else
134 {
135 WCHAR TestPath[MAX_PATH];
136 WCHAR* separator;
137 STARTUPINFOW si = { sizeof(si) };
138 PROCESS_INFORMATION pi;
139 BOOL created;
140
141 GetModuleFileNameW(NULL, TestPath, MAX_PATH);
142 separator = wcsrchr(TestPath, L'\\');
143 separator++;
144 wcscpy(separator, L"testdata\\ntdll_apitest.exe RtlDosApplyFileIsolationRedirection_Ustr DoTest");
145
146 created = CreateProcessW(NULL, TestPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
147 ok(created, "Expected CreateProcess to succeed\n");
148 if (created)
149 {
150 winetest_wait_child_process(pi.hProcess);
151 CloseHandle(pi.hThread);
152 CloseHandle(pi.hProcess);
153 }
154 }
155 }