Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 1 | /** |
| 2 | * @file test_validation.c |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 3 | * @author: Radek Krejci <rkrejci@cesnet.cz> |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 4 | * @brief unit tests for functions from validation.c |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 5 | * |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 6 | * Copyright (c) 2020 CESNET, z.s.p.o. |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 7 | * |
| 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 Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 15 | #include "tests/config.h" |
| 16 | |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 17 | #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" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 27 | #include "../../src/printer.h" |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 28 | #include "../../src/printer_data.h" |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 29 | |
| 30 | #define BUFSIZE 1024 |
| 31 | char logbuf[BUFSIZE] = {0}; |
| 32 | int store = -1; /* negative for infinite logging, positive for limited logging */ |
| 33 | |
| 34 | struct ly_ctx *ctx; /* context for tests */ |
| 35 | |
| 36 | /* set to 0 to printing error messages to stderr instead of checking them in code */ |
| 37 | #define ENABLE_LOGGER_CHECKING 1 |
| 38 | |
| 39 | #if ENABLE_LOGGER_CHECKING |
| 40 | static void |
| 41 | logger(LY_LOG_LEVEL level, const char *msg, const char *path) |
| 42 | { |
| 43 | (void) level; /* unused */ |
| 44 | if (store) { |
| 45 | if (path && path[0]) { |
| 46 | snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path); |
| 47 | } else { |
| 48 | strncpy(logbuf, msg, BUFSIZE - 1); |
| 49 | } |
| 50 | if (store > 0) { |
| 51 | --store; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | #endif |
| 56 | |
| 57 | static int |
| 58 | setup(void **state) |
| 59 | { |
| 60 | (void) state; /* unused */ |
| 61 | |
| 62 | const char *schema_a = |
| 63 | "module a {" |
| 64 | "namespace urn:tests:a;" |
| 65 | "prefix a;" |
| 66 | "yang-version 1.1;" |
| 67 | |
| 68 | "container cont {" |
| 69 | "leaf a {" |
| 70 | "when \"../../c = 'val_c'\";" |
| 71 | "type string;" |
| 72 | "}" |
| 73 | "leaf b {" |
| 74 | "type string;" |
| 75 | "}" |
| 76 | "}" |
| 77 | "leaf c {" |
| 78 | "when \"/cont/b = 'val_b'\";" |
| 79 | "type string;" |
| 80 | "}" |
| 81 | "}"; |
Michal Vasko | a388136 | 2020-01-21 15:57:35 +0100 | [diff] [blame] | 82 | const char *schema_b = |
| 83 | "module b {" |
| 84 | "namespace urn:tests:b;" |
| 85 | "prefix b;" |
| 86 | "yang-version 1.1;" |
| 87 | |
| 88 | "choice choic {" |
| 89 | "mandatory true;" |
| 90 | "leaf a {" |
| 91 | "type string;" |
| 92 | "}" |
| 93 | "case b {" |
| 94 | "leaf l {" |
| 95 | "type string;" |
| 96 | "}" |
| 97 | "}" |
| 98 | "}" |
| 99 | "leaf c {" |
| 100 | "mandatory true;" |
| 101 | "type string;" |
| 102 | "}" |
| 103 | "leaf d {" |
| 104 | "type empty;" |
| 105 | "}" |
| 106 | "}"; |
Michal Vasko | acd83e7 | 2020-02-04 14:12:01 +0100 | [diff] [blame] | 107 | const char *schema_c = |
| 108 | "module c {" |
| 109 | "namespace urn:tests:c;" |
| 110 | "prefix c;" |
| 111 | "yang-version 1.1;" |
| 112 | |
| 113 | "choice choic {" |
| 114 | "leaf a {" |
| 115 | "type string;" |
| 116 | "}" |
| 117 | "case b {" |
| 118 | "leaf-list l {" |
| 119 | "min-elements 3;" |
| 120 | "type string;" |
| 121 | "}" |
| 122 | "}" |
| 123 | "}" |
| 124 | "list lt {" |
| 125 | "max-elements 4;" |
| 126 | "key \"k\";" |
| 127 | "leaf k {" |
| 128 | "type string;" |
| 129 | "}" |
| 130 | "}" |
| 131 | "leaf d {" |
| 132 | "type empty;" |
| 133 | "}" |
| 134 | "}"; |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 135 | const char *schema_d = |
| 136 | "module d {" |
| 137 | "namespace urn:tests:d;" |
| 138 | "prefix d;" |
| 139 | "yang-version 1.1;" |
| 140 | |
| 141 | "list lt {" |
| 142 | "key \"k\";" |
| 143 | "unique \"l1\";" |
| 144 | "leaf k {" |
| 145 | "type string;" |
| 146 | "}" |
| 147 | "leaf l1 {" |
| 148 | "type string;" |
| 149 | "}" |
| 150 | "}" |
| 151 | "list lt2 {" |
| 152 | "key \"k\";" |
| 153 | "unique \"cont/l2 l4\";" |
| 154 | "unique \"l5 l6\";" |
| 155 | "leaf k {" |
| 156 | "type string;" |
| 157 | "}" |
| 158 | "container cont {" |
| 159 | "leaf l2 {" |
| 160 | "type string;" |
| 161 | "}" |
| 162 | "}" |
| 163 | "leaf l4 {" |
| 164 | "type string;" |
| 165 | "}" |
| 166 | "leaf l5 {" |
| 167 | "type string;" |
| 168 | "}" |
| 169 | "leaf l6 {" |
| 170 | "type string;" |
| 171 | "}" |
| 172 | "list lt3 {" |
| 173 | "key \"kk\";" |
| 174 | "unique \"l3\";" |
| 175 | "leaf kk {" |
| 176 | "type string;" |
| 177 | "}" |
| 178 | "leaf l3 {" |
| 179 | "type string;" |
| 180 | "}" |
| 181 | "}" |
| 182 | "}" |
| 183 | "}"; |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 184 | const char *schema_e = |
| 185 | "module e {" |
| 186 | "namespace urn:tests:e;" |
| 187 | "prefix e;" |
| 188 | "yang-version 1.1;" |
| 189 | |
| 190 | "choice choic {" |
| 191 | "leaf a {" |
| 192 | "type string;" |
| 193 | "}" |
| 194 | "case b {" |
| 195 | "leaf-list l {" |
| 196 | "type string;" |
| 197 | "}" |
| 198 | "}" |
| 199 | "}" |
| 200 | "list lt {" |
| 201 | "key \"k\";" |
| 202 | "leaf k {" |
| 203 | "type string;" |
| 204 | "}" |
| 205 | "}" |
| 206 | "leaf d {" |
| 207 | "type uint32;" |
| 208 | "}" |
| 209 | "leaf-list ll {" |
| 210 | "type string;" |
| 211 | "}" |
| 212 | "container cont {" |
| 213 | "list lt {" |
| 214 | "key \"k\";" |
| 215 | "leaf k {" |
| 216 | "type string;" |
| 217 | "}" |
| 218 | "}" |
| 219 | "leaf d {" |
| 220 | "type uint32;" |
| 221 | "}" |
| 222 | "leaf-list ll {" |
| 223 | "type string;" |
| 224 | "}" |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 225 | "leaf-list ll2 {" |
| 226 | "type enumeration {" |
| 227 | "enum one;" |
| 228 | "enum two;" |
| 229 | "}" |
| 230 | "}" |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 231 | "}" |
| 232 | "}"; |
| 233 | const char *schema_f = |
| 234 | "module f {" |
| 235 | "namespace urn:tests:f;" |
| 236 | "prefix f;" |
| 237 | "yang-version 1.1;" |
| 238 | |
| 239 | "choice choic {" |
| 240 | "default \"c\";" |
| 241 | "leaf a {" |
| 242 | "type string;" |
| 243 | "}" |
| 244 | "case b {" |
| 245 | "leaf l {" |
| 246 | "type string;" |
| 247 | "}" |
| 248 | "}" |
| 249 | "case c {" |
| 250 | "leaf-list ll1 {" |
| 251 | "type string;" |
| 252 | "default \"def1\";" |
| 253 | "default \"def2\";" |
| 254 | "default \"def3\";" |
| 255 | "}" |
| 256 | "}" |
| 257 | "}" |
| 258 | "leaf d {" |
| 259 | "type uint32;" |
| 260 | "default 15;" |
| 261 | "}" |
| 262 | "leaf-list ll2 {" |
| 263 | "type string;" |
| 264 | "default \"dflt1\";" |
| 265 | "default \"dflt2\";" |
| 266 | "}" |
| 267 | "container cont {" |
| 268 | "choice choic {" |
| 269 | "default \"c\";" |
| 270 | "leaf a {" |
| 271 | "type string;" |
| 272 | "}" |
| 273 | "case b {" |
| 274 | "leaf l {" |
| 275 | "type string;" |
| 276 | "}" |
| 277 | "}" |
| 278 | "case c {" |
| 279 | "leaf-list ll1 {" |
| 280 | "type string;" |
| 281 | "default \"def1\";" |
| 282 | "default \"def2\";" |
| 283 | "default \"def3\";" |
| 284 | "}" |
| 285 | "}" |
| 286 | "}" |
| 287 | "leaf d {" |
| 288 | "type uint32;" |
| 289 | "default 15;" |
| 290 | "}" |
| 291 | "leaf-list ll2 {" |
| 292 | "type string;" |
| 293 | "default \"dflt1\";" |
| 294 | "default \"dflt2\";" |
| 295 | "}" |
| 296 | "}" |
| 297 | "}"; |
Michal Vasko | c193ce9 | 2020-03-06 11:04:48 +0100 | [diff] [blame] | 298 | const char *schema_g = |
| 299 | "module g {" |
| 300 | "namespace urn:tests:g;" |
| 301 | "prefix g;" |
| 302 | "yang-version 1.1;" |
| 303 | |
| 304 | "feature f1;" |
| 305 | "feature f2;" |
| 306 | "feature f3;" |
| 307 | |
| 308 | "container cont {" |
| 309 | "if-feature \"f1\";" |
| 310 | "choice choic {" |
| 311 | "if-feature \"f2 or f3\";" |
| 312 | "leaf a {" |
| 313 | "type string;" |
| 314 | "}" |
| 315 | "case b {" |
| 316 | "if-feature \"f2 and f1\";" |
| 317 | "leaf l {" |
| 318 | "type string;" |
| 319 | "}" |
| 320 | "}" |
| 321 | "}" |
| 322 | "leaf d {" |
| 323 | "type uint32;" |
| 324 | "}" |
| 325 | "container cont2 {" |
| 326 | "if-feature \"f2\";" |
| 327 | "leaf e {" |
| 328 | "type string;" |
| 329 | "}" |
| 330 | "}" |
| 331 | "}" |
| 332 | "}"; |
Michal Vasko | 5b37a35 | 2020-03-06 13:38:33 +0100 | [diff] [blame] | 333 | const char *schema_h = |
| 334 | "module h {" |
| 335 | "namespace urn:tests:h;" |
| 336 | "prefix h;" |
| 337 | "yang-version 1.1;" |
| 338 | |
| 339 | "container cont {" |
| 340 | "container cont2 {" |
| 341 | "config false;" |
| 342 | "leaf l {" |
| 343 | "type string;" |
| 344 | "}" |
| 345 | "}" |
| 346 | "}" |
| 347 | "}"; |
Michal Vasko | cc048b2 | 2020-03-27 15:52:38 +0100 | [diff] [blame] | 348 | const char *schema_i = |
| 349 | "module i {" |
| 350 | "namespace urn:tests:i;" |
| 351 | "prefix i;" |
| 352 | "yang-version 1.1;" |
| 353 | |
| 354 | "container cont {" |
| 355 | "leaf l {" |
| 356 | "type string;" |
| 357 | "}" |
| 358 | "leaf l2 {" |
| 359 | "must \"../l = 'right'\";" |
| 360 | "type string;" |
| 361 | "}" |
| 362 | "}" |
| 363 | "}"; |
Michal Vasko | fea12c6 | 2020-03-30 11:00:15 +0200 | [diff] [blame] | 364 | const char *schema_j = |
| 365 | "module j {" |
| 366 | "namespace urn:tests:j;" |
| 367 | "prefix j;" |
| 368 | "yang-version 1.1;" |
| 369 | |
| 370 | "feature feat1;" |
| 371 | |
| 372 | "container cont {" |
| 373 | "must \"false()\";" |
| 374 | "list l1 {" |
| 375 | "key \"k\";" |
| 376 | "leaf k {" |
| 377 | "type string;" |
| 378 | "}" |
| 379 | "action act {" |
| 380 | "if-feature feat1;" |
| 381 | "input {" |
| 382 | "must \"../../lf1 = 'true'\";" |
| 383 | "leaf lf2 {" |
| 384 | "type leafref {" |
| 385 | "path /lf3;" |
| 386 | "}" |
| 387 | "}" |
| 388 | "}" |
Michal Vasko | cb7526d | 2020-03-30 15:08:26 +0200 | [diff] [blame] | 389 | "output {" |
| 390 | "must \"../../lf1 = 'true2'\";" |
| 391 | "leaf lf2 {" |
| 392 | "type leafref {" |
| 393 | "path /lf4;" |
| 394 | "}" |
| 395 | "}" |
| 396 | "}" |
Michal Vasko | fea12c6 | 2020-03-30 11:00:15 +0200 | [diff] [blame] | 397 | "}" |
| 398 | "}" |
| 399 | |
| 400 | "leaf lf1 {" |
| 401 | "type string;" |
| 402 | "}" |
| 403 | "}" |
| 404 | |
| 405 | "leaf lf3 {" |
| 406 | "type string;" |
| 407 | "}" |
Michal Vasko | cb7526d | 2020-03-30 15:08:26 +0200 | [diff] [blame] | 408 | |
| 409 | "leaf lf4 {" |
| 410 | "type string;" |
| 411 | "}" |
Michal Vasko | fea12c6 | 2020-03-30 11:00:15 +0200 | [diff] [blame] | 412 | "}"; |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 413 | |
| 414 | #if ENABLE_LOGGER_CHECKING |
| 415 | ly_set_log_clb(logger, 1); |
| 416 | #endif |
| 417 | |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 418 | assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &ctx)); |
| 419 | assert_non_null(ly_ctx_load_module(ctx, "ietf-netconf-with-defaults", "2011-06-01")); |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 420 | assert_non_null(lys_parse_mem(ctx, schema_a, LYS_IN_YANG)); |
Michal Vasko | a388136 | 2020-01-21 15:57:35 +0100 | [diff] [blame] | 421 | assert_non_null(lys_parse_mem(ctx, schema_b, LYS_IN_YANG)); |
Michal Vasko | acd83e7 | 2020-02-04 14:12:01 +0100 | [diff] [blame] | 422 | assert_non_null(lys_parse_mem(ctx, schema_c, LYS_IN_YANG)); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 423 | assert_non_null(lys_parse_mem(ctx, schema_d, LYS_IN_YANG)); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 424 | assert_non_null(lys_parse_mem(ctx, schema_e, LYS_IN_YANG)); |
| 425 | assert_non_null(lys_parse_mem(ctx, schema_f, LYS_IN_YANG)); |
Michal Vasko | c193ce9 | 2020-03-06 11:04:48 +0100 | [diff] [blame] | 426 | assert_non_null(lys_parse_mem(ctx, schema_g, LYS_IN_YANG)); |
Michal Vasko | 5b37a35 | 2020-03-06 13:38:33 +0100 | [diff] [blame] | 427 | assert_non_null(lys_parse_mem(ctx, schema_h, LYS_IN_YANG)); |
Michal Vasko | cc048b2 | 2020-03-27 15:52:38 +0100 | [diff] [blame] | 428 | assert_non_null(lys_parse_mem(ctx, schema_i, LYS_IN_YANG)); |
Michal Vasko | fea12c6 | 2020-03-30 11:00:15 +0200 | [diff] [blame] | 429 | assert_non_null(lys_parse_mem(ctx, schema_j, LYS_IN_YANG)); |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 430 | |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | static int |
| 435 | teardown(void **state) |
| 436 | { |
Michal Vasko | acd83e7 | 2020-02-04 14:12:01 +0100 | [diff] [blame] | 437 | (void)state; |
| 438 | ly_ctx_destroy(ctx, NULL); |
| 439 | ctx = NULL; |
| 440 | |
| 441 | return 0; |
| 442 | } |
| 443 | |
| 444 | static int |
| 445 | teardown_s(void **state) |
| 446 | { |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 447 | #if ENABLE_LOGGER_CHECKING |
| 448 | if (*state) { |
| 449 | fprintf(stderr, "%s\n", logbuf); |
| 450 | } |
| 451 | #else |
| 452 | (void) state; /* unused */ |
| 453 | #endif |
| 454 | |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | void |
| 459 | logbuf_clean(void) |
| 460 | { |
| 461 | logbuf[0] = '\0'; |
| 462 | } |
| 463 | |
| 464 | #if ENABLE_LOGGER_CHECKING |
| 465 | # define logbuf_assert(str) assert_string_equal(logbuf, str) |
| 466 | #else |
| 467 | # define logbuf_assert(str) |
| 468 | #endif |
| 469 | |
| 470 | static void |
| 471 | test_when(void **state) |
| 472 | { |
| 473 | *state = test_when; |
| 474 | |
| 475 | const char *data; |
| 476 | struct lyd_node *tree; |
| 477 | |
| 478 | data = "<c xmlns=\"urn:tests:a\">hey</c>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 479 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 480 | assert_null(tree); |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 481 | logbuf_assert("When condition \"/cont/b = 'val_b'\" not satisfied. /a:c"); |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 482 | |
| 483 | data = "<cont xmlns=\"urn:tests:a\"><b>val_b</b></cont><c xmlns=\"urn:tests:a\">hey</c>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 484 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 485 | assert_non_null(tree); |
| 486 | assert_string_equal("c", tree->next->schema->name); |
| 487 | assert_int_equal(LYD_WHEN_TRUE, tree->next->flags); |
| 488 | lyd_free_all(tree); |
| 489 | |
| 490 | data = "<cont xmlns=\"urn:tests:a\"><a>val</a><b>val_b</b></cont><c xmlns=\"urn:tests:a\">val_c</c>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 491 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 492 | assert_non_null(tree); |
| 493 | assert_string_equal("a", lyd_node_children(tree)->schema->name); |
| 494 | assert_int_equal(LYD_WHEN_TRUE, lyd_node_children(tree)->flags); |
| 495 | assert_string_equal("c", tree->next->schema->name); |
| 496 | assert_int_equal(LYD_WHEN_TRUE, tree->next->flags); |
| 497 | lyd_free_all(tree); |
| 498 | |
| 499 | *state = NULL; |
| 500 | } |
| 501 | |
Michal Vasko | a388136 | 2020-01-21 15:57:35 +0100 | [diff] [blame] | 502 | static void |
| 503 | test_mandatory(void **state) |
| 504 | { |
| 505 | *state = test_mandatory; |
| 506 | |
| 507 | const char *data; |
| 508 | struct lyd_node *tree; |
| 509 | |
| 510 | data = "<d xmlns=\"urn:tests:b\"/>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 511 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | a388136 | 2020-01-21 15:57:35 +0100 | [diff] [blame] | 512 | assert_null(tree); |
| 513 | logbuf_assert("Mandatory node \"choic\" instance does not exist. /b:choic"); |
| 514 | |
| 515 | data = "<l xmlns=\"urn:tests:b\">string</l><d xmlns=\"urn:tests:b\"/>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 516 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | a388136 | 2020-01-21 15:57:35 +0100 | [diff] [blame] | 517 | assert_null(tree); |
| 518 | logbuf_assert("Mandatory node \"c\" instance does not exist. /b:c"); |
| 519 | |
| 520 | data = "<a xmlns=\"urn:tests:b\">string</a>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 521 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | a388136 | 2020-01-21 15:57:35 +0100 | [diff] [blame] | 522 | assert_null(tree); |
| 523 | logbuf_assert("Mandatory node \"c\" instance does not exist. /b:c"); |
| 524 | |
| 525 | data = "<a xmlns=\"urn:tests:b\">string</a><c xmlns=\"urn:tests:b\">string2</c>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 526 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | a388136 | 2020-01-21 15:57:35 +0100 | [diff] [blame] | 527 | assert_non_null(tree); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 528 | lyd_free_siblings(tree); |
Michal Vasko | a388136 | 2020-01-21 15:57:35 +0100 | [diff] [blame] | 529 | |
| 530 | *state = NULL; |
| 531 | } |
| 532 | |
Michal Vasko | acd83e7 | 2020-02-04 14:12:01 +0100 | [diff] [blame] | 533 | static void |
| 534 | test_minmax(void **state) |
| 535 | { |
| 536 | *state = test_minmax; |
| 537 | |
| 538 | const char *data; |
| 539 | struct lyd_node *tree; |
| 540 | |
| 541 | data = "<d xmlns=\"urn:tests:c\"/>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 542 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | acd83e7 | 2020-02-04 14:12:01 +0100 | [diff] [blame] | 543 | assert_null(tree); |
| 544 | logbuf_assert("Too few \"l\" instances. /c:choic/b/l"); |
| 545 | |
| 546 | data = |
| 547 | "<l xmlns=\"urn:tests:c\">val1</l>" |
| 548 | "<l xmlns=\"urn:tests:c\">val2</l>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 549 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | acd83e7 | 2020-02-04 14:12:01 +0100 | [diff] [blame] | 550 | assert_null(tree); |
| 551 | logbuf_assert("Too few \"l\" instances. /c:choic/b/l"); |
| 552 | |
| 553 | data = |
| 554 | "<l xmlns=\"urn:tests:c\">val1</l>" |
| 555 | "<l xmlns=\"urn:tests:c\">val2</l>" |
| 556 | "<l xmlns=\"urn:tests:c\">val3</l>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 557 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | acd83e7 | 2020-02-04 14:12:01 +0100 | [diff] [blame] | 558 | assert_non_null(tree); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 559 | lyd_free_siblings(tree); |
Michal Vasko | acd83e7 | 2020-02-04 14:12:01 +0100 | [diff] [blame] | 560 | |
| 561 | data = |
| 562 | "<l xmlns=\"urn:tests:c\">val1</l>" |
| 563 | "<l xmlns=\"urn:tests:c\">val2</l>" |
| 564 | "<l xmlns=\"urn:tests:c\">val3</l>" |
| 565 | "<lt xmlns=\"urn:tests:c\"><k>val1</k></lt>" |
| 566 | "<lt xmlns=\"urn:tests:c\"><k>val2</k></lt>" |
| 567 | "<lt xmlns=\"urn:tests:c\"><k>val3</k></lt>" |
| 568 | "<lt xmlns=\"urn:tests:c\"><k>val4</k></lt>" |
| 569 | "<lt xmlns=\"urn:tests:c\"><k>val5</k></lt>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 570 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | acd83e7 | 2020-02-04 14:12:01 +0100 | [diff] [blame] | 571 | assert_null(tree); |
| 572 | logbuf_assert("Too many \"lt\" instances. /c:lt"); |
| 573 | |
| 574 | *state = NULL; |
| 575 | } |
| 576 | |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 577 | static void |
| 578 | test_unique(void **state) |
| 579 | { |
| 580 | *state = test_unique; |
| 581 | |
| 582 | const char *data; |
| 583 | struct lyd_node *tree; |
| 584 | |
| 585 | data = |
| 586 | "<lt xmlns=\"urn:tests:d\">" |
| 587 | "<k>val1</k>" |
| 588 | "<l1>same</l1>" |
| 589 | "</lt>" |
| 590 | "<lt xmlns=\"urn:tests:d\">" |
| 591 | "<k>val2</k>" |
| 592 | "</lt>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 593 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 594 | assert_non_null(tree); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 595 | lyd_free_siblings(tree); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 596 | |
| 597 | data = |
| 598 | "<lt xmlns=\"urn:tests:d\">" |
| 599 | "<k>val1</k>" |
| 600 | "<l1>same</l1>" |
| 601 | "</lt>" |
| 602 | "<lt xmlns=\"urn:tests:d\">" |
| 603 | "<k>val2</k>" |
| 604 | "<l1>not-same</l1>" |
| 605 | "</lt>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 606 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 607 | assert_non_null(tree); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 608 | lyd_free_siblings(tree); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 609 | |
| 610 | data = |
| 611 | "<lt xmlns=\"urn:tests:d\">" |
| 612 | "<k>val1</k>" |
| 613 | "<l1>same</l1>" |
| 614 | "</lt>" |
| 615 | "<lt xmlns=\"urn:tests:d\">" |
| 616 | "<k>val2</k>" |
| 617 | "<l1>same</l1>" |
| 618 | "</lt>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 619 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 620 | assert_null(tree); |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 621 | logbuf_assert("Unique data leaf(s) \"l1\" not satisfied in \"/d:lt[k='val1']\" and \"/d:lt[k='val2']\". /d:lt[k='val2']"); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 622 | |
| 623 | /* now try with more instances */ |
| 624 | data = |
| 625 | "<lt xmlns=\"urn:tests:d\">" |
| 626 | "<k>val1</k>" |
| 627 | "<l1>1</l1>" |
| 628 | "</lt>" |
| 629 | "<lt xmlns=\"urn:tests:d\">" |
| 630 | "<k>val2</k>" |
| 631 | "<l1>2</l1>" |
| 632 | "</lt>" |
| 633 | "<lt xmlns=\"urn:tests:d\">" |
| 634 | "<k>val3</k>" |
| 635 | "<l1>3</l1>" |
| 636 | "</lt>" |
| 637 | "<lt xmlns=\"urn:tests:d\">" |
| 638 | "<k>val4</k>" |
| 639 | "<l1>4</l1>" |
| 640 | "</lt>" |
| 641 | "<lt xmlns=\"urn:tests:d\">" |
| 642 | "<k>val5</k>" |
| 643 | "<l1>5</l1>" |
| 644 | "</lt>" |
| 645 | "<lt xmlns=\"urn:tests:d\">" |
| 646 | "<k>val6</k>" |
| 647 | "<l1>6</l1>" |
| 648 | "</lt>" |
| 649 | "<lt xmlns=\"urn:tests:d\">" |
| 650 | "<k>val7</k>" |
| 651 | "<l1>7</l1>" |
| 652 | "</lt>" |
| 653 | "<lt xmlns=\"urn:tests:d\">" |
| 654 | "<k>val8</k>" |
| 655 | "<l1>8</l1>" |
| 656 | "</lt>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 657 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 658 | assert_non_null(tree); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 659 | lyd_free_siblings(tree); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 660 | |
| 661 | data = |
| 662 | "<lt xmlns=\"urn:tests:d\">" |
| 663 | "<k>val1</k>" |
| 664 | "<l1>1</l1>" |
| 665 | "</lt>" |
| 666 | "<lt xmlns=\"urn:tests:d\">" |
| 667 | "<k>val2</k>" |
| 668 | "<l1>2</l1>" |
| 669 | "</lt>" |
| 670 | "<lt xmlns=\"urn:tests:d\">" |
| 671 | "<k>val3</k>" |
| 672 | "<l1>3</l1>" |
| 673 | "</lt>" |
| 674 | "<lt xmlns=\"urn:tests:d\">" |
| 675 | "<k>val4</k>" |
| 676 | "</lt>" |
| 677 | "<lt xmlns=\"urn:tests:d\">" |
| 678 | "<k>val5</k>" |
| 679 | "<l1>5</l1>" |
| 680 | "</lt>" |
| 681 | "<lt xmlns=\"urn:tests:d\">" |
| 682 | "<k>val6</k>" |
| 683 | "<l1>6</l1>" |
| 684 | "</lt>" |
| 685 | "<lt xmlns=\"urn:tests:d\">" |
| 686 | "<k>val7</k>" |
| 687 | "</lt>" |
| 688 | "<lt xmlns=\"urn:tests:d\">" |
| 689 | "<k>val8</k>" |
| 690 | "</lt>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 691 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 692 | assert_non_null(tree); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 693 | lyd_free_siblings(tree); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 694 | |
| 695 | data = |
| 696 | "<lt xmlns=\"urn:tests:d\">" |
| 697 | "<k>val1</k>" |
| 698 | "<l1>1</l1>" |
| 699 | "</lt>" |
| 700 | "<lt xmlns=\"urn:tests:d\">" |
| 701 | "<k>val2</k>" |
| 702 | "<l1>2</l1>" |
| 703 | "</lt>" |
| 704 | "<lt xmlns=\"urn:tests:d\">" |
| 705 | "<k>val3</k>" |
| 706 | "</lt>" |
| 707 | "<lt xmlns=\"urn:tests:d\">" |
| 708 | "<k>val4</k>" |
| 709 | "<l1>4</l1>" |
| 710 | "</lt>" |
| 711 | "<lt xmlns=\"urn:tests:d\">" |
| 712 | "<k>val5</k>" |
| 713 | "</lt>" |
| 714 | "<lt xmlns=\"urn:tests:d\">" |
| 715 | "<k>val6</k>" |
| 716 | "</lt>" |
| 717 | "<lt xmlns=\"urn:tests:d\">" |
| 718 | "<k>val7</k>" |
| 719 | "<l1>2</l1>" |
| 720 | "</lt>" |
| 721 | "<lt xmlns=\"urn:tests:d\">" |
| 722 | "<k>val8</k>" |
| 723 | "<l1>8</l1>" |
| 724 | "</lt>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 725 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 726 | assert_null(tree); |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 727 | logbuf_assert("Unique data leaf(s) \"l1\" not satisfied in \"/d:lt[k='val7']\" and \"/d:lt[k='val2']\". /d:lt[k='val2']"); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 728 | |
| 729 | *state = NULL; |
| 730 | } |
| 731 | |
| 732 | static void |
| 733 | test_unique_nested(void **state) |
| 734 | { |
| 735 | *state = test_unique_nested; |
| 736 | |
| 737 | const char *data; |
| 738 | struct lyd_node *tree; |
| 739 | |
| 740 | /* nested list uniquest are compared only with instances in the same parent list instance */ |
| 741 | data = |
| 742 | "<lt2 xmlns=\"urn:tests:d\">" |
| 743 | "<k>val1</k>" |
| 744 | "<cont>" |
| 745 | "<l2>1</l2>" |
| 746 | "</cont>" |
| 747 | "<l4>1</l4>" |
| 748 | "</lt2>" |
| 749 | "<lt2 xmlns=\"urn:tests:d\">" |
| 750 | "<k>val2</k>" |
| 751 | "<cont>" |
| 752 | "<l2>2</l2>" |
| 753 | "</cont>" |
| 754 | "<l4>2</l4>" |
| 755 | "<lt3>" |
| 756 | "<kk>val1</kk>" |
| 757 | "<l3>1</l3>" |
| 758 | "</lt3>" |
| 759 | "<lt3>" |
| 760 | "<kk>val2</kk>" |
| 761 | "<l3>2</l3>" |
| 762 | "</lt3>" |
| 763 | "</lt2>" |
| 764 | "<lt2 xmlns=\"urn:tests:d\">" |
| 765 | "<k>val3</k>" |
| 766 | "<cont>" |
| 767 | "<l2>3</l2>" |
| 768 | "</cont>" |
| 769 | "<l4>3</l4>" |
| 770 | "<lt3>" |
| 771 | "<kk>val1</kk>" |
| 772 | "<l3>2</l3>" |
| 773 | "</lt3>" |
| 774 | "</lt2>" |
| 775 | "<lt2 xmlns=\"urn:tests:d\">" |
| 776 | "<k>val4</k>" |
| 777 | "<cont>" |
| 778 | "<l2>4</l2>" |
| 779 | "</cont>" |
| 780 | "<l4>4</l4>" |
| 781 | "<lt3>" |
| 782 | "<kk>val1</kk>" |
| 783 | "<l3>3</l3>" |
| 784 | "</lt3>" |
| 785 | "</lt2>" |
| 786 | "<lt2 xmlns=\"urn:tests:d\">" |
| 787 | "<k>val5</k>" |
| 788 | "<cont>" |
| 789 | "<l2>5</l2>" |
| 790 | "</cont>" |
| 791 | "<l4>5</l4>" |
| 792 | "<lt3>" |
| 793 | "<kk>val1</kk>" |
| 794 | "<l3>3</l3>" |
| 795 | "</lt3>" |
| 796 | "</lt2>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 797 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY | LYD_OPT_STRICT, &tree)); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 798 | assert_non_null(tree); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 799 | lyd_free_siblings(tree); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 800 | |
| 801 | data = |
| 802 | "<lt2 xmlns=\"urn:tests:d\">" |
| 803 | "<k>val1</k>" |
| 804 | "<cont>" |
| 805 | "<l2>1</l2>" |
| 806 | "</cont>" |
| 807 | "<l4>1</l4>" |
| 808 | "</lt2>" |
| 809 | "<lt2 xmlns=\"urn:tests:d\">" |
| 810 | "<k>val2</k>" |
| 811 | "<cont>" |
| 812 | "<l2>2</l2>" |
| 813 | "</cont>" |
| 814 | "<lt3>" |
| 815 | "<kk>val1</kk>" |
| 816 | "<l3>1</l3>" |
| 817 | "</lt3>" |
| 818 | "<lt3>" |
| 819 | "<kk>val2</kk>" |
| 820 | "<l3>2</l3>" |
| 821 | "</lt3>" |
| 822 | "<lt3>" |
| 823 | "<kk>val3</kk>" |
| 824 | "<l3>1</l3>" |
| 825 | "</lt3>" |
| 826 | "</lt2>" |
| 827 | "<lt2 xmlns=\"urn:tests:d\">" |
| 828 | "<k>val3</k>" |
| 829 | "<cont>" |
| 830 | "<l2>3</l2>" |
| 831 | "</cont>" |
| 832 | "<l4>1</l4>" |
| 833 | "<lt3>" |
| 834 | "<kk>val1</kk>" |
| 835 | "<l3>2</l3>" |
| 836 | "</lt3>" |
| 837 | "</lt2>" |
| 838 | "<lt2 xmlns=\"urn:tests:d\">" |
| 839 | "<k>val4</k>" |
| 840 | "<cont>" |
| 841 | "<l2>4</l2>" |
| 842 | "</cont>" |
| 843 | "<lt3>" |
| 844 | "<kk>val1</kk>" |
| 845 | "<l3>3</l3>" |
| 846 | "</lt3>" |
| 847 | "</lt2>" |
| 848 | "<lt2 xmlns=\"urn:tests:d\">" |
| 849 | "<k>val5</k>" |
| 850 | "<cont>" |
| 851 | "<l2>5</l2>" |
| 852 | "</cont>" |
| 853 | "<lt3>" |
| 854 | "<kk>val1</kk>" |
| 855 | "<l3>3</l3>" |
| 856 | "</lt3>" |
| 857 | "</lt2>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 858 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 859 | assert_null(tree); |
| 860 | logbuf_assert("Unique data leaf(s) \"l3\" not satisfied in \"/d:lt2[k='val2']/lt3[kk='val3']\" and" |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 861 | " \"/d:lt2[k='val2']/lt3[kk='val1']\". /d:lt2[k='val2']/lt3[kk='val1']"); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 862 | |
| 863 | data = |
| 864 | "<lt2 xmlns=\"urn:tests:d\">" |
| 865 | "<k>val1</k>" |
| 866 | "<cont>" |
| 867 | "<l2>1</l2>" |
| 868 | "</cont>" |
| 869 | "<l4>1</l4>" |
| 870 | "</lt2>" |
| 871 | "<lt2 xmlns=\"urn:tests:d\">" |
| 872 | "<k>val2</k>" |
| 873 | "<cont>" |
| 874 | "<l2>2</l2>" |
| 875 | "</cont>" |
| 876 | "<l4>2</l4>" |
| 877 | "</lt2>" |
| 878 | "<lt2 xmlns=\"urn:tests:d\">" |
| 879 | "<k>val3</k>" |
| 880 | "<cont>" |
| 881 | "<l2>3</l2>" |
| 882 | "</cont>" |
| 883 | "<l4>3</l4>" |
| 884 | "</lt2>" |
| 885 | "<lt2 xmlns=\"urn:tests:d\">" |
| 886 | "<k>val4</k>" |
| 887 | "<cont>" |
| 888 | "<l2>2</l2>" |
| 889 | "</cont>" |
| 890 | "<l4>2</l4>" |
| 891 | "</lt2>" |
| 892 | "<lt2 xmlns=\"urn:tests:d\">" |
| 893 | "<k>val5</k>" |
| 894 | "<cont>" |
| 895 | "<l2>5</l2>" |
| 896 | "</cont>" |
| 897 | "<l4>5</l4>" |
| 898 | "</lt2>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 899 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 900 | assert_null(tree); |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 901 | 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 Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 902 | |
| 903 | data = |
| 904 | "<lt2 xmlns=\"urn:tests:d\">" |
| 905 | "<k>val1</k>" |
| 906 | "<cont>" |
| 907 | "<l2>1</l2>" |
| 908 | "</cont>" |
| 909 | "<l4>1</l4>" |
| 910 | "<l5>1</l5>" |
| 911 | "<l6>1</l6>" |
| 912 | "</lt2>" |
| 913 | "<lt2 xmlns=\"urn:tests:d\">" |
| 914 | "<k>val2</k>" |
| 915 | "<cont>" |
| 916 | "<l2>2</l2>" |
| 917 | "</cont>" |
| 918 | "<l4>1</l4>" |
| 919 | "<l5>1</l5>" |
| 920 | "</lt2>" |
| 921 | "<lt2 xmlns=\"urn:tests:d\">" |
| 922 | "<k>val3</k>" |
| 923 | "<cont>" |
| 924 | "<l2>3</l2>" |
| 925 | "</cont>" |
| 926 | "<l4>1</l4>" |
| 927 | "<l5>3</l5>" |
| 928 | "<l6>3</l6>" |
| 929 | "</lt2>" |
| 930 | "<lt2 xmlns=\"urn:tests:d\">" |
| 931 | "<k>val4</k>" |
| 932 | "<cont>" |
| 933 | "<l2>4</l2>" |
| 934 | "</cont>" |
| 935 | "<l4>1</l4>" |
| 936 | "<l6>1</l6>" |
| 937 | "</lt2>" |
| 938 | "<lt2 xmlns=\"urn:tests:d\">" |
| 939 | "<k>val5</k>" |
| 940 | "<cont>" |
| 941 | "<l2>5</l2>" |
| 942 | "</cont>" |
| 943 | "<l4>1</l4>" |
| 944 | "<l5>3</l5>" |
| 945 | "<l6>3</l6>" |
| 946 | "</lt2>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 947 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 948 | assert_null(tree); |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 949 | 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 Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 950 | |
| 951 | *state = NULL; |
| 952 | } |
| 953 | |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 954 | static void |
| 955 | test_dup(void **state) |
| 956 | { |
| 957 | *state = test_dup; |
| 958 | |
| 959 | const char *data; |
| 960 | struct lyd_node *tree; |
| 961 | |
| 962 | data = "<d xmlns=\"urn:tests:e\">25</d><d xmlns=\"urn:tests:e\">50</d>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 963 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 964 | assert_null(tree); |
| 965 | logbuf_assert("Duplicate instance of \"d\". /e:d"); |
| 966 | |
| 967 | 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 Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 968 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 969 | assert_null(tree); |
| 970 | logbuf_assert("Duplicate instance of \"lt\". /e:lt[k='A']"); |
| 971 | |
| 972 | data = "<ll xmlns=\"urn:tests:e\">A</ll><ll xmlns=\"urn:tests:e\">B</ll><ll xmlns=\"urn:tests:e\">B</ll>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 973 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 974 | assert_null(tree); |
| 975 | logbuf_assert("Duplicate instance of \"ll\". /e:ll[.='B']"); |
| 976 | |
| 977 | data = "<cont xmlns=\"urn:tests:e\"></cont><cont xmlns=\"urn:tests:e\"/>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 978 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 979 | assert_null(tree); |
| 980 | logbuf_assert("Duplicate instance of \"cont\". /e:cont"); |
| 981 | |
| 982 | /* same tests again but using hashes */ |
| 983 | 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 Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 984 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 985 | assert_null(tree); |
| 986 | logbuf_assert("Duplicate instance of \"d\". /e:cont/d"); |
| 987 | |
| 988 | data = "<cont xmlns=\"urn:tests:e\"><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll>" |
| 989 | "<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 Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 990 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 991 | assert_null(tree); |
| 992 | logbuf_assert("Duplicate instance of \"lt\". /e:cont/lt[k='c']"); |
| 993 | |
| 994 | data = "<cont xmlns=\"urn:tests:e\"><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll>" |
| 995 | "<ll>a</ll><ll>b</ll><ll>c</ll><ll>d</ll><ll>d</ll></cont>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 996 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 997 | assert_null(tree); |
| 998 | logbuf_assert("Duplicate instance of \"ll\". /e:cont/ll[.='d']"); |
| 999 | |
| 1000 | /* cases */ |
| 1001 | 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 Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 1002 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1003 | assert_null(tree); |
| 1004 | logbuf_assert("Duplicate instance of \"l\". /e:l[.='b']"); |
| 1005 | |
| 1006 | 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 Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 1007 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1008 | assert_null(tree); |
| 1009 | logbuf_assert("Data for both cases \"a\" and \"b\" exist. /e:choic"); |
| 1010 | |
| 1011 | *state = NULL; |
| 1012 | } |
| 1013 | |
| 1014 | static void |
| 1015 | test_defaults(void **state) |
| 1016 | { |
| 1017 | *state = test_defaults; |
| 1018 | |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1019 | char *str; |
| 1020 | struct lyd_node *tree, *node; |
| 1021 | const struct lys_module *mod = ly_ctx_get_module_latest(ctx, "f"); |
| 1022 | |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 1023 | struct ly_out *out; |
| 1024 | assert_non_null(out = ly_out_new_memory(&str, 0)); |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 1025 | |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 1026 | /* get defaults */ |
| 1027 | tree = NULL; |
| 1028 | assert_int_equal(lyd_validate_modules(&tree, &mod, 1, 0), LY_SUCCESS); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1029 | assert_non_null(tree); |
| 1030 | |
| 1031 | /* check all defaults exist */ |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 1032 | lyd_print(out, tree, LYD_XML, LYDP_WITHSIBLINGS | LYDP_WD_IMPL_TAG); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1033 | assert_string_equal(str, |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1034 | "<ll1 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>" |
| 1035 | "<ll1 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>" |
| 1036 | "<ll1 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>" |
| 1037 | "<d xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>" |
| 1038 | "<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>" |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 1039 | "<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>" |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 1040 | "<cont xmlns=\"urn:tests:f\">" |
| 1041 | "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>" |
| 1042 | "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>" |
| 1043 | "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>" |
| 1044 | "<d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>" |
| 1045 | "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>" |
| 1046 | "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>" |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 1047 | "</cont>"); |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 1048 | ly_out_reset(out); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1049 | |
| 1050 | /* create another explicit case and validate */ |
| 1051 | node = lyd_new_term(NULL, mod, "l", "value"); |
| 1052 | assert_non_null(node); |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 1053 | assert_int_equal(lyd_insert_sibling(tree, node), LY_SUCCESS); |
| 1054 | assert_int_equal(lyd_validate(&tree, ctx, LYD_VALOPT_DATA_ONLY), LY_SUCCESS); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1055 | |
| 1056 | /* check data tree */ |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 1057 | lyd_print(out, tree, LYD_XML, LYDP_WITHSIBLINGS | LYDP_WD_IMPL_TAG); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1058 | assert_string_equal(str, |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 1059 | "<d xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>" |
| 1060 | "<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>" |
| 1061 | "<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>" |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 1062 | "<cont xmlns=\"urn:tests:f\">" |
| 1063 | "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>" |
| 1064 | "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>" |
| 1065 | "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>" |
| 1066 | "<d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>" |
| 1067 | "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>" |
| 1068 | "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>" |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1069 | "</cont>" |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1070 | "<l xmlns=\"urn:tests:f\">value</l>"); |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 1071 | ly_out_reset(out); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1072 | |
| 1073 | /* create explicit leaf-list and leaf and validate */ |
| 1074 | node = lyd_new_term(NULL, mod, "d", "15"); |
| 1075 | assert_non_null(node); |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 1076 | assert_int_equal(lyd_insert_sibling(tree, node), LY_SUCCESS); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1077 | node = lyd_new_term(NULL, mod, "ll2", "dflt2"); |
| 1078 | assert_non_null(node); |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 1079 | assert_int_equal(lyd_insert_sibling(tree, node), LY_SUCCESS); |
| 1080 | assert_int_equal(lyd_validate(&tree, ctx, LYD_VALOPT_DATA_ONLY), LY_SUCCESS); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1081 | |
| 1082 | /* check data tree */ |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 1083 | lyd_print(out, tree, LYD_XML, LYDP_WITHSIBLINGS | LYDP_WD_IMPL_TAG); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1084 | assert_string_equal(str, |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 1085 | "<cont xmlns=\"urn:tests:f\">" |
| 1086 | "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>" |
| 1087 | "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>" |
| 1088 | "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>" |
| 1089 | "<d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>" |
| 1090 | "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>" |
| 1091 | "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>" |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1092 | "</cont>" |
| 1093 | "<l xmlns=\"urn:tests:f\">value</l>" |
| 1094 | "<d xmlns=\"urn:tests:f\">15</d>" |
| 1095 | "<ll2 xmlns=\"urn:tests:f\">dflt2</ll2>"); |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 1096 | ly_out_reset(out); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1097 | |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 1098 | /* create first explicit container, which should become implicit */ |
| 1099 | node = lyd_new_inner(NULL, mod, "cont"); |
| 1100 | assert_non_null(node); |
| 1101 | assert_int_equal(lyd_insert_before(tree, node), LY_SUCCESS); |
| 1102 | tree = tree->prev; |
| 1103 | assert_int_equal(lyd_validate(&tree, ctx, LYD_VALOPT_DATA_ONLY), LY_SUCCESS); |
| 1104 | |
| 1105 | /* check data tree */ |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 1106 | lyd_print(out, tree, LYD_XML, LYDP_WITHSIBLINGS | LYDP_WD_IMPL_TAG); |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 1107 | assert_string_equal(str, |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 1108 | "<cont xmlns=\"urn:tests:f\">" |
| 1109 | "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>" |
| 1110 | "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>" |
| 1111 | "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>" |
| 1112 | "<d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>" |
| 1113 | "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>" |
| 1114 | "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>" |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 1115 | "</cont>" |
| 1116 | "<l xmlns=\"urn:tests:f\">value</l>" |
| 1117 | "<d xmlns=\"urn:tests:f\">15</d>" |
| 1118 | "<ll2 xmlns=\"urn:tests:f\">dflt2</ll2>"); |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 1119 | ly_out_reset(out); |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 1120 | |
| 1121 | /* create second explicit container, which should become implicit, so the first tree node should be removed */ |
| 1122 | node = lyd_new_inner(NULL, mod, "cont"); |
| 1123 | assert_non_null(node); |
| 1124 | assert_int_equal(lyd_insert_after(tree, node), LY_SUCCESS); |
| 1125 | assert_int_equal(lyd_validate(&tree, ctx, LYD_VALOPT_DATA_ONLY), LY_SUCCESS); |
| 1126 | |
| 1127 | /* check data tree */ |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 1128 | lyd_print(out, tree, LYD_XML, LYDP_WITHSIBLINGS | LYDP_WD_IMPL_TAG); |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 1129 | assert_string_equal(str, |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 1130 | "<cont xmlns=\"urn:tests:f\">" |
| 1131 | "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>" |
| 1132 | "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>" |
| 1133 | "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>" |
| 1134 | "<d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>" |
| 1135 | "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>" |
| 1136 | "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>" |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 1137 | "</cont>" |
| 1138 | "<l xmlns=\"urn:tests:f\">value</l>" |
| 1139 | "<d xmlns=\"urn:tests:f\">15</d>" |
| 1140 | "<ll2 xmlns=\"urn:tests:f\">dflt2</ll2>"); |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 1141 | ly_out_reset(out); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1142 | |
| 1143 | /* similar changes for nested defaults */ |
| 1144 | assert_non_null(lyd_new_term(tree, NULL, "ll1", "def3")); |
| 1145 | assert_non_null(lyd_new_term(tree, NULL, "d", "5")); |
| 1146 | assert_non_null(lyd_new_term(tree, NULL, "ll2", "non-dflt")); |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 1147 | assert_int_equal(lyd_validate(&tree, ctx, LYD_VALOPT_DATA_ONLY), LY_SUCCESS); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1148 | |
| 1149 | /* check data tree */ |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 1150 | lyd_print(out, tree, LYD_XML, LYDP_WITHSIBLINGS | LYDP_WD_IMPL_TAG); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1151 | assert_string_equal(str, |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 1152 | "<cont xmlns=\"urn:tests:f\">" |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1153 | "<ll1>def3</ll1>" |
| 1154 | "<d>5</d>" |
| 1155 | "<ll2>non-dflt</ll2>" |
| 1156 | "</cont>" |
| 1157 | "<l xmlns=\"urn:tests:f\">value</l>" |
| 1158 | "<d xmlns=\"urn:tests:f\">15</d>" |
| 1159 | "<ll2 xmlns=\"urn:tests:f\">dflt2</ll2>"); |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 1160 | ly_out_reset(out); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1161 | |
| 1162 | lyd_free_siblings(tree); |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 1163 | ly_out_free(out, NULL, 1); |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1164 | |
| 1165 | *state = NULL; |
| 1166 | } |
| 1167 | |
Michal Vasko | c193ce9 | 2020-03-06 11:04:48 +0100 | [diff] [blame] | 1168 | static void |
| 1169 | test_iffeature(void **state) |
| 1170 | { |
| 1171 | *state = test_iffeature; |
| 1172 | |
| 1173 | const char *data; |
| 1174 | struct lyd_node *tree; |
| 1175 | const struct lys_module *mod = ly_ctx_get_module_latest(ctx, "g"); |
| 1176 | |
| 1177 | /* get empty data */ |
| 1178 | tree = NULL; |
| 1179 | assert_int_equal(lyd_validate_modules(&tree, &mod, 1, 0), LY_SUCCESS); |
| 1180 | assert_null(tree); |
| 1181 | |
| 1182 | /* disabled by f1 */ |
| 1183 | data = |
| 1184 | "<cont xmlns=\"urn:tests:g\">" |
| 1185 | "<d>51</d>" |
| 1186 | "</cont>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 1187 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | c193ce9 | 2020-03-06 11:04:48 +0100 | [diff] [blame] | 1188 | assert_null(tree); |
| 1189 | logbuf_assert("Data are disabled by \"cont\" schema node if-feature. /g:cont"); |
| 1190 | |
| 1191 | /* enable f1 */ |
| 1192 | assert_int_equal(lys_feature_enable(mod, "f1"), LY_SUCCESS); |
| 1193 | |
| 1194 | /* get data with default container */ |
| 1195 | assert_int_equal(lyd_validate_modules(&tree, &mod, 1, 0), LY_SUCCESS); |
| 1196 | assert_non_null(tree); |
| 1197 | lyd_free_siblings(tree); |
| 1198 | |
| 1199 | /* disabled by f2 */ |
| 1200 | data = |
| 1201 | "<cont xmlns=\"urn:tests:g\">" |
| 1202 | "<cont2>" |
| 1203 | "<e>val</e>" |
| 1204 | "</cont2>" |
| 1205 | "</cont>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 1206 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | c193ce9 | 2020-03-06 11:04:48 +0100 | [diff] [blame] | 1207 | assert_null(tree); |
| 1208 | logbuf_assert("Data are disabled by \"cont2\" schema node if-feature. /g:cont/cont2"); |
| 1209 | |
| 1210 | data = |
| 1211 | "<cont xmlns=\"urn:tests:g\">" |
| 1212 | "<a>val</a>" |
| 1213 | "</cont>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 1214 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | c193ce9 | 2020-03-06 11:04:48 +0100 | [diff] [blame] | 1215 | assert_null(tree); |
| 1216 | logbuf_assert("Data are disabled by \"choic\" schema node if-feature. /g:cont/a"); |
| 1217 | |
| 1218 | /* enable f3 */ |
| 1219 | assert_int_equal(lys_feature_enable(mod, "f3"), LY_SUCCESS); |
| 1220 | |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 1221 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | c193ce9 | 2020-03-06 11:04:48 +0100 | [diff] [blame] | 1222 | assert_non_null(tree); |
| 1223 | lyd_free_siblings(tree); |
| 1224 | |
| 1225 | /* disabled by f2 */ |
| 1226 | data = |
| 1227 | "<cont xmlns=\"urn:tests:g\">" |
| 1228 | "<l>val</l>" |
| 1229 | "</cont>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 1230 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | c193ce9 | 2020-03-06 11:04:48 +0100 | [diff] [blame] | 1231 | assert_null(tree); |
| 1232 | logbuf_assert("Data are disabled by \"b\" schema node if-feature. /g:cont/l"); |
| 1233 | |
| 1234 | /* enable f2 */ |
| 1235 | assert_int_equal(lys_feature_enable(mod, "f2"), LY_SUCCESS); |
| 1236 | |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 1237 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
Michal Vasko | c193ce9 | 2020-03-06 11:04:48 +0100 | [diff] [blame] | 1238 | assert_non_null(tree); |
| 1239 | lyd_free_siblings(tree); |
| 1240 | |
| 1241 | /* try separate validation */ |
| 1242 | assert_int_equal(lys_feature_disable(mod, "f1"), LY_SUCCESS); |
| 1243 | assert_int_equal(lys_feature_disable(mod, "f2"), LY_SUCCESS); |
| 1244 | assert_int_equal(lys_feature_disable(mod, "f3"), LY_SUCCESS); |
| 1245 | |
| 1246 | data = |
| 1247 | "<cont xmlns=\"urn:tests:g\">" |
| 1248 | "<l>val</l>" |
| 1249 | "<d>51</d>" |
| 1250 | "<cont2>" |
| 1251 | "<e>val</e>" |
| 1252 | "</cont2>" |
| 1253 | "</cont>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 1254 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_OPT_PARSE_ONLY, &tree)); |
Michal Vasko | c193ce9 | 2020-03-06 11:04:48 +0100 | [diff] [blame] | 1255 | assert_non_null(tree); |
| 1256 | |
| 1257 | assert_int_equal(LY_EVALID, lyd_validate(&tree, NULL, LYD_VALOPT_DATA_ONLY)); |
| 1258 | logbuf_assert("Data are disabled by \"cont\" schema node if-feature. /g:cont"); |
| 1259 | |
| 1260 | assert_int_equal(lys_feature_enable(mod, "f1"), LY_SUCCESS); |
| 1261 | |
| 1262 | assert_int_equal(LY_EVALID, lyd_validate(&tree, NULL, LYD_VALOPT_DATA_ONLY)); |
| 1263 | logbuf_assert("Data are disabled by \"b\" schema node if-feature. /g:cont/l"); |
| 1264 | |
| 1265 | assert_int_equal(lys_feature_enable(mod, "f2"), LY_SUCCESS); |
| 1266 | |
| 1267 | assert_int_equal(LY_SUCCESS, lyd_validate(&tree, NULL, LYD_VALOPT_DATA_ONLY)); |
| 1268 | |
| 1269 | lyd_free_siblings(tree); |
| 1270 | |
| 1271 | *state = NULL; |
| 1272 | } |
| 1273 | |
Michal Vasko | 5b37a35 | 2020-03-06 13:38:33 +0100 | [diff] [blame] | 1274 | static void |
| 1275 | test_state(void **state) |
| 1276 | { |
Michal Vasko | cc048b2 | 2020-03-27 15:52:38 +0100 | [diff] [blame] | 1277 | *state = test_state; |
Michal Vasko | 5b37a35 | 2020-03-06 13:38:33 +0100 | [diff] [blame] | 1278 | |
| 1279 | const char *data; |
| 1280 | struct lyd_node *tree; |
| 1281 | |
| 1282 | data = |
| 1283 | "<cont xmlns=\"urn:tests:h\">" |
| 1284 | "<cont2>" |
| 1285 | "<l>val</l>" |
| 1286 | "</cont2>" |
| 1287 | "</cont>"; |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 1288 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_OPT_PARSE_ONLY | LYD_OPT_NO_STATE, &tree)); |
Michal Vasko | 5b37a35 | 2020-03-06 13:38:33 +0100 | [diff] [blame] | 1289 | assert_null(tree); |
| 1290 | logbuf_assert("Invalid state data node \"cont2\" found. Line number 1."); |
| 1291 | |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 1292 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY | LYD_VALOPT_NO_STATE, &tree)); |
Michal Vasko | 5b37a35 | 2020-03-06 13:38:33 +0100 | [diff] [blame] | 1293 | assert_null(tree); |
| 1294 | logbuf_assert("Invalid state data node \"cont2\" found. /h:cont/cont2"); |
| 1295 | |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 1296 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_OPT_PARSE_ONLY, &tree)); |
Michal Vasko | 5b37a35 | 2020-03-06 13:38:33 +0100 | [diff] [blame] | 1297 | assert_non_null(tree); |
| 1298 | |
| 1299 | assert_int_equal(LY_EVALID, lyd_validate(&tree, NULL, LYD_VALOPT_DATA_ONLY | LYD_VALOPT_NO_STATE)); |
| 1300 | logbuf_assert("Invalid state data node \"cont2\" found. /h:cont/cont2"); |
| 1301 | |
| 1302 | lyd_free_siblings(tree); |
| 1303 | |
| 1304 | *state = NULL; |
| 1305 | } |
| 1306 | |
Michal Vasko | cc048b2 | 2020-03-27 15:52:38 +0100 | [diff] [blame] | 1307 | static void |
| 1308 | test_must(void **state) |
| 1309 | { |
| 1310 | *state = test_must; |
| 1311 | |
| 1312 | const char *data; |
| 1313 | struct lyd_node *tree; |
| 1314 | |
| 1315 | data = |
| 1316 | "<cont xmlns=\"urn:tests:i\">" |
| 1317 | "<l>wrong</l>" |
| 1318 | "<l2>val</l2>" |
| 1319 | "</cont>"; |
| 1320 | assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
| 1321 | assert_null(tree); |
| 1322 | logbuf_assert("Must condition \"../l = 'right'\" not satisfied. /i:cont/l2"); |
| 1323 | |
| 1324 | data = |
| 1325 | "<cont xmlns=\"urn:tests:i\">" |
| 1326 | "<l>right</l>" |
| 1327 | "<l2>val</l2>" |
| 1328 | "</cont>"; |
| 1329 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree)); |
| 1330 | assert_non_null(tree); |
| 1331 | lyd_free_tree(tree); |
| 1332 | |
| 1333 | *state = NULL; |
| 1334 | } |
| 1335 | |
Michal Vasko | fea12c6 | 2020-03-30 11:00:15 +0200 | [diff] [blame] | 1336 | static void |
| 1337 | test_action(void **state) |
| 1338 | { |
| 1339 | *state = test_action; |
| 1340 | |
| 1341 | const char *data; |
| 1342 | struct lyd_node *tree, *op_tree; |
| 1343 | const struct lys_module *mod; |
| 1344 | |
| 1345 | data = |
| 1346 | "<cont xmlns=\"urn:tests:j\">" |
| 1347 | "<l1>" |
| 1348 | "<k>val1</k>" |
| 1349 | "<act>" |
| 1350 | "<lf2>target</lf2>" |
| 1351 | "</act>" |
| 1352 | "</l1>" |
| 1353 | "</cont>"; |
| 1354 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_rpc(ctx, data, &op_tree, NULL)); |
| 1355 | assert_non_null(op_tree); |
| 1356 | |
| 1357 | /* missing leafref */ |
Michal Vasko | cb7526d | 2020-03-30 15:08:26 +0200 | [diff] [blame] | 1358 | assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, NULL, LYD_VALOPT_INPUT)); |
Michal Vasko | fea12c6 | 2020-03-30 11:00:15 +0200 | [diff] [blame] | 1359 | logbuf_assert("Invalid leafref - required instance \"/lf3\" does not exists in the data tree(s). /j:cont/l1[k='val1']/act/lf2"); |
| 1360 | |
| 1361 | data = |
| 1362 | "<cont xmlns=\"urn:tests:j\">" |
| 1363 | "<lf1>not true</lf1>" |
| 1364 | "</cont>" |
| 1365 | "<lf3 xmlns=\"urn:tests:j\">target</lf3>"; |
| 1366 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_OPT_PARSE_ONLY | LYD_OPT_TRUSTED, &tree)); |
| 1367 | assert_non_null(tree); |
| 1368 | |
| 1369 | /* disabled if-feature */ |
Michal Vasko | cb7526d | 2020-03-30 15:08:26 +0200 | [diff] [blame] | 1370 | assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, tree, LYD_VALOPT_INPUT)); |
Michal Vasko | fea12c6 | 2020-03-30 11:00:15 +0200 | [diff] [blame] | 1371 | logbuf_assert("Data are disabled by \"act\" schema node if-feature. /j:cont/l1[k='val1']/act"); |
| 1372 | |
| 1373 | mod = ly_ctx_get_module_latest(ctx, "j"); |
| 1374 | assert_non_null(mod); |
| 1375 | assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "feat1")); |
| 1376 | |
| 1377 | /* input must false */ |
Michal Vasko | cb7526d | 2020-03-30 15:08:26 +0200 | [diff] [blame] | 1378 | assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, tree, LYD_VALOPT_INPUT)); |
Michal Vasko | fea12c6 | 2020-03-30 11:00:15 +0200 | [diff] [blame] | 1379 | logbuf_assert("Must condition \"../../lf1 = 'true'\" not satisfied. /j:cont/l1[k='val1']/act"); |
| 1380 | |
| 1381 | lyd_free_siblings(tree); |
| 1382 | data = |
| 1383 | "<cont xmlns=\"urn:tests:j\">" |
| 1384 | "<lf1>true</lf1>" |
| 1385 | "</cont>" |
| 1386 | "<lf3 xmlns=\"urn:tests:j\">target</lf3>"; |
| 1387 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_OPT_PARSE_ONLY | LYD_OPT_TRUSTED, &tree)); |
| 1388 | assert_non_null(tree); |
| 1389 | |
| 1390 | /* success */ |
Michal Vasko | cb7526d | 2020-03-30 15:08:26 +0200 | [diff] [blame] | 1391 | assert_int_equal(LY_SUCCESS, lyd_validate_op(op_tree, tree, LYD_VALOPT_INPUT)); |
Michal Vasko | fea12c6 | 2020-03-30 11:00:15 +0200 | [diff] [blame] | 1392 | |
Michal Vasko | cb7526d | 2020-03-30 15:08:26 +0200 | [diff] [blame] | 1393 | lys_feature_disable(mod, "feat1"); |
| 1394 | lyd_free_tree(op_tree); |
| 1395 | lyd_free_siblings(tree); |
| 1396 | |
| 1397 | *state = NULL; |
| 1398 | } |
| 1399 | |
| 1400 | static void |
| 1401 | test_reply(void **state) |
| 1402 | { |
| 1403 | *state = test_reply; |
| 1404 | |
| 1405 | const char *data; |
| 1406 | struct lyd_node *tree, *op_tree, *request; |
| 1407 | const struct lys_module *mod; |
| 1408 | |
| 1409 | data = |
| 1410 | "<cont xmlns=\"urn:tests:j\">" |
| 1411 | "<l1>" |
| 1412 | "<k>val1</k>" |
| 1413 | "<act>" |
| 1414 | "<lf2>target</lf2>" |
| 1415 | "</act>" |
| 1416 | "</l1>" |
| 1417 | "</cont>"; |
| 1418 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_rpc(ctx, data, &request, NULL)); |
| 1419 | assert_non_null(request); |
| 1420 | data = "<lf2 xmlns=\"urn:tests:j\">target</lf2>"; |
| 1421 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_reply(request, data, &op_tree, NULL)); |
| 1422 | lyd_free_all(request); |
| 1423 | assert_non_null(op_tree); |
| 1424 | |
| 1425 | /* missing leafref */ |
| 1426 | assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, NULL, LYD_VALOPT_OUTPUT)); |
| 1427 | logbuf_assert("Invalid leafref - required instance \"/lf4\" does not exists in the data tree(s). /j:cont/l1[k='val1']/act/lf2"); |
| 1428 | |
| 1429 | data = |
| 1430 | "<cont xmlns=\"urn:tests:j\">" |
| 1431 | "<lf1>not true</lf1>" |
| 1432 | "</cont>" |
| 1433 | "<lf4 xmlns=\"urn:tests:j\">target</lf4>"; |
| 1434 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_OPT_PARSE_ONLY | LYD_OPT_TRUSTED, &tree)); |
| 1435 | assert_non_null(tree); |
| 1436 | |
| 1437 | /* disabled if-feature */ |
| 1438 | assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, tree, LYD_VALOPT_OUTPUT)); |
| 1439 | logbuf_assert("Data are disabled by \"act\" schema node if-feature. /j:cont/l1[k='val1']/act"); |
| 1440 | |
| 1441 | mod = ly_ctx_get_module_latest(ctx, "j"); |
| 1442 | assert_non_null(mod); |
| 1443 | assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "feat1")); |
| 1444 | |
| 1445 | /* input must false */ |
| 1446 | assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, tree, LYD_VALOPT_OUTPUT)); |
| 1447 | logbuf_assert("Must condition \"../../lf1 = 'true2'\" not satisfied. /j:cont/l1[k='val1']/act"); |
| 1448 | |
| 1449 | lyd_free_siblings(tree); |
| 1450 | data = |
| 1451 | "<cont xmlns=\"urn:tests:j\">" |
| 1452 | "<lf1>true2</lf1>" |
| 1453 | "</cont>" |
| 1454 | "<lf4 xmlns=\"urn:tests:j\">target</lf4>"; |
| 1455 | assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_OPT_PARSE_ONLY | LYD_OPT_TRUSTED, &tree)); |
| 1456 | assert_non_null(tree); |
| 1457 | |
| 1458 | /* success */ |
| 1459 | assert_int_equal(LY_SUCCESS, lyd_validate_op(op_tree, tree, LYD_VALOPT_OUTPUT)); |
| 1460 | |
| 1461 | lys_feature_disable(mod, "feat1"); |
Michal Vasko | fea12c6 | 2020-03-30 11:00:15 +0200 | [diff] [blame] | 1462 | lyd_free_tree(op_tree); |
| 1463 | lyd_free_siblings(tree); |
| 1464 | |
| 1465 | *state = NULL; |
| 1466 | } |
| 1467 | |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 1468 | int main(void) |
| 1469 | { |
| 1470 | const struct CMUnitTest tests[] = { |
Michal Vasko | acd83e7 | 2020-02-04 14:12:01 +0100 | [diff] [blame] | 1471 | cmocka_unit_test_teardown(test_when, teardown_s), |
| 1472 | cmocka_unit_test_teardown(test_mandatory, teardown_s), |
| 1473 | cmocka_unit_test_teardown(test_minmax, teardown_s), |
Michal Vasko | 1465471 | 2020-02-06 08:35:21 +0100 | [diff] [blame] | 1474 | cmocka_unit_test_teardown(test_unique, teardown_s), |
| 1475 | cmocka_unit_test_teardown(test_unique_nested, teardown_s), |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 1476 | cmocka_unit_test_teardown(test_dup, teardown_s), |
| 1477 | cmocka_unit_test_teardown(test_defaults, teardown_s), |
Michal Vasko | c193ce9 | 2020-03-06 11:04:48 +0100 | [diff] [blame] | 1478 | cmocka_unit_test_teardown(test_iffeature, teardown_s), |
Michal Vasko | 5b37a35 | 2020-03-06 13:38:33 +0100 | [diff] [blame] | 1479 | cmocka_unit_test_teardown(test_state, teardown_s), |
Michal Vasko | cc048b2 | 2020-03-27 15:52:38 +0100 | [diff] [blame] | 1480 | cmocka_unit_test_teardown(test_must, teardown_s), |
Michal Vasko | fea12c6 | 2020-03-30 11:00:15 +0200 | [diff] [blame] | 1481 | cmocka_unit_test_teardown(test_action, teardown_s), |
Michal Vasko | cb7526d | 2020-03-30 15:08:26 +0200 | [diff] [blame] | 1482 | cmocka_unit_test_teardown(test_reply, teardown_s), |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 1483 | }; |
| 1484 | |
Michal Vasko | acd83e7 | 2020-02-04 14:12:01 +0100 | [diff] [blame] | 1485 | return cmocka_run_group_tests(tests, setup, teardown); |
Michal Vasko | cde73ac | 2019-11-14 16:10:27 +0100 | [diff] [blame] | 1486 | } |