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