schema CHANGE move when statement from common schema node structure
The when statement is not present in many of the lysc_node* and
lysp_node* structures. It is actually similar to the must statement
which is placed in the specific schema node structures, so it make sense
to move the when statement to the same place.
Some helpers functions to access the musts and whens were added.
diff --git a/tests/utests/schema/test_parser_yin.c b/tests/utests/schema/test_parser_yin.c
index 0b72851..a51fcf3 100644
--- a/tests/utests/schema/test_parser_yin.c
+++ b/tests/utests/schema/test_parser_yin.c
@@ -3056,6 +3056,7 @@
/* invalid combinations */
data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_EVALID);
+ lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
CHECK_LOG_CTX("Unexpected attribute \"name\" of \"input\" element.", "Line number 1.");
memset(&inout, 0, sizeof inout);
}
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index e37fd1d..52cee54 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -2028,6 +2028,7 @@
const struct lys_module *mod;
const struct lysc_node *parent, *child;
const struct lysc_node_container *cont;
+ const struct lysc_node_leaf *leaf;
const struct lysc_node_choice *choice;
const struct lysc_node_case *cs;
@@ -2052,20 +2053,23 @@
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule bsub {belongs-to b {prefix b;} grouping grp {leaf b {when 1; type string;} leaf c {type string;}}}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;include bsub;uses grp {when 2;}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled->data);
- assert_int_equal(LYS_LEAF, mod->compiled->data->nodetype);
- assert_string_equal("b", mod->compiled->data->name);
- assert_int_equal(2, LY_ARRAY_COUNT(mod->compiled->data->when));
- assert_int_equal(1, mod->compiled->data->when[0]->refcount);
- assert_non_null(mod->compiled->data->when[0]->context);
- assert_string_equal("b", mod->compiled->data->when[0]->context->name);
- assert_int_equal(2, mod->compiled->data->when[1]->refcount);
- assert_null(mod->compiled->data->when[1]->context);
- assert_int_equal(LYS_LEAF, mod->compiled->data->next->nodetype);
- assert_string_equal("c", mod->compiled->data->next->name);
- assert_int_equal(1, LY_ARRAY_COUNT(mod->compiled->data->next->when));
- assert_int_equal(2, mod->compiled->data->next->when[0]->refcount);
- assert_null(mod->compiled->data->next->when[0]->context);
+ leaf = (struct lysc_node_leaf *)mod->compiled->data;
+ assert_int_equal(LYS_LEAF, leaf->nodetype);
+ assert_string_equal("b", leaf->name);
+ assert_int_equal(2, LY_ARRAY_COUNT(leaf->when));
+ assert_int_equal(1, leaf->when[0]->refcount);
+ assert_non_null(leaf->when[0]->context);
+ assert_string_equal("b", leaf->when[0]->context->name);
+ assert_int_equal(2, leaf->when[1]->refcount);
+ assert_null(leaf->when[1]->context);
+
+ leaf = (struct lysc_node_leaf *)leaf->next;
+ assert_int_equal(LYS_LEAF, leaf->nodetype);
+ assert_string_equal("c", leaf->name);
+ assert_int_equal(1, LY_ARRAY_COUNT(leaf->when));
+ assert_int_equal(2, leaf->when[0]->refcount);
+ assert_null(leaf->when[0]->context);
UTEST_LOG_CLEAN;
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:ii;prefix ii;"
@@ -2397,9 +2401,9 @@
assert_string_equal("c", c->name);
assert_non_null(c->when);
assert_string_equal("lc2", ((const struct lysc_node_case *)c)->child->name);
- assert_non_null(((const struct lysc_node_case *)c)->child->when);
+ assert_non_null(lysc_node_when(((const struct lysc_node_case *)c)->child));
assert_string_equal("lc1", ((const struct lysc_node_case *)c)->child->next->name);
- assert_null(((const struct lysc_node_case *)c)->child->next->when);
+ assert_null(lysc_node_when(((const struct lysc_node_case *)c)->child->next));
assert_non_null(c = (const struct lysc_node_case *)c->next);
assert_string_equal("a", c->name);
diff --git a/tests/utests/utests.h b/tests/utests/utests.h
index 762e6d8..dc0a538 100644
--- a/tests/utests/utests.h
+++ b/tests/utests/utests.h
@@ -443,7 +443,7 @@
assert_int_equal((NODE)->nodetype, NODETYPE); \
CHECK_POINTER((NODE)->parent, PARENT); \
CHECK_STRING((NODE)->ref, REF); \
- CHECK_POINTER((NODE)->when, WHEN);
+ CHECK_POINTER(lysp_node_when((struct lysp_node *)NODE), WHEN);
/**
* @brief assert that lysc_notif structure members are correct
@@ -473,7 +473,7 @@
CHECK_POINTER((NODE)->parent, PARENT); \
CHECK_POINTER((NODE)->priv, PRIV); \
CHECK_STRING((NODE)->ref, REF); \
- CHECK_ARRAY((NODE)->when, WHEN);
+ CHECK_ARRAY(lysc_node_when((struct lysc_node *)NODE), WHEN);
/**
* @brief assert that lysc_action_inout structure members are correct
@@ -524,7 +524,7 @@
CHECK_POINTER((NODE)->parent, PARENT); \
CHECK_POINTER((NODE)->priv, PRIV); \
CHECK_STRING((NODE)->ref, REF); \
- CHECK_ARRAY((NODE)->when, WHEN);
+ CHECK_ARRAY(lysc_node_when((struct lysc_node *)NODE), WHEN);
/**
* @brief assert that lysc_node structure members are correct
@@ -557,7 +557,7 @@
assert_non_null((NODE)->prev); \
CHECK_POINTER((NODE)->priv, PRIV); \
CHECK_STRING((NODE)->ref, REF); \
- CHECK_ARRAY((NODE)->when, WHEN);
+ CHECK_ARRAY(lysc_node_when(NODE), WHEN);
/**
* @brief assert that lyd_meta structure members are correct