annotate tests/test-xvasprintf.c @ 8534:342c23c60847

Tests for module 'tsearch'.
author Bruno Haible <bruno@clisp.org>
date Sun, 25 Mar 2007 02:48:08 +0000
parents 4bfe04133daf
children 1f57552cdb11
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8331
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of xvasprintf() and xasprintf() functions.
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2007 Free Software Foundation, Inc.
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 any later version.
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program; if not, write to the Free Software Foundation,
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #ifdef HAVE_CONFIG_H
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 # include <config.h>
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #endif
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include "xvasprintf.h"
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <stdarg.h>
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <stdlib.h>
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include <string.h>
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #include "progname.h"
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 #define ASSERT(expr) if (!(expr)) abort ();
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 static char *
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 my_xasprintf (const char *format, ...)
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 {
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 va_list args;
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 char *ret;
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 va_start (args, format);
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 ret = xvasprintf (format, args);
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 va_end (args);
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 return ret;
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 }
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 static void
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 test_xvasprintf ()
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 {
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 int repeat;
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 for (repeat = 0; repeat <= 8; repeat++)
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 {
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 char *result = my_xasprintf ("%d", 12345);
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 ASSERT (result != NULL);
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 ASSERT (strcmp (result, "12345") == 0);
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 free (result);
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 }
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 }
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 static void
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 test_xasprintf ()
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 {
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 int repeat;
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 for (repeat = 0; repeat <= 8; repeat++)
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 {
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 char *result = xasprintf ("%d", 12345);
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 ASSERT (result != NULL);
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 ASSERT (strcmp (result, "12345") == 0);
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 free (result);
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 }
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 }
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 int
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 main (int argc, char *argv[])
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 {
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 set_program_name (argv[0]);
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 test_xvasprintf ();
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 test_xasprintf ();
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 return 0;
0a462a560fcd Tests for module 'xvasprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 }