more decompress
[wireshark-sm.git] / epan / wscbor_test.c
blob066a0e94ee72813b3834353e58e858f9d6a48a8a
1 /* wscbor_test.c
2 * Wireshark CBOR API tests
3 * Copyright 2021, Brian Sipos <brian.sipos@gmail.com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
13 #undef G_DISABLE_ASSERT
15 #include <stdio.h>
16 #include <string.h>
17 #include <glib.h>
19 #include "wscbor.h"
20 #include <epan/wmem_scopes.h>
21 #include <epan/exceptions.h>
22 #include <wsutil/array.h>
23 #include <wsutil/wmem/wmem_list.h>
24 #include <wsutil/wmem/wmem_map.h>
26 #include <ws_diag_control.h>
28 static wmem_allocator_t *test_scope;
30 typedef struct
32 // Raw bytes
33 int enc_len;
34 const uint8_t *enc;
35 // Members of cbor_chunk_t
36 int head_length;
37 int data_length;
38 uint8_t type_major;
39 uint64_t head_value;
40 } example_s;
42 DIAG_OFF_PEDANTIC
43 example_s ex_uint = {1, (const uint8_t *)"\x01", 1, 1, CBOR_TYPE_UINT, 1};
44 example_s ex_nint = {1, (const uint8_t *)"\x20", 1, 1, CBOR_TYPE_NEGINT, 0};
45 example_s ex_bstr = {3, (const uint8_t *)"\x42\x68\x69", 1, 3, CBOR_TYPE_BYTESTRING, 2};
46 example_s ex_bstr_indef = {6, (const uint8_t *)"\x5F\x41\x68\x41\x69\xFF", 1, 6, CBOR_TYPE_BYTESTRING, 0};
47 example_s ex_bstr_indef_empty = {2, (const uint8_t *)"\x5F\xFF", 1, 2, CBOR_TYPE_BYTESTRING, 0};
48 example_s ex_tstr = {3, (const uint8_t *)"\x62\x68\x69", 1, 3, CBOR_TYPE_STRING, 2};
49 example_s ex_tstr_indef = {6, (const uint8_t *)"\x7F\x61\x68\x61\x69\xFF", 1, 6, CBOR_TYPE_STRING, 0};
50 example_s ex_false = {1, (const uint8_t *)"\xF4", 1, 1, CBOR_TYPE_FLOAT_CTRL, CBOR_CTRL_FALSE};
51 example_s ex_true = {1, (const uint8_t *)"\xF5", 1, 1, CBOR_TYPE_FLOAT_CTRL, CBOR_CTRL_TRUE};
52 example_s ex_null = {1, (const uint8_t *)"\xF6", 1, 1, CBOR_TYPE_FLOAT_CTRL, CBOR_CTRL_NULL};
53 example_s ex_undef = {1, (const uint8_t *)"\xF7", 1, 1, CBOR_TYPE_FLOAT_CTRL, CBOR_CTRL_UNDEF};
54 example_s ex_break = {1, (const uint8_t *)"\xFF", 1, 1, CBOR_TYPE_FLOAT_CTRL, 0};
56 example_s ex_uint_overflow = {9, (const uint8_t *)"\x1B\x80\x00\x00\x00\x00\x00\x00\x00", 1, 9, CBOR_TYPE_UINT, 0x8000000000000000};
57 example_s ex_nint_overflow = {9, (const uint8_t *)"\x3B\x80\x00\x00\x00\x00\x00\x00\x00", 1, 9, CBOR_TYPE_NEGINT, 0x8000000000000000};
58 example_s ex_bstr_overflow = {11, (const uint8_t *)"\x5B\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00", 1, 9, CBOR_TYPE_BYTESTRING, 0x8000000000000000};
59 example_s ex_bstr_short = {2, (const uint8_t *)"\x42\x68", 1, 3, CBOR_TYPE_BYTESTRING, 2};
60 example_s ex_tstr_short = {2, (const uint8_t *)"\x62\x68", 1, 3, CBOR_TYPE_STRING, 2};
61 DIAG_ON_PEDANTIC
63 static const example_s * all_examples[] = {
64 &ex_uint, &ex_nint,
65 &ex_bstr, &ex_bstr_indef,
66 &ex_tstr, &ex_tstr_indef,
67 &ex_false, &ex_true, &ex_null, &ex_undef, &ex_break, &ex_bstr_indef_empty
71 * These test are organized in order of the appearance, in wscbor.h, of
72 * the basic functions that they test. This makes it easier to
73 * get a quick understanding of both the testing and the organization
74 * of the header.
77 /* WSCBOR TESTING FUNCTIONS (/wscbor/) */
79 static void
80 wscbor_test_chunk_read_simple(void)
82 for (size_t ex_ix = 0; ex_ix < array_length(all_examples); ++ex_ix) {
83 const example_s *ex = all_examples[ex_ix];
84 printf("simple #%zu\n", ex_ix);
86 tvbuff_t *tvb = tvb_new_real_data(ex->enc, ex->enc_len, ex->enc_len);
87 int offset = 0;
89 wscbor_chunk_t *chunk = wscbor_chunk_read(test_scope, tvb, &offset);
90 g_assert_nonnull(chunk);
91 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
93 g_assert_cmpuint(chunk->head_length, ==, ex->head_length);
94 g_assert_cmpuint(chunk->data_length, ==, ex->data_length);
95 g_assert_cmpuint(wmem_list_count(chunk->tags), ==, 0);
96 g_assert_cmpuint(chunk->type_major, ==, ex->type_major);
97 g_assert_cmpuint(chunk->head_value, ==, ex->head_value);
99 wscbor_chunk_free(chunk);
100 tvb_free(tvb);
104 static void
105 wscbor_test_chunk_read_simple_tags(void)
107 const uint8_t *const tags = (const uint8_t *)"\xC1\xD8\xC8";
108 tvbuff_t *tvb_tags = tvb_new_real_data(tags, 3, 3);
110 for (size_t ex_ix = 0; ex_ix < array_length(all_examples); ++ex_ix) {
111 const example_s *ex = all_examples[ex_ix];
112 printf("simple #%zu\n", ex_ix);
114 tvbuff_t *tvb_item = tvb_new_real_data(ex->enc, ex->enc_len, ex->enc_len);
115 tvbuff_t *tvb = tvb_new_composite();
116 tvb_composite_append(tvb, tvb_tags);
117 tvb_composite_append(tvb, tvb_item);
118 tvb_composite_finalize(tvb);
119 int offset = 0;
121 wscbor_chunk_t *chunk = wscbor_chunk_read(test_scope, tvb, &offset);
122 g_assert_nonnull(chunk);
123 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
125 g_assert_cmpuint(chunk->head_length, ==, ex->head_length + 3);
126 g_assert_cmpuint(chunk->data_length, ==, ex->data_length + 3);
127 g_assert_cmpuint(wmem_list_count(chunk->tags), ==, 2);
129 wmem_list_frame_t *frm = wmem_list_head(chunk->tags);
130 g_assert_nonnull(frm);
132 const wscbor_tag_t *tag = wmem_list_frame_data(frm);
133 g_assert_cmpuint(tag->value, ==, 1);
135 frm = wmem_list_frame_next(frm);
136 g_assert_nonnull(frm);
138 const wscbor_tag_t *tag = wmem_list_frame_data(frm);
139 g_assert_cmpuint(tag->value, ==, 200);
141 frm = wmem_list_frame_next(frm);
142 g_assert_null(frm);
144 g_assert_cmpuint(chunk->type_major, ==, ex->type_major);
145 g_assert_cmpuint(chunk->head_value, ==, ex->head_value);
147 wscbor_chunk_free(chunk);
148 tvb_free(tvb_item);
151 tvb_free(tvb_tags);
154 static void
155 wscbor_test_chunk_read_invalid(void)
157 tvbuff_t *tvb = tvb_new_real_data((const uint8_t *)"\x00\x01\x02\xC1", 4, 2);
158 int offset = 2;
160 { // last valid item
161 wscbor_chunk_t *chunk = wscbor_chunk_read(test_scope, tvb, &offset);
162 g_assert_nonnull(chunk);
163 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
164 g_assert_cmpuint(chunk->type_major, ==, CBOR_TYPE_UINT);
165 g_assert_cmpuint(chunk->head_value, ==, 2);
166 wscbor_chunk_free(chunk);
168 g_assert_cmpint(offset, ==, 3);
169 { // Tag without item
170 volatile unsigned long caught = 0;
171 TRY {
172 wscbor_chunk_read(test_scope, tvb, &offset);
173 g_assert_true(false);
175 CATCH_BOUNDS_ERRORS {
176 caught = exc->except_id.except_code;
178 ENDTRY;
179 g_assert_cmpuint(caught, ==, ReportedBoundsError);
181 g_assert_cmpint(offset, ==, 4);
182 { // Read past the end
183 volatile unsigned long caught = 0;
184 TRY {
185 wscbor_chunk_read(test_scope, tvb, &offset);
186 g_assert_true(false);
188 CATCH_BOUNDS_ERRORS {
189 caught = exc->except_id.except_code;
191 ENDTRY;
192 g_assert_cmpuint(caught, ==, ReportedBoundsError);
194 g_assert_cmpint(offset, ==, 4);
196 tvb_free(tvb);
199 static void
200 wscbor_test_is_indefinite_break(void)
202 for (size_t ex_ix = 0; ex_ix < array_length(all_examples); ++ex_ix) {
203 const example_s *ex = all_examples[ex_ix];
204 printf("simple #%zu\n", ex_ix);
206 tvbuff_t *tvb = tvb_new_real_data(ex->enc, ex->enc_len, ex->enc_len);
207 int offset = 0;
209 wscbor_chunk_t *chunk = wscbor_chunk_read(test_scope, tvb, &offset);
210 g_assert_nonnull(chunk);
211 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
213 // this test never modifies the chunk
214 const bool val = wscbor_is_indefinite_break(chunk);
215 if (memcmp(ex->enc, "\xFF", 1) == 0) {
216 g_assert_true(val);
217 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
219 else {
220 g_assert_false(val);
221 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
224 wscbor_chunk_free(chunk);
225 tvb_free(tvb);
229 static void
230 wscbor_test_skip_next_item_simple(void)
232 // skip simple items
233 for (size_t ex_ix = 0; ex_ix < array_length(all_examples); ++ex_ix) {
234 const example_s *ex = all_examples[ex_ix];
235 printf("simple #%zu\n", ex_ix);
237 tvbuff_t *tvb = tvb_new_real_data(ex->enc, ex->enc_len, ex->enc_len);
238 int offset = 0;
239 bool valid = wscbor_skip_next_item(test_scope, tvb, &offset);
240 // break is well-formed but not valid on its own
241 g_assert_cmpint(valid, ==, (ex != &ex_break));
242 g_assert_cmpint(offset, ==, ex->data_length);
244 tvb_free(tvb);
248 static void
249 wscbor_test_skip_next_item_multiple(void)
251 tvbuff_t *tvb = tvb_new_real_data((const uint8_t *)"\x00\x01\x02\x03", 4, 4);
252 int offset = 2;
254 bool valid = wscbor_skip_next_item(test_scope, tvb, &offset);
255 g_assert_true(valid);
256 g_assert_cmpint(offset, ==, 3);
258 valid = wscbor_skip_next_item(test_scope, tvb, &offset);
259 g_assert_true(valid);
260 g_assert_cmpint(offset, ==, 4);
262 { // Read past the end
263 volatile unsigned long caught = 0;
264 TRY {
265 wscbor_skip_next_item(test_scope, tvb, &offset);
266 g_assert_true(false);
268 CATCH_BOUNDS_ERRORS {
269 caught = exc->except_id.except_code;
271 ENDTRY;
272 g_assert_cmpuint(caught, ==, ReportedBoundsError);
274 g_assert_cmpint(offset, ==, 4);
276 tvb_free(tvb);
279 static void
280 wscbor_test_require_major_type(void)
282 for (size_t ex_ix = 0; ex_ix < array_length(all_examples); ++ex_ix) {
283 const example_s *ex = all_examples[ex_ix];
284 printf("simple #%zu\n", ex_ix);
286 tvbuff_t *tvb = tvb_new_real_data(ex->enc, ex->enc_len, ex->enc_len);
287 int offset = 0;
289 wscbor_chunk_t *chunk = wscbor_chunk_read(test_scope, tvb, &offset);
290 g_assert_nonnull(chunk);
291 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
293 g_assert_true(wscbor_require_major_type(chunk, ex->type_major));
294 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
296 // any other type
297 g_assert_false(wscbor_require_major_type(chunk, ex->type_major + 1));
298 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 1);
300 wscbor_chunk_free(chunk);
301 tvb_free(tvb);
305 static void
306 wscbor_test_require_boolean_simple(void)
308 for (size_t ex_ix = 0; ex_ix < array_length(all_examples); ++ex_ix) {
309 const example_s *ex = all_examples[ex_ix];
310 printf("simple #%zu\n", ex_ix);
312 tvbuff_t *tvb = tvb_new_real_data(ex->enc, ex->enc_len, ex->enc_len);
313 int offset = 0;
315 wscbor_chunk_t *chunk = wscbor_chunk_read(test_scope, tvb, &offset);
316 g_assert_nonnull(chunk);
317 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
319 const bool *val = wscbor_require_boolean(test_scope, chunk);
320 if ((ex->type_major == CBOR_TYPE_FLOAT_CTRL)
321 && ((ex->head_value == CBOR_CTRL_FALSE) || (ex->head_value == CBOR_CTRL_TRUE))) {
322 g_assert_nonnull(val);
323 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
324 g_assert_cmpint(*val, ==, ex->head_value == CBOR_CTRL_TRUE);
326 else {
327 g_assert_null(val);
328 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 1);
331 wscbor_chunk_free(chunk);
332 tvb_free(tvb);
336 static void
337 wscbor_test_require_int64_simple(void)
339 for (size_t ex_ix = 0; ex_ix < array_length(all_examples); ++ex_ix) {
340 const example_s *ex = all_examples[ex_ix];
341 printf("simple #%zu\n", ex_ix);
343 tvbuff_t *tvb = tvb_new_real_data(ex->enc, ex->enc_len, ex->enc_len);
344 int offset = 0;
346 wscbor_chunk_t *chunk = wscbor_chunk_read(test_scope, tvb, &offset);
347 g_assert_nonnull(chunk);
348 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
350 const int64_t *val = wscbor_require_int64(test_scope, chunk);
351 if (ex->type_major == CBOR_TYPE_UINT) {
352 g_assert_nonnull(val);
353 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
354 g_assert_cmpint(*val, ==, ex->head_value);
356 else if (ex->type_major == CBOR_TYPE_NEGINT) {
357 g_assert(val);
358 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
359 g_assert_cmpint(*val, ==, -1 - ex->head_value);
361 else {
362 g_assert_null(val);
363 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 1);
366 wscbor_chunk_free(chunk);
367 tvb_free(tvb);
371 static void
372 wscbor_test_require_int64_overflow(void)
374 const example_s * examples[] = {
375 &ex_uint_overflow, &ex_nint_overflow,
377 for (size_t ex_ix = 0; ex_ix < array_length(examples); ++ex_ix) {
378 const example_s *ex = examples[ex_ix];
379 printf("simple #%zu\n", ex_ix);
381 tvbuff_t *tvb = tvb_new_real_data(ex->enc, ex->enc_len, ex->enc_len);
382 int offset = 0;
384 wscbor_chunk_t *chunk = wscbor_chunk_read(test_scope, tvb, &offset);
385 g_assert_nonnull(chunk);
386 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
387 g_assert_cmpuint(chunk->type_major, ==, ex->type_major);
388 g_assert_cmpuint(chunk->head_value, ==, ex->head_value);
390 const int64_t *val = wscbor_require_int64(test_scope, chunk);
391 if (ex->type_major == CBOR_TYPE_UINT) {
392 g_assert_nonnull(val);
393 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 1);
394 g_assert_cmpint(*val, ==, INT64_MAX);
396 else if (ex->type_major == CBOR_TYPE_NEGINT) {
397 g_assert_nonnull(val);
398 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 1);
399 g_assert_cmpint(*val, ==, INT64_MIN);
401 else {
402 g_assert_null(val);
403 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 1);
406 wscbor_chunk_free(chunk);
407 tvb_free(tvb);
411 static void
412 wscbor_test_require_tstr_simple(void)
414 for (size_t ex_ix = 0; ex_ix < array_length(all_examples); ++ex_ix) {
415 const example_s *ex = all_examples[ex_ix];
416 printf("simple #%zu\n", ex_ix);
418 tvbuff_t *tvb = tvb_new_real_data(ex->enc, ex->enc_len, ex->enc_len);
419 int offset = 0;
421 wscbor_chunk_t *chunk = wscbor_chunk_read(test_scope, tvb, &offset);
422 g_assert_nonnull(chunk);
423 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
425 const char *val = wscbor_require_tstr(test_scope, chunk);
426 if (ex->type_major == CBOR_TYPE_STRING) {
427 g_assert_nonnull(val);
428 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
429 if (ex->head_value > 0) {
430 // only works because this is Latin-1 text
431 g_assert_cmpmem(val, (int)strlen(val), ex->enc + ex->head_length, (int)ex->head_value);
434 else {
435 g_assert_null(val);
436 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 1);
439 wscbor_chunk_free(chunk);
440 tvb_free(tvb);
444 static void
445 wscbor_test_require_tstr_short(void)
447 const example_s * examples[] = {
448 &ex_tstr_short,
450 tvbuff_t *tvb = NULL;
451 wscbor_chunk_t *chunk = NULL;
453 for (size_t ex_ix = 0; ex_ix < array_length(examples); ++ex_ix) {
454 const example_s *ex = examples[ex_ix];
455 printf("simple #%zu\n", ex_ix);
457 tvb = tvb_new_real_data(ex->enc, ex->enc_len, ex->enc_len);
458 int offset = 0;
460 chunk = wscbor_chunk_read(test_scope, tvb, &offset);
461 g_assert_nonnull(chunk);
462 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
463 g_assert_cmpuint(chunk->type_major, ==, ex->type_major);
464 g_assert_cmpuint(chunk->head_value, ==, ex->head_value);
466 volatile unsigned long caught = 0;
467 TRY {
468 wscbor_require_tstr(test_scope, chunk);
469 g_assert_true(false);
471 CATCH_BOUNDS_ERRORS {
472 caught = exc->except_id.except_code;
474 ENDTRY;
475 g_assert_cmpuint(caught, ==, ContainedBoundsError);
477 wscbor_chunk_free(chunk);
478 tvb_free(tvb);
482 static void
483 wscbor_test_require_bstr_simple(void)
485 for (size_t ex_ix = 0; ex_ix < array_length(all_examples); ++ex_ix) {
486 const example_s *ex = all_examples[ex_ix];
487 printf("simple #%zu\n", ex_ix);
489 tvbuff_t *tvb = tvb_new_real_data(ex->enc, ex->enc_len, ex->enc_len);
490 int offset = 0;
492 wscbor_chunk_t *chunk = wscbor_chunk_read(test_scope, tvb, &offset);
493 g_assert_nonnull(chunk);
494 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
496 tvbuff_t *val = wscbor_require_bstr(test_scope, chunk);
497 if (ex->type_major == CBOR_TYPE_BYTESTRING) {
498 g_assert_nonnull(val);
499 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
500 if (ex->head_value > 0) {
501 g_assert_cmpint(tvb_reported_length(val), ==, ex->head_value);
502 g_assert_cmpuint(tvb_captured_length(val), ==, ex->head_value);
504 const int buflen = tvb_reported_length(val);
505 void *buf = tvb_memdup(test_scope, val, 0, buflen);
506 g_assert_nonnull(buf);
507 g_assert_cmpmem(buf, (int)buflen, ex->enc + ex->head_length, (int)ex->head_value);
510 else {
511 g_assert_null(val);
512 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 1);
515 wscbor_chunk_free(chunk);
516 tvb_free(tvb);
520 static void
521 wscbor_test_require_bstr_short(void)
523 const example_s * examples[] = {
524 &ex_bstr_short,
526 tvbuff_t *tvb = NULL;
527 wscbor_chunk_t *chunk = NULL;
528 tvbuff_t *val = NULL;
530 for (size_t ex_ix = 0; ex_ix < array_length(examples); ++ex_ix) {
531 const example_s *ex = examples[ex_ix];
532 printf("simple #%zu\n", ex_ix);
534 tvb = tvb_new_real_data(ex->enc, ex->enc_len, ex->enc_len);
535 int offset = 0;
537 chunk = wscbor_chunk_read(test_scope, tvb, &offset);
538 g_assert_nonnull(chunk);
539 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
540 g_assert_cmpuint(chunk->type_major, ==, ex->type_major);
541 g_assert_cmpuint(chunk->head_value, ==, ex->head_value);
543 // no exception, but truncated captured length
544 val = wscbor_require_bstr(test_scope, chunk);
545 g_assert_nonnull(val);
546 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 0);
547 g_assert_cmpint(tvb_reported_length(val), ==, ex->head_value);
548 g_assert_cmpuint(tvb_captured_length(val), <, ex->head_value);
550 volatile unsigned long caught = 0;
551 TRY {
552 const int buflen = tvb_reported_length(val);
553 tvb_memdup(test_scope, val, 0, buflen);
554 g_assert_true(false);
556 CATCH_BOUNDS_ERRORS {
557 caught = exc->except_id.except_code;
559 ENDTRY;
560 g_assert_cmpuint(caught, ==, ContainedBoundsError);
562 wscbor_chunk_free(chunk);
563 tvb_free(tvb);
567 static void
568 wscbor_test_require_bstr_overflow(void)
570 const example_s * examples[] = {
571 &ex_bstr_overflow,
573 for (size_t ex_ix = 0; ex_ix < array_length(examples); ++ex_ix) {
574 const example_s *ex = examples[ex_ix];
575 printf("simple #%zu\n", ex_ix);
577 tvbuff_t *tvb = tvb_new_real_data(ex->enc, ex->enc_len, ex->enc_len);
578 int offset = 0;
580 wscbor_chunk_t *chunk = wscbor_chunk_read(test_scope, tvb, &offset);
581 g_assert_nonnull(chunk);
582 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 1);
583 g_assert_cmpuint(chunk->type_major, ==, ex->type_major);
584 g_assert_cmpuint(chunk->head_value, ==, ex->head_value);
586 const tvbuff_t *val = wscbor_require_bstr(test_scope, chunk);
587 g_assert_nonnull(val);
588 g_assert_cmpuint(wscbor_has_errors(chunk), ==, 1);
589 g_assert_cmpuint(tvb_reported_length(val), ==, INT_MAX);
590 g_assert_cmpuint(tvb_captured_length(val), ==, 2);
592 wscbor_chunk_free(chunk);
593 tvb_free(tvb);
598 main(int argc, char **argv)
600 int result;
602 g_test_init(&argc, &argv, NULL);
604 g_test_add_func("/wscbor/chunk_read/simple", wscbor_test_chunk_read_simple);
605 g_test_add_func("/wscbor/chunk_read/simple_tags", wscbor_test_chunk_read_simple_tags);
606 g_test_add_func("/wscbor/chunk_read/invalid", wscbor_test_chunk_read_invalid);
607 g_test_add_func("/wscbor/is_indefinite_break", wscbor_test_is_indefinite_break);
608 g_test_add_func("/wscbor/skip_next_item/simple", wscbor_test_skip_next_item_simple);
609 g_test_add_func("/wscbor/skip_next_item/multiple", wscbor_test_skip_next_item_multiple);
610 g_test_add_func("/wscbor/require_major_type", wscbor_test_require_major_type);
611 g_test_add_func("/wscbor/require_boolean/simple", wscbor_test_require_boolean_simple);
612 g_test_add_func("/wscbor/require_int64/simple", wscbor_test_require_int64_simple);
613 g_test_add_func("/wscbor/require_int64/overflow", wscbor_test_require_int64_overflow);
614 g_test_add_func("/wscbor/require_tstr/simple", wscbor_test_require_tstr_simple);
615 g_test_add_func("/wscbor/require_tstr/short", wscbor_test_require_tstr_short);
616 g_test_add_func("/wscbor/require_bstr/simple", wscbor_test_require_bstr_simple);
617 g_test_add_func("/wscbor/require_bstr/short", wscbor_test_require_bstr_short);
618 g_test_add_func("/wscbor/require_bstr/overflow", wscbor_test_require_bstr_overflow);
619 wmem_init_scopes();
621 test_scope = wmem_allocator_new(WMEM_ALLOCATOR_STRICT);
622 //cannot use: wscbor_init();
623 result = g_test_run();
624 //none needed: wscbor_cleanup();
625 wmem_destroy_allocator(test_scope);
626 wmem_cleanup_scopes();
628 return result;
632 * Editor modelines - https://www.wireshark.org/tools/modelines.html
634 * Local variables:
635 * c-basic-offset: 4
636 * tab-width: 8
637 * indent-tabs-mode: nil
638 * End:
640 * vi: set shiftwidth=4 tabstop=8 expandtab:
641 * :indentSize=4:tabSize=8:noTabs=true: