1 // -----------------------------------------------------------------------
3 // -----------------------------------------------------------------------
5 // matching six characters literally
6 // should report six characters read
7 TESTSCAN( 0, 6, general, 0, SCAN( "123456" ) );
10 // matching a character, three whitespace chars, and another character
11 // should report five characters read
12 TESTSCAN( 0, 5, general, 30, SCAN( "1 5" ) );
15 // matching three characters, not matching whitespaces, and matching another three characters
16 // should report six characters matched
17 TESTSCAN( 0, 6, general, 0, SCAN( "123 456" ) );
20 // matching a character, two '%' characters, and two whitespaces
21 // should report five characters matched
22 TESTSCAN( 0, 5, general, 34, SCAN( "5%%%% " ) );
25 // seeking to last character in file, trying to match that char and a whitespace
26 // should report one character matched and EOF
27 TESTSCAN( 0, 1, general, 39, SCAN( "0 " ) );
30 // seeking to end of file, trying to match a -1
31 // should report error, not executing %n
32 TESTSCAN( -1, -1, general, 40, SCAN( "\377" ) ); /* FIXME */
35 // -----------------------------------------------------------------------
36 // Character matching ('%c')
37 // -----------------------------------------------------------------------
39 // reading a char array of specified width, including zero bytes
40 // should report the characters read up to first zero
44 char expected[] = "1\177\177\177\177\177\177\177";
47 char expected[] = "1\0003-5+7";
49 memset( buffer, '\177', 8 );
50 TESTSCAN( 1, count, general, 10, SCANPARMS( "%7c", buffer ) );
51 TESTCASE( memcmp( buffer, expected, 7 ) == 0 );
54 // reading a char array of unspecified width when positioned at -1 value
55 // should default to width one, read the -1 value, no zero termination of the array
57 memset( buffer, '\177', 2 );
58 TESTSCAN( 1, 1, general, 19, SCANPARMS( "%c", buffer ) );
59 TESTCASE( memcmp( buffer, "\377\177", 2 ) == 0 );
62 // reading a char array of specified width 1 when positioned at (non-space) whitespace
63 // should read the whitespace (literally), no zero termination of the array
65 memset( buffer, '\177', 2 );
66 TESTSCAN( 1, 1, general, 32, SCANPARMS( "%1c", buffer ) );
67 TESTCASE( memcmp( buffer, "\011\177", 2 ) == 0 );
70 // reading a char array of specified width 2 when positioned at last char of file
71 // should read the character, and report EOF
73 memset( buffer, '\177', 2 );
74 TESTSCAN( 1, 1, general, 39, SCANPARMS( "%2c", buffer ) );
75 TESTCASE( memcmp( buffer, "0\177", 2 ) == 0 );
78 // reading a char array of specified width 1 when positioned at last char of file
79 // should read the character, and NOT report EOF
81 memset( buffer, '\177', 2 );
82 TESTSCAN( 1, 1, general, 39, SCANPARMS( "%1c", buffer ) );
83 TESTCASE( memcmp( buffer, "0\177", 2 ) == 0 );
86 // reading a char array of specified width 1 when positioned at EOF
87 // should report input error before any conversion (-1)
89 memset( buffer, '\177', 2 );
90 TESTSCAN( -1, -1, general, 40, SCANPARMS( "%1c", buffer ) );
91 TESTCASE( memcmp( buffer, "\177\177", 2 ) == 0 );
94 // -----------------------------------------------------------------------
95 // Integer matching ('%d')
96 // -----------------------------------------------------------------------
98 // reading a whitespace-terminated integer
100 TESTSCAN( 1, 1, general, 20, SCANPARMS( "%d", &i ) );
104 // reading a -1 terminated integer
106 TESTSCAN( 1, 1, general, 18, SCANPARMS( "%d", &i ) );
110 // reading a EOF terminated integer
112 TESTSCAN( 1, 1, general, 39, SCANPARMS( "%d", &i ) );
116 // trying to read an integer when positioned at whitespace
117 // should skip whitespaces
119 TESTSCAN( 1, 3, general, 32, SCANPARMS( "%d", &i ) );
123 // trying to read an integer when positioned at -1 value
124 // should report matching failure
126 TESTSCAN( 0, -1, general, 19, SCANPARMS( "%d", &i ) );
130 // trying to read an integer when positioned at EOF
131 // should report reading failure
133 TESTSCAN( -1, -1, general, 40, SCANPARMS( "%d", &i ) );
137 // reading a '-'-prefixed integer
139 TESTSCAN( 1, 2, general, 13, SCANPARMS( "%d", &i ) );
143 // reading a '+'-prefixed integer
145 TESTSCAN( 1, 2, general, 15, SCANPARMS( "%d", &i ) );
149 // decimal integer matches
153 TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%hhd", &i ) );
159 TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%hhd", &i ) );
165 TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%hhd", &i ) );
171 TESTSCAN( 1, 4, decimal, 6, SCANPARMS( "%hhd", &i ) );
172 TESTCASE( i == -128 );
177 TESTSCAN( 1, 3, decimal, 12, SCANPARMS( "%hhd", &i ) );
178 TESTCASE( i == 127 );
183 TESTSCAN( 1, 4, decimal, 11, SCANPARMS( "%hhd", &i ) );
184 TESTCASE( i == 127 );
188 unsigned char i = -1;
189 TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%hhu", &i ) );
194 unsigned char i = -1;
195 TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%hhu", &i ) );
200 unsigned char i = -1;
201 TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%hhu", &i ) );
206 unsigned char i = -1;
207 TESTSCAN( 1, 3, decimal, 12, SCANPARMS( "%hhu", &i ) );
208 TESTCASE( i == 127 );
212 unsigned char i = -1;
213 TESTSCAN( 1, 4, decimal, 11, SCANPARMS( "%hhu", &i ) );
214 TESTCASE( i == 127 );
219 TESTSCAN( 1, 3, decimal, 17, SCANPARMS( "%hhu", &i ) );
220 TESTCASE( i == 255 );
225 TESTSCAN( 1, 4, decimal, 16, SCANPARMS( "%hhu", &i ) );
226 TESTCASE( i == 255 );
231 TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%hhi", &i ) );
237 TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%hhi", &i ) );
243 TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%hhi", &i ) );
249 TESTSCAN( 1, 4, decimal, 6, SCANPARMS( "%hhi", &i ) );
250 TESTCASE( i == -128 );
255 TESTSCAN( 1, 3, decimal, 12, SCANPARMS( "%hhi", &i ) );
256 TESTCASE( i == 127 );
261 TESTSCAN( 1, 4, decimal, 11, SCANPARMS( "%hhi", &i ) );
262 TESTCASE( i == 127 );
267 TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%hd", &i ) );
273 TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%hd", &i ) );
279 TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%hd", &i ) );
285 TESTSCAN( 1, 6, decimal, 21, SCANPARMS( "%hd", &i ) );
286 TESTCASE( i == -32768 );
291 TESTSCAN( 1, 5, decimal, 29, SCANPARMS( "%hd", &i ) );
292 TESTCASE( i == 32767 );
297 TESTSCAN( 1, 6, decimal, 28, SCANPARMS( "%hd", &i ) );
298 TESTCASE( i == 32767 );
302 unsigned short i = -1;
303 TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%hu", &i ) );
308 unsigned short i = -1;
309 TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%hu", &i ) );
314 unsigned short i = -1;
315 TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%hu", &i ) );
320 unsigned short i = -1;
321 TESTSCAN( 1, 5, decimal, 29, SCANPARMS( "%hu", &i ) );
322 TESTCASE( i == 32767 );
326 unsigned short i = -1;
327 TESTSCAN( 1, 6, decimal, 28, SCANPARMS( "%hu", &i ) );
328 TESTCASE( i == 32767 );
332 unsigned short i = 0;
333 TESTSCAN( 1, 5, decimal, 36, SCANPARMS( "%hu", &i ) );
334 TESTCASE( i == 65535 );
338 unsigned short i = 0;
339 TESTSCAN( 1, 6, decimal, 35, SCANPARMS( "%hu", &i ) );
340 TESTCASE( i == 65535 );
345 TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%hi", &i ) );
351 TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%hi", &i ) );
357 TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%hi", &i ) );
363 TESTSCAN( 1, 6, decimal, 21, SCANPARMS( "%hi", &i ) );
364 TESTCASE( i == -32768 );
369 TESTSCAN( 1, 5, decimal, 29, SCANPARMS( "%hi", &i ) );
370 TESTCASE( i == 32767 );
375 TESTSCAN( 1, 6, decimal, 28, SCANPARMS( "%hi", &i ) );
376 TESTCASE( i == 32767 );
381 TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%d", &i ) );
387 TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%d", &i ) );
393 TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%d", &i ) );
397 // reading -2147483648, d
399 TESTSCAN( 1, 11, decimal, 42, SCANPARMS( "%d", &i ) );
400 TESTCASE( i == -2147483648 );
403 // reading 2147483647, d
405 TESTSCAN( 1, 10, decimal, 55, SCANPARMS( "%d", &i ) );
406 TESTCASE( i == 2147483647 );
409 // reading +2147483647, d
411 TESTSCAN( 1, 11, decimal, 54, SCANPARMS( "%d", &i ) );
412 TESTCASE( i == 2147483647 );
417 TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%u", &i ) );
423 TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%u", &i ) );
429 TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%u", &i ) );
433 // reading 2147483647, u
435 TESTSCAN( 1, 10, decimal, 55, SCANPARMS( "%u", &i ) );
436 TESTCASE( i == 2147483647 );
439 // reading +2147483647, u
441 TESTSCAN( 1, 11, decimal, 54, SCANPARMS( "%u", &i ) );
442 TESTCASE( i == 2147483647 );
445 // reading 4294967295, u
447 TESTSCAN( 1, 10, decimal, 67, SCANPARMS( "%u", &i ) );
448 CHECK_FEQUAL( i, 4294967295, unsigned int, "%u" );
451 // reading +4294967295, u
453 TESTSCAN( 1, 11, decimal, 66, SCANPARMS( "%u", &i ) );
454 CHECK_FEQUAL( i, 4294967295, unsigned int, "%u" );
459 TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%i", &i ) );
465 TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%i", &i ) );
471 TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%i", &i ) );
475 // reading -2147483648, i
477 TESTSCAN( 1, 11, decimal, 42, SCANPARMS( "%i", &i ) );
478 TESTCASE( i == -2147483648 );
481 // reading 2147483647, i
483 TESTSCAN( 1, 10, decimal, 55, SCANPARMS( "%i", &i ) );
484 TESTCASE( i == 2147483647 );
487 // reading +2147483647, i
489 TESTSCAN( 1, 11, decimal, 54, SCANPARMS( "%i", &i ) );
490 TESTCASE( i == 2147483647 );
495 TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%ld", &i ) );
501 TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%ld", &i ) );
507 TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%ld", &i ) );
511 // reading -2147483648, d
513 TESTSCAN( 1, 11, decimal, 42, SCANPARMS( "%ld", &i ) );
514 TESTCASE( i == -2147483648l );
517 // reading 2147483647, d
519 TESTSCAN( 1, 10, decimal, 55, SCANPARMS( "%ld", &i ) );
520 TESTCASE( i == 2147483647l );
523 // reading +2147483647, d
525 TESTSCAN( 1, 11, decimal, 54, SCANPARMS( "%ld", &i ) );
526 TESTCASE( i == 2147483647l );
530 unsigned long i = -1;
531 TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%lu", &i ) );
532 TESTCASE( i == 0ul );
536 unsigned long i = -1;
537 TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%lu", &i ) );
538 TESTCASE( i == 0ul );
542 unsigned long i = -1;
543 TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%lu", &i ) );
544 TESTCASE( i == 0ul );
547 // reading 2147483647, u
548 unsigned long i = -1;
549 TESTSCAN( 1, 10, decimal, 55, SCANPARMS( "%lu", &i ) );
550 TESTCASE( i == 2147483647ul );
553 // reading +2147483647, u
554 unsigned long i = -1;
555 TESTSCAN( 1, 11, decimal, 54, SCANPARMS( "%lu", &i ) );
556 TESTCASE( i == 2147483647ul );
559 // reading 4294967295, u
561 TESTSCAN( 1, 10, decimal, 67, SCANPARMS( "%lu", &i ) );
562 CHECK_FEQUAL( i, 4294967295ul, unsigned long, "%lu" );
565 // reading +4294967295, u
567 TESTSCAN( 1, 11, decimal, 66, SCANPARMS( "%lu", &i ) );
568 CHECK_FEQUAL( i, 4294967295ul, unsigned long, "%lu" );
573 TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%li", &i ) );
579 TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%li", &i ) );
585 TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%li", &i ) );
589 // reading -2147483648, i
591 TESTSCAN( 1, 11, decimal, 42, SCANPARMS( "%li", &i ) );
592 TESTCASE( i == -2147483648l );
595 // reading 2147483647, i
597 TESTSCAN( 1, 10, decimal, 55, SCANPARMS( "%li", &i ) );
598 TESTCASE( i == 2147483647l );
601 // reading +2147483647, i
603 TESTSCAN( 1, 11, decimal, 54, SCANPARMS( "%li", &i ) );
604 TESTCASE( i == 2147483647l );
608 signed long long i = -1;
609 TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%lld", &i ) );
610 TESTCASE( i == 0ll );
614 signed long long i = -1;
615 TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%lld", &i ) );
616 TESTCASE( i == 0ll );
620 signed long long i = -1;
621 TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%lld", &i ) );
622 TESTCASE( i == 0ll );
625 // reading -9223372036854775808, d
626 signed long long i = -1;
627 TESTSCAN( 1, 20, decimal, 78, SCANPARMS( "%lli", &i ) );
628 CHECK_FEQUAL( i, LLONG_MIN, signed long long, "%lli" ); // should be literal -9223372036854775808ll but GCC balks.
632 // reading +9223372036854775807, d
633 signed long long i = -1;
634 TESTSCAN( 1, 20, decimal, 99, SCANPARMS( "%lld", &i ) );
635 CHECK_FEQUAL( i, 9223372036854775807ll, signed long long, "%lld" );
639 unsigned long long i = -1;
640 TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%llu", &i ) );
641 TESTCASE( i == 0ull );
645 unsigned long long i = -1;
646 TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%llu", &i ) );
647 TESTCASE( i == 0ull );
651 unsigned long long i = -1;
652 TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%llu", &i ) );
653 TESTCASE( i == 0ull );
656 // reading 9223372036854775807, u
657 unsigned long long i = -1;
658 TESTSCAN( 1, 19, decimal, 100, SCANPARMS( "%llu", &i ) );
659 CHECK_FEQUAL( i, 9223372036854775807ull, unsigned long long, "%llu" );
662 // reading +9223372036854775807, u
663 unsigned long long i = -1;
664 TESTSCAN( 1, 20, decimal, 99, SCANPARMS( "%llu", &i ) );
665 CHECK_FEQUAL( i, 9223372036854775807ull, unsigned long long, "%llu" );
668 // reading 18446744073709551615, u
669 unsigned long long i = 0;
670 TESTSCAN( 1, 20, decimal, 121, SCANPARMS( "%llu", &i ) );
671 CHECK_FEQUAL( i, 18446744073709551615ull, unsigned long long, "%llu" );
674 // reading +18446744073709551615, u
675 unsigned long long i = 0;
676 TESTSCAN( 1, 21, decimal, 120, SCANPARMS( "%llu", &i ) );
677 CHECK_FEQUAL( i, 18446744073709551615ull, unsigned long long, "%llu" );
681 signed long long i = -1;
682 TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%lli", &i ) );
683 TESTCASE( i == 0ll );
687 signed long long i = -1;
688 TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%lli", &i ) );
689 TESTCASE( i == 0ll );
693 signed long long i = -1;
694 TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%lli", &i ) );
695 TESTCASE( i == 0ll );
698 // reading -9223372036854775808, i
699 signed long long i = -1;
700 TESTSCAN( 1, 20, decimal, 78, SCANPARMS( "%lli", &i ) );
701 CHECK_FEQUAL( i, LLONG_MIN, signed long long, "%lli" ); // should be literal -9223372036854775808ll but GCC balks.
705 // reading 9223372036854775807, i
706 signed long long i = -1;
707 TESTSCAN( 1, 19, decimal, 100, SCANPARMS( "%lli", &i ) );
708 CHECK_FEQUAL( i, 9223372036854775807ll, signed long long, "%lli" );
711 // reading +9223372036854775807, i
712 signed long long i = -1;
713 TESTSCAN( 1, 20, decimal, 99, SCANPARMS( "%lli", &i ) );
714 CHECK_FEQUAL( i, 9223372036854775807ll, signed long long, "%lli" );
717 // hexadecimal integer matches
720 unsigned char i = -1;
721 TESTSCAN( 1, 1, hexadecimal, 3, SCANPARMS( "%hhx", &i ) );
726 unsigned char i = -1;
727 TESTSCAN( 1, 4, hexadecimal, 0, SCANPARMS( "%hhx", &i ) );
732 unsigned char i = -1;
733 TESTSCAN( 1, 6, hexadecimal, 5, SCANPARMS( "%hhx", &i ) );
739 TESTSCAN( 1, 4, hexadecimal, 0, SCANPARMS( "%hhi", &i ) );
744 unsigned char i = -1;
745 TESTSCAN( 1, 2, hexadecimal, 15, SCANPARMS( "%hhx", &i ) );
746 TESTCASE( i == 127 );
750 unsigned char i = -1;
751 TESTSCAN( 1, 5, hexadecimal, 12, SCANPARMS( "%hhx", &i ) );
752 CHECK_FEQUAL( i, -127, unsigned char, "%hhu" );
757 TESTSCAN( 1, 5, hexadecimal, 18, SCANPARMS( "%hhi", &i ) );
758 CHECK_FEQUAL( i, -128, signed char, "%hhd" );
762 unsigned char i = -1;
763 TESTSCAN( 1, 2, hexadecimal, 26, SCANPARMS( "%hhx", &i ) );
764 TESTCASE( i == 0xff );
768 unsigned char i = -1;
769 TESTSCAN( 1, 4, hexadecimal, 24, SCANPARMS( "%hhx", &i ) );
770 TESTCASE( i == 255 );
775 TESTSCAN( 1, 4, hexadecimal, 24, SCANPARMS( "%hhi", &i ) );
780 unsigned short i = -1;
781 TESTSCAN( 1, 1, hexadecimal, 3, SCANPARMS( "%hx", &i ) );
786 unsigned short i = -1;
787 TESTSCAN( 1, 4, hexadecimal, 0, SCANPARMS( "%hx", &i ) );
792 unsigned short i = -1;
793 TESTSCAN( 1, 6, hexadecimal, 5, SCANPARMS( "%hx", &i ) );
799 TESTSCAN( 1, 4, hexadecimal, 0, SCANPARMS( "%hi", &i ) );
804 unsigned short i = -1;
805 TESTSCAN( 1, 4, hexadecimal, 32, SCANPARMS( "%hx", &i ) );
806 TESTCASE( i == 32767 );
809 // reading -0x7fff, x
810 unsigned short i = -1;
811 TESTSCAN( 1, 7, hexadecimal, 29, SCANPARMS( "%hx", &i ) );
812 CHECK_FEQUAL( i, -32767, unsigned short, "%hu" );
815 // reading -0x8000, i
817 TESTSCAN( 1, 7, hexadecimal, 37, SCANPARMS( "%hi", &i ) );
818 CHECK_FEQUAL( i, -32768, signed short, "%hd" );
822 unsigned short i = -1;
823 TESTSCAN( 1, 4, hexadecimal, 47, SCANPARMS( "%hx", &i ) );
824 TESTCASE( i == 65535 );
828 unsigned short i = -1;
829 TESTSCAN( 1, 6, hexadecimal, 45, SCANPARMS( "%hx", &i ) );
830 TESTCASE( i == 65535 );
835 TESTSCAN( 1, 6, hexadecimal, 45, SCANPARMS( "%hi", &i ) );
836 CHECK_FEQUAL( i, -1, signed short, "%hd" );
841 TESTSCAN( 1, 1, hexadecimal, 3, SCANPARMS( "%x", &i ) );
847 TESTSCAN( 1, 4, hexadecimal, 0, SCANPARMS( "%x", &i ) );
853 TESTSCAN( 1, 6, hexadecimal, 5, SCANPARMS( "%x", &i ) );
859 TESTSCAN( 1, 4, hexadecimal, 0, SCANPARMS( "%i", &i ) );
863 // reading 7fffffff, x
865 TESTSCAN( 1, 8, hexadecimal, 55, SCANPARMS( "%x", &i ) );
866 TESTCASE( i == 2147483647 );
869 // reading -0x7fffffff, x
871 TESTSCAN( 1, 11, hexadecimal, 52, SCANPARMS( "%x", &i ) );
872 CHECK_FEQUAL( i, -2147483647, unsigned int, "%u" );
875 // reading -0x80000000, i
877 TESTSCAN( 1, 11, hexadecimal, 64, SCANPARMS( "%i", &i ) );
878 CHECK_FEQUAL( i, -2147483648, signed int, "%d" ); /* FIXME */
881 // reading ffffffff, x
883 TESTSCAN( 1, 8, hexadecimal, 78, SCANPARMS( "%x", &i ) );
884 CHECK_FEQUAL( i, 4294967295, unsigned int, "%d" );
887 // reading 0xffffffff, x
889 TESTSCAN( 1, 10, hexadecimal, 76, SCANPARMS( "%x", &i ) );
890 CHECK_FEQUAL( i, 4294967295, unsigned int, "%d" );
893 // octal integer matches
896 unsigned char i = -1;
897 TESTSCAN( 1, 1, octal, 4, SCANPARMS( "%hho", &i ) );
902 unsigned char i = -1;
903 TESTSCAN( 1, 5, octal, 0, SCANPARMS( "%hho", &i ) );
908 unsigned char i = -1;
909 TESTSCAN( 1, 5, octal, 6, SCANPARMS( "%hho", &i ) );
914 unsigned char i = -1;
915 TESTSCAN( 1, 4, octal, 13, SCANPARMS( "%hho", &i ) );
916 TESTCASE( i == 127u );
920 unsigned char i = -1;
921 TESTSCAN( 1, 5, octal, 12, SCANPARMS( "%hho", &i ) );
922 TESTCASE( i == 127u );
926 unsigned char i = -1;
927 TESTSCAN( 1, 4, octal, 19, SCANPARMS( "%hho", &i ) );
928 CHECK_FEQUAL( i, 255u, unsigned char, "%hhu" );
932 unsigned char i = -1;
933 TESTSCAN( 1, 5, octal, 18, SCANPARMS( "%hho", &i ) );
934 CHECK_FEQUAL( i, 255u, unsigned char, "%hhu" );
938 unsigned char i = -1;
939 TESTSCAN( 1, 5, octal, 24, SCANPARMS( "%hho", &i ) );
940 CHECK_FEQUAL( i, 1u, unsigned char, "%hhu" );
944 unsigned short i = -1;
945 TESTSCAN( 1, 6, octal, 31, SCANPARMS( "%ho", &i ) );
946 TESTCASE( i == 32767u );
949 // reading +077777, o
950 unsigned short i = -1;
951 TESTSCAN( 1, 7, octal, 30, SCANPARMS( "%ho", &i ) );
952 TESTCASE( i == 32767u );
955 // reading 0177777, o
956 unsigned short i = -1;
957 TESTSCAN( 1, 7, octal, 39, SCANPARMS( "%ho", &i ) );
958 CHECK_FEQUAL( i, 65535u, unsigned short, "%hu" );
961 // reading +0177777, o
962 unsigned short i = -1;
963 TESTSCAN( 1, 8, octal, 38, SCANPARMS( "%ho", &i ) );
964 CHECK_FEQUAL( i, 65535u, unsigned short, "%hu" );
967 // reading -0177777, o
968 unsigned short i = -1;
969 TESTSCAN( 1, 8, octal, 47, SCANPARMS( "%ho", &i ) );
970 CHECK_FEQUAL( i, 1u, unsigned short, "%hu" );
973 // reading 017777777777, o
975 TESTSCAN( 1, 12, octal, 57, SCANPARMS( "%o", &i ) );
976 TESTCASE( i == 2147483647u );
979 // reading +017777777777, o
981 TESTSCAN( 1, 13, octal, 56, SCANPARMS( "%o", &i ) );
982 TESTCASE( i == 2147483647u );
985 // reading 037777777777, o
987 TESTSCAN( 1, 12, octal, 71, SCANPARMS( "%o", &i ) );
988 CHECK_FEQUAL( i, 4294967295u, unsigned int, "%u" );
991 // reading +037777777777, o
993 TESTSCAN( 1, 13, octal, 70, SCANPARMS( "%o", &i ) );
994 CHECK_FEQUAL( i, 4294967295u, unsigned int, "%u" );
997 // reading -037777777777, o
999 TESTSCAN( 1, 13, octal, 84, SCANPARMS( "%o", &i ) );
1000 CHECK_FEQUAL( i, 1u, unsigned int, "%u" );
1003 // reading 017777777777, o
1004 unsigned long i = -1;
1005 TESTSCAN( 1, 12, octal, 57, SCANPARMS( "%lo", &i ) );
1006 TESTCASE( i == 2147483647lu );
1009 // reading +017777777777, o
1010 unsigned long i = -1;
1011 TESTSCAN( 1, 13, octal, 56, SCANPARMS( "%lo", &i ) );
1012 TESTCASE( i == 2147483647lu );
1015 // reading 037777777777, o
1016 unsigned long i = -1;
1017 TESTSCAN( 1, 12, octal, 71, SCANPARMS( "%lo", &i ) );
1018 CHECK_FEQUAL( i, 4294967295lu, unsigned long, "%lu" );
1021 // reading +037777777777, o
1022 unsigned long i = -1;
1023 TESTSCAN( 1, 13, octal, 70, SCANPARMS( "%lo", &i ) );
1024 CHECK_FEQUAL( i, 4294967295lu, unsigned long, "%lu" );
1027 // reading -037777777777, o
1028 unsigned long i = -1;
1029 TESTSCAN( 1, 13, octal, 84, SCANPARMS( "%lo", &i ) );
1030 CHECK_FEQUAL( i, 1lu, unsigned long, "%lu" );
1033 // reading 0777777777777777777777, o
1034 unsigned long long i = -1;
1035 TESTSCAN( 1, 22, octal, 99, SCANPARMS( "%llo", &i ) );
1036 CHECK_FEQUAL( i, 9223372036854775807llu, unsigned long long, "%llu" );
1039 // reading +0777777777777777777777, o
1040 unsigned long long i = -1;
1041 TESTSCAN( 1, 23, octal, 98, SCANPARMS( "%llo", &i ) );
1042 CHECK_FEQUAL( i, 9223372036854775807llu, unsigned long long, "%llu" );
1045 // reading 01777777777777777777777, o
1046 unsigned long long i = -1;
1047 TESTSCAN( 1, 23, octal, 123, SCANPARMS( "%llo", &i ) );
1048 CHECK_FEQUAL( i, 18446744073709551615llu, unsigned long long, "%llu" );
1051 // reading +01777777777777777777777, o
1052 unsigned long long i = -1;
1053 TESTSCAN( 1, 24, octal, 122, SCANPARMS( "%llo", &i ) );
1054 CHECK_FEQUAL( i, 18446744073709551615llu, unsigned long long, "%llu" );
1057 // reading -01777777777777777777777, o
1058 unsigned long long i = -1;
1059 TESTSCAN( 1, 24, octal, 147, SCANPARMS( "%llo", &i ) );
1060 CHECK_FEQUAL( i, 1llu, unsigned long long, "%llu" );
1064 size_t const BUFSIZE = 1000;
1065 char buffer[BUFSIZE];
1068 memset( buffer, '\0', BUFSIZE );
1069 TESTSCAN( 1, 3, alpha, 0, SCANPARMS( "%[abc]", buffer ) );
1070 TESTCASE( memcmp( buffer, "abc", 4 ) == 0 );
1074 memset( buffer, '\0', BUFSIZE );
1075 TESTSCAN( 1, 3, alpha, 0, SCANPARMS( "%[a-c]", buffer ) );
1076 TESTCASE( memcmp( buffer, "abc", 4 ) == 0 );
1080 memset( buffer, '\0', BUFSIZE );
1081 TESTSCAN( 1, 8, alpha, 0, SCANPARMS( "%[a-h]", buffer ) );
1082 TESTCASE( memcmp( buffer, "abcdefgh", 9 ) == 0 );
1085 // reading o-r, including [, seperate char
1086 memset( buffer, '\0', BUFSIZE );
1087 TESTSCAN( 1, 5, alpha, 15, SCANPARMS( "%[[o-qr]", buffer ) );
1088 TESTCASE( memcmp( buffer, "op[qr", 6 ) == 0 );
1091 // reading v-y, including ], two groups
1092 memset( buffer, '\0', BUFSIZE );
1093 TESTSCAN( 1, 5, alpha, 23, SCANPARMS( "%[]v-wx-y]", buffer ) );
1094 TESTCASE( memcmp( buffer, "vw]xy", 6 ) == 0 );
1097 // missing on first character
1098 memset( buffer, '\0', BUFSIZE );
1099 TESTSCAN( 0, -1, alpha, 0, SCANPARMS( "%[b]", buffer ) );
1100 TESTCASE( memcmp( buffer, "", 1 ) == 0 );
1103 // eof while reading, two groups
1104 memset( buffer, '\0', BUFSIZE );
1105 TESTSCAN( 1, 2, alpha, 27, SCANPARMS( "%[a-zA-Z]", buffer ) );
1106 TESTCASE( memcmp( buffer, "yz", 3 ) == 0 );
1109 // eof before reading
1110 memset( buffer, '\0', BUFSIZE );
1111 TESTSCAN( -1, -1, alpha, 29, SCANPARMS( "%[a-z]", buffer ) );
1112 TESTCASE( memcmp( buffer, "", 1 ) == 0 );
1115 // negation - [^...]
1116 memset( buffer, '\0', BUFSIZE );
1117 TESTSCAN( 1, 3, alpha, 0, SCANPARMS( "%[^d-f]", buffer ) );
1118 TESTCASE( memcmp( buffer, "abc", 4 ) == 0 );
1122 // special bordercase
1123 /* Most existing libraries disagree with this test case, so a little
1124 explanation of why PDCLib chose the implementation it did might be
1125 necessary. All references are from ISO/IEC 9899:1999 "Programming
1126 languages - C". Wording critical to the explanation is in UPPERCASE.
1127 Input stream holds "-0xz".
1128 6.4.4.1 Integer constants - states that '0' is a valid (hexa)decimal
1129 constant, whereas '0x' IS NOT.
1130 7.19.6.2 The fscanf function - states...
1131 ...in paragraph 9 that "an INPUT ITEM is defined as the longest
1132 sequence of input characters [...] which is, OR IS A PREFIX OF,
1133 a matching input sequence".
1134 ...in paragraph 10 that "if the INPUT ITEM is not a matching
1135 sequence, the execution of THE DIRECTIVE FAILS; this condition
1136 is a matching failure".
1137 ...in footnote 242) that "fscanf pushes back AT MOST ONE input
1138 character onto the input stream."
1139 ...in paragraph 12 that either of the conversion specifiers d, i,
1140 o, u, or x "matches an [...] integer whose format is the same as
1141 expected for THE SUBJECT SEQUENCE of the [strtol|strtoul]
1143 7.20.1.4 The strtol, strtoll, strtoul, and strtoull functions - states
1144 in paragraph 3 that "the EXPECTED FORM OF THE SUBJECT SEQUENCE is
1145 that of an integer constant AS DESCRIBED IN 6.4.4.1".
1146 These parts of the standard result in the following reasoning:
1147 - The longest sequence of input characters which is a prefix of a
1148 matching input sequence is "-0x" (negative sign, hexadecimal-prefix).
1149 The 'z' is the first character remaining unread as "-0xz" is not a
1150 (prefix of a) matching input sequence. This is according to 7.19.6.2
1152 - "0x", without a valid hexadecimal digit following it, is not a valid
1153 integer constant according to 6.4.4.1.
1154 - "0x" is thus also not of the expected form for a strto[u]l subject
1155 sequence according to 7.20.1.4 paragraph 3. (strto[u]l() would parse
1156 it as zero, but leave the "x" in the final string, i.e. outside the
1158 - "0x" is therefore also not a matching sequence to the i or x
1159 conversion specifier according to 7.19.6.2 paragraph 12.
1160 - The conversion should therefore result in a matching failure
1161 according to 7.19.6.2 paragraph 10.
1165 unsigned char i = 1;
1166 TESTSCAN( 0, -1, special, 0, SCANPARMS( "%hhx", &i ) );
1167 TESTCASE( i == 1 ); /* FIXME */
1171 unsigned short i = 1;
1172 TESTSCAN( 0, -1, special, 0, SCANPARMS( "%hx", &i ) );
1173 TESTCASE( i == 1 ); /* FIXME */
1178 TESTSCAN( 0, -1, special, 0, SCANPARMS( "%x", &i ) );
1179 TESTCASE( i == 1 ); /* FIXME */