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