e215b6e53010b34dc4564674ee88f61bf4ca18da
[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 #if 0
45 /* Redirection based on .local */
46 {__LINE__, STATUS_SUCCESS, L"test", EXPECT_IN_SAME_DIR},
47 {__LINE__, STATUS_SUCCESS, L"test.dll", EXPECT_IN_SAME_DIR},
48 {__LINE__, STATUS_SUCCESS, L"c:\\test.dll", EXPECT_IN_SAME_DIR},
49 /* known dlls are also covered */
50 {__LINE__, STATUS_SUCCESS, L"shell32", EXPECT_IN_SAME_DIR},
51 {__LINE__, STATUS_SUCCESS, L"shell32.dll", EXPECT_IN_SAME_DIR},
52 {__LINE__, STATUS_SUCCESS, L"c:\\shell32.dll", EXPECT_IN_SAME_DIR}
53 #endif
54 };
55
56 void TestRedirection(void)
57 {
58 WCHAR SystemDir[MAX_PATH];
59 WCHAR TestPath[MAX_PATH];
60 WCHAR ParameterBuffer[MAX_PATH];
61 WCHAR* separator;
62 NTSTATUS Status;
63 int i;
64
65 GetSystemDirectoryW(SystemDir, MAX_PATH);
66 GetModuleFileNameW(NULL, TestPath, MAX_PATH);
67 separator = wcsrchr(TestPath, L'\\');
68 separator++;
69 *separator = 0;
70
71 for (i = 0; i < _countof(Tests); i ++)
72 {
73 UNICODE_STRING OriginalName, DynamicString;
74 PUNICODE_STRING StringUsed = NULL;
75
76 if (memcmp(Tests[i].Param, L"c:\\windows\\system32", 38) == 0)
77 {
78 wcscpy(ParameterBuffer, SystemDir);
79 wcscat(ParameterBuffer, &Tests[i].Param[19]);
80 }
81 else
82 {
83 wcscpy(ParameterBuffer, Tests[i].Param);
84 }
85
86 RtlInitUnicodeString(&OriginalName, ParameterBuffer);
87 RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
88
89 Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
90 &OriginalName,
91 &DotDll,
92 NULL,
93 &DynamicString,
94 &StringUsed,
95 NULL,
96 NULL,
97 NULL);
98 ok(Status == Tests[i].ExpectedStatus, "%d: Status 0x%lx, expected 0x%lx\n", Tests[i].testline, Status, Tests[i].ExpectedStatus);
99
100 if (DynamicString.Buffer)
101 {
102 BOOL exists = RtlDoesFileExists_U(DynamicString.Buffer);
103 ok(exists, "%d: Expected file %S to exist!\n", Tests[i].testline, DynamicString.Buffer);
104 }
105
106 if(Tests[i].ExpectedSubString && DynamicString.Buffer == NULL)
107 {
108 ok(0, "%d: Expected a returned string\n", Tests[i].testline);
109 }
110
111 if (Tests[i].ExpectedSubString && DynamicString.Buffer != NULL)
112 {
113 if (Tests[i].ExpectedSubString == EXPECT_IN_SAME_DIR)
114 {
115 ok(wcsstr(DynamicString.Buffer, TestPath) != 0, "%d: Expected string %S in %S\n", Tests[i].testline, TestPath, DynamicString.Buffer);
116 }
117 else
118 {
119 RtlDowncaseUnicodeString(&DynamicString, &DynamicString, FALSE);
120 ok(wcsstr(DynamicString.Buffer, Tests[i].ExpectedSubString) != 0, "%d: Expected string %S in %S\n", Tests[i].testline, Tests[i].ExpectedSubString, DynamicString.Buffer);
121 }
122 }
123 }
124 }
125
126 START_TEST(RtlDosApplyFileIsolationRedirection_Ustr)
127 {
128 #if 0
129 WCHAR TestPath[MAX_PATH];
130 WCHAR* separator;
131 STARTUPINFOW si = { sizeof(si) };
132 PROCESS_INFORMATION pi;
133 BOOL created;
134 HANDLE file;
135
136 /* Create .local files */
137 GetModuleFileNameW(NULL, TestPath, MAX_PATH);
138
139 wcscat(TestPath, L".local");
140 file = CreateFileW(TestPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_NO_BUFFERING , NULL);
141 CloseHandle(file);
142 separator = wcsrchr(TestPath, L'\\');
143 separator++;
144 wcscpy(separator, L"test.dll");
145 file = CreateFileW(TestPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_NO_BUFFERING , NULL);
146 CloseHandle(file);
147 wcscpy(separator, L"shell32.dll");
148 file = CreateFileW(TestPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_NO_BUFFERING , NULL);
149 CloseHandle(file);
150 *separator = 0;
151 #endif
152 TestRedirection();
153 #if 0
154 /*Cleanup*/
155 wcscpy(separator, L"test.dll");
156 DeleteFileW(TestPath);
157 wcscpy(separator, L"shell32.dll");
158 DeleteFileW(TestPath);
159 GetModuleFileNameW(NULL, TestPath, MAX_PATH);
160 wcscat(TestPath, L".local");
161 DeleteFileW(TestPath);
162 #endif
163 }