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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/test.h"
27 #define NO_SHLWAPI_REG
28 #define NO_SHLWAPI_PATH
29 #define NO_SHLWAPI_GDI
30 #define NO_SHLWAPI_STREAM
33 /* StrToInt/StrToIntEx results */
34 typedef struct tagStrToIntResult
42 static const StrToIntResult StrToInt_results[] = {
43 { "1099", 1099, 1099, 1099 },
44 { "+88987", 0, 88987, 88987 },
45 { "012", 12, 12, 12 },
46 { "-55", -55, -55, -55 },
48 { "0x44ff", 0, 0, 0x44ff },
49 { "+0x44f4", 0, 0, 0x44f4 },
50 { "-0x44fd", 0, 0, 0x44fd },
51 { "+ 88987", 0, 0, 0 },
54 { "+ 0x44f4", 0, 0, 0 },
55 { "--0x44fd", 0, 0, 0 },
56 { " 1999", 0, 1999, 1999 },
57 { " +88987", 0, 88987, 88987 },
58 { " 012", 0, 12, 12 },
59 { " -55", 0, -55, -55 },
60 { " 0x44ff", 0, 0, 0x44ff },
61 { " +0x44f4", 0, 0, 0x44f4 },
62 { " -0x44fd", 0, 0, 0x44fd },
66 /* pStrFormatByteSize64/StrFormatKBSize results */
67 typedef struct tagStrFormatSizeResult
70 const char* byte_size_64;
72 } StrFormatSizeResult;
75 static const StrFormatSizeResult StrFormatSize_results[] = {
76 { -1023, "-1023 bytes", "0 KB"},
77 { -24, "-24 bytes", "0 KB"},
78 { 309, "309 bytes", "1 KB"},
79 { 10191, "9.95 KB", "10 KB"},
80 { 100353, "98.0 KB", "99 KB"},
81 { 1022286, "998 KB", "999 KB"},
82 { 1046862, "0.99 MB", "1,023 KB"},
83 { 1048574619, "999 MB", "1,023,999 KB"},
84 { 1073741775, "0.99 GB", "1,048,576 KB"},
85 { ((LONGLONG)0x000000f9 << 32) | 0xfffff94e, "999 GB", "1,048,575,999 KB"},
86 { ((LONGLONG)0x000000ff << 32) | 0xfffffa9b, "0.99 TB", "1,073,741,823 KB"},
87 { ((LONGLONG)0x0003e7ff << 32) | 0xfffffa9b, "999 TB", "1,073,741,823,999 KB"},
88 { ((LONGLONG)0x0003ffff << 32) | 0xfffffbe8, "0.99 PB", "1,099,511,627,775 KB"},
89 { ((LONGLONG)0x0f9fffff << 32) | 0xfffffd35, "999 PB", "1,099,511,627,776,000 KB"},
90 { ((LONGLONG)0x0fffffff << 32) | 0xfffffa9b, "0.99 EB", "1,125,899,906,842,623 KB"},
94 /* StrFormatByteSize64/StrFormatKBSize results */
95 typedef struct tagStrFromTimeIntervalResult
99 const char* time_interval;
100 } StrFromTimeIntervalResult;
103 static const StrFromTimeIntervalResult StrFromTimeInterval_results[] = {
112 { 1000000, 1, " 10 min" },
113 { 1000000, 2, " 16 min" },
114 { 1000000, 3, " 16 min 40 sec" },
115 { 1000000, 4, " 16 min 40 sec" },
116 { 1000000, 5, " 16 min 40 sec" },
117 { 1000000, 6, " 16 min 40 sec" },
118 { 1000000, 7, " 16 min 40 sec" },
120 { 1999999, 1, " 30 min" },
121 { 1999999, 2, " 33 min" },
122 { 1999999, 3, " 33 min 20 sec" },
123 { 1999999, 4, " 33 min 20 sec" },
124 { 1999999, 5, " 33 min 20 sec" },
125 { 1999999, 6, " 33 min 20 sec" },
126 { 1999999, 7, " 33 min 20 sec" },
128 { 3999997, 1, " 1 hr" },
129 { 3999997, 2, " 1 hr 6 min" },
130 { 3999997, 3, " 1 hr 6 min 40 sec" },
131 { 3999997, 4, " 1 hr 6 min 40 sec" },
132 { 3999997, 5, " 1 hr 6 min 40 sec" },
133 { 3999997, 6, " 1 hr 6 min 40 sec" },
134 { 3999997, 7, " 1 hr 6 min 40 sec" },
136 { 149999851, 7, " 41 hr 40 min 0 sec" },
137 { 150999850, 1, " 40 hr" },
138 { 150999850, 2, " 41 hr" },
139 { 150999850, 3, " 41 hr 50 min" },
140 { 150999850, 4, " 41 hr 56 min" },
141 { 150999850, 5, " 41 hr 56 min 40 sec" },
142 { 150999850, 6, " 41 hr 56 min 40 sec" },
143 { 150999850, 7, " 41 hr 56 min 40 sec" },
145 { 493999507, 1, " 100 hr" },
146 { 493999507, 2, " 130 hr" },
147 { 493999507, 3, " 137 hr" },
148 { 493999507, 4, " 137 hr 10 min" },
149 { 493999507, 5, " 137 hr 13 min" },
150 { 493999507, 6, " 137 hr 13 min 20 sec" },
151 { 493999507, 7, " 137 hr 13 min 20 sec" },
156 static void test_StrChrA(void)
161 /* this test crashes on win2k SP4 */
162 /*ok(!StrChrA(NULL,'\0'), "found a character in a NULL string!");*/
164 for (count = 32; count < 128; count++)
165 string[count] = (char)count;
168 for (count = 32; count < 128; count++)
170 LPSTR result = StrChrA(string+32, count);
171 ok(result - string == count,
172 "found char '%c' in wrong place: got %d, expected %d\n",
173 count, result - string, count);
176 for (count = 32; count < 128; count++)
178 LPSTR result = StrChrA(string+count+1, count);
179 ok(!result, "found char '%c' not in the string\n", count);
183 static void test_StrChrW(void)
188 /* this test crashes on win2k SP4 */
189 /*ok(!StrChrW(NULL,'\0'), "found a character in a NULL string!");*/
191 for (count = 32; count < 16384; count++)
192 string[count] = count;
193 string[16384] = '\0';
195 for (count = 32; count < 16384; count++)
197 LPWSTR result = StrChrW(string+32, count);
198 ok((result - string) == count, "found char %d in wrong place", count);
201 for (count = 32; count < 16384; count++)
203 LPWSTR result = StrChrW(string+count+1, count);
204 ok(!result, "found char not in the string");
208 static void test_StrChrIA(void)
213 /* this test crashes on win2k SP4 */
214 /*ok(!StrChrIA(NULL,'\0'), "found a character in a NULL string!");*/
216 for (count = 32; count < 128; count++)
217 string[count] = (char)count;
220 for (count = 'A'; count <= 'X'; count++)
222 LPSTR result = StrChrIA(string+32, count);
224 ok(result - string == count, "found char '%c' in wrong place", count);
225 ok(StrChrIA(result, count)!=NULL, "didn't find lowercase '%c'", count);
228 for (count = 'a'; count < 'z'; count++)
230 LPSTR result = StrChrIA(string+count+1, count);
231 ok(!result, "found char not in the string");
235 static void test_StrChrIW(void)
240 /* this test crashes on win2k SP4 */
241 /*ok(!StrChrIA(NULL,'\0'), "found a character in a NULL string!");*/
243 for (count = 32; count < 128; count++)
244 string[count] = count;
247 for (count = 'A'; count <= 'X'; count++)
249 LPWSTR result = StrChrIW(string+32, count);
251 ok(result - string == count, "found char '%c' in wrong place", count);
252 ok(StrChrIW(result, count)!=NULL, "didn't find lowercase '%c'", count);
255 for (count = 'a'; count < 'z'; count++)
257 LPWSTR result = StrChrIW(string+count+1, count);
258 ok(!result, "found char not in the string");
262 static void test_StrRChrA(void)
267 /* this test crashes on win2k SP4 */
268 /*ok(!StrRChrA(NULL, NULL,'\0'), "found a character in a NULL string!");*/
270 for (count = 32; count < 128; count++)
271 string[count] = (char)count;
274 for (count = 32; count < 128; count++)
276 LPSTR result = StrRChrA(string+32, NULL, count);
277 ok(result - string == count, "found char %d in wrong place", count);
280 for (count = 32; count < 128; count++)
282 LPSTR result = StrRChrA(string+count+1, NULL, count);
283 ok(!result, "found char not in the string");
286 for (count = 32; count < 128; count++)
288 LPSTR result = StrRChrA(string+count+1, string + 127, count);
289 ok(!result, "found char not in the string");
293 static void test_StrRChrW(void)
298 /* this test crashes on win2k SP4 */
299 /*ok(!StrRChrW(NULL, NULL,'\0'), "found a character in a NULL string!");*/
301 for (count = 32; count < 128; count++)
302 string[count] = count;
305 for (count = 32; count < 128; count++)
307 LPWSTR result = StrRChrW(string+32, NULL, count);
308 ok(result - string == count,
309 "found char %d in wrong place: got %d, expected %d\n",
310 count, result - string, count);
313 for (count = 32; count < 128; count++)
315 LPWSTR result = StrRChrW(string+count+1, NULL, count);
316 ok(!result, "found char %d not in the string\n", count);
319 for (count = 32; count < 128; count++)
321 LPWSTR result = StrRChrW(string+count+1, string + 127, count);
322 ok(!result, "found char %d not in the string\n", count);
326 static void test_StrCpyW(void)
330 const StrFormatSizeResult* result = StrFormatSize_results;
335 MultiByteToWideChar(0,0,result->byte_size_64,-1,szSrc,sizeof(szSrc)/sizeof(WCHAR));
337 StrCpyW(szBuff, szSrc);
338 ok(!StrCmpW(szSrc, szBuff), "Copied string %s wrong", result->byte_size_64);
344 static void test_StrToIntA(void)
346 const StrToIntResult *result = StrToInt_results;
349 while (result->string)
351 return_val = StrToIntA(result->string);
352 ok(return_val == result->str_to_int, "converted '%s' wrong (%d)",
353 result->string, return_val);
358 static void test_StrToIntW(void)
361 const StrToIntResult *result = StrToInt_results;
364 while (result->string)
366 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
367 return_val = StrToIntW(szBuff);
368 ok(return_val == result->str_to_int, "converted '%s' wrong (%d)",
369 result->string, return_val);
374 static void test_StrToIntExA(void)
376 const StrToIntResult *result = StrToInt_results;
380 while (result->string)
383 bRet = StrToIntExA(result->string,0,&return_val);
384 ok(!bRet || return_val != -1, "No result returned from '%s'",
387 ok(return_val == result->str_to_int_ex, "converted '%s' wrong (%d)",
388 result->string, return_val);
392 result = StrToInt_results;
393 while (result->string)
396 bRet = StrToIntExA(result->string,STIF_SUPPORT_HEX,&return_val);
397 ok(!bRet || return_val != -1, "No result returned from '%s'",
400 ok(return_val == result->str_to_int_hex, "converted '%s' wrong (%d)",
401 result->string, return_val);
406 static void test_StrToIntExW(void)
409 const StrToIntResult *result = StrToInt_results;
413 while (result->string)
416 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
417 bRet = StrToIntExW(szBuff, 0, &return_val);
418 ok(!bRet || return_val != -1, "No result returned from '%s'",
421 ok(return_val == result->str_to_int_ex, "converted '%s' wrong (%d)",
422 result->string, return_val);
426 result = StrToInt_results;
427 while (result->string)
430 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
431 bRet = StrToIntExW(szBuff, STIF_SUPPORT_HEX, &return_val);
432 ok(!bRet || return_val != -1, "No result returned from '%s'",
435 ok(return_val == result->str_to_int_hex, "converted '%s' wrong (%d)",
436 result->string, return_val);
441 static void test_StrDupA()
444 const StrFormatSizeResult* result = StrFormatSize_results;
448 lpszStr = StrDupA(result->byte_size_64);
450 ok(lpszStr != NULL, "Dup failed");
453 ok(!strcmp(result->byte_size_64, lpszStr), "Copied string wrong");
454 LocalFree((HLOCAL)lpszStr);
459 /* Later versions of shlwapi return NULL for this, but earlier versions
460 * returned an empty string (as Wine does).
462 lpszStr = StrDupA(NULL);
463 ok(lpszStr == NULL || *lpszStr == '\0', "NULL string returned %p", lpszStr);
466 static void test_StrFormatByteSize64A(void)
468 /* this test fails on locales which do not use '.' as a decimal separator */
471 const StrFormatSizeResult* result = StrFormatSize_results;
475 StrFormatByteSize64A(result->value, szBuff, 256);
477 ok(!strcmp(result->byte_size_64, szBuff),
478 "Formatted %lx%08lx wrong: got %s, expected %s\n",
479 (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->byte_size_64);
486 static void test_StrFormatKBSizeW(void)
488 /* FIXME: Awaiting NLS fixes in kernel before these succeed */
492 const StrFormatSizeResult* result = StrFormatSize_results;
496 StrFormatKBSizeW(result->value, szBuffW, 256);
497 WideCharToMultiByte(0,0,szBuffW,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR),0,0);
498 ok(!strcmp(result->kb_size, szBuff),
499 "Formatted %lx%08lx wrong: got %s, expected %s\n",
500 (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->kb_size);
506 static void test_StrFormatKBSizeA(void)
508 /* this test fails on locales which do not use '.' as a decimal separator */
511 const StrFormatSizeResult* result = StrFormatSize_results;
515 StrFormatKBSizeA(result->value, szBuff, 256);
517 ok(!strcmp(result->kb_size, szBuff),
518 "Formatted %lx%08lx wrong: got %s, expected %s\n",
519 (LONG)(result->value >> 32), (LONG)result->value, szBuff, result->kb_size);
525 void test_StrFromTimeIntervalA(void)
528 const StrFromTimeIntervalResult* result = StrFromTimeInterval_results;
532 StrFromTimeIntervalA(szBuff, 256, result->ms, result->digits);
534 ok(!strcmp(result->time_interval, szBuff), "Formatted %ld %d wrong",
535 result->ms, result->digits);
554 test_StrFormatByteSize64A();
555 test_StrFormatKBSizeA();
556 test_StrFormatKBSizeW();
557 test_StrFromTimeIntervalA();