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 */ |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3566 | data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END; |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3567 | assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS); |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3568 | lysp_action_inout_free(st->ctx, &inout); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3569 | memset(&inout, 0, sizeof inout); |
| 3570 | |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3571 | data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" ELEMENT_WRAPPER_END; |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3572 | assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS); |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3573 | lysp_action_inout_free(st->ctx, &inout); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3574 | memset(&inout, 0, sizeof inout); |
| 3575 | |
| 3576 | /* invalid combinations */ |
| 3577 | data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END; |
| 3578 | 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] | 3579 | logbuf_assert("Unexpected attribute \"name\" of \"input\" element. Line number 1."); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3580 | memset(&inout, 0, sizeof inout); |
| 3581 | |
| 3582 | st->finished_correctly = true; |
| 3583 | } |
| 3584 | |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3585 | static void |
| 3586 | test_action_elem(void **state) |
| 3587 | { |
| 3588 | struct state *st = *state; |
| 3589 | const char *data; |
| 3590 | struct lysp_action *actions = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 3591 | struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions}; |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3592 | |
| 3593 | /* max subelems */ |
| 3594 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3595 | data = ELEMENT_WRAPPER_START |
| 3596 | "<action name=\"act\">" |
| 3597 | "<description><text>desc</text></description>" |
| 3598 | "<grouping name=\"grouping\"/>" |
| 3599 | "<if-feature name=\"iff\"/>" |
| 3600 | "<input><uses name=\"uses-name\"/></input>" |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3601 | "<output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>" |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3602 | "<reference><text>ref</text></reference>" |
| 3603 | "<status value=\"deprecated\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3604 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3605 | EXT_SUBELEM |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3606 | "</action>" |
| 3607 | ELEMENT_WRAPPER_END; |
| 3608 | assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS); |
| 3609 | assert_null(actions->parent); |
| 3610 | assert_int_equal(actions->nodetype, LYS_ACTION); |
| 3611 | assert_true(actions->flags & LYS_STATUS_DEPRC); |
| 3612 | assert_string_equal(actions->name, "act"); |
| 3613 | assert_string_equal(actions->dsc, "desc"); |
| 3614 | assert_string_equal(actions->ref, "ref"); |
| 3615 | assert_string_equal(*actions->iffeatures, "iff"); |
| 3616 | assert_string_equal(actions->typedefs->name, "tpdf"); |
| 3617 | assert_string_equal(actions->groupings->name, "grouping"); |
| 3618 | assert_string_equal(actions->input.data->name, "uses-name"); |
| 3619 | assert_string_equal(actions->output.musts->arg, "cond"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3620 | 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] | 3621 | assert_int_equal(actions->exts[0].insubstmt_index, 0); |
| 3622 | assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3623 | FREE_ARRAY(st->ctx, actions, lysp_action_free) |
| 3624 | actions = NULL; |
| 3625 | |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3626 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3627 | data = ELEMENT_WRAPPER_START |
| 3628 | "<rpc name=\"act\">" |
| 3629 | "<description><text>desc</text></description>" |
| 3630 | "<grouping name=\"grouping\"/>" |
| 3631 | "<if-feature name=\"iff\"/>" |
| 3632 | "<input><uses name=\"uses-name\"/></input>" |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3633 | "<output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>" |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3634 | "<reference><text>ref</text></reference>" |
| 3635 | "<status value=\"deprecated\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3636 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3637 | EXT_SUBELEM |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3638 | "</rpc>" |
| 3639 | ELEMENT_WRAPPER_END; |
| 3640 | assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS); |
| 3641 | assert_null(actions->parent); |
| 3642 | assert_int_equal(actions->nodetype, LYS_ACTION); |
| 3643 | assert_true(actions->flags & LYS_STATUS_DEPRC); |
| 3644 | assert_string_equal(actions->name, "act"); |
| 3645 | assert_string_equal(actions->dsc, "desc"); |
| 3646 | assert_string_equal(actions->ref, "ref"); |
| 3647 | assert_string_equal(*actions->iffeatures, "iff"); |
| 3648 | assert_string_equal(actions->typedefs->name, "tpdf"); |
| 3649 | assert_string_equal(actions->groupings->name, "grouping"); |
| 3650 | assert_string_equal(actions->input.data->name, "uses-name"); |
| 3651 | assert_string_equal(actions->output.musts->arg, "cond"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3652 | 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] | 3653 | assert_int_equal(actions->exts[0].insubstmt_index, 0); |
| 3654 | assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3655 | FREE_ARRAY(st->ctx, actions, lysp_action_free) |
| 3656 | actions = NULL; |
| 3657 | |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3658 | /* min subelems */ |
| 3659 | data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END; |
| 3660 | assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS); |
| 3661 | assert_string_equal(actions->name, "act"); |
| 3662 | FREE_ARRAY(st->ctx, actions, lysp_action_free) |
| 3663 | actions = NULL; |
| 3664 | |
| 3665 | st->finished_correctly = true; |
| 3666 | } |
| 3667 | |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3668 | static void |
| 3669 | test_augment_elem(void **state) |
| 3670 | { |
| 3671 | struct state *st = *state; |
| 3672 | const char *data; |
| 3673 | struct lysp_augment *augments = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 3674 | struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments}; |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3675 | |
| 3676 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3677 | data = ELEMENT_WRAPPER_START |
| 3678 | "<augment target-node=\"target\">" |
| 3679 | "<action name=\"action\"/>" |
| 3680 | "<anydata name=\"anyd\"/>" |
| 3681 | "<anyxml name=\"anyx\"/>" |
| 3682 | "<case name=\"case\"/>" |
| 3683 | "<choice name=\"choice\"/>" |
| 3684 | "<container name=\"subcont\"/>" |
| 3685 | "<description><text>desc</text></description>" |
| 3686 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3687 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3688 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3689 | "<list name=\"list\"/>" |
| 3690 | "<notification name=\"notif\"/>" |
| 3691 | "<reference><text>ref</text></reference>" |
| 3692 | "<status value=\"current\"/>" |
| 3693 | "<uses name=\"uses\"/>" |
| 3694 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3695 | EXT_SUBELEM |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3696 | "</augment>" |
| 3697 | ELEMENT_WRAPPER_END; |
| 3698 | assert_int_equal(test_element_helper(st, &data, &aug_meta, NULL, NULL, true), LY_SUCCESS); |
| 3699 | assert_string_equal(augments->nodeid, "target"); |
| 3700 | assert_null(augments->parent); |
| 3701 | assert_int_equal(augments->nodetype, LYS_AUGMENT); |
| 3702 | assert_true(augments->flags & LYS_STATUS_CURR); |
| 3703 | assert_string_equal(augments->dsc, "desc"); |
| 3704 | assert_string_equal(augments->ref, "ref"); |
| 3705 | assert_string_equal(augments->when->cond, "when-cond"); |
| 3706 | assert_string_equal(*augments->iffeatures, "iff"); |
| 3707 | assert_string_equal(augments->child->name, "anyd"); |
| 3708 | assert_int_equal(augments->child->nodetype, LYS_ANYDATA); |
| 3709 | assert_string_equal(augments->child->next->name, "anyx"); |
| 3710 | assert_int_equal(augments->child->next->nodetype, LYS_ANYXML); |
| 3711 | assert_string_equal(augments->child->next->next->name, "case"); |
| 3712 | assert_int_equal(augments->child->next->next->nodetype, LYS_CASE); |
| 3713 | assert_string_equal(augments->child->next->next->next->name, "choice"); |
| 3714 | assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE); |
| 3715 | assert_string_equal(augments->child->next->next->next->next->name, "subcont"); |
| 3716 | assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER); |
| 3717 | assert_string_equal(augments->child->next->next->next->next->next->name, "leaf"); |
| 3718 | assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF); |
| 3719 | assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist"); |
| 3720 | assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3721 | assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list"); |
| 3722 | assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3723 | assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses"); |
| 3724 | assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3725 | assert_null(augments->child->next->next->next->next->next->next->next->next->next); |
| 3726 | assert_string_equal(augments->actions->name, "action"); |
| 3727 | assert_string_equal(augments->notifs->name, "notif"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3728 | 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] | 3729 | assert_int_equal(augments->exts[0].insubstmt_index, 0); |
| 3730 | assert_int_equal(augments->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3731 | FREE_ARRAY(st->ctx, augments, lysp_augment_free) |
| 3732 | augments = NULL; |
| 3733 | |
| 3734 | data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END; |
| 3735 | assert_int_equal(test_element_helper(st, &data, &aug_meta, NULL, NULL, true), LY_SUCCESS); |
| 3736 | assert_string_equal(augments->nodeid, "target"); |
| 3737 | FREE_ARRAY(st->ctx, augments, lysp_augment_free) |
| 3738 | augments = NULL; |
| 3739 | |
| 3740 | st->finished_correctly = true; |
| 3741 | } |
| 3742 | |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3743 | static void |
| 3744 | test_deviate_elem(void **state) |
| 3745 | { |
| 3746 | struct state *st = *state; |
| 3747 | const char *data; |
| 3748 | struct lysp_deviate *deviates = NULL; |
| 3749 | struct lysp_deviate_add *d_add; |
| 3750 | struct lysp_deviate_rpl *d_rpl; |
| 3751 | struct lysp_deviate_del *d_del; |
| 3752 | |
| 3753 | /* all valid arguments with min subelems */ |
| 3754 | data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END; |
| 3755 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3756 | assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED); |
| 3757 | lysp_deviate_free(st->ctx, deviates); |
| 3758 | free(deviates); |
| 3759 | deviates = NULL; |
| 3760 | |
| 3761 | data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END; |
| 3762 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3763 | assert_int_equal(deviates->mod, LYS_DEV_ADD); |
| 3764 | lysp_deviate_free(st->ctx, deviates); |
| 3765 | free(deviates); |
| 3766 | deviates = NULL; |
| 3767 | |
| 3768 | data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END; |
| 3769 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3770 | assert_int_equal(deviates->mod, LYS_DEV_REPLACE); |
| 3771 | lysp_deviate_free(st->ctx, deviates); |
| 3772 | free(deviates); |
| 3773 | deviates = NULL; |
| 3774 | |
| 3775 | data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END; |
| 3776 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3777 | assert_int_equal(deviates->mod, LYS_DEV_DELETE); |
| 3778 | lysp_deviate_free(st->ctx, deviates); |
| 3779 | free(deviates); |
| 3780 | deviates = NULL; |
| 3781 | |
| 3782 | /* max subelems and valid arguments */ |
| 3783 | data = ELEMENT_WRAPPER_START |
| 3784 | "<deviate value=\"not-supported\">" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3785 | EXT_SUBELEM |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3786 | "</deviate>" |
| 3787 | ELEMENT_WRAPPER_END; |
| 3788 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3789 | assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3790 | 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] | 3791 | assert_int_equal(deviates->exts[0].insubstmt_index, 0); |
| 3792 | assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3793 | lysp_deviate_free(st->ctx, deviates); |
| 3794 | free(deviates); |
| 3795 | deviates = NULL; |
| 3796 | |
| 3797 | data = ELEMENT_WRAPPER_START |
| 3798 | "<deviate value=\"add\">" |
| 3799 | "<units name=\"units\"/>" |
| 3800 | "<must condition=\"cond\"/>" |
| 3801 | "<unique tag=\"utag\"/>" |
| 3802 | "<default value=\"def\"/>" |
| 3803 | "<config value=\"true\"/>" |
| 3804 | "<mandatory value=\"true\"/>" |
| 3805 | "<min-elements value=\"5\"/>" |
| 3806 | "<max-elements value=\"15\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3807 | EXT_SUBELEM |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3808 | "</deviate>" |
| 3809 | ELEMENT_WRAPPER_END; |
| 3810 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3811 | d_add = (struct lysp_deviate_add *)deviates; |
| 3812 | assert_int_equal(d_add->mod, LYS_DEV_ADD); |
| 3813 | assert_null(d_add->next); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3814 | assert_string_equal(d_add->units, "units"); |
| 3815 | assert_string_equal(d_add->musts->arg, "cond"); |
| 3816 | assert_string_equal(*d_add->uniques, "utag"); |
| 3817 | assert_string_equal(*d_add->dflts, "def"); |
| 3818 | assert_true(d_add->flags & LYS_MAND_TRUE && d_add->flags & LYS_CONFIG_W); |
| 3819 | assert_int_equal(d_add->min, 5); |
| 3820 | assert_int_equal(d_add->max, 15); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3821 | 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] | 3822 | assert_int_equal(deviates->exts[0].insubstmt_index, 0); |
| 3823 | assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3824 | lysp_deviate_free(st->ctx, deviates); |
| 3825 | free(deviates); |
| 3826 | deviates = NULL; |
| 3827 | |
| 3828 | data = ELEMENT_WRAPPER_START |
| 3829 | "<deviate value=\"replace\">" |
| 3830 | "<type name=\"newtype\"/>" |
| 3831 | "<units name=\"uni\"/>" |
| 3832 | "<default value=\"def\"/>" |
| 3833 | "<config value=\"true\"/>" |
| 3834 | "<mandatory value=\"true\"/>" |
| 3835 | "<min-elements value=\"5\"/>" |
| 3836 | "<max-elements value=\"15\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3837 | EXT_SUBELEM |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3838 | "</deviate>" |
| 3839 | ELEMENT_WRAPPER_END; |
| 3840 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3841 | d_rpl = (struct lysp_deviate_rpl *)deviates; |
| 3842 | assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE); |
| 3843 | assert_null(d_rpl->next); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3844 | assert_string_equal(d_rpl->type->name, "newtype"); |
| 3845 | assert_string_equal(d_rpl->units, "uni"); |
| 3846 | assert_string_equal(d_rpl->dflt, "def"); |
| 3847 | assert_true(d_rpl->flags & LYS_MAND_TRUE && d_rpl->flags & LYS_CONFIG_W); |
| 3848 | assert_int_equal(d_rpl->min, 5); |
| 3849 | assert_int_equal(d_rpl->max, 15); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3850 | 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] | 3851 | assert_int_equal(deviates->exts[0].insubstmt_index, 0); |
| 3852 | assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3853 | lysp_deviate_free(st->ctx, deviates); |
| 3854 | free(deviates); |
| 3855 | deviates = NULL; |
| 3856 | |
| 3857 | data = ELEMENT_WRAPPER_START |
| 3858 | "<deviate value=\"delete\">" |
| 3859 | "<units name=\"u\"/>" |
| 3860 | "<must condition=\"c\"/>" |
| 3861 | "<unique tag=\"tag\"/>" |
| 3862 | "<default value=\"default\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3863 | EXT_SUBELEM |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3864 | "</deviate>" |
| 3865 | ELEMENT_WRAPPER_END; |
| 3866 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3867 | d_del = (struct lysp_deviate_del *)deviates; |
| 3868 | assert_int_equal(d_del->mod, LYS_DEV_DELETE); |
| 3869 | assert_null(d_del->next); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3870 | assert_string_equal(d_del->units, "u"); |
| 3871 | assert_string_equal(d_del->musts->arg, "c"); |
| 3872 | assert_string_equal(*d_del->uniques, "tag"); |
| 3873 | assert_string_equal(*d_del->dflts, "default"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3874 | 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] | 3875 | assert_int_equal(deviates->exts[0].insubstmt_index, 0); |
| 3876 | assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3877 | lysp_deviate_free(st->ctx, deviates); |
| 3878 | free(deviates); |
| 3879 | deviates = NULL; |
| 3880 | |
| 3881 | /* invalid arguments */ |
| 3882 | data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END; |
| 3883 | 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] | 3884 | 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] | 3885 | deviates = NULL; |
| 3886 | |
| 3887 | data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END; |
| 3888 | 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] | 3889 | 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] | 3890 | deviates = NULL; |
| 3891 | |
| 3892 | data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END; |
| 3893 | 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] | 3894 | 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] | 3895 | deviates = NULL; |
| 3896 | |
| 3897 | data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END; |
| 3898 | 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] | 3899 | 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] | 3900 | deviates = NULL; |
| 3901 | |
| 3902 | data = ELEMENT_WRAPPER_START |
| 3903 | "<deviate value=\"not-supported\">" |
| 3904 | "<must condition=\"c\"/>" |
| 3905 | "</deviate>" |
| 3906 | ELEMENT_WRAPPER_END; |
| 3907 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID); |
| 3908 | logbuf_assert("Deviate of this type doesn't allow \"must\" as it's sub-element. Line number 1."); |
| 3909 | |
| 3910 | st->finished_correctly = true; |
| 3911 | } |
| 3912 | |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3913 | static void |
| 3914 | test_deviation_elem(void **state) |
| 3915 | { |
| 3916 | struct state *st = *state; |
| 3917 | const char *data; |
| 3918 | struct lysp_deviation *deviations = NULL; |
| 3919 | |
| 3920 | /* min subelems */ |
| 3921 | data = ELEMENT_WRAPPER_START |
| 3922 | "<deviation target-node=\"target\">" |
| 3923 | "<deviate value=\"not-supported\"/>" |
| 3924 | "</deviation>" |
| 3925 | ELEMENT_WRAPPER_END; |
| 3926 | assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, true), LY_SUCCESS); |
| 3927 | assert_string_equal(deviations->nodeid, "target"); |
| 3928 | assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED); |
| 3929 | FREE_ARRAY(st->ctx, deviations, lysp_deviation_free); |
| 3930 | deviations = NULL; |
| 3931 | |
| 3932 | /* max subelems */ |
| 3933 | data = ELEMENT_WRAPPER_START |
| 3934 | "<deviation target-node=\"target\">" |
| 3935 | "<reference><text>ref</text></reference>" |
| 3936 | "<description><text>desc</text></description>" |
| 3937 | "<deviate value=\"add\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3938 | EXT_SUBELEM |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3939 | "</deviation>" |
| 3940 | ELEMENT_WRAPPER_END; |
| 3941 | assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, true), LY_SUCCESS); |
| 3942 | assert_string_equal(deviations->nodeid, "target"); |
| 3943 | assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD); |
| 3944 | assert_string_equal(deviations->ref, "ref"); |
| 3945 | assert_string_equal(deviations->dsc, "desc"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3946 | 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] | 3947 | assert_int_equal(deviations->exts[0].insubstmt_index, 0); |
| 3948 | assert_int_equal(deviations->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3949 | FREE_ARRAY(st->ctx, deviations, lysp_deviation_free); |
| 3950 | deviations = NULL; |
| 3951 | |
| 3952 | /* invalid */ |
| 3953 | data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END; |
| 3954 | assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, false), LY_EVALID); |
| 3955 | FREE_ARRAY(st->ctx, deviations, lysp_deviation_free); |
| 3956 | deviations = NULL; |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 3957 | logbuf_assert("Missing mandatory sub-element \"deviate\" of \"deviation\" element. Line number 1."); |
| 3958 | /* TODO */ |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3959 | st->finished_correctly = true; |
| 3960 | } |
| 3961 | |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3962 | static void |
| 3963 | test_module_elem(void **state) |
| 3964 | { |
| 3965 | struct state *st = *state; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 3966 | const char *data, *name, *prefix; |
| 3967 | size_t name_len, prefix_len; |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3968 | struct yin_arg_record *attrs = NULL; |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3969 | struct lys_module *lys_mod = NULL; |
| 3970 | struct lysp_module *lysp_mod = NULL; |
| 3971 | |
| 3972 | /* max subelems */ |
| 3973 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 3974 | lys_mod = calloc(1, sizeof *lys_mod); |
| 3975 | lysp_mod = calloc(1, sizeof *lysp_mod); |
| 3976 | lys_mod->ctx = st->ctx; |
| 3977 | lysp_mod->mod = lys_mod; |
| 3978 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
| 3979 | "<yang-version value=\"1.1\"/>\n" |
| 3980 | "<namespace uri=\"ns\"/>\n" |
| 3981 | "<prefix value=\"pref\"/>\n" |
| 3982 | "<include module=\"b-mod\"/>\n" |
| 3983 | "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n" |
| 3984 | "<organization><text>org</text></organization>\n" |
| 3985 | "<contact><text>contact</text></contact>\n" |
| 3986 | "<description><text>desc</text></description>" |
| 3987 | "<reference><text>ref</text></reference>\n" |
| 3988 | "<revision date=\"2019-02-02\"/>\n" |
| 3989 | "<anydata name=\"anyd\"/>\n" |
| 3990 | "<anyxml name=\"anyx\"/>\n" |
| 3991 | "<choice name=\"choice\"/>\n" |
| 3992 | "<container name=\"cont\"/>\n" |
| 3993 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 3994 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 3995 | "<list name=\"sub-list\"/>\n" |
| 3996 | "<uses name=\"uses-name\"/>\n" |
| 3997 | "<augment target-node=\"target\"/>\n" |
| 3998 | "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n" |
| 3999 | "<extension name=\"ext\"/>\n" |
| 4000 | "<feature name=\"feature\"/>\n" |
| 4001 | "<grouping name=\"grp\"/>\n" |
| 4002 | "<identity name=\"ident-name\"/>\n" |
| 4003 | "<notification name=\"notf\"/>\n" |
| 4004 | "<rpc name=\"rpc-name\"/>\n" |
| 4005 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 4006 | EXT_SUBELEM"\n" |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 4007 | "</module>\n"; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 4008 | 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] | 4009 | assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS); |
| 4010 | assert_int_equal(yin_parse_mod(st->yin_ctx, attrs, &data, lysp_mod), LY_SUCCESS); |
| 4011 | assert_string_equal(lysp_mod->mod->name, "mod"); |
| 4012 | assert_string_equal(lysp_mod->revs, "2019-02-02"); |
| 4013 | assert_string_equal(lysp_mod->mod->ns, "ns"); |
| 4014 | assert_string_equal(lysp_mod->mod->prefix, "pref"); |
| 4015 | assert_null(lysp_mod->mod->filepath); |
| 4016 | assert_string_equal(lysp_mod->mod->org, "org"); |
| 4017 | assert_string_equal(lysp_mod->mod->contact, "contact"); |
| 4018 | assert_string_equal(lysp_mod->mod->dsc, "desc"); |
| 4019 | assert_string_equal(lysp_mod->mod->ref, "ref"); |
| 4020 | assert_int_equal(lysp_mod->mod->version, LYS_VERSION_1_1); |
| 4021 | assert_string_equal(lysp_mod->imports->name, "a-mod"); |
| 4022 | assert_string_equal(lysp_mod->includes->name, "b-mod"); |
| 4023 | assert_string_equal(lysp_mod->extensions->name, "ext"); |
| 4024 | assert_string_equal(lysp_mod->features->name, "feature"); |
| 4025 | assert_string_equal(lysp_mod->identities->name, "ident-name"); |
| 4026 | assert_string_equal(lysp_mod->typedefs->name, "tpdf"); |
| 4027 | assert_string_equal(lysp_mod->groupings->name, "grp"); |
| 4028 | assert_string_equal(lysp_mod->data->name, "anyd"); |
| 4029 | assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA); |
| 4030 | assert_string_equal(lysp_mod->data->next->name, "anyx"); |
| 4031 | assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML); |
| 4032 | assert_string_equal(lysp_mod->data->next->next->name, "choice"); |
| 4033 | assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE); |
| 4034 | assert_string_equal(lysp_mod->data->next->next->next->name, "cont"); |
| 4035 | assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER); |
| 4036 | assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf"); |
| 4037 | assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF); |
| 4038 | assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist"); |
| 4039 | assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 4040 | assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list"); |
| 4041 | assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 4042 | assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name"); |
| 4043 | assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 4044 | assert_null(lysp_mod->data->next->next->next->next->next->next->next->next); |
| 4045 | assert_string_equal(lysp_mod->augments->nodeid, "target"); |
| 4046 | assert_string_equal(lysp_mod->rpcs->name, "rpc-name"); |
| 4047 | assert_string_equal(lysp_mod->notifs->name, "notf"); |
| 4048 | assert_string_equal(lysp_mod->deviations->nodeid, "target"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 4049 | 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] | 4050 | assert_int_equal(lysp_mod->exts[0].insubstmt_index, 0); |
| 4051 | assert_int_equal(lysp_mod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 4052 | lysp_module_free(lysp_mod); |
| 4053 | lys_module_free(lys_mod, NULL); |
| 4054 | FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec); |
| 4055 | attrs = NULL; |
| 4056 | |
| 4057 | /* min subelems */ |
| 4058 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 4059 | lys_mod = calloc(1, sizeof *lys_mod); |
| 4060 | lysp_mod = calloc(1, sizeof *lysp_mod); |
| 4061 | lys_mod->ctx = st->ctx; |
| 4062 | lysp_mod->mod = lys_mod; |
| 4063 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">" |
| 4064 | "<namespace uri=\"ns\"/>" |
| 4065 | "<prefix value=\"pref\"/>" |
| 4066 | "<yang-version value=\"1.1\"/>" |
| 4067 | "</module>"; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 4068 | 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] | 4069 | assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS); |
| 4070 | 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] | 4071 | assert_string_equal(lysp_mod->mod->name, "mod"); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 4072 | lysp_module_free(lysp_mod); |
| 4073 | lys_module_free(lys_mod, NULL); |
| 4074 | FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec); |
| 4075 | attrs = NULL; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4076 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 4077 | /* incorrect subelem order */ |
| 4078 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 4079 | lys_mod = calloc(1, sizeof *lys_mod); |
| 4080 | lysp_mod = calloc(1, sizeof *lysp_mod); |
| 4081 | lys_mod->ctx = st->ctx; |
| 4082 | lysp_mod->mod = lys_mod; |
| 4083 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">" |
| 4084 | "<feature name=\"feature\"/>\n" |
| 4085 | "<namespace uri=\"ns\"/>" |
| 4086 | "<prefix value=\"pref\"/>" |
| 4087 | "<yang-version value=\"1.1\"/>" |
| 4088 | "</module>"; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 4089 | 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] | 4090 | assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS); |
| 4091 | 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] | 4092 | 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] | 4093 | lysp_module_free(lysp_mod); |
| 4094 | lys_module_free(lys_mod, NULL); |
| 4095 | FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec); |
| 4096 | attrs = NULL; |
| 4097 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4098 | st->finished_correctly = true; |
| 4099 | } |
| 4100 | |
| 4101 | static void |
| 4102 | test_submodule_elem(void **state) |
| 4103 | { |
| 4104 | struct state *st = *state; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 4105 | const char *data, *name, *prefix; |
| 4106 | size_t name_len, prefix_len; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4107 | struct yin_arg_record *attrs = NULL; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4108 | struct lysp_submodule *lysp_submod = NULL; |
| 4109 | |
| 4110 | /* max subelements */ |
| 4111 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 4112 | lysp_submod = calloc(1, sizeof *lysp_submod); |
| 4113 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
| 4114 | "<yang-version value=\"1.1\"/>\n" |
| 4115 | "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>" |
| 4116 | "<include module=\"b-mod\"/>\n" |
| 4117 | "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n" |
| 4118 | "<organization><text>org</text></organization>\n" |
| 4119 | "<contact><text>contact</text></contact>\n" |
| 4120 | "<description><text>desc</text></description>" |
| 4121 | "<reference><text>ref</text></reference>\n" |
| 4122 | "<revision date=\"2019-02-02\"/>\n" |
| 4123 | "<anydata name=\"anyd\"/>\n" |
| 4124 | "<anyxml name=\"anyx\"/>\n" |
| 4125 | "<choice name=\"choice\"/>\n" |
| 4126 | "<container name=\"cont\"/>\n" |
| 4127 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 4128 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 4129 | "<list name=\"sub-list\"/>\n" |
| 4130 | "<uses name=\"uses-name\"/>\n" |
| 4131 | "<augment target-node=\"target\"/>\n" |
| 4132 | "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n" |
| 4133 | "<extension name=\"ext\"/>\n" |
| 4134 | "<feature name=\"feature\"/>\n" |
| 4135 | "<grouping name=\"grp\"/>\n" |
| 4136 | "<identity name=\"ident-name\"/>\n" |
| 4137 | "<notification name=\"notf\"/>\n" |
| 4138 | "<rpc name=\"rpc-name\"/>\n" |
| 4139 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 4140 | EXT_SUBELEM"\n" |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4141 | "</submodule>\n"; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 4142 | 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] | 4143 | assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS); |
| 4144 | assert_int_equal(yin_parse_submod(st->yin_ctx, attrs, &data, lysp_submod), LY_SUCCESS); |
| 4145 | |
| 4146 | assert_string_equal(lysp_submod->name, "mod"); |
| 4147 | assert_string_equal(lysp_submod->revs, "2019-02-02"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4148 | assert_string_equal(lysp_submod->prefix, "pref"); |
| 4149 | assert_null(lysp_submod->filepath); |
| 4150 | assert_string_equal(lysp_submod->org, "org"); |
| 4151 | assert_string_equal(lysp_submod->contact, "contact"); |
| 4152 | assert_string_equal(lysp_submod->dsc, "desc"); |
| 4153 | assert_string_equal(lysp_submod->ref, "ref"); |
| 4154 | assert_int_equal(lysp_submod->version, LYS_VERSION_1_1); |
| 4155 | assert_string_equal(lysp_submod->imports->name, "a-mod"); |
| 4156 | assert_string_equal(lysp_submod->includes->name, "b-mod"); |
| 4157 | assert_string_equal(lysp_submod->extensions->name, "ext"); |
| 4158 | assert_string_equal(lysp_submod->features->name, "feature"); |
| 4159 | assert_string_equal(lysp_submod->identities->name, "ident-name"); |
| 4160 | assert_string_equal(lysp_submod->typedefs->name, "tpdf"); |
| 4161 | assert_string_equal(lysp_submod->groupings->name, "grp"); |
| 4162 | assert_string_equal(lysp_submod->data->name, "anyd"); |
| 4163 | assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA); |
| 4164 | assert_string_equal(lysp_submod->data->next->name, "anyx"); |
| 4165 | assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML); |
| 4166 | assert_string_equal(lysp_submod->data->next->next->name, "choice"); |
| 4167 | assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE); |
| 4168 | assert_string_equal(lysp_submod->data->next->next->next->name, "cont"); |
| 4169 | assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER); |
| 4170 | assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf"); |
| 4171 | assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF); |
| 4172 | assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist"); |
| 4173 | assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 4174 | assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list"); |
| 4175 | assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 4176 | assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name"); |
| 4177 | assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 4178 | assert_null(lysp_submod->data->next->next->next->next->next->next->next->next); |
| 4179 | assert_string_equal(lysp_submod->augments->nodeid, "target"); |
| 4180 | assert_string_equal(lysp_submod->rpcs->name, "rpc-name"); |
| 4181 | assert_string_equal(lysp_submod->notifs->name, "notf"); |
| 4182 | assert_string_equal(lysp_submod->deviations->nodeid, "target"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 4183 | 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] | 4184 | assert_int_equal(lysp_submod->exts[0].insubstmt_index, 0); |
| 4185 | assert_int_equal(lysp_submod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4186 | |
| 4187 | lysp_submodule_free(st->ctx, lysp_submod); |
| 4188 | FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec); |
| 4189 | attrs = NULL; |
| 4190 | |
| 4191 | /* min subelemnts */ |
| 4192 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 4193 | lysp_submod = calloc(1, sizeof *lysp_submod); |
| 4194 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">" |
| 4195 | "<yang-version value=\"1.0\"/>" |
| 4196 | "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>" |
| 4197 | "</submodule>"; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 4198 | 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] | 4199 | assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS); |
| 4200 | assert_int_equal(yin_parse_submod(st->yin_ctx, attrs, &data, lysp_submod), LY_SUCCESS); |
| 4201 | assert_string_equal(lysp_submod->prefix, "pref"); |
| 4202 | assert_string_equal(lysp_submod->belongsto, "mod-name"); |
| 4203 | assert_int_equal(lysp_submod->version, LYS_VERSION_1_0); |
| 4204 | lysp_submodule_free(st->ctx, lysp_submod); |
| 4205 | FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec); |
| 4206 | attrs = NULL; |
| 4207 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 4208 | /* incorrect subelem order */ |
| 4209 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 4210 | lysp_submod = calloc(1, sizeof *lysp_submod); |
| 4211 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">" |
| 4212 | "<yang-version value=\"1.0\"/>" |
| 4213 | "<reference><text>ref</text></reference>\n" |
| 4214 | "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>" |
| 4215 | "</submodule>"; |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 4216 | 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] | 4217 | assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS); |
| 4218 | 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] | 4219 | 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] | 4220 | lysp_submodule_free(st->ctx, lysp_submod); |
| 4221 | FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec); |
| 4222 | attrs = NULL; |
| 4223 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4224 | st->finished_correctly = true; |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 4225 | } |
| 4226 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4227 | static void |
| 4228 | test_yin_parse_module(void **state) |
| 4229 | { |
| 4230 | struct state *st = *state; |
| 4231 | const char *data; |
| 4232 | struct lys_module *mod; |
| 4233 | struct yin_parser_ctx *yin_ctx = NULL; |
| 4234 | |
| 4235 | mod = calloc(1, sizeof *mod); |
| 4236 | mod->ctx = st->ctx; |
David Sedlák | d284488 | 2019-09-13 16:01:22 +0200 | [diff] [blame] | 4237 | 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" |
| 4238 | "<yang-version value=\"1.1\"/>\n" |
| 4239 | "<namespace uri=\"urn:tests:extensions:metadata:a\"/>\n" |
| 4240 | "<prefix value=\"a\"/>\n" |
| 4241 | "<import module=\"ietf-yang-metadata\">\n" |
| 4242 | "<prefix value=\"md\"/>\n" |
| 4243 | "</import>\n" |
| 4244 | "<feature name=\"f\"/>\n" |
| 4245 | "<md:annotation name=\"x\">\n" |
| 4246 | "<description>\n" |
| 4247 | "<text>test</text>\n" |
| 4248 | "</description>\n" |
| 4249 | "<reference>\n" |
| 4250 | "<text>test</text>\n" |
| 4251 | "</reference>\n" |
| 4252 | "<if-feature name=\"f\"/>\n" |
| 4253 | "<status value=\"current\"/>\n" |
| 4254 | "<type name=\"uint8\"/>\n" |
| 4255 | "<units name=\"meters\"/>\n" |
| 4256 | "</md:annotation>\n" |
| 4257 | "</module>\n"; |
| 4258 | assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS); |
| 4259 | assert_null(mod->parsed->exts->child->next->child); |
| 4260 | assert_string_equal(mod->parsed->exts->child->next->arg, "test"); |
| 4261 | lys_module_free(mod, NULL); |
| 4262 | yin_parser_ctx_free(yin_ctx); |
| 4263 | mod = NULL; |
| 4264 | yin_ctx = NULL; |
| 4265 | |
| 4266 | mod = calloc(1, sizeof *mod); |
| 4267 | mod->ctx = st->ctx; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4268 | data = "<module name=\"example-foo\"" |
| 4269 | "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"" |
| 4270 | "xmlns:foo=\"urn:example:foo\"" |
| 4271 | "xmlns:myext=\"urn:example:extensions\">\n" |
| 4272 | |
| 4273 | "<yang-version value=\"1.0\"/>\n" |
| 4274 | |
| 4275 | "<namespace uri=\"urn:example:foo\"/>\n" |
| 4276 | "<prefix value=\"foo\"/>\n" |
| 4277 | |
| 4278 | "<import module=\"example-extensions\">\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4279 | "<prefix value=\"myext\"/>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4280 | "</import>\n" |
| 4281 | |
| 4282 | "<list name=\"interface\">\n" |
| 4283 | "<key value=\"name\"/>\n" |
| 4284 | "<leaf name=\"name\">\n" |
| 4285 | "<type name=\"string\"/>\n" |
| 4286 | "</leaf>\n" |
| 4287 | "<leaf name=\"mtu\">\n" |
| 4288 | "<type name=\"uint32\"/>\n" |
| 4289 | "<description>\n" |
| 4290 | "<text>The MTU of the interface.</text>\n" |
| 4291 | "</description>\n" |
| 4292 | "<myext:c-define name=\"MY_MTU\"/>\n" |
| 4293 | "</leaf>\n" |
| 4294 | "</list>\n" |
| 4295 | "</module>\n"; |
| 4296 | assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS); |
| 4297 | lys_module_free(mod, NULL); |
| 4298 | yin_parser_ctx_free(yin_ctx); |
| 4299 | mod = NULL; |
| 4300 | yin_ctx = NULL; |
| 4301 | |
| 4302 | mod = calloc(1, sizeof *mod); |
| 4303 | mod->ctx = st->ctx; |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4304 | data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 4305 | "<yang-version value=\"1.0\"/>\n" |
| 4306 | "<namespace uri=\"urn:example:foo\"/>\n" |
| 4307 | "<prefix value=\"foo\"/>\n" |
| 4308 | "</module>\n"; |
| 4309 | assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS); |
| 4310 | lys_module_free(mod, NULL); |
| 4311 | yin_parser_ctx_free(yin_ctx); |
| 4312 | mod = NULL; |
| 4313 | yin_ctx = NULL; |
| 4314 | |
| 4315 | |
| 4316 | mod = calloc(1, sizeof *mod); |
| 4317 | mod->ctx = st->ctx; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4318 | data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4319 | "</submodule>\n"; |
| 4320 | assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EINVAL); |
| 4321 | logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module."); |
| 4322 | lys_module_free(mod, NULL); |
| 4323 | yin_parser_ctx_free(yin_ctx); |
| 4324 | |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4325 | mod = calloc(1, sizeof *mod); |
| 4326 | mod->ctx = st->ctx; |
| 4327 | data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 4328 | "<yang-version value=\"1.0\"/>\n" |
| 4329 | "<namespace uri=\"urn:example:foo\"/>\n" |
| 4330 | "<prefix value=\"foo\"/>\n" |
| 4331 | "</module>" |
| 4332 | "<module>"; |
| 4333 | assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EVALID); |
| 4334 | logbuf_assert("Trailing garbage \"<module>\" after module, expected end-of-input. Line number 5."); |
| 4335 | lys_module_free(mod, NULL); |
| 4336 | yin_parser_ctx_free(yin_ctx); |
| 4337 | mod = NULL; |
| 4338 | yin_ctx = NULL; |
| 4339 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4340 | st->finished_correctly = true; |
| 4341 | } |
| 4342 | |
| 4343 | static void |
| 4344 | test_yin_parse_submodule(void **state) |
| 4345 | { |
| 4346 | struct state *st = *state; |
| 4347 | const char *data; |
| 4348 | struct yin_parser_ctx *yin_ctx = NULL; |
| 4349 | struct lysp_submodule *submod = NULL; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4350 | struct lys_parser_ctx main_ctx = {}; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4351 | |
| 4352 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 4353 | "<submodule name=\"asub\"" |
| 4354 | "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"" |
| 4355 | "xmlns:a=\"urn:a\">" |
| 4356 | "<yang-version value=\"1.0\"/>\n" |
| 4357 | "<belongs-to module=\"a\">" |
| 4358 | "<prefix value=\"a_pref\"/>" |
| 4359 | "</belongs-to>" |
| 4360 | "<include module=\"atop\"/>" |
| 4361 | "<feature name=\"fox\"/>" |
| 4362 | "<notification name=\"bar-notif\">" |
| 4363 | "<if-feature name=\"bar\"/>" |
| 4364 | "</notification>" |
| 4365 | "<notification name=\"fox-notif\">" |
| 4366 | "<if-feature name=\"fox\"/>" |
| 4367 | "</notification>" |
| 4368 | "<augment target-node=\"/a_pref:top\">" |
| 4369 | "<if-feature name=\"bar\"/>" |
| 4370 | "<container name=\"bar-sub\"/>" |
| 4371 | "</augment>" |
| 4372 | "<augment target-node=\"/top\">" |
| 4373 | "<container name=\"bar-sub2\"/>" |
| 4374 | "</augment>" |
| 4375 | "</submodule>"; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4376 | 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] | 4377 | lysp_submodule_free(st->ctx, submod); |
| 4378 | yin_parser_ctx_free(yin_ctx); |
| 4379 | yin_ctx = NULL; |
| 4380 | submod = NULL; |
| 4381 | |
| 4382 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4383 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4384 | "<yang-version value=\"1.0\"/>\n" |
| 4385 | "<belongs-to module=\"a\">" |
| 4386 | "<prefix value=\"a_pref\"/>" |
| 4387 | "</belongs-to>" |
| 4388 | "</submodule>"; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4389 | 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] | 4390 | lysp_submodule_free(st->ctx, submod); |
| 4391 | yin_parser_ctx_free(yin_ctx); |
| 4392 | yin_ctx = NULL; |
| 4393 | submod = NULL; |
| 4394 | |
| 4395 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4396 | "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4397 | "</module>"; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4398 | 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] | 4399 | logbuf_assert("Input data contains module in situation when a submodule is expected."); |
| 4400 | lysp_submodule_free(st->ctx, submod); |
| 4401 | yin_parser_ctx_free(yin_ctx); |
| 4402 | yin_ctx = NULL; |
| 4403 | submod = NULL; |
| 4404 | |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4405 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 4406 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4407 | "<yang-version value=\"1.0\"/>\n" |
| 4408 | "<belongs-to module=\"a\">" |
| 4409 | "<prefix value=\"a_pref\"/>" |
| 4410 | "</belongs-to>" |
| 4411 | "</submodule>" |
| 4412 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4413 | "<yang-version value=\"1.0\"/>\n" |
| 4414 | "<belongs-to module=\"a\">" |
| 4415 | "<prefix value=\"a_pref\"/>" |
| 4416 | "</belongs-to>" |
| 4417 | "</submodule>"; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4418 | 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] | 4419 | logbuf_assert("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input. Line number 2."); |
| 4420 | lysp_submodule_free(st->ctx, submod); |
| 4421 | yin_parser_ctx_free(yin_ctx); |
| 4422 | yin_ctx = NULL; |
| 4423 | submod = NULL; |
| 4424 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4425 | st->finished_correctly = true; |
| 4426 | } |
| 4427 | |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 4428 | int |
| 4429 | main(void) |
| 4430 | { |
| 4431 | |
| 4432 | const struct CMUnitTest tests[] = { |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 4433 | 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] | 4434 | cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f), |
| 4435 | 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] | 4436 | 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] | 4437 | 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] | 4438 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 4439 | cmocka_unit_test(test_yin_match_argument_name), |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 4440 | cmocka_unit_test_setup_teardown(test_enum_elem, setup_element_test, teardown_element_test), |
| 4441 | 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] | 4442 | cmocka_unit_test_setup_teardown(test_meta_elem, setup_element_test, teardown_element_test), |
| 4443 | cmocka_unit_test_setup_teardown(test_import_elem, setup_element_test, teardown_element_test), |
| 4444 | cmocka_unit_test_setup_teardown(test_status_elem, setup_element_test, teardown_element_test), |
| 4445 | cmocka_unit_test_setup_teardown(test_ext_elem, setup_element_test, teardown_element_test), |
| 4446 | cmocka_unit_test_setup_teardown(test_yin_element_elem, setup_element_test, teardown_element_test), |
| 4447 | cmocka_unit_test_setup_teardown(test_yangversion_elem, setup_element_test, teardown_element_test), |
| 4448 | 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] | 4449 | cmocka_unit_test_setup_teardown(test_argument_elem, setup_element_test, teardown_element_test), |
| 4450 | cmocka_unit_test_setup_teardown(test_base_elem, setup_element_test, teardown_element_test), |
| 4451 | cmocka_unit_test_setup_teardown(test_belongsto_elem, setup_element_test, teardown_element_test), |
| 4452 | cmocka_unit_test_setup_teardown(test_config_elem, setup_element_test, teardown_element_test), |
| 4453 | cmocka_unit_test_setup_teardown(test_default_elem, setup_element_test, teardown_element_test), |
| 4454 | cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup_element_test, teardown_element_test), |
| 4455 | cmocka_unit_test_setup_teardown(test_err_msg_elem, setup_element_test, teardown_element_test), |
| 4456 | cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup_element_test, teardown_element_test), |
| 4457 | cmocka_unit_test_setup_teardown(test_iffeature_elem, setup_element_test, teardown_element_test), |
| 4458 | cmocka_unit_test_setup_teardown(test_length_elem, setup_element_test, teardown_element_test), |
| 4459 | cmocka_unit_test_setup_teardown(test_modifier_elem, setup_element_test, teardown_element_test), |
| 4460 | cmocka_unit_test_setup_teardown(test_namespace_elem, setup_element_test, teardown_element_test), |
| 4461 | cmocka_unit_test_setup_teardown(test_path_elem, setup_element_test, teardown_element_test), |
| 4462 | cmocka_unit_test_setup_teardown(test_pattern_elem, setup_element_test, teardown_element_test), |
| 4463 | 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] | 4464 | cmocka_unit_test_setup_teardown(test_prefix_elem, setup_element_test, teardown_element_test), |
| 4465 | cmocka_unit_test_setup_teardown(test_range_elem, setup_element_test, teardown_element_test), |
| 4466 | cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup_element_test, teardown_element_test), |
| 4467 | cmocka_unit_test_setup_teardown(test_revision_date_elem, setup_element_test, teardown_element_test), |
| 4468 | cmocka_unit_test_setup_teardown(test_unique_elem, setup_element_test, teardown_element_test), |
| 4469 | cmocka_unit_test_setup_teardown(test_units_elem, setup_element_test, teardown_element_test), |
| 4470 | cmocka_unit_test_setup_teardown(test_when_elem, setup_element_test, teardown_element_test), |
| 4471 | 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] | 4472 | 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] | 4473 | 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] | 4474 | 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] | 4475 | 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] | 4476 | 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] | 4477 | 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] | 4478 | 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] | 4479 | 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] | 4480 | 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] | 4481 | 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] | 4482 | 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] | 4483 | 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] | 4484 | 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] | 4485 | 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] | 4486 | 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] | 4487 | 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] | 4488 | 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] | 4489 | 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] | 4490 | 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] | 4491 | 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] | 4492 | 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] | 4493 | 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] | 4494 | 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] | 4495 | 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] | 4496 | 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] | 4497 | 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] | 4498 | 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] | 4499 | 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] | 4500 | 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] | 4501 | |
| 4502 | cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_logger, teardown_logger), |
| 4503 | 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] | 4504 | }; |
| 4505 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 4506 | 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] | 4507 | } |