Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1 | /* |
| 2 | * @file test_schema_stmts.c |
| 3 | * @author: Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief unit tests for YANG (YIN) statements in (sub)modules |
| 5 | * |
| 6 | * Copyright (c) 2018-2020 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" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 19 | #include "log.h" |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 20 | #include "tree_schema.h" |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 21 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 22 | void |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 23 | test_identity(void **state) |
| 24 | { |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 25 | const struct lys_module *mod, *mod_imp; |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 26 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 27 | /* |
| 28 | * parsing YANG |
| 29 | */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 30 | TEST_STMT_DUP(1, 0, "identity id", "description", "a", "b", "1"); |
| 31 | TEST_STMT_DUP(1, 0, "identity id", "reference", "a", "b", "1"); |
| 32 | TEST_STMT_DUP(1, 0, "identity id", "status", "current", "obsolete", "1"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 33 | |
| 34 | /* full content */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 35 | TEST_SCHEMA_OK(1, 0, "identityone", |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 36 | "identity test {base \"a\";base b; description text;reference \'another text\';status current; if-feature x;if-feature y; identityone:ext;}" |
| 37 | "identity a; identity b; extension ext; feature x; feature y;", mod); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 38 | assert_non_null(mod->parsed->identities); |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 39 | assert_int_equal(3, LY_ARRAY_COUNT(mod->parsed->identities)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 40 | |
| 41 | /* invalid substatement */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 42 | TEST_STMT_SUBSTM_ERR(0, "identity", "organization", "XXX"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * parsing YIN |
| 46 | */ |
| 47 | /* max subelems */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 48 | TEST_SCHEMA_OK(1, 1, "identityone-yin", "<identity name=\"ident-name\">" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 49 | "<if-feature name=\"iff\"/>" |
| 50 | "<base name=\"base-name\"/>" |
| 51 | "<status value=\"deprecated\"/>" |
| 52 | "<description><text>desc</text></description>" |
| 53 | "<reference><text>ref</text></reference>" |
| 54 | /* TODO yin-extension-prefix-compilation-bug "<myext:ext xmlns:myext=\"urn:libyang:test:identityone-yin\"/>" */ |
| 55 | "</identity><extension name=\"ext\"/><identity name=\"base-name\"/><feature name=\"iff\"/>", mod); |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 56 | assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->identities)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 57 | assert_string_equal(mod->parsed->identities[0].name, "ident-name"); |
| 58 | assert_string_equal(mod->parsed->identities[0].bases[0], "base-name"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 59 | assert_string_equal(mod->parsed->identities[0].iffeatures[0].str, "iff"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 60 | assert_string_equal(mod->parsed->identities[0].dsc, "desc"); |
| 61 | assert_string_equal(mod->parsed->identities[0].ref, "ref"); |
| 62 | assert_true(mod->parsed->identities[0].flags & LYS_STATUS_DEPRC); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 63 | /*assert_string_equal(mod->parsed->identities[0].exts[0].name, "ext"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 64 | assert_non_null(mod->parsed->identities[0].exts[0].compiled); |
| 65 | assert_int_equal(mod->parsed->identities[0].exts[0].yin, 1); |
| 66 | assert_int_equal(mod->parsed->identities[0].exts[0].insubstmt_index, 0); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 67 | assert_int_equal(mod->parsed->identities[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);*/ |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 68 | |
| 69 | /* min subelems */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 70 | TEST_SCHEMA_OK(1, 1, "identitytwo-yin", "<identity name=\"ident-name\" />", mod); |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 71 | assert_int_equal(1, LY_ARRAY_COUNT(mod->parsed->identities)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 72 | assert_string_equal(mod->parsed->identities[0].name, "ident-name"); |
| 73 | |
| 74 | /* invalid substatement */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 75 | TEST_SCHEMA_ERR(0, 1, "inv", "<identity name=\"ident-name\"><if-feature name=\"iff\"/></identity>", |
| 76 | "Invalid sub-elemnt \"if-feature\" of \"identity\" element - " |
| 77 | "this sub-element is allowed only in modules with version 1.1 or newer.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * compiling |
| 81 | */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 82 | TEST_SCHEMA_OK(0, 0, "a", "identity a1;", mod_imp); |
| 83 | TEST_SCHEMA_OK(1, 0, "b", "import a {prefix a;}" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 84 | "identity b1; identity b2; identity b3 {base b1; base b:b2; base a:a1;}" |
| 85 | "identity b4 {base b:b1; base b3;}", mod); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 86 | assert_non_null(mod_imp->compiled); |
Radek Krejci | 80d281e | 2020-09-14 17:42:54 +0200 | [diff] [blame] | 87 | assert_non_null(mod_imp->identities); |
| 88 | assert_non_null(mod->identities); |
| 89 | assert_non_null(mod_imp->identities[0].derived); |
| 90 | assert_int_equal(1, LY_ARRAY_COUNT(mod_imp->identities[0].derived)); |
| 91 | assert_ptr_equal(mod_imp->identities[0].derived[0], &mod->identities[2]); |
| 92 | assert_non_null(mod->identities[0].derived); |
| 93 | assert_int_equal(2, LY_ARRAY_COUNT(mod->identities[0].derived)); |
| 94 | assert_ptr_equal(mod->identities[0].derived[0], &mod->identities[2]); |
| 95 | assert_ptr_equal(mod->identities[0].derived[1], &mod->identities[3]); |
| 96 | assert_non_null(mod->identities[1].derived); |
| 97 | assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[1].derived)); |
| 98 | assert_ptr_equal(mod->identities[1].derived[0], &mod->identities[2]); |
| 99 | assert_non_null(mod->identities[2].derived); |
| 100 | assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[2].derived)); |
| 101 | assert_ptr_equal(mod->identities[2].derived[0], &mod->identities[3]); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 102 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 103 | TEST_SCHEMA_OK(1, 0, "c", "identity c2 {base c1;} identity c1;", mod); |
Radek Krejci | 80d281e | 2020-09-14 17:42:54 +0200 | [diff] [blame] | 104 | assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[1].derived)); |
| 105 | assert_ptr_equal(mod->identities[1].derived[0], &mod->identities[0]); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 106 | |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 107 | TEST_SCHEMA_ERR(0, 0, "inv", "identity i1;identity i1;", "Duplicate identifier \"i1\" of identity statement.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 108 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 109 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} identity i1;}"); |
| 110 | TEST_SCHEMA_ERR(0, 0, "inv", "include inv_sub;identity i1;", |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 111 | "Duplicate identifier \"i1\" of identity statement.", NULL); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 112 | TEST_SCHEMA_ERR(0, 0, "inv", "identity i1 {base i2;}", "Unable to find base (i2) of identity \"i1\".", "/inv:{identity='i1'}"); |
| 113 | TEST_SCHEMA_ERR(0, 0, "inv", "identity i1 {base i1;}", "Identity \"i1\" is derived from itself.", "/inv:{identity='i1'}"); |
| 114 | TEST_SCHEMA_ERR(0, 0, "inv", "identity i1 {base i2;}identity i2 {base i3;}identity i3 {base i1;}", |
| 115 | "Identity \"i1\" is indirectly derived from itself.", "/inv:{identity='i3'}"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 116 | |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 117 | /* base in non-implemented module */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 118 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 119 | "module base {namespace \"urn\"; prefix b; identity i1; identity i2 {base i1;}}"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 120 | TEST_SCHEMA_OK(0, 0, "ident", "import base {prefix b;} identity ii {base b:i1;}", mod); |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 121 | |
| 122 | /* default value from non-implemented module */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 123 | TEST_SCHEMA_ERR(0, 0, "ident2", "import base {prefix b;} leaf l {type identityref {base b:i1;} default b:i2;}", |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 124 | "Invalid default - value does not fit the type (Invalid identityref \"b:i2\" value" |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 125 | " - identity found in non-implemented module \"base\".).", "Schema location /ident2:l."); |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 126 | |
| 127 | /* default value in typedef from non-implemented module */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 128 | TEST_SCHEMA_ERR(0, 0, "ident2", "import base {prefix b;} typedef t1 {type identityref {base b:i1;} default b:i2;}" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 129 | "leaf l {type t1;}", "Invalid default - value does not fit the type (Invalid" |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 130 | " identityref \"b:i2\" value - identity found in non-implemented module \"base\".).", "Schema location /ident2:l."); |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 131 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 132 | /* |
| 133 | * printing |
| 134 | */ |
| 135 | |
| 136 | /* |
| 137 | * cleanup |
| 138 | */ |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 139 | } |
| 140 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 141 | void |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 142 | test_feature(void **state) |
| 143 | { |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 144 | const struct lys_module *mod; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 145 | const struct lysp_feature *f; |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 146 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 147 | /* |
| 148 | * parsing YANG |
| 149 | */ |
| 150 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 151 | TEST_STMT_DUP(1, 0, "feature f", "description", "a", "b", "1"); |
| 152 | TEST_STMT_DUP(1, 0, "feature f", "reference", "a", "b", "1"); |
| 153 | TEST_STMT_DUP(1, 0, "feature f", "status", "current", "obsolete", "1"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 154 | |
| 155 | /* full content */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 156 | TEST_SCHEMA_OK(1, 0, "featureone", |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 157 | "feature test {description text;reference \'another text\';status current; if-feature x; if-feature y; featureone:ext;}" |
| 158 | "extension ext; feature x; feature y;", mod); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 159 | assert_non_null(mod->parsed->features); |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 160 | assert_int_equal(3, LY_ARRAY_COUNT(mod->parsed->features)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 161 | |
| 162 | /* invalid substatement */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 163 | TEST_STMT_SUBSTM_ERR(0, "feature", "organization", "XXX"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 164 | |
| 165 | /* |
| 166 | * parsing YIN |
| 167 | */ |
| 168 | /* max subelems */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 169 | TEST_SCHEMA_OK(0, 1, "featureone-yin", "<feature name=\"feature-name\">" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 170 | "<if-feature name=\"iff\"/>" |
| 171 | "<status value=\"deprecated\"/>" |
| 172 | "<description><text>desc</text></description>" |
| 173 | "<reference><text>ref</text></reference>" |
| 174 | /* TODO yin-extension-prefix-compilation-bug "<myext:ext xmlns:myext=\"urn:libyang:test:featureone-yin\"/>" */ |
| 175 | "</feature><extension name=\"ext\"/><feature name=\"iff\"/>", mod); |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 176 | assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->features)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 177 | assert_string_equal(mod->parsed->features[0].name, "feature-name"); |
| 178 | assert_string_equal(mod->parsed->features[0].dsc, "desc"); |
| 179 | assert_true(mod->parsed->features[0].flags & LYS_STATUS_DEPRC); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 180 | assert_string_equal(mod->parsed->features[0].iffeatures[0].str, "iff"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 181 | assert_string_equal(mod->parsed->features[0].ref, "ref"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 182 | /*assert_string_equal(mod->parsed->features[0].exts[0].name, "ext"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 183 | assert_int_equal(mod->parsed->features[0].exts[0].insubstmt_index, 0); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 184 | assert_int_equal(mod->parsed->features[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);*/ |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 185 | |
| 186 | /* min subelems */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 187 | TEST_SCHEMA_OK(0, 1, "featuretwo-yin", "<feature name=\"feature-name\"/>", mod) |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 188 | assert_int_equal(1, LY_ARRAY_COUNT(mod->parsed->features)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 189 | assert_string_equal(mod->parsed->features[0].name, "feature-name"); |
| 190 | |
| 191 | /* invalid substatement */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 192 | TEST_SCHEMA_ERR(0, 1, "inv", "<feature name=\"feature-name\"><organization><text>org</text></organization></feature>", |
| 193 | "Unexpected sub-element \"organization\" of \"feature\" element.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 194 | |
| 195 | /* |
| 196 | * compiling |
| 197 | */ |
| 198 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 199 | TEST_SCHEMA_OK(1, 0, "a", "feature f1 {description test1;reference test2;status current;} feature f2; feature f3;\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 200 | "feature orfeature {if-feature \"f1 or f2\";}\n" |
| 201 | "feature andfeature {if-feature \"f1 and f2\";}\n" |
| 202 | "feature f6 {if-feature \"not f1\";}\n" |
| 203 | "feature f7 {if-feature \"(f2 and f3) or (not f1)\";}\n" |
| 204 | "feature f8 {if-feature \"f1 or f2 or f3 or orfeature or andfeature\";}\n" |
| 205 | "feature f9 {if-feature \"not not f1\";}", mod); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 206 | assert_non_null(mod->parsed->features); |
| 207 | assert_int_equal(9, LY_ARRAY_COUNT(mod->parsed->features)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 208 | |
| 209 | /* all features are disabled by default */ |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 210 | LY_ARRAY_FOR(mod->parsed->features, struct lysp_feature, f) { |
| 211 | assert_false(f->flags & LYS_FENABLED); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 212 | } |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 213 | |
| 214 | /* some invalid expressions */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 215 | TEST_SCHEMA_ERR(1, 0, "inv", "feature f{if-feature f1;}", |
| 216 | "Invalid value \"f1\" of if-feature - unable to find feature \"f1\".", NULL); |
| 217 | TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f2{if-feature 'f and';}", |
| 218 | "Invalid value \"f and\" of if-feature - unexpected end of expression.", NULL); |
| 219 | TEST_SCHEMA_ERR(1, 0, "inv", "feature f{if-feature 'or';}", |
| 220 | "Invalid value \"or\" of if-feature - unexpected end of expression.", NULL); |
| 221 | TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f2{if-feature '(f1';}", |
| 222 | "Invalid value \"(f1\" of if-feature - non-matching opening and closing parentheses.", NULL); |
| 223 | TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f2{if-feature 'f1)';}", |
| 224 | "Invalid value \"f1)\" of if-feature - non-matching opening and closing parentheses.", NULL); |
| 225 | TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f2{if-feature ---;}", |
| 226 | "Invalid value \"---\" of if-feature - unable to find feature \"---\".", NULL); |
| 227 | TEST_SCHEMA_ERR(0, 0, "inv", "feature f1; feature f2{if-feature 'not f1';}", |
| 228 | "Invalid value \"not f1\" of if-feature - YANG 1.1 expression in YANG 1.0 module.", NULL); |
| 229 | TEST_SCHEMA_ERR(0, 0, "inv", "feature f1; feature f1;", |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 230 | "Duplicate identifier \"f1\" of feature statement.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 231 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 232 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} feature f1;}"); |
| 233 | TEST_SCHEMA_ERR(0, 0, "inv", "include inv_sub;feature f1;", |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 234 | "Duplicate identifier \"f1\" of feature statement.", NULL); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 235 | TEST_SCHEMA_ERR(0, 0, "inv", "feature f1 {if-feature f2;} feature f2 {if-feature f1;}", |
| 236 | "Feature \"f1\" is indirectly referenced from itself.", NULL); |
| 237 | TEST_SCHEMA_ERR(0, 0, "inv", "feature f1 {if-feature f1;}", |
| 238 | "Feature \"f1\" is referenced from itself.", NULL); |
| 239 | TEST_SCHEMA_ERR(1, 0, "inv", "feature f {if-feature ();}", |
| 240 | "Invalid value \"()\" of if-feature - number of features in expression does not match the required number of operands for the operations.", NULL); |
| 241 | TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'f1(';}", |
| 242 | "Invalid value \"f1(\" of if-feature - non-matching opening and closing parentheses.", NULL); |
| 243 | TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'and f1';}", |
| 244 | "Invalid value \"and f1\" of if-feature - missing feature/expression before \"and\" operation.", NULL); |
| 245 | TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'f1 not ';}", |
| 246 | "Invalid value \"f1 not \" of if-feature - unexpected end of expression.", NULL); |
| 247 | TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'f1 not not ';}", |
| 248 | "Invalid value \"f1 not not \" of if-feature - unexpected end of expression.", NULL); |
| 249 | TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f2; feature f {if-feature 'or f1 f2';}", |
| 250 | "Invalid value \"or f1 f2\" of if-feature - missing feature/expression before \"or\" operation.", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 251 | |
| 252 | /* |
| 253 | * printing |
| 254 | */ |
| 255 | |
| 256 | /* |
| 257 | * cleanup |
| 258 | */ |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 259 | } |