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