Skip to content

Commit de6400f

Browse files
committed
chore(test.c): add check_no_operation_after_done() and match 4024e
1 parent bef48e8 commit de6400f

File tree

1 file changed

+43
-25
lines changed

1 file changed

+43
-25
lines changed

test/test.c

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,55 @@
33
#include <assert.h>
44
#include <stddef.h>
55

6+
#define JSONB_MAX_DEPTH 4
7+
#define JSONB_DEBUG
68
#include "json-build.h"
79

810
#include "greatest.h"
911

1012
TEST
1113
check_valid_singles(void)
1214
{
13-
char buf[2048] = { 0 };
15+
char buf[2048];
1416
jsonb b;
1517

1618
jsonb_init(&b);
1719
ASSERT(jsonb_push_array(&b, buf, sizeof(buf)) >= 0);
1820
ASSERT(jsonb_pop_array(&b, buf, sizeof(buf)) >= 0);
1921
ASSERT_STR_EQ("[]", buf);
20-
memset(buf, 0, sizeof(buf));
2122

2223
jsonb_init(&b);
2324
ASSERT(jsonb_push_object(&b, buf, sizeof(buf)) >= 0);
2425
ASSERT(jsonb_pop_object(&b, buf, sizeof(buf)) >= 0);
2526
ASSERT_STR_EQ("{}", buf);
26-
memset(buf, 0, sizeof(buf));
2727

2828
jsonb_init(&b);
2929
ASSERT(jsonb_push_bool(&b, buf, sizeof(buf), 0) >= 0);
3030
ASSERT_STR_EQ("false", buf);
31-
memset(buf, 0, sizeof(buf));
3231

3332
jsonb_init(&b);
3433
ASSERT(jsonb_push_bool(&b, buf, sizeof(buf), 1) >= 0);
3534
ASSERT_STR_EQ("true", buf);
36-
memset(buf, 0, sizeof(buf));
3735

3836
jsonb_init(&b);
3937
ASSERT(jsonb_push_number(&b, buf, sizeof(buf), 10) >= 0);
4038
ASSERT_STR_EQ("10", buf);
41-
memset(buf, 0, sizeof(buf));
4239

4340
jsonb_init(&b);
4441
ASSERT(jsonb_push_string(&b, buf, sizeof(buf), "hi", 2) >= 0);
4542
ASSERT_STR_EQ("\"hi\"", buf);
46-
memset(buf, 0, sizeof(buf));
4743

4844
jsonb_init(&b);
4945
ASSERT(jsonb_push_null(&b, buf, sizeof(buf)) >= 0);
5046
ASSERT_STR_EQ("null", buf);
51-
memset(buf, 0, sizeof(buf));
5247

5348
PASS();
5449
}
5550

5651
TEST
5752
check_valid_array(void)
5853
{
59-
char buf[2048] = { 0 };
54+
char buf[2048];
6055
jsonb b;
6156

6257
jsonb_init(&b);
@@ -80,7 +75,7 @@ check_valid_array(void)
8075
TEST
8176
check_valid_object(void)
8277
{
83-
char buf[2048] = { 0 };
78+
char buf[2048];
8479
jsonb b;
8580

8681
jsonb_init(&b);
@@ -119,7 +114,7 @@ SUITE(valid_output)
119114
TEST
120115
check_deep_nesting_array(void)
121116
{
122-
char buf[2048] = { 0 };
117+
char buf[2048];
123118
jsonb b;
124119
int i;
125120

@@ -134,7 +129,7 @@ check_deep_nesting_array(void)
134129
TEST
135130
check_deep_nesting_object(void)
136131
{
137-
char buf[4096] = { 0 };
132+
char buf[4096];
138133
jsonb b;
139134
int i;
140135

@@ -153,7 +148,7 @@ check_deep_nesting_object(void)
153148
TEST
154149
check_deep_nesting_object_and_array(void)
155150
{
156-
char buf[8192] = { 0 };
151+
char buf[8192];
157152
jsonb b;
158153
int i;
159154

@@ -194,7 +189,7 @@ check_string_escaping(void)
194189
",\"\\n\\t\\t\"", ",\"\\b\\u0007\\u0007\\ttest\\n\"",
195190
",\"end\"",
196191
};
197-
char buf[1028] = { 0 };
192+
char buf[1028];
198193
size_t i;
199194
jsonb b;
200195

@@ -219,52 +214,51 @@ SUITE(string)
219214
TEST
220215
check_invalid_top_level_tokens_in_sequence(void)
221216
{
222-
char buf[1028] = { 0 };
217+
char buf[1028];
223218
jsonb b;
224219

225220
jsonb_init(&b);
226221
jsonb_push_bool(&b, buf, sizeof(buf), 1);
227-
ASSERT(jsonb_push_bool(&b, buf, sizeof(buf), 0) == JSONB_ERROR_INPUT);
222+
ASSERT(JSONB_ERROR_INPUT == jsonb_push_bool(&b, buf, sizeof(buf), 0));
228223

229224
jsonb_init(&b);
230225
jsonb_push_array(&b, buf, sizeof(buf));
231226
jsonb_pop_array(&b, buf, sizeof(buf));
232-
ASSERT(jsonb_push_array(&b, buf, sizeof(buf)) == JSONB_ERROR_INPUT);
227+
ASSERT(JSONB_ERROR_INPUT == jsonb_push_array(&b, buf, sizeof(buf)));
233228

234229
jsonb_init(&b);
235230
jsonb_push_array(&b, buf, sizeof(buf));
236231
jsonb_pop_array(&b, buf, sizeof(buf));
237-
ASSERT(jsonb_push_bool(&b, buf, sizeof(buf), 1) == JSONB_ERROR_INPUT);
232+
ASSERT(JSONB_ERROR_INPUT == jsonb_push_bool(&b, buf, sizeof(buf), 1));
238233

239234
jsonb_init(&b);
240235
jsonb_push_bool(&b, buf, sizeof(buf), 1);
241-
ASSERT(jsonb_push_array(&b, buf, sizeof(buf)) == JSONB_ERROR_INPUT);
236+
ASSERT(JSONB_ERROR_INPUT == jsonb_push_array(&b, buf, sizeof(buf)));
242237

243238
jsonb_init(&b);
244239
jsonb_push_bool(&b, buf, sizeof(buf), 1);
245-
ASSERT(jsonb_push_string(&b, buf, sizeof(buf), "", 0)
246-
== JSONB_ERROR_INPUT);
240+
ASSERT(JSONB_ERROR_INPUT == jsonb_push_string(&b, buf, sizeof(buf), "", 0));
247241

248242
PASS();
249243
}
250244

251245
TEST
252246
check_not_enough_buffer_memory(void)
253247
{
254-
char buf[128] = { 0 };
248+
char buf[128];
255249
jsonb b;
256250

257251
jsonb_init(&b);
258-
ASSERT(jsonb_push_bool(&b, buf, 0, 1) == JSONB_ERROR_NOMEM);
259-
ASSERT(jsonb_push_bool(&b, buf, sizeof(buf), 1) == JSONB_END);
252+
ASSERT(JSONB_ERROR_NOMEM == jsonb_push_bool(&b, buf, 0, 1));
253+
ASSERT(JSONB_END == jsonb_push_bool(&b, buf, sizeof(buf), 1));
260254

261255
PASS();
262256
}
263257

264258
TEST
265259
check_out_of_bounds_access(void)
266260
{
267-
char buf[1024] = { 0 };
261+
char buf[1024];
268262
jsonb b;
269263

270264
jsonb_init(&b);
@@ -276,11 +270,35 @@ check_out_of_bounds_access(void)
276270
PASS();
277271
}
278272

273+
TEST
274+
check_no_operation_after_done(void)
275+
{
276+
char buf[1024];
277+
jsonb b;
278+
279+
jsonb_init(&b);
280+
ASSERT(JSONB_OK == jsonb_push_array(&b, buf, sizeof(buf)));
281+
ASSERT(JSONB_END == jsonb_pop_array(&b, buf, sizeof(buf)));
282+
ASSERT(JSONB_ERROR_INPUT == jsonb_push_array(&b, buf, sizeof(buf)));
283+
284+
jsonb_init(&b);
285+
ASSERT(JSONB_OK == jsonb_push_object(&b, buf, sizeof(buf)));
286+
ASSERT(JSONB_END == jsonb_pop_object(&b, buf, sizeof(buf)));
287+
ASSERT(JSONB_ERROR_INPUT == jsonb_push_object(&b, buf, sizeof(buf)));
288+
289+
jsonb_init(&b);
290+
ASSERT(JSONB_END == jsonb_push_null(&b, buf, sizeof(buf)));
291+
ASSERT(JSONB_ERROR_INPUT == jsonb_push_null(&b, buf, sizeof(buf)));
292+
293+
PASS();
294+
}
295+
279296
SUITE(force_error)
280297
{
281298
RUN_TEST(check_invalid_top_level_tokens_in_sequence);
282299
RUN_TEST(check_not_enough_buffer_memory);
283300
RUN_TEST(check_out_of_bounds_access);
301+
RUN_TEST(check_no_operation_after_done);
284302
}
285303

286304
GREATEST_MAIN_DEFS();

0 commit comments

Comments
 (0)