blob: d97c777c551eeb2a7d5816792edd3fdb1b593600 [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.",
78 "/sm:root/{extension='yangmnt:mount-point'}/root");
79
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.",
95 "/sm:{extension='yangmnt:mount-point'}/root");
96
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.",
117 "/sm:root/l/{extension='yangmnt:mount-point'}/root");
118
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 Vasko193dacd2022-10-13 08:43:05 +0200141 "/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 Vasko62225e22022-08-05 10:06:50 +0200300 CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", "Line number 1.");
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100301 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vasko62225e22022-08-05 10:06:50 +0200302 CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", "Line number 1.");
Michal Vaskoddd76592022-01-17 13:34:48 +0100303
304 /* missing module in yang-library data */
305 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
306 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
307 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
308 " <module-set>"
309 " <name>test-set</name>"
310 " <module>"
311 " <name>ietf-yang-library</name>"
312 " <revision>2019-01-04</revision>"
313 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
314 " </module>"
315 " </module-set>"
316 " <schema>"
317 " <name>test-schema</name>"
318 " <module-set>test-set</module-set>"
319 " </schema>"
320 " <datastore>"
321 " <name>ds:running</name>"
322 " <schema>test-schema</schema>"
323 " </datastore>"
324 " <datastore>"
325 " <name>ds:operational</name>"
326 " <schema>test-schema</schema>"
327 " </datastore>"
328 " <content-id>1</content-id>"
329 "</yang-library>"
330 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
331 " <module-set-id>1</module-set-id>"
332 "</modules-state>"
333 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
334 " <mount-point>"
335 " <module>sm</module>"
336 " <label>root</label>"
337 " <inline/>"
338 " </mount-point>"
339 "</schema-mounts>");
340 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vasko193dacd2022-10-13 08:43:05 +0200341 CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100342 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vasko193dacd2022-10-13 08:43:05 +0200343 CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", NULL);
Michal Vaskoddd76592022-01-17 13:34:48 +0100344
345 /* callback data correct, invalid YANG data */
346 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
347 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
348 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
349 " <module-set>"
350 " <name>test-set</name>"
351 " <module>"
352 " <name>ietf-datastores</name>"
353 " <revision>2018-02-14</revision>"
354 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
355 " </module>"
356 " <module>"
357 " <name>ietf-yang-library</name>"
358 " <revision>2019-01-04</revision>"
359 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
360 " </module>"
361 " <module>"
362 " <name>ietf-yang-schema-mount</name>"
363 " <revision>2019-01-14</revision>"
364 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
365 " </module>"
366 " <module>"
367 " <name>ietf-interfaces</name>"
368 " <revision>2014-05-08</revision>"
369 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
370 " </module>"
371 " <module>"
372 " <name>iana-if-type</name>"
373 " <revision>2014-05-08</revision>"
374 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
375 " </module>"
376 " <import-only-module>"
377 " <name>ietf-yang-types</name>"
378 " <revision>2013-07-15</revision>"
379 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
380 " </import-only-module>"
381 " </module-set>"
382 " <schema>"
383 " <name>test-schema</name>"
384 " <module-set>test-set</module-set>"
385 " </schema>"
386 " <datastore>"
387 " <name>ds:running</name>"
388 " <schema>test-schema</schema>"
389 " </datastore>"
390 " <datastore>"
391 " <name>ds:operational</name>"
392 " <schema>test-schema</schema>"
393 " </datastore>"
394 " <content-id>1</content-id>"
395 "</yang-library>"
396 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
397 " <module-set-id>1</module-set-id>"
398 "</modules-state>"
399 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
400 " <mount-point>"
401 " <module>sm</module>"
402 " <label>root</label>"
403 " <inline/>"
404 " </mount-point>"
405 "</schema-mounts>");
406 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vasko193dacd2022-10-13 08:43:05 +0200407 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vaskoddd76592022-01-17 13:34:48 +0100408 "Mandatory node \"type\" instance does not exist.",
Michal Vasko959f8d82022-06-16 07:51:50 +0200409 "Schema location \"/ietf-interfaces:interfaces/interface/type\".");
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100410 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, 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 Vasko61ad1ff2022-02-10 15:48:39 +0100412 "Mandatory node \"type\" instance does not exist.",
Michal Vasko193dacd2022-10-13 08:43:05 +0200413 "Schema location \"/ietf-interfaces:interfaces/interface/type\".");
Michal Vaskoddd76592022-01-17 13:34:48 +0100414
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100415 /* same validation fail in separate validation */
Michal Vaskoddd76592022-01-17 13:34:48 +0100416 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT | LYD_PARSE_ONLY, 0, LY_SUCCESS, data);
417 assert_int_equal(LY_EVALID, lyd_validate_all(&data, NULL, LYD_VALIDATE_PRESENT, NULL));
Michal Vasko193dacd2022-10-13 08:43:05 +0200418 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100419 "Mandatory node \"type\" instance does not exist.",
Michal Vasko959f8d82022-06-16 07:51:50 +0200420 "Schema location \"/ietf-interfaces:interfaces/interface/type\".");
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100421 lyd_free_siblings(data);
422
423 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT | LYD_PARSE_ONLY, 0, LY_SUCCESS, data);
424 assert_int_equal(LY_EVALID, lyd_validate_all(&data, NULL, LYD_VALIDATE_PRESENT, NULL));
Michal Vasko193dacd2022-10-13 08:43:05 +0200425 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100426 "Mandatory node \"type\" instance does not exist.",
Michal Vasko959f8d82022-06-16 07:51:50 +0200427 "Schema location \"/ietf-interfaces:interfaces/interface/type\".");
Michal Vaskoddd76592022-01-17 13:34:48 +0100428 lyd_free_siblings(data);
429
430 /* success */
431 xml =
432 "<root xmlns=\"urn:sm\">\n"
433 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
434 " <interface>\n"
435 " <name>bu</name>\n"
436 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
437 " </interface>\n"
438 " </interfaces>\n"
439 "</root>\n";
440 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
441 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
442 lyd_free_siblings(data);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100443
444 json =
445 "{\n"
446 " \"sm:root\": {\n"
447 " \"ietf-interfaces:interfaces\": {\n"
448 " \"interface\": [\n"
449 " {\n"
450 " \"name\": \"bu\",\n"
451 " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
452 " }\n"
453 " ]\n"
454 " }\n"
455 " }\n"
456 "}\n";
457 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
458 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
459 lyd_free_siblings(data);
Michal Vaskoddd76592022-01-17 13:34:48 +0100460}
461
462static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100463test_parse_inline(void **state)
Michal Vaskoddd76592022-01-17 13:34:48 +0100464{
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100465 const char *xml, *json;
Michal Vasko9883a3e2022-03-31 12:16:00 +0200466 char *lyb;
Michal Vaskoddd76592022-01-17 13:34:48 +0100467 struct lyd_node *data;
468
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100469 /* valid */
Michal Vaskoddd76592022-01-17 13:34:48 +0100470 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
471 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
472 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
473 " <module-set>"
474 " <name>test-set</name>"
475 " <module>"
476 " <name>ietf-datastores</name>"
477 " <revision>2018-02-14</revision>"
478 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
479 " </module>"
480 " <module>"
481 " <name>ietf-yang-library</name>"
482 " <revision>2019-01-04</revision>"
483 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
484 " </module>"
485 " <module>"
486 " <name>ietf-yang-schema-mount</name>"
487 " <revision>2019-01-14</revision>"
488 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
489 " </module>"
490 " <module>"
491 " <name>ietf-interfaces</name>"
492 " <revision>2014-05-08</revision>"
493 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
494 " </module>"
495 " <module>"
496 " <name>iana-if-type</name>"
497 " <revision>2014-05-08</revision>"
498 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
499 " </module>"
500 " <import-only-module>"
501 " <name>ietf-yang-types</name>"
502 " <revision>2013-07-15</revision>"
503 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
504 " </import-only-module>"
505 " </module-set>"
506 " <schema>"
507 " <name>test-schema</name>"
508 " <module-set>test-set</module-set>"
509 " </schema>"
510 " <datastore>"
511 " <name>ds:running</name>"
512 " <schema>test-schema</schema>"
513 " </datastore>"
514 " <datastore>"
515 " <name>ds:operational</name>"
516 " <schema>test-schema</schema>"
517 " </datastore>"
518 " <content-id>1</content-id>"
519 "</yang-library>"
520 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
521 " <module-set-id>1</module-set-id>"
522 "</modules-state>"
523 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
524 " <mount-point>"
525 " <module>sm</module>"
526 " <label>root</label>"
527 " <inline/>"
528 " </mount-point>"
529 "</schema-mounts>");
530 xml =
531 "<root xmlns=\"urn:sm\">\n"
532 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
533 " <interface>\n"
534 " <name>bu</name>\n"
535 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
536 " </interface>\n"
537 " </interfaces>\n"
538 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
539 " <interface>\n"
540 " <name>bu</name>\n"
541 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
542 " <oper-status>not-present</oper-status>\n"
543 " <statistics>\n"
544 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
545 " </statistics>\n"
546 " </interface>\n"
547 " </interfaces-state>\n"
548 "</root>\n";
549 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
550 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
551 lyd_free_siblings(data);
552
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100553 json =
554 "{\n"
555 " \"sm:root\": {\n"
556 " \"ietf-interfaces:interfaces\": {\n"
557 " \"interface\": [\n"
558 " {\n"
559 " \"name\": \"bu\",\n"
560 " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
561 " }\n"
562 " ]\n"
563 " },\n"
564 " \"ietf-interfaces:interfaces-state\": {\n"
565 " \"interface\": [\n"
566 " {\n"
567 " \"name\": \"bu\",\n"
568 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
569 " \"oper-status\": \"not-present\",\n"
570 " \"statistics\": {\n"
571 " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n"
572 " }\n"
573 " }\n"
574 " ]\n"
575 " }\n"
576 " }\n"
577 "}\n";
578 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
579 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
580 lyd_free_siblings(data);
581
Michal Vaskoddd76592022-01-17 13:34:48 +0100582 /* different yang-lib data */
583 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
584 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
585 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
586 " <module-set>"
587 " <name>test-set</name>"
588 " <module>"
589 " <name>ietf-datastores</name>"
590 " <revision>2018-02-14</revision>"
591 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
592 " </module>"
593 " <module>"
594 " <name>ietf-yang-library</name>"
595 " <revision>2019-01-04</revision>"
596 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
597 " </module>"
598 " <module>"
599 " <name>ietf-yang-schema-mount</name>"
600 " <revision>2019-01-14</revision>"
601 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
602 " </module>"
603 " <module>"
604 " <name>ietf-interfaces</name>"
605 " <revision>2014-05-08</revision>"
606 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
607 " </module>"
608 " <module>"
609 " <name>ietf-ip</name>"
610 " <revision>2014-06-16</revision>"
611 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
612 " </module>"
613 " <module>"
614 " <name>iana-if-type</name>"
615 " <revision>2014-05-08</revision>"
616 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
617 " </module>"
618 " <import-only-module>"
619 " <name>ietf-yang-types</name>"
620 " <revision>2013-07-15</revision>"
621 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
622 " </import-only-module>"
623 " </module-set>"
624 " <schema>"
625 " <name>test-schema</name>"
626 " <module-set>test-set</module-set>"
627 " </schema>"
628 " <datastore>"
629 " <name>ds:running</name>"
630 " <schema>test-schema</schema>"
631 " </datastore>"
632 " <datastore>"
633 " <name>ds:operational</name>"
634 " <schema>test-schema</schema>"
635 " </datastore>"
636 " <content-id>1</content-id>"
637 "</yang-library>"
638 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
639 " <module-set-id>1</module-set-id>"
640 "</modules-state>"
641 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
642 " <mount-point>"
643 " <module>sm</module>"
644 " <label>root</label>"
645 " <inline/>"
646 " </mount-point>"
647 "</schema-mounts>");
648 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
649 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
650 lyd_free_siblings(data);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100651
652 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
653 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
Michal Vasko9883a3e2022-03-31 12:16:00 +0200654
655 assert_int_equal(LY_SUCCESS, lyd_print_mem(&lyb, data, LYD_LYB, 0));
656 lyd_free_siblings(data);
657
658 CHECK_PARSE_LYD_PARAM(lyb, LYD_LYB, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
659 free(lyb);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100660 lyd_free_siblings(data);
Michal Vaskoddd76592022-01-17 13:34:48 +0100661}
662
663static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100664test_parse_shared(void **state)
Michal Vaskoddd76592022-01-17 13:34:48 +0100665{
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100666 const char *xml, *json;
Michal Vasko9883a3e2022-03-31 12:16:00 +0200667 char *lyb;
Michal Vaskoddd76592022-01-17 13:34:48 +0100668 struct lyd_node *data;
669
670 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
671 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
672 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
673 " <module-set>"
674 " <name>test-set</name>"
675 " <module>"
676 " <name>ietf-datastores</name>"
677 " <revision>2018-02-14</revision>"
678 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
679 " </module>"
680 " <module>"
681 " <name>ietf-yang-library</name>"
682 " <revision>2019-01-04</revision>"
683 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
684 " </module>"
685 " <module>"
686 " <name>ietf-yang-schema-mount</name>"
687 " <revision>2019-01-14</revision>"
688 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
689 " </module>"
690 " <module>"
691 " <name>ietf-interfaces</name>"
692 " <revision>2014-05-08</revision>"
693 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
694 " </module>"
695 " <module>"
696 " <name>iana-if-type</name>"
697 " <revision>2014-05-08</revision>"
698 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
699 " </module>"
700 " <import-only-module>"
701 " <name>ietf-yang-types</name>"
702 " <revision>2013-07-15</revision>"
703 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
704 " </import-only-module>"
705 " </module-set>"
706 " <schema>"
707 " <name>test-schema</name>"
708 " <module-set>test-set</module-set>"
709 " </schema>"
710 " <datastore>"
711 " <name>ds:running</name>"
712 " <schema>test-schema</schema>"
713 " </datastore>"
714 " <datastore>"
715 " <name>ds:operational</name>"
716 " <schema>test-schema</schema>"
717 " </datastore>"
718 " <content-id>1</content-id>"
719 "</yang-library>"
720 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
721 " <module-set-id>1</module-set-id>"
722 "</modules-state>"
723 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
724 " <mount-point>"
725 " <module>sm</module>"
726 " <label>root</label>"
727 " <shared-schema/>"
728 " </mount-point>"
729 "</schema-mounts>");
730 xml =
731 "<root xmlns=\"urn:sm\">\n"
732 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
733 " <interface>\n"
734 " <name>bu</name>\n"
735 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
736 " </interface>\n"
737 " </interfaces>\n"
738 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
739 " <interface>\n"
740 " <name>bu</name>\n"
741 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
742 " <oper-status>not-present</oper-status>\n"
743 " <statistics>\n"
744 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
745 " </statistics>\n"
746 " </interface>\n"
747 " </interfaces-state>\n"
748 "</root>\n";
749 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
750 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
751 lyd_free_siblings(data);
752
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100753 json =
754 "{\n"
755 " \"sm:root\": {\n"
756 " \"ietf-interfaces:interfaces\": {\n"
757 " \"interface\": [\n"
758 " {\n"
759 " \"name\": \"bu\",\n"
760 " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
761 " }\n"
762 " ]\n"
763 " },\n"
764 " \"ietf-interfaces:interfaces-state\": {\n"
765 " \"interface\": [\n"
766 " {\n"
767 " \"name\": \"bu\",\n"
768 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
769 " \"oper-status\": \"not-present\",\n"
770 " \"statistics\": {\n"
771 " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n"
772 " }\n"
773 " }\n"
774 " ]\n"
775 " }\n"
776 " }\n"
777 "}\n";
778 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
779 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
780 lyd_free_siblings(data);
781
Michal Vaskoddd76592022-01-17 13:34:48 +0100782 /* different yang-lib data */
783 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
784 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
785 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
786 " <module-set>"
787 " <name>test-set</name>"
788 " <module>"
789 " <name>ietf-datastores</name>"
790 " <revision>2018-02-14</revision>"
791 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
792 " </module>"
793 " <module>"
794 " <name>ietf-yang-library</name>"
795 " <revision>2019-01-04</revision>"
796 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
797 " </module>"
798 " <module>"
799 " <name>ietf-yang-schema-mount</name>"
800 " <revision>2019-01-14</revision>"
801 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
802 " </module>"
803 " <module>"
804 " <name>ietf-interfaces</name>"
805 " <revision>2014-05-08</revision>"
806 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
807 " </module>"
808 " <module>"
809 " <name>ietf-ip</name>"
810 " <revision>2014-06-16</revision>"
811 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
812 " </module>"
813 " <module>"
814 " <name>iana-if-type</name>"
815 " <revision>2014-05-08</revision>"
816 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
817 " </module>"
818 " <import-only-module>"
819 " <name>ietf-yang-types</name>"
820 " <revision>2013-07-15</revision>"
821 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
822 " </import-only-module>"
823 " </module-set>"
824 " <schema>"
825 " <name>test-schema</name>"
826 " <module-set>test-set</module-set>"
827 " </schema>"
828 " <datastore>"
829 " <name>ds:running</name>"
830 " <schema>test-schema</schema>"
831 " </datastore>"
832 " <datastore>"
833 " <name>ds:operational</name>"
834 " <schema>test-schema</schema>"
835 " </datastore>"
836 " <content-id>2</content-id>"
837 "</yang-library>"
838 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
839 " <module-set-id>1</module-set-id>"
840 "</modules-state>"
841 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
842 " <mount-point>"
843 " <module>sm</module>"
844 " <label>root</label>"
845 " <shared-schema/>"
846 " </mount-point>"
847 "</schema-mounts>");
848 xml =
849 "<root2 xmlns=\"urn:sm\">\n"
850 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
851 " <interface>\n"
852 " <name>bu</name>\n"
853 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
854 " </interface>\n"
855 " </interfaces>\n"
856 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
857 " <interface>\n"
858 " <name>bu</name>\n"
859 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
860 " <oper-status>not-present</oper-status>\n"
861 " <statistics>\n"
862 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
863 " </statistics>\n"
864 " </interface>\n"
865 " </interfaces-state>\n"
866 "</root2>\n";
867 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vasko193dacd2022-10-13 08:43:05 +0200868 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vaskoddd76592022-01-17 13:34:48 +0100869 "Shared-schema yang-library content-id \"2\" differs from \"1\" used previously.",
870 "/ietf-yang-library:yang-library/content-id");
871
872 /* data for 2 mount points */
873 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
874 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
875 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
876 " <module-set>"
877 " <name>test-set</name>"
878 " <module>"
879 " <name>ietf-datastores</name>"
880 " <revision>2018-02-14</revision>"
881 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
882 " </module>"
883 " <module>"
884 " <name>ietf-yang-library</name>"
885 " <revision>2019-01-04</revision>"
886 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
887 " </module>"
888 " <module>"
889 " <name>ietf-yang-schema-mount</name>"
890 " <revision>2019-01-14</revision>"
891 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
892 " </module>"
893 " <module>"
894 " <name>ietf-interfaces</name>"
895 " <revision>2014-05-08</revision>"
896 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
897 " </module>"
898 " <module>"
899 " <name>iana-if-type</name>"
900 " <revision>2014-05-08</revision>"
901 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
902 " </module>"
903 " <import-only-module>"
904 " <name>ietf-yang-types</name>"
905 " <revision>2013-07-15</revision>"
906 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
907 " </import-only-module>"
908 " </module-set>"
909 " <schema>"
910 " <name>test-schema</name>"
911 " <module-set>test-set</module-set>"
912 " </schema>"
913 " <datastore>"
914 " <name>ds:running</name>"
915 " <schema>test-schema</schema>"
916 " </datastore>"
917 " <datastore>"
918 " <name>ds:operational</name>"
919 " <schema>test-schema</schema>"
920 " </datastore>"
921 " <content-id>1</content-id>"
922 "</yang-library>"
923 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
924 " <module-set-id>1</module-set-id>"
925 "</modules-state>"
926 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
927 " <mount-point>"
928 " <module>sm</module>"
929 " <label>root</label>"
930 " <shared-schema/>"
931 " </mount-point>"
932 "</schema-mounts>");
933 xml =
934 "<root xmlns=\"urn:sm\">\n"
935 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
936 " <interface>\n"
937 " <name>bu</name>\n"
938 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
939 " </interface>\n"
940 " </interfaces>\n"
941 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
942 " <interface>\n"
943 " <name>bu</name>\n"
944 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
945 " <oper-status>not-present</oper-status>\n"
946 " <statistics>\n"
947 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
948 " </statistics>\n"
949 " </interface>\n"
950 " </interfaces-state>\n"
951 "</root>\n"
952 "<root2 xmlns=\"urn:sm\">\n"
953 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
954 " <interface>\n"
955 " <name>fu</name>\n"
956 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:fddi</type>\n"
957 " </interface>\n"
958 " </interfaces>\n"
959 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
960 " <interface>\n"
961 " <name>fu</name>\n"
962 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:fddi</type>\n"
963 " <oper-status>down</oper-status>\n"
964 " <statistics>\n"
965 " <discontinuity-time>2020-01-01T10:00:00-00:00</discontinuity-time>\n"
966 " </statistics>\n"
967 " </interface>\n"
968 " </interfaces-state>\n"
969 "</root2>\n";
970 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
971 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
972 lyd_free_siblings(data);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100973
974 json =
975 "{\n"
976 " \"sm:root\": {\n"
977 " \"ietf-interfaces:interfaces\": {\n"
978 " \"interface\": [\n"
979 " {\n"
980 " \"name\": \"bu\",\n"
981 " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
982 " }\n"
983 " ]\n"
984 " },\n"
985 " \"ietf-interfaces:interfaces-state\": {\n"
986 " \"interface\": [\n"
987 " {\n"
988 " \"name\": \"bu\",\n"
989 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
990 " \"oper-status\": \"not-present\",\n"
991 " \"statistics\": {\n"
992 " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n"
993 " }\n"
994 " }\n"
995 " ]\n"
996 " }\n"
997 " },\n"
998 " \"sm:root2\": {\n"
999 " \"ietf-interfaces:interfaces\": {\n"
1000 " \"interface\": [\n"
1001 " {\n"
1002 " \"name\": \"fu\",\n"
1003 " \"type\": \"iana-if-type:fddi\"\n"
1004 " }\n"
1005 " ]\n"
1006 " },\n"
1007 " \"ietf-interfaces:interfaces-state\": {\n"
1008 " \"interface\": [\n"
1009 " {\n"
1010 " \"name\": \"fu\",\n"
1011 " \"type\": \"iana-if-type:fddi\",\n"
1012 " \"oper-status\": \"down\",\n"
1013 " \"statistics\": {\n"
1014 " \"discontinuity-time\": \"2020-01-01T10:00:00-00:00\"\n"
1015 " }\n"
1016 " }\n"
1017 " ]\n"
1018 " }\n"
1019 " }\n"
1020 "}\n";
1021 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1022 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
Michal Vasko9883a3e2022-03-31 12:16:00 +02001023
1024 assert_int_equal(LY_SUCCESS, lyd_print_mem(&lyb, data, LYD_LYB, LYD_PRINT_WITHSIBLINGS));
1025 lyd_free_siblings(data);
1026
1027 CHECK_PARSE_LYD_PARAM(lyb, LYD_LYB, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1028 free(lyb);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001029 lyd_free_siblings(data);
Michal Vaskoddd76592022-01-17 13:34:48 +01001030}
1031
1032static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001033test_parse_shared_parent_ref(void **state)
Michal Vaskoddd76592022-01-17 13:34:48 +01001034{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001035 const char *xml, *json;
Michal Vaskoddd76592022-01-17 13:34:48 +01001036 struct lyd_node *data;
1037
1038 /* wrong leafref value */
1039 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
1040 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1041 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1042 " <module-set>"
1043 " <name>test-set</name>"
1044 " <module>"
1045 " <name>ietf-datastores</name>"
1046 " <revision>2018-02-14</revision>"
1047 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1048 " </module>"
1049 " <module>"
1050 " <name>ietf-yang-library</name>"
1051 " <revision>2019-01-04</revision>"
1052 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1053 " </module>"
1054 " <module>"
1055 " <name>ietf-yang-schema-mount</name>"
1056 " <revision>2019-01-14</revision>"
1057 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1058 " </module>"
1059 " <module>"
1060 " <name>sm</name>"
1061 " <namespace>urn:sm</namespace>"
1062 " </module>"
1063 " <module>"
1064 " <name>ietf-interfaces</name>"
1065 " <revision>2014-05-08</revision>"
1066 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
1067 " </module>"
1068 " <module>"
1069 " <name>iana-if-type</name>"
1070 " <revision>2014-05-08</revision>"
1071 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
1072 " </module>"
1073 " <import-only-module>"
1074 " <name>ietf-yang-types</name>"
1075 " <revision>2013-07-15</revision>"
1076 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
1077 " </import-only-module>"
1078 " </module-set>"
1079 " <schema>"
1080 " <name>test-schema</name>"
1081 " <module-set>test-set</module-set>"
1082 " </schema>"
1083 " <datastore>"
1084 " <name>ds:running</name>"
1085 " <schema>test-schema</schema>"
1086 " </datastore>"
1087 " <datastore>"
1088 " <name>ds:operational</name>"
1089 " <schema>test-schema</schema>"
1090 " </datastore>"
1091 " <content-id>1</content-id>"
1092 "</yang-library>"
1093 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1094 " <module-set-id>1</module-set-id>"
1095 "</modules-state>"
1096 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1097 " <namespace>"
1098 " <prefix>smp</prefix>"
1099 " <uri>urn:sm</uri>"
1100 " </namespace>"
1101 " <mount-point>"
1102 " <module>sm</module>"
1103 " <label>mnt-root</label>"
1104 " <shared-schema>"
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001105 " <parent-reference>/smp:target[. = current()/smp:name]</parent-reference>"
Michal Vaskoddd76592022-01-17 13:34:48 +01001106 " </shared-schema>"
1107 " </mount-point>"
1108 "</schema-mounts>");
1109 xml =
1110 "<root3 xmlns=\"urn:sm\">\n"
1111 " <ls>\n"
1112 " <name>target-value</name>\n"
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001113 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1114 " <interface>\n"
1115 " <name>bu</name>\n"
1116 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1117 " <sm-name xmlns=\"urn:sm\">target-value</sm-name>\n"
1118 " </interface>\n"
1119 " </interfaces>\n"
Michal Vaskoddd76592022-01-17 13:34:48 +01001120 " </ls>\n"
1121 "</root3>\n"
1122 "<target xmlns=\"urn:sm\">wrong-target-value</target>\n";
1123 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vasko193dacd2022-10-13 08:43:05 +02001124 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vasko5edfefd2022-08-05 10:07:11 +02001125 "Invalid leafref value \"target-value\" - no target instance \"/sm:target\" with the same value.",
Michal Vaskodbf3e652022-10-21 08:46:25 +02001126 "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);
Michal Vasko193dacd2022-10-13 08:43:05 +02001149 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vasko5edfefd2022-08-05 10:07:11 +02001150 "Invalid leafref value \"target-value\" - no target instance \"/sm:target\" with the same value.",
Michal Vaskodbf3e652022-10-21 08:46:25 +02001151 "Data location \"/ietf-interfaces:interfaces/interface[name='bu']/sm:sm-name\", line number 18.");
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001152
Michal Vaskoddd76592022-01-17 13:34:48 +01001153 /* success */
1154 xml =
1155 "<root3 xmlns=\"urn:sm\">\n"
1156 " <ls>\n"
1157 " <name>target-value</name>\n"
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001158 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1159 " <interface>\n"
1160 " <name>bu</name>\n"
1161 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1162 " <sm-name xmlns=\"urn:sm\">target-value</sm-name>\n"
1163 " </interface>\n"
1164 " </interfaces>\n"
Michal Vaskoddd76592022-01-17 13:34:48 +01001165 " </ls>\n"
1166 "</root3>\n"
1167 "<target xmlns=\"urn:sm\">target-value</target>\n";
1168 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1169 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1170 lyd_free_siblings(data);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001171
1172 json =
1173 "{\n"
1174 " \"sm:root3\": {\n"
1175 " \"ls\": [\n"
1176 " {\n"
1177 " \"name\": \"target-value\",\n"
1178 " \"ietf-interfaces:interfaces\": {\n"
1179 " \"interface\": [\n"
1180 " {\n"
1181 " \"name\": \"bu\",\n"
1182 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
1183 " \"sm:sm-name\": \"target-value\"\n"
1184 " }\n"
1185 " ]\n"
1186 " }\n"
1187 " }\n"
1188 " ]\n"
1189 " },\n"
1190 " \"sm:target\": \"target-value\"\n"
1191 "}\n";
1192 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1193 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
1194 lyd_free_siblings(data);
Michal Vaskoddd76592022-01-17 13:34:48 +01001195}
1196
1197static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001198test_parse_config(void **state)
Michal Vaskoddd76592022-01-17 13:34:48 +01001199{
1200 const char *xml;
Michal Vasko24edeb92022-07-20 08:08:46 +02001201 char *lyb;
Michal Vaskoddd76592022-01-17 13:34:48 +01001202 struct lyd_node *data;
1203 const struct lyd_node *node;
1204
1205 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
1206 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1207 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1208 " <module-set>"
1209 " <name>test-set</name>"
1210 " <module>"
1211 " <name>ietf-datastores</name>"
1212 " <revision>2018-02-14</revision>"
1213 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1214 " </module>"
1215 " <module>"
1216 " <name>ietf-yang-library</name>"
1217 " <revision>2019-01-04</revision>"
1218 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1219 " </module>"
1220 " <module>"
1221 " <name>ietf-yang-schema-mount</name>"
1222 " <revision>2019-01-14</revision>"
1223 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1224 " </module>"
1225 " <module>"
1226 " <name>ietf-interfaces</name>"
1227 " <revision>2014-05-08</revision>"
1228 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
1229 " </module>"
1230 " <module>"
1231 " <name>iana-if-type</name>"
1232 " <revision>2014-05-08</revision>"
1233 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
1234 " </module>"
1235 " <import-only-module>"
1236 " <name>ietf-yang-types</name>"
1237 " <revision>2013-07-15</revision>"
1238 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
1239 " </import-only-module>"
1240 " </module-set>"
1241 " <schema>"
1242 " <name>test-schema</name>"
1243 " <module-set>test-set</module-set>"
1244 " </schema>"
1245 " <datastore>"
1246 " <name>ds:running</name>"
1247 " <schema>test-schema</schema>"
1248 " </datastore>"
1249 " <datastore>"
1250 " <name>ds:operational</name>"
1251 " <schema>test-schema</schema>"
1252 " </datastore>"
1253 " <content-id>1</content-id>"
1254 "</yang-library>"
1255 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1256 " <module-set-id>1</module-set-id>"
1257 "</modules-state>"
1258 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1259 " <mount-point>"
1260 " <module>sm</module>"
1261 " <label>root</label>"
1262 " <config>false</config>"
1263 " <inline/>"
1264 " </mount-point>"
1265 "</schema-mounts>");
1266 xml =
1267 "<root xmlns=\"urn:sm\">\n"
1268 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1269 " <interface>\n"
1270 " <name>bu</name>\n"
1271 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1272 " <enabled>true</enabled>\n"
1273 " </interface>\n"
1274 " </interfaces>\n"
1275 "</root>\n";
1276 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1277 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1278
1279 node = lyd_child(data);
1280 assert_string_equal(LYD_NAME(node), "interfaces");
1281 assert_true(node->schema->flags & LYS_CONFIG_R);
1282 node = lyd_child(node);
1283 assert_string_equal(LYD_NAME(node), "interface");
1284 assert_true(node->schema->flags & LYS_CONFIG_R);
1285 node = lyd_child(node);
1286 assert_string_equal(LYD_NAME(node), "name");
1287 assert_true(node->schema->flags & LYS_CONFIG_R);
1288 node = node->next;
1289 assert_string_equal(LYD_NAME(node), "type");
1290 assert_true(node->schema->flags & LYS_CONFIG_R);
1291
Michal Vasko24edeb92022-07-20 08:08:46 +02001292 lyd_print_mem(&lyb, data, LYD_LYB, 0);
1293 lyd_free_siblings(data);
1294 CHECK_PARSE_LYD_PARAM(lyb, LYD_LYB, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1295 free(lyb);
1296
1297 node = lyd_child(data);
1298 assert_string_equal(LYD_NAME(node), "interfaces");
1299 assert_true(node->schema->flags & LYS_CONFIG_R);
1300 node = lyd_child(node);
1301 assert_string_equal(LYD_NAME(node), "interface");
1302 assert_true(node->schema->flags & LYS_CONFIG_R);
1303 node = lyd_child(node);
1304 assert_string_equal(LYD_NAME(node), "name");
1305 assert_true(node->schema->flags & LYS_CONFIG_R);
1306 node = node->next;
1307 assert_string_equal(LYD_NAME(node), "type");
1308 assert_true(node->schema->flags & LYS_CONFIG_R);
1309
Michal Vaskoddd76592022-01-17 13:34:48 +01001310 lyd_free_siblings(data);
Michal Vasko9e12ffe2022-09-21 15:11:30 +02001311
1312 /* the same effect but use a config false mount point instead of the separate metadata node */
1313 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
1314 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1315 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1316 " <module-set>"
1317 " <name>test-set</name>"
1318 " <module>"
1319 " <name>ietf-datastores</name>"
1320 " <revision>2018-02-14</revision>"
1321 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1322 " </module>"
1323 " <module>"
1324 " <name>ietf-yang-library</name>"
1325 " <revision>2019-01-04</revision>"
1326 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1327 " </module>"
1328 " <module>"
1329 " <name>ietf-yang-schema-mount</name>"
1330 " <revision>2019-01-14</revision>"
1331 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1332 " </module>"
1333 " <module>"
1334 " <name>ietf-interfaces</name>"
1335 " <revision>2014-05-08</revision>"
1336 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
1337 " </module>"
1338 " <module>"
1339 " <name>iana-if-type</name>"
1340 " <revision>2014-05-08</revision>"
1341 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
1342 " </module>"
1343 " <import-only-module>"
1344 " <name>ietf-yang-types</name>"
1345 " <revision>2013-07-15</revision>"
1346 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
1347 " </import-only-module>"
1348 " </module-set>"
1349 " <schema>"
1350 " <name>test-schema</name>"
1351 " <module-set>test-set</module-set>"
1352 " </schema>"
1353 " <datastore>"
1354 " <name>ds:running</name>"
1355 " <schema>test-schema</schema>"
1356 " </datastore>"
1357 " <datastore>"
1358 " <name>ds:operational</name>"
1359 " <schema>test-schema</schema>"
1360 " </datastore>"
1361 " <content-id>1</content-id>"
1362 "</yang-library>"
1363 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1364 " <module-set-id>1</module-set-id>"
1365 "</modules-state>"
1366 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1367 " <mount-point>"
1368 " <module>sm</module>"
1369 " <label>root</label>"
1370 " <inline/>"
1371 " </mount-point>"
1372 "</schema-mounts>");
1373 xml =
1374 "<root4 xmlns=\"urn:sm\">\n"
1375 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1376 " <interface>\n"
1377 " <name>bu</name>\n"
1378 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1379 " <enabled>true</enabled>\n"
1380 " </interface>\n"
1381 " </interfaces>\n"
1382 "</root4>\n";
1383 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1384 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1385
1386 node = lyd_child(data->next->next->next);
1387 assert_string_equal(LYD_NAME(node), "interfaces");
1388 assert_true(node->schema->flags & LYS_CONFIG_R);
1389 node = lyd_child(node);
1390 assert_string_equal(LYD_NAME(node), "interface");
1391 assert_true(node->schema->flags & LYS_CONFIG_R);
1392 node = lyd_child(node);
1393 assert_string_equal(LYD_NAME(node), "name");
1394 assert_true(node->schema->flags & LYS_CONFIG_R);
1395 node = node->next;
1396 assert_string_equal(LYD_NAME(node), "type");
1397 assert_true(node->schema->flags & LYS_CONFIG_R);
1398
1399 lyd_free_siblings(data);
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +01001400}
1401
Michal Vasko8cc3f662022-03-29 11:25:51 +02001402static void
1403test_new(void **state)
1404{
1405 const char *xml;
1406 const struct lys_module *mod;
1407 struct lyd_node *data, *node;
1408
1409 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
1410 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1411 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1412 " <module-set>"
1413 " <name>test-set</name>"
1414 " <module>"
1415 " <name>ietf-datastores</name>"
1416 " <revision>2018-02-14</revision>"
1417 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1418 " </module>"
1419 " <module>"
1420 " <name>ietf-yang-library</name>"
1421 " <revision>2019-01-04</revision>"
1422 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1423 " </module>"
1424 " <module>"
1425 " <name>ietf-yang-schema-mount</name>"
1426 " <revision>2019-01-14</revision>"
1427 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1428 " </module>"
1429 " <module>"
1430 " <name>ietf-interfaces</name>"
1431 " <revision>2014-05-08</revision>"
1432 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
1433 " </module>"
1434 " <module>"
1435 " <name>iana-if-type</name>"
1436 " <revision>2014-05-08</revision>"
1437 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
1438 " </module>"
Michal Vasko35b29622022-07-22 14:12:56 +02001439 " <module>"
1440 " <name>ietf-ip</name>"
1441 " <revision>2014-06-16</revision>"
1442 " <namespace>urn:ietf:params:xml:ns:yang:ietf-ip</namespace>"
1443 " </module>"
Michal Vasko8cc3f662022-03-29 11:25:51 +02001444 " <import-only-module>"
1445 " <name>ietf-yang-types</name>"
1446 " <revision>2013-07-15</revision>"
1447 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
1448 " </import-only-module>"
1449 " </module-set>"
1450 " <schema>"
1451 " <name>test-schema</name>"
1452 " <module-set>test-set</module-set>"
1453 " </schema>"
1454 " <datastore>"
1455 " <name>ds:running</name>"
1456 " <schema>test-schema</schema>"
1457 " </datastore>"
1458 " <datastore>"
1459 " <name>ds:operational</name>"
1460 " <schema>test-schema</schema>"
1461 " </datastore>"
1462 " <content-id>1</content-id>"
1463 "</yang-library>"
1464 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1465 " <module-set-id>1</module-set-id>"
1466 "</modules-state>"
1467 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1468 " <mount-point>"
1469 " <module>sm</module>"
1470 " <label>root</label>"
1471 " <shared-schema/>"
1472 " </mount-point>"
1473 "</schema-mounts>");
1474 xml =
1475 "<root xmlns=\"urn:sm\">\n"
1476 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1477 " <interface>\n"
1478 " <name>bu</name>\n"
1479 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
Michal Vasko35b29622022-07-22 14:12:56 +02001480 " <ipv4 xmlns=\"urn:ietf:params:xml:ns:yang:ietf-ip\">\n"
1481 " <enabled>false</enabled>\n"
1482 " </ipv4>\n"
Michal Vasko8cc3f662022-03-29 11:25:51 +02001483 " </interface>\n"
1484 " </interfaces>\n"
1485 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1486 " <interface>\n"
1487 " <name>bu</name>\n"
1488 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1489 " <oper-status>not-present</oper-status>\n"
1490 " <statistics>\n"
1491 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
1492 " </statistics>\n"
1493 " </interface>\n"
1494 " </interfaces-state>\n"
1495 "</root>\n";
1496
1497 /* create the data manually with simple new functions */
1498 mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "sm");
1499 assert_non_null(mod);
1500 assert_int_equal(LY_SUCCESS, lyd_new_inner(NULL, mod, "root", 0, &data));
1501
1502 mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "ietf-interfaces");
1503 assert_non_null(mod);
1504 assert_int_equal(LY_SUCCESS, lyd_new_inner(data, mod, "interfaces", 0, &node));
1505 assert_int_equal(LY_SUCCESS, lyd_new_list(node, NULL, "interface", 0, &node, "bu"));
1506 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "type", "iana-if-type:ethernetCsmacd", 0, NULL));
Michal Vasko35b29622022-07-22 14:12:56 +02001507 mod = ly_ctx_get_module_implemented(LYD_CTX(node), "ietf-ip");
1508 assert_non_null(mod);
1509 assert_int_equal(LY_SUCCESS, lyd_new_inner(node, mod, "ipv4", 0, &node));
1510 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "enabled", "false", 0, NULL));
Michal Vasko8cc3f662022-03-29 11:25:51 +02001511
Michal Vasko35b29622022-07-22 14:12:56 +02001512 mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "ietf-interfaces");
1513 assert_non_null(mod);
Michal Vasko8cc3f662022-03-29 11:25:51 +02001514 assert_int_equal(LY_SUCCESS, lyd_new_inner(data, mod, "interfaces-state", 0, &node));
1515 assert_int_equal(LY_SUCCESS, lyd_new_list(node, NULL, "interface", 0, &node, "bu"));
1516 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "type", "iana-if-type:ethernetCsmacd", 0, NULL));
1517 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "oper-status", "not-present", 0, NULL));
1518 assert_int_equal(LY_SUCCESS, lyd_new_inner(node, NULL, "statistics", 0, &node));
1519 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "discontinuity-time", "2022-01-01T10:00:00-00:00", 0, NULL));
1520
1521 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1522 lyd_free_siblings(data);
1523
1524 /* create the data using lyd_new_path */
1525 assert_int_equal(LY_SUCCESS, lyd_new_path(NULL, UTEST_LYCTX,
1526 "/sm:root/ietf-interfaces:interfaces/interface[name='bu']/type", "iana-if-type:ethernetCsmacd", 0, &data));
1527 assert_int_equal(LY_SUCCESS, lyd_new_path(data, NULL,
Michal Vasko35b29622022-07-22 14:12:56 +02001528 "/sm:root/ietf-interfaces:interfaces/interface[name='bu']/ietf-ip:ipv4/enabled", "false", 0, NULL));
1529 assert_int_equal(LY_SUCCESS, lyd_new_path(data, NULL,
Michal Vasko8cc3f662022-03-29 11:25:51 +02001530 "/sm:root/ietf-interfaces:interfaces-state/interface[name='bu']/type", "iana-if-type:ethernetCsmacd", 0, NULL));
1531 assert_int_equal(LY_SUCCESS, lyd_new_path(data, NULL,
1532 "/sm:root/ietf-interfaces:interfaces-state/interface[name='bu']/oper-status", "not-present", 0, NULL));
1533 assert_int_equal(LY_SUCCESS, lyd_new_path(data, NULL,
1534 "/sm:root/ietf-interfaces:interfaces-state/interface[name='bu']/statistics/discontinuity-time",
1535 "2022-01-01T10:00:00-00:00", 0, NULL));
1536
1537 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1538 lyd_free_siblings(data);
1539}
1540
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +01001541int
1542main(void)
1543{
1544 const struct CMUnitTest tests[] = {
Michal Vaskoddd76592022-01-17 13:34:48 +01001545 UTEST(test_schema),
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001546 UTEST(test_parse_invalid, setup),
1547 UTEST(test_parse_inline, setup),
1548 UTEST(test_parse_shared, setup),
1549 UTEST(test_parse_shared_parent_ref, setup),
1550 UTEST(test_parse_config, setup),
Michal Vasko8cc3f662022-03-29 11:25:51 +02001551 UTEST(test_new, setup),
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +01001552 };
1553
1554 return cmocka_run_group_tests(tests, NULL, NULL);
1555}