1 /* Test of xvasprintf() and xasprintf() functions.
2 Copyright (C) 2007-2015 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. */
19 /* Tell GCC not to warn about the specific edge cases tested here. */
20 #if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
21 # pragma GCC diagnostic ignored "-Wformat-zero-length"
22 # pragma GCC diagnostic ignored "-Wformat-nonliteral"
23 # pragma GCC diagnostic ignored "-Wformat-security"
28 #include "xvasprintf.h"
38 my_xasprintf (const char *format, ...)
43 va_start (args, format);
44 ret = xvasprintf (format, args);
50 test_xvasprintf (void)
55 for (repeat = 0; repeat <= 8; repeat++)
57 result = my_xasprintf ("%d", 12345);
58 ASSERT (result != NULL);
59 ASSERT (strcmp (result, "12345") == 0);
64 /* Silence gcc warning about zero-length format string. */
65 const char *empty = "";
66 result = my_xasprintf (empty);
67 ASSERT (result != NULL);
68 ASSERT (strcmp (result, "") == 0);
72 result = my_xasprintf ("%s", "foo");
73 ASSERT (result != NULL);
74 ASSERT (strcmp (result, "foo") == 0);
77 result = my_xasprintf ("%s%s", "foo", "bar");
78 ASSERT (result != NULL);
79 ASSERT (strcmp (result, "foobar") == 0);
82 result = my_xasprintf ("%s%sbaz", "foo", "bar");
83 ASSERT (result != NULL);
84 ASSERT (strcmp (result, "foobarbaz") == 0);
94 for (repeat = 0; repeat <= 8; repeat++)
96 result = xasprintf ("%d", 12345);
97 ASSERT (result != NULL);
98 ASSERT (strcmp (result, "12345") == 0);
103 /* Silence gcc warning about zero-length format string,
104 and about "format not a string literal and no format"
105 (whatever that means) . */
106 const char *empty = "";
107 result = xasprintf (empty, empty);
108 ASSERT (result != NULL);
109 ASSERT (strcmp (result, "") == 0);
113 result = xasprintf ("%s", "foo");
114 ASSERT (result != NULL);
115 ASSERT (strcmp (result, "foo") == 0);
118 result = xasprintf ("%s%s", "foo", "bar");
119 ASSERT (result != NULL);
120 ASSERT (strcmp (result, "foobar") == 0);
123 result = my_xasprintf ("%s%sbaz", "foo", "bar");
124 ASSERT (result != NULL);
125 ASSERT (strcmp (result, "foobarbaz") == 0);
130 main (int argc _GL_UNUSED, char *argv[])
132 set_program_name (argv[0]);