1 FILE * general = fopen( "scanf_testdata_general", "wb+" );
2 TESTCASE( general != NULL );
3 TESTCASE( fwrite( "12345678901\0003-5+7\0009\3772 4 6 8 0\3771 \011 5%% 0", 1, 40, general ) == 40 );
6 FILE * decimal = fopen( "scanf_testdata_decimal", "wb+" );
7 TESTCASE( decimal != NULL );
8 TESTCASE( fwrite( "-0 +0 -128 +127 +255 -32768 +32767 +65535\n"
9 "-2147483648 +2147483647 +4294967295\n"
10 "-9223372036854775808 +9223372036854775807\n"
11 "+18446744073709551615\n", 1, 142, decimal ) == 142 );
14 FILE * hexadecimal = fopen( "scanf_testdata_hexadecimal", "wb+" );
15 TESTCASE( hexadecimal != NULL );
16 TESTCASE( fwrite( "-0x0 -0x000 -0x7f -0x80 0xff -0x7fff -0x8000\n"
17 "0xffff -0x7fffffff -0x80000000 0xffffffff\n"
18 "-0x7fffffffffffffff -0x8000000000000000\n"
19 "0xffffffffffffffff\n", 1, 146, hexadecimal ) == 146 );
20 rewind( hexadecimal );
22 FILE * octal = fopen( "scanf_testdata_octal", "wb+" );
23 TESTCASE( octal != NULL );
24 TESTCASE( fwrite( "+0000 -0000 +0177 +0377 -0377 +077777 +0177777\n"
25 "-0177777 +017777777777 +037777777777\n"
26 "-037777777777 +0777777777777777777777\n"
27 "+01777777777777777777777\n"
28 "-01777777777777777777777\n", 1, 172, octal ) == 172 );
31 FILE * alpha = fopen( "scanf_testdata_alpha", "wb+" );
32 TESTCASE( alpha != NULL );
33 TESTCASE( fwrite( "abcdefgh-ijklmnop[qrs%uvw]xyz", 1, 29, alpha ) == 29 );
36 FILE * special = fopen( "scanf_testdata_special", "wb+" );
37 TESTCASE( special != NULL );
38 TESTCASE( fwrite( "-0xz\n", 1, 5, special ) == 5 );
43 #define TESTSCAN( result, count, source, offset, ... ) \
47 TESTCASE( fseek( source, offset, SEEK_SET ) == 0 ); \
48 int res = SCANFUNC( source, __VA_ARGS__ ); \
49 if ( res != result ) \
52 printf( "FAILED: " __FILE__ ", line %d - expected result %d, got %d\n", __LINE__, result, res ); \
57 printf( "FAILED: " __FILE__ ", line %d - expected count %d, got %d\n", __LINE__, count, n ); \
61 #define SCAN( format ) format "%n", &n
62 #define SCANPARMS( format, ... ) format "%n", __VA_ARGS__, &n