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 ok(!StrChrA(NULL,'\0'), "found a character in a NULL string!");
163 for (count = 32; count < 128; count++)
164 string[count] = count;
167 for (count = 32; count < 128; count++)
169 LPSTR result = StrChrA(string+32, count);
170 ok(result - string == count, "found char %d in wrong place", count);
173 for (count = 32; count < 128; count++)
175 LPSTR result = StrChrA(string+count+1, count);
176 ok(!result, "found char not in the string");
180 static void test_StrChrW(void)
185 ok(!StrChrW(NULL,'\0'), "found a character in a NULL string!");
187 for (count = 32; count < 16384; count++)
188 string[count] = count;
189 string[16384] = '\0';
191 for (count = 32; count < 16384; count++)
193 LPWSTR result = StrChrW(string+32, count);
194 ok((result - string) == count, "found char %d in wrong place", count);
197 for (count = 32; count < 16384; count++)
199 LPWSTR result = StrChrW(string+count+1, count);
200 ok(!result, "found char not in the string");
204 static void test_StrChrIA(void)
209 ok(!StrChrIA(NULL,'\0'), "found a character in a NULL string!");
211 for (count = 32; count < 128; count++)
212 string[count] = count;
215 for (count = 'A'; count <= 'X'; count++)
217 LPSTR result = StrChrIA(string+32, count);
219 ok(result - string == count, "found char '%c' in wrong place", count);
220 ok(StrChrIA(result, count)!=NULL, "didn't find lowercase '%c'", count);
223 for (count = 'a'; count < 'z'; count++)
225 LPSTR result = StrChrIA(string+count+1, count);
226 ok(!result, "found char not in the string");
230 static void test_StrChrIW(void)
235 ok(!StrChrIA(NULL,'\0'), "found a character in a NULL string!");
237 for (count = 32; count < 128; count++)
238 string[count] = count;
241 for (count = 'A'; count <= 'X'; count++)
243 LPWSTR result = StrChrIW(string+32, count);
245 ok(result - string == count, "found char '%c' in wrong place", count);
246 ok(StrChrIW(result, count)!=NULL, "didn't find lowercase '%c'", count);
249 for (count = 'a'; count < 'z'; count++)
251 LPWSTR result = StrChrIW(string+count+1, count);
252 ok(!result, "found char not in the string");
256 static void test_StrRChrA(void)
261 ok(!StrRChrA(NULL, NULL,'\0'), "found a character in a NULL string!");
263 for (count = 32; count < 128; count++)
264 string[count] = count;
267 for (count = 32; count < 128; count++)
269 LPSTR result = StrRChrA(string+32, NULL, count);
270 ok(result - string == count, "found char %d in wrong place", count);
273 for (count = 32; count < 128; count++)
275 LPSTR result = StrRChrA(string+count+1, NULL, count);
276 ok(!result, "found char not in the string");
279 for (count = 32; count < 128; count++)
281 LPSTR result = StrRChrA(string+count+1, string + 127, count);
282 ok(!result, "found char not in the string");
286 static void test_StrRChrW(void)
291 ok(!StrRChrW(NULL, NULL,'\0'), "found a character in a NULL string!");
293 for (count = 32; count < 16384; count++)
294 string[count] = count;
295 string[16384] = '\0';
297 for (count = 32; count < 16384; count++)
299 LPWSTR result = StrRChrW(string+32, NULL, count);
300 ok(result - string == count, "found char %d in wrong place", count);
303 for (count = 32; count < 16384; count++)
305 LPWSTR result = StrRChrW(string+count+1, NULL, count);
306 ok(!result, "found char not in the string");
309 for (count = 32; count < 16384; count++)
311 LPWSTR result = StrRChrW(string+count+1, string + 127, count);
312 ok(!result, "found char not in the string");
316 static void test_StrCpyW(void)
320 const StrFormatSizeResult* result = StrFormatSize_results;
325 MultiByteToWideChar(0,0,result->byte_size_64,-1,szSrc,sizeof(szSrc)/sizeof(WCHAR));
327 StrCpyW(szBuff, szSrc);
328 ok(!StrCmpW(szSrc, szBuff), "Copied string %s wrong", result->byte_size_64);
334 static void test_StrToIntA(void)
336 const StrToIntResult *result = StrToInt_results;
339 while (result->string)
341 return_val = StrToIntA(result->string);
342 ok(return_val == result->str_to_int, "converted '%s' wrong (%d)",
343 result->string, return_val);
348 static void test_StrToIntW(void)
351 const StrToIntResult *result = StrToInt_results;
354 while (result->string)
356 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
357 return_val = StrToIntW(szBuff);
358 ok(return_val == result->str_to_int, "converted '%s' wrong (%d)",
359 result->string, return_val);
364 static void test_StrToIntExA(void)
366 const StrToIntResult *result = StrToInt_results;
370 while (result->string)
373 bRet = StrToIntExA(result->string,0,&return_val);
374 ok(!bRet || return_val != -1, "No result returned from '%s'",
377 ok(return_val == result->str_to_int_ex, "converted '%s' wrong (%d)",
378 result->string, return_val);
382 result = StrToInt_results;
383 while (result->string)
386 bRet = StrToIntExA(result->string,STIF_SUPPORT_HEX,&return_val);
387 ok(!bRet || return_val != -1, "No result returned from '%s'",
390 ok(return_val == result->str_to_int_hex, "converted '%s' wrong (%d)",
391 result->string, return_val);
396 static void test_StrToIntExW(void)
399 const StrToIntResult *result = StrToInt_results;
403 while (result->string)
406 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
407 bRet = StrToIntExW(szBuff, 0, &return_val);
408 ok(!bRet || return_val != -1, "No result returned from '%s'",
411 ok(return_val == result->str_to_int_ex, "converted '%s' wrong (%d)",
412 result->string, return_val);
416 result = StrToInt_results;
417 while (result->string)
420 MultiByteToWideChar(0,0,result->string,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR));
421 bRet = StrToIntExW(szBuff, STIF_SUPPORT_HEX, &return_val);
422 ok(!bRet || return_val != -1, "No result returned from '%s'",
425 ok(return_val == result->str_to_int_hex, "converted '%s' wrong (%d)",
426 result->string, return_val);
431 static void test_StrDupA()
434 const StrFormatSizeResult* result = StrFormatSize_results;
438 lpszStr = StrDupA(result->byte_size_64);
440 ok(lpszStr != NULL, "Dup failed");
443 ok(!strcmp(result->byte_size_64, lpszStr), "Copied string wrong");
444 LocalFree((HLOCAL)lpszStr);
449 /* Later versions of shlwapi return NULL for this, but earlier versions
450 * returned an empty string (as Wine does).
452 lpszStr = StrDupA(NULL);
453 ok(lpszStr == NULL || *lpszStr == '\0', "NULL string returned %p", lpszStr);
456 static void test_StrFormatByteSize64A(void)
459 const StrFormatSizeResult* result = StrFormatSize_results;
463 StrFormatByteSize64A(result->value, szBuff, 256);
465 ok(!strcmp(result->byte_size_64, szBuff), "Formatted %lld wrong", result->value);
471 static void test_StrFormatKBSizeW(void)
473 /* FIXME: Awaiting NLS fixes in kernel before these succeed */
477 const StrFormatSizeResult* result = StrFormatSize_results;
481 StrFormatKBSizeW(result->value, szBuffW, 256);
482 WideCharToMultiByte(0,0,szBuffW,-1,szBuff,sizeof(szBuff)/sizeof(WCHAR),0,0);
483 ok(!strcmp(result->kb_size, szBuff), "Formatted %lld wrong",
490 static void test_StrFormatKBSizeA(void)
494 const StrFormatSizeResult* result = StrFormatSize_results;
498 StrFormatKBSizeA(result->value, szBuff, 256);
500 ok(!strcmp(result->kb_size, szBuff), "Formatted %lld wrong",
507 void test_StrFromTimeIntervalA(void)
510 const StrFromTimeIntervalResult* result = StrFromTimeInterval_results;
514 StrFromTimeIntervalA(szBuff, 256, result->ms, result->digits);
516 ok(!strcmp(result->time_interval, szBuff), "Formatted %ld %d wrong",
517 result->ms, result->digits);
536 test_StrFormatByteSize64A();
537 test_StrFormatKBSizeA();
538 test_StrFormatKBSizeW();
539 test_StrFromTimeIntervalA();