wined3d: Remove the Apple NV_texture_shader quirk.
[wine] / dlls / shlwapi / tests / string.c
1 /* Unit test suite for SHLWAPI string functions
2  *
3  * Copyright 2003 Jon Griffiths
4  *
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.
9  *
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.
14  *
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
18  */
19
20 #include <stdio.h>
21
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"
32
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);
37
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);
42
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
69 static int strcmpW(const WCHAR *str1, const WCHAR *str2)
70 {
71     while (*str1 && (*str1 == *str2)) { str1++; str2++; }
72     return *str1 - *str2;
73 }
74
75 /* StrToInt/StrToIntEx results */
76 typedef struct tagStrToIntResult
77 {
78   const char* string;
79   int str_to_int;
80   int str_to_int_ex;
81   int str_to_int_hex;
82 } StrToIntResult;
83
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 }
106 };
107
108 /* pStrFormatByteSize64/StrFormatKBSize results */
109 typedef struct tagStrFormatSizeResult
110 {
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;
117
118
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 }
136 };
137
138 /* StrFromTimeIntervalA/StrFromTimeIntervalW results */
139 typedef struct tagStrFromTimeIntervalResult
140 {
141   DWORD ms;
142   int   digits;
143   const char* time_interval;
144 } StrFromTimeIntervalResult;
145
146
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" },
155
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" },
163
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" },
171
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" },
179
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" },
188
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" },
196
197   { 0, 0, NULL }
198 };
199
200
201 /* Returns true if the user interface is in English. Note that this does not
202  * presume of the formatting of dates, numbers, etc.
203  */
204 static BOOL is_lang_english(void)
205 {
206     static HMODULE hkernel32 = NULL;
207     static LANGID (WINAPI *pGetThreadUILanguage)(void) = NULL;
208     static LANGID (WINAPI *pGetUserDefaultUILanguage)(void) = NULL;
209
210     if (!hkernel32)
211     {
212         hkernel32 = GetModuleHandleA("kernel32.dll");
213         pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
214         pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
215     }
216     if (pGetThreadUILanguage)
217         return PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH;
218     if (pGetUserDefaultUILanguage)
219         return PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH;
220
221     return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
222 }
223
224 /* Returns true if the dates, numbers, etc. are formatted using English
225  * conventions.
226  */
227 static BOOL is_locale_english(void)
228 {
229     /* Surprisingly GetThreadLocale() is irrelevant here */
230     return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
231 }
232
233 static void test_StrChrA(void)
234 {
235   char string[129];
236   WORD count;
237
238   /* this test crashes on win2k SP4 */
239   /*ok(!StrChrA(NULL,'\0'), "found a character in a NULL string!\n");*/
240
241   for (count = 32; count < 128; count++)
242     string[count] = (char)count;
243   string[128] = '\0';
244
245   for (count = 32; count < 128; count++)
246   {
247     LPSTR result = StrChrA(string+32, count);
248     INT pos = result - string;
249     ok(pos == count, "found char '%c' in wrong place: got %d, expected %d\n", count, pos, count);
250   }
251
252   for (count = 32; count < 128; count++)
253   {
254     LPSTR result = StrChrA(string+count+1, count);
255     ok(!result, "found char '%c' not in the string\n", count);
256   }
257 }
258
259 static void test_StrChrW(void)
260 {
261   WCHAR string[16385];
262   WORD count;
263
264   /* this test crashes on win2k SP4 */
265   /*ok(!StrChrW(NULL,'\0'), "found a character in a NULL string!\n");*/
266
267   for (count = 32; count < 16384; count++)
268     string[count] = count;
269   string[16384] = '\0';
270
271   for (count = 32; count < 16384; count++)
272   {
273     LPWSTR result = StrChrW(string+32, count);
274     ok((result - string) == count, "found char %d in wrong place\n", count);
275   }
276
277   for (count = 32; count < 16384; count++)
278   {
279     LPWSTR result = StrChrW(string+count+1, count);
280     ok(!result, "found char not in the string\n");
281   }
282 }
283
284 static void test_StrChrIA(void)
285 {
286   char string[129];
287   WORD count;
288
289   /* this test crashes on win2k SP4 */
290   /*ok(!StrChrIA(NULL,'\0'), "found a character in a NULL string!\n");*/
291
292   for (count = 32; count < 128; count++)
293     string[count] = (char)count;
294   string[128] = '\0';
295
296   for (count = 'A'; count <= 'X'; count++)
297   {
298     LPSTR result = StrChrIA(string+32, count);
299
300     ok(result - string == count, "found char '%c' in wrong place\n", count);
301     ok(StrChrIA(result, count)!=NULL, "didn't find lowercase '%c'\n", count);
302   }
303
304   for (count = 'a'; count < 'z'; count++)
305   {
306     LPSTR result = StrChrIA(string+count+1, count);
307     ok(!result, "found char not in the string\n");
308   }
309 }
310
311 static void test_StrChrIW(void)
312 {
313   WCHAR string[129];
314   WORD count;
315
316   /* this test crashes on win2k SP4 */
317   /*ok(!StrChrIA(NULL,'\0'), "found a character in a NULL string!\n");*/
318
319   for (count = 32; count < 128; count++)
320     string[count] = count;
321   string[128] = '\0';
322
323   for (count = 'A'; count <= 'X'; count++)
324   {
325     LPWSTR result = StrChrIW(string+32, count);
326
327     ok(result - string == count, "found char '%c' in wrong place\n", count);
328     ok(StrChrIW(result, count)!=NULL, "didn't find lowercase '%c'\n", count);
329   }
330
331   for (count = 'a'; count < 'z'; count++)
332   {
333     LPWSTR result = StrChrIW(string+count+1, count);
334     ok(!result, "found char not in the string\n");
335   }
336 }
337
338 static void test_StrRChrA(void)
339 {
340   char string[129];
341   WORD count;
342
343   /* this test crashes on win2k SP4 */
344   /*ok(!StrRChrA(NULL, NULL,'\0'), "found a character in a NULL string!\n");*/
345
346   for (count = 32; count < 128; count++)
347     string[count] = (char)count;
348   string[128] = '\0';
349
350   for (count = 32; count < 128; count++)
351   {
352     LPSTR result = StrRChrA(string+32, NULL, count);
353     ok(result - string == count, "found char %d in wrong place\n", count);
354   }
355
356   for (count = 32; count < 128; count++)
357   {
358     LPSTR result = StrRChrA(string+count+1, NULL, count);
359     ok(!result, "found char not in the string\n");
360   }
361
362   for (count = 32; count < 128; count++)
363   {
364     LPSTR result = StrRChrA(string+count+1, string + 127, count);
365     ok(!result, "found char not in the string\n");
366   }
367 }
368
369 static void test_StrRChrW(void)
370 {
371   WCHAR string[129];
372   WORD count;
373
374   /* this test crashes on win2k SP4 */
375   /*ok(!StrRChrW(NULL, NULL,'\0'), "found a character in a NULL string!\n");*/
376
377   for (count = 32; count < 128; count++)
378     string[count] = count;
379   string[128] = '\0';
380
381   for (count = 32; count < 128; count++)
382   {
383     LPWSTR result = StrRChrW(string+32, NULL, count);
384     INT pos = result - string;
385     ok(pos == count, "found char %d in wrong place: got %d, expected %d\n", count, pos, count);
386   }
387
388   for (count = 32; count < 128; count++)
389   {
390     LPWSTR result = StrRChrW(string+count+1, NULL, count);
391     ok(!result, "found char %d not in the string\n", count);
392   }
393
394   for (count = 32; count < 128; count++)
395   {
396     LPWSTR result = StrRChrW(string+count+1, string + 127, count);
397     ok(!result, "found char %d not in the string\n", count);
398   }
399 }
400
401 static void test_StrCpyW(void)
402 {
403   WCHAR szSrc[256];
404   WCHAR szBuff[256];
405   const StrFormatSizeResult* result = StrFormatSize_results;
406
407
408   while(result->value)
409   {
410     MultiByteToWideChar(0,0,result->byte_size_64,-1,szSrc,sizeof(szSrc)/sizeof(WCHAR));
411
412     StrCpyW(szBuff, szSrc);
413     ok(!StrCmpW(szSrc, szBuff), "Copied string %s wrong\n", result->byte_size_64);
414     result++;
415   }
416 }
417
418 static void test_StrChrNW(void)
419 {
420     static WCHAR string[] = {'T','e','s','t','i','n','g',' ','S','t','r','i','n','g',0};
421     LPWSTR p;
422
423     if (!pStrChrNW)
424     {
425         win_skip("StrChrNW not available\n");
426         return;
427     }
428
429     p = pStrChrNW(string,'t',10);
430     ok(*p=='t',"Found wrong 't'\n");
431     ok(*(p+1)=='i',"next should be 'i'\n");
432
433     p = pStrChrNW(string,'S',10);
434     ok(*p=='S',"Found wrong 'S'\n");
435
436     p = pStrChrNW(string,'r',10);
437     ok(p==NULL,"Should not have found 'r'\n");
438 }
439
440 static void test_StrToIntA(void)
441 {
442   const StrToIntResult *result = StrToInt_results;
443   int return_val;
444
445   while (result->string)
446   {
447     return_val = StrToIntA(result->string);
448     ok(return_val == result->str_to_int, "converted '%s' wrong (%d)\n",
449        result->string, return_val);
450     result++;
451   }
452 }
453
454 static void test_StrToIntW(void)
455 {
456   WCHAR szBuff[256];
457   const StrToIntResult *result = StrToInt_results;
458   int return_val;
459
460   while (result->string)
461   {
462     MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
463     return_val = StrToIntW(szBuff);
464     ok(return_val == result->str_to_int, "converted '%s' wrong (%d)\n",
465        result->string, return_val);
466     result++;
467   }
468 }
469
470 static void test_StrToIntExA(void)
471 {
472   const StrToIntResult *result = StrToInt_results;
473   int return_val;
474   BOOL bRet;
475
476   while (result->string)
477   {
478     return_val = -1;
479     bRet = StrToIntExA(result->string,0,&return_val);
480     ok(!bRet || return_val != -1, "No result returned from '%s'\n",
481        result->string);
482     if (bRet)
483       ok(return_val == result->str_to_int_ex, "converted '%s' wrong (%d)\n",
484          result->string, return_val);
485     result++;
486   }
487
488   result = StrToInt_results;
489   while (result->string)
490   {
491     return_val = -1;
492     bRet = StrToIntExA(result->string,STIF_SUPPORT_HEX,&return_val);
493     ok(!bRet || return_val != -1, "No result returned from '%s'\n",
494        result->string);
495     if (bRet)
496       ok(return_val == result->str_to_int_hex, "converted '%s' wrong (%d)\n",
497          result->string, return_val);
498     result++;
499   }
500 }
501
502 static void test_StrToIntExW(void)
503 {
504   WCHAR szBuff[256];
505   const StrToIntResult *result = StrToInt_results;
506   int return_val;
507   BOOL bRet;
508
509   while (result->string)
510   {
511     return_val = -1;
512     MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
513     bRet = StrToIntExW(szBuff, 0, &return_val);
514     ok(!bRet || return_val != -1, "No result returned from '%s'\n",
515        result->string);
516     if (bRet)
517       ok(return_val == result->str_to_int_ex, "converted '%s' wrong (%d)\n",
518          result->string, return_val);
519     result++;
520   }
521
522   result = StrToInt_results;
523   while (result->string)
524   {
525     return_val = -1;
526     MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
527     bRet = StrToIntExW(szBuff, STIF_SUPPORT_HEX, &return_val);
528     ok(!bRet || return_val != -1, "No result returned from '%s'\n",
529        result->string);
530     if (bRet)
531       ok(return_val == result->str_to_int_hex, "converted '%s' wrong (%d)\n",
532          result->string, return_val);
533     result++;
534   }
535 }
536
537 static void test_StrDupA(void)
538 {
539   LPSTR lpszStr;
540   const StrFormatSizeResult* result = StrFormatSize_results;
541
542   while(result->value)
543   {
544     lpszStr = StrDupA(result->byte_size_64);
545
546     ok(lpszStr != NULL, "Dup failed\n");
547     if (lpszStr)
548     {
549       ok(!strcmp(result->byte_size_64, lpszStr), "Copied string wrong\n");
550       LocalFree(lpszStr);
551     }
552     result++;
553   }
554
555   /* Later versions of shlwapi return NULL for this, but earlier versions
556    * returned an empty string (as Wine does).
557    */
558   lpszStr = StrDupA(NULL);
559   ok(lpszStr == NULL || *lpszStr == '\0', "NULL string returned %p\n", lpszStr);
560   LocalFree(lpszStr);
561 }
562
563 static void test_StrFormatByteSize64A(void)
564 {
565   char szBuff[256];
566   const StrFormatSizeResult* result = StrFormatSize_results;
567
568   if (!pStrFormatByteSize64A)
569   {
570     win_skip("StrFormatByteSize64A() is not available\n");
571     return;
572   }
573
574   while(result->value)
575   {
576     pStrFormatByteSize64A(result->value, szBuff, 256);
577
578     ok(!strcmp(result->byte_size_64, szBuff),
579         "Formatted %x%08x wrong: got %s, expected %s\n",
580        (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->byte_size_64);
581
582     result++;
583   }
584 }
585
586 static void test_StrFormatKBSizeW(void)
587 {
588   WCHAR szBuffW[256];
589   char szBuff[256];
590   const StrFormatSizeResult* result = StrFormatSize_results;
591
592   if (!pStrFormatKBSizeW)
593   {
594     win_skip("StrFormatKBSizeW() is not available\n");
595     return;
596   }
597
598   while(result->value)
599   {
600     pStrFormatKBSizeW(result->value, szBuffW, 256);
601     WideCharToMultiByte(0,0,szBuffW,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR),0,0);
602
603     ok(!strcmp(result->kb_size, szBuff), "Formatted %x%08x wrong: got %s, expected %s\n",
604        (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->kb_size);
605     result++;
606   }
607 }
608
609 static void test_StrFormatKBSizeA(void)
610 {
611   char szBuff[256];
612   const StrFormatSizeResult* result = StrFormatSize_results;
613
614   if (!pStrFormatKBSizeA)
615   {
616     win_skip("StrFormatKBSizeA() is not available\n");
617     return;
618   }
619
620   while(result->value)
621   {
622     pStrFormatKBSizeA(result->value, szBuff, 256);
623
624     /* shlwapi on Win98 SE does not appear to apply delimiters to the output
625      * and does not correctly handle extremely large values. */
626     ok(!strcmp(result->kb_size, szBuff) ||
627       (result->kb_size_broken && !strcmp(result->kb_size2, szBuff)),
628         "Formatted %x%08x wrong: got %s, expected %s\n",
629        (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->kb_size);
630     result++;
631   }
632 }
633
634 static void test_StrFromTimeIntervalA(void)
635 {
636   char szBuff[256];
637   const StrFromTimeIntervalResult* result = StrFromTimeInterval_results;
638
639   while(result->ms)
640   {
641     StrFromTimeIntervalA(szBuff, 256, result->ms, result->digits);
642
643     ok(!strcmp(result->time_interval, szBuff), "Formatted %d %d wrong: %s\n",
644        result->ms, result->digits, szBuff);
645     result++;
646   }
647 }
648
649 static void test_StrCmpA(void)
650 {
651   static const char str1[] = {'a','b','c','d','e','f'};
652   static const char str2[] = {'a','B','c','d','e','f'};
653   ok(0 != StrCmpNA(str1, str2, 6), "StrCmpNA is case-insensitive\n");
654   ok(0 == StrCmpNIA(str1, str2, 6), "StrCmpNIA is case-sensitive\n");
655   if (pChrCmpIA) {
656     ok(!pChrCmpIA('a', 'a'), "ChrCmpIA doesn't work at all!\n");
657     ok(!pChrCmpIA('b', 'B'), "ChrCmpIA is not case-insensitive\n");
658     ok(pChrCmpIA('a', 'z'), "ChrCmpIA believes that a == z!\n");
659   }
660   else
661     win_skip("ChrCmpIA() is not available\n");
662
663   if (pStrIsIntlEqualA)
664   {
665     ok(pStrIsIntlEqualA(FALSE, str1, str2, 5), "StrIsIntlEqualA(FALSE,...) isn't case-insensitive\n");
666     ok(!pStrIsIntlEqualA(TRUE, str1, str2, 5), "StrIsIntlEqualA(TRUE,...) isn't case-sensitive\n");
667   }
668   else
669     win_skip("StrIsIntlEqualA() is not available\n");
670
671   if (pIntlStrEqWorkerA)
672   {
673     ok(pIntlStrEqWorkerA(FALSE, str1, str2, 5), "IntlStrEqWorkerA(FALSE,...) isn't case-insensitive\n");
674     ok(!pIntlStrEqWorkerA(TRUE, str1, str2, 5), "pIntlStrEqWorkerA(TRUE,...) isn't case-sensitive\n");
675   }
676   else
677     win_skip("IntlStrEqWorkerA() is not available\n");
678 }
679
680 static void test_StrCmpW(void)
681 {
682   static const WCHAR str1[] = {'a','b','c','d','e','f'};
683   static const WCHAR str2[] = {'a','B','c','d','e','f'};
684   ok(0 != StrCmpNW(str1, str2, 5), "StrCmpNW is case-insensitive\n");
685   ok(0 == StrCmpNIW(str1, str2, 5), "StrCmpNIW is case-sensitive\n");
686   if (pChrCmpIW) {
687     ok(!pChrCmpIW('a', 'a'), "ChrCmpIW doesn't work at all!\n");
688     ok(!pChrCmpIW('b', 'B'), "ChrCmpIW is not case-insensitive\n");
689     ok(pChrCmpIW('a', 'z'), "ChrCmpIW believes that a == z!\n");
690   }
691   else
692     win_skip("ChrCmpIW() is not available\n");
693
694   if (pStrIsIntlEqualW)
695   {
696     ok(pStrIsIntlEqualW(FALSE, str1, str2, 5), "StrIsIntlEqualW(FALSE,...) isn't case-insensitive\n");
697     ok(!pStrIsIntlEqualW(TRUE, str1, str2, 5), "StrIsIntlEqualW(TRUE,...) isn't case-sensitive\n");
698   }
699   else
700     win_skip("StrIsIntlEqualW() is not available\n");
701
702   if (pIntlStrEqWorkerW)
703   {
704     ok(pIntlStrEqWorkerW(FALSE, str1, str2, 5), "IntlStrEqWorkerW(FALSE,...) isn't case-insensitive\n");
705     ok(!pIntlStrEqWorkerW(TRUE, str1, str2, 5), "IntlStrEqWorkerW(TRUE,...) isn't case-sensitive\n");
706   }
707   else
708     win_skip("IntlStrEqWorkerW() is not available\n");
709 }
710
711 static WCHAR *CoDupStrW(const char* src)
712 {
713   INT len = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0);
714   WCHAR* szTemp = CoTaskMemAlloc(len * sizeof(WCHAR));
715   MultiByteToWideChar(CP_ACP, 0, src, -1, szTemp, len);
716   return szTemp;
717 }
718
719 static void test_StrRetToBSTR(void)
720 {
721     static const WCHAR szTestW[] = { 'T','e','s','t','\0' };
722     ITEMIDLIST iidl[10];
723     BSTR bstr;
724     STRRET strret;
725     HRESULT ret;
726
727     if (!pStrRetToBSTR)
728     {
729         win_skip("StrRetToBSTR() is not available\n");
730         return;
731     }
732
733     strret.uType = STRRET_WSTR;
734     U(strret).pOleStr = CoDupStrW("Test");
735     bstr = 0;
736     ret = pStrRetToBSTR(&strret, NULL, &bstr);
737     ok(ret == S_OK && bstr && !strcmpW(bstr, szTestW),
738        "STRRET_WSTR: dup failed, ret=0x%08x, bstr %p\n", ret, bstr);
739     SysFreeString(bstr);
740
741     strret.uType = STRRET_CSTR;
742     lstrcpyA(U(strret).cStr, "Test");
743     ret = pStrRetToBSTR(&strret, NULL, &bstr);
744     ok(ret == S_OK && bstr && !strcmpW(bstr, szTestW),
745        "STRRET_CSTR: dup failed, ret=0x%08x, bstr %p\n", ret, bstr);
746     SysFreeString(bstr);
747
748     strret.uType = STRRET_OFFSET;
749     U(strret).uOffset = 1;
750     strcpy((char*)&iidl, " Test");
751     ret = pStrRetToBSTR(&strret, iidl, &bstr);
752     ok(ret == S_OK && bstr && !strcmpW(bstr, szTestW),
753        "STRRET_OFFSET: dup failed, ret=0x%08x, bstr %p\n", ret, bstr);
754     SysFreeString(bstr);
755
756     /* Native crashes if str is NULL */
757 }
758
759 static void test_StrCpyNXA(void)
760 {
761   LPCSTR lpSrc = "hello";
762   LPSTR lpszRes;
763   char dest[8];
764
765   if (!pStrCpyNXA)
766   {
767     win_skip("StrCpyNXA() is not available\n");
768     return;
769   }
770
771   memset(dest, '\n', sizeof(dest));
772   lpszRes = pStrCpyNXA(dest, lpSrc, sizeof(dest)/sizeof(dest[0]));
773   ok(lpszRes == dest + 5 && !memcmp(dest, "hello\0\n\n", sizeof(dest)),
774        "StrCpyNXA: expected %p, \"hello\\0\\n\\n\", got %p, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
775        dest + 5, lpszRes, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
776 }
777
778 static void test_StrCpyNXW(void)
779 {
780   static const WCHAR lpInit[] = { '\n','\n','\n','\n','\n','\n','\n','\n' };
781   static const WCHAR lpSrc[] = { 'h','e','l','l','o','\0' };
782   static const WCHAR lpRes[] = { 'h','e','l','l','o','\0','\n','\n' };
783   LPWSTR lpszRes;
784   WCHAR dest[8];
785
786   if (!pStrCpyNXW)
787   {
788     win_skip("StrCpyNXW() is not available\n");
789     return;
790   }
791
792   memcpy(dest, lpInit, sizeof(lpInit));
793   lpszRes = pStrCpyNXW(dest, lpSrc, sizeof(dest)/sizeof(dest[0]));
794   ok(lpszRes == dest + 5 && !memcmp(dest, lpRes, sizeof(dest)),
795        "StrCpyNXW: expected %p, \"hello\\0\\n\\n\", got %p, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
796        dest + 5, lpszRes, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
797 }
798
799 #define check_strrstri(type, str, pos, needle, exp) \
800     ret##type = StrRStrI##type(str, str+pos, needle); \
801     ok(ret##type == (exp), "Type " #type ", expected %p but got %p (string base %p)\n", \
802     (exp), ret##type, str);
803
804 static void test_StrRStrI(void)
805 {
806     static const CHAR szTest[] = "yAxxxxAy";
807     static const CHAR szTest2[] = "ABABABAB";
808     static const WCHAR wszTest[] = {'y','A','x','x','x','x','A','y',0};
809     static const WCHAR wszTest2[] = {'A','B','A','B','A','B','A','B',0};
810
811     static const WCHAR wszPattern1[] = {'A',0};
812     static const WCHAR wszPattern2[] = {'a','X',0};
813     static const WCHAR wszPattern3[] = {'A','y',0};
814     static const WCHAR wszPattern4[] = {'a','b',0};
815     LPWSTR retW;
816     LPSTR retA;
817
818     check_strrstri(A, szTest, 4, "A", szTest+1);
819     check_strrstri(A, szTest, 4, "aX", szTest+1);
820     check_strrstri(A, szTest, 4, "Ay", NULL);
821     check_strrstri(W, wszTest, 4, wszPattern1, wszTest+1);
822     check_strrstri(W, wszTest, 4, wszPattern2, wszTest+1);
823     check_strrstri(W, wszTest, 4, wszPattern3, NULL);
824
825     check_strrstri(A, szTest2, 4, "ab", szTest2+2);
826     check_strrstri(A, szTest2, 3, "ab", szTest2+2);
827     check_strrstri(A, szTest2, 2, "ab", szTest2);
828     check_strrstri(A, szTest2, 1, "ab", szTest2);
829     check_strrstri(A, szTest2, 0, "ab", NULL);
830     check_strrstri(W, wszTest2, 4, wszPattern4, wszTest2+2);
831     check_strrstri(W, wszTest2, 3, wszPattern4, wszTest2+2);
832     check_strrstri(W, wszTest2, 2, wszPattern4, wszTest2);
833     check_strrstri(W, wszTest2, 1, wszPattern4, wszTest2);
834     check_strrstri(W, wszTest2, 0, wszPattern4, NULL);
835
836 }
837
838 static void test_SHAnsiToAnsi(void)
839 {
840   char dest[8];
841   DWORD dwRet;
842
843   if (!pSHAnsiToAnsi)
844   {
845     win_skip("SHAnsiToAnsi() is not available\n");
846     return;
847   }
848
849   if (pSHAnsiToAnsi == (void *)pStrPBrkW)
850   {
851     win_skip("Ordinal 345 corresponds to StrPBrkW, skipping SHAnsiToAnsi tests\n");
852     return;
853   }
854
855   memset(dest, '\n', sizeof(dest));
856   dwRet = pSHAnsiToAnsi("hello", dest, sizeof(dest)/sizeof(dest[0]));
857   ok(dwRet == 6 && !memcmp(dest, "hello\0\n\n", sizeof(dest)),
858      "SHAnsiToAnsi: expected 6, \"hello\\0\\n\\n\", got %d, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
859      dwRet, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
860 }
861
862 static void test_SHUnicodeToUnicode(void)
863 {
864   static const WCHAR lpInit[] = { '\n','\n','\n','\n','\n','\n','\n','\n' };
865   static const WCHAR lpSrc[] = { 'h','e','l','l','o','\0' };
866   static const WCHAR lpRes[] = { 'h','e','l','l','o','\0','\n','\n' };
867   WCHAR dest[8];
868   DWORD dwRet;
869
870   if (!pSHUnicodeToUnicode)
871   {
872     win_skip("SHUnicodeToUnicode() is not available\n");
873     return;
874   }
875
876   if (pSHUnicodeToUnicode == (void *)pStrRChrA)
877   {
878     win_skip("Ordinal 346 corresponds to StrRChrA, skipping SHUnicodeToUnicode tests\n");
879     return;
880   }
881
882   memcpy(dest, lpInit, sizeof(lpInit));
883   dwRet = pSHUnicodeToUnicode(lpSrc, dest, sizeof(dest)/sizeof(dest[0]));
884   ok(dwRet == 6 && !memcmp(dest, lpRes, sizeof(dest)),
885      "SHUnicodeToUnicode: expected 6, \"hello\\0\\n\\n\", got %d, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
886      dwRet, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
887 }
888
889 static void test_StrXXX_overflows(void)
890 {
891     CHAR str1[2*MAX_PATH+1], buf[2*MAX_PATH];
892     WCHAR wstr1[2*MAX_PATH+1], wbuf[2*MAX_PATH];
893     const WCHAR fmt[] = {'%','s',0};
894     STRRET strret;
895     int ret;
896     int i;
897
898     for (i=0; i<2*MAX_PATH; i++)
899     {
900         str1[i] = '0'+(i%10);
901         wstr1[i] = '0'+(i%10);
902     }
903     str1[2*MAX_PATH] = 0;
904     wstr1[2*MAX_PATH] = 0;
905
906     memset(buf, 0xbf, sizeof(buf));
907     expect_eq(StrCpyNA(buf, str1, 10), buf, PCHAR, "%p");
908     expect_eq(buf[9], 0, CHAR, "%x");
909     expect_eq(buf[10], '\xbf', CHAR, "%x");
910
911     if (pStrCatBuffA)
912     {
913         expect_eq(pStrCatBuffA(buf, str1, 100), buf, PCHAR, "%p");
914         expect_eq(buf[99], 0, CHAR, "%x");
915         expect_eq(buf[100], '\xbf', CHAR, "%x");
916     }
917     else
918         win_skip("StrCatBuffA() is not available\n");
919
920 if (0)
921 {
922     /* crashes on XP */
923     StrCpyNW(wbuf, (LPCWSTR)0x1, 10);
924     StrCpyNW((LPWSTR)0x1, wstr1, 10);
925 }
926
927     memset(wbuf, 0xbf, sizeof(wbuf));
928     expect_eq(StrCpyNW(wbuf, (LPCWSTR)0x1, 1), wbuf, PWCHAR, "%p");
929     expect_eq(wbuf[0], 0, WCHAR, "%x");
930     expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
931
932     memset(wbuf, 0xbf, sizeof(wbuf));
933     expect_eq(StrCpyNW(wbuf, 0, 10), wbuf, PWCHAR, "%p");
934     expect_eq(wbuf[0], 0, WCHAR, "%x");
935     expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
936
937     memset(wbuf, 0xbf, sizeof(wbuf));
938     expect_eq(StrCpyNW(wbuf, 0, 0), wbuf, PWCHAR, "%p");
939     expect_eq(wbuf[0], (WCHAR)0xbfbf, WCHAR, "%x");
940     expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
941
942     memset(wbuf, 0xbf, sizeof(wbuf));
943     expect_eq(StrCpyNW(wbuf, wstr1, 0), wbuf, PWCHAR, "%p");
944     expect_eq(wbuf[0], (WCHAR)0xbfbf, WCHAR, "%x");
945     expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
946
947     memset(wbuf, 0xbf, sizeof(wbuf));
948     expect_eq(StrCpyNW(wbuf, wstr1, 10), wbuf, PWCHAR, "%p");
949     expect_eq(wbuf[9], 0, WCHAR, "%x");
950     expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
951
952     if (pStrCatBuffW)
953     {
954         expect_eq(pStrCatBuffW(wbuf, wstr1, 100), wbuf, PWCHAR, "%p");
955         expect_eq(wbuf[99], 0, WCHAR, "%x");
956         expect_eq(wbuf[100], (WCHAR)0xbfbf, WCHAR, "%x");
957     }
958     else
959         win_skip("StrCatBuffW() is not available\n");
960
961     if (pStrRetToBufW)
962     {
963         memset(wbuf, 0xbf, sizeof(wbuf));
964         strret.uType = STRRET_WSTR;
965         U(strret).pOleStr = StrDupW(wstr1);
966         expect_eq2(pStrRetToBufW(&strret, NULL, wbuf, 10), S_OK, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) /* Vista */, HRESULT, "%x");
967         expect_eq(wbuf[9], 0, WCHAR, "%x");
968         expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
969     }
970     else
971         win_skip("StrRetToBufW() is not available\n");
972
973     if (pStrRetToBufA)
974     {
975         memset(buf, 0xbf, sizeof(buf));
976         strret.uType = STRRET_CSTR;
977         StrCpyN(U(strret).cStr, str1, MAX_PATH);
978         expect_eq2(pStrRetToBufA(&strret, NULL, buf, 10), S_OK, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) /* Vista */, HRESULT, "%x");
979         expect_eq(buf[9], 0, CHAR, "%x");
980         expect_eq(buf[10], (CHAR)0xbf, CHAR, "%x");
981     }
982     else
983         win_skip("StrRetToBufA() is not available\n");
984
985     if (pwnsprintfA)
986     {
987         memset(buf, 0xbf, sizeof(buf));
988         ret = pwnsprintfA(buf, 10, "%s", str1);
989         ok(broken(ret == 9) || ret == -1 /* Vista */, "Unexpected wnsprintfA return %d, expected 9 or -1\n", ret);
990         expect_eq(buf[9], 0, CHAR, "%x");
991         expect_eq(buf[10], (CHAR)0xbf, CHAR, "%x");
992     }
993     else
994         win_skip("wnsprintfA() is not available\n");
995
996     if (pwnsprintfW)
997     {
998         memset(wbuf, 0xbf, sizeof(wbuf));
999         ret = pwnsprintfW(wbuf, 10, fmt, wstr1);
1000         ok(broken(ret == 9) || ret == -1 /* Vista */, "Unexpected wnsprintfW return %d, expected 9 or -1\n", ret);
1001         expect_eq(wbuf[9], 0, WCHAR, "%x");
1002         expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
1003     }
1004     else
1005         win_skip("wnsprintfW() is not available\n");
1006 }
1007
1008 static void test_StrStrA(void)
1009 {
1010     static const char *deadbeefA = "DeAdBeEf";
1011
1012     const struct
1013     {
1014         const char *search;
1015         const char *expect;
1016     } StrStrA_cases[] =
1017     {
1018         {"", NULL},
1019         {"DeAd", deadbeefA},
1020         {"dead", NULL},
1021         {"AdBe", deadbeefA + 2},
1022         {"adbe", NULL},
1023         {"BeEf", deadbeefA + 4},
1024         {"beef", NULL},
1025     };
1026
1027     LPSTR ret;
1028     int i;
1029
1030     /* Tests crash on Win2k */
1031     if (0)
1032     {
1033         ret = StrStrA(NULL, NULL);
1034         ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret);
1035
1036         ret = StrStrA(NULL, "");
1037         ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret);
1038
1039         ret = StrStrA("", NULL);
1040         ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret);
1041     }
1042
1043     ret = StrStrA("", "");
1044     ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret);
1045
1046     for (i = 0; i < sizeof(StrStrA_cases)/sizeof(StrStrA_cases[0]); i++)
1047     {
1048         ret = StrStrA(deadbeefA, StrStrA_cases[i].search);
1049         ok(ret == StrStrA_cases[i].expect,
1050            "[%d] Expected StrStrA to return %p, got %p\n",
1051            i, StrStrA_cases[i].expect, ret);
1052     }
1053 }
1054
1055 static void test_StrStrW(void)
1056 {
1057     static const WCHAR emptyW[] = {0};
1058     static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
1059     static const WCHAR deadW[] = {'D','e','A','d',0};
1060     static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
1061     static const WCHAR adbeW[] = {'A','d','B','e',0};
1062     static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
1063     static const WCHAR beefW[] = {'B','e','E','f',0};
1064     static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
1065
1066     const struct
1067     {
1068         const WCHAR *search;
1069         const WCHAR *expect;
1070     } StrStrW_cases[] =
1071     {
1072         {emptyW, NULL},
1073         {deadW, deadbeefW},
1074         {dead_lowerW, NULL},
1075         {adbeW, deadbeefW + 2},
1076         {adbe_lowerW, NULL},
1077         {beefW, deadbeefW + 4},
1078         {beef_lowerW, NULL},
1079     };
1080
1081     LPWSTR ret;
1082     int i;
1083
1084     /* Tests crash on Win2k */
1085     if (0)
1086     {
1087         ret = StrStrW(NULL, NULL);
1088         ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
1089
1090         ret = StrStrW(NULL, emptyW);
1091         ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
1092
1093         ret = StrStrW(emptyW, NULL);
1094         ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
1095     }
1096
1097     ret = StrStrW(emptyW, emptyW);
1098     ok(!ret, "Expected StrStrW to return NULL, got %p\n", ret);
1099
1100     for (i = 0; i < sizeof(StrStrW_cases)/sizeof(StrStrW_cases[0]); i++)
1101     {
1102         ret = StrStrW(deadbeefW, StrStrW_cases[i].search);
1103         ok(ret == StrStrW_cases[i].expect,
1104            "[%d] Expected StrStrW to return %p, got %p\n",
1105            i, StrStrW_cases[i].expect, ret);
1106     }
1107 }
1108
1109 static void test_StrStrIA(void)
1110 {
1111     static const char *deadbeefA = "DeAdBeEf";
1112
1113     const struct
1114     {
1115         const char *search;
1116         const char *expect;
1117     } StrStrIA_cases[] =
1118     {
1119         {"", NULL},
1120         {"DeAd", deadbeefA},
1121         {"dead", deadbeefA},
1122         {"AdBe", deadbeefA + 2},
1123         {"adbe", deadbeefA + 2},
1124         {"BeEf", deadbeefA + 4},
1125         {"beef", deadbeefA + 4},
1126         {"cafe", NULL},
1127     };
1128
1129     LPSTR ret;
1130     int i;
1131
1132     /* Tests crash on Win2k */
1133     if (0)
1134     {
1135         ret = StrStrIA(NULL, NULL);
1136         ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret);
1137
1138         ret = StrStrIA(NULL, "");
1139         ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret);
1140
1141         ret = StrStrIA("", NULL);
1142         ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret);
1143     }
1144
1145     ret = StrStrIA("", "");
1146     ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret);
1147
1148     for (i = 0; i < sizeof(StrStrIA_cases)/sizeof(StrStrIA_cases[0]); i++)
1149     {
1150         ret = StrStrIA(deadbeefA, StrStrIA_cases[i].search);
1151         ok(ret == StrStrIA_cases[i].expect,
1152            "[%d] Expected StrStrIA to return %p, got %p\n",
1153            i, StrStrIA_cases[i].expect, ret);
1154     }
1155 }
1156
1157 static void test_StrStrIW(void)
1158 {
1159     static const WCHAR emptyW[] = {0};
1160     static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
1161     static const WCHAR deadW[] = {'D','e','A','d',0};
1162     static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
1163     static const WCHAR adbeW[] = {'A','d','B','e',0};
1164     static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
1165     static const WCHAR beefW[] = {'B','e','E','f',0};
1166     static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
1167     static const WCHAR cafeW[] = {'c','a','f','e',0};
1168
1169     const struct
1170     {
1171         const WCHAR *search;
1172         const WCHAR *expect;
1173     } StrStrIW_cases[] =
1174     {
1175         {emptyW, NULL},
1176         {deadW, deadbeefW},
1177         {dead_lowerW, deadbeefW},
1178         {adbeW, deadbeefW + 2},
1179         {adbe_lowerW, deadbeefW + 2},
1180         {beefW, deadbeefW + 4},
1181         {beef_lowerW, deadbeefW + 4},
1182         {cafeW, NULL},
1183     };
1184
1185     LPWSTR ret;
1186     int i;
1187
1188     /* Tests crash on Win2k */
1189     if (0)
1190     {
1191         ret = StrStrIW(NULL, NULL);
1192         ok(!ret, "Expected StrStrIW to return NULL, got %p\n", ret);
1193
1194         ret = StrStrIW(NULL, emptyW);
1195         ok(!ret, "Expected StrStrIW to return NULL, got %p\n", ret);
1196
1197         ret = StrStrIW(emptyW, NULL);
1198         ok(!ret, "Expected StrStrIW to return NULL, got %p\n", ret);
1199     }
1200
1201     ret = StrStrIW(emptyW, emptyW);
1202     ok(!ret, "Expected StrStrIW to return NULL, got %p\n", ret);
1203
1204     for (i = 0; i < sizeof(StrStrIW_cases)/sizeof(StrStrIW_cases[0]); i++)
1205     {
1206         ret = StrStrIW(deadbeefW, StrStrIW_cases[i].search);
1207         ok(ret == StrStrIW_cases[i].expect,
1208            "[%d] Expected StrStrIW to return %p, got %p\n",
1209            i, StrStrIW_cases[i].expect, ret);
1210     }
1211 }
1212
1213 static void test_StrStrNW(void)
1214 {
1215     static const WCHAR emptyW[] = {0};
1216     static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
1217     static const WCHAR deadW[] = {'D','e','A','d',0};
1218     static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
1219     static const WCHAR adbeW[] = {'A','d','B','e',0};
1220     static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
1221     static const WCHAR beefW[] = {'B','e','E','f',0};
1222     static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
1223
1224     const struct
1225     {
1226         const WCHAR *search;
1227         const UINT count;
1228         const WCHAR *expect;
1229     } StrStrNW_cases[] =
1230     {
1231         {emptyW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1232         {deadW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW},
1233         {dead_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1234         {adbeW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 2},
1235         {adbe_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1236         {beefW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 4},
1237         {beef_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1238         {beefW, 0, NULL},
1239         {beefW, 1, NULL},
1240         {beefW, 2, NULL},
1241         {beefW, 3, NULL},
1242         {beefW, 4, NULL},
1243         {beefW, 5, deadbeefW + 4},
1244         {beefW, 6, deadbeefW + 4},
1245         {beefW, 7, deadbeefW + 4},
1246         {beefW, 8, deadbeefW + 4},
1247         {beefW, 9, deadbeefW + 4},
1248     };
1249
1250     LPWSTR ret;
1251     UINT i;
1252
1253     if (!pStrStrNW)
1254     {
1255         win_skip("StrStrNW() is not available\n");
1256         return;
1257     }
1258
1259     ret = pStrStrNW(NULL, NULL, 0);
1260     ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1261
1262     ret = pStrStrNW(NULL, NULL, 10);
1263     ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1264
1265     ret = pStrStrNW(NULL, emptyW, 10);
1266     ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1267
1268     ret = pStrStrNW(emptyW, NULL, 10);
1269     ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1270
1271     ret = pStrStrNW(emptyW, emptyW, 10);
1272     ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1273
1274     for (i = 0; i < sizeof(StrStrNW_cases)/sizeof(StrStrNW_cases[0]); i++)
1275     {
1276         ret = pStrStrNW(deadbeefW, StrStrNW_cases[i].search, StrStrNW_cases[i].count);
1277         ok(ret == StrStrNW_cases[i].expect,
1278            "[%d] Expected StrStrNW to return %p, got %p\n",
1279            i, StrStrNW_cases[i].expect, ret);
1280     }
1281
1282     /* StrStrNW accepts counts larger than the search string length but rejects
1283      * counts larger than around 2G. The limit seems to change based on the
1284      * caller executable itself. */
1285     ret = pStrStrNW(deadbeefW, beefW, 100);
1286     ok(ret == deadbeefW + 4, "Expected StrStrNW to return deadbeefW + 4, got %p\n", ret);
1287
1288     if (0)
1289     {
1290         ret = pStrStrNW(deadbeefW, beefW, ~0U);
1291         ok(!ret, "Expected StrStrNW to return NULL, got %p\n", ret);
1292     }
1293 }
1294
1295 static void test_StrStrNIW(void)
1296 {
1297     static const WCHAR emptyW[] = {0};
1298     static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0};
1299     static const WCHAR deadW[] = {'D','e','A','d',0};
1300     static const WCHAR dead_lowerW[] = {'d','e','a','d',0};
1301     static const WCHAR adbeW[] = {'A','d','B','e',0};
1302     static const WCHAR adbe_lowerW[] = {'a','d','b','e',0};
1303     static const WCHAR beefW[] = {'B','e','E','f',0};
1304     static const WCHAR beef_lowerW[] = {'b','e','e','f',0};
1305     static const WCHAR cafeW[] = {'c','a','f','e',0};
1306
1307     const struct
1308     {
1309         const WCHAR *search;
1310         const UINT count;
1311         const WCHAR *expect;
1312     } StrStrNIW_cases[] =
1313     {
1314         {emptyW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1315         {deadW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW},
1316         {dead_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW},
1317         {adbeW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 2},
1318         {adbe_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 2},
1319         {beefW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 4},
1320         {beef_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 4},
1321         {cafeW, sizeof(deadbeefW)/sizeof(WCHAR), NULL},
1322         {beefW, 0, NULL},
1323         {beefW, 1, NULL},
1324         {beefW, 2, NULL},
1325         {beefW, 3, NULL},
1326         {beefW, 4, NULL},
1327         {beefW, 5, deadbeefW + 4},
1328         {beefW, 6, deadbeefW + 4},
1329         {beefW, 7, deadbeefW + 4},
1330         {beefW, 8, deadbeefW + 4},
1331         {beefW, 9, deadbeefW + 4},
1332         {beef_lowerW, 0, NULL},
1333         {beef_lowerW, 1, NULL},
1334         {beef_lowerW, 2, NULL},
1335         {beef_lowerW, 3, NULL},
1336         {beef_lowerW, 4, NULL},
1337         {beef_lowerW, 5, deadbeefW + 4},
1338         {beef_lowerW, 6, deadbeefW + 4},
1339         {beef_lowerW, 7, deadbeefW + 4},
1340         {beef_lowerW, 8, deadbeefW + 4},
1341         {beef_lowerW, 9, deadbeefW + 4},
1342     };
1343
1344     LPWSTR ret;
1345     UINT i;
1346
1347     if (!pStrStrNIW)
1348     {
1349         win_skip("StrStrNIW() is not available\n");
1350         return;
1351     }
1352
1353     ret = pStrStrNIW(NULL, NULL, 0);
1354     ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1355
1356     ret = pStrStrNIW(NULL, NULL, 10);
1357     ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1358
1359     ret = pStrStrNIW(NULL, emptyW, 10);
1360     ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1361
1362     ret = pStrStrNIW(emptyW, NULL, 10);
1363     ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1364
1365     ret = pStrStrNIW(emptyW, emptyW, 10);
1366     ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1367
1368     for (i = 0; i < sizeof(StrStrNIW_cases)/sizeof(StrStrNIW_cases[0]); i++)
1369     {
1370         ret = pStrStrNIW(deadbeefW, StrStrNIW_cases[i].search, StrStrNIW_cases[i].count);
1371         ok(ret == StrStrNIW_cases[i].expect,
1372            "[%d] Expected StrStrNIW to return %p, got %p\n",
1373            i, StrStrNIW_cases[i].expect, ret);
1374     }
1375
1376     /* StrStrNIW accepts counts larger than the search string length but rejects
1377      * counts larger than around 2G. The limit seems to change based on the
1378      * caller executable itself. */
1379     ret = pStrStrNIW(deadbeefW, beefW, 100);
1380     ok(ret == deadbeefW + 4, "Expected StrStrNIW to return deadbeefW + 4, got %p\n", ret);
1381
1382     if (0)
1383     {
1384         ret = pStrStrNIW(deadbeefW, beefW, ~0U);
1385         ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret);
1386     }
1387 }
1388
1389 START_TEST(string)
1390 {
1391   HMODULE hShlwapi;
1392   TCHAR thousandDelim[8];
1393   TCHAR decimalDelim[8];
1394   CoInitialize(0);
1395
1396   GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, thousandDelim, 8);
1397   GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, decimalDelim, 8);
1398
1399   hShlwapi = GetModuleHandleA("shlwapi");
1400   pChrCmpIA = (void *)GetProcAddress(hShlwapi, "ChrCmpIA");
1401   pChrCmpIW = (void *)GetProcAddress(hShlwapi, "ChrCmpIW");
1402   pIntlStrEqWorkerA = (void *)GetProcAddress(hShlwapi, "IntlStrEqWorkerA");
1403   pIntlStrEqWorkerW = (void *)GetProcAddress(hShlwapi, "IntlStrEqWorkerW");
1404   pSHAnsiToAnsi = (void *)GetProcAddress(hShlwapi, (LPSTR)345);
1405   pSHUnicodeToUnicode = (void *)GetProcAddress(hShlwapi, (LPSTR)346);
1406   pStrCatBuffA = (void *)GetProcAddress(hShlwapi, "StrCatBuffA");
1407   pStrCatBuffW = (void *)GetProcAddress(hShlwapi, "StrCatBuffW");
1408   pStrCpyNXA = (void *)GetProcAddress(hShlwapi, (LPSTR)399);
1409   pStrCpyNXW = (void *)GetProcAddress(hShlwapi, (LPSTR)400);
1410   pStrChrNW = (void *)GetProcAddress(hShlwapi, "StrChrNW");
1411   pStrFormatByteSize64A = (void *)GetProcAddress(hShlwapi, "StrFormatByteSize64A");
1412   pStrFormatKBSizeA = (void *)GetProcAddress(hShlwapi, "StrFormatKBSizeA");
1413   pStrFormatKBSizeW = (void *)GetProcAddress(hShlwapi, "StrFormatKBSizeW");
1414   pStrIsIntlEqualA = (void *)GetProcAddress(hShlwapi, "StrIsIntlEqualA");
1415   pStrIsIntlEqualW = (void *)GetProcAddress(hShlwapi, "StrIsIntlEqualW");
1416   pStrPBrkW = (void *)GetProcAddress(hShlwapi, "StrPBrkW");
1417   pStrRChrA = (void *)GetProcAddress(hShlwapi, "StrRChrA");
1418   pStrRetToBSTR = (void *)GetProcAddress(hShlwapi, "StrRetToBSTR");
1419   pStrRetToBufA = (void *)GetProcAddress(hShlwapi, "StrRetToBufA");
1420   pStrRetToBufW = (void *)GetProcAddress(hShlwapi, "StrRetToBufW");
1421   pStrStrNW = (void *)GetProcAddress(hShlwapi, "StrStrNW");
1422   pStrStrNIW = (void *)GetProcAddress(hShlwapi, "StrStrNIW");
1423   pwnsprintfA = (void *)GetProcAddress(hShlwapi, "wnsprintfA");
1424   pwnsprintfW = (void *)GetProcAddress(hShlwapi, "wnsprintfW");
1425
1426   test_StrChrA();
1427   test_StrChrW();
1428   test_StrChrIA();
1429   test_StrChrIW();
1430   test_StrRChrA();
1431   test_StrRChrW();
1432   test_StrCpyW();
1433   test_StrChrNW();
1434   test_StrToIntA();
1435   test_StrToIntW();
1436   test_StrToIntExA();
1437   test_StrToIntExW();
1438   test_StrDupA();
1439
1440   /* language-dependent test */
1441   if (is_lang_english() && is_locale_english())
1442   {
1443     test_StrFormatByteSize64A();
1444     test_StrFormatKBSizeA();
1445     test_StrFormatKBSizeW();
1446   }
1447   else
1448     skip("An English UI and locale is required for the StrFormat*Size tests\n");
1449   if (is_lang_english())
1450     test_StrFromTimeIntervalA();
1451   else
1452     skip("An English UI is required for the StrFromTimeInterval tests\n");
1453
1454   test_StrCmpA();
1455   test_StrCmpW();
1456   test_StrRetToBSTR();
1457   test_StrCpyNXA();
1458   test_StrCpyNXW();
1459   test_StrRStrI();
1460   test_SHAnsiToAnsi();
1461   test_SHUnicodeToUnicode();
1462   test_StrXXX_overflows();
1463   test_StrStrA();
1464   test_StrStrW();
1465   test_StrStrIA();
1466   test_StrStrIW();
1467   test_StrStrNW();
1468   test_StrStrNIW();
1469
1470   CoUninitialize();
1471 }