schema compile CHANGE anydata and anyxml support
diff --git a/tests/src/test_parser_yang.c b/tests/src/test_parser_yang.c
index f3d5777..e725f4a 100644
--- a/tests/src/test_parser_yang.c
+++ b/tests/src/test_parser_yang.c
@@ -1687,6 +1687,74 @@
ly_ctx_destroy(ctx.ctx, NULL);
}
+static void
+test_any(void **state, enum yang_keyword kw)
+{
+ *state = test_any;
+
+ struct lysp_module mod = {0};
+ struct ly_parser_ctx ctx = {0};
+ struct lysp_node_anydata *any = 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;
+ if (kw == YANG_ANYDATA) {
+ ctx.mod->version = 2; /* simulate YANG 1.1 */
+ } else {
+ ctx.mod->version = 1; /* simulate YANG 1.0 */
+ }
+
+ /* invalid cardinality */
+#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
+ str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
+ assert_int_equal(LY_EVALID, parse_any(&ctx, &str, kw, NULL, (struct lysp_node**)&any)); \
+ logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
+ lysp_node_free(ctx.ctx, (struct lysp_node*)any); any = NULL;
+
+ TEST_DUP("config", "true", "false");
+ 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 = "any {config true;description test;if-feature f;mandatory true;must 'expr';reference test;status current;when true;m:ext;} ...";
+ assert_int_equal(LY_SUCCESS, parse_any(&ctx, &str, kw, NULL, (struct lysp_node**)&any));
+ assert_non_null(any);
+ assert_int_equal(kw == YANG_ANYDATA ? LYS_ANYDATA : LYS_ANYXML, any->nodetype);
+ assert_string_equal("any", any->name);
+ assert_string_equal("test", any->dsc);
+ assert_non_null(any->exts);
+ assert_non_null(any->iffeatures);
+ assert_non_null(any->musts);
+ assert_string_equal("test", any->ref);
+ assert_non_null(any->when);
+ assert_null(any->parent);
+ assert_null(any->next);
+ assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR | LYS_MAND_TRUE, any->flags);
+ lysp_node_free(ctx.ctx, (struct lysp_node*)any); any = NULL;
+
+ *state = NULL;
+ ly_ctx_destroy(ctx.ctx, NULL);
+}
+
+static void
+test_anydata(void **state)
+{
+ return test_any(state, YANG_ANYDATA);
+}
+
+static void
+test_anyxml(void **state)
+{
+ return test_any(state, YANG_ANYXML);
+}
+
int main(void)
{
const struct CMUnitTest tests[] = {
@@ -1706,6 +1774,8 @@
cmocka_unit_test_setup_teardown(test_list, logger_setup, logger_teardown),
cmocka_unit_test_setup_teardown(test_choice, logger_setup, logger_teardown),
cmocka_unit_test_setup_teardown(test_case, logger_setup, logger_teardown),
+ cmocka_unit_test_setup_teardown(test_anydata, logger_setup, logger_teardown),
+ cmocka_unit_test_setup_teardown(test_anyxml, logger_setup, logger_teardown),
};
return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/src/test_tree_schema_compile.c b/tests/src/test_tree_schema_compile.c
index a1119d9..ec02274 100644
--- a/tests/src/test_tree_schema_compile.c
+++ b/tests/src/test_tree_schema_compile.c
@@ -715,6 +715,43 @@
ly_ctx_destroy(ctx, NULL);
}
+static void
+test_node_anydata(void **state)
+{
+ *state = test_node_anydata;
+
+ struct ly_ctx *ctx;
+ struct lys_module *mod;
+ struct lysc_node_anydata *any;
+
+ assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
+
+ assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;"
+ "anydata any {config false;mandatory true;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_compile(mod, 0));
+ any = (struct lysc_node_anydata*)mod->compiled->data;
+ assert_non_null(any);
+ assert_int_equal(LYS_ANYDATA, any->nodetype);
+ assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE, any->flags);
+
+ logbuf_clean();
+ assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;"
+ "anyxml any;}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_compile(mod, 0));
+ any = (struct lysc_node_anydata*)mod->compiled->data;
+ assert_non_null(any);
+ assert_int_equal(LYS_ANYXML, any->nodetype);
+ assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR, any->flags);
+ logbuf_assert("Use of anyxml to define configuration data is not recommended."); /* warning */
+
+ /* invalid */
+ assert_null(mod = lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;anydata any;}", LYS_IN_YANG));
+ logbuf_assert("Invalid keyword \"anydata\" as a child of \"module\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
+
+ *state = NULL;
+ ly_ctx_destroy(ctx, NULL);
+}
+
/**
* actually the same as length restriction (tested in test_type_length()), so just check the correct handling in appropriate types,
* do not test the expression itself
@@ -2198,6 +2235,7 @@
cmocka_unit_test_setup_teardown(test_node_leaflist, logger_setup, logger_teardown),
cmocka_unit_test_setup_teardown(test_node_list, logger_setup, logger_teardown),
cmocka_unit_test_setup_teardown(test_node_choice, logger_setup, logger_teardown),
+ cmocka_unit_test_setup_teardown(test_node_anydata, logger_setup, logger_teardown),
};
return cmocka_run_group_tests(tests, NULL, NULL);