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