11/**
22 * @file test_printer_json.c
33 * @author: Radek Krejci <[email protected] > 4+ * @author Michal Vasko <[email protected] > 45 * @brief unit tests for functions from printer_yang.c
56 *
6- * Copyright (c) 2019-2020 CESNET, z.s.p.o.
7+ * Copyright (c) 2019 - 2025 CESNET, z.s.p.o.
78 *
89 * This source code is licensed under BSD 3-Clause License (the "License").
910 * You may not use this file except in compliance with the License.
@@ -34,6 +35,12 @@ setup(void **state)
3435 " type string;"
3536 " }"
3637 " }"
38+ " list l2 {"
39+ " key \"k2\";"
40+ " leaf k2 {"
41+ " type string;"
42+ " }"
43+ " }"
3744 " }"
3845 " leaf-list ll {"
3946 " type string;"
@@ -96,7 +103,14 @@ test_empty_leaf_list(void **state)
96103 data = "{\"schema2:a\":{\"b\":{\"c\":\"val\"}}}" ;
97104 CHECK_PARSE_LYD_PARAM (data , LYD_JSON , 0 , LYD_VALIDATE_PRESENT , LY_SUCCESS , tree );
98105 assert_int_equal (LY_SUCCESS , lyd_print_mem (& buffer , tree , LYD_JSON , LYD_PRINT_SHRINK | LYD_PRINT_EMPTY_LEAF_LIST ));
99- CHECK_STRING (buffer , "{\"schema2:a\":{\"b\":{\"c\":\"val\",\"l\":[]},\"ll\":[]},\"schema2:tl\":[]}" );
106+ CHECK_STRING (buffer , "{\"schema2:a\":{\"b\":{\"c\":\"val\",\"l\":[],\"l2\":[]},\"ll\":[]},\"schema2:tl\":[]}" );
107+ free (buffer );
108+ lyd_free_all (tree );
109+
110+ data = "{\"schema2:a\":{\"b\":{\"l\":[{\"k\":\"key1\"},{\"k\":\"key2\"}]}}}" ;
111+ CHECK_PARSE_LYD_PARAM (data , LYD_JSON , 0 , LYD_VALIDATE_PRESENT , LY_SUCCESS , tree );
112+ assert_int_equal (LY_SUCCESS , lyd_print_mem (& buffer , tree , LYD_JSON , LYD_PRINT_SHRINK | LYD_PRINT_EMPTY_LEAF_LIST ));
113+ CHECK_STRING (buffer , "{\"schema2:a\":{\"b\":{\"l\":[{\"k\":\"key1\"},{\"k\":\"key2\"}],\"l2\":[]},\"ll\":[]},\"schema2:tl\":[]}" );
100114 free (buffer );
101115 lyd_free_all (tree );
102116
@@ -107,6 +121,8 @@ test_empty_leaf_list(void **state)
107121 " \"schema2:a\": {\n"
108122 " \"b\": {\n"
109123 " \"l\": [\n"
124+ " ],\n"
125+ " \"l2\": [\n"
110126 " ]\n"
111127 " },\n"
112128 " \"ll\": [\n"
0 commit comments