Move and reshuffle reactos/regtetsts into rostests. 1/2
[reactos.git] / rostests / winetests / ntdll / rtlstr.c
1 /* Unit test suite for Rtl string functions
2 *
3 * Copyright 2002 Robert Shearman
4 * Copyright 2003 Thomas Mertes
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 *
20 * NOTES
21 * We use function pointers here as there is no import library for NTDLL on
22 * windows.
23 */
24
25 #include <stdlib.h>
26
27 #define INITGUID
28
29 #include "ntdll_test.h"
30 #include "winnls.h"
31 #include "guiddef.h"
32
33 /* Function ptrs for ntdll calls */
34 static HMODULE hntdll = 0;
35 static NTSTATUS (WINAPI *pRtlAnsiStringToUnicodeString)(PUNICODE_STRING, PCANSI_STRING, BOOLEAN);
36 static NTSTATUS (WINAPI *pRtlAppendAsciizToString)(STRING *, LPCSTR);
37 static NTSTATUS (WINAPI *pRtlAppendStringToString)(STRING *, const STRING *);
38 static NTSTATUS (WINAPI *pRtlAppendUnicodeStringToString)(UNICODE_STRING *, const UNICODE_STRING *);
39 static NTSTATUS (WINAPI *pRtlAppendUnicodeToString)(UNICODE_STRING *, LPCWSTR);
40 static NTSTATUS (WINAPI *pRtlCharToInteger)(PCSZ, ULONG, int *);
41 static VOID (WINAPI *pRtlCopyString)(STRING *, const STRING *);
42 static BOOLEAN (WINAPI *pRtlCreateUnicodeString)(PUNICODE_STRING, LPCWSTR);
43 static BOOLEAN (WINAPI *pRtlCreateUnicodeStringFromAsciiz)(PUNICODE_STRING, LPCSTR);
44 static NTSTATUS (WINAPI *pRtlDowncaseUnicodeString)(UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN);
45 static NTSTATUS (WINAPI *pRtlDuplicateUnicodeString)(long, UNICODE_STRING *, UNICODE_STRING *);
46 static BOOLEAN (WINAPI *pRtlEqualUnicodeString)(const UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN);
47 static NTSTATUS (WINAPI *pRtlFindCharInUnicodeString)(int, const UNICODE_STRING *, const UNICODE_STRING *, USHORT *);
48 static VOID (WINAPI *pRtlFreeAnsiString)(PSTRING);
49 static VOID (WINAPI *pRtlInitAnsiString)(PSTRING, LPCSTR);
50 static VOID (WINAPI *pRtlInitString)(PSTRING, LPCSTR);
51 static VOID (WINAPI *pRtlInitUnicodeString)(PUNICODE_STRING, LPCWSTR);
52 static NTSTATUS (WINAPI *pRtlInitUnicodeStringEx)(PUNICODE_STRING, LPCWSTR);
53 static NTSTATUS (WINAPI *pRtlIntegerToChar)(ULONG, ULONG, ULONG, PCHAR);
54 static NTSTATUS (WINAPI *pRtlIntegerToUnicodeString)(ULONG, ULONG, UNICODE_STRING *);
55 static NTSTATUS (WINAPI *pRtlMultiAppendUnicodeStringBuffer)(UNICODE_STRING *, long, UNICODE_STRING *);
56 static NTSTATUS (WINAPI *pRtlUnicodeStringToAnsiString)(STRING *, const UNICODE_STRING *, BOOLEAN);
57 static NTSTATUS (WINAPI *pRtlUnicodeStringToInteger)(const UNICODE_STRING *, int, int *);
58 static WCHAR (WINAPI *pRtlUpcaseUnicodeChar)(WCHAR);
59 static NTSTATUS (WINAPI *pRtlUpcaseUnicodeString)(UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN);
60 static CHAR (WINAPI *pRtlUpperChar)(CHAR);
61 static NTSTATUS (WINAPI *pRtlUpperString)(STRING *, const STRING *);
62 static NTSTATUS (WINAPI *pRtlValidateUnicodeString)(long, UNICODE_STRING *);
63 static NTSTATUS (WINAPI *pRtlGUIDFromString)(const UNICODE_STRING*,GUID*);
64 static NTSTATUS (WINAPI *pRtlStringFromGUID)(const GUID*, UNICODE_STRING*);
65
66 /*static VOID (WINAPI *pRtlFreeOemString)(PSTRING);*/
67 /*static VOID (WINAPI *pRtlFreeUnicodeString)(PUNICODE_STRING);*/
68 /*static VOID (WINAPI *pRtlCopyUnicodeString)(UNICODE_STRING *, const UNICODE_STRING *);*/
69 /*static VOID (WINAPI *pRtlEraseUnicodeString)(UNICODE_STRING *);*/
70 /*static LONG (WINAPI *pRtlCompareString)(const STRING *,const STRING *,BOOLEAN);*/
71 /*static LONG (WINAPI *pRtlCompareUnicodeString)(const UNICODE_STRING *,const UNICODE_STRING *,BOOLEAN);*/
72 /*static BOOLEAN (WINAPI *pRtlEqualString)(const STRING *,const STRING *,BOOLEAN);*/
73 /*static BOOLEAN (WINAPI *pRtlPrefixString)(const STRING *, const STRING *, BOOLEAN);*/
74 /*static BOOLEAN (WINAPI *pRtlPrefixUnicodeString)(const UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN);*/
75 /*static NTSTATUS (WINAPI *pRtlOemStringToUnicodeString)(PUNICODE_STRING, const STRING *, BOOLEAN);*/
76 /*static NTSTATUS (WINAPI *pRtlUnicodeStringToOemString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/
77 /*static NTSTATUS (WINAPI *pRtlMultiByteToUnicodeN)(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD);*/
78 /*static NTSTATUS (WINAPI *pRtlOemToUnicodeN)(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD);*/
79 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeStringToAnsiString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/
80 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeStringToOemString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/
81 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeToMultiByteN)(LPSTR, DWORD, LPDWORD, LPCWSTR, DWORD);*/
82 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeToOemN)(LPSTR, DWORD, LPDWORD, LPCWSTR, DWORD);*/
83 /*static UINT (WINAPI *pRtlOemToUnicodeSize)(const STRING *);*/
84 /*static DWORD (WINAPI *pRtlAnsiStringToUnicodeSize)(const STRING *);*/
85 /*static DWORD (WINAPI *pRtlIsTextUnicode)(LPVOID, DWORD, DWORD *);*/
86
87
88 static WCHAR* AtoW( const char* p )
89 {
90 WCHAR* buffer;
91 DWORD len = MultiByteToWideChar( CP_ACP, 0, p, -1, NULL, 0 );
92 buffer = malloc( len * sizeof(WCHAR) );
93 MultiByteToWideChar( CP_ACP, 0, p, -1, buffer, len );
94 return buffer;
95 }
96
97
98 static void InitFunctionPtrs(void)
99 {
100 hntdll = LoadLibraryA("ntdll.dll");
101 ok(hntdll != 0, "LoadLibrary failed\n");
102 if (hntdll) {
103 pRtlAnsiStringToUnicodeString = (void *)GetProcAddress(hntdll, "RtlAnsiStringToUnicodeString");
104 pRtlAppendAsciizToString = (void *)GetProcAddress(hntdll, "RtlAppendAsciizToString");
105 pRtlAppendStringToString = (void *)GetProcAddress(hntdll, "RtlAppendStringToString");
106 pRtlAppendUnicodeStringToString = (void *)GetProcAddress(hntdll, "RtlAppendUnicodeStringToString");
107 pRtlAppendUnicodeToString = (void *)GetProcAddress(hntdll, "RtlAppendUnicodeToString");
108 pRtlCharToInteger = (void *)GetProcAddress(hntdll, "RtlCharToInteger");
109 pRtlCopyString = (void *)GetProcAddress(hntdll, "RtlCopyString");
110 pRtlCreateUnicodeString = (void *)GetProcAddress(hntdll, "RtlCreateUnicodeString");
111 pRtlCreateUnicodeStringFromAsciiz = (void *)GetProcAddress(hntdll, "RtlCreateUnicodeStringFromAsciiz");
112 pRtlDowncaseUnicodeString = (void *)GetProcAddress(hntdll, "RtlDowncaseUnicodeString");
113 pRtlDuplicateUnicodeString = (void *)GetProcAddress(hntdll, "RtlDuplicateUnicodeString");
114 pRtlEqualUnicodeString = (void *)GetProcAddress(hntdll, "RtlEqualUnicodeString");
115 pRtlFindCharInUnicodeString = (void *)GetProcAddress(hntdll, "RtlFindCharInUnicodeString");
116 pRtlFreeAnsiString = (void *)GetProcAddress(hntdll, "RtlFreeAnsiString");
117 pRtlInitAnsiString = (void *)GetProcAddress(hntdll, "RtlInitAnsiString");
118 pRtlInitString = (void *)GetProcAddress(hntdll, "RtlInitString");
119 pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
120 pRtlInitUnicodeStringEx = (void *)GetProcAddress(hntdll, "RtlInitUnicodeStringEx");
121 pRtlIntegerToChar = (void *)GetProcAddress(hntdll, "RtlIntegerToChar");
122 pRtlIntegerToUnicodeString = (void *)GetProcAddress(hntdll, "RtlIntegerToUnicodeString");
123 pRtlMultiAppendUnicodeStringBuffer = (void *)GetProcAddress(hntdll, "RtlMultiAppendUnicodeStringBuffer");
124 pRtlUnicodeStringToAnsiString = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToAnsiString");
125 pRtlUnicodeStringToInteger = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToInteger");
126 pRtlUpcaseUnicodeChar = (void *)GetProcAddress(hntdll, "RtlUpcaseUnicodeChar");
127 pRtlUpcaseUnicodeString = (void *)GetProcAddress(hntdll, "RtlUpcaseUnicodeString");
128 pRtlUpperChar = (void *)GetProcAddress(hntdll, "RtlUpperChar");
129 pRtlUpperString = (void *)GetProcAddress(hntdll, "RtlUpperString");
130 pRtlValidateUnicodeString = (void *)GetProcAddress(hntdll, "RtlValidateUnicodeString");
131 pRtlGUIDFromString = (void *)GetProcAddress(hntdll, "RtlGUIDFromString");
132 pRtlStringFromGUID = (void *)GetProcAddress(hntdll, "RtlStringFromGUID");
133 }
134 }
135
136
137 static void test_RtlInitString(void)
138 {
139 static const char teststring[] = "Some Wild String";
140 STRING str;
141
142 str.Length = 0;
143 str.MaximumLength = 0;
144 str.Buffer = (void *)0xdeadbeef;
145 pRtlInitString(&str, teststring);
146 ok(str.Length == sizeof(teststring) - sizeof(char), "Length uninitialized\n");
147 ok(str.MaximumLength == sizeof(teststring), "MaximumLength uninitialized\n");
148 ok(str.Buffer == teststring, "Buffer not equal to teststring\n");
149 ok(strcmp(str.Buffer, "Some Wild String") == 0, "Buffer written to\n");
150 pRtlInitString(&str, NULL);
151 ok(str.Length == 0, "Length uninitialized\n");
152 ok(str.MaximumLength == 0, "MaximumLength uninitialized\n");
153 ok(str.Buffer == NULL, "Buffer not equal to NULL\n");
154 /* pRtlInitString(NULL, teststring); */
155 }
156
157
158 static void test_RtlInitUnicodeString(void)
159 {
160 #define STRINGW {'S','o','m','e',' ','W','i','l','d',' ','S','t','r','i','n','g',0}
161 static const WCHAR teststring[] = STRINGW;
162 static const WCHAR originalstring[] = STRINGW;
163 #undef STRINGW
164 UNICODE_STRING uni;
165
166 uni.Length = 0;
167 uni.MaximumLength = 0;
168 uni.Buffer = (void *)0xdeadbeef;
169 pRtlInitUnicodeString(&uni, teststring);
170 ok(uni.Length == sizeof(teststring) - sizeof(WCHAR), "Length uninitialized\n");
171 ok(uni.MaximumLength == sizeof(teststring), "MaximumLength uninitialized\n");
172 ok(uni.Buffer == teststring, "Buffer not equal to teststring\n");
173 ok(lstrcmpW(uni.Buffer, originalstring) == 0, "Buffer written to\n");
174 pRtlInitUnicodeString(&uni, NULL);
175 ok(uni.Length == 0, "Length uninitialized\n");
176 ok(uni.MaximumLength == 0, "MaximumLength uninitialized\n");
177 ok(uni.Buffer == NULL, "Buffer not equal to NULL\n");
178 /* pRtlInitUnicodeString(NULL, teststring); */
179 }
180
181
182 #define TESTSTRING2_LEN 1000000
183 /* #define TESTSTRING2_LEN 32766 */
184
185
186 static void test_RtlInitUnicodeStringEx(void)
187 {
188 static const WCHAR teststring[] = {'S','o','m','e',' ','W','i','l','d',' ','S','t','r','i','n','g',0};
189 WCHAR *teststring2;
190 UNICODE_STRING uni;
191 NTSTATUS result;
192
193 teststring2 = (WCHAR *) malloc((TESTSTRING2_LEN + 1) * sizeof(WCHAR));
194 memset(teststring2, 'X', TESTSTRING2_LEN * sizeof(WCHAR));
195 teststring2[TESTSTRING2_LEN] = '\0';
196
197 uni.Length = 12345;
198 uni.MaximumLength = 12345;
199 uni.Buffer = (void *) 0xdeadbeef;
200 result = pRtlInitUnicodeStringEx(&uni, teststring);
201 ok(result == STATUS_SUCCESS,
202 "pRtlInitUnicodeStringEx(&uni, 0) returns %lx, expected 0\n",
203 result);
204 ok(uni.Length == 32,
205 "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected %u\n",
206 uni.Length, 32);
207 ok(uni.MaximumLength == 34,
208 "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected %u\n",
209 uni.MaximumLength, 34);
210 ok(uni.Buffer == teststring,
211 "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %p\n",
212 uni.Buffer, teststring);
213
214 uni.Length = 12345;
215 uni.MaximumLength = 12345;
216 uni.Buffer = (void *) 0xdeadbeef;
217 pRtlInitUnicodeString(&uni, teststring);
218 ok(uni.Length == 32,
219 "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u\n",
220 uni.Length, 32);
221 ok(uni.MaximumLength == 34,
222 "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u\n",
223 uni.MaximumLength, 34);
224 ok(uni.Buffer == teststring,
225 "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p\n",
226 uni.Buffer, teststring);
227
228 uni.Length = 12345;
229 uni.MaximumLength = 12345;
230 uni.Buffer = (void *) 0xdeadbeef;
231 result = pRtlInitUnicodeStringEx(&uni, teststring2);
232 ok(result == STATUS_NAME_TOO_LONG,
233 "pRtlInitUnicodeStringEx(&uni, 0) returns %lx, expected %lx\n",
234 result, STATUS_NAME_TOO_LONG);
235 ok(uni.Length == 12345,
236 "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected %u\n",
237 uni.Length, 12345);
238 ok(uni.MaximumLength == 12345,
239 "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected %u\n",
240 uni.MaximumLength, 12345);
241 ok(uni.Buffer == (void *) 0xdeadbeef,
242 "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %x\n",
243 uni.Buffer, 0xdeadbeef);
244
245 uni.Length = 12345;
246 uni.MaximumLength = 12345;
247 uni.Buffer = (void *) 0xdeadbeef;
248 pRtlInitUnicodeString(&uni, teststring2);
249 ok(uni.Length == 33920,
250 "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u\n",
251 uni.Length, 33920);
252 ok(uni.MaximumLength == 33922,
253 "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u\n",
254 uni.MaximumLength, 33922);
255 ok(uni.Buffer == teststring2,
256 "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p\n",
257 uni.Buffer, teststring2);
258 ok(memcmp(uni.Buffer, teststring2, (TESTSTRING2_LEN + 1) * sizeof(WCHAR)) == 0,
259 "pRtlInitUnicodeString(&uni, 0) changes Buffer\n");
260
261 uni.Length = 12345;
262 uni.MaximumLength = 12345;
263 uni.Buffer = (void *) 0xdeadbeef;
264 result = pRtlInitUnicodeStringEx(&uni, 0);
265 ok(result == STATUS_SUCCESS,
266 "pRtlInitUnicodeStringEx(&uni, 0) returns %lx, expected 0\n",
267 result);
268 ok(uni.Length == 0,
269 "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected %u\n",
270 uni.Length, 0);
271 ok(uni.MaximumLength == 0,
272 "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected %u\n",
273 uni.MaximumLength, 0);
274 ok(uni.Buffer == NULL,
275 "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %p\n",
276 uni.Buffer, NULL);
277
278 uni.Length = 12345;
279 uni.MaximumLength = 12345;
280 uni.Buffer = (void *) 0xdeadbeef;
281 pRtlInitUnicodeString(&uni, 0);
282 ok(uni.Length == 0,
283 "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u\n",
284 uni.Length, 0);
285 ok(uni.MaximumLength == 0,
286 "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u\n",
287 uni.MaximumLength, 0);
288 ok(uni.Buffer == NULL,
289 "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p\n",
290 uni.Buffer, NULL);
291 }
292
293
294 typedef struct {
295 int add_nul;
296 int source_Length;
297 int source_MaximumLength;
298 int source_buf_size;
299 const char *source_buf;
300 int dest_Length;
301 int dest_MaximumLength;
302 int dest_buf_size;
303 const char *dest_buf;
304 int res_Length;
305 int res_MaximumLength;
306 int res_buf_size;
307 const char *res_buf;
308 NTSTATUS result;
309 } dupl_ustr_t;
310
311 static const dupl_ustr_t dupl_ustr[] = {
312 { 0, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 32, 32, "This is a string", STATUS_SUCCESS},
313 { 0, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 32, 32, "This is a string", STATUS_SUCCESS},
314 { 0, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
315 { 0, 32, 34, 34, "This is a string", 40, 42, 42, NULL, 32, 32, 32, "This is a string", STATUS_SUCCESS},
316 { 0, 32, 32, 32, "This is a string", 40, 42, 42, NULL, 32, 32, 32, "This is a string", STATUS_SUCCESS},
317 { 0, 32, 30, 34, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
318 { 1, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS},
319 { 1, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS},
320 { 1, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
321 { 1, 32, 34, 34, "This is a string", 40, 42, 42, NULL, 32, 34, 34, "This is a string", STATUS_SUCCESS},
322 { 1, 32, 32, 32, "This is a string", 40, 42, 42, NULL, 32, 34, 34, "This is a string", STATUS_SUCCESS},
323 { 1, 32, 30, 34, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
324 { 2, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
325 { 2, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
326 { 2, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
327 { 2, 32, 34, 34, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
328 { 2, 32, 32, 32, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
329 { 2, 32, 30, 34, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
330 { 3, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS},
331 { 3, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS},
332 { 3, 32, 30, 32, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
333 { 3, 32, 34, 34, "This is a string", 40, 42, 42, NULL, 32, 34, 34, "This is a string", STATUS_SUCCESS},
334 { 3, 32, 32, 32, "This is a string", 40, 42, 42, NULL, 32, 34, 34, "This is a string", STATUS_SUCCESS},
335 { 3, 32, 30, 32, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
336 { 4, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
337 { 5, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
338 { 6, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
339 { 7, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
340 { 8, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
341 { 9, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
342 {10, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
343 {11, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
344 {12, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
345 {13, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
346 {14, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
347 {15, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
348 {16, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
349 {-1, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
350 {-5, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
351 {-9, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
352 { 0, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
353 { 0, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
354 { 0, 0, 2, 2, "", 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
355 { 0, 0, 0, 0, "", 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
356 { 0, 0, 2, 2, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
357 { 0, 0, 0, 0, NULL, 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
358 { 0, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
359 { 0, 0, 0, 0, NULL, 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
360 { 1, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
361 { 1, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
362 { 1, 0, 2, 2, "", 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
363 { 1, 0, 0, 0, "", 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
364 { 1, 0, 2, 2, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
365 { 1, 0, 0, 0, NULL, 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
366 { 1, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
367 { 1, 0, 0, 0, NULL, 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
368 { 2, 0, 2, 2, "", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
369 { 2, 0, 0, 0, "", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
370 { 2, 0, 2, 2, "", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
371 { 2, 0, 0, 0, "", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
372 { 2, 0, 2, 2, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
373 { 2, 0, 0, 0, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
374 { 2, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
375 { 2, 0, 0, 0, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
376 { 3, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS},
377 { 3, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS},
378 { 3, 0, 2, 2, "", 40, 42, 42, NULL, 0, 2, 2, "", STATUS_SUCCESS},
379 { 3, 0, 0, 0, "", 40, 42, 42, NULL, 0, 2, 2, "", STATUS_SUCCESS},
380 { 3, 0, 2, 2, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
381 { 3, 0, 0, 0, NULL, 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS},
382 { 3, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
383 { 3, 0, 0, 0, NULL, 40, 42, 42, NULL, 0, 2, 2, "", STATUS_SUCCESS},
384 };
385 #define NB_DUPL_USTR (sizeof(dupl_ustr)/sizeof(*dupl_ustr))
386
387
388 static void test_RtlDuplicateUnicodeString(void)
389 {
390 size_t pos;
391 WCHAR source_buf[257];
392 WCHAR dest_buf[257];
393 WCHAR res_buf[257];
394 UNICODE_STRING source_str;
395 UNICODE_STRING dest_str;
396 UNICODE_STRING res_str;
397 CHAR dest_ansi_buf[257];
398 STRING dest_ansi_str;
399 NTSTATUS result;
400 size_t test_num;
401
402 for (test_num = 0; test_num < NB_DUPL_USTR; test_num++) {
403 source_str.Length = dupl_ustr[test_num].source_Length;
404 source_str.MaximumLength = dupl_ustr[test_num].source_MaximumLength;
405 if (dupl_ustr[test_num].source_buf != NULL) {
406 for (pos = 0; pos < dupl_ustr[test_num].source_buf_size/sizeof(WCHAR); pos++) {
407 source_buf[pos] = dupl_ustr[test_num].source_buf[pos];
408 }
409 source_str.Buffer = source_buf;
410 } else {
411 source_str.Buffer = NULL;
412 }
413 dest_str.Length = dupl_ustr[test_num].dest_Length;
414 dest_str.MaximumLength = dupl_ustr[test_num].dest_MaximumLength;
415 if (dupl_ustr[test_num].dest_buf != NULL) {
416 for (pos = 0; pos < dupl_ustr[test_num].dest_buf_size/sizeof(WCHAR); pos++) {
417 dest_buf[pos] = dupl_ustr[test_num].dest_buf[pos];
418 }
419 dest_str.Buffer = dest_buf;
420 } else {
421 dest_str.Buffer = NULL;
422 }
423 res_str.Length = dupl_ustr[test_num].res_Length;
424 res_str.MaximumLength = dupl_ustr[test_num].res_MaximumLength;
425 if (dupl_ustr[test_num].res_buf != NULL) {
426 for (pos = 0; pos < dupl_ustr[test_num].res_buf_size/sizeof(WCHAR); pos++) {
427 res_buf[pos] = dupl_ustr[test_num].res_buf[pos];
428 }
429 res_str.Buffer = res_buf;
430 } else {
431 res_str.Buffer = NULL;
432 }
433 result = pRtlDuplicateUnicodeString(dupl_ustr[test_num].add_nul, &source_str, &dest_str);
434 dest_ansi_str.Length = dest_str.Length / sizeof(WCHAR);
435 dest_ansi_str.MaximumLength = dest_ansi_str.Length + 1;
436 for (pos = 0; pos < dest_ansi_str.Length; pos++) {
437 dest_ansi_buf[pos] = (char)dest_buf[pos];
438 }
439 dest_ansi_buf[dest_ansi_str.Length] = '\0';
440 dest_ansi_str.Buffer = dest_ansi_buf;
441 ok(result == dupl_ustr[test_num].result,
442 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has result %lx, expected %lx\n",
443 test_num, dupl_ustr[test_num].add_nul, result, dupl_ustr[test_num].result);
444 ok(dest_str.Length == dupl_ustr[test_num].res_Length,
445 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination has Length %d, expected %d\n",
446 test_num, dupl_ustr[test_num].add_nul, dest_str.Length, dupl_ustr[test_num].res_Length);
447 ok(dest_str.MaximumLength == dupl_ustr[test_num].res_MaximumLength,
448 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination has MaximumLength %d, expected %d\n",
449 test_num, dupl_ustr[test_num].add_nul, dest_str.MaximumLength, dupl_ustr[test_num].res_MaximumLength);
450 if (result == STATUS_INVALID_PARAMETER) {
451 ok((dest_str.Buffer == NULL && res_str.Buffer == NULL) ||
452 dest_str.Buffer == dest_buf,
453 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination buffer changed %p expected %p\n",
454 test_num, dupl_ustr[test_num].add_nul, dest_str.Buffer, dest_buf);
455 } else {
456 ok(dest_str.Buffer != dest_buf,
457 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination buffer unchanged %p\n",
458 test_num, dupl_ustr[test_num].add_nul, dest_str.Buffer);
459 }
460 if (dest_str.Buffer != NULL && dupl_ustr[test_num].res_buf != NULL) {
461 ok(memcmp(dest_str.Buffer, res_str.Buffer, dupl_ustr[test_num].res_buf_size) == 0,
462 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination \"%s\" expected \"%s\"\n",
463 test_num, dupl_ustr[test_num].add_nul, dest_ansi_str.Buffer, dupl_ustr[test_num].res_buf);
464 } else {
465 ok(dest_str.Buffer == NULL && dupl_ustr[test_num].res_buf == NULL,
466 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination %p expected %p\n",
467 test_num, dupl_ustr[test_num].add_nul, dest_str.Buffer, dupl_ustr[test_num].res_buf);
468 }
469 }
470 }
471
472
473 static void test_RtlCopyString(void)
474 {
475 static const char teststring[] = "Some Wild String";
476 char deststring[] = " ";
477 STRING str;
478 STRING deststr;
479
480 pRtlInitString(&str, teststring);
481 pRtlInitString(&deststr, deststring);
482 pRtlCopyString(&deststr, &str);
483 ok(strncmp(str.Buffer, deststring, str.Length) == 0, "String not copied\n");
484 }
485
486
487 static void test_RtlUpperChar(void)
488 {
489 int ch;
490 int upper_ch;
491 int expected_upper_ch;
492 int byte_ch;
493
494 for (ch = -1; ch <= 1024; ch++) {
495 upper_ch = pRtlUpperChar(ch);
496 byte_ch = ch & 0xff;
497 if (byte_ch >= 'a' && byte_ch <= 'z') {
498 expected_upper_ch = (CHAR) (byte_ch - 'a' + 'A');
499 } else {
500 expected_upper_ch = (CHAR) byte_ch;
501 }
502 ok(upper_ch == expected_upper_ch,
503 "RtlUpperChar('%c'[=0x%x]) has result '%c'[=0x%x], expected '%c'[=0x%x]\n",
504 ch, ch, upper_ch, upper_ch, expected_upper_ch, expected_upper_ch);
505 }
506 }
507
508
509 static void test_RtlUpperString(void)
510 {
511 int i;
512 CHAR ch;
513 CHAR upper_ch;
514 char ascii_buf[257];
515 char result_buf[257];
516 char upper_buf[257];
517 STRING ascii_str;
518 STRING result_str;
519 STRING upper_str;
520
521 for (i = 0; i <= 255; i++) {
522 ch = (CHAR) i;
523 if (ch >= 'a' && ch <= 'z') {
524 upper_ch = ch - 'a' + 'A';
525 } else {
526 upper_ch = ch;
527 }
528 ascii_buf[i] = ch;
529 result_buf[i] = '\0';
530 upper_buf[i] = upper_ch;
531 }
532 ascii_buf[i] = '\0';
533 result_buf[i] = '\0';
534 upper_buf[i] = '\0';
535 ascii_str.Length = 256;
536 ascii_str.MaximumLength = 256;
537 ascii_str.Buffer = ascii_buf;
538 result_str.Length = 256;
539 result_str.MaximumLength = 256;
540 result_str.Buffer = result_buf;
541 upper_str.Length = 256;
542 upper_str.MaximumLength = 256;
543 upper_str.Buffer = upper_buf;
544
545 pRtlUpperString(&result_str, &ascii_str);
546 ok(memcmp(result_str.Buffer, upper_str.Buffer, 256) == 0,
547 "RtlUpperString does not work as expected\n");
548 }
549
550
551 static void test_RtlUpcaseUnicodeChar(void)
552 {
553 int i;
554 WCHAR ch;
555 WCHAR upper_ch;
556 WCHAR expected_upper_ch;
557
558 for (i = 0; i <= 255; i++) {
559 ch = (WCHAR) i;
560 upper_ch = pRtlUpcaseUnicodeChar(ch);
561 if (ch >= 'a' && ch <= 'z') {
562 expected_upper_ch = ch - 'a' + 'A';
563 } else if (ch >= 0xe0 && ch <= 0xfe && ch != 0xf7) {
564 expected_upper_ch = ch - 0x20;
565 } else if (ch == 0xff) {
566 expected_upper_ch = 0x178;
567 } else {
568 expected_upper_ch = ch;
569 }
570 ok(upper_ch == expected_upper_ch,
571 "RtlUpcaseUnicodeChar('%c'[=0x%x]) has result '%c'[=0x%x], expected: '%c'[=0x%x]\n",
572 ch, ch, upper_ch, upper_ch, expected_upper_ch, expected_upper_ch);
573 }
574 }
575
576
577 static void test_RtlUpcaseUnicodeString(void)
578 {
579 int i;
580 WCHAR ch;
581 WCHAR upper_ch;
582 WCHAR ascii_buf[257];
583 WCHAR result_buf[257];
584 WCHAR upper_buf[257];
585 UNICODE_STRING ascii_str;
586 UNICODE_STRING result_str;
587 UNICODE_STRING upper_str;
588
589 for (i = 0; i <= 255; i++) {
590 ch = (WCHAR) i;
591 if (ch >= 'a' && ch <= 'z') {
592 upper_ch = ch - 'a' + 'A';
593 } else if (ch >= 0xe0 && ch <= 0xfe && ch != 0xf7) {
594 upper_ch = ch - 0x20;
595 } else if (ch == 0xff) {
596 upper_ch = 0x178;
597 } else {
598 upper_ch = ch;
599 }
600 ascii_buf[i] = ch;
601 result_buf[i] = '\0';
602 upper_buf[i] = upper_ch;
603 }
604 ascii_buf[i] = '\0';
605 result_buf[i] = '\0';
606 upper_buf[i] = '\0';
607 ascii_str.Length = 512;
608 ascii_str.MaximumLength = 512;
609 ascii_str.Buffer = ascii_buf;
610 result_str.Length = 512;
611 result_str.MaximumLength = 512;
612 result_str.Buffer = result_buf;
613 upper_str.Length = 512;
614 upper_str.MaximumLength = 512;
615 upper_str.Buffer = upper_buf;
616
617 pRtlUpcaseUnicodeString(&result_str, &ascii_str, 0);
618 for (i = 0; i <= 255; i++) {
619 ok(result_str.Buffer[i] == upper_str.Buffer[i],
620 "RtlUpcaseUnicodeString works wrong: '%c'[=0x%x] is converted to '%c'[=0x%x], expected: '%c'[=0x%x]\n",
621 ascii_str.Buffer[i], ascii_str.Buffer[i],
622 result_str.Buffer[i], result_str.Buffer[i],
623 upper_str.Buffer[i], upper_str.Buffer[i]);
624 }
625 }
626
627
628 static void test_RtlDowncaseUnicodeString(void)
629 {
630 int i;
631 WCHAR ch;
632 WCHAR lower_ch;
633 WCHAR source_buf[1025];
634 WCHAR result_buf[1025];
635 WCHAR lower_buf[1025];
636 UNICODE_STRING source_str;
637 UNICODE_STRING result_str;
638 UNICODE_STRING lower_str;
639
640 for (i = 0; i <= 1024; i++) {
641 ch = (WCHAR) i;
642 if (ch >= 'A' && ch <= 'Z') {
643 lower_ch = ch - 'A' + 'a';
644 } else if (ch >= 0xc0 && ch <= 0xde && ch != 0xd7) {
645 lower_ch = ch + 0x20;
646 } else if (ch >= 0x391 && ch <= 0x3ab && ch != 0x3a2) {
647 lower_ch = ch + 0x20;
648 } else {
649 switch (ch) {
650 case 0x178: lower_ch = 0xff; break;
651 case 0x181: lower_ch = 0x253; break;
652 case 0x186: lower_ch = 0x254; break;
653 case 0x189: lower_ch = 0x256; break;
654 case 0x18a: lower_ch = 0x257; break;
655 case 0x18e: lower_ch = 0x1dd; break;
656 case 0x18f: lower_ch = 0x259; break;
657 case 0x190: lower_ch = 0x25b; break;
658 case 0x193: lower_ch = 0x260; break;
659 case 0x194: lower_ch = 0x263; break;
660 case 0x196: lower_ch = 0x269; break;
661 case 0x197: lower_ch = 0x268; break;
662 case 0x19c: lower_ch = 0x26f; break;
663 case 0x19d: lower_ch = 0x272; break;
664 case 0x19f: lower_ch = 0x275; break;
665 case 0x1a9: lower_ch = 0x283; break;
666 case 0x1ae: lower_ch = 0x288; break;
667 case 0x1b1: lower_ch = 0x28a; break;
668 case 0x1b2: lower_ch = 0x28b; break;
669 case 0x1b7: lower_ch = 0x292; break;
670 case 0x1c4: lower_ch = 0x1c6; break;
671 case 0x1c7: lower_ch = 0x1c9; break;
672 case 0x1ca: lower_ch = 0x1cc; break;
673 case 0x1f1: lower_ch = 0x1f3; break;
674 case 0x386: lower_ch = 0x3ac; break;
675 case 0x388: lower_ch = 0x3ad; break;
676 case 0x389: lower_ch = 0x3ae; break;
677 case 0x38a: lower_ch = 0x3af; break;
678 case 0x38c: lower_ch = 0x3cc; break;
679 case 0x38e: lower_ch = 0x3cd; break;
680 case 0x38f: lower_ch = 0x3ce; break;
681 case 0x400: lower_ch = 0x0; break;
682 default: lower_ch = ch; break;
683 } /* switch */
684 }
685 source_buf[i] = ch;
686 result_buf[i] = '\0';
687 lower_buf[i] = lower_ch;
688 }
689 source_buf[i] = '\0';
690 result_buf[i] = '\0';
691 lower_buf[i] = '\0';
692 source_str.Length = 2048;
693 source_str.MaximumLength = 2048;
694 source_str.Buffer = source_buf;
695 result_str.Length = 2048;
696 result_str.MaximumLength = 2048;
697 result_str.Buffer = result_buf;
698 lower_str.Length = 2048;
699 lower_str.MaximumLength = 2048;
700 lower_str.Buffer = lower_buf;
701
702 pRtlDowncaseUnicodeString(&result_str, &source_str, 0);
703 for (i = 0; i <= 1024; i++) {
704 ok(result_str.Buffer[i] == lower_str.Buffer[i] || result_str.Buffer[i] == source_str.Buffer[i] + 1,
705 "RtlDowncaseUnicodeString works wrong: '%c'[=0x%x] is converted to '%c'[=0x%x], expected: '%c'[=0x%x]\n",
706 source_str.Buffer[i], source_str.Buffer[i],
707 result_str.Buffer[i], result_str.Buffer[i],
708 lower_str.Buffer[i], lower_str.Buffer[i]);
709 }
710 }
711
712
713 typedef struct {
714 int ansi_Length;
715 int ansi_MaximumLength;
716 int ansi_buf_size;
717 const char *ansi_buf;
718 int uni_Length;
719 int uni_MaximumLength;
720 int uni_buf_size;
721 const char *uni_buf;
722 BOOLEAN doalloc;
723 int res_Length;
724 int res_MaximumLength;
725 int res_buf_size;
726 const char *res_buf;
727 NTSTATUS result;
728 } ustr2astr_t;
729
730 static const ustr2astr_t ustr2astr[] = {
731 { 10, 12, 12, "------------", 0, 0, 0, "", TRUE, 0, 1, 1, "", STATUS_SUCCESS},
732 { 10, 12, 12, "------------", 12, 12, 12, "abcdef", TRUE, 6, 7, 7, "abcdef", STATUS_SUCCESS},
733 { 0, 2, 12, "------------", 12, 12, 12, "abcdef", TRUE, 6, 7, 7, "abcdef", STATUS_SUCCESS},
734 { 10, 12, 12, NULL, 12, 12, 12, "abcdef", TRUE, 6, 7, 7, "abcdef", STATUS_SUCCESS},
735 { 0, 0, 12, "------------", 12, 12, 12, "abcdef", FALSE, 6, 0, 0, "", STATUS_BUFFER_OVERFLOW},
736 { 0, 1, 12, "------------", 12, 12, 12, "abcdef", FALSE, 0, 1, 1, "", STATUS_BUFFER_OVERFLOW},
737 { 0, 2, 12, "------------", 12, 12, 12, "abcdef", FALSE, 1, 2, 2, "a", STATUS_BUFFER_OVERFLOW},
738 { 0, 3, 12, "------------", 12, 12, 12, "abcdef", FALSE, 2, 3, 3, "ab", STATUS_BUFFER_OVERFLOW},
739 { 0, 5, 12, "------------", 12, 12, 12, "abcdef", FALSE, 4, 5, 5, "abcd", STATUS_BUFFER_OVERFLOW},
740 { 8, 5, 12, "------------", 12, 12, 12, "abcdef", FALSE, 4, 5, 5, "abcd", STATUS_BUFFER_OVERFLOW},
741 { 8, 6, 12, "------------", 12, 12, 12, "abcdef", FALSE, 5, 6, 6, "abcde", STATUS_BUFFER_OVERFLOW},
742 { 8, 7, 12, "------------", 12, 12, 12, "abcdef", FALSE, 6, 7, 7, "abcdef", STATUS_SUCCESS},
743 { 8, 7, 12, "------------", 0, 12, 12, NULL, FALSE, 0, 7, 0, "", STATUS_SUCCESS},
744 { 0, 0, 12, NULL, 10, 10, 12, NULL, FALSE, 5, 0, 0, NULL, STATUS_BUFFER_OVERFLOW},
745 };
746 #define NB_USTR2ASTR (sizeof(ustr2astr)/sizeof(*ustr2astr))
747
748
749 static void test_RtlUnicodeStringToAnsiString(void)
750 {
751 size_t pos;
752 CHAR ansi_buf[257];
753 WCHAR uni_buf[257];
754 STRING ansi_str;
755 UNICODE_STRING uni_str;
756 NTSTATUS result;
757 size_t test_num;
758
759 for (test_num = 0; test_num < NB_USTR2ASTR; test_num++) {
760 ansi_str.Length = ustr2astr[test_num].ansi_Length;
761 ansi_str.MaximumLength = ustr2astr[test_num].ansi_MaximumLength;
762 if (ustr2astr[test_num].ansi_buf != NULL) {
763 memcpy(ansi_buf, ustr2astr[test_num].ansi_buf, ustr2astr[test_num].ansi_buf_size);
764 ansi_buf[ustr2astr[test_num].ansi_buf_size] = '\0';
765 ansi_str.Buffer = ansi_buf;
766 } else {
767 ansi_str.Buffer = NULL;
768 }
769 uni_str.Length = ustr2astr[test_num].uni_Length;
770 uni_str.MaximumLength = ustr2astr[test_num].uni_MaximumLength;
771 if (ustr2astr[test_num].uni_buf != NULL) {
772 for (pos = 0; pos < ustr2astr[test_num].uni_buf_size/sizeof(WCHAR); pos++) {
773 uni_buf[pos] = ustr2astr[test_num].uni_buf[pos];
774 }
775 uni_str.Buffer = uni_buf;
776 } else {
777 uni_str.Buffer = NULL;
778 }
779 result = pRtlUnicodeStringToAnsiString(&ansi_str, &uni_str, ustr2astr[test_num].doalloc);
780 ok(result == ustr2astr[test_num].result,
781 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) has result %lx, expected %lx\n",
782 test_num, ustr2astr[test_num].doalloc, result, ustr2astr[test_num].result);
783 ok(ansi_str.Length == ustr2astr[test_num].res_Length,
784 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) ansi has Length %d, expected %d\n",
785 test_num, ustr2astr[test_num].doalloc, ansi_str.Length, ustr2astr[test_num].res_Length);
786 ok(ansi_str.MaximumLength == ustr2astr[test_num].res_MaximumLength,
787 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) ansi has MaximumLength %d, expected %d\n",
788 test_num, ustr2astr[test_num].doalloc, ansi_str.MaximumLength, ustr2astr[test_num].res_MaximumLength);
789 ok(memcmp(ansi_str.Buffer, ustr2astr[test_num].res_buf, ustr2astr[test_num].res_buf_size) == 0,
790 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) has ansi \"%s\" expected \"%s\"\n",
791 test_num, ustr2astr[test_num].doalloc, ansi_str.Buffer, ustr2astr[test_num].res_buf);
792 }
793 }
794
795
796 typedef struct {
797 int dest_Length;
798 int dest_MaximumLength;
799 int dest_buf_size;
800 const char *dest_buf;
801 const char *src;
802 int res_Length;
803 int res_MaximumLength;
804 int res_buf_size;
805 const char *res_buf;
806 NTSTATUS result;
807 } app_asc2str_t;
808
809 static const app_asc2str_t app_asc2str[] = {
810 { 5, 12, 15, "TestS01234abcde", "tring", 10, 12, 15, "TestStringabcde", STATUS_SUCCESS},
811 { 5, 11, 15, "TestS01234abcde", "tring", 10, 11, 15, "TestStringabcde", STATUS_SUCCESS},
812 { 5, 10, 15, "TestS01234abcde", "tring", 10, 10, 15, "TestStringabcde", STATUS_SUCCESS},
813 { 5, 9, 15, "TestS01234abcde", "tring", 5, 9, 15, "TestS01234abcde", STATUS_BUFFER_TOO_SMALL},
814 { 5, 0, 15, "TestS01234abcde", "tring", 5, 0, 15, "TestS01234abcde", STATUS_BUFFER_TOO_SMALL},
815 { 5, 14, 15, "TestS01234abcde", "tring", 10, 14, 15, "TestStringabcde", STATUS_SUCCESS},
816 { 5, 14, 15, "TestS01234abcde", NULL, 5, 14, 15, "TestS01234abcde", STATUS_SUCCESS},
817 { 5, 14, 15, NULL, NULL, 5, 14, 15, NULL, STATUS_SUCCESS},
818 { 5, 12, 15, "Tst\0S01234abcde", "tr\0i", 7, 12, 15, "Tst\0Str234abcde", STATUS_SUCCESS},
819 };
820 #define NB_APP_ASC2STR (sizeof(app_asc2str)/sizeof(*app_asc2str))
821
822
823 static void test_RtlAppendAsciizToString(void)
824 {
825 CHAR dest_buf[257];
826 STRING dest_str;
827 NTSTATUS result;
828 size_t test_num;
829
830 for (test_num = 0; test_num < NB_APP_ASC2STR; test_num++) {
831 dest_str.Length = app_asc2str[test_num].dest_Length;
832 dest_str.MaximumLength = app_asc2str[test_num].dest_MaximumLength;
833 if (app_asc2str[test_num].dest_buf != NULL) {
834 memcpy(dest_buf, app_asc2str[test_num].dest_buf, app_asc2str[test_num].dest_buf_size);
835 dest_buf[app_asc2str[test_num].dest_buf_size] = '\0';
836 dest_str.Buffer = dest_buf;
837 } else {
838 dest_str.Buffer = NULL;
839 }
840 result = pRtlAppendAsciizToString(&dest_str, app_asc2str[test_num].src);
841 ok(result == app_asc2str[test_num].result,
842 "(test %d): RtlAppendAsciizToString(dest, src) has result %lx, expected %lx\n",
843 test_num, result, app_asc2str[test_num].result);
844 ok(dest_str.Length == app_asc2str[test_num].res_Length,
845 "(test %d): RtlAppendAsciizToString(dest, src) dest has Length %d, expected %d\n",
846 test_num, dest_str.Length, app_asc2str[test_num].res_Length);
847 ok(dest_str.MaximumLength == app_asc2str[test_num].res_MaximumLength,
848 "(test %d): RtlAppendAsciizToString(dest, src) dest has MaximumLength %d, expected %d\n",
849 test_num, dest_str.MaximumLength, app_asc2str[test_num].res_MaximumLength);
850 if (dest_str.Buffer == dest_buf) {
851 ok(memcmp(dest_buf, app_asc2str[test_num].res_buf, app_asc2str[test_num].res_buf_size) == 0,
852 "(test %d): RtlAppendAsciizToString(dest, src) has dest \"%s\" expected \"%s\"\n",
853 test_num, dest_buf, app_asc2str[test_num].res_buf);
854 } else {
855 ok(dest_str.Buffer == app_asc2str[test_num].res_buf,
856 "(test %d): RtlAppendAsciizToString(dest, src) dest has Buffer %p expected %p\n",
857 test_num, dest_str.Buffer, app_asc2str[test_num].res_buf);
858 }
859 }
860 }
861
862
863 typedef struct {
864 int dest_Length;
865 int dest_MaximumLength;
866 int dest_buf_size;
867 const char *dest_buf;
868 int src_Length;
869 int src_MaximumLength;
870 int src_buf_size;
871 const char *src_buf;
872 int res_Length;
873 int res_MaximumLength;
874 int res_buf_size;
875 const char *res_buf;
876 NTSTATUS result;
877 } app_str2str_t;
878
879 static const app_str2str_t app_str2str[] = {
880 { 5, 12, 15, "TestS01234abcde", 5, 5, 7, "tringZY", 10, 12, 15, "TestStringabcde", STATUS_SUCCESS},
881 { 5, 11, 15, "TestS01234abcde", 5, 5, 7, "tringZY", 10, 11, 15, "TestStringabcde", STATUS_SUCCESS},
882 { 5, 10, 15, "TestS01234abcde", 5, 5, 7, "tringZY", 10, 10, 15, "TestStringabcde", STATUS_SUCCESS},
883 { 5, 9, 15, "TestS01234abcde", 5, 5, 7, "tringZY", 5, 9, 15, "TestS01234abcde", STATUS_BUFFER_TOO_SMALL},
884 { 5, 0, 15, "TestS01234abcde", 0, 0, 7, "tringZY", 5, 0, 15, "TestS01234abcde", STATUS_SUCCESS},
885 { 5, 14, 15, "TestS01234abcde", 0, 0, 7, "tringZY", 5, 14, 15, "TestS01234abcde", STATUS_SUCCESS},
886 { 5, 14, 15, "TestS01234abcde", 0, 0, 7, NULL, 5, 14, 15, "TestS01234abcde", STATUS_SUCCESS},
887 { 5, 14, 15, NULL, 0, 0, 7, NULL, 5, 14, 15, NULL, STATUS_SUCCESS},
888 { 5, 12, 15, "Tst\0S01234abcde", 4, 4, 7, "tr\0iZY", 9, 12, 15, "Tst\0Str\0i4abcde", STATUS_SUCCESS},
889 };
890 #define NB_APP_STR2STR (sizeof(app_str2str)/sizeof(*app_str2str))
891
892
893 static void test_RtlAppendStringToString(void)
894 {
895 CHAR dest_buf[257];
896 CHAR src_buf[257];
897 STRING dest_str;
898 STRING src_str;
899 NTSTATUS result;
900 size_t test_num;
901
902 for (test_num = 0; test_num < NB_APP_STR2STR; test_num++) {
903 dest_str.Length = app_str2str[test_num].dest_Length;
904 dest_str.MaximumLength = app_str2str[test_num].dest_MaximumLength;
905 if (app_str2str[test_num].dest_buf != NULL) {
906 memcpy(dest_buf, app_str2str[test_num].dest_buf, app_str2str[test_num].dest_buf_size);
907 dest_buf[app_str2str[test_num].dest_buf_size] = '\0';
908 dest_str.Buffer = dest_buf;
909 } else {
910 dest_str.Buffer = NULL;
911 }
912 src_str.Length = app_str2str[test_num].src_Length;
913 src_str.MaximumLength = app_str2str[test_num].src_MaximumLength;
914 if (app_str2str[test_num].src_buf != NULL) {
915 memcpy(src_buf, app_str2str[test_num].src_buf, app_str2str[test_num].src_buf_size);
916 src_buf[app_str2str[test_num].src_buf_size] = '\0';
917 src_str.Buffer = src_buf;
918 } else {
919 src_str.Buffer = NULL;
920 }
921 result = pRtlAppendStringToString(&dest_str, &src_str);
922 ok(result == app_str2str[test_num].result,
923 "(test %d): RtlAppendStringToString(dest, src) has result %lx, expected %lx\n",
924 test_num, result, app_str2str[test_num].result);
925 ok(dest_str.Length == app_str2str[test_num].res_Length,
926 "(test %d): RtlAppendStringToString(dest, src) dest has Length %d, expected %d\n",
927 test_num, dest_str.Length, app_str2str[test_num].res_Length);
928 ok(dest_str.MaximumLength == app_str2str[test_num].res_MaximumLength,
929 "(test %d): RtlAppendStringToString(dest, src) dest has MaximumLength %d, expected %d\n",
930 test_num, dest_str.MaximumLength, app_str2str[test_num].res_MaximumLength);
931 if (dest_str.Buffer == dest_buf) {
932 ok(memcmp(dest_buf, app_str2str[test_num].res_buf, app_str2str[test_num].res_buf_size) == 0,
933 "(test %d): RtlAppendStringToString(dest, src) has dest \"%s\" expected \"%s\"\n",
934 test_num, dest_buf, app_str2str[test_num].res_buf);
935 } else {
936 ok(dest_str.Buffer == app_str2str[test_num].res_buf,
937 "(test %d): RtlAppendStringToString(dest, src) dest has Buffer %p expected %p\n",
938 test_num, dest_str.Buffer, app_str2str[test_num].res_buf);
939 }
940 }
941 }
942
943
944 typedef struct {
945 int dest_Length;
946 int dest_MaximumLength;
947 int dest_buf_size;
948 const char *dest_buf;
949 const char *src;
950 int res_Length;
951 int res_MaximumLength;
952 int res_buf_size;
953 const char *res_buf;
954 NTSTATUS result;
955 } app_uni2str_t;
956
957 static const app_uni2str_t app_uni2str[] = {
958 { 4, 12, 14, "Fake0123abcdef", "Ustr\0", 8, 12, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
959 { 4, 11, 14, "Fake0123abcdef", "Ustr\0", 8, 11, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
960 { 4, 10, 14, "Fake0123abcdef", "Ustr\0", 8, 10, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
961 /* In the following test the native function writes beyond MaximumLength
962 * { 4, 9, 14, "Fake0123abcdef", "Ustr\0", 8, 9, 14, "FakeUstrabcdef", STATUS_SUCCESS},
963 */
964 { 4, 8, 14, "Fake0123abcdef", "Ustr\0", 8, 8, 14, "FakeUstrabcdef", STATUS_SUCCESS},
965 { 4, 7, 14, "Fake0123abcdef", "Ustr\0", 4, 7, 14, "Fake0123abcdef", STATUS_BUFFER_TOO_SMALL},
966 { 4, 0, 14, "Fake0123abcdef", "Ustr\0", 4, 0, 14, "Fake0123abcdef", STATUS_BUFFER_TOO_SMALL},
967 { 4, 14, 14, "Fake0123abcdef", "Ustr\0", 8, 14, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
968 { 4, 14, 14, "Fake0123abcdef", NULL, 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS},
969 { 4, 14, 14, NULL, NULL, 4, 14, 14, NULL, STATUS_SUCCESS},
970 { 4, 14, 14, "Fake0123abcdef", "U\0stri\0", 10, 14, 14, "FakeU\0stri\0\0ef", STATUS_SUCCESS},
971 { 6, 14, 16, "Te\0\0stabcdefghij", "St\0\0ri", 8, 14, 16, "Te\0\0stSt\0\0efghij", STATUS_SUCCESS},
972 };
973 #define NB_APP_UNI2STR (sizeof(app_uni2str)/sizeof(*app_uni2str))
974
975
976 static void test_RtlAppendUnicodeToString(void)
977 {
978 WCHAR dest_buf[257];
979 UNICODE_STRING dest_str;
980 NTSTATUS result;
981 size_t test_num;
982
983 for (test_num = 0; test_num < NB_APP_UNI2STR; test_num++) {
984 dest_str.Length = app_uni2str[test_num].dest_Length;
985 dest_str.MaximumLength = app_uni2str[test_num].dest_MaximumLength;
986 if (app_uni2str[test_num].dest_buf != NULL) {
987 memcpy(dest_buf, app_uni2str[test_num].dest_buf, app_uni2str[test_num].dest_buf_size);
988 dest_buf[app_uni2str[test_num].dest_buf_size/sizeof(WCHAR)] = '\0';
989 dest_str.Buffer = dest_buf;
990 } else {
991 dest_str.Buffer = NULL;
992 }
993 result = pRtlAppendUnicodeToString(&dest_str, (LPCWSTR) app_uni2str[test_num].src);
994 ok(result == app_uni2str[test_num].result,
995 "(test %d): RtlAppendUnicodeToString(dest, src) has result %lx, expected %lx\n",
996 test_num, result, app_uni2str[test_num].result);
997 ok(dest_str.Length == app_uni2str[test_num].res_Length,
998 "(test %d): RtlAppendUnicodeToString(dest, src) dest has Length %d, expected %d\n",
999 test_num, dest_str.Length, app_uni2str[test_num].res_Length);
1000 ok(dest_str.MaximumLength == app_uni2str[test_num].res_MaximumLength,
1001 "(test %d): RtlAppendUnicodeToString(dest, src) dest has MaximumLength %d, expected %d\n",
1002 test_num, dest_str.MaximumLength, app_uni2str[test_num].res_MaximumLength);
1003 if (dest_str.Buffer == dest_buf) {
1004 ok(memcmp(dest_buf, app_uni2str[test_num].res_buf, app_uni2str[test_num].res_buf_size) == 0,
1005 "(test %d): RtlAppendUnicodeToString(dest, src) has dest \"%s\" expected \"%s\"\n",
1006 test_num, (char *) dest_buf, app_uni2str[test_num].res_buf);
1007 } else {
1008 ok(dest_str.Buffer == (WCHAR *) app_uni2str[test_num].res_buf,
1009 "(test %d): RtlAppendUnicodeToString(dest, src) dest has Buffer %p expected %p\n",
1010 test_num, dest_str.Buffer, app_uni2str[test_num].res_buf);
1011 }
1012 }
1013 }
1014
1015
1016 typedef struct {
1017 int dest_Length;
1018 int dest_MaximumLength;
1019 int dest_buf_size;
1020 const char *dest_buf;
1021 int src_Length;
1022 int src_MaximumLength;
1023 int src_buf_size;
1024 const char *src_buf;
1025 int res_Length;
1026 int res_MaximumLength;
1027 int res_buf_size;
1028 const char *res_buf;
1029 NTSTATUS result;
1030 } app_ustr2str_t;
1031
1032 static const app_ustr2str_t app_ustr2str[] = {
1033 { 4, 12, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 12, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
1034 { 4, 11, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 11, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
1035 { 4, 10, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 10, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
1036 /* In the following test the native function writes beyond MaximumLength
1037 * { 4, 9, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 9, 14, "FakeUstrabcdef", STATUS_SUCCESS},
1038 */
1039 { 4, 8, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 8, 14, "FakeUstrabcdef", STATUS_SUCCESS},
1040 { 4, 7, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 4, 7, 14, "Fake0123abcdef", STATUS_BUFFER_TOO_SMALL},
1041 { 4, 0, 14, "Fake0123abcdef", 0, 0, 8, "UstrZYXW", 4, 0, 14, "Fake0123abcdef", STATUS_SUCCESS},
1042 { 4, 14, 14, "Fake0123abcdef", 0, 0, 8, "UstrZYXW", 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS},
1043 { 4, 14, 14, "Fake0123abcdef", 0, 0, 8, NULL, 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS},
1044 { 4, 14, 14, NULL, 0, 0, 8, NULL, 4, 14, 14, NULL, STATUS_SUCCESS},
1045 { 6, 14, 16, "Te\0\0stabcdefghij", 6, 8, 8, "St\0\0riZY", 12, 14, 16, "Te\0\0stSt\0\0ri\0\0ij", STATUS_SUCCESS},
1046 };
1047 #define NB_APP_USTR2STR (sizeof(app_ustr2str)/sizeof(*app_ustr2str))
1048
1049
1050 static void test_RtlAppendUnicodeStringToString(void)
1051 {
1052 WCHAR dest_buf[257];
1053 WCHAR src_buf[257];
1054 UNICODE_STRING dest_str;
1055 UNICODE_STRING src_str;
1056 NTSTATUS result;
1057 size_t test_num;
1058
1059 for (test_num = 0; test_num < NB_APP_USTR2STR; test_num++) {
1060 dest_str.Length = app_ustr2str[test_num].dest_Length;
1061 dest_str.MaximumLength = app_ustr2str[test_num].dest_MaximumLength;
1062 if (app_ustr2str[test_num].dest_buf != NULL) {
1063 memcpy(dest_buf, app_ustr2str[test_num].dest_buf, app_ustr2str[test_num].dest_buf_size);
1064 dest_buf[app_ustr2str[test_num].dest_buf_size/sizeof(WCHAR)] = '\0';
1065 dest_str.Buffer = dest_buf;
1066 } else {
1067 dest_str.Buffer = NULL;
1068 }
1069 src_str.Length = app_ustr2str[test_num].src_Length;
1070 src_str.MaximumLength = app_ustr2str[test_num].src_MaximumLength;
1071 if (app_ustr2str[test_num].src_buf != NULL) {
1072 memcpy(src_buf, app_ustr2str[test_num].src_buf, app_ustr2str[test_num].src_buf_size);
1073 src_buf[app_ustr2str[test_num].src_buf_size/sizeof(WCHAR)] = '\0';
1074 src_str.Buffer = src_buf;
1075 } else {
1076 src_str.Buffer = NULL;
1077 }
1078 result = pRtlAppendUnicodeStringToString(&dest_str, &src_str);
1079 ok(result == app_ustr2str[test_num].result,
1080 "(test %d): RtlAppendStringToString(dest, src) has result %lx, expected %lx\n",
1081 test_num, result, app_ustr2str[test_num].result);
1082 ok(dest_str.Length == app_ustr2str[test_num].res_Length,
1083 "(test %d): RtlAppendStringToString(dest, src) dest has Length %d, expected %d\n",
1084 test_num, dest_str.Length, app_ustr2str[test_num].res_Length);
1085 ok(dest_str.MaximumLength == app_ustr2str[test_num].res_MaximumLength,
1086 "(test %d): RtlAppendStringToString(dest, src) dest has MaximumLength %d, expected %d\n",
1087 test_num, dest_str.MaximumLength, app_ustr2str[test_num].res_MaximumLength);
1088 if (dest_str.Buffer == dest_buf) {
1089 ok(memcmp(dest_buf, app_ustr2str[test_num].res_buf, app_ustr2str[test_num].res_buf_size) == 0,
1090 "(test %d): RtlAppendStringToString(dest, src) has dest \"%s\" expected \"%s\"\n",
1091 test_num, (char *) dest_buf, app_ustr2str[test_num].res_buf);
1092 } else {
1093 ok(dest_str.Buffer == (WCHAR *) app_ustr2str[test_num].res_buf,
1094 "(test %d): RtlAppendStringToString(dest, src) dest has Buffer %p expected %p\n",
1095 test_num, dest_str.Buffer, app_ustr2str[test_num].res_buf);
1096 }
1097 }
1098 }
1099
1100
1101 typedef struct {
1102 int flags;
1103 const char *main_str;
1104 const char *search_chars;
1105 USHORT pos;
1106 NTSTATUS result;
1107 } find_ch_in_ustr_t;
1108
1109 static const find_ch_in_ustr_t find_ch_in_ustr[] = {
1110 { 0, "Some Wild String", "S", 2, STATUS_SUCCESS},
1111 { 0, "This is a String", "String", 6, STATUS_SUCCESS},
1112 { 1, "This is a String", "String", 30, STATUS_SUCCESS},
1113 { 2, "This is a String", "String", 2, STATUS_SUCCESS},
1114 { 3, "This is a String", "String", 18, STATUS_SUCCESS},
1115 { 0, "This is a String", "Wild", 6, STATUS_SUCCESS},
1116 { 1, "This is a String", "Wild", 26, STATUS_SUCCESS},
1117 { 2, "This is a String", "Wild", 2, STATUS_SUCCESS},
1118 { 3, "This is a String", "Wild", 30, STATUS_SUCCESS},
1119 { 0, "abcdefghijklmnopqrstuvwxyz", "", 0, STATUS_NOT_FOUND},
1120 { 0, "abcdefghijklmnopqrstuvwxyz", "123", 0, STATUS_NOT_FOUND},
1121 { 0, "abcdefghijklmnopqrstuvwxyz", "a", 2, STATUS_SUCCESS},
1122 { 0, "abcdefghijklmnopqrstuvwxyz", "12a34", 2, STATUS_SUCCESS},
1123 { 0, "abcdefghijklmnopqrstuvwxyz", "12b34", 4, STATUS_SUCCESS},
1124 { 0, "abcdefghijklmnopqrstuvwxyz", "12y34", 50, STATUS_SUCCESS},
1125 { 0, "abcdefghijklmnopqrstuvwxyz", "12z34", 52, STATUS_SUCCESS},
1126 { 0, "abcdefghijklmnopqrstuvwxyz", "rvz", 36, STATUS_SUCCESS},
1127 { 0, "abcdefghijklmmlkjihgfedcba", "egik", 10, STATUS_SUCCESS},
1128 { 1, "abcdefghijklmnopqrstuvwxyz", "", 0, STATUS_NOT_FOUND},
1129 { 1, "abcdefghijklmnopqrstuvwxyz", "rvz", 50, STATUS_SUCCESS},
1130 { 1, "abcdefghijklmnopqrstuvwxyz", "ravy", 48, STATUS_SUCCESS},
1131 { 1, "abcdefghijklmnopqrstuvwxyz", "raxv", 46, STATUS_SUCCESS},
1132 { 2, "abcdefghijklmnopqrstuvwxyz", "", 2, STATUS_SUCCESS},
1133 { 2, "abcdefghijklmnopqrstuvwxyz", "rvz", 2, STATUS_SUCCESS},
1134 { 2, "abcdefghijklmnopqrstuvwxyz", "vaz", 4, STATUS_SUCCESS},
1135 { 2, "abcdefghijklmnopqrstuvwxyz", "ravbz", 6, STATUS_SUCCESS},
1136 { 3, "abcdefghijklmnopqrstuvwxyz", "", 50, STATUS_SUCCESS},
1137 { 3, "abcdefghijklmnopqrstuvwxyz", "123", 50, STATUS_SUCCESS},
1138 { 3, "abcdefghijklmnopqrstuvwxyz", "ahp", 50, STATUS_SUCCESS},
1139 { 3, "abcdefghijklmnopqrstuvwxyz", "rvz", 48, STATUS_SUCCESS},
1140 { 0, NULL, "abc", 0, STATUS_NOT_FOUND},
1141 { 1, NULL, "abc", 0, STATUS_NOT_FOUND},
1142 { 2, NULL, "abc", 0, STATUS_NOT_FOUND},
1143 { 3, NULL, "abc", 0, STATUS_NOT_FOUND},
1144 { 0, "abcdefghijklmnopqrstuvwxyz", NULL, 0, STATUS_NOT_FOUND},
1145 { 1, "abcdefghijklmnopqrstuvwxyz", NULL, 0, STATUS_NOT_FOUND},
1146 { 2, "abcdefghijklmnopqrstuvwxyz", NULL, 2, STATUS_SUCCESS},
1147 { 3, "abcdefghijklmnopqrstuvwxyz", NULL, 50, STATUS_SUCCESS},
1148 { 0, NULL, NULL, 0, STATUS_NOT_FOUND},
1149 { 1, NULL, NULL, 0, STATUS_NOT_FOUND},
1150 { 2, NULL, NULL, 0, STATUS_NOT_FOUND},
1151 { 3, NULL, NULL, 0, STATUS_NOT_FOUND},
1152 { 0, "abcdabcdabcdabcdabcdabcd", "abcd", 2, STATUS_SUCCESS},
1153 { 1, "abcdabcdabcdabcdabcdabcd", "abcd", 46, STATUS_SUCCESS},
1154 { 2, "abcdabcdabcdabcdabcdabcd", "abcd", 0, STATUS_NOT_FOUND},
1155 { 3, "abcdabcdabcdabcdabcdabcd", "abcd", 0, STATUS_NOT_FOUND},
1156 };
1157 #define NB_FIND_CH_IN_USTR (sizeof(find_ch_in_ustr)/sizeof(*find_ch_in_ustr))
1158
1159
1160 static void test_RtlFindCharInUnicodeString(void)
1161 {
1162 WCHAR main_str_buf[257];
1163 WCHAR search_chars_buf[257];
1164 UNICODE_STRING main_str;
1165 UNICODE_STRING search_chars;
1166 USHORT pos;
1167 NTSTATUS result;
1168 size_t idx;
1169 size_t test_num;
1170
1171 for (test_num = 0; test_num < NB_FIND_CH_IN_USTR; test_num++) {
1172 if (find_ch_in_ustr[test_num].main_str != NULL) {
1173 main_str.Length = strlen(find_ch_in_ustr[test_num].main_str) * sizeof(WCHAR);
1174 main_str.MaximumLength = main_str.Length + sizeof(WCHAR);
1175 for (idx = 0; idx < main_str.Length / sizeof(WCHAR); idx++) {
1176 main_str_buf[idx] = find_ch_in_ustr[test_num].main_str[idx];
1177 }
1178 main_str.Buffer = main_str_buf;
1179 } else {
1180 main_str.Length = 0;
1181 main_str.MaximumLength = 0;
1182 main_str.Buffer = NULL;
1183 }
1184 if (find_ch_in_ustr[test_num].search_chars != NULL) {
1185 search_chars.Length = strlen(find_ch_in_ustr[test_num].search_chars) * sizeof(WCHAR);
1186 search_chars.MaximumLength = search_chars.Length + sizeof(WCHAR);
1187 for (idx = 0; idx < search_chars.Length / sizeof(WCHAR); idx++) {
1188 search_chars_buf[idx] = find_ch_in_ustr[test_num].search_chars[idx];
1189 }
1190 search_chars.Buffer = search_chars_buf;
1191 } else {
1192 search_chars.Length = 0;
1193 search_chars.MaximumLength = 0;
1194 search_chars.Buffer = NULL;
1195 }
1196 pos = 12345;
1197 result = pRtlFindCharInUnicodeString(find_ch_in_ustr[test_num].flags, &main_str, &search_chars, &pos);
1198 ok(result == find_ch_in_ustr[test_num].result,
1199 "(test %d): RtlFindCharInUnicodeString(%d, %s, %s, [out]) has result %lx, expected %lx\n",
1200 test_num, find_ch_in_ustr[test_num].flags,
1201 find_ch_in_ustr[test_num].main_str, find_ch_in_ustr[test_num].search_chars,
1202 result, find_ch_in_ustr[test_num].result);
1203 ok(pos == find_ch_in_ustr[test_num].pos,
1204 "(test %d): RtlFindCharInUnicodeString(%d, %s, %s, [out]) assigns %d to pos, expected %d\n",
1205 test_num, find_ch_in_ustr[test_num].flags,
1206 find_ch_in_ustr[test_num].main_str, find_ch_in_ustr[test_num].search_chars,
1207 pos, find_ch_in_ustr[test_num].pos);
1208 }
1209 }
1210
1211
1212 typedef struct {
1213 int base;
1214 const char *str;
1215 int value;
1216 NTSTATUS result;
1217 } str2int_t;
1218
1219 static const str2int_t str2int[] = {
1220 { 0, "1011101100", 1011101100, STATUS_SUCCESS},
1221 { 0, "1234567", 1234567, STATUS_SUCCESS},
1222 { 0, "-214", -214, STATUS_SUCCESS},
1223 { 0, "+214", 214, STATUS_SUCCESS}, /* The + sign is allowed also */
1224 { 0, "--214", 0, STATUS_SUCCESS}, /* Do not accept more than one sign */
1225 { 0, "-+214", 0, STATUS_SUCCESS},
1226 { 0, "++214", 0, STATUS_SUCCESS},
1227 { 0, "+-214", 0, STATUS_SUCCESS},
1228 { 0, "\001\002\003\00411", 11, STATUS_SUCCESS}, /* whitespace char 1 to 4 */
1229 { 0, "\005\006\007\01012", 12, STATUS_SUCCESS}, /* whitespace char 5 to 8 */
1230 { 0, "\011\012\013\01413", 13, STATUS_SUCCESS}, /* whitespace char 9 to 12 */
1231 { 0, "\015\016\017\02014", 14, STATUS_SUCCESS}, /* whitespace char 13 to 16 */
1232 { 0, "\021\022\023\02415", 15, STATUS_SUCCESS}, /* whitespace char 17 to 20 */
1233 { 0, "\025\026\027\03016", 16, STATUS_SUCCESS}, /* whitespace char 21 to 24 */
1234 { 0, "\031\032\033\03417", 17, STATUS_SUCCESS}, /* whitespace char 25 to 28 */
1235 { 0, "\035\036\037\04018", 18, STATUS_SUCCESS}, /* whitespace char 29 to 32 */
1236 { 0, " \n \r \t214", 214, STATUS_SUCCESS},
1237 { 0, " \n \r \t+214", 214, STATUS_SUCCESS}, /* Signs can be used after whitespace */
1238 { 0, " \n \r \t-214", -214, STATUS_SUCCESS},
1239 { 0, "+214 0", 214, STATUS_SUCCESS}, /* Space terminates the number */
1240 { 0, " 214.01", 214, STATUS_SUCCESS}, /* Decimal point not accepted */
1241 { 0, " 214,01", 214, STATUS_SUCCESS}, /* Decimal comma not accepted */
1242 { 0, "f81", 0, STATUS_SUCCESS},
1243 { 0, "0x12345", 0x12345, STATUS_SUCCESS}, /* Hex */
1244 { 0, "00x12345", 0, STATUS_SUCCESS},
1245 { 0, "0xx12345", 0, STATUS_SUCCESS},
1246 { 0, "1x34", 1, STATUS_SUCCESS},
1247 { 0, "-9999999999", -1410065407, STATUS_SUCCESS}, /* Big negative integer */
1248 { 0, "-2147483649", 2147483647, STATUS_SUCCESS}, /* Too small to fit in 32 Bits */
1249 { 0, "-2147483648", 0x80000000L, STATUS_SUCCESS}, /* Smallest negative integer */
1250 { 0, "-2147483647", -2147483647, STATUS_SUCCESS},
1251 { 0, "-1", -1, STATUS_SUCCESS},
1252 { 0, "0", 0, STATUS_SUCCESS},
1253 { 0, "1", 1, STATUS_SUCCESS},
1254 { 0, "2147483646", 2147483646, STATUS_SUCCESS},
1255 { 0, "2147483647", 2147483647, STATUS_SUCCESS}, /* Largest signed positive integer */
1256 { 0, "2147483648", 0x80000000L, STATUS_SUCCESS}, /* Positive int equal to smallest negative int */
1257 { 0, "2147483649", -2147483647, STATUS_SUCCESS},
1258 { 0, "4294967294", -2, STATUS_SUCCESS},
1259 { 0, "4294967295", -1, STATUS_SUCCESS}, /* Largest unsigned integer */
1260 { 0, "4294967296", 0, STATUS_SUCCESS}, /* Too big to fit in 32 Bits */
1261 { 0, "9999999999", 1410065407, STATUS_SUCCESS}, /* Big positive integer */
1262 { 0, "056789", 56789, STATUS_SUCCESS}, /* Leading zero and still decimal */
1263 { 0, "b1011101100", 0, STATUS_SUCCESS}, /* Binary (b-notation) */
1264 { 0, "-b1011101100", 0, STATUS_SUCCESS}, /* Negative Binary (b-notation) */
1265 { 0, "b10123456789", 0, STATUS_SUCCESS}, /* Binary with nonbinary digits (2-9) */
1266 { 0, "0b1011101100", 748, STATUS_SUCCESS}, /* Binary (0b-notation) */
1267 { 0, "-0b1011101100", -748, STATUS_SUCCESS}, /* Negative binary (0b-notation) */
1268 { 0, "0b10123456789", 5, STATUS_SUCCESS}, /* Binary with nonbinary digits (2-9) */
1269 { 0, "-0b10123456789", -5, STATUS_SUCCESS}, /* Negative binary with nonbinary digits (2-9) */
1270 { 0, "0b1", 1, STATUS_SUCCESS}, /* one digit binary */
1271 { 0, "0b2", 0, STATUS_SUCCESS}, /* empty binary */
1272 { 0, "0b", 0, STATUS_SUCCESS}, /* empty binary */
1273 { 0, "o1234567", 0, STATUS_SUCCESS}, /* Octal (o-notation) */
1274 { 0, "-o1234567", 0, STATUS_SUCCESS}, /* Negative Octal (o-notation) */
1275 { 0, "o56789", 0, STATUS_SUCCESS}, /* Octal with nonoctal digits (8 and 9) */
1276 { 0, "0o1234567", 01234567, STATUS_SUCCESS}, /* Octal (0o-notation) */
1277 { 0, "-0o1234567", -01234567, STATUS_SUCCESS}, /* Negative octal (0o-notation) */
1278 { 0, "0o56789", 0567, STATUS_SUCCESS}, /* Octal with nonoctal digits (8 and 9) */
1279 { 0, "-0o56789", -0567, STATUS_SUCCESS}, /* Negative octal with nonoctal digits (8 and 9) */
1280 { 0, "0o7", 7, STATUS_SUCCESS}, /* one digit octal */
1281 { 0, "0o8", 0, STATUS_SUCCESS}, /* empty octal */
1282 { 0, "0o", 0, STATUS_SUCCESS}, /* empty octal */
1283 { 0, "0d1011101100", 0, STATUS_SUCCESS}, /* explizit decimal with 0d */
1284 { 0, "x89abcdef", 0, STATUS_SUCCESS}, /* Hex with lower case digits a-f (x-notation) */
1285 { 0, "xFEDCBA00", 0, STATUS_SUCCESS}, /* Hex with upper case digits A-F (x-notation) */
1286 { 0, "-xFEDCBA00", 0, STATUS_SUCCESS}, /* Negative Hexadecimal (x-notation) */
1287 { 0, "0x89abcdef", 0x89abcdef, STATUS_SUCCESS}, /* Hex with lower case digits a-f (0x-notation) */
1288 { 0, "0xFEDCBA00", 0xFEDCBA00, STATUS_SUCCESS}, /* Hex with upper case digits A-F (0x-notation) */
1289 { 0, "-0xFEDCBA00", 19088896, STATUS_SUCCESS}, /* Negative Hexadecimal (0x-notation) */
1290 { 0, "0xabcdefgh", 0xabcdef, STATUS_SUCCESS}, /* Hex with illegal lower case digits (g-z) */
1291 { 0, "0xABCDEFGH", 0xABCDEF, STATUS_SUCCESS}, /* Hex with illegal upper case digits (G-Z) */
1292 { 0, "0xF", 0xf, STATUS_SUCCESS}, /* one digit hexadecimal */
1293 { 0, "0xG", 0, STATUS_SUCCESS}, /* empty hexadecimal */
1294 { 0, "0x", 0, STATUS_SUCCESS}, /* empty hexadecimal */
1295 { 0, "", 0, STATUS_SUCCESS}, /* empty string */
1296 { 2, "1011101100", 748, STATUS_SUCCESS},
1297 { 2, "-1011101100", -748, STATUS_SUCCESS},
1298 { 2, "2", 0, STATUS_SUCCESS},
1299 { 2, "0b1011101100", 0, STATUS_SUCCESS},
1300 { 2, "0o1011101100", 0, STATUS_SUCCESS},
1301 { 2, "0d1011101100", 0, STATUS_SUCCESS},
1302 { 2, "0x1011101100", 0, STATUS_SUCCESS},
1303 { 2, "", 0, STATUS_SUCCESS}, /* empty string */
1304 { 8, "1011101100", 136610368, STATUS_SUCCESS},
1305 { 8, "-1011101100", -136610368, STATUS_SUCCESS},
1306 { 8, "8", 0, STATUS_SUCCESS},
1307 { 8, "0b1011101100", 0, STATUS_SUCCESS},
1308 { 8, "0o1011101100", 0, STATUS_SUCCESS},
1309 { 8, "0d1011101100", 0, STATUS_SUCCESS},
1310 { 8, "0x1011101100", 0, STATUS_SUCCESS},
1311 { 8, "", 0, STATUS_SUCCESS}, /* empty string */
1312 {10, "1011101100", 1011101100, STATUS_SUCCESS},
1313 {10, "-1011101100", -1011101100, STATUS_SUCCESS},
1314 {10, "0b1011101100", 0, STATUS_SUCCESS},
1315 {10, "0o1011101100", 0, STATUS_SUCCESS},
1316 {10, "0d1011101100", 0, STATUS_SUCCESS},
1317 {10, "0x1011101100", 0, STATUS_SUCCESS},
1318 {10, "o12345", 0, STATUS_SUCCESS}, /* Octal although base is 10 */
1319 {10, "", 0, STATUS_SUCCESS}, /* empty string */
1320 {16, "1011101100", 286265600, STATUS_SUCCESS},
1321 {16, "-1011101100", -286265600, STATUS_SUCCESS},
1322 {16, "G", 0, STATUS_SUCCESS},
1323 {16, "g", 0, STATUS_SUCCESS},
1324 {16, "0b1011101100", 286265600, STATUS_SUCCESS},
1325 {16, "0o1011101100", 0, STATUS_SUCCESS},
1326 {16, "0d1011101100", 286265600, STATUS_SUCCESS},
1327 {16, "0x1011101100", 0, STATUS_SUCCESS},
1328 {16, "", 0, STATUS_SUCCESS}, /* empty string */
1329 {20, "0", 0xdeadbeef, STATUS_INVALID_PARAMETER}, /* illegal base */
1330 {-8, "0", 0xdeadbeef, STATUS_INVALID_PARAMETER}, /* Negative base */
1331 /* { 0, NULL, 0, STATUS_SUCCESS}, */ /* NULL as string */
1332 };
1333 #define NB_STR2INT (sizeof(str2int)/sizeof(*str2int))
1334
1335
1336 static void test_RtlUnicodeStringToInteger(void)
1337 {
1338 size_t test_num;
1339 int value;
1340 NTSTATUS result;
1341 WCHAR *wstr;
1342 UNICODE_STRING uni;
1343
1344 for (test_num = 0; test_num < NB_STR2INT; test_num++) {
1345 wstr = AtoW(str2int[test_num].str);
1346 value = 0xdeadbeef;
1347 pRtlInitUnicodeString(&uni, wstr);
1348 result = pRtlUnicodeStringToInteger(&uni, str2int[test_num].base, &value);
1349 ok(result == str2int[test_num].result,
1350 "(test %d): RtlUnicodeStringToInteger(\"%s\", %d, [out]) has result %lx, expected: %lx\n",
1351 test_num, str2int[test_num].str, str2int[test_num].base, result, str2int[test_num].result);
1352 ok(value == str2int[test_num].value,
1353 "(test %d): RtlUnicodeStringToInteger(\"%s\", %d, [out]) assigns value %d, expected: %d\n",
1354 test_num, str2int[test_num].str, str2int[test_num].base, value, str2int[test_num].value);
1355 free(wstr);
1356 }
1357
1358 wstr = AtoW(str2int[1].str);
1359 pRtlInitUnicodeString(&uni, wstr);
1360 result = pRtlUnicodeStringToInteger(&uni, str2int[1].base, NULL);
1361 ok(result == STATUS_ACCESS_VIOLATION,
1362 "call failed: RtlUnicodeStringToInteger(\"%s\", %d, NULL) has result %lx\n",
1363 str2int[1].str, str2int[1].base, result);
1364 result = pRtlUnicodeStringToInteger(&uni, 20, NULL);
1365 ok(result == STATUS_INVALID_PARAMETER,
1366 "call failed: RtlUnicodeStringToInteger(\"%s\", 20, NULL) has result %lx\n",
1367 str2int[1].str, result);
1368
1369 uni.Length = 10; /* Make Length shorter (5 WCHARS instead of 7) */
1370 result = pRtlUnicodeStringToInteger(&uni, str2int[1].base, &value);
1371 ok(result == STATUS_SUCCESS,
1372 "call failed: RtlUnicodeStringToInteger(\"12345\", %d, [out]) has result %lx\n",
1373 str2int[1].base, result);
1374 ok(value == 12345,
1375 "didn't return expected value (test a): expected: %d, got: %d\n",
1376 12345, value);
1377
1378 uni.Length = 5; /* Use odd Length (2.5 WCHARS) */
1379 result = pRtlUnicodeStringToInteger(&uni, str2int[1].base, &value);
1380 ok(result == STATUS_SUCCESS,
1381 "call failed: RtlUnicodeStringToInteger(\"12\", %d, [out]) has result %lx\n",
1382 str2int[1].base, result);
1383 ok(value == 12,
1384 "didn't return expected value (test b): expected: %d, got: %d\n",
1385 12, value);
1386
1387 uni.Length = 2;
1388 result = pRtlUnicodeStringToInteger(&uni, str2int[1].base, &value);
1389 ok(result == STATUS_SUCCESS,
1390 "call failed: RtlUnicodeStringToInteger(\"1\", %d, [out]) has result %lx\n",
1391 str2int[1].base, result);
1392 ok(value == 1,
1393 "didn't return expected value (test c): expected: %d, got: %d\n",
1394 1, value);
1395 /* w2k: uni.Length = 0 returns value 11234567 instead of 0 */
1396 free(wstr);
1397 }
1398
1399
1400 static void test_RtlCharToInteger(void)
1401 {
1402 size_t test_num;
1403 int value;
1404 NTSTATUS result;
1405
1406 for (test_num = 0; test_num < NB_STR2INT; test_num++) {
1407 /* w2k skips a leading '\0' and processes the string after */
1408 if (str2int[test_num].str[0] != '\0') {
1409 value = 0xdeadbeef;
1410 result = pRtlCharToInteger(str2int[test_num].str, str2int[test_num].base, &value);
1411 ok(result == str2int[test_num].result,
1412 "(test %d): call failed: RtlCharToInteger(\"%s\", %d, [out]) has result %lx, expected: %lx\n",
1413 test_num, str2int[test_num].str, str2int[test_num].base, result, str2int[test_num].result);
1414 ok(value == str2int[test_num].value,
1415 "(test %d): call failed: RtlCharToInteger(\"%s\", %d, [out]) assigns value %d, expected: %d\n",
1416 test_num, str2int[test_num].str, str2int[test_num].base, value, str2int[test_num].value);
1417 }
1418 }
1419
1420 result = pRtlCharToInteger(str2int[1].str, str2int[1].base, NULL);
1421 ok(result == STATUS_ACCESS_VIOLATION,
1422 "call failed: RtlCharToInteger(\"%s\", %d, NULL) has result %lx\n",
1423 str2int[1].str, str2int[1].base, result);
1424
1425 result = pRtlCharToInteger(str2int[1].str, 20, NULL);
1426 ok(result == STATUS_INVALID_PARAMETER,
1427 "call failed: RtlCharToInteger(\"%s\", 20, NULL) has result %lx\n",
1428 str2int[1].str, result);
1429 }
1430
1431
1432 #define STRI_BUFFER_LENGTH 35
1433
1434 typedef struct {
1435 int base;
1436 ULONG value;
1437 USHORT Length;
1438 USHORT MaximumLength;
1439 const char *Buffer;
1440 NTSTATUS result;
1441 } int2str_t;
1442
1443 static const int2str_t int2str[] = {
1444 {10, 123, 3, 11, "123\0-------------------------------", STATUS_SUCCESS},
1445
1446 { 0, 0x80000000U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS}, /* min signed int */
1447 { 0, -2147483647, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS},
1448 { 0, -2, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS},
1449 { 0, -1, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS},
1450 { 0, 0, 1, 11, "0\0---------------------------------", STATUS_SUCCESS},
1451 { 0, 1, 1, 11, "1\0---------------------------------", STATUS_SUCCESS},
1452 { 0, 12, 2, 11, "12\0--------------------------------", STATUS_SUCCESS},
1453 { 0, 123, 3, 11, "123\0-------------------------------", STATUS_SUCCESS},
1454 { 0, 1234, 4, 11, "1234\0------------------------------", STATUS_SUCCESS},
1455 { 0, 12345, 5, 11, "12345\0-----------------------------", STATUS_SUCCESS},
1456 { 0, 123456, 6, 11, "123456\0----------------------------", STATUS_SUCCESS},
1457 { 0, 1234567, 7, 11, "1234567\0---------------------------", STATUS_SUCCESS},
1458 { 0, 12345678, 8, 11, "12345678\0--------------------------", STATUS_SUCCESS},
1459 { 0, 123456789, 9, 11, "123456789\0-------------------------", STATUS_SUCCESS},
1460 { 0, 2147483646, 10, 11, "2147483646\0------------------------", STATUS_SUCCESS},
1461 { 0, 2147483647, 10, 11, "2147483647\0------------------------", STATUS_SUCCESS}, /* max signed int */
1462 { 0, 2147483648U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS}, /* uint = -max int */
1463 { 0, 2147483649U, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS},
1464 { 0, 4294967294U, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS},
1465 { 0, 4294967295U, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS}, /* max unsigned int */
1466
1467 { 2, 0x80000000U, 32, 33, "10000000000000000000000000000000\0--", STATUS_SUCCESS}, /* min signed int */
1468 { 2, -2147483647, 32, 33, "10000000000000000000000000000001\0--", STATUS_SUCCESS},
1469 { 2, -2, 32, 33, "11111111111111111111111111111110\0--", STATUS_SUCCESS},
1470 { 2, -1, 32, 33, "11111111111111111111111111111111\0--", STATUS_SUCCESS},
1471 { 2, 0, 1, 33, "0\0---------------------------------", STATUS_SUCCESS},
1472 { 2, 1, 1, 33, "1\0---------------------------------", STATUS_SUCCESS},
1473 { 2, 10, 4, 33, "1010\0------------------------------", STATUS_SUCCESS},
1474 { 2, 100, 7, 33, "1100100\0---------------------------", STATUS_SUCCESS},
1475 { 2, 1000, 10, 33, "1111101000\0------------------------", STATUS_SUCCESS},
1476 { 2, 10000, 14, 33, "10011100010000\0--------------------", STATUS_SUCCESS},
1477 { 2, 32767, 15, 33, "111111111111111\0-------------------", STATUS_SUCCESS},
1478 { 2, 32768, 16, 33, "1000000000000000\0------------------", STATUS_SUCCESS},
1479 { 2, 65535, 16, 33, "1111111111111111\0------------------", STATUS_SUCCESS},
1480 { 2, 65536, 17, 33, "10000000000000000\0-----------------", STATUS_SUCCESS},
1481 { 2, 100000, 17, 33, "11000011010100000\0-----------------", STATUS_SUCCESS},
1482 { 2, 1000000, 20, 33, "11110100001001000000\0--------------", STATUS_SUCCESS},
1483 { 2, 10000000, 24, 33, "100110001001011010000000\0----------", STATUS_SUCCESS},
1484 { 2, 100000000, 27, 33, "101111101011110000100000000\0-------", STATUS_SUCCESS},
1485 { 2, 1000000000, 30, 33, "111011100110101100101000000000\0----", STATUS_SUCCESS},
1486 { 2, 1073741823, 30, 33, "111111111111111111111111111111\0----", STATUS_SUCCESS},
1487 { 2, 2147483646, 31, 33, "1111111111111111111111111111110\0---", STATUS_SUCCESS},
1488 { 2, 2147483647, 31, 33, "1111111111111111111111111111111\0---", STATUS_SUCCESS}, /* max signed int */
1489 { 2, 2147483648U, 32, 33, "10000000000000000000000000000000\0--", STATUS_SUCCESS}, /* uint = -max int */
1490 { 2, 2147483649U, 32, 33, "10000000000000000000000000000001\0--", STATUS_SUCCESS},
1491 { 2, 4294967294U, 32, 33, "11111111111111111111111111111110\0--", STATUS_SUCCESS},
1492 { 2, 4294967295U, 32, 33, "11111111111111111111111111111111\0--", STATUS_SUCCESS}, /* max unsigned int */
1493
1494 { 8, 0x80000000U, 11, 12, "20000000000\0-----------------------", STATUS_SUCCESS}, /* min signed int */
1495 { 8, -2147483647, 11, 12, "20000000001\0-----------------------", STATUS_SUCCESS},
1496 { 8, -2, 11, 12, "37777777776\0-----------------------", STATUS_SUCCESS},
1497 { 8, -1, 11, 12, "37777777777\0-----------------------", STATUS_SUCCESS},
1498 { 8, 0, 1, 12, "0\0---------------------------------", STATUS_SUCCESS},
1499 { 8, 1, 1, 12, "1\0---------------------------------", STATUS_SUCCESS},
1500 { 8, 2147483646, 11, 12, "17777777776\0-----------------------", STATUS_SUCCESS},
1501 { 8, 2147483647, 11, 12, "17777777777\0-----------------------", STATUS_SUCCESS}, /* max signed int */
1502 { 8, 2147483648U, 11, 12, "20000000000\0-----------------------", STATUS_SUCCESS}, /* uint = -max int */
1503 { 8, 2147483649U, 11, 12, "20000000001\0-----------------------", STATUS_SUCCESS},
1504 { 8, 4294967294U, 11, 12, "37777777776\0-----------------------", STATUS_SUCCESS},
1505 { 8, 4294967295U, 11, 12, "37777777777\0-----------------------", STATUS_SUCCESS}, /* max unsigned int */
1506
1507 {10, 0x80000000U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS}, /* min signed int */
1508 {10, -2147483647, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS},
1509 {10, -2, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS},
1510 {10, -1, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS},
1511 {10, 0, 1, 11, "0\0---------------------------------", STATUS_SUCCESS},
1512 {10, 1, 1, 11, "1\0---------------------------------", STATUS_SUCCESS},
1513 {10, 2147483646, 10, 11, "2147483646\0------------------------", STATUS_SUCCESS},
1514 {10, 2147483647, 10, 11, "2147483647\0------------------------", STATUS_SUCCESS}, /* max signed int */
1515 {10, 2147483648U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS}, /* uint = -max int */
1516 {10, 2147483649U, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS},
1517 {10, 4294967294U, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS},
1518 {10, 4294967295U, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS}, /* max unsigned int */
1519
1520 {16, 0x80000000U, 8, 9, "80000000\0--------------------------", STATUS_SUCCESS}, /* min signed int */
1521 {16, -2147483647, 8, 9, "80000001\0--------------------------", STATUS_SUCCESS},
1522 {16, -2, 8, 9, "FFFFFFFE\0--------------------------", STATUS_SUCCESS},
1523 {16, -1, 8, 9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS},
1524 {16, 0, 1, 9, "0\0---------------------------------", STATUS_SUCCESS},
1525 {16, 1, 1, 9, "1\0---------------------------------", STATUS_SUCCESS},
1526 {16, 2147483646, 8, 9, "7FFFFFFE\0--------------------------", STATUS_SUCCESS},
1527 {16, 2147483647, 8, 9, "7FFFFFFF\0--------------------------", STATUS_SUCCESS}, /* max signed int */
1528 {16, 2147483648U, 8, 9, "80000000\0--------------------------", STATUS_SUCCESS}, /* uint = -max int */
1529 {16, 2147483649U, 8, 9, "80000001\0--------------------------", STATUS_SUCCESS},
1530 {16, 4294967294U, 8, 9, "FFFFFFFE\0--------------------------", STATUS_SUCCESS},
1531 {16, 4294967295U, 8, 9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS}, /* max unsigned int */
1532
1533 { 2, 32768, 16, 17, "1000000000000000\0------------------", STATUS_SUCCESS},
1534 { 2, 32768, 16, 16, "1000000000000000-------------------", STATUS_SUCCESS},
1535 { 2, 65536, 17, 18, "10000000000000000\0-----------------", STATUS_SUCCESS},
1536 { 2, 65536, 17, 17, "10000000000000000------------------", STATUS_SUCCESS},
1537 { 2, 131072, 18, 19, "100000000000000000\0----------------", STATUS_SUCCESS},
1538 { 2, 131072, 18, 18, "100000000000000000-----------------", STATUS_SUCCESS},
1539 {16, 0xffffffff, 8, 9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS},
1540 {16, 0xffffffff, 8, 8, "FFFFFFFF---------------------------", STATUS_SUCCESS}, /* No \0 term */
1541 {16, 0xffffffff, 8, 7, "-----------------------------------", STATUS_BUFFER_OVERFLOW}, /* Too short */
1542 {16, 0xa, 1, 2, "A\0---------------------------------", STATUS_SUCCESS},
1543 {16, 0xa, 1, 1, "A----------------------------------", STATUS_SUCCESS}, /* No \0 term */
1544 {16, 0, 1, 0, "-----------------------------------", STATUS_BUFFER_OVERFLOW},
1545 {20, 0xdeadbeef, 0, 9, "-----------------------------------", STATUS_INVALID_PARAMETER}, /* ill. base */
1546 {-8, 07654321, 0, 12, "-----------------------------------", STATUS_INVALID_PARAMETER}, /* neg. base */
1547 };
1548 #define NB_INT2STR (sizeof(int2str)/sizeof(*int2str))
1549
1550
1551 static void one_RtlIntegerToUnicodeString_test(int test_num, const int2str_t *int2str)
1552 {
1553 int pos;
1554 WCHAR expected_str_Buffer[STRI_BUFFER_LENGTH + 1];
1555 UNICODE_STRING expected_unicode_string;
1556 STRING expected_ansi_str;
1557 WCHAR str_Buffer[STRI_BUFFER_LENGTH + 1];
1558 UNICODE_STRING unicode_string;
1559 STRING ansi_str;
1560 NTSTATUS result;
1561
1562 for (pos = 0; pos < STRI_BUFFER_LENGTH; pos++) {
1563 expected_str_Buffer[pos] = int2str->Buffer[pos];
1564 }
1565 expected_unicode_string.Length = int2str->Length * sizeof(WCHAR);
1566 expected_unicode_string.MaximumLength = int2str->MaximumLength * sizeof(WCHAR);
1567 expected_unicode_string.Buffer = expected_str_Buffer;
1568 pRtlUnicodeStringToAnsiString(&expected_ansi_str, &expected_unicode_string, 1);
1569
1570 for (pos = 0; pos < STRI_BUFFER_LENGTH; pos++) {
1571 str_Buffer[pos] = '-';
1572 }
1573 unicode_string.Length = 0;
1574 unicode_string.MaximumLength = int2str->MaximumLength * sizeof(WCHAR);
1575 unicode_string.Buffer = str_Buffer;
1576
1577 result = pRtlIntegerToUnicodeString(int2str->value, int2str->base, &unicode_string);
1578 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
1579 if (result == STATUS_BUFFER_OVERFLOW) {
1580 /* On BUFFER_OVERFLOW the string Buffer should be unchanged */
1581 for (pos = 0; pos < STRI_BUFFER_LENGTH; pos++) {
1582 expected_str_Buffer[pos] = '-';
1583 }
1584 /* w2k: The native function has two reasons for BUFFER_OVERFLOW: */
1585 /* If the value is too large to convert: The Length is unchanged */
1586 /* If str is too small to hold the string: Set str->Length to the length */
1587 /* the string would have (which can be larger than the MaximumLength). */
1588 /* To allow all this in the tests we do the following: */
1589 if (expected_unicode_string.Length > 32 && unicode_string.Length == 0) {
1590 /* The value is too large to convert only triggerd when testing native */
1591 expected_unicode_string.Length = 0;
1592 }
1593 } else {
1594 ok(result == int2str->result,
1595 "(test %d): RtlIntegerToUnicodeString(%lu, %d, [out]) has result %lx, expected: %lx\n",
1596 test_num, int2str->value, int2str->base, result, int2str->result);
1597 if (result == STATUS_SUCCESS) {
1598 ok(unicode_string.Buffer[unicode_string.Length/sizeof(WCHAR)] == '\0',
1599 "(test %d): RtlIntegerToUnicodeString(%lu, %d, [out]) string \"%s\" is not NULL terminated\n",
1600 test_num, int2str->value, int2str->base, ansi_str.Buffer);
1601 }
1602 }
1603 ok(memcmp(unicode_string.Buffer, expected_unicode_string.Buffer, STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
1604 "(test %d): RtlIntegerToUnicodeString(%lu, %d, [out]) assigns string \"%s\", expected: \"%s\"\n",
1605 test_num, int2str->value, int2str->base, ansi_str.Buffer, expected_ansi_str.Buffer);
1606 ok(unicode_string.Length == expected_unicode_string.Length,
1607 "(test %d): RtlIntegerToUnicodeString(%lu, %d, [out]) string has Length %d, expected: %d\n",
1608 test_num, int2str->value, int2str->base, unicode_string.Length, expected_unicode_string.Length);
1609 ok(unicode_string.MaximumLength == expected_unicode_string.MaximumLength,
1610 "(test %d): RtlIntegerToUnicodeString(%lu, %d, [out]) string has MaximumLength %d, expected: %d\n",
1611 test_num, int2str->value, int2str->base, unicode_string.MaximumLength, expected_unicode_string.MaximumLength);
1612 pRtlFreeAnsiString(&expected_ansi_str);
1613 pRtlFreeAnsiString(&ansi_str);
1614 }
1615
1616
1617 static void test_RtlIntegerToUnicodeString(void)
1618 {
1619 size_t test_num;
1620
1621 for (test_num = 0; test_num < NB_INT2STR; test_num++)
1622 one_RtlIntegerToUnicodeString_test(test_num, &int2str[test_num]);
1623 }
1624
1625
1626 static void one_RtlIntegerToChar_test(int test_num, const int2str_t *int2str)
1627 {
1628 NTSTATUS result;
1629 char dest_str[STRI_BUFFER_LENGTH + 1];
1630
1631 memset(dest_str, '-', STRI_BUFFER_LENGTH);
1632 dest_str[STRI_BUFFER_LENGTH] = '\0';
1633 result = pRtlIntegerToChar(int2str->value, int2str->base, int2str->MaximumLength, dest_str);
1634 ok(result == int2str->result,
1635 "(test %d): RtlIntegerToChar(%lu, %d, %d, [out]) has result %lx, expected: %lx\n",
1636 test_num, int2str->value, int2str->base, int2str->MaximumLength, result, int2str->result);
1637 ok(memcmp(dest_str, int2str->Buffer, STRI_BUFFER_LENGTH) == 0,
1638 "(test %d): RtlIntegerToChar(%lu, %d, %d, [out]) assigns string \"%s\", expected: \"%s\"\n",
1639 test_num, int2str->value, int2str->base, int2str->MaximumLength, dest_str, int2str->Buffer);
1640 }
1641
1642
1643 static void test_RtlIntegerToChar(void)
1644 {
1645 NTSTATUS result;
1646 size_t test_num;
1647
1648 for (test_num = 0; test_num < NB_INT2STR; test_num++)
1649 one_RtlIntegerToChar_test(test_num, &int2str[test_num]);
1650
1651 result = pRtlIntegerToChar(int2str[0].value, 20, int2str[0].MaximumLength, NULL);
1652 ok(result == STATUS_INVALID_PARAMETER,
1653 "(test a): RtlIntegerToChar(%lu, %d, %d, NULL) has result %lx, expected: %lx\n",
1654 int2str[0].value, 20, int2str[0].MaximumLength, result, STATUS_INVALID_PARAMETER);
1655
1656 result = pRtlIntegerToChar(int2str[0].value, 20, 0, NULL);
1657 ok(result == STATUS_INVALID_PARAMETER,
1658 "(test b): RtlIntegerToChar(%lu, %d, %d, NULL) has result %lx, expected: %lx\n",
1659 int2str[0].value, 20, 0, result, STATUS_INVALID_PARAMETER);
1660
1661 result = pRtlIntegerToChar(int2str[0].value, int2str[0].base, 0, NULL);
1662 ok(result == STATUS_BUFFER_OVERFLOW,
1663 "(test c): RtlIntegerToChar(%lu, %d, %d, NULL) has result %lx, expected: %lx\n",
1664 int2str[0].value, int2str[0].base, 0, result, STATUS_BUFFER_OVERFLOW);
1665
1666 result = pRtlIntegerToChar(int2str[0].value, int2str[0].base, int2str[0].MaximumLength, NULL);
1667 ok(result == STATUS_ACCESS_VIOLATION,
1668 "(test d): RtlIntegerToChar(%lu, %d, %d, NULL) has result %lx, expected: %lx\n",
1669 int2str[0].value, int2str[0].base, int2str[0].MaximumLength, result, STATUS_ACCESS_VIOLATION);
1670 }
1671
1672 static const WCHAR szGuid[] = { '{','0','1','0','2','0','3','0','4','-',
1673 '0','5','0','6','-' ,'0','7','0','8','-','0','9','0','A','-',
1674 '0','B','0','C','0','D','0','E','0','F','0','A','}','\0' };
1675 static const WCHAR szGuid2[] = { '{','0','1','0','2','0','3','0','4','-',
1676 '0','5','0','6','-' ,'0','7','0','8','-','0','9','0','A','-',
1677 '0','B','0','C','0','D','0','E','0','F','0','A',']','\0' };
1678 DEFINE_GUID(IID_Endianess, 0x01020304, 0x0506, 0x0708, 0x09, 0x0A, 0x0B,
1679 0x0C, 0x0D, 0x0E, 0x0F, 0x0A);
1680
1681 static void test_RtlGUIDFromString(void)
1682 {
1683 GUID guid;
1684 UNICODE_STRING str;
1685 NTSTATUS ret;
1686
1687 str.Length = str.MaximumLength = (sizeof(szGuid) - 1) / sizeof(WCHAR);
1688 str.Buffer = (LPWSTR)szGuid;
1689
1690 ret = pRtlGUIDFromString(&str, &guid);
1691 ok(ret == 0, "expected ret=0, got 0x%0lx\n", ret);
1692 ok(memcmp(&guid, &IID_Endianess, sizeof(guid)) == 0, "Endianess broken\n");
1693
1694 str.Length = str.MaximumLength = (sizeof(szGuid2) - 1) / sizeof(WCHAR);
1695 str.Buffer = (LPWSTR)szGuid2;
1696
1697 ret = pRtlGUIDFromString(&str, &guid);
1698 ok(ret, "expected ret!=0\n");
1699 }
1700
1701 static void test_RtlStringFromGUID(void)
1702 {
1703 UNICODE_STRING str;
1704 NTSTATUS ret;
1705
1706 str.Length = str.MaximumLength = 0;
1707 str.Buffer = NULL;
1708
1709 ret = pRtlStringFromGUID(&IID_Endianess, &str);
1710 ok(ret == 0, "expected ret=0, got 0x%0lx\n", ret);
1711 ok(str.Buffer && !lstrcmpW(str.Buffer, szGuid), "Endianess broken\n");
1712 }
1713
1714 START_TEST(rtlstr)
1715 {
1716 InitFunctionPtrs();
1717 if (pRtlInitAnsiString) {
1718 test_RtlInitString();
1719 test_RtlInitUnicodeString();
1720 test_RtlCopyString();
1721 test_RtlUnicodeStringToInteger();
1722 test_RtlCharToInteger();
1723 test_RtlIntegerToUnicodeString();
1724 test_RtlIntegerToChar();
1725 test_RtlUpperChar();
1726 test_RtlUpperString();
1727 test_RtlUnicodeStringToAnsiString();
1728 test_RtlAppendAsciizToString();
1729 test_RtlAppendStringToString();
1730 test_RtlAppendUnicodeToString();
1731 test_RtlAppendUnicodeStringToString();
1732 }
1733
1734 if (pRtlInitUnicodeStringEx)
1735 test_RtlInitUnicodeStringEx();
1736 if (pRtlDuplicateUnicodeString)
1737 test_RtlDuplicateUnicodeString();
1738 if (pRtlFindCharInUnicodeString)
1739 test_RtlFindCharInUnicodeString();
1740 if (pRtlGUIDFromString)
1741 test_RtlGUIDFromString();
1742 if (pRtlStringFromGUID)
1743 test_RtlStringFromGUID();
1744 if(0)
1745 {
1746 test_RtlUpcaseUnicodeChar();
1747 test_RtlUpcaseUnicodeString();
1748 test_RtlDowncaseUnicodeString();
1749 }
1750 }