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