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 static HMODULE hShlwapi
;
39 static LPSTR (WINAPI
*pStrCpyNXA
)(LPSTR
,LPCSTR
,int);
40 static LPWSTR (WINAPI
*pStrCpyNXW
)(LPWSTR
,LPCWSTR
,int);
41 static HRESULT (WINAPI
*pStrRetToBSTR
)(STRRET
*,void*,BSTR
*);
42 static DWORD (WINAPI
*pSHAnsiToAnsi
)(LPCSTR
,LPSTR
,int);
43 static DWORD (WINAPI
*pSHUnicodeToUnicode
)(LPCWSTR
,LPWSTR
,int);
44 static BOOL (WINAPI
*pStrIsIntlEqualA
)(BOOL
,LPCSTR
,LPCSTR
,int);
45 static BOOL (WINAPI
*pIntlStrEqWorkerA
)(BOOL
,LPCSTR
,LPCSTR
,int);
46 static BOOL (WINAPI
*pStrIsIntlEqualW
)(BOOL
,LPCWSTR
,LPCWSTR
,int);
47 static BOOL (WINAPI
*pIntlStrEqWorkerW
)(BOOL
,LPCWSTR
,LPCWSTR
,int);
49 static int strcmpW(const WCHAR
*str1
, const WCHAR
*str2
)
51 while (*str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
55 /* StrToInt/StrToIntEx results */
56 typedef struct tagStrToIntResult
64 static const StrToIntResult StrToInt_results
[] = {
65 { "1099", 1099, 1099, 1099 },
66 { "+88987", 0, 88987, 88987 },
67 { "012", 12, 12, 12 },
68 { "-55", -55, -55, -55 },
70 { "0x44ff", 0, 0, 0x44ff },
71 { "+0x44f4", 0, 0, 0x44f4 },
72 { "-0x44fd", 0, 0, 0x44fd },
73 { "+ 88987", 0, 0, 0 },
76 { "+ 0x44f4", 0, 0, 0 },
77 { "--0x44fd", 0, 0, 0 },
78 { " 1999", 0, 1999, 1999 },
79 { " +88987", 0, 88987, 88987 },
80 { " 012", 0, 12, 12 },
81 { " -55", 0, -55, -55 },
82 { " 0x44ff", 0, 0, 0x44ff },
83 { " +0x44f4", 0, 0, 0x44f4 },
84 { " -0x44fd", 0, 0, 0x44fd },
88 /* pStrFormatByteSize64/StrFormatKBSize results */
89 typedef struct tagStrFormatSizeResult
92 const char* byte_size_64
;
94 } StrFormatSizeResult
;
97 static const StrFormatSizeResult StrFormatSize_results
[] = {
98 { -1023, "-1023 bytes", "0 KB"},
99 { -24, "-24 bytes", "0 KB"},
100 { 309, "309 bytes", "1 KB"},
101 { 10191, "9.95 KB", "10 KB"},
102 { 100353, "98.0 KB", "99 KB"},
103 { 1022286, "998 KB", "999 KB"},
104 { 1046862, "0.99 MB", "1,023 KB"},
105 { 1048574619, "999 MB", "1,023,999 KB"},
106 { 1073741775, "0.99 GB", "1,048,576 KB"},
107 { ((LONGLONG
)0x000000f9 << 32) | 0xfffff94e, "999 GB", "1,048,575,999 KB"},
108 { ((LONGLONG
)0x000000ff << 32) | 0xfffffa9b, "0.99 TB", "1,073,741,823 KB"},
109 { ((LONGLONG
)0x0003e7ff << 32) | 0xfffffa9b, "999 TB", "1,073,741,823,999 KB"},
110 { ((LONGLONG
)0x0003ffff << 32) | 0xfffffbe8, "0.99 PB", "1,099,511,627,775 KB"},
111 { ((LONGLONG
)0x0f9fffff << 32) | 0xfffffd35, "999 PB", "1,099,511,627,776,000 KB"},
112 { ((LONGLONG
)0x0fffffff << 32) | 0xfffffa9b, "0.99 EB", "1,125,899,906,842,623 KB"},
116 /* StrFormatByteSize64/StrFormatKBSize results */
117 typedef struct tagStrFromTimeIntervalResult
121 const char* time_interval
;
122 } StrFromTimeIntervalResult
;
125 static const StrFromTimeIntervalResult StrFromTimeInterval_results
[] = {
134 { 1000000, 1, " 10 min" },
135 { 1000000, 2, " 16 min" },
136 { 1000000, 3, " 16 min 40 sec" },
137 { 1000000, 4, " 16 min 40 sec" },
138 { 1000000, 5, " 16 min 40 sec" },
139 { 1000000, 6, " 16 min 40 sec" },
140 { 1000000, 7, " 16 min 40 sec" },
142 { 1999999, 1, " 30 min" },
143 { 1999999, 2, " 33 min" },
144 { 1999999, 3, " 33 min 20 sec" },
145 { 1999999, 4, " 33 min 20 sec" },
146 { 1999999, 5, " 33 min 20 sec" },
147 { 1999999, 6, " 33 min 20 sec" },
148 { 1999999, 7, " 33 min 20 sec" },
150 { 3999997, 1, " 1 hr" },
151 { 3999997, 2, " 1 hr 6 min" },
152 { 3999997, 3, " 1 hr 6 min 40 sec" },
153 { 3999997, 4, " 1 hr 6 min 40 sec" },
154 { 3999997, 5, " 1 hr 6 min 40 sec" },
155 { 3999997, 6, " 1 hr 6 min 40 sec" },
156 { 3999997, 7, " 1 hr 6 min 40 sec" },
158 { 149999851, 7, " 41 hr 40 min 0 sec" },
159 { 150999850, 1, " 40 hr" },
160 { 150999850, 2, " 41 hr" },
161 { 150999850, 3, " 41 hr 50 min" },
162 { 150999850, 4, " 41 hr 56 min" },
163 { 150999850, 5, " 41 hr 56 min 40 sec" },
164 { 150999850, 6, " 41 hr 56 min 40 sec" },
165 { 150999850, 7, " 41 hr 56 min 40 sec" },
167 { 493999507, 1, " 100 hr" },
168 { 493999507, 2, " 130 hr" },
169 { 493999507, 3, " 137 hr" },
170 { 493999507, 4, " 137 hr 10 min" },
171 { 493999507, 5, " 137 hr 13 min" },
172 { 493999507, 6, " 137 hr 13 min 20 sec" },
173 { 493999507, 7, " 137 hr 13 min 20 sec" },
178 static void test_StrChrA(void)
183 /* this test crashes on win2k SP4 */
184 /*ok(!StrChrA(NULL,'\0'), "found a character in a NULL string!\n");*/
186 for (count
= 32; count
< 128; count
++)
187 string
[count
] = (char)count
;
190 for (count
= 32; count
< 128; count
++)
192 LPSTR result
= StrChrA(string
+32, count
);
193 ok(result
- string
== count
,
194 "found char '%c' in wrong place: got %d, expected %d\n",
195 count
, result
- string
, count
);
198 for (count
= 32; count
< 128; count
++)
200 LPSTR result
= StrChrA(string
+count
+1, count
);
201 ok(!result
, "found char '%c' not in the string\n", count
);
205 static void test_StrChrW(void)
210 /* this test crashes on win2k SP4 */
211 /*ok(!StrChrW(NULL,'\0'), "found a character in a NULL string!\n");*/
213 for (count
= 32; count
< 16384; count
++)
214 string
[count
] = count
;
215 string
[16384] = '\0';
217 for (count
= 32; count
< 16384; count
++)
219 LPWSTR result
= StrChrW(string
+32, count
);
220 ok((result
- string
) == count
, "found char %d in wrong place\n", count
);
223 for (count
= 32; count
< 16384; count
++)
225 LPWSTR result
= StrChrW(string
+count
+1, count
);
226 ok(!result
, "found char not in the string\n");
230 static void test_StrChrIA(void)
235 /* this test crashes on win2k SP4 */
236 /*ok(!StrChrIA(NULL,'\0'), "found a character in a NULL string!\n");*/
238 for (count
= 32; count
< 128; count
++)
239 string
[count
] = (char)count
;
242 for (count
= 'A'; count
<= 'X'; count
++)
244 LPSTR result
= StrChrIA(string
+32, count
);
246 ok(result
- string
== count
, "found char '%c' in wrong place\n", count
);
247 ok(StrChrIA(result
, count
)!=NULL
, "didn't find lowercase '%c'\n", count
);
250 for (count
= 'a'; count
< 'z'; count
++)
252 LPSTR result
= StrChrIA(string
+count
+1, count
);
253 ok(!result
, "found char not in the string\n");
257 static void test_StrChrIW(void)
262 /* this test crashes on win2k SP4 */
263 /*ok(!StrChrIA(NULL,'\0'), "found a character in a NULL string!\n");*/
265 for (count
= 32; count
< 128; count
++)
266 string
[count
] = count
;
269 for (count
= 'A'; count
<= 'X'; count
++)
271 LPWSTR result
= StrChrIW(string
+32, count
);
273 ok(result
- string
== count
, "found char '%c' in wrong place\n", count
);
274 ok(StrChrIW(result
, count
)!=NULL
, "didn't find lowercase '%c'\n", count
);
277 for (count
= 'a'; count
< 'z'; count
++)
279 LPWSTR result
= StrChrIW(string
+count
+1, count
);
280 ok(!result
, "found char not in the string\n");
284 static void test_StrRChrA(void)
289 /* this test crashes on win2k SP4 */
290 /*ok(!StrRChrA(NULL, NULL,'\0'), "found a character in a NULL string!\n");*/
292 for (count
= 32; count
< 128; count
++)
293 string
[count
] = (char)count
;
296 for (count
= 32; count
< 128; count
++)
298 LPSTR result
= StrRChrA(string
+32, NULL
, count
);
299 ok(result
- string
== count
, "found char %d in wrong place\n", count
);
302 for (count
= 32; count
< 128; count
++)
304 LPSTR result
= StrRChrA(string
+count
+1, NULL
, count
);
305 ok(!result
, "found char not in the string\n");
308 for (count
= 32; count
< 128; count
++)
310 LPSTR result
= StrRChrA(string
+count
+1, string
+ 127, count
);
311 ok(!result
, "found char not in the string\n");
315 static void test_StrRChrW(void)
320 /* this test crashes on win2k SP4 */
321 /*ok(!StrRChrW(NULL, NULL,'\0'), "found a character in a NULL string!\n");*/
323 for (count
= 32; count
< 128; count
++)
324 string
[count
] = count
;
327 for (count
= 32; count
< 128; count
++)
329 LPWSTR result
= StrRChrW(string
+32, NULL
, count
);
330 ok(result
- string
== count
,
331 "found char %d in wrong place: got %d, expected %d\n",
332 count
, result
- string
, count
);
335 for (count
= 32; count
< 128; count
++)
337 LPWSTR result
= StrRChrW(string
+count
+1, NULL
, count
);
338 ok(!result
, "found char %d not in the string\n", count
);
341 for (count
= 32; count
< 128; count
++)
343 LPWSTR result
= StrRChrW(string
+count
+1, string
+ 127, count
);
344 ok(!result
, "found char %d not in the string\n", count
);
348 static void test_StrCpyW(void)
352 const StrFormatSizeResult
* result
= StrFormatSize_results
;
357 MultiByteToWideChar(0,0,result
->byte_size_64
,-1,szSrc
,sizeof(szSrc
)/sizeof(WCHAR
));
359 StrCpyW(szBuff
, szSrc
);
360 ok(!StrCmpW(szSrc
, szBuff
), "Copied string %s wrong\n", result
->byte_size_64
);
366 static void test_StrToIntA(void)
368 const StrToIntResult
*result
= StrToInt_results
;
371 while (result
->string
)
373 return_val
= StrToIntA(result
->string
);
374 ok(return_val
== result
->str_to_int
, "converted '%s' wrong (%d)\n",
375 result
->string
, return_val
);
380 static void test_StrToIntW(void)
383 const StrToIntResult
*result
= StrToInt_results
;
386 while (result
->string
)
388 MultiByteToWideChar(0,0,result
->string
,-1,szBuff
,sizeof(szBuff
)/sizeof(WCHAR
));
389 return_val
= StrToIntW(szBuff
);
390 ok(return_val
== result
->str_to_int
, "converted '%s' wrong (%d)\n",
391 result
->string
, return_val
);
396 static void test_StrToIntExA(void)
398 const StrToIntResult
*result
= StrToInt_results
;
402 while (result
->string
)
405 bRet
= StrToIntExA(result
->string
,0,&return_val
);
406 ok(!bRet
|| return_val
!= -1, "No result returned from '%s'\n",
409 ok(return_val
== result
->str_to_int_ex
, "converted '%s' wrong (%d)\n",
410 result
->string
, return_val
);
414 result
= StrToInt_results
;
415 while (result
->string
)
418 bRet
= StrToIntExA(result
->string
,STIF_SUPPORT_HEX
,&return_val
);
419 ok(!bRet
|| return_val
!= -1, "No result returned from '%s'\n",
422 ok(return_val
== result
->str_to_int_hex
, "converted '%s' wrong (%d)\n",
423 result
->string
, return_val
);
428 static void test_StrToIntExW(void)
431 const StrToIntResult
*result
= StrToInt_results
;
435 while (result
->string
)
438 MultiByteToWideChar(0,0,result
->string
,-1,szBuff
,sizeof(szBuff
)/sizeof(WCHAR
));
439 bRet
= StrToIntExW(szBuff
, 0, &return_val
);
440 ok(!bRet
|| return_val
!= -1, "No result returned from '%s'\n",
443 ok(return_val
== result
->str_to_int_ex
, "converted '%s' wrong (%d)\n",
444 result
->string
, return_val
);
448 result
= StrToInt_results
;
449 while (result
->string
)
452 MultiByteToWideChar(0,0,result
->string
,-1,szBuff
,sizeof(szBuff
)/sizeof(WCHAR
));
453 bRet
= StrToIntExW(szBuff
, 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_StrDupA(void)
466 const StrFormatSizeResult
* result
= StrFormatSize_results
;
470 lpszStr
= StrDupA(result
->byte_size_64
);
472 ok(lpszStr
!= NULL
, "Dup failed\n");
475 ok(!strcmp(result
->byte_size_64
, lpszStr
), "Copied string wrong\n");
476 LocalFree((HLOCAL
)lpszStr
);
481 /* Later versions of shlwapi return NULL for this, but earlier versions
482 * returned an empty string (as Wine does).
484 lpszStr
= StrDupA(NULL
);
485 ok(lpszStr
== NULL
|| *lpszStr
== '\0', "NULL string returned %p\n", lpszStr
);
488 static void test_StrFormatByteSize64A(void)
491 const StrFormatSizeResult
* result
= StrFormatSize_results
;
495 StrFormatByteSize64A(result
->value
, szBuff
, 256);
497 ok(!strcmp(result
->byte_size_64
, szBuff
),
498 "Formatted %x%08x wrong: got %s, expected %s\n",
499 (LONG
)(result
->value
>> 32), (LONG
)result
->value
, szBuff
, result
->byte_size_64
);
505 static void test_StrFormatKBSizeW(void)
509 const StrFormatSizeResult
* result
= StrFormatSize_results
;
513 StrFormatKBSizeW(result
->value
, szBuffW
, 256);
514 WideCharToMultiByte(0,0,szBuffW
,-1,szBuff
,sizeof(szBuff
)/sizeof(WCHAR
),0,0);
515 ok(!strcmp(result
->kb_size
, szBuff
),
516 "Formatted %x%08x wrong: got %s, expected %s\n",
517 (LONG
)(result
->value
>> 32), (LONG
)result
->value
, szBuff
, result
->kb_size
);
522 static void test_StrFormatKBSizeA(void)
525 const StrFormatSizeResult
* result
= StrFormatSize_results
;
529 StrFormatKBSizeA(result
->value
, szBuff
, 256);
531 ok(!strcmp(result
->kb_size
, szBuff
),
532 "Formatted %x%08x wrong: got %s, expected %s\n",
533 (LONG
)(result
->value
>> 32), (LONG
)result
->value
, szBuff
, result
->kb_size
);
538 static void test_StrFromTimeIntervalA(void)
541 const StrFromTimeIntervalResult
* result
= StrFromTimeInterval_results
;
545 StrFromTimeIntervalA(szBuff
, 256, result
->ms
, result
->digits
);
547 ok(!strcmp(result
->time_interval
, szBuff
), "Formatted %d %d wrong\n",
548 result
->ms
, result
->digits
);
553 static void test_StrCmpA(void)
555 static const char str1
[] = {'a','b','c','d','e','f'};
556 static const char str2
[] = {'a','B','c','d','e','f'};
557 ok(0 != StrCmpNA(str1
, str2
, 6), "StrCmpNA is case-insensitive\n");
558 ok(0 == StrCmpNIA(str1
, str2
, 6), "StrCmpNIA is case-sensitive\n");
559 ok(!ChrCmpIA('a', 'a'), "ChrCmpIA doesn't work at all!\n");
560 ok(!ChrCmpIA('b', 'B'), "ChrCmpIA is not case-insensitive\n");
561 ok(ChrCmpIA('a', 'z'), "ChrCmpIA believes that a == z!\n");
563 pStrIsIntlEqualA
= (void *)GetProcAddress(hShlwapi
, "StrIsIntlEqualA");
564 pIntlStrEqWorkerA
= (void *)GetProcAddress(hShlwapi
, "IntlStrEqWorkerA");
566 if (!pStrIsIntlEqualA
)
569 ok(pStrIsIntlEqualA(FALSE
, str1
, str2
, 5), "StrIsIntlEqualA(FALSE,...) isn't case-insensitive\n");
570 ok(!pStrIsIntlEqualA(TRUE
, str1
, str2
, 5), "StrIsIntlEqualA(TRUE,...) isn't case-sensitive\n");
572 if (!pIntlStrEqWorkerA
)
575 ok(pIntlStrEqWorkerA(FALSE
, str1
, str2
, 5), "IntlStrEqWorkerA(FALSE,...) isn't case-insensitive\n");
576 ok(!pIntlStrEqWorkerA(TRUE
, str1
, str2
, 5), "pIntlStrEqWorkerA(TRUE,...) isn't case-sensitive\n");
579 static void test_StrCmpW(void)
581 static const WCHAR str1
[] = {'a','b','c','d','e','f'};
582 static const WCHAR str2
[] = {'a','B','c','d','e','f'};
583 ok(0 != StrCmpNW(str1
, str2
, 5), "StrCmpNW is case-insensitive\n");
584 ok(0 == StrCmpNIW(str1
, str2
, 5), "StrCmpNIW is case-sensitive\n");
585 ok(!ChrCmpIW('a', 'a'), "ChrCmpIW doesn't work at all!\n");
586 ok(!ChrCmpIW('b', 'B'), "ChrCmpIW is not case-insensitive\n");
587 ok(ChrCmpIW('a', 'z'), "ChrCmpIW believes that a == z!\n");
589 pStrIsIntlEqualW
= (void *)GetProcAddress(hShlwapi
, "StrIsIntlEqualW");
590 pIntlStrEqWorkerW
= (void *)GetProcAddress(hShlwapi
, "IntlStrEqWorkerW");
592 if (!pStrIsIntlEqualW
)
595 ok(pStrIsIntlEqualW(FALSE
, str1
, str2
, 5), "StrIsIntlEqualW(FALSE,...) isn't case-insensitive\n");
596 ok(!pStrIsIntlEqualW(TRUE
, str1
, str2
, 5), "StrIsIntlEqualW(TRUE,...) isn't case-sensitive\n");
598 if (!pIntlStrEqWorkerW
)
601 ok(pIntlStrEqWorkerW(FALSE
, str1
, str2
, 5), "IntlStrEqWorkerW(FALSE,...) isn't case-insensitive\n");
602 ok(!pIntlStrEqWorkerW(TRUE
, str1
, str2
, 5), "IntlStrEqWorkerW(TRUE,...) isn't case-sensitive\n");
605 static WCHAR
*CoDupStrW(const char* src
)
607 INT len
= MultiByteToWideChar(CP_ACP
, 0, src
, -1, NULL
, 0);
608 WCHAR
* szTemp
= (WCHAR
*)CoTaskMemAlloc(len
* sizeof(WCHAR
));
609 MultiByteToWideChar(CP_ACP
, 0, src
, -1, szTemp
, len
);
613 static void test_StrRetToBSTR(void)
615 static const WCHAR szTestW
[] = { 'T','e','s','t','\0' };
621 pStrRetToBSTR
= (void *)GetProcAddress(hShlwapi
, "StrRetToBSTR");
622 if (!pStrRetToBSTR
) return;
624 strret
.uType
= STRRET_WSTR
;
625 U(strret
).pOleStr
= CoDupStrW("Test");
627 ret
= pStrRetToBSTR(&strret
, NULL
, &bstr
);
628 ok(ret
== S_OK
&& bstr
&& !strcmpW(bstr
, szTestW
),
629 "STRRET_WSTR: dup failed, ret=0x%08x, bstr %p\n", ret
, bstr
);
633 strret
.uType
= STRRET_CSTR
;
634 lstrcpyA(U(strret
).cStr
, "Test");
635 ret
= pStrRetToBSTR(&strret
, NULL
, &bstr
);
636 ok(ret
== S_OK
&& bstr
&& !strcmpW(bstr
, szTestW
),
637 "STRRET_CSTR: dup failed, ret=0x%08x, bstr %p\n", ret
, bstr
);
641 strret
.uType
= STRRET_OFFSET
;
642 U(strret
).uOffset
= 1;
643 strcpy((char*)&iidl
, " Test");
644 ret
= pStrRetToBSTR(&strret
, iidl
, &bstr
);
645 ok(ret
== S_OK
&& bstr
&& !strcmpW(bstr
, szTestW
),
646 "STRRET_OFFSET: dup failed, ret=0x%08x, bstr %p\n", ret
, bstr
);
650 /* Native crashes if str is NULL */
653 static void test_StrCpyNXA(void)
655 LPCSTR lpSrc
= "hello";
659 pStrCpyNXA
= (void *)GetProcAddress(hShlwapi
, (LPSTR
)399);
663 memset(dest
, '\n', sizeof(dest
));
664 lpszRes
= pStrCpyNXA(dest
, lpSrc
, sizeof(dest
)/sizeof(dest
[0]));
665 ok(lpszRes
== dest
+ 5 && !memcmp(dest
, "hello\0\n\n", sizeof(dest
)),
666 "StrCpyNXA: expected %p, \"hello\\0\\n\\n\", got %p, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
667 dest
+ 5, lpszRes
, dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
670 static void test_StrCpyNXW(void)
672 static const WCHAR lpInit
[] = { '\n','\n','\n','\n','\n','\n','\n','\n' };
673 static const WCHAR lpSrc
[] = { 'h','e','l','l','o','\0' };
674 static const WCHAR lpRes
[] = { 'h','e','l','l','o','\0','\n','\n' };
678 pStrCpyNXW
= (void *)GetProcAddress(hShlwapi
, (LPSTR
)400);
682 memcpy(dest
, lpInit
, sizeof(lpInit
));
683 lpszRes
= pStrCpyNXW(dest
, lpSrc
, sizeof(dest
)/sizeof(dest
[0]));
684 ok(lpszRes
== dest
+ 5 && !memcmp(dest
, lpRes
, sizeof(dest
)),
685 "StrCpyNXA: expected %p, \"hello\\0\\n\\n\", got %p, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
686 dest
+ 5, lpszRes
, dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
689 #define check_strrstri(type, str, pos, needle, exp) \
690 ret##type = StrRStrI##type(str, str+pos, needle); \
691 ok(ret##type == (exp), "Type " #type ", expected %p but got %p (string base %p)\n", \
692 (exp), ret##type, str);
694 static void test_StrRStrI(void)
696 static const CHAR szTest
[] = "yAxxxxAy";
697 static const CHAR szTest2
[] = "ABABABAB";
698 static const WCHAR wszTest
[] = {'y','A','x','x','x','x','A','y',0};
699 static const WCHAR wszTest2
[] = {'A','B','A','B','A','B','A','B',0};
701 static const WCHAR wszPattern1
[] = {'A',0};
702 static const WCHAR wszPattern2
[] = {'a','X',0};
703 static const WCHAR wszPattern3
[] = {'A','y',0};
704 static const WCHAR wszPattern4
[] = {'a','b',0};
708 check_strrstri(A
, szTest
, 4, "A", szTest
+1);
709 check_strrstri(A
, szTest
, 4, "aX", szTest
+1);
710 check_strrstri(A
, szTest
, 4, "Ay", NULL
);
711 check_strrstri(W
, wszTest
, 4, wszPattern1
, wszTest
+1);
712 check_strrstri(W
, wszTest
, 4, wszPattern2
, wszTest
+1);
713 check_strrstri(W
, wszTest
, 4, wszPattern3
, NULL
);
715 check_strrstri(A
, szTest2
, 4, "ab", szTest2
+2);
716 check_strrstri(A
, szTest2
, 3, "ab", szTest2
+2);
717 check_strrstri(A
, szTest2
, 2, "ab", szTest2
);
718 check_strrstri(A
, szTest2
, 1, "ab", szTest2
);
719 check_strrstri(A
, szTest2
, 0, "ab", NULL
);
720 check_strrstri(W
, wszTest2
, 4, wszPattern4
, wszTest2
+2);
721 check_strrstri(W
, wszTest2
, 3, wszPattern4
, wszTest2
+2);
722 check_strrstri(W
, wszTest2
, 2, wszPattern4
, wszTest2
);
723 check_strrstri(W
, wszTest2
, 1, wszPattern4
, wszTest2
);
724 check_strrstri(W
, wszTest2
, 0, wszPattern4
, NULL
);
728 static void test_SHAnsiToAnsi(void)
733 pSHAnsiToAnsi
= (void *)GetProcAddress(hShlwapi
, (LPSTR
)345);
737 memset(dest
, '\n', sizeof(dest
));
738 dwRet
= pSHAnsiToAnsi("hello", dest
, sizeof(dest
)/sizeof(dest
[0]));
739 ok(dwRet
== 6 && !memcmp(dest
, "hello\0\n\n", sizeof(dest
)),
740 "SHAnsiToAnsi: expected 6, \"hello\\0\\n\\n\", got %d, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
741 dwRet
, dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
744 static void test_SHUnicodeToUnicode(void)
746 static const WCHAR lpInit
[] = { '\n','\n','\n','\n','\n','\n','\n','\n' };
747 static const WCHAR lpSrc
[] = { 'h','e','l','l','o','\0' };
748 static const WCHAR lpRes
[] = { 'h','e','l','l','o','\0','\n','\n' };
752 pSHUnicodeToUnicode
= (void *)GetProcAddress(hShlwapi
, (LPSTR
)346);
753 if (!pSHUnicodeToUnicode
)
756 memcpy(dest
, lpInit
, sizeof(lpInit
));
757 dwRet
= pSHUnicodeToUnicode(lpSrc
, dest
, sizeof(dest
)/sizeof(dest
[0]));
758 ok(dwRet
== 6 && !memcmp(dest
, lpRes
, sizeof(dest
)),
759 "SHUnicodeToUnicode: expected 6, \"hello\\0\\n\\n\", got %d, \"%d,%d,%d,%d,%d,%d,%d,%d\"\n",
760 dwRet
, dest
[0], dest
[1], dest
[2], dest
[3], dest
[4], dest
[5], dest
[6], dest
[7]);
763 static void test_StrXXX_overflows(void)
765 CHAR str1
[2*MAX_PATH
+1], buf
[2*MAX_PATH
];
766 WCHAR wstr1
[2*MAX_PATH
+1], wbuf
[2*MAX_PATH
];
767 const WCHAR fmt
[] = {'%','s',0};
772 for (i
=0; i
<2*MAX_PATH
; i
++)
774 str1
[i
] = '0'+(i
%10);
775 wstr1
[i
] = '0'+(i
%10);
777 str1
[2*MAX_PATH
] = 0;
778 wstr1
[2*MAX_PATH
] = 0;
780 memset(buf
, 0xbf, sizeof(buf
));
781 expect_eq(StrCpyNA(buf
, str1
, 10), buf
, PCHAR
, "%p");
782 expect_eq(buf
[9], 0, CHAR
, "%x");
783 expect_eq(buf
[10], '\xbf', CHAR
, "%x");
784 expect_eq(StrCatBuffA(buf
, str1
, 100), buf
, PCHAR
, "%p");
785 expect_eq(buf
[99], 0, CHAR
, "%x");
786 expect_eq(buf
[100], '\xbf', CHAR
, "%x");
788 memset(wbuf
, 0xbf, sizeof(wbuf
));
789 expect_eq(StrCpyNW(wbuf
, wstr1
, 10), wbuf
, PWCHAR
, "%p");
790 expect_eq(wbuf
[9], 0, WCHAR
, "%x");
791 expect_eq(wbuf
[10], (WCHAR
)0xbfbf, WCHAR
, "%x");
792 expect_eq(StrCatBuffW(wbuf
, wstr1
, 100), wbuf
, PWCHAR
, "%p");
793 expect_eq(wbuf
[99], 0, WCHAR
, "%x");
794 expect_eq(wbuf
[100], (WCHAR
)0xbfbf, WCHAR
, "%x");
796 memset(wbuf
, 0xbf, sizeof(wbuf
));
797 strret
.uType
= STRRET_WSTR
;
798 U(strret
).pOleStr
= StrDupW(wstr1
);
799 expect_eq(StrRetToBufW(&strret
, NULL
, wbuf
, 10), S_OK
, HRESULT
, "%x");
800 expect_eq(wbuf
[9], 0, WCHAR
, "%x");
801 expect_eq(wbuf
[10], (WCHAR
)0xbfbf, WCHAR
, "%x");
803 memset(buf
, 0xbf, sizeof(buf
));
804 strret
.uType
= STRRET_CSTR
;
805 StrCpyN(U(strret
).cStr
, str1
, MAX_PATH
);
806 expect_eq(StrRetToBufA(&strret
, NULL
, buf
, 10), S_OK
, HRESULT
, "%x");
807 expect_eq(buf
[9], 0, CHAR
, "%x");
808 expect_eq(buf
[10], (CHAR
)0xbf, CHAR
, "%x");
810 memset(buf
, 0xbf, sizeof(buf
));
811 ret
= wnsprintfA(buf
, 10, "%s", str1
);
812 todo_wine
ok(ret
== 9, "Unexpected wsnprintfA return %d, expected 9\n", ret
);
813 expect_eq(buf
[9], 0, CHAR
, "%x");
814 expect_eq(buf
[10], (CHAR
)0xbf, CHAR
, "%x");
815 memset(wbuf
, 0xbf, sizeof(wbuf
));
816 ret
= wnsprintfW(wbuf
, 10, fmt
, wstr1
);
817 todo_wine
ok(ret
== 9, "Unexpected wsnprintfW return %d, expected 9\n", ret
);
818 expect_eq(wbuf
[9], 0, WCHAR
, "%x");
819 expect_eq(wbuf
[10], (WCHAR
)0xbfbf, WCHAR
, "%x");
824 TCHAR thousandDelim
[8];
825 TCHAR decimalDelim
[8];
828 GetLocaleInfo(LOCALE_USER_DEFAULT
, LOCALE_STHOUSAND
, thousandDelim
, 8);
829 GetLocaleInfo(LOCALE_USER_DEFAULT
, LOCALE_SDECIMAL
, decimalDelim
, 8);
831 hShlwapi
= GetModuleHandleA("shlwapi");
847 if (lstrcmp(thousandDelim
, ",")==0 && lstrcmp(decimalDelim
, ".")==0)
849 /* these tests are locale-dependent */
850 test_StrFormatByteSize64A();
851 test_StrFormatKBSizeA();
852 test_StrFormatKBSizeW();
855 /* language-dependent test */
856 if (PRIMARYLANGID(GetUserDefaultLangID()) != LANG_ENGLISH
)
857 trace("Skipping StrFromTimeInterval test for non English language\n");
859 test_StrFromTimeIntervalA();
868 test_SHUnicodeToUnicode();
869 test_StrXXX_overflows();