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