Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1969,7 +1969,7 @@ lyd_validate_tree(struct lyd_node *root, const struct lysc_ext_instance *ext, st

if (lysc_has_when(node->schema)) {
/* when evaluation */
r = ly_set_add(node_when, (void *)node, 1, NULL);
r = ly_set_add(node_when, (void *)node, 0, NULL);
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
}

Expand Down
38 changes: 38 additions & 0 deletions tests/utests/data/test_validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,43 @@ test_when(void **state)
lyd_free_all(tree);
}

static void
test_when_rpc_reply(void **state)
{
struct ly_in *in;
struct lyd_node *tree;
const char *schema =
"module a {\n"
" namespace urn:tests:a;\n"
" prefix a;\n"
" yang-version 1.1;\n"
"\n"
" rpc rpc1 {\n"
" output {\n"
" container c1 {\n"
" when \"../c = 'val_c'\";\n"
" leaf a {\n"
" type string;\n"
" }\n"
" }\n"
" leaf c {\n"
" type string;\n"
" }\n"
" }\n"
" }\n"
"}";

UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);

const char *data = "{\"a:rpc1\": {\"c\":\"wrong\"}}";

assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_JSON, LYD_TYPE_REPLY_YANG, 0, NULL, &tree));
assert_int_equal(LY_SUCCESS, lyd_validate_op(tree, NULL, LYD_TYPE_REPLY_YANG, NULL));
ly_in_free(in, 0);
lyd_free_all(tree);
}

static void
test_mandatory_when(void **state)
{
Expand Down Expand Up @@ -1600,6 +1637,7 @@ main(void)
{
const struct CMUnitTest tests[] = {
UTEST(test_when),
UTEST(test_when_rpc_reply),
UTEST(test_mandatory),
UTEST(test_mandatory_when),
UTEST(test_type_incomplete_when),
Expand Down