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 | 438ae43 | 2019-07-11 15:36:54 +0200 | [diff] [blame] | 516 | {YANG_RANGE, &range_type, 0}, |
| 517 | {YANG_REQUIRE_INSTANCE, &req_type, 0}, |
| 518 | {YANG_UNITS, &units, 0}, |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 519 | {YANG_POSITION, &pos_enum, 0}, |
David Sedlák | 438ae43 | 2019-07-11 15:36:54 +0200 | [diff] [blame] | 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 | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 704 | {YANG_PREFIX, dest, 0}, |
| 705 | {YANG_PRESENCE, dest, 0}, |
| 706 | {YANG_RANGE, dest, 0}, |
| 707 | {YANG_REFERENCE, dest, 0}, |
| 708 | {YANG_REFINE, dest, 0}, |
| 709 | {YANG_REQUIRE_INSTANCE, dest, 0}, |
| 710 | {YANG_REVISION, dest, 0}, |
| 711 | {YANG_REVISION_DATE, dest, 0}, |
| 712 | {YANG_RPC, dest, 0}, |
| 713 | {YANG_STATUS, dest, 0}, |
| 714 | {YANG_SUBMODULE, dest, 0}, |
| 715 | {YANG_TYPE, dest, 0}, |
| 716 | {YANG_TYPEDEF, dest, 0}, |
| 717 | {YANG_UNIQUE, dest, 0}, |
| 718 | {YANG_UNITS, dest, 0}, |
| 719 | {YANG_USES, dest, 0}, |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 720 | {YANG_POSITION, dest, 0}, |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 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 |
| 742 | test_enum_bit_elem(void **state) |
| 743 | { |
| 744 | /* yin_parse_enum_bit is function that is being mainly tested by this test */ |
| 745 | struct state *st = *state; |
| 746 | struct lysp_type type = {}; |
| 747 | const char *data; |
| 748 | data = ELEMENT_WRAPPER_START |
| 749 | "<enum name=\"enum-name\">" |
| 750 | "<if-feature name=\"feature\" />" |
| 751 | "<value value=\"55\" />" |
| 752 | "<status value=\"deprecated\" />" |
| 753 | "<description><text>desc...</text></description>" |
| 754 | "<reference><text>ref...</text></reference>" |
| 755 | "</enum>" |
| 756 | ELEMENT_WRAPPER_END; |
| 757 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 758 | assert_string_equal(*type.enums->iffeatures, "feature"); |
| 759 | assert_int_equal(type.enums->value, 55); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 760 | 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] | 761 | assert_string_equal(type.enums->dsc, "desc..."); |
| 762 | assert_string_equal(type.enums->ref, "ref..."); |
| 763 | lysp_type_free(st->ctx, &type); |
| 764 | memset(&type, 0, sizeof type); |
| 765 | |
| 766 | /* todo bit element test */ |
| 767 | st->finished_correctly = true; |
| 768 | } |
| 769 | |
| 770 | static void |
| 771 | test_meta_elem(void **state) |
| 772 | { |
| 773 | struct state *st = *state; |
| 774 | char *value = NULL; |
| 775 | const char *data; |
| 776 | |
| 777 | /* organization element */ |
| 778 | data = ELEMENT_WRAPPER_START |
| 779 | "<organization><text>organization...</text></organization>" |
| 780 | ELEMENT_WRAPPER_END; |
| 781 | assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS); |
| 782 | assert_string_equal(value, "organization..."); |
| 783 | FREE_STRING(st->ctx, value); |
| 784 | value = NULL; |
| 785 | /* contact element */ |
| 786 | data = ELEMENT_WRAPPER_START |
| 787 | "<contact><text>contact...</text></contact>" |
| 788 | ELEMENT_WRAPPER_END; |
| 789 | assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS); |
| 790 | assert_string_equal(value, "contact..."); |
| 791 | FREE_STRING(st->ctx, value); |
| 792 | value = NULL; |
| 793 | /* description element */ |
| 794 | data = ELEMENT_WRAPPER_START |
| 795 | "<description><text>description...</text></description>" |
| 796 | ELEMENT_WRAPPER_END; |
| 797 | assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS); |
| 798 | assert_string_equal(value, "description..."); |
| 799 | FREE_STRING(st->ctx, value); |
| 800 | value = NULL; |
| 801 | /* reference element */ |
| 802 | data = ELEMENT_WRAPPER_START |
| 803 | "<reference><text>reference...</text></reference>" |
| 804 | ELEMENT_WRAPPER_END; |
| 805 | assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS); |
| 806 | assert_string_equal(value, "reference..."); |
| 807 | FREE_STRING(st->ctx, value); |
| 808 | value = NULL; |
| 809 | |
| 810 | /* missing text subelement */ |
| 811 | data = ELEMENT_WRAPPER_START |
| 812 | "<reference>reference...</reference>" |
| 813 | ELEMENT_WRAPPER_END; |
| 814 | assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, false), LY_EVALID); |
| 815 | logbuf_assert("Missing mandatory subelement text of reference element. Line number 1."); |
| 816 | |
| 817 | st->finished_correctly = true; |
| 818 | } |
| 819 | |
| 820 | static void |
| 821 | test_import_elem(void **state) |
| 822 | { |
| 823 | struct state *st = *state; |
| 824 | const char *data; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 825 | struct lysp_import *imports = NULL; |
| 826 | struct import_meta imp_meta = {"prefix", &imports}; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 827 | |
| 828 | /* max subelems */ |
| 829 | data = ELEMENT_WRAPPER_START |
| 830 | "<import module=\"a\">" |
| 831 | "<prefix value=\"a_mod\"/>" |
| 832 | "<revision-date date=\"2015-01-01\"></revision-date>" |
| 833 | "<description><text>import description</text></description>" |
| 834 | "<reference><text>import reference</text></reference>" |
| 835 | "</import>" |
| 836 | ELEMENT_WRAPPER_END; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 837 | assert_int_equal(test_element_helper(st, &data, &imp_meta, NULL, NULL, true), LY_SUCCESS); |
| 838 | assert_string_equal(imports->name, "a"); |
| 839 | assert_string_equal(imports->prefix, "a_mod"); |
| 840 | assert_string_equal(imports->rev, "2015-01-01"); |
| 841 | assert_string_equal(imports->dsc, "import description"); |
| 842 | assert_string_equal(imports->ref, "import reference"); |
| 843 | FREE_ARRAY(st->ctx, imports, lysp_import_free); |
| 844 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 845 | |
| 846 | /* min subelems */ |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 847 | data = ELEMENT_WRAPPER_START |
| 848 | "<import module=\"a\">" |
| 849 | "<prefix value=\"a_mod\"/>" |
| 850 | "</import>" |
| 851 | ELEMENT_WRAPPER_END; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 852 | assert_int_equal(test_element_helper(st, &data, &imp_meta, NULL, NULL, true), LY_SUCCESS); |
| 853 | assert_string_equal(imports->prefix, "a_mod"); |
| 854 | FREE_ARRAY(st->ctx, imports, lysp_import_free); |
| 855 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 856 | |
| 857 | /* invalid (missing prefix) */ |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 858 | data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END; |
| 859 | 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] | 860 | 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] | 861 | FREE_ARRAY(st->ctx, imports, lysp_import_free); |
| 862 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 863 | |
| 864 | /* invalid reused prefix */ |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 865 | data = ELEMENT_WRAPPER_START |
| 866 | "<import module=\"a\">" |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 867 | "<prefix value=\"prefix\"/>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 868 | "</import>" |
| 869 | "<import module=\"a\">" |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 870 | "<prefix value=\"prefix\"/>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 871 | "</import>" |
| 872 | ELEMENT_WRAPPER_END; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 873 | assert_int_equal(test_element_helper(st, &data, &imp_meta, NULL, NULL, false), LY_EVALID); |
| 874 | logbuf_assert("Prefix \"prefix\" already used as module prefix. Line number 1."); |
| 875 | FREE_ARRAY(st->ctx, imports, lysp_import_free); |
| 876 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 877 | |
| 878 | st->finished_correctly = true; |
| 879 | } |
| 880 | |
| 881 | static void |
| 882 | test_status_elem(void **state) |
| 883 | { |
| 884 | struct state *st = *state; |
| 885 | const char *data; |
| 886 | uint16_t flags = 0; |
| 887 | |
| 888 | /* test valid values */ |
| 889 | data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END; |
| 890 | 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] | 891 | assert_true(flags & LYS_STATUS_CURR); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 892 | |
| 893 | data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END; |
| 894 | 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] | 895 | assert_true(flags & LYS_STATUS_DEPRC); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 896 | |
| 897 | data = ELEMENT_WRAPPER_START "<status value=\"obsolete\"></status>" ELEMENT_WRAPPER_END; |
| 898 | 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] | 899 | assert_true(flags & LYS_STATUS_OBSLT); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 900 | |
| 901 | /* test invalid value */ |
| 902 | data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END; |
| 903 | assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID); |
| 904 | logbuf_assert("Invalid value \"invalid\" of \"status\". Line number 1."); |
| 905 | st->finished_correctly = true; |
| 906 | } |
| 907 | |
| 908 | static void |
| 909 | test_ext_elem(void **state) |
| 910 | { |
| 911 | struct state *st = *state; |
| 912 | const char *data; |
| 913 | struct lysp_ext *ext = NULL; |
| 914 | |
| 915 | /* max subelems */ |
| 916 | data = ELEMENT_WRAPPER_START |
| 917 | "<extension name=\"ext_name\">" |
| 918 | "<argument name=\"arg\"></argument>" |
| 919 | "<status value=\"current\"/>" |
| 920 | "<description><text>ext_desc</text></description>" |
| 921 | "<reference><text>ext_ref</text></reference>" |
| 922 | "</extension>" |
| 923 | ELEMENT_WRAPPER_END; |
| 924 | assert_int_equal(test_element_helper(st, &data, &ext, NULL, NULL, true), LY_SUCCESS); |
| 925 | assert_string_equal(ext->name, "ext_name"); |
| 926 | assert_string_equal(ext->argument, "arg"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 927 | assert_true(ext->flags & LYS_STATUS_CURR); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 928 | assert_string_equal(ext->dsc, "ext_desc"); |
| 929 | assert_string_equal(ext->ref, "ext_ref"); |
| 930 | lysp_ext_free(st->ctx, ext); |
| 931 | LY_ARRAY_FREE(ext); |
| 932 | ext = NULL; |
| 933 | |
| 934 | /* min subelems */ |
| 935 | data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END; |
| 936 | assert_int_equal(test_element_helper(st, &data, &ext, NULL, NULL, true), LY_SUCCESS); |
| 937 | assert_string_equal(ext->name, "ext_name"); |
| 938 | lysp_ext_free(st->ctx, ext); |
| 939 | LY_ARRAY_FREE(ext); |
| 940 | ext = NULL; |
| 941 | |
| 942 | st->finished_correctly = true; |
| 943 | } |
| 944 | |
| 945 | static void |
| 946 | test_yin_element_elem(void **state) |
| 947 | { |
| 948 | struct state *st = *state; |
| 949 | const char *data; |
| 950 | uint16_t flags = 0; |
| 951 | |
| 952 | data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END; |
| 953 | 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] | 954 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 955 | |
| 956 | data = ELEMENT_WRAPPER_START "<yin-element value=\"false\" />" ELEMENT_WRAPPER_END; |
| 957 | 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] | 958 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 959 | |
| 960 | data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END; |
| 961 | 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] | 962 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 963 | logbuf_assert("Invalid value \"invalid\" of \"yin-element\". Line number 1."); |
| 964 | st->finished_correctly = true; |
| 965 | } |
| 966 | |
| 967 | static void |
| 968 | test_yangversion_elem(void **state) |
| 969 | { |
| 970 | struct state *st = *state; |
| 971 | const char *data; |
| 972 | uint8_t version = 0; |
| 973 | |
| 974 | /* valid values */ |
| 975 | data = ELEMENT_WRAPPER_START "<yang-version value=\"1.0\" />" ELEMENT_WRAPPER_END; |
| 976 | 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] | 977 | assert_true(version & LYS_VERSION_1_0); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 978 | assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_0); |
| 979 | |
| 980 | data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\" />" ELEMENT_WRAPPER_END; |
| 981 | 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] | 982 | assert_true(version & LYS_VERSION_1_1); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 983 | assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_1); |
| 984 | |
| 985 | /* invalid value */ |
| 986 | data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END; |
| 987 | assert_int_equal(test_element_helper(st, &data, &version, NULL, NULL, false), LY_EVALID); |
| 988 | logbuf_assert("Invalid value \"version\" of \"yang-version\". Line number 1."); |
| 989 | |
| 990 | st->finished_correctly = true; |
| 991 | } |
| 992 | |
| 993 | static void |
| 994 | test_mandatory_elem(void **state) |
| 995 | { |
| 996 | struct state *st = *state; |
| 997 | const char *data; |
| 998 | uint16_t man = 0; |
| 999 | |
| 1000 | /* valid values */ |
| 1001 | data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END; |
| 1002 | assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, true), LY_SUCCESS); |
| 1003 | assert_int_equal(man, LYS_MAND_TRUE); |
| 1004 | man = 0; |
| 1005 | |
| 1006 | data = ELEMENT_WRAPPER_START "<mandatory value=\"false\" />" ELEMENT_WRAPPER_END; |
| 1007 | assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, true), LY_SUCCESS); |
| 1008 | assert_int_equal(man, LYS_MAND_FALSE); |
| 1009 | |
| 1010 | data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END; |
| 1011 | assert_int_equal(test_element_helper(st, &data, &man, NULL, NULL, false), LY_EVALID); |
| 1012 | logbuf_assert("Invalid value \"invalid\" of \"mandatory\". Line number 1."); |
| 1013 | |
| 1014 | st->finished_correctly = true; |
| 1015 | } |
| 1016 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1017 | static void |
| 1018 | test_argument_elem(void **state) |
| 1019 | { |
| 1020 | struct state *st = *state; |
| 1021 | const char *data; |
| 1022 | uint16_t flags = 0; |
| 1023 | const char *arg; |
| 1024 | struct yin_argument_meta arg_meta = {&flags, &arg}; |
| 1025 | /* max subelems */ |
| 1026 | data = ELEMENT_WRAPPER_START |
| 1027 | "<argument name=\"arg-name\">" |
| 1028 | "<yin-element value=\"true\" />" |
| 1029 | "</argument>" |
| 1030 | ELEMENT_WRAPPER_END; |
| 1031 | assert_int_equal(test_element_helper(st, &data, &arg_meta, NULL, NULL, true), LY_SUCCESS); |
| 1032 | assert_string_equal(arg, "arg-name"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1033 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1034 | flags = 0; |
| 1035 | FREE_STRING(st->ctx, arg); |
| 1036 | arg = NULL; |
| 1037 | |
| 1038 | /* min subelems */ |
| 1039 | data = ELEMENT_WRAPPER_START |
| 1040 | "<argument name=\"arg\">" |
| 1041 | "</argument>" |
| 1042 | ELEMENT_WRAPPER_END; |
| 1043 | assert_int_equal(test_element_helper(st, &data, &arg_meta, NULL, NULL, true), LY_SUCCESS); |
| 1044 | assert_string_equal(arg, "arg"); |
| 1045 | assert_true(flags == 0); |
| 1046 | FREE_STRING(st->ctx, arg); |
| 1047 | |
| 1048 | st->finished_correctly = true; |
| 1049 | } |
| 1050 | |
| 1051 | static void |
| 1052 | test_base_elem(void **state) |
| 1053 | { |
| 1054 | struct state *st = *state; |
| 1055 | const char *data; |
| 1056 | const char **bases = NULL; |
| 1057 | struct lysp_type type = {}; |
| 1058 | |
| 1059 | /* as identity subelement */ |
| 1060 | data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 1061 | "<base name=\"base-name\"/>" |
| 1062 | "</identity>"; |
| 1063 | assert_int_equal(test_element_helper(st, &data, &bases, NULL, NULL, true), LY_SUCCESS); |
| 1064 | assert_string_equal(*bases, "base-name"); |
| 1065 | FREE_STRING(st->ctx, *bases); |
| 1066 | LY_ARRAY_FREE(bases); |
| 1067 | |
| 1068 | /* as type subelement */ |
| 1069 | data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 1070 | "<base name=\"base-name\"/>" |
| 1071 | "</type>"; |
| 1072 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1073 | assert_string_equal(*type.bases, "base-name"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1074 | assert_true(type.flags & LYS_SET_BASE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1075 | FREE_STRING(st->ctx, *type.bases); |
| 1076 | LY_ARRAY_FREE(type.bases); |
| 1077 | |
| 1078 | st->finished_correctly = true; |
| 1079 | } |
| 1080 | |
| 1081 | static void |
| 1082 | test_belongsto_elem(void **state) |
| 1083 | { |
| 1084 | struct state *st = *state; |
| 1085 | const char *data; |
| 1086 | struct lysp_submodule submod; |
| 1087 | |
| 1088 | data = ELEMENT_WRAPPER_START |
| 1089 | "<belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>" |
| 1090 | ELEMENT_WRAPPER_END; |
| 1091 | assert_int_equal(test_element_helper(st, &data, &submod, NULL, NULL, true), LY_SUCCESS); |
| 1092 | assert_string_equal(submod.belongsto, "module-name"); |
| 1093 | assert_string_equal(submod.prefix, "pref"); |
| 1094 | FREE_STRING(st->ctx, submod.belongsto); |
| 1095 | FREE_STRING(st->ctx, submod.prefix); |
| 1096 | |
| 1097 | data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END; |
| 1098 | assert_int_equal(test_element_helper(st, &data, &submod, NULL, NULL, false), LY_EVALID); |
| 1099 | logbuf_assert("Missing mandatory subelement prefix of belongs-to element. Line number 1."); |
| 1100 | FREE_STRING(st->ctx, submod.belongsto); |
| 1101 | |
| 1102 | st->finished_correctly = true; |
| 1103 | } |
| 1104 | |
| 1105 | static void |
| 1106 | test_config_elem(void **state) |
| 1107 | { |
| 1108 | struct state *st = *state; |
| 1109 | const char *data; |
| 1110 | uint16_t flags = 0; |
| 1111 | |
| 1112 | data = ELEMENT_WRAPPER_START "<config value=\"true\"/>" ELEMENT_WRAPPER_END; |
| 1113 | 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] | 1114 | assert_true(flags & LYS_CONFIG_W); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1115 | flags = 0; |
| 1116 | |
| 1117 | data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END; |
| 1118 | 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] | 1119 | assert_true(flags & LYS_CONFIG_R); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1120 | flags = 0; |
| 1121 | |
| 1122 | data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END; |
| 1123 | assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID); |
| 1124 | logbuf_assert("Invalid value \"invalid\" of \"config\". Line number 1."); |
| 1125 | |
| 1126 | st->finished_correctly = true; |
| 1127 | } |
| 1128 | |
| 1129 | static void |
| 1130 | test_default_elem(void **state) |
| 1131 | { |
| 1132 | struct state *st = *state; |
| 1133 | const char *data; |
| 1134 | const char *val = NULL; |
| 1135 | |
| 1136 | data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\"/>" ELEMENT_WRAPPER_END; |
| 1137 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS); |
| 1138 | assert_string_equal(val, "defaul-value"); |
| 1139 | FREE_STRING(st->ctx, val); |
| 1140 | val = NULL; |
| 1141 | |
| 1142 | data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END; |
| 1143 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID); |
| 1144 | logbuf_assert("Missing mandatory attribute value of default element. Line number 1."); |
| 1145 | |
| 1146 | st->finished_correctly = true; |
| 1147 | } |
| 1148 | |
| 1149 | static void |
| 1150 | test_err_app_tag_elem(void **state) |
| 1151 | { |
| 1152 | struct state *st = *state; |
| 1153 | const char *data; |
| 1154 | const char *val = NULL; |
| 1155 | |
| 1156 | data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\"/>" ELEMENT_WRAPPER_END; |
| 1157 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS); |
| 1158 | assert_string_equal(val, "val"); |
| 1159 | FREE_STRING(st->ctx, val); |
| 1160 | val = NULL; |
| 1161 | |
| 1162 | data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END; |
| 1163 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID); |
| 1164 | logbuf_assert("Missing mandatory attribute value of error-app-tag element. Line number 1."); |
| 1165 | |
| 1166 | st->finished_correctly = true; |
| 1167 | } |
| 1168 | |
| 1169 | static void |
| 1170 | test_err_msg_elem(void **state) |
| 1171 | { |
| 1172 | struct state *st = *state; |
| 1173 | const char *data; |
| 1174 | const char *val = NULL; |
| 1175 | |
| 1176 | data = ELEMENT_WRAPPER_START "<error-message><value>val</value></error-message>" ELEMENT_WRAPPER_END; |
| 1177 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS); |
| 1178 | assert_string_equal(val, "val"); |
| 1179 | FREE_STRING(st->ctx, val); |
| 1180 | |
| 1181 | data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END; |
| 1182 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID); |
| 1183 | logbuf_assert("Missing mandatory subelement value of error-message element. Line number 1."); |
| 1184 | |
| 1185 | st->finished_correctly = true; |
| 1186 | } |
| 1187 | |
| 1188 | static void |
| 1189 | test_fracdigits_elem(void **state) |
| 1190 | { |
| 1191 | struct state *st = *state; |
| 1192 | const char *data; |
| 1193 | struct lysp_type type = {}; |
| 1194 | |
| 1195 | /* valid value */ |
| 1196 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\"></fraction-digits>" ELEMENT_WRAPPER_END; |
| 1197 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1198 | assert_int_equal(type.fraction_digits, 10); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1199 | assert_true(type.flags & LYS_SET_FRDIGITS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1200 | |
| 1201 | /* invalid values */ |
| 1202 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END; |
| 1203 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID); |
| 1204 | logbuf_assert("Invalid value \"-1\" of \"fraction-digits\". Line number 1."); |
| 1205 | |
| 1206 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END; |
| 1207 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID); |
| 1208 | logbuf_assert("Invalid value \"02\" of \"fraction-digits\". Line number 1."); |
| 1209 | |
| 1210 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END; |
| 1211 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID); |
| 1212 | logbuf_assert("Invalid value \"1p\" of \"fraction-digits\". Line number 1."); |
| 1213 | |
| 1214 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END; |
| 1215 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID); |
| 1216 | logbuf_assert("Invalid value \"19\" of \"fraction-digits\". Line number 1."); |
| 1217 | |
| 1218 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END; |
| 1219 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID); |
| 1220 | logbuf_assert("Invalid value \"999999999999999999\" of \"fraction-digits\". Line number 1."); |
| 1221 | |
| 1222 | st->finished_correctly = true; |
| 1223 | } |
| 1224 | |
| 1225 | static void |
| 1226 | test_iffeature_elem(void **state) |
| 1227 | { |
| 1228 | struct state *st = *state; |
| 1229 | const char *data; |
| 1230 | const char **iffeatures = NULL; |
| 1231 | |
| 1232 | data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\"></if-feature>" ELEMENT_WRAPPER_END; |
| 1233 | assert_int_equal(test_element_helper(st, &data, &iffeatures, NULL, NULL, true), LY_SUCCESS); |
| 1234 | assert_string_equal(*iffeatures, "local-storage"); |
| 1235 | FREE_STRING(st->ctx, *iffeatures); |
| 1236 | LY_ARRAY_FREE(iffeatures); |
| 1237 | iffeatures = NULL; |
| 1238 | |
| 1239 | data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END; |
| 1240 | assert_int_equal(test_element_helper(st, &data, &iffeatures, NULL, NULL, false), LY_EVALID); |
| 1241 | logbuf_assert("Missing mandatory attribute name of if-feature element. Line number 1."); |
| 1242 | LY_ARRAY_FREE(iffeatures); |
| 1243 | iffeatures = NULL; |
| 1244 | |
| 1245 | st->finished_correctly = true; |
| 1246 | } |
| 1247 | |
| 1248 | static void |
| 1249 | test_length_elem(void **state) |
| 1250 | { |
| 1251 | struct state *st = *state; |
| 1252 | const char *data; |
| 1253 | struct lysp_type type = {}; |
| 1254 | |
| 1255 | /* max subelems */ |
| 1256 | data = ELEMENT_WRAPPER_START |
| 1257 | "<length value=\"length-str\">" |
| 1258 | "<error-message><value>err-msg</value></error-message>" |
| 1259 | "<error-app-tag value=\"err-app-tag\"/>" |
| 1260 | "<description><text>desc</text></description>" |
| 1261 | "<reference><text>ref</text></reference>" |
| 1262 | "</length>" |
| 1263 | ELEMENT_WRAPPER_END; |
| 1264 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1265 | assert_string_equal(type.length->arg, "length-str"); |
| 1266 | assert_string_equal(type.length->emsg, "err-msg"); |
| 1267 | assert_string_equal(type.length->eapptag, "err-app-tag"); |
| 1268 | assert_string_equal(type.length->dsc, "desc"); |
| 1269 | assert_string_equal(type.length->ref, "ref"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1270 | assert_true(type.flags & LYS_SET_LENGTH); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1271 | lysp_type_free(st->ctx, &type); |
| 1272 | memset(&type, 0, sizeof(type)); |
| 1273 | |
| 1274 | /* min subelems */ |
| 1275 | data = ELEMENT_WRAPPER_START |
| 1276 | "<length value=\"length-str\">" |
| 1277 | "</length>" |
| 1278 | ELEMENT_WRAPPER_END; |
| 1279 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1280 | assert_string_equal(type.length->arg, "length-str"); |
| 1281 | lysp_type_free(st->ctx, &type); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1282 | assert_true(type.flags & LYS_SET_LENGTH); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1283 | memset(&type, 0, sizeof(type)); |
| 1284 | |
| 1285 | data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END; |
| 1286 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID); |
| 1287 | logbuf_assert("Missing mandatory attribute value of length element. Line number 1."); |
| 1288 | lysp_type_free(st->ctx, &type); |
| 1289 | memset(&type, 0, sizeof(type)); |
| 1290 | |
| 1291 | st->finished_correctly = true; |
| 1292 | } |
| 1293 | |
| 1294 | static void |
| 1295 | test_modifier_elem(void **state) |
| 1296 | { |
| 1297 | struct state *st = *state; |
| 1298 | const char *data; |
| 1299 | const char *pat = lydict_insert(st->ctx, "\006pattern", 8); |
| 1300 | |
| 1301 | data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\" />" ELEMENT_WRAPPER_END; |
| 1302 | assert_int_equal(test_element_helper(st, &data, &pat, NULL, NULL, true), LY_SUCCESS); |
| 1303 | assert_string_equal(pat, "\x015pattern"); |
| 1304 | FREE_STRING(st->ctx, pat); |
| 1305 | |
| 1306 | pat = lydict_insert(st->ctx, "\006pattern", 8); |
| 1307 | data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END; |
| 1308 | assert_int_equal(test_element_helper(st, &data, &pat, NULL, NULL, false), LY_EVALID); |
| 1309 | logbuf_assert("Invalid value \"invert\" of \"modifier\". Line number 1."); |
| 1310 | FREE_STRING(st->ctx, pat); |
| 1311 | |
| 1312 | st->finished_correctly = true; |
| 1313 | } |
| 1314 | |
| 1315 | static void |
| 1316 | test_namespace_elem(void **state) |
| 1317 | { |
| 1318 | struct state *st = *state; |
| 1319 | const char *data; |
| 1320 | const char *ns; |
| 1321 | |
| 1322 | data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\"/>" ELEMENT_WRAPPER_END; |
| 1323 | assert_int_equal(test_element_helper(st, &data, &ns, NULL, NULL, true), LY_SUCCESS); |
| 1324 | assert_string_equal(ns, "ns"); |
| 1325 | FREE_STRING(st->ctx, ns); |
| 1326 | |
| 1327 | data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END; |
| 1328 | assert_int_equal(test_element_helper(st, &data, &ns, NULL, NULL, false), LY_EVALID); |
| 1329 | logbuf_assert("Missing mandatory attribute uri of namespace element. Line number 1."); |
| 1330 | |
| 1331 | st->finished_correctly = true; |
| 1332 | } |
| 1333 | |
| 1334 | static void |
| 1335 | test_path_elem(void **state) |
| 1336 | { |
| 1337 | struct state *st = *state; |
| 1338 | const char *data; |
| 1339 | struct lysp_type type = {}; |
| 1340 | |
| 1341 | data = ELEMENT_WRAPPER_START "<path value=\"path-val\"/>" ELEMENT_WRAPPER_END; |
| 1342 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1343 | assert_string_equal("path-val", type.path); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1344 | assert_true(type.flags & LYS_SET_PATH); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1345 | lysp_type_free(st->ctx, &type); |
| 1346 | |
| 1347 | st->finished_correctly = true; |
| 1348 | } |
| 1349 | |
| 1350 | static void |
| 1351 | test_pattern_elem(void **state) |
| 1352 | { |
| 1353 | struct state *st = *state; |
| 1354 | const char *data; |
| 1355 | struct lysp_type type = {}; |
| 1356 | |
| 1357 | /* max subelems */ |
| 1358 | data = ELEMENT_WRAPPER_START |
| 1359 | "<pattern value=\"super_pattern\">" |
| 1360 | "<modifier value=\"invert-match\"/>" |
| 1361 | "<error-message><value>err-msg-value</value></error-message>" |
| 1362 | "<error-app-tag value=\"err-app-tag-value\"/>" |
| 1363 | "<description><text>pattern-desc</text></description>" |
| 1364 | "<reference><text>pattern-ref</text></reference>" |
| 1365 | "</pattern>" |
| 1366 | ELEMENT_WRAPPER_END; |
| 1367 | 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] | 1368 | assert_true(type.flags & LYS_SET_PATTERN); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1369 | assert_string_equal(type.patterns->arg, "\x015super_pattern"); |
| 1370 | assert_string_equal(type.patterns->dsc, "pattern-desc"); |
| 1371 | assert_string_equal(type.patterns->eapptag, "err-app-tag-value"); |
| 1372 | assert_string_equal(type.patterns->emsg, "err-msg-value"); |
| 1373 | assert_string_equal(type.patterns->dsc, "pattern-desc"); |
| 1374 | assert_string_equal(type.patterns->ref, "pattern-ref"); |
| 1375 | lysp_type_free(st->ctx, &type); |
| 1376 | memset(&type, 0, sizeof(type)); |
| 1377 | |
| 1378 | /* min subelems */ |
| 1379 | data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END; |
| 1380 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1381 | assert_string_equal(type.patterns->arg, "\x006pattern"); |
| 1382 | lysp_type_free(st->ctx, &type); |
| 1383 | memset(&type, 0, sizeof(type)); |
| 1384 | |
| 1385 | st->finished_correctly = true; |
| 1386 | } |
| 1387 | |
| 1388 | static void |
| 1389 | test_value_position_elem(void **state) |
| 1390 | { |
| 1391 | struct state *st = *state; |
| 1392 | const char *data; |
| 1393 | struct lysp_type_enum en = {}; |
| 1394 | |
| 1395 | /* valid values */ |
| 1396 | data = ELEMENT_WRAPPER_START "<value value=\"55\" />" ELEMENT_WRAPPER_END; |
| 1397 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS); |
| 1398 | assert_int_equal(en.value, 55); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1399 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1400 | memset(&en, 0, sizeof(en)); |
| 1401 | |
| 1402 | data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END; |
| 1403 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS); |
| 1404 | assert_int_equal(en.value, -55); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1405 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1406 | memset(&en, 0, sizeof(en)); |
| 1407 | |
| 1408 | data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END; |
| 1409 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS); |
| 1410 | assert_int_equal(en.value, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1411 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1412 | memset(&en, 0, sizeof(en)); |
| 1413 | |
| 1414 | data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END; |
| 1415 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS); |
| 1416 | assert_int_equal(en.value, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1417 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1418 | memset(&en, 0, sizeof(en)); |
| 1419 | |
| 1420 | /* valid positions */ |
| 1421 | data = ELEMENT_WRAPPER_START "<position 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 "<position value=\"0\" />" ELEMENT_WRAPPER_END; |
| 1428 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, true), LY_SUCCESS); |
| 1429 | assert_int_equal(en.value, 0); |
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 | /* invalid values */ |
| 1434 | data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END; |
| 1435 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID); |
| 1436 | logbuf_assert("Invalid value \"99999999999999999999999\" of \"value\". Line number 1."); |
| 1437 | |
| 1438 | data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END; |
| 1439 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID); |
| 1440 | logbuf_assert("Invalid value \"1k\" of \"value\". Line number 1."); |
| 1441 | |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1442 | data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END; |
| 1443 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID); |
| 1444 | logbuf_assert("Invalid value \"\" of \"value\". Line number 1."); |
| 1445 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1446 | /*invalid positions */ |
| 1447 | data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END; |
| 1448 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID); |
| 1449 | logbuf_assert("Invalid value \"-5\" of \"position\". Line number 1."); |
| 1450 | |
| 1451 | data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END; |
| 1452 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID); |
| 1453 | logbuf_assert("Invalid value \"-0\" of \"position\". Line number 1."); |
| 1454 | |
| 1455 | data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END; |
| 1456 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID); |
| 1457 | logbuf_assert("Invalid value \"99999999999999999999\" of \"position\". Line number 1."); |
| 1458 | |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1459 | data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END; |
| 1460 | assert_int_equal(test_element_helper(st, &data, &en, NULL, NULL, false), LY_EVALID); |
| 1461 | logbuf_assert("Invalid value \"\" of \"position\". Line number 1."); |
| 1462 | |
| 1463 | st->finished_correctly = true; |
| 1464 | } |
| 1465 | |
| 1466 | static void |
| 1467 | test_prefix_elem(void **state) |
| 1468 | { |
| 1469 | struct state *st = *state; |
| 1470 | const char *data; |
| 1471 | const char *value = NULL; |
| 1472 | |
| 1473 | data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END; |
| 1474 | assert_int_equal(test_element_helper(st, &data, &value, NULL, NULL, true), LY_SUCCESS); |
| 1475 | assert_string_equal(value, "pref"); |
| 1476 | FREE_STRING(st->ctx, value); |
| 1477 | |
| 1478 | st->finished_correctly = true; |
| 1479 | } |
| 1480 | |
| 1481 | static void |
| 1482 | test_range_elem(void **state) |
| 1483 | { |
| 1484 | struct state *st = *state; |
| 1485 | const char *data; |
| 1486 | struct lysp_type type = {}; |
| 1487 | |
| 1488 | /* max subelems */ |
| 1489 | data = ELEMENT_WRAPPER_START |
| 1490 | "<range value=\"range-str\">" |
| 1491 | "<error-message><value>err-msg</value></error-message>" |
| 1492 | "<error-app-tag value=\"err-app-tag\" />" |
| 1493 | "<description><text>desc</text></description>" |
| 1494 | "<reference><text>ref</text></reference>" |
| 1495 | "</range>" |
| 1496 | ELEMENT_WRAPPER_END; |
| 1497 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1498 | assert_string_equal(type.range->arg, "range-str"); |
| 1499 | assert_string_equal(type.range->dsc, "desc"); |
| 1500 | assert_string_equal(type.range->eapptag, "err-app-tag"); |
| 1501 | assert_string_equal(type.range->emsg, "err-msg"); |
| 1502 | assert_string_equal(type.range->ref, "ref"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1503 | assert_true(type.flags & LYS_SET_RANGE); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1504 | lysp_type_free(st->ctx, &type); |
| 1505 | memset(&type, 0, sizeof(type)); |
| 1506 | |
| 1507 | /* min subelems */ |
| 1508 | data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END; |
| 1509 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1510 | assert_string_equal(type.range->arg, "range-str"); |
| 1511 | lysp_type_free(st->ctx, &type); |
| 1512 | memset(&type, 0, sizeof(type)); |
| 1513 | |
| 1514 | st->finished_correctly = true; |
| 1515 | } |
| 1516 | |
| 1517 | static void |
| 1518 | test_reqinstance_elem(void **state) |
| 1519 | { |
| 1520 | struct state *st = *state; |
| 1521 | const char *data; |
| 1522 | struct lysp_type type = {}; |
| 1523 | |
| 1524 | data = ELEMENT_WRAPPER_START "<require-instance value=\"true\"/>" ELEMENT_WRAPPER_END; |
| 1525 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1526 | assert_int_equal(type.require_instance, 1); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1527 | assert_true(type.flags & LYS_SET_REQINST); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1528 | memset(&type, 0, sizeof(type)); |
| 1529 | |
| 1530 | data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END; |
| 1531 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1532 | assert_int_equal(type.require_instance, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1533 | assert_true(type.flags & LYS_SET_REQINST); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1534 | memset(&type, 0, sizeof(type)); |
| 1535 | |
| 1536 | data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END; |
| 1537 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, false), LY_EVALID); |
| 1538 | memset(&type, 0, sizeof(type)); |
| 1539 | logbuf_assert("Invalid value \"invalid\" of \"require-instance\". Line number 1."); |
| 1540 | |
| 1541 | st->finished_correctly = true; |
| 1542 | } |
| 1543 | |
| 1544 | static void |
| 1545 | test_revision_date_elem(void **state) |
| 1546 | { |
| 1547 | struct state *st = *state; |
| 1548 | const char *data; |
| 1549 | char rev[LY_REV_SIZE]; |
| 1550 | |
| 1551 | data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END; |
| 1552 | assert_int_equal(test_element_helper(st, &data, rev, NULL, NULL, true), LY_SUCCESS); |
| 1553 | assert_string_equal(rev, "2000-01-01"); |
| 1554 | |
| 1555 | data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END; |
| 1556 | assert_int_equal(test_element_helper(st, &data, rev, NULL, NULL, false), LY_EVALID); |
| 1557 | logbuf_assert("Invalid value \"2000-50-05\" of \"revision-date\". Line number 1."); |
| 1558 | |
| 1559 | st->finished_correctly = true; |
| 1560 | } |
| 1561 | |
| 1562 | static void |
| 1563 | test_unique_elem(void **state) |
| 1564 | { |
| 1565 | struct state *st = *state; |
| 1566 | const char *data; |
| 1567 | const char **values = NULL; |
| 1568 | |
| 1569 | data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END; |
| 1570 | assert_int_equal(test_element_helper(st, &data, &values, NULL, NULL, true), LY_SUCCESS); |
| 1571 | assert_string_equal(*values, "tag"); |
| 1572 | FREE_STRING(st->ctx, *values); |
| 1573 | LY_ARRAY_FREE(values); |
| 1574 | |
| 1575 | st->finished_correctly = true; |
| 1576 | } |
| 1577 | |
| 1578 | static void |
| 1579 | test_units_elem(void **state) |
| 1580 | { |
| 1581 | struct state *st = *state; |
| 1582 | const char *data; |
| 1583 | const char *values = NULL; |
| 1584 | |
| 1585 | data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END; |
| 1586 | assert_int_equal(test_element_helper(st, &data, &values, NULL, NULL, true), LY_SUCCESS); |
| 1587 | assert_string_equal(values, "name"); |
| 1588 | FREE_STRING(st->ctx, values); |
| 1589 | |
| 1590 | st->finished_correctly = true; |
| 1591 | } |
| 1592 | |
| 1593 | static void |
| 1594 | test_when_elem(void **state) |
| 1595 | { |
| 1596 | struct state *st = *state; |
| 1597 | const char *data; |
| 1598 | struct lysp_when *when = NULL; |
| 1599 | |
| 1600 | data = ELEMENT_WRAPPER_START |
| 1601 | "<when condition=\"cond\">" |
| 1602 | "<description><text>desc</text></description>" |
| 1603 | "<reference><text>ref</text></reference>" |
| 1604 | "</when>" |
| 1605 | ELEMENT_WRAPPER_END; |
| 1606 | assert_int_equal(test_element_helper(st, &data, &when, NULL, NULL, true), LY_SUCCESS); |
| 1607 | assert_string_equal(when->cond, "cond"); |
| 1608 | assert_string_equal(when->dsc, "desc"); |
| 1609 | assert_string_equal(when->ref, "ref"); |
| 1610 | lysp_when_free(st->ctx, when); |
| 1611 | free(when); |
| 1612 | when = NULL; |
| 1613 | |
| 1614 | data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END; |
| 1615 | assert_int_equal(test_element_helper(st, &data, &when, NULL, NULL, true), LY_SUCCESS); |
| 1616 | assert_string_equal(when->cond, "cond"); |
| 1617 | lysp_when_free(st->ctx, when); |
| 1618 | free(when); |
| 1619 | when = NULL; |
| 1620 | |
| 1621 | st->finished_correctly = true; |
| 1622 | } |
| 1623 | |
| 1624 | static void |
| 1625 | test_yin_text_value_elem(void **state) |
| 1626 | { |
| 1627 | struct state *st = *state; |
| 1628 | const char *data; |
| 1629 | const char *val; |
| 1630 | |
| 1631 | data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END; |
| 1632 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS); |
| 1633 | assert_string_equal(val, "text"); |
| 1634 | FREE_STRING(st->ctx, val); |
| 1635 | |
| 1636 | data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>"; |
| 1637 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS); |
| 1638 | assert_string_equal(val, "text"); |
| 1639 | FREE_STRING(st->ctx, val); |
| 1640 | |
| 1641 | data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END; |
| 1642 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS); |
| 1643 | assert_string_equal("", val); |
| 1644 | FREE_STRING(st->ctx, val); |
| 1645 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1646 | st->finished_correctly = true; |
| 1647 | } |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1648 | |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1649 | static void |
| 1650 | test_type_elem(void **state) |
| 1651 | { |
| 1652 | struct state *st = *state; |
| 1653 | const char *data; |
| 1654 | struct lysp_type type = {}; |
| 1655 | |
| 1656 | /* max subelems */ |
| 1657 | data = ELEMENT_WRAPPER_START |
| 1658 | "<type name=\"type-name\">" |
| 1659 | "<base name=\"base-name\"/>" |
| 1660 | "<bit name=\"bit\"/>" |
| 1661 | "<enum name=\"enum\"/>" |
| 1662 | "<fraction-digits value=\"2\"/>" |
| 1663 | "<length value=\"length\"/>" |
| 1664 | "<path value=\"path\"/>" |
| 1665 | "<pattern value=\"pattern\"/>" |
| 1666 | "<range value=\"range\" />" |
| 1667 | "<require-instance value=\"true\"/>" |
| 1668 | "<type name=\"sub-type-name\"/>" |
| 1669 | "</type>" |
| 1670 | ELEMENT_WRAPPER_END; |
| 1671 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1672 | assert_string_equal(type.name, "type-name"); |
| 1673 | assert_string_equal(*type.bases, "base-name"); |
| 1674 | assert_string_equal(type.bits->name, "bit"); |
| 1675 | assert_string_equal(type.enums->name, "enum"); |
| 1676 | assert_int_equal(type.fraction_digits, 2); |
| 1677 | assert_string_equal(type.length->arg, "length"); |
| 1678 | assert_string_equal(type.path, "path"); |
| 1679 | assert_string_equal(type.patterns->arg, "\006pattern"); |
| 1680 | assert_string_equal(type.range->arg, "range"); |
| 1681 | assert_int_equal(type.require_instance, 1); |
| 1682 | assert_string_equal(type.types->name, "sub-type-name"); |
| 1683 | lysp_type_free(st->ctx, &type); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1684 | assert_true(type.flags & LYS_SET_BASE); |
| 1685 | assert_true(type.flags & LYS_SET_BIT); |
| 1686 | assert_true(type.flags & LYS_SET_ENUM); |
| 1687 | assert_true(type.flags & LYS_SET_FRDIGITS); |
| 1688 | assert_true(type.flags & LYS_SET_LENGTH); |
| 1689 | assert_true(type.flags & LYS_SET_PATH); |
| 1690 | assert_true(type.flags & LYS_SET_PATTERN); |
| 1691 | assert_true(type.flags & LYS_SET_RANGE); |
| 1692 | assert_true(type.flags & LYS_SET_REQINST); |
| 1693 | assert_true(type.flags & LYS_SET_TYPE); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1694 | memset(&type, 0, sizeof(type)); |
| 1695 | |
| 1696 | /* min subelems */ |
| 1697 | data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END; |
| 1698 | assert_int_equal(test_element_helper(st, &data, &type, NULL, NULL, true), LY_SUCCESS); |
| 1699 | lysp_type_free(st->ctx, &type); |
| 1700 | memset(&type, 0, sizeof(type)); |
| 1701 | |
| 1702 | st->finished_correctly = true; |
| 1703 | } |
| 1704 | |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1705 | static void |
| 1706 | test_max_elems_elem(void **state) |
| 1707 | { |
| 1708 | struct state *st = *state; |
| 1709 | const char *data; |
| 1710 | struct lysp_node_list list = {}; |
| 1711 | struct lysp_node_leaflist llist = {}; |
| 1712 | struct lysp_refine refine = {}; |
| 1713 | |
| 1714 | data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"unbounded\"/> </refine>"; |
| 1715 | assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS); |
| 1716 | assert_int_equal(refine.max, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1717 | assert_true(refine.flags & LYS_SET_MAX); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1718 | |
| 1719 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"5\"/> </list>"; |
| 1720 | assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, true), LY_SUCCESS); |
| 1721 | assert_int_equal(list.max, 5); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1722 | assert_true(list.flags & LYS_SET_MAX); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1723 | |
| 1724 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"85\"/> </leaf-list>"; |
| 1725 | assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, true), LY_SUCCESS); |
| 1726 | assert_int_equal(llist.max, 85); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1727 | assert_true(llist.flags & LYS_SET_MAX); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1728 | |
| 1729 | data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>"; |
| 1730 | assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS); |
| 1731 | assert_int_equal(refine.max, 10); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1732 | assert_true(refine.flags & LYS_SET_MAX); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1733 | |
| 1734 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>"; |
| 1735 | assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID); |
| 1736 | logbuf_assert("Invalid value \"0\" of \"max-elements\". Line number 1."); |
| 1737 | |
| 1738 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>"; |
| 1739 | assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID); |
| 1740 | logbuf_assert("Invalid value \"-10\" of \"max-elements\". Line number 1."); |
| 1741 | |
| 1742 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>"; |
| 1743 | assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID); |
| 1744 | logbuf_assert("Invalid value \"k\" of \"max-elements\". Line number 1."); |
| 1745 | |
| 1746 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>"; |
| 1747 | assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, false), LY_EVALID); |
| 1748 | logbuf_assert("Invalid value \"u12\" of \"max-elements\". Line number 1."); |
| 1749 | |
| 1750 | st->finished_correctly = true; |
| 1751 | } |
| 1752 | |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1753 | static void |
| 1754 | test_min_elems_elem(void **state) |
| 1755 | { |
| 1756 | struct state *st = *state; |
| 1757 | const char *data; |
| 1758 | struct lysp_node_list list = {}; |
| 1759 | struct lysp_node_leaflist llist = {}; |
| 1760 | struct lysp_refine refine = {}; |
| 1761 | |
| 1762 | data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"0\"/> </refine>"; |
| 1763 | assert_int_equal(test_element_helper(st, &data, &refine, NULL, NULL, true), LY_SUCCESS); |
| 1764 | assert_int_equal(refine.min, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1765 | assert_true(refine.flags & LYS_SET_MIN); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1766 | |
| 1767 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"41\"/> </list>"; |
| 1768 | assert_int_equal(test_element_helper(st, &data, &list, NULL, NULL, true), LY_SUCCESS); |
| 1769 | assert_int_equal(list.min, 41); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1770 | assert_true(list.flags & LYS_SET_MIN); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1771 | |
| 1772 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"50\"/> </leaf-list>"; |
| 1773 | assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, true), LY_SUCCESS); |
| 1774 | assert_int_equal(llist.min, 50); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1775 | assert_true(llist.flags & LYS_SET_MIN); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1776 | |
| 1777 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>"; |
| 1778 | assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID); |
| 1779 | logbuf_assert("Value \"-5\" is out of \"min-elements\" bounds. Line number 1."); |
| 1780 | |
| 1781 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>"; |
| 1782 | assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID); |
| 1783 | logbuf_assert("Value \"99999999999999999\" is out of \"min-elements\" bounds. Line number 1."); |
| 1784 | |
| 1785 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>"; |
| 1786 | assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID); |
| 1787 | logbuf_assert("Invalid value \"5k\" of \"min-elements\". Line number 1."); |
| 1788 | |
| 1789 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"05\"/> </leaf-list>"; |
| 1790 | assert_int_equal(test_element_helper(st, &data, &llist, NULL, NULL, false), LY_EVALID); |
| 1791 | logbuf_assert("Invalid value \"05\" of \"min-elements\". Line number 1."); |
| 1792 | |
| 1793 | st->finished_correctly = true; |
| 1794 | } |
| 1795 | |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1796 | static void |
| 1797 | test_ordby_elem(void **state) |
| 1798 | { |
| 1799 | struct state *st = *state; |
| 1800 | const char *data; |
| 1801 | uint16_t flags = 0; |
| 1802 | |
| 1803 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\"/>" ELEMENT_WRAPPER_END; |
| 1804 | 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] | 1805 | assert_true(flags & LYS_ORDBY_SYSTEM); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1806 | |
| 1807 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END; |
| 1808 | 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] | 1809 | assert_true(flags & LYS_ORDBY_USER); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1810 | |
| 1811 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END; |
| 1812 | assert_int_equal(test_element_helper(st, &data, &flags, NULL, NULL, false), LY_EVALID); |
| 1813 | logbuf_assert("Invalid value \"inv\" of \"ordered-by\". Line number 1."); |
| 1814 | |
| 1815 | st->finished_correctly = true; |
| 1816 | } |
| 1817 | |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1818 | static void |
| 1819 | test_any_elem(void **state) |
| 1820 | { |
| 1821 | struct state *st = *state; |
| 1822 | const char *data; |
| 1823 | struct lysp_node *siblings = NULL; |
| 1824 | struct tree_node_meta node_meta = {.parent = NULL, .siblings = &siblings}; |
| 1825 | struct lysp_node_anydata *parsed = NULL; |
| 1826 | |
| 1827 | /* anyxml max subelems */ |
| 1828 | data = ELEMENT_WRAPPER_START |
| 1829 | "<anyxml name=\"any-name\">" |
| 1830 | "<config value=\"true\" />" |
| 1831 | "<description><text>desc</text></description>" |
| 1832 | "<if-feature name=\"feature\" />" |
| 1833 | "<mandatory value=\"true\" />" |
| 1834 | "<must condition=\"must-cond\" />" |
| 1835 | "<reference><text>ref</text></reference>" |
| 1836 | "<status value=\"deprecated\"/>" |
| 1837 | "<when condition=\"when-cond\"/>" |
| 1838 | "</anyxml>" |
| 1839 | ELEMENT_WRAPPER_END; |
| 1840 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 1841 | parsed = (struct lysp_node_anydata *)siblings; |
| 1842 | assert_null(parsed->parent); |
| 1843 | assert_int_equal(parsed->nodetype, LYS_ANYXML); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1844 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 1845 | assert_true(parsed->flags & LYS_MAND_TRUE); |
| 1846 | assert_true(parsed->flags & LYS_STATUS_DEPRC); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1847 | assert_null(parsed->next); |
| 1848 | assert_string_equal(parsed->name, "any-name"); |
| 1849 | assert_string_equal(parsed->dsc, "desc"); |
| 1850 | assert_string_equal(parsed->ref, "ref"); |
| 1851 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 1852 | assert_string_equal(*parsed->iffeatures, "feature"); |
| 1853 | assert_null(parsed->exts); |
| 1854 | lysp_node_free(st->ctx, siblings); |
| 1855 | siblings = NULL; |
| 1856 | |
| 1857 | /* anydata max subelems */ |
| 1858 | data = ELEMENT_WRAPPER_START |
| 1859 | "<anydata name=\"any-name\">" |
| 1860 | "<config value=\"true\" />" |
| 1861 | "<description><text>desc</text></description>" |
| 1862 | "<if-feature name=\"feature\" />" |
| 1863 | "<mandatory value=\"true\" />" |
| 1864 | "<must condition=\"must-cond\" />" |
| 1865 | "<reference><text>ref</text></reference>" |
| 1866 | "<status value=\"deprecated\"/>" |
| 1867 | "<when condition=\"when-cond\"/>" |
| 1868 | "</anydata>" |
| 1869 | ELEMENT_WRAPPER_END; |
| 1870 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 1871 | parsed = (struct lysp_node_anydata *)siblings; |
| 1872 | assert_null(parsed->parent); |
| 1873 | assert_int_equal(parsed->nodetype, LYS_ANYDATA); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1874 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 1875 | assert_true(parsed->flags & LYS_MAND_TRUE); |
| 1876 | assert_true(parsed->flags & LYS_STATUS_DEPRC); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1877 | assert_null(parsed->next); |
| 1878 | assert_string_equal(parsed->name, "any-name"); |
| 1879 | assert_string_equal(parsed->dsc, "desc"); |
| 1880 | assert_string_equal(parsed->ref, "ref"); |
| 1881 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 1882 | assert_string_equal(*parsed->iffeatures, "feature"); |
| 1883 | assert_null(parsed->exts); |
| 1884 | lysp_node_free(st->ctx, siblings); |
| 1885 | siblings = NULL; |
| 1886 | |
| 1887 | /* min subelems */ |
| 1888 | node_meta.parent = (void *)0x10; |
| 1889 | data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END; |
| 1890 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 1891 | parsed = (struct lysp_node_anydata *)siblings; |
| 1892 | assert_ptr_equal(parsed->parent, node_meta.parent); |
| 1893 | assert_int_equal(parsed->nodetype, LYS_ANYDATA); |
| 1894 | assert_null(parsed->next); |
| 1895 | assert_null(parsed->exts); |
| 1896 | lysp_node_free(st->ctx, siblings); |
| 1897 | |
| 1898 | st->finished_correctly = true; |
| 1899 | } |
| 1900 | |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 1901 | static void |
| 1902 | test_leaf_elem(void **state) |
| 1903 | { |
| 1904 | struct state *st = *state; |
| 1905 | const char *data; |
| 1906 | struct lysp_node *siblings = NULL; |
| 1907 | struct tree_node_meta node_meta = {.parent = NULL, .siblings = &siblings}; |
| 1908 | struct lysp_node_leaf *parsed = NULL; |
| 1909 | |
| 1910 | /* max elements */ |
| 1911 | data = ELEMENT_WRAPPER_START |
| 1912 | "<leaf name=\"leaf\">" |
| 1913 | "<config value=\"true\" />" |
| 1914 | "<default value=\"def-val\"/>" |
| 1915 | "<description><text>desc</text></description>" |
| 1916 | "<if-feature name=\"feature\" />" |
| 1917 | "<mandatory value=\"true\" />" |
| 1918 | "<must condition=\"must-cond\" />" |
| 1919 | "<reference><text>ref</text></reference>" |
| 1920 | "<status value=\"deprecated\"/>" |
| 1921 | "<type name=\"type\"/>" |
| 1922 | "<units name=\"uni\"/>" |
| 1923 | "<when condition=\"when-cond\"/>" |
| 1924 | "</leaf>" |
| 1925 | ELEMENT_WRAPPER_END; |
| 1926 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 1927 | parsed = (struct lysp_node_leaf *)siblings; |
| 1928 | assert_null(parsed->parent); |
| 1929 | assert_int_equal(parsed->nodetype, LYS_LEAF); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1930 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 1931 | assert_true(parsed->flags & LYS_MAND_TRUE); |
| 1932 | assert_true(parsed->flags & LYS_STATUS_DEPRC); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 1933 | assert_null(parsed->next); |
| 1934 | assert_string_equal(parsed->name, "leaf"); |
| 1935 | assert_string_equal(parsed->dsc, "desc"); |
| 1936 | assert_string_equal(parsed->ref, "ref"); |
| 1937 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 1938 | assert_string_equal(*parsed->iffeatures, "feature"); |
| 1939 | assert_null(parsed->exts); |
| 1940 | assert_string_equal(parsed->musts->arg, "must-cond"); |
| 1941 | assert_string_equal(parsed->type.name, "type"); |
| 1942 | assert_string_equal(parsed->units, "uni"); |
| 1943 | assert_string_equal(parsed->dflt, "def-val"); |
| 1944 | lysp_node_free(st->ctx, siblings); |
| 1945 | siblings = NULL; |
| 1946 | |
| 1947 | /* min elements */ |
| 1948 | data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END; |
| 1949 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 1950 | parsed = (struct lysp_node_leaf *)siblings; |
| 1951 | assert_string_equal(parsed->name, "leaf"); |
| 1952 | assert_string_equal(parsed->type.name, "type"); |
| 1953 | lysp_node_free(st->ctx, siblings); |
| 1954 | siblings = NULL; |
| 1955 | |
| 1956 | st->finished_correctly = true; |
| 1957 | } |
| 1958 | |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1959 | static void |
| 1960 | test_leaf_list_elem(void **state) |
| 1961 | { |
| 1962 | struct state *st = *state; |
| 1963 | const char *data; |
| 1964 | struct lysp_node *siblings = NULL; |
| 1965 | struct tree_node_meta node_meta = {.parent = NULL, .siblings = &siblings}; |
| 1966 | struct lysp_node_leaflist *parsed = NULL; |
| 1967 | |
| 1968 | data = ELEMENT_WRAPPER_START |
| 1969 | "<leaf-list name=\"llist\">" |
| 1970 | "<config value=\"true\" />" |
| 1971 | "<default value=\"def-val0\"/>" |
| 1972 | "<default value=\"def-val1\"/>" |
| 1973 | "<description><text>desc</text></description>" |
| 1974 | "<if-feature name=\"feature\"/>" |
| 1975 | "<max-elements value=\"5\"/>" |
| 1976 | "<must condition=\"must-cond\"/>" |
| 1977 | "<ordered-by value=\"user\" />" |
| 1978 | "<reference><text>ref</text></reference>" |
| 1979 | "<status value=\"current\"/>" |
| 1980 | "<type name=\"type\"/>" |
| 1981 | "<units name=\"uni\"/>" |
| 1982 | "<when condition=\"when-cond\"/>" |
| 1983 | "</leaf-list>" |
| 1984 | ELEMENT_WRAPPER_END; |
| 1985 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 1986 | parsed = (struct lysp_node_leaflist *)siblings; |
| 1987 | assert_string_equal(parsed->dflts[0], "def-val0"); |
| 1988 | assert_string_equal(parsed->dflts[1], "def-val1"); |
| 1989 | assert_string_equal(parsed->dsc, "desc"); |
| 1990 | assert_string_equal(*parsed->iffeatures, "feature"); |
| 1991 | assert_int_equal(parsed->max, 5); |
| 1992 | assert_string_equal(parsed->musts->arg, "must-cond"); |
| 1993 | assert_string_equal(parsed->name, "llist"); |
| 1994 | assert_null(parsed->next); |
| 1995 | assert_int_equal(parsed->nodetype, LYS_LEAFLIST); |
| 1996 | assert_null(parsed->parent); |
| 1997 | assert_string_equal(parsed->ref, "ref"); |
| 1998 | assert_string_equal(parsed->type.name, "type"); |
| 1999 | assert_string_equal(parsed->units, "uni"); |
| 2000 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2001 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2002 | assert_true(parsed->flags & LYS_ORDBY_USER); |
| 2003 | assert_true(parsed->flags & LYS_STATUS_CURR); |
| 2004 | lysp_node_free(st->ctx, siblings); |
| 2005 | siblings = NULL; |
| 2006 | |
| 2007 | data = ELEMENT_WRAPPER_START |
| 2008 | "<leaf-list name=\"llist\">" |
| 2009 | "<config value=\"true\" />" |
| 2010 | "<description><text>desc</text></description>" |
| 2011 | "<if-feature name=\"feature\"/>" |
| 2012 | "<min-elements value=\"5\"/>" |
| 2013 | "<must condition=\"must-cond\"/>" |
| 2014 | "<ordered-by value=\"user\" />" |
| 2015 | "<reference><text>ref</text></reference>" |
| 2016 | "<status value=\"current\"/>" |
| 2017 | "<type name=\"type\"/>" |
| 2018 | "<units name=\"uni\"/>" |
| 2019 | "<when condition=\"when-cond\"/>" |
| 2020 | "</leaf-list>" |
| 2021 | ELEMENT_WRAPPER_END; |
| 2022 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2023 | parsed = (struct lysp_node_leaflist *)siblings; |
| 2024 | assert_string_equal(parsed->dsc, "desc"); |
| 2025 | assert_string_equal(*parsed->iffeatures, "feature"); |
| 2026 | assert_int_equal(parsed->min, 5); |
| 2027 | assert_string_equal(parsed->musts->arg, "must-cond"); |
| 2028 | assert_string_equal(parsed->name, "llist"); |
| 2029 | assert_null(parsed->next); |
| 2030 | assert_int_equal(parsed->nodetype, LYS_LEAFLIST); |
| 2031 | assert_null(parsed->parent); |
| 2032 | assert_string_equal(parsed->ref, "ref"); |
| 2033 | assert_string_equal(parsed->type.name, "type"); |
| 2034 | assert_string_equal(parsed->units, "uni"); |
| 2035 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2036 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2037 | assert_true(parsed->flags & LYS_ORDBY_USER); |
| 2038 | assert_true(parsed->flags & LYS_STATUS_CURR); |
| 2039 | lysp_node_free(st->ctx, siblings); |
| 2040 | siblings = NULL; |
| 2041 | |
| 2042 | data = ELEMENT_WRAPPER_START |
| 2043 | "<leaf-list name=\"llist\">" |
| 2044 | "<config value=\"true\" />" |
| 2045 | "<description><text>desc</text></description>" |
| 2046 | "<if-feature name=\"feature\"/>" |
| 2047 | "<max-elements value=\"15\"/>" |
| 2048 | "<min-elements value=\"5\"/>" |
| 2049 | "<must condition=\"must-cond\"/>" |
| 2050 | "<ordered-by value=\"user\" />" |
| 2051 | "<reference><text>ref</text></reference>" |
| 2052 | "<status value=\"current\"/>" |
| 2053 | "<type name=\"type\"/>" |
| 2054 | "<units name=\"uni\"/>" |
| 2055 | "<when condition=\"when-cond\"/>" |
| 2056 | "</leaf-list>" |
| 2057 | ELEMENT_WRAPPER_END; |
| 2058 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2059 | parsed = (struct lysp_node_leaflist *)siblings; |
| 2060 | assert_string_equal(parsed->dsc, "desc"); |
| 2061 | assert_string_equal(*parsed->iffeatures, "feature"); |
| 2062 | assert_int_equal(parsed->min, 5); |
| 2063 | assert_int_equal(parsed->max, 15); |
| 2064 | assert_string_equal(parsed->musts->arg, "must-cond"); |
| 2065 | assert_string_equal(parsed->name, "llist"); |
| 2066 | assert_null(parsed->next); |
| 2067 | assert_int_equal(parsed->nodetype, LYS_LEAFLIST); |
| 2068 | assert_null(parsed->parent); |
| 2069 | assert_string_equal(parsed->ref, "ref"); |
| 2070 | assert_string_equal(parsed->type.name, "type"); |
| 2071 | assert_string_equal(parsed->units, "uni"); |
| 2072 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2073 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2074 | assert_true(parsed->flags & LYS_ORDBY_USER); |
| 2075 | assert_true(parsed->flags & LYS_STATUS_CURR); |
| 2076 | lysp_node_free(st->ctx, siblings); |
| 2077 | siblings = NULL; |
| 2078 | |
| 2079 | data = ELEMENT_WRAPPER_START |
| 2080 | "<leaf-list name=\"llist\">" |
| 2081 | "<type name=\"type\"/>" |
| 2082 | "</leaf-list>" |
| 2083 | ELEMENT_WRAPPER_END; |
| 2084 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2085 | parsed = (struct lysp_node_leaflist *)siblings; |
| 2086 | assert_string_equal(parsed->name, "llist"); |
| 2087 | assert_string_equal(parsed->type.name, "type"); |
| 2088 | lysp_node_free(st->ctx, siblings); |
| 2089 | siblings = NULL; |
| 2090 | |
| 2091 | /* invalid combinations */ |
| 2092 | data = ELEMENT_WRAPPER_START |
| 2093 | "<leaf-list name=\"llist\">" |
| 2094 | "<max-elements value=\"5\"/>" |
| 2095 | "<min-elements value=\"15\"/>" |
| 2096 | "<type name=\"type\"/>" |
| 2097 | "</leaf-list>" |
| 2098 | ELEMENT_WRAPPER_END; |
| 2099 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID); |
| 2100 | logbuf_assert("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5. Line number 1."); |
| 2101 | lysp_node_free(st->ctx, siblings); |
| 2102 | siblings = NULL; |
| 2103 | |
| 2104 | data = ELEMENT_WRAPPER_START |
| 2105 | "<leaf-list name=\"llist\">" |
| 2106 | "<default value=\"def-val1\"/>" |
| 2107 | "<min-elements value=\"15\"/>" |
| 2108 | "<type name=\"type\"/>" |
| 2109 | "</leaf-list>" |
| 2110 | ELEMENT_WRAPPER_END; |
| 2111 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID); |
| 2112 | logbuf_assert("Invalid combination of keywords \"min-elements\" and \"default\" as substatements of \"leaf-list\". Line number 1."); |
| 2113 | lysp_node_free(st->ctx, siblings); |
| 2114 | siblings = NULL; |
| 2115 | |
| 2116 | data = ELEMENT_WRAPPER_START |
| 2117 | "<leaf-list name=\"llist\">" |
| 2118 | "</leaf-list>" |
| 2119 | ELEMENT_WRAPPER_END; |
| 2120 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, false), LY_EVALID); |
| 2121 | logbuf_assert("Missing mandatory subelement type of leaf-list element. Line number 1."); |
| 2122 | lysp_node_free(st->ctx, siblings); |
| 2123 | siblings = NULL; |
| 2124 | |
| 2125 | st->finished_correctly = true; |
| 2126 | } |
| 2127 | |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2128 | static void |
| 2129 | test_presence_elem(void **state) |
| 2130 | { |
| 2131 | struct state *st = *state; |
| 2132 | const char *data; |
| 2133 | const char *val; |
| 2134 | |
| 2135 | data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END; |
| 2136 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS); |
| 2137 | assert_string_equal(val, "presence-val"); |
| 2138 | FREE_STRING(st->ctx, val); |
| 2139 | |
| 2140 | data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END; |
| 2141 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID); |
| 2142 | logbuf_assert("Missing mandatory attribute value of presence element. Line number 1."); |
| 2143 | |
| 2144 | st->finished_correctly = true; |
| 2145 | } |
| 2146 | |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2147 | static void |
| 2148 | test_key_elem(void **state) |
| 2149 | { |
| 2150 | struct state *st = *state; |
| 2151 | const char *data; |
| 2152 | const char *val; |
| 2153 | |
| 2154 | data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END; |
| 2155 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, true), LY_SUCCESS); |
| 2156 | assert_string_equal(val, "key-value"); |
| 2157 | FREE_STRING(st->ctx, val); |
| 2158 | |
| 2159 | data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END; |
| 2160 | assert_int_equal(test_element_helper(st, &data, &val, NULL, NULL, false), LY_EVALID); |
| 2161 | logbuf_assert("Missing mandatory attribute value of key element. Line number 1."); |
| 2162 | |
| 2163 | st->finished_correctly = true; |
| 2164 | } |
| 2165 | |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2166 | static void |
| 2167 | test_typedef_elem(void **state) |
| 2168 | { |
| 2169 | struct state *st = *state; |
| 2170 | const char *data; |
| 2171 | struct lysp_tpdf *tpdfs = NULL; |
| 2172 | struct typedef_meta typdef_meta = {NULL, &tpdfs}; |
| 2173 | |
| 2174 | data = ELEMENT_WRAPPER_START |
| 2175 | "<typedef name=\"tpdf-name\">" |
| 2176 | "<default value=\"def-val\"/>" |
| 2177 | "<description><text>desc-text</text></description>" |
| 2178 | "<reference><text>ref-text</text></reference>" |
| 2179 | "<status value=\"current\"/>" |
| 2180 | "<type name=\"type\"/>" |
| 2181 | "<units name=\"uni\"/>" |
| 2182 | "</typedef>" |
| 2183 | ELEMENT_WRAPPER_END; |
| 2184 | assert_int_equal(test_element_helper(st, &data, &typdef_meta, NULL, NULL, true), LY_SUCCESS); |
| 2185 | assert_string_equal(tpdfs[0].dflt, "def-val"); |
| 2186 | assert_string_equal(tpdfs[0].dsc, "desc-text"); |
| 2187 | assert_null(tpdfs[0].exts); |
| 2188 | assert_string_equal(tpdfs[0].name, "tpdf-name"); |
| 2189 | assert_string_equal(tpdfs[0].ref, "ref-text"); |
| 2190 | assert_string_equal(tpdfs[0].type.name, "type"); |
| 2191 | assert_string_equal(tpdfs[0].units, "uni"); |
| 2192 | assert_true(tpdfs[0].flags & LYS_STATUS_CURR); |
| 2193 | FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free); |
| 2194 | tpdfs = NULL; |
| 2195 | |
| 2196 | data = ELEMENT_WRAPPER_START |
| 2197 | "<typedef name=\"tpdf-name\">" |
| 2198 | "<type name=\"type\"/>" |
| 2199 | "</typedef>" |
| 2200 | ELEMENT_WRAPPER_END; |
| 2201 | assert_int_equal(test_element_helper(st, &data, &typdef_meta, NULL, NULL, true), LY_SUCCESS); |
| 2202 | assert_string_equal(tpdfs[0].name, "tpdf-name"); |
| 2203 | assert_string_equal(tpdfs[0].type.name, "type"); |
| 2204 | FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free); |
| 2205 | tpdfs = NULL; |
| 2206 | |
| 2207 | st->finished_correctly = true; |
| 2208 | } |
| 2209 | |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2210 | static void |
| 2211 | test_refine_elem(void **state) |
| 2212 | { |
| 2213 | struct state *st = *state; |
| 2214 | const char *data; |
| 2215 | struct lysp_refine *refines = NULL; |
| 2216 | |
| 2217 | /* max subelems */ |
| 2218 | data = ELEMENT_WRAPPER_START |
| 2219 | "<refine target-node=\"target\">" |
| 2220 | "<if-feature name=\"feature\" />" |
| 2221 | "<must condition=\"cond\" />" |
| 2222 | "<presence value=\"presence\" />" |
| 2223 | "<default value=\"def\" />" |
| 2224 | "<config value=\"true\" />" |
| 2225 | "<mandatory value=\"true\" />" |
| 2226 | "<min-elements value=\"10\" />" |
| 2227 | "<max-elements value=\"20\" />" |
| 2228 | "<description><text>desc</text></description>" |
| 2229 | "<reference><text>ref</text></reference>" |
| 2230 | "</refine>" |
| 2231 | ELEMENT_WRAPPER_END; |
| 2232 | assert_int_equal(test_element_helper(st, &data, &refines, NULL, NULL, true), LY_SUCCESS); |
| 2233 | assert_string_equal(refines->nodeid, "target"); |
| 2234 | assert_string_equal(*refines->dflts, "def"); |
| 2235 | assert_string_equal(refines->dsc, "desc"); |
| 2236 | assert_null(refines->exts); |
| 2237 | assert_true(refines->flags & LYS_CONFIG_W); |
| 2238 | assert_true(refines->flags & LYS_MAND_TRUE); |
| 2239 | assert_string_equal(*refines->iffeatures, "feature"); |
| 2240 | assert_int_equal(refines->max, 20); |
| 2241 | assert_int_equal(refines->min, 10); |
| 2242 | assert_string_equal(refines->musts->arg, "cond"); |
| 2243 | assert_string_equal(refines->presence, "presence"); |
| 2244 | assert_string_equal(refines->ref, "ref"); |
| 2245 | FREE_ARRAY(st->ctx, refines, lysp_refine_free); |
| 2246 | refines = NULL; |
| 2247 | |
| 2248 | /* min subelems */ |
| 2249 | data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END; |
| 2250 | assert_int_equal(test_element_helper(st, &data, &refines, NULL, NULL, true), LY_SUCCESS); |
| 2251 | assert_string_equal(refines->nodeid, "target"); |
| 2252 | FREE_ARRAY(st->ctx, refines, lysp_refine_free); |
| 2253 | refines = NULL; |
| 2254 | |
| 2255 | st->finished_correctly = true; |
| 2256 | } |
| 2257 | |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2258 | static void |
| 2259 | test_uses_elem(void **state) |
| 2260 | { |
| 2261 | struct state *st = *state; |
| 2262 | const char *data; |
| 2263 | struct lysp_node *siblings = NULL; |
| 2264 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2265 | struct lysp_node_uses *parsed = NULL; |
| 2266 | |
| 2267 | /* max subelems */ |
| 2268 | data = ELEMENT_WRAPPER_START |
| 2269 | "<uses name=\"uses-name\">" |
| 2270 | "<when condition=\"cond\" />" |
| 2271 | "<if-feature name=\"feature\" />" |
| 2272 | "<status value=\"obsolete\" />" |
| 2273 | "<description><text>desc</text></description>" |
| 2274 | "<reference><text>ref</text></reference>" |
| 2275 | "<refine target-node=\"target\"/>" |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2276 | "<augment target-node=\"target\" />" |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2277 | "</uses>" |
| 2278 | ELEMENT_WRAPPER_END; |
| 2279 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2280 | parsed = (struct lysp_node_uses *)&siblings[0]; |
| 2281 | assert_string_equal(parsed->name, "uses-name"); |
| 2282 | assert_string_equal(parsed->dsc, "desc"); |
| 2283 | assert_null(parsed->exts); |
| 2284 | assert_true(parsed->flags & LYS_STATUS_OBSLT); |
| 2285 | assert_string_equal(*parsed->iffeatures, "feature"); |
| 2286 | assert_null(parsed->next); |
| 2287 | assert_int_equal(parsed->nodetype, LYS_USES); |
| 2288 | assert_null(parsed->parent); |
| 2289 | assert_string_equal(parsed->ref, "ref"); |
| 2290 | assert_string_equal(parsed->refines->nodeid, "target"); |
| 2291 | assert_string_equal(parsed->when->cond, "cond"); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2292 | assert_string_equal(parsed->augments->nodeid, "target"); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2293 | lysp_node_free(st->ctx, siblings); |
| 2294 | siblings = NULL; |
| 2295 | |
| 2296 | /* min subelems */ |
| 2297 | data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END; |
| 2298 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2299 | assert_string_equal(siblings[0].name, "uses-name"); |
| 2300 | lysp_node_free(st->ctx, siblings); |
| 2301 | siblings = NULL; |
| 2302 | |
| 2303 | st->finished_correctly = true; |
| 2304 | } |
| 2305 | |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2306 | static void |
| 2307 | test_revision_elem(void **state) |
| 2308 | { |
| 2309 | struct state *st = *state; |
| 2310 | const char *data; |
| 2311 | struct lysp_revision *revs = NULL; |
| 2312 | |
| 2313 | /* max subelems */ |
| 2314 | data = ELEMENT_WRAPPER_START |
| 2315 | "<revision date=\"2018-12-25\">" |
| 2316 | "<description><text>desc</text></description>" |
| 2317 | "<reference><text>ref</text></reference>" |
| 2318 | "</revision>" |
| 2319 | ELEMENT_WRAPPER_END; |
| 2320 | assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, true), LY_SUCCESS); |
| 2321 | assert_string_equal(revs->date, "2018-12-25"); |
| 2322 | assert_string_equal(revs->dsc, "desc"); |
| 2323 | assert_string_equal(revs->ref, "ref"); |
| 2324 | FREE_ARRAY(st->ctx, revs, lysp_revision_free); |
| 2325 | revs = NULL; |
| 2326 | |
| 2327 | /* min subelems */ |
| 2328 | data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END; |
| 2329 | assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, true), LY_SUCCESS); |
| 2330 | assert_string_equal(revs->date, "2005-05-05"); |
| 2331 | FREE_ARRAY(st->ctx, revs, lysp_revision_free); |
| 2332 | revs = NULL; |
| 2333 | |
| 2334 | /* invalid value */ |
| 2335 | data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END; |
| 2336 | assert_int_equal(test_element_helper(st, &data, &revs, NULL, NULL, false), LY_EVALID); |
| 2337 | logbuf_assert("Invalid value \"05-05-2005\" of \"revision\". Line number 1."); |
| 2338 | FREE_ARRAY(st->ctx, revs, lysp_revision_free); |
| 2339 | revs = NULL; |
| 2340 | |
| 2341 | st->finished_correctly = true; |
| 2342 | } |
| 2343 | |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2344 | static void |
| 2345 | test_include_elem(void **state) |
| 2346 | { |
| 2347 | struct state *st = *state; |
| 2348 | const char *data; |
| 2349 | struct lysp_include *includes = NULL; |
| 2350 | struct include_meta inc_meta = {"module-name", &includes}; |
| 2351 | |
| 2352 | /* max subelems */ |
| 2353 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 2354 | data = ELEMENT_WRAPPER_START |
| 2355 | "<include module=\"mod\">" |
| 2356 | "<description><text>desc</text></description>" |
| 2357 | "<reference><text>ref</text></reference>" |
| 2358 | "<revision-date date=\"1999-09-09\"/>" |
| 2359 | "</include>" |
| 2360 | ELEMENT_WRAPPER_END; |
| 2361 | assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, true), LY_SUCCESS); |
| 2362 | assert_string_equal(includes->name, "mod"); |
| 2363 | assert_string_equal(includes->dsc, "desc"); |
| 2364 | assert_string_equal(includes->ref, "ref"); |
| 2365 | assert_null(includes->exts); |
| 2366 | assert_string_equal(includes->rev, "1999-09-09"); |
| 2367 | FREE_ARRAY(st->ctx, includes, lysp_include_free); |
| 2368 | includes = NULL; |
| 2369 | |
| 2370 | /* min subelems */ |
| 2371 | data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END; |
| 2372 | assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, true), LY_SUCCESS); |
| 2373 | assert_string_equal(includes->name, "mod"); |
| 2374 | FREE_ARRAY(st->ctx, includes, lysp_include_free); |
| 2375 | includes = NULL; |
| 2376 | |
| 2377 | /* invalid combinations */ |
| 2378 | st->yin_ctx->mod_version = LYS_VERSION_1_0; |
| 2379 | data = ELEMENT_WRAPPER_START |
| 2380 | "<include module=\"mod\">" |
| 2381 | "<description><text>desc</text></description>" |
| 2382 | "<revision-date date=\"1999-09-09\"/>" |
| 2383 | "</include>" |
| 2384 | ELEMENT_WRAPPER_END; |
| 2385 | assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, false), LY_EVALID); |
| 2386 | 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."); |
| 2387 | FREE_ARRAY(st->ctx, includes, lysp_include_free); |
| 2388 | includes = NULL; |
| 2389 | |
| 2390 | st->yin_ctx->mod_version = LYS_VERSION_1_0; |
| 2391 | data = ELEMENT_WRAPPER_START |
| 2392 | "<include module=\"mod\">" |
| 2393 | "<reference><text>ref</text></reference>" |
| 2394 | "<revision-date date=\"1999-09-09\"/>" |
| 2395 | "</include>" |
| 2396 | ELEMENT_WRAPPER_END; |
| 2397 | assert_int_equal(test_element_helper(st, &data, &inc_meta, NULL, NULL, false), LY_EVALID); |
| 2398 | 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."); |
| 2399 | FREE_ARRAY(st->ctx, includes, lysp_include_free); |
| 2400 | includes = NULL; |
| 2401 | |
| 2402 | st->finished_correctly = true; |
| 2403 | } |
| 2404 | |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 2405 | static void |
| 2406 | test_feature_elem(void **state) |
| 2407 | { |
| 2408 | struct state *st = *state; |
| 2409 | const char *data; |
| 2410 | struct lysp_feature *features = NULL; |
| 2411 | |
| 2412 | /* max subelems */ |
| 2413 | data = ELEMENT_WRAPPER_START |
| 2414 | "<feature name=\"feature-name\">" |
| 2415 | "<if-feature name=\"iff\"/>" |
| 2416 | "<status value=\"deprecated\"/>" |
| 2417 | "<description><text>desc</text></description>" |
| 2418 | "<reference><text>ref</text></reference>" |
| 2419 | "</feature>" |
| 2420 | ELEMENT_WRAPPER_END; |
| 2421 | assert_int_equal(test_element_helper(st, &data, &features, NULL, NULL, true), LY_SUCCESS); |
| 2422 | assert_string_equal(features->name, "feature-name"); |
| 2423 | assert_string_equal(features->dsc, "desc"); |
| 2424 | assert_null(features->exts); |
| 2425 | assert_true(features->flags & LYS_STATUS_DEPRC); |
| 2426 | assert_string_equal(*features->iffeatures, "iff"); |
| 2427 | assert_string_equal(features->ref, "ref"); |
| 2428 | FREE_ARRAY(st->ctx, features, lysp_feature_free); |
| 2429 | features = NULL; |
| 2430 | |
| 2431 | /* min subelems */ |
| 2432 | data = ELEMENT_WRAPPER_START "<feature name=\"feature-name\"/>" ELEMENT_WRAPPER_END; |
| 2433 | assert_int_equal(test_element_helper(st, &data, &features, NULL, NULL, true), LY_SUCCESS); |
| 2434 | assert_string_equal(features->name, "feature-name"); |
| 2435 | FREE_ARRAY(st->ctx, features, lysp_feature_free); |
| 2436 | features = NULL; |
| 2437 | |
| 2438 | st->finished_correctly = true; |
| 2439 | } |
| 2440 | |
David Sedlák | 28794f2 | 2019-07-22 16:45:00 +0200 | [diff] [blame] | 2441 | static void |
| 2442 | test_identity_elem(void **state) |
| 2443 | { |
| 2444 | struct state *st = *state; |
| 2445 | const char *data; |
| 2446 | struct lysp_ident *identities = NULL; |
| 2447 | |
| 2448 | /* max subelems */ |
| 2449 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 2450 | data = ELEMENT_WRAPPER_START |
| 2451 | "<identity name=\"ident-name\">" |
| 2452 | "<if-feature name=\"iff\"/>" |
| 2453 | "<base name=\"base-name\"/>" |
| 2454 | "<status value=\"deprecated\"/>" |
| 2455 | "<description><text>desc</text></description>" |
| 2456 | "<reference><text>ref</text></reference>" |
| 2457 | "</identity>" |
| 2458 | ELEMENT_WRAPPER_END; |
| 2459 | assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, true), LY_SUCCESS); |
| 2460 | assert_string_equal(identities->name, "ident-name"); |
| 2461 | assert_string_equal(*identities->bases, "base-name"); |
| 2462 | assert_string_equal(*identities->iffeatures, "iff"); |
| 2463 | assert_string_equal(identities->dsc, "desc"); |
| 2464 | assert_string_equal(identities->ref, "ref"); |
| 2465 | assert_true(identities->flags & LYS_STATUS_DEPRC); |
| 2466 | assert_null(identities->exts); |
| 2467 | FREE_ARRAY(st->ctx, identities, lysp_ident_free); |
| 2468 | identities = NULL; |
| 2469 | |
| 2470 | /* min subelems */ |
| 2471 | data = ELEMENT_WRAPPER_START "<identity name=\"ident-name\" />" ELEMENT_WRAPPER_END; |
| 2472 | assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, true), LY_SUCCESS); |
| 2473 | assert_string_equal(identities->name, "ident-name"); |
| 2474 | FREE_ARRAY(st->ctx, identities, lysp_ident_free); |
| 2475 | identities = NULL; |
| 2476 | |
| 2477 | /* invalid */ |
| 2478 | st->yin_ctx->mod_version = LYS_VERSION_1_0; |
| 2479 | data = ELEMENT_WRAPPER_START |
| 2480 | "<identity name=\"ident-name\">" |
| 2481 | "<if-feature name=\"iff\"/>" |
| 2482 | "</identity>" |
| 2483 | ELEMENT_WRAPPER_END; |
| 2484 | assert_int_equal(test_element_helper(st, &data, &identities, NULL, NULL, false), LY_EVALID); |
| 2485 | 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."); |
| 2486 | FREE_ARRAY(st->ctx, identities, lysp_ident_free); |
| 2487 | identities = NULL; |
| 2488 | |
| 2489 | st->finished_correctly = true; |
| 2490 | } |
| 2491 | |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2492 | static void |
| 2493 | test_list_elem(void **state) |
| 2494 | { |
| 2495 | struct state *st = *state; |
| 2496 | const char *data; |
| 2497 | struct lysp_node *siblings = NULL; |
| 2498 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2499 | struct lysp_node_list *parsed = NULL; |
| 2500 | |
| 2501 | /* max subelems */ |
| 2502 | data = ELEMENT_WRAPPER_START |
| 2503 | "<list name=\"list-name\">" |
| 2504 | "<when condition=\"when\"/>" |
| 2505 | "<if-feature name=\"iff\"/>" |
| 2506 | "<must condition=\"must-cond\"/>" |
| 2507 | "<key value=\"key\"/>" |
| 2508 | "<unique tag=\"utag\"/>" |
| 2509 | "<config value=\"true\"/>" |
| 2510 | "<min-elements value=\"10\"/>" |
| 2511 | "<ordered-by value=\"user\"/>" |
| 2512 | "<status value=\"deprecated\"/>" |
| 2513 | "<description><text>desc</text></description>" |
| 2514 | "<reference><text>ref</text></reference>" |
| 2515 | "<anydata name=\"anyd\"/>" |
| 2516 | "<anyxml name=\"anyx\"/>" |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2517 | "<container name=\"cont\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2518 | "<choice name=\"choice\"/>" |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2519 | "<action name=\"action\"/>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2520 | "<grouping name=\"grp\"/>" |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2521 | "<notification name=\"notf\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2522 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 2523 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2524 | "<list name=\"sub-list\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2525 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2526 | "<uses name=\"uses-name\"/>" |
| 2527 | "</list>" |
| 2528 | ELEMENT_WRAPPER_END; |
| 2529 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2530 | parsed = (struct lysp_node_list *)&siblings[0]; |
| 2531 | assert_string_equal(parsed->dsc, "desc"); |
| 2532 | assert_string_equal(parsed->child->name, "anyd"); |
| 2533 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 2534 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 2535 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2536 | assert_string_equal(parsed->child->next->next->name, "cont"); |
| 2537 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2538 | assert_string_equal(parsed->child->next->next->next->name, "choice"); |
| 2539 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2540 | assert_string_equal(parsed->child->next->next->next->next->name, "leaf"); |
| 2541 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF); |
| 2542 | assert_string_equal(parsed->child->next->next->next->next->next->name, "llist"); |
| 2543 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2544 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list"); |
| 2545 | assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 2546 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name"); |
| 2547 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 2548 | 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] | 2549 | assert_string_equal(parsed->groupings->name, "grp"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2550 | assert_string_equal(parsed->actions->name, "action"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2551 | assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2552 | assert_string_equal(parsed->notifs->name, "notf"); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2553 | assert_null(parsed->exts); |
| 2554 | assert_true(parsed->flags & LYS_ORDBY_USER); |
| 2555 | assert_true(parsed->flags & LYS_STATUS_DEPRC); |
| 2556 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2557 | assert_string_equal(*parsed->iffeatures, "iff"); |
| 2558 | assert_string_equal(parsed->key, "key"); |
| 2559 | assert_int_equal(parsed->min, 10); |
| 2560 | assert_string_equal(parsed->musts->arg, "must-cond"); |
| 2561 | assert_string_equal(parsed->name, "list-name"); |
| 2562 | assert_null(parsed->next); |
| 2563 | assert_int_equal(parsed->nodetype, LYS_LIST); |
| 2564 | assert_null(parsed->parent); |
| 2565 | assert_string_equal(parsed->ref, "ref"); |
| 2566 | assert_string_equal(parsed->typedefs->name, "tpdf"); |
| 2567 | assert_string_equal(*parsed->uniques, "utag"); |
| 2568 | assert_string_equal(parsed->when->cond, "when"); |
| 2569 | lysp_node_free(st->ctx, siblings); |
| 2570 | ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL); |
| 2571 | siblings = NULL; |
| 2572 | |
| 2573 | /* min subelems */ |
| 2574 | data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END; |
| 2575 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2576 | parsed = (struct lysp_node_list *)&siblings[0]; |
| 2577 | assert_string_equal(parsed->name, "list-name"); |
| 2578 | lysp_node_free(st->ctx, siblings); |
| 2579 | siblings = NULL; |
| 2580 | |
| 2581 | st->finished_correctly = true; |
| 2582 | } |
| 2583 | |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2584 | static void |
| 2585 | test_notification_elem(void **state) |
| 2586 | { |
| 2587 | struct state *st = *state; |
| 2588 | const char *data; |
| 2589 | struct lysp_notif *notifs = NULL; |
| 2590 | struct notif_meta notif_meta = {NULL, ¬ifs}; |
| 2591 | |
| 2592 | /* max subelems */ |
| 2593 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 2594 | data = ELEMENT_WRAPPER_START |
| 2595 | "<notification name=\"notif-name\">" |
| 2596 | "<anydata name=\"anyd\"/>" |
| 2597 | "<anyxml name=\"anyx\"/>" |
| 2598 | "<description><text>desc</text></description>" |
| 2599 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2600 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 2601 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2602 | "<list name=\"sub-list\"/>" |
| 2603 | "<must condition=\"cond\"/>" |
| 2604 | "<reference><text>ref</text></reference>" |
| 2605 | "<status value=\"deprecated\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2606 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2607 | "<uses name=\"uses-name\"/>" |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2608 | "<container name=\"cont\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2609 | "<choice name=\"choice\"/>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2610 | "<grouping name=\"grp\"/>" |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2611 | "</notification>" |
| 2612 | ELEMENT_WRAPPER_END; |
| 2613 | assert_int_equal(test_element_helper(st, &data, ¬if_meta, NULL, NULL, true), LY_SUCCESS); |
| 2614 | assert_string_equal(notifs->name, "notif-name"); |
| 2615 | assert_string_equal(notifs->data->name, "anyd"); |
| 2616 | assert_int_equal(notifs->data->nodetype, LYS_ANYDATA); |
| 2617 | assert_string_equal(notifs->data->next->name, "anyx"); |
| 2618 | assert_int_equal(notifs->data->next->nodetype, LYS_ANYXML); |
| 2619 | assert_string_equal(notifs->data->next->next->name, "leaf"); |
| 2620 | assert_int_equal(notifs->data->next->next->nodetype, LYS_LEAF); |
| 2621 | assert_string_equal(notifs->data->next->next->next->name, "llist"); |
| 2622 | assert_int_equal(notifs->data->next->next->next->nodetype, LYS_LEAFLIST); |
| 2623 | assert_string_equal(notifs->data->next->next->next->next->name, "sub-list"); |
| 2624 | assert_int_equal(notifs->data->next->next->next->next->nodetype, LYS_LIST); |
| 2625 | assert_null(notifs->exts); |
| 2626 | assert_true(notifs->flags & LYS_STATUS_DEPRC); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2627 | assert_string_equal(notifs->groupings->name, "grp"); |
| 2628 | assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2629 | assert_string_equal(notifs->data->next->next->next->next->next->name, "uses-name"); |
| 2630 | assert_int_equal(notifs->data->next->next->next->next->next->nodetype, LYS_USES); |
| 2631 | assert_string_equal(notifs->data->next->next->next->next->next->next->name, "cont"); |
| 2632 | 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] | 2633 | assert_int_equal(notifs->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 2634 | assert_string_equal(notifs->data->next->next->next->next->next->next->next->name, "choice"); |
| 2635 | 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] | 2636 | assert_string_equal(*notifs->iffeatures, "iff"); |
| 2637 | assert_string_equal(notifs->musts->arg, "cond"); |
| 2638 | assert_int_equal(notifs->nodetype, LYS_NOTIF); |
| 2639 | assert_null(notifs->parent); |
| 2640 | assert_string_equal(notifs->ref, "ref"); |
| 2641 | assert_string_equal(notifs->typedefs->name, "tpdf"); |
| 2642 | FREE_ARRAY(st->ctx, notifs, lysp_notif_free); |
| 2643 | notifs = NULL; |
| 2644 | |
| 2645 | /* min subelems */ |
| 2646 | data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END; |
| 2647 | assert_int_equal(test_element_helper(st, &data, ¬if_meta, NULL, NULL, true), LY_SUCCESS); |
| 2648 | assert_string_equal(notifs->name, "notif-name"); |
| 2649 | FREE_ARRAY(st->ctx, notifs, lysp_notif_free); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2650 | notifs = NULL; |
| 2651 | |
| 2652 | st->finished_correctly = true; |
| 2653 | } |
| 2654 | |
| 2655 | static void |
| 2656 | test_grouping_elem(void **state) |
| 2657 | { |
| 2658 | struct state *st = *state; |
| 2659 | const char *data; |
| 2660 | struct lysp_grp *grps = NULL; |
| 2661 | struct grouping_meta grp_meta = {NULL, &grps}; |
| 2662 | |
| 2663 | /* max subelems */ |
| 2664 | data = ELEMENT_WRAPPER_START |
| 2665 | "<grouping name=\"grp-name\">" |
| 2666 | "<anydata name=\"anyd\"/>" |
| 2667 | "<anyxml name=\"anyx\"/>" |
| 2668 | "<description><text>desc</text></description>" |
| 2669 | "<grouping name=\"sub-grp\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2670 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 2671 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2672 | "<list name=\"list\"/>" |
| 2673 | "<notification name=\"notf\"/>" |
| 2674 | "<reference><text>ref</text></reference>" |
| 2675 | "<status value=\"current\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2676 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2677 | "<uses name=\"uses-name\"/>" |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2678 | "<action name=\"act\"/>" |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2679 | "<container name=\"cont\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2680 | "<choice name=\"choice\"/>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2681 | "</grouping>" |
| 2682 | ELEMENT_WRAPPER_END; |
| 2683 | assert_int_equal(test_element_helper(st, &data, &grp_meta, NULL, NULL, true), LY_SUCCESS); |
| 2684 | assert_string_equal(grps->name, "grp-name"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2685 | assert_string_equal(grps->data->name, "anyd"); |
| 2686 | assert_string_equal(grps->data->next->name, "anyx"); |
| 2687 | assert_string_equal(grps->data->next->next->name, "leaf"); |
| 2688 | assert_string_equal(grps->data->next->next->next->name, "llist"); |
| 2689 | assert_string_equal(grps->data->next->next->next->next->name, "list"); |
| 2690 | assert_string_equal(grps->dsc, "desc"); |
| 2691 | assert_null(grps->exts); |
| 2692 | assert_true(grps->flags & LYS_STATUS_CURR); |
| 2693 | assert_string_equal(grps->groupings->name, "sub-grp"); |
| 2694 | assert_int_equal(grps->nodetype, LYS_GROUPING); |
| 2695 | assert_string_equal(grps->notifs->name, "notf"); |
| 2696 | assert_null(grps->parent); |
| 2697 | assert_string_equal(grps->ref, "ref"); |
| 2698 | assert_string_equal(grps->typedefs->name, "tpdf"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2699 | assert_string_equal(grps->actions->name, "act"); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2700 | 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] | 2701 | 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] | 2702 | 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] | 2703 | assert_int_equal(grps->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER); |
| 2704 | assert_string_equal(grps->data->next->next->next->next->next->next->next->name, "choice"); |
| 2705 | 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] | 2706 | FREE_ARRAY(st->ctx, grps, lysp_grp_free); |
| 2707 | grps = NULL; |
| 2708 | |
| 2709 | /* min subelems */ |
| 2710 | data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END; |
| 2711 | assert_int_equal(test_element_helper(st, &data, &grp_meta, NULL, NULL, true), LY_SUCCESS); |
| 2712 | assert_string_equal(grps->name, "grp-name"); |
| 2713 | FREE_ARRAY(st->ctx, grps, lysp_grp_free); |
| 2714 | grps = NULL; |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2715 | |
| 2716 | st->finished_correctly = true; |
| 2717 | } |
| 2718 | |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2719 | static void |
| 2720 | test_container_elem(void **state) |
| 2721 | { |
| 2722 | struct state *st = *state; |
| 2723 | const char *data; |
| 2724 | struct lysp_node *siblings = NULL; |
| 2725 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2726 | struct lysp_node_container *parsed = NULL; |
| 2727 | |
| 2728 | /* max subelems */ |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 2729 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 2730 | data = ELEMENT_WRAPPER_START |
| 2731 | "<container name=\"cont-name\">" |
| 2732 | "<anydata name=\"anyd\"/>" |
| 2733 | "<anyxml name=\"anyx\"/>" |
| 2734 | "<config value=\"true\"/>" |
| 2735 | "<container name=\"subcont\"/>" |
| 2736 | "<description><text>desc</text></description>" |
| 2737 | "<grouping name=\"sub-grp\"/>" |
| 2738 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2739 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 2740 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 2741 | "<list name=\"list\"/>" |
| 2742 | "<must condition=\"cond\"/>" |
| 2743 | "<notification name=\"notf\"/>" |
| 2744 | "<presence value=\"presence\"/>" |
| 2745 | "<reference><text>ref</text></reference>" |
| 2746 | "<status value=\"current\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2747 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 2748 | "<uses name=\"uses-name\"/>" |
| 2749 | "<when condition=\"when-cond\"/>" |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2750 | "<action name=\"act\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2751 | "<choice name=\"choice\"/>" |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 2752 | "</container>" |
| 2753 | ELEMENT_WRAPPER_END; |
| 2754 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2755 | parsed = (struct lysp_node_container *)siblings; |
| 2756 | assert_string_equal(parsed->name, "cont-name"); |
| 2757 | assert_null(parsed->parent); |
| 2758 | assert_int_equal(parsed->nodetype, LYS_CONTAINER); |
| 2759 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2760 | assert_true(parsed->flags & LYS_STATUS_CURR); |
| 2761 | assert_null(parsed->next); |
| 2762 | assert_string_equal(parsed->dsc, "desc"); |
| 2763 | assert_string_equal(parsed->ref, "ref"); |
| 2764 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2765 | assert_string_equal(*parsed->iffeatures, "iff"); |
| 2766 | assert_null(parsed->exts); |
| 2767 | assert_string_equal(parsed->musts->arg, "cond"); |
| 2768 | assert_string_equal(parsed->presence, "presence"); |
| 2769 | assert_string_equal(parsed->typedefs->name, "tpdf"); |
| 2770 | assert_string_equal(parsed->groupings->name, "sub-grp"); |
| 2771 | assert_string_equal(parsed->child->name, "anyd"); |
| 2772 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 2773 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 2774 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 2775 | assert_string_equal(parsed->child->next->next->name, "subcont"); |
| 2776 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
| 2777 | assert_string_equal(parsed->child->next->next->next->name, "leaf"); |
| 2778 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF); |
| 2779 | assert_string_equal(parsed->child->next->next->next->next->name, "llist"); |
| 2780 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2781 | assert_string_equal(parsed->child->next->next->next->next->next->name, "list"); |
| 2782 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST); |
| 2783 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name"); |
| 2784 | 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] | 2785 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice"); |
| 2786 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 2787 | 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] | 2788 | assert_string_equal(parsed->notifs->name, "notf"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2789 | assert_string_equal(parsed->actions->name, "act"); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 2790 | lysp_node_free(st->ctx, siblings); |
| 2791 | ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL); |
| 2792 | siblings = NULL; |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2793 | |
| 2794 | /* min subelems */ |
| 2795 | data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END; |
| 2796 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2797 | parsed = (struct lysp_node_container *)siblings; |
| 2798 | assert_string_equal(parsed->name, "cont-name"); |
| 2799 | lysp_node_free(st->ctx, siblings); |
| 2800 | siblings = NULL; |
| 2801 | |
| 2802 | st->finished_correctly = true; |
| 2803 | } |
| 2804 | |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2805 | static void |
| 2806 | test_case_elem(void **state) |
| 2807 | { |
| 2808 | struct state *st = *state; |
| 2809 | const char *data; |
| 2810 | struct lysp_node *siblings = NULL; |
| 2811 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2812 | struct lysp_node_case *parsed = NULL; |
| 2813 | |
| 2814 | /* max subelems */ |
| 2815 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 2816 | data = ELEMENT_WRAPPER_START |
| 2817 | "<case name=\"case-name\">" |
| 2818 | "<anydata name=\"anyd\"/>" |
| 2819 | "<anyxml name=\"anyx\"/>" |
| 2820 | "<container name=\"subcont\"/>" |
| 2821 | "<description><text>desc</text></description>" |
| 2822 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2823 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 2824 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2825 | "<list name=\"list\"/>" |
| 2826 | "<reference><text>ref</text></reference>" |
| 2827 | "<status value=\"current\"/>" |
| 2828 | "<uses name=\"uses-name\"/>" |
| 2829 | "<when condition=\"when-cond\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2830 | "<choice name=\"choice\"/>" |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2831 | "</case>" |
| 2832 | ELEMENT_WRAPPER_END; |
| 2833 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2834 | parsed = (struct lysp_node_case *)siblings; |
| 2835 | assert_string_equal(parsed->name, "case-name"); |
| 2836 | assert_null(parsed->parent); |
| 2837 | assert_int_equal(parsed->nodetype, LYS_CASE); |
| 2838 | assert_true(parsed->flags & LYS_STATUS_CURR); |
| 2839 | assert_null(parsed->next); |
| 2840 | assert_string_equal(parsed->dsc, "desc"); |
| 2841 | assert_string_equal(parsed->ref, "ref"); |
| 2842 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2843 | assert_string_equal(*parsed->iffeatures, "iff"); |
| 2844 | assert_null(parsed->exts); |
| 2845 | assert_string_equal(parsed->child->name, "anyd"); |
| 2846 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 2847 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 2848 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 2849 | assert_string_equal(parsed->child->next->next->name, "subcont"); |
| 2850 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
| 2851 | assert_string_equal(parsed->child->next->next->next->name, "leaf"); |
| 2852 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF); |
| 2853 | assert_string_equal(parsed->child->next->next->next->next->name, "llist"); |
| 2854 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2855 | assert_string_equal(parsed->child->next->next->next->next->next->name, "list"); |
| 2856 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST); |
| 2857 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name"); |
| 2858 | 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] | 2859 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice"); |
| 2860 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 2861 | 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] | 2862 | lysp_node_free(st->ctx, siblings); |
| 2863 | siblings = NULL; |
| 2864 | |
| 2865 | /* min subelems */ |
| 2866 | data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END; |
| 2867 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2868 | parsed = (struct lysp_node_case *)siblings; |
| 2869 | assert_string_equal(parsed->name, "case-name"); |
| 2870 | lysp_node_free(st->ctx, siblings); |
| 2871 | siblings = NULL; |
| 2872 | |
| 2873 | st->finished_correctly = true; |
| 2874 | } |
| 2875 | |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2876 | static void |
| 2877 | test_choice_elem(void **state) |
| 2878 | { |
| 2879 | struct state *st = *state; |
| 2880 | const char *data; |
| 2881 | struct lysp_node *siblings = NULL; |
| 2882 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2883 | struct lysp_node_choice *parsed = NULL; |
| 2884 | |
| 2885 | /* max subelems */ |
| 2886 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 2887 | data = ELEMENT_WRAPPER_START |
| 2888 | "<choice name=\"choice-name\">" |
| 2889 | "<anydata name=\"anyd\"/>" |
| 2890 | "<anyxml name=\"anyx\"/>" |
| 2891 | "<case name=\"sub-case\"/>" |
| 2892 | "<choice name=\"choice\"/>" |
| 2893 | "<config value=\"true\"/>" |
| 2894 | "<container name=\"subcont\"/>" |
| 2895 | "<default value=\"def\"/>" |
| 2896 | "<description><text>desc</text></description>" |
| 2897 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2898 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 2899 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2900 | "<list name=\"list\"/>" |
| 2901 | "<mandatory value=\"true\" />" |
| 2902 | "<reference><text>ref</text></reference>" |
| 2903 | "<status value=\"current\"/>" |
| 2904 | "<when condition=\"when-cond\"/>" |
| 2905 | "</choice>" |
| 2906 | ELEMENT_WRAPPER_END; |
| 2907 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2908 | parsed = (struct lysp_node_choice *)siblings; |
| 2909 | assert_string_equal(parsed->name, "choice-name"); |
| 2910 | assert_null(parsed->parent); |
| 2911 | assert_int_equal(parsed->nodetype, LYS_CHOICE); |
| 2912 | assert_true(parsed->flags & LYS_CONFIG_W && parsed->flags & LYS_MAND_TRUE && parsed->flags & LYS_STATUS_CURR); |
| 2913 | assert_null(parsed->next); |
| 2914 | assert_string_equal(parsed->dsc, "desc"); |
| 2915 | assert_string_equal(parsed->ref, "ref"); |
| 2916 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2917 | assert_string_equal(*parsed->iffeatures, "iff"); |
| 2918 | assert_null(parsed->exts); |
| 2919 | assert_string_equal(parsed->child->name, "anyd"); |
| 2920 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 2921 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 2922 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 2923 | assert_string_equal(parsed->child->next->next->name, "sub-case"); |
| 2924 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE); |
| 2925 | assert_string_equal(parsed->child->next->next->next->name, "choice"); |
| 2926 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE); |
| 2927 | assert_string_equal(parsed->child->next->next->next->next->name, "subcont"); |
| 2928 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER); |
| 2929 | assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf"); |
| 2930 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF); |
| 2931 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist"); |
| 2932 | assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2933 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list"); |
| 2934 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 2935 | assert_null(parsed->child->next->next->next->next->next->next->next->next); |
| 2936 | lysp_node_free(st->ctx, siblings); |
| 2937 | siblings = NULL; |
| 2938 | |
| 2939 | /* min subelems */ |
| 2940 | data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END; |
| 2941 | assert_int_equal(test_element_helper(st, &data, &node_meta, NULL, NULL, true), LY_SUCCESS); |
| 2942 | parsed = (struct lysp_node_choice *)siblings; |
| 2943 | assert_string_equal(parsed->name, "choice-name"); |
| 2944 | lysp_node_free(st->ctx, siblings); |
| 2945 | siblings = NULL; |
| 2946 | |
| 2947 | st->finished_correctly = true; |
| 2948 | } |
| 2949 | |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2950 | static void |
| 2951 | test_inout_elem(void **state) |
| 2952 | { |
| 2953 | struct state *st = *state; |
| 2954 | const char *data; |
| 2955 | struct lysp_action_inout inout = {}; |
| 2956 | struct inout_meta inout_meta = {NULL, &inout}; |
| 2957 | |
| 2958 | /* max subelements */ |
| 2959 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 2960 | data = ELEMENT_WRAPPER_START |
| 2961 | "<input>" |
| 2962 | "<anydata name=\"anyd\"/>" |
| 2963 | "<anyxml name=\"anyx\"/>" |
| 2964 | "<choice name=\"choice\"/>" |
| 2965 | "<container name=\"subcont\"/>" |
| 2966 | "<grouping name=\"sub-grp\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2967 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 2968 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2969 | "<list name=\"list\"/>" |
| 2970 | "<must condition=\"cond\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2971 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2972 | "<uses name=\"uses-name\"/>" |
| 2973 | "</input>" |
| 2974 | ELEMENT_WRAPPER_END; |
| 2975 | assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS); |
| 2976 | assert_null(inout.parent); |
| 2977 | assert_int_equal(inout.nodetype, LYS_INPUT); |
| 2978 | assert_string_equal(inout.musts->arg, "cond"); |
| 2979 | assert_string_equal(inout.typedefs->name, "tpdf"); |
| 2980 | assert_string_equal(inout.groupings->name, "sub-grp"); |
| 2981 | assert_string_equal(inout.data->name, "anyd"); |
| 2982 | assert_int_equal(inout.data->nodetype, LYS_ANYDATA); |
| 2983 | assert_string_equal(inout.data->next->name, "anyx"); |
| 2984 | assert_int_equal(inout.data->next->nodetype, LYS_ANYXML); |
| 2985 | assert_string_equal(inout.data->next->next->name, "choice"); |
| 2986 | assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE); |
| 2987 | assert_string_equal(inout.data->next->next->next->name, "subcont"); |
| 2988 | assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER); |
| 2989 | assert_string_equal(inout.data->next->next->next->next->name, "leaf"); |
| 2990 | assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF); |
| 2991 | assert_string_equal(inout.data->next->next->next->next->next->name, "llist"); |
| 2992 | assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2993 | assert_string_equal(inout.data->next->next->next->next->next->next->name, "list"); |
| 2994 | assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 2995 | assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name"); |
| 2996 | assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 2997 | assert_null(inout.data->next->next->next->next->next->next->next->next); |
| 2998 | lysp_action_inout_free(st->ctx, &inout); |
| 2999 | memset(&inout, 0, sizeof inout); |
| 3000 | |
| 3001 | /* max subelements */ |
| 3002 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3003 | data = ELEMENT_WRAPPER_START |
| 3004 | "<output>" |
| 3005 | "<anydata name=\"anyd\"/>" |
| 3006 | "<anyxml name=\"anyx\"/>" |
| 3007 | "<choice name=\"choice\"/>" |
| 3008 | "<container name=\"subcont\"/>" |
| 3009 | "<grouping name=\"sub-grp\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3010 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3011 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3012 | "<list name=\"list\"/>" |
| 3013 | "<must condition=\"cond\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3014 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3015 | "<uses name=\"uses-name\"/>" |
| 3016 | "</output>" |
| 3017 | ELEMENT_WRAPPER_END; |
| 3018 | assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS); |
| 3019 | assert_null(inout.parent); |
| 3020 | assert_int_equal(inout.nodetype, LYS_OUTPUT); |
| 3021 | assert_string_equal(inout.musts->arg, "cond"); |
| 3022 | assert_string_equal(inout.typedefs->name, "tpdf"); |
| 3023 | assert_string_equal(inout.groupings->name, "sub-grp"); |
| 3024 | assert_string_equal(inout.data->name, "anyd"); |
| 3025 | assert_int_equal(inout.data->nodetype, LYS_ANYDATA); |
| 3026 | assert_string_equal(inout.data->next->name, "anyx"); |
| 3027 | assert_int_equal(inout.data->next->nodetype, LYS_ANYXML); |
| 3028 | assert_string_equal(inout.data->next->next->name, "choice"); |
| 3029 | assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE); |
| 3030 | assert_string_equal(inout.data->next->next->next->name, "subcont"); |
| 3031 | assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER); |
| 3032 | assert_string_equal(inout.data->next->next->next->next->name, "leaf"); |
| 3033 | assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF); |
| 3034 | assert_string_equal(inout.data->next->next->next->next->next->name, "llist"); |
| 3035 | assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3036 | assert_string_equal(inout.data->next->next->next->next->next->next->name, "list"); |
| 3037 | assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3038 | assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name"); |
| 3039 | assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3040 | assert_null(inout.data->next->next->next->next->next->next->next->next); |
| 3041 | lysp_action_inout_free(st->ctx, &inout); |
| 3042 | memset(&inout, 0, sizeof inout); |
| 3043 | |
| 3044 | /* min subelems */ |
| 3045 | data = ELEMENT_WRAPPER_START "<input />" ELEMENT_WRAPPER_END; |
| 3046 | assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS); |
| 3047 | memset(&inout, 0, sizeof inout); |
| 3048 | |
| 3049 | data = ELEMENT_WRAPPER_START "<output />" ELEMENT_WRAPPER_END; |
| 3050 | assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, true), LY_SUCCESS); |
| 3051 | memset(&inout, 0, sizeof inout); |
| 3052 | |
| 3053 | /* invalid combinations */ |
| 3054 | data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END; |
| 3055 | assert_int_equal(test_element_helper(st, &data, &inout_meta, NULL, NULL, false), LY_EVALID); |
| 3056 | logbuf_assert("Unexpected attribute \"name\" of input element. Line number 1."); |
| 3057 | memset(&inout, 0, sizeof inout); |
| 3058 | |
| 3059 | st->finished_correctly = true; |
| 3060 | } |
| 3061 | |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3062 | static void |
| 3063 | test_action_elem(void **state) |
| 3064 | { |
| 3065 | struct state *st = *state; |
| 3066 | const char *data; |
| 3067 | struct lysp_action *actions = NULL; |
| 3068 | struct action_meta act_meta = {NULL, &actions}; |
| 3069 | |
| 3070 | /* max subelems */ |
| 3071 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3072 | data = ELEMENT_WRAPPER_START |
| 3073 | "<action name=\"act\">" |
| 3074 | "<description><text>desc</text></description>" |
| 3075 | "<grouping name=\"grouping\"/>" |
| 3076 | "<if-feature name=\"iff\"/>" |
| 3077 | "<input><uses name=\"uses-name\"/></input>" |
| 3078 | "<output><must condition=\"cond\"/></output>" |
| 3079 | "<reference><text>ref</text></reference>" |
| 3080 | "<status value=\"deprecated\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3081 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3082 | "</action>" |
| 3083 | ELEMENT_WRAPPER_END; |
| 3084 | assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS); |
| 3085 | assert_null(actions->parent); |
| 3086 | assert_int_equal(actions->nodetype, LYS_ACTION); |
| 3087 | assert_true(actions->flags & LYS_STATUS_DEPRC); |
| 3088 | assert_string_equal(actions->name, "act"); |
| 3089 | assert_string_equal(actions->dsc, "desc"); |
| 3090 | assert_string_equal(actions->ref, "ref"); |
| 3091 | assert_string_equal(*actions->iffeatures, "iff"); |
| 3092 | assert_string_equal(actions->typedefs->name, "tpdf"); |
| 3093 | assert_string_equal(actions->groupings->name, "grouping"); |
| 3094 | assert_string_equal(actions->input.data->name, "uses-name"); |
| 3095 | assert_string_equal(actions->output.musts->arg, "cond"); |
| 3096 | assert_null(actions->exts); |
| 3097 | FREE_ARRAY(st->ctx, actions, lysp_action_free) |
| 3098 | actions = NULL; |
| 3099 | |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3100 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3101 | data = ELEMENT_WRAPPER_START |
| 3102 | "<rpc name=\"act\">" |
| 3103 | "<description><text>desc</text></description>" |
| 3104 | "<grouping name=\"grouping\"/>" |
| 3105 | "<if-feature name=\"iff\"/>" |
| 3106 | "<input><uses name=\"uses-name\"/></input>" |
| 3107 | "<output><must condition=\"cond\"/></output>" |
| 3108 | "<reference><text>ref</text></reference>" |
| 3109 | "<status value=\"deprecated\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3110 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3111 | "</rpc>" |
| 3112 | ELEMENT_WRAPPER_END; |
| 3113 | assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS); |
| 3114 | assert_null(actions->parent); |
| 3115 | assert_int_equal(actions->nodetype, LYS_ACTION); |
| 3116 | assert_true(actions->flags & LYS_STATUS_DEPRC); |
| 3117 | assert_string_equal(actions->name, "act"); |
| 3118 | assert_string_equal(actions->dsc, "desc"); |
| 3119 | assert_string_equal(actions->ref, "ref"); |
| 3120 | assert_string_equal(*actions->iffeatures, "iff"); |
| 3121 | assert_string_equal(actions->typedefs->name, "tpdf"); |
| 3122 | assert_string_equal(actions->groupings->name, "grouping"); |
| 3123 | assert_string_equal(actions->input.data->name, "uses-name"); |
| 3124 | assert_string_equal(actions->output.musts->arg, "cond"); |
| 3125 | assert_null(actions->exts); |
| 3126 | FREE_ARRAY(st->ctx, actions, lysp_action_free) |
| 3127 | actions = NULL; |
| 3128 | |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3129 | /* min subelems */ |
| 3130 | data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END; |
| 3131 | assert_int_equal(test_element_helper(st, &data, &act_meta, NULL, NULL, true), LY_SUCCESS); |
| 3132 | assert_string_equal(actions->name, "act"); |
| 3133 | FREE_ARRAY(st->ctx, actions, lysp_action_free) |
| 3134 | actions = NULL; |
| 3135 | |
| 3136 | st->finished_correctly = true; |
| 3137 | } |
| 3138 | |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3139 | static void |
| 3140 | test_augment_elem(void **state) |
| 3141 | { |
| 3142 | struct state *st = *state; |
| 3143 | const char *data; |
| 3144 | struct lysp_augment *augments = NULL; |
| 3145 | struct augment_meta aug_meta = {NULL, &augments}; |
| 3146 | |
| 3147 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3148 | data = ELEMENT_WRAPPER_START |
| 3149 | "<augment target-node=\"target\">" |
| 3150 | "<action name=\"action\"/>" |
| 3151 | "<anydata name=\"anyd\"/>" |
| 3152 | "<anyxml name=\"anyx\"/>" |
| 3153 | "<case name=\"case\"/>" |
| 3154 | "<choice name=\"choice\"/>" |
| 3155 | "<container name=\"subcont\"/>" |
| 3156 | "<description><text>desc</text></description>" |
| 3157 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3158 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3159 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3160 | "<list name=\"list\"/>" |
| 3161 | "<notification name=\"notif\"/>" |
| 3162 | "<reference><text>ref</text></reference>" |
| 3163 | "<status value=\"current\"/>" |
| 3164 | "<uses name=\"uses\"/>" |
| 3165 | "<when condition=\"when-cond\"/>" |
| 3166 | "</augment>" |
| 3167 | ELEMENT_WRAPPER_END; |
| 3168 | assert_int_equal(test_element_helper(st, &data, &aug_meta, NULL, NULL, true), LY_SUCCESS); |
| 3169 | assert_string_equal(augments->nodeid, "target"); |
| 3170 | assert_null(augments->parent); |
| 3171 | assert_int_equal(augments->nodetype, LYS_AUGMENT); |
| 3172 | assert_true(augments->flags & LYS_STATUS_CURR); |
| 3173 | assert_string_equal(augments->dsc, "desc"); |
| 3174 | assert_string_equal(augments->ref, "ref"); |
| 3175 | assert_string_equal(augments->when->cond, "when-cond"); |
| 3176 | assert_string_equal(*augments->iffeatures, "iff"); |
| 3177 | assert_string_equal(augments->child->name, "anyd"); |
| 3178 | assert_int_equal(augments->child->nodetype, LYS_ANYDATA); |
| 3179 | assert_string_equal(augments->child->next->name, "anyx"); |
| 3180 | assert_int_equal(augments->child->next->nodetype, LYS_ANYXML); |
| 3181 | assert_string_equal(augments->child->next->next->name, "case"); |
| 3182 | assert_int_equal(augments->child->next->next->nodetype, LYS_CASE); |
| 3183 | assert_string_equal(augments->child->next->next->next->name, "choice"); |
| 3184 | assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE); |
| 3185 | assert_string_equal(augments->child->next->next->next->next->name, "subcont"); |
| 3186 | assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER); |
| 3187 | assert_string_equal(augments->child->next->next->next->next->next->name, "leaf"); |
| 3188 | assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF); |
| 3189 | assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist"); |
| 3190 | assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3191 | assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list"); |
| 3192 | assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3193 | assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses"); |
| 3194 | assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3195 | assert_null(augments->child->next->next->next->next->next->next->next->next->next); |
| 3196 | assert_string_equal(augments->actions->name, "action"); |
| 3197 | assert_string_equal(augments->notifs->name, "notif"); |
| 3198 | assert_null(augments->exts); |
| 3199 | FREE_ARRAY(st->ctx, augments, lysp_augment_free) |
| 3200 | augments = NULL; |
| 3201 | |
| 3202 | data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END; |
| 3203 | assert_int_equal(test_element_helper(st, &data, &aug_meta, NULL, NULL, true), LY_SUCCESS); |
| 3204 | assert_string_equal(augments->nodeid, "target"); |
| 3205 | FREE_ARRAY(st->ctx, augments, lysp_augment_free) |
| 3206 | augments = NULL; |
| 3207 | |
| 3208 | st->finished_correctly = true; |
| 3209 | } |
| 3210 | |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3211 | static void |
| 3212 | test_deviate_elem(void **state) |
| 3213 | { |
| 3214 | struct state *st = *state; |
| 3215 | const char *data; |
| 3216 | struct lysp_deviate *deviates = NULL; |
| 3217 | struct lysp_deviate_add *d_add; |
| 3218 | struct lysp_deviate_rpl *d_rpl; |
| 3219 | struct lysp_deviate_del *d_del; |
| 3220 | |
| 3221 | /* all valid arguments with min subelems */ |
| 3222 | data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END; |
| 3223 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3224 | assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED); |
| 3225 | lysp_deviate_free(st->ctx, deviates); |
| 3226 | free(deviates); |
| 3227 | deviates = NULL; |
| 3228 | |
| 3229 | data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END; |
| 3230 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3231 | assert_int_equal(deviates->mod, LYS_DEV_ADD); |
| 3232 | lysp_deviate_free(st->ctx, deviates); |
| 3233 | free(deviates); |
| 3234 | deviates = NULL; |
| 3235 | |
| 3236 | data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END; |
| 3237 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3238 | assert_int_equal(deviates->mod, LYS_DEV_REPLACE); |
| 3239 | lysp_deviate_free(st->ctx, deviates); |
| 3240 | free(deviates); |
| 3241 | deviates = NULL; |
| 3242 | |
| 3243 | data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END; |
| 3244 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3245 | assert_int_equal(deviates->mod, LYS_DEV_DELETE); |
| 3246 | lysp_deviate_free(st->ctx, deviates); |
| 3247 | free(deviates); |
| 3248 | deviates = NULL; |
| 3249 | |
| 3250 | /* max subelems and valid arguments */ |
| 3251 | data = ELEMENT_WRAPPER_START |
| 3252 | "<deviate value=\"not-supported\">" |
| 3253 | "</deviate>" |
| 3254 | 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_NOT_SUPPORTED); |
| 3257 | lysp_deviate_free(st->ctx, deviates); |
| 3258 | free(deviates); |
| 3259 | deviates = NULL; |
| 3260 | |
| 3261 | data = ELEMENT_WRAPPER_START |
| 3262 | "<deviate value=\"add\">" |
| 3263 | "<units name=\"units\"/>" |
| 3264 | "<must condition=\"cond\"/>" |
| 3265 | "<unique tag=\"utag\"/>" |
| 3266 | "<default value=\"def\"/>" |
| 3267 | "<config value=\"true\"/>" |
| 3268 | "<mandatory value=\"true\"/>" |
| 3269 | "<min-elements value=\"5\"/>" |
| 3270 | "<max-elements value=\"15\"/>" |
| 3271 | "</deviate>" |
| 3272 | ELEMENT_WRAPPER_END; |
| 3273 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3274 | d_add = (struct lysp_deviate_add *)deviates; |
| 3275 | assert_int_equal(d_add->mod, LYS_DEV_ADD); |
| 3276 | assert_null(d_add->next); |
| 3277 | assert_null(d_add->exts); |
| 3278 | assert_string_equal(d_add->units, "units"); |
| 3279 | assert_string_equal(d_add->musts->arg, "cond"); |
| 3280 | assert_string_equal(*d_add->uniques, "utag"); |
| 3281 | assert_string_equal(*d_add->dflts, "def"); |
| 3282 | assert_true(d_add->flags & LYS_MAND_TRUE && d_add->flags & LYS_CONFIG_W); |
| 3283 | assert_int_equal(d_add->min, 5); |
| 3284 | assert_int_equal(d_add->max, 15); |
| 3285 | lysp_deviate_free(st->ctx, deviates); |
| 3286 | free(deviates); |
| 3287 | deviates = NULL; |
| 3288 | |
| 3289 | data = ELEMENT_WRAPPER_START |
| 3290 | "<deviate value=\"replace\">" |
| 3291 | "<type name=\"newtype\"/>" |
| 3292 | "<units name=\"uni\"/>" |
| 3293 | "<default value=\"def\"/>" |
| 3294 | "<config value=\"true\"/>" |
| 3295 | "<mandatory value=\"true\"/>" |
| 3296 | "<min-elements value=\"5\"/>" |
| 3297 | "<max-elements value=\"15\"/>" |
| 3298 | "</deviate>" |
| 3299 | ELEMENT_WRAPPER_END; |
| 3300 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3301 | d_rpl = (struct lysp_deviate_rpl *)deviates; |
| 3302 | assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE); |
| 3303 | assert_null(d_rpl->next); |
| 3304 | assert_null(d_rpl->exts); |
| 3305 | assert_string_equal(d_rpl->type->name, "newtype"); |
| 3306 | assert_string_equal(d_rpl->units, "uni"); |
| 3307 | assert_string_equal(d_rpl->dflt, "def"); |
| 3308 | assert_true(d_rpl->flags & LYS_MAND_TRUE && d_rpl->flags & LYS_CONFIG_W); |
| 3309 | assert_int_equal(d_rpl->min, 5); |
| 3310 | assert_int_equal(d_rpl->max, 15); |
| 3311 | lysp_deviate_free(st->ctx, deviates); |
| 3312 | free(deviates); |
| 3313 | deviates = NULL; |
| 3314 | |
| 3315 | data = ELEMENT_WRAPPER_START |
| 3316 | "<deviate value=\"delete\">" |
| 3317 | "<units name=\"u\"/>" |
| 3318 | "<must condition=\"c\"/>" |
| 3319 | "<unique tag=\"tag\"/>" |
| 3320 | "<default value=\"default\"/>" |
| 3321 | "</deviate>" |
| 3322 | ELEMENT_WRAPPER_END; |
| 3323 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, true), LY_SUCCESS); |
| 3324 | d_del = (struct lysp_deviate_del *)deviates; |
| 3325 | assert_int_equal(d_del->mod, LYS_DEV_DELETE); |
| 3326 | assert_null(d_del->next); |
| 3327 | assert_null(d_del->exts); |
| 3328 | assert_string_equal(d_del->units, "u"); |
| 3329 | assert_string_equal(d_del->musts->arg, "c"); |
| 3330 | assert_string_equal(*d_del->uniques, "tag"); |
| 3331 | assert_string_equal(*d_del->dflts, "default"); |
| 3332 | lysp_deviate_free(st->ctx, deviates); |
| 3333 | free(deviates); |
| 3334 | deviates = NULL; |
| 3335 | |
| 3336 | /* invalid arguments */ |
| 3337 | data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END; |
| 3338 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID); |
| 3339 | logbuf_assert("Invalid value \"\" of \"deviate\". Line number 1."); |
| 3340 | deviates = NULL; |
| 3341 | |
| 3342 | data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END; |
| 3343 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID); |
| 3344 | logbuf_assert("Invalid value \"invalid\" of \"deviate\". Line number 1."); |
| 3345 | deviates = NULL; |
| 3346 | |
| 3347 | data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END; |
| 3348 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID); |
| 3349 | logbuf_assert("Invalid value \"ad\" of \"deviate\". Line number 1."); |
| 3350 | deviates = NULL; |
| 3351 | |
| 3352 | data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END; |
| 3353 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID); |
| 3354 | logbuf_assert("Invalid value \"adds\" of \"deviate\". Line number 1."); |
| 3355 | deviates = NULL; |
| 3356 | |
| 3357 | data = ELEMENT_WRAPPER_START |
| 3358 | "<deviate value=\"not-supported\">" |
| 3359 | "<must condition=\"c\"/>" |
| 3360 | "</deviate>" |
| 3361 | ELEMENT_WRAPPER_END; |
| 3362 | assert_int_equal(test_element_helper(st, &data, &deviates, NULL, NULL, false), LY_EVALID); |
| 3363 | logbuf_assert("Deviate of this type doesn't allow \"must\" as it's sub-element. Line number 1."); |
| 3364 | |
| 3365 | st->finished_correctly = true; |
| 3366 | } |
| 3367 | |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3368 | static void |
| 3369 | test_deviation_elem(void **state) |
| 3370 | { |
| 3371 | struct state *st = *state; |
| 3372 | const char *data; |
| 3373 | struct lysp_deviation *deviations = NULL; |
| 3374 | |
| 3375 | /* min subelems */ |
| 3376 | data = ELEMENT_WRAPPER_START |
| 3377 | "<deviation target-node=\"target\">" |
| 3378 | "<deviate value=\"not-supported\"/>" |
| 3379 | "</deviation>" |
| 3380 | ELEMENT_WRAPPER_END; |
| 3381 | assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, true), LY_SUCCESS); |
| 3382 | assert_string_equal(deviations->nodeid, "target"); |
| 3383 | assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED); |
| 3384 | FREE_ARRAY(st->ctx, deviations, lysp_deviation_free); |
| 3385 | deviations = NULL; |
| 3386 | |
| 3387 | /* max subelems */ |
| 3388 | data = ELEMENT_WRAPPER_START |
| 3389 | "<deviation target-node=\"target\">" |
| 3390 | "<reference><text>ref</text></reference>" |
| 3391 | "<description><text>desc</text></description>" |
| 3392 | "<deviate value=\"add\"/>" |
| 3393 | "</deviation>" |
| 3394 | ELEMENT_WRAPPER_END; |
| 3395 | assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, true), LY_SUCCESS); |
| 3396 | assert_string_equal(deviations->nodeid, "target"); |
| 3397 | assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD); |
| 3398 | assert_string_equal(deviations->ref, "ref"); |
| 3399 | assert_string_equal(deviations->dsc, "desc"); |
| 3400 | FREE_ARRAY(st->ctx, deviations, lysp_deviation_free); |
| 3401 | deviations = NULL; |
| 3402 | |
| 3403 | /* invalid */ |
| 3404 | data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END; |
| 3405 | assert_int_equal(test_element_helper(st, &data, &deviations, NULL, NULL, false), LY_EVALID); |
| 3406 | FREE_ARRAY(st->ctx, deviations, lysp_deviation_free); |
| 3407 | deviations = NULL; |
| 3408 | logbuf_assert("Missing mandatory subelement deviate of deviate element. Line number 1."); |
| 3409 | |
| 3410 | st->finished_correctly = true; |
| 3411 | } |
| 3412 | |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3413 | static void |
| 3414 | test_module_elem(void **state) |
| 3415 | { |
| 3416 | struct state *st = *state; |
| 3417 | const char *data; |
| 3418 | struct yin_arg_record *attrs = NULL; |
| 3419 | struct sized_string name, prefix; |
| 3420 | struct lys_module *lys_mod = NULL; |
| 3421 | struct lysp_module *lysp_mod = NULL; |
| 3422 | |
| 3423 | /* max subelems */ |
| 3424 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 3425 | lys_mod = calloc(1, sizeof *lys_mod); |
| 3426 | lysp_mod = calloc(1, sizeof *lysp_mod); |
| 3427 | lys_mod->ctx = st->ctx; |
| 3428 | lysp_mod->mod = lys_mod; |
| 3429 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
| 3430 | "<yang-version value=\"1.1\"/>\n" |
| 3431 | "<namespace uri=\"ns\"/>\n" |
| 3432 | "<prefix value=\"pref\"/>\n" |
| 3433 | "<include module=\"b-mod\"/>\n" |
| 3434 | "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n" |
| 3435 | "<organization><text>org</text></organization>\n" |
| 3436 | "<contact><text>contact</text></contact>\n" |
| 3437 | "<description><text>desc</text></description>" |
| 3438 | "<reference><text>ref</text></reference>\n" |
| 3439 | "<revision date=\"2019-02-02\"/>\n" |
| 3440 | "<anydata name=\"anyd\"/>\n" |
| 3441 | "<anyxml name=\"anyx\"/>\n" |
| 3442 | "<choice name=\"choice\"/>\n" |
| 3443 | "<container name=\"cont\"/>\n" |
| 3444 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 3445 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 3446 | "<list name=\"sub-list\"/>\n" |
| 3447 | "<uses name=\"uses-name\"/>\n" |
| 3448 | "<augment target-node=\"target\"/>\n" |
| 3449 | "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n" |
| 3450 | "<extension name=\"ext\"/>\n" |
| 3451 | "<feature name=\"feature\"/>\n" |
| 3452 | "<grouping name=\"grp\"/>\n" |
| 3453 | "<identity name=\"ident-name\"/>\n" |
| 3454 | "<notification name=\"notf\"/>\n" |
| 3455 | "<rpc name=\"rpc-name\"/>\n" |
| 3456 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 3457 | "</module>\n"; |
| 3458 | assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len), LY_SUCCESS); |
| 3459 | assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS); |
| 3460 | assert_int_equal(yin_parse_mod(st->yin_ctx, attrs, &data, lysp_mod), LY_SUCCESS); |
| 3461 | assert_string_equal(lysp_mod->mod->name, "mod"); |
| 3462 | assert_string_equal(lysp_mod->revs, "2019-02-02"); |
| 3463 | assert_string_equal(lysp_mod->mod->ns, "ns"); |
| 3464 | assert_string_equal(lysp_mod->mod->prefix, "pref"); |
| 3465 | assert_null(lysp_mod->mod->filepath); |
| 3466 | assert_string_equal(lysp_mod->mod->org, "org"); |
| 3467 | assert_string_equal(lysp_mod->mod->contact, "contact"); |
| 3468 | assert_string_equal(lysp_mod->mod->dsc, "desc"); |
| 3469 | assert_string_equal(lysp_mod->mod->ref, "ref"); |
| 3470 | assert_int_equal(lysp_mod->mod->version, LYS_VERSION_1_1); |
| 3471 | assert_string_equal(lysp_mod->imports->name, "a-mod"); |
| 3472 | assert_string_equal(lysp_mod->includes->name, "b-mod"); |
| 3473 | assert_string_equal(lysp_mod->extensions->name, "ext"); |
| 3474 | assert_string_equal(lysp_mod->features->name, "feature"); |
| 3475 | assert_string_equal(lysp_mod->identities->name, "ident-name"); |
| 3476 | assert_string_equal(lysp_mod->typedefs->name, "tpdf"); |
| 3477 | assert_string_equal(lysp_mod->groupings->name, "grp"); |
| 3478 | assert_string_equal(lysp_mod->data->name, "anyd"); |
| 3479 | assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA); |
| 3480 | assert_string_equal(lysp_mod->data->next->name, "anyx"); |
| 3481 | assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML); |
| 3482 | assert_string_equal(lysp_mod->data->next->next->name, "choice"); |
| 3483 | assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE); |
| 3484 | assert_string_equal(lysp_mod->data->next->next->next->name, "cont"); |
| 3485 | assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER); |
| 3486 | assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf"); |
| 3487 | assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF); |
| 3488 | assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist"); |
| 3489 | assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3490 | assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list"); |
| 3491 | assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3492 | assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name"); |
| 3493 | assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3494 | assert_null(lysp_mod->data->next->next->next->next->next->next->next->next); |
| 3495 | assert_string_equal(lysp_mod->augments->nodeid, "target"); |
| 3496 | assert_string_equal(lysp_mod->rpcs->name, "rpc-name"); |
| 3497 | assert_string_equal(lysp_mod->notifs->name, "notf"); |
| 3498 | assert_string_equal(lysp_mod->deviations->nodeid, "target"); |
| 3499 | assert_null(lysp_mod->exts); |
| 3500 | lysp_module_free(lysp_mod); |
| 3501 | lys_module_free(lys_mod, NULL); |
| 3502 | FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec); |
| 3503 | attrs = NULL; |
| 3504 | |
| 3505 | /* min subelems */ |
| 3506 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 3507 | lys_mod = calloc(1, sizeof *lys_mod); |
| 3508 | lysp_mod = calloc(1, sizeof *lysp_mod); |
| 3509 | lys_mod->ctx = st->ctx; |
| 3510 | lysp_mod->mod = lys_mod; |
| 3511 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">" |
| 3512 | "<namespace uri=\"ns\"/>" |
| 3513 | "<prefix value=\"pref\"/>" |
| 3514 | "<yang-version value=\"1.1\"/>" |
| 3515 | "</module>"; |
| 3516 | assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len), LY_SUCCESS); |
| 3517 | assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS); |
| 3518 | 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] | 3519 | assert_string_equal(lysp_mod->mod->name, "mod"); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3520 | lysp_module_free(lysp_mod); |
| 3521 | lys_module_free(lys_mod, NULL); |
| 3522 | FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec); |
| 3523 | attrs = NULL; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3524 | |
| 3525 | st->finished_correctly = true; |
| 3526 | } |
| 3527 | |
| 3528 | static void |
| 3529 | test_submodule_elem(void **state) |
| 3530 | { |
| 3531 | struct state *st = *state; |
| 3532 | const char *data; |
| 3533 | struct yin_arg_record *attrs = NULL; |
| 3534 | struct sized_string name, prefix; |
| 3535 | struct lysp_submodule *lysp_submod = NULL; |
| 3536 | |
| 3537 | /* max subelements */ |
| 3538 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 3539 | lysp_submod = calloc(1, sizeof *lysp_submod); |
| 3540 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
| 3541 | "<yang-version value=\"1.1\"/>\n" |
| 3542 | "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>" |
| 3543 | "<include module=\"b-mod\"/>\n" |
| 3544 | "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n" |
| 3545 | "<organization><text>org</text></organization>\n" |
| 3546 | "<contact><text>contact</text></contact>\n" |
| 3547 | "<description><text>desc</text></description>" |
| 3548 | "<reference><text>ref</text></reference>\n" |
| 3549 | "<revision date=\"2019-02-02\"/>\n" |
| 3550 | "<anydata name=\"anyd\"/>\n" |
| 3551 | "<anyxml name=\"anyx\"/>\n" |
| 3552 | "<choice name=\"choice\"/>\n" |
| 3553 | "<container name=\"cont\"/>\n" |
| 3554 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 3555 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 3556 | "<list name=\"sub-list\"/>\n" |
| 3557 | "<uses name=\"uses-name\"/>\n" |
| 3558 | "<augment target-node=\"target\"/>\n" |
| 3559 | "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n" |
| 3560 | "<extension name=\"ext\"/>\n" |
| 3561 | "<feature name=\"feature\"/>\n" |
| 3562 | "<grouping name=\"grp\"/>\n" |
| 3563 | "<identity name=\"ident-name\"/>\n" |
| 3564 | "<notification name=\"notf\"/>\n" |
| 3565 | "<rpc name=\"rpc-name\"/>\n" |
| 3566 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 3567 | "</submodule>\n"; |
| 3568 | assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len), LY_SUCCESS); |
| 3569 | assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS); |
| 3570 | assert_int_equal(yin_parse_submod(st->yin_ctx, attrs, &data, lysp_submod), LY_SUCCESS); |
| 3571 | |
| 3572 | assert_string_equal(lysp_submod->name, "mod"); |
| 3573 | assert_string_equal(lysp_submod->revs, "2019-02-02"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3574 | assert_string_equal(lysp_submod->prefix, "pref"); |
| 3575 | assert_null(lysp_submod->filepath); |
| 3576 | assert_string_equal(lysp_submod->org, "org"); |
| 3577 | assert_string_equal(lysp_submod->contact, "contact"); |
| 3578 | assert_string_equal(lysp_submod->dsc, "desc"); |
| 3579 | assert_string_equal(lysp_submod->ref, "ref"); |
| 3580 | assert_int_equal(lysp_submod->version, LYS_VERSION_1_1); |
| 3581 | assert_string_equal(lysp_submod->imports->name, "a-mod"); |
| 3582 | assert_string_equal(lysp_submod->includes->name, "b-mod"); |
| 3583 | assert_string_equal(lysp_submod->extensions->name, "ext"); |
| 3584 | assert_string_equal(lysp_submod->features->name, "feature"); |
| 3585 | assert_string_equal(lysp_submod->identities->name, "ident-name"); |
| 3586 | assert_string_equal(lysp_submod->typedefs->name, "tpdf"); |
| 3587 | assert_string_equal(lysp_submod->groupings->name, "grp"); |
| 3588 | assert_string_equal(lysp_submod->data->name, "anyd"); |
| 3589 | assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA); |
| 3590 | assert_string_equal(lysp_submod->data->next->name, "anyx"); |
| 3591 | assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML); |
| 3592 | assert_string_equal(lysp_submod->data->next->next->name, "choice"); |
| 3593 | assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE); |
| 3594 | assert_string_equal(lysp_submod->data->next->next->next->name, "cont"); |
| 3595 | assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER); |
| 3596 | assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf"); |
| 3597 | assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF); |
| 3598 | assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist"); |
| 3599 | assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3600 | assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list"); |
| 3601 | assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3602 | assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name"); |
| 3603 | assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3604 | assert_null(lysp_submod->data->next->next->next->next->next->next->next->next); |
| 3605 | assert_string_equal(lysp_submod->augments->nodeid, "target"); |
| 3606 | assert_string_equal(lysp_submod->rpcs->name, "rpc-name"); |
| 3607 | assert_string_equal(lysp_submod->notifs->name, "notf"); |
| 3608 | assert_string_equal(lysp_submod->deviations->nodeid, "target"); |
| 3609 | assert_null(lysp_submod->exts); |
| 3610 | |
| 3611 | lysp_submodule_free(st->ctx, lysp_submod); |
| 3612 | FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec); |
| 3613 | attrs = NULL; |
| 3614 | |
| 3615 | /* min subelemnts */ |
| 3616 | st->yin_ctx->xml_ctx.status = LYXML_ELEMENT; |
| 3617 | lysp_submod = calloc(1, sizeof *lysp_submod); |
| 3618 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">" |
| 3619 | "<yang-version value=\"1.0\"/>" |
| 3620 | "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>" |
| 3621 | "</submodule>"; |
| 3622 | assert_int_equal(lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len), LY_SUCCESS); |
| 3623 | assert_int_equal(yin_load_attributes(st->yin_ctx, &data, &attrs), LY_SUCCESS); |
| 3624 | assert_int_equal(yin_parse_submod(st->yin_ctx, attrs, &data, lysp_submod), LY_SUCCESS); |
| 3625 | assert_string_equal(lysp_submod->prefix, "pref"); |
| 3626 | assert_string_equal(lysp_submod->belongsto, "mod-name"); |
| 3627 | assert_int_equal(lysp_submod->version, LYS_VERSION_1_0); |
| 3628 | lysp_submodule_free(st->ctx, lysp_submod); |
| 3629 | FREE_ARRAY(st->yin_ctx, attrs, free_arg_rec); |
| 3630 | attrs = NULL; |
| 3631 | |
| 3632 | st->finished_correctly = true; |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3633 | } |
| 3634 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame^] | 3635 | static void |
| 3636 | test_yin_parse_module(void **state) |
| 3637 | { |
| 3638 | struct state *st = *state; |
| 3639 | const char *data; |
| 3640 | struct lys_module *mod; |
| 3641 | struct yin_parser_ctx *yin_ctx = NULL; |
| 3642 | |
| 3643 | mod = calloc(1, sizeof *mod); |
| 3644 | mod->ctx = st->ctx; |
| 3645 | data = "<module name=\"example-foo\"" |
| 3646 | "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"" |
| 3647 | "xmlns:foo=\"urn:example:foo\"" |
| 3648 | "xmlns:myext=\"urn:example:extensions\">\n" |
| 3649 | |
| 3650 | "<yang-version value=\"1.0\"/>\n" |
| 3651 | |
| 3652 | "<namespace uri=\"urn:example:foo\"/>\n" |
| 3653 | "<prefix value=\"foo\"/>\n" |
| 3654 | |
| 3655 | "<import module=\"example-extensions\">\n" |
| 3656 | "<prefix value=\"myext\"/>\n" |
| 3657 | "</import>\n" |
| 3658 | |
| 3659 | "<list name=\"interface\">\n" |
| 3660 | "<key value=\"name\"/>\n" |
| 3661 | "<leaf name=\"name\">\n" |
| 3662 | "<type name=\"string\"/>\n" |
| 3663 | "</leaf>\n" |
| 3664 | "<leaf name=\"mtu\">\n" |
| 3665 | "<type name=\"uint32\"/>\n" |
| 3666 | "<description>\n" |
| 3667 | "<text>The MTU of the interface.</text>\n" |
| 3668 | "</description>\n" |
| 3669 | "<myext:c-define name=\"MY_MTU\"/>\n" |
| 3670 | "</leaf>\n" |
| 3671 | "</list>\n" |
| 3672 | "</module>\n"; |
| 3673 | assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS); |
| 3674 | lys_module_free(mod, NULL); |
| 3675 | yin_parser_ctx_free(yin_ctx); |
| 3676 | mod = NULL; |
| 3677 | yin_ctx = NULL; |
| 3678 | |
| 3679 | mod = calloc(1, sizeof *mod); |
| 3680 | mod->ctx = st->ctx; |
| 3681 | data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 3682 | "</submodule>\n"; |
| 3683 | assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EINVAL); |
| 3684 | logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module."); |
| 3685 | lys_module_free(mod, NULL); |
| 3686 | yin_parser_ctx_free(yin_ctx); |
| 3687 | |
| 3688 | st->finished_correctly = true; |
| 3689 | } |
| 3690 | |
| 3691 | static void |
| 3692 | test_yin_parse_submodule(void **state) |
| 3693 | { |
| 3694 | struct state *st = *state; |
| 3695 | const char *data; |
| 3696 | struct yin_parser_ctx *yin_ctx = NULL; |
| 3697 | struct lysp_submodule *submod = NULL; |
| 3698 | |
| 3699 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 3700 | "<submodule name=\"asub\"" |
| 3701 | "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"" |
| 3702 | "xmlns:a=\"urn:a\">" |
| 3703 | "<yang-version value=\"1.0\"/>\n" |
| 3704 | "<belongs-to module=\"a\">" |
| 3705 | "<prefix value=\"a_pref\"/>" |
| 3706 | "</belongs-to>" |
| 3707 | "<include module=\"atop\"/>" |
| 3708 | "<feature name=\"fox\"/>" |
| 3709 | "<notification name=\"bar-notif\">" |
| 3710 | "<if-feature name=\"bar\"/>" |
| 3711 | "</notification>" |
| 3712 | "<notification name=\"fox-notif\">" |
| 3713 | "<if-feature name=\"fox\"/>" |
| 3714 | "</notification>" |
| 3715 | "<augment target-node=\"/a_pref:top\">" |
| 3716 | "<if-feature name=\"bar\"/>" |
| 3717 | "<container name=\"bar-sub\"/>" |
| 3718 | "</augment>" |
| 3719 | "<augment target-node=\"/top\">" |
| 3720 | "<container name=\"bar-sub2\"/>" |
| 3721 | "</augment>" |
| 3722 | "</submodule>"; |
| 3723 | assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, data, &submod), LY_SUCCESS); |
| 3724 | lysp_submodule_free(st->ctx, submod); |
| 3725 | yin_parser_ctx_free(yin_ctx); |
| 3726 | yin_ctx = NULL; |
| 3727 | submod = NULL; |
| 3728 | |
| 3729 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 3730 | "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 3731 | "</module>"; |
| 3732 | assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, data, &submod), LY_EINVAL); |
| 3733 | logbuf_assert("Input data contains module in situation when a submodule is expected."); |
| 3734 | lysp_submodule_free(st->ctx, submod); |
| 3735 | yin_parser_ctx_free(yin_ctx); |
| 3736 | yin_ctx = NULL; |
| 3737 | submod = NULL; |
| 3738 | |
| 3739 | st->finished_correctly = true; |
| 3740 | } |
| 3741 | |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 3742 | int |
| 3743 | main(void) |
| 3744 | { |
| 3745 | |
| 3746 | const struct CMUnitTest tests[] = { |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 3747 | 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] | 3748 | cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f), |
| 3749 | 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] | 3750 | 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] | 3751 | 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] | 3752 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 3753 | cmocka_unit_test(test_yin_match_argument_name), |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 3754 | cmocka_unit_test_setup_teardown(test_enum_bit_elem, setup_element_test, teardown_element_test), |
| 3755 | cmocka_unit_test_setup_teardown(test_meta_elem, setup_element_test, teardown_element_test), |
| 3756 | cmocka_unit_test_setup_teardown(test_import_elem, setup_element_test, teardown_element_test), |
| 3757 | cmocka_unit_test_setup_teardown(test_status_elem, setup_element_test, teardown_element_test), |
| 3758 | cmocka_unit_test_setup_teardown(test_ext_elem, setup_element_test, teardown_element_test), |
| 3759 | cmocka_unit_test_setup_teardown(test_yin_element_elem, setup_element_test, teardown_element_test), |
| 3760 | cmocka_unit_test_setup_teardown(test_yangversion_elem, setup_element_test, teardown_element_test), |
| 3761 | 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] | 3762 | cmocka_unit_test_setup_teardown(test_argument_elem, setup_element_test, teardown_element_test), |
| 3763 | cmocka_unit_test_setup_teardown(test_base_elem, setup_element_test, teardown_element_test), |
| 3764 | cmocka_unit_test_setup_teardown(test_belongsto_elem, setup_element_test, teardown_element_test), |
| 3765 | cmocka_unit_test_setup_teardown(test_config_elem, setup_element_test, teardown_element_test), |
| 3766 | cmocka_unit_test_setup_teardown(test_default_elem, setup_element_test, teardown_element_test), |
| 3767 | cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup_element_test, teardown_element_test), |
| 3768 | cmocka_unit_test_setup_teardown(test_err_msg_elem, setup_element_test, teardown_element_test), |
| 3769 | cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup_element_test, teardown_element_test), |
| 3770 | cmocka_unit_test_setup_teardown(test_iffeature_elem, setup_element_test, teardown_element_test), |
| 3771 | cmocka_unit_test_setup_teardown(test_length_elem, setup_element_test, teardown_element_test), |
| 3772 | cmocka_unit_test_setup_teardown(test_modifier_elem, setup_element_test, teardown_element_test), |
| 3773 | cmocka_unit_test_setup_teardown(test_namespace_elem, setup_element_test, teardown_element_test), |
| 3774 | cmocka_unit_test_setup_teardown(test_path_elem, setup_element_test, teardown_element_test), |
| 3775 | cmocka_unit_test_setup_teardown(test_pattern_elem, setup_element_test, teardown_element_test), |
| 3776 | 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] | 3777 | cmocka_unit_test_setup_teardown(test_prefix_elem, setup_element_test, teardown_element_test), |
| 3778 | cmocka_unit_test_setup_teardown(test_range_elem, setup_element_test, teardown_element_test), |
| 3779 | cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup_element_test, teardown_element_test), |
| 3780 | cmocka_unit_test_setup_teardown(test_revision_date_elem, setup_element_test, teardown_element_test), |
| 3781 | cmocka_unit_test_setup_teardown(test_unique_elem, setup_element_test, teardown_element_test), |
| 3782 | cmocka_unit_test_setup_teardown(test_units_elem, setup_element_test, teardown_element_test), |
| 3783 | cmocka_unit_test_setup_teardown(test_when_elem, setup_element_test, teardown_element_test), |
| 3784 | 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] | 3785 | 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] | 3786 | 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] | 3787 | 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] | 3788 | 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] | 3789 | 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] | 3790 | 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] | 3791 | 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] | 3792 | 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] | 3793 | 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] | 3794 | 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] | 3795 | 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] | 3796 | 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] | 3797 | 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] | 3798 | 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] | 3799 | 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] | 3800 | 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] | 3801 | 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] | 3802 | 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] | 3803 | 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] | 3804 | 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] | 3805 | 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] | 3806 | 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] | 3807 | 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] | 3808 | 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] | 3809 | 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] | 3810 | 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] | 3811 | 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] | 3812 | 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] | 3813 | 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^] | 3814 | |
| 3815 | cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_logger, teardown_logger), |
| 3816 | 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] | 3817 | }; |
| 3818 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 3819 | 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] | 3820 | } |