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 | */ |
| 14 | |
| 15 | #include <stdarg.h> |
| 16 | #include <stddef.h> |
| 17 | #include <stdio.h> |
| 18 | #include <setjmp.h> |
| 19 | #include <cmocka.h> |
| 20 | |
| 21 | #include <string.h> |
| 22 | |
| 23 | #include "macros.h" |
| 24 | |
| 25 | |
| 26 | static void |
| 27 | test_identity(void **state) |
| 28 | { |
| 29 | *state = test_identity; |
| 30 | |
| 31 | struct ly_ctx *ctx; |
| 32 | struct lys_module *mod, *mod_imp; |
| 33 | |
| 34 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx)); |
| 35 | |
| 36 | /* |
| 37 | * parsing YANG |
| 38 | */ |
| 39 | TEST_STMT_DUP(ctx, 1, 0, "identity id", "description", "a", "b", "1"); |
| 40 | TEST_STMT_DUP(ctx, 1, 0, "identity id", "reference", "a", "b", "1"); |
| 41 | TEST_STMT_DUP(ctx, 1, 0, "identity id", "status", "current", "obsolete", "1"); |
| 42 | |
| 43 | /* full content */ |
| 44 | TEST_SCHEMA_OK(ctx, 1, 0, "identityone", |
| 45 | "identity test {base \"a\";base b; description text;reference \'another text\';status current; if-feature x;if-feature y; identityone:ext;}" |
| 46 | "identity a; identity b; extension ext; feature x; feature y;", mod); |
| 47 | assert_non_null(mod->parsed->identities); |
| 48 | assert_int_equal(3, LY_ARRAY_SIZE(mod->parsed->identities)); |
| 49 | |
| 50 | /* invalid substatement */ |
| 51 | TEST_STMT_SUBSTM_ERR(ctx, 0, "identity", "organization", "XXX"); |
| 52 | |
| 53 | /* |
| 54 | * parsing YIN |
| 55 | */ |
| 56 | /* max subelems */ |
| 57 | TEST_SCHEMA_OK(ctx, 1, 1, "identityone-yin", "<identity name=\"ident-name\">" |
| 58 | "<if-feature name=\"iff\"/>" |
| 59 | "<base name=\"base-name\"/>" |
| 60 | "<status value=\"deprecated\"/>" |
| 61 | "<description><text>desc</text></description>" |
| 62 | "<reference><text>ref</text></reference>" |
| 63 | "<myext:ext xmlns:myext=\"urn:libyang:test:identityone-yin\"/>" |
| 64 | "</identity><extension name=\"ext\"/><identity name=\"base-name\"/><feature name=\"iff\"/>", mod); |
| 65 | assert_int_equal(2, LY_ARRAY_SIZE(mod->parsed->identities)); |
| 66 | assert_string_equal(mod->parsed->identities[0].name, "ident-name"); |
| 67 | assert_string_equal(mod->parsed->identities[0].bases[0], "base-name"); |
| 68 | assert_string_equal(mod->parsed->identities[0].iffeatures[0], "iff"); |
| 69 | assert_string_equal(mod->parsed->identities[0].dsc, "desc"); |
| 70 | assert_string_equal(mod->parsed->identities[0].ref, "ref"); |
| 71 | assert_true(mod->parsed->identities[0].flags & LYS_STATUS_DEPRC); |
| 72 | assert_string_equal(mod->parsed->identities[0].exts[0].name, "ext"); |
| 73 | assert_non_null(mod->parsed->identities[0].exts[0].compiled); |
| 74 | assert_int_equal(mod->parsed->identities[0].exts[0].yin, 1); |
| 75 | assert_int_equal(mod->parsed->identities[0].exts[0].insubstmt_index, 0); |
| 76 | assert_int_equal(mod->parsed->identities[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
| 77 | |
| 78 | /* min subelems */ |
| 79 | TEST_SCHEMA_OK(ctx, 1, 1, "identitytwo-yin", "<identity name=\"ident-name\" />", mod); |
| 80 | assert_int_equal(1, LY_ARRAY_SIZE(mod->parsed->identities)); |
| 81 | assert_string_equal(mod->parsed->identities[0].name, "ident-name"); |
| 82 | |
| 83 | /* invalid substatement */ |
| 84 | TEST_SCHEMA_ERR(ctx, 0, 1, "inv", "<identity name=\"ident-name\"><if-feature name=\"iff\"/></identity>", |
| 85 | "Invalid sub-elemnt \"if-feature\" of \"identity\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 1."); |
| 86 | |
| 87 | /* |
| 88 | * compiling |
| 89 | */ |
| 90 | TEST_SCHEMA_OK(ctx, 0, 0, "a", "identity a1;", mod_imp); |
| 91 | TEST_SCHEMA_OK(ctx, 1, 0, "b", "import a {prefix a;}" |
| 92 | "identity b1; identity b2; identity b3 {base b1; base b:b2; base a:a1;}" |
| 93 | "identity b4 {base b:b1; base b3;}", mod); |
| 94 | assert_non_null(mod_imp->compiled); |
| 95 | assert_non_null(mod_imp->compiled->identities); |
| 96 | assert_non_null(mod->compiled); |
| 97 | assert_non_null(mod->compiled->identities); |
| 98 | assert_non_null(mod_imp->compiled->identities[0].derived); |
| 99 | assert_int_equal(1, LY_ARRAY_SIZE(mod_imp->compiled->identities[0].derived)); |
| 100 | assert_ptr_equal(mod_imp->compiled->identities[0].derived[0], &mod->compiled->identities[2]); |
| 101 | assert_non_null(mod->compiled->identities[0].derived); |
| 102 | assert_int_equal(2, LY_ARRAY_SIZE(mod->compiled->identities[0].derived)); |
| 103 | assert_ptr_equal(mod->compiled->identities[0].derived[0], &mod->compiled->identities[2]); |
| 104 | assert_ptr_equal(mod->compiled->identities[0].derived[1], &mod->compiled->identities[3]); |
| 105 | assert_non_null(mod->compiled->identities[1].derived); |
| 106 | assert_int_equal(1, LY_ARRAY_SIZE(mod->compiled->identities[1].derived)); |
| 107 | assert_ptr_equal(mod->compiled->identities[1].derived[0], &mod->compiled->identities[2]); |
| 108 | assert_non_null(mod->compiled->identities[2].derived); |
| 109 | assert_int_equal(1, LY_ARRAY_SIZE(mod->compiled->identities[2].derived)); |
| 110 | assert_ptr_equal(mod->compiled->identities[2].derived[0], &mod->compiled->identities[3]); |
| 111 | |
| 112 | TEST_SCHEMA_OK(ctx, 1, 0, "c", "identity c2 {base c1;} identity c1;", mod); |
| 113 | assert_int_equal(1, LY_ARRAY_SIZE(mod->compiled->identities[1].derived)); |
| 114 | assert_ptr_equal(mod->compiled->identities[1].derived[0], &mod->compiled->identities[0]); |
| 115 | |
| 116 | TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "identity i1;identity i1;", "Duplicate identifier \"i1\" of identity statement. /inv:{identity='i1'}"); |
| 117 | |
| 118 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} identity i1;}"); |
| 119 | TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "include inv_sub;identity i1;", |
| 120 | "Duplicate identifier \"i1\" of identity statement. /inv:{identity='i1'}"); |
| 121 | TEST_SCHEMA_ERR(ctx, 0, 0,"inv", "identity i1 {base i2;}", "Unable to find base (i2) of identity \"i1\". /inv:{identity='i1'}"); |
| 122 | TEST_SCHEMA_ERR(ctx, 0, 0,"inv", "identity i1 {base i1;}", "Identity \"i1\" is derived from itself. /inv:{identity='i1'}"); |
| 123 | TEST_SCHEMA_ERR(ctx, 0, 0,"inv", "identity i1 {base i2;}identity i2 {base i3;}identity i3 {base i1;}", |
| 124 | "Identity \"i1\" is indirectly derived from itself. /inv:{identity='i3'}"); |
| 125 | |
| 126 | /* |
| 127 | * printing |
| 128 | */ |
| 129 | |
| 130 | /* |
| 131 | * cleanup |
| 132 | */ |
| 133 | |
| 134 | *state = NULL; |
| 135 | ly_ctx_destroy(ctx, NULL); |
| 136 | } |
| 137 | |
| 138 | |
| 139 | static void |
| 140 | test_feature(void **state) |
| 141 | { |
| 142 | *state = test_feature; |
| 143 | |
| 144 | struct ly_ctx *ctx; |
| 145 | struct lys_module *mod; |
| 146 | const struct lysc_feature *f, *f1; |
| 147 | |
| 148 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx)); |
| 149 | |
| 150 | /* |
| 151 | * parsing YANG |
| 152 | */ |
| 153 | |
| 154 | TEST_STMT_DUP(ctx, 1, 0, "feature f", "description", "a", "b", "1"); |
| 155 | TEST_STMT_DUP(ctx, 1, 0, "feature f", "reference", "a", "b", "1"); |
| 156 | TEST_STMT_DUP(ctx, 1, 0, "feature f", "status", "current", "obsolete", "1"); |
| 157 | |
| 158 | /* full content */ |
| 159 | TEST_SCHEMA_OK(ctx, 1, 0, "featureone", |
| 160 | "feature test {description text;reference \'another text\';status current; if-feature x; if-feature y; featureone:ext;}" |
| 161 | "extension ext; feature x; feature y;", mod); |
| 162 | assert_non_null(mod->parsed->features); |
| 163 | assert_int_equal(3, LY_ARRAY_SIZE(mod->parsed->features)); |
| 164 | |
| 165 | /* invalid substatement */ |
| 166 | TEST_STMT_SUBSTM_ERR(ctx, 0, "feature", "organization", "XXX"); |
| 167 | |
| 168 | /* |
| 169 | * parsing YIN |
| 170 | */ |
| 171 | /* max subelems */ |
| 172 | TEST_SCHEMA_OK(ctx, 0, 1, "featureone-yin", "<feature name=\"feature-name\">" |
| 173 | "<if-feature name=\"iff\"/>" |
| 174 | "<status value=\"deprecated\"/>" |
| 175 | "<description><text>desc</text></description>" |
| 176 | "<reference><text>ref</text></reference>" |
| 177 | "<myext:ext xmlns:myext=\"urn:libyang:test:featureone-yin\"/>" |
| 178 | "</feature><extension name=\"ext\"/><feature name=\"iff\"/>", mod); |
| 179 | assert_int_equal(2, LY_ARRAY_SIZE(mod->parsed->features)); |
| 180 | assert_string_equal(mod->parsed->features[0].name, "feature-name"); |
| 181 | assert_string_equal(mod->parsed->features[0].dsc, "desc"); |
| 182 | assert_true(mod->parsed->features[0].flags & LYS_STATUS_DEPRC); |
| 183 | assert_string_equal(mod->parsed->features[0].iffeatures[0], "iff"); |
| 184 | assert_string_equal(mod->parsed->features[0].ref, "ref"); |
| 185 | assert_string_equal(mod->parsed->features[0].exts[0].name, "ext"); |
| 186 | assert_int_equal(mod->parsed->features[0].exts[0].insubstmt_index, 0); |
| 187 | assert_int_equal(mod->parsed->features[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
| 188 | |
| 189 | /* min subelems */ |
| 190 | TEST_SCHEMA_OK(ctx, 0, 1, "featuretwo-yin", "<feature name=\"feature-name\"/>", mod) |
| 191 | assert_int_equal(1, LY_ARRAY_SIZE(mod->parsed->features)); |
| 192 | assert_string_equal(mod->parsed->features[0].name, "feature-name"); |
| 193 | |
| 194 | /* invalid substatement */ |
| 195 | TEST_SCHEMA_ERR(ctx, 0, 1, "inv", "<feature name=\"feature-name\"><organization><text>org</text></organization></feature>", |
| 196 | "Unexpected sub-element \"organization\" of \"feature\" element. Line number 1."); |
| 197 | |
| 198 | /* |
| 199 | * compiling |
| 200 | */ |
| 201 | |
| 202 | TEST_SCHEMA_OK(ctx, 1, 0, "a", "feature f1 {description test1;reference test2;status current;} feature f2; feature f3;\n" |
| 203 | "feature orfeature {if-feature \"f1 or f2\";}\n" |
| 204 | "feature andfeature {if-feature \"f1 and f2\";}\n" |
| 205 | "feature f6 {if-feature \"not f1\";}\n" |
| 206 | "feature f7 {if-feature \"(f2 and f3) or (not f1)\";}\n" |
| 207 | "feature f8 {if-feature \"f1 or f2 or f3 or orfeature or andfeature\";}\n" |
| 208 | "feature f9 {if-feature \"not not f1\";}", mod); |
| 209 | assert_non_null(mod->compiled->features); |
| 210 | assert_int_equal(9, LY_ARRAY_SIZE(mod->compiled->features)); |
| 211 | |
| 212 | /* all features are disabled by default */ |
| 213 | LY_ARRAY_FOR(mod->compiled->features, struct lysc_feature, f) { |
Michal Vasko | 28d7843 | 2020-05-26 13:10:53 +0200 | [diff] [blame] | 214 | assert_int_equal(LY_ENOT, lysc_feature_value(f)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 215 | } |
| 216 | /* enable f1 */ |
| 217 | assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f1")); |
| 218 | f1 = &mod->compiled->features[0]; |
Michal Vasko | 28d7843 | 2020-05-26 13:10:53 +0200 | [diff] [blame] | 219 | assert_int_equal(LY_SUCCESS, lysc_feature_value(f1)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 220 | |
| 221 | /* enable orfeature */ |
| 222 | f = &mod->compiled->features[3]; |
Michal Vasko | 28d7843 | 2020-05-26 13:10:53 +0200 | [diff] [blame] | 223 | assert_int_equal(LY_ENOT, lysc_feature_value(f)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 224 | assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "orfeature")); |
Michal Vasko | 28d7843 | 2020-05-26 13:10:53 +0200 | [diff] [blame] | 225 | assert_int_equal(LY_SUCCESS, lysc_feature_value(f)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 226 | |
| 227 | /* enable andfeature - no possible since f2 is disabled */ |
| 228 | f = &mod->compiled->features[4]; |
Michal Vasko | 28d7843 | 2020-05-26 13:10:53 +0200 | [diff] [blame] | 229 | assert_int_equal(LY_ENOT, lysc_feature_value(f)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 230 | assert_int_equal(LY_EDENIED, lys_feature_enable(mod, "andfeature")); |
| 231 | logbuf_assert("Feature \"andfeature\" cannot be enabled since it is disabled by its if-feature condition(s)."); |
Michal Vasko | 28d7843 | 2020-05-26 13:10:53 +0200 | [diff] [blame] | 232 | assert_int_equal(LY_ENOT, lysc_feature_value(f)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 233 | |
| 234 | /* first enable f2, so f5 can be enabled then */ |
| 235 | assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f2")); |
| 236 | assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "andfeature")); |
Michal Vasko | 28d7843 | 2020-05-26 13:10:53 +0200 | [diff] [blame] | 237 | assert_int_equal(LY_SUCCESS, lysc_feature_value(f)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 238 | |
| 239 | /* f1 is enabled, so f6 cannot be enabled */ |
| 240 | f = &mod->compiled->features[5]; |
Michal Vasko | 28d7843 | 2020-05-26 13:10:53 +0200 | [diff] [blame] | 241 | assert_int_equal(LY_ENOT, lysc_feature_value(f)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 242 | assert_int_equal(LY_EDENIED, lys_feature_enable(mod, "f6")); |
| 243 | logbuf_assert("Feature \"f6\" cannot be enabled since it is disabled by its if-feature condition(s)."); |
Michal Vasko | 28d7843 | 2020-05-26 13:10:53 +0200 | [diff] [blame] | 244 | assert_int_equal(LY_ENOT, lysc_feature_value(f)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 245 | |
| 246 | /* so disable f1 - andfeature will became also disabled */ |
Michal Vasko | 28d7843 | 2020-05-26 13:10:53 +0200 | [diff] [blame] | 247 | assert_int_equal(LY_SUCCESS, lysc_feature_value(f1)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 248 | assert_int_equal(LY_SUCCESS, lys_feature_disable(mod, "f1")); |
Michal Vasko | 28d7843 | 2020-05-26 13:10:53 +0200 | [diff] [blame] | 249 | assert_int_equal(LY_ENOT, lysc_feature_value(f1)); |
| 250 | assert_int_equal(LY_ENOT, lysc_feature_value(&mod->compiled->features[4])); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 251 | /* while orfeature is stille enabled */ |
Michal Vasko | 28d7843 | 2020-05-26 13:10:53 +0200 | [diff] [blame] | 252 | assert_int_equal(LY_SUCCESS, lysc_feature_value(&mod->compiled->features[3])); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 253 | /* and finally f6 can be enabled */ |
| 254 | assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f6")); |
Michal Vasko | 28d7843 | 2020-05-26 13:10:53 +0200 | [diff] [blame] | 255 | assert_int_equal(LY_SUCCESS, lysc_feature_value(&mod->compiled->features[5])); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 256 | |
| 257 | /* complex evaluation of f7: f1 and f3 are disabled, while f2 is enabled */ |
Michal Vasko | 28d7843 | 2020-05-26 13:10:53 +0200 | [diff] [blame] | 258 | assert_int_equal(LY_SUCCESS, lysc_iffeature_value(&mod->compiled->features[6].iffeatures[0])); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 259 | /* long evaluation of f8 to need to reallocate internal stack for operators */ |
Michal Vasko | 28d7843 | 2020-05-26 13:10:53 +0200 | [diff] [blame] | 260 | assert_int_equal(LY_SUCCESS, lysc_iffeature_value(&mod->compiled->features[7].iffeatures[0])); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 261 | |
| 262 | /* double negation of disabled f1 -> disabled */ |
Michal Vasko | 28d7843 | 2020-05-26 13:10:53 +0200 | [diff] [blame] | 263 | assert_int_equal(LY_ENOT, lysc_iffeature_value(&mod->compiled->features[8].iffeatures[0])); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 264 | |
| 265 | /* disable all features */ |
| 266 | assert_int_equal(LY_SUCCESS, lys_feature_disable(mod, "*")); |
| 267 | LY_ARRAY_FOR(mod->compiled->features, struct lysc_feature, f) { |
| 268 | assert_int_equal(0, lys_feature_value(mod, f->name)); |
| 269 | } |
| 270 | /* re-setting already set feature */ |
| 271 | assert_int_equal(LY_SUCCESS, lys_feature_disable(mod, "f1")); |
| 272 | assert_int_equal(0, lys_feature_value(mod, "f1")); |
| 273 | |
| 274 | /* enabling feature that cannot be enabled due to its if-features */ |
| 275 | assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f1")); |
| 276 | assert_int_equal(LY_EDENIED, lys_feature_enable(mod, "andfeature")); |
| 277 | logbuf_assert("Feature \"andfeature\" cannot be enabled since it is disabled by its if-feature condition(s)."); |
| 278 | assert_int_equal(LY_EDENIED, lys_feature_enable(mod, "*")); |
| 279 | logbuf_assert("Feature \"f6\" cannot be enabled since it is disabled by its if-feature condition(s)."); |
| 280 | /* test if not changed */ |
| 281 | assert_int_equal(1, lys_feature_value(mod, "f1")); |
| 282 | assert_int_equal(0, lys_feature_value(mod, "f2")); |
| 283 | |
| 284 | TEST_SCHEMA_OK(ctx, 0, 0, "b", "feature f1 {if-feature f2;}feature f2;", mod); |
| 285 | assert_non_null(mod->compiled); |
| 286 | assert_non_null(mod->compiled->features); |
| 287 | assert_int_equal(2, LY_ARRAY_SIZE(mod->compiled->features)); |
| 288 | assert_non_null(mod->compiled->features[0].iffeatures); |
| 289 | assert_int_equal(1, LY_ARRAY_SIZE(mod->compiled->features[0].iffeatures)); |
| 290 | assert_non_null(mod->compiled->features[0].iffeatures[0].features); |
| 291 | assert_int_equal(1, LY_ARRAY_SIZE(mod->compiled->features[0].iffeatures[0].features)); |
| 292 | assert_ptr_equal(&mod->compiled->features[1], mod->compiled->features[0].iffeatures[0].features[0]); |
| 293 | assert_non_null(mod->compiled->features); |
| 294 | assert_int_equal(2, LY_ARRAY_SIZE(mod->compiled->features)); |
| 295 | assert_non_null(mod->compiled->features[1].depfeatures); |
| 296 | assert_int_equal(1, LY_ARRAY_SIZE(mod->compiled->features[1].depfeatures)); |
| 297 | assert_ptr_equal(&mod->compiled->features[0], mod->compiled->features[1].depfeatures[0]); |
| 298 | |
| 299 | /* invalid reference */ |
| 300 | assert_int_equal(LY_EINVAL, lys_feature_enable(mod, "xxx")); |
| 301 | logbuf_assert("Feature \"xxx\" not found in module \"b\"."); |
| 302 | |
| 303 | /* some invalid expressions */ |
| 304 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f{if-feature f1;}", |
| 305 | "Invalid value \"f1\" of if-feature - unable to find feature \"f1\". /inv:{feature='f'}"); |
| 306 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature 'f and';}", |
| 307 | "Invalid value \"f and\" of if-feature - unexpected end of expression. /inv:{feature='f2'}"); |
| 308 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f{if-feature 'or';}", |
| 309 | "Invalid value \"or\" of if-feature - unexpected end of expression. /inv:{feature='f'}"); |
| 310 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature '(f1';}", |
| 311 | "Invalid value \"(f1\" of if-feature - non-matching opening and closing parentheses. /inv:{feature='f2'}"); |
| 312 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature 'f1)';}", |
| 313 | "Invalid value \"f1)\" of if-feature - non-matching opening and closing parentheses. /inv:{feature='f2'}"); |
| 314 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature ---;}", |
| 315 | "Invalid value \"---\" of if-feature - unable to find feature \"---\". /inv:{feature='f2'}"); |
| 316 | TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1; feature f2{if-feature 'not f1';}", |
| 317 | "Invalid value \"not f1\" of if-feature - YANG 1.1 expression in YANG 1.0 module. /inv:{feature='f2'}"); |
| 318 | TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1; feature f1;", |
| 319 | "Duplicate identifier \"f1\" of feature statement. /inv:{feature='f1'}"); |
| 320 | |
| 321 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} feature f1;}"); |
| 322 | TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "include inv_sub;feature f1;", |
| 323 | "Duplicate identifier \"f1\" of feature statement. /inv:{feature='f1'}"); |
| 324 | TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1 {if-feature f2;} feature f2 {if-feature f1;}", |
| 325 | "Feature \"f1\" is indirectly referenced from itself. /inv:{feature='f2'}"); |
| 326 | TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1 {if-feature f1;}", |
| 327 | "Feature \"f1\" is referenced from itself. /inv:{feature='f1'}"); |
| 328 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f {if-feature ();}", |
| 329 | "Invalid value \"()\" of if-feature - number of features in expression does not match the required number of operands for the operations. /inv:{feature='f'}"); |
| 330 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1(';}", |
| 331 | "Invalid value \"f1(\" of if-feature - non-matching opening and closing parentheses. /inv:{feature='f'}"); |
| 332 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'and f1';}", |
| 333 | "Invalid value \"and f1\" of if-feature - missing feature/expression before \"and\" operation. /inv:{feature='f'}"); |
| 334 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1 not ';}", |
| 335 | "Invalid value \"f1 not \" of if-feature - unexpected end of expression. /inv:{feature='f'}"); |
| 336 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1 not not ';}", |
| 337 | "Invalid value \"f1 not not \" of if-feature - unexpected end of expression. /inv:{feature='f'}"); |
| 338 | TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2; feature f {if-feature 'or f1 f2';}", |
| 339 | "Invalid value \"or f1 f2\" of if-feature - missing feature/expression before \"or\" operation. /inv:{feature='f'}"); |
| 340 | |
| 341 | /* import reference */ |
| 342 | assert_non_null(mod = ly_ctx_get_module(ctx, "a", NULL)); |
| 343 | assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f1")); |
| 344 | TEST_SCHEMA_OK(ctx, 0, 0, "c", "import a {prefix a;} feature f1; feature f2{if-feature 'a:f1';}", mod); |
| 345 | assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f2")); |
| 346 | assert_int_equal(0, lys_feature_value(mod, "f1")); |
| 347 | assert_int_equal(1, lys_feature_value(mod, "f2")); |
| 348 | |
| 349 | /* |
| 350 | * printing |
| 351 | */ |
| 352 | |
| 353 | /* |
| 354 | * cleanup |
| 355 | */ |
| 356 | |
| 357 | *state = NULL; |
| 358 | ly_ctx_destroy(ctx, NULL); |
| 359 | } |