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