3 static VOID Test_buffer(
7 #define OUTPUT_COUNT 10
15 format[0].
u.
Int32 = 1234567890;
17 result =
PhFormatToBuffer(format, 1, buffer, (OUTPUT_COUNT + 1) *
sizeof(WCHAR), &returnLength);
18 assert(result && wcscmp(buffer, L
"1234567890") == 0 && returnLength == (OUTPUT_COUNT + 1) *
sizeof(WCHAR));
19 result =
PhFormatToBuffer(format, 1, buffer, 16 *
sizeof(WCHAR), &returnLength);
20 assert(result && wcscmp(buffer, L
"1234567890") == 0 && returnLength == (OUTPUT_COUNT + 1) *
sizeof(WCHAR));
21 result =
PhFormatToBuffer(format, 1, buffer, OUTPUT_COUNT *
sizeof(WCHAR), &returnLength);
22 assert(!result && buffer[0] == 0 && returnLength == (OUTPUT_COUNT + 1) *
sizeof(WCHAR));
24 assert(!result && returnLength == (OUTPUT_COUNT + 1) *
sizeof(WCHAR));
26 assert(!result && returnLength == (OUTPUT_COUNT + 1) *
sizeof(WCHAR));
29 static VOID Test_char(
38 format[0].
u.
Char =
'H';
40 format[1].
u.
Char =
'i';
42 assert(result && wcscmp(buffer, L
"Hi") == 0);
45 static VOID Test_string(
62 assert(result && wcscmp(buffer, L
"This is a string.") == 0);
65 static BOOLEAN IsThousandSepComma(
71 if (!GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, thousandSep, 4))
73 if (thousandSep[0] !=
',' || thousandSep[1] != 0)
79 static VOID Test_integer(
92 assert(result && wcscmp(buffer, L
"0") == 0);
97 assert(result && wcscmp(buffer, L
"123") == 0);
102 assert(result && wcscmp(buffer, L
"-123") == 0);
107 assert(result && wcscmp(buffer, L
"4294967173") == 0);
110 format[0].
u.
Int64 = -1234567890;
112 assert(result && wcscmp(buffer, L
"-1234567890") == 0);
115 format[0].
u.
UInt64 = 12345678901234567890;
117 assert(result && wcscmp(buffer, L
"12345678901234567890") == 0);
122 format[0].
u.
UInt64 = 12345678901234567890;
123 format[0].
Radix = 16;
125 assert(result && wcscmp(buffer, L
"ab54a98ceb1f0ad2") == 0);
128 format[0].
u.
UInt64 = 12345678901234567890;
129 format[0].
Radix = 16;
131 assert(result && wcscmp(buffer, L
"AB54A98CEB1F0AD2") == 0);
134 format[0].
u.
Int32 = -1234;
137 assert(result && wcscmp(buffer, L
"-2322") == 0);
144 assert(result && wcscmp(buffer, L
"+1234") == 0);
147 format[0].
u.
Int32 = -1234;
149 assert(result && wcscmp(buffer, L
"-1234") == 0);
158 assert(result && wcscmp(buffer, L
"000000") == 0);
161 assert(result && wcscmp(buffer, L
"000001") == 0);
162 format[0].
u.
Int32 = 12345;
164 assert(result && wcscmp(buffer, L
"012345") == 0);
165 format[0].
u.
Int32 = 123456;
167 assert(result && wcscmp(buffer, L
"123456") == 0);
168 format[0].
u.
Int32 = 1234567890;
170 assert(result && wcscmp(buffer, L
"1234567890") == 0);
173 assert(result && wcscmp(buffer, L
"-00001") == 0);
174 format[0].
u.
Int32 = -1234;
176 assert(result && wcscmp(buffer, L
"-01234") == 0);
177 format[0].
u.
Int32 = -12345;
179 assert(result && wcscmp(buffer, L
"-12345") == 0);
180 format[0].
u.
Int32 = -1234567890;
182 assert(result && wcscmp(buffer, L
"-1234567890") == 0);
186 if (!IsThousandSepComma())
193 assert(result && wcscmp(buffer, L
"0") == 0);
196 assert(result && wcscmp(buffer, L
"1") == 0);
199 assert(result && wcscmp(buffer, L
"12") == 0);
202 assert(result && wcscmp(buffer, L
"123") == 0);
205 assert(result && wcscmp(buffer, L
"1,234") == 0);
206 format[0].
u.
Int32 = 12345;
208 assert(result && wcscmp(buffer, L
"12,345") == 0);
209 format[0].
u.
Int32 = 123456;
211 assert(result && wcscmp(buffer, L
"123,456") == 0);
214 assert(result && wcscmp(buffer, L
"-123") == 0);
215 format[0].
u.
Int32 = -1234;
217 assert(result && wcscmp(buffer, L
"-1,234") == 0);
218 format[0].
u.
Int32 = -12345;
220 assert(result && wcscmp(buffer, L
"-12,345") == 0);
223 static VOID Test_float(
238 assert(result && wcscmp(buffer, L
"0.000000") == 0);
243 assert(result && wcscmp(buffer, L
"1.000000") == 0);
246 format[0].
u.
Double = 123456789;
248 assert(result && wcscmp(buffer, L
"123456789.000000") == 0);
251 format[0].
u.
Double = 3.14159265358979;
253 assert(result && wcscmp(buffer, L
"3.141593") == 0);
261 assert(result && wcscmp(buffer, L
"0") == 0);
264 format[0].
u.
Double = 3.14159265358979;
267 assert(result && wcscmp(buffer, L
"3") == 0);
270 format[0].
u.
Double = 3.14159265358979;
273 assert(result && wcscmp(buffer, L
"3.1") == 0);
276 format[0].
u.
Double = 3.14159265358979;
279 assert(result && wcscmp(buffer, L
"3.1416") == 0);
287 assert(result && wcscmp(buffer, L
"0") == 0);
293 assert(result && wcscmp(buffer, L
"1.2") == 0);
299 assert(result && wcscmp(buffer, L
"1.21") == 0);
305 assert(result && wcscmp(buffer, L
"1.216") == 0);
311 assert(result && wcscmp(buffer, L
"1.216") == 0);
318 assert(result && wcscmp(buffer, L
"+1234.000000") == 0);
324 assert(result && wcscmp(buffer, L
"+1234") == 0);
329 assert(result && wcscmp(buffer, L
"-1234.000000") == 0);
334 assert(result && wcscmp(buffer, L
"-1234.120000") == 0);
344 assert(result && wcscmp(buffer, L
"00.000") == 0);
348 assert(result && wcscmp(buffer, L
"01.230") == 0);
352 assert(result && wcscmp(buffer, L
"123456.000") == 0);
356 assert(result && wcscmp(buffer, L
"-01.23") == 0);
360 assert(result && wcscmp(buffer, L
"-1.230") == 0);
364 if (!IsThousandSepComma())
372 assert(result && wcscmp(buffer, L
"0") == 0);
376 assert(result && wcscmp(buffer, L
"1") == 0);
380 assert(result && wcscmp(buffer, L
"12") == 0);
384 assert(result && wcscmp(buffer, L
"123") == 0);
388 assert(result && wcscmp(buffer, L
"1,234") == 0);
392 assert(result && wcscmp(buffer, L
"12,345") == 0);
396 assert(result && wcscmp(buffer, L
"123,456") == 0);
400 assert(result && wcscmp(buffer, L
"-123") == 0);
404 assert(result && wcscmp(buffer, L
"-1,234") == 0);
408 assert(result && wcscmp(buffer, L
"-12,345") == 0);
412 assert(result && wcscmp(buffer, L
"-12,345.00") == 0);
413 format[0].
u.
Double = -9876543.21;
416 assert(result && wcscmp(buffer, L
"-9,876,543.21000") == 0);
419 static VOID Test_width(
431 assert(result && wcscmp(buffer, L
"asdf") == 0);
438 assert(result && wcscmp(buffer, L
"asdf") == 0);
443 assert(result && wcscmp(buffer, L
"asdf") == 0);
448 assert(result && wcscmp(buffer, L
"asdf ") == 0);
451 format[0].
Width = 10;
453 assert(result && wcscmp(buffer, L
"asdf ") == 0);
459 assert(result && wcscmp(buffer, L
"asdf!!") == 0);
466 assert(result && wcscmp(buffer, L
"asdf") == 0);
471 assert(result && wcscmp(buffer, L
"asdf") == 0);
476 assert(result && wcscmp(buffer, L
" asdf") == 0);
479 format[0].
Width = 10;
481 assert(result && wcscmp(buffer, L
" asdf") == 0);
487 assert(result && wcscmp(buffer, L
"!!asdf") == 0);
496 format[1].
Width = 10;
498 assert(result && wcscmp(buffer, L
" 1234asdf ") == 0);
501 static VOID Test_wildcards(
505 static WCHAR *testCases[][3] =
507 { L
"", L
"", L
"true" },
508 { L
"", L
"a", L
"false" },
509 { L
"a", L
"a", L
"true" },
510 { L
"a", L
"b", L
"false" },
511 { L
"?", L
"b", L
"true" },
512 { L
"??", L
"bc", L
"true" },
513 { L
"?c", L
"bc", L
"true" },
514 { L
"b?", L
"bc", L
"true" },
515 { L
"*", L
"a", L
"true" },
516 { L
"**", L
"a", L
"true" },
517 { L
"*", L
"", L
"true" },
518 { L
"*bc*hij", L
"abcdfghij", L
"true" },
519 { L
"*b*a*", L
"b", L
"false" },
520 { L
"*bc*hik", L
"abcdfghij", L
"false" },
521 { L
"abc*", L
"abc", L
"true" },
522 { L
"abc**", L
"abc", L
"true" },
523 { L
"*???", L
"abc", L
"true" },
524 { L
"*???", L
"ab", L
"false" },
525 { L
"*???", L
"abcd", L
"true" },
526 { L
"*?*", L
"abcd", L
"true" },
527 { L
"*bc", L
"abc", L
"true" },
528 { L
"*cc", L
"abc", L
"false" },
529 { L
"*a*", L
"de", L
"false" },
530 { L
"*???*", L
"123", L
"true" },
531 { L
"a*bc", L
"abbc", L
"true" },
532 { L
"a*b", L
"a", L
"false" },
533 { L
"a*?b", L
"axb", L
"true" },
534 { L
"a**b", L
"axb", L
"true" }
541 for (i = 0; i <
sizeof(testCases) /
sizeof(WCHAR *[3]); i++)
548 wprintf(L
"pattern '%s' against '%s': %s (%s expected)\n",
549 testCases[i][0], testCases[i][1], r ? L
"true" : L
"false", testCases[i][2]);