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 LONG (WINAPI
*pRtlCompareUnicodeString
)(const UNICODE_STRING
*, const UNICODE_STRING
*, BOOLEAN
);
45 static LONG (WINAPI
*pRtlCompareUnicodeStrings
)(const WCHAR
*,SIZE_T
,const WCHAR
*,SIZE_T
,BOOLEAN
);
46 static VOID (WINAPI
*pRtlCopyString
)(STRING
*, const STRING
*);
47 static BOOLEAN (WINAPI
*pRtlCreateUnicodeString
)(PUNICODE_STRING
, LPCWSTR
);
48 static BOOLEAN (WINAPI
*pRtlCreateUnicodeStringFromAsciiz
)(PUNICODE_STRING
, LPCSTR
);
49 static NTSTATUS (WINAPI
*pRtlDowncaseUnicodeString
)(UNICODE_STRING
*, const UNICODE_STRING
*, BOOLEAN
);
50 static NTSTATUS (WINAPI
*pRtlDuplicateUnicodeString
)(int, UNICODE_STRING
*, UNICODE_STRING
*);
51 static BOOLEAN (WINAPI
*pRtlEqualUnicodeString
)(const UNICODE_STRING
*, const UNICODE_STRING
*, BOOLEAN
);
52 static NTSTATUS (WINAPI
*pRtlFindCharInUnicodeString
)(int, const UNICODE_STRING
*, const UNICODE_STRING
*, USHORT
*);
53 static VOID (WINAPI
*pRtlFreeAnsiString
)(PSTRING
);
54 static VOID (WINAPI
*pRtlFreeUnicodeString
)(PUNICODE_STRING
);
55 static VOID (WINAPI
*pRtlInitAnsiString
)(PSTRING
, LPCSTR
);
56 static VOID (WINAPI
*pRtlInitString
)(PSTRING
, LPCSTR
);
57 static VOID (WINAPI
*pRtlInitUnicodeString
)(PUNICODE_STRING
, LPCWSTR
);
58 static NTSTATUS (WINAPI
*pRtlInitUnicodeStringEx
)(PUNICODE_STRING
, LPCWSTR
);
59 static NTSTATUS (WINAPI
*pRtlIntegerToChar
)(ULONG
, ULONG
, ULONG
, PCHAR
);
60 static NTSTATUS (WINAPI
*pRtlIntegerToUnicodeString
)(ULONG
, ULONG
, UNICODE_STRING
*);
61 static NTSTATUS (WINAPI
*pRtlMultiAppendUnicodeStringBuffer
)(UNICODE_STRING
*, LONG
, UNICODE_STRING
*);
62 static NTSTATUS (WINAPI
*pRtlUnicodeStringToAnsiString
)(STRING
*, const UNICODE_STRING
*, BOOLEAN
);
63 static NTSTATUS (WINAPI
*pRtlUnicodeStringToInteger
)(const UNICODE_STRING
*, int, int *);
64 static WCHAR (WINAPI
*pRtlUpcaseUnicodeChar
)(WCHAR
);
65 static NTSTATUS (WINAPI
*pRtlUpcaseUnicodeString
)(UNICODE_STRING
*, const UNICODE_STRING
*, BOOLEAN
);
66 static CHAR (WINAPI
*pRtlUpperChar
)(CHAR
);
67 static NTSTATUS (WINAPI
*pRtlUpperString
)(STRING
*, const STRING
*);
68 static NTSTATUS (WINAPI
*pRtlValidateUnicodeString
)(LONG
, UNICODE_STRING
*);
69 static NTSTATUS (WINAPI
*pRtlGUIDFromString
)(const UNICODE_STRING
*,GUID
*);
70 static NTSTATUS (WINAPI
*pRtlStringFromGUID
)(const GUID
*, UNICODE_STRING
*);
71 static BOOLEAN (WINAPI
*pRtlIsTextUnicode
)(LPVOID
, INT
, INT
*);
72 static NTSTATUS (WINAPI
*pRtlHashUnicodeString
)(PCUNICODE_STRING
,BOOLEAN
,ULONG
,ULONG
*);
73 static NTSTATUS (WINAPI
*pRtlUnicodeToUTF8N
)(CHAR
*, ULONG
, ULONG
*, const WCHAR
*, ULONG
);
74 static NTSTATUS (WINAPI
*pRtlUTF8ToUnicodeN
)(WCHAR
*, ULONG
, ULONG
*, const CHAR
*, ULONG
);
75 static NTSTATUS (WINAPI
*pRtlFormatMessage
)(const WCHAR
*,ULONG
,BOOLEAN
,BOOLEAN
,BOOLEAN
,__ms_va_list
*,LPWSTR
,ULONG
,ULONG
*);
77 /*static VOID (WINAPI *pRtlFreeOemString)(PSTRING);*/
78 /*static VOID (WINAPI *pRtlCopyUnicodeString)(UNICODE_STRING *, const UNICODE_STRING *);*/
79 /*static VOID (WINAPI *pRtlEraseUnicodeString)(UNICODE_STRING *);*/
80 /*static LONG (WINAPI *pRtlCompareString)(const STRING *,const STRING *,BOOLEAN);*/
81 /*static BOOLEAN (WINAPI *pRtlEqualString)(const STRING *,const STRING *,BOOLEAN);*/
82 /*static BOOLEAN (WINAPI *pRtlPrefixString)(const STRING *, const STRING *, BOOLEAN);*/
83 /*static BOOLEAN (WINAPI *pRtlPrefixUnicodeString)(const UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN);*/
84 /*static NTSTATUS (WINAPI *pRtlOemStringToUnicodeString)(PUNICODE_STRING, const STRING *, BOOLEAN);*/
85 /*static NTSTATUS (WINAPI *pRtlUnicodeStringToOemString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/
86 /*static NTSTATUS (WINAPI *pRtlMultiByteToUnicodeN)(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD);*/
87 /*static NTSTATUS (WINAPI *pRtlOemToUnicodeN)(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD);*/
88 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeStringToAnsiString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/
89 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeStringToOemString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/
90 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeToMultiByteN)(LPSTR, DWORD, LPDWORD, LPCWSTR, DWORD);*/
91 /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeToOemN)(LPSTR, DWORD, LPDWORD, LPCWSTR, DWORD);*/
92 /*static UINT (WINAPI *pRtlOemToUnicodeSize)(const STRING *);*/
93 /*static DWORD (WINAPI *pRtlAnsiStringToUnicodeSize)(const STRING *);*/
96 static WCHAR
* AtoW( const char* p
)
99 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, p
, -1, NULL
, 0 );
100 buffer
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
101 MultiByteToWideChar( CP_ACP
, 0, p
, -1, buffer
, len
);
106 static void InitFunctionPtrs(void)
108 hntdll
= LoadLibraryA("ntdll.dll");
109 ok(hntdll
!= 0, "LoadLibrary failed\n");
111 pRtlAnsiStringToUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlAnsiStringToUnicodeString");
112 pRtlAppendAsciizToString
= (void *)GetProcAddress(hntdll
, "RtlAppendAsciizToString");
113 pRtlAppendStringToString
= (void *)GetProcAddress(hntdll
, "RtlAppendStringToString");
114 pRtlAppendUnicodeStringToString
= (void *)GetProcAddress(hntdll
, "RtlAppendUnicodeStringToString");
115 pRtlAppendUnicodeToString
= (void *)GetProcAddress(hntdll
, "RtlAppendUnicodeToString");
116 pRtlCharToInteger
= (void *)GetProcAddress(hntdll
, "RtlCharToInteger");
117 pRtlCompareUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlCompareUnicodeString");
118 pRtlCompareUnicodeStrings
= (void *)GetProcAddress(hntdll
, "RtlCompareUnicodeStrings");
119 pRtlCopyString
= (void *)GetProcAddress(hntdll
, "RtlCopyString");
120 pRtlCreateUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlCreateUnicodeString");
121 pRtlCreateUnicodeStringFromAsciiz
= (void *)GetProcAddress(hntdll
, "RtlCreateUnicodeStringFromAsciiz");
122 pRtlDowncaseUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlDowncaseUnicodeString");
123 pRtlDuplicateUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlDuplicateUnicodeString");
124 pRtlEqualUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlEqualUnicodeString");
125 pRtlFindCharInUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFindCharInUnicodeString");
126 pRtlFreeAnsiString
= (void *)GetProcAddress(hntdll
, "RtlFreeAnsiString");
127 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
128 pRtlInitAnsiString
= (void *)GetProcAddress(hntdll
, "RtlInitAnsiString");
129 pRtlInitString
= (void *)GetProcAddress(hntdll
, "RtlInitString");
130 pRtlInitUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlInitUnicodeString");
131 pRtlInitUnicodeStringEx
= (void *)GetProcAddress(hntdll
, "RtlInitUnicodeStringEx");
132 pRtlIntegerToChar
= (void *)GetProcAddress(hntdll
, "RtlIntegerToChar");
133 pRtlIntegerToUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlIntegerToUnicodeString");
134 pRtlMultiAppendUnicodeStringBuffer
= (void *)GetProcAddress(hntdll
, "RtlMultiAppendUnicodeStringBuffer");
135 pRtlUnicodeStringToAnsiString
= (void *)GetProcAddress(hntdll
, "RtlUnicodeStringToAnsiString");
136 pRtlUnicodeStringToInteger
= (void *)GetProcAddress(hntdll
, "RtlUnicodeStringToInteger");
137 pRtlUpcaseUnicodeChar
= (void *)GetProcAddress(hntdll
, "RtlUpcaseUnicodeChar");
138 pRtlUpcaseUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlUpcaseUnicodeString");
139 pRtlUpperChar
= (void *)GetProcAddress(hntdll
, "RtlUpperChar");
140 pRtlUpperString
= (void *)GetProcAddress(hntdll
, "RtlUpperString");
141 pRtlValidateUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlValidateUnicodeString");
142 pRtlGUIDFromString
= (void *)GetProcAddress(hntdll
, "RtlGUIDFromString");
143 pRtlStringFromGUID
= (void *)GetProcAddress(hntdll
, "RtlStringFromGUID");
144 pRtlIsTextUnicode
= (void *)GetProcAddress(hntdll
, "RtlIsTextUnicode");
145 pRtlHashUnicodeString
= (void*)GetProcAddress(hntdll
, "RtlHashUnicodeString");
146 pRtlUnicodeToUTF8N
= (void*)GetProcAddress(hntdll
, "RtlUnicodeToUTF8N");
147 pRtlUTF8ToUnicodeN
= (void*)GetProcAddress(hntdll
, "RtlUTF8ToUnicodeN");
148 pRtlFormatMessage
= (void*)GetProcAddress(hntdll
, "RtlFormatMessage");
152 static void test_RtlInitString(void)
154 static const char teststring
[] = "Some Wild String";
158 str
.MaximumLength
= 0;
159 str
.Buffer
= (void *)0xdeadbeef;
160 pRtlInitString(&str
, teststring
);
161 ok(str
.Length
== sizeof(teststring
) - sizeof(char), "Length uninitialized\n");
162 ok(str
.MaximumLength
== sizeof(teststring
), "MaximumLength uninitialized\n");
163 ok(str
.Buffer
== teststring
, "Buffer not equal to teststring\n");
164 ok(strcmp(str
.Buffer
, "Some Wild String") == 0, "Buffer written to\n");
165 pRtlInitString(&str
, NULL
);
166 ok(str
.Length
== 0, "Length uninitialized\n");
167 ok(str
.MaximumLength
== 0, "MaximumLength uninitialized\n");
168 ok(str
.Buffer
== NULL
, "Buffer not equal to NULL\n");
169 /* pRtlInitString(NULL, teststring); */
173 static void test_RtlInitUnicodeString(void)
175 #define STRINGW {'S','o','m','e',' ','W','i','l','d',' ','S','t','r','i','n','g',0}
176 static const WCHAR teststring
[] = STRINGW
;
177 static const WCHAR originalstring
[] = STRINGW
;
182 uni
.MaximumLength
= 0;
183 uni
.Buffer
= (void *)0xdeadbeef;
184 pRtlInitUnicodeString(&uni
, teststring
);
185 ok(uni
.Length
== sizeof(teststring
) - sizeof(WCHAR
), "Length uninitialized\n");
186 ok(uni
.MaximumLength
== sizeof(teststring
), "MaximumLength uninitialized\n");
187 ok(uni
.Buffer
== teststring
, "Buffer not equal to teststring\n");
188 ok(lstrcmpW(uni
.Buffer
, originalstring
) == 0, "Buffer written to\n");
189 pRtlInitUnicodeString(&uni
, NULL
);
190 ok(uni
.Length
== 0, "Length uninitialized\n");
191 ok(uni
.MaximumLength
== 0, "MaximumLength uninitialized\n");
192 ok(uni
.Buffer
== NULL
, "Buffer not equal to NULL\n");
193 /* pRtlInitUnicodeString(NULL, teststring); */
197 #define TESTSTRING2_LEN 1000000
198 /* #define TESTSTRING2_LEN 32766 */
201 static void test_RtlInitUnicodeStringEx(void)
203 static const WCHAR teststring
[] = {'S','o','m','e',' ','W','i','l','d',' ','S','t','r','i','n','g',0};
208 if (!pRtlInitUnicodeStringEx
)
210 win_skip("RtlInitUnicodeStringEx is not available\n");
214 teststring2
= HeapAlloc(GetProcessHeap(), 0, (TESTSTRING2_LEN
+ 1) * sizeof(WCHAR
));
215 memset(teststring2
, 'X', TESTSTRING2_LEN
* sizeof(WCHAR
));
216 teststring2
[TESTSTRING2_LEN
] = '\0';
219 uni
.MaximumLength
= 12345;
220 uni
.Buffer
= (void *) 0xdeadbeef;
221 result
= pRtlInitUnicodeStringEx(&uni
, teststring
);
222 ok(result
== STATUS_SUCCESS
,
223 "pRtlInitUnicodeStringEx(&uni, 0) returns %x, expected 0\n",
226 "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected %u\n",
228 ok(uni
.MaximumLength
== 34,
229 "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected %u\n",
230 uni
.MaximumLength
, 34);
231 ok(uni
.Buffer
== teststring
,
232 "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %p\n",
233 uni
.Buffer
, teststring
);
236 uni
.MaximumLength
= 12345;
237 uni
.Buffer
= (void *) 0xdeadbeef;
238 pRtlInitUnicodeString(&uni
, teststring
);
240 "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u\n",
242 ok(uni
.MaximumLength
== 34,
243 "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u\n",
244 uni
.MaximumLength
, 34);
245 ok(uni
.Buffer
== teststring
,
246 "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p\n",
247 uni
.Buffer
, teststring
);
250 uni
.MaximumLength
= 12345;
251 uni
.Buffer
= (void *) 0xdeadbeef;
252 result
= pRtlInitUnicodeStringEx(&uni
, teststring2
);
253 ok(result
== STATUS_NAME_TOO_LONG
,
254 "pRtlInitUnicodeStringEx(&uni, 0) returns %x, expected %x\n",
255 result
, STATUS_NAME_TOO_LONG
);
256 ok(uni
.Length
== 12345 ||
257 uni
.Length
== 0, /* win2k3 */
258 "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected 12345 or 0\n",
260 ok(uni
.MaximumLength
== 12345 ||
261 uni
.MaximumLength
== 0, /* win2k3 */
262 "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected 12345 or 0\n",
264 ok(uni
.Buffer
== (void *) 0xdeadbeef ||
265 uni
.Buffer
== teststring2
, /* win2k3 */
266 "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %x or %p\n",
267 uni
.Buffer
, 0xdeadbeef, teststring2
);
270 uni
.MaximumLength
= 12345;
271 uni
.Buffer
= (void *) 0xdeadbeef;
272 pRtlInitUnicodeString(&uni
, teststring2
);
273 ok(uni
.Length
== 33920 /* <= Win2000 */ || uni
.Length
== 65532 /* >= Win XP */,
274 "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u\n",
276 ok(uni
.MaximumLength
== 33922 /* <= Win2000 */ || uni
.MaximumLength
== 65534 /* >= Win XP */,
277 "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u\n",
278 uni
.MaximumLength
, 65534);
279 ok(uni
.Buffer
== teststring2
,
280 "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p\n",
281 uni
.Buffer
, teststring2
);
282 ok(memcmp(uni
.Buffer
, teststring2
, (TESTSTRING2_LEN
+ 1) * sizeof(WCHAR
)) == 0,
283 "pRtlInitUnicodeString(&uni, 0) changes Buffer\n");
286 uni
.MaximumLength
= 12345;
287 uni
.Buffer
= (void *) 0xdeadbeef;
288 result
= pRtlInitUnicodeStringEx(&uni
, 0);
289 ok(result
== STATUS_SUCCESS
,
290 "pRtlInitUnicodeStringEx(&uni, 0) returns %x, expected 0\n",
293 "pRtlInitUnicodeStringEx(&uni, 0) sets Length to %u, expected %u\n",
295 ok(uni
.MaximumLength
== 0,
296 "pRtlInitUnicodeStringEx(&uni, 0) sets MaximumLength to %u, expected %u\n",
297 uni
.MaximumLength
, 0);
298 ok(uni
.Buffer
== NULL
,
299 "pRtlInitUnicodeStringEx(&uni, 0) sets Buffer to %p, expected %p\n",
303 uni
.MaximumLength
= 12345;
304 uni
.Buffer
= (void *) 0xdeadbeef;
305 pRtlInitUnicodeString(&uni
, 0);
307 "pRtlInitUnicodeString(&uni, 0) sets Length to %u, expected %u\n",
309 ok(uni
.MaximumLength
== 0,
310 "pRtlInitUnicodeString(&uni, 0) sets MaximumLength to %u, expected %u\n",
311 uni
.MaximumLength
, 0);
312 ok(uni
.Buffer
== NULL
,
313 "pRtlInitUnicodeString(&uni, 0) sets Buffer to %p, expected %p\n",
316 HeapFree(GetProcessHeap(), 0, teststring2
);
323 int source_MaximumLength
;
325 const char *source_buf
;
327 int dest_MaximumLength
;
329 const char *dest_buf
;
331 int res_MaximumLength
;
337 static const dupl_ustr_t dupl_ustr
[] = {
338 { 0, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 32, 32, "This is a string", STATUS_SUCCESS
},
339 { 0, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 32, 32, "This is a string", STATUS_SUCCESS
},
340 { 0, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
341 { 0, 32, 34, 34, "This is a string", 40, 42, 42, NULL
, 32, 32, 32, "This is a string", STATUS_SUCCESS
},
342 { 0, 32, 32, 32, "This is a string", 40, 42, 42, NULL
, 32, 32, 32, "This is a string", STATUS_SUCCESS
},
343 { 0, 32, 30, 34, "This is a string", 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
344 { 1, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS
},
345 { 1, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS
},
346 { 1, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
347 { 1, 32, 34, 34, "This is a string", 40, 42, 42, NULL
, 32, 34, 34, "This is a string", STATUS_SUCCESS
},
348 { 1, 32, 32, 32, "This is a string", 40, 42, 42, NULL
, 32, 34, 34, "This is a string", STATUS_SUCCESS
},
349 { 1, 32, 30, 34, "This is a string", 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
350 { 2, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
351 { 2, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
352 { 2, 32, 30, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
353 { 2, 32, 34, 34, "This is a string", 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
354 { 2, 32, 32, 32, "This is a string", 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
355 { 2, 32, 30, 34, "This is a string", 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
356 { 3, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS
},
357 { 3, 32, 32, 32, "This is a string", 40, 42, 42, "--------------------", 32, 34, 34, "This is a string", STATUS_SUCCESS
},
358 { 3, 32, 30, 32, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
359 { 3, 32, 34, 34, "This is a string", 40, 42, 42, NULL
, 32, 34, 34, "This is a string", STATUS_SUCCESS
},
360 { 3, 32, 32, 32, "This is a string", 40, 42, 42, NULL
, 32, 34, 34, "This is a string", STATUS_SUCCESS
},
361 { 3, 32, 30, 32, "This is a string", 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
362 { 4, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
363 { 5, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
364 { 6, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
365 { 7, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
366 { 8, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
367 { 9, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
368 {10, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
369 {11, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
370 {12, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
371 {13, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
372 {14, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
373 {15, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
374 {16, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
375 {-1, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
376 {-5, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
377 {-9, 32, 34, 34, "This is a string", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
378 { 0, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL
, STATUS_SUCCESS
},
379 { 0, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL
, STATUS_SUCCESS
},
380 { 0, 0, 2, 2, "", 40, 42, 42, NULL
, 0, 0, 0, NULL
, STATUS_SUCCESS
},
381 { 0, 0, 0, 0, "", 40, 42, 42, NULL
, 0, 0, 0, NULL
, STATUS_SUCCESS
},
382 { 0, 0, 2, 2, NULL
, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
383 { 0, 0, 0, 0, NULL
, 40, 42, 42, "--------------------", 0, 0, 0, NULL
, STATUS_SUCCESS
},
384 { 0, 0, 2, 2, NULL
, 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
385 { 0, 0, 0, 0, NULL
, 40, 42, 42, NULL
, 0, 0, 0, NULL
, STATUS_SUCCESS
},
386 { 1, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL
, STATUS_SUCCESS
},
387 { 1, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 0, 0, NULL
, STATUS_SUCCESS
},
388 { 1, 0, 2, 2, "", 40, 42, 42, NULL
, 0, 0, 0, NULL
, STATUS_SUCCESS
},
389 { 1, 0, 0, 0, "", 40, 42, 42, NULL
, 0, 0, 0, NULL
, STATUS_SUCCESS
},
390 { 1, 0, 2, 2, NULL
, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
391 { 1, 0, 0, 0, NULL
, 40, 42, 42, "--------------------", 0, 0, 0, NULL
, STATUS_SUCCESS
},
392 { 1, 0, 2, 2, NULL
, 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
393 { 1, 0, 0, 0, NULL
, 40, 42, 42, NULL
, 0, 0, 0, NULL
, STATUS_SUCCESS
},
394 { 2, 0, 2, 2, "", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
395 { 2, 0, 0, 0, "", 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
396 { 2, 0, 2, 2, "", 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
397 { 2, 0, 0, 0, "", 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
398 { 2, 0, 2, 2, NULL
, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
399 { 2, 0, 0, 0, NULL
, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
400 { 2, 0, 2, 2, NULL
, 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
401 { 2, 0, 0, 0, NULL
, 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
402 { 3, 0, 2, 2, "", 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS
},
403 { 3, 0, 0, 0, "", 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS
},
404 { 3, 0, 2, 2, "", 40, 42, 42, NULL
, 0, 2, 2, "", STATUS_SUCCESS
},
405 { 3, 0, 0, 0, "", 40, 42, 42, NULL
, 0, 2, 2, "", STATUS_SUCCESS
},
406 { 3, 0, 2, 2, NULL
, 40, 42, 42, "--------------------", 40, 42, 42, "--------------------", STATUS_INVALID_PARAMETER
},
407 { 3, 0, 0, 0, NULL
, 40, 42, 42, "--------------------", 0, 2, 2, "", STATUS_SUCCESS
},
408 { 3, 0, 2, 2, NULL
, 40, 42, 42, NULL
, 40, 42, 0, NULL
, STATUS_INVALID_PARAMETER
},
409 { 3, 0, 0, 0, NULL
, 40, 42, 42, NULL
, 0, 2, 2, "", STATUS_SUCCESS
},
413 static void test_RtlDuplicateUnicodeString(void)
416 WCHAR source_buf
[257];
419 UNICODE_STRING source_str
;
420 UNICODE_STRING dest_str
;
421 UNICODE_STRING res_str
;
422 CHAR dest_ansi_buf
[257];
423 STRING dest_ansi_str
;
425 unsigned int test_num
;
427 if (!pRtlDuplicateUnicodeString
)
429 win_skip("RtlDuplicateUnicodeString is not available\n");
433 for (test_num
= 0; test_num
< ARRAY_SIZE(dupl_ustr
); test_num
++) {
434 source_str
.Length
= dupl_ustr
[test_num
].source_Length
;
435 source_str
.MaximumLength
= dupl_ustr
[test_num
].source_MaximumLength
;
436 if (dupl_ustr
[test_num
].source_buf
!= NULL
) {
437 for (pos
= 0; pos
< dupl_ustr
[test_num
].source_buf_size
/sizeof(WCHAR
); pos
++) {
438 source_buf
[pos
] = dupl_ustr
[test_num
].source_buf
[pos
];
440 source_str
.Buffer
= source_buf
;
442 source_str
.Buffer
= NULL
;
444 dest_str
.Length
= dupl_ustr
[test_num
].dest_Length
;
445 dest_str
.MaximumLength
= dupl_ustr
[test_num
].dest_MaximumLength
;
446 if (dupl_ustr
[test_num
].dest_buf
!= NULL
) {
447 for (pos
= 0; pos
< dupl_ustr
[test_num
].dest_buf_size
/sizeof(WCHAR
); pos
++) {
448 dest_buf
[pos
] = dupl_ustr
[test_num
].dest_buf
[pos
];
450 dest_str
.Buffer
= dest_buf
;
452 dest_str
.Buffer
= NULL
;
454 res_str
.Length
= dupl_ustr
[test_num
].res_Length
;
455 res_str
.MaximumLength
= dupl_ustr
[test_num
].res_MaximumLength
;
456 if (dupl_ustr
[test_num
].res_buf
!= NULL
) {
457 for (pos
= 0; pos
< dupl_ustr
[test_num
].res_buf_size
/sizeof(WCHAR
); pos
++) {
458 res_buf
[pos
] = dupl_ustr
[test_num
].res_buf
[pos
];
460 res_str
.Buffer
= res_buf
;
462 res_str
.Buffer
= NULL
;
464 result
= pRtlDuplicateUnicodeString(dupl_ustr
[test_num
].add_nul
, &source_str
, &dest_str
);
465 dest_ansi_str
.Length
= dest_str
.Length
/ sizeof(WCHAR
);
466 dest_ansi_str
.MaximumLength
= dest_ansi_str
.Length
+ 1;
467 for (pos
= 0; pos
< dest_ansi_str
.Length
; pos
++) {
468 dest_ansi_buf
[pos
] = (char)dest_buf
[pos
];
470 dest_ansi_buf
[dest_ansi_str
.Length
] = '\0';
471 dest_ansi_str
.Buffer
= dest_ansi_buf
;
472 ok(result
== dupl_ustr
[test_num
].result
,
473 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has result %x, expected %x\n",
474 test_num
, dupl_ustr
[test_num
].add_nul
, result
, dupl_ustr
[test_num
].result
);
475 ok(dest_str
.Length
== dupl_ustr
[test_num
].res_Length
,
476 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination has Length %d, expected %d\n",
477 test_num
, dupl_ustr
[test_num
].add_nul
, dest_str
.Length
, dupl_ustr
[test_num
].res_Length
);
478 ok(dest_str
.MaximumLength
== dupl_ustr
[test_num
].res_MaximumLength
,
479 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination has MaximumLength %d, expected %d\n",
480 test_num
, dupl_ustr
[test_num
].add_nul
, dest_str
.MaximumLength
, dupl_ustr
[test_num
].res_MaximumLength
);
481 if (result
== STATUS_INVALID_PARAMETER
) {
482 ok((dest_str
.Buffer
== NULL
&& res_str
.Buffer
== NULL
) ||
483 dest_str
.Buffer
== dest_buf
,
484 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) destination buffer changed %p expected %p\n",
485 test_num
, dupl_ustr
[test_num
].add_nul
, dest_str
.Buffer
, dest_buf
);
487 ok(dest_str
.Buffer
!= dest_buf
,
488 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination buffer unchanged %p\n",
489 test_num
, dupl_ustr
[test_num
].add_nul
, dest_str
.Buffer
);
491 if (dest_str
.Buffer
!= NULL
&& dupl_ustr
[test_num
].res_buf
!= NULL
) {
492 ok(memcmp(dest_str
.Buffer
, res_str
.Buffer
, dupl_ustr
[test_num
].res_buf_size
) == 0,
493 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination \"%s\" expected \"%s\"\n",
494 test_num
, dupl_ustr
[test_num
].add_nul
, dest_ansi_str
.Buffer
, dupl_ustr
[test_num
].res_buf
);
495 if(result
== STATUS_SUCCESS
) pRtlFreeUnicodeString(&dest_str
);
497 ok(dest_str
.Buffer
== NULL
&& dupl_ustr
[test_num
].res_buf
== NULL
,
498 "(test %d): RtlDuplicateUnicodeString(%d, source, dest) has destination %p expected %p\n",
499 test_num
, dupl_ustr
[test_num
].add_nul
, dest_str
.Buffer
, dupl_ustr
[test_num
].res_buf
);
505 static void test_RtlCopyString(void)
507 static const char teststring
[] = "Some Wild String";
508 char deststring
[] = " ";
512 pRtlInitString(&str
, teststring
);
513 pRtlInitString(&deststr
, deststring
);
514 pRtlCopyString(&deststr
, &str
);
515 ok(strncmp(str
.Buffer
, deststring
, str
.Length
) == 0, "String not copied\n");
519 static void test_RtlUpperChar(void)
523 int expected_upper_ch
;
526 for (ch
= -1; ch
<= 1024; ch
++) {
527 upper_ch
= pRtlUpperChar(ch
);
529 if (byte_ch
>= 'a' && byte_ch
<= 'z') {
530 expected_upper_ch
= (CHAR
) (byte_ch
- 'a' + 'A');
532 expected_upper_ch
= (CHAR
) byte_ch
;
534 ok(upper_ch
== expected_upper_ch
,
535 "RtlUpperChar('%c'[=0x%x]) has result '%c'[=0x%x], expected '%c'[=0x%x]\n",
536 ch
, ch
, upper_ch
, upper_ch
, expected_upper_ch
, expected_upper_ch
);
541 static void test_RtlUpperString(void)
547 char result_buf
[257];
553 for (i
= 0; i
<= 255; i
++) {
555 if (ch
>= 'a' && ch
<= 'z') {
556 upper_ch
= ch
- 'a' + 'A';
561 result_buf
[i
] = '\0';
562 upper_buf
[i
] = upper_ch
;
565 result_buf
[i
] = '\0';
567 ascii_str
.Length
= 256;
568 ascii_str
.MaximumLength
= 256;
569 ascii_str
.Buffer
= ascii_buf
;
570 result_str
.Length
= 256;
571 result_str
.MaximumLength
= 256;
572 result_str
.Buffer
= result_buf
;
573 upper_str
.Length
= 256;
574 upper_str
.MaximumLength
= 256;
575 upper_str
.Buffer
= upper_buf
;
577 pRtlUpperString(&result_str
, &ascii_str
);
578 ok(memcmp(result_str
.Buffer
, upper_str
.Buffer
, 256) == 0,
579 "RtlUpperString does not work as expected\n");
583 static void test_RtlUpcaseUnicodeChar(void)
588 WCHAR expected_upper_ch
;
590 for (i
= 0; i
<= 255; i
++) {
592 upper_ch
= pRtlUpcaseUnicodeChar(ch
);
593 if (ch
>= 'a' && ch
<= 'z') {
594 expected_upper_ch
= ch
- 'a' + 'A';
595 } else if (ch
>= 0xe0 && ch
<= 0xfe && ch
!= 0xf7) {
596 expected_upper_ch
= ch
- 0x20;
597 } else if (ch
== 0xff) {
598 expected_upper_ch
= 0x178;
600 expected_upper_ch
= ch
;
602 ok(upper_ch
== expected_upper_ch
,
603 "RtlUpcaseUnicodeChar('%c'[=0x%x]) has result '%c'[=0x%x], expected: '%c'[=0x%x]\n",
604 ch
, ch
, upper_ch
, upper_ch
, expected_upper_ch
, expected_upper_ch
);
609 static void test_RtlUpcaseUnicodeString(void)
614 WCHAR ascii_buf
[257];
615 WCHAR result_buf
[257];
616 WCHAR upper_buf
[257];
617 UNICODE_STRING ascii_str
;
618 UNICODE_STRING result_str
;
619 UNICODE_STRING upper_str
;
621 for (i
= 0; i
<= 255; i
++) {
623 if (ch
>= 'a' && ch
<= 'z') {
624 upper_ch
= ch
- 'a' + 'A';
625 } else if (ch
>= 0xe0 && ch
<= 0xfe && ch
!= 0xf7) {
626 upper_ch
= ch
- 0x20;
627 } else if (ch
== 0xff) {
633 result_buf
[i
] = '\0';
634 upper_buf
[i
] = upper_ch
;
637 result_buf
[i
] = '\0';
639 ascii_str
.Length
= 512;
640 ascii_str
.MaximumLength
= 512;
641 ascii_str
.Buffer
= ascii_buf
;
642 result_str
.Length
= 512;
643 result_str
.MaximumLength
= 512;
644 result_str
.Buffer
= result_buf
;
645 upper_str
.Length
= 512;
646 upper_str
.MaximumLength
= 512;
647 upper_str
.Buffer
= upper_buf
;
649 pRtlUpcaseUnicodeString(&result_str
, &ascii_str
, 0);
650 for (i
= 0; i
<= 255; i
++) {
651 ok(result_str
.Buffer
[i
] == upper_str
.Buffer
[i
],
652 "RtlUpcaseUnicodeString works wrong: '%c'[=0x%x] is converted to '%c'[=0x%x], expected: '%c'[=0x%x]\n",
653 ascii_str
.Buffer
[i
], ascii_str
.Buffer
[i
],
654 result_str
.Buffer
[i
], result_str
.Buffer
[i
],
655 upper_str
.Buffer
[i
], upper_str
.Buffer
[i
]);
660 static void test_RtlDowncaseUnicodeString(void)
665 WCHAR source_buf
[1025];
666 WCHAR result_buf
[1025];
667 WCHAR lower_buf
[1025];
668 UNICODE_STRING source_str
;
669 UNICODE_STRING result_str
;
670 UNICODE_STRING lower_str
;
672 for (i
= 0; i
< 1024; i
++) {
674 if (ch
>= 'A' && ch
<= 'Z') {
675 lower_ch
= ch
- 'A' + 'a';
676 } else if (ch
>= 0xc0 && ch
<= 0xde && ch
!= 0xd7) {
677 lower_ch
= ch
+ 0x20;
678 } else if (ch
>= 0x391 && ch
<= 0x3ab && ch
!= 0x3a2) {
679 lower_ch
= ch
+ 0x20;
682 case 0x178: lower_ch
= 0xff; break;
683 case 0x181: lower_ch
= 0x253; break;
684 case 0x186: lower_ch
= 0x254; break;
685 case 0x189: lower_ch
= 0x256; break;
686 case 0x18a: lower_ch
= 0x257; break;
687 case 0x18e: lower_ch
= 0x1dd; break;
688 case 0x18f: lower_ch
= 0x259; break;
689 case 0x190: lower_ch
= 0x25b; break;
690 case 0x193: lower_ch
= 0x260; break;
691 case 0x194: lower_ch
= 0x263; break;
692 case 0x196: lower_ch
= 0x269; break;
693 case 0x197: lower_ch
= 0x268; break;
694 case 0x19c: lower_ch
= 0x26f; break;
695 case 0x19d: lower_ch
= 0x272; break;
696 case 0x19f: lower_ch
= 0x275; break;
697 case 0x1a9: lower_ch
= 0x283; break;
698 case 0x1a6: lower_ch
= 0x280; break;
699 case 0x1ae: lower_ch
= 0x288; break;
700 case 0x1b1: lower_ch
= 0x28a; break;
701 case 0x1b2: lower_ch
= 0x28b; break;
702 case 0x1b7: lower_ch
= 0x292; break;
703 case 0x1c4: lower_ch
= 0x1c6; break;
704 case 0x1c7: lower_ch
= 0x1c9; break;
705 case 0x1ca: lower_ch
= 0x1cc; break;
706 case 0x1f1: lower_ch
= 0x1f3; break;
707 case 0x1f6: lower_ch
= 0x195; break;
708 case 0x1f7: lower_ch
= 0x1bf; break;
709 case 0x220: lower_ch
= 0x19e; break;
710 case 0x23a: lower_ch
= 0x2c65; break;
711 case 0x23d: lower_ch
= 0x19a; break;
712 case 0x23e: lower_ch
= 0x2c66; break;
713 case 0x243: lower_ch
= 0x180; break;
714 case 0x244: lower_ch
= 0x289; break;
715 case 0x245: lower_ch
= 0x28c; break;
716 case 0x37f: lower_ch
= 0x3f3; break;
717 case 0x386: lower_ch
= 0x3ac; break;
718 case 0x388: lower_ch
= 0x3ad; break;
719 case 0x389: lower_ch
= 0x3ae; break;
720 case 0x38a: lower_ch
= 0x3af; break;
721 case 0x38c: lower_ch
= 0x3cc; break;
722 case 0x38e: lower_ch
= 0x3cd; break;
723 case 0x38f: lower_ch
= 0x3ce; break;
724 case 0x3cf: lower_ch
= 0x3d7; break;
725 case 0x3f9: lower_ch
= 0x3f2; break;
726 case 0x3fd: lower_ch
= 0x37b; break;
727 case 0x3fe: lower_ch
= 0x37c; break;
728 case 0x3ff: lower_ch
= 0x37d; break;
729 default: lower_ch
= ch
; break;
733 result_buf
[i
] = '\0';
734 lower_buf
[i
] = lower_ch
;
736 source_buf
[i
] = '\0';
737 result_buf
[i
] = '\0';
739 source_str
.Length
= 2048;
740 source_str
.MaximumLength
= 2048;
741 source_str
.Buffer
= source_buf
;
742 result_str
.Length
= 2048;
743 result_str
.MaximumLength
= 2048;
744 result_str
.Buffer
= result_buf
;
745 lower_str
.Length
= 2048;
746 lower_str
.MaximumLength
= 2048;
747 lower_str
.Buffer
= lower_buf
;
749 pRtlDowncaseUnicodeString(&result_str
, &source_str
, 0);
750 for (i
= 0; i
<= 1024; i
++) {
751 ok(result_str
.Buffer
[i
] == lower_str
.Buffer
[i
] || result_str
.Buffer
[i
] == source_str
.Buffer
[i
] + 1 ||
752 broken( result_str
.Buffer
[i
] == source_str
.Buffer
[i
] ),
753 "RtlDowncaseUnicodeString works wrong: '%c'[=0x%x] is converted to '%c'[=0x%x], expected: '%c'[=0x%x]\n",
754 source_str
.Buffer
[i
], source_str
.Buffer
[i
],
755 result_str
.Buffer
[i
], result_str
.Buffer
[i
],
756 lower_str
.Buffer
[i
], lower_str
.Buffer
[i
]);
763 int ansi_MaximumLength
;
765 const char *ansi_buf
;
767 int uni_MaximumLength
;
772 int res_MaximumLength
;
778 static const ustr2astr_t ustr2astr
[] = {
779 { 10, 12, 12, "------------", 0, 0, 0, "", TRUE
, 0, 1, 1, "", STATUS_SUCCESS
},
780 { 10, 12, 12, "------------", 12, 12, 12, "abcdef", TRUE
, 6, 7, 7, "abcdef", STATUS_SUCCESS
},
781 { 0, 2, 12, "------------", 12, 12, 12, "abcdef", TRUE
, 6, 7, 7, "abcdef", STATUS_SUCCESS
},
782 { 10, 12, 12, NULL
, 12, 12, 12, "abcdef", TRUE
, 6, 7, 7, "abcdef", STATUS_SUCCESS
},
783 { 0, 0, 12, "------------", 12, 12, 12, "abcdef", FALSE
, 6, 0, 0, "", STATUS_BUFFER_OVERFLOW
},
784 { 0, 1, 12, "------------", 12, 12, 12, "abcdef", FALSE
, 0, 1, 1, "", STATUS_BUFFER_OVERFLOW
},
785 { 0, 2, 12, "------------", 12, 12, 12, "abcdef", FALSE
, 1, 2, 2, "a", STATUS_BUFFER_OVERFLOW
},
786 { 0, 3, 12, "------------", 12, 12, 12, "abcdef", FALSE
, 2, 3, 3, "ab", STATUS_BUFFER_OVERFLOW
},
787 { 0, 5, 12, "------------", 12, 12, 12, "abcdef", FALSE
, 4, 5, 5, "abcd", STATUS_BUFFER_OVERFLOW
},
788 { 8, 5, 12, "------------", 12, 12, 12, "abcdef", FALSE
, 4, 5, 5, "abcd", STATUS_BUFFER_OVERFLOW
},
789 { 8, 6, 12, "------------", 12, 12, 12, "abcdef", FALSE
, 5, 6, 6, "abcde", STATUS_BUFFER_OVERFLOW
},
790 { 8, 7, 12, "------------", 12, 12, 12, "abcdef", FALSE
, 6, 7, 7, "abcdef", STATUS_SUCCESS
},
791 { 8, 7, 12, "------------", 0, 12, 12, NULL
, FALSE
, 0, 7, 0, "", STATUS_SUCCESS
},
793 /* crashes on Japanese and Chinese XP */
794 { 0, 0, 12, NULL
, 10, 10, 12, NULL
, FALSE
, 5, 0, 0, NULL
, STATUS_BUFFER_OVERFLOW
},
799 static void test_RtlUnicodeStringToAnsiString(void)
805 UNICODE_STRING uni_str
;
807 unsigned int test_num
;
809 for (test_num
= 0; test_num
< ARRAY_SIZE(ustr2astr
); test_num
++) {
810 ansi_str
.Length
= ustr2astr
[test_num
].ansi_Length
;
811 ansi_str
.MaximumLength
= ustr2astr
[test_num
].ansi_MaximumLength
;
812 if (ustr2astr
[test_num
].ansi_buf
!= NULL
) {
813 memcpy(ansi_buf
, ustr2astr
[test_num
].ansi_buf
, ustr2astr
[test_num
].ansi_buf_size
);
814 ansi_buf
[ustr2astr
[test_num
].ansi_buf_size
] = '\0';
815 ansi_str
.Buffer
= ansi_buf
;
817 ansi_str
.Buffer
= NULL
;
819 uni_str
.Length
= ustr2astr
[test_num
].uni_Length
;
820 uni_str
.MaximumLength
= ustr2astr
[test_num
].uni_MaximumLength
;
821 if (ustr2astr
[test_num
].uni_buf
!= NULL
) {
822 for (pos
= 0; pos
< ustr2astr
[test_num
].uni_buf_size
/sizeof(WCHAR
); pos
++) {
823 uni_buf
[pos
] = ustr2astr
[test_num
].uni_buf
[pos
];
825 uni_str
.Buffer
= uni_buf
;
827 uni_str
.Buffer
= NULL
;
829 result
= pRtlUnicodeStringToAnsiString(&ansi_str
, &uni_str
, ustr2astr
[test_num
].doalloc
);
830 ok(result
== ustr2astr
[test_num
].result
,
831 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) has result %x, expected %x\n",
832 test_num
, ustr2astr
[test_num
].doalloc
, result
, ustr2astr
[test_num
].result
);
833 ok(ansi_str
.Length
== ustr2astr
[test_num
].res_Length
,
834 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) ansi has Length %d, expected %d\n",
835 test_num
, ustr2astr
[test_num
].doalloc
, ansi_str
.Length
, ustr2astr
[test_num
].res_Length
);
836 ok(ansi_str
.MaximumLength
== ustr2astr
[test_num
].res_MaximumLength
,
837 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) ansi has MaximumLength %d, expected %d\n",
838 test_num
, ustr2astr
[test_num
].doalloc
, ansi_str
.MaximumLength
, ustr2astr
[test_num
].res_MaximumLength
);
839 ok(memcmp(ansi_str
.Buffer
, ustr2astr
[test_num
].res_buf
, ustr2astr
[test_num
].res_buf_size
) == 0,
840 "(test %d): RtlUnicodeStringToAnsiString(ansi, uni, %d) has ansi \"%s\" expected \"%s\"\n",
841 test_num
, ustr2astr
[test_num
].doalloc
, ansi_str
.Buffer
, ustr2astr
[test_num
].res_buf
);
842 if(result
== STATUS_SUCCESS
&& ustr2astr
[test_num
].doalloc
)
843 pRtlFreeAnsiString(&ansi_str
);
850 int dest_MaximumLength
;
852 const char *dest_buf
;
855 int res_MaximumLength
;
861 static const app_asc2str_t app_asc2str
[] = {
862 { 5, 12, 15, "TestS01234abcde", "tring", 10, 12, 15, "TestStringabcde", STATUS_SUCCESS
},
863 { 5, 11, 15, "TestS01234abcde", "tring", 10, 11, 15, "TestStringabcde", STATUS_SUCCESS
},
864 { 5, 10, 15, "TestS01234abcde", "tring", 10, 10, 15, "TestStringabcde", STATUS_SUCCESS
},
865 { 5, 9, 15, "TestS01234abcde", "tring", 5, 9, 15, "TestS01234abcde", STATUS_BUFFER_TOO_SMALL
},
866 { 5, 0, 15, "TestS01234abcde", "tring", 5, 0, 15, "TestS01234abcde", STATUS_BUFFER_TOO_SMALL
},
867 { 5, 14, 15, "TestS01234abcde", "tring", 10, 14, 15, "TestStringabcde", STATUS_SUCCESS
},
868 { 5, 14, 15, "TestS01234abcde", NULL
, 5, 14, 15, "TestS01234abcde", STATUS_SUCCESS
},
869 { 5, 14, 15, NULL
, NULL
, 5, 14, 15, NULL
, STATUS_SUCCESS
},
870 { 5, 12, 15, "Tst\0S01234abcde", "tr\0i", 7, 12, 15, "Tst\0Str234abcde", STATUS_SUCCESS
},
874 static void test_RtlAppendAsciizToString(void)
879 unsigned int test_num
;
881 for (test_num
= 0; test_num
< ARRAY_SIZE(app_asc2str
); test_num
++) {
882 dest_str
.Length
= app_asc2str
[test_num
].dest_Length
;
883 dest_str
.MaximumLength
= app_asc2str
[test_num
].dest_MaximumLength
;
884 if (app_asc2str
[test_num
].dest_buf
!= NULL
) {
885 memcpy(dest_buf
, app_asc2str
[test_num
].dest_buf
, app_asc2str
[test_num
].dest_buf_size
);
886 dest_buf
[app_asc2str
[test_num
].dest_buf_size
] = '\0';
887 dest_str
.Buffer
= dest_buf
;
889 dest_str
.Buffer
= NULL
;
891 result
= pRtlAppendAsciizToString(&dest_str
, app_asc2str
[test_num
].src
);
892 ok(result
== app_asc2str
[test_num
].result
,
893 "(test %d): RtlAppendAsciizToString(dest, src) has result %x, expected %x\n",
894 test_num
, result
, app_asc2str
[test_num
].result
);
895 ok(dest_str
.Length
== app_asc2str
[test_num
].res_Length
,
896 "(test %d): RtlAppendAsciizToString(dest, src) dest has Length %d, expected %d\n",
897 test_num
, dest_str
.Length
, app_asc2str
[test_num
].res_Length
);
898 ok(dest_str
.MaximumLength
== app_asc2str
[test_num
].res_MaximumLength
,
899 "(test %d): RtlAppendAsciizToString(dest, src) dest has MaximumLength %d, expected %d\n",
900 test_num
, dest_str
.MaximumLength
, app_asc2str
[test_num
].res_MaximumLength
);
901 if (dest_str
.Buffer
== dest_buf
) {
902 ok(memcmp(dest_buf
, app_asc2str
[test_num
].res_buf
, app_asc2str
[test_num
].res_buf_size
) == 0,
903 "(test %d): RtlAppendAsciizToString(dest, src) has dest \"%s\" expected \"%s\"\n",
904 test_num
, dest_buf
, app_asc2str
[test_num
].res_buf
);
906 ok(dest_str
.Buffer
== app_asc2str
[test_num
].res_buf
,
907 "(test %d): RtlAppendAsciizToString(dest, src) dest has Buffer %p expected %p\n",
908 test_num
, dest_str
.Buffer
, app_asc2str
[test_num
].res_buf
);
916 int dest_MaximumLength
;
918 const char *dest_buf
;
920 int src_MaximumLength
;
924 int res_MaximumLength
;
930 static const app_str2str_t app_str2str
[] = {
931 { 5, 12, 15, "TestS01234abcde", 5, 5, 7, "tringZY", 10, 12, 15, "TestStringabcde", STATUS_SUCCESS
},
932 { 5, 11, 15, "TestS01234abcde", 5, 5, 7, "tringZY", 10, 11, 15, "TestStringabcde", STATUS_SUCCESS
},
933 { 5, 10, 15, "TestS01234abcde", 5, 5, 7, "tringZY", 10, 10, 15, "TestStringabcde", STATUS_SUCCESS
},
934 { 5, 9, 15, "TestS01234abcde", 5, 5, 7, "tringZY", 5, 9, 15, "TestS01234abcde", STATUS_BUFFER_TOO_SMALL
},
935 { 5, 0, 15, "TestS01234abcde", 0, 0, 7, "tringZY", 5, 0, 15, "TestS01234abcde", STATUS_SUCCESS
},
936 { 5, 14, 15, "TestS01234abcde", 0, 0, 7, "tringZY", 5, 14, 15, "TestS01234abcde", STATUS_SUCCESS
},
937 { 5, 14, 15, "TestS01234abcde", 0, 0, 7, NULL
, 5, 14, 15, "TestS01234abcde", STATUS_SUCCESS
},
938 { 5, 14, 15, NULL
, 0, 0, 7, NULL
, 5, 14, 15, NULL
, STATUS_SUCCESS
},
939 { 5, 12, 15, "Tst\0S01234abcde", 4, 4, 7, "tr\0iZY", 9, 12, 15, "Tst\0Str\0i4abcde", STATUS_SUCCESS
},
943 static void test_RtlAppendStringToString(void)
950 unsigned int test_num
;
952 for (test_num
= 0; test_num
< ARRAY_SIZE(app_str2str
); test_num
++) {
953 dest_str
.Length
= app_str2str
[test_num
].dest_Length
;
954 dest_str
.MaximumLength
= app_str2str
[test_num
].dest_MaximumLength
;
955 if (app_str2str
[test_num
].dest_buf
!= NULL
) {
956 memcpy(dest_buf
, app_str2str
[test_num
].dest_buf
, app_str2str
[test_num
].dest_buf_size
);
957 dest_buf
[app_str2str
[test_num
].dest_buf_size
] = '\0';
958 dest_str
.Buffer
= dest_buf
;
960 dest_str
.Buffer
= NULL
;
962 src_str
.Length
= app_str2str
[test_num
].src_Length
;
963 src_str
.MaximumLength
= app_str2str
[test_num
].src_MaximumLength
;
964 if (app_str2str
[test_num
].src_buf
!= NULL
) {
965 memcpy(src_buf
, app_str2str
[test_num
].src_buf
, app_str2str
[test_num
].src_buf_size
);
966 src_buf
[app_str2str
[test_num
].src_buf_size
] = '\0';
967 src_str
.Buffer
= src_buf
;
969 src_str
.Buffer
= NULL
;
971 result
= pRtlAppendStringToString(&dest_str
, &src_str
);
972 ok(result
== app_str2str
[test_num
].result
,
973 "(test %d): RtlAppendStringToString(dest, src) has result %x, expected %x\n",
974 test_num
, result
, app_str2str
[test_num
].result
);
975 ok(dest_str
.Length
== app_str2str
[test_num
].res_Length
,
976 "(test %d): RtlAppendStringToString(dest, src) dest has Length %d, expected %d\n",
977 test_num
, dest_str
.Length
, app_str2str
[test_num
].res_Length
);
978 ok(dest_str
.MaximumLength
== app_str2str
[test_num
].res_MaximumLength
,
979 "(test %d): RtlAppendStringToString(dest, src) dest has MaximumLength %d, expected %d\n",
980 test_num
, dest_str
.MaximumLength
, app_str2str
[test_num
].res_MaximumLength
);
981 if (dest_str
.Buffer
== dest_buf
) {
982 ok(memcmp(dest_buf
, app_str2str
[test_num
].res_buf
, app_str2str
[test_num
].res_buf_size
) == 0,
983 "(test %d): RtlAppendStringToString(dest, src) has dest \"%s\" expected \"%s\"\n",
984 test_num
, dest_buf
, app_str2str
[test_num
].res_buf
);
986 ok(dest_str
.Buffer
== app_str2str
[test_num
].res_buf
,
987 "(test %d): RtlAppendStringToString(dest, src) dest has Buffer %p expected %p\n",
988 test_num
, dest_str
.Buffer
, app_str2str
[test_num
].res_buf
);
996 int dest_MaximumLength
;
998 const char *dest_buf
;
1001 int res_MaximumLength
;
1003 const char *res_buf
;
1007 static const app_uni2str_t app_uni2str
[] = {
1008 { 4, 12, 14, "Fake0123abcdef", "Ustr\0", 8, 12, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS
},
1009 { 4, 11, 14, "Fake0123abcdef", "Ustr\0", 8, 11, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS
},
1010 { 4, 10, 14, "Fake0123abcdef", "Ustr\0", 8, 10, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS
},
1011 /* In the following test the native function writes beyond MaximumLength
1012 * { 4, 9, 14, "Fake0123abcdef", "Ustr\0", 8, 9, 14, "FakeUstrabcdef", STATUS_SUCCESS},
1014 { 4, 8, 14, "Fake0123abcdef", "Ustr\0", 8, 8, 14, "FakeUstrabcdef", STATUS_SUCCESS
},
1015 { 4, 7, 14, "Fake0123abcdef", "Ustr\0", 4, 7, 14, "Fake0123abcdef", STATUS_BUFFER_TOO_SMALL
},
1016 { 4, 0, 14, "Fake0123abcdef", "Ustr\0", 4, 0, 14, "Fake0123abcdef", STATUS_BUFFER_TOO_SMALL
},
1017 { 4, 14, 14, "Fake0123abcdef", "Ustr\0", 8, 14, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS
},
1018 { 4, 14, 14, "Fake0123abcdef", NULL
, 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS
},
1019 { 4, 14, 14, NULL
, NULL
, 4, 14, 14, NULL
, STATUS_SUCCESS
},
1020 { 4, 14, 14, "Fake0123abcdef", "U\0stri\0", 10, 14, 14, "FakeU\0stri\0\0ef", STATUS_SUCCESS
},
1021 { 6, 14, 16, "Te\0\0stabcdefghij", "St\0\0ri", 8, 14, 16, "Te\0\0stSt\0\0efghij", STATUS_SUCCESS
},
1025 static void test_RtlAppendUnicodeToString(void)
1027 WCHAR dest_buf
[257];
1028 UNICODE_STRING dest_str
;
1030 unsigned int test_num
;
1032 for (test_num
= 0; test_num
< ARRAY_SIZE(app_uni2str
); test_num
++) {
1033 dest_str
.Length
= app_uni2str
[test_num
].dest_Length
;
1034 dest_str
.MaximumLength
= app_uni2str
[test_num
].dest_MaximumLength
;
1035 if (app_uni2str
[test_num
].dest_buf
!= NULL
) {
1036 memcpy(dest_buf
, app_uni2str
[test_num
].dest_buf
, app_uni2str
[test_num
].dest_buf_size
);
1037 dest_buf
[app_uni2str
[test_num
].dest_buf_size
/sizeof(WCHAR
)] = '\0';
1038 dest_str
.Buffer
= dest_buf
;
1040 dest_str
.Buffer
= NULL
;
1042 result
= pRtlAppendUnicodeToString(&dest_str
, (LPCWSTR
) app_uni2str
[test_num
].src
);
1043 ok(result
== app_uni2str
[test_num
].result
,
1044 "(test %d): RtlAppendUnicodeToString(dest, src) has result %x, expected %x\n",
1045 test_num
, result
, app_uni2str
[test_num
].result
);
1046 ok(dest_str
.Length
== app_uni2str
[test_num
].res_Length
,
1047 "(test %d): RtlAppendUnicodeToString(dest, src) dest has Length %d, expected %d\n",
1048 test_num
, dest_str
.Length
, app_uni2str
[test_num
].res_Length
);
1049 ok(dest_str
.MaximumLength
== app_uni2str
[test_num
].res_MaximumLength
,
1050 "(test %d): RtlAppendUnicodeToString(dest, src) dest has MaximumLength %d, expected %d\n",
1051 test_num
, dest_str
.MaximumLength
, app_uni2str
[test_num
].res_MaximumLength
);
1052 if (dest_str
.Buffer
== dest_buf
) {
1053 ok(memcmp(dest_buf
, app_uni2str
[test_num
].res_buf
, app_uni2str
[test_num
].res_buf_size
) == 0,
1054 "(test %d): RtlAppendUnicodeToString(dest, src) has dest \"%s\" expected \"%s\"\n",
1055 test_num
, (char *) dest_buf
, app_uni2str
[test_num
].res_buf
);
1057 ok(dest_str
.Buffer
== (WCHAR
*) app_uni2str
[test_num
].res_buf
,
1058 "(test %d): RtlAppendUnicodeToString(dest, src) dest has Buffer %p expected %p\n",
1059 test_num
, dest_str
.Buffer
, app_uni2str
[test_num
].res_buf
);
1067 int dest_MaximumLength
;
1069 const char *dest_buf
;
1071 int src_MaximumLength
;
1073 const char *src_buf
;
1075 int res_MaximumLength
;
1077 const char *res_buf
;
1081 static const app_ustr2str_t app_ustr2str
[] = {
1082 { 4, 12, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 12, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS
},
1083 { 4, 11, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 11, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS
},
1084 { 4, 10, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 10, 14, "FakeUstr\0\0cdef", STATUS_SUCCESS
},
1085 /* In the following test the native function writes beyond MaximumLength
1086 * { 4, 9, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 9, 14, "FakeUstrabcdef", STATUS_SUCCESS},
1088 { 4, 8, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 8, 8, 14, "FakeUstrabcdef", STATUS_SUCCESS
},
1089 { 4, 7, 14, "Fake0123abcdef", 4, 6, 8, "UstrZYXW", 4, 7, 14, "Fake0123abcdef", STATUS_BUFFER_TOO_SMALL
},
1090 { 4, 0, 14, "Fake0123abcdef", 0, 0, 8, "UstrZYXW", 4, 0, 14, "Fake0123abcdef", STATUS_SUCCESS
},
1091 { 4, 14, 14, "Fake0123abcdef", 0, 0, 8, "UstrZYXW", 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS
},
1092 { 4, 14, 14, "Fake0123abcdef", 0, 0, 8, NULL
, 4, 14, 14, "Fake0123abcdef", STATUS_SUCCESS
},
1093 { 4, 14, 14, NULL
, 0, 0, 8, NULL
, 4, 14, 14, NULL
, STATUS_SUCCESS
},
1094 { 6, 14, 16, "Te\0\0stabcdefghij", 6, 8, 8, "St\0\0riZY", 12, 14, 16, "Te\0\0stSt\0\0ri\0\0ij", STATUS_SUCCESS
},
1098 static void test_RtlAppendUnicodeStringToString(void)
1100 WCHAR dest_buf
[257];
1102 UNICODE_STRING dest_str
;
1103 UNICODE_STRING src_str
;
1105 unsigned int test_num
;
1107 for (test_num
= 0; test_num
< ARRAY_SIZE(app_ustr2str
); test_num
++) {
1108 dest_str
.Length
= app_ustr2str
[test_num
].dest_Length
;
1109 dest_str
.MaximumLength
= app_ustr2str
[test_num
].dest_MaximumLength
;
1110 if (app_ustr2str
[test_num
].dest_buf
!= NULL
) {
1111 memcpy(dest_buf
, app_ustr2str
[test_num
].dest_buf
, app_ustr2str
[test_num
].dest_buf_size
);
1112 dest_buf
[app_ustr2str
[test_num
].dest_buf_size
/sizeof(WCHAR
)] = '\0';
1113 dest_str
.Buffer
= dest_buf
;
1115 dest_str
.Buffer
= NULL
;
1117 src_str
.Length
= app_ustr2str
[test_num
].src_Length
;
1118 src_str
.MaximumLength
= app_ustr2str
[test_num
].src_MaximumLength
;
1119 if (app_ustr2str
[test_num
].src_buf
!= NULL
) {
1120 memcpy(src_buf
, app_ustr2str
[test_num
].src_buf
, app_ustr2str
[test_num
].src_buf_size
);
1121 src_buf
[app_ustr2str
[test_num
].src_buf_size
/sizeof(WCHAR
)] = '\0';
1122 src_str
.Buffer
= src_buf
;
1124 src_str
.Buffer
= NULL
;
1126 result
= pRtlAppendUnicodeStringToString(&dest_str
, &src_str
);
1127 ok(result
== app_ustr2str
[test_num
].result
,
1128 "(test %d): RtlAppendStringToString(dest, src) has result %x, expected %x\n",
1129 test_num
, result
, app_ustr2str
[test_num
].result
);
1130 ok(dest_str
.Length
== app_ustr2str
[test_num
].res_Length
,
1131 "(test %d): RtlAppendStringToString(dest, src) dest has Length %d, expected %d\n",
1132 test_num
, dest_str
.Length
, app_ustr2str
[test_num
].res_Length
);
1133 ok(dest_str
.MaximumLength
== app_ustr2str
[test_num
].res_MaximumLength
,
1134 "(test %d): RtlAppendStringToString(dest, src) dest has MaximumLength %d, expected %d\n",
1135 test_num
, dest_str
.MaximumLength
, app_ustr2str
[test_num
].res_MaximumLength
);
1136 if (dest_str
.Buffer
== dest_buf
) {
1137 ok(memcmp(dest_buf
, app_ustr2str
[test_num
].res_buf
, app_ustr2str
[test_num
].res_buf_size
) == 0,
1138 "(test %d): RtlAppendStringToString(dest, src) has dest \"%s\" expected \"%s\"\n",
1139 test_num
, (char *) dest_buf
, app_ustr2str
[test_num
].res_buf
);
1141 ok(dest_str
.Buffer
== (WCHAR
*) app_ustr2str
[test_num
].res_buf
,
1142 "(test %d): RtlAppendStringToString(dest, src) dest has Buffer %p expected %p\n",
1143 test_num
, dest_str
.Buffer
, app_ustr2str
[test_num
].res_buf
);
1151 const char *main_str
;
1152 const char *search_chars
;
1155 } find_ch_in_ustr_t
;
1157 static const find_ch_in_ustr_t find_ch_in_ustr
[] = {
1158 { 0, "Some Wild String", "S", 2, STATUS_SUCCESS
},
1159 { 0, "This is a String", "String", 6, STATUS_SUCCESS
},
1160 { 1, "This is a String", "String", 30, STATUS_SUCCESS
},
1161 { 2, "This is a String", "String", 2, STATUS_SUCCESS
},
1162 { 3, "This is a String", "String", 18, STATUS_SUCCESS
},
1163 { 0, "This is a String", "Wild", 6, STATUS_SUCCESS
},
1164 { 1, "This is a String", "Wild", 26, STATUS_SUCCESS
},
1165 { 2, "This is a String", "Wild", 2, STATUS_SUCCESS
},
1166 { 3, "This is a String", "Wild", 30, STATUS_SUCCESS
},
1167 { 0, "abcdefghijklmnopqrstuvwxyz", "", 0, STATUS_NOT_FOUND
},
1168 { 0, "abcdefghijklmnopqrstuvwxyz", "123", 0, STATUS_NOT_FOUND
},
1169 { 0, "abcdefghijklmnopqrstuvwxyz", "a", 2, STATUS_SUCCESS
},
1170 { 0, "abcdefghijklmnopqrstuvwxyz", "12a34", 2, STATUS_SUCCESS
},
1171 { 0, "abcdefghijklmnopqrstuvwxyz", "12b34", 4, STATUS_SUCCESS
},
1172 { 0, "abcdefghijklmnopqrstuvwxyz", "12y34", 50, STATUS_SUCCESS
},
1173 { 0, "abcdefghijklmnopqrstuvwxyz", "12z34", 52, STATUS_SUCCESS
},
1174 { 0, "abcdefghijklmnopqrstuvwxyz", "rvz", 36, STATUS_SUCCESS
},
1175 { 0, "abcdefghijklmmlkjihgfedcba", "egik", 10, STATUS_SUCCESS
},
1176 { 1, "abcdefghijklmnopqrstuvwxyz", "", 0, STATUS_NOT_FOUND
},
1177 { 1, "abcdefghijklmnopqrstuvwxyz", "rvz", 50, STATUS_SUCCESS
},
1178 { 1, "abcdefghijklmnopqrstuvwxyz", "ravy", 48, STATUS_SUCCESS
},
1179 { 1, "abcdefghijklmnopqrstuvwxyz", "raxv", 46, STATUS_SUCCESS
},
1180 { 2, "abcdefghijklmnopqrstuvwxyz", "", 2, STATUS_SUCCESS
},
1181 { 2, "abcdefghijklmnopqrstuvwxyz", "rvz", 2, STATUS_SUCCESS
},
1182 { 2, "abcdefghijklmnopqrstuvwxyz", "vaz", 4, STATUS_SUCCESS
},
1183 { 2, "abcdefghijklmnopqrstuvwxyz", "ravbz", 6, STATUS_SUCCESS
},
1184 { 3, "abcdefghijklmnopqrstuvwxyz", "", 50, STATUS_SUCCESS
},
1185 { 3, "abcdefghijklmnopqrstuvwxyz", "123", 50, STATUS_SUCCESS
},
1186 { 3, "abcdefghijklmnopqrstuvwxyz", "ahp", 50, STATUS_SUCCESS
},
1187 { 3, "abcdefghijklmnopqrstuvwxyz", "rvz", 48, STATUS_SUCCESS
},
1188 { 0, NULL
, "abc", 0, STATUS_NOT_FOUND
},
1189 { 1, NULL
, "abc", 0, STATUS_NOT_FOUND
},
1190 { 2, NULL
, "abc", 0, STATUS_NOT_FOUND
},
1191 { 3, NULL
, "abc", 0, STATUS_NOT_FOUND
},
1192 { 0, "abcdefghijklmnopqrstuvwxyz", NULL
, 0, STATUS_NOT_FOUND
},
1193 { 1, "abcdefghijklmnopqrstuvwxyz", NULL
, 0, STATUS_NOT_FOUND
},
1194 { 2, "abcdefghijklmnopqrstuvwxyz", NULL
, 2, STATUS_SUCCESS
},
1195 { 3, "abcdefghijklmnopqrstuvwxyz", NULL
, 50, STATUS_SUCCESS
},
1196 { 0, NULL
, NULL
, 0, STATUS_NOT_FOUND
},
1197 { 1, NULL
, NULL
, 0, STATUS_NOT_FOUND
},
1198 { 2, NULL
, NULL
, 0, STATUS_NOT_FOUND
},
1199 { 3, NULL
, NULL
, 0, STATUS_NOT_FOUND
},
1200 { 0, "abcdabcdabcdabcdabcdabcd", "abcd", 2, STATUS_SUCCESS
},
1201 { 1, "abcdabcdabcdabcdabcdabcd", "abcd", 46, STATUS_SUCCESS
},
1202 { 2, "abcdabcdabcdabcdabcdabcd", "abcd", 0, STATUS_NOT_FOUND
},
1203 { 3, "abcdabcdabcdabcdabcdabcd", "abcd", 0, STATUS_NOT_FOUND
},
1207 static void test_RtlFindCharInUnicodeString(void)
1209 WCHAR main_str_buf
[257];
1210 WCHAR search_chars_buf
[257];
1211 UNICODE_STRING main_str
;
1212 UNICODE_STRING search_chars
;
1216 unsigned int test_num
;
1218 if (!pRtlFindCharInUnicodeString
)
1220 win_skip("RtlFindCharInUnicodeString is not available\n");
1224 for (test_num
= 0; test_num
< ARRAY_SIZE(find_ch_in_ustr
); test_num
++) {
1225 if (find_ch_in_ustr
[test_num
].main_str
!= NULL
) {
1226 main_str
.Length
= strlen(find_ch_in_ustr
[test_num
].main_str
) * sizeof(WCHAR
);
1227 main_str
.MaximumLength
= main_str
.Length
+ sizeof(WCHAR
);
1228 for (idx
= 0; idx
< main_str
.Length
/ sizeof(WCHAR
); idx
++) {
1229 main_str_buf
[idx
] = find_ch_in_ustr
[test_num
].main_str
[idx
];
1231 main_str
.Buffer
= main_str_buf
;
1233 main_str
.Length
= 0;
1234 main_str
.MaximumLength
= 0;
1235 main_str
.Buffer
= NULL
;
1237 if (find_ch_in_ustr
[test_num
].search_chars
!= NULL
) {
1238 search_chars
.Length
= strlen(find_ch_in_ustr
[test_num
].search_chars
) * sizeof(WCHAR
);
1239 search_chars
.MaximumLength
= search_chars
.Length
+ sizeof(WCHAR
);
1240 for (idx
= 0; idx
< search_chars
.Length
/ sizeof(WCHAR
); idx
++) {
1241 search_chars_buf
[idx
] = find_ch_in_ustr
[test_num
].search_chars
[idx
];
1243 search_chars
.Buffer
= search_chars_buf
;
1245 search_chars
.Length
= 0;
1246 search_chars
.MaximumLength
= 0;
1247 search_chars
.Buffer
= NULL
;
1250 result
= pRtlFindCharInUnicodeString(find_ch_in_ustr
[test_num
].flags
, &main_str
, &search_chars
, &pos
);
1251 ok(result
== find_ch_in_ustr
[test_num
].result
,
1252 "(test %d): RtlFindCharInUnicodeString(%d, %s, %s, [out]) has result %x, expected %x\n",
1253 test_num
, find_ch_in_ustr
[test_num
].flags
,
1254 find_ch_in_ustr
[test_num
].main_str
, find_ch_in_ustr
[test_num
].search_chars
,
1255 result
, find_ch_in_ustr
[test_num
].result
);
1256 ok(pos
== find_ch_in_ustr
[test_num
].pos
,
1257 "(test %d): RtlFindCharInUnicodeString(%d, %s, %s, [out]) assigns %d to pos, expected %d\n",
1258 test_num
, find_ch_in_ustr
[test_num
].flags
,
1259 find_ch_in_ustr
[test_num
].main_str
, find_ch_in_ustr
[test_num
].search_chars
,
1260 pos
, find_ch_in_ustr
[test_num
].pos
);
1269 NTSTATUS result
, alternative
;
1272 static const str2int_t str2int
[] = {
1273 { 0, "1011101100", 1011101100, STATUS_SUCCESS
},
1274 { 0, "1234567", 1234567, STATUS_SUCCESS
},
1275 { 0, "-214", -214, STATUS_SUCCESS
},
1276 { 0, "+214", 214, STATUS_SUCCESS
}, /* The + sign is allowed also */
1277 { 0, "--214", 0, STATUS_SUCCESS
}, /* Do not accept more than one sign */
1278 { 0, "-+214", 0, STATUS_SUCCESS
},
1279 { 0, "++214", 0, STATUS_SUCCESS
},
1280 { 0, "+-214", 0, STATUS_SUCCESS
},
1281 { 0, "\001\002\003\00411", 11, STATUS_SUCCESS
}, /* whitespace char 1 to 4 */
1282 { 0, "\005\006\007\01012", 12, STATUS_SUCCESS
}, /* whitespace char 5 to 8 */
1283 { 0, "\011\012\013\01413", 13, STATUS_SUCCESS
}, /* whitespace char 9 to 12 */
1284 { 0, "\015\016\017\02014", 14, STATUS_SUCCESS
}, /* whitespace char 13 to 16 */
1285 { 0, "\021\022\023\02415", 15, STATUS_SUCCESS
}, /* whitespace char 17 to 20 */
1286 { 0, "\025\026\027\03016", 16, STATUS_SUCCESS
}, /* whitespace char 21 to 24 */
1287 { 0, "\031\032\033\03417", 17, STATUS_SUCCESS
}, /* whitespace char 25 to 28 */
1288 { 0, "\035\036\037\04018", 18, STATUS_SUCCESS
}, /* whitespace char 29 to 32 */
1289 { 0, " \n \r \t214", 214, STATUS_SUCCESS
},
1290 { 0, " \n \r \t+214", 214, STATUS_SUCCESS
}, /* Signs can be used after whitespace */
1291 { 0, " \n \r \t-214", -214, STATUS_SUCCESS
},
1292 { 0, "+214 0", 214, STATUS_SUCCESS
}, /* Space terminates the number */
1293 { 0, " 214.01", 214, STATUS_SUCCESS
}, /* Decimal point not accepted */
1294 { 0, " 214,01", 214, STATUS_SUCCESS
}, /* Decimal comma not accepted */
1295 { 0, "f81", 0, STATUS_SUCCESS
},
1296 { 0, "0x12345", 0x12345, STATUS_SUCCESS
}, /* Hex */
1297 { 0, "00x12345", 0, STATUS_SUCCESS
},
1298 { 0, "0xx12345", 0, STATUS_SUCCESS
},
1299 { 0, "1x34", 1, STATUS_SUCCESS
},
1300 { 0, "-9999999999", -1410065407, STATUS_SUCCESS
}, /* Big negative integer */
1301 { 0, "-2147483649", 2147483647, STATUS_SUCCESS
}, /* Too small to fit in 32 Bits */
1302 { 0, "-2147483648", 0x80000000L
, STATUS_SUCCESS
}, /* Smallest negative integer */
1303 { 0, "-2147483647", -2147483647, STATUS_SUCCESS
},
1304 { 0, "-1", -1, STATUS_SUCCESS
},
1305 { 0, "0", 0, STATUS_SUCCESS
},
1306 { 0, "1", 1, STATUS_SUCCESS
},
1307 { 0, "2147483646", 2147483646, STATUS_SUCCESS
},
1308 { 0, "2147483647", 2147483647, STATUS_SUCCESS
}, /* Largest signed positive integer */
1309 { 0, "2147483648", 0x80000000L
, STATUS_SUCCESS
}, /* Positive int equal to smallest negative int */
1310 { 0, "2147483649", -2147483647, STATUS_SUCCESS
},
1311 { 0, "4294967294", -2, STATUS_SUCCESS
},
1312 { 0, "4294967295", -1, STATUS_SUCCESS
}, /* Largest unsigned integer */
1313 { 0, "4294967296", 0, STATUS_SUCCESS
}, /* Too big to fit in 32 Bits */
1314 { 0, "9999999999", 1410065407, STATUS_SUCCESS
}, /* Big positive integer */
1315 { 0, "056789", 56789, STATUS_SUCCESS
}, /* Leading zero and still decimal */
1316 { 0, "b1011101100", 0, STATUS_SUCCESS
}, /* Binary (b-notation) */
1317 { 0, "-b1011101100", 0, STATUS_SUCCESS
}, /* Negative Binary (b-notation) */
1318 { 0, "b10123456789", 0, STATUS_SUCCESS
}, /* Binary with nonbinary digits (2-9) */
1319 { 0, "0b1011101100", 748, STATUS_SUCCESS
}, /* Binary (0b-notation) */
1320 { 0, "-0b1011101100", -748, STATUS_SUCCESS
}, /* Negative binary (0b-notation) */
1321 { 0, "0b10123456789", 5, STATUS_SUCCESS
}, /* Binary with nonbinary digits (2-9) */
1322 { 0, "-0b10123456789", -5, STATUS_SUCCESS
}, /* Negative binary with nonbinary digits (2-9) */
1323 { 0, "0b1", 1, STATUS_SUCCESS
}, /* one digit binary */
1324 { 0, "0b2", 0, STATUS_SUCCESS
}, /* empty binary */
1325 { 0, "0b", 0, STATUS_SUCCESS
}, /* empty binary */
1326 { 0, "o1234567", 0, STATUS_SUCCESS
}, /* Octal (o-notation) */
1327 { 0, "-o1234567", 0, STATUS_SUCCESS
}, /* Negative Octal (o-notation) */
1328 { 0, "o56789", 0, STATUS_SUCCESS
}, /* Octal with nonoctal digits (8 and 9) */
1329 { 0, "0o1234567", 01234567, STATUS_SUCCESS
}, /* Octal (0o-notation) */
1330 { 0, "-0o1234567", -01234567, STATUS_SUCCESS
}, /* Negative octal (0o-notation) */
1331 { 0, "0o56789", 0567, STATUS_SUCCESS
}, /* Octal with nonoctal digits (8 and 9) */
1332 { 0, "-0o56789", -0567, STATUS_SUCCESS
}, /* Negative octal with nonoctal digits (8 and 9) */
1333 { 0, "0o7", 7, STATUS_SUCCESS
}, /* one digit octal */
1334 { 0, "0o8", 0, STATUS_SUCCESS
}, /* empty octal */
1335 { 0, "0o", 0, STATUS_SUCCESS
}, /* empty octal */
1336 { 0, "0d1011101100", 0, STATUS_SUCCESS
}, /* explicit decimal with 0d */
1337 { 0, "x89abcdef", 0, STATUS_SUCCESS
}, /* Hex with lower case digits a-f (x-notation) */
1338 { 0, "xFEDCBA00", 0, STATUS_SUCCESS
}, /* Hex with upper case digits A-F (x-notation) */
1339 { 0, "-xFEDCBA00", 0, STATUS_SUCCESS
}, /* Negative Hexadecimal (x-notation) */
1340 { 0, "0x89abcdef", 0x89abcdef, STATUS_SUCCESS
}, /* Hex with lower case digits a-f (0x-notation) */
1341 { 0, "0xFEDCBA00", 0xFEDCBA00, STATUS_SUCCESS
}, /* Hex with upper case digits A-F (0x-notation) */
1342 { 0, "-0xFEDCBA00", 19088896, STATUS_SUCCESS
}, /* Negative Hexadecimal (0x-notation) */
1343 { 0, "0xabcdefgh", 0xabcdef, STATUS_SUCCESS
}, /* Hex with illegal lower case digits (g-z) */
1344 { 0, "0xABCDEFGH", 0xABCDEF, STATUS_SUCCESS
}, /* Hex with illegal upper case digits (G-Z) */
1345 { 0, "0xF", 0xf, STATUS_SUCCESS
}, /* one digit hexadecimal */
1346 { 0, "0xG", 0, STATUS_SUCCESS
}, /* empty hexadecimal */
1347 { 0, "0x", 0, STATUS_SUCCESS
}, /* empty hexadecimal */
1348 { 0, "", 0, STATUS_SUCCESS
, STATUS_INVALID_PARAMETER
}, /* empty string */
1349 { 2, "1011101100", 748, STATUS_SUCCESS
},
1350 { 2, "-1011101100", -748, STATUS_SUCCESS
},
1351 { 2, "2", 0, STATUS_SUCCESS
},
1352 { 2, "0b1011101100", 0, STATUS_SUCCESS
},
1353 { 2, "0o1011101100", 0, STATUS_SUCCESS
},
1354 { 2, "0d1011101100", 0, STATUS_SUCCESS
},
1355 { 2, "0x1011101100", 0, STATUS_SUCCESS
},
1356 { 2, "", 0, STATUS_SUCCESS
, STATUS_INVALID_PARAMETER
}, /* empty string */
1357 { 8, "1011101100", 136610368, STATUS_SUCCESS
},
1358 { 8, "-1011101100", -136610368, STATUS_SUCCESS
},
1359 { 8, "8", 0, STATUS_SUCCESS
},
1360 { 8, "0b1011101100", 0, STATUS_SUCCESS
},
1361 { 8, "0o1011101100", 0, STATUS_SUCCESS
},
1362 { 8, "0d1011101100", 0, STATUS_SUCCESS
},
1363 { 8, "0x1011101100", 0, STATUS_SUCCESS
},
1364 { 8, "", 0, STATUS_SUCCESS
, STATUS_INVALID_PARAMETER
}, /* empty string */
1365 {10, "1011101100", 1011101100, STATUS_SUCCESS
},
1366 {10, "-1011101100", -1011101100, STATUS_SUCCESS
},
1367 {10, "0b1011101100", 0, STATUS_SUCCESS
},
1368 {10, "0o1011101100", 0, STATUS_SUCCESS
},
1369 {10, "0d1011101100", 0, STATUS_SUCCESS
},
1370 {10, "0x1011101100", 0, STATUS_SUCCESS
},
1371 {10, "o12345", 0, STATUS_SUCCESS
}, /* Octal although base is 10 */
1372 {10, "", 0, STATUS_SUCCESS
, STATUS_INVALID_PARAMETER
}, /* empty string */
1373 {16, "1011101100", 286265600, STATUS_SUCCESS
},
1374 {16, "-1011101100", -286265600, STATUS_SUCCESS
},
1375 {16, "G", 0, STATUS_SUCCESS
},
1376 {16, "g", 0, STATUS_SUCCESS
},
1377 {16, "0b1011101100", 286265600, STATUS_SUCCESS
},
1378 {16, "0o1011101100", 0, STATUS_SUCCESS
},
1379 {16, "0d1011101100", 286265600, STATUS_SUCCESS
},
1380 {16, "0x1011101100", 0, STATUS_SUCCESS
},
1381 {16, "", 0, STATUS_SUCCESS
, STATUS_INVALID_PARAMETER
}, /* empty string */
1382 {20, "0", 0, STATUS_INVALID_PARAMETER
}, /* illegal base */
1383 {-8, "0", 0, STATUS_INVALID_PARAMETER
}, /* Negative base */
1384 /* { 0, NULL, 0, STATUS_SUCCESS}, */ /* NULL as string */
1388 static void test_RtlUnicodeStringToInteger(void)
1390 unsigned int test_num
;
1396 for (test_num
= 0; test_num
< ARRAY_SIZE(str2int
); test_num
++) {
1397 wstr
= AtoW(str2int
[test_num
].str
);
1399 pRtlInitUnicodeString(&uni
, wstr
);
1400 result
= pRtlUnicodeStringToInteger(&uni
, str2int
[test_num
].base
, &value
);
1401 ok(result
== str2int
[test_num
].result
||
1402 (str2int
[test_num
].alternative
&& result
== str2int
[test_num
].alternative
),
1403 "(test %d): RtlUnicodeStringToInteger(\"%s\", %d, [out]) has result %x, expected: %x (%x)\n",
1404 test_num
, str2int
[test_num
].str
, str2int
[test_num
].base
, result
,
1405 str2int
[test_num
].result
, str2int
[test_num
].alternative
);
1406 if (result
== STATUS_SUCCESS
)
1407 ok(value
== str2int
[test_num
].value
||
1408 broken(str2int
[test_num
].str
[0] == '\0' && str2int
[test_num
].base
== 16), /* nt4 */
1409 "(test %d): RtlUnicodeStringToInteger(\"%s\", %d, [out]) assigns value %d, expected: %d\n",
1410 test_num
, str2int
[test_num
].str
, str2int
[test_num
].base
, value
, str2int
[test_num
].value
);
1412 ok(value
== 0xdeadbeef || value
== 0 /* vista */,
1413 "(test %d): RtlUnicodeStringToInteger(\"%s\", %d, [out]) assigns value %d, expected 0 or deadbeef\n",
1414 test_num
, str2int
[test_num
].str
, str2int
[test_num
].base
, value
);
1415 HeapFree(GetProcessHeap(), 0, wstr
);
1418 wstr
= AtoW(str2int
[1].str
);
1419 pRtlInitUnicodeString(&uni
, wstr
);
1420 result
= pRtlUnicodeStringToInteger(&uni
, str2int
[1].base
, NULL
);
1421 ok(result
== STATUS_ACCESS_VIOLATION
,
1422 "call failed: RtlUnicodeStringToInteger(\"%s\", %d, NULL) has result %x\n",
1423 str2int
[1].str
, str2int
[1].base
, result
);
1424 result
= pRtlUnicodeStringToInteger(&uni
, 20, NULL
);
1425 ok(result
== STATUS_INVALID_PARAMETER
|| result
== STATUS_ACCESS_VIOLATION
,
1426 "call failed: RtlUnicodeStringToInteger(\"%s\", 20, NULL) has result %x\n",
1427 str2int
[1].str
, result
);
1429 uni
.Length
= 10; /* Make Length shorter (5 WCHARS instead of 7) */
1430 result
= pRtlUnicodeStringToInteger(&uni
, str2int
[1].base
, &value
);
1431 ok(result
== STATUS_SUCCESS
,
1432 "call failed: RtlUnicodeStringToInteger(\"12345\", %d, [out]) has result %x\n",
1433 str2int
[1].base
, result
);
1435 "didn't return expected value (test a): expected: %d, got: %d\n",
1438 uni
.Length
= 5; /* Use odd Length (2.5 WCHARS) */
1439 result
= pRtlUnicodeStringToInteger(&uni
, str2int
[1].base
, &value
);
1440 ok(result
== STATUS_SUCCESS
|| result
== STATUS_INVALID_PARAMETER
/* vista */,
1441 "call failed: RtlUnicodeStringToInteger(\"12\", %d, [out]) has result %x\n",
1442 str2int
[1].base
, result
);
1443 if (result
== STATUS_SUCCESS
)
1444 ok(value
== 12, "didn't return expected value (test b): expected: %d, got: %d\n", 12, value
);
1447 result
= pRtlUnicodeStringToInteger(&uni
, str2int
[1].base
, &value
);
1448 ok(result
== STATUS_SUCCESS
,
1449 "call failed: RtlUnicodeStringToInteger(\"1\", %d, [out]) has result %x\n",
1450 str2int
[1].base
, result
);
1452 "didn't return expected value (test c): expected: %d, got: %d\n",
1454 /* w2k: uni.Length = 0 returns value 11234567 instead of 0 */
1455 HeapFree(GetProcessHeap(), 0, wstr
);
1459 static void test_RtlCharToInteger(void)
1461 unsigned int test_num
;
1465 for (test_num
= 0; test_num
< ARRAY_SIZE(str2int
); test_num
++) {
1466 /* w2k skips a leading '\0' and processes the string after */
1467 if (str2int
[test_num
].str
[0] != '\0') {
1469 result
= pRtlCharToInteger(str2int
[test_num
].str
, str2int
[test_num
].base
, &value
);
1470 ok(result
== str2int
[test_num
].result
||
1471 (str2int
[test_num
].alternative
&& result
== str2int
[test_num
].alternative
),
1472 "(test %d): call failed: RtlCharToInteger(\"%s\", %d, [out]) has result %x, expected: %x (%x)\n",
1473 test_num
, str2int
[test_num
].str
, str2int
[test_num
].base
, result
,
1474 str2int
[test_num
].result
, str2int
[test_num
].alternative
);
1475 if (result
== STATUS_SUCCESS
)
1476 ok(value
== str2int
[test_num
].value
,
1477 "(test %d): call failed: RtlCharToInteger(\"%s\", %d, [out]) assigns value %d, expected: %d\n",
1478 test_num
, str2int
[test_num
].str
, str2int
[test_num
].base
, value
, str2int
[test_num
].value
);
1480 ok(value
== 0 || value
== 0xdeadbeef,
1481 "(test %d): call failed: RtlCharToInteger(\"%s\", %d, [out]) assigns value %d, expected 0 or deadbeef\n",
1482 test_num
, str2int
[test_num
].str
, str2int
[test_num
].base
, value
);
1486 result
= pRtlCharToInteger(str2int
[1].str
, str2int
[1].base
, NULL
);
1487 ok(result
== STATUS_ACCESS_VIOLATION
,
1488 "call failed: RtlCharToInteger(\"%s\", %d, NULL) has result %x\n",
1489 str2int
[1].str
, str2int
[1].base
, result
);
1491 result
= pRtlCharToInteger(str2int
[1].str
, 20, NULL
);
1492 ok(result
== STATUS_INVALID_PARAMETER
,
1493 "call failed: RtlCharToInteger(\"%s\", 20, NULL) has result %x\n",
1494 str2int
[1].str
, result
);
1498 #define STRI_BUFFER_LENGTH 35
1504 USHORT MaximumLength
;
1509 static const int2str_t int2str
[] = {
1510 {10, 123, 3, 11, "123\0-------------------------------", STATUS_SUCCESS
},
1512 { 0, 0x80000000U
, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS
}, /* min signed int */
1513 { 0, -2147483647, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS
},
1514 { 0, -2, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS
},
1515 { 0, -1, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS
},
1516 { 0, 0, 1, 11, "0\0---------------------------------", STATUS_SUCCESS
},
1517 { 0, 1, 1, 11, "1\0---------------------------------", STATUS_SUCCESS
},
1518 { 0, 12, 2, 11, "12\0--------------------------------", STATUS_SUCCESS
},
1519 { 0, 123, 3, 11, "123\0-------------------------------", STATUS_SUCCESS
},
1520 { 0, 1234, 4, 11, "1234\0------------------------------", STATUS_SUCCESS
},
1521 { 0, 12345, 5, 11, "12345\0-----------------------------", STATUS_SUCCESS
},
1522 { 0, 123456, 6, 11, "123456\0----------------------------", STATUS_SUCCESS
},
1523 { 0, 1234567, 7, 11, "1234567\0---------------------------", STATUS_SUCCESS
},
1524 { 0, 12345678, 8, 11, "12345678\0--------------------------", STATUS_SUCCESS
},
1525 { 0, 123456789, 9, 11, "123456789\0-------------------------", STATUS_SUCCESS
},
1526 { 0, 2147483646, 10, 11, "2147483646\0------------------------", STATUS_SUCCESS
},
1527 { 0, 2147483647, 10, 11, "2147483647\0------------------------", STATUS_SUCCESS
}, /* max signed int */
1528 { 0, 2147483648U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS
}, /* uint = -max int */
1529 { 0, 2147483649U, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS
},
1530 { 0, 4294967294U, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS
},
1531 { 0, 4294967295U, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS
}, /* max unsigned int */
1533 { 2, 0x80000000U
, 32, 33, "10000000000000000000000000000000\0--", STATUS_SUCCESS
}, /* min signed int */
1534 { 2, -2147483647, 32, 33, "10000000000000000000000000000001\0--", STATUS_SUCCESS
},
1535 { 2, -2, 32, 33, "11111111111111111111111111111110\0--", STATUS_SUCCESS
},
1536 { 2, -1, 32, 33, "11111111111111111111111111111111\0--", STATUS_SUCCESS
},
1537 { 2, 0, 1, 33, "0\0---------------------------------", STATUS_SUCCESS
},
1538 { 2, 1, 1, 33, "1\0---------------------------------", STATUS_SUCCESS
},
1539 { 2, 10, 4, 33, "1010\0------------------------------", STATUS_SUCCESS
},
1540 { 2, 100, 7, 33, "1100100\0---------------------------", STATUS_SUCCESS
},
1541 { 2, 1000, 10, 33, "1111101000\0------------------------", STATUS_SUCCESS
},
1542 { 2, 10000, 14, 33, "10011100010000\0--------------------", STATUS_SUCCESS
},
1543 { 2, 32767, 15, 33, "111111111111111\0-------------------", STATUS_SUCCESS
},
1544 /* { 2, 32768, 16, 33, "1000000000000000\0------------------", STATUS_SUCCESS}, broken on windows */
1545 /* { 2, 65535, 16, 33, "1111111111111111\0------------------", STATUS_SUCCESS}, broken on windows */
1546 { 2, 65536, 17, 33, "10000000000000000\0-----------------", STATUS_SUCCESS
},
1547 { 2, 100000, 17, 33, "11000011010100000\0-----------------", STATUS_SUCCESS
},
1548 { 2, 1000000, 20, 33, "11110100001001000000\0--------------", STATUS_SUCCESS
},
1549 { 2, 10000000, 24, 33, "100110001001011010000000\0----------", STATUS_SUCCESS
},
1550 { 2, 100000000, 27, 33, "101111101011110000100000000\0-------", STATUS_SUCCESS
},
1551 { 2, 1000000000, 30, 33, "111011100110101100101000000000\0----", STATUS_SUCCESS
},
1552 { 2, 1073741823, 30, 33, "111111111111111111111111111111\0----", STATUS_SUCCESS
},
1553 { 2, 2147483646, 31, 33, "1111111111111111111111111111110\0---", STATUS_SUCCESS
},
1554 { 2, 2147483647, 31, 33, "1111111111111111111111111111111\0---", STATUS_SUCCESS
}, /* max signed int */
1555 { 2, 2147483648U, 32, 33, "10000000000000000000000000000000\0--", STATUS_SUCCESS
}, /* uint = -max int */
1556 { 2, 2147483649U, 32, 33, "10000000000000000000000000000001\0--", STATUS_SUCCESS
},
1557 { 2, 4294967294U, 32, 33, "11111111111111111111111111111110\0--", STATUS_SUCCESS
},
1558 { 2, 4294967295U, 32, 33, "11111111111111111111111111111111\0--", STATUS_SUCCESS
}, /* max unsigned int */
1560 { 8, 0x80000000U
, 11, 12, "20000000000\0-----------------------", STATUS_SUCCESS
}, /* min signed int */
1561 { 8, -2147483647, 11, 12, "20000000001\0-----------------------", STATUS_SUCCESS
},
1562 { 8, -2, 11, 12, "37777777776\0-----------------------", STATUS_SUCCESS
},
1563 { 8, -1, 11, 12, "37777777777\0-----------------------", STATUS_SUCCESS
},
1564 { 8, 0, 1, 12, "0\0---------------------------------", STATUS_SUCCESS
},
1565 { 8, 1, 1, 12, "1\0---------------------------------", STATUS_SUCCESS
},
1566 { 8, 2147483646, 11, 12, "17777777776\0-----------------------", STATUS_SUCCESS
},
1567 { 8, 2147483647, 11, 12, "17777777777\0-----------------------", STATUS_SUCCESS
}, /* max signed int */
1568 { 8, 2147483648U, 11, 12, "20000000000\0-----------------------", STATUS_SUCCESS
}, /* uint = -max int */
1569 { 8, 2147483649U, 11, 12, "20000000001\0-----------------------", STATUS_SUCCESS
},
1570 { 8, 4294967294U, 11, 12, "37777777776\0-----------------------", STATUS_SUCCESS
},
1571 { 8, 4294967295U, 11, 12, "37777777777\0-----------------------", STATUS_SUCCESS
}, /* max unsigned int */
1573 {10, 0x80000000U
, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS
}, /* min signed int */
1574 {10, -2147483647, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS
},
1575 {10, -2, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS
},
1576 {10, -1, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS
},
1577 {10, 0, 1, 11, "0\0---------------------------------", STATUS_SUCCESS
},
1578 {10, 1, 1, 11, "1\0---------------------------------", STATUS_SUCCESS
},
1579 {10, 2147483646, 10, 11, "2147483646\0------------------------", STATUS_SUCCESS
},
1580 {10, 2147483647, 10, 11, "2147483647\0------------------------", STATUS_SUCCESS
}, /* max signed int */
1581 {10, 2147483648U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS
}, /* uint = -max int */
1582 {10, 2147483649U, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS
},
1583 {10, 4294967294U, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS
},
1584 {10, 4294967295U, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS
}, /* max unsigned int */
1586 {16, 0x80000000U
, 8, 9, "80000000\0--------------------------", STATUS_SUCCESS
}, /* min signed int */
1587 {16, -2147483647, 8, 9, "80000001\0--------------------------", STATUS_SUCCESS
},
1588 {16, -2, 8, 9, "FFFFFFFE\0--------------------------", STATUS_SUCCESS
},
1589 {16, -1, 8, 9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS
},
1590 {16, 0, 1, 9, "0\0---------------------------------", STATUS_SUCCESS
},
1591 {16, 1, 1, 9, "1\0---------------------------------", STATUS_SUCCESS
},
1592 {16, 2147483646, 8, 9, "7FFFFFFE\0--------------------------", STATUS_SUCCESS
},
1593 {16, 2147483647, 8, 9, "7FFFFFFF\0--------------------------", STATUS_SUCCESS
}, /* max signed int */
1594 {16, 2147483648U, 8, 9, "80000000\0--------------------------", STATUS_SUCCESS
}, /* uint = -max int */
1595 {16, 2147483649U, 8, 9, "80000001\0--------------------------", STATUS_SUCCESS
},
1596 {16, 4294967294U, 8, 9, "FFFFFFFE\0--------------------------", STATUS_SUCCESS
},
1597 {16, 4294967295U, 8, 9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS
}, /* max unsigned int */
1599 /* { 2, 32768, 16, 17, "1000000000000000\0------------------", STATUS_SUCCESS}, broken on windows */
1600 /* { 2, 32768, 16, 16, "1000000000000000-------------------", STATUS_SUCCESS}, broken on windows */
1601 { 2, 65536, 17, 18, "10000000000000000\0-----------------", STATUS_SUCCESS
},
1602 { 2, 65536, 17, 17, "10000000000000000------------------", STATUS_SUCCESS
},
1603 { 2, 131072, 18, 19, "100000000000000000\0----------------", STATUS_SUCCESS
},
1604 { 2, 131072, 18, 18, "100000000000000000-----------------", STATUS_SUCCESS
},
1605 {16, 0xffffffff, 8, 9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS
},
1606 {16, 0xffffffff, 8, 8, "FFFFFFFF---------------------------", STATUS_SUCCESS
}, /* No \0 term */
1607 {16, 0xffffffff, 8, 7, "-----------------------------------", STATUS_BUFFER_OVERFLOW
}, /* Too short */
1608 {16, 0xa, 1, 2, "A\0---------------------------------", STATUS_SUCCESS
},
1609 {16, 0xa, 1, 1, "A----------------------------------", STATUS_SUCCESS
}, /* No \0 term */
1610 {16, 0, 1, 0, "-----------------------------------", STATUS_BUFFER_OVERFLOW
},
1611 {20, 0xdeadbeef, 0, 9, "-----------------------------------", STATUS_INVALID_PARAMETER
}, /* ill. base */
1612 {-8, 07654321, 0, 12, "-----------------------------------", STATUS_INVALID_PARAMETER
}, /* neg. base */
1616 static void one_RtlIntegerToUnicodeString_test(int test_num
, const int2str_t
*int2str
)
1619 WCHAR expected_str_Buffer
[STRI_BUFFER_LENGTH
+ 1];
1620 UNICODE_STRING expected_unicode_string
;
1621 STRING expected_ansi_str
;
1622 WCHAR str_Buffer
[STRI_BUFFER_LENGTH
+ 1];
1623 UNICODE_STRING unicode_string
;
1627 for (pos
= 0; pos
< STRI_BUFFER_LENGTH
; pos
++) {
1628 expected_str_Buffer
[pos
] = int2str
->Buffer
[pos
];
1630 expected_unicode_string
.Length
= int2str
->Length
* sizeof(WCHAR
);
1631 expected_unicode_string
.MaximumLength
= int2str
->MaximumLength
* sizeof(WCHAR
);
1632 expected_unicode_string
.Buffer
= expected_str_Buffer
;
1633 pRtlUnicodeStringToAnsiString(&expected_ansi_str
, &expected_unicode_string
, 1);
1635 for (pos
= 0; pos
< STRI_BUFFER_LENGTH
; pos
++) {
1636 str_Buffer
[pos
] = '-';
1638 unicode_string
.Length
= 0;
1639 unicode_string
.MaximumLength
= int2str
->MaximumLength
* sizeof(WCHAR
);
1640 unicode_string
.Buffer
= str_Buffer
;
1642 result
= pRtlIntegerToUnicodeString(int2str
->value
, int2str
->base
, &unicode_string
);
1643 pRtlUnicodeStringToAnsiString(&ansi_str
, &unicode_string
, 1);
1644 if (result
== STATUS_BUFFER_OVERFLOW
) {
1645 /* On BUFFER_OVERFLOW the string Buffer should be unchanged */
1646 for (pos
= 0; pos
< STRI_BUFFER_LENGTH
; pos
++) {
1647 expected_str_Buffer
[pos
] = '-';
1649 /* w2k: The native function has two reasons for BUFFER_OVERFLOW: */
1650 /* If the value is too large to convert: The Length is unchanged */
1651 /* If str is too small to hold the string: Set str->Length to the length */
1652 /* the string would have (which can be larger than the MaximumLength). */
1653 /* To allow all this in the tests we do the following: */
1654 if (expected_unicode_string
.Length
> 32 && unicode_string
.Length
== 0) {
1655 /* The value is too large to convert only triggered when testing native */
1656 expected_unicode_string
.Length
= 0;
1659 ok(result
== int2str
->result
,
1660 "(test %d): RtlIntegerToUnicodeString(%u, %d, [out]) has result %x, expected: %x\n",
1661 test_num
, int2str
->value
, int2str
->base
, result
, int2str
->result
);
1662 if (result
== STATUS_SUCCESS
) {
1663 ok(unicode_string
.Buffer
[unicode_string
.Length
/sizeof(WCHAR
)] == '\0',
1664 "(test %d): RtlIntegerToUnicodeString(%u, %d, [out]) string \"%s\" is not NULL terminated\n",
1665 test_num
, int2str
->value
, int2str
->base
, ansi_str
.Buffer
);
1668 ok(memcmp(unicode_string
.Buffer
, expected_unicode_string
.Buffer
, STRI_BUFFER_LENGTH
* sizeof(WCHAR
)) == 0,
1669 "(test %d): RtlIntegerToUnicodeString(%u, %d, [out]) assigns string \"%s\", expected: \"%s\"\n",
1670 test_num
, int2str
->value
, int2str
->base
, ansi_str
.Buffer
, expected_ansi_str
.Buffer
);
1671 ok(unicode_string
.Length
== expected_unicode_string
.Length
,
1672 "(test %d): RtlIntegerToUnicodeString(%u, %d, [out]) string has Length %d, expected: %d\n",
1673 test_num
, int2str
->value
, int2str
->base
, unicode_string
.Length
, expected_unicode_string
.Length
);
1674 ok(unicode_string
.MaximumLength
== expected_unicode_string
.MaximumLength
,
1675 "(test %d): RtlIntegerToUnicodeString(%u, %d, [out]) string has MaximumLength %d, expected: %d\n",
1676 test_num
, int2str
->value
, int2str
->base
, unicode_string
.MaximumLength
, expected_unicode_string
.MaximumLength
);
1677 pRtlFreeAnsiString(&expected_ansi_str
);
1678 pRtlFreeAnsiString(&ansi_str
);
1682 static void test_RtlIntegerToUnicodeString(void)
1686 for (test_num
= 0; test_num
< ARRAY_SIZE(int2str
); test_num
++)
1687 one_RtlIntegerToUnicodeString_test(test_num
, &int2str
[test_num
]);
1691 static void one_RtlIntegerToChar_test(int test_num
, const int2str_t
*int2str
)
1694 char dest_str
[STRI_BUFFER_LENGTH
+ 1];
1696 memset(dest_str
, '-', STRI_BUFFER_LENGTH
);
1697 dest_str
[STRI_BUFFER_LENGTH
] = '\0';
1698 result
= pRtlIntegerToChar(int2str
->value
, int2str
->base
, int2str
->MaximumLength
, dest_str
);
1699 ok(result
== int2str
->result
,
1700 "(test %d): RtlIntegerToChar(%u, %d, %d, [out]) has result %x, expected: %x\n",
1701 test_num
, int2str
->value
, int2str
->base
, int2str
->MaximumLength
, result
, int2str
->result
);
1702 ok(memcmp(dest_str
, int2str
->Buffer
, STRI_BUFFER_LENGTH
) == 0,
1703 "(test %d): RtlIntegerToChar(%u, %d, %d, [out]) assigns string \"%s\", expected: \"%s\"\n",
1704 test_num
, int2str
->value
, int2str
->base
, int2str
->MaximumLength
, dest_str
, int2str
->Buffer
);
1708 static void test_RtlIntegerToChar(void)
1713 for (test_num
= 0; test_num
< ARRAY_SIZE(int2str
); test_num
++)
1714 one_RtlIntegerToChar_test(test_num
, &int2str
[test_num
]);
1716 result
= pRtlIntegerToChar(int2str
[0].value
, 20, int2str
[0].MaximumLength
, NULL
);
1717 ok(result
== STATUS_INVALID_PARAMETER
,
1718 "(test a): RtlIntegerToChar(%u, %d, %d, NULL) has result %x, expected: %x\n",
1719 int2str
[0].value
, 20, int2str
[0].MaximumLength
, result
, STATUS_INVALID_PARAMETER
);
1721 result
= pRtlIntegerToChar(int2str
[0].value
, 20, 0, NULL
);
1722 ok(result
== STATUS_INVALID_PARAMETER
,
1723 "(test b): RtlIntegerToChar(%u, %d, %d, NULL) has result %x, expected: %x\n",
1724 int2str
[0].value
, 20, 0, result
, STATUS_INVALID_PARAMETER
);
1726 result
= pRtlIntegerToChar(int2str
[0].value
, int2str
[0].base
, 0, NULL
);
1727 ok(result
== STATUS_BUFFER_OVERFLOW
,
1728 "(test c): RtlIntegerToChar(%u, %d, %d, NULL) has result %x, expected: %x\n",
1729 int2str
[0].value
, int2str
[0].base
, 0, result
, STATUS_BUFFER_OVERFLOW
);
1731 result
= pRtlIntegerToChar(int2str
[0].value
, int2str
[0].base
, int2str
[0].MaximumLength
, NULL
);
1732 ok(result
== STATUS_ACCESS_VIOLATION
,
1733 "(test d): RtlIntegerToChar(%u, %d, %d, NULL) has result %x, expected: %x\n",
1734 int2str
[0].value
, int2str
[0].base
, int2str
[0].MaximumLength
, result
, STATUS_ACCESS_VIOLATION
);
1737 static void test_RtlIsTextUnicode(void)
1739 char ascii
[] = "A simple string";
1740 char false_positive
[] = {0x41, 0x0a, 0x0d, 0x1d};
1741 WCHAR false_negative
= 0x0d0a;
1742 WCHAR unicode
[] = {'A',' ','U','n','i','c','o','d','e',' ','s','t','r','i','n','g',0};
1743 WCHAR unicode_no_controls
[] = {'A','U','n','i','c','o','d','e','s','t','r','i','n','g',0};
1744 /* String with both byte-reversed and standard Unicode control characters. */
1745 WCHAR mixed_controls
[] = {'\t',0x9000,0x0d00,'\n',0};
1747 WCHAR
*be_unicode_no_controls
;
1752 if (!pRtlIsTextUnicode
)
1754 win_skip("RtlIsTextUnicode is not available\n");
1758 ok(!pRtlIsTextUnicode(ascii
, sizeof(ascii
), NULL
), "ASCII text detected as Unicode\n");
1760 res
= pRtlIsTextUnicode(unicode
, sizeof(unicode
), NULL
);
1762 broken(res
== FALSE
), /* NT4 */
1763 "Text should be Unicode\n");
1765 ok(!pRtlIsTextUnicode(unicode
, sizeof(unicode
) - 1, NULL
), "Text should be Unicode\n");
1767 flags
= IS_TEXT_UNICODE_UNICODE_MASK
;
1768 ok(pRtlIsTextUnicode(unicode
, sizeof(unicode
), &flags
), "Text should not pass a Unicode\n");
1769 ok(flags
== (IS_TEXT_UNICODE_STATISTICS
| IS_TEXT_UNICODE_CONTROLS
),
1770 "Expected flags 0x6, obtained %x\n", flags
);
1772 flags
= IS_TEXT_UNICODE_REVERSE_MASK
;
1773 ok(!pRtlIsTextUnicode(unicode
, sizeof(unicode
), &flags
), "Text should not pass reverse Unicode tests\n");
1774 ok(flags
== 0, "Expected flags 0, obtained %x\n", flags
);
1776 flags
= IS_TEXT_UNICODE_ODD_LENGTH
;
1777 ok(!pRtlIsTextUnicode(unicode
, sizeof(unicode
) - 1, &flags
), "Odd length test should have passed\n");
1778 ok(flags
== IS_TEXT_UNICODE_ODD_LENGTH
, "Expected flags 0x200, obtained %x\n", flags
);
1780 be_unicode
= HeapAlloc(GetProcessHeap(), 0, sizeof(unicode
) + sizeof(WCHAR
));
1781 be_unicode
[0] = 0xfffe;
1782 for (i
= 0; i
< ARRAY_SIZE(unicode
); i
++)
1784 be_unicode
[i
+ 1] = (unicode
[i
] >> 8) | ((unicode
[i
] & 0xff) << 8);
1786 ok(!pRtlIsTextUnicode(be_unicode
, sizeof(unicode
) + 2, NULL
), "Reverse endian should not be Unicode\n");
1787 ok(!pRtlIsTextUnicode(&be_unicode
[1], sizeof(unicode
), NULL
), "Reverse endian should not be Unicode\n");
1789 flags
= IS_TEXT_UNICODE_REVERSE_MASK
;
1790 ok(!pRtlIsTextUnicode(&be_unicode
[1], sizeof(unicode
), &flags
), "Reverse endian should be Unicode\n");
1792 ok(flags
== (IS_TEXT_UNICODE_REVERSE_ASCII16
| IS_TEXT_UNICODE_REVERSE_STATISTICS
| IS_TEXT_UNICODE_REVERSE_CONTROLS
),
1793 "Expected flags 0x70, obtained %x\n", flags
);
1795 flags
= IS_TEXT_UNICODE_REVERSE_MASK
;
1796 ok(!pRtlIsTextUnicode(be_unicode
, sizeof(unicode
) + 2, &flags
), "Reverse endian should be Unicode\n");
1797 ok(flags
== (IS_TEXT_UNICODE_REVERSE_CONTROLS
| IS_TEXT_UNICODE_REVERSE_SIGNATURE
),
1798 "Expected flags 0xc0, obtained %x\n", flags
);
1800 /* build byte reversed unicode string with no control chars */
1801 be_unicode_no_controls
= HeapAlloc(GetProcessHeap(), 0, sizeof(unicode
) + sizeof(WCHAR
));
1802 ok(be_unicode_no_controls
!= NULL
, "Expected HeapAlloc to succeed.\n");
1803 be_unicode_no_controls
[0] = 0xfffe;
1804 for (i
= 0; i
< ARRAY_SIZE(unicode_no_controls
); i
++)
1805 be_unicode_no_controls
[i
+ 1] = (unicode_no_controls
[i
] >> 8) | ((unicode_no_controls
[i
] & 0xff) << 8);
1808 /* The following tests verify that the tests for */
1809 /* IS_TEXT_UNICODE_CONTROLS and IS_TEXT_UNICODE_REVERSE_CONTROLS */
1810 /* are not mutually exclusive. Regardless of whether the strings */
1811 /* contain an indication of endianness, the tests are still */
1812 /* run if the flag is passed to (Rtl)IsTextUnicode. */
1814 /* Test IS_TEXT_UNICODE_CONTROLS flag */
1815 flags
= IS_TEXT_UNICODE_CONTROLS
;
1816 ok(!pRtlIsTextUnicode(unicode_no_controls
, sizeof(unicode_no_controls
), &flags
), "Test should not pass on Unicode string lacking control characters.\n");
1817 ok(flags
== 0, "Expected flags 0x0, obtained %x\n", flags
);
1819 flags
= IS_TEXT_UNICODE_CONTROLS
;
1820 ok(!pRtlIsTextUnicode(be_unicode_no_controls
, sizeof(unicode_no_controls
), &flags
), "Test should not pass on byte-reversed Unicode string lacking control characters.\n");
1821 ok(flags
== 0, "Expected flags 0x0, obtained %x\n", flags
);
1823 flags
= IS_TEXT_UNICODE_CONTROLS
;
1824 ok(pRtlIsTextUnicode(unicode
, sizeof(unicode
), &flags
), "Test should pass on Unicode string lacking control characters.\n");
1825 ok(flags
== IS_TEXT_UNICODE_CONTROLS
, "Expected flags 0x04, obtained %x\n", flags
);
1827 flags
= IS_TEXT_UNICODE_CONTROLS
;
1828 ok(!pRtlIsTextUnicode(be_unicode_no_controls
, sizeof(unicode_no_controls
) + 2, &flags
),
1829 "Test should not pass with standard Unicode string.\n");
1830 ok(flags
== 0, "Expected flags 0x0, obtained %x\n", flags
);
1832 flags
= IS_TEXT_UNICODE_CONTROLS
;
1833 ok(pRtlIsTextUnicode(mixed_controls
, sizeof(mixed_controls
), &flags
), "Test should pass on a string containing control characters.\n");
1834 ok(flags
== IS_TEXT_UNICODE_CONTROLS
, "Expected flags 0x04, obtained %x\n", flags
);
1836 /* Test IS_TEXT_UNICODE_REVERSE_CONTROLS flag */
1837 flags
= IS_TEXT_UNICODE_REVERSE_CONTROLS
;
1838 ok(!pRtlIsTextUnicode(be_unicode_no_controls
, sizeof(unicode_no_controls
), &flags
), "Test should not pass on Unicode string lacking control characters.\n");
1839 ok(flags
== 0, "Expected flags 0x0, obtained %x\n", flags
);
1841 flags
= IS_TEXT_UNICODE_REVERSE_CONTROLS
;
1842 ok(!pRtlIsTextUnicode(unicode_no_controls
, sizeof(unicode_no_controls
), &flags
), "Test should not pass on Unicode string lacking control characters.\n");
1843 ok(flags
== 0, "Expected flags 0x0, obtained %x\n", flags
);
1845 flags
= IS_TEXT_UNICODE_REVERSE_CONTROLS
;
1846 ok(!pRtlIsTextUnicode(unicode
, sizeof(unicode
), &flags
), "Test should not pass on Unicode string lacking control characters.\n");
1847 ok(flags
== 0, "Expected flags 0x0, obtained %x\n", flags
);
1849 flags
= IS_TEXT_UNICODE_REVERSE_CONTROLS
;
1850 ok(!pRtlIsTextUnicode(be_unicode
, sizeof(unicode
) + 2, &flags
),
1851 "Test should pass with byte-reversed Unicode string containing control characters.\n");
1852 ok(flags
== IS_TEXT_UNICODE_REVERSE_CONTROLS
, "Expected flags 0x40, obtained %x\n", flags
);
1854 flags
= IS_TEXT_UNICODE_REVERSE_CONTROLS
;
1855 ok(!pRtlIsTextUnicode(mixed_controls
, sizeof(mixed_controls
), &flags
), "Test should pass on a string containing byte-reversed control characters.\n");
1856 ok(flags
== IS_TEXT_UNICODE_REVERSE_CONTROLS
, "Expected flags 0x40, obtained %x\n", flags
);
1858 /* Test with flags for both byte-reverse and standard Unicode characters */
1859 flags
= IS_TEXT_UNICODE_CONTROLS
| IS_TEXT_UNICODE_REVERSE_CONTROLS
;
1860 ok(!pRtlIsTextUnicode(mixed_controls
, sizeof(mixed_controls
), &flags
), "Test should pass on string containing both byte-reversed and standard control characters.\n");
1861 ok(flags
== (IS_TEXT_UNICODE_CONTROLS
| IS_TEXT_UNICODE_REVERSE_CONTROLS
), "Expected flags 0x44, obtained %x\n", flags
);
1863 flags
= IS_TEXT_UNICODE_STATISTICS
;
1864 todo_wine
ok(pRtlIsTextUnicode(false_positive
, sizeof(false_positive
), &flags
), "Test should pass on false positive.\n");
1866 ok(!pRtlIsTextUnicode(&false_negative
, sizeof(false_negative
), NULL
), "Test should fail on 0x0d0a (MALAYALAM LETTER UU).\n");
1868 HeapFree(GetProcessHeap(), 0, be_unicode
);
1869 HeapFree(GetProcessHeap(), 0, be_unicode_no_controls
);
1872 static void test_RtlCompareUnicodeString(void)
1875 UNICODE_STRING str1
, str2
;
1878 str1
.Length
= str1
.MaximumLength
= sizeof(WCHAR
);
1880 str2
.Length
= str2
.MaximumLength
= sizeof(WCHAR
);
1881 for (ch1
= 0; ch1
< 512; ch1
++)
1883 for (ch2
= 0; ch2
< 1024; ch2
++)
1885 LONG res
= pRtlCompareUnicodeString( &str1
, &str2
, FALSE
);
1886 ok( res
== (ch1
- ch2
), "wrong result %d %04x %04x\n", res
, ch1
, ch2
);
1887 res
= pRtlCompareUnicodeString( &str1
, &str2
, TRUE
);
1888 ok( res
== (pRtlUpcaseUnicodeChar(ch1
) - pRtlUpcaseUnicodeChar(ch2
)),
1889 "wrong result %d %04x %04x\n", res
, ch1
, ch2
);
1890 if (pRtlCompareUnicodeStrings
)
1892 res
= pRtlCompareUnicodeStrings( &ch1
, 1, &ch2
, 1, FALSE
);
1893 ok( res
== (ch1
- ch2
), "wrong result %d %04x %04x\n", res
, ch1
, ch2
);
1894 res
= pRtlCompareUnicodeStrings( &ch1
, 1, &ch2
, 1, TRUE
);
1895 ok( res
== (pRtlUpcaseUnicodeChar(ch1
) - pRtlUpcaseUnicodeChar(ch2
)),
1896 "wrong result %d %04x %04x\n", res
, ch1
, ch2
);
1902 static const WCHAR szGuid
[] = { '{','0','1','0','2','0','3','0','4','-',
1903 '0','5','0','6','-' ,'0','7','0','8','-','0','9','0','A','-',
1904 '0','B','0','C','0','D','0','E','0','F','0','A','}','\0' };
1905 static const WCHAR szGuid2
[] = { '{','0','1','0','2','0','3','0','4','-',
1906 '0','5','0','6','-' ,'0','7','0','8','-','0','9','0','A','-',
1907 '0','B','0','C','0','D','0','E','0','F','0','A',']','\0' };
1908 DEFINE_GUID(IID_Endianness
, 0x01020304, 0x0506, 0x0708, 0x09, 0x0A, 0x0B,
1909 0x0C, 0x0D, 0x0E, 0x0F, 0x0A);
1911 static void test_RtlGUIDFromString(void)
1917 if (!pRtlGUIDFromString
)
1919 win_skip("RtlGUIDFromString is not available\n");
1923 str
.Length
= str
.MaximumLength
= sizeof(szGuid
) - sizeof(WCHAR
);
1924 str
.Buffer
= (LPWSTR
)szGuid
;
1926 ret
= pRtlGUIDFromString(&str
, &guid
);
1927 ok(ret
== 0, "expected ret=0, got 0x%0x\n", ret
);
1928 ok(IsEqualGUID(&guid
, &IID_Endianness
), "Endianness broken\n");
1930 str
.Length
= str
.MaximumLength
= sizeof(szGuid2
) - sizeof(WCHAR
);
1931 str
.Buffer
= (LPWSTR
)szGuid2
;
1933 ret
= pRtlGUIDFromString(&str
, &guid
);
1934 ok(ret
, "expected ret!=0\n");
1937 static void test_RtlStringFromGUID(void)
1942 if (!pRtlStringFromGUID
)
1944 win_skip("RtlStringFromGUID is not available\n");
1948 str
.Length
= str
.MaximumLength
= 0;
1951 ret
= pRtlStringFromGUID(&IID_Endianness
, &str
);
1952 ok(ret
== 0, "expected ret=0, got 0x%0x\n", ret
);
1953 ok(str
.Buffer
&& !lstrcmpiW(str
.Buffer
, szGuid
), "Endianness broken\n");
1954 pRtlFreeUnicodeString(&str
);
1957 struct hash_unicodestring_test
{
1959 BOOLEAN case_insensitive
;
1963 static const struct hash_unicodestring_test hash_test
[] = {
1964 { L
"T", FALSE
, 0x00000054 },
1965 { L
"Test", FALSE
, 0x766bb952 },
1966 { L
"TeSt", FALSE
, 0x764bb172 },
1967 { L
"test", FALSE
, 0x4745d132 },
1968 { L
"test", TRUE
, 0x6689c132 },
1969 { L
"TEST", TRUE
, 0x6689c132 },
1970 { L
"TEST", FALSE
, 0x6689c132 },
1971 { L
"t\xe9st", FALSE
, 0x8845cfb6 },
1972 { L
"t\xe9st", TRUE
, 0xa789bfb6 },
1973 { L
"T\xc9ST", TRUE
, 0xa789bfb6 },
1974 { L
"T\xc9ST", FALSE
, 0xa789bfb6 },
1975 { L
"abcdef", FALSE
, 0x971318c3 },
1979 static void test_RtlHashUnicodeString(void)
1981 static const WCHAR strW
[] = {'T','e','s','t',0,'1',0};
1982 const struct hash_unicodestring_test
*ptr
;
1987 if (!pRtlHashUnicodeString
)
1989 win_skip("RtlHashUnicodeString is not available\n");
1993 status
= pRtlHashUnicodeString(NULL
, FALSE
, HASH_STRING_ALGORITHM_X65599
, &hash
);
1994 ok(status
== STATUS_INVALID_PARAMETER
, "got status 0x%08x\n", status
);
1996 pRtlInitUnicodeString(&str
, strW
);
1997 status
= pRtlHashUnicodeString(&str
, FALSE
, HASH_STRING_ALGORITHM_X65599
, NULL
);
1998 ok(status
== STATUS_INVALID_PARAMETER
, "got status 0x%08x\n", status
);
2000 status
= pRtlHashUnicodeString(&str
, FALSE
, HASH_STRING_ALGORITHM_INVALID
, &hash
);
2001 ok(status
== STATUS_INVALID_PARAMETER
, "got status 0x%08x\n", status
);
2004 str
.Buffer
= (PWSTR
)strW
;
2005 str
.Length
= sizeof(strW
) - sizeof(WCHAR
);
2006 str
.MaximumLength
= sizeof(strW
);
2007 status
= pRtlHashUnicodeString(&str
, FALSE
, HASH_STRING_ALGORITHM_X65599
, &hash
);
2008 ok(status
== STATUS_SUCCESS
, "got status 0x%08x\n", status
);
2009 ok(hash
== 0x32803083, "got 0x%08x\n", hash
);
2014 pRtlInitUnicodeString(&str
, ptr
->str
);
2016 status
= pRtlHashUnicodeString(&str
, ptr
->case_insensitive
, HASH_STRING_ALGORITHM_X65599
, &hash
);
2017 ok(status
== STATUS_SUCCESS
, "got status 0x%08x for %s\n", status
, wine_dbgstr_w(ptr
->str
));
2018 ok(hash
== ptr
->hash
, "got wrong hash 0x%08x, expected 0x%08x, for %s, mode %d\n", hash
, ptr
->hash
,
2019 wine_dbgstr_w(ptr
->str
), ptr
->case_insensitive
);
2025 struct unicode_to_utf8_test
{
2027 const char *expected
;
2031 static const struct unicode_to_utf8_test unicode_to_utf8
[] = {
2032 { { 0 }, "", STATUS_SUCCESS
},
2033 { { '-',0 }, "-", STATUS_SUCCESS
},
2034 { { 'h','e','l','l','o',0 }, "hello", STATUS_SUCCESS
},
2035 { { '-',0x7f,'-',0x80,'-',0xff,'-',0x100,'-',0 }, "-\x7F-\xC2\x80-\xC3\xBF-\xC4\x80-", STATUS_SUCCESS
},
2036 { { '-',0x7ff,'-',0x800,'-',0 }, "-\xDF\xBF-\xE0\xA0\x80-", STATUS_SUCCESS
},
2037 { { '-',0xd7ff,'-',0xe000,'-',0 }, "-\xED\x9F\xBF-\xEE\x80\x80-", STATUS_SUCCESS
},
2039 { { '-',0xffff,'-',0xd800,0xdc00,'-',0 }, "-\xEF\xBF\xBF-\xF0\x90\x80\x80-", STATUS_SUCCESS
},
2040 /* 0x103ff */ /* 0x10400 */
2041 { { '-',0xd800,0xdfff,'-',0xd801,0xdc00,'-',0 }, "-\xF0\x90\x8F\xBF-\xF0\x90\x90\x80-", STATUS_SUCCESS
},
2043 { { '-',0xdbff,0xdfff,'-',0 }, "-\xF4\x8F\xBF\xBF-", STATUS_SUCCESS
},
2044 /* standalone lead surrogates become 0xFFFD */
2045 { { '-',0xd800,'-',0xdbff,'-',0 }, "-\xEF\xBF\xBD-\xEF\xBF\xBD-", STATUS_SOME_NOT_MAPPED
},
2046 /* standalone trail surrogates become 0xFFFD */
2047 { { '-',0xdc00,'-',0xdfff,'-',0 }, "-\xEF\xBF\xBD-\xEF\xBF\xBD-", STATUS_SOME_NOT_MAPPED
},
2048 /* reverse surrogate pair */
2049 { { '-',0xdfff,0xdbff,'-',0 }, "-\xEF\xBF\xBD\xEF\xBF\xBD-", STATUS_SOME_NOT_MAPPED
},
2050 /* byte order marks */
2051 { { '-',0xfeff,'-',0xfffe,'-',0 }, "-\xEF\xBB\xBF-\xEF\xBF\xBE-", STATUS_SUCCESS
},
2052 { { 0xfeff,'-',0 }, "\xEF\xBB\xBF-", STATUS_SUCCESS
},
2053 { { 0xfffe,'-',0 }, "\xEF\xBF\xBE-", STATUS_SUCCESS
},
2054 /* invalid code points */
2055 { { 0xfffd, '-', 0xfffe, '-', 0xffff,'-',0 }, "\xEF\xBF\xBD-\xEF\xBF\xBE-\xEF\xBF\xBF-", STATUS_SUCCESS
},
2056 /* canonically equivalent representations -- no normalization should happen */
2057 { { '-',0x1e09,'-',0 }, "-\xE1\xB8\x89-", STATUS_SUCCESS
},
2058 { { '-',0x0107,0x0327,'-',0 }, "-\xC4\x87\xCC\xA7-", STATUS_SUCCESS
},
2059 { { '-',0x00e7,0x0301,'-',0 }, "-\xC3\xA7\xCC\x81-", STATUS_SUCCESS
},
2060 { { '-',0x0063,0x0327,0x0301,'-',0 }, "-\x63\xCC\xA7\xCC\x81-", STATUS_SUCCESS
},
2061 { { '-',0x0063,0x0301,0x0327,'-',0 }, "-\x63\xCC\x81\xCC\xA7-", STATUS_SUCCESS
},
2064 static void utf8_expect_(const unsigned char *out_string
, ULONG buflen
, ULONG out_bytes
,
2065 const WCHAR
*in_string
, ULONG in_bytes
,
2066 NTSTATUS expect_status
, int line
)
2071 unsigned char *buf
= (unsigned char *)buffer
;
2074 if (buflen
== (ULONG
)-1)
2075 buflen
= sizeof(buffer
);
2076 bytes_out
= 0x55555555;
2077 memset(buffer
, 0x55, sizeof(buffer
));
2078 status
= pRtlUnicodeToUTF8N(
2079 out_string
? buffer
: NULL
, buflen
, &bytes_out
,
2080 in_string
, in_bytes
);
2081 ok_(__FILE__
, line
)(status
== expect_status
, "status 0x%x, expected 0x%x\n", status
, expect_status
);
2082 ok_(__FILE__
, line
)(bytes_out
== out_bytes
, "bytes_out = %u, expected %u\n", bytes_out
, out_bytes
);
2085 for (i
= 0; i
< bytes_out
; i
++)
2086 ok_(__FILE__
, line
)(buf
[i
] == out_string
[i
],
2087 "buffer[%d] = 0x%x, expected 0x%x\n",
2088 i
, buf
[i
], out_string
[i
]);
2089 for (; i
< sizeof(buffer
); i
++)
2090 ok_(__FILE__
, line
)(buf
[i
] == 0x55,
2091 "buffer[%d] = 0x%x, expected 0x55\n",
2095 #define utf8_expect(out_string, buflen, out_bytes, in_string, in_bytes, expect_status) \
2096 utf8_expect_(out_string, buflen, out_bytes, in_string, in_bytes, expect_status, __LINE__)
2098 static void test_RtlUnicodeToUTF8N(void)
2102 ULONG bytes_out_array
[2];
2103 void * const invalid_pointer
= (void *)0x8;
2105 const WCHAR empty_string
[] = { 0 };
2106 const WCHAR test_string
[] = { 'A',0,'a','b','c','d','e','f','g',0 };
2107 const WCHAR special_string
[] = { 'X',0x80,0xd800,0 };
2108 const ULONG special_string_len
[] = { 0, 1, 1, 3, 3, 3, 6, 7 };
2109 const unsigned char special_expected
[] = { 'X',0xc2,0x80,0xef,0xbf,0xbd,0 };
2110 unsigned int input_len
;
2111 const unsigned int test_count
= ARRAY_SIZE(unicode_to_utf8
);
2112 unsigned int i
, ret
;
2114 if (!pRtlUnicodeToUTF8N
)
2116 skip("RtlUnicodeToUTF8N unavailable\n");
2120 /* show that bytes_out is really ULONG */
2121 memset(bytes_out_array
, 0x55, sizeof(bytes_out_array
));
2122 status
= pRtlUnicodeToUTF8N(NULL
, 0, bytes_out_array
, empty_string
, 0);
2123 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2124 ok(bytes_out_array
[0] == 0x00000000, "Got 0x%x\n", bytes_out_array
[0]);
2125 ok(bytes_out_array
[1] == 0x55555555, "Got 0x%x\n", bytes_out_array
[1]);
2127 /* parameter checks */
2128 status
= pRtlUnicodeToUTF8N(NULL
, 0, NULL
, NULL
, 0);
2129 ok(status
== STATUS_INVALID_PARAMETER_4
, "status = 0x%x\n", status
);
2131 status
= pRtlUnicodeToUTF8N(NULL
, 0, NULL
, empty_string
, 0);
2132 ok(status
== STATUS_INVALID_PARAMETER
, "status = 0x%x\n", status
);
2134 bytes_out
= 0x55555555;
2135 status
= pRtlUnicodeToUTF8N(NULL
, 0, &bytes_out
, NULL
, 0);
2136 ok(status
== STATUS_INVALID_PARAMETER_4
, "status = 0x%x\n", status
);
2137 ok(bytes_out
== 0x55555555, "bytes_out = 0x%x\n", bytes_out
);
2139 bytes_out
= 0x55555555;
2140 status
= pRtlUnicodeToUTF8N(NULL
, 0, &bytes_out
, invalid_pointer
, 0);
2141 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2142 ok(bytes_out
== 0, "bytes_out = 0x%x\n", bytes_out
);
2144 bytes_out
= 0x55555555;
2145 status
= pRtlUnicodeToUTF8N(NULL
, 0, &bytes_out
, empty_string
, 0);
2146 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2147 ok(bytes_out
== 0, "bytes_out = 0x%x\n", bytes_out
);
2149 bytes_out
= 0x55555555;
2150 status
= pRtlUnicodeToUTF8N(NULL
, 0, &bytes_out
, test_string
, 0);
2151 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2152 ok(bytes_out
== 0, "bytes_out = 0x%x\n", bytes_out
);
2154 bytes_out
= 0x55555555;
2155 status
= pRtlUnicodeToUTF8N(NULL
, 0, &bytes_out
, empty_string
, 1);
2156 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2157 ok(bytes_out
== 0, "bytes_out = 0x%x\n", bytes_out
);
2159 bytes_out
= 0x55555555;
2160 status
= pRtlUnicodeToUTF8N(invalid_pointer
, 0, &bytes_out
, empty_string
, 1);
2161 ok(status
== STATUS_INVALID_PARAMETER_5
, "status = 0x%x\n", status
);
2162 ok(bytes_out
== 0x55555555, "bytes_out = 0x%x\n", bytes_out
);
2164 bytes_out
= 0x55555555;
2165 status
= pRtlUnicodeToUTF8N(invalid_pointer
, 8, &bytes_out
, empty_string
, 1);
2166 ok(status
== STATUS_INVALID_PARAMETER_5
, "status = 0x%x\n", status
);
2167 ok(bytes_out
== 0x55555555, "bytes_out = 0x%x\n", bytes_out
);
2169 /* length output with special chars */
2170 #define length_expect(in_chars, out_bytes, expect_status) \
2171 utf8_expect_(NULL, 0, out_bytes, \
2172 special_string, in_chars * sizeof(WCHAR), \
2173 expect_status, __LINE__)
2175 length_expect(0, 0, STATUS_SUCCESS
);
2176 length_expect(1, 1, STATUS_SUCCESS
);
2177 length_expect(2, 3, STATUS_SUCCESS
);
2178 length_expect(3, 6, STATUS_SOME_NOT_MAPPED
);
2179 length_expect(4, 7, STATUS_SOME_NOT_MAPPED
);
2180 #undef length_expect
2182 for (i
= 0; i
<= 6; i
++)
2184 memset(buffer
, 0x55, sizeof(buffer
));
2185 bytes_out
= 0xdeadbeef;
2186 status
= pRtlUnicodeToUTF8N(buffer
, i
, &bytes_out
, special_string
, sizeof(special_string
));
2187 ok(status
== STATUS_BUFFER_TOO_SMALL
, "%d: status = 0x%x\n", i
, status
);
2188 ok(bytes_out
== special_string_len
[i
], "%d: expected %u, got %u\n", i
, special_string_len
[i
], bytes_out
);
2189 ok(memcmp(buffer
, special_expected
, special_string_len
[i
]) == 0, "%d: bad conversion\n", i
);
2192 status
= pRtlUnicodeToUTF8N(buffer
, 7, &bytes_out
, special_string
, sizeof(special_string
));
2193 ok(status
== STATUS_SOME_NOT_MAPPED
, "status = 0x%x\n", status
);
2194 ok(bytes_out
== special_string_len
[7], "expected %u, got %u\n", special_string_len
[7], bytes_out
);
2195 ok(memcmp(buffer
, special_expected
, 7) == 0, "bad conversion\n");
2197 /* conversion behavior with varying input length */
2198 for (input_len
= 0; input_len
<= sizeof(test_string
); input_len
++) {
2199 /* no output buffer, just length */
2200 utf8_expect(NULL
, 0, input_len
/ sizeof(WCHAR
),
2201 test_string
, input_len
, STATUS_SUCCESS
);
2204 bytes_out
= 0x55555555;
2205 memset(buffer
, 0x55, sizeof(buffer
));
2206 status
= pRtlUnicodeToUTF8N(
2207 buffer
, sizeof(buffer
), &bytes_out
,
2208 test_string
, input_len
);
2209 if (input_len
% sizeof(WCHAR
) == 0) {
2210 ok(status
== STATUS_SUCCESS
,
2211 "(len %u): status = 0x%x\n", input_len
, status
);
2212 ok(bytes_out
== input_len
/ sizeof(WCHAR
),
2213 "(len %u): bytes_out = 0x%x\n", input_len
, bytes_out
);
2214 for (i
= 0; i
< bytes_out
; i
++) {
2215 ok(buffer
[i
] == test_string
[i
],
2216 "(len %u): buffer[%d] = 0x%x, expected 0x%x\n",
2217 input_len
, i
, buffer
[i
], test_string
[i
]);
2219 for (; i
< sizeof(buffer
); i
++) {
2220 ok(buffer
[i
] == 0x55,
2221 "(len %u): buffer[%d] = 0x%x\n", input_len
, i
, buffer
[i
]);
2224 ok(status
== STATUS_INVALID_PARAMETER_5
,
2225 "(len %u): status = 0x%x\n", input_len
, status
);
2226 ok(bytes_out
== 0x55555555,
2227 "(len %u): bytes_out = 0x%x\n", input_len
, bytes_out
);
2228 for (i
= 0; i
< sizeof(buffer
); i
++) {
2229 ok(buffer
[i
] == 0x55,
2230 "(len %u): buffer[%d] = 0x%x\n", input_len
, i
, buffer
[i
]);
2235 /* test cases for special characters */
2236 for (i
= 0; i
< test_count
; i
++) {
2237 bytes_out
= 0x55555555;
2238 memset(buffer
, 0x55, sizeof(buffer
));
2239 status
= pRtlUnicodeToUTF8N(
2240 buffer
, sizeof(buffer
), &bytes_out
,
2241 unicode_to_utf8
[i
].unicode
, lstrlenW(unicode_to_utf8
[i
].unicode
) * sizeof(WCHAR
));
2242 ok(status
== unicode_to_utf8
[i
].status
,
2243 "(test %d): status is 0x%x, expected 0x%x\n",
2244 i
, status
, unicode_to_utf8
[i
].status
);
2245 ok(bytes_out
== strlen(unicode_to_utf8
[i
].expected
),
2246 "(test %d): bytes_out is %u, expected %u\n",
2247 i
, bytes_out
, lstrlenA(unicode_to_utf8
[i
].expected
));
2248 ok(!memcmp(buffer
, unicode_to_utf8
[i
].expected
, bytes_out
),
2249 "(test %d): got \"%.*s\", expected \"%s\"\n",
2250 i
, bytes_out
, buffer
, unicode_to_utf8
[i
].expected
);
2251 ok(buffer
[bytes_out
] == 0x55,
2252 "(test %d): behind string: 0x%x\n", i
, buffer
[bytes_out
]);
2253 memset(buffer
, 0x55, sizeof(buffer
));
2254 ret
= WideCharToMultiByte( CP_UTF8
, 0, unicode_to_utf8
[i
].unicode
, lstrlenW(unicode_to_utf8
[i
].unicode
),
2255 buffer
, sizeof(buffer
), NULL
, NULL
);
2256 ok( ret
== strlen(unicode_to_utf8
[i
].expected
), "(test %d): wrong len %u\n", i
, ret
);
2257 ok(!memcmp(buffer
, unicode_to_utf8
[i
].expected
, ret
),
2258 "(test %d): got \"%.*s\", expected \"%s\"\n",
2259 i
, ret
, buffer
, unicode_to_utf8
[i
].expected
);
2260 ok(buffer
[ret
] == 0x55, "(test %d): behind string: 0x%x\n", i
, buffer
[ret
]);
2262 /* same test but include the null terminator */
2263 bytes_out
= 0x55555555;
2264 memset(buffer
, 0x55, sizeof(buffer
));
2265 status
= pRtlUnicodeToUTF8N(
2266 buffer
, sizeof(buffer
), &bytes_out
,
2267 unicode_to_utf8
[i
].unicode
, (lstrlenW(unicode_to_utf8
[i
].unicode
) + 1) * sizeof(WCHAR
));
2268 ok(status
== unicode_to_utf8
[i
].status
,
2269 "(test %d): status is 0x%x, expected 0x%x\n",
2270 i
, status
, unicode_to_utf8
[i
].status
);
2271 ok(bytes_out
== strlen(unicode_to_utf8
[i
].expected
) + 1,
2272 "(test %d): bytes_out is %u, expected %u\n",
2273 i
, bytes_out
, lstrlenA(unicode_to_utf8
[i
].expected
) + 1);
2274 ok(!memcmp(buffer
, unicode_to_utf8
[i
].expected
, bytes_out
),
2275 "(test %d): got \"%.*s\", expected \"%s\"\n",
2276 i
, bytes_out
, buffer
, unicode_to_utf8
[i
].expected
);
2277 ok(buffer
[bytes_out
] == 0x55,
2278 "(test %d): behind string: 0x%x\n", i
, buffer
[bytes_out
]);
2279 memset(buffer
, 0x55, sizeof(buffer
));
2280 ret
= WideCharToMultiByte( CP_UTF8
, 0, unicode_to_utf8
[i
].unicode
, -1, buffer
, sizeof(buffer
), NULL
, NULL
);
2281 ok( ret
== strlen(unicode_to_utf8
[i
].expected
) + 1, "(test %d): wrong len %u\n", i
, ret
);
2282 ok(!memcmp(buffer
, unicode_to_utf8
[i
].expected
, ret
),
2283 "(test %d): got \"%.*s\", expected \"%s\"\n",
2284 i
, ret
, buffer
, unicode_to_utf8
[i
].expected
);
2285 ok(buffer
[ret
] == 0x55, "(test %d): behind string: 0x%x\n", i
, buffer
[ret
]);
2286 SetLastError( 0xdeadbeef );
2287 memset(buffer
, 0x55, sizeof(buffer
));
2288 ret
= WideCharToMultiByte( CP_UTF8
, WC_ERR_INVALID_CHARS
, unicode_to_utf8
[i
].unicode
, -1,
2289 buffer
, sizeof(buffer
), NULL
, NULL
);
2290 if (unicode_to_utf8
[i
].status
== STATUS_SOME_NOT_MAPPED
)
2292 ok( ret
== 0, "(test %d): wrong len %u\n", i
, ret
);
2293 ok( GetLastError() == ERROR_NO_UNICODE_TRANSLATION
, "(test %d): wrong error %u\n", i
, GetLastError() );
2294 ret
= strlen(unicode_to_utf8
[i
].expected
) + 1;
2297 ok( ret
== strlen(unicode_to_utf8
[i
].expected
) + 1, "(test %d): wrong len %u\n", i
, ret
);
2299 ok(!memcmp(buffer
, unicode_to_utf8
[i
].expected
, ret
),
2300 "(test %d): got \"%.*s\", expected \"%s\"\n",
2301 i
, ret
, buffer
, unicode_to_utf8
[i
].expected
);
2302 ok(buffer
[ret
] == 0x55, "(test %d): behind string: 0x%x\n", i
, buffer
[ret
]);
2306 struct utf8_to_unicode_test
{
2308 WCHAR expected
[128];
2312 static const struct utf8_to_unicode_test utf8_to_unicode
[] = {
2313 { "", { 0 }, STATUS_SUCCESS
},
2314 { "-", { '-',0 }, STATUS_SUCCESS
},
2315 { "hello", { 'h','e','l','l','o',0 }, STATUS_SUCCESS
},
2316 /* first and last of each range */
2317 { "-\x7F-\xC2\x80-\xC3\xBF-\xC4\x80-", { '-',0x7f,'-',0x80,'-',0xff,'-',0x100,'-',0 }, STATUS_SUCCESS
},
2318 { "-\xDF\xBF-\xE0\xA0\x80-", { '-',0x7ff,'-',0x800,'-',0 }, STATUS_SUCCESS
},
2319 { "-\xED\x9F\xBF-\xEE\x80\x80-", { '-',0xd7ff,'-',0xe000,'-',0 }, STATUS_SUCCESS
},
2321 { "-\xEF\xBF\xBF-\xF0\x90\x80\x80-", { '-',0xffff,'-',0xd800,0xdc00,'-',0 }, STATUS_SUCCESS
},
2322 /* 0x103ff */ /* 0x10400 */
2323 { "-\xF0\x90\x8F\xBF-\xF0\x90\x90\x80-", { '-',0xd800,0xdfff,'-',0xd801,0xdc00,'-',0 }, STATUS_SUCCESS
},
2325 { "-\xF4\x8F\xBF\xBF-", { '-',0xdbff,0xdfff,'-',0 }, STATUS_SUCCESS
},
2326 /* standalone surrogate code points */
2327 /* 0xd800 */ /* 0xdbff */
2328 { "-\xED\xA0\x80-\xED\xAF\xBF-", { '-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2329 /* 0xdc00 */ /* 0xdfff */
2330 { "-\xED\xB0\x80-\xED\xBF\xBF-", { '-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2331 /* UTF-8 encoded surrogate pair */
2332 /* 0xdbff *//* 0xdfff */
2333 { "-\xED\xAF\xBF\xED\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2334 /* reverse surrogate pair */
2335 /* 0xdfff *//* 0xdbff */
2336 { "-\xED\xBF\xBF\xED\xAF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2337 /* code points outside the UTF-16 range */
2339 { "-\xF4\x90\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2341 { "-\xF7\xBF\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2343 { "-\xFA\x80\x80\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2345 { "-\xFB\xBF\xBF\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2347 { "-\xFC\x84\x80\x80\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2349 { "-\xFD\xBF\xBF\xBF\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2350 /* overlong encodings of each length for -, NUL, and the highest possible value */
2351 { "-\xC0\xAD-\xC0\x80-\xC1\xBF-", { '-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2352 { "-\xE0\x80\xAD-\xE0\x80\x80-\xE0\x9F\xBF-", { '-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2353 { "-\xF0\x80\x80\xAD-", { '-',0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2354 { "-\xF0\x80\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2355 { "-\xF0\x8F\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2356 { "-\xF8\x80\x80\x80\xAD-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2357 { "-\xF8\x80\x80\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2358 { "-\xF8\x87\xBF\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2359 { "-\xFC\x80\x80\x80\x80\xAD-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2360 { "-\xFC\x80\x80\x80\x80\x80-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2361 { "-\xFC\x83\xBF\xBF\xBF\xBF-", { '-',0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2363 { "\xFE", { 0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2364 { "\xFF", { 0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2365 { "\xFE\xBF\xBF\xBF\xBF\xBF\xBF\xBF\xBF", { 0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2366 { "\xFF\xBF\xBF\xBF\xBF\xBF\xBF\xBF\xBF", { 0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2367 { "\xFF\x80\x80\x80\x80\x80\x80\x80\x80", { 0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2368 { "\xFF\x40\x80\x80\x80\x80\x80\x80\x80", { 0xfffd,0x40,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2369 /* lone continuation bytes */
2370 { "\x80", { 0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2371 { "\x80\x80", { 0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2372 { "\xBF", { 0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2373 { "\xBF\xBF", { 0xfffd,0xfffd,0 }, STATUS_SOME_NOT_MAPPED
},
2374 /* incomplete sequences */
2375 { "\xC2-", { 0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2376 { "\xE0\xA0-", { 0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2377 { "\xF0\x90\x80-", { 0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2378 { "\xF4\x8F\xBF-", { 0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2379 { "\xFA\x80\x80\x80-", { 0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2380 { "\xFC\x84\x80\x80\x80-", { 0xfffd,0xfffd,0xfffd,0xfffd,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2381 /* multibyte sequence followed by lone continuation byte */
2382 { "\xE0\xA0\x80\x80-", { 0x800,0xfffd,'-',0 }, STATUS_SOME_NOT_MAPPED
},
2383 /* byte order marks */
2384 { "-\xEF\xBB\xBF-\xEF\xBF\xBE-", { '-',0xfeff,'-',0xfffe,'-',0 }, STATUS_SUCCESS
},
2385 { "\xEF\xBB\xBF-", { 0xfeff,'-',0 }, STATUS_SUCCESS
},
2386 { "\xEF\xBF\xBE-", { 0xfffe,'-',0 }, STATUS_SUCCESS
},
2387 /* invalid code points */
2388 { "\xEF\xBF\xBD-\xEF\xBF\xBE-\xEF\xBF\xBF-", { 0xfffd,'-',0xfffe,'-',0xffff,'-',0 }, STATUS_SUCCESS
},
2389 /* canonically equivalent representations -- no normalization should happen */
2390 { "-\xE1\xB8\x89-", { '-',0x1e09,'-',0 }, STATUS_SUCCESS
},
2391 { "-\xC4\x87\xCC\xA7-", { '-',0x0107,0x0327,'-',0 }, STATUS_SUCCESS
},
2392 { "-\xC3\xA7\xCC\x81-", { '-',0x00e7,0x0301,'-',0 }, STATUS_SUCCESS
},
2393 { "-\x63\xCC\xA7\xCC\x81-", { '-',0x0063,0x0327,0x0301,'-',0 }, STATUS_SUCCESS
},
2394 { "-\x63\xCC\x81\xCC\xA7-", { '-',0x0063,0x0301,0x0327,'-',0 }, STATUS_SUCCESS
},
2397 static void unicode_expect_(const WCHAR
*out_string
, ULONG buflen
, ULONG out_chars
,
2398 const char *in_string
, ULONG in_chars
,
2399 NTSTATUS expect_status
, int line
)
2406 if (buflen
== (ULONG
)-1)
2407 buflen
= sizeof(buffer
);
2408 bytes_out
= 0x55555555;
2409 memset(buffer
, 0x55, sizeof(buffer
));
2410 status
= pRtlUTF8ToUnicodeN(
2411 out_string
? buffer
: NULL
, buflen
, &bytes_out
,
2412 in_string
, in_chars
);
2413 ok_(__FILE__
, line
)(status
== expect_status
, "status = 0x%x\n", status
);
2414 ok_(__FILE__
, line
)(bytes_out
== out_chars
* sizeof(WCHAR
),
2415 "bytes_out = %u, expected %u\n", bytes_out
, out_chars
* (ULONG
)sizeof(WCHAR
));
2418 for (i
= 0; i
< bytes_out
/ sizeof(WCHAR
); i
++)
2419 ok_(__FILE__
, line
)(buffer
[i
] == out_string
[i
],
2420 "buffer[%d] = 0x%x, expected 0x%x\n",
2421 i
, buffer
[i
], out_string
[i
]);
2422 for (; i
< ARRAY_SIZE(buffer
); i
++)
2423 ok_(__FILE__
, line
)(buffer
[i
] == 0x5555,
2424 "buffer[%d] = 0x%x, expected 0x5555\n",
2428 #define unicode_expect(out_string, buflen, out_chars, in_string, in_chars, expect_status) \
2429 unicode_expect_(out_string, buflen, out_chars, in_string, in_chars, expect_status, __LINE__)
2431 static void test_RtlUTF8ToUnicodeN(void)
2435 ULONG bytes_out_array
[2];
2436 void * const invalid_pointer
= (void *)0x8;
2438 const char empty_string
[] = "";
2439 const char test_string
[] = "A\0abcdefg";
2440 const WCHAR test_stringW
[] = {'A',0,'a','b','c','d','e','f','g',0 };
2441 const char special_string
[] = { 'X',0xc2,0x80,0xF0,0x90,0x80,0x80,0 };
2442 const WCHAR special_expected
[] = { 'X',0x80,0xd800,0xdc00,0 };
2443 unsigned int input_len
;
2444 const unsigned int test_count
= ARRAY_SIZE(utf8_to_unicode
);
2445 unsigned int i
, ret
;
2447 if (!pRtlUTF8ToUnicodeN
)
2449 skip("RtlUTF8ToUnicodeN unavailable\n");
2453 /* show that bytes_out is really ULONG */
2454 memset(bytes_out_array
, 0x55, sizeof(bytes_out_array
));
2455 status
= pRtlUTF8ToUnicodeN(NULL
, 0, bytes_out_array
, empty_string
, 0);
2456 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2457 ok(bytes_out_array
[0] == 0x00000000, "Got 0x%x\n", bytes_out_array
[0]);
2458 ok(bytes_out_array
[1] == 0x55555555, "Got 0x%x\n", bytes_out_array
[1]);
2460 /* parameter checks */
2461 status
= pRtlUTF8ToUnicodeN(NULL
, 0, NULL
, NULL
, 0);
2462 ok(status
== STATUS_INVALID_PARAMETER_4
, "status = 0x%x\n", status
);
2464 status
= pRtlUTF8ToUnicodeN(NULL
, 0, NULL
, empty_string
, 0);
2465 ok(status
== STATUS_INVALID_PARAMETER
, "status = 0x%x\n", status
);
2467 bytes_out
= 0x55555555;
2468 status
= pRtlUTF8ToUnicodeN(NULL
, 0, &bytes_out
, NULL
, 0);
2469 ok(status
== STATUS_INVALID_PARAMETER_4
, "status = 0x%x\n", status
);
2470 ok(bytes_out
== 0x55555555, "bytes_out = 0x%x\n", bytes_out
);
2472 bytes_out
= 0x55555555;
2473 status
= pRtlUTF8ToUnicodeN(NULL
, 0, &bytes_out
, invalid_pointer
, 0);
2474 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2475 ok(bytes_out
== 0, "bytes_out = 0x%x\n", bytes_out
);
2477 bytes_out
= 0x55555555;
2478 status
= pRtlUTF8ToUnicodeN(NULL
, 0, &bytes_out
, empty_string
, 0);
2479 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2480 ok(bytes_out
== 0, "bytes_out = 0x%x\n", bytes_out
);
2482 bytes_out
= 0x55555555;
2483 status
= pRtlUTF8ToUnicodeN(NULL
, 0, &bytes_out
, test_string
, 0);
2484 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2485 ok(bytes_out
== 0, "bytes_out = 0x%x\n", bytes_out
);
2487 bytes_out
= 0x55555555;
2488 status
= pRtlUTF8ToUnicodeN(NULL
, 0, &bytes_out
, empty_string
, 1);
2489 ok(status
== STATUS_SUCCESS
, "status = 0x%x\n", status
);
2490 ok(bytes_out
== sizeof(WCHAR
), "bytes_out = 0x%x\n", bytes_out
);
2492 /* length output with special chars */
2493 #define length_expect(in_chars, out_chars, expect_status) \
2494 unicode_expect_(NULL, 0, out_chars, special_string, in_chars, \
2495 expect_status, __LINE__)
2497 length_expect(0, 0, STATUS_SUCCESS
);
2498 length_expect(1, 1, STATUS_SUCCESS
);
2499 length_expect(2, 2, STATUS_SOME_NOT_MAPPED
);
2500 length_expect(3, 2, STATUS_SUCCESS
);
2501 length_expect(4, 3, STATUS_SOME_NOT_MAPPED
);
2502 length_expect(5, 3, STATUS_SOME_NOT_MAPPED
);
2503 length_expect(6, 3, STATUS_SOME_NOT_MAPPED
);
2504 length_expect(7, 4, STATUS_SUCCESS
);
2505 length_expect(8, 5, STATUS_SUCCESS
);
2506 #undef length_expect
2508 /* output truncation */
2509 #define truncate_expect(buflen, out_chars, expect_status) \
2510 unicode_expect_(special_expected, buflen, out_chars, \
2511 special_string, sizeof(special_string), \
2512 expect_status, __LINE__)
2514 truncate_expect( 0, 0, STATUS_BUFFER_TOO_SMALL
);
2515 truncate_expect( 1, 0, STATUS_BUFFER_TOO_SMALL
);
2516 truncate_expect( 2, 1, STATUS_BUFFER_TOO_SMALL
);
2517 truncate_expect( 3, 1, STATUS_BUFFER_TOO_SMALL
);
2518 truncate_expect( 4, 2, STATUS_BUFFER_TOO_SMALL
);
2519 truncate_expect( 5, 2, STATUS_BUFFER_TOO_SMALL
);
2520 truncate_expect( 6, 3, STATUS_BUFFER_TOO_SMALL
);
2521 truncate_expect( 7, 3, STATUS_BUFFER_TOO_SMALL
);
2522 truncate_expect( 8, 4, STATUS_BUFFER_TOO_SMALL
);
2523 truncate_expect( 9, 4, STATUS_BUFFER_TOO_SMALL
);
2524 truncate_expect(10, 5, STATUS_SUCCESS
);
2525 #undef truncate_expect
2527 /* conversion behavior with varying input length */
2528 for (input_len
= 0; input_len
<= sizeof(test_string
); input_len
++) {
2529 /* no output buffer, just length */
2530 unicode_expect(NULL
, 0, input_len
,
2531 test_string
, input_len
, STATUS_SUCCESS
);
2534 unicode_expect(test_stringW
, -1, input_len
,
2535 test_string
, input_len
, STATUS_SUCCESS
);
2538 /* test cases for special characters */
2539 for (i
= 0; i
< test_count
; i
++) {
2540 bytes_out
= 0x55555555;
2541 memset(buffer
, 0x55, sizeof(buffer
));
2542 status
= pRtlUTF8ToUnicodeN(
2543 buffer
, sizeof(buffer
), &bytes_out
,
2544 utf8_to_unicode
[i
].utf8
, strlen(utf8_to_unicode
[i
].utf8
));
2545 ok(status
== utf8_to_unicode
[i
].status
,
2546 "(test %d): status is 0x%x, expected 0x%x\n",
2547 i
, status
, utf8_to_unicode
[i
].status
);
2548 ok(bytes_out
== lstrlenW(utf8_to_unicode
[i
].expected
) * sizeof(WCHAR
),
2549 "(test %d): bytes_out is %u, expected %u\n",
2550 i
, bytes_out
, lstrlenW(utf8_to_unicode
[i
].expected
) * (ULONG
)sizeof(WCHAR
));
2551 ok(!memcmp(buffer
, utf8_to_unicode
[i
].expected
, bytes_out
),
2552 "(test %d): got %s, expected %s\n",
2553 i
, wine_dbgstr_wn(buffer
, bytes_out
/ sizeof(WCHAR
)), wine_dbgstr_w(utf8_to_unicode
[i
].expected
));
2554 ok(buffer
[bytes_out
/ sizeof(WCHAR
)] == 0x5555,
2555 "(test %d): behind string: 0x%x\n", i
, buffer
[bytes_out
/ sizeof(WCHAR
)]);
2556 memset(buffer
, 0x55, sizeof(buffer
));
2557 ret
= MultiByteToWideChar( CP_UTF8
, 0, utf8_to_unicode
[i
].utf8
, strlen(utf8_to_unicode
[i
].utf8
),
2558 buffer
, ARRAY_SIZE(buffer
) );
2559 ok( ret
== lstrlenW(utf8_to_unicode
[i
].expected
), "(test %d): wrong len %u\n", i
, ret
);
2560 ok(!memcmp(buffer
, utf8_to_unicode
[i
].expected
, lstrlenW(utf8_to_unicode
[i
].expected
) * sizeof(WCHAR
)),
2561 "(test %d): got %s, expected %s\n",
2562 i
, wine_dbgstr_wn(buffer
, ret
), wine_dbgstr_w(utf8_to_unicode
[i
].expected
));
2563 ok(buffer
[ret
] == 0x5555,
2564 "(test %d): behind string: 0x%x\n", i
, buffer
[ret
]);
2566 /* same test but include the null terminator */
2567 bytes_out
= 0x55555555;
2568 memset(buffer
, 0x55, sizeof(buffer
));
2569 status
= pRtlUTF8ToUnicodeN(
2570 buffer
, sizeof(buffer
), &bytes_out
,
2571 utf8_to_unicode
[i
].utf8
, strlen(utf8_to_unicode
[i
].utf8
) + 1);
2572 ok(status
== utf8_to_unicode
[i
].status
,
2573 "(test %d): status is 0x%x, expected 0x%x\n",
2574 i
, status
, utf8_to_unicode
[i
].status
);
2575 ok(bytes_out
== (lstrlenW(utf8_to_unicode
[i
].expected
) + 1) * sizeof(WCHAR
),
2576 "(test %d): bytes_out is %u, expected %u\n",
2577 i
, bytes_out
, (lstrlenW(utf8_to_unicode
[i
].expected
) + 1) * (ULONG
)sizeof(WCHAR
));
2578 ok(!memcmp(buffer
, utf8_to_unicode
[i
].expected
, bytes_out
),
2579 "(test %d): got %s, expected %s\n",
2580 i
, wine_dbgstr_wn(buffer
, bytes_out
/ sizeof(WCHAR
)), wine_dbgstr_w(utf8_to_unicode
[i
].expected
));
2581 ok(buffer
[bytes_out
/ sizeof(WCHAR
)] == 0x5555,
2582 "(test %d): behind string: 0x%x\n", i
, buffer
[bytes_out
/ sizeof(WCHAR
)]);
2584 memset(buffer
, 0x55, sizeof(buffer
));
2585 ret
= MultiByteToWideChar( CP_UTF8
, 0, utf8_to_unicode
[i
].utf8
, -1, buffer
, ARRAY_SIZE(buffer
) );
2586 ok( ret
== lstrlenW(utf8_to_unicode
[i
].expected
) + 1, "(test %d): wrong len %u\n", i
, ret
);
2587 ok(!memcmp(buffer
, utf8_to_unicode
[i
].expected
, ret
* sizeof(WCHAR
)),
2588 "(test %d): got %s, expected %s\n",
2589 i
, wine_dbgstr_wn(buffer
, ret
), wine_dbgstr_w(utf8_to_unicode
[i
].expected
));
2590 ok(buffer
[ret
] == 0x5555,
2591 "(test %d): behind string: 0x%x\n", i
, buffer
[ret
]);
2593 SetLastError( 0xdeadbeef );
2594 memset(buffer
, 0x55, sizeof(buffer
));
2595 ret
= MultiByteToWideChar( CP_UTF8
, MB_ERR_INVALID_CHARS
,
2596 utf8_to_unicode
[i
].utf8
, -1, buffer
, ARRAY_SIZE(buffer
) );
2597 if (utf8_to_unicode
[i
].status
== STATUS_SOME_NOT_MAPPED
)
2599 ok( ret
== 0, "(test %d): wrong len %u\n", i
, ret
);
2600 ok( GetLastError() == ERROR_NO_UNICODE_TRANSLATION
, "(test %d): wrong error %u\n", i
, GetLastError() );
2601 ret
= lstrlenW(utf8_to_unicode
[i
].expected
) + 1;
2604 ok( ret
== lstrlenW(utf8_to_unicode
[i
].expected
) + 1, "(test %d): wrong len %u\n", i
, ret
);
2606 ok(!memcmp(buffer
, utf8_to_unicode
[i
].expected
, ret
* sizeof(WCHAR
)),
2607 "(test %d): got %s, expected %s\n",
2608 i
, wine_dbgstr_wn(buffer
, ret
), wine_dbgstr_w(utf8_to_unicode
[i
].expected
));
2609 ok(buffer
[ret
] == 0x5555,
2610 "(test %d): behind string: 0x%x\n", i
, buffer
[ret
]);
2614 static NTSTATUS WINAPIV
fmt( const WCHAR
*src
, ULONG width
, BOOLEAN ignore_inserts
, BOOLEAN ansi
,
2615 WCHAR
*buffer
, ULONG size
, ULONG
*retsize
, ... )
2620 *retsize
= 0xdeadbeef;
2621 __ms_va_start( args
, retsize
);
2622 status
= pRtlFormatMessage( src
, width
, ignore_inserts
, ansi
, FALSE
, &args
, buffer
, size
, retsize
);
2623 __ms_va_end( args
);
2627 static void WINAPIV
testfmt( const WCHAR
*src
, const WCHAR
*expect
, ULONG width
, BOOL ansi
, ... )
2632 ULONG size
= 0xdeadbeef;
2634 memset( buffer
, 0xcc, sizeof(buffer
) );
2635 __ms_va_start( args
, ansi
);
2636 status
= pRtlFormatMessage( src
, width
, FALSE
, ansi
, FALSE
, &args
, buffer
, sizeof(buffer
), &size
);
2637 __ms_va_end( args
);
2638 ok( !status
, "%s: failed %x\n", debugstr_w(src
), status
);
2639 ok( !lstrcmpW( buffer
, expect
), "%s: got %s expected %s\n", debugstr_w(src
),
2640 debugstr_w(buffer
), debugstr_w(expect
) );
2641 ok( size
== (lstrlenW(expect
) + 1) * sizeof(WCHAR
), "%s: wrong size %u\n", debugstr_w(src
), size
);
2644 static void test_RtlFormatMessage(void)
2651 testfmt( L
"test", L
"test", 0, FALSE
);
2652 testfmt( L
"", L
"", 0, FALSE
);
2653 testfmt( L
"%1", L
"test", 0, FALSE
, L
"test" );
2654 testfmt( L
"%1!s!", L
"test", 0, FALSE
, L
"test" );
2655 testfmt( L
"%1!s!", L
"foo", 0, TRUE
, "foo" );
2656 testfmt( L
"%1!S!", L
"test", 0, FALSE
, "test" );
2657 testfmt( L
"%1!S!", L
"foo", 0, TRUE
, L
"foo" );
2658 testfmt( L
"%1!hs!%1!hS!", L
"testtest", 0, FALSE
, "test" );
2659 testfmt( L
"%1!ls!%1!lS!%1!ws!%1!wS!", L
"foofoofoofoo", 0, TRUE
, L
"foo" );
2660 testfmt( L
"%1!c!", L
"a", 0, FALSE
, L
'a' );
2661 testfmt( L
"%1!c!", L
"b", 0, TRUE
, 'b' );
2662 testfmt( L
"%1!C!", L
"c", 0, FALSE
, L
'c' );
2663 testfmt( L
"%1!C!", L
"d", 0, TRUE
, 'd' );
2664 testfmt( L
"%1!hc!", L
"e", 0, FALSE
, L
'e' );
2665 testfmt( L
"%1!hC!", L
"f", 0, FALSE
, L
'f' );
2666 testfmt( L
"%1!lc!", L
"g", 0, TRUE
, 'g' );
2667 testfmt( L
"%1!lC!", L
"h", 0, TRUE
, 'h' );
2668 testfmt( L
"%1!wc!", L
"i", 0, TRUE
, 'i' );
2669 testfmt( L
"%1!wC!", L
"j", 0, TRUE
, 'j' );
2670 testfmt( L
"%1!04X!", L
"BEEF", 0, FALSE
, 0xbeef );
2671 testfmt( L
"%1!Saa!", L
"testaa", 0, FALSE
, "test" );
2672 testfmt( L
"%.%%%Z%n%t%r%!% ", L
".%Z\r\n\t\r! ", 0, FALSE
);
2673 testfmt( L
"%1!*.*u!,%1!*.*u!", L
" 001, 0002", 0, FALSE
, 5, 3, 1, 4, 2 );
2674 testfmt( L
"%1!*.*u!,%3!*.*u!", L
" 001, 0002", 0, FALSE
, 5, 3, 1, 6, 4, 2 );
2675 testfmt( L
"%1", L
"(null)", 0, FALSE
, NULL
);
2676 testfmt( L
"%2", L
"(null)", 0, TRUE
, "abc", NULL
);
2677 testfmt( L
"ab%1!!cd", L
"abcd", 0, FALSE
, L
"hello" );
2678 testfmt( L
"abc%1!#.000000000000000000000000000x!", L
"abc0x22", 0, FALSE
, 34 );
2679 testfmt( L
"a\r\nb\rc\r\rd\r\r\ne", L
"a\r\nb\r\nc\r\n\r\nd\r\n\r\ne", 0, FALSE
, NULL
);
2681 testfmt( L
"%1!#I64x! %2!x!", L
"0x1234 5678", 0, FALSE
, (ULONG_PTR
)0x1234, 0x5678, 0xbeef );
2682 testfmt( L
"%1!x! %2!#I64x! %3!#I64x! %4!x!", L
"dead 0x1111222233334444 0x5555666677778888 beef",
2683 0, FALSE
, 0xdead, 0x1111222233334444ull
, 0x5555666677778888ull
, 0xbeef );
2684 testfmt( L
"%3!#I64x! %4!#I64x! %3!x! %1!x!", L
"0x3 0x4 3 1", 0, FALSE
, 0xdead00000001ll
, 2, 3ll, 4ll );
2685 testfmt( L
"%2!x! %1!I64x!", L
"5678 1234", 0, FALSE
, (ULONG_PTR
)0x1234, 0x5678, 0xbeef );
2686 testfmt( L
"%2!*.*I64x! %1!u! %4!u! %2!u!", L
" 00000000000000d 19 11 17", 0, FALSE
,
2687 19ull, 17ull, 15ull, 13ull, 11ull, 9ull );
2688 { /* argument array works differently */
2689 ULONG_PTR args
[] = { 19, 17, 15, 13, 11, 9, 7 };
2690 memset( buffer
, 0xcc, sizeof(buffer
) );
2691 status
= pRtlFormatMessage( L
"%2!*.*I64x! %1!u! %4!u! %2!u!", 0, FALSE
, FALSE
, TRUE
,
2692 (__ms_va_list
*)args
, buffer
, sizeof(buffer
), &size
);
2693 ok( !lstrcmpW( buffer
, L
" 00000000000000d 19 13 17" ), "got %s\n", wine_dbgstr_w(buffer
) );
2694 memset( buffer
, 0xcc, sizeof(buffer
) );
2695 status
= pRtlFormatMessage( L
"%1!I64u! %2!u! %4!.*I64x! %5!I64u!", 0, FALSE
, FALSE
, TRUE
,
2696 (__ms_va_list
*)args
, buffer
, sizeof(buffer
), &size
);
2697 ok( !lstrcmpW( buffer
, L
"19 17 000000000000b 11" ), "got %s\n", wine_dbgstr_w(buffer
) );
2700 fmt( L
"%1!#I64x! %2!x!", 0, FALSE
, FALSE
, buffer
, sizeof(buffer
), &size
, 0x1234, 0x5678, 0xbeef );
2701 if (lstrcmpW( buffer
, L
"0x567800001234 5678" ))
2703 testfmt( L
"%1!#I64x! %2!x!", L
"0x567800001234 beef", 0, FALSE
, 0x1234, 0x5678, 0xbeef );
2704 testfmt( L
"%1!x! %2!#I64x! %3!#I64x! %4!x!", L
"dead 0x1111222233334444 0x5555666677778888 beef",
2705 0, FALSE
, 0xdead, 0x1111222233334444ull
, 0x5555666677778888ull
, 0xbeef );
2706 testfmt( L
"%3!#I64x! %4!#I64x! %3!x! %1!x!", L
"0x1111222233334444 0x5555666677778888 33334444 1",
2707 0, FALSE
, 1, 2, 3, 4, 0x33334444, 0x11112222, 0x77778888, 0x55556666, 0xbeef, 0xbee2 );
2708 testfmt( L
"%2!x! %1!I64x!", L
"5678 1234", 0, FALSE
, 0x1234, 0x5678, 0xbeef );
2709 testfmt( L
"%2!*.*I64x! %1!u! %4!u! %2!u!", L
" 000090000000b 19 7 15", 0, FALSE
,
2710 19, 17, 15, 13, 11, 9, 7 );
2711 { /* argument array works differently */
2712 ULONG_PTR args
[] = { 19, 17, 15, 13, 11, 9, 7 };
2713 memset( buffer
, 0xcc, sizeof(buffer
) );
2714 status
= pRtlFormatMessage( L
"%2!*.*I64x! %1!u! %4!u! %2!u!", 0, FALSE
, FALSE
, TRUE
,
2715 (__ms_va_list
*)args
, buffer
, sizeof(buffer
), &size
);
2716 ok( !lstrcmpW( buffer
, L
" d0000000f 19 13 17" ), "got %s\n", wine_dbgstr_w(buffer
) );
2717 memset( buffer
, 0xcc, sizeof(buffer
) );
2718 status
= pRtlFormatMessage( L
"%1!I64u! %2!u! %4!.*I64x! %5!I64u!", 0, FALSE
, FALSE
, TRUE
,
2719 (__ms_va_list
*)args
, buffer
, sizeof(buffer
), &size
);
2720 ok( !lstrcmpW( buffer
, L
"19 17 0000b00000000 11" ), "got %s\n", wine_dbgstr_w(buffer
) );
2723 else win_skip( "I64 support broken\n" );
2725 testfmt( L
"%1!Ix! %2!QQ!", L
"1234 QQ", 0, FALSE
, (ULONG_PTR
)0x1234 );
2726 testfmt( L
"%1!#llx!%2!#x!%1!#hx!", L
"0x1234560x789abc0x3456", 0, FALSE
, 0x123456, 0x789abc );
2727 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2728 fmt( L
"ab%0cd", 0, FALSE
, FALSE
, buffer
, sizeof(buffer
), &size
);
2729 ok( !memcmp( buffer
, L
"ab\0xxxxxxx", 10 * sizeof(WCHAR
) ), "got %s\n", wine_dbgstr_wn(buffer
, 10) );
2732 testfmt( L
"%1", L
"testing\r\n", 3, FALSE
, L
"testing" );
2733 testfmt( L
"%1%2%3", L
"testing\r\nabcdef\r\nfoobar\r\n", 4, FALSE
, L
"testing", L
"abcdef", L
"foobar");
2734 testfmt( L
"%1%2%3%4", L
"test\r\nabcd\r\nabcdef\r\n", 4, FALSE
, L
"test", L
"abcd", L
"abc", L
"def" );
2735 testfmt( L
"%1a\nb%2", L
"testing\r\na\r\nbfoo bar\r\n", 3, FALSE
, L
"testing", L
"foo bar" );
2736 testfmt( L
"a%tb%t%t%t%c%r%r%r%r%r%rdefg", L
"a\r\nb\r\n\r\n\r\nc\r\r\r\r\r\rdef\r\ng", 3, FALSE
);
2737 testfmt( L
"test abcd ", L
"test\r\n\r\nabcd\r\n ", 4, FALSE
);
2738 testfmt( L
"test abcdef %1 foobar", L
"tes\r\nt\r\nabc\r\ndef\r\n\r\nhello\r\nfoo\r\nbar\r\n", 3, FALSE
, L
"hello" );
2739 testfmt( L
"te st\nabc d\nfoo", L
"te st\r\nabc d\r\nfoo", 6, FALSE
);
2740 testfmt( L
"te st ab d\nfoo", L
"te st\r\n ab\r\n d foo", 7, FALSE
);
2741 testfmt( L
"te\tst\t\t\t\tab\t\t\td\nfoo", L
"te\tst\t\t\r\n\t\tab\t\t\t\r\nd foo", 7, FALSE
);
2742 testfmt( L
"te st\n\n\r\n\nab d\nfoo ", L
"te st\r\n ab\r\n d foo\r\n ", 7, FALSE
);
2743 testfmt( L
"te st\r\nabc d\n\nfoo\rbar", L
"te st abc d foo bar", 0xff, FALSE
);
2744 testfmt( L
"te st%r%nabc d%nfoo%rbar", L
"te st\r\r\nabc d\r\nfoo\rbar", 0xff, FALSE
);
2745 testfmt( L
"\01\02\03\04\a\a\a\a\b\b\b\b\t\t\t\t\v\v\v\v\f\f\f\f\r\r\r\r a",
2746 L
"\01\02\r\n\03\04\r\n\a\a\r\n\a\a\r\n\b\b\r\n\b\b\r\n\t\t\r\n\t\t\r\n\v\v\r\n\v\v\r\n\f\f\r\n\f\f\r\n\r\n\r\n\r\n\r\na", 2, FALSE
);
2748 for (i
= 1; i
< 0xffff; i
++)
2750 WCHAR src
[] = { i
, ' ', i
, i
, i
, i
, i
, ' ', i
, 0 };
2755 lstrcpyW( expect
, L
"\r\n\r\n\t" );
2760 lstrcpyW( expect
, L
"\r\n\r\n " );
2763 lstrcpyW( expect
, L
" %% \r\nxxxx" );
2766 swprintf( expect
, ARRAY_SIZE(expect
), L
"%c\r\n%c%c%c%c\r\n%c %c", i
, i
, i
, i
, i
, i
, i
);
2769 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2770 fmt( src
, 4, FALSE
, FALSE
, buffer
, sizeof(buffer
), &size
);
2771 ok( !lstrcmpW( buffer
, expect
), "%04x: got %s\n", i
, debugstr_w(buffer
) );
2774 /* args are not counted the same way with an argument array */
2776 ULONG_PTR args
[] = { 6, 4, 2, 5, 3, 1 };
2777 memset( buffer
, 0xcc, sizeof(buffer
) );
2778 status
= pRtlFormatMessage( L
"%1!*.*u!,%1!*.*u!", 0, FALSE
, FALSE
, TRUE
, (__ms_va_list
*)args
,
2779 buffer
, sizeof(buffer
), &size
);
2780 ok( !lstrcmpW( buffer
, L
" 0002, 00003" ), "got %s\n", wine_dbgstr_w(buffer
) );
2781 memset( buffer
, 0xcc, sizeof(buffer
) );
2782 status
= pRtlFormatMessage( L
"%1!*.*u!,%4!*.*u!", 0, FALSE
, FALSE
, TRUE
, (__ms_va_list
*)args
,
2783 buffer
, sizeof(buffer
), &size
);
2784 ok( !lstrcmpW( buffer
, L
" 0002, 001" ), "got %s\n", wine_dbgstr_w(buffer
) );
2787 /* buffer overflows */
2788 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2789 status
= fmt( L
"testing", 0, FALSE
, FALSE
, buffer
, 8, &size
);
2790 ok( status
== STATUS_BUFFER_OVERFLOW
, "failed %x\n", status
);
2791 ok( !lstrcmpW( buffer
, L
"testxxxxxx" ) || broken(!lstrcmpW( buffer
, L
"tesxxxxxxx" )), /* winxp */
2792 "got %s\n", wine_dbgstr_w(buffer
) );
2793 ok( size
== 0xdeadbeef, "wrong size %u\n", size
);
2795 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2796 status
= fmt( L
"%1", 0, FALSE
, FALSE
, buffer
, 8, &size
, L
"test" );
2797 ok( status
== STATUS_BUFFER_OVERFLOW
, "failed %x\n", status
);
2798 ok( !memcmp( buffer
, L
"tes\0xxxxxx", 10 * sizeof(WCHAR
) ) || broken(!lstrcmpW( buffer
, L
"testxxxxxx" )), /* winxp */
2799 "got %s\n", wine_dbgstr_w(buffer
) );
2800 ok( size
== 0xdeadbeef, "wrong size %u\n", size
);
2802 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2803 status
= fmt( L
"%1!x!", 0, FALSE
, FALSE
, buffer
, 8, &size
, 0x12345678 );
2804 ok( status
== STATUS_BUFFER_OVERFLOW
, "failed %x\n", status
);
2805 ok( !memcmp( buffer
, L
"123\0xxxxxx", 10 * sizeof(WCHAR
) ) || broken(!lstrcmpW( buffer
, L
"1234xxxxxx" )), /* winxp */
2806 "got %s\n", wine_dbgstr_w(buffer
) );
2807 ok( size
== 0xdeadbeef, "wrong size %u\n", size
);
2809 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2810 status
= fmt( L
"%1!*s!", 0, FALSE
, FALSE
, buffer
, 10, &size
, 5, L
"abc" );
2811 ok( status
== STATUS_BUFFER_OVERFLOW
, "failed %x\n", status
);
2812 ok( !memcmp( buffer
, L
" ab\0xxxxx", 10 * sizeof(WCHAR
) ) || broken(!lstrcmpW( buffer
, L
" abcxxxxx" )), /* winxp */
2813 "got %s\n", wine_dbgstr_w(buffer
) );
2814 ok( size
== 0xdeadbeef, "wrong size %u\n", size
);
2816 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2817 status
= fmt( L
"ab%n", 0, FALSE
, FALSE
, buffer
, 6, &size
);
2818 ok( status
== STATUS_BUFFER_OVERFLOW
, "failed %x\n", status
);
2819 ok( !memcmp( buffer
, L
"abxxxxxxxx", 10 * sizeof(WCHAR
) ), "got %s\n", wine_dbgstr_w(buffer
) );
2820 ok( size
== 0xdeadbeef, "wrong size %u\n", size
);
2822 /* ignore inserts */
2823 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2824 status
= fmt( L
"%1!x!%r%%%n%t", 0, TRUE
, FALSE
, buffer
, sizeof(buffer
), &size
);
2825 ok( !lstrcmpW( buffer
, L
"%1!x!\r%%\r\n\t" ), "got %s\n", wine_dbgstr_w(buffer
) );
2827 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2828 status
= fmt( L
"ab%0cd", 0, TRUE
, FALSE
, buffer
, sizeof(buffer
), &size
);
2829 ok( !status
, "failed %x\n", status
);
2830 ok( !memcmp( buffer
, L
"ab\0xxxxxxx", 10 * sizeof(WCHAR
) ), "got %s\n", wine_dbgstr_wn(buffer
, 10) );
2833 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2835 status
= pRtlFormatMessage( L
"abc%1", 0, FALSE
, FALSE
, FALSE
, NULL
, buffer
, sizeof(buffer
), &size
);
2836 ok( status
== STATUS_INVALID_PARAMETER
, "failed %x\n", status
);
2837 ok( !lstrcmpW( buffer
, L
"abcxxxxxxx" ), "got %s\n", wine_dbgstr_w(buffer
) );
2838 ok( size
== 0xdeadbeef, "wrong size %u\n", size
);
2840 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2841 status
= pRtlFormatMessage( L
"abc%1", 0, FALSE
, FALSE
, TRUE
, NULL
, buffer
, sizeof(buffer
), &size
);
2842 ok( status
== STATUS_INVALID_PARAMETER
, "failed %x\n", status
);
2843 ok( !lstrcmpW( buffer
, L
"abcxxxxxxx" ), "got %s\n", wine_dbgstr_w(buffer
) );
2844 ok( size
== 0xdeadbeef, "wrong size %u\n", size
);
2846 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2847 status
= pRtlFormatMessage( L
"abc%", 0, FALSE
, FALSE
, TRUE
, NULL
, buffer
, sizeof(buffer
), &size
);
2848 ok( status
== STATUS_INVALID_PARAMETER
, "failed %x\n", status
);
2849 ok( !lstrcmpW( buffer
, L
"abcxxxxxxx" ), "got %s\n", wine_dbgstr_w(buffer
) );
2850 ok( size
== 0xdeadbeef, "wrong size %u\n", size
);
2852 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2853 status
= fmt( L
"%1!u! %2!u", 0, FALSE
, FALSE
, buffer
, sizeof(buffer
), &size
, 34 );
2854 ok( status
== STATUS_INVALID_PARAMETER
, "failed %x\n", status
);
2855 ok( !lstrcmpW( buffer
, L
"34 xxxxxxx" ), "got %s\n", wine_dbgstr_w(buffer
) );
2856 ok( size
== 0xdeadbeef, "wrong size %u\n", size
);
2858 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2859 status
= fmt( L
"%1!**u!", 0, FALSE
, FALSE
, buffer
, sizeof(buffer
), &size
, 34 );
2860 ok( status
== STATUS_SUCCESS
, "failed %x\n", status
);
2861 ok( !lstrcmpW( buffer
, L
"*u" ), "got %s\n", wine_dbgstr_w(buffer
) );
2863 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2864 status
= fmt( L
"%1!0.3+*u!", 0, FALSE
, FALSE
, buffer
, sizeof(buffer
), &size
, 34 );
2865 ok( status
== STATUS_SUCCESS
, "failed %x\n", status
);
2866 ok( !lstrcmpW( buffer
, L
"+*u" ), "got %s\n", wine_dbgstr_w(buffer
) );
2868 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2869 status
= fmt( L
"aa%1!***u!", 0, FALSE
, FALSE
, buffer
, sizeof(buffer
), &size
, 34 );
2870 ok( status
== STATUS_INVALID_PARAMETER
, "failed %x\n", status
);
2871 ok( !lstrcmpW( buffer
, L
"aaxxxxxxxx" ), "got %s\n", wine_dbgstr_w(buffer
) );
2872 ok( size
== 0xdeadbeef, "wrong size %u\n", size
);
2874 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2875 status
= fmt( L
"abc%1!#.000000000000000000000000000x!", 0, FALSE
, FALSE
, buffer
, sizeof(buffer
), &size
, 34 );
2876 ok( status
== STATUS_SUCCESS
, "failed %x\n", status
);
2877 ok( !lstrcmpW( buffer
, L
"abc0x22" ), "got %s\n", wine_dbgstr_w(buffer
) );
2879 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2880 status
= fmt( L
"abc%1!#.0000000000000000000000000000x!", 0, FALSE
, FALSE
, buffer
, sizeof(buffer
), &size
, 34 );
2881 ok( status
== STATUS_INVALID_PARAMETER
, "failed %x\n", status
);
2882 ok( !lstrcmpW( buffer
, L
"abcxxxxxxx" ), "got %s\n", wine_dbgstr_w(buffer
) );
2883 ok( size
== 0xdeadbeef, "wrong size %u\n", size
);
2885 lstrcpyW( buffer
, L
"xxxxxxxxxx" );
2886 status
= fmt( L
"abc%1!hsaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!", 0, FALSE
, FALSE
, buffer
, sizeof(buffer
), &size
, "hello" );
2887 ok( status
== STATUS_INVALID_PARAMETER
, "failed %x\n", status
);
2888 ok( !lstrcmpW( buffer
, L
"abcxxxxxxx" ), "got %s\n", wine_dbgstr_w(buffer
) );
2889 ok( size
== 0xdeadbeef, "wrong size %u\n", size
);
2896 if (pRtlInitAnsiString
) {
2897 test_RtlInitString();
2898 test_RtlInitUnicodeString();
2899 test_RtlCopyString();
2900 test_RtlUnicodeStringToInteger();
2901 test_RtlCharToInteger();
2902 test_RtlIntegerToUnicodeString();
2903 test_RtlIntegerToChar();
2904 test_RtlUpperChar();
2905 test_RtlUpperString();
2906 test_RtlUnicodeStringToAnsiString();
2907 test_RtlAppendAsciizToString();
2908 test_RtlAppendStringToString();
2909 test_RtlAppendUnicodeToString();
2910 test_RtlAppendUnicodeStringToString();
2913 test_RtlInitUnicodeStringEx();
2914 test_RtlDuplicateUnicodeString();
2915 test_RtlFindCharInUnicodeString();
2916 test_RtlGUIDFromString();
2917 test_RtlStringFromGUID();
2918 test_RtlIsTextUnicode();
2919 test_RtlCompareUnicodeString();
2920 test_RtlUpcaseUnicodeChar();
2921 test_RtlUpcaseUnicodeString();
2922 test_RtlDowncaseUnicodeString();
2923 test_RtlHashUnicodeString();
2924 test_RtlUnicodeToUTF8N();
2925 test_RtlUTF8ToUnicodeN();
2926 test_RtlFormatMessage();