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