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