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