Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 1 | /* |
| 2 | * @file test_parser_yang.c |
| 3 | * @author: Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief unit tests for functions from parser_yang.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 | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 15 | #include <stdarg.h> |
| 16 | #include <stddef.h> |
| 17 | #include <setjmp.h> |
| 18 | #include <cmocka.h> |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <string.h> |
| 22 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 23 | #include "../../src/common.h" |
| 24 | #include "../../src/tree_schema_internal.h" |
| 25 | #include "../../src/xpath.h" |
| 26 | |
| 27 | void lysc_feature_free(struct ly_ctx *ctx, struct lysc_feature *feat); |
| 28 | |
| 29 | LY_ERR lys_path_token(const char **path, const char **prefix, size_t *prefix_len, const char **name, size_t *name_len, |
| 30 | int *parent_times, int *has_predicate); |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 31 | |
| 32 | #define BUFSIZE 1024 |
| 33 | char logbuf[BUFSIZE] = {0}; |
| 34 | |
| 35 | /* set to 0 to printing error messages to stderr instead of checking them in code */ |
| 36 | #define ENABLE_LOGGER_CHECKING 1 |
| 37 | |
| 38 | #if ENABLE_LOGGER_CHECKING |
| 39 | static void |
| 40 | logger(LY_LOG_LEVEL level, const char *msg, const char *path) |
| 41 | { |
| 42 | (void) level; /* unused */ |
| 43 | |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 44 | if (path && path[0]) { |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 45 | snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path); |
| 46 | } else { |
| 47 | strncpy(logbuf, msg, BUFSIZE - 1); |
| 48 | } |
| 49 | } |
| 50 | #endif |
| 51 | |
| 52 | static int |
| 53 | logger_setup(void **state) |
| 54 | { |
| 55 | (void) state; /* unused */ |
| 56 | #if ENABLE_LOGGER_CHECKING |
| 57 | ly_set_log_clb(logger, 1); |
| 58 | #endif |
| 59 | return 0; |
| 60 | } |
| 61 | |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 62 | static int |
| 63 | logger_teardown(void **state) |
| 64 | { |
| 65 | (void) state; /* unused */ |
| 66 | #if ENABLE_LOGGER_CHECKING |
| 67 | if (*state) { |
| 68 | fprintf(stderr, "%s\n", logbuf); |
| 69 | } |
| 70 | #endif |
| 71 | return 0; |
| 72 | } |
| 73 | |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 74 | void |
| 75 | logbuf_clean(void) |
| 76 | { |
| 77 | logbuf[0] = '\0'; |
| 78 | } |
| 79 | |
| 80 | #if ENABLE_LOGGER_CHECKING |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 81 | # define logbuf_assert(str) assert_string_equal(logbuf, str);logbuf_clean() |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 82 | #else |
| 83 | # define logbuf_assert(str) |
| 84 | #endif |
| 85 | |
Radek Krejci | d05cbd9 | 2018-12-05 14:26:40 +0100 | [diff] [blame] | 86 | static LY_ERR test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name), |
| 87 | const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format, |
| 88 | const char **module_data, void (**free_module_data)(void *model_data, void *user_data)) |
| 89 | { |
| 90 | *module_data = user_data; |
| 91 | *format = LYS_IN_YANG; |
| 92 | *free_module_data = NULL; |
| 93 | return LY_SUCCESS; |
| 94 | } |
| 95 | |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 96 | static void |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 97 | reset_mod(struct ly_ctx *ctx, struct lys_module *module) |
| 98 | { |
| 99 | lysc_module_free(module->compiled, NULL); |
| 100 | lysp_module_free(module->parsed); |
| 101 | |
| 102 | FREE_STRING(module->ctx, module->name); |
| 103 | FREE_STRING(module->ctx, module->ns); |
| 104 | FREE_STRING(module->ctx, module->prefix); |
| 105 | FREE_STRING(module->ctx, module->filepath); |
| 106 | FREE_STRING(module->ctx, module->org); |
| 107 | FREE_STRING(module->ctx, module->contact); |
| 108 | FREE_STRING(module->ctx, module->dsc); |
| 109 | FREE_STRING(module->ctx, module->ref); |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 110 | FREE_ARRAY(module->ctx, module->off_features, lysc_feature_free); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 111 | |
| 112 | memset(module, 0, sizeof *module); |
| 113 | module->ctx = ctx; |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 114 | module->implemented = 1; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | static void |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 118 | test_module(void **state) |
| 119 | { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 120 | *state = test_module; |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 121 | |
| 122 | const char *str; |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 123 | struct lys_parser_ctx ctx = {0}; |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 124 | struct lys_module mod = {0}; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 125 | struct lysc_feature *f; |
| 126 | struct lysc_iffeature *iff; |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 127 | |
| 128 | str = "module test {namespace urn:test; prefix t;" |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 129 | "feature f1;feature f2 {if-feature f1;}}"; |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 130 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 131 | reset_mod(ctx.ctx, &mod); |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 132 | |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 133 | assert_int_equal(LY_EINVAL, lys_compile(NULL, 0)); |
| 134 | logbuf_assert("Invalid argument mod (lys_compile())."); |
| 135 | assert_int_equal(LY_EINVAL, lys_compile(&mod, 0)); |
| 136 | logbuf_assert("Invalid argument mod->parsed (lys_compile())."); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 137 | assert_int_equal(LY_SUCCESS, yang_parse_module(&ctx, str, &mod)); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 138 | mod.implemented = 0; |
| 139 | assert_int_equal(LY_SUCCESS, lys_compile(&mod, 0)); |
| 140 | assert_null(mod.compiled); |
| 141 | mod.implemented = 1; |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 142 | assert_int_equal(LY_SUCCESS, lys_compile(&mod, 0)); |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 143 | assert_non_null(mod.compiled); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 144 | assert_string_equal("test", mod.name); |
| 145 | assert_string_equal("urn:test", mod.ns); |
| 146 | assert_string_equal("t", mod.prefix); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 147 | /* features */ |
| 148 | assert_non_null(mod.compiled->features); |
| 149 | assert_int_equal(2, LY_ARRAY_SIZE(mod.compiled->features)); |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 150 | f = &mod.compiled->features[1]; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 151 | assert_non_null(f->iffeatures); |
| 152 | assert_int_equal(1, LY_ARRAY_SIZE(f->iffeatures)); |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 153 | iff = &f->iffeatures[0]; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 154 | assert_non_null(iff->expr); |
| 155 | assert_non_null(iff->features); |
| 156 | assert_int_equal(1, LY_ARRAY_SIZE(iff->features)); |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 157 | assert_ptr_equal(&mod.compiled->features[0], iff->features[0]); |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 158 | |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 159 | lysc_module_free(mod.compiled, NULL); |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 160 | |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 161 | assert_int_equal(LY_SUCCESS, lys_compile(&mod, LYSC_OPT_FREE_SP)); |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 162 | assert_non_null(mod.compiled); |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 163 | |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 164 | lysc_module_free(mod.compiled, NULL); |
| 165 | mod.compiled = NULL; |
| 166 | |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 167 | /* submodules cannot be compiled directly */ |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 168 | str = "submodule test {belongs-to xxx {prefix x;}}"; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 169 | assert_int_equal(LY_EINVAL, yang_parse_module(&ctx, str, &mod)); |
| 170 | logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module."); |
| 171 | assert_null(mod.parsed); |
| 172 | reset_mod(ctx.ctx, &mod); |
Radek Krejci | 76b3e96 | 2018-12-14 17:01:25 +0100 | [diff] [blame] | 173 | |
| 174 | /* data definition name collision in top level */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 175 | assert_int_equal(LY_SUCCESS, yang_parse_module(&ctx, "module aa {namespace urn:aa;prefix aa;" |
| 176 | "leaf a {type string;} container a{presence x;}}", &mod)); |
Radek Krejci | 76b3e96 | 2018-12-14 17:01:25 +0100 | [diff] [blame] | 177 | assert_int_equal(LY_EVALID, lys_compile(&mod, 0)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 178 | logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/Notification statement. /aa:a"); |
Radek Krejci | 76b3e96 | 2018-12-14 17:01:25 +0100 | [diff] [blame] | 179 | assert_null(mod.compiled); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 180 | reset_mod(ctx.ctx, &mod); |
Radek Krejci | 76b3e96 | 2018-12-14 17:01:25 +0100 | [diff] [blame] | 181 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 182 | *state = NULL; |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 183 | ly_ctx_destroy(ctx.ctx, NULL); |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 184 | } |
| 185 | |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 186 | static void |
| 187 | test_feature(void **state) |
| 188 | { |
Radek Krejci | d05cbd9 | 2018-12-05 14:26:40 +0100 | [diff] [blame] | 189 | *state = test_feature; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 190 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 191 | struct lys_parser_ctx ctx = {0}; |
Radek Krejci | 1aefdf7 | 2018-11-01 11:01:39 +0100 | [diff] [blame] | 192 | struct lys_module mod = {0}, *modp; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 193 | const char *str; |
| 194 | struct lysc_feature *f, *f1; |
| 195 | |
| 196 | str = "module a {namespace urn:a;prefix a;yang-version 1.1;\n" |
| 197 | "feature f1 {description test1;reference test2;status current;} feature f2; feature f3;\n" |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 198 | "feature orfeature {if-feature \"f1 or f2\";}\n" |
| 199 | "feature andfeature {if-feature \"f1 and f2\";}\n" |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 200 | "feature f6 {if-feature \"not f1\";}\n" |
Radek Krejci | dde18c5 | 2018-10-24 14:43:04 +0200 | [diff] [blame] | 201 | "feature f7 {if-feature \"(f2 and f3) or (not f1)\";}\n" |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 202 | "feature f8 {if-feature \"f1 or f2 or f3 or orfeature or andfeature\";}\n" |
| 203 | "feature f9 {if-feature \"not not f1\";}}"; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 204 | |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 205 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 206 | reset_mod(ctx.ctx, &mod); |
| 207 | |
| 208 | assert_int_equal(LY_SUCCESS, yang_parse_module(&ctx, str, &mod)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 209 | assert_int_equal(LY_SUCCESS, lys_compile(&mod, 0)); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 210 | assert_non_null(mod.compiled); |
| 211 | assert_non_null(mod.compiled->features); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 212 | assert_int_equal(9, LY_ARRAY_SIZE(mod.compiled->features)); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 213 | /* all features are disabled by default */ |
| 214 | LY_ARRAY_FOR(mod.compiled->features, struct lysc_feature, f) { |
| 215 | assert_int_equal(0, lysc_feature_value(f)); |
| 216 | } |
| 217 | /* enable f1 */ |
| 218 | assert_int_equal(LY_SUCCESS, lys_feature_enable(&mod, "f1")); |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 219 | f1 = &mod.compiled->features[0]; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 220 | assert_int_equal(1, lysc_feature_value(f1)); |
| 221 | |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 222 | /* enable orfeature */ |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 223 | f = &mod.compiled->features[3]; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 224 | assert_int_equal(0, lysc_feature_value(f)); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 225 | assert_int_equal(LY_SUCCESS, lys_feature_enable(&mod, "orfeature")); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 226 | assert_int_equal(1, lysc_feature_value(f)); |
| 227 | |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 228 | /* enable andfeature - no possible since f2 is disabled */ |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 229 | f = &mod.compiled->features[4]; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 230 | assert_int_equal(0, lysc_feature_value(f)); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 231 | assert_int_equal(LY_EDENIED, lys_feature_enable(&mod, "andfeature")); |
| 232 | logbuf_assert("Feature \"andfeature\" cannot be enabled since it is disabled by its if-feature condition(s)."); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 233 | assert_int_equal(0, lysc_feature_value(f)); |
| 234 | |
| 235 | /* first enable f2, so f5 can be enabled then */ |
| 236 | assert_int_equal(LY_SUCCESS, lys_feature_enable(&mod, "f2")); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 237 | assert_int_equal(LY_SUCCESS, lys_feature_enable(&mod, "andfeature")); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 238 | assert_int_equal(1, lysc_feature_value(f)); |
| 239 | |
| 240 | /* f1 is enabled, so f6 cannot be enabled */ |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 241 | f = &mod.compiled->features[5]; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 242 | assert_int_equal(0, lysc_feature_value(f)); |
| 243 | assert_int_equal(LY_EDENIED, lys_feature_enable(&mod, "f6")); |
| 244 | logbuf_assert("Feature \"f6\" cannot be enabled since it is disabled by its if-feature condition(s)."); |
| 245 | assert_int_equal(0, lysc_feature_value(f)); |
| 246 | |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 247 | /* so disable f1 - andfeature will became also disabled */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 248 | assert_int_equal(1, lysc_feature_value(f1)); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 249 | assert_int_equal(LY_SUCCESS, lys_feature_disable(&mod, "f1")); |
| 250 | assert_int_equal(0, lysc_feature_value(f1)); |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 251 | assert_int_equal(0, lysc_feature_value(&mod.compiled->features[4])); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 252 | /* while orfeature is stille enabled */ |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 253 | assert_int_equal(1, lysc_feature_value(&mod.compiled->features[3])); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 254 | /* and finally f6 can be enabled */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 255 | assert_int_equal(LY_SUCCESS, lys_feature_enable(&mod, "f6")); |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 256 | assert_int_equal(1, lysc_feature_value(&mod.compiled->features[5])); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 257 | |
| 258 | /* complex evaluation of f7: f1 and f3 are disabled, while f2 is enabled */ |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 259 | assert_int_equal(1, lysc_iffeature_value(&mod.compiled->features[6].iffeatures[0])); |
Radek Krejci | dde18c5 | 2018-10-24 14:43:04 +0200 | [diff] [blame] | 260 | /* long evaluation of f8 to need to reallocate internal stack for operators */ |
| 261 | assert_int_equal(1, lysc_iffeature_value(&mod.compiled->features[7].iffeatures[0])); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 262 | |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 263 | /* double negation of disabled f1 -> disabled */ |
| 264 | assert_int_equal(0, lysc_iffeature_value(&mod.compiled->features[8].iffeatures[0])); |
| 265 | |
Radek Krejci | 3892028 | 2018-11-01 09:24:16 +0100 | [diff] [blame] | 266 | /* disable all features */ |
| 267 | assert_int_equal(LY_SUCCESS, lys_feature_disable(&mod, "*")); |
| 268 | LY_ARRAY_FOR(mod.compiled->features, struct lysc_feature, f) { |
| 269 | assert_int_equal(0, lys_feature_value(&mod, f->name)); |
| 270 | } |
| 271 | /* re-setting already set feature */ |
| 272 | assert_int_equal(LY_SUCCESS, lys_feature_disable(&mod, "f1")); |
| 273 | assert_int_equal(0, lys_feature_value(&mod, "f1")); |
| 274 | |
| 275 | /* enabling feature that cannot be enabled due to its if-features */ |
Radek Krejci | 1aefdf7 | 2018-11-01 11:01:39 +0100 | [diff] [blame] | 276 | assert_int_equal(LY_SUCCESS, lys_feature_enable(&mod, "f1")); |
| 277 | assert_int_equal(LY_EDENIED, lys_feature_enable(&mod, "andfeature")); |
| 278 | logbuf_assert("Feature \"andfeature\" cannot be enabled since it is disabled by its if-feature condition(s)."); |
Radek Krejci | ca3db00 | 2018-11-01 10:31:01 +0100 | [diff] [blame] | 279 | assert_int_equal(LY_EDENIED, lys_feature_enable(&mod, "*")); |
| 280 | logbuf_assert("Feature \"f6\" cannot be enabled since it is disabled by its if-feature condition(s)."); |
Radek Krejci | 1aefdf7 | 2018-11-01 11:01:39 +0100 | [diff] [blame] | 281 | /* test if not changed */ |
| 282 | assert_int_equal(1, lys_feature_value(&mod, "f1")); |
| 283 | assert_int_equal(0, lys_feature_value(&mod, "f2")); |
Radek Krejci | 3892028 | 2018-11-01 09:24:16 +0100 | [diff] [blame] | 284 | |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 285 | assert_non_null(modp = lys_parse_mem(ctx.ctx, "module b {namespace urn:b;prefix b;" |
| 286 | "feature f1 {if-feature f2;}feature f2;}", LYS_IN_YANG)); |
| 287 | assert_non_null(modp->compiled); |
| 288 | assert_non_null(modp->compiled->features); |
| 289 | assert_int_equal(2, LY_ARRAY_SIZE(modp->compiled->features)); |
| 290 | assert_non_null(modp->compiled->features[0].iffeatures); |
| 291 | assert_int_equal(1, LY_ARRAY_SIZE(modp->compiled->features[0].iffeatures)); |
| 292 | assert_non_null(modp->compiled->features[0].iffeatures[0].features); |
| 293 | assert_int_equal(1, LY_ARRAY_SIZE(modp->compiled->features[0].iffeatures[0].features)); |
| 294 | assert_ptr_equal(&modp->compiled->features[1], modp->compiled->features[0].iffeatures[0].features[0]); |
| 295 | assert_non_null(modp->compiled->features); |
| 296 | assert_int_equal(2, LY_ARRAY_SIZE(modp->compiled->features)); |
| 297 | assert_non_null(modp->compiled->features[1].depfeatures); |
| 298 | assert_int_equal(1, LY_ARRAY_SIZE(modp->compiled->features[1].depfeatures)); |
| 299 | assert_ptr_equal(&modp->compiled->features[0], modp->compiled->features[1].depfeatures[0]); |
| 300 | |
Radek Krejci | 1aefdf7 | 2018-11-01 11:01:39 +0100 | [diff] [blame] | 301 | /* invalid reference */ |
Radek Krejci | 3892028 | 2018-11-01 09:24:16 +0100 | [diff] [blame] | 302 | assert_int_equal(LY_EINVAL, lys_feature_enable(&mod, "xxx")); |
| 303 | logbuf_assert("Feature \"xxx\" not found in module \"a\"."); |
| 304 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 305 | reset_mod(ctx.ctx, &mod); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 306 | |
| 307 | /* some invalid expressions */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 308 | assert_int_equal(LY_SUCCESS, yang_parse_module(&ctx, "module b{yang-version 1.1;namespace urn:b; prefix b; feature f{if-feature f1;}}", &mod)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 309 | assert_int_equal(LY_EVALID, lys_compile(&mod, 0)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 310 | logbuf_assert("Invalid value \"f1\" of if-feature - unable to find feature \"f1\". /b:{feature='f'}"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 311 | reset_mod(ctx.ctx, &mod); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 312 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 313 | assert_int_equal(LY_SUCCESS, yang_parse_module(&ctx, "module b{yang-version 1.1;namespace urn:b; prefix b; feature f1; feature f2{if-feature 'f and';}}", &mod)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 314 | assert_int_equal(LY_EVALID, lys_compile(&mod, 0)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 315 | logbuf_assert("Invalid value \"f and\" of if-feature - unexpected end of expression. /b:{feature='f2'}"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 316 | reset_mod(ctx.ctx, &mod); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 317 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 318 | assert_int_equal(LY_SUCCESS, yang_parse_module(&ctx, "module b{yang-version 1.1;namespace urn:b; prefix b; feature f{if-feature 'or';}}", &mod)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 319 | assert_int_equal(LY_EVALID, lys_compile(&mod, 0)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 320 | logbuf_assert("Invalid value \"or\" of if-feature - unexpected end of expression. /b:{feature='f'}"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 321 | reset_mod(ctx.ctx, &mod); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 322 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 323 | assert_int_equal(LY_SUCCESS, yang_parse_module(&ctx, "module b{yang-version 1.1;namespace urn:b; prefix b; feature f1; feature f2{if-feature '(f1';}}", &mod)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 324 | assert_int_equal(LY_EVALID, lys_compile(&mod, 0)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 325 | logbuf_assert("Invalid value \"(f1\" of if-feature - non-matching opening and closing parentheses. /b:{feature='f2'}"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 326 | reset_mod(ctx.ctx, &mod); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 327 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 328 | assert_int_equal(LY_SUCCESS, yang_parse_module(&ctx, "module b{yang-version 1.1;namespace urn:b; prefix b; feature f1; feature f2{if-feature 'f1)';}}", &mod)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 329 | assert_int_equal(LY_EVALID, lys_compile(&mod, 0)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 330 | logbuf_assert("Invalid value \"f1)\" of if-feature - non-matching opening and closing parentheses. /b:{feature='f2'}"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 331 | reset_mod(ctx.ctx, &mod); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 332 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 333 | assert_int_equal(LY_SUCCESS, yang_parse_module(&ctx, "module b{yang-version 1.1;namespace urn:b; prefix b; feature f1; feature f2{if-feature ---;}}", &mod)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 334 | assert_int_equal(LY_EVALID, lys_compile(&mod, 0)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 335 | logbuf_assert("Invalid value \"---\" of if-feature - unable to find feature \"---\". /b:{feature='f2'}"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 336 | reset_mod(ctx.ctx, &mod); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 337 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 338 | assert_int_equal(LY_SUCCESS, yang_parse_module(&ctx, "module b{namespace urn:b; prefix b; feature f1; feature f2{if-feature 'not f1';}}", &mod)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 339 | assert_int_equal(LY_EVALID, lys_compile(&mod, 0)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 340 | logbuf_assert("Invalid value \"not f1\" of if-feature - YANG 1.1 expression in YANG 1.0 module. /b:{feature='f2'}"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 341 | reset_mod(ctx.ctx, &mod); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 342 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 343 | assert_int_equal(LY_SUCCESS, yang_parse_module(&ctx, "module b{namespace urn:b; prefix b; feature f1; feature f1;}", &mod)); |
Radek Krejci | d05cbd9 | 2018-12-05 14:26:40 +0100 | [diff] [blame] | 344 | assert_int_equal(LY_EVALID, lys_compile(&mod, 0)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 345 | logbuf_assert("Duplicate identifier \"f1\" of feature statement. /b:{feature='f1'}"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 346 | reset_mod(ctx.ctx, &mod); |
Radek Krejci | d05cbd9 | 2018-12-05 14:26:40 +0100 | [diff] [blame] | 347 | |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 348 | ly_ctx_set_module_imp_clb(ctx.ctx, test_imp_clb, "submodule sz {belongs-to z {prefix z;} feature f1;}"); |
| 349 | assert_null(lys_parse_mem(ctx.ctx, "module z{namespace urn:z; prefix z; include sz;feature f1;}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 350 | logbuf_assert("Duplicate identifier \"f1\" of feature statement. /z:{feature='f1'}"); |
Radek Krejci | d05cbd9 | 2018-12-05 14:26:40 +0100 | [diff] [blame] | 351 | |
Radek Krejci | 09a1fc5 | 2019-02-13 10:55:17 +0100 | [diff] [blame] | 352 | assert_null(lys_parse_mem(ctx.ctx, "module aa{namespace urn:aa; prefix aa; feature f1 {if-feature f2;} feature f2 {if-feature f1;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 353 | logbuf_assert("Feature \"f1\" is indirectly referenced from itself. /aa:{feature='f2'}"); |
Radek Krejci | 09a1fc5 | 2019-02-13 10:55:17 +0100 | [diff] [blame] | 354 | assert_null(lys_parse_mem(ctx.ctx, "module ab{namespace urn:ab; prefix ab; feature f1 {if-feature f1;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 355 | logbuf_assert("Feature \"f1\" is referenced from itself. /ab:{feature='f1'}"); |
Radek Krejci | 09a1fc5 | 2019-02-13 10:55:17 +0100 | [diff] [blame] | 356 | |
Radek Krejci | 6788abc | 2019-06-14 13:56:49 +0200 | [diff] [blame] | 357 | assert_null(lys_parse_mem(ctx.ctx, "module bb{yang-version 1.1; namespace urn:bb; prefix bb; feature f {if-feature ();}}", LYS_IN_YANG)); |
| 358 | logbuf_assert("Invalid value \"()\" of if-feature - number of features in expression does not match the required number " |
| 359 | "of operands for the operations. /bb:{feature='f'}"); |
| 360 | assert_null(lys_parse_mem(ctx.ctx, "module bb{yang-version 1.1; namespace urn:bb; prefix bb; feature f1; feature f {if-feature 'f1(';}}", LYS_IN_YANG)); |
| 361 | logbuf_assert("Invalid value \"f1(\" of if-feature - non-matching opening and closing parentheses. /bb:{feature='f'}"); |
| 362 | assert_null(lys_parse_mem(ctx.ctx, "module bb{yang-version 1.1; namespace urn:bb; prefix bb; feature f1; feature f {if-feature 'and f1';}}", LYS_IN_YANG)); |
| 363 | logbuf_assert("Invalid value \"and f1\" of if-feature - missing feature/expression before \"and\" operation. /bb:{feature='f'}"); |
| 364 | assert_null(lys_parse_mem(ctx.ctx, "module bb{yang-version 1.1; namespace urn:bb; prefix bb; feature f1; feature f {if-feature 'f1 not ';}}", LYS_IN_YANG)); |
| 365 | logbuf_assert("Invalid value \"f1 not \" of if-feature - unexpected end of expression. /bb:{feature='f'}"); |
| 366 | assert_null(lys_parse_mem(ctx.ctx, "module bb{yang-version 1.1; namespace urn:bb; prefix bb; feature f1; feature f {if-feature 'f1 not not ';}}", LYS_IN_YANG)); |
| 367 | logbuf_assert("Invalid value \"f1 not not \" of if-feature - unexpected end of expression. /bb:{feature='f'}"); |
| 368 | assert_null(lys_parse_mem(ctx.ctx, "module bb{yang-version 1.1; namespace urn:bb; prefix bb; feature f1; feature f2; " |
| 369 | "feature f {if-feature 'or f1 f2';}}", LYS_IN_YANG)); |
| 370 | logbuf_assert("Invalid value \"or f1 f2\" of if-feature - missing feature/expression before \"or\" operation. /bb:{feature='f'}"); |
| 371 | |
Radek Krejci | 1aefdf7 | 2018-11-01 11:01:39 +0100 | [diff] [blame] | 372 | /* import reference */ |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 373 | assert_non_null(modp = lys_parse_mem(ctx.ctx, str, LYS_IN_YANG)); |
Radek Krejci | 1aefdf7 | 2018-11-01 11:01:39 +0100 | [diff] [blame] | 374 | assert_int_equal(LY_SUCCESS, lys_feature_enable(modp, "f1")); |
Radek Krejci | d05cbd9 | 2018-12-05 14:26:40 +0100 | [diff] [blame] | 375 | assert_non_null(modp = lys_parse_mem(ctx.ctx, "module c{namespace urn:c; prefix c; import a {prefix a;} feature f1; feature f2{if-feature 'a:f1';}}", LYS_IN_YANG)); |
Radek Krejci | 1aefdf7 | 2018-11-01 11:01:39 +0100 | [diff] [blame] | 376 | assert_int_equal(LY_SUCCESS, lys_feature_enable(modp, "f2")); |
| 377 | assert_int_equal(0, lys_feature_value(modp, "f1")); |
| 378 | assert_int_equal(1, lys_feature_value(modp, "f2")); |
| 379 | |
Radek Krejci | d05cbd9 | 2018-12-05 14:26:40 +0100 | [diff] [blame] | 380 | *state = NULL; |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 381 | ly_ctx_destroy(ctx.ctx, NULL); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 382 | } |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 383 | |
Radek Krejci | 478020e | 2018-10-30 16:02:14 +0100 | [diff] [blame] | 384 | static void |
| 385 | test_identity(void **state) |
| 386 | { |
Radek Krejci | 7f2a536 | 2018-11-28 13:05:37 +0100 | [diff] [blame] | 387 | *state = test_identity; |
Radek Krejci | 478020e | 2018-10-30 16:02:14 +0100 | [diff] [blame] | 388 | |
| 389 | struct ly_ctx *ctx; |
Radek Krejci | 1aefdf7 | 2018-11-01 11:01:39 +0100 | [diff] [blame] | 390 | struct lys_module *mod1, *mod2; |
Radek Krejci | 478020e | 2018-10-30 16:02:14 +0100 | [diff] [blame] | 391 | |
| 392 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
Radek Krejci | 4d483a8 | 2019-01-17 13:12:50 +0100 | [diff] [blame] | 393 | assert_non_null(mod1 = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a; identity a1;}", LYS_IN_YANG)); |
| 394 | assert_non_null(mod2 = lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b; import a {prefix a;}" |
| 395 | "identity b1; identity b2; identity b3 {base b1; base b:b2; base a:a1;}" |
| 396 | "identity b4 {base b:b1; base b3;}}", LYS_IN_YANG)); |
Radek Krejci | 478020e | 2018-10-30 16:02:14 +0100 | [diff] [blame] | 397 | |
| 398 | assert_non_null(mod1->compiled); |
| 399 | assert_non_null(mod1->compiled->identities); |
| 400 | assert_non_null(mod2->compiled); |
| 401 | assert_non_null(mod2->compiled->identities); |
| 402 | |
| 403 | assert_non_null(mod1->compiled->identities[0].derived); |
| 404 | assert_int_equal(1, LY_ARRAY_SIZE(mod1->compiled->identities[0].derived)); |
| 405 | assert_ptr_equal(mod1->compiled->identities[0].derived[0], &mod2->compiled->identities[2]); |
| 406 | assert_non_null(mod2->compiled->identities[0].derived); |
| 407 | assert_int_equal(2, LY_ARRAY_SIZE(mod2->compiled->identities[0].derived)); |
| 408 | assert_ptr_equal(mod2->compiled->identities[0].derived[0], &mod2->compiled->identities[2]); |
| 409 | assert_ptr_equal(mod2->compiled->identities[0].derived[1], &mod2->compiled->identities[3]); |
| 410 | assert_non_null(mod2->compiled->identities[1].derived); |
| 411 | assert_int_equal(1, LY_ARRAY_SIZE(mod2->compiled->identities[1].derived)); |
| 412 | assert_ptr_equal(mod2->compiled->identities[1].derived[0], &mod2->compiled->identities[2]); |
| 413 | assert_non_null(mod2->compiled->identities[2].derived); |
| 414 | assert_int_equal(1, LY_ARRAY_SIZE(mod2->compiled->identities[2].derived)); |
| 415 | assert_ptr_equal(mod2->compiled->identities[2].derived[0], &mod2->compiled->identities[3]); |
| 416 | |
Radek Krejci | 4d483a8 | 2019-01-17 13:12:50 +0100 | [diff] [blame] | 417 | assert_non_null(mod2 = lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c;" |
| 418 | "identity c2 {base c1;} identity c1;}", LYS_IN_YANG)); |
| 419 | assert_int_equal(1, LY_ARRAY_SIZE(mod2->compiled->identities[1].derived)); |
| 420 | assert_ptr_equal(mod2->compiled->identities[1].derived[0], &mod2->compiled->identities[0]); |
| 421 | |
| 422 | assert_null(lys_parse_mem(ctx, "module aa{namespace urn:aa; prefix aa; identity i1;identity i1;}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 423 | logbuf_assert("Duplicate identifier \"i1\" of identity statement. /aa:{identity='i1'}"); |
Radek Krejci | d05cbd9 | 2018-12-05 14:26:40 +0100 | [diff] [blame] | 424 | |
Radek Krejci | 4d483a8 | 2019-01-17 13:12:50 +0100 | [diff] [blame] | 425 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule sbb {belongs-to bb {prefix bb;} identity i1;}"); |
| 426 | assert_null(lys_parse_mem(ctx, "module bb{namespace urn:bb; prefix bb; include sbb;identity i1;}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 427 | logbuf_assert("Duplicate identifier \"i1\" of identity statement. /bb:{identity='i1'}"); |
Radek Krejci | d05cbd9 | 2018-12-05 14:26:40 +0100 | [diff] [blame] | 428 | |
Radek Krejci | 3822263 | 2019-02-12 16:55:05 +0100 | [diff] [blame] | 429 | assert_null(lys_parse_mem(ctx, "module cc{namespace urn:cc; prefix cc; identity i1 {base i2;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 430 | logbuf_assert("Unable to find base (i2) of identity \"i1\". /cc:{identity='i1'}"); |
Radek Krejci | 3822263 | 2019-02-12 16:55:05 +0100 | [diff] [blame] | 431 | |
| 432 | assert_null(lys_parse_mem(ctx, "module dd{namespace urn:dd; prefix dd; identity i1 {base i1;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 433 | logbuf_assert("Identity \"i1\" is derived from itself. /dd:{identity='i1'}"); |
Radek Krejci | 3822263 | 2019-02-12 16:55:05 +0100 | [diff] [blame] | 434 | assert_null(lys_parse_mem(ctx, "module de{namespace urn:de; prefix de; identity i1 {base i2;}identity i2 {base i3;}identity i3 {base i1;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 435 | logbuf_assert("Identity \"i1\" is indirectly derived from itself. /de:{identity='i3'}"); |
Radek Krejci | 3822263 | 2019-02-12 16:55:05 +0100 | [diff] [blame] | 436 | |
Radek Krejci | 7f2a536 | 2018-11-28 13:05:37 +0100 | [diff] [blame] | 437 | *state = NULL; |
Radek Krejci | 478020e | 2018-10-30 16:02:14 +0100 | [diff] [blame] | 438 | ly_ctx_destroy(ctx, NULL); |
| 439 | } |
| 440 | |
Radek Krejci | bd8d9ba | 2018-11-02 16:06:26 +0100 | [diff] [blame] | 441 | static void |
| 442 | test_node_container(void **state) |
| 443 | { |
| 444 | (void) state; /* unused */ |
| 445 | |
| 446 | struct ly_ctx *ctx; |
| 447 | struct lys_module *mod; |
| 448 | struct lysc_node_container *cont; |
| 449 | |
| 450 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 451 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;container c;}", LYS_IN_YANG)); |
Radek Krejci | bd8d9ba | 2018-11-02 16:06:26 +0100 | [diff] [blame] | 452 | assert_non_null(mod->compiled); |
| 453 | assert_non_null((cont = (struct lysc_node_container*)mod->compiled->data)); |
| 454 | assert_int_equal(LYS_CONTAINER, cont->nodetype); |
| 455 | assert_string_equal("c", cont->name); |
| 456 | assert_true(cont->flags & LYS_CONFIG_W); |
| 457 | assert_true(cont->flags & LYS_STATUS_CURR); |
| 458 | |
Radek Krejci | 98094b3 | 2018-11-02 16:21:47 +0100 | [diff] [blame] | 459 | assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;container c {config false; status deprecated; container child;}}", LYS_IN_YANG)); |
Radek Krejci | 98094b3 | 2018-11-02 16:21:47 +0100 | [diff] [blame] | 460 | logbuf_assert("Missing explicit \"deprecated\" status that was already specified in parent, inheriting."); |
Radek Krejci | bd8d9ba | 2018-11-02 16:06:26 +0100 | [diff] [blame] | 461 | assert_non_null(mod->compiled); |
| 462 | assert_non_null((cont = (struct lysc_node_container*)mod->compiled->data)); |
| 463 | assert_true(cont->flags & LYS_CONFIG_R); |
Radek Krejci | 98094b3 | 2018-11-02 16:21:47 +0100 | [diff] [blame] | 464 | assert_true(cont->flags & LYS_STATUS_DEPRC); |
Radek Krejci | bd8d9ba | 2018-11-02 16:06:26 +0100 | [diff] [blame] | 465 | assert_non_null((cont = (struct lysc_node_container*)cont->child)); |
| 466 | assert_int_equal(LYS_CONTAINER, cont->nodetype); |
| 467 | assert_true(cont->flags & LYS_CONFIG_R); |
Radek Krejci | 98094b3 | 2018-11-02 16:21:47 +0100 | [diff] [blame] | 468 | assert_true(cont->flags & LYS_STATUS_DEPRC); |
Radek Krejci | bd8d9ba | 2018-11-02 16:06:26 +0100 | [diff] [blame] | 469 | assert_string_equal("child", cont->name); |
| 470 | |
| 471 | ly_ctx_destroy(ctx, NULL); |
| 472 | } |
| 473 | |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 474 | static void |
| 475 | test_node_leaflist(void **state) |
| 476 | { |
| 477 | *state = test_node_leaflist; |
| 478 | |
| 479 | struct ly_ctx *ctx; |
| 480 | struct lys_module *mod; |
| 481 | struct lysc_type *type; |
| 482 | struct lysc_node_leaflist *ll; |
| 483 | |
| 484 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 485 | |
| 486 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;" |
| 487 | "typedef mytype {type union {type leafref {path ../target;} type string;}}" |
| 488 | "leaf-list ll1 {type union {type decimal64 {fraction-digits 2;} type mytype;}}" |
| 489 | "leaf-list ll2 {type leafref {path ../target;}}" |
| 490 | "leaf target {type int8;}}", |
| 491 | LYS_IN_YANG)); |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 492 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 493 | assert_non_null(type); |
| 494 | assert_int_equal(1, type->refcount); |
| 495 | assert_int_equal(LY_TYPE_UNION, type->basetype); |
| 496 | assert_non_null(((struct lysc_type_union*)type)->types); |
| 497 | assert_int_equal(3, LY_ARRAY_SIZE(((struct lysc_type_union*)type)->types)); |
| 498 | assert_int_equal(LY_TYPE_DEC64, ((struct lysc_type_union*)type)->types[0]->basetype); |
| 499 | assert_int_equal(LY_TYPE_LEAFREF, ((struct lysc_type_union*)type)->types[1]->basetype); |
| 500 | assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union*)type)->types[2]->basetype); |
| 501 | assert_non_null(((struct lysc_type_leafref*)((struct lysc_type_union*)type)->types[1])->realtype); |
| 502 | assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref*)((struct lysc_type_union*)type)->types[1])->realtype->basetype); |
| 503 | type = ((struct lysc_node_leaf*)mod->compiled->data->next)->type; |
| 504 | assert_non_null(type); |
| 505 | assert_int_equal(1, type->refcount); |
| 506 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 507 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 508 | assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref*)type)->realtype->basetype); |
| 509 | |
Radek Krejci | 6bb080b | 2018-11-28 17:23:41 +0100 | [diff] [blame] | 510 | assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;leaf-list ll {type string;}}", LYS_IN_YANG)); |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 511 | assert_non_null(mod->compiled); |
| 512 | assert_non_null((ll = (struct lysc_node_leaflist*)mod->compiled->data)); |
| 513 | assert_int_equal(0, ll->min); |
| 514 | assert_int_equal((uint32_t)-1, ll->max); |
| 515 | |
Radek Krejci | 6bb080b | 2018-11-28 17:23:41 +0100 | [diff] [blame] | 516 | assert_non_null(mod = lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c;typedef mytype {type int8;default 10;}" |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 517 | "leaf-list ll1 {type mytype;default 1; default 1; config false;}" |
Radek Krejci | a6d5773 | 2018-11-29 13:40:37 +0100 | [diff] [blame] | 518 | "leaf-list ll2 {type mytype; ordered-by user;}}", LYS_IN_YANG)); |
Radek Krejci | 6bb080b | 2018-11-28 17:23:41 +0100 | [diff] [blame] | 519 | assert_non_null(mod->compiled); |
| 520 | assert_non_null((ll = (struct lysc_node_leaflist*)mod->compiled->data)); |
| 521 | assert_non_null(ll->dflts); |
| 522 | assert_int_equal(3, ll->type->refcount); |
| 523 | assert_int_equal(2, LY_ARRAY_SIZE(ll->dflts)); |
| 524 | assert_string_equal("1", ll->dflts[0]); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 525 | assert_string_equal("1", ll->dflts[1]); |
Radek Krejci | 93dcc39 | 2019-02-19 10:43:38 +0100 | [diff] [blame] | 526 | assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_DFLT | LYS_SET_CONFIG, ll->flags); |
Radek Krejci | 6bb080b | 2018-11-28 17:23:41 +0100 | [diff] [blame] | 527 | assert_non_null((ll = (struct lysc_node_leaflist*)mod->compiled->data->next)); |
| 528 | assert_non_null(ll->dflts); |
| 529 | assert_int_equal(3, ll->type->refcount); |
| 530 | assert_int_equal(1, LY_ARRAY_SIZE(ll->dflts)); |
| 531 | assert_string_equal("10", ll->dflts[0]); |
Radek Krejci | a6d5773 | 2018-11-29 13:40:37 +0100 | [diff] [blame] | 532 | assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_USER, ll->flags); |
| 533 | |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 534 | /* ordered-by is ignored for state data, RPC/action output parameters and notification content */ |
Radek Krejci | a6d5773 | 2018-11-29 13:40:37 +0100 | [diff] [blame] | 535 | assert_non_null(mod = lys_parse_mem(ctx, "module d {yang-version 1.1;namespace urn:d;prefix d;" |
| 536 | "leaf-list ll {config false; type string; ordered-by user;}}", LYS_IN_YANG)); |
Radek Krejci | a6d5773 | 2018-11-29 13:40:37 +0100 | [diff] [blame] | 537 | /* but warning is present: */ |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 538 | logbuf_assert("The ordered-by statement is ignored in lists representing state data (/d:ll)."); |
Radek Krejci | a6d5773 | 2018-11-29 13:40:37 +0100 | [diff] [blame] | 539 | assert_non_null(mod->compiled); |
| 540 | assert_non_null((ll = (struct lysc_node_leaflist*)mod->compiled->data)); |
Radek Krejci | 93dcc39 | 2019-02-19 10:43:38 +0100 | [diff] [blame] | 541 | assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_CONFIG, ll->flags); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 542 | logbuf_clean(); |
| 543 | |
| 544 | assert_non_null(mod = lys_parse_mem(ctx, "module e {yang-version 1.1;namespace urn:e;prefix e;" |
| 545 | "rpc oper {output {leaf-list ll {type string; ordered-by user;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 546 | logbuf_assert("The ordered-by statement is ignored in lists representing RPC/action output parameters (/e:oper/output/ll)."); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 547 | logbuf_clean(); |
| 548 | |
| 549 | assert_non_null(mod = lys_parse_mem(ctx, "module f {yang-version 1.1;namespace urn:f;prefix f;" |
| 550 | "notification event {leaf-list ll {type string; ordered-by user;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 551 | logbuf_assert("The ordered-by statement is ignored in lists representing notification content (/f:event/ll)."); |
Radek Krejci | 6bb080b | 2018-11-28 17:23:41 +0100 | [diff] [blame] | 552 | |
| 553 | /* invalid */ |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 554 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;leaf-list ll {type empty;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 555 | logbuf_assert("Leaf-list of type \"empty\" is allowed only in YANG 1.1 modules. /aa:ll"); |
Radek Krejci | 6bb080b | 2018-11-28 17:23:41 +0100 | [diff] [blame] | 556 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 557 | assert_null(lys_parse_mem(ctx, "module bb {yang-version 1.1;namespace urn:bb;prefix bb;leaf-list ll {type empty; default x;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 558 | logbuf_assert("Leaf-list of type \"empty\" must not have a default value (x). /bb:ll"); |
Radek Krejci | 6bb080b | 2018-11-28 17:23:41 +0100 | [diff] [blame] | 559 | |
| 560 | assert_non_null(mod = lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;" |
| 561 | "leaf-list ll {config false;type string; default one;default two;default one;}}", LYS_IN_YANG)); |
Radek Krejci | 6bb080b | 2018-11-28 17:23:41 +0100 | [diff] [blame] | 562 | assert_non_null(mod->compiled); |
| 563 | assert_non_null((ll = (struct lysc_node_leaflist*)mod->compiled->data)); |
| 564 | assert_non_null(ll->dflts); |
| 565 | assert_int_equal(3, LY_ARRAY_SIZE(ll->dflts)); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 566 | assert_null(lys_parse_mem(ctx, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;" |
| 567 | "leaf-list ll {type string; default one;default two;default one;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 568 | logbuf_assert("Configuration leaf-list has multiple defaults of the same value \"one\". /dd:ll"); |
Radek Krejci | 6bb080b | 2018-11-28 17:23:41 +0100 | [diff] [blame] | 569 | |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 570 | *state = NULL; |
| 571 | ly_ctx_destroy(ctx, NULL); |
| 572 | } |
| 573 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 574 | static void |
| 575 | test_node_list(void **state) |
| 576 | { |
| 577 | *state = test_node_list; |
| 578 | |
| 579 | struct ly_ctx *ctx; |
| 580 | struct lys_module *mod; |
| 581 | struct lysc_node_list *list; |
| 582 | |
| 583 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 584 | |
| 585 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;feature f;" |
| 586 | "list l1 {key \"x y\"; ordered-by user; leaf x {type string; when 1;}leaf y{type string;if-feature f;}}" |
| 587 | "list l2 {config false;leaf value {type string;}}}", LYS_IN_YANG)); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 588 | list = (struct lysc_node_list*)mod->compiled->data; |
| 589 | assert_non_null(list); |
| 590 | assert_non_null(list->keys); |
| 591 | assert_int_equal(2, LY_ARRAY_SIZE(list->keys)); |
| 592 | assert_string_equal("x", list->keys[0]->name); |
| 593 | assert_string_equal("y", list->keys[1]->name); |
| 594 | assert_non_null(list->child); |
| 595 | assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_USER, list->flags); |
| 596 | assert_true(list->child->flags & LYS_KEY); |
| 597 | assert_true(list->child->next->flags & LYS_KEY); |
| 598 | list = (struct lysc_node_list*)mod->compiled->data->next; |
| 599 | assert_non_null(list); |
| 600 | assert_null(list->keys); |
| 601 | assert_non_null(list->child); |
Radek Krejci | 93dcc39 | 2019-02-19 10:43:38 +0100 | [diff] [blame] | 602 | assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_CONFIG, list->flags); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 603 | assert_false(list->child->flags & LYS_KEY); |
| 604 | |
| 605 | assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;" |
| 606 | "list l {key a; unique \"a c/b:b\"; unique \"c/e d\";" |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 607 | "leaf a {type string; default x;} leaf d {type string;config false;}" |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 608 | "container c {leaf b {type string;}leaf e{type string;config false;}}}}", LYS_IN_YANG)); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 609 | list = (struct lysc_node_list*)mod->compiled->data; |
| 610 | assert_non_null(list); |
| 611 | assert_string_equal("l", list->name); |
| 612 | assert_non_null(list->keys); |
| 613 | assert_int_equal(1, LY_ARRAY_SIZE(list->keys)); |
| 614 | assert_string_equal("a", list->keys[0]->name); |
| 615 | assert_true(list->keys[0]->flags & LYS_KEY); |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 616 | assert_null(list->keys[0]->dflt); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 617 | assert_non_null(list->uniques); |
| 618 | assert_int_equal(2, LY_ARRAY_SIZE(list->uniques)); |
| 619 | assert_int_equal(2, LY_ARRAY_SIZE(list->uniques[0])); |
| 620 | assert_string_equal("a", list->uniques[0][0]->name); |
| 621 | assert_true(list->uniques[0][0]->flags & LYS_UNIQUE); |
| 622 | assert_string_equal("b", list->uniques[0][1]->name); |
| 623 | assert_true(list->uniques[0][1]->flags & LYS_UNIQUE); |
| 624 | assert_int_equal(2, LY_ARRAY_SIZE(list->uniques[1])); |
| 625 | assert_string_equal("e", list->uniques[1][0]->name); |
| 626 | assert_true(list->uniques[1][0]->flags & LYS_UNIQUE); |
| 627 | assert_string_equal("d", list->uniques[1][1]->name); |
| 628 | assert_true(list->uniques[1][1]->flags & LYS_UNIQUE); |
| 629 | |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 630 | assert_non_null(mod = lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c;" |
| 631 | "list l {key a;leaf a {type empty;}}}", LYS_IN_YANG)); |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 632 | list = (struct lysc_node_list*)mod->compiled->data; |
| 633 | assert_non_null(list); |
| 634 | assert_string_equal("l", list->name); |
| 635 | assert_non_null(list->keys); |
| 636 | assert_int_equal(1, LY_ARRAY_SIZE(list->keys)); |
| 637 | assert_string_equal("a", list->keys[0]->name); |
| 638 | assert_true(list->keys[0]->flags & LYS_KEY); |
| 639 | assert_int_equal(LY_TYPE_EMPTY, list->keys[0]->type->basetype); |
| 640 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 641 | /* invalid */ |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 642 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;list l;}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 643 | logbuf_assert("Missing key in list representing configuration data. /aa:l"); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 644 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 645 | assert_null(lys_parse_mem(ctx, "module bb {yang-version 1.1; namespace urn:bb;prefix bb;" |
| 646 | "list l {key x; leaf x {type string; when 1;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 647 | logbuf_assert("List's key must not have any \"when\" statement. /bb:l/x"); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 648 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 649 | assert_null(lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;feature f;" |
| 650 | "list l {key x; leaf x {type string; if-feature f;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 651 | logbuf_assert("List's key must not have any \"if-feature\" statement. /cc:l/x"); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 652 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 653 | assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;" |
| 654 | "list l {key x; leaf x {type string; config false;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 655 | logbuf_assert("Key of the configuration list must not be status leaf. /dd:l/x"); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 656 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 657 | assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;" |
| 658 | "list l {config false;key x; leaf x {type string; config true;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 659 | logbuf_assert("Configuration node cannot be child of any state data node. /ee:l/x"); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 660 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 661 | assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;" |
| 662 | "list l {key x; leaf-list x {type string;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 663 | logbuf_assert("The list's key \"x\" not found. /ff:l"); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 664 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 665 | assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;" |
| 666 | "list l {key x; unique y;leaf x {type string;} leaf-list y {type string;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 667 | logbuf_assert("Unique's descendant-schema-nodeid \"y\" refers to leaf-list node instead of a leaf. /gg:l"); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 668 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 669 | assert_null(lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;" |
| 670 | "list l {key x; unique \"x y\";leaf x {type string;} leaf y {config false; type string;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 671 | logbuf_assert("Unique statement \"x y\" refers to leafs with different config type. /hh:l"); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 672 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 673 | assert_null(lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;" |
| 674 | "list l {key x; unique a:x;leaf x {type string;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 675 | logbuf_assert("Invalid descendant-schema-nodeid value \"a:x\" - prefix \"a\" not defined in module \"ii\". /ii:l"); |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 676 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 677 | assert_null(lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;" |
| 678 | "list l {key x; unique c/x;leaf x {type string;}container c {leaf y {type string;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 679 | logbuf_assert("Invalid descendant-schema-nodeid value \"c/x\" - target node not found. /jj:l"); |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 680 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 681 | assert_null( lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;" |
| 682 | "list l {key x; unique c^y;leaf x {type string;}container c {leaf y {type string;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 683 | logbuf_assert("Invalid descendant-schema-nodeid value \"c^\" - missing \"/\" as node-identifier separator. /kk:l"); |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 684 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 685 | assert_null(lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;" |
| 686 | "list l {key \"x y x\";leaf x {type string;}leaf y {type string;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 687 | logbuf_assert("Duplicated key identifier \"x\". /ll:l"); |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 688 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 689 | assert_null(lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;" |
| 690 | "list l {key x;leaf x {type empty;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 691 | logbuf_assert("List's key cannot be of \"empty\" type until it is in YANG 1.1 module. /mm:l/x"); |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 692 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 693 | *state = NULL; |
| 694 | ly_ctx_destroy(ctx, NULL); |
| 695 | } |
| 696 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 697 | static void |
| 698 | test_node_choice(void **state) |
| 699 | { |
| 700 | *state = test_node_choice; |
| 701 | |
| 702 | struct ly_ctx *ctx; |
| 703 | struct lys_module *mod; |
| 704 | struct lysc_node_choice *ch; |
| 705 | struct lysc_node_case *cs; |
| 706 | |
| 707 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 708 | |
| 709 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;feature f;" |
Radek Krejci | 18f2b8a | 2018-12-12 16:41:21 +0100 | [diff] [blame] | 710 | "choice ch {default a:b; case a {leaf a1 {type string;}leaf a2 {type string;}}" |
| 711 | "leaf b {type string;}}}", LYS_IN_YANG)); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 712 | ch = (struct lysc_node_choice*)mod->compiled->data; |
| 713 | assert_non_null(ch); |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 714 | assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR, ch->flags); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 715 | cs = ch->cases; |
| 716 | assert_non_null(cs); |
| 717 | assert_string_equal("a", cs->name); |
| 718 | assert_ptr_equal(ch, cs->parent); |
| 719 | assert_non_null(cs->child); |
Radek Krejci | 18f2b8a | 2018-12-12 16:41:21 +0100 | [diff] [blame] | 720 | assert_string_equal("a1", cs->child->name); |
| 721 | assert_non_null(cs->child->next); |
| 722 | assert_string_equal("a2", cs->child->next->name); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 723 | assert_ptr_equal(cs, cs->child->parent); |
| 724 | cs = (struct lysc_node_case*)cs->next; |
| 725 | assert_non_null(cs); |
| 726 | assert_string_equal("b", cs->name); |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 727 | assert_int_equal(LYS_STATUS_CURR | LYS_SET_DFLT, cs->flags); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 728 | assert_ptr_equal(ch, cs->parent); |
| 729 | assert_non_null(cs->child); |
| 730 | assert_string_equal("b", cs->child->name); |
| 731 | assert_ptr_equal(cs, cs->child->parent); |
Radek Krejci | 18f2b8a | 2018-12-12 16:41:21 +0100 | [diff] [blame] | 732 | assert_ptr_equal(ch->cases->child->next, cs->child->prev); |
| 733 | assert_ptr_equal(ch->cases->child->next->next, cs->child); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 734 | assert_ptr_equal(ch->cases->child->prev, cs->child); |
Radek Krejci | a9026eb | 2018-12-12 16:04:47 +0100 | [diff] [blame] | 735 | assert_ptr_equal(ch->dflt, cs); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 736 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 737 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;" |
| 738 | "choice ch {case a {leaf x {type string;}}leaf x {type string;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 739 | logbuf_assert("Duplicate identifier \"x\" of data definition/RPC/action/Notification statement. /aa:ch/x/x"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 740 | assert_null(lys_parse_mem(ctx, "module aa2 {namespace urn:aa2;prefix aa;" |
| 741 | "choice ch {case a {leaf y {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 742 | logbuf_assert("Duplicate identifier \"y\" of data definition/RPC/action/Notification statement. /aa2:ch/b/y"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 743 | assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;" |
| 744 | "choice ch {case a {leaf x {type string;}}leaf a {type string;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 745 | logbuf_assert("Duplicate identifier \"a\" of case statement. /bb:ch/a"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 746 | assert_null(lys_parse_mem(ctx, "module bb2 {namespace urn:bb2;prefix bb;" |
| 747 | "choice ch {case b {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 748 | logbuf_assert("Duplicate identifier \"b\" of case statement. /bb2:ch/b"); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 749 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 750 | assert_null(lys_parse_mem(ctx, "module ca {namespace urn:ca;prefix ca;" |
| 751 | "choice ch {default c;case a {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 752 | logbuf_assert("Default case \"c\" not found. /ca:ch"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 753 | assert_null(lys_parse_mem(ctx, "module cb {namespace urn:cb;prefix cb; import a {prefix a;}" |
| 754 | "choice ch {default a:a;case a {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 755 | logbuf_assert("Invalid default case referencing a case from different YANG module (by prefix \"a\"). /cb:ch"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 756 | assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;" |
| 757 | "choice ch {default a;case a {leaf x {mandatory true;type string;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 758 | logbuf_assert("Mandatory node \"x\" under the default case \"a\". /cc:ch"); |
Radek Krejci | a9026eb | 2018-12-12 16:04:47 +0100 | [diff] [blame] | 759 | /* TODO check with mandatory nodes from augment placed into the case */ |
| 760 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 761 | *state = NULL; |
| 762 | ly_ctx_destroy(ctx, NULL); |
| 763 | } |
| 764 | |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 765 | static void |
| 766 | test_node_anydata(void **state) |
| 767 | { |
| 768 | *state = test_node_anydata; |
| 769 | |
| 770 | struct ly_ctx *ctx; |
| 771 | struct lys_module *mod; |
| 772 | struct lysc_node_anydata *any; |
| 773 | |
| 774 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 775 | |
| 776 | assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;" |
| 777 | "anydata any {config false;mandatory true;}}", LYS_IN_YANG)); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 778 | any = (struct lysc_node_anydata*)mod->compiled->data; |
| 779 | assert_non_null(any); |
| 780 | assert_int_equal(LYS_ANYDATA, any->nodetype); |
Radek Krejci | 93dcc39 | 2019-02-19 10:43:38 +0100 | [diff] [blame] | 781 | assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE | LYS_SET_CONFIG, any->flags); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 782 | |
| 783 | logbuf_clean(); |
| 784 | assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;" |
| 785 | "anyxml any;}", LYS_IN_YANG)); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 786 | any = (struct lysc_node_anydata*)mod->compiled->data; |
| 787 | assert_non_null(any); |
| 788 | assert_int_equal(LYS_ANYXML, any->nodetype); |
| 789 | assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR, any->flags); |
| 790 | logbuf_assert("Use of anyxml to define configuration data is not recommended."); /* warning */ |
| 791 | |
| 792 | /* invalid */ |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 793 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;anydata any;}", LYS_IN_YANG)); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 794 | logbuf_assert("Invalid keyword \"anydata\" as a child of \"module\" - the statement is allowed only in YANG 1.1 modules. Line number 1."); |
| 795 | |
| 796 | *state = NULL; |
| 797 | ly_ctx_destroy(ctx, NULL); |
| 798 | } |
| 799 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 800 | static void |
| 801 | test_action(void **state) |
| 802 | { |
| 803 | *state = test_action; |
| 804 | |
| 805 | struct ly_ctx *ctx; |
| 806 | struct lys_module *mod; |
| 807 | const struct lysc_action *rpc; |
| 808 | |
| 809 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 810 | |
| 811 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;" |
| 812 | "rpc a {input {leaf x {type int8;} leaf y {type int8;}} output {leaf result {type int16;}}}}", LYS_IN_YANG)); |
| 813 | rpc = mod->compiled->rpcs; |
| 814 | assert_non_null(rpc); |
| 815 | assert_int_equal(1, LY_ARRAY_SIZE(rpc)); |
| 816 | assert_int_equal(LYS_ACTION, rpc->nodetype); |
| 817 | assert_int_equal(LYS_STATUS_CURR, rpc->flags); |
| 818 | assert_string_equal("a", rpc->name); |
| 819 | |
| 820 | assert_non_null(mod = lys_parse_mem(ctx, "module b {yang-version 1.1; namespace urn:b;prefix b; container top {" |
| 821 | "action b {input {leaf x {type int8;} leaf y {type int8;}} output {leaf result {type int16;}}}}}", LYS_IN_YANG)); |
| 822 | rpc = lysc_node_actions(mod->compiled->data); |
| 823 | assert_non_null(rpc); |
| 824 | assert_int_equal(1, LY_ARRAY_SIZE(rpc)); |
| 825 | assert_int_equal(LYS_ACTION, rpc->nodetype); |
| 826 | assert_int_equal(LYS_STATUS_CURR, rpc->flags); |
| 827 | assert_string_equal("b", rpc->name); |
| 828 | |
| 829 | /* invalid */ |
| 830 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;container top {action x;}}", LYS_IN_YANG)); |
| 831 | logbuf_assert("Invalid keyword \"action\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules. Line number 1."); |
| 832 | |
Radek Krejci | 8cce853 | 2019-03-05 11:27:45 +0100 | [diff] [blame] | 833 | assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf x{type string;} rpc x;}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 834 | logbuf_assert("Duplicate identifier \"x\" of data definition/RPC/action/Notification statement. /bb:x"); |
Radek Krejci | 8cce853 | 2019-03-05 11:27:45 +0100 | [diff] [blame] | 835 | assert_null(lys_parse_mem(ctx, "module cc {yang-version 1.1; namespace urn:cc;prefix cc;container c {leaf y {type string;} action y;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 836 | logbuf_assert("Duplicate identifier \"y\" of data definition/RPC/action/Notification statement. /cc:c/y"); |
Radek Krejci | 8cce853 | 2019-03-05 11:27:45 +0100 | [diff] [blame] | 837 | assert_null(lys_parse_mem(ctx, "module dd {yang-version 1.1; namespace urn:dd;prefix dd;container c {action z; action z;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 838 | logbuf_assert("Duplicate identifier \"z\" of data definition/RPC/action/Notification statement. /dd:c/z"); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 839 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule eesub {belongs-to ee {prefix ee;} notification w;}"); |
Radek Krejci | 8cce853 | 2019-03-05 11:27:45 +0100 | [diff] [blame] | 840 | assert_null(lys_parse_mem(ctx, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;include eesub; rpc w;}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 841 | logbuf_assert("Duplicate identifier \"w\" of data definition/RPC/action/Notification statement. /ee:w"); |
Radek Krejci | 8cce853 | 2019-03-05 11:27:45 +0100 | [diff] [blame] | 842 | |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 843 | assert_null(lys_parse_mem(ctx, "module ff {yang-version 1.1; namespace urn:ff;prefix ff; rpc test {input {container a {leaf b {type string;}}}}" |
| 844 | "augment /test/input/a {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 845 | logbuf_assert("Action \"invalid\" is placed inside another RPC/action. /ff:{augment='/test/input/a'}/invalid"); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 846 | |
| 847 | assert_null(lys_parse_mem(ctx, "module gg {yang-version 1.1; namespace urn:gg;prefix gg; notification test {container a {leaf b {type string;}}}" |
| 848 | "augment /test/a {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 849 | logbuf_assert("Action \"invalid\" is placed inside Notification. /gg:{augment='/test/a'}/invalid"); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 850 | |
| 851 | assert_null(lys_parse_mem(ctx, "module hh {yang-version 1.1; namespace urn:hh;prefix hh; notification test {container a {uses grp;}}" |
| 852 | "grouping grp {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 853 | logbuf_assert("Action \"invalid\" is placed inside Notification. /hh:test/a/{uses='grp'}/invalid"); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 854 | |
| 855 | *state = NULL; |
| 856 | ly_ctx_destroy(ctx, NULL); |
| 857 | } |
| 858 | |
| 859 | static void |
| 860 | test_notification(void **state) |
| 861 | { |
| 862 | *state = test_notification; |
| 863 | |
| 864 | struct ly_ctx *ctx; |
| 865 | struct lys_module *mod; |
| 866 | const struct lysc_notif *notif; |
| 867 | |
| 868 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 869 | |
| 870 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;" |
| 871 | "notification a1 {leaf x {type int8;}} notification a2;}", LYS_IN_YANG)); |
| 872 | notif = mod->compiled->notifs; |
| 873 | assert_non_null(notif); |
| 874 | assert_int_equal(2, LY_ARRAY_SIZE(notif)); |
| 875 | assert_int_equal(LYS_NOTIF, notif->nodetype); |
| 876 | assert_int_equal(LYS_STATUS_CURR, notif->flags); |
| 877 | assert_string_equal("a1", notif->name); |
| 878 | assert_non_null(notif->data); |
| 879 | assert_string_equal("x", notif->data->name); |
| 880 | assert_int_equal(LYS_NOTIF, notif[1].nodetype); |
| 881 | assert_int_equal(LYS_STATUS_CURR, notif[1].flags); |
| 882 | assert_string_equal("a2", notif[1].name); |
| 883 | assert_null(notif[1].data); |
| 884 | |
| 885 | assert_non_null(mod = lys_parse_mem(ctx, "module b {yang-version 1.1; namespace urn:b;prefix b; container top {" |
| 886 | "notification b1 {leaf x {type int8;}} notification b2;}}", LYS_IN_YANG)); |
| 887 | notif = lysc_node_notifs(mod->compiled->data); |
| 888 | assert_non_null(notif); |
| 889 | assert_int_equal(2, LY_ARRAY_SIZE(notif)); |
| 890 | assert_int_equal(LYS_NOTIF, notif->nodetype); |
| 891 | assert_int_equal(LYS_STATUS_CURR, notif->flags); |
| 892 | assert_string_equal("b1", notif->name); |
| 893 | assert_non_null(notif->data); |
| 894 | assert_string_equal("x", notif->data->name); |
| 895 | assert_int_equal(LYS_NOTIF, notif[1].nodetype); |
| 896 | assert_int_equal(LYS_STATUS_CURR, notif[1].flags); |
| 897 | assert_string_equal("b2", notif[1].name); |
| 898 | assert_null(notif[1].data); |
| 899 | |
| 900 | /* invalid */ |
| 901 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;container top {notification x;}}", LYS_IN_YANG)); |
| 902 | logbuf_assert("Invalid keyword \"notification\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules. Line number 1."); |
| 903 | |
| 904 | assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf x{type string;} notification x;}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 905 | logbuf_assert("Duplicate identifier \"x\" of data definition/RPC/action/Notification statement. /bb:x"); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 906 | assert_null(lys_parse_mem(ctx, "module cc {yang-version 1.1; namespace urn:cc;prefix cc;container c {leaf y {type string;} notification y;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 907 | logbuf_assert("Duplicate identifier \"y\" of data definition/RPC/action/Notification statement. /cc:c/y"); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 908 | assert_null(lys_parse_mem(ctx, "module dd {yang-version 1.1; namespace urn:dd;prefix dd;container c {notification z; notification z;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 909 | logbuf_assert("Duplicate identifier \"z\" of data definition/RPC/action/Notification statement. /dd:c/z"); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 910 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule eesub {belongs-to ee {prefix ee;} rpc w;}"); |
| 911 | assert_null(lys_parse_mem(ctx, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;include eesub; notification w;}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 912 | logbuf_assert("Duplicate identifier \"w\" of data definition/RPC/action/Notification statement. /ee:w"); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 913 | |
| 914 | assert_null(lys_parse_mem(ctx, "module ff {yang-version 1.1; namespace urn:ff;prefix ff; rpc test {input {container a {leaf b {type string;}}}}" |
| 915 | "augment /test/input/a {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 916 | logbuf_assert("Notification \"invalid\" is placed inside RPC/action. /ff:{augment='/test/input/a'}/invalid"); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 917 | |
| 918 | assert_null(lys_parse_mem(ctx, "module gg {yang-version 1.1; namespace urn:gg;prefix gg; notification test {container a {leaf b {type string;}}}" |
| 919 | "augment /test/a {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 920 | logbuf_assert("Notification \"invalid\" is placed inside another Notification. /gg:{augment='/test/a'}/invalid"); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 921 | |
| 922 | assert_null(lys_parse_mem(ctx, "module hh {yang-version 1.1; namespace urn:hh;prefix hh; rpc test {input {container a {uses grp;}}}" |
| 923 | "grouping grp {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 924 | logbuf_assert("Notification \"invalid\" is placed inside RPC/action. /hh:test/input/a/{uses='grp'}/invalid"); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 925 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 926 | *state = NULL; |
| 927 | ly_ctx_destroy(ctx, NULL); |
| 928 | } |
| 929 | |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 930 | /** |
| 931 | * actually the same as length restriction (tested in test_type_length()), so just check the correct handling in appropriate types, |
| 932 | * do not test the expression itself |
| 933 | */ |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 934 | static void |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 935 | test_type_range(void **state) |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 936 | { |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 937 | *state = test_type_range; |
| 938 | |
| 939 | struct ly_ctx *ctx; |
| 940 | struct lys_module *mod; |
| 941 | struct lysc_type *type; |
| 942 | |
| 943 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 944 | |
| 945 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;leaf l {type int8 {range min..10|max;}}}", LYS_IN_YANG)); |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 946 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 947 | assert_non_null(type); |
| 948 | assert_int_equal(LY_TYPE_INT8, type->basetype); |
| 949 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 950 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 951 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 952 | assert_int_equal(-128, ((struct lysc_type_num*)type)->range->parts[0].min_64); |
| 953 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_64); |
| 954 | assert_int_equal(127, ((struct lysc_type_num*)type)->range->parts[1].min_64); |
| 955 | assert_int_equal(127, ((struct lysc_type_num*)type)->range->parts[1].max_64); |
| 956 | |
| 957 | assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;leaf l {type int16 {range min..10|max;}}}", LYS_IN_YANG)); |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 958 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 959 | assert_non_null(type); |
| 960 | assert_int_equal(LY_TYPE_INT16, type->basetype); |
| 961 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 962 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 963 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 964 | assert_int_equal(-32768, ((struct lysc_type_num*)type)->range->parts[0].min_64); |
| 965 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_64); |
| 966 | assert_int_equal(32767, ((struct lysc_type_num*)type)->range->parts[1].min_64); |
| 967 | assert_int_equal(32767, ((struct lysc_type_num*)type)->range->parts[1].max_64); |
| 968 | |
| 969 | assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;leaf l {type int32 {range min..10|max;}}}", LYS_IN_YANG)); |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 970 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 971 | assert_non_null(type); |
| 972 | assert_int_equal(LY_TYPE_INT32, type->basetype); |
| 973 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 974 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 975 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 976 | assert_int_equal(INT64_C(-2147483648), ((struct lysc_type_num*)type)->range->parts[0].min_64); |
| 977 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_64); |
| 978 | assert_int_equal(INT64_C(2147483647), ((struct lysc_type_num*)type)->range->parts[1].min_64); |
| 979 | assert_int_equal(INT64_C(2147483647), ((struct lysc_type_num*)type)->range->parts[1].max_64); |
| 980 | |
| 981 | assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;leaf l {type int64 {range min..10|max;}}}", LYS_IN_YANG)); |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 982 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 983 | assert_non_null(type); |
| 984 | assert_int_equal(LY_TYPE_INT64, type->basetype); |
| 985 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 986 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 987 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 988 | assert_int_equal(INT64_C(-9223372036854775807) - INT64_C(1), ((struct lysc_type_num*)type)->range->parts[0].min_64); |
| 989 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_64); |
| 990 | assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_num*)type)->range->parts[1].min_64); |
| 991 | assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_num*)type)->range->parts[1].max_64); |
| 992 | |
| 993 | assert_non_null(mod = lys_parse_mem(ctx, "module e {namespace urn:e;prefix e;leaf l {type uint8 {range min..10|max;}}}", LYS_IN_YANG)); |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 994 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 995 | assert_non_null(type); |
| 996 | assert_int_equal(LY_TYPE_UINT8, type->basetype); |
| 997 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 998 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 999 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 1000 | assert_int_equal(0, ((struct lysc_type_num*)type)->range->parts[0].min_u64); |
| 1001 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_u64); |
| 1002 | assert_int_equal(255, ((struct lysc_type_num*)type)->range->parts[1].min_u64); |
| 1003 | assert_int_equal(255, ((struct lysc_type_num*)type)->range->parts[1].max_u64); |
| 1004 | |
| 1005 | assert_non_null(mod = lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;leaf l {type uint16 {range min..10|max;}}}", LYS_IN_YANG)); |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 1006 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1007 | assert_non_null(type); |
| 1008 | assert_int_equal(LY_TYPE_UINT16, type->basetype); |
| 1009 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 1010 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 1011 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 1012 | assert_int_equal(0, ((struct lysc_type_num*)type)->range->parts[0].min_u64); |
| 1013 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_u64); |
| 1014 | assert_int_equal(65535, ((struct lysc_type_num*)type)->range->parts[1].min_u64); |
| 1015 | assert_int_equal(65535, ((struct lysc_type_num*)type)->range->parts[1].max_u64); |
| 1016 | |
| 1017 | assert_non_null(mod = lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;leaf l {type uint32 {range min..10|max;}}}", LYS_IN_YANG)); |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 1018 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1019 | assert_non_null(type); |
| 1020 | assert_int_equal(LY_TYPE_UINT32, type->basetype); |
| 1021 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 1022 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 1023 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 1024 | assert_int_equal(0, ((struct lysc_type_num*)type)->range->parts[0].min_u64); |
| 1025 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_u64); |
| 1026 | assert_int_equal(UINT64_C(4294967295), ((struct lysc_type_num*)type)->range->parts[1].min_u64); |
| 1027 | assert_int_equal(UINT64_C(4294967295), ((struct lysc_type_num*)type)->range->parts[1].max_u64); |
| 1028 | |
| 1029 | assert_non_null(mod = lys_parse_mem(ctx, "module h {namespace urn:h;prefix h;leaf l {type uint64 {range min..10|max;}}}", LYS_IN_YANG)); |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 1030 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1031 | assert_non_null(type); |
| 1032 | assert_int_equal(LY_TYPE_UINT64, type->basetype); |
| 1033 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 1034 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 1035 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 1036 | assert_int_equal(0, ((struct lysc_type_num*)type)->range->parts[0].min_u64); |
| 1037 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_u64); |
| 1038 | assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_num*)type)->range->parts[1].min_u64); |
| 1039 | assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_num*)type)->range->parts[1].max_u64); |
| 1040 | |
| 1041 | assert_non_null(mod = lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;typedef mytype {type uint8 {range 10..100;}}" |
| 1042 | "typedef mytype2 {type mytype;} leaf l {type mytype2;}}", LYS_IN_YANG)); |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 1043 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1044 | assert_non_null(type); |
| 1045 | assert_int_equal(3, type->refcount); |
| 1046 | assert_int_equal(LY_TYPE_UINT8, type->basetype); |
| 1047 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 1048 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 1049 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 1050 | |
Radek Krejci | f139404 | 2019-01-08 10:53:34 +0100 | [diff] [blame] | 1051 | assert_non_null(mod = lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;" |
| 1052 | "typedef mytype {type uint8 {range 1..100{description \"one to hundred\";reference A;}}}" |
| 1053 | "leaf l {type mytype {range 1..10 {description \"one to ten\";reference B;}}}}", LYS_IN_YANG)); |
Radek Krejci | f139404 | 2019-01-08 10:53:34 +0100 | [diff] [blame] | 1054 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1055 | assert_non_null(type); |
| 1056 | assert_int_equal(1, type->refcount); |
| 1057 | assert_int_equal(LY_TYPE_UINT8, type->basetype); |
| 1058 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 1059 | assert_string_equal("one to ten", ((struct lysc_type_num*)type)->range->dsc); |
| 1060 | assert_string_equal("B", ((struct lysc_type_num*)type)->range->ref); |
| 1061 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 1062 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 1063 | assert_int_equal(1, ((struct lysc_type_num*)type)->range->parts[0].min_u64); |
| 1064 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_u64); |
| 1065 | |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 1066 | *state = NULL; |
| 1067 | ly_ctx_destroy(ctx, NULL); |
| 1068 | } |
| 1069 | |
| 1070 | static void |
| 1071 | test_type_length(void **state) |
| 1072 | { |
| 1073 | *state = test_type_length; |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1074 | |
| 1075 | struct ly_ctx *ctx; |
| 1076 | struct lys_module *mod; |
| 1077 | struct lysc_type *type; |
| 1078 | |
| 1079 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 1080 | |
Radek Krejci | c5ddcc0 | 2018-11-12 13:28:18 +0100 | [diff] [blame] | 1081 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;leaf l {type binary {length min {error-app-tag errortag;error-message error;}}}}", LYS_IN_YANG)); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1082 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1083 | assert_non_null(type); |
| 1084 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 1085 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
Radek Krejci | c5ddcc0 | 2018-11-12 13:28:18 +0100 | [diff] [blame] | 1086 | assert_string_equal("errortag", ((struct lysc_type_bin*)type)->length->eapptag); |
| 1087 | assert_string_equal("error", ((struct lysc_type_bin*)type)->length->emsg); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1088 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 1089 | assert_int_equal(0, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 1090 | assert_int_equal(0, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 1091 | |
| 1092 | assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;leaf l {type binary {length max;}}}", LYS_IN_YANG)); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1093 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1094 | assert_non_null(type); |
| 1095 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 1096 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 1097 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
Radek Krejci | 0fe2075 | 2018-11-27 11:33:24 +0100 | [diff] [blame] | 1098 | assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 1099 | assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1100 | |
| 1101 | assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;leaf l {type binary {length min..max;}}}", LYS_IN_YANG)); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1102 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1103 | assert_non_null(type); |
| 1104 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 1105 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 1106 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 1107 | assert_int_equal(0, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
Radek Krejci | 0fe2075 | 2018-11-27 11:33:24 +0100 | [diff] [blame] | 1108 | assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1109 | |
| 1110 | assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;leaf l {type binary {length 5;}}}", LYS_IN_YANG)); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1111 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1112 | assert_non_null(type); |
| 1113 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 1114 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 1115 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 1116 | assert_int_equal(5, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 1117 | assert_int_equal(5, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 1118 | |
| 1119 | assert_non_null(mod = lys_parse_mem(ctx, "module e {namespace urn:e;prefix e;leaf l {type binary {length 1..10;}}}", LYS_IN_YANG)); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1120 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1121 | assert_non_null(type); |
| 1122 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 1123 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 1124 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 1125 | assert_int_equal(1, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 1126 | assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 1127 | |
| 1128 | assert_non_null(mod = lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;leaf l {type binary {length 1..10|20..30;}}}", LYS_IN_YANG)); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1129 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1130 | assert_non_null(type); |
| 1131 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 1132 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 1133 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 1134 | assert_int_equal(1, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 1135 | assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 1136 | assert_int_equal(20, ((struct lysc_type_bin*)type)->length->parts[1].min_u64); |
| 1137 | assert_int_equal(30, ((struct lysc_type_bin*)type)->length->parts[1].max_u64); |
| 1138 | |
| 1139 | assert_non_null(mod = lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;leaf l {type binary {length \"16 | 32\";}}}", LYS_IN_YANG)); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1140 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1141 | assert_non_null(type); |
| 1142 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 1143 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 1144 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 1145 | assert_int_equal(16, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 1146 | assert_int_equal(16, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 1147 | assert_int_equal(32, ((struct lysc_type_bin*)type)->length->parts[1].min_u64); |
| 1148 | assert_int_equal(32, ((struct lysc_type_bin*)type)->length->parts[1].max_u64); |
| 1149 | |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 1150 | assert_non_null(mod = lys_parse_mem(ctx, "module h {namespace urn:h;prefix h;typedef mytype {type binary {length 10;}}" |
| 1151 | "leaf l {type mytype {length \"10\";}}}", LYS_IN_YANG)); |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 1152 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1153 | assert_non_null(type); |
| 1154 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 1155 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 1156 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 1157 | assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 1158 | assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 1159 | |
| 1160 | assert_non_null(mod = lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;typedef mytype {type binary {length 10..100;}}" |
| 1161 | "leaf l {type mytype {length \"50\";}}}", LYS_IN_YANG)); |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 1162 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1163 | assert_non_null(type); |
| 1164 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 1165 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 1166 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 1167 | assert_int_equal(50, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 1168 | assert_int_equal(50, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 1169 | |
| 1170 | assert_non_null(mod = lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;typedef mytype {type binary {length 10..100;}}" |
| 1171 | "leaf l {type mytype {length \"10..30|60..100\";}}}", LYS_IN_YANG)); |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 1172 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1173 | assert_non_null(type); |
| 1174 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 1175 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 1176 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 1177 | assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 1178 | assert_int_equal(30, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 1179 | assert_int_equal(60, ((struct lysc_type_bin*)type)->length->parts[1].min_u64); |
| 1180 | assert_int_equal(100, ((struct lysc_type_bin*)type)->length->parts[1].max_u64); |
| 1181 | |
| 1182 | assert_non_null(mod = lys_parse_mem(ctx, "module k {namespace urn:k;prefix k;typedef mytype {type binary {length 10..100;}}" |
Radek Krejci | 56aa27c | 2018-11-13 14:21:59 +0100 | [diff] [blame] | 1183 | "leaf l {type mytype {length \"10..80\";}}leaf ll {type mytype;}}", LYS_IN_YANG)); |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 1184 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1185 | assert_non_null(type); |
Radek Krejci | 56aa27c | 2018-11-13 14:21:59 +0100 | [diff] [blame] | 1186 | assert_int_equal(1, type->refcount); |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 1187 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 1188 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 1189 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 1190 | assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
Radek Krejci | 56aa27c | 2018-11-13 14:21:59 +0100 | [diff] [blame] | 1191 | assert_int_equal(80, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 1192 | type = ((struct lysc_node_leaf*)mod->compiled->data->next)->type; |
| 1193 | assert_non_null(type); |
Radek Krejci | 56aa27c | 2018-11-13 14:21:59 +0100 | [diff] [blame] | 1194 | assert_int_equal(2, type->refcount); |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 1195 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 1196 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 1197 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 1198 | assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 1199 | assert_int_equal(100, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 1200 | |
Radek Krejci | 56aa27c | 2018-11-13 14:21:59 +0100 | [diff] [blame] | 1201 | assert_non_null(mod = lys_parse_mem(ctx, "module l {namespace urn:l;prefix l;typedef mytype {type string {length 10..100;}}" |
| 1202 | "typedef mytype2 {type mytype {pattern '[0-9]*';}} leaf l {type mytype2 {pattern '[0-4]*';}}}", LYS_IN_YANG)); |
Radek Krejci | 9a191e6 | 2018-11-13 13:19:56 +0100 | [diff] [blame] | 1203 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1204 | assert_non_null(type); |
| 1205 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
Radek Krejci | 56aa27c | 2018-11-13 14:21:59 +0100 | [diff] [blame] | 1206 | assert_int_equal(1, type->refcount); |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 1207 | assert_non_null(((struct lysc_type_str*)type)->length); |
| 1208 | assert_non_null(((struct lysc_type_str*)type)->length->parts); |
| 1209 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_str*)type)->length->parts)); |
| 1210 | assert_int_equal(10, ((struct lysc_type_str*)type)->length->parts[0].min_u64); |
| 1211 | assert_int_equal(100, ((struct lysc_type_str*)type)->length->parts[0].max_u64); |
Radek Krejci | 9a191e6 | 2018-11-13 13:19:56 +0100 | [diff] [blame] | 1212 | |
Radek Krejci | 5969f27 | 2018-11-23 10:03:58 +0100 | [diff] [blame] | 1213 | assert_non_null(mod = lys_parse_mem(ctx, "module m {namespace urn:m;prefix m;typedef mytype {type string {length 10;}}" |
| 1214 | "leaf l {type mytype {length min..max;}}}", LYS_IN_YANG)); |
Radek Krejci | 5969f27 | 2018-11-23 10:03:58 +0100 | [diff] [blame] | 1215 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1216 | assert_non_null(type); |
| 1217 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 1218 | assert_int_equal(1, type->refcount); |
| 1219 | assert_non_null(((struct lysc_type_str*)type)->length); |
| 1220 | assert_non_null(((struct lysc_type_str*)type)->length->parts); |
| 1221 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_str*)type)->length->parts)); |
| 1222 | assert_int_equal(10, ((struct lysc_type_str*)type)->length->parts[0].min_u64); |
| 1223 | assert_int_equal(10, ((struct lysc_type_str*)type)->length->parts[0].max_u64); |
| 1224 | |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1225 | /* invalid values */ |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1226 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;leaf l {type binary {length -10;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1227 | logbuf_assert("Invalid length restriction - value \"-10\" does not fit the type limitations. /aa:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1228 | assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf l {type binary {length 18446744073709551616;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1229 | logbuf_assert("Invalid length restriction - invalid value \"18446744073709551616\". /bb:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1230 | assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;leaf l {type binary {length \"max .. 10\";}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1231 | logbuf_assert("Invalid length restriction - unexpected data after max keyword (.. 10). /cc:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1232 | assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;leaf l {type binary {length 50..10;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1233 | logbuf_assert("Invalid length restriction - values are not in ascending order (10). /dd:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1234 | assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type binary {length \"50 | 10\";}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1235 | logbuf_assert("Invalid length restriction - values are not in ascending order (10). /ee:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1236 | assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type binary {length \"x\";}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1237 | logbuf_assert("Invalid length restriction - unexpected data (x). /ff:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1238 | assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;leaf l {type binary {length \"50 | min\";}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1239 | logbuf_assert("Invalid length restriction - unexpected data before min keyword (50 | ). /gg:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1240 | assert_null(lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;leaf l {type binary {length \"| 50\";}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1241 | logbuf_assert("Invalid length restriction - unexpected beginning of the expression (| 50). /hh:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1242 | assert_null(lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;leaf l {type binary {length \"10 ..\";}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1243 | logbuf_assert("Invalid length restriction - unexpected end of the expression after \"..\" (10 ..). /ii:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1244 | assert_null(lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;leaf l {type binary {length \".. 10\";}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1245 | logbuf_assert("Invalid length restriction - unexpected \"..\" without a lower bound. /jj:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1246 | assert_null(lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;leaf l {type binary {length \"10 |\";}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1247 | logbuf_assert("Invalid length restriction - unexpected end of the expression (10 |). /kk:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1248 | assert_null(lys_parse_mem(ctx, "module kl {namespace urn:kl;prefix kl;leaf l {type binary {length \"10..20 | 15..30\";}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1249 | logbuf_assert("Invalid length restriction - values are not in ascending order (15). /kl:l"); |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 1250 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1251 | assert_null(lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;typedef mytype {type binary {length 10;}}" |
| 1252 | "leaf l {type mytype {length 11;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1253 | logbuf_assert("Invalid length restriction - the derived restriction (11) is not equally or more limiting. /ll:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1254 | assert_null(lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;typedef mytype {type binary {length 10..100;}}" |
| 1255 | "leaf l {type mytype {length 1..11;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1256 | logbuf_assert("Invalid length restriction - the derived restriction (1..11) is not equally or more limiting. /mm:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1257 | assert_null(lys_parse_mem(ctx, "module nn {namespace urn:nn;prefix nn;typedef mytype {type binary {length 10..100;}}" |
| 1258 | "leaf l {type mytype {length 20..110;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1259 | logbuf_assert("Invalid length restriction - the derived restriction (20..110) is not equally or more limiting. /nn:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1260 | assert_null(lys_parse_mem(ctx, "module oo {namespace urn:oo;prefix oo;typedef mytype {type binary {length 10..100;}}" |
| 1261 | "leaf l {type mytype {length 20..30|110..120;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1262 | logbuf_assert("Invalid length restriction - the derived restriction (20..30|110..120) is not equally or more limiting. /oo:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1263 | assert_null(lys_parse_mem(ctx, "module pp {namespace urn:pp;prefix pp;typedef mytype {type binary {length 10..11;}}" |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 1264 | "leaf l {type mytype {length 15;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1265 | logbuf_assert("Invalid length restriction - the derived restriction (15) is not equally or more limiting. /pp:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1266 | assert_null(lys_parse_mem(ctx, "module qq {namespace urn:qq;prefix qq;typedef mytype {type binary {length 10..20|30..40;}}" |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 1267 | "leaf l {type mytype {length 15..35;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1268 | logbuf_assert("Invalid length restriction - the derived restriction (15..35) is not equally or more limiting. /qq:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1269 | assert_null(lys_parse_mem(ctx, "module rr {namespace urn:rr;prefix rr;typedef mytype {type binary {length 10;}}" |
Radek Krejci | 6489bbe | 2018-11-12 17:05:19 +0100 | [diff] [blame] | 1270 | "leaf l {type mytype {length 10..35;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1271 | logbuf_assert("Invalid length restriction - the derived restriction (10..35) is not equally or more limiting. /rr:l"); |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 1272 | |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1273 | assert_null(lys_parse_mem(ctx, "module ss {namespace urn:ss;prefix ss;leaf l {type binary {pattern '[0-9]*';}}}", LYS_IN_YANG)); |
| 1274 | logbuf_assert("Invalid type restrictions for binary type. /ss:l"); |
Radek Krejci | 495903e | 2018-11-13 11:30:45 +0100 | [diff] [blame] | 1275 | |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1276 | *state = NULL; |
| 1277 | ly_ctx_destroy(ctx, NULL); |
| 1278 | } |
| 1279 | |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 1280 | static void |
| 1281 | test_type_pattern(void **state) |
| 1282 | { |
| 1283 | *state = test_type_pattern; |
| 1284 | |
| 1285 | struct ly_ctx *ctx; |
| 1286 | struct lys_module *mod; |
| 1287 | struct lysc_type *type; |
| 1288 | |
| 1289 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 1290 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1291 | assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;leaf l {type string {" |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 1292 | "pattern .* {error-app-tag errortag;error-message error;}" |
| 1293 | "pattern [0-9].*[0-9] {modifier invert-match;}}}}", LYS_IN_YANG)); |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 1294 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1295 | assert_non_null(type); |
| 1296 | assert_non_null(((struct lysc_type_str*)type)->patterns); |
| 1297 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_str*)type)->patterns)); |
| 1298 | assert_string_equal("errortag", ((struct lysc_type_str*)type)->patterns[0]->eapptag); |
| 1299 | assert_string_equal("error", ((struct lysc_type_str*)type)->patterns[0]->emsg); |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 1300 | assert_string_equal(".*", ((struct lysc_type_str*)type)->patterns[0]->expr); |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 1301 | assert_int_equal(0, ((struct lysc_type_str*)type)->patterns[0]->inverted); |
| 1302 | assert_null(((struct lysc_type_str*)type)->patterns[1]->eapptag); |
| 1303 | assert_null(((struct lysc_type_str*)type)->patterns[1]->emsg); |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 1304 | assert_string_equal("[0-9].*[0-9]", ((struct lysc_type_str*)type)->patterns[1]->expr); |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 1305 | assert_int_equal(1, ((struct lysc_type_str*)type)->patterns[1]->inverted); |
| 1306 | |
| 1307 | assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;typedef mytype {type string {pattern '[0-9]*';}}" |
| 1308 | "typedef mytype2 {type mytype {length 10;}} leaf l {type mytype2 {pattern '[0-4]*';}}}", LYS_IN_YANG)); |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 1309 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1310 | assert_non_null(type); |
| 1311 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 1312 | assert_int_equal(1, type->refcount); |
| 1313 | assert_non_null(((struct lysc_type_str*)type)->patterns); |
| 1314 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_str*)type)->patterns)); |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 1315 | assert_string_equal("[0-9]*", ((struct lysc_type_str*)type)->patterns[0]->expr); |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 1316 | assert_int_equal(3, ((struct lysc_type_str*)type)->patterns[0]->refcount); |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 1317 | assert_string_equal("[0-4]*", ((struct lysc_type_str*)type)->patterns[1]->expr); |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 1318 | assert_int_equal(1, ((struct lysc_type_str*)type)->patterns[1]->refcount); |
| 1319 | |
Radek Krejci | 04bc1e9 | 2018-11-14 14:28:13 +0100 | [diff] [blame] | 1320 | assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;typedef mytype {type string {pattern '[0-9]*';}}" |
| 1321 | "leaf l {type mytype {length 10;}}}", LYS_IN_YANG)); |
Radek Krejci | 04bc1e9 | 2018-11-14 14:28:13 +0100 | [diff] [blame] | 1322 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1323 | assert_non_null(type); |
| 1324 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 1325 | assert_int_equal(1, type->refcount); |
| 1326 | assert_non_null(((struct lysc_type_str*)type)->patterns); |
| 1327 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_str*)type)->patterns)); |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 1328 | assert_string_equal("[0-9]*", ((struct lysc_type_str*)type)->patterns[0]->expr); |
Radek Krejci | 04bc1e9 | 2018-11-14 14:28:13 +0100 | [diff] [blame] | 1329 | assert_int_equal(2, ((struct lysc_type_str*)type)->patterns[0]->refcount); |
| 1330 | |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 1331 | /* test substitutions */ |
Radek Krejci | 04bc1e9 | 2018-11-14 14:28:13 +0100 | [diff] [blame] | 1332 | assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;leaf l {type string {" |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 1333 | "pattern '^\\p{IsLatinExtended-A}$';}}}", LYS_IN_YANG)); |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 1334 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1335 | assert_non_null(type); |
| 1336 | assert_non_null(((struct lysc_type_str*)type)->patterns); |
| 1337 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_str*)type)->patterns)); |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 1338 | assert_string_equal("^\\p{IsLatinExtended-A}$", ((struct lysc_type_str*)type)->patterns[0]->expr); |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 1339 | /* TODO check some data "^Å™$" */ |
| 1340 | |
| 1341 | *state = NULL; |
| 1342 | ly_ctx_destroy(ctx, NULL); |
| 1343 | } |
| 1344 | |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1345 | static void |
| 1346 | test_type_enum(void **state) |
| 1347 | { |
| 1348 | *state = test_type_enum; |
| 1349 | |
| 1350 | struct ly_ctx *ctx; |
| 1351 | struct lys_module *mod; |
| 1352 | struct lysc_type *type; |
| 1353 | |
| 1354 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 1355 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1356 | assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;feature f; leaf l {type enumeration {" |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1357 | "enum automin; enum min {value -2147483648;}enum one {if-feature f; value 1;}" |
| 1358 | "enum two; enum seven {value 7;}enum eight;}}}", LYS_IN_YANG)); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1359 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1360 | assert_non_null(type); |
| 1361 | assert_int_equal(LY_TYPE_ENUM, type->basetype); |
| 1362 | assert_non_null(((struct lysc_type_enum*)type)->enums); |
| 1363 | assert_int_equal(6, LY_ARRAY_SIZE(((struct lysc_type_enum*)type)->enums)); |
| 1364 | assert_non_null(((struct lysc_type_enum*)type)->enums[2].iffeatures); |
| 1365 | assert_string_equal("automin", ((struct lysc_type_enum*)type)->enums[0].name); |
| 1366 | assert_int_equal(0, ((struct lysc_type_enum*)type)->enums[0].value); |
| 1367 | assert_string_equal("min", ((struct lysc_type_enum*)type)->enums[1].name); |
| 1368 | assert_int_equal(-2147483648, ((struct lysc_type_enum*)type)->enums[1].value); |
| 1369 | assert_string_equal("one", ((struct lysc_type_enum*)type)->enums[2].name); |
| 1370 | assert_int_equal(1, ((struct lysc_type_enum*)type)->enums[2].value); |
| 1371 | assert_string_equal("two", ((struct lysc_type_enum*)type)->enums[3].name); |
| 1372 | assert_int_equal(2, ((struct lysc_type_enum*)type)->enums[3].value); |
| 1373 | assert_string_equal("seven", ((struct lysc_type_enum*)type)->enums[4].name); |
| 1374 | assert_int_equal(7, ((struct lysc_type_enum*)type)->enums[4].value); |
| 1375 | assert_string_equal("eight", ((struct lysc_type_enum*)type)->enums[5].name); |
| 1376 | assert_int_equal(8, ((struct lysc_type_enum*)type)->enums[5].value); |
| 1377 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1378 | assert_non_null(mod = lys_parse_mem(ctx, "module b {yang-version 1.1; namespace urn:b;prefix b;feature f; typedef mytype {type enumeration {" |
| 1379 | "enum 11; enum min {value -2147483648;}enum x$&;" |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1380 | "enum two; enum seven {value 7;}enum eight;}} leaf l { type mytype {enum seven;enum eight;}}}", |
| 1381 | LYS_IN_YANG)); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1382 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1383 | assert_non_null(type); |
| 1384 | assert_int_equal(LY_TYPE_ENUM, type->basetype); |
| 1385 | assert_non_null(((struct lysc_type_enum*)type)->enums); |
| 1386 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_enum*)type)->enums)); |
| 1387 | assert_string_equal("seven", ((struct lysc_type_enum*)type)->enums[0].name); |
| 1388 | assert_int_equal(7, ((struct lysc_type_enum*)type)->enums[0].value); |
| 1389 | assert_string_equal("eight", ((struct lysc_type_enum*)type)->enums[1].name); |
| 1390 | assert_int_equal(8, ((struct lysc_type_enum*)type)->enums[1].value); |
| 1391 | |
| 1392 | |
| 1393 | /* invalid cases */ |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1394 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type enumeration {" |
| 1395 | "enum one {if-feature f;}}}}", LYS_IN_YANG)); |
| 1396 | logbuf_assert("Invalid keyword \"if-feature\" as a child of \"enum\" - the statement is allowed only in YANG 1.1 modules. Line number 1."); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1397 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {" |
| 1398 | "enum one {value -2147483649;}}}}", LYS_IN_YANG)); |
| 1399 | logbuf_assert("Invalid value \"-2147483649\" of \"value\". Line number 1."); |
| 1400 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {" |
| 1401 | "enum one {value 2147483648;}}}}", LYS_IN_YANG)); |
| 1402 | logbuf_assert("Invalid value \"2147483648\" of \"value\". Line number 1."); |
| 1403 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {" |
| 1404 | "enum one; enum one;}}}", LYS_IN_YANG)); |
| 1405 | logbuf_assert("Duplicate identifier \"one\" of enum statement. Line number 1."); |
| 1406 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {" |
| 1407 | "enum '';}}}", LYS_IN_YANG)); |
| 1408 | logbuf_assert("Enum name must not be zero-length. Line number 1."); |
| 1409 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {" |
| 1410 | "enum ' x';}}}", LYS_IN_YANG)); |
| 1411 | logbuf_assert("Enum name must not have any leading or trailing whitespaces (\" x\"). Line number 1."); |
| 1412 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {" |
| 1413 | "enum 'x ';}}}", LYS_IN_YANG)); |
| 1414 | logbuf_assert("Enum name must not have any leading or trailing whitespaces (\"x \"). Line number 1."); |
| 1415 | assert_non_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {" |
| 1416 | "enum 'inva\nlid';}}}", LYS_IN_YANG)); |
| 1417 | logbuf_assert("Control characters in enum name should be avoided (\"inva\nlid\", character number 5)."); |
| 1418 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1419 | assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type enumeration;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1420 | logbuf_assert("Missing enum substatement for enumeration type. /bb:l"); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1421 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1422 | assert_null(lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;typedef mytype {type enumeration {enum one;}}" |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1423 | "leaf l {type mytype {enum two;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1424 | logbuf_assert("Invalid enumeration - derived type adds new item \"two\". /cc:l"); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1425 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1426 | assert_null(lys_parse_mem(ctx, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;typedef mytype {type enumeration {enum one;}}" |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1427 | "leaf l {type mytype {enum one {value 1;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1428 | logbuf_assert("Invalid enumeration - value of the item \"one\" has changed from 0 to 1 in the derived type. /dd:l"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1429 | assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type enumeration {enum x {value 2147483647;}enum y;}}}", |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1430 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1431 | logbuf_assert("Invalid enumeration - it is not possible to auto-assign enum value for \"y\" since the highest value is already 2147483647. /ee:l"); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1432 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1433 | assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type enumeration {enum x {value 1;}enum y {value 1;}}}}", |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1434 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1435 | logbuf_assert("Invalid enumeration - value 1 collide in items \"y\" and \"x\". /ff:l"); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1436 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1437 | assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;typedef mytype {type enumeration;}" |
Radek Krejci | 04bc1e9 | 2018-11-14 14:28:13 +0100 | [diff] [blame] | 1438 | "leaf l {type mytype {enum one;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1439 | logbuf_assert("Missing enum substatement for enumeration type mytype. /gg:l"); |
Radek Krejci | 04bc1e9 | 2018-11-14 14:28:13 +0100 | [diff] [blame] | 1440 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1441 | assert_null(lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh; typedef mytype {type enumeration {enum one;}}" |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1442 | "leaf l {type mytype {enum one;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1443 | logbuf_assert("Enumeration type can be subtyped only in YANG 1.1 modules. /hh:l"); |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1444 | |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1445 | *state = NULL; |
| 1446 | ly_ctx_destroy(ctx, NULL); |
| 1447 | } |
| 1448 | |
| 1449 | static void |
| 1450 | test_type_bits(void **state) |
| 1451 | { |
| 1452 | *state = test_type_bits; |
| 1453 | |
| 1454 | struct ly_ctx *ctx; |
| 1455 | struct lys_module *mod; |
| 1456 | struct lysc_type *type; |
| 1457 | |
| 1458 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 1459 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1460 | assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;feature f; leaf l {type bits {" |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1461 | "bit automin; bit one {if-feature f; position 1;}" |
| 1462 | "bit two; bit seven {position 7;}bit eight;}}}", LYS_IN_YANG)); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1463 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1464 | assert_non_null(type); |
| 1465 | assert_int_equal(LY_TYPE_BITS, type->basetype); |
| 1466 | assert_non_null(((struct lysc_type_bits*)type)->bits); |
| 1467 | assert_int_equal(5, LY_ARRAY_SIZE(((struct lysc_type_bits*)type)->bits)); |
| 1468 | assert_non_null(((struct lysc_type_bits*)type)->bits[1].iffeatures); |
| 1469 | assert_string_equal("automin", ((struct lysc_type_bits*)type)->bits[0].name); |
| 1470 | assert_int_equal(0, ((struct lysc_type_bits*)type)->bits[0].position); |
| 1471 | assert_string_equal("one", ((struct lysc_type_bits*)type)->bits[1].name); |
| 1472 | assert_int_equal(1, ((struct lysc_type_bits*)type)->bits[1].position); |
| 1473 | assert_string_equal("two", ((struct lysc_type_bits*)type)->bits[2].name); |
| 1474 | assert_int_equal(2, ((struct lysc_type_bits*)type)->bits[2].position); |
| 1475 | assert_string_equal("seven", ((struct lysc_type_bits*)type)->bits[3].name); |
| 1476 | assert_int_equal(7, ((struct lysc_type_bits*)type)->bits[3].position); |
| 1477 | assert_string_equal("eight", ((struct lysc_type_bits*)type)->bits[4].name); |
| 1478 | assert_int_equal(8, ((struct lysc_type_bits*)type)->bits[4].position); |
| 1479 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1480 | assert_non_null(mod = lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b;feature f; typedef mytype {type bits {" |
David Sedlák | 9fb515f | 2019-07-11 10:33:58 +0200 | [diff] [blame] | 1481 | "bit automin; bit one;bit two; bit seven {position 7;}bit eight;}} leaf l { type mytype {bit eight;bit seven;bit automin;}}}", |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1482 | LYS_IN_YANG)); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1483 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1484 | assert_non_null(type); |
| 1485 | assert_int_equal(LY_TYPE_BITS, type->basetype); |
| 1486 | assert_non_null(((struct lysc_type_bits*)type)->bits); |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1487 | assert_int_equal(3, LY_ARRAY_SIZE(((struct lysc_type_bits*)type)->bits)); |
| 1488 | assert_string_equal("automin", ((struct lysc_type_bits*)type)->bits[0].name); |
| 1489 | assert_int_equal(0, ((struct lysc_type_bits*)type)->bits[0].position); |
| 1490 | assert_string_equal("seven", ((struct lysc_type_bits*)type)->bits[1].name); |
| 1491 | assert_int_equal(7, ((struct lysc_type_bits*)type)->bits[1].position); |
| 1492 | assert_string_equal("eight", ((struct lysc_type_bits*)type)->bits[2].name); |
| 1493 | assert_int_equal(8, ((struct lysc_type_bits*)type)->bits[2].position); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1494 | |
| 1495 | |
| 1496 | /* invalid cases */ |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1497 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type bits {" |
| 1498 | "bit one {if-feature f;}}}}", LYS_IN_YANG)); |
| 1499 | logbuf_assert("Invalid keyword \"if-feature\" as a child of \"bit\" - the statement is allowed only in YANG 1.1 modules. Line number 1."); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1500 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {" |
| 1501 | "bit one {position -1;}}}}", LYS_IN_YANG)); |
| 1502 | logbuf_assert("Invalid value \"-1\" of \"position\". Line number 1."); |
| 1503 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {" |
David Sedlák | 9fb515f | 2019-07-11 10:33:58 +0200 | [diff] [blame] | 1504 | "bit one {position 4294967296;}}}}", LYS_IN_YANG)); |
| 1505 | logbuf_assert("Invalid value \"4294967296\" of \"position\". Line number 1."); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1506 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {" |
| 1507 | "bit one; bit one;}}}", LYS_IN_YANG)); |
| 1508 | logbuf_assert("Duplicate identifier \"one\" of bit statement. Line number 1."); |
| 1509 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {" |
| 1510 | "bit '11';}}}", LYS_IN_YANG)); |
| 1511 | logbuf_assert("Invalid identifier first character '1'. Line number 1."); |
| 1512 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {" |
| 1513 | "bit 'x1$1';}}}", LYS_IN_YANG)); |
| 1514 | logbuf_assert("Invalid identifier character '$'. Line number 1."); |
| 1515 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1516 | assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type bits;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1517 | logbuf_assert("Missing bit substatement for bits type. /bb:l"); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1518 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1519 | assert_null(lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;typedef mytype {type bits {bit one;}}" |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1520 | "leaf l {type mytype {bit two;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1521 | logbuf_assert("Invalid bits - derived type adds new item \"two\". /cc:l"); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1522 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1523 | assert_null(lys_parse_mem(ctx, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;typedef mytype {type bits {bit one;}}" |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1524 | "leaf l {type mytype {bit one {position 1;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1525 | logbuf_assert("Invalid bits - position of the item \"one\" has changed from 0 to 1 in the derived type. /dd:l"); |
| 1526 | assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type bits {bit x {position 4294967295;}bit y;}}}", LYS_IN_YANG)); |
| 1527 | logbuf_assert("Invalid bits - it is not possible to auto-assign bit position for \"y\" since the highest value is already 4294967295. /ee:l"); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1528 | |
David Sedlák | 9fb515f | 2019-07-11 10:33:58 +0200 | [diff] [blame] | 1529 | assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type bits {bit x {position 1;}bit y {position 1;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1530 | logbuf_assert("Invalid bits - position 1 collide in items \"y\" and \"x\". /ff:l"); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1531 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1532 | assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;typedef mytype {type bits;}" |
Radek Krejci | 04bc1e9 | 2018-11-14 14:28:13 +0100 | [diff] [blame] | 1533 | "leaf l {type mytype {bit one;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1534 | logbuf_assert("Missing bit substatement for bits type mytype. /gg:l"); |
Radek Krejci | 04bc1e9 | 2018-11-14 14:28:13 +0100 | [diff] [blame] | 1535 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1536 | assert_null(lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh; typedef mytype {type bits {bit one;}}" |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1537 | "leaf l {type mytype {bit one;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1538 | logbuf_assert("Bits type can be subtyped only in YANG 1.1 modules. /hh:l"); |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1539 | |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1540 | *state = NULL; |
| 1541 | ly_ctx_destroy(ctx, NULL); |
| 1542 | } |
| 1543 | |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 1544 | static void |
| 1545 | test_type_dec64(void **state) |
| 1546 | { |
| 1547 | *state = test_type_dec64; |
| 1548 | |
| 1549 | struct ly_ctx *ctx; |
| 1550 | struct lys_module *mod; |
| 1551 | struct lysc_type *type; |
| 1552 | |
| 1553 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 1554 | |
| 1555 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;leaf l {type decimal64 {" |
| 1556 | "fraction-digits 2;range min..max;}}}", LYS_IN_YANG)); |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 1557 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1558 | assert_non_null(type); |
| 1559 | assert_int_equal(LY_TYPE_DEC64, type->basetype); |
| 1560 | assert_int_equal(2, ((struct lysc_type_dec*)type)->fraction_digits); |
| 1561 | assert_non_null(((struct lysc_type_dec*)type)->range); |
| 1562 | assert_non_null(((struct lysc_type_dec*)type)->range->parts); |
| 1563 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_dec*)type)->range->parts)); |
| 1564 | assert_int_equal(INT64_C(-9223372036854775807) - INT64_C(1), ((struct lysc_type_dec*)type)->range->parts[0].min_64); |
| 1565 | assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_dec*)type)->range->parts[0].max_64); |
| 1566 | |
| 1567 | assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;typedef mytype {type decimal64 {" |
| 1568 | "fraction-digits 2;range '3.14 | 5.1 | 10';}}leaf l {type mytype;}}", LYS_IN_YANG)); |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 1569 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1570 | assert_non_null(type); |
| 1571 | assert_int_equal(LY_TYPE_DEC64, type->basetype); |
| 1572 | assert_int_equal(2, ((struct lysc_type_dec*)type)->fraction_digits); |
| 1573 | assert_non_null(((struct lysc_type_dec*)type)->range); |
| 1574 | assert_non_null(((struct lysc_type_dec*)type)->range->parts); |
| 1575 | assert_int_equal(3, LY_ARRAY_SIZE(((struct lysc_type_dec*)type)->range->parts)); |
| 1576 | assert_int_equal(314, ((struct lysc_type_dec*)type)->range->parts[0].min_64); |
| 1577 | assert_int_equal(314, ((struct lysc_type_dec*)type)->range->parts[0].max_64); |
| 1578 | assert_int_equal(510, ((struct lysc_type_dec*)type)->range->parts[1].min_64); |
| 1579 | assert_int_equal(510, ((struct lysc_type_dec*)type)->range->parts[1].max_64); |
| 1580 | assert_int_equal(1000, ((struct lysc_type_dec*)type)->range->parts[2].min_64); |
| 1581 | assert_int_equal(1000, ((struct lysc_type_dec*)type)->range->parts[2].max_64); |
| 1582 | |
Radek Krejci | 943177f | 2019-06-14 16:32:43 +0200 | [diff] [blame] | 1583 | assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;typedef mytype {type decimal64 {" |
| 1584 | "fraction-digits 2;range '1 .. 65535';}}leaf l {type mytype;}}", LYS_IN_YANG)); |
| 1585 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1586 | assert_int_equal(LY_TYPE_DEC64, type->basetype); |
| 1587 | assert_int_equal(2, ((struct lysc_type_dec*)type)->fraction_digits); |
| 1588 | assert_non_null(((struct lysc_type_dec*)type)->range); |
| 1589 | assert_non_null(((struct lysc_type_dec*)type)->range->parts); |
| 1590 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_dec*)type)->range->parts)); |
| 1591 | assert_int_equal(100, ((struct lysc_type_dec*)type)->range->parts[0].min_64); |
| 1592 | assert_int_equal(6553500, ((struct lysc_type_dec*)type)->range->parts[0].max_64); |
| 1593 | |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 1594 | /* invalid cases */ |
| 1595 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 0;}}}", LYS_IN_YANG)); |
| 1596 | logbuf_assert("Invalid value \"0\" of \"fraction-digits\". Line number 1."); |
| 1597 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits -1;}}}", LYS_IN_YANG)); |
| 1598 | logbuf_assert("Invalid value \"-1\" of \"fraction-digits\". Line number 1."); |
| 1599 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 19;}}}", LYS_IN_YANG)); |
| 1600 | logbuf_assert("Value \"19\" is out of \"fraction-digits\" bounds. Line number 1."); |
| 1601 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1602 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1603 | logbuf_assert("Missing fraction-digits substatement for decimal64 type. /aa:l"); |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 1604 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1605 | assert_null(lys_parse_mem(ctx, "module ab {namespace urn:ab;prefix ab; typedef mytype {type decimal64;}leaf l {type mytype;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1606 | logbuf_assert("Missing fraction-digits substatement for decimal64 type mytype. /ab:l"); |
Radek Krejci | 643c824 | 2018-11-15 17:51:11 +0100 | [diff] [blame] | 1607 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1608 | assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type decimal64 {fraction-digits 2;" |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 1609 | "range '3.142';}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1610 | logbuf_assert("Range boundary \"3.142\" of decimal64 type exceeds defined number (2) of fraction digits. /bb:l"); |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 1611 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1612 | assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; leaf l {type decimal64 {fraction-digits 2;" |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 1613 | "range '4 | 3.14';}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1614 | logbuf_assert("Invalid range restriction - values are not in ascending order (3.14). /cc:l"); |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 1615 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1616 | assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; typedef mytype {type decimal64 {fraction-digits 2;}}" |
Radek Krejci | 643c824 | 2018-11-15 17:51:11 +0100 | [diff] [blame] | 1617 | "leaf l {type mytype {fraction-digits 3;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1618 | logbuf_assert("Invalid fraction-digits substatement for type not directly derived from decimal64 built-in type. /dd:l"); |
Radek Krejci | 643c824 | 2018-11-15 17:51:11 +0100 | [diff] [blame] | 1619 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1620 | assert_null(lys_parse_mem(ctx, "module de {namespace urn:de;prefix de; typedef mytype {type decimal64 {fraction-digits 2;}}" |
Radek Krejci | 643c824 | 2018-11-15 17:51:11 +0100 | [diff] [blame] | 1621 | "typedef mytype2 {type mytype {fraction-digits 3;}}leaf l {type mytype2;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1622 | logbuf_assert("Invalid fraction-digits substatement for type \"mytype2\" not directly derived from decimal64 built-in type. /de:l"); |
Radek Krejci | 643c824 | 2018-11-15 17:51:11 +0100 | [diff] [blame] | 1623 | |
Radek Krejci | 943177f | 2019-06-14 16:32:43 +0200 | [diff] [blame] | 1624 | assert_null(lys_parse_mem(ctx, "module ee {namespace urn:c;prefix c;typedef mytype {type decimal64 {" |
| 1625 | "fraction-digits 18;range '-10 .. 0';}}leaf l {type mytype;}}", LYS_IN_YANG)); |
| 1626 | logbuf_assert("Invalid range restriction - invalid value \"-10000000000000000000\". /ee:l"); |
| 1627 | assert_null(lys_parse_mem(ctx, "module ee {namespace urn:c;prefix c;typedef mytype {type decimal64 {" |
| 1628 | "fraction-digits 18;range '0 .. 10';}}leaf l {type mytype;}}", LYS_IN_YANG)); |
| 1629 | logbuf_assert("Invalid range restriction - invalid value \"10000000000000000000\". /ee:l"); |
| 1630 | |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 1631 | *state = NULL; |
| 1632 | ly_ctx_destroy(ctx, NULL); |
| 1633 | } |
| 1634 | |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 1635 | static void |
| 1636 | test_type_instanceid(void **state) |
| 1637 | { |
| 1638 | *state = test_type_instanceid; |
| 1639 | |
| 1640 | struct ly_ctx *ctx; |
| 1641 | struct lys_module *mod; |
| 1642 | struct lysc_type *type; |
| 1643 | |
| 1644 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 1645 | |
| 1646 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;typedef mytype {type instance-identifier {require-instance false;}}" |
| 1647 | "leaf l1 {type instance-identifier {require-instance true;}}" |
| 1648 | "leaf l2 {type mytype;} leaf l3 {type instance-identifier;}}", LYS_IN_YANG)); |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 1649 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1650 | assert_non_null(type); |
| 1651 | assert_int_equal(LY_TYPE_INST, type->basetype); |
| 1652 | assert_int_equal(1, ((struct lysc_type_instanceid*)type)->require_instance); |
| 1653 | |
| 1654 | type = ((struct lysc_node_leaf*)mod->compiled->data->next)->type; |
| 1655 | assert_non_null(type); |
| 1656 | assert_int_equal(LY_TYPE_INST, type->basetype); |
| 1657 | assert_int_equal(0, ((struct lysc_type_instanceid*)type)->require_instance); |
| 1658 | |
| 1659 | type = ((struct lysc_node_leaf*)mod->compiled->data->next->next)->type; |
| 1660 | assert_non_null(type); |
| 1661 | assert_int_equal(LY_TYPE_INST, type->basetype); |
| 1662 | assert_int_equal(1, ((struct lysc_type_instanceid*)type)->require_instance); |
| 1663 | |
| 1664 | /* invalid cases */ |
| 1665 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {require-instance yes;}}}", LYS_IN_YANG)); |
| 1666 | logbuf_assert("Invalid value \"yes\" of \"require-instance\". Line number 1."); |
| 1667 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1668 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {fraction-digits 1;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1669 | logbuf_assert("Invalid type restrictions for instance-identifier type. /aa:l"); |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 1670 | |
| 1671 | *state = NULL; |
| 1672 | ly_ctx_destroy(ctx, NULL); |
| 1673 | } |
| 1674 | |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1675 | static void |
| 1676 | test_type_identityref(void **state) |
| 1677 | { |
| 1678 | *state = test_type_identityref; |
| 1679 | |
| 1680 | struct ly_ctx *ctx; |
| 1681 | struct lys_module *mod; |
| 1682 | struct lysc_type *type; |
| 1683 | |
| 1684 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 1685 | |
| 1686 | assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;identity i; identity j; identity k {base i;}" |
| 1687 | "typedef mytype {type identityref {base i;}}" |
Radek Krejci | b83ea3e | 2018-11-23 14:29:13 +0100 | [diff] [blame] | 1688 | "leaf l1 {type mytype;} leaf l2 {type identityref {base a:k; base j;}}}", LYS_IN_YANG)); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1689 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1690 | assert_non_null(type); |
| 1691 | assert_int_equal(LY_TYPE_IDENT, type->basetype); |
| 1692 | assert_non_null(((struct lysc_type_identityref*)type)->bases); |
| 1693 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_identityref*)type)->bases)); |
| 1694 | assert_string_equal("i", ((struct lysc_type_identityref*)type)->bases[0]->name); |
| 1695 | |
| 1696 | type = ((struct lysc_node_leaf*)mod->compiled->data->next)->type; |
| 1697 | assert_non_null(type); |
| 1698 | assert_int_equal(LY_TYPE_IDENT, type->basetype); |
| 1699 | assert_non_null(((struct lysc_type_identityref*)type)->bases); |
| 1700 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_identityref*)type)->bases)); |
| 1701 | assert_string_equal("k", ((struct lysc_type_identityref*)type)->bases[0]->name); |
| 1702 | assert_string_equal("j", ((struct lysc_type_identityref*)type)->bases[1]->name); |
| 1703 | |
Radek Krejci | b83ea3e | 2018-11-23 14:29:13 +0100 | [diff] [blame] | 1704 | assert_non_null(mod = lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b;import a {prefix a;}" |
| 1705 | "leaf l {type identityref {base a:k; base a:j;}}}", LYS_IN_YANG)); |
Radek Krejci | b83ea3e | 2018-11-23 14:29:13 +0100 | [diff] [blame] | 1706 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1707 | assert_non_null(type); |
| 1708 | assert_int_equal(LY_TYPE_IDENT, type->basetype); |
| 1709 | assert_non_null(((struct lysc_type_identityref*)type)->bases); |
| 1710 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_identityref*)type)->bases)); |
| 1711 | assert_string_equal("k", ((struct lysc_type_identityref*)type)->bases[0]->name); |
| 1712 | assert_string_equal("j", ((struct lysc_type_identityref*)type)->bases[1]->name); |
| 1713 | |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1714 | /* invalid cases */ |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1715 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type identityref;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1716 | logbuf_assert("Missing base substatement for identityref type. /aa:l"); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1717 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1718 | assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; typedef mytype {type identityref;}" |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1719 | "leaf l {type mytype;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1720 | logbuf_assert("Missing base substatement for identityref type mytype. /bb:l"); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1721 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1722 | assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; identity i; typedef mytype {type identityref {base i;}}" |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1723 | "leaf l {type mytype {base i;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1724 | logbuf_assert("Invalid base substatement for the type not directly derived from identityref built-in type. /cc:l"); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1725 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1726 | assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; identity i; typedef mytype {type identityref {base i;}}" |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1727 | "typedef mytype2 {type mytype {base i;}}leaf l {type mytype2;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1728 | logbuf_assert("Invalid base substatement for the type \"mytype2\" not directly derived from identityref built-in type. /dd:l"); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1729 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1730 | assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee; identity i; identity j;" |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1731 | "leaf l {type identityref {base i;base j;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1732 | logbuf_assert("Multiple bases in identityref type are allowed only in YANG 1.1 modules. /ee:l"); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1733 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1734 | assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff; identity i;leaf l {type identityref {base j;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1735 | logbuf_assert("Unable to find base (j) of identityref. /ff:l"); |
Radek Krejci | 322614f | 2018-11-16 15:05:44 +0100 | [diff] [blame] | 1736 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1737 | assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;leaf l {type identityref {base x:j;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1738 | logbuf_assert("Invalid prefix used for base (x:j) of identityref. /gg:l"); |
Radek Krejci | 322614f | 2018-11-16 15:05:44 +0100 | [diff] [blame] | 1739 | |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1740 | *state = NULL; |
| 1741 | ly_ctx_destroy(ctx, NULL); |
| 1742 | } |
| 1743 | |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1744 | static void |
| 1745 | test_type_leafref(void **state) |
| 1746 | { |
| 1747 | *state = test_type_leafref; |
| 1748 | |
| 1749 | struct ly_ctx *ctx; |
| 1750 | struct lys_module *mod; |
| 1751 | struct lysc_type *type; |
| 1752 | const char *path, *name, *prefix; |
| 1753 | size_t prefix_len, name_len; |
| 1754 | int parent_times, has_predicate; |
| 1755 | |
| 1756 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 1757 | |
| 1758 | /* lys_path_token() */ |
| 1759 | path = "invalid_path"; |
| 1760 | parent_times = 0; |
| 1761 | assert_int_equal(LY_EINVAL, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1762 | path = ".."; |
| 1763 | parent_times = 0; |
| 1764 | assert_int_equal(LY_EINVAL, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1765 | path = "..["; |
| 1766 | parent_times = 0; |
| 1767 | assert_int_equal(LY_EINVAL, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1768 | path = "../"; |
| 1769 | parent_times = 0; |
| 1770 | assert_int_equal(LY_EINVAL, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1771 | path = "/"; |
| 1772 | parent_times = 0; |
| 1773 | assert_int_equal(LY_EINVAL, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1774 | |
| 1775 | path = "../../pref:id/xxx[predicate]/invalid!!!"; |
| 1776 | parent_times = 0; |
| 1777 | assert_int_equal(LY_SUCCESS, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1778 | assert_string_equal("/xxx[predicate]/invalid!!!", path); |
| 1779 | assert_int_equal(4, prefix_len); |
| 1780 | assert_int_equal(0, strncmp("pref", prefix, prefix_len)); |
| 1781 | assert_int_equal(2, name_len); |
| 1782 | assert_int_equal(0, strncmp("id", name, name_len)); |
| 1783 | assert_int_equal(2, parent_times); |
| 1784 | assert_int_equal(0, has_predicate); |
| 1785 | assert_int_equal(LY_SUCCESS, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1786 | assert_string_equal("[predicate]/invalid!!!", path); |
| 1787 | assert_int_equal(0, prefix_len); |
| 1788 | assert_null(prefix); |
| 1789 | assert_int_equal(3, name_len); |
| 1790 | assert_int_equal(0, strncmp("xxx", name, name_len)); |
| 1791 | assert_int_equal(1, has_predicate); |
| 1792 | path += 11; |
| 1793 | assert_int_equal(LY_EINVAL, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1794 | assert_string_equal("!!!", path); |
| 1795 | assert_int_equal(0, prefix_len); |
| 1796 | assert_null(prefix); |
| 1797 | assert_int_equal(7, name_len); |
| 1798 | assert_int_equal(0, strncmp("invalid", name, name_len)); |
| 1799 | |
| 1800 | path = "/absolute/prefix:path"; |
| 1801 | parent_times = 0; |
| 1802 | assert_int_equal(LY_SUCCESS, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1803 | assert_string_equal("/prefix:path", path); |
| 1804 | assert_int_equal(0, prefix_len); |
| 1805 | assert_null(prefix); |
| 1806 | assert_int_equal(8, name_len); |
| 1807 | assert_int_equal(0, strncmp("absolute", name, name_len)); |
| 1808 | assert_int_equal(-1, parent_times); |
| 1809 | assert_int_equal(0, has_predicate); |
| 1810 | assert_int_equal(LY_SUCCESS, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1811 | assert_int_equal(0, *path); |
| 1812 | assert_int_equal(6, prefix_len); |
| 1813 | assert_int_equal(0, strncmp("prefix", prefix, prefix_len)); |
| 1814 | assert_int_equal(4, name_len); |
| 1815 | assert_int_equal(0, strncmp("path", name, name_len)); |
| 1816 | assert_int_equal(0, has_predicate); |
| 1817 | |
| 1818 | /* complete leafref paths */ |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1819 | assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;" |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1820 | "leaf ref1 {type leafref {path /a:target1;}} leaf ref2 {type leafref {path /a/target2; require-instance false;}}" |
| 1821 | "leaf target1 {type string;}container a {leaf target2 {type uint8;}}}", LYS_IN_YANG)); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1822 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1823 | assert_non_null(type); |
| 1824 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1825 | assert_string_equal("/a:target1", ((struct lysc_type_leafref*)type)->path); |
Radek Krejci | 96a0bfd | 2018-11-22 15:25:06 +0100 | [diff] [blame] | 1826 | assert_ptr_equal(mod, ((struct lysc_type_leafref*)type)->path_context); |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 1827 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 1828 | assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref*)type)->realtype->basetype); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1829 | assert_int_equal(1, ((struct lysc_type_leafref*)type)->require_instance); |
| 1830 | type = ((struct lysc_node_leaf*)mod->compiled->data->next)->type; |
| 1831 | assert_non_null(type); |
| 1832 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1833 | assert_string_equal("/a/target2", ((struct lysc_type_leafref*)type)->path); |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 1834 | assert_ptr_equal(mod, ((struct lysc_type_leafref*)type)->path_context); |
| 1835 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 1836 | assert_int_equal(LY_TYPE_UINT8, ((struct lysc_type_leafref*)type)->realtype->basetype); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1837 | assert_int_equal(0, ((struct lysc_type_leafref*)type)->require_instance); |
| 1838 | |
Radek Krejci | 96a0bfd | 2018-11-22 15:25:06 +0100 | [diff] [blame] | 1839 | assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; typedef mytype {type leafref {path /b:target;}}" |
Radek Krejci | 4ce6893 | 2018-11-28 12:53:36 +0100 | [diff] [blame] | 1840 | "typedef mytype2 {type mytype;} typedef mytype3 {type leafref {path /target;}} leaf ref {type mytype2;}" |
Radek Krejci | 6be5ff1 | 2018-11-26 13:18:15 +0100 | [diff] [blame] | 1841 | "leaf target {type leafref {path ../realtarget;}} leaf realtarget {type string;}}", LYS_IN_YANG)); |
Radek Krejci | 96a0bfd | 2018-11-22 15:25:06 +0100 | [diff] [blame] | 1842 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1843 | assert_non_null(type); |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 1844 | assert_int_equal(1, type->refcount); |
Radek Krejci | 96a0bfd | 2018-11-22 15:25:06 +0100 | [diff] [blame] | 1845 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1846 | assert_string_equal("/b:target", ((struct lysc_type_leafref* )type)->path); |
| 1847 | assert_ptr_equal(mod, ((struct lysc_type_leafref*)type)->path_context); |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 1848 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 1849 | assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref*)type)->realtype->basetype); |
Radek Krejci | 96a0bfd | 2018-11-22 15:25:06 +0100 | [diff] [blame] | 1850 | assert_int_equal(1, ((struct lysc_type_leafref* )type)->require_instance); |
| 1851 | |
| 1852 | /* prefixes are reversed to check using correct context of the path! */ |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1853 | assert_non_null(mod = lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix b; import b {prefix c;}" |
Radek Krejci | 2f4a029 | 2018-11-22 15:41:53 +0100 | [diff] [blame] | 1854 | "typedef mytype3 {type c:mytype {require-instance false;}}" |
| 1855 | "leaf ref1 {type b:mytype3;}leaf ref2 {type c:mytype2;}}", LYS_IN_YANG)); |
Radek Krejci | 96a0bfd | 2018-11-22 15:25:06 +0100 | [diff] [blame] | 1856 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1857 | assert_non_null(type); |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 1858 | assert_int_equal(1, type->refcount); |
Radek Krejci | 2f4a029 | 2018-11-22 15:41:53 +0100 | [diff] [blame] | 1859 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1860 | assert_string_equal("/b:target", ((struct lysc_type_leafref* )type)->path); |
| 1861 | assert_ptr_not_equal(mod, ((struct lysc_type_leafref*)type)->path_context); |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 1862 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 1863 | assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref*)type)->realtype->basetype); |
Radek Krejci | 2f4a029 | 2018-11-22 15:41:53 +0100 | [diff] [blame] | 1864 | assert_int_equal(0, ((struct lysc_type_leafref* )type)->require_instance); |
| 1865 | type = ((struct lysc_node_leaf*)mod->compiled->data->next)->type; |
| 1866 | assert_non_null(type); |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 1867 | assert_int_equal(1, type->refcount); |
Radek Krejci | 96a0bfd | 2018-11-22 15:25:06 +0100 | [diff] [blame] | 1868 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1869 | assert_string_equal("/b:target", ((struct lysc_type_leafref* )type)->path); |
| 1870 | assert_ptr_not_equal(mod, ((struct lysc_type_leafref*)type)->path_context); |
| 1871 | assert_int_equal(1, ((struct lysc_type_leafref* )type)->require_instance); |
| 1872 | |
Radek Krejci | 4ce6893 | 2018-11-28 12:53:36 +0100 | [diff] [blame] | 1873 | /* non-prefixed nodes in path are supposed to be from the module where the leafref type is instantiated */ |
| 1874 | assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; import b {prefix b;}" |
| 1875 | "leaf ref {type b:mytype3;}leaf target {type int8;}}", LYS_IN_YANG)); |
Radek Krejci | 4ce6893 | 2018-11-28 12:53:36 +0100 | [diff] [blame] | 1876 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1877 | assert_non_null(type); |
| 1878 | assert_int_equal(1, type->refcount); |
| 1879 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1880 | assert_string_equal("/target", ((struct lysc_type_leafref* )type)->path); |
| 1881 | assert_ptr_not_equal(mod, ((struct lysc_type_leafref*)type)->path_context); |
| 1882 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 1883 | assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref*)type)->realtype->basetype); |
| 1884 | assert_int_equal(1, ((struct lysc_type_leafref* )type)->require_instance); |
| 1885 | |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 1886 | /* conditional leafrefs */ |
Radek Krejci | 4ce6893 | 2018-11-28 12:53:36 +0100 | [diff] [blame] | 1887 | assert_non_null(mod = lys_parse_mem(ctx, "module e {yang-version 1.1;namespace urn:e;prefix e;feature f1; feature f2;" |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 1888 | "leaf ref1 {if-feature 'f1 and f2';type leafref {path /target;}}" |
| 1889 | "leaf target {if-feature f1; type boolean;}}", LYS_IN_YANG)); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 1890 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1891 | assert_non_null(type); |
| 1892 | assert_int_equal(1, type->refcount); |
| 1893 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1894 | assert_string_equal("/target", ((struct lysc_type_leafref* )type)->path); |
| 1895 | assert_ptr_equal(mod, ((struct lysc_type_leafref*)type)->path_context); |
| 1896 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 1897 | assert_int_equal(LY_TYPE_BOOL, ((struct lysc_type_leafref*)type)->realtype->basetype); |
| 1898 | |
Radek Krejci | 7adf4ff | 2018-12-05 08:55:00 +0100 | [diff] [blame] | 1899 | assert_non_null(mod = lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;" |
| 1900 | "list interface{key name;leaf name{type string;}list address {key ip;leaf ip {type string;}}}" |
| 1901 | "container default-address{leaf ifname{type leafref{ path \"../../interface/name\";}}" |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 1902 | "leaf address {type leafref{ path \"../../interface[ name = current()/../ifname ]/address/ip\";}}}}", |
Radek Krejci | 7adf4ff | 2018-12-05 08:55:00 +0100 | [diff] [blame] | 1903 | LYS_IN_YANG)); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 1904 | type = ((struct lysc_node_leaf*)(*lysc_node_children_p(mod->compiled->data->prev, 0))->prev)->type; |
Radek Krejci | 7adf4ff | 2018-12-05 08:55:00 +0100 | [diff] [blame] | 1905 | assert_non_null(type); |
| 1906 | assert_int_equal(1, type->refcount); |
| 1907 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 1908 | assert_string_equal("../../interface[ name = current()/../ifname ]/address/ip", ((struct lysc_type_leafref* )type)->path); |
Radek Krejci | 7adf4ff | 2018-12-05 08:55:00 +0100 | [diff] [blame] | 1909 | assert_ptr_equal(mod, ((struct lysc_type_leafref*)type)->path_context); |
| 1910 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 1911 | assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref*)type)->realtype->basetype); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1912 | |
Radek Krejci | 20e8a18 | 2018-12-07 11:43:21 +0100 | [diff] [blame] | 1913 | assert_non_null(mod = lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;" |
| 1914 | "leaf source {type leafref {path \"/endpoint-parent[id=current()/../field]/endpoint/name\";}}" |
| 1915 | "leaf field {type int32;}list endpoint-parent {key id;leaf id {type int32;}" |
| 1916 | "list endpoint {key name;leaf name {type string;}}}}", LYS_IN_YANG)); |
Radek Krejci | 20e8a18 | 2018-12-07 11:43:21 +0100 | [diff] [blame] | 1917 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1918 | assert_non_null(type); |
| 1919 | assert_int_equal(1, type->refcount); |
| 1920 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1921 | assert_string_equal("/endpoint-parent[id=current()/../field]/endpoint/name", ((struct lysc_type_leafref* )type)->path); |
| 1922 | assert_ptr_equal(mod, ((struct lysc_type_leafref*)type)->path_context); |
| 1923 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 1924 | assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref*)type)->realtype->basetype); |
| 1925 | |
Radek Krejci | 3d92956 | 2019-02-21 11:25:55 +0100 | [diff] [blame] | 1926 | /* leafref to imported (not yet implemented) module */ |
| 1927 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module h {namespace urn:h;prefix h; leaf h {type uint16;}}"); |
| 1928 | assert_non_null(mod = lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;import h {prefix h;}" |
| 1929 | "leaf i {type leafref {path /h:h;}}}", LYS_IN_YANG)); |
| 1930 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1931 | assert_non_null(type); |
| 1932 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1933 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 1934 | assert_int_equal(LY_TYPE_UINT16, ((struct lysc_type_leafref*)type)->realtype->basetype); |
| 1935 | assert_non_null(mod = ly_ctx_get_module_implemented(ctx, "h")); |
| 1936 | assert_int_equal(1, mod->implemented); |
| 1937 | assert_non_null(mod->compiled->data); |
| 1938 | assert_string_equal("h", mod->compiled->data->name); |
| 1939 | |
Radek Krejci | 92cc851 | 2019-04-25 09:57:06 +0200 | [diff] [blame] | 1940 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module j {namespace urn:j;prefix j; leaf j {type string;}}"); |
| 1941 | assert_non_null(mod = lys_parse_mem(ctx, "module k {namespace urn:k;prefix k;import j {prefix j;}" |
| 1942 | "leaf i {type leafref {path \"/ilist[name = current()/../j:j]/value\";}}" |
| 1943 | "list ilist {key name; leaf name {type string;} leaf value {type uint16;}}}", LYS_IN_YANG)); |
| 1944 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1945 | assert_non_null(type); |
| 1946 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1947 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 1948 | assert_int_equal(LY_TYPE_UINT16, ((struct lysc_type_leafref*)type)->realtype->basetype); |
| 1949 | assert_non_null(mod = ly_ctx_get_module_implemented(ctx, "j")); |
| 1950 | assert_int_equal(1, mod->implemented); |
| 1951 | assert_non_null(mod->compiled->data); |
| 1952 | assert_string_equal("j", mod->compiled->data->name); |
| 1953 | |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1954 | /* invalid paths */ |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1955 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;container a {leaf target2 {type uint8;}}" |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1956 | "leaf ref1 {type leafref {path ../a/invalid;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1957 | logbuf_assert("Invalid leafref path - unable to find \"../a/invalid\". /aa:ref1"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1958 | assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;container a {leaf target2 {type uint8;}}" |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1959 | "leaf ref1 {type leafref {path ../../toohigh;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1960 | logbuf_assert("Invalid leafref path \"../../toohigh\" - too many \"..\" in the path. /bb:ref1"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1961 | assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;container a {leaf target2 {type uint8;}}" |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1962 | "leaf ref1 {type leafref {path /a:invalid;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1963 | logbuf_assert("Invalid leafref path - unable to find module connected with the prefix of the node \"/a:invalid\". /cc:ref1"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1964 | assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;leaf target1 {type string;}container a {leaf target2 {type uint8;}}" |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1965 | "leaf ref1 {type leafref {path '/a[target2 = current()/../target1]/target2';}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1966 | logbuf_assert("Invalid leafref path - node \"/a\" is expected to be a list, but it is container. /dd:ref1"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1967 | assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;container a {leaf target2 {type uint8;}}" |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1968 | "leaf ref1 {type leafref {path /a!invalid;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1969 | logbuf_assert("Invalid leafref path at character 3 (/a!invalid). /ee:ref1"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1970 | assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;container a {leaf target2 {type uint8;}}" |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1971 | "leaf ref1 {type leafref {path /a;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1972 | logbuf_assert("Invalid leafref path \"/a\" - target node is container instead of leaf or leaf-list. /ff:ref1"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1973 | assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;container a {leaf target2 {type uint8; status deprecated;}}" |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1974 | "leaf ref1 {type leafref {path /a/target2;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1975 | logbuf_assert("A current definition \"ref1\" is not allowed to reference deprecated definition \"target2\". /gg:ref1"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1976 | assert_null(lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;" |
Radek Krejci | 2f4a029 | 2018-11-22 15:41:53 +0100 | [diff] [blame] | 1977 | "leaf ref1 {type leafref;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1978 | logbuf_assert("Missing path substatement for leafref type. /hh:ref1"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1979 | assert_null(lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;typedef mytype {type leafref;}" |
Radek Krejci | 2f4a029 | 2018-11-22 15:41:53 +0100 | [diff] [blame] | 1980 | "leaf ref1 {type mytype;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1981 | logbuf_assert("Missing path substatement for leafref type mytype. /ii:ref1"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1982 | assert_null(lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;feature f;" |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 1983 | "leaf ref {type leafref {path /target;}}leaf target {if-feature f;type string;}}", LYS_IN_YANG)); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 1984 | logbuf_assert("Invalid leafref path \"/target\" - set of features applicable to the leafref target is not a subset of features " |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1985 | "applicable to the leafref itself. /jj:ref"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1986 | assert_null(lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;" |
Radek Krejci | b57cf1e | 2018-11-23 14:07:05 +0100 | [diff] [blame] | 1987 | "leaf ref {type leafref {path /target;}}leaf target {type string;config false;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1988 | logbuf_assert("Invalid leafref path \"/target\" - target is supposed to represent configuration data (as the leafref does), but it does not. /kk:ref"); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 1989 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1990 | assert_null(lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;" |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1991 | "leaf ref {type leafref {path /target; require-instance true;}}leaf target {type string;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1992 | logbuf_assert("Leafref type can be restricted by require-instance statement only in YANG 1.1 modules. /ll:ref"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1993 | assert_null(lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;typedef mytype {type leafref {path /target;require-instance false;}}" |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1994 | "leaf ref {type mytype;}leaf target {type string;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 1995 | logbuf_assert("Leafref type \"mytype\" can be restricted by require-instance statement only in YANG 1.1 modules. /mm:ref"); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1996 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 1997 | assert_null(lys_parse_mem(ctx, "module nn {namespace urn:nn;prefix nn;" |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 1998 | "list interface{key name;leaf name{type string;}leaf ip {type string;}}" |
| 1999 | "leaf ifname{type leafref{ path \"../interface/name\";}}" |
| 2000 | "leaf address {type leafref{ path \"/interface[name is current()/../ifname]/ip\";}}}", |
| 2001 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2002 | logbuf_assert("Invalid leafref path predicate \"[name i\" - missing \"=\" after node-identifier. /nn:address"); |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2003 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2004 | assert_null(lys_parse_mem(ctx, "module oo {namespace urn:oo;prefix oo;" |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2005 | "list interface{key name;leaf name{type string;}leaf ip {type string;}}" |
| 2006 | "leaf ifname{type leafref{ path \"../interface/name\";}}" |
| 2007 | "leaf address {type leafref{ path \"/interface[name=current()/../ifname/ip\";}}}", |
| 2008 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2009 | logbuf_assert("Invalid leafref path predicate \"[name=current()/../ifname/ip\" - missing predicate termination. /oo:address"); |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2010 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2011 | assert_null(lys_parse_mem(ctx, "module pp {namespace urn:pp;prefix pp;" |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2012 | "list interface{key name;leaf name{type string;}leaf ip {type string;}}" |
| 2013 | "leaf ifname{type leafref{ path \"../interface/name\";}}" |
| 2014 | "leaf address {type leafref{ path \"/interface[x:name=current()/../ifname]/ip\";}}}", |
| 2015 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2016 | logbuf_assert("Invalid leafref path predicate \"[x:name=current()/../ifname]\" - prefix \"x\" not defined in module \"pp\". /pp:address"); |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2017 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2018 | assert_null(lys_parse_mem(ctx, "module qq {namespace urn:qq;prefix qq;" |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2019 | "list interface{key name;leaf name{type string;}leaf ip {type string;}}" |
| 2020 | "leaf ifname{type leafref{ path \"../interface/name\";}}" |
| 2021 | "leaf address {type leafref{ path \"/interface[id=current()/../ifname]/ip\";}}}", |
| 2022 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2023 | logbuf_assert("Invalid leafref path predicate \"[id=current()/../ifname]\" - predicate's key node \"id\" not found. /qq:address"); |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2024 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2025 | assert_null(lys_parse_mem(ctx, "module rr {namespace urn:rr;prefix rr;" |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2026 | "list interface{key name;leaf name{type string;}leaf ip {type string;}}" |
| 2027 | "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}" |
| 2028 | "leaf address {type leafref{ path \"/interface[name=current() / .. / ifname][name=current()/../test]/ip\";}}}", |
| 2029 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2030 | logbuf_assert("Invalid leafref path predicate \"[name=current()/../test]\" - multiple equality tests for the key \"name\". /rr:address"); |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2031 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2032 | assert_null(lys_parse_mem(ctx, "module ss {namespace urn:ss;prefix ss;" |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2033 | "list interface{key name;leaf name{type string;}leaf ip {type string;}}" |
| 2034 | "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}" |
| 2035 | "leaf address {type leafref{ path \"/interface[name = ../ifname]/ip\";}}}", |
| 2036 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2037 | logbuf_assert("Invalid leafref path predicate \"[name = ../ifname]\" - missing current-function-invocation. /ss:address"); |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2038 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2039 | assert_null(lys_parse_mem(ctx, "module tt {namespace urn:tt;prefix tt;" |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2040 | "list interface{key name;leaf name{type string;}leaf ip {type string;}}" |
| 2041 | "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}" |
| 2042 | "leaf address {type leafref{ path \"/interface[name = current()../ifname]/ip\";}}}", |
| 2043 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2044 | logbuf_assert("Invalid leafref path predicate \"[name = current()../ifname]\" - missing \"/\" after current-function-invocation. /tt:address"); |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2045 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2046 | assert_null(lys_parse_mem(ctx, "module uu {namespace urn:uu;prefix uu;" |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2047 | "list interface{key name;leaf name{type string;}leaf ip {type string;}}" |
| 2048 | "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}" |
| 2049 | "leaf address {type leafref{ path \"/interface[name = current()/..ifname]/ip\";}}}", |
| 2050 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2051 | logbuf_assert("Invalid leafref path predicate \"[name = current()/..ifname]\" - missing \"/\" in \"../\" rel-path-keyexpr pattern. /uu:address"); |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2052 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2053 | assert_null(lys_parse_mem(ctx, "module vv {namespace urn:vv;prefix vv;" |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2054 | "list interface{key name;leaf name{type string;}leaf ip {type string;}}" |
| 2055 | "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}" |
| 2056 | "leaf address {type leafref{ path \"/interface[name = current()/ifname]/ip\";}}}", |
| 2057 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2058 | logbuf_assert("Invalid leafref path predicate \"[name = current()/ifname]\" - at least one \"..\" is expected in rel-path-keyexpr. /vv:address"); |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2059 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2060 | assert_null(lys_parse_mem(ctx, "module ww {namespace urn:ww;prefix ww;" |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2061 | "list interface{key name;leaf name{type string;}leaf ip {type string;}}" |
| 2062 | "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}" |
| 2063 | "leaf address {type leafref{ path \"/interface[name = current()/../]/ip\";}}}", |
| 2064 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2065 | logbuf_assert("Invalid leafref path predicate \"[name = current()/../]\" - at least one node-identifier is expected in rel-path-keyexpr. /ww:address"); |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2066 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2067 | assert_null(lys_parse_mem(ctx, "module xx {namespace urn:xx;prefix xx;" |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2068 | "list interface{key name;leaf name{type string;}leaf ip {type string;}}" |
| 2069 | "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}" |
| 2070 | "leaf address {type leafref{ path \"/interface[name = current()/../$node]/ip\";}}}", |
| 2071 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2072 | logbuf_assert("Invalid node identifier in leafref path predicate - character 22 (of [name = current()/../$node]). /xx:address"); |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2073 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2074 | assert_null(lys_parse_mem(ctx, "module yy {namespace urn:yy;prefix yy;" |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2075 | "list interface{key name;leaf name{type string;}leaf ip {type string;}}" |
| 2076 | "leaf ifname{type leafref{ path \"../interface/name\";}}" |
| 2077 | "leaf address {type leafref{ path \"/interface[name=current()/../x:ifname]/ip\";}}}", |
| 2078 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2079 | logbuf_assert("Invalid leafref path predicate \"[name=current()/../x:ifname]\" - unable to find module of the node \"ifname\" in rel-path-keyexpr. /yy:address"); |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2080 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2081 | assert_null(lys_parse_mem(ctx, "module zz {namespace urn:zz;prefix zz;" |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2082 | "list interface{key name;leaf name{type string;}leaf ip {type string;}}" |
| 2083 | "leaf ifname{type leafref{ path \"../interface/name\";}}" |
| 2084 | "leaf address {type leafref{ path \"/interface[name=current()/../xxx]/ip\";}}}", |
| 2085 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2086 | logbuf_assert("Invalid leafref path predicate \"[name=current()/../xxx]\" - unable to find node \"current()/../xxx\" in the rel-path-keyexpr. /zz:address"); |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2087 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2088 | assert_null(lys_parse_mem(ctx, "module zza {namespace urn:zza;prefix zza;" |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2089 | "list interface{key name;leaf name{type string;}leaf ip {type string;}}" |
| 2090 | "leaf ifname{type leafref{ path \"../interface/name\";}}container c;" |
| 2091 | "leaf address {type leafref{ path \"/interface[name=current()/../c]/ip\";}}}", |
| 2092 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2093 | logbuf_assert("Invalid leafref path predicate \"[name=current()/../c]\" - rel-path-keyexpr \"current()/../c\" refers container instead of leaf. /zza:address"); |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2094 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2095 | assert_null(lys_parse_mem(ctx, "module zzb {namespace urn:zzb;prefix zzb;" |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2096 | "list interface{key name;leaf name{type string;}leaf ip {type string;}container c;}" |
| 2097 | "leaf ifname{type leafref{ path \"../interface/name\";}}" |
| 2098 | "leaf address {type leafref{ path \"/interface[c=current()/../ifname]/ip\";}}}", |
| 2099 | LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2100 | logbuf_assert("Invalid leafref path predicate \"[c=current()/../ifname]\" - predicate's key node \"c\" not found. /zzb:address"); |
Radek Krejci | bade82a | 2018-12-05 10:13:48 +0100 | [diff] [blame] | 2101 | |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 2102 | /* circular chain */ |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2103 | assert_null(lys_parse_mem(ctx, "module aaa {namespace urn:aaa;prefix aaa;" |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 2104 | "leaf ref1 {type leafref {path /ref2;}}" |
| 2105 | "leaf ref2 {type leafref {path /ref3;}}" |
Radek Krejci | 0c3f1ad | 2018-11-23 14:19:38 +0100 | [diff] [blame] | 2106 | "leaf ref3 {type leafref {path /ref4;}}" |
| 2107 | "leaf ref4 {type leafref {path /ref1;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2108 | logbuf_assert("Invalid leafref path \"/ref1\" - circular chain of leafrefs detected. /aaa:ref4"); |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 2109 | |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 2110 | *state = NULL; |
| 2111 | ly_ctx_destroy(ctx, NULL); |
| 2112 | } |
| 2113 | |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 2114 | static void |
| 2115 | test_type_empty(void **state) |
| 2116 | { |
| 2117 | *state = test_type_empty; |
| 2118 | |
| 2119 | struct ly_ctx *ctx; |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 2120 | |
| 2121 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 2122 | |
| 2123 | /* invalid */ |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2124 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;" |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 2125 | "leaf l {type empty; default x;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2126 | logbuf_assert("Leaf of type \"empty\" must not have a default value (x). /aa:l"); |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 2127 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2128 | assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;typedef mytype {type empty; default x;}" |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 2129 | "leaf l {type mytype;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2130 | logbuf_assert("Invalid type \"mytype\" - \"empty\" type must not have a default value (x). /bb:l"); |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 2131 | |
| 2132 | *state = NULL; |
| 2133 | ly_ctx_destroy(ctx, NULL); |
| 2134 | } |
| 2135 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 2136 | |
| 2137 | static void |
| 2138 | test_type_union(void **state) |
| 2139 | { |
| 2140 | *state = test_type_union; |
| 2141 | |
| 2142 | struct ly_ctx *ctx; |
| 2143 | struct lys_module *mod; |
| 2144 | struct lysc_type *type; |
| 2145 | |
| 2146 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 2147 | |
| 2148 | assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a; typedef mybasetype {type string;}" |
| 2149 | "typedef mytype {type union {type int8; type mybasetype;}}" |
| 2150 | "leaf l {type mytype;}}", LYS_IN_YANG)); |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 2151 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 2152 | assert_non_null(type); |
| 2153 | assert_int_equal(2, type->refcount); |
| 2154 | assert_int_equal(LY_TYPE_UNION, type->basetype); |
| 2155 | assert_non_null(((struct lysc_type_union*)type)->types); |
| 2156 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_union*)type)->types)); |
| 2157 | assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_union*)type)->types[0]->basetype); |
| 2158 | assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union*)type)->types[1]->basetype); |
| 2159 | |
| 2160 | assert_non_null(mod = lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b; typedef mybasetype {type string;}" |
| 2161 | "typedef mytype {type union {type int8; type mybasetype;}}" |
| 2162 | "leaf l {type union {type decimal64 {fraction-digits 2;} type mytype;}}}", LYS_IN_YANG)); |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 2163 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 2164 | assert_non_null(type); |
| 2165 | assert_int_equal(1, type->refcount); |
| 2166 | assert_int_equal(LY_TYPE_UNION, type->basetype); |
| 2167 | assert_non_null(((struct lysc_type_union*)type)->types); |
| 2168 | assert_int_equal(3, LY_ARRAY_SIZE(((struct lysc_type_union*)type)->types)); |
| 2169 | assert_int_equal(LY_TYPE_DEC64, ((struct lysc_type_union*)type)->types[0]->basetype); |
| 2170 | assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_union*)type)->types[1]->basetype); |
| 2171 | assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union*)type)->types[2]->basetype); |
| 2172 | |
| 2173 | assert_non_null(mod = lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c; typedef mybasetype {type string;}" |
| 2174 | "typedef mytype {type union {type leafref {path ../target;} type mybasetype;}}" |
Radek Krejci | 6be5ff1 | 2018-11-26 13:18:15 +0100 | [diff] [blame] | 2175 | "leaf l {type union {type decimal64 {fraction-digits 2;} type mytype;}}" |
| 2176 | "leaf target {type leafref {path ../realtarget;}} leaf realtarget {type int8;}}", |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 2177 | LYS_IN_YANG)); |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 2178 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 2179 | assert_non_null(type); |
| 2180 | assert_int_equal(1, type->refcount); |
| 2181 | assert_int_equal(LY_TYPE_UNION, type->basetype); |
| 2182 | assert_non_null(((struct lysc_type_union*)type)->types); |
| 2183 | assert_int_equal(3, LY_ARRAY_SIZE(((struct lysc_type_union*)type)->types)); |
| 2184 | assert_int_equal(LY_TYPE_DEC64, ((struct lysc_type_union*)type)->types[0]->basetype); |
| 2185 | assert_int_equal(LY_TYPE_LEAFREF, ((struct lysc_type_union*)type)->types[1]->basetype); |
| 2186 | assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union*)type)->types[2]->basetype); |
| 2187 | assert_non_null(((struct lysc_type_leafref*)((struct lysc_type_union*)type)->types[1])->realtype); |
| 2188 | assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref*)((struct lysc_type_union*)type)->types[1])->realtype->basetype); |
| 2189 | |
Radek Krejci | 6be5ff1 | 2018-11-26 13:18:15 +0100 | [diff] [blame] | 2190 | /* invalid unions */ |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2191 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;typedef mytype {type union;}" |
Radek Krejci | 6be5ff1 | 2018-11-26 13:18:15 +0100 | [diff] [blame] | 2192 | "leaf l {type mytype;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2193 | logbuf_assert("Missing type substatement for union type mytype. /aa:l"); |
Radek Krejci | 6be5ff1 | 2018-11-26 13:18:15 +0100 | [diff] [blame] | 2194 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2195 | assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf l {type union;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2196 | logbuf_assert("Missing type substatement for union type. /bb:l"); |
Radek Krejci | 6be5ff1 | 2018-11-26 13:18:15 +0100 | [diff] [blame] | 2197 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2198 | assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;typedef mytype {type union{type int8; type string;}}" |
Radek Krejci | 6be5ff1 | 2018-11-26 13:18:15 +0100 | [diff] [blame] | 2199 | "leaf l {type mytype {type string;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2200 | logbuf_assert("Invalid type substatement for the type not directly derived from union built-in type. /cc:l"); |
Radek Krejci | 6be5ff1 | 2018-11-26 13:18:15 +0100 | [diff] [blame] | 2201 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2202 | assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;typedef mytype {type union{type int8; type string;}}" |
Radek Krejci | 6be5ff1 | 2018-11-26 13:18:15 +0100 | [diff] [blame] | 2203 | "typedef mytype2 {type mytype {type string;}}leaf l {type mytype2;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2204 | logbuf_assert("Invalid type substatement for the type \"mytype2\" not directly derived from union built-in type. /dd:l"); |
Radek Krejci | 6be5ff1 | 2018-11-26 13:18:15 +0100 | [diff] [blame] | 2205 | |
Radek Krejci | 99b5b2a | 2019-04-30 16:57:04 +0200 | [diff] [blame] | 2206 | assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;typedef mytype {type union{type mytype; type string;}}" |
| 2207 | "leaf l {type mytype;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2208 | logbuf_assert("Invalid \"mytype\" type reference - circular chain of types detected. /ee:l"); |
Radek Krejci | 99b5b2a | 2019-04-30 16:57:04 +0200 | [diff] [blame] | 2209 | assert_null(lys_parse_mem(ctx, "module ef {namespace urn:ef;prefix ef;typedef mytype {type mytype2;}" |
| 2210 | "typedef mytype2 {type mytype;} leaf l {type mytype;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2211 | logbuf_assert("Invalid \"mytype\" type reference - circular chain of types detected. /ef:l"); |
Radek Krejci | 99b5b2a | 2019-04-30 16:57:04 +0200 | [diff] [blame] | 2212 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 2213 | *state = NULL; |
| 2214 | ly_ctx_destroy(ctx, NULL); |
| 2215 | } |
| 2216 | |
| 2217 | static void |
| 2218 | test_type_dflt(void **state) |
| 2219 | { |
| 2220 | *state = test_type_union; |
| 2221 | |
| 2222 | struct ly_ctx *ctx; |
| 2223 | struct lys_module *mod; |
| 2224 | struct lysc_type *type; |
| 2225 | |
| 2226 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 2227 | |
| 2228 | /* default is not inherited from union's types */ |
| 2229 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a; typedef mybasetype {type string;default hello;units xxx;}" |
| 2230 | "leaf l {type union {type decimal64 {fraction-digits 2;} type mybasetype;}}}", LYS_IN_YANG)); |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 2231 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 2232 | assert_non_null(type); |
| 2233 | assert_int_equal(1, type->refcount); |
| 2234 | assert_int_equal(LY_TYPE_UNION, type->basetype); |
| 2235 | assert_non_null(((struct lysc_type_union*)type)->types); |
| 2236 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_union*)type)->types)); |
| 2237 | assert_int_equal(LY_TYPE_DEC64, ((struct lysc_type_union*)type)->types[0]->basetype); |
| 2238 | assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union*)type)->types[1]->basetype); |
| 2239 | assert_null(((struct lysc_node_leaf*)mod->compiled->data)->dflt); |
| 2240 | assert_null(((struct lysc_node_leaf*)mod->compiled->data)->units); |
| 2241 | |
| 2242 | assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; typedef mybasetype {type string;default hello;units xxx;}" |
| 2243 | "leaf l {type mybasetype;}}", LYS_IN_YANG)); |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 2244 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 2245 | assert_non_null(type); |
| 2246 | assert_int_equal(2, type->refcount); |
| 2247 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 2248 | assert_string_equal("hello", ((struct lysc_node_leaf*)mod->compiled->data)->dflt); |
| 2249 | assert_string_equal("xxx", ((struct lysc_node_leaf*)mod->compiled->data)->units); |
| 2250 | |
| 2251 | assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:c;prefix c; typedef mybasetype {type string;default hello;units xxx;}" |
| 2252 | "leaf l {type mybasetype; default goodbye;units yyy;}}", LYS_IN_YANG)); |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 2253 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 2254 | assert_non_null(type); |
| 2255 | assert_int_equal(2, type->refcount); |
| 2256 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 2257 | assert_string_equal("goodbye", ((struct lysc_node_leaf*)mod->compiled->data)->dflt); |
| 2258 | assert_string_equal("yyy", ((struct lysc_node_leaf*)mod->compiled->data)->units); |
| 2259 | |
Radek Krejci | 6be5ff1 | 2018-11-26 13:18:15 +0100 | [diff] [blame] | 2260 | assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; typedef mybasetype {type string;default hello;units xxx;}" |
| 2261 | "typedef mytype {type mybasetype;}leaf l1 {type mytype; default goodbye;units yyy;}" |
| 2262 | "leaf l2 {type mytype;}}", LYS_IN_YANG)); |
Radek Krejci | 6be5ff1 | 2018-11-26 13:18:15 +0100 | [diff] [blame] | 2263 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 2264 | assert_non_null(type); |
| 2265 | assert_int_equal(4, type->refcount); |
| 2266 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 2267 | assert_string_equal("goodbye", ((struct lysc_node_leaf*)mod->compiled->data)->dflt); |
| 2268 | assert_string_equal("yyy", ((struct lysc_node_leaf*)mod->compiled->data)->units); |
| 2269 | type = ((struct lysc_node_leaf*)mod->compiled->data->next)->type; |
| 2270 | assert_non_null(type); |
| 2271 | assert_int_equal(4, type->refcount); |
| 2272 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 2273 | assert_string_equal("hello", ((struct lysc_node_leaf*)mod->compiled->data->next)->dflt); |
| 2274 | assert_string_equal("xxx", ((struct lysc_node_leaf*)mod->compiled->data->next)->units); |
| 2275 | |
| 2276 | assert_non_null(mod = lys_parse_mem(ctx, "module e {namespace urn:e;prefix e; typedef mybasetype {type string;}" |
| 2277 | "typedef mytype {type mybasetype; default hello;units xxx;}leaf l {type mytype;}}", LYS_IN_YANG)); |
Radek Krejci | 6be5ff1 | 2018-11-26 13:18:15 +0100 | [diff] [blame] | 2278 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 2279 | assert_non_null(type); |
| 2280 | assert_int_equal(3, type->refcount); |
| 2281 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 2282 | assert_string_equal("hello", ((struct lysc_node_leaf*)mod->compiled->data)->dflt); |
| 2283 | assert_string_equal("xxx", ((struct lysc_node_leaf*)mod->compiled->data)->units); |
| 2284 | |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 2285 | /* mandatory leaf does not takes default value from type */ |
| 2286 | assert_non_null(mod = lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;typedef mytype {type string; default hello;units xxx;}" |
| 2287 | "leaf l {type mytype; mandatory true;}}", LYS_IN_YANG)); |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 2288 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 2289 | assert_non_null(type); |
| 2290 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 2291 | assert_null(((struct lysc_node_leaf*)mod->compiled->data)->dflt); |
| 2292 | assert_string_equal("xxx", ((struct lysc_node_leaf*)mod->compiled->data)->units); |
| 2293 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 2294 | *state = NULL; |
| 2295 | ly_ctx_destroy(ctx, NULL); |
| 2296 | } |
| 2297 | |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 2298 | static void |
| 2299 | test_status(void **state) |
| 2300 | { |
| 2301 | *state = test_status; |
| 2302 | |
| 2303 | struct ly_ctx *ctx; |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 2304 | |
| 2305 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 2306 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2307 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;" |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 2308 | "container c {status deprecated; leaf l {status current; type string;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2309 | logbuf_assert("A \"current\" status is in conflict with the parent's \"deprecated\" status. /aa:c/l"); |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 2310 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2311 | assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;" |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 2312 | "container c {status obsolete; leaf l {status current; type string;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2313 | logbuf_assert("A \"current\" status is in conflict with the parent's \"obsolete\" status. /bb:c/l"); |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 2314 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2315 | assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;" |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 2316 | "container c {status obsolete; leaf l {status deprecated; type string;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2317 | logbuf_assert("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status. /cc:c/l"); |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 2318 | |
| 2319 | *state = NULL; |
| 2320 | ly_ctx_destroy(ctx, NULL); |
| 2321 | } |
| 2322 | |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2323 | static void |
Radek Krejci | f2de0ed | 2019-05-02 14:13:18 +0200 | [diff] [blame] | 2324 | test_grouping(void **state) |
| 2325 | { |
| 2326 | *state = test_grouping; |
| 2327 | |
| 2328 | struct ly_ctx *ctx; |
| 2329 | |
| 2330 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 2331 | |
| 2332 | /* result ok, but a warning about not used locally scoped grouping printed */ |
| 2333 | assert_non_null(lys_parse_mem(ctx, "module a {namespace urn:a;prefix a; grouping grp1 {leaf a1 {type string;}}" |
| 2334 | "container a {leaf x {type string;} grouping grp2 {leaf a2 {type string;}}}}", LYS_IN_YANG)); |
| 2335 | logbuf_assert("Locally scoped grouping \"grp2\" not used."); |
| 2336 | logbuf_clean(); |
| 2337 | |
| 2338 | /* result ok - when statement or leafref target must be checked only at the place where the grouping is really instantiated */ |
| 2339 | assert_non_null(lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; grouping grp {" |
| 2340 | "leaf ref {type leafref {path \"../name\";}}" |
| 2341 | "leaf cond {type string; when \"../name = 'specialone'\";}}}", LYS_IN_YANG)); |
| 2342 | logbuf_assert(""); |
| 2343 | |
| 2344 | |
| 2345 | /* invalid - error in a non-instantiated grouping */ |
| 2346 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;" |
| 2347 | "grouping grp {leaf x {type leafref;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2348 | logbuf_assert("Missing path substatement for leafref type. /aa:{grouping='grp'}/x"); |
Radek Krejci | f2de0ed | 2019-05-02 14:13:18 +0200 | [diff] [blame] | 2349 | logbuf_clean(); |
| 2350 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;" |
| 2351 | "container a {grouping grp {leaf x {type leafref;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2352 | logbuf_assert("Missing path substatement for leafref type. /aa:a/{grouping='grp'}/x"); |
Radek Krejci | f2de0ed | 2019-05-02 14:13:18 +0200 | [diff] [blame] | 2353 | |
| 2354 | |
| 2355 | *state = NULL; |
| 2356 | ly_ctx_destroy(ctx, NULL); |
| 2357 | } |
| 2358 | |
| 2359 | static void |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2360 | test_uses(void **state) |
| 2361 | { |
| 2362 | *state = test_uses; |
| 2363 | |
| 2364 | struct ly_ctx *ctx; |
| 2365 | struct lys_module *mod; |
Radek Krejci | 3641f56 | 2019-02-13 15:38:40 +0100 | [diff] [blame] | 2366 | const struct lysc_node *parent, *child; |
Radek Krejci | 32b6ecd | 2019-04-12 10:41:24 +0200 | [diff] [blame] | 2367 | const struct lysc_node_container *cont; |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2368 | |
| 2369 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 2370 | |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 2371 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module grp {namespace urn:grp;prefix g; typedef mytype {type string;} feature f;" |
| 2372 | "grouping grp {leaf x {type mytype;} leaf y {type string; if-feature f;}}}"); |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2373 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;import grp {prefix g;}" |
| 2374 | "grouping grp_a_top {leaf a1 {type int8;}}" |
| 2375 | "container a {uses grp_a; uses grp_a_top; uses g:grp; grouping grp_a {leaf a2 {type uint8;}}}}", LYS_IN_YANG)); |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2376 | assert_non_null((parent = mod->compiled->data)); |
| 2377 | assert_int_equal(LYS_CONTAINER, parent->nodetype); |
| 2378 | assert_non_null((child = ((struct lysc_node_container*)parent)->child)); |
| 2379 | assert_string_equal("a2", child->name); |
Radek Krejci | 76b3e96 | 2018-12-14 17:01:25 +0100 | [diff] [blame] | 2380 | assert_ptr_equal(mod, child->module); |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2381 | assert_non_null((child = child->next)); |
| 2382 | assert_string_equal("a1", child->name); |
Radek Krejci | 76b3e96 | 2018-12-14 17:01:25 +0100 | [diff] [blame] | 2383 | assert_ptr_equal(mod, child->module); |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2384 | assert_non_null((child = child->next)); |
| 2385 | assert_string_equal("x", child->name); |
Radek Krejci | 76b3e96 | 2018-12-14 17:01:25 +0100 | [diff] [blame] | 2386 | assert_ptr_equal(mod, child->module); |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 2387 | assert_non_null((child = child->next)); |
| 2388 | assert_string_equal("y", child->name); |
| 2389 | assert_non_null(child->iffeatures); |
| 2390 | assert_int_equal(1, LY_ARRAY_SIZE(child->iffeatures)); |
| 2391 | assert_int_equal(1, LY_ARRAY_SIZE(child->iffeatures[0].features)); |
| 2392 | assert_string_equal("f", child->iffeatures[0].features[0]->name); |
| 2393 | assert_int_equal(LY_EINVAL, lys_feature_enable(mod->compiled->imports[0].module, "f")); |
| 2394 | logbuf_assert("Module \"grp\" is not implemented so all its features are permanently disabled without a chance to change it."); |
| 2395 | assert_int_equal(0, lysc_iffeature_value(&child->iffeatures[0])); |
| 2396 | |
| 2397 | /* make the imported module implemented and enable the feature */ |
| 2398 | assert_non_null(mod = ly_ctx_get_module(ctx, "grp", NULL)); |
| 2399 | assert_int_equal(LY_SUCCESS, ly_ctx_module_implement(ctx, mod)); |
| 2400 | assert_int_equal(LY_SUCCESS, lys_feature_enable(mod, "f")); |
| 2401 | assert_string_equal("f", child->iffeatures[0].features[0]->name); |
| 2402 | assert_int_equal(1, lysc_iffeature_value(&child->iffeatures[0])); |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2403 | |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 2404 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule bsub {belongs-to b {prefix b;} grouping grp {leaf b {when 1; type string;}}}"); |
| 2405 | assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;include bsub;uses grp {when 2;}}", LYS_IN_YANG)); |
Radek Krejci | b1b5915 | 2019-01-07 13:21:56 +0100 | [diff] [blame] | 2406 | assert_non_null(mod->compiled->data); |
| 2407 | assert_int_equal(LYS_LEAF, mod->compiled->data->nodetype); |
| 2408 | assert_string_equal("b", mod->compiled->data->name); |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 2409 | assert_int_equal(2, LY_ARRAY_SIZE(mod->compiled->data->when)); |
Radek Krejci | b1b5915 | 2019-01-07 13:21:56 +0100 | [diff] [blame] | 2410 | |
Radek Krejci | 7f6a381 | 2019-01-07 13:48:57 +0100 | [diff] [blame] | 2411 | logbuf_clean(); |
| 2412 | assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:ii;prefix ii;" |
| 2413 | "grouping grp {leaf l {type string;}leaf k {type string; status obsolete;}}" |
| 2414 | "uses grp {status deprecated;}}", LYS_IN_YANG)); |
Radek Krejci | 7f6a381 | 2019-01-07 13:48:57 +0100 | [diff] [blame] | 2415 | assert_int_equal(LYS_LEAF, mod->compiled->data->nodetype); |
| 2416 | assert_string_equal("l", mod->compiled->data->name); |
| 2417 | assert_true(LYS_STATUS_DEPRC & mod->compiled->data->flags); |
| 2418 | assert_int_equal(LYS_LEAF, mod->compiled->data->next->nodetype); |
| 2419 | assert_string_equal("k", mod->compiled->data->next->name); |
| 2420 | assert_true(LYS_STATUS_OBSLT & mod->compiled->data->next->flags); |
| 2421 | logbuf_assert(""); /* no warning about inheriting deprecated flag from uses */ |
| 2422 | |
Radek Krejci | 3641f56 | 2019-02-13 15:38:40 +0100 | [diff] [blame] | 2423 | assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; grouping grp {container g;}" |
| 2424 | "container top {uses grp {augment g {leaf x {type int8;}}}}}", LYS_IN_YANG)); |
| 2425 | assert_non_null(mod->compiled->data); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2426 | assert_non_null(child = lysc_node_children(mod->compiled->data, 0)); |
Radek Krejci | 3641f56 | 2019-02-13 15:38:40 +0100 | [diff] [blame] | 2427 | assert_string_equal("g", child->name); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2428 | assert_non_null(child = lysc_node_children(child, 0)); |
Radek Krejci | 3641f56 | 2019-02-13 15:38:40 +0100 | [diff] [blame] | 2429 | assert_string_equal("x", child->name); |
| 2430 | |
Radek Krejci | 32b6ecd | 2019-04-12 10:41:24 +0200 | [diff] [blame] | 2431 | assert_non_null(mod = lys_parse_mem(ctx, "module e {yang-version 1.1;namespace urn:e;prefix e; grouping grp {action g { description \"super g\";}}" |
| 2432 | "container top {action e; uses grp {refine g {description \"ultra g\";}}}}", LYS_IN_YANG)); |
| 2433 | assert_non_null(mod->compiled->data); |
| 2434 | cont = (const struct lysc_node_container*)mod->compiled->data; |
| 2435 | assert_non_null(cont->actions); |
| 2436 | assert_int_equal(2, LY_ARRAY_SIZE(cont->actions)); |
| 2437 | assert_string_equal("e", cont->actions[1].name); |
| 2438 | assert_string_equal("g", cont->actions[0].name); |
| 2439 | assert_string_equal("ultra g", cont->actions[0].dsc); |
| 2440 | |
| 2441 | assert_non_null(mod = lys_parse_mem(ctx, "module f {yang-version 1.1;namespace urn:f;prefix f; grouping grp {notification g { description \"super g\";}}" |
| 2442 | "container top {notification f; uses grp {refine g {description \"ultra g\";}}}}", LYS_IN_YANG)); |
| 2443 | assert_non_null(mod->compiled->data); |
| 2444 | cont = (const struct lysc_node_container*)mod->compiled->data; |
| 2445 | assert_non_null(cont->notifs); |
| 2446 | assert_int_equal(2, LY_ARRAY_SIZE(cont->notifs)); |
| 2447 | assert_string_equal("f", cont->notifs[1].name); |
| 2448 | assert_string_equal("g", cont->notifs[0].name); |
| 2449 | assert_string_equal("ultra g", cont->notifs[0].dsc); |
| 2450 | |
Radek Krejci | 684faf2 | 2019-05-27 14:31:16 +0200 | [diff] [blame] | 2451 | /* empty grouping */ |
| 2452 | assert_non_null(mod = lys_parse_mem(ctx, "module g {namespace urn:g;prefix g; grouping grp; uses grp;}", LYS_IN_YANG)); |
| 2453 | assert_null(mod->compiled->data); |
| 2454 | |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2455 | /* invalid */ |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2456 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;uses missinggrp;}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2457 | logbuf_assert("Grouping \"missinggrp\" referenced by a uses statement not found. /aa:{uses='missinggrp'}"); |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2458 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2459 | assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;uses grp;" |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2460 | "grouping grp {leaf a{type string;}uses grp1;}" |
| 2461 | "grouping grp1 {leaf b {type string;}uses grp2;}" |
| 2462 | "grouping grp2 {leaf c {type string;}uses grp;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2463 | logbuf_assert("Grouping \"grp\" references itself through a uses statement. /bb:{uses='grp'}/{uses='grp1'}/{uses='grp2'}/{uses='grp'}"); |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2464 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2465 | assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;uses a:missingprefix;}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2466 | logbuf_assert("Invalid prefix used for grouping reference. /cc:{uses='a:missingprefix'}"); |
Radek Krejci | 76b3e96 | 2018-12-14 17:01:25 +0100 | [diff] [blame] | 2467 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2468 | assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;grouping grp{leaf a{type string;}}" |
Radek Krejci | 76b3e96 | 2018-12-14 17:01:25 +0100 | [diff] [blame] | 2469 | "leaf a {type string;}uses grp;}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2470 | logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/Notification statement. /dd:{uses='grp'}/dd:a"); |
Radek Krejci | 76b3e96 | 2018-12-14 17:01:25 +0100 | [diff] [blame] | 2471 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2472 | assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;grouping grp {leaf l {type string; status deprecated;}}" |
Radek Krejci | 7f6a381 | 2019-01-07 13:48:57 +0100 | [diff] [blame] | 2473 | "uses grp {status obsolete;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2474 | logbuf_assert("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status. /ee:{uses='grp'}/ee:l"); |
Radek Krejci | 7f6a381 | 2019-01-07 13:48:57 +0100 | [diff] [blame] | 2475 | |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2476 | assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;grouping grp {leaf l {type string;}}" |
| 2477 | "leaf l {type int8;}uses grp;}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2478 | logbuf_assert("Duplicate identifier \"l\" of data definition/RPC/action/Notification statement. /ff:{uses='grp'}/ff:l"); |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2479 | assert_null(lys_parse_mem(ctx, "module fg {namespace urn:fg;prefix fg;grouping grp {leaf m {type string;}}" |
| 2480 | "uses grp;leaf m {type int8;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2481 | logbuf_assert("Duplicate identifier \"m\" of data definition/RPC/action/Notification statement. /fg:m"); |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2482 | |
Radek Krejci | 3641f56 | 2019-02-13 15:38:40 +0100 | [diff] [blame] | 2483 | |
| 2484 | assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg; grouping grp {container g;}" |
| 2485 | "leaf g {type string;}" |
| 2486 | "container top {uses grp {augment /g {leaf x {type int8;}}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2487 | logbuf_assert("Invalid descendant-schema-nodeid value \"/g\" - absolute-schema-nodeid used. /gg:top/{uses='grp'}/{augment='/g'}"); |
Radek Krejci | 3641f56 | 2019-02-13 15:38:40 +0100 | [diff] [blame] | 2488 | |
Radek Krejci | 32b6ecd | 2019-04-12 10:41:24 +0200 | [diff] [blame] | 2489 | assert_non_null(mod = lys_parse_mem(ctx, "module hh {yang-version 1.1;namespace urn:hh;prefix hh;" |
| 2490 | "grouping grp {notification g { description \"super g\";}}" |
| 2491 | "container top {notification h; uses grp {refine h {description \"ultra h\";}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2492 | logbuf_assert("Invalid descendant-schema-nodeid value \"h\" - target node not found. /hh:top/{uses='grp'}/{refine='h'}"); |
Radek Krejci | 32b6ecd | 2019-04-12 10:41:24 +0200 | [diff] [blame] | 2493 | |
| 2494 | assert_non_null(mod = lys_parse_mem(ctx, "module ii {yang-version 1.1;namespace urn:ii;prefix ii;" |
| 2495 | "grouping grp {action g { description \"super g\";}}" |
| 2496 | "container top {action i; uses grp {refine i {description \"ultra i\";}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2497 | logbuf_assert("Invalid descendant-schema-nodeid value \"i\" - target node not found. /ii:top/{uses='grp'}/{refine='i'}"); |
Radek Krejci | 3641f56 | 2019-02-13 15:38:40 +0100 | [diff] [blame] | 2498 | |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2499 | *state = NULL; |
| 2500 | ly_ctx_destroy(ctx, NULL); |
| 2501 | } |
| 2502 | |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2503 | static void |
| 2504 | test_refine(void **state) |
| 2505 | { |
| 2506 | *state = test_refine; |
| 2507 | |
| 2508 | struct ly_ctx *ctx; |
| 2509 | struct lys_module *mod; |
| 2510 | struct lysc_node *parent, *child; |
| 2511 | |
| 2512 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 2513 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2514 | assert_non_null(lys_parse_mem(ctx, "module grp {yang-version 1.1;namespace urn:grp;prefix g; feature f;typedef mytype {type string; default cheers!;}" |
| 2515 | "grouping grp {container c {leaf l {type mytype; default goodbye;}" |
| 2516 | "leaf-list ll {type mytype; default goodbye; max-elements 6;}" |
| 2517 | "choice ch {default a; leaf a {type int8;}leaf b{type uint8;}}" |
| 2518 | "leaf x {type mytype; mandatory true; must 1;}" |
| 2519 | "anydata a {mandatory false; if-feature f; description original; reference original;}" |
| 2520 | "container c {config false; leaf l {type string;}}}}}", LYS_IN_YANG)); |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2521 | |
Radek Krejci | f008908 | 2019-01-07 16:42:01 +0100 | [diff] [blame] | 2522 | assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;import grp {prefix g;}feature fa;" |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2523 | "uses g:grp {refine c/l {default hello; config false;}" |
Radek Krejci | 6b22ab7 | 2019-01-07 15:39:20 +0100 | [diff] [blame] | 2524 | "refine c/ll {default hello;default world; min-elements 2; max-elements 5;}" |
Radek Krejci | f008908 | 2019-01-07 16:42:01 +0100 | [diff] [blame] | 2525 | "refine c/ch {default b;config true; if-feature fa;}" |
Radek Krejci | f340454 | 2019-01-08 13:28:42 +0100 | [diff] [blame] | 2526 | "refine c/x {mandatory false; must ../ll;description refined; reference refined;}" |
| 2527 | "refine c/a {mandatory true; must 1; if-feature fa;description refined; reference refined;}" |
Radek Krejci | 9a54f1f | 2019-01-07 13:47:55 +0100 | [diff] [blame] | 2528 | "refine c/c {config true;presence indispensable;}}}", LYS_IN_YANG)); |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2529 | assert_non_null((parent = mod->compiled->data)); |
| 2530 | assert_int_equal(LYS_CONTAINER, parent->nodetype); |
| 2531 | assert_string_equal("c", parent->name); |
| 2532 | assert_non_null((child = ((struct lysc_node_container*)parent)->child)); |
| 2533 | assert_int_equal(LYS_LEAF, child->nodetype); |
| 2534 | assert_string_equal("l", child->name); |
| 2535 | assert_string_equal("hello", ((struct lysc_node_leaf*)child)->dflt); |
| 2536 | assert_int_equal(LYS_CONFIG_R, child->flags & LYS_CONFIG_MASK); |
| 2537 | assert_non_null(child = child->next); |
| 2538 | assert_int_equal(LYS_LEAFLIST, child->nodetype); |
| 2539 | assert_string_equal("ll", child->name); |
| 2540 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_node_leaflist*)child)->dflts)); |
| 2541 | assert_string_equal("hello", ((struct lysc_node_leaflist*)child)->dflts[0]); |
| 2542 | assert_string_equal("world", ((struct lysc_node_leaflist*)child)->dflts[1]); |
Radek Krejci | 6b22ab7 | 2019-01-07 15:39:20 +0100 | [diff] [blame] | 2543 | assert_int_equal(2, ((struct lysc_node_leaflist*)child)->min); |
| 2544 | assert_int_equal(5, ((struct lysc_node_leaflist*)child)->max); |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2545 | assert_non_null(child = child->next); |
| 2546 | assert_int_equal(LYS_CHOICE, child->nodetype); |
| 2547 | assert_string_equal("ch", child->name); |
| 2548 | assert_string_equal("b", ((struct lysc_node_choice*)child)->dflt->name); |
| 2549 | assert_true(LYS_SET_DFLT & ((struct lysc_node_choice*)child)->dflt->flags); |
| 2550 | assert_false(LYS_SET_DFLT & ((struct lysc_node_choice*)child)->cases[0].flags); |
Radek Krejci | f008908 | 2019-01-07 16:42:01 +0100 | [diff] [blame] | 2551 | assert_non_null(child->iffeatures); |
| 2552 | assert_int_equal(1, LY_ARRAY_SIZE(child->iffeatures)); |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2553 | assert_non_null(child = child->next); |
| 2554 | assert_int_equal(LYS_LEAF, child->nodetype); |
| 2555 | assert_string_equal("x", child->name); |
| 2556 | assert_false(LYS_MAND_TRUE & child->flags); |
| 2557 | assert_string_equal("cheers!", ((struct lysc_node_leaf*)child)->dflt); |
Radek Krejci | 9a564c9 | 2019-01-07 14:53:57 +0100 | [diff] [blame] | 2558 | assert_non_null(((struct lysc_node_leaf*)child)->musts); |
| 2559 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_node_leaf*)child)->musts)); |
Radek Krejci | f340454 | 2019-01-08 13:28:42 +0100 | [diff] [blame] | 2560 | assert_string_equal("refined", child->dsc); |
| 2561 | assert_string_equal("refined", child->ref); |
Radek Krejci | b1b5915 | 2019-01-07 13:21:56 +0100 | [diff] [blame] | 2562 | assert_non_null(child = child->next); |
Radek Krejci | 7f6a381 | 2019-01-07 13:48:57 +0100 | [diff] [blame] | 2563 | assert_int_equal(LYS_ANYDATA, child->nodetype); |
| 2564 | assert_string_equal("a", child->name); |
| 2565 | assert_true(LYS_MAND_TRUE & child->flags); |
Radek Krejci | 9a564c9 | 2019-01-07 14:53:57 +0100 | [diff] [blame] | 2566 | assert_non_null(((struct lysc_node_anydata*)child)->musts); |
| 2567 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_node_anydata*)child)->musts)); |
Radek Krejci | f008908 | 2019-01-07 16:42:01 +0100 | [diff] [blame] | 2568 | assert_non_null(child->iffeatures); |
| 2569 | assert_int_equal(2, LY_ARRAY_SIZE(child->iffeatures)); |
Radek Krejci | f340454 | 2019-01-08 13:28:42 +0100 | [diff] [blame] | 2570 | assert_string_equal("refined", child->dsc); |
| 2571 | assert_string_equal("refined", child->ref); |
Radek Krejci | 7f6a381 | 2019-01-07 13:48:57 +0100 | [diff] [blame] | 2572 | assert_non_null(child = child->next); |
Radek Krejci | b1b5915 | 2019-01-07 13:21:56 +0100 | [diff] [blame] | 2573 | assert_int_equal(LYS_CONTAINER, child->nodetype); |
| 2574 | assert_string_equal("c", child->name); |
Radek Krejci | 7f6a381 | 2019-01-07 13:48:57 +0100 | [diff] [blame] | 2575 | assert_true(LYS_PRESENCE & child->flags); |
Radek Krejci | b1b5915 | 2019-01-07 13:21:56 +0100 | [diff] [blame] | 2576 | assert_true(LYS_CONFIG_W & child->flags); |
| 2577 | assert_true(LYS_CONFIG_W & ((struct lysc_node_container*)child)->child->flags); |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2578 | |
| 2579 | assert_non_null(mod = lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b;import grp {prefix g;}" |
Radek Krejci | b1b5915 | 2019-01-07 13:21:56 +0100 | [diff] [blame] | 2580 | "uses g:grp {status deprecated; refine c/x {default hello; mandatory false;}}}", LYS_IN_YANG)); |
Radek Krejci | 7f6a381 | 2019-01-07 13:48:57 +0100 | [diff] [blame] | 2581 | assert_non_null((child = ((struct lysc_node_container*)mod->compiled->data)->child->prev->prev->prev)); |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2582 | assert_int_equal(LYS_LEAF, child->nodetype); |
| 2583 | assert_string_equal("x", child->name); |
| 2584 | assert_false(LYS_MAND_TRUE & child->flags); |
| 2585 | assert_string_equal("hello", ((struct lysc_node_leaf*)child)->dflt); |
| 2586 | |
| 2587 | /* invalid */ |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2588 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;import grp {prefix g;}" |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2589 | "uses g:grp {refine c {default hello;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2590 | logbuf_assert("Invalid refine of default - container cannot hold default value(s). /aa:{uses='g:grp'}/{refine='c'}"); |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2591 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2592 | assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;import grp {prefix g;}" |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2593 | "uses g:grp {refine c/l {default hello; default world;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2594 | logbuf_assert("Invalid refine of default - leaf cannot hold 2 default values. /bb:{uses='g:grp'}/{refine='c/l'}"); |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2595 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2596 | assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;import grp {prefix g;}" |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2597 | "uses g:grp {refine c/ll {default hello; default world;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2598 | logbuf_assert("Invalid refine of default in leaf-list - the default statement is allowed only in YANG 1.1 modules. /cc:{uses='g:grp'}/{refine='c/ll'}"); |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2599 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2600 | assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;import grp {prefix g;}" |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2601 | "uses g:grp {refine c/ll {mandatory true;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2602 | logbuf_assert("Invalid refine of mandatory - leaf-list cannot hold mandatory statement. /dd:{uses='g:grp'}/{refine='c/ll'}"); |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2603 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2604 | assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;import grp {prefix g;}" |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2605 | "uses g:grp {refine c/l {mandatory true;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2606 | logbuf_assert("Invalid refine of mandatory - leaf already has \"default\" statement. /ee:{uses='g:grp'}/{refine='c/l'}"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2607 | assert_null(lys_parse_mem(ctx, "module ef {namespace urn:ef;prefix ef;import grp {prefix g;}" |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2608 | "uses g:grp {refine c/ch {mandatory true;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2609 | logbuf_assert("Invalid refine of mandatory - choice already has \"default\" statement. /ef:{uses='g:grp'}/{refine='c/ch'}"); |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2610 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2611 | assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;import grp {prefix g;}" |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2612 | "uses g:grp {refine c/ch/a/a {mandatory true;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2613 | logbuf_assert("Invalid refine of mandatory under the default case. /ff:{uses='g:grp'}/{refine='c/ch/a/a'}"); |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2614 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2615 | assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;import grp {prefix g;}" |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2616 | "uses g:grp {refine c/x {default hello;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2617 | logbuf_assert("Invalid refine of default - the node is mandatory. /gg:{uses='g:grp'}/{refine='c/x'}"); |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2618 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2619 | assert_null(lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;import grp {prefix g;}" |
Radek Krejci | b1b5915 | 2019-01-07 13:21:56 +0100 | [diff] [blame] | 2620 | "uses g:grp {refine c/c/l {config true;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2621 | logbuf_assert("Invalid refine of config - configuration node cannot be child of any state data node. /hh:{uses='g:grp'}/{refine='c/c/l'}"); |
Radek Krejci | b1b5915 | 2019-01-07 13:21:56 +0100 | [diff] [blame] | 2622 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2623 | assert_null(lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;grouping grp {leaf l {type string; status deprecated;}}" |
Radek Krejci | b1b5915 | 2019-01-07 13:21:56 +0100 | [diff] [blame] | 2624 | "uses grp {status obsolete;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2625 | logbuf_assert("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status. /ii:{uses='grp'}/ii:l"); |
Radek Krejci | b1b5915 | 2019-01-07 13:21:56 +0100 | [diff] [blame] | 2626 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2627 | assert_null(lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;import grp {prefix g;}" |
Radek Krejci | 9a54f1f | 2019-01-07 13:47:55 +0100 | [diff] [blame] | 2628 | "uses g:grp {refine c/x {presence nonsence;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2629 | logbuf_assert("Invalid refine of presence statement - leaf cannot hold the presence statement. /jj:{uses='g:grp'}/{refine='c/x'}"); |
Radek Krejci | 9a54f1f | 2019-01-07 13:47:55 +0100 | [diff] [blame] | 2630 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2631 | assert_null(lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;import grp {prefix g;}" |
Radek Krejci | 9a564c9 | 2019-01-07 14:53:57 +0100 | [diff] [blame] | 2632 | "uses g:grp {refine c/ch {must 1;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2633 | logbuf_assert("Invalid refine of must statement - choice cannot hold any must statement. /kk:{uses='g:grp'}/{refine='c/ch'}"); |
Radek Krejci | 9a564c9 | 2019-01-07 14:53:57 +0100 | [diff] [blame] | 2634 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2635 | assert_null(lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;import grp {prefix g;}" |
Radek Krejci | 6b22ab7 | 2019-01-07 15:39:20 +0100 | [diff] [blame] | 2636 | "uses g:grp {refine c/x {min-elements 1;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2637 | logbuf_assert("Invalid refine of min-elements statement - leaf cannot hold this statement. /ll:{uses='g:grp'}/{refine='c/x'}"); |
Radek Krejci | 6b22ab7 | 2019-01-07 15:39:20 +0100 | [diff] [blame] | 2638 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 2639 | assert_null(lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;import grp {prefix g;}" |
Radek Krejci | f2271f1 | 2019-01-07 16:42:23 +0100 | [diff] [blame] | 2640 | "uses g:grp {refine c/ll {min-elements 10;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2641 | logbuf_assert("Invalid refine of min-elements statement - \"min-elements\" is bigger than \"max-elements\". /mm:{uses='g:grp'}/{refine='c/ll'}"); |
Radek Krejci | f2271f1 | 2019-01-07 16:42:23 +0100 | [diff] [blame] | 2642 | |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 2643 | *state = NULL; |
| 2644 | ly_ctx_destroy(ctx, NULL); |
| 2645 | } |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 2646 | |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2647 | static void |
| 2648 | test_augment(void **state) |
| 2649 | { |
| 2650 | *state = test_augment; |
| 2651 | |
| 2652 | struct ly_ctx *ctx; |
| 2653 | struct lys_module *mod; |
| 2654 | const struct lysc_node *node; |
| 2655 | const struct lysc_node_choice *ch; |
| 2656 | const struct lysc_node_case *c; |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 2657 | const struct lysc_action *rpc; |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2658 | |
| 2659 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 2660 | |
| 2661 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module a {namespace urn:a;prefix a; typedef atype {type string;}" |
| 2662 | "container top {leaf a {type string;}}}"); |
| 2663 | assert_non_null(lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}" |
| 2664 | "leaf b {type a:atype;}}", LYS_IN_YANG)); |
| 2665 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module c {namespace urn:c;prefix c; import a {prefix a;}" |
| 2666 | "augment /a:top/ { container c {leaf c {type a:atype;}}}}"); |
| 2667 | assert_non_null(lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;import a {prefix a;} import c {prefix c;}" |
| 2668 | "augment /a:top/c:c/ { leaf d {type a:atype;} leaf c {type string;}}}", LYS_IN_YANG)); |
| 2669 | assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "a"))); |
| 2670 | assert_non_null(ly_ctx_get_module_implemented(ctx, "b")); |
| 2671 | assert_non_null(ly_ctx_get_module_implemented(ctx, "c")); |
| 2672 | assert_non_null(ly_ctx_get_module_implemented(ctx, "d")); |
| 2673 | assert_non_null(node = mod->compiled->data); |
| 2674 | assert_string_equal(node->name, "top"); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2675 | assert_non_null(node = lysc_node_children(node, 0)); |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2676 | assert_string_equal(node->name, "a"); |
| 2677 | assert_non_null(node = node->next); |
| 2678 | assert_string_equal(node->name, "c"); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2679 | assert_non_null(node = lysc_node_children(node, 0)); |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2680 | assert_string_equal(node->name, "c"); |
| 2681 | assert_non_null(node = node->next); |
| 2682 | assert_string_equal(node->name, "d"); |
| 2683 | assert_non_null(node = node->next); |
| 2684 | assert_string_equal(node->name, "c"); |
| 2685 | |
| 2686 | assert_non_null((mod = lys_parse_mem(ctx, "module e {namespace urn:e;prefix e;choice ch {leaf a {type string;}}" |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 2687 | "augment /ch/c {when 1; leaf lc2 {type uint16;}}" |
| 2688 | "augment /ch { when 1; leaf b {type int8;} case c {leaf lc1 {type uint8;}}}}", LYS_IN_YANG))); |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2689 | assert_non_null((ch = (const struct lysc_node_choice*)mod->compiled->data)); |
| 2690 | assert_null(mod->compiled->data->next); |
| 2691 | assert_string_equal("ch", ch->name); |
| 2692 | assert_non_null(c = ch->cases); |
| 2693 | assert_string_equal("a", c->name); |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 2694 | assert_null(c->when); |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2695 | assert_string_equal("a", c->child->name); |
| 2696 | assert_non_null(c = (const struct lysc_node_case*)c->next); |
| 2697 | assert_string_equal("b", c->name); |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 2698 | assert_non_null(c->when); |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2699 | assert_string_equal("b", c->child->name); |
| 2700 | assert_non_null(c = (const struct lysc_node_case*)c->next); |
| 2701 | assert_string_equal("c", c->name); |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 2702 | assert_non_null(c->when); |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2703 | assert_string_equal("lc1", ((const struct lysc_node_case*)c)->child->name); |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 2704 | assert_null(((const struct lysc_node_case*)c)->child->when); |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2705 | assert_string_equal("lc2", ((const struct lysc_node_case*)c)->child->next->name); |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 2706 | assert_non_null(((const struct lysc_node_case*)c)->child->next->when); |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2707 | assert_ptr_equal(ch->cases->child->prev, ((const struct lysc_node_case*)c)->child->next); |
| 2708 | assert_null(c->next); |
| 2709 | |
| 2710 | assert_non_null((mod = lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;grouping g {leaf a {type string;}}" |
| 2711 | "container c;" |
| 2712 | "augment /c {uses g;}}", LYS_IN_YANG))); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2713 | assert_non_null(node = lysc_node_children(mod->compiled->data, 0)); |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2714 | assert_string_equal(node->name, "a"); |
| 2715 | |
Radek Krejci | 339f529 | 2019-02-11 16:42:34 +0100 | [diff] [blame] | 2716 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule gsub {belongs-to g {prefix g;}" |
| 2717 | "augment /c {container sub;}}"); |
| 2718 | assert_non_null(mod = lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;include gsub; container c;" |
| 2719 | "augment /c/sub {leaf main {type string;}}}", LYS_IN_YANG)); |
| 2720 | assert_non_null(mod->compiled->data); |
| 2721 | assert_string_equal("c", mod->compiled->data->name); |
| 2722 | assert_non_null(node = ((struct lysc_node_container*)mod->compiled->data)->child); |
| 2723 | assert_string_equal("sub", node->name); |
| 2724 | assert_non_null(node = ((struct lysc_node_container*)node)->child); |
| 2725 | assert_string_equal("main", node->name); |
| 2726 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 2727 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module himp {namespace urn:hi;prefix hi;container top; rpc func;}"); |
Radek Krejci | 733988a | 2019-02-15 15:12:44 +0100 | [diff] [blame] | 2728 | assert_non_null(mod = lys_parse_mem(ctx, "module h {namespace urn:h;prefix h;import himp {prefix hi;}container top;" |
| 2729 | "augment /hi:top {container p {presence XXX; leaf x {mandatory true;type string;}}}" |
| 2730 | "augment /hi:top {list ll {key x;leaf x {type string;}leaf y {mandatory true; type string;}}}" |
| 2731 | "augment /hi:top {leaf l {type string; mandatory true; config false;}}" |
| 2732 | "augment /top {leaf l {type string; mandatory true;}}}", LYS_IN_YANG)); |
| 2733 | assert_non_null(node = mod->compiled->data); |
| 2734 | assert_non_null(node = ((struct lysc_node_container*)node)->child); |
| 2735 | assert_string_equal("l", node->name); |
| 2736 | assert_true(node->flags & LYS_MAND_TRUE); |
| 2737 | assert_non_null(mod = ly_ctx_get_module_implemented(ctx, "himp")); |
Radek Krejci | fe90963 | 2019-02-12 15:34:42 +0100 | [diff] [blame] | 2738 | assert_non_null(node = mod->compiled->data); |
| 2739 | assert_non_null(node = ((struct lysc_node_container*)node)->child); |
| 2740 | assert_string_equal("p", node->name); |
Radek Krejci | 733988a | 2019-02-15 15:12:44 +0100 | [diff] [blame] | 2741 | assert_non_null(node = node->next); |
| 2742 | assert_string_equal("ll", node->name); |
| 2743 | assert_non_null(node = node->next); |
| 2744 | assert_string_equal("l", node->name); |
| 2745 | assert_true(node->flags & LYS_CONFIG_R); |
Radek Krejci | fe90963 | 2019-02-12 15:34:42 +0100 | [diff] [blame] | 2746 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 2747 | assert_non_null(lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;import himp {prefix hi;}" |
| 2748 | "augment /hi:func/input {leaf x {type string;}}" |
| 2749 | "augment /hi:func/output {leaf y {type string;}}}", LYS_IN_YANG)); |
| 2750 | assert_non_null(mod = ly_ctx_get_module_implemented(ctx, "himp")); |
| 2751 | assert_non_null(rpc = mod->compiled->rpcs); |
| 2752 | assert_int_equal(1, LY_ARRAY_SIZE(rpc)); |
| 2753 | assert_non_null(rpc->input.data); |
| 2754 | assert_string_equal("x", rpc->input.data->name); |
| 2755 | assert_null(rpc->input.data->next); |
| 2756 | assert_non_null(rpc->output.data); |
| 2757 | assert_string_equal("y", rpc->output.data->name); |
| 2758 | assert_null(rpc->output.data->next); |
| 2759 | |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2760 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; container c {leaf a {type string;}}" |
| 2761 | "augment /x {leaf a {type int8;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2762 | logbuf_assert("Invalid absolute-schema-nodeid value \"/x\" - target node not found. /aa:{augment='/x'}"); |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2763 | |
| 2764 | assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; container c {leaf a {type string;}}" |
| 2765 | "augment /c {leaf a {type int8;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2766 | logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/Notification statement. /bb:{augment='/c'}/a"); |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2767 | |
| 2768 | |
Radek Krejci | 339f529 | 2019-02-11 16:42:34 +0100 | [diff] [blame] | 2769 | assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; container c {leaf a {type string;}}" |
| 2770 | "augment /c/a {leaf a {type int8;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2771 | logbuf_assert("Augment's absolute-schema-nodeid \"/c/a\" refers to a leaf node which is not an allowed augment's target. /cc:{augment='/c/a'}"); |
Radek Krejci | 339f529 | 2019-02-11 16:42:34 +0100 | [diff] [blame] | 2772 | |
| 2773 | assert_null(lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; container c {leaf a {type string;}}" |
| 2774 | "augment /c {case b {leaf d {type int8;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2775 | logbuf_assert("Invalid augment of container node which is not allowed to contain case node \"b\". /dd:{augment='/c'}"); |
Radek Krejci | 339f529 | 2019-02-11 16:42:34 +0100 | [diff] [blame] | 2776 | |
Radek Krejci | 733988a | 2019-02-15 15:12:44 +0100 | [diff] [blame] | 2777 | assert_null(lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee; import himp {prefix hi;}" |
| 2778 | "augment /hi:top {container c {leaf d {mandatory true; type int8;}}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2779 | logbuf_assert("Invalid augment adding mandatory node \"c\" without making it conditional via when statement. /ee:{augment='/hi:top'}"); |
Radek Krejci | fe90963 | 2019-02-12 15:34:42 +0100 | [diff] [blame] | 2780 | |
Radek Krejci | 3641f56 | 2019-02-13 15:38:40 +0100 | [diff] [blame] | 2781 | assert_null(lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff; container top;" |
| 2782 | "augment ../top {leaf x {type int8;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2783 | logbuf_assert("Invalid absolute-schema-nodeid value \"../top\" - missing starting \"/\". /ff:{augment='../top'}"); |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2784 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 2785 | assert_null(lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg; rpc func;" |
| 2786 | "augment /func {leaf x {type int8;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 2787 | logbuf_assert("Augment's absolute-schema-nodeid \"/func\" refers to a RPC/action node which is not an allowed augment's target. /gg:{augment='/func'}"); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 2788 | |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 2789 | *state = NULL; |
| 2790 | ly_ctx_destroy(ctx, NULL); |
| 2791 | } |
| 2792 | |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 2793 | static void |
| 2794 | test_deviation(void **state) |
| 2795 | { |
| 2796 | *state = test_deviation; |
| 2797 | |
| 2798 | struct ly_ctx *ctx; |
| 2799 | struct lys_module *mod; |
| 2800 | const struct lysc_node *node; |
Radek Krejci | 7af6424 | 2019-02-18 13:07:53 +0100 | [diff] [blame] | 2801 | const struct lysc_node_list *list; |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 2802 | |
| 2803 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 2804 | |
| 2805 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module a {namespace urn:a;prefix a;" |
Radek Krejci | 88ef64b | 2019-02-18 16:02:06 +0100 | [diff] [blame] | 2806 | "container top {leaf a {type string;} leaf b {type string;} leaf c {type string;}}" |
| 2807 | "choice ch {default c; case b {leaf b{type string;}} case a {leaf a{type string;} leaf x {type string;}}" |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 2808 | " case c {leaf c{type string;}}}" |
| 2809 | "rpc func1 { input { leaf x {type int8;}} output {leaf y {type int8;}}}" |
| 2810 | "rpc func2;}"); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 2811 | assert_non_null(lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}" |
Radek Krejci | 88ef64b | 2019-02-18 16:02:06 +0100 | [diff] [blame] | 2812 | "deviation /a:top/a:b {deviate not-supported;}" |
| 2813 | "deviation /a:ch/a:a/a:x {deviate not-supported;}" |
| 2814 | "deviation /a:ch/a:c/a:c {deviate not-supported;}" |
| 2815 | "deviation /a:ch/a:b {deviate not-supported;}" |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 2816 | "deviation /a:ch/a:a/a:a {deviate not-supported;}" |
| 2817 | "deviation /a:func1/a:input {deviate not-supported;}" |
| 2818 | "deviation /a:func1/a:output {deviate not-supported;}" |
| 2819 | "deviation /a:func2 {deviate not-supported;}}", LYS_IN_YANG)); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 2820 | assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "a"))); |
| 2821 | assert_non_null(node = mod->compiled->data); |
| 2822 | assert_string_equal(node->name, "top"); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2823 | assert_non_null(node = lysc_node_children(node, 0)); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 2824 | assert_string_equal(node->name, "a"); |
| 2825 | assert_non_null(node = node->next); |
| 2826 | assert_string_equal(node->name, "c"); |
Radek Krejci | 88ef64b | 2019-02-18 16:02:06 +0100 | [diff] [blame] | 2827 | assert_null(node = node->next); |
| 2828 | assert_non_null(node = mod->compiled->data->next); |
| 2829 | assert_string_equal("ch", node->name); |
| 2830 | assert_null(((struct lysc_node_choice*)node)->dflt); |
| 2831 | assert_null(((struct lysc_node_choice*)node)->cases); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 2832 | assert_int_equal(1, LY_ARRAY_SIZE(mod->compiled->rpcs)); |
| 2833 | assert_null(mod->compiled->rpcs[0].input.data); |
| 2834 | assert_null(mod->compiled->rpcs[0].output.data); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 2835 | |
| 2836 | assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:c;prefix c; typedef mytype {type string; units kilometers;}" |
| 2837 | "leaf c1 {type mytype;} leaf c2 {type mytype; units meters;} leaf c3 {type mytype; units meters;}" |
| 2838 | "deviation /c1 {deviate add {units meters;}}" |
| 2839 | "deviation /c2 {deviate delete {units meters;}}" |
| 2840 | "deviation /c3 {deviate replace {units centimeters;}}}", LYS_IN_YANG)); |
| 2841 | assert_non_null(node = mod->compiled->data); |
| 2842 | assert_string_equal("c1", node->name); |
| 2843 | assert_string_equal("meters", ((struct lysc_node_leaf*)node)->units); |
| 2844 | assert_non_null(node = node->next); |
| 2845 | assert_string_equal("c2", node->name); |
| 2846 | assert_null(((struct lysc_node_leaf*)node)->units); |
| 2847 | assert_non_null(node = node->next); |
| 2848 | assert_string_equal("c3", node->name); |
| 2849 | assert_string_equal("centimeters", ((struct lysc_node_leaf*)node)->units); |
| 2850 | |
| 2851 | assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; leaf c1 {type string; must 1;}" |
Radek Krejci | b4532d1 | 2019-02-15 16:13:29 +0100 | [diff] [blame] | 2852 | "container c2 {presence yes; must 1; must 2;} leaf c3 {type string; must 1; must 3;}" |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 2853 | "deviation /c1 {deviate add {must 3;}}" |
| 2854 | "deviation /c2 {deviate delete {must 2;}}" |
| 2855 | "deviation /c3 {deviate delete {must 3; must 1;}}}", LYS_IN_YANG)); |
| 2856 | assert_non_null(node = mod->compiled->data); |
| 2857 | assert_string_equal("c1", node->name); |
| 2858 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_node_leaf*)node)->musts)); |
| 2859 | assert_string_equal("3", ((struct lysc_node_leaf*)node)->musts[1].cond->expr); |
| 2860 | assert_non_null(node = node->next); |
| 2861 | assert_string_equal("c2", node->name); |
Radek Krejci | b4532d1 | 2019-02-15 16:13:29 +0100 | [diff] [blame] | 2862 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_node_container*)node)->musts)); |
| 2863 | assert_string_equal("1", ((struct lysc_node_container*)node)->musts[0].cond->expr); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 2864 | assert_non_null(node = node->next); |
| 2865 | assert_string_equal("c3", node->name); |
| 2866 | assert_null(((struct lysc_node_leaf*)node)->musts); |
| 2867 | |
Radek Krejci | b4532d1 | 2019-02-15 16:13:29 +0100 | [diff] [blame] | 2868 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module e {yang-version 1.1; namespace urn:e;prefix e; typedef mytype {type string; default nothing;}" |
Radek Krejci | 468a94f | 2019-02-15 14:52:36 +0100 | [diff] [blame] | 2869 | "choice a {default a;leaf a {type string;} leaf b {type string;} leaf c {type string; mandatory true;}}" |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 2870 | "choice b {default a;leaf a {type string;} leaf b {type string;}}" |
| 2871 | "leaf c {default hello; type string;}" |
Radek Krejci | b4532d1 | 2019-02-15 16:13:29 +0100 | [diff] [blame] | 2872 | "leaf-list d {default hello; default world; type string;}" |
| 2873 | "leaf c2 {type mytype;} leaf-list d2 {type mytype;}}"); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 2874 | assert_non_null(lys_parse_mem(ctx, "module f {yang-version 1.1; namespace urn:f;prefix f;import e {prefix x;}" |
| 2875 | "deviation /x:a {deviate delete {default a;}}" |
| 2876 | "deviation /x:b {deviate delete {default x:a;}}" |
| 2877 | "deviation /x:c {deviate delete {default hello;}}" |
| 2878 | "deviation /x:d {deviate delete {default world;}}}", LYS_IN_YANG)); |
| 2879 | assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "e"))); |
| 2880 | assert_non_null(node = mod->compiled->data); |
| 2881 | assert_null(((struct lysc_node_choice*)node)->dflt); |
| 2882 | assert_non_null(node = node->next); |
| 2883 | assert_null(((struct lysc_node_choice*)node)->dflt); |
| 2884 | assert_non_null(node = node->next); |
| 2885 | assert_null(((struct lysc_node_leaf*)node)->dflt); |
| 2886 | assert_non_null(node = node->next); |
| 2887 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_node_leaflist*)node)->dflts)); |
| 2888 | assert_string_equal("hello", ((struct lysc_node_leaflist*)node)->dflts[0]); |
Radek Krejci | b4532d1 | 2019-02-15 16:13:29 +0100 | [diff] [blame] | 2889 | assert_non_null(node = node->next); |
| 2890 | assert_string_equal("nothing", ((struct lysc_node_leaf*)node)->dflt); |
| 2891 | assert_non_null(node = node->next); |
| 2892 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_node_leaflist*)node)->dflts)); |
| 2893 | assert_string_equal("nothing", ((struct lysc_node_leaflist*)node)->dflts[0]); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 2894 | |
| 2895 | assert_non_null(lys_parse_mem(ctx, "module g {yang-version 1.1; namespace urn:g;prefix g;import e {prefix x;}" |
| 2896 | "deviation /x:b {deviate add {default x:b;}}" |
| 2897 | "deviation /x:c {deviate add {default bye;}}" |
Radek Krejci | b4532d1 | 2019-02-15 16:13:29 +0100 | [diff] [blame] | 2898 | "deviation /x:d {deviate add {default all; default people;}}" |
| 2899 | "deviation /x:c2 {deviate add {default hi;}}" |
| 2900 | "deviation /x:d2 {deviate add {default hi; default all;}}}", LYS_IN_YANG)); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 2901 | assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "e"))); |
| 2902 | assert_non_null(node = mod->compiled->data); |
| 2903 | assert_null(((struct lysc_node_choice*)node)->dflt); |
| 2904 | assert_non_null(node = node->next); |
| 2905 | assert_non_null(((struct lysc_node_choice*)node)->dflt); |
| 2906 | assert_string_equal("b", ((struct lysc_node_choice*)node)->dflt->name); |
| 2907 | assert_non_null(node = node->next); |
| 2908 | assert_non_null(((struct lysc_node_leaf*)node)->dflt); |
| 2909 | assert_string_equal("bye", ((struct lysc_node_leaf*)node)->dflt); |
| 2910 | assert_non_null(node = node->next); |
| 2911 | assert_int_equal(3, LY_ARRAY_SIZE(((struct lysc_node_leaflist*)node)->dflts)); |
| 2912 | assert_string_equal("hello", ((struct lysc_node_leaflist*)node)->dflts[0]); |
| 2913 | assert_string_equal("all", ((struct lysc_node_leaflist*)node)->dflts[1]); |
| 2914 | assert_string_equal("people", ((struct lysc_node_leaflist*)node)->dflts[2]); |
Radek Krejci | b4532d1 | 2019-02-15 16:13:29 +0100 | [diff] [blame] | 2915 | assert_non_null(node = node->next); |
| 2916 | assert_non_null(((struct lysc_node_leaf*)node)->dflt); |
| 2917 | assert_string_equal("hi", ((struct lysc_node_leaf*)node)->dflt); |
| 2918 | assert_non_null(node = node->next); |
| 2919 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_node_leaflist*)node)->dflts)); |
| 2920 | assert_string_equal("hi", ((struct lysc_node_leaflist*)node)->dflts[0]); |
| 2921 | assert_string_equal("all", ((struct lysc_node_leaflist*)node)->dflts[1]); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 2922 | |
| 2923 | assert_non_null(lys_parse_mem(ctx, "module h {yang-version 1.1; namespace urn:h;prefix h;import e {prefix x;}" |
| 2924 | "deviation /x:b {deviate replace {default x:a;}}" |
| 2925 | "deviation /x:c {deviate replace {default hello;}}}", LYS_IN_YANG)); |
| 2926 | assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "e"))); |
| 2927 | assert_non_null(node = mod->compiled->data); |
| 2928 | assert_null(((struct lysc_node_choice*)node)->dflt); |
| 2929 | assert_non_null(node = node->next); |
| 2930 | assert_non_null(((struct lysc_node_choice*)node)->dflt); |
| 2931 | assert_string_equal("a", ((struct lysc_node_choice*)node)->dflt->name); |
| 2932 | assert_non_null(node = node->next); |
| 2933 | assert_non_null(((struct lysc_node_leaf*)node)->dflt); |
| 2934 | assert_string_equal("hello", ((struct lysc_node_leaf*)node)->dflt); |
| 2935 | |
Radek Krejci | 7af6424 | 2019-02-18 13:07:53 +0100 | [diff] [blame] | 2936 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module i {namespace urn:i;prefix i;" |
| 2937 | "list l1 {key a; leaf a {type string;} leaf b {type string;} leaf c {type string;}}" |
| 2938 | "list l2 {key a; unique \"b c\"; unique \"d\"; leaf a {type string;} leaf b {type string;}" |
| 2939 | " leaf c {type string;} leaf d {type string;}}}"); |
| 2940 | assert_non_null(lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;import i {prefix i;}" |
| 2941 | "augment /i:l1 {leaf j_c {type string;}}" |
| 2942 | "deviation /i:l1 {deviate add {unique \"i:b j_c\"; }}" |
| 2943 | "deviation /i:l1 {deviate add {unique \"i:c\";}}" |
| 2944 | "deviation /i:l2 {deviate delete {unique \"d\"; unique \"b c\";}}}", LYS_IN_YANG)); |
| 2945 | assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "i"))); |
| 2946 | assert_non_null(list = (struct lysc_node_list*)mod->compiled->data); |
| 2947 | assert_string_equal("l1", list->name); |
| 2948 | assert_int_equal(2, LY_ARRAY_SIZE(list->uniques)); |
| 2949 | assert_int_equal(2, LY_ARRAY_SIZE(list->uniques[0])); |
| 2950 | assert_string_equal("b", list->uniques[0][0]->name); |
| 2951 | assert_string_equal("j_c", list->uniques[0][1]->name); |
| 2952 | assert_int_equal(1, LY_ARRAY_SIZE(list->uniques[1])); |
| 2953 | assert_string_equal("c", list->uniques[1][0]->name); |
| 2954 | assert_non_null(list = (struct lysc_node_list*)list->next); |
| 2955 | assert_string_equal("l2", list->name); |
| 2956 | assert_null(list->uniques); |
| 2957 | |
Radek Krejci | 93dcc39 | 2019-02-19 10:43:38 +0100 | [diff] [blame] | 2958 | assert_non_null(mod = lys_parse_mem(ctx, "module k {namespace urn:k;prefix k; leaf a {type string;}" |
| 2959 | "container top {leaf x {type string;} leaf y {type string; config false;}}" |
| 2960 | "deviation /a {deviate add {config false; }}" |
| 2961 | "deviation /top {deviate add {config false;}}}", LYS_IN_YANG)); |
| 2962 | assert_non_null(node = mod->compiled->data); |
| 2963 | assert_string_equal("a", node->name); |
| 2964 | assert_true(node->flags & LYS_CONFIG_R); |
| 2965 | assert_non_null(node = node->next); |
| 2966 | assert_string_equal("top", node->name); |
| 2967 | assert_true(node->flags & LYS_CONFIG_R); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2968 | assert_non_null(node = lysc_node_children(node, 0)); |
Radek Krejci | 93dcc39 | 2019-02-19 10:43:38 +0100 | [diff] [blame] | 2969 | assert_string_equal("x", node->name); |
| 2970 | assert_true(node->flags & LYS_CONFIG_R); |
| 2971 | assert_non_null(node = node->next); |
| 2972 | assert_string_equal("y", node->name); |
| 2973 | assert_true(node->flags & LYS_CONFIG_R); |
| 2974 | |
| 2975 | assert_non_null(mod = lys_parse_mem(ctx, "module l {namespace urn:l;prefix l; leaf a {config false; type string;}" |
| 2976 | "container top {config false; leaf x {type string;}}" |
| 2977 | "deviation /a {deviate replace {config true;}}" |
| 2978 | "deviation /top {deviate replace {config true;}}}", LYS_IN_YANG)); |
| 2979 | assert_non_null(node = mod->compiled->data); |
| 2980 | assert_string_equal("a", node->name); |
| 2981 | assert_true(node->flags & LYS_CONFIG_W); |
| 2982 | assert_non_null(node = node->next); |
| 2983 | assert_string_equal("top", node->name); |
| 2984 | assert_true(node->flags & LYS_CONFIG_W); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2985 | assert_non_null(node = lysc_node_children(node, 0)); |
Radek Krejci | 93dcc39 | 2019-02-19 10:43:38 +0100 | [diff] [blame] | 2986 | assert_string_equal("x", node->name); |
| 2987 | assert_true(node->flags & LYS_CONFIG_W); |
| 2988 | |
Radek Krejci | f1421c2 | 2019-02-19 13:05:20 +0100 | [diff] [blame] | 2989 | assert_non_null(mod = lys_parse_mem(ctx, "module m {namespace urn:m;prefix m;" |
| 2990 | "container a {leaf a {type string;}}" |
| 2991 | "container b {leaf b {mandatory true; type string;}}" |
| 2992 | "deviation /a/a {deviate add {mandatory true;}}" |
| 2993 | "deviation /b/b {deviate replace {mandatory false;}}}", LYS_IN_YANG)); |
| 2994 | assert_non_null(node = mod->compiled->data); |
| 2995 | assert_string_equal("a", node->name); |
| 2996 | assert_true((node->flags & LYS_MAND_MASK) == LYS_MAND_TRUE); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 2997 | assert_true((lysc_node_children(node, 0)->flags & LYS_MAND_MASK) == LYS_MAND_TRUE); |
Radek Krejci | f1421c2 | 2019-02-19 13:05:20 +0100 | [diff] [blame] | 2998 | assert_non_null(node = node->next); |
| 2999 | assert_string_equal("b", node->name); |
| 3000 | assert_false(node->flags & LYS_MAND_MASK); /* just unset on container */ |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 3001 | assert_true((lysc_node_children(node, 0)->flags & LYS_MAND_MASK) == LYS_MAND_FALSE); |
Radek Krejci | f1421c2 | 2019-02-19 13:05:20 +0100 | [diff] [blame] | 3002 | |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3003 | assert_non_null(mod = lys_parse_mem(ctx, "module n {yang-version 1.1; namespace urn:n;prefix n;" |
| 3004 | "leaf a {default test; type string;}" |
| 3005 | "leaf b {mandatory true; type string;}" |
| 3006 | "deviation /a {deviate add {mandatory true;} deviate delete {default test;}}" |
| 3007 | "deviation /b {deviate add {default test;} deviate replace {mandatory false;}}}", LYS_IN_YANG)); |
| 3008 | assert_non_null(node = mod->compiled->data); |
| 3009 | assert_string_equal("a", node->name); |
| 3010 | assert_null(((struct lysc_node_leaf*)node)->dflt); |
| 3011 | assert_true((node->flags & LYS_MAND_MASK) == LYS_MAND_TRUE); |
| 3012 | assert_non_null(node = node->next); |
| 3013 | assert_string_equal("b", node->name); |
| 3014 | assert_non_null(((struct lysc_node_leaf*)node)->dflt); |
| 3015 | assert_true((node->flags & LYS_MAND_MASK) == LYS_MAND_FALSE); |
| 3016 | |
| 3017 | assert_non_null(mod = lys_parse_mem(ctx, "module o {namespace urn:o;prefix o;" |
| 3018 | "leaf-list a {type string;}" |
| 3019 | "list b {config false;}" |
| 3020 | "leaf-list c {min-elements 1; max-elements 10; type string;}" |
| 3021 | "list d {min-elements 10; max-elements 100; config false;}" |
| 3022 | "deviation /a {deviate add {min-elements 1; max-elements 10;}}" |
| 3023 | "deviation /b {deviate add {min-elements 10; max-elements 100;}}" |
| 3024 | "deviation /c {deviate replace {min-elements 10; max-elements 100;}}" |
| 3025 | "deviation /d {deviate replace {min-elements 1; max-elements 10;}}}", LYS_IN_YANG)); |
| 3026 | assert_non_null(node = mod->compiled->data); |
| 3027 | assert_string_equal("a", node->name); |
| 3028 | assert_int_equal(1, ((struct lysc_node_leaflist*)node)->min); |
| 3029 | assert_int_equal(10, ((struct lysc_node_leaflist*)node)->max); |
| 3030 | assert_non_null(node = node->next); |
| 3031 | assert_string_equal("b", node->name); |
| 3032 | assert_int_equal(10, ((struct lysc_node_list*)node)->min); |
| 3033 | assert_int_equal(100, ((struct lysc_node_list*)node)->max); |
| 3034 | assert_non_null(node = node->next); |
| 3035 | assert_string_equal("c", node->name); |
| 3036 | assert_int_equal(10, ((struct lysc_node_leaflist*)node)->min); |
| 3037 | assert_int_equal(100, ((struct lysc_node_leaflist*)node)->max); |
| 3038 | assert_non_null(node = node->next); |
| 3039 | assert_string_equal("d", node->name); |
| 3040 | assert_int_equal(1, ((struct lysc_node_list*)node)->min); |
| 3041 | assert_int_equal(10, ((struct lysc_node_list*)node)->max); |
| 3042 | |
Radek Krejci | 33f7289 | 2019-02-21 10:36:58 +0100 | [diff] [blame] | 3043 | assert_non_null(mod = lys_parse_mem(ctx, "module p {yang-version 1.1; namespace urn:p;prefix p; typedef mytype {type int8; default 1;}" |
| 3044 | "leaf a {type string; default 10;} leaf-list b {type string;}" |
| 3045 | "deviation /a {deviate replace {type mytype;}}" |
| 3046 | "deviation /b {deviate replace {type mytype;}}}", LYS_IN_YANG)); |
| 3047 | assert_non_null(node = mod->compiled->data); |
| 3048 | assert_string_equal("a", node->name); |
| 3049 | assert_int_equal(LY_TYPE_INT8, ((struct lysc_node_leaf*)node)->type->basetype); |
| 3050 | assert_string_equal("10", ((struct lysc_node_leaf*)node)->dflt); |
| 3051 | assert_non_null(node = node->next); |
| 3052 | assert_string_equal("b", node->name); |
| 3053 | assert_int_equal(LY_TYPE_INT8, ((struct lysc_node_leaflist*)node)->type->basetype); |
| 3054 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_node_leaflist*)node)->dflts)); |
| 3055 | assert_string_equal("1", ((struct lysc_node_leaflist*)node)->dflts[0]); |
| 3056 | |
Radek Krejci | 88ef64b | 2019-02-18 16:02:06 +0100 | [diff] [blame] | 3057 | assert_null(lys_parse_mem(ctx, "module aa1 {namespace urn:aa1;prefix aa1;import a {prefix a;}" |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3058 | "deviation /a:top/a:z {deviate not-supported;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3059 | logbuf_assert("Invalid absolute-schema-nodeid value \"/a:top/a:z\" - target node not found. /aa1:{deviation='/a:top/a:z'}"); |
Radek Krejci | 88ef64b | 2019-02-18 16:02:06 +0100 | [diff] [blame] | 3060 | assert_non_null(lys_parse_mem(ctx, "module aa2 {namespace urn:aa2;prefix aa2;import a {prefix a;}" |
| 3061 | "deviation /a:top/a:a {deviate not-supported;}" |
| 3062 | "deviation /a:top/a:a {deviate add {default error;}}}", LYS_IN_YANG)); |
| 3063 | /* warning */ |
| 3064 | logbuf_assert("Useless multiple (2) deviates on node \"/a:top/a:a\" since the node is not-supported."); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3065 | |
| 3066 | assert_null(lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;import a {prefix a;}" |
| 3067 | "deviation a:top/a:a {deviate not-supported;}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3068 | logbuf_assert("Invalid absolute-schema-nodeid value \"a:top/a:a\" - missing starting \"/\". /bb:{deviation='a:top/a:a'}"); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3069 | |
| 3070 | assert_null(lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; container c;" |
| 3071 | "deviation /c {deviate add {units meters;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3072 | logbuf_assert("Invalid deviation of container node - it is not possible to add \"units\" property. /cc:{deviation='/c'}"); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3073 | assert_null(lys_parse_mem(ctx, "module cd {namespace urn:cd;prefix cd; leaf c {type string; units centimeters;}" |
| 3074 | "deviation /c {deviate add {units meters;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3075 | logbuf_assert("Invalid deviation adding \"units\" property which already exists (with value \"centimeters\"). /cd:{deviation='/c'}"); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3076 | |
| 3077 | assert_null(lys_parse_mem(ctx, "module dd1 {namespace urn:dd1;prefix dd1; container c;" |
| 3078 | "deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3079 | logbuf_assert("Invalid deviation of container node - it is not possible to delete \"units\" property. /dd1:{deviation='/c'}"); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3080 | assert_null(lys_parse_mem(ctx, "module dd2 {namespace urn:dd2;prefix dd2; leaf c {type string;}" |
| 3081 | "deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3082 | logbuf_assert("Invalid deviation deleting \"units\" property \"meters\" which is not present. /dd2:{deviation='/c'}"); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3083 | assert_null(lys_parse_mem(ctx, "module dd3 {namespace urn:dd3;prefix dd3; leaf c {type string; units centimeters;}" |
| 3084 | "deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3085 | logbuf_assert("Invalid deviation deleting \"units\" property \"meters\" which does not match the target's property value \"centimeters\"." |
| 3086 | " /dd3:{deviation='/c'}"); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3087 | |
| 3088 | assert_null(lys_parse_mem(ctx, "module ee1 {namespace urn:ee1;prefix ee1; container c;" |
| 3089 | "deviation /c {deviate replace {units meters;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3090 | logbuf_assert("Invalid deviation of container node - it is not possible to replace \"units\" property. /ee1:{deviation='/c'}"); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3091 | assert_null(lys_parse_mem(ctx, "module ee2 {namespace urn:ee2;prefix ee2; leaf c {type string;}" |
| 3092 | "deviation /c {deviate replace {units meters;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3093 | logbuf_assert("Invalid deviation replacing \"units\" property \"meters\" which is not present. /ee2:{deviation='/c'}"); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3094 | |
| 3095 | /* the default is already deleted in /e:a byt module f */ |
| 3096 | assert_null(lys_parse_mem(ctx, "module ff1 {namespace urn:ff1;prefix ff1; import e {prefix e;}" |
| 3097 | "deviation /e:a {deviate delete {default x:a;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3098 | logbuf_assert("Invalid deviation deleting \"default\" property \"x:a\" which is not present. /ff1:{deviation='/e:a'}"); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3099 | assert_null(lys_parse_mem(ctx, "module ff2 {namespace urn:ff2;prefix ff2; import e {prefix e;}" |
| 3100 | "deviation /e:b {deviate delete {default x:a;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3101 | logbuf_assert("Invalid deviation deleting \"default\" property \"x:a\" of choice. " |
| 3102 | "The prefix does not match any imported module of the deviation module. /ff2:{deviation='/e:b'}"); |
Radek Krejci | 88ef64b | 2019-02-18 16:02:06 +0100 | [diff] [blame] | 3103 | assert_null(lys_parse_mem(ctx, "module ff3 {namespace urn:ff3;prefix ff3; import e {prefix e;}" |
| 3104 | "deviation /e:b {deviate delete {default e:b;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3105 | logbuf_assert("Invalid deviation deleting \"default\" property \"e:b\" of choice does not match the default case name \"a\". /ff3:{deviation='/e:b'}"); |
Radek Krejci | 88ef64b | 2019-02-18 16:02:06 +0100 | [diff] [blame] | 3106 | assert_null(lys_parse_mem(ctx, "module ff4 {namespace urn:ff4;prefix ff4; import e {prefix e;}" |
| 3107 | "deviation /e:b {deviate delete {default ff4:a;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3108 | logbuf_assert("Invalid deviation deleting \"default\" property \"ff4:a\" of choice. The prefix does not match the default case's module. /ff4:{deviation='/e:b'}"); |
Radek Krejci | 88ef64b | 2019-02-18 16:02:06 +0100 | [diff] [blame] | 3109 | assert_null(lys_parse_mem(ctx, "module ff5 {namespace urn:ff5;prefix ff5; anyxml a;" |
| 3110 | "deviation /a {deviate delete {default x;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3111 | logbuf_assert("Invalid deviation of anyxml node - it is not possible to delete \"default\" property. /ff5:{deviation='/a'}"); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3112 | |
| 3113 | assert_null(lys_parse_mem(ctx, "module gg1 {namespace urn:gg1;prefix gg1; import e {prefix e;}" |
| 3114 | "deviation /e:b {deviate add {default e:a;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3115 | logbuf_assert("Invalid deviation adding \"default\" property which already exists (with value \"a\"). /gg1:{deviation='/e:b'}"); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3116 | assert_null(lys_parse_mem(ctx, "module gg2 {namespace urn:gg2;prefix gg2; import e {prefix e;}" |
Radek Krejci | 468a94f | 2019-02-15 14:52:36 +0100 | [diff] [blame] | 3117 | "deviation /e:a {deviate add {default x:a;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3118 | logbuf_assert("Invalid deviation adding \"default\" property \"x:a\" of choice. " |
| 3119 | "The prefix does not match any imported module of the deviation module. /gg2:{deviation='/e:a'}"); |
Radek Krejci | 468a94f | 2019-02-15 14:52:36 +0100 | [diff] [blame] | 3120 | assert_null(lys_parse_mem(ctx, "module gg3 {namespace urn:gg3;prefix gg3; import e {prefix e;}" |
| 3121 | "deviation /e:a {deviate add {default a;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3122 | logbuf_assert("Invalid deviation adding \"default\" property \"a\" of choice - the specified case does not exists. /gg3:{deviation='/e:a'}"); |
Radek Krejci | 468a94f | 2019-02-15 14:52:36 +0100 | [diff] [blame] | 3123 | assert_null(lys_parse_mem(ctx, "module gg4 {namespace urn:gg4;prefix gg4; import e {prefix e;}" |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3124 | "deviation /e:c {deviate add {default hi;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3125 | logbuf_assert("Invalid deviation adding \"default\" property which already exists (with value \"hello\"). /gg4:{deviation='/e:c'}"); |
Radek Krejci | 468a94f | 2019-02-15 14:52:36 +0100 | [diff] [blame] | 3126 | assert_null(lys_parse_mem(ctx, "module gg4 {namespace urn:gg4;prefix gg4; import e {prefix e;}" |
| 3127 | "deviation /e:a {deviate add {default e:c;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3128 | logbuf_assert("Invalid deviation adding \"default\" property \"e:c\" of choice - mandatory node \"c\" under the default case. /gg4:{deviation='/e:a'}"); |
Radek Krejci | 88ef64b | 2019-02-18 16:02:06 +0100 | [diff] [blame] | 3129 | assert_null(lys_parse_mem(ctx, "module gg5 {namespace urn:gg5;prefix gg5; leaf x {type string; mandatory true;}" |
| 3130 | "deviation /x {deviate add {default error;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3131 | logbuf_assert("Invalid deviation combining default value and mandatory leaf. /gg5:{deviation='/x'}"); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3132 | |
| 3133 | assert_null(lys_parse_mem(ctx, "module hh1 {yang-version 1.1; namespace urn:hh1;prefix hh1; import e {prefix e;}" |
| 3134 | "deviation /e:d {deviate replace {default hi;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3135 | logbuf_assert("Invalid deviation of leaf-list node - it is not possible to replace \"default\" property. /hh1:{deviation='/e:d'}"); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3136 | |
Radek Krejci | 7af6424 | 2019-02-18 13:07:53 +0100 | [diff] [blame] | 3137 | assert_null(lys_parse_mem(ctx, "module ii1 {namespace urn:ii1;prefix ii1; import i {prefix i;}" |
| 3138 | "deviation /i:l1 {deviate delete {unique x;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3139 | logbuf_assert("Invalid deviation deleting \"unique\" property \"x\" which does not match any of the target's property values. /ii1:{deviation='/i:l1'}"); |
Radek Krejci | 7af6424 | 2019-02-18 13:07:53 +0100 | [diff] [blame] | 3140 | assert_null(lys_parse_mem(ctx, "module ii2 {namespace urn:ii2;prefix ii2; import i {prefix i;} leaf x { type string;}" |
| 3141 | "deviation /i:l2 {deviate delete {unique d;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3142 | logbuf_assert("Invalid deviation deleting \"unique\" property \"d\" which does not match any of the target's property values. /ii2:{deviation='/i:l2'}"); |
Radek Krejci | 7af6424 | 2019-02-18 13:07:53 +0100 | [diff] [blame] | 3143 | assert_null(lys_parse_mem(ctx, "module ii3 {namespace urn:ii3;prefix ii3; leaf x { type string;}" |
| 3144 | "deviation /x {deviate delete {unique d;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3145 | logbuf_assert("Invalid deviation of leaf node - it is not possible to delete \"unique\" property. /ii3:{deviation='/x'}"); |
Radek Krejci | 7af6424 | 2019-02-18 13:07:53 +0100 | [diff] [blame] | 3146 | assert_null(lys_parse_mem(ctx, "module ii4 {namespace urn:ii4;prefix ii4; leaf x { type string;}" |
| 3147 | "deviation /x {deviate add {unique d;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3148 | logbuf_assert("Invalid deviation of leaf node - it is not possible to add \"unique\" property. /ii4:{deviation='/x'}"); |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3149 | |
Radek Krejci | 93dcc39 | 2019-02-19 10:43:38 +0100 | [diff] [blame] | 3150 | assert_null(lys_parse_mem(ctx, "module jj1 {namespace urn:jj1;prefix jj1; choice ch {case a {leaf a{type string;}}}" |
| 3151 | "deviation /ch/a {deviate add {config false;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3152 | logbuf_assert("Invalid deviation of case node - it is not possible to add \"config\" property. /jj1:{deviation='/ch/a'}"); |
Radek Krejci | 93dcc39 | 2019-02-19 10:43:38 +0100 | [diff] [blame] | 3153 | assert_null(lys_parse_mem(ctx, "module jj2 {namespace urn:jj2;prefix jj2; container top {config false; leaf x {type string;}}" |
| 3154 | "deviation /top/x {deviate add {config true;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3155 | logbuf_assert("Invalid deviation of config - configuration node cannot be child of any state data node. /jj2:{deviation='/top/x'}"); |
Radek Krejci | 93dcc39 | 2019-02-19 10:43:38 +0100 | [diff] [blame] | 3156 | assert_null(lys_parse_mem(ctx, "module jj3 {namespace urn:jj3;prefix jj3; container top {leaf x {type string;}}" |
| 3157 | "deviation /top/x {deviate replace {config false;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3158 | logbuf_assert("Invalid deviation replacing \"config\" property \"config false\" which is not present. /jj3:{deviation='/top/x'}"); |
Radek Krejci | 93dcc39 | 2019-02-19 10:43:38 +0100 | [diff] [blame] | 3159 | assert_null(lys_parse_mem(ctx, "module jj4 {namespace urn:jj4;prefix jj4; choice ch {case a {leaf a{type string;}}}" |
| 3160 | "deviation /ch/a {deviate replace {config false;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3161 | logbuf_assert("Invalid deviation of case node - it is not possible to replace \"config\" property. /jj4:{deviation='/ch/a'}"); |
Radek Krejci | 93dcc39 | 2019-02-19 10:43:38 +0100 | [diff] [blame] | 3162 | assert_null(lys_parse_mem(ctx, "module jj5 {namespace urn:jj5;prefix jj5; container top {leaf x {type string; config true;}}" |
| 3163 | "deviation /top {deviate add {config false;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3164 | logbuf_assert("Invalid deviation of config - configuration node cannot be child of any state data node. /jj5:{deviation='/top'}"); |
Radek Krejci | f1421c2 | 2019-02-19 13:05:20 +0100 | [diff] [blame] | 3165 | assert_null(lys_parse_mem(ctx, "module jj6 {namespace urn:jj6;prefix jj6; leaf x {config false; type string;}" |
| 3166 | "deviation /x {deviate add {config true;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3167 | logbuf_assert("Invalid deviation adding \"config\" property which already exists (with value \"config false\"). /jj6:{deviation='/x'}"); |
Radek Krejci | f1421c2 | 2019-02-19 13:05:20 +0100 | [diff] [blame] | 3168 | |
| 3169 | assert_null(lys_parse_mem(ctx, "module kk1 {namespace urn:kk1;prefix kk1; container top {leaf a{type string;}}" |
| 3170 | "deviation /top {deviate add {mandatory true;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3171 | logbuf_assert("Invalid deviation of mandatory - container cannot hold mandatory statement. /kk1:{deviation='/top'}"); |
Radek Krejci | f1421c2 | 2019-02-19 13:05:20 +0100 | [diff] [blame] | 3172 | assert_null(lys_parse_mem(ctx, "module kk2 {namespace urn:kk2;prefix kk2; container top {leaf a{type string;}}" |
| 3173 | "deviation /top {deviate replace {mandatory true;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3174 | logbuf_assert("Invalid deviation replacing \"mandatory\" property \"mandatory true\" which is not present. /kk2:{deviation='/top'}"); |
Radek Krejci | f1421c2 | 2019-02-19 13:05:20 +0100 | [diff] [blame] | 3175 | assert_null(lys_parse_mem(ctx, "module kk3 {namespace urn:kk3;prefix kk3; container top {leaf x {type string;}}" |
| 3176 | "deviation /top/x {deviate replace {mandatory true;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3177 | logbuf_assert("Invalid deviation replacing \"mandatory\" property \"mandatory true\" which is not present. /kk3:{deviation='/top/x'}"); |
Radek Krejci | f1421c2 | 2019-02-19 13:05:20 +0100 | [diff] [blame] | 3178 | assert_null(lys_parse_mem(ctx, "module kk4 {namespace urn:kk4;prefix kk4; leaf x {mandatory true; type string;}" |
| 3179 | "deviation /x {deviate add {mandatory false;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3180 | logbuf_assert("Invalid deviation adding \"mandatory\" property which already exists (with value \"mandatory true\"). /kk4:{deviation='/x'}"); |
Radek Krejci | 93dcc39 | 2019-02-19 10:43:38 +0100 | [diff] [blame] | 3181 | |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3182 | assert_null(lys_parse_mem(ctx, "module ll1 {namespace urn:ll1;prefix ll1; leaf x {default test; type string;}" |
| 3183 | "deviation /x {deviate add {mandatory true;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3184 | logbuf_assert("Invalid deviation combining default value and mandatory leaf. /ll1:{deviation='/x'}"); |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3185 | assert_null(lys_parse_mem(ctx, "module ll2 {yang-version 1.1; namespace urn:ll2;prefix ll2; leaf-list x {default test; type string;}" |
| 3186 | "deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3187 | logbuf_assert("Invalid deviation combining default value and mandatory leaf-list. /ll2:{deviation='/x'}"); |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3188 | assert_null(lys_parse_mem(ctx, "module ll2 {namespace urn:ll2;prefix ll2; choice ch {default a; leaf a {type string;} leaf b {type string;}}" |
| 3189 | "deviation /ch {deviate add {mandatory true;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3190 | logbuf_assert("Invalid deviation combining default case and mandatory choice. /ll2:{deviation='/ch'}"); |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3191 | |
| 3192 | assert_null(lys_parse_mem(ctx, "module mm1 {namespace urn:mm1;prefix mm1; leaf-list x {min-elements 10; type string;}" |
| 3193 | "deviation /x {deviate add {max-elements 5;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3194 | logbuf_assert("Invalid combination of min-elements and max-elements after deviation: min value 10 is bigger than max value 5. /mm1:{deviation='/x'}"); |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3195 | assert_null(lys_parse_mem(ctx, "module mm2 {namespace urn:mm2;prefix mm2; leaf-list x {max-elements 10; type string;}" |
| 3196 | "deviation /x {deviate add {min-elements 20;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3197 | logbuf_assert("Invalid combination of min-elements and max-elements after deviation: min value 20 is bigger than max value 10. /mm2:{deviation='/x'}"); |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3198 | assert_null(lys_parse_mem(ctx, "module mm3 {namespace urn:mm3;prefix mm3; list x {min-elements 5; max-elements 10; config false;}" |
| 3199 | "deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3200 | logbuf_assert("Invalid combination of min-elements and max-elements after deviation: min value 5 is bigger than max value 1. /mm3:{deviation='/x'}"); |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3201 | assert_null(lys_parse_mem(ctx, "module mm4 {namespace urn:mm4;prefix mm4; list x {min-elements 5; max-elements 10; config false;}" |
| 3202 | "deviation /x {deviate replace {min-elements 20;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3203 | logbuf_assert("Invalid combination of min-elements and max-elements after deviation: min value 20 is bigger than max value 10. /mm4:{deviation='/x'}"); |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3204 | assert_null(lys_parse_mem(ctx, "module mm5 {namespace urn:mm5;prefix mm5; leaf-list x {type string; min-elements 5;}" |
| 3205 | "deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3206 | logbuf_assert("Invalid deviation adding \"min-elements\" property which already exists (with value \"5\"). /mm5:{deviation='/x'}"); |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3207 | assert_null(lys_parse_mem(ctx, "module mm6 {namespace urn:mm6;prefix mm6; list x {config false; min-elements 5;}" |
| 3208 | "deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3209 | logbuf_assert("Invalid deviation adding \"min-elements\" property which already exists (with value \"5\"). /mm6:{deviation='/x'}"); |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3210 | assert_null(lys_parse_mem(ctx, "module mm7 {namespace urn:mm7;prefix mm7; leaf-list x {type string; max-elements 5;}" |
| 3211 | "deviation /x {deviate add {max-elements 1;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3212 | logbuf_assert("Invalid deviation adding \"max-elements\" property which already exists (with value \"5\"). /mm7:{deviation='/x'}"); |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3213 | assert_null(lys_parse_mem(ctx, "module mm8 {namespace urn:mm8;prefix mm8; list x {config false; max-elements 5;}" |
| 3214 | "deviation /x {deviate add {max-elements 1;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3215 | logbuf_assert("Invalid deviation adding \"max-elements\" property which already exists (with value \"5\"). /mm8:{deviation='/x'}"); |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3216 | assert_null(lys_parse_mem(ctx, "module mm9 {namespace urn:mm9;prefix mm9; leaf-list x {type string;}" |
| 3217 | "deviation /x {deviate replace {min-elements 1;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3218 | logbuf_assert("Invalid deviation replacing with \"min-elements\" property \"1\" which is not present. /mm9:{deviation='/x'}"); |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3219 | assert_null(lys_parse_mem(ctx, "module mm10 {namespace urn:mm10;prefix mm10; list x {config false;}" |
| 3220 | "deviation /x {deviate replace {min-elements 1;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3221 | logbuf_assert("Invalid deviation replacing with \"min-elements\" property \"1\" which is not present. /mm10:{deviation='/x'}"); |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3222 | assert_null(lys_parse_mem(ctx, "module mm11 {namespace urn:mm11;prefix mm11; leaf-list x {type string;}" |
| 3223 | "deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3224 | logbuf_assert("Invalid deviation replacing with \"max-elements\" property \"1\" which is not present. /mm11:{deviation='/x'}"); |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3225 | assert_null(lys_parse_mem(ctx, "module mm12 {namespace urn:mm12;prefix mm12; list x {config false; }" |
| 3226 | "deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3227 | logbuf_assert("Invalid deviation replacing with \"max-elements\" property \"1\" which is not present. /mm12:{deviation='/x'}"); |
Radek Krejci | 551b12c | 2019-02-19 16:11:21 +0100 | [diff] [blame] | 3228 | |
Radek Krejci | 33f7289 | 2019-02-21 10:36:58 +0100 | [diff] [blame] | 3229 | assert_null(lys_parse_mem(ctx, "module nn1 {namespace urn:nn1;prefix nn1; anyxml x;" |
| 3230 | "deviation /x {deviate replace {type string;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3231 | logbuf_assert("Invalid deviation of anyxml node - it is not possible to replace \"type\" property. /nn1:{deviation='/x'}"); |
Radek Krejci | 33f7289 | 2019-02-21 10:36:58 +0100 | [diff] [blame] | 3232 | assert_null(lys_parse_mem(ctx, "module nn2 {namespace urn:nn2;prefix nn2; leaf-list x {type string;}" |
| 3233 | "deviation /x {deviate replace {type empty;}}}", LYS_IN_YANG)); |
Radek Krejci | 327de16 | 2019-06-14 12:52:07 +0200 | [diff] [blame] | 3234 | logbuf_assert("Leaf-list of type \"empty\" is allowed only in YANG 1.1 modules. /nn2:{deviation='/x'}"); |
Radek Krejci | 33f7289 | 2019-02-21 10:36:58 +0100 | [diff] [blame] | 3235 | |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3236 | *state = NULL; |
| 3237 | ly_ctx_destroy(ctx, NULL); |
| 3238 | } |
| 3239 | |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 3240 | int main(void) |
| 3241 | { |
| 3242 | const struct CMUnitTest tests[] = { |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 3243 | cmocka_unit_test_setup_teardown(test_module, logger_setup, logger_teardown), |
| 3244 | cmocka_unit_test_setup_teardown(test_feature, logger_setup, logger_teardown), |
| 3245 | cmocka_unit_test_setup_teardown(test_identity, logger_setup, logger_teardown), |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 3246 | cmocka_unit_test_setup_teardown(test_type_length, logger_setup, logger_teardown), |
| 3247 | cmocka_unit_test_setup_teardown(test_type_range, logger_setup, logger_teardown), |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 3248 | cmocka_unit_test_setup_teardown(test_type_pattern, logger_setup, logger_teardown), |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 3249 | cmocka_unit_test_setup_teardown(test_type_enum, logger_setup, logger_teardown), |
| 3250 | cmocka_unit_test_setup_teardown(test_type_bits, logger_setup, logger_teardown), |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 3251 | cmocka_unit_test_setup_teardown(test_type_dec64, logger_setup, logger_teardown), |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 3252 | cmocka_unit_test_setup_teardown(test_type_instanceid, logger_setup, logger_teardown), |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 3253 | cmocka_unit_test_setup_teardown(test_type_identityref, logger_setup, logger_teardown), |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 3254 | cmocka_unit_test_setup_teardown(test_type_leafref, logger_setup, logger_teardown), |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 3255 | cmocka_unit_test_setup_teardown(test_type_empty, logger_setup, logger_teardown), |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 3256 | cmocka_unit_test_setup_teardown(test_type_union, logger_setup, logger_teardown), |
| 3257 | cmocka_unit_test_setup_teardown(test_type_dflt, logger_setup, logger_teardown), |
Radek Krejci | 665421c | 2018-12-05 08:03:39 +0100 | [diff] [blame] | 3258 | cmocka_unit_test_setup_teardown(test_status, logger_setup, logger_teardown), |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 3259 | cmocka_unit_test_setup_teardown(test_node_container, logger_setup, logger_teardown), |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 3260 | cmocka_unit_test_setup_teardown(test_node_leaflist, logger_setup, logger_teardown), |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 3261 | cmocka_unit_test_setup_teardown(test_node_list, logger_setup, logger_teardown), |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 3262 | cmocka_unit_test_setup_teardown(test_node_choice, logger_setup, logger_teardown), |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 3263 | cmocka_unit_test_setup_teardown(test_node_anydata, logger_setup, logger_teardown), |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 3264 | cmocka_unit_test_setup_teardown(test_action, logger_setup, logger_teardown), |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 3265 | cmocka_unit_test_setup_teardown(test_notification, logger_setup, logger_teardown), |
Radek Krejci | f2de0ed | 2019-05-02 14:13:18 +0200 | [diff] [blame] | 3266 | cmocka_unit_test_setup_teardown(test_grouping, logger_setup, logger_teardown), |
Radek Krejci | e86bf77 | 2018-12-14 11:39:53 +0100 | [diff] [blame] | 3267 | cmocka_unit_test_setup_teardown(test_uses, logger_setup, logger_teardown), |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 3268 | cmocka_unit_test_setup_teardown(test_refine, logger_setup, logger_teardown), |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 3269 | cmocka_unit_test_setup_teardown(test_augment, logger_setup, logger_teardown), |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 3270 | cmocka_unit_test_setup_teardown(test_deviation, logger_setup, logger_teardown), |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 3271 | }; |
| 3272 | |
| 3273 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 3274 | } |