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
10 #define WIN32_NO_STATUS
11 #include <ndk/rtlfuncs.h>
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)
16 #define EXPECT_IN_SAME_DIR (WCHAR*)0xdead
18 UNICODE_STRING DotDll
= RTL_CONSTANT_STRING(L
".DLL");
23 NTSTATUS ExpectedStatus
;
25 WCHAR
* ExpectedSubString
;
28 struct test_data Tests
[] =
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
}
54 void TestRedirection(void)
56 WCHAR SystemDir
[MAX_PATH
];
57 WCHAR TestPath
[MAX_PATH
];
58 WCHAR ParameterBuffer
[MAX_PATH
];
63 GetSystemDirectoryW(SystemDir
, MAX_PATH
);
64 GetModuleFileNameW(NULL
, TestPath
, MAX_PATH
);
65 separator
= wcsrchr(TestPath
, L
'\\');
69 for (i
= 0; i
< _countof(Tests
); i
++)
71 UNICODE_STRING OriginalName
, DynamicString
;
72 PUNICODE_STRING StringUsed
= NULL
;
74 if (memcmp(Tests
[i
].Param
, L
"c:\\windows\\system32", 38) == 0)
76 wcscpy(ParameterBuffer
, SystemDir
);
77 wcscat(ParameterBuffer
, &Tests
[i
].Param
[19]);
81 wcscpy(ParameterBuffer
, Tests
[i
].Param
);
84 RtlInitUnicodeString(&OriginalName
, ParameterBuffer
);
85 RtlInitEmptyUnicodeString(&DynamicString
, NULL
, 0);
87 Status
= RtlDosApplyFileIsolationRedirection_Ustr(TRUE
,
96 ok(Status
== Tests
[i
].ExpectedStatus
, "%d: Status 0x%lx, expected 0x%lx\n", Tests
[i
].testline
, Status
, Tests
[i
].ExpectedStatus
);
98 if (DynamicString
.Buffer
)
100 BOOL exists
= RtlDoesFileExists_U(DynamicString
.Buffer
);
101 ok(exists
, "%d: Expected file %S to exist!\n", Tests
[i
].testline
, DynamicString
.Buffer
);
104 if(Tests
[i
].ExpectedSubString
&& DynamicString
.Buffer
== NULL
)
106 ok(0, "%d: Expected a returned string\n", Tests
[i
].testline
);
109 if (Tests
[i
].ExpectedSubString
&& DynamicString
.Buffer
!= NULL
)
111 if (Tests
[i
].ExpectedSubString
== EXPECT_IN_SAME_DIR
)
113 ok(wcsstr(DynamicString
.Buffer
, TestPath
) != 0, "%d: Expected string %S in %S\n", Tests
[i
].testline
, TestPath
, DynamicString
.Buffer
);
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
);
124 START_TEST(RtlDosApplyFileIsolationRedirection_Ustr
)
128 argc
= winetest_get_mainargs( &test_argv
);
135 WCHAR TestPath
[MAX_PATH
];
137 STARTUPINFOW si
= { sizeof(si
) };
138 PROCESS_INFORMATION pi
;
141 GetModuleFileNameW(NULL
, TestPath
, MAX_PATH
);
142 separator
= wcsrchr(TestPath
, L
'\\');
144 wcscpy(separator
, L
"testdata\\ntdll_apitest.exe RtlDosApplyFileIsolationRedirection_Ustr DoTest");
146 created
= CreateProcessW(NULL
, TestPath
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
147 ok(created
, "Expected CreateProcess to succeed\n");
150 winetest_wait_child_process(pi
.hProcess
);
151 CloseHandle(pi
.hThread
);
152 CloseHandle(pi
.hProcess
);