]> jfr.im git - solanum.git/blame - tests/rb_snprintf_append1.c
check bans and quiets for cmode -n/nonmember PRIVMSG
[solanum.git] / tests / rb_snprintf_append1.c
CommitLineData
0e6b8d0a
SA
1/*
2 * rb_snprintf_append1.c: Test rb_snprintf_append under various conditions
3 * Copyright 2017 Simon Arlott
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 * USA
19 */
20#include <stdio.h>
21#include <string.h>
22#include <stdlib.h>
23#include <unistd.h>
24#include "tap/basic.h"
25
26#include "stdinc.h"
27#include "ircd_defs.h"
28#include "client.h"
29#include "rb_lib.h"
30
31#define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
32
33struct Client me;
34
35static void from_empty1(void)
36{
37 char output[2048] = { 0 };
38 int len;
39
40 len = rb_snprintf_append(output, sizeof(output), "%s", "test");
41 is_int(4, len, MSG);
42 is_string("test", output, MSG);
43}
44
45static void basic_append1(void)
46{
47 char output[2048] = { 0 };
48 int len;
49
50 strcat(output, "test");
51
52 len = rb_snprintf_append(output, sizeof(output), "%s", "TESTING");
53 is_int(11, len, MSG);
54 is_string("testTESTING", output, MSG);
55}
56
57static void append_empty1(void)
58{
59 char output[2048] = { 0 };
60 int len;
61
62 strcat(output, "test");
63
64 len = rb_snprintf_append(output, sizeof(output), "%s", "");
65 is_int(4, len, MSG);
66 is_string("test", output, MSG);
67}
68
69static void exact_fit_empty1(void)
70{
71 char output[5] = { 0 };
72 int len;
73
74 strcat(output, "test");
75
76 len = rb_snprintf_append(output, sizeof(output), "%s", "");
77 is_int(4, len, MSG);
78 is_string("test", output, MSG);
79}
80
81static void exact_fit_basic_append1(void)
82{
83 char output[12] = { 0 };
84 int len;
85
86 strcat(output, "test");
87
88 len = rb_snprintf_append(output, sizeof(output), "%s", "TESTING");
89 is_int(11, len, MSG);
90 is_string("testTESTING", output, MSG);
91}
92
93static void too_long_basic_append1(void)
94{
95 char output[11] = { 0 };
96 int len;
97
98 strcat(output, "test");
99
100 len = rb_snprintf_append(output, sizeof(output), "%s", "TESTING");
101 is_int(11, len, MSG);
102 is_string("testTESTIN", output, MSG);
103}
104
105static void exact_fit_from_empty1(void)
106{
107 char output[5] = { 0 };
108 int len;
109
110 len = rb_snprintf_append(output, sizeof(output), "%s", "test");
111 is_int(4, len, MSG);
112 is_string("test", output, MSG);
113}
114
115static void too_long_from_empty1(void)
116{
117 char output[4] = { 0 };
118 int len;
119
120 len = rb_snprintf_append(output, sizeof(output), "%s", "test");
121 is_int(4, len, MSG);
122 is_string("tes", output, MSG);
123}
124
125static void truncate_existing1(void)
126{
127 char output[2048] = { 0 };
128 int len;
129
130 strcat(output, "testing");
131
132 len = rb_snprintf_append(output, 5, "%s", "");
133 is_int(4, len, MSG);
134 is_string("test", output, MSG);
135}
136
137static void truncate_existing2(void)
138{
139 char output[2048] = { 0 };
140 int len;
141
142 strcat(output, "testing");
143
144 len = rb_snprintf_append(output, 5, "%s", "TEST");
145 is_int(4, len, MSG);
146 is_string("test", output, MSG);
147}
148
149static void no_buffer(void)
150{
151 int len;
152
153 len = rb_snprintf_append(NULL, 0, "%s", "test");
154 is_int(-1, len, MSG);
155}
156
157int main(int argc, char *argv[])
158{
159 memset(&me, 0, sizeof(me));
160 strcpy(me.name, "me.name.");
161
162 rb_lib_init(NULL, NULL, NULL, 0, 1024, DNODE_HEAP_SIZE, FD_HEAP_SIZE);
163 rb_linebuf_init(LINEBUF_HEAP_SIZE);
164
165 plan_lazy();
166
167 from_empty1();
168 basic_append1();
169 append_empty1();
170
171 exact_fit_from_empty1();
172 too_long_from_empty1();
173
174 exact_fit_basic_append1();
175 too_long_basic_append1();
176
177 exact_fit_empty1();
178
179 truncate_existing1();
180 truncate_existing2();
181 no_buffer();
182
183 return 0;
184}