validation NEW rpc-reply validation
diff --git a/tests/src/test_validation.c b/tests/src/test_validation.c
index b93d388..52d59ec 100644
--- a/tests/src/test_validation.c
+++ b/tests/src/test_validation.c
@@ -385,6 +385,14 @@
"}"
"}"
"}"
+ "output {"
+ "must \"../../lf1 = 'true2'\";"
+ "leaf lf2 {"
+ "type leafref {"
+ "path /lf4;"
+ "}"
+ "}"
+ "}"
"}"
"}"
@@ -396,6 +404,10 @@
"leaf lf3 {"
"type string;"
"}"
+
+ "leaf lf4 {"
+ "type string;"
+ "}"
"}";
#if ENABLE_LOGGER_CHECKING
@@ -1338,7 +1350,7 @@
assert_non_null(op_tree);
/* missing leafref */
- assert_int_equal(LY_EVALID, lyd_validate_rpc_notif(op_tree, NULL));
+ assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, NULL, LYD_VALOPT_INPUT));
logbuf_assert("Invalid leafref - required instance \"/lf3\" does not exists in the data tree(s). /j:cont/l1[k='val1']/act/lf2");
data =
@@ -1350,7 +1362,7 @@
assert_non_null(tree);
/* disabled if-feature */
- assert_int_equal(LY_EVALID, lyd_validate_rpc_notif(op_tree, tree));
+ assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, tree, LYD_VALOPT_INPUT));
logbuf_assert("Data are disabled by \"act\" schema node if-feature. /j:cont/l1[k='val1']/act");
mod = ly_ctx_get_module_latest(ctx, "j");
@@ -1358,7 +1370,7 @@
assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "feat1"));
/* input must false */
- assert_int_equal(LY_EVALID, lyd_validate_rpc_notif(op_tree, tree));
+ assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, tree, LYD_VALOPT_INPUT));
logbuf_assert("Must condition \"../../lf1 = 'true'\" not satisfied. /j:cont/l1[k='val1']/act");
lyd_free_siblings(tree);
@@ -1371,8 +1383,77 @@
assert_non_null(tree);
/* success */
- assert_int_equal(LY_SUCCESS, lyd_validate_rpc_notif(op_tree, tree));
+ assert_int_equal(LY_SUCCESS, lyd_validate_op(op_tree, tree, LYD_VALOPT_INPUT));
+ lys_feature_disable(mod, "feat1");
+ lyd_free_tree(op_tree);
+ lyd_free_siblings(tree);
+
+ *state = NULL;
+}
+
+static void
+test_reply(void **state)
+{
+ *state = test_reply;
+
+ const char *data;
+ struct lyd_node *tree, *op_tree, *request;
+ const struct lys_module *mod;
+
+ data =
+ "<cont xmlns=\"urn:tests:j\">"
+ "<l1>"
+ "<k>val1</k>"
+ "<act>"
+ "<lf2>target</lf2>"
+ "</act>"
+ "</l1>"
+ "</cont>";
+ assert_int_equal(LY_SUCCESS, lyd_parse_xml_rpc(ctx, data, &request, NULL));
+ assert_non_null(request);
+ data = "<lf2 xmlns=\"urn:tests:j\">target</lf2>";
+ assert_int_equal(LY_SUCCESS, lyd_parse_xml_reply(request, data, &op_tree, NULL));
+ lyd_free_all(request);
+ assert_non_null(op_tree);
+
+ /* missing leafref */
+ assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, NULL, LYD_VALOPT_OUTPUT));
+ logbuf_assert("Invalid leafref - required instance \"/lf4\" does not exists in the data tree(s). /j:cont/l1[k='val1']/act/lf2");
+
+ data =
+ "<cont xmlns=\"urn:tests:j\">"
+ "<lf1>not true</lf1>"
+ "</cont>"
+ "<lf4 xmlns=\"urn:tests:j\">target</lf4>";
+ assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_OPT_PARSE_ONLY | LYD_OPT_TRUSTED, &tree));
+ assert_non_null(tree);
+
+ /* disabled if-feature */
+ assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, tree, LYD_VALOPT_OUTPUT));
+ logbuf_assert("Data are disabled by \"act\" schema node if-feature. /j:cont/l1[k='val1']/act");
+
+ mod = ly_ctx_get_module_latest(ctx, "j");
+ assert_non_null(mod);
+ assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "feat1"));
+
+ /* input must false */
+ assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, tree, LYD_VALOPT_OUTPUT));
+ logbuf_assert("Must condition \"../../lf1 = 'true2'\" not satisfied. /j:cont/l1[k='val1']/act");
+
+ lyd_free_siblings(tree);
+ data =
+ "<cont xmlns=\"urn:tests:j\">"
+ "<lf1>true2</lf1>"
+ "</cont>"
+ "<lf4 xmlns=\"urn:tests:j\">target</lf4>";
+ assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_OPT_PARSE_ONLY | LYD_OPT_TRUSTED, &tree));
+ assert_non_null(tree);
+
+ /* success */
+ assert_int_equal(LY_SUCCESS, lyd_validate_op(op_tree, tree, LYD_VALOPT_OUTPUT));
+
+ lys_feature_disable(mod, "feat1");
lyd_free_tree(op_tree);
lyd_free_siblings(tree);
@@ -1393,6 +1474,7 @@
cmocka_unit_test_teardown(test_state, teardown_s),
cmocka_unit_test_teardown(test_must, teardown_s),
cmocka_unit_test_teardown(test_action, teardown_s),
+ cmocka_unit_test_teardown(test_reply, teardown_s),
};
return cmocka_run_group_tests(tests, setup, teardown);