schema compile CHANGE partial support for choice/case nodes
- still work in progress - missing choice's default statement support
and most of the unit tests.
diff --git a/tests/src/test_parser_yang.c b/tests/src/test_parser_yang.c
index d4bc352..bc31e12 100644
--- a/tests/src/test_parser_yang.c
+++ b/tests/src/test_parser_yang.c
@@ -1562,6 +1562,59 @@
ly_ctx_destroy(ctx.ctx, NULL);
}
+static void
+test_choice(void **state)
+{
+ *state = test_choice;
+
+ struct lysp_module mod = {0};
+ struct ly_parser_ctx ctx = {0};
+ struct lysp_node_choice *ch = NULL;
+ const char *str;
+
+ assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
+ assert_non_null(ctx.ctx);
+ ctx.line = 1;
+ ctx.mod = &mod;
+ ctx.mod->version = 2; /* simulate YANG 1.1 */
+
+ /* invalid cardinality */
+#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
+ str = "ch {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
+ assert_int_equal(LY_EVALID, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch)); \
+ logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
+ lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL;
+
+ TEST_DUP("config", "true", "false");
+ TEST_DUP("default", "a", "b");
+ TEST_DUP("description", "text1", "text2");
+ TEST_DUP("mandatory", "true", "false");
+ TEST_DUP("reference", "1", "2");
+ TEST_DUP("status", "current", "obsolete");
+ TEST_DUP("when", "true", "false");
+#undef TEST_DUP
+
+ /* full content */
+ str = "ch {anydata any;anyxml anyxml; case c;choice ch;config false;container c;default c;description test;if-feature f;leaf l {type string;}"
+ "leaf-list ll {type string;} list li;mandatory true;reference test;status current;when true;m:ext;} ...";
+ assert_int_equal(LY_SUCCESS, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch));
+ assert_non_null(ch);
+ assert_int_equal(LYS_CHOICE, ch->nodetype);
+ assert_string_equal("ch", ch->name);
+ assert_string_equal("test", ch->dsc);
+ assert_non_null(ch->exts);
+ assert_non_null(ch->iffeatures);
+ assert_string_equal("test", ch->ref);
+ assert_non_null(ch->when);
+ assert_null(ch->parent);
+ assert_null(ch->next);
+ assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE, ch->flags);
+ lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL;
+
+ *state = NULL;
+ ly_ctx_destroy(ctx.ctx, NULL);
+}
+
int main(void)
{
const struct CMUnitTest tests[] = {
@@ -1579,6 +1632,7 @@
cmocka_unit_test_setup_teardown(test_leaf, logger_setup, logger_teardown),
cmocka_unit_test_setup_teardown(test_leaflist, logger_setup, logger_teardown),
cmocka_unit_test_setup_teardown(test_list, logger_setup, logger_teardown),
+ cmocka_unit_test_setup_teardown(test_choice, logger_setup, logger_teardown),
};
return cmocka_run_group_tests(tests, NULL, NULL);