yin parser CHANGE add support for action element
diff --git a/src/parser_yin.c b/src/parser_yin.c
index a15bc20..b366f86 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -1552,13 +1552,13 @@
LY_CHECK_RET(yin_parse_attribute(ctx, attrs, YIN_ARG_NAME, &list->name, Y_IDENTIF_ARG, YANG_LIST));
/* parse list content */
+ struct action_meta act_meta = {(struct lysp_node *)list, &list->actions};
struct tree_node_meta new_node_meta = {(struct lysp_node *)list, &list->child};
struct typedef_meta typedef_meta = {(struct lysp_node *)list, &list->typedefs};
struct notif_meta notif_meta = {(struct lysp_node *)list, &list->notifs};
struct grouping_meta gr_meta = {(struct lysp_node *)list, &list->groupings};
struct yin_subelement subelems[25] = {
- /* TODO action */
- {YANG_ACTION, NULL, 0},
+ {YANG_ACTION, &act_meta, 0},
{YANG_ANYDATA, &new_node_meta, 0},
{YANG_ANYXML, &new_node_meta, 0},
{YANG_CHOICE, &new_node_meta, 0},
@@ -1678,13 +1678,13 @@
LY_CHECK_RET(yin_parse_attribute(ctx, attrs, YIN_ARG_NAME, &grp->name, Y_IDENTIF_ARG, YANG_GROUPING));
/* parse grouping content */
+ struct action_meta act_meta = {(struct lysp_node *)grp, &grp->actions};
struct tree_node_meta node_meta = {(struct lysp_node *)grp, &grp->data};
struct typedef_meta typedef_meta = {(struct lysp_node *)grp, &grp->typedefs};
struct grouping_meta sub_grouping = {(struct lysp_node *)grp, &grp->groupings};
struct notif_meta notif_meta = {(struct lysp_node *)grp, &grp->notifs};
struct yin_subelement subelems[16] = {
- /* TODO action */
- {YANG_ACTION, NULL, 0},
+ {YANG_ACTION, &act_meta, 0},
{YANG_ANYDATA, &node_meta, 0},
{YANG_ANYXML, &node_meta, 0},
{YANG_CHOICE, &node_meta, 0},
@@ -1743,13 +1743,14 @@
LY_CHECK_RET(yin_parse_attribute(ctx, attrs, YIN_ARG_NAME, &cont->name, Y_IDENTIF_ARG, YANG_CONTAINER));
/* parse container content */
+ struct action_meta act_meta = {(struct lysp_node *)cont, &cont->actions};
struct tree_node_meta new_node_meta = {(struct lysp_node *)cont, &cont->child};
struct grouping_meta grp_meta = {(struct lysp_node *)cont, &cont->groupings};
struct typedef_meta typedef_meta = {(struct lysp_node *)cont, &cont->typedefs};
struct notif_meta notif_meta = {(struct lysp_node *)cont, &cont->notifs};
struct yin_subelement subelems[21] = {
/* TODO action */
- {YANG_ACTION, NULL, YIN_SUBELEM_VER2},
+ {YANG_ACTION, &act_meta, YIN_SUBELEM_VER2},
{YANG_ANYDATA, &new_node_meta, YIN_SUBELEM_VER2},
{YANG_ANYXML, &new_node_meta, 0},
{YANG_CHOICE, &new_node_meta, 0},
@@ -1938,6 +1939,42 @@
return LY_SUCCESS;
}
+static LY_ERR
+yin_parse_action(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data,
+ struct action_meta *act_meta)
+{
+ struct lysp_action *act;
+
+ /* create new action */
+ LY_ARRAY_NEW_RET(ctx->xml_ctx.ctx, *act_meta->actions, act, LY_EMEM);
+ act->nodetype = LYS_ACTION;
+ act->parent = act_meta->parent;
+
+ /* parse argument */
+ LY_CHECK_RET(yin_parse_attribute(ctx, attrs, YIN_ARG_NAME, &act->name, Y_IDENTIF_ARG, YANG_ACTION));
+
+ /* parse content */
+ struct grouping_meta grp_meta = {(struct lysp_node *)act, &act->groupings};
+ struct typedef_meta typedef_meta = {(struct lysp_node *)act, &act->typedefs};
+ struct inout_meta input = {(struct lysp_node *)act, &act->input};
+ struct inout_meta output = {(struct lysp_node *)act, &act->output};
+ struct yin_subelement subelems[9] = {
+ {YANG_DESCRIPTION, &act->dsc, YIN_SUBELEM_UNIQUE},
+ {YANG_GROUPING, &grp_meta, 0},
+ {YANG_IF_FEATURE, &act->iffeatures, 0},
+ {YANG_INPUT, &input, YIN_SUBELEM_UNIQUE},
+ {YANG_OUTPUT, &output, YIN_SUBELEM_UNIQUE},
+ {YANG_REFERENCE, &act->ref, YIN_SUBELEM_UNIQUE},
+ {YANG_STATUS, &act->flags, YIN_SUBELEM_UNIQUE},
+ {YANG_TYPEDEF, &typedef_meta, 0},
+ {YANG_CUSTOM, NULL, 0},
+ };
+ LY_CHECK_RET(yin_parse_content(ctx, subelems, 9, data, YANG_ACTION, NULL, &act->exts));
+ LY_CHECK_RET(lysp_parse_finalize_reallocated((struct lys_parser_ctx *)ctx, act->groupings, NULL, NULL, NULL));
+
+ return LY_SUCCESS;
+}
+
/**
* @brief Map keyword type to substatement info.
*
@@ -2086,6 +2123,7 @@
(subelem->dest) ? *((uint32_t*)subelem->dest) : 0, exts);
break;
case YANG_ACTION:
+ ret = yin_parse_action(ctx, attrs, data, (struct action_meta *)subelem->dest);
break;
case YANG_ANYDATA:
case YANG_ANYXML:
diff --git a/src/parser_yin.h b/src/parser_yin.h
index 98fa8e4..3174abe 100644
--- a/src/parser_yin.h
+++ b/src/parser_yin.h
@@ -129,10 +129,16 @@
/* Meta information passed to yin_parse_grouping function */
struct inout_meta {
- struct lysp_node *parent; /**< Parent node. */
+ struct lysp_node *parent; /**< Parent node. */
struct lysp_action_inout *inout_p; /**< inout_p Input/output pointer to write to. */
};
+/* Meta information passed to yin_parse_action */
+struct action_meta {
+ struct lysp_node *parent; /**< Parent node. */
+ struct lysp_action **actions; /**< Actions to add to. */
+};
+
/**
* @brief Match argument name.
*
diff --git a/tests/src/test_parser_yin.c b/tests/src/test_parser_yin.c
index acd6c83..a5da6de 100644
--- a/tests/src/test_parser_yin.c
+++ b/tests/src/test_parser_yin.c
@@ -42,6 +42,7 @@
void lysp_notif_free(struct ly_ctx *ctx, struct lysp_notif *notif);
void lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp);
void lysp_action_inout_free(struct ly_ctx *ctx, struct lysp_action_inout *inout);
+void lysp_action_free(struct ly_ctx *ctx, struct lysp_action *action);
struct state {
struct ly_ctx *ctx;
@@ -2552,7 +2553,7 @@
"<anyxml name=\"anyx\"/>"
"<container name=\"cont\"/>"
"<choice name=\"choice\"/>"
- // "<action name=\"action\"/>"
+ "<action name=\"action\"/>"
"<grouping name=\"grp\"/>"
"<notification name=\"notf\"/>"
"<leaf name=\"leaf\"/>"
@@ -2573,10 +2574,17 @@
assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER);
assert_string_equal(parsed->child->next->next->next->name, "choice");
assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE);
- // assert_string_equal(parsed->child->next->next->next->next->name, "action");
- // assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_ACTION);
- // assert_null(parsed->child->next->next->next->next->next);
+ assert_string_equal(parsed->child->next->next->next->next->name, "leaf");
+ assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF);
+ assert_string_equal(parsed->child->next->next->next->next->next->name, "llist");
+ assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST);
+ assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list");
+ assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST);
+ assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name");
+ assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES);
+ assert_null(parsed->child->next->next->next->next->next->next->next->next);
assert_string_equal(parsed->groupings->name, "grp");
+ assert_string_equal(parsed->actions->name, "action");
assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING);
assert_string_equal(parsed->notifs->name, "notf");
assert_null(parsed->exts);
@@ -2704,7 +2712,7 @@
"<status value=\"current\"/>"
"<typedef name=\"tpdf\"/>"
"<uses name=\"uses-name\"/>"
- // "<action name=\"act\"/>"
+ "<action name=\"act\"/>"
"<container name=\"cont\"/>"
"<choice name=\"choice\"/>"
"</grouping>"
@@ -2725,7 +2733,7 @@
assert_null(grps->parent);
assert_string_equal(grps->ref, "ref");
assert_string_equal(grps->typedefs->name, "tpdf");
- // assert_string_equal(grps->actions->name, "act");
+ assert_string_equal(grps->actions->name, "act");
assert_string_equal(grps->data->next->next->next->next->next->name, "uses-name");
assert_int_equal(grps->data->next->next->next->next->next->nodetype, LYS_USES);
assert_string_equal(grps->data->next->next->next->next->next->next->name, "cont");
@@ -2776,7 +2784,7 @@
"<typedef name=\"tpdf\"/>"
"<uses name=\"uses-name\"/>"
"<when condition=\"when-cond\"/>"
- // "<action name=\"act\"/>"
+ "<action name=\"act\"/>"
"<choice name=\"choice\"/>"
"</container>"
ELEMENT_WRAPPER_END;
@@ -2815,7 +2823,7 @@
assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
assert_null(parsed->child->next->next->next->next->next->next->next->next);
assert_string_equal(parsed->notifs->name, "notf");
- //assert_string_equal(parsed->actions->name, "act");
+ assert_string_equal(parsed->actions->name, "act");
lysp_node_free(st->ctx, siblings);
ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
siblings = NULL;
@@ -3088,6 +3096,54 @@
st->finished_correctly = true;
}
+static void
+test_action_elem(void **state)
+{
+ struct state *st = *state;
+ const char *data;
+ struct lysp_action *actions = NULL;
+ struct action_meta act_meta = {NULL, &actions};
+
+ /* max subelems */
+ st->yin_ctx->mod_version = LYS_VERSION_1_1;
+ data = ELEMENT_WRAPPER_START
+ "<action name=\"act\">"
+ "<description><text>desc</text></description>"
+ "<grouping name=\"grouping\"/>"
+ "<if-feature name=\"iff\"/>"
+ "<input><uses name=\"uses-name\"/></input>"
+ "<output><must condition=\"cond\"/></output>"
+ "<reference><text>ref</text></reference>"
+ "<status value=\"deprecated\"/>"
+ "<typedef name=\"tpdf\"/>"
+ "</action>"
+ ELEMENT_WRAPPER_END;
+ assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS);
+ assert_null(actions->parent);
+ assert_int_equal(actions->nodetype, LYS_ACTION);
+ assert_true(actions->flags & LYS_STATUS_DEPRC);
+ assert_string_equal(actions->name, "act");
+ assert_string_equal(actions->dsc, "desc");
+ assert_string_equal(actions->ref, "ref");
+ assert_string_equal(*actions->iffeatures, "iff");
+ assert_string_equal(actions->typedefs->name, "tpdf");
+ assert_string_equal(actions->groupings->name, "grouping");
+ assert_string_equal(actions->input.data->name, "uses-name");
+ assert_string_equal(actions->output.musts->arg, "cond");
+ assert_null(actions->exts);
+ FREE_ARRAY(st->ctx, actions, lysp_action_free)
+ actions = NULL;
+
+ /* min subelems */
+ data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END;
+ assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS);
+ assert_string_equal(actions->name, "act");
+ FREE_ARRAY(st->ctx, actions, lysp_action_free)
+ actions = NULL;
+
+ st->finished_correctly = true;
+}
+
int
main(void)
{
@@ -3155,6 +3211,7 @@
cmocka_unit_test_setup_teardown(test_case_elem, setup_element_test, teardown_element_test),
cmocka_unit_test_setup_teardown(test_choice_elem, setup_element_test, teardown_element_test),
cmocka_unit_test_setup_teardown(test_inout_elem, setup_element_test, teardown_element_test),
+ cmocka_unit_test_setup_teardown(test_action_elem, setup_element_test, teardown_element_test),
};
return cmocka_run_group_tests(tests, setup_ly_ctx, destroy_ly_ctx);