libyang REFACTOR use freeing context
Fixes compiled extension memory leaks.
Refactoring included.
diff --git a/tests/utests/CMakeLists.txt b/tests/utests/CMakeLists.txt
index 0f41a8a..5bdbd0c 100644
--- a/tests/utests/CMakeLists.txt
+++ b/tests/utests/CMakeLists.txt
@@ -8,7 +8,6 @@
${CMAKE_CURRENT_SOURCE_DIR}/data/*.c
${CMAKE_CURRENT_SOURCE_DIR}/extensions/*.c
${CMAKE_CURRENT_SOURCE_DIR}/schema/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/schema/*.h
${CMAKE_CURRENT_SOURCE_DIR}/types/*.c
${CMAKE_CURRENT_SOURCE_DIR}/restriction/*.c
${CMAKE_CURRENT_SOURCE_DIR}/node/*.c
@@ -55,7 +54,7 @@
ly_add_utest(NAME xpath SOURCES basic/test_xpath.c)
ly_add_utest(NAME yanglib SOURCES basic/test_yanglib.c)
-ly_add_utest(NAME schema SOURCES schema/test_schema.c schema/test_schema_common.c schema/test_schema_stmts.c schema/test_schema_extensions.c)
+ly_add_utest(NAME schema SOURCES schema/test_schema.c)
ly_add_utest(NAME yang SOURCES schema/test_yang.c)
ly_add_utest(NAME yin SOURCES schema/test_yin.c)
ly_add_utest(NAME tree_schema_compile SOURCES schema/test_tree_schema_compile.c)
diff --git a/tests/utests/schema/test_schema.c b/tests/utests/schema/test_schema.c
index 13e516c..adbe085 100644
--- a/tests/utests/schema/test_schema.c
+++ b/tests/utests/schema/test_schema.c
@@ -1,9 +1,10 @@
-/*
+/**
* @file test_schema.c
- * @author: Radek Krejci <rkrejci@cesnet.cz>
+ * @author Radek Krejci <rkrejci@cesnet.cz>
+ * @author Michal Vasko <mvasko@cesnet.cz>
* @brief unit tests for schema related functions
*
- * Copyright (c) 2018-2019 CESNET, z.s.p.o.
+ * Copyright (c) 2018 - 2022 CESNET, z.s.p.o.
*
* This source code is licensed under BSD 3-Clause License (the "License").
* You may not use this file except in compliance with the License.
@@ -12,16 +13,21 @@
* https://opensource.org/licenses/BSD-3-Clause
*/
#define _UTEST_MAIN_
-#include "test_schema.h"
+#include "utests.h"
#include <string.h>
+#include "compat.h"
+#include "context.h"
#include "log.h"
#include "parser_schema.h"
+#include "plugins_exts.h"
#include "set.h"
+#include "tree_edit.h"
#include "tree_schema.h"
+#include "tree_schema_internal.h"
-LY_ERR
+static LY_ERR
test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format,
const char **module_data, void (**free_module_data)(void *model_data, void *user_data))
@@ -36,37 +42,1816 @@
return LY_SUCCESS;
}
-/**
- * DECLARE OTHER SCHEMA TESTS
- */
-/* test_schema_common.c */
-void test_getnext(void **state);
-void test_date(void **state);
-void test_revisions(void **state);
-void test_collision_typedef(void **state);
-void test_collision_grouping(void **state);
-void test_collision_identity(void **state);
-void test_collision_feature(void **state);
-void test_accessible_tree(void **state);
-void test_includes(void **state);
-void test_key_order(void **state);
-void test_disabled_enum(void **state);
+#define TEST_YANG_MODULE_10(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
+ "module "MOD_NAME" { namespace "MOD_NS"; prefix "MOD_PREFIX"; "CONTENT"}"
-/* test_schema_stmts.c */
-void test_identity(void **state);
-void test_feature(void **state);
+#define TEST_YANG_MODULE_11(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
+ "module "MOD_NAME" {yang-version 1.1; namespace "MOD_NS"; prefix "MOD_PREFIX"; "CONTENT"}"
-/* test_schema_extensions.c */
-void test_extension_argument(void **state);
-void test_extension_argument_element(void **state);
-void test_extension_compile(void **state);
-void test_ext_recursive(void **state);
+#define TEST_YIN_MODULE_10(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
+ "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\""MOD_NAME"\">" \
+ "<namespace uri=\""MOD_NS"\"/><prefix value=\""MOD_PREFIX"\"/>"CONTENT"</module>"
+
+#define TEST_YIN_MODULE_11(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
+ "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\""MOD_NAME"\"><yang-version value=\"1.1\"/>" \
+ "<namespace uri=\""MOD_NS"\"/><prefix value=\""MOD_PREFIX"\"/>"CONTENT"</module>"
+
+#define TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, STR) \
+ if (YIN) { \
+ if (RFC7950) { \
+ STR = TEST_YIN_MODULE_11(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
+ } else { \
+ STR = TEST_YIN_MODULE_10(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
+ } \
+ } else { /* YANG */ \
+ if (RFC7950) { \
+ STR = TEST_YANG_MODULE_11(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
+ } else { \
+ STR = TEST_YANG_MODULE_10(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
+ } \
+ }
+
+#define TEST_SCHEMA_OK(RFC7950, YIN, MOD_NAME, CONTENT, RESULT) \
+ { \
+ const char *test_str__; \
+ TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, &(RESULT))); \
+ }
+
+#define TEST_SCHEMA_ERR(RFC7950, YIN, MOD_NAME, CONTENT, ERRMSG, ERRPATH) \
+ { \
+ const char *test_str__; \
+ TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
+ assert_int_not_equal(lys_parse_mem(UTEST_LYCTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, NULL), LY_SUCCESS); \
+ CHECK_LOG_CTX(ERRMSG, ERRPATH); \
+ }
+
+#define TEST_SCHEMA_PARSE_ERR(RFC7950, YIN, MOD_NAME, CONTENT, ERRMSG, ERRPATH) \
+ { \
+ const char *test_str__; \
+ TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
+ assert_int_not_equal(lys_parse_mem(UTEST_LYCTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, NULL), LY_SUCCESS); \
+ CHECK_LOG_CTX("Parsing module \""MOD_NAME"\" failed.", NULL, ERRMSG, ERRPATH); \
+ }
+
+#define TEST_STMT_DUP(RFC7950, YIN, STMT, MEMBER, VALUE1, VALUE2, LINE) \
+ if (YIN) { \
+ TEST_SCHEMA_PARSE_ERR(RFC7950, YIN, "dup", "", "Duplicate keyword \""MEMBER"\".", "Line number "LINE"."); \
+ } else { \
+ TEST_SCHEMA_PARSE_ERR(RFC7950, YIN, "dup", STMT"{"MEMBER" "VALUE1";"MEMBER" "VALUE2";}", \
+ "Duplicate keyword \""MEMBER"\".", "Line number "LINE"."); \
+ }
+
+#define TEST_STMT_SUBSTM_ERR(RFC7950, STMT, SUBSTMT, VALUE) ;\
+ TEST_SCHEMA_PARSE_ERR(RFC7950, 0, "inv", STMT" test {"SUBSTMT" "VALUE";}", \
+ "Invalid keyword \""SUBSTMT"\" as a child of \""STMT"\".", "Line number 1.");
+
+struct module_clb_list {
+ const char *name;
+ const char *data;
+};
+
+static LY_ERR
+module_clb(const char *mod_name, const char *UNUSED(mod_rev), const char *submod_name,
+ const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format,
+ const char **module_data, void (**free_module_data)(void *model_data, void *user_data))
+{
+ struct module_clb_list *list = (struct module_clb_list *)user_data;
+
+ for (unsigned int i = 0; list[i].data; i++) {
+
+ if ((submod_name && !strcmp(list[i].name, submod_name)) ||
+ (!submod_name && mod_name && !strcmp(list[i].name, mod_name))) {
+ *module_data = list[i].data;
+ *format = LYS_IN_YANG;
+ *free_module_data = NULL;
+ return LY_SUCCESS;
+ }
+ }
+ return LY_EINVAL;
+}
+
+static void
+test_getnext(void **state)
+{
+ struct lys_module *mod;
+ const struct lysc_node *node = NULL, *four;
+ const struct lysc_node_container *cont;
+ const struct lysc_action *rpc;
+
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1; namespace urn:a;prefix a;"
+ "container a { container one {presence test;} leaf two {type string;} leaf-list three {type string;}"
+ " list four {config false;} choice x { leaf five {type string;} case y {leaf six {type string;}}}"
+ " anyxml seven; action eight {input {leaf eight-input {type string;}} output {leaf eight-output {type string;}}}"
+ " notification nine {leaf nine-data {type string;}}}"
+ "leaf b {type string;} leaf-list c {type string;} list d {config false;}"
+ "choice x { case empty-x { choice empty-xc { case nothing;}} leaf e {type string;} case y {leaf f {type string;}}} anyxml g;"
+ "rpc h {input {leaf h-input {type string;}} output {leaf h-output {type string;}}}"
+ "rpc i;"
+ "notification j {leaf i-data {type string;}}"
+ "notification k;}", LYS_IN_YANG, &mod));
+ assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
+ assert_string_equal("a", node->name);
+ cont = (const struct lysc_node_container *)node;
+ assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
+ assert_string_equal("b", node->name);
+ assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
+ assert_string_equal("c", node->name);
+ assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
+ assert_string_equal("d", node->name);
+ assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
+ assert_string_equal("e", node->name);
+ assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
+ assert_string_equal("f", node->name);
+ assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
+ assert_string_equal("g", node->name);
+ assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
+ assert_string_equal("h", node->name);
+ rpc = (const struct lysc_action *)node;
+ assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
+ assert_string_equal("i", node->name);
+ assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
+ assert_string_equal("j", node->name);
+ assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
+ assert_string_equal("k", node->name);
+ assert_null(node = lys_getnext(node, NULL, mod->compiled, 0));
+ /* Inside container */
+ assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
+ assert_string_equal("one", node->name);
+ assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
+ assert_string_equal("two", node->name);
+ assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
+ assert_string_equal("three", node->name);
+ assert_non_null(node = four = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
+ assert_string_equal("four", node->name);
+ assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
+ assert_string_equal("five", node->name);
+ assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
+ assert_string_equal("six", node->name);
+ assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
+ assert_string_equal("seven", node->name);
+ assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
+ assert_string_equal("eight", node->name);
+ assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
+ assert_string_equal("nine", node->name);
+ assert_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
+ /* Inside RPC */
+ assert_non_null(node = lys_getnext(node, (const struct lysc_node *)rpc, mod->compiled, 0));
+ assert_string_equal("h-input", node->name);
+ assert_null(node = lys_getnext(node, (const struct lysc_node *)rpc, mod->compiled, 0));
+
+ /* options */
+ assert_non_null(node = lys_getnext(four, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCHOICE));
+ assert_string_equal("x", node->name);
+ assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCHOICE));
+ assert_string_equal("seven", node->name);
+
+ assert_non_null(node = lys_getnext(four, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_NOCHOICE));
+ assert_string_equal("seven", node->name);
+
+ assert_non_null(node = lys_getnext(four, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCASE));
+ assert_string_equal("five", node->name);
+ assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCASE));
+ assert_string_equal("y", node->name);
+ assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCASE));
+ assert_string_equal("seven", node->name);
+
+ assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, LYS_GETNEXT_INTONPCONT));
+ assert_string_equal("one", node->name);
+
+ assert_non_null(node = lys_getnext(NULL, (const struct lysc_node *)rpc, mod->compiled, LYS_GETNEXT_OUTPUT));
+ assert_string_equal("h-output", node->name);
+ assert_null(node = lys_getnext(node, (const struct lysc_node *)rpc, mod->compiled, LYS_GETNEXT_OUTPUT));
+
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c; rpc c;}", LYS_IN_YANG, &mod));
+ assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0));
+ assert_string_equal("c", node->name);
+ assert_null(node = lys_getnext(node, NULL, mod->compiled, 0));
+
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; notification d;}", LYS_IN_YANG, &mod));
+ assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0));
+ assert_string_equal("d", node->name);
+ assert_null(node = lys_getnext(node, NULL, mod->compiled, 0));
+
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e; container c {container cc;} leaf a {type string;}}", LYS_IN_YANG, &mod));
+ assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0));
+ assert_string_equal("c", node->name);
+ assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, LYS_GETNEXT_INTONPCONT));
+ assert_string_equal("a", node->name);
+}
+
+static void
+test_date(void **state)
+{
+ assert_int_equal(LY_EINVAL, lysp_check_date(NULL, NULL, 0, "date"));
+ CHECK_LOG("Invalid argument date (lysp_check_date()).", NULL);
+ assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "x", 1, "date"));
+ CHECK_LOG("Invalid argument date_len (lysp_check_date()).", NULL);
+ assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "nonsencexx", 10, "date"));
+ CHECK_LOG("Invalid value \"nonsencexx\" of \"date\".", NULL);
+ assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "123x-11-11", 10, "date"));
+ CHECK_LOG("Invalid value \"123x-11-11\" of \"date\".", NULL);
+ assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-13-11", 10, "date"));
+ CHECK_LOG("Invalid value \"2018-13-11\" of \"date\".", NULL);
+ assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-11-41", 10, "date"));
+ CHECK_LOG("Invalid value \"2018-11-41\" of \"date\".", NULL);
+ assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-02-29", 10, "date"));
+ CHECK_LOG("Invalid value \"2018-02-29\" of \"date\".", NULL);
+ assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018.02-28", 10, "date"));
+ CHECK_LOG("Invalid value \"2018.02-28\" of \"date\".", NULL);
+ assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-02.28", 10, "date"));
+ CHECK_LOG("Invalid value \"2018-02.28\" of \"date\".", NULL);
+
+ assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2018-11-11", 10, "date"));
+ assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2018-02-28", 10, "date"));
+ assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2016-02-29", 10, "date"));
+}
+
+static void
+test_revisions(void **state)
+{
+ struct lysp_revision *revs = NULL, *rev;
+
+ /* no error, it just does nothing */
+ lysp_sort_revisions(NULL);
+ CHECK_LOG(NULL, NULL);
+
+ /* revisions are stored in wrong order - the newest is the last */
+ LY_ARRAY_NEW_RET(NULL, revs, rev, );
+ strcpy(rev->date, "2018-01-01");
+ LY_ARRAY_NEW_RET(NULL, revs, rev, );
+ strcpy(rev->date, "2018-12-31");
+
+ assert_int_equal(2, LY_ARRAY_COUNT(revs));
+ assert_string_equal("2018-01-01", &revs[0]);
+ assert_string_equal("2018-12-31", &revs[1]);
+ /* the order should be fixed, so the newest revision will be the first in the array */
+ lysp_sort_revisions(revs);
+ assert_string_equal("2018-12-31", &revs[0]);
+ assert_string_equal("2018-01-01", &revs[1]);
+
+ LY_ARRAY_FREE(revs);
+}
+
+static void
+test_collision_typedef(void **state)
+{
+ const char *str;
+ char *submod;
+ struct module_clb_list list[3] = {0};
+
+ list[0].name = "asub";
+ list[1].name = "bsub";
+
+ /* collision with a built-in type */
+ str = "module a {namespace urn:a; prefix a; typedef binary {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"binary\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef bits {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"bits\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef boolean {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"boolean\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef decimal64 {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"decimal64\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef empty {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"empty\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef enumeration {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"enumeration\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef int8 {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"int8\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef int16 {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"int16\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef int32 {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"int32\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef int64 {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"int64\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef instance-identifier {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"instance-identifier\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef identityref {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"identityref\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef leafref {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"leafref\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef string {type int8;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"string\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef union {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"union\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef uint8 {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"uint8\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef uint16 {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"uint16\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef uint32 {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"uint32\" of typedef statement - name collision with a built-in type.", NULL);
+ str = "module a {namespace urn:a; prefix a; typedef uint64 {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"uint64\" of typedef statement - name collision with a built-in type.", NULL);
+
+ str = "module mytypes {namespace urn:types; prefix t; typedef binary_ {type string;} typedef bits_ {type string;} typedef boolean_ {type string;} "
+ "typedef decimal64_ {type string;} typedef empty_ {type string;} typedef enumeration_ {type string;} typedef int8_ {type string;} typedef int16_ {type string;}"
+ "typedef int32_ {type string;} typedef int64_ {type string;} typedef instance-identifier_ {type string;} typedef identityref_ {type string;}"
+ "typedef leafref_ {type string;} typedef string_ {type int8;} typedef union_ {type string;} typedef uint8_ {type string;} typedef uint16_ {type string;}"
+ "typedef uint32_ {type string;} typedef uint64_ {type string;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+
+ /* collision in node's scope */
+ str = "module a {namespace urn:a; prefix a; container c {typedef y {type int8;} typedef y {type string;}}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"y\" of typedef statement - name collision with sibling type.", NULL);
+
+ /* collision with parent node */
+ str = "module a {namespace urn:a; prefix a; container c {container d {typedef y {type int8;}} typedef y {type string;}}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"y\" of typedef statement - name collision with another scoped type.", NULL);
+
+ /* collision with module's top-level */
+ str = "module a {namespace urn:a; prefix a; typedef x {type string;} container c {typedef x {type int8;}}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"x\" of typedef statement - scoped type collide with a top-level type.", NULL);
+
+ /* collision of submodule's node with module's top-level */
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} container c {typedef x {type string;}}}");
+ str = "module a {namespace urn:a; prefix a; include b; typedef x {type int8;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"x\" of typedef statement - scoped type collide with a top-level type.", NULL);
+
+ /* collision of module's node with submodule's top-level */
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type int8;}}");
+ str = "module a {namespace urn:a; prefix a; include b; container c {typedef x {type string;}}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"x\" of typedef statement - scoped type collide with a top-level type.", NULL);
+
+ /* collision of submodule's node with another submodule's top-level */
+ str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}";
+ list[0].data = "submodule asub {belongs-to a {prefix a;} typedef g {type int;}}";
+ list[1].data = "submodule bsub {belongs-to a {prefix a;} container c {typedef g {type int;}}}";
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"g\" of typedef statement - scoped type collide with a top-level type.", NULL);
+
+ /* collision of module's top-levels */
+ str = "module a {namespace urn:a; prefix a; typedef test {type string;} typedef test {type int8;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"test\" of typedef statement - name collision with another top-level type.", NULL);
+
+ /* collision of submodule's top-levels */
+ submod = "submodule asub {belongs-to a {prefix a;} typedef g {type int;} typedef g {type int;}}";
+ str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub;}";
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod);
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"g\" of typedef statement - name collision with another top-level type.", NULL);
+
+ /* collision of module's top-level with submodule's top-levels */
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type string;}}");
+ str = "module a {namespace urn:a; prefix a; include b; typedef x {type int8;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"x\" of typedef statement - name collision with another top-level type.", NULL);
+
+ /* collision of submodule's top-level with another submodule's top-levels */
+ str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}";
+ list[0].data = "submodule asub {belongs-to a {prefix a;} typedef g {type int;}}";
+ list[1].data = "submodule bsub {belongs-to a {prefix a;} typedef g {type int;}}";
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"g\" of typedef statement - name collision with another top-level type.", NULL);
+
+ /* error in type-stmt */
+ str = "module a {namespace urn:a; prefix a; container c {typedef x {type t{}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Unexpected end-of-input.", "Line number 1.");
+ UTEST_LOG_CLEAN;
+
+ /* no collision if the same names are in different scope */
+ str = "module a {yang-version 1.1; namespace urn:a; prefix a;"
+ "container c {typedef g {type int;}} container d {typedef g {type int;}}}";
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
+}
+
+static void
+test_collision_grouping(void **state)
+{
+ const char *str;
+ char *submod;
+ struct module_clb_list list[3] = {0};
+
+ list[0].name = "asub";
+ list[1].name = "bsub";
+
+ /* collision in node's scope */
+ str = "module a {namespace urn:a; prefix a; container c {grouping y; grouping y;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"y\" of grouping statement - name collision with sibling grouping.", NULL);
+
+ /* collision with parent node */
+ str = "module a {namespace urn:a; prefix a; container c {container d {grouping y;} grouping y;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"y\" of grouping statement - name collision with another scoped grouping.", NULL);
+
+ /* collision with module's top-level */
+ str = "module a {namespace urn:a; prefix a; grouping x; container c {grouping x;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"x\" of grouping statement - scoped grouping collide with a top-level grouping.", NULL);
+
+ /* collision of submodule's node with module's top-level */
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} container c {grouping x;}}");
+ str = "module a {namespace urn:a; prefix a; include b; grouping x;}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"x\" of grouping statement - scoped grouping collide with a top-level grouping.", NULL);
+
+ /* collision of module's node with submodule's top-level */
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} grouping x;}");
+ str = "module a {namespace urn:a; prefix a; include b; container c {grouping x;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"x\" of grouping statement - scoped grouping collide with a top-level grouping.", NULL);
+
+ /* collision of submodule's node with another submodule's top-level */
+ str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}";
+ list[0].data = "submodule asub {belongs-to a {prefix a;} grouping g;}";
+ list[1].data = "submodule bsub {belongs-to a {prefix a;} container c {grouping g;}}";
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"g\" of grouping statement - scoped grouping collide with a top-level grouping.", NULL);
+
+ /* collision of module's top-levels */
+ str = "module a {namespace urn:a; prefix a; grouping test; grouping test;}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"test\" of grouping statement - name collision with another top-level grouping.", NULL);
+
+ /* collision of submodule's top-levels */
+ submod = "submodule asub {belongs-to a {prefix a;} grouping g; grouping g;}";
+ str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub;}";
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod);
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"g\" of grouping statement - name collision with another top-level grouping.", NULL);
+
+ /* collision of module's top-level with submodule's top-levels */
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} grouping x;}");
+ str = "module a {namespace urn:a; prefix a; include b; grouping x;}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"x\" of grouping statement - name collision with another top-level grouping.", NULL);
+
+ /* collision of submodule's top-level with another submodule's top-levels */
+ str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}";
+ list[0].data = "submodule asub {belongs-to a {prefix a;} grouping g;}";
+ list[1].data = "submodule bsub {belongs-to a {prefix a;} grouping g;}";
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"g\" of grouping statement - name collision with another top-level grouping.", NULL);
+
+ /* collision in nested groupings, top-level */
+ str = "module a {namespace urn:a; prefix a; grouping g {grouping g;}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"g\" of grouping statement - scoped grouping collide with a top-level grouping.", NULL);
+
+ /* collision in nested groupings, in node */
+ str = "module a {namespace urn:a; prefix a; container c {grouping g {grouping g;}}}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"g\" of grouping statement - name collision with another scoped grouping.", NULL);
+
+ /* no collision if the same names are in different scope */
+ str = "module a {yang-version 1.1; namespace urn:a; prefix a;"
+ "container c {grouping g;} container d {grouping g;}}";
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
+}
+
+static void
+test_collision_identity(void **state)
+{
+ const char *str;
+ char *submod;
+ struct module_clb_list list[3] = {0};
+
+ list[0].name = "asub";
+ list[1].name = "bsub";
+
+ /* collision of module's top-levels */
+ str = "module a {yang-version 1.1; namespace urn:a; prefix a; identity g; identity g;}";
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"g\" of identity statement - name collision with another top-level identity.", NULL);
+
+ /* collision of submodule's top-levels */
+ submod = "submodule asub {belongs-to a {prefix a;} identity g; identity g;}";
+ str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub;}";
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod);
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"g\" of identity statement - name collision with another top-level identity.", NULL);
+
+ /* collision of module's top-level with submodule's top-levels */
+ submod = "submodule asub {belongs-to a {prefix a;} identity g;}";
+ str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; identity g;}";
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod);
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"g\" of identity statement - name collision with another top-level identity.", NULL);
+
+ /* collision of submodule's top-level with another submodule's top-levels */
+ str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}";
+ list[0].data = "submodule asub {belongs-to a {prefix a;} identity g;}";
+ list[1].data = "submodule bsub {belongs-to a {prefix a;} identity g;}";
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"g\" of identity statement - name collision with another top-level identity.", NULL);
+}
+
+static void
+test_collision_feature(void **state)
+{
+ const char *str;
+ char *submod;
+ struct module_clb_list list[3] = {0};
+
+ list[0].name = "asub";
+ list[1].name = "bsub";
+
+ /* collision of module's top-levels */
+ str = "module a {yang-version 1.1; namespace urn:a; prefix a; feature g; feature g;}";
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"g\" of feature statement - name collision with another top-level feature.", NULL);
+
+ /* collision of submodule's top-levels */
+ submod = "submodule asub {belongs-to a {prefix a;} feature g; feature g;}";
+ str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub;}";
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod);
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"g\" of feature statement - name collision with another top-level feature.", NULL);
+
+ /* collision of module's top-level with submodule's top-levels */
+ submod = "submodule asub {belongs-to a {prefix a;} feature g;}";
+ str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; feature g;}";
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod);
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"g\" of feature statement - name collision with another top-level feature.", NULL);
+
+ /* collision of submodule's top-level with another submodule's top-levels */
+ str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}";
+ list[0].data = "submodule asub {belongs-to a {prefix a;} feature g;}";
+ list[1].data = "submodule bsub {belongs-to a {prefix a;} feature g;}";
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
+ CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
+ "Duplicate identifier \"g\" of feature statement - name collision with another top-level feature.", NULL);
+}
+
+static void
+test_accessible_tree(void **state)
+{
+ const char *str;
+
+ /* config -> config */
+ str = "module a {\n"
+ " namespace urn:a;\n"
+ " prefix a;\n"
+ " container cont {\n"
+ " leaf l {\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ " container cont2 {\n"
+ " leaf l2 {\n"
+ " must ../../cont/l;\n"
+ " type leafref {\n"
+ " path /cont/l;\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+ CHECK_LOG_CTX(NULL, NULL);
+
+ /* config -> state leafref */
+ str = "module b {\n"
+ " namespace urn:b;\n"
+ " prefix b;\n"
+ " container cont {\n"
+ " config false;\n"
+ " leaf l {\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ " container cont2 {\n"
+ " leaf l2 {\n"
+ " type leafref {\n"
+ " path /cont/l;\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Invalid leafref path \"/cont/l\" - target is supposed to represent configuration data"
+ " (as the leafref does), but it does not.", "Schema location \"/b:cont2/l2\".");
+
+ /* config -> state must */
+ str = "module b {\n"
+ " namespace urn:b;\n"
+ " prefix b;\n"
+ " container cont {\n"
+ " config false;\n"
+ " leaf l {\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ " container cont2 {\n"
+ " leaf l2 {\n"
+ " must ../../cont/l;\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+ CHECK_LOG_CTX("Schema node \"cont\" for parent \"<config-root>\" not found; in expr \"../../cont\" "
+ "with context node \"/b:cont2/l2\".", NULL);
+
+ /* state -> config */
+ str = "module c {\n"
+ " namespace urn:c;\n"
+ " prefix c;\n"
+ " container cont {\n"
+ " leaf l {\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ " container cont2 {\n"
+ " config false;\n"
+ " leaf l2 {\n"
+ " must ../../cont/l;\n"
+ " type leafref {\n"
+ " path /cont/l;\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+ CHECK_LOG_CTX(NULL, NULL);
+
+ /* notif -> state */
+ str = "module d {\n"
+ " namespace urn:d;\n"
+ " prefix d;\n"
+ " container cont {\n"
+ " config false;\n"
+ " leaf l {\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ " notification notif {\n"
+ " leaf l2 {\n"
+ " must ../../cont/l;\n"
+ " type leafref {\n"
+ " path /cont/l;\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+ CHECK_LOG_CTX(NULL, NULL);
+
+ /* notif -> notif */
+ str = "module e {\n"
+ " namespace urn:e;\n"
+ " prefix e;\n"
+ " notification notif {\n"
+ " leaf l {\n"
+ " type empty;\n"
+ " }\n"
+ " leaf l2 {\n"
+ " must ../../notif/l;\n"
+ " type leafref {\n"
+ " path /notif/l;\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+ CHECK_LOG_CTX(NULL, NULL);
+
+ /* rpc input -> state */
+ str = "module f {\n"
+ " namespace urn:f;\n"
+ " prefix f;\n"
+ " container cont {\n"
+ " config false;\n"
+ " leaf l {\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ " rpc rp {\n"
+ " input {\n"
+ " leaf l2 {\n"
+ " must ../../cont/l;\n"
+ " type leafref {\n"
+ " path /cont/l;\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+ CHECK_LOG_CTX(NULL, NULL);
+
+ /* rpc input -> rpc input */
+ str = "module g {\n"
+ " namespace urn:g;\n"
+ " prefix g;\n"
+ " rpc rp {\n"
+ " input {\n"
+ " leaf l {\n"
+ " type empty;\n"
+ " }\n"
+ " leaf l2 {\n"
+ " must ../l;\n"
+ " type leafref {\n"
+ " path /rp/l;\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+ CHECK_LOG_CTX(NULL, NULL);
+
+ /* rpc input -> rpc output leafref */
+ str = "module h {\n"
+ " namespace urn:h;\n"
+ " prefix h;\n"
+ " rpc rp {\n"
+ " input {\n"
+ " leaf l2 {\n"
+ " type leafref {\n"
+ " path /rp/l;\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " output {\n"
+ " leaf l {\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Not found node \"l\" in path.", "Schema location \"/h:rp/input/l2\".");
+
+ /* rpc input -> rpc output must */
+ str = "module h {\n"
+ " namespace urn:h;\n"
+ " prefix h;\n"
+ " rpc rp {\n"
+ " input {\n"
+ " leaf l2 {\n"
+ " must ../l;\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ " output {\n"
+ " leaf l {\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+ CHECK_LOG_CTX("Schema node \"l\" for parent \"/h:rp\" not found; in expr \"../l\" with context node \"/h:rp/input/l2\".", NULL);
+
+ /* rpc input -> notif leafref */
+ str = "module i {\n"
+ " namespace urn:i;\n"
+ " prefix i;\n"
+ " rpc rp {\n"
+ " input {\n"
+ " leaf l2 {\n"
+ " type leafref {\n"
+ " path ../../notif/l;\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " notification notif {\n"
+ " leaf l {\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Not found node \"notif\" in path.", "Schema location \"/i:rp/input/l2\".");
+
+ /* rpc input -> notif must */
+ str = "module i {\n"
+ " namespace urn:i;\n"
+ " prefix i;\n"
+ " rpc rp {\n"
+ " input {\n"
+ " leaf l2 {\n"
+ " must /notif/l;\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " notification notif {\n"
+ " leaf l {\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+ CHECK_LOG_CTX("Schema node \"notif\" for parent \"<root>\" not found; in expr \"/notif\" "
+ "with context node \"/i:rp/input/l2\".", NULL);
+
+ /* action output -> state */
+ str = "module j {\n"
+ " yang-version 1.1;\n"
+ " namespace urn:j;\n"
+ " prefix j;\n"
+ " container cont {\n"
+ " list ll {\n"
+ " key k;\n"
+ " leaf k {\n"
+ " type string;\n"
+ " }\n"
+ " action act {\n"
+ " output {\n"
+ " leaf l2 {\n"
+ " must /cont/l;\n"
+ " type leafref {\n"
+ " path ../../../l;\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " leaf l {\n"
+ " config false;\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+ CHECK_LOG_CTX(NULL, NULL);
+
+ /* action output -> action input leafref */
+ str = "module k {\n"
+ " yang-version 1.1;\n"
+ " namespace urn:k;\n"
+ " prefix k;\n"
+ " container cont {\n"
+ " list ll {\n"
+ " key k;\n"
+ " leaf k {\n"
+ " type string;\n"
+ " }\n"
+ " action act {\n"
+ " input {\n"
+ " leaf l {\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ " output {\n"
+ " leaf l2 {\n"
+ " type leafref {\n"
+ " path ../l;\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Not found node \"l\" in path.", "Schema location \"/k:cont/ll/act/output/l2\".");
+
+ /* action output -> action input must */
+ str = "module k {\n"
+ " yang-version 1.1;\n"
+ " namespace urn:k;\n"
+ " prefix k;\n"
+ " container cont {\n"
+ " list ll {\n"
+ " key k;\n"
+ " leaf k {\n"
+ " type string;\n"
+ " }\n"
+ " action act {\n"
+ " input {\n"
+ " leaf l {\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ " output {\n"
+ " leaf l2 {\n"
+ " must /cont/ll/act/l;\n"
+ " type empty;\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+ CHECK_LOG_CTX("Schema node \"l\" for parent \"/k:cont/ll/act\" not found; in expr \"/cont/ll/act/l\" "
+ "with context node \"/k:cont/ll/act/output/l2\".", NULL);
+}
+
+static void
+test_includes(void **state)
+{
+ struct lys_module *mod;
+
+ {
+ /* YANG 1.0 - the missing include sub_a_two in main_a will be injected from sub_a_one */
+ struct module_clb_list list[] = {
+ {"main_a", "module main_a { namespace urn:test:main_a; prefix ma; include sub_a_one;}"},
+ {"sub_a_one", "submodule sub_a_one { belongs-to main_a { prefix ma; } include sub_a_two;}"},
+ {"sub_a_two", "submodule sub_a_two { belongs-to main_a { prefix ma; } }"},
+ {NULL, NULL}
+ };
+
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
+ mod = ly_ctx_load_module(UTEST_LYCTX, "main_a", NULL, NULL);
+ assert_non_null(mod);
+ assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->includes));
+ assert_true(mod->parsed->includes[1].injected);
+ }
+
+ {
+ /* YANG 1.1 - the missing include sub_b_two in main_b is error */
+ struct module_clb_list list[] = {
+ {"main_b", "module main_b { yang-version 1.1; namespace urn:test:main_b; prefix mb; include sub_b_one;}"},
+ {"sub_b_one", "submodule sub_b_one { yang-version 1.1; belongs-to main_b { prefix mb; } include sub_b_two;}"},
+ {"sub_b_two", "submodule sub_b_two { yang-version 1.1; belongs-to main_b { prefix mb; } }"},
+ {NULL, NULL}
+ };
+
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
+ mod = ly_ctx_load_module(UTEST_LYCTX, "main_b", NULL, NULL);
+ assert_null(mod);
+ CHECK_LOG_CTX("Loading \"main_b\" module failed.", NULL,
+ "Data model \"main_b\" not found in local searchdirs.", NULL,
+ "Parsing module \"main_b\" failed.", NULL,
+ "Including \"sub_b_one\" submodule into \"main_b\" failed.", NULL,
+ "Data model \"sub_b_one\" not found in local searchdirs.", NULL,
+ "Parsing submodule \"sub_b_one\" failed.", NULL,
+ "YANG 1.1 requires all submodules to be included from main module. But submodule \"sub_b_one\" includes "
+ "submodule \"sub_b_two\" which is not included by main module \"main_b\".", NULL,
+ "YANG version 1.1 expects all includes in main module, includes in submodules (sub_b_one) are not necessary.", NULL);
+ }
+
+ {
+ /* YANG 1.1 - all includes are in main_c, includes in submodules are not necessary, so expect warning */
+ struct module_clb_list list[] = {
+ {"main_c", "module main_c { yang-version 1.1; namespace urn:test:main_c; prefix mc; include sub_c_one; include sub_c_two;}"},
+ {"sub_c_one", "submodule sub_c_one { yang-version 1.1; belongs-to main_c { prefix mc; } include sub_c_two;}"},
+ {"sub_c_two", "submodule sub_c_two { yang-version 1.1; belongs-to main_c { prefix mc; } include sub_c_one;}"},
+ {NULL, NULL}
+ };
+
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
+ mod = ly_ctx_load_module(UTEST_LYCTX, "main_c", NULL, NULL);
+ assert_non_null(mod);
+ assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->includes));
+ assert_false(mod->parsed->includes[1].injected);
+ /* result is ok, but log includes the warning */
+ CHECK_LOG_CTX("YANG version 1.1 expects all includes in main module, includes in submodules (sub_c_two) are not necessary.", NULL);
+ }
+}
+
+static void
+test_key_order(void **state)
+{
+ struct lys_module *mod;
+ const struct lysc_node *node;
+
+ struct module_clb_list list1[] = {
+ {"a", "module a {"
+ "yang-version 1.1;"
+ "namespace urn:test:a;"
+ "prefix a;"
+ "list l {"
+ " key \"k1 k2\";"
+ " leaf k2 {type string;}"
+ " leaf k1 {type string;}"
+ "}"
+ "}"},
+ {NULL, NULL}
+ };
+
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list1);
+ mod = ly_ctx_load_module(UTEST_LYCTX, "a", NULL, NULL);
+ assert_non_null(mod);
+
+ node = lysc_node_child(mod->compiled->data);
+ assert_string_equal("k1", node->name);
+ node = node->next;
+ assert_string_equal("k2", node->name);
+
+ struct module_clb_list list2[] = {
+ {"b", "module b {"
+ "yang-version 1.1;"
+ "namespace urn:test:b;"
+ "prefix b;"
+ "list l {"
+ " key \"k1 k2 k3 k4\";"
+ " leaf k4 {type string;}"
+ " container c {"
+ " leaf l1 {type string;}"
+ " }"
+ " leaf k2 {type string;}"
+ " leaf l2 {type string;}"
+ " leaf k1 {type string;}"
+ " leaf k3 {type string;}"
+ "}"
+ "}"},
+ {NULL, NULL}
+ };
+
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list2);
+ mod = ly_ctx_load_module(UTEST_LYCTX, "b", NULL, NULL);
+ assert_non_null(mod);
+
+ node = lysc_node_child(mod->compiled->data);
+ assert_string_equal("k1", node->name);
+ node = node->next;
+ assert_string_equal("k2", node->name);
+ node = node->next;
+ assert_string_equal("k3", node->name);
+ node = node->next;
+ assert_string_equal("k4", node->name);
+}
+
+static void
+test_disabled_enum(void **state)
+{
+ const char *str;
+
+ /* no enabled enum */
+ str = "module a {"
+ "yang-version 1.1;"
+ "namespace urn:test:a;"
+ "prefix a;"
+ "feature f;"
+ "leaf l {type enumeration {"
+ " enum e1 {if-feature f;}"
+ " enum e2 {if-feature f;}"
+ "}}"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Enumeration type of node \"l\" without any (or all disabled) valid values.", "Schema location \"/a:l\".");
+
+ /* disabled default value */
+ str = "module a {"
+ "yang-version 1.1;"
+ "namespace urn:test:a;"
+ "prefix a;"
+ "feature f;"
+ "leaf l {"
+ " type enumeration {"
+ " enum e1 {if-feature f;}"
+ " enum e2;"
+ " }"
+ " default e1;"
+ "}"
+ "}";
+ assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+ CHECK_LOG_CTX("Invalid default - value does not fit the type (Invalid enumeration value \"e1\".).",
+ "Schema location \"/a:l\".");
+}
+
+static void
+test_identity(void **state)
+{
+ struct lys_module *mod, *mod_imp;
+
+ /*
+ * parsing YANG
+ */
+ TEST_STMT_DUP(1, 0, "identity id", "description", "a", "b", "1");
+ TEST_STMT_DUP(1, 0, "identity id", "reference", "a", "b", "1");
+ TEST_STMT_DUP(1, 0, "identity id", "status", "current", "obsolete", "1");
+
+ /* full content */
+ TEST_SCHEMA_OK(1, 0, "identityone",
+ "identity test {base \"a\";base b; description text;reference \'another text\';status current; if-feature x;if-feature y; identityone:ext;}"
+ "identity a; identity b; extension ext; feature x; feature y;", mod);
+ assert_non_null(mod->parsed->identities);
+ assert_int_equal(3, LY_ARRAY_COUNT(mod->parsed->identities));
+
+ /* invalid substatement */
+ TEST_STMT_SUBSTM_ERR(0, "identity", "organization", "XXX");
+
+ /*
+ * parsing YIN
+ */
+ /* max subelems */
+ TEST_SCHEMA_OK(1, 1, "identityone-yin", "<identity name=\"ident-name\">"
+ "<if-feature name=\"iff\"/>"
+ "<base name=\"base-name\"/>"
+ "<status value=\"deprecated\"/>"
+ "<description><text>desc</text></description>"
+ "<reference><text>ref</text></reference>"
+ /* TODO yin-extension-prefix-compilation-bug "<myext:ext xmlns:myext=\"urn:libyang:test:identityone-yin\"/>" */
+ "</identity><extension name=\"ext\"/><identity name=\"base-name\"/><feature name=\"iff\"/>", mod);
+ assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->identities));
+ assert_string_equal(mod->parsed->identities[0].name, "ident-name");
+ assert_string_equal(mod->parsed->identities[0].bases[0], "base-name");
+ assert_string_equal(mod->parsed->identities[0].iffeatures[0].str, "iff");
+ assert_string_equal(mod->parsed->identities[0].dsc, "desc");
+ assert_string_equal(mod->parsed->identities[0].ref, "ref");
+ assert_true(mod->parsed->identities[0].flags & LYS_STATUS_DEPRC);
+ /*assert_string_equal(mod->parsed->identities[0].exts[0].name, "ext");
+ assert_non_null(mod->parsed->identities[0].exts[0].compiled);
+ assert_int_equal(mod->parsed->identities[0].exts[0].yin, 1);
+ assert_int_equal(mod->parsed->identities[0].exts[0].insubstmt_index, 0);
+ assert_int_equal(mod->parsed->identities[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);*/
+
+ /* min subelems */
+ TEST_SCHEMA_OK(1, 1, "identitytwo-yin", "<identity name=\"ident-name\" />", mod);
+ assert_int_equal(1, LY_ARRAY_COUNT(mod->parsed->identities));
+ assert_string_equal(mod->parsed->identities[0].name, "ident-name");
+
+ /* invalid substatement */
+ TEST_SCHEMA_PARSE_ERR(0, 1, "inv", "<identity name=\"ident-name\"><if-feature name=\"iff\"/></identity>",
+ "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.");
+
+ /*
+ * compiling
+ */
+ TEST_SCHEMA_OK(0, 0, "a", "identity a1;", mod_imp);
+ TEST_SCHEMA_OK(1, 0, "b", "import a {prefix a;}"
+ "identity b1; identity b2; identity b3 {base b1; base b:b2; base a:a1;}"
+ "identity b4 {base b:b1; base b3;}", mod);
+ assert_non_null(mod_imp->compiled);
+ assert_non_null(mod_imp->identities);
+ assert_non_null(mod->identities);
+ assert_non_null(mod_imp->identities[0].derived);
+ assert_int_equal(1, LY_ARRAY_COUNT(mod_imp->identities[0].derived));
+ assert_ptr_equal(mod_imp->identities[0].derived[0], &mod->identities[2]);
+ assert_non_null(mod->identities[0].derived);
+ assert_int_equal(2, LY_ARRAY_COUNT(mod->identities[0].derived));
+ assert_ptr_equal(mod->identities[0].derived[0], &mod->identities[2]);
+ assert_ptr_equal(mod->identities[0].derived[1], &mod->identities[3]);
+ assert_non_null(mod->identities[1].derived);
+ assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[1].derived));
+ assert_ptr_equal(mod->identities[1].derived[0], &mod->identities[2]);
+ assert_non_null(mod->identities[2].derived);
+ assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[2].derived));
+ assert_ptr_equal(mod->identities[2].derived[0], &mod->identities[3]);
+
+ TEST_SCHEMA_OK(1, 0, "c", "identity c2 {base c1;} identity c1;", mod);
+ assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[1].derived));
+ assert_ptr_equal(mod->identities[1].derived[0], &mod->identities[0]);
+
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} identity i1;}");
+ TEST_SCHEMA_ERR(0, 0, "inv", "identity i1 {base i2;}", "Unable to find base (i2) of identity \"i1\".", "/inv:{identity='i1'}");
+ TEST_SCHEMA_ERR(0, 0, "inv", "identity i1 {base i1;}", "Identity \"i1\" is derived from itself.", "/inv:{identity='i1'}");
+ TEST_SCHEMA_ERR(0, 0, "inv", "identity i1 {base i2;}identity i2 {base i3;}identity i3 {base i1;}",
+ "Identity \"i1\" is indirectly derived from itself.", "/inv:{identity='i3'}");
+
+ /* base in non-implemented module */
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb,
+ "module base {namespace \"urn\"; prefix b; identity i1; identity i2 {base i1;}}");
+ TEST_SCHEMA_OK(0, 0, "ident", "import base {prefix b;} identity ii {base b:i1;}", mod);
+
+ /* default value from non-implemented module */
+ TEST_SCHEMA_ERR(0, 0, "ident2", "import base {prefix b;} leaf l {type identityref {base b:i1;} default b:i2;}",
+ "Invalid default - value does not fit the type (Invalid identityref \"b:i2\" value"
+ " - identity found in non-implemented module \"base\".).", "Schema location \"/ident2:l\".");
+
+ /* default value in typedef from non-implemented module */
+ TEST_SCHEMA_ERR(0, 0, "ident2", "import base {prefix b;} typedef t1 {type identityref {base b:i1;} default b:i2;}"
+ "leaf l {type t1;}", "Invalid default - value does not fit the type (Invalid"
+ " identityref \"b:i2\" value - identity found in non-implemented module \"base\".).", "Schema location \"/ident2:l\".");
+
+ /*
+ * printing
+ */
+
+ /*
+ * cleanup
+ */
+}
+
+static void
+test_feature(void **state)
+{
+ struct lys_module *mod;
+ const struct lysp_feature *f;
+
+ /*
+ * parsing YANG
+ */
+
+ TEST_STMT_DUP(1, 0, "feature f", "description", "a", "b", "1");
+ TEST_STMT_DUP(1, 0, "feature f", "reference", "a", "b", "1");
+ TEST_STMT_DUP(1, 0, "feature f", "status", "current", "obsolete", "1");
+
+ /* full content */
+ TEST_SCHEMA_OK(1, 0, "featureone",
+ "feature test {description text;reference \'another text\';status current; if-feature x; if-feature y; featureone:ext;}"
+ "extension ext; feature x; feature y;", mod);
+ assert_non_null(mod->parsed->features);
+ assert_int_equal(3, LY_ARRAY_COUNT(mod->parsed->features));
+
+ /* invalid substatement */
+ TEST_STMT_SUBSTM_ERR(0, "feature", "organization", "XXX");
+
+ /*
+ * parsing YIN
+ */
+ /* max subelems */
+ TEST_SCHEMA_OK(0, 1, "featureone-yin", "<feature name=\"feature-name\">"
+ "<if-feature name=\"iff\"/>"
+ "<status value=\"deprecated\"/>"
+ "<description><text>desc</text></description>"
+ "<reference><text>ref</text></reference>"
+ /* TODO yin-extension-prefix-compilation-bug "<myext:ext xmlns:myext=\"urn:libyang:test:featureone-yin\"/>" */
+ "</feature><extension name=\"ext\"/><feature name=\"iff\"/>", mod);
+ assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->features));
+ assert_string_equal(mod->parsed->features[0].name, "feature-name");
+ assert_string_equal(mod->parsed->features[0].dsc, "desc");
+ assert_true(mod->parsed->features[0].flags & LYS_STATUS_DEPRC);
+ assert_string_equal(mod->parsed->features[0].iffeatures[0].str, "iff");
+ assert_string_equal(mod->parsed->features[0].ref, "ref");
+ /*assert_string_equal(mod->parsed->features[0].exts[0].name, "ext");
+ assert_int_equal(mod->parsed->features[0].exts[0].insubstmt_index, 0);
+ assert_int_equal(mod->parsed->features[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);*/
+
+ /* min subelems */
+ TEST_SCHEMA_OK(0, 1, "featuretwo-yin", "<feature name=\"feature-name\"/>", mod)
+ assert_int_equal(1, LY_ARRAY_COUNT(mod->parsed->features));
+ assert_string_equal(mod->parsed->features[0].name, "feature-name");
+
+ /* invalid substatement */
+ TEST_SCHEMA_PARSE_ERR(0, 1, "inv", "<feature name=\"feature-name\"><organization><text>org</text></organization></feature>",
+ "Unexpected sub-element \"organization\" of \"feature\" element.", "Line number 1.");
+
+ /*
+ * compiling
+ */
+
+ TEST_SCHEMA_OK(1, 0, "a", "feature f1 {description test1;reference test2;status current;} feature f2; feature f3;\n"
+ "feature orfeature {if-feature \"f1 or f2\";}\n"
+ "feature andfeature {if-feature \"f1 and f2\";}\n"
+ "feature f6 {if-feature \"not f1\";}\n"
+ "feature f7 {if-feature \"(f2 and f3) or (not f1)\";}\n"
+ "feature f8 {if-feature \"f1 or f2 or f3 or orfeature or andfeature\";}\n"
+ "feature f9 {if-feature \"not not f1\";}", mod);
+ assert_non_null(mod->parsed->features);
+ assert_int_equal(9, LY_ARRAY_COUNT(mod->parsed->features));
+
+ /* all features are disabled by default */
+ LY_ARRAY_FOR(mod->parsed->features, struct lysp_feature, f) {
+ assert_false(f->flags & LYS_FENABLED);
+ }
+
+ /* some invalid expressions */
+ TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f{if-feature f1;}",
+ "Invalid value \"f1\" of if-feature - unable to find feature \"f1\".", NULL);
+ TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f2{if-feature 'f and';}",
+ "Invalid value \"f and\" of if-feature - unexpected end of expression.", NULL);
+ TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f{if-feature 'or';}",
+ "Invalid value \"or\" of if-feature - unexpected end of expression.", NULL);
+ TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f2{if-feature '(f1';}",
+ "Invalid value \"(f1\" of if-feature - non-matching opening and closing parentheses.", NULL);
+ TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f2{if-feature 'f1)';}",
+ "Invalid value \"f1)\" of if-feature - non-matching opening and closing parentheses.", NULL);
+ TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f2{if-feature ---;}",
+ "Invalid value \"---\" of if-feature - unable to find feature \"---\".", NULL);
+ TEST_SCHEMA_PARSE_ERR(0, 0, "inv", "feature f1; feature f2{if-feature 'not f1';}",
+ "Invalid value \"not f1\" of if-feature - YANG 1.1 expression in YANG 1.0 module.", NULL);
+
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} feature f1;}");
+ TEST_SCHEMA_PARSE_ERR(0, 0, "inv", "feature f1 {if-feature f2;} feature f2 {if-feature f1;}",
+ "Feature \"f1\" is indirectly referenced from itself.", NULL);
+ TEST_SCHEMA_PARSE_ERR(0, 0, "inv", "feature f1 {if-feature f1;}",
+ "Feature \"f1\" is referenced from itself.", NULL);
+ TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f {if-feature ();}",
+ "Invalid value \"()\" of if-feature - number of features in expression does not match the required number of operands for the operations.", NULL);
+ TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'f1(';}",
+ "Invalid value \"f1(\" of if-feature - non-matching opening and closing parentheses.", NULL);
+ TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'and f1';}",
+ "Invalid value \"and f1\" of if-feature - missing feature/expression before \"and\" operation.", NULL);
+ TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'f1 not ';}",
+ "Invalid value \"f1 not \" of if-feature - unexpected end of expression.", NULL);
+ TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'f1 not not ';}",
+ "Invalid value \"f1 not not \" of if-feature - unexpected end of expression.", NULL);
+ TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f2; feature f {if-feature 'or f1 f2';}",
+ "Invalid value \"or f1 f2\" of if-feature - missing feature/expression before \"or\" operation.", NULL);
+
+ /*
+ * printing
+ */
+
+ /*
+ * cleanup
+ */
+}
+
+static void
+test_extension_argument(void **state)
+{
+ struct lys_module *mod;
+ const char *mod_def_yang = "module a {\n"
+ " namespace \"urn:a\";\n"
+ " prefix a;\n\n"
+ " extension e {\n"
+ " argument name;\n"
+ " }\n\n"
+ " a:e \"aaa\";\n"
+ "}\n";
+ const char *mod_def_yin =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<module name=\"a\"\n"
+ " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
+ " xmlns:a=\"urn:a\">\n"
+ " <namespace uri=\"urn:a\"/>\n"
+ " <prefix value=\"a\"/>\n"
+ " <extension name=\"e\">\n"
+ " <argument name=\"name\"/>\n"
+ " </extension>\n"
+ " <a:e name=\"aaa\"/>\n"
+ "</module>\n";
+ const char *mod_test_yin, *mod_test_yang;
+ char *printed;
+
+ mod_test_yang = "module b {\n"
+ " namespace \"urn:b\";\n"
+ " prefix b;\n\n"
+ " import a {\n"
+ " prefix a;\n"
+ " }\n\n"
+ " a:e \"xxx\";\n"
+ "}\n";
+ mod_test_yin =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<module name=\"b\"\n"
+ " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
+ " xmlns:b=\"urn:b\"\n"
+ " xmlns:a=\"urn:a\">\n"
+ " <namespace uri=\"urn:b\"/>\n"
+ " <prefix value=\"b\"/>\n"
+ " <import module=\"a\">\n"
+ " <prefix value=\"a\"/>\n"
+ " </import>\n"
+ " <a:e name=\"xxx\"/>\n"
+ "</module>\n";
+
+ /* from YANG */
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, (void *)mod_def_yang);
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, mod_test_yang, LYS_IN_YANG, &mod));
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG, 0));
+ assert_string_equal(printed, mod_test_yang);
+ free(printed);
+
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YIN, 0));
+ assert_string_equal(printed, mod_test_yin);
+ free(printed);
+
+ assert_non_null(mod = ly_ctx_get_module(UTEST_LYCTX, "a", NULL));
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG, 0));
+ assert_string_equal(printed, mod_def_yang);
+ free(printed);
+
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YIN, 0));
+ assert_string_equal(printed, mod_def_yin);
+ free(printed);
+
+ /* context reset */
+ ly_ctx_destroy(UTEST_LYCTX);
+ ly_ctx_new(NULL, 0, &UTEST_LYCTX);
+
+ /* from YIN */
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, (void *)mod_def_yin);
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, mod_test_yin, LYS_IN_YIN, &mod));
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG, 0));
+ assert_string_equal(printed, mod_test_yang);
+ free(printed);
+
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YIN, 0));
+ assert_string_equal(printed, mod_test_yin);
+ free(printed);
+
+ assert_non_null(mod = ly_ctx_get_module(UTEST_LYCTX, "a", NULL));
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG, 0));
+ assert_string_equal(printed, mod_def_yang);
+ free(printed);
+
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YIN, 0));
+ assert_string_equal(printed, mod_def_yin);
+ free(printed);
+}
+
+static void
+test_extension_argument_element(void **state)
+{
+ struct lys_module *mod;
+ const char *mod_def_yang = "module a {\n"
+ " namespace \"urn:a\";\n"
+ " prefix a;\n\n"
+ " extension e {\n"
+ " argument name {\n"
+ " yin-element true;\n"
+ " }\n"
+ " }\n\n"
+ " a:e \"aaa\";\n"
+ "}\n";
+ const char *mod_def_yin =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<module name=\"a\"\n"
+ " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
+ " xmlns:a=\"urn:a\">\n"
+ " <namespace uri=\"urn:a\"/>\n"
+ " <prefix value=\"a\"/>\n"
+ " <extension name=\"e\">\n"
+ " <argument name=\"name\">\n"
+ " <yin-element value=\"true\"/>\n"
+ " </argument>\n"
+ " </extension>\n"
+ " <a:e>\n"
+ " <a:name>aaa</a:name>\n"
+ " </a:e>\n"
+ "</module>\n";
+ const char *mod_test_yin, *mod_test_yang;
+ char *printed;
+
+ mod_test_yang = "module b {\n"
+ " namespace \"urn:b\";\n"
+ " prefix b;\n\n"
+ " import a {\n"
+ " prefix a;\n"
+ " }\n\n"
+ " a:e \"xxx\";\n"
+ "}\n";
+ mod_test_yin =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<module name=\"b\"\n"
+ " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
+ " xmlns:b=\"urn:b\"\n"
+ " xmlns:a=\"urn:a\">\n"
+ " <namespace uri=\"urn:b\"/>\n"
+ " <prefix value=\"b\"/>\n"
+ " <import module=\"a\">\n"
+ " <prefix value=\"a\"/>\n"
+ " </import>\n"
+ " <a:e>\n"
+ " <a:name>xxx</a:name>\n"
+ " </a:e>\n"
+ "</module>\n";
+
+ /* from YANG */
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, (void *)mod_def_yang);
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, mod_test_yang, LYS_IN_YANG, &mod));
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG, 0));
+ assert_string_equal(printed, mod_test_yang);
+ free(printed);
+
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YIN, 0));
+ assert_string_equal(printed, mod_test_yin);
+ free(printed);
+
+ assert_non_null(mod = ly_ctx_get_module(UTEST_LYCTX, "a", NULL));
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG, 0));
+ assert_string_equal(printed, mod_def_yang);
+ free(printed);
+
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YIN, 0));
+ assert_string_equal(printed, mod_def_yin);
+ free(printed);
+
+ /* context reset */
+ ly_ctx_destroy(UTEST_LYCTX);
+ ly_ctx_new(NULL, 0, &UTEST_LYCTX);
+
+ /* from YIN */
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, (void *)mod_def_yin);
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, mod_test_yin, LYS_IN_YIN, &mod));
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG, 0));
+ assert_string_equal(printed, mod_test_yang);
+ free(printed);
+
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YIN, 0));
+ assert_string_equal(printed, mod_test_yin);
+ free(printed);
+
+ assert_non_null(mod = ly_ctx_get_module(UTEST_LYCTX, "a", NULL));
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG, 0));
+ assert_string_equal(printed, mod_def_yang);
+ free(printed);
+
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YIN, 0));
+ assert_string_equal(printed, mod_def_yin);
+ free(printed);
+
+ /* invalid */
+ mod_test_yang = "module x { namespace \"urn:x\"; prefix x; import a { prefix a; } a:e; }";
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, mod_test_yang, LYS_IN_YANG, NULL));
+ CHECK_LOG_CTX("Extension instance \"a:e\" misses argument element \"name\".", "/x:{extension='a:e'}");
+
+ mod_test_yin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<module name=\"x\"\n"
+ " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
+ " xmlns:x=\"urn:x\"\n"
+ " xmlns:a=\"urn:a\">\n"
+ " <namespace uri=\"urn:x\"/>\n"
+ " <prefix value=\"x\"/>\n"
+ " <import module=\"a\">\n"
+ " <prefix value=\"a\"/>\n"
+ " </import>\n\n"
+ " <a:e/>\n"
+ "</module>\n";
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, mod_test_yin, LYS_IN_YIN, NULL));
+ CHECK_LOG_CTX("Extension instance \"a:e\" misses argument element \"name\".", "/x:{extension='a:e'}");
+
+ mod_test_yin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<module name=\"x\"\n"
+ " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
+ " xmlns:x=\"urn:x\"\n"
+ " xmlns:a=\"urn:a\">\n"
+ " <namespace uri=\"urn:x\"/>\n"
+ " <prefix value=\"x\"/>\n"
+ " <import module=\"a\">\n"
+ " <prefix value=\"a\"/>\n"
+ " </import>\n\n"
+ " <a:e name=\"xxx\"/>\n"
+ "</module>\n";
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, mod_test_yin, LYS_IN_YIN, NULL));
+ CHECK_LOG_CTX("Extension instance \"a:e\" misses argument element \"name\".", "/x:{extension='a:e'}");
+
+ mod_test_yin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<module name=\"x\"\n"
+ " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
+ " xmlns:x=\"urn:x\"\n"
+ " xmlns:a=\"urn:a\">\n"
+ " <namespace uri=\"urn:x\"/>\n"
+ " <prefix value=\"x\"/>\n"
+ " <import module=\"a\">\n"
+ " <prefix value=\"a\"/>\n"
+ " </import>\n\n"
+ " <a:e>\n"
+ " <x:name>xxx</x:name>\n"
+ " </a:e>\n"
+ "</module>\n";
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, mod_test_yin, LYS_IN_YIN, NULL));
+ CHECK_LOG_CTX("Extension instance \"a:e\" element and its argument element \"name\" are expected in the same namespace, but they differ.",
+ "/x:{extension='a:e'}");
+
+ mod_test_yin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<module name=\"x\"\n"
+ " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
+ " xmlns:x=\"urn:x\"\n"
+ " xmlns:a=\"urn:a\">\n"
+ " <namespace uri=\"urn:x\"/>\n"
+ " <prefix value=\"x\"/>\n"
+ " <import module=\"a\">\n"
+ " <prefix value=\"a\"/>\n"
+ " </import>\n\n"
+ " <a:e>\n"
+ " <a:value>xxx</a:value>\n"
+ " </a:e>\n"
+ "</module>\n";
+ assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, mod_test_yin, LYS_IN_YIN, NULL));
+ CHECK_LOG_CTX("Extension instance \"a:e\" expects argument element \"name\" as its first XML child, but \"value\" element found.",
+ "/x:{extension='a:e'}");
+
+}
+
+static void
+test_extension_compile(void **state)
+{
+ struct lys_module *mod;
+ struct lysc_ctx cctx = {0};
+ struct lysp_ext_instance ext_p = {0};
+ struct lysp_stmt child = {0};
+ struct lysc_ext_instance ext_c = {0};
+ struct lysc_ext_substmt *substmt;
+ LY_ERR rc = LY_SUCCESS;
+
+ /* current module, whatever */
+ mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "yang");
+ assert_true(mod);
+
+ /* compile context */
+ cctx.ctx = UTEST_LYCTX;
+ cctx.cur_mod = mod;
+ cctx.pmod = mod->parsed;
+ cctx.path_len = 1;
+ cctx.path[0] = '/';
+
+ /* parsed ext instance */
+ lydict_insert(UTEST_LYCTX, "pref:my-ext", 0, &ext_p.name);
+ ext_p.format = LY_VALUE_JSON;
+ ext_p.parent_stmt = LY_STMT_MODULE;
+
+ /* compiled ext instance */
+ ext_c.parent_stmt = ext_p.parent_stmt;
+ // ext_c.parent =
+ LY_ARRAY_NEW_GOTO(UTEST_LYCTX, ext_c.substmts, substmt, rc, cleanup);
+
+ /*
+ * error-message
+ */
+ ext_p.child = &child;
+ lydict_insert(UTEST_LYCTX, "error-message", 0, &child.stmt);
+ lydict_insert(UTEST_LYCTX, "my error", 0, &child.arg);
+ child.format = LY_VALUE_JSON;
+ child.kw = LY_STMT_ERROR_MESSAGE;
+
+ substmt->stmt = LY_STMT_ERROR_MESSAGE;
+ substmt->cardinality = LY_STMT_CARD_OPT;
+ substmt->storage = &ext_c.data;
+
+ /* compile */
+ assert_int_equal(LY_SUCCESS, lys_compile_extension_instance(&cctx, &ext_p, &ext_c));
+
+ /* check */
+ assert_string_equal(ext_c.data, "my error");
+
+cleanup:
+ lydict_remove(UTEST_LYCTX, ext_p.name);
+ lydict_remove(UTEST_LYCTX, child.stmt);
+ lydict_remove(UTEST_LYCTX, child.arg);
+ LY_ARRAY_FREE(ext_c.substmts);
+
+ lydict_remove(UTEST_LYCTX, ext_c.data);
+ if (rc) {
+ fail();
+ }
+}
+
+static void
+test_ext_recursive(void **state)
+{
+ const char *mod_base_yang, *mod_imp_yang, *mod_base_yin, *mod_imp_yin;
+
+ mod_imp_yang = "module b {\n"
+ " namespace \"urn:b\";\n"
+ " prefix b;\n\n"
+ " extension use-in {\n"
+ " argument name {\n"
+ " b:arg-type {\n"
+ " type string;\n"
+ " }\n"
+ " }\n"
+ " b:use-in \"extension\";\n"
+ " b:occurence \"*\";\n"
+ " }\n"
+ "\n"
+ " extension substatement {\n"
+ " argument name {\n"
+ " b:arg-type {\n"
+ " type string;\n"
+ " }\n"
+ " }\n"
+ " b:use-in \"extension\";\n"
+ " b:occurence \"*\";\n"
+ " b:substatement \"b:occurence\";\n"
+ " }\n"
+ "\n"
+ " extension arg-type {\n"
+ " b:use-in \"argument\";\n"
+ " b:substatement \"type\" {\n"
+ " b:occurence \"1\";\n"
+ " }\n"
+ " b:substatement \"default\";\n"
+ " }\n"
+ "\n"
+ " extension occurence {\n"
+ " argument value {\n"
+ " b:arg-type {\n"
+ " type enumeration {\n"
+ " enum \"?\";\n"
+ " enum \"*\";\n"
+ " enum \"+\";\n"
+ " enum \"1\";\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " b:use-in \"extension\";\n"
+ " }\n"
+ "}\n";
+
+ mod_imp_yin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<module name=\"b\"\n"
+ " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
+ " xmlns:b=\"urn:b\"\n"
+ " xmlns:a=\"urn:a\">\n"
+ " <namespace uri=\"urn:b\"/>\n"
+ " <prefix value=\"b\"/>\n"
+ " <import module=\"a\">\n"
+ " <prefix value=\"a\"/>\n"
+ " </import>\n\n"
+ " <a:e name=\"xxx\"/>\n"
+ "</module>\n";
+
+ mod_base_yang = "module a {\n"
+ " namespace \"urn:a\";\n"
+ " prefix a;\n\n"
+ " import b {\n"
+ " prefix b;\n"
+ " }\n"
+ "\n"
+ " extension abstract {\n"
+ " b:use-in \"identity\";\n"
+ " }\n"
+ "\n"
+ " identity mount-id;\n"
+ "\n"
+ " identity yang-lib-id {\n"
+ " base mount-id;\n"
+ " a:abstract;\n"
+ " }\n"
+ "}\n";
+
+ mod_base_yin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<module name=\"a\"\n"
+ " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
+ " xmlns:a=\"urn:a\">\n"
+ " <namespace uri=\"urn:a\"/>\n"
+ " <prefix value=\"a\"/>\n\n"
+ " <extension name=\"e\">\n"
+ " <argument name=\"name\"/>\n"
+ " </extension>\n\n"
+ " <a:e name=\"aaa\"/>\n"
+ "</module>\n";
+
+ /* from YANG */
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, (void *)mod_imp_yang);
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, mod_base_yang, LYS_IN_YANG, NULL));
+
+ /* context reset */
+ ly_ctx_destroy(UTEST_LYCTX);
+ ly_ctx_new(NULL, 0, &UTEST_LYCTX);
+
+ /* from YIN */
+ ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, (void *)mod_imp_yin);
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, mod_base_yin, LYS_IN_YIN, NULL));
+}
int
main(void)
{
const struct CMUnitTest tests[] = {
- /** test_schema_common.c */
UTEST(test_getnext),
UTEST(test_date),
UTEST(test_revisions),
@@ -78,12 +1863,8 @@
UTEST(test_includes),
UTEST(test_key_order),
UTEST(test_disabled_enum),
-
- /** test_schema_stmts.c */
UTEST(test_identity),
UTEST(test_feature),
-
- /** test_schema_extensions.c */
UTEST(test_extension_argument),
UTEST(test_extension_argument_element),
UTEST(test_extension_compile),
diff --git a/tests/utests/schema/test_schema.h b/tests/utests/schema/test_schema.h
deleted file mode 100644
index b7588dc..0000000
--- a/tests/utests/schema/test_schema.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * @file test_schema.h
- * @author: Radek Krejci <rkrejci@cesnet.cz>
- * @brief macros for schema tests
- *
- * Copyright (c) 2018-2020 CESNET, z.s.p.o.
- *
- * This source code is licensed under BSD 3-Clause License (the "License").
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- */
-
-#ifndef TESTS_UTESTS_SCHEMA_TEST_SCHEMA_H_
-#define TESTS_UTESTS_SCHEMA_TEST_SCHEMA_H_
-
-#include "utests.h"
-
-#include "log.h"
-#include "parser_schema.h"
-#include "set.h"
-#include "tests_config.h"
-
-LY_ERR test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
- const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT * format,
- const char **module_data, void (**free_module_data)(void *model_data, void *user_data));
-
-#define TEST_YANG_MODULE_10(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
- "module "MOD_NAME" { namespace "MOD_NS"; prefix "MOD_PREFIX"; "CONTENT"}"
-
-#define TEST_YANG_MODULE_11(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
- "module "MOD_NAME" {yang-version 1.1; namespace "MOD_NS"; prefix "MOD_PREFIX"; "CONTENT"}"
-
-#define TEST_YIN_MODULE_10(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
- "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\""MOD_NAME"\">" \
- "<namespace uri=\""MOD_NS"\"/><prefix value=\""MOD_PREFIX"\"/>"CONTENT"</module>"
-
-#define TEST_YIN_MODULE_11(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
- "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\""MOD_NAME"\"><yang-version value=\"1.1\"/>" \
- "<namespace uri=\""MOD_NS"\"/><prefix value=\""MOD_PREFIX"\"/>"CONTENT"</module>"
-
-#define TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, STR) \
- if (YIN) { \
- if (RFC7950) { \
- STR = TEST_YIN_MODULE_11(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
- } else { \
- STR = TEST_YIN_MODULE_10(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
- } \
- } else { /* YANG */ \
- if (RFC7950) { \
- STR = TEST_YANG_MODULE_11(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
- } else { \
- STR = TEST_YANG_MODULE_10(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
- } \
- }
-
-#define TEST_SCHEMA_OK(RFC7950, YIN, MOD_NAME, CONTENT, RESULT) \
- { \
- const char *test_str__; \
- TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
- assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, &(RESULT))); \
- }
-
-#define TEST_SCHEMA_ERR(RFC7950, YIN, MOD_NAME, CONTENT, ERRMSG, ERRPATH) \
- { \
- const char *test_str__; \
- TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
- assert_int_not_equal(lys_parse_mem(UTEST_LYCTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, NULL), LY_SUCCESS); \
- CHECK_LOG_CTX(ERRMSG, ERRPATH); \
- }
-
-#define TEST_SCHEMA_PARSE_ERR(RFC7950, YIN, MOD_NAME, CONTENT, ERRMSG, ERRPATH) \
- { \
- const char *test_str__; \
- TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
- assert_int_not_equal(lys_parse_mem(UTEST_LYCTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, NULL), LY_SUCCESS); \
- CHECK_LOG_CTX("Parsing module \""MOD_NAME"\" failed.", NULL, ERRMSG, ERRPATH); \
- }
-
-#define TEST_STMT_DUP(RFC7950, YIN, STMT, MEMBER, VALUE1, VALUE2, LINE) \
- if (YIN) { \
- TEST_SCHEMA_PARSE_ERR(RFC7950, YIN, "dup", "", "Duplicate keyword \""MEMBER"\".", "Line number "LINE"."); \
- } else { \
- TEST_SCHEMA_PARSE_ERR(RFC7950, YIN, "dup", STMT"{"MEMBER" "VALUE1";"MEMBER" "VALUE2";}", \
- "Duplicate keyword \""MEMBER"\".", "Line number "LINE"."); \
- }
-
-#define TEST_STMT_SUBSTM_ERR(RFC7950, STMT, SUBSTMT, VALUE) ;\
- TEST_SCHEMA_PARSE_ERR(RFC7950, 0, "inv", STMT" test {"SUBSTMT" "VALUE";}", \
- "Invalid keyword \""SUBSTMT"\" as a child of \""STMT"\".", "Line number 1.");
-
-#endif /* TESTS_UTESTS_SCHEMA_TEST_SCHEMA_H_ */
diff --git a/tests/utests/schema/test_schema_common.c b/tests/utests/schema/test_schema_common.c
deleted file mode 100644
index 42ec7c0..0000000
--- a/tests/utests/schema/test_schema_common.c
+++ /dev/null
@@ -1,1094 +0,0 @@
-/*
- * @file test_schema_common.c
- * @author: Radek Krejci <rkrejci@cesnet.cz>
- * @brief unit tests for functions from common.c
- *
- * Copyright (c) 2018 CESNET, z.s.p.o.
- *
- * This source code is licensed under BSD 3-Clause License (the "License").
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- */
-#include "test_schema.h"
-
-#include <string.h>
-
-#include "compat.h"
-#include "context.h"
-#include "log.h"
-#include "tree_edit.h"
-#include "tree_schema.h"
-#include "tree_schema_internal.h"
-
-struct module_clb_list {
- const char *name;
- const char *data;
-};
-
-static LY_ERR
-module_clb(const char *mod_name, const char *UNUSED(mod_rev), const char *submod_name,
- const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format,
- const char **module_data, void (**free_module_data)(void *model_data, void *user_data))
-{
- struct module_clb_list *list = (struct module_clb_list *)user_data;
-
- for (unsigned int i = 0; list[i].data; i++) {
-
- if ((submod_name && !strcmp(list[i].name, submod_name)) ||
- (!submod_name && mod_name && !strcmp(list[i].name, mod_name))) {
- *module_data = list[i].data;
- *format = LYS_IN_YANG;
- *free_module_data = NULL;
- return LY_SUCCESS;
- }
- }
- return LY_EINVAL;
-}
-
-void
-test_getnext(void **state)
-{
- struct lys_module *mod;
- const struct lysc_node *node = NULL, *four;
- const struct lysc_node_container *cont;
- const struct lysc_action *rpc;
-
- assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1; namespace urn:a;prefix a;"
- "container a { container one {presence test;} leaf two {type string;} leaf-list three {type string;}"
- " list four {config false;} choice x { leaf five {type string;} case y {leaf six {type string;}}}"
- " anyxml seven; action eight {input {leaf eight-input {type string;}} output {leaf eight-output {type string;}}}"
- " notification nine {leaf nine-data {type string;}}}"
- "leaf b {type string;} leaf-list c {type string;} list d {config false;}"
- "choice x { case empty-x { choice empty-xc { case nothing;}} leaf e {type string;} case y {leaf f {type string;}}} anyxml g;"
- "rpc h {input {leaf h-input {type string;}} output {leaf h-output {type string;}}}"
- "rpc i;"
- "notification j {leaf i-data {type string;}}"
- "notification k;}", LYS_IN_YANG, &mod));
- assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
- assert_string_equal("a", node->name);
- cont = (const struct lysc_node_container *)node;
- assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
- assert_string_equal("b", node->name);
- assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
- assert_string_equal("c", node->name);
- assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
- assert_string_equal("d", node->name);
- assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
- assert_string_equal("e", node->name);
- assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
- assert_string_equal("f", node->name);
- assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
- assert_string_equal("g", node->name);
- assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
- assert_string_equal("h", node->name);
- rpc = (const struct lysc_action *)node;
- assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
- assert_string_equal("i", node->name);
- assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
- assert_string_equal("j", node->name);
- assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0));
- assert_string_equal("k", node->name);
- assert_null(node = lys_getnext(node, NULL, mod->compiled, 0));
- /* Inside container */
- assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
- assert_string_equal("one", node->name);
- assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
- assert_string_equal("two", node->name);
- assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
- assert_string_equal("three", node->name);
- assert_non_null(node = four = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
- assert_string_equal("four", node->name);
- assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
- assert_string_equal("five", node->name);
- assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
- assert_string_equal("six", node->name);
- assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
- assert_string_equal("seven", node->name);
- assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
- assert_string_equal("eight", node->name);
- assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
- assert_string_equal("nine", node->name);
- assert_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0));
- /* Inside RPC */
- assert_non_null(node = lys_getnext(node, (const struct lysc_node *)rpc, mod->compiled, 0));
- assert_string_equal("h-input", node->name);
- assert_null(node = lys_getnext(node, (const struct lysc_node *)rpc, mod->compiled, 0));
-
- /* options */
- assert_non_null(node = lys_getnext(four, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCHOICE));
- assert_string_equal("x", node->name);
- assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCHOICE));
- assert_string_equal("seven", node->name);
-
- assert_non_null(node = lys_getnext(four, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_NOCHOICE));
- assert_string_equal("seven", node->name);
-
- assert_non_null(node = lys_getnext(four, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCASE));
- assert_string_equal("five", node->name);
- assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCASE));
- assert_string_equal("y", node->name);
- assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCASE));
- assert_string_equal("seven", node->name);
-
- assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, LYS_GETNEXT_INTONPCONT));
- assert_string_equal("one", node->name);
-
- assert_non_null(node = lys_getnext(NULL, (const struct lysc_node *)rpc, mod->compiled, LYS_GETNEXT_OUTPUT));
- assert_string_equal("h-output", node->name);
- assert_null(node = lys_getnext(node, (const struct lysc_node *)rpc, mod->compiled, LYS_GETNEXT_OUTPUT));
-
- assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c; rpc c;}", LYS_IN_YANG, &mod));
- assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0));
- assert_string_equal("c", node->name);
- assert_null(node = lys_getnext(node, NULL, mod->compiled, 0));
-
- assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; notification d;}", LYS_IN_YANG, &mod));
- assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0));
- assert_string_equal("d", node->name);
- assert_null(node = lys_getnext(node, NULL, mod->compiled, 0));
-
- assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e; container c {container cc;} leaf a {type string;}}", LYS_IN_YANG, &mod));
- assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0));
- assert_string_equal("c", node->name);
- assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, LYS_GETNEXT_INTONPCONT));
- assert_string_equal("a", node->name);
-}
-
-void
-test_date(void **state)
-{
- assert_int_equal(LY_EINVAL, lysp_check_date(NULL, NULL, 0, "date"));
- CHECK_LOG("Invalid argument date (lysp_check_date()).", NULL);
- assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "x", 1, "date"));
- CHECK_LOG("Invalid argument date_len (lysp_check_date()).", NULL);
- assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "nonsencexx", 10, "date"));
- CHECK_LOG("Invalid value \"nonsencexx\" of \"date\".", NULL);
- assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "123x-11-11", 10, "date"));
- CHECK_LOG("Invalid value \"123x-11-11\" of \"date\".", NULL);
- assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-13-11", 10, "date"));
- CHECK_LOG("Invalid value \"2018-13-11\" of \"date\".", NULL);
- assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-11-41", 10, "date"));
- CHECK_LOG("Invalid value \"2018-11-41\" of \"date\".", NULL);
- assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-02-29", 10, "date"));
- CHECK_LOG("Invalid value \"2018-02-29\" of \"date\".", NULL);
- assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018.02-28", 10, "date"));
- CHECK_LOG("Invalid value \"2018.02-28\" of \"date\".", NULL);
- assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-02.28", 10, "date"));
- CHECK_LOG("Invalid value \"2018-02.28\" of \"date\".", NULL);
-
- assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2018-11-11", 10, "date"));
- assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2018-02-28", 10, "date"));
- assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2016-02-29", 10, "date"));
-}
-
-void
-test_revisions(void **state)
-{
- struct lysp_revision *revs = NULL, *rev;
-
- /* no error, it just does nothing */
- lysp_sort_revisions(NULL);
- CHECK_LOG(NULL, NULL);
-
- /* revisions are stored in wrong order - the newest is the last */
- LY_ARRAY_NEW_RET(NULL, revs, rev, );
- strcpy(rev->date, "2018-01-01");
- LY_ARRAY_NEW_RET(NULL, revs, rev, );
- strcpy(rev->date, "2018-12-31");
-
- assert_int_equal(2, LY_ARRAY_COUNT(revs));
- assert_string_equal("2018-01-01", &revs[0]);
- assert_string_equal("2018-12-31", &revs[1]);
- /* the order should be fixed, so the newest revision will be the first in the array */
- lysp_sort_revisions(revs);
- assert_string_equal("2018-12-31", &revs[0]);
- assert_string_equal("2018-01-01", &revs[1]);
-
- LY_ARRAY_FREE(revs);
-}
-
-void
-test_collision_typedef(void **state)
-{
- const char *str;
- char *submod;
- struct module_clb_list list[3] = {0};
-
- list[0].name = "asub";
- list[1].name = "bsub";
-
- /* collision with a built-in type */
- str = "module a {namespace urn:a; prefix a; typedef binary {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"binary\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef bits {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"bits\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef boolean {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"boolean\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef decimal64 {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"decimal64\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef empty {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"empty\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef enumeration {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"enumeration\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef int8 {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"int8\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef int16 {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"int16\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef int32 {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"int32\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef int64 {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"int64\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef instance-identifier {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"instance-identifier\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef identityref {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"identityref\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef leafref {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"leafref\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef string {type int8;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"string\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef union {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"union\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef uint8 {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"uint8\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef uint16 {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"uint16\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef uint32 {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"uint32\" of typedef statement - name collision with a built-in type.", NULL);
- str = "module a {namespace urn:a; prefix a; typedef uint64 {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"uint64\" of typedef statement - name collision with a built-in type.", NULL);
-
- str = "module mytypes {namespace urn:types; prefix t; typedef binary_ {type string;} typedef bits_ {type string;} typedef boolean_ {type string;} "
- "typedef decimal64_ {type string;} typedef empty_ {type string;} typedef enumeration_ {type string;} typedef int8_ {type string;} typedef int16_ {type string;}"
- "typedef int32_ {type string;} typedef int64_ {type string;} typedef instance-identifier_ {type string;} typedef identityref_ {type string;}"
- "typedef leafref_ {type string;} typedef string_ {type int8;} typedef union_ {type string;} typedef uint8_ {type string;} typedef uint16_ {type string;}"
- "typedef uint32_ {type string;} typedef uint64_ {type string;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-
- /* collision in node's scope */
- str = "module a {namespace urn:a; prefix a; container c {typedef y {type int8;} typedef y {type string;}}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"y\" of typedef statement - name collision with sibling type.", NULL);
-
- /* collision with parent node */
- str = "module a {namespace urn:a; prefix a; container c {container d {typedef y {type int8;}} typedef y {type string;}}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"y\" of typedef statement - name collision with another scoped type.", NULL);
-
- /* collision with module's top-level */
- str = "module a {namespace urn:a; prefix a; typedef x {type string;} container c {typedef x {type int8;}}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"x\" of typedef statement - scoped type collide with a top-level type.", NULL);
-
- /* collision of submodule's node with module's top-level */
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} container c {typedef x {type string;}}}");
- str = "module a {namespace urn:a; prefix a; include b; typedef x {type int8;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"x\" of typedef statement - scoped type collide with a top-level type.", NULL);
-
- /* collision of module's node with submodule's top-level */
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type int8;}}");
- str = "module a {namespace urn:a; prefix a; include b; container c {typedef x {type string;}}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"x\" of typedef statement - scoped type collide with a top-level type.", NULL);
-
- /* collision of submodule's node with another submodule's top-level */
- str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}";
- list[0].data = "submodule asub {belongs-to a {prefix a;} typedef g {type int;}}";
- list[1].data = "submodule bsub {belongs-to a {prefix a;} container c {typedef g {type int;}}}";
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"g\" of typedef statement - scoped type collide with a top-level type.", NULL);
-
- /* collision of module's top-levels */
- str = "module a {namespace urn:a; prefix a; typedef test {type string;} typedef test {type int8;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"test\" of typedef statement - name collision with another top-level type.", NULL);
-
- /* collision of submodule's top-levels */
- submod = "submodule asub {belongs-to a {prefix a;} typedef g {type int;} typedef g {type int;}}";
- str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub;}";
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod);
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"g\" of typedef statement - name collision with another top-level type.", NULL);
-
- /* collision of module's top-level with submodule's top-levels */
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type string;}}");
- str = "module a {namespace urn:a; prefix a; include b; typedef x {type int8;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"x\" of typedef statement - name collision with another top-level type.", NULL);
-
- /* collision of submodule's top-level with another submodule's top-levels */
- str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}";
- list[0].data = "submodule asub {belongs-to a {prefix a;} typedef g {type int;}}";
- list[1].data = "submodule bsub {belongs-to a {prefix a;} typedef g {type int;}}";
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"g\" of typedef statement - name collision with another top-level type.", NULL);
-
- /* error in type-stmt */
- str = "module a {namespace urn:a; prefix a; container c {typedef x {type t{}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Unexpected end-of-input.", "Line number 1.");
- UTEST_LOG_CLEAN;
-
- /* no collision if the same names are in different scope */
- str = "module a {yang-version 1.1; namespace urn:a; prefix a;"
- "container c {typedef g {type int;}} container d {typedef g {type int;}}}";
- assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
-}
-
-void
-test_collision_grouping(void **state)
-{
- const char *str;
- char *submod;
- struct module_clb_list list[3] = {0};
-
- list[0].name = "asub";
- list[1].name = "bsub";
-
- /* collision in node's scope */
- str = "module a {namespace urn:a; prefix a; container c {grouping y; grouping y;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"y\" of grouping statement - name collision with sibling grouping.", NULL);
-
- /* collision with parent node */
- str = "module a {namespace urn:a; prefix a; container c {container d {grouping y;} grouping y;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"y\" of grouping statement - name collision with another scoped grouping.", NULL);
-
- /* collision with module's top-level */
- str = "module a {namespace urn:a; prefix a; grouping x; container c {grouping x;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"x\" of grouping statement - scoped grouping collide with a top-level grouping.", NULL);
-
- /* collision of submodule's node with module's top-level */
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} container c {grouping x;}}");
- str = "module a {namespace urn:a; prefix a; include b; grouping x;}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"x\" of grouping statement - scoped grouping collide with a top-level grouping.", NULL);
-
- /* collision of module's node with submodule's top-level */
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} grouping x;}");
- str = "module a {namespace urn:a; prefix a; include b; container c {grouping x;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"x\" of grouping statement - scoped grouping collide with a top-level grouping.", NULL);
-
- /* collision of submodule's node with another submodule's top-level */
- str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}";
- list[0].data = "submodule asub {belongs-to a {prefix a;} grouping g;}";
- list[1].data = "submodule bsub {belongs-to a {prefix a;} container c {grouping g;}}";
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"g\" of grouping statement - scoped grouping collide with a top-level grouping.", NULL);
-
- /* collision of module's top-levels */
- str = "module a {namespace urn:a; prefix a; grouping test; grouping test;}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"test\" of grouping statement - name collision with another top-level grouping.", NULL);
-
- /* collision of submodule's top-levels */
- submod = "submodule asub {belongs-to a {prefix a;} grouping g; grouping g;}";
- str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub;}";
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod);
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"g\" of grouping statement - name collision with another top-level grouping.", NULL);
-
- /* collision of module's top-level with submodule's top-levels */
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} grouping x;}");
- str = "module a {namespace urn:a; prefix a; include b; grouping x;}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"x\" of grouping statement - name collision with another top-level grouping.", NULL);
-
- /* collision of submodule's top-level with another submodule's top-levels */
- str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}";
- list[0].data = "submodule asub {belongs-to a {prefix a;} grouping g;}";
- list[1].data = "submodule bsub {belongs-to a {prefix a;} grouping g;}";
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"g\" of grouping statement - name collision with another top-level grouping.", NULL);
-
- /* collision in nested groupings, top-level */
- str = "module a {namespace urn:a; prefix a; grouping g {grouping g;}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"g\" of grouping statement - scoped grouping collide with a top-level grouping.", NULL);
-
- /* collision in nested groupings, in node */
- str = "module a {namespace urn:a; prefix a; container c {grouping g {grouping g;}}}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"g\" of grouping statement - name collision with another scoped grouping.", NULL);
-
- /* no collision if the same names are in different scope */
- str = "module a {yang-version 1.1; namespace urn:a; prefix a;"
- "container c {grouping g;} container d {grouping g;}}";
- assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
-}
-
-void
-test_collision_identity(void **state)
-{
- const char *str;
- char *submod;
- struct module_clb_list list[3] = {0};
-
- list[0].name = "asub";
- list[1].name = "bsub";
-
- /* collision of module's top-levels */
- str = "module a {yang-version 1.1; namespace urn:a; prefix a; identity g; identity g;}";
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"g\" of identity statement - name collision with another top-level identity.", NULL);
-
- /* collision of submodule's top-levels */
- submod = "submodule asub {belongs-to a {prefix a;} identity g; identity g;}";
- str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub;}";
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod);
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"g\" of identity statement - name collision with another top-level identity.", NULL);
-
- /* collision of module's top-level with submodule's top-levels */
- submod = "submodule asub {belongs-to a {prefix a;} identity g;}";
- str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; identity g;}";
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod);
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"g\" of identity statement - name collision with another top-level identity.", NULL);
-
- /* collision of submodule's top-level with another submodule's top-levels */
- str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}";
- list[0].data = "submodule asub {belongs-to a {prefix a;} identity g;}";
- list[1].data = "submodule bsub {belongs-to a {prefix a;} identity g;}";
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"g\" of identity statement - name collision with another top-level identity.", NULL);
-}
-
-void
-test_collision_feature(void **state)
-{
- const char *str;
- char *submod;
- struct module_clb_list list[3] = {0};
-
- list[0].name = "asub";
- list[1].name = "bsub";
-
- /* collision of module's top-levels */
- str = "module a {yang-version 1.1; namespace urn:a; prefix a; feature g; feature g;}";
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"g\" of feature statement - name collision with another top-level feature.", NULL);
-
- /* collision of submodule's top-levels */
- submod = "submodule asub {belongs-to a {prefix a;} feature g; feature g;}";
- str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub;}";
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod);
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"g\" of feature statement - name collision with another top-level feature.", NULL);
-
- /* collision of module's top-level with submodule's top-levels */
- submod = "submodule asub {belongs-to a {prefix a;} feature g;}";
- str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; feature g;}";
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod);
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"g\" of feature statement - name collision with another top-level feature.", NULL);
-
- /* collision of submodule's top-level with another submodule's top-levels */
- str = "module a {yang-version 1.1; namespace urn:a; prefix a; include asub; include bsub;}";
- list[0].data = "submodule asub {belongs-to a {prefix a;} feature g;}";
- list[1].data = "submodule bsub {belongs-to a {prefix a;} feature g;}";
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Parsing module \"a\" failed.", NULL,
- "Duplicate identifier \"g\" of feature statement - name collision with another top-level feature.", NULL);
-}
-
-void
-test_accessible_tree(void **state)
-{
- const char *str;
-
- /* config -> config */
- str = "module a {\n"
- " namespace urn:a;\n"
- " prefix a;\n"
- " container cont {\n"
- " leaf l {\n"
- " type empty;\n"
- " }\n"
- " }\n"
- " container cont2 {\n"
- " leaf l2 {\n"
- " must ../../cont/l;\n"
- " type leafref {\n"
- " path /cont/l;\n"
- " }\n"
- " }\n"
- " }\n"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
- CHECK_LOG_CTX(NULL, NULL);
-
- /* config -> state leafref */
- str = "module b {\n"
- " namespace urn:b;\n"
- " prefix b;\n"
- " container cont {\n"
- " config false;\n"
- " leaf l {\n"
- " type empty;\n"
- " }\n"
- " }\n"
- " container cont2 {\n"
- " leaf l2 {\n"
- " type leafref {\n"
- " path /cont/l;\n"
- " }\n"
- " }\n"
- " }\n"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Invalid leafref path \"/cont/l\" - target is supposed to represent configuration data"
- " (as the leafref does), but it does not.", "Schema location \"/b:cont2/l2\".");
-
- /* config -> state must */
- str = "module b {\n"
- " namespace urn:b;\n"
- " prefix b;\n"
- " container cont {\n"
- " config false;\n"
- " leaf l {\n"
- " type empty;\n"
- " }\n"
- " }\n"
- " container cont2 {\n"
- " leaf l2 {\n"
- " must ../../cont/l;\n"
- " type empty;\n"
- " }\n"
- " }\n"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
- CHECK_LOG_CTX("Schema node \"cont\" for parent \"<config-root>\" not found; in expr \"../../cont\" "
- "with context node \"/b:cont2/l2\".", NULL);
-
- /* state -> config */
- str = "module c {\n"
- " namespace urn:c;\n"
- " prefix c;\n"
- " container cont {\n"
- " leaf l {\n"
- " type empty;\n"
- " }\n"
- " }\n"
- " container cont2 {\n"
- " config false;\n"
- " leaf l2 {\n"
- " must ../../cont/l;\n"
- " type leafref {\n"
- " path /cont/l;\n"
- " }\n"
- " }\n"
- " }\n"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
- CHECK_LOG_CTX(NULL, NULL);
-
- /* notif -> state */
- str = "module d {\n"
- " namespace urn:d;\n"
- " prefix d;\n"
- " container cont {\n"
- " config false;\n"
- " leaf l {\n"
- " type empty;\n"
- " }\n"
- " }\n"
- " notification notif {\n"
- " leaf l2 {\n"
- " must ../../cont/l;\n"
- " type leafref {\n"
- " path /cont/l;\n"
- " }\n"
- " }\n"
- " }\n"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
- CHECK_LOG_CTX(NULL, NULL);
-
- /* notif -> notif */
- str = "module e {\n"
- " namespace urn:e;\n"
- " prefix e;\n"
- " notification notif {\n"
- " leaf l {\n"
- " type empty;\n"
- " }\n"
- " leaf l2 {\n"
- " must ../../notif/l;\n"
- " type leafref {\n"
- " path /notif/l;\n"
- " }\n"
- " }\n"
- " }\n"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
- CHECK_LOG_CTX(NULL, NULL);
-
- /* rpc input -> state */
- str = "module f {\n"
- " namespace urn:f;\n"
- " prefix f;\n"
- " container cont {\n"
- " config false;\n"
- " leaf l {\n"
- " type empty;\n"
- " }\n"
- " }\n"
- " rpc rp {\n"
- " input {\n"
- " leaf l2 {\n"
- " must ../../cont/l;\n"
- " type leafref {\n"
- " path /cont/l;\n"
- " }\n"
- " }\n"
- " }\n"
- " }\n"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
- CHECK_LOG_CTX(NULL, NULL);
-
- /* rpc input -> rpc input */
- str = "module g {\n"
- " namespace urn:g;\n"
- " prefix g;\n"
- " rpc rp {\n"
- " input {\n"
- " leaf l {\n"
- " type empty;\n"
- " }\n"
- " leaf l2 {\n"
- " must ../l;\n"
- " type leafref {\n"
- " path /rp/l;\n"
- " }\n"
- " }\n"
- " }\n"
- " }\n"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
- CHECK_LOG_CTX(NULL, NULL);
-
- /* rpc input -> rpc output leafref */
- str = "module h {\n"
- " namespace urn:h;\n"
- " prefix h;\n"
- " rpc rp {\n"
- " input {\n"
- " leaf l2 {\n"
- " type leafref {\n"
- " path /rp/l;\n"
- " }\n"
- " }\n"
- " }\n"
- " output {\n"
- " leaf l {\n"
- " type empty;\n"
- " }\n"
- " }\n"
- " }\n"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Not found node \"l\" in path.", "Schema location \"/h:rp/input/l2\".");
-
- /* rpc input -> rpc output must */
- str = "module h {\n"
- " namespace urn:h;\n"
- " prefix h;\n"
- " rpc rp {\n"
- " input {\n"
- " leaf l2 {\n"
- " must ../l;\n"
- " type empty;\n"
- " }\n"
- " }\n"
- " output {\n"
- " leaf l {\n"
- " type empty;\n"
- " }\n"
- " }\n"
- " }\n"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
- CHECK_LOG_CTX("Schema node \"l\" for parent \"/h:rp\" not found; in expr \"../l\" with context node \"/h:rp/input/l2\".", NULL);
-
- /* rpc input -> notif leafref */
- str = "module i {\n"
- " namespace urn:i;\n"
- " prefix i;\n"
- " rpc rp {\n"
- " input {\n"
- " leaf l2 {\n"
- " type leafref {\n"
- " path ../../notif/l;\n"
- " }\n"
- " }\n"
- " }\n"
- " }\n"
- " notification notif {\n"
- " leaf l {\n"
- " type empty;\n"
- " }\n"
- " }\n"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Not found node \"notif\" in path.", "Schema location \"/i:rp/input/l2\".");
-
- /* rpc input -> notif must */
- str = "module i {\n"
- " namespace urn:i;\n"
- " prefix i;\n"
- " rpc rp {\n"
- " input {\n"
- " leaf l2 {\n"
- " must /notif/l;\n"
- " type empty;\n"
- " }\n"
- " }\n"
- " }\n"
- " notification notif {\n"
- " leaf l {\n"
- " type empty;\n"
- " }\n"
- " }\n"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
- CHECK_LOG_CTX("Schema node \"notif\" for parent \"<root>\" not found; in expr \"/notif\" "
- "with context node \"/i:rp/input/l2\".", NULL);
-
- /* action output -> state */
- str = "module j {\n"
- " yang-version 1.1;\n"
- " namespace urn:j;\n"
- " prefix j;\n"
- " container cont {\n"
- " list ll {\n"
- " key k;\n"
- " leaf k {\n"
- " type string;\n"
- " }\n"
- " action act {\n"
- " output {\n"
- " leaf l2 {\n"
- " must /cont/l;\n"
- " type leafref {\n"
- " path ../../../l;\n"
- " }\n"
- " }\n"
- " }\n"
- " }\n"
- " }\n"
- " leaf l {\n"
- " config false;\n"
- " type empty;\n"
- " }\n"
- " }\n"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
- CHECK_LOG_CTX(NULL, NULL);
-
- /* action output -> action input leafref */
- str = "module k {\n"
- " yang-version 1.1;\n"
- " namespace urn:k;\n"
- " prefix k;\n"
- " container cont {\n"
- " list ll {\n"
- " key k;\n"
- " leaf k {\n"
- " type string;\n"
- " }\n"
- " action act {\n"
- " input {\n"
- " leaf l {\n"
- " type empty;\n"
- " }\n"
- " }\n"
- " output {\n"
- " leaf l2 {\n"
- " type leafref {\n"
- " path ../l;\n"
- " }\n"
- " }\n"
- " }\n"
- " }\n"
- " }\n"
- " }\n"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Not found node \"l\" in path.", "Schema location \"/k:cont/ll/act/output/l2\".");
-
- /* action output -> action input must */
- str = "module k {\n"
- " yang-version 1.1;\n"
- " namespace urn:k;\n"
- " prefix k;\n"
- " container cont {\n"
- " list ll {\n"
- " key k;\n"
- " leaf k {\n"
- " type string;\n"
- " }\n"
- " action act {\n"
- " input {\n"
- " leaf l {\n"
- " type empty;\n"
- " }\n"
- " }\n"
- " output {\n"
- " leaf l2 {\n"
- " must /cont/ll/act/l;\n"
- " type empty;\n"
- " }\n"
- " }\n"
- " }\n"
- " }\n"
- " }\n"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
- CHECK_LOG_CTX("Schema node \"l\" for parent \"/k:cont/ll/act\" not found; in expr \"/cont/ll/act/l\" "
- "with context node \"/k:cont/ll/act/output/l2\".", NULL);
-}
-
-void
-test_includes(void **state)
-{
- struct lys_module *mod;
-
- {
- /* YANG 1.0 - the missing include sub_a_two in main_a will be injected from sub_a_one */
- struct module_clb_list list[] = {
- {"main_a", "module main_a { namespace urn:test:main_a; prefix ma; include sub_a_one;}"},
- {"sub_a_one", "submodule sub_a_one { belongs-to main_a { prefix ma; } include sub_a_two;}"},
- {"sub_a_two", "submodule sub_a_two { belongs-to main_a { prefix ma; } }"},
- {NULL, NULL}
- };
-
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
- mod = ly_ctx_load_module(UTEST_LYCTX, "main_a", NULL, NULL);
- assert_non_null(mod);
- assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->includes));
- assert_true(mod->parsed->includes[1].injected);
- }
-
- {
- /* YANG 1.1 - the missing include sub_b_two in main_b is error */
- struct module_clb_list list[] = {
- {"main_b", "module main_b { yang-version 1.1; namespace urn:test:main_b; prefix mb; include sub_b_one;}"},
- {"sub_b_one", "submodule sub_b_one { yang-version 1.1; belongs-to main_b { prefix mb; } include sub_b_two;}"},
- {"sub_b_two", "submodule sub_b_two { yang-version 1.1; belongs-to main_b { prefix mb; } }"},
- {NULL, NULL}
- };
-
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
- mod = ly_ctx_load_module(UTEST_LYCTX, "main_b", NULL, NULL);
- assert_null(mod);
- CHECK_LOG_CTX("Loading \"main_b\" module failed.", NULL,
- "Data model \"main_b\" not found in local searchdirs.", NULL,
- "Parsing module \"main_b\" failed.", NULL,
- "Including \"sub_b_one\" submodule into \"main_b\" failed.", NULL,
- "Data model \"sub_b_one\" not found in local searchdirs.", NULL,
- "Parsing submodule \"sub_b_one\" failed.", NULL,
- "YANG 1.1 requires all submodules to be included from main module. But submodule \"sub_b_one\" includes "
- "submodule \"sub_b_two\" which is not included by main module \"main_b\".", NULL,
- "YANG version 1.1 expects all includes in main module, includes in submodules (sub_b_one) are not necessary.", NULL);
- }
-
- {
- /* YANG 1.1 - all includes are in main_c, includes in submodules are not necessary, so expect warning */
- struct module_clb_list list[] = {
- {"main_c", "module main_c { yang-version 1.1; namespace urn:test:main_c; prefix mc; include sub_c_one; include sub_c_two;}"},
- {"sub_c_one", "submodule sub_c_one { yang-version 1.1; belongs-to main_c { prefix mc; } include sub_c_two;}"},
- {"sub_c_two", "submodule sub_c_two { yang-version 1.1; belongs-to main_c { prefix mc; } include sub_c_one;}"},
- {NULL, NULL}
- };
-
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
- mod = ly_ctx_load_module(UTEST_LYCTX, "main_c", NULL, NULL);
- assert_non_null(mod);
- assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->includes));
- assert_false(mod->parsed->includes[1].injected);
- /* result is ok, but log includes the warning */
- CHECK_LOG_CTX("YANG version 1.1 expects all includes in main module, includes in submodules (sub_c_two) are not necessary.", NULL);
- }
-}
-
-void
-test_key_order(void **state)
-{
- struct lys_module *mod;
- const struct lysc_node *node;
-
- struct module_clb_list list1[] = {
- {"a", "module a {"
- "yang-version 1.1;"
- "namespace urn:test:a;"
- "prefix a;"
- "list l {"
- " key \"k1 k2\";"
- " leaf k2 {type string;}"
- " leaf k1 {type string;}"
- "}"
- "}"},
- {NULL, NULL}
- };
-
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list1);
- mod = ly_ctx_load_module(UTEST_LYCTX, "a", NULL, NULL);
- assert_non_null(mod);
-
- node = lysc_node_child(mod->compiled->data);
- assert_string_equal("k1", node->name);
- node = node->next;
- assert_string_equal("k2", node->name);
-
- struct module_clb_list list2[] = {
- {"b", "module b {"
- "yang-version 1.1;"
- "namespace urn:test:b;"
- "prefix b;"
- "list l {"
- " key \"k1 k2 k3 k4\";"
- " leaf k4 {type string;}"
- " container c {"
- " leaf l1 {type string;}"
- " }"
- " leaf k2 {type string;}"
- " leaf l2 {type string;}"
- " leaf k1 {type string;}"
- " leaf k3 {type string;}"
- "}"
- "}"},
- {NULL, NULL}
- };
-
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list2);
- mod = ly_ctx_load_module(UTEST_LYCTX, "b", NULL, NULL);
- assert_non_null(mod);
-
- node = lysc_node_child(mod->compiled->data);
- assert_string_equal("k1", node->name);
- node = node->next;
- assert_string_equal("k2", node->name);
- node = node->next;
- assert_string_equal("k3", node->name);
- node = node->next;
- assert_string_equal("k4", node->name);
-}
-
-void
-test_disabled_enum(void **state)
-{
- const char *str;
-
- /* no enabled enum */
- str = "module a {"
- "yang-version 1.1;"
- "namespace urn:test:a;"
- "prefix a;"
- "feature f;"
- "leaf l {type enumeration {"
- " enum e1 {if-feature f;}"
- " enum e2 {if-feature f;}"
- "}}"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Enumeration type of node \"l\" without any (or all disabled) valid values.", "Schema location \"/a:l\".");
-
- /* disabled default value */
- str = "module a {"
- "yang-version 1.1;"
- "namespace urn:test:a;"
- "prefix a;"
- "feature f;"
- "leaf l {"
- " type enumeration {"
- " enum e1 {if-feature f;}"
- " enum e2;"
- " }"
- " default e1;"
- "}"
- "}";
- assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
- CHECK_LOG_CTX("Invalid default - value does not fit the type (Invalid enumeration value \"e1\".).",
- "Schema location \"/a:l\".");
-}
diff --git a/tests/utests/schema/test_schema_extensions.c b/tests/utests/schema/test_schema_extensions.c
deleted file mode 100644
index b1d8504..0000000
--- a/tests/utests/schema/test_schema_extensions.c
+++ /dev/null
@@ -1,461 +0,0 @@
-/*
- * @file test_schema_extensions.c
- * @author: Radek Krejci <rkrejci@cesnet.cz>
- * @brief unit tests for YANG (YIN) extension statements and their instances in schemas
- *
- * Copyright (c) 2018-2021 CESNET, z.s.p.o.
- *
- * This source code is licensed under BSD 3-Clause License (the "License").
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- */
-#include "test_schema.h"
-
-#include <string.h>
-
-#include "context.h"
-#include "log.h"
-#include "plugins_exts.h"
-#include "tree_schema.h"
-
-void
-test_extension_argument(void **state)
-{
- struct lys_module *mod;
- const char *mod_def_yang = "module a {\n"
- " namespace \"urn:a\";\n"
- " prefix a;\n\n"
- " extension e {\n"
- " argument name;\n"
- " }\n\n"
- " a:e \"aaa\";\n"
- "}\n";
- const char *mod_def_yin =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<module name=\"a\"\n"
- " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
- " xmlns:a=\"urn:a\">\n"
- " <namespace uri=\"urn:a\"/>\n"
- " <prefix value=\"a\"/>\n"
- " <extension name=\"e\">\n"
- " <argument name=\"name\"/>\n"
- " </extension>\n"
- " <a:e name=\"aaa\"/>\n"
- "</module>\n";
- const char *mod_test_yin, *mod_test_yang;
- char *printed;
-
- mod_test_yang = "module b {\n"
- " namespace \"urn:b\";\n"
- " prefix b;\n\n"
- " import a {\n"
- " prefix a;\n"
- " }\n\n"
- " a:e \"xxx\";\n"
- "}\n";
- mod_test_yin =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<module name=\"b\"\n"
- " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
- " xmlns:b=\"urn:b\"\n"
- " xmlns:a=\"urn:a\">\n"
- " <namespace uri=\"urn:b\"/>\n"
- " <prefix value=\"b\"/>\n"
- " <import module=\"a\">\n"
- " <prefix value=\"a\"/>\n"
- " </import>\n"
- " <a:e name=\"xxx\"/>\n"
- "</module>\n";
-
- /* from YANG */
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, (void *)mod_def_yang);
- assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, mod_test_yang, LYS_IN_YANG, &mod));
- assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG, 0));
- assert_string_equal(printed, mod_test_yang);
- free(printed);
-
- assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YIN, 0));
- assert_string_equal(printed, mod_test_yin);
- free(printed);
-
- assert_non_null(mod = ly_ctx_get_module(UTEST_LYCTX, "a", NULL));
- assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG, 0));
- assert_string_equal(printed, mod_def_yang);
- free(printed);
-
- assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YIN, 0));
- assert_string_equal(printed, mod_def_yin);
- free(printed);
-
- /* context reset */
- ly_ctx_destroy(UTEST_LYCTX);
- ly_ctx_new(NULL, 0, &UTEST_LYCTX);
-
- /* from YIN */
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, (void *)mod_def_yin);
- assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, mod_test_yin, LYS_IN_YIN, &mod));
- assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG, 0));
- assert_string_equal(printed, mod_test_yang);
- free(printed);
-
- assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YIN, 0));
- assert_string_equal(printed, mod_test_yin);
- free(printed);
-
- assert_non_null(mod = ly_ctx_get_module(UTEST_LYCTX, "a", NULL));
- assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG, 0));
- assert_string_equal(printed, mod_def_yang);
- free(printed);
-
- assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YIN, 0));
- assert_string_equal(printed, mod_def_yin);
- free(printed);
-}
-
-void
-test_extension_argument_element(void **state)
-{
- struct lys_module *mod;
- const char *mod_def_yang = "module a {\n"
- " namespace \"urn:a\";\n"
- " prefix a;\n\n"
- " extension e {\n"
- " argument name {\n"
- " yin-element true;\n"
- " }\n"
- " }\n\n"
- " a:e \"aaa\";\n"
- "}\n";
- const char *mod_def_yin =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<module name=\"a\"\n"
- " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
- " xmlns:a=\"urn:a\">\n"
- " <namespace uri=\"urn:a\"/>\n"
- " <prefix value=\"a\"/>\n"
- " <extension name=\"e\">\n"
- " <argument name=\"name\">\n"
- " <yin-element value=\"true\"/>\n"
- " </argument>\n"
- " </extension>\n"
- " <a:e>\n"
- " <a:name>aaa</a:name>\n"
- " </a:e>\n"
- "</module>\n";
- const char *mod_test_yin, *mod_test_yang;
- char *printed;
-
- mod_test_yang = "module b {\n"
- " namespace \"urn:b\";\n"
- " prefix b;\n\n"
- " import a {\n"
- " prefix a;\n"
- " }\n\n"
- " a:e \"xxx\";\n"
- "}\n";
- mod_test_yin =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<module name=\"b\"\n"
- " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
- " xmlns:b=\"urn:b\"\n"
- " xmlns:a=\"urn:a\">\n"
- " <namespace uri=\"urn:b\"/>\n"
- " <prefix value=\"b\"/>\n"
- " <import module=\"a\">\n"
- " <prefix value=\"a\"/>\n"
- " </import>\n"
- " <a:e>\n"
- " <a:name>xxx</a:name>\n"
- " </a:e>\n"
- "</module>\n";
-
- /* from YANG */
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, (void *)mod_def_yang);
- assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, mod_test_yang, LYS_IN_YANG, &mod));
- assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG, 0));
- assert_string_equal(printed, mod_test_yang);
- free(printed);
-
- assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YIN, 0));
- assert_string_equal(printed, mod_test_yin);
- free(printed);
-
- assert_non_null(mod = ly_ctx_get_module(UTEST_LYCTX, "a", NULL));
- assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG, 0));
- assert_string_equal(printed, mod_def_yang);
- free(printed);
-
- assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YIN, 0));
- assert_string_equal(printed, mod_def_yin);
- free(printed);
-
- /* context reset */
- ly_ctx_destroy(UTEST_LYCTX);
- ly_ctx_new(NULL, 0, &UTEST_LYCTX);
-
- /* from YIN */
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, (void *)mod_def_yin);
- assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, mod_test_yin, LYS_IN_YIN, &mod));
- assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG, 0));
- assert_string_equal(printed, mod_test_yang);
- free(printed);
-
- assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YIN, 0));
- assert_string_equal(printed, mod_test_yin);
- free(printed);
-
- assert_non_null(mod = ly_ctx_get_module(UTEST_LYCTX, "a", NULL));
- assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG, 0));
- assert_string_equal(printed, mod_def_yang);
- free(printed);
-
- assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YIN, 0));
- assert_string_equal(printed, mod_def_yin);
- free(printed);
-
- /* invalid */
- mod_test_yang = "module x { namespace \"urn:x\"; prefix x; import a { prefix a; } a:e; }";
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, mod_test_yang, LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Extension instance \"a:e\" misses argument element \"name\".", "/x:{extension='a:e'}");
-
- mod_test_yin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<module name=\"x\"\n"
- " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
- " xmlns:x=\"urn:x\"\n"
- " xmlns:a=\"urn:a\">\n"
- " <namespace uri=\"urn:x\"/>\n"
- " <prefix value=\"x\"/>\n"
- " <import module=\"a\">\n"
- " <prefix value=\"a\"/>\n"
- " </import>\n\n"
- " <a:e/>\n"
- "</module>\n";
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, mod_test_yin, LYS_IN_YIN, NULL));
- CHECK_LOG_CTX("Extension instance \"a:e\" misses argument element \"name\".", "/x:{extension='a:e'}");
-
- mod_test_yin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<module name=\"x\"\n"
- " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
- " xmlns:x=\"urn:x\"\n"
- " xmlns:a=\"urn:a\">\n"
- " <namespace uri=\"urn:x\"/>\n"
- " <prefix value=\"x\"/>\n"
- " <import module=\"a\">\n"
- " <prefix value=\"a\"/>\n"
- " </import>\n\n"
- " <a:e name=\"xxx\"/>\n"
- "</module>\n";
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, mod_test_yin, LYS_IN_YIN, NULL));
- CHECK_LOG_CTX("Extension instance \"a:e\" misses argument element \"name\".", "/x:{extension='a:e'}");
-
- mod_test_yin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<module name=\"x\"\n"
- " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
- " xmlns:x=\"urn:x\"\n"
- " xmlns:a=\"urn:a\">\n"
- " <namespace uri=\"urn:x\"/>\n"
- " <prefix value=\"x\"/>\n"
- " <import module=\"a\">\n"
- " <prefix value=\"a\"/>\n"
- " </import>\n\n"
- " <a:e>\n"
- " <x:name>xxx</x:name>\n"
- " </a:e>\n"
- "</module>\n";
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, mod_test_yin, LYS_IN_YIN, NULL));
- CHECK_LOG_CTX("Extension instance \"a:e\" element and its argument element \"name\" are expected in the same namespace, but they differ.",
- "/x:{extension='a:e'}");
-
- mod_test_yin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<module name=\"x\"\n"
- " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
- " xmlns:x=\"urn:x\"\n"
- " xmlns:a=\"urn:a\">\n"
- " <namespace uri=\"urn:x\"/>\n"
- " <prefix value=\"x\"/>\n"
- " <import module=\"a\">\n"
- " <prefix value=\"a\"/>\n"
- " </import>\n\n"
- " <a:e>\n"
- " <a:value>xxx</a:value>\n"
- " </a:e>\n"
- "</module>\n";
- assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, mod_test_yin, LYS_IN_YIN, NULL));
- CHECK_LOG_CTX("Extension instance \"a:e\" expects argument element \"name\" as its first XML child, but \"value\" element found.",
- "/x:{extension='a:e'}");
-
-}
-
-void
-test_extension_compile(void **state)
-{
- struct lys_module *mod;
- struct lysc_ctx cctx = {0};
- struct lysp_ext_instance ext_p = {0};
- struct lysp_stmt child = {0};
- struct lysc_ext_instance ext_c = {0};
- struct lysc_ext_substmt *substmt;
- LY_ERR rc = LY_SUCCESS;
-
- /* current module, whatever */
- mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "yang");
- assert_true(mod);
-
- /* compile context */
- cctx.ctx = UTEST_LYCTX;
- cctx.cur_mod = mod;
- cctx.pmod = mod->parsed;
- cctx.path_len = 1;
- cctx.path[0] = '/';
-
- /* parsed ext instance */
- lydict_insert(UTEST_LYCTX, "pref:my-ext", 0, &ext_p.name);
- ext_p.format = LY_VALUE_JSON;
- ext_p.parent_stmt = LY_STMT_MODULE;
-
- /* compiled ext instance */
- ext_c.parent_stmt = ext_p.parent_stmt;
- // ext_c.parent =
- LY_ARRAY_NEW_GOTO(UTEST_LYCTX, ext_c.substmts, substmt, rc, cleanup);
-
- /*
- * error-message
- */
- ext_p.child = &child;
- lydict_insert(UTEST_LYCTX, "error-message", 0, &child.stmt);
- lydict_insert(UTEST_LYCTX, "my error", 0, &child.arg);
- child.format = LY_VALUE_JSON;
- child.kw = LY_STMT_ERROR_MESSAGE;
-
- substmt->stmt = LY_STMT_ERROR_MESSAGE;
- substmt->cardinality = LY_STMT_CARD_OPT;
- substmt->storage = &ext_c.data;
-
- /* compile */
- assert_int_equal(LY_SUCCESS, lys_compile_extension_instance(&cctx, &ext_p, &ext_c));
-
- /* check */
- assert_string_equal(ext_c.data, "my error");
-
-cleanup:
- lydict_remove(UTEST_LYCTX, ext_p.name);
- lydict_remove(UTEST_LYCTX, child.stmt);
- lydict_remove(UTEST_LYCTX, child.arg);
- LY_ARRAY_FREE(ext_c.substmts);
-
- lydict_remove(UTEST_LYCTX, ext_c.data);
- if (rc) {
- fail();
- }
-}
-
-void
-test_ext_recursive(void **state)
-{
- const char *mod_base_yang, *mod_imp_yang, *mod_base_yin, *mod_imp_yin;
-
- mod_imp_yang = "module b {\n"
- " namespace \"urn:b\";\n"
- " prefix b;\n\n"
- " extension use-in {\n"
- " argument name {\n"
- " b:arg-type {\n"
- " type string;\n"
- " }\n"
- " }\n"
- " b:use-in \"extension\";\n"
- " b:occurence \"*\";\n"
- " }\n"
- "\n"
- " extension substatement {\n"
- " argument name {\n"
- " b:arg-type {\n"
- " type string;\n"
- " }\n"
- " }\n"
- " b:use-in \"extension\";\n"
- " b:occurence \"*\";\n"
- " b:substatement \"b:occurence\";\n"
- " }\n"
- "\n"
- " extension arg-type {\n"
- " b:use-in \"argument\";\n"
- " b:substatement \"type\" {\n"
- " b:occurence \"1\";\n"
- " }\n"
- " b:substatement \"default\";\n"
- " }\n"
- "\n"
- " extension occurence {\n"
- " argument value {\n"
- " b:arg-type {\n"
- " type enumeration {\n"
- " enum \"?\";\n"
- " enum \"*\";\n"
- " enum \"+\";\n"
- " enum \"1\";\n"
- " }\n"
- " }\n"
- " }\n"
- " b:use-in \"extension\";\n"
- " }\n"
- "}\n";
-
- mod_imp_yin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<module name=\"b\"\n"
- " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
- " xmlns:b=\"urn:b\"\n"
- " xmlns:a=\"urn:a\">\n"
- " <namespace uri=\"urn:b\"/>\n"
- " <prefix value=\"b\"/>\n"
- " <import module=\"a\">\n"
- " <prefix value=\"a\"/>\n"
- " </import>\n\n"
- " <a:e name=\"xxx\"/>\n"
- "</module>\n";
-
- mod_base_yang = "module a {\n"
- " namespace \"urn:a\";\n"
- " prefix a;\n\n"
- " import b {\n"
- " prefix b;\n"
- " }\n"
- "\n"
- " extension abstract {\n"
- " b:use-in \"identity\";\n"
- " }\n"
- "\n"
- " identity mount-id;\n"
- "\n"
- " identity yang-lib-id {\n"
- " base mount-id;\n"
- " a:abstract;\n"
- " }\n"
- "}\n";
-
- mod_base_yin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<module name=\"a\"\n"
- " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"\n"
- " xmlns:a=\"urn:a\">\n"
- " <namespace uri=\"urn:a\"/>\n"
- " <prefix value=\"a\"/>\n\n"
- " <extension name=\"e\">\n"
- " <argument name=\"name\"/>\n"
- " </extension>\n\n"
- " <a:e name=\"aaa\"/>\n"
- "</module>\n";
-
- /* from YANG */
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, (void *)mod_imp_yang);
- assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, mod_base_yang, LYS_IN_YANG, NULL));
-
- /* context reset */
- ly_ctx_destroy(UTEST_LYCTX);
- ly_ctx_new(NULL, 0, &UTEST_LYCTX);
-
- /* from YIN */
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, (void *)mod_imp_yin);
- assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, mod_base_yin, LYS_IN_YIN, NULL));
-}
diff --git a/tests/utests/schema/test_schema_stmts.c b/tests/utests/schema/test_schema_stmts.c
deleted file mode 100644
index 81a9832..0000000
--- a/tests/utests/schema/test_schema_stmts.c
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * @file test_schema_stmts.c
- * @author: Radek Krejci <rkrejci@cesnet.cz>
- * @brief unit tests for YANG (YIN) statements in (sub)modules
- *
- * Copyright (c) 2018-2020 CESNET, z.s.p.o.
- *
- * This source code is licensed under BSD 3-Clause License (the "License").
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/BSD-3-Clause
- */
-#include "test_schema.h"
-
-#include <string.h>
-
-#include "context.h"
-#include "log.h"
-#include "tree_schema.h"
-
-void
-test_identity(void **state)
-{
- struct lys_module *mod, *mod_imp;
-
- /*
- * parsing YANG
- */
- TEST_STMT_DUP(1, 0, "identity id", "description", "a", "b", "1");
- TEST_STMT_DUP(1, 0, "identity id", "reference", "a", "b", "1");
- TEST_STMT_DUP(1, 0, "identity id", "status", "current", "obsolete", "1");
-
- /* full content */
- TEST_SCHEMA_OK(1, 0, "identityone",
- "identity test {base \"a\";base b; description text;reference \'another text\';status current; if-feature x;if-feature y; identityone:ext;}"
- "identity a; identity b; extension ext; feature x; feature y;", mod);
- assert_non_null(mod->parsed->identities);
- assert_int_equal(3, LY_ARRAY_COUNT(mod->parsed->identities));
-
- /* invalid substatement */
- TEST_STMT_SUBSTM_ERR(0, "identity", "organization", "XXX");
-
- /*
- * parsing YIN
- */
- /* max subelems */
- TEST_SCHEMA_OK(1, 1, "identityone-yin", "<identity name=\"ident-name\">"
- "<if-feature name=\"iff\"/>"
- "<base name=\"base-name\"/>"
- "<status value=\"deprecated\"/>"
- "<description><text>desc</text></description>"
- "<reference><text>ref</text></reference>"
- /* TODO yin-extension-prefix-compilation-bug "<myext:ext xmlns:myext=\"urn:libyang:test:identityone-yin\"/>" */
- "</identity><extension name=\"ext\"/><identity name=\"base-name\"/><feature name=\"iff\"/>", mod);
- assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->identities));
- assert_string_equal(mod->parsed->identities[0].name, "ident-name");
- assert_string_equal(mod->parsed->identities[0].bases[0], "base-name");
- assert_string_equal(mod->parsed->identities[0].iffeatures[0].str, "iff");
- assert_string_equal(mod->parsed->identities[0].dsc, "desc");
- assert_string_equal(mod->parsed->identities[0].ref, "ref");
- assert_true(mod->parsed->identities[0].flags & LYS_STATUS_DEPRC);
- /*assert_string_equal(mod->parsed->identities[0].exts[0].name, "ext");
- assert_non_null(mod->parsed->identities[0].exts[0].compiled);
- assert_int_equal(mod->parsed->identities[0].exts[0].yin, 1);
- assert_int_equal(mod->parsed->identities[0].exts[0].insubstmt_index, 0);
- assert_int_equal(mod->parsed->identities[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);*/
-
- /* min subelems */
- TEST_SCHEMA_OK(1, 1, "identitytwo-yin", "<identity name=\"ident-name\" />", mod);
- assert_int_equal(1, LY_ARRAY_COUNT(mod->parsed->identities));
- assert_string_equal(mod->parsed->identities[0].name, "ident-name");
-
- /* invalid substatement */
- TEST_SCHEMA_PARSE_ERR(0, 1, "inv", "<identity name=\"ident-name\"><if-feature name=\"iff\"/></identity>",
- "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.");
-
- /*
- * compiling
- */
- TEST_SCHEMA_OK(0, 0, "a", "identity a1;", mod_imp);
- TEST_SCHEMA_OK(1, 0, "b", "import a {prefix a;}"
- "identity b1; identity b2; identity b3 {base b1; base b:b2; base a:a1;}"
- "identity b4 {base b:b1; base b3;}", mod);
- assert_non_null(mod_imp->compiled);
- assert_non_null(mod_imp->identities);
- assert_non_null(mod->identities);
- assert_non_null(mod_imp->identities[0].derived);
- assert_int_equal(1, LY_ARRAY_COUNT(mod_imp->identities[0].derived));
- assert_ptr_equal(mod_imp->identities[0].derived[0], &mod->identities[2]);
- assert_non_null(mod->identities[0].derived);
- assert_int_equal(2, LY_ARRAY_COUNT(mod->identities[0].derived));
- assert_ptr_equal(mod->identities[0].derived[0], &mod->identities[2]);
- assert_ptr_equal(mod->identities[0].derived[1], &mod->identities[3]);
- assert_non_null(mod->identities[1].derived);
- assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[1].derived));
- assert_ptr_equal(mod->identities[1].derived[0], &mod->identities[2]);
- assert_non_null(mod->identities[2].derived);
- assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[2].derived));
- assert_ptr_equal(mod->identities[2].derived[0], &mod->identities[3]);
-
- TEST_SCHEMA_OK(1, 0, "c", "identity c2 {base c1;} identity c1;", mod);
- assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[1].derived));
- assert_ptr_equal(mod->identities[1].derived[0], &mod->identities[0]);
-
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} identity i1;}");
- TEST_SCHEMA_ERR(0, 0, "inv", "identity i1 {base i2;}", "Unable to find base (i2) of identity \"i1\".", "/inv:{identity='i1'}");
- TEST_SCHEMA_ERR(0, 0, "inv", "identity i1 {base i1;}", "Identity \"i1\" is derived from itself.", "/inv:{identity='i1'}");
- TEST_SCHEMA_ERR(0, 0, "inv", "identity i1 {base i2;}identity i2 {base i3;}identity i3 {base i1;}",
- "Identity \"i1\" is indirectly derived from itself.", "/inv:{identity='i3'}");
-
- /* base in non-implemented module */
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb,
- "module base {namespace \"urn\"; prefix b; identity i1; identity i2 {base i1;}}");
- TEST_SCHEMA_OK(0, 0, "ident", "import base {prefix b;} identity ii {base b:i1;}", mod);
-
- /* default value from non-implemented module */
- TEST_SCHEMA_ERR(0, 0, "ident2", "import base {prefix b;} leaf l {type identityref {base b:i1;} default b:i2;}",
- "Invalid default - value does not fit the type (Invalid identityref \"b:i2\" value"
- " - identity found in non-implemented module \"base\".).", "Schema location \"/ident2:l\".");
-
- /* default value in typedef from non-implemented module */
- TEST_SCHEMA_ERR(0, 0, "ident2", "import base {prefix b;} typedef t1 {type identityref {base b:i1;} default b:i2;}"
- "leaf l {type t1;}", "Invalid default - value does not fit the type (Invalid"
- " identityref \"b:i2\" value - identity found in non-implemented module \"base\".).", "Schema location \"/ident2:l\".");
-
- /*
- * printing
- */
-
- /*
- * cleanup
- */
-}
-
-void
-test_feature(void **state)
-{
- struct lys_module *mod;
- const struct lysp_feature *f;
-
- /*
- * parsing YANG
- */
-
- TEST_STMT_DUP(1, 0, "feature f", "description", "a", "b", "1");
- TEST_STMT_DUP(1, 0, "feature f", "reference", "a", "b", "1");
- TEST_STMT_DUP(1, 0, "feature f", "status", "current", "obsolete", "1");
-
- /* full content */
- TEST_SCHEMA_OK(1, 0, "featureone",
- "feature test {description text;reference \'another text\';status current; if-feature x; if-feature y; featureone:ext;}"
- "extension ext; feature x; feature y;", mod);
- assert_non_null(mod->parsed->features);
- assert_int_equal(3, LY_ARRAY_COUNT(mod->parsed->features));
-
- /* invalid substatement */
- TEST_STMT_SUBSTM_ERR(0, "feature", "organization", "XXX");
-
- /*
- * parsing YIN
- */
- /* max subelems */
- TEST_SCHEMA_OK(0, 1, "featureone-yin", "<feature name=\"feature-name\">"
- "<if-feature name=\"iff\"/>"
- "<status value=\"deprecated\"/>"
- "<description><text>desc</text></description>"
- "<reference><text>ref</text></reference>"
- /* TODO yin-extension-prefix-compilation-bug "<myext:ext xmlns:myext=\"urn:libyang:test:featureone-yin\"/>" */
- "</feature><extension name=\"ext\"/><feature name=\"iff\"/>", mod);
- assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->features));
- assert_string_equal(mod->parsed->features[0].name, "feature-name");
- assert_string_equal(mod->parsed->features[0].dsc, "desc");
- assert_true(mod->parsed->features[0].flags & LYS_STATUS_DEPRC);
- assert_string_equal(mod->parsed->features[0].iffeatures[0].str, "iff");
- assert_string_equal(mod->parsed->features[0].ref, "ref");
- /*assert_string_equal(mod->parsed->features[0].exts[0].name, "ext");
- assert_int_equal(mod->parsed->features[0].exts[0].insubstmt_index, 0);
- assert_int_equal(mod->parsed->features[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);*/
-
- /* min subelems */
- TEST_SCHEMA_OK(0, 1, "featuretwo-yin", "<feature name=\"feature-name\"/>", mod)
- assert_int_equal(1, LY_ARRAY_COUNT(mod->parsed->features));
- assert_string_equal(mod->parsed->features[0].name, "feature-name");
-
- /* invalid substatement */
- TEST_SCHEMA_PARSE_ERR(0, 1, "inv", "<feature name=\"feature-name\"><organization><text>org</text></organization></feature>",
- "Unexpected sub-element \"organization\" of \"feature\" element.", "Line number 1.");
-
- /*
- * compiling
- */
-
- TEST_SCHEMA_OK(1, 0, "a", "feature f1 {description test1;reference test2;status current;} feature f2; feature f3;\n"
- "feature orfeature {if-feature \"f1 or f2\";}\n"
- "feature andfeature {if-feature \"f1 and f2\";}\n"
- "feature f6 {if-feature \"not f1\";}\n"
- "feature f7 {if-feature \"(f2 and f3) or (not f1)\";}\n"
- "feature f8 {if-feature \"f1 or f2 or f3 or orfeature or andfeature\";}\n"
- "feature f9 {if-feature \"not not f1\";}", mod);
- assert_non_null(mod->parsed->features);
- assert_int_equal(9, LY_ARRAY_COUNT(mod->parsed->features));
-
- /* all features are disabled by default */
- LY_ARRAY_FOR(mod->parsed->features, struct lysp_feature, f) {
- assert_false(f->flags & LYS_FENABLED);
- }
-
- /* some invalid expressions */
- TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f{if-feature f1;}",
- "Invalid value \"f1\" of if-feature - unable to find feature \"f1\".", NULL);
- TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f2{if-feature 'f and';}",
- "Invalid value \"f and\" of if-feature - unexpected end of expression.", NULL);
- TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f{if-feature 'or';}",
- "Invalid value \"or\" of if-feature - unexpected end of expression.", NULL);
- TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f2{if-feature '(f1';}",
- "Invalid value \"(f1\" of if-feature - non-matching opening and closing parentheses.", NULL);
- TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f2{if-feature 'f1)';}",
- "Invalid value \"f1)\" of if-feature - non-matching opening and closing parentheses.", NULL);
- TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f2{if-feature ---;}",
- "Invalid value \"---\" of if-feature - unable to find feature \"---\".", NULL);
- TEST_SCHEMA_PARSE_ERR(0, 0, "inv", "feature f1; feature f2{if-feature 'not f1';}",
- "Invalid value \"not f1\" of if-feature - YANG 1.1 expression in YANG 1.0 module.", NULL);
-
- ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} feature f1;}");
- TEST_SCHEMA_PARSE_ERR(0, 0, "inv", "feature f1 {if-feature f2;} feature f2 {if-feature f1;}",
- "Feature \"f1\" is indirectly referenced from itself.", NULL);
- TEST_SCHEMA_PARSE_ERR(0, 0, "inv", "feature f1 {if-feature f1;}",
- "Feature \"f1\" is referenced from itself.", NULL);
- TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f {if-feature ();}",
- "Invalid value \"()\" of if-feature - number of features in expression does not match the required number of operands for the operations.", NULL);
- TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'f1(';}",
- "Invalid value \"f1(\" of if-feature - non-matching opening and closing parentheses.", NULL);
- TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'and f1';}",
- "Invalid value \"and f1\" of if-feature - missing feature/expression before \"and\" operation.", NULL);
- TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'f1 not ';}",
- "Invalid value \"f1 not \" of if-feature - unexpected end of expression.", NULL);
- TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'f1 not not ';}",
- "Invalid value \"f1 not not \" of if-feature - unexpected end of expression.", NULL);
- TEST_SCHEMA_PARSE_ERR(1, 0, "inv", "feature f1; feature f2; feature f {if-feature 'or f1 f2';}",
- "Invalid value \"or f1 f2\" of if-feature - missing feature/expression before \"or\" operation.", NULL);
-
- /*
- * printing
- */
-
- /*
- * cleanup
- */
-}
diff --git a/tests/utests/schema/test_yang.c b/tests/utests/schema/test_yang.c
index 34c6d36..bb30a92 100644
--- a/tests/utests/schema/test_yang.c
+++ b/tests/utests/schema/test_yang.c
@@ -24,7 +24,7 @@
#include "schema_compile.h"
#include "tree_edit.h"
#include "tree_schema.h"
-#include "tree_schema_internal.h"
+#include "tree_schema_free.h"
/* originally static functions from parser_yang.c and parser_yin.c */
LY_ERR buf_add_char(struct ly_ctx *ctx, struct ly_in *in, size_t len, char **buf, size_t *buf_len, size_t *buf_used);
@@ -57,6 +57,7 @@
LY_ERR parse_type_enum_value_pos(struct lys_yang_parser_ctx *ctx, enum ly_stmt val_kw, int64_t *value, uint16_t *flags, struct lysp_ext_instance **exts);
struct lys_yang_parser_ctx *YCTX;
+struct lysf_ctx fctx;
struct ly_in in = {0};
@@ -91,19 +92,24 @@
YCTX->in = ∈
LOG_LOCINIT(NULL, NULL, NULL, &in);
+ fctx.ctx = PARSER_CTX(YCTX);
+ fctx.mod = pmod->mod;
+
return 0;
}
static int
teardown(void **state)
{
- lys_module_free(PARSER_CUR_PMOD(YCTX)->mod, 0);
+ lys_module_free(&fctx, PARSER_CUR_PMOD(YCTX)->mod, 0);
LOG_LOCBACK(0, 0, 0, 1);
ly_set_free(YCTX->parsed_mods, NULL);
free(YCTX);
YCTX = NULL;
+ lysf_ctx_erase(&fctx);
+
UTEST_TEARDOWN;
return 0;
@@ -717,7 +723,7 @@
struct ly_ctx *ly_ctx = PARSER_CUR_PMOD(ctx)->mod->ctx;
struct lysp_module *pmod;
- lys_module_free(PARSER_CUR_PMOD(ctx)->mod, 0);
+ lys_module_free(&fctx, PARSER_CUR_PMOD(ctx)->mod, 0);
pmod = calloc(1, sizeof *pmod);
ctx->parsed_mods->objs[0] = pmod;
pmod->mod = calloc(1, sizeof *pmod->mod);
@@ -725,6 +731,7 @@
pmod->mod->ctx = ly_ctx;
ctx->in->line = 1;
+ fctx.mod = pmod->mod;
return pmod;
}
@@ -735,7 +742,7 @@
struct ly_ctx *ly_ctx = PARSER_CUR_PMOD(ctx)->mod->ctx;
struct lysp_submodule *submod;
- lys_module_free(PARSER_CUR_PMOD(ctx)->mod, 0);
+ lys_module_free(&fctx, PARSER_CUR_PMOD(ctx)->mod, 0);
submod = calloc(1, sizeof *submod);
ctx->parsed_mods->objs[0] = submod;
submod->mod = calloc(1, sizeof *submod->mod);
@@ -743,6 +750,8 @@
submod->mod->parsed = (struct lysp_module *)submod;
submod->mod->ctx = ly_ctx;
+ fctx.mod = submod->mod;
+
return submod;
}
@@ -937,7 +946,7 @@
assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m));
CHECK_LOG_CTX("Trailing garbage \"module q {names...\" after module, expected end-of-input.", "Line number 1.");
yang_parser_ctx_free(ctx_p);
- lys_module_free(m, 0);
+ lys_module_free(&fctx, m, 0);
in.current = "prefix " SCHEMA_BEGINNING "}";
m = calloc(1, sizeof *m);
@@ -945,7 +954,7 @@
assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m));
CHECK_LOG_CTX("Invalid keyword \"prefix\", expected \"module\" or \"submodule\".", "Line number 1.");
yang_parser_ctx_free(ctx_p);
- lys_module_free(m, 0);
+ lys_module_free(&fctx, m, 0);
in.current = "module " SCHEMA_BEGINNING "leaf enum {type enumeration {enum seven { position 7;}}}}";
m = calloc(1, sizeof *m);
@@ -953,7 +962,7 @@
assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m));
CHECK_LOG_CTX("Invalid keyword \"position\" as a child of \"enum\".", "Line number 1.");
yang_parser_ctx_free(ctx_p);
- lys_module_free(m, 0);
+ lys_module_free(&fctx, m, 0);
/* extensions */
TEST_GENERIC("prefix:test;}", mod->exts,
@@ -1094,7 +1103,7 @@
in.current = "cont {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_container(YCTX, NULL, (struct lysp_node**)&c)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)c); c = NULL;
+ lysp_node_free(&fctx, (struct lysp_node*)c); c = NULL;
TEST_DUP("config", "true", "false");
TEST_DUP("description", "text1", "text2");
@@ -1118,24 +1127,24 @@
assert_non_null(c->typedefs);
ly_set_erase(&YCTX->tpdfs_nodes, NULL);
ly_set_erase(&YCTX->grps_nodes, NULL);
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)c); c = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)c); c = NULL;
/* invalid */
in.current = " cont {augment /root;} ...";
assert_int_equal(LY_EVALID, parse_container(YCTX, NULL, (struct lysp_node **)&c));
CHECK_LOG_CTX("Invalid keyword \"augment\" as a child of \"container\".", "Line number 1.");
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)c); c = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)c); c = NULL;
in.current = " cont {nonsence true;} ...";
assert_int_equal(LY_EVALID, parse_container(YCTX, NULL, (struct lysp_node **)&c));
CHECK_LOG_CTX("Invalid character sequence \"nonsence\", expected a keyword.", "Line number 1.");
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)c); c = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)c); c = NULL;
PARSER_CUR_PMOD(YCTX)->version = 1; /* simulate YANG 1.0 */
in.current = " cont {action x;} ...";
assert_int_equal(LY_EVALID, parse_container(YCTX, NULL, (struct lysp_node **)&c));
CHECK_LOG_CTX("Invalid keyword \"action\" as a child of \"container\" - "
"the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)c); c = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)c); c = NULL;
}
static void
@@ -1148,7 +1157,7 @@
in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_leaf(YCTX, NULL, (struct lysp_node**)&l)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)l); l = NULL;
+ lysp_node_free(&fctx, (struct lysp_node*)l); l = NULL;
TEST_DUP("config", "true", "false");
TEST_DUP("default", "x", "y");
@@ -1170,25 +1179,25 @@
assert_string_equal("yyy", l->units);
assert_string_equal("string", l->type.name);
assert_non_null(l->musts);
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)l); l = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)l); l = NULL;
/* full content - now with mandatory */
in.current = "l {mandatory true; type string;} ...";
assert_int_equal(LY_SUCCESS, parse_leaf(YCTX, NULL, (struct lysp_node **)&l));
CHECK_LYSP_NODE(l, NULL, 0, LYS_MAND_TRUE, 0, "l", 0, LYS_LEAF, 0, NULL, 0);
assert_string_equal("string", l->type.name);
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)l); l = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)l); l = NULL;
/* invalid */
in.current = " l {description \"missing type\";} ...";
assert_int_equal(LY_EVALID, parse_leaf(YCTX, NULL, (struct lysp_node **)&l));
CHECK_LOG_CTX("Missing mandatory keyword \"type\" as a child of \"leaf\".", "Line number 1.");
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)l); l = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)l); l = NULL;
in.current = "l { type iid { path qpud wrong {";
assert_int_equal(LY_EVALID, parse_leaf(YCTX, NULL, (struct lysp_node **)&l));
CHECK_LOG_CTX("Invalid character sequence \"wrong\", expected a keyword.", "Line number 1.");
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)l); l = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)l); l = NULL;
}
static void
@@ -1203,7 +1212,7 @@
in.current = "ll {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_leaflist(YCTX, NULL, (struct lysp_node**)&ll)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)ll); ll = NULL;
+ lysp_node_free(&fctx, (struct lysp_node*)ll); ll = NULL;
TEST_DUP("config", "true", "false");
TEST_DUP("description", "text1", "text2");
@@ -1233,7 +1242,7 @@
assert_string_equal("string", ll->type.name);
assert_non_null(ll->musts);
assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_USER | LYS_SET_MAX, ll->flags);
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)ll); ll = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)ll); ll = NULL;
/* full content - now with min-elements */
in.current = "ll {min-elements 10; type string;} ...";
@@ -1243,19 +1252,19 @@
assert_int_equal(0, ll->max);
assert_int_equal(10, ll->min);
assert_int_equal(LYS_SET_MIN, ll->flags);
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)ll); ll = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)ll); ll = NULL;
/* invalid */
in.current = " ll {description \"missing type\";} ...";
assert_int_equal(LY_EVALID, parse_leaflist(YCTX, NULL, (struct lysp_node **)&ll));
CHECK_LOG_CTX("Missing mandatory keyword \"type\" as a child of \"leaf-list\".", "Line number 1.");
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)ll); ll = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)ll); ll = NULL;
PARSER_CUR_PMOD(YCTX)->version = 1; /* simulate YANG 1.0 - default statement is not allowed */
in.current = " ll {default xx; type string;} ...";
assert_int_equal(LY_EVALID, parse_leaflist(YCTX, NULL, (struct lysp_node **)&ll));
CHECK_LOG_CTX("Invalid keyword \"default\" as a child of \"leaf-list\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)ll); ll = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)ll); ll = NULL;
}
static void
@@ -1271,7 +1280,7 @@
in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_list(YCTX, NULL, (struct lysp_node**)&l)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)l); l = NULL;
+ lysp_node_free(&fctx, (struct lysp_node*)l); l = NULL;
TEST_DUP("config", "true", "false");
TEST_DUP("description", "text1", "text2");
@@ -1301,14 +1310,14 @@
assert_non_null(l->musts);
ly_set_erase(&YCTX->tpdfs_nodes, NULL);
ly_set_erase(&YCTX->grps_nodes, NULL);
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)l); l = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)l); l = NULL;
/* invalid content */
PARSER_CUR_PMOD(YCTX)->version = 1; /* simulate YANG 1.0 */
in.current = "l {action x;} ...";
assert_int_equal(LY_EVALID, parse_list(YCTX, NULL, (struct lysp_node **)&l));
CHECK_LOG_CTX("Invalid keyword \"action\" as a child of \"list\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)l); l = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)l); l = NULL;
}
static void
@@ -1323,7 +1332,7 @@
in.current = "ch {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_choice(YCTX, NULL, (struct lysp_node**)&ch)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)ch); ch = NULL;
+ lysp_node_free(&fctx, (struct lysp_node*)ch); ch = NULL;
TEST_DUP("config", "true", "false");
TEST_DUP("default", "a", "b");
@@ -1339,14 +1348,14 @@
"leaf-list ll {type string;} list li;mandatory true;reference test;status current;when true;m:ext;} ...";
assert_int_equal(LY_SUCCESS, parse_choice(YCTX, NULL, (struct lysp_node **)&ch));
CHECK_LYSP_NODE(ch, "test", 1, LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE, 1, "ch", 0, LYS_CHOICE, 0, "test", 1);
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)ch); ch = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)ch); ch = NULL;
/* full content - the default missing from the previous node */
in.current = "ch {default c;case c;} ...";
assert_int_equal(LY_SUCCESS, parse_choice(YCTX, NULL, (struct lysp_node **)&ch));
CHECK_LYSP_NODE(ch, NULL, 0, 0, 0, "ch", 0, LYS_CHOICE, 0, NULL, 0);
assert_string_equal("c", ch->dflt.str);
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)ch); ch = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)ch); ch = NULL;
}
static void
@@ -1361,7 +1370,7 @@
in.current = "cs {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_case(YCTX, NULL, (struct lysp_node**)&cs)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)cs); cs = NULL;
+ lysp_node_free(&fctx, (struct lysp_node*)cs); cs = NULL;
TEST_DUP("description", "text1", "text2");
TEST_DUP("reference", "1", "2");
@@ -1374,13 +1383,13 @@
"leaf-list ll {type string;} list li;reference test;status current;uses grp;when true;m:ext;} ...";
assert_int_equal(LY_SUCCESS, parse_case(YCTX, NULL, (struct lysp_node **)&cs));
CHECK_LYSP_NODE(cs, "test", 1, LYS_STATUS_CURR, 1, "cs", 0, LYS_CASE, 0, "test", 1);
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)cs); cs = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)cs); cs = NULL;
/* invalid content */
in.current = "cs {config true} ...";
assert_int_equal(LY_EVALID, parse_case(YCTX, NULL, (struct lysp_node **)&cs));
CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"case\".", "Line number 1.");
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)cs); cs = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)cs); cs = NULL;
}
static void
@@ -1399,7 +1408,7 @@
in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_any(YCTX, kw, NULL, (struct lysp_node**)&any)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)any); any = NULL;
+ lysp_node_free(&fctx, (struct lysp_node*)any); any = NULL;
TEST_DUP("config", "true", "false");
TEST_DUP("description", "text1", "text2");
@@ -1416,7 +1425,7 @@
uint16_t node_type = kw == LY_STMT_ANYDATA ? LYS_ANYDATA : LYS_ANYXML;
CHECK_LYSP_NODE(any, "test", 1, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_MAND_TRUE, 1, "any", 0, node_type, 0, "test", 1);
assert_non_null(any->musts);
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)any); any = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)any); any = NULL;
}
static void
@@ -1444,7 +1453,7 @@
in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_grouping(YCTX, NULL, &grp)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, &grp->node); grp = NULL;
+ lysp_node_free(&fctx, &grp->node); grp = NULL;
TEST_DUP("description", "text1", "text2");
TEST_DUP("reference", "1", "2");
@@ -1465,20 +1474,20 @@
assert_int_equal(LYS_STATUS_CURR, grp->flags);
ly_set_erase(&YCTX->tpdfs_nodes, NULL);
ly_set_erase(&YCTX->grps_nodes, NULL);
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, &grp->node);
+ lysp_node_free(&fctx, &grp->node);
grp = NULL;
/* invalid content */
in.current = "grp {config true} ...";
assert_int_equal(LY_EVALID, parse_grouping(YCTX, NULL, &grp));
CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"grouping\".", "Line number 1.");
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, &grp->node);
+ lysp_node_free(&fctx, &grp->node);
grp = NULL;
in.current = "grp {must 'expr'} ...";
assert_int_equal(LY_EVALID, parse_grouping(YCTX, NULL, &grp));
CHECK_LOG_CTX("Invalid keyword \"must\" as a child of \"grouping\".", "Line number 1.");
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, &grp->node);
+ lysp_node_free(&fctx, &grp->node);
grp = NULL;
}
@@ -1496,7 +1505,7 @@
in.current = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_action(YCTX, NULL, &rpcs)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)rpcs); rpcs = NULL;
+ lysp_node_free(&fctx, (struct lysp_node*)rpcs); rpcs = NULL;
TEST_DUP("description", "text1", "text2");
TEST_DUP("input", "{leaf l1 {type empty;}} description a", "{leaf l2 {type empty;}} description a");
@@ -1541,15 +1550,15 @@
ly_set_erase(&YCTX->tpdfs_nodes, NULL);
ly_set_erase(&YCTX->grps_nodes, NULL);
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)rpcs); rpcs = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)rpcs); rpcs = NULL;
/* invalid content */
in.current = "func {config true} ...";
assert_int_equal(LY_EVALID, parse_action(YCTX, NULL, &rpcs));
CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"rpc\".", "Line number 1.");
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)rpcs); rpcs = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)rpcs); rpcs = NULL;
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)c);
+ lysp_node_free(&fctx, (struct lysp_node *)c);
}
static void
@@ -1566,7 +1575,7 @@
in.current = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_notif(YCTX, NULL, ¬ifs)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)notifs); notifs = NULL;
+ lysp_node_free(&fctx, (struct lysp_node*)notifs); notifs = NULL;
TEST_DUP("description", "text1", "text2");
TEST_DUP("reference", "1", "2");
@@ -1594,15 +1603,15 @@
ly_set_erase(&YCTX->tpdfs_nodes, NULL);
ly_set_erase(&YCTX->grps_nodes, NULL);
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)notifs); notifs = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)notifs); notifs = NULL;
/* invalid content */
in.current = "ntf {config true} ...";
assert_int_equal(LY_EVALID, parse_notif(YCTX, NULL, ¬ifs));
CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"notification\".", "Line number 1.");
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)notifs); notifs = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)notifs); notifs = NULL;
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)c);
+ lysp_node_free(&fctx, (struct lysp_node *)c);
}
static void
@@ -1617,7 +1626,7 @@
in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_uses(YCTX, NULL, (struct lysp_node**)&u)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)u); u = NULL;
+ lysp_node_free(&fctx, (struct lysp_node*)u); u = NULL;
TEST_DUP("description", "text1", "text2");
TEST_DUP("reference", "1", "2");
@@ -1631,7 +1640,7 @@
CHECK_LYSP_NODE(u, "test", 1, LYS_STATUS_CURR, 1, "grpref", 0, LYS_USES, 0, "test", 1);
assert_non_null(u->augments);
assert_non_null(u->refines);
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)u); u = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)u); u = NULL;
}
static void
@@ -1646,7 +1655,7 @@
in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_augment(YCTX, NULL, &a)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)a); a = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)a); a = NULL;
TEST_DUP("description", "text1", "text2");
TEST_DUP("reference", "1", "2");
@@ -1668,7 +1677,7 @@
assert_non_null(a->when);
assert_null(a->parent);
assert_int_equal(LYS_STATUS_CURR, a->flags);
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)a); a = NULL;
+ lysp_node_free(&fctx, (struct lysp_node *)a); a = NULL;
}
static void
diff --git a/tests/utests/schema/test_yin.c b/tests/utests/schema/test_yin.c
index 6f75f6b..6b8a4b4 100644
--- a/tests/utests/schema/test_yin.c
+++ b/tests/utests/schema/test_yin.c
@@ -110,6 +110,7 @@
CHECK_LYSP_EXT_INSTANCE((NODE), NULL, 1, INSUBSTMT, 0, "myext:c-define", LY_VALUE_XML)
struct lys_yin_parser_ctx *YCTX;
+struct lysf_ctx fctx;
static int
setup_ctx(void **state)
@@ -140,13 +141,16 @@
setup_ctx(state);
+ fctx.ctx = UTEST_LYCTX;
+ fctx.mod = PARSER_CUR_PMOD(YCTX)->mod;
+
return 0;
}
static int
teardown_ctx(void **UNUSED(state))
{
- lys_module_free(PARSER_CUR_PMOD(YCTX)->mod, 0);
+ lys_module_free(&fctx, PARSER_CUR_PMOD(YCTX)->mod, 0);
yin_parser_ctx_free(YCTX);
YCTX = NULL;
@@ -158,6 +162,8 @@
{
teardown_ctx(state);
+ lysf_ctx_erase(&fctx);
+
UTEST_TEARDOWN;
return 0;
@@ -1286,7 +1292,7 @@
CHECK_LYSP_TYPE_ENUM(type.enums, "desc...", 1, flags, 1, "enum-name", "ref...", 55);
assert_string_equal(type.enums->iffeatures[0].str, "feature");
TEST_1_CHECK_LYSP_EXT_INSTANCE(type.enums->exts, LY_STMT_ENUM);
- lysp_type_free(UTEST_LYCTX, &type);
+ lysp_type_free(&fctx, &type);
memset(&type, 0, sizeof type);
data = ELEMENT_WRAPPER_START
@@ -1294,7 +1300,7 @@
ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
assert_string_equal(type.enums->name, "enum-name");
- lysp_type_free(UTEST_LYCTX, &type);
+ lysp_type_free(&fctx, &type);
memset(&type, 0, sizeof type);
}
@@ -1320,7 +1326,7 @@
CHECK_LYSP_TYPE_ENUM(type.bits, "desc...", 1, flags, 1, "bit-name", "ref...", 55);
assert_string_equal(type.bits->iffeatures[0].str, "feature");
TEST_1_CHECK_LYSP_EXT_INSTANCE(type.bits->exts, LY_STMT_BIT);
- lysp_type_free(UTEST_LYCTX, &type);
+ lysp_type_free(&fctx, &type);
memset(&type, 0, sizeof type);
data = ELEMENT_WRAPPER_START
@@ -1328,7 +1334,7 @@
ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
CHECK_LYSP_TYPE_ENUM(type.bits, NULL, 0, 0, 0, "bit-name", NULL, 0);
- lysp_type_free(UTEST_LYCTX, &type);
+ lysp_type_free(&fctx, &type);
memset(&type, 0, sizeof type);
}
@@ -1518,7 +1524,7 @@
"err-app-tag", "err-msg", 1, "ref");
assert_true(type.flags & LYS_SET_LENGTH);
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.length->exts[0]), LY_STMT_LENGTH);
- lysp_type_free(UTEST_LYCTX, &type);
+ lysp_type_free(&fctx, &type);
memset(&type, 0, sizeof(type));
/* min subelems */
@@ -1529,14 +1535,14 @@
assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
CHECK_LYSP_RESTR(type.length, "length-str", NULL,
NULL, NULL, 0, NULL);
- lysp_type_free(UTEST_LYCTX, &type);
+ lysp_type_free(&fctx, &type);
assert_true(type.flags & LYS_SET_LENGTH);
memset(&type, 0, sizeof(type));
data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
CHECK_LOG_CTX("Missing mandatory attribute value of length element.", "Line number 1.");
- lysp_type_free(UTEST_LYCTX, &type);
+ lysp_type_free(&fctx, &type);
memset(&type, 0, sizeof(type));
}
@@ -1587,14 +1593,14 @@
CHECK_LYSP_RESTR(type.patterns, "\x015super_pattern", "\"pattern-desc\"",
"err-app-tag-value", "err-msg-value", 1, "pattern-ref");
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.patterns->exts[0]), LY_STMT_PATTERN);
- lysp_type_free(UTEST_LYCTX, &type);
+ lysp_type_free(&fctx, &type);
memset(&type, 0, sizeof(type));
/* min subelems */
data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
CHECK_LYSP_RESTR(type.patterns, "\x006pattern", NULL, NULL, NULL, 0, NULL);
- lysp_type_free(UTEST_LYCTX, &type);
+ lysp_type_free(&fctx, &type);
memset(&type, 0, sizeof(type));
}
@@ -1690,7 +1696,7 @@
"err-app-tag", "err-msg", 1, "ref");
assert_true(type.flags & LYS_SET_RANGE);
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.range->exts[0]), LY_STMT_RANGE);
- lysp_type_free(UTEST_LYCTX, &type);
+ lysp_type_free(&fctx, &type);
memset(&type, 0, sizeof(type));
/* min subelems */
@@ -1698,7 +1704,7 @@
assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
CHECK_LYSP_RESTR(type.range, "range-str", NULL,
NULL, NULL, 0, NULL);
- lysp_type_free(UTEST_LYCTX, &type);
+ lysp_type_free(&fctx, &type);
memset(&type, 0, sizeof(type));
}
@@ -1713,7 +1719,7 @@
assert_int_equal(type.require_instance, 1);
assert_true(type.flags & LYS_SET_REQINST);
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LY_STMT_REQUIRE_INSTANCE);
- lysp_type_free(UTEST_LYCTX, &type);
+ lysp_type_free(&fctx, &type);
memset(&type, 0, sizeof(type));
data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END;
@@ -1841,13 +1847,13 @@
assert_true(type.flags & LYS_SET_RANGE);
assert_true(type.flags & LYS_SET_REQINST);
assert_true(type.flags & LYS_SET_TYPE);
- lysp_type_free(UTEST_LYCTX, &type);
+ lysp_type_free(&fctx, &type);
memset(&type, 0, sizeof(type));
/* min subelems */
data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
- lysp_type_free(UTEST_LYCTX, &type);
+ lysp_type_free(&fctx, &type);
memset(&type, 0, sizeof(type));
}
@@ -1950,7 +1956,7 @@
CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
assert_string_equal(parsed->iffeatures[0].str, "feature");
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_ANYXML);
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
/* anydata max subelems */
@@ -1975,7 +1981,7 @@
CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
assert_string_equal(parsed->iffeatures[0].str, "feature");
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_ANYDATA);
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
/* min subelems */
@@ -1986,7 +1992,7 @@
assert_ptr_equal(parsed->parent, node_meta.parent);
CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
"any-name", 0, LYS_ANYDATA, 1, NULL, 0);
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
}
static void
@@ -2027,7 +2033,7 @@
assert_string_equal(parsed->type.name, "type");
assert_string_equal(parsed->units, "uni");
assert_string_equal(parsed->dflt.str, "def-val");
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
/* min elements */
@@ -2036,7 +2042,7 @@
parsed = (struct lysp_node_leaf *)siblings;
assert_string_equal(parsed->name, "leaf");
assert_string_equal(parsed->type.name, "type");
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
}
@@ -2081,7 +2087,7 @@
assert_string_equal(parsed->units, "uni");
CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF_LIST);
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
data = ELEMENT_WRAPPER_START
@@ -2112,7 +2118,7 @@
assert_string_equal(parsed->type.name, "type");
assert_string_equal(parsed->units, "uni");
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LEAF_LIST);
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
data = ELEMENT_WRAPPER_START
@@ -2143,7 +2149,7 @@
assert_int_equal(parsed->max, 15);
assert_string_equal(parsed->type.name, "type");
assert_string_equal(parsed->units, "uni");
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
data = ELEMENT_WRAPPER_START
@@ -2155,7 +2161,7 @@
parsed = (struct lysp_node_leaflist *)siblings;
assert_string_equal(parsed->name, "llist");
assert_string_equal(parsed->type.name, "type");
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
/* invalid combinations */
@@ -2168,7 +2174,7 @@
ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
CHECK_LOG_CTX("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5.", "Line number 4.");
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
data = ELEMENT_WRAPPER_START
@@ -2180,7 +2186,7 @@
ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
CHECK_LOG_CTX("Invalid combination of sub-elemnts \"min-elements\" and \"default\" in \"leaf-list\" element.", "Line number 5.");
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
data = ELEMENT_WRAPPER_START
@@ -2189,7 +2195,7 @@
ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
CHECK_LOG_CTX("Missing mandatory sub-element \"type\" of \"leaf-list\" element.", "Line number 1.");
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
}
@@ -2255,14 +2261,14 @@
assert_string_equal(parsed->refines->nodeid, "target");
assert_string_equal(parsed->augments->nodeid, "target");
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_USES);
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
/* min subelems */
data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
assert_string_equal(siblings[0].name, "uses-name");
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
}
@@ -2338,7 +2344,7 @@
assert_string_equal(parsed->typedefs->name, "tpdf");
assert_string_equal(parsed->uniques->str, "utag");
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_LIST);
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
ly_set_erase(&YCTX->tpdfs_nodes, NULL);
siblings = NULL;
@@ -2348,7 +2354,7 @@
parsed = (struct lysp_node_list *)&siblings[0];
CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
"list-name", 0, LYS_LIST, 0, NULL, 0);
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
}
@@ -2410,14 +2416,14 @@
assert_string_equal(notifs->ref, "ref");
assert_string_equal(notifs->typedefs->name, "tpdf");
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(notifs->exts[0]), LY_STMT_NOTIFICATION);
- lysp_node_free(UTEST_LYCTX, (struct lysp_node *)notifs);
+ lysp_node_free(&fctx, (struct lysp_node *)notifs);
notifs = NULL;
/* min subelems */
data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, ¬if_meta, NULL, NULL), LY_SUCCESS);
assert_string_equal(notifs->name, "notif-name");
- lysp_node_free(UTEST_LYCTX, (struct lysp_node *)notifs);
+ lysp_node_free(&fctx, (struct lysp_node *)notifs);
notifs = NULL;
}
@@ -2472,14 +2478,14 @@
assert_string_equal(grps->child->next->next->next->next->next->next->next->name, "choice");
assert_int_equal(grps->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(grps->exts[0]), LY_STMT_GROUPING);
- lysp_node_free(UTEST_LYCTX, &grps->node);
+ lysp_node_free(&fctx, &grps->node);
grps = NULL;
/* min subelems */
data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS);
assert_string_equal(grps->name, "grp-name");
- lysp_node_free(UTEST_LYCTX, &grps->node);
+ lysp_node_free(&fctx, &grps->node);
grps = NULL;
}
@@ -2551,7 +2557,7 @@
assert_string_equal(parsed->notifs->name, "notf");
assert_string_equal(parsed->actions->name, "act");
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CONTAINER);
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
ly_set_erase(&YCTX->tpdfs_nodes, NULL);
siblings = NULL;
@@ -2561,7 +2567,7 @@
parsed = (struct lysp_node_container *)siblings;
CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
"cont-name", 0, LYS_CONTAINER, 0, NULL, 0);
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
}
@@ -2619,7 +2625,7 @@
assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
assert_null(parsed->child->next->next->next->next->next->next->next->next);
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CASE);
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
/* min subelems */
@@ -2628,7 +2634,7 @@
parsed = (struct lysp_node_case *)siblings;
CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
"case-name", 0, LYS_CASE, 0, NULL, 0);
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
}
@@ -2689,7 +2695,7 @@
assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
assert_null(parsed->child->next->next->next->next->next->next->next->next);
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LY_STMT_CHOICE);
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
/* min subelems */
@@ -2699,7 +2705,7 @@
assert_string_equal(parsed->name, "choice-name");
CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
"choice-name", 0, LYS_CHOICE, 0, NULL, 0);
- lysp_node_free(UTEST_LYCTX, siblings);
+ lysp_node_free(&fctx, siblings);
siblings = NULL;
}
@@ -2751,7 +2757,7 @@
assert_int_equal(inout.child->next->next->next->next->next->next->next->nodetype, LYS_USES);
assert_null(inout.child->next->next->next->next->next->next->next->next);
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]), LY_STMT_INPUT);
- lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
+ lysp_node_free(&fctx, (struct lysp_node *)&inout);
memset(&inout, 0, sizeof inout);
/* max subelements */
@@ -2795,24 +2801,24 @@
assert_int_equal(inout.child->next->next->next->next->next->next->next->nodetype, LYS_USES);
assert_null(inout.child->next->next->next->next->next->next->next->next);
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]), LY_STMT_OUTPUT);
- lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
+ lysp_node_free(&fctx, (struct lysp_node *)&inout);
memset(&inout, 0, sizeof inout);
/* min subelems */
data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
- lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
+ lysp_node_free(&fctx, (struct lysp_node *)&inout);
memset(&inout, 0, sizeof inout);
data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
- lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout);
+ lysp_node_free(&fctx, (struct lysp_node *)&inout);
memset(&inout, 0, sizeof inout);
/* 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);
+ lysp_node_free(&fctx, (struct lysp_node *)&inout);
CHECK_LOG_CTX("Unexpected attribute \"name\" of \"input\" element.", "Line number 1.");
memset(&inout, 0, sizeof inout);
}
@@ -2859,7 +2865,7 @@
assert_string_equal(actions->output.musts->arg.str, "cond");
assert_string_equal(actions->input.child->name, "uses-name");
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]), LY_STMT_ACTION);
- lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions);
+ lysp_node_free(&fctx, (struct lysp_node *)actions);
actions = NULL;
PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
@@ -2892,14 +2898,14 @@
assert_string_equal(actions->input.child->name, "uses-name");
assert_string_equal(actions->output.musts->arg.str, "cond");
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]), LY_STMT_RPC);
- lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions);
+ lysp_node_free(&fctx, (struct lysp_node *)actions);
actions = NULL;
/* min subelems */
data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
assert_string_equal(actions->name, "act");
- lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions);
+ lysp_node_free(&fctx, (struct lysp_node *)actions);
actions = NULL;
}
@@ -2963,13 +2969,13 @@
assert_string_equal(augments->actions->name, "action");
assert_string_equal(augments->notifs->name, "notif");
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(augments->exts[0]), LY_STMT_AUGMENT);
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)augments);
+ lysp_node_free(&fctx, (struct lysp_node *)augments);
augments = NULL;
data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS);
assert_string_equal(augments->nodeid, "target");
- lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)augments);
+ lysp_node_free(&fctx, (struct lysp_node *)augments);
augments = NULL;
}
@@ -3031,13 +3037,15 @@
struct ly_ctx *ly_ctx = PARSER_CUR_PMOD(ctx)->mod->ctx;
struct lysp_module *pmod;
- lys_module_free(PARSER_CUR_PMOD(ctx)->mod, 0);
+ lys_module_free(&fctx, PARSER_CUR_PMOD(ctx)->mod, 0);
pmod = calloc(1, sizeof *pmod);
ctx->parsed_mods->objs[0] = pmod;
pmod->mod = calloc(1, sizeof *pmod->mod);
pmod->mod->parsed = pmod;
pmod->mod->ctx = ly_ctx;
+ fctx.mod = pmod->mod;
+
return pmod;
}
@@ -3161,7 +3169,7 @@
struct ly_ctx *ly_ctx = PARSER_CUR_PMOD(ctx)->mod->ctx;
struct lysp_submodule *submod;
- lys_module_free(PARSER_CUR_PMOD(ctx)->mod, 0);
+ lys_module_free(&fctx, PARSER_CUR_PMOD(ctx)->mod, 0);
submod = calloc(1, sizeof *submod);
ctx->parsed_mods->objs[0] = submod;
submod->mod = calloc(1, sizeof *submod->mod);
@@ -3169,6 +3177,8 @@
submod->mod->parsed = (struct lysp_module *)submod;
submod->mod->ctx = ly_ctx;
+ fctx.mod = submod->mod;
+
return submod;
}
@@ -3320,7 +3330,7 @@
assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS);
assert_null(mod->parsed->exts->child->next->child);
assert_string_equal(mod->parsed->exts->child->next->arg, "test");
- lys_module_free(mod, 0);
+ lys_module_free(&fctx, mod, 0);
yin_parser_ctx_free(yin_ctx);
ly_in_free(in, 0);
mod = NULL;
@@ -3358,7 +3368,7 @@
"</module>\n";
assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS);
- lys_module_free(mod, 0);
+ lys_module_free(&fctx, mod, 0);
yin_parser_ctx_free(yin_ctx);
ly_in_free(in, 0);
mod = NULL;
@@ -3373,7 +3383,7 @@
"</module>\n";
assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS);
- lys_module_free(mod, 0);
+ lys_module_free(&fctx, mod, 0);
yin_parser_ctx_free(yin_ctx);
ly_in_free(in, 0);
mod = NULL;
@@ -3386,7 +3396,7 @@
assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_EINVAL);
CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL);
- lys_module_free(mod, 0);
+ lys_module_free(&fctx, mod, 0);
yin_parser_ctx_free(yin_ctx);
ly_in_free(in, 0);
@@ -3401,7 +3411,7 @@
assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_EVALID);
CHECK_LOG_CTX("Trailing garbage \"<module>\" after module, expected end-of-input.", "Line number 6.");
- lys_module_free(mod, 0);
+ lys_module_free(&fctx, mod, 0);
yin_parser_ctx_free(yin_ctx);
ly_in_free(in, 0);
mod = NULL;
@@ -3444,7 +3454,7 @@
"</submodule>";
assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_SUCCESS);
- lysp_module_free((struct lysp_module *)submod);
+ lysp_module_free(&fctx, (struct lysp_module *)submod);
yin_parser_ctx_free(yin_ctx);
ly_in_free(in, 0);
yin_ctx = NULL;
@@ -3459,7 +3469,7 @@
"</submodule>";
assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_SUCCESS);
- lysp_module_free((struct lysp_module *)submod);
+ lysp_module_free(&fctx, (struct lysp_module *)submod);
yin_parser_ctx_free(yin_ctx);
ly_in_free(in, 0);
yin_ctx = NULL;
@@ -3471,7 +3481,7 @@
assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_EINVAL);
CHECK_LOG_CTX("Input data contains module in situation when a submodule is expected.", NULL);
- lysp_module_free((struct lysp_module *)submod);
+ lysp_module_free(&fctx, (struct lysp_module *)submod);
yin_parser_ctx_free(yin_ctx);
ly_in_free(in, 0);
yin_ctx = NULL;
@@ -3493,7 +3503,7 @@
assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_EVALID);
CHECK_LOG_CTX("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input.", "Line number 8.");
- lysp_module_free((struct lysp_module *)submod);
+ lysp_module_free(&fctx, (struct lysp_module *)submod);
yin_parser_ctx_free(yin_ctx);
ly_in_free(in, 0);
yin_ctx = NULL;