1 | /* |
---|
2 | * asprintf and vasprintf test suite. |
---|
3 | * |
---|
4 | * Written by Russ Allbery <rra@stanford.edu> |
---|
5 | * Copyright 2006, 2008, 2009 |
---|
6 | * Board of Trustees, Leland Stanford Jr. University |
---|
7 | * |
---|
8 | * See LICENSE for licensing terms. |
---|
9 | */ |
---|
10 | |
---|
11 | #include <config.h> |
---|
12 | #include <portable/system.h> |
---|
13 | |
---|
14 | #include <tests/tap/basic.h> |
---|
15 | |
---|
16 | int test_asprintf(char **, const char *, ...); |
---|
17 | int test_vasprintf(char **, const char *, va_list); |
---|
18 | |
---|
19 | static int |
---|
20 | vatest(char **result, const char *format, ...) |
---|
21 | { |
---|
22 | va_list args; |
---|
23 | int status; |
---|
24 | |
---|
25 | va_start(args, format); |
---|
26 | status = test_vasprintf(result, format, args); |
---|
27 | va_end(args); |
---|
28 | return status; |
---|
29 | } |
---|
30 | |
---|
31 | int |
---|
32 | main(void) |
---|
33 | { |
---|
34 | char *result = NULL; |
---|
35 | |
---|
36 | plan(12); |
---|
37 | |
---|
38 | is_int(7, test_asprintf(&result, "%s", "testing"), "asprintf length"); |
---|
39 | is_string("testing", result, "asprintf result"); |
---|
40 | free(result); |
---|
41 | ok(3, "free asprintf"); |
---|
42 | is_int(0, test_asprintf(&result, "%s", ""), "asprintf empty length"); |
---|
43 | is_string("", result, "asprintf empty string"); |
---|
44 | free(result); |
---|
45 | ok(6, "free asprintf of empty string"); |
---|
46 | |
---|
47 | is_int(6, vatest(&result, "%d %s", 2, "test"), "vasprintf length"); |
---|
48 | is_string("2 test", result, "vasprintf result"); |
---|
49 | free(result); |
---|
50 | ok(9, "free vasprintf"); |
---|
51 | is_int(0, vatest(&result, "%s", ""), "vasprintf empty length"); |
---|
52 | is_string("", result, "vasprintf empty string"); |
---|
53 | free(result); |
---|
54 | ok(12, "free vasprintf of empty string"); |
---|
55 | |
---|
56 | return 0; |
---|
57 | } |
---|