blob: 17a4c94a43f5e3ba2332d6662475c1c8bae9068a [file] [log] [blame]
Michal Vaskoddd76592022-01-17 13:34:48 +01001/**
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +01002 * @file test_schema_mount.c
Michal Vaskoddd76592022-01-17 13:34:48 +01003 * @author Tadeas Vintrlik <xvintr04@stud.fit.vutbr.cz>
4 * @author Michal Vasko <mvasko@cesnet.cz>
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +01005 * @brief unit tests for Schema Mount extension support
6 *
Michal Vaskoddd76592022-01-17 13:34:48 +01007 * Copyright (c) 2021 - 2022 CESNET, z.s.p.o.
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +01008 *
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 */
Michal Vaskoddd76592022-01-17 13:34:48 +010015
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +010016#define _UTEST_MAIN_
17#include "utests.h"
18
19#include "libyang.h"
20
Michal Vaskoddd76592022-01-17 13:34:48 +010021void **glob_state;
22
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +010023static int
24setup(void **state)
25{
Michal Vaskoddd76592022-01-17 13:34:48 +010026 const char *schema =
27 "module sm {yang-version 1.1;namespace \"urn:sm\";prefix \"sm\";"
28 "import ietf-yang-schema-mount {prefix yangmnt;}"
29 "import ietf-interfaces {prefix if;}"
30 "container root {yangmnt:mount-point \"root\";}"
31 "container root2 {yangmnt:mount-point \"root\";}"
32 "container root3 {"
33 " list ls { key name; leaf name {type string;}"
Michal Vasko61ad1ff2022-02-10 15:48:39 +010034 " yangmnt:mount-point \"mnt-root\";"
Michal Vaskoddd76592022-01-17 13:34:48 +010035 " }"
36 "}"
Michal Vasko9e12ffe2022-09-21 15:11:30 +020037 "container root4 {config false; yangmnt:mount-point \"root\";}"
Michal Vaskoddd76592022-01-17 13:34:48 +010038 "leaf target{type string;}"
39 "augment /if:interfaces/if:interface {"
40 " leaf sm-name {type leafref {path \"/sm:target\";}}"
41 "}"
42 "}";
43
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +010044 UTEST_SETUP;
Michal Vaskoddd76592022-01-17 13:34:48 +010045 glob_state = state;
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +010046
47 assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
Michal Vaskoddd76592022-01-17 13:34:48 +010048 assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL));
49 assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "iana-if-type", NULL, NULL));
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +010050
51 return 0;
52}
53
54static void
Michal Vaskoddd76592022-01-17 13:34:48 +010055test_schema(void **state)
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +010056{
57 struct lys_module *mod;
Michal Vaskoddd76592022-01-17 13:34:48 +010058 const char *schema;
59 char *str;
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +010060
Michal Vaskoddd76592022-01-17 13:34:48 +010061 /* invalid */
62 schema =
63 "module sm {\n"
64 " namespace \"urn:sm\";\n"
65 " prefix sm;\n"
66 "\n"
67 " import ietf-yang-schema-mount {\n"
68 " prefix yangmnt;\n"
69 " }\n"
70 "\n"
71 " container root {\n"
72 " yangmnt:mount-point \"root\";\n"
73 " }\n"
74 "}\n";
75 assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL));
Michal Vasko193dacd2022-10-13 08:43:05 +020076 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vaskoddd76592022-01-17 13:34:48 +010077 "Extension \"yangmnt:mount-point\" instance not allowed in YANG version 1 module.",
Michal Vasko6727c682023-02-17 10:40:26 +010078 "Path \"/sm:root/{extension='yangmnt:mount-point'}/root\".");
Michal Vaskoddd76592022-01-17 13:34:48 +010079
80 schema =
81 "module sm {\n"
82 " yang-version 1.1;\n"
83 " namespace \"urn:sm\";\n"
84 " prefix sm;\n"
85 "\n"
86 " import ietf-yang-schema-mount {\n"
87 " prefix yangmnt;\n"
88 " }\n"
89 "\n"
90 " yangmnt:mount-point \"root\";\n"
91 "}\n";
92 assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL));
Michal Vasko193dacd2022-10-13 08:43:05 +020093 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vaskoddd76592022-01-17 13:34:48 +010094 "Extension \"yangmnt:mount-point\" instance allowed only in container or list statement.",
Michal Vasko6727c682023-02-17 10:40:26 +010095 "Path \"/sm:{extension='yangmnt:mount-point'}/root\".");
Michal Vaskoddd76592022-01-17 13:34:48 +010096
97 schema =
98 "module sm {\n"
99 " yang-version 1.1;\n"
100 " namespace \"urn:sm\";\n"
101 " prefix sm;\n"
102 "\n"
103 " import ietf-yang-schema-mount {\n"
104 " prefix yangmnt;\n"
105 " }\n"
106 "\n"
107 " container root {\n"
108 " leaf l {\n"
109 " type empty;\n"
110 " yangmnt:mount-point \"root\";\n"
111 " }\n"
112 " }\n"
113 "}\n";
114 assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL));
Michal Vasko193dacd2022-10-13 08:43:05 +0200115 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vaskoddd76592022-01-17 13:34:48 +0100116 "Extension \"yangmnt:mount-point\" instance allowed only in container or list statement.",
Michal Vasko6727c682023-02-17 10:40:26 +0100117 "Path \"/sm:root/l/{extension='yangmnt:mount-point'}/root\".");
Michal Vaskoddd76592022-01-17 13:34:48 +0100118
119 schema =
120 "module sm {\n"
121 " yang-version 1.1;\n"
122 " namespace \"urn:sm\";\n"
123 " prefix sm;\n"
124 "\n"
125 " import ietf-yang-schema-mount {\n"
126 " prefix yangmnt;\n"
127 " }\n"
128 "\n"
129 " list l {\n"
130 " key \"k\";\n"
131 " leaf k {\n"
132 " type string;\n"
133 " }\n"
134 " yangmnt:mount-point \"root\";\n"
135 " yangmnt:mount-point \"root2\";\n"
136 " }\n"
137 "}\n";
138 assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL));
Michal Vasko193dacd2022-10-13 08:43:05 +0200139 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vaskoddd76592022-01-17 13:34:48 +0100140 "Multiple extension \"yangmnt:mount-point\" instances.",
Michal Vasko6727c682023-02-17 10:40:26 +0100141 "Path \"/sm:l/{extension='yangmnt:mount-point'}/root\".");
Michal Vaskoddd76592022-01-17 13:34:48 +0100142
143 /* valid */
144 schema =
145 "module sm {\n"
146 " yang-version 1.1;\n"
147 " namespace \"urn:sm\";\n"
148 " prefix sm;\n"
149 "\n"
150 " import ietf-yang-schema-mount {\n"
151 " prefix yangmnt;\n"
152 " }\n"
153 "\n"
154 " container root {\n"
155 " yangmnt:mount-point \"root\";\n"
156 " }\n"
157 "}\n";
158 assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, &mod));
Michal Vasko193dacd2022-10-13 08:43:05 +0200159 lys_print_mem(&str, mod, LYS_OUT_YANG, 0);
Michal Vaskoddd76592022-01-17 13:34:48 +0100160 assert_string_equal(str, schema);
161 free(str);
162}
163
164static LY_ERR
165test_ext_data_clb(const struct lysc_ext_instance *ext, void *user_data, void **ext_data, ly_bool *ext_data_free)
166{
167 void **state = glob_state;
168 struct lyd_node *data = NULL;
169
170 (void)ext;
171
172 if (user_data) {
173 CHECK_PARSE_LYD_PARAM(user_data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
174 }
175
176 *ext_data = data;
177 *ext_data_free = 1;
178 return LY_SUCCESS;
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +0100179}
180
181static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100182test_parse_invalid(void **state)
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +0100183{
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100184 const char *xml, *json;
Michal Vaskoddd76592022-01-17 13:34:48 +0100185 struct lyd_node *data;
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +0100186
Michal Vaskoddd76592022-01-17 13:34:48 +0100187 /* no callback set */
188 xml =
189 "<root xmlns=\"urn:sm\">"
190 " <unknown xmlns=\"unknown\">"
191 " <interface>"
192 " <name>bu</name>"
193 " <type xmlns:ii=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ii:ethernetCsmacd</type>"
194 " </interface>"
195 " </unknown>"
196 "</root>";
197 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EINVAL, data);
Michal Vasko193dacd2022-10-13 08:43:05 +0200198 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": Failed to get extension data, no callback set.",
Michal Vaskoddd76592022-01-17 13:34:48 +0100199 NULL);
200
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100201 json =
202 "{"
203 " \"sm:root\": {"
204 " \"unknown:unknown\": {"
205 " \"interface\": ["
206 " {"
207 " \"name\": \"bu\","
208 " \"type\": \"iana-if-type:ethernetCsmacd\""
209 " }"
210 " ]"
211 " }"
212 " }"
213 "}";
214 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, 0, LYD_VALIDATE_PRESENT, LY_EINVAL, data);
Michal Vasko193dacd2022-10-13 08:43:05 +0200215 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": Failed to get extension data, no callback set.",
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100216 NULL);
217
Michal Vaskoddd76592022-01-17 13:34:48 +0100218 /* unknown data */
219 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb, NULL);
220 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
221 assert_string_equal(LYD_NAME(data), "root");
222 assert_null(lyd_child(data));
223 assert_non_null(data->next);
224 assert_true(data->next->flags & LYD_DEFAULT);
225 lyd_free_siblings(data);
226
227 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
228 CHECK_LOG_CTX("No module with namespace \"unknown\" in the context.",
Michal Vaskodbf3e652022-10-21 08:46:25 +0200229 "Data location \"/sm:root\", line number 1.");
Michal Vaskoddd76592022-01-17 13:34:48 +0100230
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100231 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
232 assert_string_equal(LYD_NAME(data), "root");
233 assert_null(lyd_child(data));
234 assert_non_null(data->next);
235 assert_true(data->next->flags & LYD_DEFAULT);
236 lyd_free_siblings(data);
237
238 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
239 CHECK_LOG_CTX("No module named \"unknown\" in the context.",
Michal Vaskodbf3e652022-10-21 08:46:25 +0200240 "Data location \"/sm:root\", line number 1.");
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100241
Michal Vaskoddd76592022-01-17 13:34:48 +0100242 /* missing required callback data */
243 xml =
244 "<root xmlns=\"urn:sm\">"
245 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">"
246 " <interface>"
247 " <name>bu</name>"
248 " </interface>"
249 " </interfaces>"
250 "</root>";
251 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
252 CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.",
Michal Vaskodbf3e652022-10-21 08:46:25 +0200253 "Data location \"/sm:root\", line number 1.");
Michal Vaskoddd76592022-01-17 13:34:48 +0100254
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100255 json =
256 "{"
257 " \"sm:root\": {"
258 " \"ietf-interfaces:interfaces\": {"
259 " \"interface\": ["
260 " {"
261 " \"name\": \"bu\""
262 " }"
263 " ]"
264 " }"
265 " }"
266 "}";
267 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
268 CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.",
Michal Vaskodbf3e652022-10-21 08:46:25 +0200269 "Data location \"/sm:root\", line number 1.");
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100270
Michal Vaskoddd76592022-01-17 13:34:48 +0100271 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
272 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
273 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
274 " <module-set>"
275 " <name>test-set</name>"
276 " <module>"
277 " <name>ietf-yang-library</name>"
278 " <revision>2019-01-04</revision>"
279 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
280 " </module>"
281 " </module-set>"
282 " <schema>"
283 " <name>test-schema</name>"
284 " <module-set>test-set</module-set>"
285 " </schema>"
286 " <datastore>"
287 " <name>ds:running</name>"
288 " <schema>test-schema</schema>"
289 " </datastore>"
290 " <datastore>"
291 " <name>ds:operational</name>"
292 " <schema>test-schema</schema>"
293 " </datastore>"
294 " <content-id>1</content-id>"
295 "</yang-library>"
296 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
297 " <module-set-id>1</module-set-id>"
298 "</modules-state>");
299 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vaskof8ebf132022-11-21 14:06:48 +0100300 CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.",
301 "Data location \"/sm:root\", line number 1.");
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100302 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vaskof8ebf132022-11-21 14:06:48 +0100303 CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.",
304 "Data location \"/sm:root\", line number 1.");
Michal Vaskoddd76592022-01-17 13:34:48 +0100305
306 /* missing module in yang-library data */
307 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
308 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
309 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
310 " <module-set>"
311 " <name>test-set</name>"
312 " <module>"
313 " <name>ietf-yang-library</name>"
314 " <revision>2019-01-04</revision>"
315 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
316 " </module>"
317 " </module-set>"
318 " <schema>"
319 " <name>test-schema</name>"
320 " <module-set>test-set</module-set>"
321 " </schema>"
322 " <datastore>"
323 " <name>ds:running</name>"
324 " <schema>test-schema</schema>"
325 " </datastore>"
326 " <datastore>"
327 " <name>ds:operational</name>"
328 " <schema>test-schema</schema>"
329 " </datastore>"
330 " <content-id>1</content-id>"
331 "</yang-library>"
332 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
333 " <module-set-id>1</module-set-id>"
334 "</modules-state>"
335 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
336 " <mount-point>"
337 " <module>sm</module>"
338 " <label>root</label>"
339 " <inline/>"
340 " </mount-point>"
341 "</schema-mounts>");
342 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vaskof8ebf132022-11-21 14:06:48 +0100343 CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.",
344 "Data location \"/sm:root\", line number 1.");
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100345 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vaskof8ebf132022-11-21 14:06:48 +0100346 CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.",
347 "Data location \"/sm:root\", line number 1.");
Michal Vaskoddd76592022-01-17 13:34:48 +0100348
349 /* callback data correct, invalid YANG data */
350 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
351 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
352 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
353 " <module-set>"
354 " <name>test-set</name>"
355 " <module>"
356 " <name>ietf-datastores</name>"
357 " <revision>2018-02-14</revision>"
358 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
359 " </module>"
360 " <module>"
361 " <name>ietf-yang-library</name>"
362 " <revision>2019-01-04</revision>"
363 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
364 " </module>"
365 " <module>"
366 " <name>ietf-yang-schema-mount</name>"
367 " <revision>2019-01-14</revision>"
368 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
369 " </module>"
370 " <module>"
371 " <name>ietf-interfaces</name>"
372 " <revision>2014-05-08</revision>"
373 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
374 " </module>"
375 " <module>"
376 " <name>iana-if-type</name>"
377 " <revision>2014-05-08</revision>"
378 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
379 " </module>"
380 " <import-only-module>"
381 " <name>ietf-yang-types</name>"
382 " <revision>2013-07-15</revision>"
383 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
384 " </import-only-module>"
385 " </module-set>"
386 " <schema>"
387 " <name>test-schema</name>"
388 " <module-set>test-set</module-set>"
389 " </schema>"
390 " <datastore>"
391 " <name>ds:running</name>"
392 " <schema>test-schema</schema>"
393 " </datastore>"
394 " <datastore>"
395 " <name>ds:operational</name>"
396 " <schema>test-schema</schema>"
397 " </datastore>"
398 " <content-id>1</content-id>"
399 "</yang-library>"
400 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
401 " <module-set-id>1</module-set-id>"
402 "</modules-state>"
403 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
404 " <mount-point>"
405 " <module>sm</module>"
406 " <label>root</label>"
407 " <inline/>"
408 " </mount-point>"
409 "</schema-mounts>");
410 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vasko193dacd2022-10-13 08:43:05 +0200411 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vaskoddd76592022-01-17 13:34:48 +0100412 "Mandatory node \"type\" instance does not exist.",
Michal Vasko6727c682023-02-17 10:40:26 +0100413 "Data location \"/ietf-interfaces:interfaces/interface[name='bu']\".");
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100414 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vasko193dacd2022-10-13 08:43:05 +0200415 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100416 "Mandatory node \"type\" instance does not exist.",
Michal Vasko6727c682023-02-17 10:40:26 +0100417 "Data location \"/ietf-interfaces:interfaces/interface[name='bu']\".");
Michal Vaskoddd76592022-01-17 13:34:48 +0100418
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100419 /* same validation fail in separate validation */
Michal Vaskoddd76592022-01-17 13:34:48 +0100420 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT | LYD_PARSE_ONLY, 0, LY_SUCCESS, data);
421 assert_int_equal(LY_EVALID, lyd_validate_all(&data, NULL, LYD_VALIDATE_PRESENT, NULL));
Michal Vasko193dacd2022-10-13 08:43:05 +0200422 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100423 "Mandatory node \"type\" instance does not exist.",
Michal Vasko6727c682023-02-17 10:40:26 +0100424 "Data location \"/ietf-interfaces:interfaces/interface[name='bu']\".");
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100425 lyd_free_siblings(data);
426
427 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT | LYD_PARSE_ONLY, 0, LY_SUCCESS, data);
428 assert_int_equal(LY_EVALID, lyd_validate_all(&data, NULL, LYD_VALIDATE_PRESENT, NULL));
Michal Vasko193dacd2022-10-13 08:43:05 +0200429 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100430 "Mandatory node \"type\" instance does not exist.",
Michal Vasko6727c682023-02-17 10:40:26 +0100431 "Data location \"/ietf-interfaces:interfaces/interface[name='bu']\".");
Michal Vaskoddd76592022-01-17 13:34:48 +0100432 lyd_free_siblings(data);
433
434 /* success */
435 xml =
436 "<root xmlns=\"urn:sm\">\n"
437 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
438 " <interface>\n"
439 " <name>bu</name>\n"
440 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
441 " </interface>\n"
442 " </interfaces>\n"
443 "</root>\n";
444 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
445 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
446 lyd_free_siblings(data);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100447
448 json =
449 "{\n"
450 " \"sm:root\": {\n"
451 " \"ietf-interfaces:interfaces\": {\n"
452 " \"interface\": [\n"
453 " {\n"
454 " \"name\": \"bu\",\n"
455 " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
456 " }\n"
457 " ]\n"
458 " }\n"
459 " }\n"
460 "}\n";
461 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
462 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
463 lyd_free_siblings(data);
Michal Vaskoddd76592022-01-17 13:34:48 +0100464}
465
466static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100467test_parse_inline(void **state)
Michal Vaskoddd76592022-01-17 13:34:48 +0100468{
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100469 const char *xml, *json;
Michal Vasko9883a3e2022-03-31 12:16:00 +0200470 char *lyb;
Michal Vaskoddd76592022-01-17 13:34:48 +0100471 struct lyd_node *data;
Michal Vasko27653162022-11-21 13:58:44 +0100472 const struct ly_ctx *ext_ctx;
Michal Vaskoddd76592022-01-17 13:34:48 +0100473
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100474 /* valid */
Michal Vaskoddd76592022-01-17 13:34:48 +0100475 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
476 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
477 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
478 " <module-set>"
479 " <name>test-set</name>"
480 " <module>"
481 " <name>ietf-datastores</name>"
482 " <revision>2018-02-14</revision>"
483 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
484 " </module>"
485 " <module>"
486 " <name>ietf-yang-library</name>"
487 " <revision>2019-01-04</revision>"
488 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
489 " </module>"
490 " <module>"
491 " <name>ietf-yang-schema-mount</name>"
492 " <revision>2019-01-14</revision>"
493 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
494 " </module>"
495 " <module>"
496 " <name>ietf-interfaces</name>"
497 " <revision>2014-05-08</revision>"
498 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
499 " </module>"
500 " <module>"
501 " <name>iana-if-type</name>"
502 " <revision>2014-05-08</revision>"
503 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
504 " </module>"
505 " <import-only-module>"
506 " <name>ietf-yang-types</name>"
507 " <revision>2013-07-15</revision>"
508 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
509 " </import-only-module>"
510 " </module-set>"
511 " <schema>"
512 " <name>test-schema</name>"
513 " <module-set>test-set</module-set>"
514 " </schema>"
515 " <datastore>"
516 " <name>ds:running</name>"
517 " <schema>test-schema</schema>"
518 " </datastore>"
519 " <datastore>"
520 " <name>ds:operational</name>"
521 " <schema>test-schema</schema>"
522 " </datastore>"
523 " <content-id>1</content-id>"
524 "</yang-library>"
525 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
526 " <module-set-id>1</module-set-id>"
527 "</modules-state>"
528 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
529 " <mount-point>"
530 " <module>sm</module>"
531 " <label>root</label>"
532 " <inline/>"
533 " </mount-point>"
534 "</schema-mounts>");
535 xml =
536 "<root xmlns=\"urn:sm\">\n"
537 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
538 " <interface>\n"
539 " <name>bu</name>\n"
540 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
541 " </interface>\n"
542 " </interfaces>\n"
543 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
544 " <interface>\n"
545 " <name>bu</name>\n"
546 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
547 " <oper-status>not-present</oper-status>\n"
548 " <statistics>\n"
549 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
550 " </statistics>\n"
551 " </interface>\n"
552 " </interfaces-state>\n"
553 "</root>\n";
554 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
555 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
Michal Vasko27653162022-11-21 13:58:44 +0100556 ext_ctx = LYD_CTX(lyd_child(data));
Michal Vaskoddd76592022-01-17 13:34:48 +0100557 lyd_free_siblings(data);
558
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100559 json =
560 "{\n"
561 " \"sm:root\": {\n"
562 " \"ietf-interfaces:interfaces\": {\n"
563 " \"interface\": [\n"
564 " {\n"
565 " \"name\": \"bu\",\n"
566 " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
567 " }\n"
568 " ]\n"
569 " },\n"
570 " \"ietf-interfaces:interfaces-state\": {\n"
571 " \"interface\": [\n"
572 " {\n"
573 " \"name\": \"bu\",\n"
574 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
575 " \"oper-status\": \"not-present\",\n"
576 " \"statistics\": {\n"
577 " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n"
578 " }\n"
579 " }\n"
580 " ]\n"
581 " }\n"
582 " }\n"
583 "}\n";
584 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
585 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
Michal Vasko27653162022-11-21 13:58:44 +0100586 assert_ptr_equal(ext_ctx, LYD_CTX(lyd_child(data)));
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100587 lyd_free_siblings(data);
588
Michal Vasko27653162022-11-21 13:58:44 +0100589 /* different yang-lib data with the same content-id */
Michal Vaskoddd76592022-01-17 13:34:48 +0100590 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
591 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
592 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
593 " <module-set>"
594 " <name>test-set</name>"
595 " <module>"
596 " <name>ietf-datastores</name>"
597 " <revision>2018-02-14</revision>"
598 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
599 " </module>"
600 " <module>"
601 " <name>ietf-yang-library</name>"
602 " <revision>2019-01-04</revision>"
603 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
604 " </module>"
605 " <module>"
606 " <name>ietf-yang-schema-mount</name>"
607 " <revision>2019-01-14</revision>"
608 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
609 " </module>"
610 " <module>"
611 " <name>ietf-interfaces</name>"
612 " <revision>2014-05-08</revision>"
613 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
614 " </module>"
615 " <module>"
616 " <name>ietf-ip</name>"
617 " <revision>2014-06-16</revision>"
618 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
619 " </module>"
620 " <module>"
621 " <name>iana-if-type</name>"
622 " <revision>2014-05-08</revision>"
623 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
624 " </module>"
625 " <import-only-module>"
626 " <name>ietf-yang-types</name>"
627 " <revision>2013-07-15</revision>"
628 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
629 " </import-only-module>"
630 " </module-set>"
631 " <schema>"
632 " <name>test-schema</name>"
633 " <module-set>test-set</module-set>"
634 " </schema>"
635 " <datastore>"
636 " <name>ds:running</name>"
637 " <schema>test-schema</schema>"
638 " </datastore>"
639 " <datastore>"
640 " <name>ds:operational</name>"
641 " <schema>test-schema</schema>"
642 " </datastore>"
643 " <content-id>1</content-id>"
644 "</yang-library>"
645 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
646 " <module-set-id>1</module-set-id>"
647 "</modules-state>"
648 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
649 " <mount-point>"
650 " <module>sm</module>"
651 " <label>root</label>"
652 " <inline/>"
653 " </mount-point>"
654 "</schema-mounts>");
655 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
656 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
Michal Vasko27653162022-11-21 13:58:44 +0100657 assert_ptr_not_equal(ext_ctx, LYD_CTX(lyd_child(data)));
658 ext_ctx = LYD_CTX(lyd_child(data));
Michal Vaskoddd76592022-01-17 13:34:48 +0100659 lyd_free_siblings(data);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100660
661 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
662 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
Michal Vasko27653162022-11-21 13:58:44 +0100663 assert_ptr_equal(ext_ctx, LYD_CTX(lyd_child(data)));
Michal Vasko9883a3e2022-03-31 12:16:00 +0200664
665 assert_int_equal(LY_SUCCESS, lyd_print_mem(&lyb, data, LYD_LYB, 0));
666 lyd_free_siblings(data);
667
668 CHECK_PARSE_LYD_PARAM(lyb, LYD_LYB, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
Michal Vasko27653162022-11-21 13:58:44 +0100669 assert_ptr_equal(ext_ctx, LYD_CTX(lyd_child(data)));
Michal Vasko9883a3e2022-03-31 12:16:00 +0200670 free(lyb);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100671 lyd_free_siblings(data);
Michal Vaskoddd76592022-01-17 13:34:48 +0100672}
673
674static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100675test_parse_shared(void **state)
Michal Vaskoddd76592022-01-17 13:34:48 +0100676{
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100677 const char *xml, *json;
Michal Vasko9883a3e2022-03-31 12:16:00 +0200678 char *lyb;
Michal Vaskoddd76592022-01-17 13:34:48 +0100679 struct lyd_node *data;
680
681 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
682 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
683 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
684 " <module-set>"
685 " <name>test-set</name>"
686 " <module>"
687 " <name>ietf-datastores</name>"
688 " <revision>2018-02-14</revision>"
689 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
690 " </module>"
691 " <module>"
692 " <name>ietf-yang-library</name>"
693 " <revision>2019-01-04</revision>"
694 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
695 " </module>"
696 " <module>"
697 " <name>ietf-yang-schema-mount</name>"
698 " <revision>2019-01-14</revision>"
699 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
700 " </module>"
701 " <module>"
702 " <name>ietf-interfaces</name>"
703 " <revision>2014-05-08</revision>"
704 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
705 " </module>"
706 " <module>"
707 " <name>iana-if-type</name>"
708 " <revision>2014-05-08</revision>"
709 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
710 " </module>"
711 " <import-only-module>"
712 " <name>ietf-yang-types</name>"
713 " <revision>2013-07-15</revision>"
714 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
715 " </import-only-module>"
716 " </module-set>"
717 " <schema>"
718 " <name>test-schema</name>"
719 " <module-set>test-set</module-set>"
720 " </schema>"
721 " <datastore>"
722 " <name>ds:running</name>"
723 " <schema>test-schema</schema>"
724 " </datastore>"
725 " <datastore>"
726 " <name>ds:operational</name>"
727 " <schema>test-schema</schema>"
728 " </datastore>"
729 " <content-id>1</content-id>"
730 "</yang-library>"
731 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
732 " <module-set-id>1</module-set-id>"
733 "</modules-state>"
734 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
735 " <mount-point>"
736 " <module>sm</module>"
737 " <label>root</label>"
738 " <shared-schema/>"
739 " </mount-point>"
740 "</schema-mounts>");
741 xml =
742 "<root xmlns=\"urn:sm\">\n"
743 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
744 " <interface>\n"
745 " <name>bu</name>\n"
746 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
747 " </interface>\n"
748 " </interfaces>\n"
749 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
750 " <interface>\n"
751 " <name>bu</name>\n"
752 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
753 " <oper-status>not-present</oper-status>\n"
754 " <statistics>\n"
755 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
756 " </statistics>\n"
757 " </interface>\n"
758 " </interfaces-state>\n"
759 "</root>\n";
760 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
761 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
762 lyd_free_siblings(data);
763
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100764 json =
765 "{\n"
766 " \"sm:root\": {\n"
767 " \"ietf-interfaces:interfaces\": {\n"
768 " \"interface\": [\n"
769 " {\n"
770 " \"name\": \"bu\",\n"
771 " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
772 " }\n"
773 " ]\n"
774 " },\n"
775 " \"ietf-interfaces:interfaces-state\": {\n"
776 " \"interface\": [\n"
777 " {\n"
778 " \"name\": \"bu\",\n"
779 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
780 " \"oper-status\": \"not-present\",\n"
781 " \"statistics\": {\n"
782 " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n"
783 " }\n"
784 " }\n"
785 " ]\n"
786 " }\n"
787 " }\n"
788 "}\n";
789 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
790 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
791 lyd_free_siblings(data);
792
Michal Vaskoddd76592022-01-17 13:34:48 +0100793 /* different yang-lib data */
794 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
795 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
796 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
797 " <module-set>"
798 " <name>test-set</name>"
799 " <module>"
800 " <name>ietf-datastores</name>"
801 " <revision>2018-02-14</revision>"
802 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
803 " </module>"
804 " <module>"
805 " <name>ietf-yang-library</name>"
806 " <revision>2019-01-04</revision>"
807 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
808 " </module>"
809 " <module>"
810 " <name>ietf-yang-schema-mount</name>"
811 " <revision>2019-01-14</revision>"
812 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
813 " </module>"
814 " <module>"
815 " <name>ietf-interfaces</name>"
816 " <revision>2014-05-08</revision>"
817 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
818 " </module>"
819 " <module>"
820 " <name>ietf-ip</name>"
821 " <revision>2014-06-16</revision>"
822 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
823 " </module>"
824 " <module>"
825 " <name>iana-if-type</name>"
826 " <revision>2014-05-08</revision>"
827 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
828 " </module>"
829 " <import-only-module>"
830 " <name>ietf-yang-types</name>"
831 " <revision>2013-07-15</revision>"
832 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
833 " </import-only-module>"
834 " </module-set>"
835 " <schema>"
836 " <name>test-schema</name>"
837 " <module-set>test-set</module-set>"
838 " </schema>"
839 " <datastore>"
840 " <name>ds:running</name>"
841 " <schema>test-schema</schema>"
842 " </datastore>"
843 " <datastore>"
844 " <name>ds:operational</name>"
845 " <schema>test-schema</schema>"
846 " </datastore>"
847 " <content-id>2</content-id>"
848 "</yang-library>"
849 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
850 " <module-set-id>1</module-set-id>"
851 "</modules-state>"
852 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
853 " <mount-point>"
854 " <module>sm</module>"
855 " <label>root</label>"
856 " <shared-schema/>"
857 " </mount-point>"
858 "</schema-mounts>");
859 xml =
860 "<root2 xmlns=\"urn:sm\">\n"
861 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
862 " <interface>\n"
863 " <name>bu</name>\n"
864 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
865 " </interface>\n"
866 " </interfaces>\n"
867 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
868 " <interface>\n"
869 " <name>bu</name>\n"
870 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
871 " <oper-status>not-present</oper-status>\n"
872 " <statistics>\n"
873 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
874 " </statistics>\n"
875 " </interface>\n"
876 " </interfaces-state>\n"
877 "</root2>\n";
878 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vasko193dacd2022-10-13 08:43:05 +0200879 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vaskoddd76592022-01-17 13:34:48 +0100880 "Shared-schema yang-library content-id \"2\" differs from \"1\" used previously.",
Michal Vasko6727c682023-02-17 10:40:26 +0100881 "Path \"/ietf-yang-library:yang-library/content-id\".");
Michal Vaskoddd76592022-01-17 13:34:48 +0100882
883 /* data for 2 mount points */
884 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
885 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
886 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
887 " <module-set>"
888 " <name>test-set</name>"
889 " <module>"
890 " <name>ietf-datastores</name>"
891 " <revision>2018-02-14</revision>"
892 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
893 " </module>"
894 " <module>"
895 " <name>ietf-yang-library</name>"
896 " <revision>2019-01-04</revision>"
897 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
898 " </module>"
899 " <module>"
900 " <name>ietf-yang-schema-mount</name>"
901 " <revision>2019-01-14</revision>"
902 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
903 " </module>"
904 " <module>"
905 " <name>ietf-interfaces</name>"
906 " <revision>2014-05-08</revision>"
907 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
908 " </module>"
909 " <module>"
910 " <name>iana-if-type</name>"
911 " <revision>2014-05-08</revision>"
912 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
913 " </module>"
914 " <import-only-module>"
915 " <name>ietf-yang-types</name>"
916 " <revision>2013-07-15</revision>"
917 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
918 " </import-only-module>"
919 " </module-set>"
920 " <schema>"
921 " <name>test-schema</name>"
922 " <module-set>test-set</module-set>"
923 " </schema>"
924 " <datastore>"
925 " <name>ds:running</name>"
926 " <schema>test-schema</schema>"
927 " </datastore>"
928 " <datastore>"
929 " <name>ds:operational</name>"
930 " <schema>test-schema</schema>"
931 " </datastore>"
932 " <content-id>1</content-id>"
933 "</yang-library>"
934 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
935 " <module-set-id>1</module-set-id>"
936 "</modules-state>"
937 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
938 " <mount-point>"
939 " <module>sm</module>"
940 " <label>root</label>"
941 " <shared-schema/>"
942 " </mount-point>"
943 "</schema-mounts>");
944 xml =
945 "<root xmlns=\"urn:sm\">\n"
946 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
947 " <interface>\n"
948 " <name>bu</name>\n"
949 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
950 " </interface>\n"
951 " </interfaces>\n"
952 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
953 " <interface>\n"
954 " <name>bu</name>\n"
955 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
956 " <oper-status>not-present</oper-status>\n"
957 " <statistics>\n"
958 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
959 " </statistics>\n"
960 " </interface>\n"
961 " </interfaces-state>\n"
962 "</root>\n"
963 "<root2 xmlns=\"urn:sm\">\n"
964 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
965 " <interface>\n"
966 " <name>fu</name>\n"
967 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:fddi</type>\n"
968 " </interface>\n"
969 " </interfaces>\n"
970 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
971 " <interface>\n"
972 " <name>fu</name>\n"
973 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:fddi</type>\n"
974 " <oper-status>down</oper-status>\n"
975 " <statistics>\n"
976 " <discontinuity-time>2020-01-01T10:00:00-00:00</discontinuity-time>\n"
977 " </statistics>\n"
978 " </interface>\n"
979 " </interfaces-state>\n"
980 "</root2>\n";
981 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
982 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
983 lyd_free_siblings(data);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100984
985 json =
986 "{\n"
987 " \"sm:root\": {\n"
988 " \"ietf-interfaces:interfaces\": {\n"
989 " \"interface\": [\n"
990 " {\n"
991 " \"name\": \"bu\",\n"
992 " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
993 " }\n"
994 " ]\n"
995 " },\n"
996 " \"ietf-interfaces:interfaces-state\": {\n"
997 " \"interface\": [\n"
998 " {\n"
999 " \"name\": \"bu\",\n"
1000 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
1001 " \"oper-status\": \"not-present\",\n"
1002 " \"statistics\": {\n"
1003 " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n"
1004 " }\n"
1005 " }\n"
1006 " ]\n"
1007 " }\n"
1008 " },\n"
1009 " \"sm:root2\": {\n"
1010 " \"ietf-interfaces:interfaces\": {\n"
1011 " \"interface\": [\n"
1012 " {\n"
1013 " \"name\": \"fu\",\n"
1014 " \"type\": \"iana-if-type:fddi\"\n"
1015 " }\n"
1016 " ]\n"
1017 " },\n"
1018 " \"ietf-interfaces:interfaces-state\": {\n"
1019 " \"interface\": [\n"
1020 " {\n"
1021 " \"name\": \"fu\",\n"
1022 " \"type\": \"iana-if-type:fddi\",\n"
1023 " \"oper-status\": \"down\",\n"
1024 " \"statistics\": {\n"
1025 " \"discontinuity-time\": \"2020-01-01T10:00:00-00:00\"\n"
1026 " }\n"
1027 " }\n"
1028 " ]\n"
1029 " }\n"
1030 " }\n"
1031 "}\n";
1032 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1033 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
Michal Vasko9883a3e2022-03-31 12:16:00 +02001034
1035 assert_int_equal(LY_SUCCESS, lyd_print_mem(&lyb, data, LYD_LYB, LYD_PRINT_WITHSIBLINGS));
1036 lyd_free_siblings(data);
1037
1038 CHECK_PARSE_LYD_PARAM(lyb, LYD_LYB, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1039 free(lyb);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001040 lyd_free_siblings(data);
Michal Vaskoddd76592022-01-17 13:34:48 +01001041}
1042
1043static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001044test_parse_shared_parent_ref(void **state)
Michal Vaskoddd76592022-01-17 13:34:48 +01001045{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001046 const char *xml, *json;
Michal Vaskoddd76592022-01-17 13:34:48 +01001047 struct lyd_node *data;
1048
1049 /* wrong leafref value */
1050 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
1051 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1052 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1053 " <module-set>"
1054 " <name>test-set</name>"
1055 " <module>"
1056 " <name>ietf-datastores</name>"
1057 " <revision>2018-02-14</revision>"
1058 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1059 " </module>"
1060 " <module>"
1061 " <name>ietf-yang-library</name>"
1062 " <revision>2019-01-04</revision>"
1063 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1064 " </module>"
1065 " <module>"
1066 " <name>ietf-yang-schema-mount</name>"
1067 " <revision>2019-01-14</revision>"
1068 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1069 " </module>"
1070 " <module>"
1071 " <name>sm</name>"
1072 " <namespace>urn:sm</namespace>"
1073 " </module>"
1074 " <module>"
1075 " <name>ietf-interfaces</name>"
1076 " <revision>2014-05-08</revision>"
1077 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
1078 " </module>"
1079 " <module>"
1080 " <name>iana-if-type</name>"
1081 " <revision>2014-05-08</revision>"
1082 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
1083 " </module>"
1084 " <import-only-module>"
1085 " <name>ietf-yang-types</name>"
1086 " <revision>2013-07-15</revision>"
1087 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
1088 " </import-only-module>"
1089 " </module-set>"
1090 " <schema>"
1091 " <name>test-schema</name>"
1092 " <module-set>test-set</module-set>"
1093 " </schema>"
1094 " <datastore>"
1095 " <name>ds:running</name>"
1096 " <schema>test-schema</schema>"
1097 " </datastore>"
1098 " <datastore>"
1099 " <name>ds:operational</name>"
1100 " <schema>test-schema</schema>"
1101 " </datastore>"
1102 " <content-id>1</content-id>"
1103 "</yang-library>"
1104 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1105 " <module-set-id>1</module-set-id>"
1106 "</modules-state>"
1107 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1108 " <namespace>"
1109 " <prefix>smp</prefix>"
1110 " <uri>urn:sm</uri>"
1111 " </namespace>"
1112 " <mount-point>"
1113 " <module>sm</module>"
1114 " <label>mnt-root</label>"
1115 " <shared-schema>"
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001116 " <parent-reference>/smp:target[. = current()/smp:name]</parent-reference>"
Michal Vaskoddd76592022-01-17 13:34:48 +01001117 " </shared-schema>"
1118 " </mount-point>"
1119 "</schema-mounts>");
1120 xml =
1121 "<root3 xmlns=\"urn:sm\">\n"
1122 " <ls>\n"
1123 " <name>target-value</name>\n"
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001124 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1125 " <interface>\n"
1126 " <name>bu</name>\n"
1127 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1128 " <sm-name xmlns=\"urn:sm\">target-value</sm-name>\n"
1129 " </interface>\n"
1130 " </interfaces>\n"
Michal Vaskoddd76592022-01-17 13:34:48 +01001131 " </ls>\n"
1132 "</root3>\n"
1133 "<target xmlns=\"urn:sm\">wrong-target-value</target>\n";
1134 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vasko193dacd2022-10-13 08:43:05 +02001135 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vasko5edfefd2022-08-05 10:07:11 +02001136 "Invalid leafref value \"target-value\" - no target instance \"/sm:target\" with the same value.",
Michal Vaskodbf3e652022-10-21 08:46:25 +02001137 "Data location \"/ietf-interfaces:interfaces/interface[name='bu']/sm:sm-name\".");
Michal Vaskoddd76592022-01-17 13:34:48 +01001138
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001139 json =
1140 "{\n"
1141 " \"sm:root3\": {\n"
1142 " \"ls\": ["
1143 " {\n"
1144 " \"name\": \"target-value\",\n"
1145 " \"ietf-interfaces:interfaces\": {\n"
1146 " \"interface\": [\n"
1147 " {\n"
1148 " \"name\": \"bu\",\n"
1149 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
1150 " \"sm:sm-name\": \"target-value\"\n"
1151 " }\n"
1152 " ]\n"
1153 " }\n"
1154 " }\n"
1155 " ]\n"
1156 " },\n"
1157 " \"sm:target\": \"wrong-target-value\"\n"
1158 "}\n";
1159 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vasko193dacd2022-10-13 08:43:05 +02001160 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vasko5edfefd2022-08-05 10:07:11 +02001161 "Invalid leafref value \"target-value\" - no target instance \"/sm:target\" with the same value.",
Michal Vaskof8ebf132022-11-21 14:06:48 +01001162 "Data location \"/ietf-interfaces:interfaces/interface[name='bu']/sm:sm-name\".");
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001163
Michal Vaskoddd76592022-01-17 13:34:48 +01001164 /* success */
1165 xml =
1166 "<root3 xmlns=\"urn:sm\">\n"
1167 " <ls>\n"
1168 " <name>target-value</name>\n"
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001169 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1170 " <interface>\n"
1171 " <name>bu</name>\n"
1172 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1173 " <sm-name xmlns=\"urn:sm\">target-value</sm-name>\n"
1174 " </interface>\n"
1175 " </interfaces>\n"
Michal Vaskoddd76592022-01-17 13:34:48 +01001176 " </ls>\n"
1177 "</root3>\n"
1178 "<target xmlns=\"urn:sm\">target-value</target>\n";
1179 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1180 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1181 lyd_free_siblings(data);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001182
1183 json =
1184 "{\n"
1185 " \"sm:root3\": {\n"
1186 " \"ls\": [\n"
1187 " {\n"
1188 " \"name\": \"target-value\",\n"
1189 " \"ietf-interfaces:interfaces\": {\n"
1190 " \"interface\": [\n"
1191 " {\n"
1192 " \"name\": \"bu\",\n"
1193 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
1194 " \"sm:sm-name\": \"target-value\"\n"
1195 " }\n"
1196 " ]\n"
1197 " }\n"
1198 " }\n"
1199 " ]\n"
1200 " },\n"
1201 " \"sm:target\": \"target-value\"\n"
1202 "}\n";
1203 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1204 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
1205 lyd_free_siblings(data);
Michal Vaskoddd76592022-01-17 13:34:48 +01001206}
1207
1208static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001209test_parse_config(void **state)
Michal Vaskoddd76592022-01-17 13:34:48 +01001210{
1211 const char *xml;
Michal Vasko24edeb92022-07-20 08:08:46 +02001212 char *lyb;
Michal Vaskoddd76592022-01-17 13:34:48 +01001213 struct lyd_node *data;
1214 const struct lyd_node *node;
1215
1216 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
1217 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1218 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1219 " <module-set>"
1220 " <name>test-set</name>"
1221 " <module>"
1222 " <name>ietf-datastores</name>"
1223 " <revision>2018-02-14</revision>"
1224 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1225 " </module>"
1226 " <module>"
1227 " <name>ietf-yang-library</name>"
1228 " <revision>2019-01-04</revision>"
1229 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1230 " </module>"
1231 " <module>"
1232 " <name>ietf-yang-schema-mount</name>"
1233 " <revision>2019-01-14</revision>"
1234 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1235 " </module>"
1236 " <module>"
1237 " <name>ietf-interfaces</name>"
1238 " <revision>2014-05-08</revision>"
1239 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
1240 " </module>"
1241 " <module>"
1242 " <name>iana-if-type</name>"
1243 " <revision>2014-05-08</revision>"
1244 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
1245 " </module>"
1246 " <import-only-module>"
1247 " <name>ietf-yang-types</name>"
1248 " <revision>2013-07-15</revision>"
1249 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
1250 " </import-only-module>"
1251 " </module-set>"
1252 " <schema>"
1253 " <name>test-schema</name>"
1254 " <module-set>test-set</module-set>"
1255 " </schema>"
1256 " <datastore>"
1257 " <name>ds:running</name>"
1258 " <schema>test-schema</schema>"
1259 " </datastore>"
1260 " <datastore>"
1261 " <name>ds:operational</name>"
1262 " <schema>test-schema</schema>"
1263 " </datastore>"
1264 " <content-id>1</content-id>"
1265 "</yang-library>"
1266 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1267 " <module-set-id>1</module-set-id>"
1268 "</modules-state>"
1269 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1270 " <mount-point>"
1271 " <module>sm</module>"
1272 " <label>root</label>"
1273 " <config>false</config>"
1274 " <inline/>"
1275 " </mount-point>"
1276 "</schema-mounts>");
1277 xml =
1278 "<root xmlns=\"urn:sm\">\n"
1279 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1280 " <interface>\n"
1281 " <name>bu</name>\n"
1282 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1283 " <enabled>true</enabled>\n"
1284 " </interface>\n"
1285 " </interfaces>\n"
1286 "</root>\n";
1287 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1288 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1289
1290 node = lyd_child(data);
1291 assert_string_equal(LYD_NAME(node), "interfaces");
1292 assert_true(node->schema->flags & LYS_CONFIG_R);
1293 node = lyd_child(node);
1294 assert_string_equal(LYD_NAME(node), "interface");
1295 assert_true(node->schema->flags & LYS_CONFIG_R);
1296 node = lyd_child(node);
1297 assert_string_equal(LYD_NAME(node), "name");
1298 assert_true(node->schema->flags & LYS_CONFIG_R);
1299 node = node->next;
1300 assert_string_equal(LYD_NAME(node), "type");
1301 assert_true(node->schema->flags & LYS_CONFIG_R);
1302
Michal Vasko24edeb92022-07-20 08:08:46 +02001303 lyd_print_mem(&lyb, data, LYD_LYB, 0);
1304 lyd_free_siblings(data);
1305 CHECK_PARSE_LYD_PARAM(lyb, LYD_LYB, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1306 free(lyb);
1307
1308 node = lyd_child(data);
1309 assert_string_equal(LYD_NAME(node), "interfaces");
1310 assert_true(node->schema->flags & LYS_CONFIG_R);
1311 node = lyd_child(node);
1312 assert_string_equal(LYD_NAME(node), "interface");
1313 assert_true(node->schema->flags & LYS_CONFIG_R);
1314 node = lyd_child(node);
1315 assert_string_equal(LYD_NAME(node), "name");
1316 assert_true(node->schema->flags & LYS_CONFIG_R);
1317 node = node->next;
1318 assert_string_equal(LYD_NAME(node), "type");
1319 assert_true(node->schema->flags & LYS_CONFIG_R);
1320
Michal Vaskoddd76592022-01-17 13:34:48 +01001321 lyd_free_siblings(data);
Michal Vasko9e12ffe2022-09-21 15:11:30 +02001322
1323 /* the same effect but use a config false mount point instead of the separate metadata node */
1324 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
1325 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1326 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1327 " <module-set>"
1328 " <name>test-set</name>"
1329 " <module>"
1330 " <name>ietf-datastores</name>"
1331 " <revision>2018-02-14</revision>"
1332 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1333 " </module>"
1334 " <module>"
1335 " <name>ietf-yang-library</name>"
1336 " <revision>2019-01-04</revision>"
1337 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1338 " </module>"
1339 " <module>"
1340 " <name>ietf-yang-schema-mount</name>"
1341 " <revision>2019-01-14</revision>"
1342 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1343 " </module>"
1344 " <module>"
1345 " <name>ietf-interfaces</name>"
1346 " <revision>2014-05-08</revision>"
1347 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
1348 " </module>"
1349 " <module>"
1350 " <name>iana-if-type</name>"
1351 " <revision>2014-05-08</revision>"
1352 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
1353 " </module>"
1354 " <import-only-module>"
1355 " <name>ietf-yang-types</name>"
1356 " <revision>2013-07-15</revision>"
1357 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
1358 " </import-only-module>"
1359 " </module-set>"
1360 " <schema>"
1361 " <name>test-schema</name>"
1362 " <module-set>test-set</module-set>"
1363 " </schema>"
1364 " <datastore>"
1365 " <name>ds:running</name>"
1366 " <schema>test-schema</schema>"
1367 " </datastore>"
1368 " <datastore>"
1369 " <name>ds:operational</name>"
1370 " <schema>test-schema</schema>"
1371 " </datastore>"
1372 " <content-id>1</content-id>"
1373 "</yang-library>"
1374 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1375 " <module-set-id>1</module-set-id>"
1376 "</modules-state>"
1377 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1378 " <mount-point>"
1379 " <module>sm</module>"
1380 " <label>root</label>"
1381 " <inline/>"
1382 " </mount-point>"
1383 "</schema-mounts>");
1384 xml =
1385 "<root4 xmlns=\"urn:sm\">\n"
1386 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1387 " <interface>\n"
1388 " <name>bu</name>\n"
1389 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1390 " <enabled>true</enabled>\n"
1391 " </interface>\n"
1392 " </interfaces>\n"
1393 "</root4>\n";
1394 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1395 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1396
1397 node = lyd_child(data->next->next->next);
1398 assert_string_equal(LYD_NAME(node), "interfaces");
1399 assert_true(node->schema->flags & LYS_CONFIG_R);
1400 node = lyd_child(node);
1401 assert_string_equal(LYD_NAME(node), "interface");
1402 assert_true(node->schema->flags & LYS_CONFIG_R);
1403 node = lyd_child(node);
1404 assert_string_equal(LYD_NAME(node), "name");
1405 assert_true(node->schema->flags & LYS_CONFIG_R);
1406 node = node->next;
1407 assert_string_equal(LYD_NAME(node), "type");
1408 assert_true(node->schema->flags & LYS_CONFIG_R);
1409
1410 lyd_free_siblings(data);
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +01001411}
1412
Michal Vasko8cc3f662022-03-29 11:25:51 +02001413static void
1414test_new(void **state)
1415{
1416 const char *xml;
1417 const struct lys_module *mod;
1418 struct lyd_node *data, *node;
1419
1420 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
1421 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1422 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1423 " <module-set>"
1424 " <name>test-set</name>"
1425 " <module>"
1426 " <name>ietf-datastores</name>"
1427 " <revision>2018-02-14</revision>"
1428 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1429 " </module>"
1430 " <module>"
1431 " <name>ietf-yang-library</name>"
1432 " <revision>2019-01-04</revision>"
1433 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1434 " </module>"
1435 " <module>"
1436 " <name>ietf-yang-schema-mount</name>"
1437 " <revision>2019-01-14</revision>"
1438 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1439 " </module>"
1440 " <module>"
1441 " <name>ietf-interfaces</name>"
1442 " <revision>2014-05-08</revision>"
1443 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
1444 " </module>"
1445 " <module>"
1446 " <name>iana-if-type</name>"
1447 " <revision>2014-05-08</revision>"
1448 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
1449 " </module>"
Michal Vasko35b29622022-07-22 14:12:56 +02001450 " <module>"
1451 " <name>ietf-ip</name>"
1452 " <revision>2014-06-16</revision>"
1453 " <namespace>urn:ietf:params:xml:ns:yang:ietf-ip</namespace>"
1454 " </module>"
Michal Vasko8cc3f662022-03-29 11:25:51 +02001455 " <import-only-module>"
1456 " <name>ietf-yang-types</name>"
1457 " <revision>2013-07-15</revision>"
1458 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
1459 " </import-only-module>"
1460 " </module-set>"
1461 " <schema>"
1462 " <name>test-schema</name>"
1463 " <module-set>test-set</module-set>"
1464 " </schema>"
1465 " <datastore>"
1466 " <name>ds:running</name>"
1467 " <schema>test-schema</schema>"
1468 " </datastore>"
1469 " <datastore>"
1470 " <name>ds:operational</name>"
1471 " <schema>test-schema</schema>"
1472 " </datastore>"
1473 " <content-id>1</content-id>"
1474 "</yang-library>"
1475 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1476 " <module-set-id>1</module-set-id>"
1477 "</modules-state>"
1478 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1479 " <mount-point>"
1480 " <module>sm</module>"
1481 " <label>root</label>"
1482 " <shared-schema/>"
1483 " </mount-point>"
1484 "</schema-mounts>");
1485 xml =
1486 "<root xmlns=\"urn:sm\">\n"
1487 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1488 " <interface>\n"
1489 " <name>bu</name>\n"
1490 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
Michal Vasko35b29622022-07-22 14:12:56 +02001491 " <ipv4 xmlns=\"urn:ietf:params:xml:ns:yang:ietf-ip\">\n"
1492 " <enabled>false</enabled>\n"
1493 " </ipv4>\n"
Michal Vasko8cc3f662022-03-29 11:25:51 +02001494 " </interface>\n"
1495 " </interfaces>\n"
1496 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1497 " <interface>\n"
1498 " <name>bu</name>\n"
1499 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1500 " <oper-status>not-present</oper-status>\n"
1501 " <statistics>\n"
1502 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
1503 " </statistics>\n"
1504 " </interface>\n"
1505 " </interfaces-state>\n"
1506 "</root>\n";
1507
1508 /* create the data manually with simple new functions */
1509 mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "sm");
1510 assert_non_null(mod);
1511 assert_int_equal(LY_SUCCESS, lyd_new_inner(NULL, mod, "root", 0, &data));
1512
1513 mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "ietf-interfaces");
1514 assert_non_null(mod);
1515 assert_int_equal(LY_SUCCESS, lyd_new_inner(data, mod, "interfaces", 0, &node));
1516 assert_int_equal(LY_SUCCESS, lyd_new_list(node, NULL, "interface", 0, &node, "bu"));
1517 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "type", "iana-if-type:ethernetCsmacd", 0, NULL));
Michal Vasko35b29622022-07-22 14:12:56 +02001518 mod = ly_ctx_get_module_implemented(LYD_CTX(node), "ietf-ip");
1519 assert_non_null(mod);
1520 assert_int_equal(LY_SUCCESS, lyd_new_inner(node, mod, "ipv4", 0, &node));
1521 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "enabled", "false", 0, NULL));
Michal Vasko8cc3f662022-03-29 11:25:51 +02001522
Michal Vasko35b29622022-07-22 14:12:56 +02001523 mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "ietf-interfaces");
1524 assert_non_null(mod);
Michal Vasko8cc3f662022-03-29 11:25:51 +02001525 assert_int_equal(LY_SUCCESS, lyd_new_inner(data, mod, "interfaces-state", 0, &node));
1526 assert_int_equal(LY_SUCCESS, lyd_new_list(node, NULL, "interface", 0, &node, "bu"));
1527 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "type", "iana-if-type:ethernetCsmacd", 0, NULL));
1528 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "oper-status", "not-present", 0, NULL));
1529 assert_int_equal(LY_SUCCESS, lyd_new_inner(node, NULL, "statistics", 0, &node));
1530 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "discontinuity-time", "2022-01-01T10:00:00-00:00", 0, NULL));
1531
1532 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1533 lyd_free_siblings(data);
1534
1535 /* create the data using lyd_new_path */
1536 assert_int_equal(LY_SUCCESS, lyd_new_path(NULL, UTEST_LYCTX,
1537 "/sm:root/ietf-interfaces:interfaces/interface[name='bu']/type", "iana-if-type:ethernetCsmacd", 0, &data));
1538 assert_int_equal(LY_SUCCESS, lyd_new_path(data, NULL,
Michal Vasko35b29622022-07-22 14:12:56 +02001539 "/sm:root/ietf-interfaces:interfaces/interface[name='bu']/ietf-ip:ipv4/enabled", "false", 0, NULL));
1540 assert_int_equal(LY_SUCCESS, lyd_new_path(data, NULL,
Michal Vasko8cc3f662022-03-29 11:25:51 +02001541 "/sm:root/ietf-interfaces:interfaces-state/interface[name='bu']/type", "iana-if-type:ethernetCsmacd", 0, NULL));
1542 assert_int_equal(LY_SUCCESS, lyd_new_path(data, NULL,
1543 "/sm:root/ietf-interfaces:interfaces-state/interface[name='bu']/oper-status", "not-present", 0, NULL));
1544 assert_int_equal(LY_SUCCESS, lyd_new_path(data, NULL,
1545 "/sm:root/ietf-interfaces:interfaces-state/interface[name='bu']/statistics/discontinuity-time",
1546 "2022-01-01T10:00:00-00:00", 0, NULL));
1547
1548 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1549 lyd_free_siblings(data);
1550}
1551
Michal Vaskoe482bb92023-02-01 11:41:41 +01001552static void
1553test_lys_getnext(void **state)
1554{
1555 const struct lysc_node *parent, *node;
1556 struct ly_ctx *sm_ctx;
1557
1558 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
1559 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1560 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1561 " <module-set>"
1562 " <name>test-set</name>"
1563 " <module>"
1564 " <name>ietf-datastores</name>"
1565 " <revision>2018-02-14</revision>"
1566 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1567 " </module>"
1568 " <module>"
1569 " <name>ietf-yang-library</name>"
1570 " <revision>2019-01-04</revision>"
1571 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1572 " </module>"
1573 " <module>"
1574 " <name>ietf-yang-schema-mount</name>"
1575 " <revision>2019-01-14</revision>"
1576 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1577 " </module>"
1578 " <module>"
1579 " <name>ietf-interfaces</name>"
1580 " <revision>2014-05-08</revision>"
1581 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
1582 " </module>"
1583 " <module>"
1584 " <name>iana-if-type</name>"
1585 " <revision>2014-05-08</revision>"
1586 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
1587 " </module>"
1588 " <module>"
1589 " <name>ietf-ip</name>"
1590 " <revision>2014-06-16</revision>"
1591 " <namespace>urn:ietf:params:xml:ns:yang:ietf-ip</namespace>"
1592 " </module>"
1593 " <import-only-module>"
1594 " <name>ietf-yang-types</name>"
1595 " <revision>2013-07-15</revision>"
1596 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
1597 " </import-only-module>"
1598 " </module-set>"
1599 " <schema>"
1600 " <name>test-schema</name>"
1601 " <module-set>test-set</module-set>"
1602 " </schema>"
1603 " <datastore>"
1604 " <name>ds:running</name>"
1605 " <schema>test-schema</schema>"
1606 " </datastore>"
1607 " <datastore>"
1608 " <name>ds:operational</name>"
1609 " <schema>test-schema</schema>"
1610 " </datastore>"
1611 " <content-id>1</content-id>"
1612 "</yang-library>"
1613 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1614 " <module-set-id>1</module-set-id>"
1615 "</modules-state>"
1616 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1617 " <mount-point>"
1618 " <module>sm</module>"
1619 " <label>root</label>"
1620 " <shared-schema/>"
1621 " </mount-point>"
1622 "</schema-mounts>");
1623
1624 parent = lys_find_path(UTEST_LYCTX, NULL, "/sm:root", 0);
1625 assert_non_null(parent);
1626
1627 node = lys_getnext(NULL, parent, NULL, LYS_GETNEXT_WITHSCHEMAMOUNT);
1628 assert_non_null(node);
1629 assert_string_equal(node->name, "schema-mounts");
1630 sm_ctx = node->module->ctx;
1631
1632 node = lys_getnext(node, parent, NULL, LYS_GETNEXT_WITHSCHEMAMOUNT);
1633 assert_non_null(node);
1634 assert_string_equal(node->name, "yang-library");
1635
1636 node = lys_getnext(node, parent, NULL, LYS_GETNEXT_WITHSCHEMAMOUNT);
1637 assert_non_null(node);
1638 assert_string_equal(node->name, "modules-state");
1639
1640 node = lys_getnext(node, parent, NULL, LYS_GETNEXT_WITHSCHEMAMOUNT);
1641 assert_non_null(node);
1642 assert_string_equal(node->name, "interfaces");
1643
1644 node = lys_getnext(node, parent, NULL, LYS_GETNEXT_WITHSCHEMAMOUNT);
1645 assert_non_null(node);
1646 assert_string_equal(node->name, "interfaces-state");
1647
1648 node = lys_getnext(node, parent, NULL, LYS_GETNEXT_WITHSCHEMAMOUNT);
1649 assert_null(node);
1650
1651 ly_ctx_destroy(sm_ctx);
1652}
1653
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +01001654int
1655main(void)
1656{
1657 const struct CMUnitTest tests[] = {
Michal Vaskoddd76592022-01-17 13:34:48 +01001658 UTEST(test_schema),
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001659 UTEST(test_parse_invalid, setup),
1660 UTEST(test_parse_inline, setup),
1661 UTEST(test_parse_shared, setup),
1662 UTEST(test_parse_shared_parent_ref, setup),
1663 UTEST(test_parse_config, setup),
Michal Vasko8cc3f662022-03-29 11:25:51 +02001664 UTEST(test_new, setup),
Michal Vaskoe482bb92023-02-01 11:41:41 +01001665 UTEST(test_lys_getnext, setup),
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +01001666 };
1667
1668 return cmocka_run_group_tests(tests, NULL, NULL);
1669}