This source file includes following definitions.
- test_function
- my_asnprintf
- test_vasnprintf
- test_asnprintf
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include "vasnprintf.h"
22
23 #include <locale.h>
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include "macros.h"
28
29
30
31
32 #if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__
33
34 static void
35 test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
36 {
37
38 {
39 size_t length;
40 char *result =
41 my_asnprintf (NULL, &length, "%Id %d", 1234567, 99);
42 static const char expected[] =
43 "\xDB\xB1\xDB\xB2\xDB\xB3\xDB\xB4\xDB\xB5\xDB\xB6\xDB\xB7 99";
44 ASSERT (result != NULL);
45 ASSERT (strcmp (result, expected) == 0);
46 ASSERT (length == strlen (result));
47 free (result);
48 }
49 }
50
51 static char *
52 my_asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
53 {
54 va_list args;
55 char *ret;
56
57 va_start (args, format);
58 ret = vasnprintf (resultbuf, lengthp, format, args);
59 va_end (args);
60 return ret;
61 }
62
63 static void
64 test_vasnprintf ()
65 {
66 test_function (my_asnprintf);
67 }
68
69 static void
70 test_asnprintf ()
71 {
72 test_function (asnprintf);
73 }
74
75 #endif
76
77 int
78 main (int argc, char *argv[])
79 {
80 #if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__
81
82 if (setlocale (LC_ALL, "fa_IR.UTF-8") == NULL)
83 {
84 fprintf (stderr, "Skipping test: no Iranian locale is installed\n");
85 return 77;
86 }
87
88 test_vasnprintf ();
89 test_asnprintf ();
90
91 return 0;
92 #else
93 fprintf (stderr, "Skipping test: not a glibc >= 2.3 system\n");
94 return 77;
95 #endif
96 }