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
22 #include "wine/test.h"
26 #define NO_SHLWAPI_REG
27 #define NO_SHLWAPI_PATH
28 #define NO_SHLWAPI_GDI
29 #define NO_SHLWAPI_STREAM
33 #define expect_eq(expr, val, type, fmt) do { \
35 ok(ret == val, "Unexpected value of '" #expr "': " #fmt " instead of " #val "\n", ret); \
38 #define expect_eq2(expr, val1, val2, type, fmt) do { \
40 ok(ret == val1 || ret == val2, "Unexpected value of '" #expr "': " #fmt " instead of " #val1 " or " #val2 "\n", ret); \
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++; }
77 /* StrToInt/StrToIntEx results */
78 typedef struct tagStrToIntResult
82 LONGLONG str_to_int64_ex;
83 LONGLONG str_to_int64_hex;
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 },
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 },
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 },
112 /* pStrFormatByteSize64/StrFormatKBSize results */
113 typedef struct tagStrFormatSizeResult
116 const char* byte_size_64;
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"},
142 /* StrFromTimeIntervalA/StrFromTimeIntervalW results */
143 typedef struct tagStrFromTimeIntervalResult
147 const char* time_interval;
148 } StrFromTimeIntervalResult;
151 static const StrFromTimeIntervalResult StrFromTimeInterval_results[] = {
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" },
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;
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
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)
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;
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)
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)
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;
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)
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;
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)
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;
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)
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;
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)
409 const StrFormatSizeResult* result = StrFormatSize_results;
414 MultiByteToWideChar(0,0,result->byte_size_64,-1,szSrc,sizeof(szSrc)/sizeof(WCHAR));
416 StrCpyW(szBuff, szSrc);
417 ok(!StrCmpW(szSrc, szBuff), "Copied string %s wrong\n", result->byte_size_64);
422 static void test_StrChrNW(void)
424 static WCHAR string[] = {'T','e','s','t','i','n','g',' ','S','t','r','i','n','g',0};
429 win_skip("StrChrNW not available\n");
433 p = pStrChrNW(string,'t',10);
434 ok(*p=='t',"Found wrong 't'\n");
435 ok(*(p+1)=='i',"next should be 'i'\n");
437 p = pStrChrNW(string,'S',10);
438 ok(*p=='S',"Found wrong 'S'\n");
440 p = pStrChrNW(string,'r',10);
441 ok(p==NULL,"Should not have found 'r'\n");
444 static void test_StrToIntA(void)
446 const StrToIntResult *result = StrToInt_results;
449 while (result->string)
451 return_val = StrToIntA(result->string);
452 ok(return_val == result->str_to_int, "converted '%s' wrong (%d)\n",
453 result->string, return_val);
458 static void test_StrToIntW(void)
461 const StrToIntResult *result = StrToInt_results;
464 while (result->string)
466 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
467 return_val = StrToIntW(szBuff);
468 ok(return_val == result->str_to_int, "converted '%s' wrong (%d)\n",
469 result->string, return_val);
474 static void test_StrToIntExA(void)
476 const StrToIntResult *result = StrToInt_results;
480 while (result->string)
483 bRet = StrToIntExA(result->string,0,&return_val);
484 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
487 ok(return_val == (int)result->str_to_int64_ex, "converted '%s' wrong (%d)\n",
488 result->string, return_val);
492 result = StrToInt_results;
493 while (result->string)
496 bRet = StrToIntExA(result->string,STIF_SUPPORT_HEX,&return_val);
497 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
500 ok(return_val == (int)result->str_to_int64_hex, "converted '%s' wrong (%d)\n",
501 result->string, return_val);
506 static void test_StrToIntExW(void)
509 const StrToIntResult *result = StrToInt_results;
513 while (result->string)
516 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
517 bRet = StrToIntExW(szBuff, 0, &return_val);
518 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
521 ok(return_val == (int)result->str_to_int64_ex, "converted '%s' wrong (%d)\n",
522 result->string, return_val);
526 result = StrToInt_results;
527 while (result->string)
530 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
531 bRet = StrToIntExW(szBuff, STIF_SUPPORT_HEX, &return_val);
532 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
535 ok(return_val == (int)result->str_to_int64_hex, "converted '%s' wrong (%d)\n",
536 result->string, return_val);
541 static void test_StrToInt64ExA(void)
543 const StrToIntResult *result = StrToInt_results;
549 win_skip("StrToInt64ExA() is not available\n");
553 while (result->string)
556 bRet = pStrToInt64ExA(result->string,0,&return_val);
557 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
560 ok(return_val == result->str_to_int64_ex, "converted '%s' wrong (%08x%08x)\n",
561 result->string, (DWORD)(return_val >> 32), (DWORD)return_val);
565 result = StrToInt_results;
566 while (result->string)
569 bRet = pStrToInt64ExA(result->string,STIF_SUPPORT_HEX,&return_val);
570 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
573 ok(return_val == result->str_to_int64_hex, "converted '%s' wrong (%08x%08x)\n",
574 result->string, (DWORD)(return_val >> 32), (DWORD)return_val);
579 static void test_StrToInt64ExW(void)
582 const StrToIntResult *result = StrToInt_results;
588 win_skip("StrToInt64ExW() is not available\n");
592 while (result->string)
595 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
596 bRet = pStrToInt64ExW(szBuff, 0, &return_val);
597 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
600 ok(return_val == result->str_to_int64_ex, "converted '%s' wrong (%08x%08x)\n",
601 result->string, (DWORD)(return_val >> 32), (DWORD)return_val);
605 result = StrToInt_results;
606 while (result->string)
609 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
610 bRet = pStrToInt64ExW(szBuff, STIF_SUPPORT_HEX, &return_val);
611 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
614 ok(return_val == result->str_to_int64_hex, "converted '%s' wrong (%08x%08x)\n",
615 result->string, (DWORD)(return_val >> 32), (DWORD)return_val);
620 static void test_StrDupA(void)
623 const StrFormatSizeResult* result = StrFormatSize_results;
627 lpszStr = StrDupA(result->byte_size_64);
629 ok(lpszStr != NULL, "Dup failed\n");
632 ok(!strcmp(result->byte_size_64, lpszStr), "Copied string wrong\n");
638 /* Later versions of shlwapi return NULL for this, but earlier versions
639 * returned an empty string (as Wine does).
641 lpszStr = StrDupA(NULL);
642 ok(lpszStr == NULL || *lpszStr == '\0', "NULL string returned %p\n", lpszStr);
646 static void test_StrFormatByteSize64A(void)
649 const StrFormatSizeResult* result = StrFormatSize_results;
651 if (!pStrFormatByteSize64A)
653 win_skip("StrFormatByteSize64A() is not available\n");
659 pStrFormatByteSize64A(result->value, szBuff, 256);
661 ok(!strcmp(result->byte_size_64, szBuff),
662 "Formatted %x%08x wrong: got %s, expected %s\n",
663 (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->byte_size_64);
669 static void test_StrFormatKBSizeW(void)
673 const StrFormatSizeResult* result = StrFormatSize_results;
675 if (!pStrFormatKBSizeW)
677 win_skip("StrFormatKBSizeW() is not available\n");
683 pStrFormatKBSizeW(result->value, szBuffW, 256);
684 WideCharToMultiByte(0,0,szBuffW,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR),0,0);
686 ok(!strcmp(result->kb_size, szBuff), "Formatted %x%08x wrong: got %s, expected %s\n",
687 (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->kb_size);
692 static void test_StrFormatKBSizeA(void)
695 const StrFormatSizeResult* result = StrFormatSize_results;
697 if (!pStrFormatKBSizeA)
699 win_skip("StrFormatKBSizeA() is not available\n");
705 pStrFormatKBSizeA(result->value, szBuff, 256);
707 /* shlwapi on Win98 SE does not appear to apply delimiters to the output
708 * and does not correctly handle extremely large values. */
709 ok(!strcmp(result->kb_size, szBuff) ||
710 (result->kb_size_broken && !strcmp(result->kb_size2, szBuff)),
711 "Formatted %x%08x wrong: got %s, expected %s\n",
712 (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->kb_size);
717 static void test_StrFromTimeIntervalA(void)
720 const StrFromTimeIntervalResult* result = StrFromTimeInterval_results;
724 StrFromTimeIntervalA(szBuff, 256, result->ms, result->digits);
726 ok(!strcmp(result->time_interval, szBuff), "Formatted %d %d wrong: %s\n",
727 result->ms, result->digits, szBuff);
732 static void test_StrCmpA(void)
734 static const char str1[] = {'a','b','c','d','e','f'};
735 static const char str2[] = {'a','B','c','d','e','f'};
736 ok(0 != StrCmpNA(str1, str2, 6), "StrCmpNA is case-insensitive\n");
737 ok(0 == StrCmpNIA(str1, str2, 6), "StrCmpNIA is case-sensitive\n");
739 ok(!pChrCmpIA('a', 'a'), "ChrCmpIA doesn't work at all!\n");
740 ok(!pChrCmpIA('b', 'B'), "ChrCmpIA is not case-insensitive\n");
741 ok(pChrCmpIA('a', 'z'), "ChrCmpIA believes that a == z!\n");
744 win_skip("ChrCmpIA() is not available\n");
746 if (pStrIsIntlEqualA)
748 ok(pStrIsIntlEqualA(FALSE, str1, str2, 5), "StrIsIntlEqualA(FALSE,...) isn't case-insensitive\n");
749 ok(!pStrIsIntlEqualA(TRUE, str1, str2, 5), "StrIsIntlEqualA(TRUE,...) isn't case-sensitive\n");
752 win_skip("StrIsIntlEqualA() is not available\n");
754 if (pIntlStrEqWorkerA)
756 ok(pIntlStrEqWorkerA(FALSE, str1, str2, 5), "IntlStrEqWorkerA(FALSE,...) isn't case-insensitive\n");
757 ok(!pIntlStrEqWorkerA(TRUE, str1, str2, 5), "pIntlStrEqWorkerA(TRUE,...) isn't case-sensitive\n");
760 win_skip("IntlStrEqWorkerA() is not available\n");
763 static void test_StrCmpW(void)
765 static const WCHAR str1[] = {'a','b','c','d','e','f'};
766 static const WCHAR str2[] = {'a','B','c','d','e','f'};
767 ok(0 != StrCmpNW(str1, str2, 5), "StrCmpNW is case-insensitive\n");
768 ok(0 == StrCmpNIW(str1, str2, 5), "StrCmpNIW is case-sensitive\n");
770 ok(!pChrCmpIW('a', 'a'), "ChrCmpIW doesn't work at all!\n");
771 ok(!pChrCmpIW('b', 'B'), "ChrCmpIW is not case-insensitive\n");
772 ok(pChrCmpIW('a', 'z'), "ChrCmpIW believes that a == z!\n");
775 win_skip("ChrCmpIW() is not available\n");
777 if (pStrIsIntlEqualW)
779 ok(pStrIsIntlEqualW(FALSE, str1, str2, 5), "StrIsIntlEqualW(FALSE,...) isn't case-insensitive\n");
780 ok(!pStrIsIntlEqualW(TRUE, str1, str2, 5), "StrIsIntlEqualW(TRUE,...) isn't case-sensitive\n");
783 win_skip("StrIsIntlEqualW() is not available\n");
785 if (pIntlStrEqWorkerW)
787 ok(pIntlStrEqWorkerW(FALSE, str1, str2, 5), "IntlStrEqWorkerW(FALSE,...) isn't case-insensitive\n");
788 ok(!pIntlStrEqWorkerW(TRUE, str1, str2, 5), "IntlStrEqWorkerW(TRUE,...) isn't case-sensitive\n");
791 win_skip("IntlStrEqWorkerW() is not available\n");
794 static WCHAR *CoDupStrW(const char* src)
796 INT len = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0);
797 WCHAR* szTemp = CoTaskMemAlloc(len * sizeof(WCHAR));
798 MultiByteToWideChar(CP_ACP, 0, src, -1, szTemp, len);
802 static void test_StrRetToBSTR(void)
804 static const WCHAR szTestW[] = { 'T','e','s','t','\0' };
812 win_skip("StrRetToBSTR() is not available\n");
816 strret.uType = STRRET_WSTR;
817 U(strret).pOleStr = CoDupStrW("Test");
819 ret = pStrRetToBSTR(&strret, NULL, &bstr);
820 ok(ret == S_OK && bstr && !strcmpW(bstr, szTestW),
821 "STRRET_WSTR: dup failed, ret=0x%08x, bstr %p\n", ret, bstr);
824 strret.uType = STRRET_CSTR;
825 lstrcpyA(U(strret).cStr, "Test");
826 ret = pStrRetToBSTR(&strret, NULL, &bstr);
827 ok(ret == S_OK && bstr && !strcmpW(bstr, szTestW),
828 "STRRET_CSTR: dup failed, ret=0x%08x, bstr %p\n", ret, bstr);
831 strret.uType = STRRET_OFFSET;
832 U(strret).uOffset = 1;
833 strcpy((char*)&iidl, " Test");
834 ret = pStrRetToBSTR(&strret, iidl, &bstr);
835 ok(ret == S_OK && bstr && !strcmpW(bstr, szTestW),
836 "STRRET_OFFSET: dup failed, ret=0x%08x, bstr %p\n", ret, bstr);
839 /* Native crashes if str is NULL */
842 static void test_StrCpyNXA(void)
844 LPCSTR lpSrc = "hello";
850 win_skip("StrCpyNXA() is not available\n");
854 memset(dest, '\n', sizeof(dest));
855 lpszRes = pStrCpyNXA(dest, lpSrc, sizeof(dest)/sizeof(dest[0]));
856 ok(lpszRes == dest + 5 && !memcmp(dest, "hello\0\n\n", sizeof(dest)),
857 "StrCpyNXA: expected %p, \"hello\\0\\n\\n\", got %p, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
858 dest + 5, lpszRes, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
861 static void test_StrCpyNXW(void)
863 static const WCHAR lpInit[] = { '\n','\n','\n','\n','\n','\n','\n','\n' };
864 static const WCHAR lpSrc[] = { 'h','e','l','l','o','\0' };
865 static const WCHAR lpRes[] = { 'h','e','l','l','o','\0','\n','\n' };
871 win_skip("StrCpyNXW() is not available\n");
875 memcpy(dest, lpInit, sizeof(lpInit));
876 lpszRes = pStrCpyNXW(dest, lpSrc, sizeof(dest)/sizeof(dest[0]));
877 ok(lpszRes == dest + 5 && !memcmp(dest, lpRes, sizeof(dest)),
878 "StrCpyNXW: expected %p, \"hello\\0\\n\\n\", got %p, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
879 dest + 5, lpszRes, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
882 #define check_strrstri(type, str, pos, needle, exp) \
883 ret##type = StrRStrI##type(str, str+pos, needle); \
884 ok(ret##type == (exp), "Type " #type ", expected %p but got %p (string base %p)\n", \
885 (exp), ret##type, str);
887 static void test_StrRStrI(void)
889 static const CHAR szTest[] = "yAxxxxAy";
890 static const CHAR szTest2[] = "ABABABAB";
891 static const WCHAR wszTest[] = {'y','A','x','x','x','x','A','y',0};
892 static const WCHAR wszTest2[] = {'A','B','A','B','A','B','A','B',0};
894 static const WCHAR wszPattern1[] = {'A',0};
895 static const WCHAR wszPattern2[] = {'a','X',0};
896 static const WCHAR wszPattern3[] = {'A','y',0};
897 static const WCHAR wszPattern4[] = {'a','b',0};
901 check_strrstri(A, szTest, 4, "A", szTest+1);
902 check_strrstri(A, szTest, 4, "aX", szTest+1);
903 check_strrstri(A, szTest, 4, "Ay", NULL);
904 check_strrstri(W, wszTest, 4, wszPattern1, wszTest+1);
905 check_strrstri(W, wszTest, 4, wszPattern2, wszTest+1);
906 check_strrstri(W, wszTest, 4, wszPattern3, NULL);
908 check_strrstri(A, szTest2, 4, "ab", szTest2+2);
909 check_strrstri(A, szTest2, 3, "ab", szTest2+2);
910 check_strrstri(A, szTest2, 2, "ab", szTest2);
911 check_strrstri(A, szTest2, 1, "ab", szTest2);
912 check_strrstri(A, szTest2, 0, "ab", NULL);
913 check_strrstri(W, wszTest2, 4, wszPattern4, wszTest2+2);
914 check_strrstri(W, wszTest2, 3, wszPattern4, wszTest2+2);
915 check_strrstri(W, wszTest2, 2, wszPattern4, wszTest2);
916 check_strrstri(W, wszTest2, 1, wszPattern4, wszTest2);
917 check_strrstri(W, wszTest2, 0, wszPattern4, NULL);
921 static void test_SHAnsiToAnsi(void)
928 win_skip("SHAnsiToAnsi() is not available\n");
932 if (pSHAnsiToAnsi == (void *)pStrPBrkW)
934 win_skip("Ordinal 345 corresponds to StrPBrkW, skipping SHAnsiToAnsi tests\n");
938 memset(dest, '\n', sizeof(dest));
939 dwRet = pSHAnsiToAnsi("hello", dest, sizeof(dest)/sizeof(dest[0]));
940 ok(dwRet == 6 && !memcmp(dest, "hello\0\n\n", sizeof(dest)),
941 "SHAnsiToAnsi: expected 6, \"hello\\0\\n\\n\", got %d, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
942 dwRet, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
945 static void test_SHUnicodeToUnicode(void)
947 static const WCHAR lpInit[] = { '\n','\n','\n','\n','\n','\n','\n','\n' };
948 static const WCHAR lpSrc[] = { 'h','e','l','l','o','\0' };
949 static const WCHAR lpRes[] = { 'h','e','l','l','o','\0','\n','\n' };
953 if (!pSHUnicodeToUnicode)
955 win_skip("SHUnicodeToUnicode() is not available\n");
959 if (pSHUnicodeToUnicode == (void *)pStrRChrA)
961 win_skip("Ordinal 346 corresponds to StrRChrA, skipping SHUnicodeToUnicode tests\n");
965 memcpy(dest, lpInit, sizeof(lpInit));
966 dwRet = pSHUnicodeToUnicode(lpSrc, dest, sizeof(dest)/sizeof(dest[0]));
967 ok(dwRet == 6 && !memcmp(dest, lpRes, sizeof(dest)),
968 "SHUnicodeToUnicode: expected 6, \"hello\\0\\n\\n\", got %d, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
969 dwRet, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
972 static void test_StrXXX_overflows(void)
974 CHAR str1[2*MAX_PATH+1], buf[2*MAX_PATH];
975 WCHAR wstr1[2*MAX_PATH+1], wbuf[2*MAX_PATH];
976 const WCHAR fmt[] = {'%','s',0};
981 for (i=0; i<2*MAX_PATH; i++)
983 str1[i] = '0'+(i%10);
984 wstr1[i] = '0'+(i%10);
986 str1[2*MAX_PATH] = 0;
987 wstr1[2*MAX_PATH] = 0;
989 memset(buf, 0xbf, sizeof(buf));
990 expect_eq(StrCpyNA(buf, str1, 10), buf, PCHAR, "%p");
991 expect_eq(buf[9], 0, CHAR, "%x");
992 expect_eq(buf[10], '\xbf', CHAR, "%x");
996 expect_eq(pStrCatBuffA(buf, str1, 100), buf, PCHAR, "%p");
997 expect_eq(buf[99], 0, CHAR, "%x");
998 expect_eq(buf[100], '\xbf', CHAR, "%x");
1001 win_skip("StrCatBuffA() is not available\n");
1006 StrCpyNW(wbuf, (LPCWSTR)0x1, 10);
1007 StrCpyNW((LPWSTR)0x1, wstr1, 10);
1010 memset(wbuf, 0xbf, sizeof(wbuf));
1011 expect_eq(StrCpyNW(wbuf, (LPCWSTR)0x1, 1), wbuf, PWCHAR, "%p");
1012 expect_eq(wbuf[0], 0, WCHAR, "%x");
1013 expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
1015 memset(wbuf, 0xbf, sizeof(wbuf));
1016 expect_eq(StrCpyNW(wbuf, 0, 10), wbuf, PWCHAR, "%p");
1017 expect_eq(wbuf[0], 0, WCHAR, "%x");
1018 expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
1020 memset(wbuf, 0xbf, sizeof(wbuf));
1021 expect_eq(StrCpyNW(wbuf, 0, 0), wbuf, PWCHAR, "%p");
1022 expect_eq(wbuf[0], (WCHAR)0xbfbf, WCHAR, "%x");
1023 expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
1025 memset(wbuf, 0xbf, sizeof(wbuf));
1026 expect_eq(StrCpyNW(wbuf, wstr1, 0), wbuf, PWCHAR, "%p");
1027 expect_eq(wbuf[0], (WCHAR)0xbfbf, WCHAR, "%x");
1028 expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
1030 memset(wbuf, 0xbf, sizeof(wbuf));
1031 expect_eq(StrCpyNW(wbuf, wstr1, 10), wbuf, PWCHAR, "%p");
1032 expect_eq(wbuf[9], 0, WCHAR, "%x");
1033 expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
1037 expect_eq(pStrCatBuffW(wbuf, wstr1, 100), wbuf, PWCHAR, "%p");
1038 expect_eq(wbuf[99], 0, WCHAR, "%x");
1039 expect_eq(wbuf[100], (WCHAR)0xbfbf, WCHAR, "%x");
1042 win_skip("StrCatBuffW() is not available\n");
1046 memset(wbuf, 0xbf, sizeof(wbuf));
1047 strret.uType = STRRET_WSTR;
1048 U(strret).pOleStr = StrDupW(wstr1);
1049 expect_eq2(pStrRetToBufW(&strret, NULL, wbuf, 10), S_OK, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) /* Vista */, HRESULT, "%x");
1050 expect_eq(wbuf[9], 0, WCHAR, "%x");
1051 expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
1054 win_skip("StrRetToBufW() is not available\n");
1058 memset(buf, 0xbf, sizeof(buf));
1059 strret.uType = STRRET_CSTR;
1060 StrCpyN(U(strret).cStr, str1, MAX_PATH);
1061 expect_eq2(pStrRetToBufA(&strret, NULL, buf, 10), S_OK, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) /* Vista */, HRESULT, "%x");
1062 expect_eq(buf[9], 0, CHAR, "%x");
1063 expect_eq(buf[10], (CHAR)0xbf, CHAR, "%x");
1066 win_skip("StrRetToBufA() is not available\n");
1070 memset(buf, 0xbf, sizeof(buf));
1071 ret = pwnsprintfA(buf, 10, "%s", str1);
1072 ok(broken(ret == 9) || ret == -1 /* Vista */, "Unexpected wnsprintfA return %d, expected 9 or -1\n", ret);
1073 expect_eq(buf[9], 0, CHAR, "%x");
1074 expect_eq(buf[10], (CHAR)0xbf, CHAR, "%x");
1077 win_skip("wnsprintfA() is not available\n");
1081 memset(wbuf, 0xbf, sizeof(wbuf));
1082 ret = pwnsprintfW(wbuf, 10, fmt, wstr1);
1083 ok(broken(ret == 9) || ret == -1 /* Vista */, "Unexpected wnsprintfW return %d, expected 9 or -1\n", ret);
1084 expect_eq(wbuf[9], 0, WCHAR, "%x");
1085 expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
1088 win_skip("wnsprintfW() is not available\n");
1091 static void test_StrStrA(void)
1093 static const char *deadbeefA = "DeAdBeEf";
1102 {"DeAd", deadbeefA},
1104 {"AdBe", deadbeefA + 2},
1106 {"BeEf", deadbeefA + 4},
1113 /* Tests crash on Win2k */
1116 ret = StrStrA(NULL, NULL);
1117 ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret);
1119 ret = StrStrA(NULL, "");
1120 ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret);
1122 ret = StrStrA("", NULL);
1123 ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret);
1126 ret = StrStrA("", "");
1127 ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret);
1129 for (i = 0; i < sizeof(StrStrA_cases)/sizeof(StrStrA_cases[0]); i++)
1131 ret = StrStrA(deadbeefA, StrStrA_cases[i].search);
1132 ok(ret == StrStrA_cases[i].expect,
1133 "[%d] Expected StrStrA to return %p, got %p\n",
1134 i, StrStrA_cases[i].expect, ret);
1138 static void test_StrStrW(void)
1140 static const WCHAR emptyW[] = {0};
1141 static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
1142 static const WCHAR deadW[] = {'D','e','A','d',0};
1143 static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
1144 static const WCHAR adbeW[] = {'A','d','B','e',0};
1145 static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
1146 static const WCHAR beefW[] = {'B','e','E','f',0};
1147 static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
1151 const WCHAR *search;
1152 const WCHAR *expect;
1157 {dead_lowerW, NULL},
1158 {adbeW, deadbeefW + 2},
1159 {adbe_lowerW, NULL},
1160 {beefW, deadbeefW + 4},
1161 {beef_lowerW, NULL},
1167 /* Tests crash on Win2k */
1170 ret = StrStrW(NULL, NULL);
1171 ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
1173 ret = StrStrW(NULL, emptyW);
1174 ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
1176 ret = StrStrW(emptyW, NULL);
1177 ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
1180 ret = StrStrW(emptyW, emptyW);
1181 ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
1183 for (i = 0; i < sizeof(StrStrW_cases)/sizeof(StrStrW_cases[0]); i++)
1185 ret = StrStrW(deadbeefW, StrStrW_cases[i].search);
1186 ok(ret == StrStrW_cases[i].expect,
1187 "[%d] Expected StrStrW to return %p, got %p\n",
1188 i, StrStrW_cases[i].expect, ret);
1192 static void test_StrStrIA(void)
1194 static const char *deadbeefA = "DeAdBeEf";
1200 } StrStrIA_cases[] =
1203 {"DeAd", deadbeefA},
1204 {"dead", deadbeefA},
1205 {"AdBe", deadbeefA + 2},
1206 {"adbe", deadbeefA + 2},
1207 {"BeEf", deadbeefA + 4},
1208 {"beef", deadbeefA + 4},
1215 /* Tests crash on Win2k */
1218 ret = StrStrIA(NULL, NULL);
1219 ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret);
1221 ret = StrStrIA(NULL, "");
1222 ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret);
1224 ret = StrStrIA("", NULL);
1225 ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret);
1228 ret = StrStrIA("", "");
1229 ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret);
1231 for (i = 0; i < sizeof(StrStrIA_cases)/sizeof(StrStrIA_cases[0]); i++)
1233 ret = StrStrIA(deadbeefA, StrStrIA_cases[i].search);
1234 ok(ret == StrStrIA_cases[i].expect,
1235 "[%d] Expected StrStrIA to return %p, got %p\n",
1236 i, StrStrIA_cases[i].expect, ret);
1240 static void test_StrStrIW(void)
1242 static const WCHAR emptyW[] = {0};
1243 static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
1244 static const WCHAR deadW[] = {'D','e','A','d',0};
1245 static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
1246 static const WCHAR adbeW[] = {'A','d','B','e',0};
1247 static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
1248 static const WCHAR beefW[] = {'B','e','E','f',0};
1249 static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
1250 static const WCHAR cafeW[] = {'c','a','f','e',0};
1254 const WCHAR *search;
1255 const WCHAR *expect;
1256 } StrStrIW_cases[] =
1260 {dead_lowerW, deadbeefW},
1261 {adbeW, deadbeefW + 2},
1262 {adbe_lowerW, deadbeefW + 2},
1263 {beefW, deadbeefW + 4},
1264 {beef_lowerW, deadbeefW + 4},
1271 /* Tests crash on Win2k */
1274 ret = StrStrIW(NULL, NULL);
1275 ok(!ret, "Expected StrStrIW to return NULL, got %p\n", ret);
1277 ret = StrStrIW(NULL, emptyW);
1278 ok(!ret, "Expected StrStrIW to return NULL, got %p\n", ret);
1280 ret = StrStrIW(emptyW, NULL);
1281 ok(!ret, "Expected StrStrIW to return NULL, got %p\n", ret);
1284 ret = StrStrIW(emptyW, emptyW);
1285 ok(!ret, "Expected StrStrIW to return NULL, got %p\n", ret);
1287 for (i = 0; i < sizeof(StrStrIW_cases)/sizeof(StrStrIW_cases[0]); i++)
1289 ret = StrStrIW(deadbeefW, StrStrIW_cases[i].search);
1290 ok(ret == StrStrIW_cases[i].expect,
1291 "[%d] Expected StrStrIW to return %p, got %p\n",
1292 i, StrStrIW_cases[i].expect, ret);
1296 static void test_StrStrNW(void)
1298 static const WCHAR emptyW[] = {0};
1299 static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
1300 static const WCHAR deadW[] = {'D','e','A','d',0};
1301 static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
1302 static const WCHAR adbeW[] = {'A','d','B','e',0};
1303 static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
1304 static const WCHAR beefW[] = {'B','e','E','f',0};
1305 static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
1309 const WCHAR *search;
1311 const WCHAR *expect;
1312 } StrStrNW_cases[] =
1314 {emptyW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1315 {deadW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW},
1316 {dead_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1317 {adbeW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 2},
1318 {adbe_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1319 {beefW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 4},
1320 {beef_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1326 {beefW, 5, deadbeefW + 4},
1327 {beefW, 6, deadbeefW + 4},
1328 {beefW, 7, deadbeefW + 4},
1329 {beefW, 8, deadbeefW + 4},
1330 {beefW, 9, deadbeefW + 4},
1338 win_skip("StrStrNW() is not available\n");
1342 ret = pStrStrNW(NULL, NULL, 0);
1343 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1345 ret = pStrStrNW(NULL, NULL, 10);
1346 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1348 ret = pStrStrNW(NULL, emptyW, 10);
1349 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1351 ret = pStrStrNW(emptyW, NULL, 10);
1352 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1354 ret = pStrStrNW(emptyW, emptyW, 10);
1355 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1357 for (i = 0; i < sizeof(StrStrNW_cases)/sizeof(StrStrNW_cases[0]); i++)
1359 ret = pStrStrNW(deadbeefW, StrStrNW_cases[i].search, StrStrNW_cases[i].count);
1360 ok(ret == StrStrNW_cases[i].expect,
1361 "[%d] Expected StrStrNW to return %p, got %p\n",
1362 i, StrStrNW_cases[i].expect, ret);
1365 /* StrStrNW accepts counts larger than the search string length but rejects
1366 * counts larger than around 2G. The limit seems to change based on the
1367 * caller executable itself. */
1368 ret = pStrStrNW(deadbeefW, beefW, 100);
1369 ok(ret == deadbeefW + 4, "Expected StrStrNW to return deadbeefW + 4, got %p\n", ret);
1373 ret = pStrStrNW(deadbeefW, beefW, ~0U);
1374 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1378 static void test_StrStrNIW(void)
1380 static const WCHAR emptyW[] = {0};
1381 static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
1382 static const WCHAR deadW[] = {'D','e','A','d',0};
1383 static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
1384 static const WCHAR adbeW[] = {'A','d','B','e',0};
1385 static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
1386 static const WCHAR beefW[] = {'B','e','E','f',0};
1387 static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
1388 static const WCHAR cafeW[] = {'c','a','f','e',0};
1392 const WCHAR *search;
1394 const WCHAR *expect;
1395 } StrStrNIW_cases[] =
1397 {emptyW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1398 {deadW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW},
1399 {dead_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW},
1400 {adbeW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 2},
1401 {adbe_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 2},
1402 {beefW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 4},
1403 {beef_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 4},
1404 {cafeW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1410 {beefW, 5, deadbeefW + 4},
1411 {beefW, 6, deadbeefW + 4},
1412 {beefW, 7, deadbeefW + 4},
1413 {beefW, 8, deadbeefW + 4},
1414 {beefW, 9, deadbeefW + 4},
1415 {beef_lowerW, 0, NULL},
1416 {beef_lowerW, 1, NULL},
1417 {beef_lowerW, 2, NULL},
1418 {beef_lowerW, 3, NULL},
1419 {beef_lowerW, 4, NULL},
1420 {beef_lowerW, 5, deadbeefW + 4},
1421 {beef_lowerW, 6, deadbeefW + 4},
1422 {beef_lowerW, 7, deadbeefW + 4},
1423 {beef_lowerW, 8, deadbeefW + 4},
1424 {beef_lowerW, 9, deadbeefW + 4},
1432 win_skip("StrStrNIW() is not available\n");
1436 ret = pStrStrNIW(NULL, NULL, 0);
1437 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1439 ret = pStrStrNIW(NULL, NULL, 10);
1440 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1442 ret = pStrStrNIW(NULL, emptyW, 10);
1443 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1445 ret = pStrStrNIW(emptyW, NULL, 10);
1446 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1448 ret = pStrStrNIW(emptyW, emptyW, 10);
1449 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1451 for (i = 0; i < sizeof(StrStrNIW_cases)/sizeof(StrStrNIW_cases[0]); i++)
1453 ret = pStrStrNIW(deadbeefW, StrStrNIW_cases[i].search, StrStrNIW_cases[i].count);
1454 ok(ret == StrStrNIW_cases[i].expect,
1455 "[%d] Expected StrStrNIW to return %p, got %p\n",
1456 i, StrStrNIW_cases[i].expect, ret);
1459 /* StrStrNIW accepts counts larger than the search string length but rejects
1460 * counts larger than around 2G. The limit seems to change based on the
1461 * caller executable itself. */
1462 ret = pStrStrNIW(deadbeefW, beefW, 100);
1463 ok(ret == deadbeefW + 4, "Expected StrStrNIW to return deadbeefW + 4, got %p\n", ret);
1467 ret = pStrStrNIW(deadbeefW, beefW, ~0U);
1468 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1475 TCHAR thousandDelim[8];
1476 TCHAR decimalDelim[8];
1479 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, thousandDelim, 8);
1480 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, decimalDelim, 8);
1482 hShlwapi = GetModuleHandleA("shlwapi");
1483 pChrCmpIA = (void *)GetProcAddress(hShlwapi, "ChrCmpIA");
1484 pChrCmpIW = (void *)GetProcAddress(hShlwapi, "ChrCmpIW");
1485 pIntlStrEqWorkerA = (void *)GetProcAddress(hShlwapi, "IntlStrEqWorkerA");
1486 pIntlStrEqWorkerW = (void *)GetProcAddress(hShlwapi, "IntlStrEqWorkerW");
1487 pSHAnsiToAnsi = (void *)GetProcAddress(hShlwapi, (LPSTR)345);
1488 pSHUnicodeToUnicode = (void *)GetProcAddress(hShlwapi, (LPSTR)346);
1489 pStrCatBuffA = (void *)GetProcAddress(hShlwapi, "StrCatBuffA");
1490 pStrCatBuffW = (void *)GetProcAddress(hShlwapi, "StrCatBuffW");
1491 pStrCpyNXA = (void *)GetProcAddress(hShlwapi, (LPSTR)399);
1492 pStrCpyNXW = (void *)GetProcAddress(hShlwapi, (LPSTR)400);
1493 pStrChrNW = (void *)GetProcAddress(hShlwapi, "StrChrNW");
1494 pStrFormatByteSize64A = (void *)GetProcAddress(hShlwapi, "StrFormatByteSize64A");
1495 pStrFormatKBSizeA = (void *)GetProcAddress(hShlwapi, "StrFormatKBSizeA");
1496 pStrFormatKBSizeW = (void *)GetProcAddress(hShlwapi, "StrFormatKBSizeW");
1497 pStrIsIntlEqualA = (void *)GetProcAddress(hShlwapi, "StrIsIntlEqualA");
1498 pStrIsIntlEqualW = (void *)GetProcAddress(hShlwapi, "StrIsIntlEqualW");
1499 pStrPBrkW = (void *)GetProcAddress(hShlwapi, "StrPBrkW");
1500 pStrRChrA = (void *)GetProcAddress(hShlwapi, "StrRChrA");
1501 pStrRetToBSTR = (void *)GetProcAddress(hShlwapi, "StrRetToBSTR");
1502 pStrRetToBufA = (void *)GetProcAddress(hShlwapi, "StrRetToBufA");
1503 pStrRetToBufW = (void *)GetProcAddress(hShlwapi, "StrRetToBufW");
1504 pStrStrNW = (void *)GetProcAddress(hShlwapi, "StrStrNW");
1505 pStrStrNIW = (void *)GetProcAddress(hShlwapi, "StrStrNIW");
1506 pwnsprintfA = (void *)GetProcAddress(hShlwapi, "wnsprintfA");
1507 pwnsprintfW = (void *)GetProcAddress(hShlwapi, "wnsprintfW");
1508 pStrToInt64ExA = (void *)GetProcAddress(hShlwapi, "StrToInt64ExA");
1509 pStrToInt64ExW = (void *)GetProcAddress(hShlwapi, "StrToInt64ExW");
1523 test_StrToInt64ExA();
1524 test_StrToInt64ExW();
1527 /* language-dependent test */
1528 if (is_lang_english() && is_locale_english())
1530 test_StrFormatByteSize64A();
1531 test_StrFormatKBSizeA();
1532 test_StrFormatKBSizeW();
1535 skip("An English UI and locale is required for the StrFormat*Size tests\n");
1536 if (is_lang_english())
1537 test_StrFromTimeIntervalA();
1539 skip("An English UI is required for the StrFromTimeInterval tests\n");
1543 test_StrRetToBSTR();
1547 test_SHAnsiToAnsi();
1548 test_SHUnicodeToUnicode();
1549 test_StrXXX_overflows();