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 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +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" |
| 28 | #include "../../../src/xml.h" |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 29 | |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 30 | /* prototypes of static functions */ |
| 31 | void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext); |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 32 | void lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext); |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 33 | void lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 34 | void lysp_type_free(struct ly_ctx *ctx, struct lysp_type *type); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 35 | void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 36 | void lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 37 | void lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 38 | void lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 39 | void lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include); |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 40 | void lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat); |
David Sedlák | 28794f2 | 2019-07-22 16:45:00 +0200 | [diff] [blame] | 41 | void lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 42 | void lysp_notif_free(struct ly_ctx *ctx, struct lysp_notif *notif); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 43 | void lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 44 | void lysp_action_inout_free(struct ly_ctx *ctx, struct lysp_action_inout *inout); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 45 | void lysp_action_free(struct ly_ctx *ctx, struct lysp_action *action); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 46 | void lysp_augment_free(struct ly_ctx *ctx, struct lysp_augment *augment); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 47 | void lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 48 | void lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 49 | void lysp_submodule_free(struct ly_ctx *ctx, struct lysp_submodule *submod); |
| 50 | void lysp_import_free(struct ly_ctx *ctx, struct lysp_import *import); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 51 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 52 | /* wrapping element used for mocking has nothing to do with real module structure */ |
| 53 | #define ELEMENT_WRAPPER_START "<status xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 54 | #define ELEMENT_WRAPPER_END "</status>" |
| 55 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 56 | struct test_parser_yin_state { |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 57 | struct ly_ctx *ctx; |
David Sedlák | 3017da4 | 2019-02-15 09:48:04 +0100 | [diff] [blame] | 58 | struct lys_module *mod; |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 59 | struct lysp_module *lysp_mod; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 60 | struct lys_yin_parser_ctx *yin_ctx; |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 61 | bool finished_correctly; |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 62 | }; |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 63 | |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 64 | #define BUFSIZE 1024 |
| 65 | char logbuf[BUFSIZE] = {0}; |
| 66 | int store = -1; /* negative for infinite logging, positive for limited logging */ |
| 67 | |
| 68 | /* set to 0 to printing error messages to stderr instead of checking them in code */ |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 69 | #define ENABLE_LOGGER_CHECKING 1 |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 70 | |
| 71 | #if ENABLE_LOGGER_CHECKING |
| 72 | static void |
| 73 | logger(LY_LOG_LEVEL level, const char *msg, const char *path) |
| 74 | { |
| 75 | (void) level; /* unused */ |
| 76 | if (store) { |
| 77 | if (path && path[0]) { |
| 78 | snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path); |
| 79 | } else { |
| 80 | strncpy(logbuf, msg, BUFSIZE - 1); |
| 81 | } |
| 82 | if (store > 0) { |
| 83 | --store; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | #endif |
| 88 | |
| 89 | #if ENABLE_LOGGER_CHECKING |
| 90 | # define logbuf_assert(str) assert_string_equal(logbuf, str) |
| 91 | #else |
| 92 | # define logbuf_assert(str) |
| 93 | #endif |
| 94 | |
| 95 | #define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \ |
| 96 | str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \ |
| 97 | assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \ |
| 98 | logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \ |
| 99 | CLEANUP |
| 100 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 101 | int |
| 102 | setup_ly_ctx(void **state) |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 103 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 104 | struct test_parser_yin_state *st = NULL; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 105 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 106 | /* allocate state variable */ |
| 107 | (*state) = st = calloc(1, sizeof(*st)); |
| 108 | if (!st) { |
| 109 | fprintf(stderr, "Memmory allocation failed"); |
| 110 | return EXIT_FAILURE; |
| 111 | } |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 112 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 113 | /* create new libyang context */ |
| 114 | ly_ctx_new(NULL, 0, &st->ctx); |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 115 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 116 | return EXIT_SUCCESS; |
| 117 | } |
| 118 | |
| 119 | int |
| 120 | destroy_ly_ctx(void **state) |
| 121 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 122 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 123 | ly_ctx_destroy(st->ctx, NULL); |
| 124 | free(st); |
| 125 | |
| 126 | return EXIT_SUCCESS; |
| 127 | } |
| 128 | |
| 129 | static int |
| 130 | setup_f(void **state) |
| 131 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 132 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 133 | |
| 134 | #if ENABLE_LOGGER_CHECKING |
| 135 | /* setup logger */ |
| 136 | ly_set_log_clb(logger, 1); |
| 137 | #endif |
| 138 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 139 | /* allocate new module */ |
| 140 | st->mod = calloc(1, sizeof(*st->mod)); |
| 141 | st->mod->ctx = st->ctx; |
| 142 | |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 143 | /* allocate new parsed module */ |
| 144 | st->lysp_mod = calloc(1, sizeof(*st->lysp_mod)); |
| 145 | st->lysp_mod->mod = calloc(1, sizeof(*st->lysp_mod->mod)); |
| 146 | st->lysp_mod->mod->ctx = st->ctx; |
| 147 | |
| 148 | /* allocate parser context */ |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 149 | st->yin_ctx = calloc(1, sizeof(*st->yin_ctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 150 | st->yin_ctx->format = LYS_IN_YIN; |
David Sedlák | 8f5bce0 | 2019-06-03 16:41:08 +0200 | [diff] [blame] | 151 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 152 | return EXIT_SUCCESS; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | static int |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 156 | teardown_f(void **state) |
| 157 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 158 | struct test_parser_yin_state *st = *(struct test_parser_yin_state **)state; |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 159 | struct lys_module *temp; |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 160 | |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 161 | #if ENABLE_LOGGER_CHECKING |
| 162 | /* teardown logger */ |
| 163 | if (!st->finished_correctly && logbuf[0] != '\0') { |
| 164 | fprintf(stderr, "%s\n", logbuf); |
| 165 | } |
| 166 | #endif |
| 167 | |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 168 | temp = st->lysp_mod->mod; |
| 169 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 170 | lyxml_ctx_free(st->yin_ctx->xmlctx); |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 171 | lys_module_free(st->mod, NULL); |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 172 | lysp_module_free(st->lysp_mod); |
| 173 | lys_module_free(temp, NULL); |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 174 | free(st->yin_ctx); |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 175 | |
| 176 | return EXIT_SUCCESS; |
| 177 | } |
| 178 | |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 179 | static struct test_parser_yin_state* |
David Sedlák | 392af4f | 2019-06-04 16:02:42 +0200 | [diff] [blame] | 180 | reset_state(void **state) |
| 181 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 182 | ((struct test_parser_yin_state *)*state)->finished_correctly = true; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 183 | logbuf[0] = '\0'; |
David Sedlák | 392af4f | 2019-06-04 16:02:42 +0200 | [diff] [blame] | 184 | teardown_f(state); |
| 185 | setup_f(state); |
| 186 | |
| 187 | return *state; |
| 188 | } |
| 189 | |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 190 | void |
| 191 | logbuf_clean(void) |
| 192 | { |
| 193 | logbuf[0] = '\0'; |
| 194 | } |
| 195 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 196 | static int |
| 197 | setup_logger(void **state) |
| 198 | { |
| 199 | (void)state; /* unused */ |
| 200 | #if ENABLE_LOGGER_CHECKING |
| 201 | /* setup logger */ |
| 202 | ly_set_log_clb(logger, 1); |
| 203 | #endif |
| 204 | |
| 205 | logbuf[0] = '\0'; |
| 206 | |
| 207 | return EXIT_SUCCESS; |
| 208 | } |
| 209 | |
| 210 | static int |
| 211 | teardown_logger(void **state) |
| 212 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 213 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 214 | |
| 215 | #if ENABLE_LOGGER_CHECKING |
| 216 | /* teardown logger */ |
| 217 | if (!st->finished_correctly && logbuf[0] != '\0') { |
| 218 | fprintf(stderr, "%s\n", logbuf); |
| 219 | } |
| 220 | #endif |
| 221 | |
| 222 | return EXIT_SUCCESS; |
| 223 | } |
| 224 | |
| 225 | static int |
| 226 | setup_element_test(void **state) |
| 227 | { |
| 228 | setup_logger(state); |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 229 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 230 | |
| 231 | st->yin_ctx = calloc(1, sizeof(*st->yin_ctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 232 | st->yin_ctx->format = LYS_IN_YIN; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 233 | |
| 234 | return EXIT_SUCCESS; |
| 235 | } |
| 236 | |
| 237 | static int |
| 238 | teardown_element_test(void **state) |
| 239 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 240 | struct test_parser_yin_state *st = *(struct test_parser_yin_state **)state; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 241 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 242 | lyxml_ctx_free(st->yin_ctx->xmlctx); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 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 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 253 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 254 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 255 | const char *prefix; |
| 256 | size_t prefix_len; |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 257 | /* create mock yin namespace in xml context */ |
| 258 | const char *data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 259 | lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx); |
| 260 | prefix = st->yin_ctx->xmlctx->prefix; |
| 261 | prefix_len = st->yin_ctx->xmlctx->prefix_len; |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 262 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 263 | assert_int_equal(yin_match_keyword(st->yin_ctx, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE); |
| 264 | assert_int_equal(yin_match_keyword(st->yin_ctx, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE); |
| 265 | assert_int_equal(yin_match_keyword(st->yin_ctx, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE); |
| 266 | assert_int_equal(yin_match_keyword(st->yin_ctx, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA); |
| 267 | assert_int_equal(yin_match_keyword(st->yin_ctx, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML); |
| 268 | assert_int_equal(yin_match_keyword(st->yin_ctx, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT); |
| 269 | assert_int_equal(yin_match_keyword(st->yin_ctx, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT); |
| 270 | assert_int_equal(yin_match_keyword(st->yin_ctx, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE); |
| 271 | assert_int_equal(yin_match_keyword(st->yin_ctx, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO); |
| 272 | assert_int_equal(yin_match_keyword(st->yin_ctx, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT); |
| 273 | assert_int_equal(yin_match_keyword(st->yin_ctx, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE); |
| 274 | assert_int_equal(yin_match_keyword(st->yin_ctx, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE); |
| 275 | assert_int_equal(yin_match_keyword(st->yin_ctx, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG); |
| 276 | assert_int_equal(yin_match_keyword(st->yin_ctx, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT); |
| 277 | assert_int_equal(yin_match_keyword(st->yin_ctx, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER); |
| 278 | assert_int_equal(yin_match_keyword(st->yin_ctx, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT); |
| 279 | assert_int_equal(yin_match_keyword(st->yin_ctx, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION); |
| 280 | assert_int_equal(yin_match_keyword(st->yin_ctx, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE); |
| 281 | assert_int_equal(yin_match_keyword(st->yin_ctx, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION); |
| 282 | assert_int_equal(yin_match_keyword(st->yin_ctx, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM); |
| 283 | assert_int_equal(yin_match_keyword(st->yin_ctx, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_APP_TAG); |
| 284 | assert_int_equal(yin_match_keyword(st->yin_ctx, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE); |
| 285 | assert_int_equal(yin_match_keyword(st->yin_ctx, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION); |
| 286 | assert_int_equal(yin_match_keyword(st->yin_ctx, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE); |
| 287 | assert_int_equal(yin_match_keyword(st->yin_ctx, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS); |
| 288 | assert_int_equal(yin_match_keyword(st->yin_ctx, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING); |
| 289 | assert_int_equal(yin_match_keyword(st->yin_ctx, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY); |
| 290 | assert_int_equal(yin_match_keyword(st->yin_ctx, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE); |
| 291 | assert_int_equal(yin_match_keyword(st->yin_ctx, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT); |
| 292 | assert_int_equal(yin_match_keyword(st->yin_ctx, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE); |
| 293 | assert_int_equal(yin_match_keyword(st->yin_ctx, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT); |
| 294 | assert_int_equal(yin_match_keyword(st->yin_ctx, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY); |
| 295 | assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF); |
| 296 | assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST); |
| 297 | assert_int_equal(yin_match_keyword(st->yin_ctx, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH); |
| 298 | assert_int_equal(yin_match_keyword(st->yin_ctx, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST); |
| 299 | assert_int_equal(yin_match_keyword(st->yin_ctx, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY); |
| 300 | assert_int_equal(yin_match_keyword(st->yin_ctx, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS); |
| 301 | assert_int_equal(yin_match_keyword(st->yin_ctx, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS); |
| 302 | assert_int_equal(yin_match_keyword(st->yin_ctx, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER); |
| 303 | assert_int_equal(yin_match_keyword(st->yin_ctx, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE); |
| 304 | assert_int_equal(yin_match_keyword(st->yin_ctx, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST); |
| 305 | assert_int_equal(yin_match_keyword(st->yin_ctx, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE); |
| 306 | assert_int_equal(yin_match_keyword(st->yin_ctx, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION); |
| 307 | assert_int_equal(yin_match_keyword(st->yin_ctx, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY); |
| 308 | assert_int_equal(yin_match_keyword(st->yin_ctx, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION); |
| 309 | assert_int_equal(yin_match_keyword(st->yin_ctx, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT); |
| 310 | assert_int_equal(yin_match_keyword(st->yin_ctx, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH); |
| 311 | assert_int_equal(yin_match_keyword(st->yin_ctx, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN); |
| 312 | assert_int_equal(yin_match_keyword(st->yin_ctx, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION); |
| 313 | assert_int_equal(yin_match_keyword(st->yin_ctx, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX); |
| 314 | assert_int_equal(yin_match_keyword(st->yin_ctx, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE); |
| 315 | assert_int_equal(yin_match_keyword(st->yin_ctx, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE); |
| 316 | assert_int_equal(yin_match_keyword(st->yin_ctx, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE); |
| 317 | assert_int_equal(yin_match_keyword(st->yin_ctx, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE); |
| 318 | assert_int_equal(yin_match_keyword(st->yin_ctx, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE); |
| 319 | assert_int_equal(yin_match_keyword(st->yin_ctx, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION); |
| 320 | assert_int_equal(yin_match_keyword(st->yin_ctx, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE); |
| 321 | assert_int_equal(yin_match_keyword(st->yin_ctx, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC); |
| 322 | assert_int_equal(yin_match_keyword(st->yin_ctx, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS); |
| 323 | assert_int_equal(yin_match_keyword(st->yin_ctx, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE); |
| 324 | assert_int_equal(yin_match_keyword(st->yin_ctx, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE); |
| 325 | assert_int_equal(yin_match_keyword(st->yin_ctx, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF); |
| 326 | assert_int_equal(yin_match_keyword(st->yin_ctx, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE); |
| 327 | assert_int_equal(yin_match_keyword(st->yin_ctx, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS); |
| 328 | assert_int_equal(yin_match_keyword(st->yin_ctx, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES); |
| 329 | assert_int_equal(yin_match_keyword(st->yin_ctx, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE); |
| 330 | assert_int_equal(yin_match_keyword(st->yin_ctx, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN); |
| 331 | assert_int_equal(yin_match_keyword(st->yin_ctx, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION); |
| 332 | assert_int_equal(yin_match_keyword(st->yin_ctx, "yin-element", strlen("yin-element"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YIN_ELEMENT); |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 333 | |
| 334 | st->finished_correctly = true; |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 335 | } |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 336 | |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 337 | static void |
David Sedlák | 060b00e | 2019-06-19 11:12:06 +0200 | [diff] [blame] | 338 | test_yin_match_argument_name(void **state) |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 339 | { |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 340 | (void)state; /* unused */ |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 341 | |
David Sedlák | 060b00e | 2019-06-19 11:12:06 +0200 | [diff] [blame] | 342 | assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN); |
| 343 | assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN); |
| 344 | assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN); |
| 345 | assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION); |
| 346 | assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE); |
| 347 | assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE); |
| 348 | assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME); |
| 349 | assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG); |
| 350 | assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE); |
| 351 | assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT); |
| 352 | assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI); |
| 353 | 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] | 354 | } |
| 355 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 356 | static void |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 357 | test_yin_parse_element_generic(void **state) |
| 358 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 359 | struct test_parser_yin_state *st = *state; |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 360 | struct lysp_ext_instance exts; |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 361 | LY_ERR ret; |
| 362 | |
| 363 | memset(&exts, 0, sizeof(exts)); |
| 364 | |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 365 | const char *data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 366 | lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx); |
| 367 | |
| 368 | ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 369 | assert_int_equal(ret, LY_SUCCESS); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 370 | assert_int_equal(st->yin_ctx->xmlctx->status, LYXML_ELEM_CLOSE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 371 | assert_string_equal(exts.child->stmt, "urn:example:extensions:elem"); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 372 | assert_string_equal(exts.child->arg, "text_value"); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 373 | assert_string_equal(exts.child->child->stmt, "attr"); |
| 374 | assert_string_equal(exts.child->child->arg, "value"); |
| 375 | assert_true(exts.child->child->flags & LYS_YIN_ATTR); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 376 | lysp_ext_instance_free(st->ctx, &exts); |
David Sedlák | 5392a21 | 2019-07-01 09:19:10 +0200 | [diff] [blame] | 377 | st = reset_state(state); |
| 378 | |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 379 | data = "<myext:elem xmlns:myext=\"urn:example:extensions\"></myext:elem>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 380 | lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx); |
| 381 | |
| 382 | ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child); |
David Sedlák | 5392a21 | 2019-07-01 09:19:10 +0200 | [diff] [blame] | 383 | assert_int_equal(ret, LY_SUCCESS); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 384 | assert_int_equal(st->yin_ctx->xmlctx->status, LYXML_ELEM_CLOSE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 385 | assert_string_equal(exts.child->stmt, "urn:example:extensions:elem"); |
David Sedlák | 5392a21 | 2019-07-01 09:19:10 +0200 | [diff] [blame] | 386 | assert_null(exts.child->child); |
| 387 | assert_null(exts.child->arg); |
| 388 | lysp_ext_instance_free(st->ctx, &exts); |
| 389 | |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 390 | st->finished_correctly = true; |
| 391 | } |
| 392 | |
| 393 | static void |
| 394 | test_yin_parse_extension_instance(void **state) |
| 395 | { |
| 396 | LY_ERR ret; |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 397 | struct test_parser_yin_state *st = *state; |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 398 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 399 | const char *data = "<myext:ext value1=\"test\" value=\"test2\" xmlns:myext=\"urn:example:extensions\"><myext:subelem>text</myext:subelem></myext:ext>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 400 | lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx); |
| 401 | |
| 402 | ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 403 | assert_int_equal(ret, LY_SUCCESS); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 404 | assert_string_equal(exts->name, "urn:example:extensions:ext"); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 405 | assert_int_equal(exts->insubstmt_index, 0); |
| 406 | assert_true(exts->insubstmt == LYEXT_SUBSTMT_CONTACT); |
| 407 | assert_true(exts->yin & LYS_YIN); |
| 408 | assert_string_equal(exts->child->stmt, "value1"); |
| 409 | assert_string_equal(exts->child->arg, "test"); |
| 410 | assert_null(exts->child->child); |
| 411 | assert_true(exts->child->flags & LYS_YIN_ATTR); |
| 412 | assert_string_equal(exts->child->next->stmt, "value"); |
| 413 | assert_string_equal(exts->child->next->arg, "test2"); |
| 414 | assert_null(exts->child->next->child); |
| 415 | assert_true(exts->child->next->flags & LYS_YIN_ATTR); |
| 416 | |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 417 | assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:subelem"); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 418 | assert_string_equal(exts->child->next->next->arg, "text"); |
| 419 | assert_null(exts->child->next->next->child); |
| 420 | assert_null(exts->child->next->next->next); |
| 421 | assert_false(exts->child->next->next->flags & LYS_YIN_ATTR); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 422 | lysp_ext_instance_free(st->ctx, exts); |
| 423 | LY_ARRAY_FREE(exts); |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 424 | exts = NULL; |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 425 | st = reset_state(state); |
| 426 | |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 427 | data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" />"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 428 | lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx); |
| 429 | |
| 430 | ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts); |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 431 | assert_int_equal(ret, LY_SUCCESS); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 432 | assert_string_equal(exts->name, "urn:example:extensions:extension-elem"); |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 433 | assert_null(exts->argument); |
| 434 | assert_null(exts->child); |
| 435 | assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT); |
| 436 | assert_int_equal(exts->insubstmt_index, 0); |
| 437 | assert_true(exts->yin & LYS_YIN); |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 438 | lysp_ext_instance_free(st->ctx, exts); |
| 439 | LY_ARRAY_FREE(exts); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 440 | exts = NULL; |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 441 | st = reset_state(state); |
| 442 | |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 443 | data = "<myext:ext attr1=\"text1\" attr2=\"text2\" xmlns:myext=\"urn:example:extensions\">" |
| 444 | "<myext:ext-sub1/>" |
| 445 | "<myext:ext-sub2 sattr1=\"stext2\">" |
| 446 | "<myext:ext-sub21>" |
| 447 | "<myext:ext-sub211 sattr21=\"text21\"/>" |
| 448 | "</myext:ext-sub21>" |
| 449 | "</myext:ext-sub2>" |
| 450 | "<myext:ext-sub3 attr3=\"text3\"></myext:ext-sub3>" |
| 451 | "</myext:ext>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 452 | lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx); |
| 453 | |
| 454 | ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 455 | assert_int_equal(ret, LY_SUCCESS); |
| 456 | |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 457 | assert_string_equal(exts->name, "urn:example:extensions:ext"); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 458 | assert_null(exts->argument); |
| 459 | assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT); |
| 460 | assert_int_equal(exts->insubstmt_index, 0); |
| 461 | assert_true(exts->yin & LYS_YIN); |
| 462 | assert_string_equal(exts->child->stmt, "attr1"); |
| 463 | assert_string_equal(exts->child->arg, "text1"); |
| 464 | assert_null(exts->child->child); |
| 465 | assert_true(exts->child->flags & LYS_YIN_ATTR); |
| 466 | |
| 467 | assert_string_equal(exts->child->next->stmt, "attr2"); |
| 468 | assert_string_equal(exts->child->next->arg, "text2"); |
| 469 | assert_null(exts->child->next->child); |
| 470 | assert_true(exts->child->next->flags & LYS_YIN_ATTR); |
| 471 | |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 472 | assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:ext-sub1"); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 473 | assert_null(exts->child->next->next->arg); |
| 474 | assert_null(exts->child->next->next->child); |
| 475 | assert_int_equal(exts->child->next->next->flags, 0); |
| 476 | |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 477 | assert_string_equal(exts->child->next->next->next->stmt, "urn:example:extensions:ext-sub2"); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 478 | assert_null(exts->child->next->next->next->arg); |
| 479 | assert_int_equal(exts->child->next->next->next->flags, 0); |
| 480 | assert_string_equal(exts->child->next->next->next->child->stmt, "sattr1"); |
| 481 | assert_string_equal(exts->child->next->next->next->child->arg, "stext2"); |
| 482 | assert_null(exts->child->next->next->next->child->child); |
| 483 | assert_true(exts->child->next->next->next->child->flags & LYS_YIN_ATTR); |
| 484 | |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 485 | assert_string_equal(exts->child->next->next->next->child->next->stmt, "urn:example:extensions:ext-sub21"); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 486 | assert_null(exts->child->next->next->next->child->next->arg); |
| 487 | assert_null(exts->child->next->next->next->child->next->next); |
| 488 | assert_int_equal(exts->child->next->next->next->child->next->flags, 0); |
| 489 | |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 490 | assert_string_equal(exts->child->next->next->next->child->next->child->stmt, "urn:example:extensions:ext-sub211"); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 491 | assert_null(exts->child->next->next->next->child->next->child->arg); |
| 492 | assert_int_equal(exts->child->next->next->next->child->next->child->flags, 0); |
| 493 | assert_null(exts->child->next->next->next->child->next->child->next); |
| 494 | |
| 495 | assert_string_equal(exts->child->next->next->next->child->next->child->child->stmt, "sattr21"); |
| 496 | assert_string_equal(exts->child->next->next->next->child->next->child->child->arg, "text21"); |
| 497 | assert_null(exts->child->next->next->next->child->next->child->child->next); |
| 498 | assert_null(exts->child->next->next->next->child->next->child->child->child); |
| 499 | assert_true(exts->child->next->next->next->child->next->child->child->flags & LYS_YIN_ATTR); |
| 500 | |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 501 | assert_string_equal(exts->child->next->next->next->next->stmt, "urn:example:extensions:ext-sub3"); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 502 | assert_null(exts->child->next->next->next->next->arg); |
| 503 | assert_null(exts->child->next->next->next->next->next); |
| 504 | assert_int_equal(exts->child->next->next->next->next->flags, 0); |
| 505 | |
| 506 | assert_string_equal(exts->child->next->next->next->next->child->stmt, "attr3"); |
| 507 | assert_string_equal(exts->child->next->next->next->next->child->arg, "text3"); |
| 508 | assert_null(exts->child->next->next->next->next->child->next); |
| 509 | assert_null(exts->child->next->next->next->next->child->child); |
| 510 | assert_true(exts->child->next->next->next->next->child->flags & LYS_YIN_ATTR); |
| 511 | |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 512 | lysp_ext_instance_free(st->ctx, exts); |
| 513 | LY_ARRAY_FREE(exts); |
| 514 | exts = NULL; |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 515 | st = reset_state(state); |
| 516 | |
| 517 | data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" xmlns:yin=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 518 | "<yin:action name=\"act-name\" pre:prefixed=\"ignored\"/>" |
| 519 | "<yin:augment target-node=\"target\"/>" |
| 520 | "<yin:status value=\"value\"/>" |
| 521 | "<yin:include module=\"mod\"/>" |
| 522 | "<yin:input />" |
| 523 | "<yin:must condition=\"cond\"/>" |
| 524 | "<yin:namespace uri=\"uri\"/>" |
| 525 | "<yin:revision date=\"data\"/>" |
| 526 | "<yin:unique tag=\"tag\"/>" |
David Sedlák | d284488 | 2019-09-13 16:01:22 +0200 | [diff] [blame] | 527 | "<yin:description><yin:text>contact-val</yin:text></yin:description>" |
| 528 | "<yin:error-message><yin:value>err-msg</yin:value></yin:error-message>" |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 529 | "</myext:extension-elem>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 530 | lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx); |
| 531 | |
| 532 | ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts); |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 533 | assert_int_equal(ret, LY_SUCCESS); |
| 534 | assert_string_equal(exts->child->arg, "act-name"); |
| 535 | assert_string_equal(exts->child->next->arg, "target"); |
| 536 | assert_string_equal(exts->child->next->next->arg, "value"); |
| 537 | assert_string_equal(exts->child->next->next->next->arg, "mod"); |
| 538 | assert_null(exts->child->next->next->next->next->arg); |
| 539 | assert_string_equal(exts->child->next->next->next->next->next->arg, "cond"); |
| 540 | assert_string_equal(exts->child->next->next->next->next->next->next->arg, "uri"); |
| 541 | assert_string_equal(exts->child->next->next->next->next->next->next->next->arg, "data"); |
| 542 | assert_string_equal(exts->child->next->next->next->next->next->next->next->next->arg, "tag"); |
| 543 | assert_string_equal(exts->child->next->next->next->next->next->next->next->next->next->arg, "contact-val"); |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 544 | lysp_ext_instance_free(st->ctx, exts); |
| 545 | LY_ARRAY_FREE(exts); |
| 546 | exts = NULL; |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 547 | st = reset_state(state); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 548 | |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 549 | st->finished_correctly = true; |
| 550 | } |
| 551 | |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 552 | static void |
| 553 | test_yin_parse_content(void **state) |
| 554 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 555 | struct test_parser_yin_state *st = *state; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 556 | LY_ERR ret = LY_SUCCESS; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 557 | const char *data = "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 558 | "<myext:custom xmlns:myext=\"urn:example:extensions\">" |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 559 | "totally amazing extension" |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 560 | "</myext:custom>" |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 561 | "<extension name=\"ext\">" |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 562 | "<argument name=\"argname\"></argument>" |
| 563 | "<description><text>desc</text></description>" |
| 564 | "<reference><text>ref</text></reference>" |
| 565 | "<status value=\"deprecated\"></status>" |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 566 | "</extension>" |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 567 | "<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] | 568 | "<if-feature name=\"foo\"></if-feature>" |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 569 | "<when condition=\"condition...\">" |
| 570 | "<reference><text>when_ref</text></reference>" |
| 571 | "<description><text>when_desc</text></description>" |
| 572 | "</when>" |
David Sedlák | e1a3030 | 2019-07-10 13:49:38 +0200 | [diff] [blame] | 573 | "<config value=\"true\"/>" |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 574 | "<error-message>" |
| 575 | "<value>error-msg</value>" |
| 576 | "</error-message>" |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 577 | "<error-app-tag value=\"err-app-tag\"/>" |
David Sedlák | a5b1d38 | 2019-07-10 16:31:09 +0200 | [diff] [blame] | 578 | "<units name=\"radians\"></units>" |
David Sedlák | e7084ce | 2019-07-10 16:44:15 +0200 | [diff] [blame] | 579 | "<default value=\"default-value\"/>" |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 580 | "<position value=\"25\"></position>" |
| 581 | "<value value=\"-5\"/>" |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 582 | "<require-instance value=\"true\"></require-instance>" |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 583 | "<range value=\"5..10\" />" |
David Sedlák | 438ae43 | 2019-07-11 15:36:54 +0200 | [diff] [blame] | 584 | "<length value=\"baf\"/>" |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 585 | "<pattern value='pattern'>" |
| 586 | "<modifier value='invert-match'/>" |
| 587 | "</pattern>" |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 588 | "<enum name=\"yay\">" |
| 589 | "</enum>" |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 590 | "</prefix>"; |
| 591 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 592 | const char **if_features = NULL; |
David Sedlák | e7084ce | 2019-07-10 16:44:15 +0200 | [diff] [blame] | 593 | const char *value, *err_msg, *app_tag, *units, *def; |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 594 | struct lysp_ext *ext_def = NULL; |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 595 | struct lysp_when *when_p = NULL; |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 596 | struct lysp_type_enum pos_enum = {}, val_enum = {}; |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 597 | 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] | 598 | uint8_t config = 0; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 599 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 600 | lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx); |
| 601 | lyxml_ctx_next(st->yin_ctx->xmlctx); |
| 602 | lyxml_ctx_next(st->yin_ctx->xmlctx); |
| 603 | lyxml_ctx_next(st->yin_ctx->xmlctx); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 604 | |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 605 | struct yin_subelement subelems[17] = { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 606 | {LY_STMT_CONFIG, &config, 0}, |
| 607 | {LY_STMT_DEFAULT, &def, YIN_SUBELEM_UNIQUE}, |
| 608 | {LY_STMT_ENUM, &enum_type, 0}, |
| 609 | {LY_STMT_ERROR_APP_TAG, &app_tag, YIN_SUBELEM_UNIQUE}, |
| 610 | {LY_STMT_ERROR_MESSAGE, &err_msg, 0}, |
| 611 | {LY_STMT_EXTENSION, &ext_def, 0}, |
| 612 | {LY_STMT_IF_FEATURE, &if_features, 0}, |
| 613 | {LY_STMT_LENGTH, &len_type, 0}, |
| 614 | {LY_STMT_PATTERN, &patter_type, 0}, |
| 615 | {LY_STMT_POSITION, &pos_enum, 0}, |
| 616 | {LY_STMT_RANGE, &range_type, 0}, |
| 617 | {LY_STMT_REQUIRE_INSTANCE, &req_type, 0}, |
| 618 | {LY_STMT_UNITS, &units, YIN_SUBELEM_UNIQUE}, |
| 619 | {LY_STMT_VALUE, &val_enum, 0}, |
| 620 | {LY_STMT_WHEN, &when_p, 0}, |
| 621 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 622 | {LY_STMT_ARG_TEXT, &value, 0} |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 623 | }; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 624 | ret = yin_parse_content(st->yin_ctx, subelems, 17, LY_STMT_PREFIX, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 625 | assert_int_equal(ret, LY_SUCCESS); |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 626 | /* check parsed values */ |
David Sedlák | e7084ce | 2019-07-10 16:44:15 +0200 | [diff] [blame] | 627 | assert_string_equal(def, "default-value"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 628 | assert_string_equal(exts->name, "urn:example:extensions:custom"); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 629 | assert_string_equal(exts->argument, "totally amazing extension"); |
| 630 | assert_string_equal(value, "wsefsdf"); |
David Sedlák | a5b1d38 | 2019-07-10 16:31:09 +0200 | [diff] [blame] | 631 | assert_string_equal(units, "radians"); |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 632 | assert_string_equal(when_p->cond, "condition..."); |
| 633 | assert_string_equal(when_p->dsc, "when_desc"); |
| 634 | assert_string_equal(when_p->ref, "when_ref"); |
David Sedlák | e1a3030 | 2019-07-10 13:49:38 +0200 | [diff] [blame] | 635 | assert_int_equal(config, LYS_CONFIG_W); |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 636 | assert_int_equal(pos_enum.value, 25); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 637 | assert_true(pos_enum.flags & LYS_SET_VALUE); |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 638 | assert_int_equal(val_enum.value, -5); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 639 | assert_true(val_enum.flags & LYS_SET_VALUE); |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 640 | assert_int_equal(req_type.require_instance, 1); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 641 | assert_true(req_type.flags &= LYS_SET_REQINST); |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 642 | assert_string_equal(range_type.range->arg, "5..10"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 643 | assert_true(range_type.flags & LYS_SET_RANGE); |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 644 | assert_string_equal(err_msg, "error-msg"); |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 645 | assert_string_equal(app_tag, "err-app-tag"); |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 646 | assert_string_equal(enum_type.enums->name, "yay"); |
David Sedlák | 438ae43 | 2019-07-11 15:36:54 +0200 | [diff] [blame] | 647 | assert_string_equal(len_type.length->arg, "baf"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 648 | assert_true(len_type.flags & LYS_SET_LENGTH); |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 649 | assert_string_equal(patter_type.patterns->arg, "\x015pattern"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 650 | assert_true(patter_type.flags & LYS_SET_PATTERN); |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 651 | /* cleanup */ |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 652 | lysp_ext_instance_free(st->ctx, exts); |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 653 | lysp_when_free(st->ctx, when_p); |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 654 | lysp_ext_free(st->ctx, ext_def); |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 655 | FREE_STRING(st->ctx, *if_features); |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 656 | FREE_STRING(st->ctx, err_msg); |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 657 | FREE_STRING(st->ctx, app_tag); |
David Sedlák | a5b1d38 | 2019-07-10 16:31:09 +0200 | [diff] [blame] | 658 | FREE_STRING(st->ctx, units); |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 659 | FREE_STRING(st->ctx, patter_type.patterns->arg); |
David Sedlák | e7084ce | 2019-07-10 16:44:15 +0200 | [diff] [blame] | 660 | FREE_STRING(st->ctx, def); |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 661 | FREE_STRING(st->ctx, range_type.range->arg); |
David Sedlák | 438ae43 | 2019-07-11 15:36:54 +0200 | [diff] [blame] | 662 | FREE_STRING(st->ctx, len_type.length->arg); |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 663 | FREE_STRING(st->ctx, enum_type.enums->name); |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 664 | FREE_STRING(st->ctx, value); |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 665 | LY_ARRAY_FREE(if_features); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 666 | LY_ARRAY_FREE(exts); |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 667 | LY_ARRAY_FREE(ext_def); |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 668 | LY_ARRAY_FREE(patter_type.patterns); |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 669 | LY_ARRAY_FREE(enum_type.enums); |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 670 | free(when_p); |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 671 | free(range_type.range); |
David Sedlák | 438ae43 | 2019-07-11 15:36:54 +0200 | [diff] [blame] | 672 | free(len_type.length); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 673 | st = reset_state(state); |
| 674 | |
| 675 | /* test unique subelem */ |
| 676 | const char *prefix_value; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 677 | struct yin_subelement subelems2[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE}, |
| 678 | {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_UNIQUE}}; |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 679 | data = ELEMENT_WRAPPER_START |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 680 | "<prefix value=\"inv_mod\" />" |
| 681 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
| 682 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 683 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 684 | lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx); |
| 685 | lyxml_ctx_next(st->yin_ctx->xmlctx); |
| 686 | |
| 687 | ret = yin_parse_content(st->yin_ctx, subelems2, 2, LY_STMT_STATUS, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 688 | assert_int_equal(ret, LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 689 | logbuf_assert("Redefinition of \"text\" sub-element in \"status\" element. Line number 1."); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 690 | lydict_remove(st->ctx, prefix_value); |
| 691 | lydict_remove(st->ctx, value); |
| 692 | st = reset_state(state); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 693 | |
| 694 | /* test first subelem */ |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 695 | data = ELEMENT_WRAPPER_START |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 696 | "<prefix value=\"inv_mod\" />" |
| 697 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
| 698 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 699 | ELEMENT_WRAPPER_END; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 700 | struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE}, |
| 701 | {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}}; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 702 | lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx); |
| 703 | lyxml_ctx_next(st->yin_ctx->xmlctx); |
| 704 | |
| 705 | ret = yin_parse_content(st->yin_ctx, subelems3, 2, LY_STMT_STATUS, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 706 | assert_int_equal(ret, LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 707 | logbuf_assert("Sub-element \"text\" of \"status\" element must be defined as it's first sub-element. Line number 1."); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 708 | lydict_remove(st->ctx, prefix_value); |
| 709 | st = reset_state(state); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 710 | |
| 711 | /* test mandatory subelem */ |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 712 | data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 713 | struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}}; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 714 | lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx); |
| 715 | lyxml_ctx_next(st->yin_ctx->xmlctx); |
| 716 | |
| 717 | ret = yin_parse_content(st->yin_ctx, subelems4, 1, LY_STMT_STATUS, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 718 | assert_int_equal(ret, LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 719 | logbuf_assert("Missing mandatory sub-element \"prefix\" of \"status\" element. Line number 1."); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 720 | |
| 721 | st->finished_correctly = true; |
| 722 | } |
| 723 | |
David Sedlák | 92147b0 | 2019-07-09 14:01:01 +0200 | [diff] [blame] | 724 | static void |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 725 | test_validate_value(void **state) |
| 726 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 727 | struct test_parser_yin_state *st = *state; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 728 | const char *data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END; |
| 729 | |
| 730 | /* create some XML context */ |
| 731 | lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx); |
| 732 | st->yin_ctx->xmlctx->status = LYXML_ELEM_CONTENT; |
| 733 | st->yin_ctx->xmlctx->dynamic = 0; |
| 734 | |
| 735 | st->yin_ctx->xmlctx->value = "#invalid"; |
| 736 | st->yin_ctx->xmlctx->value_len = 8; |
| 737 | assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID); |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 738 | logbuf_assert("Invalid identifier character '#'. Line number 1."); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 739 | |
| 740 | st->yin_ctx->xmlctx->value = ""; |
| 741 | st->yin_ctx->xmlctx->value_len = 0; |
| 742 | assert_int_equal(yin_validate_value(st->yin_ctx, Y_STR_ARG), LY_SUCCESS); |
| 743 | |
| 744 | st->yin_ctx->xmlctx->value = "pre:b"; |
| 745 | st->yin_ctx->xmlctx->value_len = 5; |
| 746 | assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID); |
| 747 | assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG), LY_SUCCESS); |
| 748 | |
| 749 | st->yin_ctx->xmlctx->value = "pre:pre:b"; |
| 750 | st->yin_ctx->xmlctx->value_len = 9; |
| 751 | assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG), LY_EVALID); |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 752 | |
| 753 | st->finished_correctly = true; |
| 754 | } |
| 755 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 756 | /* helper function to simplify unit test of each element using parse_content function */ |
| 757 | LY_ERR |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 758 | test_element_helper(struct test_parser_yin_state *st, const char *data, void *dest, const char **text, struct lysp_ext_instance **exts) |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 759 | { |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 760 | const char *name, *prefix; |
| 761 | size_t name_len, prefix_len; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 762 | LY_ERR ret = LY_SUCCESS; |
| 763 | struct yin_subelement subelems[71] = { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 764 | {LY_STMT_ACTION, dest, 0}, |
| 765 | {LY_STMT_ANYDATA, dest, 0}, |
| 766 | {LY_STMT_ANYXML, dest, 0}, |
| 767 | {LY_STMT_ARGUMENT,dest, 0}, |
| 768 | {LY_STMT_AUGMENT, dest, 0}, |
| 769 | {LY_STMT_BASE, dest, 0}, |
| 770 | {LY_STMT_BELONGS_TO, dest, 0}, |
| 771 | {LY_STMT_BIT, dest, 0}, |
| 772 | {LY_STMT_CASE, dest, 0}, |
| 773 | {LY_STMT_CHOICE, dest, 0}, |
| 774 | {LY_STMT_CONFIG, dest, 0}, |
| 775 | {LY_STMT_CONTACT, dest, 0}, |
| 776 | {LY_STMT_CONTAINER, dest, 0}, |
| 777 | {LY_STMT_DEFAULT, dest, YIN_SUBELEM_UNIQUE}, |
| 778 | {LY_STMT_DESCRIPTION, dest, 0}, |
| 779 | {LY_STMT_DEVIATE, dest, 0}, |
| 780 | {LY_STMT_DEVIATION, dest, 0}, |
| 781 | {LY_STMT_ENUM, dest, 0}, |
| 782 | {LY_STMT_ERROR_APP_TAG, dest, YIN_SUBELEM_UNIQUE}, |
| 783 | {LY_STMT_ERROR_MESSAGE, dest, 0}, |
| 784 | {LY_STMT_EXTENSION, dest, 0}, |
| 785 | {LY_STMT_FEATURE, dest, 0}, |
| 786 | {LY_STMT_FRACTION_DIGITS, dest, 0}, |
| 787 | {LY_STMT_GROUPING, dest, 0}, |
| 788 | {LY_STMT_IDENTITY, dest, 0}, |
| 789 | {LY_STMT_IF_FEATURE, dest, 0}, |
| 790 | {LY_STMT_IMPORT, dest, 0}, |
| 791 | {LY_STMT_INCLUDE, dest, 0}, |
| 792 | {LY_STMT_INPUT, dest, 0}, |
| 793 | {LY_STMT_KEY, dest, YIN_SUBELEM_UNIQUE}, |
| 794 | {LY_STMT_LEAF, dest, 0}, |
| 795 | {LY_STMT_LEAF_LIST, dest, 0}, |
| 796 | {LY_STMT_LENGTH, dest, 0}, |
| 797 | {LY_STMT_LIST, dest, 0}, |
| 798 | {LY_STMT_MANDATORY, dest, 0}, |
| 799 | {LY_STMT_MAX_ELEMENTS, dest, 0}, |
| 800 | {LY_STMT_MIN_ELEMENTS, dest, 0}, |
| 801 | {LY_STMT_MODIFIER, dest, 0}, |
| 802 | {LY_STMT_MODULE, dest, 0}, |
| 803 | {LY_STMT_MUST, dest, 0}, |
| 804 | {LY_STMT_NAMESPACE, dest, YIN_SUBELEM_UNIQUE}, |
| 805 | {LY_STMT_NOTIFICATION, dest, 0}, |
| 806 | {LY_STMT_ORDERED_BY, dest, 0}, |
| 807 | {LY_STMT_ORGANIZATION, dest, 0}, |
| 808 | {LY_STMT_OUTPUT, dest, 0}, |
| 809 | {LY_STMT_PATH, dest, 0}, |
| 810 | {LY_STMT_PATTERN, dest, 0}, |
| 811 | {LY_STMT_POSITION, dest, 0}, |
| 812 | {LY_STMT_PREFIX, dest, YIN_SUBELEM_UNIQUE}, |
| 813 | {LY_STMT_PRESENCE, dest, YIN_SUBELEM_UNIQUE}, |
| 814 | {LY_STMT_RANGE, dest, 0}, |
| 815 | {LY_STMT_REFERENCE, dest, 0}, |
| 816 | {LY_STMT_REFINE, dest, 0}, |
| 817 | {LY_STMT_REQUIRE_INSTANCE, dest, 0}, |
| 818 | {LY_STMT_REVISION, dest, 0}, |
| 819 | {LY_STMT_REVISION_DATE, dest, 0}, |
| 820 | {LY_STMT_RPC, dest, 0}, |
| 821 | {LY_STMT_STATUS, dest, 0}, |
| 822 | {LY_STMT_SUBMODULE, dest, 0}, |
| 823 | {LY_STMT_TYPE, dest, 0}, |
| 824 | {LY_STMT_TYPEDEF, dest, 0}, |
| 825 | {LY_STMT_UNIQUE, dest, 0}, |
| 826 | {LY_STMT_UNITS, dest, YIN_SUBELEM_UNIQUE}, |
| 827 | {LY_STMT_USES, dest, 0}, |
| 828 | {LY_STMT_VALUE, dest, 0}, |
| 829 | {LY_STMT_WHEN, dest, 0}, |
| 830 | {LY_STMT_YANG_VERSION, dest, 0}, |
| 831 | {LY_STMT_YIN_ELEMENT, dest, 0}, |
| 832 | {LY_STMT_EXTENSION_INSTANCE, dest, 0}, |
| 833 | {LY_STMT_ARG_TEXT, dest, 0}, |
| 834 | {LY_STMT_ARG_VALUE, dest, 0} |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 835 | }; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 836 | lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx); |
| 837 | prefix = st->yin_ctx->xmlctx->prefix; |
| 838 | prefix_len = st->yin_ctx->xmlctx->prefix_len; |
| 839 | name = st->yin_ctx->xmlctx->name; |
| 840 | name_len = st->yin_ctx->xmlctx->name_len; |
| 841 | lyxml_ctx_next(st->yin_ctx->xmlctx); |
| 842 | |
| 843 | ret = yin_parse_content(st->yin_ctx, subelems, 71, yin_match_keyword(st->yin_ctx, name, name_len, prefix, prefix_len, LY_STMT_NONE), text, exts); |
| 844 | |
| 845 | /* free parser */ |
| 846 | lyxml_ctx_free(st->yin_ctx->xmlctx); |
| 847 | st->yin_ctx->xmlctx = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 848 | return ret; |
| 849 | } |
| 850 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 851 | #define EXT_SUBELEM "<myext:c-define name=\"MY_MTU\" xmlns:myext=\"urn:example:extensions\"/>" |
| 852 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 853 | static void |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 854 | test_enum_elem(void **state) |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 855 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 856 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 857 | struct lysp_type type = {}; |
| 858 | const char *data; |
| 859 | data = ELEMENT_WRAPPER_START |
| 860 | "<enum name=\"enum-name\">" |
| 861 | "<if-feature name=\"feature\" />" |
| 862 | "<value value=\"55\" />" |
| 863 | "<status value=\"deprecated\" />" |
| 864 | "<description><text>desc...</text></description>" |
| 865 | "<reference><text>ref...</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 866 | EXT_SUBELEM |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 867 | "</enum>" |
| 868 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 869 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 870 | assert_string_equal(type.enums->name, "enum-name"); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 871 | assert_string_equal(*type.enums->iffeatures, "feature"); |
| 872 | assert_int_equal(type.enums->value, 55); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 873 | 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] | 874 | assert_string_equal(type.enums->dsc, "desc..."); |
| 875 | assert_string_equal(type.enums->ref, "ref..."); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 876 | assert_string_equal(type.enums->exts->name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 877 | assert_int_equal(type.enums->exts->insubstmt_index, 0); |
| 878 | assert_int_equal(type.enums->exts->insubstmt, LYEXT_SUBSTMT_SELF); |
| 879 | lysp_type_free(st->ctx, &type); |
| 880 | memset(&type, 0, sizeof type); |
| 881 | |
| 882 | data = ELEMENT_WRAPPER_START |
| 883 | "<enum name=\"enum-name\"></enum>" |
| 884 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 885 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 886 | assert_string_equal(type.enums->name, "enum-name"); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 887 | lysp_type_free(st->ctx, &type); |
| 888 | memset(&type, 0, sizeof type); |
| 889 | |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 890 | st->finished_correctly = true; |
| 891 | } |
| 892 | |
| 893 | static void |
| 894 | test_bit_elem(void **state) |
| 895 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 896 | struct test_parser_yin_state *st = *state; |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 897 | struct lysp_type type = {}; |
| 898 | const char *data; |
| 899 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 900 | "<bit name=\"bit-name\">" |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 901 | "<if-feature name=\"feature\" />" |
| 902 | "<position value=\"55\" />" |
| 903 | "<status value=\"deprecated\" />" |
| 904 | "<description><text>desc...</text></description>" |
| 905 | "<reference><text>ref...</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 906 | EXT_SUBELEM |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 907 | "</bit>" |
| 908 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 909 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 910 | assert_string_equal(type.bits->name, "bit-name"); |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 911 | assert_string_equal(*type.bits->iffeatures, "feature"); |
| 912 | assert_int_equal(type.bits->value, 55); |
| 913 | assert_true((type.bits->flags & LYS_STATUS_DEPRC) && (type.bits->flags & LYS_SET_VALUE)); |
| 914 | assert_string_equal(type.bits->dsc, "desc..."); |
| 915 | assert_string_equal(type.bits->ref, "ref..."); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 916 | assert_string_equal(type.bits->exts->name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 917 | assert_int_equal(type.bits->exts->insubstmt_index, 0); |
| 918 | assert_int_equal(type.bits->exts->insubstmt, LYEXT_SUBSTMT_SELF); |
| 919 | lysp_type_free(st->ctx, &type); |
| 920 | memset(&type, 0, sizeof type); |
| 921 | |
| 922 | data = ELEMENT_WRAPPER_START |
| 923 | "<bit name=\"bit-name\"> </bit>" |
| 924 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 925 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 926 | assert_string_equal(type.bits->name, "bit-name"); |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 927 | lysp_type_free(st->ctx, &type); |
| 928 | memset(&type, 0, sizeof type); |
| 929 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 930 | st->finished_correctly = true; |
| 931 | } |
| 932 | |
| 933 | static void |
| 934 | test_meta_elem(void **state) |
| 935 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 936 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 937 | char *value = NULL; |
| 938 | const char *data; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 939 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 940 | |
| 941 | /* organization element */ |
| 942 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 943 | "<organization><text>organization...</text>" EXT_SUBELEM EXT_SUBELEM "</organization>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 944 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 945 | assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 946 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 947 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 948 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORGANIZATION); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 949 | assert_string_equal(exts[1].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 950 | assert_int_equal(exts[1].insubstmt_index, 0); |
| 951 | assert_int_equal(exts[1].insubstmt, LYEXT_SUBSTMT_ORGANIZATION); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 952 | assert_string_equal(value, "organization..."); |
| 953 | FREE_STRING(st->ctx, value); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 954 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 955 | value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 956 | exts = NULL; |
| 957 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 958 | /* contact element */ |
| 959 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 960 | "<contact><text>contact...</text>" EXT_SUBELEM "</contact>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 961 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 962 | assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 963 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 964 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 965 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONTACT); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 966 | assert_string_equal(value, "contact..."); |
| 967 | FREE_STRING(st->ctx, value); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 968 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 969 | exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 970 | value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 971 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 972 | /* description element */ |
| 973 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 974 | "<description><text>description...</text>" EXT_SUBELEM "</description>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 975 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 976 | assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 977 | assert_string_equal(value, "description..."); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 978 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 979 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 980 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DESCRIPTION); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 981 | FREE_STRING(st->ctx, value); |
| 982 | value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 983 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 984 | exts = NULL; |
| 985 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 986 | /* reference element */ |
| 987 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 988 | "<reference><text>reference...</text>" EXT_SUBELEM "</reference>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 989 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 990 | assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 991 | assert_string_equal(value, "reference..."); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 992 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 993 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 994 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REFERENCE); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 995 | FREE_STRING(st->ctx, value); |
| 996 | value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 997 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 998 | exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 999 | |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 1000 | /* reference element */ |
| 1001 | data = ELEMENT_WRAPPER_START |
| 1002 | "<reference invalid=\"text\"><text>reference...</text>""</reference>" |
| 1003 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1004 | assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1005 | logbuf_assert("Unexpected attribute \"invalid\" of \"reference\" element. Line number 1."); |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 1006 | FREE_STRING(st->ctx, value); |
| 1007 | value = NULL; |
| 1008 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1009 | exts = NULL; |
| 1010 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1011 | /* missing text subelement */ |
| 1012 | data = ELEMENT_WRAPPER_START |
| 1013 | "<reference>reference...</reference>" |
| 1014 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1015 | assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1016 | logbuf_assert("Missing mandatory sub-element \"text\" of \"reference\" element. Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1017 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1018 | /* reference element */ |
| 1019 | data = ELEMENT_WRAPPER_START |
| 1020 | "<reference>" EXT_SUBELEM "<text>reference...</text></reference>" |
| 1021 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1022 | assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1023 | logbuf_assert("Sub-element \"text\" of \"reference\" element must be defined as it's first sub-element. Line number 1."); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1024 | FREE_STRING(st->ctx, value); |
| 1025 | value = NULL; |
| 1026 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1027 | exts = NULL; |
| 1028 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1029 | st->finished_correctly = true; |
| 1030 | } |
| 1031 | |
| 1032 | static void |
| 1033 | test_import_elem(void **state) |
| 1034 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1035 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1036 | const char *data; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1037 | struct lysp_import *imports = NULL; |
| 1038 | struct import_meta imp_meta = {"prefix", &imports}; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1039 | |
| 1040 | /* max subelems */ |
| 1041 | data = ELEMENT_WRAPPER_START |
| 1042 | "<import module=\"a\">" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1043 | EXT_SUBELEM |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1044 | "<prefix value=\"a_mod\"/>" |
| 1045 | "<revision-date date=\"2015-01-01\"></revision-date>" |
| 1046 | "<description><text>import description</text></description>" |
| 1047 | "<reference><text>import reference</text></reference>" |
| 1048 | "</import>" |
| 1049 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1050 | assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1051 | assert_string_equal(imports->name, "a"); |
| 1052 | assert_string_equal(imports->prefix, "a_mod"); |
| 1053 | assert_string_equal(imports->rev, "2015-01-01"); |
| 1054 | assert_string_equal(imports->dsc, "import description"); |
| 1055 | assert_string_equal(imports->ref, "import reference"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1056 | assert_string_equal(imports->exts->name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1057 | assert_int_equal(imports->exts->insubstmt, LYEXT_SUBSTMT_SELF); |
| 1058 | assert_int_equal(imports->exts->insubstmt_index, 0); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1059 | FREE_ARRAY(st->ctx, imports, lysp_import_free); |
| 1060 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1061 | |
| 1062 | /* min subelems */ |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1063 | data = ELEMENT_WRAPPER_START |
| 1064 | "<import module=\"a\">" |
| 1065 | "<prefix value=\"a_mod\"/>" |
| 1066 | "</import>" |
| 1067 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1068 | assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1069 | assert_string_equal(imports->prefix, "a_mod"); |
| 1070 | FREE_ARRAY(st->ctx, imports, lysp_import_free); |
| 1071 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1072 | |
| 1073 | /* invalid (missing prefix) */ |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1074 | data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1075 | assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1076 | logbuf_assert("Missing mandatory sub-element \"prefix\" of \"import\" element. Line number 1."); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1077 | FREE_ARRAY(st->ctx, imports, lysp_import_free); |
| 1078 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1079 | |
| 1080 | /* invalid reused prefix */ |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1081 | data = ELEMENT_WRAPPER_START |
| 1082 | "<import module=\"a\">" |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1083 | "<prefix value=\"prefix\"/>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1084 | "</import>" |
| 1085 | "<import module=\"a\">" |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1086 | "<prefix value=\"prefix\"/>" |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1087 | "</import>" |
| 1088 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1089 | assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 1090 | logbuf_assert("Prefix \"prefix\" already used as module prefix. Line number 1."); |
| 1091 | FREE_ARRAY(st->ctx, imports, lysp_import_free); |
| 1092 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1093 | |
| 1094 | st->finished_correctly = true; |
| 1095 | } |
| 1096 | |
| 1097 | static void |
| 1098 | test_status_elem(void **state) |
| 1099 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1100 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1101 | const char *data; |
| 1102 | uint16_t flags = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1103 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1104 | |
| 1105 | /* test valid values */ |
| 1106 | data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1107 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1108 | assert_true(flags & LYS_STATUS_CURR); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1109 | |
| 1110 | data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1111 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1112 | assert_true(flags & LYS_STATUS_DEPRC); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1113 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1114 | data = ELEMENT_WRAPPER_START "<status value=\"obsolete\">"EXT_SUBELEM"</status>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1115 | assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1116 | assert_true(flags & LYS_STATUS_OBSLT); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1117 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1118 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1119 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_STATUS); |
| 1120 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1121 | exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1122 | |
| 1123 | /* test invalid value */ |
| 1124 | data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1125 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 1126 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"status\" element. Valid values are \"current\", \"deprecated\" and \"obsolete\". Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1127 | st->finished_correctly = true; |
| 1128 | } |
| 1129 | |
| 1130 | static void |
| 1131 | test_ext_elem(void **state) |
| 1132 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1133 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1134 | const char *data; |
| 1135 | struct lysp_ext *ext = NULL; |
| 1136 | |
| 1137 | /* max subelems */ |
| 1138 | data = ELEMENT_WRAPPER_START |
| 1139 | "<extension name=\"ext_name\">" |
| 1140 | "<argument name=\"arg\"></argument>" |
| 1141 | "<status value=\"current\"/>" |
| 1142 | "<description><text>ext_desc</text></description>" |
| 1143 | "<reference><text>ext_ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1144 | EXT_SUBELEM |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1145 | "</extension>" |
| 1146 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1147 | assert_int_equal(test_element_helper(st, data, &ext, NULL, NULL), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1148 | assert_string_equal(ext->name, "ext_name"); |
| 1149 | assert_string_equal(ext->argument, "arg"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1150 | assert_true(ext->flags & LYS_STATUS_CURR); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1151 | assert_string_equal(ext->dsc, "ext_desc"); |
| 1152 | assert_string_equal(ext->ref, "ext_ref"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1153 | assert_string_equal(ext->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1154 | assert_int_equal(ext->exts[0].insubstmt_index, 0); |
| 1155 | assert_int_equal(ext->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1156 | lysp_ext_free(st->ctx, ext); |
| 1157 | LY_ARRAY_FREE(ext); |
| 1158 | ext = NULL; |
| 1159 | |
| 1160 | /* min subelems */ |
| 1161 | data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1162 | assert_int_equal(test_element_helper(st, data, &ext, NULL, NULL), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1163 | assert_string_equal(ext->name, "ext_name"); |
| 1164 | lysp_ext_free(st->ctx, ext); |
| 1165 | LY_ARRAY_FREE(ext); |
| 1166 | ext = NULL; |
| 1167 | |
| 1168 | st->finished_correctly = true; |
| 1169 | } |
| 1170 | |
| 1171 | static void |
| 1172 | test_yin_element_elem(void **state) |
| 1173 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1174 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1175 | const char *data; |
| 1176 | uint16_t flags = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1177 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1178 | |
| 1179 | data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1180 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1181 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1182 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1183 | data = ELEMENT_WRAPPER_START "<yin-element value=\"false\">" EXT_SUBELEM "</yin-element>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1184 | assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1185 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1186 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1187 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1188 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_YINELEM); |
| 1189 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1190 | |
| 1191 | data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1192 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1193 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 1194 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"yin-element\" element. Valid values are \"true\" and \"false\". Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1195 | st->finished_correctly = true; |
| 1196 | } |
| 1197 | |
| 1198 | static void |
| 1199 | test_yangversion_elem(void **state) |
| 1200 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1201 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1202 | const char *data; |
| 1203 | uint8_t version = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1204 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1205 | |
| 1206 | /* valid values */ |
| 1207 | data = ELEMENT_WRAPPER_START "<yang-version value=\"1.0\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1208 | assert_int_equal(test_element_helper(st, data, &version, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1209 | assert_true(version & LYS_VERSION_1_0); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1210 | assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_0); |
| 1211 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1212 | data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\">" EXT_SUBELEM "</yang-version>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1213 | assert_int_equal(test_element_helper(st, data, &version, NULL, &exts), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1214 | assert_true(version & LYS_VERSION_1_1); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1215 | assert_int_equal(st->yin_ctx->mod_version, LYS_VERSION_1_1); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1216 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1217 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1218 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_VERSION); |
| 1219 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1220 | |
| 1221 | /* invalid value */ |
| 1222 | data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1223 | assert_int_equal(test_element_helper(st, data, &version, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 1224 | logbuf_assert("Invalid value \"version\" of \"value\" attribute in \"yang-version\" element. Valid values are \"1.0\" and \"1.1\". Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1225 | |
| 1226 | st->finished_correctly = true; |
| 1227 | } |
| 1228 | |
| 1229 | static void |
| 1230 | test_mandatory_elem(void **state) |
| 1231 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1232 | struct test_parser_yin_state *st = *state; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1233 | const char *data; |
| 1234 | uint16_t man = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1235 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1236 | |
| 1237 | /* valid values */ |
| 1238 | data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1239 | assert_int_equal(test_element_helper(st, data, &man, NULL, NULL), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1240 | assert_int_equal(man, LYS_MAND_TRUE); |
| 1241 | man = 0; |
| 1242 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1243 | data = ELEMENT_WRAPPER_START "<mandatory value=\"false\">" EXT_SUBELEM "</mandatory>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1244 | assert_int_equal(test_element_helper(st, data, &man, NULL, &exts), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1245 | assert_int_equal(man, LYS_MAND_FALSE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1246 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1247 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1248 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MANDATORY); |
| 1249 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1250 | |
| 1251 | data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1252 | assert_int_equal(test_element_helper(st, data, &man, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 1253 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"mandatory\" element. Valid values are \"true\" and \"false\". Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1254 | |
| 1255 | st->finished_correctly = true; |
| 1256 | } |
| 1257 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1258 | static void |
| 1259 | test_argument_elem(void **state) |
| 1260 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1261 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1262 | const char *data; |
| 1263 | uint16_t flags = 0; |
| 1264 | const char *arg; |
| 1265 | struct yin_argument_meta arg_meta = {&flags, &arg}; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1266 | struct lysp_ext_instance *exts = NULL; |
| 1267 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1268 | /* max subelems */ |
| 1269 | data = ELEMENT_WRAPPER_START |
| 1270 | "<argument name=\"arg-name\">" |
| 1271 | "<yin-element value=\"true\" />" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1272 | EXT_SUBELEM |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1273 | "</argument>" |
| 1274 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1275 | assert_int_equal(test_element_helper(st, data, &arg_meta, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1276 | assert_string_equal(arg, "arg-name"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1277 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1278 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1279 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1280 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ARGUMENT); |
| 1281 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1282 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1283 | flags = 0; |
| 1284 | FREE_STRING(st->ctx, arg); |
| 1285 | arg = NULL; |
| 1286 | |
| 1287 | /* min subelems */ |
| 1288 | data = ELEMENT_WRAPPER_START |
| 1289 | "<argument name=\"arg\">" |
| 1290 | "</argument>" |
| 1291 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1292 | assert_int_equal(test_element_helper(st, data, &arg_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1293 | assert_string_equal(arg, "arg"); |
| 1294 | assert_true(flags == 0); |
| 1295 | FREE_STRING(st->ctx, arg); |
| 1296 | |
| 1297 | st->finished_correctly = true; |
| 1298 | } |
| 1299 | |
| 1300 | static void |
| 1301 | test_base_elem(void **state) |
| 1302 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1303 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1304 | const char *data; |
| 1305 | const char **bases = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1306 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1307 | struct lysp_type type = {}; |
| 1308 | |
| 1309 | /* as identity subelement */ |
| 1310 | data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1311 | "<base name=\"base-name\">" |
| 1312 | EXT_SUBELEM |
| 1313 | "</base>" |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1314 | "</identity>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1315 | assert_int_equal(test_element_helper(st, data, &bases, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1316 | assert_string_equal(*bases, "base-name"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1317 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1318 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1319 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE); |
| 1320 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1321 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1322 | FREE_STRING(st->ctx, *bases); |
| 1323 | LY_ARRAY_FREE(bases); |
| 1324 | |
| 1325 | /* as type subelement */ |
| 1326 | data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1327 | "<base name=\"base-name\">" |
| 1328 | EXT_SUBELEM |
| 1329 | "</base>" |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1330 | "</type>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1331 | assert_int_equal(test_element_helper(st, data, &type, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1332 | assert_string_equal(*type.bases, "base-name"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1333 | assert_true(type.flags & LYS_SET_BASE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1334 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1335 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1336 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE); |
| 1337 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1338 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1339 | FREE_STRING(st->ctx, *type.bases); |
| 1340 | LY_ARRAY_FREE(type.bases); |
| 1341 | |
| 1342 | st->finished_correctly = true; |
| 1343 | } |
| 1344 | |
| 1345 | static void |
| 1346 | test_belongsto_elem(void **state) |
| 1347 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1348 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1349 | const char *data; |
| 1350 | struct lysp_submodule submod; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1351 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1352 | |
| 1353 | data = ELEMENT_WRAPPER_START |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1354 | "<belongs-to module=\"module-name\"><prefix value=\"pref\"/>"EXT_SUBELEM"</belongs-to>" |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1355 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1356 | assert_int_equal(test_element_helper(st, data, &submod, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1357 | assert_string_equal(submod.belongsto, "module-name"); |
| 1358 | assert_string_equal(submod.prefix, "pref"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1359 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1360 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1361 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BELONGSTO); |
| 1362 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1363 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1364 | FREE_STRING(st->ctx, submod.belongsto); |
| 1365 | FREE_STRING(st->ctx, submod.prefix); |
| 1366 | |
| 1367 | data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1368 | assert_int_equal(test_element_helper(st, data, &submod, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1369 | logbuf_assert("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1370 | FREE_STRING(st->ctx, submod.belongsto); |
| 1371 | |
| 1372 | st->finished_correctly = true; |
| 1373 | } |
| 1374 | |
| 1375 | static void |
| 1376 | test_config_elem(void **state) |
| 1377 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1378 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1379 | const char *data; |
| 1380 | uint16_t flags = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1381 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1382 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1383 | data = ELEMENT_WRAPPER_START "<config value=\"true\">" EXT_SUBELEM "</config>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1384 | assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1385 | assert_true(flags & LYS_CONFIG_W); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1386 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1387 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1388 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONFIG); |
| 1389 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1390 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1391 | flags = 0; |
| 1392 | |
| 1393 | data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1394 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1395 | assert_true(flags & LYS_CONFIG_R); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1396 | flags = 0; |
| 1397 | |
| 1398 | data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1399 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 1400 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"config\" element. Valid values are \"true\" and \"false\". Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1401 | |
| 1402 | st->finished_correctly = true; |
| 1403 | } |
| 1404 | |
| 1405 | static void |
| 1406 | test_default_elem(void **state) |
| 1407 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1408 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1409 | const char *data; |
| 1410 | const char *val = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1411 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1412 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1413 | data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\">"EXT_SUBELEM"</default>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1414 | assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1415 | assert_string_equal(val, "defaul-value"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1416 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1417 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1418 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DEFAULT); |
| 1419 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1420 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1421 | FREE_STRING(st->ctx, val); |
| 1422 | val = NULL; |
| 1423 | |
| 1424 | data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1425 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1426 | logbuf_assert("Missing mandatory attribute value of default element. Line number 1."); |
| 1427 | |
| 1428 | st->finished_correctly = true; |
| 1429 | } |
| 1430 | |
| 1431 | static void |
| 1432 | test_err_app_tag_elem(void **state) |
| 1433 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1434 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1435 | const char *data; |
| 1436 | const char *val = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1437 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1438 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1439 | data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\">"EXT_SUBELEM"</error-app-tag>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1440 | assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1441 | assert_string_equal(val, "val"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1442 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1443 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1444 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRTAG); |
| 1445 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1446 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1447 | FREE_STRING(st->ctx, val); |
| 1448 | val = NULL; |
| 1449 | |
| 1450 | data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1451 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1452 | logbuf_assert("Missing mandatory attribute value of error-app-tag element. Line number 1."); |
| 1453 | |
| 1454 | st->finished_correctly = true; |
| 1455 | } |
| 1456 | |
| 1457 | static void |
| 1458 | test_err_msg_elem(void **state) |
| 1459 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1460 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1461 | const char *data; |
| 1462 | const char *val = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1463 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1464 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1465 | data = ELEMENT_WRAPPER_START "<error-message><value>val</value>"EXT_SUBELEM"</error-message>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1466 | assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1467 | assert_string_equal(val, "val"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1468 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1469 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1470 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRMSG); |
| 1471 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1472 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1473 | FREE_STRING(st->ctx, val); |
| 1474 | |
| 1475 | data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1476 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1477 | logbuf_assert("Missing mandatory sub-element \"value\" of \"error-message\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1478 | |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 1479 | data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1480 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1481 | logbuf_assert("Unexpected attribute \"invalid\" of \"error-message\" element. Line number 1."); |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 1482 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1483 | st->finished_correctly = true; |
| 1484 | } |
| 1485 | |
| 1486 | static void |
| 1487 | test_fracdigits_elem(void **state) |
| 1488 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1489 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1490 | const char *data; |
| 1491 | struct lysp_type type = {}; |
| 1492 | |
| 1493 | /* valid value */ |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1494 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\">"EXT_SUBELEM"</fraction-digits>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1495 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1496 | assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1497 | assert_int_equal(type.exts[0].insubstmt_index, 0); |
| 1498 | assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_FRACDIGITS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1499 | assert_int_equal(type.fraction_digits, 10); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1500 | assert_true(type.flags & LYS_SET_FRDIGITS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1501 | FREE_ARRAY(st->ctx, type.exts, lysp_ext_instance_free); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1502 | |
| 1503 | /* invalid values */ |
| 1504 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1505 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1506 | logbuf_assert("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1507 | |
| 1508 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1509 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1510 | logbuf_assert("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1511 | |
| 1512 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1513 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1514 | logbuf_assert("Invalid value \"1p\" of \"value\" attribute in \"fraction-digits\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1515 | |
| 1516 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1517 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1518 | logbuf_assert("Invalid value \"19\" of \"value\" attribute in \"fraction-digits\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1519 | |
| 1520 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1521 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1522 | logbuf_assert("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1523 | |
| 1524 | st->finished_correctly = true; |
| 1525 | } |
| 1526 | |
| 1527 | static void |
| 1528 | test_iffeature_elem(void **state) |
| 1529 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1530 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1531 | const char *data; |
| 1532 | const char **iffeatures = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1533 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1534 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1535 | data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\">"EXT_SUBELEM"</if-feature>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1536 | assert_int_equal(test_element_helper(st, data, &iffeatures, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1537 | assert_string_equal(*iffeatures, "local-storage"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1538 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1539 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1540 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_IFFEATURE); |
| 1541 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1542 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1543 | FREE_STRING(st->ctx, *iffeatures); |
| 1544 | LY_ARRAY_FREE(iffeatures); |
| 1545 | iffeatures = NULL; |
| 1546 | |
| 1547 | data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1548 | assert_int_equal(test_element_helper(st, data, &iffeatures, NULL, NULL), LY_EVALID); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1549 | logbuf_assert("Missing mandatory attribute name of if-feature element. Line number 1."); |
| 1550 | LY_ARRAY_FREE(iffeatures); |
| 1551 | iffeatures = NULL; |
| 1552 | |
| 1553 | st->finished_correctly = true; |
| 1554 | } |
| 1555 | |
| 1556 | static void |
| 1557 | test_length_elem(void **state) |
| 1558 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1559 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1560 | const char *data; |
| 1561 | struct lysp_type type = {}; |
| 1562 | |
| 1563 | /* max subelems */ |
| 1564 | data = ELEMENT_WRAPPER_START |
| 1565 | "<length value=\"length-str\">" |
| 1566 | "<error-message><value>err-msg</value></error-message>" |
| 1567 | "<error-app-tag value=\"err-app-tag\"/>" |
| 1568 | "<description><text>desc</text></description>" |
| 1569 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1570 | EXT_SUBELEM |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1571 | "</length>" |
| 1572 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1573 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1574 | assert_string_equal(type.length->arg, "length-str"); |
| 1575 | assert_string_equal(type.length->emsg, "err-msg"); |
| 1576 | assert_string_equal(type.length->eapptag, "err-app-tag"); |
| 1577 | assert_string_equal(type.length->dsc, "desc"); |
| 1578 | assert_string_equal(type.length->ref, "ref"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1579 | assert_true(type.flags & LYS_SET_LENGTH); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1580 | assert_string_equal(type.length->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1581 | assert_int_equal(type.length->exts[0].insubstmt_index, 0); |
| 1582 | assert_int_equal(type.length->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1583 | lysp_type_free(st->ctx, &type); |
| 1584 | memset(&type, 0, sizeof(type)); |
| 1585 | |
| 1586 | /* min subelems */ |
| 1587 | data = ELEMENT_WRAPPER_START |
| 1588 | "<length value=\"length-str\">" |
| 1589 | "</length>" |
| 1590 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1591 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1592 | assert_string_equal(type.length->arg, "length-str"); |
| 1593 | lysp_type_free(st->ctx, &type); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1594 | assert_true(type.flags & LYS_SET_LENGTH); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1595 | memset(&type, 0, sizeof(type)); |
| 1596 | |
| 1597 | data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1598 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1599 | logbuf_assert("Missing mandatory attribute value of length element. Line number 1."); |
| 1600 | lysp_type_free(st->ctx, &type); |
| 1601 | memset(&type, 0, sizeof(type)); |
| 1602 | |
| 1603 | st->finished_correctly = true; |
| 1604 | } |
| 1605 | |
| 1606 | static void |
| 1607 | test_modifier_elem(void **state) |
| 1608 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1609 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1610 | const char *data; |
| 1611 | const char *pat = lydict_insert(st->ctx, "\006pattern", 8); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1612 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1613 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1614 | data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\">" EXT_SUBELEM "</modifier>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1615 | assert_int_equal(test_element_helper(st, data, &pat, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1616 | assert_string_equal(pat, "\x015pattern"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1617 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1618 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1619 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MODIFIER); |
| 1620 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1621 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1622 | FREE_STRING(st->ctx, pat); |
| 1623 | |
| 1624 | pat = lydict_insert(st->ctx, "\006pattern", 8); |
| 1625 | data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1626 | assert_int_equal(test_element_helper(st, data, &pat, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 1627 | logbuf_assert("Invalid value \"invert\" of \"value\" attribute in \"modifier\" element. Only valid value is \"invert-match\". Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1628 | FREE_STRING(st->ctx, pat); |
| 1629 | |
| 1630 | st->finished_correctly = true; |
| 1631 | } |
| 1632 | |
| 1633 | static void |
| 1634 | test_namespace_elem(void **state) |
| 1635 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1636 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1637 | const char *data; |
| 1638 | const char *ns; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1639 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1640 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1641 | data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\">" EXT_SUBELEM "</namespace>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1642 | assert_int_equal(test_element_helper(st, data, &ns, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1643 | assert_string_equal(ns, "ns"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1644 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1645 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1646 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_NAMESPACE); |
| 1647 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1648 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1649 | FREE_STRING(st->ctx, ns); |
| 1650 | |
| 1651 | data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1652 | assert_int_equal(test_element_helper(st, data, &ns, NULL, NULL), LY_EVALID); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1653 | logbuf_assert("Missing mandatory attribute uri of namespace element. Line number 1."); |
| 1654 | |
| 1655 | st->finished_correctly = true; |
| 1656 | } |
| 1657 | |
| 1658 | static void |
| 1659 | test_path_elem(void **state) |
| 1660 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1661 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1662 | const char *data; |
| 1663 | struct lysp_type type = {}; |
| 1664 | |
David Sedlák | 169cc52 | 2019-08-15 13:23:45 +0200 | [diff] [blame] | 1665 | data = ELEMENT_WRAPPER_START "<path value=\"p&th-val\">" EXT_SUBELEM "</path>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1666 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 169cc52 | 2019-08-15 13:23:45 +0200 | [diff] [blame] | 1667 | assert_string_equal("p&th-val", type.path); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1668 | assert_true(type.flags & LYS_SET_PATH); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1669 | assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1670 | assert_int_equal(type.exts[0].insubstmt_index, 0); |
| 1671 | assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_PATH); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1672 | lysp_type_free(st->ctx, &type); |
| 1673 | |
| 1674 | st->finished_correctly = true; |
| 1675 | } |
| 1676 | |
| 1677 | static void |
| 1678 | test_pattern_elem(void **state) |
| 1679 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1680 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1681 | const char *data; |
| 1682 | struct lysp_type type = {}; |
| 1683 | |
| 1684 | /* max subelems */ |
| 1685 | data = ELEMENT_WRAPPER_START |
| 1686 | "<pattern value=\"super_pattern\">" |
| 1687 | "<modifier value=\"invert-match\"/>" |
| 1688 | "<error-message><value>err-msg-value</value></error-message>" |
| 1689 | "<error-app-tag value=\"err-app-tag-value\"/>" |
David Sedlák | 169cc52 | 2019-08-15 13:23:45 +0200 | [diff] [blame] | 1690 | "<description><text>"pattern-desc"</text></description>" |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1691 | "<reference><text>pattern-ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1692 | EXT_SUBELEM |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1693 | "</pattern>" |
| 1694 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1695 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1696 | assert_true(type.flags & LYS_SET_PATTERN); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1697 | assert_string_equal(type.patterns->arg, "\x015super_pattern"); |
David Sedlák | 169cc52 | 2019-08-15 13:23:45 +0200 | [diff] [blame] | 1698 | assert_string_equal(type.patterns->dsc, "\"pattern-desc\""); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1699 | assert_string_equal(type.patterns->eapptag, "err-app-tag-value"); |
| 1700 | assert_string_equal(type.patterns->emsg, "err-msg-value"); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1701 | assert_string_equal(type.patterns->ref, "pattern-ref"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1702 | assert_string_equal(type.patterns->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1703 | assert_int_equal(type.patterns->exts[0].insubstmt_index, 0); |
| 1704 | assert_int_equal(type.patterns->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1705 | lysp_type_free(st->ctx, &type); |
| 1706 | memset(&type, 0, sizeof(type)); |
| 1707 | |
| 1708 | /* min subelems */ |
| 1709 | data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1710 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1711 | assert_string_equal(type.patterns->arg, "\x006pattern"); |
| 1712 | lysp_type_free(st->ctx, &type); |
| 1713 | memset(&type, 0, sizeof(type)); |
| 1714 | |
| 1715 | st->finished_correctly = true; |
| 1716 | } |
| 1717 | |
| 1718 | static void |
| 1719 | test_value_position_elem(void **state) |
| 1720 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1721 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1722 | const char *data; |
| 1723 | struct lysp_type_enum en = {}; |
| 1724 | |
| 1725 | /* valid values */ |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1726 | data = ELEMENT_WRAPPER_START "<value value=\"55\">" EXT_SUBELEM "</value>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1727 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1728 | assert_int_equal(en.value, 55); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1729 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1730 | assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1731 | assert_int_equal(en.exts[0].insubstmt_index, 0); |
| 1732 | assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_VALUE); |
| 1733 | FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1734 | memset(&en, 0, sizeof(en)); |
| 1735 | |
| 1736 | data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1737 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1738 | assert_int_equal(en.value, -55); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1739 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1740 | memset(&en, 0, sizeof(en)); |
| 1741 | |
| 1742 | data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1743 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1744 | assert_int_equal(en.value, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1745 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1746 | memset(&en, 0, sizeof(en)); |
| 1747 | |
| 1748 | data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1749 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1750 | assert_int_equal(en.value, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1751 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1752 | memset(&en, 0, sizeof(en)); |
| 1753 | |
| 1754 | /* valid positions */ |
David Sedlák | 8d552d6 | 2019-08-06 15:29:05 +0200 | [diff] [blame] | 1755 | data = ELEMENT_WRAPPER_START "<position value=\"55\">" EXT_SUBELEM "</position>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1756 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1757 | assert_int_equal(en.value, 55); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1758 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1759 | assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | 8d552d6 | 2019-08-06 15:29:05 +0200 | [diff] [blame] | 1760 | assert_int_equal(en.exts[0].insubstmt_index, 0); |
| 1761 | assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_POSITION); |
| 1762 | FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1763 | memset(&en, 0, sizeof(en)); |
| 1764 | |
| 1765 | data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1766 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1767 | assert_int_equal(en.value, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1768 | assert_true(en.flags & LYS_SET_VALUE); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1769 | memset(&en, 0, sizeof(en)); |
| 1770 | |
| 1771 | /* invalid values */ |
| 1772 | data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1773 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1774 | logbuf_assert("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1775 | |
| 1776 | data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1777 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1778 | logbuf_assert("Invalid value \"1k\" of \"value\" attribute in \"value\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1779 | |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1780 | data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1781 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1782 | logbuf_assert("Invalid value \"\" of \"value\" attribute in \"value\" element. Line number 1."); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1783 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1784 | /*invalid positions */ |
| 1785 | data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1786 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1787 | logbuf_assert("Invalid value \"-5\" of \"value\" attribute in \"position\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1788 | |
| 1789 | data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1790 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1791 | logbuf_assert("Invalid value \"-0\" of \"value\" attribute in \"position\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1792 | |
| 1793 | data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1794 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1795 | logbuf_assert("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element. Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1796 | |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1797 | data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1798 | assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 1799 | logbuf_assert("Invalid value \"\" of \"value\" attribute in \"position\" element. Line number 1."); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1800 | |
| 1801 | st->finished_correctly = true; |
| 1802 | } |
| 1803 | |
| 1804 | static void |
| 1805 | test_prefix_elem(void **state) |
| 1806 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1807 | struct test_parser_yin_state *st = *state; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1808 | const char *data; |
| 1809 | const char *value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1810 | struct lysp_ext_instance *exts = NULL; |
| 1811 | |
| 1812 | data = ELEMENT_WRAPPER_START "<prefix value=\"pref\">" EXT_SUBELEM "</prefix>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1813 | assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1814 | assert_string_equal(value, "pref"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1815 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1816 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1817 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PREFIX); |
| 1818 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1819 | exts = NULL; |
| 1820 | FREE_STRING(st->ctx, value); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1821 | |
| 1822 | data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1823 | assert_int_equal(test_element_helper(st, data, &value, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1824 | assert_string_equal(value, "pref"); |
| 1825 | FREE_STRING(st->ctx, value); |
| 1826 | |
| 1827 | st->finished_correctly = true; |
| 1828 | } |
| 1829 | |
| 1830 | static void |
| 1831 | test_range_elem(void **state) |
| 1832 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1833 | struct test_parser_yin_state *st = *state; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1834 | const char *data; |
| 1835 | struct lysp_type type = {}; |
| 1836 | |
| 1837 | /* max subelems */ |
| 1838 | data = ELEMENT_WRAPPER_START |
| 1839 | "<range value=\"range-str\">" |
| 1840 | "<error-message><value>err-msg</value></error-message>" |
| 1841 | "<error-app-tag value=\"err-app-tag\" />" |
| 1842 | "<description><text>desc</text></description>" |
| 1843 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1844 | EXT_SUBELEM |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1845 | "</range>" |
| 1846 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1847 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1848 | assert_string_equal(type.range->arg, "range-str"); |
| 1849 | assert_string_equal(type.range->dsc, "desc"); |
| 1850 | assert_string_equal(type.range->eapptag, "err-app-tag"); |
| 1851 | assert_string_equal(type.range->emsg, "err-msg"); |
| 1852 | assert_string_equal(type.range->ref, "ref"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1853 | assert_true(type.flags & LYS_SET_RANGE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1854 | assert_string_equal(type.range->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1855 | assert_int_equal(type.range->exts[0].insubstmt_index, 0); |
| 1856 | assert_int_equal(type.range->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1857 | lysp_type_free(st->ctx, &type); |
| 1858 | memset(&type, 0, sizeof(type)); |
| 1859 | |
| 1860 | /* min subelems */ |
| 1861 | data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1862 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1863 | assert_string_equal(type.range->arg, "range-str"); |
| 1864 | lysp_type_free(st->ctx, &type); |
| 1865 | memset(&type, 0, sizeof(type)); |
| 1866 | |
| 1867 | st->finished_correctly = true; |
| 1868 | } |
| 1869 | |
| 1870 | static void |
| 1871 | test_reqinstance_elem(void **state) |
| 1872 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1873 | struct test_parser_yin_state *st = *state; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1874 | const char *data; |
| 1875 | struct lysp_type type = {}; |
| 1876 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1877 | data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1878 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1879 | assert_int_equal(type.require_instance, 1); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1880 | assert_true(type.flags & LYS_SET_REQINST); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1881 | assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1882 | assert_int_equal(type.exts[0].insubstmt_index, 0); |
| 1883 | assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_REQINSTANCE); |
| 1884 | lysp_type_free(st->ctx, &type); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1885 | memset(&type, 0, sizeof(type)); |
| 1886 | |
| 1887 | data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1888 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1889 | assert_int_equal(type.require_instance, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1890 | assert_true(type.flags & LYS_SET_REQINST); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1891 | memset(&type, 0, sizeof(type)); |
| 1892 | |
| 1893 | data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1894 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1895 | memset(&type, 0, sizeof(type)); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 1896 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"require-instance\" element. Valid values are \"true\" and \"false\". Line number 1."); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1897 | |
| 1898 | st->finished_correctly = true; |
| 1899 | } |
| 1900 | |
| 1901 | static void |
| 1902 | test_revision_date_elem(void **state) |
| 1903 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1904 | struct test_parser_yin_state *st = *state; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1905 | const char *data; |
| 1906 | char rev[LY_REV_SIZE]; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1907 | struct lysp_ext_instance *exts = NULL; |
| 1908 | |
| 1909 | data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\">"EXT_SUBELEM"</revision-date>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1910 | assert_int_equal(test_element_helper(st, data, rev, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1911 | assert_string_equal(rev, "2000-01-01"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1912 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1913 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1914 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REVISIONDATE); |
| 1915 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1916 | |
| 1917 | data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1918 | assert_int_equal(test_element_helper(st, data, rev, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1919 | assert_string_equal(rev, "2000-01-01"); |
| 1920 | |
| 1921 | data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1922 | assert_int_equal(test_element_helper(st, data, rev, NULL, NULL), LY_EVALID); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1923 | logbuf_assert("Invalid value \"2000-50-05\" of \"revision-date\". Line number 1."); |
| 1924 | |
| 1925 | st->finished_correctly = true; |
| 1926 | } |
| 1927 | |
| 1928 | static void |
| 1929 | test_unique_elem(void **state) |
| 1930 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1931 | struct test_parser_yin_state *st = *state; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1932 | const char *data; |
| 1933 | const char **values = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1934 | struct lysp_ext_instance *exts = NULL; |
| 1935 | |
| 1936 | data = ELEMENT_WRAPPER_START "<unique tag=\"tag\">"EXT_SUBELEM"</unique>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1937 | assert_int_equal(test_element_helper(st, data, &values, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1938 | assert_string_equal(*values, "tag"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1939 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1940 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1941 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNIQUE); |
| 1942 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1943 | FREE_STRING(st->ctx, *values); |
| 1944 | LY_ARRAY_FREE(values); |
| 1945 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1946 | |
| 1947 | data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1948 | assert_int_equal(test_element_helper(st, data, &values, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1949 | assert_string_equal(*values, "tag"); |
| 1950 | FREE_STRING(st->ctx, *values); |
| 1951 | LY_ARRAY_FREE(values); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1952 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1953 | |
| 1954 | st->finished_correctly = true; |
| 1955 | } |
| 1956 | |
| 1957 | static void |
| 1958 | test_units_elem(void **state) |
| 1959 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1960 | struct test_parser_yin_state *st = *state; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1961 | const char *data; |
| 1962 | const char *values = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1963 | struct lysp_ext_instance *exts = NULL; |
| 1964 | |
| 1965 | data = ELEMENT_WRAPPER_START "<units name=\"name\">"EXT_SUBELEM"</units>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1966 | assert_int_equal(test_element_helper(st, data, &values, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1967 | assert_string_equal(values, "name"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 1968 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1969 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 1970 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNITS); |
| 1971 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 1972 | FREE_STRING(st->ctx, values); |
| 1973 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1974 | |
| 1975 | data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1976 | assert_int_equal(test_element_helper(st, data, &values, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1977 | assert_string_equal(values, "name"); |
| 1978 | FREE_STRING(st->ctx, values); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1979 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1980 | |
| 1981 | st->finished_correctly = true; |
| 1982 | } |
| 1983 | |
| 1984 | static void |
| 1985 | test_when_elem(void **state) |
| 1986 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 1987 | struct test_parser_yin_state *st = *state; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1988 | const char *data; |
| 1989 | struct lysp_when *when = NULL; |
| 1990 | |
| 1991 | data = ELEMENT_WRAPPER_START |
| 1992 | "<when condition=\"cond\">" |
| 1993 | "<description><text>desc</text></description>" |
| 1994 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1995 | EXT_SUBELEM |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1996 | "</when>" |
| 1997 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1998 | assert_int_equal(test_element_helper(st, data, &when, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1999 | assert_string_equal(when->cond, "cond"); |
| 2000 | assert_string_equal(when->dsc, "desc"); |
| 2001 | assert_string_equal(when->ref, "ref"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2002 | assert_string_equal(when->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2003 | assert_int_equal(when->exts[0].insubstmt_index, 0); |
| 2004 | assert_int_equal(when->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 2005 | lysp_when_free(st->ctx, when); |
| 2006 | free(when); |
| 2007 | when = NULL; |
| 2008 | |
| 2009 | data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2010 | assert_int_equal(test_element_helper(st, data, &when, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 2011 | assert_string_equal(when->cond, "cond"); |
| 2012 | lysp_when_free(st->ctx, when); |
| 2013 | free(when); |
| 2014 | when = NULL; |
| 2015 | |
| 2016 | st->finished_correctly = true; |
| 2017 | } |
| 2018 | |
| 2019 | static void |
| 2020 | test_yin_text_value_elem(void **state) |
| 2021 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2022 | struct test_parser_yin_state *st = *state; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 2023 | const char *data; |
| 2024 | const char *val; |
| 2025 | |
| 2026 | data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2027 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 2028 | assert_string_equal(val, "text"); |
| 2029 | FREE_STRING(st->ctx, val); |
| 2030 | |
| 2031 | data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2032 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 2033 | assert_string_equal(val, "text"); |
| 2034 | FREE_STRING(st->ctx, val); |
| 2035 | |
| 2036 | data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2037 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 2038 | assert_string_equal("", val); |
| 2039 | FREE_STRING(st->ctx, val); |
| 2040 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 2041 | st->finished_correctly = true; |
| 2042 | } |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 2043 | |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 2044 | static void |
| 2045 | test_type_elem(void **state) |
| 2046 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2047 | struct test_parser_yin_state *st = *state; |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 2048 | const char *data; |
| 2049 | struct lysp_type type = {}; |
| 2050 | |
| 2051 | /* max subelems */ |
| 2052 | data = ELEMENT_WRAPPER_START |
| 2053 | "<type name=\"type-name\">" |
| 2054 | "<base name=\"base-name\"/>" |
| 2055 | "<bit name=\"bit\"/>" |
| 2056 | "<enum name=\"enum\"/>" |
| 2057 | "<fraction-digits value=\"2\"/>" |
| 2058 | "<length value=\"length\"/>" |
| 2059 | "<path value=\"path\"/>" |
| 2060 | "<pattern value=\"pattern\"/>" |
| 2061 | "<range value=\"range\" />" |
| 2062 | "<require-instance value=\"true\"/>" |
| 2063 | "<type name=\"sub-type-name\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2064 | EXT_SUBELEM |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 2065 | "</type>" |
| 2066 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2067 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 2068 | assert_string_equal(type.name, "type-name"); |
| 2069 | assert_string_equal(*type.bases, "base-name"); |
| 2070 | assert_string_equal(type.bits->name, "bit"); |
| 2071 | assert_string_equal(type.enums->name, "enum"); |
| 2072 | assert_int_equal(type.fraction_digits, 2); |
| 2073 | assert_string_equal(type.length->arg, "length"); |
| 2074 | assert_string_equal(type.path, "path"); |
| 2075 | assert_string_equal(type.patterns->arg, "\006pattern"); |
| 2076 | assert_string_equal(type.range->arg, "range"); |
| 2077 | assert_int_equal(type.require_instance, 1); |
| 2078 | assert_string_equal(type.types->name, "sub-type-name"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2079 | assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2080 | assert_int_equal(type.exts[0].insubstmt_index, 0); |
| 2081 | assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2082 | assert_true(type.flags & LYS_SET_BASE); |
| 2083 | assert_true(type.flags & LYS_SET_BIT); |
| 2084 | assert_true(type.flags & LYS_SET_ENUM); |
| 2085 | assert_true(type.flags & LYS_SET_FRDIGITS); |
| 2086 | assert_true(type.flags & LYS_SET_LENGTH); |
| 2087 | assert_true(type.flags & LYS_SET_PATH); |
| 2088 | assert_true(type.flags & LYS_SET_PATTERN); |
| 2089 | assert_true(type.flags & LYS_SET_RANGE); |
| 2090 | assert_true(type.flags & LYS_SET_REQINST); |
| 2091 | assert_true(type.flags & LYS_SET_TYPE); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2092 | lysp_type_free(st->ctx, &type); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 2093 | memset(&type, 0, sizeof(type)); |
| 2094 | |
| 2095 | /* min subelems */ |
| 2096 | data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2097 | assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 2098 | lysp_type_free(st->ctx, &type); |
| 2099 | memset(&type, 0, sizeof(type)); |
| 2100 | |
| 2101 | st->finished_correctly = true; |
| 2102 | } |
| 2103 | |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2104 | static void |
| 2105 | test_max_elems_elem(void **state) |
| 2106 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2107 | struct test_parser_yin_state *st = *state; |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2108 | const char *data; |
| 2109 | struct lysp_node_list list = {}; |
| 2110 | struct lysp_node_leaflist llist = {}; |
| 2111 | struct lysp_refine refine = {}; |
| 2112 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2113 | data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"unbounded\">"EXT_SUBELEM"</max-elements> </refine>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2114 | assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2115 | assert_int_equal(refine.max, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2116 | assert_true(refine.flags & LYS_SET_MAX); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2117 | assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2118 | assert_int_equal(refine.exts[0].insubstmt_index, 0); |
| 2119 | assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MAX); |
| 2120 | FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2121 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2122 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"5\">"EXT_SUBELEM"</max-elements> </list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2123 | assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_SUCCESS); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2124 | assert_int_equal(list.max, 5); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2125 | assert_true(list.flags & LYS_SET_MAX); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2126 | assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2127 | assert_int_equal(list.exts[0].insubstmt_index, 0); |
| 2128 | assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MAX); |
| 2129 | FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2130 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2131 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"85\">"EXT_SUBELEM"</max-elements> </leaf-list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2132 | assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_SUCCESS); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2133 | assert_int_equal(llist.max, 85); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2134 | assert_true(llist.flags & LYS_SET_MAX); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2135 | assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2136 | assert_int_equal(llist.exts[0].insubstmt_index, 0); |
| 2137 | assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MAX); |
| 2138 | FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2139 | |
| 2140 | data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2141 | assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2142 | assert_int_equal(refine.max, 10); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2143 | assert_true(refine.flags & LYS_SET_MAX); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2144 | |
| 2145 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2146 | assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2147 | logbuf_assert("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element. Line number 1."); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2148 | |
| 2149 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2150 | assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2151 | logbuf_assert("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element. Line number 1."); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2152 | |
| 2153 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2154 | assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2155 | logbuf_assert("Invalid value \"k\" of \"value\" attribute in \"max-elements\" element. Line number 1."); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2156 | |
| 2157 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2158 | assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2159 | logbuf_assert("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element. Line number 1."); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 2160 | |
| 2161 | st->finished_correctly = true; |
| 2162 | } |
| 2163 | |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2164 | static void |
| 2165 | test_min_elems_elem(void **state) |
| 2166 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2167 | struct test_parser_yin_state *st = *state; |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2168 | const char *data; |
| 2169 | struct lysp_node_list list = {}; |
| 2170 | struct lysp_node_leaflist llist = {}; |
| 2171 | struct lysp_refine refine = {}; |
| 2172 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2173 | data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"0\">"EXT_SUBELEM"</min-elements> </refine>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2174 | assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2175 | assert_int_equal(refine.min, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2176 | assert_true(refine.flags & LYS_SET_MIN); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2177 | assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2178 | assert_int_equal(refine.exts[0].insubstmt_index, 0); |
| 2179 | assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MIN); |
| 2180 | FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2181 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2182 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"41\">"EXT_SUBELEM"</min-elements> </list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2183 | assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_SUCCESS); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2184 | assert_int_equal(list.min, 41); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2185 | assert_true(list.flags & LYS_SET_MIN); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2186 | assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2187 | assert_int_equal(list.exts[0].insubstmt_index, 0); |
| 2188 | assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MIN); |
| 2189 | FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2190 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2191 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"50\">"EXT_SUBELEM"</min-elements> </leaf-list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2192 | assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_SUCCESS); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2193 | assert_int_equal(llist.min, 50); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2194 | assert_true(llist.flags & LYS_SET_MIN); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2195 | assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2196 | assert_int_equal(llist.exts[0].insubstmt_index, 0); |
| 2197 | assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MIN); |
| 2198 | FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2199 | |
| 2200 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2201 | assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2202 | logbuf_assert("Value \"-5\" of \"value\" attribute in \"min-elements\" element is out of bounds. Line number 1."); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2203 | |
| 2204 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2205 | assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2206 | logbuf_assert("Value \"99999999999999999\" of \"value\" attribute in \"min-elements\" element is out of bounds. Line number 1."); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2207 | |
| 2208 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2209 | assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2210 | logbuf_assert("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element. Line number 1."); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2211 | |
| 2212 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"05\"/> </leaf-list>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2213 | assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2214 | logbuf_assert("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element. Line number 1."); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 2215 | |
| 2216 | st->finished_correctly = true; |
| 2217 | } |
| 2218 | |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2219 | static void |
| 2220 | test_ordby_elem(void **state) |
| 2221 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2222 | struct test_parser_yin_state *st = *state; |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2223 | const char *data; |
| 2224 | uint16_t flags = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2225 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2226 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2227 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\">"EXT_SUBELEM"</ordered-by>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2228 | assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2229 | assert_true(flags & LYS_ORDBY_SYSTEM); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2230 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2231 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 2232 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORDEREDBY); |
| 2233 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2234 | |
| 2235 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2236 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2237 | assert_true(flags & LYS_ORDBY_USER); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2238 | |
| 2239 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2240 | assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 2241 | logbuf_assert("Invalid value \"inv\" of \"value\" attribute in \"ordered-by\" element. Valid values are \"system\" and \"user\". Line number 1."); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 2242 | |
| 2243 | st->finished_correctly = true; |
| 2244 | } |
| 2245 | |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2246 | static void |
| 2247 | test_any_elem(void **state) |
| 2248 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2249 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2250 | const char *data; |
| 2251 | struct lysp_node *siblings = NULL; |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2252 | struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings}; |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2253 | struct lysp_node_anydata *parsed = NULL; |
| 2254 | |
| 2255 | /* anyxml max subelems */ |
| 2256 | data = ELEMENT_WRAPPER_START |
| 2257 | "<anyxml name=\"any-name\">" |
| 2258 | "<config value=\"true\" />" |
| 2259 | "<description><text>desc</text></description>" |
| 2260 | "<if-feature name=\"feature\" />" |
| 2261 | "<mandatory value=\"true\" />" |
| 2262 | "<must condition=\"must-cond\" />" |
| 2263 | "<reference><text>ref</text></reference>" |
| 2264 | "<status value=\"deprecated\"/>" |
| 2265 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2266 | EXT_SUBELEM |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2267 | "</anyxml>" |
| 2268 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2269 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2270 | parsed = (struct lysp_node_anydata *)siblings; |
| 2271 | assert_null(parsed->parent); |
| 2272 | assert_int_equal(parsed->nodetype, LYS_ANYXML); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2273 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2274 | assert_true(parsed->flags & LYS_MAND_TRUE); |
| 2275 | assert_true(parsed->flags & LYS_STATUS_DEPRC); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2276 | assert_null(parsed->next); |
| 2277 | assert_string_equal(parsed->name, "any-name"); |
| 2278 | assert_string_equal(parsed->dsc, "desc"); |
| 2279 | assert_string_equal(parsed->ref, "ref"); |
| 2280 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2281 | assert_string_equal(*parsed->iffeatures, "feature"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2282 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2283 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2284 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2285 | lysp_node_free(st->ctx, siblings); |
| 2286 | siblings = NULL; |
| 2287 | |
| 2288 | /* anydata max subelems */ |
| 2289 | data = ELEMENT_WRAPPER_START |
| 2290 | "<anydata name=\"any-name\">" |
| 2291 | "<config value=\"true\" />" |
| 2292 | "<description><text>desc</text></description>" |
| 2293 | "<if-feature name=\"feature\" />" |
| 2294 | "<mandatory value=\"true\" />" |
| 2295 | "<must condition=\"must-cond\" />" |
| 2296 | "<reference><text>ref</text></reference>" |
| 2297 | "<status value=\"deprecated\"/>" |
| 2298 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2299 | EXT_SUBELEM |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2300 | "</anydata>" |
| 2301 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2302 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2303 | parsed = (struct lysp_node_anydata *)siblings; |
| 2304 | assert_null(parsed->parent); |
| 2305 | assert_int_equal(parsed->nodetype, LYS_ANYDATA); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2306 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2307 | assert_true(parsed->flags & LYS_MAND_TRUE); |
| 2308 | assert_true(parsed->flags & LYS_STATUS_DEPRC); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2309 | assert_null(parsed->next); |
| 2310 | assert_string_equal(parsed->name, "any-name"); |
| 2311 | assert_string_equal(parsed->dsc, "desc"); |
| 2312 | assert_string_equal(parsed->ref, "ref"); |
| 2313 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2314 | assert_string_equal(*parsed->iffeatures, "feature"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2315 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2316 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2317 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2318 | lysp_node_free(st->ctx, siblings); |
| 2319 | siblings = NULL; |
| 2320 | |
| 2321 | /* min subelems */ |
| 2322 | node_meta.parent = (void *)0x10; |
| 2323 | data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2324 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2325 | parsed = (struct lysp_node_anydata *)siblings; |
| 2326 | assert_ptr_equal(parsed->parent, node_meta.parent); |
| 2327 | assert_int_equal(parsed->nodetype, LYS_ANYDATA); |
| 2328 | assert_null(parsed->next); |
| 2329 | assert_null(parsed->exts); |
| 2330 | lysp_node_free(st->ctx, siblings); |
| 2331 | |
| 2332 | st->finished_correctly = true; |
| 2333 | } |
| 2334 | |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2335 | static void |
| 2336 | test_leaf_elem(void **state) |
| 2337 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2338 | struct test_parser_yin_state *st = *state; |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2339 | const char *data; |
| 2340 | struct lysp_node *siblings = NULL; |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2341 | struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings}; |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2342 | struct lysp_node_leaf *parsed = NULL; |
| 2343 | |
| 2344 | /* max elements */ |
| 2345 | data = ELEMENT_WRAPPER_START |
| 2346 | "<leaf name=\"leaf\">" |
| 2347 | "<config value=\"true\" />" |
| 2348 | "<default value=\"def-val\"/>" |
| 2349 | "<description><text>desc</text></description>" |
| 2350 | "<if-feature name=\"feature\" />" |
| 2351 | "<mandatory value=\"true\" />" |
| 2352 | "<must condition=\"must-cond\" />" |
| 2353 | "<reference><text>ref</text></reference>" |
| 2354 | "<status value=\"deprecated\"/>" |
| 2355 | "<type name=\"type\"/>" |
| 2356 | "<units name=\"uni\"/>" |
| 2357 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2358 | EXT_SUBELEM |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2359 | "</leaf>" |
| 2360 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2361 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2362 | parsed = (struct lysp_node_leaf *)siblings; |
| 2363 | assert_null(parsed->parent); |
| 2364 | assert_int_equal(parsed->nodetype, LYS_LEAF); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2365 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2366 | assert_true(parsed->flags & LYS_MAND_TRUE); |
| 2367 | assert_true(parsed->flags & LYS_STATUS_DEPRC); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2368 | assert_null(parsed->next); |
| 2369 | assert_string_equal(parsed->name, "leaf"); |
| 2370 | assert_string_equal(parsed->dsc, "desc"); |
| 2371 | assert_string_equal(parsed->ref, "ref"); |
| 2372 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2373 | assert_string_equal(*parsed->iffeatures, "feature"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2374 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2375 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2376 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2377 | assert_string_equal(parsed->musts->arg, "must-cond"); |
| 2378 | assert_string_equal(parsed->type.name, "type"); |
| 2379 | assert_string_equal(parsed->units, "uni"); |
| 2380 | assert_string_equal(parsed->dflt, "def-val"); |
| 2381 | lysp_node_free(st->ctx, siblings); |
| 2382 | siblings = NULL; |
| 2383 | |
| 2384 | /* min elements */ |
| 2385 | data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2386 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2387 | parsed = (struct lysp_node_leaf *)siblings; |
| 2388 | assert_string_equal(parsed->name, "leaf"); |
| 2389 | assert_string_equal(parsed->type.name, "type"); |
| 2390 | lysp_node_free(st->ctx, siblings); |
| 2391 | siblings = NULL; |
| 2392 | |
| 2393 | st->finished_correctly = true; |
| 2394 | } |
| 2395 | |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2396 | static void |
| 2397 | test_leaf_list_elem(void **state) |
| 2398 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2399 | struct test_parser_yin_state *st = *state; |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2400 | const char *data; |
| 2401 | struct lysp_node *siblings = NULL; |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2402 | struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings}; |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2403 | struct lysp_node_leaflist *parsed = NULL; |
| 2404 | |
| 2405 | data = ELEMENT_WRAPPER_START |
| 2406 | "<leaf-list name=\"llist\">" |
| 2407 | "<config value=\"true\" />" |
| 2408 | "<default value=\"def-val0\"/>" |
| 2409 | "<default value=\"def-val1\"/>" |
| 2410 | "<description><text>desc</text></description>" |
| 2411 | "<if-feature name=\"feature\"/>" |
| 2412 | "<max-elements value=\"5\"/>" |
| 2413 | "<must condition=\"must-cond\"/>" |
| 2414 | "<ordered-by value=\"user\" />" |
| 2415 | "<reference><text>ref</text></reference>" |
| 2416 | "<status value=\"current\"/>" |
| 2417 | "<type name=\"type\"/>" |
| 2418 | "<units name=\"uni\"/>" |
| 2419 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2420 | EXT_SUBELEM |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2421 | "</leaf-list>" |
| 2422 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2423 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2424 | parsed = (struct lysp_node_leaflist *)siblings; |
| 2425 | assert_string_equal(parsed->dflts[0], "def-val0"); |
| 2426 | assert_string_equal(parsed->dflts[1], "def-val1"); |
| 2427 | assert_string_equal(parsed->dsc, "desc"); |
| 2428 | assert_string_equal(*parsed->iffeatures, "feature"); |
| 2429 | assert_int_equal(parsed->max, 5); |
| 2430 | assert_string_equal(parsed->musts->arg, "must-cond"); |
| 2431 | assert_string_equal(parsed->name, "llist"); |
| 2432 | assert_null(parsed->next); |
| 2433 | assert_int_equal(parsed->nodetype, LYS_LEAFLIST); |
| 2434 | assert_null(parsed->parent); |
| 2435 | assert_string_equal(parsed->ref, "ref"); |
| 2436 | assert_string_equal(parsed->type.name, "type"); |
| 2437 | assert_string_equal(parsed->units, "uni"); |
| 2438 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2439 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2440 | assert_true(parsed->flags & LYS_ORDBY_USER); |
| 2441 | assert_true(parsed->flags & LYS_STATUS_CURR); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2442 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2443 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2444 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2445 | lysp_node_free(st->ctx, siblings); |
| 2446 | siblings = NULL; |
| 2447 | |
| 2448 | data = ELEMENT_WRAPPER_START |
| 2449 | "<leaf-list name=\"llist\">" |
| 2450 | "<config value=\"true\" />" |
| 2451 | "<description><text>desc</text></description>" |
| 2452 | "<if-feature name=\"feature\"/>" |
| 2453 | "<min-elements value=\"5\"/>" |
| 2454 | "<must condition=\"must-cond\"/>" |
| 2455 | "<ordered-by value=\"user\" />" |
| 2456 | "<reference><text>ref</text></reference>" |
| 2457 | "<status value=\"current\"/>" |
| 2458 | "<type name=\"type\"/>" |
| 2459 | "<units name=\"uni\"/>" |
| 2460 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2461 | EXT_SUBELEM |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2462 | "</leaf-list>" |
| 2463 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2464 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2465 | parsed = (struct lysp_node_leaflist *)siblings; |
| 2466 | assert_string_equal(parsed->dsc, "desc"); |
| 2467 | assert_string_equal(*parsed->iffeatures, "feature"); |
| 2468 | assert_int_equal(parsed->min, 5); |
| 2469 | assert_string_equal(parsed->musts->arg, "must-cond"); |
| 2470 | assert_string_equal(parsed->name, "llist"); |
| 2471 | assert_null(parsed->next); |
| 2472 | assert_int_equal(parsed->nodetype, LYS_LEAFLIST); |
| 2473 | assert_null(parsed->parent); |
| 2474 | assert_string_equal(parsed->ref, "ref"); |
| 2475 | assert_string_equal(parsed->type.name, "type"); |
| 2476 | assert_string_equal(parsed->units, "uni"); |
| 2477 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2478 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2479 | assert_true(parsed->flags & LYS_ORDBY_USER); |
| 2480 | assert_true(parsed->flags & LYS_STATUS_CURR); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2481 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2482 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2483 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2484 | lysp_node_free(st->ctx, siblings); |
| 2485 | siblings = NULL; |
| 2486 | |
| 2487 | data = ELEMENT_WRAPPER_START |
| 2488 | "<leaf-list name=\"llist\">" |
| 2489 | "<config value=\"true\" />" |
| 2490 | "<description><text>desc</text></description>" |
| 2491 | "<if-feature name=\"feature\"/>" |
| 2492 | "<max-elements value=\"15\"/>" |
| 2493 | "<min-elements value=\"5\"/>" |
| 2494 | "<must condition=\"must-cond\"/>" |
| 2495 | "<ordered-by value=\"user\" />" |
| 2496 | "<reference><text>ref</text></reference>" |
| 2497 | "<status value=\"current\"/>" |
| 2498 | "<type name=\"type\"/>" |
| 2499 | "<units name=\"uni\"/>" |
| 2500 | "<when condition=\"when-cond\"/>" |
| 2501 | "</leaf-list>" |
| 2502 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2503 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2504 | parsed = (struct lysp_node_leaflist *)siblings; |
| 2505 | assert_string_equal(parsed->dsc, "desc"); |
| 2506 | assert_string_equal(*parsed->iffeatures, "feature"); |
| 2507 | assert_int_equal(parsed->min, 5); |
| 2508 | assert_int_equal(parsed->max, 15); |
| 2509 | assert_string_equal(parsed->musts->arg, "must-cond"); |
| 2510 | assert_string_equal(parsed->name, "llist"); |
| 2511 | assert_null(parsed->next); |
| 2512 | assert_int_equal(parsed->nodetype, LYS_LEAFLIST); |
| 2513 | assert_null(parsed->parent); |
| 2514 | assert_string_equal(parsed->ref, "ref"); |
| 2515 | assert_string_equal(parsed->type.name, "type"); |
| 2516 | assert_string_equal(parsed->units, "uni"); |
| 2517 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 2518 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2519 | assert_true(parsed->flags & LYS_ORDBY_USER); |
| 2520 | assert_true(parsed->flags & LYS_STATUS_CURR); |
| 2521 | lysp_node_free(st->ctx, siblings); |
| 2522 | siblings = NULL; |
| 2523 | |
| 2524 | data = ELEMENT_WRAPPER_START |
| 2525 | "<leaf-list name=\"llist\">" |
| 2526 | "<type name=\"type\"/>" |
| 2527 | "</leaf-list>" |
| 2528 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2529 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2530 | parsed = (struct lysp_node_leaflist *)siblings; |
| 2531 | assert_string_equal(parsed->name, "llist"); |
| 2532 | assert_string_equal(parsed->type.name, "type"); |
| 2533 | lysp_node_free(st->ctx, siblings); |
| 2534 | siblings = NULL; |
| 2535 | |
| 2536 | /* invalid combinations */ |
| 2537 | data = ELEMENT_WRAPPER_START |
| 2538 | "<leaf-list name=\"llist\">" |
| 2539 | "<max-elements value=\"5\"/>" |
| 2540 | "<min-elements value=\"15\"/>" |
| 2541 | "<type name=\"type\"/>" |
| 2542 | "</leaf-list>" |
| 2543 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2544 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2545 | logbuf_assert("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5. Line number 1."); |
| 2546 | lysp_node_free(st->ctx, siblings); |
| 2547 | siblings = NULL; |
| 2548 | |
| 2549 | data = ELEMENT_WRAPPER_START |
| 2550 | "<leaf-list name=\"llist\">" |
| 2551 | "<default value=\"def-val1\"/>" |
| 2552 | "<min-elements value=\"15\"/>" |
| 2553 | "<type name=\"type\"/>" |
| 2554 | "</leaf-list>" |
| 2555 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2556 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2557 | logbuf_assert("Invalid combination of sub-elemnts \"min-elements\" and \"default\" in \"leaf-list\" element. Line number 1."); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2558 | lysp_node_free(st->ctx, siblings); |
| 2559 | siblings = NULL; |
| 2560 | |
| 2561 | data = ELEMENT_WRAPPER_START |
| 2562 | "<leaf-list name=\"llist\">" |
| 2563 | "</leaf-list>" |
| 2564 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2565 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 2566 | logbuf_assert("Missing mandatory sub-element \"type\" of \"leaf-list\" element. Line number 1."); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2567 | lysp_node_free(st->ctx, siblings); |
| 2568 | siblings = NULL; |
| 2569 | |
| 2570 | st->finished_correctly = true; |
| 2571 | } |
| 2572 | |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2573 | static void |
| 2574 | test_presence_elem(void **state) |
| 2575 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2576 | struct test_parser_yin_state *st = *state; |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2577 | const char *data; |
| 2578 | const char *val; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2579 | struct lysp_ext_instance *exts = NULL; |
| 2580 | |
| 2581 | data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\">"EXT_SUBELEM"</presence>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2582 | assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2583 | assert_string_equal(val, "presence-val"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2584 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2585 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 2586 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PRESENCE); |
| 2587 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 2588 | FREE_STRING(st->ctx, val); |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2589 | |
| 2590 | data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2591 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2592 | assert_string_equal(val, "presence-val"); |
| 2593 | FREE_STRING(st->ctx, val); |
| 2594 | |
| 2595 | data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2596 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID); |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2597 | logbuf_assert("Missing mandatory attribute value of presence element. Line number 1."); |
| 2598 | |
| 2599 | st->finished_correctly = true; |
| 2600 | } |
| 2601 | |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2602 | static void |
| 2603 | test_key_elem(void **state) |
| 2604 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2605 | struct test_parser_yin_state *st = *state; |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2606 | const char *data; |
| 2607 | const char *val; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2608 | struct lysp_ext_instance *exts = NULL; |
| 2609 | |
| 2610 | data = ELEMENT_WRAPPER_START "<key value=\"key-value\">"EXT_SUBELEM"</key>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2611 | assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2612 | assert_string_equal(val, "key-value"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2613 | assert_string_equal(exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2614 | assert_int_equal(exts[0].insubstmt_index, 0); |
| 2615 | assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_KEY); |
| 2616 | FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free); |
| 2617 | FREE_STRING(st->ctx, val); |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2618 | |
| 2619 | data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2620 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2621 | assert_string_equal(val, "key-value"); |
| 2622 | FREE_STRING(st->ctx, val); |
| 2623 | |
| 2624 | data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2625 | assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID); |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2626 | logbuf_assert("Missing mandatory attribute value of key element. Line number 1."); |
| 2627 | |
| 2628 | st->finished_correctly = true; |
| 2629 | } |
| 2630 | |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2631 | static void |
| 2632 | test_typedef_elem(void **state) |
| 2633 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2634 | struct test_parser_yin_state *st = *state; |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2635 | const char *data; |
| 2636 | struct lysp_tpdf *tpdfs = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 2637 | struct tree_node_meta typdef_meta = {NULL, (struct lysp_node **)&tpdfs}; |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2638 | |
| 2639 | data = ELEMENT_WRAPPER_START |
| 2640 | "<typedef name=\"tpdf-name\">" |
| 2641 | "<default value=\"def-val\"/>" |
| 2642 | "<description><text>desc-text</text></description>" |
| 2643 | "<reference><text>ref-text</text></reference>" |
| 2644 | "<status value=\"current\"/>" |
| 2645 | "<type name=\"type\"/>" |
| 2646 | "<units name=\"uni\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2647 | EXT_SUBELEM |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2648 | "</typedef>" |
| 2649 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2650 | assert_int_equal(test_element_helper(st, data, &typdef_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2651 | assert_string_equal(tpdfs[0].dflt, "def-val"); |
| 2652 | assert_string_equal(tpdfs[0].dsc, "desc-text"); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2653 | assert_string_equal(tpdfs[0].name, "tpdf-name"); |
| 2654 | assert_string_equal(tpdfs[0].ref, "ref-text"); |
| 2655 | assert_string_equal(tpdfs[0].type.name, "type"); |
| 2656 | assert_string_equal(tpdfs[0].units, "uni"); |
| 2657 | assert_true(tpdfs[0].flags & LYS_STATUS_CURR); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2658 | assert_string_equal(tpdfs[0].exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2659 | assert_int_equal(tpdfs[0].exts[0].insubstmt_index, 0); |
| 2660 | assert_int_equal(tpdfs[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2661 | FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free); |
| 2662 | tpdfs = NULL; |
| 2663 | |
| 2664 | data = ELEMENT_WRAPPER_START |
| 2665 | "<typedef name=\"tpdf-name\">" |
| 2666 | "<type name=\"type\"/>" |
| 2667 | "</typedef>" |
| 2668 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2669 | assert_int_equal(test_element_helper(st, data, &typdef_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2670 | assert_string_equal(tpdfs[0].name, "tpdf-name"); |
| 2671 | assert_string_equal(tpdfs[0].type.name, "type"); |
| 2672 | FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free); |
| 2673 | tpdfs = NULL; |
| 2674 | |
| 2675 | st->finished_correctly = true; |
| 2676 | } |
| 2677 | |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2678 | static void |
| 2679 | test_refine_elem(void **state) |
| 2680 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2681 | struct test_parser_yin_state *st = *state; |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2682 | const char *data; |
| 2683 | struct lysp_refine *refines = NULL; |
| 2684 | |
| 2685 | /* max subelems */ |
| 2686 | data = ELEMENT_WRAPPER_START |
| 2687 | "<refine target-node=\"target\">" |
| 2688 | "<if-feature name=\"feature\" />" |
| 2689 | "<must condition=\"cond\" />" |
| 2690 | "<presence value=\"presence\" />" |
| 2691 | "<default value=\"def\" />" |
| 2692 | "<config value=\"true\" />" |
| 2693 | "<mandatory value=\"true\" />" |
| 2694 | "<min-elements value=\"10\" />" |
| 2695 | "<max-elements value=\"20\" />" |
| 2696 | "<description><text>desc</text></description>" |
| 2697 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2698 | EXT_SUBELEM |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2699 | "</refine>" |
| 2700 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2701 | assert_int_equal(test_element_helper(st, data, &refines, NULL, NULL), LY_SUCCESS); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2702 | assert_string_equal(refines->nodeid, "target"); |
| 2703 | assert_string_equal(*refines->dflts, "def"); |
| 2704 | assert_string_equal(refines->dsc, "desc"); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2705 | assert_true(refines->flags & LYS_CONFIG_W); |
| 2706 | assert_true(refines->flags & LYS_MAND_TRUE); |
| 2707 | assert_string_equal(*refines->iffeatures, "feature"); |
| 2708 | assert_int_equal(refines->max, 20); |
| 2709 | assert_int_equal(refines->min, 10); |
| 2710 | assert_string_equal(refines->musts->arg, "cond"); |
| 2711 | assert_string_equal(refines->presence, "presence"); |
| 2712 | assert_string_equal(refines->ref, "ref"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2713 | assert_string_equal(refines->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2714 | assert_int_equal(refines->exts[0].insubstmt_index, 0); |
| 2715 | assert_int_equal(refines->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2716 | FREE_ARRAY(st->ctx, refines, lysp_refine_free); |
| 2717 | refines = NULL; |
| 2718 | |
| 2719 | /* min subelems */ |
| 2720 | data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2721 | assert_int_equal(test_element_helper(st, data, &refines, NULL, NULL), LY_SUCCESS); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2722 | assert_string_equal(refines->nodeid, "target"); |
| 2723 | FREE_ARRAY(st->ctx, refines, lysp_refine_free); |
| 2724 | refines = NULL; |
| 2725 | |
| 2726 | st->finished_correctly = true; |
| 2727 | } |
| 2728 | |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2729 | static void |
| 2730 | test_uses_elem(void **state) |
| 2731 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2732 | struct test_parser_yin_state *st = *state; |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2733 | const char *data; |
| 2734 | struct lysp_node *siblings = NULL; |
| 2735 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2736 | struct lysp_node_uses *parsed = NULL; |
| 2737 | |
| 2738 | /* max subelems */ |
| 2739 | data = ELEMENT_WRAPPER_START |
| 2740 | "<uses name=\"uses-name\">" |
| 2741 | "<when condition=\"cond\" />" |
| 2742 | "<if-feature name=\"feature\" />" |
| 2743 | "<status value=\"obsolete\" />" |
| 2744 | "<description><text>desc</text></description>" |
| 2745 | "<reference><text>ref</text></reference>" |
| 2746 | "<refine target-node=\"target\"/>" |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2747 | "<augment target-node=\"target\" />" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2748 | EXT_SUBELEM |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2749 | "</uses>" |
| 2750 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2751 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2752 | parsed = (struct lysp_node_uses *)&siblings[0]; |
| 2753 | assert_string_equal(parsed->name, "uses-name"); |
| 2754 | assert_string_equal(parsed->dsc, "desc"); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2755 | assert_true(parsed->flags & LYS_STATUS_OBSLT); |
| 2756 | assert_string_equal(*parsed->iffeatures, "feature"); |
| 2757 | assert_null(parsed->next); |
| 2758 | assert_int_equal(parsed->nodetype, LYS_USES); |
| 2759 | assert_null(parsed->parent); |
| 2760 | assert_string_equal(parsed->ref, "ref"); |
| 2761 | assert_string_equal(parsed->refines->nodeid, "target"); |
| 2762 | assert_string_equal(parsed->when->cond, "cond"); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2763 | assert_string_equal(parsed->augments->nodeid, "target"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2764 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2765 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2766 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2767 | lysp_node_free(st->ctx, siblings); |
| 2768 | siblings = NULL; |
| 2769 | |
| 2770 | /* min subelems */ |
| 2771 | data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2772 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2773 | assert_string_equal(siblings[0].name, "uses-name"); |
| 2774 | lysp_node_free(st->ctx, siblings); |
| 2775 | siblings = NULL; |
| 2776 | |
| 2777 | st->finished_correctly = true; |
| 2778 | } |
| 2779 | |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2780 | static void |
| 2781 | test_revision_elem(void **state) |
| 2782 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2783 | struct test_parser_yin_state *st = *state; |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2784 | const char *data; |
| 2785 | struct lysp_revision *revs = NULL; |
| 2786 | |
| 2787 | /* max subelems */ |
| 2788 | data = ELEMENT_WRAPPER_START |
| 2789 | "<revision date=\"2018-12-25\">" |
| 2790 | "<description><text>desc</text></description>" |
| 2791 | "<reference><text>ref</text></reference>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2792 | EXT_SUBELEM |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2793 | "</revision>" |
| 2794 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2795 | assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_SUCCESS); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2796 | assert_string_equal(revs->date, "2018-12-25"); |
| 2797 | assert_string_equal(revs->dsc, "desc"); |
| 2798 | assert_string_equal(revs->ref, "ref"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2799 | assert_string_equal(revs->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2800 | assert_int_equal(revs->exts[0].insubstmt_index, 0); |
| 2801 | assert_int_equal(revs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2802 | FREE_ARRAY(st->ctx, revs, lysp_revision_free); |
| 2803 | revs = NULL; |
| 2804 | |
| 2805 | /* min subelems */ |
| 2806 | data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2807 | assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_SUCCESS); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2808 | assert_string_equal(revs->date, "2005-05-05"); |
| 2809 | FREE_ARRAY(st->ctx, revs, lysp_revision_free); |
| 2810 | revs = NULL; |
| 2811 | |
| 2812 | /* invalid value */ |
| 2813 | data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2814 | assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_EVALID); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2815 | logbuf_assert("Invalid value \"05-05-2005\" of \"revision\". Line number 1."); |
| 2816 | FREE_ARRAY(st->ctx, revs, lysp_revision_free); |
| 2817 | revs = NULL; |
| 2818 | |
| 2819 | st->finished_correctly = true; |
| 2820 | } |
| 2821 | |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2822 | static void |
| 2823 | test_include_elem(void **state) |
| 2824 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2825 | struct test_parser_yin_state *st = *state; |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2826 | const char *data; |
| 2827 | struct lysp_include *includes = NULL; |
| 2828 | struct include_meta inc_meta = {"module-name", &includes}; |
| 2829 | |
| 2830 | /* max subelems */ |
| 2831 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 2832 | data = ELEMENT_WRAPPER_START |
| 2833 | "<include module=\"mod\">" |
| 2834 | "<description><text>desc</text></description>" |
| 2835 | "<reference><text>ref</text></reference>" |
| 2836 | "<revision-date date=\"1999-09-09\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2837 | EXT_SUBELEM |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2838 | "</include>" |
| 2839 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2840 | assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2841 | assert_string_equal(includes->name, "mod"); |
| 2842 | assert_string_equal(includes->dsc, "desc"); |
| 2843 | assert_string_equal(includes->ref, "ref"); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2844 | assert_string_equal(includes->rev, "1999-09-09"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2845 | assert_string_equal(includes->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2846 | assert_int_equal(includes->exts[0].insubstmt_index, 0); |
| 2847 | assert_int_equal(includes->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2848 | FREE_ARRAY(st->ctx, includes, lysp_include_free); |
| 2849 | includes = NULL; |
| 2850 | |
| 2851 | /* min subelems */ |
| 2852 | data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2853 | assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2854 | assert_string_equal(includes->name, "mod"); |
| 2855 | FREE_ARRAY(st->ctx, includes, lysp_include_free); |
| 2856 | includes = NULL; |
| 2857 | |
| 2858 | /* invalid combinations */ |
| 2859 | st->yin_ctx->mod_version = LYS_VERSION_1_0; |
| 2860 | data = ELEMENT_WRAPPER_START |
| 2861 | "<include module=\"mod\">" |
| 2862 | "<description><text>desc</text></description>" |
| 2863 | "<revision-date date=\"1999-09-09\"/>" |
| 2864 | "</include>" |
| 2865 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2866 | assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_EVALID); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2867 | 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."); |
| 2868 | FREE_ARRAY(st->ctx, includes, lysp_include_free); |
| 2869 | includes = NULL; |
| 2870 | |
| 2871 | st->yin_ctx->mod_version = LYS_VERSION_1_0; |
| 2872 | data = ELEMENT_WRAPPER_START |
| 2873 | "<include module=\"mod\">" |
| 2874 | "<reference><text>ref</text></reference>" |
| 2875 | "<revision-date date=\"1999-09-09\"/>" |
| 2876 | "</include>" |
| 2877 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2878 | assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_EVALID); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2879 | 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."); |
| 2880 | FREE_ARRAY(st->ctx, includes, lysp_include_free); |
| 2881 | includes = NULL; |
| 2882 | |
| 2883 | st->finished_correctly = true; |
| 2884 | } |
| 2885 | |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 2886 | static void |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2887 | test_list_elem(void **state) |
| 2888 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2889 | struct test_parser_yin_state *st = *state; |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2890 | const char *data; |
| 2891 | struct lysp_node *siblings = NULL; |
| 2892 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2893 | struct lysp_node_list *parsed = NULL; |
| 2894 | |
| 2895 | /* max subelems */ |
| 2896 | data = ELEMENT_WRAPPER_START |
| 2897 | "<list name=\"list-name\">" |
| 2898 | "<when condition=\"when\"/>" |
| 2899 | "<if-feature name=\"iff\"/>" |
| 2900 | "<must condition=\"must-cond\"/>" |
| 2901 | "<key value=\"key\"/>" |
| 2902 | "<unique tag=\"utag\"/>" |
| 2903 | "<config value=\"true\"/>" |
| 2904 | "<min-elements value=\"10\"/>" |
| 2905 | "<ordered-by value=\"user\"/>" |
| 2906 | "<status value=\"deprecated\"/>" |
| 2907 | "<description><text>desc</text></description>" |
| 2908 | "<reference><text>ref</text></reference>" |
| 2909 | "<anydata name=\"anyd\"/>" |
| 2910 | "<anyxml name=\"anyx\"/>" |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2911 | "<container name=\"cont\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2912 | "<choice name=\"choice\"/>" |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2913 | "<action name=\"action\"/>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2914 | "<grouping name=\"grp\"/>" |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2915 | "<notification name=\"notf\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2916 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 2917 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2918 | "<list name=\"sub-list\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2919 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2920 | "<uses name=\"uses-name\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2921 | EXT_SUBELEM |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2922 | "</list>" |
| 2923 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2924 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2925 | parsed = (struct lysp_node_list *)&siblings[0]; |
| 2926 | assert_string_equal(parsed->dsc, "desc"); |
| 2927 | assert_string_equal(parsed->child->name, "anyd"); |
| 2928 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 2929 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 2930 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2931 | assert_string_equal(parsed->child->next->next->name, "cont"); |
| 2932 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2933 | assert_string_equal(parsed->child->next->next->next->name, "choice"); |
| 2934 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2935 | assert_string_equal(parsed->child->next->next->next->next->name, "leaf"); |
| 2936 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF); |
| 2937 | assert_string_equal(parsed->child->next->next->next->next->next->name, "llist"); |
| 2938 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2939 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list"); |
| 2940 | assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 2941 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name"); |
| 2942 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 2943 | 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] | 2944 | assert_string_equal(parsed->groupings->name, "grp"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2945 | assert_string_equal(parsed->actions->name, "action"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2946 | assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2947 | assert_string_equal(parsed->notifs->name, "notf"); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2948 | assert_true(parsed->flags & LYS_ORDBY_USER); |
| 2949 | assert_true(parsed->flags & LYS_STATUS_DEPRC); |
| 2950 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 2951 | assert_string_equal(*parsed->iffeatures, "iff"); |
| 2952 | assert_string_equal(parsed->key, "key"); |
| 2953 | assert_int_equal(parsed->min, 10); |
| 2954 | assert_string_equal(parsed->musts->arg, "must-cond"); |
| 2955 | assert_string_equal(parsed->name, "list-name"); |
| 2956 | assert_null(parsed->next); |
| 2957 | assert_int_equal(parsed->nodetype, LYS_LIST); |
| 2958 | assert_null(parsed->parent); |
| 2959 | assert_string_equal(parsed->ref, "ref"); |
| 2960 | assert_string_equal(parsed->typedefs->name, "tpdf"); |
| 2961 | assert_string_equal(*parsed->uniques, "utag"); |
| 2962 | assert_string_equal(parsed->when->cond, "when"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 2963 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2964 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 2965 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2966 | lysp_node_free(st->ctx, siblings); |
| 2967 | ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL); |
| 2968 | siblings = NULL; |
| 2969 | |
| 2970 | /* min subelems */ |
| 2971 | data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2972 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2973 | parsed = (struct lysp_node_list *)&siblings[0]; |
| 2974 | assert_string_equal(parsed->name, "list-name"); |
| 2975 | lysp_node_free(st->ctx, siblings); |
| 2976 | siblings = NULL; |
| 2977 | |
| 2978 | st->finished_correctly = true; |
| 2979 | } |
| 2980 | |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2981 | static void |
| 2982 | test_notification_elem(void **state) |
| 2983 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 2984 | struct test_parser_yin_state *st = *state; |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2985 | const char *data; |
| 2986 | struct lysp_notif *notifs = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 2987 | struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)¬ifs}; |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2988 | |
| 2989 | /* max subelems */ |
| 2990 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 2991 | data = ELEMENT_WRAPPER_START |
| 2992 | "<notification name=\"notif-name\">" |
| 2993 | "<anydata name=\"anyd\"/>" |
| 2994 | "<anyxml name=\"anyx\"/>" |
| 2995 | "<description><text>desc</text></description>" |
| 2996 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2997 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 2998 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2999 | "<list name=\"sub-list\"/>" |
| 3000 | "<must condition=\"cond\"/>" |
| 3001 | "<reference><text>ref</text></reference>" |
| 3002 | "<status value=\"deprecated\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3003 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3004 | "<uses name=\"uses-name\"/>" |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3005 | "<container name=\"cont\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3006 | "<choice name=\"choice\"/>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3007 | "<grouping name=\"grp\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3008 | EXT_SUBELEM |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3009 | "</notification>" |
| 3010 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3011 | assert_int_equal(test_element_helper(st, data, ¬if_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3012 | assert_string_equal(notifs->name, "notif-name"); |
| 3013 | assert_string_equal(notifs->data->name, "anyd"); |
| 3014 | assert_int_equal(notifs->data->nodetype, LYS_ANYDATA); |
| 3015 | assert_string_equal(notifs->data->next->name, "anyx"); |
| 3016 | assert_int_equal(notifs->data->next->nodetype, LYS_ANYXML); |
| 3017 | assert_string_equal(notifs->data->next->next->name, "leaf"); |
| 3018 | assert_int_equal(notifs->data->next->next->nodetype, LYS_LEAF); |
| 3019 | assert_string_equal(notifs->data->next->next->next->name, "llist"); |
| 3020 | assert_int_equal(notifs->data->next->next->next->nodetype, LYS_LEAFLIST); |
| 3021 | assert_string_equal(notifs->data->next->next->next->next->name, "sub-list"); |
| 3022 | assert_int_equal(notifs->data->next->next->next->next->nodetype, LYS_LIST); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3023 | assert_true(notifs->flags & LYS_STATUS_DEPRC); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3024 | assert_string_equal(notifs->groupings->name, "grp"); |
| 3025 | assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3026 | assert_string_equal(notifs->data->next->next->next->next->next->name, "uses-name"); |
| 3027 | assert_int_equal(notifs->data->next->next->next->next->next->nodetype, LYS_USES); |
| 3028 | assert_string_equal(notifs->data->next->next->next->next->next->next->name, "cont"); |
| 3029 | 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] | 3030 | assert_int_equal(notifs->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 3031 | assert_string_equal(notifs->data->next->next->next->next->next->next->next->name, "choice"); |
| 3032 | 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] | 3033 | assert_string_equal(*notifs->iffeatures, "iff"); |
| 3034 | assert_string_equal(notifs->musts->arg, "cond"); |
| 3035 | assert_int_equal(notifs->nodetype, LYS_NOTIF); |
| 3036 | assert_null(notifs->parent); |
| 3037 | assert_string_equal(notifs->ref, "ref"); |
| 3038 | assert_string_equal(notifs->typedefs->name, "tpdf"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3039 | assert_string_equal(notifs->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3040 | assert_int_equal(notifs->exts[0].insubstmt_index, 0); |
| 3041 | assert_int_equal(notifs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3042 | FREE_ARRAY(st->ctx, notifs, lysp_notif_free); |
| 3043 | notifs = NULL; |
| 3044 | |
| 3045 | /* min subelems */ |
| 3046 | data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3047 | assert_int_equal(test_element_helper(st, data, ¬if_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3048 | assert_string_equal(notifs->name, "notif-name"); |
| 3049 | FREE_ARRAY(st->ctx, notifs, lysp_notif_free); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3050 | notifs = NULL; |
| 3051 | |
| 3052 | st->finished_correctly = true; |
| 3053 | } |
| 3054 | |
| 3055 | static void |
| 3056 | test_grouping_elem(void **state) |
| 3057 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3058 | struct test_parser_yin_state *st = *state; |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3059 | const char *data; |
| 3060 | struct lysp_grp *grps = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 3061 | struct tree_node_meta grp_meta = {NULL, (struct lysp_node **)&grps}; |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3062 | |
| 3063 | /* max subelems */ |
| 3064 | data = ELEMENT_WRAPPER_START |
| 3065 | "<grouping name=\"grp-name\">" |
| 3066 | "<anydata name=\"anyd\"/>" |
| 3067 | "<anyxml name=\"anyx\"/>" |
| 3068 | "<description><text>desc</text></description>" |
| 3069 | "<grouping name=\"sub-grp\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3070 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3071 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3072 | "<list name=\"list\"/>" |
| 3073 | "<notification name=\"notf\"/>" |
| 3074 | "<reference><text>ref</text></reference>" |
| 3075 | "<status value=\"current\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3076 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3077 | "<uses name=\"uses-name\"/>" |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3078 | "<action name=\"act\"/>" |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3079 | "<container name=\"cont\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3080 | "<choice name=\"choice\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3081 | EXT_SUBELEM |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3082 | "</grouping>" |
| 3083 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3084 | assert_int_equal(test_element_helper(st, data, &grp_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3085 | assert_string_equal(grps->name, "grp-name"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3086 | assert_string_equal(grps->data->name, "anyd"); |
| 3087 | assert_string_equal(grps->data->next->name, "anyx"); |
| 3088 | assert_string_equal(grps->data->next->next->name, "leaf"); |
| 3089 | assert_string_equal(grps->data->next->next->next->name, "llist"); |
| 3090 | assert_string_equal(grps->data->next->next->next->next->name, "list"); |
| 3091 | assert_string_equal(grps->dsc, "desc"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3092 | assert_true(grps->flags & LYS_STATUS_CURR); |
| 3093 | assert_string_equal(grps->groupings->name, "sub-grp"); |
| 3094 | assert_int_equal(grps->nodetype, LYS_GROUPING); |
| 3095 | assert_string_equal(grps->notifs->name, "notf"); |
| 3096 | assert_null(grps->parent); |
| 3097 | assert_string_equal(grps->ref, "ref"); |
| 3098 | assert_string_equal(grps->typedefs->name, "tpdf"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3099 | assert_string_equal(grps->actions->name, "act"); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3100 | 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] | 3101 | 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] | 3102 | 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] | 3103 | assert_int_equal(grps->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER); |
| 3104 | assert_string_equal(grps->data->next->next->next->next->next->next->next->name, "choice"); |
| 3105 | assert_int_equal(grps->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3106 | assert_string_equal(grps->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3107 | assert_int_equal(grps->exts[0].insubstmt_index, 0); |
| 3108 | assert_int_equal(grps->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3109 | FREE_ARRAY(st->ctx, grps, lysp_grp_free); |
| 3110 | grps = NULL; |
| 3111 | |
| 3112 | /* min subelems */ |
| 3113 | data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3114 | assert_int_equal(test_element_helper(st, data, &grp_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 3115 | assert_string_equal(grps->name, "grp-name"); |
| 3116 | FREE_ARRAY(st->ctx, grps, lysp_grp_free); |
| 3117 | grps = NULL; |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 3118 | |
| 3119 | st->finished_correctly = true; |
| 3120 | } |
| 3121 | |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3122 | static void |
| 3123 | test_container_elem(void **state) |
| 3124 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3125 | struct test_parser_yin_state *st = *state; |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3126 | const char *data; |
| 3127 | struct lysp_node *siblings = NULL; |
| 3128 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 3129 | struct lysp_node_container *parsed = NULL; |
| 3130 | |
| 3131 | /* max subelems */ |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3132 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3133 | data = ELEMENT_WRAPPER_START |
| 3134 | "<container name=\"cont-name\">" |
| 3135 | "<anydata name=\"anyd\"/>" |
| 3136 | "<anyxml name=\"anyx\"/>" |
| 3137 | "<config value=\"true\"/>" |
| 3138 | "<container name=\"subcont\"/>" |
| 3139 | "<description><text>desc</text></description>" |
| 3140 | "<grouping name=\"sub-grp\"/>" |
| 3141 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3142 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3143 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3144 | "<list name=\"list\"/>" |
| 3145 | "<must condition=\"cond\"/>" |
| 3146 | "<notification name=\"notf\"/>" |
| 3147 | "<presence value=\"presence\"/>" |
| 3148 | "<reference><text>ref</text></reference>" |
| 3149 | "<status value=\"current\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3150 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3151 | "<uses name=\"uses-name\"/>" |
| 3152 | "<when condition=\"when-cond\"/>" |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3153 | "<action name=\"act\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3154 | "<choice name=\"choice\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3155 | EXT_SUBELEM |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3156 | "</container>" |
| 3157 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3158 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3159 | parsed = (struct lysp_node_container *)siblings; |
| 3160 | assert_string_equal(parsed->name, "cont-name"); |
| 3161 | assert_null(parsed->parent); |
| 3162 | assert_int_equal(parsed->nodetype, LYS_CONTAINER); |
| 3163 | assert_true(parsed->flags & LYS_CONFIG_W); |
| 3164 | assert_true(parsed->flags & LYS_STATUS_CURR); |
| 3165 | assert_null(parsed->next); |
| 3166 | assert_string_equal(parsed->dsc, "desc"); |
| 3167 | assert_string_equal(parsed->ref, "ref"); |
| 3168 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 3169 | assert_string_equal(*parsed->iffeatures, "iff"); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3170 | assert_string_equal(parsed->musts->arg, "cond"); |
| 3171 | assert_string_equal(parsed->presence, "presence"); |
| 3172 | assert_string_equal(parsed->typedefs->name, "tpdf"); |
| 3173 | assert_string_equal(parsed->groupings->name, "sub-grp"); |
| 3174 | assert_string_equal(parsed->child->name, "anyd"); |
| 3175 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 3176 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 3177 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 3178 | assert_string_equal(parsed->child->next->next->name, "subcont"); |
| 3179 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
| 3180 | assert_string_equal(parsed->child->next->next->next->name, "leaf"); |
| 3181 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF); |
| 3182 | assert_string_equal(parsed->child->next->next->next->next->name, "llist"); |
| 3183 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3184 | assert_string_equal(parsed->child->next->next->next->next->next->name, "list"); |
| 3185 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST); |
| 3186 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name"); |
| 3187 | 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] | 3188 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice"); |
| 3189 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 3190 | 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] | 3191 | assert_string_equal(parsed->notifs->name, "notf"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3192 | assert_string_equal(parsed->actions->name, "act"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3193 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3194 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 3195 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 3196 | lysp_node_free(st->ctx, siblings); |
| 3197 | ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL); |
| 3198 | siblings = NULL; |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3199 | |
| 3200 | /* min subelems */ |
| 3201 | data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3202 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 3203 | parsed = (struct lysp_node_container *)siblings; |
| 3204 | assert_string_equal(parsed->name, "cont-name"); |
| 3205 | lysp_node_free(st->ctx, siblings); |
| 3206 | siblings = NULL; |
| 3207 | |
| 3208 | st->finished_correctly = true; |
| 3209 | } |
| 3210 | |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3211 | static void |
| 3212 | test_case_elem(void **state) |
| 3213 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3214 | struct test_parser_yin_state *st = *state; |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3215 | const char *data; |
| 3216 | struct lysp_node *siblings = NULL; |
| 3217 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 3218 | struct lysp_node_case *parsed = NULL; |
| 3219 | |
| 3220 | /* max subelems */ |
| 3221 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3222 | data = ELEMENT_WRAPPER_START |
| 3223 | "<case name=\"case-name\">" |
| 3224 | "<anydata name=\"anyd\"/>" |
| 3225 | "<anyxml name=\"anyx\"/>" |
| 3226 | "<container name=\"subcont\"/>" |
| 3227 | "<description><text>desc</text></description>" |
| 3228 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3229 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3230 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3231 | "<list name=\"list\"/>" |
| 3232 | "<reference><text>ref</text></reference>" |
| 3233 | "<status value=\"current\"/>" |
| 3234 | "<uses name=\"uses-name\"/>" |
| 3235 | "<when condition=\"when-cond\"/>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3236 | "<choice name=\"choice\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3237 | EXT_SUBELEM |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3238 | "</case>" |
| 3239 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3240 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3241 | parsed = (struct lysp_node_case *)siblings; |
| 3242 | assert_string_equal(parsed->name, "case-name"); |
| 3243 | assert_null(parsed->parent); |
| 3244 | assert_int_equal(parsed->nodetype, LYS_CASE); |
| 3245 | assert_true(parsed->flags & LYS_STATUS_CURR); |
| 3246 | assert_null(parsed->next); |
| 3247 | assert_string_equal(parsed->dsc, "desc"); |
| 3248 | assert_string_equal(parsed->ref, "ref"); |
| 3249 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 3250 | assert_string_equal(*parsed->iffeatures, "iff"); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3251 | assert_string_equal(parsed->child->name, "anyd"); |
| 3252 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 3253 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 3254 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 3255 | assert_string_equal(parsed->child->next->next->name, "subcont"); |
| 3256 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
| 3257 | assert_string_equal(parsed->child->next->next->next->name, "leaf"); |
| 3258 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF); |
| 3259 | assert_string_equal(parsed->child->next->next->next->next->name, "llist"); |
| 3260 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3261 | assert_string_equal(parsed->child->next->next->next->next->next->name, "list"); |
| 3262 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST); |
| 3263 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name"); |
| 3264 | 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] | 3265 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice"); |
| 3266 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 3267 | assert_null(parsed->child->next->next->next->next->next->next->next->next); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3268 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3269 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 3270 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3271 | lysp_node_free(st->ctx, siblings); |
| 3272 | siblings = NULL; |
| 3273 | |
| 3274 | /* min subelems */ |
| 3275 | data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3276 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 3277 | parsed = (struct lysp_node_case *)siblings; |
| 3278 | assert_string_equal(parsed->name, "case-name"); |
| 3279 | lysp_node_free(st->ctx, siblings); |
| 3280 | siblings = NULL; |
| 3281 | |
| 3282 | st->finished_correctly = true; |
| 3283 | } |
| 3284 | |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3285 | static void |
| 3286 | test_choice_elem(void **state) |
| 3287 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3288 | struct test_parser_yin_state *st = *state; |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3289 | const char *data; |
| 3290 | struct lysp_node *siblings = NULL; |
| 3291 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 3292 | struct lysp_node_choice *parsed = NULL; |
| 3293 | |
| 3294 | /* max subelems */ |
| 3295 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3296 | data = ELEMENT_WRAPPER_START |
| 3297 | "<choice name=\"choice-name\">" |
| 3298 | "<anydata name=\"anyd\"/>" |
| 3299 | "<anyxml name=\"anyx\"/>" |
| 3300 | "<case name=\"sub-case\"/>" |
| 3301 | "<choice name=\"choice\"/>" |
| 3302 | "<config value=\"true\"/>" |
| 3303 | "<container name=\"subcont\"/>" |
| 3304 | "<default value=\"def\"/>" |
| 3305 | "<description><text>desc</text></description>" |
| 3306 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3307 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3308 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3309 | "<list name=\"list\"/>" |
| 3310 | "<mandatory value=\"true\" />" |
| 3311 | "<reference><text>ref</text></reference>" |
| 3312 | "<status value=\"current\"/>" |
| 3313 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3314 | EXT_SUBELEM |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3315 | "</choice>" |
| 3316 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3317 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3318 | parsed = (struct lysp_node_choice *)siblings; |
| 3319 | assert_string_equal(parsed->name, "choice-name"); |
| 3320 | assert_null(parsed->parent); |
| 3321 | assert_int_equal(parsed->nodetype, LYS_CHOICE); |
| 3322 | assert_true(parsed->flags & LYS_CONFIG_W && parsed->flags & LYS_MAND_TRUE && parsed->flags & LYS_STATUS_CURR); |
| 3323 | assert_null(parsed->next); |
| 3324 | assert_string_equal(parsed->dsc, "desc"); |
| 3325 | assert_string_equal(parsed->ref, "ref"); |
| 3326 | assert_string_equal(parsed->when->cond, "when-cond"); |
| 3327 | assert_string_equal(*parsed->iffeatures, "iff"); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3328 | assert_string_equal(parsed->child->name, "anyd"); |
| 3329 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 3330 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 3331 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 3332 | assert_string_equal(parsed->child->next->next->name, "sub-case"); |
| 3333 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE); |
| 3334 | assert_string_equal(parsed->child->next->next->next->name, "choice"); |
| 3335 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE); |
| 3336 | assert_string_equal(parsed->child->next->next->next->next->name, "subcont"); |
| 3337 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER); |
| 3338 | assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf"); |
| 3339 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF); |
| 3340 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist"); |
| 3341 | assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3342 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list"); |
| 3343 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3344 | assert_null(parsed->child->next->next->next->next->next->next->next->next); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3345 | assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3346 | assert_int_equal(parsed->exts[0].insubstmt_index, 0); |
| 3347 | assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3348 | lysp_node_free(st->ctx, siblings); |
| 3349 | siblings = NULL; |
| 3350 | |
| 3351 | /* min subelems */ |
| 3352 | data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3353 | assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 3354 | parsed = (struct lysp_node_choice *)siblings; |
| 3355 | assert_string_equal(parsed->name, "choice-name"); |
| 3356 | lysp_node_free(st->ctx, siblings); |
| 3357 | siblings = NULL; |
| 3358 | |
| 3359 | st->finished_correctly = true; |
| 3360 | } |
| 3361 | |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3362 | static void |
| 3363 | test_inout_elem(void **state) |
| 3364 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3365 | struct test_parser_yin_state *st = *state; |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3366 | const char *data; |
| 3367 | struct lysp_action_inout inout = {}; |
| 3368 | struct inout_meta inout_meta = {NULL, &inout}; |
| 3369 | |
| 3370 | /* max subelements */ |
| 3371 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3372 | data = ELEMENT_WRAPPER_START |
| 3373 | "<input>" |
| 3374 | "<anydata name=\"anyd\"/>" |
| 3375 | "<anyxml name=\"anyx\"/>" |
| 3376 | "<choice name=\"choice\"/>" |
| 3377 | "<container name=\"subcont\"/>" |
| 3378 | "<grouping name=\"sub-grp\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3379 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3380 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3381 | "<list name=\"list\"/>" |
| 3382 | "<must condition=\"cond\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3383 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3384 | "<uses name=\"uses-name\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3385 | EXT_SUBELEM |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3386 | "</input>" |
| 3387 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3388 | assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3389 | assert_null(inout.parent); |
| 3390 | assert_int_equal(inout.nodetype, LYS_INPUT); |
| 3391 | assert_string_equal(inout.musts->arg, "cond"); |
| 3392 | assert_string_equal(inout.typedefs->name, "tpdf"); |
| 3393 | assert_string_equal(inout.groupings->name, "sub-grp"); |
| 3394 | assert_string_equal(inout.data->name, "anyd"); |
| 3395 | assert_int_equal(inout.data->nodetype, LYS_ANYDATA); |
| 3396 | assert_string_equal(inout.data->next->name, "anyx"); |
| 3397 | assert_int_equal(inout.data->next->nodetype, LYS_ANYXML); |
| 3398 | assert_string_equal(inout.data->next->next->name, "choice"); |
| 3399 | assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE); |
| 3400 | assert_string_equal(inout.data->next->next->next->name, "subcont"); |
| 3401 | assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER); |
| 3402 | assert_string_equal(inout.data->next->next->next->next->name, "leaf"); |
| 3403 | assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF); |
| 3404 | assert_string_equal(inout.data->next->next->next->next->next->name, "llist"); |
| 3405 | assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3406 | assert_string_equal(inout.data->next->next->next->next->next->next->name, "list"); |
| 3407 | assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3408 | assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name"); |
| 3409 | assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3410 | assert_null(inout.data->next->next->next->next->next->next->next->next); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3411 | assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3412 | assert_int_equal(inout.exts[0].insubstmt_index, 0); |
| 3413 | assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3414 | lysp_action_inout_free(st->ctx, &inout); |
| 3415 | memset(&inout, 0, sizeof inout); |
| 3416 | |
| 3417 | /* max subelements */ |
| 3418 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3419 | data = ELEMENT_WRAPPER_START |
| 3420 | "<output>" |
| 3421 | "<anydata name=\"anyd\"/>" |
| 3422 | "<anyxml name=\"anyx\"/>" |
| 3423 | "<choice name=\"choice\"/>" |
| 3424 | "<container name=\"subcont\"/>" |
| 3425 | "<grouping name=\"sub-grp\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3426 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3427 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3428 | "<list name=\"list\"/>" |
| 3429 | "<must condition=\"cond\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3430 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3431 | "<uses name=\"uses-name\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3432 | EXT_SUBELEM |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3433 | "</output>" |
| 3434 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3435 | assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3436 | assert_null(inout.parent); |
| 3437 | assert_int_equal(inout.nodetype, LYS_OUTPUT); |
| 3438 | assert_string_equal(inout.musts->arg, "cond"); |
| 3439 | assert_string_equal(inout.typedefs->name, "tpdf"); |
| 3440 | assert_string_equal(inout.groupings->name, "sub-grp"); |
| 3441 | assert_string_equal(inout.data->name, "anyd"); |
| 3442 | assert_int_equal(inout.data->nodetype, LYS_ANYDATA); |
| 3443 | assert_string_equal(inout.data->next->name, "anyx"); |
| 3444 | assert_int_equal(inout.data->next->nodetype, LYS_ANYXML); |
| 3445 | assert_string_equal(inout.data->next->next->name, "choice"); |
| 3446 | assert_int_equal(inout.data->next->next->nodetype, LYS_CHOICE); |
| 3447 | assert_string_equal(inout.data->next->next->next->name, "subcont"); |
| 3448 | assert_int_equal(inout.data->next->next->next->nodetype, LYS_CONTAINER); |
| 3449 | assert_string_equal(inout.data->next->next->next->next->name, "leaf"); |
| 3450 | assert_int_equal(inout.data->next->next->next->next->nodetype, LYS_LEAF); |
| 3451 | assert_string_equal(inout.data->next->next->next->next->next->name, "llist"); |
| 3452 | assert_int_equal(inout.data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3453 | assert_string_equal(inout.data->next->next->next->next->next->next->name, "list"); |
| 3454 | assert_int_equal(inout.data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3455 | assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name"); |
| 3456 | assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3457 | assert_null(inout.data->next->next->next->next->next->next->next->next); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3458 | assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3459 | assert_int_equal(inout.exts[0].insubstmt_index, 0); |
| 3460 | assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3461 | lysp_action_inout_free(st->ctx, &inout); |
| 3462 | memset(&inout, 0, sizeof inout); |
| 3463 | |
| 3464 | /* min subelems */ |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3465 | data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3466 | assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS); |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3467 | lysp_action_inout_free(st->ctx, &inout); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3468 | memset(&inout, 0, sizeof inout); |
| 3469 | |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3470 | data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3471 | assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS); |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3472 | lysp_action_inout_free(st->ctx, &inout); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3473 | memset(&inout, 0, sizeof inout); |
| 3474 | |
| 3475 | /* invalid combinations */ |
| 3476 | data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3477 | assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_EVALID); |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 3478 | logbuf_assert("Unexpected attribute \"name\" of \"input\" element. Line number 1."); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3479 | memset(&inout, 0, sizeof inout); |
| 3480 | |
| 3481 | st->finished_correctly = true; |
| 3482 | } |
| 3483 | |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3484 | static void |
| 3485 | test_action_elem(void **state) |
| 3486 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3487 | struct test_parser_yin_state *st = *state; |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3488 | const char *data; |
| 3489 | struct lysp_action *actions = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 3490 | struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions}; |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3491 | |
| 3492 | /* max subelems */ |
| 3493 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3494 | data = ELEMENT_WRAPPER_START |
| 3495 | "<action name=\"act\">" |
| 3496 | "<description><text>desc</text></description>" |
| 3497 | "<grouping name=\"grouping\"/>" |
| 3498 | "<if-feature name=\"iff\"/>" |
| 3499 | "<input><uses name=\"uses-name\"/></input>" |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3500 | "<output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>" |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3501 | "<reference><text>ref</text></reference>" |
| 3502 | "<status value=\"deprecated\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3503 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3504 | EXT_SUBELEM |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3505 | "</action>" |
| 3506 | ELEMENT_WRAPPER_END; |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 3507 | /* there must be parent for action */ |
| 3508 | act_meta.parent = NULL + 1; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3509 | assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS); |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 3510 | act_meta.parent = NULL; |
| 3511 | assert_non_null(actions->parent); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3512 | assert_int_equal(actions->nodetype, LYS_ACTION); |
| 3513 | assert_true(actions->flags & LYS_STATUS_DEPRC); |
| 3514 | assert_string_equal(actions->name, "act"); |
| 3515 | assert_string_equal(actions->dsc, "desc"); |
| 3516 | assert_string_equal(actions->ref, "ref"); |
| 3517 | assert_string_equal(*actions->iffeatures, "iff"); |
| 3518 | assert_string_equal(actions->typedefs->name, "tpdf"); |
| 3519 | assert_string_equal(actions->groupings->name, "grouping"); |
| 3520 | assert_string_equal(actions->input.data->name, "uses-name"); |
| 3521 | assert_string_equal(actions->output.musts->arg, "cond"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3522 | assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3523 | assert_int_equal(actions->exts[0].insubstmt_index, 0); |
| 3524 | assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3525 | FREE_ARRAY(st->ctx, actions, lysp_action_free) |
| 3526 | actions = NULL; |
| 3527 | |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3528 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3529 | data = ELEMENT_WRAPPER_START |
| 3530 | "<rpc name=\"act\">" |
| 3531 | "<description><text>desc</text></description>" |
| 3532 | "<grouping name=\"grouping\"/>" |
| 3533 | "<if-feature name=\"iff\"/>" |
| 3534 | "<input><uses name=\"uses-name\"/></input>" |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3535 | "<output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>" |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3536 | "<reference><text>ref</text></reference>" |
| 3537 | "<status value=\"deprecated\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3538 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3539 | EXT_SUBELEM |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3540 | "</rpc>" |
| 3541 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3542 | assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3543 | assert_null(actions->parent); |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 3544 | assert_int_equal(actions->nodetype, LYS_RPC); |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3545 | assert_true(actions->flags & LYS_STATUS_DEPRC); |
| 3546 | assert_string_equal(actions->name, "act"); |
| 3547 | assert_string_equal(actions->dsc, "desc"); |
| 3548 | assert_string_equal(actions->ref, "ref"); |
| 3549 | assert_string_equal(*actions->iffeatures, "iff"); |
| 3550 | assert_string_equal(actions->typedefs->name, "tpdf"); |
| 3551 | assert_string_equal(actions->groupings->name, "grouping"); |
| 3552 | assert_string_equal(actions->input.data->name, "uses-name"); |
| 3553 | assert_string_equal(actions->output.musts->arg, "cond"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3554 | assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3555 | assert_int_equal(actions->exts[0].insubstmt_index, 0); |
| 3556 | assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3557 | FREE_ARRAY(st->ctx, actions, lysp_action_free) |
| 3558 | actions = NULL; |
| 3559 | |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3560 | /* min subelems */ |
| 3561 | data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3562 | assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3563 | assert_string_equal(actions->name, "act"); |
| 3564 | FREE_ARRAY(st->ctx, actions, lysp_action_free) |
| 3565 | actions = NULL; |
| 3566 | |
| 3567 | st->finished_correctly = true; |
| 3568 | } |
| 3569 | |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3570 | static void |
| 3571 | test_augment_elem(void **state) |
| 3572 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3573 | struct test_parser_yin_state *st = *state; |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3574 | const char *data; |
| 3575 | struct lysp_augment *augments = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 3576 | struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments}; |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3577 | |
| 3578 | st->yin_ctx->mod_version = LYS_VERSION_1_1; |
| 3579 | data = ELEMENT_WRAPPER_START |
| 3580 | "<augment target-node=\"target\">" |
| 3581 | "<action name=\"action\"/>" |
| 3582 | "<anydata name=\"anyd\"/>" |
| 3583 | "<anyxml name=\"anyx\"/>" |
| 3584 | "<case name=\"case\"/>" |
| 3585 | "<choice name=\"choice\"/>" |
| 3586 | "<container name=\"subcont\"/>" |
| 3587 | "<description><text>desc</text></description>" |
| 3588 | "<if-feature name=\"iff\"/>" |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3589 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" |
| 3590 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>" |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3591 | "<list name=\"list\"/>" |
| 3592 | "<notification name=\"notif\"/>" |
| 3593 | "<reference><text>ref</text></reference>" |
| 3594 | "<status value=\"current\"/>" |
| 3595 | "<uses name=\"uses\"/>" |
| 3596 | "<when condition=\"when-cond\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3597 | EXT_SUBELEM |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3598 | "</augment>" |
| 3599 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3600 | assert_int_equal(test_element_helper(st, data, &aug_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3601 | assert_string_equal(augments->nodeid, "target"); |
| 3602 | assert_null(augments->parent); |
| 3603 | assert_int_equal(augments->nodetype, LYS_AUGMENT); |
| 3604 | assert_true(augments->flags & LYS_STATUS_CURR); |
| 3605 | assert_string_equal(augments->dsc, "desc"); |
| 3606 | assert_string_equal(augments->ref, "ref"); |
| 3607 | assert_string_equal(augments->when->cond, "when-cond"); |
| 3608 | assert_string_equal(*augments->iffeatures, "iff"); |
| 3609 | assert_string_equal(augments->child->name, "anyd"); |
| 3610 | assert_int_equal(augments->child->nodetype, LYS_ANYDATA); |
| 3611 | assert_string_equal(augments->child->next->name, "anyx"); |
| 3612 | assert_int_equal(augments->child->next->nodetype, LYS_ANYXML); |
| 3613 | assert_string_equal(augments->child->next->next->name, "case"); |
| 3614 | assert_int_equal(augments->child->next->next->nodetype, LYS_CASE); |
| 3615 | assert_string_equal(augments->child->next->next->next->name, "choice"); |
| 3616 | assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE); |
| 3617 | assert_string_equal(augments->child->next->next->next->next->name, "subcont"); |
| 3618 | assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER); |
| 3619 | assert_string_equal(augments->child->next->next->next->next->next->name, "leaf"); |
| 3620 | assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF); |
| 3621 | assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist"); |
| 3622 | assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3623 | assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list"); |
| 3624 | assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3625 | assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses"); |
| 3626 | assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3627 | assert_null(augments->child->next->next->next->next->next->next->next->next->next); |
| 3628 | assert_string_equal(augments->actions->name, "action"); |
| 3629 | assert_string_equal(augments->notifs->name, "notif"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3630 | assert_string_equal(augments->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3631 | assert_int_equal(augments->exts[0].insubstmt_index, 0); |
| 3632 | assert_int_equal(augments->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3633 | FREE_ARRAY(st->ctx, augments, lysp_augment_free) |
| 3634 | augments = NULL; |
| 3635 | |
| 3636 | data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3637 | assert_int_equal(test_element_helper(st, data, &aug_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3638 | assert_string_equal(augments->nodeid, "target"); |
| 3639 | FREE_ARRAY(st->ctx, augments, lysp_augment_free) |
| 3640 | augments = NULL; |
| 3641 | |
| 3642 | st->finished_correctly = true; |
| 3643 | } |
| 3644 | |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3645 | static void |
| 3646 | test_deviate_elem(void **state) |
| 3647 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3648 | struct test_parser_yin_state *st = *state; |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3649 | const char *data; |
| 3650 | struct lysp_deviate *deviates = NULL; |
| 3651 | struct lysp_deviate_add *d_add; |
| 3652 | struct lysp_deviate_rpl *d_rpl; |
| 3653 | struct lysp_deviate_del *d_del; |
| 3654 | |
| 3655 | /* all valid arguments with min subelems */ |
| 3656 | data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3657 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3658 | assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED); |
| 3659 | lysp_deviate_free(st->ctx, deviates); |
| 3660 | free(deviates); |
| 3661 | deviates = NULL; |
| 3662 | |
| 3663 | data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3664 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3665 | assert_int_equal(deviates->mod, LYS_DEV_ADD); |
| 3666 | lysp_deviate_free(st->ctx, deviates); |
| 3667 | free(deviates); |
| 3668 | deviates = NULL; |
| 3669 | |
| 3670 | data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3671 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3672 | assert_int_equal(deviates->mod, LYS_DEV_REPLACE); |
| 3673 | lysp_deviate_free(st->ctx, deviates); |
| 3674 | free(deviates); |
| 3675 | deviates = NULL; |
| 3676 | |
| 3677 | data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3678 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3679 | assert_int_equal(deviates->mod, LYS_DEV_DELETE); |
| 3680 | lysp_deviate_free(st->ctx, deviates); |
| 3681 | free(deviates); |
| 3682 | deviates = NULL; |
| 3683 | |
| 3684 | /* max subelems and valid arguments */ |
| 3685 | data = ELEMENT_WRAPPER_START |
| 3686 | "<deviate value=\"not-supported\">" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3687 | EXT_SUBELEM |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3688 | "</deviate>" |
| 3689 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3690 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3691 | assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3692 | assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3693 | assert_int_equal(deviates->exts[0].insubstmt_index, 0); |
| 3694 | assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3695 | lysp_deviate_free(st->ctx, deviates); |
| 3696 | free(deviates); |
| 3697 | deviates = NULL; |
| 3698 | |
| 3699 | data = ELEMENT_WRAPPER_START |
| 3700 | "<deviate value=\"add\">" |
| 3701 | "<units name=\"units\"/>" |
| 3702 | "<must condition=\"cond\"/>" |
| 3703 | "<unique tag=\"utag\"/>" |
| 3704 | "<default value=\"def\"/>" |
| 3705 | "<config value=\"true\"/>" |
| 3706 | "<mandatory value=\"true\"/>" |
| 3707 | "<min-elements value=\"5\"/>" |
| 3708 | "<max-elements value=\"15\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3709 | EXT_SUBELEM |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3710 | "</deviate>" |
| 3711 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3712 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3713 | d_add = (struct lysp_deviate_add *)deviates; |
| 3714 | assert_int_equal(d_add->mod, LYS_DEV_ADD); |
| 3715 | assert_null(d_add->next); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3716 | assert_string_equal(d_add->units, "units"); |
| 3717 | assert_string_equal(d_add->musts->arg, "cond"); |
| 3718 | assert_string_equal(*d_add->uniques, "utag"); |
| 3719 | assert_string_equal(*d_add->dflts, "def"); |
| 3720 | assert_true(d_add->flags & LYS_MAND_TRUE && d_add->flags & LYS_CONFIG_W); |
| 3721 | assert_int_equal(d_add->min, 5); |
| 3722 | assert_int_equal(d_add->max, 15); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3723 | assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3724 | assert_int_equal(deviates->exts[0].insubstmt_index, 0); |
| 3725 | assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3726 | lysp_deviate_free(st->ctx, deviates); |
| 3727 | free(deviates); |
| 3728 | deviates = NULL; |
| 3729 | |
| 3730 | data = ELEMENT_WRAPPER_START |
| 3731 | "<deviate value=\"replace\">" |
| 3732 | "<type name=\"newtype\"/>" |
| 3733 | "<units name=\"uni\"/>" |
| 3734 | "<default value=\"def\"/>" |
| 3735 | "<config value=\"true\"/>" |
| 3736 | "<mandatory value=\"true\"/>" |
| 3737 | "<min-elements value=\"5\"/>" |
| 3738 | "<max-elements value=\"15\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3739 | EXT_SUBELEM |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3740 | "</deviate>" |
| 3741 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3742 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3743 | d_rpl = (struct lysp_deviate_rpl *)deviates; |
| 3744 | assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE); |
| 3745 | assert_null(d_rpl->next); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3746 | assert_string_equal(d_rpl->type->name, "newtype"); |
| 3747 | assert_string_equal(d_rpl->units, "uni"); |
| 3748 | assert_string_equal(d_rpl->dflt, "def"); |
| 3749 | assert_true(d_rpl->flags & LYS_MAND_TRUE && d_rpl->flags & LYS_CONFIG_W); |
| 3750 | assert_int_equal(d_rpl->min, 5); |
| 3751 | assert_int_equal(d_rpl->max, 15); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3752 | assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3753 | assert_int_equal(deviates->exts[0].insubstmt_index, 0); |
| 3754 | assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3755 | lysp_deviate_free(st->ctx, deviates); |
| 3756 | free(deviates); |
| 3757 | deviates = NULL; |
| 3758 | |
| 3759 | data = ELEMENT_WRAPPER_START |
| 3760 | "<deviate value=\"delete\">" |
| 3761 | "<units name=\"u\"/>" |
| 3762 | "<must condition=\"c\"/>" |
| 3763 | "<unique tag=\"tag\"/>" |
| 3764 | "<default value=\"default\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3765 | EXT_SUBELEM |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3766 | "</deviate>" |
| 3767 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3768 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3769 | d_del = (struct lysp_deviate_del *)deviates; |
| 3770 | assert_int_equal(d_del->mod, LYS_DEV_DELETE); |
| 3771 | assert_null(d_del->next); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3772 | assert_string_equal(d_del->units, "u"); |
| 3773 | assert_string_equal(d_del->musts->arg, "c"); |
| 3774 | assert_string_equal(*d_del->uniques, "tag"); |
| 3775 | assert_string_equal(*d_del->dflts, "default"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3776 | assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3777 | assert_int_equal(deviates->exts[0].insubstmt_index, 0); |
| 3778 | assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3779 | lysp_deviate_free(st->ctx, deviates); |
| 3780 | free(deviates); |
| 3781 | deviates = NULL; |
| 3782 | |
| 3783 | /* invalid arguments */ |
| 3784 | data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3785 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 3786 | logbuf_assert("Invalid value \"\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3787 | deviates = NULL; |
| 3788 | |
| 3789 | data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3790 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 3791 | logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3792 | deviates = NULL; |
| 3793 | |
| 3794 | data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3795 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 3796 | logbuf_assert("Invalid value \"ad\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3797 | deviates = NULL; |
| 3798 | |
| 3799 | data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3800 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID); |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 3801 | logbuf_assert("Invalid value \"adds\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3802 | deviates = NULL; |
| 3803 | |
| 3804 | data = ELEMENT_WRAPPER_START |
| 3805 | "<deviate value=\"not-supported\">" |
| 3806 | "<must condition=\"c\"/>" |
| 3807 | "</deviate>" |
| 3808 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3809 | assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3810 | logbuf_assert("Deviate of this type doesn't allow \"must\" as it's sub-element. Line number 1."); |
| 3811 | |
| 3812 | st->finished_correctly = true; |
| 3813 | } |
| 3814 | |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3815 | static void |
| 3816 | test_deviation_elem(void **state) |
| 3817 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3818 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3819 | const char *data; |
| 3820 | struct lysp_deviation *deviations = NULL; |
| 3821 | |
| 3822 | /* min subelems */ |
| 3823 | data = ELEMENT_WRAPPER_START |
| 3824 | "<deviation target-node=\"target\">" |
| 3825 | "<deviate value=\"not-supported\"/>" |
| 3826 | "</deviation>" |
| 3827 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3828 | assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3829 | assert_string_equal(deviations->nodeid, "target"); |
| 3830 | assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED); |
| 3831 | FREE_ARRAY(st->ctx, deviations, lysp_deviation_free); |
| 3832 | deviations = NULL; |
| 3833 | |
| 3834 | /* max subelems */ |
| 3835 | data = ELEMENT_WRAPPER_START |
| 3836 | "<deviation target-node=\"target\">" |
| 3837 | "<reference><text>ref</text></reference>" |
| 3838 | "<description><text>desc</text></description>" |
| 3839 | "<deviate value=\"add\"/>" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3840 | EXT_SUBELEM |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3841 | "</deviation>" |
| 3842 | ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3843 | assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3844 | assert_string_equal(deviations->nodeid, "target"); |
| 3845 | assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD); |
| 3846 | assert_string_equal(deviations->ref, "ref"); |
| 3847 | assert_string_equal(deviations->dsc, "desc"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3848 | assert_string_equal(deviations->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3849 | assert_int_equal(deviations->exts[0].insubstmt_index, 0); |
| 3850 | assert_int_equal(deviations->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3851 | FREE_ARRAY(st->ctx, deviations, lysp_deviation_free); |
| 3852 | deviations = NULL; |
| 3853 | |
| 3854 | /* invalid */ |
| 3855 | data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3856 | assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_EVALID); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3857 | FREE_ARRAY(st->ctx, deviations, lysp_deviation_free); |
| 3858 | deviations = NULL; |
David Sedlák | 1538a84 | 2019-08-08 15:38:51 +0200 | [diff] [blame] | 3859 | logbuf_assert("Missing mandatory sub-element \"deviate\" of \"deviation\" element. Line number 1."); |
| 3860 | /* TODO */ |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3861 | st->finished_correctly = true; |
| 3862 | } |
| 3863 | |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3864 | static void |
| 3865 | test_module_elem(void **state) |
| 3866 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3867 | struct test_parser_yin_state *st = *state; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3868 | const char *data; |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3869 | struct lys_module *lys_mod = NULL; |
| 3870 | struct lysp_module *lysp_mod = NULL; |
| 3871 | |
| 3872 | /* max subelems */ |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3873 | lys_mod = calloc(1, sizeof *lys_mod); |
| 3874 | lysp_mod = calloc(1, sizeof *lysp_mod); |
| 3875 | lys_mod->ctx = st->ctx; |
| 3876 | lysp_mod->mod = lys_mod; |
| 3877 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
| 3878 | "<yang-version value=\"1.1\"/>\n" |
| 3879 | "<namespace uri=\"ns\"/>\n" |
| 3880 | "<prefix value=\"pref\"/>\n" |
| 3881 | "<include module=\"b-mod\"/>\n" |
| 3882 | "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n" |
| 3883 | "<organization><text>org</text></organization>\n" |
| 3884 | "<contact><text>contact</text></contact>\n" |
| 3885 | "<description><text>desc</text></description>" |
| 3886 | "<reference><text>ref</text></reference>\n" |
| 3887 | "<revision date=\"2019-02-02\"/>\n" |
| 3888 | "<anydata name=\"anyd\"/>\n" |
| 3889 | "<anyxml name=\"anyx\"/>\n" |
| 3890 | "<choice name=\"choice\"/>\n" |
| 3891 | "<container name=\"cont\"/>\n" |
| 3892 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 3893 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 3894 | "<list name=\"sub-list\"/>\n" |
| 3895 | "<uses name=\"uses-name\"/>\n" |
| 3896 | "<augment target-node=\"target\"/>\n" |
| 3897 | "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n" |
| 3898 | "<extension name=\"ext\"/>\n" |
| 3899 | "<feature name=\"feature\"/>\n" |
| 3900 | "<grouping name=\"grp\"/>\n" |
| 3901 | "<identity name=\"ident-name\"/>\n" |
| 3902 | "<notification name=\"notf\"/>\n" |
| 3903 | "<rpc name=\"rpc-name\"/>\n" |
| 3904 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3905 | EXT_SUBELEM"\n" |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3906 | "</module>\n"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3907 | assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS); |
| 3908 | |
| 3909 | assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3910 | assert_string_equal(lysp_mod->mod->name, "mod"); |
| 3911 | assert_string_equal(lysp_mod->revs, "2019-02-02"); |
| 3912 | assert_string_equal(lysp_mod->mod->ns, "ns"); |
| 3913 | assert_string_equal(lysp_mod->mod->prefix, "pref"); |
| 3914 | assert_null(lysp_mod->mod->filepath); |
| 3915 | assert_string_equal(lysp_mod->mod->org, "org"); |
| 3916 | assert_string_equal(lysp_mod->mod->contact, "contact"); |
| 3917 | assert_string_equal(lysp_mod->mod->dsc, "desc"); |
| 3918 | assert_string_equal(lysp_mod->mod->ref, "ref"); |
| 3919 | assert_int_equal(lysp_mod->mod->version, LYS_VERSION_1_1); |
| 3920 | assert_string_equal(lysp_mod->imports->name, "a-mod"); |
| 3921 | assert_string_equal(lysp_mod->includes->name, "b-mod"); |
| 3922 | assert_string_equal(lysp_mod->extensions->name, "ext"); |
| 3923 | assert_string_equal(lysp_mod->features->name, "feature"); |
| 3924 | assert_string_equal(lysp_mod->identities->name, "ident-name"); |
| 3925 | assert_string_equal(lysp_mod->typedefs->name, "tpdf"); |
| 3926 | assert_string_equal(lysp_mod->groupings->name, "grp"); |
| 3927 | assert_string_equal(lysp_mod->data->name, "anyd"); |
| 3928 | assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA); |
| 3929 | assert_string_equal(lysp_mod->data->next->name, "anyx"); |
| 3930 | assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML); |
| 3931 | assert_string_equal(lysp_mod->data->next->next->name, "choice"); |
| 3932 | assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE); |
| 3933 | assert_string_equal(lysp_mod->data->next->next->next->name, "cont"); |
| 3934 | assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER); |
| 3935 | assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf"); |
| 3936 | assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF); |
| 3937 | assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist"); |
| 3938 | assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3939 | assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list"); |
| 3940 | assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3941 | assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name"); |
| 3942 | assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3943 | assert_null(lysp_mod->data->next->next->next->next->next->next->next->next); |
| 3944 | assert_string_equal(lysp_mod->augments->nodeid, "target"); |
| 3945 | assert_string_equal(lysp_mod->rpcs->name, "rpc-name"); |
| 3946 | assert_string_equal(lysp_mod->notifs->name, "notf"); |
| 3947 | assert_string_equal(lysp_mod->deviations->nodeid, "target"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 3948 | assert_string_equal(lysp_mod->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 3949 | assert_int_equal(lysp_mod->exts[0].insubstmt_index, 0); |
| 3950 | assert_int_equal(lysp_mod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3951 | lysp_module_free(lysp_mod); |
| 3952 | lys_module_free(lys_mod, NULL); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3953 | |
| 3954 | /* min subelems */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3955 | lyxml_ctx_free(st->yin_ctx->xmlctx); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3956 | lys_mod = calloc(1, sizeof *lys_mod); |
| 3957 | lysp_mod = calloc(1, sizeof *lysp_mod); |
| 3958 | lys_mod->ctx = st->ctx; |
| 3959 | lysp_mod->mod = lys_mod; |
| 3960 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">" |
| 3961 | "<namespace uri=\"ns\"/>" |
| 3962 | "<prefix value=\"pref\"/>" |
| 3963 | "<yang-version value=\"1.1\"/>" |
| 3964 | "</module>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3965 | assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS); |
| 3966 | assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3967 | assert_string_equal(lysp_mod->mod->name, "mod"); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3968 | lysp_module_free(lysp_mod); |
| 3969 | lys_module_free(lys_mod, NULL); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3970 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3971 | /* incorrect subelem order */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3972 | lyxml_ctx_free(st->yin_ctx->xmlctx); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3973 | lys_mod = calloc(1, sizeof *lys_mod); |
| 3974 | lysp_mod = calloc(1, sizeof *lysp_mod); |
| 3975 | lys_mod->ctx = st->ctx; |
| 3976 | lysp_mod->mod = lys_mod; |
| 3977 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">" |
| 3978 | "<feature name=\"feature\"/>\n" |
| 3979 | "<namespace uri=\"ns\"/>" |
| 3980 | "<prefix value=\"pref\"/>" |
| 3981 | "<yang-version value=\"1.1\"/>" |
| 3982 | "</module>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3983 | assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS); |
| 3984 | assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_EVALID); |
| 3985 | logbuf_assert("Invalid order of module\'s sub-elements \"namespace\" can\'t appear after \"feature\". Line number 2."); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3986 | lysp_module_free(lysp_mod); |
| 3987 | lys_module_free(lys_mod, NULL); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3988 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3989 | st->finished_correctly = true; |
| 3990 | } |
| 3991 | |
| 3992 | static void |
| 3993 | test_submodule_elem(void **state) |
| 3994 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 3995 | struct test_parser_yin_state *st = *state; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3996 | const char *data; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3997 | struct lysp_submodule *lysp_submod = NULL; |
| 3998 | |
| 3999 | /* max subelements */ |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4000 | lysp_submod = calloc(1, sizeof *lysp_submod); |
| 4001 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
| 4002 | "<yang-version value=\"1.1\"/>\n" |
| 4003 | "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>" |
| 4004 | "<include module=\"b-mod\"/>\n" |
| 4005 | "<import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n" |
| 4006 | "<organization><text>org</text></organization>\n" |
| 4007 | "<contact><text>contact</text></contact>\n" |
| 4008 | "<description><text>desc</text></description>" |
| 4009 | "<reference><text>ref</text></reference>\n" |
| 4010 | "<revision date=\"2019-02-02\"/>\n" |
| 4011 | "<anydata name=\"anyd\"/>\n" |
| 4012 | "<anyxml name=\"anyx\"/>\n" |
| 4013 | "<choice name=\"choice\"/>\n" |
| 4014 | "<container name=\"cont\"/>\n" |
| 4015 | "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 4016 | "<leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 4017 | "<list name=\"sub-list\"/>\n" |
| 4018 | "<uses name=\"uses-name\"/>\n" |
| 4019 | "<augment target-node=\"target\"/>\n" |
| 4020 | "<deviation target-node=\"target\">""<deviate value=\"not-supported\"/>""</deviation>\n" |
| 4021 | "<extension name=\"ext\"/>\n" |
| 4022 | "<feature name=\"feature\"/>\n" |
| 4023 | "<grouping name=\"grp\"/>\n" |
| 4024 | "<identity name=\"ident-name\"/>\n" |
| 4025 | "<notification name=\"notf\"/>\n" |
| 4026 | "<rpc name=\"rpc-name\"/>\n" |
| 4027 | "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 4028 | EXT_SUBELEM"\n" |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4029 | "</submodule>\n"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4030 | assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS); |
| 4031 | assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4032 | |
| 4033 | assert_string_equal(lysp_submod->name, "mod"); |
| 4034 | assert_string_equal(lysp_submod->revs, "2019-02-02"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4035 | assert_string_equal(lysp_submod->prefix, "pref"); |
| 4036 | assert_null(lysp_submod->filepath); |
| 4037 | assert_string_equal(lysp_submod->org, "org"); |
| 4038 | assert_string_equal(lysp_submod->contact, "contact"); |
| 4039 | assert_string_equal(lysp_submod->dsc, "desc"); |
| 4040 | assert_string_equal(lysp_submod->ref, "ref"); |
| 4041 | assert_int_equal(lysp_submod->version, LYS_VERSION_1_1); |
| 4042 | assert_string_equal(lysp_submod->imports->name, "a-mod"); |
| 4043 | assert_string_equal(lysp_submod->includes->name, "b-mod"); |
| 4044 | assert_string_equal(lysp_submod->extensions->name, "ext"); |
| 4045 | assert_string_equal(lysp_submod->features->name, "feature"); |
| 4046 | assert_string_equal(lysp_submod->identities->name, "ident-name"); |
| 4047 | assert_string_equal(lysp_submod->typedefs->name, "tpdf"); |
| 4048 | assert_string_equal(lysp_submod->groupings->name, "grp"); |
| 4049 | assert_string_equal(lysp_submod->data->name, "anyd"); |
| 4050 | assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA); |
| 4051 | assert_string_equal(lysp_submod->data->next->name, "anyx"); |
| 4052 | assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML); |
| 4053 | assert_string_equal(lysp_submod->data->next->next->name, "choice"); |
| 4054 | assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE); |
| 4055 | assert_string_equal(lysp_submod->data->next->next->next->name, "cont"); |
| 4056 | assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER); |
| 4057 | assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf"); |
| 4058 | assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF); |
| 4059 | assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist"); |
| 4060 | assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 4061 | assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list"); |
| 4062 | assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 4063 | assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name"); |
| 4064 | assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 4065 | assert_null(lysp_submod->data->next->next->next->next->next->next->next->next); |
| 4066 | assert_string_equal(lysp_submod->augments->nodeid, "target"); |
| 4067 | assert_string_equal(lysp_submod->rpcs->name, "rpc-name"); |
| 4068 | assert_string_equal(lysp_submod->notifs->name, "notf"); |
| 4069 | assert_string_equal(lysp_submod->deviations->nodeid, "target"); |
David Sedlák | e0ef1c6 | 2019-09-13 10:05:55 +0200 | [diff] [blame] | 4070 | assert_string_equal(lysp_submod->exts[0].name, "urn:example:extensions:c-define"); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 4071 | assert_int_equal(lysp_submod->exts[0].insubstmt_index, 0); |
| 4072 | assert_int_equal(lysp_submod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4073 | |
| 4074 | lysp_submodule_free(st->ctx, lysp_submod); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4075 | |
| 4076 | /* min subelemnts */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4077 | lyxml_ctx_free(st->yin_ctx->xmlctx); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4078 | lysp_submod = calloc(1, sizeof *lysp_submod); |
| 4079 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">" |
| 4080 | "<yang-version value=\"1.0\"/>" |
| 4081 | "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>" |
| 4082 | "</submodule>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4083 | assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS); |
| 4084 | assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4085 | assert_string_equal(lysp_submod->prefix, "pref"); |
| 4086 | assert_string_equal(lysp_submod->belongsto, "mod-name"); |
| 4087 | assert_int_equal(lysp_submod->version, LYS_VERSION_1_0); |
| 4088 | lysp_submodule_free(st->ctx, lysp_submod); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4089 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 4090 | /* incorrect subelem order */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4091 | lyxml_ctx_free(st->yin_ctx->xmlctx); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 4092 | lysp_submod = calloc(1, sizeof *lysp_submod); |
| 4093 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">" |
| 4094 | "<yang-version value=\"1.0\"/>" |
| 4095 | "<reference><text>ref</text></reference>\n" |
| 4096 | "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>" |
| 4097 | "</submodule>"; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4098 | assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS); |
| 4099 | assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_EVALID); |
| 4100 | logbuf_assert("Invalid order of submodule's sub-elements \"belongs-to\" can't appear after \"reference\". Line number 2."); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 4101 | lysp_submodule_free(st->ctx, lysp_submod); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 4102 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 4103 | st->finished_correctly = true; |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 4104 | } |
| 4105 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4106 | static void |
| 4107 | test_yin_parse_module(void **state) |
| 4108 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 4109 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4110 | const char *data; |
| 4111 | struct lys_module *mod; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4112 | struct lys_yin_parser_ctx *yin_ctx = NULL; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4113 | |
| 4114 | mod = calloc(1, sizeof *mod); |
| 4115 | mod->ctx = st->ctx; |
David Sedlák | d284488 | 2019-09-13 16:01:22 +0200 | [diff] [blame] | 4116 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" name=\"a\"> \n" |
| 4117 | "<yang-version value=\"1.1\"/>\n" |
| 4118 | "<namespace uri=\"urn:tests:extensions:metadata:a\"/>\n" |
| 4119 | "<prefix value=\"a\"/>\n" |
| 4120 | "<import module=\"ietf-yang-metadata\">\n" |
| 4121 | "<prefix value=\"md\"/>\n" |
| 4122 | "</import>\n" |
| 4123 | "<feature name=\"f\"/>\n" |
| 4124 | "<md:annotation name=\"x\">\n" |
| 4125 | "<description>\n" |
| 4126 | "<text>test</text>\n" |
| 4127 | "</description>\n" |
| 4128 | "<reference>\n" |
| 4129 | "<text>test</text>\n" |
| 4130 | "</reference>\n" |
| 4131 | "<if-feature name=\"f\"/>\n" |
| 4132 | "<status value=\"current\"/>\n" |
| 4133 | "<type name=\"uint8\"/>\n" |
| 4134 | "<units name=\"meters\"/>\n" |
| 4135 | "</md:annotation>\n" |
| 4136 | "</module>\n"; |
| 4137 | assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS); |
| 4138 | assert_null(mod->parsed->exts->child->next->child); |
| 4139 | assert_string_equal(mod->parsed->exts->child->next->arg, "test"); |
| 4140 | lys_module_free(mod, NULL); |
| 4141 | yin_parser_ctx_free(yin_ctx); |
| 4142 | mod = NULL; |
| 4143 | yin_ctx = NULL; |
| 4144 | |
| 4145 | mod = calloc(1, sizeof *mod); |
| 4146 | mod->ctx = st->ctx; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4147 | data = "<module name=\"example-foo\"" |
| 4148 | "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"" |
| 4149 | "xmlns:foo=\"urn:example:foo\"" |
| 4150 | "xmlns:myext=\"urn:example:extensions\">\n" |
| 4151 | |
| 4152 | "<yang-version value=\"1.0\"/>\n" |
| 4153 | |
| 4154 | "<namespace uri=\"urn:example:foo\"/>\n" |
| 4155 | "<prefix value=\"foo\"/>\n" |
| 4156 | |
| 4157 | "<import module=\"example-extensions\">\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4158 | "<prefix value=\"myext\"/>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4159 | "</import>\n" |
| 4160 | |
| 4161 | "<list name=\"interface\">\n" |
| 4162 | "<key value=\"name\"/>\n" |
| 4163 | "<leaf name=\"name\">\n" |
| 4164 | "<type name=\"string\"/>\n" |
| 4165 | "</leaf>\n" |
| 4166 | "<leaf name=\"mtu\">\n" |
| 4167 | "<type name=\"uint32\"/>\n" |
| 4168 | "<description>\n" |
| 4169 | "<text>The MTU of the interface.</text>\n" |
| 4170 | "</description>\n" |
| 4171 | "<myext:c-define name=\"MY_MTU\"/>\n" |
| 4172 | "</leaf>\n" |
| 4173 | "</list>\n" |
| 4174 | "</module>\n"; |
| 4175 | assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS); |
| 4176 | lys_module_free(mod, NULL); |
| 4177 | yin_parser_ctx_free(yin_ctx); |
| 4178 | mod = NULL; |
| 4179 | yin_ctx = NULL; |
| 4180 | |
| 4181 | mod = calloc(1, sizeof *mod); |
| 4182 | mod->ctx = st->ctx; |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4183 | data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 4184 | "<yang-version value=\"1.0\"/>\n" |
| 4185 | "<namespace uri=\"urn:example:foo\"/>\n" |
| 4186 | "<prefix value=\"foo\"/>\n" |
| 4187 | "</module>\n"; |
| 4188 | assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS); |
| 4189 | lys_module_free(mod, NULL); |
| 4190 | yin_parser_ctx_free(yin_ctx); |
| 4191 | mod = NULL; |
| 4192 | yin_ctx = NULL; |
| 4193 | |
| 4194 | |
| 4195 | mod = calloc(1, sizeof *mod); |
| 4196 | mod->ctx = st->ctx; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4197 | data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4198 | "</submodule>\n"; |
| 4199 | assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EINVAL); |
| 4200 | logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module."); |
| 4201 | lys_module_free(mod, NULL); |
| 4202 | yin_parser_ctx_free(yin_ctx); |
| 4203 | |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4204 | mod = calloc(1, sizeof *mod); |
| 4205 | mod->ctx = st->ctx; |
| 4206 | data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 4207 | "<yang-version value=\"1.0\"/>\n" |
| 4208 | "<namespace uri=\"urn:example:foo\"/>\n" |
| 4209 | "<prefix value=\"foo\"/>\n" |
| 4210 | "</module>" |
| 4211 | "<module>"; |
| 4212 | assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EVALID); |
| 4213 | logbuf_assert("Trailing garbage \"<module>\" after module, expected end-of-input. Line number 5."); |
| 4214 | lys_module_free(mod, NULL); |
| 4215 | yin_parser_ctx_free(yin_ctx); |
| 4216 | mod = NULL; |
| 4217 | yin_ctx = NULL; |
| 4218 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4219 | st->finished_correctly = true; |
| 4220 | } |
| 4221 | |
| 4222 | static void |
| 4223 | test_yin_parse_submodule(void **state) |
| 4224 | { |
Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame] | 4225 | struct test_parser_yin_state *st = *state; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4226 | const char *data; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 4227 | struct lys_yin_parser_ctx *yin_ctx = NULL; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4228 | struct lysp_submodule *submod = NULL; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4229 | struct lys_parser_ctx main_ctx = {}; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4230 | |
| 4231 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 4232 | "<submodule name=\"asub\"" |
| 4233 | "xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"" |
| 4234 | "xmlns:a=\"urn:a\">" |
| 4235 | "<yang-version value=\"1.0\"/>\n" |
| 4236 | "<belongs-to module=\"a\">" |
| 4237 | "<prefix value=\"a_pref\"/>" |
| 4238 | "</belongs-to>" |
| 4239 | "<include module=\"atop\"/>" |
| 4240 | "<feature name=\"fox\"/>" |
| 4241 | "<notification name=\"bar-notif\">" |
| 4242 | "<if-feature name=\"bar\"/>" |
| 4243 | "</notification>" |
| 4244 | "<notification name=\"fox-notif\">" |
| 4245 | "<if-feature name=\"fox\"/>" |
| 4246 | "</notification>" |
| 4247 | "<augment target-node=\"/a_pref:top\">" |
| 4248 | "<if-feature name=\"bar\"/>" |
| 4249 | "<container name=\"bar-sub\"/>" |
| 4250 | "</augment>" |
| 4251 | "<augment target-node=\"/top\">" |
| 4252 | "<container name=\"bar-sub2\"/>" |
| 4253 | "</augment>" |
| 4254 | "</submodule>"; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4255 | assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_SUCCESS); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4256 | lysp_submodule_free(st->ctx, submod); |
| 4257 | yin_parser_ctx_free(yin_ctx); |
| 4258 | yin_ctx = NULL; |
| 4259 | submod = NULL; |
| 4260 | |
| 4261 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4262 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4263 | "<yang-version value=\"1.0\"/>\n" |
| 4264 | "<belongs-to module=\"a\">" |
| 4265 | "<prefix value=\"a_pref\"/>" |
| 4266 | "</belongs-to>" |
| 4267 | "</submodule>"; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4268 | assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_SUCCESS); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4269 | lysp_submodule_free(st->ctx, submod); |
| 4270 | yin_parser_ctx_free(yin_ctx); |
| 4271 | yin_ctx = NULL; |
| 4272 | submod = NULL; |
| 4273 | |
| 4274 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4275 | "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4276 | "</module>"; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4277 | assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_EINVAL); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4278 | logbuf_assert("Input data contains module in situation when a submodule is expected."); |
| 4279 | lysp_submodule_free(st->ctx, submod); |
| 4280 | yin_parser_ctx_free(yin_ctx); |
| 4281 | yin_ctx = NULL; |
| 4282 | submod = NULL; |
| 4283 | |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4284 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 4285 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4286 | "<yang-version value=\"1.0\"/>\n" |
| 4287 | "<belongs-to module=\"a\">" |
| 4288 | "<prefix value=\"a_pref\"/>" |
| 4289 | "</belongs-to>" |
| 4290 | "</submodule>" |
| 4291 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 4292 | "<yang-version value=\"1.0\"/>\n" |
| 4293 | "<belongs-to module=\"a\">" |
| 4294 | "<prefix value=\"a_pref\"/>" |
| 4295 | "</belongs-to>" |
| 4296 | "</submodule>"; |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4297 | assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_EVALID); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 4298 | logbuf_assert("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input. Line number 2."); |
| 4299 | lysp_submodule_free(st->ctx, submod); |
| 4300 | yin_parser_ctx_free(yin_ctx); |
| 4301 | yin_ctx = NULL; |
| 4302 | submod = NULL; |
| 4303 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 4304 | st->finished_correctly = true; |
| 4305 | } |
| 4306 | |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 4307 | int |
| 4308 | main(void) |
| 4309 | { |
| 4310 | |
| 4311 | const struct CMUnitTest tests[] = { |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 4312 | 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] | 4313 | cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f), |
| 4314 | cmocka_unit_test_setup_teardown(test_yin_parse_extension_instance, setup_f, teardown_f), |
David Sedlák | 071f766 | 2019-09-12 02:02:51 +0200 | [diff] [blame] | 4315 | 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] | 4316 | 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] | 4317 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 4318 | cmocka_unit_test(test_yin_match_argument_name), |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 4319 | cmocka_unit_test_setup_teardown(test_enum_elem, setup_element_test, teardown_element_test), |
| 4320 | cmocka_unit_test_setup_teardown(test_bit_elem, setup_element_test, teardown_element_test), |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 4321 | cmocka_unit_test_setup_teardown(test_meta_elem, setup_element_test, teardown_element_test), |
| 4322 | cmocka_unit_test_setup_teardown(test_import_elem, setup_element_test, teardown_element_test), |
| 4323 | cmocka_unit_test_setup_teardown(test_status_elem, setup_element_test, teardown_element_test), |
| 4324 | cmocka_unit_test_setup_teardown(test_ext_elem, setup_element_test, teardown_element_test), |
| 4325 | cmocka_unit_test_setup_teardown(test_yin_element_elem, setup_element_test, teardown_element_test), |
| 4326 | cmocka_unit_test_setup_teardown(test_yangversion_elem, setup_element_test, teardown_element_test), |
| 4327 | 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] | 4328 | cmocka_unit_test_setup_teardown(test_argument_elem, setup_element_test, teardown_element_test), |
| 4329 | cmocka_unit_test_setup_teardown(test_base_elem, setup_element_test, teardown_element_test), |
| 4330 | cmocka_unit_test_setup_teardown(test_belongsto_elem, setup_element_test, teardown_element_test), |
| 4331 | cmocka_unit_test_setup_teardown(test_config_elem, setup_element_test, teardown_element_test), |
| 4332 | cmocka_unit_test_setup_teardown(test_default_elem, setup_element_test, teardown_element_test), |
| 4333 | cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup_element_test, teardown_element_test), |
| 4334 | cmocka_unit_test_setup_teardown(test_err_msg_elem, setup_element_test, teardown_element_test), |
| 4335 | cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup_element_test, teardown_element_test), |
| 4336 | cmocka_unit_test_setup_teardown(test_iffeature_elem, setup_element_test, teardown_element_test), |
| 4337 | cmocka_unit_test_setup_teardown(test_length_elem, setup_element_test, teardown_element_test), |
| 4338 | cmocka_unit_test_setup_teardown(test_modifier_elem, setup_element_test, teardown_element_test), |
| 4339 | cmocka_unit_test_setup_teardown(test_namespace_elem, setup_element_test, teardown_element_test), |
| 4340 | cmocka_unit_test_setup_teardown(test_path_elem, setup_element_test, teardown_element_test), |
| 4341 | cmocka_unit_test_setup_teardown(test_pattern_elem, setup_element_test, teardown_element_test), |
| 4342 | 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] | 4343 | cmocka_unit_test_setup_teardown(test_prefix_elem, setup_element_test, teardown_element_test), |
| 4344 | cmocka_unit_test_setup_teardown(test_range_elem, setup_element_test, teardown_element_test), |
| 4345 | cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup_element_test, teardown_element_test), |
| 4346 | cmocka_unit_test_setup_teardown(test_revision_date_elem, setup_element_test, teardown_element_test), |
| 4347 | cmocka_unit_test_setup_teardown(test_unique_elem, setup_element_test, teardown_element_test), |
| 4348 | cmocka_unit_test_setup_teardown(test_units_elem, setup_element_test, teardown_element_test), |
| 4349 | cmocka_unit_test_setup_teardown(test_when_elem, setup_element_test, teardown_element_test), |
| 4350 | 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] | 4351 | 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] | 4352 | 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] | 4353 | 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] | 4354 | 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] | 4355 | 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] | 4356 | 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] | 4357 | 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] | 4358 | 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] | 4359 | 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] | 4360 | 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] | 4361 | 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] | 4362 | 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] | 4363 | 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] | 4364 | cmocka_unit_test_setup_teardown(test_include_elem, setup_element_test, teardown_element_test), |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 4365 | 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] | 4366 | 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] | 4367 | 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] | 4368 | 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] | 4369 | 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] | 4370 | 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] | 4371 | 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] | 4372 | 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] | 4373 | 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] | 4374 | 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] | 4375 | 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] | 4376 | 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] | 4377 | 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] | 4378 | |
| 4379 | cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_logger, teardown_logger), |
| 4380 | 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] | 4381 | }; |
| 4382 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 4383 | 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] | 4384 | } |