configure: Changes from running autconf after previous patch.
[wine/hacks.git] / dlls / shlwapi / tests / string.c
blob17c652de4110f46b3cb9cb02231a6c17c4d10ae3
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 HRESULT (WINAPI *pStrRetToBSTR)(STRRET*,void*,BSTR*);
59 static HRESULT (WINAPI *pStrRetToBufA)(STRRET*,LPCITEMIDLIST,LPSTR,UINT);
60 static HRESULT (WINAPI *pStrRetToBufW)(STRRET*,LPCITEMIDLIST,LPWSTR,UINT);
61 static INT (WINAPIV *pwnsprintfA)(LPSTR,INT,LPCSTR, ...);
62 static INT (WINAPIV *pwnsprintfW)(LPWSTR,INT,LPCWSTR, ...);
63 static LPWSTR (WINAPI *pStrChrNW)(LPWSTR,WCHAR,UINT);
65 static int strcmpW(const WCHAR *str1, const WCHAR *str2)
67 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
68 return *str1 - *str2;
71 /* StrToInt/StrToIntEx results */
72 typedef struct tagStrToIntResult
74 const char* string;
75 int str_to_int;
76 int str_to_int_ex;
77 int str_to_int_hex;
78 } StrToIntResult;
80 static const StrToIntResult StrToInt_results[] = {
81 { "1099", 1099, 1099, 1099 },
82 { "+88987", 0, 88987, 88987 },
83 { "012", 12, 12, 12 },
84 { "-55", -55, -55, -55 },
85 { "-0", 0, 0, 0 },
86 { "0x44ff", 0, 0, 0x44ff },
87 { "+0x44f4", 0, 0, 0x44f4 },
88 { "-0x44fd", 0, 0, 0x44fd },
89 { "+ 88987", 0, 0, 0 },
90 { "- 55", 0, 0, 0 },
91 { "- 0", 0, 0, 0 },
92 { "+ 0x44f4", 0, 0, 0 },
93 { "--0x44fd", 0, 0, 0 },
94 { " 1999", 0, 1999, 1999 },
95 { " +88987", 0, 88987, 88987 },
96 { " 012", 0, 12, 12 },
97 { " -55", 0, -55, -55 },
98 { " 0x44ff", 0, 0, 0x44ff },
99 { " +0x44f4", 0, 0, 0x44f4 },
100 { " -0x44fd", 0, 0, 0x44fd },
101 { NULL, 0, 0, 0 }
104 /* pStrFormatByteSize64/StrFormatKBSize results */
105 typedef struct tagStrFormatSizeResult
107 LONGLONG value;
108 const char* byte_size_64;
109 const char* kb_size;
110 } StrFormatSizeResult;
113 static const StrFormatSizeResult StrFormatSize_results[] = {
114 { -1023, "-1023 bytes", "0 KB"},
115 { -24, "-24 bytes", "0 KB"},
116 { 309, "309 bytes", "1 KB"},
117 { 10191, "9.95 KB", "10 KB"},
118 { 100353, "98.0 KB", "99 KB"},
119 { 1022286, "998 KB", "999 KB"},
120 { 1046862, "0.99 MB", "1,023 KB"},
121 { 1048574619, "999 MB", "1,023,999 KB"},
122 { 1073741775, "0.99 GB", "1,048,576 KB"},
123 { ((LONGLONG)0x000000f9 << 32) | 0xfffff94e, "999 GB", "1,048,575,999 KB"},
124 { ((LONGLONG)0x000000ff << 32) | 0xfffffa9b, "0.99 TB", "1,073,741,823 KB"},
125 { ((LONGLONG)0x0003e7ff << 32) | 0xfffffa9b, "999 TB", "1,073,741,823,999 KB"},
126 { ((LONGLONG)0x0003ffff << 32) | 0xfffffbe8, "0.99 PB", "1,099,511,627,775 KB"},
127 { ((LONGLONG)0x0f9fffff << 32) | 0xfffffd35, "999 PB", "1,099,511,627,776,000 KB"},
128 { ((LONGLONG)0x0fffffff << 32) | 0xfffffa9b, "0.99 EB", "1,125,899,906,842,623 KB"},
129 { 0, NULL, NULL }
132 /* StrFormatByteSize64/StrFormatKBSize results */
133 typedef struct tagStrFromTimeIntervalResult
135 DWORD ms;
136 int digits;
137 const char* time_interval;
138 } StrFromTimeIntervalResult;
141 static const StrFromTimeIntervalResult StrFromTimeInterval_results[] = {
142 { 1, 1, " 0 sec" },
143 { 1, 2, " 0 sec" },
144 { 1, 3, " 0 sec" },
145 { 1, 4, " 0 sec" },
146 { 1, 5, " 0 sec" },
147 { 1, 6, " 0 sec" },
148 { 1, 7, " 0 sec" },
150 { 1000000, 1, " 10 min" },
151 { 1000000, 2, " 16 min" },
152 { 1000000, 3, " 16 min 40 sec" },
153 { 1000000, 4, " 16 min 40 sec" },
154 { 1000000, 5, " 16 min 40 sec" },
155 { 1000000, 6, " 16 min 40 sec" },
156 { 1000000, 7, " 16 min 40 sec" },
158 { 1999999, 1, " 30 min" },
159 { 1999999, 2, " 33 min" },
160 { 1999999, 3, " 33 min 20 sec" },
161 { 1999999, 4, " 33 min 20 sec" },
162 { 1999999, 5, " 33 min 20 sec" },
163 { 1999999, 6, " 33 min 20 sec" },
164 { 1999999, 7, " 33 min 20 sec" },
166 { 3999997, 1, " 1 hr" },
167 { 3999997, 2, " 1 hr 6 min" },
168 { 3999997, 3, " 1 hr 6 min 40 sec" },
169 { 3999997, 4, " 1 hr 6 min 40 sec" },
170 { 3999997, 5, " 1 hr 6 min 40 sec" },
171 { 3999997, 6, " 1 hr 6 min 40 sec" },
172 { 3999997, 7, " 1 hr 6 min 40 sec" },
174 { 149999851, 7, " 41 hr 40 min 0 sec" },
175 { 150999850, 1, " 40 hr" },
176 { 150999850, 2, " 41 hr" },
177 { 150999850, 3, " 41 hr 50 min" },
178 { 150999850, 4, " 41 hr 56 min" },
179 { 150999850, 5, " 41 hr 56 min 40 sec" },
180 { 150999850, 6, " 41 hr 56 min 40 sec" },
181 { 150999850, 7, " 41 hr 56 min 40 sec" },
183 { 493999507, 1, " 100 hr" },
184 { 493999507, 2, " 130 hr" },
185 { 493999507, 3, " 137 hr" },
186 { 493999507, 4, " 137 hr 10 min" },
187 { 493999507, 5, " 137 hr 13 min" },
188 { 493999507, 6, " 137 hr 13 min 20 sec" },
189 { 493999507, 7, " 137 hr 13 min 20 sec" },
191 { 0, 0, NULL }
194 static void test_StrChrA(void)
196 char string[129];
197 WORD count;
199 /* this test crashes on win2k SP4 */
200 /*ok(!StrChrA(NULL,'\0'), "found a character in a NULL string!\n");*/
202 for (count = 32; count < 128; count++)
203 string[count] = (char)count;
204 string[128] = '\0';
206 for (count = 32; count < 128; count++)
208 LPSTR result = StrChrA(string+32, count);
209 INT pos = result - string;
210 ok(pos == count, "found char '%c' in wrong place: got %d, expected %d\n", count, pos, count);
213 for (count = 32; count < 128; count++)
215 LPSTR result = StrChrA(string+count+1, count);
216 ok(!result, "found char '%c' not in the string\n", count);
220 static void test_StrChrW(void)
222 WCHAR string[16385];
223 WORD count;
225 /* this test crashes on win2k SP4 */
226 /*ok(!StrChrW(NULL,'\0'), "found a character in a NULL string!\n");*/
228 for (count = 32; count < 16384; count++)
229 string[count] = count;
230 string[16384] = '\0';
232 for (count = 32; count < 16384; count++)
234 LPWSTR result = StrChrW(string+32, count);
235 ok((result - string) == count, "found char %d in wrong place\n", count);
238 for (count = 32; count < 16384; count++)
240 LPWSTR result = StrChrW(string+count+1, count);
241 ok(!result, "found char not in the string\n");
245 static void test_StrChrIA(void)
247 char string[129];
248 WORD count;
250 /* this test crashes on win2k SP4 */
251 /*ok(!StrChrIA(NULL,'\0'), "found a character in a NULL string!\n");*/
253 for (count = 32; count < 128; count++)
254 string[count] = (char)count;
255 string[128] = '\0';
257 for (count = 'A'; count <= 'X'; count++)
259 LPSTR result = StrChrIA(string+32, count);
261 ok(result - string == count, "found char '%c' in wrong place\n", count);
262 ok(StrChrIA(result, count)!=NULL, "didn't find lowercase '%c'\n", count);
265 for (count = 'a'; count < 'z'; count++)
267 LPSTR result = StrChrIA(string+count+1, count);
268 ok(!result, "found char not in the string\n");
272 static void test_StrChrIW(void)
274 WCHAR string[129];
275 WORD count;
277 /* this test crashes on win2k SP4 */
278 /*ok(!StrChrIA(NULL,'\0'), "found a character in a NULL string!\n");*/
280 for (count = 32; count < 128; count++)
281 string[count] = count;
282 string[128] = '\0';
284 for (count = 'A'; count <= 'X'; count++)
286 LPWSTR result = StrChrIW(string+32, count);
288 ok(result - string == count, "found char '%c' in wrong place\n", count);
289 ok(StrChrIW(result, count)!=NULL, "didn't find lowercase '%c'\n", count);
292 for (count = 'a'; count < 'z'; count++)
294 LPWSTR result = StrChrIW(string+count+1, count);
295 ok(!result, "found char not in the string\n");
299 static void test_StrRChrA(void)
301 char string[129];
302 WORD count;
304 /* this test crashes on win2k SP4 */
305 /*ok(!StrRChrA(NULL, NULL,'\0'), "found a character in a NULL string!\n");*/
307 for (count = 32; count < 128; count++)
308 string[count] = (char)count;
309 string[128] = '\0';
311 for (count = 32; count < 128; count++)
313 LPSTR result = StrRChrA(string+32, NULL, count);
314 ok(result - string == count, "found char %d in wrong place\n", count);
317 for (count = 32; count < 128; count++)
319 LPSTR result = StrRChrA(string+count+1, NULL, count);
320 ok(!result, "found char not in the string\n");
323 for (count = 32; count < 128; count++)
325 LPSTR result = StrRChrA(string+count+1, string + 127, count);
326 ok(!result, "found char not in the string\n");
330 static void test_StrRChrW(void)
332 WCHAR string[129];
333 WORD count;
335 /* this test crashes on win2k SP4 */
336 /*ok(!StrRChrW(NULL, NULL,'\0'), "found a character in a NULL string!\n");*/
338 for (count = 32; count < 128; count++)
339 string[count] = count;
340 string[128] = '\0';
342 for (count = 32; count < 128; count++)
344 LPWSTR result = StrRChrW(string+32, NULL, count);
345 INT pos = result - string;
346 ok(pos == count, "found char %d in wrong place: got %d, expected %d\n", count, pos, count);
349 for (count = 32; count < 128; count++)
351 LPWSTR result = StrRChrW(string+count+1, NULL, count);
352 ok(!result, "found char %d not in the string\n", count);
355 for (count = 32; count < 128; count++)
357 LPWSTR result = StrRChrW(string+count+1, string + 127, count);
358 ok(!result, "found char %d not in the string\n", count);
362 static void test_StrCpyW(void)
364 WCHAR szSrc[256];
365 WCHAR szBuff[256];
366 const StrFormatSizeResult* result = StrFormatSize_results;
369 while(result->value)
371 MultiByteToWideChar(0,0,result->byte_size_64,-1,szSrc,sizeof(szSrc)/sizeof(WCHAR));
373 StrCpyW(szBuff, szSrc);
374 ok(!StrCmpW(szSrc, szBuff), "Copied string %s wrong\n", result->byte_size_64);
375 result++;
379 static void test_StrChrNW(void)
381 static WCHAR string[] = {'T','e','s','t','i','n','g',' ','S','t','r','i','n','g',0};
382 LPWSTR p;
384 if (!pStrChrNW)
386 win_skip("StrChrNW not available\n");
387 return;
390 p = pStrChrNW(string,'t',10);
391 ok(*p=='t',"Found wrong 't'\n");
392 ok(*(p+1)=='i',"next should be 'i'\n");
394 p = pStrChrNW(string,'S',10);
395 ok(*p=='S',"Found wrong 'S'\n");
397 p = pStrChrNW(string,'r',10);
398 ok(p==NULL,"Should not have found 'r'\n");
401 static void test_StrToIntA(void)
403 const StrToIntResult *result = StrToInt_results;
404 int return_val;
406 while (result->string)
408 return_val = StrToIntA(result->string);
409 ok(return_val == result->str_to_int, "converted '%s' wrong (%d)\n",
410 result->string, return_val);
411 result++;
415 static void test_StrToIntW(void)
417 WCHAR szBuff[256];
418 const StrToIntResult *result = StrToInt_results;
419 int return_val;
421 while (result->string)
423 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
424 return_val = StrToIntW(szBuff);
425 ok(return_val == result->str_to_int, "converted '%s' wrong (%d)\n",
426 result->string, return_val);
427 result++;
431 static void test_StrToIntExA(void)
433 const StrToIntResult *result = StrToInt_results;
434 int return_val;
435 BOOL bRet;
437 while (result->string)
439 return_val = -1;
440 bRet = StrToIntExA(result->string,0,&return_val);
441 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
442 result->string);
443 if (bRet)
444 ok(return_val == result->str_to_int_ex, "converted '%s' wrong (%d)\n",
445 result->string, return_val);
446 result++;
449 result = StrToInt_results;
450 while (result->string)
452 return_val = -1;
453 bRet = StrToIntExA(result->string,STIF_SUPPORT_HEX,&return_val);
454 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
455 result->string);
456 if (bRet)
457 ok(return_val == result->str_to_int_hex, "converted '%s' wrong (%d)\n",
458 result->string, return_val);
459 result++;
463 static void test_StrToIntExW(void)
465 WCHAR szBuff[256];
466 const StrToIntResult *result = StrToInt_results;
467 int return_val;
468 BOOL bRet;
470 while (result->string)
472 return_val = -1;
473 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
474 bRet = StrToIntExW(szBuff, 0, &return_val);
475 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
476 result->string);
477 if (bRet)
478 ok(return_val == result->str_to_int_ex, "converted '%s' wrong (%d)\n",
479 result->string, return_val);
480 result++;
483 result = StrToInt_results;
484 while (result->string)
486 return_val = -1;
487 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
488 bRet = StrToIntExW(szBuff, STIF_SUPPORT_HEX, &return_val);
489 ok(!bRet || return_val != -1, "No result returned from '%s'\n",
490 result->string);
491 if (bRet)
492 ok(return_val == result->str_to_int_hex, "converted '%s' wrong (%d)\n",
493 result->string, return_val);
494 result++;
498 static void test_StrDupA(void)
500 LPSTR lpszStr;
501 const StrFormatSizeResult* result = StrFormatSize_results;
503 while(result->value)
505 lpszStr = StrDupA(result->byte_size_64);
507 ok(lpszStr != NULL, "Dup failed\n");
508 if (lpszStr)
510 ok(!strcmp(result->byte_size_64, lpszStr), "Copied string wrong\n");
511 LocalFree(lpszStr);
513 result++;
516 /* Later versions of shlwapi return NULL for this, but earlier versions
517 * returned an empty string (as Wine does).
519 lpszStr = StrDupA(NULL);
520 ok(lpszStr == NULL || *lpszStr == '\0', "NULL string returned %p\n", lpszStr);
521 LocalFree(lpszStr);
524 static void test_StrFormatByteSize64A(void)
526 char szBuff[256];
527 const StrFormatSizeResult* result = StrFormatSize_results;
529 if (!pStrFormatByteSize64A)
531 win_skip("StrFormatByteSize64A() is not available\n");
532 return;
535 while(result->value)
537 pStrFormatByteSize64A(result->value, szBuff, 256);
539 ok(!strcmp(result->byte_size_64, szBuff),
540 "Formatted %x%08x wrong: got %s, expected %s\n",
541 (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->byte_size_64);
543 result++;
547 static void test_StrFormatKBSizeW(void)
549 WCHAR szBuffW[256];
550 char szBuff[256];
551 const StrFormatSizeResult* result = StrFormatSize_results;
553 if (!pStrFormatKBSizeW)
555 win_skip("StrFormatKBSizeW() is not available\n");
556 return;
559 while(result->value)
561 pStrFormatKBSizeW(result->value, szBuffW, 256);
562 WideCharToMultiByte(0,0,szBuffW,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR),0,0);
563 ok(!strcmp(result->kb_size, szBuff),
564 "Formatted %x%08x wrong: got %s, expected %s\n",
565 (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->kb_size);
566 result++;
570 static void test_StrFormatKBSizeA(void)
572 char szBuff[256];
573 const StrFormatSizeResult* result = StrFormatSize_results;
575 if (!pStrFormatKBSizeA)
577 win_skip("StrFormatKBSizeA() is not available\n");
578 return;
581 while(result->value)
583 pStrFormatKBSizeA(result->value, szBuff, 256);
585 ok(!strcmp(result->kb_size, szBuff),
586 "Formatted %x%08x wrong: got %s, expected %s\n",
587 (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->kb_size);
588 result++;
592 static void test_StrFromTimeIntervalA(void)
594 char szBuff[256];
595 const StrFromTimeIntervalResult* result = StrFromTimeInterval_results;
597 while(result->ms)
599 StrFromTimeIntervalA(szBuff, 256, result->ms, result->digits);
601 ok(!strcmp(result->time_interval, szBuff), "Formatted %d %d wrong\n",
602 result->ms, result->digits);
603 result++;
607 static void test_StrCmpA(void)
609 static const char str1[] = {'a','b','c','d','e','f'};
610 static const char str2[] = {'a','B','c','d','e','f'};
611 ok(0 != StrCmpNA(str1, str2, 6), "StrCmpNA is case-insensitive\n");
612 ok(0 == StrCmpNIA(str1, str2, 6), "StrCmpNIA is case-sensitive\n");
613 if (pChrCmpIA) {
614 ok(!pChrCmpIA('a', 'a'), "ChrCmpIA doesn't work at all!\n");
615 ok(!pChrCmpIA('b', 'B'), "ChrCmpIA is not case-insensitive\n");
616 ok(pChrCmpIA('a', 'z'), "ChrCmpIA believes that a == z!\n");
618 else
619 win_skip("ChrCmpIA() is not available\n");
621 if (pStrIsIntlEqualA)
623 ok(pStrIsIntlEqualA(FALSE, str1, str2, 5), "StrIsIntlEqualA(FALSE,...) isn't case-insensitive\n");
624 ok(!pStrIsIntlEqualA(TRUE, str1, str2, 5), "StrIsIntlEqualA(TRUE,...) isn't case-sensitive\n");
626 else
627 win_skip("StrIsIntlEqualA() is not available\n");
629 if (pIntlStrEqWorkerA)
631 ok(pIntlStrEqWorkerA(FALSE, str1, str2, 5), "IntlStrEqWorkerA(FALSE,...) isn't case-insensitive\n");
632 ok(!pIntlStrEqWorkerA(TRUE, str1, str2, 5), "pIntlStrEqWorkerA(TRUE,...) isn't case-sensitive\n");
634 else
635 win_skip("IntlStrEqWorkerA() is not available\n");
638 static void test_StrCmpW(void)
640 static const WCHAR str1[] = {'a','b','c','d','e','f'};
641 static const WCHAR str2[] = {'a','B','c','d','e','f'};
642 ok(0 != StrCmpNW(str1, str2, 5), "StrCmpNW is case-insensitive\n");
643 ok(0 == StrCmpNIW(str1, str2, 5), "StrCmpNIW is case-sensitive\n");
644 if (pChrCmpIW) {
645 ok(!pChrCmpIW('a', 'a'), "ChrCmpIW doesn't work at all!\n");
646 ok(!pChrCmpIW('b', 'B'), "ChrCmpIW is not case-insensitive\n");
647 ok(pChrCmpIW('a', 'z'), "ChrCmpIW believes that a == z!\n");
649 else
650 win_skip("ChrCmpIW() is not available\n");
652 if (pStrIsIntlEqualW)
654 ok(pStrIsIntlEqualW(FALSE, str1, str2, 5), "StrIsIntlEqualW(FALSE,...) isn't case-insensitive\n");
655 ok(!pStrIsIntlEqualW(TRUE, str1, str2, 5), "StrIsIntlEqualW(TRUE,...) isn't case-sensitive\n");
657 else
658 win_skip("StrIsIntlEqualW() is not available\n");
660 if (pIntlStrEqWorkerW)
662 ok(pIntlStrEqWorkerW(FALSE, str1, str2, 5), "IntlStrEqWorkerW(FALSE,...) isn't case-insensitive\n");
663 ok(!pIntlStrEqWorkerW(TRUE, str1, str2, 5), "IntlStrEqWorkerW(TRUE,...) isn't case-sensitive\n");
665 else
666 win_skip("IntlStrEqWorkerW() is not available\n");
669 static WCHAR *CoDupStrW(const char* src)
671 INT len = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0);
672 WCHAR* szTemp = CoTaskMemAlloc(len * sizeof(WCHAR));
673 MultiByteToWideChar(CP_ACP, 0, src, -1, szTemp, len);
674 return szTemp;
677 static void test_StrRetToBSTR(void)
679 static const WCHAR szTestW[] = { 'T','e','s','t','\0' };
680 ITEMIDLIST iidl[10];
681 BSTR bstr;
682 STRRET strret;
683 HRESULT ret;
685 if (!pStrRetToBSTR)
687 win_skip("StrRetToBSTR() is not available\n");
688 return;
691 strret.uType = STRRET_WSTR;
692 U(strret).pOleStr = CoDupStrW("Test");
693 bstr = 0;
694 ret = pStrRetToBSTR(&strret, NULL, &bstr);
695 ok(ret == S_OK && bstr && !strcmpW(bstr, szTestW),
696 "STRRET_WSTR: dup failed, ret=0x%08x, bstr %p\n", ret, bstr);
697 SysFreeString(bstr);
699 strret.uType = STRRET_CSTR;
700 lstrcpyA(U(strret).cStr, "Test");
701 ret = pStrRetToBSTR(&strret, NULL, &bstr);
702 ok(ret == S_OK && bstr && !strcmpW(bstr, szTestW),
703 "STRRET_CSTR: dup failed, ret=0x%08x, bstr %p\n", ret, bstr);
704 SysFreeString(bstr);
706 strret.uType = STRRET_OFFSET;
707 U(strret).uOffset = 1;
708 strcpy((char*)&iidl, " Test");
709 ret = pStrRetToBSTR(&strret, iidl, &bstr);
710 ok(ret == S_OK && bstr && !strcmpW(bstr, szTestW),
711 "STRRET_OFFSET: dup failed, ret=0x%08x, bstr %p\n", ret, bstr);
712 SysFreeString(bstr);
714 /* Native crashes if str is NULL */
717 static void test_StrCpyNXA(void)
719 LPCSTR lpSrc = "hello";
720 LPSTR lpszRes;
721 char dest[8];
723 if (!pStrCpyNXA)
725 win_skip("StrCpyNXA() is not available\n");
726 return;
729 memset(dest, '\n', sizeof(dest));
730 lpszRes = pStrCpyNXA(dest, lpSrc, sizeof(dest)/sizeof(dest[0]));
731 ok(lpszRes == dest + 5 && !memcmp(dest, "hello\0\n\n", sizeof(dest)),
732 "StrCpyNXA: expected %p, \"hello\\0\\n\\n\", got %p, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
733 dest + 5, lpszRes, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
736 static void test_StrCpyNXW(void)
738 static const WCHAR lpInit[] = { '\n','\n','\n','\n','\n','\n','\n','\n' };
739 static const WCHAR lpSrc[] = { 'h','e','l','l','o','\0' };
740 static const WCHAR lpRes[] = { 'h','e','l','l','o','\0','\n','\n' };
741 LPWSTR lpszRes;
742 WCHAR dest[8];
744 if (!pStrCpyNXW)
746 win_skip("StrCpyNXW() is not available\n");
747 return;
750 memcpy(dest, lpInit, sizeof(lpInit));
751 lpszRes = pStrCpyNXW(dest, lpSrc, sizeof(dest)/sizeof(dest[0]));
752 ok(lpszRes == dest + 5 && !memcmp(dest, lpRes, sizeof(dest)),
753 "StrCpyNXW: expected %p, \"hello\\0\\n\\n\", got %p, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
754 dest + 5, lpszRes, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
757 #define check_strrstri(type, str, pos, needle, exp) \
758 ret##type = StrRStrI##type(str, str+pos, needle); \
759 ok(ret##type == (exp), "Type " #type ", expected %p but got %p (string base %p)\n", \
760 (exp), ret##type, str);
762 static void test_StrRStrI(void)
764 static const CHAR szTest[] = "yAxxxxAy";
765 static const CHAR szTest2[] = "ABABABAB";
766 static const WCHAR wszTest[] = {'y','A','x','x','x','x','A','y',0};
767 static const WCHAR wszTest2[] = {'A','B','A','B','A','B','A','B',0};
769 static const WCHAR wszPattern1[] = {'A',0};
770 static const WCHAR wszPattern2[] = {'a','X',0};
771 static const WCHAR wszPattern3[] = {'A','y',0};
772 static const WCHAR wszPattern4[] = {'a','b',0};
773 LPWSTR retW;
774 LPSTR retA;
776 check_strrstri(A, szTest, 4, "A", szTest+1);
777 check_strrstri(A, szTest, 4, "aX", szTest+1);
778 check_strrstri(A, szTest, 4, "Ay", NULL);
779 check_strrstri(W, wszTest, 4, wszPattern1, wszTest+1);
780 check_strrstri(W, wszTest, 4, wszPattern2, wszTest+1);
781 check_strrstri(W, wszTest, 4, wszPattern3, NULL);
783 check_strrstri(A, szTest2, 4, "ab", szTest2+2);
784 check_strrstri(A, szTest2, 3, "ab", szTest2+2);
785 check_strrstri(A, szTest2, 2, "ab", szTest2);
786 check_strrstri(A, szTest2, 1, "ab", szTest2);
787 check_strrstri(A, szTest2, 0, "ab", NULL);
788 check_strrstri(W, wszTest2, 4, wszPattern4, wszTest2+2);
789 check_strrstri(W, wszTest2, 3, wszPattern4, wszTest2+2);
790 check_strrstri(W, wszTest2, 2, wszPattern4, wszTest2);
791 check_strrstri(W, wszTest2, 1, wszPattern4, wszTest2);
792 check_strrstri(W, wszTest2, 0, wszPattern4, NULL);
796 static void test_SHAnsiToAnsi(void)
798 char dest[8];
799 DWORD dwRet;
801 if (!pSHAnsiToAnsi)
803 win_skip("SHAnsiToAnsi() is not available\n");
804 return;
807 memset(dest, '\n', sizeof(dest));
808 dwRet = pSHAnsiToAnsi("hello", dest, sizeof(dest)/sizeof(dest[0]));
809 ok(dwRet == 6 && !memcmp(dest, "hello\0\n\n", sizeof(dest)),
810 "SHAnsiToAnsi: expected 6, \"hello\\0\\n\\n\", got %d, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
811 dwRet, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
814 static void test_SHUnicodeToUnicode(void)
816 static const WCHAR lpInit[] = { '\n','\n','\n','\n','\n','\n','\n','\n' };
817 static const WCHAR lpSrc[] = { 'h','e','l','l','o','\0' };
818 static const WCHAR lpRes[] = { 'h','e','l','l','o','\0','\n','\n' };
819 WCHAR dest[8];
820 DWORD dwRet;
822 if (!pSHUnicodeToUnicode)
824 win_skip("SHUnicodeToUnicode() is not available\n");
825 return;
828 memcpy(dest, lpInit, sizeof(lpInit));
829 dwRet = pSHUnicodeToUnicode(lpSrc, dest, sizeof(dest)/sizeof(dest[0]));
830 ok(dwRet == 6 && !memcmp(dest, lpRes, sizeof(dest)),
831 "SHUnicodeToUnicode: expected 6, \"hello\\0\\n\\n\", got %d, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
832 dwRet, dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
835 static void test_StrXXX_overflows(void)
837 CHAR str1[2*MAX_PATH+1], buf[2*MAX_PATH];
838 WCHAR wstr1[2*MAX_PATH+1], wbuf[2*MAX_PATH];
839 const WCHAR fmt[] = {'%','s',0};
840 STRRET strret;
841 int ret;
842 int i;
844 for (i=0; i<2*MAX_PATH; i++)
846 str1[i] = '0'+(i%10);
847 wstr1[i] = '0'+(i%10);
849 str1[2*MAX_PATH] = 0;
850 wstr1[2*MAX_PATH] = 0;
852 memset(buf, 0xbf, sizeof(buf));
853 expect_eq(StrCpyNA(buf, str1, 10), buf, PCHAR, "%p");
854 expect_eq(buf[9], 0, CHAR, "%x");
855 expect_eq(buf[10], '\xbf', CHAR, "%x");
857 if (pStrCatBuffA)
859 expect_eq(pStrCatBuffA(buf, str1, 100), buf, PCHAR, "%p");
860 expect_eq(buf[99], 0, CHAR, "%x");
861 expect_eq(buf[100], '\xbf', CHAR, "%x");
863 else
864 win_skip("StrCatBuffA() is not available\n");
866 if (0)
868 /* crashes on XP */
869 StrCpyNW(wbuf, (LPCWSTR)0x1, 10);
870 StrCpyNW((LPWSTR)0x1, wstr1, 10);
873 memset(wbuf, 0xbf, sizeof(wbuf));
874 expect_eq(StrCpyNW(wbuf, (LPCWSTR)0x1, 1), wbuf, PWCHAR, "%p");
875 expect_eq(wbuf[0], 0, WCHAR, "%x");
876 expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
878 memset(wbuf, 0xbf, sizeof(wbuf));
879 expect_eq(StrCpyNW(wbuf, 0, 10), wbuf, PWCHAR, "%p");
880 expect_eq(wbuf[0], 0, WCHAR, "%x");
881 expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
883 memset(wbuf, 0xbf, sizeof(wbuf));
884 expect_eq(StrCpyNW(wbuf, 0, 0), wbuf, PWCHAR, "%p");
885 expect_eq(wbuf[0], (WCHAR)0xbfbf, WCHAR, "%x");
886 expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
888 memset(wbuf, 0xbf, sizeof(wbuf));
889 expect_eq(StrCpyNW(wbuf, wstr1, 0), wbuf, PWCHAR, "%p");
890 expect_eq(wbuf[0], (WCHAR)0xbfbf, WCHAR, "%x");
891 expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
893 memset(wbuf, 0xbf, sizeof(wbuf));
894 expect_eq(StrCpyNW(wbuf, wstr1, 10), wbuf, PWCHAR, "%p");
895 expect_eq(wbuf[9], 0, WCHAR, "%x");
896 expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
898 if (pStrCatBuffW)
900 expect_eq(pStrCatBuffW(wbuf, wstr1, 100), wbuf, PWCHAR, "%p");
901 expect_eq(wbuf[99], 0, WCHAR, "%x");
902 expect_eq(wbuf[100], (WCHAR)0xbfbf, WCHAR, "%x");
904 else
905 win_skip("StrCatBuffW() is not available\n");
907 if (pStrRetToBufW)
909 memset(wbuf, 0xbf, sizeof(wbuf));
910 strret.uType = STRRET_WSTR;
911 U(strret).pOleStr = StrDupW(wstr1);
912 expect_eq2(pStrRetToBufW(&strret, NULL, wbuf, 10), S_OK, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) /* Vista */, HRESULT, "%x");
913 expect_eq(wbuf[9], 0, WCHAR, "%x");
914 expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
916 else
917 win_skip("StrRetToBufW() is not available\n");
919 if (pStrRetToBufA)
921 memset(buf, 0xbf, sizeof(buf));
922 strret.uType = STRRET_CSTR;
923 StrCpyN(U(strret).cStr, str1, MAX_PATH);
924 expect_eq2(pStrRetToBufA(&strret, NULL, buf, 10), S_OK, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) /* Vista */, HRESULT, "%x");
925 expect_eq(buf[9], 0, CHAR, "%x");
926 expect_eq(buf[10], (CHAR)0xbf, CHAR, "%x");
928 else
929 win_skip("StrRetToBufA() is not available\n");
931 if (pwnsprintfA)
933 memset(buf, 0xbf, sizeof(buf));
934 ret = pwnsprintfA(buf, 10, "%s", str1);
935 ok(broken(ret == 9) || ret == -1 /* Vista */, "Unexpected wsnprintfA return %d, expected 9 or -1\n", ret);
936 expect_eq(buf[9], 0, CHAR, "%x");
937 expect_eq(buf[10], (CHAR)0xbf, CHAR, "%x");
939 else
940 win_skip("wnsprintfA() is not available\n");
942 if (pwnsprintfW)
944 memset(wbuf, 0xbf, sizeof(wbuf));
945 ret = pwnsprintfW(wbuf, 10, fmt, wstr1);
946 ok(broken(ret == 9) || ret == -1 /* Vista */, "Unexpected wsnprintfW return %d, expected 9 or -1\n", ret);
947 expect_eq(wbuf[9], 0, WCHAR, "%x");
948 expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
950 else
951 win_skip("wnsprintfW() is not available\n");
954 START_TEST(string)
956 HMODULE hShlwapi;
957 TCHAR thousandDelim[8];
958 TCHAR decimalDelim[8];
959 CoInitialize(0);
961 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, thousandDelim, 8);
962 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, decimalDelim, 8);
964 hShlwapi = GetModuleHandleA("shlwapi");
965 pChrCmpIA = (void *)GetProcAddress(hShlwapi, "ChrCmpIA");
966 pChrCmpIW = (void *)GetProcAddress(hShlwapi, "ChrCmpIW");
967 pIntlStrEqWorkerA = (void *)GetProcAddress(hShlwapi, "IntlStrEqWorkerA");
968 pIntlStrEqWorkerW = (void *)GetProcAddress(hShlwapi, "IntlStrEqWorkerW");
969 pSHAnsiToAnsi = (void *)GetProcAddress(hShlwapi, (LPSTR)345);
970 pSHUnicodeToUnicode = (void *)GetProcAddress(hShlwapi, (LPSTR)346);
971 pStrCatBuffA = (void *)GetProcAddress(hShlwapi, "StrCatBuffA");
972 pStrCatBuffW = (void *)GetProcAddress(hShlwapi, "StrCatBuffW");
973 pStrCpyNXA = (void *)GetProcAddress(hShlwapi, (LPSTR)399);
974 pStrCpyNXW = (void *)GetProcAddress(hShlwapi, (LPSTR)400);
975 pStrChrNW = (void *)GetProcAddress(hShlwapi, "StrChrNW");
976 pStrFormatByteSize64A = (void *)GetProcAddress(hShlwapi, "StrFormatByteSize64A");
977 pStrFormatKBSizeA = (void *)GetProcAddress(hShlwapi, "StrFormatKBSizeA");
978 pStrFormatKBSizeW = (void *)GetProcAddress(hShlwapi, "StrFormatKBSizeW");
979 pStrIsIntlEqualA = (void *)GetProcAddress(hShlwapi, "StrIsIntlEqualA");
980 pStrIsIntlEqualW = (void *)GetProcAddress(hShlwapi, "StrIsIntlEqualW");
981 pStrRetToBSTR = (void *)GetProcAddress(hShlwapi, "StrRetToBSTR");
982 pStrRetToBufA = (void *)GetProcAddress(hShlwapi, "StrRetToBufA");
983 pStrRetToBufW = (void *)GetProcAddress(hShlwapi, "StrRetToBufW");
984 pwnsprintfA = (void *)GetProcAddress(hShlwapi, "wnsprintfA");
985 pwnsprintfW = (void *)GetProcAddress(hShlwapi, "wnsprintfW");
987 test_StrChrA();
988 test_StrChrW();
989 test_StrChrIA();
990 test_StrChrIW();
991 test_StrRChrA();
992 test_StrRChrW();
993 test_StrCpyW();
994 test_StrChrNW();
995 test_StrToIntA();
996 test_StrToIntW();
997 test_StrToIntExA();
998 test_StrToIntExW();
999 test_StrDupA();
1000 if (lstrcmp(thousandDelim, ",")==0 && lstrcmp(decimalDelim, ".")==0)
1002 /* these tests are locale-dependent */
1003 test_StrFormatByteSize64A();
1004 test_StrFormatKBSizeA();
1005 test_StrFormatKBSizeW();
1008 /* language-dependent test */
1009 if (PRIMARYLANGID(GetUserDefaultLangID()) != LANG_ENGLISH)
1010 trace("Skipping StrFromTimeInterval test for non English language\n");
1011 else
1012 test_StrFromTimeIntervalA();
1014 test_StrCmpA();
1015 test_StrCmpW();
1016 test_StrRetToBSTR();
1017 test_StrCpyNXA();
1018 test_StrCpyNXW();
1019 test_StrRStrI();
1020 test_SHAnsiToAnsi();
1021 test_SHUnicodeToUnicode();
1022 test_StrXXX_overflows();
1024 CoUninitialize();