xref: /freebsd/contrib/libcbor/test/pretty_printer_test.c (revision 5d3e7166f6a0187fa3f8831b16a06bd9955c21ff)
110ff414cSEd Maste /*
210ff414cSEd Maste  * Copyright (c) 2014-2020 Pavel Kalvoda <me@pavelkalvoda.com>
310ff414cSEd Maste  *
410ff414cSEd Maste  * libcbor is free software; you can redistribute it and/or modify
510ff414cSEd Maste  * it under the terms of the MIT license. See LICENSE for details.
610ff414cSEd Maste  */
710ff414cSEd Maste 
810ff414cSEd Maste #include <stdio.h>
9*5d3e7166SEd Maste #include "assertions.h"
1010ff414cSEd Maste #include "cbor.h"
1110ff414cSEd Maste 
1210ff414cSEd Maste unsigned char data[] = {0x8B, 0x01, 0x20, 0x5F, 0x41, 0x01, 0x41, 0x02,
1310ff414cSEd Maste                         0xFF, 0x7F, 0x61, 0x61, 0x61, 0x62, 0xFF, 0x9F,
1410ff414cSEd Maste                         0xFF, 0xA1, 0x61, 0x61, 0x61, 0x62, 0xC0, 0xBF,
1510ff414cSEd Maste                         0xFF, 0xFB, 0x40, 0x09, 0x1E, 0xB8, 0x51, 0xEB,
1610ff414cSEd Maste                         0x85, 0x1F, 0xF6, 0xF7, 0xF5};
1710ff414cSEd Maste 
18*5d3e7166SEd Maste static void test_pretty_printer(void **_CBOR_UNUSED(_state)) {
1910ff414cSEd Maste #if CBOR_PRETTY_PRINTER
2010ff414cSEd Maste   FILE *outfile = tmpfile();
2110ff414cSEd Maste   struct cbor_load_result res;
2210ff414cSEd Maste   cbor_item_t *item = cbor_load(data, 37, &res);
2310ff414cSEd Maste   cbor_describe(item, outfile);
2410ff414cSEd Maste   cbor_decref(&item);
2510ff414cSEd Maste 
2610ff414cSEd Maste   item = cbor_new_ctrl();
2710ff414cSEd Maste   cbor_set_ctrl(item, 1);
2810ff414cSEd Maste   cbor_describe(item, outfile);
2910ff414cSEd Maste   cbor_decref(&item);
3010ff414cSEd Maste 
3110ff414cSEd Maste   fclose(outfile);
3210ff414cSEd Maste #endif
3310ff414cSEd Maste }
3410ff414cSEd Maste 
3510ff414cSEd Maste int main(void) {
3610ff414cSEd Maste   const struct CMUnitTest tests[] = {cmocka_unit_test(test_pretty_printer)};
3710ff414cSEd Maste   return cmocka_run_group_tests(tests, NULL, NULL);
3810ff414cSEd Maste }
39