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 | |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame] | 24 | struct module_clb_list { |
| 25 | const char *name; |
| 26 | const char *data; |
| 27 | }; |
| 28 | |
| 29 | static LY_ERR |
| 30 | module_clb(const char *mod_name, const char *UNUSED(mod_rev), const char *submod_name, |
| 31 | const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format, |
| 32 | const char **module_data, void (**free_module_data)(void *model_data, void *user_data)) |
| 33 | { |
| 34 | struct module_clb_list *list = (struct module_clb_list *)user_data; |
| 35 | |
| 36 | for (unsigned int i = 0; list[i].data; i++) { |
| 37 | |
| 38 | if ((submod_name && !strcmp(list[i].name, submod_name)) || |
| 39 | (!submod_name && mod_name && !strcmp(list[i].name, mod_name))) { |
| 40 | *module_data = list[i].data; |
| 41 | *format = LYS_IN_YANG; |
| 42 | *free_module_data = NULL; |
| 43 | return LY_SUCCESS; |
| 44 | } |
| 45 | } |
| 46 | return LY_EINVAL; |
| 47 | } |
| 48 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 49 | void |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 50 | test_getnext(void **state) |
| 51 | { |
Michal Vasko | 4de7d07 | 2021-07-09 09:13:18 +0200 | [diff] [blame] | 52 | struct lys_module *mod; |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 53 | const struct lysc_node *node = NULL, *four; |
| 54 | const struct lysc_node_container *cont; |
| 55 | const struct lysc_action *rpc; |
| 56 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 57 | 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] | 58 | "container a { container one {presence test;} leaf two {type string;} leaf-list three {type string;}" |
| 59 | " list four {config false;} choice x { leaf five {type string;} case y {leaf six {type string;}}}" |
| 60 | " anyxml seven; action eight {input {leaf eight-input {type string;}} output {leaf eight-output {type string;}}}" |
| 61 | " notification nine {leaf nine-data {type string;}}}" |
| 62 | "leaf b {type string;} leaf-list c {type string;} list d {config false;}" |
| 63 | "choice x { case empty-x { choice empty-xc { case nothing;}} leaf e {type string;} case y {leaf f {type string;}}} anyxml g;" |
| 64 | "rpc h {input {leaf h-input {type string;}} output {leaf h-output {type string;}}}" |
| 65 | "rpc i;" |
| 66 | "notification j {leaf i-data {type string;}}" |
| 67 | "notification k;}", LYS_IN_YANG, &mod)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 68 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 69 | assert_string_equal("a", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 70 | cont = (const struct lysc_node_container *)node; |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 71 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 72 | assert_string_equal("b", node->name); |
| 73 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 74 | assert_string_equal("c", node->name); |
| 75 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 76 | assert_string_equal("d", node->name); |
| 77 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 78 | assert_string_equal("e", node->name); |
| 79 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 80 | assert_string_equal("f", node->name); |
| 81 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 82 | assert_string_equal("g", node->name); |
| 83 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 84 | assert_string_equal("h", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 85 | rpc = (const struct lysc_action *)node; |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 86 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 87 | assert_string_equal("i", node->name); |
| 88 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 89 | assert_string_equal("j", node->name); |
| 90 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 91 | assert_string_equal("k", node->name); |
| 92 | assert_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 93 | /* Inside container */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 94 | 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] | 95 | assert_string_equal("one", 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, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 97 | assert_string_equal("two", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 98 | 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] | 99 | assert_string_equal("three", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 100 | 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] | 101 | assert_string_equal("four", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 102 | 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] | 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, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 105 | assert_string_equal("six", 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, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 107 | assert_string_equal("seven", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 108 | 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] | 109 | assert_string_equal("eight", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 110 | 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] | 111 | assert_string_equal("nine", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 112 | 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] | 113 | /* Inside RPC */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 114 | 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] | 115 | assert_string_equal("h-input", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 116 | 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] | 117 | |
| 118 | /* options */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 119 | 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] | 120 | assert_string_equal("x", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 121 | 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] | 122 | assert_string_equal("seven", node->name); |
| 123 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 124 | 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] | 125 | assert_string_equal("seven", node->name); |
| 126 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 127 | 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] | 128 | assert_string_equal("five", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 129 | 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] | 130 | assert_string_equal("y", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 131 | 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] | 132 | assert_string_equal("seven", node->name); |
| 133 | |
| 134 | assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, LYS_GETNEXT_INTONPCONT)); |
| 135 | assert_string_equal("one", node->name); |
| 136 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 137 | 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] | 138 | assert_string_equal("h-output", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 139 | 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] | 140 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 141 | 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] | 142 | assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0)); |
| 143 | assert_string_equal("c", node->name); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 144 | assert_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 145 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 146 | 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] | 147 | assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0)); |
| 148 | assert_string_equal("d", node->name); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 149 | assert_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 150 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 151 | 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] | 152 | assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0)); |
| 153 | assert_string_equal("c", node->name); |
| 154 | assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, LYS_GETNEXT_INTONPCONT)); |
| 155 | assert_string_equal("a", node->name); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 156 | } |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 157 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 158 | void |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 159 | test_date(void **state) |
| 160 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 161 | 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] | 162 | CHECK_LOG("Invalid argument date (lysp_check_date()).", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 163 | 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] | 164 | CHECK_LOG("Invalid argument date_len (lysp_check_date()).", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 165 | 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] | 166 | CHECK_LOG("Invalid value \"nonsencexx\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 167 | 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] | 168 | CHECK_LOG("Invalid value \"123x-11-11\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 169 | 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] | 170 | CHECK_LOG("Invalid value \"2018-13-11\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 171 | 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] | 172 | CHECK_LOG("Invalid value \"2018-11-41\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 173 | 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] | 174 | CHECK_LOG("Invalid value \"2018-02-29\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 175 | 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] | 176 | CHECK_LOG("Invalid value \"2018.02-28\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 177 | 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] | 178 | CHECK_LOG("Invalid value \"2018-02.28\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 179 | |
| 180 | assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2018-11-11", 10, "date")); |
| 181 | assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2018-02-28", 10, "date")); |
| 182 | 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] | 183 | } |
| 184 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 185 | void |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 186 | test_revisions(void **state) |
| 187 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 188 | struct lysp_revision *revs = NULL, *rev; |
| 189 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 190 | /* no error, it just does nothing */ |
| 191 | lysp_sort_revisions(NULL); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 192 | CHECK_LOG(NULL, NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 193 | |
| 194 | /* revisions are stored in wrong order - the newest is the last */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 195 | LY_ARRAY_NEW_RET(NULL, revs, rev, ); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 196 | strcpy(rev->date, "2018-01-01"); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 197 | LY_ARRAY_NEW_RET(NULL, revs, rev, ); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 198 | strcpy(rev->date, "2018-12-31"); |
| 199 | |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 200 | assert_int_equal(2, LY_ARRAY_COUNT(revs)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 201 | assert_string_equal("2018-01-01", &revs[0]); |
| 202 | assert_string_equal("2018-12-31", &revs[1]); |
| 203 | /* the order should be fixed, so the newest revision will be the first in the array */ |
| 204 | lysp_sort_revisions(revs); |
| 205 | assert_string_equal("2018-12-31", &revs[0]); |
| 206 | assert_string_equal("2018-01-01", &revs[1]); |
| 207 | |
| 208 | LY_ARRAY_FREE(revs); |
| 209 | } |
| 210 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 211 | void |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame] | 212 | test_collision_typedef(void **state) |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 213 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 214 | const char *str; |
aPiecek | 28afeef | 2021-06-30 07:57:18 +0200 | [diff] [blame] | 215 | char *submod; |
| 216 | struct module_clb_list list[3] = {0}; |
| 217 | |
| 218 | list[0].name = "asub"; |
| 219 | list[1].name = "bsub"; |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 220 | |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame] | 221 | /* collision with a built-in type */ |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 222 | str = "module a {namespace urn:a; prefix a; typedef binary {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 223 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 224 | CHECK_LOG("Duplicate identifier \"binary\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 225 | str = "module a {namespace urn:a; prefix a; typedef bits {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 226 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 227 | CHECK_LOG("Duplicate identifier \"bits\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 228 | str = "module a {namespace urn:a; prefix a; typedef boolean {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 229 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 230 | CHECK_LOG("Duplicate identifier \"boolean\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 231 | str = "module a {namespace urn:a; prefix a; typedef decimal64 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 232 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 233 | CHECK_LOG("Duplicate identifier \"decimal64\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 234 | str = "module a {namespace urn:a; prefix a; typedef empty {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 235 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 236 | CHECK_LOG("Duplicate identifier \"empty\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 237 | str = "module a {namespace urn:a; prefix a; typedef enumeration {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 238 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 239 | CHECK_LOG("Duplicate identifier \"enumeration\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 240 | str = "module a {namespace urn:a; prefix a; typedef int8 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 241 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 242 | CHECK_LOG("Duplicate identifier \"int8\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 243 | str = "module a {namespace urn:a; prefix a; typedef int16 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 244 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 245 | CHECK_LOG("Duplicate identifier \"int16\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 246 | str = "module a {namespace urn:a; prefix a; typedef int32 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 247 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 248 | CHECK_LOG("Duplicate identifier \"int32\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 249 | str = "module a {namespace urn:a; prefix a; typedef int64 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 250 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 251 | CHECK_LOG("Duplicate identifier \"int64\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 252 | str = "module a {namespace urn:a; prefix a; typedef instance-identifier {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 253 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 254 | CHECK_LOG("Duplicate identifier \"instance-identifier\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 255 | str = "module a {namespace urn:a; prefix a; typedef identityref {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 256 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 257 | CHECK_LOG("Duplicate identifier \"identityref\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 258 | str = "module a {namespace urn:a; prefix a; typedef leafref {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 259 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 260 | CHECK_LOG("Duplicate identifier \"leafref\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 261 | str = "module a {namespace urn:a; prefix a; typedef string {type int8;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 262 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 263 | CHECK_LOG("Duplicate identifier \"string\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 264 | str = "module a {namespace urn:a; prefix a; typedef union {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 265 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 266 | CHECK_LOG("Duplicate identifier \"union\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 267 | str = "module a {namespace urn:a; prefix a; typedef uint8 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 268 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 269 | CHECK_LOG("Duplicate identifier \"uint8\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 270 | str = "module a {namespace urn:a; prefix a; typedef uint16 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 271 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 272 | CHECK_LOG("Duplicate identifier \"uint16\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 273 | str = "module a {namespace urn:a; prefix a; typedef uint32 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 274 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 275 | CHECK_LOG("Duplicate identifier \"uint32\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 276 | str = "module a {namespace urn:a; prefix a; typedef uint64 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 277 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 278 | CHECK_LOG("Duplicate identifier \"uint64\" of typedef statement - name collision with a built-in type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 279 | |
| 280 | 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] | 281 | "typedef decimal64_ {type string;} typedef empty_ {type string;} typedef enumeration_ {type string;} typedef int8_ {type string;} typedef int16_ {type string;}" |
| 282 | "typedef int32_ {type string;} typedef int64_ {type string;} typedef instance-identifier_ {type string;} typedef identityref_ {type string;}" |
| 283 | "typedef leafref_ {type string;} typedef string_ {type int8;} typedef union_ {type string;} typedef uint8_ {type string;} typedef uint16_ {type string;}" |
| 284 | "typedef uint32_ {type string;} typedef uint64_ {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 285 | 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] | 286 | |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame] | 287 | /* collision in node's scope */ |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 288 | str = "module a {namespace urn:a; prefix a; container c {typedef y {type int8;} typedef y {type string;}}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 289 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 290 | CHECK_LOG("Duplicate identifier \"y\" of typedef statement - name collision with sibling type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 291 | |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame] | 292 | /* collision with parent node */ |
| 293 | str = "module a {namespace urn:a; prefix a; container c {container d {typedef y {type int8;}} typedef y {type string;}}}"; |
aPiecek | 8d4e75d | 2021-06-24 14:47:06 +0200 | [diff] [blame] | 294 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame] | 295 | CHECK_LOG("Duplicate identifier \"y\" of typedef statement - name collision with another scoped type.", NULL); |
aPiecek | 8d4e75d | 2021-06-24 14:47:06 +0200 | [diff] [blame] | 296 | |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame] | 297 | /* collision with module's top-level */ |
| 298 | str = "module a {namespace urn:a; prefix a; typedef x {type string;} container c {typedef x {type int8;}}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 299 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame] | 300 | CHECK_LOG("Duplicate identifier \"x\" of typedef statement - scoped type collide with a top-level type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 301 | |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame] | 302 | /* collision of submodule's node with module's top-level */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 303 | 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] | 304 | str = "module a {namespace urn:a; prefix a; include b; typedef x {type int8;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 305 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 306 | CHECK_LOG("Duplicate identifier \"x\" of typedef statement - scoped type collide with a top-level type.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 307 | |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame] | 308 | /* collision of module's node with submodule's top-level */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 309 | 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] | 310 | str = "module a {namespace urn:a; prefix a; include b; container c {typedef x {type string;}}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 311 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 312 | CHECK_LOG("Duplicate identifier \"x\" of typedef statement - scoped type collide with a top-level type.", NULL); |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame] | 313 | |
| 314 | /* collision of submodule's node with another submodule's top-level */ |
aPiecek | 28afeef | 2021-06-30 07:57:18 +0200 | [diff] [blame] | 315 | str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}"; |
| 316 | list[0].data = "submodule asub {belongs-to a {prefix a;} typedef g {type int;}}"; |
| 317 | list[1].data = "submodule bsub {belongs-to a {prefix a;} container c {typedef g {type int;}}}"; |
| 318 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list); |
| 319 | assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL)); |
| 320 | CHECK_LOG("Duplicate identifier \"g\" of typedef statement - scoped type collide with a top-level type.", NULL); |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame] | 321 | |
| 322 | /* collision of module's top-levels */ |
| 323 | str = "module a {namespace urn:a; prefix a; typedef test {type string;} typedef test {type int8;}}"; |
| 324 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 325 | CHECK_LOG("Duplicate identifier \"test\" of typedef statement - name collision with another top-level type.", NULL); |
| 326 | |
| 327 | /* collision of submodule's top-levels */ |
aPiecek | 28afeef | 2021-06-30 07:57:18 +0200 | [diff] [blame] | 328 | submod = "submodule asub {belongs-to a {prefix a;} typedef g {type int;} typedef g {type int;}}"; |
| 329 | str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub;}"; |
| 330 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod); |
| 331 | assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL)); |
| 332 | CHECK_LOG("Duplicate identifier \"g\" of typedef statement - name collision with another top-level type.", NULL); |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame] | 333 | |
| 334 | /* collision of module's top-level with submodule's top-levels */ |
| 335 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type string;}}"); |
| 336 | str = "module a {namespace urn:a; prefix a; include b; typedef x {type int8;}}"; |
| 337 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 338 | CHECK_LOG("Duplicate identifier \"x\" of typedef statement - name collision with another top-level type.", NULL); |
| 339 | |
| 340 | /* collision of submodule's top-level with another submodule's top-levels */ |
aPiecek | 28afeef | 2021-06-30 07:57:18 +0200 | [diff] [blame] | 341 | str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}"; |
| 342 | list[0].data = "submodule asub {belongs-to a {prefix a;} typedef g {type int;}}"; |
| 343 | list[1].data = "submodule bsub {belongs-to a {prefix a;} typedef g {type int;}}"; |
| 344 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list); |
| 345 | assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL)); |
| 346 | CHECK_LOG("Duplicate identifier \"g\" of typedef statement - name collision with another top-level type.", NULL); |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame] | 347 | |
| 348 | /* error in type-stmt */ |
| 349 | str = "module a {namespace urn:a; prefix a; container c {typedef x {type t{}}"; |
| 350 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 351 | CHECK_STRING(_UC->err_msg, "Unexpected end-of-input."); |
| 352 | UTEST_LOG_CLEAN; |
| 353 | |
| 354 | /* no collision if the same names are in different scope */ |
aPiecek | 28afeef | 2021-06-30 07:57:18 +0200 | [diff] [blame] | 355 | str = "module a {yang-version 1.1; namespace urn:a; prefix a;" |
| 356 | "container c {typedef g {type int;}} container d {typedef g {type int;}}}"; |
| 357 | assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 358 | } |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 359 | |
| 360 | void |
aPiecek | 0b36561 | 2021-06-30 13:12:58 +0200 | [diff] [blame] | 361 | test_collision_grouping(void **state) |
| 362 | { |
| 363 | const char *str; |
| 364 | char *submod; |
| 365 | struct module_clb_list list[3] = {0}; |
| 366 | |
| 367 | list[0].name = "asub"; |
| 368 | list[1].name = "bsub"; |
| 369 | |
| 370 | /* collision in node's scope */ |
| 371 | str = "module a {namespace urn:a; prefix a; container c {grouping y; grouping y;}}"; |
| 372 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 373 | CHECK_LOG("Duplicate identifier \"y\" of grouping statement - name collision with sibling grouping.", NULL); |
| 374 | |
| 375 | /* collision with parent node */ |
| 376 | str = "module a {namespace urn:a; prefix a; container c {container d {grouping y;} grouping y;}}"; |
| 377 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 378 | CHECK_LOG("Duplicate identifier \"y\" of grouping statement - name collision with another scoped grouping.", NULL); |
| 379 | |
| 380 | /* collision with module's top-level */ |
| 381 | str = "module a {namespace urn:a; prefix a; grouping x; container c {grouping x;}}"; |
| 382 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 383 | CHECK_LOG("Duplicate identifier \"x\" of grouping statement - scoped grouping collide with a top-level grouping.", NULL); |
| 384 | |
| 385 | /* collision of submodule's node with module's top-level */ |
| 386 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} container c {grouping x;}}"); |
| 387 | str = "module a {namespace urn:a; prefix a; include b; grouping x;}"; |
| 388 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 389 | CHECK_LOG("Duplicate identifier \"x\" of grouping statement - scoped grouping collide with a top-level grouping.", NULL); |
| 390 | |
| 391 | /* collision of module's node with submodule's top-level */ |
| 392 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} grouping x;}"); |
| 393 | str = "module a {namespace urn:a; prefix a; include b; container c {grouping x;}}"; |
| 394 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 395 | CHECK_LOG("Duplicate identifier \"x\" of grouping statement - scoped grouping collide with a top-level grouping.", NULL); |
| 396 | |
| 397 | /* collision of submodule's node with another submodule's top-level */ |
| 398 | str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}"; |
| 399 | list[0].data = "submodule asub {belongs-to a {prefix a;} grouping g;}"; |
| 400 | list[1].data = "submodule bsub {belongs-to a {prefix a;} container c {grouping g;}}"; |
| 401 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list); |
| 402 | assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL)); |
| 403 | CHECK_LOG("Duplicate identifier \"g\" of grouping statement - scoped grouping collide with a top-level grouping.", NULL); |
| 404 | |
| 405 | /* collision of module's top-levels */ |
| 406 | str = "module a {namespace urn:a; prefix a; grouping test; grouping test;}"; |
| 407 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 408 | CHECK_LOG("Duplicate identifier \"test\" of grouping statement - name collision with another top-level grouping.", NULL); |
| 409 | |
| 410 | /* collision of submodule's top-levels */ |
| 411 | submod = "submodule asub {belongs-to a {prefix a;} grouping g; grouping g;}"; |
| 412 | str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub;}"; |
| 413 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod); |
| 414 | assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL)); |
| 415 | CHECK_LOG("Duplicate identifier \"g\" of grouping statement - name collision with another top-level grouping.", NULL); |
| 416 | |
| 417 | /* collision of module's top-level with submodule's top-levels */ |
| 418 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} grouping x;}"); |
| 419 | str = "module a {namespace urn:a; prefix a; include b; grouping x;}"; |
| 420 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 421 | CHECK_LOG("Duplicate identifier \"x\" of grouping statement - name collision with another top-level grouping.", NULL); |
| 422 | |
| 423 | /* collision of submodule's top-level with another submodule's top-levels */ |
| 424 | str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}"; |
| 425 | list[0].data = "submodule asub {belongs-to a {prefix a;} grouping g;}"; |
| 426 | list[1].data = "submodule bsub {belongs-to a {prefix a;} grouping g;}"; |
| 427 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list); |
| 428 | assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL)); |
| 429 | CHECK_LOG("Duplicate identifier \"g\" of grouping statement - name collision with another top-level grouping.", NULL); |
| 430 | |
| 431 | /* collision in nested groupings, top-level */ |
| 432 | str = "module a {namespace urn:a; prefix a; grouping g {grouping g;}}"; |
| 433 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 434 | CHECK_LOG("Duplicate identifier \"g\" of grouping statement - scoped grouping collide with a top-level grouping.", NULL); |
| 435 | |
| 436 | /* collision in nested groupings, in node */ |
| 437 | str = "module a {namespace urn:a; prefix a; container c {grouping g {grouping g;}}}"; |
| 438 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 439 | CHECK_LOG("Duplicate identifier \"g\" of grouping statement - name collision with another scoped grouping.", NULL); |
| 440 | |
| 441 | /* no collision if the same names are in different scope */ |
| 442 | str = "module a {yang-version 1.1; namespace urn:a; prefix a;" |
| 443 | "container c {grouping g;} container d {grouping g;}}"; |
| 444 | assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL)); |
| 445 | } |
| 446 | |
| 447 | void |
aPiecek | 14d07f0 | 2021-06-30 09:46:50 +0200 | [diff] [blame] | 448 | test_collision_identity(void **state) |
| 449 | { |
| 450 | const char *str; |
| 451 | char *submod; |
aPiecek | 0b36561 | 2021-06-30 13:12:58 +0200 | [diff] [blame] | 452 | struct module_clb_list list[3] = {0}; |
| 453 | |
| 454 | list[0].name = "asub"; |
| 455 | list[1].name = "bsub"; |
aPiecek | 14d07f0 | 2021-06-30 09:46:50 +0200 | [diff] [blame] | 456 | |
| 457 | /* collision of module's top-levels */ |
| 458 | str = "module a {yang-version 1.1; namespace urn:a; prefix a; identity g; identity g;}"; |
| 459 | assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL)); |
| 460 | CHECK_LOG("Duplicate identifier \"g\" of identity statement - name collision with another top-level identity.", NULL); |
| 461 | |
aPiecek | 0b36561 | 2021-06-30 13:12:58 +0200 | [diff] [blame] | 462 | /* collision of submodule's top-levels */ |
| 463 | submod = "submodule asub {belongs-to a {prefix a;} identity g; identity g;}"; |
| 464 | str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub;}"; |
| 465 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod); |
| 466 | assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL)); |
| 467 | CHECK_LOG("Duplicate identifier \"g\" of identity statement - name collision with another top-level identity.", NULL); |
| 468 | |
aPiecek | 14d07f0 | 2021-06-30 09:46:50 +0200 | [diff] [blame] | 469 | /* collision of module's top-level with submodule's top-levels */ |
| 470 | submod = "submodule asub {belongs-to a {prefix a;} identity g;}"; |
| 471 | str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; identity g;}"; |
| 472 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod); |
| 473 | assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL)); |
| 474 | CHECK_LOG("Duplicate identifier \"g\" of identity statement - name collision with another top-level identity.", NULL); |
aPiecek | 0b36561 | 2021-06-30 13:12:58 +0200 | [diff] [blame] | 475 | |
| 476 | /* collision of submodule's top-level with another submodule's top-levels */ |
| 477 | str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}"; |
| 478 | list[0].data = "submodule asub {belongs-to a {prefix a;} identity g;}"; |
| 479 | list[1].data = "submodule bsub {belongs-to a {prefix a;} identity g;}"; |
| 480 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list); |
| 481 | assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL)); |
| 482 | CHECK_LOG("Duplicate identifier \"g\" of identity statement - name collision with another top-level identity.", NULL); |
aPiecek | 14d07f0 | 2021-06-30 09:46:50 +0200 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | void |
| 486 | test_collision_feature(void **state) |
| 487 | { |
| 488 | const char *str; |
| 489 | char *submod; |
aPiecek | 0b36561 | 2021-06-30 13:12:58 +0200 | [diff] [blame] | 490 | struct module_clb_list list[3] = {0}; |
| 491 | |
| 492 | list[0].name = "asub"; |
| 493 | list[1].name = "bsub"; |
aPiecek | 14d07f0 | 2021-06-30 09:46:50 +0200 | [diff] [blame] | 494 | |
| 495 | /* collision of module's top-levels */ |
| 496 | str = "module a {yang-version 1.1; namespace urn:a; prefix a; feature g; feature g;}"; |
| 497 | assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL)); |
| 498 | CHECK_LOG("Duplicate identifier \"g\" of feature statement - name collision with another top-level feature.", NULL); |
| 499 | |
aPiecek | 0b36561 | 2021-06-30 13:12:58 +0200 | [diff] [blame] | 500 | /* collision of submodule's top-levels */ |
| 501 | submod = "submodule asub {belongs-to a {prefix a;} feature g; feature g;}"; |
| 502 | str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub;}"; |
| 503 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod); |
| 504 | assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL)); |
| 505 | CHECK_LOG("Duplicate identifier \"g\" of feature statement - name collision with another top-level feature.", NULL); |
| 506 | |
aPiecek | 14d07f0 | 2021-06-30 09:46:50 +0200 | [diff] [blame] | 507 | /* collision of module's top-level with submodule's top-levels */ |
| 508 | submod = "submodule asub {belongs-to a {prefix a;} feature g;}"; |
| 509 | str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; feature g;}"; |
| 510 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod); |
| 511 | assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL)); |
| 512 | CHECK_LOG("Duplicate identifier \"g\" of feature statement - name collision with another top-level feature.", NULL); |
aPiecek | 0b36561 | 2021-06-30 13:12:58 +0200 | [diff] [blame] | 513 | |
| 514 | /* collision of submodule's top-level with another submodule's top-levels */ |
| 515 | str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}"; |
| 516 | list[0].data = "submodule asub {belongs-to a {prefix a;} feature g;}"; |
| 517 | list[1].data = "submodule bsub {belongs-to a {prefix a;} feature g;}"; |
| 518 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list); |
| 519 | assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL)); |
| 520 | CHECK_LOG("Duplicate identifier \"g\" of feature statement - name collision with another top-level feature.", NULL); |
aPiecek | 14d07f0 | 2021-06-30 09:46:50 +0200 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | void |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 524 | test_accessible_tree(void **state) |
| 525 | { |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 526 | const char *str; |
| 527 | |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 528 | /* config -> config */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 529 | str = "module a {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 530 | " namespace urn:a;\n" |
| 531 | " prefix a;\n" |
| 532 | " container cont {\n" |
| 533 | " leaf l {\n" |
| 534 | " type empty;\n" |
| 535 | " }\n" |
| 536 | " }\n" |
| 537 | " container cont2 {\n" |
| 538 | " leaf l2 {\n" |
| 539 | " must ../../cont/l;\n" |
| 540 | " type leafref {\n" |
| 541 | " path /cont/l;\n" |
| 542 | " }\n" |
| 543 | " }\n" |
| 544 | " }\n" |
| 545 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 546 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 547 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 548 | |
| 549 | /* config -> state leafref */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 550 | str = "module b {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 551 | " namespace urn:a;\n" |
| 552 | " prefix a;\n" |
| 553 | " container cont {\n" |
| 554 | " config false;\n" |
| 555 | " leaf l {\n" |
| 556 | " type empty;\n" |
| 557 | " }\n" |
| 558 | " }\n" |
| 559 | " container cont2 {\n" |
| 560 | " leaf l2 {\n" |
| 561 | " type leafref {\n" |
| 562 | " path /cont/l;\n" |
| 563 | " }\n" |
| 564 | " }\n" |
| 565 | " }\n" |
| 566 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 567 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 568 | 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] | 569 | " (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] | 570 | |
| 571 | /* config -> state must */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 572 | str = "module b {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 573 | " namespace urn:a;\n" |
| 574 | " prefix a;\n" |
| 575 | " container cont {\n" |
| 576 | " config false;\n" |
| 577 | " leaf l {\n" |
| 578 | " type empty;\n" |
| 579 | " }\n" |
| 580 | " }\n" |
| 581 | " container cont2 {\n" |
| 582 | " leaf l2 {\n" |
| 583 | " must ../../cont/l;\n" |
| 584 | " type empty;\n" |
| 585 | " }\n" |
| 586 | " }\n" |
| 587 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 588 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 589 | 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] | 590 | |
| 591 | /* state -> config */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 592 | str = "module c {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 593 | " namespace urn:a;\n" |
| 594 | " prefix a;\n" |
| 595 | " container cont {\n" |
| 596 | " leaf l {\n" |
| 597 | " type empty;\n" |
| 598 | " }\n" |
| 599 | " }\n" |
| 600 | " container cont2 {\n" |
| 601 | " config false;\n" |
| 602 | " leaf l2 {\n" |
| 603 | " must ../../cont/l;\n" |
| 604 | " type leafref {\n" |
| 605 | " path /cont/l;\n" |
| 606 | " }\n" |
| 607 | " }\n" |
| 608 | " }\n" |
| 609 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 610 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 611 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 612 | |
| 613 | /* notif -> state */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 614 | str = "module d {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 615 | " namespace urn:a;\n" |
| 616 | " prefix a;\n" |
| 617 | " container cont {\n" |
| 618 | " config false;\n" |
| 619 | " leaf l {\n" |
| 620 | " type empty;\n" |
| 621 | " }\n" |
| 622 | " }\n" |
| 623 | " notification notif {\n" |
| 624 | " leaf l2 {\n" |
| 625 | " must ../../cont/l;\n" |
| 626 | " type leafref {\n" |
| 627 | " path /cont/l;\n" |
| 628 | " }\n" |
| 629 | " }\n" |
| 630 | " }\n" |
| 631 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 632 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 633 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 634 | |
| 635 | /* notif -> notif */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 636 | str = "module e {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 637 | " namespace urn:a;\n" |
| 638 | " prefix a;\n" |
| 639 | " notification notif {\n" |
| 640 | " leaf l {\n" |
| 641 | " type empty;\n" |
| 642 | " }\n" |
| 643 | " leaf l2 {\n" |
| 644 | " must ../../notif/l;\n" |
| 645 | " type leafref {\n" |
| 646 | " path /notif/l;\n" |
| 647 | " }\n" |
| 648 | " }\n" |
| 649 | " }\n" |
| 650 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 651 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 652 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 653 | |
| 654 | /* rpc input -> state */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 655 | str = "module f {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 656 | " namespace urn:a;\n" |
| 657 | " prefix a;\n" |
| 658 | " container cont {\n" |
| 659 | " config false;\n" |
| 660 | " leaf l {\n" |
| 661 | " type empty;\n" |
| 662 | " }\n" |
| 663 | " }\n" |
| 664 | " rpc rp {\n" |
| 665 | " input {\n" |
| 666 | " leaf l2 {\n" |
| 667 | " must ../../cont/l;\n" |
| 668 | " type leafref {\n" |
| 669 | " path /cont/l;\n" |
| 670 | " }\n" |
| 671 | " }\n" |
| 672 | " }\n" |
| 673 | " }\n" |
| 674 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 675 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 676 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 677 | |
| 678 | /* rpc input -> rpc input */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 679 | str = "module g {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 680 | " namespace urn:a;\n" |
| 681 | " prefix a;\n" |
| 682 | " rpc rp {\n" |
| 683 | " input {\n" |
| 684 | " leaf l {\n" |
| 685 | " type empty;\n" |
| 686 | " }\n" |
| 687 | " leaf l2 {\n" |
| 688 | " must ../l;\n" |
| 689 | " type leafref {\n" |
| 690 | " path /rp/l;\n" |
| 691 | " }\n" |
| 692 | " }\n" |
| 693 | " }\n" |
| 694 | " }\n" |
| 695 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 696 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 697 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 698 | |
| 699 | /* rpc input -> rpc output leafref */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 700 | str = "module h {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 701 | " namespace urn:a;\n" |
| 702 | " prefix a;\n" |
| 703 | " rpc rp {\n" |
| 704 | " input {\n" |
| 705 | " leaf l2 {\n" |
| 706 | " type leafref {\n" |
| 707 | " path /rp/l;\n" |
| 708 | " }\n" |
| 709 | " }\n" |
| 710 | " }\n" |
| 711 | " output {\n" |
| 712 | " leaf l {\n" |
| 713 | " type empty;\n" |
| 714 | " }\n" |
| 715 | " }\n" |
| 716 | " }\n" |
| 717 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 718 | 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] | 719 | 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] | 720 | |
| 721 | /* rpc input -> rpc output must */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 722 | str = "module h {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 723 | " namespace urn:a;\n" |
| 724 | " prefix a;\n" |
| 725 | " rpc rp {\n" |
| 726 | " input {\n" |
| 727 | " leaf l2 {\n" |
| 728 | " must ../l;\n" |
| 729 | " type empty;\n" |
| 730 | " }\n" |
| 731 | " }\n" |
| 732 | " output {\n" |
| 733 | " leaf l {\n" |
| 734 | " type empty;\n" |
| 735 | " }\n" |
| 736 | " }\n" |
| 737 | " }\n" |
| 738 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 739 | 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] | 740 | 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] | 741 | |
| 742 | /* rpc input -> notif leafref */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 743 | str = "module i {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 744 | " namespace urn:a;\n" |
| 745 | " prefix a;\n" |
| 746 | " rpc rp {\n" |
| 747 | " input {\n" |
| 748 | " leaf l2 {\n" |
| 749 | " type leafref {\n" |
| 750 | " path ../../notif/l;\n" |
| 751 | " }\n" |
| 752 | " }\n" |
| 753 | " }\n" |
| 754 | " }\n" |
| 755 | " notification notif {\n" |
| 756 | " leaf l {\n" |
| 757 | " type empty;\n" |
| 758 | " }\n" |
| 759 | " }\n" |
| 760 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 761 | 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] | 762 | 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] | 763 | |
| 764 | /* rpc input -> notif must */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 765 | str = "module i {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 766 | " namespace urn:a;\n" |
| 767 | " prefix a;\n" |
| 768 | " rpc rp {\n" |
| 769 | " input {\n" |
| 770 | " leaf l2 {\n" |
| 771 | " must /notif/l;\n" |
| 772 | " type empty;\n" |
| 773 | " }\n" |
| 774 | " }\n" |
| 775 | " }\n" |
| 776 | " notification notif {\n" |
| 777 | " leaf l {\n" |
| 778 | " type empty;\n" |
| 779 | " }\n" |
| 780 | " }\n" |
| 781 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 782 | 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] | 783 | 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] | 784 | |
| 785 | /* action output -> state */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 786 | str = "module j {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 787 | " yang-version 1.1;\n" |
| 788 | " namespace urn:a;\n" |
| 789 | " prefix a;\n" |
| 790 | " container cont {\n" |
| 791 | " list ll {\n" |
| 792 | " key k;\n" |
| 793 | " leaf k {\n" |
| 794 | " type string;\n" |
| 795 | " }\n" |
| 796 | " action act {\n" |
| 797 | " output {\n" |
| 798 | " leaf l2 {\n" |
| 799 | " must /cont/l;\n" |
| 800 | " type leafref {\n" |
| 801 | " path ../../../l;\n" |
| 802 | " }\n" |
| 803 | " }\n" |
| 804 | " }\n" |
| 805 | " }\n" |
| 806 | " }\n" |
| 807 | " leaf l {\n" |
| 808 | " config false;\n" |
| 809 | " type empty;\n" |
| 810 | " }\n" |
| 811 | " }\n" |
| 812 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 813 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 814 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 815 | |
| 816 | /* action output -> action input leafref */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 817 | str = "module k {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 818 | " yang-version 1.1;\n" |
| 819 | " namespace urn:a;\n" |
| 820 | " prefix a;\n" |
| 821 | " container cont {\n" |
| 822 | " list ll {\n" |
| 823 | " key k;\n" |
| 824 | " leaf k {\n" |
| 825 | " type string;\n" |
| 826 | " }\n" |
| 827 | " action act {\n" |
| 828 | " input {\n" |
| 829 | " leaf l {\n" |
| 830 | " type empty;\n" |
| 831 | " }\n" |
| 832 | " }\n" |
| 833 | " output {\n" |
| 834 | " leaf l2 {\n" |
| 835 | " type leafref {\n" |
| 836 | " path ../l;\n" |
| 837 | " }\n" |
| 838 | " }\n" |
| 839 | " }\n" |
| 840 | " }\n" |
| 841 | " }\n" |
| 842 | " }\n" |
| 843 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 844 | 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] | 845 | 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] | 846 | |
| 847 | /* action output -> action input must */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 848 | str = "module k {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 849 | " yang-version 1.1;\n" |
| 850 | " namespace urn:a;\n" |
| 851 | " prefix a;\n" |
| 852 | " container cont {\n" |
| 853 | " list ll {\n" |
| 854 | " key k;\n" |
| 855 | " leaf k {\n" |
| 856 | " type string;\n" |
| 857 | " }\n" |
| 858 | " action act {\n" |
| 859 | " input {\n" |
| 860 | " leaf l {\n" |
| 861 | " type empty;\n" |
| 862 | " }\n" |
| 863 | " }\n" |
| 864 | " output {\n" |
| 865 | " leaf l2 {\n" |
| 866 | " must /cont/ll/act/l;\n" |
| 867 | " type empty;\n" |
| 868 | " }\n" |
| 869 | " }\n" |
| 870 | " }\n" |
| 871 | " }\n" |
| 872 | " }\n" |
| 873 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 874 | 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] | 875 | 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] | 876 | } |
Radek Krejci | 589c547 | 2021-01-20 10:29:06 +0100 | [diff] [blame] | 877 | |
Radek Krejci | 589c547 | 2021-01-20 10:29:06 +0100 | [diff] [blame] | 878 | void |
| 879 | test_includes(void **state) |
| 880 | { |
Michal Vasko | 4de7d07 | 2021-07-09 09:13:18 +0200 | [diff] [blame] | 881 | struct lys_module *mod; |
Radek Krejci | 589c547 | 2021-01-20 10:29:06 +0100 | [diff] [blame] | 882 | |
| 883 | { |
| 884 | /* YANG 1.0 - the missing include sub_a_two in main_a will be injected from sub_a_one */ |
| 885 | struct module_clb_list list[] = { |
Radek Krejci | df54913 | 2021-01-21 10:32:32 +0100 | [diff] [blame] | 886 | {"main_a", "module main_a { namespace urn:test:main_a; prefix ma; include sub_a_one;}"}, |
| 887 | {"sub_a_one", "submodule sub_a_one { belongs-to main_a { prefix ma; } include sub_a_two;}"}, |
| 888 | {"sub_a_two", "submodule sub_a_two { belongs-to main_a { prefix ma; } }"}, |
| 889 | {NULL, NULL} |
Radek Krejci | 589c547 | 2021-01-20 10:29:06 +0100 | [diff] [blame] | 890 | }; |
| 891 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list); |
| 892 | mod = ly_ctx_load_module(UTEST_LYCTX, "main_a", NULL, NULL); |
| 893 | assert_non_null(mod); |
| 894 | assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->includes)); |
| 895 | assert_true(mod->parsed->includes[1].injected); |
| 896 | } |
| 897 | |
| 898 | { |
| 899 | /* YANG 1.1 - the missing include sub_b_two in main_b is error */ |
| 900 | struct module_clb_list list[] = { |
Radek Krejci | df54913 | 2021-01-21 10:32:32 +0100 | [diff] [blame] | 901 | {"main_b", "module main_b { yang-version 1.1; namespace urn:test:main_b; prefix mb; include sub_b_one;}"}, |
| 902 | {"sub_b_one", "submodule sub_b_one { yang-version 1.1; belongs-to main_b { prefix mb; } include sub_b_two;}"}, |
| 903 | {"sub_b_two", "submodule sub_b_two { yang-version 1.1; belongs-to main_b { prefix mb; } }"}, |
| 904 | {NULL, NULL} |
Radek Krejci | 589c547 | 2021-01-20 10:29:06 +0100 | [diff] [blame] | 905 | }; |
| 906 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list); |
| 907 | mod = ly_ctx_load_module(UTEST_LYCTX, "main_b", NULL, NULL); |
| 908 | assert_null(mod); |
| 909 | CHECK_LOG_CTX("Loading \"main_b\" module failed.", NULL, |
| 910 | "Data model \"main_b\" not found in local searchdirs.", NULL, |
| 911 | "Including \"sub_b_one\" submodule into \"main_b\" failed.", NULL, |
| 912 | "Data model \"sub_b_one\" not found in local searchdirs.", NULL, |
| 913 | "YANG 1.1 requires all submodules to be included from main module. But submodule \"sub_b_one\" includes " |
| 914 | "submodule \"sub_b_two\" which is not included by main module \"main_b\".", NULL); |
| 915 | } |
| 916 | |
| 917 | { |
| 918 | /* YANG 1.1 - all includes are in main_c, includes in submodules are not necessary, so expect warning */ |
| 919 | struct module_clb_list list[] = { |
Radek Krejci | df54913 | 2021-01-21 10:32:32 +0100 | [diff] [blame] | 920 | {"main_c", "module main_c { yang-version 1.1; namespace urn:test:main_c; prefix mc; include sub_c_one; include sub_c_two;}"}, |
| 921 | {"sub_c_one", "submodule sub_c_one { yang-version 1.1; belongs-to main_c { prefix mc; } include sub_c_two;}"}, |
| 922 | {"sub_c_two", "submodule sub_c_two { yang-version 1.1; belongs-to main_c { prefix mc; } }"}, |
| 923 | {NULL, NULL} |
Radek Krejci | 589c547 | 2021-01-20 10:29:06 +0100 | [diff] [blame] | 924 | }; |
| 925 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list); |
| 926 | mod = ly_ctx_load_module(UTEST_LYCTX, "main_c", NULL, NULL); |
| 927 | assert_non_null(mod); |
| 928 | assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->includes)); |
| 929 | assert_false(mod->parsed->includes[1].injected); |
| 930 | /* result is ok, but log includes the warning */ |
| 931 | CHECK_LOG_CTX("YANG version 1.1 expects all includes in main module, includes in submodules (sub_c_one) are not necessary.", NULL); |
| 932 | } |
| 933 | } |