blob: 889e5024fd5018657f6f7eceb7b38857af632f3e [file] [log] [blame]
Michal Vasko1b2a3f42022-12-20 09:38:28 +01001/**
Radek Krejci509e2592019-05-15 16:30:48 +02002 * @file test_parser_xml.c
Michal Vasko1b2a3f42022-12-20 09:38:28 +01003 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @author Michal Vasko <mvasko@cesnet.cz>
Radek Krejci509e2592019-05-15 16:30:48 +02005 * @brief unit tests for functions from parser_xml.c
6 *
Michal Vasko1b2a3f42022-12-20 09:38:28 +01007 * Copyright (c) 2019 - 2022 CESNET, z.s.p.o.
Radek Krejci509e2592019-05-15 16:30:48 +02008 *
9 * This source code is licensed under BSD 3-Clause License (the "License").
10 * You may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * https://opensource.org/licenses/BSD-3-Clause
14 */
Radek Iša56ca9e42020-09-08 18:42:00 +020015#define _UTEST_MAIN_
16#include "utests.h"
Radek Krejci509e2592019-05-15 16:30:48 +020017
Radek Krejci70593c12020-06-13 20:48:09 +020018#include "context.h"
Michal Vaskoafac7822020-10-20 14:22:26 +020019#include "in.h"
Michal Vaskoafac7822020-10-20 14:22:26 +020020#include "out.h"
Radek Krejcib4ac5a92020-11-23 17:54:33 +010021#include "parser_data.h"
Radek Krejci70593c12020-06-13 20:48:09 +020022#include "printer_data.h"
Radek Krejci70593c12020-06-13 20:48:09 +020023#include "tree_data_internal.h"
24#include "tree_schema.h"
Radek Krejci509e2592019-05-15 16:30:48 +020025
26static int
27setup(void **state)
28{
Radek Iša56ca9e42020-09-08 18:42:00 +020029 const char *schema =
Radek Krejcib4ac5a92020-11-23 17:54:33 +010030 "module a {\n"
31 " namespace urn:tests:a;\n"
32 " prefix a;\n"
33 " yang-version 1.1;\n"
Michal Vaskodbf3e652022-10-21 08:46:25 +020034 " list l1 { key \"a b c\"; leaf a {type string;} leaf b {type string;} leaf c {type int16;}"
35 " leaf d {type string;}"
36 " container cont {leaf e {type boolean;}}"
37 " }"
Radek Krejcib4ac5a92020-11-23 17:54:33 +010038 " leaf foo { type string;}\n"
39 " container c {\n"
40 " leaf x {type string;}\n"
41 " action act { input { leaf al {type string;} } output { leaf al {type uint8;} } }\n"
42 " notification n1 { leaf nl {type string;}}}\n"
43 " container cp {presence \"container switch\"; leaf y {type string;} leaf z {type int8;}}\n"
44 " anydata any {config false;}\n"
Michal Vasko5b414dd2023-04-13 10:29:58 +020045 " anyxml anyx;\n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +010046 " leaf foo2 { type string; default \"default-val\"; }\n"
47 " leaf foo3 { type uint32; }\n"
48 " notification n2;}";
Radek Krejci509e2592019-05-15 16:30:48 +020049
Radek Iša56ca9e42020-09-08 18:42:00 +020050 UTEST_SETUP;
Radek Krejci509e2592019-05-15 16:30:48 +020051
Radek Iša56ca9e42020-09-08 18:42:00 +020052 UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
53 assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
Radek Krejci509e2592019-05-15 16:30:48 +020054
55 return 0;
56}
57
Radek Iša56ca9e42020-09-08 18:42:00 +020058#define CHECK_PARSE_LYD(INPUT, PARSE_OPTION, VALIDATE_OPTION, TREE) \
59 CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, PARSE_OPTION, VALIDATE_OPTION, LY_SUCCESS, TREE)
Radek Krejci509e2592019-05-15 16:30:48 +020060
Radek Iša56ca9e42020-09-08 18:42:00 +020061#define PARSER_CHECK_ERROR(INPUT, PARSE_OPTION, VALIDATE_OPTION, MODEL, RET_VAL, ERR_MESSAGE, ERR_PATH) \
62 assert_int_equal(RET_VAL, lyd_parse_data_mem(UTEST_LYCTX, INPUT, LYD_XML, PARSE_OPTION, VALIDATE_OPTION, &MODEL));\
63 CHECK_LOG_CTX(ERR_MESSAGE, ERR_PATH);\
64 assert_null(MODEL)
Radek Krejci509e2592019-05-15 16:30:48 +020065
Radek Iša56ca9e42020-09-08 18:42:00 +020066#define CHECK_LYD_STRING(IN_MODEL, PRINT_OPTION, TEXT) \
67 CHECK_LYD_STRING_PARAM(IN_MODEL, TEXT, LYD_XML, PRINT_OPTION)
Radek Krejci509e2592019-05-15 16:30:48 +020068
Radek Krejci509e2592019-05-15 16:30:48 +020069static void
70test_leaf(void **state)
71{
Radek Krejci509e2592019-05-15 16:30:48 +020072 const char *data = "<foo xmlns=\"urn:tests:a\">foo value</foo>";
73 struct lyd_node *tree;
74 struct lyd_node_term *leaf;
75
Radek Iša56ca9e42020-09-08 18:42:00 +020076 assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf-with-defaults", "2011-06-01", NULL));
Radek Krejci509e2592019-05-15 16:30:48 +020077
Radek Iša56ca9e42020-09-08 18:42:00 +020078 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);
80 leaf = (struct lyd_node_term *)tree;
81 CHECK_LYD_VALUE(leaf->value, STRING, "foo value");
82
83 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 CHECK_LYD_VALUE(leaf->value, STRING, "default-val");
Michal Vasko8d544252020-03-02 10:19:52 +010087 assert_true(leaf->flags & LYD_DEFAULT);
Radek Krejci509e2592019-05-15 16:30:48 +020088 lyd_free_all(tree);
Michal Vasko8d544252020-03-02 10:19:52 +010089
90 /* make foo2 explicit */
91 data = "<foo2 xmlns=\"urn:tests:a\">default-val</foo2>";
Radek Iša56ca9e42020-09-08 18:42:00 +020092 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
Michal Vasko8d544252020-03-02 10:19:52 +010093 assert_non_null(tree);
Michal Vasko26123192020-11-09 21:02:34 +010094 tree = tree->next;
Radek Iša56ca9e42020-09-08 18:42:00 +020095 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2",
96 1, LYS_LEAF, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +010097 leaf = (struct lyd_node_term *)tree;
Radek Iša56ca9e42020-09-08 18:42:00 +020098 CHECK_LYD_VALUE(leaf->value, STRING, "default-val");
Michal Vasko8d544252020-03-02 10:19:52 +010099 assert_false(leaf->flags & LYD_DEFAULT);
Michal Vasko8d544252020-03-02 10:19:52 +0100100 lyd_free_all(tree);
101
Radek Krejci1798aae2020-07-14 13:26:06 +0200102 /* parse foo2 but make it implicit, skip metadata xxx from missing schema */
Radek Iša56ca9e42020-09-08 18:42:00 +0200103 data = "<foo2 xmlns=\"urn:tests:a\" xmlns:wd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" "
104 "wd:default=\"true\" xmlns:x=\"urn:x\" x:xxx=\"false\">default-val</foo2>";
105 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
Michal Vasko8d544252020-03-02 10:19:52 +0100106 assert_non_null(tree);
Michal Vasko26123192020-11-09 21:02:34 +0100107 tree = tree->next;
Radek Iša56ca9e42020-09-08 18:42:00 +0200108 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2",
109 1, LYS_LEAF, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100110 leaf = (struct lyd_node_term *)tree;
Radek Iša56ca9e42020-09-08 18:42:00 +0200111 CHECK_LYD_VALUE(leaf->value, STRING, "default-val");
Michal Vasko8d544252020-03-02 10:19:52 +0100112 assert_true(leaf->flags & LYD_DEFAULT);
Michal Vasko8d544252020-03-02 10:19:52 +0100113 lyd_free_all(tree);
Michal Vaskodbf3e652022-10-21 08:46:25 +0200114
115 /* invalid value */
116 data = "<l1 xmlns=\"urn:tests:a\"><a>val-a</a><b>val-b</b><c>1</c><cont><e>0</e></cont></l1>";
117 PARSER_CHECK_ERROR(data, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
118 "Invalid boolean value \"0\".",
119 "Data location \"/a:l1[a='val-a'][b='val-b'][c='1']/cont/e\", line number 1.");
Radek Krejci509e2592019-05-15 16:30:48 +0200120}
121
Radek Krejciee4cab22019-07-17 17:07:47 +0200122static void
123test_anydata(void **state)
124{
Michal Vasko52927e22020-03-16 17:26:14 +0100125 const char *data;
Michal Vasko5b414dd2023-04-13 10:29:58 +0200126 char *str;
Radek Krejciee4cab22019-07-17 17:07:47 +0200127 struct lyd_node *tree;
Radek Krejciee4cab22019-07-17 17:07:47 +0200128
Radek Iša56ca9e42020-09-08 18:42:00 +0200129 data = "<any xmlns=\"urn:tests:a\">\n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100130 " <element1>\n"
131 " <x:element2 x:attr2=\"test\" xmlns:a=\"urn:tests:a\" xmlns:x=\"urn:x\">a:data</x:element2>\n"
132 " </element1>\n"
133 " <element1a/>\n"
134 "</any>\n";
Radek Iša56ca9e42020-09-08 18:42:00 +0200135 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
Radek Krejciee4cab22019-07-17 17:07:47 +0200136 assert_non_null(tree);
Michal Vasko26123192020-11-09 21:02:34 +0100137 tree = tree->next;
Radek Iša56ca9e42020-09-08 18:42:00 +0200138 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_R | LYS_STATUS_CURR | LYS_SET_CONFIG, 1, "any",
139 1, LYS_ANYDATA, 0, 0, NULL, 0);
Michal Vaskodbf3e652022-10-21 08:46:25 +0200140
Radek Iša56ca9e42020-09-08 18:42:00 +0200141 const char *data_expected =
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100142 "<any xmlns=\"urn:tests:a\">\n"
143 " <element1>\n"
144 " <element2 xmlns=\"urn:x\" xmlns:x=\"urn:x\" x:attr2=\"test\" xmlns:a=\"urn:tests:a\">a:data</element2>\n"
145 " </element1>\n"
146 " <element1a/>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200147 "</any>\n";
148
149 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data_expected);
Michal Vasko5b414dd2023-04-13 10:29:58 +0200150
151 assert_int_equal(LY_SUCCESS, lyd_any_value_str(tree, &str));
152 lyd_free_all(tree);
153
154 assert_int_equal(LY_SUCCESS, lyd_new_path2(NULL, UTEST_LYCTX, "/a:any", str, strlen(str), LYD_ANYDATA_XML, 0, &tree, NULL));
155 free(str);
156 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data_expected);
157 lyd_free_all(tree);
158}
159
160static void
161test_anyxml(void **state)
162{
163 const char *data;
164 char *str;
165 struct lyd_node *tree;
166
167 data = "<anyx xmlns=\"urn:tests:a\">\n"
168 " <element1>\n"
169 " <element2 x:attr2=\"test\" xmlns:x=\"urn:x\">data</element2>\n"
170 " </element1>\n"
171 " <element1a/>\n"
172 "</anyx>\n";
173 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
174 assert_non_null(tree);
175 tree = tree->next;
176
177 const char *data_expected =
178 "<anyx xmlns=\"urn:tests:a\">\n"
179 " <element1>\n"
180 " <element2 xmlns:x=\"urn:x\" x:attr2=\"test\">data</element2>\n"
181 " </element1>\n"
182 " <element1a/>\n"
183 "</anyx>\n";
184
185 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data_expected);
186
187 assert_int_equal(LY_SUCCESS, lyd_any_value_str(tree, &str));
188 lyd_free_all(tree);
189
190 assert_int_equal(LY_SUCCESS, lyd_new_path2(NULL, UTEST_LYCTX, "/a:anyx", str, strlen(str), LYD_ANYDATA_XML, 0, &tree, NULL));
191 free(str);
192 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data_expected);
Radek Krejciee4cab22019-07-17 17:07:47 +0200193 lyd_free_all(tree);
Radek Krejciee4cab22019-07-17 17:07:47 +0200194}
195
Radek Krejci1f05b6a2019-07-18 16:15:06 +0200196static void
197test_list(void **state)
198{
Radek Iša56ca9e42020-09-08 18:42:00 +0200199 const char *data;
Radek Krejci1f05b6a2019-07-18 16:15:06 +0200200 struct lyd_node *tree, *iter;
201 struct lyd_node_inner *list;
Radek Krejci710226d2019-07-24 17:24:59 +0200202 struct lyd_node_term *leaf;
Radek Krejci1f05b6a2019-07-18 16:15:06 +0200203
Radek Krejci710226d2019-07-24 17:24:59 +0200204 /* check hashes */
Radek Iša56ca9e42020-09-08 18:42:00 +0200205 data = "<l1 xmlns=\"urn:tests:a\"><a>one</a><b>one</b><c>1</c></l1>";
206 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
207 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1",
208 1, LYS_LIST, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100209 list = (struct lyd_node_inner *)tree;
Radek Krejci1f05b6a2019-07-18 16:15:06 +0200210 LY_LIST_FOR(list->child, iter) {
211 assert_int_not_equal(0, iter->hash);
212 }
Radek Krejci1f05b6a2019-07-18 16:15:06 +0200213 lyd_free_all(tree);
Radek Krejci710226d2019-07-24 17:24:59 +0200214
Michal Vasko9f96a052020-03-10 09:41:45 +0100215 /* missing keys */
Radek Iša56ca9e42020-09-08 18:42:00 +0200216 PARSER_CHECK_ERROR("<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b></l1>", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vaskodbf3e652022-10-21 08:46:25 +0200217 "List instance is missing its key \"a\".", "Data location \"/a:l1[b='b'][c='1']\", line number 1.");
Michal Vasko62af3692023-02-09 14:00:09 +0100218 CHECK_LOG_CTX("Invalid position of the key \"b\" in a list.", NULL);
Michal Vasko9f96a052020-03-10 09:41:45 +0100219
Radek Iša56ca9e42020-09-08 18:42:00 +0200220 PARSER_CHECK_ERROR("<l1 xmlns=\"urn:tests:a\"><a>a</a></l1>", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vaskodbf3e652022-10-21 08:46:25 +0200221 "List instance is missing its key \"b\".", "Data location \"/a:l1[a='a']\", line number 1.");
Michal Vasko9f96a052020-03-10 09:41:45 +0100222
Radek Iša56ca9e42020-09-08 18:42:00 +0200223 PARSER_CHECK_ERROR("<l1 xmlns=\"urn:tests:a\"><b>b</b><a>a</a></l1>", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vaskodbf3e652022-10-21 08:46:25 +0200224 "List instance is missing its key \"c\".", "Data location \"/a:l1[a='a'][b='b']\", line number 1.");
Michal Vasko62af3692023-02-09 14:00:09 +0100225 CHECK_LOG_CTX("Invalid position of the key \"a\" in a list.", NULL);
Michal Vasko9f96a052020-03-10 09:41:45 +0100226
227 /* key duplicate */
Radek Iša56ca9e42020-09-08 18:42:00 +0200228 PARSER_CHECK_ERROR("<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b><a>a</a><c>1</c></l1>", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vasko959f8d82022-06-16 07:51:50 +0200229 "Duplicate instance of \"c\".",
Michal Vaskodbf3e652022-10-21 08:46:25 +0200230 "Data location \"/a:l1[a='a'][b='b'][c='1'][c='1']/c\", line number 1.");
Michal Vasko62af3692023-02-09 14:00:09 +0100231 CHECK_LOG_CTX("Invalid position of the key \"a\" in a list.", NULL);
232 CHECK_LOG_CTX("Invalid position of the key \"b\" in a list.", NULL);
Michal Vasko9f96a052020-03-10 09:41:45 +0100233
Radek Krejci710226d2019-07-24 17:24:59 +0200234 /* keys order */
Radek Iša56ca9e42020-09-08 18:42:00 +0200235 CHECK_PARSE_LYD("<l1 xmlns=\"urn:tests:a\"><d>d</d><a>a</a><c>1</c><b>b</b></l1>", 0, LYD_VALIDATE_PRESENT, tree);
236 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1",
237 1, LYS_LIST, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100238 list = (struct lyd_node_inner *)tree;
239 assert_non_null(leaf = (struct lyd_node_term *)list->child);
Radek Iša56ca9e42020-09-08 18:42:00 +0200240 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 +0100241 assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
Radek Iša56ca9e42020-09-08 18:42:00 +0200242 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 +0100243 assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
Radek Iša56ca9e42020-09-08 18:42:00 +0200244 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 +0100245 assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
Michal Vaskodbf3e652022-10-21 08:46:25 +0200246 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 +0200247 CHECK_LOG_CTX("Invalid position of the key \"b\" in a list.", NULL);
Radek Krejci710226d2019-07-24 17:24:59 +0200248 lyd_free_all(tree);
249
Michal Vasko44685da2020-03-17 15:38:06 +0100250 data = "<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b><a>a</a></l1>";
Radek Iša56ca9e42020-09-08 18:42:00 +0200251 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
252 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1", 1, LYS_LIST, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100253 list = (struct lyd_node_inner *)tree;
254 assert_non_null(leaf = (struct lyd_node_term *)list->child);
Radek Iša56ca9e42020-09-08 18:42:00 +0200255 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 +0100256 assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
Radek Iša56ca9e42020-09-08 18:42:00 +0200257 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 +0100258 assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
Radek Iša56ca9e42020-09-08 18:42:00 +0200259 CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "c", 1, LYS_LEAF, 1, 0, NULL, 0);
260 CHECK_LOG_CTX("Invalid position of the key \"a\" in a list.", NULL);
Michal Vasko62af3692023-02-09 14:00:09 +0100261 CHECK_LOG_CTX("Invalid position of the key \"b\" in a list.", NULL);
Radek Krejci710226d2019-07-24 17:24:59 +0200262 lyd_free_all(tree);
263
Radek Iša56ca9e42020-09-08 18:42:00 +0200264 PARSER_CHECK_ERROR(data, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vaskodbf3e652022-10-21 08:46:25 +0200265 "Invalid position of the key \"b\" in a list.", "Data location \"/a:l1[c='1']/b\", line number 1.");
Radek Krejci1f05b6a2019-07-18 16:15:06 +0200266}
267
Radek Krejcib6f7ae52019-07-19 10:31:42 +0200268static void
269test_container(void **state)
270{
Radek Krejcib6f7ae52019-07-19 10:31:42 +0200271 struct lyd_node *tree;
272 struct lyd_node_inner *cont;
273
Radek Iša56ca9e42020-09-08 18:42:00 +0200274 CHECK_PARSE_LYD("<c xmlns=\"urn:tests:a\"/>", 0, LYD_VALIDATE_PRESENT, tree);
275 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c", 1, LYS_CONTAINER, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100276 cont = (struct lyd_node_inner *)tree;
Radek Krejcib6f7ae52019-07-19 10:31:42 +0200277 assert_true(cont->flags & LYD_DEFAULT);
278 lyd_free_all(tree);
279
Radek Iša56ca9e42020-09-08 18:42:00 +0200280 CHECK_PARSE_LYD("<cp xmlns=\"urn:tests:a\"/>", 0, LYD_VALIDATE_PRESENT, tree);
Radek Krejcib6f7ae52019-07-19 10:31:42 +0200281 assert_non_null(tree);
Michal Vasko26123192020-11-09 21:02:34 +0100282 tree = tree->next;
Michal Vaskoe16c7b72021-02-26 10:39:06 +0100283 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 +0200284 1, LYS_CONTAINER, 0, 0, NULL, 0);
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100285 cont = (struct lyd_node_inner *)tree;
Radek Krejcib6f7ae52019-07-19 10:31:42 +0200286 assert_false(cont->flags & LYD_DEFAULT);
287 lyd_free_all(tree);
Radek Krejcib6f7ae52019-07-19 10:31:42 +0200288}
289
Michal Vasko44685da2020-03-17 15:38:06 +0100290static void
291test_opaq(void **state)
292{
Michal Vasko44685da2020-03-17 15:38:06 +0100293 const char *data;
Michal Vasko44685da2020-03-17 15:38:06 +0100294 struct lyd_node *tree;
295
296 /* invalid value, no flags */
297 data = "<foo3 xmlns=\"urn:tests:a\"/>";
Radek Iša56ca9e42020-09-08 18:42:00 +0200298 PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vasko959f8d82022-06-16 07:51:50 +0200299 "Invalid type uint32 empty value.", "Schema location \"/a:foo3\", line number 1.");
Michal Vasko44685da2020-03-17 15:38:06 +0100300
301 /* opaq flag */
Radek Iša56ca9e42020-09-08 18:42:00 +0200302 CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree);
Michal Vasko535d21c2023-08-09 10:41:44 +0200303 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0, LY_VALUE_XML, "foo3", 0, 0, NULL, 1, "");
Radek Iša56ca9e42020-09-08 18:42:00 +0200304 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, "<foo3 xmlns=\"urn:tests:a\"/>\n");
Michal Vasko44685da2020-03-17 15:38:06 +0100305 lyd_free_all(tree);
306
Michal Vaskoda8fbbf2021-06-16 11:44:44 +0200307 /* list, opaq flag */
308 data = "<l1 xmlns=\"urn:tests:a\"/>";
309 CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree);
Michal Vasko535d21c2023-08-09 10:41:44 +0200310 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0, LY_VALUE_XML, "l1", 0, 0, NULL, 1, "");
Michal Vaskoda8fbbf2021-06-16 11:44:44 +0200311 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, "<l1 xmlns=\"urn:tests:a\"/>\n");
312 lyd_free_all(tree);
313
Michal Vasko44685da2020-03-17 15:38:06 +0100314 /* missing key, no flags */
Radek Iša56ca9e42020-09-08 18:42:00 +0200315 data = "<l1 xmlns=\"urn:tests:a\">\n"
316 " <a>val_a</a>\n"
317 " <b>val_b</b>\n"
318 " <d>val_d</d>\n"
319 "</l1>\n";
320 PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vasko959f8d82022-06-16 07:51:50 +0200321 "List instance is missing its key \"c\".",
Michal Vaskodbf3e652022-10-21 08:46:25 +0200322 "Data location \"/a:l1[a='val_a'][b='val_b']\", line number 5.");
Michal Vasko44685da2020-03-17 15:38:06 +0100323
324 /* opaq flag */
Radek Iša56ca9e42020-09-08 18:42:00 +0200325 CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree);
Michal Vasko535d21c2023-08-09 10:41:44 +0200326 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_VALUE_XML, "l1", 0, 0, NULL, 1, "");
Radek Iša56ca9e42020-09-08 18:42:00 +0200327 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
Michal Vasko44685da2020-03-17 15:38:06 +0100328 lyd_free_all(tree);
329
330 /* invalid key, no flags */
Radek Iša56ca9e42020-09-08 18:42:00 +0200331 data = "<l1 xmlns=\"urn:tests:a\">\n"
332 " <a>val_a</a>\n"
333 " <b>val_b</b>\n"
334 " <c>val_c</c>\n"
335 "</l1>\n";
336 PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
Michal Vasko959f8d82022-06-16 07:51:50 +0200337 "Invalid type int16 value \"val_c\".",
Michal Vaskoa4dfb3c2022-10-25 14:59:31 +0200338 "Data location \"/a:l1[a='val_a'][b='val_b']/c\", line number 4.");
Michal Vasko44685da2020-03-17 15:38:06 +0100339
340 /* opaq flag */
Radek Iša56ca9e42020-09-08 18:42:00 +0200341 CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree);
Michal Vasko535d21c2023-08-09 10:41:44 +0200342 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_VALUE_XML, "l1", 0, 0, NULL, 1, "");
Radek Iša56ca9e42020-09-08 18:42:00 +0200343 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
Michal Vasko44685da2020-03-17 15:38:06 +0100344 lyd_free_all(tree);
345
Michal Vasko413c7f22020-05-05 12:34:06 +0200346 /* opaq flag and fail */
Radek Iša56ca9e42020-09-08 18:42:00 +0200347 assert_int_equal(LY_EVALID, lyd_parse_data_mem(UTEST_LYCTX,
348 "<a xmlns=\"ns\">\n"
349 " <b>x</b>\n"
Michal Vaskoe137fc42021-07-22 11:53:13 +0200350 " <c xmld:id=\"D\">1</c>\n"
Radek Iša56ca9e42020-09-08 18:42:00 +0200351 "</a>\n",
352 LYD_XML, LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree));
Michal Vaskoa878a892023-08-18 12:22:07 +0200353 CHECK_LOG_CTX("Unknown XML prefix \"xmld\".", "Data location \"/a\", line number 3.");
Michal Vasko44685da2020-03-17 15:38:06 +0100354}
355
Michal Vaskob36053d2020-03-26 15:49:30 +0100356static void
357test_rpc(void **state)
358{
Michal Vaskob36053d2020-03-26 15:49:30 +0100359 const char *data;
Michal Vasko63f3d842020-07-08 10:10:14 +0200360 struct ly_in *in;
Michal Vaskob36053d2020-03-26 15:49:30 +0100361 struct lyd_node *tree, *op;
Michal Vasko1bf09392020-03-27 12:38:10 +0100362 const struct lyd_node *node;
Radek Iša56ca9e42020-09-08 18:42:00 +0200363 const char *dsc = "The <edit-config> operation loads all or part of a specified\n"
364 "configuration to the specified target configuration.";
365 const char *ref = "RFC 6241, Section 7.2";
366 const char *feats[] = {"writable-running", NULL};
Michal Vaskob36053d2020-03-26 15:49:30 +0100367
Radek Iša56ca9e42020-09-08 18:42:00 +0200368 assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf", "2011-06-01", feats)));
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100369
Michal Vasko2552ea32020-12-08 15:32:34 +0100370 data = "<edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
371 " <target>\n"
372 " <running/>\n"
373 " </target>\n"
374 " <config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
375 " <l1 xmlns=\"urn:tests:a\" nc:operation=\"replace\">\n"
376 " <a>val_a</a>\n"
377 " <b>val_b</b>\n"
378 " <c>val_c</c>\n"
379 " </l1>\n"
380 " <cp xmlns=\"urn:tests:a\">\n"
381 " <z nc:operation=\"delete\"/>\n"
382 " </cp>\n"
383 " </config>\n"
384 "</edit-config>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +0200385 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100386 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_YANG, &tree, &op));
Michal Vasko63f3d842020-07-08 10:10:14 +0200387 ly_in_free(in, 0);
Michal Vasko1bf09392020-03-27 12:38:10 +0100388
389 assert_non_null(op);
Radek Iša56ca9e42020-09-08 18:42:00 +0200390
Radek Krejci2a9fc652021-01-22 17:44:34 +0100391 CHECK_LYSC_ACTION((struct lysc_node_action *)op->schema, dsc, 0, LYS_STATUS_CURR,
Radek Iša56ca9e42020-09-08 18:42:00 +0200392 1, 0, 0, 1, "edit-config", LYS_RPC,
393 0, 0, 0, 0, 0, ref, 0);
Michal Vasko1bf09392020-03-27 12:38:10 +0100394
Michal Vaskob36053d2020-03-26 15:49:30 +0100395 assert_non_null(tree);
Radek Iša56ca9e42020-09-08 18:42:00 +0200396
Michal Vasko2552ea32020-12-08 15:32:34 +0100397 node = tree;
Radek Krejci2a9fc652021-01-22 17:44:34 +0100398 CHECK_LYSC_ACTION((struct lysc_node_action *)node->schema, dsc, 0, LYS_STATUS_CURR,
Radek Iša56ca9e42020-09-08 18:42:00 +0200399 1, 0, 0, 1, "edit-config", LYS_RPC,
400 0, 0, 0, 0, 0, ref, 0);
Radek Krejcia1c1e542020-09-29 16:06:52 +0200401 node = lyd_child(node)->next;
Radek Iša56ca9e42020-09-08 18:42:00 +0200402 dsc = "Inline Config content.";
Michal Vaskod1e53b92021-01-28 13:11:06 +0100403 CHECK_LYSC_NODE(node->schema, dsc, 0, LYS_STATUS_CURR | LYS_IS_INPUT, 1, "config", 0, LYS_ANYXML, 1, 0, NULL, 0);
Michal Vaskob104f112020-07-17 09:54:54 +0200404
Michal Vasko1bf09392020-03-27 12:38:10 +0100405 node = ((struct lyd_node_any *)node)->value.tree;
Michal Vaskoe16c7b72021-02-26 10:39:06 +0100406 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 +0200407 1, LYS_CONTAINER, 0, 0, NULL, 0);
408
Radek Krejcia1c1e542020-09-29 16:06:52 +0200409 node = lyd_child(node);
Michal Vasko1bf09392020-03-27 12:38:10 +0100410 /* z has no value */
Michal Vasko535d21c2023-08-09 10:41:44 +0200411 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0, LY_VALUE_XML, "z", 0, 0, NULL, 1, "");
Michal Vaskob104f112020-07-17 09:54:54 +0200412 node = node->parent->next;
413 /* l1 key c has invalid value so it is at the end */
Michal Vasko535d21c2023-08-09 10:41:44 +0200414 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0x1, LY_VALUE_XML, "l1", 0, 0, NULL, 1, "");
Michal Vaskob36053d2020-03-26 15:49:30 +0100415
Radek Iša56ca9e42020-09-08 18:42:00 +0200416 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS,
Michal Vasko2552ea32020-12-08 15:32:34 +0100417 "<edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
418 " <target>\n"
419 " <running/>\n"
420 " </target>\n"
421 " <config>\n"
422 " <cp xmlns=\"urn:tests:a\">\n"
423 " <z xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"delete\"/>\n"
424 " </cp>\n"
425 " <l1 xmlns=\"urn:tests:a\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"replace\">\n"
426 " <a>val_a</a>\n"
427 " <b>val_b</b>\n"
428 " <c>val_c</c>\n"
429 " </l1>\n"
430 " </config>\n"
431 "</edit-config>\n");
Radek Iša56ca9e42020-09-08 18:42:00 +0200432
Michal Vaskob36053d2020-03-26 15:49:30 +0100433 lyd_free_all(tree);
434
435 /* wrong namespace, element name, whatever... */
Michal Vaskoa8edff02020-03-27 14:47:01 +0100436 /* TODO */
Michal Vaskoa8edff02020-03-27 14:47:01 +0100437}
438
439static void
440test_action(void **state)
441{
Michal Vaskoa8edff02020-03-27 14:47:01 +0100442 const char *data;
Michal Vasko63f3d842020-07-08 10:10:14 +0200443 struct ly_in *in;
Michal Vaskoa8edff02020-03-27 14:47:01 +0100444 struct lyd_node *tree, *op;
Michal Vaskoa8edff02020-03-27 14:47:01 +0100445
Michal Vasko2552ea32020-12-08 15:32:34 +0100446 data = "<c xmlns=\"urn:tests:a\">\n"
447 " <act>\n"
448 " <al>value</al>\n"
449 " </act>\n"
450 "</c>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +0200451 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100452 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_YANG, &tree, &op));
Michal Vasko63f3d842020-07-08 10:10:14 +0200453 ly_in_free(in, 0);
Michal Vaskoa8edff02020-03-27 14:47:01 +0100454
455 assert_non_null(op);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100456 CHECK_LYSC_ACTION((struct lysc_node_action *)op->schema, NULL, 0, LYS_STATUS_CURR,
Radek Iša56ca9e42020-09-08 18:42:00 +0200457 1, 0, 0, 1, "act", LYS_ACTION,
458 1, 0, 0, 1, 0, NULL, 0);
Michal Vaskoa8edff02020-03-27 14:47:01 +0100459
Radek Iša56ca9e42020-09-08 18:42:00 +0200460 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS,
Michal Vasko2552ea32020-12-08 15:32:34 +0100461 "<c xmlns=\"urn:tests:a\">\n"
462 " <act>\n"
463 " <al>value</al>\n"
464 " </act>\n"
465 "</c>\n");
Radek Iša56ca9e42020-09-08 18:42:00 +0200466
Michal Vaskoa8edff02020-03-27 14:47:01 +0100467 lyd_free_all(tree);
468
469 /* wrong namespace, element name, whatever... */
470 /* TODO */
Michal Vaskoa8edff02020-03-27 14:47:01 +0100471}
472
473static void
474test_notification(void **state)
475{
Michal Vaskoa8edff02020-03-27 14:47:01 +0100476 const char *data;
Michal Vasko63f3d842020-07-08 10:10:14 +0200477 struct ly_in *in;
Michal Vaskoa8edff02020-03-27 14:47:01 +0100478 struct lyd_node *tree, *ntf;
Michal Vaskoa8edff02020-03-27 14:47:01 +0100479
Michal Vasko2552ea32020-12-08 15:32:34 +0100480 data = "<c xmlns=\"urn:tests:a\">\n"
481 " <n1>\n"
482 " <nl>value</nl>\n"
483 " </n1>\n"
484 "</c>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +0200485 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100486 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_NOTIF_YANG, &tree, &ntf));
Michal Vasko63f3d842020-07-08 10:10:14 +0200487 ly_in_free(in, 0);
Michal Vaskoa8edff02020-03-27 14:47:01 +0100488
489 assert_non_null(ntf);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100490 CHECK_LYSC_NOTIF((struct lysc_node_notif *)ntf->schema, 1, NULL, 0, 0x4, 1, 0, "n1", 1, 0, NULL, 0);
Michal Vaskoa8edff02020-03-27 14:47:01 +0100491
Michal Vasko2552ea32020-12-08 15:32:34 +0100492 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c", 1, LYS_CONTAINER, 0, 0, NULL, 0);
Michal Vaskoa8edff02020-03-27 14:47:01 +0100493
Radek Iša56ca9e42020-09-08 18:42:00 +0200494 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
Michal Vaskoa8edff02020-03-27 14:47:01 +0100495 lyd_free_all(tree);
496
497 /* top-level notif without envelope */
Radek Iša56ca9e42020-09-08 18:42:00 +0200498 data = "<n2 xmlns=\"urn:tests:a\"/>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +0200499 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100500 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_NOTIF_YANG, &tree, &ntf));
Michal Vasko63f3d842020-07-08 10:10:14 +0200501 ly_in_free(in, 0);
Michal Vaskoa8edff02020-03-27 14:47:01 +0100502
503 assert_non_null(ntf);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100504 CHECK_LYSC_NOTIF((struct lysc_node_notif *)ntf->schema, 0, NULL, 0, 0x4, 1, 0, "n2", 0, 0, NULL, 0);
Michal Vaskoa8edff02020-03-27 14:47:01 +0100505
506 assert_non_null(tree);
507 assert_ptr_equal(ntf, tree);
508
Radek Iša56ca9e42020-09-08 18:42:00 +0200509 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
Michal Vaskoa8edff02020-03-27 14:47:01 +0100510 lyd_free_all(tree);
511
512 /* wrong namespace, element name, whatever... */
513 /* TODO */
Michal Vaskob36053d2020-03-26 15:49:30 +0100514}
515
Michal Vasko1ce933a2020-03-30 12:38:22 +0200516static void
517test_reply(void **state)
518{
Michal Vasko1ce933a2020-03-30 12:38:22 +0200519 const char *data;
Michal Vasko63f3d842020-07-08 10:10:14 +0200520 struct ly_in *in;
Michal Vasko2552ea32020-12-08 15:32:34 +0100521 struct lyd_node *tree, *op;
Michal Vasko1ce933a2020-03-30 12:38:22 +0200522 const struct lyd_node *node;
523
Michal Vasko79135ae2020-12-16 10:08:35 +0100524 data = "<c xmlns=\"urn:tests:a\">\n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100525 " <act>\n"
Michal Vasko2552ea32020-12-08 15:32:34 +0100526 " <al>25</al>\n"
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100527 " </act>\n"
528 "</c>\n";
Michal Vasko63f3d842020-07-08 10:10:14 +0200529 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100530 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_REPLY_YANG, &tree, &op));
Michal Vasko63f3d842020-07-08 10:10:14 +0200531 ly_in_free(in, 0);
532
Michal Vasko1ce933a2020-03-30 12:38:22 +0200533 assert_non_null(op);
Radek Iša56ca9e42020-09-08 18:42:00 +0200534
Radek Krejci2a9fc652021-01-22 17:44:34 +0100535 CHECK_LYSC_ACTION((struct lysc_node_action *)op->schema, NULL, 0, LYS_STATUS_CURR,
Radek Iša56ca9e42020-09-08 18:42:00 +0200536 1, 0, 0, 1, "act", LYS_ACTION,
537 1, 0, 0, 1, 0, NULL, 0);
Radek Krejcia1c1e542020-09-29 16:06:52 +0200538 node = lyd_child(op);
Michal Vaskod1e53b92021-01-28 13:11:06 +0100539 CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_STATUS_CURR | LYS_IS_OUTPUT, 1, "al", 0, LYS_LEAF, 1, 0, NULL, 0);
Michal Vasko1ce933a2020-03-30 12:38:22 +0200540
Michal Vasko2552ea32020-12-08 15:32:34 +0100541 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c", 1, LYS_CONTAINER, 0, 0, NULL, 0);
Michal Vasko1ce933a2020-03-30 12:38:22 +0200542
543 /* TODO print only rpc-reply node and then output subtree */
Radek Iša56ca9e42020-09-08 18:42:00 +0200544 CHECK_LYD_STRING(lyd_child(op), LYD_PRINT_WITHSIBLINGS, "<al xmlns=\"urn:tests:a\">25</al>\n");
Michal Vasko1ce933a2020-03-30 12:38:22 +0200545 lyd_free_all(tree);
546
547 /* wrong namespace, element name, whatever... */
548 /* TODO */
Michal Vasko1ce933a2020-03-30 12:38:22 +0200549}
550
Michal Vaskoe0665742021-02-11 11:08:44 +0100551static void
552test_netconf_rpc(void **state)
553{
554 const char *data;
555 struct ly_in *in;
556 struct lyd_node *tree, *op;
557 const struct lyd_node *node;
558 const char *dsc = "The <edit-config> operation loads all or part of a specified\n"
559 "configuration to the specified target configuration.";
560 const char *ref = "RFC 6241, Section 7.2";
561 const char *feats[] = {"writable-running", NULL};
562
563 assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf", "2011-06-01", feats)));
564
565 data = "<rpc message-id=\"25\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
566 "<edit-config>\n"
567 " <target>\n"
568 " <running/>\n"
569 " </target>\n"
570 " <config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
571 " <l1 xmlns=\"urn:tests:a\" nc:operation=\"replace\">\n"
572 " <a>val_a</a>\n"
573 " <b>val_b</b>\n"
574 " <c>val_c</c>\n"
575 " </l1>\n"
576 " <cp xmlns=\"urn:tests:a\">\n"
577 " <z nc:operation=\"delete\"/>\n"
578 " </cp>\n"
579 " </config>\n"
580 "</edit-config>\n"
581 "</rpc>\n";
582 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100583 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_NETCONF, &tree, &op));
Michal Vaskoe0665742021-02-11 11:08:44 +0100584 ly_in_free(in, 0);
585
586 assert_non_null(op);
587
588 node = tree;
Radek Krejci8df109d2021-04-23 12:19:08 +0200589 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 1, 0, LY_VALUE_XML, "rpc", 0, 0, 0, 0, "");
Michal Vaskoe0665742021-02-11 11:08:44 +0100590
591 assert_non_null(tree);
592
593 node = op;
594 CHECK_LYSC_ACTION((struct lysc_node_action *)node->schema, dsc, 0, LYS_STATUS_CURR,
595 1, 0, 0, 1, "edit-config", LYS_RPC,
596 0, 0, 0, 0, 0, ref, 0);
597 node = lyd_child(node)->next;
598 dsc = "Inline Config content.";
599 CHECK_LYSC_NODE(node->schema, dsc, 0, LYS_STATUS_CURR | LYS_IS_INPUT, 1, "config", 0, LYS_ANYXML, 1, 0, NULL, 0);
600
601 node = ((struct lyd_node_any *)node)->value.tree;
Michal Vaskoe16c7b72021-02-26 10:39:06 +0100602 CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp",
Michal Vaskoe0665742021-02-11 11:08:44 +0100603 1, LYS_CONTAINER, 0, 0, NULL, 0);
604
605 node = lyd_child(node);
606 /* z has no value */
Michal Vasko535d21c2023-08-09 10:41:44 +0200607 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0, LY_VALUE_XML, "z", 0, 0, NULL, 1, "");
Michal Vaskoe0665742021-02-11 11:08:44 +0100608 node = node->parent->next;
609 /* l1 key c has invalid value so it is at the end */
Michal Vasko535d21c2023-08-09 10:41:44 +0200610 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0x1, LY_VALUE_XML, "l1", 0, 0, NULL, 1, "");
Michal Vaskoe0665742021-02-11 11:08:44 +0100611
612 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS,
613 "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"25\"/>\n");
614 CHECK_LYD_STRING(op, LYD_PRINT_WITHSIBLINGS,
615 "<edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
616 " <target>\n"
617 " <running/>\n"
618 " </target>\n"
619 " <config>\n"
620 " <cp xmlns=\"urn:tests:a\">\n"
621 " <z xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"delete\"/>\n"
622 " </cp>\n"
623 " <l1 xmlns=\"urn:tests:a\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"replace\">\n"
624 " <a>val_a</a>\n"
625 " <b>val_b</b>\n"
626 " <c>val_c</c>\n"
627 " </l1>\n"
628 " </config>\n"
629 "</edit-config>\n");
630
631 lyd_free_all(tree);
632 lyd_free_all(op);
633
Michal Vasko85be65e2023-06-13 09:44:17 +0200634 /* invalid anyxml nested metadata value */
635 data = "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\" pid=\"4114692032\">\n"
636 " <copy-config>\n"
637 " <target>\n"
638 " <running/>\n"
639 " </target>\n"
640 " <source>\n"
641 " <config>\n"
642 " <l1 xmlns=\"urn:tests:a\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
643 " <a>val_a</a>\n"
644 " <b>val_b</b>\n"
645 " <c>5</c>\n"
646 " <cont nc:operation=\"merge\">\n"
647 " <e nc:operation=\"merge2\">false</e>\n"
648 " </cont>\n"
649 " </l1>\n"
650 " </config>\n"
651 " </source>\n"
652 " </copy-config>\n"
653 "</rpc>\n";
654 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
655 assert_int_equal(LY_EVALID, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_NETCONF, &tree, &op));
656 ly_in_free(in, 0);
657 CHECK_LOG_CTX("Invalid enumeration value \"merge2\".",
658 "Data location \"/ietf-netconf:copy-config/source/config/a:l1[a='val_a'][b='val_b'][c='5']/cont/e\", line number 13.");
659 lyd_free_all(tree);
660 assert_null(op);
Michal Vaskoe0665742021-02-11 11:08:44 +0100661}
662
663static void
664test_netconf_action(void **state)
665{
666 const char *data;
667 struct ly_in *in;
668 struct lyd_node *tree, *op;
669
670 data = "<rpc message-id=\"25\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
671 "<action xmlns=\"urn:ietf:params:xml:ns:yang:1\">"
672 "<c xmlns=\"urn:tests:a\">\n"
673 " <act>\n"
674 " <al>value</al>\n"
675 " </act>\n"
676 "</c>\n"
677 "</action>\n"
678 "</rpc>\n";
679 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100680 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_NETCONF, &tree, &op));
Michal Vaskoe0665742021-02-11 11:08:44 +0100681 ly_in_free(in, 0);
682
Radek Krejci8df109d2021-04-23 12:19:08 +0200683 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 1, 1, LY_VALUE_XML, "rpc", 0, 0, 0, 0, "");
684 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)lyd_child(tree), 0, 0, LY_VALUE_XML, "action", 0, 0, 0, 0, "");
Michal Vaskoe0665742021-02-11 11:08:44 +0100685
686 assert_non_null(op);
687 CHECK_LYSC_ACTION((struct lysc_node_action *)op->schema, NULL, 0, LYS_STATUS_CURR,
688 1, 0, 0, 1, "act", LYS_ACTION,
689 1, 0, 0, 1, 0, NULL, 0);
690
691 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS,
692 "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"25\">\n"
693 " <action xmlns=\"urn:ietf:params:xml:ns:yang:1\"/>\n"
694 "</rpc>\n");
695 CHECK_LYD_STRING(op, LYD_PRINT_WITHSIBLINGS,
696 "<act xmlns=\"urn:tests:a\">\n"
697 " <al>value</al>\n"
698 "</act>\n");
699
700 lyd_free_all(tree);
701 lyd_free_all(op);
702
703 /* wrong namespace, element name, whatever... */
704 /* TODO */
705}
706
707static void
708test_netconf_reply_or_notification(void **state)
709{
710 const char *data;
711 struct ly_in *in;
712 struct lyd_node *action, *tree, *op, *op2;
713
714 /* parse the action */
715 data = "<c xmlns=\"urn:tests:a\">\n"
716 " <act>\n"
717 " <al>value</al>\n"
718 " </act>\n"
719 "</c>\n";
720 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100721 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_YANG, &action, &op));
Michal Vaskoe0665742021-02-11 11:08:44 +0100722 ly_in_free(in, 0);
723
724 /* parse notification first */
725 data = "<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n"
726 "<eventTime>2010-12-06T08:00:01Z</eventTime>\n"
727 "<c xmlns=\"urn:tests:a\">\n"
728 " <n1>\n"
729 " <nl>value</nl>\n"
730 " </n1>\n"
731 "</c>\n"
732 "</notification>\n";
733 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100734 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_NOTIF_NETCONF, &tree, &op2));
Michal Vaskoe0665742021-02-11 11:08:44 +0100735 ly_in_free(in, 0);
736
Radek Krejci8df109d2021-04-23 12:19:08 +0200737 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 1, LY_VALUE_XML, "notification", 0, 0, 0, 0, "");
738 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)lyd_child(tree), 0, 0, LY_VALUE_XML, "eventTime", 0, 0, 0, 0,
Michal Vaskoe0665742021-02-11 11:08:44 +0100739 "2010-12-06T08:00:01Z");
740
741 assert_non_null(op2);
742 CHECK_LYSC_NOTIF((struct lysc_node_notif *)op2->schema, 1, NULL, 0, 0x4, 1, 0, "n1", 1, 0, NULL, 0);
743
744 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS,
745 "<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n"
746 " <eventTime>2010-12-06T08:00:01Z</eventTime>\n"
747 "</notification>\n");
748 CHECK_LYD_STRING(op2, LYD_PRINT_WITHSIBLINGS,
749 "<n1 xmlns=\"urn:tests:a\">\n"
750 " <nl>value</nl>\n"
751 "</n1>\n");
752
753 lyd_free_all(tree);
754 lyd_free_all(op2);
755
756 /* parse a data reply */
757 data = "<rpc-reply message-id=\"55\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
758 " <al xmlns=\"urn:tests:a\">25</al>\n"
759 "</rpc-reply>\n";
760 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100761 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, op, in, LYD_XML, LYD_TYPE_REPLY_NETCONF, &tree, NULL));
Michal Vaskoe0665742021-02-11 11:08:44 +0100762 ly_in_free(in, 0);
763
Radek Krejci8df109d2021-04-23 12:19:08 +0200764 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 1, 0, LY_VALUE_XML, "rpc-reply", 0, 0, 0, 0, "");
Michal Vaskoe0665742021-02-11 11:08:44 +0100765
Michal Vaskoe0665742021-02-11 11:08:44 +0100766 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS,
767 "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"55\"/>\n");
Michal Vaskoe0665742021-02-11 11:08:44 +0100768
769 lyd_free_all(tree);
770 /* it was connected to the action, do not free */
771
772 /* parse an ok reply */
773 data = "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"55\">\n"
774 " <ok/>\n"
775 "</rpc-reply>\n";
776 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100777 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, op, in, LYD_XML, LYD_TYPE_REPLY_NETCONF, &tree, NULL));
Michal Vaskoe0665742021-02-11 11:08:44 +0100778 ly_in_free(in, 0);
779
Radek Krejci8df109d2021-04-23 12:19:08 +0200780 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 1, 1, LY_VALUE_XML, "rpc-reply", 0, 0, 0, 0, "");
781 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)lyd_child(tree), 0, 0, LY_VALUE_XML, "ok", 0, 0, 0, 0, "");
Michal Vaskoe0665742021-02-11 11:08:44 +0100782
Michal Vaskoe0665742021-02-11 11:08:44 +0100783 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
784
785 lyd_free_all(tree);
786
787 /* parse an error reply */
788 data = "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"55\">\n"
789 " <rpc-error>\n"
790 " <error-type>rpc</error-type>\n"
791 " <error-tag>missing-attribute</error-tag>\n"
792 " <error-severity>error</error-severity>\n"
793 " <error-info>\n"
794 " <bad-attribute>message-id</bad-attribute>\n"
795 " <bad-element>rpc</bad-element>\n"
796 " </error-info>\n"
797 " </rpc-error>\n"
798 "</rpc-reply>\n";
799 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100800 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, op, in, LYD_XML, LYD_TYPE_REPLY_NETCONF, &tree, NULL));
Michal Vaskoe0665742021-02-11 11:08:44 +0100801 ly_in_free(in, 0);
802
Radek Krejci8df109d2021-04-23 12:19:08 +0200803 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 1, 1, LY_VALUE_XML, "rpc-reply", 0, 0, 0, 0, "");
804 CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)lyd_child(tree), 0, 1, LY_VALUE_XML, "rpc-error", 0, 0, 0, 0, "");
Michal Vaskoe0665742021-02-11 11:08:44 +0100805
Michal Vaskoe0665742021-02-11 11:08:44 +0100806 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
807
808 lyd_free_all(tree);
809
810 lyd_free_all(action);
811
812 /* wrong namespace, element name, whatever... */
813 /* TODO */
814}
815
aPiecek9cdb9e62021-05-18 09:46:20 +0200816static void
Michal Vasko820efe82023-05-12 15:47:43 +0200817test_restconf_rpc(void **state)
818{
819 const char *data;
820 struct ly_in *in;
821 struct lyd_node *tree, *envp;
822
823 assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf-nmda", "2019-01-07", NULL)));
824
825 assert_int_equal(LY_SUCCESS, lyd_new_path(NULL, UTEST_LYCTX, "/ietf-netconf-nmda:edit-data", NULL, 0, &tree));
826
827 data = "<input xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-nmda\">"
828 "<datastore xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">ds:running</datastore>"
829 "<config>"
830 "<cp xmlns=\"urn:tests:a\"><z xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"replace\"/></cp>"
831 "<l1 xmlns=\"urn:tests:a\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"replace\">"
832 "<a>val_a</a><b>val_b</b><c>val_c</c>"
833 "</l1>"
834 "</config></input>";
835 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
836 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, tree, in, LYD_XML, LYD_TYPE_RPC_RESTCONF, &envp, NULL));
837 ly_in_free(in, 0);
838
839 /* the same just connected to the edit-data RPC */
840 data = "<edit-data xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-nmda\">"
841 "<datastore xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">ds:running</datastore>"
842 "<config>"
843 "<cp xmlns=\"urn:tests:a\"><z xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"replace\"/></cp>"
844 "<l1 xmlns=\"urn:tests:a\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"replace\">"
845 "<a>val_a</a><b>val_b</b><c>val_c</c>"
846 "</l1>"
847 "</config></edit-data>";
848 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
849 lyd_free_all(tree);
850 lyd_free_all(envp);
851}
852
853static void
854test_restconf_reply(void **state)
855{
856 const char *data;
857 struct ly_in *in;
858 struct lyd_node *tree, *envp;
859
860 assert_int_equal(LY_SUCCESS, lyd_new_path(NULL, UTEST_LYCTX, "/a:c/act", NULL, 0, &tree));
861
862 data = "<output xmlns=\"urn:tests:a\"><al>25</al></output>";
863 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
864 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, lyd_child(tree), in, LYD_XML, LYD_TYPE_REPLY_RESTCONF, &envp, NULL));
865 ly_in_free(in, 0);
866
867 /* connected to the RPC with the parent */
868 data = "<c xmlns=\"urn:tests:a\"><act><al>25</al></act></c>";
869 CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
870 lyd_free_all(tree);
871 lyd_free_all(envp);
872}
873
874static void
Michal Vasko45791ad2021-06-17 08:45:03 +0200875test_filter_attributes(void **state)
876{
877 const char *data;
878 struct ly_in *in;
879 struct lyd_node *tree;
880 const struct lyd_node *node;
881 const char *dsc;
882 const char *ref = "RFC 6241, Section 7.7";
883 const char *feats[] = {"writable-running", NULL};
884
885 assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf", "2011-06-01", feats)));
Michal Vasko1b2a3f42022-12-20 09:38:28 +0100886 assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "notifications", "2008-07-14", NULL)));
Michal Vasko45791ad2021-06-17 08:45:03 +0200887
888 data = "<get xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
889 " <filter type=\"xpath\" select=\"/*\"/>\n"
890 "</get>\n";
891 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
892 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_YANG, &tree, NULL));
893 ly_in_free(in, 0);
894 assert_non_null(tree);
895
896 node = tree;
897 dsc = "Retrieve running configuration and device state information.";
898 CHECK_LYSC_ACTION((struct lysc_node_action *)node->schema, dsc, 0, LYS_STATUS_CURR,
899 1, 0, 0, 1, "get", LYS_RPC,
900 1, 0, 0, 0, 0, ref, 0);
901 node = lyd_child(node);
902 dsc = "This parameter specifies the portion of the system\nconfiguration and state data to retrieve.";
903 CHECK_LYSC_NODE(node->schema, dsc, 1, LYS_STATUS_CURR | LYS_IS_INPUT, 1, "filter", 0, LYS_ANYXML, 1, 0, NULL, 0);
904
Michal Vasko1b2a3f42022-12-20 09:38:28 +0100905 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
906 lyd_free_all(tree);
Michal Vasko45791ad2021-06-17 08:45:03 +0200907
Michal Vasko1b2a3f42022-12-20 09:38:28 +0100908 data = "<create-subscription xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n"
909 " <filter type=\"subtree\">\n"
910 " <inner-node xmlns=\"my:urn\"/>\n"
911 " </filter>\n"
912 "</create-subscription>\n";
913 assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
914 assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_YANG, &tree, NULL));
915 ly_in_free(in, 0);
916 assert_non_null(tree);
917
918 CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
Michal Vasko45791ad2021-06-17 08:45:03 +0200919 lyd_free_all(tree);
920}
921
922static void
aPiecek9cdb9e62021-05-18 09:46:20 +0200923test_data_skip(void **state)
924{
925 const char *data;
926 struct lyd_node *tree;
927 struct lyd_node_term *leaf;
928
929 /* add invalid data to a module that is not implemented */
930 data = "<foo xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\"><u/></foo>";
931 assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(_UC->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
932 assert_null(tree);
933
934 /* add invalid data to a module that is implemented */
935 data = "<fooX xmlns=\"urn:tests:a\"><u/><list><value/></list></fooX>";
936 assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(_UC->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
937 assert_null(tree);
938
939 /* first invalid, next valid */
940 data = "<fooX xmlns=\"urn:tests:a\"><u/></fooX> <foo xmlns=\"urn:tests:a\">foo value</foo>";
941 CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
942 CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "foo", 1, LYS_LEAF, 0, 0, NULL, 0);
943 leaf = (struct lyd_node_term *)tree;
944 CHECK_LYD_VALUE(leaf->value, STRING, "foo value");
945 lyd_free_all(tree);
946}
947
Radek Krejcib4ac5a92020-11-23 17:54:33 +0100948int
949main(void)
Radek Krejci509e2592019-05-15 16:30:48 +0200950{
951 const struct CMUnitTest tests[] = {
Radek Iša56ca9e42020-09-08 18:42:00 +0200952 UTEST(test_leaf, setup),
953 UTEST(test_anydata, setup),
Michal Vasko5b414dd2023-04-13 10:29:58 +0200954 UTEST(test_anyxml, setup),
Radek Iša56ca9e42020-09-08 18:42:00 +0200955 UTEST(test_list, setup),
956 UTEST(test_container, setup),
957 UTEST(test_opaq, setup),
958 UTEST(test_rpc, setup),
959 UTEST(test_action, setup),
960 UTEST(test_notification, setup),
961 UTEST(test_reply, setup),
Michal Vaskoe0665742021-02-11 11:08:44 +0100962 UTEST(test_netconf_rpc, setup),
963 UTEST(test_netconf_action, setup),
964 UTEST(test_netconf_reply_or_notification, setup),
Michal Vasko820efe82023-05-12 15:47:43 +0200965 UTEST(test_restconf_rpc, setup),
966 UTEST(test_restconf_reply, setup),
Michal Vasko45791ad2021-06-17 08:45:03 +0200967 UTEST(test_filter_attributes, setup),
aPiecek9cdb9e62021-05-18 09:46:20 +0200968 UTEST(test_data_skip, setup),
Radek Krejci509e2592019-05-15 16:30:48 +0200969 };
970
971 return cmocka_run_group_tests(tests, NULL, NULL);
972}