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