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 <http://www.eyrie.org/~eagle/software/rra-c-util/>.
7
* Written by Russ Allbery <rra@stanford.edu>
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/system.h>
21
#include <tests/tap/basic.h>
23
int test_asprintf(char **, const char *, ...)
24
__attribute__((__format__(printf, 2, 3)));
25
int test_vasprintf(char **, const char *, va_list);
28
vatest(char **result, const char *format, ...)
33
va_start(args, format);
34
status = test_vasprintf(result, format, args);
46
is_int(7, test_asprintf(&result, "%s", "testing"), "asprintf length");
47
is_string("testing", result, "asprintf result");
49
ok(3, "free asprintf");
50
is_int(0, test_asprintf(&result, "%s", ""), "asprintf empty length");
51
is_string("", result, "asprintf empty string");
53
ok(6, "free asprintf of empty string");
55
is_int(6, vatest(&result, "%d %s", 2, "test"), "vasprintf length");
56
is_string("2 test", result, "vasprintf result");
58
ok(9, "free vasprintf");
59
is_int(0, vatest(&result, "%s", ""), "vasprintf empty length");
60
is_string("", result, "vasprintf empty string");
62
ok(12, "free vasprintf of empty string");