blob: 52d59ec8c82fc0efde1894995dc69441fc241078 [file] [log] [blame]
Michal Vaskob1b5c262020-03-05 14:29:47 +01001/**
2 * @file test_validation.c
Michal Vaskocde73ac2019-11-14 16:10:27 +01003 * @author: Radek Krejci <rkrejci@cesnet.cz>
Michal Vaskob1b5c262020-03-05 14:29:47 +01004 * @brief unit tests for functions from validation.c
Michal Vaskocde73ac2019-11-14 16:10:27 +01005 *
Michal Vaskob1b5c262020-03-05 14:29:47 +01006 * Copyright (c) 2020 CESNET, z.s.p.o.
Michal Vaskocde73ac2019-11-14 16:10:27 +01007 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
Michal Vasko52927e22020-03-16 17:26:14 +010015#include "tests/config.h"
16
Michal Vaskocde73ac2019-11-14 16:10:27 +010017#include <stdarg.h>
18#include <stddef.h>
19#include <setjmp.h>
20#include <cmocka.h>
21
22#include <stdio.h>
23#include <string.h>
24
25#include "../../src/context.h"
26#include "../../src/tree_data_internal.h"
Michal Vaskof03ed032020-03-04 13:31:44 +010027#include "../../src/printer_data.h"
Michal Vaskocde73ac2019-11-14 16:10:27 +010028
29#define BUFSIZE 1024
30char logbuf[BUFSIZE] = {0};
31int store = -1; /* negative for infinite logging, positive for limited logging */
32
33struct ly_ctx *ctx; /* context for tests */
34
35/* set to 0 to printing error messages to stderr instead of checking them in code */
36#define ENABLE_LOGGER_CHECKING 1
37
38#if ENABLE_LOGGER_CHECKING
39static void
40logger(LY_LOG_LEVEL level, const char *msg, const char *path)
41{
42 (void) level; /* unused */
43 if (store) {
44 if (path && path[0]) {
45 snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
46 } else {
47 strncpy(logbuf, msg, BUFSIZE - 1);
48 }
49 if (store > 0) {
50 --store;
51 }
52 }
53}
54#endif
55
56static int
57setup(void **state)
58{
59 (void) state; /* unused */
60
61 const char *schema_a =
62 "module a {"
63 "namespace urn:tests:a;"
64 "prefix a;"
65 "yang-version 1.1;"
66
67 "container cont {"
68 "leaf a {"
69 "when \"../../c = 'val_c'\";"
70 "type string;"
71 "}"
72 "leaf b {"
73 "type string;"
74 "}"
75 "}"
76 "leaf c {"
77 "when \"/cont/b = 'val_b'\";"
78 "type string;"
79 "}"
80 "}";
Michal Vaskoa3881362020-01-21 15:57:35 +010081 const char *schema_b =
82 "module b {"
83 "namespace urn:tests:b;"
84 "prefix b;"
85 "yang-version 1.1;"
86
87 "choice choic {"
88 "mandatory true;"
89 "leaf a {"
90 "type string;"
91 "}"
92 "case b {"
93 "leaf l {"
94 "type string;"
95 "}"
96 "}"
97 "}"
98 "leaf c {"
99 "mandatory true;"
100 "type string;"
101 "}"
102 "leaf d {"
103 "type empty;"
104 "}"
105 "}";
Michal Vaskoacd83e72020-02-04 14:12:01 +0100106 const char *schema_c =
107 "module c {"
108 "namespace urn:tests:c;"
109 "prefix c;"
110 "yang-version 1.1;"
111
112 "choice choic {"
113 "leaf a {"
114 "type string;"
115 "}"
116 "case b {"
117 "leaf-list l {"
118 "min-elements 3;"
119 "type string;"
120 "}"
121 "}"
122 "}"
123 "list lt {"
124 "max-elements 4;"
125 "key \"k\";"
126 "leaf k {"
127 "type string;"
128 "}"
129 "}"
130 "leaf d {"
131 "type empty;"
132 "}"
133 "}";
Michal Vasko14654712020-02-06 08:35:21 +0100134 const char *schema_d =
135 "module d {"
136 "namespace urn:tests:d;"
137 "prefix d;"
138 "yang-version 1.1;"
139
140 "list lt {"
141 "key \"k\";"
142 "unique \"l1\";"
143 "leaf k {"
144 "type string;"
145 "}"
146 "leaf l1 {"
147 "type string;"
148 "}"
149 "}"
150 "list lt2 {"
151 "key \"k\";"
152 "unique \"cont/l2 l4\";"
153 "unique \"l5 l6\";"
154 "leaf k {"
155 "type string;"
156 "}"
157 "container cont {"
158 "leaf l2 {"
159 "type string;"
160 "}"
161 "}"
162 "leaf l4 {"
163 "type string;"
164 "}"
165 "leaf l5 {"
166 "type string;"
167 "}"
168 "leaf l6 {"
169 "type string;"
170 "}"
171 "list lt3 {"
172 "key \"kk\";"
173 "unique \"l3\";"
174 "leaf kk {"
175 "type string;"
176 "}"
177 "leaf l3 {"
178 "type string;"
179 "}"
180 "}"
181 "}"
182 "}";
Michal Vaskof03ed032020-03-04 13:31:44 +0100183 const char *schema_e =
184 "module e {"
185 "namespace urn:tests:e;"
186 "prefix e;"
187 "yang-version 1.1;"
188
189 "choice choic {"
190 "leaf a {"
191 "type string;"
192 "}"
193 "case b {"
194 "leaf-list l {"
195 "type string;"
196 "}"
197 "}"
198 "}"
199 "list lt {"
200 "key \"k\";"
201 "leaf k {"
202 "type string;"
203 "}"
204 "}"
205 "leaf d {"
206 "type uint32;"
207 "}"
208 "leaf-list ll {"
209 "type string;"
210 "}"
211 "container cont {"
212 "list lt {"
213 "key \"k\";"
214 "leaf k {"
215 "type string;"
216 "}"
217 "}"
218 "leaf d {"
219 "type uint32;"
220 "}"
221 "leaf-list ll {"
222 "type string;"
223 "}"
Michal Vasko9f96a052020-03-10 09:41:45 +0100224 "leaf-list ll2 {"
225 "type enumeration {"
226 "enum one;"
227 "enum two;"
228 "}"
229 "}"
Michal Vaskof03ed032020-03-04 13:31:44 +0100230 "}"
231 "}";
232 const char *schema_f =
233 "module f {"
234 "namespace urn:tests:f;"
235 "prefix f;"
236 "yang-version 1.1;"
237
238 "choice choic {"
239 "default \"c\";"
240 "leaf a {"
241 "type string;"
242 "}"
243 "case b {"
244 "leaf l {"
245 "type string;"
246 "}"
247 "}"
248 "case c {"
249 "leaf-list ll1 {"
250 "type string;"
251 "default \"def1\";"
252 "default \"def2\";"
253 "default \"def3\";"
254 "}"
255 "}"
256 "}"
257 "leaf d {"
258 "type uint32;"
259 "default 15;"
260 "}"
261 "leaf-list ll2 {"
262 "type string;"
263 "default \"dflt1\";"
264 "default \"dflt2\";"
265 "}"
266 "container cont {"
267 "choice choic {"
268 "default \"c\";"
269 "leaf a {"
270 "type string;"
271 "}"
272 "case b {"
273 "leaf l {"
274 "type string;"
275 "}"
276 "}"
277 "case c {"
278 "leaf-list ll1 {"
279 "type string;"
280 "default \"def1\";"
281 "default \"def2\";"
282 "default \"def3\";"
283 "}"
284 "}"
285 "}"
286 "leaf d {"
287 "type uint32;"
288 "default 15;"
289 "}"
290 "leaf-list ll2 {"
291 "type string;"
292 "default \"dflt1\";"
293 "default \"dflt2\";"
294 "}"
295 "}"
296 "}";
Michal Vaskoc193ce92020-03-06 11:04:48 +0100297 const char *schema_g =
298 "module g {"
299 "namespace urn:tests:g;"
300 "prefix g;"
301 "yang-version 1.1;"
302
303 "feature f1;"
304 "feature f2;"
305 "feature f3;"
306
307 "container cont {"
308 "if-feature \"f1\";"
309 "choice choic {"
310 "if-feature \"f2 or f3\";"
311 "leaf a {"
312 "type string;"
313 "}"
314 "case b {"
315 "if-feature \"f2 and f1\";"
316 "leaf l {"
317 "type string;"
318 "}"
319 "}"
320 "}"
321 "leaf d {"
322 "type uint32;"
323 "}"
324 "container cont2 {"
325 "if-feature \"f2\";"
326 "leaf e {"
327 "type string;"
328 "}"
329 "}"
330 "}"
331 "}";
Michal Vasko5b37a352020-03-06 13:38:33 +0100332 const char *schema_h =
333 "module h {"
334 "namespace urn:tests:h;"
335 "prefix h;"
336 "yang-version 1.1;"
337
338 "container cont {"
339 "container cont2 {"
340 "config false;"
341 "leaf l {"
342 "type string;"
343 "}"
344 "}"
345 "}"
346 "}";
Michal Vaskocc048b22020-03-27 15:52:38 +0100347 const char *schema_i =
348 "module i {"
349 "namespace urn:tests:i;"
350 "prefix i;"
351 "yang-version 1.1;"
352
353 "container cont {"
354 "leaf l {"
355 "type string;"
356 "}"
357 "leaf l2 {"
358 "must \"../l = 'right'\";"
359 "type string;"
360 "}"
361 "}"
362 "}";
Michal Vaskofea12c62020-03-30 11:00:15 +0200363 const char *schema_j =
364 "module j {"
365 "namespace urn:tests:j;"
366 "prefix j;"
367 "yang-version 1.1;"
368
369 "feature feat1;"
370
371 "container cont {"
372 "must \"false()\";"
373 "list l1 {"
374 "key \"k\";"
375 "leaf k {"
376 "type string;"
377 "}"
378 "action act {"
379 "if-feature feat1;"
380 "input {"
381 "must \"../../lf1 = 'true'\";"
382 "leaf lf2 {"
383 "type leafref {"
384 "path /lf3;"
385 "}"
386 "}"
387 "}"
Michal Vaskocb7526d2020-03-30 15:08:26 +0200388 "output {"
389 "must \"../../lf1 = 'true2'\";"
390 "leaf lf2 {"
391 "type leafref {"
392 "path /lf4;"
393 "}"
394 "}"
395 "}"
Michal Vaskofea12c62020-03-30 11:00:15 +0200396 "}"
397 "}"
398
399 "leaf lf1 {"
400 "type string;"
401 "}"
402 "}"
403
404 "leaf lf3 {"
405 "type string;"
406 "}"
Michal Vaskocb7526d2020-03-30 15:08:26 +0200407
408 "leaf lf4 {"
409 "type string;"
410 "}"
Michal Vaskofea12c62020-03-30 11:00:15 +0200411 "}";
Michal Vaskocde73ac2019-11-14 16:10:27 +0100412
413#if ENABLE_LOGGER_CHECKING
414 ly_set_log_clb(logger, 1);
415#endif
416
Michal Vaskof03ed032020-03-04 13:31:44 +0100417 assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &ctx));
418 assert_non_null(ly_ctx_load_module(ctx, "ietf-netconf-with-defaults", "2011-06-01"));
Michal Vaskocde73ac2019-11-14 16:10:27 +0100419 assert_non_null(lys_parse_mem(ctx, schema_a, LYS_IN_YANG));
Michal Vaskoa3881362020-01-21 15:57:35 +0100420 assert_non_null(lys_parse_mem(ctx, schema_b, LYS_IN_YANG));
Michal Vaskoacd83e72020-02-04 14:12:01 +0100421 assert_non_null(lys_parse_mem(ctx, schema_c, LYS_IN_YANG));
Michal Vasko14654712020-02-06 08:35:21 +0100422 assert_non_null(lys_parse_mem(ctx, schema_d, LYS_IN_YANG));
Michal Vaskof03ed032020-03-04 13:31:44 +0100423 assert_non_null(lys_parse_mem(ctx, schema_e, LYS_IN_YANG));
424 assert_non_null(lys_parse_mem(ctx, schema_f, LYS_IN_YANG));
Michal Vaskoc193ce92020-03-06 11:04:48 +0100425 assert_non_null(lys_parse_mem(ctx, schema_g, LYS_IN_YANG));
Michal Vasko5b37a352020-03-06 13:38:33 +0100426 assert_non_null(lys_parse_mem(ctx, schema_h, LYS_IN_YANG));
Michal Vaskocc048b22020-03-27 15:52:38 +0100427 assert_non_null(lys_parse_mem(ctx, schema_i, LYS_IN_YANG));
Michal Vaskofea12c62020-03-30 11:00:15 +0200428 assert_non_null(lys_parse_mem(ctx, schema_j, LYS_IN_YANG));
Michal Vaskocde73ac2019-11-14 16:10:27 +0100429
430 return 0;
431}
432
433static int
434teardown(void **state)
435{
Michal Vaskoacd83e72020-02-04 14:12:01 +0100436 (void)state;
437 ly_ctx_destroy(ctx, NULL);
438 ctx = NULL;
439
440 return 0;
441}
442
443static int
444teardown_s(void **state)
445{
Michal Vaskocde73ac2019-11-14 16:10:27 +0100446#if ENABLE_LOGGER_CHECKING
447 if (*state) {
448 fprintf(stderr, "%s\n", logbuf);
449 }
450#else
451 (void) state; /* unused */
452#endif
453
Michal Vaskocde73ac2019-11-14 16:10:27 +0100454 return 0;
455}
456
457void
458logbuf_clean(void)
459{
460 logbuf[0] = '\0';
461}
462
463#if ENABLE_LOGGER_CHECKING
464# define logbuf_assert(str) assert_string_equal(logbuf, str)
465#else
466# define logbuf_assert(str)
467#endif
468
469static void
470test_when(void **state)
471{
472 *state = test_when;
473
474 const char *data;
475 struct lyd_node *tree;
476
477 data = "<c xmlns=\"urn:tests:a\">hey</c>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100478 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskocde73ac2019-11-14 16:10:27 +0100479 assert_null(tree);
Michal Vasko9b368d32020-02-14 13:53:31 +0100480 logbuf_assert("When condition \"/cont/b = 'val_b'\" not satisfied. /a:c");
Michal Vaskocde73ac2019-11-14 16:10:27 +0100481
482 data = "<cont xmlns=\"urn:tests:a\"><b>val_b</b></cont><c xmlns=\"urn:tests:a\">hey</c>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100483 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskocde73ac2019-11-14 16:10:27 +0100484 assert_non_null(tree);
485 assert_string_equal("c", tree->next->schema->name);
486 assert_int_equal(LYD_WHEN_TRUE, tree->next->flags);
487 lyd_free_all(tree);
488
489 data = "<cont xmlns=\"urn:tests:a\"><a>val</a><b>val_b</b></cont><c xmlns=\"urn:tests:a\">val_c</c>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100490 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskocde73ac2019-11-14 16:10:27 +0100491 assert_non_null(tree);
492 assert_string_equal("a", lyd_node_children(tree)->schema->name);
493 assert_int_equal(LYD_WHEN_TRUE, lyd_node_children(tree)->flags);
494 assert_string_equal("c", tree->next->schema->name);
495 assert_int_equal(LYD_WHEN_TRUE, tree->next->flags);
496 lyd_free_all(tree);
497
498 *state = NULL;
499}
500
Michal Vaskoa3881362020-01-21 15:57:35 +0100501static void
502test_mandatory(void **state)
503{
504 *state = test_mandatory;
505
506 const char *data;
507 struct lyd_node *tree;
508
509 data = "<d xmlns=\"urn:tests:b\"/>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100510 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskoa3881362020-01-21 15:57:35 +0100511 assert_null(tree);
512 logbuf_assert("Mandatory node \"choic\" instance does not exist. /b:choic");
513
514 data = "<l xmlns=\"urn:tests:b\">string</l><d xmlns=\"urn:tests:b\"/>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100515 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskoa3881362020-01-21 15:57:35 +0100516 assert_null(tree);
517 logbuf_assert("Mandatory node \"c\" instance does not exist. /b:c");
518
519 data = "<a xmlns=\"urn:tests:b\">string</a>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100520 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskoa3881362020-01-21 15:57:35 +0100521 assert_null(tree);
522 logbuf_assert("Mandatory node \"c\" instance does not exist. /b:c");
523
524 data = "<a xmlns=\"urn:tests:b\">string</a><c xmlns=\"urn:tests:b\">string2</c>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100525 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskoa3881362020-01-21 15:57:35 +0100526 assert_non_null(tree);
Michal Vaskof03ed032020-03-04 13:31:44 +0100527 lyd_free_siblings(tree);
Michal Vaskoa3881362020-01-21 15:57:35 +0100528
529 *state = NULL;
530}
531
Michal Vaskoacd83e72020-02-04 14:12:01 +0100532static void
533test_minmax(void **state)
534{
535 *state = test_minmax;
536
537 const char *data;
538 struct lyd_node *tree;
539
540 data = "<d xmlns=\"urn:tests:c\"/>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100541 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskoacd83e72020-02-04 14:12:01 +0100542 assert_null(tree);
543 logbuf_assert("Too few \"l\" instances. /c:choic/b/l");
544
545 data =
546 "<l xmlns=\"urn:tests:c\">val1</l>"
547 "<l xmlns=\"urn:tests:c\">val2</l>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100548 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskoacd83e72020-02-04 14:12:01 +0100549 assert_null(tree);
550 logbuf_assert("Too few \"l\" instances. /c:choic/b/l");
551
552 data =
553 "<l xmlns=\"urn:tests:c\">val1</l>"
554 "<l xmlns=\"urn:tests:c\">val2</l>"
555 "<l xmlns=\"urn:tests:c\">val3</l>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100556 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskoacd83e72020-02-04 14:12:01 +0100557 assert_non_null(tree);
Michal Vaskof03ed032020-03-04 13:31:44 +0100558 lyd_free_siblings(tree);
Michal Vaskoacd83e72020-02-04 14:12:01 +0100559
560 data =
561 "<l xmlns=\"urn:tests:c\">val1</l>"
562 "<l xmlns=\"urn:tests:c\">val2</l>"
563 "<l xmlns=\"urn:tests:c\">val3</l>"
564 "<lt xmlns=\"urn:tests:c\"><k>val1</k></lt>"
565 "<lt xmlns=\"urn:tests:c\"><k>val2</k></lt>"
566 "<lt xmlns=\"urn:tests:c\"><k>val3</k></lt>"
567 "<lt xmlns=\"urn:tests:c\"><k>val4</k></lt>"
568 "<lt xmlns=\"urn:tests:c\"><k>val5</k></lt>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100569 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskoacd83e72020-02-04 14:12:01 +0100570 assert_null(tree);
571 logbuf_assert("Too many \"lt\" instances. /c:lt");
572
573 *state = NULL;
574}
575
Michal Vasko14654712020-02-06 08:35:21 +0100576static void
577test_unique(void **state)
578{
579 *state = test_unique;
580
581 const char *data;
582 struct lyd_node *tree;
583
584 data =
585 "<lt xmlns=\"urn:tests:d\">"
586 "<k>val1</k>"
587 "<l1>same</l1>"
588 "</lt>"
589 "<lt xmlns=\"urn:tests:d\">"
590 "<k>val2</k>"
591 "</lt>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100592 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vasko14654712020-02-06 08:35:21 +0100593 assert_non_null(tree);
Michal Vaskof03ed032020-03-04 13:31:44 +0100594 lyd_free_siblings(tree);
Michal Vasko14654712020-02-06 08:35:21 +0100595
596 data =
597 "<lt xmlns=\"urn:tests:d\">"
598 "<k>val1</k>"
599 "<l1>same</l1>"
600 "</lt>"
601 "<lt xmlns=\"urn:tests:d\">"
602 "<k>val2</k>"
603 "<l1>not-same</l1>"
604 "</lt>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100605 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vasko14654712020-02-06 08:35:21 +0100606 assert_non_null(tree);
Michal Vaskof03ed032020-03-04 13:31:44 +0100607 lyd_free_siblings(tree);
Michal Vasko14654712020-02-06 08:35:21 +0100608
609 data =
610 "<lt xmlns=\"urn:tests:d\">"
611 "<k>val1</k>"
612 "<l1>same</l1>"
613 "</lt>"
614 "<lt xmlns=\"urn:tests:d\">"
615 "<k>val2</k>"
616 "<l1>same</l1>"
617 "</lt>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100618 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vasko14654712020-02-06 08:35:21 +0100619 assert_null(tree);
Michal Vasko9b368d32020-02-14 13:53:31 +0100620 logbuf_assert("Unique data leaf(s) \"l1\" not satisfied in \"/d:lt[k='val1']\" and \"/d:lt[k='val2']\". /d:lt[k='val2']");
Michal Vasko14654712020-02-06 08:35:21 +0100621
622 /* now try with more instances */
623 data =
624 "<lt xmlns=\"urn:tests:d\">"
625 "<k>val1</k>"
626 "<l1>1</l1>"
627 "</lt>"
628 "<lt xmlns=\"urn:tests:d\">"
629 "<k>val2</k>"
630 "<l1>2</l1>"
631 "</lt>"
632 "<lt xmlns=\"urn:tests:d\">"
633 "<k>val3</k>"
634 "<l1>3</l1>"
635 "</lt>"
636 "<lt xmlns=\"urn:tests:d\">"
637 "<k>val4</k>"
638 "<l1>4</l1>"
639 "</lt>"
640 "<lt xmlns=\"urn:tests:d\">"
641 "<k>val5</k>"
642 "<l1>5</l1>"
643 "</lt>"
644 "<lt xmlns=\"urn:tests:d\">"
645 "<k>val6</k>"
646 "<l1>6</l1>"
647 "</lt>"
648 "<lt xmlns=\"urn:tests:d\">"
649 "<k>val7</k>"
650 "<l1>7</l1>"
651 "</lt>"
652 "<lt xmlns=\"urn:tests:d\">"
653 "<k>val8</k>"
654 "<l1>8</l1>"
655 "</lt>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100656 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vasko14654712020-02-06 08:35:21 +0100657 assert_non_null(tree);
Michal Vaskof03ed032020-03-04 13:31:44 +0100658 lyd_free_siblings(tree);
Michal Vasko14654712020-02-06 08:35:21 +0100659
660 data =
661 "<lt xmlns=\"urn:tests:d\">"
662 "<k>val1</k>"
663 "<l1>1</l1>"
664 "</lt>"
665 "<lt xmlns=\"urn:tests:d\">"
666 "<k>val2</k>"
667 "<l1>2</l1>"
668 "</lt>"
669 "<lt xmlns=\"urn:tests:d\">"
670 "<k>val3</k>"
671 "<l1>3</l1>"
672 "</lt>"
673 "<lt xmlns=\"urn:tests:d\">"
674 "<k>val4</k>"
675 "</lt>"
676 "<lt xmlns=\"urn:tests:d\">"
677 "<k>val5</k>"
678 "<l1>5</l1>"
679 "</lt>"
680 "<lt xmlns=\"urn:tests:d\">"
681 "<k>val6</k>"
682 "<l1>6</l1>"
683 "</lt>"
684 "<lt xmlns=\"urn:tests:d\">"
685 "<k>val7</k>"
686 "</lt>"
687 "<lt xmlns=\"urn:tests:d\">"
688 "<k>val8</k>"
689 "</lt>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100690 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vasko14654712020-02-06 08:35:21 +0100691 assert_non_null(tree);
Michal Vaskof03ed032020-03-04 13:31:44 +0100692 lyd_free_siblings(tree);
Michal Vasko14654712020-02-06 08:35:21 +0100693
694 data =
695 "<lt xmlns=\"urn:tests:d\">"
696 "<k>val1</k>"
697 "<l1>1</l1>"
698 "</lt>"
699 "<lt xmlns=\"urn:tests:d\">"
700 "<k>val2</k>"
701 "<l1>2</l1>"
702 "</lt>"
703 "<lt xmlns=\"urn:tests:d\">"
704 "<k>val3</k>"
705 "</lt>"
706 "<lt xmlns=\"urn:tests:d\">"
707 "<k>val4</k>"
708 "<l1>4</l1>"
709 "</lt>"
710 "<lt xmlns=\"urn:tests:d\">"
711 "<k>val5</k>"
712 "</lt>"
713 "<lt xmlns=\"urn:tests:d\">"
714 "<k>val6</k>"
715 "</lt>"
716 "<lt xmlns=\"urn:tests:d\">"
717 "<k>val7</k>"
718 "<l1>2</l1>"
719 "</lt>"
720 "<lt xmlns=\"urn:tests:d\">"
721 "<k>val8</k>"
722 "<l1>8</l1>"
723 "</lt>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100724 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vasko14654712020-02-06 08:35:21 +0100725 assert_null(tree);
Michal Vasko9b368d32020-02-14 13:53:31 +0100726 logbuf_assert("Unique data leaf(s) \"l1\" not satisfied in \"/d:lt[k='val7']\" and \"/d:lt[k='val2']\". /d:lt[k='val2']");
Michal Vasko14654712020-02-06 08:35:21 +0100727
728 *state = NULL;
729}
730
731static void
732test_unique_nested(void **state)
733{
734 *state = test_unique_nested;
735
736 const char *data;
737 struct lyd_node *tree;
738
739 /* nested list uniquest are compared only with instances in the same parent list instance */
740 data =
741 "<lt2 xmlns=\"urn:tests:d\">"
742 "<k>val1</k>"
743 "<cont>"
744 "<l2>1</l2>"
745 "</cont>"
746 "<l4>1</l4>"
747 "</lt2>"
748 "<lt2 xmlns=\"urn:tests:d\">"
749 "<k>val2</k>"
750 "<cont>"
751 "<l2>2</l2>"
752 "</cont>"
753 "<l4>2</l4>"
754 "<lt3>"
755 "<kk>val1</kk>"
756 "<l3>1</l3>"
757 "</lt3>"
758 "<lt3>"
759 "<kk>val2</kk>"
760 "<l3>2</l3>"
761 "</lt3>"
762 "</lt2>"
763 "<lt2 xmlns=\"urn:tests:d\">"
764 "<k>val3</k>"
765 "<cont>"
766 "<l2>3</l2>"
767 "</cont>"
768 "<l4>3</l4>"
769 "<lt3>"
770 "<kk>val1</kk>"
771 "<l3>2</l3>"
772 "</lt3>"
773 "</lt2>"
774 "<lt2 xmlns=\"urn:tests:d\">"
775 "<k>val4</k>"
776 "<cont>"
777 "<l2>4</l2>"
778 "</cont>"
779 "<l4>4</l4>"
780 "<lt3>"
781 "<kk>val1</kk>"
782 "<l3>3</l3>"
783 "</lt3>"
784 "</lt2>"
785 "<lt2 xmlns=\"urn:tests:d\">"
786 "<k>val5</k>"
787 "<cont>"
788 "<l2>5</l2>"
789 "</cont>"
790 "<l4>5</l4>"
791 "<lt3>"
792 "<kk>val1</kk>"
793 "<l3>3</l3>"
794 "</lt3>"
795 "</lt2>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100796 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY | LYD_OPT_STRICT, &tree));
Michal Vasko14654712020-02-06 08:35:21 +0100797 assert_non_null(tree);
Michal Vaskof03ed032020-03-04 13:31:44 +0100798 lyd_free_siblings(tree);
Michal Vasko14654712020-02-06 08:35:21 +0100799
800 data =
801 "<lt2 xmlns=\"urn:tests:d\">"
802 "<k>val1</k>"
803 "<cont>"
804 "<l2>1</l2>"
805 "</cont>"
806 "<l4>1</l4>"
807 "</lt2>"
808 "<lt2 xmlns=\"urn:tests:d\">"
809 "<k>val2</k>"
810 "<cont>"
811 "<l2>2</l2>"
812 "</cont>"
813 "<lt3>"
814 "<kk>val1</kk>"
815 "<l3>1</l3>"
816 "</lt3>"
817 "<lt3>"
818 "<kk>val2</kk>"
819 "<l3>2</l3>"
820 "</lt3>"
821 "<lt3>"
822 "<kk>val3</kk>"
823 "<l3>1</l3>"
824 "</lt3>"
825 "</lt2>"
826 "<lt2 xmlns=\"urn:tests:d\">"
827 "<k>val3</k>"
828 "<cont>"
829 "<l2>3</l2>"
830 "</cont>"
831 "<l4>1</l4>"
832 "<lt3>"
833 "<kk>val1</kk>"
834 "<l3>2</l3>"
835 "</lt3>"
836 "</lt2>"
837 "<lt2 xmlns=\"urn:tests:d\">"
838 "<k>val4</k>"
839 "<cont>"
840 "<l2>4</l2>"
841 "</cont>"
842 "<lt3>"
843 "<kk>val1</kk>"
844 "<l3>3</l3>"
845 "</lt3>"
846 "</lt2>"
847 "<lt2 xmlns=\"urn:tests:d\">"
848 "<k>val5</k>"
849 "<cont>"
850 "<l2>5</l2>"
851 "</cont>"
852 "<lt3>"
853 "<kk>val1</kk>"
854 "<l3>3</l3>"
855 "</lt3>"
856 "</lt2>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100857 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vasko14654712020-02-06 08:35:21 +0100858 assert_null(tree);
859 logbuf_assert("Unique data leaf(s) \"l3\" not satisfied in \"/d:lt2[k='val2']/lt3[kk='val3']\" and"
Michal Vasko9b368d32020-02-14 13:53:31 +0100860 " \"/d:lt2[k='val2']/lt3[kk='val1']\". /d:lt2[k='val2']/lt3[kk='val1']");
Michal Vasko14654712020-02-06 08:35:21 +0100861
862 data =
863 "<lt2 xmlns=\"urn:tests:d\">"
864 "<k>val1</k>"
865 "<cont>"
866 "<l2>1</l2>"
867 "</cont>"
868 "<l4>1</l4>"
869 "</lt2>"
870 "<lt2 xmlns=\"urn:tests:d\">"
871 "<k>val2</k>"
872 "<cont>"
873 "<l2>2</l2>"
874 "</cont>"
875 "<l4>2</l4>"
876 "</lt2>"
877 "<lt2 xmlns=\"urn:tests:d\">"
878 "<k>val3</k>"
879 "<cont>"
880 "<l2>3</l2>"
881 "</cont>"
882 "<l4>3</l4>"
883 "</lt2>"
884 "<lt2 xmlns=\"urn:tests:d\">"
885 "<k>val4</k>"
886 "<cont>"
887 "<l2>2</l2>"
888 "</cont>"
889 "<l4>2</l4>"
890 "</lt2>"
891 "<lt2 xmlns=\"urn:tests:d\">"
892 "<k>val5</k>"
893 "<cont>"
894 "<l2>5</l2>"
895 "</cont>"
896 "<l4>5</l4>"
897 "</lt2>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100898 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vasko14654712020-02-06 08:35:21 +0100899 assert_null(tree);
Michal Vasko9b368d32020-02-14 13:53:31 +0100900 logbuf_assert("Unique data leaf(s) \"cont/l2 l4\" not satisfied in \"/d:lt2[k='val4']\" and \"/d:lt2[k='val2']\". /d:lt2[k='val2']");
Michal Vasko14654712020-02-06 08:35:21 +0100901
902 data =
903 "<lt2 xmlns=\"urn:tests:d\">"
904 "<k>val1</k>"
905 "<cont>"
906 "<l2>1</l2>"
907 "</cont>"
908 "<l4>1</l4>"
909 "<l5>1</l5>"
910 "<l6>1</l6>"
911 "</lt2>"
912 "<lt2 xmlns=\"urn:tests:d\">"
913 "<k>val2</k>"
914 "<cont>"
915 "<l2>2</l2>"
916 "</cont>"
917 "<l4>1</l4>"
918 "<l5>1</l5>"
919 "</lt2>"
920 "<lt2 xmlns=\"urn:tests:d\">"
921 "<k>val3</k>"
922 "<cont>"
923 "<l2>3</l2>"
924 "</cont>"
925 "<l4>1</l4>"
926 "<l5>3</l5>"
927 "<l6>3</l6>"
928 "</lt2>"
929 "<lt2 xmlns=\"urn:tests:d\">"
930 "<k>val4</k>"
931 "<cont>"
932 "<l2>4</l2>"
933 "</cont>"
934 "<l4>1</l4>"
935 "<l6>1</l6>"
936 "</lt2>"
937 "<lt2 xmlns=\"urn:tests:d\">"
938 "<k>val5</k>"
939 "<cont>"
940 "<l2>5</l2>"
941 "</cont>"
942 "<l4>1</l4>"
943 "<l5>3</l5>"
944 "<l6>3</l6>"
945 "</lt2>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100946 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vasko14654712020-02-06 08:35:21 +0100947 assert_null(tree);
Michal Vasko9b368d32020-02-14 13:53:31 +0100948 logbuf_assert("Unique data leaf(s) \"l5 l6\" not satisfied in \"/d:lt2[k='val5']\" and \"/d:lt2[k='val3']\". /d:lt2[k='val3']");
Michal Vasko14654712020-02-06 08:35:21 +0100949
950 *state = NULL;
951}
952
Michal Vaskof03ed032020-03-04 13:31:44 +0100953static void
954test_dup(void **state)
955{
956 *state = test_dup;
957
958 const char *data;
959 struct lyd_node *tree;
960
961 data = "<d xmlns=\"urn:tests:e\">25</d><d xmlns=\"urn:tests:e\">50</d>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100962 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskof03ed032020-03-04 13:31:44 +0100963 assert_null(tree);
964 logbuf_assert("Duplicate instance of \"d\". /e:d");
965
966 data = "<lt xmlns=\"urn:tests:e\"><k>A</k></lt><lt xmlns=\"urn:tests:e\"><k>B</k></lt><lt xmlns=\"urn:tests:e\"><k>A</k></lt>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100967 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskof03ed032020-03-04 13:31:44 +0100968 assert_null(tree);
969 logbuf_assert("Duplicate instance of \"lt\". /e:lt[k='A']");
970
971 data = "<ll xmlns=\"urn:tests:e\">A</ll><ll xmlns=\"urn:tests:e\">B</ll><ll xmlns=\"urn:tests:e\">B</ll>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100972 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskof03ed032020-03-04 13:31:44 +0100973 assert_null(tree);
974 logbuf_assert("Duplicate instance of \"ll\". /e:ll[.='B']");
975
976 data = "<cont xmlns=\"urn:tests:e\"></cont><cont xmlns=\"urn:tests:e\"/>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100977 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskof03ed032020-03-04 13:31:44 +0100978 assert_null(tree);
979 logbuf_assert("Duplicate instance of \"cont\". /e:cont");
980
981 /* same tests again but using hashes */
982 data = "<cont xmlns=\"urn:tests:e\"><d>25</d><d>50</d><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll></cont>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100983 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskof03ed032020-03-04 13:31:44 +0100984 assert_null(tree);
985 logbuf_assert("Duplicate instance of \"d\". /e:cont/d");
986
987 data = "<cont xmlns=\"urn:tests:e\"><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll>"
988 "<lt><k>a</k></lt><lt><k>b</k></lt><lt><k>c</k></lt><lt><k>d</k></lt><lt><k>c</k></lt></cont>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100989 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskof03ed032020-03-04 13:31:44 +0100990 assert_null(tree);
991 logbuf_assert("Duplicate instance of \"lt\". /e:cont/lt[k='c']");
992
993 data = "<cont xmlns=\"urn:tests:e\"><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll>"
994 "<ll>a</ll><ll>b</ll><ll>c</ll><ll>d</ll><ll>d</ll></cont>";
Michal Vasko9f96a052020-03-10 09:41:45 +0100995 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskof03ed032020-03-04 13:31:44 +0100996 assert_null(tree);
997 logbuf_assert("Duplicate instance of \"ll\". /e:cont/ll[.='d']");
998
999 /* cases */
1000 data = "<l xmlns=\"urn:tests:e\">a</l><l xmlns=\"urn:tests:e\">b</l><l xmlns=\"urn:tests:e\">c</l><l xmlns=\"urn:tests:e\">b</l>";
Michal Vasko9f96a052020-03-10 09:41:45 +01001001 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskof03ed032020-03-04 13:31:44 +01001002 assert_null(tree);
1003 logbuf_assert("Duplicate instance of \"l\". /e:l[.='b']");
1004
1005 data = "<l xmlns=\"urn:tests:e\">a</l><l xmlns=\"urn:tests:e\">b</l><l xmlns=\"urn:tests:e\">c</l><a xmlns=\"urn:tests:e\">aa</a>";
Michal Vasko9f96a052020-03-10 09:41:45 +01001006 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskof03ed032020-03-04 13:31:44 +01001007 assert_null(tree);
1008 logbuf_assert("Data for both cases \"a\" and \"b\" exist. /e:choic");
1009
1010 *state = NULL;
1011}
1012
1013static void
1014test_defaults(void **state)
1015{
1016 *state = test_defaults;
1017
Michal Vaskof03ed032020-03-04 13:31:44 +01001018 char *str;
1019 struct lyd_node *tree, *node;
1020 const struct lys_module *mod = ly_ctx_get_module_latest(ctx, "f");
1021
Michal Vaskob1b5c262020-03-05 14:29:47 +01001022 /* get defaults */
1023 tree = NULL;
1024 assert_int_equal(lyd_validate_modules(&tree, &mod, 1, 0), LY_SUCCESS);
Michal Vaskof03ed032020-03-04 13:31:44 +01001025 assert_non_null(tree);
1026
1027 /* check all defaults exist */
1028 lyd_print_mem(&str, tree, LYD_XML, LYDP_WITHSIBLINGS | LYDP_WD_IMPL_TAG);
1029 assert_string_equal(str,
Michal Vaskof03ed032020-03-04 13:31:44 +01001030 "<ll1 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>"
1031 "<ll1 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>"
1032 "<ll1 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>"
1033 "<d xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>"
1034 "<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>"
Michal Vaskob1b5c262020-03-05 14:29:47 +01001035 "<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>"
Michal Vasko52927e22020-03-16 17:26:14 +01001036 "<cont xmlns=\"urn:tests:f\">"
1037 "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>"
1038 "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>"
1039 "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>"
1040 "<d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>"
1041 "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>"
1042 "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>"
Michal Vaskob1b5c262020-03-05 14:29:47 +01001043 "</cont>");
Michal Vaskof03ed032020-03-04 13:31:44 +01001044 free(str);
1045
1046 /* create another explicit case and validate */
1047 node = lyd_new_term(NULL, mod, "l", "value");
1048 assert_non_null(node);
Michal Vaskob1b5c262020-03-05 14:29:47 +01001049 assert_int_equal(lyd_insert_sibling(tree, node), LY_SUCCESS);
1050 assert_int_equal(lyd_validate(&tree, ctx, LYD_VALOPT_DATA_ONLY), LY_SUCCESS);
Michal Vaskof03ed032020-03-04 13:31:44 +01001051
1052 /* check data tree */
1053 lyd_print_mem(&str, tree, LYD_XML, LYDP_WITHSIBLINGS | LYDP_WD_IMPL_TAG);
1054 assert_string_equal(str,
Michal Vaskob1b5c262020-03-05 14:29:47 +01001055 "<d xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>"
1056 "<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>"
1057 "<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>"
Michal Vasko52927e22020-03-16 17:26:14 +01001058 "<cont xmlns=\"urn:tests:f\">"
1059 "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>"
1060 "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>"
1061 "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>"
1062 "<d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>"
1063 "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>"
1064 "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>"
Michal Vaskof03ed032020-03-04 13:31:44 +01001065 "</cont>"
Michal Vaskof03ed032020-03-04 13:31:44 +01001066 "<l xmlns=\"urn:tests:f\">value</l>");
1067 free(str);
1068
1069 /* create explicit leaf-list and leaf and validate */
1070 node = lyd_new_term(NULL, mod, "d", "15");
1071 assert_non_null(node);
Michal Vaskob1b5c262020-03-05 14:29:47 +01001072 assert_int_equal(lyd_insert_sibling(tree, node), LY_SUCCESS);
Michal Vaskof03ed032020-03-04 13:31:44 +01001073 node = lyd_new_term(NULL, mod, "ll2", "dflt2");
1074 assert_non_null(node);
Michal Vaskob1b5c262020-03-05 14:29:47 +01001075 assert_int_equal(lyd_insert_sibling(tree, node), LY_SUCCESS);
1076 assert_int_equal(lyd_validate(&tree, ctx, LYD_VALOPT_DATA_ONLY), LY_SUCCESS);
Michal Vaskof03ed032020-03-04 13:31:44 +01001077
1078 /* check data tree */
1079 lyd_print_mem(&str, tree, LYD_XML, LYDP_WITHSIBLINGS | LYDP_WD_IMPL_TAG);
1080 assert_string_equal(str,
Michal Vasko52927e22020-03-16 17:26:14 +01001081 "<cont xmlns=\"urn:tests:f\">"
1082 "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>"
1083 "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>"
1084 "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>"
1085 "<d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>"
1086 "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>"
1087 "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>"
Michal Vaskof03ed032020-03-04 13:31:44 +01001088 "</cont>"
1089 "<l xmlns=\"urn:tests:f\">value</l>"
1090 "<d xmlns=\"urn:tests:f\">15</d>"
1091 "<ll2 xmlns=\"urn:tests:f\">dflt2</ll2>");
1092 free(str);
1093
Michal Vaskob1b5c262020-03-05 14:29:47 +01001094 /* create first explicit container, which should become implicit */
1095 node = lyd_new_inner(NULL, mod, "cont");
1096 assert_non_null(node);
1097 assert_int_equal(lyd_insert_before(tree, node), LY_SUCCESS);
1098 tree = tree->prev;
1099 assert_int_equal(lyd_validate(&tree, ctx, LYD_VALOPT_DATA_ONLY), LY_SUCCESS);
1100
1101 /* check data tree */
1102 lyd_print_mem(&str, tree, LYD_XML, LYDP_WITHSIBLINGS | LYDP_WD_IMPL_TAG);
1103 assert_string_equal(str,
Michal Vasko52927e22020-03-16 17:26:14 +01001104 "<cont xmlns=\"urn:tests:f\">"
1105 "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>"
1106 "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>"
1107 "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>"
1108 "<d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>"
1109 "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>"
1110 "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>"
Michal Vaskob1b5c262020-03-05 14:29:47 +01001111 "</cont>"
1112 "<l xmlns=\"urn:tests:f\">value</l>"
1113 "<d xmlns=\"urn:tests:f\">15</d>"
1114 "<ll2 xmlns=\"urn:tests:f\">dflt2</ll2>");
1115 free(str);
1116
1117 /* create second explicit container, which should become implicit, so the first tree node should be removed */
1118 node = lyd_new_inner(NULL, mod, "cont");
1119 assert_non_null(node);
1120 assert_int_equal(lyd_insert_after(tree, node), LY_SUCCESS);
1121 assert_int_equal(lyd_validate(&tree, ctx, LYD_VALOPT_DATA_ONLY), LY_SUCCESS);
1122
1123 /* check data tree */
1124 lyd_print_mem(&str, tree, LYD_XML, LYDP_WITHSIBLINGS | LYDP_WD_IMPL_TAG);
1125 assert_string_equal(str,
Michal Vasko52927e22020-03-16 17:26:14 +01001126 "<cont xmlns=\"urn:tests:f\">"
1127 "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>"
1128 "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>"
1129 "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>"
1130 "<d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>"
1131 "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>"
1132 "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>"
Michal Vaskob1b5c262020-03-05 14:29:47 +01001133 "</cont>"
1134 "<l xmlns=\"urn:tests:f\">value</l>"
1135 "<d xmlns=\"urn:tests:f\">15</d>"
1136 "<ll2 xmlns=\"urn:tests:f\">dflt2</ll2>");
1137 free(str);
Michal Vaskof03ed032020-03-04 13:31:44 +01001138
1139 /* similar changes for nested defaults */
1140 assert_non_null(lyd_new_term(tree, NULL, "ll1", "def3"));
1141 assert_non_null(lyd_new_term(tree, NULL, "d", "5"));
1142 assert_non_null(lyd_new_term(tree, NULL, "ll2", "non-dflt"));
Michal Vaskob1b5c262020-03-05 14:29:47 +01001143 assert_int_equal(lyd_validate(&tree, ctx, LYD_VALOPT_DATA_ONLY), LY_SUCCESS);
Michal Vaskof03ed032020-03-04 13:31:44 +01001144
1145 /* check data tree */
1146 lyd_print_mem(&str, tree, LYD_XML, LYDP_WITHSIBLINGS | LYDP_WD_IMPL_TAG);
1147 assert_string_equal(str,
Michal Vasko52927e22020-03-16 17:26:14 +01001148 "<cont xmlns=\"urn:tests:f\">"
Michal Vaskof03ed032020-03-04 13:31:44 +01001149 "<ll1>def3</ll1>"
1150 "<d>5</d>"
1151 "<ll2>non-dflt</ll2>"
1152 "</cont>"
1153 "<l xmlns=\"urn:tests:f\">value</l>"
1154 "<d xmlns=\"urn:tests:f\">15</d>"
1155 "<ll2 xmlns=\"urn:tests:f\">dflt2</ll2>");
1156 free(str);
1157
1158 lyd_free_siblings(tree);
1159
1160 *state = NULL;
1161}
1162
Michal Vaskoc193ce92020-03-06 11:04:48 +01001163static void
1164test_iffeature(void **state)
1165{
1166 *state = test_iffeature;
1167
1168 const char *data;
1169 struct lyd_node *tree;
1170 const struct lys_module *mod = ly_ctx_get_module_latest(ctx, "g");
1171
1172 /* get empty data */
1173 tree = NULL;
1174 assert_int_equal(lyd_validate_modules(&tree, &mod, 1, 0), LY_SUCCESS);
1175 assert_null(tree);
1176
1177 /* disabled by f1 */
1178 data =
1179 "<cont xmlns=\"urn:tests:g\">"
1180 "<d>51</d>"
1181 "</cont>";
Michal Vasko9f96a052020-03-10 09:41:45 +01001182 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskoc193ce92020-03-06 11:04:48 +01001183 assert_null(tree);
1184 logbuf_assert("Data are disabled by \"cont\" schema node if-feature. /g:cont");
1185
1186 /* enable f1 */
1187 assert_int_equal(lys_feature_enable(mod, "f1"), LY_SUCCESS);
1188
1189 /* get data with default container */
1190 assert_int_equal(lyd_validate_modules(&tree, &mod, 1, 0), LY_SUCCESS);
1191 assert_non_null(tree);
1192 lyd_free_siblings(tree);
1193
1194 /* disabled by f2 */
1195 data =
1196 "<cont xmlns=\"urn:tests:g\">"
1197 "<cont2>"
1198 "<e>val</e>"
1199 "</cont2>"
1200 "</cont>";
Michal Vasko9f96a052020-03-10 09:41:45 +01001201 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskoc193ce92020-03-06 11:04:48 +01001202 assert_null(tree);
1203 logbuf_assert("Data are disabled by \"cont2\" schema node if-feature. /g:cont/cont2");
1204
1205 data =
1206 "<cont xmlns=\"urn:tests:g\">"
1207 "<a>val</a>"
1208 "</cont>";
Michal Vasko9f96a052020-03-10 09:41:45 +01001209 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskoc193ce92020-03-06 11:04:48 +01001210 assert_null(tree);
1211 logbuf_assert("Data are disabled by \"choic\" schema node if-feature. /g:cont/a");
1212
1213 /* enable f3 */
1214 assert_int_equal(lys_feature_enable(mod, "f3"), LY_SUCCESS);
1215
Michal Vasko9f96a052020-03-10 09:41:45 +01001216 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskoc193ce92020-03-06 11:04:48 +01001217 assert_non_null(tree);
1218 lyd_free_siblings(tree);
1219
1220 /* disabled by f2 */
1221 data =
1222 "<cont xmlns=\"urn:tests:g\">"
1223 "<l>val</l>"
1224 "</cont>";
Michal Vasko9f96a052020-03-10 09:41:45 +01001225 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskoc193ce92020-03-06 11:04:48 +01001226 assert_null(tree);
1227 logbuf_assert("Data are disabled by \"b\" schema node if-feature. /g:cont/l");
1228
1229 /* enable f2 */
1230 assert_int_equal(lys_feature_enable(mod, "f2"), LY_SUCCESS);
1231
Michal Vasko9f96a052020-03-10 09:41:45 +01001232 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
Michal Vaskoc193ce92020-03-06 11:04:48 +01001233 assert_non_null(tree);
1234 lyd_free_siblings(tree);
1235
1236 /* try separate validation */
1237 assert_int_equal(lys_feature_disable(mod, "f1"), LY_SUCCESS);
1238 assert_int_equal(lys_feature_disable(mod, "f2"), LY_SUCCESS);
1239 assert_int_equal(lys_feature_disable(mod, "f3"), LY_SUCCESS);
1240
1241 data =
1242 "<cont xmlns=\"urn:tests:g\">"
1243 "<l>val</l>"
1244 "<d>51</d>"
1245 "<cont2>"
1246 "<e>val</e>"
1247 "</cont2>"
1248 "</cont>";
Michal Vasko9f96a052020-03-10 09:41:45 +01001249 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_OPT_PARSE_ONLY, &tree));
Michal Vaskoc193ce92020-03-06 11:04:48 +01001250 assert_non_null(tree);
1251
1252 assert_int_equal(LY_EVALID, lyd_validate(&tree, NULL, LYD_VALOPT_DATA_ONLY));
1253 logbuf_assert("Data are disabled by \"cont\" schema node if-feature. /g:cont");
1254
1255 assert_int_equal(lys_feature_enable(mod, "f1"), LY_SUCCESS);
1256
1257 assert_int_equal(LY_EVALID, lyd_validate(&tree, NULL, LYD_VALOPT_DATA_ONLY));
1258 logbuf_assert("Data are disabled by \"b\" schema node if-feature. /g:cont/l");
1259
1260 assert_int_equal(lys_feature_enable(mod, "f2"), LY_SUCCESS);
1261
1262 assert_int_equal(LY_SUCCESS, lyd_validate(&tree, NULL, LYD_VALOPT_DATA_ONLY));
1263
1264 lyd_free_siblings(tree);
1265
1266 *state = NULL;
1267}
1268
Michal Vasko5b37a352020-03-06 13:38:33 +01001269static void
1270test_state(void **state)
1271{
Michal Vaskocc048b22020-03-27 15:52:38 +01001272 *state = test_state;
Michal Vasko5b37a352020-03-06 13:38:33 +01001273
1274 const char *data;
1275 struct lyd_node *tree;
1276
1277 data =
1278 "<cont xmlns=\"urn:tests:h\">"
1279 "<cont2>"
1280 "<l>val</l>"
1281 "</cont2>"
1282 "</cont>";
Michal Vasko9f96a052020-03-10 09:41:45 +01001283 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_OPT_PARSE_ONLY | LYD_OPT_NO_STATE, &tree));
Michal Vasko5b37a352020-03-06 13:38:33 +01001284 assert_null(tree);
1285 logbuf_assert("Invalid state data node \"cont2\" found. Line number 1.");
1286
Michal Vasko9f96a052020-03-10 09:41:45 +01001287 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY | LYD_VALOPT_NO_STATE, &tree));
Michal Vasko5b37a352020-03-06 13:38:33 +01001288 assert_null(tree);
1289 logbuf_assert("Invalid state data node \"cont2\" found. /h:cont/cont2");
1290
Michal Vasko9f96a052020-03-10 09:41:45 +01001291 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_OPT_PARSE_ONLY, &tree));
Michal Vasko5b37a352020-03-06 13:38:33 +01001292 assert_non_null(tree);
1293
1294 assert_int_equal(LY_EVALID, lyd_validate(&tree, NULL, LYD_VALOPT_DATA_ONLY | LYD_VALOPT_NO_STATE));
1295 logbuf_assert("Invalid state data node \"cont2\" found. /h:cont/cont2");
1296
1297 lyd_free_siblings(tree);
1298
1299 *state = NULL;
1300}
1301
Michal Vaskocc048b22020-03-27 15:52:38 +01001302static void
1303test_must(void **state)
1304{
1305 *state = test_must;
1306
1307 const char *data;
1308 struct lyd_node *tree;
1309
1310 data =
1311 "<cont xmlns=\"urn:tests:i\">"
1312 "<l>wrong</l>"
1313 "<l2>val</l2>"
1314 "</cont>";
1315 assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
1316 assert_null(tree);
1317 logbuf_assert("Must condition \"../l = 'right'\" not satisfied. /i:cont/l2");
1318
1319 data =
1320 "<cont xmlns=\"urn:tests:i\">"
1321 "<l>right</l>"
1322 "<l2>val</l2>"
1323 "</cont>";
1324 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
1325 assert_non_null(tree);
1326 lyd_free_tree(tree);
1327
1328 *state = NULL;
1329}
1330
Michal Vaskofea12c62020-03-30 11:00:15 +02001331static void
1332test_action(void **state)
1333{
1334 *state = test_action;
1335
1336 const char *data;
1337 struct lyd_node *tree, *op_tree;
1338 const struct lys_module *mod;
1339
1340 data =
1341 "<cont xmlns=\"urn:tests:j\">"
1342 "<l1>"
1343 "<k>val1</k>"
1344 "<act>"
1345 "<lf2>target</lf2>"
1346 "</act>"
1347 "</l1>"
1348 "</cont>";
1349 assert_int_equal(LY_SUCCESS, lyd_parse_xml_rpc(ctx, data, &op_tree, NULL));
1350 assert_non_null(op_tree);
1351
1352 /* missing leafref */
Michal Vaskocb7526d2020-03-30 15:08:26 +02001353 assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, NULL, LYD_VALOPT_INPUT));
Michal Vaskofea12c62020-03-30 11:00:15 +02001354 logbuf_assert("Invalid leafref - required instance \"/lf3\" does not exists in the data tree(s). /j:cont/l1[k='val1']/act/lf2");
1355
1356 data =
1357 "<cont xmlns=\"urn:tests:j\">"
1358 "<lf1>not true</lf1>"
1359 "</cont>"
1360 "<lf3 xmlns=\"urn:tests:j\">target</lf3>";
1361 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_OPT_PARSE_ONLY | LYD_OPT_TRUSTED, &tree));
1362 assert_non_null(tree);
1363
1364 /* disabled if-feature */
Michal Vaskocb7526d2020-03-30 15:08:26 +02001365 assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, tree, LYD_VALOPT_INPUT));
Michal Vaskofea12c62020-03-30 11:00:15 +02001366 logbuf_assert("Data are disabled by \"act\" schema node if-feature. /j:cont/l1[k='val1']/act");
1367
1368 mod = ly_ctx_get_module_latest(ctx, "j");
1369 assert_non_null(mod);
1370 assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "feat1"));
1371
1372 /* input must false */
Michal Vaskocb7526d2020-03-30 15:08:26 +02001373 assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, tree, LYD_VALOPT_INPUT));
Michal Vaskofea12c62020-03-30 11:00:15 +02001374 logbuf_assert("Must condition \"../../lf1 = 'true'\" not satisfied. /j:cont/l1[k='val1']/act");
1375
1376 lyd_free_siblings(tree);
1377 data =
1378 "<cont xmlns=\"urn:tests:j\">"
1379 "<lf1>true</lf1>"
1380 "</cont>"
1381 "<lf3 xmlns=\"urn:tests:j\">target</lf3>";
1382 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_OPT_PARSE_ONLY | LYD_OPT_TRUSTED, &tree));
1383 assert_non_null(tree);
1384
1385 /* success */
Michal Vaskocb7526d2020-03-30 15:08:26 +02001386 assert_int_equal(LY_SUCCESS, lyd_validate_op(op_tree, tree, LYD_VALOPT_INPUT));
Michal Vaskofea12c62020-03-30 11:00:15 +02001387
Michal Vaskocb7526d2020-03-30 15:08:26 +02001388 lys_feature_disable(mod, "feat1");
1389 lyd_free_tree(op_tree);
1390 lyd_free_siblings(tree);
1391
1392 *state = NULL;
1393}
1394
1395static void
1396test_reply(void **state)
1397{
1398 *state = test_reply;
1399
1400 const char *data;
1401 struct lyd_node *tree, *op_tree, *request;
1402 const struct lys_module *mod;
1403
1404 data =
1405 "<cont xmlns=\"urn:tests:j\">"
1406 "<l1>"
1407 "<k>val1</k>"
1408 "<act>"
1409 "<lf2>target</lf2>"
1410 "</act>"
1411 "</l1>"
1412 "</cont>";
1413 assert_int_equal(LY_SUCCESS, lyd_parse_xml_rpc(ctx, data, &request, NULL));
1414 assert_non_null(request);
1415 data = "<lf2 xmlns=\"urn:tests:j\">target</lf2>";
1416 assert_int_equal(LY_SUCCESS, lyd_parse_xml_reply(request, data, &op_tree, NULL));
1417 lyd_free_all(request);
1418 assert_non_null(op_tree);
1419
1420 /* missing leafref */
1421 assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, NULL, LYD_VALOPT_OUTPUT));
1422 logbuf_assert("Invalid leafref - required instance \"/lf4\" does not exists in the data tree(s). /j:cont/l1[k='val1']/act/lf2");
1423
1424 data =
1425 "<cont xmlns=\"urn:tests:j\">"
1426 "<lf1>not true</lf1>"
1427 "</cont>"
1428 "<lf4 xmlns=\"urn:tests:j\">target</lf4>";
1429 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_OPT_PARSE_ONLY | LYD_OPT_TRUSTED, &tree));
1430 assert_non_null(tree);
1431
1432 /* disabled if-feature */
1433 assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, tree, LYD_VALOPT_OUTPUT));
1434 logbuf_assert("Data are disabled by \"act\" schema node if-feature. /j:cont/l1[k='val1']/act");
1435
1436 mod = ly_ctx_get_module_latest(ctx, "j");
1437 assert_non_null(mod);
1438 assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "feat1"));
1439
1440 /* input must false */
1441 assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, tree, LYD_VALOPT_OUTPUT));
1442 logbuf_assert("Must condition \"../../lf1 = 'true2'\" not satisfied. /j:cont/l1[k='val1']/act");
1443
1444 lyd_free_siblings(tree);
1445 data =
1446 "<cont xmlns=\"urn:tests:j\">"
1447 "<lf1>true2</lf1>"
1448 "</cont>"
1449 "<lf4 xmlns=\"urn:tests:j\">target</lf4>";
1450 assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_OPT_PARSE_ONLY | LYD_OPT_TRUSTED, &tree));
1451 assert_non_null(tree);
1452
1453 /* success */
1454 assert_int_equal(LY_SUCCESS, lyd_validate_op(op_tree, tree, LYD_VALOPT_OUTPUT));
1455
1456 lys_feature_disable(mod, "feat1");
Michal Vaskofea12c62020-03-30 11:00:15 +02001457 lyd_free_tree(op_tree);
1458 lyd_free_siblings(tree);
1459
1460 *state = NULL;
1461}
1462
Michal Vaskocde73ac2019-11-14 16:10:27 +01001463int main(void)
1464{
1465 const struct CMUnitTest tests[] = {
Michal Vaskoacd83e72020-02-04 14:12:01 +01001466 cmocka_unit_test_teardown(test_when, teardown_s),
1467 cmocka_unit_test_teardown(test_mandatory, teardown_s),
1468 cmocka_unit_test_teardown(test_minmax, teardown_s),
Michal Vasko14654712020-02-06 08:35:21 +01001469 cmocka_unit_test_teardown(test_unique, teardown_s),
1470 cmocka_unit_test_teardown(test_unique_nested, teardown_s),
Michal Vaskof03ed032020-03-04 13:31:44 +01001471 cmocka_unit_test_teardown(test_dup, teardown_s),
1472 cmocka_unit_test_teardown(test_defaults, teardown_s),
Michal Vaskoc193ce92020-03-06 11:04:48 +01001473 cmocka_unit_test_teardown(test_iffeature, teardown_s),
Michal Vasko5b37a352020-03-06 13:38:33 +01001474 cmocka_unit_test_teardown(test_state, teardown_s),
Michal Vaskocc048b22020-03-27 15:52:38 +01001475 cmocka_unit_test_teardown(test_must, teardown_s),
Michal Vaskofea12c62020-03-30 11:00:15 +02001476 cmocka_unit_test_teardown(test_action, teardown_s),
Michal Vaskocb7526d2020-03-30 15:08:26 +02001477 cmocka_unit_test_teardown(test_reply, teardown_s),
Michal Vaskocde73ac2019-11-14 16:10:27 +01001478 };
1479
Michal Vaskoacd83e72020-02-04 14:12:01 +01001480 return cmocka_run_group_tests(tests, setup, teardown);
Michal Vaskocde73ac2019-11-14 16:10:27 +01001481}