2 * asprintf and vasprintf test suite.
4 * The canonical version of this file is maintained in the rra-c-util package,
5 * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
7 * Written by Russ Allbery <eagle@eyrie.org>
9 * The authors hereby relinquish any claim to any copyright that they may have
10 * in this work, whether granted under contract or by operation of law or
11 * international treaty, and hereby commit to the public, at large, that they
12 * shall not, at any time in the future, seek to enforce any copyright in this
13 * work against any person or entity, or prevent any person or entity from
14 * copying, publishing, distributing or creating derivative works of this
19 #include <portable/macros.h>
20 #include <portable/system.h>
22 #include <tests/tap/basic.h>
24 int test_asprintf(char **, const char *, ...)
25 __attribute__((__format__(printf, 2, 3)));
26 int test_vasprintf(char **, const char *, va_list);
29 vatest(char **result, const char *format, ...)
34 va_start(args, format);
35 status = test_vasprintf(result, format, args);
47 is_int(7, test_asprintf(&result, "%s", "testing"), "asprintf length");
48 is_string("testing", result, "asprintf result");
50 ok(3, "free asprintf");
51 is_int(0, test_asprintf(&result, "%s", ""), "asprintf empty length");
52 is_string("", result, "asprintf empty string");
54 ok(6, "free asprintf of empty string");
56 is_int(6, vatest(&result, "%d %s", 2, "test"), "vasprintf length");
57 is_string("2 test", result, "vasprintf result");
59 ok(9, "free vasprintf");
60 is_int(0, vatest(&result, "%s", ""), "vasprintf empty length");
61 is_string("", result, "vasprintf empty string");
63 ok(12, "free vasprintf of empty string");