David Sedlák | b1ce3f8 | 2019-06-05 14:37:26 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file test_parser_yin.c |
| 3 | * @author David Sedlák <xsedla1d@stud.fit.vutbr.cz> |
| 4 | * @brief unit tests for functions from parser_yin.c |
| 5 | * |
| 6 | * Copyright (c) 2015 - 2019 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 | |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 15 | #include <stdarg.h> |
| 16 | #include <stddef.h> |
| 17 | #include <setjmp.h> |
| 18 | #include <cmocka.h> |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <string.h> |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 22 | #include <stdbool.h> |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 23 | |
David Sedlák | ecf5eb8 | 2019-06-03 14:12:44 +0200 | [diff] [blame] | 24 | #include "../../src/common.h" |
| 25 | #include "../../src/tree_schema.h" |
| 26 | #include "../../src/tree_schema_internal.h" |
| 27 | #include "../../src/parser_yin.h" |
David Sedlák | 8f5bce0 | 2019-06-03 16:41:08 +0200 | [diff] [blame] | 28 | #include "../../src/xml.h" |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 29 | |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 30 | /* prototypes of static functions */ |
| 31 | void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext); |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 32 | void lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext); |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 33 | void lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 34 | void lysp_type_free(struct ly_ctx *ctx, struct lysp_type *type); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 35 | void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 36 | void lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 37 | void lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 38 | void lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 39 | void lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include); |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 40 | void lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat); |
David Sedlák | 28794f2 | 2019-07-22 16:45:00 +0200 | [diff] [blame] | 41 | void lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 42 | void lysp_notif_free(struct ly_ctx *ctx, struct lysp_notif *notif); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 43 | void lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 44 | void lysp_action_inout_free(struct ly_ctx *ctx, struct lysp_action_inout *inout); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 45 | void lysp_action_free(struct ly_ctx *ctx, struct lysp_action *action); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 46 | void lysp_augment_free(struct ly_ctx *ctx, struct lysp_augment *augment); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 47 | void lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 48 | void lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 49 | void lysp_submodule_free(struct ly_ctx *ctx, struct lysp_submodule *submod); |
| 50 | void lysp_import_free(struct ly_ctx *ctx, struct lysp_import *import); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 51 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 52 | /* wrapping element used for mocking has nothing to do with real module structure */ |
| 53 | #define ELEMENT_WRAPPER_START "<status xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 54 | #define ELEMENT_WRAPPER_END "</status>" |
| 55 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 56 | struct state { |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 57 | struct ly_ctx *ctx; |
David Sedlák | 3017da4 | 2019-02-15 09:48:04 +0100 | [diff] [blame] | 58 | struct lys_module *mod; |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 59 | struct lysp_module *lysp_mod; |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 60 | struct yin_parser_ctx *yin_ctx; |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 61 | bool finished_correctly; |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 62 | }; |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 63 | |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 64 | #define BUFSIZE 1024 |
| 65 | char logbuf[BUFSIZE] = {0}; |
| 66 | int store = -1; /* negative for infinite logging, positive for limited logging */ |
| 67 | |
| 68 | /* set to 0 to printing error messages to stderr instead of checking them in code */ |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 69 | #define ENABLE_LOGGER_CHECKING 1 |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 70 | |
| 71 | #if ENABLE_LOGGER_CHECKING |
| 72 | static void |
| 73 | logger(LY_LOG_LEVEL level, const char *msg, const char *path) |
| 74 | { |
| 75 | (void) level; /* unused */ |
| 76 | if (store) { |
| 77 | if (path && path[0]) { |
| 78 | snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path); |
| 79 | } else { |
| 80 | strncpy(logbuf, msg, BUFSIZE - 1); |
| 81 | } |
| 82 | if (store > 0) { |
| 83 | --store; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | #endif |
| 88 | |
| 89 | #if ENABLE_LOGGER_CHECKING |
| 90 | # define logbuf_assert(str) assert_string_equal(logbuf, str) |
| 91 | #else |
| 92 | # define logbuf_assert(str) |
| 93 | #endif |
| 94 | |
| 95 | #define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \ |
| 96 | str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 97 | assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \ |
| 98 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \ |
| 99 | CLEANUP |
| 100 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 101 | int |
| 102 | setup_ly_ctx(void **state) |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 103 | { |
| 104 | struct state *st = NULL; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 105 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 106 | /* allocate state variable */ |
| 107 | (*state) = st = calloc(1, sizeof(*st)); |
| 108 | if (!st) { |
| 109 | fprintf(stderr, "Memmory allocation failed"); |
| 110 | return EXIT_FAILURE; |
| 111 | } |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 112 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 113 | /* create new libyang context */ |
| 114 | ly_ctx_new(NULL, 0, &st->ctx); |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 115 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 116 | return EXIT_SUCCESS; |
| 117 | } |
| 118 | |
| 119 | int |
| 120 | destroy_ly_ctx(void **state) |
| 121 | { |
| 122 | struct state *st = *state; |
| 123 | ly_ctx_destroy(st->ctx, NULL); |
| 124 | free(st); |
| 125 | |
| 126 | return EXIT_SUCCESS; |
| 127 | } |
| 128 | |
| 129 | static int |
| 130 | setup_f(void **state) |
| 131 | { |
| 132 | struct state *st = *state; |
| 133 | |
| 134 | #if ENABLE_LOGGER_CHECKING |
| 135 | /* setup logger */ |
| 136 | ly_set_log_clb(logger, 1); |
| 137 | #endif |
| 138 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 139 | /* allocate new module */ |
| 140 | st->mod = calloc(1, sizeof(*st->mod)); |
| 141 | st->mod->ctx = st->ctx; |
| 142 | |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 143 | /* allocate new parsed module */ |
| 144 | st->lysp_mod = calloc(1, sizeof(*st->lysp_mod)); |
| 145 | st->lysp_mod->mod = calloc(1, sizeof(*st->lysp_mod->mod)); |
| 146 | st->lysp_mod->mod->ctx = st->ctx; |
| 147 | |
| 148 | /* allocate parser context */ |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 149 | st->yin_ctx = calloc(1, sizeof(*st->yin_ctx)); |
| 150 | st->yin_ctx->xml_ctx.ctx = st->ctx; |
| 151 | st->yin_ctx->xml_ctx.line = 1; |
David Sedlák | 8f5bce0 | 2019-06-03 16:41:08 +0200 | [diff] [blame] | 152 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 153 | return EXIT_SUCCESS; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | static int |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 157 | teardown_f(void **state) |
| 158 | { |
| 159 | struct state *st = *(struct state **)state; |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 160 | struct lys_module *temp; |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 161 | |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 162 | #if ENABLE_LOGGER_CHECKING |
| 163 | /* teardown logger */ |
| 164 | if (!st->finished_correctly && logbuf[0] != '\0') { |
| 165 | fprintf(stderr, "%s\n", logbuf); |
| 166 | } |
| 167 | #endif |
| 168 | |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 169 | temp = st->lysp_mod->mod; |
| 170 | |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 171 | lyxml_context_clear(&st->yin_ctx->xml_ctx); |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 172 | lys_module_free(st->mod, NULL); |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 173 | lysp_module_free(st->lysp_mod); |
| 174 | lys_module_free(temp, NULL); |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 175 | free(st->yin_ctx); |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 176 | |
| 177 | return EXIT_SUCCESS; |
| 178 | } |
| 179 | |
David Sedlák | 392af4f | 2019-06-04 16:02:42 +0200 | [diff] [blame] | 180 | static struct state* |
| 181 | reset_state(void **state) |
| 182 | { |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 183 | ((struct state *)*state)->finished_correctly = true; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 184 | logbuf[0] = '\0'; |
David Sedlák | 392af4f | 2019-06-04 16:02:42 +0200 | [diff] [blame] | 185 | teardown_f(state); |
| 186 | setup_f(state); |
| 187 | |
| 188 | return *state; |
| 189 | } |
| 190 | |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 191 | void |
| 192 | logbuf_clean(void) |
| 193 | { |
| 194 | logbuf[0] = '\0'; |
| 195 | } |
| 196 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 197 | static int |
| 198 | setup_logger(void **state) |
| 199 | { |
| 200 | (void)state; /* unused */ |
| 201 | #if ENABLE_LOGGER_CHECKING |
| 202 | /* setup logger */ |
| 203 | ly_set_log_clb(logger, 1); |
| 204 | #endif |
| 205 | |
| 206 | logbuf[0] = '\0'; |
| 207 | |
| 208 | return EXIT_SUCCESS; |
| 209 | } |
| 210 | |
| 211 | static int |
| 212 | teardown_logger(void **state) |
| 213 | { |
| 214 | struct state *st = *state; |
| 215 | |
| 216 | #if ENABLE_LOGGER_CHECKING |
| 217 | /* teardown logger */ |
| 218 | if (!st->finished_correctly && logbuf[0] != '\0') { |
| 219 | fprintf(stderr, "%s\n", logbuf); |
| 220 | } |
| 221 | #endif |
| 222 | |
| 223 | return EXIT_SUCCESS; |
| 224 | } |
| 225 | |
| 226 | static int |
| 227 | setup_element_test(void **state) |
| 228 | { |
| 229 | setup_logger(state); |
| 230 | struct state *st = *state; |
| 231 | |
| 232 | st->yin_ctx = calloc(1, sizeof(*st->yin_ctx)); |
| 233 | |
| 234 | /* allocate parser context */ |
| 235 | st->yin_ctx->xml_ctx.ctx = st->ctx; |
| 236 | st->yin_ctx->xml_ctx.line = 1; |
| 237 | |
| 238 | return EXIT_SUCCESS; |
| 239 | } |
| 240 | |
| 241 | static int |
| 242 | teardown_element_test(void **state) |
| 243 | { |
| 244 | struct state *st = *(struct state **)state; |
| 245 | |
| 246 | lyxml_context_clear(&st->yin_ctx->xml_ctx); |
| 247 | free(st->yin_ctx); |
| 248 | |
| 249 | teardown_logger(state); |
| 250 | |
| 251 | return EXIT_SUCCESS; |
| 252 | } |
| 253 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 254 | static void |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 255 | test_yin_match_keyword(void **state) |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 256 | { |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 257 | struct state *st = *state; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 258 | |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 259 | const char *prefix, *name; |
| 260 | struct yin_arg_record *args = NULL; |
| 261 | size_t prefix_len, name_len; |
| 262 | /* create mock yin namespace in xml context */ |
| 263 | const char *data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />"; |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 264 | lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len); |
| 265 | yin_load_attributes(st->yin_ctx, &data, &args); |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 266 | LY_ARRAY_FREE(args); |
| 267 | |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 268 | assert_int_equal(yin_match_keyword(st->yin_ctx, "anydatax", strlen("anydatax"), prefix, prefix_len, YANG_NONE), YANG_NONE); |
| 269 | assert_int_equal(yin_match_keyword(st->yin_ctx, "asdasd", strlen("asdasd"), prefix, prefix_len, YANG_NONE), YANG_NONE); |
| 270 | assert_int_equal(yin_match_keyword(st->yin_ctx, "", 0, prefix, prefix_len, YANG_NONE), YANG_NONE); |
| 271 | assert_int_equal(yin_match_keyword(st->yin_ctx, "anydata", strlen("anydata"), prefix, prefix_len, YANG_NONE), YANG_ANYDATA); |
| 272 | assert_int_equal(yin_match_keyword(st->yin_ctx, "anyxml", strlen("anyxml"), prefix, prefix_len, YANG_NONE), YANG_ANYXML); |
| 273 | assert_int_equal(yin_match_keyword(st->yin_ctx, "argument", strlen("argument"), prefix, prefix_len, YANG_NONE), YANG_ARGUMENT); |
| 274 | assert_int_equal(yin_match_keyword(st->yin_ctx, "augment", strlen("augment"), prefix, prefix_len, YANG_NONE), YANG_AUGMENT); |
| 275 | assert_int_equal(yin_match_keyword(st->yin_ctx, "base", strlen("base"), prefix, prefix_len, YANG_NONE), YANG_BASE); |
| 276 | assert_int_equal(yin_match_keyword(st->yin_ctx, "belongs-to", strlen("belongs-to"), prefix, prefix_len, YANG_NONE), YANG_BELONGS_TO); |
| 277 | assert_int_equal(yin_match_keyword(st->yin_ctx, "bit", strlen("bit"), prefix, prefix_len, YANG_NONE), YANG_BIT); |
| 278 | assert_int_equal(yin_match_keyword(st->yin_ctx, "case", strlen("case"), prefix, prefix_len, YANG_NONE), YANG_CASE); |
| 279 | assert_int_equal(yin_match_keyword(st->yin_ctx, "choice", strlen("choice"), prefix, prefix_len, YANG_NONE), YANG_CHOICE); |
| 280 | assert_int_equal(yin_match_keyword(st->yin_ctx, "config", strlen("config"), prefix, prefix_len, YANG_NONE), YANG_CONFIG); |
| 281 | assert_int_equal(yin_match_keyword(st->yin_ctx, "contact", strlen("contact"), prefix, prefix_len, YANG_NONE), YANG_CONTACT); |
| 282 | assert_int_equal(yin_match_keyword(st->yin_ctx, "container", strlen("container"), prefix, prefix_len, YANG_NONE), YANG_CONTAINER); |
| 283 | assert_int_equal(yin_match_keyword(st->yin_ctx, "default", strlen("default"), prefix, prefix_len, YANG_NONE), YANG_DEFAULT); |
| 284 | assert_int_equal(yin_match_keyword(st->yin_ctx, "description", strlen("description"), prefix, prefix_len, YANG_NONE), YANG_DESCRIPTION); |
| 285 | assert_int_equal(yin_match_keyword(st->yin_ctx, "deviate", strlen("deviate"), prefix, prefix_len, YANG_NONE), YANG_DEVIATE); |
| 286 | assert_int_equal(yin_match_keyword(st->yin_ctx, "deviation", strlen("deviation"), prefix, prefix_len, YANG_NONE), YANG_DEVIATION); |
| 287 | assert_int_equal(yin_match_keyword(st->yin_ctx, "enum", strlen("enum"), prefix, prefix_len, YANG_NONE), YANG_ENUM); |
| 288 | assert_int_equal(yin_match_keyword(st->yin_ctx, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len, YANG_NONE), YANG_ERROR_APP_TAG); |
| 289 | assert_int_equal(yin_match_keyword(st->yin_ctx, "error-message", strlen("error-message"), prefix, prefix_len, YANG_NONE), YANG_ERROR_MESSAGE); |
| 290 | assert_int_equal(yin_match_keyword(st->yin_ctx, "extension", strlen("extension"), prefix, prefix_len, YANG_NONE), YANG_EXTENSION); |
| 291 | assert_int_equal(yin_match_keyword(st->yin_ctx, "feature", strlen("feature"), prefix, prefix_len, YANG_NONE), YANG_FEATURE); |
| 292 | assert_int_equal(yin_match_keyword(st->yin_ctx, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, YANG_NONE), YANG_FRACTION_DIGITS); |
| 293 | assert_int_equal(yin_match_keyword(st->yin_ctx, "grouping", strlen("grouping"), prefix, prefix_len, YANG_NONE), YANG_GROUPING); |
| 294 | assert_int_equal(yin_match_keyword(st->yin_ctx, "identity", strlen("identity"), prefix, prefix_len, YANG_NONE), YANG_IDENTITY); |
| 295 | assert_int_equal(yin_match_keyword(st->yin_ctx, "if-feature", strlen("if-feature"), prefix, prefix_len, YANG_NONE), YANG_IF_FEATURE); |
| 296 | assert_int_equal(yin_match_keyword(st->yin_ctx, "import", strlen("import"), prefix, prefix_len, YANG_NONE), YANG_IMPORT); |
| 297 | assert_int_equal(yin_match_keyword(st->yin_ctx, "include", strlen("include"), prefix, prefix_len, YANG_NONE), YANG_INCLUDE); |
| 298 | assert_int_equal(yin_match_keyword(st->yin_ctx, "input", strlen("input"), prefix, prefix_len, YANG_NONE), YANG_INPUT); |
| 299 | assert_int_equal(yin_match_keyword(st->yin_ctx, "key", strlen("key"), prefix, prefix_len, YANG_NONE), YANG_KEY); |
| 300 | assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf", strlen("leaf"), prefix, prefix_len, YANG_NONE), YANG_LEAF); |
| 301 | assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf-list", strlen("leaf-list"), prefix, prefix_len, YANG_NONE), YANG_LEAF_LIST); |
| 302 | assert_int_equal(yin_match_keyword(st->yin_ctx, "length", strlen("length"), prefix, prefix_len, YANG_NONE), YANG_LENGTH); |
| 303 | assert_int_equal(yin_match_keyword(st->yin_ctx, "list", strlen("list"), prefix, prefix_len, YANG_NONE), YANG_LIST); |
| 304 | assert_int_equal(yin_match_keyword(st->yin_ctx, "mandatory", strlen("mandatory"), prefix, prefix_len, YANG_NONE), YANG_MANDATORY); |
| 305 | assert_int_equal(yin_match_keyword(st->yin_ctx, "max-elements", strlen("max-elements"), prefix, prefix_len, YANG_NONE), YANG_MAX_ELEMENTS); |
| 306 | assert_int_equal(yin_match_keyword(st->yin_ctx, "min-elements", strlen("min-elements"), prefix, prefix_len, YANG_NONE), YANG_MIN_ELEMENTS); |
| 307 | assert_int_equal(yin_match_keyword(st->yin_ctx, "modifier", strlen("modifier"), prefix, prefix_len, YANG_NONE), YANG_MODIFIER); |
| 308 | assert_int_equal(yin_match_keyword(st->yin_ctx, "module", strlen("module"), prefix, prefix_len, YANG_NONE), YANG_MODULE); |
| 309 | assert_int_equal(yin_match_keyword(st->yin_ctx, "must", strlen("must"), prefix, prefix_len, YANG_NONE), YANG_MUST); |
| 310 | assert_int_equal(yin_match_keyword(st->yin_ctx, "namespace", strlen("namespace"), prefix, prefix_len, YANG_NONE), YANG_NAMESPACE); |
| 311 | assert_int_equal(yin_match_keyword(st->yin_ctx, "notification", strlen("notification"), prefix, prefix_len, YANG_NONE), YANG_NOTIFICATION); |
| 312 | assert_int_equal(yin_match_keyword(st->yin_ctx, "ordered-by", strlen("ordered-by"), prefix, prefix_len, YANG_NONE), YANG_ORDERED_BY); |
| 313 | assert_int_equal(yin_match_keyword(st->yin_ctx, "organization", strlen("organization"), prefix, prefix_len, YANG_NONE), YANG_ORGANIZATION); |
| 314 | assert_int_equal(yin_match_keyword(st->yin_ctx, "output", strlen("output"), prefix, prefix_len, YANG_NONE), YANG_OUTPUT); |
| 315 | assert_int_equal(yin_match_keyword(st->yin_ctx, "path", strlen("path"), prefix, prefix_len, YANG_NONE), YANG_PATH); |
| 316 | assert_int_equal(yin_match_keyword(st->yin_ctx, "pattern", strlen("pattern"), prefix, prefix_len, YANG_NONE), YANG_PATTERN); |
| 317 | assert_int_equal(yin_match_keyword(st->yin_ctx, "position", strlen("position"), prefix, prefix_len, YANG_NONE), YANG_POSITION); |
| 318 | assert_int_equal(yin_match_keyword(st->yin_ctx, "prefix", strlen("prefix"), prefix, prefix_len, YANG_NONE), YANG_PREFIX); |
| 319 | assert_int_equal(yin_match_keyword(st->yin_ctx, "presence", strlen("presence"), prefix, prefix_len, YANG_NONE), YANG_PRESENCE); |
| 320 | assert_int_equal(yin_match_keyword(st->yin_ctx, "range", strlen("range"), prefix, prefix_len, YANG_NONE), YANG_RANGE); |
| 321 | assert_int_equal(yin_match_keyword(st->yin_ctx, "reference", strlen("reference"), prefix, prefix_len, YANG_NONE), YANG_REFERENCE); |
| 322 | assert_int_equal(yin_match_keyword(st->yin_ctx, "refine", strlen("refine"), prefix, prefix_len, YANG_NONE), YANG_REFINE); |
| 323 | assert_int_equal(yin_match_keyword(st->yin_ctx, "require-instance", strlen("require-instance"), prefix, prefix_len, YANG_NONE), YANG_REQUIRE_INSTANCE); |
| 324 | assert_int_equal(yin_match_keyword(st->yin_ctx, "revision", strlen("revision"), prefix, prefix_len, YANG_NONE), YANG_REVISION); |
| 325 | assert_int_equal(yin_match_keyword(st->yin_ctx, "revision-date", strlen("revision-date"), prefix, prefix_len, YANG_NONE), YANG_REVISION_DATE); |
| 326 | assert_int_equal(yin_match_keyword(st->yin_ctx, "rpc", strlen("rpc"), prefix, prefix_len, YANG_NONE), YANG_RPC); |
| 327 | assert_int_equal(yin_match_keyword(st->yin_ctx, "status", strlen("status"), prefix, prefix_len, YANG_NONE), YANG_STATUS); |
| 328 | assert_int_equal(yin_match_keyword(st->yin_ctx, "submodule", strlen("submodule"), prefix, prefix_len, YANG_NONE), YANG_SUBMODULE); |
| 329 | assert_int_equal(yin_match_keyword(st->yin_ctx, "type", strlen("type"), prefix, prefix_len, YANG_NONE), YANG_TYPE); |
| 330 | assert_int_equal(yin_match_keyword(st->yin_ctx, "typedef", strlen("typedef"), prefix, prefix_len, YANG_NONE), YANG_TYPEDEF); |
| 331 | assert_int_equal(yin_match_keyword(st->yin_ctx, "unique", strlen("unique"), prefix, prefix_len, YANG_NONE), YANG_UNIQUE); |
| 332 | assert_int_equal(yin_match_keyword(st->yin_ctx, "units", strlen("units"), prefix, prefix_len, YANG_NONE), YANG_UNITS); |
| 333 | assert_int_equal(yin_match_keyword(st->yin_ctx, "uses", strlen("uses"), prefix, prefix_len, YANG_NONE), YANG_USES); |
| 334 | assert_int_equal(yin_match_keyword(st->yin_ctx, "value", strlen("value"), prefix, prefix_len, YANG_NONE), YANG_VALUE); |
| 335 | assert_int_equal(yin_match_keyword(st->yin_ctx, "when", strlen("when"), prefix, prefix_len, YANG_NONE), YANG_WHEN); |
| 336 | assert_int_equal(yin_match_keyword(st->yin_ctx, "yang-version", strlen("yang-version"), prefix, prefix_len, YANG_NONE), YANG_YANG_VERSION); |
| 337 | assert_int_equal(yin_match_keyword(st->yin_ctx, "yin-element", strlen("yin-element"), prefix, prefix_len, YANG_NONE), YANG_YIN_ELEMENT); |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 338 | |
| 339 | st->finished_correctly = true; |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 340 | } |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 341 | |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 342 | static void |
David Sedlák | 060b00e | 2019-06-19 11:12:06 +0200 | [diff] [blame] | 343 | test_yin_match_argument_name(void **state) |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 344 | { |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 345 | (void)state; /* unused */ |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 346 | |
David Sedlák | 060b00e | 2019-06-19 11:12:06 +0200 | [diff] [blame] | 347 | assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN); |
| 348 | assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN); |
| 349 | assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN); |
| 350 | assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION); |
| 351 | assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE); |
| 352 | assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE); |
| 353 | assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME); |
| 354 | assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG); |
| 355 | assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE); |
| 356 | assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT); |
| 357 | assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI); |
| 358 | assert_int_equal(yin_match_argument_name("value", 5), YIN_ARG_VALUE); |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 359 | } |
| 360 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 361 | static void |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 362 | test_yin_parse_element_generic(void **state) |
| 363 | { |
| 364 | const char *prefix, *name; |
| 365 | struct state *st = *state; |
| 366 | struct lysp_ext_instance exts; |
| 367 | size_t prefix_len, name_len; |
| 368 | LY_ERR ret; |
| 369 | |
| 370 | memset(&exts, 0, sizeof(exts)); |
| 371 | |
| 372 | const char *data = "<elem attr=\"value\">text_value</elem>"; |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 373 | lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 374 | ret = yin_parse_element_generic(st->yin_ctx, name, name_len, &data, &exts.child); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 375 | assert_int_equal(ret, LY_SUCCESS); |
David Sedlák | 1fdb252 | 2019-07-09 16:22:57 +0200 | [diff] [blame] | 376 | assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 377 | assert_string_equal(exts.child->stmt, "elem"); |
| 378 | assert_string_equal(exts.child->arg, "text_value"); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 379 | assert_string_equal(exts.child->child->stmt, "attr"); |
| 380 | assert_string_equal(exts.child->child->arg, "value"); |
| 381 | assert_true(exts.child->child->flags & LYS_YIN_ATTR); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 382 | lysp_ext_instance_free(st->ctx, &exts); |
David Sedlák | 5392a21 | 2019-07-01 09:19:10 +0200 | [diff] [blame] | 383 | st = reset_state(state); |
| 384 | |
| 385 | data = "<elem></elem>"; |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 386 | lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 387 | ret = yin_parse_element_generic(st->yin_ctx, name, name_len, &data, &exts.child); |
David Sedlák | 5392a21 | 2019-07-01 09:19:10 +0200 | [diff] [blame] | 388 | assert_int_equal(ret, LY_SUCCESS); |
| 389 | assert_string_equal(exts.child->stmt, "elem"); |
| 390 | assert_null(exts.child->child); |
| 391 | assert_null(exts.child->arg); |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 392 | assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END); |
David Sedlák | 5392a21 | 2019-07-01 09:19:10 +0200 | [diff] [blame] | 393 | lysp_ext_instance_free(st->ctx, &exts); |
| 394 | |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 395 | st->finished_correctly = true; |
| 396 | } |
| 397 | |
| 398 | static void |
| 399 | test_yin_parse_extension_instance(void **state) |
| 400 | { |
| 401 | LY_ERR ret; |
| 402 | struct state *st = *state; |
| 403 | const char *prefix, *name; |
| 404 | size_t prefix_len, name_len; |
| 405 | struct yin_arg_record *args = NULL; |
| 406 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 407 | const char *data = "<ext value1=\"test\" value=\"test2\"><subelem>text</subelem></ext>"; |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 408 | lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len); |
| 409 | yin_load_attributes(st->yin_ctx, &data, &args); |
David Sedlák | 1f90d25 | 2019-07-10 17:09:32 +0200 | [diff] [blame] | 410 | ret = yin_parse_extension_instance(st->yin_ctx, args, &data, name2fullname(name, prefix_len), |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 411 | namelen2fulllen(name_len, prefix_len), LYEXT_SUBSTMT_CONTACT, 0, &exts); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 412 | assert_int_equal(ret, LY_SUCCESS); |
| 413 | assert_string_equal(exts->name, "ext"); |
| 414 | assert_int_equal(exts->insubstmt_index, 0); |
| 415 | assert_true(exts->insubstmt == LYEXT_SUBSTMT_CONTACT); |
| 416 | assert_true(exts->yin & LYS_YIN); |
| 417 | assert_string_equal(exts->child->stmt, "value1"); |
| 418 | assert_string_equal(exts->child->arg, "test"); |
| 419 | assert_null(exts->child->child); |
| 420 | assert_true(exts->child->flags & LYS_YIN_ATTR); |
| 421 | assert_string_equal(exts->child->next->stmt, "value"); |
| 422 | assert_string_equal(exts->child->next->arg, "test2"); |
| 423 | assert_null(exts->child->next->child); |
| 424 | assert_true(exts->child->next->flags & LYS_YIN_ATTR); |
| 425 | |
| 426 | assert_string_equal(exts->child->next->next->stmt, "subelem"); |
| 427 | assert_string_equal(exts->child->next->next->arg, "text"); |
| 428 | assert_null(exts->child->next->next->child); |
| 429 | assert_null(exts->child->next->next->next); |
| 430 | assert_false(exts->child->next->next->flags & LYS_YIN_ATTR); |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 431 | assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 432 | LY_ARRAY_FREE(args); |
| 433 | lysp_ext_instance_free(st->ctx, exts); |
| 434 | LY_ARRAY_FREE(exts); |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 435 | exts = NULL; |
| 436 | args = NULL; |
| 437 | st = reset_state(state); |
| 438 | |
| 439 | data = "<extension-elem />"; |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 440 | lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len); |
| 441 | yin_load_attributes(st->yin_ctx, &data, &args); |
David Sedlák | 1f90d25 | 2019-07-10 17:09:32 +0200 | [diff] [blame] | 442 | ret = yin_parse_extension_instance(st->yin_ctx, args, &data, name, name_len, LYEXT_SUBSTMT_CONTACT, 0, &exts); |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 443 | assert_int_equal(ret, LY_SUCCESS); |
| 444 | assert_string_equal(exts->name, "extension-elem"); |
| 445 | assert_null(exts->argument); |
| 446 | assert_null(exts->child); |
| 447 | assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT); |
| 448 | assert_int_equal(exts->insubstmt_index, 0); |
| 449 | assert_true(exts->yin & LYS_YIN); |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 450 | assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END); |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 451 | LY_ARRAY_FREE(args); |
| 452 | lysp_ext_instance_free(st->ctx, exts); |
| 453 | LY_ARRAY_FREE(exts); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 454 | st->finished_correctly = true; |
| 455 | } |
| 456 | |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 457 | static void |
| 458 | test_yin_parse_content(void **state) |
| 459 | { |
| 460 | struct state *st = *state; |
| 461 | LY_ERR ret = LY_SUCCESS; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame^] | 462 | const char *name, *prefix; |
| 463 | size_t name_len, prefix_len; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 464 | const char *data = "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 465 | "<custom xmlns=\"my-ext\">" |
| 466 | "totally amazing extension" |
| 467 | "</custom>" |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 468 | "<extension name=\"ext\">" |
| 469 | "<argument name=\"argname\"></argument>" |
| 470 | "<description><text>desc</text></description>" |
| 471 | "<reference><text>ref</text></reference>" |
| 472 | "<status value=\"deprecated\"></status>" |
| 473 | "</extension>" |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 474 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 475 | "<if-feature name=\"foo\"></if-feature>" |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 476 | "<when condition=\"condition...\">" |
| 477 | "<reference><text>when_ref</text></reference>" |
| 478 | "<description><text>when_desc</text></description>" |
| 479 | "</when>" |
David Sedlák | e1a3030 | 2019-07-10 13:49:38 +0200 | [diff] [blame] | 480 | "<config value=\"true\"/>" |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 481 | "<error-message>" |
| 482 | "<value>error-msg</value>" |
| 483 | "</error-message>" |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 484 | "<error-app-tag value=\"err-app-tag\"/>" |
David Sedlák | a5b1d38 | 2019-07-10 16:31:09 +0200 | [diff] [blame] | 485 | "<units name=\"radians\"></units>" |
David Sedlák | e7084ce | 2019-07-10 16:44:15 +0200 | [diff] [blame] | 486 | "<default value=\"default-value\"/>" |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 487 | "<position value=\"25\"></position>" |
| 488 | "<value value=\"-5\"/>" |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 489 | "<require-instance value=\"true\"></require-instance>" |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 490 | "<range value=\"5..10\" />" |
David Sedlák | 438ae43 | 2019-07-11 15:36:54 +0200 | [diff] [blame] | 491 | "<length value=\"baf\"/>" |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 492 | "<pattern value='pattern'>" |
| 493 | "<modifier value='invert-match'/>" |
| 494 | "</pattern>" |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 495 | "<enum name=\"yay\">" |
| 496 | "</enum>" |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 497 | "</prefix>"; |
| 498 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 499 | const char **if_features = NULL; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 500 | struct yin_arg_record *attrs = NULL; |
David Sedlák | e7084ce | 2019-07-10 16:44:15 +0200 | [diff] [blame] | 501 | const char *value, *err_msg, *app_tag, *units, *def; |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 502 | struct lysp_ext *ext_def = NULL; |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 503 | struct lysp_when *when_p = NULL; |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 504 | struct lysp_type_enum pos_enum = {}, val_enum = {}; |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 505 | struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {}; |
David Sedlák | e1a3030 | 2019-07-10 13:49:38 +0200 | [diff] [blame] | 506 | uint8_t config = 0; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 507 | |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame^] | 508 | lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len); |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 509 | yin_load_attributes(st->yin_ctx, &data, &attrs); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 510 | |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 511 | struct yin_subelement subelems[17] = { |
David Sedlák | 438ae43 | 2019-07-11 15:36:54 +0200 | [diff] [blame] | 512 | {YANG_CONFIG, &config, 0}, |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 513 | {YANG_DEFAULT, &def, YIN_SUBELEM_UNIQUE}, |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 514 | {YANG_ENUM, &enum_type, 0}, |
David Sedlák | 438ae43 | 2019-07-11 15:36:54 +0200 | [diff] [blame] | 515 | {YANG_ERROR_APP_TAG, &app_tag, 0}, |
| 516 | {YANG_ERROR_MESSAGE, &err_msg, 0}, |
| 517 | {YANG_EXTENSION, &ext_def, 0}, |
| 518 | {YANG_IF_FEATURE, &if_features, 0}, |
| 519 | {YANG_LENGTH, &len_type, 0}, |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 520 | {YANG_PATTERN, &patter_type, 0}, |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 521 | {YANG_POSITION, &pos_enum, 0}, |
David Sedlák | 438ae43 | 2019-07-11 15:36:54 +0200 | [diff] [blame] | 522 | {YANG_RANGE, &range_type, 0}, |
| 523 | {YANG_REQUIRE_INSTANCE, &req_type, 0}, |
| 524 | {YANG_UNITS, &units, 0}, |
| 525 | {YANG_VALUE, &val_enum, 0}, |
| 526 | {YANG_WHEN, &when_p, 0}, |
| 527 | {YANG_CUSTOM, NULL, 0}, |
| 528 | {YIN_TEXT, &value, 0} |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 529 | }; |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 530 | ret = yin_parse_content(st->yin_ctx, subelems, 17, &data, YANG_PREFIX, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 531 | assert_int_equal(ret, LY_SUCCESS); |
David Sedlák | 1fdb252 | 2019-07-09 16:22:57 +0200 | [diff] [blame] | 532 | assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END); |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 533 | /* check parsed values */ |
David Sedlák | e7084ce | 2019-07-10 16:44:15 +0200 | [diff] [blame] | 534 | assert_string_equal(def, "default-value"); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 535 | assert_string_equal(exts->name, "custom"); |
| 536 | assert_string_equal(exts->argument, "totally amazing extension"); |
| 537 | assert_string_equal(value, "wsefsdf"); |
David Sedlák | a5b1d38 | 2019-07-10 16:31:09 +0200 | [diff] [blame] | 538 | assert_string_equal(units, "radians"); |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 539 | assert_string_equal(when_p->cond, "condition..."); |
| 540 | assert_string_equal(when_p->dsc, "when_desc"); |
| 541 | assert_string_equal(when_p->ref, "when_ref"); |
David Sedlák | e1a3030 | 2019-07-10 13:49:38 +0200 | [diff] [blame] | 542 | assert_int_equal(config, LYS_CONFIG_W); |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 543 | assert_int_equal(pos_enum.value, 25); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 544 | assert_true(pos_enum.flags & LYS_SET_VALUE); |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 545 | assert_int_equal(val_enum.value, -5); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 546 | assert_true(val_enum.flags & LYS_SET_VALUE); |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 547 | assert_int_equal(req_type.require_instance, 1); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 548 | assert_true(req_type.flags &= LYS_SET_REQINST); |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 549 | assert_string_equal(range_type.range->arg, "5..10"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 550 | assert_true(range_type.flags & LYS_SET_RANGE); |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 551 | assert_string_equal(err_msg, "error-msg"); |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 552 | assert_string_equal(app_tag, "err-app-tag"); |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 553 | assert_string_equal(enum_type.enums->name, "yay"); |
David Sedlák | 438ae43 | 2019-07-11 15:36:54 +0200 | [diff] [blame] | 554 | assert_string_equal(len_type.length->arg, "baf"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 555 | assert_true(len_type.flags & LYS_SET_LENGTH); |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 556 | assert_string_equal(patter_type.patterns->arg, "\x015pattern"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 557 | assert_true(patter_type.flags & LYS_SET_PATTERN); |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 558 | /* cleanup */ |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 559 | lysp_ext_instance_free(st->ctx, exts); |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 560 | lysp_when_free(st->ctx, when_p); |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 561 | lysp_ext_free(st->ctx, ext_def); |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 562 | FREE_STRING(st->ctx, *if_features); |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 563 | FREE_STRING(st->ctx, err_msg); |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 564 | FREE_STRING(st->ctx, app_tag); |
David Sedlák | a5b1d38 | 2019-07-10 16:31:09 +0200 | [diff] [blame] | 565 | FREE_STRING(st->ctx, units); |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 566 | FREE_STRING(st->ctx, patter_type.patterns->arg); |
David Sedlák | e7084ce | 2019-07-10 16:44:15 +0200 | [diff] [blame] | 567 | FREE_STRING(st->ctx, def); |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 568 | FREE_STRING(st->ctx, range_type.range->arg); |
David Sedlák | 438ae43 | 2019-07-11 15:36:54 +0200 | [diff] [blame] | 569 | FREE_STRING(st->ctx, len_type.length->arg); |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 570 | FREE_STRING(st->ctx, enum_type.enums->name); |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 571 | FREE_STRING(st->ctx, value); |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 572 | LY_ARRAY_FREE(if_features); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 573 | LY_ARRAY_FREE(exts); |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 574 | LY_ARRAY_FREE(ext_def); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 575 | LY_ARRAY_FREE(attrs); |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 576 | LY_ARRAY_FREE(patter_type.patterns); |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 577 | LY_ARRAY_FREE(enum_type.enums); |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 578 | free(when_p); |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 579 | free(range_type.range); |
David Sedlák | 438ae43 | 2019-07-11 15:36:54 +0200 | [diff] [blame] | 580 | free(len_type.length); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 581 | attrs = NULL; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 582 | st = reset_state(state); |
| 583 | |
| 584 | /* test unique subelem */ |
| 585 | const char *prefix_value; |
| 586 | struct yin_subelement subelems2[2] = {{YANG_PREFIX, &prefix_value, 0}, |
| 587 | {YIN_TEXT, &value, YIN_SUBELEM_UNIQUE}}; |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 588 | data = ELEMENT_WRAPPER_START |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 589 | "<prefix value=\"inv_mod\" />" |
| 590 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
| 591 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 592 | ELEMENT_WRAPPER_END; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame^] | 593 | lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len); |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 594 | yin_load_attributes(st->yin_ctx, &data, &attrs); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 595 | ret = yin_parse_content(st->yin_ctx, subelems2, 2, &data, YANG_STATUS, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 596 | assert_int_equal(ret, LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 597 | logbuf_assert("Redefinition of \"text\" sub-element in \"status\" element. Line number 1."); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 598 | lydict_remove(st->ctx, prefix_value); |
| 599 | lydict_remove(st->ctx, value); |
| 600 | st = reset_state(state); |
| 601 | LY_ARRAY_FREE(attrs); |
| 602 | attrs = NULL; |
| 603 | |
| 604 | /* test first subelem */ |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 605 | data = ELEMENT_WRAPPER_START |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 606 | "<prefix value=\"inv_mod\" />" |
| 607 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
| 608 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 609 | ELEMENT_WRAPPER_END; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 610 | struct yin_subelement subelems3[2] = {{YANG_PREFIX, &prefix_value, 0}, |
| 611 | {YIN_TEXT, &value, YIN_SUBELEM_FIRST}}; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame^] | 612 | lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len); |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 613 | yin_load_attributes(st->yin_ctx, &data, &attrs); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 614 | ret = yin_parse_content(st->yin_ctx, subelems3, 2, &data, YANG_STATUS, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 615 | assert_int_equal(ret, LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 616 | logbuf_assert("Sub-element \"text\" of \"status\" element must be defined as it's first sub-element. Line number 1."); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 617 | lydict_remove(st->ctx, prefix_value); |
| 618 | st = reset_state(state); |
| 619 | LY_ARRAY_FREE(attrs); |
| 620 | attrs = NULL; |
| 621 | |
| 622 | /* test mandatory subelem */ |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 623 | data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 624 | struct yin_subelement subelems4[1] = {{YANG_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY}}; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame^] | 625 | lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len); |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 626 | yin_load_attributes(st->yin_ctx, &data, &attrs); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 627 | ret = yin_parse_content(st->yin_ctx, subelems4, 1, &data, YANG_STATUS, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 628 | assert_int_equal(ret, LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 629 | logbuf_assert("Missing mandatory sub-element \"prefix\" of \"status\" element. Line number 1."); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 630 | LY_ARRAY_FREE(attrs); |
| 631 | |
| 632 | st->finished_correctly = true; |
| 633 | } |
| 634 | |
David Sedlák | 92147b0 | 2019-07-09 14:01:01 +0200 | [diff] [blame] | 635 | static void |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 636 | test_validate_value(void **state) |
| 637 | { |
| 638 | struct state *st = *state; |
| 639 | assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG, "#invalid", 8), LY_EVALID); |
| 640 | logbuf_assert("Invalid identifier character '#'. Line number 1."); |
| 641 | assert_int_equal(yin_validate_value(st->yin_ctx, Y_STR_ARG, "", 0), LY_SUCCESS); |
| 642 | assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG, "pre:b", 5), LY_EVALID); |
| 643 | assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG, "pre:b", 5), LY_SUCCESS); |
| 644 | assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG, "pre:pre:b", 9), LY_EVALID); |
| 645 | |
| 646 | st->finished_correctly = true; |
| 647 | } |
| 648 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 649 | /* helper function to simplify unit test of each element using parse_content function */ |
| 650 | LY_ERR |
| 651 | test_element_helper(struct state *st, const char **data, void *dest, const char **text, |
| 652 | struct lysp_ext_instance **exts, bool valid) |
| 653 | { |
| 654 | struct yin_arg_record *attrs = NULL; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame^] | 655 | const char *name, *prefix; |
| 656 | size_t name_len, prefix_len; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 657 | LY_ERR ret = LY_SUCCESS; |
| 658 | struct yin_subelement subelems[71] = { |
| 659 | {YANG_ACTION, dest, 0}, |
| 660 | {YANG_ANYDATA, dest, 0}, |
| 661 | {YANG_ANYXML, dest, 0}, |
| 662 | {YANG_ARGUMENT,dest, 0}, |
| 663 | {YANG_AUGMENT, dest, 0}, |
| 664 | {YANG_BASE, dest, 0}, |
| 665 | {YANG_BELONGS_TO, dest, 0}, |
| 666 | {YANG_BIT, dest, 0}, |
| 667 | {YANG_CASE, dest, 0}, |
| 668 | {YANG_CHOICE, dest, 0}, |
| 669 | {YANG_CONFIG, dest, 0}, |
| 670 | {YANG_CONTACT, dest, 0}, |
| 671 | {YANG_CONTAINER, dest, 0}, |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 672 | {YANG_DEFAULT, dest, YIN_SUBELEM_UNIQUE}, |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 673 | {YANG_DESCRIPTION, dest, 0}, |
| 674 | {YANG_DEVIATE, dest, 0}, |
| 675 | {YANG_DEVIATION, dest, 0}, |
| 676 | {YANG_ENUM, dest, 0}, |
| 677 | {YANG_ERROR_APP_TAG, dest, 0}, |
| 678 | {YANG_ERROR_MESSAGE, dest, 0}, |
| 679 | {YANG_EXTENSION, dest, 0}, |
| 680 | {YANG_FEATURE, dest, 0}, |
| 681 | {YANG_FRACTION_DIGITS, dest, 0}, |
| 682 | {YANG_GROUPING, dest, 0}, |
| 683 | {YANG_IDENTITY, dest, 0}, |
| 684 | {YANG_IF_FEATURE, dest, 0}, |
| 685 | {YANG_IMPORT, dest, 0}, |
| 686 | {YANG_INCLUDE, dest, 0}, |
| 687 | {YANG_INPUT, dest, 0}, |
| 688 | {YANG_KEY, dest, 0}, |
| 689 | {YANG_LEAF, dest, 0}, |
| 690 | {YANG_LEAF_LIST, dest, 0}, |
| 691 | {YANG_LENGTH, dest, 0}, |
| 692 | {YANG_LIST, dest, 0}, |
| 693 | {YANG_MANDATORY, dest, 0}, |
| 694 | {YANG_MAX_ELEMENTS, dest, 0}, |
| 695 | {YANG_MIN_ELEMENTS, dest, 0}, |
| 696 | {YANG_MODIFIER, dest, 0}, |
| 697 | {YANG_MODULE, dest, 0}, |
| 698 | {YANG_MUST, dest, 0}, |
| 699 | {YANG_NAMESPACE, dest, 0}, |
| 700 | {YANG_NOTIFICATION, dest, 0}, |
| 701 | {YANG_ORDERED_BY, dest, 0}, |
| 702 | {YANG_ORGANIZATION, dest, 0}, |
| 703 | {YANG_OUTPUT, dest, 0}, |
| 704 | {YANG_PATH, dest, 0}, |
| 705 | {YANG_PATTERN, dest, 0}, |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 706 | {YANG_POSITION, dest, 0}, |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 707 | {YANG_PREFIX, dest, 0}, |
| 708 | {YANG_PRESENCE, dest, 0}, |
| 709 | {YANG_RANGE, dest, 0}, |
| 710 | {YANG_REFERENCE, dest, 0}, |
| 711 | {YANG_REFINE, dest, 0}, |
| 712 | {YANG_REQUIRE_INSTANCE, dest, 0}, |
| 713 | {YANG_REVISION, dest, 0}, |
| 714 | {YANG_REVISION_DATE, dest, 0}, |
| 715 | {YANG_RPC, dest, 0}, |
| 716 | {YANG_STATUS, dest, 0}, |
| 717 | {YANG_SUBMODULE, dest, 0}, |
| 718 | {YANG_TYPE, dest, 0}, |
| 719 | {YANG_TYPEDEF, dest, 0}, |
| 720 | {YANG_UNIQUE, dest, 0}, |
| 721 | {YANG_UNITS, dest, 0}, |
| 722 | {YANG_USES, dest, 0}, |
| 723 | {YANG_VALUE, dest, 0}, |
| 724 | {YANG_WHEN, dest, 0}, |
| 725 | {YANG_YANG_VERSION, dest, 0}, |
| 726 | {YANG_YIN_ELEMENT, dest, 0}, |
| 727 | {YANG_CUSTOM, dest, 0}, |
| 728 | {YIN_TEXT, dest, 0}, |
| 729 | {YIN_VALUE, dest, 0} |
| 730 | }; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame^] | 731 | LY_CHECK_RET(lyxml_get_element(&st->yin_ctx->xml_ctx, data, &prefix, &prefix_len, &name, &name_len)); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 732 | LY_CHECK_RET(yin_load_attributes(st->yin_ctx, data, &attrs)); |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame^] | 733 | ret = yin_parse_content(st->yin_ctx, subelems, 71, data, yin_match_keyword(st->yin_ctx, name, name_len, prefix, prefix_len, YANG_NONE), text, exts); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 734 | LY_ARRAY_FREE(attrs); |
| 735 | if (valid) { |
| 736 | assert_int_equal(st->yin_ctx->xml_ctx.status, LYXML_END); |
| 737 | } |
| 738 | /* reset status */ |
| 739 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 740 | return ret; |
| 741 | } |
| 742 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 743 | #define EXT_SUBELEM "<myext:c-define name=\"MY_MTU\" xmlns:myext=\"urn:example:extensions\"/>" |
| 744 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 745 | static void |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 746 | test_enum_elem(void **state) |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 747 | { |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 748 | struct state *st = *state; |
| 749 | struct lysp_type type = {}; |
| 750 | const char *data; |
| 751 | data = ELEMENT_WRAPPER_START |
| 752 | "<enum name=\"enum-name\">" |
| 753 | "<if-feature name=\"feature\" />" |
| 754 | "<value value=\"55\" />" |
| 755 | "<status value=\"deprecated\" />" |
| 756 | "<description><text>desc...</text></description>" |
| 757 | "<reference><text>ref...</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 758 | EXT_SUBELEM |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 759 | "</enum>" |
| 760 | ELEMENT_WRAPPER_END; |
| 761 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 762 | assert_string_equal(type.enums->name, "enum-name"); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 763 | assert_string_equal(*type.enums->iffeatures, "feature"); |
| 764 | assert_int_equal(type.enums->value, 55); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 765 | assert_true((type.enums->flags & LYS_STATUS_DEPRC) && (type.enums->flags & LYS_SET_VALUE)); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 766 | assert_string_equal(type.enums->dsc, "desc..."); |
| 767 | assert_string_equal(type.enums->ref, "ref..."); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 768 | assert_string_equal(type.enums->exts->name, "myext:c-define"); |
| 769 | assert_int_equal(type.enums->exts->insubstmt_index, 0); |
| 770 | assert_int_equal(type.enums->exts->insubstmt, LYEXT_SUBSTMT_SELF); |
| 771 | lysp_type_free(st->ctx, &type); |
| 772 | memset(&type, 0, sizeof type); |
| 773 | |
| 774 | data = ELEMENT_WRAPPER_START |
| 775 | "<enum name=\"enum-name\"></enum>" |
| 776 | ELEMENT_WRAPPER_END; |
| 777 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 778 | assert_string_equal(type.enums->name, "enum-name"); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 779 | lysp_type_free(st->ctx, &type); |
| 780 | memset(&type, 0, sizeof type); |
| 781 | |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 782 | st->finished_correctly = true; |
| 783 | } |
| 784 | |
| 785 | static void |
| 786 | test_bit_elem(void **state) |
| 787 | { |
| 788 | struct state *st = *state; |
| 789 | struct lysp_type type = {}; |
| 790 | const char *data; |
| 791 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 792 | "<bit name=\"bit-name\">" |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 793 | "<if-feature name=\"feature\" />" |
| 794 | "<position value=\"55\" />" |
| 795 | "<status value=\"deprecated\" />" |
| 796 | "<description><text>desc...</text></description>" |
| 797 | "<reference><text>ref...</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 798 | EXT_SUBELEM |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 799 | "</bit>" |
| 800 | ELEMENT_WRAPPER_END; |
| 801 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 802 | assert_string_equal(type.bits->name, "bit-name"); |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 803 | assert_string_equal(*type.bits->iffeatures, "feature"); |
| 804 | assert_int_equal(type.bits->value, 55); |
| 805 | assert_true((type.bits->flags & LYS_STATUS_DEPRC) && (type.bits->flags & LYS_SET_VALUE)); |
| 806 | assert_string_equal(type.bits->dsc, "desc..."); |
| 807 | assert_string_equal(type.bits->ref, "ref..."); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 808 | assert_string_equal(type.bits->exts->name, "myext:c-define"); |
| 809 | assert_int_equal(type.bits->exts->insubstmt_index, 0); |
| 810 | assert_int_equal(type.bits->exts->insubstmt, LYEXT_SUBSTMT_SELF); |
| 811 | lysp_type_free(st->ctx, &type); |
| 812 | memset(&type, 0, sizeof type); |
| 813 | |
| 814 | data = ELEMENT_WRAPPER_START |
| 815 | "<bit name=\"bit-name\"> </bit>" |
| 816 | ELEMENT_WRAPPER_END; |
| 817 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 818 | assert_string_equal(type.bits->name, "bit-name"); |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 819 | lysp_type_free(st->ctx, &type); |
| 820 | memset(&type, 0, sizeof type); |
| 821 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 822 | st->finished_correctly = true; |
| 823 | } |
| 824 | |
| 825 | static void |
| 826 | test_meta_elem(void **state) |
| 827 | { |
| 828 | struct state *st = *state; |
| 829 | char *value = NULL; |
| 830 | const char *data; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 831 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 832 | |
| 833 | /* organization element */ |
| 834 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 835 | "<organization><text>organization...</text>" EXT_SUBELEM EXT_SUBELEM "</organization>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 836 | ELEMENT_WRAPPER_END; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 837 | assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, true), LY_SUCCESS); |
| 838 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 839 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 840 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORGANIZATION); |
| 841 | assert_string_equal(exts[1].name, "myext:c-define"); |
| 842 | assert_int_equal(exts[1].insubstmt_index, 0); |
| 843 | assert_int_equal(exts[1].insubstmt, LYEXT_SUBSTMT_ORGANIZATION); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 844 | assert_string_equal(value, "organization..."); |
| 845 | FREE_STRING(st->ctx, value); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 846 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 847 | value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 848 | exts = NULL; |
| 849 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 850 | /* contact element */ |
| 851 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 852 | "<contact><text>contact...</text>" EXT_SUBELEM "</contact>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 853 | ELEMENT_WRAPPER_END; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 854 | assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, true), LY_SUCCESS); |
| 855 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 856 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 857 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONTACT); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 858 | assert_string_equal(value, "contact..."); |
| 859 | FREE_STRING(st->ctx, value); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 860 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 861 | exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 862 | value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 863 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 864 | /* description element */ |
| 865 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 866 | "<description><text>description...</text>" EXT_SUBELEM "</description>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 867 | ELEMENT_WRAPPER_END; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 868 | assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 869 | assert_string_equal(value, "description..."); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 870 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 871 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 872 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DESCRIPTION); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 873 | FREE_STRING(st->ctx, value); |
| 874 | value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 875 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 876 | exts = NULL; |
| 877 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 878 | /* reference element */ |
| 879 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 880 | "<reference><text>reference...</text>" EXT_SUBELEM "</reference>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 881 | ELEMENT_WRAPPER_END; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 882 | assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 883 | assert_string_equal(value, "reference..."); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 884 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 885 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 886 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REFERENCE); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 887 | FREE_STRING(st->ctx, value); |
| 888 | value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 889 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 890 | exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 891 | |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 892 | /* reference element */ |
| 893 | data = ELEMENT_WRAPPER_START |
| 894 | "<reference invalid=\"text\"><text>reference...</text>""</reference>" |
| 895 | ELEMENT_WRAPPER_END; |
| 896 | assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 897 | logbuf_assert("Unexpected attribute \"invalid\" of \"reference\" element. Line number 1."); |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 898 | FREE_STRING(st->ctx, value); |
| 899 | value = NULL; |
| 900 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 901 | exts = NULL; |
| 902 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 903 | /* missing text subelement */ |
| 904 | data = ELEMENT_WRAPPER_START |
| 905 | "<reference>reference...</reference>" |
| 906 | ELEMENT_WRAPPER_END; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 907 | assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 908 | logbuf_assert("Missing mandatory sub-element \"text\" of \"reference\" element. Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 909 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 910 | /* reference element */ |
| 911 | data = ELEMENT_WRAPPER_START |
| 912 | "<reference>" EXT_SUBELEM "<text>reference...</text></reference>" |
| 913 | ELEMENT_WRAPPER_END; |
| 914 | assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 915 | logbuf_assert("Sub-element \"text\" of \"reference\" element must be defined as it's first sub-element. Line number 1."); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 916 | FREE_STRING(st->ctx, value); |
| 917 | value = NULL; |
| 918 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 919 | exts = NULL; |
| 920 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 921 | st->finished_correctly = true; |
| 922 | } |
| 923 | |
| 924 | static void |
| 925 | test_import_elem(void **state) |
| 926 | { |
| 927 | struct state *st = *state; |
| 928 | const char *data; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 929 | struct lysp_import *imports = NULL; |
| 930 | struct import_meta imp_meta = {"prefix", &imports}; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 931 | |
| 932 | /* max subelems */ |
| 933 | data = ELEMENT_WRAPPER_START |
| 934 | "<import module=\"a\">" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 935 | EXT_SUBELEM |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 936 | "<prefix value=\"a_mod\"/>" |
| 937 | "<revision-date date=\"2015-01-01\"></revision-date>" |
| 938 | "<description><text>import description</text></description>" |
| 939 | "<reference><text>import reference</text></reference>" |
| 940 | "</import>" |
| 941 | ELEMENT_WRAPPER_END; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 942 | assert_int_equal(test_element_helper(st, &data, &imp_meta, NULL, NULL, true), LY_SUCCESS); |
| 943 | assert_string_equal(imports->name, "a"); |
| 944 | assert_string_equal(imports->prefix, "a_mod"); |
| 945 | assert_string_equal(imports->rev, "2015-01-01"); |
| 946 | assert_string_equal(imports->dsc, "import description"); |
| 947 | assert_string_equal(imports->ref, "import reference"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 948 | assert_string_equal(imports->exts->name, "myext:c-define"); |
| 949 | assert_int_equal(imports->exts->insubstmt, LYEXT_SUBSTMT_SELF); |
| 950 | assert_int_equal(imports->exts->insubstmt_index, 0); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 951 | FREE_ARRAY(st->ctx, imports, lysp_import_free); |
| 952 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 953 | |
| 954 | /* min subelems */ |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 955 | data = ELEMENT_WRAPPER_START |
| 956 | "<import module=\"a\">" |
| 957 | "<prefix value=\"a_mod\"/>" |
| 958 | "</import>" |
| 959 | ELEMENT_WRAPPER_END; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 960 | assert_int_equal(test_element_helper(st, &data, &imp_meta, NULL, NULL, true), LY_SUCCESS); |
| 961 | assert_string_equal(imports->prefix, "a_mod"); |
| 962 | FREE_ARRAY(st->ctx, imports, lysp_import_free); |
| 963 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 964 | |
| 965 | /* invalid (missing prefix) */ |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 966 | data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END; |
| 967 | assert_int_equal(test_element_helper(st, &data, &imp_meta, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 968 | logbuf_assert("Missing mandatory sub-element \"prefix\" of \"import\" element. Line number 1."); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 969 | FREE_ARRAY(st->ctx, imports, lysp_import_free); |
| 970 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 971 | |
| 972 | /* invalid reused prefix */ |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 973 | data = ELEMENT_WRAPPER_START |
| 974 | "<import module=\"a\">" |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 975 | "<prefix value=\"prefix\"/>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 976 | "</import>" |
| 977 | "<import module=\"a\">" |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 978 | "<prefix value=\"prefix\"/>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 979 | "</import>" |
| 980 | ELEMENT_WRAPPER_END; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 981 | assert_int_equal(test_element_helper(st, &data, &imp_meta, NULL, NULL, false), LY_EVALID); |
| 982 | logbuf_assert("Prefix \"prefix\" already used as module prefix. Line number 1."); |
| 983 | FREE_ARRAY(st->ctx, imports, lysp_import_free); |
| 984 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 985 | |
| 986 | st->finished_correctly = true; |
| 987 | } |
| 988 | |
| 989 | static void |
| 990 | test_status_elem(void **state) |
| 991 | { |
| 992 | struct state *st = *state; |
| 993 | const char *data; |
| 994 | uint16_t flags = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 995 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 996 | |
| 997 | /* test valid values */ |
| 998 | data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END; |
| 999 | assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1000 | assert_true(flags & LYS_STATUS_CURR); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1001 | |
| 1002 | data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END; |
| 1003 | assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1004 | assert_true(flags & LYS_STATUS_DEPRC); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1005 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1006 | data = ELEMENT_WRAPPER_START "<status value=\"obsolete\">"EXT_SUBELEM"</status>" ELEMENT_WRAPPER_END; |
| 1007 | assert_int_equal(test_element_helper(st, &data, &flags, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1008 | assert_true(flags & LYS_STATUS_OBSLT); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1009 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1010 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1011 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_STATUS); |
| 1012 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1013 | exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1014 | |
| 1015 | /* test invalid value */ |
| 1016 | data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END; |
| 1017 | assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1018 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"status\" element. Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1019 | st->finished_correctly = true; |
| 1020 | } |
| 1021 | |
| 1022 | static void |
| 1023 | test_ext_elem(void **state) |
| 1024 | { |
| 1025 | struct state *st = *state; |
| 1026 | const char *data; |
| 1027 | struct lysp_ext *ext = NULL; |
| 1028 | |
| 1029 | /* max subelems */ |
| 1030 | data = ELEMENT_WRAPPER_START |
| 1031 | "<extension name=\"ext_name\">" |
| 1032 | "<argument name=\"arg\"></argument>" |
| 1033 | "<status value=\"current\"/>" |
| 1034 | "<description><text>ext_desc</text></description>" |
| 1035 | "<reference><text>ext_ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1036 | EXT_SUBELEM |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1037 | "</extension>" |
| 1038 | ELEMENT_WRAPPER_END; |
| 1039 | assert_int_equal(test_element_helper(st, &data, &ext, NULL, NULL, true), LY_SUCCESS); |
| 1040 | assert_string_equal(ext->name, "ext_name"); |
| 1041 | assert_string_equal(ext->argument, "arg"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1042 | assert_true(ext->flags & LYS_STATUS_CURR); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1043 | assert_string_equal(ext->dsc, "ext_desc"); |
| 1044 | assert_string_equal(ext->ref, "ext_ref"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1045 | assert_string_equal(ext->exts[0].name, "myext:c-define"); |
| 1046 | assert_int_equal(ext->exts[0].insubstmt_index, 0); |
| 1047 | assert_int_equal(ext->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1048 | lysp_ext_free(st->ctx, ext); |
| 1049 | LY_ARRAY_FREE(ext); |
| 1050 | ext = NULL; |
| 1051 | |
| 1052 | /* min subelems */ |
| 1053 | data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END; |
| 1054 | assert_int_equal(test_element_helper(st, &data, &ext, NULL, NULL, true), LY_SUCCESS); |
| 1055 | assert_string_equal(ext->name, "ext_name"); |
| 1056 | lysp_ext_free(st->ctx, ext); |
| 1057 | LY_ARRAY_FREE(ext); |
| 1058 | ext = NULL; |
| 1059 | |
| 1060 | st->finished_correctly = true; |
| 1061 | } |
| 1062 | |
| 1063 | static void |
| 1064 | test_yin_element_elem(void **state) |
| 1065 | { |
| 1066 | struct state *st = *state; |
| 1067 | const char *data; |
| 1068 | uint16_t flags = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1069 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1070 | |
| 1071 | data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END; |
| 1072 | assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1073 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1074 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1075 | data = ELEMENT_WRAPPER_START "<yin-element value=\"false\">" EXT_SUBELEM "</yin-element>" ELEMENT_WRAPPER_END; |
| 1076 | assert_int_equal(test_element_helper(st, &data, &flags, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1077 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1078 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1079 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1080 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_YINELEM); |
| 1081 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1082 | |
| 1083 | data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END; |
| 1084 | assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1085 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1086 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"yin-element\" element. Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1087 | st->finished_correctly = true; |
| 1088 | } |
| 1089 | |
| 1090 | static void |
| 1091 | test_yangversion_elem(void **state) |
| 1092 | { |
| 1093 | struct state *st = *state; |
| 1094 | const char *data; |
| 1095 | uint8_t version = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1096 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1097 | |
| 1098 | /* valid values */ |
| 1099 | data = ELEMENT_WRAPPER_START "<yang-version value=\"1.0\" />" ELEMENT_WRAPPER_END; |
| 1100 | assert_int_equal(test_element_helper(st, &data, &version, NULL, NULL, true), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1101 | assert_true(version & LYS_VERSION_1_0); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1102 | assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_0); |
| 1103 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1104 | data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\">" EXT_SUBELEM "</yang-version>" ELEMENT_WRAPPER_END; |
| 1105 | assert_int_equal(test_element_helper(st, &data, &version, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1106 | assert_true(version & LYS_VERSION_1_1); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1107 | assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_1); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1108 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1109 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1110 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_VERSION); |
| 1111 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1112 | |
| 1113 | /* invalid value */ |
| 1114 | data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END; |
| 1115 | assert_int_equal(test_element_helper(st, &data, &version, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1116 | logbuf_assert("Invalid value \"version\" of \"value\" attribute in \"yang-version\" element. Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1117 | |
| 1118 | st->finished_correctly = true; |
| 1119 | } |
| 1120 | |
| 1121 | static void |
| 1122 | test_mandatory_elem(void **state) |
| 1123 | { |
| 1124 | struct state *st = *state; |
| 1125 | const char *data; |
| 1126 | uint16_t man = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1127 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1128 | |
| 1129 | /* valid values */ |
| 1130 | data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END; |
| 1131 | assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, true), LY_SUCCESS); |
| 1132 | assert_int_equal(man, LYS_MAND_TRUE); |
| 1133 | man = 0; |
| 1134 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1135 | data = ELEMENT_WRAPPER_START "<mandatory value=\"false\">" EXT_SUBELEM "</mandatory>" ELEMENT_WRAPPER_END; |
| 1136 | assert_int_equal(test_element_helper(st, &data, &man, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1137 | assert_int_equal(man, LYS_MAND_FALSE); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1138 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1139 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1140 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MANDATORY); |
| 1141 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1142 | |
| 1143 | data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END; |
| 1144 | assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1145 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"mandatory\" element. Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1146 | |
| 1147 | st->finished_correctly = true; |
| 1148 | } |
| 1149 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1150 | static void |
| 1151 | test_argument_elem(void **state) |
| 1152 | { |
| 1153 | struct state *st = *state; |
| 1154 | const char *data; |
| 1155 | uint16_t flags = 0; |
| 1156 | const char *arg; |
| 1157 | struct yin_argument_meta arg_meta = {&flags, &arg}; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1158 | struct lysp_ext_instance *exts = NULL; |
| 1159 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1160 | /* max subelems */ |
| 1161 | data = ELEMENT_WRAPPER_START |
| 1162 | "<argument name=\"arg-name\">" |
| 1163 | "<yin-element value=\"true\" />" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1164 | EXT_SUBELEM |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1165 | "</argument>" |
| 1166 | ELEMENT_WRAPPER_END; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1167 | assert_int_equal(test_element_helper(st, &data, &arg_meta, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1168 | assert_string_equal(arg, "arg-name"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1169 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1170 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1171 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1172 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ARGUMENT); |
| 1173 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1174 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1175 | flags = 0; |
| 1176 | FREE_STRING(st->ctx, arg); |
| 1177 | arg = NULL; |
| 1178 | |
| 1179 | /* min subelems */ |
| 1180 | data = ELEMENT_WRAPPER_START |
| 1181 | "<argument name=\"arg\">" |
| 1182 | "</argument>" |
| 1183 | ELEMENT_WRAPPER_END; |
| 1184 | assert_int_equal(test_element_helper(st, &data, &arg_meta, NULL, NULL, true), LY_SUCCESS); |
| 1185 | assert_string_equal(arg, "arg"); |
| 1186 | assert_true(flags == 0); |
| 1187 | FREE_STRING(st->ctx, arg); |
| 1188 | |
| 1189 | st->finished_correctly = true; |
| 1190 | } |
| 1191 | |
| 1192 | static void |
| 1193 | test_base_elem(void **state) |
| 1194 | { |
| 1195 | struct state *st = *state; |
| 1196 | const char *data; |
| 1197 | const char **bases = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1198 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1199 | struct lysp_type type = {}; |
| 1200 | |
| 1201 | /* as identity subelement */ |
| 1202 | data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1203 | "<base name=\"base-name\">" |
| 1204 | EXT_SUBELEM |
| 1205 | "</base>" |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1206 | "</identity>"; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1207 | assert_int_equal(test_element_helper(st, &data, &bases, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1208 | assert_string_equal(*bases, "base-name"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1209 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1210 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1211 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE); |
| 1212 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1213 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1214 | FREE_STRING(st->ctx, *bases); |
| 1215 | LY_ARRAY_FREE(bases); |
| 1216 | |
| 1217 | /* as type subelement */ |
| 1218 | data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1219 | "<base name=\"base-name\">" |
| 1220 | EXT_SUBELEM |
| 1221 | "</base>" |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1222 | "</type>"; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1223 | assert_int_equal(test_element_helper(st, &data, &type, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1224 | assert_string_equal(*type.bases, "base-name"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1225 | assert_true(type.flags & LYS_SET_BASE); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1226 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1227 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1228 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE); |
| 1229 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1230 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1231 | FREE_STRING(st->ctx, *type.bases); |
| 1232 | LY_ARRAY_FREE(type.bases); |
| 1233 | |
| 1234 | st->finished_correctly = true; |
| 1235 | } |
| 1236 | |
| 1237 | static void |
| 1238 | test_belongsto_elem(void **state) |
| 1239 | { |
| 1240 | struct state *st = *state; |
| 1241 | const char *data; |
| 1242 | struct lysp_submodule submod; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1243 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1244 | |
| 1245 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1246 | "<belongs-to module=\"module-name\"><prefix value=\"pref\"/>"EXT_SUBELEM"</belongs-to>" |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1247 | ELEMENT_WRAPPER_END; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1248 | assert_int_equal(test_element_helper(st, &data, &submod, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1249 | assert_string_equal(submod.belongsto, "module-name"); |
| 1250 | assert_string_equal(submod.prefix, "pref"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1251 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1252 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1253 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BELONGSTO); |
| 1254 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1255 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1256 | FREE_STRING(st->ctx, submod.belongsto); |
| 1257 | FREE_STRING(st->ctx, submod.prefix); |
| 1258 | |
| 1259 | data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END; |
| 1260 | assert_int_equal(test_element_helper(st, &data, &submod, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1261 | logbuf_assert("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1262 | FREE_STRING(st->ctx, submod.belongsto); |
| 1263 | |
| 1264 | st->finished_correctly = true; |
| 1265 | } |
| 1266 | |
| 1267 | static void |
| 1268 | test_config_elem(void **state) |
| 1269 | { |
| 1270 | struct state *st = *state; |
| 1271 | const char *data; |
| 1272 | uint16_t flags = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1273 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1274 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1275 | data = ELEMENT_WRAPPER_START "<config value=\"true\">" EXT_SUBELEM "</config>" ELEMENT_WRAPPER_END; |
| 1276 | assert_int_equal(test_element_helper(st, &data, &flags, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1277 | assert_true(flags & LYS_CONFIG_W); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1278 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1279 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1280 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONFIG); |
| 1281 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1282 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1283 | flags = 0; |
| 1284 | |
| 1285 | data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END; |
| 1286 | assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1287 | assert_true(flags & LYS_CONFIG_R); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1288 | flags = 0; |
| 1289 | |
| 1290 | data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END; |
| 1291 | assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1292 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"config\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1293 | |
| 1294 | st->finished_correctly = true; |
| 1295 | } |
| 1296 | |
| 1297 | static void |
| 1298 | test_default_elem(void **state) |
| 1299 | { |
| 1300 | struct state *st = *state; |
| 1301 | const char *data; |
| 1302 | const char *val = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1303 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1304 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1305 | data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\">"EXT_SUBELEM"</default>" ELEMENT_WRAPPER_END; |
| 1306 | assert_int_equal(test_element_helper(st, &data, &val, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1307 | assert_string_equal(val, "defaul-value"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1308 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1309 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1310 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DEFAULT); |
| 1311 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1312 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1313 | FREE_STRING(st->ctx, val); |
| 1314 | val = NULL; |
| 1315 | |
| 1316 | data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END; |
| 1317 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID); |
| 1318 | logbuf_assert("Missing mandatory attribute value of default element. Line number 1."); |
| 1319 | |
| 1320 | st->finished_correctly = true; |
| 1321 | } |
| 1322 | |
| 1323 | static void |
| 1324 | test_err_app_tag_elem(void **state) |
| 1325 | { |
| 1326 | struct state *st = *state; |
| 1327 | const char *data; |
| 1328 | const char *val = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1329 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1330 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1331 | data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\">"EXT_SUBELEM"</error-app-tag>" ELEMENT_WRAPPER_END; |
| 1332 | assert_int_equal(test_element_helper(st, &data, &val, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1333 | assert_string_equal(val, "val"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1334 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1335 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1336 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRTAG); |
| 1337 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1338 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1339 | FREE_STRING(st->ctx, val); |
| 1340 | val = NULL; |
| 1341 | |
| 1342 | data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END; |
| 1343 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID); |
| 1344 | logbuf_assert("Missing mandatory attribute value of error-app-tag element. Line number 1."); |
| 1345 | |
| 1346 | st->finished_correctly = true; |
| 1347 | } |
| 1348 | |
| 1349 | static void |
| 1350 | test_err_msg_elem(void **state) |
| 1351 | { |
| 1352 | struct state *st = *state; |
| 1353 | const char *data; |
| 1354 | const char *val = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1355 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1356 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1357 | data = ELEMENT_WRAPPER_START "<error-message><value>val</value>"EXT_SUBELEM"</error-message>" ELEMENT_WRAPPER_END; |
| 1358 | assert_int_equal(test_element_helper(st, &data, &val, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1359 | assert_string_equal(val, "val"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1360 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1361 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1362 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRMSG); |
| 1363 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1364 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1365 | FREE_STRING(st->ctx, val); |
| 1366 | |
| 1367 | data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END; |
| 1368 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1369 | logbuf_assert("Missing mandatory sub-element \"value\" of \"error-message\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1370 | |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 1371 | data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END; |
| 1372 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1373 | logbuf_assert("Unexpected attribute \"invalid\" of \"error-message\" element. Line number 1."); |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 1374 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1375 | st->finished_correctly = true; |
| 1376 | } |
| 1377 | |
| 1378 | static void |
| 1379 | test_fracdigits_elem(void **state) |
| 1380 | { |
| 1381 | struct state *st = *state; |
| 1382 | const char *data; |
| 1383 | struct lysp_type type = {}; |
| 1384 | |
| 1385 | /* valid value */ |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1386 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\">"EXT_SUBELEM"</fraction-digits>" ELEMENT_WRAPPER_END; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1387 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1388 | assert_string_equal(type.exts[0].name, "myext:c-define"); |
| 1389 | assert_int_equal(type.exts[0].insubstmt_index, 0); |
| 1390 | assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_FRACDIGITS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1391 | assert_int_equal(type.fraction_digits, 10); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1392 | assert_true(type.flags & LYS_SET_FRDIGITS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1393 | FREE_ARRAY(st->ctx, type.exts, lysp_ext_instance_free); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1394 | |
| 1395 | /* invalid values */ |
| 1396 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END; |
| 1397 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1398 | logbuf_assert("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1399 | |
| 1400 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END; |
| 1401 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1402 | logbuf_assert("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1403 | |
| 1404 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END; |
| 1405 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1406 | logbuf_assert("Invalid value \"1p\" of \"value\" attribute in \"fraction-digits\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1407 | |
| 1408 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END; |
| 1409 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1410 | logbuf_assert("Invalid value \"19\" of \"value\" attribute in \"fraction-digits\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1411 | |
| 1412 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END; |
| 1413 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1414 | logbuf_assert("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1415 | |
| 1416 | st->finished_correctly = true; |
| 1417 | } |
| 1418 | |
| 1419 | static void |
| 1420 | test_iffeature_elem(void **state) |
| 1421 | { |
| 1422 | struct state *st = *state; |
| 1423 | const char *data; |
| 1424 | const char **iffeatures = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1425 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1426 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1427 | data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\">"EXT_SUBELEM"</if-feature>" ELEMENT_WRAPPER_END; |
| 1428 | assert_int_equal(test_element_helper(st, &data, &iffeatures, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1429 | assert_string_equal(*iffeatures, "local-storage"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1430 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1431 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1432 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_IFFEATURE); |
| 1433 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1434 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1435 | FREE_STRING(st->ctx, *iffeatures); |
| 1436 | LY_ARRAY_FREE(iffeatures); |
| 1437 | iffeatures = NULL; |
| 1438 | |
| 1439 | data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END; |
| 1440 | assert_int_equal(test_element_helper(st, &data, &iffeatures, NULL, NULL, false), LY_EVALID); |
| 1441 | logbuf_assert("Missing mandatory attribute name of if-feature element. Line number 1."); |
| 1442 | LY_ARRAY_FREE(iffeatures); |
| 1443 | iffeatures = NULL; |
| 1444 | |
| 1445 | st->finished_correctly = true; |
| 1446 | } |
| 1447 | |
| 1448 | static void |
| 1449 | test_length_elem(void **state) |
| 1450 | { |
| 1451 | struct state *st = *state; |
| 1452 | const char *data; |
| 1453 | struct lysp_type type = {}; |
| 1454 | |
| 1455 | /* max subelems */ |
| 1456 | data = ELEMENT_WRAPPER_START |
| 1457 | "<length value=\"length-str\">" |
| 1458 | "<error-message><value>err-msg</value></error-message>" |
| 1459 | "<error-app-tag value=\"err-app-tag\"/>" |
| 1460 | "<description><text>desc</text></description>" |
| 1461 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1462 | EXT_SUBELEM |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1463 | "</length>" |
| 1464 | ELEMENT_WRAPPER_END; |
| 1465 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1466 | assert_string_equal(type.length->arg, "length-str"); |
| 1467 | assert_string_equal(type.length->emsg, "err-msg"); |
| 1468 | assert_string_equal(type.length->eapptag, "err-app-tag"); |
| 1469 | assert_string_equal(type.length->dsc, "desc"); |
| 1470 | assert_string_equal(type.length->ref, "ref"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1471 | assert_true(type.flags & LYS_SET_LENGTH); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1472 | assert_string_equal(type.length->exts[0].name, "myext:c-define"); |
| 1473 | assert_int_equal(type.length->exts[0].insubstmt_index, 0); |
| 1474 | assert_int_equal(type.length->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1475 | lysp_type_free(st->ctx, &type); |
| 1476 | memset(&type, 0, sizeof(type)); |
| 1477 | |
| 1478 | /* min subelems */ |
| 1479 | data = ELEMENT_WRAPPER_START |
| 1480 | "<length value=\"length-str\">" |
| 1481 | "</length>" |
| 1482 | ELEMENT_WRAPPER_END; |
| 1483 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1484 | assert_string_equal(type.length->arg, "length-str"); |
| 1485 | lysp_type_free(st->ctx, &type); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1486 | assert_true(type.flags & LYS_SET_LENGTH); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1487 | memset(&type, 0, sizeof(type)); |
| 1488 | |
| 1489 | data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END; |
| 1490 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID); |
| 1491 | logbuf_assert("Missing mandatory attribute value of length element. Line number 1."); |
| 1492 | lysp_type_free(st->ctx, &type); |
| 1493 | memset(&type, 0, sizeof(type)); |
| 1494 | |
| 1495 | st->finished_correctly = true; |
| 1496 | } |
| 1497 | |
| 1498 | static void |
| 1499 | test_modifier_elem(void **state) |
| 1500 | { |
| 1501 | struct state *st = *state; |
| 1502 | const char *data; |
| 1503 | const char *pat = lydict_insert(st->ctx, "\006pattern", 8); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1504 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1505 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1506 | data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\">" EXT_SUBELEM "</modifier>" ELEMENT_WRAPPER_END; |
| 1507 | assert_int_equal(test_element_helper(st, &data, &pat, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1508 | assert_string_equal(pat, "\x015pattern"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1509 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1510 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1511 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MODIFIER); |
| 1512 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1513 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1514 | FREE_STRING(st->ctx, pat); |
| 1515 | |
| 1516 | pat = lydict_insert(st->ctx, "\006pattern", 8); |
| 1517 | data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END; |
| 1518 | assert_int_equal(test_element_helper(st, &data, &pat, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1519 | logbuf_assert("Invalid value \"invert\" of \"value\" attribute in \"modifier\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1520 | FREE_STRING(st->ctx, pat); |
| 1521 | |
| 1522 | st->finished_correctly = true; |
| 1523 | } |
| 1524 | |
| 1525 | static void |
| 1526 | test_namespace_elem(void **state) |
| 1527 | { |
| 1528 | struct state *st = *state; |
| 1529 | const char *data; |
| 1530 | const char *ns; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1531 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1532 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1533 | data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\">" EXT_SUBELEM "</namespace>" ELEMENT_WRAPPER_END; |
| 1534 | assert_int_equal(test_element_helper(st, &data, &ns, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1535 | assert_string_equal(ns, "ns"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1536 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1537 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1538 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_NAMESPACE); |
| 1539 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1540 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1541 | FREE_STRING(st->ctx, ns); |
| 1542 | |
| 1543 | data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END; |
| 1544 | assert_int_equal(test_element_helper(st, &data, &ns, NULL, NULL, false), LY_EVALID); |
| 1545 | logbuf_assert("Missing mandatory attribute uri of namespace element. Line number 1."); |
| 1546 | |
| 1547 | st->finished_correctly = true; |
| 1548 | } |
| 1549 | |
| 1550 | static void |
| 1551 | test_path_elem(void **state) |
| 1552 | { |
| 1553 | struct state *st = *state; |
| 1554 | const char *data; |
| 1555 | struct lysp_type type = {}; |
| 1556 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1557 | data = ELEMENT_WRAPPER_START "<path value=\"path-val\">" EXT_SUBELEM "</path>" ELEMENT_WRAPPER_END; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1558 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1559 | assert_string_equal("path-val", type.path); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1560 | assert_true(type.flags & LYS_SET_PATH); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1561 | assert_string_equal(type.exts[0].name, "myext:c-define"); |
| 1562 | assert_int_equal(type.exts[0].insubstmt_index, 0); |
| 1563 | assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_PATH); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1564 | lysp_type_free(st->ctx, &type); |
| 1565 | |
| 1566 | st->finished_correctly = true; |
| 1567 | } |
| 1568 | |
| 1569 | static void |
| 1570 | test_pattern_elem(void **state) |
| 1571 | { |
| 1572 | struct state *st = *state; |
| 1573 | const char *data; |
| 1574 | struct lysp_type type = {}; |
| 1575 | |
| 1576 | /* max subelems */ |
| 1577 | data = ELEMENT_WRAPPER_START |
| 1578 | "<pattern value=\"super_pattern\">" |
| 1579 | "<modifier value=\"invert-match\"/>" |
| 1580 | "<error-message><value>err-msg-value</value></error-message>" |
| 1581 | "<error-app-tag value=\"err-app-tag-value\"/>" |
| 1582 | "<description><text>pattern-desc</text></description>" |
| 1583 | "<reference><text>pattern-ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1584 | EXT_SUBELEM |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1585 | "</pattern>" |
| 1586 | ELEMENT_WRAPPER_END; |
| 1587 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1588 | assert_true(type.flags & LYS_SET_PATTERN); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1589 | assert_string_equal(type.patterns->arg, "\x015super_pattern"); |
| 1590 | assert_string_equal(type.patterns->dsc, "pattern-desc"); |
| 1591 | assert_string_equal(type.patterns->eapptag, "err-app-tag-value"); |
| 1592 | assert_string_equal(type.patterns->emsg, "err-msg-value"); |
| 1593 | assert_string_equal(type.patterns->dsc, "pattern-desc"); |
| 1594 | assert_string_equal(type.patterns->ref, "pattern-ref"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1595 | assert_string_equal(type.patterns->exts[0].name, "myext:c-define"); |
| 1596 | assert_int_equal(type.patterns->exts[0].insubstmt_index, 0); |
| 1597 | assert_int_equal(type.patterns->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1598 | lysp_type_free(st->ctx, &type); |
| 1599 | memset(&type, 0, sizeof(type)); |
| 1600 | |
| 1601 | /* min subelems */ |
| 1602 | data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END; |
| 1603 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1604 | assert_string_equal(type.patterns->arg, "\x006pattern"); |
| 1605 | lysp_type_free(st->ctx, &type); |
| 1606 | memset(&type, 0, sizeof(type)); |
| 1607 | |
| 1608 | st->finished_correctly = true; |
| 1609 | } |
| 1610 | |
| 1611 | static void |
| 1612 | test_value_position_elem(void **state) |
| 1613 | { |
| 1614 | struct state *st = *state; |
| 1615 | const char *data; |
| 1616 | struct lysp_type_enum en = {}; |
| 1617 | |
| 1618 | /* valid values */ |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1619 | data = ELEMENT_WRAPPER_START "<value value=\"55\">" EXT_SUBELEM "</value>" ELEMENT_WRAPPER_END; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1620 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS); |
| 1621 | assert_int_equal(en.value, 55); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1622 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1623 | assert_string_equal(en.exts[0].name, "myext:c-define"); |
| 1624 | assert_int_equal(en.exts[0].insubstmt_index, 0); |
| 1625 | assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_VALUE); |
| 1626 | FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1627 | memset(&en, 0, sizeof(en)); |
| 1628 | |
| 1629 | data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END; |
| 1630 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS); |
| 1631 | assert_int_equal(en.value, -55); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1632 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1633 | memset(&en, 0, sizeof(en)); |
| 1634 | |
| 1635 | data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END; |
| 1636 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS); |
| 1637 | assert_int_equal(en.value, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1638 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1639 | memset(&en, 0, sizeof(en)); |
| 1640 | |
| 1641 | data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END; |
| 1642 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS); |
| 1643 | assert_int_equal(en.value, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1644 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1645 | memset(&en, 0, sizeof(en)); |
| 1646 | |
| 1647 | /* valid positions */ |
David Sedlák | 8d552d6 | 2019-08-06 15:29:05 +0200 | [diff] [blame] | 1648 | data = ELEMENT_WRAPPER_START "<position value=\"55\">" EXT_SUBELEM "</position>" ELEMENT_WRAPPER_END; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1649 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS); |
| 1650 | assert_int_equal(en.value, 55); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1651 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8d552d6 | 2019-08-06 15:29:05 +0200 | [diff] [blame] | 1652 | assert_string_equal(en.exts[0].name, "myext:c-define"); |
| 1653 | assert_int_equal(en.exts[0].insubstmt_index, 0); |
| 1654 | assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_POSITION); |
| 1655 | FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1656 | memset(&en, 0, sizeof(en)); |
| 1657 | |
| 1658 | data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END; |
| 1659 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS); |
| 1660 | assert_int_equal(en.value, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1661 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1662 | memset(&en, 0, sizeof(en)); |
| 1663 | |
| 1664 | /* invalid values */ |
| 1665 | data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END; |
| 1666 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1667 | logbuf_assert("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1668 | |
| 1669 | data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END; |
| 1670 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1671 | logbuf_assert("Invalid value \"1k\" of \"value\" attribute in \"value\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1672 | |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1673 | data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END; |
| 1674 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1675 | logbuf_assert("Invalid value \"\" of \"value\" attribute in \"value\" element. Line number 1."); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1676 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1677 | /*invalid positions */ |
| 1678 | data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END; |
| 1679 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1680 | logbuf_assert("Invalid value \"-5\" of \"value\" attribute in \"position\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1681 | |
| 1682 | data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END; |
| 1683 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1684 | logbuf_assert("Invalid value \"-0\" of \"value\" attribute in \"position\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1685 | |
| 1686 | data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END; |
| 1687 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1688 | logbuf_assert("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1689 | |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1690 | data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END; |
| 1691 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1692 | logbuf_assert("Invalid value \"\" of \"value\" attribute in \"position\" element. Line number 1."); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1693 | |
| 1694 | st->finished_correctly = true; |
| 1695 | } |
| 1696 | |
| 1697 | static void |
| 1698 | test_prefix_elem(void **state) |
| 1699 | { |
| 1700 | struct state *st = *state; |
| 1701 | const char *data; |
| 1702 | const char *value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1703 | struct lysp_ext_instance *exts = NULL; |
| 1704 | |
| 1705 | data = ELEMENT_WRAPPER_START "<prefix value=\"pref\">" EXT_SUBELEM "</prefix>" ELEMENT_WRAPPER_END; |
| 1706 | assert_int_equal(test_element_helper(st, &data, &value, NULL, &exts, true), LY_SUCCESS); |
| 1707 | assert_string_equal(value, "pref"); |
| 1708 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1709 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1710 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PREFIX); |
| 1711 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1712 | exts = NULL; |
| 1713 | FREE_STRING(st->ctx, value); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1714 | |
| 1715 | data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END; |
| 1716 | assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS); |
| 1717 | assert_string_equal(value, "pref"); |
| 1718 | FREE_STRING(st->ctx, value); |
| 1719 | |
| 1720 | st->finished_correctly = true; |
| 1721 | } |
| 1722 | |
| 1723 | static void |
| 1724 | test_range_elem(void **state) |
| 1725 | { |
| 1726 | struct state *st = *state; |
| 1727 | const char *data; |
| 1728 | struct lysp_type type = {}; |
| 1729 | |
| 1730 | /* max subelems */ |
| 1731 | data = ELEMENT_WRAPPER_START |
| 1732 | "<range value=\"range-str\">" |
| 1733 | "<error-message><value>err-msg</value></error-message>" |
| 1734 | "<error-app-tag value=\"err-app-tag\" />" |
| 1735 | "<description><text>desc</text></description>" |
| 1736 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1737 | EXT_SUBELEM |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1738 | "</range>" |
| 1739 | ELEMENT_WRAPPER_END; |
| 1740 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1741 | assert_string_equal(type.range->arg, "range-str"); |
| 1742 | assert_string_equal(type.range->dsc, "desc"); |
| 1743 | assert_string_equal(type.range->eapptag, "err-app-tag"); |
| 1744 | assert_string_equal(type.range->emsg, "err-msg"); |
| 1745 | assert_string_equal(type.range->ref, "ref"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1746 | assert_true(type.flags & LYS_SET_RANGE); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1747 | assert_string_equal(type.range->exts[0].name, "myext:c-define"); |
| 1748 | assert_int_equal(type.range->exts[0].insubstmt_index, 0); |
| 1749 | assert_int_equal(type.range->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1750 | lysp_type_free(st->ctx, &type); |
| 1751 | memset(&type, 0, sizeof(type)); |
| 1752 | |
| 1753 | /* min subelems */ |
| 1754 | data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END; |
| 1755 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1756 | assert_string_equal(type.range->arg, "range-str"); |
| 1757 | lysp_type_free(st->ctx, &type); |
| 1758 | memset(&type, 0, sizeof(type)); |
| 1759 | |
| 1760 | st->finished_correctly = true; |
| 1761 | } |
| 1762 | |
| 1763 | static void |
| 1764 | test_reqinstance_elem(void **state) |
| 1765 | { |
| 1766 | struct state *st = *state; |
| 1767 | const char *data; |
| 1768 | struct lysp_type type = {}; |
| 1769 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1770 | data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1771 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1772 | assert_int_equal(type.require_instance, 1); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1773 | assert_true(type.flags & LYS_SET_REQINST); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1774 | assert_string_equal(type.exts[0].name, "myext:c-define"); |
| 1775 | assert_int_equal(type.exts[0].insubstmt_index, 0); |
| 1776 | assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_REQINSTANCE); |
| 1777 | lysp_type_free(st->ctx, &type); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1778 | memset(&type, 0, sizeof(type)); |
| 1779 | |
| 1780 | data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END; |
| 1781 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1782 | assert_int_equal(type.require_instance, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1783 | assert_true(type.flags & LYS_SET_REQINST); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1784 | memset(&type, 0, sizeof(type)); |
| 1785 | |
| 1786 | data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END; |
| 1787 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID); |
| 1788 | memset(&type, 0, sizeof(type)); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1789 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"require-instance\" element. Line number 1."); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1790 | |
| 1791 | st->finished_correctly = true; |
| 1792 | } |
| 1793 | |
| 1794 | static void |
| 1795 | test_revision_date_elem(void **state) |
| 1796 | { |
| 1797 | struct state *st = *state; |
| 1798 | const char *data; |
| 1799 | char rev[LY_REV_SIZE]; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1800 | struct lysp_ext_instance *exts = NULL; |
| 1801 | |
| 1802 | data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\">"EXT_SUBELEM"</revision-date>" ELEMENT_WRAPPER_END; |
| 1803 | assert_int_equal(test_element_helper(st, &data, rev, NULL, &exts, true), LY_SUCCESS); |
| 1804 | assert_string_equal(rev, "2000-01-01"); |
| 1805 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1806 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1807 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REVISIONDATE); |
| 1808 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1809 | |
| 1810 | data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END; |
| 1811 | assert_int_equal(test_element_helper(st, &data, rev, NULL, NULL, true), LY_SUCCESS); |
| 1812 | assert_string_equal(rev, "2000-01-01"); |
| 1813 | |
| 1814 | data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END; |
| 1815 | assert_int_equal(test_element_helper(st, &data, rev, NULL, NULL, false), LY_EVALID); |
| 1816 | logbuf_assert("Invalid value \"2000-50-05\" of \"revision-date\". Line number 1."); |
| 1817 | |
| 1818 | st->finished_correctly = true; |
| 1819 | } |
| 1820 | |
| 1821 | static void |
| 1822 | test_unique_elem(void **state) |
| 1823 | { |
| 1824 | struct state *st = *state; |
| 1825 | const char *data; |
| 1826 | const char **values = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1827 | struct lysp_ext_instance *exts = NULL; |
| 1828 | |
| 1829 | data = ELEMENT_WRAPPER_START "<unique tag=\"tag\">"EXT_SUBELEM"</unique>" ELEMENT_WRAPPER_END; |
| 1830 | assert_int_equal(test_element_helper(st, &data, &values, NULL, &exts, true), LY_SUCCESS); |
| 1831 | assert_string_equal(*values, "tag"); |
| 1832 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1833 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1834 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNIQUE); |
| 1835 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1836 | FREE_STRING(st->ctx, *values); |
| 1837 | LY_ARRAY_FREE(values); |
| 1838 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1839 | |
| 1840 | data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END; |
| 1841 | assert_int_equal(test_element_helper(st, &data, &values, NULL, NULL, true), LY_SUCCESS); |
| 1842 | assert_string_equal(*values, "tag"); |
| 1843 | FREE_STRING(st->ctx, *values); |
| 1844 | LY_ARRAY_FREE(values); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1845 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1846 | |
| 1847 | st->finished_correctly = true; |
| 1848 | } |
| 1849 | |
| 1850 | static void |
| 1851 | test_units_elem(void **state) |
| 1852 | { |
| 1853 | struct state *st = *state; |
| 1854 | const char *data; |
| 1855 | const char *values = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1856 | struct lysp_ext_instance *exts = NULL; |
| 1857 | |
| 1858 | data = ELEMENT_WRAPPER_START "<units name=\"name\">"EXT_SUBELEM"</units>" ELEMENT_WRAPPER_END; |
| 1859 | assert_int_equal(test_element_helper(st, &data, &values, NULL, &exts, true), LY_SUCCESS); |
| 1860 | assert_string_equal(values, "name"); |
| 1861 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 1862 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1863 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNITS); |
| 1864 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1865 | FREE_STRING(st->ctx, values); |
| 1866 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1867 | |
| 1868 | data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END; |
| 1869 | assert_int_equal(test_element_helper(st, &data, &values, NULL, NULL, true), LY_SUCCESS); |
| 1870 | assert_string_equal(values, "name"); |
| 1871 | FREE_STRING(st->ctx, values); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1872 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1873 | |
| 1874 | st->finished_correctly = true; |
| 1875 | } |
| 1876 | |
| 1877 | static void |
| 1878 | test_when_elem(void **state) |
| 1879 | { |
| 1880 | struct state *st = *state; |
| 1881 | const char *data; |
| 1882 | struct lysp_when *when = NULL; |
| 1883 | |
| 1884 | data = ELEMENT_WRAPPER_START |
| 1885 | "<when condition=\"cond\">" |
| 1886 | "<description><text>desc</text></description>" |
| 1887 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1888 | EXT_SUBELEM |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1889 | "</when>" |
| 1890 | ELEMENT_WRAPPER_END; |
| 1891 | assert_int_equal(test_element_helper(st, &data, &when, NULL, NULL, true), LY_SUCCESS); |
| 1892 | assert_string_equal(when->cond, "cond"); |
| 1893 | assert_string_equal(when->dsc, "desc"); |
| 1894 | assert_string_equal(when->ref, "ref"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1895 | assert_string_equal(when->exts[0].name, "myext:c-define"); |
| 1896 | assert_int_equal(when->exts[0].insubstmt_index, 0); |
| 1897 | assert_int_equal(when->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1898 | lysp_when_free(st->ctx, when); |
| 1899 | free(when); |
| 1900 | when = NULL; |
| 1901 | |
| 1902 | data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END; |
| 1903 | assert_int_equal(test_element_helper(st, &data, &when, NULL, NULL, true), LY_SUCCESS); |
| 1904 | assert_string_equal(when->cond, "cond"); |
| 1905 | lysp_when_free(st->ctx, when); |
| 1906 | free(when); |
| 1907 | when = NULL; |
| 1908 | |
| 1909 | st->finished_correctly = true; |
| 1910 | } |
| 1911 | |
| 1912 | static void |
| 1913 | test_yin_text_value_elem(void **state) |
| 1914 | { |
| 1915 | struct state *st = *state; |
| 1916 | const char *data; |
| 1917 | const char *val; |
| 1918 | |
| 1919 | data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END; |
| 1920 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS); |
| 1921 | assert_string_equal(val, "text"); |
| 1922 | FREE_STRING(st->ctx, val); |
| 1923 | |
| 1924 | data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>"; |
| 1925 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS); |
| 1926 | assert_string_equal(val, "text"); |
| 1927 | FREE_STRING(st->ctx, val); |
| 1928 | |
| 1929 | data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END; |
| 1930 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS); |
| 1931 | assert_string_equal("", val); |
| 1932 | FREE_STRING(st->ctx, val); |
| 1933 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1934 | st->finished_correctly = true; |
| 1935 | } |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1936 | |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1937 | static void |
| 1938 | test_type_elem(void **state) |
| 1939 | { |
| 1940 | struct state *st = *state; |
| 1941 | const char *data; |
| 1942 | struct lysp_type type = {}; |
| 1943 | |
| 1944 | /* max subelems */ |
| 1945 | data = ELEMENT_WRAPPER_START |
| 1946 | "<type name=\"type-name\">" |
| 1947 | "<base name=\"base-name\"/>" |
| 1948 | "<bit name=\"bit\"/>" |
| 1949 | "<enum name=\"enum\"/>" |
| 1950 | "<fraction-digits value=\"2\"/>" |
| 1951 | "<length value=\"length\"/>" |
| 1952 | "<path value=\"path\"/>" |
| 1953 | "<pattern value=\"pattern\"/>" |
| 1954 | "<range value=\"range\" />" |
| 1955 | "<require-instance value=\"true\"/>" |
| 1956 | "<type name=\"sub-type-name\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1957 | EXT_SUBELEM |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1958 | "</type>" |
| 1959 | ELEMENT_WRAPPER_END; |
| 1960 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1961 | assert_string_equal(type.name, "type-name"); |
| 1962 | assert_string_equal(*type.bases, "base-name"); |
| 1963 | assert_string_equal(type.bits->name, "bit"); |
| 1964 | assert_string_equal(type.enums->name, "enum"); |
| 1965 | assert_int_equal(type.fraction_digits, 2); |
| 1966 | assert_string_equal(type.length->arg, "length"); |
| 1967 | assert_string_equal(type.path, "path"); |
| 1968 | assert_string_equal(type.patterns->arg, "\006pattern"); |
| 1969 | assert_string_equal(type.range->arg, "range"); |
| 1970 | assert_int_equal(type.require_instance, 1); |
| 1971 | assert_string_equal(type.types->name, "sub-type-name"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1972 | assert_string_equal(type.exts[0].name, "myext:c-define"); |
| 1973 | assert_int_equal(type.exts[0].insubstmt_index, 0); |
| 1974 | assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1975 | assert_true(type.flags & LYS_SET_BASE); |
| 1976 | assert_true(type.flags & LYS_SET_BIT); |
| 1977 | assert_true(type.flags & LYS_SET_ENUM); |
| 1978 | assert_true(type.flags & LYS_SET_FRDIGITS); |
| 1979 | assert_true(type.flags & LYS_SET_LENGTH); |
| 1980 | assert_true(type.flags & LYS_SET_PATH); |
| 1981 | assert_true(type.flags & LYS_SET_PATTERN); |
| 1982 | assert_true(type.flags & LYS_SET_RANGE); |
| 1983 | assert_true(type.flags & LYS_SET_REQINST); |
| 1984 | assert_true(type.flags & LYS_SET_TYPE); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1985 | lysp_type_free(st->ctx, &type); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1986 | memset(&type, 0, sizeof(type)); |
| 1987 | |
| 1988 | /* min subelems */ |
| 1989 | data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END; |
| 1990 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1991 | lysp_type_free(st->ctx, &type); |
| 1992 | memset(&type, 0, sizeof(type)); |
| 1993 | |
| 1994 | st->finished_correctly = true; |
| 1995 | } |
| 1996 | |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1997 | static void |
| 1998 | test_max_elems_elem(void **state) |
| 1999 | { |
| 2000 | struct state *st = *state; |
| 2001 | const char *data; |
| 2002 | struct lysp_node_list list = {}; |
| 2003 | struct lysp_node_leaflist llist = {}; |
| 2004 | struct lysp_refine refine = {}; |
| 2005 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2006 | data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"unbounded\">"EXT_SUBELEM"</max-elements> </refine>"; |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2007 | assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS); |
| 2008 | assert_int_equal(refine.max, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2009 | assert_true(refine.flags & LYS_SET_MAX); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2010 | assert_string_equal(refine.exts[0].name, "myext:c-define"); |
| 2011 | assert_int_equal(refine.exts[0].insubstmt_index, 0); |
| 2012 | assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MAX); |
| 2013 | FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2014 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2015 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"5\">"EXT_SUBELEM"</max-elements> </list>"; |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2016 | assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, true), LY_SUCCESS); |
| 2017 | assert_int_equal(list.max, 5); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2018 | assert_true(list.flags & LYS_SET_MAX); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2019 | assert_string_equal(list.exts[0].name, "myext:c-define"); |
| 2020 | assert_int_equal(list.exts[0].insubstmt_index, 0); |
| 2021 | assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MAX); |
| 2022 | FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2023 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2024 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"85\">"EXT_SUBELEM"</max-elements> </leaf-list>"; |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2025 | assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, true), LY_SUCCESS); |
| 2026 | assert_int_equal(llist.max, 85); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2027 | assert_true(llist.flags & LYS_SET_MAX); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2028 | assert_string_equal(llist.exts[0].name, "myext:c-define"); |
| 2029 | assert_int_equal(llist.exts[0].insubstmt_index, 0); |
| 2030 | assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MAX); |
| 2031 | FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2032 | |
| 2033 | data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>"; |
| 2034 | assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS); |
| 2035 | assert_int_equal(refine.max, 10); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2036 | assert_true(refine.flags & LYS_SET_MAX); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2037 | |
| 2038 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>"; |
| 2039 | assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2040 | logbuf_assert("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element. Line number 1."); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2041 | |
| 2042 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>"; |
| 2043 | assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2044 | logbuf_assert("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element. Line number 1."); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2045 | |
| 2046 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>"; |
| 2047 | assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2048 | logbuf_assert("Invalid value \"k\" of \"value\" attribute in \"max-elements\" element. Line number 1."); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2049 | |
| 2050 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>"; |
| 2051 | assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2052 | logbuf_assert("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element. Line number 1."); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2053 | |
| 2054 | st->finished_correctly = true; |
| 2055 | } |
| 2056 | |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2057 | static void |
| 2058 | test_min_elems_elem(void **state) |
| 2059 | { |
| 2060 | struct state *st = *state; |
| 2061 | const char *data; |
| 2062 | struct lysp_node_list list = {}; |
| 2063 | struct lysp_node_leaflist llist = {}; |
| 2064 | struct lysp_refine refine = {}; |
| 2065 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2066 | data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"0\">"EXT_SUBELEM"</min-elements> </refine>"; |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2067 | assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS); |
| 2068 | assert_int_equal(refine.min, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2069 | assert_true(refine.flags & LYS_SET_MIN); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2070 | assert_string_equal(refine.exts[0].name, "myext:c-define"); |
| 2071 | assert_int_equal(refine.exts[0].insubstmt_index, 0); |
| 2072 | assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MIN); |
| 2073 | FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2074 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2075 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"41\">"EXT_SUBELEM"</min-elements> </list>"; |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2076 | assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, true), LY_SUCCESS); |
| 2077 | assert_int_equal(list.min, 41); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2078 | assert_true(list.flags & LYS_SET_MIN); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2079 | assert_string_equal(list.exts[0].name, "myext:c-define"); |
| 2080 | assert_int_equal(list.exts[0].insubstmt_index, 0); |
| 2081 | assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MIN); |
| 2082 | FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2083 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2084 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"50\">"EXT_SUBELEM"</min-elements> </leaf-list>"; |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2085 | assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, true), LY_SUCCESS); |
| 2086 | assert_int_equal(llist.min, 50); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2087 | assert_true(llist.flags & LYS_SET_MIN); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2088 | assert_string_equal(llist.exts[0].name, "myext:c-define"); |
| 2089 | assert_int_equal(llist.exts[0].insubstmt_index, 0); |
| 2090 | assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MIN); |
| 2091 | FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2092 | |
| 2093 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>"; |
| 2094 | assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2095 | logbuf_assert("Value \"-5\" of \"value\" attribute in \"min-elements\" element is out of bounds. Line number 1."); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2096 | |
| 2097 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>"; |
| 2098 | assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2099 | logbuf_assert("Value \"99999999999999999\" of \"value\" attribute in \"min-elements\" element is out of bounds. Line number 1."); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2100 | |
| 2101 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>"; |
| 2102 | assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2103 | logbuf_assert("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element. Line number 1."); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2104 | |
| 2105 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"05\"/> </leaf-list>"; |
| 2106 | assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2107 | logbuf_assert("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element. Line number 1."); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2108 | |
| 2109 | st->finished_correctly = true; |
| 2110 | } |
| 2111 | |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2112 | static void |
| 2113 | test_ordby_elem(void **state) |
| 2114 | { |
| 2115 | struct state *st = *state; |
| 2116 | const char *data; |
| 2117 | uint16_t flags = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2118 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2119 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2120 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\">"EXT_SUBELEM"</ordered-by>" ELEMENT_WRAPPER_END; |
| 2121 | assert_int_equal(test_element_helper(st, &data, &flags, NULL, &exts, true), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2122 | assert_true(flags & LYS_ORDBY_SYSTEM); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2123 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 2124 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 2125 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORDEREDBY); |
| 2126 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2127 | |
| 2128 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END; |
| 2129 | assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, true), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2130 | assert_true(flags & LYS_ORDBY_USER); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2131 | |
| 2132 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END; |
| 2133 | assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2134 | logbuf_assert("Invalid value \"inv\" of \"value\" attribute in \"ordered-by\" element. Line number 1."); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2135 | |
| 2136 | st->finished_correctly = true; |
| 2137 | } |
| 2138 | |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2139 | static void |
| 2140 | test_any_elem(void **state) |
| 2141 | { |
| 2142 | struct state *st = *state; |
| 2143 | const char *data; |
| 2144 | struct lysp_node *siblings = NULL; |
| 2145 | struct tree_node_meta node_meta = {.parent = NULL, .siblings = &siblings}; |
| 2146 | struct lysp_node_anydata *parsed = NULL; |
| 2147 | |
| 2148 | /* anyxml max subelems */ |
| 2149 | data = ELEMENT_WRAPPER_START |
| 2150 | "<anyxml name=\"any-name\">" |
| 2151 | "<config value=\"true\" />" |
| 2152 | "<description><text>desc</text></description>" |
| 2153 | "<if-feature name=\"feature\" />" |
| 2154 | "<mandatory value=\"true\" />" |
| 2155 | "<must condition=\"must-cond\" />" |
| 2156 | "<reference><text>ref</text></reference>" |
| 2157 | "<status value=\"deprecated\"/>" |
| 2158 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2159 | EXT_SUBELEM |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2160 | "</anyxml>" |
| 2161 | ELEMENT_WRAPPER_END; |
| 2162 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2163 | parsed = (struct lysp_node_anydata *)siblings; |
| 2164 | assert_null(parsed->parent); |
| 2165 | assert_int_equal(parsed->nodetype, LYS_ANYXML); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2166 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2167 | assert_true(parsed->flags & LYS_MAND_TRUE); |
| 2168 | assert_true(parsed->flags & LYS_STATUS_DEPRC); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2169 | assert_null(parsed->next); |
| 2170 | assert_string_equal(parsed->name, "any-name"); |
| 2171 | assert_string_equal(parsed->dsc, "desc"); |
| 2172 | assert_string_equal(parsed->ref, "ref"); |
| 2173 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2174 | assert_string_equal(*parsed->iffeatures, "feature"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2175 | assert_string_equal(parsed->exts[0].name, "myext:c-define"); |
| 2176 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2177 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2178 | lysp_node_free(st->ctx, siblings); |
| 2179 | siblings = NULL; |
| 2180 | |
| 2181 | /* anydata max subelems */ |
| 2182 | data = ELEMENT_WRAPPER_START |
| 2183 | "<anydata name=\"any-name\">" |
| 2184 | "<config value=\"true\" />" |
| 2185 | "<description><text>desc</text></description>" |
| 2186 | "<if-feature name=\"feature\" />" |
| 2187 | "<mandatory value=\"true\" />" |
| 2188 | "<must condition=\"must-cond\" />" |
| 2189 | "<reference><text>ref</text></reference>" |
| 2190 | "<status value=\"deprecated\"/>" |
| 2191 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2192 | EXT_SUBELEM |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2193 | "</anydata>" |
| 2194 | ELEMENT_WRAPPER_END; |
| 2195 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2196 | parsed = (struct lysp_node_anydata *)siblings; |
| 2197 | assert_null(parsed->parent); |
| 2198 | assert_int_equal(parsed->nodetype, LYS_ANYDATA); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2199 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2200 | assert_true(parsed->flags & LYS_MAND_TRUE); |
| 2201 | assert_true(parsed->flags & LYS_STATUS_DEPRC); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2202 | assert_null(parsed->next); |
| 2203 | assert_string_equal(parsed->name, "any-name"); |
| 2204 | assert_string_equal(parsed->dsc, "desc"); |
| 2205 | assert_string_equal(parsed->ref, "ref"); |
| 2206 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2207 | assert_string_equal(*parsed->iffeatures, "feature"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2208 | assert_string_equal(parsed->exts[0].name, "myext:c-define"); |
| 2209 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2210 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2211 | lysp_node_free(st->ctx, siblings); |
| 2212 | siblings = NULL; |
| 2213 | |
| 2214 | /* min subelems */ |
| 2215 | node_meta.parent = (void *)0x10; |
| 2216 | data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END; |
| 2217 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2218 | parsed = (struct lysp_node_anydata *)siblings; |
| 2219 | assert_ptr_equal(parsed->parent, node_meta.parent); |
| 2220 | assert_int_equal(parsed->nodetype, LYS_ANYDATA); |
| 2221 | assert_null(parsed->next); |
| 2222 | assert_null(parsed->exts); |
| 2223 | lysp_node_free(st->ctx, siblings); |
| 2224 | |
| 2225 | st->finished_correctly = true; |
| 2226 | } |
| 2227 | |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2228 | static void |
| 2229 | test_leaf_elem(void **state) |
| 2230 | { |
| 2231 | struct state *st = *state; |
| 2232 | const char *data; |
| 2233 | struct lysp_node *siblings = NULL; |
| 2234 | struct tree_node_meta node_meta = {.parent = NULL, .siblings = &siblings}; |
| 2235 | struct lysp_node_leaf *parsed = NULL; |
| 2236 | |
| 2237 | /* max elements */ |
| 2238 | data = ELEMENT_WRAPPER_START |
| 2239 | "<leaf name=\"leaf\">" |
| 2240 | "<config value=\"true\" />" |
| 2241 | "<default value=\"def-val\"/>" |
| 2242 | "<description><text>desc</text></description>" |
| 2243 | "<if-feature name=\"feature\" />" |
| 2244 | "<mandatory value=\"true\" />" |
| 2245 | "<must condition=\"must-cond\" />" |
| 2246 | "<reference><text>ref</text></reference>" |
| 2247 | "<status value=\"deprecated\"/>" |
| 2248 | "<type name=\"type\"/>" |
| 2249 | "<units name=\"uni\"/>" |
| 2250 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2251 | EXT_SUBELEM |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2252 | "</leaf>" |
| 2253 | ELEMENT_WRAPPER_END; |
| 2254 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2255 | parsed = (struct lysp_node_leaf *)siblings; |
| 2256 | assert_null(parsed->parent); |
| 2257 | assert_int_equal(parsed->nodetype, LYS_LEAF); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2258 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2259 | assert_true(parsed->flags & LYS_MAND_TRUE); |
| 2260 | assert_true(parsed->flags & LYS_STATUS_DEPRC); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2261 | assert_null(parsed->next); |
| 2262 | assert_string_equal(parsed->name, "leaf"); |
| 2263 | assert_string_equal(parsed->dsc, "desc"); |
| 2264 | assert_string_equal(parsed->ref, "ref"); |
| 2265 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2266 | assert_string_equal(*parsed->iffeatures, "feature"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2267 | assert_string_equal(parsed->exts[0].name, "myext:c-define"); |
| 2268 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2269 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2270 | assert_string_equal(parsed->musts->arg, "must-cond"); |
| 2271 | assert_string_equal(parsed->type.name, "type"); |
| 2272 | assert_string_equal(parsed->units, "uni"); |
| 2273 | assert_string_equal(parsed->dflt, "def-val"); |
| 2274 | lysp_node_free(st->ctx, siblings); |
| 2275 | siblings = NULL; |
| 2276 | |
| 2277 | /* min elements */ |
| 2278 | data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END; |
| 2279 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2280 | parsed = (struct lysp_node_leaf *)siblings; |
| 2281 | assert_string_equal(parsed->name, "leaf"); |
| 2282 | assert_string_equal(parsed->type.name, "type"); |
| 2283 | lysp_node_free(st->ctx, siblings); |
| 2284 | siblings = NULL; |
| 2285 | |
| 2286 | st->finished_correctly = true; |
| 2287 | } |
| 2288 | |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2289 | static void |
| 2290 | test_leaf_list_elem(void **state) |
| 2291 | { |
| 2292 | struct state *st = *state; |
| 2293 | const char *data; |
| 2294 | struct lysp_node *siblings = NULL; |
| 2295 | struct tree_node_meta node_meta = {.parent = NULL, .siblings = &siblings}; |
| 2296 | struct lysp_node_leaflist *parsed = NULL; |
| 2297 | |
| 2298 | data = ELEMENT_WRAPPER_START |
| 2299 | "<leaf-list name=\"llist\">" |
| 2300 | "<config value=\"true\" />" |
| 2301 | "<default value=\"def-val0\"/>" |
| 2302 | "<default value=\"def-val1\"/>" |
| 2303 | "<description><text>desc</text></description>" |
| 2304 | "<if-feature name=\"feature\"/>" |
| 2305 | "<max-elements value=\"5\"/>" |
| 2306 | "<must condition=\"must-cond\"/>" |
| 2307 | "<ordered-by value=\"user\" />" |
| 2308 | "<reference><text>ref</text></reference>" |
| 2309 | "<status value=\"current\"/>" |
| 2310 | "<type name=\"type\"/>" |
| 2311 | "<units name=\"uni\"/>" |
| 2312 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2313 | EXT_SUBELEM |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2314 | "</leaf-list>" |
| 2315 | ELEMENT_WRAPPER_END; |
| 2316 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2317 | parsed = (struct lysp_node_leaflist *)siblings; |
| 2318 | assert_string_equal(parsed->dflts[0], "def-val0"); |
| 2319 | assert_string_equal(parsed->dflts[1], "def-val1"); |
| 2320 | assert_string_equal(parsed->dsc, "desc"); |
| 2321 | assert_string_equal(*parsed->iffeatures, "feature"); |
| 2322 | assert_int_equal(parsed->max, 5); |
| 2323 | assert_string_equal(parsed->musts->arg, "must-cond"); |
| 2324 | assert_string_equal(parsed->name, "llist"); |
| 2325 | assert_null(parsed->next); |
| 2326 | assert_int_equal(parsed->nodetype, LYS_LEAFLIST); |
| 2327 | assert_null(parsed->parent); |
| 2328 | assert_string_equal(parsed->ref, "ref"); |
| 2329 | assert_string_equal(parsed->type.name, "type"); |
| 2330 | assert_string_equal(parsed->units, "uni"); |
| 2331 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2332 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2333 | assert_true(parsed->flags & LYS_ORDBY_USER); |
| 2334 | assert_true(parsed->flags & LYS_STATUS_CURR); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2335 | assert_string_equal(parsed->exts[0].name, "myext:c-define"); |
| 2336 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2337 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2338 | lysp_node_free(st->ctx, siblings); |
| 2339 | siblings = NULL; |
| 2340 | |
| 2341 | data = ELEMENT_WRAPPER_START |
| 2342 | "<leaf-list name=\"llist\">" |
| 2343 | "<config value=\"true\" />" |
| 2344 | "<description><text>desc</text></description>" |
| 2345 | "<if-feature name=\"feature\"/>" |
| 2346 | "<min-elements value=\"5\"/>" |
| 2347 | "<must condition=\"must-cond\"/>" |
| 2348 | "<ordered-by value=\"user\" />" |
| 2349 | "<reference><text>ref</text></reference>" |
| 2350 | "<status value=\"current\"/>" |
| 2351 | "<type name=\"type\"/>" |
| 2352 | "<units name=\"uni\"/>" |
| 2353 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2354 | EXT_SUBELEM |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2355 | "</leaf-list>" |
| 2356 | ELEMENT_WRAPPER_END; |
| 2357 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2358 | parsed = (struct lysp_node_leaflist *)siblings; |
| 2359 | assert_string_equal(parsed->dsc, "desc"); |
| 2360 | assert_string_equal(*parsed->iffeatures, "feature"); |
| 2361 | assert_int_equal(parsed->min, 5); |
| 2362 | assert_string_equal(parsed->musts->arg, "must-cond"); |
| 2363 | assert_string_equal(parsed->name, "llist"); |
| 2364 | assert_null(parsed->next); |
| 2365 | assert_int_equal(parsed->nodetype, LYS_LEAFLIST); |
| 2366 | assert_null(parsed->parent); |
| 2367 | assert_string_equal(parsed->ref, "ref"); |
| 2368 | assert_string_equal(parsed->type.name, "type"); |
| 2369 | assert_string_equal(parsed->units, "uni"); |
| 2370 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2371 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2372 | assert_true(parsed->flags & LYS_ORDBY_USER); |
| 2373 | assert_true(parsed->flags & LYS_STATUS_CURR); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2374 | assert_string_equal(parsed->exts[0].name, "myext:c-define"); |
| 2375 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2376 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2377 | lysp_node_free(st->ctx, siblings); |
| 2378 | siblings = NULL; |
| 2379 | |
| 2380 | data = ELEMENT_WRAPPER_START |
| 2381 | "<leaf-list name=\"llist\">" |
| 2382 | "<config value=\"true\" />" |
| 2383 | "<description><text>desc</text></description>" |
| 2384 | "<if-feature name=\"feature\"/>" |
| 2385 | "<max-elements value=\"15\"/>" |
| 2386 | "<min-elements value=\"5\"/>" |
| 2387 | "<must condition=\"must-cond\"/>" |
| 2388 | "<ordered-by value=\"user\" />" |
| 2389 | "<reference><text>ref</text></reference>" |
| 2390 | "<status value=\"current\"/>" |
| 2391 | "<type name=\"type\"/>" |
| 2392 | "<units name=\"uni\"/>" |
| 2393 | "<when condition=\"when-cond\"/>" |
| 2394 | "</leaf-list>" |
| 2395 | ELEMENT_WRAPPER_END; |
| 2396 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2397 | parsed = (struct lysp_node_leaflist *)siblings; |
| 2398 | assert_string_equal(parsed->dsc, "desc"); |
| 2399 | assert_string_equal(*parsed->iffeatures, "feature"); |
| 2400 | assert_int_equal(parsed->min, 5); |
| 2401 | assert_int_equal(parsed->max, 15); |
| 2402 | assert_string_equal(parsed->musts->arg, "must-cond"); |
| 2403 | assert_string_equal(parsed->name, "llist"); |
| 2404 | assert_null(parsed->next); |
| 2405 | assert_int_equal(parsed->nodetype, LYS_LEAFLIST); |
| 2406 | assert_null(parsed->parent); |
| 2407 | assert_string_equal(parsed->ref, "ref"); |
| 2408 | assert_string_equal(parsed->type.name, "type"); |
| 2409 | assert_string_equal(parsed->units, "uni"); |
| 2410 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2411 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2412 | assert_true(parsed->flags & LYS_ORDBY_USER); |
| 2413 | assert_true(parsed->flags & LYS_STATUS_CURR); |
| 2414 | lysp_node_free(st->ctx, siblings); |
| 2415 | siblings = NULL; |
| 2416 | |
| 2417 | data = ELEMENT_WRAPPER_START |
| 2418 | "<leaf-list name=\"llist\">" |
| 2419 | "<type name=\"type\"/>" |
| 2420 | "</leaf-list>" |
| 2421 | ELEMENT_WRAPPER_END; |
| 2422 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2423 | parsed = (struct lysp_node_leaflist *)siblings; |
| 2424 | assert_string_equal(parsed->name, "llist"); |
| 2425 | assert_string_equal(parsed->type.name, "type"); |
| 2426 | lysp_node_free(st->ctx, siblings); |
| 2427 | siblings = NULL; |
| 2428 | |
| 2429 | /* invalid combinations */ |
| 2430 | data = ELEMENT_WRAPPER_START |
| 2431 | "<leaf-list name=\"llist\">" |
| 2432 | "<max-elements value=\"5\"/>" |
| 2433 | "<min-elements value=\"15\"/>" |
| 2434 | "<type name=\"type\"/>" |
| 2435 | "</leaf-list>" |
| 2436 | ELEMENT_WRAPPER_END; |
| 2437 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID); |
| 2438 | logbuf_assert("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5. Line number 1."); |
| 2439 | lysp_node_free(st->ctx, siblings); |
| 2440 | siblings = NULL; |
| 2441 | |
| 2442 | data = ELEMENT_WRAPPER_START |
| 2443 | "<leaf-list name=\"llist\">" |
| 2444 | "<default value=\"def-val1\"/>" |
| 2445 | "<min-elements value=\"15\"/>" |
| 2446 | "<type name=\"type\"/>" |
| 2447 | "</leaf-list>" |
| 2448 | ELEMENT_WRAPPER_END; |
| 2449 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2450 | logbuf_assert("Invalid combination of sub-elemnts \"min-elements\" and \"default\" in \"leaf-list\" element. Line number 1."); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2451 | lysp_node_free(st->ctx, siblings); |
| 2452 | siblings = NULL; |
| 2453 | |
| 2454 | data = ELEMENT_WRAPPER_START |
| 2455 | "<leaf-list name=\"llist\">" |
| 2456 | "</leaf-list>" |
| 2457 | ELEMENT_WRAPPER_END; |
| 2458 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2459 | logbuf_assert("Missing mandatory sub-element \"type\" of \"leaf-list\" element. Line number 1."); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2460 | lysp_node_free(st->ctx, siblings); |
| 2461 | siblings = NULL; |
| 2462 | |
| 2463 | st->finished_correctly = true; |
| 2464 | } |
| 2465 | |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2466 | static void |
| 2467 | test_presence_elem(void **state) |
| 2468 | { |
| 2469 | struct state *st = *state; |
| 2470 | const char *data; |
| 2471 | const char *val; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2472 | struct lysp_ext_instance *exts = NULL; |
| 2473 | |
| 2474 | data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\">"EXT_SUBELEM"</presence>" ELEMENT_WRAPPER_END; |
| 2475 | assert_int_equal(test_element_helper(st, &data, &val, NULL, &exts, true), LY_SUCCESS); |
| 2476 | assert_string_equal(val, "presence-val"); |
| 2477 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 2478 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 2479 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PRESENCE); |
| 2480 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 2481 | FREE_STRING(st->ctx, val); |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2482 | |
| 2483 | data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END; |
| 2484 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS); |
| 2485 | assert_string_equal(val, "presence-val"); |
| 2486 | FREE_STRING(st->ctx, val); |
| 2487 | |
| 2488 | data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END; |
| 2489 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID); |
| 2490 | logbuf_assert("Missing mandatory attribute value of presence element. Line number 1."); |
| 2491 | |
| 2492 | st->finished_correctly = true; |
| 2493 | } |
| 2494 | |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2495 | static void |
| 2496 | test_key_elem(void **state) |
| 2497 | { |
| 2498 | struct state *st = *state; |
| 2499 | const char *data; |
| 2500 | const char *val; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2501 | struct lysp_ext_instance *exts = NULL; |
| 2502 | |
| 2503 | data = ELEMENT_WRAPPER_START "<key value=\"key-value\">"EXT_SUBELEM"</key>" ELEMENT_WRAPPER_END; |
| 2504 | assert_int_equal(test_element_helper(st, &data, &val, NULL, &exts, true), LY_SUCCESS); |
| 2505 | assert_string_equal(val, "key-value"); |
| 2506 | assert_string_equal(exts[0].name, "myext:c-define"); |
| 2507 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 2508 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_KEY); |
| 2509 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 2510 | FREE_STRING(st->ctx, val); |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2511 | |
| 2512 | data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END; |
| 2513 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS); |
| 2514 | assert_string_equal(val, "key-value"); |
| 2515 | FREE_STRING(st->ctx, val); |
| 2516 | |
| 2517 | data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END; |
| 2518 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID); |
| 2519 | logbuf_assert("Missing mandatory attribute value of key element. Line number 1."); |
| 2520 | |
| 2521 | st->finished_correctly = true; |
| 2522 | } |
| 2523 | |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2524 | static void |
| 2525 | test_typedef_elem(void **state) |
| 2526 | { |
| 2527 | struct state *st = *state; |
| 2528 | const char *data; |
| 2529 | struct lysp_tpdf *tpdfs = NULL; |
| 2530 | struct typedef_meta typdef_meta = {NULL, &tpdfs}; |
| 2531 | |
| 2532 | data = ELEMENT_WRAPPER_START |
| 2533 | "<typedef name=\"tpdf-name\">" |
| 2534 | "<default value=\"def-val\"/>" |
| 2535 | "<description><text>desc-text</text></description>" |
| 2536 | "<reference><text>ref-text</text></reference>" |
| 2537 | "<status value=\"current\"/>" |
| 2538 | "<type name=\"type\"/>" |
| 2539 | "<units name=\"uni\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2540 | EXT_SUBELEM |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2541 | "</typedef>" |
| 2542 | ELEMENT_WRAPPER_END; |
| 2543 | assert_int_equal(test_element_helper(st, &data, &typdef_meta, NULL, NULL, true), LY_SUCCESS); |
| 2544 | assert_string_equal(tpdfs[0].dflt, "def-val"); |
| 2545 | assert_string_equal(tpdfs[0].dsc, "desc-text"); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2546 | assert_string_equal(tpdfs[0].name, "tpdf-name"); |
| 2547 | assert_string_equal(tpdfs[0].ref, "ref-text"); |
| 2548 | assert_string_equal(tpdfs[0].type.name, "type"); |
| 2549 | assert_string_equal(tpdfs[0].units, "uni"); |
| 2550 | assert_true(tpdfs[0].flags & LYS_STATUS_CURR); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2551 | assert_string_equal(tpdfs[0].exts[0].name, "myext:c-define"); |
| 2552 | assert_int_equal(tpdfs[0].exts[0].insubstmt_index, 0); |
| 2553 | assert_int_equal(tpdfs[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2554 | FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free); |
| 2555 | tpdfs = NULL; |
| 2556 | |
| 2557 | data = ELEMENT_WRAPPER_START |
| 2558 | "<typedef name=\"tpdf-name\">" |
| 2559 | "<type name=\"type\"/>" |
| 2560 | "</typedef>" |
| 2561 | ELEMENT_WRAPPER_END; |
| 2562 | assert_int_equal(test_element_helper(st, &data, &typdef_meta, NULL, NULL, true), LY_SUCCESS); |
| 2563 | assert_string_equal(tpdfs[0].name, "tpdf-name"); |
| 2564 | assert_string_equal(tpdfs[0].type.name, "type"); |
| 2565 | FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free); |
| 2566 | tpdfs = NULL; |
| 2567 | |
| 2568 | st->finished_correctly = true; |
| 2569 | } |
| 2570 | |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2571 | static void |
| 2572 | test_refine_elem(void **state) |
| 2573 | { |
| 2574 | struct state *st = *state; |
| 2575 | const char *data; |
| 2576 | struct lysp_refine *refines = NULL; |
| 2577 | |
| 2578 | /* max subelems */ |
| 2579 | data = ELEMENT_WRAPPER_START |
| 2580 | "<refine target-node=\"target\">" |
| 2581 | "<if-feature name=\"feature\" />" |
| 2582 | "<must condition=\"cond\" />" |
| 2583 | "<presence value=\"presence\" />" |
| 2584 | "<default value=\"def\" />" |
| 2585 | "<config value=\"true\" />" |
| 2586 | "<mandatory value=\"true\" />" |
| 2587 | "<min-elements value=\"10\" />" |
| 2588 | "<max-elements value=\"20\" />" |
| 2589 | "<description><text>desc</text></description>" |
| 2590 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2591 | EXT_SUBELEM |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2592 | "</refine>" |
| 2593 | ELEMENT_WRAPPER_END; |
| 2594 | assert_int_equal(test_element_helper(st, &data, &refines, NULL, NULL, true), LY_SUCCESS); |
| 2595 | assert_string_equal(refines->nodeid, "target"); |
| 2596 | assert_string_equal(*refines->dflts, "def"); |
| 2597 | assert_string_equal(refines->dsc, "desc"); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2598 | assert_true(refines->flags & LYS_CONFIG_W); |
| 2599 | assert_true(refines->flags & LYS_MAND_TRUE); |
| 2600 | assert_string_equal(*refines->iffeatures, "feature"); |
| 2601 | assert_int_equal(refines->max, 20); |
| 2602 | assert_int_equal(refines->min, 10); |
| 2603 | assert_string_equal(refines->musts->arg, "cond"); |
| 2604 | assert_string_equal(refines->presence, "presence"); |
| 2605 | assert_string_equal(refines->ref, "ref"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2606 | assert_string_equal(refines->exts[0].name, "myext:c-define"); |
| 2607 | assert_int_equal(refines->exts[0].insubstmt_index, 0); |
| 2608 | assert_int_equal(refines->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2609 | FREE_ARRAY(st->ctx, refines, lysp_refine_free); |
| 2610 | refines = NULL; |
| 2611 | |
| 2612 | /* min subelems */ |
| 2613 | data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END; |
| 2614 | assert_int_equal(test_element_helper(st, &data, &refines, NULL, NULL, true), LY_SUCCESS); |
| 2615 | assert_string_equal(refines->nodeid, "target"); |
| 2616 | FREE_ARRAY(st->ctx, refines, lysp_refine_free); |
| 2617 | refines = NULL; |
| 2618 | |
| 2619 | st->finished_correctly = true; |
| 2620 | } |
| 2621 | |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2622 | static void |
| 2623 | test_uses_elem(void **state) |
| 2624 | { |
| 2625 | struct state *st = *state; |
| 2626 | const char *data; |
| 2627 | struct lysp_node *siblings = NULL; |
| 2628 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2629 | struct lysp_node_uses *parsed = NULL; |
| 2630 | |
| 2631 | /* max subelems */ |
| 2632 | data = ELEMENT_WRAPPER_START |
| 2633 | "<uses name=\"uses-name\">" |
| 2634 | "<when condition=\"cond\" />" |
| 2635 | "<if-feature name=\"feature\" />" |
| 2636 | "<status value=\"obsolete\" />" |
| 2637 | "<description><text>desc</text></description>" |
| 2638 | "<reference><text>ref</text></reference>" |
| 2639 | "<refine target-node=\"target\"/>" |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2640 | "<augment target-node=\"target\" />" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2641 | EXT_SUBELEM |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2642 | "</uses>" |
| 2643 | ELEMENT_WRAPPER_END; |
| 2644 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2645 | parsed = (struct lysp_node_uses *)&siblings[0]; |
| 2646 | assert_string_equal(parsed->name, "uses-name"); |
| 2647 | assert_string_equal(parsed->dsc, "desc"); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2648 | assert_true(parsed->flags & LYS_STATUS_OBSLT); |
| 2649 | assert_string_equal(*parsed->iffeatures, "feature"); |
| 2650 | assert_null(parsed->next); |
| 2651 | assert_int_equal(parsed->nodetype, LYS_USES); |
| 2652 | assert_null(parsed->parent); |
| 2653 | assert_string_equal(parsed->ref, "ref"); |
| 2654 | assert_string_equal(parsed->refines->nodeid, "target"); |
| 2655 | assert_string_equal(parsed->when->cond, "cond"); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2656 | assert_string_equal(parsed->augments->nodeid, "target"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2657 | assert_string_equal(parsed->exts[0].name, "myext:c-define"); |
| 2658 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2659 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2660 | lysp_node_free(st->ctx, siblings); |
| 2661 | siblings = NULL; |
| 2662 | |
| 2663 | /* min subelems */ |
| 2664 | data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END; |
| 2665 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2666 | assert_string_equal(siblings[0].name, "uses-name"); |
| 2667 | lysp_node_free(st->ctx, siblings); |
| 2668 | siblings = NULL; |
| 2669 | |
| 2670 | st->finished_correctly = true; |
| 2671 | } |
| 2672 | |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2673 | static void |
| 2674 | test_revision_elem(void **state) |
| 2675 | { |
| 2676 | struct state *st = *state; |
| 2677 | const char *data; |
| 2678 | struct lysp_revision *revs = NULL; |
| 2679 | |
| 2680 | /* max subelems */ |
| 2681 | data = ELEMENT_WRAPPER_START |
| 2682 | "<revision date=\"2018-12-25\">" |
| 2683 | "<description><text>desc</text></description>" |
| 2684 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2685 | EXT_SUBELEM |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2686 | "</revision>" |
| 2687 | ELEMENT_WRAPPER_END; |
| 2688 | assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, true), LY_SUCCESS); |
| 2689 | assert_string_equal(revs->date, "2018-12-25"); |
| 2690 | assert_string_equal(revs->dsc, "desc"); |
| 2691 | assert_string_equal(revs->ref, "ref"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2692 | assert_string_equal(revs->exts[0].name, "myext:c-define"); |
| 2693 | assert_int_equal(revs->exts[0].insubstmt_index, 0); |
| 2694 | assert_int_equal(revs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2695 | FREE_ARRAY(st->ctx, revs, lysp_revision_free); |
| 2696 | revs = NULL; |
| 2697 | |
| 2698 | /* min subelems */ |
| 2699 | data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END; |
| 2700 | assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, true), LY_SUCCESS); |
| 2701 | assert_string_equal(revs->date, "2005-05-05"); |
| 2702 | FREE_ARRAY(st->ctx, revs, lysp_revision_free); |
| 2703 | revs = NULL; |
| 2704 | |
| 2705 | /* invalid value */ |
| 2706 | data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END; |
| 2707 | assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, false), LY_EVALID); |
| 2708 | logbuf_assert("Invalid value \"05-05-2005\" of \"revision\". Line number 1."); |
| 2709 | FREE_ARRAY(st->ctx, revs, lysp_revision_free); |
| 2710 | revs = NULL; |
| 2711 | |
| 2712 | st->finished_correctly = true; |
| 2713 | } |
| 2714 | |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2715 | static void |
| 2716 | test_include_elem(void **state) |
| 2717 | { |
| 2718 | struct state *st = *state; |
| 2719 | const char *data; |
| 2720 | struct lysp_include *includes = NULL; |
| 2721 | struct include_meta inc_meta = {"module-name", &includes}; |
| 2722 | |
| 2723 | /* max subelems */ |
| 2724 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 2725 | data = ELEMENT_WRAPPER_START |
| 2726 | "<include module=\"mod\">" |
| 2727 | "<description><text>desc</text></description>" |
| 2728 | "<reference><text>ref</text></reference>" |
| 2729 | "<revision-date date=\"1999-09-09\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2730 | EXT_SUBELEM |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2731 | "</include>" |
| 2732 | ELEMENT_WRAPPER_END; |
| 2733 | assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, true), LY_SUCCESS); |
| 2734 | assert_string_equal(includes->name, "mod"); |
| 2735 | assert_string_equal(includes->dsc, "desc"); |
| 2736 | assert_string_equal(includes->ref, "ref"); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2737 | assert_string_equal(includes->rev, "1999-09-09"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2738 | assert_string_equal(includes->exts[0].name, "myext:c-define"); |
| 2739 | assert_int_equal(includes->exts[0].insubstmt_index, 0); |
| 2740 | assert_int_equal(includes->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2741 | FREE_ARRAY(st->ctx, includes, lysp_include_free); |
| 2742 | includes = NULL; |
| 2743 | |
| 2744 | /* min subelems */ |
| 2745 | data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END; |
| 2746 | assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, true), LY_SUCCESS); |
| 2747 | assert_string_equal(includes->name, "mod"); |
| 2748 | FREE_ARRAY(st->ctx, includes, lysp_include_free); |
| 2749 | includes = NULL; |
| 2750 | |
| 2751 | /* invalid combinations */ |
| 2752 | st->yin_ctx->mod_version = LYS_VERSION_1_0; |
| 2753 | data = ELEMENT_WRAPPER_START |
| 2754 | "<include module=\"mod\">" |
| 2755 | "<description><text>desc</text></description>" |
| 2756 | "<revision-date date=\"1999-09-09\"/>" |
| 2757 | "</include>" |
| 2758 | ELEMENT_WRAPPER_END; |
| 2759 | assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, false), LY_EVALID); |
| 2760 | logbuf_assert("Invalid sub-elemnt \"description\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 1."); |
| 2761 | FREE_ARRAY(st->ctx, includes, lysp_include_free); |
| 2762 | includes = NULL; |
| 2763 | |
| 2764 | st->yin_ctx->mod_version = LYS_VERSION_1_0; |
| 2765 | data = ELEMENT_WRAPPER_START |
| 2766 | "<include module=\"mod\">" |
| 2767 | "<reference><text>ref</text></reference>" |
| 2768 | "<revision-date date=\"1999-09-09\"/>" |
| 2769 | "</include>" |
| 2770 | ELEMENT_WRAPPER_END; |
| 2771 | assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, false), LY_EVALID); |
| 2772 | logbuf_assert("Invalid sub-elemnt \"reference\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 1."); |
| 2773 | FREE_ARRAY(st->ctx, includes, lysp_include_free); |
| 2774 | includes = NULL; |
| 2775 | |
| 2776 | st->finished_correctly = true; |
| 2777 | } |
| 2778 | |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 2779 | static void |
| 2780 | test_feature_elem(void **state) |
| 2781 | { |
| 2782 | struct state *st = *state; |
| 2783 | const char *data; |
| 2784 | struct lysp_feature *features = NULL; |
| 2785 | |
| 2786 | /* max subelems */ |
| 2787 | data = ELEMENT_WRAPPER_START |
| 2788 | "<feature name=\"feature-name\">" |
| 2789 | "<if-feature name=\"iff\"/>" |
| 2790 | "<status value=\"deprecated\"/>" |
| 2791 | "<description><text>desc</text></description>" |
| 2792 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2793 | EXT_SUBELEM |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 2794 | "</feature>" |
| 2795 | ELEMENT_WRAPPER_END; |
| 2796 | assert_int_equal(test_element_helper(st, &data, &features, NULL, NULL, true), LY_SUCCESS); |
| 2797 | assert_string_equal(features->name, "feature-name"); |
| 2798 | assert_string_equal(features->dsc, "desc"); |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 2799 | assert_true(features->flags & LYS_STATUS_DEPRC); |
| 2800 | assert_string_equal(*features->iffeatures, "iff"); |
| 2801 | assert_string_equal(features->ref, "ref"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2802 | assert_string_equal(features->exts[0].name, "myext:c-define"); |
| 2803 | assert_int_equal(features->exts[0].insubstmt_index, 0); |
| 2804 | assert_int_equal(features->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 2805 | FREE_ARRAY(st->ctx, features, lysp_feature_free); |
| 2806 | features = NULL; |
| 2807 | |
| 2808 | /* min subelems */ |
| 2809 | data = ELEMENT_WRAPPER_START "<feature name=\"feature-name\"/>" ELEMENT_WRAPPER_END; |
| 2810 | assert_int_equal(test_element_helper(st, &data, &features, NULL, NULL, true), LY_SUCCESS); |
| 2811 | assert_string_equal(features->name, "feature-name"); |
| 2812 | FREE_ARRAY(st->ctx, features, lysp_feature_free); |
| 2813 | features = NULL; |
| 2814 | |
| 2815 | st->finished_correctly = true; |
| 2816 | } |
| 2817 | |
David Sedlák | 28794f2 | 2019-07-22 16:45:00 +0200 | [diff] [blame] | 2818 | static void |
| 2819 | test_identity_elem(void **state) |
| 2820 | { |
| 2821 | struct state *st = *state; |
| 2822 | const char *data; |
| 2823 | struct lysp_ident *identities = NULL; |
| 2824 | |
| 2825 | /* max subelems */ |
| 2826 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 2827 | data = ELEMENT_WRAPPER_START |
| 2828 | "<identity name=\"ident-name\">" |
| 2829 | "<if-feature name=\"iff\"/>" |
| 2830 | "<base name=\"base-name\"/>" |
| 2831 | "<status value=\"deprecated\"/>" |
| 2832 | "<description><text>desc</text></description>" |
| 2833 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2834 | EXT_SUBELEM |
David Sedlák | 28794f2 | 2019-07-22 16:45:00 +0200 | [diff] [blame] | 2835 | "</identity>" |
| 2836 | ELEMENT_WRAPPER_END; |
| 2837 | assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, true), LY_SUCCESS); |
| 2838 | assert_string_equal(identities->name, "ident-name"); |
| 2839 | assert_string_equal(*identities->bases, "base-name"); |
| 2840 | assert_string_equal(*identities->iffeatures, "iff"); |
| 2841 | assert_string_equal(identities->dsc, "desc"); |
| 2842 | assert_string_equal(identities->ref, "ref"); |
| 2843 | assert_true(identities->flags & LYS_STATUS_DEPRC); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2844 | assert_string_equal(identities->exts[0].name, "myext:c-define"); |
| 2845 | assert_int_equal(identities->exts[0].insubstmt_index, 0); |
| 2846 | assert_int_equal(identities->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 28794f2 | 2019-07-22 16:45:00 +0200 | [diff] [blame] | 2847 | FREE_ARRAY(st->ctx, identities, lysp_ident_free); |
| 2848 | identities = NULL; |
| 2849 | |
| 2850 | /* min subelems */ |
| 2851 | data = ELEMENT_WRAPPER_START "<identity name=\"ident-name\" />" ELEMENT_WRAPPER_END; |
| 2852 | assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, true), LY_SUCCESS); |
| 2853 | assert_string_equal(identities->name, "ident-name"); |
| 2854 | FREE_ARRAY(st->ctx, identities, lysp_ident_free); |
| 2855 | identities = NULL; |
| 2856 | |
| 2857 | /* invalid */ |
| 2858 | st->yin_ctx->mod_version = LYS_VERSION_1_0; |
| 2859 | data = ELEMENT_WRAPPER_START |
| 2860 | "<identity name=\"ident-name\">" |
| 2861 | "<if-feature name=\"iff\"/>" |
| 2862 | "</identity>" |
| 2863 | ELEMENT_WRAPPER_END; |
| 2864 | assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, false), LY_EVALID); |
| 2865 | logbuf_assert("Invalid sub-elemnt \"if-feature\" of \"identity\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 1."); |
| 2866 | FREE_ARRAY(st->ctx, identities, lysp_ident_free); |
| 2867 | identities = NULL; |
| 2868 | |
| 2869 | st->finished_correctly = true; |
| 2870 | } |
| 2871 | |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2872 | static void |
| 2873 | test_list_elem(void **state) |
| 2874 | { |
| 2875 | struct state *st = *state; |
| 2876 | const char *data; |
| 2877 | struct lysp_node *siblings = NULL; |
| 2878 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2879 | struct lysp_node_list *parsed = NULL; |
| 2880 | |
| 2881 | /* max subelems */ |
| 2882 | data = ELEMENT_WRAPPER_START |
| 2883 | "<list name=\"list-name\">" |
| 2884 | "<when condition=\"when\"/>" |
| 2885 | "<if-feature name=\"iff\"/>" |
| 2886 | "<must condition=\"must-cond\"/>" |
| 2887 | "<key value=\"key\"/>" |
| 2888 | "<unique tag=\"utag\"/>" |
| 2889 | "<config value=\"true\"/>" |
| 2890 | "<min-elements value=\"10\"/>" |
| 2891 | "<ordered-by value=\"user\"/>" |
| 2892 | "<status value=\"deprecated\"/>" |
| 2893 | "<description><text>desc</text></description>" |
| 2894 | "<reference><text>ref</text></reference>" |
| 2895 | "<anydata name=\"anyd\"/>" |
| 2896 | "<anyxml name=\"anyx\"/>" |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2897 | "<container name=\"cont\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2898 | "<choice name=\"choice\"/>" |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2899 | "<action name=\"action\"/>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2900 | "<grouping name=\"grp\"/>" |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2901 | "<notification name=\"notf\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2902 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 2903 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2904 | "<list name=\"sub-list\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2905 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2906 | "<uses name=\"uses-name\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2907 | EXT_SUBELEM |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2908 | "</list>" |
| 2909 | ELEMENT_WRAPPER_END; |
| 2910 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2911 | parsed = (struct lysp_node_list *)&siblings[0]; |
| 2912 | assert_string_equal(parsed->dsc, "desc"); |
| 2913 | assert_string_equal(parsed->child->name, "anyd"); |
| 2914 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 2915 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 2916 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2917 | assert_string_equal(parsed->child->next->next->name, "cont"); |
| 2918 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2919 | assert_string_equal(parsed->child->next->next->next->name, "choice"); |
| 2920 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2921 | assert_string_equal(parsed->child->next->next->next->next->name, "leaf"); |
| 2922 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF); |
| 2923 | assert_string_equal(parsed->child->next->next->next->next->next->name, "llist"); |
| 2924 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2925 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list"); |
| 2926 | assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 2927 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name"); |
| 2928 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 2929 | assert_null(parsed->child->next->next->next->next->next->next->next->next); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2930 | assert_string_equal(parsed->groupings->name, "grp"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2931 | assert_string_equal(parsed->actions->name, "action"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2932 | assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2933 | assert_string_equal(parsed->notifs->name, "notf"); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2934 | assert_true(parsed->flags & LYS_ORDBY_USER); |
| 2935 | assert_true(parsed->flags & LYS_STATUS_DEPRC); |
| 2936 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2937 | assert_string_equal(*parsed->iffeatures, "iff"); |
| 2938 | assert_string_equal(parsed->key, "key"); |
| 2939 | assert_int_equal(parsed->min, 10); |
| 2940 | assert_string_equal(parsed->musts->arg, "must-cond"); |
| 2941 | assert_string_equal(parsed->name, "list-name"); |
| 2942 | assert_null(parsed->next); |
| 2943 | assert_int_equal(parsed->nodetype, LYS_LIST); |
| 2944 | assert_null(parsed->parent); |
| 2945 | assert_string_equal(parsed->ref, "ref"); |
| 2946 | assert_string_equal(parsed->typedefs->name, "tpdf"); |
| 2947 | assert_string_equal(*parsed->uniques, "utag"); |
| 2948 | assert_string_equal(parsed->when->cond, "when"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2949 | assert_string_equal(parsed->exts[0].name, "myext:c-define"); |
| 2950 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2951 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2952 | lysp_node_free(st->ctx, siblings); |
| 2953 | ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL); |
| 2954 | siblings = NULL; |
| 2955 | |
| 2956 | /* min subelems */ |
| 2957 | data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END; |
| 2958 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2959 | parsed = (struct lysp_node_list *)&siblings[0]; |
| 2960 | assert_string_equal(parsed->name, "list-name"); |
| 2961 | lysp_node_free(st->ctx, siblings); |
| 2962 | siblings = NULL; |
| 2963 | |
| 2964 | st->finished_correctly = true; |
| 2965 | } |
| 2966 | |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2967 | static void |
| 2968 | test_notification_elem(void **state) |
| 2969 | { |
| 2970 | struct state *st = *state; |
| 2971 | const char *data; |
| 2972 | struct lysp_notif *notifs = NULL; |
| 2973 | struct notif_meta notif_meta = {NULL, ¬ifs}; |
| 2974 | |
| 2975 | /* max subelems */ |
| 2976 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 2977 | data = ELEMENT_WRAPPER_START |
| 2978 | "<notification name=\"notif-name\">" |
| 2979 | "<anydata name=\"anyd\"/>" |
| 2980 | "<anyxml name=\"anyx\"/>" |
| 2981 | "<description><text>desc</text></description>" |
| 2982 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2983 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 2984 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2985 | "<list name=\"sub-list\"/>" |
| 2986 | "<must condition=\"cond\"/>" |
| 2987 | "<reference><text>ref</text></reference>" |
| 2988 | "<status value=\"deprecated\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2989 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2990 | "<uses name=\"uses-name\"/>" |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2991 | "<container name=\"cont\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2992 | "<choice name=\"choice\"/>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2993 | "<grouping name=\"grp\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2994 | EXT_SUBELEM |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2995 | "</notification>" |
| 2996 | ELEMENT_WRAPPER_END; |
| 2997 | assert_int_equal(test_element_helper(st, &data, ¬if_meta, NULL, NULL, true), LY_SUCCESS); |
| 2998 | assert_string_equal(notifs->name, "notif-name"); |
| 2999 | assert_string_equal(notifs->data->name, "anyd"); |
| 3000 | assert_int_equal(notifs->data->nodetype, LYS_ANYDATA); |
| 3001 | assert_string_equal(notifs->data->next->name, "anyx"); |
| 3002 | assert_int_equal(notifs->data->next->nodetype, LYS_ANYXML); |
| 3003 | assert_string_equal(notifs->data->next->next->name, "leaf"); |
| 3004 | assert_int_equal(notifs->data->next->next->nodetype, LYS_LEAF); |
| 3005 | assert_string_equal(notifs->data->next->next->next->name, "llist"); |
| 3006 | assert_int_equal(notifs->data->next->next->next->nodetype, LYS_LEAFLIST); |
| 3007 | assert_string_equal(notifs->data->next->next->next->next->name, "sub-list"); |
| 3008 | assert_int_equal(notifs->data->next->next->next->next->nodetype, LYS_LIST); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3009 | assert_true(notifs->flags & LYS_STATUS_DEPRC); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3010 | assert_string_equal(notifs->groupings->name, "grp"); |
| 3011 | assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3012 | assert_string_equal(notifs->data->next->next->next->next->next->name, "uses-name"); |
| 3013 | assert_int_equal(notifs->data->next->next->next->next->next->nodetype, LYS_USES); |
| 3014 | assert_string_equal(notifs->data->next->next->next->next->next->next->name, "cont"); |
| 3015 | assert_int_equal(notifs->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3016 | assert_int_equal(notifs->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 3017 | assert_string_equal(notifs->data->next->next->next->next->next->next->next->name, "choice"); |
| 3018 | assert_null(notifs->data->next->next->next->next->next->next->next->next); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3019 | assert_string_equal(*notifs->iffeatures, "iff"); |
| 3020 | assert_string_equal(notifs->musts->arg, "cond"); |
| 3021 | assert_int_equal(notifs->nodetype, LYS_NOTIF); |
| 3022 | assert_null(notifs->parent); |
| 3023 | assert_string_equal(notifs->ref, "ref"); |
| 3024 | assert_string_equal(notifs->typedefs->name, "tpdf"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3025 | assert_string_equal(notifs->exts[0].name, "myext:c-define"); |
| 3026 | assert_int_equal(notifs->exts[0].insubstmt_index, 0); |
| 3027 | assert_int_equal(notifs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3028 | FREE_ARRAY(st->ctx, notifs, lysp_notif_free); |
| 3029 | notifs = NULL; |
| 3030 | |
| 3031 | /* min subelems */ |
| 3032 | data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END; |
| 3033 | assert_int_equal(test_element_helper(st, &data, ¬if_meta, NULL, NULL, true), LY_SUCCESS); |
| 3034 | assert_string_equal(notifs->name, "notif-name"); |
| 3035 | FREE_ARRAY(st->ctx, notifs, lysp_notif_free); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3036 | notifs = NULL; |
| 3037 | |
| 3038 | st->finished_correctly = true; |
| 3039 | } |
| 3040 | |
| 3041 | static void |
| 3042 | test_grouping_elem(void **state) |
| 3043 | { |
| 3044 | struct state *st = *state; |
| 3045 | const char *data; |
| 3046 | struct lysp_grp *grps = NULL; |
| 3047 | struct grouping_meta grp_meta = {NULL, &grps}; |
| 3048 | |
| 3049 | /* max subelems */ |
| 3050 | data = ELEMENT_WRAPPER_START |
| 3051 | "<grouping name=\"grp-name\">" |
| 3052 | "<anydata name=\"anyd\"/>" |
| 3053 | "<anyxml name=\"anyx\"/>" |
| 3054 | "<description><text>desc</text></description>" |
| 3055 | "<grouping name=\"sub-grp\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3056 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3057 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3058 | "<list name=\"list\"/>" |
| 3059 | "<notification name=\"notf\"/>" |
| 3060 | "<reference><text>ref</text></reference>" |
| 3061 | "<status value=\"current\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3062 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3063 | "<uses name=\"uses-name\"/>" |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3064 | "<action name=\"act\"/>" |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3065 | "<container name=\"cont\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3066 | "<choice name=\"choice\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3067 | EXT_SUBELEM |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3068 | "</grouping>" |
| 3069 | ELEMENT_WRAPPER_END; |
| 3070 | assert_int_equal(test_element_helper(st, &data, &grp_meta, NULL, NULL, true), LY_SUCCESS); |
| 3071 | assert_string_equal(grps->name, "grp-name"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3072 | assert_string_equal(grps->data->name, "anyd"); |
| 3073 | assert_string_equal(grps->data->next->name, "anyx"); |
| 3074 | assert_string_equal(grps->data->next->next->name, "leaf"); |
| 3075 | assert_string_equal(grps->data->next->next->next->name, "llist"); |
| 3076 | assert_string_equal(grps->data->next->next->next->next->name, "list"); |
| 3077 | assert_string_equal(grps->dsc, "desc"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3078 | assert_true(grps->flags & LYS_STATUS_CURR); |
| 3079 | assert_string_equal(grps->groupings->name, "sub-grp"); |
| 3080 | assert_int_equal(grps->nodetype, LYS_GROUPING); |
| 3081 | assert_string_equal(grps->notifs->name, "notf"); |
| 3082 | assert_null(grps->parent); |
| 3083 | assert_string_equal(grps->ref, "ref"); |
| 3084 | assert_string_equal(grps->typedefs->name, "tpdf"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3085 | assert_string_equal(grps->actions->name, "act"); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3086 | assert_string_equal(grps->data->next->next->next->next->next->name, "uses-name"); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3087 | assert_int_equal(grps->data->next->next->next->next->next->nodetype, LYS_USES); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3088 | assert_string_equal(grps->data->next->next->next->next->next->next->name, "cont"); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3089 | assert_int_equal(grps->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER); |
| 3090 | assert_string_equal(grps->data->next->next->next->next->next->next->next->name, "choice"); |
| 3091 | assert_int_equal(grps->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3092 | assert_string_equal(grps->exts[0].name, "myext:c-define"); |
| 3093 | assert_int_equal(grps->exts[0].insubstmt_index, 0); |
| 3094 | assert_int_equal(grps->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3095 | FREE_ARRAY(st->ctx, grps, lysp_grp_free); |
| 3096 | grps = NULL; |
| 3097 | |
| 3098 | /* min subelems */ |
| 3099 | data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END; |
| 3100 | assert_int_equal(test_element_helper(st, &data, &grp_meta, NULL, NULL, true), LY_SUCCESS); |
| 3101 | assert_string_equal(grps->name, "grp-name"); |
| 3102 | FREE_ARRAY(st->ctx, grps, lysp_grp_free); |
| 3103 | grps = NULL; |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3104 | |
| 3105 | st->finished_correctly = true; |
| 3106 | } |
| 3107 | |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3108 | static void |
| 3109 | test_container_elem(void **state) |
| 3110 | { |
| 3111 | struct state *st = *state; |
| 3112 | const char *data; |
| 3113 | struct lysp_node *siblings = NULL; |
| 3114 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 3115 | struct lysp_node_container *parsed = NULL; |
| 3116 | |
| 3117 | /* max subelems */ |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3118 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3119 | data = ELEMENT_WRAPPER_START |
| 3120 | "<container name=\"cont-name\">" |
| 3121 | "<anydata name=\"anyd\"/>" |
| 3122 | "<anyxml name=\"anyx\"/>" |
| 3123 | "<config value=\"true\"/>" |
| 3124 | "<container name=\"subcont\"/>" |
| 3125 | "<description><text>desc</text></description>" |
| 3126 | "<grouping name=\"sub-grp\"/>" |
| 3127 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3128 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3129 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3130 | "<list name=\"list\"/>" |
| 3131 | "<must condition=\"cond\"/>" |
| 3132 | "<notification name=\"notf\"/>" |
| 3133 | "<presence value=\"presence\"/>" |
| 3134 | "<reference><text>ref</text></reference>" |
| 3135 | "<status value=\"current\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3136 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3137 | "<uses name=\"uses-name\"/>" |
| 3138 | "<when condition=\"when-cond\"/>" |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3139 | "<action name=\"act\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3140 | "<choice name=\"choice\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3141 | EXT_SUBELEM |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3142 | "</container>" |
| 3143 | ELEMENT_WRAPPER_END; |
| 3144 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 3145 | parsed = (struct lysp_node_container *)siblings; |
| 3146 | assert_string_equal(parsed->name, "cont-name"); |
| 3147 | assert_null(parsed->parent); |
| 3148 | assert_int_equal(parsed->nodetype, LYS_CONTAINER); |
| 3149 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 3150 | assert_true(parsed->flags & LYS_STATUS_CURR); |
| 3151 | assert_null(parsed->next); |
| 3152 | assert_string_equal(parsed->dsc, "desc"); |
| 3153 | assert_string_equal(parsed->ref, "ref"); |
| 3154 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 3155 | assert_string_equal(*parsed->iffeatures, "iff"); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3156 | assert_string_equal(parsed->musts->arg, "cond"); |
| 3157 | assert_string_equal(parsed->presence, "presence"); |
| 3158 | assert_string_equal(parsed->typedefs->name, "tpdf"); |
| 3159 | assert_string_equal(parsed->groupings->name, "sub-grp"); |
| 3160 | assert_string_equal(parsed->child->name, "anyd"); |
| 3161 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 3162 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 3163 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 3164 | assert_string_equal(parsed->child->next->next->name, "subcont"); |
| 3165 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
| 3166 | assert_string_equal(parsed->child->next->next->next->name, "leaf"); |
| 3167 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF); |
| 3168 | assert_string_equal(parsed->child->next->next->next->next->name, "llist"); |
| 3169 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3170 | assert_string_equal(parsed->child->next->next->next->next->next->name, "list"); |
| 3171 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST); |
| 3172 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name"); |
| 3173 | assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3174 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice"); |
| 3175 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 3176 | assert_null(parsed->child->next->next->next->next->next->next->next->next); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3177 | assert_string_equal(parsed->notifs->name, "notf"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3178 | assert_string_equal(parsed->actions->name, "act"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3179 | assert_string_equal(parsed->exts[0].name, "myext:c-define"); |
| 3180 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 3181 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3182 | lysp_node_free(st->ctx, siblings); |
| 3183 | ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL); |
| 3184 | siblings = NULL; |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3185 | |
| 3186 | /* min subelems */ |
| 3187 | data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END; |
| 3188 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 3189 | parsed = (struct lysp_node_container *)siblings; |
| 3190 | assert_string_equal(parsed->name, "cont-name"); |
| 3191 | lysp_node_free(st->ctx, siblings); |
| 3192 | siblings = NULL; |
| 3193 | |
| 3194 | st->finished_correctly = true; |
| 3195 | } |
| 3196 | |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3197 | static void |
| 3198 | test_case_elem(void **state) |
| 3199 | { |
| 3200 | struct state *st = *state; |
| 3201 | const char *data; |
| 3202 | struct lysp_node *siblings = NULL; |
| 3203 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 3204 | struct lysp_node_case *parsed = NULL; |
| 3205 | |
| 3206 | /* max subelems */ |
| 3207 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3208 | data = ELEMENT_WRAPPER_START |
| 3209 | "<case name=\"case-name\">" |
| 3210 | "<anydata name=\"anyd\"/>" |
| 3211 | "<anyxml name=\"anyx\"/>" |
| 3212 | "<container name=\"subcont\"/>" |
| 3213 | "<description><text>desc</text></description>" |
| 3214 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3215 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3216 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3217 | "<list name=\"list\"/>" |
| 3218 | "<reference><text>ref</text></reference>" |
| 3219 | "<status value=\"current\"/>" |
| 3220 | "<uses name=\"uses-name\"/>" |
| 3221 | "<when condition=\"when-cond\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3222 | "<choice name=\"choice\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3223 | EXT_SUBELEM |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3224 | "</case>" |
| 3225 | ELEMENT_WRAPPER_END; |
| 3226 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 3227 | parsed = (struct lysp_node_case *)siblings; |
| 3228 | assert_string_equal(parsed->name, "case-name"); |
| 3229 | assert_null(parsed->parent); |
| 3230 | assert_int_equal(parsed->nodetype, LYS_CASE); |
| 3231 | assert_true(parsed->flags & LYS_STATUS_CURR); |
| 3232 | assert_null(parsed->next); |
| 3233 | assert_string_equal(parsed->dsc, "desc"); |
| 3234 | assert_string_equal(parsed->ref, "ref"); |
| 3235 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 3236 | assert_string_equal(*parsed->iffeatures, "iff"); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3237 | assert_string_equal(parsed->child->name, "anyd"); |
| 3238 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 3239 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 3240 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 3241 | assert_string_equal(parsed->child->next->next->name, "subcont"); |
| 3242 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
| 3243 | assert_string_equal(parsed->child->next->next->next->name, "leaf"); |
| 3244 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF); |
| 3245 | assert_string_equal(parsed->child->next->next->next->next->name, "llist"); |
| 3246 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3247 | assert_string_equal(parsed->child->next->next->next->next->next->name, "list"); |
| 3248 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST); |
| 3249 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name"); |
| 3250 | assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_USES); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3251 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice"); |
| 3252 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 3253 | assert_null(parsed->child->next->next->next->next->next->next->next->next); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3254 | assert_string_equal(parsed->exts[0].name, "myext:c-define"); |
| 3255 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 3256 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3257 | lysp_node_free(st->ctx, siblings); |
| 3258 | siblings = NULL; |
| 3259 | |
| 3260 | /* min subelems */ |
| 3261 | data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END; |
| 3262 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 3263 | parsed = (struct lysp_node_case *)siblings; |
| 3264 | assert_string_equal(parsed->name, "case-name"); |
| 3265 | lysp_node_free(st->ctx, siblings); |
| 3266 | siblings = NULL; |
| 3267 | |
| 3268 | st->finished_correctly = true; |
| 3269 | } |
| 3270 | |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3271 | static void |
| 3272 | test_choice_elem(void **state) |
| 3273 | { |
| 3274 | struct state *st = *state; |
| 3275 | const char *data; |
| 3276 | struct lysp_node *siblings = NULL; |
| 3277 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 3278 | struct lysp_node_choice *parsed = NULL; |
| 3279 | |
| 3280 | /* max subelems */ |
| 3281 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3282 | data = ELEMENT_WRAPPER_START |
| 3283 | "<choice name=\"choice-name\">" |
| 3284 | "<anydata name=\"anyd\"/>" |
| 3285 | "<anyxml name=\"anyx\"/>" |
| 3286 | "<case name=\"sub-case\"/>" |
| 3287 | "<choice name=\"choice\"/>" |
| 3288 | "<config value=\"true\"/>" |
| 3289 | "<container name=\"subcont\"/>" |
| 3290 | "<default value=\"def\"/>" |
| 3291 | "<description><text>desc</text></description>" |
| 3292 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3293 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3294 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3295 | "<list name=\"list\"/>" |
| 3296 | "<mandatory value=\"true\" />" |
| 3297 | "<reference><text>ref</text></reference>" |
| 3298 | "<status value=\"current\"/>" |
| 3299 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3300 | EXT_SUBELEM |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3301 | "</choice>" |
| 3302 | ELEMENT_WRAPPER_END; |
| 3303 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 3304 | parsed = (struct lysp_node_choice *)siblings; |
| 3305 | assert_string_equal(parsed->name, "choice-name"); |
| 3306 | assert_null(parsed->parent); |
| 3307 | assert_int_equal(parsed->nodetype, LYS_CHOICE); |
| 3308 | assert_true(parsed->flags & LYS_CONFIG_W && parsed->flags & LYS_MAND_TRUE && parsed->flags & LYS_STATUS_CURR); |
| 3309 | assert_null(parsed->next); |
| 3310 | assert_string_equal(parsed->dsc, "desc"); |
| 3311 | assert_string_equal(parsed->ref, "ref"); |
| 3312 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 3313 | assert_string_equal(*parsed->iffeatures, "iff"); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3314 | assert_string_equal(parsed->child->name, "anyd"); |
| 3315 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 3316 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 3317 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 3318 | assert_string_equal(parsed->child->next->next->name, "sub-case"); |
| 3319 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE); |
| 3320 | assert_string_equal(parsed->child->next->next->next->name, "choice"); |
| 3321 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE); |
| 3322 | assert_string_equal(parsed->child->next->next->next->next->name, "subcont"); |
| 3323 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER); |
| 3324 | assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf"); |
| 3325 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF); |
| 3326 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist"); |
| 3327 | assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3328 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list"); |
| 3329 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3330 | assert_null(parsed->child->next->next->next->next->next->next->next->next); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3331 | assert_string_equal(parsed->exts[0].name, "myext:c-define"); |
| 3332 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 3333 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3334 | lysp_node_free(st->ctx, siblings); |
| 3335 | siblings = NULL; |
| 3336 | |
| 3337 | /* min subelems */ |
| 3338 | data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END; |
| 3339 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 3340 | parsed = (struct lysp_node_choice *)siblings; |
| 3341 | assert_string_equal(parsed->name, "choice-name"); |
| 3342 | lysp_node_free(st->ctx, siblings); |
| 3343 | siblings = NULL; |
| 3344 | |
| 3345 | st->finished_correctly = true; |
| 3346 | } |
| 3347 | |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3348 | static void |
| 3349 | test_inout_elem(void **state) |
| 3350 | { |
| 3351 | struct state *st = *state; |
| 3352 | const char *data; |
| 3353 | struct lysp_action_inout inout = {}; |
| 3354 | struct inout_meta inout_meta = {NULL, &inout}; |
| 3355 | |
| 3356 | /* max subelements */ |
| 3357 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3358 | data = ELEMENT_WRAPPER_START |
| 3359 | "<input>" |
| 3360 | "<anydata name=\"anyd\"/>" |
| 3361 | "<anyxml name=\"anyx\"/>" |
| 3362 | "<choice name=\"choice\"/>" |
| 3363 | "<container name=\"subcont\"/>" |
| 3364 | "<grouping name=\"sub-grp\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3365 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3366 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3367 | "<list name=\"list\"/>" |
| 3368 | "<must condition=\"cond\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3369 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3370 | "<uses name=\"uses-name\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3371 | EXT_SUBELEM |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3372 | "</input>" |
| 3373 | ELEMENT_WRAPPER_END; |
| 3374 | assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS); |
| 3375 | assert_null(inout.parent); |
| 3376 | assert_int_equal(inout.nodetype, LYS_INPUT); |
| 3377 | assert_string_equal(inout.musts->arg, "cond"); |
| 3378 | assert_string_equal(inout.typedefs->name, "tpdf"); |
| 3379 | assert_string_equal(inout.groupings->name, "sub-grp"); |
| 3380 | assert_string_equal(inout.data->name, "anyd"); |
| 3381 | assert_int_equal(inout.data->nodetype, LYS_ANYDATA); |
| 3382 | assert_string_equal(inout.data->next->name, "anyx"); |
| 3383 | assert_int_equal(inout.data->next->nodetype, LYS_ANYXML); |
| 3384 | assert_string_equal(inout.data->next->next->name, "choice"); |
| 3385 | assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE); |
| 3386 | assert_string_equal(inout.data->next->next->next->name, "subcont"); |
| 3387 | assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER); |
| 3388 | assert_string_equal(inout.data->next->next->next->next->name, "leaf"); |
| 3389 | assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF); |
| 3390 | assert_string_equal(inout.data->next->next->next->next->next->name, "llist"); |
| 3391 | assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3392 | assert_string_equal(inout.data->next->next->next->next->next->next->name, "list"); |
| 3393 | assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3394 | assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name"); |
| 3395 | assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3396 | assert_null(inout.data->next->next->next->next->next->next->next->next); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3397 | assert_string_equal(inout.exts[0].name, "myext:c-define"); |
| 3398 | assert_int_equal(inout.exts[0].insubstmt_index, 0); |
| 3399 | assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3400 | lysp_action_inout_free(st->ctx, &inout); |
| 3401 | memset(&inout, 0, sizeof inout); |
| 3402 | |
| 3403 | /* max subelements */ |
| 3404 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3405 | data = ELEMENT_WRAPPER_START |
| 3406 | "<output>" |
| 3407 | "<anydata name=\"anyd\"/>" |
| 3408 | "<anyxml name=\"anyx\"/>" |
| 3409 | "<choice name=\"choice\"/>" |
| 3410 | "<container name=\"subcont\"/>" |
| 3411 | "<grouping name=\"sub-grp\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3412 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3413 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3414 | "<list name=\"list\"/>" |
| 3415 | "<must condition=\"cond\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3416 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3417 | "<uses name=\"uses-name\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3418 | EXT_SUBELEM |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3419 | "</output>" |
| 3420 | ELEMENT_WRAPPER_END; |
| 3421 | assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS); |
| 3422 | assert_null(inout.parent); |
| 3423 | assert_int_equal(inout.nodetype, LYS_OUTPUT); |
| 3424 | assert_string_equal(inout.musts->arg, "cond"); |
| 3425 | assert_string_equal(inout.typedefs->name, "tpdf"); |
| 3426 | assert_string_equal(inout.groupings->name, "sub-grp"); |
| 3427 | assert_string_equal(inout.data->name, "anyd"); |
| 3428 | assert_int_equal(inout.data->nodetype, LYS_ANYDATA); |
| 3429 | assert_string_equal(inout.data->next->name, "anyx"); |
| 3430 | assert_int_equal(inout.data->next->nodetype, LYS_ANYXML); |
| 3431 | assert_string_equal(inout.data->next->next->name, "choice"); |
| 3432 | assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE); |
| 3433 | assert_string_equal(inout.data->next->next->next->name, "subcont"); |
| 3434 | assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER); |
| 3435 | assert_string_equal(inout.data->next->next->next->next->name, "leaf"); |
| 3436 | assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF); |
| 3437 | assert_string_equal(inout.data->next->next->next->next->next->name, "llist"); |
| 3438 | assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3439 | assert_string_equal(inout.data->next->next->next->next->next->next->name, "list"); |
| 3440 | assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3441 | assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name"); |
| 3442 | assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3443 | assert_null(inout.data->next->next->next->next->next->next->next->next); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3444 | assert_string_equal(inout.exts[0].name, "myext:c-define"); |
| 3445 | assert_int_equal(inout.exts[0].insubstmt_index, 0); |
| 3446 | assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3447 | lysp_action_inout_free(st->ctx, &inout); |
| 3448 | memset(&inout, 0, sizeof inout); |
| 3449 | |
| 3450 | /* min subelems */ |
| 3451 | data = ELEMENT_WRAPPER_START "<input />" ELEMENT_WRAPPER_END; |
| 3452 | assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS); |
| 3453 | memset(&inout, 0, sizeof inout); |
| 3454 | |
| 3455 | data = ELEMENT_WRAPPER_START "<output />" ELEMENT_WRAPPER_END; |
| 3456 | assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS); |
| 3457 | memset(&inout, 0, sizeof inout); |
| 3458 | |
| 3459 | /* invalid combinations */ |
| 3460 | data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END; |
| 3461 | assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 3462 | logbuf_assert("Unexpected attribute \"name\" of \"input\" element. Line number 1."); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3463 | memset(&inout, 0, sizeof inout); |
| 3464 | |
| 3465 | st->finished_correctly = true; |
| 3466 | } |
| 3467 | |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3468 | static void |
| 3469 | test_action_elem(void **state) |
| 3470 | { |
| 3471 | struct state *st = *state; |
| 3472 | const char *data; |
| 3473 | struct lysp_action *actions = NULL; |
| 3474 | struct action_meta act_meta = {NULL, &actions}; |
| 3475 | |
| 3476 | /* max subelems */ |
| 3477 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3478 | data = ELEMENT_WRAPPER_START |
| 3479 | "<action name=\"act\">" |
| 3480 | "<description><text>desc</text></description>" |
| 3481 | "<grouping name=\"grouping\"/>" |
| 3482 | "<if-feature name=\"iff\"/>" |
| 3483 | "<input><uses name=\"uses-name\"/></input>" |
| 3484 | "<output><must condition=\"cond\"/></output>" |
| 3485 | "<reference><text>ref</text></reference>" |
| 3486 | "<status value=\"deprecated\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3487 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3488 | EXT_SUBELEM |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3489 | "</action>" |
| 3490 | ELEMENT_WRAPPER_END; |
| 3491 | assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS); |
| 3492 | assert_null(actions->parent); |
| 3493 | assert_int_equal(actions->nodetype, LYS_ACTION); |
| 3494 | assert_true(actions->flags & LYS_STATUS_DEPRC); |
| 3495 | assert_string_equal(actions->name, "act"); |
| 3496 | assert_string_equal(actions->dsc, "desc"); |
| 3497 | assert_string_equal(actions->ref, "ref"); |
| 3498 | assert_string_equal(*actions->iffeatures, "iff"); |
| 3499 | assert_string_equal(actions->typedefs->name, "tpdf"); |
| 3500 | assert_string_equal(actions->groupings->name, "grouping"); |
| 3501 | assert_string_equal(actions->input.data->name, "uses-name"); |
| 3502 | assert_string_equal(actions->output.musts->arg, "cond"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3503 | assert_string_equal(actions->exts[0].name, "myext:c-define"); |
| 3504 | assert_int_equal(actions->exts[0].insubstmt_index, 0); |
| 3505 | assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3506 | FREE_ARRAY(st->ctx, actions, lysp_action_free) |
| 3507 | actions = NULL; |
| 3508 | |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3509 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3510 | data = ELEMENT_WRAPPER_START |
| 3511 | "<rpc name=\"act\">" |
| 3512 | "<description><text>desc</text></description>" |
| 3513 | "<grouping name=\"grouping\"/>" |
| 3514 | "<if-feature name=\"iff\"/>" |
| 3515 | "<input><uses name=\"uses-name\"/></input>" |
| 3516 | "<output><must condition=\"cond\"/></output>" |
| 3517 | "<reference><text>ref</text></reference>" |
| 3518 | "<status value=\"deprecated\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3519 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3520 | EXT_SUBELEM |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3521 | "</rpc>" |
| 3522 | ELEMENT_WRAPPER_END; |
| 3523 | assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS); |
| 3524 | assert_null(actions->parent); |
| 3525 | assert_int_equal(actions->nodetype, LYS_ACTION); |
| 3526 | assert_true(actions->flags & LYS_STATUS_DEPRC); |
| 3527 | assert_string_equal(actions->name, "act"); |
| 3528 | assert_string_equal(actions->dsc, "desc"); |
| 3529 | assert_string_equal(actions->ref, "ref"); |
| 3530 | assert_string_equal(*actions->iffeatures, "iff"); |
| 3531 | assert_string_equal(actions->typedefs->name, "tpdf"); |
| 3532 | assert_string_equal(actions->groupings->name, "grouping"); |
| 3533 | assert_string_equal(actions->input.data->name, "uses-name"); |
| 3534 | assert_string_equal(actions->output.musts->arg, "cond"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3535 | assert_string_equal(actions->exts[0].name, "myext:c-define"); |
| 3536 | assert_int_equal(actions->exts[0].insubstmt_index, 0); |
| 3537 | assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3538 | FREE_ARRAY(st->ctx, actions, lysp_action_free) |
| 3539 | actions = NULL; |
| 3540 | |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3541 | /* min subelems */ |
| 3542 | data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END; |
| 3543 | assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS); |
| 3544 | assert_string_equal(actions->name, "act"); |
| 3545 | FREE_ARRAY(st->ctx, actions, lysp_action_free) |
| 3546 | actions = NULL; |
| 3547 | |
| 3548 | st->finished_correctly = true; |
| 3549 | } |
| 3550 | |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3551 | static void |
| 3552 | test_augment_elem(void **state) |
| 3553 | { |
| 3554 | struct state *st = *state; |
| 3555 | const char *data; |
| 3556 | struct lysp_augment *augments = NULL; |
| 3557 | struct augment_meta aug_meta = {NULL, &augments}; |
| 3558 | |
| 3559 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3560 | data = ELEMENT_WRAPPER_START |
| 3561 | "<augment target-node=\"target\">" |
| 3562 | "<action name=\"action\"/>" |
| 3563 | "<anydata name=\"anyd\"/>" |
| 3564 | "<anyxml name=\"anyx\"/>" |
| 3565 | "<case name=\"case\"/>" |
| 3566 | "<choice name=\"choice\"/>" |
| 3567 | "<container name=\"subcont\"/>" |
| 3568 | "<description><text>desc</text></description>" |
| 3569 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3570 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3571 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3572 | "<list name=\"list\"/>" |
| 3573 | "<notification name=\"notif\"/>" |
| 3574 | "<reference><text>ref</text></reference>" |
| 3575 | "<status value=\"current\"/>" |
| 3576 | "<uses name=\"uses\"/>" |
| 3577 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3578 | EXT_SUBELEM |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3579 | "</augment>" |
| 3580 | ELEMENT_WRAPPER_END; |
| 3581 | assert_int_equal(test_element_helper(st, &data, &aug_meta, NULL, NULL, true), LY_SUCCESS); |
| 3582 | assert_string_equal(augments->nodeid, "target"); |
| 3583 | assert_null(augments->parent); |
| 3584 | assert_int_equal(augments->nodetype, LYS_AUGMENT); |
| 3585 | assert_true(augments->flags & LYS_STATUS_CURR); |
| 3586 | assert_string_equal(augments->dsc, "desc"); |
| 3587 | assert_string_equal(augments->ref, "ref"); |
| 3588 | assert_string_equal(augments->when->cond, "when-cond"); |
| 3589 | assert_string_equal(*augments->iffeatures, "iff"); |
| 3590 | assert_string_equal(augments->child->name, "anyd"); |
| 3591 | assert_int_equal(augments->child->nodetype, LYS_ANYDATA); |
| 3592 | assert_string_equal(augments->child->next->name, "anyx"); |
| 3593 | assert_int_equal(augments->child->next->nodetype, LYS_ANYXML); |
| 3594 | assert_string_equal(augments->child->next->next->name, "case"); |
| 3595 | assert_int_equal(augments->child->next->next->nodetype, LYS_CASE); |
| 3596 | assert_string_equal(augments->child->next->next->next->name, "choice"); |
| 3597 | assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE); |
| 3598 | assert_string_equal(augments->child->next->next->next->next->name, "subcont"); |
| 3599 | assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER); |
| 3600 | assert_string_equal(augments->child->next->next->next->next->next->name, "leaf"); |
| 3601 | assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF); |
| 3602 | assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist"); |
| 3603 | assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3604 | assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list"); |
| 3605 | assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3606 | assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses"); |
| 3607 | assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3608 | assert_null(augments->child->next->next->next->next->next->next->next->next->next); |
| 3609 | assert_string_equal(augments->actions->name, "action"); |
| 3610 | assert_string_equal(augments->notifs->name, "notif"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3611 | assert_string_equal(augments->exts[0].name, "myext:c-define"); |
| 3612 | assert_int_equal(augments->exts[0].insubstmt_index, 0); |
| 3613 | assert_int_equal(augments->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3614 | FREE_ARRAY(st->ctx, augments, lysp_augment_free) |
| 3615 | augments = NULL; |
| 3616 | |
| 3617 | data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END; |
| 3618 | assert_int_equal(test_element_helper(st, &data, &aug_meta, NULL, NULL, true), LY_SUCCESS); |
| 3619 | assert_string_equal(augments->nodeid, "target"); |
| 3620 | FREE_ARRAY(st->ctx, augments, lysp_augment_free) |
| 3621 | augments = NULL; |
| 3622 | |
| 3623 | st->finished_correctly = true; |
| 3624 | } |
| 3625 | |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3626 | static void |
| 3627 | test_deviate_elem(void **state) |
| 3628 | { |
| 3629 | struct state *st = *state; |
| 3630 | const char *data; |
| 3631 | struct lysp_deviate *deviates = NULL; |
| 3632 | struct lysp_deviate_add *d_add; |
| 3633 | struct lysp_deviate_rpl *d_rpl; |
| 3634 | struct lysp_deviate_del *d_del; |
| 3635 | |
| 3636 | /* all valid arguments with min subelems */ |
| 3637 | data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END; |
| 3638 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3639 | assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED); |
| 3640 | lysp_deviate_free(st->ctx, deviates); |
| 3641 | free(deviates); |
| 3642 | deviates = NULL; |
| 3643 | |
| 3644 | data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END; |
| 3645 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3646 | assert_int_equal(deviates->mod, LYS_DEV_ADD); |
| 3647 | lysp_deviate_free(st->ctx, deviates); |
| 3648 | free(deviates); |
| 3649 | deviates = NULL; |
| 3650 | |
| 3651 | data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END; |
| 3652 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3653 | assert_int_equal(deviates->mod, LYS_DEV_REPLACE); |
| 3654 | lysp_deviate_free(st->ctx, deviates); |
| 3655 | free(deviates); |
| 3656 | deviates = NULL; |
| 3657 | |
| 3658 | data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END; |
| 3659 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3660 | assert_int_equal(deviates->mod, LYS_DEV_DELETE); |
| 3661 | lysp_deviate_free(st->ctx, deviates); |
| 3662 | free(deviates); |
| 3663 | deviates = NULL; |
| 3664 | |
| 3665 | /* max subelems and valid arguments */ |
| 3666 | data = ELEMENT_WRAPPER_START |
| 3667 | "<deviate value=\"not-supported\">" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3668 | EXT_SUBELEM |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3669 | "</deviate>" |
| 3670 | ELEMENT_WRAPPER_END; |
| 3671 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3672 | assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3673 | assert_string_equal(deviates->exts[0].name, "myext:c-define"); |
| 3674 | assert_int_equal(deviates->exts[0].insubstmt_index, 0); |
| 3675 | assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3676 | lysp_deviate_free(st->ctx, deviates); |
| 3677 | free(deviates); |
| 3678 | deviates = NULL; |
| 3679 | |
| 3680 | data = ELEMENT_WRAPPER_START |
| 3681 | "<deviate value=\"add\">" |
| 3682 | "<units name=\"units\"/>" |
| 3683 | "<must condition=\"cond\"/>" |
| 3684 | "<unique tag=\"utag\"/>" |
| 3685 | "<default value=\"def\"/>" |
| 3686 | "<config value=\"true\"/>" |
| 3687 | "<mandatory value=\"true\"/>" |
| 3688 | "<min-elements value=\"5\"/>" |
| 3689 | "<max-elements value=\"15\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3690 | EXT_SUBELEM |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3691 | "</deviate>" |
| 3692 | ELEMENT_WRAPPER_END; |
| 3693 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3694 | d_add = (struct lysp_deviate_add *)deviates; |
| 3695 | assert_int_equal(d_add->mod, LYS_DEV_ADD); |
| 3696 | assert_null(d_add->next); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3697 | assert_string_equal(d_add->units, "units"); |
| 3698 | assert_string_equal(d_add->musts->arg, "cond"); |
| 3699 | assert_string_equal(*d_add->uniques, "utag"); |
| 3700 | assert_string_equal(*d_add->dflts, "def"); |
| 3701 | assert_true(d_add->flags & LYS_MAND_TRUE && d_add->flags & LYS_CONFIG_W); |
| 3702 | assert_int_equal(d_add->min, 5); |
| 3703 | assert_int_equal(d_add->max, 15); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3704 | assert_string_equal(deviates->exts[0].name, "myext:c-define"); |
| 3705 | assert_int_equal(deviates->exts[0].insubstmt_index, 0); |
| 3706 | assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3707 | lysp_deviate_free(st->ctx, deviates); |
| 3708 | free(deviates); |
| 3709 | deviates = NULL; |
| 3710 | |
| 3711 | data = ELEMENT_WRAPPER_START |
| 3712 | "<deviate value=\"replace\">" |
| 3713 | "<type name=\"newtype\"/>" |
| 3714 | "<units name=\"uni\"/>" |
| 3715 | "<default value=\"def\"/>" |
| 3716 | "<config value=\"true\"/>" |
| 3717 | "<mandatory value=\"true\"/>" |
| 3718 | "<min-elements value=\"5\"/>" |
| 3719 | "<max-elements value=\"15\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3720 | EXT_SUBELEM |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3721 | "</deviate>" |
| 3722 | ELEMENT_WRAPPER_END; |
| 3723 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3724 | d_rpl = (struct lysp_deviate_rpl *)deviates; |
| 3725 | assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE); |
| 3726 | assert_null(d_rpl->next); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3727 | assert_string_equal(d_rpl->type->name, "newtype"); |
| 3728 | assert_string_equal(d_rpl->units, "uni"); |
| 3729 | assert_string_equal(d_rpl->dflt, "def"); |
| 3730 | assert_true(d_rpl->flags & LYS_MAND_TRUE && d_rpl->flags & LYS_CONFIG_W); |
| 3731 | assert_int_equal(d_rpl->min, 5); |
| 3732 | assert_int_equal(d_rpl->max, 15); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3733 | assert_string_equal(deviates->exts[0].name, "myext:c-define"); |
| 3734 | assert_int_equal(deviates->exts[0].insubstmt_index, 0); |
| 3735 | assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3736 | lysp_deviate_free(st->ctx, deviates); |
| 3737 | free(deviates); |
| 3738 | deviates = NULL; |
| 3739 | |
| 3740 | data = ELEMENT_WRAPPER_START |
| 3741 | "<deviate value=\"delete\">" |
| 3742 | "<units name=\"u\"/>" |
| 3743 | "<must condition=\"c\"/>" |
| 3744 | "<unique tag=\"tag\"/>" |
| 3745 | "<default value=\"default\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3746 | EXT_SUBELEM |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3747 | "</deviate>" |
| 3748 | ELEMENT_WRAPPER_END; |
| 3749 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3750 | d_del = (struct lysp_deviate_del *)deviates; |
| 3751 | assert_int_equal(d_del->mod, LYS_DEV_DELETE); |
| 3752 | assert_null(d_del->next); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3753 | assert_string_equal(d_del->units, "u"); |
| 3754 | assert_string_equal(d_del->musts->arg, "c"); |
| 3755 | assert_string_equal(*d_del->uniques, "tag"); |
| 3756 | assert_string_equal(*d_del->dflts, "default"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3757 | assert_string_equal(deviates->exts[0].name, "myext:c-define"); |
| 3758 | assert_int_equal(deviates->exts[0].insubstmt_index, 0); |
| 3759 | assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3760 | lysp_deviate_free(st->ctx, deviates); |
| 3761 | free(deviates); |
| 3762 | deviates = NULL; |
| 3763 | |
| 3764 | /* invalid arguments */ |
| 3765 | data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END; |
| 3766 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 3767 | logbuf_assert("Invalid value \"\" of \"value\" attribute in \"deviate\" element. Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3768 | deviates = NULL; |
| 3769 | |
| 3770 | data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END; |
| 3771 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 3772 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"deviate\" element. Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3773 | deviates = NULL; |
| 3774 | |
| 3775 | data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END; |
| 3776 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 3777 | logbuf_assert("Invalid value \"ad\" of \"value\" attribute in \"deviate\" element. Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3778 | deviates = NULL; |
| 3779 | |
| 3780 | data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END; |
| 3781 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 3782 | logbuf_assert("Invalid value \"adds\" of \"value\" attribute in \"deviate\" element. Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3783 | deviates = NULL; |
| 3784 | |
| 3785 | data = ELEMENT_WRAPPER_START |
| 3786 | "<deviate value=\"not-supported\">" |
| 3787 | "<must condition=\"c\"/>" |
| 3788 | "</deviate>" |
| 3789 | ELEMENT_WRAPPER_END; |
| 3790 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID); |
| 3791 | logbuf_assert("Deviate of this type doesn't allow \"must\" as it's sub-element. Line number 1."); |
| 3792 | |
| 3793 | st->finished_correctly = true; |
| 3794 | } |
| 3795 | |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3796 | static void |
| 3797 | test_deviation_elem(void **state) |
| 3798 | { |
| 3799 | struct state *st = *state; |
| 3800 | const char *data; |
| 3801 | struct lysp_deviation *deviations = NULL; |
| 3802 | |
| 3803 | /* min subelems */ |
| 3804 | data = ELEMENT_WRAPPER_START |
| 3805 | "<deviation target-node=\"target\">" |
| 3806 | "<deviate value=\"not-supported\"/>" |
| 3807 | "</deviation>" |
| 3808 | ELEMENT_WRAPPER_END; |
| 3809 | assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, true), LY_SUCCESS); |
| 3810 | assert_string_equal(deviations->nodeid, "target"); |
| 3811 | assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED); |
| 3812 | FREE_ARRAY(st->ctx, deviations, lysp_deviation_free); |
| 3813 | deviations = NULL; |
| 3814 | |
| 3815 | /* max subelems */ |
| 3816 | data = ELEMENT_WRAPPER_START |
| 3817 | "<deviation target-node=\"target\">" |
| 3818 | "<reference><text>ref</text></reference>" |
| 3819 | "<description><text>desc</text></description>" |
| 3820 | "<deviate value=\"add\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3821 | EXT_SUBELEM |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3822 | "</deviation>" |
| 3823 | ELEMENT_WRAPPER_END; |
| 3824 | assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, true), LY_SUCCESS); |
| 3825 | assert_string_equal(deviations->nodeid, "target"); |
| 3826 | assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD); |
| 3827 | assert_string_equal(deviations->ref, "ref"); |
| 3828 | assert_string_equal(deviations->dsc, "desc"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3829 | assert_string_equal(deviations->exts[0].name, "myext:c-define"); |
| 3830 | assert_int_equal(deviations->exts[0].insubstmt_index, 0); |
| 3831 | assert_int_equal(deviations->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3832 | FREE_ARRAY(st->ctx, deviations, lysp_deviation_free); |
| 3833 | deviations = NULL; |
| 3834 | |
| 3835 | /* invalid */ |
| 3836 | data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END; |
| 3837 | assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, false), LY_EVALID); |
| 3838 | FREE_ARRAY(st->ctx, deviations, lysp_deviation_free); |
| 3839 | deviations = NULL; |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 3840 | logbuf_assert("Missing mandatory sub-element \"deviate\" of \"deviation\" element. Line number 1."); |
| 3841 | /* TODO */ |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3842 | st->finished_correctly = true; |
| 3843 | } |
| 3844 | |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3845 | static void |
| 3846 | test_module_elem(void **state) |
| 3847 | { |
| 3848 | struct state *st = *state; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame^] | 3849 | const char *data, *name, *prefix; |
| 3850 | size_t name_len, prefix_len; |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3851 | struct yin_arg_record *attrs = NULL; |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3852 | struct lys_module *lys_mod = NULL; |
| 3853 | struct lysp_module *lysp_mod = NULL; |
| 3854 | |
| 3855 | /* max subelems */ |
| 3856 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 3857 | lys_mod = calloc(1, sizeof *lys_mod); |
| 3858 | lysp_mod = calloc(1, sizeof *lysp_mod); |
| 3859 | lys_mod->ctx = st->ctx; |
| 3860 | lysp_mod->mod = lys_mod; |
| 3861 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
| 3862 | "<yang-version value=\"1.1\"/>\n" |
| 3863 | "<namespace uri=\"ns\"/>\n" |
| 3864 | "<prefix value=\"pref\"/>\n" |
| 3865 | "<include module=\"b-mod\"/>\n" |
| 3866 | "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n" |
| 3867 | "<organization><text>org</text></organization>\n" |
| 3868 | "<contact><text>contact</text></contact>\n" |
| 3869 | "<description><text>desc</text></description>" |
| 3870 | "<reference><text>ref</text></reference>\n" |
| 3871 | "<revision date=\"2019-02-02\"/>\n" |
| 3872 | "<anydata name=\"anyd\"/>\n" |
| 3873 | "<anyxml name=\"anyx\"/>\n" |
| 3874 | "<choice name=\"choice\"/>\n" |
| 3875 | "<container name=\"cont\"/>\n" |
| 3876 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 3877 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 3878 | "<list name=\"sub-list\"/>\n" |
| 3879 | "<uses name=\"uses-name\"/>\n" |
| 3880 | "<augment target-node=\"target\"/>\n" |
| 3881 | "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n" |
| 3882 | "<extension name=\"ext\"/>\n" |
| 3883 | "<feature name=\"feature\"/>\n" |
| 3884 | "<grouping name=\"grp\"/>\n" |
| 3885 | "<identity name=\"ident-name\"/>\n" |
| 3886 | "<notification name=\"notf\"/>\n" |
| 3887 | "<rpc name=\"rpc-name\"/>\n" |
| 3888 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3889 | EXT_SUBELEM"\n" |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3890 | "</module>\n"; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame^] | 3891 | assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3892 | assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS); |
| 3893 | assert_int_equal(yin_parse_mod(st->yin_ctx, attrs, &data, lysp_mod), LY_SUCCESS); |
| 3894 | assert_string_equal(lysp_mod->mod->name, "mod"); |
| 3895 | assert_string_equal(lysp_mod->revs, "2019-02-02"); |
| 3896 | assert_string_equal(lysp_mod->mod->ns, "ns"); |
| 3897 | assert_string_equal(lysp_mod->mod->prefix, "pref"); |
| 3898 | assert_null(lysp_mod->mod->filepath); |
| 3899 | assert_string_equal(lysp_mod->mod->org, "org"); |
| 3900 | assert_string_equal(lysp_mod->mod->contact, "contact"); |
| 3901 | assert_string_equal(lysp_mod->mod->dsc, "desc"); |
| 3902 | assert_string_equal(lysp_mod->mod->ref, "ref"); |
| 3903 | assert_int_equal(lysp_mod->mod->version, LYS_VERSION_1_1); |
| 3904 | assert_string_equal(lysp_mod->imports->name, "a-mod"); |
| 3905 | assert_string_equal(lysp_mod->includes->name, "b-mod"); |
| 3906 | assert_string_equal(lysp_mod->extensions->name, "ext"); |
| 3907 | assert_string_equal(lysp_mod->features->name, "feature"); |
| 3908 | assert_string_equal(lysp_mod->identities->name, "ident-name"); |
| 3909 | assert_string_equal(lysp_mod->typedefs->name, "tpdf"); |
| 3910 | assert_string_equal(lysp_mod->groupings->name, "grp"); |
| 3911 | assert_string_equal(lysp_mod->data->name, "anyd"); |
| 3912 | assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA); |
| 3913 | assert_string_equal(lysp_mod->data->next->name, "anyx"); |
| 3914 | assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML); |
| 3915 | assert_string_equal(lysp_mod->data->next->next->name, "choice"); |
| 3916 | assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE); |
| 3917 | assert_string_equal(lysp_mod->data->next->next->next->name, "cont"); |
| 3918 | assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER); |
| 3919 | assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf"); |
| 3920 | assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF); |
| 3921 | assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist"); |
| 3922 | assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3923 | assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list"); |
| 3924 | assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3925 | assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name"); |
| 3926 | assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3927 | assert_null(lysp_mod->data->next->next->next->next->next->next->next->next); |
| 3928 | assert_string_equal(lysp_mod->augments->nodeid, "target"); |
| 3929 | assert_string_equal(lysp_mod->rpcs->name, "rpc-name"); |
| 3930 | assert_string_equal(lysp_mod->notifs->name, "notf"); |
| 3931 | assert_string_equal(lysp_mod->deviations->nodeid, "target"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3932 | assert_string_equal(lysp_mod->exts[0].name, "myext:c-define"); |
| 3933 | assert_int_equal(lysp_mod->exts[0].insubstmt_index, 0); |
| 3934 | assert_int_equal(lysp_mod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3935 | lysp_module_free(lysp_mod); |
| 3936 | lys_module_free(lys_mod, NULL); |
| 3937 | FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec); |
| 3938 | attrs = NULL; |
| 3939 | |
| 3940 | /* min subelems */ |
| 3941 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 3942 | lys_mod = calloc(1, sizeof *lys_mod); |
| 3943 | lysp_mod = calloc(1, sizeof *lysp_mod); |
| 3944 | lys_mod->ctx = st->ctx; |
| 3945 | lysp_mod->mod = lys_mod; |
| 3946 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">" |
| 3947 | "<namespace uri=\"ns\"/>" |
| 3948 | "<prefix value=\"pref\"/>" |
| 3949 | "<yang-version value=\"1.1\"/>" |
| 3950 | "</module>"; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame^] | 3951 | assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3952 | assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS); |
| 3953 | assert_int_equal(yin_parse_mod(st->yin_ctx, attrs, &data, lysp_mod), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3954 | assert_string_equal(lysp_mod->mod->name, "mod"); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3955 | lysp_module_free(lysp_mod); |
| 3956 | lys_module_free(lys_mod, NULL); |
| 3957 | FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec); |
| 3958 | attrs = NULL; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3959 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3960 | /* incorrect subelem order */ |
| 3961 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 3962 | lys_mod = calloc(1, sizeof *lys_mod); |
| 3963 | lysp_mod = calloc(1, sizeof *lysp_mod); |
| 3964 | lys_mod->ctx = st->ctx; |
| 3965 | lysp_mod->mod = lys_mod; |
| 3966 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">" |
| 3967 | "<feature name=\"feature\"/>\n" |
| 3968 | "<namespace uri=\"ns\"/>" |
| 3969 | "<prefix value=\"pref\"/>" |
| 3970 | "<yang-version value=\"1.1\"/>" |
| 3971 | "</module>"; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame^] | 3972 | assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3973 | assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS); |
| 3974 | assert_int_equal(yin_parse_mod(st->yin_ctx, attrs, &data, lysp_mod), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 3975 | logbuf_assert("Invalid order of module\'s sub-elements \"namespace\" can\'t appear after \"feature\". Line number 30."); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3976 | lysp_module_free(lysp_mod); |
| 3977 | lys_module_free(lys_mod, NULL); |
| 3978 | FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec); |
| 3979 | attrs = NULL; |
| 3980 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3981 | st->finished_correctly = true; |
| 3982 | } |
| 3983 | |
| 3984 | static void |
| 3985 | test_submodule_elem(void **state) |
| 3986 | { |
| 3987 | struct state *st = *state; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame^] | 3988 | const char *data, *name, *prefix; |
| 3989 | size_t name_len, prefix_len; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3990 | struct yin_arg_record *attrs = NULL; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3991 | struct lysp_submodule *lysp_submod = NULL; |
| 3992 | |
| 3993 | /* max subelements */ |
| 3994 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 3995 | lysp_submod = calloc(1, sizeof *lysp_submod); |
| 3996 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
| 3997 | "<yang-version value=\"1.1\"/>\n" |
| 3998 | "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>" |
| 3999 | "<include module=\"b-mod\"/>\n" |
| 4000 | "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n" |
| 4001 | "<organization><text>org</text></organization>\n" |
| 4002 | "<contact><text>contact</text></contact>\n" |
| 4003 | "<description><text>desc</text></description>" |
| 4004 | "<reference><text>ref</text></reference>\n" |
| 4005 | "<revision date=\"2019-02-02\"/>\n" |
| 4006 | "<anydata name=\"anyd\"/>\n" |
| 4007 | "<anyxml name=\"anyx\"/>\n" |
| 4008 | "<choice name=\"choice\"/>\n" |
| 4009 | "<container name=\"cont\"/>\n" |
| 4010 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 4011 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 4012 | "<list name=\"sub-list\"/>\n" |
| 4013 | "<uses name=\"uses-name\"/>\n" |
| 4014 | "<augment target-node=\"target\"/>\n" |
| 4015 | "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n" |
| 4016 | "<extension name=\"ext\"/>\n" |
| 4017 | "<feature name=\"feature\"/>\n" |
| 4018 | "<grouping name=\"grp\"/>\n" |
| 4019 | "<identity name=\"ident-name\"/>\n" |
| 4020 | "<notification name=\"notf\"/>\n" |
| 4021 | "<rpc name=\"rpc-name\"/>\n" |
| 4022 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 4023 | EXT_SUBELEM"\n" |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4024 | "</submodule>\n"; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame^] | 4025 | assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4026 | assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS); |
| 4027 | assert_int_equal(yin_parse_submod(st->yin_ctx, attrs, &data, lysp_submod), LY_SUCCESS); |
| 4028 | |
| 4029 | assert_string_equal(lysp_submod->name, "mod"); |
| 4030 | assert_string_equal(lysp_submod->revs, "2019-02-02"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4031 | assert_string_equal(lysp_submod->prefix, "pref"); |
| 4032 | assert_null(lysp_submod->filepath); |
| 4033 | assert_string_equal(lysp_submod->org, "org"); |
| 4034 | assert_string_equal(lysp_submod->contact, "contact"); |
| 4035 | assert_string_equal(lysp_submod->dsc, "desc"); |
| 4036 | assert_string_equal(lysp_submod->ref, "ref"); |
| 4037 | assert_int_equal(lysp_submod->version, LYS_VERSION_1_1); |
| 4038 | assert_string_equal(lysp_submod->imports->name, "a-mod"); |
| 4039 | assert_string_equal(lysp_submod->includes->name, "b-mod"); |
| 4040 | assert_string_equal(lysp_submod->extensions->name, "ext"); |
| 4041 | assert_string_equal(lysp_submod->features->name, "feature"); |
| 4042 | assert_string_equal(lysp_submod->identities->name, "ident-name"); |
| 4043 | assert_string_equal(lysp_submod->typedefs->name, "tpdf"); |
| 4044 | assert_string_equal(lysp_submod->groupings->name, "grp"); |
| 4045 | assert_string_equal(lysp_submod->data->name, "anyd"); |
| 4046 | assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA); |
| 4047 | assert_string_equal(lysp_submod->data->next->name, "anyx"); |
| 4048 | assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML); |
| 4049 | assert_string_equal(lysp_submod->data->next->next->name, "choice"); |
| 4050 | assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE); |
| 4051 | assert_string_equal(lysp_submod->data->next->next->next->name, "cont"); |
| 4052 | assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER); |
| 4053 | assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf"); |
| 4054 | assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF); |
| 4055 | assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist"); |
| 4056 | assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 4057 | assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list"); |
| 4058 | assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 4059 | assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name"); |
| 4060 | assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 4061 | assert_null(lysp_submod->data->next->next->next->next->next->next->next->next); |
| 4062 | assert_string_equal(lysp_submod->augments->nodeid, "target"); |
| 4063 | assert_string_equal(lysp_submod->rpcs->name, "rpc-name"); |
| 4064 | assert_string_equal(lysp_submod->notifs->name, "notf"); |
| 4065 | assert_string_equal(lysp_submod->deviations->nodeid, "target"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 4066 | assert_string_equal(lysp_submod->exts[0].name, "myext:c-define"); |
| 4067 | assert_int_equal(lysp_submod->exts[0].insubstmt_index, 0); |
| 4068 | assert_int_equal(lysp_submod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4069 | |
| 4070 | lysp_submodule_free(st->ctx, lysp_submod); |
| 4071 | FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec); |
| 4072 | attrs = NULL; |
| 4073 | |
| 4074 | /* min subelemnts */ |
| 4075 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 4076 | lysp_submod = calloc(1, sizeof *lysp_submod); |
| 4077 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">" |
| 4078 | "<yang-version value=\"1.0\"/>" |
| 4079 | "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>" |
| 4080 | "</submodule>"; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame^] | 4081 | assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4082 | assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS); |
| 4083 | assert_int_equal(yin_parse_submod(st->yin_ctx, attrs, &data, lysp_submod), LY_SUCCESS); |
| 4084 | assert_string_equal(lysp_submod->prefix, "pref"); |
| 4085 | assert_string_equal(lysp_submod->belongsto, "mod-name"); |
| 4086 | assert_int_equal(lysp_submod->version, LYS_VERSION_1_0); |
| 4087 | lysp_submodule_free(st->ctx, lysp_submod); |
| 4088 | FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec); |
| 4089 | attrs = NULL; |
| 4090 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 4091 | /* incorrect subelem order */ |
| 4092 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 4093 | lysp_submod = calloc(1, sizeof *lysp_submod); |
| 4094 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">" |
| 4095 | "<yang-version value=\"1.0\"/>" |
| 4096 | "<reference><text>ref</text></reference>\n" |
| 4097 | "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>" |
| 4098 | "</submodule>"; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame^] | 4099 | assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len), LY_SUCCESS); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 4100 | assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS); |
| 4101 | assert_int_equal(yin_parse_submod(st->yin_ctx, attrs, &data, lysp_submod), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 4102 | logbuf_assert("Invalid order of submodule's sub-elements \"belongs-to\" can't appear after \"reference\". Line number 28."); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 4103 | lysp_submodule_free(st->ctx, lysp_submod); |
| 4104 | FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec); |
| 4105 | attrs = NULL; |
| 4106 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4107 | st->finished_correctly = true; |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 4108 | } |
| 4109 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4110 | static void |
| 4111 | test_yin_parse_module(void **state) |
| 4112 | { |
| 4113 | struct state *st = *state; |
| 4114 | const char *data; |
| 4115 | struct lys_module *mod; |
| 4116 | struct yin_parser_ctx *yin_ctx = NULL; |
| 4117 | |
| 4118 | mod = calloc(1, sizeof *mod); |
| 4119 | mod->ctx = st->ctx; |
| 4120 | data = "<module name=\"example-foo\"" |
| 4121 | "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"" |
| 4122 | "xmlns:foo=\"urn:example:foo\"" |
| 4123 | "xmlns:myext=\"urn:example:extensions\">\n" |
| 4124 | |
| 4125 | "<yang-version value=\"1.0\"/>\n" |
| 4126 | |
| 4127 | "<namespace uri=\"urn:example:foo\"/>\n" |
| 4128 | "<prefix value=\"foo\"/>\n" |
| 4129 | |
| 4130 | "<import module=\"example-extensions\">\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4131 | "<prefix value=\"myext\"/>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4132 | "</import>\n" |
| 4133 | |
| 4134 | "<list name=\"interface\">\n" |
| 4135 | "<key value=\"name\"/>\n" |
| 4136 | "<leaf name=\"name\">\n" |
| 4137 | "<type name=\"string\"/>\n" |
| 4138 | "</leaf>\n" |
| 4139 | "<leaf name=\"mtu\">\n" |
| 4140 | "<type name=\"uint32\"/>\n" |
| 4141 | "<description>\n" |
| 4142 | "<text>The MTU of the interface.</text>\n" |
| 4143 | "</description>\n" |
| 4144 | "<myext:c-define name=\"MY_MTU\"/>\n" |
| 4145 | "</leaf>\n" |
| 4146 | "</list>\n" |
| 4147 | "</module>\n"; |
| 4148 | assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS); |
| 4149 | lys_module_free(mod, NULL); |
| 4150 | yin_parser_ctx_free(yin_ctx); |
| 4151 | mod = NULL; |
| 4152 | yin_ctx = NULL; |
| 4153 | |
| 4154 | mod = calloc(1, sizeof *mod); |
| 4155 | mod->ctx = st->ctx; |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4156 | data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 4157 | "<yang-version value=\"1.0\"/>\n" |
| 4158 | "<namespace uri=\"urn:example:foo\"/>\n" |
| 4159 | "<prefix value=\"foo\"/>\n" |
| 4160 | "</module>\n"; |
| 4161 | assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS); |
| 4162 | lys_module_free(mod, NULL); |
| 4163 | yin_parser_ctx_free(yin_ctx); |
| 4164 | mod = NULL; |
| 4165 | yin_ctx = NULL; |
| 4166 | |
| 4167 | |
| 4168 | mod = calloc(1, sizeof *mod); |
| 4169 | mod->ctx = st->ctx; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4170 | data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4171 | "</submodule>\n"; |
| 4172 | assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EINVAL); |
| 4173 | logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module."); |
| 4174 | lys_module_free(mod, NULL); |
| 4175 | yin_parser_ctx_free(yin_ctx); |
| 4176 | |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4177 | mod = calloc(1, sizeof *mod); |
| 4178 | mod->ctx = st->ctx; |
| 4179 | data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 4180 | "<yang-version value=\"1.0\"/>\n" |
| 4181 | "<namespace uri=\"urn:example:foo\"/>\n" |
| 4182 | "<prefix value=\"foo\"/>\n" |
| 4183 | "</module>" |
| 4184 | "<module>"; |
| 4185 | assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EVALID); |
| 4186 | logbuf_assert("Trailing garbage \"<module>\" after module, expected end-of-input. Line number 5."); |
| 4187 | lys_module_free(mod, NULL); |
| 4188 | yin_parser_ctx_free(yin_ctx); |
| 4189 | mod = NULL; |
| 4190 | yin_ctx = NULL; |
| 4191 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4192 | st->finished_correctly = true; |
| 4193 | } |
| 4194 | |
| 4195 | static void |
| 4196 | test_yin_parse_submodule(void **state) |
| 4197 | { |
| 4198 | struct state *st = *state; |
| 4199 | const char *data; |
| 4200 | struct yin_parser_ctx *yin_ctx = NULL; |
| 4201 | struct lysp_submodule *submod = NULL; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4202 | struct lys_parser_ctx main_ctx = {}; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4203 | |
| 4204 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 4205 | "<submodule name=\"asub\"" |
| 4206 | "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"" |
| 4207 | "xmlns:a=\"urn:a\">" |
| 4208 | "<yang-version value=\"1.0\"/>\n" |
| 4209 | "<belongs-to module=\"a\">" |
| 4210 | "<prefix value=\"a_pref\"/>" |
| 4211 | "</belongs-to>" |
| 4212 | "<include module=\"atop\"/>" |
| 4213 | "<feature name=\"fox\"/>" |
| 4214 | "<notification name=\"bar-notif\">" |
| 4215 | "<if-feature name=\"bar\"/>" |
| 4216 | "</notification>" |
| 4217 | "<notification name=\"fox-notif\">" |
| 4218 | "<if-feature name=\"fox\"/>" |
| 4219 | "</notification>" |
| 4220 | "<augment target-node=\"/a_pref:top\">" |
| 4221 | "<if-feature name=\"bar\"/>" |
| 4222 | "<container name=\"bar-sub\"/>" |
| 4223 | "</augment>" |
| 4224 | "<augment target-node=\"/top\">" |
| 4225 | "<container name=\"bar-sub2\"/>" |
| 4226 | "</augment>" |
| 4227 | "</submodule>"; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4228 | assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_SUCCESS); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4229 | lysp_submodule_free(st->ctx, submod); |
| 4230 | yin_parser_ctx_free(yin_ctx); |
| 4231 | yin_ctx = NULL; |
| 4232 | submod = NULL; |
| 4233 | |
| 4234 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4235 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4236 | "<yang-version value=\"1.0\"/>\n" |
| 4237 | "<belongs-to module=\"a\">" |
| 4238 | "<prefix value=\"a_pref\"/>" |
| 4239 | "</belongs-to>" |
| 4240 | "</submodule>"; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4241 | assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_SUCCESS); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4242 | lysp_submodule_free(st->ctx, submod); |
| 4243 | yin_parser_ctx_free(yin_ctx); |
| 4244 | yin_ctx = NULL; |
| 4245 | submod = NULL; |
| 4246 | |
| 4247 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4248 | "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4249 | "</module>"; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4250 | assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_EINVAL); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4251 | logbuf_assert("Input data contains module in situation when a submodule is expected."); |
| 4252 | lysp_submodule_free(st->ctx, submod); |
| 4253 | yin_parser_ctx_free(yin_ctx); |
| 4254 | yin_ctx = NULL; |
| 4255 | submod = NULL; |
| 4256 | |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4257 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 4258 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4259 | "<yang-version value=\"1.0\"/>\n" |
| 4260 | "<belongs-to module=\"a\">" |
| 4261 | "<prefix value=\"a_pref\"/>" |
| 4262 | "</belongs-to>" |
| 4263 | "</submodule>" |
| 4264 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4265 | "<yang-version value=\"1.0\"/>\n" |
| 4266 | "<belongs-to module=\"a\">" |
| 4267 | "<prefix value=\"a_pref\"/>" |
| 4268 | "</belongs-to>" |
| 4269 | "</submodule>"; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4270 | assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_EVALID); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4271 | logbuf_assert("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input. Line number 2."); |
| 4272 | lysp_submodule_free(st->ctx, submod); |
| 4273 | yin_parser_ctx_free(yin_ctx); |
| 4274 | yin_ctx = NULL; |
| 4275 | submod = NULL; |
| 4276 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4277 | st->finished_correctly = true; |
| 4278 | } |
| 4279 | |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 4280 | int |
| 4281 | main(void) |
| 4282 | { |
| 4283 | |
| 4284 | const struct CMUnitTest tests[] = { |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 4285 | cmocka_unit_test_setup_teardown(test_yin_match_keyword, setup_f, teardown_f), |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 4286 | cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f), |
| 4287 | cmocka_unit_test_setup_teardown(test_yin_parse_extension_instance, setup_f, teardown_f), |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 4288 | cmocka_unit_test_setup_teardown(test_yin_parse_content, setup_f, teardown_f), |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 4289 | cmocka_unit_test_setup_teardown(test_validate_value, setup_f, teardown_f), |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 4290 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 4291 | cmocka_unit_test(test_yin_match_argument_name), |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 4292 | cmocka_unit_test_setup_teardown(test_enum_elem, setup_element_test, teardown_element_test), |
| 4293 | cmocka_unit_test_setup_teardown(test_bit_elem, setup_element_test, teardown_element_test), |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 4294 | cmocka_unit_test_setup_teardown(test_meta_elem, setup_element_test, teardown_element_test), |
| 4295 | cmocka_unit_test_setup_teardown(test_import_elem, setup_element_test, teardown_element_test), |
| 4296 | cmocka_unit_test_setup_teardown(test_status_elem, setup_element_test, teardown_element_test), |
| 4297 | cmocka_unit_test_setup_teardown(test_ext_elem, setup_element_test, teardown_element_test), |
| 4298 | cmocka_unit_test_setup_teardown(test_yin_element_elem, setup_element_test, teardown_element_test), |
| 4299 | cmocka_unit_test_setup_teardown(test_yangversion_elem, setup_element_test, teardown_element_test), |
| 4300 | cmocka_unit_test_setup_teardown(test_mandatory_elem, setup_element_test, teardown_element_test), |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 4301 | cmocka_unit_test_setup_teardown(test_argument_elem, setup_element_test, teardown_element_test), |
| 4302 | cmocka_unit_test_setup_teardown(test_base_elem, setup_element_test, teardown_element_test), |
| 4303 | cmocka_unit_test_setup_teardown(test_belongsto_elem, setup_element_test, teardown_element_test), |
| 4304 | cmocka_unit_test_setup_teardown(test_config_elem, setup_element_test, teardown_element_test), |
| 4305 | cmocka_unit_test_setup_teardown(test_default_elem, setup_element_test, teardown_element_test), |
| 4306 | cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup_element_test, teardown_element_test), |
| 4307 | cmocka_unit_test_setup_teardown(test_err_msg_elem, setup_element_test, teardown_element_test), |
| 4308 | cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup_element_test, teardown_element_test), |
| 4309 | cmocka_unit_test_setup_teardown(test_iffeature_elem, setup_element_test, teardown_element_test), |
| 4310 | cmocka_unit_test_setup_teardown(test_length_elem, setup_element_test, teardown_element_test), |
| 4311 | cmocka_unit_test_setup_teardown(test_modifier_elem, setup_element_test, teardown_element_test), |
| 4312 | cmocka_unit_test_setup_teardown(test_namespace_elem, setup_element_test, teardown_element_test), |
| 4313 | cmocka_unit_test_setup_teardown(test_path_elem, setup_element_test, teardown_element_test), |
| 4314 | cmocka_unit_test_setup_teardown(test_pattern_elem, setup_element_test, teardown_element_test), |
| 4315 | cmocka_unit_test_setup_teardown(test_value_position_elem, setup_element_test, teardown_element_test), |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 4316 | cmocka_unit_test_setup_teardown(test_prefix_elem, setup_element_test, teardown_element_test), |
| 4317 | cmocka_unit_test_setup_teardown(test_range_elem, setup_element_test, teardown_element_test), |
| 4318 | cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup_element_test, teardown_element_test), |
| 4319 | cmocka_unit_test_setup_teardown(test_revision_date_elem, setup_element_test, teardown_element_test), |
| 4320 | cmocka_unit_test_setup_teardown(test_unique_elem, setup_element_test, teardown_element_test), |
| 4321 | cmocka_unit_test_setup_teardown(test_units_elem, setup_element_test, teardown_element_test), |
| 4322 | cmocka_unit_test_setup_teardown(test_when_elem, setup_element_test, teardown_element_test), |
| 4323 | cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup_element_test, teardown_element_test), |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 4324 | cmocka_unit_test_setup_teardown(test_type_elem, setup_element_test, teardown_element_test), |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 4325 | cmocka_unit_test_setup_teardown(test_max_elems_elem, setup_element_test, teardown_element_test), |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 4326 | cmocka_unit_test_setup_teardown(test_min_elems_elem, setup_element_test, teardown_element_test), |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 4327 | cmocka_unit_test_setup_teardown(test_ordby_elem, setup_element_test, teardown_element_test), |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 4328 | cmocka_unit_test_setup_teardown(test_any_elem, setup_element_test, teardown_element_test), |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 4329 | cmocka_unit_test_setup_teardown(test_leaf_elem, setup_element_test, teardown_element_test), |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 4330 | cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup_element_test, teardown_element_test), |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 4331 | cmocka_unit_test_setup_teardown(test_presence_elem, setup_element_test, teardown_element_test), |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 4332 | cmocka_unit_test_setup_teardown(test_key_elem, setup_element_test, teardown_element_test), |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 4333 | cmocka_unit_test_setup_teardown(test_typedef_elem, setup_element_test, teardown_element_test), |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 4334 | cmocka_unit_test_setup_teardown(test_refine_elem, setup_element_test, teardown_element_test), |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 4335 | cmocka_unit_test_setup_teardown(test_uses_elem, setup_element_test, teardown_element_test), |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 4336 | cmocka_unit_test_setup_teardown(test_revision_elem, setup_element_test, teardown_element_test), |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 4337 | cmocka_unit_test_setup_teardown(test_include_elem, setup_element_test, teardown_element_test), |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 4338 | cmocka_unit_test_setup_teardown(test_feature_elem, setup_element_test, teardown_element_test), |
David Sedlák | 28794f2 | 2019-07-22 16:45:00 +0200 | [diff] [blame] | 4339 | cmocka_unit_test_setup_teardown(test_identity_elem, setup_element_test, teardown_element_test), |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 4340 | cmocka_unit_test_setup_teardown(test_list_elem, setup_element_test, teardown_element_test), |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 4341 | cmocka_unit_test_setup_teardown(test_notification_elem, setup_element_test, teardown_element_test), |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 4342 | cmocka_unit_test_setup_teardown(test_grouping_elem, setup_element_test, teardown_element_test), |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 4343 | cmocka_unit_test_setup_teardown(test_container_elem, setup_element_test, teardown_element_test), |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 4344 | cmocka_unit_test_setup_teardown(test_case_elem, setup_element_test, teardown_element_test), |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 4345 | cmocka_unit_test_setup_teardown(test_choice_elem, setup_element_test, teardown_element_test), |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 4346 | cmocka_unit_test_setup_teardown(test_inout_elem, setup_element_test, teardown_element_test), |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 4347 | cmocka_unit_test_setup_teardown(test_action_elem, setup_element_test, teardown_element_test), |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 4348 | cmocka_unit_test_setup_teardown(test_augment_elem, setup_element_test, teardown_element_test), |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 4349 | cmocka_unit_test_setup_teardown(test_deviate_elem, setup_element_test, teardown_element_test), |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 4350 | cmocka_unit_test_setup_teardown(test_deviation_elem, setup_element_test, teardown_element_test), |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 4351 | cmocka_unit_test_setup_teardown(test_module_elem, setup_element_test, teardown_element_test), |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4352 | cmocka_unit_test_setup_teardown(test_submodule_elem, setup_element_test, teardown_element_test), |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4353 | |
| 4354 | cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_logger, teardown_logger), |
| 4355 | cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup_logger, teardown_logger), |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 4356 | }; |
| 4357 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 4358 | return cmocka_run_group_tests(tests, setup_ly_ctx, destroy_ly_ctx); |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 4359 | } |