blob: 0433832ebb273c891226eacad4973bdb6c6f0e4f [file] [log] [blame]
Radek Krejci1798aae2020-07-14 13:26:06 +02001/*
aPiecek023f83a2021-05-11 07:37:03 +02002 * @file test_parser_json.c
Radek Krejci1798aae2020-07-14 13:26:06 +02003 * @author: Radek Krejci <rkrejci@cesnet.cz>
4 * @brief unit tests for functions from parser_xml.c
5 *
6 * Copyright (c) 2019 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 */
Radek Iša56ca9e42020-09-08 18:42:00 +020014#define _UTEST_MAIN_
15#include "utests.h"
Radek Krejci1798aae2020-07-14 13:26:06 +020016
Radek Krejci1798aae2020-07-14 13:26:06 +020017#include "context.h"
Michal Vaskoafac7822020-10-20 14:22:26 +020018#include "in.h"
Michal Vaskoafac7822020-10-20 14:22:26 +020019#include "out.h"
Radek Krejcib4ac5a92020-11-23 17:54:33 +010020#include "parser_data.h"
Radek Krejci1798aae2020-07-14 13:26:06 +020021#include "printer_data.h"
Radek Krejcief5f7672021-04-01 17:04:12 +020022#include "tests_config.h"
Radek Krejci1798aae2020-07-14 13:26:06 +020023#include "tree_data_internal.h"
24#include "tree_schema.h"
Radek Krejci1798aae2020-07-14 13:26:06 +020025
26static int
27setup(void **state)
28{
Radek Iša56ca9e42020-09-08 18:42:00 +020029 const char *schema = "module a {namespace urn:tests:a;prefix a;yang-version 1.1; import ietf-yang-metadata {prefix md;}"
Radek Krejci1798aae2020-07-14 13:26:06 +020030 "md:annotation hint { type int8;}"
Michal Vaskodbf3e652022-10-21 08:46:25 +020031 "list l1 { key \"a b c\"; leaf a {type string;} leaf b {type string;} leaf c {type int16;}"
32 " leaf d {type string;}"
33 " container cont {leaf e {type boolean;}}"
34 "}"
Radek Krejci1798aae2020-07-14 13:26:06 +020035 "leaf foo { type string;}"
36 "container c {"
Radek Krejcib4ac5a92020-11-23 17:54:33 +010037 " leaf x {type string;}"
38 " action act { input { leaf al {type string;} } output { leaf al {type uint8;} } }"
39 " notification n1 { leaf nl {type string;} }"
Radek Krejci1798aae2020-07-14 13:26:06 +020040 "}"
41 "container cp {presence \"container switch\"; leaf y {type string;} leaf z {type int8;}}"
42 "anydata any {config false;}"
Michal Vasko76096ec2022-02-24 16:06:16 +010043 "anyxml axml;"
Radek Krejci1798aae2020-07-14 13:26:06 +020044 "leaf-list ll1 { type uint8; }"
45 "leaf foo2 { type string; default \"default-val\"; }"
46 "leaf foo3 { type uint32; }"
47 "notification n2;}";
Radek Krejci1798aae2020-07-14 13:26:06 +020048
Radek Iša56ca9e42020-09-08 18:42:00 +020049 UTEST_SETUP;
Radek Krejci1798aae2020-07-14 13:26:06 +020050
Radek Iša56ca9e42020-09-08 18:42:00 +020051 UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
52 assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
Radek Krejci1798aae2020-07-14 13:26:06 +020053
54 return 0;
55}
56
Radek Iša56ca9e42020-09-08 18:42:00 +020057#define CHECK_PARSE_LYD(INPUT, PARSE_OPTION, VALIDATE_OPTION, TREE) \
58 CHECK_PARSE_LYD_PARAM(INPUT, LYD_JSON, PARSE_OPTION, VALIDATE_OPTION, LY_SUCCESS, TREE)
Radek Krejci1798aae2020-07-14 13:26:06 +020059
Radek Iša56ca9e42020-09-08 18:42:00 +020060#define PARSER_CHECK_ERROR(INPUT, PARSE_OPTION, VALIDATE_OPTION, MODEL, RET_VAL, ERR_MESSAGE, ERR_PATH) \
61 assert_int_equal(RET_VAL, lyd_parse_data_mem(UTEST_LYCTX, INPUT, LYD_JSON, PARSE_OPTION, VALIDATE_OPTION, &MODEL));\
62 CHECK_LOG_CTX(ERR_MESSAGE, ERR_PATH);\
63 assert_null(MODEL)
Radek Krejci1798aae2020-07-14 13:26:06 +020064
Radek Iša56ca9e42020-09-08 18:42:00 +020065#define CHECK_LYD_STRING(IN_MODEL, PRINT_OPTION, TEXT) \
66 CHECK_LYD_STRING_PARAM(IN_MODEL, TEXT, LYD_JSON, PRINT_OPTION)
Radek Krejci1798aae2020-07-14 13:26:06 +020067
68static void
69test_leaf(void **state)
70{
Radek Krejci1798aae2020-07-14 13:26:06 +020071 struct lyd_node *tree;
72 struct lyd_node_term *leaf;
Radek Iša56ca9e42020-09-08 18:42:00 +020073 const char *data;
Radek Krejci1798aae2020-07-14 13:26:06 +020074
Radek Iša56ca9e42020-09-08 18:42:00 +020075 assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf-with-defaults", "2011-06-01", NULL));
Radek Krejcib4ac5a92020-11-23 17:54:33 +010076
Radek Iša56ca9e42020-09-08 18:42:00 +020077 data = "{\"a:foo\":\"foo value\"}";
78 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
79 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "foo", 1, LYS_LEAF, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +010080 leaf = (struct lyd_node_term *)tree;
Radek Iša56ca9e42020-09-08 18:42:00 +020081 CHECK_LYD_VALUE(leaf->value, STRING, "foo value");
Radek Krejci1798aae2020-07-14 13:26:06 +020082
Radek Iša56ca9e42020-09-08 18:42:00 +020083 CHECK_LYSC_NODE(tree->next->next->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2",
84 1, LYS_LEAF, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +010085 leaf = (struct lyd_node_term *)tree->next->next;
Radek Iša56ca9e42020-09-08 18:42:00 +020086
87 CHECK_LYD_VALUE(leaf->value, STRING, "default-val");
Radek Krejci1798aae2020-07-14 13:26:06 +020088 assert_true(leaf->flags & LYD_DEFAULT);
89
Radek Iša56ca9e42020-09-08 18:42:00 +020090 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +020091 lyd_free_all(tree);
92
93 /* make foo2 explicit */
94 data = "{\"a:foo2\":\"default-val\"}";
Radek Iša56ca9e42020-09-08 18:42:00 +020095 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
Radek Krejci1798aae2020-07-14 13:26:06 +020096 assert_non_null(tree);
Michal Vasko26123192020-11-09 21:02:34 +010097 tree = tree->next;
Radek Iša56ca9e42020-09-08 18:42:00 +020098 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2",
99 1, LYS_LEAF, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100100 leaf = (struct lyd_node_term *)tree;
Radek Iša56ca9e42020-09-08 18:42:00 +0200101 CHECK_LYD_VALUE(leaf->value, STRING, "default-val");
Radek Krejci1798aae2020-07-14 13:26:06 +0200102 assert_false(leaf->flags & LYD_DEFAULT);
103
Radek Iša56ca9e42020-09-08 18:42:00 +0200104 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200105 lyd_free_all(tree);
106
107 /* parse foo2 but make it implicit */
Radek Krejci5536d282020-08-04 23:27:44 +0200108 data = "{\"a:foo2\":\"default-val\",\"@a:foo2\":{\"ietf-netconf-with-defaults:default\":true}}";
Radek Iša56ca9e42020-09-08 18:42:00 +0200109 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
Radek Krejci1798aae2020-07-14 13:26:06 +0200110 assert_non_null(tree);
Michal Vasko26123192020-11-09 21:02:34 +0100111 tree = tree->next;
Radek Iša56ca9e42020-09-08 18:42:00 +0200112 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2",
113 1, LYS_LEAF, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100114 leaf = (struct lyd_node_term *)tree;
Radek Iša56ca9e42020-09-08 18:42:00 +0200115 CHECK_LYD_VALUE(leaf->value, STRING, "default-val");
Radek Krejci1798aae2020-07-14 13:26:06 +0200116 assert_true(leaf->flags & LYD_DEFAULT);
117
Michal Vaskob68c3b42022-05-20 10:36:40 +0200118 /* print default values */
119 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL_TAG, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200120 lyd_free_all(tree);
121
Michal Vaskoa4af6252022-05-20 10:38:54 +0200122 /* skip leaf */
123 data = "{\"a:cp\":{\"x\":\"val\",\"y\":\"valy\",\"z\":5}}";
124 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
125 assert_non_null(tree);
126
127 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, "{\"a:cp\":{\"y\":\"valy\",\"z\":5}}");
128 lyd_free_all(tree);
129
Radek Krejci1798aae2020-07-14 13:26:06 +0200130 /* multiple meatadata hint and unknown metadata xxx supposed to be skipped since it is from missing schema */
Radek Krejci5536d282020-08-04 23:27:44 +0200131 data = "{\"@a:foo\":{\"a:hint\":1,\"a:hint\":2,\"x:xxx\":{\"value\":\"/x:no/x:yes\"}},\"a:foo\":\"xxx\"}";
Radek Iša56ca9e42020-09-08 18:42:00 +0200132 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
133 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "foo", 1, LYS_LEAF, 0, 0, NULL, 0);
134 CHECK_LYD_META(tree->meta, 1, "hint", 1, 1, INT8, "1", 1);
135 CHECK_LYD_META(tree->meta->next, 1, "hint", 0, 1, INT8, "2", 2);
Radek Krejci1798aae2020-07-14 13:26:06 +0200136 assert_null(tree->meta->next->next);
137
Radek Iša56ca9e42020-09-08 18:42:00 +0200138 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS,
139 "{\"a:foo\":\"xxx\",\"@a:foo\":{\"a:hint\":1,\"a:hint\":2}}");
Radek Krejci1798aae2020-07-14 13:26:06 +0200140 lyd_free_all(tree);
141
Radek Iša56ca9e42020-09-08 18:42:00 +0200142 PARSER_CHECK_ERROR(data, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vasko959f8d82022-06-16 07:51:50 +0200143 "Unknown (or not implemented) YANG module \"x\" of metadata \"x:xxx\".", "Data location \"/@a:foo\", line number 1.");
Radek Krejci1798aae2020-07-14 13:26:06 +0200144
145 /* missing referenced metadata node */
Radek Iša56ca9e42020-09-08 18:42:00 +0200146 PARSER_CHECK_ERROR("{\"@a:foo\" : { \"a:hint\" : 1 }}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vasko959f8d82022-06-16 07:51:50 +0200147 "Missing JSON data instance to be coupled with @a:foo metadata.", "Data location \"/@a:foo\", line number 1.");
Radek Krejci1798aae2020-07-14 13:26:06 +0200148
149 /* missing namespace for meatadata*/
Radek Iša56ca9e42020-09-08 18:42:00 +0200150 PARSER_CHECK_ERROR("{\"a:foo\" : \"value\", \"@a:foo\" : { \"hint\" : 1 }}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vasko959f8d82022-06-16 07:51:50 +0200151 "Metadata in JSON must be namespace-qualified, missing prefix for \"hint\".",
152 "Schema location \"/a:foo\", line number 1.");
aPiecek49e2a3a2021-05-13 10:36:46 +0200153
Michal Vaskodbf3e652022-10-21 08:46:25 +0200154 /* invalid JSON type */
155 data = "{\"a:l1\" : [{ \"a\" : \"val-a\", \"b\" : \"val-b\", \"c\" : 1, \"cont\" : { \"e\" : \"0\" } }]}";
156 PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
157 "Invalid non-boolean-encoded boolean value \"0\".",
158 "Data location \"/a:l1[a='val-a'][b='val-b'][c='1']/cont/e\", line number 1.");
159
aPiecek49e2a3a2021-05-13 10:36:46 +0200160 /* reverse solidus in JSON object member name */
161 data = "{\"@a:foo\":{\"a:hi\\nt\":1},\"a:foo\":\"xxx\"}";
162 assert_int_equal(LY_EINVAL, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
Michal Vasko62af3692023-02-09 14:00:09 +0100163 CHECK_LOG_CTX("Annotation definition for attribute \"a:hi\nt\" not found.", "Data location \"/@a:foo\", line number 1.");
Radek Krejci1798aae2020-07-14 13:26:06 +0200164}
165
166static void
167test_leaflist(void **state)
168{
Radek Iša56ca9e42020-09-08 18:42:00 +0200169 const char *data;
Radek Krejci1798aae2020-07-14 13:26:06 +0200170 struct lyd_node *tree;
171 struct lyd_node_term *ll;
172
Radek Iša56ca9e42020-09-08 18:42:00 +0200173 data = "{\"a:ll1\":[10,11]}";
174 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
Radek Krejci1798aae2020-07-14 13:26:06 +0200175 assert_non_null(tree);
Michal Vasko26123192020-11-09 21:02:34 +0100176 tree = tree->next;
Radek Iša56ca9e42020-09-08 18:42:00 +0200177 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "ll1",
178 1, LYS_LEAFLIST, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100179 ll = (struct lyd_node_term *)tree;
Radek Iša56ca9e42020-09-08 18:42:00 +0200180 CHECK_LYD_VALUE(ll->value, UINT8, "10", 10);
Radek Krejci1798aae2020-07-14 13:26:06 +0200181
182 assert_non_null(tree->next);
Radek Iša56ca9e42020-09-08 18:42:00 +0200183 CHECK_LYSC_NODE(tree->next->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "ll1",
184 1, LYS_LEAFLIST, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100185 ll = (struct lyd_node_term *)tree->next;
Radek Iša56ca9e42020-09-08 18:42:00 +0200186 CHECK_LYD_VALUE(ll->value, UINT8, "11", 11);
Radek Krejci1798aae2020-07-14 13:26:06 +0200187
Radek Iša56ca9e42020-09-08 18:42:00 +0200188 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200189 lyd_free_all(tree);
190
Michal Vasko4e26adc2022-03-30 11:01:16 +0200191 /* accept empty */
192 data = "{\"a:ll1\":[]}";
193 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
194 assert_null(tree);
195
Radek Krejci1798aae2020-07-14 13:26:06 +0200196 /* simple metadata */
Radek Krejci5536d282020-08-04 23:27:44 +0200197 data = "{\"a:ll1\":[10,11],\"@a:ll1\":[null,{\"a:hint\":2}]}";
Radek Iša56ca9e42020-09-08 18:42:00 +0200198 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
Radek Krejci1798aae2020-07-14 13:26:06 +0200199 assert_non_null(tree);
Michal Vasko26123192020-11-09 21:02:34 +0100200 tree = tree->next;
Radek Iša56ca9e42020-09-08 18:42:00 +0200201 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "ll1",
202 1, LYS_LEAFLIST, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100203 ll = (struct lyd_node_term *)tree;
Radek Iša56ca9e42020-09-08 18:42:00 +0200204 CHECK_LYD_VALUE(ll->value, UINT8, "10", 10);
Radek Krejci1798aae2020-07-14 13:26:06 +0200205 assert_null(ll->meta);
206
207 assert_non_null(tree->next);
Radek Iša56ca9e42020-09-08 18:42:00 +0200208 CHECK_LYSC_NODE(tree->next->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "ll1",
209 1, LYS_LEAFLIST, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100210 ll = (struct lyd_node_term *)tree->next;
Radek Iša56ca9e42020-09-08 18:42:00 +0200211 CHECK_LYD_VALUE(ll->value, UINT8, "11", 11);
212 CHECK_LYD_META(ll->meta, 1, "hint", 0, 1, INT8, "2", 2);
Radek Krejci1798aae2020-07-14 13:26:06 +0200213 assert_null(ll->meta->next);
214
Radek Iša56ca9e42020-09-08 18:42:00 +0200215 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200216 lyd_free_all(tree);
217
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100218 /* multiple meatadata hint and unknown metadata xxx supposed to be skipped since it is from missing schema */
Radek Iša56ca9e42020-09-08 18:42:00 +0200219 data = "{\"@a:ll1\" : [{\"a:hint\" : 1, \"x:xxx\" : { \"value\" : \"/x:no/x:yes\" }, "
220 "\"a:hint\" : 10},null,{\"a:hint\" : 3}], \"a:ll1\" : [1,2,3]}";
221 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
Radek Krejci1798aae2020-07-14 13:26:06 +0200222 assert_non_null(tree);
Michal Vasko26123192020-11-09 21:02:34 +0100223 tree = tree->next;
Radek Iša56ca9e42020-09-08 18:42:00 +0200224 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "ll1",
225 1, LYS_LEAFLIST, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100226 ll = (struct lyd_node_term *)tree;
Radek Iša56ca9e42020-09-08 18:42:00 +0200227 CHECK_LYD_VALUE(ll->value, UINT8, "1", 1);
228 CHECK_LYD_META(ll->meta, 1, "hint", 1, 1, INT8, "1", 1);
229 CHECK_LYD_META(ll->meta->next, 1, "hint", 0, 1, INT8, "10", 10);
Radek Krejci1798aae2020-07-14 13:26:06 +0200230
231 assert_non_null(tree->next);
Radek Iša56ca9e42020-09-08 18:42:00 +0200232 CHECK_LYSC_NODE(tree->next->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "ll1",
233 1, LYS_LEAFLIST, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100234 ll = (struct lyd_node_term *)tree->next;
Radek Iša56ca9e42020-09-08 18:42:00 +0200235 CHECK_LYD_VALUE(ll->value, UINT8, "2", 2);
Radek Krejci1798aae2020-07-14 13:26:06 +0200236 assert_null(ll->meta);
237
238 assert_non_null(tree->next->next);
Radek Iša56ca9e42020-09-08 18:42:00 +0200239 CHECK_LYSC_NODE(tree->next->next->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "ll1",
240 1, LYS_LEAFLIST, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100241 ll = (struct lyd_node_term *)tree->next->next;
Radek Iša56ca9e42020-09-08 18:42:00 +0200242 CHECK_LYD_VALUE(ll->value, UINT8, "3", 3);
243 CHECK_LYD_META(ll->meta, 1, "hint", 0, 1, INT8, "3", 3);
Radek Krejci1798aae2020-07-14 13:26:06 +0200244 assert_null(ll->meta->next);
245
Radek Iša56ca9e42020-09-08 18:42:00 +0200246 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS,
247 "{\"a:ll1\":[1,2,3],\"@a:ll1\":[{\"a:hint\":1,\"a:hint\":10},null,{\"a:hint\":3}]}");
Radek Krejci1798aae2020-07-14 13:26:06 +0200248 lyd_free_all(tree);
249
250 /* missing referenced metadata node */
Radek Iša56ca9e42020-09-08 18:42:00 +0200251 PARSER_CHECK_ERROR("{\"@a:ll1\":[{\"a:hint\":1}]}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vasko959f8d82022-06-16 07:51:50 +0200252 "Missing JSON data instance to be coupled with @a:ll1 metadata.", "Data location \"/@a:ll1\", line number 1.");
Radek Krejci1798aae2020-07-14 13:26:06 +0200253
Radek Iša56ca9e42020-09-08 18:42:00 +0200254 PARSER_CHECK_ERROR("{\"a:ll1\":[1],\"@a:ll1\":[{\"a:hint\":1},{\"a:hint\":2}]}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vasko959f8d82022-06-16 07:51:50 +0200255 "Missing JSON data instance #2 of a:ll1 to be coupled with metadata.", "Schema location \"/a:ll1\", line number 1.");
Radek Krejci1798aae2020-07-14 13:26:06 +0200256
Radek Iša56ca9e42020-09-08 18:42:00 +0200257 PARSER_CHECK_ERROR("{\"@a:ll1\":[{\"a:hint\":1},{\"a:hint\":2},{\"a:hint\":3}],\"a:ll1\" : [1, 2]}", 0, LYD_VALIDATE_PRESENT,
Michal Vasko959f8d82022-06-16 07:51:50 +0200258 tree, LY_EVALID, "Missing JSON data instance #3 to be coupled with @a:ll1 metadata.",
259 "Data location \"/@a:ll1\", line number 1.");
Radek Krejci1798aae2020-07-14 13:26:06 +0200260}
261
262static void
263test_anydata(void **state)
264{
Radek Krejci1798aae2020-07-14 13:26:06 +0200265 const char *data;
Radek Krejci1798aae2020-07-14 13:26:06 +0200266 struct lyd_node *tree;
267
Radek Krejci1798aae2020-07-14 13:26:06 +0200268 data = "{\"a:any\":{\"x:element1\":{\"element2\":\"/a:some/a:path\",\"list\":[{},{\"key\":\"a\"}]}}}";
Radek Iša56ca9e42020-09-08 18:42:00 +0200269 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
Radek Krejci1798aae2020-07-14 13:26:06 +0200270 assert_non_null(tree);
Michal Vasko26123192020-11-09 21:02:34 +0100271 tree = tree->next;
Michal Vasko76096ec2022-02-24 16:06:16 +0100272 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_STATUS_CURR | LYS_CONFIG_R | LYS_SET_CONFIG, 1, "any",
Radek Iša56ca9e42020-09-08 18:42:00 +0200273 1, LYS_ANYDATA, 0, 0, NULL, 0);
274 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200275 lyd_free_all(tree);
Michal Vaskofbc4a252022-02-03 13:15:58 +0100276
277 data = "{\"a:any\":{}}";
278 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
279 assert_non_null(tree);
280 tree = tree->next;
Michal Vasko76096ec2022-02-24 16:06:16 +0100281 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_STATUS_CURR | LYS_CONFIG_R | LYS_SET_CONFIG, 1, "any",
Michal Vaskofbc4a252022-02-03 13:15:58 +0100282 1, LYS_ANYDATA, 0, 0, NULL, 0);
283 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
284 lyd_free_all(tree);
Michal Vasko76096ec2022-02-24 16:06:16 +0100285
Michal Vaskoe3ed7dc2022-11-30 11:39:44 +0100286 data = "{\"a:any\":{\"node\":20}}";
Michal Vasko76096ec2022-02-24 16:06:16 +0100287 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
288 assert_non_null(tree);
289 tree = tree->next;
290 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_STATUS_CURR | LYS_CONFIG_R | LYS_SET_CONFIG, 1, "any",
291 1, LYS_ANYDATA, 0, 0, NULL, 0);
292 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
293 lyd_free_all(tree);
294}
295
296static void
297test_anyxml(void **state)
298{
299 const char *data;
300 struct lyd_node *tree;
301
302 data = "{\"a:axml\":\"some-value in string\"}";
303 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
304 assert_non_null(tree);
305 tree = tree->next;
306 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_STATUS_CURR | LYS_CONFIG_W, 1, "axml", 1, LYS_ANYXML, 0, 0, NULL, 0);
307 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
308 lyd_free_all(tree);
309
310 data = "{\"a:axml\":\"\"}";
311 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
312 assert_non_null(tree);
313 tree = tree->next;
314 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_STATUS_CURR | LYS_CONFIG_W, 1, "axml", 1, LYS_ANYXML, 0, 0, NULL, 0);
315 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
316 lyd_free_all(tree);
317
318 data = "{\"a:axml\":55}";
319 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
320 assert_non_null(tree);
321 tree = tree->next;
322 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_STATUS_CURR | LYS_CONFIG_W, 1, "axml", 1, LYS_ANYXML, 0, 0, NULL, 0);
323 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
324 lyd_free_all(tree);
325
326 data = "{\"a:axml\":false}";
327 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
328 assert_non_null(tree);
329 tree = tree->next;
330 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_STATUS_CURR | LYS_CONFIG_W, 1, "axml", 1, LYS_ANYXML, 0, 0, NULL, 0);
331 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
332 lyd_free_all(tree);
333
334 data = "{\"a:axml\":null}";
335 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
336 assert_non_null(tree);
337 tree = tree->next;
338 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_STATUS_CURR | LYS_CONFIG_W, 1, "axml", 1, LYS_ANYXML, 0, 0, NULL, 0);
339 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
340 lyd_free_all(tree);
341
342 data = "{\"a:axml\":[null,true,false]}";
343 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
344 assert_non_null(tree);
345 tree = tree->next;
346 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_STATUS_CURR | LYS_CONFIG_W, 1, "axml", 1, LYS_ANYXML, 0, 0, NULL, 0);
347 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
348 lyd_free_all(tree);
349
350 data = "{\"a:axml\":[null,true,{\"name\":[25,40, false]}]}";
351 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
352 assert_non_null(tree);
353 tree = tree->next;
354 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_STATUS_CURR | LYS_CONFIG_W, 1, "axml", 1, LYS_ANYXML, 0, 0, NULL, 0);
355 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
356 lyd_free_all(tree);
357
358 /* same as anydata tests */
359 data = "{\"a:axml\":{\"x:element1\":{\"element2\":\"/a:some/a:path\",\"list\":[{},{\"key\":\"a\"}]}}}";
360 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
361 assert_non_null(tree);
362 tree = tree->next;
363 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_STATUS_CURR | LYS_CONFIG_W, 1, "axml", 1, LYS_ANYXML, 0, 0, NULL, 0);
364 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
365 lyd_free_all(tree);
366
367 data = "{\"a:axml\":{}}";
368 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
369 assert_non_null(tree);
370 tree = tree->next;
371 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_STATUS_CURR | LYS_CONFIG_W, 1, "axml", 1, LYS_ANYXML, 0, 0, NULL, 0);
372 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
373 lyd_free_all(tree);
Radek Krejci1798aae2020-07-14 13:26:06 +0200374}
375
376static void
377test_list(void **state)
378{
Radek Iša56ca9e42020-09-08 18:42:00 +0200379 const char *data;
Radek Krejci1798aae2020-07-14 13:26:06 +0200380 struct lyd_node *tree, *iter;
381 struct lyd_node_inner *list;
382 struct lyd_node_term *leaf;
383
384 /* check hashes */
Radek Iša56ca9e42020-09-08 18:42:00 +0200385 data = "{\"a:l1\":[{\"a\":\"one\",\"b\":\"one\",\"c\":1}]}";
386 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
387 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1",
388 1, LYS_LIST, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100389 list = (struct lyd_node_inner *)tree;
Radek Krejci1798aae2020-07-14 13:26:06 +0200390 LY_LIST_FOR(list->child, iter) {
391 assert_int_not_equal(0, iter->hash);
392 }
Radek Iša56ca9e42020-09-08 18:42:00 +0200393 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200394 lyd_free_all(tree);
395
Michal Vasko4e26adc2022-03-30 11:01:16 +0200396 /* accept empty */
397 data = "{\"a:l1\":[]}";
398 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
399 assert_null(tree);
400
Radek Krejci1798aae2020-07-14 13:26:06 +0200401 /* missing keys */
Radek Iša56ca9e42020-09-08 18:42:00 +0200402 PARSER_CHECK_ERROR("{ \"a:l1\": [ {\"c\" : 1, \"b\" : \"b\"}]}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vasko959f8d82022-06-16 07:51:50 +0200403 "List instance is missing its key \"a\".",
Michal Vaskodbf3e652022-10-21 08:46:25 +0200404 "Data location \"/a:l1[b='b'][c='1']\", line number 1.");
Radek Krejci1798aae2020-07-14 13:26:06 +0200405
Radek Iša56ca9e42020-09-08 18:42:00 +0200406 PARSER_CHECK_ERROR("{ \"a:l1\": [ {\"a\" : \"a\"}]}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vaskodbf3e652022-10-21 08:46:25 +0200407 "List instance is missing its key \"b\".", "Data location \"/a:l1[a='a']\", line number 1.");
Radek Krejci1798aae2020-07-14 13:26:06 +0200408
Radek Iša56ca9e42020-09-08 18:42:00 +0200409 PARSER_CHECK_ERROR("{ \"a:l1\": [ {\"b\" : \"b\", \"a\" : \"a\"}]}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vaskodbf3e652022-10-21 08:46:25 +0200410 "List instance is missing its key \"c\".", "Data location \"/a:l1[a='a'][b='b']\", line number 1.");
Radek Krejci1798aae2020-07-14 13:26:06 +0200411
412 /* key duplicate */
Radek Iša56ca9e42020-09-08 18:42:00 +0200413 PARSER_CHECK_ERROR("{ \"a:l1\": [ {\"c\" : 1, \"b\" : \"b\", \"a\" : \"a\", \"c\" : 1}]}", 0, LYD_VALIDATE_PRESENT,
Michal Vasko959f8d82022-06-16 07:51:50 +0200414 tree, LY_EVALID, "Duplicate instance of \"c\".",
Michal Vaskodbf3e652022-10-21 08:46:25 +0200415 "Data location \"/a:l1[a='a'][b='b'][c='1'][c='1']/c\", line number 1.");
Radek Krejci1798aae2020-07-14 13:26:06 +0200416
417 /* keys order, in contrast to XML, JSON accepts keys in any order even in strict mode */
Radek Iša56ca9e42020-09-08 18:42:00 +0200418 CHECK_PARSE_LYD("{ \"a:l1\": [ {\"d\" : \"d\", \"a\" : \"a\", \"c\" : 1, \"b\" : \"b\"}]}", 0, LYD_VALIDATE_PRESENT, tree);
419 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1",
420 1, LYS_LIST, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100421 list = (struct lyd_node_inner *)tree;
422 assert_non_null(leaf = (struct lyd_node_term *)list->child);
Radek Iša56ca9e42020-09-08 18:42:00 +0200423 CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "a", 1, LYS_LEAF, 1, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100424 assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
Radek Iša56ca9e42020-09-08 18:42:00 +0200425 CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "b", 1, LYS_LEAF, 1, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100426 assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
Radek Iša56ca9e42020-09-08 18:42:00 +0200427 CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "c", 1, LYS_LEAF, 1, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100428 assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
Michal Vaskodbf3e652022-10-21 08:46:25 +0200429 CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "d", 1, LYS_LEAF, 1, 0, NULL, 0);
Radek Iša56ca9e42020-09-08 18:42:00 +0200430 CHECK_LOG_CTX(NULL, NULL);
Radek Iša56ca9e42020-09-08 18:42:00 +0200431 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS,
432 "{\"a:l1\":[{\"a\":\"a\",\"b\":\"b\",\"c\":1,\"d\":\"d\"}]}");
Radek Krejci1798aae2020-07-14 13:26:06 +0200433 lyd_free_all(tree);
434
Radek Iša56ca9e42020-09-08 18:42:00 +0200435 CHECK_PARSE_LYD("{\"a:l1\":[{\"c\":1,\"b\":\"b\",\"a\":\"a\"}]}", LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, tree);
436 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1",
437 1, LYS_LIST, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100438 list = (struct lyd_node_inner *)tree;
439 assert_non_null(leaf = (struct lyd_node_term *)list->child);
Radek Iša56ca9e42020-09-08 18:42:00 +0200440 CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "a",
441 1, LYS_LEAF, 1, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100442 assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
Radek Iša56ca9e42020-09-08 18:42:00 +0200443 CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "b",
444 1, LYS_LEAF, 1, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100445 assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
Radek Iša56ca9e42020-09-08 18:42:00 +0200446 CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "c",
447 1, LYS_LEAF, 1, 0, NULL, 0);
448 CHECK_LOG_CTX(NULL, NULL);
Radek Iša56ca9e42020-09-08 18:42:00 +0200449 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS,
450 "{\"a:l1\":[{\"a\":\"a\",\"b\":\"b\",\"c\":1}]}");
Radek Krejci1798aae2020-07-14 13:26:06 +0200451 lyd_free_all(tree);
452
Michal Vasko87c5d6b2023-02-14 15:27:41 +0100453 /* skip unknown nested nodes */
454 data = "{\"a:l1\":[{\"a\":\"val_a\",\"b\":\"val_b\",\"c\":3,\"counters\":{\"count1\":\"c1\",\"count2\":\"c2\"}}]}";
455 CHECK_PARSE_LYD(data, LYD_PARSE_ONLY, 0, tree);
456 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, "{\"a:l1\":[{\"a\":\"val_a\",\"b\":\"val_b\",\"c\":3}]}");
457 lyd_free_all(tree);
458
Radek Krejci5536d282020-08-04 23:27:44 +0200459 data = "{\"a:cp\":{\"@\":{\"a:hint\":1}}}";
Radek Iša56ca9e42020-09-08 18:42:00 +0200460 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
Radek Krejci1798aae2020-07-14 13:26:06 +0200461 assert_non_null(tree);
Michal Vasko26123192020-11-09 21:02:34 +0100462 tree = tree->next;
Michal Vaskoe16c7b72021-02-26 10:39:06 +0100463 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp",
Radek Iša56ca9e42020-09-08 18:42:00 +0200464 1, LYS_CONTAINER, 0, 0, NULL, 0);
465 CHECK_LYD_META(tree->meta, 1, "hint", 0, 1, INT8, "1", 1);
Radek Krejci1798aae2020-07-14 13:26:06 +0200466 assert_null(tree->meta->next);
Radek Iša56ca9e42020-09-08 18:42:00 +0200467 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200468 lyd_free_all(tree);
Radek Krejci1798aae2020-07-14 13:26:06 +0200469}
470
471static void
472test_container(void **state)
473{
Radek Iša56ca9e42020-09-08 18:42:00 +0200474 const char *data;
Radek Krejci1798aae2020-07-14 13:26:06 +0200475 struct lyd_node *tree;
476 struct lyd_node_inner *cont;
477
Radek Iša56ca9e42020-09-08 18:42:00 +0200478 CHECK_PARSE_LYD("{\"a:c\":{}}", 0, LYD_VALIDATE_PRESENT, tree);
479 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c",
480 1, LYS_CONTAINER, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100481 cont = (struct lyd_node_inner *)tree;
Radek Krejci1798aae2020-07-14 13:26:06 +0200482 assert_true(cont->flags & LYD_DEFAULT);
Radek Krejci5536d282020-08-04 23:27:44 +0200483
Radek Iša56ca9e42020-09-08 18:42:00 +0200484 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, "{}");
Radek Krejci1798aae2020-07-14 13:26:06 +0200485 lyd_free_all(tree);
486
Radek Krejci5536d282020-08-04 23:27:44 +0200487 data = "{\"a:cp\":{}}";
Radek Iša56ca9e42020-09-08 18:42:00 +0200488 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
Radek Krejci1798aae2020-07-14 13:26:06 +0200489 assert_non_null(tree);
Michal Vasko26123192020-11-09 21:02:34 +0100490 tree = tree->next;
Michal Vaskoe16c7b72021-02-26 10:39:06 +0100491 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp",
Radek Iša56ca9e42020-09-08 18:42:00 +0200492 1, LYS_CONTAINER, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100493 cont = (struct lyd_node_inner *)tree;
Radek Krejci1798aae2020-07-14 13:26:06 +0200494 assert_false(cont->flags & LYD_DEFAULT);
Radek Krejci5536d282020-08-04 23:27:44 +0200495
Radek Iša56ca9e42020-09-08 18:42:00 +0200496 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200497 lyd_free_all(tree);
Michal Vaskoa4af6252022-05-20 10:38:54 +0200498
499 /* skip container */
500 CHECK_PARSE_LYD("{\"a:unknown\":{\"a\":\"val\",\"b\":5}}", 0, LYD_VALIDATE_PRESENT, tree);
501 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, "{}");
502 lyd_free_all(tree);
Radek Krejci1798aae2020-07-14 13:26:06 +0200503}
504
505static void
506test_opaq(void **state)
507{
Radek Krejci1798aae2020-07-14 13:26:06 +0200508 const char *data;
Radek Krejci1798aae2020-07-14 13:26:06 +0200509 struct lyd_node *tree;
510
Radek Krejci1798aae2020-07-14 13:26:06 +0200511 /* invalid value, no flags */
512 data = "{\"a:foo3\":[null]}";
Radek Iša56ca9e42020-09-08 18:42:00 +0200513 PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vasko959f8d82022-06-16 07:51:50 +0200514 "Invalid non-number-encoded uint32 value \"\".", "Schema location \"/a:foo3\", line number 1.");
Radek Krejci1798aae2020-07-14 13:26:06 +0200515
516 /* opaq flag */
Michal Vasko1a85d332021-08-27 10:35:28 +0200517 CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree);
Radek Krejci8df109d2021-04-23 12:19:08 +0200518 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0, LY_VALUE_JSON, "foo3", 0, 0, NULL, 0, "");
Radek Iša56ca9e42020-09-08 18:42:00 +0200519 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200520 lyd_free_all(tree);
521
522 /* missing key, no flags */
523 data = "{\"a:l1\":[{\"a\":\"val_a\",\"b\":\"val_b\",\"d\":\"val_d\"}]}";
Radek Iša56ca9e42020-09-08 18:42:00 +0200524 PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vasko959f8d82022-06-16 07:51:50 +0200525 "List instance is missing its key \"c\".",
Michal Vaskodbf3e652022-10-21 08:46:25 +0200526 "Data location \"/a:l1[a='val_a'][b='val_b']\", line number 1.");
Radek Krejci1798aae2020-07-14 13:26:06 +0200527
528 /* opaq flag */
Michal Vasko1a85d332021-08-27 10:35:28 +0200529 CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree);
Radek Krejci8df109d2021-04-23 12:19:08 +0200530 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_VALUE_JSON, "l1", 0, 0, NULL, 0, "");
Radek Iša56ca9e42020-09-08 18:42:00 +0200531 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200532 lyd_free_all(tree);
533
534 /* invalid key, no flags */
535 data = "{\"a:l1\":[{\"a\":\"val_a\",\"b\":\"val_b\",\"c\":\"val_c\"}]}";
Radek Iša56ca9e42020-09-08 18:42:00 +0200536 PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vasko959f8d82022-06-16 07:51:50 +0200537 "Invalid non-number-encoded int16 value \"val_c\".",
Michal Vaskoa4dfb3c2022-10-25 14:59:31 +0200538 "Data location \"/a:l1[a='val_a'][b='val_b']/c\", line number 1.");
Radek Krejci1798aae2020-07-14 13:26:06 +0200539
540 /* opaq flag */
Michal Vasko1a85d332021-08-27 10:35:28 +0200541 CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree);
Radek Krejci8df109d2021-04-23 12:19:08 +0200542 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_VALUE_JSON, "l1", 0, 0, NULL, 0, "");
Radek Iša56ca9e42020-09-08 18:42:00 +0200543 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200544 lyd_free_all(tree);
545
546 data = "{\"a:l1\":[{\"a\":\"val_a\",\"b\":\"val_b\",\"c\":{\"val\":\"val_c\"}}]}";
Michal Vasko1a85d332021-08-27 10:35:28 +0200547 CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree);
Radek Krejci8df109d2021-04-23 12:19:08 +0200548 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_VALUE_JSON, "l1", 0, 0, NULL, 0, "");
Radek Iša56ca9e42020-09-08 18:42:00 +0200549 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200550 lyd_free_all(tree);
551
552 data = "{\"a:l1\":[{\"a\":\"val_a\",\"b\":\"val_b\"}]}";
Michal Vasko1a85d332021-08-27 10:35:28 +0200553 CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree);
Radek Krejci8df109d2021-04-23 12:19:08 +0200554 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_VALUE_JSON, "l1", 0, 0, NULL, 0, "");
Radek Iša56ca9e42020-09-08 18:42:00 +0200555 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200556 lyd_free_all(tree);
aPiecekb7b29e62021-05-11 10:02:43 +0200557
Michal Vasko6a6e3082022-05-10 10:32:38 +0200558 /* invalid metadata */
aPiecekc5f36a72021-05-18 14:12:31 +0200559 data = "{\"@a:foo\":\"str\",\"@a:foo3\":1,\"a:foo3\":2}";
Michal Vasko6a6e3082022-05-10 10:32:38 +0200560 PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vasko6727c682023-02-17 10:40:26 +0100561 "Unknown module of node \"@a:foo\".", "Path \"/\".");
Michal Vasko62af3692023-02-09 14:00:09 +0100562 CHECK_LOG_CTX("Missing JSON data instance to be coupled with @a:foo metadata.", "Data location \"/@a:foo\", line number 1.");
aPiecekc5f36a72021-05-18 14:12:31 +0200563
aPiecekb7b29e62021-05-11 10:02:43 +0200564 /* empty name */
565 PARSER_CHECK_ERROR("{\"@a:foo\":{\"\":0}}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vaskobfebf662023-02-17 09:07:22 +0100566 "JSON object member name cannot be a zero-length string.", "Line number 1.");
Michal Vasko1a85d332021-08-27 10:35:28 +0200567
568 /* opaque data tree format print */
569 data =
570 "{\n"
571 " \"ietf-netconf-nmda:get-data\": {\n"
572 " \"data\": {\n"
573 " \"ietf-keystore:keystore\": {\n"
574 " \"asymmetric-keys\": {\n"
575 " \"asymmetric-key\": [\n"
576 " {\n"
577 " \"name\": \"genkey\",\n"
578 " \"algorithm\": \"rsa2048\"\n"
579 " }\n"
580 " ]\n"
581 " }\n"
582 " },\n"
583 " \"ietf-netconf-server:netconf-server\": {\n"
584 " \"listen\": {\n"
585 " \"idle-timeout\": 3600,\n"
586 " \"endpoint\": [\n"
587 " {\n"
588 " \"name\": \"default-ssh\",\n"
589 " \"ssh\": {\n"
590 " \"tcp-server-parameters\": {\n"
591 " \"local-address\": \"0.0.0.0\",\n"
592 " \"local-port\": 830\n"
593 " },\n"
594 " \"ssh-server-parameters\": {\n"
595 " \"server-identity\": {\n"
596 " \"host-key\": [\n"
597 " {\n"
598 " \"name\": \"default-key\",\n"
599 " \"public-key\": {\n"
600 " \"keystore-reference\": \"genkey\"\n"
601 " }\n"
602 " }\n"
603 " ]\n"
604 " },\n"
605 " \"client-authentication\": {\n"
606 " \"supported-authentication-methods\": {\n"
607 " \"publickey\": [null],\n"
608 " \"passsword\": [null],\n"
609 " \"other\": [\n"
610 " \"interactive\",\n"
611 " \"gssapi\"\n"
612 " ]\n"
613 " }\n"
614 " }\n"
615 " }\n"
616 " }\n"
617 " }\n"
618 " ]\n"
619 " }\n"
620 " }\n"
621 " }\n"
622 " }\n"
623 "}\n";
624 CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree);
625 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
626 lyd_free_all(tree);
Radek Krejci1798aae2020-07-14 13:26:06 +0200627}
628
629static void
630test_rpc(void **state)
631{
Radek Krejci1798aae2020-07-14 13:26:06 +0200632 const char *data;
633 struct ly_in *in;
Radek Krejci1798aae2020-07-14 13:26:06 +0200634 struct lyd_node *tree, *op;
635 const struct lyd_node *node;
Michal Vaskobbdadda2022-01-06 11:40:10 +0100636 const char *dsc = "Edit data in an NMDA datastore.\n"
637 "\n"
638 "If an error condition occurs such that an error severity\n"
639 "<rpc-error> element is generated, the server will stop\n"
640 "processing the <edit-data> operation and restore the\n"
641 "specified configuration to its complete state at\n"
642 "the start of this <edit-data> operation.";
Radek Krejci1798aae2020-07-14 13:26:06 +0200643
Michal Vaskobbdadda2022-01-06 11:40:10 +0100644 assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf-nmda", "2019-01-07", NULL)));
Radek Krejci1798aae2020-07-14 13:26:06 +0200645
Michal Vaskobbdadda2022-01-06 11:40:10 +0100646 data = "{\"ietf-netconf-nmda:edit-data\":{"
647 "\"datastore\":\"ietf-datastores:running\","
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100648 "\"config\":{\"a:cp\":{\"z\":[null],\"@z\":{\"ietf-netconf:operation\":\"replace\"}},"
649 "\"a:l1\":[{\"@\":{\"ietf-netconf:operation\":\"replace\"},\"a\":\"val_a\",\"b\":\"val_b\",\"c\":\"val_c\"}]}"
Michal Vasko2552ea32020-12-08 15:32:34 +0100650 "}}";
Radek Krejci1798aae2020-07-14 13:26:06 +0200651 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100652 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_JSON, LYD_TYPE_RPC_YANG, &tree, &op));
Radek Krejci1798aae2020-07-14 13:26:06 +0200653 ly_in_free(in, 0);
654
655 assert_non_null(op);
Radek Krejci1798aae2020-07-14 13:26:06 +0200656
Radek Krejci2a9fc652021-01-22 17:44:34 +0100657 CHECK_LYSC_ACTION((struct lysc_node_action *)op->schema, dsc, 0, LYS_STATUS_CURR,
Michal Vaskobbdadda2022-01-06 11:40:10 +0100658 1, 0, 0, 1, "edit-data", LYS_RPC,
659 0, 0, 0, 0, 0, NULL, 0);
Radek Iša56ca9e42020-09-08 18:42:00 +0200660
Michal Vasko2552ea32020-12-08 15:32:34 +0100661 node = tree;
Radek Krejci2a9fc652021-01-22 17:44:34 +0100662 CHECK_LYSC_ACTION((struct lysc_node_action *)node->schema, dsc, 0, LYS_STATUS_CURR,
Michal Vaskobbdadda2022-01-06 11:40:10 +0100663 1, 0, 0, 1, "edit-data", LYS_RPC,
664 0, 0, 0, 0, 0, NULL, 0);
Radek Krejcia1c1e542020-09-29 16:06:52 +0200665 node = lyd_child(node)->next;
Michal Vaskobbdadda2022-01-06 11:40:10 +0100666 CHECK_LYSC_NODE(node->schema, "Inline config content.", 0, LYS_STATUS_CURR | LYS_IS_INPUT, 1, "config",
667 0, LYS_ANYDATA, 1, 0, NULL, 0);
Radek Krejci1798aae2020-07-14 13:26:06 +0200668
669 node = ((struct lyd_node_any *)node)->value.tree;
Michal Vaskoe16c7b72021-02-26 10:39:06 +0100670 CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp",
Radek Iša56ca9e42020-09-08 18:42:00 +0200671 1, LYS_CONTAINER, 0, 0, NULL, 0);
Radek Krejcia1c1e542020-09-29 16:06:52 +0200672 node = lyd_child(node);
Radek Krejci1798aae2020-07-14 13:26:06 +0200673 /* z has no value */
Radek Krejci8df109d2021-04-23 12:19:08 +0200674 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0, LY_VALUE_JSON, "z", 0, 0, NULL, 0, "");
Radek Krejci1798aae2020-07-14 13:26:06 +0200675 node = node->parent->next;
676 /* l1 key c has invalid value so it is at the end */
Radek Krejci8df109d2021-04-23 12:19:08 +0200677 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0x1, LY_VALUE_JSON, "l1", 0, 0, NULL, 0, "");
Radek Krejci1798aae2020-07-14 13:26:06 +0200678
Radek Iša56ca9e42020-09-08 18:42:00 +0200679 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200680 lyd_free_all(tree);
681
682 /* wrong namespace, element name, whatever... */
683 /* TODO */
Radek Krejci1798aae2020-07-14 13:26:06 +0200684}
685
686static void
687test_action(void **state)
688{
Radek Krejci1798aae2020-07-14 13:26:06 +0200689 const char *data;
690 struct ly_in *in;
Radek Krejci1798aae2020-07-14 13:26:06 +0200691 struct lyd_node *tree, *op;
Radek Krejci1798aae2020-07-14 13:26:06 +0200692
Michal Vasko2552ea32020-12-08 15:32:34 +0100693 data = "{\"a:c\":{\"act\":{\"al\":\"value\"}}}";
Radek Krejci1798aae2020-07-14 13:26:06 +0200694 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100695 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_JSON, LYD_TYPE_RPC_YANG, &tree, &op));
Radek Krejci1798aae2020-07-14 13:26:06 +0200696 ly_in_free(in, 0);
697
698 assert_non_null(op);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100699 CHECK_LYSC_ACTION((struct lysc_node_action *)op->schema, NULL, 0, LYS_STATUS_CURR,
Radek Iša56ca9e42020-09-08 18:42:00 +0200700 1, 0, 0, 1, "act", LYS_ACTION,
701 1, 0, 0, 1, 0, NULL, 0);
Radek Krejci1798aae2020-07-14 13:26:06 +0200702
Radek Iša56ca9e42020-09-08 18:42:00 +0200703 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200704 lyd_free_all(tree);
705
706 /* wrong namespace, element name, whatever... */
707 /* TODO */
Radek Krejci1798aae2020-07-14 13:26:06 +0200708}
709
710static void
711test_notification(void **state)
712{
Radek Krejci1798aae2020-07-14 13:26:06 +0200713 const char *data;
714 struct ly_in *in;
Radek Krejci1798aae2020-07-14 13:26:06 +0200715 struct lyd_node *tree, *ntf;
Radek Krejci1798aae2020-07-14 13:26:06 +0200716
Michal Vasko2552ea32020-12-08 15:32:34 +0100717 data = "{\"a:c\":{\"n1\":{\"nl\":\"value\"}}}";
Radek Krejci1798aae2020-07-14 13:26:06 +0200718 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100719 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_JSON, LYD_TYPE_NOTIF_YANG, &tree, &ntf));
Radek Krejci1798aae2020-07-14 13:26:06 +0200720 ly_in_free(in, 0);
721
722 assert_non_null(ntf);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100723 CHECK_LYSC_NOTIF((struct lysc_node_notif *)ntf->schema, 1, NULL, 0, 0x4, 1, 0, "n1", 1, 0, NULL, 0);
Radek Krejci1798aae2020-07-14 13:26:06 +0200724
Michal Vasko2552ea32020-12-08 15:32:34 +0100725 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c", 1, LYS_CONTAINER, 0, 0, NULL, 0);
Radek Krejci1798aae2020-07-14 13:26:06 +0200726
Radek Iša56ca9e42020-09-08 18:42:00 +0200727 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200728 lyd_free_all(tree);
729
Radek Krejci1798aae2020-07-14 13:26:06 +0200730 data = "{\"a:n2\":{}}";
731 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100732 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_JSON, LYD_TYPE_NOTIF_YANG, &tree, &ntf));
Radek Krejci1798aae2020-07-14 13:26:06 +0200733 ly_in_free(in, 0);
734
735 assert_non_null(ntf);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100736 CHECK_LYSC_NOTIF((struct lysc_node_notif *)ntf->schema, 0, NULL, 0, 0x4, 1, 0, "n2", 0, 0, NULL, 0);
Radek Krejci1798aae2020-07-14 13:26:06 +0200737
738 assert_non_null(tree);
739 assert_ptr_equal(ntf, tree);
740
Radek Iša56ca9e42020-09-08 18:42:00 +0200741 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
Radek Krejci1798aae2020-07-14 13:26:06 +0200742 lyd_free_all(tree);
743
744 /* wrong namespace, element name, whatever... */
745 /* TODO */
Radek Krejci1798aae2020-07-14 13:26:06 +0200746}
747
748static void
749test_reply(void **state)
750{
Radek Krejci1798aae2020-07-14 13:26:06 +0200751 const char *data;
752 struct ly_in *in;
Michal Vasko2552ea32020-12-08 15:32:34 +0100753 struct lyd_node *tree, *op;
Radek Krejci1798aae2020-07-14 13:26:06 +0200754 const struct lyd_node *node;
755
Michal Vasko2552ea32020-12-08 15:32:34 +0100756 data = "{\"a:c\":{\"act\":{\"al\":25}}}";
Radek Krejci1798aae2020-07-14 13:26:06 +0200757 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100758 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_JSON, LYD_TYPE_REPLY_YANG, &tree, &op));
Radek Krejci1798aae2020-07-14 13:26:06 +0200759 ly_in_free(in, 0);
760
Radek Krejci1798aae2020-07-14 13:26:06 +0200761 assert_non_null(op);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100762 CHECK_LYSC_ACTION((struct lysc_node_action *)op->schema, NULL, 0, LYS_STATUS_CURR,
Radek Iša56ca9e42020-09-08 18:42:00 +0200763 1, 0, 0, 1, "act", LYS_ACTION,
764 1, 0, 0, 1, 0, NULL, 0);
Radek Krejcia1c1e542020-09-29 16:06:52 +0200765 node = lyd_child(op);
Michal Vaskod1e53b92021-01-28 13:11:06 +0100766 CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_STATUS_CURR | LYS_IS_OUTPUT, 1, "al", 0, LYS_LEAF, 1, 0, NULL, 0);
Radek Krejci1798aae2020-07-14 13:26:06 +0200767
Michal Vasko2552ea32020-12-08 15:32:34 +0100768 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c", 1, LYS_CONTAINER, 0, 0, NULL, 0);
Radek Krejci1798aae2020-07-14 13:26:06 +0200769
770 /* TODO print only rpc-reply node and then output subtree */
Radek Iša56ca9e42020-09-08 18:42:00 +0200771 CHECK_LYD_STRING(lyd_child(op), LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, "{\"a:al\":25}");
Michal Vasko2552ea32020-12-08 15:32:34 +0100772 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, "{\"a:c\":{\"act\":{\"al\":25}}}");
Radek Krejci1798aae2020-07-14 13:26:06 +0200773 lyd_free_all(tree);
774
775 /* wrong namespace, element name, whatever... */
776 /* TODO */
Radek Krejci1798aae2020-07-14 13:26:06 +0200777}
778
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100779int
780main(void)
Radek Krejci1798aae2020-07-14 13:26:06 +0200781{
782 const struct CMUnitTest tests[] = {
Radek Iša56ca9e42020-09-08 18:42:00 +0200783 UTEST(test_leaf, setup),
784 UTEST(test_leaflist, setup),
785 UTEST(test_anydata, setup),
Michal Vasko76096ec2022-02-24 16:06:16 +0100786 UTEST(test_anyxml, setup),
Radek Iša56ca9e42020-09-08 18:42:00 +0200787 UTEST(test_list, setup),
788 UTEST(test_container, setup),
789 UTEST(test_opaq, setup),
790 UTEST(test_rpc, setup),
791 UTEST(test_action, setup),
792 UTEST(test_notification, setup),
793 UTEST(test_reply, setup),
Radek Krejci1798aae2020-07-14 13:26:06 +0200794 };
795
796 return cmocka_run_group_tests(tests, NULL, NULL);
797}