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 (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ...))
34 {
35
36
37 {
38 const char *locale_string = "\303\204rger";
39 {
40 size_t length;
41 uint8_t *result =
42 my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55);
43 static const uint8_t expected[] = "\303\204rger 33";
44 ASSERT (result != NULL);
45 ASSERT (u8_strcmp (result, expected) == 0);
46 ASSERT (length == u8_strlen (result));
47 free (result);
48 }
49 {
50 size_t length;
51 uint8_t *result =
52 my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55);
53 static const uint8_t expected[] = " \303\204rger 33";
54 ASSERT (result != NULL);
55 ASSERT (u8_strcmp (result, expected) == 0);
56 ASSERT (length == u8_strlen (result));
57 free (result);
58 }
59 {
60 size_t length;
61 uint8_t *result =
62 my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55);
63 static const uint8_t expected[] = "\303\204rger 33";
64 ASSERT (result != NULL);
65 ASSERT (u8_strcmp (result, expected) == 0);
66 ASSERT (length == u8_strlen (result));
67 free (result);
68 }
69 {
70 size_t length;
71 uint8_t *result =
72 my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55);
73 static const uint8_t expected[] = " \303\204rger 33";
74 ASSERT (result != NULL);
75 ASSERT (u8_strcmp (result, expected) == 0);
76 ASSERT (length == u8_strlen (result));
77 free (result);
78 }
79 }
80 }
81
82 static uint8_t *
83 my_asnprintf (uint8_t *resultbuf, size_t *lengthp, const char *format, ...)
84 {
85 va_list args;
86 uint8_t *ret;
87
88 va_start (args, format);
89 ret = u8_vasnprintf (resultbuf, lengthp, format, args);
90 va_end (args);
91 return ret;
92 }
93
94 static void
95 test_vasnprintf ()
96 {
97 test_function (my_asnprintf);
98 }
99
100 int
101 main (int argc, char *argv[])
102 {
103
104 if (setlocale (LC_ALL, "") == NULL)
105 return 1;
106
107 test_vasnprintf ();
108 return 0;
109 }