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 | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 52 | const 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; |
| 215 | |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame^] | 216 | /* collision with a built-in type */ |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 217 | str = "module a {namespace urn:a; prefix a; typedef binary {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 218 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 219 | 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] | 220 | str = "module a {namespace urn:a; prefix a; typedef bits {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 221 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 222 | 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] | 223 | str = "module a {namespace urn:a; prefix a; typedef boolean {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 224 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 225 | 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] | 226 | str = "module a {namespace urn:a; prefix a; typedef decimal64 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 227 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 228 | 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] | 229 | str = "module a {namespace urn:a; prefix a; typedef empty {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 230 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 231 | 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] | 232 | str = "module a {namespace urn:a; prefix a; typedef enumeration {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 233 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 234 | 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] | 235 | str = "module a {namespace urn:a; prefix a; typedef int8 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 236 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 237 | 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] | 238 | str = "module a {namespace urn:a; prefix a; typedef int16 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 239 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 240 | 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] | 241 | str = "module a {namespace urn:a; prefix a; typedef int32 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 242 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 243 | 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] | 244 | str = "module a {namespace urn:a; prefix a; typedef int64 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 245 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 246 | 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] | 247 | str = "module a {namespace urn:a; prefix a; typedef instance-identifier {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 248 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 249 | 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] | 250 | str = "module a {namespace urn:a; prefix a; typedef identityref {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 251 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 252 | 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] | 253 | str = "module a {namespace urn:a; prefix a; typedef leafref {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 254 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 255 | 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] | 256 | str = "module a {namespace urn:a; prefix a; typedef string {type int8;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 257 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 258 | 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] | 259 | str = "module a {namespace urn:a; prefix a; typedef union {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 260 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 261 | 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] | 262 | str = "module a {namespace urn:a; prefix a; typedef uint8 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 263 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 264 | 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] | 265 | str = "module a {namespace urn:a; prefix a; typedef uint16 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 266 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 267 | 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] | 268 | str = "module a {namespace urn:a; prefix a; typedef uint32 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 269 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 270 | 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] | 271 | str = "module a {namespace urn:a; prefix a; typedef uint64 {type string;}}"; |
aPiecek | c7594b7 | 2021-06-29 09:00:03 +0200 | [diff] [blame] | 272 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 273 | 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] | 274 | |
| 275 | 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] | 276 | "typedef decimal64_ {type string;} typedef empty_ {type string;} typedef enumeration_ {type string;} typedef int8_ {type string;} typedef int16_ {type string;}" |
| 277 | "typedef int32_ {type string;} typedef int64_ {type string;} typedef instance-identifier_ {type string;} typedef identityref_ {type string;}" |
| 278 | "typedef leafref_ {type string;} typedef string_ {type int8;} typedef union_ {type string;} typedef uint8_ {type string;} typedef uint16_ {type string;}" |
| 279 | "typedef uint32_ {type string;} typedef uint64_ {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 280 | 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] | 281 | |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame^] | 282 | /* collision in node's scope */ |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 283 | 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] | 284 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 285 | 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] | 286 | |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame^] | 287 | /* collision with parent node */ |
| 288 | 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] | 289 | 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^] | 290 | 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] | 291 | |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame^] | 292 | /* collision with module's top-level */ |
| 293 | 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] | 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 \"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] | 296 | |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame^] | 297 | /* collision of submodule's node with module's top-level */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 298 | 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] | 299 | 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] | 300 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 301 | 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] | 302 | |
aPiecek | 4f49a14 | 2021-06-29 15:32:39 +0200 | [diff] [blame^] | 303 | /* collision of module's node with submodule's top-level */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 304 | 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] | 305 | 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] | 306 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 307 | 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^] | 308 | |
| 309 | /* collision of submodule's node with another submodule's top-level */ |
| 310 | //TODO |
| 311 | |
| 312 | /* collision of module's top-levels */ |
| 313 | str = "module a {namespace urn:a; prefix a; typedef test {type string;} typedef test {type int8;}}"; |
| 314 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 315 | CHECK_LOG("Duplicate identifier \"test\" of typedef statement - name collision with another top-level type.", NULL); |
| 316 | |
| 317 | /* collision of submodule's top-levels */ |
| 318 | //TODO |
| 319 | |
| 320 | /* collision of module's top-level with submodule's top-levels */ |
| 321 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type string;}}"); |
| 322 | str = "module a {namespace urn:a; prefix a; include b; typedef x {type int8;}}"; |
| 323 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 324 | CHECK_LOG("Duplicate identifier \"x\" of typedef statement - name collision with another top-level type.", NULL); |
| 325 | |
| 326 | /* collision of submodule's top-level with another submodule's top-levels */ |
| 327 | //TODO |
| 328 | |
| 329 | /* error in type-stmt */ |
| 330 | str = "module a {namespace urn:a; prefix a; container c {typedef x {type t{}}"; |
| 331 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 332 | CHECK_STRING(_UC->err_msg, "Unexpected end-of-input."); |
| 333 | UTEST_LOG_CLEAN; |
| 334 | |
| 335 | /* no collision if the same names are in different scope */ |
| 336 | //TODO |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 337 | } |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 338 | |
| 339 | void |
| 340 | test_accessible_tree(void **state) |
| 341 | { |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 342 | const char *str; |
| 343 | |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 344 | /* config -> config */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 345 | str = "module a {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 346 | " namespace urn:a;\n" |
| 347 | " prefix a;\n" |
| 348 | " container cont {\n" |
| 349 | " leaf l {\n" |
| 350 | " type empty;\n" |
| 351 | " }\n" |
| 352 | " }\n" |
| 353 | " container cont2 {\n" |
| 354 | " leaf l2 {\n" |
| 355 | " must ../../cont/l;\n" |
| 356 | " type leafref {\n" |
| 357 | " path /cont/l;\n" |
| 358 | " }\n" |
| 359 | " }\n" |
| 360 | " }\n" |
| 361 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 362 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 363 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 364 | |
| 365 | /* config -> state leafref */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 366 | str = "module b {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 367 | " namespace urn:a;\n" |
| 368 | " prefix a;\n" |
| 369 | " container cont {\n" |
| 370 | " config false;\n" |
| 371 | " leaf l {\n" |
| 372 | " type empty;\n" |
| 373 | " }\n" |
| 374 | " }\n" |
| 375 | " container cont2 {\n" |
| 376 | " leaf l2 {\n" |
| 377 | " type leafref {\n" |
| 378 | " path /cont/l;\n" |
| 379 | " }\n" |
| 380 | " }\n" |
| 381 | " }\n" |
| 382 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 383 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 384 | 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] | 385 | " (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] | 386 | |
| 387 | /* config -> state must */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 388 | str = "module b {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 389 | " namespace urn:a;\n" |
| 390 | " prefix a;\n" |
| 391 | " container cont {\n" |
| 392 | " config false;\n" |
| 393 | " leaf l {\n" |
| 394 | " type empty;\n" |
| 395 | " }\n" |
| 396 | " }\n" |
| 397 | " container cont2 {\n" |
| 398 | " leaf l2 {\n" |
| 399 | " must ../../cont/l;\n" |
| 400 | " type empty;\n" |
| 401 | " }\n" |
| 402 | " }\n" |
| 403 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 404 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 405 | 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] | 406 | |
| 407 | /* state -> config */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 408 | str = "module c {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 409 | " namespace urn:a;\n" |
| 410 | " prefix a;\n" |
| 411 | " container cont {\n" |
| 412 | " leaf l {\n" |
| 413 | " type empty;\n" |
| 414 | " }\n" |
| 415 | " }\n" |
| 416 | " container cont2 {\n" |
| 417 | " config false;\n" |
| 418 | " leaf l2 {\n" |
| 419 | " must ../../cont/l;\n" |
| 420 | " type leafref {\n" |
| 421 | " path /cont/l;\n" |
| 422 | " }\n" |
| 423 | " }\n" |
| 424 | " }\n" |
| 425 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 426 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 427 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 428 | |
| 429 | /* notif -> state */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 430 | str = "module d {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 431 | " namespace urn:a;\n" |
| 432 | " prefix a;\n" |
| 433 | " container cont {\n" |
| 434 | " config false;\n" |
| 435 | " leaf l {\n" |
| 436 | " type empty;\n" |
| 437 | " }\n" |
| 438 | " }\n" |
| 439 | " notification notif {\n" |
| 440 | " leaf l2 {\n" |
| 441 | " must ../../cont/l;\n" |
| 442 | " type leafref {\n" |
| 443 | " path /cont/l;\n" |
| 444 | " }\n" |
| 445 | " }\n" |
| 446 | " }\n" |
| 447 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 448 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 449 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 450 | |
| 451 | /* notif -> notif */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 452 | str = "module e {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 453 | " namespace urn:a;\n" |
| 454 | " prefix a;\n" |
| 455 | " notification notif {\n" |
| 456 | " leaf l {\n" |
| 457 | " type empty;\n" |
| 458 | " }\n" |
| 459 | " leaf l2 {\n" |
| 460 | " must ../../notif/l;\n" |
| 461 | " type leafref {\n" |
| 462 | " path /notif/l;\n" |
| 463 | " }\n" |
| 464 | " }\n" |
| 465 | " }\n" |
| 466 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 467 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 468 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 469 | |
| 470 | /* rpc input -> state */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 471 | str = "module f {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 472 | " namespace urn:a;\n" |
| 473 | " prefix a;\n" |
| 474 | " container cont {\n" |
| 475 | " config false;\n" |
| 476 | " leaf l {\n" |
| 477 | " type empty;\n" |
| 478 | " }\n" |
| 479 | " }\n" |
| 480 | " rpc rp {\n" |
| 481 | " input {\n" |
| 482 | " leaf l2 {\n" |
| 483 | " must ../../cont/l;\n" |
| 484 | " type leafref {\n" |
| 485 | " path /cont/l;\n" |
| 486 | " }\n" |
| 487 | " }\n" |
| 488 | " }\n" |
| 489 | " }\n" |
| 490 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 491 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 492 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 493 | |
| 494 | /* rpc input -> rpc input */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 495 | str = "module g {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 496 | " namespace urn:a;\n" |
| 497 | " prefix a;\n" |
| 498 | " rpc rp {\n" |
| 499 | " input {\n" |
| 500 | " leaf l {\n" |
| 501 | " type empty;\n" |
| 502 | " }\n" |
| 503 | " leaf l2 {\n" |
| 504 | " must ../l;\n" |
| 505 | " type leafref {\n" |
| 506 | " path /rp/l;\n" |
| 507 | " }\n" |
| 508 | " }\n" |
| 509 | " }\n" |
| 510 | " }\n" |
| 511 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 512 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 513 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 514 | |
| 515 | /* rpc input -> rpc output leafref */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 516 | str = "module h {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 517 | " namespace urn:a;\n" |
| 518 | " prefix a;\n" |
| 519 | " rpc rp {\n" |
| 520 | " input {\n" |
| 521 | " leaf l2 {\n" |
| 522 | " type leafref {\n" |
| 523 | " path /rp/l;\n" |
| 524 | " }\n" |
| 525 | " }\n" |
| 526 | " }\n" |
| 527 | " output {\n" |
| 528 | " leaf l {\n" |
| 529 | " type empty;\n" |
| 530 | " }\n" |
| 531 | " }\n" |
| 532 | " }\n" |
| 533 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 534 | 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] | 535 | 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] | 536 | |
| 537 | /* rpc input -> rpc output must */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 538 | str = "module h {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 539 | " namespace urn:a;\n" |
| 540 | " prefix a;\n" |
| 541 | " rpc rp {\n" |
| 542 | " input {\n" |
| 543 | " leaf l2 {\n" |
| 544 | " must ../l;\n" |
| 545 | " type empty;\n" |
| 546 | " }\n" |
| 547 | " }\n" |
| 548 | " output {\n" |
| 549 | " leaf l {\n" |
| 550 | " type empty;\n" |
| 551 | " }\n" |
| 552 | " }\n" |
| 553 | " }\n" |
| 554 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 555 | 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] | 556 | 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] | 557 | |
| 558 | /* rpc input -> notif leafref */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 559 | str = "module i {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 560 | " namespace urn:a;\n" |
| 561 | " prefix a;\n" |
| 562 | " rpc rp {\n" |
| 563 | " input {\n" |
| 564 | " leaf l2 {\n" |
| 565 | " type leafref {\n" |
| 566 | " path ../../notif/l;\n" |
| 567 | " }\n" |
| 568 | " }\n" |
| 569 | " }\n" |
| 570 | " }\n" |
| 571 | " notification notif {\n" |
| 572 | " leaf l {\n" |
| 573 | " type empty;\n" |
| 574 | " }\n" |
| 575 | " }\n" |
| 576 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 577 | 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] | 578 | 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] | 579 | |
| 580 | /* rpc input -> notif must */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 581 | str = "module i {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 582 | " namespace urn:a;\n" |
| 583 | " prefix a;\n" |
| 584 | " rpc rp {\n" |
| 585 | " input {\n" |
| 586 | " leaf l2 {\n" |
| 587 | " must /notif/l;\n" |
| 588 | " type empty;\n" |
| 589 | " }\n" |
| 590 | " }\n" |
| 591 | " }\n" |
| 592 | " notification notif {\n" |
| 593 | " leaf l {\n" |
| 594 | " type empty;\n" |
| 595 | " }\n" |
| 596 | " }\n" |
| 597 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 598 | 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] | 599 | 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] | 600 | |
| 601 | /* action output -> state */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 602 | str = "module j {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 603 | " yang-version 1.1;\n" |
| 604 | " namespace urn:a;\n" |
| 605 | " prefix a;\n" |
| 606 | " container cont {\n" |
| 607 | " list ll {\n" |
| 608 | " key k;\n" |
| 609 | " leaf k {\n" |
| 610 | " type string;\n" |
| 611 | " }\n" |
| 612 | " action act {\n" |
| 613 | " output {\n" |
| 614 | " leaf l2 {\n" |
| 615 | " must /cont/l;\n" |
| 616 | " type leafref {\n" |
| 617 | " path ../../../l;\n" |
| 618 | " }\n" |
| 619 | " }\n" |
| 620 | " }\n" |
| 621 | " }\n" |
| 622 | " }\n" |
| 623 | " leaf l {\n" |
| 624 | " config false;\n" |
| 625 | " type empty;\n" |
| 626 | " }\n" |
| 627 | " }\n" |
| 628 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 629 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 630 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 631 | |
| 632 | /* action output -> action input leafref */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 633 | str = "module k {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 634 | " yang-version 1.1;\n" |
| 635 | " namespace urn:a;\n" |
| 636 | " prefix a;\n" |
| 637 | " container cont {\n" |
| 638 | " list ll {\n" |
| 639 | " key k;\n" |
| 640 | " leaf k {\n" |
| 641 | " type string;\n" |
| 642 | " }\n" |
| 643 | " action act {\n" |
| 644 | " input {\n" |
| 645 | " leaf l {\n" |
| 646 | " type empty;\n" |
| 647 | " }\n" |
| 648 | " }\n" |
| 649 | " output {\n" |
| 650 | " leaf l2 {\n" |
| 651 | " type leafref {\n" |
| 652 | " path ../l;\n" |
| 653 | " }\n" |
| 654 | " }\n" |
| 655 | " }\n" |
| 656 | " }\n" |
| 657 | " }\n" |
| 658 | " }\n" |
| 659 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 660 | 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] | 661 | 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] | 662 | |
| 663 | /* action output -> action input must */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 664 | str = "module k {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 665 | " yang-version 1.1;\n" |
| 666 | " namespace urn:a;\n" |
| 667 | " prefix a;\n" |
| 668 | " container cont {\n" |
| 669 | " list ll {\n" |
| 670 | " key k;\n" |
| 671 | " leaf k {\n" |
| 672 | " type string;\n" |
| 673 | " }\n" |
| 674 | " action act {\n" |
| 675 | " input {\n" |
| 676 | " leaf l {\n" |
| 677 | " type empty;\n" |
| 678 | " }\n" |
| 679 | " }\n" |
| 680 | " output {\n" |
| 681 | " leaf l2 {\n" |
| 682 | " must /cont/ll/act/l;\n" |
| 683 | " type empty;\n" |
| 684 | " }\n" |
| 685 | " }\n" |
| 686 | " }\n" |
| 687 | " }\n" |
| 688 | " }\n" |
| 689 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 690 | 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] | 691 | 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] | 692 | } |
Radek Krejci | 589c547 | 2021-01-20 10:29:06 +0100 | [diff] [blame] | 693 | |
Radek Krejci | 589c547 | 2021-01-20 10:29:06 +0100 | [diff] [blame] | 694 | void |
| 695 | test_includes(void **state) |
| 696 | { |
| 697 | const struct lys_module *mod; |
| 698 | |
| 699 | { |
| 700 | /* YANG 1.0 - the missing include sub_a_two in main_a will be injected from sub_a_one */ |
| 701 | struct module_clb_list list[] = { |
Radek Krejci | df54913 | 2021-01-21 10:32:32 +0100 | [diff] [blame] | 702 | {"main_a", "module main_a { namespace urn:test:main_a; prefix ma; include sub_a_one;}"}, |
| 703 | {"sub_a_one", "submodule sub_a_one { belongs-to main_a { prefix ma; } include sub_a_two;}"}, |
| 704 | {"sub_a_two", "submodule sub_a_two { belongs-to main_a { prefix ma; } }"}, |
| 705 | {NULL, NULL} |
Radek Krejci | 589c547 | 2021-01-20 10:29:06 +0100 | [diff] [blame] | 706 | }; |
| 707 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list); |
| 708 | mod = ly_ctx_load_module(UTEST_LYCTX, "main_a", NULL, NULL); |
| 709 | assert_non_null(mod); |
| 710 | assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->includes)); |
| 711 | assert_true(mod->parsed->includes[1].injected); |
| 712 | } |
| 713 | |
| 714 | { |
| 715 | /* YANG 1.1 - the missing include sub_b_two in main_b is error */ |
| 716 | struct module_clb_list list[] = { |
Radek Krejci | df54913 | 2021-01-21 10:32:32 +0100 | [diff] [blame] | 717 | {"main_b", "module main_b { yang-version 1.1; namespace urn:test:main_b; prefix mb; include sub_b_one;}"}, |
| 718 | {"sub_b_one", "submodule sub_b_one { yang-version 1.1; belongs-to main_b { prefix mb; } include sub_b_two;}"}, |
| 719 | {"sub_b_two", "submodule sub_b_two { yang-version 1.1; belongs-to main_b { prefix mb; } }"}, |
| 720 | {NULL, NULL} |
Radek Krejci | 589c547 | 2021-01-20 10:29:06 +0100 | [diff] [blame] | 721 | }; |
| 722 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list); |
| 723 | mod = ly_ctx_load_module(UTEST_LYCTX, "main_b", NULL, NULL); |
| 724 | assert_null(mod); |
| 725 | CHECK_LOG_CTX("Loading \"main_b\" module failed.", NULL, |
| 726 | "Data model \"main_b\" not found in local searchdirs.", NULL, |
| 727 | "Including \"sub_b_one\" submodule into \"main_b\" failed.", NULL, |
| 728 | "Data model \"sub_b_one\" not found in local searchdirs.", NULL, |
| 729 | "YANG 1.1 requires all submodules to be included from main module. But submodule \"sub_b_one\" includes " |
| 730 | "submodule \"sub_b_two\" which is not included by main module \"main_b\".", NULL); |
| 731 | } |
| 732 | |
| 733 | { |
| 734 | /* YANG 1.1 - all includes are in main_c, includes in submodules are not necessary, so expect warning */ |
| 735 | struct module_clb_list list[] = { |
Radek Krejci | df54913 | 2021-01-21 10:32:32 +0100 | [diff] [blame] | 736 | {"main_c", "module main_c { yang-version 1.1; namespace urn:test:main_c; prefix mc; include sub_c_one; include sub_c_two;}"}, |
| 737 | {"sub_c_one", "submodule sub_c_one { yang-version 1.1; belongs-to main_c { prefix mc; } include sub_c_two;}"}, |
| 738 | {"sub_c_two", "submodule sub_c_two { yang-version 1.1; belongs-to main_c { prefix mc; } }"}, |
| 739 | {NULL, NULL} |
Radek Krejci | 589c547 | 2021-01-20 10:29:06 +0100 | [diff] [blame] | 740 | }; |
| 741 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list); |
| 742 | mod = ly_ctx_load_module(UTEST_LYCTX, "main_c", NULL, NULL); |
| 743 | assert_non_null(mod); |
| 744 | assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->includes)); |
| 745 | assert_false(mod->parsed->includes[1].injected); |
| 746 | /* result is ok, but log includes the warning */ |
| 747 | CHECK_LOG_CTX("YANG version 1.1 expects all includes in main module, includes in submodules (sub_c_one) are not necessary.", NULL); |
| 748 | } |
| 749 | } |