1 /* Unit test suite for SHLWAPI string functions
3 * Copyright 2003 Jon Griffiths
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/test.h"
26 #define NO_SHLWAPI_REG
27 #define NO_SHLWAPI_PATH
28 #define NO_SHLWAPI_GDI
29 #define NO_SHLWAPI_STREAM
33 #define expect_eq(expr, val, type, fmt) do { \
35 ok(ret == val, "Unexpected value of '" #expr "': " #fmt " instead of " #val "\n", ret); \
38 #define expect_eq2(expr, val1, val2, type, fmt) do { \
40 ok(ret == val1 || ret == val2, "Unexpected value of '" #expr "': " #fmt " instead of " #val1 " or " #val2 "\n", ret); \
43 static BOOL (WINAPI
*pChrCmpIA
)(CHAR
, CHAR
);
44 static BOOL (WINAPI
*pChrCmpIW
)(WCHAR
, WCHAR
);
45 static BOOL (WINAPI
*pIntlStrEqWorkerA
)(BOOL
,LPCSTR
,LPCSTR
,int);
46 static BOOL (WINAPI
*pIntlStrEqWorkerW
)(BOOL
,LPCWSTR
,LPCWSTR
,int);
47 static DWORD (WINAPI
*pSHAnsiToAnsi
)(LPCSTR
,LPSTR
,int);
48 static DWORD (WINAPI
*pSHUnicodeToUnicode
)(LPCWSTR
,LPWSTR
,int);
49 static LPSTR (WINAPI
*pStrCatBuffA
)(LPSTR
,LPCSTR
,INT
);
50 static LPWSTR (WINAPI
*pStrCatBuffW
)(LPWSTR
,LPCWSTR
,INT
);
51 static LPSTR (WINAPI
*pStrCpyNXA
)(LPSTR
,LPCSTR
,int);
52 static LPWSTR (WINAPI
*pStrCpyNXW
)(LPWSTR
,LPCWSTR
,int);
53 static LPSTR (WINAPI
*pStrFormatByteSize64A
)(LONGLONG
,LPSTR
,UINT
);
54 static LPSTR (WINAPI
*pStrFormatKBSizeA
)(LONGLONG
,LPSTR
,UINT
);
55 static LPWSTR (WINAPI
*pStrFormatKBSizeW
)(LONGLONG
,LPWSTR
,UINT
);
56 static BOOL (WINAPI
*pStrIsIntlEqualA
)(BOOL
,LPCSTR
,LPCSTR
,int);
57 static BOOL (WINAPI
*pStrIsIntlEqualW
)(BOOL
,LPCWSTR
,LPCWSTR
,int);
58 static 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
++; }
71 /* StrToInt/StrToIntEx results */
72 typedef struct tagStrToIntResult
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 },
86 { "0x44ff", 0, 0, 0x44ff },
87 { "+0x44f4", 0, 0, 0x44f4 },
88 { "-0x44fd", 0, 0, 0x44fd },
89 { "+ 88987", 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 },
104 /* pStrFormatByteSize64/StrFormatKBSize results */
105 typedef struct tagStrFormatSizeResult
108 const char* byte_size_64
;
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"},
132 /* StrFormatByteSize64/StrFormatKBSize results */
133 typedef struct tagStrFromTimeIntervalResult
137 const char* time_interval
;
138 } StrFromTimeIntervalResult
;
141 static const StrFromTimeIntervalResult StrFromTimeInterval_results
[] = {
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" },
194 static void test_StrChrA(void)
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
;
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)
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)
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
;
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)
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
;
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)
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
;
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)
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
;
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)
366 const StrFormatSizeResult
* result
= StrFormatSize_results
;
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
);
379 static void test_StrChrNW(void)
381 static WCHAR string
[] = {'T','e','s','t','i','n','g',' ','S','t','r','i','n','g',0};
386 win_skip("StrChrNW not available\n");
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
;
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
);
415 static void test_StrToIntW(void)
418 const StrToIntResult
*result
= StrToInt_results
;
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
);
431 static void test_StrToIntExA(void)
433 const StrToIntResult
*result
= StrToInt_results
;
437 while (result
->string
)
440 bRet
= StrToIntExA(result
->string
,0,&return_val
);
441 ok(!bRet
|| return_val
!= -1, "No result returned from '%s'\n",
444 ok(return_val
== result
->str_to_int_ex
, "converted '%s' wrong (%d)\n",
445 result
->string
, return_val
);
449 result
= StrToInt_results
;
450 while (result
->string
)
453 bRet
= StrToIntExA(result
->string
,STIF_SUPPORT_HEX
,&return_val
);
454 ok(!bRet
|| return_val
!= -1, "No result returned from '%s'\n",
457 ok(return_val
== result
->str_to_int_hex
, "converted '%s' wrong (%d)\n",
458 result
->string
, return_val
);
463 static void test_StrToIntExW(void)
466 const StrToIntResult
*result
= StrToInt_results
;
470 while (result
->string
)
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",
478 ok(return_val
== result
->str_to_int_ex
, "converted '%s' wrong (%d)\n",
479 result
->string
, return_val
);
483 result
= StrToInt_results
;
484 while (result
->string
)
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",
492 ok(return_val
== result
->str_to_int_hex
, "converted '%s' wrong (%d)\n",
493 result
->string
, return_val
);
498 static void test_StrDupA(void)
501 const StrFormatSizeResult
* result
= StrFormatSize_results
;
505 lpszStr
= StrDupA(result
->byte_size_64
);
507 ok(lpszStr
!= NULL
, "Dup failed\n");
510 ok(!strcmp(result
->byte_size_64
, lpszStr
), "Copied string wrong\n");
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
);
524 static void test_StrFormatByteSize64A(void)
527 const StrFormatSizeResult
* result
= StrFormatSize_results
;
529 if (!pStrFormatByteSize64A
)
531 win_skip("StrFormatByteSize64A() is not available\n");
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
);
547 static void test_StrFormatKBSizeW(void)
551 const StrFormatSizeResult
* result
= StrFormatSize_results
;
553 if (!pStrFormatKBSizeW
)
555 win_skip("StrFormatKBSizeW() is not available\n");
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
);
570 static void test_StrFormatKBSizeA(void)
573 const StrFormatSizeResult
* result
= StrFormatSize_results
;
575 if (!pStrFormatKBSizeA
)
577 win_skip("StrFormatKBSizeA() is not available\n");
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
);
592 static void test_StrFromTimeIntervalA(void)
595 const StrFromTimeIntervalResult
* result
= StrFromTimeInterval_results
;
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
);
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");
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");
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");
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");
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");
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");
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");
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");
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
);
677 static void test_StrRetToBSTR(void)
679 static const WCHAR szTestW
[] = { 'T','e','s','t','\0' };
687 win_skip("StrRetToBSTR() is not available\n");
691 strret
.uType
= STRRET_WSTR
;
692 U(strret
).pOleStr
= CoDupStrW("Test");
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
);
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
);
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
);
714 /* Native crashes if str is NULL */
717 static void test_StrCpyNXA(void)
719 LPCSTR lpSrc
= "hello";
725 win_skip("StrCpyNXA() is not available\n");
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' };
746 win_skip("StrCpyNXW() is not available\n");
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};
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)
803 win_skip("SHAnsiToAnsi() is not available\n");
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' };
822 if (!pSHUnicodeToUnicode
)
824 win_skip("SHUnicodeToUnicode() is not available\n");
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};
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");
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");
864 win_skip("StrCatBuffA() is not available\n");
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");
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");
905 win_skip("StrCatBuffW() is not available\n");
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");
917 win_skip("StrRetToBufW() is not available\n");
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");
929 win_skip("StrRetToBufA() is not available\n");
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");
940 win_skip("wnsprintfA() is not available\n");
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");
951 win_skip("wnsprintfW() is not available\n");
957 TCHAR thousandDelim
[8];
958 TCHAR decimalDelim
[8];
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");
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");
1012 test_StrFromTimeIntervalA();
1016 test_StrRetToBSTR();
1020 test_SHAnsiToAnsi();
1021 test_SHUnicodeToUnicode();
1022 test_StrXXX_overflows();