1 /* Unit test suite for Rtl string functions
3 * Copyright 2002 Robert Shearman
4 * Copyright 2003 Thomas Mertes
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * We use function pointers here as there is no import library for NTDLL on
28 #include "wine/test.h"
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)(char *, 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 *);
64 /*static VOID (WINAPI *pRtlFreeOemString)(PSTRING);*/
65 /*static VOID (WINAPI *pRtlFreeUnicodeString)(PUNICODE_STRING);*/
66 /*static VOID (WINAPI *pRtlCopyUnicodeString)(UNICODE_STRING *, const UNICODE_STRING *);*/
67 /*static VOID (WINAPI *pRtlEraseUnicodeString)(UNICODE_STRING *);*/
68 /*static LONG (WINAPI *pRtlCompareString)(const STRING *,const STRING *,BOOLEAN);*/
69 /*static LONG (WINAPI *pRtlCompareUnicodeString)(const UNICODE_STRING *,const UNICODE_STRING *,BOOLEAN);*/
70 /*static BOOLEAN (WINAPI *pRtlEqualString)(const STRING *,const STRING *,BOOLEAN);*/
71 /*static BOOLEAN (WINAPI *pRtlPrefixString)(const STRING *, const STRING *, BOOLEAN);*/
72 /*static BOOLEAN (WINAPI *pRtlPrefixUnicodeString)(const UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN);*/
73 /*static NTSTATUS (WINAPI *pRtlOemStringToUnicodeString)(PUNICODE_STRING, const STRING *, BOOLEAN);*/
74 /*static NTSTATUS (WINAPI *pRtlUnicodeStringToOemString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/
75 /*static NTSTATUS (WINAPI *pRtlMultiByteToUnicodeN)(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD);*/
76 /*static NTSTATUS (WINAPI *pRtlOemToUnicodeN)(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD);*/
77 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeStringToAnsiString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/
78 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeStringToOemString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/
79 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeToMultiByteN)(LPSTR, DWORD, LPDWORD, LPCWSTR, DWORD);*/
80 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeToOemN)(LPSTR, DWORD, LPDWORD, LPCWSTR, DWORD);*/
81 /*static UINT (WINAPI *pRtlOemToUnicodeSize)(const STRING *);*/
82 /*static DWORD (WINAPI *pRtlAnsiStringToUnicodeSize)(const STRING *);*/
83 /*static DWORD (WINAPI *pRtlIsTextUnicode)(LPVOID, DWORD, DWORD *);*/
86 static WCHAR* AtoW( char* p )
89 DWORD len = MultiByteToWideChar( CP_ACP, 0, p, -1, NULL, 0 );
90 buffer = malloc( len * sizeof(WCHAR) );
91 MultiByteToWideChar( CP_ACP, 0, p, -1, buffer, len );
96 static void InitFunctionPtrs(void)
98 hntdll = LoadLibraryA("ntdll.dll");
99 ok(hntdll != 0, "LoadLibrary failed");
101 pRtlAnsiStringToUnicodeString = (void *)GetProcAddress(hntdll, "RtlAnsiStringToUnicodeString");
102 pRtlAppendAsciizToString = (void *)GetProcAddress(hntdll, "RtlAppendAsciizToString");
103 pRtlAppendStringToString = (void *)GetProcAddress(hntdll, "RtlAppendStringToString");
104 pRtlAppendUnicodeStringToString = (void *)GetProcAddress(hntdll, "RtlAppendUnicodeStringToString");
105 pRtlAppendUnicodeToString = (void *)GetProcAddress(hntdll, "RtlAppendUnicodeToString");
106 pRtlCharToInteger = (void *)GetProcAddress(hntdll, "RtlCharToInteger");
107 pRtlCopyString = (void *)GetProcAddress(hntdll, "RtlCopyString");
108 pRtlCreateUnicodeString = (void *)GetProcAddress(hntdll, "RtlCreateUnicodeString");
109 pRtlCreateUnicodeStringFromAsciiz = (void *)GetProcAddress(hntdll, "RtlCreateUnicodeStringFromAsciiz");
110 pRtlDowncaseUnicodeString = (void *)GetProcAddress(hntdll, "RtlDowncaseUnicodeString");
111 pRtlDuplicateUnicodeString = (void *)GetProcAddress(hntdll, "RtlDuplicateUnicodeString");
112 pRtlEqualUnicodeString = (void *)GetProcAddress(hntdll, "RtlEqualUnicodeString");
113 pRtlFindCharInUnicodeString = (void *)GetProcAddress(hntdll, "RtlFindCharInUnicodeString");
114 pRtlFreeAnsiString = (void *)GetProcAddress(hntdll, "RtlFreeAnsiString");
115 pRtlInitAnsiString = (void *)GetProcAddress(hntdll, "RtlInitAnsiString");
116 pRtlInitString = (void *)GetProcAddress(hntdll, "RtlInitString");
117 pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
118 pRtlInitUnicodeStringEx = (void *)GetProcAddress(hntdll, "RtlInitUnicodeStringEx");
119 pRtlIntegerToChar = (void *)GetProcAddress(hntdll, "RtlIntegerToChar");
120 pRtlIntegerToUnicodeString = (void *)GetProcAddress(hntdll, "RtlIntegerToUnicodeString");
121 pRtlMultiAppendUnicodeStringBuffer = (void *)GetProcAddress(hntdll, "RtlMultiAppendUnicodeStringBuffer");
122 pRtlUnicodeStringToAnsiString = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToAnsiString");
123 pRtlUnicodeStringToInteger = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToInteger");
124 pRtlUpcaseUnicodeChar = (void *)GetProcAddress(hntdll, "RtlUpcaseUnicodeChar");
125 pRtlUpcaseUnicodeString = (void *)GetProcAddress(hntdll, "RtlUpcaseUnicodeString");
126 pRtlUpperChar = (void *)GetProcAddress(hntdll, "RtlUpperChar");
127 pRtlUpperString = (void *)GetProcAddress(hntdll, "RtlUpperString");
128 pRtlValidateUnicodeString = (void *)GetProcAddress(hntdll, "RtlValidateUnicodeString");
133 static void test_RtlInitString(void)
135 static const char teststring[] = "Some Wild String";
139 str.MaximumLength = 0;
140 str.Buffer = (void *)0xdeadbeef;
141 pRtlInitString(&str, teststring);
142 ok(str.Length == sizeof(teststring) - sizeof(char), "Length uninitialized");
143 ok(str.MaximumLength == sizeof(teststring), "MaximumLength uninitialized");
144 ok(str.Buffer == teststring, "Buffer not equal to teststring");
145 ok(strcmp(str.Buffer, "Some Wild String") == 0, "Buffer written to");
146 pRtlInitString(&str, NULL);
147 ok(str.Length == 0, "Length uninitialized");
148 ok(str.MaximumLength == 0, "MaximumLength uninitialized");
149 ok(str.Buffer == NULL, "Buffer not equal to NULL");
150 /* pRtlInitString(NULL, teststring); */
154 static void test_RtlInitUnicodeString(void)
156 #define STRINGW {'S','o','m','e',' ','W','i','l','d',' ','S','t','r','i','n','g',0}
157 static const WCHAR teststring[] = STRINGW;
158 static const WCHAR originalstring[] = STRINGW;
163 uni.MaximumLength = 0;
164 uni.Buffer = (void *)0xdeadbeef;
165 pRtlInitUnicodeString(&uni, teststring);
166 ok(uni.Length == sizeof(teststring) - sizeof(WCHAR), "Length uninitialized");
167 ok(uni.MaximumLength == sizeof(teststring), "MaximumLength uninitialized");
168 ok(uni.Buffer == teststring, "Buffer not equal to teststring");
169 ok(lstrcmpW(uni.Buffer, originalstring) == 0, "Buffer written to");
170 pRtlInitUnicodeString(&uni, NULL);
171 ok(uni.Length == 0, "Length uninitialized");
172 ok(uni.MaximumLength == 0, "MaximumLength uninitialized");
173 ok(uni.Buffer == NULL, "Buffer not equal to NULL");
174 /* pRtlInitUnicodeString(NULL, teststring); */
178 #define TESTSTRING2_LEN 1000000
179 /* #define TESTSTRING2_LEN 32766 */
182 static void test_RtlInitUnicodeStringEx(void)
184 WCHAR teststring[] = {'S','o','m','e',' ','W','i','l','d',' ','S','t','r','i','n','g',0};
189 teststring2 = (WCHAR *) malloc((TESTSTRING2_LEN + 1) * sizeof(WCHAR));
190 memset(teststring2, 'X', TESTSTRING2_LEN * sizeof(WCHAR));
191 teststring2[TESTSTRING2_LEN] = '\0';
194 uni.MaximumLength = 12345;
195 uni.Buffer = (void *) 0xdeadbeef;
196 result = pRtlInitUnicodeStringEx(&uni, teststring);
197 ok(result == STATUS_SUCCESS,
198 "pRtlInitUnicodeStringEx(&uni, 0) returns %lx, expected %x",
199 result, STATUS_SUCCESS);
201 "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected %u",
203 ok(uni.MaximumLength == 34,
204 "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected %u",
205 uni.MaximumLength, 34);
206 ok(uni.Buffer == teststring,
207 "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %p",
208 uni.Buffer, teststring);
211 uni.MaximumLength = 12345;
212 uni.Buffer = (void *) 0xdeadbeef;
213 pRtlInitUnicodeString(&uni, teststring);
215 "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u",
217 ok(uni.MaximumLength == 34,
218 "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u",
219 uni.MaximumLength, 34);
220 ok(uni.Buffer == teststring,
221 "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p",
222 uni.Buffer, teststring);
225 uni.MaximumLength = 12345;
226 uni.Buffer = (void *) 0xdeadbeef;
227 result = pRtlInitUnicodeStringEx(&uni, teststring2);
228 ok(result == STATUS_NAME_TOO_LONG,
229 "pRtlInitUnicodeStringEx(&uni, 0) returns %lx, expected %x",
230 result, STATUS_NAME_TOO_LONG);
231 ok(uni.Length == 12345,
232 "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected %u",
234 ok(uni.MaximumLength == 12345,
235 "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected %u",
236 uni.MaximumLength, 12345);
237 ok(uni.Buffer == (void *) 0xdeadbeef,
238 "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %x",
239 uni.Buffer, 0xdeadbeef);
242 uni.MaximumLength = 12345;
243 uni.Buffer = (void *) 0xdeadbeef;
244 pRtlInitUnicodeString(&uni, teststring2);
245 ok(uni.Length == 33920,
246 "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u",
248 ok(uni.MaximumLength == 33922,
249 "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u",
250 uni.MaximumLength, 33922);
251 ok(uni.Buffer == teststring2,
252 "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p",
253 uni.Buffer, teststring2);
254 ok(memcmp(uni.Buffer, teststring2, (TESTSTRING2_LEN + 1) * sizeof(WCHAR)) == 0,
255 "pRtlInitUnicodeString(&uni, 0) changes Buffer");
258 uni.MaximumLength = 12345;
259 uni.Buffer = (void *) 0xdeadbeef;
260 result = pRtlInitUnicodeStringEx(&uni, 0);
261 ok(result == STATUS_SUCCESS,
262 "pRtlInitUnicodeStringEx(&uni, 0) returns %lx, expected %x",
263 result, STATUS_SUCCESS);
265 "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected %u",
267 ok(uni.MaximumLength == 0,
268 "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected %u",
269 uni.MaximumLength, 0);
270 ok(uni.Buffer == NULL,
271 "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %p",
275 uni.MaximumLength = 12345;
276 uni.Buffer = (void *) 0xdeadbeef;
277 pRtlInitUnicodeString(&uni, 0);
279 "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u",
281 ok(uni.MaximumLength == 0,
282 "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u",
283 uni.MaximumLength, 0);
284 ok(uni.Buffer == NULL,
285 "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p",
293 int source_MaximumLength;
297 int dest_MaximumLength;
301 int res_MaximumLength;
307 static const dupl_ustr_t dupl_ustr[] = {
308 { 0, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 32, 32, "This is a string", STATUS_SUCCESS},
309 { 0, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 32, 32, "This is a string", STATUS_SUCCESS},
310 { 0, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
311 { 0, 32, 34, 34, "This is a string", 40, 42, 42, NULL, 32, 32, 32, "This is a string", STATUS_SUCCESS},
312 { 0, 32, 32, 32, "This is a string", 40, 42, 42, NULL, 32, 32, 32, "This is a string", STATUS_SUCCESS},
313 { 0, 32, 30, 34, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
314 { 1, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS},
315 { 1, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS},
316 { 1, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
317 { 1, 32, 34, 34, "This is a string", 40, 42, 42, NULL, 32, 34, 34, "This is a string", STATUS_SUCCESS},
318 { 1, 32, 32, 32, "This is a string", 40, 42, 42, NULL, 32, 34, 34, "This is a string", STATUS_SUCCESS},
319 { 1, 32, 30, 34, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
320 { 2, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
321 { 2, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
322 { 2, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
323 { 2, 32, 34, 34, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
324 { 2, 32, 32, 32, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
325 { 2, 32, 30, 34, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
326 { 3, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS},
327 { 3, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS},
328 { 3, 32, 30, 32, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
329 { 3, 32, 34, 34, "This is a string", 40, 42, 42, NULL, 32, 34, 34, "This is a string", STATUS_SUCCESS},
330 { 3, 32, 32, 32, "This is a string", 40, 42, 42, NULL, 32, 34, 34, "This is a string", STATUS_SUCCESS},
331 { 3, 32, 30, 32, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
332 { 4, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
333 { 5, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
334 { 6, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
335 { 7, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
336 { 8, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
337 { 9, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
338 {10, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
339 {11, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
340 {12, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
341 {13, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
342 {14, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
343 {15, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
344 {16, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
345 {-1, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
346 {-5, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
347 {-9, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
348 { 0, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
349 { 0, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
350 { 0, 0, 2, 2, "", 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
351 { 0, 0, 0, 0, "", 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
352 { 0, 0, 2, 2, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
353 { 0, 0, 0, 0, NULL, 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
354 { 0, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
355 { 0, 0, 0, 0, NULL, 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
356 { 1, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
357 { 1, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
358 { 1, 0, 2, 2, "", 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
359 { 1, 0, 0, 0, "", 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
360 { 1, 0, 2, 2, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
361 { 1, 0, 0, 0, NULL, 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
362 { 1, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
363 { 1, 0, 0, 0, NULL, 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
364 { 2, 0, 2, 2, "", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
365 { 2, 0, 0, 0, "", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
366 { 2, 0, 2, 2, "", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
367 { 2, 0, 0, 0, "", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
368 { 2, 0, 2, 2, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
369 { 2, 0, 0, 0, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
370 { 2, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
371 { 2, 0, 0, 0, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
372 { 3, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS},
373 { 3, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS},
374 { 3, 0, 2, 2, "", 40, 42, 42, NULL, 0, 2, 2, "", STATUS_SUCCESS},
375 { 3, 0, 0, 0, "", 40, 42, 42, NULL, 0, 2, 2, "", STATUS_SUCCESS},
376 { 3, 0, 2, 2, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
377 { 3, 0, 0, 0, NULL, 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS},
378 { 3, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
379 { 3, 0, 0, 0, NULL, 40, 42, 42, NULL, 0, 2, 2, "", STATUS_SUCCESS},
381 #define NB_DUPL_USTR (sizeof(dupl_ustr)/sizeof(*dupl_ustr))
384 static void test_RtlDuplicateUnicodeString(void)
387 WCHAR source_buf[257];
390 UNICODE_STRING source_str;
391 UNICODE_STRING dest_str;
392 UNICODE_STRING res_str;
393 CHAR dest_ansi_buf[257];
394 STRING dest_ansi_str;
398 for (test_num = 0; test_num < NB_DUPL_USTR; test_num++) {
399 source_str.Length = dupl_ustr[test_num].source_Length;
400 source_str.MaximumLength = dupl_ustr[test_num].source_MaximumLength;
401 if (dupl_ustr[test_num].source_buf != NULL) {
402 for (pos = 0; pos < dupl_ustr[test_num].source_buf_size/sizeof(WCHAR); pos++) {
403 source_buf[pos] = dupl_ustr[test_num].source_buf[pos];
405 source_str.Buffer = source_buf;
407 source_str.Buffer = NULL;
409 dest_str.Length = dupl_ustr[test_num].dest_Length;
410 dest_str.MaximumLength = dupl_ustr[test_num].dest_MaximumLength;
411 if (dupl_ustr[test_num].dest_buf != NULL) {
412 for (pos = 0; pos < dupl_ustr[test_num].dest_buf_size/sizeof(WCHAR); pos++) {
413 dest_buf[pos] = dupl_ustr[test_num].dest_buf[pos];
415 dest_str.Buffer = dest_buf;
417 dest_str.Buffer = NULL;
419 res_str.Length = dupl_ustr[test_num].res_Length;
420 res_str.MaximumLength = dupl_ustr[test_num].res_MaximumLength;
421 if (dupl_ustr[test_num].res_buf != NULL) {
422 for (pos = 0; pos < dupl_ustr[test_num].res_buf_size/sizeof(WCHAR); pos++) {
423 res_buf[pos] = dupl_ustr[test_num].res_buf[pos];
425 res_str.Buffer = res_buf;
427 res_str.Buffer = NULL;
429 result = pRtlDuplicateUnicodeString(dupl_ustr[test_num].add_nul, &source_str, &dest_str);
430 dest_ansi_str.Length = dest_str.Length / sizeof(WCHAR);
431 dest_ansi_str.MaximumLength = dest_ansi_str.Length + 1;
432 for (pos = 0; pos < dest_ansi_str.Length; pos++) {
433 dest_ansi_buf[pos] = dest_buf[pos];
435 dest_ansi_buf[dest_ansi_str.Length] = '\0';
436 dest_ansi_str.Buffer = dest_ansi_buf;
437 ok(result == dupl_ustr[test_num].result,
438 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has result %lx, expected %lx",
439 test_num, dupl_ustr[test_num].add_nul, result, dupl_ustr[test_num].result);
440 ok(dest_str.Length == dupl_ustr[test_num].res_Length,
441 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination has Length %d, expected %d",
442 test_num, dupl_ustr[test_num].add_nul, dest_str.Length, dupl_ustr[test_num].res_Length);
443 ok(dest_str.MaximumLength == dupl_ustr[test_num].res_MaximumLength,
444 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination has MaximumLength %d, expected %d",
445 test_num, dupl_ustr[test_num].add_nul, dest_str.MaximumLength, dupl_ustr[test_num].res_MaximumLength);
446 if (result == STATUS_INVALID_PARAMETER) {
447 ok((dest_str.Buffer == NULL && res_str.Buffer == NULL) ||
448 dest_str.Buffer == dest_buf,
449 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination buffer changed %p expected %p",
450 test_num, dupl_ustr[test_num].add_nul, dest_str.Buffer, dest_buf);
452 ok(dest_str.Buffer != dest_buf,
453 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination buffer unchanged %p",
454 test_num, dupl_ustr[test_num].add_nul, dest_str.Buffer);
456 if (dest_str.Buffer != NULL && dupl_ustr[test_num].res_buf != NULL) {
457 ok(memcmp(dest_str.Buffer, res_str.Buffer, dupl_ustr[test_num].res_buf_size) == 0,
458 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination \"%s\" expected \"%s\"",
459 test_num, dupl_ustr[test_num].add_nul, dest_ansi_str.Buffer, dupl_ustr[test_num].res_buf);
461 ok(dest_str.Buffer == NULL && dupl_ustr[test_num].res_buf == NULL,
462 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination %p expected %p",
463 test_num, dupl_ustr[test_num].add_nul, dest_str.Buffer, dupl_ustr[test_num].res_buf);
469 static void test_RtlCopyString(void)
471 static const char teststring[] = "Some Wild String";
472 static char deststring[] = " ";
476 pRtlInitString(&str, teststring);
477 pRtlInitString(&deststr, deststring);
478 pRtlCopyString(&deststr, &str);
479 ok(strncmp(str.Buffer, deststring, str.Length) == 0, "String not copied");
483 static void test_RtlUpperChar(void)
487 int expected_upper_ch;
490 for (ch = -1; ch <= 1024; ch++) {
491 upper_ch = pRtlUpperChar(ch);
493 if (byte_ch >= 'a' && byte_ch <= 'z') {
494 expected_upper_ch = (CHAR) (byte_ch - 'a' + 'A');
496 expected_upper_ch = (CHAR) byte_ch;
498 ok(upper_ch == expected_upper_ch,
499 "RtlUpperChar('%c'[=0x%x]) has result '%c'[=0x%x], expected '%c'[=0x%x]",
500 ch, ch, upper_ch, upper_ch, expected_upper_ch, expected_upper_ch);
505 static void test_RtlUpperString(void)
511 char result_buf[257];
517 for (i = 0; i <= 255; i++) {
519 if (ch >= 'a' && ch <= 'z') {
520 upper_ch = ch - 'a' + 'A';
525 result_buf[i] = '\0';
526 upper_buf[i] = upper_ch;
529 result_buf[i] = '\0';
531 ascii_str.Length = 256;
532 ascii_str.MaximumLength = 256;
533 ascii_str.Buffer = ascii_buf;
534 result_str.Length = 256;
535 result_str.MaximumLength = 256;
536 result_str.Buffer = result_buf;
537 upper_str.Length = 256;
538 upper_str.MaximumLength = 256;
539 upper_str.Buffer = upper_buf;
541 pRtlUpperString(&result_str, &ascii_str);
542 ok(memcmp(result_str.Buffer, upper_str.Buffer, 256) == 0,
543 "RtlUpperString does not work as expected");
547 static void test_RtlUpcaseUnicodeChar(void)
552 WCHAR expected_upper_ch;
554 for (i = 0; i <= 255; i++) {
556 upper_ch = pRtlUpcaseUnicodeChar(ch);
557 if (ch >= 'a' && ch <= 'z') {
558 expected_upper_ch = ch - 'a' + 'A';
559 } else if (ch >= 0xe0 && ch <= 0xfe && ch != 0xf7) {
560 expected_upper_ch = ch - 0x20;
561 } else if (ch == 0xff) {
562 expected_upper_ch = 0x178;
564 expected_upper_ch = ch;
566 ok(upper_ch == expected_upper_ch,
567 "RtlUpcaseUnicodeChar('%c'[=0x%x]) has result '%c'[=0x%x], expected: '%c'[=0x%x]",
568 ch, ch, upper_ch, upper_ch, expected_upper_ch, expected_upper_ch);
573 static void test_RtlUpcaseUnicodeString(void)
578 WCHAR ascii_buf[257];
579 WCHAR result_buf[257];
580 WCHAR upper_buf[257];
581 UNICODE_STRING ascii_str;
582 UNICODE_STRING result_str;
583 UNICODE_STRING upper_str;
585 for (i = 0; i <= 255; i++) {
587 if (ch >= 'a' && ch <= 'z') {
588 upper_ch = ch - 'a' + 'A';
589 } else if (ch >= 0xe0 && ch <= 0xfe && ch != 0xf7) {
590 upper_ch = ch - 0x20;
591 } else if (ch == 0xff) {
597 result_buf[i] = '\0';
598 upper_buf[i] = upper_ch;
601 result_buf[i] = '\0';
603 ascii_str.Length = 512;
604 ascii_str.MaximumLength = 512;
605 ascii_str.Buffer = ascii_buf;
606 result_str.Length = 512;
607 result_str.MaximumLength = 512;
608 result_str.Buffer = result_buf;
609 upper_str.Length = 512;
610 upper_str.MaximumLength = 512;
611 upper_str.Buffer = upper_buf;
613 pRtlUpcaseUnicodeString(&result_str, &ascii_str, 0);
614 for (i = 0; i <= 255; i++) {
615 ok(result_str.Buffer[i] == upper_str.Buffer[i],
616 "RtlUpcaseUnicodeString works wrong: '%c'[=0x%x] is converted to '%c'[=0x%x], expected: '%c'[=0x%x]",
617 ascii_str.Buffer[i], ascii_str.Buffer[i],
618 result_str.Buffer[i], result_str.Buffer[i],
619 upper_str.Buffer[i], upper_str.Buffer[i]);
624 static void test_RtlDowncaseUnicodeString(void)
629 WCHAR source_buf[1025];
630 WCHAR result_buf[1025];
631 WCHAR lower_buf[1025];
632 UNICODE_STRING source_str;
633 UNICODE_STRING result_str;
634 UNICODE_STRING lower_str;
636 for (i = 0; i <= 1024; i++) {
638 if (ch >= 'A' && ch <= 'Z') {
639 lower_ch = ch - 'A' + 'a';
640 } else if (ch >= 0xc0 && ch <= 0xde && ch != 0xd7) {
641 lower_ch = ch + 0x20;
642 } else if (ch >= 0x391 && ch <= 0x3ab && ch != 0x3a2) {
643 lower_ch = ch + 0x20;
646 case 0x178: lower_ch = 0xff; break;
647 case 0x181: lower_ch = 0x253; break;
648 case 0x186: lower_ch = 0x254; break;
649 case 0x189: lower_ch = 0x256; break;
650 case 0x18a: lower_ch = 0x257; break;
651 case 0x18e: lower_ch = 0x1dd; break;
652 case 0x18f: lower_ch = 0x259; break;
653 case 0x190: lower_ch = 0x25b; break;
654 case 0x193: lower_ch = 0x260; break;
655 case 0x194: lower_ch = 0x263; break;
656 case 0x196: lower_ch = 0x269; break;
657 case 0x197: lower_ch = 0x268; break;
658 case 0x19c: lower_ch = 0x26f; break;
659 case 0x19d: lower_ch = 0x272; break;
660 case 0x19f: lower_ch = 0x275; break;
661 case 0x1a9: lower_ch = 0x283; break;
662 case 0x1ae: lower_ch = 0x288; break;
663 case 0x1b1: lower_ch = 0x28a; break;
664 case 0x1b2: lower_ch = 0x28b; break;
665 case 0x1b7: lower_ch = 0x292; break;
666 case 0x1c4: lower_ch = 0x1c6; break;
667 case 0x1c7: lower_ch = 0x1c9; break;
668 case 0x1ca: lower_ch = 0x1cc; break;
669 case 0x1f1: lower_ch = 0x1f3; break;
670 case 0x386: lower_ch = 0x3ac; break;
671 case 0x388: lower_ch = 0x3ad; break;
672 case 0x389: lower_ch = 0x3ae; break;
673 case 0x38a: lower_ch = 0x3af; break;
674 case 0x38c: lower_ch = 0x3cc; break;
675 case 0x38e: lower_ch = 0x3cd; break;
676 case 0x38f: lower_ch = 0x3ce; break;
677 case 0x400: lower_ch = 0x0; break;
678 default: lower_ch = ch; break;
682 result_buf[i] = '\0';
683 lower_buf[i] = lower_ch;
685 source_buf[i] = '\0';
686 result_buf[i] = '\0';
688 source_str.Length = 2048;
689 source_str.MaximumLength = 2048;
690 source_str.Buffer = source_buf;
691 result_str.Length = 2048;
692 result_str.MaximumLength = 2048;
693 result_str.Buffer = result_buf;
694 lower_str.Length = 2048;
695 lower_str.MaximumLength = 2048;
696 lower_str.Buffer = lower_buf;
698 pRtlDowncaseUnicodeString(&result_str, &source_str, 0);
699 for (i = 0; i <= 1024; i++) {
700 ok(result_str.Buffer[i] == lower_str.Buffer[i] || result_str.Buffer[i] == source_str.Buffer[i] + 1,
701 "RtlDowncaseUnicodeString works wrong: '%c'[=0x%x] is converted to '%c'[=0x%x], expected: '%c'[=0x%x]",
702 source_str.Buffer[i], source_str.Buffer[i],
703 result_str.Buffer[i], result_str.Buffer[i],
704 lower_str.Buffer[i], lower_str.Buffer[i]);
711 int ansi_MaximumLength;
715 int uni_MaximumLength;
720 int res_MaximumLength;
726 static const ustr2astr_t ustr2astr[] = {
727 { 10, 12, 12, "------------", 0, 0, 0, "", TRUE, 0, 1, 1, "", STATUS_SUCCESS},
728 { 10, 12, 12, "------------", 12, 12, 12, "abcdef", TRUE, 6, 7, 7, "abcdef", STATUS_SUCCESS},
729 { 0, 2, 12, "------------", 12, 12, 12, "abcdef", TRUE, 6, 7, 7, "abcdef", STATUS_SUCCESS},
730 { 10, 12, 12, NULL, 12, 12, 12, "abcdef", TRUE, 6, 7, 7, "abcdef", STATUS_SUCCESS},
731 { 0, 0, 12, "------------", 12, 12, 12, "abcdef", FALSE, 6, 0, 0, "", STATUS_BUFFER_OVERFLOW},
732 { 0, 1, 12, "------------", 12, 12, 12, "abcdef", FALSE, 0, 1, 1, "", STATUS_BUFFER_OVERFLOW},
733 { 0, 2, 12, "------------", 12, 12, 12, "abcdef", FALSE, 1, 2, 2, "a", STATUS_BUFFER_OVERFLOW},
734 { 0, 3, 12, "------------", 12, 12, 12, "abcdef", FALSE, 2, 3, 3, "ab", STATUS_BUFFER_OVERFLOW},
735 { 0, 5, 12, "------------", 12, 12, 12, "abcdef", FALSE, 4, 5, 5, "abcd", STATUS_BUFFER_OVERFLOW},
736 { 8, 5, 12, "------------", 12, 12, 12, "abcdef", FALSE, 4, 5, 5, "abcd", STATUS_BUFFER_OVERFLOW},
737 { 8, 6, 12, "------------", 12, 12, 12, "abcdef", FALSE, 5, 6, 6, "abcde", STATUS_BUFFER_OVERFLOW},
738 { 8, 7, 12, "------------", 12, 12, 12, "abcdef", FALSE, 6, 7, 7, "abcdef", STATUS_SUCCESS},
739 { 8, 7, 12, "------------", 0, 12, 12, NULL, FALSE, 0, 7, 0, "", STATUS_SUCCESS},
740 { 0, 0, 12, NULL, 10, 10, 12, NULL, FALSE, 5, 0, 0, NULL, STATUS_BUFFER_OVERFLOW},
742 #define NB_USTR2ASTR (sizeof(ustr2astr)/sizeof(*ustr2astr))
745 static void test_RtlUnicodeStringToAnsiString(void)
751 UNICODE_STRING uni_str;
755 for (test_num = 0; test_num < NB_USTR2ASTR; test_num++) {
756 ansi_str.Length = ustr2astr[test_num].ansi_Length;
757 ansi_str.MaximumLength = ustr2astr[test_num].ansi_MaximumLength;
758 if (ustr2astr[test_num].ansi_buf != NULL) {
759 memcpy(ansi_buf, ustr2astr[test_num].ansi_buf, ustr2astr[test_num].ansi_buf_size);
760 ansi_buf[ustr2astr[test_num].ansi_buf_size] = '\0';
761 ansi_str.Buffer = ansi_buf;
763 ansi_str.Buffer = NULL;
765 uni_str.Length = ustr2astr[test_num].uni_Length;
766 uni_str.MaximumLength = ustr2astr[test_num].uni_MaximumLength;
767 if (ustr2astr[test_num].uni_buf != NULL) {
768 for (pos = 0; pos < ustr2astr[test_num].uni_buf_size/sizeof(WCHAR); pos++) {
769 uni_buf[pos] = ustr2astr[test_num].uni_buf[pos];
771 uni_str.Buffer = uni_buf;
773 uni_str.Buffer = NULL;
775 result = pRtlUnicodeStringToAnsiString(&ansi_str, &uni_str, ustr2astr[test_num].doalloc);
776 ok(result == ustr2astr[test_num].result,
777 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) has result %lx, expected %lx",
778 test_num, ustr2astr[test_num].doalloc, result, ustr2astr[test_num].result);
779 ok(ansi_str.Length == ustr2astr[test_num].res_Length,
780 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) ansi has Length %d, expected %d",
781 test_num, ustr2astr[test_num].doalloc, ansi_str.Length, ustr2astr[test_num].res_Length);
782 ok(ansi_str.MaximumLength == ustr2astr[test_num].res_MaximumLength,
783 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) ansi has MaximumLength %d, expected %d",
784 test_num, ustr2astr[test_num].doalloc, ansi_str.MaximumLength, ustr2astr[test_num].res_MaximumLength);
785 ok(memcmp(ansi_str.Buffer, ustr2astr[test_num].res_buf, ustr2astr[test_num].res_buf_size) == 0,
786 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) has ansi \"%s\" expected \"%s\"",
787 test_num, ustr2astr[test_num].doalloc, ansi_str.Buffer, ustr2astr[test_num].res_buf);
794 int dest_MaximumLength;
799 int res_MaximumLength;
805 static const app_asc2str_t app_asc2str[] = {
806 { 5, 12, 15, "TestS01234abcde", "tring", 10, 12, 15, "TestStringabcde", STATUS_SUCCESS},
807 { 5, 11, 15, "TestS01234abcde", "tring", 10, 11, 15, "TestStringabcde", STATUS_SUCCESS},
808 { 5, 10, 15, "TestS01234abcde", "tring", 10, 10, 15, "TestStringabcde", STATUS_SUCCESS},
809 { 5, 9, 15, "TestS01234abcde", "tring", 5, 9, 15, "TestS01234abcde", STATUS_BUFFER_TOO_SMALL},
810 { 5, 0, 15, "TestS01234abcde", "tring", 5, 0, 15, "TestS01234abcde", STATUS_BUFFER_TOO_SMALL},
811 { 5, 14, 15, "TestS01234abcde", "tring", 10, 14, 15, "TestStringabcde", STATUS_SUCCESS},
812 { 5, 14, 15, "TestS01234abcde", NULL, 5, 14, 15, "TestS01234abcde", STATUS_SUCCESS},
813 { 5, 14, 15, NULL, NULL, 5, 14, 15, NULL, STATUS_SUCCESS},
814 { 5, 12, 15, "Tst\0S01234abcde", "tr\0i", 7, 12, 15, "Tst\0Str234abcde", STATUS_SUCCESS},
816 #define NB_APP_ASC2STR (sizeof(app_asc2str)/sizeof(*app_asc2str))
819 static void test_RtlAppendAsciizToString(void)
826 for (test_num = 0; test_num < NB_APP_ASC2STR; test_num++) {
827 dest_str.Length = app_asc2str[test_num].dest_Length;
828 dest_str.MaximumLength = app_asc2str[test_num].dest_MaximumLength;
829 if (app_asc2str[test_num].dest_buf != NULL) {
830 memcpy(dest_buf, app_asc2str[test_num].dest_buf, app_asc2str[test_num].dest_buf_size);
831 dest_buf[app_asc2str[test_num].dest_buf_size] = '\0';
832 dest_str.Buffer = dest_buf;
834 dest_str.Buffer = NULL;
836 result = pRtlAppendAsciizToString(&dest_str, app_asc2str[test_num].src);
837 ok(result == app_asc2str[test_num].result,
838 "(test %d): RtlAppendAsciizToString(dest, src) has result %lx, expected %lx",
839 test_num, result, app_asc2str[test_num].result);
840 ok(dest_str.Length == app_asc2str[test_num].res_Length,
841 "(test %d): RtlAppendAsciizToString(dest, src) dest has Length %d, expected %d",
842 test_num, dest_str.Length, app_asc2str[test_num].res_Length);
843 ok(dest_str.MaximumLength == app_asc2str[test_num].res_MaximumLength,
844 "(test %d): RtlAppendAsciizToString(dest, src) dest has MaximumLength %d, expected %d",
845 test_num, dest_str.MaximumLength, app_asc2str[test_num].res_MaximumLength);
846 if (dest_str.Buffer == dest_buf) {
847 ok(memcmp(dest_buf, app_asc2str[test_num].res_buf, app_asc2str[test_num].res_buf_size) == 0,
848 "(test %d): RtlAppendAsciizToString(dest, src) has dest \"%s\" expected \"%s\"",
849 test_num, dest_buf, app_asc2str[test_num].res_buf);
851 ok(dest_str.Buffer == app_asc2str[test_num].res_buf,
852 "(test %d): RtlAppendAsciizToString(dest, src) dest has Buffer %p expected %p",
853 test_num, dest_str.Buffer, app_asc2str[test_num].res_buf);
861 int dest_MaximumLength;
865 int src_MaximumLength;
869 int res_MaximumLength;
875 static const app_str2str_t app_str2str[] = {
876 { 5, 12, 15, "TestS01234abcde", 5, 5, 7, "tringZY", 10, 12, 15, "TestStringabcde", STATUS_SUCCESS},
877 { 5, 11, 15, "TestS01234abcde", 5, 5, 7, "tringZY", 10, 11, 15, "TestStringabcde", STATUS_SUCCESS},
878 { 5, 10, 15, "TestS01234abcde", 5, 5, 7, "tringZY", 10, 10, 15, "TestStringabcde", STATUS_SUCCESS},
879 { 5, 9, 15, "TestS01234abcde", 5, 5, 7, "tringZY", 5, 9, 15, "TestS01234abcde", STATUS_BUFFER_TOO_SMALL},
880 { 5, 0, 15, "TestS01234abcde", 0, 0, 7, "tringZY", 5, 0, 15, "TestS01234abcde", STATUS_SUCCESS},
881 { 5, 14, 15, "TestS01234abcde", 0, 0, 7, "tringZY", 5, 14, 15, "TestS01234abcde", STATUS_SUCCESS},
882 { 5, 14, 15, "TestS01234abcde", 0, 0, 7, NULL, 5, 14, 15, "TestS01234abcde", STATUS_SUCCESS},
883 { 5, 14, 15, NULL, 0, 0, 7, NULL, 5, 14, 15, NULL, STATUS_SUCCESS},
884 { 5, 12, 15, "Tst\0S01234abcde", 4, 4, 7, "tr\0iZY", 9, 12, 15, "Tst\0Str\0i4abcde", STATUS_SUCCESS},
886 #define NB_APP_STR2STR (sizeof(app_str2str)/sizeof(*app_str2str))
889 static void test_RtlAppendStringToString(void)
898 for (test_num = 0; test_num < NB_APP_STR2STR; test_num++) {
899 dest_str.Length = app_str2str[test_num].dest_Length;
900 dest_str.MaximumLength = app_str2str[test_num].dest_MaximumLength;
901 if (app_str2str[test_num].dest_buf != NULL) {
902 memcpy(dest_buf, app_str2str[test_num].dest_buf, app_str2str[test_num].dest_buf_size);
903 dest_buf[app_str2str[test_num].dest_buf_size] = '\0';
904 dest_str.Buffer = dest_buf;
906 dest_str.Buffer = NULL;
908 src_str.Length = app_str2str[test_num].src_Length;
909 src_str.MaximumLength = app_str2str[test_num].src_MaximumLength;
910 if (app_str2str[test_num].src_buf != NULL) {
911 memcpy(src_buf, app_str2str[test_num].src_buf, app_str2str[test_num].src_buf_size);
912 src_buf[app_str2str[test_num].src_buf_size] = '\0';
913 src_str.Buffer = src_buf;
915 src_str.Buffer = NULL;
917 result = pRtlAppendStringToString(&dest_str, &src_str);
918 ok(result == app_str2str[test_num].result,
919 "(test %d): RtlAppendStringToString(dest, src) has result %lx, expected %lx",
920 test_num, result, app_str2str[test_num].result);
921 ok(dest_str.Length == app_str2str[test_num].res_Length,
922 "(test %d): RtlAppendStringToString(dest, src) dest has Length %d, expected %d",
923 test_num, dest_str.Length, app_str2str[test_num].res_Length);
924 ok(dest_str.MaximumLength == app_str2str[test_num].res_MaximumLength,
925 "(test %d): RtlAppendStringToString(dest, src) dest has MaximumLength %d, expected %d",
926 test_num, dest_str.MaximumLength, app_str2str[test_num].res_MaximumLength);
927 if (dest_str.Buffer == dest_buf) {
928 ok(memcmp(dest_buf, app_str2str[test_num].res_buf, app_str2str[test_num].res_buf_size) == 0,
929 "(test %d): RtlAppendStringToString(dest, src) has dest \"%s\" expected \"%s\"",
930 test_num, dest_buf, app_str2str[test_num].res_buf);
932 ok(dest_str.Buffer == app_str2str[test_num].res_buf,
933 "(test %d): RtlAppendStringToString(dest, src) dest has Buffer %p expected %p",
934 test_num, dest_str.Buffer, app_str2str[test_num].res_buf);
942 int dest_MaximumLength;
947 int res_MaximumLength;
953 static const app_uni2str_t app_uni2str[] = {
954 { 4, 12, 14, "Fake0123abcdef", "Ustr\0", 8, 12, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
955 { 4, 11, 14, "Fake0123abcdef", "Ustr\0", 8, 11, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
956 { 4, 10, 14, "Fake0123abcdef", "Ustr\0", 8, 10, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
957 /* In the following test the native function writes beyond MaximumLength
958 * { 4, 9, 14, "Fake0123abcdef", "Ustr\0", 8, 9, 14, "FakeUstrabcdef", STATUS_SUCCESS},
960 { 4, 8, 14, "Fake0123abcdef", "Ustr\0", 8, 8, 14, "FakeUstrabcdef", STATUS_SUCCESS},
961 { 4, 7, 14, "Fake0123abcdef", "Ustr\0", 4, 7, 14, "Fake0123abcdef", STATUS_BUFFER_TOO_SMALL},
962 { 4, 0, 14, "Fake0123abcdef", "Ustr\0", 4, 0, 14, "Fake0123abcdef", STATUS_BUFFER_TOO_SMALL},
963 { 4, 14, 14, "Fake0123abcdef", "Ustr\0", 8, 14, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
964 { 4, 14, 14, "Fake0123abcdef", NULL, 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS},
965 { 4, 14, 14, NULL, NULL, 4, 14, 14, NULL, STATUS_SUCCESS},
966 { 4, 14, 14, "Fake0123abcdef", "U\0stri\0", 10, 14, 14, "FakeU\0stri\0\0ef", STATUS_SUCCESS},
967 { 6, 14, 16, "Te\0\0stabcdefghij", "St\0\0ri", 8, 14, 16, "Te\0\0stSt\0\0efghij", STATUS_SUCCESS},
969 #define NB_APP_UNI2STR (sizeof(app_uni2str)/sizeof(*app_uni2str))
972 static void test_RtlAppendUnicodeToString(void)
975 UNICODE_STRING dest_str;
979 for (test_num = 0; test_num < NB_APP_UNI2STR; test_num++) {
980 dest_str.Length = app_uni2str[test_num].dest_Length;
981 dest_str.MaximumLength = app_uni2str[test_num].dest_MaximumLength;
982 if (app_uni2str[test_num].dest_buf != NULL) {
983 memcpy(dest_buf, app_uni2str[test_num].dest_buf, app_uni2str[test_num].dest_buf_size);
984 dest_buf[app_uni2str[test_num].dest_buf_size/sizeof(WCHAR)] = '\0';
985 dest_str.Buffer = dest_buf;
987 dest_str.Buffer = NULL;
989 result = pRtlAppendUnicodeToString(&dest_str, (LPCWSTR) app_uni2str[test_num].src);
990 ok(result == app_uni2str[test_num].result,
991 "(test %d): RtlAppendUnicodeToString(dest, src) has result %lx, expected %lx",
992 test_num, result, app_uni2str[test_num].result);
993 ok(dest_str.Length == app_uni2str[test_num].res_Length,
994 "(test %d): RtlAppendUnicodeToString(dest, src) dest has Length %d, expected %d",
995 test_num, dest_str.Length, app_uni2str[test_num].res_Length);
996 ok(dest_str.MaximumLength == app_uni2str[test_num].res_MaximumLength,
997 "(test %d): RtlAppendUnicodeToString(dest, src) dest has MaximumLength %d, expected %d",
998 test_num, dest_str.MaximumLength, app_uni2str[test_num].res_MaximumLength);
999 if (dest_str.Buffer == dest_buf) {
1000 ok(memcmp(dest_buf, app_uni2str[test_num].res_buf, app_uni2str[test_num].res_buf_size) == 0,
1001 "(test %d): RtlAppendUnicodeToString(dest, src) has dest \"%s\" expected \"%s\"",
1002 test_num, (char *) dest_buf, app_uni2str[test_num].res_buf);
1004 ok(dest_str.Buffer == (WCHAR *) app_uni2str[test_num].res_buf,
1005 "(test %d): RtlAppendUnicodeToString(dest, src) dest has Buffer %p expected %p",
1006 test_num, dest_str.Buffer, app_uni2str[test_num].res_buf);
1014 int dest_MaximumLength;
1018 int src_MaximumLength;
1022 int res_MaximumLength;
1028 static const app_ustr2str_t app_ustr2str[] = {
1029 { 4, 12, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 12, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
1030 { 4, 11, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 11, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
1031 { 4, 10, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 10, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
1032 /* In the following test the native function writes beyond MaximumLength
1033 * { 4, 9, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 9, 14, "FakeUstrabcdef", STATUS_SUCCESS},
1035 { 4, 8, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 8, 14, "FakeUstrabcdef", STATUS_SUCCESS},
1036 { 4, 7, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 4, 7, 14, "Fake0123abcdef", STATUS_BUFFER_TOO_SMALL},
1037 { 4, 0, 14, "Fake0123abcdef", 0, 0, 8, "UstrZYXW", 4, 0, 14, "Fake0123abcdef", STATUS_SUCCESS},
1038 { 4, 14, 14, "Fake0123abcdef", 0, 0, 8, "UstrZYXW", 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS},
1039 { 4, 14, 14, "Fake0123abcdef", 0, 0, 8, NULL, 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS},
1040 { 4, 14, 14, NULL, 0, 0, 8, NULL, 4, 14, 14, NULL, STATUS_SUCCESS},
1041 { 6, 14, 16, "Te\0\0stabcdefghij", 6, 8, 8, "St\0\0riZY", 12, 14, 16, "Te\0\0stSt\0\0ri\0\0ij", STATUS_SUCCESS},
1043 #define NB_APP_USTR2STR (sizeof(app_ustr2str)/sizeof(*app_ustr2str))
1046 static void test_RtlAppendUnicodeStringToString(void)
1048 WCHAR dest_buf[257];
1050 UNICODE_STRING dest_str;
1051 UNICODE_STRING src_str;
1055 for (test_num = 0; test_num < NB_APP_USTR2STR; test_num++) {
1056 dest_str.Length = app_ustr2str[test_num].dest_Length;
1057 dest_str.MaximumLength = app_ustr2str[test_num].dest_MaximumLength;
1058 if (app_ustr2str[test_num].dest_buf != NULL) {
1059 memcpy(dest_buf, app_ustr2str[test_num].dest_buf, app_ustr2str[test_num].dest_buf_size);
1060 dest_buf[app_ustr2str[test_num].dest_buf_size/sizeof(WCHAR)] = '\0';
1061 dest_str.Buffer = dest_buf;
1063 dest_str.Buffer = NULL;
1065 src_str.Length = app_ustr2str[test_num].src_Length;
1066 src_str.MaximumLength = app_ustr2str[test_num].src_MaximumLength;
1067 if (app_ustr2str[test_num].src_buf != NULL) {
1068 memcpy(src_buf, app_ustr2str[test_num].src_buf, app_ustr2str[test_num].src_buf_size);
1069 src_buf[app_ustr2str[test_num].src_buf_size/sizeof(WCHAR)] = '\0';
1070 src_str.Buffer = src_buf;
1072 src_str.Buffer = NULL;
1074 result = pRtlAppendUnicodeStringToString(&dest_str, &src_str);
1075 ok(result == app_ustr2str[test_num].result,
1076 "(test %d): RtlAppendStringToString(dest, src) has result %lx, expected %lx",
1077 test_num, result, app_ustr2str[test_num].result);
1078 ok(dest_str.Length == app_ustr2str[test_num].res_Length,
1079 "(test %d): RtlAppendStringToString(dest, src) dest has Length %d, expected %d",
1080 test_num, dest_str.Length, app_ustr2str[test_num].res_Length);
1081 ok(dest_str.MaximumLength == app_ustr2str[test_num].res_MaximumLength,
1082 "(test %d): RtlAppendStringToString(dest, src) dest has MaximumLength %d, expected %d",
1083 test_num, dest_str.MaximumLength, app_ustr2str[test_num].res_MaximumLength);
1084 if (dest_str.Buffer == dest_buf) {
1085 ok(memcmp(dest_buf, app_ustr2str[test_num].res_buf, app_ustr2str[test_num].res_buf_size) == 0,
1086 "(test %d): RtlAppendStringToString(dest, src) has dest \"%s\" expected \"%s\"",
1087 test_num, (char *) dest_buf, app_ustr2str[test_num].res_buf);
1089 ok(dest_str.Buffer == (WCHAR *) app_ustr2str[test_num].res_buf,
1090 "(test %d): RtlAppendStringToString(dest, src) dest has Buffer %p expected %p",
1091 test_num, dest_str.Buffer, app_ustr2str[test_num].res_buf);
1103 } find_ch_in_ustr_t;
1105 static const find_ch_in_ustr_t find_ch_in_ustr[] = {
1106 { 0, "Some Wild String", "S", 2, STATUS_SUCCESS},
1107 { 0, "This is a String", "String", 6, STATUS_SUCCESS},
1108 { 1, "This is a String", "String", 30, STATUS_SUCCESS},
1109 { 2, "This is a String", "String", 2, STATUS_SUCCESS},
1110 { 3, "This is a String", "String", 18, STATUS_SUCCESS},
1111 { 0, "This is a String", "Wild", 6, STATUS_SUCCESS},
1112 { 1, "This is a String", "Wild", 26, STATUS_SUCCESS},
1113 { 2, "This is a String", "Wild", 2, STATUS_SUCCESS},
1114 { 3, "This is a String", "Wild", 30, STATUS_SUCCESS},
1115 { 0, "abcdefghijklmnopqrstuvwxyz", "", 0, STATUS_NOT_FOUND},
1116 { 0, "abcdefghijklmnopqrstuvwxyz", "123", 0, STATUS_NOT_FOUND},
1117 { 0, "abcdefghijklmnopqrstuvwxyz", "a", 2, STATUS_SUCCESS},
1118 { 0, "abcdefghijklmnopqrstuvwxyz", "12a34", 2, STATUS_SUCCESS},
1119 { 0, "abcdefghijklmnopqrstuvwxyz", "12b34", 4, STATUS_SUCCESS},
1120 { 0, "abcdefghijklmnopqrstuvwxyz", "12y34", 50, STATUS_SUCCESS},
1121 { 0, "abcdefghijklmnopqrstuvwxyz", "12z34", 52, STATUS_SUCCESS},
1122 { 0, "abcdefghijklmnopqrstuvwxyz", "rvz", 36, STATUS_SUCCESS},
1123 { 0, "abcdefghijklmmlkjihgfedcba", "egik", 10, STATUS_SUCCESS},
1124 { 1, "abcdefghijklmnopqrstuvwxyz", "", 0, STATUS_NOT_FOUND},
1125 { 1, "abcdefghijklmnopqrstuvwxyz", "rvz", 50, STATUS_SUCCESS},
1126 { 1, "abcdefghijklmnopqrstuvwxyz", "ravy", 48, STATUS_SUCCESS},
1127 { 1, "abcdefghijklmnopqrstuvwxyz", "raxv", 46, STATUS_SUCCESS},
1128 { 2, "abcdefghijklmnopqrstuvwxyz", "", 2, STATUS_SUCCESS},
1129 { 2, "abcdefghijklmnopqrstuvwxyz", "rvz", 2, STATUS_SUCCESS},
1130 { 2, "abcdefghijklmnopqrstuvwxyz", "vaz", 4, STATUS_SUCCESS},
1131 { 2, "abcdefghijklmnopqrstuvwxyz", "ravbz", 6, STATUS_SUCCESS},
1132 { 3, "abcdefghijklmnopqrstuvwxyz", "", 50, STATUS_SUCCESS},
1133 { 3, "abcdefghijklmnopqrstuvwxyz", "123", 50, STATUS_SUCCESS},
1134 { 3, "abcdefghijklmnopqrstuvwxyz", "ahp", 50, STATUS_SUCCESS},
1135 { 3, "abcdefghijklmnopqrstuvwxyz", "rvz", 48, STATUS_SUCCESS},
1136 { 0, NULL, "abc", 0, STATUS_NOT_FOUND},
1137 { 1, NULL, "abc", 0, STATUS_NOT_FOUND},
1138 { 2, NULL, "abc", 0, STATUS_NOT_FOUND},
1139 { 3, NULL, "abc", 0, STATUS_NOT_FOUND},
1140 { 0, "abcdefghijklmnopqrstuvwxyz", NULL, 0, STATUS_NOT_FOUND},
1141 { 1, "abcdefghijklmnopqrstuvwxyz", NULL, 0, STATUS_NOT_FOUND},
1142 { 2, "abcdefghijklmnopqrstuvwxyz", NULL, 2, STATUS_SUCCESS},
1143 { 3, "abcdefghijklmnopqrstuvwxyz", NULL, 50, STATUS_SUCCESS},
1144 { 0, NULL, NULL, 0, STATUS_NOT_FOUND},
1145 { 1, NULL, NULL, 0, STATUS_NOT_FOUND},
1146 { 2, NULL, NULL, 0, STATUS_NOT_FOUND},
1147 { 3, NULL, NULL, 0, STATUS_NOT_FOUND},
1148 { 0, "abcdabcdabcdabcdabcdabcd", "abcd", 2, STATUS_SUCCESS},
1149 { 1, "abcdabcdabcdabcdabcdabcd", "abcd", 46, STATUS_SUCCESS},
1150 { 2, "abcdabcdabcdabcdabcdabcd", "abcd", 0, STATUS_NOT_FOUND},
1151 { 3, "abcdabcdabcdabcdabcdabcd", "abcd", 0, STATUS_NOT_FOUND},
1153 #define NB_FIND_CH_IN_USTR (sizeof(find_ch_in_ustr)/sizeof(*find_ch_in_ustr))
1156 static void test_RtlFindCharInUnicodeString(void)
1158 WCHAR main_str_buf[257];
1159 WCHAR search_chars_buf[257];
1160 UNICODE_STRING main_str;
1161 UNICODE_STRING search_chars;
1167 for (test_num = 0; test_num < NB_FIND_CH_IN_USTR; test_num++) {
1168 if (find_ch_in_ustr[test_num].main_str != NULL) {
1169 main_str.Length = strlen(find_ch_in_ustr[test_num].main_str) * sizeof(WCHAR);
1170 main_str.MaximumLength = main_str.Length + sizeof(WCHAR);
1171 for (idx = 0; idx < main_str.Length / sizeof(WCHAR); idx++) {
1172 main_str_buf[idx] = find_ch_in_ustr[test_num].main_str[idx];
1174 main_str.Buffer = main_str_buf;
1176 main_str.Length = 0;
1177 main_str.MaximumLength = 0;
1178 main_str.Buffer = NULL;
1180 if (find_ch_in_ustr[test_num].search_chars != NULL) {
1181 search_chars.Length = strlen(find_ch_in_ustr[test_num].search_chars) * sizeof(WCHAR);
1182 search_chars.MaximumLength = search_chars.Length + sizeof(WCHAR);
1183 for (idx = 0; idx < search_chars.Length / sizeof(WCHAR); idx++) {
1184 search_chars_buf[idx] = find_ch_in_ustr[test_num].search_chars[idx];
1186 search_chars.Buffer = search_chars_buf;
1188 search_chars.Length = 0;
1189 search_chars.MaximumLength = 0;
1190 search_chars.Buffer = NULL;
1193 result = pRtlFindCharInUnicodeString(find_ch_in_ustr[test_num].flags, &main_str, &search_chars, &pos);
1194 ok(result == find_ch_in_ustr[test_num].result,
1195 "(test %d): RtlFindCharInUnicodeString(%d, %s, %s, [out]) has result %lx, expected %lx",
1196 test_num, find_ch_in_ustr[test_num].flags,
1197 find_ch_in_ustr[test_num].main_str, find_ch_in_ustr[test_num].search_chars,
1198 result, find_ch_in_ustr[test_num].result);
1199 ok(pos == find_ch_in_ustr[test_num].pos,
1200 "(test %d): RtlFindCharInUnicodeString(%d, %s, %s, [out]) assigns %d to pos, expected %d",
1201 test_num, find_ch_in_ustr[test_num].flags,
1202 find_ch_in_ustr[test_num].main_str, find_ch_in_ustr[test_num].search_chars,
1203 pos, find_ch_in_ustr[test_num].pos);
1215 static const str2int_t str2int[] = {
1216 { 0, "1011101100", 1011101100, STATUS_SUCCESS},
1217 { 0, "1234567", 1234567, STATUS_SUCCESS},
1218 { 0, "-214", -214, STATUS_SUCCESS},
1219 { 0, "+214", 214, STATUS_SUCCESS}, /* The + sign is allowed also */
1220 { 0, "--214", 0, STATUS_SUCCESS}, /* Do not accept more than one sign */
1221 { 0, "-+214", 0, STATUS_SUCCESS},
1222 { 0, "++214", 0, STATUS_SUCCESS},
1223 { 0, "+-214", 0, STATUS_SUCCESS},
1224 { 0, "\001\002\003\00411", 11, STATUS_SUCCESS}, /* whitespace char 1 to 4 */
1225 { 0, "\005\006\007\01012", 12, STATUS_SUCCESS}, /* whitespace char 5 to 8 */
1226 { 0, "\011\012\013\01413", 13, STATUS_SUCCESS}, /* whitespace char 9 to 12 */
1227 { 0, "\015\016\017\02014", 14, STATUS_SUCCESS}, /* whitespace char 13 to 16 */
1228 { 0, "\021\022\023\02415", 15, STATUS_SUCCESS}, /* whitespace char 17 to 20 */
1229 { 0, "\025\026\027\03016", 16, STATUS_SUCCESS}, /* whitespace char 21 to 24 */
1230 { 0, "\031\032\033\03417", 17, STATUS_SUCCESS}, /* whitespace char 25 to 28 */
1231 { 0, "\035\036\037\04018", 18, STATUS_SUCCESS}, /* whitespace char 29 to 32 */
1232 { 0, " \n \r \t214", 214, STATUS_SUCCESS},
1233 { 0, " \n \r \t+214", 214, STATUS_SUCCESS}, /* Signs can be used after whitespace */
1234 { 0, " \n \r \t-214", -214, STATUS_SUCCESS},
1235 { 0, "+214 0", 214, STATUS_SUCCESS}, /* Space terminates the number */
1236 { 0, " 214.01", 214, STATUS_SUCCESS}, /* Decimal point not accepted */
1237 { 0, " 214,01", 214, STATUS_SUCCESS}, /* Decimal comma not accepted */
1238 { 0, "f81", 0, STATUS_SUCCESS},
1239 { 0, "0x12345", 0x12345, STATUS_SUCCESS}, /* Hex */
1240 { 0, "00x12345", 0, STATUS_SUCCESS},
1241 { 0, "0xx12345", 0, STATUS_SUCCESS},
1242 { 0, "1x34", 1, STATUS_SUCCESS},
1243 { 0, "-9999999999", -1410065407, STATUS_SUCCESS}, /* Big negative integer */
1244 { 0, "-2147483649", 2147483647, STATUS_SUCCESS}, /* Too small to fit in 32 Bits */
1245 { 0, "-2147483648", 0x80000000L, STATUS_SUCCESS}, /* Smallest negative integer */
1246 { 0, "-2147483647", -2147483647, STATUS_SUCCESS},
1247 { 0, "-1", -1, STATUS_SUCCESS},
1248 { 0, "0", 0, STATUS_SUCCESS},
1249 { 0, "1", 1, STATUS_SUCCESS},
1250 { 0, "2147483646", 2147483646, STATUS_SUCCESS},
1251 { 0, "2147483647", 2147483647, STATUS_SUCCESS}, /* Largest signed positive integer */
1252 { 0, "2147483648", 0x80000000L, STATUS_SUCCESS}, /* Positive int equal to smallest negative int */
1253 { 0, "2147483649", -2147483647, STATUS_SUCCESS},
1254 { 0, "4294967294", -2, STATUS_SUCCESS},
1255 { 0, "4294967295", -1, STATUS_SUCCESS}, /* Largest unsigned integer */
1256 { 0, "4294967296", 0, STATUS_SUCCESS}, /* Too big to fit in 32 Bits */
1257 { 0, "9999999999", 1410065407, STATUS_SUCCESS}, /* Big positive integer */
1258 { 0, "056789", 56789, STATUS_SUCCESS}, /* Leading zero and still decimal */
1259 { 0, "b1011101100", 0, STATUS_SUCCESS}, /* Binary (b-notation) */
1260 { 0, "-b1011101100", 0, STATUS_SUCCESS}, /* Negative Binary (b-notation) */
1261 { 0, "b10123456789", 0, STATUS_SUCCESS}, /* Binary with nonbinary digits (2-9) */
1262 { 0, "0b1011101100", 748, STATUS_SUCCESS}, /* Binary (0b-notation) */
1263 { 0, "-0b1011101100", -748, STATUS_SUCCESS}, /* Negative binary (0b-notation) */
1264 { 0, "0b10123456789", 5, STATUS_SUCCESS}, /* Binary with nonbinary digits (2-9) */
1265 { 0, "-0b10123456789", -5, STATUS_SUCCESS}, /* Negative binary with nonbinary digits (2-9) */
1266 { 0, "0b1", 1, STATUS_SUCCESS}, /* one digit binary */
1267 { 0, "0b2", 0, STATUS_SUCCESS}, /* empty binary */
1268 { 0, "0b", 0, STATUS_SUCCESS}, /* empty binary */
1269 { 0, "o1234567", 0, STATUS_SUCCESS}, /* Octal (o-notation) */
1270 { 0, "-o1234567", 0, STATUS_SUCCESS}, /* Negative Octal (o-notation) */
1271 { 0, "o56789", 0, STATUS_SUCCESS}, /* Octal with nonoctal digits (8 and 9) */
1272 { 0, "0o1234567", 01234567, STATUS_SUCCESS}, /* Octal (0o-notation) */
1273 { 0, "-0o1234567", -01234567, STATUS_SUCCESS}, /* Negative octal (0o-notation) */
1274 { 0, "0o56789", 0567, STATUS_SUCCESS}, /* Octal with nonoctal digits (8 and 9) */
1275 { 0, "-0o56789", -0567, STATUS_SUCCESS}, /* Negative octal with nonoctal digits (8 and 9) */
1276 { 0, "0o7", 7, STATUS_SUCCESS}, /* one digit octal */
1277 { 0, "0o8", 0, STATUS_SUCCESS}, /* empty octal */
1278 { 0, "0o", 0, STATUS_SUCCESS}, /* empty octal */
1279 { 0, "0d1011101100", 0, STATUS_SUCCESS}, /* explizit decimal with 0d */
1280 { 0, "x89abcdef", 0, STATUS_SUCCESS}, /* Hex with lower case digits a-f (x-notation) */
1281 { 0, "xFEDCBA00", 0, STATUS_SUCCESS}, /* Hex with upper case digits A-F (x-notation) */
1282 { 0, "-xFEDCBA00", 0, STATUS_SUCCESS}, /* Negative Hexadecimal (x-notation) */
1283 { 0, "0x89abcdef", 0x89abcdef, STATUS_SUCCESS}, /* Hex with lower case digits a-f (0x-notation) */
1284 { 0, "0xFEDCBA00", 0xFEDCBA00, STATUS_SUCCESS}, /* Hex with upper case digits A-F (0x-notation) */
1285 { 0, "-0xFEDCBA00", -0xFEDCBA00, STATUS_SUCCESS}, /* Negative Hexadecimal (0x-notation) */
1286 { 0, "0xabcdefgh", 0xabcdef, STATUS_SUCCESS}, /* Hex with illegal lower case digits (g-z) */
1287 { 0, "0xABCDEFGH", 0xABCDEF, STATUS_SUCCESS}, /* Hex with illegal upper case digits (G-Z) */
1288 { 0, "0xF", 0xf, STATUS_SUCCESS}, /* one digit hexadecimal */
1289 { 0, "0xG", 0, STATUS_SUCCESS}, /* empty hexadecimal */
1290 { 0, "0x", 0, STATUS_SUCCESS}, /* empty hexadecimal */
1291 { 0, "", 0, STATUS_SUCCESS}, /* empty string */
1292 { 2, "1011101100", 748, STATUS_SUCCESS},
1293 { 2, "-1011101100", -748, STATUS_SUCCESS},
1294 { 2, "2", 0, STATUS_SUCCESS},
1295 { 2, "0b1011101100", 0, STATUS_SUCCESS},
1296 { 2, "0o1011101100", 0, STATUS_SUCCESS},
1297 { 2, "0d1011101100", 0, STATUS_SUCCESS},
1298 { 2, "0x1011101100", 0, STATUS_SUCCESS},
1299 { 2, "", 0, STATUS_SUCCESS}, /* empty string */
1300 { 8, "1011101100", 136610368, STATUS_SUCCESS},
1301 { 8, "-1011101100", -136610368, STATUS_SUCCESS},
1302 { 8, "8", 0, STATUS_SUCCESS},
1303 { 8, "0b1011101100", 0, STATUS_SUCCESS},
1304 { 8, "0o1011101100", 0, STATUS_SUCCESS},
1305 { 8, "0d1011101100", 0, STATUS_SUCCESS},
1306 { 8, "0x1011101100", 0, STATUS_SUCCESS},
1307 { 8, "", 0, STATUS_SUCCESS}, /* empty string */
1308 {10, "1011101100", 1011101100, STATUS_SUCCESS},
1309 {10, "-1011101100", -1011101100, STATUS_SUCCESS},
1310 {10, "0b1011101100", 0, STATUS_SUCCESS},
1311 {10, "0o1011101100", 0, STATUS_SUCCESS},
1312 {10, "0d1011101100", 0, STATUS_SUCCESS},
1313 {10, "0x1011101100", 0, STATUS_SUCCESS},
1314 {10, "o12345", 0, STATUS_SUCCESS}, /* Octal altrough base is 10 */
1315 {10, "", 0, STATUS_SUCCESS}, /* empty string */
1316 {16, "1011101100", 286265600, STATUS_SUCCESS},
1317 {16, "-1011101100", -286265600, STATUS_SUCCESS},
1318 {16, "G", 0, STATUS_SUCCESS},
1319 {16, "g", 0, STATUS_SUCCESS},
1320 {16, "0b1011101100", 286265600, STATUS_SUCCESS},
1321 {16, "0o1011101100", 0, STATUS_SUCCESS},
1322 {16, "0d1011101100", 286265600, STATUS_SUCCESS},
1323 {16, "0x1011101100", 0, STATUS_SUCCESS},
1324 {16, "", 0, STATUS_SUCCESS}, /* empty string */
1325 {20, "0", 0xdeadbeef, STATUS_INVALID_PARAMETER}, /* illegal base */
1326 {-8, "0", 0xdeadbeef, STATUS_INVALID_PARAMETER}, /* Negative base */
1327 /* { 0, NULL, 0, STATUS_SUCCESS}, */ /* NULL as string */
1329 #define NB_STR2INT (sizeof(str2int)/sizeof(*str2int))
1332 static void test_RtlUnicodeStringToInteger(void)
1340 for (test_num = 0; test_num < NB_STR2INT; test_num++) {
1341 wstr = AtoW(str2int[test_num].str);
1343 pRtlInitUnicodeString(&uni, wstr);
1344 result = pRtlUnicodeStringToInteger(&uni, str2int[test_num].base, &value);
1345 ok(result == str2int[test_num].result,
1346 "(test %d): RtlUnicodeStringToInteger(\"%s\", %d, [out]) has result %lx, expected: %lx",
1347 test_num, str2int[test_num].str, str2int[test_num].base, result, str2int[test_num].result);
1348 ok(value == str2int[test_num].value,
1349 "(test %d): RtlUnicodeStringToInteger(\"%s\", %d, [out]) assigns value %d, expected: %d",
1350 test_num, str2int[test_num].str, str2int[test_num].base, value, str2int[test_num].value);
1354 wstr = AtoW(str2int[1].str);
1355 pRtlInitUnicodeString(&uni, wstr);
1356 result = pRtlUnicodeStringToInteger(&uni, str2int[1].base, NULL);
1357 ok(result == STATUS_ACCESS_VIOLATION,
1358 "call failed: RtlUnicodeStringToInteger(\"%s\", %d, NULL) has result %lx",
1359 str2int[1].str, str2int[1].base, result);
1360 result = pRtlUnicodeStringToInteger(&uni, 20, NULL);
1361 ok(result == STATUS_INVALID_PARAMETER,
1362 "call failed: RtlUnicodeStringToInteger(\"%s\", 20, NULL) has result %lx",
1363 str2int[1].str, result);
1365 uni.Length = 10; /* Make Length shorter (5 WCHARS instead of 7) */
1366 result = pRtlUnicodeStringToInteger(&uni, str2int[1].base, &value);
1367 ok(result == STATUS_SUCCESS,
1368 "call failed: RtlUnicodeStringToInteger(\"12345\", %d, [out]) has result %lx",
1369 str2int[1].base, result);
1371 "didn't return expected value (test a): expected: %d, got: %d",
1374 uni.Length = 5; /* Use odd Length (2.5 WCHARS) */
1375 result = pRtlUnicodeStringToInteger(&uni, str2int[1].base, &value);
1376 ok(result == STATUS_SUCCESS,
1377 "call failed: RtlUnicodeStringToInteger(\"12\", %d, [out]) has result %lx",
1378 str2int[1].base, result);
1380 "didn't return expected value (test b): expected: %d, got: %d",
1384 result = pRtlUnicodeStringToInteger(&uni, str2int[1].base, &value);
1385 ok(result == STATUS_SUCCESS,
1386 "call failed: RtlUnicodeStringToInteger(\"1\", %d, [out]) has result %lx",
1387 str2int[1].base, result);
1389 "didn't return expected value (test c): expected: %d, got: %d",
1391 /* w2k: uni.Length = 0 returns value 11234567 instead of 0 */
1396 static void test_RtlCharToInteger(void)
1402 for (test_num = 0; test_num < NB_STR2INT; test_num++) {
1403 /* w2k skips a leading '\0' and processes the string after */
1404 if (str2int[test_num].str[0] != '\0') {
1406 result = pRtlCharToInteger(str2int[test_num].str, str2int[test_num].base, &value);
1407 ok(result == str2int[test_num].result,
1408 "(test %d): call failed: RtlCharToInteger(\"%s\", %d, [out]) has result %lx, expected: %lx",
1409 test_num, str2int[test_num].str, str2int[test_num].base, result, str2int[test_num].result);
1410 ok(value == str2int[test_num].value,
1411 "(test %d): call failed: RtlCharToInteger(\"%s\", %d, [out]) assigns value %d, expected: %d",
1412 test_num, str2int[test_num].str, str2int[test_num].base, value, str2int[test_num].value);
1416 result = pRtlCharToInteger(str2int[1].str, str2int[1].base, NULL);
1417 ok(result == STATUS_ACCESS_VIOLATION,
1418 "call failed: RtlCharToInteger(\"%s\", %d, NULL) has result %lx",
1419 str2int[1].str, str2int[1].base, result);
1421 result = pRtlCharToInteger(str2int[1].str, 20, NULL);
1422 ok(result == STATUS_INVALID_PARAMETER,
1423 "call failed: RtlCharToInteger(\"%s\", 20, NULL) has result %lx",
1424 str2int[1].str, result);
1428 #define STRI_BUFFER_LENGTH 35
1434 USHORT MaximumLength;
1439 static const int2str_t int2str[] = {
1440 {10, 123, 3, 11, "123\0-------------------------------", STATUS_SUCCESS},
1442 { 0, 0x80000000U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS}, /* min signed int */
1443 { 0, -2147483647, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS},
1444 { 0, -2, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS},
1445 { 0, -1, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS},
1446 { 0, 0, 1, 11, "0\0---------------------------------", STATUS_SUCCESS},
1447 { 0, 1, 1, 11, "1\0---------------------------------", STATUS_SUCCESS},
1448 { 0, 12, 2, 11, "12\0--------------------------------", STATUS_SUCCESS},
1449 { 0, 123, 3, 11, "123\0-------------------------------", STATUS_SUCCESS},
1450 { 0, 1234, 4, 11, "1234\0------------------------------", STATUS_SUCCESS},
1451 { 0, 12345, 5, 11, "12345\0-----------------------------", STATUS_SUCCESS},
1452 { 0, 123456, 6, 11, "123456\0----------------------------", STATUS_SUCCESS},
1453 { 0, 1234567, 7, 11, "1234567\0---------------------------", STATUS_SUCCESS},
1454 { 0, 12345678, 8, 11, "12345678\0--------------------------", STATUS_SUCCESS},
1455 { 0, 123456789, 9, 11, "123456789\0-------------------------", STATUS_SUCCESS},
1456 { 0, 2147483646, 10, 11, "2147483646\0------------------------", STATUS_SUCCESS},
1457 { 0, 2147483647, 10, 11, "2147483647\0------------------------", STATUS_SUCCESS}, /* max signed int */
1458 { 0, 2147483648U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS}, /* uint = -max int */
1459 { 0, 2147483649U, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS},
1460 { 0, 4294967294U, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS},
1461 { 0, 4294967295U, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS}, /* max unsigned int */
1463 { 2, 0x80000000U, 32, 33, "10000000000000000000000000000000\0--", STATUS_SUCCESS}, /* min signed int */
1464 { 2, -2147483647, 32, 33, "10000000000000000000000000000001\0--", STATUS_SUCCESS},
1465 { 2, -2, 32, 33, "11111111111111111111111111111110\0--", STATUS_SUCCESS},
1466 { 2, -1, 32, 33, "11111111111111111111111111111111\0--", STATUS_SUCCESS},
1467 { 2, 0, 1, 33, "0\0---------------------------------", STATUS_SUCCESS},
1468 { 2, 1, 1, 33, "1\0---------------------------------", STATUS_SUCCESS},
1469 { 2, 10, 4, 33, "1010\0------------------------------", STATUS_SUCCESS},
1470 { 2, 100, 7, 33, "1100100\0---------------------------", STATUS_SUCCESS},
1471 { 2, 1000, 10, 33, "1111101000\0------------------------", STATUS_SUCCESS},
1472 { 2, 10000, 14, 33, "10011100010000\0--------------------", STATUS_SUCCESS},
1473 { 2, 32767, 15, 33, "111111111111111\0-------------------", STATUS_SUCCESS},
1474 { 2, 32768, 16, 33, "1000000000000000\0------------------", STATUS_SUCCESS},
1475 { 2, 65535, 16, 33, "1111111111111111\0------------------", STATUS_SUCCESS},
1476 { 2, 65536, 17, 33, "10000000000000000\0-----------------", STATUS_SUCCESS},
1477 { 2, 100000, 17, 33, "11000011010100000\0-----------------", STATUS_SUCCESS},
1478 { 2, 1000000, 20, 33, "11110100001001000000\0--------------", STATUS_SUCCESS},
1479 { 2, 10000000, 24, 33, "100110001001011010000000\0----------", STATUS_SUCCESS},
1480 { 2, 100000000, 27, 33, "101111101011110000100000000\0-------", STATUS_SUCCESS},
1481 { 2, 1000000000, 30, 33, "111011100110101100101000000000\0----", STATUS_SUCCESS},
1482 { 2, 1073741823, 30, 33, "111111111111111111111111111111\0----", STATUS_SUCCESS},
1483 { 2, 2147483646, 31, 33, "1111111111111111111111111111110\0---", STATUS_SUCCESS},
1484 { 2, 2147483647, 31, 33, "1111111111111111111111111111111\0---", STATUS_SUCCESS}, /* max signed int */
1485 { 2, 2147483648U, 32, 33, "10000000000000000000000000000000\0--", STATUS_SUCCESS}, /* uint = -max int */
1486 { 2, 2147483649U, 32, 33, "10000000000000000000000000000001\0--", STATUS_SUCCESS},
1487 { 2, 4294967294U, 32, 33, "11111111111111111111111111111110\0--", STATUS_SUCCESS},
1488 { 2, 4294967295U, 32, 33, "11111111111111111111111111111111\0--", STATUS_SUCCESS}, /* max unsigned int */
1490 { 8, 0x80000000U, 11, 12, "20000000000\0-----------------------", STATUS_SUCCESS}, /* min signed int */
1491 { 8, -2147483647, 11, 12, "20000000001\0-----------------------", STATUS_SUCCESS},
1492 { 8, -2, 11, 12, "37777777776\0-----------------------", STATUS_SUCCESS},
1493 { 8, -1, 11, 12, "37777777777\0-----------------------", STATUS_SUCCESS},
1494 { 8, 0, 1, 12, "0\0---------------------------------", STATUS_SUCCESS},
1495 { 8, 1, 1, 12, "1\0---------------------------------", STATUS_SUCCESS},
1496 { 8, 2147483646, 11, 12, "17777777776\0-----------------------", STATUS_SUCCESS},
1497 { 8, 2147483647, 11, 12, "17777777777\0-----------------------", STATUS_SUCCESS}, /* max signed int */
1498 { 8, 2147483648U, 11, 12, "20000000000\0-----------------------", STATUS_SUCCESS}, /* uint = -max int */
1499 { 8, 2147483649U, 11, 12, "20000000001\0-----------------------", STATUS_SUCCESS},
1500 { 8, 4294967294U, 11, 12, "37777777776\0-----------------------", STATUS_SUCCESS},
1501 { 8, 4294967295U, 11, 12, "37777777777\0-----------------------", STATUS_SUCCESS}, /* max unsigned int */
1503 {10, 0x80000000U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS}, /* min signed int */
1504 {10, -2147483647, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS},
1505 {10, -2, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS},
1506 {10, -1, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS},
1507 {10, 0, 1, 11, "0\0---------------------------------", STATUS_SUCCESS},
1508 {10, 1, 1, 11, "1\0---------------------------------", STATUS_SUCCESS},
1509 {10, 2147483646, 10, 11, "2147483646\0------------------------", STATUS_SUCCESS},
1510 {10, 2147483647, 10, 11, "2147483647\0------------------------", STATUS_SUCCESS}, /* max signed int */
1511 {10, 2147483648U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS}, /* uint = -max int */
1512 {10, 2147483649U, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS},
1513 {10, 4294967294U, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS},
1514 {10, 4294967295U, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS}, /* max unsigned int */
1516 {16, 0x80000000U, 8, 9, "80000000\0--------------------------", STATUS_SUCCESS}, /* min signed int */
1517 {16, -2147483647, 8, 9, "80000001\0--------------------------", STATUS_SUCCESS},
1518 {16, -2, 8, 9, "FFFFFFFE\0--------------------------", STATUS_SUCCESS},
1519 {16, -1, 8, 9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS},
1520 {16, 0, 1, 9, "0\0---------------------------------", STATUS_SUCCESS},
1521 {16, 1, 1, 9, "1\0---------------------------------", STATUS_SUCCESS},
1522 {16, 2147483646, 8, 9, "7FFFFFFE\0--------------------------", STATUS_SUCCESS},
1523 {16, 2147483647, 8, 9, "7FFFFFFF\0--------------------------", STATUS_SUCCESS}, /* max signed int */
1524 {16, 2147483648U, 8, 9, "80000000\0--------------------------", STATUS_SUCCESS}, /* uint = -max int */
1525 {16, 2147483649U, 8, 9, "80000001\0--------------------------", STATUS_SUCCESS},
1526 {16, 4294967294U, 8, 9, "FFFFFFFE\0--------------------------", STATUS_SUCCESS},
1527 {16, 4294967295U, 8, 9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS}, /* max unsigned int */
1529 { 2, 32768, 16, 17, "1000000000000000\0------------------", STATUS_SUCCESS},
1530 { 2, 32768, 16, 16, "1000000000000000-------------------", STATUS_SUCCESS},
1531 { 2, 65536, 17, 18, "10000000000000000\0-----------------", STATUS_SUCCESS},
1532 { 2, 65536, 17, 17, "10000000000000000------------------", STATUS_SUCCESS},
1533 { 2, 131072, 18, 19, "100000000000000000\0----------------", STATUS_SUCCESS},
1534 { 2, 131072, 18, 18, "100000000000000000-----------------", STATUS_SUCCESS},
1535 {16, 0xffffffff, 8, 9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS},
1536 {16, 0xffffffff, 8, 8, "FFFFFFFF---------------------------", STATUS_SUCCESS}, /* No \0 term */
1537 {16, 0xffffffff, 8, 7, "-----------------------------------", STATUS_BUFFER_OVERFLOW}, /* Too short */
1538 {16, 0xa, 1, 2, "A\0---------------------------------", STATUS_SUCCESS},
1539 {16, 0xa, 1, 1, "A----------------------------------", STATUS_SUCCESS}, /* No \0 term */
1540 {16, 0, 1, 0, "-----------------------------------", STATUS_BUFFER_OVERFLOW},
1541 {20, 0xdeadbeef, 0, 9, "-----------------------------------", STATUS_INVALID_PARAMETER}, /* ill. base */
1542 {-8, 07654321, 0, 12, "-----------------------------------", STATUS_INVALID_PARAMETER}, /* neg. base */
1544 #define NB_INT2STR (sizeof(int2str)/sizeof(*int2str))
1547 static void one_RtlIntegerToUnicodeString_test(int test_num, const int2str_t *int2str)
1550 WCHAR expected_str_Buffer[STRI_BUFFER_LENGTH + 1];
1551 UNICODE_STRING expected_unicode_string;
1552 STRING expected_ansi_str;
1553 WCHAR str_Buffer[STRI_BUFFER_LENGTH + 1];
1554 UNICODE_STRING unicode_string;
1558 for (pos = 0; pos < STRI_BUFFER_LENGTH; pos++) {
1559 expected_str_Buffer[pos] = int2str->Buffer[pos];
1561 expected_unicode_string.Length = int2str->Length * sizeof(WCHAR);
1562 expected_unicode_string.MaximumLength = int2str->MaximumLength * sizeof(WCHAR);
1563 expected_unicode_string.Buffer = expected_str_Buffer;
1564 pRtlUnicodeStringToAnsiString(&expected_ansi_str, &expected_unicode_string, 1);
1566 for (pos = 0; pos < STRI_BUFFER_LENGTH; pos++) {
1567 str_Buffer[pos] = '-';
1569 unicode_string.Length = 0;
1570 unicode_string.MaximumLength = int2str->MaximumLength * sizeof(WCHAR);
1571 unicode_string.Buffer = str_Buffer;
1573 result = pRtlIntegerToUnicodeString(int2str->value, int2str->base, &unicode_string);
1574 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
1575 if (result == STATUS_BUFFER_OVERFLOW) {
1576 /* On BUFFER_OVERFLOW the string Buffer should be unchanged */
1577 for (pos = 0; pos < STRI_BUFFER_LENGTH; pos++) {
1578 expected_str_Buffer[pos] = '-';
1580 /* w2k: The native function has two reasons for BUFFER_OVERFLOW: */
1581 /* If the value is too large to convert: The Length is unchanged */
1582 /* If str is too small to hold the string: Set str->Length to the length */
1583 /* the string would have (which can be larger than the MaximumLength). */
1584 /* To allow all this in the tests we do the following: */
1585 if (expected_unicode_string.Length > 32 && unicode_string.Length == 0) {
1586 /* The value is too large to convert only triggerd when testing native */
1587 expected_unicode_string.Length = 0;
1590 ok(result == int2str->result,
1591 "(test %d): RtlIntegerToUnicodeString(%lu, %d, [out]) has result %lx, expected: %lx",
1592 test_num, int2str->value, int2str->base, result, int2str->result);
1593 if (result == STATUS_SUCCESS) {
1594 ok(unicode_string.Buffer[unicode_string.Length/sizeof(WCHAR)] == '\0',
1595 "(test %d): RtlIntegerToUnicodeString(%lu, %d, [out]) string \"%s\" is not NULL terminated",
1596 test_num, int2str->value, int2str->base, ansi_str.Buffer);
1599 ok(memcmp(unicode_string.Buffer, expected_unicode_string.Buffer, STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
1600 "(test %d): RtlIntegerToUnicodeString(%lu, %d, [out]) assigns string \"%s\", expected: \"%s\"",
1601 test_num, int2str->value, int2str->base, ansi_str.Buffer, expected_ansi_str.Buffer);
1602 ok(unicode_string.Length == expected_unicode_string.Length,
1603 "(test %d): RtlIntegerToUnicodeString(%lu, %d, [out]) string has Length %d, expected: %d",
1604 test_num, int2str->value, int2str->base, unicode_string.Length, expected_unicode_string.Length);
1605 ok(unicode_string.MaximumLength == expected_unicode_string.MaximumLength,
1606 "(test %d): RtlIntegerToUnicodeString(%lu, %d, [out]) string has MaximumLength %d, expected: %d",
1607 test_num, int2str->value, int2str->base, unicode_string.MaximumLength, expected_unicode_string.MaximumLength);
1608 pRtlFreeAnsiString(&expected_ansi_str);
1609 pRtlFreeAnsiString(&ansi_str);
1613 static void test_RtlIntegerToUnicodeString(void)
1617 for (test_num = 0; test_num < NB_INT2STR; test_num++) {
1618 one_RtlIntegerToUnicodeString_test(test_num, &int2str[test_num]);
1623 static void one_RtlIntegerToChar_test(int test_num, const int2str_t *int2str)
1626 char dest_str[STRI_BUFFER_LENGTH + 1];
1628 memset(dest_str, '-', STRI_BUFFER_LENGTH);
1629 dest_str[STRI_BUFFER_LENGTH] = '\0';
1630 result = pRtlIntegerToChar(int2str->value, int2str->base, int2str->MaximumLength, dest_str);
1631 ok(result == int2str->result,
1632 "(test %d): RtlIntegerToChar(%lu, %d, %d, [out]) has result %lx, expected: %lx",
1633 test_num, int2str->value, int2str->base, int2str->MaximumLength, result, int2str->result);
1634 ok(memcmp(dest_str, int2str->Buffer, STRI_BUFFER_LENGTH) == 0,
1635 "(test %d): RtlIntegerToChar(%lu, %d, %d, [out]) assigns string \"%s\", expected: \"%s\"",
1636 test_num, int2str->value, int2str->base, int2str->MaximumLength, dest_str, int2str->Buffer);
1640 static void test_RtlIntegerToChar(void)
1645 for (test_num = 0; test_num < NB_INT2STR; test_num++) {
1646 one_RtlIntegerToChar_test(test_num, &int2str[test_num]);
1649 result = pRtlIntegerToChar(int2str[0].value, 20, int2str[0].MaximumLength, NULL);
1650 ok(result == STATUS_INVALID_PARAMETER,
1651 "(test a): RtlIntegerToChar(%lu, %d, %d, NULL) has result %lx, expected: %x",
1652 int2str[0].value, 20, int2str[0].MaximumLength, result, STATUS_INVALID_PARAMETER);
1654 result = pRtlIntegerToChar(int2str[0].value, 20, 0, NULL);
1655 ok(result == STATUS_INVALID_PARAMETER,
1656 "(test b): RtlIntegerToChar(%lu, %d, %d, NULL) has result %lx, expected: %x",
1657 int2str[0].value, 20, 0, result, STATUS_INVALID_PARAMETER);
1659 result = pRtlIntegerToChar(int2str[0].value, int2str[0].base, 0, NULL);
1660 ok(result == STATUS_BUFFER_OVERFLOW,
1661 "(test c): RtlIntegerToChar(%lu, %d, %d, NULL) has result %lx, expected: %x",
1662 int2str[0].value, int2str[0].base, 0, result, STATUS_BUFFER_OVERFLOW);
1664 result = pRtlIntegerToChar(int2str[0].value, int2str[0].base, int2str[0].MaximumLength, NULL);
1665 ok(result == STATUS_ACCESS_VIOLATION,
1666 "(test d): RtlIntegerToChar(%lu, %d, %d, NULL) has result %lx, expected: %x",
1667 int2str[0].value, int2str[0].base, int2str[0].MaximumLength, result, STATUS_ACCESS_VIOLATION);
1674 if (pRtlInitAnsiString) {
1675 test_RtlInitString();
1676 test_RtlInitUnicodeString();
1677 test_RtlCopyString();
1678 test_RtlUnicodeStringToInteger();
1679 test_RtlCharToInteger();
1680 test_RtlIntegerToUnicodeString();
1681 test_RtlIntegerToChar();
1682 test_RtlUpperChar();
1683 test_RtlUpperString();
1684 test_RtlUnicodeStringToAnsiString();
1685 test_RtlAppendAsciizToString();
1686 test_RtlAppendStringToString();
1687 test_RtlAppendUnicodeToString();
1688 test_RtlAppendUnicodeStringToString();
1691 if (pRtlInitUnicodeStringEx) {
1692 test_RtlInitUnicodeStringEx();
1694 if (pRtlDuplicateUnicodeString) {
1695 test_RtlDuplicateUnicodeString();
1697 if (pRtlFindCharInUnicodeString) {
1698 test_RtlFindCharInUnicodeString();
1701 * test_RtlUpcaseUnicodeChar();
1702 * test_RtlUpcaseUnicodeString();
1703 * test_RtlDowncaseUnicodeString();