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
},
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
}
56 void TestRedirection(void)
58 WCHAR SystemDir
[MAX_PATH
];
59 WCHAR TestPath
[MAX_PATH
];
60 WCHAR ParameterBuffer
[MAX_PATH
];
65 GetSystemDirectoryW(SystemDir
, MAX_PATH
);
66 GetModuleFileNameW(NULL
, TestPath
, MAX_PATH
);
67 separator
= wcsrchr(TestPath
, L
'\\');
71 for (i
= 0; i
< _countof(Tests
); i
++)
73 UNICODE_STRING OriginalName
, DynamicString
;
74 PUNICODE_STRING StringUsed
= NULL
;
76 if (memcmp(Tests
[i
].Param
, L
"c:\\windows\\system32", 38) == 0)
78 wcscpy(ParameterBuffer
, SystemDir
);
79 wcscat(ParameterBuffer
, &Tests
[i
].Param
[19]);
83 wcscpy(ParameterBuffer
, Tests
[i
].Param
);
86 RtlInitUnicodeString(&OriginalName
, ParameterBuffer
);
87 RtlInitEmptyUnicodeString(&DynamicString
, NULL
, 0);
89 Status
= RtlDosApplyFileIsolationRedirection_Ustr(TRUE
,
98 ok(Status
== Tests
[i
].ExpectedStatus
, "Status 0x%lx, expected 0x%lx\n", value
, expected
)
99 ok_eq_hex(Status
, Tests
[i
].ExpectedStatus
);
101 if (DynamicString
.Buffer
)
103 BOOL exists
= RtlDoesFileExists_U(DynamicString
.Buffer
);
104 ok(exists
, "%d: Expected file %S to exist!\n", Tests
[i
].testline
, DynamicString
.Buffer
);
107 if(Tests
[i
].ExpectedSubString
&& DynamicString
.Buffer
== NULL
)
109 ok(0, "%d: Expected a returned string\n", Tests
[i
].testline
);
112 if (Tests
[i
].ExpectedSubString
&& DynamicString
.Buffer
!= NULL
)
114 if (Tests
[i
].ExpectedSubString
== EXPECT_IN_SAME_DIR
)
116 ok(wcsstr(DynamicString
.Buffer
, TestPath
) != 0, "%d: Expected string %S in %S\n", Tests
[i
].testline
, TestPath
, DynamicString
.Buffer
);
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
);
127 START_TEST(RtlDosApplyFileIsolationRedirection_Ustr
)
130 WCHAR TestPath
[MAX_PATH
];
132 STARTUPINFOW si
= { sizeof(si
) };
133 PROCESS_INFORMATION pi
;
137 /* Create .local files */
138 GetModuleFileNameW(NULL
, TestPath
, MAX_PATH
);
140 wcscat(TestPath
, L
".local");
141 file
= CreateFileW(TestPath
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_FLAG_NO_BUFFERING
, NULL
);
143 separator
= wcsrchr(TestPath
, L
'\\');
145 wcscpy(separator
, L
"test.dll");
146 file
= CreateFileW(TestPath
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_FLAG_NO_BUFFERING
, NULL
);
148 wcscpy(separator
, L
"shell32.dll");
149 file
= CreateFileW(TestPath
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_FLAG_NO_BUFFERING
, NULL
);
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
);