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