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 | |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 24 | #include "common.h" |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 25 | #include "in.h" |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 26 | #include "parser_internal.h" |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 27 | #include "tree_schema.h" |
| 28 | #include "tree_schema_internal.h" |
| 29 | #include "xml.h" |
| 30 | #include "xpath.h" |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 31 | |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 32 | /* copied from parser_yin.c */ |
| 33 | enum yin_argument { |
| 34 | YIN_ARG_UNKNOWN = 0, /**< parsed argument can not be matched with any supported yin argument keyword */ |
| 35 | YIN_ARG_NAME, /**< argument name */ |
| 36 | YIN_ARG_TARGET_NODE, /**< argument target-node */ |
| 37 | YIN_ARG_MODULE, /**< argument module */ |
| 38 | YIN_ARG_VALUE, /**< argument value */ |
| 39 | YIN_ARG_TEXT, /**< argument text */ |
| 40 | YIN_ARG_CONDITION, /**< argument condition */ |
| 41 | YIN_ARG_URI, /**< argument uri */ |
| 42 | YIN_ARG_DATE, /**< argument data */ |
| 43 | YIN_ARG_TAG, /**< argument tag */ |
| 44 | YIN_ARG_NONE /**< empty (special value) */ |
| 45 | }; |
| 46 | |
| 47 | struct yin_subelement { |
| 48 | enum ly_stmt type; /**< type of keyword */ |
| 49 | void *dest; /**< meta infromation passed to responsible function (mostly information about where parsed subelement should be stored) */ |
| 50 | uint16_t flags; /**< describes constraints of subelement can be set to YIN_SUBELEM_MANDATORY, YIN_SUBELEM_UNIQUE, YIN_SUBELEM_FIRST, YIN_SUBELEM_VER2, and YIN_SUBELEM_DEFAULT_TEXT */ |
| 51 | }; |
| 52 | |
| 53 | struct import_meta { |
| 54 | const char *prefix; /**< module prefix. */ |
| 55 | struct lysp_import **imports; /**< imports to add to. */ |
| 56 | }; |
| 57 | |
| 58 | struct yin_argument_meta { |
| 59 | uint16_t *flags; /**< Argument flags */ |
| 60 | const char **argument; /**< Argument value */ |
| 61 | }; |
| 62 | |
| 63 | struct tree_node_meta { |
| 64 | struct lysp_node *parent; /**< parent node */ |
| 65 | struct lysp_node **nodes; /**< linked list of siblings */ |
| 66 | }; |
| 67 | |
| 68 | struct include_meta { |
| 69 | const char *name; /**< Module/submodule name. */ |
| 70 | struct lysp_include **includes; /**< [Sized array](@ref sizedarrays) of parsed includes to add to. */ |
| 71 | }; |
| 72 | |
| 73 | struct inout_meta { |
| 74 | struct lysp_node *parent; /**< Parent node. */ |
| 75 | struct lysp_action_inout *inout_p; /**< inout_p Input/output pointer to write to. */ |
| 76 | }; |
| 77 | |
| 78 | struct minmax_dev_meta { |
| 79 | uint32_t *lim; /**< min/max value to write to. */ |
| 80 | uint16_t *flags; /**< min/max flags to write to. */ |
| 81 | struct lysp_ext_instance **exts; /**< extension instances to add to. */ |
| 82 | }; |
| 83 | |
| 84 | #define YIN_SUBELEM_MANDATORY 0x01 |
| 85 | #define YIN_SUBELEM_UNIQUE 0x02 |
| 86 | #define YIN_SUBELEM_FIRST 0x04 |
| 87 | #define YIN_SUBELEM_VER2 0x08 |
| 88 | |
| 89 | #define YIN_SUBELEM_PARSED 0x80 |
| 90 | |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 91 | /* prototypes of static functions */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 92 | enum yin_argument yin_match_argument_name(const char *name, size_t len); |
| 93 | LY_ERR yin_parse_content(struct lys_yin_parser_ctx *ctx, struct yin_subelement *subelem_info, size_t subelem_info_size, |
| 94 | enum ly_stmt current_element, const char **text_content, struct lysp_ext_instance **exts); |
| 95 | LY_ERR yin_validate_value(struct lys_yin_parser_ctx *ctx, enum yang_arg val_type); |
| 96 | enum ly_stmt yin_match_keyword(struct lys_yin_parser_ctx *ctx, const char *name, size_t name_len, |
| 97 | const char *prefix, size_t prefix_len, enum ly_stmt parrent); |
| 98 | LY_ERR yin_parse_extension_instance(struct lys_yin_parser_ctx *ctx, LYEXT_SUBSTMT subelem, LY_ARRAY_COUNT_TYPE subelem_index, |
| 99 | struct lysp_ext_instance **exts); |
| 100 | LY_ERR yin_parse_element_generic(struct lys_yin_parser_ctx *ctx, enum ly_stmt parent, struct lysp_stmt **element); |
| 101 | LY_ERR yin_parse_mod(struct lys_yin_parser_ctx *ctx, struct lysp_module *mod); |
| 102 | LY_ERR yin_parse_submod(struct lys_yin_parser_ctx *ctx, struct lysp_submodule *submod); |
| 103 | |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 104 | 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] | 105 | 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] | 106 | 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] | 107 | 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] | 108 | 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] | 109 | 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] | 110 | 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] | 111 | 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] | 112 | 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] | 113 | 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] | 114 | 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] | 115 | 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] | 116 | 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] | 117 | 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] | 118 | 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] | 119 | 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] | 120 | 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] | 121 | 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] | 122 | 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] | 123 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 124 | /* wrapping element used for mocking has nothing to do with real module structure */ |
| 125 | #define ELEMENT_WRAPPER_START "<status xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 126 | #define ELEMENT_WRAPPER_END "</status>" |
| 127 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 128 | struct test_parser_yin_state { |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 129 | struct ly_ctx *ctx; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 130 | struct lys_yin_parser_ctx *yin_ctx; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 131 | struct ly_in *in; |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 132 | bool finished_correctly; |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 133 | }; |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 134 | |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 135 | #define BUFSIZE 1024 |
| 136 | char logbuf[BUFSIZE] = {0}; |
| 137 | int store = -1; /* negative for infinite logging, positive for limited logging */ |
| 138 | |
| 139 | /* set to 0 to printing error messages to stderr instead of checking them in code */ |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 140 | #define ENABLE_LOGGER_CHECKING 1 |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 141 | |
| 142 | #if ENABLE_LOGGER_CHECKING |
| 143 | static void |
| 144 | logger(LY_LOG_LEVEL level, const char *msg, const char *path) |
| 145 | { |
| 146 | (void) level; /* unused */ |
| 147 | if (store) { |
| 148 | if (path && path[0]) { |
| 149 | snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path); |
| 150 | } else { |
| 151 | strncpy(logbuf, msg, BUFSIZE - 1); |
| 152 | } |
| 153 | if (store > 0) { |
| 154 | --store; |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | #endif |
| 159 | |
| 160 | #if ENABLE_LOGGER_CHECKING |
| 161 | # define logbuf_assert(str) assert_string_equal(logbuf, str) |
| 162 | #else |
| 163 | # define logbuf_assert(str) |
| 164 | #endif |
| 165 | |
| 166 | #define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \ |
| 167 | str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 168 | assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \ |
| 169 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \ |
| 170 | CLEANUP |
| 171 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 172 | int |
| 173 | setup_ly_ctx(void **state) |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 174 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 175 | struct test_parser_yin_state *st = NULL; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 176 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 177 | /* allocate state variable */ |
| 178 | (*state) = st = calloc(1, sizeof(*st)); |
| 179 | if (!st) { |
| 180 | fprintf(stderr, "Memmory allocation failed"); |
| 181 | return EXIT_FAILURE; |
| 182 | } |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 183 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 184 | /* create new libyang context */ |
| 185 | ly_ctx_new(NULL, 0, &st->ctx); |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 186 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 187 | return EXIT_SUCCESS; |
| 188 | } |
| 189 | |
| 190 | int |
| 191 | destroy_ly_ctx(void **state) |
| 192 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 193 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 194 | ly_ctx_destroy(st->ctx, NULL); |
| 195 | free(st); |
| 196 | |
| 197 | return EXIT_SUCCESS; |
| 198 | } |
| 199 | |
| 200 | static int |
| 201 | setup_f(void **state) |
| 202 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 203 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 204 | |
| 205 | #if ENABLE_LOGGER_CHECKING |
| 206 | /* setup logger */ |
| 207 | ly_set_log_clb(logger, 1); |
| 208 | #endif |
| 209 | |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 210 | /* allocate parser context */ |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 211 | st->yin_ctx = calloc(1, sizeof(*st->yin_ctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 212 | st->yin_ctx->format = LYS_IN_YIN; |
David Sedlák | 8f5bce0 | 2019-06-03 16:41:08 +0200 | [diff] [blame] | 213 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 214 | /* allocate new parsed module */ |
| 215 | st->yin_ctx->parsed_mod = calloc(1, sizeof *st->yin_ctx->parsed_mod); |
| 216 | |
| 217 | /* allocate new module */ |
| 218 | st->yin_ctx->parsed_mod->mod = calloc(1, sizeof *st->yin_ctx->parsed_mod->mod); |
| 219 | st->yin_ctx->parsed_mod->mod->ctx = st->ctx; |
| 220 | st->yin_ctx->parsed_mod->mod->parsed = st->yin_ctx->parsed_mod; |
| 221 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 222 | st->in = NULL; |
| 223 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 224 | return EXIT_SUCCESS; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | static int |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 228 | teardown_f(void **state) |
| 229 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 230 | struct test_parser_yin_state *st = *(struct test_parser_yin_state **)state; |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 231 | |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 232 | #if ENABLE_LOGGER_CHECKING |
| 233 | /* teardown logger */ |
| 234 | if (!st->finished_correctly && logbuf[0] != '\0') { |
| 235 | fprintf(stderr, "%s\n", logbuf); |
| 236 | } |
| 237 | #endif |
| 238 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 239 | lyxml_ctx_free(st->yin_ctx->xmlctx); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 240 | lys_module_free(st->yin_ctx->parsed_mod->mod, NULL); |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 241 | free(st->yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 242 | ly_in_free(st->in, 0); |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 243 | |
| 244 | return EXIT_SUCCESS; |
| 245 | } |
| 246 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 247 | static struct test_parser_yin_state* |
David Sedlák | 392af4f | 2019-06-04 16:02:42 +0200 | [diff] [blame] | 248 | reset_state(void **state) |
| 249 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 250 | ((struct test_parser_yin_state *)*state)->finished_correctly = true; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 251 | logbuf[0] = '\0'; |
David Sedlák | 392af4f | 2019-06-04 16:02:42 +0200 | [diff] [blame] | 252 | teardown_f(state); |
| 253 | setup_f(state); |
| 254 | |
| 255 | return *state; |
| 256 | } |
| 257 | |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 258 | void |
| 259 | logbuf_clean(void) |
| 260 | { |
| 261 | logbuf[0] = '\0'; |
| 262 | } |
| 263 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 264 | static int |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 265 | setup_element_test(void **state) |
| 266 | { |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 267 | struct test_parser_yin_state *st; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 268 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 269 | setup_f(state); |
| 270 | st = *state; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 271 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 272 | lydict_insert(st->ctx, "module-name", 0, &st->yin_ctx->parsed_mod->mod->name); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 273 | |
| 274 | return EXIT_SUCCESS; |
| 275 | } |
| 276 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 277 | static void |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 278 | test_yin_match_keyword(void **state) |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 279 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 280 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 281 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 282 | const char *prefix; |
| 283 | size_t prefix_len; |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 284 | /* create mock yin namespace in xml context */ |
| 285 | const char *data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 286 | ly_in_new_memory(data, &st->in); |
| 287 | lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 288 | prefix = st->yin_ctx->xmlctx->prefix; |
| 289 | prefix_len = st->yin_ctx->xmlctx->prefix_len; |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 290 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 291 | assert_int_equal(yin_match_keyword(st->yin_ctx, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE); |
| 292 | assert_int_equal(yin_match_keyword(st->yin_ctx, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE); |
| 293 | assert_int_equal(yin_match_keyword(st->yin_ctx, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE); |
| 294 | assert_int_equal(yin_match_keyword(st->yin_ctx, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA); |
| 295 | assert_int_equal(yin_match_keyword(st->yin_ctx, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML); |
| 296 | assert_int_equal(yin_match_keyword(st->yin_ctx, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT); |
| 297 | assert_int_equal(yin_match_keyword(st->yin_ctx, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT); |
| 298 | assert_int_equal(yin_match_keyword(st->yin_ctx, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE); |
| 299 | assert_int_equal(yin_match_keyword(st->yin_ctx, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO); |
| 300 | assert_int_equal(yin_match_keyword(st->yin_ctx, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT); |
| 301 | assert_int_equal(yin_match_keyword(st->yin_ctx, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE); |
| 302 | assert_int_equal(yin_match_keyword(st->yin_ctx, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE); |
| 303 | assert_int_equal(yin_match_keyword(st->yin_ctx, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG); |
| 304 | assert_int_equal(yin_match_keyword(st->yin_ctx, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT); |
| 305 | assert_int_equal(yin_match_keyword(st->yin_ctx, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER); |
| 306 | assert_int_equal(yin_match_keyword(st->yin_ctx, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT); |
| 307 | assert_int_equal(yin_match_keyword(st->yin_ctx, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION); |
| 308 | assert_int_equal(yin_match_keyword(st->yin_ctx, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE); |
| 309 | assert_int_equal(yin_match_keyword(st->yin_ctx, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION); |
| 310 | assert_int_equal(yin_match_keyword(st->yin_ctx, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM); |
| 311 | assert_int_equal(yin_match_keyword(st->yin_ctx, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_APP_TAG); |
| 312 | assert_int_equal(yin_match_keyword(st->yin_ctx, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE); |
| 313 | assert_int_equal(yin_match_keyword(st->yin_ctx, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION); |
| 314 | assert_int_equal(yin_match_keyword(st->yin_ctx, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE); |
| 315 | assert_int_equal(yin_match_keyword(st->yin_ctx, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS); |
| 316 | assert_int_equal(yin_match_keyword(st->yin_ctx, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING); |
| 317 | assert_int_equal(yin_match_keyword(st->yin_ctx, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY); |
| 318 | assert_int_equal(yin_match_keyword(st->yin_ctx, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE); |
| 319 | assert_int_equal(yin_match_keyword(st->yin_ctx, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT); |
| 320 | assert_int_equal(yin_match_keyword(st->yin_ctx, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE); |
| 321 | assert_int_equal(yin_match_keyword(st->yin_ctx, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT); |
| 322 | assert_int_equal(yin_match_keyword(st->yin_ctx, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY); |
| 323 | assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF); |
| 324 | assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST); |
| 325 | assert_int_equal(yin_match_keyword(st->yin_ctx, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH); |
| 326 | assert_int_equal(yin_match_keyword(st->yin_ctx, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST); |
| 327 | assert_int_equal(yin_match_keyword(st->yin_ctx, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY); |
| 328 | assert_int_equal(yin_match_keyword(st->yin_ctx, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS); |
| 329 | assert_int_equal(yin_match_keyword(st->yin_ctx, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS); |
| 330 | assert_int_equal(yin_match_keyword(st->yin_ctx, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER); |
| 331 | assert_int_equal(yin_match_keyword(st->yin_ctx, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE); |
| 332 | assert_int_equal(yin_match_keyword(st->yin_ctx, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST); |
| 333 | assert_int_equal(yin_match_keyword(st->yin_ctx, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE); |
| 334 | assert_int_equal(yin_match_keyword(st->yin_ctx, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION); |
| 335 | assert_int_equal(yin_match_keyword(st->yin_ctx, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY); |
| 336 | assert_int_equal(yin_match_keyword(st->yin_ctx, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION); |
| 337 | assert_int_equal(yin_match_keyword(st->yin_ctx, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT); |
| 338 | assert_int_equal(yin_match_keyword(st->yin_ctx, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH); |
| 339 | assert_int_equal(yin_match_keyword(st->yin_ctx, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN); |
| 340 | assert_int_equal(yin_match_keyword(st->yin_ctx, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION); |
| 341 | assert_int_equal(yin_match_keyword(st->yin_ctx, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX); |
| 342 | assert_int_equal(yin_match_keyword(st->yin_ctx, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE); |
| 343 | assert_int_equal(yin_match_keyword(st->yin_ctx, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE); |
| 344 | assert_int_equal(yin_match_keyword(st->yin_ctx, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE); |
| 345 | assert_int_equal(yin_match_keyword(st->yin_ctx, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE); |
| 346 | assert_int_equal(yin_match_keyword(st->yin_ctx, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE); |
| 347 | assert_int_equal(yin_match_keyword(st->yin_ctx, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION); |
| 348 | assert_int_equal(yin_match_keyword(st->yin_ctx, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE); |
| 349 | assert_int_equal(yin_match_keyword(st->yin_ctx, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC); |
| 350 | assert_int_equal(yin_match_keyword(st->yin_ctx, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS); |
| 351 | assert_int_equal(yin_match_keyword(st->yin_ctx, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE); |
| 352 | assert_int_equal(yin_match_keyword(st->yin_ctx, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE); |
| 353 | assert_int_equal(yin_match_keyword(st->yin_ctx, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF); |
| 354 | assert_int_equal(yin_match_keyword(st->yin_ctx, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE); |
| 355 | assert_int_equal(yin_match_keyword(st->yin_ctx, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS); |
| 356 | assert_int_equal(yin_match_keyword(st->yin_ctx, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES); |
| 357 | assert_int_equal(yin_match_keyword(st->yin_ctx, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE); |
| 358 | assert_int_equal(yin_match_keyword(st->yin_ctx, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN); |
| 359 | assert_int_equal(yin_match_keyword(st->yin_ctx, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION); |
| 360 | assert_int_equal(yin_match_keyword(st->yin_ctx, "yin-element", strlen("yin-element"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YIN_ELEMENT); |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 361 | |
| 362 | st->finished_correctly = true; |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 363 | } |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 364 | |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 365 | static void |
David Sedlák | 060b00e | 2019-06-19 11:12:06 +0200 | [diff] [blame] | 366 | test_yin_match_argument_name(void **state) |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 367 | { |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 368 | (void)state; /* unused */ |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 369 | |
David Sedlák | 060b00e | 2019-06-19 11:12:06 +0200 | [diff] [blame] | 370 | assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN); |
| 371 | assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN); |
| 372 | assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN); |
| 373 | assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION); |
| 374 | assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE); |
| 375 | assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE); |
| 376 | assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME); |
| 377 | assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG); |
| 378 | assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE); |
| 379 | assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT); |
| 380 | assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI); |
| 381 | 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] | 382 | } |
| 383 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 384 | static void |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 385 | test_yin_parse_element_generic(void **state) |
| 386 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 387 | struct test_parser_yin_state *st = *state; |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 388 | struct lysp_ext_instance exts; |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 389 | LY_ERR ret; |
| 390 | |
| 391 | memset(&exts, 0, sizeof(exts)); |
| 392 | |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 393 | const char *data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 394 | ly_in_new_memory(data, &st->in); |
| 395 | lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 396 | |
| 397 | ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 398 | assert_int_equal(ret, LY_SUCCESS); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 399 | assert_int_equal(st->yin_ctx->xmlctx->status, LYXML_ELEM_CLOSE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 400 | assert_string_equal(exts.child->stmt, "urn:example:extensions:elem"); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 401 | assert_string_equal(exts.child->arg, "text_value"); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 402 | assert_string_equal(exts.child->child->stmt, "attr"); |
| 403 | assert_string_equal(exts.child->child->arg, "value"); |
| 404 | assert_true(exts.child->child->flags & LYS_YIN_ATTR); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 405 | lysp_ext_instance_free(st->ctx, &exts); |
David Sedlák | 5392a21 | 2019-07-01 09:19:10 +0200 | [diff] [blame] | 406 | st = reset_state(state); |
| 407 | |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 408 | data = "<myext:elem xmlns:myext=\"urn:example:extensions\"></myext:elem>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 409 | ly_in_new_memory(data, &st->in); |
| 410 | lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 411 | |
| 412 | ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child); |
David Sedlák | 5392a21 | 2019-07-01 09:19:10 +0200 | [diff] [blame] | 413 | assert_int_equal(ret, LY_SUCCESS); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 414 | assert_int_equal(st->yin_ctx->xmlctx->status, LYXML_ELEM_CLOSE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 415 | assert_string_equal(exts.child->stmt, "urn:example:extensions:elem"); |
David Sedlák | 5392a21 | 2019-07-01 09:19:10 +0200 | [diff] [blame] | 416 | assert_null(exts.child->child); |
| 417 | assert_null(exts.child->arg); |
| 418 | lysp_ext_instance_free(st->ctx, &exts); |
| 419 | |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 420 | st->finished_correctly = true; |
| 421 | } |
| 422 | |
| 423 | static void |
| 424 | test_yin_parse_extension_instance(void **state) |
| 425 | { |
| 426 | LY_ERR ret; |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 427 | struct test_parser_yin_state *st = *state; |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 428 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 429 | const char *data = "<myext:ext value1=\"test\" value=\"test2\" xmlns:myext=\"urn:example:extensions\"><myext:subelem>text</myext:subelem></myext:ext>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 430 | ly_in_new_memory(data, &st->in); |
| 431 | lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 432 | |
| 433 | ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 434 | assert_int_equal(ret, LY_SUCCESS); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 435 | assert_string_equal(exts->name, "urn:example:extensions:ext"); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 436 | assert_int_equal(exts->insubstmt_index, 0); |
| 437 | assert_true(exts->insubstmt == LYEXT_SUBSTMT_CONTACT); |
| 438 | assert_true(exts->yin & LYS_YIN); |
| 439 | assert_string_equal(exts->child->stmt, "value1"); |
| 440 | assert_string_equal(exts->child->arg, "test"); |
| 441 | assert_null(exts->child->child); |
| 442 | assert_true(exts->child->flags & LYS_YIN_ATTR); |
| 443 | assert_string_equal(exts->child->next->stmt, "value"); |
| 444 | assert_string_equal(exts->child->next->arg, "test2"); |
| 445 | assert_null(exts->child->next->child); |
| 446 | assert_true(exts->child->next->flags & LYS_YIN_ATTR); |
| 447 | |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 448 | assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:subelem"); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 449 | assert_string_equal(exts->child->next->next->arg, "text"); |
| 450 | assert_null(exts->child->next->next->child); |
| 451 | assert_null(exts->child->next->next->next); |
| 452 | assert_false(exts->child->next->next->flags & LYS_YIN_ATTR); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 453 | lysp_ext_instance_free(st->ctx, exts); |
| 454 | LY_ARRAY_FREE(exts); |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 455 | exts = NULL; |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 456 | st = reset_state(state); |
| 457 | |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 458 | data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" />"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 459 | ly_in_new_memory(data, &st->in); |
| 460 | lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 461 | |
| 462 | ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts); |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 463 | assert_int_equal(ret, LY_SUCCESS); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 464 | assert_string_equal(exts->name, "urn:example:extensions:extension-elem"); |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 465 | assert_null(exts->argument); |
| 466 | assert_null(exts->child); |
| 467 | assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT); |
| 468 | assert_int_equal(exts->insubstmt_index, 0); |
| 469 | assert_true(exts->yin & LYS_YIN); |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 470 | lysp_ext_instance_free(st->ctx, exts); |
| 471 | LY_ARRAY_FREE(exts); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 472 | exts = NULL; |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 473 | st = reset_state(state); |
| 474 | |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 475 | data = "<myext:ext attr1=\"text1\" attr2=\"text2\" xmlns:myext=\"urn:example:extensions\">" |
| 476 | "<myext:ext-sub1/>" |
| 477 | "<myext:ext-sub2 sattr1=\"stext2\">" |
| 478 | "<myext:ext-sub21>" |
| 479 | "<myext:ext-sub211 sattr21=\"text21\"/>" |
| 480 | "</myext:ext-sub21>" |
| 481 | "</myext:ext-sub2>" |
| 482 | "<myext:ext-sub3 attr3=\"text3\"></myext:ext-sub3>" |
| 483 | "</myext:ext>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 484 | ly_in_new_memory(data, &st->in); |
| 485 | lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 486 | |
| 487 | ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 488 | assert_int_equal(ret, LY_SUCCESS); |
| 489 | |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 490 | assert_string_equal(exts->name, "urn:example:extensions:ext"); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 491 | assert_null(exts->argument); |
| 492 | assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT); |
| 493 | assert_int_equal(exts->insubstmt_index, 0); |
| 494 | assert_true(exts->yin & LYS_YIN); |
| 495 | assert_string_equal(exts->child->stmt, "attr1"); |
| 496 | assert_string_equal(exts->child->arg, "text1"); |
| 497 | assert_null(exts->child->child); |
| 498 | assert_true(exts->child->flags & LYS_YIN_ATTR); |
| 499 | |
| 500 | assert_string_equal(exts->child->next->stmt, "attr2"); |
| 501 | assert_string_equal(exts->child->next->arg, "text2"); |
| 502 | assert_null(exts->child->next->child); |
| 503 | assert_true(exts->child->next->flags & LYS_YIN_ATTR); |
| 504 | |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 505 | assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:ext-sub1"); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 506 | assert_null(exts->child->next->next->arg); |
| 507 | assert_null(exts->child->next->next->child); |
| 508 | assert_int_equal(exts->child->next->next->flags, 0); |
| 509 | |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 510 | assert_string_equal(exts->child->next->next->next->stmt, "urn:example:extensions:ext-sub2"); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 511 | assert_null(exts->child->next->next->next->arg); |
| 512 | assert_int_equal(exts->child->next->next->next->flags, 0); |
| 513 | assert_string_equal(exts->child->next->next->next->child->stmt, "sattr1"); |
| 514 | assert_string_equal(exts->child->next->next->next->child->arg, "stext2"); |
| 515 | assert_null(exts->child->next->next->next->child->child); |
| 516 | assert_true(exts->child->next->next->next->child->flags & LYS_YIN_ATTR); |
| 517 | |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 518 | assert_string_equal(exts->child->next->next->next->child->next->stmt, "urn:example:extensions:ext-sub21"); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 519 | assert_null(exts->child->next->next->next->child->next->arg); |
| 520 | assert_null(exts->child->next->next->next->child->next->next); |
| 521 | assert_int_equal(exts->child->next->next->next->child->next->flags, 0); |
| 522 | |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 523 | assert_string_equal(exts->child->next->next->next->child->next->child->stmt, "urn:example:extensions:ext-sub211"); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 524 | assert_null(exts->child->next->next->next->child->next->child->arg); |
| 525 | assert_int_equal(exts->child->next->next->next->child->next->child->flags, 0); |
| 526 | assert_null(exts->child->next->next->next->child->next->child->next); |
| 527 | |
| 528 | assert_string_equal(exts->child->next->next->next->child->next->child->child->stmt, "sattr21"); |
| 529 | assert_string_equal(exts->child->next->next->next->child->next->child->child->arg, "text21"); |
| 530 | assert_null(exts->child->next->next->next->child->next->child->child->next); |
| 531 | assert_null(exts->child->next->next->next->child->next->child->child->child); |
| 532 | assert_true(exts->child->next->next->next->child->next->child->child->flags & LYS_YIN_ATTR); |
| 533 | |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 534 | assert_string_equal(exts->child->next->next->next->next->stmt, "urn:example:extensions:ext-sub3"); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 535 | assert_null(exts->child->next->next->next->next->arg); |
| 536 | assert_null(exts->child->next->next->next->next->next); |
| 537 | assert_int_equal(exts->child->next->next->next->next->flags, 0); |
| 538 | |
| 539 | assert_string_equal(exts->child->next->next->next->next->child->stmt, "attr3"); |
| 540 | assert_string_equal(exts->child->next->next->next->next->child->arg, "text3"); |
| 541 | assert_null(exts->child->next->next->next->next->child->next); |
| 542 | assert_null(exts->child->next->next->next->next->child->child); |
| 543 | assert_true(exts->child->next->next->next->next->child->flags & LYS_YIN_ATTR); |
| 544 | |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 545 | lysp_ext_instance_free(st->ctx, exts); |
| 546 | LY_ARRAY_FREE(exts); |
| 547 | exts = NULL; |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 548 | st = reset_state(state); |
| 549 | |
| 550 | data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" xmlns:yin=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 551 | "<yin:action name=\"act-name\" pre:prefixed=\"ignored\"/>" |
| 552 | "<yin:augment target-node=\"target\"/>" |
| 553 | "<yin:status value=\"value\"/>" |
| 554 | "<yin:include module=\"mod\"/>" |
| 555 | "<yin:input />" |
| 556 | "<yin:must condition=\"cond\"/>" |
| 557 | "<yin:namespace uri=\"uri\"/>" |
| 558 | "<yin:revision date=\"data\"/>" |
| 559 | "<yin:unique tag=\"tag\"/>" |
David Sedlák | d284488 | 2019-09-13 16:01:22 +0200 | [diff] [blame] | 560 | "<yin:description><yin:text>contact-val</yin:text></yin:description>" |
| 561 | "<yin:error-message><yin:value>err-msg</yin:value></yin:error-message>" |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 562 | "</myext:extension-elem>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 563 | ly_in_new_memory(data, &st->in); |
| 564 | lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 565 | |
| 566 | ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts); |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 567 | assert_int_equal(ret, LY_SUCCESS); |
| 568 | assert_string_equal(exts->child->arg, "act-name"); |
| 569 | assert_string_equal(exts->child->next->arg, "target"); |
| 570 | assert_string_equal(exts->child->next->next->arg, "value"); |
| 571 | assert_string_equal(exts->child->next->next->next->arg, "mod"); |
| 572 | assert_null(exts->child->next->next->next->next->arg); |
| 573 | assert_string_equal(exts->child->next->next->next->next->next->arg, "cond"); |
| 574 | assert_string_equal(exts->child->next->next->next->next->next->next->arg, "uri"); |
| 575 | assert_string_equal(exts->child->next->next->next->next->next->next->next->arg, "data"); |
| 576 | assert_string_equal(exts->child->next->next->next->next->next->next->next->next->arg, "tag"); |
| 577 | assert_string_equal(exts->child->next->next->next->next->next->next->next->next->next->arg, "contact-val"); |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 578 | lysp_ext_instance_free(st->ctx, exts); |
| 579 | LY_ARRAY_FREE(exts); |
| 580 | exts = NULL; |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 581 | st = reset_state(state); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 582 | |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 583 | st->finished_correctly = true; |
| 584 | } |
| 585 | |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 586 | static void |
| 587 | test_yin_parse_content(void **state) |
| 588 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 589 | struct test_parser_yin_state *st = *state; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 590 | LY_ERR ret = LY_SUCCESS; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 591 | const char *data = "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 592 | "<myext:custom xmlns:myext=\"urn:example:extensions\">" |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 593 | "totally amazing extension" |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 594 | "</myext:custom>" |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 595 | "<extension name=\"ext\">" |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 596 | "<argument name=\"argname\"></argument>" |
| 597 | "<description><text>desc</text></description>" |
| 598 | "<reference><text>ref</text></reference>" |
| 599 | "<status value=\"deprecated\"></status>" |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 600 | "</extension>" |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 601 | "<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] | 602 | "<if-feature name=\"foo\"></if-feature>" |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 603 | "<when condition=\"condition...\">" |
| 604 | "<reference><text>when_ref</text></reference>" |
| 605 | "<description><text>when_desc</text></description>" |
| 606 | "</when>" |
David Sedlák | e1a3030 | 2019-07-10 13:49:38 +0200 | [diff] [blame] | 607 | "<config value=\"true\"/>" |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 608 | "<error-message>" |
| 609 | "<value>error-msg</value>" |
| 610 | "</error-message>" |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 611 | "<error-app-tag value=\"err-app-tag\"/>" |
David Sedlák | a5b1d38 | 2019-07-10 16:31:09 +0200 | [diff] [blame] | 612 | "<units name=\"radians\"></units>" |
David Sedlák | e7084ce | 2019-07-10 16:44:15 +0200 | [diff] [blame] | 613 | "<default value=\"default-value\"/>" |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 614 | "<position value=\"25\"></position>" |
| 615 | "<value value=\"-5\"/>" |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 616 | "<require-instance value=\"true\"></require-instance>" |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 617 | "<range value=\"5..10\" />" |
David Sedlák | 438ae43 | 2019-07-11 15:36:54 +0200 | [diff] [blame] | 618 | "<length value=\"baf\"/>" |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 619 | "<pattern value='pattern'>" |
| 620 | "<modifier value='invert-match'/>" |
| 621 | "</pattern>" |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 622 | "<enum name=\"yay\">" |
| 623 | "</enum>" |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 624 | "</prefix>"; |
| 625 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 626 | const char **if_features = NULL; |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 627 | const char *value, *err_msg, *app_tag, *units; |
| 628 | struct lysp_qname def = {0}; |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 629 | struct lysp_ext *ext_def = NULL; |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 630 | struct lysp_when *when_p = NULL; |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 631 | struct lysp_type_enum pos_enum = {}, val_enum = {}; |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 632 | struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {}; |
Juraj Vijtiuk | f6a0737 | 2020-10-29 21:13:33 +0100 | [diff] [blame] | 633 | uint16_t config = 0; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 634 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 635 | ly_in_new_memory(data, &st->in); |
| 636 | lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 637 | lyxml_ctx_next(st->yin_ctx->xmlctx); |
| 638 | lyxml_ctx_next(st->yin_ctx->xmlctx); |
| 639 | lyxml_ctx_next(st->yin_ctx->xmlctx); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 640 | |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 641 | struct yin_subelement subelems[17] = { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 642 | {LY_STMT_CONFIG, &config, 0}, |
| 643 | {LY_STMT_DEFAULT, &def, YIN_SUBELEM_UNIQUE}, |
| 644 | {LY_STMT_ENUM, &enum_type, 0}, |
| 645 | {LY_STMT_ERROR_APP_TAG, &app_tag, YIN_SUBELEM_UNIQUE}, |
| 646 | {LY_STMT_ERROR_MESSAGE, &err_msg, 0}, |
| 647 | {LY_STMT_EXTENSION, &ext_def, 0}, |
| 648 | {LY_STMT_IF_FEATURE, &if_features, 0}, |
| 649 | {LY_STMT_LENGTH, &len_type, 0}, |
| 650 | {LY_STMT_PATTERN, &patter_type, 0}, |
| 651 | {LY_STMT_POSITION, &pos_enum, 0}, |
| 652 | {LY_STMT_RANGE, &range_type, 0}, |
| 653 | {LY_STMT_REQUIRE_INSTANCE, &req_type, 0}, |
| 654 | {LY_STMT_UNITS, &units, YIN_SUBELEM_UNIQUE}, |
| 655 | {LY_STMT_VALUE, &val_enum, 0}, |
| 656 | {LY_STMT_WHEN, &when_p, 0}, |
| 657 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 658 | {LY_STMT_ARG_TEXT, &value, 0} |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 659 | }; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 660 | ret = yin_parse_content(st->yin_ctx, subelems, 17, LY_STMT_PREFIX, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 661 | assert_int_equal(ret, LY_SUCCESS); |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 662 | /* check parsed values */ |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 663 | assert_string_equal(def.str, "default-value"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 664 | assert_string_equal(exts->name, "urn:example:extensions:custom"); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 665 | assert_string_equal(exts->argument, "totally amazing extension"); |
| 666 | assert_string_equal(value, "wsefsdf"); |
David Sedlák | a5b1d38 | 2019-07-10 16:31:09 +0200 | [diff] [blame] | 667 | assert_string_equal(units, "radians"); |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 668 | assert_string_equal(when_p->cond, "condition..."); |
| 669 | assert_string_equal(when_p->dsc, "when_desc"); |
| 670 | assert_string_equal(when_p->ref, "when_ref"); |
David Sedlák | e1a3030 | 2019-07-10 13:49:38 +0200 | [diff] [blame] | 671 | assert_int_equal(config, LYS_CONFIG_W); |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 672 | assert_int_equal(pos_enum.value, 25); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 673 | assert_true(pos_enum.flags & LYS_SET_VALUE); |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 674 | assert_int_equal(val_enum.value, -5); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 675 | assert_true(val_enum.flags & LYS_SET_VALUE); |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 676 | assert_int_equal(req_type.require_instance, 1); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 677 | assert_true(req_type.flags &= LYS_SET_REQINST); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 678 | assert_string_equal(range_type.range->arg.str, "5..10"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 679 | assert_true(range_type.flags & LYS_SET_RANGE); |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 680 | assert_string_equal(err_msg, "error-msg"); |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 681 | assert_string_equal(app_tag, "err-app-tag"); |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 682 | assert_string_equal(enum_type.enums->name, "yay"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 683 | assert_string_equal(len_type.length->arg.str, "baf"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 684 | assert_true(len_type.flags & LYS_SET_LENGTH); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 685 | assert_string_equal(patter_type.patterns->arg.str, "\x015pattern"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 686 | assert_true(patter_type.flags & LYS_SET_PATTERN); |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 687 | /* cleanup */ |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 688 | lysp_ext_instance_free(st->ctx, exts); |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 689 | lysp_when_free(st->ctx, when_p); |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 690 | lysp_ext_free(st->ctx, ext_def); |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 691 | FREE_STRING(st->ctx, *if_features); |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 692 | FREE_STRING(st->ctx, err_msg); |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 693 | FREE_STRING(st->ctx, app_tag); |
David Sedlák | a5b1d38 | 2019-07-10 16:31:09 +0200 | [diff] [blame] | 694 | FREE_STRING(st->ctx, units); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 695 | FREE_STRING(st->ctx, patter_type.patterns->arg.str); |
| 696 | FREE_STRING(st->ctx, def.str); |
| 697 | FREE_STRING(st->ctx, range_type.range->arg.str); |
| 698 | FREE_STRING(st->ctx, len_type.length->arg.str); |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 699 | FREE_STRING(st->ctx, enum_type.enums->name); |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 700 | FREE_STRING(st->ctx, value); |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 701 | LY_ARRAY_FREE(if_features); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 702 | LY_ARRAY_FREE(exts); |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 703 | LY_ARRAY_FREE(ext_def); |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 704 | LY_ARRAY_FREE(patter_type.patterns); |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 705 | LY_ARRAY_FREE(enum_type.enums); |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 706 | free(when_p); |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 707 | free(range_type.range); |
David Sedlák | 438ae43 | 2019-07-11 15:36:54 +0200 | [diff] [blame] | 708 | free(len_type.length); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 709 | st = reset_state(state); |
| 710 | |
| 711 | /* test unique subelem */ |
| 712 | const char *prefix_value; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 713 | struct yin_subelement subelems2[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE}, |
| 714 | {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_UNIQUE}}; |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 715 | data = ELEMENT_WRAPPER_START |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 716 | "<prefix value=\"inv_mod\" />" |
| 717 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
| 718 | "<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] | 719 | ELEMENT_WRAPPER_END; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 720 | ly_in_new_memory(data, &st->in); |
| 721 | lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 722 | lyxml_ctx_next(st->yin_ctx->xmlctx); |
| 723 | |
| 724 | ret = yin_parse_content(st->yin_ctx, subelems2, 2, LY_STMT_STATUS, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 725 | assert_int_equal(ret, LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 726 | 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] | 727 | lydict_remove(st->ctx, prefix_value); |
| 728 | lydict_remove(st->ctx, value); |
| 729 | st = reset_state(state); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 730 | |
| 731 | /* test first subelem */ |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 732 | data = ELEMENT_WRAPPER_START |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 733 | "<prefix value=\"inv_mod\" />" |
| 734 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
| 735 | "<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] | 736 | ELEMENT_WRAPPER_END; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 737 | struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE}, |
| 738 | {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}}; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 739 | ly_in_new_memory(data, &st->in); |
| 740 | lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 741 | lyxml_ctx_next(st->yin_ctx->xmlctx); |
| 742 | |
| 743 | ret = yin_parse_content(st->yin_ctx, subelems3, 2, LY_STMT_STATUS, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 744 | assert_int_equal(ret, LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 745 | 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] | 746 | lydict_remove(st->ctx, prefix_value); |
| 747 | st = reset_state(state); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 748 | |
| 749 | /* test mandatory subelem */ |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 750 | data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 751 | struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}}; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 752 | ly_in_new_memory(data, &st->in); |
| 753 | lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 754 | lyxml_ctx_next(st->yin_ctx->xmlctx); |
| 755 | |
| 756 | ret = yin_parse_content(st->yin_ctx, subelems4, 1, LY_STMT_STATUS, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 757 | assert_int_equal(ret, LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 758 | 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] | 759 | |
| 760 | st->finished_correctly = true; |
| 761 | } |
| 762 | |
David Sedlák | 92147b0 | 2019-07-09 14:01:01 +0200 | [diff] [blame] | 763 | static void |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 764 | test_validate_value(void **state) |
| 765 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 766 | struct test_parser_yin_state *st = *state; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 767 | const char *data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END; |
| 768 | |
| 769 | /* create some XML context */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 770 | ly_in_new_memory(data, &st->in); |
| 771 | lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 772 | st->yin_ctx->xmlctx->status = LYXML_ELEM_CONTENT; |
| 773 | st->yin_ctx->xmlctx->dynamic = 0; |
| 774 | |
| 775 | st->yin_ctx->xmlctx->value = "#invalid"; |
| 776 | st->yin_ctx->xmlctx->value_len = 8; |
| 777 | assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID); |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 778 | logbuf_assert("Invalid identifier character '#' (0x0023). Line number 1."); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 779 | |
| 780 | st->yin_ctx->xmlctx->value = ""; |
| 781 | st->yin_ctx->xmlctx->value_len = 0; |
| 782 | assert_int_equal(yin_validate_value(st->yin_ctx, Y_STR_ARG), LY_SUCCESS); |
| 783 | |
| 784 | st->yin_ctx->xmlctx->value = "pre:b"; |
| 785 | st->yin_ctx->xmlctx->value_len = 5; |
| 786 | assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID); |
| 787 | assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG), LY_SUCCESS); |
| 788 | |
| 789 | st->yin_ctx->xmlctx->value = "pre:pre:b"; |
| 790 | st->yin_ctx->xmlctx->value_len = 9; |
| 791 | assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG), LY_EVALID); |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 792 | |
| 793 | st->finished_correctly = true; |
| 794 | } |
| 795 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 796 | /* helper function to simplify unit test of each element using parse_content function */ |
| 797 | LY_ERR |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 798 | test_element_helper(struct test_parser_yin_state *st, const char *data, void *dest, const char **text, struct lysp_ext_instance **exts) |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 799 | { |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 800 | const char *name, *prefix; |
| 801 | size_t name_len, prefix_len; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 802 | LY_ERR ret = LY_SUCCESS; |
| 803 | struct yin_subelement subelems[71] = { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 804 | {LY_STMT_ACTION, dest, 0}, |
| 805 | {LY_STMT_ANYDATA, dest, 0}, |
| 806 | {LY_STMT_ANYXML, dest, 0}, |
| 807 | {LY_STMT_ARGUMENT,dest, 0}, |
| 808 | {LY_STMT_AUGMENT, dest, 0}, |
| 809 | {LY_STMT_BASE, dest, 0}, |
| 810 | {LY_STMT_BELONGS_TO, dest, 0}, |
| 811 | {LY_STMT_BIT, dest, 0}, |
| 812 | {LY_STMT_CASE, dest, 0}, |
| 813 | {LY_STMT_CHOICE, dest, 0}, |
| 814 | {LY_STMT_CONFIG, dest, 0}, |
| 815 | {LY_STMT_CONTACT, dest, 0}, |
| 816 | {LY_STMT_CONTAINER, dest, 0}, |
| 817 | {LY_STMT_DEFAULT, dest, YIN_SUBELEM_UNIQUE}, |
| 818 | {LY_STMT_DESCRIPTION, dest, 0}, |
| 819 | {LY_STMT_DEVIATE, dest, 0}, |
| 820 | {LY_STMT_DEVIATION, dest, 0}, |
| 821 | {LY_STMT_ENUM, dest, 0}, |
| 822 | {LY_STMT_ERROR_APP_TAG, dest, YIN_SUBELEM_UNIQUE}, |
| 823 | {LY_STMT_ERROR_MESSAGE, dest, 0}, |
| 824 | {LY_STMT_EXTENSION, dest, 0}, |
| 825 | {LY_STMT_FEATURE, dest, 0}, |
| 826 | {LY_STMT_FRACTION_DIGITS, dest, 0}, |
| 827 | {LY_STMT_GROUPING, dest, 0}, |
| 828 | {LY_STMT_IDENTITY, dest, 0}, |
| 829 | {LY_STMT_IF_FEATURE, dest, 0}, |
| 830 | {LY_STMT_IMPORT, dest, 0}, |
| 831 | {LY_STMT_INCLUDE, dest, 0}, |
| 832 | {LY_STMT_INPUT, dest, 0}, |
| 833 | {LY_STMT_KEY, dest, YIN_SUBELEM_UNIQUE}, |
| 834 | {LY_STMT_LEAF, dest, 0}, |
| 835 | {LY_STMT_LEAF_LIST, dest, 0}, |
| 836 | {LY_STMT_LENGTH, dest, 0}, |
| 837 | {LY_STMT_LIST, dest, 0}, |
| 838 | {LY_STMT_MANDATORY, dest, 0}, |
| 839 | {LY_STMT_MAX_ELEMENTS, dest, 0}, |
| 840 | {LY_STMT_MIN_ELEMENTS, dest, 0}, |
| 841 | {LY_STMT_MODIFIER, dest, 0}, |
| 842 | {LY_STMT_MODULE, dest, 0}, |
| 843 | {LY_STMT_MUST, dest, 0}, |
| 844 | {LY_STMT_NAMESPACE, dest, YIN_SUBELEM_UNIQUE}, |
| 845 | {LY_STMT_NOTIFICATION, dest, 0}, |
| 846 | {LY_STMT_ORDERED_BY, dest, 0}, |
| 847 | {LY_STMT_ORGANIZATION, dest, 0}, |
| 848 | {LY_STMT_OUTPUT, dest, 0}, |
| 849 | {LY_STMT_PATH, dest, 0}, |
| 850 | {LY_STMT_PATTERN, dest, 0}, |
| 851 | {LY_STMT_POSITION, dest, 0}, |
| 852 | {LY_STMT_PREFIX, dest, YIN_SUBELEM_UNIQUE}, |
| 853 | {LY_STMT_PRESENCE, dest, YIN_SUBELEM_UNIQUE}, |
| 854 | {LY_STMT_RANGE, dest, 0}, |
| 855 | {LY_STMT_REFERENCE, dest, 0}, |
| 856 | {LY_STMT_REFINE, dest, 0}, |
| 857 | {LY_STMT_REQUIRE_INSTANCE, dest, 0}, |
| 858 | {LY_STMT_REVISION, dest, 0}, |
| 859 | {LY_STMT_REVISION_DATE, dest, 0}, |
| 860 | {LY_STMT_RPC, dest, 0}, |
| 861 | {LY_STMT_STATUS, dest, 0}, |
| 862 | {LY_STMT_SUBMODULE, dest, 0}, |
| 863 | {LY_STMT_TYPE, dest, 0}, |
| 864 | {LY_STMT_TYPEDEF, dest, 0}, |
| 865 | {LY_STMT_UNIQUE, dest, 0}, |
| 866 | {LY_STMT_UNITS, dest, YIN_SUBELEM_UNIQUE}, |
| 867 | {LY_STMT_USES, dest, 0}, |
| 868 | {LY_STMT_VALUE, dest, 0}, |
| 869 | {LY_STMT_WHEN, dest, 0}, |
| 870 | {LY_STMT_YANG_VERSION, dest, 0}, |
| 871 | {LY_STMT_YIN_ELEMENT, dest, 0}, |
| 872 | {LY_STMT_EXTENSION_INSTANCE, dest, 0}, |
| 873 | {LY_STMT_ARG_TEXT, dest, 0}, |
| 874 | {LY_STMT_ARG_VALUE, dest, 0} |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 875 | }; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 876 | ly_in_new_memory(data, &st->in); |
| 877 | lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 878 | prefix = st->yin_ctx->xmlctx->prefix; |
| 879 | prefix_len = st->yin_ctx->xmlctx->prefix_len; |
| 880 | name = st->yin_ctx->xmlctx->name; |
| 881 | name_len = st->yin_ctx->xmlctx->name_len; |
| 882 | lyxml_ctx_next(st->yin_ctx->xmlctx); |
| 883 | |
| 884 | ret = yin_parse_content(st->yin_ctx, subelems, 71, yin_match_keyword(st->yin_ctx, name, name_len, prefix, prefix_len, LY_STMT_NONE), text, exts); |
| 885 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 886 | /* free parser and input */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 887 | lyxml_ctx_free(st->yin_ctx->xmlctx); |
| 888 | st->yin_ctx->xmlctx = NULL; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 889 | ly_in_free(st->in, 0); |
| 890 | st->in = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 891 | return ret; |
| 892 | } |
| 893 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 894 | #define EXT_SUBELEM "<myext:c-define name=\"MY_MTU\" xmlns:myext=\"urn:example:extensions\"/>" |
| 895 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 896 | static void |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 897 | test_enum_elem(void **state) |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 898 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 899 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 900 | struct lysp_type type = {}; |
| 901 | const char *data; |
| 902 | data = ELEMENT_WRAPPER_START |
| 903 | "<enum name=\"enum-name\">" |
| 904 | "<if-feature name=\"feature\" />" |
| 905 | "<value value=\"55\" />" |
| 906 | "<status value=\"deprecated\" />" |
| 907 | "<description><text>desc...</text></description>" |
| 908 | "<reference><text>ref...</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 909 | EXT_SUBELEM |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 910 | "</enum>" |
| 911 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 912 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 913 | assert_string_equal(type.enums->name, "enum-name"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 914 | assert_string_equal(type.enums->iffeatures[0].str, "feature"); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 915 | assert_int_equal(type.enums->value, 55); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 916 | 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] | 917 | assert_string_equal(type.enums->dsc, "desc..."); |
| 918 | assert_string_equal(type.enums->ref, "ref..."); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 919 | assert_string_equal(type.enums->exts->name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 920 | assert_int_equal(type.enums->exts->insubstmt_index, 0); |
| 921 | assert_int_equal(type.enums->exts->insubstmt, LYEXT_SUBSTMT_SELF); |
| 922 | lysp_type_free(st->ctx, &type); |
| 923 | memset(&type, 0, sizeof type); |
| 924 | |
| 925 | data = ELEMENT_WRAPPER_START |
| 926 | "<enum name=\"enum-name\"></enum>" |
| 927 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 928 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 929 | assert_string_equal(type.enums->name, "enum-name"); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 930 | lysp_type_free(st->ctx, &type); |
| 931 | memset(&type, 0, sizeof type); |
| 932 | |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 933 | st->finished_correctly = true; |
| 934 | } |
| 935 | |
| 936 | static void |
| 937 | test_bit_elem(void **state) |
| 938 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 939 | struct test_parser_yin_state *st = *state; |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 940 | struct lysp_type type = {}; |
| 941 | const char *data; |
| 942 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 943 | "<bit name=\"bit-name\">" |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 944 | "<if-feature name=\"feature\" />" |
| 945 | "<position value=\"55\" />" |
| 946 | "<status value=\"deprecated\" />" |
| 947 | "<description><text>desc...</text></description>" |
| 948 | "<reference><text>ref...</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 949 | EXT_SUBELEM |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 950 | "</bit>" |
| 951 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 952 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 953 | assert_string_equal(type.bits->name, "bit-name"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 954 | assert_string_equal(type.bits->iffeatures[0].str, "feature"); |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 955 | assert_int_equal(type.bits->value, 55); |
| 956 | assert_true((type.bits->flags & LYS_STATUS_DEPRC) && (type.bits->flags & LYS_SET_VALUE)); |
| 957 | assert_string_equal(type.bits->dsc, "desc..."); |
| 958 | assert_string_equal(type.bits->ref, "ref..."); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 959 | assert_string_equal(type.bits->exts->name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 960 | assert_int_equal(type.bits->exts->insubstmt_index, 0); |
| 961 | assert_int_equal(type.bits->exts->insubstmt, LYEXT_SUBSTMT_SELF); |
| 962 | lysp_type_free(st->ctx, &type); |
| 963 | memset(&type, 0, sizeof type); |
| 964 | |
| 965 | data = ELEMENT_WRAPPER_START |
| 966 | "<bit name=\"bit-name\"> </bit>" |
| 967 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 968 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 969 | assert_string_equal(type.bits->name, "bit-name"); |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 970 | lysp_type_free(st->ctx, &type); |
| 971 | memset(&type, 0, sizeof type); |
| 972 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 973 | st->finished_correctly = true; |
| 974 | } |
| 975 | |
| 976 | static void |
| 977 | test_meta_elem(void **state) |
| 978 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 979 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 980 | char *value = NULL; |
| 981 | const char *data; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 982 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 983 | |
| 984 | /* organization element */ |
| 985 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 986 | "<organization><text>organization...</text>" EXT_SUBELEM EXT_SUBELEM "</organization>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 987 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 988 | assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 989 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 990 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 991 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORGANIZATION); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 992 | assert_string_equal(exts[1].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 993 | assert_int_equal(exts[1].insubstmt_index, 0); |
| 994 | assert_int_equal(exts[1].insubstmt, LYEXT_SUBSTMT_ORGANIZATION); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 995 | assert_string_equal(value, "organization..."); |
| 996 | FREE_STRING(st->ctx, value); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 997 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 998 | value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 999 | exts = NULL; |
| 1000 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1001 | /* contact element */ |
| 1002 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1003 | "<contact><text>contact...</text>" EXT_SUBELEM "</contact>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1004 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1005 | assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1006 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1007 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1008 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONTACT); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1009 | assert_string_equal(value, "contact..."); |
| 1010 | FREE_STRING(st->ctx, value); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1011 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1012 | exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1013 | value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1014 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1015 | /* description element */ |
| 1016 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1017 | "<description><text>description...</text>" EXT_SUBELEM "</description>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1018 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1019 | assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1020 | assert_string_equal(value, "description..."); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1021 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1022 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1023 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DESCRIPTION); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1024 | FREE_STRING(st->ctx, value); |
| 1025 | value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1026 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1027 | exts = NULL; |
| 1028 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1029 | /* reference element */ |
| 1030 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1031 | "<reference><text>reference...</text>" EXT_SUBELEM "</reference>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1032 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1033 | assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1034 | assert_string_equal(value, "reference..."); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1035 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1036 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1037 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REFERENCE); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1038 | FREE_STRING(st->ctx, value); |
| 1039 | value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1040 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1041 | exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1042 | |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 1043 | /* reference element */ |
| 1044 | data = ELEMENT_WRAPPER_START |
| 1045 | "<reference invalid=\"text\"><text>reference...</text>""</reference>" |
| 1046 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1047 | assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1048 | logbuf_assert("Unexpected attribute \"invalid\" of \"reference\" element. Line number 1."); |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 1049 | FREE_STRING(st->ctx, value); |
| 1050 | value = NULL; |
| 1051 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1052 | exts = NULL; |
| 1053 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1054 | /* missing text subelement */ |
| 1055 | data = ELEMENT_WRAPPER_START |
| 1056 | "<reference>reference...</reference>" |
| 1057 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1058 | assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1059 | 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] | 1060 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1061 | /* reference element */ |
| 1062 | data = ELEMENT_WRAPPER_START |
| 1063 | "<reference>" EXT_SUBELEM "<text>reference...</text></reference>" |
| 1064 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1065 | assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1066 | 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] | 1067 | FREE_STRING(st->ctx, value); |
| 1068 | value = NULL; |
| 1069 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1070 | exts = NULL; |
| 1071 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1072 | st->finished_correctly = true; |
| 1073 | } |
| 1074 | |
| 1075 | static void |
| 1076 | test_import_elem(void **state) |
| 1077 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1078 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1079 | const char *data; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1080 | struct lysp_import *imports = NULL; |
| 1081 | struct import_meta imp_meta = {"prefix", &imports}; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1082 | |
| 1083 | /* max subelems */ |
| 1084 | data = ELEMENT_WRAPPER_START |
| 1085 | "<import module=\"a\">" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1086 | EXT_SUBELEM |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1087 | "<prefix value=\"a_mod\"/>" |
| 1088 | "<revision-date date=\"2015-01-01\"></revision-date>" |
| 1089 | "<description><text>import description</text></description>" |
| 1090 | "<reference><text>import reference</text></reference>" |
| 1091 | "</import>" |
| 1092 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1093 | assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1094 | assert_string_equal(imports->name, "a"); |
| 1095 | assert_string_equal(imports->prefix, "a_mod"); |
| 1096 | assert_string_equal(imports->rev, "2015-01-01"); |
| 1097 | assert_string_equal(imports->dsc, "import description"); |
| 1098 | assert_string_equal(imports->ref, "import reference"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1099 | assert_string_equal(imports->exts->name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1100 | assert_int_equal(imports->exts->insubstmt, LYEXT_SUBSTMT_SELF); |
| 1101 | assert_int_equal(imports->exts->insubstmt_index, 0); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1102 | FREE_ARRAY(st->ctx, imports, lysp_import_free); |
| 1103 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1104 | |
| 1105 | /* min subelems */ |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1106 | data = ELEMENT_WRAPPER_START |
| 1107 | "<import module=\"a\">" |
| 1108 | "<prefix value=\"a_mod\"/>" |
| 1109 | "</import>" |
| 1110 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1111 | assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1112 | assert_string_equal(imports->prefix, "a_mod"); |
| 1113 | FREE_ARRAY(st->ctx, imports, lysp_import_free); |
| 1114 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1115 | |
| 1116 | /* invalid (missing prefix) */ |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1117 | data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1118 | assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1119 | 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] | 1120 | FREE_ARRAY(st->ctx, imports, lysp_import_free); |
| 1121 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1122 | |
| 1123 | /* invalid reused prefix */ |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1124 | data = ELEMENT_WRAPPER_START |
| 1125 | "<import module=\"a\">" |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1126 | "<prefix value=\"prefix\"/>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1127 | "</import>" |
| 1128 | "<import module=\"a\">" |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1129 | "<prefix value=\"prefix\"/>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1130 | "</import>" |
| 1131 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1132 | assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1133 | logbuf_assert("Prefix \"prefix\" already used as module prefix. Line number 1."); |
| 1134 | FREE_ARRAY(st->ctx, imports, lysp_import_free); |
| 1135 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1136 | |
| 1137 | st->finished_correctly = true; |
| 1138 | } |
| 1139 | |
| 1140 | static void |
| 1141 | test_status_elem(void **state) |
| 1142 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1143 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1144 | const char *data; |
| 1145 | uint16_t flags = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1146 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1147 | |
| 1148 | /* test valid values */ |
| 1149 | data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1150 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1151 | assert_true(flags & LYS_STATUS_CURR); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1152 | |
| 1153 | data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1154 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1155 | assert_true(flags & LYS_STATUS_DEPRC); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1156 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1157 | data = ELEMENT_WRAPPER_START "<status value=\"obsolete\">"EXT_SUBELEM"</status>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1158 | assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1159 | assert_true(flags & LYS_STATUS_OBSLT); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1160 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1161 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1162 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_STATUS); |
| 1163 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1164 | exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1165 | |
| 1166 | /* test invalid value */ |
| 1167 | data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1168 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 1169 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"status\" element. Valid values are \"current\", \"deprecated\" and \"obsolete\". Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1170 | st->finished_correctly = true; |
| 1171 | } |
| 1172 | |
| 1173 | static void |
| 1174 | test_ext_elem(void **state) |
| 1175 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1176 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1177 | const char *data; |
| 1178 | struct lysp_ext *ext = NULL; |
| 1179 | |
| 1180 | /* max subelems */ |
| 1181 | data = ELEMENT_WRAPPER_START |
| 1182 | "<extension name=\"ext_name\">" |
| 1183 | "<argument name=\"arg\"></argument>" |
| 1184 | "<status value=\"current\"/>" |
| 1185 | "<description><text>ext_desc</text></description>" |
| 1186 | "<reference><text>ext_ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1187 | EXT_SUBELEM |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1188 | "</extension>" |
| 1189 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1190 | assert_int_equal(test_element_helper(st, data, &ext, NULL, NULL), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1191 | assert_string_equal(ext->name, "ext_name"); |
| 1192 | assert_string_equal(ext->argument, "arg"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1193 | assert_true(ext->flags & LYS_STATUS_CURR); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1194 | assert_string_equal(ext->dsc, "ext_desc"); |
| 1195 | assert_string_equal(ext->ref, "ext_ref"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1196 | assert_string_equal(ext->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1197 | assert_int_equal(ext->exts[0].insubstmt_index, 0); |
| 1198 | assert_int_equal(ext->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1199 | lysp_ext_free(st->ctx, ext); |
| 1200 | LY_ARRAY_FREE(ext); |
| 1201 | ext = NULL; |
| 1202 | |
| 1203 | /* min subelems */ |
| 1204 | data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1205 | assert_int_equal(test_element_helper(st, data, &ext, NULL, NULL), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1206 | assert_string_equal(ext->name, "ext_name"); |
| 1207 | lysp_ext_free(st->ctx, ext); |
| 1208 | LY_ARRAY_FREE(ext); |
| 1209 | ext = NULL; |
| 1210 | |
| 1211 | st->finished_correctly = true; |
| 1212 | } |
| 1213 | |
| 1214 | static void |
| 1215 | test_yin_element_elem(void **state) |
| 1216 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1217 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1218 | const char *data; |
| 1219 | uint16_t flags = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1220 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1221 | |
| 1222 | data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1223 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1224 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1225 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1226 | data = ELEMENT_WRAPPER_START "<yin-element value=\"false\">" EXT_SUBELEM "</yin-element>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1227 | assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1228 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1229 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1230 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1231 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_YINELEM); |
| 1232 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1233 | |
| 1234 | data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1235 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1236 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 1237 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"yin-element\" element. Valid values are \"true\" and \"false\". Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1238 | st->finished_correctly = true; |
| 1239 | } |
| 1240 | |
| 1241 | static void |
| 1242 | test_yangversion_elem(void **state) |
| 1243 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1244 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1245 | const char *data; |
| 1246 | uint8_t version = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1247 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1248 | |
| 1249 | /* valid values */ |
Radek Krejci | 96e48da | 2020-09-04 13:18:06 +0200 | [diff] [blame] | 1250 | data = ELEMENT_WRAPPER_START "<yang-version value=\"1\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1251 | assert_int_equal(test_element_helper(st, data, &version, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1252 | assert_true(version & LYS_VERSION_1_0); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1253 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1254 | data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\">" EXT_SUBELEM "</yang-version>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1255 | assert_int_equal(test_element_helper(st, data, &version, NULL, &exts), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1256 | assert_true(version & LYS_VERSION_1_1); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1257 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1258 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1259 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_VERSION); |
| 1260 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1261 | |
| 1262 | /* invalid value */ |
| 1263 | data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1264 | assert_int_equal(test_element_helper(st, data, &version, NULL, NULL), LY_EVALID); |
Radek Krejci | 96e48da | 2020-09-04 13:18:06 +0200 | [diff] [blame] | 1265 | logbuf_assert("Invalid value \"version\" of \"value\" attribute in \"yang-version\" element. Valid values are \"1\" and \"1.1\". Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1266 | |
| 1267 | st->finished_correctly = true; |
| 1268 | } |
| 1269 | |
| 1270 | static void |
| 1271 | test_mandatory_elem(void **state) |
| 1272 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1273 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1274 | const char *data; |
| 1275 | uint16_t man = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1276 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1277 | |
| 1278 | /* valid values */ |
| 1279 | data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1280 | assert_int_equal(test_element_helper(st, data, &man, NULL, NULL), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1281 | assert_int_equal(man, LYS_MAND_TRUE); |
| 1282 | man = 0; |
| 1283 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1284 | data = ELEMENT_WRAPPER_START "<mandatory value=\"false\">" EXT_SUBELEM "</mandatory>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1285 | assert_int_equal(test_element_helper(st, data, &man, NULL, &exts), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1286 | assert_int_equal(man, LYS_MAND_FALSE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1287 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1288 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1289 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MANDATORY); |
| 1290 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1291 | |
| 1292 | data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1293 | assert_int_equal(test_element_helper(st, data, &man, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 1294 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"mandatory\" element. Valid values are \"true\" and \"false\". Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1295 | |
| 1296 | st->finished_correctly = true; |
| 1297 | } |
| 1298 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1299 | static void |
| 1300 | test_argument_elem(void **state) |
| 1301 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1302 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1303 | const char *data; |
| 1304 | uint16_t flags = 0; |
| 1305 | const char *arg; |
| 1306 | struct yin_argument_meta arg_meta = {&flags, &arg}; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1307 | struct lysp_ext_instance *exts = NULL; |
| 1308 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1309 | /* max subelems */ |
| 1310 | data = ELEMENT_WRAPPER_START |
| 1311 | "<argument name=\"arg-name\">" |
| 1312 | "<yin-element value=\"true\" />" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1313 | EXT_SUBELEM |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1314 | "</argument>" |
| 1315 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1316 | assert_int_equal(test_element_helper(st, data, &arg_meta, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1317 | assert_string_equal(arg, "arg-name"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1318 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1319 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1320 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1321 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ARGUMENT); |
| 1322 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1323 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1324 | flags = 0; |
| 1325 | FREE_STRING(st->ctx, arg); |
| 1326 | arg = NULL; |
| 1327 | |
| 1328 | /* min subelems */ |
| 1329 | data = ELEMENT_WRAPPER_START |
| 1330 | "<argument name=\"arg\">" |
| 1331 | "</argument>" |
| 1332 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1333 | assert_int_equal(test_element_helper(st, data, &arg_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1334 | assert_string_equal(arg, "arg"); |
| 1335 | assert_true(flags == 0); |
| 1336 | FREE_STRING(st->ctx, arg); |
| 1337 | |
| 1338 | st->finished_correctly = true; |
| 1339 | } |
| 1340 | |
| 1341 | static void |
| 1342 | test_base_elem(void **state) |
| 1343 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1344 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1345 | const char *data; |
| 1346 | const char **bases = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1347 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1348 | struct lysp_type type = {}; |
| 1349 | |
| 1350 | /* as identity subelement */ |
| 1351 | data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1352 | "<base name=\"base-name\">" |
| 1353 | EXT_SUBELEM |
| 1354 | "</base>" |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1355 | "</identity>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1356 | assert_int_equal(test_element_helper(st, data, &bases, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1357 | assert_string_equal(*bases, "base-name"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1358 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1359 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1360 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE); |
| 1361 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1362 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1363 | FREE_STRING(st->ctx, *bases); |
| 1364 | LY_ARRAY_FREE(bases); |
| 1365 | |
| 1366 | /* as type subelement */ |
| 1367 | data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1368 | "<base name=\"base-name\">" |
| 1369 | EXT_SUBELEM |
| 1370 | "</base>" |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1371 | "</type>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1372 | assert_int_equal(test_element_helper(st, data, &type, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1373 | assert_string_equal(*type.bases, "base-name"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1374 | assert_true(type.flags & LYS_SET_BASE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1375 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1376 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1377 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE); |
| 1378 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1379 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1380 | FREE_STRING(st->ctx, *type.bases); |
| 1381 | LY_ARRAY_FREE(type.bases); |
| 1382 | |
| 1383 | st->finished_correctly = true; |
| 1384 | } |
| 1385 | |
| 1386 | static void |
| 1387 | test_belongsto_elem(void **state) |
| 1388 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1389 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1390 | const char *data; |
| 1391 | struct lysp_submodule submod; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1392 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1393 | |
| 1394 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1395 | "<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] | 1396 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1397 | assert_int_equal(test_element_helper(st, data, &submod, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1398 | assert_string_equal(submod.prefix, "pref"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1399 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1400 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1401 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BELONGSTO); |
| 1402 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1403 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1404 | FREE_STRING(st->ctx, submod.prefix); |
| 1405 | |
| 1406 | data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1407 | assert_int_equal(test_element_helper(st, data, &submod, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1408 | 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] | 1409 | |
| 1410 | st->finished_correctly = true; |
| 1411 | } |
| 1412 | |
| 1413 | static void |
| 1414 | test_config_elem(void **state) |
| 1415 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1416 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1417 | const char *data; |
| 1418 | uint16_t flags = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1419 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1420 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1421 | data = ELEMENT_WRAPPER_START "<config value=\"true\">" EXT_SUBELEM "</config>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1422 | assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1423 | assert_true(flags & LYS_CONFIG_W); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1424 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1425 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1426 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONFIG); |
| 1427 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1428 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1429 | flags = 0; |
| 1430 | |
| 1431 | data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1432 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1433 | assert_true(flags & LYS_CONFIG_R); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1434 | flags = 0; |
| 1435 | |
| 1436 | data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1437 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 1438 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"config\" element. Valid values are \"true\" and \"false\". Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1439 | |
| 1440 | st->finished_correctly = true; |
| 1441 | } |
| 1442 | |
| 1443 | static void |
| 1444 | test_default_elem(void **state) |
| 1445 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1446 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1447 | const char *data; |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1448 | struct lysp_qname val = {0}; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1449 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1450 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1451 | data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\">"EXT_SUBELEM"</default>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1452 | assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1453 | assert_string_equal(val.str, "defaul-value"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1454 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1455 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1456 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DEFAULT); |
| 1457 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1458 | exts = NULL; |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1459 | FREE_STRING(st->ctx, val.str); |
| 1460 | val.str = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1461 | |
| 1462 | data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1463 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1464 | logbuf_assert("Missing mandatory attribute value of default element. Line number 1."); |
| 1465 | |
| 1466 | st->finished_correctly = true; |
| 1467 | } |
| 1468 | |
| 1469 | static void |
| 1470 | test_err_app_tag_elem(void **state) |
| 1471 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1472 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1473 | const char *data; |
| 1474 | const char *val = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1475 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1476 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1477 | data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\">"EXT_SUBELEM"</error-app-tag>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1478 | assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1479 | assert_string_equal(val, "val"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1480 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1481 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1482 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRTAG); |
| 1483 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1484 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1485 | FREE_STRING(st->ctx, val); |
| 1486 | val = NULL; |
| 1487 | |
| 1488 | data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1489 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1490 | logbuf_assert("Missing mandatory attribute value of error-app-tag element. Line number 1."); |
| 1491 | |
| 1492 | st->finished_correctly = true; |
| 1493 | } |
| 1494 | |
| 1495 | static void |
| 1496 | test_err_msg_elem(void **state) |
| 1497 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1498 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1499 | const char *data; |
| 1500 | const char *val = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1501 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1502 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1503 | data = ELEMENT_WRAPPER_START "<error-message><value>val</value>"EXT_SUBELEM"</error-message>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1504 | assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1505 | assert_string_equal(val, "val"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1506 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1507 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1508 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRMSG); |
| 1509 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1510 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1511 | FREE_STRING(st->ctx, val); |
| 1512 | |
| 1513 | data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1514 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1515 | 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] | 1516 | |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 1517 | data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1518 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1519 | 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] | 1520 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1521 | st->finished_correctly = true; |
| 1522 | } |
| 1523 | |
| 1524 | static void |
| 1525 | test_fracdigits_elem(void **state) |
| 1526 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1527 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1528 | const char *data; |
| 1529 | struct lysp_type type = {}; |
| 1530 | |
| 1531 | /* valid value */ |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1532 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\">"EXT_SUBELEM"</fraction-digits>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1533 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1534 | assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1535 | assert_int_equal(type.exts[0].insubstmt_index, 0); |
| 1536 | assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_FRACDIGITS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1537 | assert_int_equal(type.fraction_digits, 10); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1538 | assert_true(type.flags & LYS_SET_FRDIGITS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1539 | FREE_ARRAY(st->ctx, type.exts, lysp_ext_instance_free); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1540 | |
| 1541 | /* invalid values */ |
| 1542 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1543 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1544 | 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] | 1545 | |
| 1546 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1547 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1548 | 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] | 1549 | |
| 1550 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1551 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1552 | 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] | 1553 | |
| 1554 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1555 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1556 | 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] | 1557 | |
| 1558 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1559 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1560 | 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] | 1561 | |
| 1562 | st->finished_correctly = true; |
| 1563 | } |
| 1564 | |
| 1565 | static void |
| 1566 | test_iffeature_elem(void **state) |
| 1567 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1568 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1569 | const char *data; |
| 1570 | const char **iffeatures = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1571 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1572 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1573 | data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\">"EXT_SUBELEM"</if-feature>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1574 | assert_int_equal(test_element_helper(st, data, &iffeatures, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1575 | assert_string_equal(*iffeatures, "local-storage"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1576 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1577 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1578 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_IFFEATURE); |
| 1579 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1580 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1581 | FREE_STRING(st->ctx, *iffeatures); |
| 1582 | LY_ARRAY_FREE(iffeatures); |
| 1583 | iffeatures = NULL; |
| 1584 | |
| 1585 | data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1586 | assert_int_equal(test_element_helper(st, data, &iffeatures, NULL, NULL), LY_EVALID); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1587 | logbuf_assert("Missing mandatory attribute name of if-feature element. Line number 1."); |
| 1588 | LY_ARRAY_FREE(iffeatures); |
| 1589 | iffeatures = NULL; |
| 1590 | |
| 1591 | st->finished_correctly = true; |
| 1592 | } |
| 1593 | |
| 1594 | static void |
| 1595 | test_length_elem(void **state) |
| 1596 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1597 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1598 | const char *data; |
| 1599 | struct lysp_type type = {}; |
| 1600 | |
| 1601 | /* max subelems */ |
| 1602 | data = ELEMENT_WRAPPER_START |
| 1603 | "<length value=\"length-str\">" |
| 1604 | "<error-message><value>err-msg</value></error-message>" |
| 1605 | "<error-app-tag value=\"err-app-tag\"/>" |
| 1606 | "<description><text>desc</text></description>" |
| 1607 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1608 | EXT_SUBELEM |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1609 | "</length>" |
| 1610 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1611 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1612 | assert_string_equal(type.length->arg.str, "length-str"); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1613 | assert_string_equal(type.length->emsg, "err-msg"); |
| 1614 | assert_string_equal(type.length->eapptag, "err-app-tag"); |
| 1615 | assert_string_equal(type.length->dsc, "desc"); |
| 1616 | assert_string_equal(type.length->ref, "ref"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1617 | assert_true(type.flags & LYS_SET_LENGTH); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1618 | assert_string_equal(type.length->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1619 | assert_int_equal(type.length->exts[0].insubstmt_index, 0); |
| 1620 | assert_int_equal(type.length->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1621 | lysp_type_free(st->ctx, &type); |
| 1622 | memset(&type, 0, sizeof(type)); |
| 1623 | |
| 1624 | /* min subelems */ |
| 1625 | data = ELEMENT_WRAPPER_START |
| 1626 | "<length value=\"length-str\">" |
| 1627 | "</length>" |
| 1628 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1629 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1630 | assert_string_equal(type.length->arg.str, "length-str"); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1631 | lysp_type_free(st->ctx, &type); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1632 | assert_true(type.flags & LYS_SET_LENGTH); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1633 | memset(&type, 0, sizeof(type)); |
| 1634 | |
| 1635 | data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1636 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1637 | logbuf_assert("Missing mandatory attribute value of length element. Line number 1."); |
| 1638 | lysp_type_free(st->ctx, &type); |
| 1639 | memset(&type, 0, sizeof(type)); |
| 1640 | |
| 1641 | st->finished_correctly = true; |
| 1642 | } |
| 1643 | |
| 1644 | static void |
| 1645 | test_modifier_elem(void **state) |
| 1646 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1647 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1648 | const char *data; |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1649 | const char *pat; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1650 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1651 | |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1652 | assert_int_equal(LY_SUCCESS, lydict_insert(st->ctx, "\006pattern", 8, &pat)); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1653 | data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\">" EXT_SUBELEM "</modifier>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1654 | assert_int_equal(test_element_helper(st, data, &pat, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1655 | assert_string_equal(pat, "\x015pattern"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1656 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1657 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1658 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MODIFIER); |
| 1659 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1660 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1661 | FREE_STRING(st->ctx, pat); |
| 1662 | |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1663 | assert_int_equal(LY_SUCCESS, lydict_insert(st->ctx, "\006pattern", 8, &pat)); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1664 | data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1665 | assert_int_equal(test_element_helper(st, data, &pat, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 1666 | logbuf_assert("Invalid value \"invert\" of \"value\" attribute in \"modifier\" element. Only valid value is \"invert-match\". Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1667 | FREE_STRING(st->ctx, pat); |
| 1668 | |
| 1669 | st->finished_correctly = true; |
| 1670 | } |
| 1671 | |
| 1672 | static void |
| 1673 | test_namespace_elem(void **state) |
| 1674 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1675 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1676 | const char *data; |
| 1677 | const char *ns; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1678 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1679 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1680 | data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\">" EXT_SUBELEM "</namespace>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1681 | assert_int_equal(test_element_helper(st, data, &ns, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1682 | assert_string_equal(ns, "ns"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1683 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1684 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1685 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_NAMESPACE); |
| 1686 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1687 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1688 | FREE_STRING(st->ctx, ns); |
| 1689 | |
| 1690 | data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1691 | assert_int_equal(test_element_helper(st, data, &ns, NULL, NULL), LY_EVALID); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1692 | logbuf_assert("Missing mandatory attribute uri of namespace element. Line number 1."); |
| 1693 | |
| 1694 | st->finished_correctly = true; |
| 1695 | } |
| 1696 | |
| 1697 | static void |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1698 | test_pattern_elem(void **state) |
| 1699 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1700 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1701 | const char *data; |
| 1702 | struct lysp_type type = {}; |
| 1703 | |
| 1704 | /* max subelems */ |
| 1705 | data = ELEMENT_WRAPPER_START |
| 1706 | "<pattern value=\"super_pattern\">" |
| 1707 | "<modifier value=\"invert-match\"/>" |
| 1708 | "<error-message><value>err-msg-value</value></error-message>" |
| 1709 | "<error-app-tag value=\"err-app-tag-value\"/>" |
David Sedlák | 169cc52 | 2019-08-15 13:23:45 +0200 | [diff] [blame] | 1710 | "<description><text>"pattern-desc"</text></description>" |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1711 | "<reference><text>pattern-ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1712 | EXT_SUBELEM |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1713 | "</pattern>" |
| 1714 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1715 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1716 | assert_true(type.flags & LYS_SET_PATTERN); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1717 | assert_string_equal(type.patterns->arg.str, "\x015super_pattern"); |
David Sedlák | 169cc52 | 2019-08-15 13:23:45 +0200 | [diff] [blame] | 1718 | assert_string_equal(type.patterns->dsc, "\"pattern-desc\""); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1719 | assert_string_equal(type.patterns->eapptag, "err-app-tag-value"); |
| 1720 | assert_string_equal(type.patterns->emsg, "err-msg-value"); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1721 | assert_string_equal(type.patterns->ref, "pattern-ref"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1722 | assert_string_equal(type.patterns->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1723 | assert_int_equal(type.patterns->exts[0].insubstmt_index, 0); |
| 1724 | assert_int_equal(type.patterns->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1725 | lysp_type_free(st->ctx, &type); |
| 1726 | memset(&type, 0, sizeof(type)); |
| 1727 | |
| 1728 | /* min subelems */ |
| 1729 | data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1730 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1731 | assert_string_equal(type.patterns->arg.str, "\x006pattern"); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1732 | lysp_type_free(st->ctx, &type); |
| 1733 | memset(&type, 0, sizeof(type)); |
| 1734 | |
| 1735 | st->finished_correctly = true; |
| 1736 | } |
| 1737 | |
| 1738 | static void |
| 1739 | test_value_position_elem(void **state) |
| 1740 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1741 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1742 | const char *data; |
| 1743 | struct lysp_type_enum en = {}; |
| 1744 | |
| 1745 | /* valid values */ |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1746 | data = ELEMENT_WRAPPER_START "<value value=\"55\">" EXT_SUBELEM "</value>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1747 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1748 | assert_int_equal(en.value, 55); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1749 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1750 | assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1751 | assert_int_equal(en.exts[0].insubstmt_index, 0); |
| 1752 | assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_VALUE); |
| 1753 | FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1754 | memset(&en, 0, sizeof(en)); |
| 1755 | |
| 1756 | data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1757 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1758 | assert_int_equal(en.value, -55); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1759 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1760 | memset(&en, 0, sizeof(en)); |
| 1761 | |
| 1762 | data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1763 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1764 | assert_int_equal(en.value, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1765 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1766 | memset(&en, 0, sizeof(en)); |
| 1767 | |
| 1768 | data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1769 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1770 | assert_int_equal(en.value, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1771 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1772 | memset(&en, 0, sizeof(en)); |
| 1773 | |
| 1774 | /* valid positions */ |
David Sedlák | 8d552d6 | 2019-08-06 15:29:05 +0200 | [diff] [blame] | 1775 | data = ELEMENT_WRAPPER_START "<position value=\"55\">" EXT_SUBELEM "</position>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1776 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1777 | assert_int_equal(en.value, 55); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1778 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1779 | assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | 8d552d6 | 2019-08-06 15:29:05 +0200 | [diff] [blame] | 1780 | assert_int_equal(en.exts[0].insubstmt_index, 0); |
| 1781 | assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_POSITION); |
| 1782 | FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1783 | memset(&en, 0, sizeof(en)); |
| 1784 | |
| 1785 | data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1786 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1787 | assert_int_equal(en.value, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1788 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1789 | memset(&en, 0, sizeof(en)); |
| 1790 | |
| 1791 | /* invalid values */ |
| 1792 | data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1793 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1794 | 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] | 1795 | |
| 1796 | data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1797 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1798 | 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] | 1799 | |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1800 | data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1801 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1802 | 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] | 1803 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1804 | /*invalid positions */ |
| 1805 | data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1806 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1807 | 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] | 1808 | |
| 1809 | data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1810 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1811 | 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] | 1812 | |
| 1813 | data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1814 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1815 | 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] | 1816 | |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1817 | data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1818 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1819 | 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] | 1820 | |
| 1821 | st->finished_correctly = true; |
| 1822 | } |
| 1823 | |
| 1824 | static void |
| 1825 | test_prefix_elem(void **state) |
| 1826 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1827 | struct test_parser_yin_state *st = *state; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1828 | const char *data; |
| 1829 | const char *value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1830 | struct lysp_ext_instance *exts = NULL; |
| 1831 | |
| 1832 | data = ELEMENT_WRAPPER_START "<prefix value=\"pref\">" EXT_SUBELEM "</prefix>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1833 | assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1834 | assert_string_equal(value, "pref"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1835 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1836 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1837 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PREFIX); |
| 1838 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1839 | exts = NULL; |
| 1840 | FREE_STRING(st->ctx, value); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1841 | |
| 1842 | data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1843 | assert_int_equal(test_element_helper(st, data, &value, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1844 | assert_string_equal(value, "pref"); |
| 1845 | FREE_STRING(st->ctx, value); |
| 1846 | |
| 1847 | st->finished_correctly = true; |
| 1848 | } |
| 1849 | |
| 1850 | static void |
| 1851 | test_range_elem(void **state) |
| 1852 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1853 | struct test_parser_yin_state *st = *state; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1854 | const char *data; |
| 1855 | struct lysp_type type = {}; |
| 1856 | |
| 1857 | /* max subelems */ |
| 1858 | data = ELEMENT_WRAPPER_START |
| 1859 | "<range value=\"range-str\">" |
| 1860 | "<error-message><value>err-msg</value></error-message>" |
| 1861 | "<error-app-tag value=\"err-app-tag\" />" |
| 1862 | "<description><text>desc</text></description>" |
| 1863 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1864 | EXT_SUBELEM |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1865 | "</range>" |
| 1866 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1867 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1868 | assert_string_equal(type.range->arg.str, "range-str"); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1869 | assert_string_equal(type.range->dsc, "desc"); |
| 1870 | assert_string_equal(type.range->eapptag, "err-app-tag"); |
| 1871 | assert_string_equal(type.range->emsg, "err-msg"); |
| 1872 | assert_string_equal(type.range->ref, "ref"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1873 | assert_true(type.flags & LYS_SET_RANGE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1874 | assert_string_equal(type.range->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1875 | assert_int_equal(type.range->exts[0].insubstmt_index, 0); |
| 1876 | assert_int_equal(type.range->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1877 | lysp_type_free(st->ctx, &type); |
| 1878 | memset(&type, 0, sizeof(type)); |
| 1879 | |
| 1880 | /* min subelems */ |
| 1881 | data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1882 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1883 | assert_string_equal(type.range->arg.str, "range-str"); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1884 | lysp_type_free(st->ctx, &type); |
| 1885 | memset(&type, 0, sizeof(type)); |
| 1886 | |
| 1887 | st->finished_correctly = true; |
| 1888 | } |
| 1889 | |
| 1890 | static void |
| 1891 | test_reqinstance_elem(void **state) |
| 1892 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1893 | struct test_parser_yin_state *st = *state; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1894 | const char *data; |
| 1895 | struct lysp_type type = {}; |
| 1896 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1897 | data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1898 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1899 | assert_int_equal(type.require_instance, 1); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1900 | assert_true(type.flags & LYS_SET_REQINST); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1901 | assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1902 | assert_int_equal(type.exts[0].insubstmt_index, 0); |
| 1903 | assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_REQINSTANCE); |
| 1904 | lysp_type_free(st->ctx, &type); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1905 | memset(&type, 0, sizeof(type)); |
| 1906 | |
| 1907 | data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1908 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1909 | assert_int_equal(type.require_instance, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1910 | assert_true(type.flags & LYS_SET_REQINST); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1911 | memset(&type, 0, sizeof(type)); |
| 1912 | |
| 1913 | data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1914 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1915 | memset(&type, 0, sizeof(type)); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 1916 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"require-instance\" element. Valid values are \"true\" and \"false\". Line number 1."); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1917 | |
| 1918 | st->finished_correctly = true; |
| 1919 | } |
| 1920 | |
| 1921 | static void |
| 1922 | test_revision_date_elem(void **state) |
| 1923 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1924 | struct test_parser_yin_state *st = *state; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1925 | const char *data; |
| 1926 | char rev[LY_REV_SIZE]; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1927 | struct lysp_ext_instance *exts = NULL; |
| 1928 | |
| 1929 | data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\">"EXT_SUBELEM"</revision-date>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1930 | assert_int_equal(test_element_helper(st, data, rev, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1931 | assert_string_equal(rev, "2000-01-01"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1932 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1933 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1934 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REVISIONDATE); |
| 1935 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1936 | |
| 1937 | data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1938 | assert_int_equal(test_element_helper(st, data, rev, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1939 | assert_string_equal(rev, "2000-01-01"); |
| 1940 | |
| 1941 | data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1942 | assert_int_equal(test_element_helper(st, data, rev, NULL, NULL), LY_EVALID); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1943 | logbuf_assert("Invalid value \"2000-50-05\" of \"revision-date\". Line number 1."); |
| 1944 | |
| 1945 | st->finished_correctly = true; |
| 1946 | } |
| 1947 | |
| 1948 | static void |
| 1949 | test_unique_elem(void **state) |
| 1950 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1951 | struct test_parser_yin_state *st = *state; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1952 | const char *data; |
| 1953 | const char **values = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1954 | struct lysp_ext_instance *exts = NULL; |
| 1955 | |
| 1956 | data = ELEMENT_WRAPPER_START "<unique tag=\"tag\">"EXT_SUBELEM"</unique>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1957 | assert_int_equal(test_element_helper(st, data, &values, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1958 | assert_string_equal(*values, "tag"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1959 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1960 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1961 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNIQUE); |
| 1962 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1963 | FREE_STRING(st->ctx, *values); |
| 1964 | LY_ARRAY_FREE(values); |
| 1965 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1966 | |
| 1967 | data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1968 | assert_int_equal(test_element_helper(st, data, &values, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1969 | assert_string_equal(*values, "tag"); |
| 1970 | FREE_STRING(st->ctx, *values); |
| 1971 | LY_ARRAY_FREE(values); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1972 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1973 | |
| 1974 | st->finished_correctly = true; |
| 1975 | } |
| 1976 | |
| 1977 | static void |
| 1978 | test_units_elem(void **state) |
| 1979 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1980 | struct test_parser_yin_state *st = *state; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1981 | const char *data; |
| 1982 | const char *values = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1983 | struct lysp_ext_instance *exts = NULL; |
| 1984 | |
| 1985 | data = ELEMENT_WRAPPER_START "<units name=\"name\">"EXT_SUBELEM"</units>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1986 | assert_int_equal(test_element_helper(st, data, &values, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1987 | assert_string_equal(values, "name"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1988 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1989 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1990 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNITS); |
| 1991 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1992 | FREE_STRING(st->ctx, values); |
| 1993 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1994 | |
| 1995 | data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1996 | assert_int_equal(test_element_helper(st, data, &values, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1997 | assert_string_equal(values, "name"); |
| 1998 | FREE_STRING(st->ctx, values); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1999 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 2000 | |
| 2001 | st->finished_correctly = true; |
| 2002 | } |
| 2003 | |
| 2004 | static void |
| 2005 | test_when_elem(void **state) |
| 2006 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2007 | struct test_parser_yin_state *st = *state; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 2008 | const char *data; |
| 2009 | struct lysp_when *when = NULL; |
| 2010 | |
| 2011 | data = ELEMENT_WRAPPER_START |
| 2012 | "<when condition=\"cond\">" |
| 2013 | "<description><text>desc</text></description>" |
| 2014 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2015 | EXT_SUBELEM |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 2016 | "</when>" |
| 2017 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2018 | assert_int_equal(test_element_helper(st, data, &when, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 2019 | assert_string_equal(when->cond, "cond"); |
| 2020 | assert_string_equal(when->dsc, "desc"); |
| 2021 | assert_string_equal(when->ref, "ref"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2022 | assert_string_equal(when->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2023 | assert_int_equal(when->exts[0].insubstmt_index, 0); |
| 2024 | assert_int_equal(when->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 2025 | lysp_when_free(st->ctx, when); |
| 2026 | free(when); |
| 2027 | when = NULL; |
| 2028 | |
| 2029 | data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2030 | assert_int_equal(test_element_helper(st, data, &when, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 2031 | assert_string_equal(when->cond, "cond"); |
| 2032 | lysp_when_free(st->ctx, when); |
| 2033 | free(when); |
| 2034 | when = NULL; |
| 2035 | |
| 2036 | st->finished_correctly = true; |
| 2037 | } |
| 2038 | |
| 2039 | static void |
| 2040 | test_yin_text_value_elem(void **state) |
| 2041 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2042 | struct test_parser_yin_state *st = *state; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 2043 | const char *data; |
| 2044 | const char *val; |
| 2045 | |
| 2046 | data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2047 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 2048 | assert_string_equal(val, "text"); |
| 2049 | FREE_STRING(st->ctx, val); |
| 2050 | |
| 2051 | data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2052 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 2053 | assert_string_equal(val, "text"); |
| 2054 | FREE_STRING(st->ctx, val); |
| 2055 | |
| 2056 | data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2057 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 2058 | assert_string_equal("", val); |
| 2059 | FREE_STRING(st->ctx, val); |
| 2060 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 2061 | st->finished_correctly = true; |
| 2062 | } |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 2063 | |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 2064 | static void |
| 2065 | test_type_elem(void **state) |
| 2066 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2067 | struct test_parser_yin_state *st = *state; |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 2068 | const char *data; |
| 2069 | struct lysp_type type = {}; |
| 2070 | |
| 2071 | /* max subelems */ |
| 2072 | data = ELEMENT_WRAPPER_START |
| 2073 | "<type name=\"type-name\">" |
| 2074 | "<base name=\"base-name\"/>" |
| 2075 | "<bit name=\"bit\"/>" |
| 2076 | "<enum name=\"enum\"/>" |
| 2077 | "<fraction-digits value=\"2\"/>" |
| 2078 | "<length value=\"length\"/>" |
Michal Vasko | cb8c6d4 | 2020-10-16 11:58:30 +0200 | [diff] [blame] | 2079 | "<path value=\"/path\"/>" |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 2080 | "<pattern value=\"pattern\"/>" |
| 2081 | "<range value=\"range\" />" |
| 2082 | "<require-instance value=\"true\"/>" |
| 2083 | "<type name=\"sub-type-name\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2084 | EXT_SUBELEM |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 2085 | "</type>" |
| 2086 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2087 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 2088 | assert_string_equal(type.name, "type-name"); |
| 2089 | assert_string_equal(*type.bases, "base-name"); |
| 2090 | assert_string_equal(type.bits->name, "bit"); |
| 2091 | assert_string_equal(type.enums->name, "enum"); |
| 2092 | assert_int_equal(type.fraction_digits, 2); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2093 | assert_string_equal(type.length->arg.str, "length"); |
Michal Vasko | cb8c6d4 | 2020-10-16 11:58:30 +0200 | [diff] [blame] | 2094 | assert_string_equal(type.path->expr, "/path"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2095 | assert_string_equal(type.patterns->arg.str, "\006pattern"); |
| 2096 | assert_string_equal(type.range->arg.str, "range"); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 2097 | assert_int_equal(type.require_instance, 1); |
| 2098 | assert_string_equal(type.types->name, "sub-type-name"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2099 | assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2100 | assert_int_equal(type.exts[0].insubstmt_index, 0); |
| 2101 | assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2102 | assert_true(type.flags & LYS_SET_BASE); |
| 2103 | assert_true(type.flags & LYS_SET_BIT); |
| 2104 | assert_true(type.flags & LYS_SET_ENUM); |
| 2105 | assert_true(type.flags & LYS_SET_FRDIGITS); |
| 2106 | assert_true(type.flags & LYS_SET_LENGTH); |
| 2107 | assert_true(type.flags & LYS_SET_PATH); |
| 2108 | assert_true(type.flags & LYS_SET_PATTERN); |
| 2109 | assert_true(type.flags & LYS_SET_RANGE); |
| 2110 | assert_true(type.flags & LYS_SET_REQINST); |
| 2111 | assert_true(type.flags & LYS_SET_TYPE); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2112 | lysp_type_free(st->ctx, &type); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 2113 | memset(&type, 0, sizeof(type)); |
| 2114 | |
| 2115 | /* min subelems */ |
| 2116 | data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2117 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 2118 | lysp_type_free(st->ctx, &type); |
| 2119 | memset(&type, 0, sizeof(type)); |
| 2120 | |
| 2121 | st->finished_correctly = true; |
| 2122 | } |
| 2123 | |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2124 | static void |
| 2125 | test_max_elems_elem(void **state) |
| 2126 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2127 | struct test_parser_yin_state *st = *state; |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2128 | const char *data; |
| 2129 | struct lysp_node_list list = {}; |
| 2130 | struct lysp_node_leaflist llist = {}; |
| 2131 | struct lysp_refine refine = {}; |
| 2132 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2133 | data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"unbounded\">"EXT_SUBELEM"</max-elements> </refine>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2134 | assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2135 | assert_int_equal(refine.max, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2136 | assert_true(refine.flags & LYS_SET_MAX); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2137 | assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2138 | assert_int_equal(refine.exts[0].insubstmt_index, 0); |
| 2139 | assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MAX); |
| 2140 | FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2141 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2142 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"5\">"EXT_SUBELEM"</max-elements> </list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2143 | assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_SUCCESS); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2144 | assert_int_equal(list.max, 5); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2145 | assert_true(list.flags & LYS_SET_MAX); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2146 | assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2147 | assert_int_equal(list.exts[0].insubstmt_index, 0); |
| 2148 | assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MAX); |
| 2149 | FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2150 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2151 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"85\">"EXT_SUBELEM"</max-elements> </leaf-list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2152 | assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_SUCCESS); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2153 | assert_int_equal(llist.max, 85); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2154 | assert_true(llist.flags & LYS_SET_MAX); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2155 | assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2156 | assert_int_equal(llist.exts[0].insubstmt_index, 0); |
| 2157 | assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MAX); |
| 2158 | FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2159 | |
| 2160 | data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2161 | assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2162 | assert_int_equal(refine.max, 10); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2163 | assert_true(refine.flags & LYS_SET_MAX); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2164 | |
| 2165 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2166 | assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2167 | 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] | 2168 | |
| 2169 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2170 | assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2171 | 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] | 2172 | |
| 2173 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2174 | assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2175 | 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] | 2176 | |
| 2177 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2178 | assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2179 | 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] | 2180 | |
| 2181 | st->finished_correctly = true; |
| 2182 | } |
| 2183 | |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2184 | static void |
| 2185 | test_min_elems_elem(void **state) |
| 2186 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2187 | struct test_parser_yin_state *st = *state; |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2188 | const char *data; |
| 2189 | struct lysp_node_list list = {}; |
| 2190 | struct lysp_node_leaflist llist = {}; |
| 2191 | struct lysp_refine refine = {}; |
| 2192 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2193 | data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"0\">"EXT_SUBELEM"</min-elements> </refine>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2194 | assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2195 | assert_int_equal(refine.min, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2196 | assert_true(refine.flags & LYS_SET_MIN); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2197 | assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2198 | assert_int_equal(refine.exts[0].insubstmt_index, 0); |
| 2199 | assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MIN); |
| 2200 | FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2201 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2202 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"41\">"EXT_SUBELEM"</min-elements> </list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2203 | assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_SUCCESS); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2204 | assert_int_equal(list.min, 41); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2205 | assert_true(list.flags & LYS_SET_MIN); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2206 | assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2207 | assert_int_equal(list.exts[0].insubstmt_index, 0); |
| 2208 | assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MIN); |
| 2209 | FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2210 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2211 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"50\">"EXT_SUBELEM"</min-elements> </leaf-list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2212 | assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_SUCCESS); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2213 | assert_int_equal(llist.min, 50); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2214 | assert_true(llist.flags & LYS_SET_MIN); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2215 | assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2216 | assert_int_equal(llist.exts[0].insubstmt_index, 0); |
| 2217 | assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MIN); |
| 2218 | FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2219 | |
| 2220 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2221 | assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2222 | 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] | 2223 | |
| 2224 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2225 | assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2226 | 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] | 2227 | |
| 2228 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2229 | assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2230 | 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] | 2231 | |
| 2232 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"05\"/> </leaf-list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2233 | assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2234 | 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] | 2235 | |
| 2236 | st->finished_correctly = true; |
| 2237 | } |
| 2238 | |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2239 | static void |
| 2240 | test_ordby_elem(void **state) |
| 2241 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2242 | struct test_parser_yin_state *st = *state; |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2243 | const char *data; |
| 2244 | uint16_t flags = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2245 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2246 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2247 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\">"EXT_SUBELEM"</ordered-by>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2248 | assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2249 | assert_true(flags & LYS_ORDBY_SYSTEM); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2250 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2251 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 2252 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORDEREDBY); |
| 2253 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2254 | |
| 2255 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2256 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2257 | assert_true(flags & LYS_ORDBY_USER); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2258 | |
| 2259 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2260 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 2261 | logbuf_assert("Invalid value \"inv\" of \"value\" attribute in \"ordered-by\" element. Valid values are \"system\" and \"user\". Line number 1."); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2262 | |
| 2263 | st->finished_correctly = true; |
| 2264 | } |
| 2265 | |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2266 | static void |
| 2267 | test_any_elem(void **state) |
| 2268 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2269 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2270 | const char *data; |
| 2271 | struct lysp_node *siblings = NULL; |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2272 | struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings}; |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2273 | struct lysp_node_anydata *parsed = NULL; |
| 2274 | |
| 2275 | /* anyxml max subelems */ |
| 2276 | data = ELEMENT_WRAPPER_START |
| 2277 | "<anyxml name=\"any-name\">" |
| 2278 | "<config value=\"true\" />" |
| 2279 | "<description><text>desc</text></description>" |
| 2280 | "<if-feature name=\"feature\" />" |
| 2281 | "<mandatory value=\"true\" />" |
| 2282 | "<must condition=\"must-cond\" />" |
| 2283 | "<reference><text>ref</text></reference>" |
| 2284 | "<status value=\"deprecated\"/>" |
| 2285 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2286 | EXT_SUBELEM |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2287 | "</anyxml>" |
| 2288 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2289 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2290 | parsed = (struct lysp_node_anydata *)siblings; |
| 2291 | assert_null(parsed->parent); |
| 2292 | assert_int_equal(parsed->nodetype, LYS_ANYXML); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2293 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2294 | assert_true(parsed->flags & LYS_MAND_TRUE); |
| 2295 | assert_true(parsed->flags & LYS_STATUS_DEPRC); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2296 | assert_null(parsed->next); |
| 2297 | assert_string_equal(parsed->name, "any-name"); |
| 2298 | assert_string_equal(parsed->dsc, "desc"); |
| 2299 | assert_string_equal(parsed->ref, "ref"); |
| 2300 | assert_string_equal(parsed->when->cond, "when-cond"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2301 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2302 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2303 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2304 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2305 | lysp_node_free(st->ctx, siblings); |
| 2306 | siblings = NULL; |
| 2307 | |
| 2308 | /* anydata max subelems */ |
| 2309 | data = ELEMENT_WRAPPER_START |
| 2310 | "<anydata name=\"any-name\">" |
| 2311 | "<config value=\"true\" />" |
| 2312 | "<description><text>desc</text></description>" |
| 2313 | "<if-feature name=\"feature\" />" |
| 2314 | "<mandatory value=\"true\" />" |
| 2315 | "<must condition=\"must-cond\" />" |
| 2316 | "<reference><text>ref</text></reference>" |
| 2317 | "<status value=\"deprecated\"/>" |
| 2318 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2319 | EXT_SUBELEM |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2320 | "</anydata>" |
| 2321 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2322 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2323 | parsed = (struct lysp_node_anydata *)siblings; |
| 2324 | assert_null(parsed->parent); |
| 2325 | assert_int_equal(parsed->nodetype, LYS_ANYDATA); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2326 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2327 | assert_true(parsed->flags & LYS_MAND_TRUE); |
| 2328 | assert_true(parsed->flags & LYS_STATUS_DEPRC); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2329 | assert_null(parsed->next); |
| 2330 | assert_string_equal(parsed->name, "any-name"); |
| 2331 | assert_string_equal(parsed->dsc, "desc"); |
| 2332 | assert_string_equal(parsed->ref, "ref"); |
| 2333 | assert_string_equal(parsed->when->cond, "when-cond"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2334 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2335 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2336 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2337 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2338 | lysp_node_free(st->ctx, siblings); |
| 2339 | siblings = NULL; |
| 2340 | |
| 2341 | /* min subelems */ |
| 2342 | node_meta.parent = (void *)0x10; |
| 2343 | data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2344 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2345 | parsed = (struct lysp_node_anydata *)siblings; |
| 2346 | assert_ptr_equal(parsed->parent, node_meta.parent); |
| 2347 | assert_int_equal(parsed->nodetype, LYS_ANYDATA); |
| 2348 | assert_null(parsed->next); |
| 2349 | assert_null(parsed->exts); |
| 2350 | lysp_node_free(st->ctx, siblings); |
| 2351 | |
| 2352 | st->finished_correctly = true; |
| 2353 | } |
| 2354 | |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2355 | static void |
| 2356 | test_leaf_elem(void **state) |
| 2357 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2358 | struct test_parser_yin_state *st = *state; |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2359 | const char *data; |
| 2360 | struct lysp_node *siblings = NULL; |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2361 | struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings}; |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2362 | struct lysp_node_leaf *parsed = NULL; |
| 2363 | |
| 2364 | /* max elements */ |
| 2365 | data = ELEMENT_WRAPPER_START |
| 2366 | "<leaf name=\"leaf\">" |
| 2367 | "<config value=\"true\" />" |
| 2368 | "<default value=\"def-val\"/>" |
| 2369 | "<description><text>desc</text></description>" |
| 2370 | "<if-feature name=\"feature\" />" |
| 2371 | "<mandatory value=\"true\" />" |
| 2372 | "<must condition=\"must-cond\" />" |
| 2373 | "<reference><text>ref</text></reference>" |
| 2374 | "<status value=\"deprecated\"/>" |
| 2375 | "<type name=\"type\"/>" |
| 2376 | "<units name=\"uni\"/>" |
| 2377 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2378 | EXT_SUBELEM |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2379 | "</leaf>" |
| 2380 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2381 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2382 | parsed = (struct lysp_node_leaf *)siblings; |
| 2383 | assert_null(parsed->parent); |
| 2384 | assert_int_equal(parsed->nodetype, LYS_LEAF); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2385 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2386 | assert_true(parsed->flags & LYS_MAND_TRUE); |
| 2387 | assert_true(parsed->flags & LYS_STATUS_DEPRC); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2388 | assert_null(parsed->next); |
| 2389 | assert_string_equal(parsed->name, "leaf"); |
| 2390 | assert_string_equal(parsed->dsc, "desc"); |
| 2391 | assert_string_equal(parsed->ref, "ref"); |
| 2392 | assert_string_equal(parsed->when->cond, "when-cond"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2393 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2394 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2395 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2396 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2397 | assert_string_equal(parsed->musts->arg.str, "must-cond"); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2398 | assert_string_equal(parsed->type.name, "type"); |
| 2399 | assert_string_equal(parsed->units, "uni"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2400 | assert_string_equal(parsed->dflt.str, "def-val"); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2401 | lysp_node_free(st->ctx, siblings); |
| 2402 | siblings = NULL; |
| 2403 | |
| 2404 | /* min elements */ |
| 2405 | data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2406 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2407 | parsed = (struct lysp_node_leaf *)siblings; |
| 2408 | assert_string_equal(parsed->name, "leaf"); |
| 2409 | assert_string_equal(parsed->type.name, "type"); |
| 2410 | lysp_node_free(st->ctx, siblings); |
| 2411 | siblings = NULL; |
| 2412 | |
| 2413 | st->finished_correctly = true; |
| 2414 | } |
| 2415 | |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2416 | static void |
| 2417 | test_leaf_list_elem(void **state) |
| 2418 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2419 | struct test_parser_yin_state *st = *state; |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2420 | const char *data; |
| 2421 | struct lysp_node *siblings = NULL; |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2422 | struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings}; |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2423 | struct lysp_node_leaflist *parsed = NULL; |
| 2424 | |
| 2425 | data = ELEMENT_WRAPPER_START |
| 2426 | "<leaf-list name=\"llist\">" |
| 2427 | "<config value=\"true\" />" |
| 2428 | "<default value=\"def-val0\"/>" |
| 2429 | "<default value=\"def-val1\"/>" |
| 2430 | "<description><text>desc</text></description>" |
| 2431 | "<if-feature name=\"feature\"/>" |
| 2432 | "<max-elements value=\"5\"/>" |
| 2433 | "<must condition=\"must-cond\"/>" |
| 2434 | "<ordered-by value=\"user\" />" |
| 2435 | "<reference><text>ref</text></reference>" |
| 2436 | "<status value=\"current\"/>" |
| 2437 | "<type name=\"type\"/>" |
| 2438 | "<units name=\"uni\"/>" |
| 2439 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2440 | EXT_SUBELEM |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2441 | "</leaf-list>" |
| 2442 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2443 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2444 | parsed = (struct lysp_node_leaflist *)siblings; |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2445 | assert_string_equal(parsed->dflts[0].str, "def-val0"); |
| 2446 | assert_string_equal(parsed->dflts[1].str, "def-val1"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2447 | assert_string_equal(parsed->dsc, "desc"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2448 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2449 | assert_int_equal(parsed->max, 5); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2450 | assert_string_equal(parsed->musts->arg.str, "must-cond"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2451 | assert_string_equal(parsed->name, "llist"); |
| 2452 | assert_null(parsed->next); |
| 2453 | assert_int_equal(parsed->nodetype, LYS_LEAFLIST); |
| 2454 | assert_null(parsed->parent); |
| 2455 | assert_string_equal(parsed->ref, "ref"); |
| 2456 | assert_string_equal(parsed->type.name, "type"); |
| 2457 | assert_string_equal(parsed->units, "uni"); |
| 2458 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2459 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2460 | assert_true(parsed->flags & LYS_ORDBY_USER); |
| 2461 | assert_true(parsed->flags & LYS_STATUS_CURR); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2462 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2463 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2464 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2465 | lysp_node_free(st->ctx, siblings); |
| 2466 | siblings = NULL; |
| 2467 | |
| 2468 | data = ELEMENT_WRAPPER_START |
| 2469 | "<leaf-list name=\"llist\">" |
| 2470 | "<config value=\"true\" />" |
| 2471 | "<description><text>desc</text></description>" |
| 2472 | "<if-feature name=\"feature\"/>" |
| 2473 | "<min-elements value=\"5\"/>" |
| 2474 | "<must condition=\"must-cond\"/>" |
| 2475 | "<ordered-by value=\"user\" />" |
| 2476 | "<reference><text>ref</text></reference>" |
| 2477 | "<status value=\"current\"/>" |
| 2478 | "<type name=\"type\"/>" |
| 2479 | "<units name=\"uni\"/>" |
| 2480 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2481 | EXT_SUBELEM |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2482 | "</leaf-list>" |
| 2483 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2484 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2485 | parsed = (struct lysp_node_leaflist *)siblings; |
| 2486 | assert_string_equal(parsed->dsc, "desc"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2487 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2488 | assert_int_equal(parsed->min, 5); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2489 | assert_string_equal(parsed->musts->arg.str, "must-cond"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2490 | assert_string_equal(parsed->name, "llist"); |
| 2491 | assert_null(parsed->next); |
| 2492 | assert_int_equal(parsed->nodetype, LYS_LEAFLIST); |
| 2493 | assert_null(parsed->parent); |
| 2494 | assert_string_equal(parsed->ref, "ref"); |
| 2495 | assert_string_equal(parsed->type.name, "type"); |
| 2496 | assert_string_equal(parsed->units, "uni"); |
| 2497 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2498 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2499 | assert_true(parsed->flags & LYS_ORDBY_USER); |
| 2500 | assert_true(parsed->flags & LYS_STATUS_CURR); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2501 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2502 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2503 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2504 | lysp_node_free(st->ctx, siblings); |
| 2505 | siblings = NULL; |
| 2506 | |
| 2507 | data = ELEMENT_WRAPPER_START |
| 2508 | "<leaf-list name=\"llist\">" |
| 2509 | "<config value=\"true\" />" |
| 2510 | "<description><text>desc</text></description>" |
| 2511 | "<if-feature name=\"feature\"/>" |
| 2512 | "<max-elements value=\"15\"/>" |
| 2513 | "<min-elements value=\"5\"/>" |
| 2514 | "<must condition=\"must-cond\"/>" |
| 2515 | "<ordered-by value=\"user\" />" |
| 2516 | "<reference><text>ref</text></reference>" |
| 2517 | "<status value=\"current\"/>" |
| 2518 | "<type name=\"type\"/>" |
| 2519 | "<units name=\"uni\"/>" |
| 2520 | "<when condition=\"when-cond\"/>" |
| 2521 | "</leaf-list>" |
| 2522 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2523 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2524 | parsed = (struct lysp_node_leaflist *)siblings; |
| 2525 | assert_string_equal(parsed->dsc, "desc"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2526 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2527 | assert_int_equal(parsed->min, 5); |
| 2528 | assert_int_equal(parsed->max, 15); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2529 | assert_string_equal(parsed->musts->arg.str, "must-cond"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2530 | assert_string_equal(parsed->name, "llist"); |
| 2531 | assert_null(parsed->next); |
| 2532 | assert_int_equal(parsed->nodetype, LYS_LEAFLIST); |
| 2533 | assert_null(parsed->parent); |
| 2534 | assert_string_equal(parsed->ref, "ref"); |
| 2535 | assert_string_equal(parsed->type.name, "type"); |
| 2536 | assert_string_equal(parsed->units, "uni"); |
| 2537 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2538 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2539 | assert_true(parsed->flags & LYS_ORDBY_USER); |
| 2540 | assert_true(parsed->flags & LYS_STATUS_CURR); |
| 2541 | lysp_node_free(st->ctx, siblings); |
| 2542 | siblings = NULL; |
| 2543 | |
| 2544 | data = ELEMENT_WRAPPER_START |
| 2545 | "<leaf-list name=\"llist\">" |
| 2546 | "<type name=\"type\"/>" |
| 2547 | "</leaf-list>" |
| 2548 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2549 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2550 | parsed = (struct lysp_node_leaflist *)siblings; |
| 2551 | assert_string_equal(parsed->name, "llist"); |
| 2552 | assert_string_equal(parsed->type.name, "type"); |
| 2553 | lysp_node_free(st->ctx, siblings); |
| 2554 | siblings = NULL; |
| 2555 | |
| 2556 | /* invalid combinations */ |
| 2557 | data = ELEMENT_WRAPPER_START |
| 2558 | "<leaf-list name=\"llist\">" |
| 2559 | "<max-elements value=\"5\"/>" |
| 2560 | "<min-elements value=\"15\"/>" |
| 2561 | "<type name=\"type\"/>" |
| 2562 | "</leaf-list>" |
| 2563 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2564 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2565 | logbuf_assert("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5. Line number 1."); |
| 2566 | lysp_node_free(st->ctx, siblings); |
| 2567 | siblings = NULL; |
| 2568 | |
| 2569 | data = ELEMENT_WRAPPER_START |
| 2570 | "<leaf-list name=\"llist\">" |
| 2571 | "<default value=\"def-val1\"/>" |
| 2572 | "<min-elements value=\"15\"/>" |
| 2573 | "<type name=\"type\"/>" |
| 2574 | "</leaf-list>" |
| 2575 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2576 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2577 | 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] | 2578 | lysp_node_free(st->ctx, siblings); |
| 2579 | siblings = NULL; |
| 2580 | |
| 2581 | data = ELEMENT_WRAPPER_START |
| 2582 | "<leaf-list name=\"llist\">" |
| 2583 | "</leaf-list>" |
| 2584 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2585 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2586 | 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] | 2587 | lysp_node_free(st->ctx, siblings); |
| 2588 | siblings = NULL; |
| 2589 | |
| 2590 | st->finished_correctly = true; |
| 2591 | } |
| 2592 | |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2593 | static void |
| 2594 | test_presence_elem(void **state) |
| 2595 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2596 | struct test_parser_yin_state *st = *state; |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2597 | const char *data; |
| 2598 | const char *val; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2599 | struct lysp_ext_instance *exts = NULL; |
| 2600 | |
| 2601 | data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\">"EXT_SUBELEM"</presence>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2602 | assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2603 | assert_string_equal(val, "presence-val"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2604 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2605 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 2606 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PRESENCE); |
| 2607 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 2608 | FREE_STRING(st->ctx, val); |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2609 | |
| 2610 | data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2611 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2612 | assert_string_equal(val, "presence-val"); |
| 2613 | FREE_STRING(st->ctx, val); |
| 2614 | |
| 2615 | data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2616 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID); |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2617 | logbuf_assert("Missing mandatory attribute value of presence element. Line number 1."); |
| 2618 | |
| 2619 | st->finished_correctly = true; |
| 2620 | } |
| 2621 | |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2622 | static void |
| 2623 | test_key_elem(void **state) |
| 2624 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2625 | struct test_parser_yin_state *st = *state; |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2626 | const char *data; |
| 2627 | const char *val; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2628 | struct lysp_ext_instance *exts = NULL; |
| 2629 | |
| 2630 | data = ELEMENT_WRAPPER_START "<key value=\"key-value\">"EXT_SUBELEM"</key>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2631 | assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2632 | assert_string_equal(val, "key-value"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2633 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2634 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 2635 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_KEY); |
| 2636 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 2637 | FREE_STRING(st->ctx, val); |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2638 | |
| 2639 | data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2640 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2641 | assert_string_equal(val, "key-value"); |
| 2642 | FREE_STRING(st->ctx, val); |
| 2643 | |
| 2644 | data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2645 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID); |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2646 | logbuf_assert("Missing mandatory attribute value of key element. Line number 1."); |
| 2647 | |
| 2648 | st->finished_correctly = true; |
| 2649 | } |
| 2650 | |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2651 | static void |
| 2652 | test_typedef_elem(void **state) |
| 2653 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2654 | struct test_parser_yin_state *st = *state; |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2655 | const char *data; |
| 2656 | struct lysp_tpdf *tpdfs = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 2657 | struct tree_node_meta typdef_meta = {NULL, (struct lysp_node **)&tpdfs}; |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2658 | |
| 2659 | data = ELEMENT_WRAPPER_START |
| 2660 | "<typedef name=\"tpdf-name\">" |
| 2661 | "<default value=\"def-val\"/>" |
| 2662 | "<description><text>desc-text</text></description>" |
| 2663 | "<reference><text>ref-text</text></reference>" |
| 2664 | "<status value=\"current\"/>" |
| 2665 | "<type name=\"type\"/>" |
| 2666 | "<units name=\"uni\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2667 | EXT_SUBELEM |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2668 | "</typedef>" |
| 2669 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2670 | assert_int_equal(test_element_helper(st, data, &typdef_meta, NULL, NULL), LY_SUCCESS); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2671 | assert_string_equal(tpdfs[0].dflt.str, "def-val"); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2672 | assert_string_equal(tpdfs[0].dsc, "desc-text"); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2673 | assert_string_equal(tpdfs[0].name, "tpdf-name"); |
| 2674 | assert_string_equal(tpdfs[0].ref, "ref-text"); |
| 2675 | assert_string_equal(tpdfs[0].type.name, "type"); |
| 2676 | assert_string_equal(tpdfs[0].units, "uni"); |
| 2677 | assert_true(tpdfs[0].flags & LYS_STATUS_CURR); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2678 | assert_string_equal(tpdfs[0].exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2679 | assert_int_equal(tpdfs[0].exts[0].insubstmt_index, 0); |
| 2680 | assert_int_equal(tpdfs[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2681 | FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free); |
| 2682 | tpdfs = NULL; |
| 2683 | |
| 2684 | data = ELEMENT_WRAPPER_START |
| 2685 | "<typedef name=\"tpdf-name\">" |
| 2686 | "<type name=\"type\"/>" |
| 2687 | "</typedef>" |
| 2688 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2689 | assert_int_equal(test_element_helper(st, data, &typdef_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2690 | assert_string_equal(tpdfs[0].name, "tpdf-name"); |
| 2691 | assert_string_equal(tpdfs[0].type.name, "type"); |
| 2692 | FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free); |
| 2693 | tpdfs = NULL; |
| 2694 | |
| 2695 | st->finished_correctly = true; |
| 2696 | } |
| 2697 | |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2698 | static void |
| 2699 | test_refine_elem(void **state) |
| 2700 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2701 | struct test_parser_yin_state *st = *state; |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2702 | const char *data; |
| 2703 | struct lysp_refine *refines = NULL; |
| 2704 | |
| 2705 | /* max subelems */ |
| 2706 | data = ELEMENT_WRAPPER_START |
| 2707 | "<refine target-node=\"target\">" |
| 2708 | "<if-feature name=\"feature\" />" |
| 2709 | "<must condition=\"cond\" />" |
| 2710 | "<presence value=\"presence\" />" |
| 2711 | "<default value=\"def\" />" |
| 2712 | "<config value=\"true\" />" |
| 2713 | "<mandatory value=\"true\" />" |
| 2714 | "<min-elements value=\"10\" />" |
| 2715 | "<max-elements value=\"20\" />" |
| 2716 | "<description><text>desc</text></description>" |
| 2717 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2718 | EXT_SUBELEM |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2719 | "</refine>" |
| 2720 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2721 | assert_int_equal(test_element_helper(st, data, &refines, NULL, NULL), LY_SUCCESS); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2722 | assert_string_equal(refines->nodeid, "target"); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2723 | assert_string_equal(refines->dflts[0].str, "def"); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2724 | assert_string_equal(refines->dsc, "desc"); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2725 | assert_true(refines->flags & LYS_CONFIG_W); |
| 2726 | assert_true(refines->flags & LYS_MAND_TRUE); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2727 | assert_string_equal(refines->iffeatures[0].str, "feature"); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2728 | assert_int_equal(refines->max, 20); |
| 2729 | assert_int_equal(refines->min, 10); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2730 | assert_string_equal(refines->musts->arg.str, "cond"); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2731 | assert_string_equal(refines->presence, "presence"); |
| 2732 | assert_string_equal(refines->ref, "ref"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2733 | assert_string_equal(refines->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2734 | assert_int_equal(refines->exts[0].insubstmt_index, 0); |
| 2735 | assert_int_equal(refines->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2736 | FREE_ARRAY(st->ctx, refines, lysp_refine_free); |
| 2737 | refines = NULL; |
| 2738 | |
| 2739 | /* min subelems */ |
| 2740 | data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2741 | assert_int_equal(test_element_helper(st, data, &refines, NULL, NULL), LY_SUCCESS); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2742 | assert_string_equal(refines->nodeid, "target"); |
| 2743 | FREE_ARRAY(st->ctx, refines, lysp_refine_free); |
| 2744 | refines = NULL; |
| 2745 | |
| 2746 | st->finished_correctly = true; |
| 2747 | } |
| 2748 | |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2749 | static void |
| 2750 | test_uses_elem(void **state) |
| 2751 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2752 | struct test_parser_yin_state *st = *state; |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2753 | const char *data; |
| 2754 | struct lysp_node *siblings = NULL; |
| 2755 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2756 | struct lysp_node_uses *parsed = NULL; |
| 2757 | |
| 2758 | /* max subelems */ |
| 2759 | data = ELEMENT_WRAPPER_START |
| 2760 | "<uses name=\"uses-name\">" |
| 2761 | "<when condition=\"cond\" />" |
| 2762 | "<if-feature name=\"feature\" />" |
| 2763 | "<status value=\"obsolete\" />" |
| 2764 | "<description><text>desc</text></description>" |
| 2765 | "<reference><text>ref</text></reference>" |
| 2766 | "<refine target-node=\"target\"/>" |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2767 | "<augment target-node=\"target\" />" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2768 | EXT_SUBELEM |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2769 | "</uses>" |
| 2770 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2771 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2772 | parsed = (struct lysp_node_uses *)&siblings[0]; |
| 2773 | assert_string_equal(parsed->name, "uses-name"); |
| 2774 | assert_string_equal(parsed->dsc, "desc"); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2775 | assert_true(parsed->flags & LYS_STATUS_OBSLT); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2776 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2777 | assert_null(parsed->next); |
| 2778 | assert_int_equal(parsed->nodetype, LYS_USES); |
| 2779 | assert_null(parsed->parent); |
| 2780 | assert_string_equal(parsed->ref, "ref"); |
| 2781 | assert_string_equal(parsed->refines->nodeid, "target"); |
| 2782 | assert_string_equal(parsed->when->cond, "cond"); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2783 | assert_string_equal(parsed->augments->nodeid, "target"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2784 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2785 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2786 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2787 | lysp_node_free(st->ctx, siblings); |
| 2788 | siblings = NULL; |
| 2789 | |
| 2790 | /* min subelems */ |
| 2791 | data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2792 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2793 | assert_string_equal(siblings[0].name, "uses-name"); |
| 2794 | lysp_node_free(st->ctx, siblings); |
| 2795 | siblings = NULL; |
| 2796 | |
| 2797 | st->finished_correctly = true; |
| 2798 | } |
| 2799 | |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2800 | static void |
| 2801 | test_revision_elem(void **state) |
| 2802 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2803 | struct test_parser_yin_state *st = *state; |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2804 | const char *data; |
| 2805 | struct lysp_revision *revs = NULL; |
| 2806 | |
| 2807 | /* max subelems */ |
| 2808 | data = ELEMENT_WRAPPER_START |
| 2809 | "<revision date=\"2018-12-25\">" |
| 2810 | "<description><text>desc</text></description>" |
| 2811 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2812 | EXT_SUBELEM |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2813 | "</revision>" |
| 2814 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2815 | assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_SUCCESS); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2816 | assert_string_equal(revs->date, "2018-12-25"); |
| 2817 | assert_string_equal(revs->dsc, "desc"); |
| 2818 | assert_string_equal(revs->ref, "ref"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2819 | assert_string_equal(revs->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2820 | assert_int_equal(revs->exts[0].insubstmt_index, 0); |
| 2821 | assert_int_equal(revs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2822 | FREE_ARRAY(st->ctx, revs, lysp_revision_free); |
| 2823 | revs = NULL; |
| 2824 | |
| 2825 | /* min subelems */ |
| 2826 | data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2827 | assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_SUCCESS); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2828 | assert_string_equal(revs->date, "2005-05-05"); |
| 2829 | FREE_ARRAY(st->ctx, revs, lysp_revision_free); |
| 2830 | revs = NULL; |
| 2831 | |
| 2832 | /* invalid value */ |
| 2833 | data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2834 | assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_EVALID); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2835 | logbuf_assert("Invalid value \"05-05-2005\" of \"revision\". Line number 1."); |
| 2836 | FREE_ARRAY(st->ctx, revs, lysp_revision_free); |
| 2837 | revs = NULL; |
| 2838 | |
| 2839 | st->finished_correctly = true; |
| 2840 | } |
| 2841 | |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2842 | static void |
| 2843 | test_include_elem(void **state) |
| 2844 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2845 | struct test_parser_yin_state *st = *state; |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2846 | const char *data; |
| 2847 | struct lysp_include *includes = NULL; |
| 2848 | struct include_meta inc_meta = {"module-name", &includes}; |
| 2849 | |
| 2850 | /* max subelems */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2851 | st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2852 | data = ELEMENT_WRAPPER_START |
| 2853 | "<include module=\"mod\">" |
| 2854 | "<description><text>desc</text></description>" |
| 2855 | "<reference><text>ref</text></reference>" |
| 2856 | "<revision-date date=\"1999-09-09\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2857 | EXT_SUBELEM |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2858 | "</include>" |
| 2859 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2860 | assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2861 | assert_string_equal(includes->name, "mod"); |
| 2862 | assert_string_equal(includes->dsc, "desc"); |
| 2863 | assert_string_equal(includes->ref, "ref"); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2864 | assert_string_equal(includes->rev, "1999-09-09"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2865 | assert_string_equal(includes->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2866 | assert_int_equal(includes->exts[0].insubstmt_index, 0); |
| 2867 | assert_int_equal(includes->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2868 | FREE_ARRAY(st->ctx, includes, lysp_include_free); |
| 2869 | includes = NULL; |
| 2870 | |
| 2871 | /* min subelems */ |
| 2872 | data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2873 | assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2874 | assert_string_equal(includes->name, "mod"); |
| 2875 | FREE_ARRAY(st->ctx, includes, lysp_include_free); |
| 2876 | includes = NULL; |
| 2877 | |
| 2878 | /* invalid combinations */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2879 | st->yin_ctx->parsed_mod->version = LYS_VERSION_1_0; |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2880 | data = ELEMENT_WRAPPER_START |
| 2881 | "<include module=\"mod\">" |
| 2882 | "<description><text>desc</text></description>" |
| 2883 | "<revision-date date=\"1999-09-09\"/>" |
| 2884 | "</include>" |
| 2885 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2886 | assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_EVALID); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2887 | 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."); |
| 2888 | FREE_ARRAY(st->ctx, includes, lysp_include_free); |
| 2889 | includes = NULL; |
| 2890 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2891 | st->yin_ctx->parsed_mod->version = LYS_VERSION_1_0; |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2892 | data = ELEMENT_WRAPPER_START |
| 2893 | "<include module=\"mod\">" |
| 2894 | "<reference><text>ref</text></reference>" |
| 2895 | "<revision-date date=\"1999-09-09\"/>" |
| 2896 | "</include>" |
| 2897 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2898 | assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_EVALID); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2899 | 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."); |
| 2900 | FREE_ARRAY(st->ctx, includes, lysp_include_free); |
| 2901 | includes = NULL; |
| 2902 | |
| 2903 | st->finished_correctly = true; |
| 2904 | } |
| 2905 | |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 2906 | static void |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2907 | test_list_elem(void **state) |
| 2908 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2909 | struct test_parser_yin_state *st = *state; |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2910 | const char *data; |
| 2911 | struct lysp_node *siblings = NULL; |
| 2912 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2913 | struct lysp_node_list *parsed = NULL; |
| 2914 | |
| 2915 | /* max subelems */ |
| 2916 | data = ELEMENT_WRAPPER_START |
| 2917 | "<list name=\"list-name\">" |
| 2918 | "<when condition=\"when\"/>" |
| 2919 | "<if-feature name=\"iff\"/>" |
| 2920 | "<must condition=\"must-cond\"/>" |
| 2921 | "<key value=\"key\"/>" |
| 2922 | "<unique tag=\"utag\"/>" |
| 2923 | "<config value=\"true\"/>" |
| 2924 | "<min-elements value=\"10\"/>" |
| 2925 | "<ordered-by value=\"user\"/>" |
| 2926 | "<status value=\"deprecated\"/>" |
| 2927 | "<description><text>desc</text></description>" |
| 2928 | "<reference><text>ref</text></reference>" |
| 2929 | "<anydata name=\"anyd\"/>" |
| 2930 | "<anyxml name=\"anyx\"/>" |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2931 | "<container name=\"cont\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2932 | "<choice name=\"choice\"/>" |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2933 | "<action name=\"action\"/>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2934 | "<grouping name=\"grp\"/>" |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2935 | "<notification name=\"notf\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2936 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 2937 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2938 | "<list name=\"sub-list\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2939 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2940 | "<uses name=\"uses-name\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2941 | EXT_SUBELEM |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2942 | "</list>" |
| 2943 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2944 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2945 | parsed = (struct lysp_node_list *)&siblings[0]; |
| 2946 | assert_string_equal(parsed->dsc, "desc"); |
| 2947 | assert_string_equal(parsed->child->name, "anyd"); |
| 2948 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 2949 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 2950 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2951 | assert_string_equal(parsed->child->next->next->name, "cont"); |
| 2952 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2953 | assert_string_equal(parsed->child->next->next->next->name, "choice"); |
| 2954 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2955 | assert_string_equal(parsed->child->next->next->next->next->name, "leaf"); |
| 2956 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF); |
| 2957 | assert_string_equal(parsed->child->next->next->next->next->next->name, "llist"); |
| 2958 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2959 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list"); |
| 2960 | assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 2961 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name"); |
| 2962 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 2963 | 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] | 2964 | assert_string_equal(parsed->groupings->name, "grp"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2965 | assert_string_equal(parsed->actions->name, "action"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2966 | assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2967 | assert_string_equal(parsed->notifs->name, "notf"); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2968 | assert_true(parsed->flags & LYS_ORDBY_USER); |
| 2969 | assert_true(parsed->flags & LYS_STATUS_DEPRC); |
| 2970 | assert_true(parsed->flags & LYS_CONFIG_W); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2971 | assert_string_equal(parsed->iffeatures[0].str, "iff"); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2972 | assert_string_equal(parsed->key, "key"); |
| 2973 | assert_int_equal(parsed->min, 10); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2974 | assert_string_equal(parsed->musts->arg.str, "must-cond"); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2975 | assert_string_equal(parsed->name, "list-name"); |
| 2976 | assert_null(parsed->next); |
| 2977 | assert_int_equal(parsed->nodetype, LYS_LIST); |
| 2978 | assert_null(parsed->parent); |
| 2979 | assert_string_equal(parsed->ref, "ref"); |
| 2980 | assert_string_equal(parsed->typedefs->name, "tpdf"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2981 | assert_string_equal(parsed->uniques->str, "utag"); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2982 | assert_string_equal(parsed->when->cond, "when"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2983 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2984 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2985 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2986 | lysp_node_free(st->ctx, siblings); |
| 2987 | ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL); |
| 2988 | siblings = NULL; |
| 2989 | |
| 2990 | /* min subelems */ |
| 2991 | data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2992 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2993 | parsed = (struct lysp_node_list *)&siblings[0]; |
| 2994 | assert_string_equal(parsed->name, "list-name"); |
| 2995 | lysp_node_free(st->ctx, siblings); |
| 2996 | siblings = NULL; |
| 2997 | |
| 2998 | st->finished_correctly = true; |
| 2999 | } |
| 3000 | |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3001 | static void |
| 3002 | test_notification_elem(void **state) |
| 3003 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3004 | struct test_parser_yin_state *st = *state; |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3005 | const char *data; |
| 3006 | struct lysp_notif *notifs = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 3007 | struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)¬ifs}; |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3008 | |
| 3009 | /* max subelems */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3010 | st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3011 | data = ELEMENT_WRAPPER_START |
| 3012 | "<notification name=\"notif-name\">" |
| 3013 | "<anydata name=\"anyd\"/>" |
| 3014 | "<anyxml name=\"anyx\"/>" |
| 3015 | "<description><text>desc</text></description>" |
| 3016 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3017 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3018 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3019 | "<list name=\"sub-list\"/>" |
| 3020 | "<must condition=\"cond\"/>" |
| 3021 | "<reference><text>ref</text></reference>" |
| 3022 | "<status value=\"deprecated\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3023 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3024 | "<uses name=\"uses-name\"/>" |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3025 | "<container name=\"cont\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3026 | "<choice name=\"choice\"/>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3027 | "<grouping name=\"grp\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3028 | EXT_SUBELEM |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3029 | "</notification>" |
| 3030 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3031 | assert_int_equal(test_element_helper(st, data, ¬if_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3032 | assert_string_equal(notifs->name, "notif-name"); |
| 3033 | assert_string_equal(notifs->data->name, "anyd"); |
| 3034 | assert_int_equal(notifs->data->nodetype, LYS_ANYDATA); |
| 3035 | assert_string_equal(notifs->data->next->name, "anyx"); |
| 3036 | assert_int_equal(notifs->data->next->nodetype, LYS_ANYXML); |
| 3037 | assert_string_equal(notifs->data->next->next->name, "leaf"); |
| 3038 | assert_int_equal(notifs->data->next->next->nodetype, LYS_LEAF); |
| 3039 | assert_string_equal(notifs->data->next->next->next->name, "llist"); |
| 3040 | assert_int_equal(notifs->data->next->next->next->nodetype, LYS_LEAFLIST); |
| 3041 | assert_string_equal(notifs->data->next->next->next->next->name, "sub-list"); |
| 3042 | 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] | 3043 | assert_true(notifs->flags & LYS_STATUS_DEPRC); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3044 | assert_string_equal(notifs->groupings->name, "grp"); |
| 3045 | assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3046 | assert_string_equal(notifs->data->next->next->next->next->next->name, "uses-name"); |
| 3047 | assert_int_equal(notifs->data->next->next->next->next->next->nodetype, LYS_USES); |
| 3048 | assert_string_equal(notifs->data->next->next->next->next->next->next->name, "cont"); |
| 3049 | 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] | 3050 | assert_int_equal(notifs->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 3051 | assert_string_equal(notifs->data->next->next->next->next->next->next->next->name, "choice"); |
| 3052 | assert_null(notifs->data->next->next->next->next->next->next->next->next); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3053 | assert_string_equal(notifs->iffeatures[0].str, "iff"); |
| 3054 | assert_string_equal(notifs->musts->arg.str, "cond"); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3055 | assert_int_equal(notifs->nodetype, LYS_NOTIF); |
| 3056 | assert_null(notifs->parent); |
| 3057 | assert_string_equal(notifs->ref, "ref"); |
| 3058 | assert_string_equal(notifs->typedefs->name, "tpdf"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3059 | assert_string_equal(notifs->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3060 | assert_int_equal(notifs->exts[0].insubstmt_index, 0); |
| 3061 | assert_int_equal(notifs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3062 | FREE_ARRAY(st->ctx, notifs, lysp_notif_free); |
| 3063 | notifs = NULL; |
| 3064 | |
| 3065 | /* min subelems */ |
| 3066 | data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3067 | assert_int_equal(test_element_helper(st, data, ¬if_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3068 | assert_string_equal(notifs->name, "notif-name"); |
| 3069 | FREE_ARRAY(st->ctx, notifs, lysp_notif_free); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3070 | notifs = NULL; |
| 3071 | |
| 3072 | st->finished_correctly = true; |
| 3073 | } |
| 3074 | |
| 3075 | static void |
| 3076 | test_grouping_elem(void **state) |
| 3077 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3078 | struct test_parser_yin_state *st = *state; |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3079 | const char *data; |
| 3080 | struct lysp_grp *grps = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 3081 | struct tree_node_meta grp_meta = {NULL, (struct lysp_node **)&grps}; |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3082 | |
| 3083 | /* max subelems */ |
| 3084 | data = ELEMENT_WRAPPER_START |
| 3085 | "<grouping name=\"grp-name\">" |
| 3086 | "<anydata name=\"anyd\"/>" |
| 3087 | "<anyxml name=\"anyx\"/>" |
| 3088 | "<description><text>desc</text></description>" |
| 3089 | "<grouping name=\"sub-grp\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3090 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3091 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3092 | "<list name=\"list\"/>" |
| 3093 | "<notification name=\"notf\"/>" |
| 3094 | "<reference><text>ref</text></reference>" |
| 3095 | "<status value=\"current\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3096 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3097 | "<uses name=\"uses-name\"/>" |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3098 | "<action name=\"act\"/>" |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3099 | "<container name=\"cont\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3100 | "<choice name=\"choice\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3101 | EXT_SUBELEM |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3102 | "</grouping>" |
| 3103 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3104 | assert_int_equal(test_element_helper(st, data, &grp_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3105 | assert_string_equal(grps->name, "grp-name"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3106 | assert_string_equal(grps->data->name, "anyd"); |
| 3107 | assert_string_equal(grps->data->next->name, "anyx"); |
| 3108 | assert_string_equal(grps->data->next->next->name, "leaf"); |
| 3109 | assert_string_equal(grps->data->next->next->next->name, "llist"); |
| 3110 | assert_string_equal(grps->data->next->next->next->next->name, "list"); |
| 3111 | assert_string_equal(grps->dsc, "desc"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3112 | assert_true(grps->flags & LYS_STATUS_CURR); |
| 3113 | assert_string_equal(grps->groupings->name, "sub-grp"); |
| 3114 | assert_int_equal(grps->nodetype, LYS_GROUPING); |
| 3115 | assert_string_equal(grps->notifs->name, "notf"); |
| 3116 | assert_null(grps->parent); |
| 3117 | assert_string_equal(grps->ref, "ref"); |
| 3118 | assert_string_equal(grps->typedefs->name, "tpdf"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3119 | assert_string_equal(grps->actions->name, "act"); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3120 | 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] | 3121 | 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] | 3122 | 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] | 3123 | assert_int_equal(grps->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER); |
| 3124 | assert_string_equal(grps->data->next->next->next->next->next->next->next->name, "choice"); |
| 3125 | assert_int_equal(grps->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3126 | assert_string_equal(grps->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3127 | assert_int_equal(grps->exts[0].insubstmt_index, 0); |
| 3128 | assert_int_equal(grps->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3129 | FREE_ARRAY(st->ctx, grps, lysp_grp_free); |
| 3130 | grps = NULL; |
| 3131 | |
| 3132 | /* min subelems */ |
| 3133 | data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3134 | assert_int_equal(test_element_helper(st, data, &grp_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3135 | assert_string_equal(grps->name, "grp-name"); |
| 3136 | FREE_ARRAY(st->ctx, grps, lysp_grp_free); |
| 3137 | grps = NULL; |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3138 | |
| 3139 | st->finished_correctly = true; |
| 3140 | } |
| 3141 | |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3142 | static void |
| 3143 | test_container_elem(void **state) |
| 3144 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3145 | struct test_parser_yin_state *st = *state; |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3146 | const char *data; |
| 3147 | struct lysp_node *siblings = NULL; |
| 3148 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 3149 | struct lysp_node_container *parsed = NULL; |
| 3150 | |
| 3151 | /* max subelems */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3152 | st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3153 | data = ELEMENT_WRAPPER_START |
| 3154 | "<container name=\"cont-name\">" |
| 3155 | "<anydata name=\"anyd\"/>" |
| 3156 | "<anyxml name=\"anyx\"/>" |
| 3157 | "<config value=\"true\"/>" |
| 3158 | "<container name=\"subcont\"/>" |
| 3159 | "<description><text>desc</text></description>" |
| 3160 | "<grouping name=\"sub-grp\"/>" |
| 3161 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3162 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3163 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3164 | "<list name=\"list\"/>" |
| 3165 | "<must condition=\"cond\"/>" |
| 3166 | "<notification name=\"notf\"/>" |
| 3167 | "<presence value=\"presence\"/>" |
| 3168 | "<reference><text>ref</text></reference>" |
| 3169 | "<status value=\"current\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3170 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3171 | "<uses name=\"uses-name\"/>" |
| 3172 | "<when condition=\"when-cond\"/>" |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3173 | "<action name=\"act\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3174 | "<choice name=\"choice\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3175 | EXT_SUBELEM |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3176 | "</container>" |
| 3177 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3178 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3179 | parsed = (struct lysp_node_container *)siblings; |
| 3180 | assert_string_equal(parsed->name, "cont-name"); |
| 3181 | assert_null(parsed->parent); |
| 3182 | assert_int_equal(parsed->nodetype, LYS_CONTAINER); |
| 3183 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 3184 | assert_true(parsed->flags & LYS_STATUS_CURR); |
| 3185 | assert_null(parsed->next); |
| 3186 | assert_string_equal(parsed->dsc, "desc"); |
| 3187 | assert_string_equal(parsed->ref, "ref"); |
| 3188 | assert_string_equal(parsed->when->cond, "when-cond"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3189 | assert_string_equal(parsed->iffeatures[0].str, "iff"); |
| 3190 | assert_string_equal(parsed->musts->arg.str, "cond"); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3191 | assert_string_equal(parsed->presence, "presence"); |
| 3192 | assert_string_equal(parsed->typedefs->name, "tpdf"); |
| 3193 | assert_string_equal(parsed->groupings->name, "sub-grp"); |
| 3194 | assert_string_equal(parsed->child->name, "anyd"); |
| 3195 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 3196 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 3197 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 3198 | assert_string_equal(parsed->child->next->next->name, "subcont"); |
| 3199 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
| 3200 | assert_string_equal(parsed->child->next->next->next->name, "leaf"); |
| 3201 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF); |
| 3202 | assert_string_equal(parsed->child->next->next->next->next->name, "llist"); |
| 3203 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3204 | assert_string_equal(parsed->child->next->next->next->next->next->name, "list"); |
| 3205 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST); |
| 3206 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name"); |
| 3207 | 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] | 3208 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice"); |
| 3209 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 3210 | 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] | 3211 | assert_string_equal(parsed->notifs->name, "notf"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3212 | assert_string_equal(parsed->actions->name, "act"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3213 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3214 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 3215 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3216 | lysp_node_free(st->ctx, siblings); |
| 3217 | ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL); |
| 3218 | siblings = NULL; |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3219 | |
| 3220 | /* min subelems */ |
| 3221 | data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3222 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3223 | parsed = (struct lysp_node_container *)siblings; |
| 3224 | assert_string_equal(parsed->name, "cont-name"); |
| 3225 | lysp_node_free(st->ctx, siblings); |
| 3226 | siblings = NULL; |
| 3227 | |
| 3228 | st->finished_correctly = true; |
| 3229 | } |
| 3230 | |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3231 | static void |
| 3232 | test_case_elem(void **state) |
| 3233 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3234 | struct test_parser_yin_state *st = *state; |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3235 | const char *data; |
| 3236 | struct lysp_node *siblings = NULL; |
| 3237 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 3238 | struct lysp_node_case *parsed = NULL; |
| 3239 | |
| 3240 | /* max subelems */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3241 | st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3242 | data = ELEMENT_WRAPPER_START |
| 3243 | "<case name=\"case-name\">" |
| 3244 | "<anydata name=\"anyd\"/>" |
| 3245 | "<anyxml name=\"anyx\"/>" |
| 3246 | "<container name=\"subcont\"/>" |
| 3247 | "<description><text>desc</text></description>" |
| 3248 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3249 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3250 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3251 | "<list name=\"list\"/>" |
| 3252 | "<reference><text>ref</text></reference>" |
| 3253 | "<status value=\"current\"/>" |
| 3254 | "<uses name=\"uses-name\"/>" |
| 3255 | "<when condition=\"when-cond\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3256 | "<choice name=\"choice\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3257 | EXT_SUBELEM |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3258 | "</case>" |
| 3259 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3260 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3261 | parsed = (struct lysp_node_case *)siblings; |
| 3262 | assert_string_equal(parsed->name, "case-name"); |
| 3263 | assert_null(parsed->parent); |
| 3264 | assert_int_equal(parsed->nodetype, LYS_CASE); |
| 3265 | assert_true(parsed->flags & LYS_STATUS_CURR); |
| 3266 | assert_null(parsed->next); |
| 3267 | assert_string_equal(parsed->dsc, "desc"); |
| 3268 | assert_string_equal(parsed->ref, "ref"); |
| 3269 | assert_string_equal(parsed->when->cond, "when-cond"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3270 | assert_string_equal(parsed->iffeatures[0].str, "iff"); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3271 | assert_string_equal(parsed->child->name, "anyd"); |
| 3272 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 3273 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 3274 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 3275 | assert_string_equal(parsed->child->next->next->name, "subcont"); |
| 3276 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
| 3277 | assert_string_equal(parsed->child->next->next->next->name, "leaf"); |
| 3278 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF); |
| 3279 | assert_string_equal(parsed->child->next->next->next->next->name, "llist"); |
| 3280 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3281 | assert_string_equal(parsed->child->next->next->next->next->next->name, "list"); |
| 3282 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST); |
| 3283 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name"); |
| 3284 | 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] | 3285 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice"); |
| 3286 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 3287 | assert_null(parsed->child->next->next->next->next->next->next->next->next); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3288 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3289 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 3290 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3291 | lysp_node_free(st->ctx, siblings); |
| 3292 | siblings = NULL; |
| 3293 | |
| 3294 | /* min subelems */ |
| 3295 | data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3296 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3297 | parsed = (struct lysp_node_case *)siblings; |
| 3298 | assert_string_equal(parsed->name, "case-name"); |
| 3299 | lysp_node_free(st->ctx, siblings); |
| 3300 | siblings = NULL; |
| 3301 | |
| 3302 | st->finished_correctly = true; |
| 3303 | } |
| 3304 | |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3305 | static void |
| 3306 | test_choice_elem(void **state) |
| 3307 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3308 | struct test_parser_yin_state *st = *state; |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3309 | const char *data; |
| 3310 | struct lysp_node *siblings = NULL; |
| 3311 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 3312 | struct lysp_node_choice *parsed = NULL; |
| 3313 | |
| 3314 | /* max subelems */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3315 | st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3316 | data = ELEMENT_WRAPPER_START |
| 3317 | "<choice name=\"choice-name\">" |
| 3318 | "<anydata name=\"anyd\"/>" |
| 3319 | "<anyxml name=\"anyx\"/>" |
| 3320 | "<case name=\"sub-case\"/>" |
| 3321 | "<choice name=\"choice\"/>" |
| 3322 | "<config value=\"true\"/>" |
| 3323 | "<container name=\"subcont\"/>" |
| 3324 | "<default value=\"def\"/>" |
| 3325 | "<description><text>desc</text></description>" |
| 3326 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3327 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3328 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3329 | "<list name=\"list\"/>" |
| 3330 | "<mandatory value=\"true\" />" |
| 3331 | "<reference><text>ref</text></reference>" |
| 3332 | "<status value=\"current\"/>" |
| 3333 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3334 | EXT_SUBELEM |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3335 | "</choice>" |
| 3336 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3337 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3338 | parsed = (struct lysp_node_choice *)siblings; |
| 3339 | assert_string_equal(parsed->name, "choice-name"); |
| 3340 | assert_null(parsed->parent); |
| 3341 | assert_int_equal(parsed->nodetype, LYS_CHOICE); |
| 3342 | assert_true(parsed->flags & LYS_CONFIG_W && parsed->flags & LYS_MAND_TRUE && parsed->flags & LYS_STATUS_CURR); |
| 3343 | assert_null(parsed->next); |
| 3344 | assert_string_equal(parsed->dsc, "desc"); |
| 3345 | assert_string_equal(parsed->ref, "ref"); |
| 3346 | assert_string_equal(parsed->when->cond, "when-cond"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3347 | assert_string_equal(parsed->iffeatures[0].str, "iff"); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3348 | assert_string_equal(parsed->child->name, "anyd"); |
| 3349 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 3350 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 3351 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 3352 | assert_string_equal(parsed->child->next->next->name, "sub-case"); |
| 3353 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE); |
| 3354 | assert_string_equal(parsed->child->next->next->next->name, "choice"); |
| 3355 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE); |
| 3356 | assert_string_equal(parsed->child->next->next->next->next->name, "subcont"); |
| 3357 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER); |
| 3358 | assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf"); |
| 3359 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF); |
| 3360 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist"); |
| 3361 | assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3362 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list"); |
| 3363 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3364 | assert_null(parsed->child->next->next->next->next->next->next->next->next); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3365 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3366 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 3367 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3368 | lysp_node_free(st->ctx, siblings); |
| 3369 | siblings = NULL; |
| 3370 | |
| 3371 | /* min subelems */ |
| 3372 | data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3373 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3374 | parsed = (struct lysp_node_choice *)siblings; |
| 3375 | assert_string_equal(parsed->name, "choice-name"); |
| 3376 | lysp_node_free(st->ctx, siblings); |
| 3377 | siblings = NULL; |
| 3378 | |
| 3379 | st->finished_correctly = true; |
| 3380 | } |
| 3381 | |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3382 | static void |
| 3383 | test_inout_elem(void **state) |
| 3384 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3385 | struct test_parser_yin_state *st = *state; |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3386 | const char *data; |
| 3387 | struct lysp_action_inout inout = {}; |
| 3388 | struct inout_meta inout_meta = {NULL, &inout}; |
| 3389 | |
| 3390 | /* max subelements */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3391 | st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3392 | data = ELEMENT_WRAPPER_START |
| 3393 | "<input>" |
| 3394 | "<anydata name=\"anyd\"/>" |
| 3395 | "<anyxml name=\"anyx\"/>" |
| 3396 | "<choice name=\"choice\"/>" |
| 3397 | "<container name=\"subcont\"/>" |
| 3398 | "<grouping name=\"sub-grp\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3399 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3400 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3401 | "<list name=\"list\"/>" |
| 3402 | "<must condition=\"cond\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3403 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3404 | "<uses name=\"uses-name\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3405 | EXT_SUBELEM |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3406 | "</input>" |
| 3407 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3408 | assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3409 | assert_null(inout.parent); |
| 3410 | assert_int_equal(inout.nodetype, LYS_INPUT); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3411 | assert_string_equal(inout.musts->arg.str, "cond"); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3412 | assert_string_equal(inout.typedefs->name, "tpdf"); |
| 3413 | assert_string_equal(inout.groupings->name, "sub-grp"); |
| 3414 | assert_string_equal(inout.data->name, "anyd"); |
| 3415 | assert_int_equal(inout.data->nodetype, LYS_ANYDATA); |
| 3416 | assert_string_equal(inout.data->next->name, "anyx"); |
| 3417 | assert_int_equal(inout.data->next->nodetype, LYS_ANYXML); |
| 3418 | assert_string_equal(inout.data->next->next->name, "choice"); |
| 3419 | assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE); |
| 3420 | assert_string_equal(inout.data->next->next->next->name, "subcont"); |
| 3421 | assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER); |
| 3422 | assert_string_equal(inout.data->next->next->next->next->name, "leaf"); |
| 3423 | assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF); |
| 3424 | assert_string_equal(inout.data->next->next->next->next->next->name, "llist"); |
| 3425 | assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3426 | assert_string_equal(inout.data->next->next->next->next->next->next->name, "list"); |
| 3427 | assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3428 | assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name"); |
| 3429 | assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3430 | assert_null(inout.data->next->next->next->next->next->next->next->next); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3431 | assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3432 | assert_int_equal(inout.exts[0].insubstmt_index, 0); |
| 3433 | assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3434 | lysp_action_inout_free(st->ctx, &inout); |
| 3435 | memset(&inout, 0, sizeof inout); |
| 3436 | |
| 3437 | /* max subelements */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3438 | st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3439 | data = ELEMENT_WRAPPER_START |
| 3440 | "<output>" |
| 3441 | "<anydata name=\"anyd\"/>" |
| 3442 | "<anyxml name=\"anyx\"/>" |
| 3443 | "<choice name=\"choice\"/>" |
| 3444 | "<container name=\"subcont\"/>" |
| 3445 | "<grouping name=\"sub-grp\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3446 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3447 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3448 | "<list name=\"list\"/>" |
| 3449 | "<must condition=\"cond\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3450 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3451 | "<uses name=\"uses-name\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3452 | EXT_SUBELEM |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3453 | "</output>" |
| 3454 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3455 | assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3456 | assert_null(inout.parent); |
| 3457 | assert_int_equal(inout.nodetype, LYS_OUTPUT); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3458 | assert_string_equal(inout.musts->arg.str, "cond"); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3459 | assert_string_equal(inout.typedefs->name, "tpdf"); |
| 3460 | assert_string_equal(inout.groupings->name, "sub-grp"); |
| 3461 | assert_string_equal(inout.data->name, "anyd"); |
| 3462 | assert_int_equal(inout.data->nodetype, LYS_ANYDATA); |
| 3463 | assert_string_equal(inout.data->next->name, "anyx"); |
| 3464 | assert_int_equal(inout.data->next->nodetype, LYS_ANYXML); |
| 3465 | assert_string_equal(inout.data->next->next->name, "choice"); |
| 3466 | assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE); |
| 3467 | assert_string_equal(inout.data->next->next->next->name, "subcont"); |
| 3468 | assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER); |
| 3469 | assert_string_equal(inout.data->next->next->next->next->name, "leaf"); |
| 3470 | assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF); |
| 3471 | assert_string_equal(inout.data->next->next->next->next->next->name, "llist"); |
| 3472 | assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3473 | assert_string_equal(inout.data->next->next->next->next->next->next->name, "list"); |
| 3474 | assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3475 | assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name"); |
| 3476 | assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3477 | assert_null(inout.data->next->next->next->next->next->next->next->next); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3478 | assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3479 | assert_int_equal(inout.exts[0].insubstmt_index, 0); |
| 3480 | assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3481 | lysp_action_inout_free(st->ctx, &inout); |
| 3482 | memset(&inout, 0, sizeof inout); |
| 3483 | |
| 3484 | /* min subelems */ |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3485 | data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3486 | assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS); |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3487 | lysp_action_inout_free(st->ctx, &inout); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3488 | memset(&inout, 0, sizeof inout); |
| 3489 | |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3490 | data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3491 | assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS); |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3492 | lysp_action_inout_free(st->ctx, &inout); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3493 | memset(&inout, 0, sizeof inout); |
| 3494 | |
| 3495 | /* invalid combinations */ |
| 3496 | data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3497 | assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 3498 | logbuf_assert("Unexpected attribute \"name\" of \"input\" element. Line number 1."); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3499 | memset(&inout, 0, sizeof inout); |
| 3500 | |
| 3501 | st->finished_correctly = true; |
| 3502 | } |
| 3503 | |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3504 | static void |
| 3505 | test_action_elem(void **state) |
| 3506 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3507 | struct test_parser_yin_state *st = *state; |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3508 | const char *data; |
| 3509 | struct lysp_action *actions = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 3510 | struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions}; |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3511 | |
| 3512 | /* max subelems */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3513 | st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3514 | data = ELEMENT_WRAPPER_START |
| 3515 | "<action name=\"act\">" |
| 3516 | "<description><text>desc</text></description>" |
| 3517 | "<grouping name=\"grouping\"/>" |
| 3518 | "<if-feature name=\"iff\"/>" |
| 3519 | "<input><uses name=\"uses-name\"/></input>" |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3520 | "<output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>" |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3521 | "<reference><text>ref</text></reference>" |
| 3522 | "<status value=\"deprecated\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3523 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3524 | EXT_SUBELEM |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3525 | "</action>" |
| 3526 | ELEMENT_WRAPPER_END; |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 3527 | /* there must be parent for action */ |
Radek Krejci | f482abc | 2020-08-27 15:29:05 +0200 | [diff] [blame] | 3528 | act_meta.parent = (void*)1; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3529 | assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS); |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 3530 | act_meta.parent = NULL; |
| 3531 | assert_non_null(actions->parent); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3532 | assert_int_equal(actions->nodetype, LYS_ACTION); |
| 3533 | assert_true(actions->flags & LYS_STATUS_DEPRC); |
| 3534 | assert_string_equal(actions->name, "act"); |
| 3535 | assert_string_equal(actions->dsc, "desc"); |
| 3536 | assert_string_equal(actions->ref, "ref"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3537 | assert_string_equal(actions->iffeatures[0].str, "iff"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3538 | assert_string_equal(actions->typedefs->name, "tpdf"); |
| 3539 | assert_string_equal(actions->groupings->name, "grouping"); |
| 3540 | assert_string_equal(actions->input.data->name, "uses-name"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3541 | assert_string_equal(actions->output.musts->arg.str, "cond"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3542 | assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3543 | assert_int_equal(actions->exts[0].insubstmt_index, 0); |
| 3544 | assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3545 | FREE_ARRAY(st->ctx, actions, lysp_action_free) |
| 3546 | actions = NULL; |
| 3547 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3548 | st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3549 | data = ELEMENT_WRAPPER_START |
| 3550 | "<rpc name=\"act\">" |
| 3551 | "<description><text>desc</text></description>" |
| 3552 | "<grouping name=\"grouping\"/>" |
| 3553 | "<if-feature name=\"iff\"/>" |
| 3554 | "<input><uses name=\"uses-name\"/></input>" |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3555 | "<output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>" |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3556 | "<reference><text>ref</text></reference>" |
| 3557 | "<status value=\"deprecated\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3558 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3559 | EXT_SUBELEM |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3560 | "</rpc>" |
| 3561 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3562 | assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3563 | assert_null(actions->parent); |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 3564 | assert_int_equal(actions->nodetype, LYS_RPC); |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3565 | assert_true(actions->flags & LYS_STATUS_DEPRC); |
| 3566 | assert_string_equal(actions->name, "act"); |
| 3567 | assert_string_equal(actions->dsc, "desc"); |
| 3568 | assert_string_equal(actions->ref, "ref"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3569 | assert_string_equal(actions->iffeatures[0].str, "iff"); |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3570 | assert_string_equal(actions->typedefs->name, "tpdf"); |
| 3571 | assert_string_equal(actions->groupings->name, "grouping"); |
| 3572 | assert_string_equal(actions->input.data->name, "uses-name"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3573 | assert_string_equal(actions->output.musts->arg.str, "cond"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3574 | assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3575 | assert_int_equal(actions->exts[0].insubstmt_index, 0); |
| 3576 | assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3577 | FREE_ARRAY(st->ctx, actions, lysp_action_free) |
| 3578 | actions = NULL; |
| 3579 | |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3580 | /* min subelems */ |
| 3581 | data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3582 | assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3583 | assert_string_equal(actions->name, "act"); |
| 3584 | FREE_ARRAY(st->ctx, actions, lysp_action_free) |
| 3585 | actions = NULL; |
| 3586 | |
| 3587 | st->finished_correctly = true; |
| 3588 | } |
| 3589 | |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3590 | static void |
| 3591 | test_augment_elem(void **state) |
| 3592 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3593 | struct test_parser_yin_state *st = *state; |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3594 | const char *data; |
| 3595 | struct lysp_augment *augments = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 3596 | struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments}; |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3597 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3598 | st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3599 | data = ELEMENT_WRAPPER_START |
| 3600 | "<augment target-node=\"target\">" |
| 3601 | "<action name=\"action\"/>" |
| 3602 | "<anydata name=\"anyd\"/>" |
| 3603 | "<anyxml name=\"anyx\"/>" |
| 3604 | "<case name=\"case\"/>" |
| 3605 | "<choice name=\"choice\"/>" |
| 3606 | "<container name=\"subcont\"/>" |
| 3607 | "<description><text>desc</text></description>" |
| 3608 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3609 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3610 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3611 | "<list name=\"list\"/>" |
| 3612 | "<notification name=\"notif\"/>" |
| 3613 | "<reference><text>ref</text></reference>" |
| 3614 | "<status value=\"current\"/>" |
| 3615 | "<uses name=\"uses\"/>" |
| 3616 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3617 | EXT_SUBELEM |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3618 | "</augment>" |
| 3619 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3620 | assert_int_equal(test_element_helper(st, data, &aug_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3621 | assert_string_equal(augments->nodeid, "target"); |
| 3622 | assert_null(augments->parent); |
| 3623 | assert_int_equal(augments->nodetype, LYS_AUGMENT); |
| 3624 | assert_true(augments->flags & LYS_STATUS_CURR); |
| 3625 | assert_string_equal(augments->dsc, "desc"); |
| 3626 | assert_string_equal(augments->ref, "ref"); |
| 3627 | assert_string_equal(augments->when->cond, "when-cond"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3628 | assert_string_equal(augments->iffeatures[0].str, "iff"); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3629 | assert_string_equal(augments->child->name, "anyd"); |
| 3630 | assert_int_equal(augments->child->nodetype, LYS_ANYDATA); |
| 3631 | assert_string_equal(augments->child->next->name, "anyx"); |
| 3632 | assert_int_equal(augments->child->next->nodetype, LYS_ANYXML); |
| 3633 | assert_string_equal(augments->child->next->next->name, "case"); |
| 3634 | assert_int_equal(augments->child->next->next->nodetype, LYS_CASE); |
| 3635 | assert_string_equal(augments->child->next->next->next->name, "choice"); |
| 3636 | assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE); |
| 3637 | assert_string_equal(augments->child->next->next->next->next->name, "subcont"); |
| 3638 | assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER); |
| 3639 | assert_string_equal(augments->child->next->next->next->next->next->name, "leaf"); |
| 3640 | assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF); |
| 3641 | assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist"); |
| 3642 | assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3643 | assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list"); |
| 3644 | assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3645 | assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses"); |
| 3646 | assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3647 | assert_null(augments->child->next->next->next->next->next->next->next->next->next); |
| 3648 | assert_string_equal(augments->actions->name, "action"); |
| 3649 | assert_string_equal(augments->notifs->name, "notif"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3650 | assert_string_equal(augments->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3651 | assert_int_equal(augments->exts[0].insubstmt_index, 0); |
| 3652 | assert_int_equal(augments->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3653 | FREE_ARRAY(st->ctx, augments, lysp_augment_free) |
| 3654 | augments = NULL; |
| 3655 | |
| 3656 | data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3657 | assert_int_equal(test_element_helper(st, data, &aug_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3658 | assert_string_equal(augments->nodeid, "target"); |
| 3659 | FREE_ARRAY(st->ctx, augments, lysp_augment_free) |
| 3660 | augments = NULL; |
| 3661 | |
| 3662 | st->finished_correctly = true; |
| 3663 | } |
| 3664 | |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3665 | static void |
| 3666 | test_deviate_elem(void **state) |
| 3667 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3668 | struct test_parser_yin_state *st = *state; |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3669 | const char *data; |
| 3670 | struct lysp_deviate *deviates = NULL; |
| 3671 | struct lysp_deviate_add *d_add; |
| 3672 | struct lysp_deviate_rpl *d_rpl; |
| 3673 | struct lysp_deviate_del *d_del; |
| 3674 | |
| 3675 | /* all valid arguments with min subelems */ |
| 3676 | data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3677 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3678 | assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED); |
| 3679 | lysp_deviate_free(st->ctx, deviates); |
| 3680 | free(deviates); |
| 3681 | deviates = NULL; |
| 3682 | |
| 3683 | data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3684 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3685 | assert_int_equal(deviates->mod, LYS_DEV_ADD); |
| 3686 | lysp_deviate_free(st->ctx, deviates); |
| 3687 | free(deviates); |
| 3688 | deviates = NULL; |
| 3689 | |
| 3690 | data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3691 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3692 | assert_int_equal(deviates->mod, LYS_DEV_REPLACE); |
| 3693 | lysp_deviate_free(st->ctx, deviates); |
| 3694 | free(deviates); |
| 3695 | deviates = NULL; |
| 3696 | |
| 3697 | data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3698 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3699 | assert_int_equal(deviates->mod, LYS_DEV_DELETE); |
| 3700 | lysp_deviate_free(st->ctx, deviates); |
| 3701 | free(deviates); |
| 3702 | deviates = NULL; |
| 3703 | |
| 3704 | /* max subelems and valid arguments */ |
| 3705 | data = ELEMENT_WRAPPER_START |
| 3706 | "<deviate value=\"not-supported\">" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3707 | EXT_SUBELEM |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3708 | "</deviate>" |
| 3709 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3710 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3711 | assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3712 | assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3713 | assert_int_equal(deviates->exts[0].insubstmt_index, 0); |
| 3714 | assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3715 | lysp_deviate_free(st->ctx, deviates); |
| 3716 | free(deviates); |
| 3717 | deviates = NULL; |
| 3718 | |
| 3719 | data = ELEMENT_WRAPPER_START |
| 3720 | "<deviate value=\"add\">" |
| 3721 | "<units name=\"units\"/>" |
| 3722 | "<must condition=\"cond\"/>" |
| 3723 | "<unique tag=\"utag\"/>" |
| 3724 | "<default value=\"def\"/>" |
| 3725 | "<config value=\"true\"/>" |
| 3726 | "<mandatory value=\"true\"/>" |
| 3727 | "<min-elements value=\"5\"/>" |
| 3728 | "<max-elements value=\"15\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3729 | EXT_SUBELEM |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3730 | "</deviate>" |
| 3731 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3732 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3733 | d_add = (struct lysp_deviate_add *)deviates; |
| 3734 | assert_int_equal(d_add->mod, LYS_DEV_ADD); |
| 3735 | assert_null(d_add->next); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3736 | assert_string_equal(d_add->units, "units"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3737 | assert_string_equal(d_add->musts->arg.str, "cond"); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3738 | assert_string_equal(d_add->uniques[0].str, "utag"); |
| 3739 | assert_string_equal(d_add->dflts[0].str, "def"); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3740 | assert_true(d_add->flags & LYS_MAND_TRUE && d_add->flags & LYS_CONFIG_W); |
| 3741 | assert_int_equal(d_add->min, 5); |
| 3742 | assert_int_equal(d_add->max, 15); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3743 | assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3744 | assert_int_equal(deviates->exts[0].insubstmt_index, 0); |
| 3745 | assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3746 | lysp_deviate_free(st->ctx, deviates); |
| 3747 | free(deviates); |
| 3748 | deviates = NULL; |
| 3749 | |
| 3750 | data = ELEMENT_WRAPPER_START |
| 3751 | "<deviate value=\"replace\">" |
| 3752 | "<type name=\"newtype\"/>" |
| 3753 | "<units name=\"uni\"/>" |
| 3754 | "<default value=\"def\"/>" |
| 3755 | "<config value=\"true\"/>" |
| 3756 | "<mandatory value=\"true\"/>" |
| 3757 | "<min-elements value=\"5\"/>" |
| 3758 | "<max-elements value=\"15\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3759 | EXT_SUBELEM |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3760 | "</deviate>" |
| 3761 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3762 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3763 | d_rpl = (struct lysp_deviate_rpl *)deviates; |
| 3764 | assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE); |
| 3765 | assert_null(d_rpl->next); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3766 | assert_string_equal(d_rpl->type->name, "newtype"); |
| 3767 | assert_string_equal(d_rpl->units, "uni"); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3768 | assert_string_equal(d_rpl->dflt.str, "def"); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3769 | assert_true(d_rpl->flags & LYS_MAND_TRUE && d_rpl->flags & LYS_CONFIG_W); |
| 3770 | assert_int_equal(d_rpl->min, 5); |
| 3771 | assert_int_equal(d_rpl->max, 15); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3772 | assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3773 | assert_int_equal(deviates->exts[0].insubstmt_index, 0); |
| 3774 | assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3775 | lysp_deviate_free(st->ctx, deviates); |
| 3776 | free(deviates); |
| 3777 | deviates = NULL; |
| 3778 | |
| 3779 | data = ELEMENT_WRAPPER_START |
| 3780 | "<deviate value=\"delete\">" |
| 3781 | "<units name=\"u\"/>" |
| 3782 | "<must condition=\"c\"/>" |
| 3783 | "<unique tag=\"tag\"/>" |
| 3784 | "<default value=\"default\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3785 | EXT_SUBELEM |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3786 | "</deviate>" |
| 3787 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3788 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3789 | d_del = (struct lysp_deviate_del *)deviates; |
| 3790 | assert_int_equal(d_del->mod, LYS_DEV_DELETE); |
| 3791 | assert_null(d_del->next); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3792 | assert_string_equal(d_del->units, "u"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3793 | assert_string_equal(d_del->musts->arg.str, "c"); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3794 | assert_string_equal(d_del->uniques[0].str, "tag"); |
| 3795 | assert_string_equal(d_del->dflts[0].str, "default"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3796 | assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3797 | assert_int_equal(deviates->exts[0].insubstmt_index, 0); |
| 3798 | assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3799 | lysp_deviate_free(st->ctx, deviates); |
| 3800 | free(deviates); |
| 3801 | deviates = NULL; |
| 3802 | |
| 3803 | /* invalid arguments */ |
| 3804 | data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3805 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 3806 | logbuf_assert("Invalid value \"\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3807 | deviates = NULL; |
| 3808 | |
| 3809 | data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3810 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 3811 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3812 | deviates = NULL; |
| 3813 | |
| 3814 | data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3815 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 3816 | logbuf_assert("Invalid value \"ad\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3817 | deviates = NULL; |
| 3818 | |
| 3819 | data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3820 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 3821 | logbuf_assert("Invalid value \"adds\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3822 | deviates = NULL; |
| 3823 | |
| 3824 | data = ELEMENT_WRAPPER_START |
| 3825 | "<deviate value=\"not-supported\">" |
| 3826 | "<must condition=\"c\"/>" |
| 3827 | "</deviate>" |
| 3828 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3829 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3830 | logbuf_assert("Deviate of this type doesn't allow \"must\" as it's sub-element. Line number 1."); |
| 3831 | |
| 3832 | st->finished_correctly = true; |
| 3833 | } |
| 3834 | |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3835 | static void |
| 3836 | test_deviation_elem(void **state) |
| 3837 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3838 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3839 | const char *data; |
| 3840 | struct lysp_deviation *deviations = NULL; |
| 3841 | |
| 3842 | /* min subelems */ |
| 3843 | data = ELEMENT_WRAPPER_START |
| 3844 | "<deviation target-node=\"target\">" |
| 3845 | "<deviate value=\"not-supported\"/>" |
| 3846 | "</deviation>" |
| 3847 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3848 | assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3849 | assert_string_equal(deviations->nodeid, "target"); |
| 3850 | assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED); |
| 3851 | FREE_ARRAY(st->ctx, deviations, lysp_deviation_free); |
| 3852 | deviations = NULL; |
| 3853 | |
| 3854 | /* max subelems */ |
| 3855 | data = ELEMENT_WRAPPER_START |
| 3856 | "<deviation target-node=\"target\">" |
| 3857 | "<reference><text>ref</text></reference>" |
| 3858 | "<description><text>desc</text></description>" |
| 3859 | "<deviate value=\"add\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3860 | EXT_SUBELEM |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3861 | "</deviation>" |
| 3862 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3863 | assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3864 | assert_string_equal(deviations->nodeid, "target"); |
| 3865 | assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD); |
| 3866 | assert_string_equal(deviations->ref, "ref"); |
| 3867 | assert_string_equal(deviations->dsc, "desc"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3868 | assert_string_equal(deviations->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3869 | assert_int_equal(deviations->exts[0].insubstmt_index, 0); |
| 3870 | assert_int_equal(deviations->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3871 | FREE_ARRAY(st->ctx, deviations, lysp_deviation_free); |
| 3872 | deviations = NULL; |
| 3873 | |
| 3874 | /* invalid */ |
| 3875 | data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3876 | assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_EVALID); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3877 | FREE_ARRAY(st->ctx, deviations, lysp_deviation_free); |
| 3878 | deviations = NULL; |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 3879 | logbuf_assert("Missing mandatory sub-element \"deviate\" of \"deviation\" element. Line number 1."); |
| 3880 | /* TODO */ |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3881 | st->finished_correctly = true; |
| 3882 | } |
| 3883 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3884 | static struct lysp_module * |
| 3885 | mod_renew(struct lys_yin_parser_ctx *ctx) |
| 3886 | { |
| 3887 | struct ly_ctx *ly_ctx = ctx->parsed_mod->mod->ctx; |
| 3888 | |
| 3889 | lys_module_free(ctx->parsed_mod->mod, NULL); |
| 3890 | ctx->parsed_mod = calloc(1, sizeof *ctx->parsed_mod); |
| 3891 | ctx->parsed_mod->mod = calloc(1, sizeof *ctx->parsed_mod->mod); |
| 3892 | ctx->parsed_mod->mod->parsed = ctx->parsed_mod; |
| 3893 | ctx->parsed_mod->mod->ctx = ly_ctx; |
| 3894 | |
| 3895 | return ctx->parsed_mod; |
| 3896 | } |
| 3897 | |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3898 | static void |
| 3899 | test_module_elem(void **state) |
| 3900 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3901 | struct test_parser_yin_state *st = *state; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3902 | const char *data; |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3903 | struct lysp_module *lysp_mod = mod_renew(st->yin_ctx); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3904 | |
| 3905 | /* max subelems */ |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3906 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
| 3907 | "<yang-version value=\"1.1\"/>\n" |
| 3908 | "<namespace uri=\"ns\"/>\n" |
| 3909 | "<prefix value=\"pref\"/>\n" |
| 3910 | "<include module=\"b-mod\"/>\n" |
| 3911 | "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n" |
| 3912 | "<organization><text>org</text></organization>\n" |
| 3913 | "<contact><text>contact</text></contact>\n" |
| 3914 | "<description><text>desc</text></description>" |
| 3915 | "<reference><text>ref</text></reference>\n" |
| 3916 | "<revision date=\"2019-02-02\"/>\n" |
| 3917 | "<anydata name=\"anyd\"/>\n" |
| 3918 | "<anyxml name=\"anyx\"/>\n" |
| 3919 | "<choice name=\"choice\"/>\n" |
| 3920 | "<container name=\"cont\"/>\n" |
| 3921 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 3922 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 3923 | "<list name=\"sub-list\"/>\n" |
| 3924 | "<uses name=\"uses-name\"/>\n" |
| 3925 | "<augment target-node=\"target\"/>\n" |
| 3926 | "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n" |
| 3927 | "<extension name=\"ext\"/>\n" |
| 3928 | "<feature name=\"feature\"/>\n" |
| 3929 | "<grouping name=\"grp\"/>\n" |
| 3930 | "<identity name=\"ident-name\"/>\n" |
| 3931 | "<notification name=\"notf\"/>\n" |
| 3932 | "<rpc name=\"rpc-name\"/>\n" |
| 3933 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3934 | EXT_SUBELEM"\n" |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3935 | "</module>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3936 | assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS); |
| 3937 | assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3938 | |
| 3939 | assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3940 | assert_string_equal(lysp_mod->mod->name, "mod"); |
| 3941 | assert_string_equal(lysp_mod->revs, "2019-02-02"); |
| 3942 | assert_string_equal(lysp_mod->mod->ns, "ns"); |
| 3943 | assert_string_equal(lysp_mod->mod->prefix, "pref"); |
| 3944 | assert_null(lysp_mod->mod->filepath); |
| 3945 | assert_string_equal(lysp_mod->mod->org, "org"); |
| 3946 | assert_string_equal(lysp_mod->mod->contact, "contact"); |
| 3947 | assert_string_equal(lysp_mod->mod->dsc, "desc"); |
| 3948 | assert_string_equal(lysp_mod->mod->ref, "ref"); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3949 | assert_int_equal(lysp_mod->version, LYS_VERSION_1_1); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3950 | assert_string_equal(lysp_mod->imports->name, "a-mod"); |
| 3951 | assert_string_equal(lysp_mod->includes->name, "b-mod"); |
| 3952 | assert_string_equal(lysp_mod->extensions->name, "ext"); |
| 3953 | assert_string_equal(lysp_mod->features->name, "feature"); |
| 3954 | assert_string_equal(lysp_mod->identities->name, "ident-name"); |
| 3955 | assert_string_equal(lysp_mod->typedefs->name, "tpdf"); |
| 3956 | assert_string_equal(lysp_mod->groupings->name, "grp"); |
| 3957 | assert_string_equal(lysp_mod->data->name, "anyd"); |
| 3958 | assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA); |
| 3959 | assert_string_equal(lysp_mod->data->next->name, "anyx"); |
| 3960 | assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML); |
| 3961 | assert_string_equal(lysp_mod->data->next->next->name, "choice"); |
| 3962 | assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE); |
| 3963 | assert_string_equal(lysp_mod->data->next->next->next->name, "cont"); |
| 3964 | assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER); |
| 3965 | assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf"); |
| 3966 | assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF); |
| 3967 | assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist"); |
| 3968 | assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3969 | assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list"); |
| 3970 | assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3971 | assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name"); |
| 3972 | assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3973 | assert_null(lysp_mod->data->next->next->next->next->next->next->next->next); |
| 3974 | assert_string_equal(lysp_mod->augments->nodeid, "target"); |
| 3975 | assert_string_equal(lysp_mod->rpcs->name, "rpc-name"); |
| 3976 | assert_string_equal(lysp_mod->notifs->name, "notf"); |
| 3977 | assert_string_equal(lysp_mod->deviations->nodeid, "target"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3978 | assert_string_equal(lysp_mod->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3979 | assert_int_equal(lysp_mod->exts[0].insubstmt_index, 0); |
| 3980 | assert_int_equal(lysp_mod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3981 | |
| 3982 | /* min subelems */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3983 | ly_in_free(st->in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3984 | lyxml_ctx_free(st->yin_ctx->xmlctx); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3985 | lysp_mod = mod_renew(st->yin_ctx); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3986 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">" |
| 3987 | "<namespace uri=\"ns\"/>" |
| 3988 | "<prefix value=\"pref\"/>" |
| 3989 | "<yang-version value=\"1.1\"/>" |
| 3990 | "</module>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3991 | assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS); |
| 3992 | assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3993 | assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3994 | assert_string_equal(lysp_mod->mod->name, "mod"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3995 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3996 | /* incorrect subelem order */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3997 | ly_in_free(st->in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3998 | lyxml_ctx_free(st->yin_ctx->xmlctx); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3999 | lysp_mod = mod_renew(st->yin_ctx); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 4000 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">" |
| 4001 | "<feature name=\"feature\"/>\n" |
| 4002 | "<namespace uri=\"ns\"/>" |
| 4003 | "<prefix value=\"pref\"/>" |
| 4004 | "<yang-version value=\"1.1\"/>" |
| 4005 | "</module>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4006 | assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS); |
| 4007 | assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4008 | assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_EVALID); |
| 4009 | logbuf_assert("Invalid order of module\'s sub-elements \"namespace\" can\'t appear after \"feature\". Line number 2."); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 4010 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4011 | st->finished_correctly = true; |
| 4012 | } |
| 4013 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4014 | static struct lysp_submodule * |
| 4015 | submod_renew(struct lys_yin_parser_ctx *ctx, const char *belongs_to) |
| 4016 | { |
| 4017 | struct ly_ctx *ly_ctx = ctx->parsed_mod->mod->ctx; |
| 4018 | |
| 4019 | lys_module_free(ctx->parsed_mod->mod, NULL); |
| 4020 | ctx->parsed_mod = calloc(1, sizeof(struct lysp_submodule)); |
| 4021 | ctx->parsed_mod->mod = calloc(1, sizeof *ctx->parsed_mod->mod); |
| 4022 | lydict_insert(ly_ctx, belongs_to, 0, &ctx->parsed_mod->mod->name); |
| 4023 | ctx->parsed_mod->mod->parsed = ctx->parsed_mod; |
| 4024 | ctx->parsed_mod->mod->ctx = ly_ctx; |
| 4025 | |
| 4026 | return (struct lysp_submodule *)ctx->parsed_mod; |
| 4027 | } |
| 4028 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4029 | static void |
| 4030 | test_submodule_elem(void **state) |
| 4031 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 4032 | struct test_parser_yin_state *st = *state; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4033 | const char *data; |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4034 | struct lysp_submodule *lysp_submod = submod_renew(st->yin_ctx, "module-name"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4035 | |
| 4036 | /* max subelements */ |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4037 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
| 4038 | "<yang-version value=\"1.1\"/>\n" |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 4039 | "<belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>" |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4040 | "<include module=\"b-mod\"/>\n" |
| 4041 | "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n" |
| 4042 | "<organization><text>org</text></organization>\n" |
| 4043 | "<contact><text>contact</text></contact>\n" |
| 4044 | "<description><text>desc</text></description>" |
| 4045 | "<reference><text>ref</text></reference>\n" |
| 4046 | "<revision date=\"2019-02-02\"/>\n" |
| 4047 | "<anydata name=\"anyd\"/>\n" |
| 4048 | "<anyxml name=\"anyx\"/>\n" |
| 4049 | "<choice name=\"choice\"/>\n" |
| 4050 | "<container name=\"cont\"/>\n" |
| 4051 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 4052 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 4053 | "<list name=\"sub-list\"/>\n" |
| 4054 | "<uses name=\"uses-name\"/>\n" |
| 4055 | "<augment target-node=\"target\"/>\n" |
| 4056 | "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n" |
| 4057 | "<extension name=\"ext\"/>\n" |
| 4058 | "<feature name=\"feature\"/>\n" |
| 4059 | "<grouping name=\"grp\"/>\n" |
| 4060 | "<identity name=\"ident-name\"/>\n" |
| 4061 | "<notification name=\"notf\"/>\n" |
| 4062 | "<rpc name=\"rpc-name\"/>\n" |
| 4063 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 4064 | EXT_SUBELEM"\n" |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4065 | "</submodule>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4066 | assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS); |
| 4067 | assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4068 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4069 | assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4070 | assert_string_equal(lysp_submod->name, "mod"); |
| 4071 | assert_string_equal(lysp_submod->revs, "2019-02-02"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4072 | assert_string_equal(lysp_submod->prefix, "pref"); |
| 4073 | assert_null(lysp_submod->filepath); |
| 4074 | assert_string_equal(lysp_submod->org, "org"); |
| 4075 | assert_string_equal(lysp_submod->contact, "contact"); |
| 4076 | assert_string_equal(lysp_submod->dsc, "desc"); |
| 4077 | assert_string_equal(lysp_submod->ref, "ref"); |
| 4078 | assert_int_equal(lysp_submod->version, LYS_VERSION_1_1); |
| 4079 | assert_string_equal(lysp_submod->imports->name, "a-mod"); |
| 4080 | assert_string_equal(lysp_submod->includes->name, "b-mod"); |
| 4081 | assert_string_equal(lysp_submod->extensions->name, "ext"); |
| 4082 | assert_string_equal(lysp_submod->features->name, "feature"); |
| 4083 | assert_string_equal(lysp_submod->identities->name, "ident-name"); |
| 4084 | assert_string_equal(lysp_submod->typedefs->name, "tpdf"); |
| 4085 | assert_string_equal(lysp_submod->groupings->name, "grp"); |
| 4086 | assert_string_equal(lysp_submod->data->name, "anyd"); |
| 4087 | assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA); |
| 4088 | assert_string_equal(lysp_submod->data->next->name, "anyx"); |
| 4089 | assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML); |
| 4090 | assert_string_equal(lysp_submod->data->next->next->name, "choice"); |
| 4091 | assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE); |
| 4092 | assert_string_equal(lysp_submod->data->next->next->next->name, "cont"); |
| 4093 | assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER); |
| 4094 | assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf"); |
| 4095 | assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF); |
| 4096 | assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist"); |
| 4097 | assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 4098 | assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list"); |
| 4099 | assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 4100 | assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name"); |
| 4101 | assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 4102 | assert_null(lysp_submod->data->next->next->next->next->next->next->next->next); |
| 4103 | assert_string_equal(lysp_submod->augments->nodeid, "target"); |
| 4104 | assert_string_equal(lysp_submod->rpcs->name, "rpc-name"); |
| 4105 | assert_string_equal(lysp_submod->notifs->name, "notf"); |
| 4106 | assert_string_equal(lysp_submod->deviations->nodeid, "target"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 4107 | assert_string_equal(lysp_submod->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 4108 | assert_int_equal(lysp_submod->exts[0].insubstmt_index, 0); |
| 4109 | assert_int_equal(lysp_submod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4110 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4111 | /* min subelemnts */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4112 | ly_in_free(st->in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4113 | lyxml_ctx_free(st->yin_ctx->xmlctx); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4114 | lysp_submod = submod_renew(st->yin_ctx, "module-name"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4115 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">" |
Radek Krejci | 96e48da | 2020-09-04 13:18:06 +0200 | [diff] [blame] | 4116 | "<yang-version value=\"1\"/>" |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 4117 | "<belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>" |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4118 | "</submodule>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4119 | assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS); |
| 4120 | assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4121 | assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4122 | assert_string_equal(lysp_submod->prefix, "pref"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4123 | assert_int_equal(lysp_submod->version, LYS_VERSION_1_0); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4124 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 4125 | /* incorrect subelem order */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4126 | ly_in_free(st->in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4127 | lyxml_ctx_free(st->yin_ctx->xmlctx); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4128 | lysp_submod = submod_renew(st->yin_ctx, "module-name"); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 4129 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">" |
Radek Krejci | 96e48da | 2020-09-04 13:18:06 +0200 | [diff] [blame] | 4130 | "<yang-version value=\"1\"/>" |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 4131 | "<reference><text>ref</text></reference>\n" |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 4132 | "<belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>" |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 4133 | "</submodule>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4134 | assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS); |
| 4135 | assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4136 | assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_EVALID); |
| 4137 | logbuf_assert("Invalid order of submodule's sub-elements \"belongs-to\" can't appear after \"reference\". Line number 2."); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 4138 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4139 | st->finished_correctly = true; |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 4140 | } |
| 4141 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4142 | static void |
| 4143 | test_yin_parse_module(void **state) |
| 4144 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 4145 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4146 | const char *data; |
| 4147 | struct lys_module *mod; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4148 | struct lys_yin_parser_ctx *yin_ctx = NULL; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4149 | struct ly_in *in = NULL; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4150 | |
| 4151 | mod = calloc(1, sizeof *mod); |
| 4152 | mod->ctx = st->ctx; |
David Sedlák | d284488 | 2019-09-13 16:01:22 +0200 | [diff] [blame] | 4153 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" name=\"a\"> \n" |
| 4154 | "<yang-version value=\"1.1\"/>\n" |
| 4155 | "<namespace uri=\"urn:tests:extensions:metadata:a\"/>\n" |
| 4156 | "<prefix value=\"a\"/>\n" |
| 4157 | "<import module=\"ietf-yang-metadata\">\n" |
| 4158 | "<prefix value=\"md\"/>\n" |
| 4159 | "</import>\n" |
| 4160 | "<feature name=\"f\"/>\n" |
| 4161 | "<md:annotation name=\"x\">\n" |
| 4162 | "<description>\n" |
| 4163 | "<text>test</text>\n" |
| 4164 | "</description>\n" |
| 4165 | "<reference>\n" |
| 4166 | "<text>test</text>\n" |
| 4167 | "</reference>\n" |
| 4168 | "<if-feature name=\"f\"/>\n" |
| 4169 | "<status value=\"current\"/>\n" |
| 4170 | "<type name=\"uint8\"/>\n" |
| 4171 | "<units name=\"meters\"/>\n" |
| 4172 | "</md:annotation>\n" |
| 4173 | "</module>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4174 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
| 4175 | assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS); |
David Sedlák | d284488 | 2019-09-13 16:01:22 +0200 | [diff] [blame] | 4176 | assert_null(mod->parsed->exts->child->next->child); |
| 4177 | assert_string_equal(mod->parsed->exts->child->next->arg, "test"); |
| 4178 | lys_module_free(mod, NULL); |
| 4179 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4180 | ly_in_free(in, 0); |
David Sedlák | d284488 | 2019-09-13 16:01:22 +0200 | [diff] [blame] | 4181 | mod = NULL; |
| 4182 | yin_ctx = NULL; |
| 4183 | |
| 4184 | mod = calloc(1, sizeof *mod); |
| 4185 | mod->ctx = st->ctx; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4186 | data = "<module name=\"example-foo\"" |
| 4187 | "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"" |
| 4188 | "xmlns:foo=\"urn:example:foo\"" |
| 4189 | "xmlns:myext=\"urn:example:extensions\">\n" |
| 4190 | |
Radek Krejci | 96e48da | 2020-09-04 13:18:06 +0200 | [diff] [blame] | 4191 | "<yang-version value=\"1\"/>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4192 | |
| 4193 | "<namespace uri=\"urn:example:foo\"/>\n" |
| 4194 | "<prefix value=\"foo\"/>\n" |
| 4195 | |
| 4196 | "<import module=\"example-extensions\">\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4197 | "<prefix value=\"myext\"/>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4198 | "</import>\n" |
| 4199 | |
| 4200 | "<list name=\"interface\">\n" |
| 4201 | "<key value=\"name\"/>\n" |
| 4202 | "<leaf name=\"name\">\n" |
| 4203 | "<type name=\"string\"/>\n" |
| 4204 | "</leaf>\n" |
| 4205 | "<leaf name=\"mtu\">\n" |
| 4206 | "<type name=\"uint32\"/>\n" |
| 4207 | "<description>\n" |
| 4208 | "<text>The MTU of the interface.</text>\n" |
| 4209 | "</description>\n" |
| 4210 | "<myext:c-define name=\"MY_MTU\"/>\n" |
| 4211 | "</leaf>\n" |
| 4212 | "</list>\n" |
| 4213 | "</module>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4214 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
| 4215 | assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4216 | lys_module_free(mod, NULL); |
| 4217 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4218 | ly_in_free(in, 0); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4219 | mod = NULL; |
| 4220 | yin_ctx = NULL; |
| 4221 | |
| 4222 | mod = calloc(1, sizeof *mod); |
| 4223 | mod->ctx = st->ctx; |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4224 | data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
Radek Krejci | 96e48da | 2020-09-04 13:18:06 +0200 | [diff] [blame] | 4225 | "<yang-version value=\"1\"/>\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4226 | "<namespace uri=\"urn:example:foo\"/>\n" |
| 4227 | "<prefix value=\"foo\"/>\n" |
| 4228 | "</module>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4229 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
| 4230 | assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4231 | lys_module_free(mod, NULL); |
| 4232 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4233 | ly_in_free(in, 0); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4234 | mod = NULL; |
| 4235 | yin_ctx = NULL; |
| 4236 | |
| 4237 | |
| 4238 | mod = calloc(1, sizeof *mod); |
| 4239 | mod->ctx = st->ctx; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4240 | data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4241 | "</submodule>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4242 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
| 4243 | assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_EINVAL); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4244 | logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module."); |
| 4245 | lys_module_free(mod, NULL); |
| 4246 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4247 | ly_in_free(in, 0); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4248 | |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4249 | mod = calloc(1, sizeof *mod); |
| 4250 | mod->ctx = st->ctx; |
| 4251 | data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
Radek Krejci | 96e48da | 2020-09-04 13:18:06 +0200 | [diff] [blame] | 4252 | "<yang-version value=\"1\"/>\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4253 | "<namespace uri=\"urn:example:foo\"/>\n" |
| 4254 | "<prefix value=\"foo\"/>\n" |
| 4255 | "</module>" |
| 4256 | "<module>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4257 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
| 4258 | assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_EVALID); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4259 | logbuf_assert("Trailing garbage \"<module>\" after module, expected end-of-input. Line number 5."); |
| 4260 | lys_module_free(mod, NULL); |
| 4261 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4262 | ly_in_free(in, 0); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4263 | mod = NULL; |
| 4264 | yin_ctx = NULL; |
| 4265 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4266 | st->finished_correctly = true; |
| 4267 | } |
| 4268 | |
| 4269 | static void |
| 4270 | test_yin_parse_submodule(void **state) |
| 4271 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 4272 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4273 | const char *data; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4274 | struct lys_yin_parser_ctx *yin_ctx = NULL; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4275 | struct lysp_submodule *submod = NULL; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4276 | struct ly_in *in; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4277 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4278 | lydict_insert(st->ctx, "a", 0, &st->yin_ctx->parsed_mod->mod->name); |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 4279 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4280 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 4281 | "<submodule name=\"asub\"" |
| 4282 | "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"" |
| 4283 | "xmlns:a=\"urn:a\">" |
Radek Krejci | 96e48da | 2020-09-04 13:18:06 +0200 | [diff] [blame] | 4284 | "<yang-version value=\"1\"/>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4285 | "<belongs-to module=\"a\">" |
| 4286 | "<prefix value=\"a_pref\"/>" |
| 4287 | "</belongs-to>" |
| 4288 | "<include module=\"atop\"/>" |
| 4289 | "<feature name=\"fox\"/>" |
| 4290 | "<notification name=\"bar-notif\">" |
| 4291 | "<if-feature name=\"bar\"/>" |
| 4292 | "</notification>" |
| 4293 | "<notification name=\"fox-notif\">" |
| 4294 | "<if-feature name=\"fox\"/>" |
| 4295 | "</notification>" |
| 4296 | "<augment target-node=\"/a_pref:top\">" |
| 4297 | "<if-feature name=\"bar\"/>" |
| 4298 | "<container name=\"bar-sub\"/>" |
| 4299 | "</augment>" |
| 4300 | "<augment target-node=\"/top\">" |
| 4301 | "<container name=\"bar-sub2\"/>" |
| 4302 | "</augment>" |
| 4303 | "</submodule>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4304 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4305 | assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, (struct lys_parser_ctx *)st->yin_ctx, in, &submod), LY_SUCCESS); |
| 4306 | lysp_module_free((struct lysp_module *)submod); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4307 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4308 | ly_in_free(in, 0); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4309 | yin_ctx = NULL; |
| 4310 | submod = NULL; |
| 4311 | |
| 4312 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4313 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
Radek Krejci | 96e48da | 2020-09-04 13:18:06 +0200 | [diff] [blame] | 4314 | "<yang-version value=\"1\"/>\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4315 | "<belongs-to module=\"a\">" |
| 4316 | "<prefix value=\"a_pref\"/>" |
| 4317 | "</belongs-to>" |
| 4318 | "</submodule>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4319 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4320 | assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, (struct lys_parser_ctx *)st->yin_ctx, in, &submod), LY_SUCCESS); |
| 4321 | lysp_module_free((struct lysp_module *)submod); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4322 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4323 | ly_in_free(in, 0); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4324 | yin_ctx = NULL; |
| 4325 | submod = NULL; |
| 4326 | |
| 4327 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4328 | "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4329 | "</module>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4330 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4331 | assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, (struct lys_parser_ctx *)st->yin_ctx, in, &submod), LY_EINVAL); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4332 | logbuf_assert("Input data contains module in situation when a submodule is expected."); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4333 | lysp_module_free((struct lysp_module *)submod); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4334 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4335 | ly_in_free(in, 0); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4336 | yin_ctx = NULL; |
| 4337 | submod = NULL; |
| 4338 | |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4339 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 4340 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
Radek Krejci | 96e48da | 2020-09-04 13:18:06 +0200 | [diff] [blame] | 4341 | "<yang-version value=\"1\"/>\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4342 | "<belongs-to module=\"a\">" |
| 4343 | "<prefix value=\"a_pref\"/>" |
| 4344 | "</belongs-to>" |
| 4345 | "</submodule>" |
| 4346 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
Radek Krejci | 96e48da | 2020-09-04 13:18:06 +0200 | [diff] [blame] | 4347 | "<yang-version value=\"1\"/>\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4348 | "<belongs-to module=\"a\">" |
| 4349 | "<prefix value=\"a_pref\"/>" |
| 4350 | "</belongs-to>" |
| 4351 | "</submodule>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4352 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4353 | assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, (struct lys_parser_ctx *)st->yin_ctx, in, &submod), LY_EVALID); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4354 | logbuf_assert("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input. Line number 2."); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4355 | lysp_module_free((struct lysp_module *)submod); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4356 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 4357 | ly_in_free(in, 0); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4358 | yin_ctx = NULL; |
| 4359 | submod = NULL; |
| 4360 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4361 | st->finished_correctly = true; |
| 4362 | } |
| 4363 | |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 4364 | int |
| 4365 | main(void) |
| 4366 | { |
| 4367 | |
| 4368 | const struct CMUnitTest tests[] = { |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 4369 | 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] | 4370 | cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f), |
| 4371 | cmocka_unit_test_setup_teardown(test_yin_parse_extension_instance, setup_f, teardown_f), |
David Sedlák | 071f766 | 2019-09-12 02:02:51 +0200 | [diff] [blame] | 4372 | 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] | 4373 | 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] | 4374 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 4375 | cmocka_unit_test(test_yin_match_argument_name), |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4376 | cmocka_unit_test_setup_teardown(test_enum_elem, setup_element_test, teardown_f), |
| 4377 | cmocka_unit_test_setup_teardown(test_bit_elem, setup_element_test, teardown_f), |
| 4378 | cmocka_unit_test_setup_teardown(test_meta_elem, setup_element_test, teardown_f), |
| 4379 | cmocka_unit_test_setup_teardown(test_import_elem, setup_element_test, teardown_f), |
| 4380 | cmocka_unit_test_setup_teardown(test_status_elem, setup_element_test, teardown_f), |
| 4381 | cmocka_unit_test_setup_teardown(test_ext_elem, setup_element_test, teardown_f), |
| 4382 | cmocka_unit_test_setup_teardown(test_yin_element_elem, setup_element_test, teardown_f), |
| 4383 | cmocka_unit_test_setup_teardown(test_yangversion_elem, setup_element_test, teardown_f), |
| 4384 | cmocka_unit_test_setup_teardown(test_mandatory_elem, setup_element_test, teardown_f), |
| 4385 | cmocka_unit_test_setup_teardown(test_argument_elem, setup_element_test, teardown_f), |
| 4386 | cmocka_unit_test_setup_teardown(test_base_elem, setup_element_test, teardown_f), |
| 4387 | cmocka_unit_test_setup_teardown(test_belongsto_elem, setup_element_test, teardown_f), |
| 4388 | cmocka_unit_test_setup_teardown(test_config_elem, setup_element_test, teardown_f), |
| 4389 | cmocka_unit_test_setup_teardown(test_default_elem, setup_element_test, teardown_f), |
| 4390 | cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup_element_test, teardown_f), |
| 4391 | cmocka_unit_test_setup_teardown(test_err_msg_elem, setup_element_test, teardown_f), |
| 4392 | cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup_element_test, teardown_f), |
| 4393 | cmocka_unit_test_setup_teardown(test_iffeature_elem, setup_element_test, teardown_f), |
| 4394 | cmocka_unit_test_setup_teardown(test_length_elem, setup_element_test, teardown_f), |
| 4395 | cmocka_unit_test_setup_teardown(test_modifier_elem, setup_element_test, teardown_f), |
| 4396 | cmocka_unit_test_setup_teardown(test_namespace_elem, setup_element_test, teardown_f), |
| 4397 | cmocka_unit_test_setup_teardown(test_pattern_elem, setup_element_test, teardown_f), |
| 4398 | cmocka_unit_test_setup_teardown(test_value_position_elem, setup_element_test, teardown_f), |
| 4399 | cmocka_unit_test_setup_teardown(test_prefix_elem, setup_element_test, teardown_f), |
| 4400 | cmocka_unit_test_setup_teardown(test_range_elem, setup_element_test, teardown_f), |
| 4401 | cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup_element_test, teardown_f), |
| 4402 | cmocka_unit_test_setup_teardown(test_revision_date_elem, setup_element_test, teardown_f), |
| 4403 | cmocka_unit_test_setup_teardown(test_unique_elem, setup_element_test, teardown_f), |
| 4404 | cmocka_unit_test_setup_teardown(test_units_elem, setup_element_test, teardown_f), |
| 4405 | cmocka_unit_test_setup_teardown(test_when_elem, setup_element_test, teardown_f), |
| 4406 | cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup_element_test, teardown_f), |
| 4407 | cmocka_unit_test_setup_teardown(test_type_elem, setup_element_test, teardown_f), |
| 4408 | cmocka_unit_test_setup_teardown(test_max_elems_elem, setup_element_test, teardown_f), |
| 4409 | cmocka_unit_test_setup_teardown(test_min_elems_elem, setup_element_test, teardown_f), |
| 4410 | cmocka_unit_test_setup_teardown(test_ordby_elem, setup_element_test, teardown_f), |
| 4411 | cmocka_unit_test_setup_teardown(test_any_elem, setup_element_test, teardown_f), |
| 4412 | cmocka_unit_test_setup_teardown(test_leaf_elem, setup_element_test, teardown_f), |
| 4413 | cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup_element_test, teardown_f), |
| 4414 | cmocka_unit_test_setup_teardown(test_presence_elem, setup_element_test, teardown_f), |
| 4415 | cmocka_unit_test_setup_teardown(test_key_elem, setup_element_test, teardown_f), |
| 4416 | cmocka_unit_test_setup_teardown(test_typedef_elem, setup_element_test, teardown_f), |
| 4417 | cmocka_unit_test_setup_teardown(test_refine_elem, setup_element_test, teardown_f), |
| 4418 | cmocka_unit_test_setup_teardown(test_uses_elem, setup_element_test, teardown_f), |
| 4419 | cmocka_unit_test_setup_teardown(test_revision_elem, setup_element_test, teardown_f), |
| 4420 | cmocka_unit_test_setup_teardown(test_include_elem, setup_element_test, teardown_f), |
| 4421 | cmocka_unit_test_setup_teardown(test_list_elem, setup_element_test, teardown_f), |
| 4422 | cmocka_unit_test_setup_teardown(test_notification_elem, setup_element_test, teardown_f), |
| 4423 | cmocka_unit_test_setup_teardown(test_grouping_elem, setup_element_test, teardown_f), |
| 4424 | cmocka_unit_test_setup_teardown(test_container_elem, setup_element_test, teardown_f), |
| 4425 | cmocka_unit_test_setup_teardown(test_case_elem, setup_element_test, teardown_f), |
| 4426 | cmocka_unit_test_setup_teardown(test_choice_elem, setup_element_test, teardown_f), |
| 4427 | cmocka_unit_test_setup_teardown(test_inout_elem, setup_element_test, teardown_f), |
| 4428 | cmocka_unit_test_setup_teardown(test_action_elem, setup_element_test, teardown_f), |
| 4429 | cmocka_unit_test_setup_teardown(test_augment_elem, setup_element_test, teardown_f), |
| 4430 | cmocka_unit_test_setup_teardown(test_deviate_elem, setup_element_test, teardown_f), |
| 4431 | cmocka_unit_test_setup_teardown(test_deviation_elem, setup_element_test, teardown_f), |
| 4432 | cmocka_unit_test_setup_teardown(test_module_elem, setup_element_test, teardown_f), |
| 4433 | cmocka_unit_test_setup_teardown(test_submodule_elem, setup_element_test, teardown_f), |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4434 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 4435 | cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_f, teardown_f), |
| 4436 | cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup_f, teardown_f), |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 4437 | }; |
| 4438 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 4439 | 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] | 4440 | } |