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