]> eyrie.org Git - kerberos/krb5-strength.git/blob - tests/portable/asprintf-t.c
Change CrackLib tests for system CrackLib
[kerberos/krb5-strength.git] / tests / portable / asprintf-t.c
1 /*
2  * asprintf and vasprintf test suite.
3  *
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/>.
6  *
7  * Written by Russ Allbery <eagle@eyrie.org>
8  *
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
15  * work.
16  */
17
18 #include <config.h>
19 #include <portable/macros.h>
20 #include <portable/system.h>
21
22 #include <tests/tap/basic.h>
23
24 int test_asprintf(char **, const char *, ...)
25     __attribute__((__format__(printf, 2, 3)));
26 int test_vasprintf(char **, const char *, va_list);
27
28 static int
29 vatest(char **result, const char *format, ...)
30 {
31     va_list args;
32     int status;
33
34     va_start(args, format);
35     status = test_vasprintf(result, format, args);
36     va_end(args);
37     return status;
38 }
39
40 int
41 main(void)
42 {
43     char *result = NULL;
44
45     plan(12);
46
47     is_int(7, test_asprintf(&result, "%s", "testing"), "asprintf length");
48     is_string("testing", result, "asprintf result");
49     free(result);
50     ok(3, "free asprintf");
51     is_int(0, test_asprintf(&result, "%s", ""), "asprintf empty length");
52     is_string("", result, "asprintf empty string");
53     free(result);
54     ok(6, "free asprintf of empty string");
55
56     is_int(6, vatest(&result, "%d %s", 2, "test"), "vasprintf length");
57     is_string("2 test", result, "vasprintf result");
58     free(result);
59     ok(9, "free vasprintf");
60     is_int(0, vatest(&result, "%s", ""), "vasprintf empty length");
61     is_string("", result, "vasprintf empty string");
62     free(result);
63     ok(12, "free vasprintf of empty string");
64
65     return 0;
66 }