5 #include <assert.h> /* assert() */
6 #include <string.h> /* strcmp() */
9 int main(UNUSED_ARG(int, argc), UNUSED_ARG(char **,argv))
12 static const char test_string[] = "Hello, world!\n";
13 static const pgm_char test_string_pgm[] = "Hello, world!\n";
15 snprintf(buf, sizeof buf, "%s", test_string);
16 assert(strcmp(buf, test_string) == 0);
18 snprintf(buf, sizeof buf, "%S", test_string_pgm);
19 assert(strcmp(buf, test_string_pgm) == 0);
21 snprintf(buf, sizeof buf, "%d", 12345);
22 assert(strcmp(buf, "12345") == 0);
24 snprintf(buf, sizeof buf, "%ld", 123456789L);
25 assert(strcmp(buf, "123456789") == 0);
27 snprintf(buf, sizeof buf, "%lu", 4294967295UL);
28 assert(strcmp(buf, "4294967295") == 0);
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 */