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