| 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 | #include <string.h> | 
|---|
| 27 |  | 
|---|
| 28 | #include "winbase.h" | 
|---|
| 29 | #include "test.h" | 
|---|
| 30 | #include "winnt.h" | 
|---|
| 31 | #include "winnls.h" | 
|---|
| 32 | #include "winternl.h" | 
|---|
| 33 |  | 
|---|
| 34 | static UNICODE_STRING uni; | 
|---|
| 35 | static STRING str; | 
|---|
| 36 |  | 
|---|
| 37 | /* Function ptrs for ntdll calls */ | 
|---|
| 38 | static HMODULE hntdll = 0; | 
|---|
| 39 | static NTSTATUS (WINAPI *pRtlAppendUnicodeStringToString)(UNICODE_STRING *, const UNICODE_STRING *); | 
|---|
| 40 | static NTSTATUS (WINAPI *pRtlCharToInteger)(char *, ULONG, int *); | 
|---|
| 41 | static VOID     (WINAPI *pRtlCopyString)(STRING *, const STRING *); | 
|---|
| 42 | static BOOLEAN  (WINAPI *pRtlCreateUnicodeString)(PUNICODE_STRING, LPCWSTR); | 
|---|
| 43 | static NTSTATUS (WINAPI *pRtlDowncaseUnicodeString)(UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN); | 
|---|
| 44 | static BOOLEAN  (WINAPI *pRtlEqualUnicodeString)(const UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN); | 
|---|
| 45 | static VOID     (WINAPI *pRtlFreeAnsiString)(PSTRING); | 
|---|
| 46 | static VOID     (WINAPI *pRtlInitAnsiString)(PSTRING, LPCSTR); | 
|---|
| 47 | static VOID     (WINAPI *pRtlInitString)(PSTRING, LPCSTR); | 
|---|
| 48 | static VOID     (WINAPI *pRtlInitUnicodeString)(PUNICODE_STRING, LPCWSTR); | 
|---|
| 49 | static NTSTATUS (WINAPI *pRtlIntegerToChar)(ULONG, ULONG, ULONG, PCHAR); | 
|---|
| 50 | static NTSTATUS (WINAPI *pRtlIntegerToUnicodeString)(ULONG, ULONG, UNICODE_STRING *); | 
|---|
| 51 | static NTSTATUS (WINAPI *pRtlUnicodeStringToAnsiString)(STRING *, const UNICODE_STRING *, BOOLEAN); | 
|---|
| 52 | static NTSTATUS (WINAPI *pRtlUnicodeStringToInteger)(const UNICODE_STRING *, int, int *); | 
|---|
| 53 | static WCHAR    (WINAPI *pRtlUpcaseUnicodeChar)(WCHAR); | 
|---|
| 54 | static NTSTATUS (WINAPI *pRtlUpcaseUnicodeString)(UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN); | 
|---|
| 55 | static CHAR     (WINAPI *pRtlUpperChar)(CHAR); | 
|---|
| 56 | static NTSTATUS (WINAPI *pRtlUpperString)(STRING *, const STRING *); | 
|---|
| 57 |  | 
|---|
| 58 | /*static VOID (WINAPI *pRtlFreeOemString)(PSTRING);*/ | 
|---|
| 59 | /*static BOOLEAN (WINAPI *pRtlCreateUnicodeStringFromAsciiz)(PUNICODE_STRING,LPCSTR);*/ | 
|---|
| 60 | /*static VOID (WINAPI *pRtlFreeUnicodeString)(PUNICODE_STRING);*/ | 
|---|
| 61 | /*static VOID (WINAPI *pRtlCopyUnicodeString)(UNICODE_STRING *, const UNICODE_STRING *);*/ | 
|---|
| 62 | /*static VOID (WINAPI *pRtlEraseUnicodeString)(UNICODE_STRING *);*/ | 
|---|
| 63 | /*static LONG (WINAPI *pRtlCompareString)(const STRING *,const STRING *,BOOLEAN);*/ | 
|---|
| 64 | /*static LONG (WINAPI *pRtlCompareUnicodeString)(const UNICODE_STRING *,const UNICODE_STRING *,BOOLEAN);*/ | 
|---|
| 65 | /*static BOOLEAN (WINAPI *pRtlEqualString)(const STRING *,const STRING *,BOOLEAN);*/ | 
|---|
| 66 | /*static BOOLEAN (WINAPI *pRtlPrefixString)(const STRING *, const STRING *, BOOLEAN);*/ | 
|---|
| 67 | /*static BOOLEAN (WINAPI *pRtlPrefixUnicodeString)(const UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN);*/ | 
|---|
| 68 | /*static NTSTATUS (WINAPI *pRtlAnsiStringToUnicodeString)(PUNICODE_STRING, PCANSI_STRING, BOOLEAN);*/ | 
|---|
| 69 | /*static NTSTATUS (WINAPI *pRtlOemStringToUnicodeString)(PUNICODE_STRING, const STRING *, BOOLEAN);*/ | 
|---|
| 70 | /*static NTSTATUS (WINAPI *pRtlUnicodeStringToOemString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/ | 
|---|
| 71 | /*static NTSTATUS (WINAPI *pRtlMultiByteToUnicodeN)(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD);*/ | 
|---|
| 72 | /*static NTSTATUS (WINAPI *pRtlOemToUnicodeN)(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD);*/ | 
|---|
| 73 | /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeStringToAnsiString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/ | 
|---|
| 74 | /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeStringToOemString)(STRING *, const UNICODE_STRING *, BOOLEAN);*/ | 
|---|
| 75 | /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeToMultiByteN)(LPSTR, DWORD, LPDWORD, LPCWSTR, DWORD);*/ | 
|---|
| 76 | /*static NTSTATUS (WINAPI *pRtlUpcaseUnicodeToOemN)(LPSTR, DWORD, LPDWORD, LPCWSTR, DWORD);*/ | 
|---|
| 77 | /*static UINT (WINAPI *pRtlOemToUnicodeSize)(const STRING *);*/ | 
|---|
| 78 | /*static DWORD (WINAPI *pRtlAnsiStringToUnicodeSize)(const STRING *);*/ | 
|---|
| 79 | /*static DWORD (WINAPI *pRtlIsTextUnicode)(LPVOID, DWORD, DWORD *);*/ | 
|---|
| 80 |  | 
|---|
| 81 |  | 
|---|
| 82 | static WCHAR* AtoW( char* p ) | 
|---|
| 83 | { | 
|---|
| 84 | WCHAR* buffer; | 
|---|
| 85 | DWORD len = MultiByteToWideChar( CP_ACP, 0, p, -1, NULL, 0 ); | 
|---|
| 86 | buffer = malloc( len * sizeof(WCHAR) ); | 
|---|
| 87 | MultiByteToWideChar( CP_ACP, 0, p, -1, buffer, len ); | 
|---|
| 88 | return buffer; | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 |  | 
|---|
| 92 | static void InitFunctionPtrs(void) | 
|---|
| 93 | { | 
|---|
| 94 | hntdll = LoadLibraryA("ntdll.dll"); | 
|---|
| 95 | ok(hntdll != 0, "LoadLibrary failed"); | 
|---|
| 96 | if (hntdll) { | 
|---|
| 97 | pRtlAppendUnicodeStringToString = (void *)GetProcAddress(hntdll, "RtlAppendUnicodeStringToString"); | 
|---|
| 98 | pRtlCharToInteger = (void *)GetProcAddress(hntdll, "RtlCharToInteger"); | 
|---|
| 99 | pRtlCopyString = (void *)GetProcAddress(hntdll, "RtlCopyString"); | 
|---|
| 100 | pRtlCreateUnicodeString = (void *)GetProcAddress(hntdll, "RtlCreateUnicodeString"); | 
|---|
| 101 | pRtlDowncaseUnicodeString = (void *)GetProcAddress(hntdll, "RtlDowncaseUnicodeString"); | 
|---|
| 102 | pRtlEqualUnicodeString = (void *)GetProcAddress(hntdll, "RtlEqualUnicodeString"); | 
|---|
| 103 | pRtlFreeAnsiString = (void *)GetProcAddress(hntdll, "RtlFreeAnsiString"); | 
|---|
| 104 | pRtlInitAnsiString = (void *)GetProcAddress(hntdll, "RtlInitAnsiString"); | 
|---|
| 105 | pRtlInitString = (void *)GetProcAddress(hntdll, "RtlInitString"); | 
|---|
| 106 | pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString"); | 
|---|
| 107 | pRtlIntegerToChar = (void *)GetProcAddress(hntdll, "RtlIntegerToChar"); | 
|---|
| 108 | pRtlIntegerToUnicodeString = (void *)GetProcAddress(hntdll, "RtlIntegerToUnicodeString"); | 
|---|
| 109 | pRtlUnicodeStringToAnsiString = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToAnsiString"); | 
|---|
| 110 | pRtlUnicodeStringToInteger = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToInteger"); | 
|---|
| 111 | pRtlUpcaseUnicodeChar = (void *)GetProcAddress(hntdll, "RtlUpcaseUnicodeChar"); | 
|---|
| 112 | pRtlUpcaseUnicodeString = (void *)GetProcAddress(hntdll, "RtlUpcaseUnicodeString"); | 
|---|
| 113 | pRtlUpperChar = (void *)GetProcAddress(hntdll, "RtlUpperChar"); | 
|---|
| 114 | pRtlUpperString = (void *)GetProcAddress(hntdll, "RtlUpperString"); | 
|---|
| 115 | } /* if */ | 
|---|
| 116 | } | 
|---|
| 117 |  | 
|---|
| 118 |  | 
|---|
| 119 | static void test_RtlInitString(void) | 
|---|
| 120 | { | 
|---|
| 121 | static const char teststring[] = "Some Wild String"; | 
|---|
| 122 | str.Length = 0; | 
|---|
| 123 | str.MaximumLength = 0; | 
|---|
| 124 | str.Buffer = (void *)0xdeadbeef; | 
|---|
| 125 | pRtlInitString(&str, teststring); | 
|---|
| 126 | ok(str.Length == sizeof(teststring) - sizeof(char), "Length uninitialized"); | 
|---|
| 127 | ok(str.MaximumLength == sizeof(teststring), "MaximumLength uninitialized"); | 
|---|
| 128 | ok(str.Buffer == teststring, "Buffer not equal to teststring"); | 
|---|
| 129 | ok(strcmp(str.Buffer, "Some Wild String") == 0, "Buffer written to"); | 
|---|
| 130 | pRtlInitString(&str, NULL); | 
|---|
| 131 | ok(str.Length == 0, "Length uninitialized"); | 
|---|
| 132 | ok(str.MaximumLength == 0, "MaximumLength uninitialized"); | 
|---|
| 133 | ok(str.Buffer == NULL, "Buffer not equal to NULL"); | 
|---|
| 134 | /*      pRtlInitString(NULL, teststring); */ | 
|---|
| 135 | } | 
|---|
| 136 |  | 
|---|
| 137 |  | 
|---|
| 138 | static void test_RtlInitUnicodeString(void) | 
|---|
| 139 | { | 
|---|
| 140 | #define STRINGW {'S','o','m','e',' ','W','i','l','d',' ','S','t','r','i','n','g',0} | 
|---|
| 141 | static const WCHAR teststring[] = STRINGW; | 
|---|
| 142 | static const WCHAR originalstring[] = STRINGW; | 
|---|
| 143 | #undef STRINGW | 
|---|
| 144 | uni.Length = 0; | 
|---|
| 145 | uni.MaximumLength = 0; | 
|---|
| 146 | uni.Buffer = (void *)0xdeadbeef; | 
|---|
| 147 | pRtlInitUnicodeString(&uni, teststring); | 
|---|
| 148 | ok(uni.Length == sizeof(teststring) - sizeof(WCHAR), "Length uninitialized"); | 
|---|
| 149 | ok(uni.MaximumLength == sizeof(teststring), "MaximumLength uninitialized"); | 
|---|
| 150 | ok(uni.Buffer == teststring, "Buffer not equal to teststring"); | 
|---|
| 151 | ok(lstrcmpW(uni.Buffer, originalstring) == 0, "Buffer written to"); | 
|---|
| 152 | pRtlInitUnicodeString(&uni, NULL); | 
|---|
| 153 | ok(uni.Length == 0, "Length uninitialized"); | 
|---|
| 154 | ok(uni.MaximumLength == 0, "MaximumLength uninitialized"); | 
|---|
| 155 | ok(uni.Buffer == NULL, "Buffer not equal to NULL"); | 
|---|
| 156 | /*      pRtlInitUnicodeString(NULL, teststring); */ | 
|---|
| 157 | } | 
|---|
| 158 |  | 
|---|
| 159 |  | 
|---|
| 160 | static void test_RtlCopyString(void) | 
|---|
| 161 | { | 
|---|
| 162 | static const char teststring[] = "Some Wild String"; | 
|---|
| 163 | static char deststring[] = "                    "; | 
|---|
| 164 | STRING deststr; | 
|---|
| 165 | pRtlInitString(&str, teststring); | 
|---|
| 166 | pRtlInitString(&deststr, deststring); | 
|---|
| 167 | pRtlCopyString(&deststr, &str); | 
|---|
| 168 | ok(strncmp(str.Buffer, deststring, str.Length) == 0, "String not copied"); | 
|---|
| 169 | } | 
|---|
| 170 |  | 
|---|
| 171 |  | 
|---|
| 172 | static void test_RtlUpperChar(void) | 
|---|
| 173 | { | 
|---|
| 174 | int ch; | 
|---|
| 175 | int upper_ch; | 
|---|
| 176 | int expected_upper_ch; | 
|---|
| 177 | int byte_ch; | 
|---|
| 178 |  | 
|---|
| 179 | for (ch = -1; ch <= 1024; ch++) { | 
|---|
| 180 | upper_ch = pRtlUpperChar(ch); | 
|---|
| 181 | byte_ch = ch & 0xff; | 
|---|
| 182 | if (byte_ch >= 'a' && byte_ch <= 'z') { | 
|---|
| 183 | expected_upper_ch = (CHAR) (byte_ch - 'a' + 'A'); | 
|---|
| 184 | } else { | 
|---|
| 185 | expected_upper_ch = (CHAR) byte_ch; | 
|---|
| 186 | } /* if */ | 
|---|
| 187 | ok(upper_ch == expected_upper_ch, | 
|---|
| 188 | "RtlUpperChar('%c'[=0x%x]) has result '%c'[=0x%x], expected '%c'[=0x%x]", | 
|---|
| 189 | ch, ch, upper_ch, upper_ch, expected_upper_ch, expected_upper_ch); | 
|---|
| 190 | } /* for */ | 
|---|
| 191 | } | 
|---|
| 192 |  | 
|---|
| 193 |  | 
|---|
| 194 | static void test_RtlUpperString(void) | 
|---|
| 195 | { | 
|---|
| 196 | int i; | 
|---|
| 197 | CHAR ch; | 
|---|
| 198 | CHAR upper_ch; | 
|---|
| 199 | char ascii_buf[257]; | 
|---|
| 200 | char result_buf[257]; | 
|---|
| 201 | char upper_buf[257]; | 
|---|
| 202 | STRING ascii_str; | 
|---|
| 203 | STRING result_str; | 
|---|
| 204 | STRING upper_str; | 
|---|
| 205 |  | 
|---|
| 206 | for (i = 0; i <= 255; i++) { | 
|---|
| 207 | ch = (CHAR) i; | 
|---|
| 208 | if (ch >= 'a' && ch <= 'z') { | 
|---|
| 209 | upper_ch = ch - 'a' + 'A'; | 
|---|
| 210 | } else { | 
|---|
| 211 | upper_ch = ch; | 
|---|
| 212 | } | 
|---|
| 213 | ascii_buf[i] = ch; | 
|---|
| 214 | result_buf[i] = '\0'; | 
|---|
| 215 | upper_buf[i] = upper_ch; | 
|---|
| 216 | } /* for */ | 
|---|
| 217 | ascii_buf[i] = '\0'; | 
|---|
| 218 | result_buf[i] = '\0'; | 
|---|
| 219 | upper_buf[i] = '\0'; | 
|---|
| 220 | ascii_str.Length = 256; | 
|---|
| 221 | ascii_str.MaximumLength = 256; | 
|---|
| 222 | ascii_str.Buffer = ascii_buf; | 
|---|
| 223 | result_str.Length = 256; | 
|---|
| 224 | result_str.MaximumLength = 256; | 
|---|
| 225 | result_str.Buffer = result_buf; | 
|---|
| 226 | upper_str.Length = 256; | 
|---|
| 227 | upper_str.MaximumLength = 256; | 
|---|
| 228 | upper_str.Buffer = upper_buf; | 
|---|
| 229 |  | 
|---|
| 230 | pRtlUpperString(&result_str, &ascii_str); | 
|---|
| 231 | ok(memcmp(result_str.Buffer, upper_str.Buffer, 256) == 0, | 
|---|
| 232 | "RtlUpperString does not work as expected"); | 
|---|
| 233 | } | 
|---|
| 234 |  | 
|---|
| 235 |  | 
|---|
| 236 | static void test_RtlUpcaseUnicodeChar(void) | 
|---|
| 237 | { | 
|---|
| 238 | int i; | 
|---|
| 239 | WCHAR ch; | 
|---|
| 240 | WCHAR upper_ch; | 
|---|
| 241 | WCHAR expected_upper_ch; | 
|---|
| 242 |  | 
|---|
| 243 | for (i = 0; i <= 255; i++) { | 
|---|
| 244 | ch = (WCHAR) i; | 
|---|
| 245 | upper_ch = pRtlUpcaseUnicodeChar(ch); | 
|---|
| 246 | if (ch >= 'a' && ch <= 'z') { | 
|---|
| 247 | expected_upper_ch = ch - 'a' + 'A'; | 
|---|
| 248 | } else if (ch >= 0xe0 && ch <= 0xfe && ch != 0xf7) { | 
|---|
| 249 | expected_upper_ch = ch - 0x20; | 
|---|
| 250 | } else if (ch == 0xff) { | 
|---|
| 251 | expected_upper_ch = 0x178; | 
|---|
| 252 | } else { | 
|---|
| 253 | expected_upper_ch = ch; | 
|---|
| 254 | } /* if */ | 
|---|
| 255 | ok(upper_ch == expected_upper_ch, | 
|---|
| 256 | "RtlUpcaseUnicodeChar('%c'[=0x%x]) has result '%c'[=0x%x], expected: '%c'[=0x%x]", | 
|---|
| 257 | ch, ch, upper_ch, upper_ch, expected_upper_ch, expected_upper_ch); | 
|---|
| 258 | } /* for */ | 
|---|
| 259 | } | 
|---|
| 260 |  | 
|---|
| 261 |  | 
|---|
| 262 | static void test_RtlUpcaseUnicodeString(void) | 
|---|
| 263 | { | 
|---|
| 264 | int i; | 
|---|
| 265 | WCHAR ch; | 
|---|
| 266 | WCHAR upper_ch; | 
|---|
| 267 | WCHAR ascii_buf[257]; | 
|---|
| 268 | WCHAR result_buf[257]; | 
|---|
| 269 | WCHAR upper_buf[257]; | 
|---|
| 270 | UNICODE_STRING ascii_str; | 
|---|
| 271 | UNICODE_STRING result_str; | 
|---|
| 272 | UNICODE_STRING upper_str; | 
|---|
| 273 |  | 
|---|
| 274 | for (i = 0; i <= 255; i++) { | 
|---|
| 275 | ch = (WCHAR) i; | 
|---|
| 276 | if (ch >= 'a' && ch <= 'z') { | 
|---|
| 277 | upper_ch = ch - 'a' + 'A'; | 
|---|
| 278 | } else if (ch >= 0xe0 && ch <= 0xfe && ch != 0xf7) { | 
|---|
| 279 | upper_ch = ch - 0x20; | 
|---|
| 280 | } else if (ch == 0xff) { | 
|---|
| 281 | upper_ch = 0x178; | 
|---|
| 282 | } else { | 
|---|
| 283 | upper_ch = ch; | 
|---|
| 284 | } /* if */ | 
|---|
| 285 | ascii_buf[i] = ch; | 
|---|
| 286 | result_buf[i] = '\0'; | 
|---|
| 287 | upper_buf[i] = upper_ch; | 
|---|
| 288 | } /* for */ | 
|---|
| 289 | ascii_buf[i] = '\0'; | 
|---|
| 290 | result_buf[i] = '\0'; | 
|---|
| 291 | upper_buf[i] = '\0'; | 
|---|
| 292 | ascii_str.Length = 512; | 
|---|
| 293 | ascii_str.MaximumLength = 512; | 
|---|
| 294 | ascii_str.Buffer = ascii_buf; | 
|---|
| 295 | result_str.Length = 512; | 
|---|
| 296 | result_str.MaximumLength = 512; | 
|---|
| 297 | result_str.Buffer = result_buf; | 
|---|
| 298 | upper_str.Length = 512; | 
|---|
| 299 | upper_str.MaximumLength = 512; | 
|---|
| 300 | upper_str.Buffer = upper_buf; | 
|---|
| 301 |  | 
|---|
| 302 | pRtlUpcaseUnicodeString(&result_str, &ascii_str, 0); | 
|---|
| 303 | for (i = 0; i <= 255; i++) { | 
|---|
| 304 | ok(result_str.Buffer[i] == upper_str.Buffer[i], | 
|---|
| 305 | "RtlUpcaseUnicodeString works wrong: '%c'[=0x%x] is converted to '%c'[=0x%x], expected: '%c'[=0x%x]", | 
|---|
| 306 | ascii_str.Buffer[i], ascii_str.Buffer[i], | 
|---|
| 307 | result_str.Buffer[i], result_str.Buffer[i], | 
|---|
| 308 | upper_str.Buffer[i], upper_str.Buffer[i]); | 
|---|
| 309 | } /* for */ | 
|---|
| 310 | } | 
|---|
| 311 |  | 
|---|
| 312 |  | 
|---|
| 313 | static void test_RtlDowncaseUnicodeString(void) | 
|---|
| 314 | { | 
|---|
| 315 | int i; | 
|---|
| 316 | WCHAR ch; | 
|---|
| 317 | WCHAR lower_ch; | 
|---|
| 318 | WCHAR source_buf[1025]; | 
|---|
| 319 | WCHAR result_buf[1025]; | 
|---|
| 320 | WCHAR lower_buf[1025]; | 
|---|
| 321 | UNICODE_STRING source_str; | 
|---|
| 322 | UNICODE_STRING result_str; | 
|---|
| 323 | UNICODE_STRING lower_str; | 
|---|
| 324 |  | 
|---|
| 325 | for (i = 0; i <= 1024; i++) { | 
|---|
| 326 | ch = (WCHAR) i; | 
|---|
| 327 | if (ch >= 'A' && ch <= 'Z') { | 
|---|
| 328 | lower_ch = ch - 'A' + 'a'; | 
|---|
| 329 | } else if (ch >= 0xc0 && ch <= 0xde && ch != 0xd7) { | 
|---|
| 330 | lower_ch = ch + 0x20; | 
|---|
| 331 | } else if (ch >= 0x391 && ch <= 0x3ab && ch != 0x3a2) { | 
|---|
| 332 | lower_ch = ch + 0x20; | 
|---|
| 333 | } else { | 
|---|
| 334 | switch (ch) { | 
|---|
| 335 | case 0x178: lower_ch = 0xff; break; | 
|---|
| 336 | case 0x181: lower_ch = 0x253; break; | 
|---|
| 337 | case 0x186: lower_ch = 0x254; break; | 
|---|
| 338 | case 0x189: lower_ch = 0x256; break; | 
|---|
| 339 | case 0x18a: lower_ch = 0x257; break; | 
|---|
| 340 | case 0x18e: lower_ch = 0x1dd; break; | 
|---|
| 341 | case 0x18f: lower_ch = 0x259; break; | 
|---|
| 342 | case 0x190: lower_ch = 0x25b; break; | 
|---|
| 343 | case 0x193: lower_ch = 0x260; break; | 
|---|
| 344 | case 0x194: lower_ch = 0x263; break; | 
|---|
| 345 | case 0x196: lower_ch = 0x269; break; | 
|---|
| 346 | case 0x197: lower_ch = 0x268; break; | 
|---|
| 347 | case 0x19c: lower_ch = 0x26f; break; | 
|---|
| 348 | case 0x19d: lower_ch = 0x272; break; | 
|---|
| 349 | case 0x19f: lower_ch = 0x275; break; | 
|---|
| 350 | case 0x1a9: lower_ch = 0x283; break; | 
|---|
| 351 | case 0x1ae: lower_ch = 0x288; break; | 
|---|
| 352 | case 0x1b1: lower_ch = 0x28a; break; | 
|---|
| 353 | case 0x1b2: lower_ch = 0x28b; break; | 
|---|
| 354 | case 0x1b7: lower_ch = 0x292; break; | 
|---|
| 355 | case 0x1c4: lower_ch = 0x1c6; break; | 
|---|
| 356 | case 0x1c7: lower_ch = 0x1c9; break; | 
|---|
| 357 | case 0x1ca: lower_ch = 0x1cc; break; | 
|---|
| 358 | case 0x1f1: lower_ch = 0x1f3; break; | 
|---|
| 359 | case 0x386: lower_ch = 0x3ac; break; | 
|---|
| 360 | case 0x388: lower_ch = 0x3ad; break; | 
|---|
| 361 | case 0x389: lower_ch = 0x3ae; break; | 
|---|
| 362 | case 0x38a: lower_ch = 0x3af; break; | 
|---|
| 363 | case 0x38c: lower_ch = 0x3cc; break; | 
|---|
| 364 | case 0x38e: lower_ch = 0x3cd; break; | 
|---|
| 365 | case 0x38f: lower_ch = 0x3ce; break; | 
|---|
| 366 | case 0x400: lower_ch = 0x0; break; | 
|---|
| 367 | default: lower_ch = ch; break; | 
|---|
| 368 | } /* switch */ | 
|---|
| 369 | } /* if */ | 
|---|
| 370 | source_buf[i] = ch; | 
|---|
| 371 | result_buf[i] = '\0'; | 
|---|
| 372 | lower_buf[i] = lower_ch; | 
|---|
| 373 | } /* for */ | 
|---|
| 374 | source_buf[i] = '\0'; | 
|---|
| 375 | result_buf[i] = '\0'; | 
|---|
| 376 | lower_buf[i] = '\0'; | 
|---|
| 377 | source_str.Length = 2048; | 
|---|
| 378 | source_str.MaximumLength = 2048; | 
|---|
| 379 | source_str.Buffer = source_buf; | 
|---|
| 380 | result_str.Length = 2048; | 
|---|
| 381 | result_str.MaximumLength = 2048; | 
|---|
| 382 | result_str.Buffer = result_buf; | 
|---|
| 383 | lower_str.Length = 2048; | 
|---|
| 384 | lower_str.MaximumLength = 2048; | 
|---|
| 385 | lower_str.Buffer = lower_buf; | 
|---|
| 386 |  | 
|---|
| 387 | pRtlDowncaseUnicodeString(&result_str, &source_str, 0); | 
|---|
| 388 | for (i = 0; i <= 1024; i++) { | 
|---|
| 389 | ok(result_str.Buffer[i] == lower_str.Buffer[i] || result_str.Buffer[i] == source_str.Buffer[i] + 1, | 
|---|
| 390 | "RtlDowncaseUnicodeString works wrong: '%c'[=0x%x] is converted to '%c'[=0x%x], expected: '%c'[=0x%x]", | 
|---|
| 391 | source_str.Buffer[i], source_str.Buffer[i], | 
|---|
| 392 | result_str.Buffer[i], result_str.Buffer[i], | 
|---|
| 393 | lower_str.Buffer[i], lower_str.Buffer[i]); | 
|---|
| 394 | } /* for */ | 
|---|
| 395 | } | 
|---|
| 396 |  | 
|---|
| 397 |  | 
|---|
| 398 | static void test_RtlAppendUnicodeStringToString(void) | 
|---|
| 399 | { | 
|---|
| 400 | CHAR dest_buf[257]; | 
|---|
| 401 | CHAR src_buf[257]; | 
|---|
| 402 | UNICODE_STRING dest_str; | 
|---|
| 403 | UNICODE_STRING src_str; | 
|---|
| 404 | NTSTATUS result; | 
|---|
| 405 |  | 
|---|
| 406 | strcpy(dest_buf, "ThisisafakeU0123456789abcdefghij"); | 
|---|
| 407 | strcpy(src_buf, "nicodeStringZYXWVUTS"); | 
|---|
| 408 | dest_str.Length = 12; | 
|---|
| 409 | dest_str.MaximumLength = 26; | 
|---|
| 410 | dest_str.Buffer = (WCHAR *) dest_buf; | 
|---|
| 411 | src_str.Length = 12; | 
|---|
| 412 | src_str.MaximumLength = 12; | 
|---|
| 413 | src_str.Buffer = (WCHAR *) src_buf; | 
|---|
| 414 | result = pRtlAppendUnicodeStringToString(&dest_str, &src_str); | 
|---|
| 415 | ok(result == STATUS_SUCCESS, | 
|---|
| 416 | "call failed: RtlAppendUnicodeStringToString(dest, src) has result %lx", | 
|---|
| 417 | result); | 
|---|
| 418 | ok(memcmp(dest_buf, "ThisisafakeUnicodeString\0\0efghij", 32) == 0, | 
|---|
| 419 | "call failed: RtlAppendUnicodeStringToString(dest, src) has dest \"%s\"", | 
|---|
| 420 | dest_buf); | 
|---|
| 421 |  | 
|---|
| 422 | strcpy(dest_buf, "ThisisafakeU0123456789abcdefghij"); | 
|---|
| 423 | dest_str.Length = 12; | 
|---|
| 424 | dest_str.MaximumLength = 25; | 
|---|
| 425 | result = pRtlAppendUnicodeStringToString(&dest_str, &src_str); | 
|---|
| 426 | ok(result == STATUS_SUCCESS, | 
|---|
| 427 | "call failed: RtlAppendUnicodeStringToString(dest, src) has result %lx", | 
|---|
| 428 | result); | 
|---|
| 429 | ok(memcmp(dest_buf, "ThisisafakeUnicodeString\0\0efghij", 32) == 0, | 
|---|
| 430 | "call failed: RtlAppendUnicodeStringToString(dest, src) has dest \"%s\"", | 
|---|
| 431 | dest_buf); | 
|---|
| 432 |  | 
|---|
| 433 | strcpy(dest_buf, "ThisisafakeU0123456789abcdefghij"); | 
|---|
| 434 | dest_str.Length = 12; | 
|---|
| 435 | dest_str.MaximumLength = 24; | 
|---|
| 436 | result = pRtlAppendUnicodeStringToString(&dest_str, &src_str); | 
|---|
| 437 | ok(result == STATUS_SUCCESS, | 
|---|
| 438 | "call failed: RtlAppendUnicodeStringToString(dest, src) has result %lx", | 
|---|
| 439 | result); | 
|---|
| 440 | ok(memcmp(dest_buf, "ThisisafakeUnicodeStringcdefghij", 32) == 0, | 
|---|
| 441 | "call failed: RtlAppendUnicodeStringToString(dest, src) has dest \"%s\"", | 
|---|
| 442 | dest_buf); | 
|---|
| 443 |  | 
|---|
| 444 | strcpy(dest_buf, "ThisisafakeU0123456789abcdefghij"); | 
|---|
| 445 | dest_str.Length = 12; | 
|---|
| 446 | dest_str.MaximumLength = 23; | 
|---|
| 447 | result = pRtlAppendUnicodeStringToString(&dest_str, &src_str); | 
|---|
| 448 | ok(result == STATUS_BUFFER_TOO_SMALL, | 
|---|
| 449 | "call failed: RtlAppendUnicodeStringToString(dest, src) has result %lx", | 
|---|
| 450 | result); | 
|---|
| 451 | ok(memcmp(dest_buf, "ThisisafakeU0123456789abcdefghij", 32) == 0, | 
|---|
| 452 | "call failed: RtlAppendUnicodeStringToString(dest, src) has dest \"%s\"", | 
|---|
| 453 | dest_buf); | 
|---|
| 454 |  | 
|---|
| 455 | strcpy(dest_buf, "ThisisafakeU0123456789abcdefghij"); | 
|---|
| 456 | dest_str.Length = 12; | 
|---|
| 457 | dest_str.MaximumLength = 0; | 
|---|
| 458 | src_str.Length = 0; | 
|---|
| 459 | src_str.MaximumLength = 0; | 
|---|
| 460 | result = pRtlAppendUnicodeStringToString(&dest_str, &src_str); | 
|---|
| 461 | ok(result == STATUS_SUCCESS, | 
|---|
| 462 | "call failed: RtlAppendUnicodeStringToString(dest, src) has result %lx", | 
|---|
| 463 | result); | 
|---|
| 464 | ok(memcmp(dest_buf, "ThisisafakeU0123456789abcdefghij", 32) == 0, | 
|---|
| 465 | "call failed: RtlAppendUnicodeStringToString(dest, src) has dest \"%s\"", | 
|---|
| 466 | dest_buf); | 
|---|
| 467 |  | 
|---|
| 468 | strcpy(dest_buf, "ThisisafakeU0123456789abcdefghij"); | 
|---|
| 469 | dest_str.Length = 12; | 
|---|
| 470 | dest_str.MaximumLength = 22; | 
|---|
| 471 | src_str.Length = 0; | 
|---|
| 472 | src_str.MaximumLength = 0; | 
|---|
| 473 | result = pRtlAppendUnicodeStringToString(&dest_str, &src_str); | 
|---|
| 474 | ok(result == STATUS_SUCCESS, | 
|---|
| 475 | "call failed: RtlAppendUnicodeStringToString(dest, src) has result %lx", | 
|---|
| 476 | result); | 
|---|
| 477 | ok(memcmp(dest_buf, "ThisisafakeU0123456789abcdefghij", 32) == 0, | 
|---|
| 478 | "call failed: RtlAppendUnicodeStringToString(dest, src) has dest \"%s\"", | 
|---|
| 479 | dest_buf); | 
|---|
| 480 |  | 
|---|
| 481 | strcpy(dest_buf, "ThisisafakeU0123456789abcdefghij"); | 
|---|
| 482 | dest_str.Length = 12; | 
|---|
| 483 | dest_str.MaximumLength = 22; | 
|---|
| 484 | src_str.Length = 0; | 
|---|
| 485 | src_str.MaximumLength = 0; | 
|---|
| 486 | src_str.Buffer = NULL; | 
|---|
| 487 | result = pRtlAppendUnicodeStringToString(&dest_str, &src_str); | 
|---|
| 488 | ok(result == STATUS_SUCCESS, | 
|---|
| 489 | "call failed: RtlAppendUnicodeStringToString(dest, src) has result %lx", | 
|---|
| 490 | result); | 
|---|
| 491 | ok(memcmp(dest_buf, "ThisisafakeU0123456789abcdefghij", 32) == 0, | 
|---|
| 492 | "call failed: RtlAppendUnicodeStringToString(dest, src) has dest \"%s\"", | 
|---|
| 493 | dest_buf); | 
|---|
| 494 | } | 
|---|
| 495 |  | 
|---|
| 496 |  | 
|---|
| 497 | typedef struct { | 
|---|
| 498 | int base; | 
|---|
| 499 | char *str; | 
|---|
| 500 | int value; | 
|---|
| 501 | NTSTATUS result; | 
|---|
| 502 | } str2int_t; | 
|---|
| 503 |  | 
|---|
| 504 | static const str2int_t str2int[] = { | 
|---|
| 505 | { 0, "1011101100",   1011101100, STATUS_SUCCESS}, | 
|---|
| 506 | { 0, "1234567",         1234567, STATUS_SUCCESS}, | 
|---|
| 507 | { 0, "-214",               -214, STATUS_SUCCESS}, | 
|---|
| 508 | { 0, "+214",                214, STATUS_SUCCESS}, /* The + sign is allowed also */ | 
|---|
| 509 | { 0, "--214",                 0, STATUS_SUCCESS}, /* Do not accept more than one sign */ | 
|---|
| 510 | { 0, "-+214",                 0, STATUS_SUCCESS}, | 
|---|
| 511 | { 0, "++214",                 0, STATUS_SUCCESS}, | 
|---|
| 512 | { 0, "+-214",                 0, STATUS_SUCCESS}, | 
|---|
| 513 | { 0, "\001\002\003\00411",   11, STATUS_SUCCESS}, /* whitespace char  1 to  4 */ | 
|---|
| 514 | { 0, "\005\006\007\01012",   12, STATUS_SUCCESS}, /* whitespace char  5 to  8 */ | 
|---|
| 515 | { 0, "\011\012\013\01413",   13, STATUS_SUCCESS}, /* whitespace char  9 to 12 */ | 
|---|
| 516 | { 0, "\015\016\017\02014",   14, STATUS_SUCCESS}, /* whitespace char 13 to 16 */ | 
|---|
| 517 | { 0, "\021\022\023\02415",   15, STATUS_SUCCESS}, /* whitespace char 17 to 20 */ | 
|---|
| 518 | { 0, "\025\026\027\03016",   16, STATUS_SUCCESS}, /* whitespace char 21 to 24 */ | 
|---|
| 519 | { 0, "\031\032\033\03417",   17, STATUS_SUCCESS}, /* whitespace char 25 to 28 */ | 
|---|
| 520 | { 0, "\035\036\037\04018",   18, STATUS_SUCCESS}, /* whitespace char 29 to 32 */ | 
|---|
| 521 | { 0, " \n \r \t214",        214, STATUS_SUCCESS}, | 
|---|
| 522 | { 0, " \n \r \t+214",       214, STATUS_SUCCESS}, /* Signs can be used after whitespace */ | 
|---|
| 523 | { 0, " \n \r \t-214",      -214, STATUS_SUCCESS}, | 
|---|
| 524 | { 0, "+214 0",              214, STATUS_SUCCESS}, /* Space terminates the number */ | 
|---|
| 525 | { 0, " 214.01",             214, STATUS_SUCCESS}, /* Decimal point not accepted */ | 
|---|
| 526 | { 0, " 214,01",             214, STATUS_SUCCESS}, /* Decimal comma not accepted */ | 
|---|
| 527 | { 0, "f81",                   0, STATUS_SUCCESS}, | 
|---|
| 528 | { 0, "0x12345",         0x12345, STATUS_SUCCESS}, /* Hex */ | 
|---|
| 529 | { 0, "00x12345",              0, STATUS_SUCCESS}, | 
|---|
| 530 | { 0, "0xx12345",              0, STATUS_SUCCESS}, | 
|---|
| 531 | { 0, "1x34",                  1, STATUS_SUCCESS}, | 
|---|
| 532 | { 0, "-9999999999", -1410065407, STATUS_SUCCESS}, /* Big negative integer */ | 
|---|
| 533 | { 0, "-2147483649",  2147483647, STATUS_SUCCESS}, /* Too small to fit in 32 Bits */ | 
|---|
| 534 | { 0, "-2147483648", 0x80000000L, STATUS_SUCCESS}, /* Smallest negative integer */ | 
|---|
| 535 | { 0, "-2147483647", -2147483647, STATUS_SUCCESS}, | 
|---|
| 536 | { 0, "-1",                   -1, STATUS_SUCCESS}, | 
|---|
| 537 | { 0, "0",                     0, STATUS_SUCCESS}, | 
|---|
| 538 | { 0, "1",                     1, STATUS_SUCCESS}, | 
|---|
| 539 | { 0, "2147483646",   2147483646, STATUS_SUCCESS}, | 
|---|
| 540 | { 0, "2147483647",   2147483647, STATUS_SUCCESS}, /* Largest signed positive integer */ | 
|---|
| 541 | { 0, "2147483648",  0x80000000L, STATUS_SUCCESS}, /* Positive int equal to smallest negative int */ | 
|---|
| 542 | { 0, "2147483649",  -2147483647, STATUS_SUCCESS}, | 
|---|
| 543 | { 0, "4294967294",           -2, STATUS_SUCCESS}, | 
|---|
| 544 | { 0, "4294967295",           -1, STATUS_SUCCESS}, /* Largest unsigned integer */ | 
|---|
| 545 | { 0, "4294967296",            0, STATUS_SUCCESS}, /* Too big to fit in 32 Bits */ | 
|---|
| 546 | { 0, "9999999999",   1410065407, STATUS_SUCCESS}, /* Big positive integer */ | 
|---|
| 547 | { 0, "056789",            56789, STATUS_SUCCESS}, /* Leading zero and still decimal */ | 
|---|
| 548 | { 0, "b1011101100",           0, STATUS_SUCCESS}, /* Binary (b-notation) */ | 
|---|
| 549 | { 0, "-b1011101100",          0, STATUS_SUCCESS}, /* Negative Binary (b-notation) */ | 
|---|
| 550 | { 0, "b10123456789",          0, STATUS_SUCCESS}, /* Binary with nonbinary digits (2-9) */ | 
|---|
| 551 | { 0, "0b1011101100",        748, STATUS_SUCCESS}, /* Binary (0b-notation) */ | 
|---|
| 552 | { 0, "-0b1011101100",      -748, STATUS_SUCCESS}, /* Negative binary (0b-notation) */ | 
|---|
| 553 | { 0, "0b10123456789",         5, STATUS_SUCCESS}, /* Binary with nonbinary digits (2-9) */ | 
|---|
| 554 | { 0, "-0b10123456789",       -5, STATUS_SUCCESS}, /* Negative binary with nonbinary digits (2-9) */ | 
|---|
| 555 | { 0, "0b1",                   1, STATUS_SUCCESS}, /* one digit binary */ | 
|---|
| 556 | { 0, "0b2",                   0, STATUS_SUCCESS}, /* empty binary */ | 
|---|
| 557 | { 0, "0b",                    0, STATUS_SUCCESS}, /* empty binary */ | 
|---|
| 558 | { 0, "o1234567",              0, STATUS_SUCCESS}, /* Octal (o-notation) */ | 
|---|
| 559 | { 0, "-o1234567",             0, STATUS_SUCCESS}, /* Negative Octal (o-notation) */ | 
|---|
| 560 | { 0, "o56789",                0, STATUS_SUCCESS}, /* Octal with nonoctal digits (8 and 9) */ | 
|---|
| 561 | { 0, "0o1234567",      01234567, STATUS_SUCCESS}, /* Octal (0o-notation) */ | 
|---|
| 562 | { 0, "-0o1234567",    -01234567, STATUS_SUCCESS}, /* Negative octal (0o-notation) */ | 
|---|
| 563 | { 0, "0o56789",            0567, STATUS_SUCCESS}, /* Octal with nonoctal digits (8 and 9) */ | 
|---|
| 564 | { 0, "-0o56789",          -0567, STATUS_SUCCESS}, /* Negative octal with nonoctal digits (8 and 9) */ | 
|---|
| 565 | { 0, "0o7",                   7, STATUS_SUCCESS}, /* one digit octal */ | 
|---|
| 566 | { 0, "0o8",                   0, STATUS_SUCCESS}, /* empty octal */ | 
|---|
| 567 | { 0, "0o",                    0, STATUS_SUCCESS}, /* empty octal */ | 
|---|
| 568 | { 0, "0d1011101100",          0, STATUS_SUCCESS}, /* explizit decimal with 0d */ | 
|---|
| 569 | { 0, "x89abcdef",             0, STATUS_SUCCESS}, /* Hex with lower case digits a-f (x-notation) */ | 
|---|
| 570 | { 0, "xFEDCBA00",             0, STATUS_SUCCESS}, /* Hex with upper case digits A-F (x-notation) */ | 
|---|
| 571 | { 0, "-xFEDCBA00",            0, STATUS_SUCCESS}, /* Negative Hexadecimal (x-notation) */ | 
|---|
| 572 | { 0, "0x89abcdef",   0x89abcdef, STATUS_SUCCESS}, /* Hex with lower case digits a-f (0x-notation) */ | 
|---|
| 573 | { 0, "0xFEDCBA00",   0xFEDCBA00, STATUS_SUCCESS}, /* Hex with upper case digits A-F (0x-notation) */ | 
|---|
| 574 | { 0, "-0xFEDCBA00", -0xFEDCBA00, STATUS_SUCCESS}, /* Negative Hexadecimal (0x-notation) */ | 
|---|
| 575 | { 0, "0xabcdefgh",     0xabcdef, STATUS_SUCCESS}, /* Hex with illegal lower case digits (g-z) */ | 
|---|
| 576 | { 0, "0xABCDEFGH",     0xABCDEF, STATUS_SUCCESS}, /* Hex with illegal upper case digits (G-Z) */ | 
|---|
| 577 | { 0, "0xF",                 0xf, STATUS_SUCCESS}, /* one digit hexadecimal */ | 
|---|
| 578 | { 0, "0xG",                   0, STATUS_SUCCESS}, /* empty hexadecimal */ | 
|---|
| 579 | { 0, "0x",                    0, STATUS_SUCCESS}, /* empty hexadecimal */ | 
|---|
| 580 | { 0, "",                      0, STATUS_SUCCESS}, /* empty string */ | 
|---|
| 581 | { 2, "1011101100",          748, STATUS_SUCCESS}, | 
|---|
| 582 | { 2, "-1011101100",        -748, STATUS_SUCCESS}, | 
|---|
| 583 | { 2, "2",                     0, STATUS_SUCCESS}, | 
|---|
| 584 | { 2, "0b1011101100",          0, STATUS_SUCCESS}, | 
|---|
| 585 | { 2, "0o1011101100",          0, STATUS_SUCCESS}, | 
|---|
| 586 | { 2, "0d1011101100",          0, STATUS_SUCCESS}, | 
|---|
| 587 | { 2, "0x1011101100",          0, STATUS_SUCCESS}, | 
|---|
| 588 | { 2, "",                      0, STATUS_SUCCESS}, /* empty string */ | 
|---|
| 589 | { 8, "1011101100",    136610368, STATUS_SUCCESS}, | 
|---|
| 590 | { 8, "-1011101100",  -136610368, STATUS_SUCCESS}, | 
|---|
| 591 | { 8, "8",                     0, STATUS_SUCCESS}, | 
|---|
| 592 | { 8, "0b1011101100",          0, STATUS_SUCCESS}, | 
|---|
| 593 | { 8, "0o1011101100",          0, STATUS_SUCCESS}, | 
|---|
| 594 | { 8, "0d1011101100",          0, STATUS_SUCCESS}, | 
|---|
| 595 | { 8, "0x1011101100",          0, STATUS_SUCCESS}, | 
|---|
| 596 | { 8, "",                      0, STATUS_SUCCESS}, /* empty string */ | 
|---|
| 597 | {10, "1011101100",   1011101100, STATUS_SUCCESS}, | 
|---|
| 598 | {10, "-1011101100", -1011101100, STATUS_SUCCESS}, | 
|---|
| 599 | {10, "0b1011101100",          0, STATUS_SUCCESS}, | 
|---|
| 600 | {10, "0o1011101100",          0, STATUS_SUCCESS}, | 
|---|
| 601 | {10, "0d1011101100",          0, STATUS_SUCCESS}, | 
|---|
| 602 | {10, "0x1011101100",          0, STATUS_SUCCESS}, | 
|---|
| 603 | {10, "o12345",                0, STATUS_SUCCESS}, /* Octal altrough base is 10 */ | 
|---|
| 604 | {10, "",                      0, STATUS_SUCCESS}, /* empty string */ | 
|---|
| 605 | {16, "1011101100",    286265600, STATUS_SUCCESS}, | 
|---|
| 606 | {16, "-1011101100",  -286265600, STATUS_SUCCESS}, | 
|---|
| 607 | {16, "G",                     0, STATUS_SUCCESS}, | 
|---|
| 608 | {16, "g",                     0, STATUS_SUCCESS}, | 
|---|
| 609 | {16, "0b1011101100",  286265600, STATUS_SUCCESS}, | 
|---|
| 610 | {16, "0o1011101100",          0, STATUS_SUCCESS}, | 
|---|
| 611 | {16, "0d1011101100",  286265600, STATUS_SUCCESS}, | 
|---|
| 612 | {16, "0x1011101100",          0, STATUS_SUCCESS}, | 
|---|
| 613 | {16, "",                      0, STATUS_SUCCESS}, /* empty string */ | 
|---|
| 614 | {20, "0",            0xdeadbeef, STATUS_INVALID_PARAMETER}, /* illegal base */ | 
|---|
| 615 | {-8, "0",            0xdeadbeef, STATUS_INVALID_PARAMETER}, /* Negative base */ | 
|---|
| 616 | /*    { 0, NULL,                    0, STATUS_SUCCESS}, */ /* NULL as string */ | 
|---|
| 617 | }; | 
|---|
| 618 | #define NB_STR2INT (sizeof(str2int)/sizeof(*str2int)) | 
|---|
| 619 |  | 
|---|
| 620 |  | 
|---|
| 621 | static void test_RtlUnicodeStringToInteger(void) | 
|---|
| 622 | { | 
|---|
| 623 | int test_num; | 
|---|
| 624 | int value; | 
|---|
| 625 | NTSTATUS result; | 
|---|
| 626 | WCHAR *wstr; | 
|---|
| 627 |  | 
|---|
| 628 | for (test_num = 0; test_num < NB_STR2INT; test_num++) { | 
|---|
| 629 | wstr = AtoW(str2int[test_num].str); | 
|---|
| 630 | value = 0xdeadbeef; | 
|---|
| 631 | pRtlInitUnicodeString(&uni, wstr); | 
|---|
| 632 | result = pRtlUnicodeStringToInteger(&uni, str2int[test_num].base, &value); | 
|---|
| 633 | ok(result == str2int[test_num].result, | 
|---|
| 634 | "(test %d): RtlUnicodeStringToInteger(\"%s\", %d, [out]) has result %lx, expected: %lx", | 
|---|
| 635 | test_num, str2int[test_num].str, str2int[test_num].base, result, str2int[test_num].result); | 
|---|
| 636 | ok(value == str2int[test_num].value, | 
|---|
| 637 | "(test %d): RtlUnicodeStringToInteger(\"%s\", %d, [out]) assigns value %d, expected: %d", | 
|---|
| 638 | test_num, str2int[test_num].str, str2int[test_num].base, value, str2int[test_num].value); | 
|---|
| 639 | free(wstr); | 
|---|
| 640 | } /* for */ | 
|---|
| 641 |  | 
|---|
| 642 | wstr = AtoW(str2int[1].str); | 
|---|
| 643 | pRtlInitUnicodeString(&uni, wstr); | 
|---|
| 644 | result = pRtlUnicodeStringToInteger(&uni, str2int[1].base, NULL); | 
|---|
| 645 | ok(result == STATUS_ACCESS_VIOLATION, | 
|---|
| 646 | "call failed: RtlUnicodeStringToInteger(\"%s\", %d, NULL) has result %lx", | 
|---|
| 647 | str2int[1].str, str2int[1].base, result); | 
|---|
| 648 | result = pRtlUnicodeStringToInteger(&uni, 20, NULL); | 
|---|
| 649 | ok(result == STATUS_INVALID_PARAMETER, | 
|---|
| 650 | "call failed: RtlUnicodeStringToInteger(\"%s\", 20, NULL) has result %lx", | 
|---|
| 651 | str2int[1].str, result); | 
|---|
| 652 |  | 
|---|
| 653 | uni.Length = 10; /* Make Length shorter (5 WCHARS instead of 7) */ | 
|---|
| 654 | result = pRtlUnicodeStringToInteger(&uni, str2int[1].base, &value); | 
|---|
| 655 | ok(result == STATUS_SUCCESS, | 
|---|
| 656 | "call failed: RtlUnicodeStringToInteger(\"12345\", %d, [out]) has result %lx", | 
|---|
| 657 | str2int[1].base, result); | 
|---|
| 658 | ok(value == 12345, | 
|---|
| 659 | "didn't return expected value (test a): expected: %d, got: %d", | 
|---|
| 660 | 12345, value); | 
|---|
| 661 |  | 
|---|
| 662 | uni.Length = 5; /* Use odd Length (2.5 WCHARS) */ | 
|---|
| 663 | result = pRtlUnicodeStringToInteger(&uni, str2int[1].base, &value); | 
|---|
| 664 | ok(result == STATUS_SUCCESS, | 
|---|
| 665 | "call failed: RtlUnicodeStringToInteger(\"12\", %d, [out]) has result %lx", | 
|---|
| 666 | str2int[1].base, result); | 
|---|
| 667 | ok(value == 12, | 
|---|
| 668 | "didn't return expected value (test b): expected: %d, got: %d", | 
|---|
| 669 | 12, value); | 
|---|
| 670 |  | 
|---|
| 671 | uni.Length = 2; | 
|---|
| 672 | result = pRtlUnicodeStringToInteger(&uni, str2int[1].base, &value); | 
|---|
| 673 | ok(result == STATUS_SUCCESS, | 
|---|
| 674 | "call failed: RtlUnicodeStringToInteger(\"1\", %d, [out]) has result %lx", | 
|---|
| 675 | str2int[1].base, result); | 
|---|
| 676 | ok(value == 1, | 
|---|
| 677 | "didn't return expected value (test c): expected: %d, got: %d", | 
|---|
| 678 | 1, value); | 
|---|
| 679 | /* w2k: uni.Length = 0 returns value 11234567 instead of 0 */ | 
|---|
| 680 | free(wstr); | 
|---|
| 681 | } | 
|---|
| 682 |  | 
|---|
| 683 |  | 
|---|
| 684 | static void test_RtlCharToInteger(void) | 
|---|
| 685 | { | 
|---|
| 686 | int test_num; | 
|---|
| 687 | int value; | 
|---|
| 688 | NTSTATUS result; | 
|---|
| 689 |  | 
|---|
| 690 | for (test_num = 0; test_num < NB_STR2INT; test_num++) { | 
|---|
| 691 | /* w2k skips a leading '\0' and processes the string after */ | 
|---|
| 692 | if (str2int[test_num].str[0] != '\0') { | 
|---|
| 693 | value = 0xdeadbeef; | 
|---|
| 694 | result = pRtlCharToInteger(str2int[test_num].str, str2int[test_num].base, &value); | 
|---|
| 695 | ok(result == str2int[test_num].result, | 
|---|
| 696 | "(test %d): call failed: RtlCharToInteger(\"%s\", %d, [out]) has result %lx, expected: %lx", | 
|---|
| 697 | test_num, str2int[test_num].str, str2int[test_num].base, result, str2int[test_num].result); | 
|---|
| 698 | ok(value == str2int[test_num].value, | 
|---|
| 699 | "(test %d): call failed: RtlCharToInteger(\"%s\", %d, [out]) assigns value %d, expected: %d", | 
|---|
| 700 | test_num, str2int[test_num].str, str2int[test_num].base, value, str2int[test_num].value); | 
|---|
| 701 | } /* if */ | 
|---|
| 702 | } /* for */ | 
|---|
| 703 |  | 
|---|
| 704 | result = pRtlCharToInteger(str2int[1].str, str2int[1].base, NULL); | 
|---|
| 705 | ok(result == STATUS_ACCESS_VIOLATION, | 
|---|
| 706 | "call failed: RtlCharToInteger(\"%s\", %d, NULL) has result %lx", | 
|---|
| 707 | str2int[1].str, str2int[1].base, result); | 
|---|
| 708 |  | 
|---|
| 709 | result = pRtlCharToInteger(str2int[1].str, 20, NULL); | 
|---|
| 710 | ok(result == STATUS_INVALID_PARAMETER, | 
|---|
| 711 | "call failed: RtlCharToInteger(\"%s\", 20, NULL) has result %lx", | 
|---|
| 712 | str2int[1].str, result); | 
|---|
| 713 | } | 
|---|
| 714 |  | 
|---|
| 715 |  | 
|---|
| 716 | #define STRI_BUFFER_LENGTH 35 | 
|---|
| 717 |  | 
|---|
| 718 | typedef struct { | 
|---|
| 719 | int base; | 
|---|
| 720 | ULONG value; | 
|---|
| 721 | USHORT Length; | 
|---|
| 722 | USHORT MaximumLength; | 
|---|
| 723 | char *Buffer; | 
|---|
| 724 | NTSTATUS result; | 
|---|
| 725 | } int2str_t; | 
|---|
| 726 |  | 
|---|
| 727 | static const int2str_t int2str[] = { | 
|---|
| 728 | {10,          123,  3, 11, "123\0-------------------------------", STATUS_SUCCESS}, | 
|---|
| 729 |  | 
|---|
| 730 | { 0,  0x80000000U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS}, /* min signed int */ | 
|---|
| 731 | { 0,  -2147483647, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS}, | 
|---|
| 732 | { 0,           -2, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS}, | 
|---|
| 733 | { 0,           -1, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS}, | 
|---|
| 734 | { 0,            0,  1, 11, "0\0---------------------------------", STATUS_SUCCESS}, | 
|---|
| 735 | { 0,            1,  1, 11, "1\0---------------------------------", STATUS_SUCCESS}, | 
|---|
| 736 | { 0,           12,  2, 11, "12\0--------------------------------", STATUS_SUCCESS}, | 
|---|
| 737 | { 0,          123,  3, 11, "123\0-------------------------------", STATUS_SUCCESS}, | 
|---|
| 738 | { 0,         1234,  4, 11, "1234\0------------------------------", STATUS_SUCCESS}, | 
|---|
| 739 | { 0,        12345,  5, 11, "12345\0-----------------------------", STATUS_SUCCESS}, | 
|---|
| 740 | { 0,       123456,  6, 11, "123456\0----------------------------", STATUS_SUCCESS}, | 
|---|
| 741 | { 0,      1234567,  7, 11, "1234567\0---------------------------", STATUS_SUCCESS}, | 
|---|
| 742 | { 0,     12345678,  8, 11, "12345678\0--------------------------", STATUS_SUCCESS}, | 
|---|
| 743 | { 0,    123456789,  9, 11, "123456789\0-------------------------", STATUS_SUCCESS}, | 
|---|
| 744 | { 0,   2147483646, 10, 11, "2147483646\0------------------------", STATUS_SUCCESS}, | 
|---|
| 745 | { 0,   2147483647, 10, 11, "2147483647\0------------------------", STATUS_SUCCESS}, /* max signed int */ | 
|---|
| 746 | { 0,  2147483648U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS}, /* uint = -max int */ | 
|---|
| 747 | { 0,  2147483649U, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS}, | 
|---|
| 748 | { 0,  4294967294U, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS}, | 
|---|
| 749 | { 0,  4294967295U, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS}, /* max unsigned int */ | 
|---|
| 750 |  | 
|---|
| 751 | { 2,  0x80000000U, 32, 33, "10000000000000000000000000000000\0--", STATUS_SUCCESS}, /* min signed int */ | 
|---|
| 752 | { 2,  -2147483647, 32, 33, "10000000000000000000000000000001\0--", STATUS_SUCCESS}, | 
|---|
| 753 | { 2,           -2, 32, 33, "11111111111111111111111111111110\0--", STATUS_SUCCESS}, | 
|---|
| 754 | { 2,           -1, 32, 33, "11111111111111111111111111111111\0--", STATUS_SUCCESS}, | 
|---|
| 755 | { 2,            0,  1, 33, "0\0---------------------------------", STATUS_SUCCESS}, | 
|---|
| 756 | { 2,            1,  1, 33, "1\0---------------------------------", STATUS_SUCCESS}, | 
|---|
| 757 | { 2,           10,  4, 33, "1010\0------------------------------", STATUS_SUCCESS}, | 
|---|
| 758 | { 2,          100,  7, 33, "1100100\0---------------------------", STATUS_SUCCESS}, | 
|---|
| 759 | { 2,         1000, 10, 33, "1111101000\0------------------------", STATUS_SUCCESS}, | 
|---|
| 760 | { 2,        10000, 14, 33, "10011100010000\0--------------------", STATUS_SUCCESS}, | 
|---|
| 761 | { 2,        32767, 15, 33, "111111111111111\0-------------------", STATUS_SUCCESS}, | 
|---|
| 762 | { 2,        32768, 16, 33, "1000000000000000\0------------------", STATUS_SUCCESS}, | 
|---|
| 763 | { 2,        65535, 16, 33, "1111111111111111\0------------------", STATUS_SUCCESS}, | 
|---|
| 764 | { 2,        65536, 17, 33, "10000000000000000\0-----------------", STATUS_SUCCESS}, | 
|---|
| 765 | { 2,       100000, 17, 33, "11000011010100000\0-----------------", STATUS_SUCCESS}, | 
|---|
| 766 | { 2,      1000000, 20, 33, "11110100001001000000\0--------------", STATUS_SUCCESS}, | 
|---|
| 767 | { 2,     10000000, 24, 33, "100110001001011010000000\0----------", STATUS_SUCCESS}, | 
|---|
| 768 | { 2,    100000000, 27, 33, "101111101011110000100000000\0-------", STATUS_SUCCESS}, | 
|---|
| 769 | { 2,   1000000000, 30, 33, "111011100110101100101000000000\0----", STATUS_SUCCESS}, | 
|---|
| 770 | { 2,   1073741823, 30, 33, "111111111111111111111111111111\0----", STATUS_SUCCESS}, | 
|---|
| 771 | { 2,   2147483646, 31, 33, "1111111111111111111111111111110\0---", STATUS_SUCCESS}, | 
|---|
| 772 | { 2,   2147483647, 31, 33, "1111111111111111111111111111111\0---", STATUS_SUCCESS}, /* max signed int */ | 
|---|
| 773 | { 2,  2147483648U, 32, 33, "10000000000000000000000000000000\0--", STATUS_SUCCESS}, /* uint = -max int */ | 
|---|
| 774 | { 2,  2147483649U, 32, 33, "10000000000000000000000000000001\0--", STATUS_SUCCESS}, | 
|---|
| 775 | { 2,  4294967294U, 32, 33, "11111111111111111111111111111110\0--", STATUS_SUCCESS}, | 
|---|
| 776 | { 2,  4294967295U, 32, 33, "11111111111111111111111111111111\0--", STATUS_SUCCESS}, /* max unsigned int */ | 
|---|
| 777 |  | 
|---|
| 778 | { 8,  0x80000000U, 11, 12, "20000000000\0-----------------------", STATUS_SUCCESS}, /* min signed int */ | 
|---|
| 779 | { 8,  -2147483647, 11, 12, "20000000001\0-----------------------", STATUS_SUCCESS}, | 
|---|
| 780 | { 8,           -2, 11, 12, "37777777776\0-----------------------", STATUS_SUCCESS}, | 
|---|
| 781 | { 8,           -1, 11, 12, "37777777777\0-----------------------", STATUS_SUCCESS}, | 
|---|
| 782 | { 8,            0,  1, 12, "0\0---------------------------------", STATUS_SUCCESS}, | 
|---|
| 783 | { 8,            1,  1, 12, "1\0---------------------------------", STATUS_SUCCESS}, | 
|---|
| 784 | { 8,   2147483646, 11, 12, "17777777776\0-----------------------", STATUS_SUCCESS}, | 
|---|
| 785 | { 8,   2147483647, 11, 12, "17777777777\0-----------------------", STATUS_SUCCESS}, /* max signed int */ | 
|---|
| 786 | { 8,  2147483648U, 11, 12, "20000000000\0-----------------------", STATUS_SUCCESS}, /* uint = -max int */ | 
|---|
| 787 | { 8,  2147483649U, 11, 12, "20000000001\0-----------------------", STATUS_SUCCESS}, | 
|---|
| 788 | { 8,  4294967294U, 11, 12, "37777777776\0-----------------------", STATUS_SUCCESS}, | 
|---|
| 789 | { 8,  4294967295U, 11, 12, "37777777777\0-----------------------", STATUS_SUCCESS}, /* max unsigned int */ | 
|---|
| 790 |  | 
|---|
| 791 | {10,  0x80000000U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS}, /* min signed int */ | 
|---|
| 792 | {10,  -2147483647, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS}, | 
|---|
| 793 | {10,           -2, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS}, | 
|---|
| 794 | {10,           -1, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS}, | 
|---|
| 795 | {10,            0,  1, 11, "0\0---------------------------------", STATUS_SUCCESS}, | 
|---|
| 796 | {10,            1,  1, 11, "1\0---------------------------------", STATUS_SUCCESS}, | 
|---|
| 797 | {10,   2147483646, 10, 11, "2147483646\0------------------------", STATUS_SUCCESS}, | 
|---|
| 798 | {10,   2147483647, 10, 11, "2147483647\0------------------------", STATUS_SUCCESS}, /* max signed int */ | 
|---|
| 799 | {10,  2147483648U, 10, 11, "2147483648\0------------------------", STATUS_SUCCESS}, /* uint = -max int */ | 
|---|
| 800 | {10,  2147483649U, 10, 11, "2147483649\0------------------------", STATUS_SUCCESS}, | 
|---|
| 801 | {10,  4294967294U, 10, 11, "4294967294\0------------------------", STATUS_SUCCESS}, | 
|---|
| 802 | {10,  4294967295U, 10, 11, "4294967295\0------------------------", STATUS_SUCCESS}, /* max unsigned int */ | 
|---|
| 803 |  | 
|---|
| 804 | {16,  0x80000000U,  8,  9, "80000000\0--------------------------", STATUS_SUCCESS}, /* min signed int */ | 
|---|
| 805 | {16,  -2147483647,  8,  9, "80000001\0--------------------------", STATUS_SUCCESS}, | 
|---|
| 806 | {16,           -2,  8,  9, "FFFFFFFE\0--------------------------", STATUS_SUCCESS}, | 
|---|
| 807 | {16,           -1,  8,  9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS}, | 
|---|
| 808 | {16,            0,  1,  9, "0\0---------------------------------", STATUS_SUCCESS}, | 
|---|
| 809 | {16,            1,  1,  9, "1\0---------------------------------", STATUS_SUCCESS}, | 
|---|
| 810 | {16,   2147483646,  8,  9, "7FFFFFFE\0--------------------------", STATUS_SUCCESS}, | 
|---|
| 811 | {16,   2147483647,  8,  9, "7FFFFFFF\0--------------------------", STATUS_SUCCESS}, /* max signed int */ | 
|---|
| 812 | {16,  2147483648U,  8,  9, "80000000\0--------------------------", STATUS_SUCCESS}, /* uint = -max int */ | 
|---|
| 813 | {16,  2147483649U,  8,  9, "80000001\0--------------------------", STATUS_SUCCESS}, | 
|---|
| 814 | {16,  4294967294U,  8,  9, "FFFFFFFE\0--------------------------", STATUS_SUCCESS}, | 
|---|
| 815 | {16,  4294967295U,  8,  9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS}, /* max unsigned int */ | 
|---|
| 816 |  | 
|---|
| 817 | { 2,        32768, 16, 17, "1000000000000000\0------------------", STATUS_SUCCESS}, | 
|---|
| 818 | { 2,        32768, 16, 16, "1000000000000000-------------------",  STATUS_SUCCESS}, | 
|---|
| 819 | { 2,        65536, 17, 18, "10000000000000000\0-----------------", STATUS_SUCCESS}, | 
|---|
| 820 | { 2,        65536, 17, 17, "10000000000000000------------------",  STATUS_SUCCESS}, | 
|---|
| 821 | { 2,       131072, 18, 19, "100000000000000000\0----------------", STATUS_SUCCESS}, | 
|---|
| 822 | { 2,       131072, 18, 18, "100000000000000000-----------------",  STATUS_SUCCESS}, | 
|---|
| 823 | {16,   0xffffffff,  8,  9, "FFFFFFFF\0--------------------------", STATUS_SUCCESS}, | 
|---|
| 824 | {16,   0xffffffff,  8,  8, "FFFFFFFF---------------------------",  STATUS_SUCCESS}, /* No \0 term */ | 
|---|
| 825 | {16,   0xffffffff,  8,  7, "-----------------------------------",  STATUS_BUFFER_OVERFLOW}, /* Too short */ | 
|---|
| 826 | {16,          0xa,  1,  2, "A\0---------------------------------", STATUS_SUCCESS}, | 
|---|
| 827 | {16,          0xa,  1,  1, "A----------------------------------",  STATUS_SUCCESS}, /* No \0 term */ | 
|---|
| 828 | {16,            0,  1,  0, "-----------------------------------",  STATUS_BUFFER_OVERFLOW}, | 
|---|
| 829 | {20,   0xdeadbeef,  0,  9, "-----------------------------------",  STATUS_INVALID_PARAMETER}, /* ill. base */ | 
|---|
| 830 | {-8,     07654321,  0, 12, "-----------------------------------",  STATUS_INVALID_PARAMETER}, /* neg. base */ | 
|---|
| 831 | }; | 
|---|
| 832 | #define NB_INT2STR (sizeof(int2str)/sizeof(*int2str)) | 
|---|
| 833 |  | 
|---|
| 834 |  | 
|---|
| 835 | static void one_RtlIntegerToUnicodeString_test(int test_num, const int2str_t *int2str) | 
|---|
| 836 | { | 
|---|
| 837 | int pos; | 
|---|
| 838 | WCHAR expected_str_Buffer[STRI_BUFFER_LENGTH + 1]; | 
|---|
| 839 | UNICODE_STRING expected_unicode_string; | 
|---|
| 840 | STRING expected_ansi_str; | 
|---|
| 841 | WCHAR str_Buffer[STRI_BUFFER_LENGTH + 1]; | 
|---|
| 842 | UNICODE_STRING unicode_string; | 
|---|
| 843 | STRING ansi_str; | 
|---|
| 844 | NTSTATUS result; | 
|---|
| 845 |  | 
|---|
| 846 | for (pos = 0; pos < STRI_BUFFER_LENGTH; pos++) { | 
|---|
| 847 | expected_str_Buffer[pos] = int2str->Buffer[pos]; | 
|---|
| 848 | } /* for */ | 
|---|
| 849 | expected_unicode_string.Length = int2str->Length * sizeof(WCHAR); | 
|---|
| 850 | expected_unicode_string.MaximumLength = int2str->MaximumLength * sizeof(WCHAR); | 
|---|
| 851 | expected_unicode_string.Buffer = expected_str_Buffer; | 
|---|
| 852 | pRtlUnicodeStringToAnsiString(&expected_ansi_str, &expected_unicode_string, 1); | 
|---|
| 853 |  | 
|---|
| 854 | for (pos = 0; pos < STRI_BUFFER_LENGTH; pos++) { | 
|---|
| 855 | str_Buffer[pos] = '-'; | 
|---|
| 856 | } /* for */ | 
|---|
| 857 | unicode_string.Length = 0; | 
|---|
| 858 | unicode_string.MaximumLength = int2str->MaximumLength * sizeof(WCHAR); | 
|---|
| 859 | unicode_string.Buffer = str_Buffer; | 
|---|
| 860 |  | 
|---|
| 861 | result = pRtlIntegerToUnicodeString(int2str->value, int2str->base, &unicode_string); | 
|---|
| 862 | pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1); | 
|---|
| 863 | if (result == STATUS_BUFFER_OVERFLOW) { | 
|---|
| 864 | /* On BUFFER_OVERFLOW the string Buffer should be unchanged */ | 
|---|
| 865 | for (pos = 0; pos < STRI_BUFFER_LENGTH; pos++) { | 
|---|
| 866 | expected_str_Buffer[pos] = '-'; | 
|---|
| 867 | } /* for */ | 
|---|
| 868 | /* w2k: The native function has two reasons for BUFFER_OVERFLOW: */ | 
|---|
| 869 | /* If the value is too large to convert: The Length is unchanged */ | 
|---|
| 870 | /* If str is too small to hold the string: Set str->Length to the length */ | 
|---|
| 871 | /* the string would have (which can be larger than the MaximumLength). */ | 
|---|
| 872 | /* To allow all this in the tests we do the following: */ | 
|---|
| 873 | if (expected_unicode_string.Length > 32 && unicode_string.Length == 0) { | 
|---|
| 874 | /* The value is too large to convert only triggerd when testing native */ | 
|---|
| 875 | expected_unicode_string.Length = 0; | 
|---|
| 876 | } /* if */ | 
|---|
| 877 | } else { | 
|---|
| 878 | ok(result == int2str->result, | 
|---|
| 879 | "(test %d): RtlIntegerToUnicodeString(%lu, %d, [out]) has result %lx, expected: %lx", | 
|---|
| 880 | test_num, int2str->value, int2str->base, result, int2str->result); | 
|---|
| 881 | if (result == STATUS_SUCCESS) { | 
|---|
| 882 | ok(unicode_string.Buffer[unicode_string.Length/sizeof(WCHAR)] == '\0', | 
|---|
| 883 | "(test %d): RtlIntegerToUnicodeString(%lu, %d, [out]) string \"%s\" is not NULL terminated", | 
|---|
| 884 | test_num, int2str->value, int2str->base, ansi_str.Buffer); | 
|---|
| 885 | } /* if */ | 
|---|
| 886 | } /* if */ | 
|---|
| 887 | ok(memcmp(unicode_string.Buffer, expected_unicode_string.Buffer, STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0, | 
|---|
| 888 | "(test %d): RtlIntegerToUnicodeString(%lu, %d, [out]) assigns string \"%s\", expected: \"%s\"", | 
|---|
| 889 | test_num, int2str->value, int2str->base, ansi_str.Buffer, expected_ansi_str.Buffer); | 
|---|
| 890 | ok(unicode_string.Length == expected_unicode_string.Length, | 
|---|
| 891 | "(test %d): RtlIntegerToUnicodeString(%lu, %d, [out]) string has Length %d, expected: %d", | 
|---|
| 892 | test_num, int2str->value, int2str->base, unicode_string.Length, expected_unicode_string.Length); | 
|---|
| 893 | ok(unicode_string.MaximumLength == expected_unicode_string.MaximumLength, | 
|---|
| 894 | "(test %d): RtlIntegerToUnicodeString(%lu, %d, [out]) string has MaximumLength %d, expected: %d", | 
|---|
| 895 | test_num, int2str->value, int2str->base, unicode_string.MaximumLength, expected_unicode_string.MaximumLength); | 
|---|
| 896 | pRtlFreeAnsiString(&expected_ansi_str); | 
|---|
| 897 | pRtlFreeAnsiString(&ansi_str); | 
|---|
| 898 | } | 
|---|
| 899 |  | 
|---|
| 900 |  | 
|---|
| 901 | static void test_RtlIntegerToUnicodeString(void) | 
|---|
| 902 | { | 
|---|
| 903 | int test_num; | 
|---|
| 904 |  | 
|---|
| 905 | for (test_num = 0; test_num < NB_INT2STR; test_num++) { | 
|---|
| 906 | one_RtlIntegerToUnicodeString_test(test_num, &int2str[test_num]); | 
|---|
| 907 | } /* for */ | 
|---|
| 908 | } | 
|---|
| 909 |  | 
|---|
| 910 |  | 
|---|
| 911 | static void one_RtlIntegerToChar_test(int test_num, const int2str_t *int2str) | 
|---|
| 912 | { | 
|---|
| 913 | NTSTATUS result; | 
|---|
| 914 | char dest_str[STRI_BUFFER_LENGTH + 1]; | 
|---|
| 915 |  | 
|---|
| 916 | memset(dest_str, '-', STRI_BUFFER_LENGTH); | 
|---|
| 917 | dest_str[STRI_BUFFER_LENGTH] = '\0'; | 
|---|
| 918 | result = pRtlIntegerToChar(int2str->value, int2str->base, int2str->MaximumLength, dest_str); | 
|---|
| 919 | ok(result == int2str->result, | 
|---|
| 920 | "(test %d): RtlIntegerToChar(%lu, %d, %d, [out]) has result %lx, expected: %lx", | 
|---|
| 921 | test_num, int2str->value, int2str->base, int2str->MaximumLength, result, int2str->result); | 
|---|
| 922 | ok(memcmp(dest_str, int2str->Buffer, STRI_BUFFER_LENGTH) == 0, | 
|---|
| 923 | "(test %d): RtlIntegerToChar(%lu, %d, %d, [out]) assigns string \"%s\", expected: \"%s\"", | 
|---|
| 924 | test_num, int2str->value, int2str->base, int2str->MaximumLength, dest_str, int2str->Buffer); | 
|---|
| 925 | } | 
|---|
| 926 |  | 
|---|
| 927 |  | 
|---|
| 928 | static void test_RtlIntegerToChar(void) | 
|---|
| 929 | { | 
|---|
| 930 | NTSTATUS result; | 
|---|
| 931 | int test_num; | 
|---|
| 932 |  | 
|---|
| 933 | for (test_num = 0; test_num < NB_INT2STR; test_num++) { | 
|---|
| 934 | one_RtlIntegerToChar_test(test_num, &int2str[test_num]); | 
|---|
| 935 | } /* for */ | 
|---|
| 936 |  | 
|---|
| 937 | result = pRtlIntegerToChar(int2str[0].value, 20, int2str[0].MaximumLength, NULL); | 
|---|
| 938 | ok(result == STATUS_INVALID_PARAMETER, | 
|---|
| 939 | "(test a): RtlIntegerToChar(%lu, %d, %d, NULL) has result %lx, expected: %x", | 
|---|
| 940 | int2str[0].value, 20, int2str[0].MaximumLength, result, STATUS_INVALID_PARAMETER); | 
|---|
| 941 |  | 
|---|
| 942 | result = pRtlIntegerToChar(int2str[0].value, 20, 0, NULL); | 
|---|
| 943 | ok(result == STATUS_INVALID_PARAMETER, | 
|---|
| 944 | "(test b): RtlIntegerToChar(%lu, %d, %d, NULL) has result %lx, expected: %x", | 
|---|
| 945 | int2str[0].value, 20, 0, result, STATUS_INVALID_PARAMETER); | 
|---|
| 946 |  | 
|---|
| 947 | result = pRtlIntegerToChar(int2str[0].value, int2str[0].base, 0, NULL); | 
|---|
| 948 | ok(result == STATUS_BUFFER_OVERFLOW, | 
|---|
| 949 | "(test c): RtlIntegerToChar(%lu, %d, %d, NULL) has result %lx, expected: %x", | 
|---|
| 950 | int2str[0].value, int2str[0].base, 0, result, STATUS_BUFFER_OVERFLOW); | 
|---|
| 951 |  | 
|---|
| 952 | result = pRtlIntegerToChar(int2str[0].value, int2str[0].base, int2str[0].MaximumLength, NULL); | 
|---|
| 953 | ok(result == STATUS_ACCESS_VIOLATION, | 
|---|
| 954 | "(test d): RtlIntegerToChar(%lu, %d, %d, NULL) has result %lx, expected: %x", | 
|---|
| 955 | int2str[0].value, int2str[0].base, int2str[0].MaximumLength, result, STATUS_ACCESS_VIOLATION); | 
|---|
| 956 | } | 
|---|
| 957 |  | 
|---|
| 958 |  | 
|---|
| 959 | START_TEST(rtlstr) | 
|---|
| 960 | { | 
|---|
| 961 | InitFunctionPtrs(); | 
|---|
| 962 | if (pRtlInitAnsiString) { | 
|---|
| 963 | test_RtlInitString(); | 
|---|
| 964 | test_RtlInitUnicodeString(); | 
|---|
| 965 | test_RtlCopyString(); | 
|---|
| 966 | test_RtlUnicodeStringToInteger(); | 
|---|
| 967 | test_RtlCharToInteger(); | 
|---|
| 968 | test_RtlIntegerToUnicodeString(); | 
|---|
| 969 | test_RtlIntegerToChar(); | 
|---|
| 970 | test_RtlUpperChar(); | 
|---|
| 971 | test_RtlUpperString(); | 
|---|
| 972 | test_RtlAppendUnicodeStringToString(); | 
|---|
| 973 | } /* if */ | 
|---|
| 974 | /* | 
|---|
| 975 | * test_RtlUpcaseUnicodeChar(); | 
|---|
| 976 | * test_RtlUpcaseUnicodeString(); | 
|---|
| 977 | * test_RtlDowncaseUnicodeString(); | 
|---|
| 978 | */ | 
|---|
| 979 | } | 
|---|