blob: 9e347422c3fd78841d9b175ef05e00735e4b0153 [file] [log] [blame]
Radek Krejci3a4889a2020-05-19 17:01:58 +02001/*
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 Krejci18abde42020-06-13 20:04:39 +020023#include "log.h"
24#include "context.h"
25#include "test_schema.h"
26#include "tree_schema.h"
Radek Krejci3a4889a2020-05-19 17:01:58 +020027
Radek Krejci18abde42020-06-13 20:04:39 +020028#include "test_schema.h"
Radek Krejci3a4889a2020-05-19 17:01:58 +020029
Radek Krejci18abde42020-06-13 20:04:39 +020030void
Radek Krejci3a4889a2020-05-19 17:01:58 +020031test_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);
Michal Vaskofd69e1d2020-07-03 11:57:17 +020052 assert_int_equal(3, LY_ARRAY_COUNT(mod->parsed->identities));
Radek Krejci3a4889a2020-05-19 17:01:58 +020053
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);
Michal Vaskofd69e1d2020-07-03 11:57:17 +020069 assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->identities));
Radek Krejci3a4889a2020-05-19 17:01:58 +020070 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);
Michal Vaskofd69e1d2020-07-03 11:57:17 +020084 assert_int_equal(1, LY_ARRAY_COUNT(mod->parsed->identities));
Radek Krejci3a4889a2020-05-19 17:01:58 +020085 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);
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200103 assert_int_equal(1, LY_ARRAY_COUNT(mod_imp->compiled->identities[0].derived));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200104 assert_ptr_equal(mod_imp->compiled->identities[0].derived[0], &mod->compiled->identities[2]);
105 assert_non_null(mod->compiled->identities[0].derived);
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200106 assert_int_equal(2, LY_ARRAY_COUNT(mod->compiled->identities[0].derived));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200107 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);
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200110 assert_int_equal(1, LY_ARRAY_COUNT(mod->compiled->identities[1].derived));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200111 assert_ptr_equal(mod->compiled->identities[1].derived[0], &mod->compiled->identities[2]);
112 assert_non_null(mod->compiled->identities[2].derived);
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200113 assert_int_equal(1, LY_ARRAY_COUNT(mod->compiled->identities[2].derived));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200114 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);
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200117 assert_int_equal(1, LY_ARRAY_COUNT(mod->compiled->identities[1].derived));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200118 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
Michal Vasko33ff9422020-07-03 09:50:39 +0200130 /* base in non-implemented module */
131 ly_ctx_set_module_imp_clb(ctx, test_imp_clb,
132 "module base {namespace \"urn\"; prefix b; identity i1; identity i2 {base i1;}}");
133 TEST_SCHEMA_OK(ctx, 0, 0, "ident", "import base {prefix b;} identity ii {base b:i1;}", mod);
134
135 /* default value from non-implemented module */
136 TEST_SCHEMA_ERR(ctx, 0, 0, "ident2", "import base {prefix b;} leaf l {type identityref {base b:i1;} default b:i2;}",
137 "Invalid leaf's default value \"b:i2\" which does not fit the type (Invalid identityref \"b:i2\" value"
138 " - identity found in non-implemented module \"base\".). /ident2:l");
139
140 /* default value in typedef from non-implemented module */
141 TEST_SCHEMA_ERR(ctx, 0, 0, "ident2", "import base {prefix b;} typedef t1 {type identityref {base b:i1;} default b:i2;}"
142 "leaf l {type t1;}", "Invalid type's default value \"b:i2\" which does not fit the type (Invalid"
143 " identityref \"b:i2\" value - identity found in non-implemented module \"base\".). /ident2:l");
144
Radek Krejci3a4889a2020-05-19 17:01:58 +0200145 /*
146 * printing
147 */
148
149 /*
150 * cleanup
151 */
152
153 *state = NULL;
154 ly_ctx_destroy(ctx, NULL);
155}
156
157
Radek Krejci18abde42020-06-13 20:04:39 +0200158void
Radek Krejci3a4889a2020-05-19 17:01:58 +0200159test_feature(void **state)
160{
161 *state = test_feature;
162
163 struct ly_ctx *ctx;
164 struct lys_module *mod;
165 const struct lysc_feature *f, *f1;
166
167 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
168
169 /*
170 * parsing YANG
171 */
172
173 TEST_STMT_DUP(ctx, 1, 0, "feature f", "description", "a", "b", "1");
174 TEST_STMT_DUP(ctx, 1, 0, "feature f", "reference", "a", "b", "1");
175 TEST_STMT_DUP(ctx, 1, 0, "feature f", "status", "current", "obsolete", "1");
176
177 /* full content */
178 TEST_SCHEMA_OK(ctx, 1, 0, "featureone",
179 "feature test {description text;reference \'another text\';status current; if-feature x; if-feature y; featureone:ext;}"
180 "extension ext; feature x; feature y;", mod);
181 assert_non_null(mod->parsed->features);
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200182 assert_int_equal(3, LY_ARRAY_COUNT(mod->parsed->features));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200183
184 /* invalid substatement */
185 TEST_STMT_SUBSTM_ERR(ctx, 0, "feature", "organization", "XXX");
186
187 /*
188 * parsing YIN
189 */
190 /* max subelems */
191 TEST_SCHEMA_OK(ctx, 0, 1, "featureone-yin", "<feature name=\"feature-name\">"
192 "<if-feature name=\"iff\"/>"
193 "<status value=\"deprecated\"/>"
194 "<description><text>desc</text></description>"
195 "<reference><text>ref</text></reference>"
196 "<myext:ext xmlns:myext=\"urn:libyang:test:featureone-yin\"/>"
197 "</feature><extension name=\"ext\"/><feature name=\"iff\"/>", mod);
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200198 assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->features));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200199 assert_string_equal(mod->parsed->features[0].name, "feature-name");
200 assert_string_equal(mod->parsed->features[0].dsc, "desc");
201 assert_true(mod->parsed->features[0].flags & LYS_STATUS_DEPRC);
202 assert_string_equal(mod->parsed->features[0].iffeatures[0], "iff");
203 assert_string_equal(mod->parsed->features[0].ref, "ref");
204 assert_string_equal(mod->parsed->features[0].exts[0].name, "ext");
205 assert_int_equal(mod->parsed->features[0].exts[0].insubstmt_index, 0);
206 assert_int_equal(mod->parsed->features[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
207
208 /* min subelems */
209 TEST_SCHEMA_OK(ctx, 0, 1, "featuretwo-yin", "<feature name=\"feature-name\"/>", mod)
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200210 assert_int_equal(1, LY_ARRAY_COUNT(mod->parsed->features));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200211 assert_string_equal(mod->parsed->features[0].name, "feature-name");
212
213 /* invalid substatement */
214 TEST_SCHEMA_ERR(ctx, 0, 1, "inv", "<feature name=\"feature-name\"><organization><text>org</text></organization></feature>",
215 "Unexpected sub-element \"organization\" of \"feature\" element. Line number 1.");
216
217 /*
218 * compiling
219 */
220
221 TEST_SCHEMA_OK(ctx, 1, 0, "a", "feature f1 {description test1;reference test2;status current;} feature f2; feature f3;\n"
222 "feature orfeature {if-feature \"f1 or f2\";}\n"
223 "feature andfeature {if-feature \"f1 and f2\";}\n"
224 "feature f6 {if-feature \"not f1\";}\n"
225 "feature f7 {if-feature \"(f2 and f3) or (not f1)\";}\n"
226 "feature f8 {if-feature \"f1 or f2 or f3 or orfeature or andfeature\";}\n"
227 "feature f9 {if-feature \"not not f1\";}", mod);
228 assert_non_null(mod->compiled->features);
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200229 assert_int_equal(9, LY_ARRAY_COUNT(mod->compiled->features));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200230
231 /* all features are disabled by default */
232 LY_ARRAY_FOR(mod->compiled->features, struct lysc_feature, f) {
Michal Vasko28d78432020-05-26 13:10:53 +0200233 assert_int_equal(LY_ENOT, lysc_feature_value(f));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200234 }
235 /* enable f1 */
236 assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f1"));
237 f1 = &mod->compiled->features[0];
Michal Vasko28d78432020-05-26 13:10:53 +0200238 assert_int_equal(LY_SUCCESS, lysc_feature_value(f1));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200239
240 /* enable orfeature */
241 f = &mod->compiled->features[3];
Michal Vasko28d78432020-05-26 13:10:53 +0200242 assert_int_equal(LY_ENOT, lysc_feature_value(f));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200243 assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "orfeature"));
Michal Vasko28d78432020-05-26 13:10:53 +0200244 assert_int_equal(LY_SUCCESS, lysc_feature_value(f));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200245
246 /* enable andfeature - no possible since f2 is disabled */
247 f = &mod->compiled->features[4];
Michal Vasko28d78432020-05-26 13:10:53 +0200248 assert_int_equal(LY_ENOT, lysc_feature_value(f));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200249 assert_int_equal(LY_EDENIED, lys_feature_enable(mod, "andfeature"));
250 logbuf_assert("Feature \"andfeature\" cannot be enabled since it is disabled by its if-feature condition(s).");
Michal Vasko28d78432020-05-26 13:10:53 +0200251 assert_int_equal(LY_ENOT, lysc_feature_value(f));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200252
253 /* first enable f2, so f5 can be enabled then */
254 assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f2"));
255 assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "andfeature"));
Michal Vasko28d78432020-05-26 13:10:53 +0200256 assert_int_equal(LY_SUCCESS, lysc_feature_value(f));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200257
258 /* f1 is enabled, so f6 cannot be enabled */
259 f = &mod->compiled->features[5];
Michal Vasko28d78432020-05-26 13:10:53 +0200260 assert_int_equal(LY_ENOT, lysc_feature_value(f));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200261 assert_int_equal(LY_EDENIED, lys_feature_enable(mod, "f6"));
262 logbuf_assert("Feature \"f6\" cannot be enabled since it is disabled by its if-feature condition(s).");
Michal Vasko28d78432020-05-26 13:10:53 +0200263 assert_int_equal(LY_ENOT, lysc_feature_value(f));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200264
265 /* so disable f1 - andfeature will became also disabled */
Michal Vasko28d78432020-05-26 13:10:53 +0200266 assert_int_equal(LY_SUCCESS, lysc_feature_value(f1));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200267 assert_int_equal(LY_SUCCESS, lys_feature_disable(mod, "f1"));
Michal Vasko28d78432020-05-26 13:10:53 +0200268 assert_int_equal(LY_ENOT, lysc_feature_value(f1));
269 assert_int_equal(LY_ENOT, lysc_feature_value(&mod->compiled->features[4]));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200270 /* while orfeature is stille enabled */
Michal Vasko28d78432020-05-26 13:10:53 +0200271 assert_int_equal(LY_SUCCESS, lysc_feature_value(&mod->compiled->features[3]));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200272 /* and finally f6 can be enabled */
273 assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f6"));
Michal Vasko28d78432020-05-26 13:10:53 +0200274 assert_int_equal(LY_SUCCESS, lysc_feature_value(&mod->compiled->features[5]));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200275
276 /* complex evaluation of f7: f1 and f3 are disabled, while f2 is enabled */
Michal Vasko28d78432020-05-26 13:10:53 +0200277 assert_int_equal(LY_SUCCESS, lysc_iffeature_value(&mod->compiled->features[6].iffeatures[0]));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200278 /* long evaluation of f8 to need to reallocate internal stack for operators */
Michal Vasko28d78432020-05-26 13:10:53 +0200279 assert_int_equal(LY_SUCCESS, lysc_iffeature_value(&mod->compiled->features[7].iffeatures[0]));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200280
281 /* double negation of disabled f1 -> disabled */
Michal Vasko28d78432020-05-26 13:10:53 +0200282 assert_int_equal(LY_ENOT, lysc_iffeature_value(&mod->compiled->features[8].iffeatures[0]));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200283
284 /* disable all features */
285 assert_int_equal(LY_SUCCESS, lys_feature_disable(mod, "*"));
286 LY_ARRAY_FOR(mod->compiled->features, struct lysc_feature, f) {
287 assert_int_equal(0, lys_feature_value(mod, f->name));
288 }
289 /* re-setting already set feature */
290 assert_int_equal(LY_SUCCESS, lys_feature_disable(mod, "f1"));
291 assert_int_equal(0, lys_feature_value(mod, "f1"));
292
293 /* enabling feature that cannot be enabled due to its if-features */
294 assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f1"));
295 assert_int_equal(LY_EDENIED, lys_feature_enable(mod, "andfeature"));
296 logbuf_assert("Feature \"andfeature\" cannot be enabled since it is disabled by its if-feature condition(s).");
297 assert_int_equal(LY_EDENIED, lys_feature_enable(mod, "*"));
298 logbuf_assert("Feature \"f6\" cannot be enabled since it is disabled by its if-feature condition(s).");
299 /* test if not changed */
300 assert_int_equal(1, lys_feature_value(mod, "f1"));
301 assert_int_equal(0, lys_feature_value(mod, "f2"));
302
303 TEST_SCHEMA_OK(ctx, 0, 0, "b", "feature f1 {if-feature f2;}feature f2;", mod);
304 assert_non_null(mod->compiled);
305 assert_non_null(mod->compiled->features);
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200306 assert_int_equal(2, LY_ARRAY_COUNT(mod->compiled->features));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200307 assert_non_null(mod->compiled->features[0].iffeatures);
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200308 assert_int_equal(1, LY_ARRAY_COUNT(mod->compiled->features[0].iffeatures));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200309 assert_non_null(mod->compiled->features[0].iffeatures[0].features);
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200310 assert_int_equal(1, LY_ARRAY_COUNT(mod->compiled->features[0].iffeatures[0].features));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200311 assert_ptr_equal(&mod->compiled->features[1], mod->compiled->features[0].iffeatures[0].features[0]);
312 assert_non_null(mod->compiled->features);
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200313 assert_int_equal(2, LY_ARRAY_COUNT(mod->compiled->features));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200314 assert_non_null(mod->compiled->features[1].depfeatures);
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200315 assert_int_equal(1, LY_ARRAY_COUNT(mod->compiled->features[1].depfeatures));
Radek Krejci3a4889a2020-05-19 17:01:58 +0200316 assert_ptr_equal(&mod->compiled->features[0], mod->compiled->features[1].depfeatures[0]);
317
318 /* invalid reference */
319 assert_int_equal(LY_EINVAL, lys_feature_enable(mod, "xxx"));
320 logbuf_assert("Feature \"xxx\" not found in module \"b\".");
321
322 /* some invalid expressions */
323 TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f{if-feature f1;}",
324 "Invalid value \"f1\" of if-feature - unable to find feature \"f1\". /inv:{feature='f'}");
325 TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature 'f and';}",
326 "Invalid value \"f and\" of if-feature - unexpected end of expression. /inv:{feature='f2'}");
327 TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f{if-feature 'or';}",
328 "Invalid value \"or\" of if-feature - unexpected end of expression. /inv:{feature='f'}");
329 TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature '(f1';}",
330 "Invalid value \"(f1\" of if-feature - non-matching opening and closing parentheses. /inv:{feature='f2'}");
331 TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature 'f1)';}",
332 "Invalid value \"f1)\" of if-feature - non-matching opening and closing parentheses. /inv:{feature='f2'}");
333 TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature ---;}",
334 "Invalid value \"---\" of if-feature - unable to find feature \"---\". /inv:{feature='f2'}");
335 TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1; feature f2{if-feature 'not f1';}",
336 "Invalid value \"not f1\" of if-feature - YANG 1.1 expression in YANG 1.0 module. /inv:{feature='f2'}");
337 TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1; feature f1;",
338 "Duplicate identifier \"f1\" of feature statement. /inv:{feature='f1'}");
339
340 ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} feature f1;}");
341 TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "include inv_sub;feature f1;",
342 "Duplicate identifier \"f1\" of feature statement. /inv:{feature='f1'}");
343 TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1 {if-feature f2;} feature f2 {if-feature f1;}",
344 "Feature \"f1\" is indirectly referenced from itself. /inv:{feature='f2'}");
345 TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1 {if-feature f1;}",
346 "Feature \"f1\" is referenced from itself. /inv:{feature='f1'}");
347 TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f {if-feature ();}",
348 "Invalid value \"()\" of if-feature - number of features in expression does not match the required number of operands for the operations. /inv:{feature='f'}");
349 TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1(';}",
350 "Invalid value \"f1(\" of if-feature - non-matching opening and closing parentheses. /inv:{feature='f'}");
351 TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'and f1';}",
352 "Invalid value \"and f1\" of if-feature - missing feature/expression before \"and\" operation. /inv:{feature='f'}");
353 TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1 not ';}",
354 "Invalid value \"f1 not \" of if-feature - unexpected end of expression. /inv:{feature='f'}");
355 TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1 not not ';}",
356 "Invalid value \"f1 not not \" of if-feature - unexpected end of expression. /inv:{feature='f'}");
357 TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2; feature f {if-feature 'or f1 f2';}",
358 "Invalid value \"or f1 f2\" of if-feature - missing feature/expression before \"or\" operation. /inv:{feature='f'}");
359
360 /* import reference */
361 assert_non_null(mod = ly_ctx_get_module(ctx, "a", NULL));
362 assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f1"));
363 TEST_SCHEMA_OK(ctx, 0, 0, "c", "import a {prefix a;} feature f1; feature f2{if-feature 'a:f1';}", mod);
364 assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f2"));
365 assert_int_equal(0, lys_feature_value(mod, "f1"));
366 assert_int_equal(1, lys_feature_value(mod, "f2"));
367
368 /*
369 * printing
370 */
371
372 /*
373 * cleanup
374 */
375
376 *state = NULL;
377 ly_ctx_destroy(ctx, NULL);
378}