Usermode/utests - Fix DNS utest, update libc utests to new format (no more EXP files)
[tpg/acess2.git] / Usermode / Libraries / libc.so_src / TEST_printf.c
1 /*
2  * Acess2 C Library (Test)
3  * - By John Hodge (thePowersGang)
4  *
5  * TEST_printf.c
6  * - Tests for printf.c
7  */
8 #include <stdio.h>
9 #include <string.h>
10 #include <utest_common.h>
11
12 #define TST(_name, exp, fmt, val...) do { \
13         char buf[64]; \
14         snprintf(buf, sizeof(buf), fmt, ##val); \
15         if( strcmp(buf, exp) != 0 ) { \
16                 fprintf(stderr, "FAIL: exp '%s' != got '%s'\n", exp, buf);\
17                 exit(1); \
18         } \
19 } while(0)
20
21 int main(int argc, char *argv[])
22 {
23         TST("None", "Hello World!\n", "Hello World!\n");
24         TST("String", "teststring", "%s", "teststring");
25         TST("String", "tests",      "%.5s", "teststring");
26         TST("String", "     tests", "%10.5s", "teststring");
27         TST("String", "tests     ", "%-10.5s", "teststring");
28         
29         TST("Integer", "1234", "%i", 1234);
30         TST("Integer", "1234", "%d", 1234);
31         TST("Integer", "1234", "%u", 1234);
32         
33         TST("Float", "3.141593", "%f", 3.1415926535);
34         TST("Float", "10.000000",    "%f", 10.0);
35         TST("Float", "-0.000000", "%f", -0.0);
36         TST("Float", "3.1415926535", "%.10f", 3.1415926535);
37         TST("Float", "3.141593e+00", "%e", 3.1415926535);
38         TST("Float", "3.14159", "%g", 3.1415926535);
39         TST("Float", "1.000000E+09", "%E", 1000000000.00);
40         TST("Float", "0x1p+4", "%a", 16.0);
41         TST("Float", "0x1p+10", "%a", 1024.0);
42         TST("Float", "0x1.ff8p+9", "%a", 1023.0);
43         TST("Float", "0X1.DCD65P+29", "%A", 1000000000.00);
44         return 0;
45 }

UCC git Repository :: git.ucc.asn.au