tangled
alpha
login
or
join now
huwcampbell.com
/
reactos
0
fork
atom
Reactos
0
fork
atom
overview
issues
pulls
pipelines
[NTDLL_APITEST] Add test for RtlComputePrivatizedDllName_U
Mark Jansen
7 years ago
88cd8d68
e1aae1c6
+239
3 changed files
expand all
collapse all
unified
split
modules
rostests
apitests
ntdll
CMakeLists.txt
RtlComputePrivatizedDllName_U.c
testlist.c
+1
modules/rostests/apitests/ntdll/CMakeLists.txt
reviewed
···
38
38
NtWriteFile.c
39
39
RtlAllocateHeap.c
40
40
RtlBitmap.c
41
41
+
RtlComputePrivatizedDllName_U.c
41
42
RtlCopyMappedMemory.c
42
43
RtlDeleteAce.c
43
44
RtlDetermineDosPathNameType.c
+236
modules/rostests/apitests/ntdll/RtlComputePrivatizedDllName_U.c
reviewed
···
1
1
+
/*
2
2
+
* PROJECT: ReactOS api tests
3
3
+
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4
4
+
* PURPOSE: Test for RtlComputePrivatizedDllName_U
5
5
+
* COPYRIGHT: Copyright 2019 Mark Jansen (mark.jansen@reactos.org)
6
6
+
*/
7
7
+
8
8
+
#include "precomp.h"
9
9
+
10
10
+
11
11
+
static WCHAR ProcessDir[MAX_PATH];
12
12
+
static WCHAR LocalDir[MAX_PATH + 10];
13
13
+
14
14
+
static BOOL InitTestData()
15
15
+
{
16
16
+
static const UNICODE_STRING PathDividerFind = RTL_CONSTANT_STRING(L"\\/");
17
17
+
UNICODE_STRING StrU;
18
18
+
USHORT PathDivider;
19
19
+
20
20
+
GetModuleFileNameW(NULL, ProcessDir, RTL_NUMBER_OF(ProcessDir));
21
21
+
GetModuleFileNameW(NULL, LocalDir, RTL_NUMBER_OF(LocalDir));
22
22
+
23
23
+
RtlInitUnicodeString(&StrU, ProcessDir);
24
24
+
25
25
+
if (!NT_SUCCESS(RtlFindCharInUnicodeString(RTL_FIND_CHAR_IN_UNICODE_STRING_START_AT_END,
26
26
+
&StrU, &PathDividerFind, &PathDivider)))
27
27
+
{
28
28
+
skip("Failed to find path divider\n");
29
29
+
return FALSE;
30
30
+
}
31
31
+
ProcessDir[PathDivider / sizeof(WCHAR) + 1] = UNICODE_NULL;
32
32
+
33
33
+
RtlInitUnicodeString(&StrU, LocalDir);
34
34
+
StrU.MaximumLength = sizeof(LocalDir);
35
35
+
36
36
+
if (!NT_SUCCESS(RtlAppendUnicodeToString(&StrU, L".Local\\")))
37
37
+
{
38
38
+
skip("Failed to append .Local\\\n");
39
39
+
return FALSE;
40
40
+
}
41
41
+
return TRUE;
42
42
+
}
43
43
+
44
44
+
static void ok_strings_(PCUNICODE_STRING RealName, PCUNICODE_STRING LocalName, LPCWSTR DllName, int line)
45
45
+
{
46
46
+
WCHAR ExpectReal[MAX_PATH*2];
47
47
+
WCHAR ExpectLocal[MAX_PATH*2];
48
48
+
int RealLen;
49
49
+
int ExpectLen;
50
50
+
51
51
+
RealLen = swprintf(ExpectReal, L"%s%s", ProcessDir, DllName) * sizeof(WCHAR);
52
52
+
ExpectLen = swprintf(ExpectLocal, L"%s%s", LocalDir, DllName) * sizeof(WCHAR);
53
53
+
54
54
+
ok_(__FILE__, line)(RealLen == RealName->Length, "Expected Real %u, got %u\n",
55
55
+
(UINT)RealLen, (UINT)RealName->Length);
56
56
+
ok_(__FILE__, line)(ExpectLen == LocalName->Length, "Expected Local %u, got %u\n",
57
57
+
(UINT)ExpectLen, (UINT)LocalName->Length);
58
58
+
59
59
+
ok_(__FILE__, line)(!wcscmp(RealName->Buffer, ExpectReal), "Expected Real %s, got %s\n",
60
60
+
wine_dbgstr_w(ExpectReal), wine_dbgstr_w(RealName->Buffer));
61
61
+
ok_(__FILE__, line)(!wcscmp(LocalName->Buffer, ExpectLocal), "Expected Local %s, got %s\n",
62
62
+
wine_dbgstr_w(ExpectLocal), wine_dbgstr_w(LocalName->Buffer));
63
63
+
}
64
64
+
#define ok_strings(Real, Local, Dll) ok_strings_(Real, Local, Dll, __LINE__)
65
65
+
66
66
+
67
67
+
static void cleanup(PUNICODE_STRING String, WCHAR* Buffer, USHORT BufferSize)
68
68
+
{
69
69
+
if (String->Buffer != Buffer)
70
70
+
{
71
71
+
RtlFreeUnicodeString(String);
72
72
+
RtlInitEmptyUnicodeString(String, Buffer, BufferSize);
73
73
+
}
74
74
+
}
75
75
+
76
76
+
77
77
+
static void test_dllnames(void)
78
78
+
{
79
79
+
WCHAR Buf1[MAX_PATH];
80
80
+
WCHAR Buf2[MAX_PATH];
81
81
+
82
82
+
UNICODE_STRING Str1, Str2;
83
83
+
UNICODE_STRING DllName;
84
84
+
NTSTATUS Status;
85
85
+
86
86
+
RtlInitEmptyUnicodeString(&Str1, Buf1, sizeof(Buf1));
87
87
+
RtlInitEmptyUnicodeString(&Str2, Buf2, sizeof(Buf2));
88
88
+
89
89
+
RtlInitUnicodeString(&DllName, L"kernel32.dll");
90
90
+
Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
91
91
+
ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
92
92
+
ok_strings(&Str1, &Str2, L"kernel32.dll");
93
93
+
cleanup(&Str1, Buf1, sizeof(Buf1));
94
94
+
cleanup(&Str2, Buf2, sizeof(Buf2));
95
95
+
96
96
+
97
97
+
RtlInitUnicodeString(&DllName, L"kernel32");
98
98
+
Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
99
99
+
ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
100
100
+
ok_strings(&Str1, &Str2, L"kernel32.DLL");
101
101
+
cleanup(&Str1, Buf1, sizeof(Buf1));
102
102
+
cleanup(&Str2, Buf2, sizeof(Buf2));
103
103
+
104
104
+
RtlInitUnicodeString(&DllName, L"kernel32.dll.dll");
105
105
+
Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
106
106
+
ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
107
107
+
ok_strings(&Str1, &Str2, L"kernel32.dll.dll");
108
108
+
cleanup(&Str1, Buf1, sizeof(Buf1));
109
109
+
cleanup(&Str2, Buf2, sizeof(Buf2));
110
110
+
111
111
+
RtlInitUnicodeString(&DllName, L"kernel32.dll.exe");
112
112
+
Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
113
113
+
ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
114
114
+
ok_strings(&Str1, &Str2, L"kernel32.dll.exe");
115
115
+
cleanup(&Str1, Buf1, sizeof(Buf1));
116
116
+
cleanup(&Str2, Buf2, sizeof(Buf2));
117
117
+
118
118
+
RtlInitUnicodeString(&DllName, L"kernel32.");
119
119
+
Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
120
120
+
ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
121
121
+
ok_strings(&Str1, &Str2, L"kernel32.");
122
122
+
cleanup(&Str1, Buf1, sizeof(Buf1));
123
123
+
cleanup(&Str2, Buf2, sizeof(Buf2));
124
124
+
125
125
+
RtlInitUnicodeString(&DllName, L".kernel32");
126
126
+
Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
127
127
+
ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
128
128
+
ok_strings(&Str1, &Str2, L".kernel32.DLL");
129
129
+
cleanup(&Str1, Buf1, sizeof(Buf1));
130
130
+
cleanup(&Str2, Buf2, sizeof(Buf2));
131
131
+
132
132
+
RtlInitUnicodeString(&DllName, L"..kernel32");
133
133
+
Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
134
134
+
ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
135
135
+
ok_strings(&Str1, &Str2, L"..kernel32");
136
136
+
cleanup(&Str1, Buf1, sizeof(Buf1));
137
137
+
cleanup(&Str2, Buf2, sizeof(Buf2));
138
138
+
139
139
+
RtlInitUnicodeString(&DllName, L".kernel32.");
140
140
+
Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
141
141
+
ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
142
142
+
ok_strings(&Str1, &Str2, L".kernel32.");
143
143
+
cleanup(&Str1, Buf1, sizeof(Buf1));
144
144
+
cleanup(&Str2, Buf2, sizeof(Buf2));
145
145
+
146
146
+
147
147
+
RtlInitUnicodeString(&DllName, L"test\\kernel32.dll");
148
148
+
Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
149
149
+
ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
150
150
+
ok_strings(&Str1, &Str2, L"kernel32.dll");
151
151
+
cleanup(&Str1, Buf1, sizeof(Buf1));
152
152
+
cleanup(&Str2, Buf2, sizeof(Buf2));
153
153
+
154
154
+
RtlInitUnicodeString(&DllName, L"test/kernel32.dll");
155
155
+
Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
156
156
+
ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
157
157
+
ok_strings(&Str1, &Str2, L"kernel32.dll");
158
158
+
cleanup(&Str1, Buf1, sizeof(Buf1));
159
159
+
cleanup(&Str2, Buf2, sizeof(Buf2));
160
160
+
161
161
+
RtlInitUnicodeString(&DllName, L"test.dll/kernel32");
162
162
+
Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
163
163
+
ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
164
164
+
ok_strings(&Str1, &Str2, L"kernel32.DLL");
165
165
+
cleanup(&Str1, Buf1, sizeof(Buf1));
166
166
+
cleanup(&Str2, Buf2, sizeof(Buf2));
167
167
+
168
168
+
RtlInitUnicodeString(&DllName, L"test.dll\\kernel32");
169
169
+
Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
170
170
+
ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
171
171
+
ok_strings(&Str1, &Str2, L"kernel32.DLL");
172
172
+
cleanup(&Str1, Buf1, sizeof(Buf1));
173
173
+
cleanup(&Str2, Buf2, sizeof(Buf2));
174
174
+
175
175
+
RtlInitUnicodeString(&DllName, L"//");
176
176
+
Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
177
177
+
ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
178
178
+
ok_strings(&Str1, &Str2, L".DLL");
179
179
+
cleanup(&Str1, Buf1, sizeof(Buf1));
180
180
+
cleanup(&Str2, Buf2, sizeof(Buf2));
181
181
+
182
182
+
// Bug :)
183
183
+
RtlInitUnicodeString(&DllName, L"\\");
184
184
+
Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
185
185
+
ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
186
186
+
if (wcsstr(Str1.Buffer, L"\\\\"))
187
187
+
{
188
188
+
trace("Allowing bug found in windows' implementation\n");
189
189
+
ok_strings(&Str1, &Str2, L"\\.DLL");
190
190
+
}
191
191
+
else
192
192
+
{
193
193
+
ok_strings(&Str1, &Str2, L".DLL");
194
194
+
}
195
195
+
cleanup(&Str1, Buf1, sizeof(Buf1));
196
196
+
cleanup(&Str2, Buf2, sizeof(Buf2));
197
197
+
198
198
+
RtlInitUnicodeString(&DllName, L"");
199
199
+
Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
200
200
+
ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
201
201
+
ok_strings(&Str1, &Str2, L".DLL");
202
202
+
cleanup(&Str1, Buf1, sizeof(Buf1));
203
203
+
cleanup(&Str2, Buf2, sizeof(Buf2));
204
204
+
}
205
205
+
206
206
+
static void test_allocations(void)
207
207
+
{
208
208
+
WCHAR Buf1[10];
209
209
+
WCHAR Buf2[10];
210
210
+
211
211
+
UNICODE_STRING Str1, Str2;
212
212
+
UNICODE_STRING DllName;
213
213
+
NTSTATUS Status;
214
214
+
215
215
+
RtlInitEmptyUnicodeString(&Str1, Buf1, sizeof(Buf1));
216
216
+
RtlInitEmptyUnicodeString(&Str2, Buf2, sizeof(Buf2));
217
217
+
218
218
+
RtlInitUnicodeString(&DllName, L"kernel32.dll");
219
219
+
Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
220
220
+
ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
221
221
+
ok_strings(&Str1, &Str2, L"kernel32.dll");
222
222
+
ok(Str1.Buffer != Buf1, "Expected a changed buffer\n");
223
223
+
ok(Str2.Buffer != Buf2, "Expected a changed buffer\n");
224
224
+
cleanup(&Str1, Buf1, sizeof(Buf1));
225
225
+
cleanup(&Str2, Buf2, sizeof(Buf2));
226
226
+
}
227
227
+
228
228
+
229
229
+
START_TEST(RtlComputePrivatizedDllName_U)
230
230
+
{
231
231
+
if (!InitTestData())
232
232
+
return;
233
233
+
234
234
+
test_dllnames();
235
235
+
test_allocations();
236
236
+
}
+2
modules/rostests/apitests/ntdll/testlist.c
reviewed
···
37
37
extern void func_NtWriteFile(void);
38
38
extern void func_RtlAllocateHeap(void);
39
39
extern void func_RtlBitmap(void);
40
40
+
extern void func_RtlComputePrivatizedDllName_U(void);
40
41
extern void func_RtlCopyMappedMemory(void);
41
42
extern void func_RtlDeleteAce(void);
42
43
extern void func_RtlDetermineDosPathNameType(void);
···
102
103
{ "NtWriteFile", func_NtWriteFile },
103
104
{ "RtlAllocateHeap", func_RtlAllocateHeap },
104
105
{ "RtlBitmapApi", func_RtlBitmap },
106
106
+
{ "RtlComputePrivatizedDllName_U", func_RtlComputePrivatizedDllName_U },
105
107
{ "RtlCopyMappedMemory", func_RtlCopyMappedMemory },
106
108
{ "RtlDeleteAce", func_RtlDeleteAce },
107
109
{ "RtlDetermineDosPathNameType", func_RtlDetermineDosPathNameType },