aboutsummaryrefslogtreecommitdiff
path: root/test/pretty_printer_test.c
blob: 4a6249c412d889c7261d1db0be3adeed6feb0fbb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 * Copyright (c) 2014-2020 Pavel Kalvoda <me@pavelkalvoda.com>
 *
 * libcbor is free software; you can redistribute it and/or modify
 * it under the terms of the MIT license. See LICENSE for details.
 */

#include <stdio.h>
#include "assertions.h"
#include "cbor.h"

unsigned char data[] = {0x8B, 0x01, 0x20, 0x5F, 0x41, 0x01, 0x41, 0x02,
                        0xFF, 0x7F, 0x61, 0x61, 0x61, 0x62, 0xFF, 0x9F,
                        0xFF, 0xA1, 0x61, 0x61, 0x61, 0x62, 0xC0, 0xBF,
                        0xFF, 0xFB, 0x40, 0x09, 0x1E, 0xB8, 0x51, 0xEB,
                        0x85, 0x1F, 0xF6, 0xF7, 0xF5};

static void test_pretty_printer(void **_CBOR_UNUSED(_state)) {
#if CBOR_PRETTY_PRINTER
  FILE *outfile = tmpfile();
  struct cbor_load_result res;
  cbor_item_t *item = cbor_load(data, 37, &res);
  cbor_describe(item, outfile);
  cbor_decref(&item);

  item = cbor_new_ctrl();
  cbor_set_ctrl(item, 1);
  cbor_describe(item, outfile);
  cbor_decref(&item);

  fclose(outfile);
#endif
}

int main(void) {
  const struct CMUnitTest tests[] = {cmocka_unit_test(test_pretty_printer)};
  return cmocka_run_group_tests(tests, NULL, NULL);
}