blob: 85ace73d13beb983507f2b54add2e369421b035d [file] [log] [blame]
stewegcbbae422024-04-22 11:38:25 +02001/*
2 * @file test_printer_json.c
3 * @author: Radek Krejci <rkrejci@cesnet.cz>
4 * @brief unit tests for functions from printer_yang.c
5 *
6 * Copyright (c) 2019-2020 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14#define _UTEST_MAIN_
15#include "utests.h"
16
17static int
18setup(void **state)
19{
20 const char *schema1 = "module schema1 {namespace urn:tests:schema1;prefix schema1;yang-version 1.1;"
21 "revision 2014-05-08;"
22 "anydata data;"
23 "}";
24
25 UTEST_SETUP;
26 UTEST_ADD_MODULE(schema1, LYS_IN_YANG, NULL, NULL);
27 return 0;
28}
29
30static void
31test_container_presence(void **state)
32{
33 struct lyd_node *tree;
34 char *buffer = NULL;
35 const char *data = "{\"schema1:data\":{\"cont1\":{}}}";
36
37 CHECK_PARSE_LYD_PARAM(data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree);
38 assert_int_equal(LY_SUCCESS, lyd_print_mem(&buffer, tree, LYD_JSON, LYD_PRINT_SHRINK));
39 CHECK_STRING(buffer, data);
40 free(buffer);
41 lyd_free_all(tree);
42}
43
44int
45main(void)
46{
47 const struct CMUnitTest tests[] = {
48 UTEST(test_container_presence, setup),
49 };
50
51 return cmocka_run_group_tests(tests, NULL, NULL);
52}