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>
8 * Copyright 2014, 2018 Russ Allbery <eagle@eyrie.org>
9 * Copyright 2006-2009, 2011
10 * The Board of Trustees of the Leland Stanford Junior University
12 * Copying and distribution of this file, with or without modification, are
13 * permitted in any medium without royalty provided the copyright notice and
14 * this notice are preserved. This file is offered as-is, without any
17 * SPDX-License-Identifier: FSFAP
21 #include <portable/macros.h>
22 #include <portable/system.h>
24 #include <tests/tap/basic.h>
26 int test_asprintf(char **, const char *, ...)
27 __attribute__((__format__(printf, 2, 3)));
28 int test_vasprintf(char **, const char *, va_list)
29 __attribute__((__format__(printf, 2, 0)));
31 static int __attribute__((__format__(printf, 2, 3)))
32 vatest(char **result, const char *format, ...)
37 va_start(args, format);
38 status = test_vasprintf(result, format, args);
50 is_int(7, test_asprintf(&result, "%s", "testing"), "asprintf length");
51 is_string("testing", result, "asprintf result");
53 ok(3, "free asprintf");
54 is_int(0, test_asprintf(&result, "%s", ""), "asprintf empty length");
55 is_string("", result, "asprintf empty string");
57 ok(6, "free asprintf of empty string");
59 is_int(6, vatest(&result, "%d %s", 2, "test"), "vasprintf length");
60 is_string("2 test", result, "vasprintf result");
62 ok(9, "free vasprintf");
63 is_int(0, vatest(&result, "%s", ""), "vasprintf empty length");
64 is_string("", result, "vasprintf empty string");
66 ok(12, "free vasprintf of empty string");