Release 1.3.7.
[wine/gsoc-2012-control.git] / dlls / shlwapi / tests / string.c
blob00a446972daeeb0b0347050b2e06657f2743dc63
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);
69 static int strcmpW(const WCHAR *str1, const WCHAR *str2)
71 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
72 return *str1 - *str2;
75 /* StrToInt/StrToIntEx results */
76 typedef struct tagStrToIntResult
78 const char* string;
79 int str_to_int;
80 int str_to_int_ex;
81 int str_to_int_hex;
82 } StrToIntResult;
84 static const StrToIntResult StrToInt_results[] = {
85 { "1099", 1099, 1099, 1099 },
86 { "+88987", 0, 88987, 88987 },
87 { "012", 12, 12, 12 },
88 { "-55", -55, -55, -55 },
89 { "-0", 0, 0, 0 },
90 { "0x44ff", 0, 0, 0x44ff },
91 { "+0x44f4", 0, 0, 0x44f4 },
92 { "-0x44fd", 0, 0, 0x44fd },
93 { "+ 88987", 0, 0, 0 },
94 { "- 55", 0, 0, 0 },
95 { "- 0", 0, 0, 0 },
96 { "+ 0x44f4", 0, 0, 0 },
97 { "--0x44fd", 0, 0, 0 },
98 { " 1999", 0, 1999, 1999 },
99 { " +88987", 0, 88987, 88987 },
100 { " 012", 0, 12, 12 },
101 { " -55", 0, -55, -55 },
102 { " 0x44ff", 0, 0, 0x44ff },
103 { " +0x44f4", 0, 0, 0x44f4 },
104 { " -0x44fd", 0, 0, 0x44fd },
105 { NULL, 0, 0, 0 }
108 /* pStrFormatByteSize64/StrFormatKBSize results */
109 typedef struct tagStrFormatSizeResult
111 LONGLONG value;
112 const char* byte_size_64;
113 const char* kb_size;
114 int kb_size_broken;
115 const char* kb_size2;
116 } StrFormatSizeResult;
119 static const StrFormatSizeResult StrFormatSize_results[] = {
120 { -1023, "-1023 bytes", "0 KB"},
121 { -24, "-24 bytes", "0 KB"},
122 { 309, "309 bytes", "1 KB"},
123 { 10191, "9.95 KB", "10 KB"},
124 { 100353, "98.0 KB", "99 KB"},
125 { 1022286, "998 KB", "999 KB"},
126 { 1046862, "0.99 MB", "1,023 KB", 1, "1023 KB"},
127 { 1048574619, "999 MB", "1,023,999 KB", 1, "1023999 KB"},
128 { 1073741775, "0.99 GB", "1,048,576 KB", 1, "1048576 KB"},
129 { ((LONGLONG)0x000000f9 << 32) | 0xfffff94e, "999 GB", "1,048,575,999 KB", 1, "1048575999 KB"},
130 { ((LONGLONG)0x000000ff << 32) | 0xfffffa9b, "0.99 TB", "1,073,741,823 KB", 1, "1073741823 KB"},
131 { ((LONGLONG)0x0003e7ff << 32) | 0xfffffa9b, "999 TB", "1,073,741,823,999 KB", 1, "4294967295 KB"},
132 { ((LONGLONG)0x0003ffff << 32) | 0xfffffbe8, "0.99 PB", "1,099,511,627,775 KB", 1, "4294967295 KB"},
133 { ((LONGLONG)0x0f9fffff << 32) | 0xfffffd35, "999 PB", "1,099,511,627,776,000 KB", 1, "0 KB"},
134 { ((LONGLONG)0x0fffffff << 32) | 0xfffffa9b, "0.99 EB", "1,125,899,906,842,623 KB", 1, "4294967295 KB"},
135 { 0, NULL, NULL }
138 /* StrFormatByteSize64/StrFormatKBSize results */
139 typedef struct tagStrFromTimeIntervalResult
141 DWORD ms;
142 int digits;
143 const char* time_interval;
144 } StrFromTimeIntervalResult;
147 static const StrFromTimeIntervalResult StrFromTimeInterval_results[] = {
148 { 1, 1, " 0 sec" },
149 { 1, 2, " 0 sec" },
150 { 1, 3, " 0 sec" },
151 { 1, 4, " 0 sec" },
152 { 1, 5, " 0 sec" },
153 { 1, 6, " 0 sec" },
154 { 1, 7, " 0 sec" },
156 { 1000000, 1, " 10 min" },
157 { 1000000, 2, " 16 min" },
158 { 1000000, 3, " 16 min 40 sec" },
159 { 1000000, 4, " 16 min 40 sec" },
160 { 1000000, 5, " 16 min 40 sec" },
161 { 1000000, 6, " 16 min 40 sec" },
162 { 1000000, 7, " 16 min 40 sec" },
164 { 1999999, 1, " 30 min" },
165 { 1999999, 2, " 33 min" },
166 { 1999999, 3, " 33 min 20 sec" },
167 { 1999999, 4, " 33 min 20 sec" },
168 { 1999999, 5, " 33 min 20 sec" },
169 { 1999999, 6, " 33 min 20 sec" },
170 { 1999999, 7, " 33 min 20 sec" },
172 { 3999997, 1, " 1 hr" },
173 { 3999997, 2, " 1 hr 6 min" },
174 { 3999997, 3, " 1 hr 6 min 40 sec" },
175 { 3999997, 4, " 1 hr 6 min 40 sec" },
176 { 3999997, 5, " 1 hr 6 min 40 sec" },
177 { 3999997, 6, " 1 hr 6 min 40 sec" },
178 { 3999997, 7, " 1 hr 6 min 40 sec" },
180 { 149999851, 7, " 41 hr 40 min 0 sec" },
181 { 150999850, 1, " 40 hr" },
182 { 150999850, 2, " 41 hr" },
183 { 150999850, 3, " 41 hr 50 min" },
184 { 150999850, 4, " 41 hr 56 min" },
185 { 150999850, 5, " 41 hr 56 min 40 sec" },
186 { 150999850, 6, " 41 hr 56 min 40 sec" },
187 { 150999850, 7, " 41 hr 56 min 40 sec" },
189 { 493999507, 1, " 100 hr" },
190 { 493999507, 2, " 130 hr" },
191 { 493999507, 3, " 137 hr" },
192 { 493999507, 4, " 137 hr 10 min" },
193 { 493999507, 5, " 137 hr 13 min" },
194 { 493999507, 6, " 137 hr 13 min 20 sec" },
195 { 493999507, 7, " 137 hr 13 min 20 sec" },
197 { 0, 0, NULL }
200 static void test_StrChrA(void)
202 char string[129];
203 WORD count;
205 /* this test crashes on win2k SP4 */
206 /*ok(!StrChrA(NULL,'\0'), "found a character in a NULL string!\n");*/
208 for (count = 32; count < 128; count++)
209 string[count] = (char)count;
210 string[128] = '\0';
212 for (count = 32; count < 128; count++)
214 LPSTR result = StrChrA(string+32, count);
215 INT pos = result - string;
216 ok(pos == count, "found char '%c' in wrong place: got %d, expected %d\n", count, pos, count);
219 for (count = 32; count < 128; count++)
221 LPSTR result = StrChrA(string+count+1, count);
222 ok(!result, "found char '%c' not in the string\n", count);
226 static void test_StrChrW(void)
228 WCHAR string[16385];
229 WORD count;
231 /* this test crashes on win2k SP4 */
232 /*ok(!StrChrW(NULL,'\0'), "found a character in a NULL string!\n");*/
234 for (count = 32; count < 16384; count++)
235 string[count] = count;
236 string[16384] = '\0';
238 for (count = 32; count < 16384; count++)
240 LPWSTR result = StrChrW(string+32, count);
241 ok((result - string) == count, "found char %d in wrong place\n", count);
244 for (count = 32; count < 16384; count++)
246 LPWSTR result = StrChrW(string+count+1, count);
247 ok(!result, "found char not in the string\n");
251 static void test_StrChrIA(void)
253 char string[129];
254 WORD count;
256 /* this test crashes on win2k SP4 */
257 /*ok(!StrChrIA(NULL,'\0'), "found a character in a NULL string!\n");*/
259 for (count = 32; count < 128; count++)
260 string[count] = (char)count;
261 string[128] = '\0';
263 for (count = 'A'; count <= 'X'; count++)
265 LPSTR result = StrChrIA(string+32, count);
267 ok(result - string == count, "found char '%c' in wrong place\n", count);
268 ok(StrChrIA(result, count)!=NULL, "didn't find lowercase '%c'\n", count);
271 for (count = 'a'; count < 'z'; count++)
273 LPSTR result = StrChrIA(string+count+1, count);
274 ok(!result, "found char not in the string\n");
278 static void test_StrChrIW(void)
280 WCHAR string[129];
281 WORD count;
283 /* this test crashes on win2k SP4 */
284 /*ok(!StrChrIA(NULL,'\0'), "found a character in a NULL string!\n");*/
286 for (count = 32; count < 128; count++)
287 string[count] = count;
288 string[128] = '\0';
290 for (count = 'A'; count <= 'X'; count++)
292 LPWSTR result = StrChrIW(string+32, count);
294 ok(result - string == count, "found char '%c' in wrong place\n", count);
295 ok(StrChrIW(result, count)!=NULL, "didn't find lowercase '%c'\n", count);
298 for (count = 'a'; count < 'z'; count++)
300 LPWSTR result = StrChrIW(string+count+1, count);
301 ok(!result, "found char not in the string\n");
305 static void test_StrRChrA(void)
307 char string[129];
308 WORD count;
310 /* this test crashes on win2k SP4 */
311 /*ok(!StrRChrA(NULL, NULL,'\0'), "found a character in a NULL string!\n");*/
313 for (count = 32; count < 128; count++)
314 string[count] = (char)count;
315 string[128] = '\0';
317 for (count = 32; count < 128; count++)
319 LPSTR result = StrRChrA(string+32, NULL, count);
320 ok(result - string == count, "found char %d in wrong place\n", count);
323 for (count = 32; count < 128; count++)
325 LPSTR result = StrRChrA(string+count+1, NULL, count);
326 ok(!result, "found char not in the string\n");
329 for (count = 32; count < 128; count++)
331 LPSTR result = StrRChrA(string+count+1, string + 127, count);
332 ok(!result, "found char not in the string\n");
336 static void test_StrRChrW(void)
338 WCHAR string[129];
339 WORD count;
341 /* this test crashes on win2k SP4 */
342 /*ok(!StrRChrW(NULL, NULL,'\0'), "found a character in a NULL string!\n");*/
344 for (count = 32; count < 128; count++)
345 string[count] = count;
346 string[128] = '\0';
348 for (count = 32; count < 128; count++)
350 LPWSTR result = StrRChrW(string+32, NULL, count);
351 INT pos = result - string;
352 ok(pos == count, "found char %d in wrong place: got %d, expected %d\n", count, pos, count);
355 for (count = 32; count < 128; count++)
357 LPWSTR result = StrRChrW(string+count+1, NULL, count);
358 ok(!result, "found char %d not in the string\n", count);
361 for (count = 32; count < 128; count++)
363 LPWSTR result = StrRChrW(string+count+1, string + 127, count);
364 ok(!result, "found char %d not in the string\n", count);
368 static void test_StrCpyW(void)
370 WCHAR szSrc[256];
371 WCHAR szBuff[256];
372 const StrFormatSizeResult* result = StrFormatSize_results;
375 while(result->value)
377 MultiByteToWideChar(0,0,result->byte_size_64,-1,szSrc,sizeof(szSrc)/sizeof(WCHAR));
379 StrCpyW(szBuff, szSrc);
380 ok(!StrCmpW(szSrc, szBuff), "Copied string %s wrong\n", result->byte_size_64);
381 result++;
385 static void test_StrChrNW(void)
387 static WCHAR string[] = {'T','e','s','t','i','n','g',' ','S','t','r','i','n','g',0};
388 LPWSTR p;
390 if (!pStrChrNW)
392 win_skip("StrChrNW not available\n");
393 return;
396 p = pStrChrNW(string,'t',10);
397 ok(*p=='t',"Found wrong 't'\n");
398 ok(*(p+1)=='i',"next should be 'i'\n");
400 p = pStrChrNW(string,'S',10);
401 ok(*p=='S',"Found wrong 'S'\n");
403 p = pStrChrNW(string,'r',10);
404 ok(p==NULL,"Should not have found 'r'\n");
407 static void test_StrToIntA(void)
409 const StrToIntResult *result = StrToInt_results;
410 int return_val;
412 while (result->string)
414 return_val = StrToIntA(result->string);
415 ok(return_val == result->str_to_int, "converted '%s' wrong (%d)\n",
416 result->string, return_val);
417 result++;
421 static void test_StrToIntW(void)
423 WCHAR szBuff[256];
424 const StrToIntResult *result = StrToInt_results;
425 int return_val;
427 while (result->string)
429 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
430 return_val = StrToIntW(szBuff);
431 ok(return_val == result->str_to_int, "converted '%s' wrong (%d)\n",
432 result->string, return_val);
433 result++;
437 static void test_StrToIntExA(void)
439 const StrToIntResult *result = StrToInt_results;
440 int return_val;
441 BOOL bRet;
443 while (result->string)
445 return_val = -1;
446 bRet = StrToIntExA(result->string,0,&return_val);
447 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
448 result->string);
449 if (bRet)
450 ok(return_val == result->str_to_int_ex, "converted '%s' wrong (%d)\n",
451 result->string, return_val);
452 result++;
455 result = StrToInt_results;
456 while (result->string)
458 return_val = -1;
459 bRet = StrToIntExA(result->string,STIF_SUPPORT_HEX,&return_val);
460 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
461 result->string);
462 if (bRet)
463 ok(return_val == result->str_to_int_hex, "converted '%s' wrong (%d)\n",
464 result->string, return_val);
465 result++;
469 static void test_StrToIntExW(void)
471 WCHAR szBuff[256];
472 const StrToIntResult *result = StrToInt_results;
473 int return_val;
474 BOOL bRet;
476 while (result->string)
478 return_val = -1;
479 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
480 bRet = StrToIntExW(szBuff, 0, &return_val);
481 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
482 result->string);
483 if (bRet)
484 ok(return_val == result->str_to_int_ex, "converted '%s' wrong (%d)\n",
485 result->string, return_val);
486 result++;
489 result = StrToInt_results;
490 while (result->string)
492 return_val = -1;
493 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
494 bRet = StrToIntExW(szBuff, STIF_SUPPORT_HEX, &return_val);
495 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
496 result->string);
497 if (bRet)
498 ok(return_val == result->str_to_int_hex, "converted '%s' wrong (%d)\n",
499 result->string, return_val);
500 result++;
504 static void test_StrDupA(void)
506 LPSTR lpszStr;
507 const StrFormatSizeResult* result = StrFormatSize_results;
509 while(result->value)
511 lpszStr = StrDupA(result->byte_size_64);
513 ok(lpszStr != NULL, "Dup failed\n");
514 if (lpszStr)
516 ok(!strcmp(result->byte_size_64, lpszStr), "Copied string wrong\n");
517 LocalFree(lpszStr);
519 result++;
522 /* Later versions of shlwapi return NULL for this, but earlier versions
523 * returned an empty string (as Wine does).
525 lpszStr = StrDupA(NULL);
526 ok(lpszStr == NULL || *lpszStr == '\0', "NULL string returned %p\n", lpszStr);
527 LocalFree(lpszStr);
530 static void test_StrFormatByteSize64A(void)
532 char szBuff[256];
533 const StrFormatSizeResult* result = StrFormatSize_results;
535 if (!pStrFormatByteSize64A)
537 win_skip("StrFormatByteSize64A() is not available\n");
538 return;
541 while(result->value)
543 pStrFormatByteSize64A(result->value, szBuff, 256);
545 ok(!strcmp(result->byte_size_64, szBuff),
546 "Formatted %x%08x wrong: got %s, expected %s\n",
547 (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->byte_size_64);
549 result++;
553 static void test_StrFormatKBSizeW(void)
555 WCHAR szBuffW[256];
556 char szBuff[256];
557 const StrFormatSizeResult* result = StrFormatSize_results;
559 if (!pStrFormatKBSizeW)
561 win_skip("StrFormatKBSizeW() is not available\n");
562 return;
565 while(result->value)
567 pStrFormatKBSizeW(result->value, szBuffW, 256);
568 WideCharToMultiByte(0,0,szBuffW,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR),0,0);
570 /* shlwapi on Win98 SE does not appear to apply delimiters to the output
571 * and does not correctly handle extremely large values. */
572 ok(!strcmp(result->kb_size, szBuff) ||
573 (result->kb_size_broken && !strcmp(result->kb_size2, szBuff)),
574 "Formatted %x%08x wrong: got %s, expected %s\n",
575 (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->kb_size);
576 result++;
580 static void test_StrFormatKBSizeA(void)
582 char szBuff[256];
583 const StrFormatSizeResult* result = StrFormatSize_results;
585 if (!pStrFormatKBSizeA)
587 win_skip("StrFormatKBSizeA() is not available\n");
588 return;
591 while(result->value)
593 pStrFormatKBSizeA(result->value, szBuff, 256);
595 /* shlwapi on Win98 SE does not appear to apply delimiters to the output
596 * and does not correctly handle extremely large values. */
597 ok(!strcmp(result->kb_size, szBuff) ||
598 (result->kb_size_broken && !strcmp(result->kb_size2, szBuff)),
599 "Formatted %x%08x wrong: got %s, expected %s\n",
600 (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->kb_size);
601 result++;
605 static void test_StrFromTimeIntervalA(void)
607 char szBuff[256];
608 const StrFromTimeIntervalResult* result = StrFromTimeInterval_results;
610 while(result->ms)
612 StrFromTimeIntervalA(szBuff, 256, result->ms, result->digits);
614 ok(!strcmp(result->time_interval, szBuff), "Formatted %d %d wrong\n",
615 result->ms, result->digits);
616 result++;
620 static void test_StrCmpA(void)
622 static const char str1[] = {'a','b','c','d','e','f'};
623 static const char str2[] = {'a','B','c','d','e','f'};
624 ok(0 != StrCmpNA(str1, str2, 6), "StrCmpNA is case-insensitive\n");
625 ok(0 == StrCmpNIA(str1, str2, 6), "StrCmpNIA is case-sensitive\n");
626 if (pChrCmpIA) {
627 ok(!pChrCmpIA('a', 'a'), "ChrCmpIA doesn't work at all!\n");
628 ok(!pChrCmpIA('b', 'B'), "ChrCmpIA is not case-insensitive\n");
629 ok(pChrCmpIA('a', 'z'), "ChrCmpIA believes that a == z!\n");
631 else
632 win_skip("ChrCmpIA() is not available\n");
634 if (pStrIsIntlEqualA)
636 ok(pStrIsIntlEqualA(FALSE, str1, str2, 5), "StrIsIntlEqualA(FALSE,...) isn't case-insensitive\n");
637 ok(!pStrIsIntlEqualA(TRUE, str1, str2, 5), "StrIsIntlEqualA(TRUE,...) isn't case-sensitive\n");
639 else
640 win_skip("StrIsIntlEqualA() is not available\n");
642 if (pIntlStrEqWorkerA)
644 ok(pIntlStrEqWorkerA(FALSE, str1, str2, 5), "IntlStrEqWorkerA(FALSE,...) isn't case-insensitive\n");
645 ok(!pIntlStrEqWorkerA(TRUE, str1, str2, 5), "pIntlStrEqWorkerA(TRUE,...) isn't case-sensitive\n");
647 else
648 win_skip("IntlStrEqWorkerA() is not available\n");
651 static void test_StrCmpW(void)
653 static const WCHAR str1[] = {'a','b','c','d','e','f'};
654 static const WCHAR str2[] = {'a','B','c','d','e','f'};
655 ok(0 != StrCmpNW(str1, str2, 5), "StrCmpNW is case-insensitive\n");
656 ok(0 == StrCmpNIW(str1, str2, 5), "StrCmpNIW is case-sensitive\n");
657 if (pChrCmpIW) {
658 ok(!pChrCmpIW('a', 'a'), "ChrCmpIW doesn't work at all!\n");
659 ok(!pChrCmpIW('b', 'B'), "ChrCmpIW is not case-insensitive\n");
660 ok(pChrCmpIW('a', 'z'), "ChrCmpIW believes that a == z!\n");
662 else
663 win_skip("ChrCmpIW() is not available\n");
665 if (pStrIsIntlEqualW)
667 ok(pStrIsIntlEqualW(FALSE, str1, str2, 5), "StrIsIntlEqualW(FALSE,...) isn't case-insensitive\n");
668 ok(!pStrIsIntlEqualW(TRUE, str1, str2, 5), "StrIsIntlEqualW(TRUE,...) isn't case-sensitive\n");
670 else
671 win_skip("StrIsIntlEqualW() is not available\n");
673 if (pIntlStrEqWorkerW)
675 ok(pIntlStrEqWorkerW(FALSE, str1, str2, 5), "IntlStrEqWorkerW(FALSE,...) isn't case-insensitive\n");
676 ok(!pIntlStrEqWorkerW(TRUE, str1, str2, 5), "IntlStrEqWorkerW(TRUE,...) isn't case-sensitive\n");
678 else
679 win_skip("IntlStrEqWorkerW() is not available\n");
682 static WCHAR *CoDupStrW(const char* src)
684 INT len = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0);
685 WCHAR* szTemp = CoTaskMemAlloc(len * sizeof(WCHAR));
686 MultiByteToWideChar(CP_ACP, 0, src, -1, szTemp, len);
687 return szTemp;
690 static void test_StrRetToBSTR(void)
692 static const WCHAR szTestW[] = { 'T','e','s','t','\0' };
693 ITEMIDLIST iidl[10];
694 BSTR bstr;
695 STRRET strret;
696 HRESULT ret;
698 if (!pStrRetToBSTR)
700 win_skip("StrRetToBSTR() is not available\n");
701 return;
704 strret.uType = STRRET_WSTR;
705 U(strret).pOleStr = CoDupStrW("Test");
706 bstr = 0;
707 ret = pStrRetToBSTR(&strret, NULL, &bstr);
708 ok(ret == S_OK && bstr && !strcmpW(bstr, szTestW),
709 "STRRET_WSTR: dup failed, ret=0x%08x, bstr %p\n", ret, bstr);
710 SysFreeString(bstr);
712 strret.uType = STRRET_CSTR;
713 lstrcpyA(U(strret).cStr, "Test");
714 ret = pStrRetToBSTR(&strret, NULL, &bstr);
715 ok(ret == S_OK && bstr && !strcmpW(bstr, szTestW),
716 "STRRET_CSTR: dup failed, ret=0x%08x, bstr %p\n", ret, bstr);
717 SysFreeString(bstr);
719 strret.uType = STRRET_OFFSET;
720 U(strret).uOffset = 1;
721 strcpy((char*)&iidl, " Test");
722 ret = pStrRetToBSTR(&strret, iidl, &bstr);
723 ok(ret == S_OK && bstr && !strcmpW(bstr, szTestW),
724 "STRRET_OFFSET: dup failed, ret=0x%08x, bstr %p\n", ret, bstr);
725 SysFreeString(bstr);
727 /* Native crashes if str is NULL */
730 static void test_StrCpyNXA(void)
732 LPCSTR lpSrc = "hello";
733 LPSTR lpszRes;
734 char dest[8];
736 if (!pStrCpyNXA)
738 win_skip("StrCpyNXA() is not available\n");
739 return;
742 memset(dest, '\n', sizeof(dest));
743 lpszRes = pStrCpyNXA(dest, lpSrc, sizeof(dest)/sizeof(dest[0]));
744 ok(lpszRes == dest + 5 && !memcmp(dest, "hello\0\n\n", sizeof(dest)),
745 "StrCpyNXA: expected %p, \"hello\\0\\n\\n\", got %p, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
746 dest + 5, lpszRes, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
749 static void test_StrCpyNXW(void)
751 static const WCHAR lpInit[] = { '\n','\n','\n','\n','\n','\n','\n','\n' };
752 static const WCHAR lpSrc[] = { 'h','e','l','l','o','\0' };
753 static const WCHAR lpRes[] = { 'h','e','l','l','o','\0','\n','\n' };
754 LPWSTR lpszRes;
755 WCHAR dest[8];
757 if (!pStrCpyNXW)
759 win_skip("StrCpyNXW() is not available\n");
760 return;
763 memcpy(dest, lpInit, sizeof(lpInit));
764 lpszRes = pStrCpyNXW(dest, lpSrc, sizeof(dest)/sizeof(dest[0]));
765 ok(lpszRes == dest + 5 && !memcmp(dest, lpRes, sizeof(dest)),
766 "StrCpyNXW: expected %p, \"hello\\0\\n\\n\", got %p, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
767 dest + 5, lpszRes, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
770 #define check_strrstri(type, str, pos, needle, exp) \
771 ret##type = StrRStrI##type(str, str+pos, needle); \
772 ok(ret##type == (exp), "Type " #type ", expected %p but got %p (string base %p)\n", \
773 (exp), ret##type, str);
775 static void test_StrRStrI(void)
777 static const CHAR szTest[] = "yAxxxxAy";
778 static const CHAR szTest2[] = "ABABABAB";
779 static const WCHAR wszTest[] = {'y','A','x','x','x','x','A','y',0};
780 static const WCHAR wszTest2[] = {'A','B','A','B','A','B','A','B',0};
782 static const WCHAR wszPattern1[] = {'A',0};
783 static const WCHAR wszPattern2[] = {'a','X',0};
784 static const WCHAR wszPattern3[] = {'A','y',0};
785 static const WCHAR wszPattern4[] = {'a','b',0};
786 LPWSTR retW;
787 LPSTR retA;
789 /* StrCpyNXA was chosen simply because it doesn't appear to be available on
790 * Win9x machines where StrRStrI crashes. Despite StrRStrI being exported
791 * by name, all StrRStrI tests appear to crash for unknown reasons. */
792 if (!pStrCpyNXA)
794 win_skip("StrRStrI crashes on older Win9x platforms\n");
795 return;
798 check_strrstri(A, szTest, 4, "A", szTest+1);
799 check_strrstri(A, szTest, 4, "aX", szTest+1);
800 check_strrstri(A, szTest, 4, "Ay", NULL);
801 check_strrstri(W, wszTest, 4, wszPattern1, wszTest+1);
802 check_strrstri(W, wszTest, 4, wszPattern2, wszTest+1);
803 check_strrstri(W, wszTest, 4, wszPattern3, NULL);
805 check_strrstri(A, szTest2, 4, "ab", szTest2+2);
806 check_strrstri(A, szTest2, 3, "ab", szTest2+2);
807 check_strrstri(A, szTest2, 2, "ab", szTest2);
808 check_strrstri(A, szTest2, 1, "ab", szTest2);
809 check_strrstri(A, szTest2, 0, "ab", NULL);
810 check_strrstri(W, wszTest2, 4, wszPattern4, wszTest2+2);
811 check_strrstri(W, wszTest2, 3, wszPattern4, wszTest2+2);
812 check_strrstri(W, wszTest2, 2, wszPattern4, wszTest2);
813 check_strrstri(W, wszTest2, 1, wszPattern4, wszTest2);
814 check_strrstri(W, wszTest2, 0, wszPattern4, NULL);
818 static void test_SHAnsiToAnsi(void)
820 char dest[8];
821 DWORD dwRet;
823 if (!pSHAnsiToAnsi)
825 win_skip("SHAnsiToAnsi() is not available\n");
826 return;
829 if (pSHAnsiToAnsi == (void *)pStrPBrkW)
831 win_skip("Ordinal 345 corresponds to StrPBrkW, skipping SHAnsiToAnsi tests\n");
832 return;
835 memset(dest, '\n', sizeof(dest));
836 dwRet = pSHAnsiToAnsi("hello", dest, sizeof(dest)/sizeof(dest[0]));
837 ok(dwRet == 6 && !memcmp(dest, "hello\0\n\n", sizeof(dest)),
838 "SHAnsiToAnsi: expected 6, \"hello\\0\\n\\n\", got %d, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
839 dwRet, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
842 static void test_SHUnicodeToUnicode(void)
844 static const WCHAR lpInit[] = { '\n','\n','\n','\n','\n','\n','\n','\n' };
845 static const WCHAR lpSrc[] = { 'h','e','l','l','o','\0' };
846 static const WCHAR lpRes[] = { 'h','e','l','l','o','\0','\n','\n' };
847 WCHAR dest[8];
848 DWORD dwRet;
850 if (!pSHUnicodeToUnicode)
852 win_skip("SHUnicodeToUnicode() is not available\n");
853 return;
856 if (pSHUnicodeToUnicode == (void *)pStrRChrA)
858 win_skip("Ordinal 346 corresponds to StrRChrA, skipping SHUnicodeToUnicode tests\n");
859 return;
862 memcpy(dest, lpInit, sizeof(lpInit));
863 dwRet = pSHUnicodeToUnicode(lpSrc, dest, sizeof(dest)/sizeof(dest[0]));
864 ok(dwRet == 6 && !memcmp(dest, lpRes, sizeof(dest)),
865 "SHUnicodeToUnicode: expected 6, \"hello\\0\\n\\n\", got %d, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
866 dwRet, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
869 static void test_StrXXX_overflows(void)
871 CHAR str1[2*MAX_PATH+1], buf[2*MAX_PATH];
872 WCHAR wstr1[2*MAX_PATH+1], wbuf[2*MAX_PATH];
873 const WCHAR fmt[] = {'%','s',0};
874 STRRET strret;
875 int ret;
876 int i;
878 for (i=0; i<2*MAX_PATH; i++)
880 str1[i] = '0'+(i%10);
881 wstr1[i] = '0'+(i%10);
883 str1[2*MAX_PATH] = 0;
884 wstr1[2*MAX_PATH] = 0;
886 memset(buf, 0xbf, sizeof(buf));
887 expect_eq(StrCpyNA(buf, str1, 10), buf, PCHAR, "%p");
888 expect_eq(buf[9], 0, CHAR, "%x");
889 expect_eq(buf[10], '\xbf', CHAR, "%x");
891 if (pStrCatBuffA)
893 expect_eq(pStrCatBuffA(buf, str1, 100), buf, PCHAR, "%p");
894 expect_eq(buf[99], 0, CHAR, "%x");
895 expect_eq(buf[100], '\xbf', CHAR, "%x");
897 else
898 win_skip("StrCatBuffA() is not available\n");
900 if (0)
902 /* crashes on XP */
903 StrCpyNW(wbuf, (LPCWSTR)0x1, 10);
904 StrCpyNW((LPWSTR)0x1, wstr1, 10);
907 memset(wbuf, 0xbf, sizeof(wbuf));
908 expect_eq(StrCpyNW(wbuf, (LPCWSTR)0x1, 1), wbuf, PWCHAR, "%p");
909 expect_eq(wbuf[0], 0, WCHAR, "%x");
910 expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
912 if (pStrCpyNXA)
914 memset(wbuf, 0xbf, sizeof(wbuf));
915 expect_eq(StrCpyNW(wbuf, 0, 10), wbuf, PWCHAR, "%p");
916 expect_eq(wbuf[0], 0, WCHAR, "%x");
917 expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
919 else
920 win_skip("StrCpyNW test crashes on older Win9x platforms\n");
922 memset(wbuf, 0xbf, sizeof(wbuf));
923 expect_eq(StrCpyNW(wbuf, 0, 0), wbuf, PWCHAR, "%p");
924 expect_eq(wbuf[0], (WCHAR)0xbfbf, WCHAR, "%x");
925 expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
927 memset(wbuf, 0xbf, sizeof(wbuf));
928 expect_eq(StrCpyNW(wbuf, wstr1, 0), wbuf, PWCHAR, "%p");
929 expect_eq(wbuf[0], (WCHAR)0xbfbf, WCHAR, "%x");
930 expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
932 memset(wbuf, 0xbf, sizeof(wbuf));
933 expect_eq(StrCpyNW(wbuf, wstr1, 10), wbuf, PWCHAR, "%p");
934 expect_eq(wbuf[9], 0, WCHAR, "%x");
935 expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
937 if (pStrCatBuffW)
939 expect_eq(pStrCatBuffW(wbuf, wstr1, 100), wbuf, PWCHAR, "%p");
940 expect_eq(wbuf[99], 0, WCHAR, "%x");
941 expect_eq(wbuf[100], (WCHAR)0xbfbf, WCHAR, "%x");
943 else
944 win_skip("StrCatBuffW() is not available\n");
946 if (pStrRetToBufW)
948 memset(wbuf, 0xbf, sizeof(wbuf));
949 strret.uType = STRRET_WSTR;
950 U(strret).pOleStr = StrDupW(wstr1);
951 expect_eq2(pStrRetToBufW(&strret, NULL, wbuf, 10), S_OK, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) /* Vista */, HRESULT, "%x");
952 expect_eq(wbuf[9], 0, WCHAR, "%x");
953 expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
955 else
956 win_skip("StrRetToBufW() is not available\n");
958 if (pStrRetToBufA)
960 memset(buf, 0xbf, sizeof(buf));
961 strret.uType = STRRET_CSTR;
962 StrCpyN(U(strret).cStr, str1, MAX_PATH);
963 expect_eq2(pStrRetToBufA(&strret, NULL, buf, 10), S_OK, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) /* Vista */, HRESULT, "%x");
964 expect_eq(buf[9], 0, CHAR, "%x");
965 expect_eq(buf[10], (CHAR)0xbf, CHAR, "%x");
967 else
968 win_skip("StrRetToBufA() is not available\n");
970 if (pwnsprintfA)
972 memset(buf, 0xbf, sizeof(buf));
973 ret = pwnsprintfA(buf, 10, "%s", str1);
974 ok(broken(ret == 9) || ret == -1 /* Vista */, "Unexpected wsnprintfA return %d, expected 9 or -1\n", ret);
975 expect_eq(buf[9], 0, CHAR, "%x");
976 expect_eq(buf[10], (CHAR)0xbf, CHAR, "%x");
978 else
979 win_skip("wnsprintfA() is not available\n");
981 if (pwnsprintfW)
983 memset(wbuf, 0xbf, sizeof(wbuf));
984 ret = pwnsprintfW(wbuf, 10, fmt, wstr1);
985 ok(broken(ret == 9) || ret == -1 /* Vista */, "Unexpected wsnprintfW return %d, expected 9 or -1\n", ret);
986 expect_eq(wbuf[9], 0, WCHAR, "%x");
987 expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
989 else
990 win_skip("wnsprintfW() is not available\n");
993 static void test_StrStrA(void)
995 static const char *deadbeefA = "DeAdBeEf";
997 const struct
999 const char *search;
1000 const char *expect;
1001 } StrStrA_cases[] =
1003 {"", NULL},
1004 {"DeAd", deadbeefA},
1005 {"dead", NULL},
1006 {"AdBe", deadbeefA + 2},
1007 {"adbe", NULL},
1008 {"BeEf", deadbeefA + 4},
1009 {"beef", NULL},
1012 LPSTR ret;
1013 int i;
1015 /* Tests crash on Win9x/Win2k. */
1016 if (0)
1018 ret = StrStrA(NULL, NULL);
1019 ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret);
1021 ret = StrStrA(NULL, "");
1022 ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret);
1024 ret = StrStrA("", NULL);
1025 ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret);
1028 ret = StrStrA("", "");
1029 ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret);
1031 for (i = 0; i < sizeof(StrStrA_cases)/sizeof(StrStrA_cases[0]); i++)
1033 ret = StrStrA(deadbeefA, StrStrA_cases[i].search);
1034 ok(ret == StrStrA_cases[i].expect,
1035 "[%d] Expected StrStrA to return %p, got %p\n",
1036 i, StrStrA_cases[i].expect, ret);
1040 static void test_StrStrW(void)
1042 static const WCHAR emptyW[] = {0};
1043 static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
1044 static const WCHAR deadW[] = {'D','e','A','d',0};
1045 static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
1046 static const WCHAR adbeW[] = {'A','d','B','e',0};
1047 static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
1048 static const WCHAR beefW[] = {'B','e','E','f',0};
1049 static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
1051 const struct
1053 const WCHAR *search;
1054 const WCHAR *expect;
1055 } StrStrW_cases[] =
1057 {emptyW, NULL},
1058 {deadW, deadbeefW},
1059 {dead_lowerW, NULL},
1060 {adbeW, deadbeefW + 2},
1061 {adbe_lowerW, NULL},
1062 {beefW, deadbeefW + 4},
1063 {beef_lowerW, NULL},
1066 LPWSTR ret;
1067 int i;
1069 /* Tests crash on Win9x. */
1070 if (0)
1072 ret = StrStrW(NULL, NULL);
1073 ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
1075 ret = StrStrW(NULL, emptyW);
1076 ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
1078 ret = StrStrW(emptyW, NULL);
1079 ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
1082 ret = StrStrW(emptyW, emptyW);
1083 ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
1085 for (i = 0; i < sizeof(StrStrW_cases)/sizeof(StrStrW_cases[0]); i++)
1087 ret = StrStrW(deadbeefW, StrStrW_cases[i].search);
1088 ok(ret == StrStrW_cases[i].expect,
1089 "[%d] Expected StrStrW to return %p, got %p\n",
1090 i, StrStrW_cases[i].expect, ret);
1094 static void test_StrStrIA(void)
1096 static const char *deadbeefA = "DeAdBeEf";
1098 const struct
1100 const char *search;
1101 const char *expect;
1102 } StrStrIA_cases[] =
1104 {"", NULL},
1105 {"DeAd", deadbeefA},
1106 {"dead", deadbeefA},
1107 {"AdBe", deadbeefA + 2},
1108 {"adbe", deadbeefA + 2},
1109 {"BeEf", deadbeefA + 4},
1110 {"beef", deadbeefA + 4},
1111 {"cafe", NULL},
1114 LPSTR ret;
1115 int i;
1117 /* Tests crash on Win9x/Win2k. */
1118 if (0)
1120 ret = StrStrIA(NULL, NULL);
1121 ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret);
1123 ret = StrStrIA(NULL, "");
1124 ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret);
1126 ret = StrStrIA("", NULL);
1127 ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret);
1130 ret = StrStrIA("", "");
1131 ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret);
1133 for (i = 0; i < sizeof(StrStrIA_cases)/sizeof(StrStrIA_cases[0]); i++)
1135 ret = StrStrIA(deadbeefA, StrStrIA_cases[i].search);
1136 ok(ret == StrStrIA_cases[i].expect,
1137 "[%d] Expected StrStrIA to return %p, got %p\n",
1138 i, StrStrIA_cases[i].expect, ret);
1142 static void test_StrStrIW(void)
1144 static const WCHAR emptyW[] = {0};
1145 static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
1146 static const WCHAR deadW[] = {'D','e','A','d',0};
1147 static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
1148 static const WCHAR adbeW[] = {'A','d','B','e',0};
1149 static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
1150 static const WCHAR beefW[] = {'B','e','E','f',0};
1151 static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
1152 static const WCHAR cafeW[] = {'c','a','f','e',0};
1154 const struct
1156 const WCHAR *search;
1157 const WCHAR *expect;
1158 } StrStrIW_cases[] =
1160 {emptyW, NULL},
1161 {deadW, deadbeefW},
1162 {dead_lowerW, deadbeefW},
1163 {adbeW, deadbeefW + 2},
1164 {adbe_lowerW, deadbeefW + 2},
1165 {beefW, deadbeefW + 4},
1166 {beef_lowerW, deadbeefW + 4},
1167 {cafeW, NULL},
1170 LPWSTR ret;
1171 int i;
1173 /* Tests crash on Win9x/Win2k */
1174 if (0)
1176 ret = StrStrIW(NULL, NULL);
1177 ok(!ret, "Expected StrStrIW to return NULL, got %p\n", ret);
1179 ret = StrStrIW(NULL, emptyW);
1180 ok(!ret, "Expected StrStrIW to return NULL, got %p\n", ret);
1182 ret = StrStrIW(emptyW, NULL);
1183 ok(!ret, "Expected StrStrIW to return NULL, got %p\n", ret);
1186 ret = StrStrIW(emptyW, emptyW);
1187 ok(!ret, "Expected StrStrIW to return NULL, got %p\n", ret);
1189 for (i = 0; i < sizeof(StrStrIW_cases)/sizeof(StrStrIW_cases[0]); i++)
1191 ret = StrStrIW(deadbeefW, StrStrIW_cases[i].search);
1192 ok(ret == StrStrIW_cases[i].expect,
1193 "[%d] Expected StrStrIW to return %p, got %p\n",
1194 i, StrStrIW_cases[i].expect, ret);
1198 static void test_StrStrNW(void)
1200 static const WCHAR emptyW[] = {0};
1201 static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
1202 static const WCHAR deadW[] = {'D','e','A','d',0};
1203 static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
1204 static const WCHAR adbeW[] = {'A','d','B','e',0};
1205 static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
1206 static const WCHAR beefW[] = {'B','e','E','f',0};
1207 static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
1209 const struct
1211 const WCHAR *search;
1212 const UINT count;
1213 const WCHAR *expect;
1214 } StrStrNW_cases[] =
1216 {emptyW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1217 {deadW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW},
1218 {dead_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1219 {adbeW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 2},
1220 {adbe_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1221 {beefW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 4},
1222 {beef_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1223 {beefW, 0, NULL},
1224 {beefW, 1, NULL},
1225 {beefW, 2, NULL},
1226 {beefW, 3, NULL},
1227 {beefW, 4, NULL},
1228 {beefW, 5, deadbeefW + 4},
1229 {beefW, 6, deadbeefW + 4},
1230 {beefW, 7, deadbeefW + 4},
1231 {beefW, 8, deadbeefW + 4},
1232 {beefW, 9, deadbeefW + 4},
1235 LPWSTR ret;
1236 UINT i;
1238 if (!pStrStrNW)
1240 win_skip("StrStrNW() is not available\n");
1241 return;
1244 ret = pStrStrNW(NULL, NULL, 0);
1245 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1247 ret = pStrStrNW(NULL, NULL, 10);
1248 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1250 ret = pStrStrNW(NULL, emptyW, 10);
1251 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1253 ret = pStrStrNW(emptyW, NULL, 10);
1254 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1256 ret = pStrStrNW(emptyW, emptyW, 10);
1257 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1259 for (i = 0; i < sizeof(StrStrNW_cases)/sizeof(StrStrNW_cases[0]); i++)
1261 ret = pStrStrNW(deadbeefW, StrStrNW_cases[i].search, StrStrNW_cases[i].count);
1262 ok(ret == StrStrNW_cases[i].expect,
1263 "[%d] Expected StrStrNW to return %p, got %p\n",
1264 i, StrStrNW_cases[i].expect, ret);
1267 /* StrStrNW accepts counts larger than the search string length but rejects
1268 * counts larger than around 2G. The limit seems to change based on the
1269 * caller executable itself. */
1270 ret = pStrStrNW(deadbeefW, beefW, 100);
1271 ok(ret == deadbeefW + 4, "Expected StrStrNW to return deadbeefW + 4, got %p\n", ret);
1273 if (0)
1275 ret = pStrStrNW(deadbeefW, beefW, ~0U);
1276 ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1280 static void test_StrStrNIW(void)
1282 static const WCHAR emptyW[] = {0};
1283 static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
1284 static const WCHAR deadW[] = {'D','e','A','d',0};
1285 static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
1286 static const WCHAR adbeW[] = {'A','d','B','e',0};
1287 static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
1288 static const WCHAR beefW[] = {'B','e','E','f',0};
1289 static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
1290 static const WCHAR cafeW[] = {'c','a','f','e',0};
1292 const struct
1294 const WCHAR *search;
1295 const UINT count;
1296 const WCHAR *expect;
1297 } StrStrNIW_cases[] =
1299 {emptyW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1300 {deadW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW},
1301 {dead_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW},
1302 {adbeW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 2},
1303 {adbe_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 2},
1304 {beefW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 4},
1305 {beef_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 4},
1306 {cafeW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1307 {beefW, 0, NULL},
1308 {beefW, 1, NULL},
1309 {beefW, 2, NULL},
1310 {beefW, 3, NULL},
1311 {beefW, 4, NULL},
1312 {beefW, 5, deadbeefW + 4},
1313 {beefW, 6, deadbeefW + 4},
1314 {beefW, 7, deadbeefW + 4},
1315 {beefW, 8, deadbeefW + 4},
1316 {beefW, 9, deadbeefW + 4},
1317 {beef_lowerW, 0, NULL},
1318 {beef_lowerW, 1, NULL},
1319 {beef_lowerW, 2, NULL},
1320 {beef_lowerW, 3, NULL},
1321 {beef_lowerW, 4, NULL},
1322 {beef_lowerW, 5, deadbeefW + 4},
1323 {beef_lowerW, 6, deadbeefW + 4},
1324 {beef_lowerW, 7, deadbeefW + 4},
1325 {beef_lowerW, 8, deadbeefW + 4},
1326 {beef_lowerW, 9, deadbeefW + 4},
1329 LPWSTR ret;
1330 UINT i;
1332 if (!pStrStrNIW)
1334 win_skip("StrStrNIW() is not available\n");
1335 return;
1338 ret = pStrStrNIW(NULL, NULL, 0);
1339 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1341 ret = pStrStrNIW(NULL, NULL, 10);
1342 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1344 ret = pStrStrNIW(NULL, emptyW, 10);
1345 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1347 ret = pStrStrNIW(emptyW, NULL, 10);
1348 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1350 ret = pStrStrNIW(emptyW, emptyW, 10);
1351 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1353 for (i = 0; i < sizeof(StrStrNIW_cases)/sizeof(StrStrNIW_cases[0]); i++)
1355 ret = pStrStrNIW(deadbeefW, StrStrNIW_cases[i].search, StrStrNIW_cases[i].count);
1356 ok(ret == StrStrNIW_cases[i].expect,
1357 "[%d] Expected StrStrNIW to return %p, got %p\n",
1358 i, StrStrNIW_cases[i].expect, ret);
1361 /* StrStrNIW accepts counts larger than the search string length but rejects
1362 * counts larger than around 2G. The limit seems to change based on the
1363 * caller executable itself. */
1364 ret = pStrStrNIW(deadbeefW, beefW, 100);
1365 ok(ret == deadbeefW + 4, "Expected StrStrNIW to return deadbeefW + 4, got %p\n", ret);
1367 if (0)
1369 ret = pStrStrNIW(deadbeefW, beefW, ~0U);
1370 ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1374 START_TEST(string)
1376 HMODULE hShlwapi;
1377 TCHAR thousandDelim[8];
1378 TCHAR decimalDelim[8];
1379 CoInitialize(0);
1381 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, thousandDelim, 8);
1382 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, decimalDelim, 8);
1384 hShlwapi = GetModuleHandleA("shlwapi");
1385 pChrCmpIA = (void *)GetProcAddress(hShlwapi, "ChrCmpIA");
1386 pChrCmpIW = (void *)GetProcAddress(hShlwapi, "ChrCmpIW");
1387 pIntlStrEqWorkerA = (void *)GetProcAddress(hShlwapi, "IntlStrEqWorkerA");
1388 pIntlStrEqWorkerW = (void *)GetProcAddress(hShlwapi, "IntlStrEqWorkerW");
1389 pSHAnsiToAnsi = (void *)GetProcAddress(hShlwapi, (LPSTR)345);
1390 pSHUnicodeToUnicode = (void *)GetProcAddress(hShlwapi, (LPSTR)346);
1391 pStrCatBuffA = (void *)GetProcAddress(hShlwapi, "StrCatBuffA");
1392 pStrCatBuffW = (void *)GetProcAddress(hShlwapi, "StrCatBuffW");
1393 pStrCpyNXA = (void *)GetProcAddress(hShlwapi, (LPSTR)399);
1394 pStrCpyNXW = (void *)GetProcAddress(hShlwapi, (LPSTR)400);
1395 pStrChrNW = (void *)GetProcAddress(hShlwapi, "StrChrNW");
1396 pStrFormatByteSize64A = (void *)GetProcAddress(hShlwapi, "StrFormatByteSize64A");
1397 pStrFormatKBSizeA = (void *)GetProcAddress(hShlwapi, "StrFormatKBSizeA");
1398 pStrFormatKBSizeW = (void *)GetProcAddress(hShlwapi, "StrFormatKBSizeW");
1399 pStrIsIntlEqualA = (void *)GetProcAddress(hShlwapi, "StrIsIntlEqualA");
1400 pStrIsIntlEqualW = (void *)GetProcAddress(hShlwapi, "StrIsIntlEqualW");
1401 pStrPBrkW = (void *)GetProcAddress(hShlwapi, "StrPBrkW");
1402 pStrRChrA = (void *)GetProcAddress(hShlwapi, "StrRChrA");
1403 pStrRetToBSTR = (void *)GetProcAddress(hShlwapi, "StrRetToBSTR");
1404 pStrRetToBufA = (void *)GetProcAddress(hShlwapi, "StrRetToBufA");
1405 pStrRetToBufW = (void *)GetProcAddress(hShlwapi, "StrRetToBufW");
1406 pStrStrNW = (void *)GetProcAddress(hShlwapi, "StrStrNW");
1407 pStrStrNIW = (void *)GetProcAddress(hShlwapi, "StrStrNIW");
1408 pwnsprintfA = (void *)GetProcAddress(hShlwapi, "wnsprintfA");
1409 pwnsprintfW = (void *)GetProcAddress(hShlwapi, "wnsprintfW");
1411 test_StrChrA();
1412 test_StrChrW();
1413 test_StrChrIA();
1414 test_StrChrIW();
1415 test_StrRChrA();
1416 test_StrRChrW();
1417 test_StrCpyW();
1418 test_StrChrNW();
1419 test_StrToIntA();
1420 test_StrToIntW();
1421 test_StrToIntExA();
1422 test_StrToIntExW();
1423 test_StrDupA();
1425 /* language-dependent test */
1426 if (PRIMARYLANGID(GetUserDefaultLangID()) != LANG_ENGLISH)
1427 skip("English is required for StrFromTimeInterval and StrFormat*Size tests\n");
1428 else
1430 test_StrFormatByteSize64A();
1431 test_StrFormatKBSizeA();
1432 test_StrFormatKBSizeW();
1433 test_StrFromTimeIntervalA();
1436 test_StrCmpA();
1437 test_StrCmpW();
1438 test_StrRetToBSTR();
1439 test_StrCpyNXA();
1440 test_StrCpyNXW();
1441 test_StrRStrI();
1442 test_SHAnsiToAnsi();
1443 test_SHUnicodeToUnicode();
1444 test_StrXXX_overflows();
1445 test_StrStrA();
1446 test_StrStrW();
1447 test_StrStrIA();
1448 test_StrStrIW();
1449 test_StrStrNW();
1450 test_StrStrNIW();
1452 CoUninitialize();