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