This source file includes following definitions.
- test_function
- my_asnprintf
- test_vasnprintf
- 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 "unistdio.h"
22
23 #include <locale.h>
24 #include <stdarg.h>
25 #include <stdint.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include "unistr.h"
30 #include "macros.h"
31
32 static void
33 test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, ...))
34 {
35
36
37 {
38 const char *locale_string = "\303\204rger";
39 {
40 size_t length;
41 uint32_t *result =
42 my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55);
43 static const uint32_t expected[] =
44 { 0x00c4, 'r', 'g', 'e', 'r', ' ', '3', '3', 0 };
45 ASSERT (result != NULL);
46 ASSERT (u32_strcmp (result, expected) == 0);
47 ASSERT (length == u32_strlen (result));
48 free (result);
49 }
50 {
51 size_t length;
52 uint32_t *result =
53 my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55);
54 static const uint32_t expected[] =
55 { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r',
56 ' ', '3', '3', 0
57 };
58 ASSERT (result != NULL);
59 ASSERT (u32_strcmp (result, expected) == 0);
60 ASSERT (length == u32_strlen (result));
61 free (result);
62 }
63 {
64 size_t length;
65 uint32_t *result =
66 my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55);
67 static const uint32_t expected[] =
68 { 0x00c4, 'r', 'g', 'e', 'r', ' ', ' ', ' ', ' ', ' ',
69 ' ', '3', '3', 0
70 };
71 ASSERT (result != NULL);
72 ASSERT (u32_strcmp (result, expected) == 0);
73 ASSERT (length == u32_strlen (result));
74 free (result);
75 }
76 {
77 size_t length;
78 uint32_t *result =
79 my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55);
80 static const uint32_t expected[] =
81 { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r',
82 ' ', '3', '3', 0
83 };
84 ASSERT (result != NULL);
85 ASSERT (u32_strcmp (result, expected) == 0);
86 ASSERT (length == u32_strlen (result));
87 free (result);
88 }
89 }
90 }
91
92 static uint32_t *
93 my_asnprintf (uint32_t *resultbuf, size_t *lengthp, const char *format, ...)
94 {
95 va_list args;
96 uint32_t *ret;
97
98 va_start (args, format);
99 ret = u32_vasnprintf (resultbuf, lengthp, format, args);
100 va_end (args);
101 return ret;
102 }
103
104 static void
105 test_vasnprintf ()
106 {
107 test_function (my_asnprintf);
108 }
109
110 int
111 main (int argc, char *argv[])
112 {
113
114 if (setlocale (LC_ALL, "") == NULL)
115 return 1;
116
117 test_vasnprintf ();
118 return 0;
119 }