xref: /freebsd/contrib/libcbor/test/pretty_printer_test.c (revision fe75646a0234a261c0013bf1840fdac4acaf0cec)
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 <stdio.h>
9 #include "assertions.h"
10 #include "cbor.h"
11 
12 unsigned char data[] = {0x8B, 0x01, 0x20, 0x5F, 0x41, 0x01, 0x41, 0x02,
13                         0xFF, 0x7F, 0x61, 0x61, 0x61, 0x62, 0xFF, 0x9F,
14                         0xFF, 0xA1, 0x61, 0x61, 0x61, 0x62, 0xC0, 0xBF,
15                         0xFF, 0xFB, 0x40, 0x09, 0x1E, 0xB8, 0x51, 0xEB,
16                         0x85, 0x1F, 0xF6, 0xF7, 0xF5};
17 
18 static void test_pretty_printer(void **_CBOR_UNUSED(_state)) {
19 #if CBOR_PRETTY_PRINTER
20   FILE *outfile = tmpfile();
21   struct cbor_load_result res;
22   cbor_item_t *item = cbor_load(data, 37, &res);
23   cbor_describe(item, outfile);
24   cbor_decref(&item);
25 
26   item = cbor_new_ctrl();
27   cbor_set_ctrl(item, 1);
28   cbor_describe(item, outfile);
29   cbor_decref(&item);
30 
31   fclose(outfile);
32 #endif
33 }
34 
35 int main(void) {
36   const struct CMUnitTest tests[] = {cmocka_unit_test(test_pretty_printer)};
37   return cmocka_run_group_tests(tests, NULL, NULL);
38 }
39