1 #include <ccan/asprintf/asprintf.h>
2 /* Include the C files directly. */
5 /* Override vasprintf for testing. */
7 #define vasprintf my_vasprintf
8 static int my_vasprintf(char **strp, const char *fmt, va_list ap);
11 #define vsnprintf my_vsnprintf
12 static int my_vsnprintf(char *str, size_t size, const char *format, va_list ap);
15 #include <ccan/asprintf/asprintf.c>
16 #include <ccan/tap/tap.h>
25 static int my_vasprintf(char **strp, const char *fmt, va_list ap)
28 /* Set strp to crap. */
29 *strp = (char *)(long)1;
32 return vasprintf(strp, fmt, ap);
36 static int my_vsnprintf(char *str, size_t size, const char *format, va_list ap)
41 return vsnprintf(str, size, format, ap);
50 /* This is how many tests you plan to run */
54 p = afmt("Test %u%cafter-nul", 1, nul);
56 ok1(strlen(p) == strlen("Test 1"));
57 ok1(memcmp(p, "Test 1\0after-nul\0", 17) == 0);
60 ret = asprintf(&p, "Test %u%cafter-nul", 1, nul);
63 ok1(strlen(p) == strlen("Test 1"));
64 ok1(memcmp(p, "Test 1\0after-nul\0", 17) == 0);
68 p = afmt("Test %u%cafter-nul", 1, nul);
71 /* This exits depending on whether all tests passed */