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