blob: ded8ce666b4e5f703c51313a251d763847211370 [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;
Michal Vasko27653162022-11-21 13:58:44 +0100468 const struct ly_ctx *ext_ctx;
Michal Vaskoddd76592022-01-17 13:34:48 +0100469
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100470 /* valid */
Michal Vaskoddd76592022-01-17 13:34:48 +0100471 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
472 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
473 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
474 " <module-set>"
475 " <name>test-set</name>"
476 " <module>"
477 " <name>ietf-datastores</name>"
478 " <revision>2018-02-14</revision>"
479 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
480 " </module>"
481 " <module>"
482 " <name>ietf-yang-library</name>"
483 " <revision>2019-01-04</revision>"
484 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
485 " </module>"
486 " <module>"
487 " <name>ietf-yang-schema-mount</name>"
488 " <revision>2019-01-14</revision>"
489 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
490 " </module>"
491 " <module>"
492 " <name>ietf-interfaces</name>"
493 " <revision>2014-05-08</revision>"
494 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
495 " </module>"
496 " <module>"
497 " <name>iana-if-type</name>"
498 " <revision>2014-05-08</revision>"
499 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
500 " </module>"
501 " <import-only-module>"
502 " <name>ietf-yang-types</name>"
503 " <revision>2013-07-15</revision>"
504 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
505 " </import-only-module>"
506 " </module-set>"
507 " <schema>"
508 " <name>test-schema</name>"
509 " <module-set>test-set</module-set>"
510 " </schema>"
511 " <datastore>"
512 " <name>ds:running</name>"
513 " <schema>test-schema</schema>"
514 " </datastore>"
515 " <datastore>"
516 " <name>ds:operational</name>"
517 " <schema>test-schema</schema>"
518 " </datastore>"
519 " <content-id>1</content-id>"
520 "</yang-library>"
521 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
522 " <module-set-id>1</module-set-id>"
523 "</modules-state>"
524 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
525 " <mount-point>"
526 " <module>sm</module>"
527 " <label>root</label>"
528 " <inline/>"
529 " </mount-point>"
530 "</schema-mounts>");
531 xml =
532 "<root xmlns=\"urn:sm\">\n"
533 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
534 " <interface>\n"
535 " <name>bu</name>\n"
536 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
537 " </interface>\n"
538 " </interfaces>\n"
539 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
540 " <interface>\n"
541 " <name>bu</name>\n"
542 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
543 " <oper-status>not-present</oper-status>\n"
544 " <statistics>\n"
545 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
546 " </statistics>\n"
547 " </interface>\n"
548 " </interfaces-state>\n"
549 "</root>\n";
550 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
551 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
Michal Vasko27653162022-11-21 13:58:44 +0100552 ext_ctx = LYD_CTX(lyd_child(data));
Michal Vaskoddd76592022-01-17 13:34:48 +0100553 lyd_free_siblings(data);
554
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100555 json =
556 "{\n"
557 " \"sm:root\": {\n"
558 " \"ietf-interfaces:interfaces\": {\n"
559 " \"interface\": [\n"
560 " {\n"
561 " \"name\": \"bu\",\n"
562 " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
563 " }\n"
564 " ]\n"
565 " },\n"
566 " \"ietf-interfaces:interfaces-state\": {\n"
567 " \"interface\": [\n"
568 " {\n"
569 " \"name\": \"bu\",\n"
570 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
571 " \"oper-status\": \"not-present\",\n"
572 " \"statistics\": {\n"
573 " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n"
574 " }\n"
575 " }\n"
576 " ]\n"
577 " }\n"
578 " }\n"
579 "}\n";
580 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
581 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
Michal Vasko27653162022-11-21 13:58:44 +0100582 assert_ptr_equal(ext_ctx, LYD_CTX(lyd_child(data)));
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100583 lyd_free_siblings(data);
584
Michal Vasko27653162022-11-21 13:58:44 +0100585 /* different yang-lib data with the same content-id */
Michal Vaskoddd76592022-01-17 13:34:48 +0100586 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
587 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
588 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
589 " <module-set>"
590 " <name>test-set</name>"
591 " <module>"
592 " <name>ietf-datastores</name>"
593 " <revision>2018-02-14</revision>"
594 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
595 " </module>"
596 " <module>"
597 " <name>ietf-yang-library</name>"
598 " <revision>2019-01-04</revision>"
599 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
600 " </module>"
601 " <module>"
602 " <name>ietf-yang-schema-mount</name>"
603 " <revision>2019-01-14</revision>"
604 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
605 " </module>"
606 " <module>"
607 " <name>ietf-interfaces</name>"
608 " <revision>2014-05-08</revision>"
609 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
610 " </module>"
611 " <module>"
612 " <name>ietf-ip</name>"
613 " <revision>2014-06-16</revision>"
614 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
615 " </module>"
616 " <module>"
617 " <name>iana-if-type</name>"
618 " <revision>2014-05-08</revision>"
619 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
620 " </module>"
621 " <import-only-module>"
622 " <name>ietf-yang-types</name>"
623 " <revision>2013-07-15</revision>"
624 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
625 " </import-only-module>"
626 " </module-set>"
627 " <schema>"
628 " <name>test-schema</name>"
629 " <module-set>test-set</module-set>"
630 " </schema>"
631 " <datastore>"
632 " <name>ds:running</name>"
633 " <schema>test-schema</schema>"
634 " </datastore>"
635 " <datastore>"
636 " <name>ds:operational</name>"
637 " <schema>test-schema</schema>"
638 " </datastore>"
639 " <content-id>1</content-id>"
640 "</yang-library>"
641 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
642 " <module-set-id>1</module-set-id>"
643 "</modules-state>"
644 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
645 " <mount-point>"
646 " <module>sm</module>"
647 " <label>root</label>"
648 " <inline/>"
649 " </mount-point>"
650 "</schema-mounts>");
651 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
652 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
Michal Vasko27653162022-11-21 13:58:44 +0100653 assert_ptr_not_equal(ext_ctx, LYD_CTX(lyd_child(data)));
654 ext_ctx = LYD_CTX(lyd_child(data));
Michal Vaskoddd76592022-01-17 13:34:48 +0100655 lyd_free_siblings(data);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100656
657 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
658 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
Michal Vasko27653162022-11-21 13:58:44 +0100659 assert_ptr_equal(ext_ctx, LYD_CTX(lyd_child(data)));
Michal Vasko9883a3e2022-03-31 12:16:00 +0200660
661 assert_int_equal(LY_SUCCESS, lyd_print_mem(&lyb, data, LYD_LYB, 0));
662 lyd_free_siblings(data);
663
664 CHECK_PARSE_LYD_PARAM(lyb, LYD_LYB, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
Michal Vasko27653162022-11-21 13:58:44 +0100665 assert_ptr_equal(ext_ctx, LYD_CTX(lyd_child(data)));
Michal Vasko9883a3e2022-03-31 12:16:00 +0200666 free(lyb);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100667 lyd_free_siblings(data);
Michal Vaskoddd76592022-01-17 13:34:48 +0100668}
669
670static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100671test_parse_shared(void **state)
Michal Vaskoddd76592022-01-17 13:34:48 +0100672{
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100673 const char *xml, *json;
Michal Vasko9883a3e2022-03-31 12:16:00 +0200674 char *lyb;
Michal Vaskoddd76592022-01-17 13:34:48 +0100675 struct lyd_node *data;
676
677 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
678 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
679 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
680 " <module-set>"
681 " <name>test-set</name>"
682 " <module>"
683 " <name>ietf-datastores</name>"
684 " <revision>2018-02-14</revision>"
685 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
686 " </module>"
687 " <module>"
688 " <name>ietf-yang-library</name>"
689 " <revision>2019-01-04</revision>"
690 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
691 " </module>"
692 " <module>"
693 " <name>ietf-yang-schema-mount</name>"
694 " <revision>2019-01-14</revision>"
695 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
696 " </module>"
697 " <module>"
698 " <name>ietf-interfaces</name>"
699 " <revision>2014-05-08</revision>"
700 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
701 " </module>"
702 " <module>"
703 " <name>iana-if-type</name>"
704 " <revision>2014-05-08</revision>"
705 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
706 " </module>"
707 " <import-only-module>"
708 " <name>ietf-yang-types</name>"
709 " <revision>2013-07-15</revision>"
710 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
711 " </import-only-module>"
712 " </module-set>"
713 " <schema>"
714 " <name>test-schema</name>"
715 " <module-set>test-set</module-set>"
716 " </schema>"
717 " <datastore>"
718 " <name>ds:running</name>"
719 " <schema>test-schema</schema>"
720 " </datastore>"
721 " <datastore>"
722 " <name>ds:operational</name>"
723 " <schema>test-schema</schema>"
724 " </datastore>"
725 " <content-id>1</content-id>"
726 "</yang-library>"
727 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
728 " <module-set-id>1</module-set-id>"
729 "</modules-state>"
730 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
731 " <mount-point>"
732 " <module>sm</module>"
733 " <label>root</label>"
734 " <shared-schema/>"
735 " </mount-point>"
736 "</schema-mounts>");
737 xml =
738 "<root xmlns=\"urn:sm\">\n"
739 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
740 " <interface>\n"
741 " <name>bu</name>\n"
742 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
743 " </interface>\n"
744 " </interfaces>\n"
745 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
746 " <interface>\n"
747 " <name>bu</name>\n"
748 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
749 " <oper-status>not-present</oper-status>\n"
750 " <statistics>\n"
751 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
752 " </statistics>\n"
753 " </interface>\n"
754 " </interfaces-state>\n"
755 "</root>\n";
756 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
757 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
758 lyd_free_siblings(data);
759
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100760 json =
761 "{\n"
762 " \"sm:root\": {\n"
763 " \"ietf-interfaces:interfaces\": {\n"
764 " \"interface\": [\n"
765 " {\n"
766 " \"name\": \"bu\",\n"
767 " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
768 " }\n"
769 " ]\n"
770 " },\n"
771 " \"ietf-interfaces:interfaces-state\": {\n"
772 " \"interface\": [\n"
773 " {\n"
774 " \"name\": \"bu\",\n"
775 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
776 " \"oper-status\": \"not-present\",\n"
777 " \"statistics\": {\n"
778 " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n"
779 " }\n"
780 " }\n"
781 " ]\n"
782 " }\n"
783 " }\n"
784 "}\n";
785 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
786 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
787 lyd_free_siblings(data);
788
Michal Vaskoddd76592022-01-17 13:34:48 +0100789 /* different yang-lib data */
790 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
791 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
792 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
793 " <module-set>"
794 " <name>test-set</name>"
795 " <module>"
796 " <name>ietf-datastores</name>"
797 " <revision>2018-02-14</revision>"
798 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
799 " </module>"
800 " <module>"
801 " <name>ietf-yang-library</name>"
802 " <revision>2019-01-04</revision>"
803 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
804 " </module>"
805 " <module>"
806 " <name>ietf-yang-schema-mount</name>"
807 " <revision>2019-01-14</revision>"
808 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
809 " </module>"
810 " <module>"
811 " <name>ietf-interfaces</name>"
812 " <revision>2014-05-08</revision>"
813 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
814 " </module>"
815 " <module>"
816 " <name>ietf-ip</name>"
817 " <revision>2014-06-16</revision>"
818 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
819 " </module>"
820 " <module>"
821 " <name>iana-if-type</name>"
822 " <revision>2014-05-08</revision>"
823 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
824 " </module>"
825 " <import-only-module>"
826 " <name>ietf-yang-types</name>"
827 " <revision>2013-07-15</revision>"
828 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
829 " </import-only-module>"
830 " </module-set>"
831 " <schema>"
832 " <name>test-schema</name>"
833 " <module-set>test-set</module-set>"
834 " </schema>"
835 " <datastore>"
836 " <name>ds:running</name>"
837 " <schema>test-schema</schema>"
838 " </datastore>"
839 " <datastore>"
840 " <name>ds:operational</name>"
841 " <schema>test-schema</schema>"
842 " </datastore>"
843 " <content-id>2</content-id>"
844 "</yang-library>"
845 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
846 " <module-set-id>1</module-set-id>"
847 "</modules-state>"
848 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
849 " <mount-point>"
850 " <module>sm</module>"
851 " <label>root</label>"
852 " <shared-schema/>"
853 " </mount-point>"
854 "</schema-mounts>");
855 xml =
856 "<root2 xmlns=\"urn:sm\">\n"
857 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
858 " <interface>\n"
859 " <name>bu</name>\n"
860 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
861 " </interface>\n"
862 " </interfaces>\n"
863 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
864 " <interface>\n"
865 " <name>bu</name>\n"
866 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
867 " <oper-status>not-present</oper-status>\n"
868 " <statistics>\n"
869 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
870 " </statistics>\n"
871 " </interface>\n"
872 " </interfaces-state>\n"
873 "</root2>\n";
874 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vasko193dacd2022-10-13 08:43:05 +0200875 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vaskoddd76592022-01-17 13:34:48 +0100876 "Shared-schema yang-library content-id \"2\" differs from \"1\" used previously.",
877 "/ietf-yang-library:yang-library/content-id");
878
879 /* data for 2 mount points */
880 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
881 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
882 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
883 " <module-set>"
884 " <name>test-set</name>"
885 " <module>"
886 " <name>ietf-datastores</name>"
887 " <revision>2018-02-14</revision>"
888 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
889 " </module>"
890 " <module>"
891 " <name>ietf-yang-library</name>"
892 " <revision>2019-01-04</revision>"
893 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
894 " </module>"
895 " <module>"
896 " <name>ietf-yang-schema-mount</name>"
897 " <revision>2019-01-14</revision>"
898 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
899 " </module>"
900 " <module>"
901 " <name>ietf-interfaces</name>"
902 " <revision>2014-05-08</revision>"
903 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
904 " </module>"
905 " <module>"
906 " <name>iana-if-type</name>"
907 " <revision>2014-05-08</revision>"
908 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
909 " </module>"
910 " <import-only-module>"
911 " <name>ietf-yang-types</name>"
912 " <revision>2013-07-15</revision>"
913 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
914 " </import-only-module>"
915 " </module-set>"
916 " <schema>"
917 " <name>test-schema</name>"
918 " <module-set>test-set</module-set>"
919 " </schema>"
920 " <datastore>"
921 " <name>ds:running</name>"
922 " <schema>test-schema</schema>"
923 " </datastore>"
924 " <datastore>"
925 " <name>ds:operational</name>"
926 " <schema>test-schema</schema>"
927 " </datastore>"
928 " <content-id>1</content-id>"
929 "</yang-library>"
930 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
931 " <module-set-id>1</module-set-id>"
932 "</modules-state>"
933 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
934 " <mount-point>"
935 " <module>sm</module>"
936 " <label>root</label>"
937 " <shared-schema/>"
938 " </mount-point>"
939 "</schema-mounts>");
940 xml =
941 "<root xmlns=\"urn:sm\">\n"
942 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
943 " <interface>\n"
944 " <name>bu</name>\n"
945 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
946 " </interface>\n"
947 " </interfaces>\n"
948 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
949 " <interface>\n"
950 " <name>bu</name>\n"
951 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
952 " <oper-status>not-present</oper-status>\n"
953 " <statistics>\n"
954 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
955 " </statistics>\n"
956 " </interface>\n"
957 " </interfaces-state>\n"
958 "</root>\n"
959 "<root2 xmlns=\"urn:sm\">\n"
960 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
961 " <interface>\n"
962 " <name>fu</name>\n"
963 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:fddi</type>\n"
964 " </interface>\n"
965 " </interfaces>\n"
966 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
967 " <interface>\n"
968 " <name>fu</name>\n"
969 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:fddi</type>\n"
970 " <oper-status>down</oper-status>\n"
971 " <statistics>\n"
972 " <discontinuity-time>2020-01-01T10:00:00-00:00</discontinuity-time>\n"
973 " </statistics>\n"
974 " </interface>\n"
975 " </interfaces-state>\n"
976 "</root2>\n";
977 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
978 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
979 lyd_free_siblings(data);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100980
981 json =
982 "{\n"
983 " \"sm:root\": {\n"
984 " \"ietf-interfaces:interfaces\": {\n"
985 " \"interface\": [\n"
986 " {\n"
987 " \"name\": \"bu\",\n"
988 " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
989 " }\n"
990 " ]\n"
991 " },\n"
992 " \"ietf-interfaces:interfaces-state\": {\n"
993 " \"interface\": [\n"
994 " {\n"
995 " \"name\": \"bu\",\n"
996 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
997 " \"oper-status\": \"not-present\",\n"
998 " \"statistics\": {\n"
999 " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n"
1000 " }\n"
1001 " }\n"
1002 " ]\n"
1003 " }\n"
1004 " },\n"
1005 " \"sm:root2\": {\n"
1006 " \"ietf-interfaces:interfaces\": {\n"
1007 " \"interface\": [\n"
1008 " {\n"
1009 " \"name\": \"fu\",\n"
1010 " \"type\": \"iana-if-type:fddi\"\n"
1011 " }\n"
1012 " ]\n"
1013 " },\n"
1014 " \"ietf-interfaces:interfaces-state\": {\n"
1015 " \"interface\": [\n"
1016 " {\n"
1017 " \"name\": \"fu\",\n"
1018 " \"type\": \"iana-if-type:fddi\",\n"
1019 " \"oper-status\": \"down\",\n"
1020 " \"statistics\": {\n"
1021 " \"discontinuity-time\": \"2020-01-01T10:00:00-00:00\"\n"
1022 " }\n"
1023 " }\n"
1024 " ]\n"
1025 " }\n"
1026 " }\n"
1027 "}\n";
1028 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1029 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
Michal Vasko9883a3e2022-03-31 12:16:00 +02001030
1031 assert_int_equal(LY_SUCCESS, lyd_print_mem(&lyb, data, LYD_LYB, LYD_PRINT_WITHSIBLINGS));
1032 lyd_free_siblings(data);
1033
1034 CHECK_PARSE_LYD_PARAM(lyb, LYD_LYB, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1035 free(lyb);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001036 lyd_free_siblings(data);
Michal Vaskoddd76592022-01-17 13:34:48 +01001037}
1038
1039static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001040test_parse_shared_parent_ref(void **state)
Michal Vaskoddd76592022-01-17 13:34:48 +01001041{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001042 const char *xml, *json;
Michal Vaskoddd76592022-01-17 13:34:48 +01001043 struct lyd_node *data;
1044
1045 /* wrong leafref value */
1046 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
1047 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1048 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1049 " <module-set>"
1050 " <name>test-set</name>"
1051 " <module>"
1052 " <name>ietf-datastores</name>"
1053 " <revision>2018-02-14</revision>"
1054 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1055 " </module>"
1056 " <module>"
1057 " <name>ietf-yang-library</name>"
1058 " <revision>2019-01-04</revision>"
1059 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1060 " </module>"
1061 " <module>"
1062 " <name>ietf-yang-schema-mount</name>"
1063 " <revision>2019-01-14</revision>"
1064 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1065 " </module>"
1066 " <module>"
1067 " <name>sm</name>"
1068 " <namespace>urn:sm</namespace>"
1069 " </module>"
1070 " <module>"
1071 " <name>ietf-interfaces</name>"
1072 " <revision>2014-05-08</revision>"
1073 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
1074 " </module>"
1075 " <module>"
1076 " <name>iana-if-type</name>"
1077 " <revision>2014-05-08</revision>"
1078 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
1079 " </module>"
1080 " <import-only-module>"
1081 " <name>ietf-yang-types</name>"
1082 " <revision>2013-07-15</revision>"
1083 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
1084 " </import-only-module>"
1085 " </module-set>"
1086 " <schema>"
1087 " <name>test-schema</name>"
1088 " <module-set>test-set</module-set>"
1089 " </schema>"
1090 " <datastore>"
1091 " <name>ds:running</name>"
1092 " <schema>test-schema</schema>"
1093 " </datastore>"
1094 " <datastore>"
1095 " <name>ds:operational</name>"
1096 " <schema>test-schema</schema>"
1097 " </datastore>"
1098 " <content-id>1</content-id>"
1099 "</yang-library>"
1100 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1101 " <module-set-id>1</module-set-id>"
1102 "</modules-state>"
1103 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1104 " <namespace>"
1105 " <prefix>smp</prefix>"
1106 " <uri>urn:sm</uri>"
1107 " </namespace>"
1108 " <mount-point>"
1109 " <module>sm</module>"
1110 " <label>mnt-root</label>"
1111 " <shared-schema>"
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001112 " <parent-reference>/smp:target[. = current()/smp:name]</parent-reference>"
Michal Vaskoddd76592022-01-17 13:34:48 +01001113 " </shared-schema>"
1114 " </mount-point>"
1115 "</schema-mounts>");
1116 xml =
1117 "<root3 xmlns=\"urn:sm\">\n"
1118 " <ls>\n"
1119 " <name>target-value</name>\n"
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001120 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1121 " <interface>\n"
1122 " <name>bu</name>\n"
1123 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1124 " <sm-name xmlns=\"urn:sm\">target-value</sm-name>\n"
1125 " </interface>\n"
1126 " </interfaces>\n"
Michal Vaskoddd76592022-01-17 13:34:48 +01001127 " </ls>\n"
1128 "</root3>\n"
1129 "<target xmlns=\"urn:sm\">wrong-target-value</target>\n";
1130 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vasko193dacd2022-10-13 08:43:05 +02001131 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vasko5edfefd2022-08-05 10:07:11 +02001132 "Invalid leafref value \"target-value\" - no target instance \"/sm:target\" with the same value.",
Michal Vaskodbf3e652022-10-21 08:46:25 +02001133 "Data location \"/ietf-interfaces:interfaces/interface[name='bu']/sm:sm-name\".");
Michal Vaskoddd76592022-01-17 13:34:48 +01001134
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001135 json =
1136 "{\n"
1137 " \"sm:root3\": {\n"
1138 " \"ls\": ["
1139 " {\n"
1140 " \"name\": \"target-value\",\n"
1141 " \"ietf-interfaces:interfaces\": {\n"
1142 " \"interface\": [\n"
1143 " {\n"
1144 " \"name\": \"bu\",\n"
1145 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
1146 " \"sm:sm-name\": \"target-value\"\n"
1147 " }\n"
1148 " ]\n"
1149 " }\n"
1150 " }\n"
1151 " ]\n"
1152 " },\n"
1153 " \"sm:target\": \"wrong-target-value\"\n"
1154 "}\n";
1155 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
Michal Vasko193dacd2022-10-13 08:43:05 +02001156 CHECK_LOG_CTX("Ext plugin \"ly2 schema mount v1\": "
Michal Vasko5edfefd2022-08-05 10:07:11 +02001157 "Invalid leafref value \"target-value\" - no target instance \"/sm:target\" with the same value.",
Michal Vaskodbf3e652022-10-21 08:46:25 +02001158 "Data location \"/ietf-interfaces:interfaces/interface[name='bu']/sm:sm-name\", line number 18.");
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001159
Michal Vaskoddd76592022-01-17 13:34:48 +01001160 /* success */
1161 xml =
1162 "<root3 xmlns=\"urn:sm\">\n"
1163 " <ls>\n"
1164 " <name>target-value</name>\n"
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001165 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1166 " <interface>\n"
1167 " <name>bu</name>\n"
1168 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1169 " <sm-name xmlns=\"urn:sm\">target-value</sm-name>\n"
1170 " </interface>\n"
1171 " </interfaces>\n"
Michal Vaskoddd76592022-01-17 13:34:48 +01001172 " </ls>\n"
1173 "</root3>\n"
1174 "<target xmlns=\"urn:sm\">target-value</target>\n";
1175 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1176 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1177 lyd_free_siblings(data);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001178
1179 json =
1180 "{\n"
1181 " \"sm:root3\": {\n"
1182 " \"ls\": [\n"
1183 " {\n"
1184 " \"name\": \"target-value\",\n"
1185 " \"ietf-interfaces:interfaces\": {\n"
1186 " \"interface\": [\n"
1187 " {\n"
1188 " \"name\": \"bu\",\n"
1189 " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
1190 " \"sm:sm-name\": \"target-value\"\n"
1191 " }\n"
1192 " ]\n"
1193 " }\n"
1194 " }\n"
1195 " ]\n"
1196 " },\n"
1197 " \"sm:target\": \"target-value\"\n"
1198 "}\n";
1199 CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1200 CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
1201 lyd_free_siblings(data);
Michal Vaskoddd76592022-01-17 13:34:48 +01001202}
1203
1204static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001205test_parse_config(void **state)
Michal Vaskoddd76592022-01-17 13:34:48 +01001206{
1207 const char *xml;
Michal Vasko24edeb92022-07-20 08:08:46 +02001208 char *lyb;
Michal Vaskoddd76592022-01-17 13:34:48 +01001209 struct lyd_node *data;
1210 const struct lyd_node *node;
1211
1212 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
1213 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1214 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1215 " <module-set>"
1216 " <name>test-set</name>"
1217 " <module>"
1218 " <name>ietf-datastores</name>"
1219 " <revision>2018-02-14</revision>"
1220 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1221 " </module>"
1222 " <module>"
1223 " <name>ietf-yang-library</name>"
1224 " <revision>2019-01-04</revision>"
1225 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1226 " </module>"
1227 " <module>"
1228 " <name>ietf-yang-schema-mount</name>"
1229 " <revision>2019-01-14</revision>"
1230 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1231 " </module>"
1232 " <module>"
1233 " <name>ietf-interfaces</name>"
1234 " <revision>2014-05-08</revision>"
1235 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
1236 " </module>"
1237 " <module>"
1238 " <name>iana-if-type</name>"
1239 " <revision>2014-05-08</revision>"
1240 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
1241 " </module>"
1242 " <import-only-module>"
1243 " <name>ietf-yang-types</name>"
1244 " <revision>2013-07-15</revision>"
1245 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
1246 " </import-only-module>"
1247 " </module-set>"
1248 " <schema>"
1249 " <name>test-schema</name>"
1250 " <module-set>test-set</module-set>"
1251 " </schema>"
1252 " <datastore>"
1253 " <name>ds:running</name>"
1254 " <schema>test-schema</schema>"
1255 " </datastore>"
1256 " <datastore>"
1257 " <name>ds:operational</name>"
1258 " <schema>test-schema</schema>"
1259 " </datastore>"
1260 " <content-id>1</content-id>"
1261 "</yang-library>"
1262 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1263 " <module-set-id>1</module-set-id>"
1264 "</modules-state>"
1265 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1266 " <mount-point>"
1267 " <module>sm</module>"
1268 " <label>root</label>"
1269 " <config>false</config>"
1270 " <inline/>"
1271 " </mount-point>"
1272 "</schema-mounts>");
1273 xml =
1274 "<root xmlns=\"urn:sm\">\n"
1275 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1276 " <interface>\n"
1277 " <name>bu</name>\n"
1278 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1279 " <enabled>true</enabled>\n"
1280 " </interface>\n"
1281 " </interfaces>\n"
1282 "</root>\n";
1283 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1284 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1285
1286 node = lyd_child(data);
1287 assert_string_equal(LYD_NAME(node), "interfaces");
1288 assert_true(node->schema->flags & LYS_CONFIG_R);
1289 node = lyd_child(node);
1290 assert_string_equal(LYD_NAME(node), "interface");
1291 assert_true(node->schema->flags & LYS_CONFIG_R);
1292 node = lyd_child(node);
1293 assert_string_equal(LYD_NAME(node), "name");
1294 assert_true(node->schema->flags & LYS_CONFIG_R);
1295 node = node->next;
1296 assert_string_equal(LYD_NAME(node), "type");
1297 assert_true(node->schema->flags & LYS_CONFIG_R);
1298
Michal Vasko24edeb92022-07-20 08:08:46 +02001299 lyd_print_mem(&lyb, data, LYD_LYB, 0);
1300 lyd_free_siblings(data);
1301 CHECK_PARSE_LYD_PARAM(lyb, LYD_LYB, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1302 free(lyb);
1303
1304 node = lyd_child(data);
1305 assert_string_equal(LYD_NAME(node), "interfaces");
1306 assert_true(node->schema->flags & LYS_CONFIG_R);
1307 node = lyd_child(node);
1308 assert_string_equal(LYD_NAME(node), "interface");
1309 assert_true(node->schema->flags & LYS_CONFIG_R);
1310 node = lyd_child(node);
1311 assert_string_equal(LYD_NAME(node), "name");
1312 assert_true(node->schema->flags & LYS_CONFIG_R);
1313 node = node->next;
1314 assert_string_equal(LYD_NAME(node), "type");
1315 assert_true(node->schema->flags & LYS_CONFIG_R);
1316
Michal Vaskoddd76592022-01-17 13:34:48 +01001317 lyd_free_siblings(data);
Michal Vasko9e12ffe2022-09-21 15:11:30 +02001318
1319 /* the same effect but use a config false mount point instead of the separate metadata node */
1320 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
1321 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1322 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1323 " <module-set>"
1324 " <name>test-set</name>"
1325 " <module>"
1326 " <name>ietf-datastores</name>"
1327 " <revision>2018-02-14</revision>"
1328 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1329 " </module>"
1330 " <module>"
1331 " <name>ietf-yang-library</name>"
1332 " <revision>2019-01-04</revision>"
1333 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1334 " </module>"
1335 " <module>"
1336 " <name>ietf-yang-schema-mount</name>"
1337 " <revision>2019-01-14</revision>"
1338 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1339 " </module>"
1340 " <module>"
1341 " <name>ietf-interfaces</name>"
1342 " <revision>2014-05-08</revision>"
1343 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
1344 " </module>"
1345 " <module>"
1346 " <name>iana-if-type</name>"
1347 " <revision>2014-05-08</revision>"
1348 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
1349 " </module>"
1350 " <import-only-module>"
1351 " <name>ietf-yang-types</name>"
1352 " <revision>2013-07-15</revision>"
1353 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
1354 " </import-only-module>"
1355 " </module-set>"
1356 " <schema>"
1357 " <name>test-schema</name>"
1358 " <module-set>test-set</module-set>"
1359 " </schema>"
1360 " <datastore>"
1361 " <name>ds:running</name>"
1362 " <schema>test-schema</schema>"
1363 " </datastore>"
1364 " <datastore>"
1365 " <name>ds:operational</name>"
1366 " <schema>test-schema</schema>"
1367 " </datastore>"
1368 " <content-id>1</content-id>"
1369 "</yang-library>"
1370 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1371 " <module-set-id>1</module-set-id>"
1372 "</modules-state>"
1373 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1374 " <mount-point>"
1375 " <module>sm</module>"
1376 " <label>root</label>"
1377 " <inline/>"
1378 " </mount-point>"
1379 "</schema-mounts>");
1380 xml =
1381 "<root4 xmlns=\"urn:sm\">\n"
1382 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1383 " <interface>\n"
1384 " <name>bu</name>\n"
1385 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1386 " <enabled>true</enabled>\n"
1387 " </interface>\n"
1388 " </interfaces>\n"
1389 "</root4>\n";
1390 CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
1391 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1392
1393 node = lyd_child(data->next->next->next);
1394 assert_string_equal(LYD_NAME(node), "interfaces");
1395 assert_true(node->schema->flags & LYS_CONFIG_R);
1396 node = lyd_child(node);
1397 assert_string_equal(LYD_NAME(node), "interface");
1398 assert_true(node->schema->flags & LYS_CONFIG_R);
1399 node = lyd_child(node);
1400 assert_string_equal(LYD_NAME(node), "name");
1401 assert_true(node->schema->flags & LYS_CONFIG_R);
1402 node = node->next;
1403 assert_string_equal(LYD_NAME(node), "type");
1404 assert_true(node->schema->flags & LYS_CONFIG_R);
1405
1406 lyd_free_siblings(data);
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +01001407}
1408
Michal Vasko8cc3f662022-03-29 11:25:51 +02001409static void
1410test_new(void **state)
1411{
1412 const char *xml;
1413 const struct lys_module *mod;
1414 struct lyd_node *data, *node;
1415
1416 ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
1417 "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1418 " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1419 " <module-set>"
1420 " <name>test-set</name>"
1421 " <module>"
1422 " <name>ietf-datastores</name>"
1423 " <revision>2018-02-14</revision>"
1424 " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1425 " </module>"
1426 " <module>"
1427 " <name>ietf-yang-library</name>"
1428 " <revision>2019-01-04</revision>"
1429 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1430 " </module>"
1431 " <module>"
1432 " <name>ietf-yang-schema-mount</name>"
1433 " <revision>2019-01-14</revision>"
1434 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1435 " </module>"
1436 " <module>"
1437 " <name>ietf-interfaces</name>"
1438 " <revision>2014-05-08</revision>"
1439 " <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namespace>"
1440 " </module>"
1441 " <module>"
1442 " <name>iana-if-type</name>"
1443 " <revision>2014-05-08</revision>"
1444 " <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>"
1445 " </module>"
Michal Vasko35b29622022-07-22 14:12:56 +02001446 " <module>"
1447 " <name>ietf-ip</name>"
1448 " <revision>2014-06-16</revision>"
1449 " <namespace>urn:ietf:params:xml:ns:yang:ietf-ip</namespace>"
1450 " </module>"
Michal Vasko8cc3f662022-03-29 11:25:51 +02001451 " <import-only-module>"
1452 " <name>ietf-yang-types</name>"
1453 " <revision>2013-07-15</revision>"
1454 " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>"
1455 " </import-only-module>"
1456 " </module-set>"
1457 " <schema>"
1458 " <name>test-schema</name>"
1459 " <module-set>test-set</module-set>"
1460 " </schema>"
1461 " <datastore>"
1462 " <name>ds:running</name>"
1463 " <schema>test-schema</schema>"
1464 " </datastore>"
1465 " <datastore>"
1466 " <name>ds:operational</name>"
1467 " <schema>test-schema</schema>"
1468 " </datastore>"
1469 " <content-id>1</content-id>"
1470 "</yang-library>"
1471 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1472 " <module-set-id>1</module-set-id>"
1473 "</modules-state>"
1474 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1475 " <mount-point>"
1476 " <module>sm</module>"
1477 " <label>root</label>"
1478 " <shared-schema/>"
1479 " </mount-point>"
1480 "</schema-mounts>");
1481 xml =
1482 "<root xmlns=\"urn:sm\">\n"
1483 " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1484 " <interface>\n"
1485 " <name>bu</name>\n"
1486 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
Michal Vasko35b29622022-07-22 14:12:56 +02001487 " <ipv4 xmlns=\"urn:ietf:params:xml:ns:yang:ietf-ip\">\n"
1488 " <enabled>false</enabled>\n"
1489 " </ipv4>\n"
Michal Vasko8cc3f662022-03-29 11:25:51 +02001490 " </interface>\n"
1491 " </interfaces>\n"
1492 " <interfaces-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
1493 " <interface>\n"
1494 " <name>bu</name>\n"
1495 " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
1496 " <oper-status>not-present</oper-status>\n"
1497 " <statistics>\n"
1498 " <discontinuity-time>2022-01-01T10:00:00-00:00</discontinuity-time>\n"
1499 " </statistics>\n"
1500 " </interface>\n"
1501 " </interfaces-state>\n"
1502 "</root>\n";
1503
1504 /* create the data manually with simple new functions */
1505 mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "sm");
1506 assert_non_null(mod);
1507 assert_int_equal(LY_SUCCESS, lyd_new_inner(NULL, mod, "root", 0, &data));
1508
1509 mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "ietf-interfaces");
1510 assert_non_null(mod);
1511 assert_int_equal(LY_SUCCESS, lyd_new_inner(data, mod, "interfaces", 0, &node));
1512 assert_int_equal(LY_SUCCESS, lyd_new_list(node, NULL, "interface", 0, &node, "bu"));
1513 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "type", "iana-if-type:ethernetCsmacd", 0, NULL));
Michal Vasko35b29622022-07-22 14:12:56 +02001514 mod = ly_ctx_get_module_implemented(LYD_CTX(node), "ietf-ip");
1515 assert_non_null(mod);
1516 assert_int_equal(LY_SUCCESS, lyd_new_inner(node, mod, "ipv4", 0, &node));
1517 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "enabled", "false", 0, NULL));
Michal Vasko8cc3f662022-03-29 11:25:51 +02001518
Michal Vasko35b29622022-07-22 14:12:56 +02001519 mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "ietf-interfaces");
1520 assert_non_null(mod);
Michal Vasko8cc3f662022-03-29 11:25:51 +02001521 assert_int_equal(LY_SUCCESS, lyd_new_inner(data, mod, "interfaces-state", 0, &node));
1522 assert_int_equal(LY_SUCCESS, lyd_new_list(node, NULL, "interface", 0, &node, "bu"));
1523 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "type", "iana-if-type:ethernetCsmacd", 0, NULL));
1524 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "oper-status", "not-present", 0, NULL));
1525 assert_int_equal(LY_SUCCESS, lyd_new_inner(node, NULL, "statistics", 0, &node));
1526 assert_int_equal(LY_SUCCESS, lyd_new_term(node, NULL, "discontinuity-time", "2022-01-01T10:00:00-00:00", 0, NULL));
1527
1528 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1529 lyd_free_siblings(data);
1530
1531 /* create the data using lyd_new_path */
1532 assert_int_equal(LY_SUCCESS, lyd_new_path(NULL, UTEST_LYCTX,
1533 "/sm:root/ietf-interfaces:interfaces/interface[name='bu']/type", "iana-if-type:ethernetCsmacd", 0, &data));
1534 assert_int_equal(LY_SUCCESS, lyd_new_path(data, NULL,
Michal Vasko35b29622022-07-22 14:12:56 +02001535 "/sm:root/ietf-interfaces:interfaces/interface[name='bu']/ietf-ip:ipv4/enabled", "false", 0, NULL));
1536 assert_int_equal(LY_SUCCESS, lyd_new_path(data, NULL,
Michal Vasko8cc3f662022-03-29 11:25:51 +02001537 "/sm:root/ietf-interfaces:interfaces-state/interface[name='bu']/type", "iana-if-type:ethernetCsmacd", 0, NULL));
1538 assert_int_equal(LY_SUCCESS, lyd_new_path(data, NULL,
1539 "/sm:root/ietf-interfaces:interfaces-state/interface[name='bu']/oper-status", "not-present", 0, NULL));
1540 assert_int_equal(LY_SUCCESS, lyd_new_path(data, NULL,
1541 "/sm:root/ietf-interfaces:interfaces-state/interface[name='bu']/statistics/discontinuity-time",
1542 "2022-01-01T10:00:00-00:00", 0, NULL));
1543
1544 CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
1545 lyd_free_siblings(data);
1546}
1547
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +01001548int
1549main(void)
1550{
1551 const struct CMUnitTest tests[] = {
Michal Vaskoddd76592022-01-17 13:34:48 +01001552 UTEST(test_schema),
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001553 UTEST(test_parse_invalid, setup),
1554 UTEST(test_parse_inline, setup),
1555 UTEST(test_parse_shared, setup),
1556 UTEST(test_parse_shared_parent_ref, setup),
1557 UTEST(test_parse_config, setup),
Michal Vasko8cc3f662022-03-29 11:25:51 +02001558 UTEST(test_new, setup),
tadeas-vintrlik2aa36b42021-11-03 13:07:34 +01001559 };
1560
1561 return cmocka_run_group_tests(tests, NULL, NULL);
1562}