This source file includes following definitions.
- my_appendf
- 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 "string-buffer.h"
22
23 #include <string.h>
24
25 #include "macros.h"
26
27 static int
28 my_appendf (struct string_buffer *buffer, const char *formatstring, ...)
29 {
30 va_list args;
31
32 va_start (args, formatstring);
33 int ret = sb_appendvf (buffer, formatstring, args);
34 va_end (args);
35
36 return ret;
37 }
38
39 char invalid_format_string_1[] = "%&";
40 char invalid_format_string_2[] = "%^";
41
42 int
43 main ()
44 {
45
46 {
47 struct string_buffer buffer;
48
49 sb_init (&buffer);
50 char *s = sb_dupfree (&buffer);
51 ASSERT (s != NULL && strcmp (s, "") == 0);
52 free (s);
53 }
54
55 {
56 struct string_buffer buffer;
57
58 sb_init (&buffer);
59 sb_append (&buffer, "abc");
60 sb_append (&buffer, "");
61 sb_append (&buffer, "defg");
62 char *s = sb_dupfree (&buffer);
63 ASSERT (s != NULL && strcmp (s, "abcdefg") == 0);
64 free (s);
65 }
66
67
68 {
69 struct string_buffer buffer;
70
71 sb_init (&buffer);
72 sb_append (&buffer, "<");
73 sb_appendf (&buffer, "%x", 3735928559U);
74 sb_append (&buffer, ">");
75 char *s = sb_dupfree (&buffer);
76 ASSERT (s != NULL && strcmp (s, "<deadbeef>") == 0);
77 free (s);
78 }
79
80
81 {
82 struct string_buffer buffer;
83
84 sb_init (&buffer);
85 sb_append (&buffer, "<");
86 my_appendf (&buffer, "%x", 3735928559U);
87 sb_append (&buffer, ">");
88 char *s = sb_dupfree (&buffer);
89 ASSERT (s != NULL && strcmp (s, "<deadbeef>") == 0);
90 free (s);
91 }
92
93
94
95
96
97
98
99 {
100 struct string_buffer buffer;
101
102 sb_init (&buffer);
103 sb_append (&buffer, "<");
104 sb_appendf (&buffer, "%lc", 0x76543210);
105 sb_append (&buffer, "|");
106 sb_appendf (&buffer, invalid_format_string_1, 1);
107 sb_append (&buffer, "|");
108 sb_appendf (&buffer, invalid_format_string_2, 2);
109 sb_append (&buffer, ">");
110 char *s = sb_dupfree (&buffer);
111 ASSERT (s == NULL);
112 }
113
114 return 0;
115 }