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 | f3f4784 | 2018-11-15 11:22:15 +0100 | [diff] [blame] | 15 | #include "../../src/common.c" |
| 16 | #include "../../src/log.c" |
| 17 | #include "../../src/set.c" |
| 18 | #include "../../src/xpath.c" |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 19 | #include "../../src/parser_yang.c" |
Radek Krejci | f3f4784 | 2018-11-15 11:22:15 +0100 | [diff] [blame] | 20 | #include "../../src/tree_schema_helpers.c" |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 21 | #include "../../src/tree_schema_free.c" |
| 22 | #include "../../src/tree_schema_compile.c" |
Radek Krejci | f3f4784 | 2018-11-15 11:22:15 +0100 | [diff] [blame] | 23 | #include "../../src/tree_schema.c" |
| 24 | #include "../../src/context.c" |
| 25 | #include "../../src/hash_table.c" |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 26 | |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 27 | #include <stdarg.h> |
| 28 | #include <stddef.h> |
| 29 | #include <setjmp.h> |
| 30 | #include <cmocka.h> |
| 31 | |
| 32 | #include <stdio.h> |
| 33 | #include <string.h> |
| 34 | |
| 35 | #include "libyang.h" |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 36 | |
| 37 | #define BUFSIZE 1024 |
| 38 | char logbuf[BUFSIZE] = {0}; |
| 39 | |
| 40 | /* set to 0 to printing error messages to stderr instead of checking them in code */ |
| 41 | #define ENABLE_LOGGER_CHECKING 1 |
| 42 | |
| 43 | #if ENABLE_LOGGER_CHECKING |
| 44 | static void |
| 45 | logger(LY_LOG_LEVEL level, const char *msg, const char *path) |
| 46 | { |
| 47 | (void) level; /* unused */ |
| 48 | |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 49 | if (path && path[0]) { |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 50 | snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path); |
| 51 | } else { |
| 52 | strncpy(logbuf, msg, BUFSIZE - 1); |
| 53 | } |
| 54 | } |
| 55 | #endif |
| 56 | |
| 57 | static int |
| 58 | logger_setup(void **state) |
| 59 | { |
| 60 | (void) state; /* unused */ |
| 61 | #if ENABLE_LOGGER_CHECKING |
| 62 | ly_set_log_clb(logger, 1); |
| 63 | #endif |
| 64 | return 0; |
| 65 | } |
| 66 | |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 67 | static int |
| 68 | logger_teardown(void **state) |
| 69 | { |
| 70 | (void) state; /* unused */ |
| 71 | #if ENABLE_LOGGER_CHECKING |
| 72 | if (*state) { |
| 73 | fprintf(stderr, "%s\n", logbuf); |
| 74 | } |
| 75 | #endif |
| 76 | return 0; |
| 77 | } |
| 78 | |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 79 | void |
| 80 | logbuf_clean(void) |
| 81 | { |
| 82 | logbuf[0] = '\0'; |
| 83 | } |
| 84 | |
| 85 | #if ENABLE_LOGGER_CHECKING |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 86 | # define logbuf_assert(str) assert_string_equal(logbuf, str);logbuf_clean() |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 87 | #else |
| 88 | # define logbuf_assert(str) |
| 89 | #endif |
| 90 | |
| 91 | static void |
| 92 | test_module(void **state) |
| 93 | { |
| 94 | (void) state; /* unused */ |
| 95 | |
| 96 | const char *str; |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 97 | struct ly_parser_ctx ctx = {0}; |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 98 | struct lys_module mod = {0}; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 99 | struct lysc_feature *f; |
| 100 | struct lysc_iffeature *iff; |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 101 | |
| 102 | str = "module test {namespace urn:test; prefix t;" |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 103 | "feature f1;feature f2 {if-feature f1;}}"; |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 104 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 105 | |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 106 | assert_int_equal(LY_EINVAL, lys_compile(NULL, 0)); |
| 107 | logbuf_assert("Invalid argument mod (lys_compile())."); |
| 108 | assert_int_equal(LY_EINVAL, lys_compile(&mod, 0)); |
| 109 | logbuf_assert("Invalid argument mod->parsed (lys_compile())."); |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 110 | assert_int_equal(LY_SUCCESS, yang_parse(&ctx, str, &mod.parsed)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 111 | assert_int_equal(LY_SUCCESS, lys_compile(&mod, 0)); |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 112 | assert_non_null(mod.compiled); |
| 113 | assert_ptr_equal(mod.parsed->name, mod.compiled->name); |
| 114 | assert_ptr_equal(mod.parsed->ns, mod.compiled->ns); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 115 | /* features */ |
| 116 | assert_non_null(mod.compiled->features); |
| 117 | assert_int_equal(2, LY_ARRAY_SIZE(mod.compiled->features)); |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 118 | f = &mod.compiled->features[1]; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 119 | assert_non_null(f->iffeatures); |
| 120 | assert_int_equal(1, LY_ARRAY_SIZE(f->iffeatures)); |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 121 | iff = &f->iffeatures[0]; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 122 | assert_non_null(iff->expr); |
| 123 | assert_non_null(iff->features); |
| 124 | assert_int_equal(1, LY_ARRAY_SIZE(iff->features)); |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 125 | assert_ptr_equal(&mod.compiled->features[0], iff->features[0]); |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 126 | |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 127 | lysc_module_free(mod.compiled, NULL); |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 128 | |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 129 | assert_int_equal(LY_SUCCESS, lys_compile(&mod, LYSC_OPT_FREE_SP)); |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 130 | assert_non_null(mod.compiled); |
| 131 | assert_string_equal("test", mod.compiled->name); |
| 132 | assert_string_equal("urn:test", mod.compiled->ns); |
| 133 | |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 134 | lysc_module_free(mod.compiled, NULL); |
| 135 | mod.compiled = NULL; |
| 136 | |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 137 | /* submodules cannot be compiled directly */ |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 138 | str = "submodule test {belongs-to xxx {prefix x;}}"; |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 139 | assert_int_equal(LY_SUCCESS, yang_parse(&ctx, str, &mod.parsed)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 140 | assert_int_equal(LY_EINVAL, lys_compile(&mod, 0)); |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 141 | logbuf_assert("Submodules (test) are not supposed to be compiled, compile only the main modules."); |
| 142 | assert_null(mod.compiled); |
| 143 | |
| 144 | lysp_module_free(mod.parsed); |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 145 | ly_ctx_destroy(ctx.ctx, NULL); |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 146 | } |
| 147 | |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 148 | static void |
| 149 | test_feature(void **state) |
| 150 | { |
| 151 | (void) state; /* unused */ |
| 152 | |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 153 | struct ly_parser_ctx ctx = {0}; |
Radek Krejci | 1aefdf7 | 2018-11-01 11:01:39 +0100 | [diff] [blame] | 154 | struct lys_module mod = {0}, *modp; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 155 | const char *str; |
| 156 | struct lysc_feature *f, *f1; |
| 157 | |
| 158 | str = "module a {namespace urn:a;prefix a;yang-version 1.1;\n" |
| 159 | "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] | 160 | "feature orfeature {if-feature \"f1 or f2\";}\n" |
| 161 | "feature andfeature {if-feature \"f1 and f2\";}\n" |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 162 | "feature f6 {if-feature \"not f1\";}\n" |
Radek Krejci | dde18c5 | 2018-10-24 14:43:04 +0200 | [diff] [blame] | 163 | "feature f7 {if-feature \"(f2 and f3) or (not f1)\";}\n" |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 164 | "feature f8 {if-feature \"f1 or f2 or f3 or orfeature or andfeature\";}\n" |
| 165 | "feature f9 {if-feature \"not not f1\";}}"; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 166 | |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 167 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx)); |
| 168 | assert_int_equal(LY_SUCCESS, yang_parse(&ctx, str, &mod.parsed)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 169 | assert_int_equal(LY_SUCCESS, lys_compile(&mod, 0)); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 170 | assert_non_null(mod.compiled); |
| 171 | assert_non_null(mod.compiled->features); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 172 | assert_int_equal(9, LY_ARRAY_SIZE(mod.compiled->features)); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 173 | /* all features are disabled by default */ |
| 174 | LY_ARRAY_FOR(mod.compiled->features, struct lysc_feature, f) { |
| 175 | assert_int_equal(0, lysc_feature_value(f)); |
| 176 | } |
| 177 | /* enable f1 */ |
| 178 | assert_int_equal(LY_SUCCESS, lys_feature_enable(&mod, "f1")); |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 179 | f1 = &mod.compiled->features[0]; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 180 | assert_int_equal(1, lysc_feature_value(f1)); |
| 181 | |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 182 | /* enable orfeature */ |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 183 | f = &mod.compiled->features[3]; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 184 | assert_int_equal(0, lysc_feature_value(f)); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 185 | assert_int_equal(LY_SUCCESS, lys_feature_enable(&mod, "orfeature")); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 186 | assert_int_equal(1, lysc_feature_value(f)); |
| 187 | |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 188 | /* enable andfeature - no possible since f2 is disabled */ |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 189 | f = &mod.compiled->features[4]; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 190 | assert_int_equal(0, lysc_feature_value(f)); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 191 | assert_int_equal(LY_EDENIED, lys_feature_enable(&mod, "andfeature")); |
| 192 | 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] | 193 | assert_int_equal(0, lysc_feature_value(f)); |
| 194 | |
| 195 | /* first enable f2, so f5 can be enabled then */ |
| 196 | assert_int_equal(LY_SUCCESS, lys_feature_enable(&mod, "f2")); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 197 | assert_int_equal(LY_SUCCESS, lys_feature_enable(&mod, "andfeature")); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 198 | assert_int_equal(1, lysc_feature_value(f)); |
| 199 | |
| 200 | /* f1 is enabled, so f6 cannot be enabled */ |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 201 | f = &mod.compiled->features[5]; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 202 | assert_int_equal(0, lysc_feature_value(f)); |
| 203 | assert_int_equal(LY_EDENIED, lys_feature_enable(&mod, "f6")); |
| 204 | logbuf_assert("Feature \"f6\" cannot be enabled since it is disabled by its if-feature condition(s)."); |
| 205 | assert_int_equal(0, lysc_feature_value(f)); |
| 206 | |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 207 | /* so disable f1 - andfeature will became also disabled */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 208 | assert_int_equal(1, lysc_feature_value(f1)); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 209 | assert_int_equal(LY_SUCCESS, lys_feature_disable(&mod, "f1")); |
| 210 | assert_int_equal(0, lysc_feature_value(f1)); |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 211 | assert_int_equal(0, lysc_feature_value(&mod.compiled->features[4])); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 212 | /* while orfeature is stille enabled */ |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 213 | assert_int_equal(1, lysc_feature_value(&mod.compiled->features[3])); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 214 | /* and finally f6 can be enabled */ |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 215 | assert_int_equal(LY_SUCCESS, lys_feature_enable(&mod, "f6")); |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 216 | assert_int_equal(1, lysc_feature_value(&mod.compiled->features[5])); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 217 | |
| 218 | /* 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] | 219 | 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] | 220 | /* long evaluation of f8 to need to reallocate internal stack for operators */ |
| 221 | 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] | 222 | |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 223 | /* double negation of disabled f1 -> disabled */ |
| 224 | assert_int_equal(0, lysc_iffeature_value(&mod.compiled->features[8].iffeatures[0])); |
| 225 | |
Radek Krejci | 3892028 | 2018-11-01 09:24:16 +0100 | [diff] [blame] | 226 | /* disable all features */ |
| 227 | assert_int_equal(LY_SUCCESS, lys_feature_disable(&mod, "*")); |
| 228 | LY_ARRAY_FOR(mod.compiled->features, struct lysc_feature, f) { |
| 229 | assert_int_equal(0, lys_feature_value(&mod, f->name)); |
| 230 | } |
| 231 | /* re-setting already set feature */ |
| 232 | assert_int_equal(LY_SUCCESS, lys_feature_disable(&mod, "f1")); |
| 233 | assert_int_equal(0, lys_feature_value(&mod, "f1")); |
| 234 | |
| 235 | /* enabling feature that cannot be enabled due to its if-features */ |
Radek Krejci | 1aefdf7 | 2018-11-01 11:01:39 +0100 | [diff] [blame] | 236 | assert_int_equal(LY_SUCCESS, lys_feature_enable(&mod, "f1")); |
| 237 | assert_int_equal(LY_EDENIED, lys_feature_enable(&mod, "andfeature")); |
| 238 | 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] | 239 | assert_int_equal(LY_EDENIED, lys_feature_enable(&mod, "*")); |
| 240 | 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] | 241 | /* test if not changed */ |
| 242 | assert_int_equal(1, lys_feature_value(&mod, "f1")); |
| 243 | assert_int_equal(0, lys_feature_value(&mod, "f2")); |
Radek Krejci | 3892028 | 2018-11-01 09:24:16 +0100 | [diff] [blame] | 244 | |
Radek Krejci | 1aefdf7 | 2018-11-01 11:01:39 +0100 | [diff] [blame] | 245 | /* invalid reference */ |
Radek Krejci | 3892028 | 2018-11-01 09:24:16 +0100 | [diff] [blame] | 246 | assert_int_equal(LY_EINVAL, lys_feature_enable(&mod, "xxx")); |
| 247 | logbuf_assert("Feature \"xxx\" not found in module \"a\"."); |
| 248 | |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 249 | lysc_module_free(mod.compiled, NULL); |
| 250 | lysp_module_free(mod.parsed); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 251 | |
| 252 | /* some invalid expressions */ |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 253 | assert_int_equal(LY_SUCCESS, yang_parse(&ctx, "module b{yang-version 1.1;namespace urn:b; prefix b; feature f{if-feature f1;}}", &mod.parsed)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 254 | assert_int_equal(LY_EVALID, lys_compile(&mod, 0)); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 255 | logbuf_assert("Invalid value \"f1\" of if-feature - unable to find feature \"f1\"."); |
| 256 | lysp_module_free(mod.parsed); |
| 257 | |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 258 | assert_int_equal(LY_SUCCESS, yang_parse(&ctx, "module b{yang-version 1.1;namespace urn:b; prefix b; feature f1; feature f2{if-feature 'f and';}}", &mod.parsed)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 259 | assert_int_equal(LY_EVALID, lys_compile(&mod, 0)); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 260 | logbuf_assert("Invalid value \"f and\" of if-feature - unexpected end of expression."); |
| 261 | lysp_module_free(mod.parsed); |
| 262 | |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 263 | assert_int_equal(LY_SUCCESS, yang_parse(&ctx, "module b{yang-version 1.1;namespace urn:b; prefix b; feature f{if-feature 'or';}}", &mod.parsed)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 264 | assert_int_equal(LY_EVALID, lys_compile(&mod, 0)); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 265 | logbuf_assert("Invalid value \"or\" of if-feature - unexpected end of expression."); |
| 266 | lysp_module_free(mod.parsed); |
| 267 | |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 268 | assert_int_equal(LY_SUCCESS, yang_parse(&ctx, "module b{yang-version 1.1;namespace urn:b; prefix b; feature f1; feature f2{if-feature '(f1';}}", &mod.parsed)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 269 | assert_int_equal(LY_EVALID, lys_compile(&mod, 0)); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 270 | logbuf_assert("Invalid value \"(f1\" of if-feature - non-matching opening and closing parentheses."); |
| 271 | lysp_module_free(mod.parsed); |
| 272 | |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 273 | assert_int_equal(LY_SUCCESS, yang_parse(&ctx, "module b{yang-version 1.1;namespace urn:b; prefix b; feature f1; feature f2{if-feature 'f1)';}}", &mod.parsed)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 274 | assert_int_equal(LY_EVALID, lys_compile(&mod, 0)); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 275 | logbuf_assert("Invalid value \"f1)\" of if-feature - non-matching opening and closing parentheses."); |
| 276 | lysp_module_free(mod.parsed); |
| 277 | |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 278 | assert_int_equal(LY_SUCCESS, yang_parse(&ctx, "module b{yang-version 1.1;namespace urn:b; prefix b; feature f1; feature f2{if-feature ---;}}", &mod.parsed)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 279 | assert_int_equal(LY_EVALID, lys_compile(&mod, 0)); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 280 | logbuf_assert("Invalid value \"---\" of if-feature - unable to find feature \"---\"."); |
| 281 | lysp_module_free(mod.parsed); |
| 282 | |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 283 | assert_int_equal(LY_SUCCESS, yang_parse(&ctx, "module b{namespace urn:b; prefix b; feature f1; feature f2{if-feature 'not f1';}}", &mod.parsed)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 284 | assert_int_equal(LY_EVALID, lys_compile(&mod, 0)); |
Radek Krejci | 87616bb | 2018-10-31 13:30:52 +0100 | [diff] [blame] | 285 | logbuf_assert("Invalid value \"not f1\" of if-feature - YANG 1.1 expression in YANG 1.0 module."); |
| 286 | lysp_module_free(mod.parsed); |
| 287 | |
Radek Krejci | 1aefdf7 | 2018-11-01 11:01:39 +0100 | [diff] [blame] | 288 | /* import reference */ |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 289 | assert_non_null(modp = lys_parse_mem(ctx.ctx, str, LYS_IN_YANG)); |
Radek Krejci | 1aefdf7 | 2018-11-01 11:01:39 +0100 | [diff] [blame] | 290 | assert_int_equal(LY_SUCCESS, lys_compile(modp, 0)); |
| 291 | assert_int_equal(LY_SUCCESS, lys_feature_enable(modp, "f1")); |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 292 | assert_non_null(modp = lys_parse_mem(ctx.ctx, "module b{namespace urn:b; prefix b; 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] | 293 | assert_int_equal(LY_SUCCESS, lys_compile(modp, 0)); |
| 294 | assert_int_equal(LY_SUCCESS, lys_feature_enable(modp, "f2")); |
| 295 | assert_int_equal(0, lys_feature_value(modp, "f1")); |
| 296 | assert_int_equal(1, lys_feature_value(modp, "f2")); |
| 297 | |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 298 | ly_ctx_destroy(ctx.ctx, NULL); |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 299 | } |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 300 | |
Radek Krejci | 478020e | 2018-10-30 16:02:14 +0100 | [diff] [blame] | 301 | static void |
| 302 | test_identity(void **state) |
| 303 | { |
Radek Krejci | 7f2a536 | 2018-11-28 13:05:37 +0100 | [diff] [blame] | 304 | *state = test_identity; |
Radek Krejci | 478020e | 2018-10-30 16:02:14 +0100 | [diff] [blame] | 305 | |
| 306 | struct ly_ctx *ctx; |
Radek Krejci | 1aefdf7 | 2018-11-01 11:01:39 +0100 | [diff] [blame] | 307 | struct lys_module *mod1, *mod2; |
Radek Krejci | 478020e | 2018-10-30 16:02:14 +0100 | [diff] [blame] | 308 | const char *mod1_str = "module a {namespace urn:a;prefix a; identity a1;}"; |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 309 | const char *mod2_str = "module b {yang-version 1.1;namespace urn:b;prefix b; import a {prefix a;}identity b1; identity b2; identity b3 {base b1; base b:b2; base a:a1;} identity b4 {base b:b1; base b3;}}"; |
Radek Krejci | 478020e | 2018-10-30 16:02:14 +0100 | [diff] [blame] | 310 | |
| 311 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 312 | assert_non_null(mod1 = lys_parse_mem(ctx, mod1_str, LYS_IN_YANG)); |
| 313 | assert_non_null(mod2 = lys_parse_mem(ctx, mod2_str, LYS_IN_YANG)); |
Radek Krejci | 7f2a536 | 2018-11-28 13:05:37 +0100 | [diff] [blame] | 314 | assert_int_equal(LY_SUCCESS, lys_compile(mod1, 0)); |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 315 | assert_int_equal(LY_SUCCESS, lys_compile(mod2, 0)); |
Radek Krejci | 478020e | 2018-10-30 16:02:14 +0100 | [diff] [blame] | 316 | |
| 317 | assert_non_null(mod1->compiled); |
| 318 | assert_non_null(mod1->compiled->identities); |
| 319 | assert_non_null(mod2->compiled); |
| 320 | assert_non_null(mod2->compiled->identities); |
| 321 | |
| 322 | assert_non_null(mod1->compiled->identities[0].derived); |
| 323 | assert_int_equal(1, LY_ARRAY_SIZE(mod1->compiled->identities[0].derived)); |
| 324 | assert_ptr_equal(mod1->compiled->identities[0].derived[0], &mod2->compiled->identities[2]); |
| 325 | assert_non_null(mod2->compiled->identities[0].derived); |
| 326 | assert_int_equal(2, LY_ARRAY_SIZE(mod2->compiled->identities[0].derived)); |
| 327 | assert_ptr_equal(mod2->compiled->identities[0].derived[0], &mod2->compiled->identities[2]); |
| 328 | assert_ptr_equal(mod2->compiled->identities[0].derived[1], &mod2->compiled->identities[3]); |
| 329 | assert_non_null(mod2->compiled->identities[1].derived); |
| 330 | assert_int_equal(1, LY_ARRAY_SIZE(mod2->compiled->identities[1].derived)); |
| 331 | assert_ptr_equal(mod2->compiled->identities[1].derived[0], &mod2->compiled->identities[2]); |
| 332 | assert_non_null(mod2->compiled->identities[2].derived); |
| 333 | assert_int_equal(1, LY_ARRAY_SIZE(mod2->compiled->identities[2].derived)); |
| 334 | assert_ptr_equal(mod2->compiled->identities[2].derived[0], &mod2->compiled->identities[3]); |
| 335 | |
Radek Krejci | 7f2a536 | 2018-11-28 13:05:37 +0100 | [diff] [blame] | 336 | *state = NULL; |
Radek Krejci | 478020e | 2018-10-30 16:02:14 +0100 | [diff] [blame] | 337 | ly_ctx_destroy(ctx, NULL); |
| 338 | } |
| 339 | |
Radek Krejci | bd8d9ba | 2018-11-02 16:06:26 +0100 | [diff] [blame] | 340 | static void |
| 341 | test_node_container(void **state) |
| 342 | { |
| 343 | (void) state; /* unused */ |
| 344 | |
| 345 | struct ly_ctx *ctx; |
| 346 | struct lys_module *mod; |
| 347 | struct lysc_node_container *cont; |
| 348 | |
| 349 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 350 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;container c;}", LYS_IN_YANG)); |
| 351 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 352 | assert_non_null(mod->compiled); |
| 353 | assert_non_null((cont = (struct lysc_node_container*)mod->compiled->data)); |
| 354 | assert_int_equal(LYS_CONTAINER, cont->nodetype); |
| 355 | assert_string_equal("c", cont->name); |
| 356 | assert_true(cont->flags & LYS_CONFIG_W); |
| 357 | assert_true(cont->flags & LYS_STATUS_CURR); |
| 358 | |
Radek Krejci | 98094b3 | 2018-11-02 16:21:47 +0100 | [diff] [blame] | 359 | 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 | bd8d9ba | 2018-11-02 16:06:26 +0100 | [diff] [blame] | 360 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
Radek Krejci | 98094b3 | 2018-11-02 16:21:47 +0100 | [diff] [blame] | 361 | 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] | 362 | assert_non_null(mod->compiled); |
| 363 | assert_non_null((cont = (struct lysc_node_container*)mod->compiled->data)); |
| 364 | assert_true(cont->flags & LYS_CONFIG_R); |
Radek Krejci | 98094b3 | 2018-11-02 16:21:47 +0100 | [diff] [blame] | 365 | assert_true(cont->flags & LYS_STATUS_DEPRC); |
Radek Krejci | bd8d9ba | 2018-11-02 16:06:26 +0100 | [diff] [blame] | 366 | assert_non_null((cont = (struct lysc_node_container*)cont->child)); |
| 367 | assert_int_equal(LYS_CONTAINER, cont->nodetype); |
| 368 | assert_true(cont->flags & LYS_CONFIG_R); |
Radek Krejci | 98094b3 | 2018-11-02 16:21:47 +0100 | [diff] [blame] | 369 | assert_true(cont->flags & LYS_STATUS_DEPRC); |
Radek Krejci | bd8d9ba | 2018-11-02 16:06:26 +0100 | [diff] [blame] | 370 | assert_string_equal("child", cont->name); |
| 371 | |
| 372 | ly_ctx_destroy(ctx, NULL); |
| 373 | } |
| 374 | |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 375 | static void |
| 376 | test_node_leaflist(void **state) |
| 377 | { |
| 378 | *state = test_node_leaflist; |
| 379 | |
| 380 | struct ly_ctx *ctx; |
| 381 | struct lys_module *mod; |
| 382 | struct lysc_type *type; |
| 383 | struct lysc_node_leaflist *ll; |
| 384 | |
| 385 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 386 | |
| 387 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;" |
| 388 | "typedef mytype {type union {type leafref {path ../target;} type string;}}" |
| 389 | "leaf-list ll1 {type union {type decimal64 {fraction-digits 2;} type mytype;}}" |
| 390 | "leaf-list ll2 {type leafref {path ../target;}}" |
| 391 | "leaf target {type int8;}}", |
| 392 | LYS_IN_YANG)); |
| 393 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 394 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 395 | assert_non_null(type); |
| 396 | assert_int_equal(1, type->refcount); |
| 397 | assert_int_equal(LY_TYPE_UNION, type->basetype); |
| 398 | assert_non_null(((struct lysc_type_union*)type)->types); |
| 399 | assert_int_equal(3, LY_ARRAY_SIZE(((struct lysc_type_union*)type)->types)); |
| 400 | assert_int_equal(LY_TYPE_DEC64, ((struct lysc_type_union*)type)->types[0]->basetype); |
| 401 | assert_int_equal(LY_TYPE_LEAFREF, ((struct lysc_type_union*)type)->types[1]->basetype); |
| 402 | assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union*)type)->types[2]->basetype); |
| 403 | assert_non_null(((struct lysc_type_leafref*)((struct lysc_type_union*)type)->types[1])->realtype); |
| 404 | assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref*)((struct lysc_type_union*)type)->types[1])->realtype->basetype); |
| 405 | type = ((struct lysc_node_leaf*)mod->compiled->data->next)->type; |
| 406 | assert_non_null(type); |
| 407 | assert_int_equal(1, type->refcount); |
| 408 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 409 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 410 | assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref*)type)->realtype->basetype); |
| 411 | |
Radek Krejci | 6bb080b | 2018-11-28 17:23:41 +0100 | [diff] [blame^] | 412 | 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] | 413 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 414 | assert_non_null(mod->compiled); |
| 415 | assert_non_null((ll = (struct lysc_node_leaflist*)mod->compiled->data)); |
| 416 | assert_int_equal(0, ll->min); |
| 417 | assert_int_equal((uint32_t)-1, ll->max); |
| 418 | |
Radek Krejci | 6bb080b | 2018-11-28 17:23:41 +0100 | [diff] [blame^] | 419 | 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;}" |
| 420 | "leaf-list ll1 {type mytype;default 1; default 2;}" |
| 421 | "leaf-list ll2 {type mytype;}}", LYS_IN_YANG)); |
| 422 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 423 | assert_non_null(mod->compiled); |
| 424 | assert_non_null((ll = (struct lysc_node_leaflist*)mod->compiled->data)); |
| 425 | assert_non_null(ll->dflts); |
| 426 | assert_int_equal(3, ll->type->refcount); |
| 427 | assert_int_equal(2, LY_ARRAY_SIZE(ll->dflts)); |
| 428 | assert_string_equal("1", ll->dflts[0]); |
| 429 | assert_string_equal("2", ll->dflts[1]); |
| 430 | assert_non_null((ll = (struct lysc_node_leaflist*)mod->compiled->data->next)); |
| 431 | assert_non_null(ll->dflts); |
| 432 | assert_int_equal(3, ll->type->refcount); |
| 433 | assert_int_equal(1, LY_ARRAY_SIZE(ll->dflts)); |
| 434 | assert_string_equal("10", ll->dflts[0]); |
| 435 | |
| 436 | /* invalid */ |
| 437 | assert_non_null(mod = lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;leaf-list ll {type empty;}}", LYS_IN_YANG)); |
| 438 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 439 | logbuf_assert("Leaf-list of type \"empty\" is allowed only in YANG 1.1 modules."); |
| 440 | |
| 441 | assert_non_null(mod = 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)); |
| 442 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 443 | logbuf_assert("Leaf-list of type \"empty\" must not have a default value (x)."); |
| 444 | |
| 445 | assert_non_null(mod = lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;" |
| 446 | "leaf-list ll {config false;type string; default one;default two;default one;}}", LYS_IN_YANG)); |
| 447 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 448 | assert_non_null(mod->compiled); |
| 449 | assert_non_null((ll = (struct lysc_node_leaflist*)mod->compiled->data)); |
| 450 | assert_non_null(ll->dflts); |
| 451 | assert_int_equal(3, LY_ARRAY_SIZE(ll->dflts)); |
| 452 | assert_non_null(mod = lys_parse_mem(ctx, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;" |
| 453 | "leaf-list ll {type string; default one;default two;default one;}}", LYS_IN_YANG)); |
| 454 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 455 | logbuf_assert("Configuration leaf-list has multiple defaults of the same value \"one\"."); |
| 456 | |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 457 | *state = NULL; |
| 458 | ly_ctx_destroy(ctx, NULL); |
| 459 | } |
| 460 | |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 461 | /** |
| 462 | * actually the same as length restriction (tested in test_type_length()), so just check the correct handling in appropriate types, |
| 463 | * do not test the expression itself |
| 464 | */ |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 465 | static void |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 466 | test_type_range(void **state) |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 467 | { |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 468 | *state = test_type_range; |
| 469 | |
| 470 | struct ly_ctx *ctx; |
| 471 | struct lys_module *mod; |
| 472 | struct lysc_type *type; |
| 473 | |
| 474 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 475 | |
| 476 | 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)); |
| 477 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 478 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 479 | assert_non_null(type); |
| 480 | assert_int_equal(LY_TYPE_INT8, type->basetype); |
| 481 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 482 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 483 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 484 | assert_int_equal(-128, ((struct lysc_type_num*)type)->range->parts[0].min_64); |
| 485 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_64); |
| 486 | assert_int_equal(127, ((struct lysc_type_num*)type)->range->parts[1].min_64); |
| 487 | assert_int_equal(127, ((struct lysc_type_num*)type)->range->parts[1].max_64); |
| 488 | |
| 489 | 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)); |
| 490 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 491 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 492 | assert_non_null(type); |
| 493 | assert_int_equal(LY_TYPE_INT16, type->basetype); |
| 494 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 495 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 496 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 497 | assert_int_equal(-32768, ((struct lysc_type_num*)type)->range->parts[0].min_64); |
| 498 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_64); |
| 499 | assert_int_equal(32767, ((struct lysc_type_num*)type)->range->parts[1].min_64); |
| 500 | assert_int_equal(32767, ((struct lysc_type_num*)type)->range->parts[1].max_64); |
| 501 | |
| 502 | 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)); |
| 503 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 504 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 505 | assert_non_null(type); |
| 506 | assert_int_equal(LY_TYPE_INT32, type->basetype); |
| 507 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 508 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 509 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 510 | assert_int_equal(INT64_C(-2147483648), ((struct lysc_type_num*)type)->range->parts[0].min_64); |
| 511 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_64); |
| 512 | assert_int_equal(INT64_C(2147483647), ((struct lysc_type_num*)type)->range->parts[1].min_64); |
| 513 | assert_int_equal(INT64_C(2147483647), ((struct lysc_type_num*)type)->range->parts[1].max_64); |
| 514 | |
| 515 | 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)); |
| 516 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 517 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 518 | assert_non_null(type); |
| 519 | assert_int_equal(LY_TYPE_INT64, type->basetype); |
| 520 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 521 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 522 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 523 | assert_int_equal(INT64_C(-9223372036854775807) - INT64_C(1), ((struct lysc_type_num*)type)->range->parts[0].min_64); |
| 524 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_64); |
| 525 | assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_num*)type)->range->parts[1].min_64); |
| 526 | assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_num*)type)->range->parts[1].max_64); |
| 527 | |
| 528 | 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)); |
| 529 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 530 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 531 | assert_non_null(type); |
| 532 | assert_int_equal(LY_TYPE_UINT8, type->basetype); |
| 533 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 534 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 535 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 536 | assert_int_equal(0, ((struct lysc_type_num*)type)->range->parts[0].min_u64); |
| 537 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_u64); |
| 538 | assert_int_equal(255, ((struct lysc_type_num*)type)->range->parts[1].min_u64); |
| 539 | assert_int_equal(255, ((struct lysc_type_num*)type)->range->parts[1].max_u64); |
| 540 | |
| 541 | 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)); |
| 542 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 543 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 544 | assert_non_null(type); |
| 545 | assert_int_equal(LY_TYPE_UINT16, type->basetype); |
| 546 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 547 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 548 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 549 | assert_int_equal(0, ((struct lysc_type_num*)type)->range->parts[0].min_u64); |
| 550 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_u64); |
| 551 | assert_int_equal(65535, ((struct lysc_type_num*)type)->range->parts[1].min_u64); |
| 552 | assert_int_equal(65535, ((struct lysc_type_num*)type)->range->parts[1].max_u64); |
| 553 | |
| 554 | 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)); |
| 555 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 556 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 557 | assert_non_null(type); |
| 558 | assert_int_equal(LY_TYPE_UINT32, type->basetype); |
| 559 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 560 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 561 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 562 | assert_int_equal(0, ((struct lysc_type_num*)type)->range->parts[0].min_u64); |
| 563 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_u64); |
| 564 | assert_int_equal(UINT64_C(4294967295), ((struct lysc_type_num*)type)->range->parts[1].min_u64); |
| 565 | assert_int_equal(UINT64_C(4294967295), ((struct lysc_type_num*)type)->range->parts[1].max_u64); |
| 566 | |
| 567 | 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)); |
| 568 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 569 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 570 | assert_non_null(type); |
| 571 | assert_int_equal(LY_TYPE_UINT64, type->basetype); |
| 572 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 573 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 574 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 575 | assert_int_equal(0, ((struct lysc_type_num*)type)->range->parts[0].min_u64); |
| 576 | assert_int_equal(10, ((struct lysc_type_num*)type)->range->parts[0].max_u64); |
| 577 | assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_num*)type)->range->parts[1].min_u64); |
| 578 | assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_num*)type)->range->parts[1].max_u64); |
| 579 | |
| 580 | assert_non_null(mod = lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;typedef mytype {type uint8 {range 10..100;}}" |
| 581 | "typedef mytype2 {type mytype;} leaf l {type mytype2;}}", LYS_IN_YANG)); |
| 582 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 583 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 584 | assert_non_null(type); |
| 585 | assert_int_equal(3, type->refcount); |
| 586 | assert_int_equal(LY_TYPE_UINT8, type->basetype); |
| 587 | assert_non_null(((struct lysc_type_num*)type)->range); |
| 588 | assert_non_null(((struct lysc_type_num*)type)->range->parts); |
| 589 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_num*)type)->range->parts)); |
| 590 | |
| 591 | *state = NULL; |
| 592 | ly_ctx_destroy(ctx, NULL); |
| 593 | } |
| 594 | |
| 595 | static void |
| 596 | test_type_length(void **state) |
| 597 | { |
| 598 | *state = test_type_length; |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 599 | |
| 600 | struct ly_ctx *ctx; |
| 601 | struct lys_module *mod; |
| 602 | struct lysc_type *type; |
| 603 | |
| 604 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 605 | |
Radek Krejci | c5ddcc0 | 2018-11-12 13:28:18 +0100 | [diff] [blame] | 606 | 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] | 607 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 608 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 609 | assert_non_null(type); |
| 610 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 611 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
Radek Krejci | c5ddcc0 | 2018-11-12 13:28:18 +0100 | [diff] [blame] | 612 | assert_string_equal("errortag", ((struct lysc_type_bin*)type)->length->eapptag); |
| 613 | assert_string_equal("error", ((struct lysc_type_bin*)type)->length->emsg); |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 614 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 615 | assert_int_equal(0, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 616 | assert_int_equal(0, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 617 | |
| 618 | assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;leaf l {type binary {length max;}}}", LYS_IN_YANG)); |
| 619 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 620 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 621 | assert_non_null(type); |
| 622 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 623 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 624 | 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] | 625 | assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 626 | 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] | 627 | |
| 628 | 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)); |
| 629 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 630 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 631 | assert_non_null(type); |
| 632 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 633 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 634 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 635 | 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] | 636 | 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] | 637 | |
| 638 | assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;leaf l {type binary {length 5;}}}", LYS_IN_YANG)); |
| 639 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 640 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 641 | assert_non_null(type); |
| 642 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 643 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 644 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 645 | assert_int_equal(5, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 646 | assert_int_equal(5, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 647 | |
| 648 | 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)); |
| 649 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 650 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 651 | assert_non_null(type); |
| 652 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 653 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 654 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 655 | assert_int_equal(1, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 656 | assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 657 | |
| 658 | 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)); |
| 659 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 660 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 661 | assert_non_null(type); |
| 662 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 663 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 664 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 665 | assert_int_equal(1, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 666 | assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 667 | assert_int_equal(20, ((struct lysc_type_bin*)type)->length->parts[1].min_u64); |
| 668 | assert_int_equal(30, ((struct lysc_type_bin*)type)->length->parts[1].max_u64); |
| 669 | |
| 670 | 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)); |
| 671 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 672 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 673 | assert_non_null(type); |
| 674 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 675 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 676 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 677 | assert_int_equal(16, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 678 | assert_int_equal(16, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 679 | assert_int_equal(32, ((struct lysc_type_bin*)type)->length->parts[1].min_u64); |
| 680 | assert_int_equal(32, ((struct lysc_type_bin*)type)->length->parts[1].max_u64); |
| 681 | |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 682 | assert_non_null(mod = lys_parse_mem(ctx, "module h {namespace urn:h;prefix h;typedef mytype {type binary {length 10;}}" |
| 683 | "leaf l {type mytype {length \"10\";}}}", LYS_IN_YANG)); |
| 684 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 685 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 686 | assert_non_null(type); |
| 687 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 688 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 689 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 690 | assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 691 | assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 692 | |
| 693 | assert_non_null(mod = lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;typedef mytype {type binary {length 10..100;}}" |
| 694 | "leaf l {type mytype {length \"50\";}}}", LYS_IN_YANG)); |
| 695 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 696 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 697 | assert_non_null(type); |
| 698 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 699 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 700 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 701 | assert_int_equal(50, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 702 | assert_int_equal(50, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 703 | |
| 704 | assert_non_null(mod = lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;typedef mytype {type binary {length 10..100;}}" |
| 705 | "leaf l {type mytype {length \"10..30|60..100\";}}}", LYS_IN_YANG)); |
| 706 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 707 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 708 | assert_non_null(type); |
| 709 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 710 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 711 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 712 | assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 713 | assert_int_equal(30, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 714 | assert_int_equal(60, ((struct lysc_type_bin*)type)->length->parts[1].min_u64); |
| 715 | assert_int_equal(100, ((struct lysc_type_bin*)type)->length->parts[1].max_u64); |
| 716 | |
| 717 | 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] | 718 | "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] | 719 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 720 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 721 | assert_non_null(type); |
Radek Krejci | 56aa27c | 2018-11-13 14:21:59 +0100 | [diff] [blame] | 722 | assert_int_equal(1, type->refcount); |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 723 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 724 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 725 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 726 | 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] | 727 | 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] | 728 | type = ((struct lysc_node_leaf*)mod->compiled->data->next)->type; |
| 729 | assert_non_null(type); |
Radek Krejci | 56aa27c | 2018-11-13 14:21:59 +0100 | [diff] [blame] | 730 | assert_int_equal(2, type->refcount); |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 731 | assert_non_null(((struct lysc_type_bin*)type)->length); |
| 732 | assert_non_null(((struct lysc_type_bin*)type)->length->parts); |
| 733 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_bin*)type)->length->parts)); |
| 734 | assert_int_equal(10, ((struct lysc_type_bin*)type)->length->parts[0].min_u64); |
| 735 | assert_int_equal(100, ((struct lysc_type_bin*)type)->length->parts[0].max_u64); |
| 736 | |
Radek Krejci | 56aa27c | 2018-11-13 14:21:59 +0100 | [diff] [blame] | 737 | assert_non_null(mod = lys_parse_mem(ctx, "module l {namespace urn:l;prefix l;typedef mytype {type string {length 10..100;}}" |
| 738 | "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] | 739 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 740 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 741 | assert_non_null(type); |
| 742 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
Radek Krejci | 56aa27c | 2018-11-13 14:21:59 +0100 | [diff] [blame] | 743 | assert_int_equal(1, type->refcount); |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 744 | assert_non_null(((struct lysc_type_str*)type)->length); |
| 745 | assert_non_null(((struct lysc_type_str*)type)->length->parts); |
| 746 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_str*)type)->length->parts)); |
| 747 | assert_int_equal(10, ((struct lysc_type_str*)type)->length->parts[0].min_u64); |
| 748 | 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] | 749 | |
Radek Krejci | 5969f27 | 2018-11-23 10:03:58 +0100 | [diff] [blame] | 750 | assert_non_null(mod = lys_parse_mem(ctx, "module m {namespace urn:m;prefix m;typedef mytype {type string {length 10;}}" |
| 751 | "leaf l {type mytype {length min..max;}}}", LYS_IN_YANG)); |
| 752 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 753 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 754 | assert_non_null(type); |
| 755 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 756 | assert_int_equal(1, type->refcount); |
| 757 | assert_non_null(((struct lysc_type_str*)type)->length); |
| 758 | assert_non_null(((struct lysc_type_str*)type)->length->parts); |
| 759 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_str*)type)->length->parts)); |
| 760 | assert_int_equal(10, ((struct lysc_type_str*)type)->length->parts[0].min_u64); |
| 761 | assert_int_equal(10, ((struct lysc_type_str*)type)->length->parts[0].max_u64); |
| 762 | |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 763 | /* invalid values */ |
| 764 | assert_non_null(mod = lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;leaf l {type binary {length -10;}}}", LYS_IN_YANG)); |
| 765 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 766 | logbuf_assert("Invalid length restriction - value \"-10\" does not fit the type limitations."); |
| 767 | assert_non_null(mod = lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf l {type binary {length 18446744073709551616;}}}", LYS_IN_YANG)); |
| 768 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 769 | logbuf_assert("Invalid length restriction - invalid value \"18446744073709551616\"."); |
| 770 | assert_non_null(mod = lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;leaf l {type binary {length \"max .. 10\";}}}", LYS_IN_YANG)); |
| 771 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 772 | logbuf_assert("Invalid length restriction - unexpected data after max keyword (.. 10)."); |
| 773 | assert_non_null(mod = lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;leaf l {type binary {length 50..10;}}}", LYS_IN_YANG)); |
| 774 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 775 | logbuf_assert("Invalid length restriction - values are not in ascending order (10)."); |
| 776 | assert_non_null(mod = lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type binary {length \"50 | 10\";}}}", LYS_IN_YANG)); |
| 777 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 778 | logbuf_assert("Invalid length restriction - values are not in ascending order (10)."); |
| 779 | assert_non_null(mod = lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type binary {length \"x\";}}}", LYS_IN_YANG)); |
| 780 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 781 | logbuf_assert("Invalid length restriction - unexpected data (x)."); |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 782 | assert_non_null(mod = lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;leaf l {type binary {length \"50 | min\";}}}", LYS_IN_YANG)); |
| 783 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 784 | logbuf_assert("Invalid length restriction - unexpected data before min keyword (50 | )."); |
| 785 | assert_non_null(mod = lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;leaf l {type binary {length \"| 50\";}}}", LYS_IN_YANG)); |
| 786 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 787 | logbuf_assert("Invalid length restriction - unexpected beginning of the expression (| 50)."); |
| 788 | assert_non_null(mod = lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;leaf l {type binary {length \"10 ..\";}}}", LYS_IN_YANG)); |
| 789 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 790 | logbuf_assert("Invalid length restriction - unexpected end of the expression after \"..\" (10 ..)."); |
| 791 | assert_non_null(mod = lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;leaf l {type binary {length \".. 10\";}}}", LYS_IN_YANG)); |
| 792 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 793 | logbuf_assert("Invalid length restriction - unexpected \"..\" without a lower bound."); |
| 794 | assert_non_null(mod = lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;leaf l {type binary {length \"10 |\";}}}", LYS_IN_YANG)); |
| 795 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 796 | logbuf_assert("Invalid length restriction - unexpected end of the expression (10 |)."); |
Radek Krejci | 6489bbe | 2018-11-12 17:05:19 +0100 | [diff] [blame] | 797 | assert_non_null(mod = lys_parse_mem(ctx, "module kl {namespace urn:kl;prefix kl;leaf l {type binary {length \"10..20 | 15..30\";}}}", LYS_IN_YANG)); |
| 798 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 799 | logbuf_assert("Invalid length restriction - values are not in ascending order (15)."); |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 800 | |
| 801 | assert_non_null(mod = lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;typedef mytype {type binary {length 10;}}" |
| 802 | "leaf l {type mytype {length 11;}}}", LYS_IN_YANG)); |
| 803 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 804 | logbuf_assert("Invalid length restriction - the derived restriction (11) is not equally or more limiting."); |
| 805 | assert_non_null(mod = lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;typedef mytype {type binary {length 10..100;}}" |
| 806 | "leaf l {type mytype {length 1..11;}}}", LYS_IN_YANG)); |
| 807 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 808 | logbuf_assert("Invalid length restriction - the derived restriction (1..11) is not equally or more limiting."); |
| 809 | assert_non_null(mod = lys_parse_mem(ctx, "module nn {namespace urn:nn;prefix nn;typedef mytype {type binary {length 10..100;}}" |
| 810 | "leaf l {type mytype {length 20..110;}}}", LYS_IN_YANG)); |
| 811 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 812 | logbuf_assert("Invalid length restriction - the derived restriction (20..110) is not equally or more limiting."); |
| 813 | assert_non_null(mod = lys_parse_mem(ctx, "module oo {namespace urn:oo;prefix oo;typedef mytype {type binary {length 10..100;}}" |
| 814 | "leaf l {type mytype {length 20..30|110..120;}}}", LYS_IN_YANG)); |
| 815 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 816 | logbuf_assert("Invalid length restriction - the derived restriction (20..30|110..120) is not equally or more limiting."); |
| 817 | assert_non_null(mod = lys_parse_mem(ctx, "module pp {namespace urn:pp;prefix pp;typedef mytype {type binary {length 10..11;}}" |
| 818 | "leaf l {type mytype {length 15;}}}", LYS_IN_YANG)); |
| 819 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 820 | logbuf_assert("Invalid length restriction - the derived restriction (15) is not equally or more limiting."); |
| 821 | assert_non_null(mod = lys_parse_mem(ctx, "module qq {namespace urn:qq;prefix qq;typedef mytype {type binary {length 10..20|30..40;}}" |
| 822 | "leaf l {type mytype {length 15..35;}}}", LYS_IN_YANG)); |
| 823 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 824 | logbuf_assert("Invalid length restriction - the derived restriction (15..35) is not equally or more limiting."); |
Radek Krejci | 6489bbe | 2018-11-12 17:05:19 +0100 | [diff] [blame] | 825 | assert_non_null(mod = lys_parse_mem(ctx, "module rr {namespace urn:rr;prefix rr;typedef mytype {type binary {length 10;}}" |
| 826 | "leaf l {type mytype {length 10..35;}}}", LYS_IN_YANG)); |
| 827 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 828 | logbuf_assert("Invalid length restriction - the derived restriction (10..35) is not equally or more limiting."); |
Radek Krejci | b31c899 | 2018-11-12 16:29:16 +0100 | [diff] [blame] | 829 | |
Radek Krejci | 495903e | 2018-11-13 11:30:45 +0100 | [diff] [blame] | 830 | assert_non_null(mod = lys_parse_mem(ctx, "module ss {namespace urn:rr;prefix rr;leaf l {type binary {pattern '[0-9]*';}}}", LYS_IN_YANG)); |
| 831 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 832 | logbuf_assert("Invalid type restrictions for binary type."); |
| 833 | |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 834 | *state = NULL; |
| 835 | ly_ctx_destroy(ctx, NULL); |
| 836 | } |
| 837 | |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 838 | static void |
| 839 | test_type_pattern(void **state) |
| 840 | { |
| 841 | *state = test_type_pattern; |
| 842 | |
| 843 | struct ly_ctx *ctx; |
| 844 | struct lys_module *mod; |
| 845 | struct lysc_type *type; |
| 846 | |
| 847 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 848 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 849 | 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] | 850 | "pattern .* {error-app-tag errortag;error-message error;}" |
| 851 | "pattern [0-9].*[0-9] {modifier invert-match;}}}}", LYS_IN_YANG)); |
| 852 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 853 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 854 | assert_non_null(type); |
| 855 | assert_non_null(((struct lysc_type_str*)type)->patterns); |
| 856 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_str*)type)->patterns)); |
| 857 | assert_string_equal("errortag", ((struct lysc_type_str*)type)->patterns[0]->eapptag); |
| 858 | assert_string_equal("error", ((struct lysc_type_str*)type)->patterns[0]->emsg); |
| 859 | assert_int_equal(0, ((struct lysc_type_str*)type)->patterns[0]->inverted); |
| 860 | assert_null(((struct lysc_type_str*)type)->patterns[1]->eapptag); |
| 861 | assert_null(((struct lysc_type_str*)type)->patterns[1]->emsg); |
| 862 | assert_int_equal(1, ((struct lysc_type_str*)type)->patterns[1]->inverted); |
| 863 | |
| 864 | assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;typedef mytype {type string {pattern '[0-9]*';}}" |
| 865 | "typedef mytype2 {type mytype {length 10;}} leaf l {type mytype2 {pattern '[0-4]*';}}}", LYS_IN_YANG)); |
| 866 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 867 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 868 | assert_non_null(type); |
| 869 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 870 | assert_int_equal(1, type->refcount); |
| 871 | assert_non_null(((struct lysc_type_str*)type)->patterns); |
| 872 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_str*)type)->patterns)); |
| 873 | assert_int_equal(3, ((struct lysc_type_str*)type)->patterns[0]->refcount); |
| 874 | assert_int_equal(1, ((struct lysc_type_str*)type)->patterns[1]->refcount); |
| 875 | |
Radek Krejci | 04bc1e9 | 2018-11-14 14:28:13 +0100 | [diff] [blame] | 876 | assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;typedef mytype {type string {pattern '[0-9]*';}}" |
| 877 | "leaf l {type mytype {length 10;}}}", LYS_IN_YANG)); |
| 878 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 879 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 880 | assert_non_null(type); |
| 881 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 882 | assert_int_equal(1, type->refcount); |
| 883 | assert_non_null(((struct lysc_type_str*)type)->patterns); |
| 884 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_str*)type)->patterns)); |
| 885 | assert_int_equal(2, ((struct lysc_type_str*)type)->patterns[0]->refcount); |
| 886 | |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 887 | /* test substitutions */ |
Radek Krejci | 04bc1e9 | 2018-11-14 14:28:13 +0100 | [diff] [blame] | 888 | 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] | 889 | "pattern '^\\p{IsLatinExtended-A}$';}}}", LYS_IN_YANG)); |
| 890 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 891 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 892 | assert_non_null(type); |
| 893 | assert_non_null(((struct lysc_type_str*)type)->patterns); |
| 894 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_str*)type)->patterns)); |
| 895 | /* TODO check some data "^Å™$" */ |
| 896 | |
| 897 | *state = NULL; |
| 898 | ly_ctx_destroy(ctx, NULL); |
| 899 | } |
| 900 | |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 901 | static void |
| 902 | test_type_enum(void **state) |
| 903 | { |
| 904 | *state = test_type_enum; |
| 905 | |
| 906 | struct ly_ctx *ctx; |
| 907 | struct lys_module *mod; |
| 908 | struct lysc_type *type; |
| 909 | |
| 910 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 911 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 912 | 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] | 913 | "enum automin; enum min {value -2147483648;}enum one {if-feature f; value 1;}" |
| 914 | "enum two; enum seven {value 7;}enum eight;}}}", LYS_IN_YANG)); |
| 915 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 916 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 917 | assert_non_null(type); |
| 918 | assert_int_equal(LY_TYPE_ENUM, type->basetype); |
| 919 | assert_non_null(((struct lysc_type_enum*)type)->enums); |
| 920 | assert_int_equal(6, LY_ARRAY_SIZE(((struct lysc_type_enum*)type)->enums)); |
| 921 | assert_non_null(((struct lysc_type_enum*)type)->enums[2].iffeatures); |
| 922 | assert_string_equal("automin", ((struct lysc_type_enum*)type)->enums[0].name); |
| 923 | assert_int_equal(0, ((struct lysc_type_enum*)type)->enums[0].value); |
| 924 | assert_string_equal("min", ((struct lysc_type_enum*)type)->enums[1].name); |
| 925 | assert_int_equal(-2147483648, ((struct lysc_type_enum*)type)->enums[1].value); |
| 926 | assert_string_equal("one", ((struct lysc_type_enum*)type)->enums[2].name); |
| 927 | assert_int_equal(1, ((struct lysc_type_enum*)type)->enums[2].value); |
| 928 | assert_string_equal("two", ((struct lysc_type_enum*)type)->enums[3].name); |
| 929 | assert_int_equal(2, ((struct lysc_type_enum*)type)->enums[3].value); |
| 930 | assert_string_equal("seven", ((struct lysc_type_enum*)type)->enums[4].name); |
| 931 | assert_int_equal(7, ((struct lysc_type_enum*)type)->enums[4].value); |
| 932 | assert_string_equal("eight", ((struct lysc_type_enum*)type)->enums[5].name); |
| 933 | assert_int_equal(8, ((struct lysc_type_enum*)type)->enums[5].value); |
| 934 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 935 | 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 {" |
| 936 | "enum 11; enum min {value -2147483648;}enum x$&;" |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 937 | "enum two; enum seven {value 7;}enum eight;}} leaf l { type mytype {enum seven;enum eight;}}}", |
| 938 | LYS_IN_YANG)); |
| 939 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 940 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 941 | assert_non_null(type); |
| 942 | assert_int_equal(LY_TYPE_ENUM, type->basetype); |
| 943 | assert_non_null(((struct lysc_type_enum*)type)->enums); |
| 944 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_enum*)type)->enums)); |
| 945 | assert_string_equal("seven", ((struct lysc_type_enum*)type)->enums[0].name); |
| 946 | assert_int_equal(7, ((struct lysc_type_enum*)type)->enums[0].value); |
| 947 | assert_string_equal("eight", ((struct lysc_type_enum*)type)->enums[1].name); |
| 948 | assert_int_equal(8, ((struct lysc_type_enum*)type)->enums[1].value); |
| 949 | |
| 950 | |
| 951 | /* invalid cases */ |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 952 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type enumeration {" |
| 953 | "enum one {if-feature f;}}}}", LYS_IN_YANG)); |
| 954 | 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] | 955 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {" |
| 956 | "enum one {value -2147483649;}}}}", LYS_IN_YANG)); |
| 957 | logbuf_assert("Invalid value \"-2147483649\" of \"value\". Line number 1."); |
| 958 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {" |
| 959 | "enum one {value 2147483648;}}}}", LYS_IN_YANG)); |
| 960 | logbuf_assert("Invalid value \"2147483648\" of \"value\". Line number 1."); |
| 961 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {" |
| 962 | "enum one; enum one;}}}", LYS_IN_YANG)); |
| 963 | logbuf_assert("Duplicate identifier \"one\" of enum statement. Line number 1."); |
| 964 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {" |
| 965 | "enum '';}}}", LYS_IN_YANG)); |
| 966 | logbuf_assert("Enum name must not be zero-length. Line number 1."); |
| 967 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {" |
| 968 | "enum ' x';}}}", LYS_IN_YANG)); |
| 969 | logbuf_assert("Enum name must not have any leading or trailing whitespaces (\" x\"). Line number 1."); |
| 970 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {" |
| 971 | "enum 'x ';}}}", LYS_IN_YANG)); |
| 972 | logbuf_assert("Enum name must not have any leading or trailing whitespaces (\"x \"). Line number 1."); |
| 973 | assert_non_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {" |
| 974 | "enum 'inva\nlid';}}}", LYS_IN_YANG)); |
| 975 | logbuf_assert("Control characters in enum name should be avoided (\"inva\nlid\", character number 5)."); |
| 976 | |
| 977 | assert_non_null(mod = lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type enumeration;}}", LYS_IN_YANG)); |
| 978 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 979 | logbuf_assert("Missing enum substatement for enumeration type."); |
| 980 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 981 | assert_non_null(mod = 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] | 982 | "leaf l {type mytype {enum two;}}}", LYS_IN_YANG)); |
| 983 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 984 | logbuf_assert("Invalid enumeration - derived type adds new item \"two\"."); |
| 985 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 986 | assert_non_null(mod = 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] | 987 | "leaf l {type mytype {enum one {value 1;}}}}", LYS_IN_YANG)); |
| 988 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 989 | logbuf_assert("Invalid enumeration - value of the item \"one\" has changed from 0 to 1 in the derived type."); |
| 990 | assert_non_null(mod = lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type enumeration {enum x {value 2147483647;}enum y;}}}", |
| 991 | LYS_IN_YANG)); |
| 992 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 993 | logbuf_assert("Invalid enumeration - it is not possible to auto-assign enum value for \"y\" since the highest value is already 2147483647."); |
| 994 | |
| 995 | assert_non_null(mod = lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type enumeration {enum x {value 1;}enum y {value 1;}}}}", |
| 996 | LYS_IN_YANG)); |
| 997 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 998 | logbuf_assert("Invalid enumeration - value 1 collide in items \"y\" and \"x\"."); |
| 999 | |
Radek Krejci | 04bc1e9 | 2018-11-14 14:28:13 +0100 | [diff] [blame] | 1000 | assert_non_null(mod = lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;typedef mytype {type enumeration;}" |
| 1001 | "leaf l {type mytype {enum one;}}}", LYS_IN_YANG)); |
| 1002 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1003 | logbuf_assert("Missing enum substatement for enumeration type mytype."); |
Radek Krejci | 04bc1e9 | 2018-11-14 14:28:13 +0100 | [diff] [blame] | 1004 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1005 | assert_non_null(mod = lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh; typedef mytype {type enumeration {enum one;}}" |
| 1006 | "leaf l {type mytype {enum one;}}}", LYS_IN_YANG)); |
| 1007 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1008 | logbuf_assert("Enumeration type can be subtyped only in YANG 1.1 modules."); |
| 1009 | |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1010 | *state = NULL; |
| 1011 | ly_ctx_destroy(ctx, NULL); |
| 1012 | } |
| 1013 | |
| 1014 | static void |
| 1015 | test_type_bits(void **state) |
| 1016 | { |
| 1017 | *state = test_type_bits; |
| 1018 | |
| 1019 | struct ly_ctx *ctx; |
| 1020 | struct lys_module *mod; |
| 1021 | struct lysc_type *type; |
| 1022 | |
| 1023 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 1024 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1025 | 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] | 1026 | "bit automin; bit one {if-feature f; position 1;}" |
| 1027 | "bit two; bit seven {position 7;}bit eight;}}}", LYS_IN_YANG)); |
| 1028 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1029 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1030 | assert_non_null(type); |
| 1031 | assert_int_equal(LY_TYPE_BITS, type->basetype); |
| 1032 | assert_non_null(((struct lysc_type_bits*)type)->bits); |
| 1033 | assert_int_equal(5, LY_ARRAY_SIZE(((struct lysc_type_bits*)type)->bits)); |
| 1034 | assert_non_null(((struct lysc_type_bits*)type)->bits[1].iffeatures); |
| 1035 | assert_string_equal("automin", ((struct lysc_type_bits*)type)->bits[0].name); |
| 1036 | assert_int_equal(0, ((struct lysc_type_bits*)type)->bits[0].position); |
| 1037 | assert_string_equal("one", ((struct lysc_type_bits*)type)->bits[1].name); |
| 1038 | assert_int_equal(1, ((struct lysc_type_bits*)type)->bits[1].position); |
| 1039 | assert_string_equal("two", ((struct lysc_type_bits*)type)->bits[2].name); |
| 1040 | assert_int_equal(2, ((struct lysc_type_bits*)type)->bits[2].position); |
| 1041 | assert_string_equal("seven", ((struct lysc_type_bits*)type)->bits[3].name); |
| 1042 | assert_int_equal(7, ((struct lysc_type_bits*)type)->bits[3].position); |
| 1043 | assert_string_equal("eight", ((struct lysc_type_bits*)type)->bits[4].name); |
| 1044 | assert_int_equal(8, ((struct lysc_type_bits*)type)->bits[4].position); |
| 1045 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1046 | 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 {" |
| 1047 | "bit automin; bit one;bit two; bit seven {value 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] | 1048 | LYS_IN_YANG)); |
| 1049 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1050 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1051 | assert_non_null(type); |
| 1052 | assert_int_equal(LY_TYPE_BITS, type->basetype); |
| 1053 | assert_non_null(((struct lysc_type_bits*)type)->bits); |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1054 | assert_int_equal(3, LY_ARRAY_SIZE(((struct lysc_type_bits*)type)->bits)); |
| 1055 | assert_string_equal("automin", ((struct lysc_type_bits*)type)->bits[0].name); |
| 1056 | assert_int_equal(0, ((struct lysc_type_bits*)type)->bits[0].position); |
| 1057 | assert_string_equal("seven", ((struct lysc_type_bits*)type)->bits[1].name); |
| 1058 | assert_int_equal(7, ((struct lysc_type_bits*)type)->bits[1].position); |
| 1059 | assert_string_equal("eight", ((struct lysc_type_bits*)type)->bits[2].name); |
| 1060 | assert_int_equal(8, ((struct lysc_type_bits*)type)->bits[2].position); |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1061 | |
| 1062 | |
| 1063 | /* invalid cases */ |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1064 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type bits {" |
| 1065 | "bit one {if-feature f;}}}}", LYS_IN_YANG)); |
| 1066 | 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] | 1067 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {" |
| 1068 | "bit one {position -1;}}}}", LYS_IN_YANG)); |
| 1069 | logbuf_assert("Invalid value \"-1\" of \"position\". Line number 1."); |
| 1070 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {" |
| 1071 | "bit one {value 4294967296;}}}}", LYS_IN_YANG)); |
| 1072 | logbuf_assert("Invalid value \"4294967296\" of \"value\". Line number 1."); |
| 1073 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {" |
| 1074 | "bit one; bit one;}}}", LYS_IN_YANG)); |
| 1075 | logbuf_assert("Duplicate identifier \"one\" of bit statement. Line number 1."); |
| 1076 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {" |
| 1077 | "bit '11';}}}", LYS_IN_YANG)); |
| 1078 | logbuf_assert("Invalid identifier first character '1'. Line number 1."); |
| 1079 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {" |
| 1080 | "bit 'x1$1';}}}", LYS_IN_YANG)); |
| 1081 | logbuf_assert("Invalid identifier character '$'. Line number 1."); |
| 1082 | |
| 1083 | assert_non_null(mod = lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type bits;}}", LYS_IN_YANG)); |
| 1084 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1085 | logbuf_assert("Missing bit substatement for bits type."); |
| 1086 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1087 | assert_non_null(mod = 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] | 1088 | "leaf l {type mytype {bit two;}}}", LYS_IN_YANG)); |
| 1089 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1090 | logbuf_assert("Invalid bits - derived type adds new item \"two\"."); |
| 1091 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1092 | assert_non_null(mod = 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] | 1093 | "leaf l {type mytype {bit one {position 1;}}}}", LYS_IN_YANG)); |
| 1094 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1095 | logbuf_assert("Invalid bits - position of the item \"one\" has changed from 0 to 1 in the derived type."); |
| 1096 | assert_non_null(mod = lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type bits {bit x {position 4294967295;}bit y;}}}", |
| 1097 | LYS_IN_YANG)); |
| 1098 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1099 | logbuf_assert("Invalid bits - it is not possible to auto-assign bit position for \"y\" since the highest value is already 4294967295."); |
| 1100 | |
| 1101 | assert_non_null(mod = lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type bits {bit x {value 1;}bit y {value 1;}}}}", |
| 1102 | LYS_IN_YANG)); |
| 1103 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1104 | logbuf_assert("Invalid bits - position 1 collide in items \"y\" and \"x\"."); |
| 1105 | |
Radek Krejci | 04bc1e9 | 2018-11-14 14:28:13 +0100 | [diff] [blame] | 1106 | assert_non_null(mod = lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;typedef mytype {type bits;}" |
| 1107 | "leaf l {type mytype {bit one;}}}", LYS_IN_YANG)); |
| 1108 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1109 | logbuf_assert("Missing bit substatement for bits type mytype."); |
Radek Krejci | 04bc1e9 | 2018-11-14 14:28:13 +0100 | [diff] [blame] | 1110 | |
Radek Krejci | 027d580 | 2018-11-14 16:57:28 +0100 | [diff] [blame] | 1111 | assert_non_null(mod = lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh; typedef mytype {type bits {bit one;}}" |
| 1112 | "leaf l {type mytype {bit one;}}}", LYS_IN_YANG)); |
| 1113 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1114 | logbuf_assert("Bits type can be subtyped only in YANG 1.1 modules."); |
| 1115 | |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1116 | *state = NULL; |
| 1117 | ly_ctx_destroy(ctx, NULL); |
| 1118 | } |
| 1119 | |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 1120 | static void |
| 1121 | test_type_dec64(void **state) |
| 1122 | { |
| 1123 | *state = test_type_dec64; |
| 1124 | |
| 1125 | struct ly_ctx *ctx; |
| 1126 | struct lys_module *mod; |
| 1127 | struct lysc_type *type; |
| 1128 | |
| 1129 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 1130 | |
| 1131 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;leaf l {type decimal64 {" |
| 1132 | "fraction-digits 2;range min..max;}}}", LYS_IN_YANG)); |
| 1133 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1134 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1135 | assert_non_null(type); |
| 1136 | assert_int_equal(LY_TYPE_DEC64, type->basetype); |
| 1137 | assert_int_equal(2, ((struct lysc_type_dec*)type)->fraction_digits); |
| 1138 | assert_non_null(((struct lysc_type_dec*)type)->range); |
| 1139 | assert_non_null(((struct lysc_type_dec*)type)->range->parts); |
| 1140 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_dec*)type)->range->parts)); |
| 1141 | assert_int_equal(INT64_C(-9223372036854775807) - INT64_C(1), ((struct lysc_type_dec*)type)->range->parts[0].min_64); |
| 1142 | assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_dec*)type)->range->parts[0].max_64); |
| 1143 | |
| 1144 | assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;typedef mytype {type decimal64 {" |
| 1145 | "fraction-digits 2;range '3.14 | 5.1 | 10';}}leaf l {type mytype;}}", LYS_IN_YANG)); |
| 1146 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1147 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1148 | assert_non_null(type); |
| 1149 | assert_int_equal(LY_TYPE_DEC64, type->basetype); |
| 1150 | assert_int_equal(2, ((struct lysc_type_dec*)type)->fraction_digits); |
| 1151 | assert_non_null(((struct lysc_type_dec*)type)->range); |
| 1152 | assert_non_null(((struct lysc_type_dec*)type)->range->parts); |
| 1153 | assert_int_equal(3, LY_ARRAY_SIZE(((struct lysc_type_dec*)type)->range->parts)); |
| 1154 | assert_int_equal(314, ((struct lysc_type_dec*)type)->range->parts[0].min_64); |
| 1155 | assert_int_equal(314, ((struct lysc_type_dec*)type)->range->parts[0].max_64); |
| 1156 | assert_int_equal(510, ((struct lysc_type_dec*)type)->range->parts[1].min_64); |
| 1157 | assert_int_equal(510, ((struct lysc_type_dec*)type)->range->parts[1].max_64); |
| 1158 | assert_int_equal(1000, ((struct lysc_type_dec*)type)->range->parts[2].min_64); |
| 1159 | assert_int_equal(1000, ((struct lysc_type_dec*)type)->range->parts[2].max_64); |
| 1160 | |
| 1161 | /* invalid cases */ |
| 1162 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 0;}}}", LYS_IN_YANG)); |
| 1163 | logbuf_assert("Invalid value \"0\" of \"fraction-digits\". Line number 1."); |
| 1164 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits -1;}}}", LYS_IN_YANG)); |
| 1165 | logbuf_assert("Invalid value \"-1\" of \"fraction-digits\". Line number 1."); |
| 1166 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 19;}}}", LYS_IN_YANG)); |
| 1167 | logbuf_assert("Value \"19\" is out of \"fraction-digits\" bounds. Line number 1."); |
| 1168 | |
| 1169 | assert_non_null(mod = lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64;}}", LYS_IN_YANG)); |
| 1170 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1171 | logbuf_assert("Missing fraction-digits substatement for decimal64 type."); |
| 1172 | |
Radek Krejci | 643c824 | 2018-11-15 17:51:11 +0100 | [diff] [blame] | 1173 | assert_non_null(mod = lys_parse_mem(ctx, "module ab {namespace urn:ab;prefix ab; typedef mytype {type decimal64;}leaf l {type mytype;}}", LYS_IN_YANG)); |
| 1174 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1175 | logbuf_assert("Missing fraction-digits substatement for decimal64 type mytype."); |
Radek Krejci | 643c824 | 2018-11-15 17:51:11 +0100 | [diff] [blame] | 1176 | |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 1177 | assert_non_null(mod = lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type decimal64 {fraction-digits 2;" |
| 1178 | "range '3.142';}}}", LYS_IN_YANG)); |
| 1179 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1180 | logbuf_assert("Range boundary \"3.142\" of decimal64 type exceeds defined number (2) of fraction digits."); |
| 1181 | |
| 1182 | assert_non_null(mod = lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; leaf l {type decimal64 {fraction-digits 2;" |
| 1183 | "range '4 | 3.14';}}}", LYS_IN_YANG)); |
| 1184 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1185 | logbuf_assert("Invalid range restriction - values are not in ascending order (3.14)."); |
| 1186 | |
Radek Krejci | 643c824 | 2018-11-15 17:51:11 +0100 | [diff] [blame] | 1187 | assert_non_null(mod = lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; typedef mytype {type decimal64 {fraction-digits 2;}}" |
| 1188 | "leaf l {type mytype {fraction-digits 3;}}}", LYS_IN_YANG)); |
| 1189 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1190 | logbuf_assert("Invalid fraction-digits substatement for type not directly derived from decimal64 built-in type."); |
| 1191 | |
| 1192 | assert_non_null(mod = lys_parse_mem(ctx, "module de {namespace urn:de;prefix de; typedef mytype {type decimal64 {fraction-digits 2;}}" |
| 1193 | "typedef mytype2 {type mytype {fraction-digits 3;}}leaf l {type mytype2;}}", LYS_IN_YANG)); |
| 1194 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1195 | logbuf_assert("Invalid fraction-digits substatement for type \"mytype2\" not directly derived from decimal64 built-in type."); |
| 1196 | |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 1197 | *state = NULL; |
| 1198 | ly_ctx_destroy(ctx, NULL); |
| 1199 | } |
| 1200 | |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 1201 | static void |
| 1202 | test_type_instanceid(void **state) |
| 1203 | { |
| 1204 | *state = test_type_instanceid; |
| 1205 | |
| 1206 | struct ly_ctx *ctx; |
| 1207 | struct lys_module *mod; |
| 1208 | struct lysc_type *type; |
| 1209 | |
| 1210 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 1211 | |
| 1212 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;typedef mytype {type instance-identifier {require-instance false;}}" |
| 1213 | "leaf l1 {type instance-identifier {require-instance true;}}" |
| 1214 | "leaf l2 {type mytype;} leaf l3 {type instance-identifier;}}", LYS_IN_YANG)); |
| 1215 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1216 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1217 | assert_non_null(type); |
| 1218 | assert_int_equal(LY_TYPE_INST, type->basetype); |
| 1219 | assert_int_equal(1, ((struct lysc_type_instanceid*)type)->require_instance); |
| 1220 | |
| 1221 | type = ((struct lysc_node_leaf*)mod->compiled->data->next)->type; |
| 1222 | assert_non_null(type); |
| 1223 | assert_int_equal(LY_TYPE_INST, type->basetype); |
| 1224 | assert_int_equal(0, ((struct lysc_type_instanceid*)type)->require_instance); |
| 1225 | |
| 1226 | type = ((struct lysc_node_leaf*)mod->compiled->data->next->next)->type; |
| 1227 | assert_non_null(type); |
| 1228 | assert_int_equal(LY_TYPE_INST, type->basetype); |
| 1229 | assert_int_equal(1, ((struct lysc_type_instanceid*)type)->require_instance); |
| 1230 | |
| 1231 | /* invalid cases */ |
| 1232 | assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {require-instance yes;}}}", LYS_IN_YANG)); |
| 1233 | logbuf_assert("Invalid value \"yes\" of \"require-instance\". Line number 1."); |
| 1234 | |
| 1235 | assert_non_null(mod = lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {fraction-digits 1;}}}", LYS_IN_YANG)); |
| 1236 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1237 | logbuf_assert("Invalid type restrictions for instance-identifier type."); |
| 1238 | |
| 1239 | *state = NULL; |
| 1240 | ly_ctx_destroy(ctx, NULL); |
| 1241 | } |
| 1242 | |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1243 | static void |
| 1244 | test_type_identityref(void **state) |
| 1245 | { |
| 1246 | *state = test_type_identityref; |
| 1247 | |
| 1248 | struct ly_ctx *ctx; |
| 1249 | struct lys_module *mod; |
| 1250 | struct lysc_type *type; |
| 1251 | |
| 1252 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 1253 | |
| 1254 | 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;}" |
| 1255 | "typedef mytype {type identityref {base i;}}" |
Radek Krejci | b83ea3e | 2018-11-23 14:29:13 +0100 | [diff] [blame] | 1256 | "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] | 1257 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1258 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1259 | assert_non_null(type); |
| 1260 | assert_int_equal(LY_TYPE_IDENT, type->basetype); |
| 1261 | assert_non_null(((struct lysc_type_identityref*)type)->bases); |
| 1262 | assert_int_equal(1, LY_ARRAY_SIZE(((struct lysc_type_identityref*)type)->bases)); |
| 1263 | assert_string_equal("i", ((struct lysc_type_identityref*)type)->bases[0]->name); |
| 1264 | |
| 1265 | type = ((struct lysc_node_leaf*)mod->compiled->data->next)->type; |
| 1266 | assert_non_null(type); |
| 1267 | assert_int_equal(LY_TYPE_IDENT, type->basetype); |
| 1268 | assert_non_null(((struct lysc_type_identityref*)type)->bases); |
| 1269 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_identityref*)type)->bases)); |
| 1270 | assert_string_equal("k", ((struct lysc_type_identityref*)type)->bases[0]->name); |
| 1271 | assert_string_equal("j", ((struct lysc_type_identityref*)type)->bases[1]->name); |
| 1272 | |
Radek Krejci | b83ea3e | 2018-11-23 14:29:13 +0100 | [diff] [blame] | 1273 | assert_non_null(mod = lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b;import a {prefix a;}" |
| 1274 | "leaf l {type identityref {base a:k; base a:j;}}}", LYS_IN_YANG)); |
| 1275 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1276 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1277 | assert_non_null(type); |
| 1278 | assert_int_equal(LY_TYPE_IDENT, type->basetype); |
| 1279 | assert_non_null(((struct lysc_type_identityref*)type)->bases); |
| 1280 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_identityref*)type)->bases)); |
| 1281 | assert_string_equal("k", ((struct lysc_type_identityref*)type)->bases[0]->name); |
| 1282 | assert_string_equal("j", ((struct lysc_type_identityref*)type)->bases[1]->name); |
| 1283 | |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1284 | /* invalid cases */ |
| 1285 | assert_non_null(mod = lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type identityref;}}", LYS_IN_YANG)); |
| 1286 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1287 | logbuf_assert("Missing base substatement for identityref type."); |
| 1288 | |
| 1289 | assert_non_null(mod = lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; typedef mytype {type identityref;}" |
| 1290 | "leaf l {type mytype;}}", LYS_IN_YANG)); |
| 1291 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1292 | logbuf_assert("Missing base substatement for identityref type mytype."); |
| 1293 | |
| 1294 | assert_non_null(mod = lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; identity i; typedef mytype {type identityref {base i;}}" |
| 1295 | "leaf l {type mytype {base i;}}}", LYS_IN_YANG)); |
| 1296 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 1297 | logbuf_assert("Invalid base substatement for the type not directly derived from identityref built-in type."); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1298 | |
| 1299 | assert_non_null(mod = lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; identity i; typedef mytype {type identityref {base i;}}" |
| 1300 | "typedef mytype2 {type mytype {base i;}}leaf l {type mytype2;}}", LYS_IN_YANG)); |
| 1301 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 1302 | logbuf_assert("Invalid base substatement for the type \"mytype2\" not directly derived from identityref built-in type."); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1303 | |
| 1304 | assert_non_null(mod = lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee; identity i; identity j;" |
| 1305 | "leaf l {type identityref {base i;base j;}}}", LYS_IN_YANG)); |
| 1306 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1307 | logbuf_assert("Multiple bases in identityref type are allowed only in YANG 1.1 modules."); |
| 1308 | |
Radek Krejci | 322614f | 2018-11-16 15:05:44 +0100 | [diff] [blame] | 1309 | assert_non_null(mod = lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff; identity i;leaf l {type identityref {base j;}}}", LYS_IN_YANG)); |
| 1310 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1311 | logbuf_assert("Unable to find base (j) of identityref."); |
| 1312 | |
| 1313 | assert_non_null(mod = lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;leaf l {type identityref {base x:j;}}}", LYS_IN_YANG)); |
| 1314 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1315 | logbuf_assert("Invalid prefix used for base (x:j) of identityref."); |
| 1316 | |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1317 | *state = NULL; |
| 1318 | ly_ctx_destroy(ctx, NULL); |
| 1319 | } |
| 1320 | |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1321 | static void |
| 1322 | test_type_leafref(void **state) |
| 1323 | { |
| 1324 | *state = test_type_leafref; |
| 1325 | |
| 1326 | struct ly_ctx *ctx; |
| 1327 | struct lys_module *mod; |
| 1328 | struct lysc_type *type; |
| 1329 | const char *path, *name, *prefix; |
| 1330 | size_t prefix_len, name_len; |
| 1331 | int parent_times, has_predicate; |
| 1332 | |
| 1333 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 1334 | |
| 1335 | /* lys_path_token() */ |
| 1336 | path = "invalid_path"; |
| 1337 | parent_times = 0; |
| 1338 | assert_int_equal(LY_EINVAL, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1339 | path = ".."; |
| 1340 | parent_times = 0; |
| 1341 | assert_int_equal(LY_EINVAL, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1342 | path = "..["; |
| 1343 | parent_times = 0; |
| 1344 | assert_int_equal(LY_EINVAL, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1345 | path = "../"; |
| 1346 | parent_times = 0; |
| 1347 | assert_int_equal(LY_EINVAL, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1348 | path = "/"; |
| 1349 | parent_times = 0; |
| 1350 | assert_int_equal(LY_EINVAL, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1351 | |
| 1352 | path = "../../pref:id/xxx[predicate]/invalid!!!"; |
| 1353 | parent_times = 0; |
| 1354 | assert_int_equal(LY_SUCCESS, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1355 | assert_string_equal("/xxx[predicate]/invalid!!!", path); |
| 1356 | assert_int_equal(4, prefix_len); |
| 1357 | assert_int_equal(0, strncmp("pref", prefix, prefix_len)); |
| 1358 | assert_int_equal(2, name_len); |
| 1359 | assert_int_equal(0, strncmp("id", name, name_len)); |
| 1360 | assert_int_equal(2, parent_times); |
| 1361 | assert_int_equal(0, has_predicate); |
| 1362 | assert_int_equal(LY_SUCCESS, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1363 | assert_string_equal("[predicate]/invalid!!!", path); |
| 1364 | assert_int_equal(0, prefix_len); |
| 1365 | assert_null(prefix); |
| 1366 | assert_int_equal(3, name_len); |
| 1367 | assert_int_equal(0, strncmp("xxx", name, name_len)); |
| 1368 | assert_int_equal(1, has_predicate); |
| 1369 | path += 11; |
| 1370 | assert_int_equal(LY_EINVAL, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1371 | assert_string_equal("!!!", path); |
| 1372 | assert_int_equal(0, prefix_len); |
| 1373 | assert_null(prefix); |
| 1374 | assert_int_equal(7, name_len); |
| 1375 | assert_int_equal(0, strncmp("invalid", name, name_len)); |
| 1376 | |
| 1377 | path = "/absolute/prefix:path"; |
| 1378 | parent_times = 0; |
| 1379 | assert_int_equal(LY_SUCCESS, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1380 | assert_string_equal("/prefix:path", path); |
| 1381 | assert_int_equal(0, prefix_len); |
| 1382 | assert_null(prefix); |
| 1383 | assert_int_equal(8, name_len); |
| 1384 | assert_int_equal(0, strncmp("absolute", name, name_len)); |
| 1385 | assert_int_equal(-1, parent_times); |
| 1386 | assert_int_equal(0, has_predicate); |
| 1387 | assert_int_equal(LY_SUCCESS, lys_path_token(&path, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)); |
| 1388 | assert_int_equal(0, *path); |
| 1389 | assert_int_equal(6, prefix_len); |
| 1390 | assert_int_equal(0, strncmp("prefix", prefix, prefix_len)); |
| 1391 | assert_int_equal(4, name_len); |
| 1392 | assert_int_equal(0, strncmp("path", name, name_len)); |
| 1393 | assert_int_equal(0, has_predicate); |
| 1394 | |
| 1395 | /* complete leafref paths */ |
Radek Krejci | 96a0bfd | 2018-11-22 15:25:06 +0100 | [diff] [blame] | 1396 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;" |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1397 | "leaf ref1 {type leafref {path /a:target1;}} leaf ref2 {type leafref {path /a/target2; require-instance false;}}" |
| 1398 | "leaf target1 {type string;}container a {leaf target2 {type uint8;}}}", LYS_IN_YANG)); |
| 1399 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1400 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1401 | assert_non_null(type); |
| 1402 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1403 | assert_string_equal("/a:target1", ((struct lysc_type_leafref*)type)->path); |
Radek Krejci | 96a0bfd | 2018-11-22 15:25:06 +0100 | [diff] [blame] | 1404 | assert_ptr_equal(mod, ((struct lysc_type_leafref*)type)->path_context); |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 1405 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 1406 | 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] | 1407 | assert_int_equal(1, ((struct lysc_type_leafref*)type)->require_instance); |
| 1408 | type = ((struct lysc_node_leaf*)mod->compiled->data->next)->type; |
| 1409 | assert_non_null(type); |
| 1410 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1411 | assert_string_equal("/a/target2", ((struct lysc_type_leafref*)type)->path); |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 1412 | assert_ptr_equal(mod, ((struct lysc_type_leafref*)type)->path_context); |
| 1413 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 1414 | 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] | 1415 | assert_int_equal(0, ((struct lysc_type_leafref*)type)->require_instance); |
| 1416 | |
Radek Krejci | 96a0bfd | 2018-11-22 15:25:06 +0100 | [diff] [blame] | 1417 | 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] | 1418 | "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] | 1419 | "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] | 1420 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1421 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1422 | assert_non_null(type); |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 1423 | assert_int_equal(1, type->refcount); |
Radek Krejci | 96a0bfd | 2018-11-22 15:25:06 +0100 | [diff] [blame] | 1424 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1425 | assert_string_equal("/b:target", ((struct lysc_type_leafref* )type)->path); |
| 1426 | assert_ptr_equal(mod, ((struct lysc_type_leafref*)type)->path_context); |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 1427 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 1428 | 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] | 1429 | assert_int_equal(1, ((struct lysc_type_leafref* )type)->require_instance); |
| 1430 | |
| 1431 | /* prefixes are reversed to check using correct context of the path! */ |
| 1432 | assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:c;prefix b; import b {prefix c;}" |
Radek Krejci | 2f4a029 | 2018-11-22 15:41:53 +0100 | [diff] [blame] | 1433 | "typedef mytype3 {type c:mytype {require-instance false;}}" |
| 1434 | "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] | 1435 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1436 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1437 | assert_non_null(type); |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 1438 | assert_int_equal(1, type->refcount); |
Radek Krejci | 2f4a029 | 2018-11-22 15:41:53 +0100 | [diff] [blame] | 1439 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1440 | assert_string_equal("/b:target", ((struct lysc_type_leafref* )type)->path); |
| 1441 | assert_ptr_not_equal(mod, ((struct lysc_type_leafref*)type)->path_context); |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 1442 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 1443 | 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] | 1444 | assert_int_equal(0, ((struct lysc_type_leafref* )type)->require_instance); |
| 1445 | type = ((struct lysc_node_leaf*)mod->compiled->data->next)->type; |
| 1446 | assert_non_null(type); |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 1447 | assert_int_equal(1, type->refcount); |
Radek Krejci | 96a0bfd | 2018-11-22 15:25:06 +0100 | [diff] [blame] | 1448 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1449 | assert_string_equal("/b:target", ((struct lysc_type_leafref* )type)->path); |
| 1450 | assert_ptr_not_equal(mod, ((struct lysc_type_leafref*)type)->path_context); |
| 1451 | assert_int_equal(1, ((struct lysc_type_leafref* )type)->require_instance); |
| 1452 | |
Radek Krejci | 4ce6893 | 2018-11-28 12:53:36 +0100 | [diff] [blame] | 1453 | /* non-prefixed nodes in path are supposed to be from the module where the leafref type is instantiated */ |
| 1454 | assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; import b {prefix b;}" |
| 1455 | "leaf ref {type b:mytype3;}leaf target {type int8;}}", LYS_IN_YANG)); |
| 1456 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1457 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1458 | assert_non_null(type); |
| 1459 | assert_int_equal(1, type->refcount); |
| 1460 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1461 | assert_string_equal("/target", ((struct lysc_type_leafref* )type)->path); |
| 1462 | assert_ptr_not_equal(mod, ((struct lysc_type_leafref*)type)->path_context); |
| 1463 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 1464 | assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref*)type)->realtype->basetype); |
| 1465 | assert_int_equal(1, ((struct lysc_type_leafref* )type)->require_instance); |
| 1466 | |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 1467 | /* conditional leafrefs */ |
Radek Krejci | 4ce6893 | 2018-11-28 12:53:36 +0100 | [diff] [blame] | 1468 | 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] | 1469 | "leaf ref1 {if-feature 'f1 and f2';type leafref {path /target;}}" |
| 1470 | "leaf target {if-feature f1; type boolean;}}", LYS_IN_YANG)); |
| 1471 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1472 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1473 | assert_non_null(type); |
| 1474 | assert_int_equal(1, type->refcount); |
| 1475 | assert_int_equal(LY_TYPE_LEAFREF, type->basetype); |
| 1476 | assert_string_equal("/target", ((struct lysc_type_leafref* )type)->path); |
| 1477 | assert_ptr_equal(mod, ((struct lysc_type_leafref*)type)->path_context); |
| 1478 | assert_non_null(((struct lysc_type_leafref*)type)->realtype); |
| 1479 | assert_int_equal(LY_TYPE_BOOL, ((struct lysc_type_leafref*)type)->realtype->basetype); |
| 1480 | |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1481 | /* TODO target in list with predicates */ |
| 1482 | |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1483 | /* invalid paths */ |
| 1484 | assert_non_null(mod = lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;container a {leaf target2 {type uint8;}}" |
| 1485 | "leaf ref1 {type leafref {path ../a/invalid;}}}", LYS_IN_YANG)); |
| 1486 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1487 | logbuf_assert("Invalid leafref path - unable to find \"../a/invalid\"."); |
| 1488 | assert_non_null(mod = lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;container a {leaf target2 {type uint8;}}" |
| 1489 | "leaf ref1 {type leafref {path ../../toohigh;}}}", LYS_IN_YANG)); |
| 1490 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1491 | logbuf_assert("Invalid leafref path \"../../toohigh\" - too many \"..\" in the path."); |
| 1492 | assert_non_null(mod = lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;container a {leaf target2 {type uint8;}}" |
| 1493 | "leaf ref1 {type leafref {path /a:invalid;}}}", LYS_IN_YANG)); |
| 1494 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1495 | logbuf_assert("Invalid leafref path - unable to find module connected with the prefix of the node \"/a:invalid\"."); |
| 1496 | assert_non_null(mod = lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;leaf target1 {type string;}container a {leaf target2 {type uint8;}}" |
| 1497 | "leaf ref1 {type leafref {path '/a[target2 = current()/../target1]/target2';}}}", LYS_IN_YANG)); |
| 1498 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1499 | logbuf_assert("Invalid leafref path - node \"/a\" is expected to be a list, but it is container."); |
| 1500 | assert_non_null(mod = lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;container a {leaf target2 {type uint8;}}" |
| 1501 | "leaf ref1 {type leafref {path /a!invalid;}}}", LYS_IN_YANG)); |
| 1502 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1503 | logbuf_assert("Invalid leafref path at character 3 (/a!invalid)."); |
| 1504 | assert_non_null(mod = lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;container a {leaf target2 {type uint8;}}" |
| 1505 | "leaf ref1 {type leafref {path /a;}}}", LYS_IN_YANG)); |
| 1506 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1507 | logbuf_assert("Invalid leafref path \"/a\" - target node is container instead of leaf or leaf-list."); |
| 1508 | assert_non_null(mod = lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;container a {leaf target2 {type uint8; status deprecated;}}" |
| 1509 | "leaf ref1 {type leafref {path /a/target2;}}}", LYS_IN_YANG)); |
| 1510 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1511 | logbuf_assert("A current definition \"ref1\" is not allowed to reference deprecated definition \"target2\"."); |
Radek Krejci | 2f4a029 | 2018-11-22 15:41:53 +0100 | [diff] [blame] | 1512 | assert_non_null(mod = lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;" |
| 1513 | "leaf ref1 {type leafref;}}", LYS_IN_YANG)); |
| 1514 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1515 | logbuf_assert("Missing path substatement for leafref type."); |
| 1516 | assert_non_null(mod = lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;typedef mytype {type leafref;}" |
| 1517 | "leaf ref1 {type mytype;}}", LYS_IN_YANG)); |
| 1518 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1519 | logbuf_assert("Missing path substatement for leafref type mytype."); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 1520 | assert_non_null(mod = lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;feature f;" |
| 1521 | "leaf ref {type leafref {path /target;}}leaf target {if-feature f;type string;}}", LYS_IN_YANG)); |
| 1522 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1523 | logbuf_assert("Invalid leafref path \"/target\" - set of features applicable to the leafref target is not a subset of features " |
| 1524 | "applicable to the leafref itself."); |
Radek Krejci | b57cf1e | 2018-11-23 14:07:05 +0100 | [diff] [blame] | 1525 | assert_non_null(mod = lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;" |
| 1526 | "leaf ref {type leafref {path /target;}}leaf target {type string;config false;}}", LYS_IN_YANG)); |
| 1527 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1528 | logbuf_assert("Invalid leafref path \"/target\" - target is supposed to represent configuration data (as the leafref does), but it does not."); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 1529 | |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 1530 | /* circular chain */ |
| 1531 | assert_non_null(mod = lys_parse_mem(ctx, "module aaa {namespace urn:aaa;prefix aaa;" |
| 1532 | "leaf ref1 {type leafref {path /ref2;}}" |
| 1533 | "leaf ref2 {type leafref {path /ref3;}}" |
Radek Krejci | 0c3f1ad | 2018-11-23 14:19:38 +0100 | [diff] [blame] | 1534 | "leaf ref3 {type leafref {path /ref4;}}" |
| 1535 | "leaf ref4 {type leafref {path /ref1;}}}", LYS_IN_YANG)); |
Radek Krejci | 412ddfa | 2018-11-23 11:44:11 +0100 | [diff] [blame] | 1536 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1537 | logbuf_assert("Invalid leafref path \"/ref1\" - circular chain of leafrefs detected."); |
| 1538 | |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1539 | *state = NULL; |
| 1540 | ly_ctx_destroy(ctx, NULL); |
| 1541 | } |
| 1542 | |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 1543 | static void |
| 1544 | test_type_empty(void **state) |
| 1545 | { |
| 1546 | *state = test_type_empty; |
| 1547 | |
| 1548 | struct ly_ctx *ctx; |
| 1549 | struct lys_module *mod; |
| 1550 | |
| 1551 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 1552 | |
| 1553 | /* invalid */ |
| 1554 | assert_non_null(mod = lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;" |
| 1555 | "leaf l {type empty; default x;}}", LYS_IN_YANG)); |
| 1556 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1557 | logbuf_assert("Leaf of type \"empty\" must not have a default value (x)."); |
| 1558 | |
| 1559 | assert_non_null(mod = lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;typedef mytype {type empty; default x;}" |
| 1560 | "leaf l {type mytype;}}", LYS_IN_YANG)); |
| 1561 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1562 | logbuf_assert("Invalid type \"mytype\" - \"empty\" type must not have a default value (x)."); |
| 1563 | |
| 1564 | *state = NULL; |
| 1565 | ly_ctx_destroy(ctx, NULL); |
| 1566 | } |
| 1567 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 1568 | |
| 1569 | static void |
| 1570 | test_type_union(void **state) |
| 1571 | { |
| 1572 | *state = test_type_union; |
| 1573 | |
| 1574 | struct ly_ctx *ctx; |
| 1575 | struct lys_module *mod; |
| 1576 | struct lysc_type *type; |
| 1577 | |
| 1578 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 1579 | |
| 1580 | assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a; typedef mybasetype {type string;}" |
| 1581 | "typedef mytype {type union {type int8; type mybasetype;}}" |
| 1582 | "leaf l {type mytype;}}", LYS_IN_YANG)); |
| 1583 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1584 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1585 | assert_non_null(type); |
| 1586 | assert_int_equal(2, type->refcount); |
| 1587 | assert_int_equal(LY_TYPE_UNION, type->basetype); |
| 1588 | assert_non_null(((struct lysc_type_union*)type)->types); |
| 1589 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_union*)type)->types)); |
| 1590 | assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_union*)type)->types[0]->basetype); |
| 1591 | assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union*)type)->types[1]->basetype); |
| 1592 | |
| 1593 | assert_non_null(mod = lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b; typedef mybasetype {type string;}" |
| 1594 | "typedef mytype {type union {type int8; type mybasetype;}}" |
| 1595 | "leaf l {type union {type decimal64 {fraction-digits 2;} type mytype;}}}", LYS_IN_YANG)); |
| 1596 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1597 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1598 | assert_non_null(type); |
| 1599 | assert_int_equal(1, type->refcount); |
| 1600 | assert_int_equal(LY_TYPE_UNION, type->basetype); |
| 1601 | assert_non_null(((struct lysc_type_union*)type)->types); |
| 1602 | assert_int_equal(3, LY_ARRAY_SIZE(((struct lysc_type_union*)type)->types)); |
| 1603 | assert_int_equal(LY_TYPE_DEC64, ((struct lysc_type_union*)type)->types[0]->basetype); |
| 1604 | assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_union*)type)->types[1]->basetype); |
| 1605 | assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union*)type)->types[2]->basetype); |
| 1606 | |
| 1607 | assert_non_null(mod = lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c; typedef mybasetype {type string;}" |
| 1608 | "typedef mytype {type union {type leafref {path ../target;} type mybasetype;}}" |
Radek Krejci | 6be5ff1 | 2018-11-26 13:18:15 +0100 | [diff] [blame] | 1609 | "leaf l {type union {type decimal64 {fraction-digits 2;} type mytype;}}" |
| 1610 | "leaf target {type leafref {path ../realtarget;}} leaf realtarget {type int8;}}", |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 1611 | LYS_IN_YANG)); |
| 1612 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1613 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1614 | assert_non_null(type); |
| 1615 | assert_int_equal(1, type->refcount); |
| 1616 | assert_int_equal(LY_TYPE_UNION, type->basetype); |
| 1617 | assert_non_null(((struct lysc_type_union*)type)->types); |
| 1618 | assert_int_equal(3, LY_ARRAY_SIZE(((struct lysc_type_union*)type)->types)); |
| 1619 | assert_int_equal(LY_TYPE_DEC64, ((struct lysc_type_union*)type)->types[0]->basetype); |
| 1620 | assert_int_equal(LY_TYPE_LEAFREF, ((struct lysc_type_union*)type)->types[1]->basetype); |
| 1621 | assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union*)type)->types[2]->basetype); |
| 1622 | assert_non_null(((struct lysc_type_leafref*)((struct lysc_type_union*)type)->types[1])->realtype); |
| 1623 | assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref*)((struct lysc_type_union*)type)->types[1])->realtype->basetype); |
| 1624 | |
Radek Krejci | 6be5ff1 | 2018-11-26 13:18:15 +0100 | [diff] [blame] | 1625 | /* invalid unions */ |
| 1626 | assert_non_null(mod = lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;typedef mytype {type union;}" |
| 1627 | "leaf l {type mytype;}}", LYS_IN_YANG)); |
| 1628 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1629 | logbuf_assert("Missing type substatement for union type mytype."); |
| 1630 | |
| 1631 | assert_non_null(mod = lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf l {type union;}}", LYS_IN_YANG)); |
| 1632 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1633 | logbuf_assert("Missing type substatement for union type."); |
| 1634 | |
| 1635 | assert_non_null(mod = lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;typedef mytype {type union{type int8; type string;}}" |
| 1636 | "leaf l {type mytype {type string;}}}", LYS_IN_YANG)); |
| 1637 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1638 | logbuf_assert("Invalid type substatement for the type not directly derived from union built-in type."); |
| 1639 | |
| 1640 | assert_non_null(mod = lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;typedef mytype {type union{type int8; type string;}}" |
| 1641 | "typedef mytype2 {type mytype {type string;}}leaf l {type mytype2;}}", LYS_IN_YANG)); |
| 1642 | assert_int_equal(LY_EVALID, lys_compile(mod, 0)); |
| 1643 | logbuf_assert("Invalid type substatement for the type \"mytype2\" not directly derived from union built-in type."); |
| 1644 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 1645 | *state = NULL; |
| 1646 | ly_ctx_destroy(ctx, NULL); |
| 1647 | } |
| 1648 | |
| 1649 | static void |
| 1650 | test_type_dflt(void **state) |
| 1651 | { |
| 1652 | *state = test_type_union; |
| 1653 | |
| 1654 | struct ly_ctx *ctx; |
| 1655 | struct lys_module *mod; |
| 1656 | struct lysc_type *type; |
| 1657 | |
| 1658 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 1659 | |
| 1660 | /* default is not inherited from union's types */ |
| 1661 | assert_non_null(mod = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a; typedef mybasetype {type string;default hello;units xxx;}" |
| 1662 | "leaf l {type union {type decimal64 {fraction-digits 2;} type mybasetype;}}}", LYS_IN_YANG)); |
| 1663 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1664 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1665 | assert_non_null(type); |
| 1666 | assert_int_equal(1, type->refcount); |
| 1667 | assert_int_equal(LY_TYPE_UNION, type->basetype); |
| 1668 | assert_non_null(((struct lysc_type_union*)type)->types); |
| 1669 | assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_type_union*)type)->types)); |
| 1670 | assert_int_equal(LY_TYPE_DEC64, ((struct lysc_type_union*)type)->types[0]->basetype); |
| 1671 | assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union*)type)->types[1]->basetype); |
| 1672 | assert_null(((struct lysc_node_leaf*)mod->compiled->data)->dflt); |
| 1673 | assert_null(((struct lysc_node_leaf*)mod->compiled->data)->units); |
| 1674 | |
| 1675 | assert_non_null(mod = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; typedef mybasetype {type string;default hello;units xxx;}" |
| 1676 | "leaf l {type mybasetype;}}", LYS_IN_YANG)); |
| 1677 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1678 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1679 | assert_non_null(type); |
| 1680 | assert_int_equal(2, type->refcount); |
| 1681 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 1682 | assert_string_equal("hello", ((struct lysc_node_leaf*)mod->compiled->data)->dflt); |
| 1683 | assert_string_equal("xxx", ((struct lysc_node_leaf*)mod->compiled->data)->units); |
| 1684 | |
| 1685 | assert_non_null(mod = lys_parse_mem(ctx, "module c {namespace urn:c;prefix c; typedef mybasetype {type string;default hello;units xxx;}" |
| 1686 | "leaf l {type mybasetype; default goodbye;units yyy;}}", LYS_IN_YANG)); |
| 1687 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1688 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1689 | assert_non_null(type); |
| 1690 | assert_int_equal(2, type->refcount); |
| 1691 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 1692 | assert_string_equal("goodbye", ((struct lysc_node_leaf*)mod->compiled->data)->dflt); |
| 1693 | assert_string_equal("yyy", ((struct lysc_node_leaf*)mod->compiled->data)->units); |
| 1694 | |
Radek Krejci | 6be5ff1 | 2018-11-26 13:18:15 +0100 | [diff] [blame] | 1695 | assert_non_null(mod = lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; typedef mybasetype {type string;default hello;units xxx;}" |
| 1696 | "typedef mytype {type mybasetype;}leaf l1 {type mytype; default goodbye;units yyy;}" |
| 1697 | "leaf l2 {type mytype;}}", LYS_IN_YANG)); |
| 1698 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1699 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1700 | assert_non_null(type); |
| 1701 | assert_int_equal(4, type->refcount); |
| 1702 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 1703 | assert_string_equal("goodbye", ((struct lysc_node_leaf*)mod->compiled->data)->dflt); |
| 1704 | assert_string_equal("yyy", ((struct lysc_node_leaf*)mod->compiled->data)->units); |
| 1705 | type = ((struct lysc_node_leaf*)mod->compiled->data->next)->type; |
| 1706 | assert_non_null(type); |
| 1707 | assert_int_equal(4, type->refcount); |
| 1708 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 1709 | assert_string_equal("hello", ((struct lysc_node_leaf*)mod->compiled->data->next)->dflt); |
| 1710 | assert_string_equal("xxx", ((struct lysc_node_leaf*)mod->compiled->data->next)->units); |
| 1711 | |
| 1712 | assert_non_null(mod = lys_parse_mem(ctx, "module e {namespace urn:e;prefix e; typedef mybasetype {type string;}" |
| 1713 | "typedef mytype {type mybasetype; default hello;units xxx;}leaf l {type mytype;}}", LYS_IN_YANG)); |
| 1714 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1715 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1716 | assert_non_null(type); |
| 1717 | assert_int_equal(3, type->refcount); |
| 1718 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 1719 | assert_string_equal("hello", ((struct lysc_node_leaf*)mod->compiled->data)->dflt); |
| 1720 | assert_string_equal("xxx", ((struct lysc_node_leaf*)mod->compiled->data)->units); |
| 1721 | |
Radek Krejci | b1a5dcc | 2018-11-26 14:50:05 +0100 | [diff] [blame] | 1722 | /* mandatory leaf does not takes default value from type */ |
| 1723 | assert_non_null(mod = lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;typedef mytype {type string; default hello;units xxx;}" |
| 1724 | "leaf l {type mytype; mandatory true;}}", LYS_IN_YANG)); |
| 1725 | assert_int_equal(LY_SUCCESS, lys_compile(mod, 0)); |
| 1726 | type = ((struct lysc_node_leaf*)mod->compiled->data)->type; |
| 1727 | assert_non_null(type); |
| 1728 | assert_int_equal(LY_TYPE_STRING, type->basetype); |
| 1729 | assert_null(((struct lysc_node_leaf*)mod->compiled->data)->dflt); |
| 1730 | assert_string_equal("xxx", ((struct lysc_node_leaf*)mod->compiled->data)->units); |
| 1731 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 1732 | *state = NULL; |
| 1733 | ly_ctx_destroy(ctx, NULL); |
| 1734 | } |
| 1735 | |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 1736 | int main(void) |
| 1737 | { |
| 1738 | const struct CMUnitTest tests[] = { |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1739 | cmocka_unit_test_setup_teardown(test_module, logger_setup, logger_teardown), |
| 1740 | cmocka_unit_test_setup_teardown(test_feature, logger_setup, logger_teardown), |
| 1741 | cmocka_unit_test_setup_teardown(test_identity, logger_setup, logger_teardown), |
Radek Krejci | 0f07bed | 2018-11-13 14:01:40 +0100 | [diff] [blame] | 1742 | cmocka_unit_test_setup_teardown(test_type_length, logger_setup, logger_teardown), |
| 1743 | cmocka_unit_test_setup_teardown(test_type_range, logger_setup, logger_teardown), |
Radek Krejci | cda7415 | 2018-11-13 15:27:32 +0100 | [diff] [blame] | 1744 | cmocka_unit_test_setup_teardown(test_type_pattern, logger_setup, logger_teardown), |
Radek Krejci | 8b76466 | 2018-11-14 14:15:13 +0100 | [diff] [blame] | 1745 | cmocka_unit_test_setup_teardown(test_type_enum, logger_setup, logger_teardown), |
| 1746 | cmocka_unit_test_setup_teardown(test_type_bits, logger_setup, logger_teardown), |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 1747 | cmocka_unit_test_setup_teardown(test_type_dec64, logger_setup, logger_teardown), |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 1748 | cmocka_unit_test_setup_teardown(test_type_instanceid, logger_setup, logger_teardown), |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 1749 | cmocka_unit_test_setup_teardown(test_type_identityref, logger_setup, logger_teardown), |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1750 | cmocka_unit_test_setup_teardown(test_type_leafref, logger_setup, logger_teardown), |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 1751 | cmocka_unit_test_setup_teardown(test_type_empty, logger_setup, logger_teardown), |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 1752 | cmocka_unit_test_setup_teardown(test_type_union, logger_setup, logger_teardown), |
| 1753 | cmocka_unit_test_setup_teardown(test_type_dflt, logger_setup, logger_teardown), |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 1754 | cmocka_unit_test_setup_teardown(test_node_container, logger_setup, logger_teardown), |
Radek Krejci | 0e5d838 | 2018-11-28 16:37:53 +0100 | [diff] [blame] | 1755 | cmocka_unit_test_setup_teardown(test_node_leaflist, logger_setup, logger_teardown), |
Radek Krejci | dd4e8d4 | 2018-10-16 14:55:43 +0200 | [diff] [blame] | 1756 | }; |
| 1757 | |
| 1758 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 1759 | } |