Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1 | /* |
| 2 | * @file set.c |
| 3 | * @author: Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief unit tests for functions from common.c |
| 5 | * |
| 6 | * Copyright (c) 2018 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 14 | #include "test_schema.h" |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 15 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 16 | #include <string.h> |
| 17 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 18 | #include "context.h" |
| 19 | #include "log.h" |
| 20 | #include "tree_schema.h" |
| 21 | #include "tree_schema_internal.h" |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 22 | |
| 23 | void |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 24 | test_getnext(void **state) |
| 25 | { |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 26 | const struct lys_module *mod; |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 27 | const struct lysc_node *node = NULL, *four; |
| 28 | const struct lysc_node_container *cont; |
| 29 | const struct lysc_action *rpc; |
| 30 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 31 | assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1; namespace urn:a;prefix a;" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 32 | "container a { container one {presence test;} leaf two {type string;} leaf-list three {type string;}" |
| 33 | " list four {config false;} choice x { leaf five {type string;} case y {leaf six {type string;}}}" |
| 34 | " anyxml seven; action eight {input {leaf eight-input {type string;}} output {leaf eight-output {type string;}}}" |
| 35 | " notification nine {leaf nine-data {type string;}}}" |
| 36 | "leaf b {type string;} leaf-list c {type string;} list d {config false;}" |
| 37 | "choice x { case empty-x { choice empty-xc { case nothing;}} leaf e {type string;} case y {leaf f {type string;}}} anyxml g;" |
| 38 | "rpc h {input {leaf h-input {type string;}} output {leaf h-output {type string;}}}" |
| 39 | "rpc i;" |
| 40 | "notification j {leaf i-data {type string;}}" |
| 41 | "notification k;}", LYS_IN_YANG, &mod)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 42 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 43 | assert_string_equal("a", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 44 | cont = (const struct lysc_node_container *)node; |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 45 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 46 | assert_string_equal("b", node->name); |
| 47 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 48 | assert_string_equal("c", node->name); |
| 49 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 50 | assert_string_equal("d", node->name); |
| 51 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 52 | assert_string_equal("e", node->name); |
| 53 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 54 | assert_string_equal("f", node->name); |
| 55 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 56 | assert_string_equal("g", node->name); |
| 57 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 58 | assert_string_equal("h", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 59 | rpc = (const struct lysc_action *)node; |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 60 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 61 | assert_string_equal("i", node->name); |
| 62 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 63 | assert_string_equal("j", node->name); |
| 64 | assert_non_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 65 | assert_string_equal("k", node->name); |
| 66 | assert_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
| 67 | /* Inside container */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 68 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 69 | assert_string_equal("one", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 70 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 71 | assert_string_equal("two", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 72 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 73 | assert_string_equal("three", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 74 | assert_non_null(node = four = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 75 | assert_string_equal("four", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 76 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 77 | assert_string_equal("five", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 78 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 79 | assert_string_equal("six", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 80 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 81 | assert_string_equal("seven", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 82 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 83 | assert_string_equal("eight", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 84 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 85 | assert_string_equal("nine", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 86 | assert_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 87 | /* Inside RPC */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 88 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)rpc, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 89 | assert_string_equal("h-input", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 90 | assert_null(node = lys_getnext(node, (const struct lysc_node *)rpc, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 91 | |
| 92 | /* options */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 93 | assert_non_null(node = lys_getnext(four, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCHOICE)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 94 | assert_string_equal("x", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 95 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCHOICE)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 96 | assert_string_equal("seven", node->name); |
| 97 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 98 | assert_non_null(node = lys_getnext(four, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_NOCHOICE)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 99 | assert_string_equal("seven", node->name); |
| 100 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 101 | assert_non_null(node = lys_getnext(four, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCASE)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 102 | assert_string_equal("five", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 103 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCASE)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 104 | assert_string_equal("y", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 105 | assert_non_null(node = lys_getnext(node, (const struct lysc_node *)cont, mod->compiled, LYS_GETNEXT_WITHCASE)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 106 | assert_string_equal("seven", node->name); |
| 107 | |
| 108 | assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, LYS_GETNEXT_INTONPCONT)); |
| 109 | assert_string_equal("one", node->name); |
| 110 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 111 | assert_non_null(node = lys_getnext(NULL, (const struct lysc_node *)rpc, mod->compiled, LYS_GETNEXT_OUTPUT)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 112 | assert_string_equal("h-output", node->name); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 113 | assert_null(node = lys_getnext(node, (const struct lysc_node *)rpc, mod->compiled, LYS_GETNEXT_OUTPUT)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 114 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 115 | assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c; rpc c;}", LYS_IN_YANG, &mod)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 116 | assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0)); |
| 117 | assert_string_equal("c", node->name); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 118 | assert_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 119 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 120 | assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; notification d;}", LYS_IN_YANG, &mod)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 121 | assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0)); |
| 122 | assert_string_equal("d", node->name); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 123 | assert_null(node = lys_getnext(node, NULL, mod->compiled, 0)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 124 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 125 | assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e; container c {container cc;} leaf a {type string;}}", LYS_IN_YANG, &mod)); |
Radek Krejci | b93bd41 | 2020-11-02 13:23:11 +0100 | [diff] [blame] | 126 | assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0)); |
| 127 | assert_string_equal("c", node->name); |
| 128 | assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, LYS_GETNEXT_INTONPCONT)); |
| 129 | assert_string_equal("a", node->name); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 130 | } |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 131 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 132 | void |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 133 | test_date(void **state) |
| 134 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 135 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, NULL, 0, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 136 | CHECK_LOG("Invalid argument date (lysp_check_date()).", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 137 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "x", 1, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 138 | CHECK_LOG("Invalid argument date_len (lysp_check_date()).", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 139 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "nonsencexx", 10, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 140 | CHECK_LOG("Invalid value \"nonsencexx\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 141 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "123x-11-11", 10, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 142 | CHECK_LOG("Invalid value \"123x-11-11\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 143 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-13-11", 10, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 144 | CHECK_LOG("Invalid value \"2018-13-11\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 145 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-11-41", 10, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 146 | CHECK_LOG("Invalid value \"2018-11-41\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 147 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-02-29", 10, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 148 | CHECK_LOG("Invalid value \"2018-02-29\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 149 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018.02-28", 10, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 150 | CHECK_LOG("Invalid value \"2018.02-28\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 151 | assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-02.28", 10, "date")); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 152 | CHECK_LOG("Invalid value \"2018-02.28\" of \"date\".", NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 153 | |
| 154 | assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2018-11-11", 10, "date")); |
| 155 | assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2018-02-28", 10, "date")); |
| 156 | assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2016-02-29", 10, "date")); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 157 | } |
| 158 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 159 | void |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 160 | test_revisions(void **state) |
| 161 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 162 | struct lysp_revision *revs = NULL, *rev; |
| 163 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 164 | /* no error, it just does nothing */ |
| 165 | lysp_sort_revisions(NULL); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 166 | CHECK_LOG(NULL, NULL); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 167 | |
| 168 | /* revisions are stored in wrong order - the newest is the last */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 169 | LY_ARRAY_NEW_RET(NULL, revs, rev, ); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 170 | strcpy(rev->date, "2018-01-01"); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 171 | LY_ARRAY_NEW_RET(NULL, revs, rev, ); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 172 | strcpy(rev->date, "2018-12-31"); |
| 173 | |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 174 | assert_int_equal(2, LY_ARRAY_COUNT(revs)); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 175 | assert_string_equal("2018-01-01", &revs[0]); |
| 176 | assert_string_equal("2018-12-31", &revs[1]); |
| 177 | /* the order should be fixed, so the newest revision will be the first in the array */ |
| 178 | lysp_sort_revisions(revs); |
| 179 | assert_string_equal("2018-12-31", &revs[0]); |
| 180 | assert_string_equal("2018-01-01", &revs[1]); |
| 181 | |
| 182 | LY_ARRAY_FREE(revs); |
| 183 | } |
| 184 | |
Radek Krejci | 18abde4 | 2020-06-13 20:04:39 +0200 | [diff] [blame] | 185 | void |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 186 | test_typedef(void **state) |
| 187 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 188 | const char *str; |
| 189 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 190 | str = "module a {namespace urn:a; prefix a; typedef binary {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 191 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 192 | CHECK_LOG("Invalid name \"binary\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 193 | str = "module a {namespace urn:a; prefix a; typedef bits {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 194 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 195 | CHECK_LOG("Invalid name \"bits\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 196 | str = "module a {namespace urn:a; prefix a; typedef boolean {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 197 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 198 | CHECK_LOG("Invalid name \"boolean\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 199 | str = "module a {namespace urn:a; prefix a; typedef decimal64 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 200 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 201 | CHECK_LOG("Invalid name \"decimal64\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 202 | str = "module a {namespace urn:a; prefix a; typedef empty {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 203 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 204 | CHECK_LOG("Invalid name \"empty\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 205 | str = "module a {namespace urn:a; prefix a; typedef enumeration {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 206 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 207 | CHECK_LOG("Invalid name \"enumeration\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 208 | str = "module a {namespace urn:a; prefix a; typedef int8 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 209 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 210 | CHECK_LOG("Invalid name \"int8\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 211 | str = "module a {namespace urn:a; prefix a; typedef int16 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 212 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 213 | CHECK_LOG("Invalid name \"int16\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 214 | str = "module a {namespace urn:a; prefix a; typedef int32 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 215 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 216 | CHECK_LOG("Invalid name \"int32\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 217 | str = "module a {namespace urn:a; prefix a; typedef int64 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 218 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 219 | CHECK_LOG("Invalid name \"int64\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 220 | str = "module a {namespace urn:a; prefix a; typedef instance-identifier {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 221 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 222 | CHECK_LOG("Invalid name \"instance-identifier\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 223 | str = "module a {namespace urn:a; prefix a; typedef identityref {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 224 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 225 | CHECK_LOG("Invalid name \"identityref\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 226 | str = "module a {namespace urn:a; prefix a; typedef leafref {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 227 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 228 | CHECK_LOG("Invalid name \"leafref\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 229 | str = "module a {namespace urn:a; prefix a; typedef string {type int8;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 230 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 231 | CHECK_LOG("Invalid name \"string\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 232 | str = "module a {namespace urn:a; prefix a; typedef union {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 233 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 234 | CHECK_LOG("Invalid name \"union\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 235 | str = "module a {namespace urn:a; prefix a; typedef uint8 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 236 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 237 | CHECK_LOG("Invalid name \"uint8\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 238 | str = "module a {namespace urn:a; prefix a; typedef uint16 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 239 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 240 | CHECK_LOG("Invalid name \"uint16\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 241 | str = "module a {namespace urn:a; prefix a; typedef uint32 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 242 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 243 | CHECK_LOG("Invalid name \"uint32\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 244 | str = "module a {namespace urn:a; prefix a; typedef uint64 {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 245 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 246 | CHECK_LOG("Invalid name \"uint64\" of typedef - name collision with a built-in type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 247 | |
| 248 | str = "module mytypes {namespace urn:types; prefix t; typedef binary_ {type string;} typedef bits_ {type string;} typedef boolean_ {type string;} " |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 249 | "typedef decimal64_ {type string;} typedef empty_ {type string;} typedef enumeration_ {type string;} typedef int8_ {type string;} typedef int16_ {type string;}" |
| 250 | "typedef int32_ {type string;} typedef int64_ {type string;} typedef instance-identifier_ {type string;} typedef identityref_ {type string;}" |
| 251 | "typedef leafref_ {type string;} typedef string_ {type int8;} typedef union_ {type string;} typedef uint8_ {type string;} typedef uint16_ {type string;}" |
| 252 | "typedef uint32_ {type string;} typedef uint64_ {type string;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 253 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 254 | |
| 255 | str = "module a {namespace urn:a; prefix a; typedef test {type string;} typedef test {type int8;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 256 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 257 | CHECK_LOG("Invalid name \"test\" of typedef - name collision with another top-level type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 258 | |
| 259 | str = "module a {namespace urn:a; prefix a; typedef x {type string;} container c {typedef x {type int8;}}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 260 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 261 | CHECK_LOG("Invalid name \"x\" of typedef - scoped type collide with a top-level type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 262 | |
| 263 | str = "module a {namespace urn:a; prefix a; container c {container d {typedef y {type int8;}} typedef y {type string;}}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 264 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 265 | CHECK_LOG("Invalid name \"y\" of typedef - name collision with another scoped type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 266 | |
| 267 | str = "module a {namespace urn:a; prefix a; container c {typedef y {type int8;} typedef y {type string;}}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 268 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 269 | CHECK_LOG("Invalid name \"y\" of typedef - name collision with sibling type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 270 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 271 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type string;}}"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 272 | str = "module a {namespace urn:a; prefix a; include b; typedef x {type int8;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 273 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 274 | CHECK_LOG("Invalid name \"x\" of typedef - name collision with another top-level type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 275 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 276 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} container c {typedef x {type string;}}}"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 277 | str = "module a {namespace urn:a; prefix a; include b; typedef x {type int8;}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 278 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 279 | CHECK_LOG("Invalid name \"x\" of typedef - scoped type collide with a top-level type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 280 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 281 | ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type int8;}}"); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 282 | str = "module a {namespace urn:a; prefix a; include b; container c {typedef x {type string;}}}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 283 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST); |
| 284 | CHECK_LOG("Invalid name \"x\" of typedef - scoped type collide with a top-level type.", "Line number 1."); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 285 | } |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 286 | |
| 287 | void |
| 288 | test_accessible_tree(void **state) |
| 289 | { |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 290 | const char *str; |
| 291 | |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 292 | /* config -> config */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 293 | str = "module a {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 294 | " namespace urn:a;\n" |
| 295 | " prefix a;\n" |
| 296 | " container cont {\n" |
| 297 | " leaf l {\n" |
| 298 | " type empty;\n" |
| 299 | " }\n" |
| 300 | " }\n" |
| 301 | " container cont2 {\n" |
| 302 | " leaf l2 {\n" |
| 303 | " must ../../cont/l;\n" |
| 304 | " type leafref {\n" |
| 305 | " path /cont/l;\n" |
| 306 | " }\n" |
| 307 | " }\n" |
| 308 | " }\n" |
| 309 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 310 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 311 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 312 | |
| 313 | /* config -> state leafref */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 314 | str = "module b {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 315 | " namespace urn:a;\n" |
| 316 | " prefix a;\n" |
| 317 | " container cont {\n" |
| 318 | " config false;\n" |
| 319 | " leaf l {\n" |
| 320 | " type empty;\n" |
| 321 | " }\n" |
| 322 | " }\n" |
| 323 | " container cont2 {\n" |
| 324 | " leaf l2 {\n" |
| 325 | " type leafref {\n" |
| 326 | " path /cont/l;\n" |
| 327 | " }\n" |
| 328 | " }\n" |
| 329 | " }\n" |
| 330 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 331 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 332 | CHECK_LOG_CTX("Invalid leafref path \"/cont/l\" - target is supposed to represent configuration data" |
| 333 | " (as the leafref does), but it does not.", "/b:cont2/l2"); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 334 | |
| 335 | /* config -> state must */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 336 | str = "module b {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 337 | " namespace urn:a;\n" |
| 338 | " prefix a;\n" |
| 339 | " container cont {\n" |
| 340 | " config false;\n" |
| 341 | " leaf l {\n" |
| 342 | " type empty;\n" |
| 343 | " }\n" |
| 344 | " }\n" |
| 345 | " container cont2 {\n" |
| 346 | " leaf l2 {\n" |
| 347 | " must ../../cont/l;\n" |
| 348 | " type empty;\n" |
| 349 | " }\n" |
| 350 | " }\n" |
| 351 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 352 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 353 | CHECK_LOG_CTX("Schema node \"l\" not found (\"../../cont/l\") with context node \"/b:cont2/l2\".", NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 354 | |
| 355 | /* state -> config */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 356 | str = "module c {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 357 | " namespace urn:a;\n" |
| 358 | " prefix a;\n" |
| 359 | " container cont {\n" |
| 360 | " leaf l {\n" |
| 361 | " type empty;\n" |
| 362 | " }\n" |
| 363 | " }\n" |
| 364 | " container cont2 {\n" |
| 365 | " config false;\n" |
| 366 | " leaf l2 {\n" |
| 367 | " must ../../cont/l;\n" |
| 368 | " type leafref {\n" |
| 369 | " path /cont/l;\n" |
| 370 | " }\n" |
| 371 | " }\n" |
| 372 | " }\n" |
| 373 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 374 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 375 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 376 | |
| 377 | /* notif -> state */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 378 | str = "module d {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 379 | " namespace urn:a;\n" |
| 380 | " prefix a;\n" |
| 381 | " container cont {\n" |
| 382 | " config false;\n" |
| 383 | " leaf l {\n" |
| 384 | " type empty;\n" |
| 385 | " }\n" |
| 386 | " }\n" |
| 387 | " notification notif {\n" |
| 388 | " leaf l2 {\n" |
| 389 | " must ../../cont/l;\n" |
| 390 | " type leafref {\n" |
| 391 | " path /cont/l;\n" |
| 392 | " }\n" |
| 393 | " }\n" |
| 394 | " }\n" |
| 395 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 396 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 397 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 398 | |
| 399 | /* notif -> notif */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 400 | str = "module e {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 401 | " namespace urn:a;\n" |
| 402 | " prefix a;\n" |
| 403 | " notification notif {\n" |
| 404 | " leaf l {\n" |
| 405 | " type empty;\n" |
| 406 | " }\n" |
| 407 | " leaf l2 {\n" |
| 408 | " must ../../notif/l;\n" |
| 409 | " type leafref {\n" |
| 410 | " path /notif/l;\n" |
| 411 | " }\n" |
| 412 | " }\n" |
| 413 | " }\n" |
| 414 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 415 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 416 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 417 | |
| 418 | /* rpc input -> state */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 419 | str = "module f {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 420 | " namespace urn:a;\n" |
| 421 | " prefix a;\n" |
| 422 | " container cont {\n" |
| 423 | " config false;\n" |
| 424 | " leaf l {\n" |
| 425 | " type empty;\n" |
| 426 | " }\n" |
| 427 | " }\n" |
| 428 | " rpc rp {\n" |
| 429 | " input {\n" |
| 430 | " leaf l2 {\n" |
| 431 | " must ../../cont/l;\n" |
| 432 | " type leafref {\n" |
| 433 | " path /cont/l;\n" |
| 434 | " }\n" |
| 435 | " }\n" |
| 436 | " }\n" |
| 437 | " }\n" |
| 438 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 439 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 440 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 441 | |
| 442 | /* rpc input -> rpc input */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 443 | str = "module g {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 444 | " namespace urn:a;\n" |
| 445 | " prefix a;\n" |
| 446 | " rpc rp {\n" |
| 447 | " input {\n" |
| 448 | " leaf l {\n" |
| 449 | " type empty;\n" |
| 450 | " }\n" |
| 451 | " leaf l2 {\n" |
| 452 | " must ../l;\n" |
| 453 | " type leafref {\n" |
| 454 | " path /rp/l;\n" |
| 455 | " }\n" |
| 456 | " }\n" |
| 457 | " }\n" |
| 458 | " }\n" |
| 459 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 460 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 461 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 462 | |
| 463 | /* rpc input -> rpc output leafref */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 464 | str = "module h {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 465 | " namespace urn:a;\n" |
| 466 | " prefix a;\n" |
| 467 | " rpc rp {\n" |
| 468 | " input {\n" |
| 469 | " leaf l2 {\n" |
| 470 | " type leafref {\n" |
| 471 | " path /rp/l;\n" |
| 472 | " }\n" |
| 473 | " }\n" |
| 474 | " }\n" |
| 475 | " output {\n" |
| 476 | " leaf l {\n" |
| 477 | " type empty;\n" |
| 478 | " }\n" |
| 479 | " }\n" |
| 480 | " }\n" |
| 481 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 482 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 483 | CHECK_LOG_CTX("Not found node \"l\" in path.", "/h:rp/l2"); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 484 | |
| 485 | /* rpc input -> rpc output must */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 486 | str = "module h {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 487 | " namespace urn:a;\n" |
| 488 | " prefix a;\n" |
| 489 | " rpc rp {\n" |
| 490 | " input {\n" |
| 491 | " leaf l2 {\n" |
| 492 | " must ../l;\n" |
| 493 | " type empty;\n" |
| 494 | " }\n" |
| 495 | " }\n" |
| 496 | " output {\n" |
| 497 | " leaf l {\n" |
| 498 | " type empty;\n" |
| 499 | " }\n" |
| 500 | " }\n" |
| 501 | " }\n" |
| 502 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 503 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 504 | CHECK_LOG_CTX("Schema node \"l\" not found (\"../l\") with context node \"/h:rp/l2\".", NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 505 | |
| 506 | /* rpc input -> notif leafref */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 507 | str = "module i {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 508 | " namespace urn:a;\n" |
| 509 | " prefix a;\n" |
| 510 | " rpc rp {\n" |
| 511 | " input {\n" |
| 512 | " leaf l2 {\n" |
| 513 | " type leafref {\n" |
| 514 | " path ../../notif/l;\n" |
| 515 | " }\n" |
| 516 | " }\n" |
| 517 | " }\n" |
| 518 | " }\n" |
| 519 | " notification notif {\n" |
| 520 | " leaf l {\n" |
| 521 | " type empty;\n" |
| 522 | " }\n" |
| 523 | " }\n" |
| 524 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 525 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 526 | CHECK_LOG_CTX("Not found node \"notif\" in path.", "/i:rp/l2"); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 527 | |
| 528 | /* rpc input -> notif must */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 529 | str = "module i {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 530 | " namespace urn:a;\n" |
| 531 | " prefix a;\n" |
| 532 | " rpc rp {\n" |
| 533 | " input {\n" |
| 534 | " leaf l2 {\n" |
| 535 | " must /notif/l;\n" |
| 536 | " type empty;\n" |
| 537 | " }\n" |
| 538 | " }\n" |
| 539 | " }\n" |
| 540 | " notification notif {\n" |
| 541 | " leaf l {\n" |
| 542 | " type empty;\n" |
| 543 | " }\n" |
| 544 | " }\n" |
| 545 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 546 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 547 | CHECK_LOG_CTX("Schema node \"l\" not found (\"/notif/l\") with context node \"/i:rp/l2\".", NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 548 | |
| 549 | /* action output -> state */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 550 | str = "module j {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 551 | " yang-version 1.1;\n" |
| 552 | " namespace urn:a;\n" |
| 553 | " prefix a;\n" |
| 554 | " container cont {\n" |
| 555 | " list ll {\n" |
| 556 | " key k;\n" |
| 557 | " leaf k {\n" |
| 558 | " type string;\n" |
| 559 | " }\n" |
| 560 | " action act {\n" |
| 561 | " output {\n" |
| 562 | " leaf l2 {\n" |
| 563 | " must /cont/l;\n" |
| 564 | " type leafref {\n" |
| 565 | " path ../../../l;\n" |
| 566 | " }\n" |
| 567 | " }\n" |
| 568 | " }\n" |
| 569 | " }\n" |
| 570 | " }\n" |
| 571 | " leaf l {\n" |
| 572 | " config false;\n" |
| 573 | " type empty;\n" |
| 574 | " }\n" |
| 575 | " }\n" |
| 576 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 577 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 578 | CHECK_LOG_CTX(NULL, NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 579 | |
| 580 | /* action output -> action input leafref */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 581 | str = "module k {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 582 | " yang-version 1.1;\n" |
| 583 | " namespace urn:a;\n" |
| 584 | " prefix a;\n" |
| 585 | " container cont {\n" |
| 586 | " list ll {\n" |
| 587 | " key k;\n" |
| 588 | " leaf k {\n" |
| 589 | " type string;\n" |
| 590 | " }\n" |
| 591 | " action act {\n" |
| 592 | " input {\n" |
| 593 | " leaf l {\n" |
| 594 | " type empty;\n" |
| 595 | " }\n" |
| 596 | " }\n" |
| 597 | " output {\n" |
| 598 | " leaf l2 {\n" |
| 599 | " type leafref {\n" |
| 600 | " path ../l;\n" |
| 601 | " }\n" |
| 602 | " }\n" |
| 603 | " }\n" |
| 604 | " }\n" |
| 605 | " }\n" |
| 606 | " }\n" |
| 607 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 608 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID); |
| 609 | CHECK_LOG_CTX("Not found node \"l\" in path.", "/k:cont/ll/act/l2"); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 610 | |
| 611 | /* action output -> action input must */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 612 | str = "module k {\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 613 | " yang-version 1.1;\n" |
| 614 | " namespace urn:a;\n" |
| 615 | " prefix a;\n" |
| 616 | " container cont {\n" |
| 617 | " list ll {\n" |
| 618 | " key k;\n" |
| 619 | " leaf k {\n" |
| 620 | " type string;\n" |
| 621 | " }\n" |
| 622 | " action act {\n" |
| 623 | " input {\n" |
| 624 | " leaf l {\n" |
| 625 | " type empty;\n" |
| 626 | " }\n" |
| 627 | " }\n" |
| 628 | " output {\n" |
| 629 | " leaf l2 {\n" |
| 630 | " must /cont/ll/act/l;\n" |
| 631 | " type empty;\n" |
| 632 | " }\n" |
| 633 | " }\n" |
| 634 | " }\n" |
| 635 | " }\n" |
| 636 | " }\n" |
| 637 | "}"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 638 | assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS); |
| 639 | CHECK_LOG_CTX("Schema node \"l\" not found (\"/cont/ll/act/l\") with context node \"/k:cont/ll/act/l2\".", NULL); |
Michal Vasko | 6b26e74 | 2020-07-17 15:02:10 +0200 | [diff] [blame] | 640 | } |