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 #define WIN32_NO_STATUS
22 #define COM_NO_WINDOWS_H
26 #include <wine/test.h>
27 //#include "winbase.h"
28 //#include "winerror.h"
31 #define NO_SHLWAPI_REG
32 #define NO_SHLWAPI_PATH
33 #define NO_SHLWAPI_GDI
34 #define NO_SHLWAPI_STREAM
36 //#include "shtypes.h"
38 #define expect_eq(expr, val, type, fmt) do { \
40 ok(ret == val, "Unexpected value of '" #expr "': " #fmt " instead of " #val "\n", ret); \
43 #define expect_eq2(expr, val1, val2, type, fmt) do { \
45 ok(ret == val1 || ret == val2, "Unexpected value of '" #expr "': " #fmt " instead of " #val1 " or " #val2 "\n", ret); \
48 static BOOL (WINAPI
*pChrCmpIA
)(CHAR
, CHAR
);
49 static BOOL (WINAPI
*pChrCmpIW
)(WCHAR
, WCHAR
);
50 static BOOL (WINAPI
*pIntlStrEqWorkerA
)(BOOL
,LPCSTR
,LPCSTR
,int);
51 static BOOL (WINAPI
*pIntlStrEqWorkerW
)(BOOL
,LPCWSTR
,LPCWSTR
,int);
52 static DWORD (WINAPI
*pSHAnsiToAnsi
)(LPCSTR
,LPSTR
,int);
53 static DWORD (WINAPI
*pSHUnicodeToUnicode
)(LPCWSTR
,LPWSTR
,int);
54 static LPSTR (WINAPI
*pStrCatBuffA
)(LPSTR
,LPCSTR
,INT
);
55 static LPWSTR (WINAPI
*pStrCatBuffW
)(LPWSTR
,LPCWSTR
,INT
);
56 static DWORD (WINAPI
*pStrCatChainW
)(LPWSTR
,DWORD
,DWORD
,LPCWSTR
);
57 static LPSTR (WINAPI
*pStrCpyNXA
)(LPSTR
,LPCSTR
,int);
58 static LPWSTR (WINAPI
*pStrCpyNXW
)(LPWSTR
,LPCWSTR
,int);
59 static LPSTR (WINAPI
*pStrFormatByteSize64A
)(LONGLONG
,LPSTR
,UINT
);
60 static LPSTR (WINAPI
*pStrFormatKBSizeA
)(LONGLONG
,LPSTR
,UINT
);
61 static LPWSTR (WINAPI
*pStrFormatKBSizeW
)(LONGLONG
,LPWSTR
,UINT
);
62 static BOOL (WINAPI
*pStrIsIntlEqualA
)(BOOL
,LPCSTR
,LPCSTR
,int);
63 static BOOL (WINAPI
*pStrIsIntlEqualW
)(BOOL
,LPCWSTR
,LPCWSTR
,int);
64 static LPWSTR (WINAPI
*pStrPBrkW
)(LPCWSTR
,LPCWSTR
);
65 static LPSTR (WINAPI
*pStrRChrA
)(LPCSTR
,LPCSTR
,WORD
);
66 static HRESULT (WINAPI
*pStrRetToBSTR
)(STRRET
*,LPCITEMIDLIST
,BSTR
*);
67 static HRESULT (WINAPI
*pStrRetToBufA
)(STRRET
*,LPCITEMIDLIST
,LPSTR
,UINT
);
68 static HRESULT (WINAPI
*pStrRetToBufW
)(STRRET
*,LPCITEMIDLIST
,LPWSTR
,UINT
);
69 static LPWSTR (WINAPI
*pStrStrNW
)(LPCWSTR
,LPCWSTR
,UINT
);
70 static LPWSTR (WINAPI
*pStrStrNIW
)(LPCWSTR
,LPCWSTR
,UINT
);
71 static INT (WINAPIV
*pwnsprintfA
)(LPSTR
,INT
,LPCSTR
, ...);
72 static INT (WINAPIV
*pwnsprintfW
)(LPWSTR
,INT
,LPCWSTR
, ...);
73 static LPWSTR (WINAPI
*pStrChrNW
)(LPCWSTR
,WCHAR
,UINT
);
74 static BOOL (WINAPI
*pStrToInt64ExA
)(LPCSTR
,DWORD
,LONGLONG
*);
75 static BOOL (WINAPI
*pStrToInt64ExW
)(LPCWSTR
,DWORD
,LONGLONG
*);
77 static int strcmpW(const WCHAR
*str1
, const WCHAR
*str2
)
79 while (*str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
83 /* StrToInt/StrToIntEx results */
84 typedef struct tagStrToIntResult
88 LONGLONG str_to_int64_ex
;
89 LONGLONG str_to_int64_hex
;
92 static const StrToIntResult StrToInt_results
[] = {
93 { "1099", 1099, 1099, 1099 },
94 { "4294967319", 23, ((LONGLONG
)1 << 32) | 23, ((LONGLONG
)1 << 32) | 23 },
95 { "+88987", 0, 88987, 88987 },
96 { "012", 12, 12, 12 },
97 { "-55", -55, -55, -55 },
99 { "0x44ff", 0, 0, 0x44ff },
100 { "0x2bdc546291f4b1", 0, 0, ((LONGLONG
)0x2bdc54 << 32) | 0x6291f4b1 },
101 { "+0x44f4", 0, 0, 0x44f4 },
102 { "-0x44fd", 0, 0, 0x44fd },
103 { "+ 88987", 0, 0, 0 },
106 { "+ 0x44f4", 0, 0, 0 },
107 { "--0x44fd", 0, 0, 0 },
108 { " 1999", 0, 1999, 1999 },
109 { " +88987", 0, 88987, 88987 },
110 { " 012", 0, 12, 12 },
111 { " -55", 0, -55, -55 },
112 { " 0x44ff", 0, 0, 0x44ff },
113 { " +0x44f4", 0, 0, 0x44f4 },
114 { " -0x44fd", 0, 0, 0x44fd },
118 /* pStrFormatByteSize64/StrFormatKBSize results */
119 typedef struct tagStrFormatSizeResult
122 const char* byte_size_64
;
125 const char* kb_size2
;
126 } StrFormatSizeResult
;
129 static const StrFormatSizeResult StrFormatSize_results
[] = {
130 { -1023, "-1023 bytes", "0 KB"},
131 { -24, "-24 bytes", "0 KB"},
132 { 309, "309 bytes", "1 KB"},
133 { 10191, "9.95 KB", "10 KB"},
134 { 100353, "98.0 KB", "99 KB"},
135 { 1022286, "998 KB", "999 KB"},
136 { 1046862, "0.99 MB", "1,023 KB", 1, "1023 KB"},
137 { 1048574619, "999 MB", "1,023,999 KB", 1, "1023999 KB"},
138 { 1073741775, "0.99 GB", "1,048,576 KB", 1, "1048576 KB"},
139 { ((LONGLONG
)0x000000f9 << 32) | 0xfffff94e, "999 GB", "1,048,575,999 KB", 1, "1048575999 KB"},
140 { ((LONGLONG
)0x000000ff << 32) | 0xfffffa9b, "0.99 TB", "1,073,741,823 KB", 1, "1073741823 KB"},
141 { ((LONGLONG
)0x0003e7ff << 32) | 0xfffffa9b, "999 TB", "1,073,741,823,999 KB", 1, "4294967295 KB"},
142 { ((LONGLONG
)0x0003ffff << 32) | 0xfffffbe8, "0.99 PB", "1,099,511,627,775 KB", 1, "4294967295 KB"},
143 { ((LONGLONG
)0x0f9fffff << 32) | 0xfffffd35, "999 PB", "1,099,511,627,776,000 KB", 1, "0 KB"},
144 { ((LONGLONG
)0x0fffffff << 32) | 0xfffffa9b, "0.99 EB", "1,125,899,906,842,623 KB", 1, "4294967295 KB"},
148 /* StrFromTimeIntervalA/StrFromTimeIntervalW results */
149 typedef struct tagStrFromTimeIntervalResult
153 const char* time_interval
;
154 } StrFromTimeIntervalResult
;
157 static const StrFromTimeIntervalResult StrFromTimeInterval_results
[] = {
166 { 1000000, 1, " 10 min" },
167 { 1000000, 2, " 16 min" },
168 { 1000000, 3, " 16 min 40 sec" },
169 { 1000000, 4, " 16 min 40 sec" },
170 { 1000000, 5, " 16 min 40 sec" },
171 { 1000000, 6, " 16 min 40 sec" },
172 { 1000000, 7, " 16 min 40 sec" },
174 { 1999999, 1, " 30 min" },
175 { 1999999, 2, " 33 min" },
176 { 1999999, 3, " 33 min 20 sec" },
177 { 1999999, 4, " 33 min 20 sec" },
178 { 1999999, 5, " 33 min 20 sec" },
179 { 1999999, 6, " 33 min 20 sec" },
180 { 1999999, 7, " 33 min 20 sec" },
182 { 3999997, 1, " 1 hr" },
183 { 3999997, 2, " 1 hr 6 min" },
184 { 3999997, 3, " 1 hr 6 min 40 sec" },
185 { 3999997, 4, " 1 hr 6 min 40 sec" },
186 { 3999997, 5, " 1 hr 6 min 40 sec" },
187 { 3999997, 6, " 1 hr 6 min 40 sec" },
188 { 3999997, 7, " 1 hr 6 min 40 sec" },
190 { 149999851, 7, " 41 hr 40 min 0 sec" },
191 { 150999850, 1, " 40 hr" },
192 { 150999850, 2, " 41 hr" },
193 { 150999850, 3, " 41 hr 50 min" },
194 { 150999850, 4, " 41 hr 56 min" },
195 { 150999850, 5, " 41 hr 56 min 40 sec" },
196 { 150999850, 6, " 41 hr 56 min 40 sec" },
197 { 150999850, 7, " 41 hr 56 min 40 sec" },
199 { 493999507, 1, " 100 hr" },
200 { 493999507, 2, " 130 hr" },
201 { 493999507, 3, " 137 hr" },
202 { 493999507, 4, " 137 hr 10 min" },
203 { 493999507, 5, " 137 hr 13 min" },
204 { 493999507, 6, " 137 hr 13 min 20 sec" },
205 { 493999507, 7, " 137 hr 13 min 20 sec" },
211 /* Returns true if the user interface is in English. Note that this does not
212 * presume of the formatting of dates, numbers, etc.
214 static BOOL
is_lang_english(void)
216 static HMODULE hkernel32
= NULL
;
217 static LANGID (WINAPI
*pGetThreadUILanguage
)(void) = NULL
;
218 static LANGID (WINAPI
*pGetUserDefaultUILanguage
)(void) = NULL
;
222 hkernel32
= GetModuleHandleA("kernel32.dll");
223 pGetThreadUILanguage
= (void*)GetProcAddress(hkernel32
, "GetThreadUILanguage");
224 pGetUserDefaultUILanguage
= (void*)GetProcAddress(hkernel32
, "GetUserDefaultUILanguage");
226 if (pGetThreadUILanguage
)
227 return PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH
;
228 if (pGetUserDefaultUILanguage
)
229 return PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH
;
231 return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH
;
234 /* Returns true if the dates, numbers, etc. are formatted using English
237 static BOOL
is_locale_english(void)
239 /* Surprisingly GetThreadLocale() is irrelevant here */
240 return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH
;
243 static void test_StrChrA(void)
248 /* this test crashes on win2k SP4 */
249 /*ok(!StrChrA(NULL,'\0'), "found a character in a NULL string!\n");*/
251 for (count
= 32; count
< 128; count
++)
252 string
[count
] = (char)count
;
255 for (count
= 32; count
< 128; count
++)
257 LPSTR result
= StrChrA(string
+32, count
);
258 INT pos
= result
- string
;
259 ok(pos
== count
, "found char '%c' in wrong place: got %d, expected %d\n", count
, pos
, count
);
262 for (count
= 32; count
< 128; count
++)
264 LPSTR result
= StrChrA(string
+count
+1, count
);
265 ok(!result
, "found char '%c' not in the string\n", count
);
269 static void test_StrChrW(void)
274 /* this test crashes on win2k SP4 */
275 /*ok(!StrChrW(NULL,'\0'), "found a character in a NULL string!\n");*/
277 for (count
= 32; count
< 16384; count
++)
278 string
[count
] = count
;
279 string
[16384] = '\0';
281 for (count
= 32; count
< 16384; count
++)
283 LPWSTR result
= StrChrW(string
+32, count
);
284 ok((result
- string
) == count
, "found char %d in wrong place\n", count
);
287 for (count
= 32; count
< 16384; count
++)
289 LPWSTR result
= StrChrW(string
+count
+1, count
);
290 ok(!result
, "found char not in the string\n");
294 static void test_StrChrIA(void)
299 /* this test crashes on win2k SP4 */
300 /*ok(!StrChrIA(NULL,'\0'), "found a character in a NULL string!\n");*/
302 for (count
= 32; count
< 128; count
++)
303 string
[count
] = (char)count
;
306 for (count
= 'A'; count
<= 'X'; count
++)
308 LPSTR result
= StrChrIA(string
+32, count
);
310 ok(result
- string
== count
, "found char '%c' in wrong place\n", count
);
311 ok(StrChrIA(result
, count
)!=NULL
, "didn't find lowercase '%c'\n", count
);
314 for (count
= 'a'; count
< 'z'; count
++)
316 LPSTR result
= StrChrIA(string
+count
+1, count
);
317 ok(!result
, "found char not in the string\n");
321 static void test_StrChrIW(void)
326 /* this test crashes on win2k SP4 */
327 /*ok(!StrChrIA(NULL,'\0'), "found a character in a NULL string!\n");*/
329 for (count
= 32; count
< 128; count
++)
330 string
[count
] = count
;
333 for (count
= 'A'; count
<= 'X'; count
++)
335 LPWSTR result
= StrChrIW(string
+32, count
);
337 ok(result
- string
== count
, "found char '%c' in wrong place\n", count
);
338 ok(StrChrIW(result
, count
)!=NULL
, "didn't find lowercase '%c'\n", count
);
341 for (count
= 'a'; count
< 'z'; count
++)
343 LPWSTR result
= StrChrIW(string
+count
+1, count
);
344 ok(!result
, "found char not in the string\n");
348 static void test_StrRChrA(void)
353 /* this test crashes on win2k SP4 */
354 /*ok(!StrRChrA(NULL, NULL,'\0'), "found a character in a NULL string!\n");*/
356 for (count
= 32; count
< 128; count
++)
357 string
[count
] = (char)count
;
360 for (count
= 32; count
< 128; count
++)
362 LPSTR result
= StrRChrA(string
+32, NULL
, count
);
363 ok(result
- string
== count
, "found char %d in wrong place\n", count
);
366 for (count
= 32; count
< 128; count
++)
368 LPSTR result
= StrRChrA(string
+count
+1, NULL
, count
);
369 ok(!result
, "found char not in the string\n");
372 for (count
= 32; count
< 128; count
++)
374 LPSTR result
= StrRChrA(string
+count
+1, string
+ 127, count
);
375 ok(!result
, "found char not in the string\n");
379 static void test_StrRChrW(void)
384 /* this test crashes on win2k SP4 */
385 /*ok(!StrRChrW(NULL, NULL,'\0'), "found a character in a NULL string!\n");*/
387 for (count
= 32; count
< 128; count
++)
388 string
[count
] = count
;
391 for (count
= 32; count
< 128; count
++)
393 LPWSTR result
= StrRChrW(string
+32, NULL
, count
);
394 INT pos
= result
- string
;
395 ok(pos
== count
, "found char %d in wrong place: got %d, expected %d\n", count
, pos
, count
);
398 for (count
= 32; count
< 128; count
++)
400 LPWSTR result
= StrRChrW(string
+count
+1, NULL
, count
);
401 ok(!result
, "found char %d not in the string\n", count
);
404 for (count
= 32; count
< 128; count
++)
406 LPWSTR result
= StrRChrW(string
+count
+1, string
+ 127, count
);
407 ok(!result
, "found char %d not in the string\n", count
);
411 static void test_StrCpyW(void)
415 const StrFormatSizeResult
* result
= StrFormatSize_results
;
420 MultiByteToWideChar(CP_ACP
,0,result
->byte_size_64
,-1,szSrc
,sizeof(szSrc
)/sizeof(WCHAR
));
422 lpRes
= StrCpyW(szBuff
, szSrc
);
423 ok(!StrCmpW(szSrc
, szBuff
) && lpRes
== szBuff
, "Copied string %s wrong\n", result
->byte_size_64
);
427 /* this test crashes on win2k SP4 */
428 /*lpRes = StrCpyW(szBuff, NULL);*/
429 /*ok(lpRes == szBuff, "Wrong return value: got %p expected %p\n", lpRes, szBuff);*/
431 /* this test crashes on win2k SP4 */
432 /*lpRes = StrCpyW(NULL, szSrc);*/
433 /*ok(lpRes == NULL, "Wrong return value: got %p expected NULL\n", lpRes);*/
435 /* this test crashes on win2k SP4 */
436 /*lpRes = StrCpyW(NULL, NULL);*/
437 /*ok(lpRes == NULL, "Wrong return value: got %p expected NULL\n", lpRes);*/
440 static void test_StrChrNW(void)
442 static const WCHAR string
[] = {'T','e','s','t','i','n','g',' ','S','t','r','i','n','g',0};
447 win_skip("StrChrNW not available\n");
451 p
= pStrChrNW(string
,'t',10);
452 ok(*p
=='t',"Found wrong 't'\n");
453 ok(*(p
+1)=='i',"next should be 'i'\n");
455 p
= pStrChrNW(string
,'S',10);
456 ok(*p
=='S',"Found wrong 'S'\n");
458 p
= pStrChrNW(string
,'r',10);
459 ok(p
==NULL
,"Should not have found 'r'\n");
462 static void test_StrToIntA(void)
464 const StrToIntResult
*result
= StrToInt_results
;
467 while (result
->string
)
469 return_val
= StrToIntA(result
->string
);
470 ok(return_val
== result
->str_to_int
, "converted '%s' wrong (%d)\n",
471 result
->string
, return_val
);
476 static void test_StrToIntW(void)
479 const StrToIntResult
*result
= StrToInt_results
;
482 while (result
->string
)
484 MultiByteToWideChar(CP_ACP
,0,result
->string
,-1,szBuff
,sizeof(szBuff
)/sizeof(WCHAR
));
485 return_val
= StrToIntW(szBuff
);
486 ok(return_val
== result
->str_to_int
, "converted '%s' wrong (%d)\n",
487 result
->string
, return_val
);
492 static void test_StrToIntExA(void)
494 const StrToIntResult
*result
= StrToInt_results
;
498 while (result
->string
)
501 bRet
= StrToIntExA(result
->string
,0,&return_val
);
502 ok(!bRet
|| return_val
!= -1, "No result returned from '%s'\n",
505 ok(return_val
== (int)result
->str_to_int64_ex
, "converted '%s' wrong (%d)\n",
506 result
->string
, return_val
);
510 result
= StrToInt_results
;
511 while (result
->string
)
514 bRet
= StrToIntExA(result
->string
,STIF_SUPPORT_HEX
,&return_val
);
515 ok(!bRet
|| return_val
!= -1, "No result returned from '%s'\n",
518 ok(return_val
== (int)result
->str_to_int64_hex
, "converted '%s' wrong (%d)\n",
519 result
->string
, return_val
);
524 static void test_StrToIntExW(void)
527 const StrToIntResult
*result
= StrToInt_results
;
531 while (result
->string
)
534 MultiByteToWideChar(CP_ACP
,0,result
->string
,-1,szBuff
,sizeof(szBuff
)/sizeof(WCHAR
));
535 bRet
= StrToIntExW(szBuff
, 0, &return_val
);
536 ok(!bRet
|| return_val
!= -1, "No result returned from '%s'\n",
539 ok(return_val
== (int)result
->str_to_int64_ex
, "converted '%s' wrong (%d)\n",
540 result
->string
, return_val
);
544 result
= StrToInt_results
;
545 while (result
->string
)
548 MultiByteToWideChar(CP_ACP
,0,result
->string
,-1,szBuff
,sizeof(szBuff
)/sizeof(WCHAR
));
549 bRet
= StrToIntExW(szBuff
, STIF_SUPPORT_HEX
, &return_val
);
550 ok(!bRet
|| return_val
!= -1, "No result returned from '%s'\n",
553 ok(return_val
== (int)result
->str_to_int64_hex
, "converted '%s' wrong (%d)\n",
554 result
->string
, return_val
);
559 static void test_StrToInt64ExA(void)
561 const StrToIntResult
*result
= StrToInt_results
;
567 win_skip("StrToInt64ExA() is not available\n");
571 while (result
->string
)
574 bRet
= pStrToInt64ExA(result
->string
,0,&return_val
);
575 ok(!bRet
|| return_val
!= -1, "No result returned from '%s'\n",
578 ok(return_val
== result
->str_to_int64_ex
, "converted '%s' wrong (%08x%08x)\n",
579 result
->string
, (DWORD
)(return_val
>> 32), (DWORD
)return_val
);
583 result
= StrToInt_results
;
584 while (result
->string
)
587 bRet
= pStrToInt64ExA(result
->string
,STIF_SUPPORT_HEX
,&return_val
);
588 ok(!bRet
|| return_val
!= -1, "No result returned from '%s'\n",
591 ok(return_val
== result
->str_to_int64_hex
, "converted '%s' wrong (%08x%08x)\n",
592 result
->string
, (DWORD
)(return_val
>> 32), (DWORD
)return_val
);
597 static void test_StrToInt64ExW(void)
600 const StrToIntResult
*result
= StrToInt_results
;
606 win_skip("StrToInt64ExW() is not available\n");
610 while (result
->string
)
613 MultiByteToWideChar(CP_ACP
,0,result
->string
,-1,szBuff
,sizeof(szBuff
)/sizeof(WCHAR
));
614 bRet
= pStrToInt64ExW(szBuff
, 0, &return_val
);
615 ok(!bRet
|| return_val
!= -1, "No result returned from '%s'\n",
618 ok(return_val
== result
->str_to_int64_ex
, "converted '%s' wrong (%08x%08x)\n",
619 result
->string
, (DWORD
)(return_val
>> 32), (DWORD
)return_val
);
623 result
= StrToInt_results
;
624 while (result
->string
)
627 MultiByteToWideChar(CP_ACP
,0,result
->string
,-1,szBuff
,sizeof(szBuff
)/sizeof(WCHAR
));
628 bRet
= pStrToInt64ExW(szBuff
, STIF_SUPPORT_HEX
, &return_val
);
629 ok(!bRet
|| return_val
!= -1, "No result returned from '%s'\n",
632 ok(return_val
== result
->str_to_int64_hex
, "converted '%s' wrong (%08x%08x)\n",
633 result
->string
, (DWORD
)(return_val
>> 32), (DWORD
)return_val
);
638 static void test_StrDupA(void)
641 const StrFormatSizeResult
* result
= StrFormatSize_results
;
645 lpszStr
= StrDupA(result
->byte_size_64
);
647 ok(lpszStr
!= NULL
, "Dup failed\n");
650 ok(!strcmp(result
->byte_size_64
, lpszStr
), "Copied string wrong\n");
656 /* Later versions of shlwapi return NULL for this, but earlier versions
657 * returned an empty string (as Wine does).
659 lpszStr
= StrDupA(NULL
);
660 ok(lpszStr
== NULL
|| *lpszStr
== '\0', "NULL string returned %p\n", lpszStr
);
664 static void test_StrFormatByteSize64A(void)
667 const StrFormatSizeResult
* result
= StrFormatSize_results
;
669 if (!pStrFormatByteSize64A
)
671 win_skip("StrFormatByteSize64A() is not available\n");
677 pStrFormatByteSize64A(result
->value
, szBuff
, 256);
679 ok(!strcmp(result
->byte_size_64
, szBuff
),
680 "Formatted %x%08x wrong: got %s, expected %s\n",
681 (LONG
)(result
->value
>> 32), (LONG
)result
->value
, szBuff
, result
->byte_size_64
);
687 static void test_StrFormatKBSizeW(void)
691 const StrFormatSizeResult
* result
= StrFormatSize_results
;
693 if (!pStrFormatKBSizeW
)
695 win_skip("StrFormatKBSizeW() is not available\n");
701 pStrFormatKBSizeW(result
->value
, szBuffW
, 256);
702 WideCharToMultiByte(CP_ACP
,0,szBuffW
,-1,szBuff
,sizeof(szBuff
)/sizeof(WCHAR
),NULL
,NULL
);
704 ok(!strcmp(result
->kb_size
, szBuff
), "Formatted %x%08x wrong: got %s, expected %s\n",
705 (LONG
)(result
->value
>> 32), (LONG
)result
->value
, szBuff
, result
->kb_size
);
710 static void test_StrFormatKBSizeA(void)
713 const StrFormatSizeResult
* result
= StrFormatSize_results
;
715 if (!pStrFormatKBSizeA
)
717 win_skip("StrFormatKBSizeA() is not available\n");
723 pStrFormatKBSizeA(result
->value
, szBuff
, 256);
725 /* shlwapi on Win98 SE does not appear to apply delimiters to the output
726 * and does not correctly handle extremely large values. */
727 ok(!strcmp(result
->kb_size
, szBuff
) ||
728 (result
->kb_size_broken
&& !strcmp(result
->kb_size2
, szBuff
)),
729 "Formatted %x%08x wrong: got %s, expected %s\n",
730 (LONG
)(result
->value
>> 32), (LONG
)result
->value
, szBuff
, result
->kb_size
);
735 static void test_StrFromTimeIntervalA(void)
738 const StrFromTimeIntervalResult
* result
= StrFromTimeInterval_results
;
742 StrFromTimeIntervalA(szBuff
, 256, result
->ms
, result
->digits
);
744 ok(!strcmp(result
->time_interval
, szBuff
), "Formatted %d %d wrong: %s\n",
745 result
->ms
, result
->digits
, szBuff
);
750 static void test_StrCmpA(void)
752 static const char str1
[] = {'a','b','c','d','e','f'};
753 static const char str2
[] = {'a','B','c','d','e','f'};
754 ok(0 != StrCmpNA(str1
, str2
, 6), "StrCmpNA is case-insensitive\n");
755 ok(0 == StrCmpNIA(str1
, str2
, 6), "StrCmpNIA is case-sensitive\n");
757 ok(!pChrCmpIA('a', 'a'), "ChrCmpIA doesn't work at all!\n");
758 ok(!pChrCmpIA('b', 'B'), "ChrCmpIA is not case-insensitive\n");
759 ok(pChrCmpIA('a', 'z'), "ChrCmpIA believes that a == z!\n");
762 win_skip("ChrCmpIA() is not available\n");
764 if (pStrIsIntlEqualA
)
766 ok(pStrIsIntlEqualA(FALSE
, str1
, str2
, 5), "StrIsIntlEqualA(FALSE,...) isn't case-insensitive\n");
767 ok(!pStrIsIntlEqualA(TRUE
, str1
, str2
, 5), "StrIsIntlEqualA(TRUE,...) isn't case-sensitive\n");
770 win_skip("StrIsIntlEqualA() is not available\n");
772 if (pIntlStrEqWorkerA
)
774 ok(pIntlStrEqWorkerA(FALSE
, str1
, str2
, 5), "IntlStrEqWorkerA(FALSE,...) isn't case-insensitive\n");
775 ok(!pIntlStrEqWorkerA(TRUE
, str1
, str2
, 5), "pIntlStrEqWorkerA(TRUE,...) isn't case-sensitive\n");
778 win_skip("IntlStrEqWorkerA() is not available\n");
781 static void test_StrCmpW(void)
783 static const WCHAR str1
[] = {'a','b','c','d','e','f'};
784 static const WCHAR str2
[] = {'a','B','c','d','e','f'};
785 ok(0 != StrCmpNW(str1
, str2
, 5), "StrCmpNW is case-insensitive\n");
786 ok(0 == StrCmpNIW(str1
, str2
, 5), "StrCmpNIW is case-sensitive\n");
788 ok(!pChrCmpIW('a', 'a'), "ChrCmpIW doesn't work at all!\n");
789 ok(!pChrCmpIW('b', 'B'), "ChrCmpIW is not case-insensitive\n");
790 ok(pChrCmpIW('a', 'z'), "ChrCmpIW believes that a == z!\n");
793 win_skip("ChrCmpIW() is not available\n");
795 if (pStrIsIntlEqualW
)
797 ok(pStrIsIntlEqualW(FALSE
, str1
, str2
, 5), "StrIsIntlEqualW(FALSE,...) isn't case-insensitive\n");
798 ok(!pStrIsIntlEqualW(TRUE
, str1
, str2
, 5), "StrIsIntlEqualW(TRUE,...) isn't case-sensitive\n");
801 win_skip("StrIsIntlEqualW() is not available\n");
803 if (pIntlStrEqWorkerW
)
805 ok(pIntlStrEqWorkerW(FALSE
, str1
, str2
, 5), "IntlStrEqWorkerW(FALSE,...) isn't case-insensitive\n");
806 ok(!pIntlStrEqWorkerW(TRUE
, str1
, str2
, 5), "IntlStrEqWorkerW(TRUE,...) isn't case-sensitive\n");
809 win_skip("IntlStrEqWorkerW() is not available\n");
812 static WCHAR
*CoDupStrW(const char* src
)
814 INT len
= MultiByteToWideChar(CP_ACP
, 0, src
, -1, NULL
, 0);
815 WCHAR
* szTemp
= CoTaskMemAlloc(len
* sizeof(WCHAR
));
816 MultiByteToWideChar(CP_ACP
, 0, src
, -1, szTemp
, len
);
820 static void test_StrRetToBSTR(void)
822 static const WCHAR szTestW
[] = { 'T','e','s','t','\0' };
830 win_skip("StrRetToBSTR() is not available\n");
834 strret
.uType
= STRRET_WSTR
;
835 U(strret
).pOleStr
= CoDupStrW("Test");
837 ret
= pStrRetToBSTR(&strret
, NULL
, &bstr
);
838 ok(ret
== S_OK
&& bstr
&& !strcmpW(bstr
, szTestW
),
839 "STRRET_WSTR: dup failed, ret=0x%08x, bstr %p\n", ret
, bstr
);
842 strret
.uType
= STRRET_CSTR
;
843 lstrcpyA(U(strret
).cStr
, "Test");
844 ret
= pStrRetToBSTR(&strret
, NULL
, &bstr
);
845 ok(ret
== S_OK
&& bstr
&& !strcmpW(bstr
, szTestW
),
846 "STRRET_CSTR: dup failed, ret=0x%08x, bstr %p\n", ret
, bstr
);
849 strret
.uType
= STRRET_OFFSET
;
850 U(strret
).uOffset
= 1;
851 strcpy((char*)&iidl
, " Test");
852 ret
= pStrRetToBSTR(&strret
, iidl
, &bstr
);
853 ok(ret
== S_OK
&& bstr
&& !strcmpW(bstr
, szTestW
),
854 "STRRET_OFFSET: dup failed, ret=0x%08x, bstr %p\n", ret
, bstr
);
857 /* Native crashes if str is NULL */
860 static void test_StrCpyNXA(void)
862 LPCSTR lpSrc
= "hello";
868 win_skip("StrCpyNXA() is not available\n");
872 memset(dest
, '\n', sizeof(dest
));
873 lpszRes
= pStrCpyNXA(dest
, lpSrc
, sizeof(dest
)/sizeof(dest
[0]));
874 ok(lpszRes
== dest
+ 5 && !memcmp(dest
, "hello\0\n\n", sizeof(dest
)),
875 "StrCpyNXA: expected %p, \"hello\\0\\n\\n\", got %p, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
876 dest
+ 5, lpszRes
, dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
879 static void test_StrCpyNXW(void)
881 static const WCHAR lpInit
[] = { '\n','\n','\n','\n','\n','\n','\n','\n' };
882 static const WCHAR lpSrc
[] = { 'h','e','l','l','o','\0' };
883 static const WCHAR lpRes
[] = { 'h','e','l','l','o','\0','\n','\n' };
889 win_skip("StrCpyNXW() is not available\n");
893 memcpy(dest
, lpInit
, sizeof(lpInit
));
894 lpszRes
= pStrCpyNXW(dest
, lpSrc
, sizeof(dest
)/sizeof(dest
[0]));
895 ok(lpszRes
== dest
+ 5 && !memcmp(dest
, lpRes
, sizeof(dest
)),
896 "StrCpyNXW: expected %p, \"hello\\0\\n\\n\", got %p, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
897 dest
+ 5, lpszRes
, dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
900 #define check_strrstri(type, str, pos, needle, exp) \
901 ret##type = StrRStrI##type(str, str+pos, needle); \
902 ok(ret##type == (exp), "Type " #type ", expected %p but got %p (string base %p)\n", \
903 (exp), ret##type, str);
905 static void test_StrRStrI(void)
907 static const CHAR szTest
[] = "yAxxxxAy";
908 static const CHAR szTest2
[] = "ABABABAB";
909 static const WCHAR wszTest
[] = {'y','A','x','x','x','x','A','y',0};
910 static const WCHAR wszTest2
[] = {'A','B','A','B','A','B','A','B',0};
912 static const WCHAR wszPattern1
[] = {'A',0};
913 static const WCHAR wszPattern2
[] = {'a','X',0};
914 static const WCHAR wszPattern3
[] = {'A','y',0};
915 static const WCHAR wszPattern4
[] = {'a','b',0};
919 check_strrstri(A
, szTest
, 4, "A", szTest
+1);
920 check_strrstri(A
, szTest
, 4, "aX", szTest
+1);
921 check_strrstri(A
, szTest
, 4, "Ay", NULL
);
922 check_strrstri(W
, wszTest
, 4, wszPattern1
, wszTest
+1);
923 check_strrstri(W
, wszTest
, 4, wszPattern2
, wszTest
+1);
924 check_strrstri(W
, wszTest
, 4, wszPattern3
, NULL
);
926 check_strrstri(A
, szTest2
, 4, "ab", szTest2
+2);
927 check_strrstri(A
, szTest2
, 3, "ab", szTest2
+2);
928 check_strrstri(A
, szTest2
, 2, "ab", szTest2
);
929 check_strrstri(A
, szTest2
, 1, "ab", szTest2
);
930 check_strrstri(A
, szTest2
, 0, "ab", NULL
);
931 check_strrstri(W
, wszTest2
, 4, wszPattern4
, wszTest2
+2);
932 check_strrstri(W
, wszTest2
, 3, wszPattern4
, wszTest2
+2);
933 check_strrstri(W
, wszTest2
, 2, wszPattern4
, wszTest2
);
934 check_strrstri(W
, wszTest2
, 1, wszPattern4
, wszTest2
);
935 check_strrstri(W
, wszTest2
, 0, wszPattern4
, NULL
);
939 static void test_SHAnsiToAnsi(void)
946 win_skip("SHAnsiToAnsi() is not available\n");
950 if (pSHAnsiToAnsi
== (void *)pStrPBrkW
)
952 win_skip("Ordinal 345 corresponds to StrPBrkW, skipping SHAnsiToAnsi tests\n");
956 memset(dest
, '\n', sizeof(dest
));
957 dwRet
= pSHAnsiToAnsi("hello", dest
, sizeof(dest
)/sizeof(dest
[0]));
958 ok(dwRet
== 6 && !memcmp(dest
, "hello\0\n\n", sizeof(dest
)),
959 "SHAnsiToAnsi: expected 6, \"hello\\0\\n\\n\", got %d, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
960 dwRet
, dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
963 static void test_SHUnicodeToUnicode(void)
965 static const WCHAR lpInit
[] = { '\n','\n','\n','\n','\n','\n','\n','\n' };
966 static const WCHAR lpSrc
[] = { 'h','e','l','l','o','\0' };
967 static const WCHAR lpRes
[] = { 'h','e','l','l','o','\0','\n','\n' };
971 if (!pSHUnicodeToUnicode
)
973 win_skip("SHUnicodeToUnicode() is not available\n");
977 if (pSHUnicodeToUnicode
== (void *)pStrRChrA
)
979 win_skip("Ordinal 346 corresponds to StrRChrA, skipping SHUnicodeToUnicode tests\n");
983 memcpy(dest
, lpInit
, sizeof(lpInit
));
984 dwRet
= pSHUnicodeToUnicode(lpSrc
, dest
, sizeof(dest
)/sizeof(dest
[0]));
985 ok(dwRet
== 6 && !memcmp(dest
, lpRes
, sizeof(dest
)),
986 "SHUnicodeToUnicode: expected 6, \"hello\\0\\n\\n\", got %d, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
987 dwRet
, dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
990 static void test_StrXXX_overflows(void)
992 CHAR str1
[2*MAX_PATH
+1], buf
[2*MAX_PATH
];
993 WCHAR wstr1
[2*MAX_PATH
+1], wbuf
[2*MAX_PATH
];
994 const WCHAR fmt
[] = {'%','s',0};
999 for (i
=0; i
<2*MAX_PATH
; i
++)
1001 str1
[i
] = '0'+(i
%10);
1002 wstr1
[i
] = '0'+(i
%10);
1004 str1
[2*MAX_PATH
] = 0;
1005 wstr1
[2*MAX_PATH
] = 0;
1007 memset(buf
, 0xbf, sizeof(buf
));
1008 expect_eq(StrCpyNA(buf
, str1
, 10), buf
, PCHAR
, "%p");
1009 expect_eq(buf
[9], 0, CHAR
, "%x");
1010 expect_eq(buf
[10], '\xbf', CHAR
, "%x");
1014 expect_eq(pStrCatBuffA(buf
, str1
, 100), buf
, PCHAR
, "%p");
1015 expect_eq(buf
[99], 0, CHAR
, "%x");
1016 expect_eq(buf
[100], '\xbf', CHAR
, "%x");
1019 win_skip("StrCatBuffA() is not available\n");
1024 StrCpyNW(wbuf
, (LPCWSTR
)0x1, 10);
1025 StrCpyNW((LPWSTR
)0x1, wstr1
, 10);
1028 memset(wbuf
, 0xbf, sizeof(wbuf
));
1029 expect_eq(StrCpyNW(wbuf
, (LPCWSTR
)0x1, 1), wbuf
, PWCHAR
, "%p");
1030 expect_eq(wbuf
[0], 0, WCHAR
, "%x");
1031 expect_eq(wbuf
[1], (WCHAR
)0xbfbf, WCHAR
, "%x");
1033 memset(wbuf
, 0xbf, sizeof(wbuf
));
1034 expect_eq(StrCpyNW(wbuf
, 0, 10), wbuf
, PWCHAR
, "%p");
1035 expect_eq(wbuf
[0], 0, WCHAR
, "%x");
1036 expect_eq(wbuf
[1], (WCHAR
)0xbfbf, WCHAR
, "%x");
1038 memset(wbuf
, 0xbf, sizeof(wbuf
));
1039 expect_eq(StrCpyNW(wbuf
, 0, 0), wbuf
, PWCHAR
, "%p");
1040 expect_eq(wbuf
[0], (WCHAR
)0xbfbf, WCHAR
, "%x");
1041 expect_eq(wbuf
[1], (WCHAR
)0xbfbf, WCHAR
, "%x");
1043 memset(wbuf
, 0xbf, sizeof(wbuf
));
1044 expect_eq(StrCpyNW(wbuf
, wstr1
, 0), wbuf
, PWCHAR
, "%p");
1045 expect_eq(wbuf
[0], (WCHAR
)0xbfbf, WCHAR
, "%x");
1046 expect_eq(wbuf
[1], (WCHAR
)0xbfbf, WCHAR
, "%x");
1048 memset(wbuf
, 0xbf, sizeof(wbuf
));
1049 expect_eq(StrCpyNW(wbuf
, wstr1
, 10), wbuf
, PWCHAR
, "%p");
1050 expect_eq(wbuf
[9], 0, WCHAR
, "%x");
1051 expect_eq(wbuf
[10], (WCHAR
)0xbfbf, WCHAR
, "%x");
1055 expect_eq(pStrCatBuffW(wbuf
, wstr1
, 100), wbuf
, PWCHAR
, "%p");
1056 expect_eq(wbuf
[99], 0, WCHAR
, "%x");
1057 expect_eq(wbuf
[100], (WCHAR
)0xbfbf, WCHAR
, "%x");
1060 win_skip("StrCatBuffW() is not available\n");
1064 memset(wbuf
, 0xbf, sizeof(wbuf
));
1065 strret
.uType
= STRRET_WSTR
;
1066 U(strret
).pOleStr
= StrDupW(wstr1
);
1067 expect_eq2(pStrRetToBufW(&strret
, NULL
, wbuf
, 10), S_OK
, E_NOT_SUFFICIENT_BUFFER
/* Vista */, HRESULT
, "%x");
1068 expect_eq(wbuf
[9], 0, WCHAR
, "%x");
1069 expect_eq(wbuf
[10], (WCHAR
)0xbfbf, WCHAR
, "%x");
1072 win_skip("StrRetToBufW() is not available\n");
1076 memset(buf
, 0xbf, sizeof(buf
));
1077 strret
.uType
= STRRET_CSTR
;
1078 StrCpyNA(U(strret
).cStr
, str1
, MAX_PATH
);
1079 expect_eq2(pStrRetToBufA(&strret
, NULL
, buf
, 10), S_OK
, E_NOT_SUFFICIENT_BUFFER
/* Vista */, HRESULT
, "%x");
1080 expect_eq(buf
[9], 0, CHAR
, "%x");
1081 expect_eq(buf
[10], (CHAR
)0xbf, CHAR
, "%x");
1084 win_skip("StrRetToBufA() is not available\n");
1088 memset(buf
, 0xbf, sizeof(buf
));
1089 ret
= pwnsprintfA(buf
, 10, "%s", str1
);
1090 ok(broken(ret
== 9) || ret
== -1 /* Vista */, "Unexpected wnsprintfA return %d, expected 9 or -1\n", ret
);
1091 expect_eq(buf
[9], 0, CHAR
, "%x");
1092 expect_eq(buf
[10], (CHAR
)0xbf, CHAR
, "%x");
1095 win_skip("wnsprintfA() is not available\n");
1099 memset(wbuf
, 0xbf, sizeof(wbuf
));
1100 ret
= pwnsprintfW(wbuf
, 10, fmt
, wstr1
);
1101 ok(broken(ret
== 9) || ret
== -1 /* Vista */, "Unexpected wnsprintfW return %d, expected 9 or -1\n", ret
);
1102 expect_eq(wbuf
[9], 0, WCHAR
, "%x");
1103 expect_eq(wbuf
[10], (WCHAR
)0xbfbf, WCHAR
, "%x");
1106 win_skip("wnsprintfW() is not available\n");
1109 static void test_StrStrA(void)
1111 static const char *deadbeefA
= "DeAdBeEf";
1120 {"DeAd", deadbeefA
},
1122 {"AdBe", deadbeefA
+ 2},
1124 {"BeEf", deadbeefA
+ 4},
1131 /* Tests crash on Win2k */
1134 ret
= StrStrA(NULL
, NULL
);
1135 ok(!ret
, "Expected StrStrA to return NULL, got %p\n", ret
);
1137 ret
= StrStrA(NULL
, "");
1138 ok(!ret
, "Expected StrStrA to return NULL, got %p\n", ret
);
1140 ret
= StrStrA("", NULL
);
1141 ok(!ret
, "Expected StrStrA to return NULL, got %p\n", ret
);
1144 ret
= StrStrA("", "");
1145 ok(!ret
, "Expected StrStrA to return NULL, got %p\n", ret
);
1147 for (i
= 0; i
< sizeof(StrStrA_cases
)/sizeof(StrStrA_cases
[0]); i
++)
1149 ret
= StrStrA(deadbeefA
, StrStrA_cases
[i
].search
);
1150 ok(ret
== StrStrA_cases
[i
].expect
,
1151 "[%d] Expected StrStrA to return %p, got %p\n",
1152 i
, StrStrA_cases
[i
].expect
, ret
);
1156 static void test_StrStrW(void)
1158 static const WCHAR emptyW
[] = {0};
1159 static const WCHAR deadbeefW
[] = {'D','e','A','d','B','e','E','f',0};
1160 static const WCHAR deadW
[] = {'D','e','A','d',0};
1161 static const WCHAR dead_lowerW
[] = {'d','e','a','d',0};
1162 static const WCHAR adbeW
[] = {'A','d','B','e',0};
1163 static const WCHAR adbe_lowerW
[] = {'a','d','b','e',0};
1164 static const WCHAR beefW
[] = {'B','e','E','f',0};
1165 static const WCHAR beef_lowerW
[] = {'b','e','e','f',0};
1169 const WCHAR
*search
;
1170 const WCHAR
*expect
;
1175 {dead_lowerW
, NULL
},
1176 {adbeW
, deadbeefW
+ 2},
1177 {adbe_lowerW
, NULL
},
1178 {beefW
, deadbeefW
+ 4},
1179 {beef_lowerW
, NULL
},
1185 /* Tests crash on Win2k */
1188 ret
= StrStrW(NULL
, NULL
);
1189 ok(!ret
, "Expected StrStrW to return NULL, got %p\n", ret
);
1191 ret
= StrStrW(NULL
, emptyW
);
1192 ok(!ret
, "Expected StrStrW to return NULL, got %p\n", ret
);
1194 ret
= StrStrW(emptyW
, NULL
);
1195 ok(!ret
, "Expected StrStrW to return NULL, got %p\n", ret
);
1198 ret
= StrStrW(emptyW
, emptyW
);
1199 ok(!ret
, "Expected StrStrW to return NULL, got %p\n", ret
);
1201 for (i
= 0; i
< sizeof(StrStrW_cases
)/sizeof(StrStrW_cases
[0]); i
++)
1203 ret
= StrStrW(deadbeefW
, StrStrW_cases
[i
].search
);
1204 ok(ret
== StrStrW_cases
[i
].expect
,
1205 "[%d] Expected StrStrW to return %p, got %p\n",
1206 i
, StrStrW_cases
[i
].expect
, ret
);
1210 static void test_StrStrIA(void)
1212 static const char *deadbeefA
= "DeAdBeEf";
1218 } StrStrIA_cases
[] =
1221 {"DeAd", deadbeefA
},
1222 {"dead", deadbeefA
},
1223 {"AdBe", deadbeefA
+ 2},
1224 {"adbe", deadbeefA
+ 2},
1225 {"BeEf", deadbeefA
+ 4},
1226 {"beef", deadbeefA
+ 4},
1233 /* Tests crash on Win2k */
1236 ret
= StrStrIA(NULL
, NULL
);
1237 ok(!ret
, "Expected StrStrIA to return NULL, got %p\n", ret
);
1239 ret
= StrStrIA(NULL
, "");
1240 ok(!ret
, "Expected StrStrIA to return NULL, got %p\n", ret
);
1242 ret
= StrStrIA("", NULL
);
1243 ok(!ret
, "Expected StrStrIA to return NULL, got %p\n", ret
);
1246 ret
= StrStrIA("", "");
1247 ok(!ret
, "Expected StrStrIA to return NULL, got %p\n", ret
);
1249 for (i
= 0; i
< sizeof(StrStrIA_cases
)/sizeof(StrStrIA_cases
[0]); i
++)
1251 ret
= StrStrIA(deadbeefA
, StrStrIA_cases
[i
].search
);
1252 ok(ret
== StrStrIA_cases
[i
].expect
,
1253 "[%d] Expected StrStrIA to return %p, got %p\n",
1254 i
, StrStrIA_cases
[i
].expect
, ret
);
1258 static void test_StrStrIW(void)
1260 static const WCHAR emptyW
[] = {0};
1261 static const WCHAR deadbeefW
[] = {'D','e','A','d','B','e','E','f',0};
1262 static const WCHAR deadW
[] = {'D','e','A','d',0};
1263 static const WCHAR dead_lowerW
[] = {'d','e','a','d',0};
1264 static const WCHAR adbeW
[] = {'A','d','B','e',0};
1265 static const WCHAR adbe_lowerW
[] = {'a','d','b','e',0};
1266 static const WCHAR beefW
[] = {'B','e','E','f',0};
1267 static const WCHAR beef_lowerW
[] = {'b','e','e','f',0};
1268 static const WCHAR cafeW
[] = {'c','a','f','e',0};
1272 const WCHAR
*search
;
1273 const WCHAR
*expect
;
1274 } StrStrIW_cases
[] =
1278 {dead_lowerW
, deadbeefW
},
1279 {adbeW
, deadbeefW
+ 2},
1280 {adbe_lowerW
, deadbeefW
+ 2},
1281 {beefW
, deadbeefW
+ 4},
1282 {beef_lowerW
, deadbeefW
+ 4},
1289 /* Tests crash on Win2k */
1292 ret
= StrStrIW(NULL
, NULL
);
1293 ok(!ret
, "Expected StrStrIW to return NULL, got %p\n", ret
);
1295 ret
= StrStrIW(NULL
, emptyW
);
1296 ok(!ret
, "Expected StrStrIW to return NULL, got %p\n", ret
);
1298 ret
= StrStrIW(emptyW
, NULL
);
1299 ok(!ret
, "Expected StrStrIW to return NULL, got %p\n", ret
);
1302 ret
= StrStrIW(emptyW
, emptyW
);
1303 ok(!ret
, "Expected StrStrIW to return NULL, got %p\n", ret
);
1305 for (i
= 0; i
< sizeof(StrStrIW_cases
)/sizeof(StrStrIW_cases
[0]); i
++)
1307 ret
= StrStrIW(deadbeefW
, StrStrIW_cases
[i
].search
);
1308 ok(ret
== StrStrIW_cases
[i
].expect
,
1309 "[%d] Expected StrStrIW to return %p, got %p\n",
1310 i
, StrStrIW_cases
[i
].expect
, ret
);
1314 static void test_StrStrNW(void)
1316 static const WCHAR emptyW
[] = {0};
1317 static const WCHAR deadbeefW
[] = {'D','e','A','d','B','e','E','f',0};
1318 static const WCHAR deadW
[] = {'D','e','A','d',0};
1319 static const WCHAR dead_lowerW
[] = {'d','e','a','d',0};
1320 static const WCHAR adbeW
[] = {'A','d','B','e',0};
1321 static const WCHAR adbe_lowerW
[] = {'a','d','b','e',0};
1322 static const WCHAR beefW
[] = {'B','e','E','f',0};
1323 static const WCHAR beef_lowerW
[] = {'b','e','e','f',0};
1327 const WCHAR
*search
;
1329 const WCHAR
*expect
;
1330 } StrStrNW_cases
[] =
1332 {emptyW
, sizeof(deadbeefW
)/sizeof(WCHAR
), NULL
},
1333 {deadW
, sizeof(deadbeefW
)/sizeof(WCHAR
), deadbeefW
},
1334 {dead_lowerW
, sizeof(deadbeefW
)/sizeof(WCHAR
), NULL
},
1335 {adbeW
, sizeof(deadbeefW
)/sizeof(WCHAR
), deadbeefW
+ 2},
1336 {adbe_lowerW
, sizeof(deadbeefW
)/sizeof(WCHAR
), NULL
},
1337 {beefW
, sizeof(deadbeefW
)/sizeof(WCHAR
), deadbeefW
+ 4},
1338 {beef_lowerW
, sizeof(deadbeefW
)/sizeof(WCHAR
), NULL
},
1344 {beefW
, 5, deadbeefW
+ 4},
1345 {beefW
, 6, deadbeefW
+ 4},
1346 {beefW
, 7, deadbeefW
+ 4},
1347 {beefW
, 8, deadbeefW
+ 4},
1348 {beefW
, 9, deadbeefW
+ 4},
1356 win_skip("StrStrNW() is not available\n");
1360 ret
= pStrStrNW(NULL
, NULL
, 0);
1361 ok(!ret
, "Expected StrStrNW to return NULL, got %p\n", ret
);
1363 ret
= pStrStrNW(NULL
, NULL
, 10);
1364 ok(!ret
, "Expected StrStrNW to return NULL, got %p\n", ret
);
1366 ret
= pStrStrNW(NULL
, emptyW
, 10);
1367 ok(!ret
, "Expected StrStrNW to return NULL, got %p\n", ret
);
1369 ret
= pStrStrNW(emptyW
, NULL
, 10);
1370 ok(!ret
, "Expected StrStrNW to return NULL, got %p\n", ret
);
1372 ret
= pStrStrNW(emptyW
, emptyW
, 10);
1373 ok(!ret
, "Expected StrStrNW to return NULL, got %p\n", ret
);
1375 for (i
= 0; i
< sizeof(StrStrNW_cases
)/sizeof(StrStrNW_cases
[0]); i
++)
1377 ret
= pStrStrNW(deadbeefW
, StrStrNW_cases
[i
].search
, StrStrNW_cases
[i
].count
);
1378 ok(ret
== StrStrNW_cases
[i
].expect
,
1379 "[%d] Expected StrStrNW to return %p, got %p\n",
1380 i
, StrStrNW_cases
[i
].expect
, ret
);
1383 /* StrStrNW accepts counts larger than the search string length but rejects
1384 * counts larger than around 2G. The limit seems to change based on the
1385 * caller executable itself. */
1386 ret
= pStrStrNW(deadbeefW
, beefW
, 100);
1387 ok(ret
== deadbeefW
+ 4, "Expected StrStrNW to return deadbeefW + 4, got %p\n", ret
);
1391 ret
= pStrStrNW(deadbeefW
, beefW
, ~0U);
1392 ok(!ret
, "Expected StrStrNW to return NULL, got %p\n", ret
);
1396 static void test_StrStrNIW(void)
1398 static const WCHAR emptyW
[] = {0};
1399 static const WCHAR deadbeefW
[] = {'D','e','A','d','B','e','E','f',0};
1400 static const WCHAR deadW
[] = {'D','e','A','d',0};
1401 static const WCHAR dead_lowerW
[] = {'d','e','a','d',0};
1402 static const WCHAR adbeW
[] = {'A','d','B','e',0};
1403 static const WCHAR adbe_lowerW
[] = {'a','d','b','e',0};
1404 static const WCHAR beefW
[] = {'B','e','E','f',0};
1405 static const WCHAR beef_lowerW
[] = {'b','e','e','f',0};
1406 static const WCHAR cafeW
[] = {'c','a','f','e',0};
1410 const WCHAR
*search
;
1412 const WCHAR
*expect
;
1413 } StrStrNIW_cases
[] =
1415 {emptyW
, sizeof(deadbeefW
)/sizeof(WCHAR
), NULL
},
1416 {deadW
, sizeof(deadbeefW
)/sizeof(WCHAR
), deadbeefW
},
1417 {dead_lowerW
, sizeof(deadbeefW
)/sizeof(WCHAR
), deadbeefW
},
1418 {adbeW
, sizeof(deadbeefW
)/sizeof(WCHAR
), deadbeefW
+ 2},
1419 {adbe_lowerW
, sizeof(deadbeefW
)/sizeof(WCHAR
), deadbeefW
+ 2},
1420 {beefW
, sizeof(deadbeefW
)/sizeof(WCHAR
), deadbeefW
+ 4},
1421 {beef_lowerW
, sizeof(deadbeefW
)/sizeof(WCHAR
), deadbeefW
+ 4},
1422 {cafeW
, sizeof(deadbeefW
)/sizeof(WCHAR
), NULL
},
1428 {beefW
, 5, deadbeefW
+ 4},
1429 {beefW
, 6, deadbeefW
+ 4},
1430 {beefW
, 7, deadbeefW
+ 4},
1431 {beefW
, 8, deadbeefW
+ 4},
1432 {beefW
, 9, deadbeefW
+ 4},
1433 {beef_lowerW
, 0, NULL
},
1434 {beef_lowerW
, 1, NULL
},
1435 {beef_lowerW
, 2, NULL
},
1436 {beef_lowerW
, 3, NULL
},
1437 {beef_lowerW
, 4, NULL
},
1438 {beef_lowerW
, 5, deadbeefW
+ 4},
1439 {beef_lowerW
, 6, deadbeefW
+ 4},
1440 {beef_lowerW
, 7, deadbeefW
+ 4},
1441 {beef_lowerW
, 8, deadbeefW
+ 4},
1442 {beef_lowerW
, 9, deadbeefW
+ 4},
1450 win_skip("StrStrNIW() is not available\n");
1454 ret
= pStrStrNIW(NULL
, NULL
, 0);
1455 ok(!ret
, "Expected StrStrNIW to return NULL, got %p\n", ret
);
1457 ret
= pStrStrNIW(NULL
, NULL
, 10);
1458 ok(!ret
, "Expected StrStrNIW to return NULL, got %p\n", ret
);
1460 ret
= pStrStrNIW(NULL
, emptyW
, 10);
1461 ok(!ret
, "Expected StrStrNIW to return NULL, got %p\n", ret
);
1463 ret
= pStrStrNIW(emptyW
, NULL
, 10);
1464 ok(!ret
, "Expected StrStrNIW to return NULL, got %p\n", ret
);
1466 ret
= pStrStrNIW(emptyW
, emptyW
, 10);
1467 ok(!ret
, "Expected StrStrNIW to return NULL, got %p\n", ret
);
1469 for (i
= 0; i
< sizeof(StrStrNIW_cases
)/sizeof(StrStrNIW_cases
[0]); i
++)
1471 ret
= pStrStrNIW(deadbeefW
, StrStrNIW_cases
[i
].search
, StrStrNIW_cases
[i
].count
);
1472 ok(ret
== StrStrNIW_cases
[i
].expect
,
1473 "[%d] Expected StrStrNIW to return %p, got %p\n",
1474 i
, StrStrNIW_cases
[i
].expect
, ret
);
1477 /* StrStrNIW accepts counts larger than the search string length but rejects
1478 * counts larger than around 2G. The limit seems to change based on the
1479 * caller executable itself. */
1480 ret
= pStrStrNIW(deadbeefW
, beefW
, 100);
1481 ok(ret
== deadbeefW
+ 4, "Expected StrStrNIW to return deadbeefW + 4, got %p\n", ret
);
1485 ret
= pStrStrNIW(deadbeefW
, beefW
, ~0U);
1486 ok(!ret
, "Expected StrStrNIW to return NULL, got %p\n", ret
);
1490 static void test_StrCatChainW(void)
1492 static const WCHAR deadbeefW
[] = {'D','e','A','d','B','e','E','f',0};
1493 static const WCHAR deadW
[] = {'D','e','A','d',0};
1494 static const WCHAR beefW
[] = {'B','e','E','f',0};
1501 win_skip("StrCatChainW is not available\n");
1505 /* Test with NULL buffer */
1506 ret
= pStrCatChainW(NULL
, 0, 0, beefW
);
1507 ok(ret
== 0, "Expected StrCatChainW to return 0, got %u\n", ret
);
1509 /* Test with empty buffer */
1510 memset(buf
, 0x11, sizeof(buf
));
1511 ret
= pStrCatChainW(buf
, 0, 0, beefW
);
1512 ok(ret
== 0, "Expected StrCatChainW to return 0, got %u\n", ret
);
1513 ok(buf
[0] == 0x1111, "Expected buf[0] = 0x1111, got %x\n", buf
[0]);
1515 memcpy(buf
, deadbeefW
, sizeof(deadbeefW
));
1516 ret
= pStrCatChainW(buf
, 0, -1, beefW
);
1517 ok(ret
== 8, "Expected StrCatChainW to return 8, got %u\n", ret
);
1518 ok(!memcmp(buf
, deadbeefW
, sizeof(deadbeefW
)), "Buffer contains wrong data\n");
1520 /* Append data to existing string with offset = -1 */
1521 memset(buf
, 0x11, sizeof(buf
));
1522 ret
= pStrCatChainW(buf
, 32, 0, deadW
);
1523 ok(ret
== 4, "Expected StrCatChainW to return 4, got %u\n", ret
);
1524 ok(!memcmp(buf
, deadW
, sizeof(deadW
)), "Buffer contains wrong data\n");
1526 ret
= pStrCatChainW(buf
, 32, -1, beefW
);
1527 ok(ret
== 8, "Expected StrCatChainW to return 8, got %u\n", ret
);
1528 ok(!memcmp(buf
, deadbeefW
, sizeof(deadbeefW
)), "Buffer contains wrong data\n");
1530 /* Append data at a fixed offset */
1531 memset(buf
, 0x11, sizeof(buf
));
1532 ret
= pStrCatChainW(buf
, 32, 0, deadW
);
1533 ok(ret
== 4, "Expected StrCatChainW to return 4, got %u\n", ret
);
1534 ok(!memcmp(buf
, deadW
, sizeof(deadW
)), "Buffer contains wrong data\n");
1536 ret
= pStrCatChainW(buf
, 32, 4, beefW
);
1537 ok(ret
== 8, "Expected StrCatChainW to return 8, got %u\n", ret
);
1538 ok(!memcmp(buf
, deadbeefW
, sizeof(deadbeefW
)), "Buffer contains wrong data\n");
1540 /* Buffer exactly sufficient for string + terminating null */
1541 memset(buf
, 0x11, sizeof(buf
));
1542 ret
= pStrCatChainW(buf
, 5, 0, deadW
);
1543 ok(ret
== 4, "Expected StrCatChainW to return 4, got %u\n", ret
);
1544 ok(!memcmp(buf
, deadW
, sizeof(deadW
)), "Buffer contains wrong data\n");
1546 /* Buffer too small, string will be truncated */
1547 memset(buf
, 0x11, sizeof(buf
));
1548 ret
= pStrCatChainW(buf
, 4, 0, deadW
);
1551 /* Windows 2000 and XP uses a slightly different implementation
1552 * for StrCatChainW, which doesn't ensure that strings are null-
1553 * terminated. Skip test if we detect such an implementation. */
1554 win_skip("Windows2000/XP behaviour detected for StrCatChainW, skipping tests\n");
1557 ok(ret
== 3, "Expected StrCatChainW to return 3, got %u\n", ret
);
1558 ok(!memcmp(buf
, deadW
, 3 * sizeof(WCHAR
)), "Buffer contains wrong data\n");
1559 ok(!buf
[3], "String is not nullterminated\n");
1560 ok(buf
[4] == 0x1111, "Expected buf[4] = 0x1111, got %x\n", buf
[4]);
1562 /* Overwrite part of an existing string */
1563 ret
= pStrCatChainW(buf
, 4, 1, beefW
);
1564 ok(ret
== 3, "Expected StrCatChainW to return 3, got %u\n", ret
);
1565 ok(buf
[0] == 'D', "Expected buf[0] = 'D', got %x\n", buf
[0]);
1566 ok(buf
[1] == 'B', "Expected buf[1] = 'B', got %x\n", buf
[1]);
1567 ok(buf
[2] == 'e', "Expected buf[2] = 'e', got %x\n", buf
[2]);
1568 ok(!buf
[3], "String is not nullterminated\n");
1569 ok(buf
[4] == 0x1111, "Expected buf[4] = 0x1111, got %x\n", buf
[4]);
1571 /* Test appending to full buffer */
1572 memset(buf
, 0x11, sizeof(buf
));
1573 memcpy(buf
, deadbeefW
, sizeof(deadbeefW
));
1574 memcpy(buf
+ 9, deadW
, sizeof(deadW
));
1575 ret
= pStrCatChainW(buf
, 9, 8, beefW
);
1576 ok(ret
== 8, "Expected StrCatChainW to return 8, got %u\n", ret
);
1577 ok(!memcmp(buf
, deadbeefW
, sizeof(deadbeefW
)), "Buffer contains wrong data\n");
1578 ok(!memcmp(buf
+ 9, deadW
, sizeof(deadW
)), "Buffer contains wrong data\n");
1580 /* Offset points at the end of the buffer */
1581 ret
= pStrCatChainW(buf
, 9, 9, beefW
);
1582 ok(ret
== 8, "Expected StrCatChainW to return 8, got %u\n", ret
);
1583 ok(!memcmp(buf
, deadbeefW
, sizeof(deadbeefW
)), "Buffer contains wrong data\n");
1584 ok(!memcmp(buf
+ 9, deadW
, sizeof(deadW
)), "Buffer contains wrong data\n");
1586 /* Offset points outside of the buffer */
1587 ret
= pStrCatChainW(buf
, 9, 10, beefW
);
1588 ok(ret
== 10, "Expected StrCatChainW to return 10, got %u\n", ret
);
1589 ok(!memcmp(buf
, deadbeefW
, sizeof(deadbeefW
)), "Buffer contains wrong data\n");
1590 ok(!memcmp(buf
+ 9, deadW
, sizeof(deadW
)), "Buffer contains wrong data\n");
1592 /* The same but without nullterminated string */
1593 memcpy(buf
, deadbeefW
, sizeof(deadbeefW
));
1594 ret
= pStrCatChainW(buf
, 5, -1, deadW
);
1595 ok(ret
== 8, "Expected StrCatChainW to return 8, got %u\n", ret
);
1596 ok(!memcmp(buf
, deadbeefW
, sizeof(deadbeefW
)), "Buffer contains wrong data\n");
1598 ret
= pStrCatChainW(buf
, 5, 5, deadW
);
1599 ok(ret
== 4, "Expected StrCatChainW to return 4, got %u\n", ret
);
1600 ok(!memcmp(buf
, deadW
, sizeof(deadW
)), "Buffer contains wrong data\n");
1601 ok(buf
[5] == 'e', "Expected buf[5] = 'e', got %x\n", buf
[5]);
1603 ret
= pStrCatChainW(buf
, 5, 6, deadW
);
1604 ok(ret
== 6, "Expected StrCatChainW to return 6, got %u\n", ret
);
1605 ok(!memcmp(buf
, deadW
, sizeof(deadW
)), "Buffer contains wrong data\n");
1606 ok(buf
[5] == 'e', "Expected buf[5] = 'e', got %x\n", buf
[5]);
1612 CHAR thousandDelim
[8];
1613 CHAR decimalDelim
[8];
1616 GetLocaleInfoA(LOCALE_USER_DEFAULT
, LOCALE_STHOUSAND
, thousandDelim
, 8);
1617 GetLocaleInfoA(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
, decimalDelim
, 8);
1619 hShlwapi
= GetModuleHandleA("shlwapi");
1620 pChrCmpIA
= (void *)GetProcAddress(hShlwapi
, "ChrCmpIA");
1621 pChrCmpIW
= (void *)GetProcAddress(hShlwapi
, "ChrCmpIW");
1622 pIntlStrEqWorkerA
= (void *)GetProcAddress(hShlwapi
, "IntlStrEqWorkerA");
1623 pIntlStrEqWorkerW
= (void *)GetProcAddress(hShlwapi
, "IntlStrEqWorkerW");
1624 pSHAnsiToAnsi
= (void *)GetProcAddress(hShlwapi
, (LPSTR
)345);
1625 pSHUnicodeToUnicode
= (void *)GetProcAddress(hShlwapi
, (LPSTR
)346);
1626 pStrCatBuffA
= (void *)GetProcAddress(hShlwapi
, "StrCatBuffA");
1627 pStrCatBuffW
= (void *)GetProcAddress(hShlwapi
, "StrCatBuffW");
1628 pStrCatChainW
= (void *)GetProcAddress(hShlwapi
, "StrCatChainW");
1629 pStrCpyNXA
= (void *)GetProcAddress(hShlwapi
, (LPSTR
)399);
1630 pStrCpyNXW
= (void *)GetProcAddress(hShlwapi
, (LPSTR
)400);
1631 pStrChrNW
= (void *)GetProcAddress(hShlwapi
, "StrChrNW");
1632 pStrFormatByteSize64A
= (void *)GetProcAddress(hShlwapi
, "StrFormatByteSize64A");
1633 pStrFormatKBSizeA
= (void *)GetProcAddress(hShlwapi
, "StrFormatKBSizeA");
1634 pStrFormatKBSizeW
= (void *)GetProcAddress(hShlwapi
, "StrFormatKBSizeW");
1635 pStrIsIntlEqualA
= (void *)GetProcAddress(hShlwapi
, "StrIsIntlEqualA");
1636 pStrIsIntlEqualW
= (void *)GetProcAddress(hShlwapi
, "StrIsIntlEqualW");
1637 pStrPBrkW
= (void *)GetProcAddress(hShlwapi
, "StrPBrkW");
1638 pStrRChrA
= (void *)GetProcAddress(hShlwapi
, "StrRChrA");
1639 pStrRetToBSTR
= (void *)GetProcAddress(hShlwapi
, "StrRetToBSTR");
1640 pStrRetToBufA
= (void *)GetProcAddress(hShlwapi
, "StrRetToBufA");
1641 pStrRetToBufW
= (void *)GetProcAddress(hShlwapi
, "StrRetToBufW");
1642 pStrStrNW
= (void *)GetProcAddress(hShlwapi
, "StrStrNW");
1643 pStrStrNIW
= (void *)GetProcAddress(hShlwapi
, "StrStrNIW");
1644 pwnsprintfA
= (void *)GetProcAddress(hShlwapi
, "wnsprintfA");
1645 pwnsprintfW
= (void *)GetProcAddress(hShlwapi
, "wnsprintfW");
1646 pStrToInt64ExA
= (void *)GetProcAddress(hShlwapi
, "StrToInt64ExA");
1647 pStrToInt64ExW
= (void *)GetProcAddress(hShlwapi
, "StrToInt64ExW");
1661 test_StrToInt64ExA();
1662 test_StrToInt64ExW();
1665 /* language-dependent test */
1666 if (is_lang_english() && is_locale_english())
1668 test_StrFormatByteSize64A();
1669 test_StrFormatKBSizeA();
1670 test_StrFormatKBSizeW();
1673 skip("An English UI and locale is required for the StrFormat*Size tests\n");
1674 if (is_lang_english())
1675 test_StrFromTimeIntervalA();
1677 skip("An English UI is required for the StrFromTimeInterval tests\n");
1681 test_StrRetToBSTR();
1685 test_SHAnsiToAnsi();
1686 test_SHUnicodeToUnicode();
1687 test_StrXXX_overflows();
1694 test_StrCatChainW();