source: web/old/remctl-2.14/tests/portable/asprintf-t.c @ f6f3e91

web
Last change on this file since f6f3e91 was f6f3e91, checked in by Jessica B. Hamrick <jhamrick@…>, 15 years ago

Preserve directory hierarchy (not sure what happened to it)

  • Property mode set to 100644
File size: 1.4 KB
Line 
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
16int test_asprintf(char **, const char *, ...);
17int test_vasprintf(char **, const char *, va_list);
18
19static int
20vatest(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
31int
32main(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}
Note: See TracBrowser for help on using the repository browser.