Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / shlwapi / tests / string.c
blobaac79f83bd1842754ee59a4e41e96e46ddfbe8f2
1 /* Unit test suite for SHLWAPI string functions
3 * Copyright 2003 Jon Griffiths
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdio.h>
22 #include "wine/test.h"
23 #include "winbase.h"
24 #include "winerror.h"
25 #include "winnls.h"
26 #define NO_SHLWAPI_REG
27 #define NO_SHLWAPI_PATH
28 #define NO_SHLWAPI_GDI
29 #define NO_SHLWAPI_STREAM
30 #include "shlwapi.h"
31 #include "shtypes.h"
33 #define expect_eq(expr, val, type, fmt) do { \
34 type ret = expr; \
35 ok(ret == val, "Unexpected value of '" #expr "': " #fmt " instead of " #val "\n", ret); \
36 } while (0);
38 #define expect_eq2(expr, val1, val2, type, fmt) do { \
39 type ret = expr; \
40 ok(ret == val1 || ret == val2, "Unexpected value of '" #expr "': " #fmt " instead of " #val1 " or " #val2 "\n", ret); \
41 } while (0);
43 static BOOL (WINAPI *pChrCmpIA)(CHAR, CHAR);
44 static BOOL (WINAPI *pChrCmpIW)(WCHAR, WCHAR);
45 static BOOL (WINAPI *pIntlStrEqWorkerA)(BOOL,LPCSTR,LPCSTR,int);
46 static BOOL (WINAPI *pIntlStrEqWorkerW)(BOOL,LPCWSTR,LPCWSTR,int);
47 static DWORD (WINAPI *pSHAnsiToAnsi)(LPCSTR,LPSTR,int);
48 static DWORD (WINAPI *pSHUnicodeToUnicode)(LPCWSTR,LPWSTR,int);
49 static LPSTR (WINAPI *pStrCatBuffA)(LPSTR,LPCSTR,INT);
50 static LPWSTR (WINAPI *pStrCatBuffW)(LPWSTR,LPCWSTR,INT);
51 static LPSTR (WINAPI *pStrCpyNXA)(LPSTR,LPCSTR,int);
52 static LPWSTR (WINAPI *pStrCpyNXW)(LPWSTR,LPCWSTR,int);
53 static LPSTR (WINAPI *pStrFormatByteSize64A)(LONGLONG,LPSTR,UINT);
54 static LPSTR (WINAPI *pStrFormatKBSizeA)(LONGLONG,LPSTR,UINT);
55 static LPWSTR (WINAPI *pStrFormatKBSizeW)(LONGLONG,LPWSTR,UINT);
56 static BOOL (WINAPI *pStrIsIntlEqualA)(BOOL,LPCSTR,LPCSTR,int);
57 static BOOL (WINAPI *pStrIsIntlEqualW)(BOOL,LPCWSTR,LPCWSTR,int);
58 static LPWSTR (WINAPI *pStrPBrkW)(LPCWSTR,LPCWSTR);
59 static LPSTR (WINAPI *pStrRChrA)(LPCSTR,LPCSTR,WORD);
60 static HRESULT (WINAPI *pStrRetToBSTR)(STRRET*,LPCITEMIDLIST,BSTR*);
61 static HRESULT (WINAPI *pStrRetToBufA)(STRRET*,LPCITEMIDLIST,LPSTR,UINT);
62 static HRESULT (WINAPI *pStrRetToBufW)(STRRET*,LPCITEMIDLIST,LPWSTR,UINT);
63 static LPWSTR (WINAPI *pStrStrNW)(LPCWSTR,LPCWSTR,UINT);
64 static LPWSTR (WINAPI *pStrStrNIW)(LPCWSTR,LPCWSTR,UINT);
65 static INT (WINAPIV *pwnsprintfA)(LPSTR,INT,LPCSTR, ...);
66 static INT (WINAPIV *pwnsprintfW)(LPWSTR,INT,LPCWSTR, ...);
67 static LPWSTR (WINAPI *pStrChrNW)(LPWSTR,WCHAR,UINT);
68 static BOOL (WINAPI *pStrToInt64ExA)(LPCSTR,DWORD,LONGLONG*);
69 static BOOL (WINAPI *pStrToInt64ExW)(LPCWSTR,DWORD,LONGLONG*);
71 static int strcmpW(const WCHAR *str1, const WCHAR *str2)
73 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
74 return *str1 - *str2;
77 /* StrToInt/StrToIntEx results */
78 typedef struct tagStrToIntResult
80 const char* string;
81 int str_to_int;
82 LONGLONG str_to_int64_ex;
83 LONGLONG str_to_int64_hex;
84 } StrToIntResult;
86 static const StrToIntResult StrToInt_results[] = {
87 { "1099", 1099, 1099, 1099 },
88 { "4294967319", 23, ((LONGLONG)1 << 32) | 23, ((LONGLONG)1 << 32) | 23 },
89 { "+88987", 0, 88987, 88987 },
90 { "012", 12, 12, 12 },
91 { "-55", -55, -55, -55 },
92 { "-0", 0, 0, 0 },
93 { "0x44ff", 0, 0, 0x44ff },
94 { "0x2bdc546291f4b1", 0, 0, ((LONGLONG)0x2bdc54 << 32) | 0x6291f4b1 },
95 { "+0x44f4", 0, 0, 0x44f4 },
96 { "-0x44fd", 0, 0, 0x44fd },
97 { "+ 88987", 0, 0, 0 },
98 { "- 55", 0, 0, 0 },
99 { "- 0", 0, 0, 0 },
100 { "+ 0x44f4", 0, 0, 0 },
101 { "--0x44fd", 0, 0, 0 },
102 { " 1999", 0, 1999, 1999 },
103 { " +88987", 0, 88987, 88987 },
104 { " 012", 0, 12, 12 },
105 { " -55", 0, -55, -55 },
106 { " 0x44ff", 0, 0, 0x44ff },
107 { " +0x44f4", 0, 0, 0x44f4 },
108 { " -0x44fd", 0, 0, 0x44fd },
109 { NULL, 0, 0, 0 }
112 /* pStrFormatByteSize64/StrFormatKBSize results */
113 typedef struct tagStrFormatSizeResult
115 LONGLONG value;
116 const char* byte_size_64;
117 const char* kb_size;
118 int kb_size_broken;
119 const char* kb_size2;
120 } StrFormatSizeResult;
123 static const StrFormatSizeResult StrFormatSize_results[] = {
124 { -1023, "-1023 bytes", "0 KB"},
125 { -24, "-24 bytes", "0 KB"},
126 { 309, "309 bytes", "1 KB"},
127 { 10191, "9.95 KB", "10 KB"},
128 { 100353, "98.0 KB", "99 KB"},
129 { 1022286, "998 KB", "999 KB"},
130 { 1046862, "0.99 MB", "1,023 KB", 1, "1023 KB"},
131 { 1048574619, "999 MB", "1,023,999 KB", 1, "1023999 KB"},
132 { 1073741775, "0.99 GB", "1,048,576 KB", 1, "1048576 KB"},
133 { ((LONGLONG)0x000000f9 << 32) | 0xfffff94e, "999 GB", "1,048,575,999 KB", 1, "1048575999 KB"},
134 { ((LONGLONG)0x000000ff << 32) | 0xfffffa9b, "0.99 TB", "1,073,741,823 KB", 1, "1073741823 KB"},
135 { ((LONGLONG)0x0003e7ff << 32) | 0xfffffa9b, "999 TB", "1,073,741,823,999 KB", 1, "4294967295 KB"},
136 { ((LONGLONG)0x0003ffff << 32) | 0xfffffbe8, "0.99 PB", "1,099,511,627,775 KB", 1, "4294967295 KB"},
137 { ((LONGLONG)0x0f9fffff << 32) | 0xfffffd35, "999 PB", "1,099,511,627,776,000 KB", 1, "0 KB"},
138 { ((LONGLONG)0x0fffffff << 32) | 0xfffffa9b, "0.99 EB", "1,125,899,906,842,623 KB", 1, "4294967295 KB"},
139 { 0, NULL, NULL }
142 /* StrFromTimeIntervalA/StrFromTimeIntervalW results */
143 typedef struct tagStrFromTimeIntervalResult
145 DWORD ms;
146 int digits;
147 const char* time_interval;
148 } StrFromTimeIntervalResult;
151 static const StrFromTimeIntervalResult StrFromTimeInterval_results[] = {
152 { 1, 1, " 0 sec" },
153 { 1, 2, " 0 sec" },
154 { 1, 3, " 0 sec" },
155 { 1, 4, " 0 sec" },
156 { 1, 5, " 0 sec" },
157 { 1, 6, " 0 sec" },
158 { 1, 7, " 0 sec" },
160 { 1000000, 1, " 10 min" },
161 { 1000000, 2, " 16 min" },
162 { 1000000, 3, " 16 min 40 sec" },
163 { 1000000, 4, " 16 min 40 sec" },
164 { 1000000, 5, " 16 min 40 sec" },
165 { 1000000, 6, " 16 min 40 sec" },
166 { 1000000, 7, " 16 min 40 sec" },
168 { 1999999, 1, " 30 min" },
169 { 1999999, 2, " 33 min" },
170 { 1999999, 3, " 33 min 20 sec" },
171 { 1999999, 4, " 33 min 20 sec" },
172 { 1999999, 5, " 33 min 20 sec" },
173 { 1999999, 6, " 33 min 20 sec" },
174 { 1999999, 7, " 33 min 20 sec" },
176 { 3999997, 1, " 1 hr" },
177 { 3999997, 2, " 1 hr 6 min" },
178 { 3999997, 3, " 1 hr 6 min 40 sec" },
179 { 3999997, 4, " 1 hr 6 min 40 sec" },
180 { 3999997, 5, " 1 hr 6 min 40 sec" },
181 { 3999997, 6, " 1 hr 6 min 40 sec" },
182 { 3999997, 7, " 1 hr 6 min 40 sec" },
184 { 149999851, 7, " 41 hr 40 min 0 sec" },
185 { 150999850, 1, " 40 hr" },
186 { 150999850, 2, " 41 hr" },
187 { 150999850, 3, " 41 hr 50 min" },
188 { 150999850, 4, " 41 hr 56 min" },
189 { 150999850, 5, " 41 hr 56 min 40 sec" },
190 { 150999850, 6, " 41 hr 56 min 40 sec" },
191 { 150999850, 7, " 41 hr 56 min 40 sec" },
193 { 493999507, 1, " 100 hr" },
194 { 493999507, 2, " 130 hr" },
195 { 493999507, 3, " 137 hr" },
196 { 493999507, 4, " 137 hr 10 min" },
197 { 493999507, 5, " 137 hr 13 min" },
198 { 493999507, 6, " 137 hr 13 min 20 sec" },
199 { 493999507, 7, " 137 hr 13 min 20 sec" },
201 { 0, 0, NULL }
205 /* Returns true if the user interface is in English. Note that this does not
206 * presume of the formatting of dates, numbers, etc.
208 static BOOL is_lang_english(void)
210 static HMODULE hkernel32 = NULL;
211 static LANGID (WINAPI *pGetThreadUILanguage)(void) = NULL;
212 static LANGID (WINAPI *pGetUserDefaultUILanguage)(void) = NULL;
214 if (!hkernel32)
216 hkernel32 = GetModuleHandleA("kernel32.dll");
217 pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
218 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
220 if (pGetThreadUILanguage)
221 return PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH;
222 if (pGetUserDefaultUILanguage)
223 return PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH;
225 return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
228 /* Returns true if the dates, numbers, etc. are formatted using English
229 * conventions.
231 static BOOL is_locale_english(void)
233 /* Surprisingly GetThreadLocale() is irrelevant here */
234 return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
237 static void test_StrChrA(void)
239 char string[129];
240 WORD count;
242 /* this test crashes on win2k SP4 */
243 /*ok(!StrChrA(NULL,'\0'), "found a character in a NULL string!\n");*/
245 for (count = 32; count < 128; count++)
246 string[count] = (char)count;
247 string[128] = '\0';
249 for (count = 32; count < 128; count++)
251 LPSTR result = StrChrA(string+32, count);
252 INT pos = result - string;
253 ok(pos == count, "found char '%c' in wrong place: got %d, expected %d\n", count, pos, count);
256 for (count = 32; count < 128; count++)
258 LPSTR result = StrChrA(string+count+1, count);
259 ok(!result, "found char '%c' not in the string\n", count);
263 static void test_StrChrW(void)
265 WCHAR string[16385];
266 WORD count;
268 /* this test crashes on win2k SP4 */
269 /*ok(!StrChrW(NULL,'\0'), "found a character in a NULL string!\n");*/
271 for (count = 32; count < 16384; count++)
272 string[count] = count;
273 string[16384] = '\0';
275 for (count = 32; count < 16384; count++)
277 LPWSTR result = StrChrW(string+32, count);
278 ok((result - string) == count, "found char %d in wrong place\n", count);
281 for (count = 32; count < 16384; count++)
283 LPWSTR result = StrChrW(string+count+1, count);
284 ok(!result, "found char not in the string\n");
288 static void test_StrChrIA(void)
290 char string[129];
291 WORD count;
293 /* this test crashes on win2k SP4 */
294 /*ok(!StrChrIA(NULL,'\0'), "found a character in a NULL string!\n");*/
296 for (count = 32; count < 128; count++)
297 string[count] = (char)count;
298 string[128] = '\0';
300 for (count = 'A'; count <= 'X'; count++)
302 LPSTR result = StrChrIA(string+32, count);
304 ok(result - string == count, "found char '%c' in wrong place\n", count);
305 ok(StrChrIA(result, count)!=NULL, "didn't find lowercase '%c'\n", count);
308 for (count = 'a'; count < 'z'; count++)
310 LPSTR result = StrChrIA(string+count+1, count);
311 ok(!result, "found char not in the string\n");
315 static void test_StrChrIW(void)
317 WCHAR string[129];
318 WORD count;
320 /* this test crashes on win2k SP4 */
321 /*ok(!StrChrIA(NULL,'\0'), "found a character in a NULL string!\n");*/
323 for (count = 32; count < 128; count++)
324 string[count] = count;
325 string[128] = '\0';
327 for (count = 'A'; count <= 'X'; count++)
329 LPWSTR result = StrChrIW(string+32, count);
331 ok(result - string == count, "found char '%c' in wrong place\n", count);
332 ok(StrChrIW(result, count)!=NULL, "didn't find lowercase '%c'\n", count);
335 for (count = 'a'; count < 'z'; count++)
337 LPWSTR result = StrChrIW(string+count+1, count);
338 ok(!result, "found char not in the string\n");
342 static void test_StrRChrA(void)
344 char string[129];
345 WORD count;
347 /* this test crashes on win2k SP4 */
348 /*ok(!StrRChrA(NULL, NULL,'\0'), "found a character in a NULL string!\n");*/
350 for (count = 32; count < 128; count++)
351 string[count] = (char)count;
352 string[128] = '\0';
354 for (count = 32; count < 128; count++)
356 LPSTR result = StrRChrA(string+32, NULL, count);
357 ok(result - string == count, "found char %d in wrong place\n", count);
360 for (count = 32; count < 128; count++)
362 LPSTR result = StrRChrA(string+count+1, NULL, count);
363 ok(!result, "found char not in the string\n");
366 for (count = 32; count < 128; count++)
368 LPSTR result = StrRChrA(string+count+1, string + 127, count);
369 ok(!result, "found char not in the string\n");
373 static void test_StrRChrW(void)
375 WCHAR string[129];
376 WORD count;
378 /* this test crashes on win2k SP4 */
379 /*ok(!StrRChrW(NULL, NULL,'\0'), "found a character in a NULL string!\n");*/
381 for (count = 32; count < 128; count++)
382 string[count] = count;
383 string[128] = '\0';
385 for (count = 32; count < 128; count++)
387 LPWSTR result = StrRChrW(string+32, NULL, count);
388 INT pos = result - string;
389 ok(pos == count, "found char %d in wrong place: got %d, expected %d\n", count, pos, count);
392 for (count = 32; count < 128; count++)
394 LPWSTR result = StrRChrW(string+count+1, NULL, count);
395 ok(!result, "found char %d not in the string\n", count);
398 for (count = 32; count < 128; count++)
400 LPWSTR result = StrRChrW(string+count+1, string + 127, count);
401 ok(!result, "found char %d not in the string\n", count);
405 static void test_StrCpyW(void)
407 WCHAR szSrc[256];
408 WCHAR szBuff[256];
409 const StrFormatSizeResult* result = StrFormatSize_results;
410 LPWSTR lpRes;
412 while(result->value)
414 MultiByteToWideChar(0,0,result->byte_size_64,-1,szSrc,sizeof(szSrc)/sizeof(WCHAR));
416 lpRes = StrCpyW(szBuff, szSrc);
417 ok(!StrCmpW(szSrc, szBuff) && lpRes == szBuff, "Copied string %s wrong\n", result->byte_size_64);
418 result++;
421 /* this test crashes on win2k SP4 */
422 /*lpRes = StrCpyW(szBuff, NULL);*/
423 /*ok(lpRes == szBuff, "Wrong return value: got %p expected %p\n", lpRes, szBuff);*/
425 /* this test crashes on win2k SP4 */
426 /*lpRes = StrCpyW(NULL, szSrc);*/
427 /*ok(lpRes == NULL, "Wrong return value: got %p expected NULL\n", lpRes);*/
429 /* this test crashes on win2k SP4 */
430 /*lpRes = StrCpyW(NULL, NULL);*/
431 /*ok(lpRes == NULL, "Wrong return value: got %p expected NULL\n", lpRes);*/
434 static void test_StrChrNW(void)
436 static WCHAR string[] = {'T','e','s','t','i','n','g',' ','S','t','r','i','n','g',0};
437 LPWSTR p;
439 if (!pStrChrNW)
441 win_skip("StrChrNW not available\n");
442 return;
445 p = pStrChrNW(string,'t',10);
446 ok(*p=='t',"Found wrong 't'\n");
447 ok(*(p+1)=='i',"next should be 'i'\n");
449 p = pStrChrNW(string,'S',10);
450 ok(*p=='S',"Found wrong 'S'\n");
452 p = pStrChrNW(string,'r',10);
453 ok(p==NULL,"Should not have found 'r'\n");
456 static void test_StrToIntA(void)
458 const StrToIntResult *result = StrToInt_results;
459 int return_val;
461 while (result->string)
463 return_val = StrToIntA(result->string);
464 ok(return_val == result->str_to_int, "converted '%s' wrong (%d)\n",
465 result->string, return_val);
466 result++;
470 static void test_StrToIntW(void)
472 WCHAR szBuff[256];
473 const StrToIntResult *result = StrToInt_results;
474 int return_val;
476 while (result->string)
478 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
479 return_val = StrToIntW(szBuff);
480 ok(return_val == result->str_to_int, "converted '%s' wrong (%d)\n",
481 result->string, return_val);
482 result++;
486 static void test_StrToIntExA(void)
488 const StrToIntResult *result = StrToInt_results;
489 int return_val;
490 BOOL bRet;
492 while (result->string)
494 return_val = -1;
495 bRet = StrToIntExA(result->string,0,&return_val);
496 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
497 result->string);
498 if (bRet)
499 ok(return_val == (int)result->str_to_int64_ex, "converted '%s' wrong (%d)\n",
500 result->string, return_val);
501 result++;
504 result = StrToInt_results;
505 while (result->string)
507 return_val = -1;
508 bRet = StrToIntExA(result->string,STIF_SUPPORT_HEX,&return_val);
509 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
510 result->string);
511 if (bRet)
512 ok(return_val == (int)result->str_to_int64_hex, "converted '%s' wrong (%d)\n",
513 result->string, return_val);
514 result++;
518 static void test_StrToIntExW(void)
520 WCHAR szBuff[256];
521 const StrToIntResult *result = StrToInt_results;
522 int return_val;
523 BOOL bRet;
525 while (result->string)
527 return_val = -1;
528 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
529 bRet = StrToIntExW(szBuff, 0, &return_val);
530 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
531 result->string);
532 if (bRet)
533 ok(return_val == (int)result->str_to_int64_ex, "converted '%s' wrong (%d)\n",
534 result->string, return_val);
535 result++;
538 result = StrToInt_results;
539 while (result->string)
541 return_val = -1;
542 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
543 bRet = StrToIntExW(szBuff, STIF_SUPPORT_HEX, &return_val);
544 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
545 result->string);
546 if (bRet)
547 ok(return_val == (int)result->str_to_int64_hex, "converted '%s' wrong (%d)\n",
548 result->string, return_val);
549 result++;
553 static void test_StrToInt64ExA(void)
555 const StrToIntResult *result = StrToInt_results;
556 LONGLONG return_val;
557 BOOL bRet;
559 if (!pStrToInt64ExA)
561 win_skip("StrToInt64ExA() is not available\n");
562 return;
565 while (result->string)
567 return_val = -1;
568 bRet = pStrToInt64ExA(result->string,0,&return_val);
569 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
570 result->string);
571 if (bRet)
572 ok(return_val == result->str_to_int64_ex, "converted '%s' wrong (%08x%08x)\n",
573 result->string, (DWORD)(return_val >> 32), (DWORD)return_val);
574 result++;
577 result = StrToInt_results;
578 while (result->string)
580 return_val = -1;
581 bRet = pStrToInt64ExA(result->string,STIF_SUPPORT_HEX,&return_val);
582 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
583 result->string);
584 if (bRet)
585 ok(return_val == result->str_to_int64_hex, "converted '%s' wrong (%08x%08x)\n",
586 result->string, (DWORD)(return_val >> 32), (DWORD)return_val);
587 result++;
591 static void test_StrToInt64ExW(void)
593 WCHAR szBuff[256];
594 const StrToIntResult *result = StrToInt_results;
595 LONGLONG return_val;
596 BOOL bRet;
598 if (!pStrToInt64ExW)
600 win_skip("StrToInt64ExW() is not available\n");
601 return;
604 while (result->string)
606 return_val = -1;
607 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
608 bRet = pStrToInt64ExW(szBuff, 0, &return_val);
609 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
610 result->string);
611 if (bRet)
612 ok(return_val == result->str_to_int64_ex, "converted '%s' wrong (%08x%08x)\n",
613 result->string, (DWORD)(return_val >> 32), (DWORD)return_val);
614 result++;
617 result = StrToInt_results;
618 while (result->string)
620 return_val = -1;
621 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
622 bRet = pStrToInt64ExW(szBuff, STIF_SUPPORT_HEX, &return_val);
623 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
624 result->string);
625 if (bRet)
626 ok(return_val == result->str_to_int64_hex, "converted '%s' wrong (%08x%08x)\n",
627 result->string, (DWORD)(return_val >> 32), (DWORD)return_val);
628 result++;
632 static void test_StrDupA(void)
634 LPSTR lpszStr;
635 const StrFormatSizeResult* result = StrFormatSize_results;
637 while(result->value)
639 lpszStr = StrDupA(result->byte_size_64);
641 ok(lpszStr != NULL, "Dup failed\n");
642 if (lpszStr)
644 ok(!strcmp(result->byte_size_64, lpszStr), "Copied string wrong\n");
645 LocalFree(lpszStr);
647 result++;
650 /* Later versions of shlwapi return NULL for this, but earlier versions
651 * returned an empty string (as Wine does).
653 lpszStr = StrDupA(NULL);
654 ok(lpszStr == NULL || *lpszStr == '\0', "NULL string returned %p\n", lpszStr);
655 LocalFree(lpszStr);
658 static void test_StrFormatByteSize64A(void)
660 char szBuff[256];
661 const StrFormatSizeResult* result = StrFormatSize_results;
663 if (!pStrFormatByteSize64A)
665 win_skip("StrFormatByteSize64A() is not available\n");
666 return;
669 while(result->value)
671 pStrFormatByteSize64A(result->value, szBuff, 256);
673 ok(!strcmp(result->byte_size_64, szBuff),
674 "Formatted %x%08x wrong: got %s, expected %s\n",
675 (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->byte_size_64);
677 result++;
681 static void test_StrFormatKBSizeW(void)
683 WCHAR szBuffW[256];
684 char szBuff[256];
685 const StrFormatSizeResult* result = StrFormatSize_results;
687 if (!pStrFormatKBSizeW)
689 win_skip("StrFormatKBSizeW() is not available\n");
690 return;
693 while(result->value)
695 pStrFormatKBSizeW(result->value, szBuffW, 256);
696 WideCharToMultiByte(0,0,szBuffW,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR),0,0);
698 ok(!strcmp(result->kb_size, szBuff), "Formatted %x%08x wrong: got %s, expected %s\n",
699 (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->kb_size);
700 result++;
704 static void test_StrFormatKBSizeA(void)
706 char szBuff[256];
707 const StrFormatSizeResult* result = StrFormatSize_results;
709 if (!pStrFormatKBSizeA)
711 win_skip("StrFormatKBSizeA() is not available\n");
712 return;
715 while(result->value)
717 pStrFormatKBSizeA(result->value, szBuff, 256);
719 /* shlwapi on Win98 SE does not appear to apply delimiters to the output
720 * and does not correctly handle extremely large values. */
721 ok(!strcmp(result->kb_size, szBuff) ||
722 (result->kb_size_broken && !strcmp(result->kb_size2, szBuff)),
723 "Formatted %x%08x wrong: got %s, expected %s\n",
724 (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->kb_size);
725 result++;
729 static void test_StrFromTimeIntervalA(void)
731 char szBuff[256];
732 const StrFromTimeIntervalResult* result = StrFromTimeInterval_results;
734 while(result->ms)
736 StrFromTimeIntervalA(szBuff, 256, result->ms, result->digits);
738 ok(!strcmp(result->time_interval, szBuff), "Formatted %d %d wrong: %s\n",
739 result->ms, result->digits, szBuff);
740 result++;
744 static void test_StrCmpA(void)
746 static const char str1[] = {'a','b','c','d','e','f'};
747 static const char str2[] = {'a','B','c','d','e','f'};
748 ok(0 != StrCmpNA(str1, str2, 6), "StrCmpNA is case-insensitive\n");
749 ok(0 == StrCmpNIA(str1, str2, 6), "StrCmpNIA is case-sensitive\n");
750 if (pChrCmpIA) {
751 ok(!pChrCmpIA('a', 'a'), "ChrCmpIA doesn't work at all!\n");
752 ok(!pChrCmpIA('b', 'B'), "ChrCmpIA is not case-insensitive\n");
753 ok(pChrCmpIA('a', 'z'), "ChrCmpIA believes that a == z!\n");
755 else
756 win_skip("ChrCmpIA() is not available\n");
758 if (pStrIsIntlEqualA)
760 ok(pStrIsIntlEqualA(FALSE, str1, str2, 5), "StrIsIntlEqualA(FALSE,...) isn't case-insensitive\n");
761 ok(!pStrIsIntlEqualA(TRUE, str1, str2, 5), "StrIsIntlEqualA(TRUE,...) isn't case-sensitive\n");
763 else
764 win_skip("StrIsIntlEqualA() is not available\n");
766 if (pIntlStrEqWorkerA)
768 ok(pIntlStrEqWorkerA(FALSE, str1, str2, 5), "IntlStrEqWorkerA(FALSE,...) isn't case-insensitive\n");
769 ok(!pIntlStrEqWorkerA(TRUE, str1, str2, 5), "pIntlStrEqWorkerA(TRUE,...) isn't case-sensitive\n");
771 else
772 win_skip("IntlStrEqWorkerA() is not available\n");
775 static void test_StrCmpW(void)
777 static const WCHAR str1[] = {'a','b','c','d','e','f'};
778 static const WCHAR str2[] = {'a','B','c','d','e','f'};
779 ok(0 != StrCmpNW(str1, str2, 5), "StrCmpNW is case-insensitive\n");
780 ok(0 == StrCmpNIW(str1, str2, 5), "StrCmpNIW is case-sensitive\n");
781 if (pChrCmpIW) {
782 ok(!pChrCmpIW('a', 'a'), "ChrCmpIW doesn't work at all!\n");
783 ok(!pChrCmpIW('b', 'B'), "ChrCmpIW is not case-insensitive\n");
784 ok(pChrCmpIW('a', 'z'), "ChrCmpIW believes that a == z!\n");
786 else
787 win_skip("ChrCmpIW() is not available\n");
789 if (pStrIsIntlEqualW)
791 ok(pStrIsIntlEqualW(FALSE, str1, str2, 5), "StrIsIntlEqualW(FALSE,...) isn't case-insensitive\n");
792 ok(!pStrIsIntlEqualW(TRUE, str1, str2, 5), "StrIsIntlEqualW(TRUE,...) isn't case-sensitive\n");
794 else
795 win_skip("StrIsIntlEqualW() is not available\n");
797 if (pIntlStrEqWorkerW)
799 ok(pIntlStrEqWorkerW(FALSE, str1, str2, 5), "IntlStrEqWorkerW(FALSE,...) isn't case-insensitive\n");
800 ok(!pIntlStrEqWorkerW(TRUE, str1, str2, 5), "IntlStrEqWorkerW(TRUE,...) isn't case-sensitive\n");
802 else
803 win_skip("IntlStrEqWorkerW() is not available\n");
806 static WCHAR *CoDupStrW(const char* src)
808 INT len = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0);
809 WCHAR* szTemp = CoTaskMemAlloc(len * sizeof(WCHAR));
810 MultiByteToWideChar(CP_ACP, 0, src, -1, szTemp, len);
811 return szTemp;
814 static void test_StrRetToBSTR(void)
816 static const WCHAR szTestW[] = { 'T','e','s','t','\0' };
817 ITEMIDLIST iidl[10];
818 BSTR bstr;
819 STRRET strret;
820 HRESULT ret;
822 if (!pStrRetToBSTR)
824 win_skip("StrRetToBSTR() is not available\n");
825 return;
828 strret.uType = STRRET_WSTR;
829 U(strret).pOleStr = CoDupStrW("Test");
830 bstr = 0;
831 ret = pStrRetToBSTR(&strret, NULL, &bstr);
832 ok(ret == S_OK && bstr && !strcmpW(bstr, szTestW),
833 "STRRET_WSTR: dup failed, ret=0x%08x, bstr %p\n", ret, bstr);
834 SysFreeString(bstr);
836 strret.uType = STRRET_CSTR;
837 lstrcpyA(U(strret).cStr, "Test");
838 ret = pStrRetToBSTR(&strret, NULL, &bstr);
839 ok(ret == S_OK && bstr && !strcmpW(bstr, szTestW),
840 "STRRET_CSTR: dup failed, ret=0x%08x, bstr %p\n", ret, bstr);
841 SysFreeString(bstr);
843 strret.uType = STRRET_OFFSET;
844 U(strret).uOffset = 1;
845 strcpy((char*)&iidl, " Test");
846 ret = pStrRetToBSTR(&strret, iidl, &bstr);
847 ok(ret == S_OK && bstr && !strcmpW(bstr, szTestW),
848 "STRRET_OFFSET: dup failed, ret=0x%08x, bstr %p\n", ret, bstr);
849 SysFreeString(bstr);
851 /* Native crashes if str is NULL */
854 static void test_StrCpyNXA(void)
856 LPCSTR lpSrc = "hello";
857 LPSTR lpszRes;
858 char dest[8];
860 if (!pStrCpyNXA)
862 win_skip("StrCpyNXA() is not available\n");
863 return;
866 memset(dest, '\n', sizeof(dest));
867 lpszRes = pStrCpyNXA(dest, lpSrc, sizeof(dest)/sizeof(dest[0]));
868 ok(lpszRes == dest + 5 && !memcmp(dest, "hello\0\n\n", sizeof(dest)),
869 "StrCpyNXA: expected %p, \"hello\\0\\n\\n\", got %p, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
870 dest + 5, lpszRes, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
873 static void test_StrCpyNXW(void)
875 static const WCHAR lpInit[] = { '\n','\n','\n','\n','\n','\n','\n','\n' };
876 static const WCHAR lpSrc[] = { 'h','e','l','l','o','\0' };
877 static const WCHAR lpRes[] = { 'h','e','l','l','o','\0','\n','\n' };
878 LPWSTR lpszRes;
879 WCHAR dest[8];
881 if (!pStrCpyNXW)
883 win_skip("StrCpyNXW() is not available\n");
884 return;
887 memcpy(dest, lpInit, sizeof(lpInit));
888 lpszRes = pStrCpyNXW(dest, lpSrc, sizeof(dest)/sizeof(dest[0]));
889 ok(lpszRes == dest + 5 && !memcmp(dest, lpRes, sizeof(dest)),
890 "StrCpyNXW: expected %p, \"hello\\0\\n\\n\", got %p, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
891 dest + 5, lpszRes, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
894 #define check_strrstri(type, str, pos, needle, exp) \
895 ret##type = StrRStrI##type(str, str+pos, needle); \
896 ok(ret##type == (exp), "Type " #type ", expected %p but got %p (string base %p)\n", \
897 (exp), ret##type, str);
899 static void test_StrRStrI(void)
901 static const CHAR szTest[] = "yAxxxxAy";
902 static const CHAR szTest2[] = "ABABABAB";
903 static const WCHAR wszTest[] = {'y','A','x','x','x','x','A','y',0};
904 static const WCHAR wszTest2[] = {'A','B','A','B','A','B','A','B',0};
906 static const WCHAR wszPattern1[] = {'A',0};
907 static const WCHAR wszPattern2[] = {'a','X',0};
908 static const WCHAR wszPattern3[] = {'A','y',0};
909 static const WCHAR wszPattern4[] = {'a','b',0};
910 LPWSTR retW;
911 LPSTR retA;
913 check_strrstri(A, szTest, 4, "A", szTest+1);
914 check_strrstri(A, szTest, 4, "aX", szTest+1);
915 check_strrstri(A, szTest, 4, "Ay", NULL);
916 check_strrstri(W, wszTest, 4, wszPattern1, wszTest+1);
917 check_strrstri(W, wszTest, 4, wszPattern2, wszTest+1);
918 check_strrstri(W, wszTest, 4, wszPattern3, NULL);
920 check_strrstri(A, szTest2, 4, "ab", szTest2+2);
921 check_strrstri(A, szTest2, 3, "ab", szTest2+2);
922 check_strrstri(A, szTest2, 2, "ab", szTest2);
923 check_strrstri(A, szTest2, 1, "ab", szTest2);
924 check_strrstri(A, szTest2, 0, "ab", NULL);
925 check_strrstri(W, wszTest2, 4, wszPattern4, wszTest2+2);
926 check_strrstri(W, wszTest2, 3, wszPattern4, wszTest2+2);
927 check_strrstri(W, wszTest2, 2, wszPattern4, wszTest2);
928 check_strrstri(W, wszTest2, 1, wszPattern4, wszTest2);
929 check_strrstri(W, wszTest2, 0, wszPattern4, NULL);
933 static void test_SHAnsiToAnsi(void)
935 char dest[8];
936 DWORD dwRet;
938 if (!pSHAnsiToAnsi)
940 win_skip("SHAnsiToAnsi() is not available\n");
941 return;
944 if (pSHAnsiToAnsi == (void *)pStrPBrkW)
946 win_skip("Ordinal 345 corresponds to StrPBrkW, skipping SHAnsiToAnsi tests\n");
947 return;
950 memset(dest, '\n', sizeof(dest));
951 dwRet = pSHAnsiToAnsi("hello", dest, sizeof(dest)/sizeof(dest[0]));
952 ok(dwRet == 6 && !memcmp(dest, "hello\0\n\n", sizeof(dest)),
953 "SHAnsiToAnsi: expected 6, \"hello\\0\\n\\n\", got %d, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
954 dwRet, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
957 static void test_SHUnicodeToUnicode(void)
959 static const WCHAR lpInit[] = { '\n','\n','\n','\n','\n','\n','\n','\n' };
960 static const WCHAR lpSrc[] = { 'h','e','l','l','o','\0' };
961 static const WCHAR lpRes[] = { 'h','e','l','l','o','\0','\n','\n' };
962 WCHAR dest[8];
963 DWORD dwRet;
965 if (!pSHUnicodeToUnicode)
967 win_skip("SHUnicodeToUnicode() is not available\n");
968 return;
971 if (pSHUnicodeToUnicode == (void *)pStrRChrA)
973 win_skip("Ordinal 346 corresponds to StrRChrA, skipping SHUnicodeToUnicode tests\n");
974 return;
977 memcpy(dest, lpInit, sizeof(lpInit));
978 dwRet = pSHUnicodeToUnicode(lpSrc, dest, sizeof(dest)/sizeof(dest[0]));
979 ok(dwRet == 6 && !memcmp(dest, lpRes, sizeof(dest)),
980 "SHUnicodeToUnicode: expected 6, \"hello\\0\\n\\n\", got %d, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
981 dwRet, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
984 static void test_StrXXX_overflows(void)
986 CHAR str1[2*MAX_PATH+1], buf[2*MAX_PATH];
987 WCHAR wstr1[2*MAX_PATH+1], wbuf[2*MAX_PATH];
988 const WCHAR fmt[] = {'%','s',0};
989 STRRET strret;
990 int ret;
991 int i;
993 for (i=0; i<2*MAX_PATH; i++)
995 str1[i] = '0'+(i%10);
996 wstr1[i] = '0'+(i%10);
998 str1[2*MAX_PATH] = 0;
999 wstr1[2*MAX_PATH] = 0;
1001 memset(buf, 0xbf, sizeof(buf));
1002 expect_eq(StrCpyNA(buf, str1, 10), buf, PCHAR, "%p");
1003 expect_eq(buf[9], 0, CHAR, "%x");
1004 expect_eq(buf[10], '\xbf', CHAR, "%x");
1006 if (pStrCatBuffA)
1008 expect_eq(pStrCatBuffA(buf, str1, 100), buf, PCHAR, "%p");
1009 expect_eq(buf[99], 0, CHAR, "%x");
1010 expect_eq(buf[100], '\xbf', CHAR, "%x");
1012 else
1013 win_skip("StrCatBuffA() is not available\n");
1015 if (0)
1017 /* crashes on XP */
1018 StrCpyNW(wbuf, (LPCWSTR)0x1, 10);
1019 StrCpyNW((LPWSTR)0x1, wstr1, 10);
1022 memset(wbuf, 0xbf, sizeof(wbuf));
1023 expect_eq(StrCpyNW(wbuf, (LPCWSTR)0x1, 1), wbuf, PWCHAR, "%p");
1024 expect_eq(wbuf[0], 0, WCHAR, "%x");
1025 expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
1027 memset(wbuf, 0xbf, sizeof(wbuf));
1028 expect_eq(StrCpyNW(wbuf, 0, 10), wbuf, PWCHAR, "%p");
1029 expect_eq(wbuf[0], 0, WCHAR, "%x");
1030 expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
1032 memset(wbuf, 0xbf, sizeof(wbuf));
1033 expect_eq(StrCpyNW(wbuf, 0, 0), wbuf, PWCHAR, "%p");
1034 expect_eq(wbuf[0], (WCHAR)0xbfbf, WCHAR, "%x");
1035 expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
1037 memset(wbuf, 0xbf, sizeof(wbuf));
1038 expect_eq(StrCpyNW(wbuf, wstr1, 0), wbuf, PWCHAR, "%p");
1039 expect_eq(wbuf[0], (WCHAR)0xbfbf, WCHAR, "%x");
1040 expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
1042 memset(wbuf, 0xbf, sizeof(wbuf));
1043 expect_eq(StrCpyNW(wbuf, wstr1, 10), wbuf, PWCHAR, "%p");
1044 expect_eq(wbuf[9], 0, WCHAR, "%x");
1045 expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
1047 if (pStrCatBuffW)
1049 expect_eq(pStrCatBuffW(wbuf, wstr1, 100), wbuf, PWCHAR, "%p");
1050 expect_eq(wbuf[99], 0, WCHAR, "%x");
1051 expect_eq(wbuf[100], (WCHAR)0xbfbf, WCHAR, "%x");
1053 else
1054 win_skip("StrCatBuffW() is not available\n");
1056 if (pStrRetToBufW)
1058 memset(wbuf, 0xbf, sizeof(wbuf));
1059 strret.uType = STRRET_WSTR;
1060 U(strret).pOleStr = StrDupW(wstr1);
1061 expect_eq2(pStrRetToBufW(&strret, NULL, wbuf, 10), S_OK, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) /* Vista */, HRESULT, "%x");
1062 expect_eq(wbuf[9], 0, WCHAR, "%x");
1063 expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
1065 else
1066 win_skip("StrRetToBufW() is not available\n");
1068 if (pStrRetToBufA)
1070 memset(buf, 0xbf, sizeof(buf));
1071 strret.uType = STRRET_CSTR;
1072 StrCpyN(U(strret).cStr, str1, MAX_PATH);
1073 expect_eq2(pStrRetToBufA(&strret, NULL, buf, 10), S_OK, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) /* Vista */, HRESULT, "%x");
1074 expect_eq(buf[9], 0, CHAR, "%x");
1075 expect_eq(buf[10], (CHAR)0xbf, CHAR, "%x");
1077 else
1078 win_skip("StrRetToBufA() is not available\n");
1080 if (pwnsprintfA)
1082 memset(buf, 0xbf, sizeof(buf));
1083 ret = pwnsprintfA(buf, 10, "%s", str1);
1084 ok(broken(ret == 9) || ret == -1 /* Vista */, "Unexpected wnsprintfA return %d, expected 9 or -1\n", ret);
1085 expect_eq(buf[9], 0, CHAR, "%x");
1086 expect_eq(buf[10], (CHAR)0xbf, CHAR, "%x");
1088 else
1089 win_skip("wnsprintfA() is not available\n");
1091 if (pwnsprintfW)
1093 memset(wbuf, 0xbf, sizeof(wbuf));
1094 ret = pwnsprintfW(wbuf, 10, fmt, wstr1);
1095 ok(broken(ret == 9) || ret == -1 /* Vista */, "Unexpected wnsprintfW return %d, expected 9 or -1\n", ret);
1096 expect_eq(wbuf[9], 0, WCHAR, "%x");
1097 expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
1099 else
1100 win_skip("wnsprintfW() is not available\n");
1103 static void test_StrStrA(void)
1105 static const char *deadbeefA = "DeAdBeEf";
1107 const struct
1109 const char *search;
1110 const char *expect;
1111 } StrStrA_cases[] =
1113 {"", NULL},
1114 {"DeAd", deadbeefA},
1115 {"dead", NULL},
1116 {"AdBe", deadbeefA + 2},
1117 {"adbe", NULL},
1118 {"BeEf", deadbeefA + 4},
1119 {"beef", NULL},
1122 LPSTR ret;
1123 int i;
1125 /* Tests crash on Win2k */
1126 if (0)
1128 ret = StrStrA(NULL, NULL);
1129 ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret);
1131 ret = StrStrA(NULL, "");
1132 ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret);
1134 ret = StrStrA("", NULL);
1135 ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret);
1138 ret = StrStrA("", "");
1139 ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret);
1141 for (i = 0; i < sizeof(StrStrA_cases)/sizeof(StrStrA_cases[0]); i++)
1143 ret = StrStrA(deadbeefA, StrStrA_cases[i].search);
1144 ok(ret == StrStrA_cases[i].expect,
1145 "[%d] Expected StrStrA to return %p, got %p\n",
1146 i, StrStrA_cases[i].expect, ret);
1150 static void test_StrStrW(void)
1152 static const WCHAR emptyW[] = {0};
1153 static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
1154 static const WCHAR deadW[] = {'D','e','A','d',0};
1155 static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
1156 static const WCHAR adbeW[] = {'A','d','B','e',0};
1157 static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
1158 static const WCHAR beefW[] = {'B','e','E','f',0};
1159 static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
1161 const struct
1163 const WCHAR *search;
1164 const WCHAR *expect;
1165 } StrStrW_cases[] =
1167 {emptyW, NULL},
1168 {deadW, deadbeefW},
1169 {dead_lowerW, NULL},
1170 {adbeW, deadbeefW + 2},
1171 {adbe_lowerW, NULL},
1172 {beefW, deadbeefW + 4},
1173 {beef_lowerW, NULL},
1176 LPWSTR ret;
1177 int i;
1179 /* Tests crash on Win2k */
1180 if (0)
1182 ret = StrStrW(NULL, NULL);
1183 ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
1185 ret = StrStrW(NULL, emptyW);
1186 ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
1188 ret = StrStrW(emptyW, NULL);
1189 ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
1192 ret = StrStrW(emptyW, emptyW);
1193 ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
1195 for (i = 0; i < sizeof(StrStrW_cases)/sizeof(StrStrW_cases[0]); i++)
1197 ret = StrStrW(deadbeefW, StrStrW_cases[i].search);
1198 ok(ret == StrStrW_cases[i].expect,
1199 "[%d] Expected StrStrW to return %p, got %p\n",
1200 i, StrStrW_cases[i].expect, ret);
1204 static void test_StrStrIA(void)
1206 static const char *deadbeefA = "DeAdBeEf";
1208 const struct
1210 const char *search;
1211 const char *expect;
1212 } StrStrIA_cases[] =
1214 {"", NULL},
1215 {"DeAd", deadbeefA},
1216 {"dead", deadbeefA},
1217 {"AdBe", deadbeefA + 2},
1218 {"adbe", deadbeefA + 2},
1219 {"BeEf", deadbeefA + 4},
1220 {"beef", deadbeefA + 4},
1221 {"cafe", NULL},
1224 LPSTR ret;
1225 int i;
1227 /* Tests crash on Win2k */
1228 if (0)
1230 ret = StrStrIA(NULL, NULL);
1231 ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret);
1233 ret = StrStrIA(NULL, "");
1234 ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret);
1236 ret = StrStrIA("", NULL);
1237 ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret);
1240 ret = StrStrIA("", "");
1241 ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret);
1243 for (i = 0; i < sizeof(StrStrIA_cases)/sizeof(StrStrIA_cases[0]); i++)
1245 ret = StrStrIA(deadbeefA, StrStrIA_cases[i].search);
1246 ok(ret == StrStrIA_cases[i].expect,
1247 "[%d] Expected StrStrIA to return %p, got %p\n",
1248 i, StrStrIA_cases[i].expect, ret);
1252 static void test_StrStrIW(void)
1254 static const WCHAR emptyW[] = {0};
1255 static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
1256 static const WCHAR deadW[] = {'D','e','A','d',0};
1257 static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
1258 static const WCHAR adbeW[] = {'A','d','B','e',0};
1259 static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
1260 static const WCHAR beefW[] = {'B','e','E','f',0};
1261 static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
1262 static const WCHAR cafeW[] = {'c','a','f','e',0};
1264 const struct
1266 const WCHAR *search;
1267 const WCHAR *expect;
1268 } StrStrIW_cases[] =
1270 {emptyW, NULL},
1271 {deadW, deadbeefW},
1272 {dead_lowerW, deadbeefW},
1273 {adbeW, deadbeefW + 2},
1274 {adbe_lowerW, deadbeefW + 2},
1275 {beefW, deadbeefW + 4},
1276 {beef_lowerW, deadbeefW + 4},
1277 {cafeW, NULL},
1280 LPWSTR ret;
1281 int i;
1283 /* Tests crash on Win2k */
1284 if (0)
1286 ret = StrStrIW(NULL, NULL);
1287 ok(!ret, "Expected StrStrIW to return NULL, got %p\n", ret);
1289 ret = StrStrIW(NULL, emptyW);
1290 ok(!ret, "Expected StrStrIW to return NULL, got %p\n", ret);
1292 ret = StrStrIW(emptyW, NULL);
1293 ok(!ret, "Expected StrStrIW to return NULL, got %p\n", ret);
1296 ret = StrStrIW(emptyW, emptyW);
1297 ok(!ret, "Expected StrStrIW to return NULL, got %p\n", ret);
1299 for (i = 0; i < sizeof(StrStrIW_cases)/sizeof(StrStrIW_cases[0]); i++)
1301 ret = StrStrIW(deadbeefW, StrStrIW_cases[i].search);
1302 ok(ret == StrStrIW_cases[i].expect,
1303 "[%d] Expected StrStrIW to return %p, got %p\n",
1304 i, StrStrIW_cases[i].expect, ret);
1308 static void test_StrStrNW(void)
1310 static const WCHAR emptyW[] = {0};
1311 static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
1312 static const WCHAR deadW[] = {'D','e','A','d',0};
1313 static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
1314 static const WCHAR adbeW[] = {'A','d','B','e',0};
1315 static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
1316 static const WCHAR beefW[] = {'B','e','E','f',0};
1317 static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
1319 const struct
1321 const WCHAR *search;
1322 const UINT count;
1323 const WCHAR *expect;
1324 } StrStrNW_cases[] =
1326 {emptyW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1327 {deadW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW},
1328 {dead_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1329 {adbeW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 2},
1330 {adbe_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1331 {beefW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 4},
1332 {beef_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1333 {beefW, 0, NULL},
1334 {beefW, 1, NULL},
1335 {beefW, 2, NULL},
1336 {beefW, 3, NULL},
1337 {beefW, 4, NULL},
1338 {beefW, 5, deadbeefW + 4},
1339 {beefW, 6, deadbeefW + 4},
1340 {beefW, 7, deadbeefW + 4},
1341 {beefW, 8, deadbeefW + 4},
1342 {beefW, 9, deadbeefW + 4},
1345 LPWSTR ret;
1346 UINT i;
1348 if (!pStrStrNW)
1350 win_skip("StrStrNW() is not available\n");
1351 return;
1354 ret = pStrStrNW(NULL, NULL, 0);
1355 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1357 ret = pStrStrNW(NULL, NULL, 10);
1358 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1360 ret = pStrStrNW(NULL, emptyW, 10);
1361 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1363 ret = pStrStrNW(emptyW, NULL, 10);
1364 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1366 ret = pStrStrNW(emptyW, emptyW, 10);
1367 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1369 for (i = 0; i < sizeof(StrStrNW_cases)/sizeof(StrStrNW_cases[0]); i++)
1371 ret = pStrStrNW(deadbeefW, StrStrNW_cases[i].search, StrStrNW_cases[i].count);
1372 ok(ret == StrStrNW_cases[i].expect,
1373 "[%d] Expected StrStrNW to return %p, got %p\n",
1374 i, StrStrNW_cases[i].expect, ret);
1377 /* StrStrNW accepts counts larger than the search string length but rejects
1378 * counts larger than around 2G. The limit seems to change based on the
1379 * caller executable itself. */
1380 ret = pStrStrNW(deadbeefW, beefW, 100);
1381 ok(ret == deadbeefW + 4, "Expected StrStrNW to return deadbeefW + 4, got %p\n", ret);
1383 if (0)
1385 ret = pStrStrNW(deadbeefW, beefW, ~0U);
1386 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1390 static void test_StrStrNIW(void)
1392 static const WCHAR emptyW[] = {0};
1393 static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
1394 static const WCHAR deadW[] = {'D','e','A','d',0};
1395 static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
1396 static const WCHAR adbeW[] = {'A','d','B','e',0};
1397 static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
1398 static const WCHAR beefW[] = {'B','e','E','f',0};
1399 static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
1400 static const WCHAR cafeW[] = {'c','a','f','e',0};
1402 const struct
1404 const WCHAR *search;
1405 const UINT count;
1406 const WCHAR *expect;
1407 } StrStrNIW_cases[] =
1409 {emptyW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1410 {deadW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW},
1411 {dead_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW},
1412 {adbeW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 2},
1413 {adbe_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 2},
1414 {beefW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 4},
1415 {beef_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 4},
1416 {cafeW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1417 {beefW, 0, NULL},
1418 {beefW, 1, NULL},
1419 {beefW, 2, NULL},
1420 {beefW, 3, NULL},
1421 {beefW, 4, NULL},
1422 {beefW, 5, deadbeefW + 4},
1423 {beefW, 6, deadbeefW + 4},
1424 {beefW, 7, deadbeefW + 4},
1425 {beefW, 8, deadbeefW + 4},
1426 {beefW, 9, deadbeefW + 4},
1427 {beef_lowerW, 0, NULL},
1428 {beef_lowerW, 1, NULL},
1429 {beef_lowerW, 2, NULL},
1430 {beef_lowerW, 3, NULL},
1431 {beef_lowerW, 4, NULL},
1432 {beef_lowerW, 5, deadbeefW + 4},
1433 {beef_lowerW, 6, deadbeefW + 4},
1434 {beef_lowerW, 7, deadbeefW + 4},
1435 {beef_lowerW, 8, deadbeefW + 4},
1436 {beef_lowerW, 9, deadbeefW + 4},
1439 LPWSTR ret;
1440 UINT i;
1442 if (!pStrStrNIW)
1444 win_skip("StrStrNIW() is not available\n");
1445 return;
1448 ret = pStrStrNIW(NULL, NULL, 0);
1449 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1451 ret = pStrStrNIW(NULL, NULL, 10);
1452 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1454 ret = pStrStrNIW(NULL, emptyW, 10);
1455 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1457 ret = pStrStrNIW(emptyW, NULL, 10);
1458 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1460 ret = pStrStrNIW(emptyW, emptyW, 10);
1461 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1463 for (i = 0; i < sizeof(StrStrNIW_cases)/sizeof(StrStrNIW_cases[0]); i++)
1465 ret = pStrStrNIW(deadbeefW, StrStrNIW_cases[i].search, StrStrNIW_cases[i].count);
1466 ok(ret == StrStrNIW_cases[i].expect,
1467 "[%d] Expected StrStrNIW to return %p, got %p\n",
1468 i, StrStrNIW_cases[i].expect, ret);
1471 /* StrStrNIW accepts counts larger than the search string length but rejects
1472 * counts larger than around 2G. The limit seems to change based on the
1473 * caller executable itself. */
1474 ret = pStrStrNIW(deadbeefW, beefW, 100);
1475 ok(ret == deadbeefW + 4, "Expected StrStrNIW to return deadbeefW + 4, got %p\n", ret);
1477 if (0)
1479 ret = pStrStrNIW(deadbeefW, beefW, ~0U);
1480 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1484 START_TEST(string)
1486 HMODULE hShlwapi;
1487 TCHAR thousandDelim[8];
1488 TCHAR decimalDelim[8];
1489 CoInitialize(0);
1491 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, thousandDelim, 8);
1492 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, decimalDelim, 8);
1494 hShlwapi = GetModuleHandleA("shlwapi");
1495 pChrCmpIA = (void *)GetProcAddress(hShlwapi, "ChrCmpIA");
1496 pChrCmpIW = (void *)GetProcAddress(hShlwapi, "ChrCmpIW");
1497 pIntlStrEqWorkerA = (void *)GetProcAddress(hShlwapi, "IntlStrEqWorkerA");
1498 pIntlStrEqWorkerW = (void *)GetProcAddress(hShlwapi, "IntlStrEqWorkerW");
1499 pSHAnsiToAnsi = (void *)GetProcAddress(hShlwapi, (LPSTR)345);
1500 pSHUnicodeToUnicode = (void *)GetProcAddress(hShlwapi, (LPSTR)346);
1501 pStrCatBuffA = (void *)GetProcAddress(hShlwapi, "StrCatBuffA");
1502 pStrCatBuffW = (void *)GetProcAddress(hShlwapi, "StrCatBuffW");
1503 pStrCpyNXA = (void *)GetProcAddress(hShlwapi, (LPSTR)399);
1504 pStrCpyNXW = (void *)GetProcAddress(hShlwapi, (LPSTR)400);
1505 pStrChrNW = (void *)GetProcAddress(hShlwapi, "StrChrNW");
1506 pStrFormatByteSize64A = (void *)GetProcAddress(hShlwapi, "StrFormatByteSize64A");
1507 pStrFormatKBSizeA = (void *)GetProcAddress(hShlwapi, "StrFormatKBSizeA");
1508 pStrFormatKBSizeW = (void *)GetProcAddress(hShlwapi, "StrFormatKBSizeW");
1509 pStrIsIntlEqualA = (void *)GetProcAddress(hShlwapi, "StrIsIntlEqualA");
1510 pStrIsIntlEqualW = (void *)GetProcAddress(hShlwapi, "StrIsIntlEqualW");
1511 pStrPBrkW = (void *)GetProcAddress(hShlwapi, "StrPBrkW");
1512 pStrRChrA = (void *)GetProcAddress(hShlwapi, "StrRChrA");
1513 pStrRetToBSTR = (void *)GetProcAddress(hShlwapi, "StrRetToBSTR");
1514 pStrRetToBufA = (void *)GetProcAddress(hShlwapi, "StrRetToBufA");
1515 pStrRetToBufW = (void *)GetProcAddress(hShlwapi, "StrRetToBufW");
1516 pStrStrNW = (void *)GetProcAddress(hShlwapi, "StrStrNW");
1517 pStrStrNIW = (void *)GetProcAddress(hShlwapi, "StrStrNIW");
1518 pwnsprintfA = (void *)GetProcAddress(hShlwapi, "wnsprintfA");
1519 pwnsprintfW = (void *)GetProcAddress(hShlwapi, "wnsprintfW");
1520 pStrToInt64ExA = (void *)GetProcAddress(hShlwapi, "StrToInt64ExA");
1521 pStrToInt64ExW = (void *)GetProcAddress(hShlwapi, "StrToInt64ExW");
1523 test_StrChrA();
1524 test_StrChrW();
1525 test_StrChrIA();
1526 test_StrChrIW();
1527 test_StrRChrA();
1528 test_StrRChrW();
1529 test_StrCpyW();
1530 test_StrChrNW();
1531 test_StrToIntA();
1532 test_StrToIntW();
1533 test_StrToIntExA();
1534 test_StrToIntExW();
1535 test_StrToInt64ExA();
1536 test_StrToInt64ExW();
1537 test_StrDupA();
1539 /* language-dependent test */
1540 if (is_lang_english() && is_locale_english())
1542 test_StrFormatByteSize64A();
1543 test_StrFormatKBSizeA();
1544 test_StrFormatKBSizeW();
1546 else
1547 skip("An English UI and locale is required for the StrFormat*Size tests\n");
1548 if (is_lang_english())
1549 test_StrFromTimeIntervalA();
1550 else
1551 skip("An English UI is required for the StrFromTimeInterval tests\n");
1553 test_StrCmpA();
1554 test_StrCmpW();
1555 test_StrRetToBSTR();
1556 test_StrCpyNXA();
1557 test_StrCpyNXW();
1558 test_StrRStrI();
1559 test_SHAnsiToAnsi();
1560 test_SHUnicodeToUnicode();
1561 test_StrXXX_overflows();
1562 test_StrStrA();
1563 test_StrStrW();
1564 test_StrStrIA();
1565 test_StrStrIW();
1566 test_StrStrNW();
1567 test_StrStrNIW();
1569 CoUninitialize();