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