Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1 | /* |
aPiecek | 023f83a | 2021-05-11 07:37:03 +0200 | [diff] [blame^] | 2 | * @file test_schema_common.c |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3 | * @author: Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief unit tests for functions from common.c |
| 5 | * |
| 6 | * Copyright (c) 2018 CESNET, z.s.p.o. |
| 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 | */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 14 | #include "test_schema.h" |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 15 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 16 | #include <string.h> |
| 17 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 18 | #include "context.h" |
| 19 | #include "log.h" |
Radek Krejci | 859a15a | 2021-03-05 20:56:59 +0100 | [diff] [blame] | 20 | #include "tree_edit.h" |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 21 | #include "tree_schema.h" |
| 22 | #include "tree_schema_internal.h" |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 23 | |
| 24 | void |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 25 | test_getnext(void **state) |
| 26 | { |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 27 | const struct lys_module *mod; |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 28 | const struct lysc_node *node = NULL, *four; |
| 29 | const struct lysc_node_container *cont; |
| 30 | const struct lysc_action *rpc; |
| 31 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 32 | assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1; namespace urn:a;prefix a;" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 33 | "container a { container one {presence test;} leaf two {type string;} leaf-list three {type string;}" |
| 34 | " list four {config false;} choice x { leaf five {type string;} case y {leaf six {type string;}}}" |
| 35 | " anyxml seven; action eight {input {leaf eight-input {type string;}} output {leaf eight-output {type string;}}}" |
| 36 | " notification nine {leaf nine-data {type string;}}}" |
| 37 | "leaf b {type string;} leaf-list c {type string;} list d {config false;}" |
| 38 | "choice x { case empty-x { choice empty-xc { case nothing;}} leaf e {type string;} case y {leaf f {type string;}}} anyxml g;" |
| 39 | "rpc h {input {leaf h-input {type string;}} output {leaf h-output {type string;}}}" |
| 40 | "rpc i;" |
| 41 | "notification j {leaf i-data {type string;}}" |
| 42 | "notification k;}", LYS_IN_YANG, &mod)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 43 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 44 | assert_string_equal("a", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 45 | cont = (const struct lysc_node_container *)node; |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 46 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 47 | assert_string_equal("b", node->name); |
| 48 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 49 | assert_string_equal("c", node->name); |
| 50 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 51 | assert_string_equal("d", node->name); |
| 52 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 53 | assert_string_equal("e", node->name); |
| 54 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 55 | assert_string_equal("f", node->name); |
| 56 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 57 | assert_string_equal("g", node->name); |
| 58 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 59 | assert_string_equal("h", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 60 | rpc = (const struct lysc_action *)node; |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 61 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 62 | assert_string_equal("i", node->name); |
| 63 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 64 | assert_string_equal("j", node->name); |
| 65 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 66 | assert_string_equal("k", node->name); |
| 67 | assert_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 68 | /* Inside container */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 69 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 70 | assert_string_equal("one", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 71 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 72 | assert_string_equal("two", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 73 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 74 | assert_string_equal("three", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 75 | assert_non_null(node = four = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 76 | assert_string_equal("four", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 77 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 78 | assert_string_equal("five", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 79 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 80 | assert_string_equal("six", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 81 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 82 | assert_string_equal("seven", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 83 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 84 | assert_string_equal("eight", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 85 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 86 | assert_string_equal("nine", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 87 | assert_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 88 | /* Inside RPC */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 89 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)rpc, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 90 | assert_string_equal("h-input", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 91 | assert_null(node = lys_getnext(node, (const struct lysc_node *)rpc, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 92 | |
| 93 | /* options */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 94 | assert_non_null(node = lys_getnext(four, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCHOICE)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 95 | assert_string_equal("x", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 96 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCHOICE)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 97 | assert_string_equal("seven", node->name); |
| 98 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 99 | assert_non_null(node = lys_getnext(four, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_NOCHOICE)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 100 | assert_string_equal("seven", node->name); |
| 101 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 102 | assert_non_null(node = lys_getnext(four, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCASE)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 103 | assert_string_equal("five", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 104 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCASE)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 105 | assert_string_equal("y", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 106 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCASE)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 107 | assert_string_equal("seven", node->name); |
| 108 | |
| 109 | assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, LYS_GETNEXT_INTONPCONT)); |
| 110 | assert_string_equal("one", node->name); |
| 111 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 112 | assert_non_null(node = lys_getnext(NULL, (const struct lysc_node *)rpc, mod->compiled, LYS_GETNEXT_OUTPUT)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 113 | assert_string_equal("h-output", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 114 | assert_null(node = lys_getnext(node, (const struct lysc_node *)rpc, mod->compiled, LYS_GETNEXT_OUTPUT)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 115 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 116 | assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c; rpc c;}", LYS_IN_YANG, &mod)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 117 | assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0)); |
| 118 | assert_string_equal("c", node->name); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 119 | assert_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 120 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 121 | assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; notification d;}", LYS_IN_YANG, &mod)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 122 | assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0)); |
| 123 | assert_string_equal("d", node->name); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 124 | assert_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 125 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 126 | assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e; container c {container cc;} leaf a {type string;}}", LYS_IN_YANG, &mod)); |
Radek Krejci | b93bd41 | 2020-11-02 13:23:11 +0100 | [diff] [blame] | 127 | assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0)); |
| 128 | assert_string_equal("c", node->name); |
| 129 | assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, LYS_GETNEXT_INTONPCONT)); |
| 130 | assert_string_equal("a", node->name); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 131 | } |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 132 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 133 | void |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 134 | test_date(void **state) |
| 135 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 136 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, NULL, 0, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 137 | CHECK_LOG("Invalid argument date (lysp_check_date()).", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 138 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "x", 1, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 139 | CHECK_LOG("Invalid argument date_len (lysp_check_date()).", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 140 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "nonsencexx", 10, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 141 | CHECK_LOG("Invalid value \"nonsencexx\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 142 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "123x-11-11", 10, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 143 | CHECK_LOG("Invalid value \"123x-11-11\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 144 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-13-11", 10, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 145 | CHECK_LOG("Invalid value \"2018-13-11\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 146 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-11-41", 10, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 147 | CHECK_LOG("Invalid value \"2018-11-41\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 148 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-02-29", 10, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 149 | CHECK_LOG("Invalid value \"2018-02-29\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 150 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018.02-28", 10, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 151 | CHECK_LOG("Invalid value \"2018.02-28\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 152 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-02.28", 10, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 153 | CHECK_LOG("Invalid value \"2018-02.28\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 154 | |
| 155 | assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2018-11-11", 10, "date")); |
| 156 | assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2018-02-28", 10, "date")); |
| 157 | assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2016-02-29", 10, "date")); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 158 | } |
| 159 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 160 | void |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 161 | test_revisions(void **state) |
| 162 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 163 | struct lysp_revision *revs = NULL, *rev; |
| 164 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 165 | /* no error, it just does nothing */ |
| 166 | lysp_sort_revisions(NULL); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 167 | CHECK_LOG(NULL, NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 168 | |
| 169 | /* revisions are stored in wrong order - the newest is the last */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 170 | LY_ARRAY_NEW_RET(NULL, revs, rev, ); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 171 | strcpy(rev->date, "2018-01-01"); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 172 | LY_ARRAY_NEW_RET(NULL, revs, rev, ); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 173 | strcpy(rev->date, "2018-12-31"); |
| 174 | |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 175 | assert_int_equal(2, LY_ARRAY_COUNT(revs)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 176 | assert_string_equal("2018-01-01", &revs[0]); |
| 177 | assert_string_equal("2018-12-31", &revs[1]); |
| 178 | /* the order should be fixed, so the newest revision will be the first in the array */ |
| 179 | lysp_sort_revisions(revs); |
| 180 | assert_string_equal("2018-12-31", &revs[0]); |
| 181 | assert_string_equal("2018-01-01", &revs[1]); |
| 182 | |
| 183 | LY_ARRAY_FREE(revs); |
| 184 | } |
| 185 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 186 | void |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 187 | test_typedef(void **state) |
| 188 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 189 | const char *str; |
| 190 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 191 | str = "module a {namespace urn:a; prefix a; typedef binary {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 192 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 193 | CHECK_LOG("Invalid name \"binary\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 194 | str = "module a {namespace urn:a; prefix a; typedef bits {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 195 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 196 | CHECK_LOG("Invalid name \"bits\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 197 | str = "module a {namespace urn:a; prefix a; typedef boolean {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 198 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 199 | CHECK_LOG("Invalid name \"boolean\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 200 | str = "module a {namespace urn:a; prefix a; typedef decimal64 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 201 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 202 | CHECK_LOG("Invalid name \"decimal64\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 203 | str = "module a {namespace urn:a; prefix a; typedef empty {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 204 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 205 | CHECK_LOG("Invalid name \"empty\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 206 | str = "module a {namespace urn:a; prefix a; typedef enumeration {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 207 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 208 | CHECK_LOG("Invalid name \"enumeration\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 209 | str = "module a {namespace urn:a; prefix a; typedef int8 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 210 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 211 | CHECK_LOG("Invalid name \"int8\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 212 | str = "module a {namespace urn:a; prefix a; typedef int16 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 213 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 214 | CHECK_LOG("Invalid name \"int16\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 215 | str = "module a {namespace urn:a; prefix a; typedef int32 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 216 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 217 | CHECK_LOG("Invalid name \"int32\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 218 | str = "module a {namespace urn:a; prefix a; typedef int64 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 219 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 220 | CHECK_LOG("Invalid name \"int64\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 221 | str = "module a {namespace urn:a; prefix a; typedef instance-identifier {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 222 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 223 | CHECK_LOG("Invalid name \"instance-identifier\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 224 | str = "module a {namespace urn:a; prefix a; typedef identityref {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 225 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 226 | CHECK_LOG("Invalid name \"identityref\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 227 | str = "module a {namespace urn:a; prefix a; typedef leafref {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 228 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 229 | CHECK_LOG("Invalid name \"leafref\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 230 | str = "module a {namespace urn:a; prefix a; typedef string {type int8;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 231 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 232 | CHECK_LOG("Invalid name \"string\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 233 | str = "module a {namespace urn:a; prefix a; typedef union {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 234 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 235 | CHECK_LOG("Invalid name \"union\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 236 | str = "module a {namespace urn:a; prefix a; typedef uint8 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 237 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 238 | CHECK_LOG("Invalid name \"uint8\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 239 | str = "module a {namespace urn:a; prefix a; typedef uint16 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 240 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 241 | CHECK_LOG("Invalid name \"uint16\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 242 | str = "module a {namespace urn:a; prefix a; typedef uint32 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 243 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 244 | CHECK_LOG("Invalid name \"uint32\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 245 | str = "module a {namespace urn:a; prefix a; typedef uint64 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 246 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 247 | CHECK_LOG("Invalid name \"uint64\" of typedef - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 248 | |
| 249 | str = "module mytypes {namespace urn:types; prefix t; typedef binary_ {type string;} typedef bits_ {type string;} typedef boolean_ {type string;} " |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 250 | "typedef decimal64_ {type string;} typedef empty_ {type string;} typedef enumeration_ {type string;} typedef int8_ {type string;} typedef int16_ {type string;}" |
| 251 | "typedef int32_ {type string;} typedef int64_ {type string;} typedef instance-identifier_ {type string;} typedef identityref_ {type string;}" |
| 252 | "typedef leafref_ {type string;} typedef string_ {type int8;} typedef union_ {type string;} typedef uint8_ {type string;} typedef uint16_ {type string;}" |
| 253 | "typedef uint32_ {type string;} typedef uint64_ {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 254 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 255 | |
| 256 | str = "module a {namespace urn:a; prefix a; typedef test {type string;} typedef test {type int8;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 257 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 258 | CHECK_LOG("Invalid name \"test\" of typedef - name collision with another top-level type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 259 | |
| 260 | str = "module a {namespace urn:a; prefix a; typedef x {type string;} container c {typedef x {type int8;}}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 261 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 262 | CHECK_LOG("Invalid name \"x\" of typedef - scoped type collide with a top-level type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 263 | |
| 264 | str = "module a {namespace urn:a; prefix a; container c {container d {typedef y {type int8;}} typedef y {type string;}}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 265 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 266 | CHECK_LOG("Invalid name \"y\" of typedef - name collision with another scoped type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 267 | |
| 268 | str = "module a {namespace urn:a; prefix a; container c {typedef y {type int8;} typedef y {type string;}}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 269 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 270 | CHECK_LOG("Invalid name \"y\" of typedef - name collision with sibling type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 271 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 272 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type string;}}"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 273 | str = "module a {namespace urn:a; prefix a; include b; typedef x {type int8;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 274 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 275 | CHECK_LOG("Invalid name \"x\" of typedef - name collision with another top-level type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 276 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 277 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} container c {typedef x {type string;}}}"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 278 | str = "module a {namespace urn:a; prefix a; include b; typedef x {type int8;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 279 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 280 | CHECK_LOG("Invalid name \"x\" of typedef - scoped type collide with a top-level type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 281 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 282 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type int8;}}"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 283 | str = "module a {namespace urn:a; prefix a; include b; container c {typedef x {type string;}}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 284 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 285 | CHECK_LOG("Invalid name \"x\" of typedef - scoped type collide with a top-level type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 286 | } |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 287 | |
| 288 | void |
| 289 | test_accessible_tree(void **state) |
| 290 | { |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 291 | const char *str; |
| 292 | |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 293 | /* config -> config */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 294 | str = "module a {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 295 | " namespace urn:a;\n" |
| 296 | " prefix a;\n" |
| 297 | " container cont {\n" |
| 298 | " leaf l {\n" |
| 299 | " type empty;\n" |
| 300 | " }\n" |
| 301 | " }\n" |
| 302 | " container cont2 {\n" |
| 303 | " leaf l2 {\n" |
| 304 | " must ../../cont/l;\n" |
| 305 | " type leafref {\n" |
| 306 | " path /cont/l;\n" |
| 307 | " }\n" |
| 308 | " }\n" |
| 309 | " }\n" |
| 310 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 311 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 312 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 313 | |
| 314 | /* config -> state leafref */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 315 | str = "module b {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 316 | " namespace urn:a;\n" |
| 317 | " prefix a;\n" |
| 318 | " container cont {\n" |
| 319 | " config false;\n" |
| 320 | " leaf l {\n" |
| 321 | " type empty;\n" |
| 322 | " }\n" |
| 323 | " }\n" |
| 324 | " container cont2 {\n" |
| 325 | " leaf l2 {\n" |
| 326 | " type leafref {\n" |
| 327 | " path /cont/l;\n" |
| 328 | " }\n" |
| 329 | " }\n" |
| 330 | " }\n" |
| 331 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 332 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 333 | CHECK_LOG_CTX("Invalid leafref path \"/cont/l\" - target is supposed to represent configuration data" |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 334 | " (as the leafref does), but it does not.", "Schema location /b:cont2/l2."); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 335 | |
| 336 | /* config -> state must */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 337 | str = "module b {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 338 | " namespace urn:a;\n" |
| 339 | " prefix a;\n" |
| 340 | " container cont {\n" |
| 341 | " config false;\n" |
| 342 | " leaf l {\n" |
| 343 | " type empty;\n" |
| 344 | " }\n" |
| 345 | " }\n" |
| 346 | " container cont2 {\n" |
| 347 | " leaf l2 {\n" |
| 348 | " must ../../cont/l;\n" |
| 349 | " type empty;\n" |
| 350 | " }\n" |
| 351 | " }\n" |
| 352 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 353 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 354 | CHECK_LOG_CTX("Schema node \"l\" not found (\"../../cont/l\") with context node \"/b:cont2/l2\".", NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 355 | |
| 356 | /* state -> config */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 357 | str = "module c {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 358 | " namespace urn:a;\n" |
| 359 | " prefix a;\n" |
| 360 | " container cont {\n" |
| 361 | " leaf l {\n" |
| 362 | " type empty;\n" |
| 363 | " }\n" |
| 364 | " }\n" |
| 365 | " container cont2 {\n" |
| 366 | " config false;\n" |
| 367 | " leaf l2 {\n" |
| 368 | " must ../../cont/l;\n" |
| 369 | " type leafref {\n" |
| 370 | " path /cont/l;\n" |
| 371 | " }\n" |
| 372 | " }\n" |
| 373 | " }\n" |
| 374 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 375 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 376 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 377 | |
| 378 | /* notif -> state */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 379 | str = "module d {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 380 | " namespace urn:a;\n" |
| 381 | " prefix a;\n" |
| 382 | " container cont {\n" |
| 383 | " config false;\n" |
| 384 | " leaf l {\n" |
| 385 | " type empty;\n" |
| 386 | " }\n" |
| 387 | " }\n" |
| 388 | " notification notif {\n" |
| 389 | " leaf l2 {\n" |
| 390 | " must ../../cont/l;\n" |
| 391 | " type leafref {\n" |
| 392 | " path /cont/l;\n" |
| 393 | " }\n" |
| 394 | " }\n" |
| 395 | " }\n" |
| 396 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 397 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 398 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 399 | |
| 400 | /* notif -> notif */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 401 | str = "module e {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 402 | " namespace urn:a;\n" |
| 403 | " prefix a;\n" |
| 404 | " notification notif {\n" |
| 405 | " leaf l {\n" |
| 406 | " type empty;\n" |
| 407 | " }\n" |
| 408 | " leaf l2 {\n" |
| 409 | " must ../../notif/l;\n" |
| 410 | " type leafref {\n" |
| 411 | " path /notif/l;\n" |
| 412 | " }\n" |
| 413 | " }\n" |
| 414 | " }\n" |
| 415 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 416 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 417 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 418 | |
| 419 | /* rpc input -> state */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 420 | str = "module f {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 421 | " namespace urn:a;\n" |
| 422 | " prefix a;\n" |
| 423 | " container cont {\n" |
| 424 | " config false;\n" |
| 425 | " leaf l {\n" |
| 426 | " type empty;\n" |
| 427 | " }\n" |
| 428 | " }\n" |
| 429 | " rpc rp {\n" |
| 430 | " input {\n" |
| 431 | " leaf l2 {\n" |
| 432 | " must ../../cont/l;\n" |
| 433 | " type leafref {\n" |
| 434 | " path /cont/l;\n" |
| 435 | " }\n" |
| 436 | " }\n" |
| 437 | " }\n" |
| 438 | " }\n" |
| 439 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 440 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 441 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 442 | |
| 443 | /* rpc input -> rpc input */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 444 | str = "module g {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 445 | " namespace urn:a;\n" |
| 446 | " prefix a;\n" |
| 447 | " rpc rp {\n" |
| 448 | " input {\n" |
| 449 | " leaf l {\n" |
| 450 | " type empty;\n" |
| 451 | " }\n" |
| 452 | " leaf l2 {\n" |
| 453 | " must ../l;\n" |
| 454 | " type leafref {\n" |
| 455 | " path /rp/l;\n" |
| 456 | " }\n" |
| 457 | " }\n" |
| 458 | " }\n" |
| 459 | " }\n" |
| 460 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 461 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 462 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 463 | |
| 464 | /* rpc input -> rpc output leafref */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 465 | str = "module h {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 466 | " namespace urn:a;\n" |
| 467 | " prefix a;\n" |
| 468 | " rpc rp {\n" |
| 469 | " input {\n" |
| 470 | " leaf l2 {\n" |
| 471 | " type leafref {\n" |
| 472 | " path /rp/l;\n" |
| 473 | " }\n" |
| 474 | " }\n" |
| 475 | " }\n" |
| 476 | " output {\n" |
| 477 | " leaf l {\n" |
| 478 | " type empty;\n" |
| 479 | " }\n" |
| 480 | " }\n" |
| 481 | " }\n" |
| 482 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 483 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 484 | CHECK_LOG_CTX("Not found node \"l\" in path.", "Schema location /h:rp/input/l2."); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 485 | |
| 486 | /* rpc input -> rpc output must */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 487 | str = "module h {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 488 | " namespace urn:a;\n" |
| 489 | " prefix a;\n" |
| 490 | " rpc rp {\n" |
| 491 | " input {\n" |
| 492 | " leaf l2 {\n" |
| 493 | " must ../l;\n" |
| 494 | " type empty;\n" |
| 495 | " }\n" |
| 496 | " }\n" |
| 497 | " output {\n" |
| 498 | " leaf l {\n" |
| 499 | " type empty;\n" |
| 500 | " }\n" |
| 501 | " }\n" |
| 502 | " }\n" |
| 503 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 504 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 505 | CHECK_LOG_CTX("Schema node \"l\" not found (\"../l\") with context node \"/h:rp/input/l2\".", NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 506 | |
| 507 | /* rpc input -> notif leafref */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 508 | str = "module i {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 509 | " namespace urn:a;\n" |
| 510 | " prefix a;\n" |
| 511 | " rpc rp {\n" |
| 512 | " input {\n" |
| 513 | " leaf l2 {\n" |
| 514 | " type leafref {\n" |
| 515 | " path ../../notif/l;\n" |
| 516 | " }\n" |
| 517 | " }\n" |
| 518 | " }\n" |
| 519 | " }\n" |
| 520 | " notification notif {\n" |
| 521 | " leaf l {\n" |
| 522 | " type empty;\n" |
| 523 | " }\n" |
| 524 | " }\n" |
| 525 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 526 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 527 | CHECK_LOG_CTX("Not found node \"notif\" in path.", "Schema location /i:rp/input/l2."); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 528 | |
| 529 | /* rpc input -> notif must */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 530 | str = "module i {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 531 | " namespace urn:a;\n" |
| 532 | " prefix a;\n" |
| 533 | " rpc rp {\n" |
| 534 | " input {\n" |
| 535 | " leaf l2 {\n" |
| 536 | " must /notif/l;\n" |
| 537 | " type empty;\n" |
| 538 | " }\n" |
| 539 | " }\n" |
| 540 | " }\n" |
| 541 | " notification notif {\n" |
| 542 | " leaf l {\n" |
| 543 | " type empty;\n" |
| 544 | " }\n" |
| 545 | " }\n" |
| 546 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 547 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 548 | CHECK_LOG_CTX("Schema node \"l\" not found (\"/notif/l\") with context node \"/i:rp/input/l2\".", NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 549 | |
| 550 | /* action output -> state */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 551 | str = "module j {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 552 | " yang-version 1.1;\n" |
| 553 | " namespace urn:a;\n" |
| 554 | " prefix a;\n" |
| 555 | " container cont {\n" |
| 556 | " list ll {\n" |
| 557 | " key k;\n" |
| 558 | " leaf k {\n" |
| 559 | " type string;\n" |
| 560 | " }\n" |
| 561 | " action act {\n" |
| 562 | " output {\n" |
| 563 | " leaf l2 {\n" |
| 564 | " must /cont/l;\n" |
| 565 | " type leafref {\n" |
| 566 | " path ../../../l;\n" |
| 567 | " }\n" |
| 568 | " }\n" |
| 569 | " }\n" |
| 570 | " }\n" |
| 571 | " }\n" |
| 572 | " leaf l {\n" |
| 573 | " config false;\n" |
| 574 | " type empty;\n" |
| 575 | " }\n" |
| 576 | " }\n" |
| 577 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 578 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 579 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 580 | |
| 581 | /* action output -> action input leafref */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 582 | str = "module k {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 583 | " yang-version 1.1;\n" |
| 584 | " namespace urn:a;\n" |
| 585 | " prefix a;\n" |
| 586 | " container cont {\n" |
| 587 | " list ll {\n" |
| 588 | " key k;\n" |
| 589 | " leaf k {\n" |
| 590 | " type string;\n" |
| 591 | " }\n" |
| 592 | " action act {\n" |
| 593 | " input {\n" |
| 594 | " leaf l {\n" |
| 595 | " type empty;\n" |
| 596 | " }\n" |
| 597 | " }\n" |
| 598 | " output {\n" |
| 599 | " leaf l2 {\n" |
| 600 | " type leafref {\n" |
| 601 | " path ../l;\n" |
| 602 | " }\n" |
| 603 | " }\n" |
| 604 | " }\n" |
| 605 | " }\n" |
| 606 | " }\n" |
| 607 | " }\n" |
| 608 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 609 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 610 | CHECK_LOG_CTX("Not found node \"l\" in path.", "Schema location /k:cont/ll/act/output/l2."); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 611 | |
| 612 | /* action output -> action input must */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 613 | str = "module k {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 614 | " yang-version 1.1;\n" |
| 615 | " namespace urn:a;\n" |
| 616 | " prefix a;\n" |
| 617 | " container cont {\n" |
| 618 | " list ll {\n" |
| 619 | " key k;\n" |
| 620 | " leaf k {\n" |
| 621 | " type string;\n" |
| 622 | " }\n" |
| 623 | " action act {\n" |
| 624 | " input {\n" |
| 625 | " leaf l {\n" |
| 626 | " type empty;\n" |
| 627 | " }\n" |
| 628 | " }\n" |
| 629 | " output {\n" |
| 630 | " leaf l2 {\n" |
| 631 | " must /cont/ll/act/l;\n" |
| 632 | " type empty;\n" |
| 633 | " }\n" |
| 634 | " }\n" |
| 635 | " }\n" |
| 636 | " }\n" |
| 637 | " }\n" |
| 638 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 639 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 640 | CHECK_LOG_CTX("Schema node \"l\" not found (\"/cont/ll/act/l\") with context node \"/k:cont/ll/act/output/l2\".", NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 641 | } |
Radek Krejci | 589c547 | 2021-01-20 10:29:06 +0100 | [diff] [blame] | 642 | |
| 643 | struct module_clb_list { |
| 644 | const char *name; |
| 645 | const char *data; |
| 646 | }; |
| 647 | |
| 648 | static LY_ERR |
| 649 | module_clb(const char *mod_name, const char *UNUSED(mod_rev), const char *submod_name, |
| 650 | const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format, |
| 651 | const char **module_data, void (**free_module_data)(void *model_data, void *user_data)) |
| 652 | { |
| 653 | struct module_clb_list *list = (struct module_clb_list *)user_data; |
| 654 | |
| 655 | for (unsigned int i = 0; list[i].data; i++) { |
| 656 | |
| 657 | if ((submod_name && !strcmp(list[i].name, submod_name)) || |
| 658 | (!submod_name && mod_name && !strcmp(list[i].name, mod_name))) { |
| 659 | *module_data = list[i].data; |
| 660 | *format = LYS_IN_YANG; |
| 661 | *free_module_data = NULL; |
| 662 | return LY_SUCCESS; |
| 663 | } |
| 664 | } |
| 665 | return LY_EINVAL; |
| 666 | } |
| 667 | |
| 668 | void |
| 669 | test_includes(void **state) |
| 670 | { |
| 671 | const struct lys_module *mod; |
| 672 | |
| 673 | { |
| 674 | /* YANG 1.0 - the missing include sub_a_two in main_a will be injected from sub_a_one */ |
| 675 | struct module_clb_list list[] = { |
Radek Krejci | df54913 | 2021-01-21 10:32:32 +0100 | [diff] [blame] | 676 | {"main_a", "module main_a { namespace urn:test:main_a; prefix ma; include sub_a_one;}"}, |
| 677 | {"sub_a_one", "submodule sub_a_one { belongs-to main_a { prefix ma; } include sub_a_two;}"}, |
| 678 | {"sub_a_two", "submodule sub_a_two { belongs-to main_a { prefix ma; } }"}, |
| 679 | {NULL, NULL} |
Radek Krejci | 589c547 | 2021-01-20 10:29:06 +0100 | [diff] [blame] | 680 | }; |
| 681 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list); |
| 682 | mod = ly_ctx_load_module(UTEST_LYCTX, "main_a", NULL, NULL); |
| 683 | assert_non_null(mod); |
| 684 | assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->includes)); |
| 685 | assert_true(mod->parsed->includes[1].injected); |
| 686 | } |
| 687 | |
| 688 | { |
| 689 | /* YANG 1.1 - the missing include sub_b_two in main_b is error */ |
| 690 | struct module_clb_list list[] = { |
Radek Krejci | df54913 | 2021-01-21 10:32:32 +0100 | [diff] [blame] | 691 | {"main_b", "module main_b { yang-version 1.1; namespace urn:test:main_b; prefix mb; include sub_b_one;}"}, |
| 692 | {"sub_b_one", "submodule sub_b_one { yang-version 1.1; belongs-to main_b { prefix mb; } include sub_b_two;}"}, |
| 693 | {"sub_b_two", "submodule sub_b_two { yang-version 1.1; belongs-to main_b { prefix mb; } }"}, |
| 694 | {NULL, NULL} |
Radek Krejci | 589c547 | 2021-01-20 10:29:06 +0100 | [diff] [blame] | 695 | }; |
| 696 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list); |
| 697 | mod = ly_ctx_load_module(UTEST_LYCTX, "main_b", NULL, NULL); |
| 698 | assert_null(mod); |
| 699 | CHECK_LOG_CTX("Loading \"main_b\" module failed.", NULL, |
| 700 | "Data model \"main_b\" not found in local searchdirs.", NULL, |
| 701 | "Including \"sub_b_one\" submodule into \"main_b\" failed.", NULL, |
| 702 | "Data model \"sub_b_one\" not found in local searchdirs.", NULL, |
| 703 | "YANG 1.1 requires all submodules to be included from main module. But submodule \"sub_b_one\" includes " |
| 704 | "submodule \"sub_b_two\" which is not included by main module \"main_b\".", NULL); |
| 705 | } |
| 706 | |
| 707 | { |
| 708 | /* YANG 1.1 - all includes are in main_c, includes in submodules are not necessary, so expect warning */ |
| 709 | struct module_clb_list list[] = { |
Radek Krejci | df54913 | 2021-01-21 10:32:32 +0100 | [diff] [blame] | 710 | {"main_c", "module main_c { yang-version 1.1; namespace urn:test:main_c; prefix mc; include sub_c_one; include sub_c_two;}"}, |
| 711 | {"sub_c_one", "submodule sub_c_one { yang-version 1.1; belongs-to main_c { prefix mc; } include sub_c_two;}"}, |
| 712 | {"sub_c_two", "submodule sub_c_two { yang-version 1.1; belongs-to main_c { prefix mc; } }"}, |
| 713 | {NULL, NULL} |
Radek Krejci | 589c547 | 2021-01-20 10:29:06 +0100 | [diff] [blame] | 714 | }; |
| 715 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list); |
| 716 | mod = ly_ctx_load_module(UTEST_LYCTX, "main_c", NULL, NULL); |
| 717 | assert_non_null(mod); |
| 718 | assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->includes)); |
| 719 | assert_false(mod->parsed->includes[1].injected); |
| 720 | /* result is ok, but log includes the warning */ |
| 721 | CHECK_LOG_CTX("YANG version 1.1 expects all includes in main module, includes in submodules (sub_c_one) are not necessary.", NULL); |
| 722 | } |
| 723 | } |