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