Formatted output functions for Unicode strings.
[gnulib.git] / tests / unistdio / test-ulc-vsnprintf1.c
1 /* Test of ulc_vsnprintf() function.
2    Copyright (C) 2007 Free Software Foundation, Inc.
3
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 2, or (at your option)
7    any later version.
8
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.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
19
20 #include <config.h>
21
22 #include "unistdio.h"
23
24 #include <stdarg.h>
25 #include <stddef.h>
26 #include <stdio.h>
27 #include <stdint.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "xalloc.h"
32
33 #define SIZEOF(array) (sizeof (array) / sizeof (array[0]))
34 #define ASSERT(expr) \
35   do                                                                         \
36     {                                                                        \
37       if (!(expr))                                                           \
38         {                                                                    \
39           fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
40           abort ();                                                          \
41         }                                                                    \
42     }                                                                        \
43   while (0)
44
45 #include "test-ulc-printf1.h"
46
47 static char *
48 my_xasprintf (const char *format, ...)
49 {
50   va_list args;
51   char result[1000];
52   int retval;
53
54   va_start (args, format);
55   retval = ulc_vsnprintf (result, sizeof (result), format, args);
56   va_end (args);
57   if (retval < 0 || retval >= (int) sizeof (result))
58     return NULL;
59   return xstrdup (result);
60 }
61
62 static void
63 test_vsnprintf ()
64 {
65   test_xfunction (my_xasprintf);
66 }
67
68 int
69 main (int argc, char *argv[])
70 {
71   test_vsnprintf ();
72   return 0;
73 }