Fixes for sprintf_test.
[bertos.git] / mware / sprintf_test.c
1 #include "sprintf.c"
2 #include "formatwr.c"
3 #include "hex.c"
4
5 #include <assert.h> /* assert() */
6 #include <string.h> /* strcmp() */
7
8
9 int main(UNUSED_ARG(int, argc), UNUSED_ARG(char **,argv))
10 {
11         char buf[256];
12         static const char test_string[] = "Hello, world!\n";
13         static const pgm_char test_string_pgm[] = "Hello, world!\n";
14
15         snprintf(buf, sizeof buf, "%s", test_string);
16         assert(strcmp(buf, test_string) == 0);
17
18         snprintf(buf, sizeof buf, "%S", test_string_pgm);
19         assert(strcmp(buf, test_string_pgm) == 0);
20
21         snprintf(buf, sizeof buf, "%d", 12345);
22         assert(strcmp(buf, "12345") == 0);
23
24         snprintf(buf, sizeof buf, "%ld", 123456789L);
25         assert(strcmp(buf, "123456789") == 0);
26
27         snprintf(buf, sizeof buf, "%lu", 4294967295UL);
28         assert(strcmp(buf, "4294967295") == 0);
29
30         /*
31          * Stress tests.
32          */
33         snprintf(buf, sizeof buf, "%s", NULL);
34         assert(strcmp(buf, "<NULL>") == 0);
35         snprintf(buf, sizeof buf, "%k");
36         assert(strcmp(buf, "???") == 0);
37         sprintf(NULL, test_string); /* must not crash */
38
39         return 0;
40 }