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
21 * We use function pointers here as there is no import library for NTDLL on
29 #include "ntdll_test.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 VOID (WINAPI
*pRtlCopyString
)(STRING
*, const STRING
*);
45 static BOOLEAN (WINAPI
*pRtlCreateUnicodeString
)(PUNICODE_STRING
, LPCWSTR
);
46 static BOOLEAN (WINAPI
*pRtlCreateUnicodeStringFromAsciiz
)(PUNICODE_STRING
, LPCSTR
);
47 static NTSTATUS (WINAPI
*pRtlDowncaseUnicodeString
)(UNICODE_STRING
*, const UNICODE_STRING
*, BOOLEAN
);
48 static NTSTATUS (WINAPI
*pRtlDuplicateUnicodeString
)(int, UNICODE_STRING
*, UNICODE_STRING
*);
49 static BOOLEAN (WINAPI
*pRtlEqualUnicodeString
)(const UNICODE_STRING
*, const UNICODE_STRING
*, BOOLEAN
);
50 static NTSTATUS (WINAPI
*pRtlFindCharInUnicodeString
)(int, const UNICODE_STRING
*, const UNICODE_STRING
*, USHORT
*);
51 static VOID (WINAPI
*pRtlFreeAnsiString
)(PSTRING
);
52 static VOID (WINAPI
*pRtlFreeUnicodeString
)(PUNICODE_STRING
);
53 static VOID (WINAPI
*pRtlInitAnsiString
)(PSTRING
, LPCSTR
);
54 static VOID (WINAPI
*pRtlInitString
)(PSTRING
, LPCSTR
);
55 static VOID (WINAPI
*pRtlInitUnicodeString
)(PUNICODE_STRING
, LPCWSTR
);
56 static NTSTATUS (WINAPI
*pRtlInitUnicodeStringEx
)(PUNICODE_STRING
, LPCWSTR
);
57 static NTSTATUS (WINAPI
*pRtlIntegerToChar
)(ULONG
, ULONG
, ULONG
, PCHAR
);
58 static NTSTATUS (WINAPI
*pRtlIntegerToUnicodeString
)(ULONG
, ULONG
, UNICODE_STRING
*);
59 static NTSTATUS (WINAPI
*pRtlMultiAppendUnicodeStringBuffer
)(UNICODE_STRING
*, LONG
, UNICODE_STRING
*);
60 static NTSTATUS (WINAPI
*pRtlUnicodeStringToAnsiString
)(STRING
*, const UNICODE_STRING
*, BOOLEAN
);
61 static NTSTATUS (WINAPI
*pRtlUnicodeStringToInteger
)(const UNICODE_STRING
*, int, int *);
62 static WCHAR (WINAPI
*pRtlUpcaseUnicodeChar
)(WCHAR
);
63 static NTSTATUS (WINAPI
*pRtlUpcaseUnicodeString
)(UNICODE_STRING
*, const UNICODE_STRING
*, BOOLEAN
);
64 static CHAR (WINAPI
*pRtlUpperChar
)(CHAR
);
65 static NTSTATUS (WINAPI
*pRtlUpperString
)(STRING
*, const STRING
*);
66 static NTSTATUS (WINAPI
*pRtlValidateUnicodeString
)(LONG
, UNICODE_STRING
*);
67 static NTSTATUS (WINAPI
*pRtlGUIDFromString
)(const UNICODE_STRING
*,GUID
*);
68 static NTSTATUS (WINAPI
*pRtlStringFromGUID
)(const GUID
*, UNICODE_STRING
*);
69 static BOOLEAN (WINAPI
*pRtlIsTextUnicode
)(LPVOID
, INT
, INT
*);
70 static NTSTATUS (WINAPI
*pRtlHashUnicodeString
)(PCUNICODE_STRING
,BOOLEAN
,ULONG
,ULONG
*);
71 static NTSTATUS (WINAPI
*pRtlUnicodeToUTF8N
)(CHAR
*, ULONG
, ULONG
*, const WCHAR
*, ULONG
);
72 static NTSTATUS (WINAPI
*pRtlUTF8ToUnicodeN
)(WCHAR
*, ULONG
, ULONG
*, const CHAR
*, ULONG
);
74 /*static VOID (WINAPI *pRtlFreeOemString)(PSTRING);*/
75 /*static VOID (WINAPI *pRtlCopyUnicodeString)(UNICODE_STRING *, const UNICODE_STRING *);*/
76 /*static VOID (WINAPI *pRtlEraseUnicodeString)(UNICODE_STRING *);*/
77 /*static LONG (WINAPI *pRtlCompareString)(const STRING *,const STRING *,BOOLEAN);*/
78 /*static LONG (WINAPI *pRtlCompareUnicodeString)(const UNICODE_STRING *,const UNICODE_STRING *,BOOLEAN);*/
79 /*static BOOLEAN (WINAPI *pRtlEqualString)(const STRING *,const STRING *,BOOLEAN);*/
80 /*static BOOLEAN (WINAPI *pRtlPrefixString)(const STRING *, const STRING *, BOOLEAN);*/
81 /*static BOOLEAN (WINAPI *pRtlPrefixUnicodeString)(const UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN);*/
82 /*static NTSTATUS (WINAPI *pRtlOemStringToUnicodeString)(PUNICODE_STRING, const STRING *, BOOLEAN);*/
83 /*static NTSTATUS (WINAPI *pRtlUnicodeStringToOemString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/
84 /*static NTSTATUS (WINAPI *pRtlMultiByteToUnicodeN)(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD);*/
85 /*static NTSTATUS (WINAPI *pRtlOemToUnicodeN)(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD);*/
86 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeStringToAnsiString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/
87 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeStringToOemString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/
88 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeToMultiByteN)(LPSTR, DWORD, LPDWORD, LPCWSTR, DWORD);*/
89 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeToOemN)(LPSTR, DWORD, LPDWORD, LPCWSTR, DWORD);*/
90 /*static UINT (WINAPI *pRtlOemToUnicodeSize)(const STRING *);*/
91 /*static DWORD (WINAPI *pRtlAnsiStringToUnicodeSize)(const STRING *);*/
94 static WCHAR
* AtoW( const char* p
)
97 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, p
, -1, NULL
, 0 );
98 buffer
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
99 MultiByteToWideChar( CP_ACP
, 0, p
, -1, buffer
, len
);
104 static void InitFunctionPtrs(void)
106 hntdll
= LoadLibraryA("ntdll.dll");
107 ok(hntdll
!= 0, "LoadLibrary failed\n");
109 pRtlAnsiStringToUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlAnsiStringToUnicodeString");
110 pRtlAppendAsciizToString
= (void *)GetProcAddress(hntdll
, "RtlAppendAsciizToString");
111 pRtlAppendStringToString
= (void *)GetProcAddress(hntdll
, "RtlAppendStringToString");
112 pRtlAppendUnicodeStringToString
= (void *)GetProcAddress(hntdll
, "RtlAppendUnicodeStringToString");
113 pRtlAppendUnicodeToString
= (void *)GetProcAddress(hntdll
, "RtlAppendUnicodeToString");
114 pRtlCharToInteger
= (void *)GetProcAddress(hntdll
, "RtlCharToInteger");
115 pRtlCopyString
= (void *)GetProcAddress(hntdll
, "RtlCopyString");
116 pRtlCreateUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlCreateUnicodeString");
117 pRtlCreateUnicodeStringFromAsciiz
= (void *)GetProcAddress(hntdll
, "RtlCreateUnicodeStringFromAsciiz");
118 pRtlDowncaseUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlDowncaseUnicodeString");
119 pRtlDuplicateUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlDuplicateUnicodeString");
120 pRtlEqualUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlEqualUnicodeString");
121 pRtlFindCharInUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFindCharInUnicodeString");
122 pRtlFreeAnsiString
= (void *)GetProcAddress(hntdll
, "RtlFreeAnsiString");
123 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
124 pRtlInitAnsiString
= (void *)GetProcAddress(hntdll
, "RtlInitAnsiString");
125 pRtlInitString
= (void *)GetProcAddress(hntdll
, "RtlInitString");
126 pRtlInitUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlInitUnicodeString");
127 pRtlInitUnicodeStringEx
= (void *)GetProcAddress(hntdll
, "RtlInitUnicodeStringEx");
128 pRtlIntegerToChar
= (void *)GetProcAddress(hntdll
, "RtlIntegerToChar");
129 pRtlIntegerToUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlIntegerToUnicodeString");
130 pRtlMultiAppendUnicodeStringBuffer
= (void *)GetProcAddress(hntdll
, "RtlMultiAppendUnicodeStringBuffer");
131 pRtlUnicodeStringToAnsiString
= (void *)GetProcAddress(hntdll
, "RtlUnicodeStringToAnsiString");
132 pRtlUnicodeStringToInteger
= (void *)GetProcAddress(hntdll
, "RtlUnicodeStringToInteger");
133 pRtlUpcaseUnicodeChar
= (void *)GetProcAddress(hntdll
, "RtlUpcaseUnicodeChar");
134 pRtlUpcaseUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlUpcaseUnicodeString");
135 pRtlUpperChar
= (void *)GetProcAddress(hntdll
, "RtlUpperChar");
136 pRtlUpperString
= (void *)GetProcAddress(hntdll
, "RtlUpperString");
137 pRtlValidateUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlValidateUnicodeString");
138 pRtlGUIDFromString
= (void *)GetProcAddress(hntdll
, "RtlGUIDFromString");
139 pRtlStringFromGUID
= (void *)GetProcAddress(hntdll
, "RtlStringFromGUID");
140 pRtlIsTextUnicode
= (void *)GetProcAddress(hntdll
, "RtlIsTextUnicode");
141 pRtlHashUnicodeString
= (void*)GetProcAddress(hntdll
, "RtlHashUnicodeString");
142 pRtlUnicodeToUTF8N
= (void*)GetProcAddress(hntdll
, "RtlUnicodeToUTF8N");
143 pRtlUTF8ToUnicodeN
= (void*)GetProcAddress(hntdll
, "RtlUTF8ToUnicodeN");
147 static void test_RtlInitString(void)
149 static const char teststring
[] = "Some Wild String";
153 str
.MaximumLength
= 0;
154 str
.Buffer
= (void *)0xdeadbeef;
155 pRtlInitString(&str
, teststring
);
156 ok(str
.Length
== sizeof(teststring
) - sizeof(char), "Length uninitialized\n");
157 ok(str
.MaximumLength
== sizeof(teststring
), "MaximumLength uninitialized\n");
158 ok(str
.Buffer
== teststring
, "Buffer not equal to teststring\n");
159 ok(strcmp(str
.Buffer
, "Some Wild String") == 0, "Buffer written to\n");
160 pRtlInitString(&str
, NULL
);
161 ok(str
.Length
== 0, "Length uninitialized\n");
162 ok(str
.MaximumLength
== 0, "MaximumLength uninitialized\n");
163 ok(str
.Buffer
== NULL
, "Buffer not equal to NULL\n");
164 /* pRtlInitString(NULL, teststring); */
168 static void test_RtlInitUnicodeString(void)
170 #define STRINGW {'S','o','m','e',' ','W','i','l','d',' ','S','t','r','i','n','g',0}
171 static const WCHAR teststring
[] = STRINGW
;
172 static const WCHAR originalstring
[] = STRINGW
;
177 uni
.MaximumLength
= 0;
178 uni
.Buffer
= (void *)0xdeadbeef;
179 pRtlInitUnicodeString(&uni
, teststring
);
180 ok(uni
.Length
== sizeof(teststring
) - sizeof(WCHAR
), "Length uninitialized\n");
181 ok(uni
.MaximumLength
== sizeof(teststring
), "MaximumLength uninitialized\n");
182 ok(uni
.Buffer
== teststring
, "Buffer not equal to teststring\n");
183 ok(lstrcmpW(uni
.Buffer
, originalstring
) == 0, "Buffer written to\n");
184 pRtlInitUnicodeString(&uni
, NULL
);
185 ok(uni
.Length
== 0, "Length uninitialized\n");
186 ok(uni
.MaximumLength
== 0, "MaximumLength uninitialized\n");
187 ok(uni
.Buffer
== NULL
, "Buffer not equal to NULL\n");
188 /* pRtlInitUnicodeString(NULL, teststring); */
192 #define TESTSTRING2_LEN 1000000
193 /* #define TESTSTRING2_LEN 32766 */
196 static void test_RtlInitUnicodeStringEx(void)
198 static const WCHAR teststring
[] = {'S','o','m','e',' ','W','i','l','d',' ','S','t','r','i','n','g',0};
203 if (!pRtlInitUnicodeStringEx
)
205 win_skip("RtlInitUnicodeStringEx is not available\n");
209 teststring2
= HeapAlloc(GetProcessHeap(), 0, (TESTSTRING2_LEN
+ 1) * sizeof(WCHAR
));
210 memset(teststring2
, 'X', TESTSTRING2_LEN
* sizeof(WCHAR
));
211 teststring2
[TESTSTRING2_LEN
] = '\0';
214 uni
.MaximumLength
= 12345;
215 uni
.Buffer
= (void *) 0xdeadbeef;
216 result
= pRtlInitUnicodeStringEx(&uni
, teststring
);
217 ok(result
== STATUS_SUCCESS
,
218 "pRtlInitUnicodeStringEx(&uni, 0) returns %x, expected 0\n",
221 "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected %u\n",
223 ok(uni
.MaximumLength
== 34,
224 "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected %u\n",
225 uni
.MaximumLength
, 34);
226 ok(uni
.Buffer
== teststring
,
227 "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %p\n",
228 uni
.Buffer
, teststring
);
231 uni
.MaximumLength
= 12345;
232 uni
.Buffer
= (void *) 0xdeadbeef;
233 pRtlInitUnicodeString(&uni
, teststring
);
235 "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u\n",
237 ok(uni
.MaximumLength
== 34,
238 "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u\n",
239 uni
.MaximumLength
, 34);
240 ok(uni
.Buffer
== teststring
,
241 "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p\n",
242 uni
.Buffer
, teststring
);
245 uni
.MaximumLength
= 12345;
246 uni
.Buffer
= (void *) 0xdeadbeef;
247 result
= pRtlInitUnicodeStringEx(&uni
, teststring2
);
248 ok(result
== STATUS_NAME_TOO_LONG
,
249 "pRtlInitUnicodeStringEx(&uni, 0) returns %x, expected %x\n",
250 result
, STATUS_NAME_TOO_LONG
);
251 ok(uni
.Length
== 12345 ||
252 uni
.Length
== 0, /* win2k3 */
253 "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected 12345 or 0\n",
255 ok(uni
.MaximumLength
== 12345 ||
256 uni
.MaximumLength
== 0, /* win2k3 */
257 "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected 12345 or 0\n",
259 ok(uni
.Buffer
== (void *) 0xdeadbeef ||
260 uni
.Buffer
== teststring2
, /* win2k3 */
261 "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %x or %p\n",
262 uni
.Buffer
, 0xdeadbeef, teststring2
);
265 uni
.MaximumLength
= 12345;
266 uni
.Buffer
= (void *) 0xdeadbeef;
267 pRtlInitUnicodeString(&uni
, teststring2
);
268 ok(uni
.Length
== 33920 /* <= Win2000 */ || uni
.Length
== 65532 /* >= Win XP */,
269 "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u\n",
271 ok(uni
.MaximumLength
== 33922 /* <= Win2000 */ || uni
.MaximumLength
== 65534 /* >= Win XP */,
272 "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u\n",
273 uni
.MaximumLength
, 65534);
274 ok(uni
.Buffer
== teststring2
,
275 "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p\n",
276 uni
.Buffer
, teststring2
);
277 ok(memcmp(uni
.Buffer
, teststring2
, (TESTSTRING2_LEN
+ 1) * sizeof(WCHAR
)) == 0,
278 "pRtlInitUnicodeString(&uni, 0) changes Buffer\n");
281 uni
.MaximumLength
= 12345;
282 uni
.Buffer
= (void *) 0xdeadbeef;
283 result
= pRtlInitUnicodeStringEx(&uni
, 0);
284 ok(result
== STATUS_SUCCESS
,
285 "pRtlInitUnicodeStringEx(&uni, 0) returns %x, expected 0\n",
288 "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected %u\n",
290 ok(uni
.MaximumLength
== 0,
291 "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected %u\n",
292 uni
.MaximumLength
, 0);
293 ok(uni
.Buffer
== NULL
,
294 "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %p\n",
298 uni
.MaximumLength
= 12345;
299 uni
.Buffer
= (void *) 0xdeadbeef;
300 pRtlInitUnicodeString(&uni
, 0);
302 "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u\n",
304 ok(uni
.MaximumLength
== 0,
305 "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u\n",
306 uni
.MaximumLength
, 0);
307 ok(uni
.Buffer
== NULL
,
308 "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p\n",
311 HeapFree(GetProcessHeap(), 0, teststring2
);
318 int source_MaximumLength
;
320 const char *source_buf
;
322 int dest_MaximumLength
;
324 const char *dest_buf
;
326 int res_MaximumLength
;
332 static const dupl_ustr_t dupl_ustr
[] = {
333 { 0, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 32, 32, "This is a string", STATUS_SUCCESS
},
334 { 0, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 32, 32, "This is a string", STATUS_SUCCESS
},
335 { 0, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
336 { 0, 32, 34, 34, "This is a string", 40, 42, 42, NULL
, 32, 32, 32, "This is a string", STATUS_SUCCESS
},
337 { 0, 32, 32, 32, "This is a string", 40, 42, 42, NULL
, 32, 32, 32, "This is a string", STATUS_SUCCESS
},
338 { 0, 32, 30, 34, "This is a string", 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
339 { 1, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS
},
340 { 1, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS
},
341 { 1, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
342 { 1, 32, 34, 34, "This is a string", 40, 42, 42, NULL
, 32, 34, 34, "This is a string", STATUS_SUCCESS
},
343 { 1, 32, 32, 32, "This is a string", 40, 42, 42, NULL
, 32, 34, 34, "This is a string", STATUS_SUCCESS
},
344 { 1, 32, 30, 34, "This is a string", 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
345 { 2, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
346 { 2, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
347 { 2, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
348 { 2, 32, 34, 34, "This is a string", 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
349 { 2, 32, 32, 32, "This is a string", 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
350 { 2, 32, 30, 34, "This is a string", 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
351 { 3, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS
},
352 { 3, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS
},
353 { 3, 32, 30, 32, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
354 { 3, 32, 34, 34, "This is a string", 40, 42, 42, NULL
, 32, 34, 34, "This is a string", STATUS_SUCCESS
},
355 { 3, 32, 32, 32, "This is a string", 40, 42, 42, NULL
, 32, 34, 34, "This is a string", STATUS_SUCCESS
},
356 { 3, 32, 30, 32, "This is a string", 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
357 { 4, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
358 { 5, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
359 { 6, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
360 { 7, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
361 { 8, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
362 { 9, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
363 {10, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
364 {11, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
365 {12, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
366 {13, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
367 {14, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
368 {15, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
369 {16, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
370 {-1, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
371 {-5, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
372 {-9, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
373 { 0, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL
, STATUS_SUCCESS
},
374 { 0, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL
, STATUS_SUCCESS
},
375 { 0, 0, 2, 2, "", 40, 42, 42, NULL
, 0, 0, 0, NULL
, STATUS_SUCCESS
},
376 { 0, 0, 0, 0, "", 40, 42, 42, NULL
, 0, 0, 0, NULL
, STATUS_SUCCESS
},
377 { 0, 0, 2, 2, NULL
, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
378 { 0, 0, 0, 0, NULL
, 40, 42, 42, "--------------------", 0, 0, 0, NULL
, STATUS_SUCCESS
},
379 { 0, 0, 2, 2, NULL
, 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
380 { 0, 0, 0, 0, NULL
, 40, 42, 42, NULL
, 0, 0, 0, NULL
, STATUS_SUCCESS
},
381 { 1, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL
, STATUS_SUCCESS
},
382 { 1, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL
, STATUS_SUCCESS
},
383 { 1, 0, 2, 2, "", 40, 42, 42, NULL
, 0, 0, 0, NULL
, STATUS_SUCCESS
},
384 { 1, 0, 0, 0, "", 40, 42, 42, NULL
, 0, 0, 0, NULL
, STATUS_SUCCESS
},
385 { 1, 0, 2, 2, NULL
, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
386 { 1, 0, 0, 0, NULL
, 40, 42, 42, "--------------------", 0, 0, 0, NULL
, STATUS_SUCCESS
},
387 { 1, 0, 2, 2, NULL
, 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
388 { 1, 0, 0, 0, NULL
, 40, 42, 42, NULL
, 0, 0, 0, NULL
, STATUS_SUCCESS
},
389 { 2, 0, 2, 2, "", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
390 { 2, 0, 0, 0, "", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
391 { 2, 0, 2, 2, "", 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
392 { 2, 0, 0, 0, "", 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
393 { 2, 0, 2, 2, NULL
, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
394 { 2, 0, 0, 0, NULL
, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
395 { 2, 0, 2, 2, NULL
, 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
396 { 2, 0, 0, 0, NULL
, 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
397 { 3, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS
},
398 { 3, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS
},
399 { 3, 0, 2, 2, "", 40, 42, 42, NULL
, 0, 2, 2, "", STATUS_SUCCESS
},
400 { 3, 0, 0, 0, "", 40, 42, 42, NULL
, 0, 2, 2, "", STATUS_SUCCESS
},
401 { 3, 0, 2, 2, NULL
, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
402 { 3, 0, 0, 0, NULL
, 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS
},
403 { 3, 0, 2, 2, NULL
, 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
404 { 3, 0, 0, 0, NULL
, 40, 42, 42, NULL
, 0, 2, 2, "", STATUS_SUCCESS
},
406 #define NB_DUPL_USTR (sizeof(dupl_ustr)/sizeof(*dupl_ustr))
409 static void test_RtlDuplicateUnicodeString(void)
412 WCHAR source_buf
[257];
415 UNICODE_STRING source_str
;
416 UNICODE_STRING dest_str
;
417 UNICODE_STRING res_str
;
418 CHAR dest_ansi_buf
[257];
419 STRING dest_ansi_str
;
421 unsigned int test_num
;
423 if (!pRtlDuplicateUnicodeString
)
425 win_skip("RtlDuplicateUnicodeString is not available\n");
429 for (test_num
= 0; test_num
< NB_DUPL_USTR
; test_num
++) {
430 source_str
.Length
= dupl_ustr
[test_num
].source_Length
;
431 source_str
.MaximumLength
= dupl_ustr
[test_num
].source_MaximumLength
;
432 if (dupl_ustr
[test_num
].source_buf
!= NULL
) {
433 for (pos
= 0; pos
< dupl_ustr
[test_num
].source_buf_size
/sizeof(WCHAR
); pos
++) {
434 source_buf
[pos
] = dupl_ustr
[test_num
].source_buf
[pos
];
436 source_str
.Buffer
= source_buf
;
438 source_str
.Buffer
= NULL
;
440 dest_str
.Length
= dupl_ustr
[test_num
].dest_Length
;
441 dest_str
.MaximumLength
= dupl_ustr
[test_num
].dest_MaximumLength
;
442 if (dupl_ustr
[test_num
].dest_buf
!= NULL
) {
443 for (pos
= 0; pos
< dupl_ustr
[test_num
].dest_buf_size
/sizeof(WCHAR
); pos
++) {
444 dest_buf
[pos
] = dupl_ustr
[test_num
].dest_buf
[pos
];
446 dest_str
.Buffer
= dest_buf
;
448 dest_str
.Buffer
= NULL
;
450 res_str
.Length
= dupl_ustr
[test_num
].res_Length
;
451 res_str
.MaximumLength
= dupl_ustr
[test_num
].res_MaximumLength
;
452 if (dupl_ustr
[test_num
].res_buf
!= NULL
) {
453 for (pos
= 0; pos
< dupl_ustr
[test_num
].res_buf_size
/sizeof(WCHAR
); pos
++) {
454 res_buf
[pos
] = dupl_ustr
[test_num
].res_buf
[pos
];
456 res_str
.Buffer
= res_buf
;
458 res_str
.Buffer
= NULL
;
460 result
= pRtlDuplicateUnicodeString(dupl_ustr
[test_num
].add_nul
, &source_str
, &dest_str
);
461 dest_ansi_str
.Length
= dest_str
.Length
/ sizeof(WCHAR
);
462 dest_ansi_str
.MaximumLength
= dest_ansi_str
.Length
+ 1;
463 for (pos
= 0; pos
< dest_ansi_str
.Length
; pos
++) {
464 dest_ansi_buf
[pos
] = (char)dest_buf
[pos
];
466 dest_ansi_buf
[dest_ansi_str
.Length
] = '\0';
467 dest_ansi_str
.Buffer
= dest_ansi_buf
;
468 ok(result
== dupl_ustr
[test_num
].result
,
469 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has result %x, expected %x\n",
470 test_num
, dupl_ustr
[test_num
].add_nul
, result
, dupl_ustr
[test_num
].result
);
471 ok(dest_str
.Length
== dupl_ustr
[test_num
].res_Length
,
472 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination has Length %d, expected %d\n",
473 test_num
, dupl_ustr
[test_num
].add_nul
, dest_str
.Length
, dupl_ustr
[test_num
].res_Length
);
474 ok(dest_str
.MaximumLength
== dupl_ustr
[test_num
].res_MaximumLength
,
475 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination has MaximumLength %d, expected %d\n",
476 test_num
, dupl_ustr
[test_num
].add_nul
, dest_str
.MaximumLength
, dupl_ustr
[test_num
].res_MaximumLength
);
477 if (result
== STATUS_INVALID_PARAMETER
) {
478 ok((dest_str
.Buffer
== NULL
&& res_str
.Buffer
== NULL
) ||
479 dest_str
.Buffer
== dest_buf
,
480 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination buffer changed %p expected %p\n",
481 test_num
, dupl_ustr
[test_num
].add_nul
, dest_str
.Buffer
, dest_buf
);
483 ok(dest_str
.Buffer
!= dest_buf
,
484 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination buffer unchanged %p\n",
485 test_num
, dupl_ustr
[test_num
].add_nul
, dest_str
.Buffer
);
487 if (dest_str
.Buffer
!= NULL
&& dupl_ustr
[test_num
].res_buf
!= NULL
) {
488 ok(memcmp(dest_str
.Buffer
, res_str
.Buffer
, dupl_ustr
[test_num
].res_buf_size
) == 0,
489 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination \"%s\" expected \"%s\"\n",
490 test_num
, dupl_ustr
[test_num
].add_nul
, dest_ansi_str
.Buffer
, dupl_ustr
[test_num
].res_buf
);
491 if(result
== STATUS_SUCCESS
) pRtlFreeUnicodeString(&dest_str
);
493 ok(dest_str
.Buffer
== NULL
&& dupl_ustr
[test_num
].res_buf
== NULL
,
494 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination %p expected %p\n",
495 test_num
, dupl_ustr
[test_num
].add_nul
, dest_str
.Buffer
, dupl_ustr
[test_num
].res_buf
);
501 static void test_RtlCopyString(void)
503 static const char teststring
[] = "Some Wild String";
504 char deststring
[] = " ";
508 pRtlInitString(&str
, teststring
);
509 pRtlInitString(&deststr
, deststring
);
510 pRtlCopyString(&deststr
, &str
);
511 ok(strncmp(str
.Buffer
, deststring
, str
.Length
) == 0, "String not copied\n");
515 static void test_RtlUpperChar(void)
519 int expected_upper_ch
;
522 for (ch
= -1; ch
<= 1024; ch
++) {
523 upper_ch
= pRtlUpperChar(ch
);
525 if (byte_ch
>= 'a' && byte_ch
<= 'z') {
526 expected_upper_ch
= (CHAR
) (byte_ch
- 'a' + 'A');
528 expected_upper_ch
= (CHAR
) byte_ch
;
530 ok(upper_ch
== expected_upper_ch
,
531 "RtlUpperChar('%c'[=0x%x]) has result '%c'[=0x%x], expected '%c'[=0x%x]\n",
532 ch
, ch
, upper_ch
, upper_ch
, expected_upper_ch
, expected_upper_ch
);
537 static void test_RtlUpperString(void)
543 char result_buf
[257];
549 for (i
= 0; i
<= 255; i
++) {
551 if (ch
>= 'a' && ch
<= 'z') {
552 upper_ch
= ch
- 'a' + 'A';
557 result_buf
[i
] = '\0';
558 upper_buf
[i
] = upper_ch
;
561 result_buf
[i
] = '\0';
563 ascii_str
.Length
= 256;
564 ascii_str
.MaximumLength
= 256;
565 ascii_str
.Buffer
= ascii_buf
;
566 result_str
.Length
= 256;
567 result_str
.MaximumLength
= 256;
568 result_str
.Buffer
= result_buf
;
569 upper_str
.Length
= 256;
570 upper_str
.MaximumLength
= 256;
571 upper_str
.Buffer
= upper_buf
;
573 pRtlUpperString(&result_str
, &ascii_str
);
574 ok(memcmp(result_str
.Buffer
, upper_str
.Buffer
, 256) == 0,
575 "RtlUpperString does not work as expected\n");
579 static void test_RtlUpcaseUnicodeChar(void)
584 WCHAR expected_upper_ch
;
586 for (i
= 0; i
<= 255; i
++) {
588 upper_ch
= pRtlUpcaseUnicodeChar(ch
);
589 if (ch
>= 'a' && ch
<= 'z') {
590 expected_upper_ch
= ch
- 'a' + 'A';
591 } else if (ch
>= 0xe0 && ch
<= 0xfe && ch
!= 0xf7) {
592 expected_upper_ch
= ch
- 0x20;
593 } else if (ch
== 0xff) {
594 expected_upper_ch
= 0x178;
596 expected_upper_ch
= ch
;
598 ok(upper_ch
== expected_upper_ch
,
599 "RtlUpcaseUnicodeChar('%c'[=0x%x]) has result '%c'[=0x%x], expected: '%c'[=0x%x]\n",
600 ch
, ch
, upper_ch
, upper_ch
, expected_upper_ch
, expected_upper_ch
);
605 static void test_RtlUpcaseUnicodeString(void)
610 WCHAR ascii_buf
[257];
611 WCHAR result_buf
[257];
612 WCHAR upper_buf
[257];
613 UNICODE_STRING ascii_str
;
614 UNICODE_STRING result_str
;
615 UNICODE_STRING upper_str
;
617 for (i
= 0; i
<= 255; i
++) {
619 if (ch
>= 'a' && ch
<= 'z') {
620 upper_ch
= ch
- 'a' + 'A';
621 } else if (ch
>= 0xe0 && ch
<= 0xfe && ch
!= 0xf7) {
622 upper_ch
= ch
- 0x20;
623 } else if (ch
== 0xff) {
629 result_buf
[i
] = '\0';
630 upper_buf
[i
] = upper_ch
;
633 result_buf
[i
] = '\0';
635 ascii_str
.Length
= 512;
636 ascii_str
.MaximumLength
= 512;
637 ascii_str
.Buffer
= ascii_buf
;
638 result_str
.Length
= 512;
639 result_str
.MaximumLength
= 512;
640 result_str
.Buffer
= result_buf
;
641 upper_str
.Length
= 512;
642 upper_str
.MaximumLength
= 512;
643 upper_str
.Buffer
= upper_buf
;
645 pRtlUpcaseUnicodeString(&result_str
, &ascii_str
, 0);
646 for (i
= 0; i
<= 255; i
++) {
647 ok(result_str
.Buffer
[i
] == upper_str
.Buffer
[i
],
648 "RtlUpcaseUnicodeString works wrong: '%c'[=0x%x] is converted to '%c'[=0x%x], expected: '%c'[=0x%x]\n",
649 ascii_str
.Buffer
[i
], ascii_str
.Buffer
[i
],
650 result_str
.Buffer
[i
], result_str
.Buffer
[i
],
651 upper_str
.Buffer
[i
], upper_str
.Buffer
[i
]);
656 static void test_RtlDowncaseUnicodeString(void)
661 WCHAR source_buf
[1025];
662 WCHAR result_buf
[1025];
663 WCHAR lower_buf
[1025];
664 UNICODE_STRING source_str
;
665 UNICODE_STRING result_str
;
666 UNICODE_STRING lower_str
;
668 for (i
= 0; i
< 1024; i
++) {
670 if (ch
>= 'A' && ch
<= 'Z') {
671 lower_ch
= ch
- 'A' + 'a';
672 } else if (ch
>= 0xc0 && ch
<= 0xde && ch
!= 0xd7) {
673 lower_ch
= ch
+ 0x20;
674 } else if (ch
>= 0x391 && ch
<= 0x3ab && ch
!= 0x3a2) {
675 lower_ch
= ch
+ 0x20;
678 case 0x178: lower_ch
= 0xff; break;
679 case 0x181: lower_ch
= 0x253; break;
680 case 0x186: lower_ch
= 0x254; break;
681 case 0x189: lower_ch
= 0x256; break;
682 case 0x18a: lower_ch
= 0x257; break;
683 case 0x18e: lower_ch
= 0x1dd; break;
684 case 0x18f: lower_ch
= 0x259; break;
685 case 0x190: lower_ch
= 0x25b; break;
686 case 0x193: lower_ch
= 0x260; break;
687 case 0x194: lower_ch
= 0x263; break;
688 case 0x196: lower_ch
= 0x269; break;
689 case 0x197: lower_ch
= 0x268; break;
690 case 0x19c: lower_ch
= 0x26f; break;
691 case 0x19d: lower_ch
= 0x272; break;
692 case 0x19f: lower_ch
= 0x275; break;
693 case 0x1a9: lower_ch
= 0x283; break;
694 case 0x1ae: lower_ch
= 0x288; break;
695 case 0x1b1: lower_ch
= 0x28a; break;
696 case 0x1b2: lower_ch
= 0x28b; break;
697 case 0x1b7: lower_ch
= 0x292; break;
698 case 0x1c4: lower_ch
= 0x1c6; break;
699 case 0x1c7: lower_ch
= 0x1c9; break;
700 case 0x1ca: lower_ch
= 0x1cc; break;
701 case 0x1f1: lower_ch
= 0x1f3; break;
702 case 0x386: lower_ch
= 0x3ac; break;
703 case 0x388: lower_ch
= 0x3ad; break;
704 case 0x389: lower_ch
= 0x3ae; break;
705 case 0x38a: lower_ch
= 0x3af; break;
706 case 0x38c: lower_ch
= 0x3cc; break;
707 case 0x38e: lower_ch
= 0x3cd; break;
708 case 0x38f: lower_ch
= 0x3ce; break;
709 default: lower_ch
= ch
; break;
713 result_buf
[i
] = '\0';
714 lower_buf
[i
] = lower_ch
;
716 source_buf
[i
] = '\0';
717 result_buf
[i
] = '\0';
719 source_str
.Length
= 2048;
720 source_str
.MaximumLength
= 2048;
721 source_str
.Buffer
= source_buf
;
722 result_str
.Length
= 2048;
723 result_str
.MaximumLength
= 2048;
724 result_str
.Buffer
= result_buf
;
725 lower_str
.Length
= 2048;
726 lower_str
.MaximumLength
= 2048;
727 lower_str
.Buffer
= lower_buf
;
729 pRtlDowncaseUnicodeString(&result_str
, &source_str
, 0);
730 for (i
= 0; i
<= 1024; i
++) {
731 ok(result_str
.Buffer
[i
] == lower_str
.Buffer
[i
] || result_str
.Buffer
[i
] == source_str
.Buffer
[i
] + 1,
732 "RtlDowncaseUnicodeString works wrong: '%c'[=0x%x] is converted to '%c'[=0x%x], expected: '%c'[=0x%x]\n",
733 source_str
.Buffer
[i
], source_str
.Buffer
[i
],
734 result_str
.Buffer
[i
], result_str
.Buffer
[i
],
735 lower_str
.Buffer
[i
], lower_str
.Buffer
[i
]);
742 int ansi_MaximumLength
;
744 const char *ansi_buf
;
746 int uni_MaximumLength
;
751 int res_MaximumLength
;
757 static const ustr2astr_t ustr2astr
[] = {
758 { 10, 12, 12, "------------", 0, 0, 0, "", TRUE
, 0, 1, 1, "", STATUS_SUCCESS
},
759 { 10, 12, 12, "------------", 12, 12, 12, "abcdef", TRUE
, 6, 7, 7, "abcdef", STATUS_SUCCESS
},
760 { 0, 2, 12, "------------", 12, 12, 12, "abcdef", TRUE
, 6, 7, 7, "abcdef", STATUS_SUCCESS
},
761 { 10, 12, 12, NULL
, 12, 12, 12, "abcdef", TRUE
, 6, 7, 7, "abcdef", STATUS_SUCCESS
},
762 { 0, 0, 12, "------------", 12, 12, 12, "abcdef", FALSE
, 6, 0, 0, "", STATUS_BUFFER_OVERFLOW
},
763 { 0, 1, 12, "------------", 12, 12, 12, "abcdef", FALSE
, 0, 1, 1, "", STATUS_BUFFER_OVERFLOW
},
764 { 0, 2, 12, "------------", 12, 12, 12, "abcdef", FALSE
, 1, 2, 2, "a", STATUS_BUFFER_OVERFLOW
},
765 { 0, 3, 12, "------------", 12, 12, 12, "abcdef", FALSE
, 2, 3, 3, "ab", STATUS_BUFFER_OVERFLOW
},
766 { 0, 5, 12, "------------", 12, 12, 12, "abcdef", FALSE
, 4, 5, 5, "abcd", STATUS_BUFFER_OVERFLOW
},
767 { 8, 5, 12, "------------", 12, 12, 12, "abcdef", FALSE
, 4, 5, 5, "abcd", STATUS_BUFFER_OVERFLOW
},
768 { 8, 6, 12, "------------", 12, 12, 12, "abcdef", FALSE
, 5, 6, 6, "abcde", STATUS_BUFFER_OVERFLOW
},
769 { 8, 7, 12, "------------", 12, 12, 12, "abcdef", FALSE
, 6, 7, 7, "abcdef", STATUS_SUCCESS
},
770 { 8, 7, 12, "------------", 0, 12, 12, NULL
, FALSE
, 0, 7, 0, "", STATUS_SUCCESS
},
772 /* crashes on Japanese and Chinese XP */
773 { 0, 0, 12, NULL
, 10, 10, 12, NULL
, FALSE
, 5, 0, 0, NULL
, STATUS_BUFFER_OVERFLOW
},
776 #define NB_USTR2ASTR (sizeof(ustr2astr)/sizeof(*ustr2astr))
779 static void test_RtlUnicodeStringToAnsiString(void)
785 UNICODE_STRING uni_str
;
787 unsigned int test_num
;
789 for (test_num
= 0; test_num
< NB_USTR2ASTR
; test_num
++) {
790 ansi_str
.Length
= ustr2astr
[test_num
].ansi_Length
;
791 ansi_str
.MaximumLength
= ustr2astr
[test_num
].ansi_MaximumLength
;
792 if (ustr2astr
[test_num
].ansi_buf
!= NULL
) {
793 memcpy(ansi_buf
, ustr2astr
[test_num
].ansi_buf
, ustr2astr
[test_num
].ansi_buf_size
);
794 ansi_buf
[ustr2astr
[test_num
].ansi_buf_size
] = '\0';
795 ansi_str
.Buffer
= ansi_buf
;
797 ansi_str
.Buffer
= NULL
;
799 uni_str
.Length
= ustr2astr
[test_num
].uni_Length
;
800 uni_str
.MaximumLength
= ustr2astr
[test_num
].uni_MaximumLength
;
801 if (ustr2astr
[test_num
].uni_buf
!= NULL
) {
802 for (pos
= 0; pos
< ustr2astr
[test_num
].uni_buf_size
/sizeof(WCHAR
); pos
++) {
803 uni_buf
[pos
] = ustr2astr
[test_num
].uni_buf
[pos
];
805 uni_str
.Buffer
= uni_buf
;
807 uni_str
.Buffer
= NULL
;
809 result
= pRtlUnicodeStringToAnsiString(&ansi_str
, &uni_str
, ustr2astr
[test_num
].doalloc
);
810 ok(result
== ustr2astr
[test_num
].result
,
811 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) has result %x, expected %x\n",
812 test_num
, ustr2astr
[test_num
].doalloc
, result
, ustr2astr
[test_num
].result
);
813 ok(ansi_str
.Length
== ustr2astr
[test_num
].res_Length
,
814 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) ansi has Length %d, expected %d\n",
815 test_num
, ustr2astr
[test_num
].doalloc
, ansi_str
.Length
, ustr2astr
[test_num
].res_Length
);
816 ok(ansi_str
.MaximumLength
== ustr2astr
[test_num
].res_MaximumLength
,
817 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) ansi has MaximumLength %d, expected %d\n",
818 test_num
, ustr2astr
[test_num
].doalloc
, ansi_str
.MaximumLength
, ustr2astr
[test_num
].res_MaximumLength
);
819 ok(memcmp(ansi_str
.Buffer
, ustr2astr
[test_num
].res_buf
, ustr2astr
[test_num
].res_buf_size
) == 0,
820 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) has ansi \"%s\" expected \"%s\"\n",
821 test_num
, ustr2astr
[test_num
].doalloc
, ansi_str
.Buffer
, ustr2astr
[test_num
].res_buf
);
822 if(result
== STATUS_SUCCESS
&& ustr2astr
[test_num
].doalloc
)
823 pRtlFreeAnsiString(&ansi_str
);
830 int dest_MaximumLength
;
832 const char *dest_buf
;
835 int res_MaximumLength
;
841 static const app_asc2str_t app_asc2str
[] = {
842 { 5, 12, 15, "TestS01234abcde", "tring", 10, 12, 15, "TestStringabcde", STATUS_SUCCESS
},
843 { 5, 11, 15, "TestS01234abcde", "tring", 10, 11, 15, "TestStringabcde", STATUS_SUCCESS
},
844 { 5, 10, 15, "TestS01234abcde", "tring", 10, 10, 15, "TestStringabcde", STATUS_SUCCESS
},
845 { 5, 9, 15, "TestS01234abcde", "tring", 5, 9, 15, "TestS01234abcde", STATUS_BUFFER_TOO_SMALL
},
846 { 5, 0, 15, "TestS01234abcde", "tring", 5, 0, 15, "TestS01234abcde", STATUS_BUFFER_TOO_SMALL
},
847 { 5, 14, 15, "TestS01234abcde", "tring", 10, 14, 15, "TestStringabcde", STATUS_SUCCESS
},
848 { 5, 14, 15, "TestS01234abcde", NULL
, 5, 14, 15, "TestS01234abcde", STATUS_SUCCESS
},
849 { 5, 14, 15, NULL
, NULL
, 5, 14, 15, NULL
, STATUS_SUCCESS
},
850 { 5, 12, 15, "Tst\0S01234abcde", "tr\0i", 7, 12, 15, "Tst\0Str234abcde", STATUS_SUCCESS
},
852 #define NB_APP_ASC2STR (sizeof(app_asc2str)/sizeof(*app_asc2str))
855 static void test_RtlAppendAsciizToString(void)
860 unsigned int test_num
;
862 for (test_num
= 0; test_num
< NB_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
;
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
);
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
);
897 int dest_MaximumLength
;
899 const char *dest_buf
;
901 int src_MaximumLength
;
905 int res_MaximumLength
;
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
},
922 #define NB_APP_STR2STR (sizeof(app_str2str)/sizeof(*app_str2str))
925 static void test_RtlAppendStringToString(void)
932 unsigned int test_num
;
934 for (test_num
= 0; test_num
< NB_APP_STR2STR
; test_num
++) {
935 dest_str
.Length
= app_str2str
[test_num
].dest_Length
;
936 dest_str
.MaximumLength
= app_str2str
[test_num
].dest_MaximumLength
;
937 if (app_str2str
[test_num
].dest_buf
!= NULL
) {
938 memcpy(dest_buf
, app_str2str
[test_num
].dest_buf
, app_str2str
[test_num
].dest_buf_size
);
939 dest_buf
[app_str2str
[test_num
].dest_buf_size
] = '\0';
940 dest_str
.Buffer
= dest_buf
;
942 dest_str
.Buffer
= NULL
;
944 src_str
.Length
= app_str2str
[test_num
].src_Length
;
945 src_str
.MaximumLength
= app_str2str
[test_num
].src_MaximumLength
;
946 if (app_str2str
[test_num
].src_buf
!= NULL
) {
947 memcpy(src_buf
, app_str2str
[test_num
].src_buf
, app_str2str
[test_num
].src_buf_size
);
948 src_buf
[app_str2str
[test_num
].src_buf_size
] = '\0';
949 src_str
.Buffer
= src_buf
;
951 src_str
.Buffer
= NULL
;
953 result
= pRtlAppendStringToString(&dest_str
, &src_str
);
954 ok(result
== app_str2str
[test_num
].result
,
955 "(test %d): RtlAppendStringToString(dest, src) has result %x, expected %x\n",
956 test_num
, result
, app_str2str
[test_num
].result
);
957 ok(dest_str
.Length
== app_str2str
[test_num
].res_Length
,
958 "(test %d): RtlAppendStringToString(dest, src) dest has Length %d, expected %d\n",
959 test_num
, dest_str
.Length
, app_str2str
[test_num
].res_Length
);
960 ok(dest_str
.MaximumLength
== app_str2str
[test_num
].res_MaximumLength
,
961 "(test %d): RtlAppendStringToString(dest, src) dest has MaximumLength %d, expected %d\n",
962 test_num
, dest_str
.MaximumLength
, app_str2str
[test_num
].res_MaximumLength
);
963 if (dest_str
.Buffer
== dest_buf
) {
964 ok(memcmp(dest_buf
, app_str2str
[test_num
].res_buf
, app_str2str
[test_num
].res_buf_size
) == 0,
965 "(test %d): RtlAppendStringToString(dest, src) has dest \"%s\" expected \"%s\"\n",
966 test_num
, dest_buf
, app_str2str
[test_num
].res_buf
);
968 ok(dest_str
.Buffer
== app_str2str
[test_num
].res_buf
,
969 "(test %d): RtlAppendStringToString(dest, src) dest has Buffer %p expected %p\n",
970 test_num
, dest_str
.Buffer
, app_str2str
[test_num
].res_buf
);
978 int dest_MaximumLength
;
980 const char *dest_buf
;
983 int res_MaximumLength
;
989 static const app_uni2str_t app_uni2str
[] = {
990 { 4, 12, 14, "Fake0123abcdef", "Ustr\0", 8, 12, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS
},
991 { 4, 11, 14, "Fake0123abcdef", "Ustr\0", 8, 11, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS
},
992 { 4, 10, 14, "Fake0123abcdef", "Ustr\0", 8, 10, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS
},
993 /* In the following test the native function writes beyond MaximumLength
994 * { 4, 9, 14, "Fake0123abcdef", "Ustr\0", 8, 9, 14, "FakeUstrabcdef", STATUS_SUCCESS},
996 { 4, 8, 14, "Fake0123abcdef", "Ustr\0", 8, 8, 14, "FakeUstrabcdef", STATUS_SUCCESS
},
997 { 4, 7, 14, "Fake0123abcdef", "Ustr\0", 4, 7, 14, "Fake0123abcdef", STATUS_BUFFER_TOO_SMALL
},
998 { 4, 0, 14, "Fake0123abcdef", "Ustr\0", 4, 0, 14, "Fake0123abcdef", STATUS_BUFFER_TOO_SMALL
},
999 { 4, 14, 14, "Fake0123abcdef", "Ustr\0", 8, 14, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS
},
1000 { 4, 14, 14, "Fake0123abcdef", NULL
, 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS
},
1001 { 4, 14, 14, NULL
, NULL
, 4, 14, 14, NULL
, STATUS_SUCCESS
},
1002 { 4, 14, 14, "Fake0123abcdef", "U\0stri\0", 10, 14, 14, "FakeU\0stri\0\0ef", STATUS_SUCCESS
},
1003 { 6, 14, 16, "Te\0\0stabcdefghij", "St\0\0ri", 8, 14, 16, "Te\0\0stSt\0\0efghij", STATUS_SUCCESS
},
1005 #define NB_APP_UNI2STR (sizeof(app_uni2str)/sizeof(*app_uni2str))
1008 static void test_RtlAppendUnicodeToString(void)
1010 WCHAR dest_buf
[257];
1011 UNICODE_STRING dest_str
;
1013 unsigned int test_num
;
1015 for (test_num
= 0; test_num
< NB_APP_UNI2STR
; test_num
++) {
1016 dest_str
.Length
= app_uni2str
[test_num
].dest_Length
;
1017 dest_str
.MaximumLength
= app_uni2str
[test_num
].dest_MaximumLength
;
1018 if (app_uni2str
[test_num
].dest_buf
!= NULL
) {
1019 memcpy(dest_buf
, app_uni2str
[test_num
].dest_buf
, app_uni2str
[test_num
].dest_buf_size
);
1020 dest_buf
[app_uni2str
[test_num
].dest_buf_size
/sizeof(WCHAR
)] = '\0';
1021 dest_str
.Buffer
= dest_buf
;
1023 dest_str
.Buffer
= NULL
;
1025 result
= pRtlAppendUnicodeToString(&dest_str
, (LPCWSTR
) app_uni2str
[test_num
].src
);
1026 ok(result
== app_uni2str
[test_num
].result
,
1027 "(test %d): RtlAppendUnicodeToString(dest, src) has result %x, expected %x\n",
1028 test_num
, result
, app_uni2str
[test_num
].result
);
1029 ok(dest_str
.Length
== app_uni2str
[test_num
].res_Length
,
1030 "(test %d): RtlAppendUnicodeToString(dest, src) dest has Length %d, expected %d\n",
1031 test_num
, dest_str
.Length
, app_uni2str
[test_num
].res_Length
);
1032 ok(dest_str
.MaximumLength
== app_uni2str
[test_num
].res_MaximumLength
,
1033 "(test %d): RtlAppendUnicodeToString(dest, src) dest has MaximumLength %d, expected %d\n",
1034 test_num
, dest_str
.MaximumLength
, app_uni2str
[test_num
].res_MaximumLength
);
1035 if (dest_str
.Buffer
== dest_buf
) {
1036 ok(memcmp(dest_buf
, app_uni2str
[test_num
].res_buf
, app_uni2str
[test_num
].res_buf_size
) == 0,
1037 "(test %d): RtlAppendUnicodeToString(dest, src) has dest \"%s\" expected \"%s\"\n",
1038 test_num
, (char *) dest_buf
, app_uni2str
[test_num
].res_buf
);
1040 ok(dest_str
.Buffer
== (WCHAR
*) app_uni2str
[test_num
].res_buf
,
1041 "(test %d): RtlAppendUnicodeToString(dest, src) dest has Buffer %p expected %p\n",
1042 test_num
, dest_str
.Buffer
, app_uni2str
[test_num
].res_buf
);
1050 int dest_MaximumLength
;
1052 const char *dest_buf
;
1054 int src_MaximumLength
;
1056 const char *src_buf
;
1058 int res_MaximumLength
;
1060 const char *res_buf
;
1064 static const app_ustr2str_t app_ustr2str
[] = {
1065 { 4, 12, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 12, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS
},
1066 { 4, 11, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 11, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS
},
1067 { 4, 10, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 10, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS
},
1068 /* In the following test the native function writes beyond MaximumLength
1069 * { 4, 9, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 9, 14, "FakeUstrabcdef", STATUS_SUCCESS},
1071 { 4, 8, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 8, 14, "FakeUstrabcdef", STATUS_SUCCESS
},
1072 { 4, 7, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 4, 7, 14, "Fake0123abcdef", STATUS_BUFFER_TOO_SMALL
},
1073 { 4, 0, 14, "Fake0123abcdef", 0, 0, 8, "UstrZYXW", 4, 0, 14, "Fake0123abcdef", STATUS_SUCCESS
},
1074 { 4, 14, 14, "Fake0123abcdef", 0, 0, 8, "UstrZYXW", 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS
},
1075 { 4, 14, 14, "Fake0123abcdef", 0, 0, 8, NULL
, 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS
},
1076 { 4, 14, 14, NULL
, 0, 0, 8, NULL
, 4, 14, 14, NULL
, STATUS_SUCCESS
},
1077 { 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 #define NB_APP_USTR2STR (sizeof(app_ustr2str)/sizeof(*app_ustr2str))
1082 static void test_RtlAppendUnicodeStringToString(void)
1084 WCHAR dest_buf
[257];
1086 UNICODE_STRING dest_str
;
1087 UNICODE_STRING src_str
;
1089 unsigned int test_num
;
1091 for (test_num
= 0; test_num
< NB_APP_USTR2STR
; test_num
++) {
1092 dest_str
.Length
= app_ustr2str
[test_num
].dest_Length
;
1093 dest_str
.MaximumLength
= app_ustr2str
[test_num
].dest_MaximumLength
;
1094 if (app_ustr2str
[test_num
].dest_buf
!= NULL
) {
1095 memcpy(dest_buf
, app_ustr2str
[test_num
].dest_buf
, app_ustr2str
[test_num
].dest_buf_size
);
1096 dest_buf
[app_ustr2str
[test_num
].dest_buf_size
/sizeof(WCHAR
)] = '\0';
1097 dest_str
.Buffer
= dest_buf
;
1099 dest_str
.Buffer
= NULL
;
1101 src_str
.Length
= app_ustr2str
[test_num
].src_Length
;
1102 src_str
.MaximumLength
= app_ustr2str
[test_num
].src_MaximumLength
;
1103 if (app_ustr2str
[test_num
].src_buf
!= NULL
) {
1104 memcpy(src_buf
, app_ustr2str
[test_num
].src_buf
, app_ustr2str
[test_num
].src_buf_size
);
1105 src_buf
[app_ustr2str
[test_num
].src_buf_size
/sizeof(WCHAR
)] = '\0';
1106 src_str
.Buffer
= src_buf
;
1108 src_str
.Buffer
= NULL
;
1110 result
= pRtlAppendUnicodeStringToString(&dest_str
, &src_str
);
1111 ok(result
== app_ustr2str
[test_num
].result
,
1112 "(test %d): RtlAppendStringToString(dest, src) has result %x, expected %x\n",
1113 test_num
, result
, app_ustr2str
[test_num
].result
);
1114 ok(dest_str
.Length
== app_ustr2str
[test_num
].res_Length
,
1115 "(test %d): RtlAppendStringToString(dest, src) dest has Length %d, expected %d\n",
1116 test_num
, dest_str
.Length
, app_ustr2str
[test_num
].res_Length
);
1117 ok(dest_str
.MaximumLength
== app_ustr2str
[test_num
].res_MaximumLength
,
1118 "(test %d): RtlAppendStringToString(dest, src) dest has MaximumLength %d, expected %d\n",
1119 test_num
, dest_str
.MaximumLength
, app_ustr2str
[test_num
].res_MaximumLength
);
1120 if (dest_str
.Buffer
== dest_buf
) {
1121 ok(memcmp(dest_buf
, app_ustr2str
[test_num
].res_buf
, app_ustr2str
[test_num
].res_buf_size
) == 0,
1122 "(test %d): RtlAppendStringToString(dest, src) has dest \"%s\" expected \"%s\"\n",
1123 test_num
, (char *) dest_buf
, app_ustr2str
[test_num
].res_buf
);
1125 ok(dest_str
.Buffer
== (WCHAR
*) app_ustr2str
[test_num
].res_buf
,
1126 "(test %d): RtlAppendStringToString(dest, src) dest has Buffer %p expected %p\n",
1127 test_num
, dest_str
.Buffer
, app_ustr2str
[test_num
].res_buf
);
1135 const char *main_str
;
1136 const char *search_chars
;
1139 } find_ch_in_ustr_t
;
1141 static const find_ch_in_ustr_t find_ch_in_ustr
[] = {
1142 { 0, "Some Wild String", "S", 2, STATUS_SUCCESS
},
1143 { 0, "This is a String", "String", 6, STATUS_SUCCESS
},
1144 { 1, "This is a String", "String", 30, STATUS_SUCCESS
},
1145 { 2, "This is a String", "String", 2, STATUS_SUCCESS
},
1146 { 3, "This is a String", "String", 18, STATUS_SUCCESS
},
1147 { 0, "This is a String", "Wild", 6, STATUS_SUCCESS
},
1148 { 1, "This is a String", "Wild", 26, STATUS_SUCCESS
},
1149 { 2, "This is a String", "Wild", 2, STATUS_SUCCESS
},
1150 { 3, "This is a String", "Wild", 30, STATUS_SUCCESS
},
1151 { 0, "abcdefghijklmnopqrstuvwxyz", "", 0, STATUS_NOT_FOUND
},
1152 { 0, "abcdefghijklmnopqrstuvwxyz", "123", 0, STATUS_NOT_FOUND
},
1153 { 0, "abcdefghijklmnopqrstuvwxyz", "a", 2, STATUS_SUCCESS
},
1154 { 0, "abcdefghijklmnopqrstuvwxyz", "12a34", 2, STATUS_SUCCESS
},
1155 { 0, "abcdefghijklmnopqrstuvwxyz", "12b34", 4, STATUS_SUCCESS
},
1156 { 0, "abcdefghijklmnopqrstuvwxyz", "12y34", 50, STATUS_SUCCESS
},
1157 { 0, "abcdefghijklmnopqrstuvwxyz", "12z34", 52, STATUS_SUCCESS
},
1158 { 0, "abcdefghijklmnopqrstuvwxyz", "rvz", 36, STATUS_SUCCESS
},
1159 { 0, "abcdefghijklmmlkjihgfedcba", "egik", 10, STATUS_SUCCESS
},
1160 { 1, "abcdefghijklmnopqrstuvwxyz", "", 0, STATUS_NOT_FOUND
},
1161 { 1, "abcdefghijklmnopqrstuvwxyz", "rvz", 50, STATUS_SUCCESS
},
1162 { 1, "abcdefghijklmnopqrstuvwxyz", "ravy", 48, STATUS_SUCCESS
},
1163 { 1, "abcdefghijklmnopqrstuvwxyz", "raxv", 46, STATUS_SUCCESS
},
1164 { 2, "abcdefghijklmnopqrstuvwxyz", "", 2, STATUS_SUCCESS
},
1165 { 2, "abcdefghijklmnopqrstuvwxyz", "rvz", 2, STATUS_SUCCESS
},
1166 { 2, "abcdefghijklmnopqrstuvwxyz", "vaz", 4, STATUS_SUCCESS
},
1167 { 2, "abcdefghijklmnopqrstuvwxyz", "ravbz", 6, STATUS_SUCCESS
},
1168 { 3, "abcdefghijklmnopqrstuvwxyz", "", 50, STATUS_SUCCESS
},
1169 { 3, "abcdefghijklmnopqrstuvwxyz", "123", 50, STATUS_SUCCESS
},
1170 { 3, "abcdefghijklmnopqrstuvwxyz", "ahp", 50, STATUS_SUCCESS
},
1171 { 3, "abcdefghijklmnopqrstuvwxyz", "rvz", 48, STATUS_SUCCESS
},
1172 { 0, NULL
, "abc", 0, STATUS_NOT_FOUND
},
1173 { 1, NULL
, "abc", 0, STATUS_NOT_FOUND
},
1174 { 2, NULL
, "abc", 0, STATUS_NOT_FOUND
},
1175 { 3, NULL
, "abc", 0, STATUS_NOT_FOUND
},
1176 { 0, "abcdefghijklmnopqrstuvwxyz", NULL
, 0, STATUS_NOT_FOUND
},
1177 { 1, "abcdefghijklmnopqrstuvwxyz", NULL
, 0, STATUS_NOT_FOUND
},
1178 { 2, "abcdefghijklmnopqrstuvwxyz", NULL
, 2, STATUS_SUCCESS
},
1179 { 3, "abcdefghijklmnopqrstuvwxyz", NULL
, 50, STATUS_SUCCESS
},
1180 { 0, NULL
, NULL
, 0, STATUS_NOT_FOUND
},
1181 { 1, NULL
, NULL
, 0, STATUS_NOT_FOUND
},
1182 { 2, NULL
, NULL
, 0, STATUS_NOT_FOUND
},
1183 { 3, NULL
, NULL
, 0, STATUS_NOT_FOUND
},
1184 { 0, "abcdabcdabcdabcdabcdabcd", "abcd", 2, STATUS_SUCCESS
},
1185 { 1, "abcdabcdabcdabcdabcdabcd", "abcd", 46, STATUS_SUCCESS
},
1186 { 2, "abcdabcdabcdabcdabcdabcd", "abcd", 0, STATUS_NOT_FOUND
},
1187 { 3, "abcdabcdabcdabcdabcdabcd", "abcd", 0, STATUS_NOT_FOUND
},
1189 #define NB_FIND_CH_IN_USTR (sizeof(find_ch_in_ustr)/sizeof(*find_ch_in_ustr))
1192 static void test_RtlFindCharInUnicodeString(void)
1194 WCHAR main_str_buf
[257];
1195 WCHAR search_chars_buf
[257];
1196 UNICODE_STRING main_str
;
1197 UNICODE_STRING search_chars
;
1201 unsigned int test_num
;
1203 if (!pRtlFindCharInUnicodeString
)
1205 win_skip("RtlFindCharInUnicodeString is not available\n");
1209 for (test_num
= 0; test_num
< NB_FIND_CH_IN_USTR
; test_num
++) {
1210 if (find_ch_in_ustr
[test_num
].main_str
!= NULL
) {
1211 main_str
.Length
= strlen(find_ch_in_ustr
[test_num
].main_str
) * sizeof(WCHAR
);
1212 main_str
.MaximumLength
= main_str
.Length
+ sizeof(WCHAR
);
1213 for (idx
= 0; idx
< main_str
.Length
/ sizeof(WCHAR
); idx
++) {
1214 main_str_buf
[idx
] = find_ch_in_ustr
[test_num
].main_str
[idx
];
1216 main_str
.Buffer
= main_str_buf
;
1218 main_str
.Length
= 0;
1219 main_str
.MaximumLength
= 0;
1220 main_str
.Buffer
= NULL
;
1222 if (find_ch_in_ustr
[test_num
].search_chars
!= NULL
) {
1223 search_chars
.Length
= strlen(find_ch_in_ustr
[test_num
].search_chars
) * sizeof(WCHAR
);
1224 search_chars
.MaximumLength
= search_chars
.Length
+ sizeof(WCHAR
);
1225 for (idx
= 0; idx
< search_chars
.Length
/ sizeof(WCHAR
); idx
++) {
1226 search_chars_buf
[idx
] = find_ch_in_ustr
[test_num
].search_chars
[idx
];
1228 search_chars
.Buffer
= search_chars_buf
;
1230 search_chars
.Length
= 0;
1231 search_chars
.MaximumLength
= 0;
1232 search_chars
.Buffer
= NULL
;
1235 result
= pRtlFindCharInUnicodeString(find_ch_in_ustr
[test_num
].flags
, &main_str
, &search_chars
, &pos
);
1236 ok(result
== find_ch_in_ustr
[test_num
].result
,
1237 "(test %d): RtlFindCharInUnicodeString(%d, %s, %s, [out]) has result %x, expected %x\n",
1238 test_num
, find_ch_in_ustr
[test_num
].flags
,
1239 find_ch_in_ustr
[test_num
].main_str
, find_ch_in_ustr
[test_num
].search_chars
,
1240 result
, find_ch_in_ustr
[test_num
].result
);
1241 ok(pos
== find_ch_in_ustr
[test_num
].pos
,
1242 "(test %d): RtlFindCharInUnicodeString(%d, %s, %s, [out]) assigns %d to pos, expected %d\n",
1243 test_num
, find_ch_in_ustr
[test_num
].flags
,
1244 find_ch_in_ustr
[test_num
].main_str
, find_ch_in_ustr
[test_num
].search_chars
,
1245 pos
, find_ch_in_ustr
[test_num
].pos
);
1254 NTSTATUS result
, alternative
;
1257 static const str2int_t str2int
[] = {
1258 { 0, "1011101100", 1011101100, STATUS_SUCCESS
},
1259 { 0, "1234567", 1234567, STATUS_SUCCESS
},
1260 { 0, "-214", -214, STATUS_SUCCESS
},
1261 { 0, "+214", 214, STATUS_SUCCESS
}, /* The + sign is allowed also */
1262 { 0, "--214", 0, STATUS_SUCCESS
}, /* Do not accept more than one sign */
1263 { 0, "-+214", 0, STATUS_SUCCESS
},
1264 { 0, "++214", 0, STATUS_SUCCESS
},
1265 { 0, "+-214", 0, STATUS_SUCCESS
},
1266 { 0, "\001\002\003\00411", 11, STATUS_SUCCESS
}, /* whitespace char 1 to 4 */
1267 { 0, "\005\006\007\01012", 12, STATUS_SUCCESS
}, /* whitespace char 5 to 8 */
1268 { 0, "\011\012\013\01413", 13, STATUS_SUCCESS
}, /* whitespace char 9 to 12 */
1269 { 0, "\015\016\017\02014", 14, STATUS_SUCCESS
}, /* whitespace char 13 to 16 */
1270 { 0, "\021\022\023\02415", 15, STATUS_SUCCESS
}, /* whitespace char 17 to 20 */
1271 { 0, "\025\026\027\03016", 16, STATUS_SUCCESS
}, /* whitespace char 21 to 24 */
1272 { 0, "\031\032\033\03417", 17, STATUS_SUCCESS
}, /* whitespace char 25 to 28 */
1273 { 0, "\035\036\037\04018", 18, STATUS_SUCCESS
}, /* whitespace char 29 to 32 */
1274 { 0, " \n \r \t214", 214, STATUS_SUCCESS
},
1275 { 0, " \n \r \t+214", 214, STATUS_SUCCESS
}, /* Signs can be used after whitespace */
1276 { 0, " \n \r \t-214", -214, STATUS_SUCCESS
},
1277 { 0, "+214 0", 214, STATUS_SUCCESS
}, /* Space terminates the number */
1278 { 0, " 214.01", 214, STATUS_SUCCESS
}, /* Decimal point not accepted */
1279 { 0, " 214,01", 214, STATUS_SUCCESS
}, /* Decimal comma not accepted */
1280 { 0, "f81", 0, STATUS_SUCCESS
},
1281 { 0, "0x12345", 0x12345, STATUS_SUCCESS
}, /* Hex */
1282 { 0, "00x12345", 0, STATUS_SUCCESS
},
1283 { 0, "0xx12345", 0, STATUS_SUCCESS
},
1284 { 0, "1x34", 1, STATUS_SUCCESS
},
1285 { 0, "-9999999999", -1410065407, STATUS_SUCCESS
}, /* Big negative integer */
1286 { 0, "-2147483649", 2147483647, STATUS_SUCCESS
}, /* Too small to fit in 32 Bits */
1287 { 0, "-2147483648", 0x80000000L
, STATUS_SUCCESS
}, /* Smallest negative integer */
1288 { 0, "-2147483647", -2147483647, STATUS_SUCCESS
},
1289 { 0, "-1", -1, STATUS_SUCCESS
},
1290 { 0, "0", 0, STATUS_SUCCESS
},
1291 { 0, "1", 1, STATUS_SUCCESS
},
1292 { 0, "2147483646", 2147483646, STATUS_SUCCESS
},
1293 { 0, "2147483647", 2147483647, STATUS_SUCCESS
}, /* Largest signed positive integer */
1294 { 0, "2147483648", 0x80000000L
, STATUS_SUCCESS
}, /* Positive int equal to smallest negative int */
1295 { 0, "2147483649", -2147483647, STATUS_SUCCESS
},
1296 { 0, "4294967294", -2, STATUS_SUCCESS
},
1297 { 0, "4294967295", -1, STATUS_SUCCESS
}, /* Largest unsigned integer */
1298 { 0, "4294967296", 0, STATUS_SUCCESS
}, /* Too big to fit in 32 Bits */
1299 { 0, "9999999999", 1410065407, STATUS_SUCCESS
}, /* Big positive integer */
1300 { 0, "056789", 56789, STATUS_SUCCESS
}, /* Leading zero and still decimal */
1301 { 0, "b1011101100", 0, STATUS_SUCCESS
}, /* Binary (b-notation) */
1302 { 0, "-b1011101100", 0, STATUS_SUCCESS
}, /* Negative Binary (b-notation) */
1303 { 0, "b10123456789", 0, STATUS_SUCCESS
}, /* Binary with nonbinary digits (2-9) */
1304 { 0, "0b1011101100", 748, STATUS_SUCCESS
}, /* Binary (0b-notation) */
1305 { 0, "-0b1011101100", -748, STATUS_SUCCESS
}, /* Negative binary (0b-notation) */
1306 { 0, "0b10123456789", 5, STATUS_SUCCESS
}, /* Binary with nonbinary digits (2-9) */
1307 { 0, "-0b10123456789", -5, STATUS_SUCCESS
}, /* Negative binary with nonbinary digits (2-9) */
1308 { 0, "0b1", 1, STATUS_SUCCESS
}, /* one digit binary */
1309 { 0, "0b2", 0, STATUS_SUCCESS
}, /* empty binary */
1310 { 0, "0b", 0, STATUS_SUCCESS
}, /* empty binary */
1311 { 0, "o1234567", 0, STATUS_SUCCESS
}, /* Octal (o-notation) */
1312 { 0, "-o1234567", 0, STATUS_SUCCESS
}, /* Negative Octal (o-notation) */
1313 { 0, "o56789", 0, STATUS_SUCCESS
}, /* Octal with nonoctal digits (8 and 9) */
1314 { 0, "0o1234567", 01234567, STATUS_SUCCESS
}, /* Octal (0o-notation) */
1315 { 0, "-0o1234567", -01234567, STATUS_SUCCESS
}, /* Negative octal (0o-notation) */
1316 { 0, "0o56789", 0567, STATUS_SUCCESS
}, /* Octal with nonoctal digits (8 and 9) */
1317 { 0, "-0o56789", -0567, STATUS_SUCCESS
}, /* Negative octal with nonoctal digits (8 and 9) */
1318 { 0, "0o7", 7, STATUS_SUCCESS
}, /* one digit octal */
1319 { 0, "0o8", 0, STATUS_SUCCESS
}, /* empty octal */
1320 { 0, "0o", 0, STATUS_SUCCESS
}, /* empty octal */
1321 { 0, "0d1011101100", 0, STATUS_SUCCESS
}, /* explicit decimal with 0d */
1322 { 0, "x89abcdef", 0, STATUS_SUCCESS
}, /* Hex with lower case digits a-f (x-notation) */
1323 { 0, "xFEDCBA00", 0, STATUS_SUCCESS
}, /* Hex with upper case digits A-F (x-notation) */
1324 { 0, "-xFEDCBA00", 0, STATUS_SUCCESS
}, /* Negative Hexadecimal (x-notation) */
1325 { 0, "0x89abcdef", 0x89abcdef, STATUS_SUCCESS
}, /* Hex with lower case digits a-f (0x-notation) */
1326 { 0, "0xFEDCBA00", 0xFEDCBA00, STATUS_SUCCESS
}, /* Hex with upper case digits A-F (0x-notation) */
1327 { 0, "-0xFEDCBA00", 19088896, STATUS_SUCCESS
}, /* Negative Hexadecimal (0x-notation) */
1328 { 0, "0xabcdefgh", 0xabcdef, STATUS_SUCCESS
}, /* Hex with illegal lower case digits (g-z) */
1329 { 0, "0xABCDEFGH", 0xABCDEF, STATUS_SUCCESS
}, /* Hex with illegal upper case digits (G-Z) */
1330 { 0, "0xF", 0xf, STATUS_SUCCESS
}, /* one digit hexadecimal */
1331 { 0, "0xG", 0, STATUS_SUCCESS
}, /* empty hexadecimal */
1332 { 0, "0x", 0, STATUS_SUCCESS
}, /* empty hexadecimal */
1333 { 0, "", 0, STATUS_SUCCESS
, STATUS_INVALID_PARAMETER
}, /* empty string */
1334 { 2, "1011101100", 748, STATUS_SUCCESS
},
1335 { 2, "-1011101100", -748, STATUS_SUCCESS
},
1336 { 2, "2", 0, STATUS_SUCCESS
},
1337 { 2, "0b1011101100", 0, STATUS_SUCCESS
},
1338 { 2, "0o1011101100", 0, STATUS_SUCCESS
},
1339 { 2, "0d1011101100", 0, STATUS_SUCCESS
},
1340 { 2, "0x1011101100", 0, STATUS_SUCCESS
},
1341 { 2, "", 0, STATUS_SUCCESS
, STATUS_INVALID_PARAMETER
}, /* empty string */
1342 { 8, "1011101100", 136610368, STATUS_SUCCESS
},
1343 { 8, "-1011101100", -136610368, STATUS_SUCCESS
},
1344 { 8, "8", 0, STATUS_SUCCESS
},
1345 { 8, "0b1011101100", 0, STATUS_SUCCESS
},
1346 { 8, "0o1011101100", 0, STATUS_SUCCESS
},
1347 { 8, "0d1011101100", 0, STATUS_SUCCESS
},
1348 { 8, "0x1011101100", 0, STATUS_SUCCESS
},
1349 { 8, "", 0, STATUS_SUCCESS
, STATUS_INVALID_PARAMETER
}, /* empty string */
1350 {10, "1011101100", 1011101100, STATUS_SUCCESS
},
1351 {10, "-1011101100", -1011101100, STATUS_SUCCESS
},
1352 {10, "0b1011101100", 0, STATUS_SUCCESS
},
1353 {10, "0o1011101100", 0, STATUS_SUCCESS
},
1354 {10, "0d1011101100", 0, STATUS_SUCCESS
},
1355 {10, "0x1011101100", 0, STATUS_SUCCESS
},
1356 {10, "o12345", 0, STATUS_SUCCESS
}, /* Octal although base is 10 */
1357 {10, "", 0, STATUS_SUCCESS
, STATUS_INVALID_PARAMETER
}, /* empty string */
1358 {16, "1011101100", 286265600, STATUS_SUCCESS
},
1359 {16, "-1011101100", -286265600, STATUS_SUCCESS
},
1360 {16, "G", 0, STATUS_SUCCESS
},
1361 {16, "g", 0, STATUS_SUCCESS
},
1362 {16, "0b1011101100", 286265600, STATUS_SUCCESS
},
1363 {16, "0o1011101100", 0, STATUS_SUCCESS
},
1364 {16, "0d1011101100", 286265600, STATUS_SUCCESS
},
1365 {16, "0x1011101100", 0, STATUS_SUCCESS
},
1366 {16, "", 0, STATUS_SUCCESS
, STATUS_INVALID_PARAMETER
}, /* empty string */
1367 {20, "0", 0, STATUS_INVALID_PARAMETER
}, /* illegal base */
1368 {-8, "0", 0, STATUS_INVALID_PARAMETER
}, /* Negative base */
1369 /* { 0, NULL, 0, STATUS_SUCCESS}, */ /* NULL as string */
1371 #define NB_STR2INT (sizeof(str2int)/sizeof(*str2int))
1374 static void test_RtlUnicodeStringToInteger(void)
1376 unsigned int test_num
;
1382 for (test_num
= 0; test_num
< NB_STR2INT
; test_num
++) {
1383 wstr
= AtoW(str2int
[test_num
].str
);
1385 pRtlInitUnicodeString(&uni
, wstr
);
1386 result
= pRtlUnicodeStringToInteger(&uni
, str2int
[test_num
].base
, &value
);
1387 ok(result
== str2int
[test_num
].result
||
1388 (str2int
[test_num
].alternative
&& result
== str2int
[test_num
].alternative
),
1389 "(test %d): RtlUnicodeStringToInteger(\"%s\", %d, [out]) has result %x, expected: %x (%x)\n",
1390 test_num
, str2int
[test_num
].str
, str2int
[test_num
].base
, result
,
1391 str2int
[test_num
].result
, str2int
[test_num
].alternative
);
1392 if (result
== STATUS_SUCCESS
)
1393 ok(value
== str2int
[test_num
].value
||
1394 broken(str2int
[test_num
].str
[0] == '\0' && str2int
[test_num
].base
== 16), /* nt4 */
1395 "(test %d): RtlUnicodeStringToInteger(\"%s\", %d, [out]) assigns value %d, expected: %d\n",
1396 test_num
, str2int
[test_num
].str
, str2int
[test_num
].base
, value
, str2int
[test_num
].value
);
1398 ok(value
== 0xdeadbeef || value
== 0 /* vista */,
1399 "(test %d): RtlUnicodeStringToInteger(\"%s\", %d, [out]) assigns value %d, expected 0 or deadbeef\n",
1400 test_num
, str2int
[test_num
].str
, str2int
[test_num
].base
, value
);
1401 HeapFree(GetProcessHeap(), 0, wstr
);
1404 wstr
= AtoW(str2int
[1].str
);
1405 pRtlInitUnicodeString(&uni
, wstr
);
1406 result
= pRtlUnicodeStringToInteger(&uni
, str2int
[1].base
, NULL
);
1407 ok(result
== STATUS_ACCESS_VIOLATION
,
1408 "call failed: RtlUnicodeStringToInteger(\"%s\", %d, NULL) has result %x\n",
1409 str2int
[1].str
, str2int
[1].base
, result
);
1410 result
= pRtlUnicodeStringToInteger(&uni
, 20, NULL
);
1411 ok(result
== STATUS_INVALID_PARAMETER
|| result
== STATUS_ACCESS_VIOLATION
,
1412 "call failed: RtlUnicodeStringToInteger(\"%s\", 20, NULL) has result %x\n",
1413 str2int
[1].str
, result
);
1415 uni
.Length
= 10; /* Make Length shorter (5 WCHARS instead of 7) */
1416 result
= pRtlUnicodeStringToInteger(&uni
, str2int
[1].base
, &value
);
1417 ok(result
== STATUS_SUCCESS
,
1418 "call failed: RtlUnicodeStringToInteger(\"12345\", %d, [out]) has result %x\n",
1419 str2int
[1].base
, result
);
1421 "didn't return expected value (test a): expected: %d, got: %d\n",
1424 uni
.Length
= 5; /* Use odd Length (2.5 WCHARS) */
1425 result
= pRtlUnicodeStringToInteger(&uni
, str2int
[1].base
, &value
);
1426 ok(result
== STATUS_SUCCESS
|| result
== STATUS_INVALID_PARAMETER
/* vista */,
1427 "call failed: RtlUnicodeStringToInteger(\"12\", %d, [out]) has result %x\n",
1428 str2int
[1].base
, result
);
1429 if (result
== STATUS_SUCCESS
)
1430 ok(value
== 12, "didn't return expected value (test b): expected: %d, got: %d\n", 12, value
);
1433 result
= pRtlUnicodeStringToInteger(&uni
, str2int
[1].base
, &value
);
1434 ok(result
== STATUS_SUCCESS
,
1435 "call failed: RtlUnicodeStringToInteger(\"1\", %d, [out]) has result %x\n",
1436 str2int
[1].base
, result
);
1438 "didn't return expected value (test c): expected: %d, got: %d\n",
1440 /* w2k: uni.Length = 0 returns value 11234567 instead of 0 */
1441 HeapFree(GetProcessHeap(), 0, wstr
);
1445 static void test_RtlCharToInteger(void)
1447 unsigned int test_num
;
1451 for (test_num
= 0; test_num
< NB_STR2INT
; test_num
++) {
1452 /* w2k skips a leading '\0' and processes the string after */
1453 if (str2int
[test_num
].str
[0] != '\0') {
1455 result
= pRtlCharToInteger(str2int
[test_num
].str
, str2int
[test_num
].base
, &value
);
1456 ok(result
== str2int
[test_num
].result
||
1457 (str2int
[test_num
].alternative
&& result
== str2int
[test_num
].alternative
),
1458 "(test %d): call failed: RtlCharToInteger(\"%s\", %d, [out]) has result %x, expected: %x (%x)\n",
1459 test_num
, str2int
[test_num
].str
, str2int
[test_num
].base
, result
,
1460 str2int
[test_num
].result
, str2int
[test_num
].alternative
);
1461 if (result
== STATUS_SUCCESS
)
1462 ok(value
== str2int
[test_num
].value
,
1463 "(test %d): call failed: RtlCharToInteger(\"%s\", %d, [out]) assigns value %d, expected: %d\n",
1464 test_num
, str2int
[test_num
].str
, str2int
[test_num
].base
, value
, str2int
[test_num
].value
);
1466 ok(value
== 0 || value
== 0xdeadbeef,
1467 "(test %d): call failed: RtlCharToInteger(\"%s\", %d, [out]) assigns value %d, expected 0 or deadbeef\n",
1468 test_num
, str2int
[test_num
].str
, str2int
[test_num
].base
, value
);
1472 result
= pRtlCharToInteger(str2int
[1].str
, str2int
[1].base
, NULL
);
1473 ok(result
== STATUS_ACCESS_VIOLATION
,
1474 "call failed: RtlCharToInteger(\"%s\", %d, NULL) has result %x\n",
1475 str2int
[1].str
, str2int
[1].base
, result
);
1477 result
= pRtlCharToInteger(str2int
[1].str
, 20, NULL
);
1478 ok(result
== STATUS_INVALID_PARAMETER
,
1479 "call failed: RtlCharToInteger(\"%s\", 20, NULL) has result %x\n",
1480 str2int
[1].str
, result
);
1484 #define STRI_BUFFER_LENGTH 35
1490 USHORT MaximumLength
;
1495 static const int2str_t int2str
[] = {
1496 {10, 123, 3, 11, "123\0-------------------------------", STATUS_SUCCESS
},
1498 { 0, 0x80000000U
, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS
}, /* min signed int */
1499 { 0, -2147483647, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS
},
1500 { 0, -2, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS
},
1501 { 0, -1, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS
},
1502 { 0, 0, 1, 11, "0\0---------------------------------", STATUS_SUCCESS
},
1503 { 0, 1, 1, 11, "1\0---------------------------------", STATUS_SUCCESS
},
1504 { 0, 12, 2, 11, "12\0--------------------------------", STATUS_SUCCESS
},
1505 { 0, 123, 3, 11, "123\0-------------------------------", STATUS_SUCCESS
},
1506 { 0, 1234, 4, 11, "1234\0------------------------------", STATUS_SUCCESS
},
1507 { 0, 12345, 5, 11, "12345\0-----------------------------", STATUS_SUCCESS
},
1508 { 0, 123456, 6, 11, "123456\0----------------------------", STATUS_SUCCESS
},
1509 { 0, 1234567, 7, 11, "1234567\0---------------------------", STATUS_SUCCESS
},
1510 { 0, 12345678, 8, 11, "12345678\0--------------------------", STATUS_SUCCESS
},
1511 { 0, 123456789, 9, 11, "123456789\0-------------------------", STATUS_SUCCESS
},
1512 { 0, 2147483646, 10, 11, "2147483646\0------------------------", STATUS_SUCCESS
},
1513 { 0, 2147483647, 10, 11, "2147483647\0------------------------", STATUS_SUCCESS
}, /* max signed int */
1514 { 0, 2147483648U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS
}, /* uint = -max int */
1515 { 0, 2147483649U, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS
},
1516 { 0, 4294967294U, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS
},
1517 { 0, 4294967295U, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS
}, /* max unsigned int */
1519 { 2, 0x80000000U
, 32, 33, "10000000000000000000000000000000\0--", STATUS_SUCCESS
}, /* min signed int */
1520 { 2, -2147483647, 32, 33, "10000000000000000000000000000001\0--", STATUS_SUCCESS
},
1521 { 2, -2, 32, 33, "11111111111111111111111111111110\0--", STATUS_SUCCESS
},
1522 { 2, -1, 32, 33, "11111111111111111111111111111111\0--", STATUS_SUCCESS
},
1523 { 2, 0, 1, 33, "0\0---------------------------------", STATUS_SUCCESS
},
1524 { 2, 1, 1, 33, "1\0---------------------------------", STATUS_SUCCESS
},
1525 { 2, 10, 4, 33, "1010\0------------------------------", STATUS_SUCCESS
},
1526 { 2, 100, 7, 33, "1100100\0---------------------------", STATUS_SUCCESS
},
1527 { 2, 1000, 10, 33, "1111101000\0------------------------", STATUS_SUCCESS
},
1528 { 2, 10000, 14, 33, "10011100010000\0--------------------", STATUS_SUCCESS
},
1529 { 2, 32767, 15, 33, "111111111111111\0-------------------", STATUS_SUCCESS
},
1530 /* { 2, 32768, 16, 33, "1000000000000000\0------------------", STATUS_SUCCESS}, broken on windows */
1531 /* { 2, 65535, 16, 33, "1111111111111111\0------------------", STATUS_SUCCESS}, broken on windows */
1532 { 2, 65536, 17, 33, "10000000000000000\0-----------------", STATUS_SUCCESS
},
1533 { 2, 100000, 17, 33, "11000011010100000\0-----------------", STATUS_SUCCESS
},
1534 { 2, 1000000, 20, 33, "11110100001001000000\0--------------", STATUS_SUCCESS
},
1535 { 2, 10000000, 24, 33, "100110001001011010000000\0----------", STATUS_SUCCESS
},
1536 { 2, 100000000, 27, 33, "101111101011110000100000000\0-------", STATUS_SUCCESS
},
1537 { 2, 1000000000, 30, 33, "111011100110101100101000000000\0----", STATUS_SUCCESS
},
1538 { 2, 1073741823, 30, 33, "111111111111111111111111111111\0----", STATUS_SUCCESS
},
1539 { 2, 2147483646, 31, 33, "1111111111111111111111111111110\0---", STATUS_SUCCESS
},
1540 { 2, 2147483647, 31, 33, "1111111111111111111111111111111\0---", STATUS_SUCCESS
}, /* max signed int */
1541 { 2, 2147483648U, 32, 33, "10000000000000000000000000000000\0--", STATUS_SUCCESS
}, /* uint = -max int */
1542 { 2, 2147483649U, 32, 33, "10000000000000000000000000000001\0--", STATUS_SUCCESS
},
1543 { 2, 4294967294U, 32, 33, "11111111111111111111111111111110\0--", STATUS_SUCCESS
},
1544 { 2, 4294967295U, 32, 33, "11111111111111111111111111111111\0--", STATUS_SUCCESS
}, /* max unsigned int */
1546 { 8, 0x80000000U
, 11, 12, "20000000000\0-----------------------", STATUS_SUCCESS
}, /* min signed int */
1547 { 8, -2147483647, 11, 12, "20000000001\0-----------------------", STATUS_SUCCESS
},
1548 { 8, -2, 11, 12, "37777777776\0-----------------------", STATUS_SUCCESS
},
1549 { 8, -1, 11, 12, "37777777777\0-----------------------", STATUS_SUCCESS
},
1550 { 8, 0, 1, 12, "0\0---------------------------------", STATUS_SUCCESS
},
1551 { 8, 1, 1, 12, "1\0---------------------------------", STATUS_SUCCESS
},
1552 { 8, 2147483646, 11, 12, "17777777776\0-----------------------", STATUS_SUCCESS
},
1553 { 8, 2147483647, 11, 12, "17777777777\0-----------------------", STATUS_SUCCESS
}, /* max signed int */
1554 { 8, 2147483648U, 11, 12, "20000000000\0-----------------------", STATUS_SUCCESS
}, /* uint = -max int */
1555 { 8, 2147483649U, 11, 12, "20000000001\0-----------------------", STATUS_SUCCESS
},
1556 { 8, 4294967294U, 11, 12, "37777777776\0-----------------------", STATUS_SUCCESS
},
1557 { 8, 4294967295U, 11, 12, "37777777777\0-----------------------", STATUS_SUCCESS
}, /* max unsigned int */
1559 {10, 0x80000000U
, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS
}, /* min signed int */
1560 {10, -2147483647, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS
},
1561 {10, -2, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS
},
1562 {10, -1, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS
},
1563 {10, 0, 1, 11, "0\0---------------------------------", STATUS_SUCCESS
},
1564 {10, 1, 1, 11, "1\0---------------------------------", STATUS_SUCCESS
},
1565 {10, 2147483646, 10, 11, "2147483646\0------------------------", STATUS_SUCCESS
},
1566 {10, 2147483647, 10, 11, "2147483647\0------------------------", STATUS_SUCCESS
}, /* max signed int */
1567 {10, 2147483648U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS
}, /* uint = -max int */
1568 {10, 2147483649U, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS
},
1569 {10, 4294967294U, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS
},
1570 {10, 4294967295U, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS
}, /* max unsigned int */
1572 {16, 0x80000000U
, 8, 9, "80000000\0--------------------------", STATUS_SUCCESS
}, /* min signed int */
1573 {16, -2147483647, 8, 9, "80000001\0--------------------------", STATUS_SUCCESS
},
1574 {16, -2, 8, 9, "FFFFFFFE\0--------------------------", STATUS_SUCCESS
},
1575 {16, -1, 8, 9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS
},
1576 {16, 0, 1, 9, "0\0---------------------------------", STATUS_SUCCESS
},
1577 {16, 1, 1, 9, "1\0---------------------------------", STATUS_SUCCESS
},
1578 {16, 2147483646, 8, 9, "7FFFFFFE\0--------------------------", STATUS_SUCCESS
},
1579 {16, 2147483647, 8, 9, "7FFFFFFF\0--------------------------", STATUS_SUCCESS
}, /* max signed int */
1580 {16, 2147483648U, 8, 9, "80000000\0--------------------------", STATUS_SUCCESS
}, /* uint = -max int */
1581 {16, 2147483649U, 8, 9, "80000001\0--------------------------", STATUS_SUCCESS
},
1582 {16, 4294967294U, 8, 9, "FFFFFFFE\0--------------------------", STATUS_SUCCESS
},
1583 {16, 4294967295U, 8, 9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS
}, /* max unsigned int */
1585 /* { 2, 32768, 16, 17, "1000000000000000\0------------------", STATUS_SUCCESS}, broken on windows */
1586 /* { 2, 32768, 16, 16, "1000000000000000-------------------", STATUS_SUCCESS}, broken on windows */
1587 { 2, 65536, 17, 18, "10000000000000000\0-----------------", STATUS_SUCCESS
},
1588 { 2, 65536, 17, 17, "10000000000000000------------------", STATUS_SUCCESS
},
1589 { 2, 131072, 18, 19, "100000000000000000\0----------------", STATUS_SUCCESS
},
1590 { 2, 131072, 18, 18, "100000000000000000-----------------", STATUS_SUCCESS
},
1591 {16, 0xffffffff, 8, 9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS
},
1592 {16, 0xffffffff, 8, 8, "FFFFFFFF---------------------------", STATUS_SUCCESS
}, /* No \0 term */
1593 {16, 0xffffffff, 8, 7, "-----------------------------------", STATUS_BUFFER_OVERFLOW
}, /* Too short */
1594 {16, 0xa, 1, 2, "A\0---------------------------------", STATUS_SUCCESS
},
1595 {16, 0xa, 1, 1, "A----------------------------------", STATUS_SUCCESS
}, /* No \0 term */
1596 {16, 0, 1, 0, "-----------------------------------", STATUS_BUFFER_OVERFLOW
},
1597 {20, 0xdeadbeef, 0, 9, "-----------------------------------", STATUS_INVALID_PARAMETER
}, /* ill. base */
1598 {-8, 07654321, 0, 12, "-----------------------------------", STATUS_INVALID_PARAMETER
}, /* neg. base */
1600 #define NB_INT2STR (sizeof(int2str)/sizeof(*int2str))
1603 static void one_RtlIntegerToUnicodeString_test(int test_num
, const int2str_t
*int2str
)
1606 WCHAR expected_str_Buffer
[STRI_BUFFER_LENGTH
+ 1];
1607 UNICODE_STRING expected_unicode_string
;
1608 STRING expected_ansi_str
;
1609 WCHAR str_Buffer
[STRI_BUFFER_LENGTH
+ 1];
1610 UNICODE_STRING unicode_string
;
1614 for (pos
= 0; pos
< STRI_BUFFER_LENGTH
; pos
++) {
1615 expected_str_Buffer
[pos
] = int2str
->Buffer
[pos
];
1617 expected_unicode_string
.Length
= int2str
->Length
* sizeof(WCHAR
);
1618 expected_unicode_string
.MaximumLength
= int2str
->MaximumLength
* sizeof(WCHAR
);
1619 expected_unicode_string
.Buffer
= expected_str_Buffer
;
1620 pRtlUnicodeStringToAnsiString(&expected_ansi_str
, &expected_unicode_string
, 1);
1622 for (pos
= 0; pos
< STRI_BUFFER_LENGTH
; pos
++) {
1623 str_Buffer
[pos
] = '-';
1625 unicode_string
.Length
= 0;
1626 unicode_string
.MaximumLength
= int2str
->MaximumLength
* sizeof(WCHAR
);
1627 unicode_string
.Buffer
= str_Buffer
;
1629 result
= pRtlIntegerToUnicodeString(int2str
->value
, int2str
->base
, &unicode_string
);
1630 pRtlUnicodeStringToAnsiString(&ansi_str
, &unicode_string
, 1);
1631 if (result
== STATUS_BUFFER_OVERFLOW
) {
1632 /* On BUFFER_OVERFLOW the string Buffer should be unchanged */
1633 for (pos
= 0; pos
< STRI_BUFFER_LENGTH
; pos
++) {
1634 expected_str_Buffer
[pos
] = '-';
1636 /* w2k: The native function has two reasons for BUFFER_OVERFLOW: */
1637 /* If the value is too large to convert: The Length is unchanged */
1638 /* If str is too small to hold the string: Set str->Length to the length */
1639 /* the string would have (which can be larger than the MaximumLength). */
1640 /* To allow all this in the tests we do the following: */
1641 if (expected_unicode_string
.Length
> 32 && unicode_string
.Length
== 0) {
1642 /* The value is too large to convert only triggered when testing native */
1643 expected_unicode_string
.Length
= 0;
1646 ok(result
== int2str
->result
,
1647 "(test %d): RtlIntegerToUnicodeString(%u, %d, [out]) has result %x, expected: %x\n",
1648 test_num
, int2str
->value
, int2str
->base
, result
, int2str
->result
);
1649 if (result
== STATUS_SUCCESS
) {
1650 ok(unicode_string
.Buffer
[unicode_string
.Length
/sizeof(WCHAR
)] == '\0',
1651 "(test %d): RtlIntegerToUnicodeString(%u, %d, [out]) string \"%s\" is not NULL terminated\n",
1652 test_num
, int2str
->value
, int2str
->base
, ansi_str
.Buffer
);
1655 ok(memcmp(unicode_string
.Buffer
, expected_unicode_string
.Buffer
, STRI_BUFFER_LENGTH
* sizeof(WCHAR
)) == 0,
1656 "(test %d): RtlIntegerToUnicodeString(%u, %d, [out]) assigns string \"%s\", expected: \"%s\"\n",
1657 test_num
, int2str
->value
, int2str
->base
, ansi_str
.Buffer
, expected_ansi_str
.Buffer
);
1658 ok(unicode_string
.Length
== expected_unicode_string
.Length
,
1659 "(test %d): RtlIntegerToUnicodeString(%u, %d, [out]) string has Length %d, expected: %d\n",
1660 test_num
, int2str
->value
, int2str
->base
, unicode_string
.Length
, expected_unicode_string
.Length
);
1661 ok(unicode_string
.MaximumLength
== expected_unicode_string
.MaximumLength
,
1662 "(test %d): RtlIntegerToUnicodeString(%u, %d, [out]) string has MaximumLength %d, expected: %d\n",
1663 test_num
, int2str
->value
, int2str
->base
, unicode_string
.MaximumLength
, expected_unicode_string
.MaximumLength
);
1664 pRtlFreeAnsiString(&expected_ansi_str
);
1665 pRtlFreeAnsiString(&ansi_str
);
1669 static void test_RtlIntegerToUnicodeString(void)
1673 for (test_num
= 0; test_num
< NB_INT2STR
; test_num
++)
1674 one_RtlIntegerToUnicodeString_test(test_num
, &int2str
[test_num
]);
1678 static void one_RtlIntegerToChar_test(int test_num
, const int2str_t
*int2str
)
1681 char dest_str
[STRI_BUFFER_LENGTH
+ 1];
1683 memset(dest_str
, '-', STRI_BUFFER_LENGTH
);
1684 dest_str
[STRI_BUFFER_LENGTH
] = '\0';
1685 result
= pRtlIntegerToChar(int2str
->value
, int2str
->base
, int2str
->MaximumLength
, dest_str
);
1686 ok(result
== int2str
->result
,
1687 "(test %d): RtlIntegerToChar(%u, %d, %d, [out]) has result %x, expected: %x\n",
1688 test_num
, int2str
->value
, int2str
->base
, int2str
->MaximumLength
, result
, int2str
->result
);
1689 ok(memcmp(dest_str
, int2str
->Buffer
, STRI_BUFFER_LENGTH
) == 0,
1690 "(test %d): RtlIntegerToChar(%u, %d, %d, [out]) assigns string \"%s\", expected: \"%s\"\n",
1691 test_num
, int2str
->value
, int2str
->base
, int2str
->MaximumLength
, dest_str
, int2str
->Buffer
);
1695 static void test_RtlIntegerToChar(void)
1700 for (test_num
= 0; test_num
< NB_INT2STR
; test_num
++)
1701 one_RtlIntegerToChar_test(test_num
, &int2str
[test_num
]);
1703 result
= pRtlIntegerToChar(int2str
[0].value
, 20, int2str
[0].MaximumLength
, NULL
);
1704 ok(result
== STATUS_INVALID_PARAMETER
,
1705 "(test a): RtlIntegerToChar(%u, %d, %d, NULL) has result %x, expected: %x\n",
1706 int2str
[0].value
, 20, int2str
[0].MaximumLength
, result
, STATUS_INVALID_PARAMETER
);
1708 result
= pRtlIntegerToChar(int2str
[0].value
, 20, 0, NULL
);
1709 ok(result
== STATUS_INVALID_PARAMETER
,
1710 "(test b): RtlIntegerToChar(%u, %d, %d, NULL) has result %x, expected: %x\n",
1711 int2str
[0].value
, 20, 0, result
, STATUS_INVALID_PARAMETER
);
1713 result
= pRtlIntegerToChar(int2str
[0].value
, int2str
[0].base
, 0, NULL
);
1714 ok(result
== STATUS_BUFFER_OVERFLOW
,
1715 "(test c): RtlIntegerToChar(%u, %d, %d, NULL) has result %x, expected: %x\n",
1716 int2str
[0].value
, int2str
[0].base
, 0, result
, STATUS_BUFFER_OVERFLOW
);
1718 result
= pRtlIntegerToChar(int2str
[0].value
, int2str
[0].base
, int2str
[0].MaximumLength
, NULL
);
1719 ok(result
== STATUS_ACCESS_VIOLATION
,
1720 "(test d): RtlIntegerToChar(%u, %d, %d, NULL) has result %x, expected: %x\n",
1721 int2str
[0].value
, int2str
[0].base
, int2str
[0].MaximumLength
, result
, STATUS_ACCESS_VIOLATION
);
1724 static void test_RtlIsTextUnicode(void)
1726 char ascii
[] = "A simple string";
1727 char false_positive
[] = {0x41, 0x0a, 0x0d, 0x1d};
1728 WCHAR false_negative
= 0x0d0a;
1729 WCHAR unicode
[] = {'A',' ','U','n','i','c','o','d','e',' ','s','t','r','i','n','g',0};
1730 WCHAR unicode_no_controls
[] = {'A','U','n','i','c','o','d','e','s','t','r','i','n','g',0};
1731 /* String with both byte-reversed and standard Unicode control characters. */
1732 WCHAR mixed_controls
[] = {'\t',0x9000,0x0d00,'\n',0};
1734 WCHAR
*be_unicode_no_controls
;
1739 if (!pRtlIsTextUnicode
)
1741 win_skip("RtlIsTextUnicode is not available\n");
1745 ok(!pRtlIsTextUnicode(ascii
, sizeof(ascii
), NULL
), "ASCII text detected as Unicode\n");
1747 res
= pRtlIsTextUnicode(unicode
, sizeof(unicode
), NULL
);
1749 broken(res
== FALSE
), /* NT4 */
1750 "Text should be Unicode\n");
1752 ok(!pRtlIsTextUnicode(unicode
, sizeof(unicode
) - 1, NULL
), "Text should be Unicode\n");
1754 flags
= IS_TEXT_UNICODE_UNICODE_MASK
;
1755 ok(pRtlIsTextUnicode(unicode
, sizeof(unicode
), &flags
), "Text should not pass a Unicode\n");
1756 ok(flags
== (IS_TEXT_UNICODE_STATISTICS
| IS_TEXT_UNICODE_CONTROLS
),
1757 "Expected flags 0x6, obtained %x\n", flags
);
1759 flags
= IS_TEXT_UNICODE_REVERSE_MASK
;
1760 ok(!pRtlIsTextUnicode(unicode
, sizeof(unicode
), &flags
), "Text should not pass reverse Unicode tests\n");
1761 ok(flags
== 0, "Expected flags 0, obtained %x\n", flags
);
1763 flags
= IS_TEXT_UNICODE_ODD_LENGTH
;
1764 ok(!pRtlIsTextUnicode(unicode
, sizeof(unicode
) - 1, &flags
), "Odd length test should have passed\n");
1765 ok(flags
== IS_TEXT_UNICODE_ODD_LENGTH
, "Expected flags 0x200, obtained %x\n", flags
);
1767 be_unicode
= HeapAlloc(GetProcessHeap(), 0, sizeof(unicode
) + sizeof(WCHAR
));
1768 be_unicode
[0] = 0xfffe;
1769 for (i
= 0; i
< sizeof(unicode
)/sizeof(unicode
[0]); i
++)
1771 be_unicode
[i
+ 1] = (unicode
[i
] >> 8) | ((unicode
[i
] & 0xff) << 8);
1773 ok(!pRtlIsTextUnicode(be_unicode
, sizeof(unicode
) + 2, NULL
), "Reverse endian should not be Unicode\n");
1774 ok(!pRtlIsTextUnicode(&be_unicode
[1], sizeof(unicode
), NULL
), "Reverse endian should not be Unicode\n");
1776 flags
= IS_TEXT_UNICODE_REVERSE_MASK
;
1777 ok(!pRtlIsTextUnicode(&be_unicode
[1], sizeof(unicode
), &flags
), "Reverse endian should be Unicode\n");
1779 ok(flags
== (IS_TEXT_UNICODE_REVERSE_ASCII16
| IS_TEXT_UNICODE_REVERSE_STATISTICS
| IS_TEXT_UNICODE_REVERSE_CONTROLS
),
1780 "Expected flags 0x70, obtained %x\n", flags
);
1782 flags
= IS_TEXT_UNICODE_REVERSE_MASK
;
1783 ok(!pRtlIsTextUnicode(be_unicode
, sizeof(unicode
) + 2, &flags
), "Reverse endian should be Unicode\n");
1784 ok(flags
== (IS_TEXT_UNICODE_REVERSE_CONTROLS
| IS_TEXT_UNICODE_REVERSE_SIGNATURE
),
1785 "Expected flags 0xc0, obtained %x\n", flags
);
1787 /* build byte reversed unicode string with no control chars */
1788 be_unicode_no_controls
= HeapAlloc(GetProcessHeap(), 0, sizeof(unicode
) + sizeof(WCHAR
));
1789 ok(be_unicode_no_controls
!= NULL
, "Expected HeapAlloc to succeed.\n");
1790 be_unicode_no_controls
[0] = 0xfffe;
1791 for (i
= 0; i
< sizeof(unicode_no_controls
)/sizeof(unicode_no_controls
[0]); i
++)
1792 be_unicode_no_controls
[i
+ 1] = (unicode_no_controls
[i
] >> 8) | ((unicode_no_controls
[i
] & 0xff) << 8);
1795 /* The following tests verify that the tests for */
1796 /* IS_TEXT_UNICODE_CONTROLS and IS_TEXT_UNICODE_REVERSE_CONTROLS */
1797 /* are not mutually exclusive. Regardless of whether the strings */
1798 /* contain an indication of endianness, the tests are still */
1799 /* run if the flag is passed to (Rtl)IsTextUnicode. */
1801 /* Test IS_TEXT_UNICODE_CONTROLS flag */
1802 flags
= IS_TEXT_UNICODE_CONTROLS
;
1803 ok(!pRtlIsTextUnicode(unicode_no_controls
, sizeof(unicode_no_controls
), &flags
), "Test should not pass on Unicode string lacking control characters.\n");
1804 ok(flags
== 0, "Expected flags 0x0, obtained %x\n", flags
);
1806 flags
= IS_TEXT_UNICODE_CONTROLS
;
1807 ok(!pRtlIsTextUnicode(be_unicode_no_controls
, sizeof(unicode_no_controls
), &flags
), "Test should not pass on byte-reversed Unicode string lacking control characters.\n");
1808 ok(flags
== 0, "Expected flags 0x0, obtained %x\n", flags
);
1810 flags
= IS_TEXT_UNICODE_CONTROLS
;
1811 ok(pRtlIsTextUnicode(unicode
, sizeof(unicode
), &flags
), "Test should pass on Unicode string lacking control characters.\n");
1812 ok(flags
== IS_TEXT_UNICODE_CONTROLS
, "Expected flags 0x04, obtained %x\n", flags
);
1814 flags
= IS_TEXT_UNICODE_CONTROLS
;
1815 ok(!pRtlIsTextUnicode(be_unicode_no_controls
, sizeof(unicode_no_controls
) + 2, &flags
),
1816 "Test should not pass with standard Unicode string.\n");
1817 ok(flags
== 0, "Expected flags 0x0, obtained %x\n", flags
);
1819 flags
= IS_TEXT_UNICODE_CONTROLS
;
1820 ok(pRtlIsTextUnicode(mixed_controls
, sizeof(mixed_controls
), &flags
), "Test should pass on a string containing control characters.\n");
1821 ok(flags
== IS_TEXT_UNICODE_CONTROLS
, "Expected flags 0x04, obtained %x\n", flags
);
1823 /* Test IS_TEXT_UNICODE_REVERSE_CONTROLS flag */
1824 flags
= IS_TEXT_UNICODE_REVERSE_CONTROLS
;
1825 ok(!pRtlIsTextUnicode(be_unicode_no_controls
, sizeof(unicode_no_controls
), &flags
), "Test should not pass on Unicode string lacking control characters.\n");
1826 ok(flags
== 0, "Expected flags 0x0, obtained %x\n", flags
);
1828 flags
= IS_TEXT_UNICODE_REVERSE_CONTROLS
;
1829 ok(!pRtlIsTextUnicode(unicode_no_controls
, sizeof(unicode_no_controls
), &flags
), "Test should not pass on Unicode string lacking control characters.\n");
1830 ok(flags
== 0, "Expected flags 0x0, obtained %x\n", flags
);
1832 flags
= IS_TEXT_UNICODE_REVERSE_CONTROLS
;
1833 ok(!pRtlIsTextUnicode(unicode
, sizeof(unicode
), &flags
), "Test should not pass on Unicode string lacking control characters.\n");
1834 ok(flags
== 0, "Expected flags 0x0, obtained %x\n", flags
);
1836 flags
= IS_TEXT_UNICODE_REVERSE_CONTROLS
;
1837 ok(!pRtlIsTextUnicode(be_unicode
, sizeof(unicode
) + 2, &flags
),
1838 "Test should pass with byte-reversed Unicode string containing control characters.\n");
1839 ok(flags
== IS_TEXT_UNICODE_REVERSE_CONTROLS
, "Expected flags 0x40, obtained %x\n", flags
);
1841 flags
= IS_TEXT_UNICODE_REVERSE_CONTROLS
;
1842 ok(!pRtlIsTextUnicode(mixed_controls
, sizeof(mixed_controls
), &flags
), "Test should pass on a string containing byte-reversed control characters.\n");
1843 ok(flags
== IS_TEXT_UNICODE_REVERSE_CONTROLS
, "Expected flags 0x40, obtained %x\n", flags
);
1845 /* Test with flags for both byte-reverse and standard Unicode characters */
1846 flags
= IS_TEXT_UNICODE_CONTROLS
| IS_TEXT_UNICODE_REVERSE_CONTROLS
;
1847 ok(!pRtlIsTextUnicode(mixed_controls
, sizeof(mixed_controls
), &flags
), "Test should pass on string containing both byte-reversed and standard control characters.\n");
1848 ok(flags
== (IS_TEXT_UNICODE_CONTROLS
| IS_TEXT_UNICODE_REVERSE_CONTROLS
), "Expected flags 0x44, obtained %x\n", flags
);
1850 flags
= IS_TEXT_UNICODE_STATISTICS
;
1851 todo_wine
ok(pRtlIsTextUnicode(false_positive
, sizeof(false_positive
), &flags
), "Test should pass on false positive.\n");
1853 ok(!pRtlIsTextUnicode(&false_negative
, sizeof(false_negative
), NULL
), "Test should fail on 0x0d0a (MALAYALAM LETTER UU).\n");
1855 HeapFree(GetProcessHeap(), 0, be_unicode
);
1856 HeapFree(GetProcessHeap(), 0, be_unicode_no_controls
);
1859 static const WCHAR szGuid
[] = { '{','0','1','0','2','0','3','0','4','-',
1860 '0','5','0','6','-' ,'0','7','0','8','-','0','9','0','A','-',
1861 '0','B','0','C','0','D','0','E','0','F','0','A','}','\0' };
1862 static const WCHAR szGuid2
[] = { '{','0','1','0','2','0','3','0','4','-',
1863 '0','5','0','6','-' ,'0','7','0','8','-','0','9','0','A','-',
1864 '0','B','0','C','0','D','0','E','0','F','0','A',']','\0' };
1865 DEFINE_GUID(IID_Endianness
, 0x01020304, 0x0506, 0x0708, 0x09, 0x0A, 0x0B,
1866 0x0C, 0x0D, 0x0E, 0x0F, 0x0A);
1868 static void test_RtlGUIDFromString(void)
1874 if (!pRtlGUIDFromString
)
1876 win_skip("RtlGUIDFromString is not available\n");
1880 str
.Length
= str
.MaximumLength
= sizeof(szGuid
) - sizeof(WCHAR
);
1881 str
.Buffer
= (LPWSTR
)szGuid
;
1883 ret
= pRtlGUIDFromString(&str
, &guid
);
1884 ok(ret
== 0, "expected ret=0, got 0x%0x\n", ret
);
1885 ok(IsEqualGUID(&guid
, &IID_Endianness
), "Endianness broken\n");
1887 str
.Length
= str
.MaximumLength
= sizeof(szGuid2
) - sizeof(WCHAR
);
1888 str
.Buffer
= (LPWSTR
)szGuid2
;
1890 ret
= pRtlGUIDFromString(&str
, &guid
);
1891 ok(ret
, "expected ret!=0\n");
1894 static void test_RtlStringFromGUID(void)
1899 if (!pRtlStringFromGUID
)
1901 win_skip("RtlStringFromGUID is not available\n");
1905 str
.Length
= str
.MaximumLength
= 0;
1908 ret
= pRtlStringFromGUID(&IID_Endianness
, &str
);
1909 ok(ret
== 0, "expected ret=0, got 0x%0x\n", ret
);
1910 ok(str
.Buffer
&& !lstrcmpiW(str
.Buffer
, szGuid
), "Endianness broken\n");
1911 pRtlFreeUnicodeString(&str
);
1914 struct hash_unicodestring_test
{
1916 BOOLEAN case_insensitive
;
1920 static const struct hash_unicodestring_test hash_test
[] = {
1921 { {'T',0}, FALSE
, 0x00000054 },
1922 { {'T','e','s','t',0}, FALSE
, 0x766bb952 },
1923 { {'T','e','S','t',0}, FALSE
, 0x764bb172 },
1924 { {'t','e','s','t',0}, FALSE
, 0x4745d132 },
1925 { {'t','e','s','t',0}, TRUE
, 0x6689c132 },
1926 { {'T','E','S','T',0}, TRUE
, 0x6689c132 },
1927 { {'T','E','S','T',0}, FALSE
, 0x6689c132 },
1928 { {'a','b','c','d','e','f',0}, FALSE
, 0x971318c3 },
1932 static void test_RtlHashUnicodeString(void)
1934 static const WCHAR strW
[] = {'T','e','s','t',0,'1',0};
1935 const struct hash_unicodestring_test
*ptr
;
1940 if (!pRtlHashUnicodeString
)
1942 win_skip("RtlHashUnicodeString is not available\n");
1946 status
= pRtlHashUnicodeString(NULL
, FALSE
, HASH_STRING_ALGORITHM_X65599
, &hash
);
1947 ok(status
== STATUS_INVALID_PARAMETER
, "got status 0x%08x\n", status
);
1949 RtlInitUnicodeString(&str
, strW
);
1950 status
= pRtlHashUnicodeString(&str
, FALSE
, HASH_STRING_ALGORITHM_X65599
, NULL
);
1951 ok(status
== STATUS_INVALID_PARAMETER
, "got status 0x%08x\n", status
);
1953 status
= pRtlHashUnicodeString(&str
, FALSE
, HASH_STRING_ALGORITHM_INVALID
, &hash
);
1954 ok(status
== STATUS_INVALID_PARAMETER
, "got status 0x%08x\n", status
);
1957 str
.Buffer
= (PWSTR
)strW
;
1958 str
.Length
= sizeof(strW
) - sizeof(WCHAR
);
1959 str
.MaximumLength
= sizeof(strW
);
1960 status
= pRtlHashUnicodeString(&str
, FALSE
, HASH_STRING_ALGORITHM_X65599
, &hash
);
1961 ok(status
== STATUS_SUCCESS
, "got status 0x%08x\n", status
);
1962 ok(hash
== 0x32803083, "got 0x%08x\n", hash
);
1967 RtlInitUnicodeString(&str
, ptr
->str
);
1969 status
= pRtlHashUnicodeString(&str
, ptr
->case_insensitive
, HASH_STRING_ALGORITHM_X65599
, &hash
);
1970 ok(status
== STATUS_SUCCESS
, "got status 0x%08x for %s\n", status
, wine_dbgstr_w(ptr
->str
));
1971 ok(hash
== ptr
->hash
, "got wrong hash 0x%08x, expected 0x%08x, for %s, mode %d\n", hash
, ptr
->hash
,
1972 wine_dbgstr_w(ptr
->str
), ptr
->case_insensitive
);
1978 struct unicode_to_utf8_test
{
1980 const char *expected
;
1984 static const struct unicode_to_utf8_test unicode_to_utf8
[] = {
1985 { { 0 }, "", STATUS_SUCCESS
},
1986 { { '-',0 }, "-", STATUS_SUCCESS
},
1987 { { 'h','e','l','l','o',0 }, "hello", STATUS_SUCCESS
},
1988 { { '-',0x7f,'-',0x80,'-',0xff,'-',0x100,'-',0 }, "-\x7F-\xC2\x80-\xC3\xBF-\xC4\x80-", STATUS_SUCCESS
},
1989 { { '-',0x7ff,'-',0x800,'-',0 }, "-\xDF\xBF-\xE0\xA0\x80-", STATUS_SUCCESS
},
1990 { { '-',0xd7ff,'-',0xe000,'-',0 }, "-\xED\x9F\xBF-\xEE\x80\x80-", STATUS_SUCCESS
},
1992 { { '-',0xffff,'-',0xd800,0xdc00,'-',0 }, "-\xEF\xBF\xBF-\xF0\x90\x80\x80-", STATUS_SUCCESS
},
1993 /* 0x103ff */ /* 0x10400 */
1994 { { '-',0xd800,0xdfff,'-',0xd801,0xdc00,'-',0 }, "-\xF0\x90\x8F\xBF-\xF0\x90\x90\x80-", STATUS_SUCCESS
},
1996 { { '-',0xdbff,0xdfff,'-',0 }, "-\xF4\x8F\xBF\xBF-", STATUS_SUCCESS
},
1997 /* standalone lead surrogates become 0xFFFD */
1998 { { '-',0xd800,'-',0xdbff,'-',0 }, "-\xEF\xBF\xBD-\xEF\xBF\xBD-", STATUS_SOME_NOT_MAPPED
},
1999 /* standalone trail surrogates become 0xFFFD */
2000 { { '-',0xdc00,'-',0xdfff,'-',0 }, "-\xEF\xBF\xBD-\xEF\xBF\xBD-", STATUS_SOME_NOT_MAPPED
},
2001 /* reverse surrogate pair */
2002 { { '-',0xdfff,0xdbff,'-',0 }, "-\xEF\xBF\xBD\xEF\xBF\xBD-", STATUS_SOME_NOT_MAPPED
},
2003 /* byte order marks */
2004 { { '-',0xfeff,'-',0xfffe,'-',0 }, "-\xEF\xBB\xBF-\xEF\xBF\xBE-", STATUS_SUCCESS
},
2005 { { 0xfeff,'-',0 }, "\xEF\xBB\xBF-", STATUS_SUCCESS
},
2006 { { 0xfffe,'-',0 }, "\xEF\xBF\xBE-", STATUS_SUCCESS
},
2007 /* invalid code point */
2008 { { 0xffff,'-',0 }, "\xEF\xBF\xBF-", STATUS_SUCCESS
},
2009 /* canonically equivalent representations -- no normalization should happen */
2010 { { '-',0x1e09,'-',0 }, "-\xE1\xB8\x89-", STATUS_SUCCESS
},
2011 { { '-',0x0107,0x0327,'-',0 }, "-\xC4\x87\xCC\xA7-", STATUS_SUCCESS
},
2012 { { '-',0x00e7,0x0301,'-',0 }, "-\xC3\xA7\xCC\x81-", STATUS_SUCCESS
},
2013 { { '-',0x0063,0x0327,0x0301,'-',0 }, "-\x63\xCC\xA7\xCC\x81-", STATUS_SUCCESS
},
2014 { { '-',0x0063,0x0301,0x0327,'-',0 }, "-\x63\xCC\x81\xCC\xA7-", STATUS_SUCCESS
},
2017 static void utf8_expect_(const unsigned char *out_string
, ULONG buflen
, ULONG out_bytes
,
2018 const WCHAR
*in_string
, ULONG in_bytes
,
2019 NTSTATUS expect_status
, int line
)
2024 unsigned char *buf
= (unsigned char *)buffer
;
2027 if (buflen
== (ULONG
)-1)
2028 buflen
= sizeof(buffer
);
2029 bytes_out
= 0x55555555;
2030 memset(buffer
, 0x55, sizeof(buffer
));
2031 status
= pRtlUnicodeToUTF8N(
2032 out_string
? buffer
: NULL
, buflen
, &bytes_out
,
2033 in_string
, in_bytes
);
2034 ok_(__FILE__
, line
)(status
== expect_status
, "status = 0x%x\n", status
);
2035 ok_(__FILE__
, line
)(bytes_out
== out_bytes
, "bytes_out = %u\n", bytes_out
);
2038 for (i
= 0; i
< bytes_out
; i
++)
2039 ok_(__FILE__
, line
)(buf
[i
] == out_string
[i
],
2040 "buffer[%d] = 0x%x, expected 0x%x\n",
2041 i
, buf
[i
], out_string
[i
]);
2042 for (; i
< sizeof(buffer
); i
++)
2043 ok_(__FILE__
, line
)(buf
[i
] == 0x55,
2044 "buffer[%d] = 0x%x, expected 0x55\n",
2048 #define utf8_expect(out_string, buflen, out_bytes, in_string, in_bytes, expect_status) \
2049 utf8_expect_(out_string, buflen, out_bytes, in_string, in_bytes, expect_status, __LINE__)
2051 static void test_RtlUnicodeToUTF8N(void)
2055 ULONG bytes_out_array
[2];
2056 void * const invalid_pointer
= (void *)0x8;
2058 const WCHAR empty_string
[] = { 0 };
2059 const WCHAR test_string
[] = { 'A',0,'a','b','c','d','e','f','g',0 };
2060 const WCHAR special_string
[] = { 'X',0x80,0xd800,0 };
2061 const unsigned char special_expected
[] = { 'X',0xc2,0x80,0xef,0xbf,0xbd,0 };
2062 unsigned int input_len
;
2063 const unsigned int test_count
= sizeof(unicode_to_utf8
) / sizeof(unicode_to_utf8
[0]);
2066 if (!pRtlUnicodeToUTF8N
)
2068 skip("RtlUnicodeToUTF8N unavailable\n");
2072 /* show that bytes_out is really ULONG */
2073 memset(bytes_out_array
, 0x55, sizeof(bytes_out_array
));
2074 status
= pRtlUnicodeToUTF8N(NULL
, 0, bytes_out_array
, empty_string
, 0);
2075 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2076 ok(bytes_out_array
[0] == 0x00000000, "Got 0x%x\n", bytes_out_array
[0]);
2077 ok(bytes_out_array
[1] == 0x55555555, "Got 0x%x\n", bytes_out_array
[1]);
2079 /* parameter checks */
2080 status
= pRtlUnicodeToUTF8N(NULL
, 0, NULL
, NULL
, 0);
2081 ok(status
== STATUS_INVALID_PARAMETER_4
, "status = 0x%x\n", status
);
2083 status
= pRtlUnicodeToUTF8N(NULL
, 0, NULL
, empty_string
, 0);
2084 ok(status
== STATUS_INVALID_PARAMETER
, "status = 0x%x\n", status
);
2086 bytes_out
= 0x55555555;
2087 status
= pRtlUnicodeToUTF8N(NULL
, 0, &bytes_out
, NULL
, 0);
2088 ok(status
== STATUS_INVALID_PARAMETER_4
, "status = 0x%x\n", status
);
2089 ok(bytes_out
== 0x55555555, "bytes_out = 0x%x\n", bytes_out
);
2091 bytes_out
= 0x55555555;
2092 status
= pRtlUnicodeToUTF8N(NULL
, 0, &bytes_out
, invalid_pointer
, 0);
2093 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2094 ok(bytes_out
== 0, "bytes_out = 0x%x\n", bytes_out
);
2096 bytes_out
= 0x55555555;
2097 status
= pRtlUnicodeToUTF8N(NULL
, 0, &bytes_out
, empty_string
, 0);
2098 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2099 ok(bytes_out
== 0, "bytes_out = 0x%x\n", bytes_out
);
2101 bytes_out
= 0x55555555;
2102 status
= pRtlUnicodeToUTF8N(NULL
, 0, &bytes_out
, test_string
, 0);
2103 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2104 ok(bytes_out
== 0, "bytes_out = 0x%x\n", bytes_out
);
2106 bytes_out
= 0x55555555;
2107 status
= pRtlUnicodeToUTF8N(NULL
, 0, &bytes_out
, empty_string
, 1);
2108 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2109 ok(bytes_out
== 0, "bytes_out = 0x%x\n", bytes_out
);
2111 bytes_out
= 0x55555555;
2112 status
= pRtlUnicodeToUTF8N(invalid_pointer
, 0, &bytes_out
, empty_string
, 1);
2113 ok(status
== STATUS_INVALID_PARAMETER_5
, "status = 0x%x\n", status
);
2114 ok(bytes_out
== 0x55555555, "bytes_out = 0x%x\n", bytes_out
);
2116 bytes_out
= 0x55555555;
2117 status
= pRtlUnicodeToUTF8N(invalid_pointer
, 8, &bytes_out
, empty_string
, 1);
2118 ok(status
== STATUS_INVALID_PARAMETER_5
, "status = 0x%x\n", status
);
2119 ok(bytes_out
== 0x55555555, "bytes_out = 0x%x\n", bytes_out
);
2121 /* length output with special chars */
2122 #define length_expect(in_chars, out_bytes, expect_status) \
2123 utf8_expect_(NULL, 0, out_bytes, \
2124 special_string, in_chars * sizeof(WCHAR), \
2125 expect_status, __LINE__)
2127 length_expect(0, 0, STATUS_SUCCESS
);
2128 length_expect(1, 1, STATUS_SUCCESS
);
2129 length_expect(2, 3, STATUS_SUCCESS
);
2130 length_expect(3, 6, STATUS_SOME_NOT_MAPPED
);
2131 length_expect(4, 7, STATUS_SOME_NOT_MAPPED
);
2132 #undef length_expect
2134 /* output truncation */
2135 #define truncate_expect(buflen, out_bytes, expect_status) \
2136 utf8_expect_(special_expected, buflen, out_bytes, \
2137 special_string, sizeof(special_string), \
2138 expect_status, __LINE__)
2140 truncate_expect(0, 0, STATUS_BUFFER_TOO_SMALL
);
2141 truncate_expect(1, 1, STATUS_BUFFER_TOO_SMALL
);
2142 truncate_expect(2, 1, STATUS_BUFFER_TOO_SMALL
);
2143 truncate_expect(3, 3, STATUS_BUFFER_TOO_SMALL
);
2144 truncate_expect(4, 3, STATUS_BUFFER_TOO_SMALL
);
2145 truncate_expect(5, 3, STATUS_BUFFER_TOO_SMALL
);
2146 truncate_expect(6, 6, STATUS_BUFFER_TOO_SMALL
);
2147 truncate_expect(7, 7, STATUS_SOME_NOT_MAPPED
);
2148 #undef truncate_expect
2150 /* conversion behavior with varying input length */
2151 for (input_len
= 0; input_len
<= sizeof(test_string
); input_len
++) {
2152 /* no output buffer, just length */
2153 utf8_expect(NULL
, 0, input_len
/ sizeof(WCHAR
),
2154 test_string
, input_len
, STATUS_SUCCESS
);
2157 bytes_out
= 0x55555555;
2158 memset(buffer
, 0x55, sizeof(buffer
));
2159 status
= pRtlUnicodeToUTF8N(
2160 buffer
, sizeof(buffer
), &bytes_out
,
2161 test_string
, input_len
);
2162 if (input_len
% sizeof(WCHAR
) == 0) {
2163 ok(status
== STATUS_SUCCESS
,
2164 "(len %u): status = 0x%x\n", input_len
, status
);
2165 ok(bytes_out
== input_len
/ sizeof(WCHAR
),
2166 "(len %u): bytes_out = 0x%x\n", input_len
, bytes_out
);
2167 for (i
= 0; i
< bytes_out
; i
++) {
2168 ok(buffer
[i
] == test_string
[i
],
2169 "(len %u): buffer[%d] = 0x%x, expected 0x%x\n",
2170 input_len
, i
, buffer
[i
], test_string
[i
]);
2172 for (; i
< sizeof(buffer
); i
++) {
2173 ok(buffer
[i
] == 0x55,
2174 "(len %u): buffer[%d] = 0x%x\n", input_len
, i
, buffer
[i
]);
2177 ok(status
== STATUS_INVALID_PARAMETER_5
,
2178 "(len %u): status = 0x%x\n", input_len
, status
);
2179 ok(bytes_out
== 0x55555555,
2180 "(len %u): bytes_out = 0x%x\n", input_len
, bytes_out
);
2181 for (i
= 0; i
< sizeof(buffer
); i
++) {
2182 ok(buffer
[i
] == 0x55,
2183 "(len %u): buffer[%d] = 0x%x\n", input_len
, i
, buffer
[i
]);
2188 /* test cases for special characters */
2189 for (i
= 0; i
< test_count
; i
++) {
2190 bytes_out
= 0x55555555;
2191 memset(buffer
, 0x55, sizeof(buffer
));
2192 status
= pRtlUnicodeToUTF8N(
2193 buffer
, sizeof(buffer
), &bytes_out
,
2194 unicode_to_utf8
[i
].unicode
, lstrlenW(unicode_to_utf8
[i
].unicode
) * sizeof(WCHAR
));
2195 ok(status
== unicode_to_utf8
[i
].status
,
2196 "(test %d): status is 0x%x, expected 0x%x\n",
2197 i
, status
, unicode_to_utf8
[i
].status
);
2198 ok(bytes_out
== strlen(unicode_to_utf8
[i
].expected
),
2199 "(test %d): bytes_out is %u, expected %u\n",
2200 i
, bytes_out
, lstrlenA(unicode_to_utf8
[i
].expected
));
2201 ok(!memcmp(buffer
, unicode_to_utf8
[i
].expected
, bytes_out
),
2202 "(test %d): got \"%.*s\", expected \"%s\"\n",
2203 i
, bytes_out
, buffer
, unicode_to_utf8
[i
].expected
);
2204 ok(buffer
[bytes_out
] == 0x55,
2205 "(test %d): behind string: 0x%x\n", i
, buffer
[bytes_out
]);
2207 /* same test but include the null terminator */
2208 bytes_out
= 0x55555555;
2209 memset(buffer
, 0x55, sizeof(buffer
));
2210 status
= pRtlUnicodeToUTF8N(
2211 buffer
, sizeof(buffer
), &bytes_out
,
2212 unicode_to_utf8
[i
].unicode
, (lstrlenW(unicode_to_utf8
[i
].unicode
) + 1) * sizeof(WCHAR
));
2213 ok(status
== unicode_to_utf8
[i
].status
,
2214 "(test %d): status is 0x%x, expected 0x%x\n",
2215 i
, status
, unicode_to_utf8
[i
].status
);
2216 ok(bytes_out
== strlen(unicode_to_utf8
[i
].expected
) + 1,
2217 "(test %d): bytes_out is %u, expected %u\n",
2218 i
, bytes_out
, lstrlenA(unicode_to_utf8
[i
].expected
) + 1);
2219 ok(!memcmp(buffer
, unicode_to_utf8
[i
].expected
, bytes_out
),
2220 "(test %d): got \"%.*s\", expected \"%s\"\n",
2221 i
, bytes_out
, buffer
, unicode_to_utf8
[i
].expected
);
2222 ok(buffer
[bytes_out
] == 0x55,
2223 "(test %d): behind string: 0x%x\n", i
, buffer
[bytes_out
]);
2227 struct utf8_to_unicode_test
{
2229 WCHAR expected
[128];
2233 static const struct utf8_to_unicode_test utf8_to_unicode
[] = {
2234 { "", { 0 }, STATUS_SUCCESS
},
2235 { "-", { '-',0 }, STATUS_SUCCESS
},
2236 { "hello", { 'h','e','l','l','o',0 }, STATUS_SUCCESS
},
2237 /* first and last of each range */
2238 { "-\x7F-\xC2\x80-\xC3\xBF-\xC4\x80-", { '-',0x7f,'-',0x80,'-',0xff,'-',0x100,'-',0 }, STATUS_SUCCESS
},
2239 { "-\xDF\xBF-\xE0\xA0\x80-", { '-',0x7ff,'-',0x800,'-',0 }, STATUS_SUCCESS
},
2240 { "-\xED\x9F\xBF-\xEE\x80\x80-", { '-',0xd7ff,'-',0xe000,'-',0 }, STATUS_SUCCESS
},
2242 { "-\xEF\xBF\xBF-\xF0\x90\x80\x80-", { '-',0xffff,'-',0xd800,0xdc00,'-',0 }, STATUS_SUCCESS
},
2243 /* 0x103ff */ /* 0x10400 */
2244 { "-\xF0\x90\x8F\xBF-\xF0\x90\x90\x80-", { '-',0xd800,0xdfff,'-',0xd801,0xdc00,'-',0 }, STATUS_SUCCESS
},
2246 { "-\xF4\x8F\xBF\xBF-", { '-',0xdbff,0xdfff,'-',0 }, STATUS_SUCCESS
},
2247 /* standalone surrogate code points */
2248 /* 0xd800 */ /* 0xdbff */
2249 { "-\xED\xA0\x80-\xED\xAF\xBF-", { '-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2250 /* 0xdc00 */ /* 0xdfff */
2251 { "-\xED\xB0\x80-\xED\xBF\xBF-", { '-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2252 /* UTF-8 encoded surrogate pair */
2253 /* 0xdbff *//* 0xdfff */
2254 { "-\xED\xAF\xBF\xED\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2255 /* reverse surrogate pair */
2256 /* 0xdfff *//* 0xdbff */
2257 { "-\xED\xBF\xBF\xED\xAF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2258 /* code points outside the UTF-16 range */
2260 { "-\xF4\x90\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2262 { "-\xF7\xBF\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2264 { "-\xFA\x80\x80\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2266 { "-\xFB\xBF\xBF\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2268 { "-\xFC\x84\x80\x80\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2270 { "-\xFD\xBF\xBF\xBF\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2271 /* overlong encodings of each length for -, NUL, and the highest possible value */
2272 { "-\xC0\xAD-\xC0\x80-\xC1\xBF-", { '-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2273 { "-\xE0\x80\xAD-\xE0\x80\x80-\xE0\x9F\xBF-", { '-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2274 { "-\xF0\x80\x80\xAD-", { '-',0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2275 { "-\xF0\x80\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2276 { "-\xF0\x8F\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2277 { "-\xF8\x80\x80\x80\xAD-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2278 { "-\xF8\x80\x80\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2279 { "-\xF8\x87\xBF\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2280 { "-\xFC\x80\x80\x80\x80\xAD-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2281 { "-\xFC\x80\x80\x80\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2282 { "-\xFC\x83\xBF\xBF\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2284 { "\xFE", { 0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2285 { "\xFF", { 0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2286 { "\xFE\xBF\xBF\xBF\xBF\xBF\xBF\xBF\xBF", { 0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2287 { "\xFF\xBF\xBF\xBF\xBF\xBF\xBF\xBF\xBF", { 0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2288 { "\xFF\x80\x80\x80\x80\x80\x80\x80\x80", { 0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2289 { "\xFF\x40\x80\x80\x80\x80\x80\x80\x80", { 0xfffd,0x40,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2290 /* lone continuation bytes */
2291 { "\x80", { 0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2292 { "\x80\x80", { 0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2293 { "\xBF", { 0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2294 { "\xBF\xBF", { 0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2295 /* incomplete sequences */
2296 { "\xC2-", { 0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2297 { "\xE0\xA0-", { 0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2298 { "\xF0\x90\x80-", { 0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2299 { "\xF4\x8F\xBF-", { 0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2300 { "\xFA\x80\x80\x80-", { 0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2301 { "\xFC\x84\x80\x80\x80-", { 0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2302 /* multibyte sequence followed by lone continuation byte */
2303 { "\xE0\xA0\x80\x80-", { 0x800,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2304 /* byte order marks */
2305 { "-\xEF\xBB\xBF-\xEF\xBF\xBE-", { '-',0xfeff,'-',0xfffe,'-',0 }, STATUS_SUCCESS
},
2306 { "\xEF\xBB\xBF-", { 0xfeff,'-',0 }, STATUS_SUCCESS
},
2307 { "\xEF\xBF\xBE-", { 0xfffe,'-',0 }, STATUS_SUCCESS
},
2308 /* invalid code point */
2310 { "\xEF\xBF\xBF-", { 0xffff,'-',0 }, STATUS_SUCCESS
},
2311 /* canonically equivalent representations -- no normalization should happen */
2312 { "-\xE1\xB8\x89-", { '-',0x1e09,'-',0 }, STATUS_SUCCESS
},
2313 { "-\xC4\x87\xCC\xA7-", { '-',0x0107,0x0327,'-',0 }, STATUS_SUCCESS
},
2314 { "-\xC3\xA7\xCC\x81-", { '-',0x00e7,0x0301,'-',0 }, STATUS_SUCCESS
},
2315 { "-\x63\xCC\xA7\xCC\x81-", { '-',0x0063,0x0327,0x0301,'-',0 }, STATUS_SUCCESS
},
2316 { "-\x63\xCC\x81\xCC\xA7-", { '-',0x0063,0x0301,0x0327,'-',0 }, STATUS_SUCCESS
},
2319 static void unicode_expect_(const WCHAR
*out_string
, ULONG buflen
, ULONG out_chars
,
2320 const char *in_string
, ULONG in_chars
,
2321 NTSTATUS expect_status
, int line
)
2328 if (buflen
== (ULONG
)-1)
2329 buflen
= sizeof(buffer
);
2330 bytes_out
= 0x55555555;
2331 memset(buffer
, 0x55, sizeof(buffer
));
2332 status
= pRtlUTF8ToUnicodeN(
2333 out_string
? buffer
: NULL
, buflen
, &bytes_out
,
2334 in_string
, in_chars
);
2335 ok_(__FILE__
, line
)(status
== expect_status
, "status = 0x%x\n", status
);
2336 ok_(__FILE__
, line
)(bytes_out
== out_chars
* sizeof(WCHAR
),
2337 "bytes_out = %u, expected %u\n", bytes_out
, out_chars
* (ULONG
)sizeof(WCHAR
));
2340 for (i
= 0; i
< bytes_out
/ sizeof(WCHAR
); i
++)
2341 ok_(__FILE__
, line
)(buffer
[i
] == out_string
[i
],
2342 "buffer[%d] = 0x%x, expected 0x%x\n",
2343 i
, buffer
[i
], out_string
[i
]);
2344 for (; i
< sizeof(buffer
) / sizeof(WCHAR
); i
++)
2345 ok_(__FILE__
, line
)(buffer
[i
] == 0x5555,
2346 "buffer[%d] = 0x%x, expected 0x5555\n",
2350 #define unicode_expect(out_string, buflen, out_chars, in_string, in_chars, expect_status) \
2351 unicode_expect_(out_string, buflen, out_chars, in_string, in_chars, expect_status, __LINE__)
2353 static void test_RtlUTF8ToUnicodeN(void)
2357 ULONG bytes_out_array
[2];
2358 void * const invalid_pointer
= (void *)0x8;
2360 const char empty_string
[] = "";
2361 const char test_string
[] = "A\0abcdefg";
2362 const WCHAR test_stringW
[] = {'A',0,'a','b','c','d','e','f','g',0 };
2363 const char special_string
[] = { 'X',0xc2,0x80,0xF0,0x90,0x80,0x80,0 };
2364 const WCHAR special_expected
[] = { 'X',0x80,0xd800,0xdc00,0 };
2365 unsigned int input_len
;
2366 const unsigned int test_count
= sizeof(utf8_to_unicode
) / sizeof(utf8_to_unicode
[0]);
2369 if (!pRtlUTF8ToUnicodeN
)
2371 skip("RtlUTF8ToUnicodeN unavailable\n");
2375 /* show that bytes_out is really ULONG */
2376 memset(bytes_out_array
, 0x55, sizeof(bytes_out_array
));
2377 status
= pRtlUTF8ToUnicodeN(NULL
, 0, bytes_out_array
, empty_string
, 0);
2378 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2379 ok(bytes_out_array
[0] == 0x00000000, "Got 0x%x\n", bytes_out_array
[0]);
2380 ok(bytes_out_array
[1] == 0x55555555, "Got 0x%x\n", bytes_out_array
[1]);
2382 /* parameter checks */
2383 status
= pRtlUTF8ToUnicodeN(NULL
, 0, NULL
, NULL
, 0);
2384 ok(status
== STATUS_INVALID_PARAMETER_4
, "status = 0x%x\n", status
);
2386 status
= pRtlUTF8ToUnicodeN(NULL
, 0, NULL
, empty_string
, 0);
2387 ok(status
== STATUS_INVALID_PARAMETER
, "status = 0x%x\n", status
);
2389 bytes_out
= 0x55555555;
2390 status
= pRtlUTF8ToUnicodeN(NULL
, 0, &bytes_out
, NULL
, 0);
2391 ok(status
== STATUS_INVALID_PARAMETER_4
, "status = 0x%x\n", status
);
2392 ok(bytes_out
== 0x55555555, "bytes_out = 0x%x\n", bytes_out
);
2394 bytes_out
= 0x55555555;
2395 status
= pRtlUTF8ToUnicodeN(NULL
, 0, &bytes_out
, invalid_pointer
, 0);
2396 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2397 ok(bytes_out
== 0, "bytes_out = 0x%x\n", bytes_out
);
2399 bytes_out
= 0x55555555;
2400 status
= pRtlUTF8ToUnicodeN(NULL
, 0, &bytes_out
, empty_string
, 0);
2401 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2402 ok(bytes_out
== 0, "bytes_out = 0x%x\n", bytes_out
);
2404 bytes_out
= 0x55555555;
2405 status
= pRtlUTF8ToUnicodeN(NULL
, 0, &bytes_out
, test_string
, 0);
2406 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2407 ok(bytes_out
== 0, "bytes_out = 0x%x\n", bytes_out
);
2409 bytes_out
= 0x55555555;
2410 status
= pRtlUTF8ToUnicodeN(NULL
, 0, &bytes_out
, empty_string
, 1);
2411 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2412 ok(bytes_out
== sizeof(WCHAR
), "bytes_out = 0x%x\n", bytes_out
);
2414 /* length output with special chars */
2415 #define length_expect(in_chars, out_chars, expect_status) \
2416 unicode_expect_(NULL, 0, out_chars, special_string, in_chars, \
2417 expect_status, __LINE__)
2419 length_expect(0, 0, STATUS_SUCCESS
);
2420 length_expect(1, 1, STATUS_SUCCESS
);
2421 length_expect(2, 2, STATUS_SOME_NOT_MAPPED
);
2422 length_expect(3, 2, STATUS_SUCCESS
);
2423 length_expect(4, 3, STATUS_SOME_NOT_MAPPED
);
2424 length_expect(5, 3, STATUS_SOME_NOT_MAPPED
);
2425 length_expect(6, 3, STATUS_SOME_NOT_MAPPED
);
2426 length_expect(7, 4, STATUS_SUCCESS
);
2427 length_expect(8, 5, STATUS_SUCCESS
);
2428 #undef length_expect
2430 /* output truncation */
2431 #define truncate_expect(buflen, out_chars, expect_status) \
2432 unicode_expect_(special_expected, buflen, out_chars, \
2433 special_string, sizeof(special_string), \
2434 expect_status, __LINE__)
2436 truncate_expect( 0, 0, STATUS_BUFFER_TOO_SMALL
);
2437 truncate_expect( 1, 0, STATUS_BUFFER_TOO_SMALL
);
2438 truncate_expect( 2, 1, STATUS_BUFFER_TOO_SMALL
);
2439 truncate_expect( 3, 1, STATUS_BUFFER_TOO_SMALL
);
2440 truncate_expect( 4, 2, STATUS_BUFFER_TOO_SMALL
);
2441 truncate_expect( 5, 2, STATUS_BUFFER_TOO_SMALL
);
2442 truncate_expect( 6, 3, STATUS_BUFFER_TOO_SMALL
);
2443 truncate_expect( 7, 3, STATUS_BUFFER_TOO_SMALL
);
2444 truncate_expect( 8, 4, STATUS_BUFFER_TOO_SMALL
);
2445 truncate_expect( 9, 4, STATUS_BUFFER_TOO_SMALL
);
2446 truncate_expect(10, 5, STATUS_SUCCESS
);
2447 #undef truncate_expect
2449 /* conversion behavior with varying input length */
2450 for (input_len
= 0; input_len
<= sizeof(test_string
); input_len
++) {
2451 /* no output buffer, just length */
2452 unicode_expect(NULL
, 0, input_len
,
2453 test_string
, input_len
, STATUS_SUCCESS
);
2456 unicode_expect(test_stringW
, -1, input_len
,
2457 test_string
, input_len
, STATUS_SUCCESS
);
2460 /* test cases for special characters */
2461 for (i
= 0; i
< test_count
; i
++) {
2462 bytes_out
= 0x55555555;
2463 memset(buffer
, 0x55, sizeof(buffer
));
2464 status
= pRtlUTF8ToUnicodeN(
2465 buffer
, sizeof(buffer
), &bytes_out
,
2466 utf8_to_unicode
[i
].utf8
, strlen(utf8_to_unicode
[i
].utf8
));
2467 ok(status
== utf8_to_unicode
[i
].status
,
2468 "(test %d): status is 0x%x, expected 0x%x\n",
2469 i
, status
, utf8_to_unicode
[i
].status
);
2470 ok(bytes_out
== lstrlenW(utf8_to_unicode
[i
].expected
) * sizeof(WCHAR
),
2471 "(test %d): bytes_out is %u, expected %u\n",
2472 i
, bytes_out
, lstrlenW(utf8_to_unicode
[i
].expected
) * (ULONG
)sizeof(WCHAR
));
2473 ok(!memcmp(buffer
, utf8_to_unicode
[i
].expected
, bytes_out
),
2474 "(test %d): got %s, expected %s\n",
2475 i
, wine_dbgstr_wn(buffer
, bytes_out
/ sizeof(WCHAR
)), wine_dbgstr_w(utf8_to_unicode
[i
].expected
));
2476 ok(buffer
[bytes_out
] == 0x5555,
2477 "(test %d): behind string: 0x%x\n", i
, buffer
[bytes_out
]);
2479 /* same test but include the null terminator */
2480 bytes_out
= 0x55555555;
2481 memset(buffer
, 0x55, sizeof(buffer
));
2482 status
= pRtlUTF8ToUnicodeN(
2483 buffer
, sizeof(buffer
), &bytes_out
,
2484 utf8_to_unicode
[i
].utf8
, strlen(utf8_to_unicode
[i
].utf8
) + 1);
2485 ok(status
== utf8_to_unicode
[i
].status
,
2486 "(test %d): status is 0x%x, expected 0x%x\n",
2487 i
, status
, utf8_to_unicode
[i
].status
);
2488 ok(bytes_out
== (lstrlenW(utf8_to_unicode
[i
].expected
) + 1) * sizeof(WCHAR
),
2489 "(test %d): bytes_out is %u, expected %u\n",
2490 i
, bytes_out
, (lstrlenW(utf8_to_unicode
[i
].expected
) + 1) * (ULONG
)sizeof(WCHAR
));
2491 ok(!memcmp(buffer
, utf8_to_unicode
[i
].expected
, bytes_out
),
2492 "(test %d): got %s, expected %s\n",
2493 i
, wine_dbgstr_wn(buffer
, bytes_out
/ sizeof(WCHAR
)), wine_dbgstr_w(utf8_to_unicode
[i
].expected
));
2494 ok(buffer
[bytes_out
] == 0x5555,
2495 "(test %d): behind string: 0x%x\n", i
, buffer
[bytes_out
]);
2502 if (pRtlInitAnsiString
) {
2503 test_RtlInitString();
2504 test_RtlInitUnicodeString();
2505 test_RtlCopyString();
2506 test_RtlUnicodeStringToInteger();
2507 test_RtlCharToInteger();
2508 test_RtlIntegerToUnicodeString();
2509 test_RtlIntegerToChar();
2510 test_RtlUpperChar();
2511 test_RtlUpperString();
2512 test_RtlUnicodeStringToAnsiString();
2513 test_RtlAppendAsciizToString();
2514 test_RtlAppendStringToString();
2515 test_RtlAppendUnicodeToString();
2516 test_RtlAppendUnicodeStringToString();
2519 test_RtlInitUnicodeStringEx();
2520 test_RtlDuplicateUnicodeString();
2521 test_RtlFindCharInUnicodeString();
2522 test_RtlGUIDFromString();
2523 test_RtlStringFromGUID();
2524 test_RtlIsTextUnicode();
2527 test_RtlUpcaseUnicodeChar();
2528 test_RtlUpcaseUnicodeString();
2529 test_RtlDowncaseUnicodeString();
2531 test_RtlHashUnicodeString();
2532 test_RtlUnicodeToUTF8N();
2533 test_RtlUTF8ToUnicodeN();