libyang REFACTOR return values and options changes
Unified, all functions that return a variety
of errors return LY_ERR. Any options such as
NOSIBLINGS, WITHSIBLINGS and so on were replaced
by function variants with suffixes _single, _all,
_tree, and _siblings.
diff --git a/src/context.c b/src/context.c
index 302638e..b2637ff 100644
--- a/src/context.c
+++ b/src/context.c
@@ -257,10 +257,9 @@
/* load internal modules */
for (i = 0; i < ((options & LY_CTX_NOYANGLIBRARY) ? (LY_INTERNAL_MODS_COUNT - 2) : LY_INTERNAL_MODS_COUNT); i++) {
ly_in_memory(in, internal_modules[i].data);
- module = (struct lys_module *)lys_parse_mem_module(ctx, in, internal_modules[i].format,
- internal_modules[i].implemented, NULL, NULL);
- LY_CHECK_ERR_GOTO(!module, rc = ly_errcode(ctx), error);
- LY_CHECK_GOTO((rc = lys_compile(&module, 0)), error);
+ LY_CHECK_GOTO(rc = lys_parse_mem_module(ctx, in, internal_modules[i].format, internal_modules[i].implemented,
+ NULL, NULL, &module), error);
+ LY_CHECK_GOTO(rc = lys_compile(&module, 0), error);
}
ly_in_free(in, 0);
@@ -551,7 +550,6 @@
ylib_feature(struct lyd_node *parent, const struct lys_module *cur_mod)
{
LY_ARRAY_COUNT_TYPE i;
- struct lyd_node *node;
if (!cur_mod->implemented) {
/* no features can be enabled */
@@ -563,8 +561,7 @@
continue;
}
- node = lyd_new_term(parent, NULL, "feature", cur_mod->compiled->features[i].name);
- LY_CHECK_RET(!node, LY_EOTHER);
+ LY_CHECK_RET(lyd_new_term(parent, NULL, "feature", cur_mod->compiled->features[i].name, NULL));
}
return LY_SUCCESS;
@@ -574,7 +571,6 @@
ylib_deviation(struct lyd_node *parent, const struct lys_module *cur_mod, int bis)
{
LY_ARRAY_COUNT_TYPE i;
- struct lyd_node *node;
struct lys_module *mod;
if (!cur_mod->implemented) {
@@ -586,11 +582,10 @@
mod = cur_mod->compiled->deviated_by[i];
if (bis) {
- node = lyd_new_term(parent, NULL, "deviation", mod->name);
- LY_CHECK_RET(!node, LY_EOTHER);
+ LY_CHECK_RET(lyd_new_term(parent, NULL, "deviation", mod->name, NULL));
} else {
- node = lyd_new_list(parent, NULL, "deviation", mod->name, (mod->parsed->revs ? mod->parsed->revs[0].date : ""));
- LY_CHECK_RET(!node, LY_EOTHER);
+ LY_CHECK_RET(lyd_new_list(parent, NULL, "deviation", NULL, mod->name,
+ (mod->parsed->revs ? mod->parsed->revs[0].date : "")));
}
}
@@ -600,35 +595,34 @@
static LY_ERR
ylib_submodules(struct lyd_node *parent, const struct lys_module *cur_mod, int bis)
{
+ LY_ERR ret;
LY_ARRAY_COUNT_TYPE i;
- struct lyd_node *node, *cont;
+ struct lyd_node *cont;
struct lysp_submodule *submod;
- int ret;
+ int r;
char *str;
LY_ARRAY_FOR(cur_mod->parsed->includes, i) {
submod = cur_mod->parsed->includes[i].submodule;
if (bis) {
- cont = lyd_new_list(parent, NULL, "submodule", submod->name);
- LY_CHECK_RET(!cont, LY_EOTHER);
+ LY_CHECK_RET(lyd_new_list(parent, NULL, "submodule", &cont, submod->name));
if (submod->revs) {
- node = lyd_new_term(cont, NULL, "revision", submod->revs[0].date);
- LY_CHECK_RET(!node, LY_EOTHER);
+ LY_CHECK_RET(lyd_new_term(cont, NULL, "revision", submod->revs[0].date, NULL));
}
} else {
- cont = lyd_new_list(parent, NULL, "submodule", submod->name, (submod->revs ? submod->revs[0].date : ""));
- LY_CHECK_RET(!cont, LY_EOTHER);
+ LY_CHECK_RET(lyd_new_list(parent, NULL, "submodule", &cont, submod->name,
+ (submod->revs ? submod->revs[0].date : "")));
}
if (submod->filepath) {
- ret = asprintf(&str, "file://%s", submod->filepath);
- LY_CHECK_ERR_RET(ret == -1, LOGMEM(cur_mod->ctx), LY_EMEM);
+ r = asprintf(&str, "file://%s", submod->filepath);
+ LY_CHECK_ERR_RET(r == -1, LOGMEM(cur_mod->ctx), LY_EMEM);
- node = lyd_new_term(cont, NULL, bis ? "location" : "schema", str);
- LY_CHECK_RET(!node, LY_EOTHER);
+ ret = lyd_new_term(cont, NULL, bis ? "location" : "schema", str, NULL);
free(str);
+ LY_CHECK_RET(ret);
}
}
@@ -641,19 +635,20 @@
return ctx->module_set_id;
}
-API struct lyd_node *
-ly_ctx_get_yanglib_data(const struct ly_ctx *ctx)
+API LY_ERR
+ly_ctx_get_yanglib_data(const struct ly_ctx *ctx, struct lyd_node **root_p)
{
+ LY_ERR ret;
uint32_t i;
- int bis = 0, ret;
+ int bis = 0, r;
char id[8], *str;
const struct lys_module *mod;
- struct lyd_node *root = NULL, *root_bis = NULL, *cont, *set_bis = NULL, *node;
+ struct lyd_node *root = NULL, *root_bis = NULL, *cont, *set_bis = NULL;
- LY_CHECK_ARG_RET(ctx, ctx, NULL);
+ LY_CHECK_ARG_RET(ctx, ctx, root_p, LY_EINVAL);
mod = ly_ctx_get_module_implemented(ctx, "ietf-yang-library");
- LY_CHECK_ERR_RET(!mod, LOGERR(ctx, LY_EINVAL, "Module \"ietf-yang-library\" is not implemented."), NULL);
+ LY_CHECK_ERR_RET(!mod, LOGERR(ctx, LY_EINVAL, "Module \"ietf-yang-library\" is not implemented."), LY_EINVAL);
if (mod->parsed->revs && !strcmp(mod->parsed->revs[0].date, "2016-06-21")) {
bis = 0;
@@ -661,18 +656,14 @@
bis = 1;
} else {
LOGERR(ctx, LY_EINVAL, "Incompatible ietf-yang-library version in context.");
- return NULL;
+ return LY_EINVAL;
}
- root = lyd_new_inner(NULL, mod, "modules-state");
- LY_CHECK_GOTO(!root, error);
+ LY_CHECK_GOTO(ret = lyd_new_inner(NULL, mod, "modules-state", &root), error);
if (bis) {
- root_bis = lyd_new_inner(NULL, mod, "yang-library");
- LY_CHECK_GOTO(!root_bis, error);
-
- set_bis = lyd_new_list(root_bis, NULL, "module-set", "complete");
- LY_CHECK_GOTO(!set_bis, error);
+ LY_CHECK_GOTO(ret = lyd_new_inner(NULL, mod, "yang-library", &root_bis), error);
+ LY_CHECK_GOTO(ret = lyd_new_list(root_bis, NULL, "module-set", &set_bis, "complete"), error);
}
for (i = 0; i < ctx->list.count; ++i) {
@@ -681,35 +672,34 @@
/*
* deprecated legacy
*/
- cont = lyd_new_list(root, NULL, "module", mod->name, (mod->parsed->revs ? mod->parsed->revs[0].date : ""));
- LY_CHECK_GOTO(!cont, error);
+ LY_CHECK_GOTO(ret = lyd_new_list(root, NULL, "module", &cont, mod->name,
+ (mod->parsed->revs ? mod->parsed->revs[0].date : "")), error);
/* schema */
if (mod->filepath) {
- ret = asprintf(&str, "file://%s", mod->filepath);
- LY_CHECK_ERR_GOTO(ret == -1, LOGMEM(ctx), error);
+ r = asprintf(&str, "file://%s", mod->filepath);
+ LY_CHECK_ERR_GOTO(r == -1, LOGMEM(ctx); ret = LY_EMEM, error);
- node = lyd_new_term(cont, NULL, "schema", str);
+ ret = lyd_new_term(cont, NULL, "schema", str, NULL);
free(str);
- LY_CHECK_GOTO(!node, error);
+ LY_CHECK_GOTO(ret, error);
}
/* namespace */
- node = lyd_new_term(cont, NULL, "namespace", mod->ns);
- LY_CHECK_GOTO(!node, error);
+ LY_CHECK_GOTO(ret = lyd_new_term(cont, NULL, "namespace", mod->ns, NULL), error);
/* feature leaf-list */
- LY_CHECK_GOTO(ylib_feature(cont, mod), error);
+ LY_CHECK_GOTO(ret = ylib_feature(cont, mod), error);
/* deviation list */
- LY_CHECK_GOTO(ylib_deviation(cont, mod, 0), error);
+ LY_CHECK_GOTO(ret = ylib_deviation(cont, mod, 0), error);
/* conformance-type */
- node = lyd_new_term(cont, NULL, "conformance-type", (mod->implemented ? "implement" : "import"));
- LY_CHECK_GOTO(!node, error);
+ LY_CHECK_GOTO(ret = lyd_new_term(cont, NULL, "conformance-type", mod->implemented ? "implement" : "import",
+ NULL), error);
/* submodule list */
- LY_CHECK_GOTO(ylib_submodules(cont, mod, 0), error);
+ LY_CHECK_GOTO(ret = ylib_submodules(cont, mod, 0), error);
/*
* current revision
@@ -717,60 +707,52 @@
if (bis) {
/* name and revision */
if (mod->implemented) {
- cont = lyd_new_list(set_bis, NULL, "module", mod->name);
- LY_CHECK_GOTO(!cont, error);
+ LY_CHECK_GOTO(ret = lyd_new_list(set_bis, NULL, "module", &cont, mod->name), error);
if (mod->parsed->revs) {
- node = lyd_new_term(cont, NULL, "revision", mod->parsed->revs[0].date);
- LY_CHECK_GOTO(!node, error);
+ LY_CHECK_GOTO(ret = lyd_new_term(cont, NULL, "revision", mod->parsed->revs[0].date, NULL), error);
}
} else {
- cont = lyd_new_list(set_bis, NULL, "import-only-module", mod->name,
- (mod->parsed->revs ? mod->parsed->revs[0].date : ""));
- LY_CHECK_GOTO(!cont, error);
+ LY_CHECK_GOTO(ret = lyd_new_list(set_bis, NULL, "import-only-module", &cont, mod->name,
+ (mod->parsed->revs ? mod->parsed->revs[0].date : "")), error);
}
/* namespace */
- node = lyd_new_term(cont, NULL, "namespace", mod->ns);
- LY_CHECK_GOTO(!node, error);
+ LY_CHECK_GOTO(ret = lyd_new_term(cont, NULL, "namespace", mod->ns, NULL), error);
/* location */
if (mod->filepath) {
- ret = asprintf(&str, "file://%s", mod->filepath);
- LY_CHECK_ERR_GOTO(ret == -1, LOGMEM(ctx), error);
+ r = asprintf(&str, "file://%s", mod->filepath);
+ LY_CHECK_ERR_GOTO(r == -1, LOGMEM(ctx); ret = LY_EMEM, error);
- node = lyd_new_term(cont, NULL, "schema", str);
+ ret = lyd_new_term(cont, NULL, "schema", str, NULL);
free(str);
- LY_CHECK_GOTO(!node, error);
+ LY_CHECK_GOTO(ret, error);
}
/* submodule list */
- LY_CHECK_GOTO(ylib_submodules(cont, mod, 1), error);
+ LY_CHECK_GOTO(ret = ylib_submodules(cont, mod, 1), error);
/* feature list */
- LY_CHECK_GOTO(ylib_feature(cont, mod), error);
+ LY_CHECK_GOTO(ret = ylib_feature(cont, mod), error);
/* deviation */
- LY_CHECK_GOTO(ylib_deviation(cont, mod, 1), error);
+ LY_CHECK_GOTO(ret = ylib_deviation(cont, mod, 1), error);
}
}
/* IDs */
sprintf(id, "%u", ctx->module_set_id);
- node = lyd_new_term(root, NULL, "module-set-id", id);
- LY_CHECK_GOTO(!node, error);
+ LY_CHECK_GOTO(ret = lyd_new_term(root, NULL, "module-set-id", id, NULL), error);
if (bis) {
/* create one complete schema */
- cont = lyd_new_list(root_bis, NULL, "schema", "complete");
- LY_CHECK_GOTO(!cont, error);
+ LY_CHECK_GOTO(ret = lyd_new_list(root_bis, NULL, "schema", &cont, "complete"), error);
- node = lyd_new_term(cont, NULL, "module-set", "complete");
- LY_CHECK_GOTO(!node, error);
+ LY_CHECK_GOTO(ret = lyd_new_term(cont, NULL, "module-set", "complete", NULL), error);
/* content-id */
- node = lyd_new_term(root_bis, NULL, "content-id", id);
- LY_CHECK_GOTO(!node, error);
+ LY_CHECK_GOTO(ret = lyd_new_term(root_bis, NULL, "content-id", id, NULL), error);
}
if (root_bis) {
@@ -781,16 +763,15 @@
root_bis = 0;
}
- if (lyd_validate(&root, NULL, LYD_VALIDATE_PRESENT, NULL)) {
- goto error;
- }
+ LY_CHECK_GOTO(ret = lyd_validate_all(&root, NULL, LYD_VALIDATE_PRESENT, NULL), error);
- return root;
+ *root_p = root;
+ return LY_SUCCESS;
error:
lyd_free_all(root);
lyd_free_all(root_bis);
- return NULL;
+ return ret;
}
API void
diff --git a/src/context.h b/src/context.h
index 9dc3f57..cdd5ced 100644
--- a/src/context.h
+++ b/src/context.h
@@ -24,6 +24,7 @@
extern "C" {
#endif
+struct lyd_node;
struct lysc_node;
/**
@@ -446,10 +447,10 @@
* ietf-yang-library module must be loaded.
*
* @param[in] ctx Context with the modules.
- * @return Generated data, must be freed,
- * @return NULL on error.
+ * @param[out] root Generated yang-library data.
+ * @return LY_ERR value
*/
-struct lyd_node *ly_ctx_get_yanglib_data(const struct ly_ctx *ctx);
+LY_ERR ly_ctx_get_yanglib_data(const struct ly_ctx *ctx, struct lyd_node **root);
/**
* @brief Free all internal structures of the specified context.
diff --git a/src/diff.c b/src/diff.c
index e69f52a..cef0713 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -102,8 +102,8 @@
}
/* duplicate the subtree (and connect to the diff if possible) */
- dup = lyd_dup(node, (struct lyd_node_inner *)diff_parent, LYD_DUP_RECURSIVE | LYD_DUP_NO_META | LYD_DUP_WITH_PARENTS);
- LY_CHECK_RET(!dup, LY_EMEM);
+ LY_CHECK_RET(lyd_dup_single(node, (struct lyd_node_inner *)diff_parent,
+ LYD_DUP_RECURSIVE | LYD_DUP_NO_META | LYD_DUP_WITH_PARENTS, &dup));
/* find the first duplicated parent */
if (!diff_parent) {
@@ -139,38 +139,36 @@
assert(!strcmp(yang_mod->name, "yang"));
/* add parent operation, if any */
- if (diff_parent && (diff_parent != dup) && !lyd_new_meta(diff_parent, yang_mod, "operation", "none")) {
- return LY_EMEM;
+ if (diff_parent && (diff_parent != dup)) {
+ LY_CHECK_RET(lyd_new_meta(diff_parent, yang_mod, "operation", "none", NULL));
}
/* add subtree operation */
- if (!lyd_new_meta(dup, yang_mod, "operation", lyd_diff_op2str(op))) {
- return LY_EMEM;
- }
+ LY_CHECK_RET(lyd_new_meta(dup, yang_mod, "operation", lyd_diff_op2str(op), NULL));
/* orig-default */
- if (orig_default && !lyd_new_meta(dup, yang_mod, "orig-default", orig_default)) {
- return LY_EMEM;
+ if (orig_default) {
+ LY_CHECK_RET(lyd_new_meta(dup, yang_mod, "orig-default", orig_default, NULL));
}
/* orig-value */
- if (orig_value && !lyd_new_meta(dup, yang_mod, "orig-value", orig_value)) {
- return LY_EMEM;
+ if (orig_value) {
+ LY_CHECK_RET(lyd_new_meta(dup, yang_mod, "orig-value", orig_value, NULL));
}
/* key */
- if (key && !lyd_new_meta(dup, yang_mod, "key", key)) {
- return LY_EMEM;
+ if (key) {
+ LY_CHECK_RET(lyd_new_meta(dup, yang_mod, "key", key, NULL));
}
/* value */
- if (value && !lyd_new_meta(dup, yang_mod, "value", value)) {
- return LY_EMEM;
+ if (value) {
+ LY_CHECK_RET(lyd_new_meta(dup, yang_mod, "value", value, NULL));
}
/* orig-key */
- if (orig_key && !lyd_new_meta(dup, yang_mod, "orig-key", orig_key)) {
- return LY_EMEM;
+ if (orig_key) {
+ LY_CHECK_RET(lyd_new_meta(dup, yang_mod, "orig-key", orig_key, NULL));
}
return LY_SUCCESS;
@@ -290,7 +288,7 @@
if (lyd_compare(second, userord_item->inst[second_pos], 0)) {
/* in first, there is a different instance on the second position, we are going to move 'first' node */
*op = LYD_DIFF_OP_REPLACE;
- } else if ((options & LYD_DIFF_WITHDEFAULTS) && ((first->flags & LYD_DEFAULT) != (second->flags & LYD_DEFAULT))) {
+ } else if ((options & LYD_DIFF_DEFAULTS) && ((first->flags & LYD_DEFAULT) != (second->flags & LYD_DEFAULT))) {
/* default flag change */
*op = LYD_DIFF_OP_NONE;
} else {
@@ -304,7 +302,7 @@
*/
/* orig-default */
- if ((options & LYD_DIFF_WITHDEFAULTS) && (schema->nodetype == LYS_LEAFLIST)
+ if ((options & LYD_DIFF_DEFAULTS) && (schema->nodetype == LYS_LEAFLIST)
&& ((*op == LYD_DIFF_OP_REPLACE) || (*op == LYD_DIFF_OP_NONE))
&& ((first->flags & LYD_DEFAULT) != (second->flags & LYD_DEFAULT))) {
if (first->flags & LYD_DEFAULT) {
@@ -440,7 +438,7 @@
return LY_ENOT;
case LYS_LIST:
case LYS_LEAFLIST:
- if ((options & LYD_DIFF_WITHDEFAULTS) && ((first->flags & LYD_DEFAULT) != (second->flags & LYD_DEFAULT))) {
+ if ((options & LYD_DIFF_DEFAULTS) && ((first->flags & LYD_DEFAULT) != (second->flags & LYD_DEFAULT))) {
/* default flag change */
*op = LYD_DIFF_OP_NONE;
} else {
@@ -454,7 +452,7 @@
if (lyd_compare(first, second, 0)) {
/* different values */
*op = LYD_DIFF_OP_REPLACE;
- } else if ((options & LYD_DIFF_WITHDEFAULTS) && ((first->flags & LYD_DEFAULT) != (second->flags & LYD_DEFAULT))) {
+ } else if ((options & LYD_DIFF_DEFAULTS) && ((first->flags & LYD_DEFAULT) != (second->flags & LYD_DEFAULT))) {
/* default flag change */
*op = LYD_DIFF_OP_NONE;
} else {
@@ -472,7 +470,7 @@
*/
/* orig-default */
- if ((options & LYD_DIFF_WITHDEFAULTS) && (schema->nodetype & LYD_NODE_TERM)
+ if ((options & LYD_DIFF_DEFAULTS) && (schema->nodetype & LYD_NODE_TERM)
&& ((*op == LYD_DIFF_OP_REPLACE) || (*op == LYD_DIFF_OP_NONE))
&& ((first->flags & LYD_DEFAULT) != (second->flags & LYD_DEFAULT))) {
if (first->flags & LYD_DEFAULT) {
@@ -532,32 +530,27 @@
* @param[in] first First tree first sibling.
* @param[in] second Second tree first sibling.
* @param[in] options Diff options.
+ * @param[in] nosiblings Whether to skip following siblings.
* @param[in,out] diff Diff to append to.
* @return LY_ERR value.
*/
static LY_ERR
-lyd_diff_siblings_r(const struct lyd_node *first, const struct lyd_node *second, int options, struct lyd_node **diff)
+lyd_diff_siblings_r(const struct lyd_node *first, const struct lyd_node *second, int options, int nosiblings,
+ struct lyd_node **diff)
{
LY_ERR ret = LY_SUCCESS;
const struct lyd_node *iter_first, *iter_second;
struct lyd_node *match_second, *match_first;
- int nosiblings = 0;
struct lyd_diff_userord *userord = NULL;
LY_ARRAY_COUNT_TYPE u;
enum lyd_diff_op op;
const char *orig_default;
char *orig_value, *key, *value, *orig_key;
- if (options & LYD_DIFF_NOSIBLINGS) {
- /* remember it for this function call only, should not be passed recursively */
- nosiblings = 1;
- options &= ~LYD_DIFF_NOSIBLINGS;
- }
-
/* compare first tree to the second tree - delete, replace, none */
LY_LIST_FOR(first, iter_first) {
assert(!(iter_first->schema->flags & LYS_KEY));
- if ((iter_first->flags & LYD_DEFAULT) && !(options & LYD_DIFF_WITHDEFAULTS)) {
+ if ((iter_first->flags & LYD_DEFAULT) && !(options & LYD_DIFF_DEFAULTS)) {
/* skip default nodes */
continue;
}
@@ -570,7 +563,7 @@
lyd_find_sibling_val(second, iter_first->schema, NULL, 0, &match_second);
}
- if (match_second && (match_second->flags & LYD_DEFAULT) && !(options & LYD_DIFF_WITHDEFAULTS)) {
+ if (match_second && (match_second->flags & LYD_DEFAULT) && !(options & LYD_DIFF_DEFAULTS)) {
/* ignore default nodes */
match_second = NULL;
}
@@ -617,7 +610,7 @@
/* check descendants, if any, recursively */
if (match_second) {
- LY_CHECK_GOTO(lyd_diff_siblings_r(LYD_CHILD(iter_first), LYD_CHILD(match_second), options, diff), cleanup);
+ LY_CHECK_GOTO(lyd_diff_siblings_r(LYD_CHILD(iter_first), LYD_CHILD(match_second), options, 0, diff), cleanup);
}
if (nosiblings) {
@@ -633,7 +626,7 @@
/* compare second tree to the first tree - create, user-ordered move */
LY_LIST_FOR(second, iter_second) {
assert(!(iter_second->schema->flags & LYS_KEY));
- if ((iter_second->flags & LYD_DEFAULT) && !(options & LYD_DIFF_WITHDEFAULTS)) {
+ if ((iter_second->flags & LYD_DEFAULT) && !(options & LYD_DIFF_DEFAULTS)) {
/* skip default nodes */
continue;
}
@@ -644,7 +637,7 @@
lyd_find_sibling_val(first, iter_second->schema, NULL, 0, &match_first);
}
- if (match_first && (match_first->flags & LYD_DEFAULT) && !(options & LYD_DIFF_WITHDEFAULTS)) {
+ if (match_first && (match_first->flags & LYD_DEFAULT) && !(options & LYD_DIFF_DEFAULTS)) {
/* ignore default nodes */
match_first = NULL;
}
@@ -693,8 +686,8 @@
return ret;
}
-API LY_ERR
-lyd_diff(const struct lyd_node *first, const struct lyd_node *second, int options, struct lyd_node **diff)
+static LY_ERR
+lyd_diff(const struct lyd_node *first, const struct lyd_node *second, int options, int nosiblings, struct lyd_node **diff)
{
const struct ly_ctx *ctx;
@@ -715,7 +708,19 @@
*diff = NULL;
- return lyd_diff_siblings_r(first, second, options, diff);
+ return lyd_diff_siblings_r(first, second, options, nosiblings, diff);
+}
+
+API LY_ERR
+lyd_diff_tree(const struct lyd_node *first, const struct lyd_node *second, int options, struct lyd_node **diff)
+{
+ return lyd_diff(first, second, options, 1, diff);
+}
+
+API LY_ERR
+lyd_diff_siblings(const struct lyd_node *first, const struct lyd_node *second, int options, struct lyd_node **diff)
+{
+ return lyd_diff(first, second, options, 0, diff);
}
/**
@@ -886,9 +891,8 @@
/* find the node (we must have some siblings because the node was only moved) */
lyd_diff_find_node(*first_node, diff_node, &match);
} else {
- /* duplicate the node(s) */
- match = lyd_dup(diff_node, NULL, LYD_DUP_NO_META);
- LY_CHECK_RET(!match, LY_EMEM);
+ /* duplicate the node */
+ LY_CHECK_RET(lyd_dup_single(diff_node, NULL, LYD_DUP_NO_META, &match));
}
/* get "key" or "value" metadata string value */
@@ -937,8 +941,7 @@
break;
case LYD_DIFF_OP_CREATE:
/* duplicate the node */
- match = lyd_dup(diff_node, NULL, LYD_DUP_NO_META);
- LY_CHECK_RET(!match, LY_EMEM);
+ LY_CHECK_RET(lyd_dup_single(diff_node, NULL, LYD_DUP_NO_META, &match));
/* insert it at the end */
ret = 0;
@@ -1026,7 +1029,7 @@
}
API LY_ERR
-lyd_diff_apply(struct lyd_node **data, const struct lyd_node *diff)
+lyd_diff_apply_all(struct lyd_node **data, const struct lyd_node *diff)
{
return lyd_diff_apply_module(data, diff, NULL, NULL, NULL);
}
@@ -1073,7 +1076,7 @@
LY_LIST_FOR(node->meta, meta) {
if (!strcmp(meta->name, name) && !strcmp(meta->annotation->module->name, "yang")) {
- lyd_free_meta(LYD_NODE_CTX(node), meta, 0);
+ lyd_free_meta_single(meta);
return;
}
}
@@ -1095,15 +1098,12 @@
LY_LIST_FOR(node->meta, meta) {
if (!strcmp(meta->name, "operation") && !strcmp(meta->annotation->module->name, "yang")) {
- lyd_free_meta(LYD_NODE_CTX(node), meta, 0);
+ lyd_free_meta_single(meta);
break;
}
}
- if (!lyd_new_meta(node, NULL, "yang:operation", lyd_diff_op2str(op))) {
- return LY_EINT;
- }
- return LY_SUCCESS;
+ return lyd_new_meta(node, NULL, "yang:operation", lyd_diff_op2str(op), NULL);
}
/**
@@ -1142,9 +1142,7 @@
lyd_diff_del_meta(diff_match, meta_name);
meta = lyd_find_meta(src_diff->meta, mod, meta_name);
LY_CHECK_ERR_RET(!meta, LOGINT(LYD_NODE_CTX(src_diff)), LY_EINT);
- if (!lyd_dup_meta(meta, diff_match)) {
- return LY_EINT;
- }
+ LY_CHECK_RET(lyd_dup_meta_single(meta, diff_match, NULL));
break;
case LYS_LEAF:
/* replaced with the exact same value, impossible */
@@ -1175,7 +1173,7 @@
}
if (!ret) {
/* values are the same, remove orig-value meta and set oper to NONE */
- lyd_free_meta(LYD_NODE_CTX(diff_match), meta, 0);
+ lyd_free_meta_single(meta);
LY_CHECK_RET(lyd_diff_change_op(diff_match, LYD_DIFF_OP_NONE));
}
@@ -1208,15 +1206,11 @@
/* set orig-key and key metadata */
meta = lyd_find_meta(src_diff->meta, mod, "orig-key");
LY_CHECK_ERR_RET(!meta, LOGINT(LYD_NODE_CTX(src_diff)), LY_EINT);
- if (!lyd_dup_meta(meta, diff_match)) {
- return LY_EINT;
- }
+ LY_CHECK_RET(lyd_dup_meta_single(meta, diff_match, NULL));
meta = lyd_find_meta(src_diff->meta, mod, "key");
LY_CHECK_ERR_RET(!meta, LOGINT(LYD_NODE_CTX(src_diff)), LY_EINT);
- if (!lyd_dup_meta(meta, diff_match)) {
- return LY_EINT;
- }
+ LY_CHECK_RET(lyd_dup_meta_single(meta, diff_match, NULL));
break;
default:
/* delete operation is not valid */
@@ -1238,7 +1232,6 @@
lyd_diff_merge_create(struct lyd_node *diff_match, enum lyd_diff_op cur_op, const struct lyd_node *src_diff)
{
struct lyd_node *child;
- struct lyd_meta *meta;
const char *str_val;
int dynamic;
LY_ERR ret;
@@ -1252,9 +1245,8 @@
if (diff_match->schema->nodetype & LYD_NODE_TERM) {
/* add orig-dflt metadata */
- if (!lyd_new_meta(diff_match, NULL, "yang:orig-default", diff_match->flags & LYD_DEFAULT ? "true" : "false")) {
- return LY_EINT;
- }
+ LY_CHECK_RET(lyd_new_meta(diff_match, NULL, "yang:orig-default",
+ diff_match->flags & LYD_DEFAULT ? "true" : "false", NULL));
}
} else {
assert(diff_match->schema->nodetype == LYS_LEAF);
@@ -1263,11 +1255,11 @@
/* current value is the previous one (meta) */
str_val = lyd_value2str((struct lyd_node_term *)diff_match, &dynamic);
- meta = lyd_new_meta(diff_match, NULL, "yang:orig-value", str_val);
+ ret = lyd_new_meta(diff_match, NULL, "yang:orig-value", str_val, NULL);
if (dynamic) {
free((char *)str_val);
}
- LY_CHECK_RET(!meta, LY_EINT);
+ LY_CHECK_RET(ret);
/* update the value itself */
str_val = lyd_value2str((struct lyd_node_term *)src_diff, &dynamic);
@@ -1320,9 +1312,8 @@
if (diff_match->schema->nodetype & LYD_NODE_TERM) {
/* add orig-default meta because it is expected */
- if (!lyd_new_meta(diff_match, NULL, "yang:orig-default", diff_match->flags & LYD_DEFAULT ? "true" : "false")) {
- return LY_EINT;
- }
+ LY_CHECK_RET(lyd_new_meta(diff_match, NULL, "yang:orig-default",
+ diff_match->flags & LYD_DEFAULT ? "true" : "false", NULL));
} else {
/* keep operation for all descendants (for now) */
LY_LIST_FOR(LYD_CHILD(diff_match), child) {
@@ -1384,8 +1375,8 @@
if (!lyd_compare_meta(orig_val_meta, val_meta)) {
/* there is actually no move */
- lyd_free_meta(LYD_NODE_CTX(diff), orig_val_meta, 0);
- lyd_free_meta(LYD_NODE_CTX(diff), val_meta, 0);
+ lyd_free_meta_single(orig_val_meta);
+ lyd_free_meta_single(val_meta);
if (child) {
/* change operation to NONE, we have siblings */
lyd_diff_change_op(diff, LYD_DIFF_OP_NONE);
@@ -1486,8 +1477,7 @@
}
} else {
/* add new diff node with all descendants */
- diff_node = lyd_dup(src_diff, (struct lyd_node_inner *)diff_parent, LYD_DUP_RECURSIVE);
- LY_CHECK_RET(!diff_node, LY_EINT);
+ LY_CHECK_RET(lyd_dup_single(src_diff, (struct lyd_node_inner *)diff_parent, LYD_DUP_RECURSIVE, &diff_node));
/* insert node into diff if not already */
if (!diff_parent) {
@@ -1541,7 +1531,7 @@
}
API LY_ERR
-lyd_diff_merge(const struct lyd_node *src_diff, struct lyd_node **diff)
+lyd_diff_merge_all(const struct lyd_node *src_diff, struct lyd_node **diff)
{
return lyd_diff_merge_module(src_diff, NULL, NULL, NULL, diff);
}
@@ -1662,8 +1652,7 @@
}
/* duplicate diff */
- *diff = lyd_dup(src_diff, NULL, LYD_DUP_WITH_SIBLINGS | LYD_DUP_RECURSIVE);
- LY_CHECK_RET(!*diff, LY_EMEM);
+ LY_CHECK_RET(lyd_dup_siblings(src_diff, NULL, LYD_DUP_RECURSIVE, diff));
/* find module with metadata needed for later */
mod = ly_ctx_get_module_latest(LYD_NODE_CTX(src_diff), "yang");
diff --git a/src/parser_data.h b/src/parser_data.h
index 7bf68b2..a8ec4d5 100644
--- a/src/parser_data.h
+++ b/src/parser_data.h
@@ -131,7 +131,8 @@
* @return LY_SUCCESS in case of successful parsing (and validation).
* @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions.
*/
-LY_ERR lyd_parse_data(const struct ly_ctx *ctx, struct ly_in *in, LYD_FORMAT format, int parse_options, int validate_options, struct lyd_node **tree);
+LY_ERR lyd_parse_data(const struct ly_ctx *ctx, struct ly_in *in, LYD_FORMAT format, int parse_options,
+ int validate_options, struct lyd_node **tree);
/**
* @brief Parse (and validate) input data as a YANG data tree.
@@ -148,7 +149,8 @@
* @return LY_SUCCESS in case of successful parsing (and validation).
* @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions.
*/
-LY_ERR lyd_parse_data_mem(const struct ly_ctx *ctx, const char *data, LYD_FORMAT format, int parse_options, int validate_options, struct lyd_node **tree);
+LY_ERR lyd_parse_data_mem(const struct ly_ctx *ctx, const char *data, LYD_FORMAT format, int parse_options,
+ int validate_options, struct lyd_node **tree);
/**
* @brief Parse (and validate) input data as a YANG data tree.
@@ -165,7 +167,8 @@
* @return LY_SUCCESS in case of successful parsing (and validation).
* @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions.
*/
-LY_ERR lyd_parse_data_fd(const struct ly_ctx *ctx, int fd, LYD_FORMAT format, int parse_options, int validate_options, struct lyd_node **tree);
+LY_ERR lyd_parse_data_fd(const struct ly_ctx *ctx, int fd, LYD_FORMAT format, int parse_options, int validate_options,
+ struct lyd_node **tree);
/**
* @brief Parse (and validate) input data as a YANG data tree.
@@ -182,7 +185,8 @@
* @return LY_SUCCESS in case of successful parsing (and validation).
* @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions.
*/
-LY_ERR lyd_parse_data_path(const struct ly_ctx *ctx, const char *path, LYD_FORMAT format, int parse_options, int validate_options, struct lyd_node **tree);
+LY_ERR lyd_parse_data_path(const struct ly_ctx *ctx, const char *path, LYD_FORMAT format, int parse_options,
+ int validate_options, struct lyd_node **tree);
/**
* @brief Parse (and validate) data from the input handler as a YANG RPC/action invocation.
@@ -201,7 +205,8 @@
* @return LY_SUCCESS in case of successful parsing (and validation).
* @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions.
*/
-LY_ERR lyd_parse_rpc(const struct ly_ctx *ctx, struct ly_in *in, LYD_FORMAT format, struct lyd_node **tree, struct lyd_node **op);
+LY_ERR lyd_parse_rpc(const struct ly_ctx *ctx, struct ly_in *in, LYD_FORMAT format, struct lyd_node **tree,
+ struct lyd_node **op);
/**
* @brief Parse (and validate) data from the input handler as a YANG RPC/action reply.
@@ -221,7 +226,8 @@
* @return LY_SUCCESS in case of successful parsing (and validation).
* @return LY_ERR value in case of error. Additional error information can be obtained from the request's context using ly_err* functions.
*/
-LY_ERR lyd_parse_reply(const struct lyd_node *request, struct ly_in *in, LYD_FORMAT format, struct lyd_node **tree, struct lyd_node **op);
+LY_ERR lyd_parse_reply(const struct lyd_node *request, struct ly_in *in, LYD_FORMAT format, struct lyd_node **tree,
+ struct lyd_node **op);
/**
* @brief Parse XML string as YANG notification.
@@ -238,7 +244,8 @@
* @return LY_SUCCESS in case of successful parsing (and validation).
* @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions.
*/
-LY_ERR lyd_parse_notif(const struct ly_ctx *ctx, struct ly_in *in, LYD_FORMAT format, struct lyd_node **tree, struct lyd_node **ntf);
+LY_ERR lyd_parse_notif(const struct ly_ctx *ctx, struct ly_in *in, LYD_FORMAT format, struct lyd_node **tree,
+ struct lyd_node **ntf);
/**
* @brief Fully validate a data tree.
@@ -250,7 +257,7 @@
* @return LY_SUCCESS on success.
* @return LY_ERR error on error.
*/
-LY_ERR lyd_validate(struct lyd_node **tree, const struct ly_ctx *ctx, int val_opts, struct lyd_node **diff);
+LY_ERR lyd_validate_all(struct lyd_node **tree, const struct ly_ctx *ctx, int val_opts, struct lyd_node **diff);
/**
* @brief Fully validate a data tree of a module.
diff --git a/src/parser_lyb.c b/src/parser_lyb.c
index 1965afb..95ff05a 100644
--- a/src/parser_lyb.c
+++ b/src/parser_lyb.c
@@ -379,7 +379,7 @@
cleanup:
free(meta_name);
if (ret) {
- lyd_free_meta(lybctx->ctx, *meta, 1);
+ lyd_free_meta_siblings(*meta);
*meta = NULL;
}
return ret;
@@ -518,7 +518,7 @@
}
ly_free_val_prefs(lybctx->ctx, val_prefs);
if (ret) {
- ly_free_attr(lybctx->ctx, *attr, 1);
+ ly_free_attr_siblings(lybctx->ctx, *attr);
*attr = NULL;
}
return ret;
@@ -910,8 +910,8 @@
}
ly_free_val_prefs(lybctx->ctx, val_prefs);
- lyd_free_meta(lybctx->ctx, meta, 1);
- ly_free_attr(lybctx->ctx, attr, 1);
+ lyd_free_meta_siblings(meta);
+ ly_free_attr_siblings(lybctx->ctx, attr);
lyd_free_tree(node);
return ret;
}
@@ -1208,8 +1208,8 @@
}
/* duplicate request OP with parents */
- rep_op = lyd_dup(req_op, NULL, LYD_DUP_WITH_PARENTS);
- LY_CHECK_ERR_GOTO(!rep_op, ret = LY_EMEM, cleanup);
+ ret = lyd_dup_single(req_op, NULL, LYD_DUP_WITH_PARENTS, &rep_op);
+ LY_CHECK_GOTO(ret, cleanup);
/* read magic number */
ret = lyb_parse_magic_number(&lybctx);
diff --git a/src/parser_schema.h b/src/parser_schema.h
index 82bdd9b..9e3985a 100644
--- a/src/parser_schema.h
+++ b/src/parser_schema.h
@@ -20,6 +20,7 @@
#endif
struct ly_in;
+struct lys_module;
/**
* @addtogroup schematree
@@ -41,9 +42,10 @@
* @param[in] ctx libyang context where to process the data model.
* @param[in] in The input handle to provide the dumped data model in the specified format.
* @param[in] format Format of the schema to parse.
- * @return Pointer to the data model structure or NULL on error.
+ * @param[out] module Optional parsed module.
+ * @return LY_ERR value.
*/
-struct lys_module *lys_parse(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format);
+LY_ERR lys_parse(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, const struct lys_module **module);
/**
* @brief Load a schema into the specified context.
@@ -52,12 +54,12 @@
* consider use of lys_parse() with a standalone input handler.
*
* @param[in] ctx libyang context where to process the data model.
- * @param[in] data The string containing the dumped data model in the specified
- * format.
+ * @param[in] data The string containing the dumped data model in the specified format.
* @param[in] format Format of the input data (YANG or YIN).
- * @return Pointer to the data model structure or NULL on error.
+ * @param[out] module Optional parsed module.
+ * @return LY_ERR value.
*/
-struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
+LY_ERR lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format, const struct lys_module **module);
/**
* @brief Read a schema from file descriptor into the specified context.
@@ -71,9 +73,10 @@
* @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
* in the specified format.
* @param[in] format Format of the input data (YANG or YIN).
- * @return Pointer to the data model structure or NULL on error.
+ * @param[out] module Optional parsed module.
+ * @return LY_ERR value.
*/
-struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
+LY_ERR lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format, const struct lys_module **module);
/**
* @brief Load a schema into the specified context from a file.
@@ -84,9 +87,10 @@
* @param[in] ctx libyang context where to process the data model.
* @param[in] path Path to the file with the model in the specified format.
* @param[in] format Format of the input data (YANG or YIN).
- * @return Pointer to the data model structure or NULL on error.
+ * @param[out] module Optional parsed module.
+ * @return LY_ERR value.
*/
-struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
+LY_ERR lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format, const struct lys_module **module);
/**
* @brief Search for the schema file in the specified searchpaths.
@@ -103,7 +107,8 @@
* file suffix.
* @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
*/
-LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format);
+LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision,
+ char **localfile, LYS_INFORMAT *format);
/** @} schematree */
diff --git a/src/parser_xml.c b/src/parser_xml.c
index c382a78..eb73a8f 100644
--- a/src/parser_xml.c
+++ b/src/parser_xml.c
@@ -139,7 +139,7 @@
cleanup:
if (ret) {
- lyd_free_meta(xmlctx->ctx, *meta, 1);
+ lyd_free_meta_siblings(*meta);
*meta = NULL;
}
return ret;
@@ -203,7 +203,7 @@
cleanup:
if (ret) {
- ly_free_attr(xmlctx->ctx, *attr, 1);
+ ly_free_attr_siblings(xmlctx->ctx, *attr);
*attr = NULL;
}
return ret;
@@ -662,8 +662,8 @@
ret = LY_SUCCESS;
cleanup:
- lyd_free_meta(ctx, meta, 1);
- ly_free_attr(ctx, attr, 1);
+ lyd_free_meta_siblings(meta);
+ ly_free_attr_siblings(ctx, attr);
lyd_free_tree(cur);
if (ret && *first) {
lyd_free_siblings(*first);
@@ -799,7 +799,7 @@
attr = NULL;
cleanup:
- ly_free_attr(xmlctx->ctx, attr, 1);
+ ly_free_attr_siblings(xmlctx->ctx, attr);
return ret;
}
@@ -982,7 +982,7 @@
cleanup:
if (ret) {
lyd_free_tree(*envp);
- ly_free_attr(xmlctx->ctx, attr, 1);
+ ly_free_attr_siblings(xmlctx->ctx, attr);
}
return ret;
}
@@ -1080,11 +1080,11 @@
}
/* duplicate request OP with parents */
- rep_op = lyd_dup(req_op, NULL, LYD_DUP_WITH_PARENTS);
- LY_CHECK_ERR_GOTO(!rep_op, ret = LY_EMEM, cleanup);
+ LY_CHECK_GOTO(ret = lyd_dup_single(req_op, NULL, LYD_DUP_WITH_PARENTS, &rep_op), cleanup);
/* parse "rpc-reply", if any */
- LY_CHECK_GOTO(ret = lydxml_envelope(lydctx.xmlctx, "rpc-reply", "urn:ietf:params:xml:ns:netconf:base:1.0", &rpcr_e), cleanup);
+ LY_CHECK_GOTO(ret = lydxml_envelope(lydctx.xmlctx, "rpc-reply", "urn:ietf:params:xml:ns:netconf:base:1.0", &rpcr_e),
+ cleanup);
/* parse the rest of data normally but connect them to the duplicated operation */
LY_CHECK_GOTO(ret = lydxml_data_r(&lydctx, (struct lyd_node_inner *)rep_op, lyd_node_children_p(rep_op)), cleanup);
diff --git a/src/path.c b/src/path.c
index f4829e3..eb72c2f 100644
--- a/src/path.c
+++ b/src/path.c
@@ -424,7 +424,7 @@
key = lys_find_child(ctx_node, mod, name, name_len, 0, LYS_GETNEXT_NOSTATECHECK);
if (!key) {
LOGVAL(ctx, LY_VLOG_NONE, NULL, LYVE_XPATH, "Not found node \"%.*s\" in path.", name_len, name);
- return LY_EVALID;
+ return LY_ENOTFOUND;
} else if ((key->nodetype != LYS_LEAF) || !(key->flags & LYS_KEY)) {
LOGVAL(ctx, LY_VLOG_LYSC, key, LYVE_XPATH, "Key expected instead of %s \"%s\" in path.",
lys_nodetype2str(key->nodetype), key->name);
diff --git a/src/printer_data.c b/src/printer_data.c
index bbb2eda..3d78d3b 100644
--- a/src/printer_data.c
+++ b/src/printer_data.c
@@ -23,15 +23,10 @@
#include "printer_internal.h"
#include "tree_data.h"
-API LY_ERR
-lyd_print(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options)
+static LY_ERR
+lyd_print_(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options)
{
- LY_ERR ret = LY_EINVAL;
-
- LY_CHECK_ARG_RET(NULL, out, root, LY_EINVAL);
-
- /* reset number of printed bytes */
- out->func_printed = 0;
+ LY_ERR ret = LY_SUCCESS;
switch (format) {
case LYD_XML:
@@ -54,22 +49,46 @@
return ret;
}
-static LY_ERR
-lyd_print_(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options)
+API LY_ERR
+lyd_print_all(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options)
{
- LY_ERR ret;
+ LY_CHECK_ARG_RET(NULL, out, root, !(options & LYD_PRINT_WITHSIBLINGS), LY_EINVAL);
- LY_CHECK_ARG_RET(NULL, out, LY_EINVAL);
+ /* reset the number of printed bytes */
+ out->func_printed = 0;
- ret = lyd_print(out, root, format, options);
+ /* get first top-level sibling */
+ while (root->parent) {
+ root = (struct lyd_node *)root->parent;
+ }
+ while (root->prev->next) {
+ root = root->prev;
+ }
- ly_out_free(out, NULL, 0);
- return ret;
+ /* print each top-level sibling */
+ LY_CHECK_RET(lyd_print_(out, root, format, options | LYD_PRINT_WITHSIBLINGS));
+
+ return LY_SUCCESS;
+}
+
+API LY_ERR
+lyd_print_tree(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options)
+{
+ LY_CHECK_ARG_RET(NULL, out, root, !(options & LYD_PRINT_WITHSIBLINGS), LY_EINVAL);
+
+ /* reset the number of printed bytes */
+ out->func_printed = 0;
+
+ /* print the subtree */
+ LY_CHECK_RET(lyd_print_(out, root, format, options));
+
+ return LY_SUCCESS;
}
API LY_ERR
lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, int options)
{
+ LY_ERR ret;
struct ly_out *out;
LY_CHECK_ARG_RET(NULL, strp, root, LY_EINVAL);
@@ -78,50 +97,64 @@
*strp = NULL;
LY_CHECK_RET(ly_out_new_memory(strp, 0, &out));
- return lyd_print_(out, root, format, options);
+ ret = lyd_print_(out, root, format, options);
+ ly_out_free(out, NULL, 0);
+ return ret;
}
API LY_ERR
lyd_print_fd(int fd, const struct lyd_node *root, LYD_FORMAT format, int options)
{
+ LY_ERR ret;
struct ly_out *out;
LY_CHECK_ARG_RET(NULL, fd != -1, root, LY_EINVAL);
LY_CHECK_RET(ly_out_new_fd(fd, &out));
- return lyd_print_(out, root, format, options);
+ ret = lyd_print_(out, root, format, options);
+ ly_out_free(out, NULL, 0);
+ return ret;
}
API LY_ERR
lyd_print_file(FILE *f, const struct lyd_node *root, LYD_FORMAT format, int options)
{
+ LY_ERR ret;
struct ly_out *out;
LY_CHECK_ARG_RET(NULL, f, root, LY_EINVAL);
LY_CHECK_RET(ly_out_new_file(f, &out));
- return lyd_print_(out, root, format, options);
+ ret = lyd_print_(out, root, format, options);
+ ly_out_free(out, NULL, 0);
+ return ret;
}
API LY_ERR
lyd_print_path(const char *path, const struct lyd_node *root, LYD_FORMAT format, int options)
{
+ LY_ERR ret;
struct ly_out *out;
LY_CHECK_ARG_RET(NULL, path, root, LY_EINVAL);
LY_CHECK_RET(ly_out_new_filepath(path, &out));
- return lyd_print_(out, root, format, options);
+ ret = lyd_print_(out, root, format, options);
+ ly_out_free(out, NULL, 0);
+ return ret;
}
API LY_ERR
lyd_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg,
const struct lyd_node *root, LYD_FORMAT format, int options)
{
+ LY_ERR ret;
struct ly_out *out;
LY_CHECK_ARG_RET(NULL, writeclb, root, LY_EINVAL);
LY_CHECK_RET(ly_out_new_clb(writeclb, arg, &out));
- return lyd_print_(out, root, format, options);
+ ret = lyd_print_(out, root, format, options);
+ ly_out_free(out, NULL, 0);
+ return ret;
}
diff --git a/src/printer_data.h b/src/printer_data.h
index afe0418..09fe8f5 100644
--- a/src/printer_data.h
+++ b/src/printer_data.h
@@ -57,15 +57,26 @@
*/
/**
- * @brief Common YANG data printer.
+ * @brief Print the whole data tree of the root, including all the siblings.
*
* @param[in] out Printer handler for a specific output. Use ly_out_*() functions to create and free the handler.
- * @param[in] root The root element of the (sub)tree to print.
+ * @param[in] root The root element of the tree to print, can be any sibling.
* @param[in] format Output format.
- * @param[in] options [Data printer flags](@ref dataprinterflags).
+ * @param[in] options [Data printer flags](@ref dataprinterflags) except ::LYD_PRINT_WITHSIBLINGS.
* @return LY_ERR value.
*/
-LY_ERR lyd_print(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options);
+LY_ERR lyd_print_all(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options);
+
+/**
+ * @brief Print the selected data subtree.
+ *
+ * @param[in] out Printer handler for a specific output. Use ly_out_*() functions to create and free the handler.
+ * @param[in] root The root element of the subtree to print.
+ * @param[in] format Output format.
+ * @param[in] options [Data printer flags](@ref dataprinterflags) except ::LYD_PRINT_WITHSIBLINGS.
+ * @return LY_ERR value.
+ */
+LY_ERR lyd_print_tree(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options);
/**
* @brief Print data tree in the specified format.
diff --git a/src/tree_data.c b/src/tree_data.c
index 3b7e1a3..7780c97 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -657,30 +657,36 @@
return LY_SUCCESS;
}
-API struct lyd_node *
-lyd_new_inner(struct lyd_node *parent, const struct lys_module *module, const char *name)
+API LY_ERR
+lyd_new_inner(struct lyd_node *parent, const struct lys_module *module, const char *name, struct lyd_node **node)
{
struct lyd_node *ret = NULL;
const struct lysc_node *schema;
struct ly_ctx *ctx = parent ? parent->schema->module->ctx : (module ? module->ctx : NULL);
- LY_CHECK_ARG_RET(ctx, parent || module, name, NULL);
+ LY_CHECK_ARG_RET(ctx, parent || module, name, LY_EINVAL);
if (!module) {
module = parent->schema->module;
}
- schema = lys_find_child(parent ? parent->schema : NULL, module, name, 0, LYS_CONTAINER | LYS_NOTIF | LYS_RPC | LYS_ACTION, 0);
- LY_CHECK_ERR_RET(!schema, LOGERR(ctx, LY_EINVAL, "Inner node (and not a list) \"%s\" not found.", name), NULL);
+ schema = lys_find_child(parent ? parent->schema : NULL, module, name, 0,
+ LYS_CONTAINER | LYS_NOTIF | LYS_RPC | LYS_ACTION, 0);
+ LY_CHECK_ERR_RET(!schema, LOGERR(ctx, LY_EINVAL, "Inner node (and not a list) \"%s\" not found.", name), LY_ENOTFOUND);
- if (!lyd_create_inner(schema, &ret) && parent) {
+ LY_CHECK_RET(lyd_create_inner(schema, &ret));
+ if (parent) {
lyd_insert_node(parent, NULL, ret);
}
- return ret;
+
+ if (node) {
+ *node = ret;
+ }
+ return LY_SUCCESS;
}
-API struct lyd_node *
-lyd_new_list(struct lyd_node *parent, const struct lys_module *module, const char *name, ...)
+API LY_ERR
+lyd_new_list(struct lyd_node *parent, const struct lys_module *module, const char *name, struct lyd_node **node, ...)
{
struct lyd_node *ret = NULL, *key;
const struct lysc_node *schema, *key_s;
@@ -689,19 +695,19 @@
const char *key_val;
LY_ERR rc = LY_SUCCESS;
- LY_CHECK_ARG_RET(ctx, parent || module, name, NULL);
+ LY_CHECK_ARG_RET(ctx, parent || module, name, LY_EINVAL);
if (!module) {
module = parent->schema->module;
}
schema = lys_find_child(parent ? parent->schema : NULL, module, name, 0, LYS_LIST, 0);
- LY_CHECK_ERR_RET(!schema, LOGERR(ctx, LY_EINVAL, "List node \"%s\" not found.", name), NULL);
+ LY_CHECK_ERR_RET(!schema, LOGERR(ctx, LY_EINVAL, "List node \"%s\" not found.", name), LY_ENOTFOUND);
/* create list inner node */
- LY_CHECK_RET(lyd_create_inner(schema, &ret), NULL);
+ LY_CHECK_RET(lyd_create_inner(schema, &ret));
- va_start(ap, name);
+ va_start(ap, node);
/* create and insert all the keys */
for (key_s = lysc_node_children(schema, 0); key_s && (key_s->flags & LYS_KEY); key_s = key_s->next) {
@@ -713,30 +719,30 @@
lyd_insert_node(ret, NULL, key);
}
- /* hash having all the keys */
- lyd_hash(ret);
-
if (parent) {
lyd_insert_node(parent, NULL, ret);
}
cleanup:
+ va_end(ap);
if (rc) {
lyd_free_tree(ret);
ret = NULL;
+ } else if (node) {
+ *node = ret;
}
- va_end(ap);
- return ret;
+ return rc;
}
-API struct lyd_node *
-lyd_new_list2(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *keys)
+API LY_ERR
+lyd_new_list2(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *keys,
+ struct lyd_node **node)
{
struct lyd_node *ret = NULL;
const struct lysc_node *schema;
struct ly_ctx *ctx = parent ? parent->schema->module->ctx : (module ? module->ctx : NULL);
- LY_CHECK_ARG_RET(ctx, parent || module, name, NULL);
+ LY_CHECK_ARG_RET(ctx, parent || module, name, LY_EINVAL);
if (!module) {
module = parent->schema->module;
@@ -747,69 +753,81 @@
/* find schema node */
schema = lys_find_child(parent ? parent->schema : NULL, module, name, 0, LYS_LIST, 0);
- LY_CHECK_ERR_RET(!schema, LOGERR(ctx, LY_EINVAL, "List node \"%s\" not found.", name), NULL);
+ LY_CHECK_ERR_RET(!schema, LOGERR(ctx, LY_EINVAL, "List node \"%s\" not found.", name), LY_ENOTFOUND);
if ((schema->flags & LYS_KEYLESS) && !keys[0]) {
/* key-less list */
- LY_CHECK_RET(lyd_create_inner(schema, &ret), NULL);
+ LY_CHECK_RET(lyd_create_inner(schema, &ret));
} else {
/* create the list node */
- LY_CHECK_RET(lyd_create_list2(schema, keys, strlen(keys), &ret), NULL);
+ LY_CHECK_RET(lyd_create_list2(schema, keys, strlen(keys), &ret));
}
-
if (parent) {
lyd_insert_node(parent, NULL, ret);
}
- return ret;
+
+ if (node) {
+ *node = ret;
+ }
+ return LY_SUCCESS;
}
-API struct lyd_node *
-lyd_new_term(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *val_str)
+API LY_ERR
+lyd_new_term(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *val_str,
+ struct lyd_node **node)
{
LY_ERR rc;
struct lyd_node *ret = NULL;
const struct lysc_node *schema;
struct ly_ctx *ctx = parent ? parent->schema->module->ctx : (module ? module->ctx : NULL);
- LY_CHECK_ARG_RET(ctx, parent || module, name, NULL);
+ LY_CHECK_ARG_RET(ctx, parent || module, name, LY_EINVAL);
if (!module) {
module = parent->schema->module;
}
schema = lys_find_child(parent ? parent->schema : NULL, module, name, 0, LYD_NODE_TERM, 0);
- LY_CHECK_ERR_RET(!schema, LOGERR(ctx, LY_EINVAL, "Term node \"%s\" not found.", name), NULL);
+ LY_CHECK_ERR_RET(!schema, LOGERR(ctx, LY_EINVAL, "Term node \"%s\" not found.", name), LY_ENOTFOUND);
rc = lyd_create_term(schema, val_str, val_str ? strlen(val_str) : 0, NULL, lydjson_resolve_prefix, NULL, LYD_JSON, &ret);
- LY_CHECK_RET(rc && (rc != LY_EINCOMPLETE), NULL);
-
+ LY_CHECK_RET(rc && (rc != LY_EINCOMPLETE), rc);
if (parent) {
lyd_insert_node(parent, NULL, ret);
}
- return ret;
+
+ if (node) {
+ *node = ret;
+ }
+ return LY_SUCCESS;
}
-API struct lyd_node *
+API LY_ERR
lyd_new_any(struct lyd_node *parent, const struct lys_module *module, const char *name, const void *value,
- LYD_ANYDATA_VALUETYPE value_type)
+ LYD_ANYDATA_VALUETYPE value_type, struct lyd_node **node)
{
struct lyd_node *ret = NULL;
const struct lysc_node *schema;
struct ly_ctx *ctx = parent ? parent->schema->module->ctx : (module ? module->ctx : NULL);
- LY_CHECK_ARG_RET(ctx, parent || module, name, NULL);
+ LY_CHECK_ARG_RET(ctx, parent || module, name, LY_EINVAL);
if (!module) {
module = parent->schema->module;
}
schema = lys_find_child(parent ? parent->schema : NULL, module, name, 0, LYD_NODE_ANY, 0);
- LY_CHECK_ERR_RET(!schema, LOGERR(ctx, LY_EINVAL, "Any node \"%s\" not found.", name), NULL);
+ LY_CHECK_ERR_RET(!schema, LOGERR(ctx, LY_EINVAL, "Any node \"%s\" not found.", name), LY_ENOTFOUND);
- if (!lyd_create_any(schema, value, value_type, &ret) && parent) {
+ LY_CHECK_RET(lyd_create_any(schema, value, value_type, &ret));
+ if (parent) {
lyd_insert_node(parent, NULL, ret);
}
- return ret;
+
+ if (node) {
+ *node = ret;
+ }
+ return LY_SUCCESS;
}
/**
@@ -885,8 +903,9 @@
return ret;
}
-API struct lyd_meta *
-lyd_new_meta(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *val_str)
+API LY_ERR
+lyd_new_meta(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *val_str,
+ struct lyd_meta **meta)
{
struct lyd_meta *ret = NULL;
const struct ly_ctx *ctx;
@@ -894,7 +913,7 @@
char *str;
size_t pref_len, name_len;
- LY_CHECK_ARG_RET(NULL, parent, name, module || strchr(name, ':'), NULL);
+ LY_CHECK_ARG_RET(NULL, parent, name, module || strchr(name, ':'), LY_EINVAL);
ctx = LYD_NODE_CTX(parent);
@@ -902,7 +921,7 @@
tmp = name;
if (ly_parse_nodeid(&tmp, &prefix, &pref_len, &name, &name_len) || tmp[0]) {
LOGERR(ctx, LY_EINVAL, "Metadata name \"%s\" is not valid.", name);
- return NULL;
+ return LY_EVALID;
}
/* find the module */
@@ -910,7 +929,7 @@
str = strndup(prefix, pref_len);
module = ly_ctx_get_module_implemented(ctx, str);
free(str);
- LY_CHECK_ERR_RET(!module, LOGERR(ctx, LY_EINVAL, "Module \"%.*s\" not found.", pref_len, prefix), NULL);
+ LY_CHECK_ERR_RET(!module, LOGERR(ctx, LY_EINVAL, "Module \"%.*s\" not found.", pref_len, prefix), LY_ENOTFOUND);
}
/* set value if none */
@@ -918,18 +937,22 @@
val_str = "";
}
- lyd_create_meta(parent, &ret, module, name, name_len, val_str, strlen(val_str), NULL, lydjson_resolve_prefix, NULL,
- LYD_JSON, parent->schema);
- return ret;
+ LY_CHECK_RET(lyd_create_meta(parent, &ret, module, name, name_len, val_str, strlen(val_str), NULL,
+ lydjson_resolve_prefix, NULL, LYD_JSON, parent->schema));
+
+ if (meta) {
+ *meta = ret;
+ }
+ return LY_SUCCESS;
}
-API struct lyd_node *
+API LY_ERR
lyd_new_opaq(struct lyd_node *parent, const struct ly_ctx *ctx, const char *name, const char *value,
- const char *module_name)
+ const char *module_name, struct lyd_node **node)
{
struct lyd_node *ret = NULL;
- LY_CHECK_ARG_RET(ctx, parent || ctx, name, module_name, NULL);
+ LY_CHECK_ARG_RET(ctx, parent || ctx, name, module_name, LY_EINVAL);
if (!ctx) {
ctx = LYD_NODE_CTX(parent);
@@ -938,22 +961,28 @@
value = "";
}
- if (!lyd_create_opaq(ctx, name, strlen(name), value, strlen(value), NULL, LYD_JSON, NULL, NULL, 0, module_name, &ret)
- && parent) {
+ LY_CHECK_RET(lyd_create_opaq(ctx, name, strlen(name), value, strlen(value), NULL, LYD_JSON, NULL, NULL, 0,
+ module_name, &ret));
+ if (parent) {
lyd_insert_node(parent, NULL, ret);
}
- return ret;
+
+ if (node) {
+ *node = ret;
+ }
+ return LY_SUCCESS;
}
-API struct ly_attr *
-lyd_new_attr(struct lyd_node *parent, const char *module_name, const char *name, const char *val_str)
+API LY_ERR
+lyd_new_attr(struct lyd_node *parent, const char *module_name, const char *name, const char *val_str,
+ struct ly_attr **attr)
{
struct ly_attr *ret = NULL;
const struct ly_ctx *ctx;
const char *prefix, *tmp;
size_t pref_len, name_len;
- LY_CHECK_ARG_RET(NULL, parent, !parent->schema, name, NULL);
+ LY_CHECK_ARG_RET(NULL, parent, !parent->schema, name, LY_EINVAL);
ctx = LYD_NODE_CTX(parent);
@@ -961,7 +990,7 @@
tmp = name;
if (ly_parse_nodeid(&tmp, &prefix, &pref_len, &name, &name_len) || tmp[0]) {
LOGERR(ctx, LY_EINVAL, "Metadata name \"%s\" is not valid.", name);
- return NULL;
+ return LY_EVALID;
}
/* set value if none */
@@ -969,9 +998,13 @@
val_str = "";
}
- ly_create_attr(parent, &ret, ctx, name, name_len, val_str, strlen(val_str), NULL, LYD_JSON, NULL, prefix,
- pref_len, module_name);
- return ret;
+ LY_CHECK_RET(ly_create_attr(parent, &ret, ctx, name, name_len, val_str, strlen(val_str), NULL, LYD_JSON, NULL,
+ prefix, pref_len, module_name));
+
+ if (attr) {
+ *attr = ret;
+ }
+ return LY_SUCCESS;
}
API LY_ERR
@@ -1092,23 +1125,11 @@
return ret;
}
-API struct lyd_node *
-lyd_new_path(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const char *value, int options)
+API LY_ERR
+lyd_new_path(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const char *value, int options,
+ struct lyd_node **node)
{
- struct lyd_node *new_parent = NULL;
-
- lyd_new_path2(parent, ctx, path, value, 0, options, &new_parent, NULL);
- return new_parent;
-}
-
-API struct lyd_node *
-lyd_new_path_any(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const void *value,
- LYD_ANYDATA_VALUETYPE value_type, int options)
-{
- struct lyd_node *new_parent = NULL;
-
- lyd_new_path2(parent, ctx, path, value, value_type, options, &new_parent, NULL);
- return new_parent;
+ return lyd_new_path2(parent, ctx, path, value, 0, options, node, NULL);
}
API LY_ERR
@@ -2106,8 +2127,8 @@
* @return LY_ERR value
*/
static LY_ERR
-lyd_dup_recursive(const struct lyd_node *node, struct lyd_node *parent, struct lyd_node **first, int options,
- struct lyd_node **dup_p)
+lyd_dup_r(const struct lyd_node *node, struct lyd_node *parent, struct lyd_node **first, int options,
+ struct lyd_node **dup_p)
{
LY_ERR ret;
struct lyd_node *dup = NULL;
@@ -2155,10 +2176,7 @@
/* duplicate metadata */
if (!(options & LYD_DUP_NO_META)) {
LY_LIST_FOR(node->meta, meta) {
- if (!lyd_dup_meta(meta, dup)) {
- ret = LY_EINT;
- goto error;
- }
+ LY_CHECK_GOTO(ret = lyd_dup_meta_single(meta, dup, NULL), error);
}
}
@@ -2171,7 +2189,7 @@
if (options & LYD_DUP_RECURSIVE) {
/* duplicate all the children */
LY_LIST_FOR(orig->child, child) {
- LY_CHECK_GOTO(ret = lyd_dup_recursive(child, dup, NULL, options, NULL), error);
+ LY_CHECK_GOTO(ret = lyd_dup_r(child, dup, NULL, options, NULL), error);
}
}
opaq->name = lydict_insert(LYD_NODE_CTX(node), orig->name, 0);
@@ -2207,7 +2225,7 @@
if (options & LYD_DUP_RECURSIVE) {
/* duplicate all the children */
LY_LIST_FOR(orig->child, child) {
- LY_CHECK_GOTO(ret = lyd_dup_recursive(child, dup, NULL, options, NULL), error);
+ LY_CHECK_GOTO(ret = lyd_dup_r(child, dup, NULL, options, NULL), error);
}
} else if (dup->schema->nodetype == LYS_LIST && !(dup->schema->flags & LYS_KEYLESS)) {
/* always duplicate keys of a list */
@@ -2223,7 +2241,7 @@
* but there can be also some non-key nodes */
continue;
}
- LY_CHECK_GOTO(ret = lyd_dup_recursive(child, dup, NULL, options, NULL), error);
+ LY_CHECK_GOTO(ret = lyd_dup_r(child, dup, NULL, options, NULL), error);
child = child->next;
}
}
@@ -2247,86 +2265,92 @@
return ret;
}
-API struct lyd_node *
-lyd_dup(const struct lyd_node *node, struct lyd_node_inner *parent, int options)
+static LY_ERR
+lyd_dup_get_local_parent(const struct lyd_node *node, const struct lyd_node_inner *parent, struct lyd_node **dup_parent,
+ struct lyd_node_inner **local_parent)
{
+ const struct lyd_node_inner *orig_parent, *iter;
+ int repeat = 1;
+
+ *dup_parent = NULL;
+ *local_parent = NULL;
+
+ for (orig_parent = node->parent; repeat && orig_parent; orig_parent = orig_parent->parent) {
+ if (parent && (parent->schema == orig_parent->schema)) {
+ /* stop creating parents, connect what we have into the provided parent */
+ iter = parent;
+ repeat = 0;
+ } else {
+ iter = NULL;
+ LY_CHECK_RET(lyd_dup_r((struct lyd_node *)orig_parent, NULL, (struct lyd_node **)&iter, 0,
+ (struct lyd_node **)&iter));
+ }
+ if (!*local_parent) {
+ *local_parent = (struct lyd_node_inner *)iter;
+ }
+ if (iter->child) {
+ /* 1) list - add after keys
+ * 2) provided parent with some children */
+ iter->child->prev->next = *dup_parent;
+ if (*dup_parent) {
+ (*dup_parent)->prev = iter->child->prev;
+ iter->child->prev = *dup_parent;
+ }
+ } else {
+ ((struct lyd_node_inner *)iter)->child = *dup_parent;
+ }
+ if (*dup_parent) {
+ (*dup_parent)->parent = (struct lyd_node_inner *)iter;
+ }
+ *dup_parent = (struct lyd_node *)iter;
+ }
+
+ if (repeat && parent) {
+ /* given parent and created parents chain actually do not interconnect */
+ LOGERR(LYD_NODE_CTX(node), LY_EINVAL,
+ "Invalid argument parent (%s()) - does not interconnect with the created node's parents chain.", __func__);
+ return LY_EINVAL;
+ }
+
+ return LY_SUCCESS;
+}
+
+static LY_ERR
+lyd_dup(const struct lyd_node *node, struct lyd_node_inner *parent, int options, int nosiblings, struct lyd_node **dup)
+{
+ LY_ERR rc;
const struct lyd_node *orig; /* original node to be duplicated */
struct lyd_node *first = NULL; /* the first duplicated node, this is returned */
struct lyd_node *top = NULL; /* the most higher created node */
struct lyd_node_inner *local_parent = NULL; /* the direct parent node for the duplicated node(s) */
- int keyless_parent_list = 0;
- LY_CHECK_ARG_RET(NULL, node, NULL);
+ LY_CHECK_ARG_RET(NULL, node, LY_EINVAL);
if (options & LYD_DUP_WITH_PARENTS) {
- struct lyd_node_inner *orig_parent, *iter;
- int repeat = 1;
- for (top = NULL, orig_parent = node->parent; repeat && orig_parent; orig_parent = orig_parent->parent) {
- if (parent && parent->schema == orig_parent->schema) {
- /* stop creating parents, connect what we have into the provided parent */
- iter = parent;
- repeat = 0;
- /* get know if there is a keyless list which we will have to rehash */
- for (struct lyd_node_inner *piter = parent; piter; piter = piter->parent) {
- if (piter->schema->nodetype == LYS_LIST && (piter->schema->flags & LYS_KEYLESS)) {
- keyless_parent_list = 1;
- break;
- }
- }
- } else {
- iter = NULL;
- LY_CHECK_GOTO(lyd_dup_recursive((struct lyd_node *)orig_parent, NULL, (struct lyd_node **)&iter, 0,
- (struct lyd_node **)&iter), error);
- }
- if (!local_parent) {
- local_parent = iter;
- }
- if (iter->child) {
- /* 1) list - add after keys
- * 2) provided parent with some children */
- iter->child->prev->next = top;
- if (top) {
- top->prev = iter->child->prev;
- iter->child->prev = top;
- }
- } else {
- iter->child = top;
- if (iter->schema->nodetype == LYS_LIST) {
- /* keyless list - we will need to rehash it since we are going to add nodes into it */
- keyless_parent_list = 1;
- }
- }
- if (top) {
- top->parent = iter;
- }
- top = (struct lyd_node*)iter;
- }
- if (repeat && parent) {
- /* given parent and created parents chain actually do not interconnect */
- LOGERR(LYD_NODE_CTX(node), LY_EINVAL,
- "Invalid argument parent (%s()) - does not interconnect with the created node's parents chain.", __func__);
- goto error;
- }
+ LY_CHECK_GOTO(rc = lyd_dup_get_local_parent(node, parent, &top, &local_parent), error);
} else {
local_parent = parent;
}
LY_LIST_FOR(node, orig) {
/* if there is no local parent, it will be inserted into first */
- LY_CHECK_GOTO(lyd_dup_recursive(orig, (struct lyd_node *)local_parent, &first, options, first ? NULL : &first), error);
- if (!(options & LYD_DUP_WITH_SIBLINGS)) {
+ LY_CHECK_GOTO(rc = lyd_dup_r(orig, (struct lyd_node *)local_parent, &first, options, first ? NULL : &first), error);
+ if (nosiblings) {
break;
}
}
- if (keyless_parent_list) {
- /* rehash */
- for (; local_parent; local_parent = local_parent->parent) {
- if (local_parent->schema->nodetype == LYS_LIST && (local_parent->schema->flags & LYS_KEYLESS)) {
- lyd_hash((struct lyd_node*)local_parent);
- }
+
+ /* rehash if needed */
+ for (; local_parent; local_parent = local_parent->parent) {
+ if (local_parent->schema->nodetype == LYS_LIST && (local_parent->schema->flags & LYS_KEYLESS)) {
+ lyd_hash((struct lyd_node *)local_parent);
}
}
- return first;
+
+ if (dup) {
+ *dup = first;
+ }
+ return LY_SUCCESS;
error:
if (top) {
@@ -2334,25 +2358,37 @@
} else {
lyd_free_siblings(first);
}
- return NULL;
+ return rc;
}
-API struct lyd_meta *
-lyd_dup_meta(const struct lyd_meta *meta, struct lyd_node *node)
+API LY_ERR
+lyd_dup_single(const struct lyd_node *node, struct lyd_node_inner *parent, int options, struct lyd_node **dup)
+{
+ return lyd_dup(node, parent, options, 1, dup);
+}
+
+API LY_ERR
+lyd_dup_siblings(const struct lyd_node *node, struct lyd_node_inner *parent, int options, struct lyd_node **dup)
+{
+ return lyd_dup(node, parent, options, 0, dup);
+}
+
+API LY_ERR
+lyd_dup_meta_single(const struct lyd_meta *meta, struct lyd_node *node, struct lyd_meta **dup)
{
LY_ERR ret;
struct lyd_meta *mt, *last;
- LY_CHECK_ARG_RET(NULL, meta, node, NULL);
+ LY_CHECK_ARG_RET(NULL, meta, node, LY_EINVAL);
/* create a copy */
mt = calloc(1, sizeof *mt);
- LY_CHECK_ERR_RET(!mt, LOGMEM(LYD_NODE_CTX(node)), NULL);
+ LY_CHECK_ERR_RET(!mt, LOGMEM(LYD_NODE_CTX(node)), LY_EMEM);
mt->parent = node;
mt->annotation = meta->annotation;
mt->value.realtype = meta->value.realtype;
ret = mt->value.realtype->plugin->duplicate(LYD_NODE_CTX(node), &meta->value, &mt->value);
- LY_CHECK_ERR_RET(ret, LOGERR(LYD_NODE_CTX(node), LY_EINT, "Value duplication failed."), NULL);
+ LY_CHECK_ERR_RET(ret, LOGERR(LYD_NODE_CTX(node), LY_EINT, "Value duplication failed."), ret);
mt->name = lydict_insert(LYD_NODE_CTX(node), meta->name, 0);
/* insert as the last attribute */
@@ -2363,7 +2399,10 @@
node->meta = mt;
}
- return mt;
+ if (dup) {
+ *dup = mt;
+ }
+ return LY_SUCCESS;
}
/**
@@ -2401,8 +2440,8 @@
/* since they are different, they cannot both be default */
assert(!(sibling_src->flags & LYD_DEFAULT) || !(match_trg->flags & LYD_DEFAULT));
- /* update value (or only LYD_DEFAULT flag) only if no flag set or the source node is not default */
- if (!(options & LYD_MERGE_EXPLICIT) || !(sibling_src->flags & LYD_DEFAULT)) {
+ /* update value (or only LYD_DEFAULT flag) only if flag set or the source node is not default */
+ if ((options & LYD_MERGE_DEFAULTS) || !(sibling_src->flags & LYD_DEFAULT)) {
type = ((struct lysc_node_leaf *)match_trg->schema)->type;
type->plugin->free(LYD_NODE_CTX(match_trg), &((struct lyd_node_term *)match_trg)->value);
LY_CHECK_RET(type->plugin->duplicate(LYD_NODE_CTX(match_trg), &((struct lyd_node_term *)sibling_src)->value,
@@ -2418,8 +2457,7 @@
/* spend it */
*sibling_src_p = NULL;
} else {
- dup_src = lyd_dup(sibling_src, NULL, 0);
- LY_CHECK_RET(!dup_src, LY_EMEM);
+ LY_CHECK_RET(lyd_dup_single(sibling_src, NULL, 0, &dup_src));
}
/* just switch values */
tmp_val_type = ((struct lyd_node_any *)match_trg)->value_type;
@@ -2448,8 +2486,7 @@
/* spend it */
*sibling_src_p = NULL;
} else {
- dup_src = lyd_dup(sibling_src, NULL, LYD_DUP_RECURSIVE | LYD_DUP_WITH_FLAGS);
- LY_CHECK_RET(!dup_src, LY_EMEM);
+ LY_CHECK_RET(lyd_dup_single(sibling_src, NULL, LYD_DUP_RECURSIVE | LYD_DUP_WITH_FLAGS, &dup_src));
}
/* set LYD_NEW for all the new nodes, required for validation */
@@ -2464,8 +2501,8 @@
return LY_SUCCESS;
}
-API LY_ERR
-lyd_merge(struct lyd_node **target, const struct lyd_node *source, int options)
+static LY_ERR
+lyd_merge(struct lyd_node **target, const struct lyd_node *source, int options, int nosiblings)
{
const struct lyd_node *sibling_src, *tmp;
int first;
@@ -2490,7 +2527,7 @@
source = tmp;
}
- if (options & LYD_MERGE_NOSIBLINGS) {
+ if (nosiblings) {
break;
}
}
@@ -2503,6 +2540,18 @@
return LY_SUCCESS;
}
+API LY_ERR
+lyd_merge_tree(struct lyd_node **target, const struct lyd_node *source, int options)
+{
+ return lyd_merge(target, source, options, 1);
+}
+
+API LY_ERR
+lyd_merge_siblings(struct lyd_node **target, const struct lyd_node *source, int options)
+{
+ return lyd_merge(target, source, options, 0);
+}
+
static LY_ERR
lyd_path_str_enlarge(char **buffer, size_t *buflen, size_t reqlen, int is_static)
{
diff --git a/src/tree_data.h b/src/tree_data.h
index 9991eec..ea44fe7 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -475,10 +475,10 @@
* @param[in] parent Parent node for the node being created. NULL in case of creating a top level element.
* @param[in] module Module of the node being created. If NULL, @p parent module will be used.
* @param[in] name Schema node name of the new data node. The node can be #LYS_CONTAINER, #LYS_NOTIF, #LYS_RPC, or #LYS_ACTION.
- * @return New created node.
- * @return NULL on error.
+ * @param[out] node Optional created node.
+ * @return LY_ERR value.
*/
-struct lyd_node *lyd_new_inner(struct lyd_node *parent, const struct lys_module *module, const char *name);
+LY_ERR lyd_new_inner(struct lyd_node *parent, const struct lys_module *module, const char *name, struct lyd_node **node);
/**
* @brief Create a new list node in the data tree.
@@ -486,13 +486,13 @@
* @param[in] parent Parent node for the node being created. NULL in case of creating a top level element.
* @param[in] module Module of the node being created. If NULL, @p parent module will be used.
* @param[in] name Schema node name of the new data node. The node must be #LYS_LIST.
+ * @param[out] node Optional created node.
* @param[in] ... Ordered key values of the new list instance, all must be set. In case of an instance-identifier
* or identityref value, the JSON format is expected (module names instead of prefixes). No keys are expected for
* key-less lists.
- * @return New created node.
- * @return NULL on error.
+ * @return LY_ERR value.
*/
-struct lyd_node *lyd_new_list(struct lyd_node *parent, const struct lys_module *module, const char *name, ...);
+LY_ERR lyd_new_list(struct lyd_node *parent, const struct lys_module *module, const char *name, struct lyd_node **node, ...);
/**
* @brief Create a new list node in the data tree.
@@ -503,10 +503,11 @@
* @param[in] keys All key values predicate in the form of "[key1='val1'][key2='val2']...", they do not have to be ordered.
* In case of an instance-identifier or identityref value, the JSON format is expected (module names instead of prefixes).
* Use NULL or string of length 0 in case of key-less list.
- * @return New created node.
- * @return NULL on error.
+ * @param[out] node Optional created node.
+ * @return LY_ERR value.
*/
-struct lyd_node *lyd_new_list2(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *keys);
+LY_ERR lyd_new_list2(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *keys,
+ struct lyd_node **node);
/**
* @brief Create a new term node in the data tree.
@@ -516,10 +517,11 @@
* @param[in] name Schema node name of the new data node. The node can be #LYS_LEAF or #LYS_LEAFLIST.
* @param[in] val_str String form of the value of the node being created. In case of an instance-identifier or identityref
* value, the JSON format is expected (module names instead of prefixes).
- * @return New created node.
- * @return NULL on error.
+ * @param[out] node Optional created node.
+ * @return LY_ERR value.
*/
-struct lyd_node *lyd_new_term(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *val_str);
+LY_ERR lyd_new_term(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *val_str,
+ struct lyd_node **node);
/**
* @brief Create a new any node in the data tree.
@@ -529,11 +531,11 @@
* @param[in] name Schema node name of the new data node. The node can be #LYS_ANYDATA or #LYS_ANYXML.
* @param[in] value Value to be directly assigned to the node. Expected type is determined by @p value_type.
* @param[in] value_type Type of the provided value in @p value.
- * @return New created node.
- * @return NULL on error.
+ * @param[out] node Optional created node.
+ * @return LY_ERR value.
*/
-struct lyd_node *lyd_new_any(struct lyd_node *parent, const struct lys_module *module, const char *name,
- const void *value, LYD_ANYDATA_VALUETYPE value_type);
+LY_ERR lyd_new_any(struct lyd_node *parent, const struct lys_module *module, const char *name, const void *value,
+ LYD_ANYDATA_VALUETYPE value_type, struct lyd_node **node);
/**
* @brief Create new metadata for a data node.
@@ -544,11 +546,11 @@
* If the prefix is specified it is always used but if not specified, @p module must be set.
* @param[in] val_str String form of the value of the metadata. In case of an instance-identifier or identityref
* value, the JSON format is expected (module names instead of prefixes).
- * @return New created metadata of @p parent.
- * @return NULL on error.
+ * @param[out] meta Optional created metadata.
+ * @return LY_ERR value.
*/
-struct lyd_meta *lyd_new_meta(struct lyd_node *parent, const struct lys_module *module, const char *name,
- const char *val_str);
+LY_ERR lyd_new_meta(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *val_str,
+ struct lyd_meta **meta);
/**
* @brief Create a new opaque node in the data tree.
@@ -558,11 +560,11 @@
* @param[in] name Node name.
* @param[in] value Node value, may be NULL.
* @param[in] module_name Node module name.
- * @return New created node.
- * @return NULL on error.
+ * @param[out] node Optional created node.
+ * @return LY_ERR value.
*/
-struct lyd_node *lyd_new_opaq(struct lyd_node *parent, const struct ly_ctx *ctx, const char *name, const char *value,
- const char *module_name);
+LY_ERR lyd_new_opaq(struct lyd_node *parent, const struct ly_ctx *ctx, const char *name, const char *value,
+ const char *module_name, struct lyd_node **node);
/**
* @brief Create new attribute for an opaque data node.
@@ -571,10 +573,11 @@
* @param[in] module Module name of the attribute being created. There may be none.
* @param[in] name Attribute name. It can include the module name as the prefix.
* @param[in] val_str String value of the attribute. Is stored directly.
- * @return New created attribute of @p parent.
- * @return NULL on error.
+ * @param[out] attr Optional created attribute.
+ * @return LY_ERR value.
*/
-struct ly_attr *lyd_new_attr(struct lyd_node *parent, const char *module_name, const char *name, const char *val_str);
+LY_ERR lyd_new_attr(struct lyd_node *parent, const char *module_name, const char *name, const char *val_str,
+ struct ly_attr **attr);
/**
* @defgroup pathoptions Data path creation options
@@ -614,11 +617,11 @@
* @param[in] path Path to create (TODO ref path).
* @param[in] value Value of the new leaf/leaf-list. For other node types, it is ignored.
* @param[in] options Bitmask of options, see @ref pathoptions.
- * @return First created node.
- * @return NULL on error.
+ * @param[out] node Optional first created node.
+ * @return LY_ERR value.
*/
-struct lyd_node *lyd_new_path(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const char *value,
- int options);
+LY_ERR lyd_new_path(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const char *value,
+ int options, struct lyd_node **node);
/**
* @brief Create a new node in the data tree based on a path. All node types can be created.
@@ -633,11 +636,11 @@
* @param[in] value Value of the new leaf/leaf-list/anyxml/anydata. For other node types, it is ignored.
* @param[in] value_type Anyxml/anydata node @p value type.
* @param[in] options Bitmask of options, see @ref pathoptions.
- * @return First created node.
- * @return NULL on error.
+ * @param[out] node Optional first created node.
+ * @return LY_ERR value.
*/
-struct lyd_node *lyd_new_path_any(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const void *value,
- LYD_ANYDATA_VALUETYPE value_type, int options);
+LY_ERR lyd_new_path_any(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const void *value,
+ LYD_ANYDATA_VALUETYPE value_type, int options, struct lyd_node **node);
/**
* @brief Create a new node in the data tree based on a path. All node types can be created.
@@ -652,8 +655,8 @@
* @param[in] value Value of the new leaf/leaf-list/anyxml/anydata. For other node types, it is ignored.
* @param[in] value_type Anyxml/anydata node @p value type.
* @param[in] options Bitmask of options, see @ref pathoptions.
- * @param[out] new_parent First parent node created, can be NULL. If only one node was created, equals to @p new_node.
- * @param[out] new_node Last node created, can be NULL.
+ * @param[out] new_parent Optional first parent node created. If only one node was created, equals to @p new_node.
+ * @param[out] new_node Optional last node created.
* @return LY_ERR value.
*/
LY_ERR lyd_new_path2(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const void *value,
@@ -753,7 +756,7 @@
void lyd_free_all(struct lyd_node *node);
/**
- * @brief Free all the sibling nodes.
+ * @brief Free all the sibling nodes (preceding as well as succeeding).
*
* @param[in] node Any of the sibling nodes to free.
*/
@@ -767,24 +770,34 @@
void lyd_free_tree(struct lyd_node *node);
/**
- * @brief Destroy metadata.
+ * @brief Free a single metadata instance.
*
- * @param[in] ctx Context where the metadata was created.
- * @param[in] meta Metadata to destroy
- * @param[in] recursive Zero to destroy only the single metadata (the metadata list is corrected),
- * non-zero to destroy also all the subsequent metadata in the list.
+ * @param[in] meta Metadata to free.
*/
-void lyd_free_meta(const struct ly_ctx *ctx, struct lyd_meta *meta, int recursive);
+void lyd_free_meta_single(struct lyd_meta *meta);
/**
- * @brief Destroy attributes.
+ * @brief Free the metadata instance with any following instances.
+ *
+ * @param[in] meta Metadata to free.
+ */
+void lyd_free_meta_siblings(struct lyd_meta *meta);
+
+/**
+ * @brief Free a single attribute.
*
* @param[in] ctx Context where the attributes were created.
- * @param[in] attr Attributes to destroy.
- * @param[in] recursive Zero to destroy only the single attribute (the attribute list is corrected),
- * non-zero to destroy also all the subsequent attributes in the list.
+ * @param[in] attr Attribute to free.
*/
-void ly_free_attr(const struct ly_ctx *ctx, struct ly_attr *attr, int recursive);
+void ly_free_attr_single(const struct ly_ctx *ctx, struct ly_attr *attr);
+
+/**
+ * @brief Free the attribute with any following attributes.
+ *
+ * @param[in] ctx Context where the attributes were created.
+ * @param[in] attr First attribute to free.
+ */
+void ly_free_attr_siblings(const struct ly_ctx *ctx, struct ly_attr *attr);
/**
* @brief Check type restrictions applicable to the particular leaf/leaf-list with the given string @p value.
@@ -877,7 +890,7 @@
*
* Default behavior:
* - only the specified node is duplicated without siblings, parents, or children.
- * - all the attributes of the duplicated nodes are also duplicated.
+ * - all the metadata of the duplicated nodes are also duplicated.
* @{
*/
@@ -886,8 +899,7 @@
#define LYD_DUP_NO_META 0x02 /**< Do not duplicate metadata of any node. */
#define LYD_DUP_WITH_PARENTS 0x04 /**< If a nested node is being duplicated, duplicate also all the parents.
Keys are also duplicated for lists. Return value does not change! */
-#define LYD_DUP_WITH_SIBLINGS 0x08 /**< Duplicate also all the sibling of the given node. */
-#define LYD_DUP_WITH_FLAGS 0x10 /**< Also copy any data node flags. That will cause the duplicated data to preserve
+#define LYD_DUP_WITH_FLAGS 0x08 /**< Also copy any data node flags. That will cause the duplicated data to preserve
its validation/default node state. */
/** @} dupoptions */
@@ -897,24 +909,38 @@
*
* @param[in] node Data tree node to be duplicated.
* @param[in] parent Optional parent node where to connect the duplicated node(s).
- * If set in combination with LYD_DUP_WITH_PARENTS, the parents chain is duplicated until it comes to and connect with the @p parent
- * (if the parents chain does not match at some node the schema node of the provided @p parent, duplication fails).
+ * If set in combination with LYD_DUP_WITH_PARENTS, the parents chain is duplicated until it comes to and connects with
+ * the @p parent.
* @param[in] options Bitmask of options flags, see @ref dupoptions.
- * @return Created copy of the provided data \p node (the first of the duplicated siblings when LYD_DUP_WITH_SIBLINGS used).
- * Note that in case the parents chain is duplicated for the duplicated node(s) (when LYD_DUP_WITH_PARENTS used), the first duplicated node
- * is still returned, not a pointer to the duplicated parents.
+ * @param[out] dup Optional created copy of the node. Note that in case the parents chain is duplicated for the duplicated
+ * node(s) (when LYD_DUP_WITH_PARENTS used), the first duplicated node is still returned.
+ * @return LY_ERR value.
*/
-struct lyd_node *lyd_dup(const struct lyd_node *node, struct lyd_node_inner *parent, int options);
+LY_ERR lyd_dup_single(const struct lyd_node *node, struct lyd_node_inner *parent, int options, struct lyd_node **dup);
+
+/**
+ * @brief Create a copy of the specified data tree \p node with any following siblings. Schema references are kept the same.
+ *
+ * @param[in] node Data tree node to be duplicated.
+ * @param[in] parent Optional parent node where to connect the duplicated node(s).
+ * If set in combination with LYD_DUP_WITH_PARENTS, the parents chain is duplicated until it comes to and connects with
+ * the @p parent.
+ * @param[in] options Bitmask of options flags, see @ref dupoptions.
+ * @param[out] dup Optional created copy of the node. Note that in case the parents chain is duplicated for the duplicated
+ * node(s) (when LYD_DUP_WITH_PARENTS used), the first duplicated node is still returned.
+ * @return LY_ERR value.
+ */
+LY_ERR lyd_dup_siblings(const struct lyd_node *node, struct lyd_node_inner *parent, int options, struct lyd_node **dup);
/**
* @brief Create a copy of the metadata.
*
* @param[in] meta Metadata to copy.
- * @param[in] node Node where to append the new metadata.
- * @return Created metadata copy,
- * @return NULL on error.
+ * @param[in] parent Node where to append the new metadata.
+ * @param[out] dup Optional created metadata copy.
+ * @return LY_ERR value.
*/
-struct lyd_meta *lyd_dup_meta(const struct lyd_meta *meta, struct lyd_node *node);
+LY_ERR lyd_dup_meta_single(const struct lyd_meta *meta, struct lyd_node *parent, struct lyd_meta **dup);
/**
* @defgroup mergeoptions Data merge options.
@@ -924,20 +950,17 @@
*
* Default behavior:
* - source data tree is not modified in any way,
- * - source data tree is merged with any succeeding siblings,
- * - any default nodes from source replace explicit nodes in the target.
+ * - any default nodes in the source are ignored if there are explicit nodes in the target.
* @{
*/
#define LYD_MERGE_DESTRUCT 0x01 /**< Spend source data tree in the function, it cannot be used afterwards! */
-#define LYD_MERGE_NOSIBLINGS 0x02 /**< Merge only the single source data tree, no siblings. */
-#define LYD_MERGE_EXPLICIT 0x04 /**< Default nodes in the source tree are ignored if there are explicit nodes
- in the target tree. */
+#define LYD_MERGE_DEFAULTS 0x02 /**< Default nodes in the source tree replace even explicit nodes in the target. */
/** @} mergeoptions */
/**
- * @brief Merge the source data tree into the target data tree. Merge may not be complete until validation
+ * @brief Merge the source data subtree into the target data tree. Merge may not be complete until validation
* is called on the resulting data tree (data from more cases may be present, default and non-default values).
*
* @param[in,out] target Target data tree to merge into, must be a top-level tree.
@@ -946,7 +969,20 @@
* @return LY_SUCCESS on success,
* @return LY_ERR value on error.
*/
-LY_ERR lyd_merge(struct lyd_node **target, const struct lyd_node *source, int options);
+LY_ERR lyd_merge_tree(struct lyd_node **target, const struct lyd_node *source, int options);
+
+/**
+ * @brief Merge the source data tree with any following siblings into the target data tree. Merge may not be
+ * complete until validation called on the resulting data tree (data from more cases may be present, default
+ * and non-default values).
+ *
+ * @param[in,out] target Target data tree to merge into, must be a top-level tree.
+ * @param[in] source Source data tree to merge, must be a top-level tree.
+ * @param[in] options Bitmask of option flags, see @ref mergeoptions.
+ * @return LY_SUCCESS on success,
+ * @return LY_ERR value on error.
+ */
+LY_ERR lyd_merge_siblings(struct lyd_node **target, const struct lyd_node *source, int options);
/**
* @defgroup diffoptions Data diff options.
@@ -955,15 +991,13 @@
* Various options to change lyd_diff() behavior.
*
* Default behavior:
- * - data trees are compared with all the siblings,
* - any default nodes are treated as non-existent and ignored.
* @{
*/
-#define LYD_DIFF_NOSIBLINGS 0x01 /**< Only the single subtree is compared, no siblings. */
-#define LYD_DIFF_WITHDEFAULTS 0x02 /**< Default nodes in the trees are not ignored but treated similarly to explicit
- nodes. Also, leaves and leaf-lists are added into diff even in case only their
- default flag (state) was changed. */
+#define LYD_DIFF_DEFAULTS 0x01 /**< Default nodes in the trees are not ignored but treated similarly to explicit
+ nodes. Also, leaves and leaf-lists are added into diff even in case only their
+ default flag (state) was changed. */
/** @} diffoptions */
@@ -992,7 +1026,19 @@
* @return LY_SUCCESS on success,
* @return LY_ERR on error.
*/
-LY_ERR lyd_diff(const struct lyd_node *first, const struct lyd_node *second, int options, struct lyd_node **diff);
+LY_ERR lyd_diff_tree(const struct lyd_node *first, const struct lyd_node *second, int options, struct lyd_node **diff);
+
+/**
+ * @brief Learn the differences between 2 data trees including all the following siblings.
+ *
+ * @param[in] first First data tree.
+ * @param[in] second Second data tree.
+ * @param[in] options Bitmask of options flags, see @ref diffoptions.
+ * @param[out] diff Generated diff.
+ * @return LY_SUCCESS on success,
+ * @return LY_ERR on error.
+ */
+LY_ERR lyd_diff_siblings(const struct lyd_node *first, const struct lyd_node *second, int options, struct lyd_node **diff);
/**
* @brief Callback for diff nodes.
@@ -1005,7 +1051,7 @@
typedef LY_ERR (*lyd_diff_cb)(const struct lyd_node *diff_node, struct lyd_node *data_node, void *cb_data);
/**
- * @brief Apply a difference on a data tree but restrict the operation to one module.
+ * @brief Apply the whole diff on a data tree but restrict the operation to one module.
*
* @param[in,out] data Data to apply the diff on.
* @param[in] diff Diff to apply.
@@ -1019,14 +1065,14 @@
lyd_diff_cb diff_cb, void *cb_data);
/**
- * @brief Apply a difference on a data tree.
+ * @brief Apply the whole diff tree on a data tree.
*
* @param[in,out] data Data to apply the diff on.
* @param[in] diff Diff to apply.
* @return LY_SUCCESS on success,
* @return LY_ERR on error.
*/
-LY_ERR lyd_diff_apply(struct lyd_node **data, const struct lyd_node *diff);
+LY_ERR lyd_diff_apply_all(struct lyd_node **data, const struct lyd_node *diff);
/**
* @brief Merge 2 diffs into each other but restrict the operation to one module.
@@ -1060,7 +1106,7 @@
* @return LY_SUCCESS on success,
* @return LY_ERR on error.
*/
-LY_ERR lyd_diff_merge(const struct lyd_node *src_diff, struct lyd_node **diff);
+LY_ERR lyd_diff_merge_all(const struct lyd_node *src_diff, struct lyd_node **diff);
/**
* @brief Reverse a diff and make the opposite changes. Meaning change create to delete, delete to create,
@@ -1071,7 +1117,7 @@
* @return LY_SUCCESS on success.
* @return LY_ERR on error.
*/
-LY_ERR lyd_diff_reverse(const struct lyd_node *src_diff, struct lyd_node **diff);
+LY_ERR lyd_diff_reverse_all(const struct lyd_node *src_diff, struct lyd_node **diff);
/**
* @brief Find the target in data of a compiled ly_path structure (instance-identifier).
diff --git a/src/tree_data_free.c b/src/tree_data_free.c
index 9cb946e..7cd1283 100644
--- a/src/tree_data_free.c
+++ b/src/tree_data_free.c
@@ -23,19 +23,18 @@
#include "tree_data_internal.h"
#include "plugins_types.h"
-API void
-lyd_free_meta(const struct ly_ctx *ctx, struct lyd_meta *meta, int recursive)
+static void
+lyd_free_meta(struct lyd_meta *meta, int siblings)
{
struct lyd_meta *iter;
- LY_CHECK_ARG_RET(NULL, ctx, );
if (!meta) {
return;
}
if (meta->parent) {
if (meta->parent->meta == meta) {
- if (recursive) {
+ if (siblings) {
meta->parent->meta = NULL;
} else {
meta->parent->meta = meta->next;
@@ -43,7 +42,7 @@
} else {
for (iter = meta->parent->meta; iter->next != meta; iter = iter->next);
if (iter->next) {
- if (recursive) {
+ if (siblings) {
iter->next = NULL;
} else {
iter->next = meta->next;
@@ -52,7 +51,7 @@
}
}
- if (!recursive) {
+ if (!siblings) {
meta->next = NULL;
}
@@ -60,14 +59,26 @@
meta = iter;
iter = iter->next;
- FREE_STRING(ctx, meta->name);
- meta->value.realtype->plugin->free(ctx, &meta->value);
+ FREE_STRING(meta->annotation->module->ctx, meta->name);
+ meta->value.realtype->plugin->free(meta->annotation->module->ctx, &meta->value);
free(meta);
}
}
API void
-ly_free_attr(const struct ly_ctx *ctx, struct ly_attr *attr, int recursive)
+lyd_free_meta_single(struct lyd_meta *meta)
+{
+ lyd_free_meta(meta, 0);
+}
+
+API void
+lyd_free_meta_siblings(struct lyd_meta *meta)
+{
+ lyd_free_meta(meta, 1);
+}
+
+static void
+ly_free_attr(const struct ly_ctx *ctx, struct ly_attr *attr, int siblings)
{
struct ly_attr *iter;
LY_ARRAY_COUNT_TYPE u;
@@ -79,7 +90,7 @@
if (attr->parent) {
if (attr->parent->attr == attr) {
- if (recursive) {
+ if (siblings) {
attr->parent->attr = NULL;
} else {
attr->parent->attr = attr->next;
@@ -87,7 +98,7 @@
} else {
for (iter = attr->parent->attr; iter->next != attr; iter = iter->next);
if (iter->next) {
- if (recursive) {
+ if (siblings) {
iter->next = NULL;
} else {
iter->next = attr->next;
@@ -96,7 +107,7 @@
}
}
- if (!recursive) {
+ if (!siblings) {
attr->next = NULL;
}
@@ -117,6 +128,18 @@
}
}
+API void
+ly_free_attr_single(const struct ly_ctx *ctx, struct ly_attr *attr)
+{
+ ly_free_attr(ctx, attr, 0);
+}
+
+API void
+ly_free_attr_siblings(const struct ly_ctx *ctx, struct ly_attr *attr)
+{
+ ly_free_attr(ctx, attr, 1);
+}
+
void
ly_free_val_prefs(const struct ly_ctx *ctx, struct ly_prefix *val_prefs)
{
@@ -175,10 +198,10 @@
}
if (!node->schema) {
- ly_free_attr(LYD_NODE_CTX(node), opaq->attr, 1);
+ ly_free_attr_siblings(LYD_NODE_CTX(node), opaq->attr);
} else {
/* free the node's metadata */
- lyd_free_meta(LYD_NODE_CTX(node), node->meta, 1);
+ lyd_free_meta_siblings(node->meta);
}
/* unlink only the nodes from the first level, nodes in subtree are freed all, so no unlink is needed */
diff --git a/src/tree_data_helpers.c b/src/tree_data_helpers.c
index e11815b..7551667 100644
--- a/src/tree_data_helpers.c
+++ b/src/tree_data_helpers.c
@@ -198,7 +198,7 @@
} else {
*meta = (*meta)->next;
}
- lyd_free_meta(LYD_NODE_CTX(node), meta2, 0);
+ lyd_free_meta_single(meta2);
break;
}
@@ -242,8 +242,7 @@
switch (value_type) {
case LYD_ANYDATA_DATATREE:
if (value->tree) {
- t->value.tree = lyd_dup(value->tree, NULL, LYD_DUP_RECURSIVE | LYD_DUP_WITH_SIBLINGS);
- LY_CHECK_RET(!t->value.tree, LY_EINT);
+ LY_CHECK_RET(lyd_dup_siblings(value->tree, NULL, LYD_DUP_RECURSIVE, &t->value.tree));
}
break;
case LYD_ANYDATA_STRING:
diff --git a/src/tree_schema.c b/src/tree_schema.c
index b958df4..e89cd01 100644
--- a/src/tree_schema.c
+++ b/src/tree_schema.c
@@ -749,17 +749,18 @@
return lys_set_implemented_internal(mod, 1);
}
-struct lysp_submodule *
+LY_ERR
lys_parse_mem_submodule(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, struct lys_parser_ctx *main_ctx,
- LY_ERR (*custom_check)(const struct ly_ctx*, struct lysp_module*, struct lysp_submodule*, void*), void *check_data)
+ LY_ERR (*custom_check)(const struct ly_ctx*, struct lysp_module*, struct lysp_submodule*, void*),
+ void *check_data, struct lysp_submodule **submodule)
{
- LY_ERR ret = LY_EINVAL;
+ LY_ERR ret;
struct lysp_submodule *submod = NULL, *latest_sp;
struct lys_yang_parser_ctx *yangctx = NULL;
struct lys_yin_parser_ctx *yinctx = NULL;
struct lys_parser_ctx *pctx;
- LY_CHECK_ARG_RET(ctx, ctx, in, NULL);
+ LY_CHECK_ARG_RET(ctx, ctx, in, LY_EINVAL);
switch (format) {
case LYS_IN_YIN:
@@ -802,7 +803,7 @@
}
if (custom_check) {
- LY_CHECK_GOTO(custom_check(PARSER_CTX(pctx), NULL, submod, check_data), error);
+ LY_CHECK_GOTO(ret = custom_check(PARSER_CTX(pctx), NULL, submod, check_data), error);
}
if (latest_sp) {
@@ -818,7 +819,8 @@
} else {
yin_parser_ctx_free(yinctx);
}
- return submod;
+ *submodule = submod;
+ return LY_SUCCESS;
error:
lysp_submodule_free(ctx, submod);
@@ -827,27 +829,28 @@
} else {
yin_parser_ctx_free(yinctx);
}
- return NULL;
+ return ret;
}
-struct lys_module *
+LY_ERR
lys_parse_mem_module(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, int implement,
- LY_ERR (*custom_check)(const struct ly_ctx *ctx, struct lysp_module *mod, struct lysp_submodule *submod, void *data),
- void *check_data)
+ LY_ERR (*custom_check)(const struct ly_ctx *ctx, struct lysp_module *mod,
+ struct lysp_submodule *submod, void *data), void *check_data,
+ struct lys_module **module)
{
struct lys_module *mod = NULL, *latest, *mod_dup;
struct lysp_import *imp;
struct lysp_include *inc;
- LY_ERR ret = LY_EINVAL;
+ LY_ERR ret;
LY_ARRAY_COUNT_TYPE u, v;
struct lys_yang_parser_ctx *yangctx = NULL;
struct lys_yin_parser_ctx *yinctx = NULL;
struct lys_parser_ctx *pctx = NULL;
- LY_CHECK_ARG_RET(ctx, ctx, in, NULL);
+ LY_CHECK_ARG_RET(ctx, ctx, in, LY_EINVAL);
mod = calloc(1, sizeof *mod);
- LY_CHECK_ERR_RET(!mod, LOGMEM(ctx), NULL);
+ LY_CHECK_ERR_RET(!mod, LOGMEM(ctx), LY_EMEM);
mod->ctx = ctx;
switch (format) {
@@ -861,6 +864,7 @@
break;
default:
LOGERR(ctx, LY_EINVAL, "Invalid schema input format.");
+ ret = LY_EINVAL;
break;
}
LY_CHECK_GOTO(ret, error);
@@ -893,13 +897,14 @@
}
if (custom_check) {
- LY_CHECK_GOTO(custom_check(ctx, mod->parsed, NULL, check_data), error);
+ LY_CHECK_GOTO(ret = custom_check(ctx, mod->parsed, NULL, check_data), error);
}
if (implement) {
/* mark the loaded module implemented */
if (ly_ctx_get_module_implemented(ctx, mod->name)) {
LOGERR(ctx, LY_EDENIED, "Module \"%s\" is already implemented in the context.", mod->name);
+ ret = LY_EDENIED;
goto error;
}
mod->implemented = 1;
@@ -917,6 +922,7 @@
LOGERR(ctx, LY_EEXIST, "Module \"%s\" with no revision is already present in the context.",
mod->name);
}
+ ret = LY_EEXIST;
goto error;
} else {
/* add the parsed data to the currently compiled-only module in the context */
@@ -931,8 +937,8 @@
if (!mod->implemented) {
/* pre-compile features and identities of the module */
- LY_CHECK_GOTO(lys_feature_precompile(NULL, ctx, mod, mod->parsed->features, &mod->dis_features), error);
- LY_CHECK_GOTO(lys_identity_precompile(NULL, ctx, mod, mod->parsed->identities, &mod->dis_identities), error);
+ LY_CHECK_GOTO(ret = lys_feature_precompile(NULL, ctx, mod, mod->parsed->features, &mod->dis_features), error);
+ LY_CHECK_GOTO(ret = lys_identity_precompile(NULL, ctx, mod, mod->parsed->identities, &mod->dis_identities), error);
}
if (latest) {
@@ -947,39 +953,44 @@
mod->parsed->parsing = 1;
LY_ARRAY_FOR(mod->parsed->imports, u) {
imp = &mod->parsed->imports[u];
- if (!imp->module && lysp_load_module(ctx, imp->name, imp->rev[0] ? imp->rev : NULL, 0, 0, &imp->module)) {
- goto error_ctx;
+ if (!imp->module) {
+ LY_CHECK_GOTO(ret = lysp_load_module(ctx, imp->name, imp->rev[0] ? imp->rev : NULL, 0, 0, &imp->module),
+ error_ctx);
}
/* check for importing the same module twice */
for (v = 0; v < u; ++v) {
if (imp->module == mod->parsed->imports[v].module) {
- LOGVAL(ctx, LY_VLOG_NONE, NULL, LYVE_REFERENCE, "Single revision of the module \"%s\" referred twice.", imp->name);
+ LOGVAL(ctx, LY_VLOG_NONE, NULL, LYVE_REFERENCE, "Single revision of the module \"%s\" referred twice.",
+ imp->name);
+ ret = LY_EVALID;
goto error_ctx;
}
}
}
LY_ARRAY_FOR(mod->parsed->includes, u) {
inc = &mod->parsed->includes[u];
- if (!inc->submodule && lysp_load_submodule(pctx, mod->parsed, inc)) {
- goto error_ctx;
+ if (!inc->submodule) {
+ LY_CHECK_GOTO(ret = lysp_load_submodule(pctx, mod->parsed, inc), error_ctx);
}
if (!mod->implemented) {
/* pre-compile features and identities of the submodule */
- LY_CHECK_GOTO(lys_feature_precompile(NULL, ctx, mod, inc->submodule->features, &mod->dis_features), error);
- LY_CHECK_GOTO(lys_identity_precompile(NULL, ctx, mod, inc->submodule->identities, &mod->dis_identities), error);
+ LY_CHECK_GOTO(ret = lys_feature_precompile(NULL, ctx, mod, inc->submodule->features, &mod->dis_features), error);
+ LY_CHECK_GOTO(ret = lys_identity_precompile(NULL, ctx, mod, inc->submodule->identities, &mod->dis_identities),
+ error);
}
}
mod->parsed->parsing = 0;
/* check name collisions - typedefs and TODO groupings */
- LY_CHECK_GOTO(lysp_check_typedefs(pctx, mod->parsed), error_ctx);
+ LY_CHECK_GOTO(ret = lysp_check_typedefs(pctx, mod->parsed), error_ctx);
if (format == LYS_IN_YANG) {
yang_parser_ctx_free(yangctx);
} else {
yin_parser_ctx_free(yinctx);
}
- return mod;
+ *module = mod;
+ return LY_SUCCESS;
error_ctx:
ly_set_rm(&ctx->list, mod, NULL);
@@ -994,23 +1005,25 @@
yin_parser_ctx_free(yinctx);
}
- return NULL;
+ return ret;
}
-API struct lys_module *
-lys_parse(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format)
+API LY_ERR
+lys_parse(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, const struct lys_module **module)
{
struct lys_module *mod;
char *filename, *rev, *dot;
size_t len;
- LY_CHECK_ARG_RET(NULL, ctx, in, format > LYS_IN_UNKNOWN, NULL);
+ if (module) {
+ *module = NULL;
+ }
+ LY_CHECK_ARG_RET(NULL, ctx, in, format > LYS_IN_UNKNOWN, LY_EINVAL);
/* remember input position */
in->func_start = in->current;
- mod = lys_parse_mem_module(ctx, in, format, 1, NULL, NULL);
- LY_CHECK_RET(!mod, NULL);
+ LY_CHECK_RET(lys_parse_mem_module(ctx, in, format, 1, NULL, NULL, &mod));
switch (in->type) {
case LY_IN_FILEPATH:
@@ -1045,65 +1058,66 @@
/* nothing special to do */
break;
default:
- LOGINT(ctx);
+ LOGINT_RET(ctx);
break;
}
lys_parser_fill_filepath(ctx, in, &mod->filepath);
- lys_compile(&mod, 0);
+ LY_CHECK_RET(lys_compile(&mod, 0));
- return mod;
+ if (module) {
+ *module = mod;
+ }
+ return LY_SUCCESS;
}
-API struct lys_module *
-lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format)
+API LY_ERR
+lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format, const struct lys_module **module)
{
LY_ERR ret;
struct ly_in *in = NULL;
- struct lys_module *result = NULL;
- LY_CHECK_ARG_RET(ctx, data, format != LYS_IN_UNKNOWN, NULL);
+ LY_CHECK_ARG_RET(ctx, data, format != LYS_IN_UNKNOWN, LY_EINVAL);
- LY_CHECK_ERR_RET(ret = ly_in_new_memory(data, &in), LOGERR(ctx, ret, "Unable to create input handler."), NULL);
+ LY_CHECK_ERR_RET(ret = ly_in_new_memory(data, &in), LOGERR(ctx, ret, "Unable to create input handler."), ret);
- result = lys_parse(ctx, in, format);
+ ret = lys_parse(ctx, in, format, module);
ly_in_free(in, 0);
- return result;
+ return ret;
}
-API struct lys_module *
-lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format)
+API LY_ERR
+lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format, const struct lys_module **module)
{
LY_ERR ret;
struct ly_in *in = NULL;
- struct lys_module *result = NULL;
- LY_CHECK_ARG_RET(ctx, fd != -1, format != LYS_IN_UNKNOWN, NULL);
+ LY_CHECK_ARG_RET(ctx, fd > -1, format != LYS_IN_UNKNOWN, LY_EINVAL);
- LY_CHECK_ERR_RET(ret = ly_in_new_fd(fd, &in), LOGERR(ctx, ret, "Unable to create input handler."), NULL);
+ LY_CHECK_ERR_RET(ret = ly_in_new_fd(fd, &in), LOGERR(ctx, ret, "Unable to create input handler."), ret);
- result = lys_parse(ctx, in, format);
+ ret = lys_parse(ctx, in, format, module);
ly_in_free(in, 0);
- return result;
+ return ret;
}
-API struct lys_module *
-lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format)
+API LY_ERR
+lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format, const struct lys_module **module)
{
LY_ERR ret;
struct ly_in *in = NULL;
- struct lys_module *result = NULL;
- LY_CHECK_ARG_RET(ctx, path, format != LYS_IN_UNKNOWN, NULL);
+ LY_CHECK_ARG_RET(ctx, path, format != LYS_IN_UNKNOWN, LY_EINVAL);
- LY_CHECK_ERR_RET(ret = ly_in_new_filepath(path, 0, &in), LOGERR(ctx, ret, "Unable to create input handler for filepath %s.", path), NULL);
+ LY_CHECK_ERR_RET(ret = ly_in_new_filepath(path, 0, &in),
+ LOGERR(ctx, ret, "Unable to create input handler for filepath %s.", path), ret);
- result = lys_parse(ctx, in, format);
+ ret = lys_parse(ctx, in, format, module);
ly_in_free(in, 0);
- return result;
+ return ret;
}
API LY_ERR
diff --git a/src/tree_schema_compile.c b/src/tree_schema_compile.c
index d62473b..ca53a39 100644
--- a/src/tree_schema_compile.c
+++ b/src/tree_schema_compile.c
@@ -911,7 +911,7 @@
static LY_ERR
lys_compile_import(struct lysc_ctx *ctx, struct lysp_import *imp_p, struct lysc_import *imp)
{
- struct lys_module *mod = NULL;
+ const struct lys_module *mod = NULL;
LY_ERR ret = LY_SUCCESS;
DUP_STRING(ctx->ctx, imp_p->prefix, imp->prefix);
@@ -928,16 +928,18 @@
if (ly_in_new_filepath(imp->module->filepath, 0, &in)) {
LOGINT(ctx->ctx);
} else {
- mod = lys_parse(ctx->ctx, in, !strcmp(&imp->module->filepath[strlen(imp->module->filepath - 4)], ".yin") ? LYS_IN_YIN : LYS_IN_YANG);
+ LY_CHECK_RET(lys_parse(ctx->ctx, in, !strcmp(&imp->module->filepath[strlen(imp->module->filepath - 4)],
+ ".yin") ? LYS_IN_YIN : LYS_IN_YANG, &mod));
if (mod != imp->module) {
- LOGERR(ctx->ctx, LY_EINT, "Filepath \"%s\" of the module \"%s\" does not match.", imp->module->filepath, imp->module->name);
+ LOGERR(ctx->ctx, LY_EINT, "Filepath \"%s\" of the module \"%s\" does not match.",
+ imp->module->filepath, imp->module->name);
mod = NULL;
}
}
ly_in_free(in, 1);
}
if (!mod) {
- if (lysp_load_module(ctx->ctx, imp->module->name, imp->module->revision, 0, 1, &mod)) {
+ if (lysp_load_module(ctx->ctx, imp->module->name, imp->module->revision, 0, 1, (struct lys_module **)&mod)) {
LOGERR(ctx->ctx, LY_ENOTFOUND, "Unable to reload \"%s\" module to import it into \"%s\", source data not found.",
imp->module->name, ctx->mod->name);
return LY_ENOTFOUND;
diff --git a/src/tree_schema_helpers.c b/src/tree_schema_helpers.c
index e079640..bedf795 100644
--- a/src/tree_schema_helpers.c
+++ b/src/tree_schema_helpers.c
@@ -755,34 +755,42 @@
LY_CHECK_RET(lys_search_localfile(ly_ctx_get_searchdirs(ctx), !(ctx->flags & LY_CTX_DISABLE_SEARCHDIR_CWD), name, revision,
&filepath, &format));
- LY_CHECK_ERR_RET(!filepath, if (required) {LOGERR(ctx, LY_ENOTFOUND, "Data model \"%s%s%s\" not found in local searchdirs.",
- name, revision ? "@" : "", revision ? revision : "");}, LY_ENOTFOUND);
+ if (!filepath) {
+ if (required) {
+ LOGERR(ctx, LY_ENOTFOUND, "Data model \"%s%s%s\" not found in local searchdirs.", name, revision ? "@" : "",
+ revision ? revision : "");
+ }
+ return LY_ENOTFOUND;
+ }
LOGVRB("Loading schema from \"%s\" file.", filepath);
/* get the (sub)module */
- LY_CHECK_ERR_GOTO(ret = ly_in_new_filepath(filepath, 0, &in), LOGERR(ctx, ret, "Unable to create input handler for filepath %s.", filepath), cleanup);
+ LY_CHECK_ERR_GOTO(ret = ly_in_new_filepath(filepath, 0, &in),
+ LOGERR(ctx, ret, "Unable to create input handler for filepath %s.", filepath), cleanup);
check_data.name = name;
check_data.revision = revision;
check_data.path = filepath;
check_data.submoduleof = main_name;
if (main_ctx) {
- mod = lys_parse_mem_submodule(ctx, in, format, main_ctx, lysp_load_module_check, &check_data);
+ ret = lys_parse_mem_submodule(ctx, in, format, main_ctx, lysp_load_module_check, &check_data,
+ (struct lysp_submodule **)&mod);
} else {
- mod = lys_parse_mem_module(ctx, in, format, implement, lysp_load_module_check, &check_data);
+ ret = lys_parse_mem_module(ctx, in, format, implement, lysp_load_module_check, &check_data,
+ (struct lys_module **)&mod);
}
- LY_CHECK_ERR_GOTO(!mod, ly_in_free(in, 1);ly_errcode(ctx), cleanup);
+ LY_CHECK_ERR_GOTO(ret, ly_in_free(in, 1), cleanup);
if (main_ctx) {
- lys_parser_fill_filepath(ctx, in, &((struct lysp_submodule*)mod)->filepath);
+ lys_parser_fill_filepath(ctx, in, &((struct lysp_submodule *)mod)->filepath);
} else {
- lys_parser_fill_filepath(ctx, in, &((struct lys_module*)mod)->filepath);
+ lys_parser_fill_filepath(ctx, in, &((struct lys_module *)mod)->filepath);
}
ly_in_free(in, 1);
if (mod && implement) {
- lys_compile((struct lys_module**)&mod, 0);
+ lys_compile((struct lys_module **)&mod, 0);
}
*result = mod;
@@ -794,7 +802,8 @@
}
LY_ERR
-lysp_load_module(struct ly_ctx *ctx, const char *name, const char *revision, int implement, int require_parsed, struct lys_module **mod)
+lysp_load_module(struct ly_ctx *ctx, const char *name, const char *revision, int implement, int require_parsed,
+ struct lys_module **mod)
{
const char *module_data = NULL;
LYS_INFORMAT format = LYS_IN_UNKNOWN;
@@ -848,7 +857,7 @@
LY_CHECK_RET(ly_in_new_memory(module_data, &in));
check_data.name = name;
check_data.revision = revision;
- *mod = lys_parse_mem_module(ctx, in, format, implement, lysp_load_module_check, &check_data);
+ lys_parse_mem_module(ctx, in, format, implement, lysp_load_module_check, &check_data, mod);
ly_in_free(in, 0);
if (module_data_free) {
module_data_free((void*)module_data, ctx->imp_clb_data);
@@ -970,7 +979,7 @@
check_data.name = inc->name;
check_data.revision = inc->rev[0] ? inc->rev : NULL;
check_data.submoduleof = mod->mod->name;
- submod = lys_parse_mem_submodule(ctx, in, format, pctx, lysp_load_module_check, &check_data);
+ lys_parse_mem_submodule(ctx, in, format, pctx, lysp_load_module_check, &check_data, &submod);
ly_in_free(in, 0);
if (submodule_data_free) {
submodule_data_free((void*)submodule_data, ctx->imp_clb_data);
diff --git a/src/tree_schema_internal.h b/src/tree_schema_internal.h
index 880a297..2952413 100644
--- a/src/tree_schema_internal.h
+++ b/src/tree_schema_internal.h
@@ -520,7 +520,8 @@
*/
const char *lys_datatype2str(LY_DATA_TYPE basetype);
-typedef LY_ERR (*lys_custom_check)(const struct ly_ctx *ctx, struct lysp_module *mod, struct lysp_submodule *submod, void *check_data);
+typedef LY_ERR (*lys_custom_check)(const struct ly_ctx *ctx, struct lysp_module *mod, struct lysp_submodule *submod,
+ void *check_data);
/**
* @brief Parse module from a string.
@@ -533,10 +534,11 @@
* @param[in] implement Flag if the schema is supposed to be marked as implemented.
* @param[in] custom_check Callback to check the parsed schema before it is accepted.
* @param[in] check_data Caller's data to pass to the custom_check callback.
- * @return Pointer to the data model structure or NULL on error.
+ * @param[out] module Parsed module.
+ * @return LY_ERR value.
*/
-struct lys_module *lys_parse_mem_module(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, int implement,
- lys_custom_check custom_check, void *check_data);
+LY_ERR lys_parse_mem_module(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, int implement,
+ lys_custom_check custom_check, void *check_data, struct lys_module **module);
/**
* @brief Parse submodule from a string.
@@ -549,11 +551,12 @@
* @param[in] main_ctx Parser context of the main module.
* @param[in] custom_check Callback to check the parsed schema before it is accepted.
* @param[in] check_data Caller's data to pass to the custom_check callback.
- * @return Pointer to the data model structure or NULL on error.
+ * @param[out] submodule Parsed submodule.
+ * @return LY_ERR value.
*/
-struct lysp_submodule *lys_parse_mem_submodule(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format,
- struct lys_parser_ctx *main_ctx, lys_custom_check custom_check,
- void *check_data);
+LY_ERR lys_parse_mem_submodule(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format,
+ struct lys_parser_ctx *main_ctx, lys_custom_check custom_check,
+ void *check_data, struct lysp_submodule **submodule);
/**
* @brief Fill filepath value if available in input handler @p in
diff --git a/src/validation.c b/src/validation.c
index 631fde6..437ce21 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -117,7 +117,7 @@
LY_CHECK_RET(lyd_diff_add(node, op, NULL, NULL, NULL, NULL, NULL, &new_diff));
/* merge into existing diff */
- ret = lyd_diff_merge(new_diff, diff);
+ ret = lyd_diff_merge_all(new_diff, diff);
lyd_free_tree(new_diff);
return ret;
@@ -1256,7 +1256,7 @@
* @return LY_ERR value.
*/
static LY_ERR
-_lyd_validate(struct lyd_node **tree, const struct lys_module *module, const struct ly_ctx *ctx, int val_opts,
+lyd_validate(struct lyd_node **tree, const struct lys_module *module, const struct ly_ctx *ctx, int val_opts,
struct lyd_node **diff)
{
LY_ERR ret = LY_SUCCESS;
@@ -1319,15 +1319,15 @@
}
API LY_ERR
-lyd_validate(struct lyd_node **tree, const struct ly_ctx *ctx, int val_opts, struct lyd_node **diff)
+lyd_validate_all(struct lyd_node **tree, const struct ly_ctx *ctx, int val_opts, struct lyd_node **diff)
{
- return _lyd_validate(tree, NULL, ctx, val_opts, diff);
+ return lyd_validate(tree, NULL, ctx, val_opts, diff);
}
API LY_ERR
lyd_validate_module(struct lyd_node **tree, const struct lys_module *module, int val_opts, struct lyd_node **diff)
{
- return _lyd_validate(tree, module, NULL, val_opts, diff);
+ return lyd_validate(tree, module, NULL, val_opts, diff);
}
/**
diff --git a/src/xpath.c b/src/xpath.c
index 3a1f3df..55a0f6b 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -431,7 +431,7 @@
break;
case LYD_ANYDATA_DATATREE:
LY_CHECK_RET(ly_out_new_memory(&buf, 0, &out));
- rc = lyd_print(out, any->value.tree, LYD_XML, LYD_PRINT_WITHSIBLINGS);
+ rc = lyd_print_all(out, any->value.tree, LYD_XML, 0);
ly_out_free(out, NULL, 0);
LY_CHECK_RET(rc < 0, -rc);
break;
diff --git a/tests/utests/data/test_diff.c b/tests/utests/data/test_diff.c
index 612bf88..bb52594 100644
--- a/tests/utests/data/test_diff.c
+++ b/tests/utests/data/test_diff.c
@@ -228,7 +228,7 @@
assert_non_null(st);
assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &st->ctx));
assert_non_null(ly_ctx_load_module(st->ctx, "ietf-netconf-acm", "2018-02-14"));
- assert_non_null(lys_parse_mem(st->ctx, schema, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, schema, LYS_IN_YANG, NULL));
return 0;
}
@@ -263,9 +263,9 @@
assert_non_null(st->first);
st->second = NULL;
- assert_int_equal(lyd_diff(st->first, lyd_node_children(st->first, 0), 0, &st->diff1), LY_EINVAL);
+ assert_int_equal(lyd_diff_siblings(st->first, lyd_node_children(st->first, 0), 0, &st->diff1), LY_EINVAL);
- assert_int_equal(lyd_diff(NULL, NULL, 0, NULL), LY_EINVAL);
+ assert_int_equal(lyd_diff_siblings(NULL, NULL, 0, NULL), LY_EINVAL);
}
static void
@@ -288,10 +288,10 @@
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->second));
assert_non_null(st->second);
- assert_int_equal(lyd_diff(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
assert_null(st->diff1);
- assert_int_equal(lyd_diff_apply(&st->first, st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
lyd_print_mem(&st->xml1, st->first, LYD_XML, LYD_PRINT_WITHSIBLINGS);
lyd_print_mem(&st->xml2, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
assert_string_equal(st->xml1, st->xml2);
@@ -313,7 +313,7 @@
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->second));
assert_non_null(st->second);
- assert_int_equal(lyd_diff(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
assert_non_null(st->diff1);
lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -326,7 +326,7 @@
"</hidden>"
);
- assert_int_equal(lyd_diff_apply(&st->first, st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
lyd_print_mem(&st->xml1, st->first, LYD_XML, LYD_PRINT_WITHSIBLINGS);
lyd_print_mem(&st->xml2, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
assert_string_equal(st->xml1, st->xml2);
@@ -345,7 +345,7 @@
assert_non_null(st->first);
st->second = NULL;
- assert_int_equal(lyd_diff(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
assert_non_null(st->diff1);
lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -358,7 +358,7 @@
"</hidden>"
);
- assert_int_equal(lyd_diff_apply(&st->first, st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
assert_ptr_equal(st->first, st->second);
}
@@ -372,10 +372,10 @@
assert_non_null(st->first);
st->second = NULL;
- assert_int_equal(lyd_diff(NULL, NULL, 0, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(NULL, NULL, 0, &st->diff1), LY_SUCCESS);
assert_null(st->diff1);
- assert_int_equal(lyd_diff(NULL, lyd_node_children(st->first, 0), 0, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(NULL, lyd_node_children(st->first, 0), 0, &st->diff1), LY_SUCCESS);
assert_non_null(st->diff1);
lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -386,7 +386,7 @@
);
free(st->xml);
- assert_int_equal(lyd_diff(lyd_node_children(st->first, 0), NULL, 0, &st->diff2), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(lyd_node_children(st->first, 0), NULL, 0, &st->diff2), LY_SUCCESS);
assert_non_null(st->diff2);
lyd_print_mem(&st->xml, st->diff2, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -428,7 +428,7 @@
assert_non_null(st->third);
/* diff1 */
- assert_int_equal(lyd_diff(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
assert_non_null(st->diff1);
lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -443,13 +443,13 @@
"</hidden>"
);
- assert_int_equal(lyd_diff_apply(&st->first, st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
lyd_print_mem(&st->xml1, st->first, LYD_XML, LYD_PRINT_WITHSIBLINGS);
lyd_print_mem(&st->xml2, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
assert_string_equal(st->xml1, st->xml2);
/* diff2 */
- assert_int_equal(lyd_diff(st->second, st->third, 0, &st->diff2), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(st->second, st->third, 0, &st->diff2), LY_SUCCESS);
assert_non_null(st->diff2);
free(st->xml);
@@ -464,7 +464,7 @@
"</hidden>"
);
- assert_int_equal(lyd_diff_apply(&st->second, st->diff2), LY_SUCCESS);
+ assert_int_equal(lyd_diff_apply_all(&st->second, st->diff2), LY_SUCCESS);
free(st->xml1);
lyd_print_mem(&st->xml1, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
free(st->xml2);
@@ -472,7 +472,7 @@
assert_string_equal(st->xml1, st->xml2);
/* merge */
- assert_int_equal(lyd_diff_merge(st->diff2, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_merge_all(st->diff2, &st->diff1), LY_SUCCESS);
free(st->xml);
lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -512,7 +512,7 @@
assert_non_null(st->third);
/* diff1 */
- assert_int_equal(lyd_diff(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
assert_non_null(st->diff1);
lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -533,13 +533,13 @@
"</df>"
);
- assert_int_equal(lyd_diff_apply(&st->first, st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
lyd_print_mem(&st->xml1, st->first, LYD_XML, LYD_PRINT_WITHSIBLINGS);
lyd_print_mem(&st->xml2, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
assert_string_equal(st->xml1, st->xml2);
/* diff2 */
- assert_int_equal(lyd_diff(st->second, st->third, 0, &st->diff2), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(st->second, st->third, 0, &st->diff2), LY_SUCCESS);
assert_non_null(st->diff2);
free(st->xml);
@@ -557,7 +557,7 @@
"</df>"
);
- assert_int_equal(lyd_diff_apply(&st->second, st->diff2), LY_SUCCESS);
+ assert_int_equal(lyd_diff_apply_all(&st->second, st->diff2), LY_SUCCESS);
free(st->xml1);
lyd_print_mem(&st->xml1, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
free(st->xml2);
@@ -565,7 +565,7 @@
/* TODO ordering assert_string_equal(st->xml1, st->xml2); */
/* merge */
- assert_int_equal(lyd_diff_merge(st->diff2, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_merge_all(st->diff2, &st->diff1), LY_SUCCESS);
free(st->xml);
lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -616,7 +616,7 @@
assert_non_null(st->third);
/* diff1 */
- assert_int_equal(lyd_diff(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
assert_non_null(st->diff1);
lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -627,13 +627,13 @@
"</df>"
);
- assert_int_equal(lyd_diff_apply(&st->first, st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
lyd_print_mem(&st->xml1, st->first, LYD_XML, LYD_PRINT_WITHSIBLINGS);
lyd_print_mem(&st->xml2, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
assert_string_equal(st->xml1, st->xml2);
/* diff2 */
- assert_int_equal(lyd_diff(st->second, st->third, 0, &st->diff2), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(st->second, st->third, 0, &st->diff2), LY_SUCCESS);
assert_non_null(st->diff2);
free(st->xml);
@@ -645,7 +645,7 @@
"</df>"
);
- assert_int_equal(lyd_diff_apply(&st->second, st->diff2), LY_SUCCESS);
+ assert_int_equal(lyd_diff_apply_all(&st->second, st->diff2), LY_SUCCESS);
free(st->xml1);
lyd_print_mem(&st->xml1, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
free(st->xml2);
@@ -653,7 +653,7 @@
assert_string_equal(st->xml1, st->xml2);
/* merge */
- assert_int_equal(lyd_diff_merge(st->diff2, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_merge_all(st->diff2, &st->diff1), LY_SUCCESS);
free(st->xml);
lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -700,7 +700,7 @@
assert_non_null(st->third);
/* diff1 */
- assert_int_equal(lyd_diff(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
assert_non_null(st->diff1);
lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -710,13 +710,13 @@
"</df>"
);
- assert_int_equal(lyd_diff_apply(&st->first, st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
lyd_print_mem(&st->xml1, st->first, LYD_XML, LYD_PRINT_WITHSIBLINGS);
lyd_print_mem(&st->xml2, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
assert_string_equal(st->xml1, st->xml2);
/* diff2 */
- assert_int_equal(lyd_diff(st->second, st->third, 0, &st->diff2), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(st->second, st->third, 0, &st->diff2), LY_SUCCESS);
assert_non_null(st->diff2);
free(st->xml);
@@ -728,7 +728,7 @@
"</df>"
);
- assert_int_equal(lyd_diff_apply(&st->second, st->diff2), LY_SUCCESS);
+ assert_int_equal(lyd_diff_apply_all(&st->second, st->diff2), LY_SUCCESS);
free(st->xml1);
lyd_print_mem(&st->xml1, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
free(st->xml2);
@@ -736,7 +736,7 @@
assert_string_equal(st->xml1, st->xml2);
/* merge */
- assert_int_equal(lyd_diff_merge(st->diff2, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_merge_all(st->diff2, &st->diff1), LY_SUCCESS);
free(st->xml);
lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -775,7 +775,7 @@
assert_non_null(st->third);
/* diff1 */
- assert_int_equal(lyd_diff(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
assert_non_null(st->diff1);
lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -786,13 +786,13 @@
"</df>"
);
- assert_int_equal(lyd_diff_apply(&st->first, st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
lyd_print_mem(&st->xml1, st->first, LYD_XML, LYD_PRINT_WITHSIBLINGS);
lyd_print_mem(&st->xml2, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
assert_string_equal(st->xml1, st->xml2);
/* diff2 */
- assert_int_equal(lyd_diff(st->second, st->third, 0, &st->diff2), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(st->second, st->third, 0, &st->diff2), LY_SUCCESS);
assert_non_null(st->diff2);
free(st->xml);
@@ -804,7 +804,7 @@
"</df>"
);
- assert_int_equal(lyd_diff_apply(&st->second, st->diff2), LY_SUCCESS);
+ assert_int_equal(lyd_diff_apply_all(&st->second, st->diff2), LY_SUCCESS);
free(st->xml1);
lyd_print_mem(&st->xml1, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
free(st->xml2);
@@ -812,7 +812,7 @@
assert_string_equal(st->xml1, st->xml2);
/* merge */
- assert_int_equal(lyd_diff_merge(st->diff2, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_merge_all(st->diff2, &st->diff1), LY_SUCCESS);
free(st->xml);
lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -850,7 +850,7 @@
assert_non_null(st->third);
/* diff1 */
- assert_int_equal(lyd_diff(st->first, st->second, LYD_DIFF_WITHDEFAULTS, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(st->first, st->second, LYD_DIFF_DEFAULTS, &st->diff1), LY_SUCCESS);
assert_non_null(st->diff1);
lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL);
@@ -864,14 +864,14 @@
"</df>"
);
- assert_int_equal(lyd_diff_apply(&st->first, st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
lyd_print_mem(&st->xml1, st->first, LYD_XML, LYD_PRINT_WITHSIBLINGS);
lyd_print_mem(&st->xml2, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
/* TODO just an ordering problem
assert_string_equal(st->xml1, st->xml2);*/
/* diff2 */
- assert_int_equal(lyd_diff(st->second, st->third, LYD_DIFF_WITHDEFAULTS, &st->diff2), LY_SUCCESS);
+ assert_int_equal(lyd_diff_siblings(st->second, st->third, LYD_DIFF_DEFAULTS, &st->diff2), LY_SUCCESS);
assert_non_null(st->diff2);
free(st->xml);
@@ -883,7 +883,7 @@
"</df>"
);
- assert_int_equal(lyd_diff_apply(&st->second, st->diff2), LY_SUCCESS);
+ assert_int_equal(lyd_diff_apply_all(&st->second, st->diff2), LY_SUCCESS);
free(st->xml1);
lyd_print_mem(&st->xml1, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
free(st->xml2);
@@ -891,7 +891,7 @@
/* TODO ordering assert_string_equal(st->xml1, st->xml2); */
/* merge */
- assert_int_equal(lyd_diff_merge(st->diff2, &st->diff1), LY_SUCCESS);
+ assert_int_equal(lyd_diff_merge_all(st->diff2, &st->diff1), LY_SUCCESS);
free(st->xml);
lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL);
diff --git a/tests/utests/data/test_lyb.c b/tests/utests/data/test_lyb.c
index a46f3d6..ee29809 100644
--- a/tests/utests/data/test_lyb.c
+++ b/tests/utests/data/test_lyb.c
@@ -304,7 +304,7 @@
"<leaf3 xmlns:or=\"urn:ietf:params:xml:ns:yang:ietf-origin\" or:origin=\"or:system\">125</leaf3>"
"</cont>";
- assert_non_null(lys_parse_mem(st->ctx, origin_yang, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, origin_yang, LYS_IN_YANG, NULL));
lys_set_implemented(ly_ctx_get_module_latest(st->ctx, "ietf-origin"));
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, data_xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->dt1));
@@ -514,8 +514,8 @@
"<iref>random-identity</iref>"
"</random>";
- assert_non_null(lys_parse_mem(st->ctx, links_yang, LYS_IN_YANG));
- assert_non_null(lys_parse_mem(st->ctx, statements_yang, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, links_yang, LYS_IN_YANG, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, statements_yang, LYS_IN_YANG, NULL));
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, data_xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->dt1));
assert_ptr_not_equal(st->dt1, NULL);
diff --git a/tests/utests/data/test_merge.c b/tests/utests/data/test_merge.c
index 4ad6c9f..2ded52e 100644
--- a/tests/utests/data/test_merge.c
+++ b/tests/utests/data/test_merge.c
@@ -242,7 +242,7 @@
assert_int_equal(LY_SUCCESS, lyd_parse_data(st->ctx, in, LYD_XML, LYD_PARSE_ONLY, 0, &st->source));
assert_non_null(st->source);
- assert_int_equal(LY_SUCCESS, lyd_merge(&st->target, st->source, LYD_MERGE_DESTRUCT));
+ assert_int_equal(LY_SUCCESS, lyd_merge_siblings(&st->target, st->source, LYD_MERGE_DESTRUCT));
st->source = NULL;
}
@@ -272,7 +272,7 @@
const char *result = "<A xmlns=\"urn:x\"><f1>aa</f1><B><f2>bb</f2></B></A>";
char *printed = NULL;
- assert_non_null(lys_parse_mem(st->ctx, sch, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, sch, LYS_IN_YANG, NULL));
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, src, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->source));
assert_non_null(st->source);
@@ -281,8 +281,8 @@
assert_non_null(st->target);
/* merge them */
- assert_int_equal(lyd_merge(&st->target, st->source, 0), LY_SUCCESS);
- assert_int_equal(lyd_validate(&st->target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+ assert_int_equal(lyd_merge_siblings(&st->target, st->source, 0), LY_SUCCESS);
+ assert_int_equal(lyd_validate_all(&st->target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
/* check the result */
lyd_print_mem(&printed, st->target, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -314,7 +314,7 @@
const char *result = "<A xmlns=\"aa:A\"><B><f2>aaa</f2></B><C><f3>bbb</f3></C></A>";
char *printed = NULL;
- assert_non_null(lys_parse_mem(st->ctx, sch, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, sch, LYS_IN_YANG, NULL));
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, src, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->source));
assert_non_null(st->source);
@@ -323,8 +323,8 @@
assert_non_null(st->target);
/* merge them */
- assert_int_equal(lyd_merge(&st->target, st->source, 0), LY_SUCCESS);
- assert_int_equal(lyd_validate(&st->target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+ assert_int_equal(lyd_merge_siblings(&st->target, st->source, 0), LY_SUCCESS);
+ assert_int_equal(lyd_validate_all(&st->target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
/* check the result */
lyd_print_mem(&printed, st->target, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -384,7 +384,7 @@
"</inner1>";
char *printed = NULL;
- assert_non_null(lys_parse_mem(st->ctx, sch, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, sch, LYS_IN_YANG, NULL));
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, src, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->source));
assert_non_null(st->source);
@@ -393,8 +393,8 @@
assert_non_null(st->target);
/* merge them */
- assert_int_equal(lyd_merge(&st->target, st->source, LYD_MERGE_EXPLICIT), LY_SUCCESS);
- assert_int_equal(lyd_validate(&st->target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+ assert_int_equal(lyd_merge_siblings(&st->target, st->source, 0), LY_SUCCESS);
+ assert_int_equal(lyd_validate_all(&st->target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
/* check the result */
lyd_print_mem(&printed, st->target, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -463,7 +463,7 @@
"</inner1>";
char *printed = NULL;
- assert_non_null(lys_parse_mem(st->ctx, sch, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, sch, LYS_IN_YANG, NULL));
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, src, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->source));
assert_non_null(st->source);
@@ -472,8 +472,8 @@
assert_non_null(st->target);
/* merge them */
- assert_int_equal(lyd_merge(&st->target, st->source, LYD_MERGE_EXPLICIT), LY_SUCCESS);
- assert_int_equal(lyd_validate(&st->target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+ assert_int_equal(lyd_merge_siblings(&st->target, st->source, 0), LY_SUCCESS);
+ assert_int_equal(lyd_validate_all(&st->target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
/* check the result */
lyd_print_mem(&printed, st->target, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -521,7 +521,7 @@
"</cont>";
char *printed = NULL;
- assert_non_null(lys_parse_mem(st->ctx, sch, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, sch, LYS_IN_YANG, NULL));
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, src, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->source));
assert_non_null(st->source);
@@ -530,8 +530,8 @@
assert_non_null(st->target);
/* merge them */
- assert_int_equal(lyd_merge(&st->target, st->source, 0), LY_SUCCESS);
- assert_int_equal(lyd_validate(&st->target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+ assert_int_equal(lyd_merge_siblings(&st->target, st->source, 0), LY_SUCCESS);
+ assert_int_equal(lyd_validate_all(&st->target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
/* check the result */
lyd_print_mem(&printed, st->target, LYD_XML, LYD_PRINT_WITHSIBLINGS);
@@ -543,7 +543,6 @@
test_dflt(void **state)
{
struct state *st = (*state);
- struct lyd_node *tmp;
const char *sch =
"module merge-dflt {"
"namespace \"urn:merge-dflt\";"
@@ -562,19 +561,16 @@
"}"
"}";
- assert_non_null(lys_parse_mem(st->ctx, sch, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, sch, LYS_IN_YANG, NULL));
- st->target = lyd_new_path(NULL, st->ctx, "/merge-dflt:top/c", "c_dflt", 0);
- assert_non_null(st->target);
- assert_int_equal(lyd_validate(&(st->target), NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+ assert_int_equal(lyd_new_path(NULL, st->ctx, "/merge-dflt:top/c", "c_dflt", 0, &st->target), LY_SUCCESS);
+ assert_int_equal(lyd_validate_all(&(st->target), NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
- st->source = lyd_new_path(NULL, st->ctx, "/merge-dflt:top/a", "a_val", 0);
- assert_non_null(st->source);
- tmp = lyd_new_path(st->source, st->ctx, "/merge-dflt:top/b", "b_val", 0);
- assert_non_null(tmp);
- assert_int_equal(lyd_validate(&(st->source), NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+ assert_int_equal(lyd_new_path(NULL, st->ctx, "/merge-dflt:top/a", "a_val", 0, &st->source), LY_SUCCESS);
+ assert_int_equal(lyd_new_path(st->source, st->ctx, "/merge-dflt:top/b", "b_val", 0, NULL), LY_SUCCESS);
+ assert_int_equal(lyd_validate_all(&(st->source), NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
- assert_int_equal(lyd_merge(&st->target, st->source, LYD_MERGE_DESTRUCT), LY_SUCCESS);
+ assert_int_equal(lyd_merge_siblings(&st->target, st->source, LYD_MERGE_DESTRUCT | LYD_MERGE_DEFAULTS), LY_SUCCESS);
st->source = NULL;
/* c should be replaced and now be default */
@@ -585,7 +581,6 @@
test_dflt2(void **state)
{
struct state *st = (*state);
- struct lyd_node *tmp;
const char *sch =
"module merge-dflt {"
"namespace \"urn:merge-dflt\";"
@@ -604,19 +599,16 @@
"}"
"}";
- assert_non_null(lys_parse_mem(st->ctx, sch, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, sch, LYS_IN_YANG, NULL));
- st->target = lyd_new_path(NULL, st->ctx, "/merge-dflt:top/c", "c_dflt", 0);
- assert_non_null(st->target);
- assert_int_equal(lyd_validate(&(st->target), NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+ assert_int_equal(lyd_new_path(NULL, st->ctx, "/merge-dflt:top/c", "c_dflt", 0, &st->target), LY_SUCCESS);
+ assert_int_equal(lyd_validate_all(&(st->target), NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
- st->source = lyd_new_path(NULL, st->ctx, "/merge-dflt:top/a", "a_val", 0);
- assert_non_null(st->source);
- tmp = lyd_new_path(st->source, st->ctx, "/merge-dflt:top/b", "b_val", 0);
- assert_non_null(tmp);
- assert_int_equal(lyd_validate(&(st->source), NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+ assert_int_equal(lyd_new_path(NULL, st->ctx, "/merge-dflt:top/a", "a_val", 0, &st->source), LY_SUCCESS);
+ assert_int_equal(lyd_new_path(st->source, st->ctx, "/merge-dflt:top/b", "b_val", 0, NULL), LY_SUCCESS);
+ assert_int_equal(lyd_validate_all(&(st->source), NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
- assert_int_equal(lyd_merge(&st->target, st->source, LYD_MERGE_EXPLICIT), LY_SUCCESS);
+ assert_int_equal(lyd_merge_siblings(&st->target, st->source, 0), LY_SUCCESS);
/* c should not be replaced, so c remains not default */
assert_false(lyd_node_children(st->target, 0)->flags & LYD_DEFAULT);
@@ -643,7 +635,7 @@
"<l xmlns=\"urn:x\"><n>c</n><r>a</r></l>";
char *prt = NULL;
- assert_non_null(lys_parse_mem(st->ctx, sch, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, sch, LYS_IN_YANG, NULL));
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, src, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->source));
assert_non_null(st->source);
@@ -651,8 +643,7 @@
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, trg, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->target));
assert_non_null(st->target);
- assert_int_equal(lyd_merge(&st->target, st->source, LYD_MERGE_DESTRUCT), LY_SUCCESS);
- st->source = NULL;
+ assert_int_equal(lyd_merge_siblings(&st->target, st->source, 0), LY_SUCCESS);
lyd_print_mem(&prt, st->target, LYD_XML, LYD_PRINT_WITHSIBLINGS);
assert_string_equal(prt, res);
diff --git a/tests/utests/data/test_new.c b/tests/utests/data/test_new.c
index ee42a0b..c9c32f8 100644
--- a/tests/utests/data/test_new.c
+++ b/tests/utests/data/test_new.c
@@ -65,7 +65,7 @@
#endif
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
- assert_non_null(lys_parse_mem(ctx, schema_a, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_a, LYS_IN_YANG, NULL));
return 0;
}
@@ -112,93 +112,72 @@
assert_non_null(mod);
/* list */
- node = lyd_new_list(NULL, mod, "l1", "val_a", "val_b");
- assert_non_null(node);
+ assert_int_equal(lyd_new_list(NULL, mod, "l1", &node, "val_a", "val_b"), LY_SUCCESS);
lyd_free_tree(node);
- node = lyd_new_list2(NULL, mod, "l1", "[]");
- assert_null(node);
+ assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[]", &node), LY_EVALID);
logbuf_assert("Unexpected XPath token ] (]).");
- node = lyd_new_list2(NULL, mod, "l1", "[key1='a'][key2='b']");
- assert_null(node);
+ assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[key1='a'][key2='b']", NULL), LY_ENOTFOUND);
logbuf_assert("Not found node \"key1\" in path.");
- node = lyd_new_list2(NULL, mod, "l1", "[a='a'][b='b'][c='c']");
- assert_null(node);
+ assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[a='a'][b='b'][c='c']", NULL), LY_EVALID);
logbuf_assert("Key expected instead of leaf \"c\" in path. /a:l1/c");
- node = lyd_new_list2(NULL, mod, "c", "[a='a'][b='b']");
- assert_null(node);
+ assert_int_equal(lyd_new_list2(NULL, mod, "c", "[a='a'][b='b']", NULL), LY_ENOTFOUND);
logbuf_assert("List node \"c\" not found.");
- node = lyd_new_list2(NULL, mod, "l1", "[a='a'][b='b']");
- assert_non_null(node);
+ assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[a='a'][b='b']", &node), LY_SUCCESS);
lyd_free_tree(node);
- node = lyd_new_list2(NULL, mod, "l1", "[a=''][b='']");
- assert_non_null(node);
+ assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[a=''][b='']", &node), LY_SUCCESS);
lyd_free_tree(node);
- node = lyd_new_list2(NULL, mod, "l1", "[a:a='a'][a:b='b']");
- assert_non_null(node);
+ assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[a:a='a'][a:b='b']", &node), LY_SUCCESS);
lyd_free_tree(node);
- node = lyd_new_list2(NULL, mod, "l1", "[a= 'a']\n[b =\t'b']");
- assert_non_null(node);
+ assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[a= 'a']\n[b =\t'b']", &node), LY_SUCCESS);
lyd_free_tree(node);
/* leaf */
- node = lyd_new_term(NULL, mod, "foo", "[a='a'][b='b'][c='c']");
- assert_null(node);
+ assert_int_equal(lyd_new_term(NULL, mod, "foo", "[a='a'][b='b'][c='c']", NULL), LY_EVALID);
logbuf_assert("Invalid uint16 value \"[a='a'][b='b'][c='c']\". /a:foo");
- node = lyd_new_term(NULL, mod, "c", "value");
- assert_null(node);
+ assert_int_equal(lyd_new_term(NULL, mod, "c", "value", NULL), LY_ENOTFOUND);
logbuf_assert("Term node \"c\" not found.");
- node = lyd_new_term(NULL, mod, "foo", "256");
- assert_non_null(node);
+ assert_int_equal(lyd_new_term(NULL, mod, "foo", "256", &node), LY_SUCCESS);
lyd_free_tree(node);
/* leaf-list */
- node = lyd_new_term(NULL, mod, "ll", "ahoy");
- assert_non_null(node);
+ assert_int_equal(lyd_new_term(NULL, mod, "ll", "ahoy", &node), LY_SUCCESS);
lyd_free_tree(node);
/* container */
- node = lyd_new_inner(NULL, mod, "c");
- assert_non_null(node);
+ assert_int_equal(lyd_new_inner(NULL, mod, "c", &node), LY_SUCCESS);
lyd_free_tree(node);
- node = lyd_new_inner(NULL, mod, "l1");
- assert_null(node);
+ assert_int_equal(lyd_new_inner(NULL, mod, "l1", NULL), LY_ENOTFOUND);
logbuf_assert("Inner node (and not a list) \"l1\" not found.");
- node = lyd_new_inner(NULL, mod, "l2");
- assert_null(node);
+ assert_int_equal(lyd_new_inner(NULL, mod, "l2", NULL), LY_ENOTFOUND);
logbuf_assert("Inner node (and not a list) \"l2\" not found.");
/* anydata */
- node = lyd_new_any(NULL, mod, "any", "some-value", LYD_ANYDATA_STRING);
- assert_non_null(node);
+ assert_int_equal(lyd_new_any(NULL, mod, "any", "some-value", LYD_ANYDATA_STRING, &node), LY_SUCCESS);
lyd_free_tree(node);
/* key-less list */
- node = lyd_new_list2(NULL, mod, "l2", "[a='a'][b='b']");
- assert_null(node);
+ assert_int_equal(lyd_new_list2(NULL, mod, "l2", "[a='a'][b='b']", NULL), LY_EVALID);
logbuf_assert("List predicate defined for keyless list \"l2\" in path.");
- node = lyd_new_list2(NULL, mod, "l2", "");
- assert_non_null(node);
+ assert_int_equal(lyd_new_list2(NULL, mod, "l2", "", &node), LY_SUCCESS);
lyd_free_tree(node);
- node = lyd_new_list2(NULL, mod, "l2", NULL);
- assert_non_null(node);
+ assert_int_equal(lyd_new_list2(NULL, mod, "l2", NULL, &node), LY_SUCCESS);
lyd_free_tree(node);
- node = lyd_new_list(NULL, mod, "l2");
- assert_non_null(node);
+ assert_int_equal(lyd_new_list(NULL, mod, "l2", &node), LY_SUCCESS);
lyd_free_tree(node);
*state = NULL;
@@ -212,16 +191,14 @@
struct lyd_node *root, *node;
struct lyd_node_opaq *opq;
- root = lyd_new_opaq(NULL, ctx, "node1", NULL, "my-module");
- assert_non_null(root);
+ assert_int_equal(lyd_new_opaq(NULL, ctx, "node1", NULL, "my-module", &root), LY_SUCCESS);
assert_null(root->schema);
opq = (struct lyd_node_opaq *)root;
assert_string_equal(opq->name, "node1");
assert_string_equal(opq->value, "");
assert_string_equal(opq->prefix.ns, "my-module");
- node = lyd_new_opaq(root, NULL, "node2", "value", "my-module2");
- assert_non_null(node);
+ assert_int_equal(lyd_new_opaq(root, NULL, "node2", "value", "my-module2", &node), LY_SUCCESS);
assert_null(node->schema);
opq = (struct lyd_node_opaq *)node;
assert_string_equal(opq->name, "node2");
diff --git a/tests/utests/data/test_parser_xml.c b/tests/utests/data/test_parser_xml.c
index 79c85f5..06510da 100644
--- a/tests/utests/data/test_parser_xml.c
+++ b/tests/utests/data/test_parser_xml.c
@@ -84,7 +84,7 @@
assert_non_null(ly_ctx_load_module(ctx, "ietf-netconf-with-defaults", "2011-06-01"));
assert_non_null((mod = ly_ctx_load_module(ctx, "ietf-netconf", "2011-06-01")));
assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "writable-running"));
- assert_non_null(lys_parse_mem(ctx, schema_a, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_a, LYS_IN_YANG, NULL));
return 0;
}
@@ -193,7 +193,7 @@
assert_int_equal(LYS_ANYDATA, tree->schema->nodetype);
assert_string_equal("any", tree->schema->name);
- lyd_print(out, tree, LYD_XML, 0);
+ lyd_print_tree(out, tree, LYD_XML, 0);
assert_string_equal(str,
"<any xmlns=\"urn:tests:a\">"
"<element1>"
@@ -343,7 +343,7 @@
assert_string_equal(((struct lyd_node_opaq *)tree)->name, "foo3");
assert_string_equal(((struct lyd_node_opaq *)tree)->value, "");
- lyd_print(out, tree, LYD_XML, 0);
+ lyd_print_tree(out, tree, LYD_XML, 0);
assert_string_equal(str, "<foo3 xmlns=\"urn:tests:a\"/>");
ly_out_reset(out);
lyd_free_all(tree);
@@ -361,7 +361,7 @@
assert_string_equal(((struct lyd_node_opaq *)tree)->name, "l1");
assert_string_equal(((struct lyd_node_opaq *)tree)->value, "");
- lyd_print(out, tree, LYD_XML, 0);
+ lyd_print_tree(out, tree, LYD_XML, 0);
assert_string_equal(str, data);
ly_out_reset(out);
lyd_free_all(tree);
@@ -379,7 +379,7 @@
assert_string_equal(((struct lyd_node_opaq *)tree)->name, "l1");
assert_string_equal(((struct lyd_node_opaq *)tree)->value, "");
- lyd_print(out, tree, LYD_XML, 0);
+ lyd_print_tree(out, tree, LYD_XML, 0);
assert_string_equal(str, data);
ly_out_reset(out);
lyd_free_all(tree);
@@ -453,7 +453,7 @@
assert_null(node->schema);
assert_string_equal(((struct lyd_node_opaq *)node)->name, "z");
- lyd_print(out, tree, LYD_XML, 0);
+ lyd_print_tree(out, tree, LYD_XML, 0);
assert_string_equal(str,
"<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" msgid=\"25\" custom-attr=\"val\">"
"<edit-config>"
@@ -523,7 +523,7 @@
assert_string_equal(((struct lyd_node_opaq *)node)->name, "action");
assert_null(((struct lyd_node_opaq *)node)->attr);
- lyd_print(out, tree, LYD_XML, 0);
+ lyd_print_tree(out, tree, LYD_XML, 0);
assert_string_equal(str,
"<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" msgid=\"25\" custom-attr=\"val\">"
"<action xmlns=\"urn:ietf:params:xml:ns:yang:1\">"
@@ -588,7 +588,7 @@
assert_non_null(node->schema);
assert_string_equal(node->schema->name, "c");
- lyd_print(out, tree, LYD_XML, 0);
+ lyd_print_tree(out, tree, LYD_XML, 0);
assert_string_equal(str, data);
ly_out_reset(out);
lyd_free_all(tree);
@@ -605,7 +605,7 @@
assert_non_null(tree);
assert_ptr_equal(ntf, tree);
- lyd_print(out, tree, LYD_XML, 0);
+ lyd_print_tree(out, tree, LYD_XML, 0);
assert_string_equal(str, data);
ly_out_reset(out);
lyd_free_all(tree);
@@ -667,7 +667,7 @@
assert_string_equal(node->schema->name, "c");
/* TODO print only rpc-reply node and then output subtree */
- lyd_print(out, lyd_node_children(op, 0), LYD_XML, 0);
+ lyd_print_tree(out, lyd_node_children(op, 0), LYD_XML, 0);
assert_string_equal(str,
"<al xmlns=\"urn:tests:a\">25</al>");
ly_out_reset(out);
diff --git a/tests/utests/data/test_printer_xml.c b/tests/utests/data/test_printer_xml.c
index 7f44fb4..f6d8089 100644
--- a/tests/utests/data/test_printer_xml.c
+++ b/tests/utests/data/test_printer_xml.c
@@ -132,9 +132,9 @@
assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &s->ctx));
assert_non_null(ly_ctx_load_module(s->ctx, "ietf-netconf-with-defaults", "2011-06-01"));
- assert_non_null(lys_parse_mem(s->ctx, schema_a, LYS_IN_YANG));
- assert_non_null(lys_parse_mem(s->ctx, schema_b, LYS_IN_YANG));
- assert_non_null(lys_parse_mem(s->ctx, schema_c, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, schema_a, LYS_IN_YANG, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, schema_b, LYS_IN_YANG, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, schema_c, LYS_IN_YANG, NULL));
*state = s;
@@ -186,7 +186,7 @@
data = "<int8 xmlns=\"urn:tests:types\">\n 15 \t\n </int8>";
result = "<int8 xmlns=\"urn:tests:types\">15</int8>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
- assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, 0));
+ assert_int_equal(LY_SUCCESS, lyd_print_tree(out, tree, LYD_XML, 0));
assert_int_equal(strlen(printed), ly_out_printed(out));
assert_string_equal(printed, result);
lyd_free_all(tree);
@@ -209,7 +209,7 @@
data = "<any xmlns=\"urn:tests:types\"><somexml xmlns:x=\"url:x\" xmlns=\"example.com\"><x:x/></somexml></any>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
- assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, 0));
+ assert_int_equal(LY_SUCCESS, lyd_print_tree(out, tree, LYD_XML, 0));
assert_int_equal(strlen(printed), ly_out_printed(out));
/* canonized */
data = "<any xmlns=\"urn:tests:types\"><somexml xmlns=\"example.com\"><x xmlns=\"url:x\"/></somexml></any>";
@@ -219,7 +219,7 @@
data = "<any xmlns=\"urn:tests:types\"/>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
- assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, 0));
+ assert_int_equal(LY_SUCCESS, lyd_print_tree(out, tree, LYD_XML, 0));
assert_int_equal(strlen(printed), ly_out_printed(out));
assert_string_equal(printed, data);
ly_out_reset(out);
@@ -241,7 +241,7 @@
assert_string_equal(((struct lyd_node_any *)tree)->value.tree->schema->name, "cont");
/* but its children not */
assert_null(((struct lyd_node_inner *)(((struct lyd_node_any *)tree)->value.tree))->child->schema);
- assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, 0));
+ assert_int_equal(LY_SUCCESS, lyd_print_tree(out, tree, LYD_XML, 0));
assert_int_equal(strlen(printed), ly_out_printed(out));
/* canonized */
data =
@@ -279,18 +279,18 @@
data = "<c xmlns=\"urn:defaults\">aa</c>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
- assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_TRIM));
+ assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_TRIM));
assert_int_equal(strlen(printed), ly_out_printed(out));
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL));
+ assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_ALL));
assert_int_equal(strlen(printed), ly_out_printed(out));
data = "<c xmlns=\"urn:defaults\">aa</c><a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a>";
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL_TAG));
+ assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_ALL_TAG));
assert_int_equal(strlen(printed), ly_out_printed(out));
data = "<c xmlns=\"urn:defaults\">aa</c>"
"<a xmlns=\"urn:defaults\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""
@@ -298,7 +298,7 @@
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG));
+ assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG));
assert_int_equal(strlen(printed), ly_out_printed(out));
data = "<c xmlns=\"urn:defaults\">aa</c>"
"<a xmlns=\"urn:defaults\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""
@@ -312,22 +312,22 @@
data = "<c xmlns=\"urn:defaults\">aa</c><a xmlns=\"urn:defaults\">/d:b</a>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
- assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_TRIM));
+ assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_TRIM));
assert_int_equal(strlen(printed), ly_out_printed(out));
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL));
+ assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_ALL));
assert_int_equal(strlen(printed), ly_out_printed(out));
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL_TAG));
+ assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_ALL_TAG));
assert_int_equal(strlen(printed), ly_out_printed(out));
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG));
+ assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG));
assert_int_equal(strlen(printed), ly_out_printed(out));
assert_string_equal(printed, data);
ly_out_reset(out);
@@ -338,19 +338,19 @@
data = "<c xmlns=\"urn:defaults\">aa</c><a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a><b xmlns=\"urn:defaults\">val</b>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
- assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_TRIM));
+ assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_TRIM));
assert_int_equal(strlen(printed), ly_out_printed(out));
data = "<c xmlns=\"urn:defaults\">aa</c><b xmlns=\"urn:defaults\">val</b>";
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL));
+ assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_ALL));
assert_int_equal(strlen(printed), ly_out_printed(out));
data = "<c xmlns=\"urn:defaults\">aa</c><a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a><b xmlns=\"urn:defaults\">val</b>";
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL_TAG));
+ assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_ALL_TAG));
assert_int_equal(strlen(printed), ly_out_printed(out));
data = "<c xmlns=\"urn:defaults\">aa</c>"
"<a xmlns=\"urn:defaults\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""
@@ -359,7 +359,7 @@
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG));
+ assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG));
assert_int_equal(strlen(printed), ly_out_printed(out));
data = "<c xmlns=\"urn:defaults\">aa</c><a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a><b xmlns=\"urn:defaults\">val</b>";
assert_string_equal(printed, data);
@@ -393,13 +393,13 @@
reply = "<result xmlns=\"urn:tests:types\">30</result>";
result = "<sum xmlns=\"urn:tests:types\"><result>30</result></sum>";
assert_non_null(tree1 = lyd_parse_mem(s->ctx, request, LYD_XML, LYD_OPT_RPC, NULL));
- assert_true((len = lyd_print(out, tree1, LYD_XML, 0)) >= 0);
+ assert_true((len = lyd_print_tree(out, tree1, LYD_XML, 0)) >= 0);
assert_int_equal(len, strlen(printed));
assert_string_equal(printed, request);
ly_out_reset(out);
assert_non_null(trees = lyd_trees_new(1, tree1));
assert_non_null(tree2 = lyd_parse_mem(s->ctx, reply, LYD_XML, LYD_OPT_RPCREPLY, trees));
- assert_true((len = lyd_print(out, tree2, LYD_XML, 0)) >= 0);
+ assert_true((len = lyd_print_tree(out, tree2, LYD_XML, 0)) >= 0);
assert_int_equal(len, strlen(printed));
assert_string_equal(printed, result);
ly_out_reset(out);
@@ -412,13 +412,13 @@
reply = "";
result = "<sum xmlns=\"urn:tests:types\"/>";
assert_non_null(tree1 = lyd_parse_mem(s->ctx, request, LYD_XML, LYD_OPT_RPC, NULL));
- assert_true((len = lyd_print(out, tree1, LYD_XML, 0)) >= 0);
+ assert_true((len = lyd_print_tree(out, tree1, LYD_XML, 0)) >= 0);
assert_int_equal(len, strlen(printed));
assert_string_equal(printed, request);
ly_out_reset(out);
assert_non_null(trees = lyd_trees_new(1, tree1));
assert_non_null(tree2 = lyd_parse_mem(s->ctx, reply, LYD_XML, LYD_OPT_RPCREPLY, trees));
- assert_true((len = lyd_print(out, tree2, LYD_XML, 0)) >= 0);
+ assert_true((len = lyd_print_tree(out, tree2, LYD_XML, 0)) >= 0);
assert_int_equal(len, strlen(printed));
assert_string_equal(printed, result);
ly_out_reset(out);
@@ -436,13 +436,13 @@
reply = "<b xmlns=\"urn:tests:types\">test-reply</b>";
result = "<cont xmlns=\"urn:tests:types\"><listtarget><id>10</id><test><b>test-reply</b></test></listtarget></cont>";;
assert_non_null(tree1 = lyd_parse_mem(s->ctx, request, LYD_XML, LYD_OPT_RPC, NULL));
- assert_true((len = lyd_print(out, tree1, LYD_XML, 0)) >= 0);
+ assert_true((len = lyd_print_tree(out, tree1, LYD_XML, 0)) >= 0);
assert_int_equal(len, strlen(printed));
assert_string_equal(printed, request);
ly_out_reset(out);
assert_non_null(trees = lyd_trees_new(1, tree1));
assert_non_null(tree2 = lyd_parse_mem(s->ctx, reply, LYD_XML, LYD_OPT_RPCREPLY, trees));
- assert_true((len = lyd_print(out, tree2, LYD_XML, 0)) >= 0);
+ assert_true((len = lyd_print_tree(out, tree2, LYD_XML, 0)) >= 0);
assert_int_equal(len, strlen(printed));
assert_string_equal(printed, result);
ly_out_reset(out);
diff --git a/tests/utests/data/test_tree_data.c b/tests/utests/data/test_tree_data.c
index 31f0488..fbf888a 100644
--- a/tests/utests/data/test_tree_data.c
+++ b/tests/utests/data/test_tree_data.c
@@ -65,7 +65,7 @@
#endif
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
- assert_non_null(lys_parse_mem(ctx, schema_a, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_a, LYS_IN_YANG, NULL));
return 0;
}
@@ -182,7 +182,7 @@
const char *data = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>x</c></l1>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
- assert_non_null(tree2 = lyd_dup(tree1, NULL, LYD_DUP_RECURSIVE));
+ assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1, NULL, LYD_DUP_RECURSIVE, &tree2));
assert_int_equal(LY_SUCCESS, lyd_compare(tree1, tree2, LYD_COMPARE_FULL_RECURSION));
lyd_free_all(tree1);
lyd_free_all(tree2);
@@ -190,7 +190,7 @@
data = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>x</c></l1>";
result = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b></l1>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
- assert_non_null(tree2 = lyd_dup(tree1, NULL, 0));
+ assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1, NULL, 0, &tree2));
lyd_free_all(tree1);
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, result, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
assert_int_equal(LY_SUCCESS, lyd_compare(tree1, tree2, LYD_COMPARE_FULL_RECURSION));
@@ -200,16 +200,16 @@
data = "<l2 xmlns=\"urn:tests:a\"><c><x>a</x></c></l2><l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>";
result = "<l2 xmlns=\"urn:tests:a\"><c><x>a</x></c></l2>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
- assert_non_null(tree2 = lyd_dup(tree1, NULL, LYD_DUP_WITH_SIBLINGS | LYD_DUP_RECURSIVE));
+ assert_int_equal(LY_SUCCESS, lyd_dup_siblings(tree1, NULL, LYD_DUP_RECURSIVE, &tree2));
assert_int_equal(LY_SUCCESS, lyd_compare(tree1, tree2, LYD_COMPARE_FULL_RECURSION));
lyd_free_all(tree2);
- assert_non_null(tree2 = lyd_dup(tree1, NULL, LYD_DUP_RECURSIVE));
+ assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1, NULL, LYD_DUP_RECURSIVE, &tree2));
lyd_free_all(tree1);
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, result, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
assert_int_equal(LY_SUCCESS, lyd_compare(tree1, tree2, LYD_COMPARE_FULL_RECURSION));
lyd_free_all(tree2);
- assert_non_null(tree2 = lyd_dup(tree1, NULL, 0));
+ assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1, NULL, 0, &tree2));
lyd_free_all(tree1);
result = "<l2 xmlns=\"urn:tests:a\"/>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, result, LYD_XML, LYD_PARSE_ONLY, 0, &tree1));
@@ -219,14 +219,15 @@
data = "<any xmlns=\"urn:tests:a\"><c><a>a</a></c></any>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
- assert_non_null(tree2 = lyd_dup(tree1, NULL, 0));
+ assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1, NULL, 0, &tree2));
assert_int_equal(LY_SUCCESS, lyd_compare(tree1, tree2, LYD_COMPARE_FULL_RECURSION));
lyd_free_all(tree1);
lyd_free_all(tree2);
data = "<l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
- assert_non_null(tree2 = lyd_dup(((struct lyd_node_inner*)((struct lyd_node_inner*)tree1)->child)->child, NULL, LYD_DUP_WITH_PARENTS));
+ assert_int_equal(LY_SUCCESS, lyd_dup_single(((struct lyd_node_inner*)((struct lyd_node_inner*)tree1)->child)->child, NULL,
+ LYD_DUP_WITH_PARENTS, &tree2));
assert_string_equal("x", tree2->schema->name);
assert_non_null(tree2->parent);
assert_int_equal(LY_SUCCESS, lyd_compare(tree1, (struct lyd_node*)tree2->parent->parent, LYD_COMPARE_FULL_RECURSION));
@@ -235,7 +236,8 @@
data = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>c</c></l1>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
- assert_non_null(tree2 = lyd_dup(((struct lyd_node_inner*)tree1)->child->prev, NULL, LYD_DUP_WITH_PARENTS));
+ assert_int_equal(LY_SUCCESS, lyd_dup_single(((struct lyd_node_inner*)tree1)->child->prev, NULL,
+ LYD_DUP_WITH_PARENTS, &tree2));
assert_string_equal("c", tree2->schema->name);
assert_non_null(tree2->parent);
assert_int_equal(LY_SUCCESS, lyd_compare(tree1, (struct lyd_node*)tree2->parent, LYD_COMPARE_FULL_RECURSION));
@@ -244,9 +246,9 @@
data = "<l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
- assert_non_null(tree2 = lyd_dup(tree1, NULL, 0));
- assert_non_null(lyd_dup(((struct lyd_node_inner*)((struct lyd_node_inner*)tree1)->child)->child,
- (struct lyd_node_inner*)tree2, LYD_DUP_WITH_PARENTS));
+ assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1, NULL, 0, &tree2));
+ assert_int_equal(LY_SUCCESS, lyd_dup_single(((struct lyd_node_inner*)((struct lyd_node_inner*)tree1)->child)->child,
+ (struct lyd_node_inner*)tree2, LYD_DUP_WITH_PARENTS, NULL));
assert_int_equal(LY_SUCCESS, lyd_compare(tree1, tree2, LYD_COMPARE_FULL_RECURSION));
lyd_free_all(tree1);
lyd_free_all(tree2);
@@ -254,7 +256,8 @@
/* invalid */
data = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>c</c></l1><l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
- assert_null(lyd_dup(((struct lyd_node_inner*)tree1)->child->prev, (struct lyd_node_inner*)tree1->next, LYD_DUP_WITH_PARENTS));
+ assert_int_equal(LY_EINVAL, lyd_dup_single(((struct lyd_node_inner*)tree1)->child->prev,
+ (struct lyd_node_inner*)tree1->next, LYD_DUP_WITH_PARENTS, NULL));
lyd_free_all(tree1);
*state = NULL;
diff --git a/tests/utests/data/test_types.c b/tests/utests/data/test_types.c
index 6d8de5f..6d223dc 100644
--- a/tests/utests/data/test_types.c
+++ b/tests/utests/data/test_types.c
@@ -113,8 +113,8 @@
#endif
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &s->ctx));
- assert_non_null(lys_parse_mem(s->ctx, schema_a, LYS_IN_YANG));
- assert_non_null(lys_parse_mem(s->ctx, schema_b, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, schema_a, LYS_IN_YANG, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, schema_b, LYS_IN_YANG, NULL));
*state = s;
@@ -897,7 +897,7 @@
TEST_DATA("<t:inst-noreq xmlns:t=\"urn:tests:types\">/t:cont/t:listtarget[t:value='x']</t:inst-noreq>", LY_EVALID,
"Invalid instance-identifier \"/t:cont/t:listtarget[t:value='x']\" value - semantic error. /types:inst-noreq");
- TEST_DATA("<t:inst-noreq xmlns:t=\"urn:tests:types\">/t:cont/t:listtarget[t:x='x']</t:inst-noreq>", LY_EVALID,
+ TEST_DATA("<t:inst-noreq xmlns:t=\"urn:tests:types\">/t:cont/t:listtarget[t:x='x']</t:inst-noreq>", LY_ENOTFOUND,
"Invalid instance-identifier \"/t:cont/t:listtarget[t:x='x']\" value - semantic error. /types:inst-noreq");
TEST_DATA("<cont xmlns=\"urn:tests:types\"><listtarget><id>1</id><value>x</value></listtarget></cont>"
"<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:listtarget[.='x']</t:inst>", LY_EVALID,
@@ -990,7 +990,7 @@
"}}}";
/* additional schema */
- assert_non_null(lys_parse_mem(s->ctx, schema, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, schema, LYS_IN_YANG, NULL));
/* valid data */
TEST_DATA("<leaflisttarget xmlns=\"urn:tests:types\">x</leaflisttarget><leaflisttarget xmlns=\"urn:tests:types\">y</leaflisttarget><lref xmlns=\"urn:tests:types\">y</lref>", LY_SUCCESS, "");
diff --git a/tests/utests/data/test_validation.c b/tests/utests/data/test_validation.c
index da68a40..e0c4de8 100644
--- a/tests/utests/data/test_validation.c
+++ b/tests/utests/data/test_validation.c
@@ -419,16 +419,16 @@
assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &ctx));
assert_non_null(ly_ctx_load_module(ctx, "ietf-netconf-with-defaults", "2011-06-01"));
- assert_non_null(lys_parse_mem(ctx, schema_a, LYS_IN_YANG));
- assert_non_null(lys_parse_mem(ctx, schema_b, LYS_IN_YANG));
- assert_non_null(lys_parse_mem(ctx, schema_c, LYS_IN_YANG));
- assert_non_null(lys_parse_mem(ctx, schema_d, LYS_IN_YANG));
- assert_non_null(lys_parse_mem(ctx, schema_e, LYS_IN_YANG));
- assert_non_null(lys_parse_mem(ctx, schema_f, LYS_IN_YANG));
- assert_non_null(lys_parse_mem(ctx, schema_g, LYS_IN_YANG));
- assert_non_null(lys_parse_mem(ctx, schema_h, LYS_IN_YANG));
- assert_non_null(lys_parse_mem(ctx, schema_i, LYS_IN_YANG));
- assert_non_null(lys_parse_mem(ctx, schema_j, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_a, LYS_IN_YANG, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_b, LYS_IN_YANG, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_c, LYS_IN_YANG, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_d, LYS_IN_YANG, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_e, LYS_IN_YANG, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_f, LYS_IN_YANG, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_g, LYS_IN_YANG, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_h, LYS_IN_YANG, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_i, LYS_IN_YANG, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_j, LYS_IN_YANG, NULL));
return 0;
}
@@ -1032,7 +1032,7 @@
assert_non_null(diff);
/* check all defaults exist */
- lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG);
+ lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG);
assert_string_equal(str,
"<ll1 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>"
"<ll1 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>"
@@ -1051,7 +1051,7 @@
ly_out_reset(out);
/* check diff */
- lyd_print(out, diff, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL);
+ lyd_print_all(out, diff, LYD_XML, LYD_PRINT_WD_ALL);
assert_string_equal(str,
"<ll1 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">def1</ll1>"
"<ll1 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">def2</ll1>"
@@ -1072,13 +1072,12 @@
lyd_free_siblings(diff);
/* create another explicit case and validate */
- node = lyd_new_term(NULL, mod, "l", "value");
- assert_non_null(node);
+ assert_int_equal(lyd_new_term(NULL, mod, "l", "value", &node), LY_SUCCESS);
assert_int_equal(lyd_insert_sibling(tree, node), LY_SUCCESS);
- assert_int_equal(lyd_validate(&tree, ctx, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
+ assert_int_equal(lyd_validate_all(&tree, ctx, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
/* check data tree */
- lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG);
+ lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG);
assert_string_equal(str,
"<d xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>"
"<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>"
@@ -1095,7 +1094,7 @@
ly_out_reset(out);
/* check diff */
- lyd_print(out, diff, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL);
+ lyd_print_all(out, diff, LYD_XML, LYD_PRINT_WD_ALL);
assert_string_equal(str,
"<ll1 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">def1</ll1>"
"<ll1 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">def2</ll1>"
@@ -1105,16 +1104,14 @@
lyd_free_siblings(diff);
/* create explicit leaf-list and leaf and validate */
- node = lyd_new_term(NULL, mod, "d", "15");
- assert_non_null(node);
+ assert_int_equal(lyd_new_term(NULL, mod, "d", "15", &node), LY_SUCCESS);
assert_int_equal(lyd_insert_sibling(tree, node), LY_SUCCESS);
- node = lyd_new_term(NULL, mod, "ll2", "dflt2");
- assert_non_null(node);
+ assert_int_equal(lyd_new_term(NULL, mod, "ll2", "dflt2", &node), LY_SUCCESS);
assert_int_equal(lyd_insert_sibling(tree, node), LY_SUCCESS);
- assert_int_equal(lyd_validate(&tree, ctx, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
+ assert_int_equal(lyd_validate_all(&tree, ctx, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
/* check data tree */
- lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG);
+ lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG);
assert_string_equal(str,
"<cont xmlns=\"urn:tests:f\">"
"<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>"
@@ -1130,7 +1127,7 @@
ly_out_reset(out);
/* check diff */
- lyd_print(out, diff, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL);
+ lyd_print_all(out, diff, LYD_XML, LYD_PRINT_WD_ALL);
assert_string_equal(str,
"<d xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">15</d>"
"<ll2 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">dflt1</ll2>"
@@ -1140,14 +1137,13 @@
lyd_free_siblings(diff);
/* create first explicit container, which should become implicit */
- node = lyd_new_inner(NULL, mod, "cont");
- assert_non_null(node);
+ assert_int_equal(lyd_new_inner(NULL, mod, "cont", &node), LY_SUCCESS);
assert_int_equal(lyd_insert_before(tree, node), LY_SUCCESS);
tree = tree->prev;
- assert_int_equal(lyd_validate(&tree, ctx, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
+ assert_int_equal(lyd_validate_all(&tree, ctx, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
/* check data tree */
- lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG);
+ lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG);
assert_string_equal(str,
"<cont xmlns=\"urn:tests:f\">"
"<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>"
@@ -1166,13 +1162,12 @@
assert_null(diff);
/* create second explicit container, which should become implicit, so the first tree node should be removed */
- node = lyd_new_inner(NULL, mod, "cont");
- assert_non_null(node);
+ assert_int_equal(lyd_new_inner(NULL, mod, "cont", &node), LY_SUCCESS);
assert_int_equal(lyd_insert_after(tree, node), LY_SUCCESS);
- assert_int_equal(lyd_validate(&tree, ctx, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
+ assert_int_equal(lyd_validate_all(&tree, ctx, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
/* check data tree */
- lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG);
+ lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG);
assert_string_equal(str,
"<cont xmlns=\"urn:tests:f\">"
"<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>"
@@ -1191,13 +1186,13 @@
assert_null(diff);
/* similar changes for nested defaults */
- assert_non_null(lyd_new_term(tree, NULL, "ll1", "def3"));
- assert_non_null(lyd_new_term(tree, NULL, "d", "5"));
- assert_non_null(lyd_new_term(tree, NULL, "ll2", "non-dflt"));
- assert_int_equal(lyd_validate(&tree, ctx, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
+ assert_int_equal(lyd_new_term(tree, NULL, "ll1", "def3", NULL), LY_SUCCESS);
+ assert_int_equal(lyd_new_term(tree, NULL, "d", "5", NULL), LY_SUCCESS);
+ assert_int_equal(lyd_new_term(tree, NULL, "ll2", "non-dflt", NULL), LY_SUCCESS);
+ assert_int_equal(lyd_validate_all(&tree, ctx, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
/* check data tree */
- lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG);
+ lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG);
assert_string_equal(str,
"<cont xmlns=\"urn:tests:f\">"
"<ll1>def3</ll1>"
@@ -1210,7 +1205,7 @@
ly_out_reset(out);
/* check diff */
- lyd_print(out, diff, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL);
+ lyd_print_all(out, diff, LYD_XML, LYD_PRINT_WD_ALL);
assert_string_equal(str,
"<cont xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">"
"<ll1 yang:operation=\"delete\">def1</ll1>"
@@ -1319,17 +1314,17 @@
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY, 0, &tree));
assert_non_null(tree);
- assert_int_equal(LY_EVALID, lyd_validate(&tree, NULL, LYD_VALIDATE_PRESENT, NULL));
+ assert_int_equal(LY_EVALID, lyd_validate_all(&tree, NULL, LYD_VALIDATE_PRESENT, NULL));
logbuf_assert("Data are disabled by \"cont\" schema node if-feature. /g:cont");
assert_int_equal(lys_feature_enable(mod, "f1"), LY_SUCCESS);
- assert_int_equal(LY_EVALID, lyd_validate(&tree, NULL, LYD_VALIDATE_PRESENT, NULL));
+ assert_int_equal(LY_EVALID, lyd_validate_all(&tree, NULL, LYD_VALIDATE_PRESENT, NULL));
logbuf_assert("Data are disabled by \"b\" schema node if-feature. /g:cont/l");
assert_int_equal(lys_feature_enable(mod, "f2"), LY_SUCCESS);
- assert_int_equal(LY_SUCCESS, lyd_validate(&tree, NULL, LYD_VALIDATE_PRESENT, NULL));
+ assert_int_equal(LY_SUCCESS, lyd_validate_all(&tree, NULL, LYD_VALIDATE_PRESENT, NULL));
lyd_free_siblings(tree);
@@ -1361,7 +1356,7 @@
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY, 0, &tree));
assert_non_null(tree);
- assert_int_equal(LY_EVALID, lyd_validate(&tree, NULL, LYD_VALIDATE_PRESENT | LYD_VALIDATE_NO_STATE, NULL));
+ assert_int_equal(LY_EVALID, lyd_validate_all(&tree, NULL, LYD_VALIDATE_PRESENT | LYD_VALIDATE_NO_STATE, NULL));
logbuf_assert("Invalid state data node \"cont2\" found. /h:cont/cont2");
lyd_free_siblings(tree);
diff --git a/tests/utests/extensions/test_metadata.c b/tests/utests/extensions/test_metadata.c
index e206d22..71cb8ce 100644
--- a/tests/utests/extensions/test_metadata.c
+++ b/tests/utests/extensions/test_metadata.c
@@ -106,7 +106,7 @@
struct state_s *s = (struct state_s*)(*state);
s->func = test_yang;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_ext_instance *e;
struct lyext_metadata *ant;
@@ -121,7 +121,7 @@
" type uint8;"
" units meters;"
"}}";
- assert_non_null(mod = lys_parse_mem(s->ctx, data, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, data, LYS_IN_YANG, &mod));
assert_int_equal(1, LY_ARRAY_COUNT(mod->compiled->exts));
e = &mod->compiled->exts[0];
assert_non_null(ant = (struct lyext_metadata*)e->data);
@@ -132,42 +132,42 @@
data = "module aa {yang-version 1.1; namespace urn:tests:extensions:metadata:aa; prefix aa;"
"import ietf-yang-metadata {prefix md;}"
"md:annotation aa;}";
- assert_null(lys_parse_mem(s->ctx, data, LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
logbuf_assert("Missing mandatory keyword \"type\" as a child of \"md:annotation aa\". /aa:{extension='md:annotation'}/aa");
/* not allowed substatement */
data = "module aa {yang-version 1.1; namespace urn:tests:extensions:metadata:aa; prefix aa;"
"import ietf-yang-metadata {prefix md;}"
"md:annotation aa {default x;}}";
- assert_null(lys_parse_mem(s->ctx, data, LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
logbuf_assert("Invalid keyword \"default\" as a child of \"md:annotation aa\" extension instance. /aa:{extension='md:annotation'}/aa");
/* invalid cardinality of units substatement */
data = "module aa {yang-version 1.1; namespace urn:tests:extensions:metadata:aa; prefix aa;"
"import ietf-yang-metadata {prefix md;}"
"md:annotation aa {type string; units x; units y;}}";
- assert_null(lys_parse_mem(s->ctx, data, LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
logbuf_assert("Duplicate keyword \"units\". /aa:{extension='md:annotation'}/aa");
/* invalid cardinality of status substatement */
data = "module aa {yang-version 1.1; namespace urn:tests:extensions:metadata:aa; prefix aa;"
"import ietf-yang-metadata {prefix md;}"
"md:annotation aa {type string; status current; status obsolete;}}";
- assert_null(lys_parse_mem(s->ctx, data, LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
logbuf_assert("Duplicate keyword \"status\". /aa:{extension='md:annotation'}/aa");
/* invalid cardinality of status substatement */
data = "module aa {yang-version 1.1; namespace urn:tests:extensions:metadata:aa; prefix aa;"
"import ietf-yang-metadata {prefix md;}"
"md:annotation aa {type string; type uint8;}}";
- assert_null(lys_parse_mem(s->ctx, data, LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
logbuf_assert("Duplicate keyword \"type\". /aa:{extension='md:annotation'}/aa");
/* duplication of the same annotation */
data = "module aa {yang-version 1.1; namespace urn:tests:extensions:metadata:aa; prefix aa;"
"import ietf-yang-metadata {prefix md;}"
"md:annotation aa {type string;} md:annotation aa {type uint8;}}";
- assert_null(lys_parse_mem(s->ctx, data, LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
logbuf_assert("Extension plugin \"libyang 2 - metadata, version 1\": "
"Extension md:annotation is instantiated multiple times.) /aa:{extension='md:annotation'}/aa");
@@ -180,7 +180,7 @@
struct state_s *s = (struct state_s*)(*state);
s->func = test_yin;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_ext_instance *e;
struct lyext_metadata *ant;
@@ -196,7 +196,7 @@
" <type name=\"uint8\"/>\n"
" <units name=\"meters\"/>\n"
"</md:annotation></module>";
- assert_non_null(mod = lys_parse_mem(s->ctx, data, LYS_IN_YIN));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, data, LYS_IN_YIN, &mod));
assert_int_equal(1, LY_ARRAY_COUNT(mod->compiled->exts));
e = &mod->compiled->exts[0];
assert_non_null(ant = (struct lyext_metadata*)e->data);
@@ -209,7 +209,7 @@
"<import module=\"ietf-yang-metadata\"><prefix value=\"md\"/></import>\n"
"<md:annotation name=\"aa\"/>\n"
"</module>";
- assert_null(lys_parse_mem(s->ctx, data, LYS_IN_YIN));
+ assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YIN, NULL));
logbuf_assert("Missing mandatory keyword \"type\" as a child of \"md:annotation aa\". /aa:{extension='md:annotation'}/aa");
/* not allowed substatement */
@@ -219,7 +219,7 @@
"<md:annotation name=\"aa\">\n"
" <default value=\"x\"/>\n"
"</md:annotation></module>";
- assert_null(lys_parse_mem(s->ctx, data, LYS_IN_YIN));
+ assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YIN, NULL));
logbuf_assert("Invalid keyword \"default\" as a child of \"md:annotation aa\" extension instance. /aa:{extension='md:annotation'}/aa");
/* invalid cardinality of units substatement */
@@ -231,7 +231,7 @@
" <units name=\"x\"/>\n"
" <units name=\"y\"/>\n"
"</md:annotation></module>";
- assert_null(lys_parse_mem(s->ctx, data, LYS_IN_YIN));
+ assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YIN, NULL));
logbuf_assert("Duplicate keyword \"units\". /aa:{extension='md:annotation'}/aa");
/* invalid cardinality of status substatement */
@@ -243,7 +243,7 @@
" <status value=\"current\"/>\n"
" <status value=\"obsolete\"/>\n"
"</md:annotation></module>";
- assert_null(lys_parse_mem(s->ctx, data, LYS_IN_YIN));
+ assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YIN, NULL));
logbuf_assert("Duplicate keyword \"status\". /aa:{extension='md:annotation'}/aa");
/* invalid cardinality of status substatement */
@@ -254,7 +254,7 @@
" <type name=\"string\"/>\n"
" <type name=\"uint8\"/>\n"
"</md:annotation></module>";
- assert_null(lys_parse_mem(s->ctx, data, LYS_IN_YIN));
+ assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YIN, NULL));
logbuf_assert("Duplicate keyword \"type\". /aa:{extension='md:annotation'}/aa");
/* duplication of the same annotation */
@@ -266,7 +266,7 @@
"</md:annotation><md:annotation name=\"aa\">\n"
" <type name=\"uint8\"/>\n"
"</md:annotation></module>";
- assert_null(lys_parse_mem(s->ctx, data, LYS_IN_YIN));
+ assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YIN, NULL));
logbuf_assert("Extension plugin \"libyang 2 - metadata, version 1\": "
"Extension md:annotation is instantiated multiple times.) /aa:{extension='md:annotation'}/aa");
s->func = NULL;
diff --git a/tests/utests/extensions/test_nacm.c b/tests/utests/extensions/test_nacm.c
index 4e494f8..86b2b80 100644
--- a/tests/utests/extensions/test_nacm.c
+++ b/tests/utests/extensions/test_nacm.c
@@ -108,7 +108,7 @@
struct state_s *s = (struct state_s*)(*state);
s->func = test_deny_all;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_node_container *cont;
struct lysc_node_leaf *leaf;
struct lysc_ext_instance *e;
@@ -119,7 +119,7 @@
"leaf b {type string;}}";
/* valid data */
- assert_non_null(mod = lys_parse_mem(s->ctx, data, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, data, LYS_IN_YANG, &mod));
assert_non_null(cont = (struct lysc_node_container*)mod->compiled->data);
assert_non_null(leaf = (struct lysc_node_leaf*)cont->child);
assert_non_null(e = &cont->exts[0]);
@@ -133,14 +133,14 @@
data = "module aa {yang-version 1.1; namespace urn:tests:extensions:nacm:aa; prefix en;"
"import ietf-netconf-acm {revision-date 2018-02-14; prefix nacm;}"
"nacm:default-deny-all;}";
- assert_null(lys_parse_mem(s->ctx, data, LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
logbuf_assert("Extension plugin \"libyang 2 - NACM, version 1\": "
"Extension nacm:default-deny-all is allowed only in a data nodes, but it is placed in \"module\" statement.) /aa:{extension='nacm:default-deny-all'}");
data = "module aa {yang-version 1.1; namespace urn:tests:extensions:nacm:aa; prefix en;"
"import ietf-netconf-acm {revision-date 2018-02-14; prefix nacm;}"
"leaf l { type string; nacm:default-deny-all; nacm:default-deny-write;}}";
- assert_null(lys_parse_mem(s->ctx, data, LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
logbuf_assert("Extension plugin \"libyang 2 - NACM, version 1\": "
"Extension nacm:default-deny-write is mixed with nacm:default-deny-all.) /aa:l/{extension='nacm:default-deny-write'}");
@@ -153,7 +153,7 @@
struct state_s *s = (struct state_s*)(*state);
s->func = test_deny_write;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_node_container *cont;
struct lysc_node_leaf *leaf;
struct lysc_ext_instance *e;
@@ -164,7 +164,7 @@
"leaf b {type string;}}";
/* valid data */
- assert_non_null(mod = lys_parse_mem(s->ctx, data, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, data, LYS_IN_YANG, &mod));
assert_non_null(cont = (struct lysc_node_container*)mod->compiled->data);
assert_non_null(leaf = (struct lysc_node_leaf*)cont->child);
assert_non_null(e = &cont->exts[0]);
@@ -178,14 +178,14 @@
data = "module aa {yang-version 1.1; namespace urn:tests:extensions:nacm:aa; prefix en;"
"import ietf-netconf-acm {revision-date 2018-02-14; prefix nacm;}"
"notification notif {nacm:default-deny-write;}}";
- assert_null(lys_parse_mem(s->ctx, data, LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
logbuf_assert("Extension plugin \"libyang 2 - NACM, version 1\": "
"Extension nacm:default-deny-write is not allowed in notification statement.) /aa:notif/{extension='nacm:default-deny-write'}");
data = "module aa {yang-version 1.1; namespace urn:tests:extensions:nacm:aa; prefix en;"
"import ietf-netconf-acm {revision-date 2018-02-14; prefix nacm;}"
"leaf l { type string; nacm:default-deny-write; nacm:default-deny-write;}}";
- assert_null(lys_parse_mem(s->ctx, data, LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
logbuf_assert("Extension plugin \"libyang 2 - NACM, version 1\": "
"Extension nacm:default-deny-write is instantiated multiple times.) /aa:l/{extension='nacm:default-deny-write'}");
diff --git a/tests/utests/schema/test_parser_yang.c b/tests/utests/schema/test_parser_yang.c
index ea24966..13e0971 100644
--- a/tests/utests/schema/test_parser_yang.c
+++ b/tests/utests/schema/test_parser_yang.c
@@ -1007,24 +1007,21 @@
logbuf_assert("Prefix \"y\" already used to import \"zzz\" module. Line number 2.");
mod = mod_renew(&ctx);
in.current = "module" SCHEMA_BEGINNING "import zzz {prefix y;}import zzz {prefix z;}}";
- assert_null(lys_parse_mem(ctx.ctx, in.current, LYS_IN_YANG));
- assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx));
+ assert_int_equal(lys_parse_mem(ctx.ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Single revision of the module \"zzz\" referred twice.");
/* include */
store = 1;
ly_ctx_set_module_imp_clb(ctx.ctx, test_imp_clb, "module xxx { namespace urn:xxx; prefix x;}");
in.current = "module" SCHEMA_BEGINNING "include xxx;}";
- assert_null(lys_parse_mem(ctx.ctx, in.current, LYS_IN_YANG));
- assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx));
+ assert_int_equal(lys_parse_mem(ctx.ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Input data contains module in situation when a submodule is expected.");
store = -1;
store = 1;
ly_ctx_set_module_imp_clb(ctx.ctx, test_imp_clb, "submodule xxx {belongs-to wrong-name {prefix w;}}");
in.current = "module" SCHEMA_BEGINNING "include xxx;}";
- assert_null(lys_parse_mem(ctx.ctx, in.current, LYS_IN_YANG));
- assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx));
+ assert_int_equal(lys_parse_mem(ctx.ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Included \"xxx\" submodule from \"name\" belongs-to a different module \"wrong-name\".");
store = -1;
diff --git a/tests/utests/schema/test_printer_yang.c b/tests/utests/schema/test_printer_yang.c
index 6352695..66d3d6b 100644
--- a/tests/utests/schema/test_printer_yang.c
+++ b/tests/utests/schema/test_printer_yang.c
@@ -137,7 +137,7 @@
assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, orig, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, orig, LYS_IN_YANG, &mod));
assert_int_equal(LY_SUCCESS, lys_print(out, mod, LYS_OUT_YANG, 0, 0));
assert_int_equal(strlen(orig), ly_out_printed(out));
assert_string_equal(printed, orig);
@@ -188,7 +188,7 @@
" if-feature \"not f1\";\n"
" }\n"
"}\n";
- assert_non_null(mod = lys_parse_mem(ctx, orig, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, orig, LYS_IN_YANG, &mod));
assert_int_equal(LY_SUCCESS, lys_print(out, mod, LYS_OUT_YANG, 0, 0));
assert_int_equal(strlen(orig), ly_out_printed(out));
assert_string_equal(printed, orig);
@@ -215,7 +215,7 @@
" status obsolete;\n"
" }\n"
"}\n";
- assert_non_null(mod = lys_parse_mem(ctx, orig, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, orig, LYS_IN_YANG, &mod));
assert_int_equal(LY_SUCCESS, lys_print(out, mod, LYS_OUT_YANG, 0, 0));
assert_int_equal(strlen(orig), ly_out_printed(out));
assert_string_equal(printed, orig);
diff --git a/tests/utests/schema/test_printer_yin.c b/tests/utests/schema/test_printer_yin.c
index eda568f..1e06558 100644
--- a/tests/utests/schema/test_printer_yin.c
+++ b/tests/utests/schema/test_printer_yin.c
@@ -586,7 +586,7 @@
assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, orig, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, orig, LYS_IN_YANG, &mod));
assert_int_equal(LY_SUCCESS, lys_print(out, mod, LYS_OUT_YIN, 0, 0));
assert_int_equal(strlen(ori_res), ly_out_printed(out));
assert_string_equal(printed, ori_res);
diff --git a/tests/utests/schema/test_schema.h b/tests/utests/schema/test_schema.h
index d0212fb..866e986 100644
--- a/tests/utests/schema/test_schema.h
+++ b/tests/utests/schema/test_schema.h
@@ -68,14 +68,14 @@
{ \
const char *test_str__; \
TEST_SCHEMA_STR(CTX, RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
- assert_non_null(RESULT = lys_parse_mem(CTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG)); \
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(CTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, &(RESULT))); \
}
#define TEST_SCHEMA_ERR(CTX, RFC7950, YIN, MOD_NAME, CONTENT, ERRMSG) \
{ \
const char *test_str__; \
TEST_SCHEMA_STR(CTX, RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
- assert_null(lys_parse_mem(CTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG)); \
+ assert_int_not_equal(lys_parse_mem(CTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, NULL), LY_SUCCESS); \
logbuf_assert(ERRMSG); \
}
diff --git a/tests/utests/schema/test_schema_common.c b/tests/utests/schema/test_schema_common.c
index ebcdaec..5b75b9e 100644
--- a/tests/utests/schema/test_schema_common.c
+++ b/tests/utests/schema/test_schema_common.c
@@ -33,14 +33,14 @@
*state = test_getnext;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const 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, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "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;}}}"
@@ -50,7 +50,7 @@
"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));
+ "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;
@@ -124,20 +124,20 @@
assert_string_equal("h-output", node->name);
assert_null(node = lys_getnext(node, (const struct lysc_node*)rpc, mod->compiled, LYS_GETNEXT_OUTPUT));
- assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; feature f;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; feature f;"
"leaf a {type string; if-feature f;}"
- "leaf b {type string;}}", LYS_IN_YANG));
+ "leaf b {type string;}}", LYS_IN_YANG, &mod));
assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0));
assert_string_equal("b", node->name);
assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, LYS_GETNEXT_NOSTATECHECK));
assert_string_equal("a", node->name);
- assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:c;prefix c; rpc c;}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "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, LYS_GETNEXT_NOSTATECHECK));
- assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; notification d;}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "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, LYS_GETNEXT_NOSTATECHECK));
@@ -216,61 +216,61 @@
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
str = "module a {namespace urn:a; prefix a; typedef binary {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"binary\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef bits {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"bits\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef boolean {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"boolean\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef decimal64 {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"decimal64\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef empty {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"empty\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef enumeration {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"enumeration\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef int8 {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"int8\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef int16 {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"int16\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef int32 {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"int32\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef int64 {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"int64\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef instance-identifier {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"instance-identifier\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef identityref {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"identityref\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef leafref {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"leafref\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef string {type int8;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"string\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef union {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"union\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef uint8 {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"uint8\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef uint16 {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"uint16\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef uint32 {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"uint32\" of typedef - name collision with a built-in type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef uint64 {type string;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"uint64\" of typedef - name collision with a built-in type. Line number 1.");
str = "module mytypes {namespace urn:types; prefix t; typedef binary_ {type string;} typedef bits_ {type string;} typedef boolean_ {type string;} "
@@ -278,37 +278,37 @@
"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_non_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
str = "module a {namespace urn:a; prefix a; typedef test {type string;} typedef test {type int8;}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"test\" of typedef - name collision with another top-level type. Line number 1.");
str = "module a {namespace urn:a; prefix a; typedef x {type string;} container c {typedef x {type int8;}}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"x\" of typedef - scoped type collide with a top-level type. Line number 1.");
str = "module a {namespace urn:a; prefix a; container c {container d {typedef y {type int8;}} typedef y {type string;}}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"y\" of typedef - name collision with another scoped type. Line number 1.");
str = "module a {namespace urn:a; prefix a; container c {typedef y {type int8;} typedef y {type string;}}}";
- assert_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"y\" of typedef - name collision with sibling type. Line number 1.");
ly_ctx_set_module_imp_clb(ctx, 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_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"x\" of typedef - name collision with another top-level type. Line number 1.");
ly_ctx_set_module_imp_clb(ctx, 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_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"x\" of typedef - scoped type collide with a top-level type. Line number 1.");
ly_ctx_set_module_imp_clb(ctx, 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_null(lys_parse_mem(ctx, str, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
logbuf_assert("Invalid name \"x\" of typedef - scoped type collide with a top-level type. Line number 1.");
*state = NULL;
diff --git a/tests/utests/schema/test_schema_stmts.c b/tests/utests/schema/test_schema_stmts.c
index 9e34742..97ad697 100644
--- a/tests/utests/schema/test_schema_stmts.c
+++ b/tests/utests/schema/test_schema_stmts.c
@@ -33,7 +33,7 @@
*state = test_identity;
struct ly_ctx *ctx;
- struct lys_module *mod, *mod_imp;
+ const struct lys_module *mod, *mod_imp;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
@@ -161,7 +161,7 @@
*state = test_feature;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
const struct lysc_feature *f, *f1;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index 40de6f4..e7c82e7 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -117,7 +117,7 @@
assert_int_equal(LY_EINVAL, lys_compile(&mod, 0));
logbuf_assert("Invalid argument *mod (lys_compile()).");
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
- assert_non_null(mod = lys_parse_mem_module(ctx, in, LYS_IN_YANG, 0, NULL, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 0, NULL, NULL, &mod));
ly_in_free(in, 0);
assert_int_equal(0, mod->implemented);
assert_int_equal(LY_SUCCESS, lys_compile(&mod, 0));
@@ -143,14 +143,14 @@
/* submodules cannot be compiled directly */
str = "submodule test {belongs-to xxx {prefix x;}}";
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
- assert_null(lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL));
+ assert_int_equal(LY_EINVAL, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, NULL));
ly_in_free(in, 0);
logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
/* data definition name collision in top level */
str = "module aa {namespace urn:aa;prefix aa; leaf a {type string;} container a{presence x;}}";
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
- assert_non_null(mod = lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, &mod));
ly_in_free(in, 0);
assert_int_equal(LY_EVALID, lys_compile(&mod, 0));
logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/notification statement. /aa:a");
@@ -160,19 +160,17 @@
ly_ctx_destroy(ctx, NULL);
}
-
-
static void
test_node_container(void **state)
{
(void) state; /* unused */
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_node_container *cont;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;container c;}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;container c;}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled);
assert_non_null((cont = (struct lysc_node_container*)mod->compiled->data));
assert_int_equal(LYS_CONTAINER, cont->nodetype);
@@ -180,7 +178,7 @@
assert_true(cont->flags & LYS_CONFIG_W);
assert_true(cont->flags & LYS_STATUS_CURR);
- assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;container c {config false; status deprecated; container child;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;container c {config false; status deprecated; container child;}}", LYS_IN_YANG, &mod));
logbuf_assert("Missing explicit \"deprecated\" status that was already specified in parent, inheriting.");
assert_non_null(mod->compiled);
assert_non_null((cont = (struct lysc_node_container*)mod->compiled->data));
@@ -201,7 +199,7 @@
*state = test_node_leaflist;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_type *type;
struct lysc_node_leaflist *ll;
struct lysc_node_leaf *l;
@@ -210,12 +208,12 @@
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;"
"typedef mytype {type union {type leafref {path ../target;} type string;}}"
"leaf-list ll1 {type union {type decimal64 {fraction-digits 2;} type mytype;}}"
"leaf-list ll2 {type leafref {path ../target;}}"
"leaf target {type int8;}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
@@ -234,15 +232,15 @@
assert_non_null(((struct lysc_type_leafref*)type)->realtype);
assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref*)type)->realtype->basetype);
- assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;leaf-list ll {type string;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;leaf-list ll {type string;}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled);
assert_non_null((ll = (struct lysc_node_leaflist*)mod->compiled->data));
assert_int_equal(0, ll->min);
assert_int_equal((uint32_t)-1, ll->max);
- assert_non_null(mod = lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c;typedef mytype {type int8;default 10;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c;typedef mytype {type int8;default 10;}"
"leaf-list ll1 {type mytype;default 1; default 1; config false;}"
- "leaf-list ll2 {type mytype; ordered-by user;}}", LYS_IN_YANG));
+ "leaf-list ll2 {type mytype; ordered-by user;}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled);
assert_non_null((ll = (struct lysc_node_leaflist*)mod->compiled->data));
assert_non_null(ll->dflts);
@@ -262,8 +260,8 @@
assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_USER, ll->flags);
/* ordered-by is ignored for state data, RPC/action output parameters and notification content */
- assert_non_null(mod = lys_parse_mem(ctx, "module d {yang-version 1.1;namespace urn:d;prefix d;"
- "leaf-list ll {config false; type string; ordered-by user;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {yang-version 1.1;namespace urn:d;prefix d;"
+ "leaf-list ll {config false; type string; ordered-by user;}}", LYS_IN_YANG, &mod));
/* but warning is present: */
logbuf_assert("The ordered-by statement is ignored in lists representing state data (/d:ll).");
assert_non_null(mod->compiled);
@@ -271,43 +269,44 @@
assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_CONFIG, ll->flags);
logbuf_clean();
- assert_non_null(mod = lys_parse_mem(ctx, "module e {yang-version 1.1;namespace urn:e;prefix e;"
- "rpc oper {output {leaf-list ll {type string; ordered-by user;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {yang-version 1.1;namespace urn:e;prefix e;"
+ "rpc oper {output {leaf-list ll {type string; ordered-by user;}}}}", LYS_IN_YANG, &mod));
logbuf_assert("The ordered-by statement is ignored in lists representing RPC/action output parameters (/e:oper/output/ll).");
logbuf_clean();
- assert_non_null(mod = lys_parse_mem(ctx, "module f {yang-version 1.1;namespace urn:f;prefix f;"
- "notification event {leaf-list ll {type string; ordered-by user;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {yang-version 1.1;namespace urn:f;prefix f;"
+ "notification event {leaf-list ll {type string; ordered-by user;}}}", LYS_IN_YANG, &mod));
logbuf_assert("The ordered-by statement is ignored in lists representing notification content (/f:event/ll).");
/* forward reference in default */
- assert_non_null(mod = lys_parse_mem(ctx, "module g {yang-version 1.1; namespace urn:g;prefix g;"
- "leaf ref {type instance-identifier {require-instance true;} default \"/g:g[.='val']\";}"
- "leaf-list g {type string;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {yang-version 1.1; namespace urn:g;prefix g;"
+ "leaf ref {type instance-identifier {require-instance true;} default \"/g:g[.='val']\";}"
+ "leaf-list g {type string;}}", LYS_IN_YANG, &mod));
assert_non_null(l = (struct lysc_node_leaf*)mod->compiled->data);
assert_string_equal("ref", l->name);
assert_non_null(l->dflt);
assert_null(l->dflt->canonical_cache);
/* invalid */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;leaf-list ll {type empty;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;leaf-list ll {type empty;}}",
+ LYS_IN_YANG, NULL));
logbuf_assert("Leaf-list of type \"empty\" is allowed only in YANG 1.1 modules. /aa:ll");
- assert_null(lys_parse_mem(ctx, "module bb {yang-version 1.1;namespace urn:bb;prefix bb;leaf-list ll {type empty; default x;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {yang-version 1.1;namespace urn:bb;prefix bb;leaf-list ll {type empty; default x;}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid leaf-lists's default value \"x\" which does not fit the type (Invalid empty value \"x\".). /bb:ll");
- assert_non_null(mod = lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;"
- "leaf-list ll {config false;type string; default one;default two;default one;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;"
+ "leaf-list ll {config false;type string; default one;default two;default one;}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled);
assert_non_null((ll = (struct lysc_node_leaflist*)mod->compiled->data));
assert_non_null(ll->dflts);
assert_int_equal(3, LY_ARRAY_COUNT(ll->dflts));
- assert_null(lys_parse_mem(ctx, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;"
- "leaf-list ll {type string; default one;default two;default one;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;"
+ "leaf-list ll {type string; default one;default two;default one;}}", LYS_IN_YANG, NULL));
logbuf_assert("Configuration leaf-list has multiple defaults of the same value \"one\". /dd:ll");
- assert_null(lys_parse_mem(ctx, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;"
- "leaf ref {type instance-identifier {require-instance true;} default \"/ee:g\";}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;"
+ "leaf ref {type instance-identifier {require-instance true;} default \"/ee:g\";}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid default - value does not fit the type "
"(Invalid instance-identifier \"/ee:g\" value - semantic error.). /ee:ref");
@@ -321,15 +320,15 @@
*state = test_node_list;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_node_list *list;
struct lysc_node *child;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;feature f;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;feature f;"
"list l1 {key \"x y\"; ordered-by user; leaf y{type string;if-feature f;} leaf x {type string; when 1;}}"
- "list l2 {config false;leaf value {type string;}}}", LYS_IN_YANG));
+ "list l2 {config false;leaf value {type string;}}}", LYS_IN_YANG, &mod));
list = (struct lysc_node_list*)mod->compiled->data;
assert_non_null(list);
assert_non_null(list->child);
@@ -347,10 +346,11 @@
assert_false(list->child->flags & LYS_KEY);
assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_CONFIG | LYS_KEYLESS, list->flags);
- assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;"
"list l {key a; unique \"a c/b:b\"; unique \"c/e d\";"
"leaf a {type string; default x;} leaf d {type string;config false;}"
- "container c {leaf b {type string;}leaf e{type string;config false;}}}}", LYS_IN_YANG));
+ "container c {leaf b {type string;}leaf e{type string;config false;}}}}",
+ LYS_IN_YANG, &mod));
list = (struct lysc_node_list*)mod->compiled->data;
assert_non_null(list);
assert_string_equal("l", list->name);
@@ -370,8 +370,8 @@
assert_string_equal("d", list->uniques[1][1]->name);
assert_true(list->uniques[1][1]->flags & LYS_UNIQUE);
- assert_non_null(mod = lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c;"
- "list l {key a;leaf a {type empty;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c;"
+ "list l {key a;leaf a {type empty;}}}", LYS_IN_YANG, &mod));
list = (struct lysc_node_list*)mod->compiled->data;
assert_non_null(list);
assert_string_equal("l", list->name);
@@ -380,8 +380,8 @@
assert_int_equal(LY_TYPE_EMPTY, ((struct lysc_node_leaf*)list->child)->type->basetype);
/* keys order */
- assert_non_null(mod = lys_parse_mem(ctx, "module d {yang-version 1.1;namespace urn:d;prefix d;"
- "list l {key \"d b c\";leaf a {type string;} leaf b {type string;} leaf c {type string;} leaf d {type string;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {yang-version 1.1;namespace urn:d;prefix d;"
+ "list l {key \"d b c\";leaf a {type string;} leaf b {type string;} leaf c {type string;} leaf d {type string;}}}", LYS_IN_YANG, &mod));
list = (struct lysc_node_list*)mod->compiled->data;
assert_non_null(list);
assert_string_equal("l", list->name);
@@ -399,55 +399,55 @@
assert_false(child->flags & LYS_KEY);
/* invalid */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;list l;}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;list l;}", LYS_IN_YANG, NULL));
logbuf_assert("Missing key in list representing configuration data. /aa:l");
- assert_null(lys_parse_mem(ctx, "module bb {yang-version 1.1; namespace urn:bb;prefix bb;"
- "list l {key x; leaf x {type string; when 1;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {yang-version 1.1; namespace urn:bb;prefix bb;"
+ "list l {key x; leaf x {type string; when 1;}}}", LYS_IN_YANG, NULL));
logbuf_assert("List's key must not have any \"when\" statement. /bb:l/x");
- assert_null(lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;feature f;"
- "list l {key x; leaf x {type string; if-feature f;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;feature f;"
+ "list l {key x; leaf x {type string; if-feature f;}}}", LYS_IN_YANG, NULL));
logbuf_assert("List's key must not have any \"if-feature\" statement. /cc:l/x");
- assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;"
- "list l {key x; leaf x {type string; config false;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;"
+ "list l {key x; leaf x {type string; config false;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Key of the configuration list must not be status leaf. /dd:l/x");
- assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;"
- "list l {config false;key x; leaf x {type string; config true;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;"
+ "list l {config false;key x; leaf x {type string; config true;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Configuration node cannot be child of any state data node. /ee:l/x");
- assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;"
- "list l {key x; leaf-list x {type string;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;"
+ "list l {key x; leaf-list x {type string;}}}", LYS_IN_YANG, NULL));
logbuf_assert("The list's key \"x\" not found. /ff:l");
- assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;"
- "list l {key x; unique y;leaf x {type string;} leaf-list y {type string;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;"
+ "list l {key x; unique y;leaf x {type string;} leaf-list y {type string;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Unique's descendant-schema-nodeid \"y\" refers to leaf-list node instead of a leaf. /gg:l");
- assert_null(lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;"
- "list l {key x; unique \"x y\";leaf x {type string;} leaf y {config false; type string;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;"
+ "list l {key x; unique \"x y\";leaf x {type string;} leaf y {config false; type string;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Unique statement \"x y\" refers to leaves with different config type. /hh:l");
- assert_null(lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;"
- "list l {key x; unique a:x;leaf x {type string;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;"
+ "list l {key x; unique a:x;leaf x {type string;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid descendant-schema-nodeid value \"a:x\" - prefix \"a\" not defined in module \"ii\". /ii:l");
- assert_null(lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;"
- "list l {key x; unique c/x;leaf x {type string;}container c {leaf y {type string;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;"
+ "list l {key x; unique c/x;leaf x {type string;}container c {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid descendant-schema-nodeid value \"c/x\" - target node not found. /jj:l");
- assert_null( lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;"
- "list l {key x; unique c^y;leaf x {type string;}container c {leaf y {type string;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;"
+ "list l {key x; unique c^y;leaf x {type string;}container c {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid descendant-schema-nodeid value \"c^\" - missing \"/\" as node-identifier separator. /kk:l");
- assert_null(lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;"
- "list l {key \"x y x\";leaf x {type string;}leaf y {type string;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;"
+ "list l {key \"x y x\";leaf x {type string;}leaf y {type string;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Duplicated key identifier \"x\". /ll:l");
- assert_null(lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;"
- "list l {key x;leaf x {type empty;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;"
+ "list l {key x;leaf x {type empty;}}}", LYS_IN_YANG, NULL));
logbuf_assert("List's key cannot be of \"empty\" type until it is in YANG 1.1 module. /mm:l/x");
*state = NULL;
@@ -460,15 +460,15 @@
*state = test_node_choice;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_node_choice *ch;
struct lysc_node_case *cs;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;feature f;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;feature f;"
"choice ch {default a:b; when \"true()\"; case a {leaf a1 {type string;}leaf a2 {type string;}}"
- "leaf b {type string;}}}", LYS_IN_YANG));
+ "leaf b {type string;}}}", LYS_IN_YANG, &mod));
ch = (struct lysc_node_choice*)mod->compiled->data;
assert_non_null(ch);
assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR, ch->flags);
@@ -496,27 +496,27 @@
assert_ptr_equal(ch->cases->child->prev, cs->child);
assert_ptr_equal(ch->dflt, cs);
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
- "choice ch {case a {leaf x {type string;}}leaf x {type string;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
+ "choice ch {case a {leaf x {type string;}}leaf x {type string;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Duplicate identifier \"x\" of data definition/RPC/action/notification statement. /aa:ch/x/x");
- assert_null(lys_parse_mem(ctx, "module aa2 {namespace urn:aa2;prefix aa;"
- "choice ch {case a {leaf y {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa2 {namespace urn:aa2;prefix aa;"
+ "choice ch {case a {leaf y {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
logbuf_assert("Duplicate identifier \"y\" of data definition/RPC/action/notification statement. /aa2:ch/b/y");
- assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;"
- "choice ch {case a {leaf x {type string;}}leaf a {type string;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;"
+ "choice ch {case a {leaf x {type string;}}leaf a {type string;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Duplicate identifier \"a\" of case statement. /bb:ch/a");
- assert_null(lys_parse_mem(ctx, "module bb2 {namespace urn:bb2;prefix bb;"
- "choice ch {case b {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb2 {namespace urn:bb2;prefix bb;"
+ "choice ch {case b {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
logbuf_assert("Duplicate identifier \"b\" of case statement. /bb2:ch/b");
- assert_null(lys_parse_mem(ctx, "module ca {namespace urn:ca;prefix ca;"
- "choice ch {default c;case a {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ca {namespace urn:ca;prefix ca;"
+ "choice ch {default c;case a {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
logbuf_assert("Default case \"c\" not found. /ca:ch");
- assert_null(lys_parse_mem(ctx, "module cb {namespace urn:cb;prefix cb; import a {prefix a;}"
- "choice ch {default a:a;case a {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cb {namespace urn:cb;prefix cb; import a {prefix a;}"
+ "choice ch {default a:a;case a {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid default case referencing a case from different YANG module (by prefix \"a\"). /cb:ch");
- assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;"
- "choice ch {default a;case a {leaf x {mandatory true;type string;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;"
+ "choice ch {default a;case a {leaf x {mandatory true;type string;}}}}", LYS_IN_YANG, NULL));
logbuf_assert("Mandatory node \"x\" under the default case \"a\". /cc:ch");
/* TODO check with mandatory nodes from augment placed into the case */
@@ -530,21 +530,21 @@
*state = test_node_anydata;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_node_anydata *any;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;"
- "anydata any {config false;mandatory true;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;"
+ "anydata any {config false;mandatory true;}}", LYS_IN_YANG, &mod));
any = (struct lysc_node_anydata*)mod->compiled->data;
assert_non_null(any);
assert_int_equal(LYS_ANYDATA, any->nodetype);
assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE | LYS_SET_CONFIG, any->flags);
logbuf_clean();
- assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;"
- "anyxml any;}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;"
+ "anyxml any;}", LYS_IN_YANG, &mod));
any = (struct lysc_node_anydata*)mod->compiled->data;
assert_non_null(any);
assert_int_equal(LYS_ANYXML, any->nodetype);
@@ -552,7 +552,7 @@
logbuf_assert("Use of anyxml to define configuration data is not recommended."); /* warning */
/* invalid */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;anydata any;}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;anydata any;}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid keyword \"anydata\" as a child of \"module\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
*state = NULL;
@@ -565,13 +565,13 @@
*state = test_action;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
const struct lysc_action *rpc;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;"
- "rpc a {input {leaf x {type int8;} leaf y {type int8;}} output {leaf result {type int16;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;"
+ "rpc a {input {leaf x {type int8;} leaf y {type int8;}} output {leaf result {type int16;}}}}", LYS_IN_YANG, &mod));
rpc = mod->compiled->rpcs;
assert_non_null(rpc);
assert_int_equal(1, LY_ARRAY_COUNT(rpc));
@@ -579,9 +579,9 @@
assert_int_equal(LYS_STATUS_CURR, rpc->flags);
assert_string_equal("a", rpc->name);
- assert_non_null(mod = lys_parse_mem(ctx, "module b {yang-version 1.1; namespace urn:b;prefix b; container top {"
- "action b {input {leaf x {type int8;} leaf y {type int8;}}"
- "output {must \"result > 25\"; must \"/top\"; leaf result {type int16;}}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1; namespace urn:b;prefix b; container top {"
+ "action b {input {leaf x {type int8;} leaf y {type int8;}}"
+ "output {must \"result > 25\"; must \"/top\"; leaf result {type int16;}}}}}", LYS_IN_YANG, &mod));
rpc = lysc_node_actions(mod->compiled->data);
assert_non_null(rpc);
assert_int_equal(1, LY_ARRAY_COUNT(rpc));
@@ -592,29 +592,31 @@
assert_int_equal(2, LY_ARRAY_COUNT(rpc->output.musts));
/* invalid */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;container top {action x;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;container top {action x;}}",
+ LYS_IN_YANG, NULL));
logbuf_assert("Invalid keyword \"action\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
- assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf x{type string;} rpc x;}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf x{type string;} rpc x;}",
+ LYS_IN_YANG, NULL));
logbuf_assert("Duplicate identifier \"x\" of data definition/RPC/action/notification statement. /bb:x");
- assert_null(lys_parse_mem(ctx, "module cc {yang-version 1.1; namespace urn:cc;prefix cc;container c {leaf y {type string;} action y;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {yang-version 1.1; namespace urn:cc;prefix cc;container c {leaf y {type string;} action y;}}", LYS_IN_YANG, NULL));
logbuf_assert("Duplicate identifier \"y\" of data definition/RPC/action/notification statement. /cc:c/y");
- assert_null(lys_parse_mem(ctx, "module dd {yang-version 1.1; namespace urn:dd;prefix dd;container c {action z; action z;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {yang-version 1.1; namespace urn:dd;prefix dd;container c {action z; action z;}}", LYS_IN_YANG, NULL));
logbuf_assert("Duplicate identifier \"z\" of data definition/RPC/action/notification statement. /dd:c/z");
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule eesub {belongs-to ee {prefix ee;} notification w;}");
- assert_null(lys_parse_mem(ctx, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;include eesub; rpc w;}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;include eesub; rpc w;}", LYS_IN_YANG, NULL));
logbuf_assert("Duplicate identifier \"w\" of data definition/RPC/action/notification statement. /ee:w");
- assert_null(lys_parse_mem(ctx, "module ff {yang-version 1.1; namespace urn:ff;prefix ff; rpc test {input {container a {leaf b {type string;}}}}"
- "augment /test/input/a {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {yang-version 1.1; namespace urn:ff;prefix ff; rpc test {input {container a {leaf b {type string;}}}}"
+ "augment /test/input/a {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG, NULL));
logbuf_assert("Action \"invalid\" is placed inside another RPC/action. /ff:{augment='/test/input/a'}/invalid");
- assert_null(lys_parse_mem(ctx, "module gg {yang-version 1.1; namespace urn:gg;prefix gg; notification test {container a {leaf b {type string;}}}"
- "augment /test/a {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {yang-version 1.1; namespace urn:gg;prefix gg; notification test {container a {leaf b {type string;}}}"
+ "augment /test/a {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG, NULL));
logbuf_assert("Action \"invalid\" is placed inside notification. /gg:{augment='/test/a'}/invalid");
- assert_null(lys_parse_mem(ctx, "module hh {yang-version 1.1; namespace urn:hh;prefix hh; notification test {container a {uses grp;}}"
- "grouping grp {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {yang-version 1.1; namespace urn:hh;prefix hh; notification test {container a {uses grp;}}"
+ "grouping grp {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG, NULL));
logbuf_assert("Action \"invalid\" is placed inside notification. /hh:test/a/{uses='grp'}/invalid");
*state = NULL;
@@ -627,13 +629,13 @@
*state = test_notification;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
const struct lysc_notif *notif;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;"
- "notification a1 {leaf x {type int8;}} notification a2;}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;"
+ "notification a1 {leaf x {type int8;}} notification a2;}", LYS_IN_YANG, &mod));
notif = mod->compiled->notifs;
assert_non_null(notif);
assert_int_equal(2, LY_ARRAY_COUNT(notif));
@@ -647,8 +649,8 @@
assert_string_equal("a2", notif[1].name);
assert_null(notif[1].data);
- assert_non_null(mod = lys_parse_mem(ctx, "module b {yang-version 1.1; namespace urn:b;prefix b; container top {"
- "notification b1 {leaf x {type int8;}} notification b2 {must \"/top\";}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1; namespace urn:b;prefix b; container top {"
+ "notification b1 {leaf x {type int8;}} notification b2 {must \"/top\";}}}", LYS_IN_YANG, &mod));
notif = lysc_node_notifs(mod->compiled->data);
assert_non_null(notif);
assert_int_equal(2, LY_ARRAY_COUNT(notif));
@@ -664,29 +666,30 @@
assert_int_equal(1, LY_ARRAY_COUNT(notif[1].musts));
/* invalid */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;container top {notification x;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;container top {notification x;}}",
+ LYS_IN_YANG, NULL));
logbuf_assert("Invalid keyword \"notification\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
- assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf x{type string;} notification x;}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf x{type string;} notification x;}", LYS_IN_YANG, NULL));
logbuf_assert("Duplicate identifier \"x\" of data definition/RPC/action/notification statement. /bb:x");
- assert_null(lys_parse_mem(ctx, "module cc {yang-version 1.1; namespace urn:cc;prefix cc;container c {leaf y {type string;} notification y;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {yang-version 1.1; namespace urn:cc;prefix cc;container c {leaf y {type string;} notification y;}}", LYS_IN_YANG, NULL));
logbuf_assert("Duplicate identifier \"y\" of data definition/RPC/action/notification statement. /cc:c/y");
- assert_null(lys_parse_mem(ctx, "module dd {yang-version 1.1; namespace urn:dd;prefix dd;container c {notification z; notification z;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {yang-version 1.1; namespace urn:dd;prefix dd;container c {notification z; notification z;}}", LYS_IN_YANG, NULL));
logbuf_assert("Duplicate identifier \"z\" of data definition/RPC/action/notification statement. /dd:c/z");
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule eesub {belongs-to ee {prefix ee;} rpc w;}");
- assert_null(lys_parse_mem(ctx, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;include eesub; notification w;}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;include eesub; notification w;}", LYS_IN_YANG, NULL));
logbuf_assert("Duplicate identifier \"w\" of data definition/RPC/action/notification statement. /ee:w");
- assert_null(lys_parse_mem(ctx, "module ff {yang-version 1.1; namespace urn:ff;prefix ff; rpc test {input {container a {leaf b {type string;}}}}"
- "augment /test/input/a {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {yang-version 1.1; namespace urn:ff;prefix ff; rpc test {input {container a {leaf b {type string;}}}}"
+ "augment /test/input/a {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG, NULL));
logbuf_assert("Notification \"invalid\" is placed inside RPC/action. /ff:{augment='/test/input/a'}/invalid");
- assert_null(lys_parse_mem(ctx, "module gg {yang-version 1.1; namespace urn:gg;prefix gg; notification test {container a {leaf b {type string;}}}"
- "augment /test/a {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {yang-version 1.1; namespace urn:gg;prefix gg; notification test {container a {leaf b {type string;}}}"
+ "augment /test/a {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG, NULL));
logbuf_assert("Notification \"invalid\" is placed inside another notification. /gg:{augment='/test/a'}/invalid");
- assert_null(lys_parse_mem(ctx, "module hh {yang-version 1.1; namespace urn:hh;prefix hh; rpc test {input {container a {uses grp;}}}"
- "grouping grp {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {yang-version 1.1; namespace urn:hh;prefix hh; rpc test {input {container a {uses grp;}}}"
+ "grouping grp {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG, NULL));
logbuf_assert("Notification \"invalid\" is placed inside RPC/action. /hh:test/input/a/{uses='grp'}/invalid");
*state = NULL;
@@ -703,12 +706,12 @@
*state = test_type_range;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_type *type;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;leaf l {type int8 {range min..10|max;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;leaf l {type int8 {range min..10|max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_INT8, type->basetype);
@@ -720,7 +723,7 @@
assert_int_equal(127, ((struct lysc_type_num*)type)->range->parts[1].min_64);
assert_int_equal(127, ((struct lysc_type_num*)type)->range->parts[1].max_64);
- assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;leaf l {type int16 {range min..10|max;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;leaf l {type int16 {range min..10|max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_INT16, type->basetype);
@@ -732,7 +735,7 @@
assert_int_equal(32767, ((struct lysc_type_num*)type)->range->parts[1].min_64);
assert_int_equal(32767, ((struct lysc_type_num*)type)->range->parts[1].max_64);
- assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;leaf l {type int32 {range min..10|max;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;leaf l {type int32 {range min..10|max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_INT32, type->basetype);
@@ -744,7 +747,7 @@
assert_int_equal(INT64_C(2147483647), ((struct lysc_type_num*)type)->range->parts[1].min_64);
assert_int_equal(INT64_C(2147483647), ((struct lysc_type_num*)type)->range->parts[1].max_64);
- assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;leaf l {type int64 {range min..10|max;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;leaf l {type int64 {range min..10|max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_INT64, type->basetype);
@@ -756,7 +759,7 @@
assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_num*)type)->range->parts[1].min_64);
assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_num*)type)->range->parts[1].max_64);
- assert_non_null(mod = lys_parse_mem(ctx, "module e {namespace urn:e;prefix e;leaf l {type uint8 {range min..10|max;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {namespace urn:e;prefix e;leaf l {type uint8 {range min..10|max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_UINT8, type->basetype);
@@ -768,7 +771,7 @@
assert_int_equal(255, ((struct lysc_type_num*)type)->range->parts[1].min_u64);
assert_int_equal(255, ((struct lysc_type_num*)type)->range->parts[1].max_u64);
- assert_non_null(mod = lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;leaf l {type uint16 {range min..10|max;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;leaf l {type uint16 {range min..10|max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_UINT16, type->basetype);
@@ -780,7 +783,7 @@
assert_int_equal(65535, ((struct lysc_type_num*)type)->range->parts[1].min_u64);
assert_int_equal(65535, ((struct lysc_type_num*)type)->range->parts[1].max_u64);
- assert_non_null(mod = lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;leaf l {type uint32 {range min..10|max;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;leaf l {type uint32 {range min..10|max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_UINT32, type->basetype);
@@ -792,7 +795,7 @@
assert_int_equal(UINT64_C(4294967295), ((struct lysc_type_num*)type)->range->parts[1].min_u64);
assert_int_equal(UINT64_C(4294967295), ((struct lysc_type_num*)type)->range->parts[1].max_u64);
- assert_non_null(mod = lys_parse_mem(ctx, "module h {namespace urn:h;prefix h;leaf l {type uint64 {range min..10|max;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module h {namespace urn:h;prefix h;leaf l {type uint64 {range min..10|max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_UINT64, type->basetype);
@@ -804,8 +807,8 @@
assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_num*)type)->range->parts[1].min_u64);
assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_num*)type)->range->parts[1].max_u64);
- assert_non_null(mod = lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;typedef mytype {type uint8 {range 10..100;}}"
- "typedef mytype2 {type mytype;} leaf l {type mytype2;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;typedef mytype {type uint8 {range 10..100;}}"
+ "typedef mytype2 {type mytype;} leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(3, type->refcount);
@@ -814,9 +817,9 @@
assert_non_null(((struct lysc_type_num*)type)->range->parts);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_num*)type)->range->parts));
- assert_non_null(mod = lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;"
- "typedef mytype {type uint8 {range 1..100{description \"one to hundred\";reference A;}}}"
- "leaf l {type mytype {range 1..10 {description \"one to ten\";reference B;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;"
+ "typedef mytype {type uint8 {range 1..100{description \"one to hundred\";reference A;}}}"
+ "leaf l {type mytype {range 1..10 {description \"one to ten\";reference B;}}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
@@ -839,12 +842,12 @@
*state = test_type_length;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_type *type;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;leaf l {type binary {length min {error-app-tag errortag;error-message error;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;leaf l {type binary {length min {error-app-tag errortag;error-message error;}}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin*)type)->length);
@@ -855,7 +858,7 @@
assert_int_equal(0, ((struct lysc_type_bin*)type)->length->parts[0].min_u64);
assert_int_equal(0, ((struct lysc_type_bin*)type)->length->parts[0].max_u64);
- assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;leaf l {type binary {length max;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;leaf l {type binary {length max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin*)type)->length);
@@ -864,7 +867,7 @@
assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_bin*)type)->length->parts[0].min_u64);
assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_bin*)type)->length->parts[0].max_u64);
- assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;leaf l {type binary {length min..max;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;leaf l {type binary {length min..max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin*)type)->length);
@@ -873,7 +876,7 @@
assert_int_equal(0, ((struct lysc_type_bin*)type)->length->parts[0].min_u64);
assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_bin*)type)->length->parts[0].max_u64);
- assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;leaf l {type binary {length 5;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;leaf l {type binary {length 5;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin*)type)->length);
@@ -882,7 +885,7 @@
assert_int_equal(5, ((struct lysc_type_bin*)type)->length->parts[0].min_u64);
assert_int_equal(5, ((struct lysc_type_bin*)type)->length->parts[0].max_u64);
- assert_non_null(mod = lys_parse_mem(ctx, "module e {namespace urn:e;prefix e;leaf l {type binary {length 1..10;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {namespace urn:e;prefix e;leaf l {type binary {length 1..10;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin*)type)->length);
@@ -891,7 +894,7 @@
assert_int_equal(1, ((struct lysc_type_bin*)type)->length->parts[0].min_u64);
assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].max_u64);
- assert_non_null(mod = lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;leaf l {type binary {length 1..10|20..30;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;leaf l {type binary {length 1..10|20..30;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin*)type)->length);
@@ -902,7 +905,7 @@
assert_int_equal(20, ((struct lysc_type_bin*)type)->length->parts[1].min_u64);
assert_int_equal(30, ((struct lysc_type_bin*)type)->length->parts[1].max_u64);
- assert_non_null(mod = lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;leaf l {type binary {length \"16 | 32\";}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;leaf l {type binary {length \"16 | 32\";}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin*)type)->length);
@@ -913,8 +916,8 @@
assert_int_equal(32, ((struct lysc_type_bin*)type)->length->parts[1].min_u64);
assert_int_equal(32, ((struct lysc_type_bin*)type)->length->parts[1].max_u64);
- assert_non_null(mod = lys_parse_mem(ctx, "module h {namespace urn:h;prefix h;typedef mytype {type binary {length 10;}}"
- "leaf l {type mytype {length \"10\";}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module h {namespace urn:h;prefix h;typedef mytype {type binary {length 10;}}"
+ "leaf l {type mytype {length \"10\";}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin*)type)->length);
@@ -923,8 +926,8 @@
assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].min_u64);
assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].max_u64);
- assert_non_null(mod = lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;typedef mytype {type binary {length 10..100;}}"
- "leaf l {type mytype {length \"50\";}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;typedef mytype {type binary {length 10..100;}}"
+ "leaf l {type mytype {length \"50\";}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin*)type)->length);
@@ -933,8 +936,8 @@
assert_int_equal(50, ((struct lysc_type_bin*)type)->length->parts[0].min_u64);
assert_int_equal(50, ((struct lysc_type_bin*)type)->length->parts[0].max_u64);
- assert_non_null(mod = lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;typedef mytype {type binary {length 10..100;}}"
- "leaf l {type mytype {length \"10..30|60..100\";}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;typedef mytype {type binary {length 10..100;}}"
+ "leaf l {type mytype {length \"10..30|60..100\";}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin*)type)->length);
@@ -945,8 +948,8 @@
assert_int_equal(60, ((struct lysc_type_bin*)type)->length->parts[1].min_u64);
assert_int_equal(100, ((struct lysc_type_bin*)type)->length->parts[1].max_u64);
- assert_non_null(mod = lys_parse_mem(ctx, "module k {namespace urn:k;prefix k;typedef mytype {type binary {length 10..100;}}"
- "leaf l {type mytype {length \"10..80\";}}leaf ll {type mytype;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module k {namespace urn:k;prefix k;typedef mytype {type binary {length 10..100;}}"
+ "leaf l {type mytype {length \"10..80\";}}leaf ll {type mytype;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
@@ -964,8 +967,8 @@
assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].min_u64);
assert_int_equal(100, ((struct lysc_type_bin*)type)->length->parts[0].max_u64);
- assert_non_null(mod = lys_parse_mem(ctx, "module l {namespace urn:l;prefix l;typedef mytype {type string {length 10..100;}}"
- "typedef mytype2 {type mytype {pattern '[0-9]*';}} leaf l {type mytype2 {pattern '[0-4]*';}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module l {namespace urn:l;prefix l;typedef mytype {type string {length 10..100;}}"
+ "typedef mytype2 {type mytype {pattern '[0-9]*';}} leaf l {type mytype2 {pattern '[0-4]*';}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_STRING, type->basetype);
@@ -976,8 +979,8 @@
assert_int_equal(10, ((struct lysc_type_str*)type)->length->parts[0].min_u64);
assert_int_equal(100, ((struct lysc_type_str*)type)->length->parts[0].max_u64);
- assert_non_null(mod = lys_parse_mem(ctx, "module m {namespace urn:m;prefix m;typedef mytype {type string {length 10;}}"
- "leaf l {type mytype {length min..max;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module m {namespace urn:m;prefix m;typedef mytype {type string {length 10;}}"
+ "leaf l {type mytype {length min..max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_STRING, type->basetype);
@@ -989,54 +992,54 @@
assert_int_equal(10, ((struct lysc_type_str*)type)->length->parts[0].max_u64);
/* invalid values */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;leaf l {type binary {length -10;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;leaf l {type binary {length -10;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - value \"-10\" does not fit the type limitations. /aa:l");
- assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf l {type binary {length 18446744073709551616;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf l {type binary {length 18446744073709551616;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - invalid value \"18446744073709551616\". /bb:l");
- assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;leaf l {type binary {length \"max .. 10\";}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;leaf l {type binary {length \"max .. 10\";}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - unexpected data after max keyword (.. 10). /cc:l");
- assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;leaf l {type binary {length 50..10;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;leaf l {type binary {length 50..10;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - values are not in ascending order (10). /dd:l");
- assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type binary {length \"50 | 10\";}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type binary {length \"50 | 10\";}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - values are not in ascending order (10). /ee:l");
- assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type binary {length \"x\";}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type binary {length \"x\";}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - unexpected data (x). /ff:l");
- assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;leaf l {type binary {length \"50 | min\";}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;leaf l {type binary {length \"50 | min\";}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - unexpected data before min keyword (50 | ). /gg:l");
- assert_null(lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;leaf l {type binary {length \"| 50\";}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;leaf l {type binary {length \"| 50\";}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - unexpected beginning of the expression (| 50). /hh:l");
- assert_null(lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;leaf l {type binary {length \"10 ..\";}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;leaf l {type binary {length \"10 ..\";}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - unexpected end of the expression after \"..\" (10 ..). /ii:l");
- assert_null(lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;leaf l {type binary {length \".. 10\";}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;leaf l {type binary {length \".. 10\";}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - unexpected \"..\" without a lower bound. /jj:l");
- assert_null(lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;leaf l {type binary {length \"10 |\";}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;leaf l {type binary {length \"10 |\";}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - unexpected end of the expression (10 |). /kk:l");
- assert_null(lys_parse_mem(ctx, "module kl {namespace urn:kl;prefix kl;leaf l {type binary {length \"10..20 | 15..30\";}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kl {namespace urn:kl;prefix kl;leaf l {type binary {length \"10..20 | 15..30\";}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - values are not in ascending order (15). /kl:l");
- assert_null(lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;typedef mytype {type binary {length 10;}}"
- "leaf l {type mytype {length 11;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;typedef mytype {type binary {length 10;}}"
+ "leaf l {type mytype {length 11;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - the derived restriction (11) is not equally or more limiting. /ll:l");
- assert_null(lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;typedef mytype {type binary {length 10..100;}}"
- "leaf l {type mytype {length 1..11;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;typedef mytype {type binary {length 10..100;}}"
+ "leaf l {type mytype {length 1..11;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - the derived restriction (1..11) is not equally or more limiting. /mm:l");
- assert_null(lys_parse_mem(ctx, "module nn {namespace urn:nn;prefix nn;typedef mytype {type binary {length 10..100;}}"
- "leaf l {type mytype {length 20..110;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module nn {namespace urn:nn;prefix nn;typedef mytype {type binary {length 10..100;}}"
+ "leaf l {type mytype {length 20..110;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - the derived restriction (20..110) is not equally or more limiting. /nn:l");
- assert_null(lys_parse_mem(ctx, "module oo {namespace urn:oo;prefix oo;typedef mytype {type binary {length 10..100;}}"
- "leaf l {type mytype {length 20..30|110..120;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module oo {namespace urn:oo;prefix oo;typedef mytype {type binary {length 10..100;}}"
+ "leaf l {type mytype {length 20..30|110..120;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - the derived restriction (20..30|110..120) is not equally or more limiting. /oo:l");
- assert_null(lys_parse_mem(ctx, "module pp {namespace urn:pp;prefix pp;typedef mytype {type binary {length 10..11;}}"
- "leaf l {type mytype {length 15;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module pp {namespace urn:pp;prefix pp;typedef mytype {type binary {length 10..11;}}"
+ "leaf l {type mytype {length 15;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - the derived restriction (15) is not equally or more limiting. /pp:l");
- assert_null(lys_parse_mem(ctx, "module qq {namespace urn:qq;prefix qq;typedef mytype {type binary {length 10..20|30..40;}}"
- "leaf l {type mytype {length 15..35;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module qq {namespace urn:qq;prefix qq;typedef mytype {type binary {length 10..20|30..40;}}"
+ "leaf l {type mytype {length 15..35;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - the derived restriction (15..35) is not equally or more limiting. /qq:l");
- assert_null(lys_parse_mem(ctx, "module rr {namespace urn:rr;prefix rr;typedef mytype {type binary {length 10;}}"
- "leaf l {type mytype {length 10..35;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module rr {namespace urn:rr;prefix rr;typedef mytype {type binary {length 10;}}"
+ "leaf l {type mytype {length 10..35;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid length restriction - the derived restriction (10..35) is not equally or more limiting. /rr:l");
- assert_null(lys_parse_mem(ctx, "module ss {namespace urn:ss;prefix ss;leaf l {type binary {pattern '[0-9]*';}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ss {namespace urn:ss;prefix ss;leaf l {type binary {pattern '[0-9]*';}}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid type restrictions for binary type. /ss:l");
*state = NULL;
@@ -1049,14 +1052,14 @@
*state = test_type_pattern;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_type *type;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;leaf l {type string {"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;leaf l {type string {"
"pattern .* {error-app-tag errortag;error-message error;}"
- "pattern [0-9].*[0-9] {modifier invert-match;}}}}", LYS_IN_YANG));
+ "pattern [0-9].*[0-9] {modifier invert-match;}}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_str*)type)->patterns);
@@ -1070,8 +1073,8 @@
assert_string_equal("[0-9].*[0-9]", ((struct lysc_type_str*)type)->patterns[1]->expr);
assert_int_equal(1, ((struct lysc_type_str*)type)->patterns[1]->inverted);
- assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;typedef mytype {type string {pattern '[0-9]*';}}"
- "typedef mytype2 {type mytype {length 10;}} leaf l {type mytype2 {pattern '[0-4]*';}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;typedef mytype {type string {pattern '[0-9]*';}}"
+ "typedef mytype2 {type mytype {length 10;}} leaf l {type mytype2 {pattern '[0-4]*';}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_STRING, type->basetype);
@@ -1083,8 +1086,8 @@
assert_string_equal("[0-4]*", ((struct lysc_type_str*)type)->patterns[1]->expr);
assert_int_equal(1, ((struct lysc_type_str*)type)->patterns[1]->refcount);
- assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;typedef mytype {type string {pattern '[0-9]*';}}"
- "leaf l {type mytype {length 10;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;typedef mytype {type string {pattern '[0-9]*';}}"
+ "leaf l {type mytype {length 10;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_STRING, type->basetype);
@@ -1095,8 +1098,8 @@
assert_int_equal(2, ((struct lysc_type_str*)type)->patterns[0]->refcount);
/* test substitutions */
- assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;leaf l {type string {"
- "pattern '^\\p{IsLatinExtended-A}$';}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;leaf l {type string {"
+ "pattern '^\\p{IsLatinExtended-A}$';}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_str*)type)->patterns);
@@ -1114,14 +1117,14 @@
*state = test_type_enum;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_type *type;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;feature f; leaf l {type enumeration {"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;feature f; leaf l {type enumeration {"
"enum automin; enum min {value -2147483648;}enum one {if-feature f; value 1;}"
- "enum two; enum seven {value 7;}enum eight;}}}", LYS_IN_YANG));
+ "enum two; enum seven {value 7;}enum eight;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_ENUM, type->basetype);
@@ -1141,10 +1144,10 @@
assert_string_equal("eight", ((struct lysc_type_enum*)type)->enums[5].name);
assert_int_equal(8, ((struct lysc_type_enum*)type)->enums[5].value);
- assert_non_null(mod = lys_parse_mem(ctx, "module b {yang-version 1.1; namespace urn:b;prefix b;feature f; typedef mytype {type enumeration {"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1; namespace urn:b;prefix b;feature f; typedef mytype {type enumeration {"
"enum 11; enum min {value -2147483648;}enum x$&;"
"enum two; enum seven {value 7;}enum eight;}} leaf l { type mytype {enum seven;enum eight;}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_ENUM, type->basetype);
@@ -1157,55 +1160,55 @@
/* invalid cases */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type enumeration {"
- "enum one {if-feature f;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type enumeration {"
+ "enum one {if-feature f;}}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid keyword \"if-feature\" as a child of \"enum\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
- "enum one {value -2147483649;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+ "enum one {value -2147483649;}}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid value \"-2147483649\" of \"value\". Line number 1.");
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
- "enum one {value 2147483648;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+ "enum one {value 2147483648;}}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid value \"2147483648\" of \"value\". Line number 1.");
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
- "enum one; enum one;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+ "enum one; enum one;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Duplicate identifier \"one\" of enum statement. Line number 1.");
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
- "enum '';}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+ "enum '';}}}", LYS_IN_YANG, &mod));
logbuf_assert("Enum name must not be zero-length. Line number 1.");
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
- "enum ' x';}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+ "enum ' x';}}}", LYS_IN_YANG, &mod));
logbuf_assert("Enum name must not have any leading or trailing whitespaces (\" x\"). Line number 1.");
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
- "enum 'x ';}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+ "enum 'x ';}}}", LYS_IN_YANG, &mod));
logbuf_assert("Enum name must not have any leading or trailing whitespaces (\"x \"). Line number 1.");
- assert_non_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
- "enum 'inva\nlid';}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+ "enum 'inva\nlid';}}}", LYS_IN_YANG, &mod));
logbuf_assert("Control characters in enum name should be avoided (\"inva\nlid\", character number 5).");
- assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type enumeration;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type enumeration;}}", LYS_IN_YANG, &mod));
logbuf_assert("Missing enum substatement for enumeration type. /bb:l");
- assert_null(lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;typedef mytype {type enumeration {enum one;}}"
- "leaf l {type mytype {enum two;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;typedef mytype {type enumeration {enum one;}}"
+ "leaf l {type mytype {enum two;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid enumeration - derived type adds new item \"two\". /cc:l");
- assert_null(lys_parse_mem(ctx, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;typedef mytype {type enumeration {enum one;}}"
- "leaf l {type mytype {enum one {value 1;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;typedef mytype {type enumeration {enum one;}}"
+ "leaf l {type mytype {enum one {value 1;}}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid enumeration - value of the item \"one\" has changed from 0 to 1 in the derived type. /dd:l");
- assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type enumeration {enum x {value 2147483647;}enum y;}}}",
- LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type enumeration {enum x {value 2147483647;}enum y;}}}",
+ LYS_IN_YANG, &mod));
logbuf_assert("Invalid enumeration - it is not possible to auto-assign enum value for \"y\" since the highest value is already 2147483647. /ee:l");
- assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type enumeration {enum x {value 1;}enum y {value 1;}}}}",
- LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type enumeration {enum x {value 1;}enum y {value 1;}}}}",
+ LYS_IN_YANG, &mod));
logbuf_assert("Invalid enumeration - value 1 collide in items \"y\" and \"x\". /ff:l");
- assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;typedef mytype {type enumeration;}"
- "leaf l {type mytype {enum one;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;typedef mytype {type enumeration;}"
+ "leaf l {type mytype {enum one;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Missing enum substatement for enumeration type mytype. /gg:l");
- assert_null(lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh; typedef mytype {type enumeration {enum one;}}"
- "leaf l {type mytype {enum one;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh; typedef mytype {type enumeration {enum one;}}"
+ "leaf l {type mytype {enum one;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Enumeration type can be subtyped only in YANG 1.1 modules. /hh:l");
*state = NULL;
@@ -1218,14 +1221,14 @@
*state = test_type_bits;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_type *type;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;feature f; leaf l {type bits {"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;feature f; leaf l {type bits {"
"bit automin; bit one {if-feature f; position 1;}"
- "bit two; bit seven {position 7;}bit eight;}}}", LYS_IN_YANG));
+ "bit two; bit seven {position 7;}bit eight;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_BITS, type->basetype);
@@ -1243,9 +1246,9 @@
assert_string_equal("eight", ((struct lysc_type_bits*)type)->bits[4].name);
assert_int_equal(8, ((struct lysc_type_bits*)type)->bits[4].position);
- assert_non_null(mod = lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b;feature f; typedef mytype {type bits {"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b;feature f; typedef mytype {type bits {"
"bit automin; bit one;bit two; bit seven {position 7;}bit eight;}} leaf l { type mytype {bit eight;bit seven;bit automin;}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_BITS, type->basetype);
@@ -1260,47 +1263,47 @@
/* invalid cases */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type bits {"
- "bit one {if-feature f;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type bits {"
+ "bit one {if-feature f;}}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid keyword \"if-feature\" as a child of \"bit\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
- "bit one {position -1;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
+ "bit one {position -1;}}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid value \"-1\" of \"position\". Line number 1.");
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
- "bit one {position 4294967296;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
+ "bit one {position 4294967296;}}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid value \"4294967296\" of \"position\". Line number 1.");
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
- "bit one; bit one;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
+ "bit one; bit one;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Duplicate identifier \"one\" of bit statement. Line number 1.");
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
- "bit '11';}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
+ "bit '11';}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid identifier first character '1'. Line number 1.");
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
- "bit 'x1$1';}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
+ "bit 'x1$1';}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid identifier character '$'. Line number 1.");
- assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type bits;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type bits;}}", LYS_IN_YANG, &mod));
logbuf_assert("Missing bit substatement for bits type. /bb:l");
- assert_null(lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;typedef mytype {type bits {bit one;}}"
- "leaf l {type mytype {bit two;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;typedef mytype {type bits {bit one;}}"
+ "leaf l {type mytype {bit two;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid bits - derived type adds new item \"two\". /cc:l");
- assert_null(lys_parse_mem(ctx, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;typedef mytype {type bits {bit one;}}"
- "leaf l {type mytype {bit one {position 1;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;typedef mytype {type bits {bit one;}}"
+ "leaf l {type mytype {bit one {position 1;}}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid bits - position of the item \"one\" has changed from 0 to 1 in the derived type. /dd:l");
- assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type bits {bit x {position 4294967295;}bit y;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type bits {bit x {position 4294967295;}bit y;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid bits - it is not possible to auto-assign bit position for \"y\" since the highest value is already 4294967295. /ee:l");
- assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type bits {bit x {position 1;}bit y {position 1;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type bits {bit x {position 1;}bit y {position 1;}}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid bits - position 1 collide in items \"y\" and \"x\". /ff:l");
- assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;typedef mytype {type bits;}"
- "leaf l {type mytype {bit one;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;typedef mytype {type bits;}"
+ "leaf l {type mytype {bit one;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Missing bit substatement for bits type mytype. /gg:l");
- assert_null(lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh; typedef mytype {type bits {bit one;}}"
- "leaf l {type mytype {bit one;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh; typedef mytype {type bits {bit one;}}"
+ "leaf l {type mytype {bit one;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Bits type can be subtyped only in YANG 1.1 modules. /hh:l");
*state = NULL;
@@ -1313,13 +1316,13 @@
*state = test_type_dec64;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_type *type;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;leaf l {type decimal64 {"
- "fraction-digits 2;range min..max;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;leaf l {type decimal64 {"
+ "fraction-digits 2;range min..max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_DEC64, type->basetype);
@@ -1330,8 +1333,8 @@
assert_int_equal(INT64_C(-9223372036854775807) - INT64_C(1), ((struct lysc_type_dec*)type)->range->parts[0].min_64);
assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_dec*)type)->range->parts[0].max_64);
- assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;typedef mytype {type decimal64 {"
- "fraction-digits 2;range '3.14 | 5.1 | 10';}}leaf l {type mytype;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;typedef mytype {type decimal64 {"
+ "fraction-digits 2;range '3.14 | 5.1 | 10';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_DEC64, type->basetype);
@@ -1346,8 +1349,8 @@
assert_int_equal(1000, ((struct lysc_type_dec*)type)->range->parts[2].min_64);
assert_int_equal(1000, ((struct lysc_type_dec*)type)->range->parts[2].max_64);
- assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
- "fraction-digits 2;range '1 .. 65535';}}leaf l {type mytype;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
+ "fraction-digits 2;range '1 .. 65535';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_int_equal(LY_TYPE_DEC64, type->basetype);
assert_int_equal(2, ((struct lysc_type_dec*)type)->fraction_digits);
@@ -1358,40 +1361,40 @@
assert_int_equal(6553500, ((struct lysc_type_dec*)type)->range->parts[0].max_64);
/* invalid cases */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 0;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 0;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid value \"0\" of \"fraction-digits\". Line number 1.");
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits -1;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits -1;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid value \"-1\" of \"fraction-digits\". Line number 1.");
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 19;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 19;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Value \"19\" is out of \"fraction-digits\" bounds. Line number 1.");
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64;}}", LYS_IN_YANG, &mod));
logbuf_assert("Missing fraction-digits substatement for decimal64 type. /aa:l");
- assert_null(lys_parse_mem(ctx, "module ab {namespace urn:ab;prefix ab; typedef mytype {type decimal64;}leaf l {type mytype;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ab {namespace urn:ab;prefix ab; typedef mytype {type decimal64;}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
logbuf_assert("Missing fraction-digits substatement for decimal64 type mytype. /ab:l");
- assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type decimal64 {fraction-digits 2;"
- "range '3.142';}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type decimal64 {fraction-digits 2;"
+ "range '3.142';}}}", LYS_IN_YANG, &mod));
logbuf_assert("Range boundary \"3.142\" of decimal64 type exceeds defined number (2) of fraction digits. /bb:l");
- assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; leaf l {type decimal64 {fraction-digits 2;"
- "range '4 | 3.14';}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; leaf l {type decimal64 {fraction-digits 2;"
+ "range '4 | 3.14';}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid range restriction - values are not in ascending order (3.14). /cc:l");
- assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; typedef mytype {type decimal64 {fraction-digits 2;}}"
- "leaf l {type mytype {fraction-digits 3;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; typedef mytype {type decimal64 {fraction-digits 2;}}"
+ "leaf l {type mytype {fraction-digits 3;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid fraction-digits substatement for type not directly derived from decimal64 built-in type. /dd:l");
- assert_null(lys_parse_mem(ctx, "module de {namespace urn:de;prefix de; typedef mytype {type decimal64 {fraction-digits 2;}}"
- "typedef mytype2 {type mytype {fraction-digits 3;}}leaf l {type mytype2;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module de {namespace urn:de;prefix de; typedef mytype {type decimal64 {fraction-digits 2;}}"
+ "typedef mytype2 {type mytype {fraction-digits 3;}}leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid fraction-digits substatement for type \"mytype2\" not directly derived from decimal64 built-in type. /de:l");
- assert_null(lys_parse_mem(ctx, "module ee {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
- "fraction-digits 18;range '-10 .. 0';}}leaf l {type mytype;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
+ "fraction-digits 18;range '-10 .. 0';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid range restriction - invalid value \"-10000000000000000000\". /ee:l");
- assert_null(lys_parse_mem(ctx, "module ee {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
- "fraction-digits 18;range '0 .. 10';}}leaf l {type mytype;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
+ "fraction-digits 18;range '0 .. 10';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid range restriction - invalid value \"10000000000000000000\". /ee:l");
*state = NULL;
@@ -1404,14 +1407,14 @@
*state = test_type_instanceid;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_type *type;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;typedef mytype {type instance-identifier {require-instance false;}}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;typedef mytype {type instance-identifier {require-instance false;}}"
"leaf l1 {type instance-identifier {require-instance true;}}"
- "leaf l2 {type mytype;} leaf l3 {type instance-identifier;}}", LYS_IN_YANG));
+ "leaf l2 {type mytype;} leaf l3 {type instance-identifier;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_INST, type->basetype);
@@ -1428,10 +1431,10 @@
assert_int_equal(1, ((struct lysc_type_instanceid*)type)->require_instance);
/* invalid cases */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {require-instance yes;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {require-instance yes;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid value \"yes\" of \"require-instance\". Line number 1.");
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {fraction-digits 1;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {fraction-digits 1;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid type restrictions for instance-identifier type. /aa:l");
*state = NULL;
@@ -1444,14 +1447,14 @@
*state = test_type_identityref;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_type *type;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;identity i; identity j; identity k {base i;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;identity i; identity j; identity k {base i;}"
"typedef mytype {type identityref {base i;}}"
- "leaf l1 {type mytype;} leaf l2 {type identityref {base a:k; base j;}}}", LYS_IN_YANG));
+ "leaf l1 {type mytype;} leaf l2 {type identityref {base a:k; base j;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_IDENT, type->basetype);
@@ -1467,8 +1470,8 @@
assert_string_equal("k", ((struct lysc_type_identityref*)type)->bases[0]->name);
assert_string_equal("j", ((struct lysc_type_identityref*)type)->bases[1]->name);
- assert_non_null(mod = lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b;import a {prefix a;}"
- "leaf l {type identityref {base a:k; base a:j;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b;import a {prefix a;}"
+ "leaf l {type identityref {base a:k; base a:j;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_IDENT, type->basetype);
@@ -1478,29 +1481,29 @@
assert_string_equal("j", ((struct lysc_type_identityref*)type)->bases[1]->name);
/* invalid cases */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type identityref;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type identityref;}}", LYS_IN_YANG, &mod));
logbuf_assert("Missing base substatement for identityref type. /aa:l");
- assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; typedef mytype {type identityref;}"
- "leaf l {type mytype;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; typedef mytype {type identityref;}"
+ "leaf l {type mytype;}}", LYS_IN_YANG, &mod));
logbuf_assert("Missing base substatement for identityref type mytype. /bb:l");
- assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; identity i; typedef mytype {type identityref {base i;}}"
- "leaf l {type mytype {base i;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; identity i; typedef mytype {type identityref {base i;}}"
+ "leaf l {type mytype {base i;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid base substatement for the type not directly derived from identityref built-in type. /cc:l");
- assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; identity i; typedef mytype {type identityref {base i;}}"
- "typedef mytype2 {type mytype {base i;}}leaf l {type mytype2;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; identity i; typedef mytype {type identityref {base i;}}"
+ "typedef mytype2 {type mytype {base i;}}leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid base substatement for the type \"mytype2\" not directly derived from identityref built-in type. /dd:l");
- assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee; identity i; identity j;"
- "leaf l {type identityref {base i;base j;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee; identity i; identity j;"
+ "leaf l {type identityref {base i;base j;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Multiple bases in identityref type are allowed only in YANG 1.1 modules. /ee:l");
- assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff; identity i;leaf l {type identityref {base j;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff; identity i;leaf l {type identityref {base j;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Unable to find base (j) of identityref. /ff:l");
- assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;leaf l {type identityref {base x:j;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;leaf l {type identityref {base x:j;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid prefix used for base (x:j) of identityref. /gg:l");
*state = NULL;
@@ -1513,7 +1516,7 @@
*state = test_type_leafref;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_type *type;
const char *path, *name, *prefix;
size_t prefix_len, name_len;
@@ -1582,9 +1585,9 @@
assert_int_equal(0, has_predicate);
/* complete leafref paths */
- assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;"
"leaf ref1 {type leafref {path /a:target1;}} leaf ref2 {type leafref {path /a/target2; require-instance false;}}"
- "leaf target1 {type string;}container a {leaf target2 {type uint8;}}}", LYS_IN_YANG));
+ "leaf target1 {type string;}container a {leaf target2 {type uint8;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
@@ -1602,9 +1605,9 @@
assert_int_equal(LY_TYPE_UINT8, ((struct lysc_type_leafref*)type)->realtype->basetype);
assert_int_equal(0, ((struct lysc_type_leafref*)type)->require_instance);
- assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; typedef mytype {type leafref {path /b:target;}}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; typedef mytype {type leafref {path /b:target;}}"
"typedef mytype2 {type mytype;} typedef mytype3 {type leafref {path /target;}} leaf ref {type mytype2;}"
- "leaf target {type leafref {path ../realtarget;}} leaf realtarget {type string;}}", LYS_IN_YANG));
+ "leaf target {type leafref {path ../realtarget;}} leaf realtarget {type string;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
@@ -1616,9 +1619,9 @@
assert_int_equal(1, ((struct lysc_type_leafref* )type)->require_instance);
/* prefixes are reversed to check using correct context of the path! */
- assert_non_null(mod = lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix b; import b {prefix c;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix b; import b {prefix c;}"
"typedef mytype3 {type c:mytype {require-instance false;}}"
- "leaf ref1 {type b:mytype3;}leaf ref2 {type c:mytype2;}}", LYS_IN_YANG));
+ "leaf ref1 {type b:mytype3;}leaf ref2 {type c:mytype2;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
@@ -1637,8 +1640,8 @@
assert_int_equal(1, ((struct lysc_type_leafref* )type)->require_instance);
/* non-prefixed nodes in path are supposed to be from the module where the leafref type is instantiated */
- assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; import b {prefix b;}"
- "leaf ref {type b:mytype3;}leaf target {type int8;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; import b {prefix b;}"
+ "leaf ref {type b:mytype3;}leaf target {type int8;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
@@ -1650,9 +1653,9 @@
assert_int_equal(1, ((struct lysc_type_leafref* )type)->require_instance);
/* conditional leafrefs */
- assert_non_null(mod = lys_parse_mem(ctx, "module e {yang-version 1.1;namespace urn:e;prefix e;feature f1; feature f2;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {yang-version 1.1;namespace urn:e;prefix e;feature f1; feature f2;"
"leaf ref1 {if-feature 'f1 and f2';type leafref {path /target;}}"
- "leaf target {if-feature f1; type boolean;}}", LYS_IN_YANG));
+ "leaf target {if-feature f1; type boolean;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
@@ -1662,11 +1665,11 @@
assert_non_null(((struct lysc_type_leafref*)type)->realtype);
assert_int_equal(LY_TYPE_BOOL, ((struct lysc_type_leafref*)type)->realtype->basetype);
- assert_non_null(mod = lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;"
"list interface{key name;leaf name{type string;}list address {key ip;leaf ip {type string;}}}"
"container default-address{leaf ifname{type leafref{ path \"../../interface/name\";}}"
"leaf address {type leafref{ path \"../../interface[ name = current()/../ifname ]/address/ip\";}}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)(*lysc_node_children_p(mod->compiled->data->prev, 0))->prev)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
@@ -1677,10 +1680,10 @@
assert_non_null(((struct lysc_type_leafref*)type)->realtype);
assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref*)type)->realtype->basetype);
- assert_non_null(mod = lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;"
"leaf source {type leafref {path \"/endpoint-parent[id=current()/../field]/endpoint/name\";}}"
"leaf field {type int32;}list endpoint-parent {key id;leaf id {type int32;}"
- "list endpoint {key name;leaf name {type string;}}}}", LYS_IN_YANG));
+ "list endpoint {key name;leaf name {type string;}}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
@@ -1692,8 +1695,8 @@
/* leafref to imported (not yet implemented) module */
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module h {namespace urn:h;prefix h; leaf h {type uint16;}}");
- assert_non_null(mod = lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;import h {prefix h;}"
- "leaf i {type leafref {path /h:h;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;import h {prefix h;}"
+ "leaf i {type leafref {path /h:h;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
@@ -1705,9 +1708,9 @@
assert_string_equal("h", mod->compiled->data->name);
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module j {namespace urn:j;prefix j; leaf j {type string;}}");
- assert_non_null(mod = lys_parse_mem(ctx, "module k {namespace urn:k;prefix k;import j {prefix j;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module k {namespace urn:k;prefix k;import j {prefix j;}"
"leaf i {type leafref {path \"/ilist[name = current()/../j:j]/value\";}}"
- "list ilist {key name; leaf name {type string;} leaf value {type uint16;}}}", LYS_IN_YANG));
+ "list ilist {key name; leaf name {type string;} leaf value {type uint16;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
@@ -1719,9 +1722,9 @@
assert_string_equal("j", mod->compiled->data->name);
/* leafref with a default value */
- assert_non_null(mod = lys_parse_mem(ctx, "module l {namespace urn:l;prefix l;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module l {namespace urn:l;prefix l;"
"leaf source {type leafref {path \"../target\";}default true;}"
- "leaf target {type boolean;}}", LYS_IN_YANG));
+ "leaf target {type boolean;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
@@ -1734,169 +1737,169 @@
assert_int_equal(1, ((struct lysc_node_leaf*)mod->compiled->data)->dflt->boolean);
/* invalid paths */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;container a {leaf target2 {type uint8;}}"
- "leaf ref1 {type leafref {path ../a/invalid;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;container a {leaf target2 {type uint8;}}"
+ "leaf ref1 {type leafref {path ../a/invalid;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Not found node \"invalid\" in path.");
- assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;container a {leaf target2 {type uint8;}}"
- "leaf ref1 {type leafref {path ../../toohigh;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;container a {leaf target2 {type uint8;}}"
+ "leaf ref1 {type leafref {path ../../toohigh;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Too many parent references in path.");
- assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;container a {leaf target2 {type uint8;}}"
- "leaf ref1 {type leafref {path /a:invalid;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;container a {leaf target2 {type uint8;}}"
+ "leaf ref1 {type leafref {path /a:invalid;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Prefix \"a\" not found of a module in path.");
- assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;leaf target1 {type string;}"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;leaf target1 {type string;}"
"container a {leaf target2 {type uint8;}} leaf ref1 {type leafref {"
- "path '/a[target2 = current()/../target1]/target2';}}}", LYS_IN_YANG));
+ "path '/a[target2 = current()/../target1]/target2';}}}", LYS_IN_YANG, &mod));
logbuf_assert("List predicate defined for container \"a\" in path.");
- assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;container a {leaf target2 {type uint8;}}"
- "leaf ref1 {type leafref {path /a!invalid;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;container a {leaf target2 {type uint8;}}"
+ "leaf ref1 {type leafref {path /a!invalid;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid character 0x21 ('!'), perhaps \"a\" is supposed to be a function call.");
- assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;container a {leaf target2 {type uint8;}}"
- "leaf ref1 {type leafref {path /a;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;container a {leaf target2 {type uint8;}}"
+ "leaf ref1 {type leafref {path /a;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid leafref path \"/a\" - target node is container instead of leaf or leaf-list. /ff:ref1");
- assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;container a {leaf target2 {type uint8;"
- "status deprecated;}} leaf ref1 {type leafref {path /a/target2;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;container a {leaf target2 {type uint8;"
+ "status deprecated;}} leaf ref1 {type leafref {path /a/target2;}}}", LYS_IN_YANG, &mod));
logbuf_assert("A current definition \"ref1\" is not allowed to reference deprecated definition \"target2\". /gg:ref1");
- assert_null(lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;"
- "leaf ref1 {type leafref;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;"
+ "leaf ref1 {type leafref;}}", LYS_IN_YANG, &mod));
logbuf_assert("Missing path substatement for leafref type. /hh:ref1");
- assert_null(lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;typedef mytype {type leafref;}"
- "leaf ref1 {type mytype;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;typedef mytype {type leafref;}"
+ "leaf ref1 {type mytype;}}", LYS_IN_YANG, &mod));
logbuf_assert("Missing path substatement for leafref type mytype. /ii:ref1");
- assert_null(lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;feature f;"
- "leaf ref {type leafref {path /target;}}leaf target {if-feature f;type string;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;feature f;"
+ "leaf ref {type leafref {path /target;}}leaf target {if-feature f;type string;}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid leafref path \"/target\" - set of features applicable to the leafref target is not a subset of features "
"applicable to the leafref itself. /jj:ref");
- assert_null(lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;"
- "leaf ref {type leafref {path /target;}}leaf target {type string;config false;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;"
+ "leaf ref {type leafref {path /target;}}leaf target {type string;config false;}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid leafref path \"/target\" - target is supposed to represent configuration data (as the leafref does), but it does not. /kk:ref");
- assert_null(lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;"
- "leaf ref {type leafref {path /target; require-instance true;}}leaf target {type string;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;"
+ "leaf ref {type leafref {path /target; require-instance true;}}leaf target {type string;}}", LYS_IN_YANG, &mod));
logbuf_assert("Leafref type can be restricted by require-instance statement only in YANG 1.1 modules. /ll:ref");
- assert_null(lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;typedef mytype {type leafref {path /target;require-instance false;}}"
- "leaf ref {type mytype;}leaf target {type string;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;typedef mytype {type leafref {path /target;require-instance false;}}"
+ "leaf ref {type mytype;}leaf target {type string;}}", LYS_IN_YANG, &mod));
logbuf_assert("Leafref type \"mytype\" can be restricted by require-instance statement only in YANG 1.1 modules. /mm:ref");
- assert_null(lys_parse_mem(ctx, "module nn {namespace urn:nn;prefix nn;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module nn {namespace urn:nn;prefix nn;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}"
"leaf address {type leafref{ path \"/interface[name is current()/../ifname]/ip\";}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
logbuf_assert("Invalid character 0x69 ('i'), perhaps \"name\" is supposed to be a function call.");
- assert_null(lys_parse_mem(ctx, "module oo {namespace urn:oo;prefix oo;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module oo {namespace urn:oo;prefix oo;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}"
"leaf address {type leafref{ path \"/interface[name=current()/../ifname/ip\";}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
logbuf_assert("Unexpected XPath expression end.");
- assert_null(lys_parse_mem(ctx, "module pp {namespace urn:pp;prefix pp;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module pp {namespace urn:pp;prefix pp;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}"
"leaf address {type leafref{ path \"/interface[x:name=current()/../ifname]/ip\";}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
logbuf_assert("Prefix \"x\" not found of a module in path.");
- assert_null(lys_parse_mem(ctx, "module qq {namespace urn:qq;prefix qq;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module qq {namespace urn:qq;prefix qq;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}"
"leaf address {type leafref{ path \"/interface[id=current()/../ifname]/ip\";}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
logbuf_assert("Not found node \"id\" in path.");
- assert_null(lys_parse_mem(ctx, "module rr {namespace urn:rr;prefix rr;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module rr {namespace urn:rr;prefix rr;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
"leaf address {type leafref{ path \"/interface[name=current() / .. / ifname][name=current()/../test]/ip\";}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
logbuf_assert("Duplicate predicate key \"name\" in path.");
- assert_null(lys_parse_mem(ctx, "module ss {namespace urn:ss;prefix ss;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ss {namespace urn:ss;prefix ss;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
"leaf address {type leafref{ path \"/interface[name = ../ifname]/ip\";}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
logbuf_assert("Unexpected XPath token .. (../ifname]/ip).");
- assert_null(lys_parse_mem(ctx, "module tt {namespace urn:tt;prefix tt;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module tt {namespace urn:tt;prefix tt;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
"leaf address {type leafref{ path \"/interface[name = current()../ifname]/ip\";}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
logbuf_assert("Unexpected XPath token .. (../ifname]/ip).");
- assert_null(lys_parse_mem(ctx, "module uu {namespace urn:uu;prefix uu;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module uu {namespace urn:uu;prefix uu;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
"leaf address {type leafref{ path \"/interface[name = current()/..ifname]/ip\";}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
logbuf_assert("Invalid character number 31 of expression '/interface[name = current()/..ifname]/ip'.");
- assert_null(lys_parse_mem(ctx, "module vv {namespace urn:vv;prefix vv;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module vv {namespace urn:vv;prefix vv;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
"leaf address {type leafref{ path \"/interface[name = current()/ifname]/ip\";}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
logbuf_assert("Unexpected XPath token NameTest (ifname]/ip).");
- assert_null(lys_parse_mem(ctx, "module ww {namespace urn:ww;prefix ww;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ww {namespace urn:ww;prefix ww;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
"leaf address {type leafref{ path \"/interface[name = current()/../]/ip\";}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
logbuf_assert("Unexpected XPath token ] (]/ip).");
- assert_null(lys_parse_mem(ctx, "module xx {namespace urn:xx;prefix xx;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module xx {namespace urn:xx;prefix xx;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
"leaf address {type leafref{ path \"/interface[name = current()/../$node]/ip\";}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
logbuf_assert("Invalid character 0x24 ('$'), perhaps \"\" is supposed to be a function call.");
- assert_null(lys_parse_mem(ctx, "module yy {namespace urn:yy;prefix yy;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module yy {namespace urn:yy;prefix yy;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}"
"leaf address {type leafref{ path \"/interface[name=current()/../x:ifname]/ip\";}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
logbuf_assert("Prefix \"x\" not found of a module in path.");
- assert_null(lys_parse_mem(ctx, "module zz {namespace urn:zz;prefix zz;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module zz {namespace urn:zz;prefix zz;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}"
"leaf address {type leafref{ path \"/interface[name=current()/../xxx]/ip\";}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
logbuf_assert("Not found node \"xxx\" in path.");
- assert_null(lys_parse_mem(ctx, "module zza {namespace urn:zza;prefix zza;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module zza {namespace urn:zza;prefix zza;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}container c;"
"leaf address {type leafref{ path \"/interface[name=current()/../c]/ip\";}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
logbuf_assert("Leaf expected instead of container \"c\" in leafref predicate in path.");
- assert_null(lys_parse_mem(ctx, "module zzb {namespace urn:zzb;prefix zzb;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module zzb {namespace urn:zzb;prefix zzb;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}container c;}"
"leaf ifname{type leafref{ path \"../interface/name\";}}"
"leaf address {type leafref{ path \"/interface[c=current()/../ifname]/ip\";}}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
logbuf_assert("Key expected instead of container \"c\" in path.");
- assert_null(lys_parse_mem(ctx, "module zzc {namespace urn:zzc;prefix zzc;"
- "leaf source {type leafref {path \"../target\";}default true;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module zzc {namespace urn:zzc;prefix zzc;"
+ "leaf source {type leafref {path \"../target\";}default true;}}", LYS_IN_YANG, &mod));
logbuf_assert("Not found node \"target\" in path.");
- assert_null(lys_parse_mem(ctx, "module zzd {namespace urn:zzd;prefix zzd;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module zzd {namespace urn:zzd;prefix zzd;"
"leaf source {type leafref {path \"../target\";}default true;}"
- "leaf target {type uint8;}}", LYS_IN_YANG));
+ "leaf target {type uint8;}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid default - value does not fit the type (Invalid uint8 value \"true\".). /zzd:source");
/* circular chain */
- assert_null(lys_parse_mem(ctx, "module aaa {namespace urn:aaa;prefix aaa;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aaa {namespace urn:aaa;prefix aaa;"
"leaf ref1 {type leafref {path /ref2;}}"
"leaf ref2 {type leafref {path /ref3;}}"
"leaf ref3 {type leafref {path /ref4;}}"
- "leaf ref4 {type leafref {path /ref1;}}}", LYS_IN_YANG));
+ "leaf ref4 {type leafref {path /ref1;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid leafref path \"/ref1\" - circular chain of leafrefs detected. /aaa:ref4");
*state = NULL;
@@ -1913,12 +1916,12 @@
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
/* invalid */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
- "leaf l {type empty; default x;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
+ "leaf l {type empty; default x;}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid leaf's default value \"x\" which does not fit the type (Invalid empty value \"x\".). /aa:l");
- assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;typedef mytype {type empty; default x;}"
- "leaf l {type mytype;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;typedef mytype {type empty; default x;}"
+ "leaf l {type mytype;}}", LYS_IN_YANG, NULL));
logbuf_assert("Invalid type \"mytype\" - \"empty\" type must not have a default value (x). /bb:l");
*state = NULL;
@@ -1931,14 +1934,14 @@
*state = test_type_union;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_type *type;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a; typedef mybasetype {type string;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a; typedef mybasetype {type string;}"
"typedef mytype {type union {type int8; type mybasetype;}}"
- "leaf l {type mytype;}}", LYS_IN_YANG));
+ "leaf l {type mytype;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(2, type->refcount);
@@ -1948,9 +1951,9 @@
assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_union*)type)->types[0]->basetype);
assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union*)type)->types[1]->basetype);
- assert_non_null(mod = lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b; typedef mybasetype {type string;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b; typedef mybasetype {type string;}"
"typedef mytype {type union {type int8; type mybasetype;}}"
- "leaf l {type union {type decimal64 {fraction-digits 2;} type mytype;}}}", LYS_IN_YANG));
+ "leaf l {type union {type decimal64 {fraction-digits 2;} type mytype;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
@@ -1961,11 +1964,11 @@
assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_union*)type)->types[1]->basetype);
assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union*)type)->types[2]->basetype);
- assert_non_null(mod = lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c; typedef mybasetype {type string;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c; typedef mybasetype {type string;}"
"typedef mytype {type union {type leafref {path ../target;} type mybasetype;}}"
"leaf l {type union {type decimal64 {fraction-digits 2;} type mytype;}}"
"leaf target {type leafref {path ../realtarget;}} leaf realtarget {type int8;}}",
- LYS_IN_YANG));
+ LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
@@ -1979,26 +1982,26 @@
assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref*)((struct lysc_type_union*)type)->types[1])->realtype->basetype);
/* invalid unions */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;typedef mytype {type union;}"
- "leaf l {type mytype;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;typedef mytype {type union;}"
+ "leaf l {type mytype;}}", LYS_IN_YANG, &mod));
logbuf_assert("Missing type substatement for union type mytype. /aa:l");
- assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf l {type union;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf l {type union;}}", LYS_IN_YANG, &mod));
logbuf_assert("Missing type substatement for union type. /bb:l");
- assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;typedef mytype {type union{type int8; type string;}}"
- "leaf l {type mytype {type string;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;typedef mytype {type union{type int8; type string;}}"
+ "leaf l {type mytype {type string;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid type substatement for the type not directly derived from union built-in type. /cc:l");
- assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;typedef mytype {type union{type int8; type string;}}"
- "typedef mytype2 {type mytype {type string;}}leaf l {type mytype2;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;typedef mytype {type union{type int8; type string;}}"
+ "typedef mytype2 {type mytype {type string;}}leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid type substatement for the type \"mytype2\" not directly derived from union built-in type. /dd:l");
- assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;typedef mytype {type union{type mytype; type string;}}"
- "leaf l {type mytype;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;typedef mytype {type union{type mytype; type string;}}"
+ "leaf l {type mytype;}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid \"mytype\" type reference - circular chain of types detected. /ee:l");
- assert_null(lys_parse_mem(ctx, "module ef {namespace urn:ef;prefix ef;typedef mytype {type mytype2;}"
- "typedef mytype2 {type mytype;} leaf l {type mytype;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ef {namespace urn:ef;prefix ef;typedef mytype {type mytype2;}"
+ "typedef mytype2 {type mytype;} leaf l {type mytype;}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid \"mytype\" type reference - circular chain of types detected. /ef:l");
*state = NULL;
@@ -2011,7 +2014,7 @@
*state = test_type_union;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_type *type;
struct lysc_node_leaf *leaf;
int dynamic;
@@ -2019,8 +2022,8 @@
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
/* default is not inherited from union's types */
- assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a; typedef mybasetype {type string;default hello;units xxx;}"
- "leaf l {type union {type decimal64 {fraction-digits 2;} type mybasetype;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a; typedef mybasetype {type string;default hello;units xxx;}"
+ "leaf l {type union {type decimal64 {fraction-digits 2;} type mybasetype;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
@@ -2032,8 +2035,8 @@
assert_null(((struct lysc_node_leaf*)mod->compiled->data)->dflt);
assert_null(((struct lysc_node_leaf*)mod->compiled->data)->units);
- assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; typedef mybasetype {type string;default hello;units xxx;}"
- "leaf l {type mybasetype;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; typedef mybasetype {type string;default hello;units xxx;}"
+ "leaf l {type mybasetype;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(3, type->refcount); /* 2x type reference, 1x default value's reference (typedf's default does not reference own type)*/
@@ -2043,8 +2046,8 @@
assert_int_equal(0, dynamic);
assert_string_equal("xxx", leaf->units);
- assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:c;prefix c; typedef mybasetype {type string;default hello;units xxx;}"
- "leaf l {type mybasetype; default goodbye;units yyy;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c; typedef mybasetype {type string;default hello;units xxx;}"
+ "leaf l {type mybasetype; default goodbye;units yyy;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(3, type->refcount); /* 2x type reference, 1x default value's reference */
@@ -2054,9 +2057,9 @@
assert_int_equal(0, dynamic);
assert_string_equal("yyy", leaf->units);
- assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; typedef mybasetype {type string;default hello;units xxx;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; typedef mybasetype {type string;default hello;units xxx;}"
"typedef mytype {type mybasetype;}leaf l1 {type mytype; default goodbye;units yyy;}"
- "leaf l2 {type mytype;}}", LYS_IN_YANG));
+ "leaf l2 {type mytype;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(6, type->refcount); /* 4x type reference, 2x default value's reference (1 shared compiled type of typedefs which default does not reference own type) */
@@ -2074,8 +2077,8 @@
assert_int_equal(0, dynamic);
assert_string_equal("xxx", leaf->units);
- assert_non_null(mod = lys_parse_mem(ctx, "module e {namespace urn:e;prefix e; typedef mybasetype {type string;}"
- "typedef mytype {type mybasetype; default hello;units xxx;}leaf l {type mytype;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {namespace urn:e;prefix e; typedef mybasetype {type string;}"
+ "typedef mytype {type mybasetype; default hello;units xxx;}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(4, type->refcount); /* 3x type reference, 1x default value's reference (typedef's default does not reference own type) */
@@ -2086,8 +2089,8 @@
assert_string_equal("xxx", leaf->units);
/* mandatory leaf does not takes default value from type */
- assert_non_null(mod = lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;typedef mytype {type string; default hello;units xxx;}"
- "leaf l {type mytype; mandatory true;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;typedef mytype {type string; default hello;units xxx;}"
+ "leaf l {type mytype; mandatory true;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_STRING, type->basetype);
@@ -2107,21 +2110,21 @@
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
- "container c {status deprecated; leaf l {status current; type string;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
+ "container c {status deprecated; leaf l {status current; type string;}}}", LYS_IN_YANG, NULL));
logbuf_assert("A \"current\" status is in conflict with the parent's \"deprecated\" status. /aa:c/l");
- assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;"
- "container c {status obsolete; leaf l {status current; type string;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;"
+ "container c {status obsolete; leaf l {status current; type string;}}}", LYS_IN_YANG, NULL));
logbuf_assert("A \"current\" status is in conflict with the parent's \"obsolete\" status. /bb:c/l");
- assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;"
- "container c {status obsolete; leaf l {status deprecated; type string;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;"
+ "container c {status obsolete; leaf l {status deprecated; type string;}}}", LYS_IN_YANG, NULL));
logbuf_assert("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status. /cc:c/l");
- assert_null(lys_parse_mem(ctx, "module cc {namespace urn:dd;prefix d;"
- "container c {leaf l {status obsolete; type string;}}"
- "container d {leaf m {when \"../../c/l\"; type string;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:dd;prefix d;"
+ "container c {leaf l {status obsolete; type string;}}"
+ "container d {leaf m {when \"../../c/l\"; type string;}}}", LYS_IN_YANG, NULL));
logbuf_assert("A current definition \"m\" is not allowed to reference obsolete definition \"l\". /cc:d/m");
*state = NULL;
@@ -2138,25 +2141,25 @@
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
/* result ok, but a warning about not used locally scoped grouping printed */
- assert_non_null(lys_parse_mem(ctx, "module a {namespace urn:a;prefix a; grouping grp1 {leaf a1 {type string;}}"
- "container a {leaf x {type string;} grouping grp2 {leaf a2 {type string;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a; grouping grp1 {leaf a1 {type string;}}"
+ "container a {leaf x {type string;} grouping grp2 {leaf a2 {type string;}}}}", LYS_IN_YANG, NULL));
logbuf_assert("Locally scoped grouping \"grp2\" not used.");
logbuf_clean();
/* result ok - when statement or leafref target must be checked only at the place where the grouping is really instantiated */
- assert_non_null(lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; grouping grp {"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; grouping grp {"
"leaf ref {type leafref {path \"../name\";}}"
- "leaf cond {type string; when \"../name = 'specialone'\";}}}", LYS_IN_YANG));
+ "leaf cond {type string; when \"../name = 'specialone'\";}}}", LYS_IN_YANG, NULL));
logbuf_assert("");
/* invalid - error in a non-instantiated grouping */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
- "grouping grp {leaf x {type leafref;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
+ "grouping grp {leaf x {type leafref;}}}", LYS_IN_YANG, NULL));
logbuf_assert("Missing path substatement for leafref type. /aa:{grouping='grp'}/x");
logbuf_clean();
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
- "container a {grouping grp {leaf x {type leafref;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
+ "container a {grouping grp {leaf x {type leafref;}}}}", LYS_IN_YANG, NULL));
logbuf_assert("Missing path substatement for leafref type. /aa:a/{grouping='grp'}/x");
@@ -2170,7 +2173,7 @@
*state = test_uses;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
const struct lysc_node *parent, *child;
const struct lysc_node_container *cont;
@@ -2178,9 +2181,9 @@
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module grp {namespace urn:grp;prefix g; typedef mytype {type string;} feature f;"
"grouping grp {leaf x {type mytype;} leaf y {type string; if-feature f;}}}");
- assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;import grp {prefix g;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;import grp {prefix g;}"
"grouping grp_a_top {leaf a1 {type int8;}}"
- "container a {uses grp_a; uses grp_a_top; uses g:grp; grouping grp_a {leaf a2 {type uint8;}}}}", LYS_IN_YANG));
+ "container a {uses grp_a; uses grp_a_top; uses g:grp; grouping grp_a {leaf a2 {type uint8;}}}}", LYS_IN_YANG, &mod));
assert_non_null((parent = mod->compiled->data));
assert_int_equal(LYS_CONTAINER, parent->nodetype);
assert_non_null((child = ((struct lysc_node_container*)parent)->child));
@@ -2204,13 +2207,13 @@
/* make the imported module implemented and enable the feature */
assert_non_null(mod = ly_ctx_get_module(ctx, "grp", NULL));
- assert_int_equal(LY_SUCCESS, lys_set_implemented(mod));
+ assert_int_equal(LY_SUCCESS, lys_set_implemented((struct lys_module *)mod));
assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f"));
assert_string_equal("f", child->iffeatures[0].features[0]->name);
assert_int_equal(LY_SUCCESS, lysc_iffeature_value(&child->iffeatures[0]));
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule bsub {belongs-to b {prefix b;} grouping grp {leaf b {when 1; type string;} leaf c {type string;}}}");
- assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;include bsub;uses grp {when 2;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;include bsub;uses grp {when 2;}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled->data);
assert_int_equal(LYS_LEAF, mod->compiled->data->nodetype);
assert_string_equal("b", mod->compiled->data->name);
@@ -2228,9 +2231,9 @@
assert_null(mod->compiled->data->next->when[0]->context);
logbuf_clean();
- assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:ii;prefix ii;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:ii;prefix ii;"
"grouping grp {leaf l {type string;}leaf k {type string; status obsolete;}}"
- "uses grp {status deprecated;}}", LYS_IN_YANG));
+ "uses grp {status deprecated;}}", LYS_IN_YANG, &mod));
assert_int_equal(LYS_LEAF, mod->compiled->data->nodetype);
assert_string_equal("l", mod->compiled->data->name);
assert_true(LYS_STATUS_DEPRC & mod->compiled->data->flags);
@@ -2239,16 +2242,16 @@
assert_true(LYS_STATUS_OBSLT & mod->compiled->data->next->flags);
logbuf_assert(""); /* no warning about inheriting deprecated flag from uses */
- assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; grouping grp {container g;}"
- "container top {uses grp {augment g {leaf x {type int8;}}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; grouping grp {container g;}"
+ "container top {uses grp {augment g {leaf x {type int8;}}}}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled->data);
assert_non_null(child = lysc_node_children(mod->compiled->data, 0));
assert_string_equal("g", child->name);
assert_non_null(child = lysc_node_children(child, 0));
assert_string_equal("x", child->name);
- assert_non_null(mod = lys_parse_mem(ctx, "module e {yang-version 1.1;namespace urn:e;prefix e; grouping grp {action g { description \"super g\";}}"
- "container top {action e; uses grp {refine g {description \"ultra g\";}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {yang-version 1.1;namespace urn:e;prefix e; grouping grp {action g { description \"super g\";}}"
+ "container top {action e; uses grp {refine g {description \"ultra g\";}}}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled->data);
cont = (const struct lysc_node_container*)mod->compiled->data;
assert_non_null(cont->actions);
@@ -2257,8 +2260,8 @@
assert_string_equal("g", cont->actions[0].name);
assert_string_equal("ultra g", cont->actions[0].dsc);
- assert_non_null(mod = lys_parse_mem(ctx, "module f {yang-version 1.1;namespace urn:f;prefix f; grouping grp {notification g { description \"super g\";}}"
- "container top {notification f; uses grp {refine g {description \"ultra g\";}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {yang-version 1.1;namespace urn:f;prefix f; grouping grp {notification g { description \"super g\";}}"
+ "container top {notification f; uses grp {refine g {description \"ultra g\";}}}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled->data);
cont = (const struct lysc_node_container*)mod->compiled->data;
assert_non_null(cont->notifs);
@@ -2268,56 +2271,56 @@
assert_string_equal("ultra g", cont->notifs[0].dsc);
/* empty grouping */
- assert_non_null(mod = lys_parse_mem(ctx, "module g {namespace urn:g;prefix g; grouping grp; uses grp;}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {namespace urn:g;prefix g; grouping grp; uses grp;}", LYS_IN_YANG, &mod));
assert_null(mod->compiled->data);
/* invalid */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;uses missinggrp;}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;uses missinggrp;}", LYS_IN_YANG, &mod));
logbuf_assert("Grouping \"missinggrp\" referenced by a uses statement not found. /aa:{uses='missinggrp'}");
- assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;uses grp;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;uses grp;"
"grouping grp {leaf a{type string;}uses grp1;}"
"grouping grp1 {leaf b {type string;}uses grp2;}"
- "grouping grp2 {leaf c {type string;}uses grp;}}", LYS_IN_YANG));
+ "grouping grp2 {leaf c {type string;}uses grp;}}", LYS_IN_YANG, &mod));
logbuf_assert("Grouping \"grp\" references itself through a uses statement. /bb:{uses='grp'}/{uses='grp1'}/{uses='grp2'}/{uses='grp'}");
- assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;uses a:missingprefix;}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;uses a:missingprefix;}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid prefix used for grouping reference. /cc:{uses='a:missingprefix'}");
- assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;grouping grp{leaf a{type string;}}"
- "leaf a {type string;}uses grp;}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;grouping grp{leaf a{type string;}}"
+ "leaf a {type string;}uses grp;}", LYS_IN_YANG, &mod));
logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/notification statement. /dd:{uses='grp'}/dd:a");
- assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;grouping grp {leaf l {type string; status deprecated;}}"
- "uses grp {status obsolete;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;grouping grp {leaf l {type string; status deprecated;}}"
+ "uses grp {status obsolete;}}", LYS_IN_YANG, &mod));
logbuf_assert("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status. /ee:{uses='grp'}/ee:l");
- assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;grouping grp {leaf l {type string;}}"
- "leaf l {type int8;}uses grp;}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;grouping grp {leaf l {type string;}}"
+ "leaf l {type int8;}uses grp;}", LYS_IN_YANG, &mod));
logbuf_assert("Duplicate identifier \"l\" of data definition/RPC/action/notification statement. /ff:{uses='grp'}/ff:l");
- assert_null(lys_parse_mem(ctx, "module fg {namespace urn:fg;prefix fg;grouping grp {leaf m {type string;}}"
- "uses grp;leaf m {type int8;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module fg {namespace urn:fg;prefix fg;grouping grp {leaf m {type string;}}"
+ "uses grp;leaf m {type int8;}}", LYS_IN_YANG, &mod));
logbuf_assert("Duplicate identifier \"m\" of data definition/RPC/action/notification statement. /fg:m");
- assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg; grouping grp {container g;}"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg; grouping grp {container g;}"
"leaf g {type string;}"
- "container top {uses grp {augment /g {leaf x {type int8;}}}}}", LYS_IN_YANG));
+ "container top {uses grp {augment /g {leaf x {type int8;}}}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid descendant-schema-nodeid value \"/g\" - absolute-schema-nodeid used. /gg:top/{uses='grp'}/{augment='/g'}");
- assert_non_null(mod = lys_parse_mem(ctx, "module hh {yang-version 1.1;namespace urn:hh;prefix hh;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module hh {yang-version 1.1;namespace urn:hh;prefix hh;"
"grouping grp {notification g { description \"super g\";}}"
- "container top {notification h; uses grp {refine h {description \"ultra h\";}}}}", LYS_IN_YANG));
+ "container top {notification h; uses grp {refine h {description \"ultra h\";}}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid descendant-schema-nodeid value \"h\" - target node not found. /hh:top/{uses='grp'}/{refine='h'}");
- assert_non_null(mod = lys_parse_mem(ctx, "module ii {yang-version 1.1;namespace urn:ii;prefix ii;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module ii {yang-version 1.1;namespace urn:ii;prefix ii;"
"grouping grp {action g { description \"super g\";}}"
- "container top {action i; uses grp {refine i {description \"ultra i\";}}}}", LYS_IN_YANG));
+ "container top {action i; uses grp {refine i {description \"ultra i\";}}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid descendant-schema-nodeid value \"i\" - target node not found. /ii:top/{uses='grp'}/{refine='i'}");
- assert_null(lys_parse_mem(ctx, "module jj {yang-version 1.1;namespace urn:jj;prefix jj;"
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj {yang-version 1.1;namespace urn:jj;prefix jj;"
"grouping grp {leaf j { when \"1\"; type invalid;}}"
- "container top {uses grp;}}", LYS_IN_YANG));
+ "container top {uses grp;}}", LYS_IN_YANG, &mod));
logbuf_assert("Referenced type \"invalid\" not found. /jj:top/{uses='grp'}/j");
*state = NULL;
@@ -2330,7 +2333,7 @@
*state = test_refine;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
struct lysc_node *parent, *child;
struct lysc_node_leaf *leaf;
struct lysc_node_leaflist *llist;
@@ -2338,21 +2341,21 @@
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_non_null(lys_parse_mem(ctx, "module grp {yang-version 1.1;namespace urn:grp;prefix g; feature f;typedef mytype {type string; default cheers!;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module grp {yang-version 1.1;namespace urn:grp;prefix g; feature f;typedef mytype {type string; default cheers!;}"
"grouping grp {container c {leaf l {type mytype; default goodbye;}"
"leaf-list ll {type mytype; default goodbye; max-elements 6;}"
"choice ch {default a; leaf a {type int8;}leaf b{type uint8;}}"
"leaf x {type mytype; mandatory true; must 1;}"
"anydata a {mandatory false; if-feature f; description original; reference original;}"
- "container c {config false; leaf l {type string;}}}}}", LYS_IN_YANG));
+ "container c {config false; leaf l {type string;}}}}}", LYS_IN_YANG, NULL));
- assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;import grp {prefix g;}feature fa;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;import grp {prefix g;}feature fa;"
"uses g:grp {refine c/l {default hello; config false;}"
"refine c/ll {default hello;default world; min-elements 2; max-elements 5;}"
"refine c/ch {default b;config true; if-feature fa;}"
"refine c/x {mandatory false; must ../ll;description refined; reference refined;}"
"refine c/a {mandatory true; must 1; if-feature fa;description refined; reference refined;}"
- "refine c/c {config true;presence indispensable;}}}", LYS_IN_YANG));
+ "refine c/c {config true;presence indispensable;}}}", LYS_IN_YANG, &mod));
assert_non_null((parent = mod->compiled->data));
assert_int_equal(LYS_CONTAINER, parent->nodetype);
assert_string_equal("c", parent->name);
@@ -2407,8 +2410,8 @@
assert_true(LYS_CONFIG_W & child->flags);
assert_true(LYS_CONFIG_W & ((struct lysc_node_container*)child)->child->flags);
- assert_non_null(mod = lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b;import grp {prefix g;}"
- "uses g:grp {status deprecated; refine c/x {default hello; mandatory false;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b;import grp {prefix g;}"
+ "uses g:grp {status deprecated; refine c/x {default hello; mandatory false;}}}", LYS_IN_YANG, &mod));
assert_non_null((leaf = (struct lysc_node_leaf*)((struct lysc_node_container*)mod->compiled->data)->child->prev->prev->prev));
assert_int_equal(LYS_LEAF, leaf->nodetype);
assert_string_equal("x", leaf->name);
@@ -2417,59 +2420,59 @@
assert_int_equal(0, dynamic);
/* invalid */
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;import grp {prefix g;}"
- "uses g:grp {refine c {default hello;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;import grp {prefix g;}"
+ "uses g:grp {refine c {default hello;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid refine of default - container cannot hold default value(s). /aa:{uses='g:grp'}/{refine='c'}");
- assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;import grp {prefix g;}"
- "uses g:grp {refine c/l {default hello; default world;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;import grp {prefix g;}"
+ "uses g:grp {refine c/l {default hello; default world;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid refine of default - leaf cannot hold 2 default values. /bb:{uses='g:grp'}/{refine='c/l'}");
- assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;import grp {prefix g;}"
- "uses g:grp {refine c/ll {default hello; default world;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;import grp {prefix g;}"
+ "uses g:grp {refine c/ll {default hello; default world;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid refine of default in leaf-list - the default statement is allowed only in YANG 1.1 modules. /cc:{uses='g:grp'}/{refine='c/ll'}");
- assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;import grp {prefix g;}"
- "uses g:grp {refine c/ll {mandatory true;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;import grp {prefix g;}"
+ "uses g:grp {refine c/ll {mandatory true;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid refine of mandatory - leaf-list cannot hold mandatory statement. /dd:{uses='g:grp'}/{refine='c/ll'}");
- assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;import grp {prefix g;}"
- "uses g:grp {refine c/l {mandatory true;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;import grp {prefix g;}"
+ "uses g:grp {refine c/l {mandatory true;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid refine of mandatory - leaf already has \"default\" statement. /ee:{uses='g:grp'}/{refine='c/l'}");
- assert_null(lys_parse_mem(ctx, "module ef {namespace urn:ef;prefix ef;import grp {prefix g;}"
- "uses g:grp {refine c/ch {mandatory true;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ef {namespace urn:ef;prefix ef;import grp {prefix g;}"
+ "uses g:grp {refine c/ch {mandatory true;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid refine of mandatory - choice already has \"default\" statement. /ef:{uses='g:grp'}/{refine='c/ch'}");
- assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;import grp {prefix g;}"
- "uses g:grp {refine c/ch/a/a {mandatory true;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;import grp {prefix g;}"
+ "uses g:grp {refine c/ch/a/a {mandatory true;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid refine of mandatory under the default case. /ff:{uses='g:grp'}/{refine='c/ch/a/a'}");
- assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;import grp {prefix g;}"
- "uses g:grp {refine c/x {default hello;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;import grp {prefix g;}"
+ "uses g:grp {refine c/x {default hello;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid refine of default - the node is mandatory. /gg:{uses='g:grp'}/{refine='c/x'}");
- assert_null(lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;import grp {prefix g;}"
- "uses g:grp {refine c/c/l {config true;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;import grp {prefix g;}"
+ "uses g:grp {refine c/c/l {config true;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid refine of config - configuration node cannot be child of any state data node. /hh:{uses='g:grp'}/{refine='c/c/l'}");
- assert_null(lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;grouping grp {leaf l {type string; status deprecated;}}"
- "uses grp {status obsolete;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;grouping grp {leaf l {type string; status deprecated;}}"
+ "uses grp {status obsolete;}}", LYS_IN_YANG, &mod));
logbuf_assert("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status. /ii:{uses='grp'}/ii:l");
- assert_null(lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;import grp {prefix g;}"
- "uses g:grp {refine c/x {presence nonsence;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;import grp {prefix g;}"
+ "uses g:grp {refine c/x {presence nonsence;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid refine of presence statement - leaf cannot hold the presence statement. /jj:{uses='g:grp'}/{refine='c/x'}");
- assert_null(lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;import grp {prefix g;}"
- "uses g:grp {refine c/ch {must 1;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;import grp {prefix g;}"
+ "uses g:grp {refine c/ch {must 1;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid refine of must statement - choice cannot hold any must statement. /kk:{uses='g:grp'}/{refine='c/ch'}");
- assert_null(lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;import grp {prefix g;}"
- "uses g:grp {refine c/x {min-elements 1;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;import grp {prefix g;}"
+ "uses g:grp {refine c/x {min-elements 1;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid refine of min-elements statement - leaf cannot hold this statement. /ll:{uses='g:grp'}/{refine='c/x'}");
- assert_null(lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;import grp {prefix g;}"
- "uses g:grp {refine c/ll {min-elements 10;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;import grp {prefix g;}"
+ "uses g:grp {refine c/ll {min-elements 10;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid refine of min-elements statement - \"min-elements\" is bigger than \"max-elements\". /mm:{uses='g:grp'}/{refine='c/ll'}");
*state = NULL;
@@ -2482,7 +2485,7 @@
*state = test_augment;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
const struct lysc_node *node;
const struct lysc_node_choice *ch;
const struct lysc_node_case *c;
@@ -2494,12 +2497,12 @@
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module a {namespace urn:a;prefix a; typedef atype {type string;}"
"container top {leaf a {type string;}}}");
- assert_non_null(lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}"
- "leaf b {type a:atype;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}"
+ "leaf b {type a:atype;}}", LYS_IN_YANG, &mod));
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module c {namespace urn:c;prefix c; import a {prefix a;}"
"augment /a:top/ { container c {leaf c {type a:atype;}}}}");
- assert_non_null(lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;import a {prefix a;} import c {prefix c;}"
- "augment /a:top/c:c/ { leaf d {type a:atype;} leaf c {type string;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;import a {prefix a;} import c {prefix c;}"
+ "augment /a:top/c:c/ { leaf d {type a:atype;} leaf c {type string;}}}", LYS_IN_YANG, &mod));
assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "a")));
assert_non_null(ly_ctx_get_module_implemented(ctx, "b"));
assert_non_null(ly_ctx_get_module_implemented(ctx, "c"));
@@ -2517,9 +2520,9 @@
assert_non_null(node = node->next);
assert_string_equal(node->name, "c");
- assert_non_null((mod = lys_parse_mem(ctx, "module e {namespace urn:e;prefix e;choice ch {leaf a {type string;}}"
- "augment /ch/c {when 1; leaf lc2 {type uint16;}}"
- "augment /ch { when 1; leaf b {type int8;} case c {leaf lc1 {type uint8;}}}}", LYS_IN_YANG)));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {namespace urn:e;prefix e;choice ch {leaf a {type string;}}"
+ "augment /ch/c {when 1; leaf lc2 {type uint16;}}"
+ "augment /ch { when 1; leaf b {type int8;} case c {leaf lc1 {type uint8;}}}}", LYS_IN_YANG, &mod));
assert_non_null((ch = (const struct lysc_node_choice*)mod->compiled->data));
assert_null(mod->compiled->data->next);
assert_string_equal("ch", ch->name);
@@ -2541,16 +2544,16 @@
assert_ptr_equal(ch->cases->child->prev, ((const struct lysc_node_case*)c)->child->next);
assert_null(c->next);
- assert_non_null((mod = lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;grouping g {leaf a {type string;}}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;grouping g {leaf a {type string;}}"
"container c;"
- "augment /c {uses g;}}", LYS_IN_YANG)));
+ "augment /c {uses g;}}", LYS_IN_YANG, &mod));
assert_non_null(node = lysc_node_children(mod->compiled->data, 0));
assert_string_equal(node->name, "a");
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule gsub {belongs-to g {prefix g;}"
"augment /c {container sub;}}");
- assert_non_null(mod = lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;include gsub; container c;"
- "augment /c/sub {leaf main {type string;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;include gsub; container c;"
+ "augment /c/sub {leaf main {type string;}}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled->data);
assert_string_equal("c", mod->compiled->data->name);
assert_non_null(node = ((struct lysc_node_container*)mod->compiled->data)->child);
@@ -2559,11 +2562,11 @@
assert_string_equal("main", node->name);
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module himp {namespace urn:hi;prefix hi;container top; rpc func;}");
- assert_non_null(mod = lys_parse_mem(ctx, "module h {namespace urn:h;prefix h;import himp {prefix hi;}container top;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module h {namespace urn:h;prefix h;import himp {prefix hi;}container top;"
"augment /hi:top {container p {presence XXX; leaf x {mandatory true;type string;}}}"
"augment /hi:top {list ll {key x;leaf x {type string;}leaf y {mandatory true; type string;}}}"
"augment /hi:top {leaf l {type string; mandatory true; config false;}}"
- "augment /top {leaf l {type string; mandatory true;}}}", LYS_IN_YANG));
+ "augment /top {leaf l {type string; mandatory true;}}}", LYS_IN_YANG, &mod));
assert_non_null(node = mod->compiled->data);
assert_non_null(node = ((struct lysc_node_container*)node)->child);
assert_string_equal("l", node->name);
@@ -2578,9 +2581,9 @@
assert_string_equal("l", node->name);
assert_true(node->flags & LYS_CONFIG_R);
- assert_non_null(lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;import himp {prefix hi;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;import himp {prefix hi;}"
"augment /hi:func/input {leaf x {type string;}}"
- "augment /hi:func/output {leaf y {type string;}}}", LYS_IN_YANG));
+ "augment /hi:func/output {leaf y {type string;}}}", LYS_IN_YANG, NULL));
assert_non_null(mod = ly_ctx_get_module_implemented(ctx, "himp"));
assert_non_null(rpc = mod->compiled->rpcs);
assert_int_equal(1, LY_ARRAY_COUNT(rpc));
@@ -2591,41 +2594,41 @@
assert_string_equal("y", rpc->output.data->name);
assert_null(rpc->output.data->next);
- assert_non_null(mod = lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;yang-version 1.1; container root;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;yang-version 1.1; container root;"
"grouping grp {notification grp-notif;}"
- "augment /root {uses grp;}}", LYS_IN_YANG));
+ "augment /root {uses grp;}}", LYS_IN_YANG, &mod));
assert_non_null(cont = (const struct lysc_node_container*)mod->compiled->data);
assert_null(cont->child);
assert_non_null(notif = cont->notifs);
assert_int_equal(1, LY_ARRAY_COUNT(notif));
- assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; container c {leaf a {type string;}}"
- "augment /x {leaf a {type int8;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; container c {leaf a {type string;}}"
+ "augment /x {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid absolute-schema-nodeid value \"/x\" - target node not found. /aa:{augment='/x'}");
- assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; container c {leaf a {type string;}}"
- "augment /c {leaf a {type int8;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; container c {leaf a {type string;}}"
+ "augment /c {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/notification statement. /bb:{augment='/c'}/a");
- assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; container c {leaf a {type string;}}"
- "augment /c/a {leaf a {type int8;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; container c {leaf a {type string;}}"
+ "augment /c/a {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Augment's absolute-schema-nodeid \"/c/a\" refers to a leaf node which is not an allowed augment's target. /cc:{augment='/c/a'}");
- assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; container c {leaf a {type string;}}"
- "augment /c {case b {leaf d {type int8;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; container c {leaf a {type string;}}"
+ "augment /c {case b {leaf d {type int8;}}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid augment of container node which is not allowed to contain case node \"b\". /dd:{augment='/c'}");
- assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee; import himp {prefix hi;}"
- "augment /hi:top {container c {leaf d {mandatory true; type int8;}}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee; import himp {prefix hi;}"
+ "augment /hi:top {container c {leaf d {mandatory true; type int8;}}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid augment adding mandatory node \"c\" without making it conditional via when statement. /ee:{augment='/hi:top'}");
- assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff; container top;"
- "augment ../top {leaf x {type int8;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff; container top;"
+ "augment ../top {leaf x {type int8;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid absolute-schema-nodeid value \"../top\" - missing starting \"/\". /ff:{augment='../top'}");
- assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg; rpc func;"
- "augment /func {leaf x {type int8;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg; rpc func;"
+ "augment /func {leaf x {type int8;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Augment's absolute-schema-nodeid \"/func\" refers to a RPC node which is not an allowed augment's target. /gg:{augment='/func'}");
*state = NULL;
@@ -2638,7 +2641,7 @@
*state = test_deviation;
struct ly_ctx *ctx;
- struct lys_module *mod;
+ const struct lys_module *mod;
const struct lysc_node *node;
const struct lysc_node_list *list;
const struct lysc_node_leaflist *llist;
@@ -2654,7 +2657,7 @@
" case c {leaf c{type string;}}}"
"rpc func1 { input { leaf x {type int8;}} output {leaf y {type int8;}}}"
"rpc func2;}");
- assert_non_null(lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}"
"deviation /a:top/a:b {deviate not-supported;}"
"deviation /a:ch/a:a/a:x {deviate not-supported;}"
"deviation /a:ch/a:c/a:c {deviate not-supported;}"
@@ -2662,7 +2665,7 @@
"deviation /a:ch/a:a/a:a {deviate not-supported;}"
"deviation /a:func1/a:input {deviate not-supported;}"
"deviation /a:func1/a:output {deviate not-supported;}"
- "deviation /a:func2 {deviate not-supported;}}", LYS_IN_YANG));
+ "deviation /a:func2 {deviate not-supported;}}", LYS_IN_YANG, NULL));
assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "a")));
assert_non_null(node = mod->compiled->data);
assert_string_equal(node->name, "top");
@@ -2679,11 +2682,11 @@
assert_null(mod->compiled->rpcs[0].input.data);
assert_null(mod->compiled->rpcs[0].output.data);
- assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:c;prefix c; typedef mytype {type string; units kilometers;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c; typedef mytype {type string; units kilometers;}"
"leaf c1 {type mytype;} leaf c2 {type mytype; units meters;} leaf c3 {type mytype; units meters;}"
"deviation /c1 {deviate add {units meters;}}"
"deviation /c2 {deviate delete {units meters;}}"
- "deviation /c3 {deviate replace {units centimeters;}}}", LYS_IN_YANG));
+ "deviation /c3 {deviate replace {units centimeters;}}}", LYS_IN_YANG, &mod));
assert_non_null(node = mod->compiled->data);
assert_string_equal("c1", node->name);
assert_string_equal("meters", ((struct lysc_node_leaf*)node)->units);
@@ -2694,11 +2697,11 @@
assert_string_equal("c3", node->name);
assert_string_equal("centimeters", ((struct lysc_node_leaf*)node)->units);
- assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; leaf c1 {type string; must 1;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; leaf c1 {type string; must 1;}"
"container c2 {presence yes; must 1; must 2;} leaf c3 {type string; must 1; must 3;}"
"deviation /c1 {deviate add {must 3;}}"
"deviation /c2 {deviate delete {must 2;}}"
- "deviation /c3 {deviate delete {must 3; must 1;}}}", LYS_IN_YANG));
+ "deviation /c3 {deviate delete {must 3; must 1;}}}", LYS_IN_YANG, &mod));
assert_non_null(node = mod->compiled->data);
assert_string_equal("c1", node->name);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_node_leaf*)node)->musts));
@@ -2717,11 +2720,11 @@
"leaf c {default hello; type string;}"
"leaf-list d {default hello; default world; type string;}"
"leaf c2 {type mytype;} leaf-list d2 {type mytype;}}");
- assert_non_null(lys_parse_mem(ctx, "module f {yang-version 1.1; namespace urn:f;prefix f;import e {prefix x;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {yang-version 1.1; namespace urn:f;prefix f;import e {prefix x;}"
"deviation /x:a {deviate delete {default a;}}"
"deviation /x:b {deviate delete {default x:a;}}"
"deviation /x:c {deviate delete {default hello;}}"
- "deviation /x:d {deviate delete {default world;}}}", LYS_IN_YANG));
+ "deviation /x:d {deviate delete {default world;}}}", LYS_IN_YANG, NULL));
assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "e")));
assert_non_null(node = mod->compiled->data);
assert_null(((struct lysc_node_choice*)node)->dflt);
@@ -2742,12 +2745,12 @@
assert_string_equal("nothing", llist->dflts[0]->realtype->plugin->print(llist->dflts[0], LYD_XML, NULL, NULL, &dynamic));
assert_int_equal(0, dynamic);
- assert_non_null(lys_parse_mem(ctx, "module g {yang-version 1.1; namespace urn:g;prefix g;import e {prefix x;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {yang-version 1.1; namespace urn:g;prefix g;import e {prefix x;}"
"deviation /x:b {deviate add {default x:b;}}"
"deviation /x:c {deviate add {default bye;}}"
"deviation /x:d {deviate add {default all; default people;}}"
"deviation /x:c2 {deviate add {default hi; must 1;}}"
- "deviation /x:d2 {deviate add {default hi; default all;}}}", LYS_IN_YANG));
+ "deviation /x:d2 {deviate add {default hi; default all;}}}", LYS_IN_YANG, NULL));
assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "e")));
assert_non_null(node = mod->compiled->data);
assert_null(((struct lysc_node_choice*)node)->dflt);
@@ -2781,9 +2784,9 @@
assert_string_equal("all", llist->dflts[1]->realtype->plugin->print(llist->dflts[1], LYD_XML, NULL, NULL, &dynamic));
assert_int_equal(0, dynamic);
- assert_non_null(lys_parse_mem(ctx, "module h {yang-version 1.1; namespace urn:h;prefix h;import e {prefix x;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module h {yang-version 1.1; namespace urn:h;prefix h;import e {prefix x;}"
"deviation /x:b {deviate replace {default x:a;}}"
- "deviation /x:c {deviate replace {default hello;}}}", LYS_IN_YANG));
+ "deviation /x:c {deviate replace {default hello;}}}", LYS_IN_YANG, NULL));
assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "e")));
assert_non_null(node = mod->compiled->data);
assert_null(((struct lysc_node_choice*)node)->dflt);
@@ -2799,11 +2802,11 @@
"list l1 {key a; leaf a {type string;} leaf b {type string;} leaf c {type string;}}"
"list l2 {key a; unique \"b c\"; unique \"d\"; leaf a {type string;} leaf b {type string;}"
" leaf c {type string;} leaf d {type string;}}}");
- assert_non_null(lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;import i {prefix i;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;import i {prefix i;}"
"augment /i:l1 {leaf j_c {type string;}}"
"deviation /i:l1 {deviate add {unique \"i:b j_c\"; }}"
"deviation /i:l1 {deviate add {unique \"i:c\";}}"
- "deviation /i:l2 {deviate delete {unique \"d\"; unique \"b c\";}}}", LYS_IN_YANG));
+ "deviation /i:l2 {deviate delete {unique \"d\"; unique \"b c\";}}}", LYS_IN_YANG, NULL));
assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "i")));
assert_non_null(list = (struct lysc_node_list*)mod->compiled->data);
assert_string_equal("l1", list->name);
@@ -2817,10 +2820,10 @@
assert_string_equal("l2", list->name);
assert_null(list->uniques);
- assert_non_null(mod = lys_parse_mem(ctx, "module k {namespace urn:k;prefix k; leaf a {type string;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module k {namespace urn:k;prefix k; leaf a {type string;}"
"container top {leaf x {type string;} leaf y {type string; config false;}}"
"deviation /a {deviate add {config false; }}"
- "deviation /top {deviate add {config false;}}}", LYS_IN_YANG));
+ "deviation /top {deviate add {config false;}}}", LYS_IN_YANG, &mod));
assert_non_null(node = mod->compiled->data);
assert_string_equal("a", node->name);
assert_true(node->flags & LYS_CONFIG_R);
@@ -2834,10 +2837,10 @@
assert_string_equal("y", node->name);
assert_true(node->flags & LYS_CONFIG_R);
- assert_non_null(mod = lys_parse_mem(ctx, "module l {namespace urn:l;prefix l; leaf a {config false; type string;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module l {namespace urn:l;prefix l; leaf a {config false; type string;}"
"container top {config false; leaf x {type string;}}"
"deviation /a {deviate replace {config true;}}"
- "deviation /top {deviate replace {config true;}}}", LYS_IN_YANG));
+ "deviation /top {deviate replace {config true;}}}", LYS_IN_YANG, &mod));
assert_non_null(node = mod->compiled->data);
assert_string_equal("a", node->name);
assert_true(node->flags & LYS_CONFIG_W);
@@ -2848,11 +2851,11 @@
assert_string_equal("x", node->name);
assert_true(node->flags & LYS_CONFIG_W);
- assert_non_null(mod = lys_parse_mem(ctx, "module m {namespace urn:m;prefix m;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module m {namespace urn:m;prefix m;"
"container a {leaf a {type string;}}"
"container b {leaf b {mandatory true; type string;}}"
"deviation /a/a {deviate add {mandatory true;}}"
- "deviation /b/b {deviate replace {mandatory false;}}}", LYS_IN_YANG));
+ "deviation /b/b {deviate replace {mandatory false;}}}", LYS_IN_YANG, &mod));
assert_non_null(node = mod->compiled->data);
assert_string_equal("a", node->name);
assert_true((node->flags & LYS_MAND_MASK) == LYS_MAND_TRUE);
@@ -2862,11 +2865,11 @@
assert_false(node->flags & LYS_MAND_MASK); /* just unset on container */
assert_true((lysc_node_children(node, 0)->flags & LYS_MAND_MASK) == LYS_MAND_FALSE);
- assert_non_null(mod = lys_parse_mem(ctx, "module n {yang-version 1.1; namespace urn:n;prefix n;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module n {yang-version 1.1; namespace urn:n;prefix n;"
"leaf a {default test; type string;}"
"leaf b {mandatory true; type string;}"
"deviation /a {deviate add {mandatory true;} deviate delete {default test;}}"
- "deviation /b {deviate add {default test;} deviate replace {mandatory false;}}}", LYS_IN_YANG));
+ "deviation /b {deviate add {default test;} deviate replace {mandatory false;}}}", LYS_IN_YANG, &mod));
assert_non_null(node = mod->compiled->data);
assert_string_equal("a", node->name);
assert_null(((struct lysc_node_leaf*)node)->dflt);
@@ -2876,7 +2879,7 @@
assert_non_null(((struct lysc_node_leaf*)node)->dflt);
assert_true((node->flags & LYS_MAND_MASK) == LYS_MAND_FALSE);
- assert_non_null(mod = lys_parse_mem(ctx, "module o {namespace urn:o;prefix o;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module o {namespace urn:o;prefix o;"
"leaf-list a {type string;}"
"list b {config false;}"
"leaf-list c {min-elements 1; max-elements 10; type string;}"
@@ -2884,7 +2887,7 @@
"deviation /a {deviate add {min-elements 1; max-elements 10;}}"
"deviation /b {deviate add {min-elements 10; max-elements 100;}}"
"deviation /c {deviate replace {min-elements 10; max-elements 100;}}"
- "deviation /d {deviate replace {min-elements 1; max-elements 10;}}}", LYS_IN_YANG));
+ "deviation /d {deviate replace {min-elements 1; max-elements 10;}}}", LYS_IN_YANG, &mod));
assert_non_null(node = mod->compiled->data);
assert_string_equal("a", node->name);
assert_int_equal(1, ((struct lysc_node_leaflist*)node)->min);
@@ -2902,10 +2905,10 @@
assert_int_equal(1, ((struct lysc_node_list*)node)->min);
assert_int_equal(10, ((struct lysc_node_list*)node)->max);
- assert_non_null(mod = lys_parse_mem(ctx, "module p {yang-version 1.1; namespace urn:p;prefix p; typedef mytype {type int8; default 1;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module p {yang-version 1.1; namespace urn:p;prefix p; typedef mytype {type int8; default 1;}"
"leaf a {type string; default 10;} leaf-list b {type string;}"
"deviation /a {deviate replace {type mytype;}}"
- "deviation /b {deviate replace {type mytype;}}}", LYS_IN_YANG));
+ "deviation /b {deviate replace {type mytype;}}}", LYS_IN_YANG, &mod));
assert_non_null(leaf = (struct lysc_node_leaf*)mod->compiled->data);
assert_string_equal("a", leaf->name);
assert_int_equal(LY_TYPE_INT8, leaf->type->basetype);
@@ -2921,12 +2924,12 @@
assert_int_equal(1, llist->dflts[0]->uint8);
/* instance-identifiers with NULL canonical_cach are changed to string types with a canonical_cache value equal to the original value */
- assert_non_null(mod = lys_parse_mem(ctx, "module q {yang-version 1.1; namespace urn:q;prefix q; import e {prefix e;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module q {yang-version 1.1; namespace urn:q;prefix q; import e {prefix e;}"
"leaf q {type instance-identifier; default \"/e:d2[.='a']\";}"
- "leaf-list ql {type instance-identifier; default \"/e:d[.='b']\"; default \"/e:d2[.='c']\";}}", LYS_IN_YANG));
- assert_non_null(lys_parse_mem(ctx, "module qdev {yang-version 1.1; namespace urn:qdev;prefix qd; import q {prefix q;}"
+ "leaf-list ql {type instance-identifier; default \"/e:d[.='b']\"; default \"/e:d2[.='c']\";}}", LYS_IN_YANG, &mod));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module qdev {yang-version 1.1; namespace urn:qdev;prefix qd; import q {prefix q;}"
"deviation /q:q { deviate replace {type string;}}"
- "deviation /q:ql { deviate replace {type string;}}}", LYS_IN_YANG));
+ "deviation /q:ql { deviate replace {type string;}}}", LYS_IN_YANG, NULL));
assert_non_null(leaf = (struct lysc_node_leaf*)mod->compiled->data);
assert_int_equal(LY_TYPE_STRING, leaf->dflt->realtype->basetype);
assert_non_null(leaf->dflt->canonical_cache);
@@ -2941,11 +2944,11 @@
assert_int_equal(LY_TYPE_STRING, llist->dflts[0]->realtype->basetype);
assert_string_equal("/e:d2[.='c']", llist->dflts[1]->canonical_cache);
- assert_non_null(mod = lys_parse_mem(ctx, "module r {yang-version 1.1; namespace urn:r;prefix r;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module r {yang-version 1.1; namespace urn:r;prefix r;"
"typedef mytype {type uint8; default 200;}"
"leaf r {type mytype;} leaf-list lr {type mytype;}"
"deviation /r:r {deviate replace {type string;}}"
- "deviation /r:lr {deviate replace {type string;}}}", LYS_IN_YANG));
+ "deviation /r:lr {deviate replace {type string;}}}", LYS_IN_YANG, &mod));
assert_non_null(leaf = (struct lysc_node_leaf*)mod->compiled->data);
assert_string_equal("r", leaf->name);
assert_null(leaf->dflt);
@@ -2955,220 +2958,221 @@
assert_null(llist->dflts);
assert_null(llist->dflts_mods);
- assert_non_null(mod = lys_parse_mem(ctx, "module s {yang-version 1.1; namespace urn:s;prefix s;"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module s {yang-version 1.1; namespace urn:s;prefix s;"
"leaf s {type instance-identifier {require-instance true;} default /s:x;}"
"leaf x {type string;} leaf y {type string;}"
- "deviation /s:s {deviate replace {default /s:y;}}}", LYS_IN_YANG));
+ "deviation /s:s {deviate replace {default /s:y;}}}", LYS_IN_YANG, &mod));
assert_non_null(leaf = (struct lysc_node_leaf*)mod->compiled->data);
assert_string_equal("s", leaf->name);
assert_non_null(leaf->dflt);
- assert_non_null(str = leaf->dflt->realtype->plugin->print(leaf->dflt, LYD_XML, lys_get_prefix, mod, &dynamic));
+ assert_non_null(str = leaf->dflt->realtype->plugin->print(leaf->dflt, LYD_XML, lys_get_prefix,
+ (struct lys_module *)mod, &dynamic));
assert_string_equal("/s:y", str);
if (dynamic) { free((char*)str); }
- assert_null(lys_parse_mem(ctx, "module aa1 {namespace urn:aa1;prefix aa1;import a {prefix a;}"
- "deviation /a:top/a:z {deviate not-supported;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa1 {namespace urn:aa1;prefix aa1;import a {prefix a;}"
+ "deviation /a:top/a:z {deviate not-supported;}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid absolute-schema-nodeid value \"/a:top/a:z\" - target node not found. /aa1:{deviation='/a:top/a:z'}");
- assert_non_null(lys_parse_mem(ctx, "module aa2 {namespace urn:aa2;prefix aa2;import a {prefix a;}"
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module aa2 {namespace urn:aa2;prefix aa2;import a {prefix a;}"
"deviation /a:top/a:a {deviate not-supported;}"
- "deviation /a:top/a:a {deviate add {default error;}}}", LYS_IN_YANG));
+ "deviation /a:top/a:a {deviate add {default error;}}}", LYS_IN_YANG, NULL));
/* warning */
logbuf_assert("Useless multiple (2) deviates on node \"/a:top/a:a\" since the node is not-supported.");
- assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;import a {prefix a;}"
- "deviation a:top/a:a {deviate not-supported;}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;import a {prefix a;}"
+ "deviation a:top/a:a {deviate not-supported;}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid absolute-schema-nodeid value \"a:top/a:a\" - missing starting \"/\". /bb:{deviation='a:top/a:a'}");
- assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; container c;"
- "deviation /c {deviate add {units meters;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; container c;"
+ "deviation /c {deviate add {units meters;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation of container node - it is not possible to add \"units\" property. /cc:{deviation='/c'}");
- assert_null(lys_parse_mem(ctx, "module cd {namespace urn:cd;prefix cd; leaf c {type string; units centimeters;}"
- "deviation /c {deviate add {units meters;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cd {namespace urn:cd;prefix cd; leaf c {type string; units centimeters;}"
+ "deviation /c {deviate add {units meters;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation adding \"units\" property which already exists (with value \"centimeters\"). /cd:{deviation='/c'}");
- assert_null(lys_parse_mem(ctx, "module dd1 {namespace urn:dd1;prefix dd1; container c;"
- "deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd1 {namespace urn:dd1;prefix dd1; container c;"
+ "deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation of container node - it is not possible to delete \"units\" property. /dd1:{deviation='/c'}");
- assert_null(lys_parse_mem(ctx, "module dd2 {namespace urn:dd2;prefix dd2; leaf c {type string;}"
- "deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd2 {namespace urn:dd2;prefix dd2; leaf c {type string;}"
+ "deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation deleting \"units\" property \"meters\" which is not present. /dd2:{deviation='/c'}");
- assert_null(lys_parse_mem(ctx, "module dd3 {namespace urn:dd3;prefix dd3; leaf c {type string; units centimeters;}"
- "deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd3 {namespace urn:dd3;prefix dd3; leaf c {type string; units centimeters;}"
+ "deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation deleting \"units\" property \"meters\" which does not match the target's property value \"centimeters\"."
" /dd3:{deviation='/c'}");
- assert_null(lys_parse_mem(ctx, "module ee1 {namespace urn:ee1;prefix ee1; container c;"
- "deviation /c {deviate replace {units meters;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee1 {namespace urn:ee1;prefix ee1; container c;"
+ "deviation /c {deviate replace {units meters;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation of container node - it is not possible to replace \"units\" property. /ee1:{deviation='/c'}");
- assert_null(lys_parse_mem(ctx, "module ee2 {namespace urn:ee2;prefix ee2; leaf c {type string;}"
- "deviation /c {deviate replace {units meters;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee2 {namespace urn:ee2;prefix ee2; leaf c {type string;}"
+ "deviation /c {deviate replace {units meters;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation replacing \"units\" property \"meters\" which is not present. /ee2:{deviation='/c'}");
/* the default is already deleted in /e:a byt module f */
- assert_null(lys_parse_mem(ctx, "module ff1 {namespace urn:ff1;prefix ff1; import e {prefix e;}"
- "deviation /e:a {deviate delete {default x:a;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff1 {namespace urn:ff1;prefix ff1; import e {prefix e;}"
+ "deviation /e:a {deviate delete {default x:a;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation deleting \"default\" property \"x:a\" which is not present. /ff1:{deviation='/e:a'}");
- assert_null(lys_parse_mem(ctx, "module ff2 {namespace urn:ff2;prefix ff2; import e {prefix e;}"
- "deviation /e:b {deviate delete {default x:a;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff2 {namespace urn:ff2;prefix ff2; import e {prefix e;}"
+ "deviation /e:b {deviate delete {default x:a;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation deleting \"default\" property \"x:a\" of choice. "
"The prefix does not match any imported module of the deviation module. /ff2:{deviation='/e:b'}");
- assert_null(lys_parse_mem(ctx, "module ff3 {namespace urn:ff3;prefix ff3; import e {prefix e;}"
- "deviation /e:b {deviate delete {default e:b;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff3 {namespace urn:ff3;prefix ff3; import e {prefix e;}"
+ "deviation /e:b {deviate delete {default e:b;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation deleting \"default\" property \"e:b\" of choice does not match the default case name \"a\". /ff3:{deviation='/e:b'}");
- assert_null(lys_parse_mem(ctx, "module ff4 {namespace urn:ff4;prefix ff4; import e {prefix e;}"
- "deviation /e:b {deviate delete {default ff4:a;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff4 {namespace urn:ff4;prefix ff4; import e {prefix e;}"
+ "deviation /e:b {deviate delete {default ff4:a;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation deleting \"default\" property \"ff4:a\" of choice. The prefix does not match the default case's module. /ff4:{deviation='/e:b'}");
- assert_null(lys_parse_mem(ctx, "module ff5 {namespace urn:ff5;prefix ff5; anyxml a;"
- "deviation /a {deviate delete {default x;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff5 {namespace urn:ff5;prefix ff5; anyxml a;"
+ "deviation /a {deviate delete {default x;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation of anyxml node - it is not possible to delete \"default\" property. /ff5:{deviation='/a'}");
- assert_null(lys_parse_mem(ctx, "module ff6 {namespace urn:ff6;prefix ff6; import e {prefix e;}"
- "deviation /e:c {deviate delete {default hi;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff6 {namespace urn:ff6;prefix ff6; import e {prefix e;}"
+ "deviation /e:c {deviate delete {default hi;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation deleting \"default\" property \"hi\" which does not match the target's property value \"hello\". /ff6:{deviation='/e:c'}");
- assert_null(lys_parse_mem(ctx, "module ff7 {namespace urn:ff7;prefix ff7; import e {prefix e;}"
- "deviation /e:d {deviate delete {default hi;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff7 {namespace urn:ff7;prefix ff7; import e {prefix e;}"
+ "deviation /e:d {deviate delete {default hi;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation deleting \"default\" property \"hi\" which does not match any of the target's property values. /ff7:{deviation='/e:d'}");
- assert_null(lys_parse_mem(ctx, "module gg1 {namespace urn:gg1;prefix gg1; import e {prefix e;}"
- "deviation /e:b {deviate add {default e:a;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg1 {namespace urn:gg1;prefix gg1; import e {prefix e;}"
+ "deviation /e:b {deviate add {default e:a;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation adding \"default\" property which already exists (with value \"a\"). /gg1:{deviation='/e:b'}");
- assert_null(lys_parse_mem(ctx, "module gg2 {namespace urn:gg2;prefix gg2; import e {prefix e;}"
- "deviation /e:a {deviate add {default x:a;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg2 {namespace urn:gg2;prefix gg2; import e {prefix e;}"
+ "deviation /e:a {deviate add {default x:a;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation adding \"default\" property \"x:a\" of choice. "
"The prefix does not match any imported module of the deviation module. /gg2:{deviation='/e:a'}");
- assert_null(lys_parse_mem(ctx, "module gg3 {namespace urn:gg3;prefix gg3; import e {prefix e;}"
- "deviation /e:a {deviate add {default a;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg3 {namespace urn:gg3;prefix gg3; import e {prefix e;}"
+ "deviation /e:a {deviate add {default a;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation adding \"default\" property \"a\" of choice - the specified case does not exists. /gg3:{deviation='/e:a'}");
- assert_null(lys_parse_mem(ctx, "module gg4 {namespace urn:gg4;prefix gg4; import e {prefix e;}"
- "deviation /e:c {deviate add {default hi;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg4 {namespace urn:gg4;prefix gg4; import e {prefix e;}"
+ "deviation /e:c {deviate add {default hi;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation adding \"default\" property which already exists (with value \"hello\"). /gg4:{deviation='/e:c'}");
- assert_null(lys_parse_mem(ctx, "module gg4 {namespace urn:gg4;prefix gg4; import e {prefix e;}"
- "deviation /e:a {deviate add {default e:c;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg4 {namespace urn:gg4;prefix gg4; import e {prefix e;}"
+ "deviation /e:a {deviate add {default e:c;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation adding \"default\" property \"e:c\" of choice - mandatory node \"c\" under the default case. /gg4:{deviation='/e:a'}");
- assert_null(lys_parse_mem(ctx, "module gg5 {namespace urn:gg5;prefix gg5; leaf x {type string; mandatory true;}"
- "deviation /x {deviate add {default error;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg5 {namespace urn:gg5;prefix gg5; leaf x {type string; mandatory true;}"
+ "deviation /x {deviate add {default error;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation combining default value and mandatory leaf. /gg5:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module hh1 {yang-version 1.1; namespace urn:hh1;prefix hh1; import e {prefix e;}"
- "deviation /e:d {deviate replace {default hi;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh1 {yang-version 1.1; namespace urn:hh1;prefix hh1; import e {prefix e;}"
+ "deviation /e:d {deviate replace {default hi;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation of leaf-list node - it is not possible to replace \"default\" property. /hh1:{deviation='/e:d'}");
- assert_null(lys_parse_mem(ctx, "module ii1 {namespace urn:ii1;prefix ii1; import i {prefix i;}"
- "deviation /i:l1 {deviate delete {unique x;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii1 {namespace urn:ii1;prefix ii1; import i {prefix i;}"
+ "deviation /i:l1 {deviate delete {unique x;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation deleting \"unique\" property \"x\" which does not match any of the target's property values. /ii1:{deviation='/i:l1'}");
- assert_null(lys_parse_mem(ctx, "module ii2 {namespace urn:ii2;prefix ii2; import i {prefix i;} leaf x { type string;}"
- "deviation /i:l2 {deviate delete {unique d;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii2 {namespace urn:ii2;prefix ii2; import i {prefix i;} leaf x { type string;}"
+ "deviation /i:l2 {deviate delete {unique d;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation deleting \"unique\" property \"d\" which does not match any of the target's property values. /ii2:{deviation='/i:l2'}");
- assert_null(lys_parse_mem(ctx, "module ii3 {namespace urn:ii3;prefix ii3; leaf x { type string;}"
- "deviation /x {deviate delete {unique d;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii3 {namespace urn:ii3;prefix ii3; leaf x { type string;}"
+ "deviation /x {deviate delete {unique d;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation of leaf node - it is not possible to delete \"unique\" property. /ii3:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module ii4 {namespace urn:ii4;prefix ii4; leaf x { type string;}"
- "deviation /x {deviate add {unique d;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii4 {namespace urn:ii4;prefix ii4; leaf x { type string;}"
+ "deviation /x {deviate add {unique d;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation of leaf node - it is not possible to add \"unique\" property. /ii4:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module jj1 {namespace urn:jj1;prefix jj1; choice ch {case a {leaf a{type string;}}}"
- "deviation /ch/a {deviate add {config false;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj1 {namespace urn:jj1;prefix jj1; choice ch {case a {leaf a{type string;}}}"
+ "deviation /ch/a {deviate add {config false;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation of case node - it is not possible to add \"config\" property. /jj1:{deviation='/ch/a'}");
- assert_null(lys_parse_mem(ctx, "module jj2 {namespace urn:jj2;prefix jj2; container top {config false; leaf x {type string;}}"
- "deviation /top/x {deviate add {config true;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj2 {namespace urn:jj2;prefix jj2; container top {config false; leaf x {type string;}}"
+ "deviation /top/x {deviate add {config true;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation of config - configuration node cannot be child of any state data node. /jj2:{deviation='/top/x'}");
- assert_null(lys_parse_mem(ctx, "module jj3 {namespace urn:jj3;prefix jj3; container top {leaf x {type string;}}"
- "deviation /top/x {deviate replace {config false;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj3 {namespace urn:jj3;prefix jj3; container top {leaf x {type string;}}"
+ "deviation /top/x {deviate replace {config false;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation replacing \"config\" property \"config false\" which is not present. /jj3:{deviation='/top/x'}");
- assert_null(lys_parse_mem(ctx, "module jj4 {namespace urn:jj4;prefix jj4; choice ch {case a {leaf a{type string;}}}"
- "deviation /ch/a {deviate replace {config false;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj4 {namespace urn:jj4;prefix jj4; choice ch {case a {leaf a{type string;}}}"
+ "deviation /ch/a {deviate replace {config false;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation of case node - it is not possible to replace \"config\" property. /jj4:{deviation='/ch/a'}");
- assert_null(lys_parse_mem(ctx, "module jj5 {namespace urn:jj5;prefix jj5; container top {leaf x {type string; config true;}}"
- "deviation /top {deviate add {config false;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj5 {namespace urn:jj5;prefix jj5; container top {leaf x {type string; config true;}}"
+ "deviation /top {deviate add {config false;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation of config - configuration node cannot be child of any state data node. /jj5:{deviation='/top'}");
- assert_null(lys_parse_mem(ctx, "module jj6 {namespace urn:jj6;prefix jj6; leaf x {config false; type string;}"
- "deviation /x {deviate add {config true;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj6 {namespace urn:jj6;prefix jj6; leaf x {config false; type string;}"
+ "deviation /x {deviate add {config true;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation adding \"config\" property which already exists (with value \"config false\"). /jj6:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module kk1 {namespace urn:kk1;prefix kk1; container top {leaf a{type string;}}"
- "deviation /top {deviate add {mandatory true;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk1 {namespace urn:kk1;prefix kk1; container top {leaf a{type string;}}"
+ "deviation /top {deviate add {mandatory true;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation of mandatory - container cannot hold mandatory statement. /kk1:{deviation='/top'}");
- assert_null(lys_parse_mem(ctx, "module kk2 {namespace urn:kk2;prefix kk2; container top {leaf a{type string;}}"
- "deviation /top {deviate replace {mandatory true;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk2 {namespace urn:kk2;prefix kk2; container top {leaf a{type string;}}"
+ "deviation /top {deviate replace {mandatory true;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation replacing \"mandatory\" property \"mandatory true\" which is not present. /kk2:{deviation='/top'}");
- assert_null(lys_parse_mem(ctx, "module kk3 {namespace urn:kk3;prefix kk3; container top {leaf x {type string;}}"
- "deviation /top/x {deviate replace {mandatory true;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk3 {namespace urn:kk3;prefix kk3; container top {leaf x {type string;}}"
+ "deviation /top/x {deviate replace {mandatory true;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation replacing \"mandatory\" property \"mandatory true\" which is not present. /kk3:{deviation='/top/x'}");
- assert_null(lys_parse_mem(ctx, "module kk4 {namespace urn:kk4;prefix kk4; leaf x {mandatory true; type string;}"
- "deviation /x {deviate add {mandatory false;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk4 {namespace urn:kk4;prefix kk4; leaf x {mandatory true; type string;}"
+ "deviation /x {deviate add {mandatory false;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation adding \"mandatory\" property which already exists (with value \"mandatory true\"). /kk4:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module ll1 {namespace urn:ll1;prefix ll1; leaf x {default test; type string;}"
- "deviation /x {deviate add {mandatory true;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll1 {namespace urn:ll1;prefix ll1; leaf x {default test; type string;}"
+ "deviation /x {deviate add {mandatory true;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation combining default value and mandatory leaf. /ll1:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module ll2 {yang-version 1.1; namespace urn:ll2;prefix ll2; leaf-list x {default test; type string;}"
- "deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll2 {yang-version 1.1; namespace urn:ll2;prefix ll2; leaf-list x {default test; type string;}"
+ "deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation combining default value and mandatory leaf-list. /ll2:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module ll2 {namespace urn:ll2;prefix ll2; choice ch {default a; leaf a {type string;} leaf b {type string;}}"
- "deviation /ch {deviate add {mandatory true;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll2 {namespace urn:ll2;prefix ll2; choice ch {default a; leaf a {type string;} leaf b {type string;}}"
+ "deviation /ch {deviate add {mandatory true;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation combining default case and mandatory choice. /ll2:{deviation='/ch'}");
- assert_null(lys_parse_mem(ctx, "module mm1 {namespace urn:mm1;prefix mm1; leaf-list x {min-elements 10; type string;}"
- "deviation /x {deviate add {max-elements 5;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm1 {namespace urn:mm1;prefix mm1; leaf-list x {min-elements 10; type string;}"
+ "deviation /x {deviate add {max-elements 5;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid combination of min-elements and max-elements after deviation: min value 10 is bigger than max value 5. /mm1:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module mm2 {namespace urn:mm2;prefix mm2; leaf-list x {max-elements 10; type string;}"
- "deviation /x {deviate add {min-elements 20;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm2 {namespace urn:mm2;prefix mm2; leaf-list x {max-elements 10; type string;}"
+ "deviation /x {deviate add {min-elements 20;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid combination of min-elements and max-elements after deviation: min value 20 is bigger than max value 10. /mm2:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module mm3 {namespace urn:mm3;prefix mm3; list x {min-elements 5; max-elements 10; config false;}"
- "deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm3 {namespace urn:mm3;prefix mm3; list x {min-elements 5; max-elements 10; config false;}"
+ "deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid combination of min-elements and max-elements after deviation: min value 5 is bigger than max value 1. /mm3:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module mm4 {namespace urn:mm4;prefix mm4; list x {min-elements 5; max-elements 10; config false;}"
- "deviation /x {deviate replace {min-elements 20;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm4 {namespace urn:mm4;prefix mm4; list x {min-elements 5; max-elements 10; config false;}"
+ "deviation /x {deviate replace {min-elements 20;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid combination of min-elements and max-elements after deviation: min value 20 is bigger than max value 10. /mm4:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module mm5 {namespace urn:mm5;prefix mm5; leaf-list x {type string; min-elements 5;}"
- "deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm5 {namespace urn:mm5;prefix mm5; leaf-list x {type string; min-elements 5;}"
+ "deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation adding \"min-elements\" property which already exists (with value \"5\"). /mm5:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module mm6 {namespace urn:mm6;prefix mm6; list x {config false; min-elements 5;}"
- "deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm6 {namespace urn:mm6;prefix mm6; list x {config false; min-elements 5;}"
+ "deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation adding \"min-elements\" property which already exists (with value \"5\"). /mm6:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module mm7 {namespace urn:mm7;prefix mm7; leaf-list x {type string; max-elements 5;}"
- "deviation /x {deviate add {max-elements 1;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm7 {namespace urn:mm7;prefix mm7; leaf-list x {type string; max-elements 5;}"
+ "deviation /x {deviate add {max-elements 1;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation adding \"max-elements\" property which already exists (with value \"5\"). /mm7:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module mm8 {namespace urn:mm8;prefix mm8; list x {config false; max-elements 5;}"
- "deviation /x {deviate add {max-elements 1;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm8 {namespace urn:mm8;prefix mm8; list x {config false; max-elements 5;}"
+ "deviation /x {deviate add {max-elements 1;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation adding \"max-elements\" property which already exists (with value \"5\"). /mm8:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module mm9 {namespace urn:mm9;prefix mm9; leaf-list x {type string;}"
- "deviation /x {deviate replace {min-elements 1;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm9 {namespace urn:mm9;prefix mm9; leaf-list x {type string;}"
+ "deviation /x {deviate replace {min-elements 1;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation replacing with \"min-elements\" property \"1\" which is not present. /mm9:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module mm10 {namespace urn:mm10;prefix mm10; list x {config false;}"
- "deviation /x {deviate replace {min-elements 1;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm10 {namespace urn:mm10;prefix mm10; list x {config false;}"
+ "deviation /x {deviate replace {min-elements 1;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation replacing with \"min-elements\" property \"1\" which is not present. /mm10:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module mm11 {namespace urn:mm11;prefix mm11; leaf-list x {type string;}"
- "deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm11 {namespace urn:mm11;prefix mm11; leaf-list x {type string;}"
+ "deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation replacing with \"max-elements\" property \"1\" which is not present. /mm11:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module mm12 {namespace urn:mm12;prefix mm12; list x {config false; }"
- "deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm12 {namespace urn:mm12;prefix mm12; list x {config false; }"
+ "deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation replacing with \"max-elements\" property \"1\" which is not present. /mm12:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module nn1 {namespace urn:nn1;prefix nn1; anyxml x;"
- "deviation /x {deviate replace {type string;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module nn1 {namespace urn:nn1;prefix nn1; anyxml x;"
+ "deviation /x {deviate replace {type string;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation of anyxml node - it is not possible to replace \"type\" property. /nn1:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module nn2 {namespace urn:nn2;prefix nn2; leaf-list x {type string;}"
- "deviation /x {deviate replace {type empty;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module nn2 {namespace urn:nn2;prefix nn2; leaf-list x {type string;}"
+ "deviation /x {deviate replace {type empty;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Leaf-list of type \"empty\" is allowed only in YANG 1.1 modules. /nn2:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module oo1 {namespace urn:oo1;prefix oo1; leaf x {type uint16; default 300;}"
- "deviation /x {deviate replace {type uint8;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module oo1 {namespace urn:oo1;prefix oo1; leaf x {type uint16; default 300;}"
+ "deviation /x {deviate replace {type uint8;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation replacing leaf's type - the leaf's default value \"300\" does not match the type "
"(Value \"300\" is out of uint8's min/max bounds.). /oo1:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module oo2 {yang-version 1.1;namespace urn:oo2;prefix oo2; leaf-list x {type uint16; default 10; default 300;}"
- "deviation /x {deviate replace {type uint8;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module oo2 {yang-version 1.1;namespace urn:oo2;prefix oo2; leaf-list x {type uint16; default 10; default 300;}"
+ "deviation /x {deviate replace {type uint8;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation replacing leaf-list's type - the leaf-list's default value \"300\" does not match the type "
"(Value \"300\" is out of uint8's min/max bounds.). /oo2:{deviation='/x'}");
- assert_null(lys_parse_mem(ctx, "module oo3 {namespace urn:oo3;prefix oo3; leaf x {type uint8;}"
- "deviation /x {deviate add {default 300;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module oo3 {namespace urn:oo3;prefix oo3; leaf x {type uint8;}"
+ "deviation /x {deviate add {default 300;}}}", LYS_IN_YANG, &mod));
logbuf_assert("Invalid deviation setting \"default\" property \"300\" which does not fit the type "
"(Value \"300\" is out of uint8's min/max bounds.). /oo3:{deviation='/x'}");
/* TODO recompiling reference object after deviation changes schema tree
assert_non_null(lys_parse_mem(ctx, "module pp {namespace urn:pp;prefix pp; leaf l { type leafref {path /c/x;}}"
- "container c {leaf x {type string;} leaf y {type string;}}}", LYS_IN_YANG));
- assert_null(lys_parse_mem(ctx, "module pp1 {namespace urn:pp1;prefix pp1; import pp {prefix pp;}"
- "deviation /pp:c/pp:x {deviate not-supported;}}", LYS_IN_YANG));
+ "container c {leaf x {type string;} leaf y {type string;}}}", LYS_IN_YANG, &mod));
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module pp1 {namespace urn:pp1;prefix pp1; import pp {prefix pp;}"
+ "deviation /pp:c/pp:x {deviate not-supported;}}", LYS_IN_YANG, &mod));
logbuf_assert("???. /pp:l}");
*/
@@ -3185,7 +3189,7 @@
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
- assert_null(lys_parse_mem(ctx,
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx,
"module a {"
"namespace urn:a;"
"prefix a;"
@@ -3210,10 +3214,10 @@
"when ../cont/l;"
"}"
"}"
- , LYS_IN_YANG));
+ , LYS_IN_YANG, NULL));
logbuf_assert("When condition of \"cont2\" includes a self-reference (referenced by when of \"l\"). /a:cont2");
- assert_null(lys_parse_mem(ctx,
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx,
"module a {"
"namespace urn:a;"
"prefix a;"
@@ -3238,10 +3242,10 @@
"when ../cont/lst/val;"
"}"
"}"
- , LYS_IN_YANG));
+ , LYS_IN_YANG, NULL));
logbuf_assert("When condition of \"cont2\" includes a self-reference (referenced by when of \"val\"). /a:cont2");
- assert_null(lys_parse_mem(ctx,
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx,
"module a {"
"namespace urn:a;"
"prefix a;"
@@ -3250,10 +3254,10 @@
"when \"../val='25'\";"
"}"
"}"
- , LYS_IN_YANG));
+ , LYS_IN_YANG, NULL));
logbuf_assert("When condition of \"val\" is accessing its own conditional node. /a:val");
- assert_null(lys_parse_mem(ctx,
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx,
"module a {"
"namespace urn:a;"
"prefix a;"
@@ -3266,10 +3270,10 @@
"when \"val='25'\";"
"}"
"}"
- , LYS_IN_YANG));
+ , LYS_IN_YANG, NULL));
logbuf_assert("When condition of \"val\" is accessing its own conditional node. /a:val");
- assert_null(lys_parse_mem(ctx,
+ assert_int_equal(LY_EVALID, lys_parse_mem(ctx,
"module a {"
"namespace urn:a;"
"prefix a;"
@@ -3281,7 +3285,7 @@
"}"
"container cont;"
"}"
- , LYS_IN_YANG));
+ , LYS_IN_YANG, NULL));
logbuf_assert("When condition of \"val\" is accessing its own conditional node. /a:cont/val");
*state = NULL;
diff --git a/tests/utests/test_context.c b/tests/utests/test_context.c
index 9a09dee..9cb43ff 100644
--- a/tests/utests/test_context.c
+++ b/tests/utests/test_context.c
@@ -285,7 +285,7 @@
assert_int_equal(ctx->module_set_id, ly_ctx_get_module_set_id(ctx));
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module x {namespace urn:x;prefix x;}", &in));
- assert_null(lys_parse_mem_module(ctx, in, 4, 1, NULL, NULL));
+ assert_int_equal(LY_EINVAL, lys_parse_mem_module(ctx, in, 4, 1, NULL, NULL, &mod1));
ly_in_free(in, 0);
logbuf_assert("Invalid schema input format.");
@@ -303,26 +303,23 @@
/* name collision of module and submodule */
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule y {belongs-to a {prefix a;} revision 2018-10-30;}");
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module y {namespace urn:y;prefix y;include y;}", &in));
- assert_null(lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL));
+ assert_int_equal(LY_EVALID, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, &mod1));
ly_in_free(in, 0);
- assert_int_equal(LY_EVALID, ly_errcode(ctx));
logbuf_assert("Name collision between module and submodule of name \"y\". Line number 1.");
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module a {namespace urn:a;prefix a;include y;revision 2018-10-30; }", &in));
- assert_non_null(lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, &mod1));
ly_in_free(in, 0);
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module y {namespace urn:y;prefix y;}", &in));
- assert_null(lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL));
+ assert_int_equal(LY_EVALID, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, &mod1));
ly_in_free(in, 0);
- assert_int_equal(LY_EVALID, ly_errcode(ctx));
logbuf_assert("Name collision between module and submodule of name \"y\". Line number 1.");
store = 1;
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule y {belongs-to b {prefix b;}}");
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module b {namespace urn:b;prefix b;include y;}", &in));
- assert_null(lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL));
+ assert_int_equal(LY_EVALID, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, &mod1));
ly_in_free(in, 0);
- assert_int_equal(LY_EVALID, ly_errcode(ctx));
logbuf_assert("Name collision between submodules of name \"y\". Line number 1.");
store = -1;
@@ -330,24 +327,21 @@
ly_ctx_reset_latests(ctx);
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule y {belongs-to a {prefix a;} revision 2018-10-31;}");
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module a {namespace urn:a;prefix a;include y; revision 2018-10-31;}", &in));
- mod2 = lys_parse_mem_module(ctx, in, LYS_IN_YANG, 0, NULL, NULL);
+ assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 0, NULL, NULL, &mod2));
ly_in_free(in, 0);
- assert_non_null(mod2);
assert_string_equal("2018-10-31", mod2->parsed->includes[0].submodule->revs[0].date);
/* reloading module in case only the compiled module resists in the context */
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module w {namespace urn:w;prefix w;revision 2018-10-24;}", &in));
- mod1 = lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL);
+ assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, &mod1));
ly_in_free(in, 0);
- assert_non_null(mod1);
assert_int_equal(LY_SUCCESS, lys_compile(&mod1, LYSC_OPT_FREE_SP));
assert_non_null(mod1->compiled);
assert_null(mod1->parsed);
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module z {namespace urn:z;prefix z;import w {prefix w;revision-date 2018-10-24;}}", &in));
- mod2 = lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL);
+ assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, &mod2));
ly_in_free(in, 0);
- assert_non_null(mod2);
/* mod1->parsed is necessary to compile mod2 because of possible groupings, typedefs, ... */
ly_ctx_set_module_imp_clb(ctx, NULL, NULL);
assert_int_equal(LY_ENOTFOUND, lys_compile(&mod2, 0));
@@ -355,9 +349,8 @@
assert_null(mod2);
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module z {namespace urn:z;prefix z;import w {prefix w;revision-date 2018-10-24;}}", &in));
- mod2 = lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL);
+ assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, &mod2));
ly_in_free(in, 0);
- assert_non_null(mod2);
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module w {namespace urn:w;prefix w;revision 2018-10-24;}");
assert_int_equal(LY_SUCCESS, lys_compile(&mod2, 0));
assert_non_null(mod2);
@@ -375,16 +368,18 @@
*state = test_imports;
struct ly_ctx *ctx;
- struct lys_module *mod1, *mod2, *import;
+ const struct lys_module *mod1, *mod2, *import;
/* import callback provides newer revision of module 'a' than present in context, so when importing 'a', the newer revision
* from the callback should be loaded into the context and used as an import */
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module a {namespace urn:a; prefix a; revision 2019-09-17;}");
- assert_non_null(mod1 = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;revision 2019-09-16;}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;revision 2019-09-16;}",
+ LYS_IN_YANG, &mod1));
assert_int_equal(1, mod1->latest_revision);
assert_int_equal(1, mod1->implemented);
- assert_non_null(mod2 = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}}",
+ LYS_IN_YANG, &mod2));
import = mod2->compiled->imports[0].module;
assert_int_equal(2, import->latest_revision);
assert_int_equal(0, mod1->latest_revision);
@@ -398,10 +393,12 @@
* already present in the context should be selected and the callback's revision should not be loaded into the context */
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module a {namespace urn:a; prefix a; revision 2019-09-17;}");
- assert_non_null(mod1 = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;revision 2019-09-18;}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;revision 2019-09-18;}",
+ LYS_IN_YANG, &mod1));
assert_int_equal(1, mod1->latest_revision);
assert_int_equal(1, mod1->implemented);
- assert_non_null(mod2 = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}}", LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}}",
+ LYS_IN_YANG, &mod2));
import = mod2->compiled->imports[0].module;
assert_ptr_equal(mod1, import);
assert_int_equal(2, import->latest_revision);
@@ -420,7 +417,7 @@
*state = test_get_models;
struct ly_ctx *ctx;
- const struct lys_module *mod, *mod2;
+ struct lys_module *mod, *mod2;
const char *str0 = "module a {namespace urn:a;prefix a;}";
const char *str1 = "module a {namespace urn:a;prefix a;revision 2018-10-23;}";
const char *str2 = "module a {namespace urn:a;prefix a;revision 2018-10-23;revision 2018-10-24;}";
@@ -459,17 +456,16 @@
assert_non_null(ly_ctx_get_module_ns(ctx, "urn:ietf:params:xml:ns:yang:ietf-datastores", "2018-02-14"));
/* select module by revision */
- mod = lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 1, NULL, NULL);
+ assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 1, NULL, NULL, &mod));
/* invalid attempts - implementing module of the same name and inserting the same module */
- assert_null(lys_parse_mem_module(ctx, in2, LYS_IN_YANG, 1, NULL, NULL));
+ assert_int_equal(LY_EDENIED, lys_parse_mem_module(ctx, in2, LYS_IN_YANG, 1, NULL, NULL, NULL));
logbuf_assert("Module \"a\" is already implemented in the context.");
ly_in_reset(in1);
- assert_null(lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 0, NULL, NULL));
+ assert_int_equal(LY_EEXIST, lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 0, NULL, NULL, NULL));
logbuf_assert("Module \"a\" of revision \"2018-10-23\" is already present in the context.");
/* insert the second module only as imported, not implemented */
ly_in_reset(in2);
- mod2 = lys_parse_mem_module(ctx, in2, LYS_IN_YANG, 0, NULL, NULL);
- assert_non_null(mod);
+ assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in2, LYS_IN_YANG, 0, NULL, NULL, &mod2));
assert_non_null(mod2);
assert_ptr_not_equal(mod, mod2);
mod = ly_ctx_get_module_latest(ctx, "a");
@@ -477,18 +473,17 @@
mod2 = ly_ctx_get_module_latest_ns(ctx, mod->ns);
assert_ptr_equal(mod, mod2);
/* work with module with no revision */
- mod = lys_parse_mem_module(ctx, in0, LYS_IN_YANG, 0, NULL, NULL);
- assert_non_null(mod);
+ assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in0, LYS_IN_YANG, 0, NULL, NULL, &mod));
assert_ptr_equal(mod, ly_ctx_get_module(ctx, "a", NULL));
assert_ptr_not_equal(mod, ly_ctx_get_module_latest(ctx, "a"));
str1 = "submodule b {belongs-to a {prefix a;}}";
ly_in_free(in1, 0);
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str1, &in1));
- assert_null(lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 1, NULL, NULL));
+ assert_int_equal(LY_EINVAL, lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 1, NULL, NULL, &mod));
logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
- while ((mod = ly_ctx_get_module_iter(ctx, &index))) {
+ while ((mod = (struct lys_module *)ly_ctx_get_module_iter(ctx, &index))) {
assert_string_equal(names[index - 1], mod->name);
}
assert_int_equal(9, index);
diff --git a/tests/utests/test_xpath.c b/tests/utests/test_xpath.c
index 32f0f8d..9301f7d 100644
--- a/tests/utests/test_xpath.c
+++ b/tests/utests/test_xpath.c
@@ -126,8 +126,8 @@
#endif
assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &ctx));
- assert_non_null(lys_parse_mem(ctx, schema_a, LYS_IN_YANG));
- assert_non_null(lys_parse_mem(ctx, schema_b, LYS_IN_YANG));
+ assert_int_equal(lys_parse_mem(ctx, schema_a, LYS_IN_YANG, NULL), LY_SUCCESS);
+ assert_int_equal(lys_parse_mem(ctx, schema_b, LYS_IN_YANG, NULL), LY_SUCCESS);
return 0;
}
diff --git a/tests/utests/test_yanglib.c b/tests/utests/test_yanglib.c
index 824f2c2..8f72540 100644
--- a/tests/utests/test_yanglib.c
+++ b/tests/utests/test_yanglib.c
@@ -145,10 +145,9 @@
assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &ctx));
ly_ctx_set_module_imp_clb(ctx, test_imp_clb, NULL);
- mod = lys_parse_mem(ctx, schema_a, LYS_IN_YANG);
- assert_non_null(mod);
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_a, LYS_IN_YANG, &mod));
assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "feat1"));
- assert_non_null(lys_parse_mem(ctx, schema_b, LYS_IN_YANG));
+ assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_b, LYS_IN_YANG, NULL));
return 0;
}
@@ -191,8 +190,7 @@
struct ly_set *set;
LY_ERR ret;
- tree = ly_ctx_get_yanglib_data(ctx);
- assert_non_null(tree);
+ assert_int_equal(LY_SUCCESS, ly_ctx_get_yanglib_data(ctx, &tree));
/* make sure there is "a" with a submodule and deviation */
ret = lyd_find_xpath(tree, "/ietf-yang-library:yang-library/module-set/module[name='a'][submodule/name='a_sub']"
diff --git a/tools/lint/commands.c b/tools/lint/commands.c
index dce7a5d..0030203 100644
--- a/tools/lint/commands.c
+++ b/tools/lint/commands.c
@@ -231,7 +231,7 @@
dir = strdup(path);
ly_ctx_set_searchdir(ctx, dirname(dir));
- model = lys_parse_path(ctx, path, format);
+ lys_parse_path(ctx, path, format, &model);
ly_ctx_unset_searchdir(ctx, index);
free(path);
free(dir);
@@ -822,7 +822,7 @@
}
if (outformat) {
- ret = lyd_print(out, data, outformat, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_FORMAT | printopt);
+ ret = lyd_print_all(out, data, outformat, LYD_PRINT_FORMAT | printopt);
ret = ret < 0 ? ret * (-1) : 0;
}
diff --git a/tools/lint/main_ni.c b/tools/lint/main_ni.c
index 202fff5..3eef135 100644
--- a/tools/lint/main_ni.c
+++ b/tools/lint/main_ni.c
@@ -704,7 +704,7 @@
}
dir = strdup(argv[optind + i]);
ly_ctx_set_searchdir(ctx, ptr = dirname(dir));
- mod = lys_parse_path(ctx, argv[optind + i], informat_s);
+ lys_parse_path(ctx, argv[optind + i], informat_s, &mod);
ly_ctx_unset_searchdir(ctx, index);
free(dir);
if (!mod) {
@@ -1067,7 +1067,7 @@
}
}
#endif
- lyd_print(out, data_item->tree, outformat_d, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_FORMAT /* TODO defaults | options_dflt */);
+ lyd_print_all(out, data_item->tree, outformat_d, LYD_PRINT_FORMAT /* TODO defaults | options_dflt */);
#if 0
if (envelope_s) {
if (data_item->type == LYD_OPT_RPC && data_item->tree->schema->nodetype != LYS_RPC) {
diff --git a/tools/re/main.c b/tools/re/main.c
index 613ec2e..01e45c4 100644
--- a/tools/re/main.c
+++ b/tools/re/main.c
@@ -268,8 +268,7 @@
}
ly_set_log_clb(pattern_error, 0);
- mod = lys_parse_mem(ctx, modstr, LYS_IN_YANG);
- if (!mod || !mod->compiled || !mod->compiled->data) {
+ if (lys_parse_mem(ctx, modstr, LYS_IN_YANG, &mod) || !mod->compiled || !mod->compiled->data) {
goto cleanup;
}