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