1 /*
2  * Copyright (c) 2014-2020 Pavel Kalvoda <me@pavelkalvoda.com>
3  *
4  * libcbor is free software; you can redistribute it and/or modify
5  * it under the terms of the MIT license. See LICENSE for details.
6  */
7 
8 #include <setjmp.h>
9 #include <stdarg.h>
10 #include <stddef.h>
11 
12 #include <cmocka.h>
13 
14 #include <stdio.h>
15 #include "cbor.h"
16 
17 unsigned char data[] = {0x8B, 0x01, 0x20, 0x5F, 0x41, 0x01, 0x41, 0x02,
18                         0xFF, 0x7F, 0x61, 0x61, 0x61, 0x62, 0xFF, 0x9F,
19                         0xFF, 0xA1, 0x61, 0x61, 0x61, 0x62, 0xC0, 0xBF,
20                         0xFF, 0xFB, 0x40, 0x09, 0x1E, 0xB8, 0x51, 0xEB,
21                         0x85, 0x1F, 0xF6, 0xF7, 0xF5};
22 
23 static void test_pretty_printer(void **state) {
24 #if CBOR_PRETTY_PRINTER
25   FILE *outfile = tmpfile();
26   struct cbor_load_result res;
27   cbor_item_t *item = cbor_load(data, 37, &res);
28   cbor_describe(item, outfile);
29   cbor_decref(&item);
30 
31   item = cbor_new_ctrl();
32   cbor_set_ctrl(item, 1);
33   cbor_describe(item, outfile);
34   cbor_decref(&item);
35 
36   fclose(outfile);
37 #endif
38 }
39 
40 int main(void) {
41   const struct CMUnitTest tests[] = {cmocka_unit_test(test_pretty_printer)};
42   return cmocka_run_group_tests(tests, NULL, NULL);
43 }
44