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