usp10/tests: A spelling fix in an ok() message.
[wine.git] / dlls / ntdll / tests / rtlstr.c
blob8b948fa82ac0ecf89a5fe6202b38f42ae7a36bf7
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * NOTES
21 * We use function pointers here as there is no import library for NTDLL on
22 * windows.
25 #include <stdlib.h>
27 #define INITGUID
29 #include "ntdll_test.h"
30 #include "winnls.h"
31 #include "guiddef.h"
33 #define HASH_STRING_ALGORITHM_X65599 1
34 #define HASH_STRING_ALGORITHM_INVALID 0xffffffff
36 /* Function ptrs for ntdll calls */
37 static HMODULE hntdll = 0;
38 static NTSTATUS (WINAPI *pRtlAnsiStringToUnicodeString)(PUNICODE_STRING, PCANSI_STRING, BOOLEAN);
39 static NTSTATUS (WINAPI *pRtlAppendAsciizToString)(STRING *, LPCSTR);
40 static NTSTATUS (WINAPI *pRtlAppendStringToString)(STRING *, const STRING *);
41 static NTSTATUS (WINAPI *pRtlAppendUnicodeStringToString)(UNICODE_STRING *, const UNICODE_STRING *);
42 static NTSTATUS (WINAPI *pRtlAppendUnicodeToString)(UNICODE_STRING *, LPCWSTR);
43 static NTSTATUS (WINAPI *pRtlCharToInteger)(PCSZ, ULONG, int *);
44 static LONG (WINAPI *pRtlCompareUnicodeString)(const UNICODE_STRING*, const UNICODE_STRING*, BOOLEAN);
45 static LONG (WINAPI *pRtlCompareUnicodeStrings)(const WCHAR *,SIZE_T,const WCHAR *,SIZE_T,BOOLEAN);
46 static VOID (WINAPI *pRtlCopyString)(STRING *, const STRING *);
47 static BOOLEAN (WINAPI *pRtlCreateUnicodeString)(PUNICODE_STRING, LPCWSTR);
48 static BOOLEAN (WINAPI *pRtlCreateUnicodeStringFromAsciiz)(PUNICODE_STRING, LPCSTR);
49 static NTSTATUS (WINAPI *pRtlDowncaseUnicodeString)(UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN);
50 static NTSTATUS (WINAPI *pRtlDuplicateUnicodeString)(int, UNICODE_STRING *, UNICODE_STRING *);
51 static BOOLEAN (WINAPI *pRtlEqualUnicodeString)(const UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN);
52 static NTSTATUS (WINAPI *pRtlFindCharInUnicodeString)(int, const UNICODE_STRING *, const UNICODE_STRING *, USHORT *);
53 static VOID (WINAPI *pRtlFreeAnsiString)(PSTRING);
54 static VOID (WINAPI *pRtlFreeUnicodeString)(PUNICODE_STRING);
55 static VOID (WINAPI *pRtlInitAnsiString)(PSTRING, LPCSTR);
56 static VOID (WINAPI *pRtlInitString)(PSTRING, LPCSTR);
57 static VOID (WINAPI *pRtlInitUnicodeString)(PUNICODE_STRING, LPCWSTR);
58 static NTSTATUS (WINAPI *pRtlInitUnicodeStringEx)(PUNICODE_STRING, LPCWSTR);
59 static NTSTATUS (WINAPI *pRtlIntegerToChar)(ULONG, ULONG, ULONG, PCHAR);
60 static NTSTATUS (WINAPI *pRtlIntegerToUnicodeString)(ULONG, ULONG, UNICODE_STRING *);
61 static NTSTATUS (WINAPI *pRtlMultiAppendUnicodeStringBuffer)(UNICODE_STRING *, LONG, UNICODE_STRING *);
62 static NTSTATUS (WINAPI *pRtlUnicodeStringToAnsiString)(STRING *, const UNICODE_STRING *, BOOLEAN);
63 static NTSTATUS (WINAPI *pRtlUnicodeStringToInteger)(const UNICODE_STRING *, int, int *);
64 static WCHAR (WINAPI *pRtlUpcaseUnicodeChar)(WCHAR);
65 static NTSTATUS (WINAPI *pRtlUpcaseUnicodeString)(UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN);
66 static CHAR (WINAPI *pRtlUpperChar)(CHAR);
67 static NTSTATUS (WINAPI *pRtlUpperString)(STRING *, const STRING *);
68 static NTSTATUS (WINAPI *pRtlValidateUnicodeString)(LONG, UNICODE_STRING *);
69 static NTSTATUS (WINAPI *pRtlGUIDFromString)(const UNICODE_STRING*,GUID*);
70 static NTSTATUS (WINAPI *pRtlStringFromGUID)(const GUID*, UNICODE_STRING*);
71 static BOOLEAN (WINAPI *pRtlIsTextUnicode)(LPVOID, INT, INT *);
72 static NTSTATUS (WINAPI *pRtlHashUnicodeString)(PCUNICODE_STRING,BOOLEAN,ULONG,ULONG*);
73 static NTSTATUS (WINAPI *pRtlUnicodeToUTF8N)(CHAR *, ULONG, ULONG *, const WCHAR *, ULONG);
74 static NTSTATUS (WINAPI *pRtlUTF8ToUnicodeN)(WCHAR *, ULONG, ULONG *, const CHAR *, ULONG);
76 /*static VOID (WINAPI *pRtlFreeOemString)(PSTRING);*/
77 /*static VOID (WINAPI *pRtlCopyUnicodeString)(UNICODE_STRING *, const UNICODE_STRING *);*/
78 /*static VOID (WINAPI *pRtlEraseUnicodeString)(UNICODE_STRING *);*/
79 /*static LONG (WINAPI *pRtlCompareString)(const STRING *,const STRING *,BOOLEAN);*/
80 /*static BOOLEAN (WINAPI *pRtlEqualString)(const STRING *,const STRING *,BOOLEAN);*/
81 /*static BOOLEAN (WINAPI *pRtlPrefixString)(const STRING *, const STRING *, BOOLEAN);*/
82 /*static BOOLEAN (WINAPI *pRtlPrefixUnicodeString)(const UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN);*/
83 /*static NTSTATUS (WINAPI *pRtlOemStringToUnicodeString)(PUNICODE_STRING, const STRING *, BOOLEAN);*/
84 /*static NTSTATUS (WINAPI *pRtlUnicodeStringToOemString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/
85 /*static NTSTATUS (WINAPI *pRtlMultiByteToUnicodeN)(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD);*/
86 /*static NTSTATUS (WINAPI *pRtlOemToUnicodeN)(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD);*/
87 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeStringToAnsiString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/
88 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeStringToOemString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/
89 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeToMultiByteN)(LPSTR, DWORD, LPDWORD, LPCWSTR, DWORD);*/
90 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeToOemN)(LPSTR, DWORD, LPDWORD, LPCWSTR, DWORD);*/
91 /*static UINT (WINAPI *pRtlOemToUnicodeSize)(const STRING *);*/
92 /*static DWORD (WINAPI *pRtlAnsiStringToUnicodeSize)(const STRING *);*/
95 static WCHAR* AtoW( const char* p )
97 WCHAR* buffer;
98 DWORD len = MultiByteToWideChar( CP_ACP, 0, p, -1, NULL, 0 );
99 buffer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR) );
100 MultiByteToWideChar( CP_ACP, 0, p, -1, buffer, len );
101 return buffer;
105 static void InitFunctionPtrs(void)
107 hntdll = LoadLibraryA("ntdll.dll");
108 ok(hntdll != 0, "LoadLibrary failed\n");
109 if (hntdll) {
110 pRtlAnsiStringToUnicodeString = (void *)GetProcAddress(hntdll, "RtlAnsiStringToUnicodeString");
111 pRtlAppendAsciizToString = (void *)GetProcAddress(hntdll, "RtlAppendAsciizToString");
112 pRtlAppendStringToString = (void *)GetProcAddress(hntdll, "RtlAppendStringToString");
113 pRtlAppendUnicodeStringToString = (void *)GetProcAddress(hntdll, "RtlAppendUnicodeStringToString");
114 pRtlAppendUnicodeToString = (void *)GetProcAddress(hntdll, "RtlAppendUnicodeToString");
115 pRtlCharToInteger = (void *)GetProcAddress(hntdll, "RtlCharToInteger");
116 pRtlCompareUnicodeString = (void *)GetProcAddress(hntdll, "RtlCompareUnicodeString");
117 pRtlCompareUnicodeStrings = (void *)GetProcAddress(hntdll, "RtlCompareUnicodeStrings");
118 pRtlCopyString = (void *)GetProcAddress(hntdll, "RtlCopyString");
119 pRtlCreateUnicodeString = (void *)GetProcAddress(hntdll, "RtlCreateUnicodeString");
120 pRtlCreateUnicodeStringFromAsciiz = (void *)GetProcAddress(hntdll, "RtlCreateUnicodeStringFromAsciiz");
121 pRtlDowncaseUnicodeString = (void *)GetProcAddress(hntdll, "RtlDowncaseUnicodeString");
122 pRtlDuplicateUnicodeString = (void *)GetProcAddress(hntdll, "RtlDuplicateUnicodeString");
123 pRtlEqualUnicodeString = (void *)GetProcAddress(hntdll, "RtlEqualUnicodeString");
124 pRtlFindCharInUnicodeString = (void *)GetProcAddress(hntdll, "RtlFindCharInUnicodeString");
125 pRtlFreeAnsiString = (void *)GetProcAddress(hntdll, "RtlFreeAnsiString");
126 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
127 pRtlInitAnsiString = (void *)GetProcAddress(hntdll, "RtlInitAnsiString");
128 pRtlInitString = (void *)GetProcAddress(hntdll, "RtlInitString");
129 pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
130 pRtlInitUnicodeStringEx = (void *)GetProcAddress(hntdll, "RtlInitUnicodeStringEx");
131 pRtlIntegerToChar = (void *)GetProcAddress(hntdll, "RtlIntegerToChar");
132 pRtlIntegerToUnicodeString = (void *)GetProcAddress(hntdll, "RtlIntegerToUnicodeString");
133 pRtlMultiAppendUnicodeStringBuffer = (void *)GetProcAddress(hntdll, "RtlMultiAppendUnicodeStringBuffer");
134 pRtlUnicodeStringToAnsiString = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToAnsiString");
135 pRtlUnicodeStringToInteger = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToInteger");
136 pRtlUpcaseUnicodeChar = (void *)GetProcAddress(hntdll, "RtlUpcaseUnicodeChar");
137 pRtlUpcaseUnicodeString = (void *)GetProcAddress(hntdll, "RtlUpcaseUnicodeString");
138 pRtlUpperChar = (void *)GetProcAddress(hntdll, "RtlUpperChar");
139 pRtlUpperString = (void *)GetProcAddress(hntdll, "RtlUpperString");
140 pRtlValidateUnicodeString = (void *)GetProcAddress(hntdll, "RtlValidateUnicodeString");
141 pRtlGUIDFromString = (void *)GetProcAddress(hntdll, "RtlGUIDFromString");
142 pRtlStringFromGUID = (void *)GetProcAddress(hntdll, "RtlStringFromGUID");
143 pRtlIsTextUnicode = (void *)GetProcAddress(hntdll, "RtlIsTextUnicode");
144 pRtlHashUnicodeString = (void*)GetProcAddress(hntdll, "RtlHashUnicodeString");
145 pRtlUnicodeToUTF8N = (void*)GetProcAddress(hntdll, "RtlUnicodeToUTF8N");
146 pRtlUTF8ToUnicodeN = (void*)GetProcAddress(hntdll, "RtlUTF8ToUnicodeN");
150 static void test_RtlInitString(void)
152 static const char teststring[] = "Some Wild String";
153 STRING str;
155 str.Length = 0;
156 str.MaximumLength = 0;
157 str.Buffer = (void *)0xdeadbeef;
158 pRtlInitString(&str, teststring);
159 ok(str.Length == sizeof(teststring) - sizeof(char), "Length uninitialized\n");
160 ok(str.MaximumLength == sizeof(teststring), "MaximumLength uninitialized\n");
161 ok(str.Buffer == teststring, "Buffer not equal to teststring\n");
162 ok(strcmp(str.Buffer, "Some Wild String") == 0, "Buffer written to\n");
163 pRtlInitString(&str, NULL);
164 ok(str.Length == 0, "Length uninitialized\n");
165 ok(str.MaximumLength == 0, "MaximumLength uninitialized\n");
166 ok(str.Buffer == NULL, "Buffer not equal to NULL\n");
167 /* pRtlInitString(NULL, teststring); */
171 static void test_RtlInitUnicodeString(void)
173 #define STRINGW {'S','o','m','e',' ','W','i','l','d',' ','S','t','r','i','n','g',0}
174 static const WCHAR teststring[] = STRINGW;
175 static const WCHAR originalstring[] = STRINGW;
176 #undef STRINGW
177 UNICODE_STRING uni;
179 uni.Length = 0;
180 uni.MaximumLength = 0;
181 uni.Buffer = (void *)0xdeadbeef;
182 pRtlInitUnicodeString(&uni, teststring);
183 ok(uni.Length == sizeof(teststring) - sizeof(WCHAR), "Length uninitialized\n");
184 ok(uni.MaximumLength == sizeof(teststring), "MaximumLength uninitialized\n");
185 ok(uni.Buffer == teststring, "Buffer not equal to teststring\n");
186 ok(lstrcmpW(uni.Buffer, originalstring) == 0, "Buffer written to\n");
187 pRtlInitUnicodeString(&uni, NULL);
188 ok(uni.Length == 0, "Length uninitialized\n");
189 ok(uni.MaximumLength == 0, "MaximumLength uninitialized\n");
190 ok(uni.Buffer == NULL, "Buffer not equal to NULL\n");
191 /* pRtlInitUnicodeString(NULL, teststring); */
195 #define TESTSTRING2_LEN 1000000
196 /* #define TESTSTRING2_LEN 32766 */
199 static void test_RtlInitUnicodeStringEx(void)
201 static const WCHAR teststring[] = {'S','o','m','e',' ','W','i','l','d',' ','S','t','r','i','n','g',0};
202 WCHAR *teststring2;
203 UNICODE_STRING uni;
204 NTSTATUS result;
206 if (!pRtlInitUnicodeStringEx)
208 win_skip("RtlInitUnicodeStringEx is not available\n");
209 return;
212 teststring2 = HeapAlloc(GetProcessHeap(), 0, (TESTSTRING2_LEN + 1) * sizeof(WCHAR));
213 memset(teststring2, 'X', TESTSTRING2_LEN * sizeof(WCHAR));
214 teststring2[TESTSTRING2_LEN] = '\0';
216 uni.Length = 12345;
217 uni.MaximumLength = 12345;
218 uni.Buffer = (void *) 0xdeadbeef;
219 result = pRtlInitUnicodeStringEx(&uni, teststring);
220 ok(result == STATUS_SUCCESS,
221 "pRtlInitUnicodeStringEx(&uni, 0) returns %x, expected 0\n",
222 result);
223 ok(uni.Length == 32,
224 "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected %u\n",
225 uni.Length, 32);
226 ok(uni.MaximumLength == 34,
227 "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected %u\n",
228 uni.MaximumLength, 34);
229 ok(uni.Buffer == teststring,
230 "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %p\n",
231 uni.Buffer, teststring);
233 uni.Length = 12345;
234 uni.MaximumLength = 12345;
235 uni.Buffer = (void *) 0xdeadbeef;
236 pRtlInitUnicodeString(&uni, teststring);
237 ok(uni.Length == 32,
238 "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u\n",
239 uni.Length, 32);
240 ok(uni.MaximumLength == 34,
241 "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u\n",
242 uni.MaximumLength, 34);
243 ok(uni.Buffer == teststring,
244 "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p\n",
245 uni.Buffer, teststring);
247 uni.Length = 12345;
248 uni.MaximumLength = 12345;
249 uni.Buffer = (void *) 0xdeadbeef;
250 result = pRtlInitUnicodeStringEx(&uni, teststring2);
251 ok(result == STATUS_NAME_TOO_LONG,
252 "pRtlInitUnicodeStringEx(&uni, 0) returns %x, expected %x\n",
253 result, STATUS_NAME_TOO_LONG);
254 ok(uni.Length == 12345 ||
255 uni.Length == 0, /* win2k3 */
256 "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected 12345 or 0\n",
257 uni.Length);
258 ok(uni.MaximumLength == 12345 ||
259 uni.MaximumLength == 0, /* win2k3 */
260 "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected 12345 or 0\n",
261 uni.MaximumLength);
262 ok(uni.Buffer == (void *) 0xdeadbeef ||
263 uni.Buffer == teststring2, /* win2k3 */
264 "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %x or %p\n",
265 uni.Buffer, 0xdeadbeef, teststring2);
267 uni.Length = 12345;
268 uni.MaximumLength = 12345;
269 uni.Buffer = (void *) 0xdeadbeef;
270 pRtlInitUnicodeString(&uni, teststring2);
271 ok(uni.Length == 33920 /* <= Win2000 */ || uni.Length == 65532 /* >= Win XP */,
272 "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u\n",
273 uni.Length, 65532);
274 ok(uni.MaximumLength == 33922 /* <= Win2000 */ || uni.MaximumLength == 65534 /* >= Win XP */,
275 "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u\n",
276 uni.MaximumLength, 65534);
277 ok(uni.Buffer == teststring2,
278 "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p\n",
279 uni.Buffer, teststring2);
280 ok(memcmp(uni.Buffer, teststring2, (TESTSTRING2_LEN + 1) * sizeof(WCHAR)) == 0,
281 "pRtlInitUnicodeString(&uni, 0) changes Buffer\n");
283 uni.Length = 12345;
284 uni.MaximumLength = 12345;
285 uni.Buffer = (void *) 0xdeadbeef;
286 result = pRtlInitUnicodeStringEx(&uni, 0);
287 ok(result == STATUS_SUCCESS,
288 "pRtlInitUnicodeStringEx(&uni, 0) returns %x, expected 0\n",
289 result);
290 ok(uni.Length == 0,
291 "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected %u\n",
292 uni.Length, 0);
293 ok(uni.MaximumLength == 0,
294 "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected %u\n",
295 uni.MaximumLength, 0);
296 ok(uni.Buffer == NULL,
297 "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %p\n",
298 uni.Buffer, NULL);
300 uni.Length = 12345;
301 uni.MaximumLength = 12345;
302 uni.Buffer = (void *) 0xdeadbeef;
303 pRtlInitUnicodeString(&uni, 0);
304 ok(uni.Length == 0,
305 "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u\n",
306 uni.Length, 0);
307 ok(uni.MaximumLength == 0,
308 "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u\n",
309 uni.MaximumLength, 0);
310 ok(uni.Buffer == NULL,
311 "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p\n",
312 uni.Buffer, NULL);
314 HeapFree(GetProcessHeap(), 0, teststring2);
318 typedef struct {
319 int add_nul;
320 int source_Length;
321 int source_MaximumLength;
322 int source_buf_size;
323 const char *source_buf;
324 int dest_Length;
325 int dest_MaximumLength;
326 int dest_buf_size;
327 const char *dest_buf;
328 int res_Length;
329 int res_MaximumLength;
330 int res_buf_size;
331 const char *res_buf;
332 NTSTATUS result;
333 } dupl_ustr_t;
335 static const dupl_ustr_t dupl_ustr[] = {
336 { 0, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 32, 32, "This is a string", STATUS_SUCCESS},
337 { 0, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 32, 32, "This is a string", STATUS_SUCCESS},
338 { 0, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
339 { 0, 32, 34, 34, "This is a string", 40, 42, 42, NULL, 32, 32, 32, "This is a string", STATUS_SUCCESS},
340 { 0, 32, 32, 32, "This is a string", 40, 42, 42, NULL, 32, 32, 32, "This is a string", STATUS_SUCCESS},
341 { 0, 32, 30, 34, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
342 { 1, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS},
343 { 1, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS},
344 { 1, 32, 30, 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, NULL, 32, 34, 34, "This is a string", STATUS_SUCCESS},
346 { 1, 32, 32, 32, "This is a string", 40, 42, 42, NULL, 32, 34, 34, "This is a string", STATUS_SUCCESS},
347 { 1, 32, 30, 34, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
348 { 2, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
349 { 2, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
350 { 2, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
351 { 2, 32, 34, 34, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
352 { 2, 32, 32, 32, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
353 { 2, 32, 30, 34, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
354 { 3, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS},
355 { 3, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS},
356 { 3, 32, 30, 32, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
357 { 3, 32, 34, 34, "This is a string", 40, 42, 42, NULL, 32, 34, 34, "This is a string", STATUS_SUCCESS},
358 { 3, 32, 32, 32, "This is a string", 40, 42, 42, NULL, 32, 34, 34, "This is a string", STATUS_SUCCESS},
359 { 3, 32, 30, 32, "This is a string", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
360 { 4, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
361 { 5, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
362 { 6, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
363 { 7, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
364 { 8, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
365 { 9, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
366 {10, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
367 {11, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
368 {12, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
369 {13, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
370 {14, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
371 {15, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
372 {16, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
373 {-1, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
374 {-5, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
375 {-9, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
376 { 0, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
377 { 0, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
378 { 0, 0, 2, 2, "", 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
379 { 0, 0, 0, 0, "", 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
380 { 0, 0, 2, 2, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
381 { 0, 0, 0, 0, NULL, 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
382 { 0, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
383 { 0, 0, 0, 0, NULL, 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
384 { 1, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
385 { 1, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
386 { 1, 0, 2, 2, "", 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
387 { 1, 0, 0, 0, "", 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
388 { 1, 0, 2, 2, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
389 { 1, 0, 0, 0, NULL, 40, 42, 42, "--------------------", 0, 0, 0, NULL, STATUS_SUCCESS},
390 { 1, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
391 { 1, 0, 0, 0, NULL, 40, 42, 42, NULL, 0, 0, 0, NULL, STATUS_SUCCESS},
392 { 2, 0, 2, 2, "", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
393 { 2, 0, 0, 0, "", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
394 { 2, 0, 2, 2, "", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
395 { 2, 0, 0, 0, "", 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
396 { 2, 0, 2, 2, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
397 { 2, 0, 0, 0, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
398 { 2, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
399 { 2, 0, 0, 0, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
400 { 3, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS},
401 { 3, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS},
402 { 3, 0, 2, 2, "", 40, 42, 42, NULL, 0, 2, 2, "", STATUS_SUCCESS},
403 { 3, 0, 0, 0, "", 40, 42, 42, NULL, 0, 2, 2, "", STATUS_SUCCESS},
404 { 3, 0, 2, 2, NULL, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER},
405 { 3, 0, 0, 0, NULL, 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS},
406 { 3, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER},
407 { 3, 0, 0, 0, NULL, 40, 42, 42, NULL, 0, 2, 2, "", STATUS_SUCCESS},
411 static void test_RtlDuplicateUnicodeString(void)
413 size_t pos;
414 WCHAR source_buf[257];
415 WCHAR dest_buf[257];
416 WCHAR res_buf[257];
417 UNICODE_STRING source_str;
418 UNICODE_STRING dest_str;
419 UNICODE_STRING res_str;
420 CHAR dest_ansi_buf[257];
421 STRING dest_ansi_str;
422 NTSTATUS result;
423 unsigned int test_num;
425 if (!pRtlDuplicateUnicodeString)
427 win_skip("RtlDuplicateUnicodeString is not available\n");
428 return;
431 for (test_num = 0; test_num < ARRAY_SIZE(dupl_ustr); test_num++) {
432 source_str.Length = dupl_ustr[test_num].source_Length;
433 source_str.MaximumLength = dupl_ustr[test_num].source_MaximumLength;
434 if (dupl_ustr[test_num].source_buf != NULL) {
435 for (pos = 0; pos < dupl_ustr[test_num].source_buf_size/sizeof(WCHAR); pos++) {
436 source_buf[pos] = dupl_ustr[test_num].source_buf[pos];
438 source_str.Buffer = source_buf;
439 } else {
440 source_str.Buffer = NULL;
442 dest_str.Length = dupl_ustr[test_num].dest_Length;
443 dest_str.MaximumLength = dupl_ustr[test_num].dest_MaximumLength;
444 if (dupl_ustr[test_num].dest_buf != NULL) {
445 for (pos = 0; pos < dupl_ustr[test_num].dest_buf_size/sizeof(WCHAR); pos++) {
446 dest_buf[pos] = dupl_ustr[test_num].dest_buf[pos];
448 dest_str.Buffer = dest_buf;
449 } else {
450 dest_str.Buffer = NULL;
452 res_str.Length = dupl_ustr[test_num].res_Length;
453 res_str.MaximumLength = dupl_ustr[test_num].res_MaximumLength;
454 if (dupl_ustr[test_num].res_buf != NULL) {
455 for (pos = 0; pos < dupl_ustr[test_num].res_buf_size/sizeof(WCHAR); pos++) {
456 res_buf[pos] = dupl_ustr[test_num].res_buf[pos];
458 res_str.Buffer = res_buf;
459 } else {
460 res_str.Buffer = NULL;
462 result = pRtlDuplicateUnicodeString(dupl_ustr[test_num].add_nul, &source_str, &dest_str);
463 dest_ansi_str.Length = dest_str.Length / sizeof(WCHAR);
464 dest_ansi_str.MaximumLength = dest_ansi_str.Length + 1;
465 for (pos = 0; pos < dest_ansi_str.Length; pos++) {
466 dest_ansi_buf[pos] = (char)dest_buf[pos];
468 dest_ansi_buf[dest_ansi_str.Length] = '\0';
469 dest_ansi_str.Buffer = dest_ansi_buf;
470 ok(result == dupl_ustr[test_num].result,
471 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has result %x, expected %x\n",
472 test_num, dupl_ustr[test_num].add_nul, result, dupl_ustr[test_num].result);
473 ok(dest_str.Length == dupl_ustr[test_num].res_Length,
474 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination has Length %d, expected %d\n",
475 test_num, dupl_ustr[test_num].add_nul, dest_str.Length, dupl_ustr[test_num].res_Length);
476 ok(dest_str.MaximumLength == dupl_ustr[test_num].res_MaximumLength,
477 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination has MaximumLength %d, expected %d\n",
478 test_num, dupl_ustr[test_num].add_nul, dest_str.MaximumLength, dupl_ustr[test_num].res_MaximumLength);
479 if (result == STATUS_INVALID_PARAMETER) {
480 ok((dest_str.Buffer == NULL && res_str.Buffer == NULL) ||
481 dest_str.Buffer == dest_buf,
482 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination buffer changed %p expected %p\n",
483 test_num, dupl_ustr[test_num].add_nul, dest_str.Buffer, dest_buf);
484 } else {
485 ok(dest_str.Buffer != dest_buf,
486 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination buffer unchanged %p\n",
487 test_num, dupl_ustr[test_num].add_nul, dest_str.Buffer);
489 if (dest_str.Buffer != NULL && dupl_ustr[test_num].res_buf != NULL) {
490 ok(memcmp(dest_str.Buffer, res_str.Buffer, dupl_ustr[test_num].res_buf_size) == 0,
491 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination \"%s\" expected \"%s\"\n",
492 test_num, dupl_ustr[test_num].add_nul, dest_ansi_str.Buffer, dupl_ustr[test_num].res_buf);
493 if(result == STATUS_SUCCESS) pRtlFreeUnicodeString(&dest_str);
494 } else {
495 ok(dest_str.Buffer == NULL && dupl_ustr[test_num].res_buf == NULL,
496 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination %p expected %p\n",
497 test_num, dupl_ustr[test_num].add_nul, dest_str.Buffer, dupl_ustr[test_num].res_buf);
503 static void test_RtlCopyString(void)
505 static const char teststring[] = "Some Wild String";
506 char deststring[] = " ";
507 STRING str;
508 STRING deststr;
510 pRtlInitString(&str, teststring);
511 pRtlInitString(&deststr, deststring);
512 pRtlCopyString(&deststr, &str);
513 ok(strncmp(str.Buffer, deststring, str.Length) == 0, "String not copied\n");
517 static void test_RtlUpperChar(void)
519 int ch;
520 int upper_ch;
521 int expected_upper_ch;
522 int byte_ch;
524 for (ch = -1; ch <= 1024; ch++) {
525 upper_ch = pRtlUpperChar(ch);
526 byte_ch = ch & 0xff;
527 if (byte_ch >= 'a' && byte_ch <= 'z') {
528 expected_upper_ch = (CHAR) (byte_ch - 'a' + 'A');
529 } else {
530 expected_upper_ch = (CHAR) byte_ch;
532 ok(upper_ch == expected_upper_ch,
533 "RtlUpperChar('%c'[=0x%x]) has result '%c'[=0x%x], expected '%c'[=0x%x]\n",
534 ch, ch, upper_ch, upper_ch, expected_upper_ch, expected_upper_ch);
539 static void test_RtlUpperString(void)
541 int i;
542 CHAR ch;
543 CHAR upper_ch;
544 char ascii_buf[257];
545 char result_buf[257];
546 char upper_buf[257];
547 STRING ascii_str;
548 STRING result_str;
549 STRING upper_str;
551 for (i = 0; i <= 255; i++) {
552 ch = (CHAR) i;
553 if (ch >= 'a' && ch <= 'z') {
554 upper_ch = ch - 'a' + 'A';
555 } else {
556 upper_ch = ch;
558 ascii_buf[i] = ch;
559 result_buf[i] = '\0';
560 upper_buf[i] = upper_ch;
562 ascii_buf[i] = '\0';
563 result_buf[i] = '\0';
564 upper_buf[i] = '\0';
565 ascii_str.Length = 256;
566 ascii_str.MaximumLength = 256;
567 ascii_str.Buffer = ascii_buf;
568 result_str.Length = 256;
569 result_str.MaximumLength = 256;
570 result_str.Buffer = result_buf;
571 upper_str.Length = 256;
572 upper_str.MaximumLength = 256;
573 upper_str.Buffer = upper_buf;
575 pRtlUpperString(&result_str, &ascii_str);
576 ok(memcmp(result_str.Buffer, upper_str.Buffer, 256) == 0,
577 "RtlUpperString does not work as expected\n");
581 static void test_RtlUpcaseUnicodeChar(void)
583 int i;
584 WCHAR ch;
585 WCHAR upper_ch;
586 WCHAR expected_upper_ch;
588 for (i = 0; i <= 255; i++) {
589 ch = (WCHAR) i;
590 upper_ch = pRtlUpcaseUnicodeChar(ch);
591 if (ch >= 'a' && ch <= 'z') {
592 expected_upper_ch = ch - 'a' + 'A';
593 } else if (ch >= 0xe0 && ch <= 0xfe && ch != 0xf7) {
594 expected_upper_ch = ch - 0x20;
595 } else if (ch == 0xff) {
596 expected_upper_ch = 0x178;
597 } else {
598 expected_upper_ch = ch;
600 ok(upper_ch == expected_upper_ch,
601 "RtlUpcaseUnicodeChar('%c'[=0x%x]) has result '%c'[=0x%x], expected: '%c'[=0x%x]\n",
602 ch, ch, upper_ch, upper_ch, expected_upper_ch, expected_upper_ch);
607 static void test_RtlUpcaseUnicodeString(void)
609 int i;
610 WCHAR ch;
611 WCHAR upper_ch;
612 WCHAR ascii_buf[257];
613 WCHAR result_buf[257];
614 WCHAR upper_buf[257];
615 UNICODE_STRING ascii_str;
616 UNICODE_STRING result_str;
617 UNICODE_STRING upper_str;
619 for (i = 0; i <= 255; i++) {
620 ch = (WCHAR) i;
621 if (ch >= 'a' && ch <= 'z') {
622 upper_ch = ch - 'a' + 'A';
623 } else if (ch >= 0xe0 && ch <= 0xfe && ch != 0xf7) {
624 upper_ch = ch - 0x20;
625 } else if (ch == 0xff) {
626 upper_ch = 0x178;
627 } else {
628 upper_ch = ch;
630 ascii_buf[i] = ch;
631 result_buf[i] = '\0';
632 upper_buf[i] = upper_ch;
634 ascii_buf[i] = '\0';
635 result_buf[i] = '\0';
636 upper_buf[i] = '\0';
637 ascii_str.Length = 512;
638 ascii_str.MaximumLength = 512;
639 ascii_str.Buffer = ascii_buf;
640 result_str.Length = 512;
641 result_str.MaximumLength = 512;
642 result_str.Buffer = result_buf;
643 upper_str.Length = 512;
644 upper_str.MaximumLength = 512;
645 upper_str.Buffer = upper_buf;
647 pRtlUpcaseUnicodeString(&result_str, &ascii_str, 0);
648 for (i = 0; i <= 255; i++) {
649 ok(result_str.Buffer[i] == upper_str.Buffer[i],
650 "RtlUpcaseUnicodeString works wrong: '%c'[=0x%x] is converted to '%c'[=0x%x], expected: '%c'[=0x%x]\n",
651 ascii_str.Buffer[i], ascii_str.Buffer[i],
652 result_str.Buffer[i], result_str.Buffer[i],
653 upper_str.Buffer[i], upper_str.Buffer[i]);
658 static void test_RtlDowncaseUnicodeString(void)
660 int i;
661 WCHAR ch;
662 WCHAR lower_ch;
663 WCHAR source_buf[1025];
664 WCHAR result_buf[1025];
665 WCHAR lower_buf[1025];
666 UNICODE_STRING source_str;
667 UNICODE_STRING result_str;
668 UNICODE_STRING lower_str;
670 for (i = 0; i < 1024; i++) {
671 ch = (WCHAR) i;
672 if (ch >= 'A' && ch <= 'Z') {
673 lower_ch = ch - 'A' + 'a';
674 } else if (ch >= 0xc0 && ch <= 0xde && ch != 0xd7) {
675 lower_ch = ch + 0x20;
676 } else if (ch >= 0x391 && ch <= 0x3ab && ch != 0x3a2) {
677 lower_ch = ch + 0x20;
678 } else {
679 switch (ch) {
680 case 0x178: lower_ch = 0xff; break;
681 case 0x181: lower_ch = 0x253; break;
682 case 0x186: lower_ch = 0x254; break;
683 case 0x189: lower_ch = 0x256; break;
684 case 0x18a: lower_ch = 0x257; break;
685 case 0x18e: lower_ch = 0x1dd; break;
686 case 0x18f: lower_ch = 0x259; break;
687 case 0x190: lower_ch = 0x25b; break;
688 case 0x193: lower_ch = 0x260; break;
689 case 0x194: lower_ch = 0x263; break;
690 case 0x196: lower_ch = 0x269; break;
691 case 0x197: lower_ch = 0x268; break;
692 case 0x19c: lower_ch = 0x26f; break;
693 case 0x19d: lower_ch = 0x272; break;
694 case 0x19f: lower_ch = 0x275; break;
695 case 0x1a9: lower_ch = 0x283; break;
696 case 0x1ae: lower_ch = 0x288; break;
697 case 0x1b1: lower_ch = 0x28a; break;
698 case 0x1b2: lower_ch = 0x28b; break;
699 case 0x1b7: lower_ch = 0x292; break;
700 case 0x1c4: lower_ch = 0x1c6; break;
701 case 0x1c7: lower_ch = 0x1c9; break;
702 case 0x1ca: lower_ch = 0x1cc; break;
703 case 0x1f1: lower_ch = 0x1f3; break;
704 case 0x386: lower_ch = 0x3ac; break;
705 case 0x388: lower_ch = 0x3ad; break;
706 case 0x389: lower_ch = 0x3ae; break;
707 case 0x38a: lower_ch = 0x3af; break;
708 case 0x38c: lower_ch = 0x3cc; break;
709 case 0x38e: lower_ch = 0x3cd; break;
710 case 0x38f: lower_ch = 0x3ce; break;
711 default: lower_ch = ch; break;
712 } /* switch */
714 source_buf[i] = ch;
715 result_buf[i] = '\0';
716 lower_buf[i] = lower_ch;
718 source_buf[i] = '\0';
719 result_buf[i] = '\0';
720 lower_buf[i] = '\0';
721 source_str.Length = 2048;
722 source_str.MaximumLength = 2048;
723 source_str.Buffer = source_buf;
724 result_str.Length = 2048;
725 result_str.MaximumLength = 2048;
726 result_str.Buffer = result_buf;
727 lower_str.Length = 2048;
728 lower_str.MaximumLength = 2048;
729 lower_str.Buffer = lower_buf;
731 pRtlDowncaseUnicodeString(&result_str, &source_str, 0);
732 for (i = 0; i <= 1024; i++) {
733 ok(result_str.Buffer[i] == lower_str.Buffer[i] || result_str.Buffer[i] == source_str.Buffer[i] + 1,
734 "RtlDowncaseUnicodeString works wrong: '%c'[=0x%x] is converted to '%c'[=0x%x], expected: '%c'[=0x%x]\n",
735 source_str.Buffer[i], source_str.Buffer[i],
736 result_str.Buffer[i], result_str.Buffer[i],
737 lower_str.Buffer[i], lower_str.Buffer[i]);
742 typedef struct {
743 int ansi_Length;
744 int ansi_MaximumLength;
745 int ansi_buf_size;
746 const char *ansi_buf;
747 int uni_Length;
748 int uni_MaximumLength;
749 int uni_buf_size;
750 const char *uni_buf;
751 BOOLEAN doalloc;
752 int res_Length;
753 int res_MaximumLength;
754 int res_buf_size;
755 const char *res_buf;
756 NTSTATUS result;
757 } ustr2astr_t;
759 static const ustr2astr_t ustr2astr[] = {
760 { 10, 12, 12, "------------", 0, 0, 0, "", TRUE, 0, 1, 1, "", STATUS_SUCCESS},
761 { 10, 12, 12, "------------", 12, 12, 12, "abcdef", TRUE, 6, 7, 7, "abcdef", STATUS_SUCCESS},
762 { 0, 2, 12, "------------", 12, 12, 12, "abcdef", TRUE, 6, 7, 7, "abcdef", STATUS_SUCCESS},
763 { 10, 12, 12, NULL, 12, 12, 12, "abcdef", TRUE, 6, 7, 7, "abcdef", STATUS_SUCCESS},
764 { 0, 0, 12, "------------", 12, 12, 12, "abcdef", FALSE, 6, 0, 0, "", STATUS_BUFFER_OVERFLOW},
765 { 0, 1, 12, "------------", 12, 12, 12, "abcdef", FALSE, 0, 1, 1, "", STATUS_BUFFER_OVERFLOW},
766 { 0, 2, 12, "------------", 12, 12, 12, "abcdef", FALSE, 1, 2, 2, "a", STATUS_BUFFER_OVERFLOW},
767 { 0, 3, 12, "------------", 12, 12, 12, "abcdef", FALSE, 2, 3, 3, "ab", STATUS_BUFFER_OVERFLOW},
768 { 0, 5, 12, "------------", 12, 12, 12, "abcdef", FALSE, 4, 5, 5, "abcd", STATUS_BUFFER_OVERFLOW},
769 { 8, 5, 12, "------------", 12, 12, 12, "abcdef", FALSE, 4, 5, 5, "abcd", STATUS_BUFFER_OVERFLOW},
770 { 8, 6, 12, "------------", 12, 12, 12, "abcdef", FALSE, 5, 6, 6, "abcde", STATUS_BUFFER_OVERFLOW},
771 { 8, 7, 12, "------------", 12, 12, 12, "abcdef", FALSE, 6, 7, 7, "abcdef", STATUS_SUCCESS},
772 { 8, 7, 12, "------------", 0, 12, 12, NULL, FALSE, 0, 7, 0, "", STATUS_SUCCESS},
773 #if 0
774 /* crashes on Japanese and Chinese XP */
775 { 0, 0, 12, NULL, 10, 10, 12, NULL, FALSE, 5, 0, 0, NULL, STATUS_BUFFER_OVERFLOW},
776 #endif
780 static void test_RtlUnicodeStringToAnsiString(void)
782 size_t pos;
783 CHAR ansi_buf[257];
784 WCHAR uni_buf[257];
785 STRING ansi_str;
786 UNICODE_STRING uni_str;
787 NTSTATUS result;
788 unsigned int test_num;
790 for (test_num = 0; test_num < ARRAY_SIZE(ustr2astr); test_num++) {
791 ansi_str.Length = ustr2astr[test_num].ansi_Length;
792 ansi_str.MaximumLength = ustr2astr[test_num].ansi_MaximumLength;
793 if (ustr2astr[test_num].ansi_buf != NULL) {
794 memcpy(ansi_buf, ustr2astr[test_num].ansi_buf, ustr2astr[test_num].ansi_buf_size);
795 ansi_buf[ustr2astr[test_num].ansi_buf_size] = '\0';
796 ansi_str.Buffer = ansi_buf;
797 } else {
798 ansi_str.Buffer = NULL;
800 uni_str.Length = ustr2astr[test_num].uni_Length;
801 uni_str.MaximumLength = ustr2astr[test_num].uni_MaximumLength;
802 if (ustr2astr[test_num].uni_buf != NULL) {
803 for (pos = 0; pos < ustr2astr[test_num].uni_buf_size/sizeof(WCHAR); pos++) {
804 uni_buf[pos] = ustr2astr[test_num].uni_buf[pos];
806 uni_str.Buffer = uni_buf;
807 } else {
808 uni_str.Buffer = NULL;
810 result = pRtlUnicodeStringToAnsiString(&ansi_str, &uni_str, ustr2astr[test_num].doalloc);
811 ok(result == ustr2astr[test_num].result,
812 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) has result %x, expected %x\n",
813 test_num, ustr2astr[test_num].doalloc, result, ustr2astr[test_num].result);
814 ok(ansi_str.Length == ustr2astr[test_num].res_Length,
815 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) ansi has Length %d, expected %d\n",
816 test_num, ustr2astr[test_num].doalloc, ansi_str.Length, ustr2astr[test_num].res_Length);
817 ok(ansi_str.MaximumLength == ustr2astr[test_num].res_MaximumLength,
818 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) ansi has MaximumLength %d, expected %d\n",
819 test_num, ustr2astr[test_num].doalloc, ansi_str.MaximumLength, ustr2astr[test_num].res_MaximumLength);
820 ok(memcmp(ansi_str.Buffer, ustr2astr[test_num].res_buf, ustr2astr[test_num].res_buf_size) == 0,
821 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) has ansi \"%s\" expected \"%s\"\n",
822 test_num, ustr2astr[test_num].doalloc, ansi_str.Buffer, ustr2astr[test_num].res_buf);
823 if(result == STATUS_SUCCESS && ustr2astr[test_num].doalloc)
824 pRtlFreeAnsiString(&ansi_str);
829 typedef struct {
830 int dest_Length;
831 int dest_MaximumLength;
832 int dest_buf_size;
833 const char *dest_buf;
834 const char *src;
835 int res_Length;
836 int res_MaximumLength;
837 int res_buf_size;
838 const char *res_buf;
839 NTSTATUS result;
840 } app_asc2str_t;
842 static const app_asc2str_t app_asc2str[] = {
843 { 5, 12, 15, "TestS01234abcde", "tring", 10, 12, 15, "TestStringabcde", STATUS_SUCCESS},
844 { 5, 11, 15, "TestS01234abcde", "tring", 10, 11, 15, "TestStringabcde", STATUS_SUCCESS},
845 { 5, 10, 15, "TestS01234abcde", "tring", 10, 10, 15, "TestStringabcde", STATUS_SUCCESS},
846 { 5, 9, 15, "TestS01234abcde", "tring", 5, 9, 15, "TestS01234abcde", STATUS_BUFFER_TOO_SMALL},
847 { 5, 0, 15, "TestS01234abcde", "tring", 5, 0, 15, "TestS01234abcde", STATUS_BUFFER_TOO_SMALL},
848 { 5, 14, 15, "TestS01234abcde", "tring", 10, 14, 15, "TestStringabcde", STATUS_SUCCESS},
849 { 5, 14, 15, "TestS01234abcde", NULL, 5, 14, 15, "TestS01234abcde", STATUS_SUCCESS},
850 { 5, 14, 15, NULL, NULL, 5, 14, 15, NULL, STATUS_SUCCESS},
851 { 5, 12, 15, "Tst\0S01234abcde", "tr\0i", 7, 12, 15, "Tst\0Str234abcde", STATUS_SUCCESS},
855 static void test_RtlAppendAsciizToString(void)
857 CHAR dest_buf[257];
858 STRING dest_str;
859 NTSTATUS result;
860 unsigned int test_num;
862 for (test_num = 0; test_num < ARRAY_SIZE(app_asc2str); test_num++) {
863 dest_str.Length = app_asc2str[test_num].dest_Length;
864 dest_str.MaximumLength = app_asc2str[test_num].dest_MaximumLength;
865 if (app_asc2str[test_num].dest_buf != NULL) {
866 memcpy(dest_buf, app_asc2str[test_num].dest_buf, app_asc2str[test_num].dest_buf_size);
867 dest_buf[app_asc2str[test_num].dest_buf_size] = '\0';
868 dest_str.Buffer = dest_buf;
869 } else {
870 dest_str.Buffer = NULL;
872 result = pRtlAppendAsciizToString(&dest_str, app_asc2str[test_num].src);
873 ok(result == app_asc2str[test_num].result,
874 "(test %d): RtlAppendAsciizToString(dest, src) has result %x, expected %x\n",
875 test_num, result, app_asc2str[test_num].result);
876 ok(dest_str.Length == app_asc2str[test_num].res_Length,
877 "(test %d): RtlAppendAsciizToString(dest, src) dest has Length %d, expected %d\n",
878 test_num, dest_str.Length, app_asc2str[test_num].res_Length);
879 ok(dest_str.MaximumLength == app_asc2str[test_num].res_MaximumLength,
880 "(test %d): RtlAppendAsciizToString(dest, src) dest has MaximumLength %d, expected %d\n",
881 test_num, dest_str.MaximumLength, app_asc2str[test_num].res_MaximumLength);
882 if (dest_str.Buffer == dest_buf) {
883 ok(memcmp(dest_buf, app_asc2str[test_num].res_buf, app_asc2str[test_num].res_buf_size) == 0,
884 "(test %d): RtlAppendAsciizToString(dest, src) has dest \"%s\" expected \"%s\"\n",
885 test_num, dest_buf, app_asc2str[test_num].res_buf);
886 } else {
887 ok(dest_str.Buffer == app_asc2str[test_num].res_buf,
888 "(test %d): RtlAppendAsciizToString(dest, src) dest has Buffer %p expected %p\n",
889 test_num, dest_str.Buffer, app_asc2str[test_num].res_buf);
895 typedef struct {
896 int dest_Length;
897 int dest_MaximumLength;
898 int dest_buf_size;
899 const char *dest_buf;
900 int src_Length;
901 int src_MaximumLength;
902 int src_buf_size;
903 const char *src_buf;
904 int res_Length;
905 int res_MaximumLength;
906 int res_buf_size;
907 const char *res_buf;
908 NTSTATUS result;
909 } app_str2str_t;
911 static const app_str2str_t app_str2str[] = {
912 { 5, 12, 15, "TestS01234abcde", 5, 5, 7, "tringZY", 10, 12, 15, "TestStringabcde", STATUS_SUCCESS},
913 { 5, 11, 15, "TestS01234abcde", 5, 5, 7, "tringZY", 10, 11, 15, "TestStringabcde", STATUS_SUCCESS},
914 { 5, 10, 15, "TestS01234abcde", 5, 5, 7, "tringZY", 10, 10, 15, "TestStringabcde", STATUS_SUCCESS},
915 { 5, 9, 15, "TestS01234abcde", 5, 5, 7, "tringZY", 5, 9, 15, "TestS01234abcde", STATUS_BUFFER_TOO_SMALL},
916 { 5, 0, 15, "TestS01234abcde", 0, 0, 7, "tringZY", 5, 0, 15, "TestS01234abcde", STATUS_SUCCESS},
917 { 5, 14, 15, "TestS01234abcde", 0, 0, 7, "tringZY", 5, 14, 15, "TestS01234abcde", STATUS_SUCCESS},
918 { 5, 14, 15, "TestS01234abcde", 0, 0, 7, NULL, 5, 14, 15, "TestS01234abcde", STATUS_SUCCESS},
919 { 5, 14, 15, NULL, 0, 0, 7, NULL, 5, 14, 15, NULL, STATUS_SUCCESS},
920 { 5, 12, 15, "Tst\0S01234abcde", 4, 4, 7, "tr\0iZY", 9, 12, 15, "Tst\0Str\0i4abcde", STATUS_SUCCESS},
924 static void test_RtlAppendStringToString(void)
926 CHAR dest_buf[257];
927 CHAR src_buf[257];
928 STRING dest_str;
929 STRING src_str;
930 NTSTATUS result;
931 unsigned int test_num;
933 for (test_num = 0; test_num < ARRAY_SIZE(app_str2str); test_num++) {
934 dest_str.Length = app_str2str[test_num].dest_Length;
935 dest_str.MaximumLength = app_str2str[test_num].dest_MaximumLength;
936 if (app_str2str[test_num].dest_buf != NULL) {
937 memcpy(dest_buf, app_str2str[test_num].dest_buf, app_str2str[test_num].dest_buf_size);
938 dest_buf[app_str2str[test_num].dest_buf_size] = '\0';
939 dest_str.Buffer = dest_buf;
940 } else {
941 dest_str.Buffer = NULL;
943 src_str.Length = app_str2str[test_num].src_Length;
944 src_str.MaximumLength = app_str2str[test_num].src_MaximumLength;
945 if (app_str2str[test_num].src_buf != NULL) {
946 memcpy(src_buf, app_str2str[test_num].src_buf, app_str2str[test_num].src_buf_size);
947 src_buf[app_str2str[test_num].src_buf_size] = '\0';
948 src_str.Buffer = src_buf;
949 } else {
950 src_str.Buffer = NULL;
952 result = pRtlAppendStringToString(&dest_str, &src_str);
953 ok(result == app_str2str[test_num].result,
954 "(test %d): RtlAppendStringToString(dest, src) has result %x, expected %x\n",
955 test_num, result, app_str2str[test_num].result);
956 ok(dest_str.Length == app_str2str[test_num].res_Length,
957 "(test %d): RtlAppendStringToString(dest, src) dest has Length %d, expected %d\n",
958 test_num, dest_str.Length, app_str2str[test_num].res_Length);
959 ok(dest_str.MaximumLength == app_str2str[test_num].res_MaximumLength,
960 "(test %d): RtlAppendStringToString(dest, src) dest has MaximumLength %d, expected %d\n",
961 test_num, dest_str.MaximumLength, app_str2str[test_num].res_MaximumLength);
962 if (dest_str.Buffer == dest_buf) {
963 ok(memcmp(dest_buf, app_str2str[test_num].res_buf, app_str2str[test_num].res_buf_size) == 0,
964 "(test %d): RtlAppendStringToString(dest, src) has dest \"%s\" expected \"%s\"\n",
965 test_num, dest_buf, app_str2str[test_num].res_buf);
966 } else {
967 ok(dest_str.Buffer == app_str2str[test_num].res_buf,
968 "(test %d): RtlAppendStringToString(dest, src) dest has Buffer %p expected %p\n",
969 test_num, dest_str.Buffer, app_str2str[test_num].res_buf);
975 typedef struct {
976 int dest_Length;
977 int dest_MaximumLength;
978 int dest_buf_size;
979 const char *dest_buf;
980 const char *src;
981 int res_Length;
982 int res_MaximumLength;
983 int res_buf_size;
984 const char *res_buf;
985 NTSTATUS result;
986 } app_uni2str_t;
988 static const app_uni2str_t app_uni2str[] = {
989 { 4, 12, 14, "Fake0123abcdef", "Ustr\0", 8, 12, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
990 { 4, 11, 14, "Fake0123abcdef", "Ustr\0", 8, 11, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
991 { 4, 10, 14, "Fake0123abcdef", "Ustr\0", 8, 10, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
992 /* In the following test the native function writes beyond MaximumLength
993 * { 4, 9, 14, "Fake0123abcdef", "Ustr\0", 8, 9, 14, "FakeUstrabcdef", STATUS_SUCCESS},
995 { 4, 8, 14, "Fake0123abcdef", "Ustr\0", 8, 8, 14, "FakeUstrabcdef", STATUS_SUCCESS},
996 { 4, 7, 14, "Fake0123abcdef", "Ustr\0", 4, 7, 14, "Fake0123abcdef", STATUS_BUFFER_TOO_SMALL},
997 { 4, 0, 14, "Fake0123abcdef", "Ustr\0", 4, 0, 14, "Fake0123abcdef", STATUS_BUFFER_TOO_SMALL},
998 { 4, 14, 14, "Fake0123abcdef", "Ustr\0", 8, 14, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
999 { 4, 14, 14, "Fake0123abcdef", NULL, 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS},
1000 { 4, 14, 14, NULL, NULL, 4, 14, 14, NULL, STATUS_SUCCESS},
1001 { 4, 14, 14, "Fake0123abcdef", "U\0stri\0", 10, 14, 14, "FakeU\0stri\0\0ef", STATUS_SUCCESS},
1002 { 6, 14, 16, "Te\0\0stabcdefghij", "St\0\0ri", 8, 14, 16, "Te\0\0stSt\0\0efghij", STATUS_SUCCESS},
1006 static void test_RtlAppendUnicodeToString(void)
1008 WCHAR dest_buf[257];
1009 UNICODE_STRING dest_str;
1010 NTSTATUS result;
1011 unsigned int test_num;
1013 for (test_num = 0; test_num < ARRAY_SIZE(app_uni2str); test_num++) {
1014 dest_str.Length = app_uni2str[test_num].dest_Length;
1015 dest_str.MaximumLength = app_uni2str[test_num].dest_MaximumLength;
1016 if (app_uni2str[test_num].dest_buf != NULL) {
1017 memcpy(dest_buf, app_uni2str[test_num].dest_buf, app_uni2str[test_num].dest_buf_size);
1018 dest_buf[app_uni2str[test_num].dest_buf_size/sizeof(WCHAR)] = '\0';
1019 dest_str.Buffer = dest_buf;
1020 } else {
1021 dest_str.Buffer = NULL;
1023 result = pRtlAppendUnicodeToString(&dest_str, (LPCWSTR) app_uni2str[test_num].src);
1024 ok(result == app_uni2str[test_num].result,
1025 "(test %d): RtlAppendUnicodeToString(dest, src) has result %x, expected %x\n",
1026 test_num, result, app_uni2str[test_num].result);
1027 ok(dest_str.Length == app_uni2str[test_num].res_Length,
1028 "(test %d): RtlAppendUnicodeToString(dest, src) dest has Length %d, expected %d\n",
1029 test_num, dest_str.Length, app_uni2str[test_num].res_Length);
1030 ok(dest_str.MaximumLength == app_uni2str[test_num].res_MaximumLength,
1031 "(test %d): RtlAppendUnicodeToString(dest, src) dest has MaximumLength %d, expected %d\n",
1032 test_num, dest_str.MaximumLength, app_uni2str[test_num].res_MaximumLength);
1033 if (dest_str.Buffer == dest_buf) {
1034 ok(memcmp(dest_buf, app_uni2str[test_num].res_buf, app_uni2str[test_num].res_buf_size) == 0,
1035 "(test %d): RtlAppendUnicodeToString(dest, src) has dest \"%s\" expected \"%s\"\n",
1036 test_num, (char *) dest_buf, app_uni2str[test_num].res_buf);
1037 } else {
1038 ok(dest_str.Buffer == (WCHAR *) app_uni2str[test_num].res_buf,
1039 "(test %d): RtlAppendUnicodeToString(dest, src) dest has Buffer %p expected %p\n",
1040 test_num, dest_str.Buffer, app_uni2str[test_num].res_buf);
1046 typedef struct {
1047 int dest_Length;
1048 int dest_MaximumLength;
1049 int dest_buf_size;
1050 const char *dest_buf;
1051 int src_Length;
1052 int src_MaximumLength;
1053 int src_buf_size;
1054 const char *src_buf;
1055 int res_Length;
1056 int res_MaximumLength;
1057 int res_buf_size;
1058 const char *res_buf;
1059 NTSTATUS result;
1060 } app_ustr2str_t;
1062 static const app_ustr2str_t app_ustr2str[] = {
1063 { 4, 12, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 12, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
1064 { 4, 11, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 11, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
1065 { 4, 10, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 10, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS},
1066 /* In the following test the native function writes beyond MaximumLength
1067 * { 4, 9, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 9, 14, "FakeUstrabcdef", STATUS_SUCCESS},
1069 { 4, 8, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 8, 14, "FakeUstrabcdef", STATUS_SUCCESS},
1070 { 4, 7, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 4, 7, 14, "Fake0123abcdef", STATUS_BUFFER_TOO_SMALL},
1071 { 4, 0, 14, "Fake0123abcdef", 0, 0, 8, "UstrZYXW", 4, 0, 14, "Fake0123abcdef", STATUS_SUCCESS},
1072 { 4, 14, 14, "Fake0123abcdef", 0, 0, 8, "UstrZYXW", 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS},
1073 { 4, 14, 14, "Fake0123abcdef", 0, 0, 8, NULL, 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS},
1074 { 4, 14, 14, NULL, 0, 0, 8, NULL, 4, 14, 14, NULL, STATUS_SUCCESS},
1075 { 6, 14, 16, "Te\0\0stabcdefghij", 6, 8, 8, "St\0\0riZY", 12, 14, 16, "Te\0\0stSt\0\0ri\0\0ij", STATUS_SUCCESS},
1079 static void test_RtlAppendUnicodeStringToString(void)
1081 WCHAR dest_buf[257];
1082 WCHAR src_buf[257];
1083 UNICODE_STRING dest_str;
1084 UNICODE_STRING src_str;
1085 NTSTATUS result;
1086 unsigned int test_num;
1088 for (test_num = 0; test_num < ARRAY_SIZE(app_ustr2str); test_num++) {
1089 dest_str.Length = app_ustr2str[test_num].dest_Length;
1090 dest_str.MaximumLength = app_ustr2str[test_num].dest_MaximumLength;
1091 if (app_ustr2str[test_num].dest_buf != NULL) {
1092 memcpy(dest_buf, app_ustr2str[test_num].dest_buf, app_ustr2str[test_num].dest_buf_size);
1093 dest_buf[app_ustr2str[test_num].dest_buf_size/sizeof(WCHAR)] = '\0';
1094 dest_str.Buffer = dest_buf;
1095 } else {
1096 dest_str.Buffer = NULL;
1098 src_str.Length = app_ustr2str[test_num].src_Length;
1099 src_str.MaximumLength = app_ustr2str[test_num].src_MaximumLength;
1100 if (app_ustr2str[test_num].src_buf != NULL) {
1101 memcpy(src_buf, app_ustr2str[test_num].src_buf, app_ustr2str[test_num].src_buf_size);
1102 src_buf[app_ustr2str[test_num].src_buf_size/sizeof(WCHAR)] = '\0';
1103 src_str.Buffer = src_buf;
1104 } else {
1105 src_str.Buffer = NULL;
1107 result = pRtlAppendUnicodeStringToString(&dest_str, &src_str);
1108 ok(result == app_ustr2str[test_num].result,
1109 "(test %d): RtlAppendStringToString(dest, src) has result %x, expected %x\n",
1110 test_num, result, app_ustr2str[test_num].result);
1111 ok(dest_str.Length == app_ustr2str[test_num].res_Length,
1112 "(test %d): RtlAppendStringToString(dest, src) dest has Length %d, expected %d\n",
1113 test_num, dest_str.Length, app_ustr2str[test_num].res_Length);
1114 ok(dest_str.MaximumLength == app_ustr2str[test_num].res_MaximumLength,
1115 "(test %d): RtlAppendStringToString(dest, src) dest has MaximumLength %d, expected %d\n",
1116 test_num, dest_str.MaximumLength, app_ustr2str[test_num].res_MaximumLength);
1117 if (dest_str.Buffer == dest_buf) {
1118 ok(memcmp(dest_buf, app_ustr2str[test_num].res_buf, app_ustr2str[test_num].res_buf_size) == 0,
1119 "(test %d): RtlAppendStringToString(dest, src) has dest \"%s\" expected \"%s\"\n",
1120 test_num, (char *) dest_buf, app_ustr2str[test_num].res_buf);
1121 } else {
1122 ok(dest_str.Buffer == (WCHAR *) app_ustr2str[test_num].res_buf,
1123 "(test %d): RtlAppendStringToString(dest, src) dest has Buffer %p expected %p\n",
1124 test_num, dest_str.Buffer, app_ustr2str[test_num].res_buf);
1130 typedef struct {
1131 int flags;
1132 const char *main_str;
1133 const char *search_chars;
1134 USHORT pos;
1135 NTSTATUS result;
1136 } find_ch_in_ustr_t;
1138 static const find_ch_in_ustr_t find_ch_in_ustr[] = {
1139 { 0, "Some Wild String", "S", 2, STATUS_SUCCESS},
1140 { 0, "This is a String", "String", 6, STATUS_SUCCESS},
1141 { 1, "This is a String", "String", 30, STATUS_SUCCESS},
1142 { 2, "This is a String", "String", 2, STATUS_SUCCESS},
1143 { 3, "This is a String", "String", 18, STATUS_SUCCESS},
1144 { 0, "This is a String", "Wild", 6, STATUS_SUCCESS},
1145 { 1, "This is a String", "Wild", 26, STATUS_SUCCESS},
1146 { 2, "This is a String", "Wild", 2, STATUS_SUCCESS},
1147 { 3, "This is a String", "Wild", 30, STATUS_SUCCESS},
1148 { 0, "abcdefghijklmnopqrstuvwxyz", "", 0, STATUS_NOT_FOUND},
1149 { 0, "abcdefghijklmnopqrstuvwxyz", "123", 0, STATUS_NOT_FOUND},
1150 { 0, "abcdefghijklmnopqrstuvwxyz", "a", 2, STATUS_SUCCESS},
1151 { 0, "abcdefghijklmnopqrstuvwxyz", "12a34", 2, STATUS_SUCCESS},
1152 { 0, "abcdefghijklmnopqrstuvwxyz", "12b34", 4, STATUS_SUCCESS},
1153 { 0, "abcdefghijklmnopqrstuvwxyz", "12y34", 50, STATUS_SUCCESS},
1154 { 0, "abcdefghijklmnopqrstuvwxyz", "12z34", 52, STATUS_SUCCESS},
1155 { 0, "abcdefghijklmnopqrstuvwxyz", "rvz", 36, STATUS_SUCCESS},
1156 { 0, "abcdefghijklmmlkjihgfedcba", "egik", 10, STATUS_SUCCESS},
1157 { 1, "abcdefghijklmnopqrstuvwxyz", "", 0, STATUS_NOT_FOUND},
1158 { 1, "abcdefghijklmnopqrstuvwxyz", "rvz", 50, STATUS_SUCCESS},
1159 { 1, "abcdefghijklmnopqrstuvwxyz", "ravy", 48, STATUS_SUCCESS},
1160 { 1, "abcdefghijklmnopqrstuvwxyz", "raxv", 46, STATUS_SUCCESS},
1161 { 2, "abcdefghijklmnopqrstuvwxyz", "", 2, STATUS_SUCCESS},
1162 { 2, "abcdefghijklmnopqrstuvwxyz", "rvz", 2, STATUS_SUCCESS},
1163 { 2, "abcdefghijklmnopqrstuvwxyz", "vaz", 4, STATUS_SUCCESS},
1164 { 2, "abcdefghijklmnopqrstuvwxyz", "ravbz", 6, STATUS_SUCCESS},
1165 { 3, "abcdefghijklmnopqrstuvwxyz", "", 50, STATUS_SUCCESS},
1166 { 3, "abcdefghijklmnopqrstuvwxyz", "123", 50, STATUS_SUCCESS},
1167 { 3, "abcdefghijklmnopqrstuvwxyz", "ahp", 50, STATUS_SUCCESS},
1168 { 3, "abcdefghijklmnopqrstuvwxyz", "rvz", 48, STATUS_SUCCESS},
1169 { 0, NULL, "abc", 0, STATUS_NOT_FOUND},
1170 { 1, NULL, "abc", 0, STATUS_NOT_FOUND},
1171 { 2, NULL, "abc", 0, STATUS_NOT_FOUND},
1172 { 3, NULL, "abc", 0, STATUS_NOT_FOUND},
1173 { 0, "abcdefghijklmnopqrstuvwxyz", NULL, 0, STATUS_NOT_FOUND},
1174 { 1, "abcdefghijklmnopqrstuvwxyz", NULL, 0, STATUS_NOT_FOUND},
1175 { 2, "abcdefghijklmnopqrstuvwxyz", NULL, 2, STATUS_SUCCESS},
1176 { 3, "abcdefghijklmnopqrstuvwxyz", NULL, 50, STATUS_SUCCESS},
1177 { 0, NULL, NULL, 0, STATUS_NOT_FOUND},
1178 { 1, NULL, NULL, 0, STATUS_NOT_FOUND},
1179 { 2, NULL, NULL, 0, STATUS_NOT_FOUND},
1180 { 3, NULL, NULL, 0, STATUS_NOT_FOUND},
1181 { 0, "abcdabcdabcdabcdabcdabcd", "abcd", 2, STATUS_SUCCESS},
1182 { 1, "abcdabcdabcdabcdabcdabcd", "abcd", 46, STATUS_SUCCESS},
1183 { 2, "abcdabcdabcdabcdabcdabcd", "abcd", 0, STATUS_NOT_FOUND},
1184 { 3, "abcdabcdabcdabcdabcdabcd", "abcd", 0, STATUS_NOT_FOUND},
1188 static void test_RtlFindCharInUnicodeString(void)
1190 WCHAR main_str_buf[257];
1191 WCHAR search_chars_buf[257];
1192 UNICODE_STRING main_str;
1193 UNICODE_STRING search_chars;
1194 USHORT pos;
1195 NTSTATUS result;
1196 unsigned int idx;
1197 unsigned int test_num;
1199 if (!pRtlFindCharInUnicodeString)
1201 win_skip("RtlFindCharInUnicodeString is not available\n");
1202 return;
1205 for (test_num = 0; test_num < ARRAY_SIZE(find_ch_in_ustr); test_num++) {
1206 if (find_ch_in_ustr[test_num].main_str != NULL) {
1207 main_str.Length = strlen(find_ch_in_ustr[test_num].main_str) * sizeof(WCHAR);
1208 main_str.MaximumLength = main_str.Length + sizeof(WCHAR);
1209 for (idx = 0; idx < main_str.Length / sizeof(WCHAR); idx++) {
1210 main_str_buf[idx] = find_ch_in_ustr[test_num].main_str[idx];
1212 main_str.Buffer = main_str_buf;
1213 } else {
1214 main_str.Length = 0;
1215 main_str.MaximumLength = 0;
1216 main_str.Buffer = NULL;
1218 if (find_ch_in_ustr[test_num].search_chars != NULL) {
1219 search_chars.Length = strlen(find_ch_in_ustr[test_num].search_chars) * sizeof(WCHAR);
1220 search_chars.MaximumLength = search_chars.Length + sizeof(WCHAR);
1221 for (idx = 0; idx < search_chars.Length / sizeof(WCHAR); idx++) {
1222 search_chars_buf[idx] = find_ch_in_ustr[test_num].search_chars[idx];
1224 search_chars.Buffer = search_chars_buf;
1225 } else {
1226 search_chars.Length = 0;
1227 search_chars.MaximumLength = 0;
1228 search_chars.Buffer = NULL;
1230 pos = 12345;
1231 result = pRtlFindCharInUnicodeString(find_ch_in_ustr[test_num].flags, &main_str, &search_chars, &pos);
1232 ok(result == find_ch_in_ustr[test_num].result,
1233 "(test %d): RtlFindCharInUnicodeString(%d, %s, %s, [out]) has result %x, expected %x\n",
1234 test_num, find_ch_in_ustr[test_num].flags,
1235 find_ch_in_ustr[test_num].main_str, find_ch_in_ustr[test_num].search_chars,
1236 result, find_ch_in_ustr[test_num].result);
1237 ok(pos == find_ch_in_ustr[test_num].pos,
1238 "(test %d): RtlFindCharInUnicodeString(%d, %s, %s, [out]) assigns %d to pos, expected %d\n",
1239 test_num, find_ch_in_ustr[test_num].flags,
1240 find_ch_in_ustr[test_num].main_str, find_ch_in_ustr[test_num].search_chars,
1241 pos, find_ch_in_ustr[test_num].pos);
1246 typedef struct {
1247 int base;
1248 const char *str;
1249 int value;
1250 NTSTATUS result, alternative;
1251 } str2int_t;
1253 static const str2int_t str2int[] = {
1254 { 0, "1011101100", 1011101100, STATUS_SUCCESS},
1255 { 0, "1234567", 1234567, STATUS_SUCCESS},
1256 { 0, "-214", -214, STATUS_SUCCESS},
1257 { 0, "+214", 214, STATUS_SUCCESS}, /* The + sign is allowed also */
1258 { 0, "--214", 0, STATUS_SUCCESS}, /* Do not accept more than one sign */
1259 { 0, "-+214", 0, STATUS_SUCCESS},
1260 { 0, "++214", 0, STATUS_SUCCESS},
1261 { 0, "+-214", 0, STATUS_SUCCESS},
1262 { 0, "\001\002\003\00411", 11, STATUS_SUCCESS}, /* whitespace char 1 to 4 */
1263 { 0, "\005\006\007\01012", 12, STATUS_SUCCESS}, /* whitespace char 5 to 8 */
1264 { 0, "\011\012\013\01413", 13, STATUS_SUCCESS}, /* whitespace char 9 to 12 */
1265 { 0, "\015\016\017\02014", 14, STATUS_SUCCESS}, /* whitespace char 13 to 16 */
1266 { 0, "\021\022\023\02415", 15, STATUS_SUCCESS}, /* whitespace char 17 to 20 */
1267 { 0, "\025\026\027\03016", 16, STATUS_SUCCESS}, /* whitespace char 21 to 24 */
1268 { 0, "\031\032\033\03417", 17, STATUS_SUCCESS}, /* whitespace char 25 to 28 */
1269 { 0, "\035\036\037\04018", 18, STATUS_SUCCESS}, /* whitespace char 29 to 32 */
1270 { 0, " \n \r \t214", 214, STATUS_SUCCESS},
1271 { 0, " \n \r \t+214", 214, STATUS_SUCCESS}, /* Signs can be used after whitespace */
1272 { 0, " \n \r \t-214", -214, STATUS_SUCCESS},
1273 { 0, "+214 0", 214, STATUS_SUCCESS}, /* Space terminates the number */
1274 { 0, " 214.01", 214, STATUS_SUCCESS}, /* Decimal point not accepted */
1275 { 0, " 214,01", 214, STATUS_SUCCESS}, /* Decimal comma not accepted */
1276 { 0, "f81", 0, STATUS_SUCCESS},
1277 { 0, "0x12345", 0x12345, STATUS_SUCCESS}, /* Hex */
1278 { 0, "00x12345", 0, STATUS_SUCCESS},
1279 { 0, "0xx12345", 0, STATUS_SUCCESS},
1280 { 0, "1x34", 1, STATUS_SUCCESS},
1281 { 0, "-9999999999", -1410065407, STATUS_SUCCESS}, /* Big negative integer */
1282 { 0, "-2147483649", 2147483647, STATUS_SUCCESS}, /* Too small to fit in 32 Bits */
1283 { 0, "-2147483648", 0x80000000L, STATUS_SUCCESS}, /* Smallest negative integer */
1284 { 0, "-2147483647", -2147483647, STATUS_SUCCESS},
1285 { 0, "-1", -1, STATUS_SUCCESS},
1286 { 0, "0", 0, STATUS_SUCCESS},
1287 { 0, "1", 1, STATUS_SUCCESS},
1288 { 0, "2147483646", 2147483646, STATUS_SUCCESS},
1289 { 0, "2147483647", 2147483647, STATUS_SUCCESS}, /* Largest signed positive integer */
1290 { 0, "2147483648", 0x80000000L, STATUS_SUCCESS}, /* Positive int equal to smallest negative int */
1291 { 0, "2147483649", -2147483647, STATUS_SUCCESS},
1292 { 0, "4294967294", -2, STATUS_SUCCESS},
1293 { 0, "4294967295", -1, STATUS_SUCCESS}, /* Largest unsigned integer */
1294 { 0, "4294967296", 0, STATUS_SUCCESS}, /* Too big to fit in 32 Bits */
1295 { 0, "9999999999", 1410065407, STATUS_SUCCESS}, /* Big positive integer */
1296 { 0, "056789", 56789, STATUS_SUCCESS}, /* Leading zero and still decimal */
1297 { 0, "b1011101100", 0, STATUS_SUCCESS}, /* Binary (b-notation) */
1298 { 0, "-b1011101100", 0, STATUS_SUCCESS}, /* Negative Binary (b-notation) */
1299 { 0, "b10123456789", 0, STATUS_SUCCESS}, /* Binary with nonbinary digits (2-9) */
1300 { 0, "0b1011101100", 748, STATUS_SUCCESS}, /* Binary (0b-notation) */
1301 { 0, "-0b1011101100", -748, STATUS_SUCCESS}, /* Negative binary (0b-notation) */
1302 { 0, "0b10123456789", 5, STATUS_SUCCESS}, /* Binary with nonbinary digits (2-9) */
1303 { 0, "-0b10123456789", -5, STATUS_SUCCESS}, /* Negative binary with nonbinary digits (2-9) */
1304 { 0, "0b1", 1, STATUS_SUCCESS}, /* one digit binary */
1305 { 0, "0b2", 0, STATUS_SUCCESS}, /* empty binary */
1306 { 0, "0b", 0, STATUS_SUCCESS}, /* empty binary */
1307 { 0, "o1234567", 0, STATUS_SUCCESS}, /* Octal (o-notation) */
1308 { 0, "-o1234567", 0, STATUS_SUCCESS}, /* Negative Octal (o-notation) */
1309 { 0, "o56789", 0, STATUS_SUCCESS}, /* Octal with nonoctal digits (8 and 9) */
1310 { 0, "0o1234567", 01234567, STATUS_SUCCESS}, /* Octal (0o-notation) */
1311 { 0, "-0o1234567", -01234567, STATUS_SUCCESS}, /* Negative octal (0o-notation) */
1312 { 0, "0o56789", 0567, STATUS_SUCCESS}, /* Octal with nonoctal digits (8 and 9) */
1313 { 0, "-0o56789", -0567, STATUS_SUCCESS}, /* Negative octal with nonoctal digits (8 and 9) */
1314 { 0, "0o7", 7, STATUS_SUCCESS}, /* one digit octal */
1315 { 0, "0o8", 0, STATUS_SUCCESS}, /* empty octal */
1316 { 0, "0o", 0, STATUS_SUCCESS}, /* empty octal */
1317 { 0, "0d1011101100", 0, STATUS_SUCCESS}, /* explicit decimal with 0d */
1318 { 0, "x89abcdef", 0, STATUS_SUCCESS}, /* Hex with lower case digits a-f (x-notation) */
1319 { 0, "xFEDCBA00", 0, STATUS_SUCCESS}, /* Hex with upper case digits A-F (x-notation) */
1320 { 0, "-xFEDCBA00", 0, STATUS_SUCCESS}, /* Negative Hexadecimal (x-notation) */
1321 { 0, "0x89abcdef", 0x89abcdef, STATUS_SUCCESS}, /* Hex with lower case digits a-f (0x-notation) */
1322 { 0, "0xFEDCBA00", 0xFEDCBA00, STATUS_SUCCESS}, /* Hex with upper case digits A-F (0x-notation) */
1323 { 0, "-0xFEDCBA00", 19088896, STATUS_SUCCESS}, /* Negative Hexadecimal (0x-notation) */
1324 { 0, "0xabcdefgh", 0xabcdef, STATUS_SUCCESS}, /* Hex with illegal lower case digits (g-z) */
1325 { 0, "0xABCDEFGH", 0xABCDEF, STATUS_SUCCESS}, /* Hex with illegal upper case digits (G-Z) */
1326 { 0, "0xF", 0xf, STATUS_SUCCESS}, /* one digit hexadecimal */
1327 { 0, "0xG", 0, STATUS_SUCCESS}, /* empty hexadecimal */
1328 { 0, "0x", 0, STATUS_SUCCESS}, /* empty hexadecimal */
1329 { 0, "", 0, STATUS_SUCCESS, STATUS_INVALID_PARAMETER}, /* empty string */
1330 { 2, "1011101100", 748, STATUS_SUCCESS},
1331 { 2, "-1011101100", -748, STATUS_SUCCESS},
1332 { 2, "2", 0, STATUS_SUCCESS},
1333 { 2, "0b1011101100", 0, STATUS_SUCCESS},
1334 { 2, "0o1011101100", 0, STATUS_SUCCESS},
1335 { 2, "0d1011101100", 0, STATUS_SUCCESS},
1336 { 2, "0x1011101100", 0, STATUS_SUCCESS},
1337 { 2, "", 0, STATUS_SUCCESS, STATUS_INVALID_PARAMETER}, /* empty string */
1338 { 8, "1011101100", 136610368, STATUS_SUCCESS},
1339 { 8, "-1011101100", -136610368, STATUS_SUCCESS},
1340 { 8, "8", 0, STATUS_SUCCESS},
1341 { 8, "0b1011101100", 0, STATUS_SUCCESS},
1342 { 8, "0o1011101100", 0, STATUS_SUCCESS},
1343 { 8, "0d1011101100", 0, STATUS_SUCCESS},
1344 { 8, "0x1011101100", 0, STATUS_SUCCESS},
1345 { 8, "", 0, STATUS_SUCCESS, STATUS_INVALID_PARAMETER}, /* empty string */
1346 {10, "1011101100", 1011101100, STATUS_SUCCESS},
1347 {10, "-1011101100", -1011101100, STATUS_SUCCESS},
1348 {10, "0b1011101100", 0, STATUS_SUCCESS},
1349 {10, "0o1011101100", 0, STATUS_SUCCESS},
1350 {10, "0d1011101100", 0, STATUS_SUCCESS},
1351 {10, "0x1011101100", 0, STATUS_SUCCESS},
1352 {10, "o12345", 0, STATUS_SUCCESS}, /* Octal although base is 10 */
1353 {10, "", 0, STATUS_SUCCESS, STATUS_INVALID_PARAMETER}, /* empty string */
1354 {16, "1011101100", 286265600, STATUS_SUCCESS},
1355 {16, "-1011101100", -286265600, STATUS_SUCCESS},
1356 {16, "G", 0, STATUS_SUCCESS},
1357 {16, "g", 0, STATUS_SUCCESS},
1358 {16, "0b1011101100", 286265600, STATUS_SUCCESS},
1359 {16, "0o1011101100", 0, STATUS_SUCCESS},
1360 {16, "0d1011101100", 286265600, STATUS_SUCCESS},
1361 {16, "0x1011101100", 0, STATUS_SUCCESS},
1362 {16, "", 0, STATUS_SUCCESS, STATUS_INVALID_PARAMETER}, /* empty string */
1363 {20, "0", 0, STATUS_INVALID_PARAMETER}, /* illegal base */
1364 {-8, "0", 0, STATUS_INVALID_PARAMETER}, /* Negative base */
1365 /* { 0, NULL, 0, STATUS_SUCCESS}, */ /* NULL as string */
1369 static void test_RtlUnicodeStringToInteger(void)
1371 unsigned int test_num;
1372 int value;
1373 NTSTATUS result;
1374 WCHAR *wstr;
1375 UNICODE_STRING uni;
1377 for (test_num = 0; test_num < ARRAY_SIZE(str2int); test_num++) {
1378 wstr = AtoW(str2int[test_num].str);
1379 value = 0xdeadbeef;
1380 pRtlInitUnicodeString(&uni, wstr);
1381 result = pRtlUnicodeStringToInteger(&uni, str2int[test_num].base, &value);
1382 ok(result == str2int[test_num].result ||
1383 (str2int[test_num].alternative && result == str2int[test_num].alternative),
1384 "(test %d): RtlUnicodeStringToInteger(\"%s\", %d, [out]) has result %x, expected: %x (%x)\n",
1385 test_num, str2int[test_num].str, str2int[test_num].base, result,
1386 str2int[test_num].result, str2int[test_num].alternative);
1387 if (result == STATUS_SUCCESS)
1388 ok(value == str2int[test_num].value ||
1389 broken(str2int[test_num].str[0] == '\0' && str2int[test_num].base == 16), /* nt4 */
1390 "(test %d): RtlUnicodeStringToInteger(\"%s\", %d, [out]) assigns value %d, expected: %d\n",
1391 test_num, str2int[test_num].str, str2int[test_num].base, value, str2int[test_num].value);
1392 else
1393 ok(value == 0xdeadbeef || value == 0 /* vista */,
1394 "(test %d): RtlUnicodeStringToInteger(\"%s\", %d, [out]) assigns value %d, expected 0 or deadbeef\n",
1395 test_num, str2int[test_num].str, str2int[test_num].base, value);
1396 HeapFree(GetProcessHeap(), 0, wstr);
1399 wstr = AtoW(str2int[1].str);
1400 pRtlInitUnicodeString(&uni, wstr);
1401 result = pRtlUnicodeStringToInteger(&uni, str2int[1].base, NULL);
1402 ok(result == STATUS_ACCESS_VIOLATION,
1403 "call failed: RtlUnicodeStringToInteger(\"%s\", %d, NULL) has result %x\n",
1404 str2int[1].str, str2int[1].base, result);
1405 result = pRtlUnicodeStringToInteger(&uni, 20, NULL);
1406 ok(result == STATUS_INVALID_PARAMETER || result == STATUS_ACCESS_VIOLATION,
1407 "call failed: RtlUnicodeStringToInteger(\"%s\", 20, NULL) has result %x\n",
1408 str2int[1].str, result);
1410 uni.Length = 10; /* Make Length shorter (5 WCHARS instead of 7) */
1411 result = pRtlUnicodeStringToInteger(&uni, str2int[1].base, &value);
1412 ok(result == STATUS_SUCCESS,
1413 "call failed: RtlUnicodeStringToInteger(\"12345\", %d, [out]) has result %x\n",
1414 str2int[1].base, result);
1415 ok(value == 12345,
1416 "didn't return expected value (test a): expected: %d, got: %d\n",
1417 12345, value);
1419 uni.Length = 5; /* Use odd Length (2.5 WCHARS) */
1420 result = pRtlUnicodeStringToInteger(&uni, str2int[1].base, &value);
1421 ok(result == STATUS_SUCCESS || result == STATUS_INVALID_PARAMETER /* vista */,
1422 "call failed: RtlUnicodeStringToInteger(\"12\", %d, [out]) has result %x\n",
1423 str2int[1].base, result);
1424 if (result == STATUS_SUCCESS)
1425 ok(value == 12, "didn't return expected value (test b): expected: %d, got: %d\n", 12, value);
1427 uni.Length = 2;
1428 result = pRtlUnicodeStringToInteger(&uni, str2int[1].base, &value);
1429 ok(result == STATUS_SUCCESS,
1430 "call failed: RtlUnicodeStringToInteger(\"1\", %d, [out]) has result %x\n",
1431 str2int[1].base, result);
1432 ok(value == 1,
1433 "didn't return expected value (test c): expected: %d, got: %d\n",
1434 1, value);
1435 /* w2k: uni.Length = 0 returns value 11234567 instead of 0 */
1436 HeapFree(GetProcessHeap(), 0, wstr);
1440 static void test_RtlCharToInteger(void)
1442 unsigned int test_num;
1443 int value;
1444 NTSTATUS result;
1446 for (test_num = 0; test_num < ARRAY_SIZE(str2int); test_num++) {
1447 /* w2k skips a leading '\0' and processes the string after */
1448 if (str2int[test_num].str[0] != '\0') {
1449 value = 0xdeadbeef;
1450 result = pRtlCharToInteger(str2int[test_num].str, str2int[test_num].base, &value);
1451 ok(result == str2int[test_num].result ||
1452 (str2int[test_num].alternative && result == str2int[test_num].alternative),
1453 "(test %d): call failed: RtlCharToInteger(\"%s\", %d, [out]) has result %x, expected: %x (%x)\n",
1454 test_num, str2int[test_num].str, str2int[test_num].base, result,
1455 str2int[test_num].result, str2int[test_num].alternative);
1456 if (result == STATUS_SUCCESS)
1457 ok(value == str2int[test_num].value,
1458 "(test %d): call failed: RtlCharToInteger(\"%s\", %d, [out]) assigns value %d, expected: %d\n",
1459 test_num, str2int[test_num].str, str2int[test_num].base, value, str2int[test_num].value);
1460 else
1461 ok(value == 0 || value == 0xdeadbeef,
1462 "(test %d): call failed: RtlCharToInteger(\"%s\", %d, [out]) assigns value %d, expected 0 or deadbeef\n",
1463 test_num, str2int[test_num].str, str2int[test_num].base, value);
1467 result = pRtlCharToInteger(str2int[1].str, str2int[1].base, NULL);
1468 ok(result == STATUS_ACCESS_VIOLATION,
1469 "call failed: RtlCharToInteger(\"%s\", %d, NULL) has result %x\n",
1470 str2int[1].str, str2int[1].base, result);
1472 result = pRtlCharToInteger(str2int[1].str, 20, NULL);
1473 ok(result == STATUS_INVALID_PARAMETER,
1474 "call failed: RtlCharToInteger(\"%s\", 20, NULL) has result %x\n",
1475 str2int[1].str, result);
1479 #define STRI_BUFFER_LENGTH 35
1481 typedef struct {
1482 int base;
1483 ULONG value;
1484 USHORT Length;
1485 USHORT MaximumLength;
1486 const char *Buffer;
1487 NTSTATUS result;
1488 } int2str_t;
1490 static const int2str_t int2str[] = {
1491 {10, 123, 3, 11, "123\0-------------------------------", STATUS_SUCCESS},
1493 { 0, 0x80000000U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS}, /* min signed int */
1494 { 0, -2147483647, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS},
1495 { 0, -2, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS},
1496 { 0, -1, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS},
1497 { 0, 0, 1, 11, "0\0---------------------------------", STATUS_SUCCESS},
1498 { 0, 1, 1, 11, "1\0---------------------------------", STATUS_SUCCESS},
1499 { 0, 12, 2, 11, "12\0--------------------------------", STATUS_SUCCESS},
1500 { 0, 123, 3, 11, "123\0-------------------------------", STATUS_SUCCESS},
1501 { 0, 1234, 4, 11, "1234\0------------------------------", STATUS_SUCCESS},
1502 { 0, 12345, 5, 11, "12345\0-----------------------------", STATUS_SUCCESS},
1503 { 0, 123456, 6, 11, "123456\0----------------------------", STATUS_SUCCESS},
1504 { 0, 1234567, 7, 11, "1234567\0---------------------------", STATUS_SUCCESS},
1505 { 0, 12345678, 8, 11, "12345678\0--------------------------", STATUS_SUCCESS},
1506 { 0, 123456789, 9, 11, "123456789\0-------------------------", STATUS_SUCCESS},
1507 { 0, 2147483646, 10, 11, "2147483646\0------------------------", STATUS_SUCCESS},
1508 { 0, 2147483647, 10, 11, "2147483647\0------------------------", STATUS_SUCCESS}, /* max signed int */
1509 { 0, 2147483648U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS}, /* uint = -max int */
1510 { 0, 2147483649U, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS},
1511 { 0, 4294967294U, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS},
1512 { 0, 4294967295U, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS}, /* max unsigned int */
1514 { 2, 0x80000000U, 32, 33, "10000000000000000000000000000000\0--", STATUS_SUCCESS}, /* min signed int */
1515 { 2, -2147483647, 32, 33, "10000000000000000000000000000001\0--", STATUS_SUCCESS},
1516 { 2, -2, 32, 33, "11111111111111111111111111111110\0--", STATUS_SUCCESS},
1517 { 2, -1, 32, 33, "11111111111111111111111111111111\0--", STATUS_SUCCESS},
1518 { 2, 0, 1, 33, "0\0---------------------------------", STATUS_SUCCESS},
1519 { 2, 1, 1, 33, "1\0---------------------------------", STATUS_SUCCESS},
1520 { 2, 10, 4, 33, "1010\0------------------------------", STATUS_SUCCESS},
1521 { 2, 100, 7, 33, "1100100\0---------------------------", STATUS_SUCCESS},
1522 { 2, 1000, 10, 33, "1111101000\0------------------------", STATUS_SUCCESS},
1523 { 2, 10000, 14, 33, "10011100010000\0--------------------", STATUS_SUCCESS},
1524 { 2, 32767, 15, 33, "111111111111111\0-------------------", STATUS_SUCCESS},
1525 /* { 2, 32768, 16, 33, "1000000000000000\0------------------", STATUS_SUCCESS}, broken on windows */
1526 /* { 2, 65535, 16, 33, "1111111111111111\0------------------", STATUS_SUCCESS}, broken on windows */
1527 { 2, 65536, 17, 33, "10000000000000000\0-----------------", STATUS_SUCCESS},
1528 { 2, 100000, 17, 33, "11000011010100000\0-----------------", STATUS_SUCCESS},
1529 { 2, 1000000, 20, 33, "11110100001001000000\0--------------", STATUS_SUCCESS},
1530 { 2, 10000000, 24, 33, "100110001001011010000000\0----------", STATUS_SUCCESS},
1531 { 2, 100000000, 27, 33, "101111101011110000100000000\0-------", STATUS_SUCCESS},
1532 { 2, 1000000000, 30, 33, "111011100110101100101000000000\0----", STATUS_SUCCESS},
1533 { 2, 1073741823, 30, 33, "111111111111111111111111111111\0----", STATUS_SUCCESS},
1534 { 2, 2147483646, 31, 33, "1111111111111111111111111111110\0---", STATUS_SUCCESS},
1535 { 2, 2147483647, 31, 33, "1111111111111111111111111111111\0---", STATUS_SUCCESS}, /* max signed int */
1536 { 2, 2147483648U, 32, 33, "10000000000000000000000000000000\0--", STATUS_SUCCESS}, /* uint = -max int */
1537 { 2, 2147483649U, 32, 33, "10000000000000000000000000000001\0--", STATUS_SUCCESS},
1538 { 2, 4294967294U, 32, 33, "11111111111111111111111111111110\0--", STATUS_SUCCESS},
1539 { 2, 4294967295U, 32, 33, "11111111111111111111111111111111\0--", STATUS_SUCCESS}, /* max unsigned int */
1541 { 8, 0x80000000U, 11, 12, "20000000000\0-----------------------", STATUS_SUCCESS}, /* min signed int */
1542 { 8, -2147483647, 11, 12, "20000000001\0-----------------------", STATUS_SUCCESS},
1543 { 8, -2, 11, 12, "37777777776\0-----------------------", STATUS_SUCCESS},
1544 { 8, -1, 11, 12, "37777777777\0-----------------------", STATUS_SUCCESS},
1545 { 8, 0, 1, 12, "0\0---------------------------------", STATUS_SUCCESS},
1546 { 8, 1, 1, 12, "1\0---------------------------------", STATUS_SUCCESS},
1547 { 8, 2147483646, 11, 12, "17777777776\0-----------------------", STATUS_SUCCESS},
1548 { 8, 2147483647, 11, 12, "17777777777\0-----------------------", STATUS_SUCCESS}, /* max signed int */
1549 { 8, 2147483648U, 11, 12, "20000000000\0-----------------------", STATUS_SUCCESS}, /* uint = -max int */
1550 { 8, 2147483649U, 11, 12, "20000000001\0-----------------------", STATUS_SUCCESS},
1551 { 8, 4294967294U, 11, 12, "37777777776\0-----------------------", STATUS_SUCCESS},
1552 { 8, 4294967295U, 11, 12, "37777777777\0-----------------------", STATUS_SUCCESS}, /* max unsigned int */
1554 {10, 0x80000000U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS}, /* min signed int */
1555 {10, -2147483647, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS},
1556 {10, -2, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS},
1557 {10, -1, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS},
1558 {10, 0, 1, 11, "0\0---------------------------------", STATUS_SUCCESS},
1559 {10, 1, 1, 11, "1\0---------------------------------", STATUS_SUCCESS},
1560 {10, 2147483646, 10, 11, "2147483646\0------------------------", STATUS_SUCCESS},
1561 {10, 2147483647, 10, 11, "2147483647\0------------------------", STATUS_SUCCESS}, /* max signed int */
1562 {10, 2147483648U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS}, /* uint = -max int */
1563 {10, 2147483649U, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS},
1564 {10, 4294967294U, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS},
1565 {10, 4294967295U, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS}, /* max unsigned int */
1567 {16, 0x80000000U, 8, 9, "80000000\0--------------------------", STATUS_SUCCESS}, /* min signed int */
1568 {16, -2147483647, 8, 9, "80000001\0--------------------------", STATUS_SUCCESS},
1569 {16, -2, 8, 9, "FFFFFFFE\0--------------------------", STATUS_SUCCESS},
1570 {16, -1, 8, 9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS},
1571 {16, 0, 1, 9, "0\0---------------------------------", STATUS_SUCCESS},
1572 {16, 1, 1, 9, "1\0---------------------------------", STATUS_SUCCESS},
1573 {16, 2147483646, 8, 9, "7FFFFFFE\0--------------------------", STATUS_SUCCESS},
1574 {16, 2147483647, 8, 9, "7FFFFFFF\0--------------------------", STATUS_SUCCESS}, /* max signed int */
1575 {16, 2147483648U, 8, 9, "80000000\0--------------------------", STATUS_SUCCESS}, /* uint = -max int */
1576 {16, 2147483649U, 8, 9, "80000001\0--------------------------", STATUS_SUCCESS},
1577 {16, 4294967294U, 8, 9, "FFFFFFFE\0--------------------------", STATUS_SUCCESS},
1578 {16, 4294967295U, 8, 9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS}, /* max unsigned int */
1580 /* { 2, 32768, 16, 17, "1000000000000000\0------------------", STATUS_SUCCESS}, broken on windows */
1581 /* { 2, 32768, 16, 16, "1000000000000000-------------------", STATUS_SUCCESS}, broken on windows */
1582 { 2, 65536, 17, 18, "10000000000000000\0-----------------", STATUS_SUCCESS},
1583 { 2, 65536, 17, 17, "10000000000000000------------------", STATUS_SUCCESS},
1584 { 2, 131072, 18, 19, "100000000000000000\0----------------", STATUS_SUCCESS},
1585 { 2, 131072, 18, 18, "100000000000000000-----------------", STATUS_SUCCESS},
1586 {16, 0xffffffff, 8, 9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS},
1587 {16, 0xffffffff, 8, 8, "FFFFFFFF---------------------------", STATUS_SUCCESS}, /* No \0 term */
1588 {16, 0xffffffff, 8, 7, "-----------------------------------", STATUS_BUFFER_OVERFLOW}, /* Too short */
1589 {16, 0xa, 1, 2, "A\0---------------------------------", STATUS_SUCCESS},
1590 {16, 0xa, 1, 1, "A----------------------------------", STATUS_SUCCESS}, /* No \0 term */
1591 {16, 0, 1, 0, "-----------------------------------", STATUS_BUFFER_OVERFLOW},
1592 {20, 0xdeadbeef, 0, 9, "-----------------------------------", STATUS_INVALID_PARAMETER}, /* ill. base */
1593 {-8, 07654321, 0, 12, "-----------------------------------", STATUS_INVALID_PARAMETER}, /* neg. base */
1597 static void one_RtlIntegerToUnicodeString_test(int test_num, const int2str_t *int2str)
1599 int pos;
1600 WCHAR expected_str_Buffer[STRI_BUFFER_LENGTH + 1];
1601 UNICODE_STRING expected_unicode_string;
1602 STRING expected_ansi_str;
1603 WCHAR str_Buffer[STRI_BUFFER_LENGTH + 1];
1604 UNICODE_STRING unicode_string;
1605 STRING ansi_str;
1606 NTSTATUS result;
1608 for (pos = 0; pos < STRI_BUFFER_LENGTH; pos++) {
1609 expected_str_Buffer[pos] = int2str->Buffer[pos];
1611 expected_unicode_string.Length = int2str->Length * sizeof(WCHAR);
1612 expected_unicode_string.MaximumLength = int2str->MaximumLength * sizeof(WCHAR);
1613 expected_unicode_string.Buffer = expected_str_Buffer;
1614 pRtlUnicodeStringToAnsiString(&expected_ansi_str, &expected_unicode_string, 1);
1616 for (pos = 0; pos < STRI_BUFFER_LENGTH; pos++) {
1617 str_Buffer[pos] = '-';
1619 unicode_string.Length = 0;
1620 unicode_string.MaximumLength = int2str->MaximumLength * sizeof(WCHAR);
1621 unicode_string.Buffer = str_Buffer;
1623 result = pRtlIntegerToUnicodeString(int2str->value, int2str->base, &unicode_string);
1624 pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1);
1625 if (result == STATUS_BUFFER_OVERFLOW) {
1626 /* On BUFFER_OVERFLOW the string Buffer should be unchanged */
1627 for (pos = 0; pos < STRI_BUFFER_LENGTH; pos++) {
1628 expected_str_Buffer[pos] = '-';
1630 /* w2k: The native function has two reasons for BUFFER_OVERFLOW: */
1631 /* If the value is too large to convert: The Length is unchanged */
1632 /* If str is too small to hold the string: Set str->Length to the length */
1633 /* the string would have (which can be larger than the MaximumLength). */
1634 /* To allow all this in the tests we do the following: */
1635 if (expected_unicode_string.Length > 32 && unicode_string.Length == 0) {
1636 /* The value is too large to convert only triggered when testing native */
1637 expected_unicode_string.Length = 0;
1639 } else {
1640 ok(result == int2str->result,
1641 "(test %d): RtlIntegerToUnicodeString(%u, %d, [out]) has result %x, expected: %x\n",
1642 test_num, int2str->value, int2str->base, result, int2str->result);
1643 if (result == STATUS_SUCCESS) {
1644 ok(unicode_string.Buffer[unicode_string.Length/sizeof(WCHAR)] == '\0',
1645 "(test %d): RtlIntegerToUnicodeString(%u, %d, [out]) string \"%s\" is not NULL terminated\n",
1646 test_num, int2str->value, int2str->base, ansi_str.Buffer);
1649 ok(memcmp(unicode_string.Buffer, expected_unicode_string.Buffer, STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0,
1650 "(test %d): RtlIntegerToUnicodeString(%u, %d, [out]) assigns string \"%s\", expected: \"%s\"\n",
1651 test_num, int2str->value, int2str->base, ansi_str.Buffer, expected_ansi_str.Buffer);
1652 ok(unicode_string.Length == expected_unicode_string.Length,
1653 "(test %d): RtlIntegerToUnicodeString(%u, %d, [out]) string has Length %d, expected: %d\n",
1654 test_num, int2str->value, int2str->base, unicode_string.Length, expected_unicode_string.Length);
1655 ok(unicode_string.MaximumLength == expected_unicode_string.MaximumLength,
1656 "(test %d): RtlIntegerToUnicodeString(%u, %d, [out]) string has MaximumLength %d, expected: %d\n",
1657 test_num, int2str->value, int2str->base, unicode_string.MaximumLength, expected_unicode_string.MaximumLength);
1658 pRtlFreeAnsiString(&expected_ansi_str);
1659 pRtlFreeAnsiString(&ansi_str);
1663 static void test_RtlIntegerToUnicodeString(void)
1665 size_t test_num;
1667 for (test_num = 0; test_num < ARRAY_SIZE(int2str); test_num++)
1668 one_RtlIntegerToUnicodeString_test(test_num, &int2str[test_num]);
1672 static void one_RtlIntegerToChar_test(int test_num, const int2str_t *int2str)
1674 NTSTATUS result;
1675 char dest_str[STRI_BUFFER_LENGTH + 1];
1677 memset(dest_str, '-', STRI_BUFFER_LENGTH);
1678 dest_str[STRI_BUFFER_LENGTH] = '\0';
1679 result = pRtlIntegerToChar(int2str->value, int2str->base, int2str->MaximumLength, dest_str);
1680 ok(result == int2str->result,
1681 "(test %d): RtlIntegerToChar(%u, %d, %d, [out]) has result %x, expected: %x\n",
1682 test_num, int2str->value, int2str->base, int2str->MaximumLength, result, int2str->result);
1683 ok(memcmp(dest_str, int2str->Buffer, STRI_BUFFER_LENGTH) == 0,
1684 "(test %d): RtlIntegerToChar(%u, %d, %d, [out]) assigns string \"%s\", expected: \"%s\"\n",
1685 test_num, int2str->value, int2str->base, int2str->MaximumLength, dest_str, int2str->Buffer);
1689 static void test_RtlIntegerToChar(void)
1691 NTSTATUS result;
1692 size_t test_num;
1694 for (test_num = 0; test_num < ARRAY_SIZE(int2str); test_num++)
1695 one_RtlIntegerToChar_test(test_num, &int2str[test_num]);
1697 result = pRtlIntegerToChar(int2str[0].value, 20, int2str[0].MaximumLength, NULL);
1698 ok(result == STATUS_INVALID_PARAMETER,
1699 "(test a): RtlIntegerToChar(%u, %d, %d, NULL) has result %x, expected: %x\n",
1700 int2str[0].value, 20, int2str[0].MaximumLength, result, STATUS_INVALID_PARAMETER);
1702 result = pRtlIntegerToChar(int2str[0].value, 20, 0, NULL);
1703 ok(result == STATUS_INVALID_PARAMETER,
1704 "(test b): RtlIntegerToChar(%u, %d, %d, NULL) has result %x, expected: %x\n",
1705 int2str[0].value, 20, 0, result, STATUS_INVALID_PARAMETER);
1707 result = pRtlIntegerToChar(int2str[0].value, int2str[0].base, 0, NULL);
1708 ok(result == STATUS_BUFFER_OVERFLOW,
1709 "(test c): RtlIntegerToChar(%u, %d, %d, NULL) has result %x, expected: %x\n",
1710 int2str[0].value, int2str[0].base, 0, result, STATUS_BUFFER_OVERFLOW);
1712 result = pRtlIntegerToChar(int2str[0].value, int2str[0].base, int2str[0].MaximumLength, NULL);
1713 ok(result == STATUS_ACCESS_VIOLATION,
1714 "(test d): RtlIntegerToChar(%u, %d, %d, NULL) has result %x, expected: %x\n",
1715 int2str[0].value, int2str[0].base, int2str[0].MaximumLength, result, STATUS_ACCESS_VIOLATION);
1718 static void test_RtlIsTextUnicode(void)
1720 char ascii[] = "A simple string";
1721 char false_positive[] = {0x41, 0x0a, 0x0d, 0x1d};
1722 WCHAR false_negative = 0x0d0a;
1723 WCHAR unicode[] = {'A',' ','U','n','i','c','o','d','e',' ','s','t','r','i','n','g',0};
1724 WCHAR unicode_no_controls[] = {'A','U','n','i','c','o','d','e','s','t','r','i','n','g',0};
1725 /* String with both byte-reversed and standard Unicode control characters. */
1726 WCHAR mixed_controls[] = {'\t',0x9000,0x0d00,'\n',0};
1727 WCHAR *be_unicode;
1728 WCHAR *be_unicode_no_controls;
1729 BOOLEAN res;
1730 int flags;
1731 int i;
1733 if (!pRtlIsTextUnicode)
1735 win_skip("RtlIsTextUnicode is not available\n");
1736 return;
1739 ok(!pRtlIsTextUnicode(ascii, sizeof(ascii), NULL), "ASCII text detected as Unicode\n");
1741 res = pRtlIsTextUnicode(unicode, sizeof(unicode), NULL);
1742 ok(res ||
1743 broken(res == FALSE), /* NT4 */
1744 "Text should be Unicode\n");
1746 ok(!pRtlIsTextUnicode(unicode, sizeof(unicode) - 1, NULL), "Text should be Unicode\n");
1748 flags = IS_TEXT_UNICODE_UNICODE_MASK;
1749 ok(pRtlIsTextUnicode(unicode, sizeof(unicode), &flags), "Text should not pass a Unicode\n");
1750 ok(flags == (IS_TEXT_UNICODE_STATISTICS | IS_TEXT_UNICODE_CONTROLS),
1751 "Expected flags 0x6, obtained %x\n", flags);
1753 flags = IS_TEXT_UNICODE_REVERSE_MASK;
1754 ok(!pRtlIsTextUnicode(unicode, sizeof(unicode), &flags), "Text should not pass reverse Unicode tests\n");
1755 ok(flags == 0, "Expected flags 0, obtained %x\n", flags);
1757 flags = IS_TEXT_UNICODE_ODD_LENGTH;
1758 ok(!pRtlIsTextUnicode(unicode, sizeof(unicode) - 1, &flags), "Odd length test should have passed\n");
1759 ok(flags == IS_TEXT_UNICODE_ODD_LENGTH, "Expected flags 0x200, obtained %x\n", flags);
1761 be_unicode = HeapAlloc(GetProcessHeap(), 0, sizeof(unicode) + sizeof(WCHAR));
1762 be_unicode[0] = 0xfffe;
1763 for (i = 0; i < ARRAY_SIZE(unicode); i++)
1765 be_unicode[i + 1] = (unicode[i] >> 8) | ((unicode[i] & 0xff) << 8);
1767 ok(!pRtlIsTextUnicode(be_unicode, sizeof(unicode) + 2, NULL), "Reverse endian should not be Unicode\n");
1768 ok(!pRtlIsTextUnicode(&be_unicode[1], sizeof(unicode), NULL), "Reverse endian should not be Unicode\n");
1770 flags = IS_TEXT_UNICODE_REVERSE_MASK;
1771 ok(!pRtlIsTextUnicode(&be_unicode[1], sizeof(unicode), &flags), "Reverse endian should be Unicode\n");
1772 todo_wine
1773 ok(flags == (IS_TEXT_UNICODE_REVERSE_ASCII16 | IS_TEXT_UNICODE_REVERSE_STATISTICS | IS_TEXT_UNICODE_REVERSE_CONTROLS),
1774 "Expected flags 0x70, obtained %x\n", flags);
1776 flags = IS_TEXT_UNICODE_REVERSE_MASK;
1777 ok(!pRtlIsTextUnicode(be_unicode, sizeof(unicode) + 2, &flags), "Reverse endian should be Unicode\n");
1778 ok(flags == (IS_TEXT_UNICODE_REVERSE_CONTROLS | IS_TEXT_UNICODE_REVERSE_SIGNATURE),
1779 "Expected flags 0xc0, obtained %x\n", flags);
1781 /* build byte reversed unicode string with no control chars */
1782 be_unicode_no_controls = HeapAlloc(GetProcessHeap(), 0, sizeof(unicode) + sizeof(WCHAR));
1783 ok(be_unicode_no_controls != NULL, "Expected HeapAlloc to succeed.\n");
1784 be_unicode_no_controls[0] = 0xfffe;
1785 for (i = 0; i < ARRAY_SIZE(unicode_no_controls); i++)
1786 be_unicode_no_controls[i + 1] = (unicode_no_controls[i] >> 8) | ((unicode_no_controls[i] & 0xff) << 8);
1789 /* The following tests verify that the tests for */
1790 /* IS_TEXT_UNICODE_CONTROLS and IS_TEXT_UNICODE_REVERSE_CONTROLS */
1791 /* are not mutually exclusive. Regardless of whether the strings */
1792 /* contain an indication of endianness, the tests are still */
1793 /* run if the flag is passed to (Rtl)IsTextUnicode. */
1795 /* Test IS_TEXT_UNICODE_CONTROLS flag */
1796 flags = IS_TEXT_UNICODE_CONTROLS;
1797 ok(!pRtlIsTextUnicode(unicode_no_controls, sizeof(unicode_no_controls), &flags), "Test should not pass on Unicode string lacking control characters.\n");
1798 ok(flags == 0, "Expected flags 0x0, obtained %x\n", flags);
1800 flags = IS_TEXT_UNICODE_CONTROLS;
1801 ok(!pRtlIsTextUnicode(be_unicode_no_controls, sizeof(unicode_no_controls), &flags), "Test should not pass on byte-reversed Unicode string lacking control characters.\n");
1802 ok(flags == 0, "Expected flags 0x0, obtained %x\n", flags);
1804 flags = IS_TEXT_UNICODE_CONTROLS;
1805 ok(pRtlIsTextUnicode(unicode, sizeof(unicode), &flags), "Test should pass on Unicode string lacking control characters.\n");
1806 ok(flags == IS_TEXT_UNICODE_CONTROLS, "Expected flags 0x04, obtained %x\n", flags);
1808 flags = IS_TEXT_UNICODE_CONTROLS;
1809 ok(!pRtlIsTextUnicode(be_unicode_no_controls, sizeof(unicode_no_controls) + 2, &flags),
1810 "Test should not pass with standard Unicode string.\n");
1811 ok(flags == 0, "Expected flags 0x0, obtained %x\n", flags);
1813 flags = IS_TEXT_UNICODE_CONTROLS;
1814 ok(pRtlIsTextUnicode(mixed_controls, sizeof(mixed_controls), &flags), "Test should pass on a string containing control characters.\n");
1815 ok(flags == IS_TEXT_UNICODE_CONTROLS, "Expected flags 0x04, obtained %x\n", flags);
1817 /* Test IS_TEXT_UNICODE_REVERSE_CONTROLS flag */
1818 flags = IS_TEXT_UNICODE_REVERSE_CONTROLS;
1819 ok(!pRtlIsTextUnicode(be_unicode_no_controls, sizeof(unicode_no_controls), &flags), "Test should not pass on Unicode string lacking control characters.\n");
1820 ok(flags == 0, "Expected flags 0x0, obtained %x\n", flags);
1822 flags = IS_TEXT_UNICODE_REVERSE_CONTROLS;
1823 ok(!pRtlIsTextUnicode(unicode_no_controls, sizeof(unicode_no_controls), &flags), "Test should not pass on Unicode string lacking control characters.\n");
1824 ok(flags == 0, "Expected flags 0x0, obtained %x\n", flags);
1826 flags = IS_TEXT_UNICODE_REVERSE_CONTROLS;
1827 ok(!pRtlIsTextUnicode(unicode, sizeof(unicode), &flags), "Test should not pass on Unicode string lacking control characters.\n");
1828 ok(flags == 0, "Expected flags 0x0, obtained %x\n", flags);
1830 flags = IS_TEXT_UNICODE_REVERSE_CONTROLS;
1831 ok(!pRtlIsTextUnicode(be_unicode, sizeof(unicode) + 2, &flags),
1832 "Test should pass with byte-reversed Unicode string containing control characters.\n");
1833 ok(flags == IS_TEXT_UNICODE_REVERSE_CONTROLS, "Expected flags 0x40, obtained %x\n", flags);
1835 flags = IS_TEXT_UNICODE_REVERSE_CONTROLS;
1836 ok(!pRtlIsTextUnicode(mixed_controls, sizeof(mixed_controls), &flags), "Test should pass on a string containing byte-reversed control characters.\n");
1837 ok(flags == IS_TEXT_UNICODE_REVERSE_CONTROLS, "Expected flags 0x40, obtained %x\n", flags);
1839 /* Test with flags for both byte-reverse and standard Unicode characters */
1840 flags = IS_TEXT_UNICODE_CONTROLS | IS_TEXT_UNICODE_REVERSE_CONTROLS;
1841 ok(!pRtlIsTextUnicode(mixed_controls, sizeof(mixed_controls), &flags), "Test should pass on string containing both byte-reversed and standard control characters.\n");
1842 ok(flags == (IS_TEXT_UNICODE_CONTROLS | IS_TEXT_UNICODE_REVERSE_CONTROLS), "Expected flags 0x44, obtained %x\n", flags);
1844 flags = IS_TEXT_UNICODE_STATISTICS;
1845 todo_wine ok(pRtlIsTextUnicode(false_positive, sizeof(false_positive), &flags), "Test should pass on false positive.\n");
1847 ok(!pRtlIsTextUnicode(&false_negative, sizeof(false_negative), NULL), "Test should fail on 0x0d0a (MALAYALAM LETTER UU).\n");
1849 HeapFree(GetProcessHeap(), 0, be_unicode);
1850 HeapFree(GetProcessHeap(), 0, be_unicode_no_controls);
1853 static void test_RtlCompareUnicodeString(void)
1855 WCHAR ch1, ch2;
1856 UNICODE_STRING str1, str2;
1858 str1.Buffer = &ch1;
1859 str1.Length = str1.MaximumLength = sizeof(WCHAR);
1860 str2.Buffer = &ch2;
1861 str2.Length = str2.MaximumLength = sizeof(WCHAR);
1862 for (ch1 = 0; ch1 < 512; ch1++)
1864 for (ch2 = 0; ch2 < 1024; ch2++)
1866 LONG res = pRtlCompareUnicodeString( &str1, &str2, FALSE );
1867 ok( res == (ch1 - ch2), "wrong result %d %04x %04x\n", res, ch1, ch2 );
1868 res = pRtlCompareUnicodeString( &str1, &str2, TRUE );
1869 ok( res == (pRtlUpcaseUnicodeChar(ch1) - pRtlUpcaseUnicodeChar(ch2)),
1870 "wrong result %d %04x %04x\n", res, ch1, ch2 );
1871 if (pRtlCompareUnicodeStrings)
1873 res = pRtlCompareUnicodeStrings( &ch1, 1, &ch2, 1, FALSE );
1874 ok( res == (ch1 - ch2), "wrong result %d %04x %04x\n", res, ch1, ch2 );
1875 res = pRtlCompareUnicodeStrings( &ch1, 1, &ch2, 1, TRUE );
1876 ok( res == (pRtlUpcaseUnicodeChar(ch1) - pRtlUpcaseUnicodeChar(ch2)),
1877 "wrong result %d %04x %04x\n", res, ch1, ch2 );
1883 static const WCHAR szGuid[] = { '{','0','1','0','2','0','3','0','4','-',
1884 '0','5','0','6','-' ,'0','7','0','8','-','0','9','0','A','-',
1885 '0','B','0','C','0','D','0','E','0','F','0','A','}','\0' };
1886 static const WCHAR szGuid2[] = { '{','0','1','0','2','0','3','0','4','-',
1887 '0','5','0','6','-' ,'0','7','0','8','-','0','9','0','A','-',
1888 '0','B','0','C','0','D','0','E','0','F','0','A',']','\0' };
1889 DEFINE_GUID(IID_Endianness, 0x01020304, 0x0506, 0x0708, 0x09, 0x0A, 0x0B,
1890 0x0C, 0x0D, 0x0E, 0x0F, 0x0A);
1892 static void test_RtlGUIDFromString(void)
1894 GUID guid;
1895 UNICODE_STRING str;
1896 NTSTATUS ret;
1898 if (!pRtlGUIDFromString)
1900 win_skip("RtlGUIDFromString is not available\n");
1901 return;
1904 str.Length = str.MaximumLength = sizeof(szGuid) - sizeof(WCHAR);
1905 str.Buffer = (LPWSTR)szGuid;
1907 ret = pRtlGUIDFromString(&str, &guid);
1908 ok(ret == 0, "expected ret=0, got 0x%0x\n", ret);
1909 ok(IsEqualGUID(&guid, &IID_Endianness), "Endianness broken\n");
1911 str.Length = str.MaximumLength = sizeof(szGuid2) - sizeof(WCHAR);
1912 str.Buffer = (LPWSTR)szGuid2;
1914 ret = pRtlGUIDFromString(&str, &guid);
1915 ok(ret, "expected ret!=0\n");
1918 static void test_RtlStringFromGUID(void)
1920 UNICODE_STRING str;
1921 NTSTATUS ret;
1923 if (!pRtlStringFromGUID)
1925 win_skip("RtlStringFromGUID is not available\n");
1926 return;
1929 str.Length = str.MaximumLength = 0;
1930 str.Buffer = NULL;
1932 ret = pRtlStringFromGUID(&IID_Endianness, &str);
1933 ok(ret == 0, "expected ret=0, got 0x%0x\n", ret);
1934 ok(str.Buffer && !lstrcmpiW(str.Buffer, szGuid), "Endianness broken\n");
1935 pRtlFreeUnicodeString(&str);
1938 struct hash_unicodestring_test {
1939 WCHAR str[50];
1940 BOOLEAN case_insensitive;
1941 ULONG hash;
1944 static const struct hash_unicodestring_test hash_test[] = {
1945 { {'T',0}, FALSE, 0x00000054 },
1946 { {'T','e','s','t',0}, FALSE, 0x766bb952 },
1947 { {'T','e','S','t',0}, FALSE, 0x764bb172 },
1948 { {'t','e','s','t',0}, FALSE, 0x4745d132 },
1949 { {'t','e','s','t',0}, TRUE, 0x6689c132 },
1950 { {'T','E','S','T',0}, TRUE, 0x6689c132 },
1951 { {'T','E','S','T',0}, FALSE, 0x6689c132 },
1952 { {'a','b','c','d','e','f',0}, FALSE, 0x971318c3 },
1953 { { 0 } }
1956 static void test_RtlHashUnicodeString(void)
1958 static const WCHAR strW[] = {'T','e','s','t',0,'1',0};
1959 const struct hash_unicodestring_test *ptr;
1960 UNICODE_STRING str;
1961 NTSTATUS status;
1962 ULONG hash;
1964 if (!pRtlHashUnicodeString)
1966 win_skip("RtlHashUnicodeString is not available\n");
1967 return;
1970 status = pRtlHashUnicodeString(NULL, FALSE, HASH_STRING_ALGORITHM_X65599, &hash);
1971 ok(status == STATUS_INVALID_PARAMETER, "got status 0x%08x\n", status);
1973 RtlInitUnicodeString(&str, strW);
1974 status = pRtlHashUnicodeString(&str, FALSE, HASH_STRING_ALGORITHM_X65599, NULL);
1975 ok(status == STATUS_INVALID_PARAMETER, "got status 0x%08x\n", status);
1977 status = pRtlHashUnicodeString(&str, FALSE, HASH_STRING_ALGORITHM_INVALID, &hash);
1978 ok(status == STATUS_INVALID_PARAMETER, "got status 0x%08x\n", status);
1980 /* embedded null */
1981 str.Buffer = (PWSTR)strW;
1982 str.Length = sizeof(strW) - sizeof(WCHAR);
1983 str.MaximumLength = sizeof(strW);
1984 status = pRtlHashUnicodeString(&str, FALSE, HASH_STRING_ALGORITHM_X65599, &hash);
1985 ok(status == STATUS_SUCCESS, "got status 0x%08x\n", status);
1986 ok(hash == 0x32803083, "got 0x%08x\n", hash);
1988 ptr = hash_test;
1989 while (*ptr->str)
1991 RtlInitUnicodeString(&str, ptr->str);
1992 hash = 0;
1993 status = pRtlHashUnicodeString(&str, ptr->case_insensitive, HASH_STRING_ALGORITHM_X65599, &hash);
1994 ok(status == STATUS_SUCCESS, "got status 0x%08x for %s\n", status, wine_dbgstr_w(ptr->str));
1995 ok(hash == ptr->hash, "got wrong hash 0x%08x, expected 0x%08x, for %s, mode %d\n", hash, ptr->hash,
1996 wine_dbgstr_w(ptr->str), ptr->case_insensitive);
1998 ptr++;
2002 struct unicode_to_utf8_test {
2003 WCHAR unicode[128];
2004 const char *expected;
2005 NTSTATUS status;
2008 static const struct unicode_to_utf8_test unicode_to_utf8[] = {
2009 { { 0 }, "", STATUS_SUCCESS },
2010 { { '-',0 }, "-", STATUS_SUCCESS },
2011 { { 'h','e','l','l','o',0 }, "hello", STATUS_SUCCESS },
2012 { { '-',0x7f,'-',0x80,'-',0xff,'-',0x100,'-',0 }, "-\x7F-\xC2\x80-\xC3\xBF-\xC4\x80-", STATUS_SUCCESS },
2013 { { '-',0x7ff,'-',0x800,'-',0 }, "-\xDF\xBF-\xE0\xA0\x80-", STATUS_SUCCESS },
2014 { { '-',0xd7ff,'-',0xe000,'-',0 }, "-\xED\x9F\xBF-\xEE\x80\x80-", STATUS_SUCCESS },
2015 /* 0x10000 */
2016 { { '-',0xffff,'-',0xd800,0xdc00,'-',0 }, "-\xEF\xBF\xBF-\xF0\x90\x80\x80-", STATUS_SUCCESS },
2017 /* 0x103ff */ /* 0x10400 */
2018 { { '-',0xd800,0xdfff,'-',0xd801,0xdc00,'-',0 }, "-\xF0\x90\x8F\xBF-\xF0\x90\x90\x80-", STATUS_SUCCESS },
2019 /* 0x10ffff */
2020 { { '-',0xdbff,0xdfff,'-',0 }, "-\xF4\x8F\xBF\xBF-", STATUS_SUCCESS },
2021 /* standalone lead surrogates become 0xFFFD */
2022 { { '-',0xd800,'-',0xdbff,'-',0 }, "-\xEF\xBF\xBD-\xEF\xBF\xBD-", STATUS_SOME_NOT_MAPPED },
2023 /* standalone trail surrogates become 0xFFFD */
2024 { { '-',0xdc00,'-',0xdfff,'-',0 }, "-\xEF\xBF\xBD-\xEF\xBF\xBD-", STATUS_SOME_NOT_MAPPED },
2025 /* reverse surrogate pair */
2026 { { '-',0xdfff,0xdbff,'-',0 }, "-\xEF\xBF\xBD\xEF\xBF\xBD-", STATUS_SOME_NOT_MAPPED },
2027 /* byte order marks */
2028 { { '-',0xfeff,'-',0xfffe,'-',0 }, "-\xEF\xBB\xBF-\xEF\xBF\xBE-", STATUS_SUCCESS },
2029 { { 0xfeff,'-',0 }, "\xEF\xBB\xBF-", STATUS_SUCCESS },
2030 { { 0xfffe,'-',0 }, "\xEF\xBF\xBE-", STATUS_SUCCESS },
2031 /* invalid code point */
2032 { { 0xffff,'-',0 }, "\xEF\xBF\xBF-", STATUS_SUCCESS },
2033 /* canonically equivalent representations -- no normalization should happen */
2034 { { '-',0x1e09,'-',0 }, "-\xE1\xB8\x89-", STATUS_SUCCESS },
2035 { { '-',0x0107,0x0327,'-',0 }, "-\xC4\x87\xCC\xA7-", STATUS_SUCCESS },
2036 { { '-',0x00e7,0x0301,'-',0 }, "-\xC3\xA7\xCC\x81-", STATUS_SUCCESS },
2037 { { '-',0x0063,0x0327,0x0301,'-',0 }, "-\x63\xCC\xA7\xCC\x81-", STATUS_SUCCESS },
2038 { { '-',0x0063,0x0301,0x0327,'-',0 }, "-\x63\xCC\x81\xCC\xA7-", STATUS_SUCCESS },
2041 static void utf8_expect_(const unsigned char *out_string, ULONG buflen, ULONG out_bytes,
2042 const WCHAR *in_string, ULONG in_bytes,
2043 NTSTATUS expect_status, int line)
2045 NTSTATUS status;
2046 ULONG bytes_out;
2047 char buffer[128];
2048 unsigned char *buf = (unsigned char *)buffer;
2049 unsigned int i;
2051 if (buflen == (ULONG)-1)
2052 buflen = sizeof(buffer);
2053 bytes_out = 0x55555555;
2054 memset(buffer, 0x55, sizeof(buffer));
2055 status = pRtlUnicodeToUTF8N(
2056 out_string ? buffer : NULL, buflen, &bytes_out,
2057 in_string, in_bytes);
2058 ok_(__FILE__, line)(status == expect_status, "status = 0x%x\n", status);
2059 ok_(__FILE__, line)(bytes_out == out_bytes, "bytes_out = %u\n", bytes_out);
2060 if (out_string)
2062 for (i = 0; i < bytes_out; i++)
2063 ok_(__FILE__, line)(buf[i] == out_string[i],
2064 "buffer[%d] = 0x%x, expected 0x%x\n",
2065 i, buf[i], out_string[i]);
2066 for (; i < sizeof(buffer); i++)
2067 ok_(__FILE__, line)(buf[i] == 0x55,
2068 "buffer[%d] = 0x%x, expected 0x55\n",
2069 i, buf[i]);
2072 #define utf8_expect(out_string, buflen, out_bytes, in_string, in_bytes, expect_status) \
2073 utf8_expect_(out_string, buflen, out_bytes, in_string, in_bytes, expect_status, __LINE__)
2075 static void test_RtlUnicodeToUTF8N(void)
2077 NTSTATUS status;
2078 ULONG bytes_out;
2079 ULONG bytes_out_array[2];
2080 void * const invalid_pointer = (void *)0x8;
2081 char buffer[128];
2082 const WCHAR empty_string[] = { 0 };
2083 const WCHAR test_string[] = { 'A',0,'a','b','c','d','e','f','g',0 };
2084 const WCHAR special_string[] = { 'X',0x80,0xd800,0 };
2085 const unsigned char special_expected[] = { 'X',0xc2,0x80,0xef,0xbf,0xbd,0 };
2086 unsigned int input_len;
2087 const unsigned int test_count = ARRAY_SIZE(unicode_to_utf8);
2088 unsigned int i;
2090 if (!pRtlUnicodeToUTF8N)
2092 skip("RtlUnicodeToUTF8N unavailable\n");
2093 return;
2096 /* show that bytes_out is really ULONG */
2097 memset(bytes_out_array, 0x55, sizeof(bytes_out_array));
2098 status = pRtlUnicodeToUTF8N(NULL, 0, bytes_out_array, empty_string, 0);
2099 ok(status == STATUS_SUCCESS, "status = 0x%x\n", status);
2100 ok(bytes_out_array[0] == 0x00000000, "Got 0x%x\n", bytes_out_array[0]);
2101 ok(bytes_out_array[1] == 0x55555555, "Got 0x%x\n", bytes_out_array[1]);
2103 /* parameter checks */
2104 status = pRtlUnicodeToUTF8N(NULL, 0, NULL, NULL, 0);
2105 ok(status == STATUS_INVALID_PARAMETER_4, "status = 0x%x\n", status);
2107 status = pRtlUnicodeToUTF8N(NULL, 0, NULL, empty_string, 0);
2108 ok(status == STATUS_INVALID_PARAMETER, "status = 0x%x\n", status);
2110 bytes_out = 0x55555555;
2111 status = pRtlUnicodeToUTF8N(NULL, 0, &bytes_out, NULL, 0);
2112 ok(status == STATUS_INVALID_PARAMETER_4, "status = 0x%x\n", status);
2113 ok(bytes_out == 0x55555555, "bytes_out = 0x%x\n", bytes_out);
2115 bytes_out = 0x55555555;
2116 status = pRtlUnicodeToUTF8N(NULL, 0, &bytes_out, invalid_pointer, 0);
2117 ok(status == STATUS_SUCCESS, "status = 0x%x\n", status);
2118 ok(bytes_out == 0, "bytes_out = 0x%x\n", bytes_out);
2120 bytes_out = 0x55555555;
2121 status = pRtlUnicodeToUTF8N(NULL, 0, &bytes_out, empty_string, 0);
2122 ok(status == STATUS_SUCCESS, "status = 0x%x\n", status);
2123 ok(bytes_out == 0, "bytes_out = 0x%x\n", bytes_out);
2125 bytes_out = 0x55555555;
2126 status = pRtlUnicodeToUTF8N(NULL, 0, &bytes_out, test_string, 0);
2127 ok(status == STATUS_SUCCESS, "status = 0x%x\n", status);
2128 ok(bytes_out == 0, "bytes_out = 0x%x\n", bytes_out);
2130 bytes_out = 0x55555555;
2131 status = pRtlUnicodeToUTF8N(NULL, 0, &bytes_out, empty_string, 1);
2132 ok(status == STATUS_SUCCESS, "status = 0x%x\n", status);
2133 ok(bytes_out == 0, "bytes_out = 0x%x\n", bytes_out);
2135 bytes_out = 0x55555555;
2136 status = pRtlUnicodeToUTF8N(invalid_pointer, 0, &bytes_out, empty_string, 1);
2137 ok(status == STATUS_INVALID_PARAMETER_5, "status = 0x%x\n", status);
2138 ok(bytes_out == 0x55555555, "bytes_out = 0x%x\n", bytes_out);
2140 bytes_out = 0x55555555;
2141 status = pRtlUnicodeToUTF8N(invalid_pointer, 8, &bytes_out, empty_string, 1);
2142 ok(status == STATUS_INVALID_PARAMETER_5, "status = 0x%x\n", status);
2143 ok(bytes_out == 0x55555555, "bytes_out = 0x%x\n", bytes_out);
2145 /* length output with special chars */
2146 #define length_expect(in_chars, out_bytes, expect_status) \
2147 utf8_expect_(NULL, 0, out_bytes, \
2148 special_string, in_chars * sizeof(WCHAR), \
2149 expect_status, __LINE__)
2151 length_expect(0, 0, STATUS_SUCCESS);
2152 length_expect(1, 1, STATUS_SUCCESS);
2153 length_expect(2, 3, STATUS_SUCCESS);
2154 length_expect(3, 6, STATUS_SOME_NOT_MAPPED);
2155 length_expect(4, 7, STATUS_SOME_NOT_MAPPED);
2156 #undef length_expect
2158 /* output truncation */
2159 #define truncate_expect(buflen, out_bytes, expect_status) \
2160 utf8_expect_(special_expected, buflen, out_bytes, \
2161 special_string, sizeof(special_string), \
2162 expect_status, __LINE__)
2164 truncate_expect(0, 0, STATUS_BUFFER_TOO_SMALL);
2165 truncate_expect(1, 1, STATUS_BUFFER_TOO_SMALL);
2166 truncate_expect(2, 1, STATUS_BUFFER_TOO_SMALL);
2167 truncate_expect(3, 3, STATUS_BUFFER_TOO_SMALL);
2168 truncate_expect(4, 3, STATUS_BUFFER_TOO_SMALL);
2169 truncate_expect(5, 3, STATUS_BUFFER_TOO_SMALL);
2170 truncate_expect(6, 6, STATUS_BUFFER_TOO_SMALL);
2171 truncate_expect(7, 7, STATUS_SOME_NOT_MAPPED);
2172 #undef truncate_expect
2174 /* conversion behavior with varying input length */
2175 for (input_len = 0; input_len <= sizeof(test_string); input_len++) {
2176 /* no output buffer, just length */
2177 utf8_expect(NULL, 0, input_len / sizeof(WCHAR),
2178 test_string, input_len, STATUS_SUCCESS);
2180 /* write output */
2181 bytes_out = 0x55555555;
2182 memset(buffer, 0x55, sizeof(buffer));
2183 status = pRtlUnicodeToUTF8N(
2184 buffer, sizeof(buffer), &bytes_out,
2185 test_string, input_len);
2186 if (input_len % sizeof(WCHAR) == 0) {
2187 ok(status == STATUS_SUCCESS,
2188 "(len %u): status = 0x%x\n", input_len, status);
2189 ok(bytes_out == input_len / sizeof(WCHAR),
2190 "(len %u): bytes_out = 0x%x\n", input_len, bytes_out);
2191 for (i = 0; i < bytes_out; i++) {
2192 ok(buffer[i] == test_string[i],
2193 "(len %u): buffer[%d] = 0x%x, expected 0x%x\n",
2194 input_len, i, buffer[i], test_string[i]);
2196 for (; i < sizeof(buffer); i++) {
2197 ok(buffer[i] == 0x55,
2198 "(len %u): buffer[%d] = 0x%x\n", input_len, i, buffer[i]);
2200 } else {
2201 ok(status == STATUS_INVALID_PARAMETER_5,
2202 "(len %u): status = 0x%x\n", input_len, status);
2203 ok(bytes_out == 0x55555555,
2204 "(len %u): bytes_out = 0x%x\n", input_len, bytes_out);
2205 for (i = 0; i < sizeof(buffer); i++) {
2206 ok(buffer[i] == 0x55,
2207 "(len %u): buffer[%d] = 0x%x\n", input_len, i, buffer[i]);
2212 /* test cases for special characters */
2213 for (i = 0; i < test_count; i++) {
2214 bytes_out = 0x55555555;
2215 memset(buffer, 0x55, sizeof(buffer));
2216 status = pRtlUnicodeToUTF8N(
2217 buffer, sizeof(buffer), &bytes_out,
2218 unicode_to_utf8[i].unicode, lstrlenW(unicode_to_utf8[i].unicode) * sizeof(WCHAR));
2219 ok(status == unicode_to_utf8[i].status,
2220 "(test %d): status is 0x%x, expected 0x%x\n",
2221 i, status, unicode_to_utf8[i].status);
2222 ok(bytes_out == strlen(unicode_to_utf8[i].expected),
2223 "(test %d): bytes_out is %u, expected %u\n",
2224 i, bytes_out, lstrlenA(unicode_to_utf8[i].expected));
2225 ok(!memcmp(buffer, unicode_to_utf8[i].expected, bytes_out),
2226 "(test %d): got \"%.*s\", expected \"%s\"\n",
2227 i, bytes_out, buffer, unicode_to_utf8[i].expected);
2228 ok(buffer[bytes_out] == 0x55,
2229 "(test %d): behind string: 0x%x\n", i, buffer[bytes_out]);
2231 /* same test but include the null terminator */
2232 bytes_out = 0x55555555;
2233 memset(buffer, 0x55, sizeof(buffer));
2234 status = pRtlUnicodeToUTF8N(
2235 buffer, sizeof(buffer), &bytes_out,
2236 unicode_to_utf8[i].unicode, (lstrlenW(unicode_to_utf8[i].unicode) + 1) * sizeof(WCHAR));
2237 ok(status == unicode_to_utf8[i].status,
2238 "(test %d): status is 0x%x, expected 0x%x\n",
2239 i, status, unicode_to_utf8[i].status);
2240 ok(bytes_out == strlen(unicode_to_utf8[i].expected) + 1,
2241 "(test %d): bytes_out is %u, expected %u\n",
2242 i, bytes_out, lstrlenA(unicode_to_utf8[i].expected) + 1);
2243 ok(!memcmp(buffer, unicode_to_utf8[i].expected, bytes_out),
2244 "(test %d): got \"%.*s\", expected \"%s\"\n",
2245 i, bytes_out, buffer, unicode_to_utf8[i].expected);
2246 ok(buffer[bytes_out] == 0x55,
2247 "(test %d): behind string: 0x%x\n", i, buffer[bytes_out]);
2251 struct utf8_to_unicode_test {
2252 const char *utf8;
2253 WCHAR expected[128];
2254 NTSTATUS status;
2257 static const struct utf8_to_unicode_test utf8_to_unicode[] = {
2258 { "", { 0 }, STATUS_SUCCESS },
2259 { "-", { '-',0 }, STATUS_SUCCESS },
2260 { "hello", { 'h','e','l','l','o',0 }, STATUS_SUCCESS },
2261 /* first and last of each range */
2262 { "-\x7F-\xC2\x80-\xC3\xBF-\xC4\x80-", { '-',0x7f,'-',0x80,'-',0xff,'-',0x100,'-',0 }, STATUS_SUCCESS },
2263 { "-\xDF\xBF-\xE0\xA0\x80-", { '-',0x7ff,'-',0x800,'-',0 }, STATUS_SUCCESS },
2264 { "-\xED\x9F\xBF-\xEE\x80\x80-", { '-',0xd7ff,'-',0xe000,'-',0 }, STATUS_SUCCESS },
2265 /* 0x10000 */
2266 { "-\xEF\xBF\xBF-\xF0\x90\x80\x80-", { '-',0xffff,'-',0xd800,0xdc00,'-',0 }, STATUS_SUCCESS },
2267 /* 0x103ff */ /* 0x10400 */
2268 { "-\xF0\x90\x8F\xBF-\xF0\x90\x90\x80-", { '-',0xd800,0xdfff,'-',0xd801,0xdc00,'-',0 }, STATUS_SUCCESS },
2269 /* 0x10ffff */
2270 { "-\xF4\x8F\xBF\xBF-", { '-',0xdbff,0xdfff,'-',0 }, STATUS_SUCCESS },
2271 /* standalone surrogate code points */
2272 /* 0xd800 */ /* 0xdbff */
2273 { "-\xED\xA0\x80-\xED\xAF\xBF-", { '-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2274 /* 0xdc00 */ /* 0xdfff */
2275 { "-\xED\xB0\x80-\xED\xBF\xBF-", { '-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2276 /* UTF-8 encoded surrogate pair */
2277 /* 0xdbff *//* 0xdfff */
2278 { "-\xED\xAF\xBF\xED\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2279 /* reverse surrogate pair */
2280 /* 0xdfff *//* 0xdbff */
2281 { "-\xED\xBF\xBF\xED\xAF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2282 /* code points outside the UTF-16 range */
2283 /* 0x110000 */
2284 { "-\xF4\x90\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2285 /* 0x1fffff */
2286 { "-\xF7\xBF\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2287 /* 0x200000 */
2288 { "-\xFA\x80\x80\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2289 /* 0x3ffffff */
2290 { "-\xFB\xBF\xBF\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2291 /* 0x4000000 */
2292 { "-\xFC\x84\x80\x80\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2293 /* 0x7fffffff */
2294 { "-\xFD\xBF\xBF\xBF\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2295 /* overlong encodings of each length for -, NUL, and the highest possible value */
2296 { "-\xC0\xAD-\xC0\x80-\xC1\xBF-", { '-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2297 { "-\xE0\x80\xAD-\xE0\x80\x80-\xE0\x9F\xBF-", { '-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2298 { "-\xF0\x80\x80\xAD-", { '-',0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2299 { "-\xF0\x80\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2300 { "-\xF0\x8F\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2301 { "-\xF8\x80\x80\x80\xAD-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2302 { "-\xF8\x80\x80\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2303 { "-\xF8\x87\xBF\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2304 { "-\xFC\x80\x80\x80\x80\xAD-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2305 { "-\xFC\x80\x80\x80\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2306 { "-\xFC\x83\xBF\xBF\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2307 /* invalid bytes */
2308 { "\xFE", { 0xfffd,0 }, STATUS_SOME_NOT_MAPPED },
2309 { "\xFF", { 0xfffd,0 }, STATUS_SOME_NOT_MAPPED },
2310 { "\xFE\xBF\xBF\xBF\xBF\xBF\xBF\xBF\xBF", { 0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED },
2311 { "\xFF\xBF\xBF\xBF\xBF\xBF\xBF\xBF\xBF", { 0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED },
2312 { "\xFF\x80\x80\x80\x80\x80\x80\x80\x80", { 0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED },
2313 { "\xFF\x40\x80\x80\x80\x80\x80\x80\x80", { 0xfffd,0x40,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED },
2314 /* lone continuation bytes */
2315 { "\x80", { 0xfffd,0 }, STATUS_SOME_NOT_MAPPED },
2316 { "\x80\x80", { 0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED },
2317 { "\xBF", { 0xfffd,0 }, STATUS_SOME_NOT_MAPPED },
2318 { "\xBF\xBF", { 0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED },
2319 /* incomplete sequences */
2320 { "\xC2-", { 0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2321 { "\xE0\xA0-", { 0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2322 { "\xF0\x90\x80-", { 0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2323 { "\xF4\x8F\xBF-", { 0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2324 { "\xFA\x80\x80\x80-", { 0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2325 { "\xFC\x84\x80\x80\x80-", { 0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2326 /* multibyte sequence followed by lone continuation byte */
2327 { "\xE0\xA0\x80\x80-", { 0x800,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED },
2328 /* byte order marks */
2329 { "-\xEF\xBB\xBF-\xEF\xBF\xBE-", { '-',0xfeff,'-',0xfffe,'-',0 }, STATUS_SUCCESS },
2330 { "\xEF\xBB\xBF-", { 0xfeff,'-',0 }, STATUS_SUCCESS },
2331 { "\xEF\xBF\xBE-", { 0xfffe,'-',0 }, STATUS_SUCCESS },
2332 /* invalid code point */
2333 /* 0xffff */
2334 { "\xEF\xBF\xBF-", { 0xffff,'-',0 }, STATUS_SUCCESS },
2335 /* canonically equivalent representations -- no normalization should happen */
2336 { "-\xE1\xB8\x89-", { '-',0x1e09,'-',0 }, STATUS_SUCCESS },
2337 { "-\xC4\x87\xCC\xA7-", { '-',0x0107,0x0327,'-',0 }, STATUS_SUCCESS },
2338 { "-\xC3\xA7\xCC\x81-", { '-',0x00e7,0x0301,'-',0 }, STATUS_SUCCESS },
2339 { "-\x63\xCC\xA7\xCC\x81-", { '-',0x0063,0x0327,0x0301,'-',0 }, STATUS_SUCCESS },
2340 { "-\x63\xCC\x81\xCC\xA7-", { '-',0x0063,0x0301,0x0327,'-',0 }, STATUS_SUCCESS },
2343 static void unicode_expect_(const WCHAR *out_string, ULONG buflen, ULONG out_chars,
2344 const char *in_string, ULONG in_chars,
2345 NTSTATUS expect_status, int line)
2347 NTSTATUS status;
2348 ULONG bytes_out;
2349 WCHAR buffer[128];
2350 unsigned int i;
2352 if (buflen == (ULONG)-1)
2353 buflen = sizeof(buffer);
2354 bytes_out = 0x55555555;
2355 memset(buffer, 0x55, sizeof(buffer));
2356 status = pRtlUTF8ToUnicodeN(
2357 out_string ? buffer : NULL, buflen, &bytes_out,
2358 in_string, in_chars);
2359 ok_(__FILE__, line)(status == expect_status, "status = 0x%x\n", status);
2360 ok_(__FILE__, line)(bytes_out == out_chars * sizeof(WCHAR),
2361 "bytes_out = %u, expected %u\n", bytes_out, out_chars * (ULONG)sizeof(WCHAR));
2362 if (out_string)
2364 for (i = 0; i < bytes_out / sizeof(WCHAR); i++)
2365 ok_(__FILE__, line)(buffer[i] == out_string[i],
2366 "buffer[%d] = 0x%x, expected 0x%x\n",
2367 i, buffer[i], out_string[i]);
2368 for (; i < ARRAY_SIZE(buffer); i++)
2369 ok_(__FILE__, line)(buffer[i] == 0x5555,
2370 "buffer[%d] = 0x%x, expected 0x5555\n",
2371 i, buffer[i]);
2374 #define unicode_expect(out_string, buflen, out_chars, in_string, in_chars, expect_status) \
2375 unicode_expect_(out_string, buflen, out_chars, in_string, in_chars, expect_status, __LINE__)
2377 static void test_RtlUTF8ToUnicodeN(void)
2379 NTSTATUS status;
2380 ULONG bytes_out;
2381 ULONG bytes_out_array[2];
2382 void * const invalid_pointer = (void *)0x8;
2383 WCHAR buffer[128];
2384 const char empty_string[] = "";
2385 const char test_string[] = "A\0abcdefg";
2386 const WCHAR test_stringW[] = {'A',0,'a','b','c','d','e','f','g',0 };
2387 const char special_string[] = { 'X',0xc2,0x80,0xF0,0x90,0x80,0x80,0 };
2388 const WCHAR special_expected[] = { 'X',0x80,0xd800,0xdc00,0 };
2389 unsigned int input_len;
2390 const unsigned int test_count = ARRAY_SIZE(utf8_to_unicode);
2391 unsigned int i;
2393 if (!pRtlUTF8ToUnicodeN)
2395 skip("RtlUTF8ToUnicodeN unavailable\n");
2396 return;
2399 /* show that bytes_out is really ULONG */
2400 memset(bytes_out_array, 0x55, sizeof(bytes_out_array));
2401 status = pRtlUTF8ToUnicodeN(NULL, 0, bytes_out_array, empty_string, 0);
2402 ok(status == STATUS_SUCCESS, "status = 0x%x\n", status);
2403 ok(bytes_out_array[0] == 0x00000000, "Got 0x%x\n", bytes_out_array[0]);
2404 ok(bytes_out_array[1] == 0x55555555, "Got 0x%x\n", bytes_out_array[1]);
2406 /* parameter checks */
2407 status = pRtlUTF8ToUnicodeN(NULL, 0, NULL, NULL, 0);
2408 ok(status == STATUS_INVALID_PARAMETER_4, "status = 0x%x\n", status);
2410 status = pRtlUTF8ToUnicodeN(NULL, 0, NULL, empty_string, 0);
2411 ok(status == STATUS_INVALID_PARAMETER, "status = 0x%x\n", status);
2413 bytes_out = 0x55555555;
2414 status = pRtlUTF8ToUnicodeN(NULL, 0, &bytes_out, NULL, 0);
2415 ok(status == STATUS_INVALID_PARAMETER_4, "status = 0x%x\n", status);
2416 ok(bytes_out == 0x55555555, "bytes_out = 0x%x\n", bytes_out);
2418 bytes_out = 0x55555555;
2419 status = pRtlUTF8ToUnicodeN(NULL, 0, &bytes_out, invalid_pointer, 0);
2420 ok(status == STATUS_SUCCESS, "status = 0x%x\n", status);
2421 ok(bytes_out == 0, "bytes_out = 0x%x\n", bytes_out);
2423 bytes_out = 0x55555555;
2424 status = pRtlUTF8ToUnicodeN(NULL, 0, &bytes_out, empty_string, 0);
2425 ok(status == STATUS_SUCCESS, "status = 0x%x\n", status);
2426 ok(bytes_out == 0, "bytes_out = 0x%x\n", bytes_out);
2428 bytes_out = 0x55555555;
2429 status = pRtlUTF8ToUnicodeN(NULL, 0, &bytes_out, test_string, 0);
2430 ok(status == STATUS_SUCCESS, "status = 0x%x\n", status);
2431 ok(bytes_out == 0, "bytes_out = 0x%x\n", bytes_out);
2433 bytes_out = 0x55555555;
2434 status = pRtlUTF8ToUnicodeN(NULL, 0, &bytes_out, empty_string, 1);
2435 ok(status == STATUS_SUCCESS, "status = 0x%x\n", status);
2436 ok(bytes_out == sizeof(WCHAR), "bytes_out = 0x%x\n", bytes_out);
2438 /* length output with special chars */
2439 #define length_expect(in_chars, out_chars, expect_status) \
2440 unicode_expect_(NULL, 0, out_chars, special_string, in_chars, \
2441 expect_status, __LINE__)
2443 length_expect(0, 0, STATUS_SUCCESS);
2444 length_expect(1, 1, STATUS_SUCCESS);
2445 length_expect(2, 2, STATUS_SOME_NOT_MAPPED);
2446 length_expect(3, 2, STATUS_SUCCESS);
2447 length_expect(4, 3, STATUS_SOME_NOT_MAPPED);
2448 length_expect(5, 3, STATUS_SOME_NOT_MAPPED);
2449 length_expect(6, 3, STATUS_SOME_NOT_MAPPED);
2450 length_expect(7, 4, STATUS_SUCCESS);
2451 length_expect(8, 5, STATUS_SUCCESS);
2452 #undef length_expect
2454 /* output truncation */
2455 #define truncate_expect(buflen, out_chars, expect_status) \
2456 unicode_expect_(special_expected, buflen, out_chars, \
2457 special_string, sizeof(special_string), \
2458 expect_status, __LINE__)
2460 truncate_expect( 0, 0, STATUS_BUFFER_TOO_SMALL);
2461 truncate_expect( 1, 0, STATUS_BUFFER_TOO_SMALL);
2462 truncate_expect( 2, 1, STATUS_BUFFER_TOO_SMALL);
2463 truncate_expect( 3, 1, STATUS_BUFFER_TOO_SMALL);
2464 truncate_expect( 4, 2, STATUS_BUFFER_TOO_SMALL);
2465 truncate_expect( 5, 2, STATUS_BUFFER_TOO_SMALL);
2466 truncate_expect( 6, 3, STATUS_BUFFER_TOO_SMALL);
2467 truncate_expect( 7, 3, STATUS_BUFFER_TOO_SMALL);
2468 truncate_expect( 8, 4, STATUS_BUFFER_TOO_SMALL);
2469 truncate_expect( 9, 4, STATUS_BUFFER_TOO_SMALL);
2470 truncate_expect(10, 5, STATUS_SUCCESS);
2471 #undef truncate_expect
2473 /* conversion behavior with varying input length */
2474 for (input_len = 0; input_len <= sizeof(test_string); input_len++) {
2475 /* no output buffer, just length */
2476 unicode_expect(NULL, 0, input_len,
2477 test_string, input_len, STATUS_SUCCESS);
2479 /* write output */
2480 unicode_expect(test_stringW, -1, input_len,
2481 test_string, input_len, STATUS_SUCCESS);
2484 /* test cases for special characters */
2485 for (i = 0; i < test_count; i++) {
2486 bytes_out = 0x55555555;
2487 memset(buffer, 0x55, sizeof(buffer));
2488 status = pRtlUTF8ToUnicodeN(
2489 buffer, sizeof(buffer), &bytes_out,
2490 utf8_to_unicode[i].utf8, strlen(utf8_to_unicode[i].utf8));
2491 ok(status == utf8_to_unicode[i].status,
2492 "(test %d): status is 0x%x, expected 0x%x\n",
2493 i, status, utf8_to_unicode[i].status);
2494 ok(bytes_out == lstrlenW(utf8_to_unicode[i].expected) * sizeof(WCHAR),
2495 "(test %d): bytes_out is %u, expected %u\n",
2496 i, bytes_out, lstrlenW(utf8_to_unicode[i].expected) * (ULONG)sizeof(WCHAR));
2497 ok(!memcmp(buffer, utf8_to_unicode[i].expected, bytes_out),
2498 "(test %d): got %s, expected %s\n",
2499 i, wine_dbgstr_wn(buffer, bytes_out / sizeof(WCHAR)), wine_dbgstr_w(utf8_to_unicode[i].expected));
2500 ok(buffer[bytes_out] == 0x5555,
2501 "(test %d): behind string: 0x%x\n", i, buffer[bytes_out]);
2503 /* same test but include the null terminator */
2504 bytes_out = 0x55555555;
2505 memset(buffer, 0x55, sizeof(buffer));
2506 status = pRtlUTF8ToUnicodeN(
2507 buffer, sizeof(buffer), &bytes_out,
2508 utf8_to_unicode[i].utf8, strlen(utf8_to_unicode[i].utf8) + 1);
2509 ok(status == utf8_to_unicode[i].status,
2510 "(test %d): status is 0x%x, expected 0x%x\n",
2511 i, status, utf8_to_unicode[i].status);
2512 ok(bytes_out == (lstrlenW(utf8_to_unicode[i].expected) + 1) * sizeof(WCHAR),
2513 "(test %d): bytes_out is %u, expected %u\n",
2514 i, bytes_out, (lstrlenW(utf8_to_unicode[i].expected) + 1) * (ULONG)sizeof(WCHAR));
2515 ok(!memcmp(buffer, utf8_to_unicode[i].expected, bytes_out),
2516 "(test %d): got %s, expected %s\n",
2517 i, wine_dbgstr_wn(buffer, bytes_out / sizeof(WCHAR)), wine_dbgstr_w(utf8_to_unicode[i].expected));
2518 ok(buffer[bytes_out] == 0x5555,
2519 "(test %d): behind string: 0x%x\n", i, buffer[bytes_out]);
2523 START_TEST(rtlstr)
2525 InitFunctionPtrs();
2526 if (pRtlInitAnsiString) {
2527 test_RtlInitString();
2528 test_RtlInitUnicodeString();
2529 test_RtlCopyString();
2530 test_RtlUnicodeStringToInteger();
2531 test_RtlCharToInteger();
2532 test_RtlIntegerToUnicodeString();
2533 test_RtlIntegerToChar();
2534 test_RtlUpperChar();
2535 test_RtlUpperString();
2536 test_RtlUnicodeStringToAnsiString();
2537 test_RtlAppendAsciizToString();
2538 test_RtlAppendStringToString();
2539 test_RtlAppendUnicodeToString();
2540 test_RtlAppendUnicodeStringToString();
2543 test_RtlInitUnicodeStringEx();
2544 test_RtlDuplicateUnicodeString();
2545 test_RtlFindCharInUnicodeString();
2546 test_RtlGUIDFromString();
2547 test_RtlStringFromGUID();
2548 test_RtlIsTextUnicode();
2549 test_RtlCompareUnicodeString();
2550 if(0)
2552 test_RtlUpcaseUnicodeChar();
2553 test_RtlUpcaseUnicodeString();
2554 test_RtlDowncaseUnicodeString();
2556 test_RtlHashUnicodeString();
2557 test_RtlUnicodeToUTF8N();
2558 test_RtlUTF8ToUnicodeN();