[NTDLL_APITEST]
[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, "Status 0x%lx, expected 0x%lx\n", value, expected)
99 ok_eq_hex(Status, Tests[i].ExpectedStatus);
100
101 if (DynamicString.Buffer)
102 {
103 BOOL exists = RtlDoesFileExists_U(DynamicString.Buffer);
104 ok(exists, "%d: Expected file %S to exist!\n", Tests[i].testline, DynamicString.Buffer);
105 }
106
107 if(Tests[i].ExpectedSubString && DynamicString.Buffer == NULL)
108 {
109 ok(0, "%d: Expected a returned string\n", Tests[i].testline);
110 }
111
112 if (Tests[i].ExpectedSubString && DynamicString.Buffer != NULL)
113 {
114 if (Tests[i].ExpectedSubString == EXPECT_IN_SAME_DIR)
115 {
116 ok(wcsstr(DynamicString.Buffer, TestPath) != 0, "%d: Expected string %S in %S\n", Tests[i].testline, TestPath, DynamicString.Buffer);
117 }
118 else
119 {
120 RtlDowncaseUnicodeString(&DynamicString, &DynamicString, FALSE);
121 ok(wcsstr(DynamicString.Buffer, Tests[i].ExpectedSubString) != 0, "%d: Expected string %S in %S\n", Tests[i].testline, Tests[i].ExpectedSubString, DynamicString.Buffer);
122 }
123 }
124 }
125 }
126
127 START_TEST(RtlDosApplyFileIsolationRedirection_Ustr)
128 {
129 #if 0
130 WCHAR TestPath[MAX_PATH];
131 WCHAR* separator;
132 STARTUPINFOW si = { sizeof(si) };
133 PROCESS_INFORMATION pi;
134 BOOL created;
135 HANDLE file;
136
137 /* Create .local files */
138 GetModuleFileNameW(NULL, TestPath, MAX_PATH);
139
140 wcscat(TestPath, L".local");
141 file = CreateFileW(TestPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_NO_BUFFERING , NULL);
142 CloseHandle(file);
143 separator = wcsrchr(TestPath, L'\\');
144 separator++;
145 wcscpy(separator, L"test.dll");
146 file = CreateFileW(TestPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_NO_BUFFERING , NULL);
147 CloseHandle(file);
148 wcscpy(separator, L"shell32.dll");
149 file = CreateFileW(TestPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_NO_BUFFERING , NULL);
150 CloseHandle(file);
151 *separator = 0;
152 #endif
153 TestRedirection();
154 #if 0
155 /*Cleanup*/
156 wcscpy(separator, L"test.dll");
157 DeleteFileW(TestPath);
158 wcscpy(separator, L"shell32.dll");
159 DeleteFileW(TestPath);
160 GetModuleFileNameW(NULL, TestPath, MAX_PATH);
161 wcscat(TestPath, L".local");
162 DeleteFileW(TestPath);
163 #endif
164 }