1 /* Test of xvasprintf() and xasprintf() functions.
2 Copyright (C) 2007-2009 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
21 #include "xvasprintf.h"
30 #define ASSERT(expr) \
35 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
43 my_xasprintf (const char *format, ...)
48 va_start (args, format);
49 ret = xvasprintf (format, args);
55 test_xvasprintf (void)
60 for (repeat = 0; repeat <= 8; repeat++)
62 result = my_xasprintf ("%d", 12345);
63 ASSERT (result != NULL);
64 ASSERT (strcmp (result, "12345") == 0);
68 result = my_xasprintf ("");
69 ASSERT (result != NULL);
70 ASSERT (strcmp (result, "") == 0);
73 result = my_xasprintf ("%s", "foo");
74 ASSERT (result != NULL);
75 ASSERT (strcmp (result, "foo") == 0);
78 result = my_xasprintf ("%s%s", "foo", "bar");
79 ASSERT (result != NULL);
80 ASSERT (strcmp (result, "foobar") == 0);
83 result = my_xasprintf ("%s%sbaz", "foo", "bar");
84 ASSERT (result != NULL);
85 ASSERT (strcmp (result, "foobarbaz") == 0);
95 for (repeat = 0; repeat <= 8; repeat++)
97 result = xasprintf ("%d", 12345);
98 ASSERT (result != NULL);
99 ASSERT (strcmp (result, "12345") == 0);
103 result = xasprintf ("");
104 ASSERT (result != NULL);
105 ASSERT (strcmp (result, "") == 0);
108 result = xasprintf ("%s", "foo");
109 ASSERT (result != NULL);
110 ASSERT (strcmp (result, "foo") == 0);
113 result = xasprintf ("%s%s", "foo", "bar");
114 ASSERT (result != NULL);
115 ASSERT (strcmp (result, "foobar") == 0);
118 result = my_xasprintf ("%s%sbaz", "foo", "bar");
119 ASSERT (result != NULL);
120 ASSERT (strcmp (result, "foobarbaz") == 0);
125 main (int argc _UNUSED_PARAMETER_, char *argv[])
127 set_program_name (argv[0]);