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