blob: 381648a06a3f17cf8caac5bba8dd77f1262a91b1 [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 "}"
37 "leaf target{type string;}"
38 "augment /if:interfaces/if:interface {"
39 " leaf sm-name {type leafref {path \"/sm:target\";}}"
40 "}"
41 "}";
42
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +010043 UTEST_SETUP;
Michal Vaskoddd76592022-01-17 13:34:48 +010044 glob_state = state;
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +010045
46 assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
Michal Vaskoddd76592022-01-17 13:34:48 +010047 assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL));
48 assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "iana-if-type", NULL, NULL));
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +010049
50 return 0;
51}
52
53static void
Michal Vaskoddd76592022-01-17 13:34:48 +010054test_schema(void **state)
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +010055{
56 struct lys_module *mod;
Michal Vaskoddd76592022-01-17 13:34:48 +010057 const char *schema;
58 char *str;
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +010059
Michal Vaskoddd76592022-01-17 13:34:48 +010060 /* invalid */
61 schema =
62 "module sm {\n"
63 " namespace \"urn:sm\";\n"
64 " prefix sm;\n"
65 "\n"
66 " import ietf-yang-schema-mount {\n"
67 " prefix yangmnt;\n"
68 " }\n"
69 "\n"
70 " container root {\n"
71 " yangmnt:mount-point \"root\";\n"
72 " }\n"
73 "}\n";
74 assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL));
75 CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": "
76 "Extension \"yangmnt:mount-point\" instance not allowed in YANG version 1 module.",
77 "/sm:root/{extension='yangmnt:mount-point'}/root");
78
79 schema =
80 "module sm {\n"
81 " yang-version 1.1;\n"
82 " namespace \"urn:sm\";\n"
83 " prefix sm;\n"
84 "\n"
85 " import ietf-yang-schema-mount {\n"
86 " prefix yangmnt;\n"
87 " }\n"
88 "\n"
89 " yangmnt:mount-point \"root\";\n"
90 "}\n";
91 assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL));
92 CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": "
93 "Extension \"yangmnt:mount-point\" instance allowed only in container or list statement.",
94 "/sm:{extension='yangmnt:mount-point'}/root");
95
96 schema =
97 "module sm {\n"
98 " yang-version 1.1;\n"
99 " namespace \"urn:sm\";\n"
100 " prefix sm;\n"
101 "\n"
102 " import ietf-yang-schema-mount {\n"
103 " prefix yangmnt;\n"
104 " }\n"
105 "\n"
106 " container root {\n"
107 " leaf l {\n"
108 " type empty;\n"
109 " yangmnt:mount-point \"root\";\n"
110 " }\n"
111 " }\n"
112 "}\n";
113 assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL));
114 CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": "
115 "Extension \"yangmnt:mount-point\" instance allowed only in container or list statement.",
116 "/sm:root/l/{extension='yangmnt:mount-point'}/root");
117
118 schema =
119 "module sm {\n"
120 " yang-version 1.1;\n"
121 " namespace \"urn:sm\";\n"
122 " prefix sm;\n"
123 "\n"
124 " import ietf-yang-schema-mount {\n"
125 " prefix yangmnt;\n"
126 " }\n"
127 "\n"
128 " list l {\n"
129 " key \"k\";\n"
130 " leaf k {\n"
131 " type string;\n"
132 " }\n"
133 " yangmnt:mount-point \"root\";\n"
134 " yangmnt:mount-point \"root2\";\n"
135 " }\n"
136 "}\n";
137 assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, NULL));
138 CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": "
139 "Multiple extension \"yangmnt:mount-point\" instances.",
140 "/sm:l/{extension='yangmnt:mount-point'}/root2");
141
142 /* valid */
143 schema =
144 "module sm {\n"
145 " yang-version 1.1;\n"
146 " namespace \"urn:sm\";\n"
147 " prefix sm;\n"
148 "\n"
149 " import ietf-yang-schema-mount {\n"
150 " prefix yangmnt;\n"
151 " }\n"
152 "\n"
153 " container root {\n"
154 " yangmnt:mount-point \"root\";\n"
155 " }\n"
156 "}\n";
157 assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, &mod));
158 lys_print_mem(&str, mod, LYS_YIN, 0);
159 assert_string_equal(str, schema);
160 free(str);
161}
162
163static LY_ERR
164test_ext_data_clb(const struct lysc_ext_instance *ext, void *user_data, void **ext_data, ly_bool *ext_data_free)
165{
166 void **state = glob_state;
167 struct lyd_node *data = NULL;
168
169 (void)ext;
170
171 if (user_data) {
172 CHECK_PARSE_LYD_PARAM(user_data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
173 }
174
175 *ext_data = data;
176 *ext_data_free = 1;
177 return LY_SUCCESS;
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +0100178}
179
180static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100181test_parse_invalid(void **state)
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +0100182{
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100183 const char *xml, *json;
Michal Vaskoddd76592022-01-17 13:34:48 +0100184 struct lyd_node *data;
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +0100185
Michal Vaskoddd76592022-01-17 13:34:48 +0100186 /* no callback set */
187 xml =
188 "<root xmlns=\"urn:sm\">"
189 " <unknown xmlns=\"unknown\">"
190 " <interface>"
191 " <name>bu</name>"
192 " <type xmlns:ii=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ii:ethernetCsmacd</type>"
193 " </interface>"
194 " </unknown>"
195 "</root>";
196 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EINVAL, data);
197 CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": Failed to get extension data, no callback set.",
198 NULL);
199
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100200 json =
201 "{"
202 " \"sm:root\": {"
203 " \"unknown:unknown\": {"
204 " \"interface\": ["
205 " {"
206 " \"name\": \"bu\","
207 " \"type\": \"iana-if-type:ethernetCsmacd\""
208 " }"
209 " ]"
210 " }"
211 " }"
212 "}";
213 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, 0, LYD_VALIDATE_PRESENT, LY_EINVAL, data);
214 CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": Failed to get extension data, no callback set.",
215 NULL);
216
Michal Vaskoddd76592022-01-17 13:34:48 +0100217 /* unknown data */
218 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb, NULL);
219 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
220 assert_string_equal(LYD_NAME(data), "root");
221 assert_null(lyd_child(data));
222 assert_non_null(data->next);
223 assert_true(data->next->flags & LYD_DEFAULT);
224 lyd_free_siblings(data);
225
226 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
227 CHECK_LOG_CTX("No module with namespace \"unknown\" in the context.",
Michal Vasko959f8d82022-06-16 07:51:50 +0200228 "Schema location \"/sm:root\", data location \"/sm:root\", line number 1.");
Michal Vaskoddd76592022-01-17 13:34:48 +0100229
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100230 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
231 assert_string_equal(LYD_NAME(data), "root");
232 assert_null(lyd_child(data));
233 assert_non_null(data->next);
234 assert_true(data->next->flags & LYD_DEFAULT);
235 lyd_free_siblings(data);
236
237 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
238 CHECK_LOG_CTX("No module named \"unknown\" in the context.",
Michal Vasko959f8d82022-06-16 07:51:50 +0200239 "Schema location \"/sm:root\", data location \"/sm:root\", line number 1.");
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100240
Michal Vaskoddd76592022-01-17 13:34:48 +0100241 /* missing required callback data */
242 xml =
243 "<root xmlns=\"urn:sm\">"
244 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">"
245 " <interface>"
246 " <name>bu</name>"
247 " </interface>"
248 " </interfaces>"
249 "</root>";
250 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
251 CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.",
Michal Vasko959f8d82022-06-16 07:51:50 +0200252 "Schema location \"/sm:root\", data location \"/sm:root\", line number 1.");
Michal Vaskoddd76592022-01-17 13:34:48 +0100253
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100254 json =
255 "{"
256 " \"sm:root\": {"
257 " \"ietf-interfaces:interfaces\": {"
258 " \"interface\": ["
259 " {"
260 " \"name\": \"bu\""
261 " }"
262 " ]"
263 " }"
264 " }"
265 "}";
266 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
267 CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.",
Michal Vasko959f8d82022-06-16 07:51:50 +0200268 "Schema location \"/sm:root\", data location \"/sm:root\", line number 1.");
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100269
Michal Vaskoddd76592022-01-17 13:34:48 +0100270 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
271 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
272 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
273 " <module-set>"
274 " <name>test-set</name>"
275 " <module>"
276 " <name>ietf-yang-library</name>"
277 " <revision>2019-01-04</revision>"
278 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
279 " </module>"
280 " </module-set>"
281 " <schema>"
282 " <name>test-schema</name>"
283 " <module-set>test-set</module-set>"
284 " </schema>"
285 " <datastore>"
286 " <name>ds:running</name>"
287 " <schema>test-schema</schema>"
288 " </datastore>"
289 " <datastore>"
290 " <name>ds:operational</name>"
291 " <schema>test-schema</schema>"
292 " </datastore>"
293 " <content-id>1</content-id>"
294 "</yang-library>"
295 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
296 " <module-set-id>1</module-set-id>"
297 "</modules-state>");
298 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
299 CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100300 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
301 CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", NULL);
Michal Vaskoddd76592022-01-17 13:34:48 +0100302
303 /* missing module in yang-library data */
304 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
305 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
306 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
307 " <module-set>"
308 " <name>test-set</name>"
309 " <module>"
310 " <name>ietf-yang-library</name>"
311 " <revision>2019-01-04</revision>"
312 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
313 " </module>"
314 " </module-set>"
315 " <schema>"
316 " <name>test-schema</name>"
317 " <module-set>test-set</module-set>"
318 " </schema>"
319 " <datastore>"
320 " <name>ds:running</name>"
321 " <schema>test-schema</schema>"
322 " </datastore>"
323 " <datastore>"
324 " <name>ds:operational</name>"
325 " <schema>test-schema</schema>"
326 " </datastore>"
327 " <content-id>1</content-id>"
328 "</yang-library>"
329 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
330 " <module-set-id>1</module-set-id>"
331 "</modules-state>"
332 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
333 " <mount-point>"
334 " <module>sm</module>"
335 " <label>root</label>"
336 " <inline/>"
337 " </mount-point>"
338 "</schema-mounts>");
339 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
340 CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100341 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
342 CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", NULL);
Michal Vaskoddd76592022-01-17 13:34:48 +0100343
344 /* callback data correct, invalid YANG data */
345 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
346 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
347 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
348 " <module-set>"
349 " <name>test-set</name>"
350 " <module>"
351 " <name>ietf-datastores</name>"
352 " <revision>2018-02-14</revision>"
353 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
354 " </module>"
355 " <module>"
356 " <name>ietf-yang-library</name>"
357 " <revision>2019-01-04</revision>"
358 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
359 " </module>"
360 " <module>"
361 " <name>ietf-yang-schema-mount</name>"
362 " <revision>2019-01-14</revision>"
363 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
364 " </module>"
365 " <module>"
366 " <name>ietf-interfaces</name>"
367 " <revision>2014-05-08</revision>"
368 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
369 " </module>"
370 " <module>"
371 " <name>iana-if-type</name>"
372 " <revision>2014-05-08</revision>"
373 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
374 " </module>"
375 " <import-only-module>"
376 " <name>ietf-yang-types</name>"
377 " <revision>2013-07-15</revision>"
378 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
379 " </import-only-module>"
380 " </module-set>"
381 " <schema>"
382 " <name>test-schema</name>"
383 " <module-set>test-set</module-set>"
384 " </schema>"
385 " <datastore>"
386 " <name>ds:running</name>"
387 " <schema>test-schema</schema>"
388 " </datastore>"
389 " <datastore>"
390 " <name>ds:operational</name>"
391 " <schema>test-schema</schema>"
392 " </datastore>"
393 " <content-id>1</content-id>"
394 "</yang-library>"
395 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
396 " <module-set-id>1</module-set-id>"
397 "</modules-state>"
398 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
399 " <mount-point>"
400 " <module>sm</module>"
401 " <label>root</label>"
402 " <inline/>"
403 " </mount-point>"
404 "</schema-mounts>");
405 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
406 CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": "
407 "Mandatory node \"type\" instance does not exist.",
Michal Vasko959f8d82022-06-16 07:51:50 +0200408 "Schema location \"/ietf-interfaces:interfaces/interface/type\".");
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100409 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
410 CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": "
411 "Mandatory node \"type\" instance does not exist.",
Michal Vasko959f8d82022-06-16 07:51:50 +0200412 "Schema location \"/ietf-interfaces:interfaces/interface/type\".");
Michal Vaskoddd76592022-01-17 13:34:48 +0100413
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100414 /* same validation fail in separate validation */
Michal Vaskoddd76592022-01-17 13:34:48 +0100415 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT | LYD_PARSE_ONLY, 0, LY_SUCCESS, data);
416 assert_int_equal(LY_EVALID, lyd_validate_all(&data, NULL, LYD_VALIDATE_PRESENT, NULL));
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100417 CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": "
418 "Mandatory node \"type\" instance does not exist.",
Michal Vasko959f8d82022-06-16 07:51:50 +0200419 "Schema location \"/ietf-interfaces:interfaces/interface/type\".");
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100420 lyd_free_siblings(data);
421
422 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT | LYD_PARSE_ONLY, 0, LY_SUCCESS, data);
423 assert_int_equal(LY_EVALID, lyd_validate_all(&data, NULL, LYD_VALIDATE_PRESENT, NULL));
424 CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": "
425 "Mandatory node \"type\" instance does not exist.",
Michal Vasko959f8d82022-06-16 07:51:50 +0200426 "Schema location \"/ietf-interfaces:interfaces/interface/type\".");
Michal Vaskoddd76592022-01-17 13:34:48 +0100427 lyd_free_siblings(data);
428
429 /* success */
430 xml =
431 "<root xmlns=\"urn:sm\">\n"
432 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
433 " <interface>\n"
434 " <name>bu</name>\n"
435 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
436 " </interface>\n"
437 " </interfaces>\n"
438 "</root>\n";
439 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
440 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
441 lyd_free_siblings(data);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100442
443 json =
444 "{\n"
445 " \"sm:root\": {\n"
446 " \"ietf-interfaces:interfaces\": {\n"
447 " \"interface\": [\n"
448 " {\n"
449 " \"name\": \"bu\",\n"
450 " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
451 " }\n"
452 " ]\n"
453 " }\n"
454 " }\n"
455 "}\n";
456 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
457 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
458 lyd_free_siblings(data);
Michal Vaskoddd76592022-01-17 13:34:48 +0100459}
460
461static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100462test_parse_inline(void **state)
Michal Vaskoddd76592022-01-17 13:34:48 +0100463{
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100464 const char *xml, *json;
Michal Vasko9883a3e2022-03-31 12:16:00 +0200465 char *lyb;
Michal Vaskoddd76592022-01-17 13:34:48 +0100466 struct lyd_node *data;
467
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100468 /* valid */
Michal Vaskoddd76592022-01-17 13:34:48 +0100469 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
470 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
471 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
472 " <module-set>"
473 " <name>test-set</name>"
474 " <module>"
475 " <name>ietf-datastores</name>"
476 " <revision>2018-02-14</revision>"
477 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
478 " </module>"
479 " <module>"
480 " <name>ietf-yang-library</name>"
481 " <revision>2019-01-04</revision>"
482 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
483 " </module>"
484 " <module>"
485 " <name>ietf-yang-schema-mount</name>"
486 " <revision>2019-01-14</revision>"
487 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
488 " </module>"
489 " <module>"
490 " <name>ietf-interfaces</name>"
491 " <revision>2014-05-08</revision>"
492 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
493 " </module>"
494 " <module>"
495 " <name>iana-if-type</name>"
496 " <revision>2014-05-08</revision>"
497 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
498 " </module>"
499 " <import-only-module>"
500 " <name>ietf-yang-types</name>"
501 " <revision>2013-07-15</revision>"
502 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
503 " </import-only-module>"
504 " </module-set>"
505 " <schema>"
506 " <name>test-schema</name>"
507 " <module-set>test-set</module-set>"
508 " </schema>"
509 " <datastore>"
510 " <name>ds:running</name>"
511 " <schema>test-schema</schema>"
512 " </datastore>"
513 " <datastore>"
514 " <name>ds:operational</name>"
515 " <schema>test-schema</schema>"
516 " </datastore>"
517 " <content-id>1</content-id>"
518 "</yang-library>"
519 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
520 " <module-set-id>1</module-set-id>"
521 "</modules-state>"
522 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
523 " <mount-point>"
524 " <module>sm</module>"
525 " <label>root</label>"
526 " <inline/>"
527 " </mount-point>"
528 "</schema-mounts>");
529 xml =
530 "<root xmlns=\"urn:sm\">\n"
531 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
532 " <interface>\n"
533 " <name>bu</name>\n"
534 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
535 " </interface>\n"
536 " </interfaces>\n"
537 " <interfaces-state 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 " <oper-status>not-present</oper-status>\n"
542 " <statistics>\n"
543 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
544 " </statistics>\n"
545 " </interface>\n"
546 " </interfaces-state>\n"
547 "</root>\n";
548 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
549 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
550 lyd_free_siblings(data);
551
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100552 json =
553 "{\n"
554 " \"sm:root\": {\n"
555 " \"ietf-interfaces:interfaces\": {\n"
556 " \"interface\": [\n"
557 " {\n"
558 " \"name\": \"bu\",\n"
559 " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
560 " }\n"
561 " ]\n"
562 " },\n"
563 " \"ietf-interfaces:interfaces-state\": {\n"
564 " \"interface\": [\n"
565 " {\n"
566 " \"name\": \"bu\",\n"
567 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
568 " \"oper-status\": \"not-present\",\n"
569 " \"statistics\": {\n"
570 " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n"
571 " }\n"
572 " }\n"
573 " ]\n"
574 " }\n"
575 " }\n"
576 "}\n";
577 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
578 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
579 lyd_free_siblings(data);
580
Michal Vaskoddd76592022-01-17 13:34:48 +0100581 /* different yang-lib data */
582 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
583 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
584 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
585 " <module-set>"
586 " <name>test-set</name>"
587 " <module>"
588 " <name>ietf-datastores</name>"
589 " <revision>2018-02-14</revision>"
590 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
591 " </module>"
592 " <module>"
593 " <name>ietf-yang-library</name>"
594 " <revision>2019-01-04</revision>"
595 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
596 " </module>"
597 " <module>"
598 " <name>ietf-yang-schema-mount</name>"
599 " <revision>2019-01-14</revision>"
600 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
601 " </module>"
602 " <module>"
603 " <name>ietf-interfaces</name>"
604 " <revision>2014-05-08</revision>"
605 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
606 " </module>"
607 " <module>"
608 " <name>ietf-ip</name>"
609 " <revision>2014-06-16</revision>"
610 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
611 " </module>"
612 " <module>"
613 " <name>iana-if-type</name>"
614 " <revision>2014-05-08</revision>"
615 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
616 " </module>"
617 " <import-only-module>"
618 " <name>ietf-yang-types</name>"
619 " <revision>2013-07-15</revision>"
620 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
621 " </import-only-module>"
622 " </module-set>"
623 " <schema>"
624 " <name>test-schema</name>"
625 " <module-set>test-set</module-set>"
626 " </schema>"
627 " <datastore>"
628 " <name>ds:running</name>"
629 " <schema>test-schema</schema>"
630 " </datastore>"
631 " <datastore>"
632 " <name>ds:operational</name>"
633 " <schema>test-schema</schema>"
634 " </datastore>"
635 " <content-id>1</content-id>"
636 "</yang-library>"
637 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
638 " <module-set-id>1</module-set-id>"
639 "</modules-state>"
640 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
641 " <mount-point>"
642 " <module>sm</module>"
643 " <label>root</label>"
644 " <inline/>"
645 " </mount-point>"
646 "</schema-mounts>");
647 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
648 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
649 lyd_free_siblings(data);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100650
651 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
652 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
Michal Vasko9883a3e2022-03-31 12:16:00 +0200653
654 assert_int_equal(LY_SUCCESS, lyd_print_mem(&lyb, data, LYD_LYB, 0));
655 lyd_free_siblings(data);
656
657 CHECK_PARSE_LYD_PARAM(lyb, LYD_LYB, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
658 free(lyb);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100659 lyd_free_siblings(data);
Michal Vaskoddd76592022-01-17 13:34:48 +0100660}
661
662static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100663test_parse_shared(void **state)
Michal Vaskoddd76592022-01-17 13:34:48 +0100664{
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100665 const char *xml, *json;
Michal Vasko9883a3e2022-03-31 12:16:00 +0200666 char *lyb;
Michal Vaskoddd76592022-01-17 13:34:48 +0100667 struct lyd_node *data;
668
669 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
670 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
671 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
672 " <module-set>"
673 " <name>test-set</name>"
674 " <module>"
675 " <name>ietf-datastores</name>"
676 " <revision>2018-02-14</revision>"
677 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
678 " </module>"
679 " <module>"
680 " <name>ietf-yang-library</name>"
681 " <revision>2019-01-04</revision>"
682 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
683 " </module>"
684 " <module>"
685 " <name>ietf-yang-schema-mount</name>"
686 " <revision>2019-01-14</revision>"
687 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
688 " </module>"
689 " <module>"
690 " <name>ietf-interfaces</name>"
691 " <revision>2014-05-08</revision>"
692 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
693 " </module>"
694 " <module>"
695 " <name>iana-if-type</name>"
696 " <revision>2014-05-08</revision>"
697 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
698 " </module>"
699 " <import-only-module>"
700 " <name>ietf-yang-types</name>"
701 " <revision>2013-07-15</revision>"
702 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
703 " </import-only-module>"
704 " </module-set>"
705 " <schema>"
706 " <name>test-schema</name>"
707 " <module-set>test-set</module-set>"
708 " </schema>"
709 " <datastore>"
710 " <name>ds:running</name>"
711 " <schema>test-schema</schema>"
712 " </datastore>"
713 " <datastore>"
714 " <name>ds:operational</name>"
715 " <schema>test-schema</schema>"
716 " </datastore>"
717 " <content-id>1</content-id>"
718 "</yang-library>"
719 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
720 " <module-set-id>1</module-set-id>"
721 "</modules-state>"
722 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
723 " <mount-point>"
724 " <module>sm</module>"
725 " <label>root</label>"
726 " <shared-schema/>"
727 " </mount-point>"
728 "</schema-mounts>");
729 xml =
730 "<root xmlns=\"urn:sm\">\n"
731 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
732 " <interface>\n"
733 " <name>bu</name>\n"
734 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
735 " </interface>\n"
736 " </interfaces>\n"
737 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
738 " <interface>\n"
739 " <name>bu</name>\n"
740 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
741 " <oper-status>not-present</oper-status>\n"
742 " <statistics>\n"
743 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
744 " </statistics>\n"
745 " </interface>\n"
746 " </interfaces-state>\n"
747 "</root>\n";
748 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
749 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
750 lyd_free_siblings(data);
751
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100752 json =
753 "{\n"
754 " \"sm:root\": {\n"
755 " \"ietf-interfaces:interfaces\": {\n"
756 " \"interface\": [\n"
757 " {\n"
758 " \"name\": \"bu\",\n"
759 " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
760 " }\n"
761 " ]\n"
762 " },\n"
763 " \"ietf-interfaces:interfaces-state\": {\n"
764 " \"interface\": [\n"
765 " {\n"
766 " \"name\": \"bu\",\n"
767 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
768 " \"oper-status\": \"not-present\",\n"
769 " \"statistics\": {\n"
770 " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n"
771 " }\n"
772 " }\n"
773 " ]\n"
774 " }\n"
775 " }\n"
776 "}\n";
777 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
778 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
779 lyd_free_siblings(data);
780
Michal Vaskoddd76592022-01-17 13:34:48 +0100781 /* different yang-lib data */
782 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
783 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
784 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
785 " <module-set>"
786 " <name>test-set</name>"
787 " <module>"
788 " <name>ietf-datastores</name>"
789 " <revision>2018-02-14</revision>"
790 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
791 " </module>"
792 " <module>"
793 " <name>ietf-yang-library</name>"
794 " <revision>2019-01-04</revision>"
795 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
796 " </module>"
797 " <module>"
798 " <name>ietf-yang-schema-mount</name>"
799 " <revision>2019-01-14</revision>"
800 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
801 " </module>"
802 " <module>"
803 " <name>ietf-interfaces</name>"
804 " <revision>2014-05-08</revision>"
805 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
806 " </module>"
807 " <module>"
808 " <name>ietf-ip</name>"
809 " <revision>2014-06-16</revision>"
810 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
811 " </module>"
812 " <module>"
813 " <name>iana-if-type</name>"
814 " <revision>2014-05-08</revision>"
815 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
816 " </module>"
817 " <import-only-module>"
818 " <name>ietf-yang-types</name>"
819 " <revision>2013-07-15</revision>"
820 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
821 " </import-only-module>"
822 " </module-set>"
823 " <schema>"
824 " <name>test-schema</name>"
825 " <module-set>test-set</module-set>"
826 " </schema>"
827 " <datastore>"
828 " <name>ds:running</name>"
829 " <schema>test-schema</schema>"
830 " </datastore>"
831 " <datastore>"
832 " <name>ds:operational</name>"
833 " <schema>test-schema</schema>"
834 " </datastore>"
835 " <content-id>2</content-id>"
836 "</yang-library>"
837 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
838 " <module-set-id>1</module-set-id>"
839 "</modules-state>"
840 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
841 " <mount-point>"
842 " <module>sm</module>"
843 " <label>root</label>"
844 " <shared-schema/>"
845 " </mount-point>"
846 "</schema-mounts>");
847 xml =
848 "<root2 xmlns=\"urn:sm\">\n"
849 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
850 " <interface>\n"
851 " <name>bu</name>\n"
852 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
853 " </interface>\n"
854 " </interfaces>\n"
855 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
856 " <interface>\n"
857 " <name>bu</name>\n"
858 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
859 " <oper-status>not-present</oper-status>\n"
860 " <statistics>\n"
861 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
862 " </statistics>\n"
863 " </interface>\n"
864 " </interfaces-state>\n"
865 "</root2>\n";
866 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
867 CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": "
868 "Shared-schema yang-library content-id \"2\" differs from \"1\" used previously.",
869 "/ietf-yang-library:yang-library/content-id");
870
871 /* data for 2 mount points */
872 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
873 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
874 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
875 " <module-set>"
876 " <name>test-set</name>"
877 " <module>"
878 " <name>ietf-datastores</name>"
879 " <revision>2018-02-14</revision>"
880 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
881 " </module>"
882 " <module>"
883 " <name>ietf-yang-library</name>"
884 " <revision>2019-01-04</revision>"
885 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
886 " </module>"
887 " <module>"
888 " <name>ietf-yang-schema-mount</name>"
889 " <revision>2019-01-14</revision>"
890 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
891 " </module>"
892 " <module>"
893 " <name>ietf-interfaces</name>"
894 " <revision>2014-05-08</revision>"
895 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
896 " </module>"
897 " <module>"
898 " <name>iana-if-type</name>"
899 " <revision>2014-05-08</revision>"
900 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
901 " </module>"
902 " <import-only-module>"
903 " <name>ietf-yang-types</name>"
904 " <revision>2013-07-15</revision>"
905 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
906 " </import-only-module>"
907 " </module-set>"
908 " <schema>"
909 " <name>test-schema</name>"
910 " <module-set>test-set</module-set>"
911 " </schema>"
912 " <datastore>"
913 " <name>ds:running</name>"
914 " <schema>test-schema</schema>"
915 " </datastore>"
916 " <datastore>"
917 " <name>ds:operational</name>"
918 " <schema>test-schema</schema>"
919 " </datastore>"
920 " <content-id>1</content-id>"
921 "</yang-library>"
922 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
923 " <module-set-id>1</module-set-id>"
924 "</modules-state>"
925 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
926 " <mount-point>"
927 " <module>sm</module>"
928 " <label>root</label>"
929 " <shared-schema/>"
930 " </mount-point>"
931 "</schema-mounts>");
932 xml =
933 "<root xmlns=\"urn:sm\">\n"
934 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
935 " <interface>\n"
936 " <name>bu</name>\n"
937 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
938 " </interface>\n"
939 " </interfaces>\n"
940 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
941 " <interface>\n"
942 " <name>bu</name>\n"
943 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
944 " <oper-status>not-present</oper-status>\n"
945 " <statistics>\n"
946 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
947 " </statistics>\n"
948 " </interface>\n"
949 " </interfaces-state>\n"
950 "</root>\n"
951 "<root2 xmlns=\"urn:sm\">\n"
952 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
953 " <interface>\n"
954 " <name>fu</name>\n"
955 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:fddi</type>\n"
956 " </interface>\n"
957 " </interfaces>\n"
958 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
959 " <interface>\n"
960 " <name>fu</name>\n"
961 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:fddi</type>\n"
962 " <oper-status>down</oper-status>\n"
963 " <statistics>\n"
964 " <discontinuity-time>2020-01-01T10:00:00-00:00</discontinuity-time>\n"
965 " </statistics>\n"
966 " </interface>\n"
967 " </interfaces-state>\n"
968 "</root2>\n";
969 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
970 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
971 lyd_free_siblings(data);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100972
973 json =
974 "{\n"
975 " \"sm:root\": {\n"
976 " \"ietf-interfaces:interfaces\": {\n"
977 " \"interface\": [\n"
978 " {\n"
979 " \"name\": \"bu\",\n"
980 " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
981 " }\n"
982 " ]\n"
983 " },\n"
984 " \"ietf-interfaces:interfaces-state\": {\n"
985 " \"interface\": [\n"
986 " {\n"
987 " \"name\": \"bu\",\n"
988 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
989 " \"oper-status\": \"not-present\",\n"
990 " \"statistics\": {\n"
991 " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n"
992 " }\n"
993 " }\n"
994 " ]\n"
995 " }\n"
996 " },\n"
997 " \"sm:root2\": {\n"
998 " \"ietf-interfaces:interfaces\": {\n"
999 " \"interface\": [\n"
1000 " {\n"
1001 " \"name\": \"fu\",\n"
1002 " \"type\": \"iana-if-type:fddi\"\n"
1003 " }\n"
1004 " ]\n"
1005 " },\n"
1006 " \"ietf-interfaces:interfaces-state\": {\n"
1007 " \"interface\": [\n"
1008 " {\n"
1009 " \"name\": \"fu\",\n"
1010 " \"type\": \"iana-if-type:fddi\",\n"
1011 " \"oper-status\": \"down\",\n"
1012 " \"statistics\": {\n"
1013 " \"discontinuity-time\": \"2020-01-01T10:00:00-00:00\"\n"
1014 " }\n"
1015 " }\n"
1016 " ]\n"
1017 " }\n"
1018 " }\n"
1019 "}\n";
1020 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1021 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
Michal Vasko9883a3e2022-03-31 12:16:00 +02001022
1023 assert_int_equal(LY_SUCCESS, lyd_print_mem(&lyb, data, LYD_LYB, LYD_PRINT_WITHSIBLINGS));
1024 lyd_free_siblings(data);
1025
1026 CHECK_PARSE_LYD_PARAM(lyb, LYD_LYB, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1027 free(lyb);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001028 lyd_free_siblings(data);
Michal Vaskoddd76592022-01-17 13:34:48 +01001029}
1030
1031static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001032test_parse_shared_parent_ref(void **state)
Michal Vaskoddd76592022-01-17 13:34:48 +01001033{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001034 const char *xml, *json;
Michal Vaskoddd76592022-01-17 13:34:48 +01001035 struct lyd_node *data;
1036
1037 /* wrong leafref value */
1038 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
1039 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1040 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1041 " <module-set>"
1042 " <name>test-set</name>"
1043 " <module>"
1044 " <name>ietf-datastores</name>"
1045 " <revision>2018-02-14</revision>"
1046 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1047 " </module>"
1048 " <module>"
1049 " <name>ietf-yang-library</name>"
1050 " <revision>2019-01-04</revision>"
1051 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1052 " </module>"
1053 " <module>"
1054 " <name>ietf-yang-schema-mount</name>"
1055 " <revision>2019-01-14</revision>"
1056 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1057 " </module>"
1058 " <module>"
1059 " <name>sm</name>"
1060 " <namespace>urn:sm</namespace>"
1061 " </module>"
1062 " <module>"
1063 " <name>ietf-interfaces</name>"
1064 " <revision>2014-05-08</revision>"
1065 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
1066 " </module>"
1067 " <module>"
1068 " <name>iana-if-type</name>"
1069 " <revision>2014-05-08</revision>"
1070 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
1071 " </module>"
1072 " <import-only-module>"
1073 " <name>ietf-yang-types</name>"
1074 " <revision>2013-07-15</revision>"
1075 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
1076 " </import-only-module>"
1077 " </module-set>"
1078 " <schema>"
1079 " <name>test-schema</name>"
1080 " <module-set>test-set</module-set>"
1081 " </schema>"
1082 " <datastore>"
1083 " <name>ds:running</name>"
1084 " <schema>test-schema</schema>"
1085 " </datastore>"
1086 " <datastore>"
1087 " <name>ds:operational</name>"
1088 " <schema>test-schema</schema>"
1089 " </datastore>"
1090 " <content-id>1</content-id>"
1091 "</yang-library>"
1092 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1093 " <module-set-id>1</module-set-id>"
1094 "</modules-state>"
1095 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1096 " <namespace>"
1097 " <prefix>smp</prefix>"
1098 " <uri>urn:sm</uri>"
1099 " </namespace>"
1100 " <mount-point>"
1101 " <module>sm</module>"
1102 " <label>mnt-root</label>"
1103 " <shared-schema>"
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001104 " <parent-reference>/smp:target[. = current()/smp:name]</parent-reference>"
Michal Vaskoddd76592022-01-17 13:34:48 +01001105 " </shared-schema>"
1106 " </mount-point>"
1107 "</schema-mounts>");
1108 xml =
1109 "<root3 xmlns=\"urn:sm\">\n"
1110 " <ls>\n"
1111 " <name>target-value</name>\n"
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001112 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1113 " <interface>\n"
1114 " <name>bu</name>\n"
1115 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1116 " <sm-name xmlns=\"urn:sm\">target-value</sm-name>\n"
1117 " </interface>\n"
1118 " </interfaces>\n"
Michal Vaskoddd76592022-01-17 13:34:48 +01001119 " </ls>\n"
1120 "</root3>\n"
1121 "<target xmlns=\"urn:sm\">wrong-target-value</target>\n";
1122 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
1123 CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": "
1124 "Invalid leafref value \"target-value\" - no existing target instance \"/sm:target\".",
Michal Vasko959f8d82022-06-16 07:51:50 +02001125 "Schema location \"/ietf-interfaces:interfaces/interface/sm:sm-name\", "
1126 "data location \"/ietf-interfaces:interfaces/interface[name='bu']/sm:sm-name\".");
Michal Vaskoddd76592022-01-17 13:34:48 +01001127
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001128 json =
1129 "{\n"
1130 " \"sm:root3\": {\n"
1131 " \"ls\": ["
1132 " {\n"
1133 " \"name\": \"target-value\",\n"
1134 " \"ietf-interfaces:interfaces\": {\n"
1135 " \"interface\": [\n"
1136 " {\n"
1137 " \"name\": \"bu\",\n"
1138 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
1139 " \"sm:sm-name\": \"target-value\"\n"
1140 " }\n"
1141 " ]\n"
1142 " }\n"
1143 " }\n"
1144 " ]\n"
1145 " },\n"
1146 " \"sm:target\": \"wrong-target-value\"\n"
1147 "}\n";
1148 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
1149 CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": "
1150 "Invalid leafref value \"target-value\" - no existing target instance \"/sm:target\".",
Michal Vasko959f8d82022-06-16 07:51:50 +02001151 "Schema location \"/ietf-interfaces:interfaces/interface/sm:sm-name\", "
1152 "data location \"/ietf-interfaces:interfaces/interface[name='bu']/sm:sm-name\".");
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001153
Michal Vaskoddd76592022-01-17 13:34:48 +01001154 /* success */
1155 xml =
1156 "<root3 xmlns=\"urn:sm\">\n"
1157 " <ls>\n"
1158 " <name>target-value</name>\n"
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001159 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1160 " <interface>\n"
1161 " <name>bu</name>\n"
1162 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1163 " <sm-name xmlns=\"urn:sm\">target-value</sm-name>\n"
1164 " </interface>\n"
1165 " </interfaces>\n"
Michal Vaskoddd76592022-01-17 13:34:48 +01001166 " </ls>\n"
1167 "</root3>\n"
1168 "<target xmlns=\"urn:sm\">target-value</target>\n";
1169 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1170 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1171 lyd_free_siblings(data);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001172
1173 json =
1174 "{\n"
1175 " \"sm:root3\": {\n"
1176 " \"ls\": [\n"
1177 " {\n"
1178 " \"name\": \"target-value\",\n"
1179 " \"ietf-interfaces:interfaces\": {\n"
1180 " \"interface\": [\n"
1181 " {\n"
1182 " \"name\": \"bu\",\n"
1183 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
1184 " \"sm:sm-name\": \"target-value\"\n"
1185 " }\n"
1186 " ]\n"
1187 " }\n"
1188 " }\n"
1189 " ]\n"
1190 " },\n"
1191 " \"sm:target\": \"target-value\"\n"
1192 "}\n";
1193 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1194 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
1195 lyd_free_siblings(data);
Michal Vaskoddd76592022-01-17 13:34:48 +01001196}
1197
1198static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001199test_parse_config(void **state)
Michal Vaskoddd76592022-01-17 13:34:48 +01001200{
1201 const char *xml;
Michal Vasko24edeb92022-07-20 08:08:46 +02001202 char *lyb;
Michal Vaskoddd76592022-01-17 13:34:48 +01001203 struct lyd_node *data;
1204 const struct lyd_node *node;
1205
1206 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
1207 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1208 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1209 " <module-set>"
1210 " <name>test-set</name>"
1211 " <module>"
1212 " <name>ietf-datastores</name>"
1213 " <revision>2018-02-14</revision>"
1214 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1215 " </module>"
1216 " <module>"
1217 " <name>ietf-yang-library</name>"
1218 " <revision>2019-01-04</revision>"
1219 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1220 " </module>"
1221 " <module>"
1222 " <name>ietf-yang-schema-mount</name>"
1223 " <revision>2019-01-14</revision>"
1224 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1225 " </module>"
1226 " <module>"
1227 " <name>ietf-interfaces</name>"
1228 " <revision>2014-05-08</revision>"
1229 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
1230 " </module>"
1231 " <module>"
1232 " <name>iana-if-type</name>"
1233 " <revision>2014-05-08</revision>"
1234 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
1235 " </module>"
1236 " <import-only-module>"
1237 " <name>ietf-yang-types</name>"
1238 " <revision>2013-07-15</revision>"
1239 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
1240 " </import-only-module>"
1241 " </module-set>"
1242 " <schema>"
1243 " <name>test-schema</name>"
1244 " <module-set>test-set</module-set>"
1245 " </schema>"
1246 " <datastore>"
1247 " <name>ds:running</name>"
1248 " <schema>test-schema</schema>"
1249 " </datastore>"
1250 " <datastore>"
1251 " <name>ds:operational</name>"
1252 " <schema>test-schema</schema>"
1253 " </datastore>"
1254 " <content-id>1</content-id>"
1255 "</yang-library>"
1256 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1257 " <module-set-id>1</module-set-id>"
1258 "</modules-state>"
1259 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1260 " <mount-point>"
1261 " <module>sm</module>"
1262 " <label>root</label>"
1263 " <config>false</config>"
1264 " <inline/>"
1265 " </mount-point>"
1266 "</schema-mounts>");
1267 xml =
1268 "<root xmlns=\"urn:sm\">\n"
1269 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1270 " <interface>\n"
1271 " <name>bu</name>\n"
1272 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1273 " <enabled>true</enabled>\n"
1274 " </interface>\n"
1275 " </interfaces>\n"
1276 "</root>\n";
1277 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1278 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1279
1280 node = lyd_child(data);
1281 assert_string_equal(LYD_NAME(node), "interfaces");
1282 assert_true(node->schema->flags & LYS_CONFIG_R);
1283 node = lyd_child(node);
1284 assert_string_equal(LYD_NAME(node), "interface");
1285 assert_true(node->schema->flags & LYS_CONFIG_R);
1286 node = lyd_child(node);
1287 assert_string_equal(LYD_NAME(node), "name");
1288 assert_true(node->schema->flags & LYS_CONFIG_R);
1289 node = node->next;
1290 assert_string_equal(LYD_NAME(node), "type");
1291 assert_true(node->schema->flags & LYS_CONFIG_R);
1292
Michal Vasko24edeb92022-07-20 08:08:46 +02001293 lyd_print_mem(&lyb, data, LYD_LYB, 0);
1294 lyd_free_siblings(data);
1295 CHECK_PARSE_LYD_PARAM(lyb, LYD_LYB, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1296 free(lyb);
1297
1298 node = lyd_child(data);
1299 assert_string_equal(LYD_NAME(node), "interfaces");
1300 assert_true(node->schema->flags & LYS_CONFIG_R);
1301 node = lyd_child(node);
1302 assert_string_equal(LYD_NAME(node), "interface");
1303 assert_true(node->schema->flags & LYS_CONFIG_R);
1304 node = lyd_child(node);
1305 assert_string_equal(LYD_NAME(node), "name");
1306 assert_true(node->schema->flags & LYS_CONFIG_R);
1307 node = node->next;
1308 assert_string_equal(LYD_NAME(node), "type");
1309 assert_true(node->schema->flags & LYS_CONFIG_R);
1310
Michal Vaskoddd76592022-01-17 13:34:48 +01001311 lyd_free_siblings(data);
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +01001312}
1313
Michal Vasko8cc3f662022-03-29 11:25:51 +02001314static void
1315test_new(void **state)
1316{
1317 const char *xml;
1318 const struct lys_module *mod;
1319 struct lyd_node *data, *node;
1320
1321 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
1322 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1323 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1324 " <module-set>"
1325 " <name>test-set</name>"
1326 " <module>"
1327 " <name>ietf-datastores</name>"
1328 " <revision>2018-02-14</revision>"
1329 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1330 " </module>"
1331 " <module>"
1332 " <name>ietf-yang-library</name>"
1333 " <revision>2019-01-04</revision>"
1334 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1335 " </module>"
1336 " <module>"
1337 " <name>ietf-yang-schema-mount</name>"
1338 " <revision>2019-01-14</revision>"
1339 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1340 " </module>"
1341 " <module>"
1342 " <name>ietf-interfaces</name>"
1343 " <revision>2014-05-08</revision>"
1344 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
1345 " </module>"
1346 " <module>"
1347 " <name>iana-if-type</name>"
1348 " <revision>2014-05-08</revision>"
1349 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
1350 " </module>"
Michal Vasko35b29622022-07-22 14:12:56 +02001351 " <module>"
1352 " <name>ietf-ip</name>"
1353 " <revision>2014-06-16</revision>"
1354 " <namespace>urn:ietf:params:xml:ns:yang:ietf-ip</namespace>"
1355 " </module>"
Michal Vasko8cc3f662022-03-29 11:25:51 +02001356 " <import-only-module>"
1357 " <name>ietf-yang-types</name>"
1358 " <revision>2013-07-15</revision>"
1359 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
1360 " </import-only-module>"
1361 " </module-set>"
1362 " <schema>"
1363 " <name>test-schema</name>"
1364 " <module-set>test-set</module-set>"
1365 " </schema>"
1366 " <datastore>"
1367 " <name>ds:running</name>"
1368 " <schema>test-schema</schema>"
1369 " </datastore>"
1370 " <datastore>"
1371 " <name>ds:operational</name>"
1372 " <schema>test-schema</schema>"
1373 " </datastore>"
1374 " <content-id>1</content-id>"
1375 "</yang-library>"
1376 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1377 " <module-set-id>1</module-set-id>"
1378 "</modules-state>"
1379 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1380 " <mount-point>"
1381 " <module>sm</module>"
1382 " <label>root</label>"
1383 " <shared-schema/>"
1384 " </mount-point>"
1385 "</schema-mounts>");
1386 xml =
1387 "<root xmlns=\"urn:sm\">\n"
1388 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1389 " <interface>\n"
1390 " <name>bu</name>\n"
1391 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
Michal Vasko35b29622022-07-22 14:12:56 +02001392 " <ipv4 xmlns=\"urn:ietf:params:xml:ns:yang:ietf-ip\">\n"
1393 " <enabled>false</enabled>\n"
1394 " </ipv4>\n"
Michal Vasko8cc3f662022-03-29 11:25:51 +02001395 " </interface>\n"
1396 " </interfaces>\n"
1397 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1398 " <interface>\n"
1399 " <name>bu</name>\n"
1400 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1401 " <oper-status>not-present</oper-status>\n"
1402 " <statistics>\n"
1403 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
1404 " </statistics>\n"
1405 " </interface>\n"
1406 " </interfaces-state>\n"
1407 "</root>\n";
1408
1409 /* create the data manually with simple new functions */
1410 mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "sm");
1411 assert_non_null(mod);
1412 assert_int_equal(LY_SUCCESS, lyd_new_inner(NULL, mod, "root", 0, &data));
1413
1414 mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "ietf-interfaces");
1415 assert_non_null(mod);
1416 assert_int_equal(LY_SUCCESS, lyd_new_inner(data, mod, "interfaces", 0, &node));
1417 assert_int_equal(LY_SUCCESS, lyd_new_list(node, NULL, "interface", 0, &node, "bu"));
1418 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "type", "iana-if-type:ethernetCsmacd", 0, NULL));
Michal Vasko35b29622022-07-22 14:12:56 +02001419 mod = ly_ctx_get_module_implemented(LYD_CTX(node), "ietf-ip");
1420 assert_non_null(mod);
1421 assert_int_equal(LY_SUCCESS, lyd_new_inner(node, mod, "ipv4", 0, &node));
1422 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "enabled", "false", 0, NULL));
Michal Vasko8cc3f662022-03-29 11:25:51 +02001423
Michal Vasko35b29622022-07-22 14:12:56 +02001424 mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "ietf-interfaces");
1425 assert_non_null(mod);
Michal Vasko8cc3f662022-03-29 11:25:51 +02001426 assert_int_equal(LY_SUCCESS, lyd_new_inner(data, mod, "interfaces-state", 0, &node));
1427 assert_int_equal(LY_SUCCESS, lyd_new_list(node, NULL, "interface", 0, &node, "bu"));
1428 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "type", "iana-if-type:ethernetCsmacd", 0, NULL));
1429 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "oper-status", "not-present", 0, NULL));
1430 assert_int_equal(LY_SUCCESS, lyd_new_inner(node, NULL, "statistics", 0, &node));
1431 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "discontinuity-time", "2022-01-01T10:00:00-00:00", 0, NULL));
1432
1433 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1434 lyd_free_siblings(data);
1435
1436 /* create the data using lyd_new_path */
1437 assert_int_equal(LY_SUCCESS, lyd_new_path(NULL, UTEST_LYCTX,
1438 "/sm:root/ietf-interfaces:interfaces/interface[name='bu']/type", "iana-if-type:ethernetCsmacd", 0, &data));
1439 assert_int_equal(LY_SUCCESS, lyd_new_path(data, NULL,
Michal Vasko35b29622022-07-22 14:12:56 +02001440 "/sm:root/ietf-interfaces:interfaces/interface[name='bu']/ietf-ip:ipv4/enabled", "false", 0, NULL));
1441 assert_int_equal(LY_SUCCESS, lyd_new_path(data, NULL,
Michal Vasko8cc3f662022-03-29 11:25:51 +02001442 "/sm:root/ietf-interfaces:interfaces-state/interface[name='bu']/type", "iana-if-type:ethernetCsmacd", 0, NULL));
1443 assert_int_equal(LY_SUCCESS, lyd_new_path(data, NULL,
1444 "/sm:root/ietf-interfaces:interfaces-state/interface[name='bu']/oper-status", "not-present", 0, NULL));
1445 assert_int_equal(LY_SUCCESS, lyd_new_path(data, NULL,
1446 "/sm:root/ietf-interfaces:interfaces-state/interface[name='bu']/statistics/discontinuity-time",
1447 "2022-01-01T10:00:00-00:00", 0, NULL));
1448
1449 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1450 lyd_free_siblings(data);
1451}
1452
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +01001453int
1454main(void)
1455{
1456 const struct CMUnitTest tests[] = {
Michal Vaskoddd76592022-01-17 13:34:48 +01001457 UTEST(test_schema),
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001458 UTEST(test_parse_invalid, setup),
1459 UTEST(test_parse_inline, setup),
1460 UTEST(test_parse_shared, setup),
1461 UTEST(test_parse_shared_parent_ref, setup),
1462 UTEST(test_parse_config, setup),
Michal Vasko8cc3f662022-03-29 11:25:51 +02001463 UTEST(test_new, setup),
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +01001464 };
1465
1466 return cmocka_run_group_tests(tests, NULL, NULL);
1467}