4 #include <assert.h> /* assert() */
5 #include <string.h> /* strcmp() */
8 int main(UNUSED_ARG(int, argc), UNUSED_ARG(char **,argv))
11 static const char test_string[] = "Hello, world!\n";
12 static const pgm_char test_string_pgm[] = "Hello, world!\n";
14 snprintf(buf, sizeof buf, "%s", test_string);
15 assert(strcmp(buf, test_string) == 0);
17 snprintf(buf, sizeof buf, "%S", test_string_pgm);
18 assert(strcmp(buf, test_string_pgm) == 0);
20 snprintf(buf, sizeof buf, "%d", 12345);
21 assert(strcmp(buf, "12345") == 0);
23 snprintf(buf, sizeof buf, "%ld", 123456789L);
24 assert(strcmp(buf, "123456789") == 0);
26 snprintf(buf, sizeof buf, "%lu", 4294967295UL);
27 assert(strcmp(buf, "4294967295") == 0);
32 snprintf(buf, sizeof buf, "%s", NULL);
33 assert(strcmp(buf, "<NULL>") == 0);
34 snprintf(buf, sizeof buf, "%k");
35 assert(strcmp(buf, "???") == 0);
36 sprintf(NULL, test_string); /* must not crash */