xref: /netbsd-src/external/mit/libcbor/dist/test/callbacks_test.c (revision 5dd36a3bc8bf2a9dec29ceb6349550414570c447)
1*5dd36a3bSchristos /*
2*5dd36a3bSchristos  * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
3*5dd36a3bSchristos  *
4*5dd36a3bSchristos  * libcbor is free software; you can redistribute it and/or modify
5*5dd36a3bSchristos  * it under the terms of the MIT license. See LICENSE for details.
6*5dd36a3bSchristos  */
7*5dd36a3bSchristos 
8*5dd36a3bSchristos #include <setjmp.h>
9*5dd36a3bSchristos #include <stdarg.h>
10*5dd36a3bSchristos #include <stddef.h>
11*5dd36a3bSchristos 
12*5dd36a3bSchristos #include <cmocka.h>
13*5dd36a3bSchristos 
14*5dd36a3bSchristos #include "cbor.h"
15*5dd36a3bSchristos 
16*5dd36a3bSchristos unsigned char data[] = {
17*5dd36a3bSchristos     0x93, 0x01, 0x19, 0x01, 0x01, 0x1A, 0x00, 0x01, 0x05, 0xB8, 0x1B, 0x00,
18*5dd36a3bSchristos     0x00, 0x00, 0x01, 0x8F, 0x5A, 0xE8, 0xB8, 0x20, 0x39, 0x01, 0x00, 0x3A,
19*5dd36a3bSchristos     0x00, 0x01, 0x05, 0xB7, 0x3B, 0x00, 0x00, 0x00, 0x01, 0x8F, 0x5A, 0xE8,
20*5dd36a3bSchristos     0xB7, 0x5F, 0x41, 0x01, 0x41, 0x02, 0xFF, 0x7F, 0x61, 0x61, 0x61, 0x62,
21*5dd36a3bSchristos     0xFF, 0x9F, 0xFF, 0xA1, 0x61, 0x61, 0x61, 0x62, 0xC0, 0xBF, 0xFF, 0xF9,
22*5dd36a3bSchristos     0x3C, 0x00, 0xFA, 0x47, 0xC3, 0x50, 0x00, 0xFB, 0x7E, 0x37, 0xE4, 0x3C,
23*5dd36a3bSchristos     0x88, 0x00, 0x75, 0x9C, 0xF6, 0xF7, 0xF5};
24*5dd36a3bSchristos 
25*5dd36a3bSchristos /* Exercise the default callbacks */
test_default_callbacks(void ** state)26*5dd36a3bSchristos static void test_default_callbacks(void **state) {
27*5dd36a3bSchristos   size_t read = 0;
28*5dd36a3bSchristos   while (read < 79) {
29*5dd36a3bSchristos     struct cbor_decoder_result result =
30*5dd36a3bSchristos         cbor_stream_decode(data + read, 79 - read, &cbor_empty_callbacks, NULL);
31*5dd36a3bSchristos     read += result.read;
32*5dd36a3bSchristos   }
33*5dd36a3bSchristos }
34*5dd36a3bSchristos 
main(void)35*5dd36a3bSchristos int main(void) {
36*5dd36a3bSchristos   const struct CMUnitTest tests[] = {
37*5dd36a3bSchristos 
38*5dd36a3bSchristos       cmocka_unit_test(test_default_callbacks)};
39*5dd36a3bSchristos   return cmocka_run_group_tests(tests, NULL, NULL);
40*5dd36a3bSchristos }
41