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