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