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 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 6 | * Copyright (c) 2015 - 2020 CESNET, z.s.p.o. |
David Sedlák | b1ce3f8 | 2019-06-05 14:37:26 +0200 | [diff] [blame] | 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 | */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 14 | #define _UTEST_MAIN_ |
| 15 | #include "utests.h" |
David Sedlák | b1ce3f8 | 2019-06-05 14:37:26 +0200 | [diff] [blame] | 16 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 17 | #include <stdbool.h> |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 18 | #include <stdio.h> |
| 19 | #include <string.h> |
| 20 | |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 21 | #include "common.h" |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 22 | #include "in.h" |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 23 | #include "parser_internal.h" |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 24 | #include "schema_compile.h" |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 25 | #include "tree_schema.h" |
| 26 | #include "tree_schema_internal.h" |
| 27 | #include "xml.h" |
| 28 | #include "xpath.h" |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 29 | |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 30 | /* copied from parser_yin.c */ |
| 31 | enum yin_argument { |
| 32 | YIN_ARG_UNKNOWN = 0, /**< parsed argument can not be matched with any supported yin argument keyword */ |
| 33 | YIN_ARG_NAME, /**< argument name */ |
| 34 | YIN_ARG_TARGET_NODE, /**< argument target-node */ |
| 35 | YIN_ARG_MODULE, /**< argument module */ |
| 36 | YIN_ARG_VALUE, /**< argument value */ |
| 37 | YIN_ARG_TEXT, /**< argument text */ |
| 38 | YIN_ARG_CONDITION, /**< argument condition */ |
| 39 | YIN_ARG_URI, /**< argument uri */ |
| 40 | YIN_ARG_DATE, /**< argument data */ |
| 41 | YIN_ARG_TAG, /**< argument tag */ |
| 42 | YIN_ARG_NONE /**< empty (special value) */ |
| 43 | }; |
| 44 | |
| 45 | struct yin_subelement { |
| 46 | enum ly_stmt type; /**< type of keyword */ |
| 47 | void *dest; /**< meta infromation passed to responsible function (mostly information about where parsed subelement should be stored) */ |
| 48 | uint16_t flags; /**< describes constraints of subelement can be set to YIN_SUBELEM_MANDATORY, YIN_SUBELEM_UNIQUE, YIN_SUBELEM_FIRST, YIN_SUBELEM_VER2, and YIN_SUBELEM_DEFAULT_TEXT */ |
| 49 | }; |
| 50 | |
| 51 | struct import_meta { |
| 52 | const char *prefix; /**< module prefix. */ |
| 53 | struct lysp_import **imports; /**< imports to add to. */ |
| 54 | }; |
| 55 | |
| 56 | struct yin_argument_meta { |
| 57 | uint16_t *flags; /**< Argument flags */ |
| 58 | const char **argument; /**< Argument value */ |
| 59 | }; |
| 60 | |
| 61 | struct tree_node_meta { |
| 62 | struct lysp_node *parent; /**< parent node */ |
| 63 | struct lysp_node **nodes; /**< linked list of siblings */ |
| 64 | }; |
| 65 | |
| 66 | struct include_meta { |
| 67 | const char *name; /**< Module/submodule name. */ |
| 68 | struct lysp_include **includes; /**< [Sized array](@ref sizedarrays) of parsed includes to add to. */ |
| 69 | }; |
| 70 | |
| 71 | struct inout_meta { |
| 72 | struct lysp_node *parent; /**< Parent node. */ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 73 | struct lysp_node_action_inout *inout_p; /**< inout_p Input/output pointer to write to. */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | struct minmax_dev_meta { |
| 77 | uint32_t *lim; /**< min/max value to write to. */ |
| 78 | uint16_t *flags; /**< min/max flags to write to. */ |
| 79 | struct lysp_ext_instance **exts; /**< extension instances to add to. */ |
| 80 | }; |
| 81 | |
| 82 | #define YIN_SUBELEM_MANDATORY 0x01 |
| 83 | #define YIN_SUBELEM_UNIQUE 0x02 |
| 84 | #define YIN_SUBELEM_FIRST 0x04 |
| 85 | #define YIN_SUBELEM_VER2 0x08 |
| 86 | |
| 87 | #define YIN_SUBELEM_PARSED 0x80 |
| 88 | |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 89 | /* prototypes of static functions */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 90 | enum yin_argument yin_match_argument_name(const char *name, size_t len); |
| 91 | LY_ERR yin_parse_content(struct lys_yin_parser_ctx *ctx, struct yin_subelement *subelem_info, size_t subelem_info_size, |
| 92 | enum ly_stmt current_element, const char **text_content, struct lysp_ext_instance **exts); |
| 93 | LY_ERR yin_validate_value(struct lys_yin_parser_ctx *ctx, enum yang_arg val_type); |
| 94 | enum ly_stmt yin_match_keyword(struct lys_yin_parser_ctx *ctx, const char *name, size_t name_len, |
| 95 | const char *prefix, size_t prefix_len, enum ly_stmt parrent); |
| 96 | LY_ERR yin_parse_extension_instance(struct lys_yin_parser_ctx *ctx, LYEXT_SUBSTMT subelem, LY_ARRAY_COUNT_TYPE subelem_index, |
| 97 | struct lysp_ext_instance **exts); |
| 98 | LY_ERR yin_parse_element_generic(struct lys_yin_parser_ctx *ctx, enum ly_stmt parent, struct lysp_stmt **element); |
| 99 | LY_ERR yin_parse_mod(struct lys_yin_parser_ctx *ctx, struct lysp_module *mod); |
| 100 | LY_ERR yin_parse_submod(struct lys_yin_parser_ctx *ctx, struct lysp_submodule *submod); |
| 101 | |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 102 | 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] | 103 | 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] | 104 | 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] | 105 | 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] | 106 | 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] | 107 | 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] | 108 | 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] | 109 | 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] | 110 | 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] | 111 | 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] | 112 | void lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 113 | void lysp_grp_free(struct ly_ctx *ctx, struct lysp_node_grp *grp); |
| 114 | void lysp_augment_free(struct ly_ctx *ctx, struct lysp_node_augment *augment); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 115 | 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] | 116 | 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] | 117 | 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] | 118 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 119 | /* wrapping element used for mocking has nothing to do with real module structure */ |
| 120 | #define ELEMENT_WRAPPER_START "<status xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 121 | #define ELEMENT_WRAPPER_END "</status>" |
| 122 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 123 | #define TEST_1_CHECK_LYSP_EXT_INSTANCE(NODE, INSUBSTMT)\ |
| 124 | CHECK_LYSP_EXT_INSTANCE((NODE), NULL, 1, NULL, INSUBSTMT, 0, "urn:example:extensions:c-define", 0, 0x2, 0x1) |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 125 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 126 | struct lys_yin_parser_ctx *YCTX; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 127 | |
| 128 | static int |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 129 | setup_ctx(void **state) |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 130 | { |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 131 | /* allocate parser context */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 132 | YCTX = calloc(1, sizeof(*YCTX)); |
| 133 | YCTX->format = LYS_IN_YIN; |
David Sedlák | 8f5bce0 | 2019-06-03 16:41:08 +0200 | [diff] [blame] | 134 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 135 | /* allocate new parsed module */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 136 | YCTX->parsed_mod = calloc(1, sizeof *YCTX->parsed_mod); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 137 | |
| 138 | /* allocate new module */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 139 | YCTX->parsed_mod->mod = calloc(1, sizeof *YCTX->parsed_mod->mod); |
| 140 | YCTX->parsed_mod->mod->ctx = UTEST_LYCTX; |
| 141 | YCTX->parsed_mod->mod->parsed = YCTX->parsed_mod; |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 142 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 143 | return 0; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | static int |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 147 | setup(void **state) |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 148 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 149 | UTEST_SETUP; |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 150 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 151 | setup_ctx(state); |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 152 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 153 | return 0; |
David Sedlák | 79e50cb | 2019-06-05 16:33:09 +0200 | [diff] [blame] | 154 | } |
| 155 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 156 | static int |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 157 | teardown_ctx(void **UNUSED(state)) |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 158 | { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 159 | lyxml_ctx_free(YCTX->xmlctx); |
| 160 | lys_module_free(YCTX->parsed_mod->mod, NULL); |
| 161 | free(YCTX); |
| 162 | YCTX = NULL; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 163 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 164 | return 0; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 165 | } |
| 166 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 167 | static int |
| 168 | teardown(void **state) |
| 169 | { |
| 170 | teardown_ctx(state); |
| 171 | |
| 172 | UTEST_TEARDOWN; |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | #define RESET_STATE \ |
| 178 | ly_in_free(UTEST_IN, 0); \ |
| 179 | UTEST_IN = NULL; \ |
| 180 | teardown_ctx(state); \ |
| 181 | setup_ctx(state) |
| 182 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 183 | static void |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 184 | test_yin_match_keyword(void **state) |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 185 | { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 186 | const char *prefix; |
| 187 | size_t prefix_len; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 188 | |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 189 | /* create mock yin namespace in xml context */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 190 | ly_in_new_memory("<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />", &UTEST_IN); |
| 191 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
| 192 | prefix = YCTX->xmlctx->prefix; |
| 193 | prefix_len = YCTX->xmlctx->prefix_len; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 194 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 195 | assert_int_equal(yin_match_keyword(YCTX, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE); |
| 196 | assert_int_equal(yin_match_keyword(YCTX, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE); |
| 197 | assert_int_equal(yin_match_keyword(YCTX, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE); |
| 198 | assert_int_equal(yin_match_keyword(YCTX, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA); |
| 199 | assert_int_equal(yin_match_keyword(YCTX, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML); |
| 200 | assert_int_equal(yin_match_keyword(YCTX, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT); |
| 201 | assert_int_equal(yin_match_keyword(YCTX, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT); |
| 202 | assert_int_equal(yin_match_keyword(YCTX, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE); |
| 203 | assert_int_equal(yin_match_keyword(YCTX, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO); |
| 204 | assert_int_equal(yin_match_keyword(YCTX, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT); |
| 205 | assert_int_equal(yin_match_keyword(YCTX, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE); |
| 206 | assert_int_equal(yin_match_keyword(YCTX, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE); |
| 207 | assert_int_equal(yin_match_keyword(YCTX, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG); |
| 208 | assert_int_equal(yin_match_keyword(YCTX, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT); |
| 209 | assert_int_equal(yin_match_keyword(YCTX, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER); |
| 210 | assert_int_equal(yin_match_keyword(YCTX, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT); |
| 211 | assert_int_equal(yin_match_keyword(YCTX, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION); |
| 212 | assert_int_equal(yin_match_keyword(YCTX, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE); |
| 213 | assert_int_equal(yin_match_keyword(YCTX, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION); |
| 214 | assert_int_equal(yin_match_keyword(YCTX, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM); |
| 215 | assert_int_equal(yin_match_keyword(YCTX, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_APP_TAG); |
| 216 | assert_int_equal(yin_match_keyword(YCTX, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE); |
| 217 | assert_int_equal(yin_match_keyword(YCTX, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION); |
| 218 | assert_int_equal(yin_match_keyword(YCTX, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE); |
| 219 | assert_int_equal(yin_match_keyword(YCTX, "fraction-digits", strlen("fraction-digits"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS); |
| 220 | assert_int_equal(yin_match_keyword(YCTX, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING); |
| 221 | assert_int_equal(yin_match_keyword(YCTX, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY); |
| 222 | assert_int_equal(yin_match_keyword(YCTX, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE); |
| 223 | assert_int_equal(yin_match_keyword(YCTX, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT); |
| 224 | assert_int_equal(yin_match_keyword(YCTX, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE); |
| 225 | assert_int_equal(yin_match_keyword(YCTX, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT); |
| 226 | assert_int_equal(yin_match_keyword(YCTX, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY); |
| 227 | assert_int_equal(yin_match_keyword(YCTX, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF); |
| 228 | assert_int_equal(yin_match_keyword(YCTX, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST); |
| 229 | assert_int_equal(yin_match_keyword(YCTX, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH); |
| 230 | assert_int_equal(yin_match_keyword(YCTX, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST); |
| 231 | assert_int_equal(yin_match_keyword(YCTX, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY); |
| 232 | assert_int_equal(yin_match_keyword(YCTX, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS); |
| 233 | assert_int_equal(yin_match_keyword(YCTX, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS); |
| 234 | assert_int_equal(yin_match_keyword(YCTX, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER); |
| 235 | assert_int_equal(yin_match_keyword(YCTX, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE); |
| 236 | assert_int_equal(yin_match_keyword(YCTX, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST); |
| 237 | assert_int_equal(yin_match_keyword(YCTX, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE); |
| 238 | assert_int_equal(yin_match_keyword(YCTX, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION); |
| 239 | assert_int_equal(yin_match_keyword(YCTX, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY); |
| 240 | assert_int_equal(yin_match_keyword(YCTX, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION); |
| 241 | assert_int_equal(yin_match_keyword(YCTX, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT); |
| 242 | assert_int_equal(yin_match_keyword(YCTX, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH); |
| 243 | assert_int_equal(yin_match_keyword(YCTX, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN); |
| 244 | assert_int_equal(yin_match_keyword(YCTX, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION); |
| 245 | assert_int_equal(yin_match_keyword(YCTX, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX); |
| 246 | assert_int_equal(yin_match_keyword(YCTX, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE); |
| 247 | assert_int_equal(yin_match_keyword(YCTX, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE); |
| 248 | assert_int_equal(yin_match_keyword(YCTX, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE); |
| 249 | assert_int_equal(yin_match_keyword(YCTX, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE); |
| 250 | assert_int_equal(yin_match_keyword(YCTX, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE); |
| 251 | assert_int_equal(yin_match_keyword(YCTX, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION); |
| 252 | assert_int_equal(yin_match_keyword(YCTX, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE); |
| 253 | assert_int_equal(yin_match_keyword(YCTX, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC); |
| 254 | assert_int_equal(yin_match_keyword(YCTX, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS); |
| 255 | assert_int_equal(yin_match_keyword(YCTX, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE); |
| 256 | assert_int_equal(yin_match_keyword(YCTX, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE); |
| 257 | assert_int_equal(yin_match_keyword(YCTX, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF); |
| 258 | assert_int_equal(yin_match_keyword(YCTX, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE); |
| 259 | assert_int_equal(yin_match_keyword(YCTX, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS); |
| 260 | assert_int_equal(yin_match_keyword(YCTX, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES); |
| 261 | assert_int_equal(yin_match_keyword(YCTX, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE); |
| 262 | assert_int_equal(yin_match_keyword(YCTX, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN); |
| 263 | assert_int_equal(yin_match_keyword(YCTX, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION); |
| 264 | assert_int_equal(yin_match_keyword(YCTX, "yin-element", strlen("yin-element"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YIN_ELEMENT); |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 265 | } |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 266 | |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 267 | static void |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 268 | test_yin_match_argument_name(void **UNUSED(state)) |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 269 | { |
David Sedlák | 060b00e | 2019-06-19 11:12:06 +0200 | [diff] [blame] | 270 | assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN); |
| 271 | assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN); |
| 272 | assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN); |
| 273 | assert_int_equal(yin_match_argument_name("condition", 9), YIN_ARG_CONDITION); |
| 274 | assert_int_equal(yin_match_argument_name("date", 4), YIN_ARG_DATE); |
| 275 | assert_int_equal(yin_match_argument_name("module", 6), YIN_ARG_MODULE); |
| 276 | assert_int_equal(yin_match_argument_name("name", 4), YIN_ARG_NAME); |
| 277 | assert_int_equal(yin_match_argument_name("tag", 3), YIN_ARG_TAG); |
| 278 | assert_int_equal(yin_match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE); |
| 279 | assert_int_equal(yin_match_argument_name("text", 4), YIN_ARG_TEXT); |
| 280 | assert_int_equal(yin_match_argument_name("uri", 3), YIN_ARG_URI); |
| 281 | 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] | 282 | } |
| 283 | |
David Sedlák | 68a1af1 | 2019-03-08 13:46:54 +0100 | [diff] [blame] | 284 | static void |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 285 | test_yin_parse_element_generic(void **state) |
| 286 | { |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 287 | struct lysp_ext_instance exts; |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 288 | LY_ERR ret; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 289 | const char *arg; |
| 290 | const char *stmt; |
| 291 | const char *data; |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 292 | |
| 293 | memset(&exts, 0, sizeof(exts)); |
| 294 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 295 | data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>"; |
| 296 | ly_in_new_memory(data, &UTEST_IN); |
| 297 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 298 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 299 | ret = yin_parse_element_generic(YCTX, LY_STMT_EXTENSION_INSTANCE, &exts.child); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 300 | assert_int_equal(ret, LY_SUCCESS); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 301 | assert_int_equal(YCTX->xmlctx->status, LYXML_ELEM_CLOSE); |
| 302 | stmt = "urn:example:extensions:elem"; |
| 303 | arg = "text_value"; |
| 304 | CHECK_LYSP_STMT(exts.child, arg, 1, 0, 0x45, 0, stmt); |
| 305 | stmt = "attr"; |
| 306 | arg = "value"; |
| 307 | CHECK_LYSP_STMT(exts.child->child, arg, 0, 0x400, 0, 0, stmt); |
| 308 | lysp_ext_instance_free(UTEST_LYCTX, &exts); |
| 309 | RESET_STATE; |
David Sedlák | 5392a21 | 2019-07-01 09:19:10 +0200 | [diff] [blame] | 310 | |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 311 | data = "<myext:elem xmlns:myext=\"urn:example:extensions\"></myext:elem>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 312 | ly_in_new_memory(data, &UTEST_IN); |
| 313 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 314 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 315 | ret = yin_parse_element_generic(YCTX, LY_STMT_EXTENSION_INSTANCE, &exts.child); |
David Sedlák | 5392a21 | 2019-07-01 09:19:10 +0200 | [diff] [blame] | 316 | assert_int_equal(ret, LY_SUCCESS); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 317 | assert_int_equal(YCTX->xmlctx->status, LYXML_ELEM_CLOSE); |
| 318 | stmt = "urn:example:extensions:elem"; |
| 319 | CHECK_LYSP_STMT(exts.child, NULL, 0, 0x0, 0x45, 0, stmt); |
| 320 | lysp_ext_instance_free(UTEST_LYCTX, &exts); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | static void |
| 324 | test_yin_parse_extension_instance(void **state) |
| 325 | { |
| 326 | LY_ERR ret; |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 327 | struct lysp_ext_instance *exts = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 328 | struct lysp_stmt *act_child; |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 329 | const char *data = "<myext:ext value1=\"test\" value=\"test2\" xmlns:myext=\"urn:example:extensions\"><myext:subelem>text</myext:subelem></myext:ext>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 330 | const char *exts_name; |
| 331 | const char *stmt = "value1"; |
| 332 | const char *arg = "test"; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 333 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 334 | ly_in_new_memory(data, &UTEST_IN); |
| 335 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 336 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 337 | ret = yin_parse_extension_instance(YCTX, LYEXT_SUBSTMT_CONTACT, 0, &exts); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 338 | assert_int_equal(ret, LY_SUCCESS); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 339 | exts_name = "urn:example:extensions:ext"; |
| 340 | CHECK_LYSP_EXT_INSTANCE(exts, NULL, 1, NULL, |
| 341 | LYEXT_SUBSTMT_CONTACT, 0, exts_name, 0, 0x2, LYS_YIN); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 342 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 343 | CHECK_LYSP_STMT(exts->child, arg, 0, LYS_YIN_ATTR, 0, 1, stmt); |
| 344 | stmt = "value"; |
| 345 | arg = "test2"; |
| 346 | CHECK_LYSP_STMT(exts->child->next, arg, 0, LYS_YIN_ATTR, 0, 1, stmt); |
| 347 | stmt = "urn:example:extensions:subelem"; |
| 348 | arg = "text"; |
| 349 | CHECK_LYSP_STMT(exts->child->next->next, arg, 0, 0, 0x45, 0, stmt); |
| 350 | lysp_ext_instance_free(UTEST_LYCTX, exts); |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 351 | LY_ARRAY_FREE(exts); |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 352 | exts = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 353 | RESET_STATE; |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 354 | |
David Sedlák | b0ca07d | 2019-09-11 11:54:05 +0200 | [diff] [blame] | 355 | data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" />"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 356 | ly_in_new_memory(data, &UTEST_IN); |
| 357 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 358 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 359 | ret = yin_parse_extension_instance(YCTX, LYEXT_SUBSTMT_CONTACT, 0, &exts); |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 360 | assert_int_equal(ret, LY_SUCCESS); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 361 | exts_name = "urn:example:extensions:extension-elem"; |
| 362 | CHECK_LYSP_EXT_INSTANCE(exts, NULL, 0, NULL, |
| 363 | LYEXT_SUBSTMT_CONTACT, 0, exts_name, 0, 0x2, LYS_YIN); |
| 364 | lysp_ext_instance_free(UTEST_LYCTX, exts); |
David Sedlák | f250ecf | 2019-07-01 11:02:05 +0200 | [diff] [blame] | 365 | LY_ARRAY_FREE(exts); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 366 | exts = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 367 | RESET_STATE; |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 368 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 369 | data = |
| 370 | "<myext:ext attr1=\"text1\" attr2=\"text2\" xmlns:myext=\"urn:example:extensions\">\n" |
| 371 | " <myext:ext-sub1/>\n" |
| 372 | " <myext:ext-sub2 sattr1=\"stext2\">\n" |
| 373 | " <myext:ext-sub21>\n" |
| 374 | " <myext:ext-sub211 sattr21=\"text21\"/>\n" |
| 375 | " </myext:ext-sub21>\n" |
| 376 | " </myext:ext-sub2>\n" |
| 377 | " <myext:ext-sub3 attr3=\"text3\"></myext:ext-sub3>\n" |
| 378 | "</myext:ext>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 379 | ly_in_new_memory(data, &UTEST_IN); |
| 380 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 381 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 382 | ret = yin_parse_extension_instance(YCTX, LYEXT_SUBSTMT_CONTACT, 0, &exts); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 383 | assert_int_equal(ret, LY_SUCCESS); |
| 384 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 385 | exts_name = "urn:example:extensions:ext"; |
| 386 | CHECK_LYSP_EXT_INSTANCE(exts, NULL, 1, NULL, |
| 387 | LYEXT_SUBSTMT_CONTACT, 0, exts_name, 0, 0x2, LYS_YIN); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 388 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 389 | stmt = "attr1"; |
| 390 | arg = "text1"; |
| 391 | act_child = exts->child; |
| 392 | CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0x0, 1, stmt); |
| 393 | stmt = "attr2"; |
| 394 | arg = "text2"; |
| 395 | act_child = act_child->next; |
| 396 | CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0x0, 1, stmt); |
| 397 | stmt = "urn:example:extensions:ext-sub1"; |
| 398 | arg = NULL; |
| 399 | act_child = act_child->next; |
| 400 | CHECK_LYSP_STMT(act_child, arg, NULL, 0, 0x45, 1, stmt); |
| 401 | stmt = "urn:example:extensions:ext-sub2"; |
| 402 | arg = NULL; |
| 403 | act_child = act_child->next; |
| 404 | CHECK_LYSP_STMT(act_child, arg, 1, 0, 0x45, 1, stmt); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 405 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 406 | stmt = "sattr1"; |
| 407 | arg = "stext2"; |
| 408 | act_child = act_child->child; |
| 409 | CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0, 1, stmt); |
| 410 | stmt = "urn:example:extensions:ext-sub21"; |
| 411 | arg = NULL; |
| 412 | act_child = act_child->next; |
| 413 | CHECK_LYSP_STMT(act_child, arg, 1, 0, 0x45, 0, stmt); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 414 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 415 | stmt = "urn:example:extensions:ext-sub211"; |
| 416 | arg = NULL; |
| 417 | act_child = act_child->child; |
| 418 | CHECK_LYSP_STMT(act_child, arg, 1, 0, 0x45, 0, stmt); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 419 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 420 | stmt = "sattr21"; |
| 421 | arg = "text21"; |
| 422 | act_child = act_child->child; |
| 423 | CHECK_LYSP_STMT(act_child, arg, 0, LYS_YIN_ATTR, 0, 0, stmt); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 424 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 425 | stmt = "urn:example:extensions:ext-sub3"; |
| 426 | arg = NULL; |
| 427 | act_child = exts->child->next->next->next->next; |
| 428 | CHECK_LYSP_STMT(act_child, arg, 1, 0, 0x45, 0, stmt); |
| 429 | stmt = "attr3"; |
| 430 | arg = "text3"; |
| 431 | act_child = act_child->child; |
| 432 | CHECK_LYSP_STMT(act_child, arg, 0, LYS_YIN_ATTR, 0, 0, stmt); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 433 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 434 | lysp_ext_instance_free(UTEST_LYCTX, exts); |
David Sedlák | add0c2e | 2019-08-16 10:49:12 +0200 | [diff] [blame] | 435 | LY_ARRAY_FREE(exts); |
| 436 | exts = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 437 | RESET_STATE; |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 438 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 439 | data = |
| 440 | "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" xmlns:yin=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 441 | " <yin:action name=\"act-name\" pre:prefixed=\"ignored\"/>\n" |
| 442 | " <yin:augment target-node=\"target\"/>\n" |
| 443 | " <yin:status value=\"value\"/>\n" |
| 444 | " <yin:include module=\"mod\"/>\n" |
| 445 | " <yin:input />\n" |
| 446 | " <yin:must condition=\"cond\"/>\n" |
| 447 | " <yin:namespace uri=\"uri\"/>\n" |
| 448 | " <yin:revision date=\"data\"/>\n" |
| 449 | " <yin:unique tag=\"tag\"/>\n" |
| 450 | " <yin:description><yin:text>contact-val</yin:text></yin:description>\n" |
| 451 | " <yin:error-message><yin:value>err-msg</yin:value></yin:error-message>\n" |
| 452 | "</myext:extension-elem>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 453 | ly_in_new_memory(data, &UTEST_IN); |
| 454 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 455 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 456 | ret = yin_parse_extension_instance(YCTX, LYEXT_SUBSTMT_CONTACT, 0, &exts); |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 457 | assert_int_equal(ret, LY_SUCCESS); |
| 458 | assert_string_equal(exts->child->arg, "act-name"); |
| 459 | assert_string_equal(exts->child->next->arg, "target"); |
| 460 | assert_string_equal(exts->child->next->next->arg, "value"); |
| 461 | assert_string_equal(exts->child->next->next->next->arg, "mod"); |
| 462 | assert_null(exts->child->next->next->next->next->arg); |
| 463 | assert_string_equal(exts->child->next->next->next->next->next->arg, "cond"); |
| 464 | assert_string_equal(exts->child->next->next->next->next->next->next->arg, "uri"); |
| 465 | assert_string_equal(exts->child->next->next->next->next->next->next->next->arg, "data"); |
| 466 | assert_string_equal(exts->child->next->next->next->next->next->next->next->next->arg, "tag"); |
| 467 | assert_string_equal(exts->child->next->next->next->next->next->next->next->next->next->arg, "contact-val"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 468 | lysp_ext_instance_free(UTEST_LYCTX, exts); |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 469 | LY_ARRAY_FREE(exts); |
| 470 | exts = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 471 | RESET_STATE; |
David Sedlák | b1a7835 | 2019-06-28 16:16:29 +0200 | [diff] [blame] | 472 | } |
| 473 | |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 474 | static void |
| 475 | test_yin_parse_content(void **state) |
| 476 | { |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 477 | LY_ERR ret = LY_SUCCESS; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 478 | const char *data = |
| 479 | "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 480 | " <myext:custom xmlns:myext=\"urn:example:extensions\">totally amazing extension</myext:custom>\n" |
| 481 | " <extension name=\"ext\">\n" |
| 482 | " <argument name=\"argname\"></argument>\n" |
| 483 | " <description><text>desc</text></description>\n" |
| 484 | " <reference><text>ref</text></reference>\n" |
| 485 | " <status value=\"deprecated\"></status>\n" |
| 486 | " </extension>\n" |
| 487 | " <text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>\n" |
| 488 | " <if-feature name=\"foo\"></if-feature>\n" |
| 489 | " <when condition=\"condition...\">\n" |
| 490 | " <reference><text>when_ref</text></reference>\n" |
| 491 | " <description><text>when_desc</text></description>\n" |
| 492 | " </when>\n" |
| 493 | " <config value=\"true\"/>\n" |
| 494 | " <error-message>\n" |
| 495 | " <value>error-msg</value>\n" |
| 496 | " </error-message>\n" |
| 497 | " <error-app-tag value=\"err-app-tag\"/>\n" |
| 498 | " <units name=\"radians\"></units>\n" |
| 499 | " <default value=\"default-value\"/>\n" |
| 500 | " <position value=\"25\"></position>\n" |
| 501 | " <value value=\"-5\"/>\n" |
| 502 | " <require-instance value=\"true\"></require-instance>\n" |
| 503 | " <range value=\"5..10\" />\n" |
| 504 | " <length value=\"baf\"/>\n" |
| 505 | " <pattern value='pattern'>\n" |
| 506 | " <modifier value='invert-match'/>\n" |
| 507 | " </pattern>\n" |
| 508 | " <enum name=\"yay\">\n" |
| 509 | " </enum>\n" |
| 510 | "</prefix>"; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 511 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 512 | const char **if_features = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 513 | const char *value, *error_message, *app_tag, *units; |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 514 | struct lysp_qname def = {0}; |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 515 | struct lysp_ext *ext_def = NULL; |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 516 | struct lysp_when *when_p = NULL; |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 517 | struct lysp_type_enum pos_enum = {}, val_enum = {}; |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 518 | struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {}; |
Juraj Vijtiuk | f6a0737 | 2020-10-29 21:13:33 +0100 | [diff] [blame] | 519 | uint16_t config = 0; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 520 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 521 | ly_in_new_memory(data, &UTEST_IN); |
| 522 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
| 523 | lyxml_ctx_next(YCTX->xmlctx); |
| 524 | lyxml_ctx_next(YCTX->xmlctx); |
| 525 | lyxml_ctx_next(YCTX->xmlctx); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 526 | |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 527 | struct yin_subelement subelems[17] = { |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 528 | {LY_STMT_CONFIG, &config, 0}, |
| 529 | {LY_STMT_DEFAULT, &def, YIN_SUBELEM_UNIQUE}, |
| 530 | {LY_STMT_ENUM, &enum_type, 0}, |
| 531 | {LY_STMT_ERROR_APP_TAG, &app_tag, YIN_SUBELEM_UNIQUE}, |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 532 | {LY_STMT_ERROR_MESSAGE, &error_message, 0}, |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 533 | {LY_STMT_EXTENSION, &ext_def, 0}, |
| 534 | {LY_STMT_IF_FEATURE, &if_features, 0}, |
| 535 | {LY_STMT_LENGTH, &len_type, 0}, |
| 536 | {LY_STMT_PATTERN, &patter_type, 0}, |
| 537 | {LY_STMT_POSITION, &pos_enum, 0}, |
| 538 | {LY_STMT_RANGE, &range_type, 0}, |
| 539 | {LY_STMT_REQUIRE_INSTANCE, &req_type, 0}, |
| 540 | {LY_STMT_UNITS, &units, YIN_SUBELEM_UNIQUE}, |
| 541 | {LY_STMT_VALUE, &val_enum, 0}, |
| 542 | {LY_STMT_WHEN, &when_p, 0}, |
| 543 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 544 | {LY_STMT_ARG_TEXT, &value, 0} |
| 545 | }; |
| 546 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 547 | ret = yin_parse_content(YCTX, subelems, 17, LY_STMT_PREFIX, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 548 | assert_int_equal(ret, LY_SUCCESS); |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 549 | /* check parsed values */ |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 550 | assert_string_equal(def.str, "default-value"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 551 | const char *exts_name = "urn:example:extensions:custom"; |
| 552 | const char *exts_arg = "totally amazing extension"; |
| 553 | |
| 554 | CHECK_LYSP_EXT_INSTANCE(exts, exts_arg, 0, NULL, |
| 555 | LYEXT_SUBSTMT_PREFIX, 0, exts_name, 0, 0x1, 0x1); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 556 | assert_string_equal(value, "wsefsdf"); |
David Sedlák | a5b1d38 | 2019-07-10 16:31:09 +0200 | [diff] [blame] | 557 | assert_string_equal(units, "radians"); |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 558 | assert_string_equal(when_p->cond, "condition..."); |
| 559 | assert_string_equal(when_p->dsc, "when_desc"); |
| 560 | assert_string_equal(when_p->ref, "when_ref"); |
David Sedlák | e1a3030 | 2019-07-10 13:49:38 +0200 | [diff] [blame] | 561 | assert_int_equal(config, LYS_CONFIG_W); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 562 | CHECK_LYSP_TYPE_ENUM(&pos_enum, NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 25); |
| 563 | CHECK_LYSP_TYPE_ENUM(&val_enum, NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, -5); |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 564 | assert_int_equal(req_type.require_instance, 1); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 565 | assert_true(req_type.flags &= LYS_SET_REQINST); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 566 | assert_string_equal(range_type.range->arg.str, "5..10"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 567 | assert_true(range_type.flags & LYS_SET_RANGE); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 568 | assert_string_equal(error_message, "error-msg"); |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 569 | assert_string_equal(app_tag, "err-app-tag"); |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 570 | assert_string_equal(enum_type.enums->name, "yay"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 571 | CHECK_LYSP_RESTR(len_type.length, "baf", NULL, |
| 572 | NULL, NULL, 0, NULL); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 573 | assert_true(len_type.flags & LYS_SET_LENGTH); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 574 | assert_string_equal(patter_type.patterns->arg.str, "\x015pattern"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 575 | assert_true(patter_type.flags & LYS_SET_PATTERN); |
David Sedlák | 2ce1be6 | 2019-07-10 16:15:09 +0200 | [diff] [blame] | 576 | /* cleanup */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 577 | lysp_ext_instance_free(UTEST_LYCTX, exts); |
| 578 | lysp_when_free(UTEST_LYCTX, when_p); |
| 579 | lysp_ext_free(UTEST_LYCTX, ext_def); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 580 | lydict_remove(UTEST_LYCTX, *if_features); |
| 581 | lydict_remove(UTEST_LYCTX, error_message); |
| 582 | lydict_remove(UTEST_LYCTX, app_tag); |
| 583 | lydict_remove(UTEST_LYCTX, units); |
| 584 | lydict_remove(UTEST_LYCTX, patter_type.patterns->arg.str); |
| 585 | lydict_remove(UTEST_LYCTX, def.str); |
| 586 | lydict_remove(UTEST_LYCTX, range_type.range->arg.str); |
| 587 | lydict_remove(UTEST_LYCTX, len_type.length->arg.str); |
| 588 | lydict_remove(UTEST_LYCTX, enum_type.enums->name); |
| 589 | lydict_remove(UTEST_LYCTX, value); |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 590 | LY_ARRAY_FREE(if_features); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 591 | LY_ARRAY_FREE(exts); |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 592 | LY_ARRAY_FREE(ext_def); |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 593 | LY_ARRAY_FREE(patter_type.patterns); |
David Sedlák | fd5b9c3 | 2019-07-12 15:33:13 +0200 | [diff] [blame] | 594 | LY_ARRAY_FREE(enum_type.enums); |
David Sedlák | 32eee7b | 2019-07-09 12:38:44 +0200 | [diff] [blame] | 595 | free(when_p); |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 596 | free(range_type.range); |
David Sedlák | 438ae43 | 2019-07-11 15:36:54 +0200 | [diff] [blame] | 597 | free(len_type.length); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 598 | RESET_STATE; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 599 | |
| 600 | /* test unique subelem */ |
| 601 | const char *prefix_value; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 602 | struct yin_subelement subelems2[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE}, |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 603 | {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_UNIQUE}}; |
| 604 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 605 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 606 | "<prefix value=\"inv_mod\" />" |
| 607 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
| 608 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
| 609 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 610 | ly_in_new_memory(data, &UTEST_IN); |
| 611 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
| 612 | lyxml_ctx_next(YCTX->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 613 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 614 | ret = yin_parse_content(YCTX, subelems2, 2, LY_STMT_STATUS, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 615 | assert_int_equal(ret, LY_EVALID); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 616 | CHECK_LOG_CTX("Redefinition of \"text\" sub-element in \"status\" element.", "Line number 1."); |
| 617 | lydict_remove(UTEST_LYCTX, prefix_value); |
| 618 | lydict_remove(UTEST_LYCTX, value); |
| 619 | RESET_STATE; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 620 | |
| 621 | /* test first subelem */ |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 622 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 623 | "<prefix value=\"inv_mod\" />" |
| 624 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
| 625 | "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>" |
| 626 | ELEMENT_WRAPPER_END; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 627 | struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE}, |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 628 | {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}}; |
| 629 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 630 | ly_in_new_memory(data, &UTEST_IN); |
| 631 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
| 632 | lyxml_ctx_next(YCTX->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 633 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 634 | ret = yin_parse_content(YCTX, subelems3, 2, LY_STMT_STATUS, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 635 | assert_int_equal(ret, LY_EVALID); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 636 | CHECK_LOG_CTX("Sub-element \"text\" of \"status\" element must be defined as it's first sub-element.", "Line number 1."); |
| 637 | lydict_remove(UTEST_LYCTX, prefix_value); |
| 638 | RESET_STATE; |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 639 | |
| 640 | /* test mandatory subelem */ |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 641 | data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 642 | struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}}; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 643 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 644 | ly_in_new_memory(data, &UTEST_IN); |
| 645 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
| 646 | lyxml_ctx_next(YCTX->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 647 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 648 | ret = yin_parse_content(YCTX, subelems4, 1, LY_STMT_STATUS, NULL, &exts); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 649 | assert_int_equal(ret, LY_EVALID); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 650 | CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"status\" element.", "Line number 1."); |
David Sedlák | 555c720 | 2019-07-04 12:14:12 +0200 | [diff] [blame] | 651 | } |
| 652 | |
David Sedlák | 92147b0 | 2019-07-09 14:01:01 +0200 | [diff] [blame] | 653 | static void |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 654 | test_validate_value(void **state) |
| 655 | { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 656 | const char *data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END; |
| 657 | |
| 658 | /* create some XML context */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 659 | ly_in_new_memory(data, &UTEST_IN); |
| 660 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
| 661 | YCTX->xmlctx->status = LYXML_ELEM_CONTENT; |
| 662 | YCTX->xmlctx->dynamic = 0; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 663 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 664 | YCTX->xmlctx->value = "#invalid"; |
| 665 | YCTX->xmlctx->value_len = 8; |
| 666 | assert_int_equal(yin_validate_value(YCTX, Y_IDENTIF_ARG), LY_EVALID); |
| 667 | CHECK_LOG_CTX("Invalid identifier character '#' (0x0023).", "Line number 1."); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 668 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 669 | YCTX->xmlctx->value = ""; |
| 670 | YCTX->xmlctx->value_len = 0; |
| 671 | assert_int_equal(yin_validate_value(YCTX, Y_STR_ARG), LY_SUCCESS); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 672 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 673 | YCTX->xmlctx->value = "pre:b"; |
| 674 | YCTX->xmlctx->value_len = 5; |
| 675 | assert_int_equal(yin_validate_value(YCTX, Y_IDENTIF_ARG), LY_EVALID); |
| 676 | assert_int_equal(yin_validate_value(YCTX, Y_PREF_IDENTIF_ARG), LY_SUCCESS); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 677 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 678 | YCTX->xmlctx->value = "pre:pre:b"; |
| 679 | YCTX->xmlctx->value_len = 9; |
| 680 | assert_int_equal(yin_validate_value(YCTX, Y_PREF_IDENTIF_ARG), LY_EVALID); |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 681 | } |
| 682 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 683 | /* helper function to simplify unit test of each element using parse_content function */ |
| 684 | LY_ERR |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 685 | test_element_helper(void **state, const char *data, void *dest, const char **text, struct lysp_ext_instance **exts) |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 686 | { |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 687 | const char *name, *prefix; |
| 688 | size_t name_len, prefix_len; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 689 | LY_ERR ret = LY_SUCCESS; |
| 690 | struct yin_subelement subelems[71] = { |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 691 | {LY_STMT_ACTION, dest, 0}, |
| 692 | {LY_STMT_ANYDATA, dest, 0}, |
| 693 | {LY_STMT_ANYXML, dest, 0}, |
| 694 | {LY_STMT_ARGUMENT, dest, 0}, |
| 695 | {LY_STMT_AUGMENT, dest, 0}, |
| 696 | {LY_STMT_BASE, dest, 0}, |
| 697 | {LY_STMT_BELONGS_TO, dest, 0}, |
| 698 | {LY_STMT_BIT, dest, 0}, |
| 699 | {LY_STMT_CASE, dest, 0}, |
| 700 | {LY_STMT_CHOICE, dest, 0}, |
| 701 | {LY_STMT_CONFIG, dest, 0}, |
| 702 | {LY_STMT_CONTACT, dest, 0}, |
| 703 | {LY_STMT_CONTAINER, dest, 0}, |
| 704 | {LY_STMT_DEFAULT, dest, YIN_SUBELEM_UNIQUE}, |
| 705 | {LY_STMT_DESCRIPTION, dest, 0}, |
| 706 | {LY_STMT_DEVIATE, dest, 0}, |
| 707 | {LY_STMT_DEVIATION, dest, 0}, |
| 708 | {LY_STMT_ENUM, dest, 0}, |
| 709 | {LY_STMT_ERROR_APP_TAG, dest, YIN_SUBELEM_UNIQUE}, |
| 710 | {LY_STMT_ERROR_MESSAGE, dest, 0}, |
| 711 | {LY_STMT_EXTENSION, dest, 0}, |
| 712 | {LY_STMT_FEATURE, dest, 0}, |
| 713 | {LY_STMT_FRACTION_DIGITS, dest, 0}, |
| 714 | {LY_STMT_GROUPING, dest, 0}, |
| 715 | {LY_STMT_IDENTITY, dest, 0}, |
| 716 | {LY_STMT_IF_FEATURE, dest, 0}, |
| 717 | {LY_STMT_IMPORT, dest, 0}, |
| 718 | {LY_STMT_INCLUDE, dest, 0}, |
| 719 | {LY_STMT_INPUT, dest, 0}, |
| 720 | {LY_STMT_KEY, dest, YIN_SUBELEM_UNIQUE}, |
| 721 | {LY_STMT_LEAF, dest, 0}, |
| 722 | {LY_STMT_LEAF_LIST, dest, 0}, |
| 723 | {LY_STMT_LENGTH, dest, 0}, |
| 724 | {LY_STMT_LIST, dest, 0}, |
| 725 | {LY_STMT_MANDATORY, dest, 0}, |
| 726 | {LY_STMT_MAX_ELEMENTS, dest, 0}, |
| 727 | {LY_STMT_MIN_ELEMENTS, dest, 0}, |
| 728 | {LY_STMT_MODIFIER, dest, 0}, |
| 729 | {LY_STMT_MODULE, dest, 0}, |
| 730 | {LY_STMT_MUST, dest, 0}, |
| 731 | {LY_STMT_NAMESPACE, dest, YIN_SUBELEM_UNIQUE}, |
| 732 | {LY_STMT_NOTIFICATION, dest, 0}, |
| 733 | {LY_STMT_ORDERED_BY, dest, 0}, |
| 734 | {LY_STMT_ORGANIZATION, dest, 0}, |
| 735 | {LY_STMT_OUTPUT, dest, 0}, |
| 736 | {LY_STMT_PATH, dest, 0}, |
| 737 | {LY_STMT_PATTERN, dest, 0}, |
| 738 | {LY_STMT_POSITION, dest, 0}, |
| 739 | {LY_STMT_PREFIX, dest, YIN_SUBELEM_UNIQUE}, |
| 740 | {LY_STMT_PRESENCE, dest, YIN_SUBELEM_UNIQUE}, |
| 741 | {LY_STMT_RANGE, dest, 0}, |
| 742 | {LY_STMT_REFERENCE, dest, 0}, |
| 743 | {LY_STMT_REFINE, dest, 0}, |
| 744 | {LY_STMT_REQUIRE_INSTANCE, dest, 0}, |
| 745 | {LY_STMT_REVISION, dest, 0}, |
| 746 | {LY_STMT_REVISION_DATE, dest, 0}, |
| 747 | {LY_STMT_RPC, dest, 0}, |
| 748 | {LY_STMT_STATUS, dest, 0}, |
| 749 | {LY_STMT_SUBMODULE, dest, 0}, |
| 750 | {LY_STMT_TYPE, dest, 0}, |
| 751 | {LY_STMT_TYPEDEF, dest, 0}, |
| 752 | {LY_STMT_UNIQUE, dest, 0}, |
| 753 | {LY_STMT_UNITS, dest, YIN_SUBELEM_UNIQUE}, |
| 754 | {LY_STMT_USES, dest, 0}, |
| 755 | {LY_STMT_VALUE, dest, 0}, |
| 756 | {LY_STMT_WHEN, dest, 0}, |
| 757 | {LY_STMT_YANG_VERSION, dest, 0}, |
| 758 | {LY_STMT_YIN_ELEMENT, dest, 0}, |
| 759 | {LY_STMT_EXTENSION_INSTANCE, dest, 0}, |
| 760 | {LY_STMT_ARG_TEXT, dest, 0}, |
| 761 | {LY_STMT_ARG_VALUE, dest, 0} |
| 762 | }; |
| 763 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 764 | ly_in_new_memory(data, &UTEST_IN); |
| 765 | lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx); |
| 766 | prefix = YCTX->xmlctx->prefix; |
| 767 | prefix_len = YCTX->xmlctx->prefix_len; |
| 768 | name = YCTX->xmlctx->name; |
| 769 | name_len = YCTX->xmlctx->name_len; |
| 770 | lyxml_ctx_next(YCTX->xmlctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 771 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 772 | ret = yin_parse_content(YCTX, subelems, 71, yin_match_keyword(YCTX, name, name_len, prefix, prefix_len, LY_STMT_NONE), text, exts); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 773 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 774 | /* free parser and input */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 775 | lyxml_ctx_free(YCTX->xmlctx); |
| 776 | YCTX->xmlctx = NULL; |
| 777 | ly_in_free(UTEST_IN, 0); |
| 778 | UTEST_IN = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 779 | return ret; |
| 780 | } |
| 781 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 782 | #define EXT_SUBELEM "<myext:c-define name=\"MY_MTU\" xmlns:myext=\"urn:example:extensions\"/>" |
| 783 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 784 | static void |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 785 | test_enum_elem(void **state) |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 786 | { |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 787 | struct lysp_type type = {}; |
| 788 | const char *data; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 789 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 790 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 791 | "<enum name=\"enum-name\">\n" |
| 792 | " <if-feature name=\"feature\" />\n" |
| 793 | " <value value=\"55\" />\n" |
| 794 | " <status value=\"deprecated\" />\n" |
| 795 | " <description><text>desc...</text></description>\n" |
| 796 | " <reference><text>ref...</text></reference>\n" |
| 797 | " " EXT_SUBELEM "\n" |
| 798 | "</enum>" |
| 799 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 800 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 801 | uint16_t flags = LYS_STATUS_DEPRC | LYS_SET_VALUE; |
| 802 | |
| 803 | CHECK_LYSP_TYPE_ENUM(type.enums, "desc...", 1, flags, 1, "enum-name", "ref...", 55); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 804 | assert_string_equal(type.enums->iffeatures[0].str, "feature"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 805 | TEST_1_CHECK_LYSP_EXT_INSTANCE(type.enums->exts, LYEXT_SUBSTMT_SELF); |
| 806 | lysp_type_free(UTEST_LYCTX, &type); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 807 | memset(&type, 0, sizeof type); |
| 808 | |
| 809 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 810 | "<enum name=\"enum-name\"></enum>" |
| 811 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 812 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 813 | assert_string_equal(type.enums->name, "enum-name"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 814 | lysp_type_free(UTEST_LYCTX, &type); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 815 | memset(&type, 0, sizeof type); |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | static void |
| 819 | test_bit_elem(void **state) |
| 820 | { |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 821 | struct lysp_type type = {}; |
| 822 | const char *data; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 823 | |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 824 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 825 | "<bit name=\"bit-name\">\n" |
| 826 | " <if-feature name=\"feature\" />\n" |
| 827 | " <position value=\"55\" />\n" |
| 828 | " <status value=\"deprecated\" />\n" |
| 829 | " <description><text>desc...</text></description>\n" |
| 830 | " <reference><text>ref...</text></reference>\n" |
| 831 | EXT_SUBELEM |
| 832 | "</bit>" |
| 833 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 834 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 835 | uint16_t flags = LYS_STATUS_DEPRC | LYS_SET_VALUE; |
| 836 | |
| 837 | CHECK_LYSP_TYPE_ENUM(type.bits, "desc...", 1, flags, 1, "bit-name", "ref...", 55); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 838 | assert_string_equal(type.bits->iffeatures[0].str, "feature"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 839 | TEST_1_CHECK_LYSP_EXT_INSTANCE(type.bits->exts, LYEXT_SUBSTMT_SELF); |
| 840 | lysp_type_free(UTEST_LYCTX, &type); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 841 | memset(&type, 0, sizeof type); |
| 842 | |
| 843 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 844 | "<bit name=\"bit-name\"> </bit>" |
| 845 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 846 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 847 | CHECK_LYSP_TYPE_ENUM(type.bits, NULL, 0, 0, 0, "bit-name", NULL, 0); |
| 848 | lysp_type_free(UTEST_LYCTX, &type); |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 849 | memset(&type, 0, sizeof type); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | static void |
| 853 | test_meta_elem(void **state) |
| 854 | { |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 855 | char *value = NULL; |
| 856 | const char *data; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 857 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 858 | |
| 859 | /* organization element */ |
| 860 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 861 | "<organization><text>organization...</text>" EXT_SUBELEM EXT_SUBELEM "</organization>" |
| 862 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 863 | assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS); |
| 864 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_ORGANIZATION); |
| 865 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[1]), LYEXT_SUBSTMT_ORGANIZATION); |
| 866 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 867 | assert_string_equal(value, "organization..."); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 868 | lydict_remove(UTEST_LYCTX, value); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 869 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 870 | value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 871 | exts = NULL; |
| 872 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 873 | /* contact element */ |
| 874 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 875 | "<contact><text>contact...</text>" EXT_SUBELEM "</contact>" |
| 876 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 877 | assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS); |
| 878 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_CONTACT); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 879 | assert_string_equal(value, "contact..."); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 880 | lydict_remove(UTEST_LYCTX, value); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 881 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 882 | exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 883 | value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 884 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 885 | /* description element */ |
| 886 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 887 | "<description><text>description...</text>" EXT_SUBELEM "</description>" |
| 888 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 889 | assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS); |
| 890 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_DESCRIPTION); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 891 | assert_string_equal(value, "description..."); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 892 | lydict_remove(UTEST_LYCTX, value); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 893 | value = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 894 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 895 | exts = NULL; |
| 896 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 897 | /* reference element */ |
| 898 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 899 | "<reference><text>reference...</text>" EXT_SUBELEM "</reference>" |
| 900 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 901 | assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 902 | assert_string_equal(value, "reference..."); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 903 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_REFERENCE); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 904 | lydict_remove(UTEST_LYCTX, value); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 905 | value = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 906 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 907 | exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 908 | |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 909 | /* reference element */ |
| 910 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 911 | "<reference invalid=\"text\"><text>reference...</text>" "</reference>" |
| 912 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 913 | assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID); |
| 914 | CHECK_LOG_CTX("Unexpected attribute \"invalid\" of \"reference\" element.", "Line number 1."); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 915 | lydict_remove(UTEST_LYCTX, value); |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 916 | value = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 917 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 918 | exts = NULL; |
| 919 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 920 | /* missing text subelement */ |
| 921 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 922 | "<reference>reference...</reference>" |
| 923 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 924 | assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID); |
| 925 | CHECK_LOG_CTX("Missing mandatory sub-element \"text\" of \"reference\" element.", "Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 926 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 927 | /* reference element */ |
| 928 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 929 | "<reference>" EXT_SUBELEM "<text>reference...</text></reference>" |
| 930 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 931 | assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID); |
| 932 | CHECK_LOG_CTX("Sub-element \"text\" of \"reference\" element must be defined as it's first sub-element.", "Line number 1."); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 933 | lydict_remove(UTEST_LYCTX, value); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 934 | value = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 935 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 936 | exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | static void |
| 940 | test_import_elem(void **state) |
| 941 | { |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 942 | const char *data; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 943 | struct lysp_import *imports = NULL; |
| 944 | struct import_meta imp_meta = {"prefix", &imports}; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 945 | |
| 946 | /* max subelems */ |
| 947 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 948 | "<import module=\"a\">\n" |
| 949 | EXT_SUBELEM |
| 950 | " <prefix value=\"a_mod\"/>\n" |
| 951 | " <revision-date date=\"2015-01-01\"></revision-date>\n" |
| 952 | " <description><text>import description</text></description>\n" |
| 953 | " <reference><text>import reference</text></reference>\n" |
| 954 | "</import>" |
| 955 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 956 | assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_SUCCESS); |
| 957 | CHECK_LYSP_IMPORT(imports, "import description", 1, "a", |
| 958 | "a_mod", "import reference", "2015-01-01"); |
| 959 | TEST_1_CHECK_LYSP_EXT_INSTANCE(imports->exts, LYEXT_SUBSTMT_SELF); |
| 960 | FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 961 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 962 | |
| 963 | /* min subelems */ |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 964 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 965 | "<import module=\"a\">\n" |
| 966 | " <prefix value=\"a_mod\"/>\n" |
| 967 | "</import>" |
| 968 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 969 | assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_SUCCESS); |
| 970 | CHECK_LYSP_IMPORT(imports, NULL, 0, "a", |
| 971 | "a_mod", NULL, ""); |
| 972 | FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 973 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 974 | |
| 975 | /* invalid (missing prefix) */ |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 976 | data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 977 | assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID); |
| 978 | CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"import\" element.", "Line number 1."); |
| 979 | FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 980 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 981 | |
| 982 | /* invalid reused prefix */ |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 983 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 984 | "<import module=\"a\">\n" |
| 985 | " <prefix value=\"prefix\"/>\n" |
| 986 | "</import>" |
| 987 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 988 | assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID); |
| 989 | CHECK_LOG_CTX("Prefix \"prefix\" already used as module prefix.", "Line number 3."); |
| 990 | FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 991 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 992 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 993 | data = ELEMENT_WRAPPER_START |
| 994 | "<import module=\"a\">\n" |
| 995 | " <prefix value=\"a\"/>\n" |
| 996 | "</import>\n" |
| 997 | "<import module=\"a\">\n" |
| 998 | " <prefix value=\"a\"/>\n" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 999 | "</import>\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1000 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1001 | assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID); |
| 1002 | CHECK_LOG_CTX("Prefix \"a\" already used to import \"a\" module.", "Line number 6."); |
| 1003 | FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1004 | imports = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | static void |
| 1008 | test_status_elem(void **state) |
| 1009 | { |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1010 | const char *data; |
| 1011 | uint16_t flags = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1012 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1013 | |
| 1014 | /* test valid values */ |
| 1015 | data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1016 | assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1017 | assert_true(flags & LYS_STATUS_CURR); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1018 | |
| 1019 | data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1020 | assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1021 | assert_true(flags & LYS_STATUS_DEPRC); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1022 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1023 | data = ELEMENT_WRAPPER_START "<status value=\"obsolete\">"EXT_SUBELEM "</status>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1024 | assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1025 | assert_true(flags & LYS_STATUS_OBSLT); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1026 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_STATUS); |
| 1027 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1028 | exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1029 | |
| 1030 | /* test invalid value */ |
| 1031 | data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1032 | assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID); |
| 1033 | CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"status\" element. " |
| 1034 | "Valid values are \"current\", \"deprecated\" and \"obsolete\".", "Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | static void |
| 1038 | test_ext_elem(void **state) |
| 1039 | { |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1040 | const char *data; |
| 1041 | struct lysp_ext *ext = NULL; |
| 1042 | |
| 1043 | /* max subelems */ |
| 1044 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1045 | "<extension name=\"ext_name\">\n" |
| 1046 | " <argument name=\"arg\"></argument>\n" |
| 1047 | " <status value=\"current\"/>\n" |
| 1048 | " <description><text>ext_desc</text></description>\n" |
| 1049 | " <reference><text>ext_ref</text></reference>\n" |
| 1050 | EXT_SUBELEM |
| 1051 | "</extension>" |
| 1052 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1053 | assert_int_equal(test_element_helper(state, data, &ext, NULL, NULL), LY_SUCCESS); |
| 1054 | CHECK_LYSP_EXT(ext, "arg", 0, "ext_desc", 1, LYS_STATUS_CURR, "ext_name", "ext_ref"); |
| 1055 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(ext->exts[0]), LYEXT_SUBSTMT_SELF); |
| 1056 | lysp_ext_free(UTEST_LYCTX, ext); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1057 | LY_ARRAY_FREE(ext); |
| 1058 | ext = NULL; |
| 1059 | |
| 1060 | /* min subelems */ |
| 1061 | data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1062 | assert_int_equal(test_element_helper(state, data, &ext, NULL, NULL), LY_SUCCESS); |
| 1063 | CHECK_LYSP_EXT(ext, NULL, 0, NULL, 0, 0, "ext_name", NULL); |
| 1064 | lysp_ext_free(UTEST_LYCTX, ext); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1065 | LY_ARRAY_FREE(ext); |
| 1066 | ext = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | static void |
| 1070 | test_yin_element_elem(void **state) |
| 1071 | { |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1072 | const char *data; |
| 1073 | uint16_t flags = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1074 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1075 | |
| 1076 | data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1077 | assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1078 | assert_true(flags & LYS_YINELEM_TRUE); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1079 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1080 | data = ELEMENT_WRAPPER_START "<yin-element value=\"false\">" EXT_SUBELEM "</yin-element>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1081 | assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1082 | assert_true(flags & LYS_YINELEM_TRUE); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1083 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_YINELEM); |
| 1084 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1085 | |
| 1086 | data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1087 | assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1088 | assert_true(flags & LYS_YINELEM_TRUE); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1089 | CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"yin-element\" element. " |
| 1090 | "Valid values are \"true\" and \"false\".", "Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | static void |
| 1094 | test_yangversion_elem(void **state) |
| 1095 | { |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1096 | const char *data; |
| 1097 | uint8_t version = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1098 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1099 | |
| 1100 | /* valid values */ |
Radek Krejci | 96e48da | 2020-09-04 13:18:06 +0200 | [diff] [blame] | 1101 | data = ELEMENT_WRAPPER_START "<yang-version value=\"1\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1102 | assert_int_equal(test_element_helper(state, data, &version, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1103 | assert_true(version & LYS_VERSION_1_0); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1104 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1105 | data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\">" EXT_SUBELEM "</yang-version>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1106 | assert_int_equal(test_element_helper(state, data, &version, NULL, &exts), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1107 | assert_true(version & LYS_VERSION_1_1); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1108 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_VERSION); |
| 1109 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1110 | |
| 1111 | /* invalid value */ |
| 1112 | data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1113 | assert_int_equal(test_element_helper(state, data, &version, NULL, NULL), LY_EVALID); |
| 1114 | CHECK_LOG_CTX("Invalid value \"version\" of \"value\" attribute in \"yang-version\" element. " |
| 1115 | "Valid values are \"1\" and \"1.1\".", "Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | static void |
| 1119 | test_mandatory_elem(void **state) |
| 1120 | { |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1121 | const char *data; |
| 1122 | uint16_t man = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1123 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1124 | |
| 1125 | /* valid values */ |
| 1126 | data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1127 | assert_int_equal(test_element_helper(state, data, &man, NULL, NULL), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1128 | assert_int_equal(man, LYS_MAND_TRUE); |
| 1129 | man = 0; |
| 1130 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1131 | data = ELEMENT_WRAPPER_START "<mandatory value=\"false\">" EXT_SUBELEM "</mandatory>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1132 | assert_int_equal(test_element_helper(state, data, &man, NULL, &exts), LY_SUCCESS); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1133 | assert_int_equal(man, LYS_MAND_FALSE); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1134 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_MANDATORY); |
| 1135 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1136 | |
| 1137 | data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1138 | assert_int_equal(test_element_helper(state, data, &man, NULL, NULL), LY_EVALID); |
| 1139 | CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"mandatory\" element. " |
| 1140 | "Valid values are \"true\" and \"false\".", "Line number 1."); |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1141 | } |
| 1142 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1143 | static void |
| 1144 | test_argument_elem(void **state) |
| 1145 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1146 | const char *data; |
| 1147 | uint16_t flags = 0; |
| 1148 | const char *arg; |
| 1149 | struct yin_argument_meta arg_meta = {&flags, &arg}; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1150 | struct lysp_ext_instance *exts = NULL; |
| 1151 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1152 | /* max subelems */ |
| 1153 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1154 | "<argument name=\"arg-name\">\n" |
| 1155 | " <yin-element value=\"true\" />\n" |
| 1156 | EXT_SUBELEM |
| 1157 | "</argument>" |
| 1158 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1159 | assert_int_equal(test_element_helper(state, data, &arg_meta, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1160 | assert_string_equal(arg, "arg-name"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1161 | assert_true(flags & LYS_YINELEM_TRUE); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1162 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_ARGUMENT); |
| 1163 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1164 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1165 | flags = 0; |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1166 | lydict_remove(UTEST_LYCTX, arg); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1167 | arg = NULL; |
| 1168 | |
| 1169 | /* min subelems */ |
| 1170 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1171 | "<argument name=\"arg\">" |
| 1172 | "</argument>" |
| 1173 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1174 | assert_int_equal(test_element_helper(state, data, &arg_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1175 | assert_string_equal(arg, "arg"); |
| 1176 | assert_true(flags == 0); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1177 | lydict_remove(UTEST_LYCTX, arg); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | static void |
| 1181 | test_base_elem(void **state) |
| 1182 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1183 | const char *data; |
| 1184 | const char **bases = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1185 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1186 | struct lysp_type type = {}; |
| 1187 | |
| 1188 | /* as identity subelement */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1189 | data = "<identity xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 1190 | " <base name=\"base-name\">\n" |
| 1191 | EXT_SUBELEM |
| 1192 | " </base>\n" |
| 1193 | "</identity>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1194 | assert_int_equal(test_element_helper(state, data, &bases, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1195 | assert_string_equal(*bases, "base-name"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1196 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_BASE); |
| 1197 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1198 | exts = NULL; |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1199 | lydict_remove(UTEST_LYCTX, *bases); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1200 | LY_ARRAY_FREE(bases); |
| 1201 | |
| 1202 | /* as type subelement */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1203 | data = "<type xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 1204 | " <base name=\"base-name\">\n" |
| 1205 | EXT_SUBELEM |
| 1206 | " </base>\n" |
| 1207 | "</type>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1208 | assert_int_equal(test_element_helper(state, data, &type, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1209 | assert_string_equal(*type.bases, "base-name"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1210 | assert_true(type.flags & LYS_SET_BASE); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1211 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_BASE); |
| 1212 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1213 | exts = NULL; |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1214 | lydict_remove(UTEST_LYCTX, *type.bases); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1215 | LY_ARRAY_FREE(type.bases); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | static void |
| 1219 | test_belongsto_elem(void **state) |
| 1220 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1221 | const char *data; |
| 1222 | struct lysp_submodule submod; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1223 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1224 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1225 | lydict_insert(UTEST_LYCTX, "module-name", 0, &YCTX->parsed_mod->mod->name); |
| 1226 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1227 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1228 | "<belongs-to module=\"module-name\"><prefix value=\"pref\"/>"EXT_SUBELEM "</belongs-to>" |
| 1229 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1230 | assert_int_equal(test_element_helper(state, data, &submod, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1231 | assert_string_equal(submod.prefix, "pref"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1232 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_BELONGSTO); |
| 1233 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1234 | exts = NULL; |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1235 | lydict_remove(UTEST_LYCTX, submod.prefix); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1236 | |
| 1237 | data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1238 | assert_int_equal(test_element_helper(state, data, &submod, NULL, NULL), LY_EVALID); |
| 1239 | CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | static void |
| 1243 | test_config_elem(void **state) |
| 1244 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1245 | const char *data; |
| 1246 | uint16_t flags = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1247 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1248 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1249 | data = ELEMENT_WRAPPER_START "<config value=\"true\">" EXT_SUBELEM "</config>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1250 | assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1251 | assert_true(flags & LYS_CONFIG_W); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1252 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_CONFIG); |
| 1253 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1254 | exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1255 | flags = 0; |
| 1256 | |
| 1257 | data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1258 | assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1259 | assert_true(flags & LYS_CONFIG_R); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1260 | flags = 0; |
| 1261 | |
| 1262 | data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1263 | assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID); |
| 1264 | CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"config\" element. " |
| 1265 | "Valid values are \"true\" and \"false\".", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | static void |
| 1269 | test_default_elem(void **state) |
| 1270 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1271 | const char *data; |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1272 | struct lysp_qname val = {0}; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1273 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1274 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1275 | data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\">"EXT_SUBELEM "</default>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1276 | assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1277 | assert_string_equal(val.str, "defaul-value"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1278 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_DEFAULT); |
| 1279 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1280 | exts = NULL; |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1281 | lydict_remove(UTEST_LYCTX, val.str); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1282 | val.str = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1283 | |
| 1284 | data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1285 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID); |
| 1286 | CHECK_LOG_CTX("Missing mandatory attribute value of default element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | static void |
| 1290 | test_err_app_tag_elem(void **state) |
| 1291 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1292 | const char *data; |
| 1293 | const char *val = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1294 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1295 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1296 | data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\">"EXT_SUBELEM "</error-app-tag>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1297 | assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1298 | assert_string_equal(val, "val"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1299 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_ERRTAG); |
| 1300 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1301 | exts = NULL; |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1302 | lydict_remove(UTEST_LYCTX, val); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1303 | val = NULL; |
| 1304 | |
| 1305 | data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1306 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID); |
| 1307 | CHECK_LOG_CTX("Missing mandatory attribute value of error-app-tag element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | static void |
| 1311 | test_err_msg_elem(void **state) |
| 1312 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1313 | const char *data; |
| 1314 | const char *val = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1315 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1316 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1317 | data = ELEMENT_WRAPPER_START "<error-message><value>val</value>"EXT_SUBELEM "</error-message>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1318 | assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1319 | assert_string_equal(val, "val"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1320 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_ERRMSG); |
| 1321 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1322 | exts = NULL; |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1323 | lydict_remove(UTEST_LYCTX, val); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1324 | |
| 1325 | data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1326 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID); |
| 1327 | CHECK_LOG_CTX("Missing mandatory sub-element \"value\" of \"error-message\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1328 | |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 1329 | data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1330 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID); |
| 1331 | CHECK_LOG_CTX("Unexpected attribute \"invalid\" of \"error-message\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | static void |
| 1335 | test_fracdigits_elem(void **state) |
| 1336 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1337 | const char *data; |
| 1338 | struct lysp_type type = {}; |
| 1339 | |
| 1340 | /* valid value */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1341 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\">"EXT_SUBELEM "</fraction-digits>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1342 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 1343 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LYEXT_SUBSTMT_FRACDIGITS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1344 | assert_int_equal(type.fraction_digits, 10); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1345 | assert_true(type.flags & LYS_SET_FRDIGITS); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1346 | FREE_ARRAY(UTEST_LYCTX, type.exts, lysp_ext_instance_free); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1347 | |
| 1348 | /* invalid values */ |
| 1349 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1350 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID); |
| 1351 | CHECK_LOG_CTX("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1352 | |
| 1353 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1354 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID); |
| 1355 | CHECK_LOG_CTX("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1356 | |
| 1357 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1358 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID); |
| 1359 | CHECK_LOG_CTX("Invalid value \"1p\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1360 | |
| 1361 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1362 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID); |
| 1363 | CHECK_LOG_CTX("Invalid value \"19\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1364 | |
| 1365 | data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1366 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID); |
| 1367 | CHECK_LOG_CTX("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | static void |
| 1371 | test_iffeature_elem(void **state) |
| 1372 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1373 | const char *data; |
| 1374 | const char **iffeatures = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1375 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1376 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1377 | data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\">"EXT_SUBELEM "</if-feature>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1378 | assert_int_equal(test_element_helper(state, data, &iffeatures, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1379 | assert_string_equal(*iffeatures, "local-storage"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1380 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_IFFEATURE); |
| 1381 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1382 | exts = NULL; |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1383 | lydict_remove(UTEST_LYCTX, *iffeatures); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1384 | LY_ARRAY_FREE(iffeatures); |
| 1385 | iffeatures = NULL; |
| 1386 | |
| 1387 | data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1388 | assert_int_equal(test_element_helper(state, data, &iffeatures, NULL, NULL), LY_EVALID); |
| 1389 | CHECK_LOG_CTX("Missing mandatory attribute name of if-feature element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1390 | LY_ARRAY_FREE(iffeatures); |
| 1391 | iffeatures = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | static void |
| 1395 | test_length_elem(void **state) |
| 1396 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1397 | const char *data; |
| 1398 | struct lysp_type type = {}; |
| 1399 | |
| 1400 | /* max subelems */ |
| 1401 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1402 | "<length value=\"length-str\">\n" |
| 1403 | " <error-message><value>err-msg</value></error-message>\n" |
| 1404 | " <error-app-tag value=\"err-app-tag\"/>\n" |
| 1405 | " <description><text>desc</text></description>\n" |
| 1406 | " <reference><text>ref</text></reference>\n" |
| 1407 | EXT_SUBELEM |
| 1408 | "</length>" |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1409 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1410 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 1411 | CHECK_LYSP_RESTR(type.length, "length-str", "desc", |
| 1412 | "err-app-tag", "err-msg", 1, "ref"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1413 | assert_true(type.flags & LYS_SET_LENGTH); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1414 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.length->exts[0]), LYEXT_SUBSTMT_SELF); |
| 1415 | lysp_type_free(UTEST_LYCTX, &type); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1416 | memset(&type, 0, sizeof(type)); |
| 1417 | |
| 1418 | /* min subelems */ |
| 1419 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1420 | "<length value=\"length-str\">" |
| 1421 | "</length>" |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1422 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1423 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 1424 | CHECK_LYSP_RESTR(type.length, "length-str", NULL, |
| 1425 | NULL, NULL, 0, NULL); |
| 1426 | lysp_type_free(UTEST_LYCTX, &type); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1427 | assert_true(type.flags & LYS_SET_LENGTH); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1428 | memset(&type, 0, sizeof(type)); |
| 1429 | |
| 1430 | data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1431 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID); |
| 1432 | CHECK_LOG_CTX("Missing mandatory attribute value of length element.", "Line number 1."); |
| 1433 | lysp_type_free(UTEST_LYCTX, &type); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1434 | memset(&type, 0, sizeof(type)); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | static void |
| 1438 | test_modifier_elem(void **state) |
| 1439 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1440 | const char *data; |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 1441 | const char *pat; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1442 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1443 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1444 | assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "\006pattern", 8, &pat)); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1445 | data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\">" EXT_SUBELEM "</modifier>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1446 | assert_int_equal(test_element_helper(state, data, &pat, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1447 | assert_string_equal(pat, "\x015pattern"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1448 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_MODIFIER); |
| 1449 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1450 | exts = NULL; |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1451 | lydict_remove(UTEST_LYCTX, pat); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1452 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1453 | assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "\006pattern", 8, &pat)); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1454 | data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1455 | assert_int_equal(test_element_helper(state, data, &pat, NULL, NULL), LY_EVALID); |
| 1456 | CHECK_LOG_CTX("Invalid value \"invert\" of \"value\" attribute in \"modifier\" element. " |
| 1457 | "Only valid value is \"invert-match\".", "Line number 1."); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1458 | lydict_remove(UTEST_LYCTX, pat); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | static void |
| 1462 | test_namespace_elem(void **state) |
| 1463 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1464 | const char *data; |
| 1465 | const char *ns; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1466 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1467 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1468 | data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\">" EXT_SUBELEM "</namespace>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1469 | assert_int_equal(test_element_helper(state, data, &ns, NULL, &exts), LY_SUCCESS); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1470 | assert_string_equal(ns, "ns"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1471 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_NAMESPACE); |
| 1472 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1473 | exts = NULL; |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1474 | lydict_remove(UTEST_LYCTX, ns); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1475 | |
| 1476 | data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1477 | assert_int_equal(test_element_helper(state, data, &ns, NULL, NULL), LY_EVALID); |
| 1478 | CHECK_LOG_CTX("Missing mandatory attribute uri of namespace element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | static void |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1482 | test_pattern_elem(void **state) |
| 1483 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1484 | const char *data; |
| 1485 | struct lysp_type type = {}; |
| 1486 | |
| 1487 | /* max subelems */ |
| 1488 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1489 | "<pattern value=\"super_pattern\">\n" |
| 1490 | " <modifier value=\"invert-match\"/>\n" |
| 1491 | " <error-message><value>err-msg-value</value></error-message>\n" |
| 1492 | " <error-app-tag value=\"err-app-tag-value\"/>\n" |
| 1493 | " <description><text>"pattern-desc"</text></description>\n" |
| 1494 | " <reference><text>pattern-ref</text></reference>\n" |
| 1495 | EXT_SUBELEM |
| 1496 | "</pattern>" |
| 1497 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1498 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1499 | assert_true(type.flags & LYS_SET_PATTERN); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1500 | CHECK_LYSP_RESTR(type.patterns, "\x015super_pattern", "\"pattern-desc\"", |
| 1501 | "err-app-tag-value", "err-msg-value", 1, "pattern-ref"); |
| 1502 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.patterns->exts[0]), LYEXT_SUBSTMT_SELF); |
| 1503 | lysp_type_free(UTEST_LYCTX, &type); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1504 | memset(&type, 0, sizeof(type)); |
| 1505 | |
| 1506 | /* min subelems */ |
| 1507 | data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1508 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 1509 | CHECK_LYSP_RESTR(type.patterns, "\x006pattern", NULL, NULL, NULL, 0, NULL); |
| 1510 | lysp_type_free(UTEST_LYCTX, &type); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1511 | memset(&type, 0, sizeof(type)); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | static void |
| 1515 | test_value_position_elem(void **state) |
| 1516 | { |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1517 | const char *data; |
| 1518 | struct lysp_type_enum en = {}; |
| 1519 | |
| 1520 | /* valid values */ |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1521 | data = ELEMENT_WRAPPER_START "<value value=\"55\">" EXT_SUBELEM "</value>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1522 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS); |
| 1523 | CHECK_LYSP_TYPE_ENUM(&(en), NULL, 1, LYS_SET_VALUE, 0, NULL, NULL, 55); |
| 1524 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(en.exts[0]), LYEXT_SUBSTMT_VALUE); |
| 1525 | FREE_ARRAY(UTEST_LYCTX, en.exts, lysp_ext_instance_free); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1526 | memset(&en, 0, sizeof(en)); |
| 1527 | |
| 1528 | data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1529 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS); |
| 1530 | CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, -55); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1531 | memset(&en, 0, sizeof(en)); |
| 1532 | |
| 1533 | data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1534 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS); |
| 1535 | CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1536 | memset(&en, 0, sizeof(en)); |
| 1537 | |
| 1538 | data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1539 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS); |
| 1540 | CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1541 | memset(&en, 0, sizeof(en)); |
| 1542 | |
| 1543 | /* valid positions */ |
David Sedlák | 8d552d6 | 2019-08-06 15:29:05 +0200 | [diff] [blame] | 1544 | data = ELEMENT_WRAPPER_START "<position value=\"55\">" EXT_SUBELEM "</position>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1545 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS); |
| 1546 | CHECK_LYSP_TYPE_ENUM(&(en), NULL, 1, LYS_SET_VALUE, 0, NULL, NULL, 55); |
| 1547 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(en.exts[0]), LYEXT_SUBSTMT_POSITION); |
| 1548 | FREE_ARRAY(UTEST_LYCTX, en.exts, lysp_ext_instance_free); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1549 | memset(&en, 0, sizeof(en)); |
| 1550 | |
| 1551 | data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1552 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS); |
| 1553 | CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1554 | memset(&en, 0, sizeof(en)); |
| 1555 | |
| 1556 | /* invalid values */ |
| 1557 | data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1558 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID); |
| 1559 | CHECK_LOG_CTX("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1560 | |
| 1561 | data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1562 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID); |
| 1563 | CHECK_LOG_CTX("Invalid value \"1k\" of \"value\" attribute in \"value\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1564 | |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1565 | data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1566 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID); |
| 1567 | CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"value\" element.", "Line number 1."); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1568 | |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1569 | /*invalid positions */ |
| 1570 | data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1571 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID); |
| 1572 | CHECK_LOG_CTX("Invalid value \"-5\" of \"value\" attribute in \"position\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1573 | |
| 1574 | data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1575 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID); |
| 1576 | CHECK_LOG_CTX("Invalid value \"-0\" of \"value\" attribute in \"position\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1577 | |
| 1578 | data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1579 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID); |
| 1580 | CHECK_LOG_CTX("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element.", "Line number 1."); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1581 | |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1582 | data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1583 | assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID); |
| 1584 | CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"position\" element.", "Line number 1."); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | static void |
| 1588 | test_prefix_elem(void **state) |
| 1589 | { |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1590 | const char *data; |
| 1591 | const char *value = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1592 | struct lysp_ext_instance *exts = NULL; |
| 1593 | |
| 1594 | data = ELEMENT_WRAPPER_START "<prefix value=\"pref\">" EXT_SUBELEM "</prefix>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1595 | assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1596 | assert_string_equal(value, "pref"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1597 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_PREFIX); |
| 1598 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1599 | exts = NULL; |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1600 | lydict_remove(UTEST_LYCTX, value); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1601 | |
| 1602 | data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1603 | assert_int_equal(test_element_helper(state, data, &value, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1604 | assert_string_equal(value, "pref"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1605 | lydict_remove(UTEST_LYCTX, value); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | static void |
| 1609 | test_range_elem(void **state) |
| 1610 | { |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1611 | const char *data; |
| 1612 | struct lysp_type type = {}; |
| 1613 | |
| 1614 | /* max subelems */ |
| 1615 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1616 | "<range value=\"range-str\">\n" |
| 1617 | " <error-message><value>err-msg</value></error-message>\n" |
| 1618 | " <error-app-tag value=\"err-app-tag\" />\n" |
| 1619 | " <description><text>desc</text></description>\n" |
| 1620 | " <reference><text>ref</text></reference>\n" |
| 1621 | EXT_SUBELEM |
| 1622 | "</range>" |
| 1623 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1624 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 1625 | CHECK_LYSP_RESTR(type.range, "range-str", "desc", |
| 1626 | "err-app-tag", "err-msg", 1, "ref"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1627 | assert_true(type.flags & LYS_SET_RANGE); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1628 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.range->exts[0]), LYEXT_SUBSTMT_SELF); |
| 1629 | lysp_type_free(UTEST_LYCTX, &type); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1630 | memset(&type, 0, sizeof(type)); |
| 1631 | |
| 1632 | /* min subelems */ |
| 1633 | data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1634 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 1635 | CHECK_LYSP_RESTR(type.range, "range-str", NULL, |
| 1636 | NULL, NULL, 0, NULL); |
| 1637 | lysp_type_free(UTEST_LYCTX, &type); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1638 | memset(&type, 0, sizeof(type)); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | static void |
| 1642 | test_reqinstance_elem(void **state) |
| 1643 | { |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1644 | const char *data; |
| 1645 | struct lysp_type type = {}; |
| 1646 | |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1647 | data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1648 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1649 | assert_int_equal(type.require_instance, 1); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1650 | assert_true(type.flags & LYS_SET_REQINST); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1651 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LYEXT_SUBSTMT_REQINSTANCE); |
| 1652 | lysp_type_free(UTEST_LYCTX, &type); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1653 | memset(&type, 0, sizeof(type)); |
| 1654 | |
| 1655 | data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1656 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1657 | assert_int_equal(type.require_instance, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1658 | assert_true(type.flags & LYS_SET_REQINST); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1659 | memset(&type, 0, sizeof(type)); |
| 1660 | |
| 1661 | data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1662 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1663 | memset(&type, 0, sizeof(type)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1664 | CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"require-instance\" element. " |
| 1665 | "Valid values are \"true\" and \"false\".", "Line number 1."); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | static void |
| 1669 | test_revision_date_elem(void **state) |
| 1670 | { |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1671 | const char *data; |
| 1672 | char rev[LY_REV_SIZE]; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1673 | struct lysp_ext_instance *exts = NULL; |
| 1674 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1675 | data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\">"EXT_SUBELEM "</revision-date>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1676 | assert_int_equal(test_element_helper(state, data, rev, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1677 | assert_string_equal(rev, "2000-01-01"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1678 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_REVISIONDATE); |
| 1679 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1680 | |
| 1681 | data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1682 | assert_int_equal(test_element_helper(state, data, rev, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1683 | assert_string_equal(rev, "2000-01-01"); |
| 1684 | |
| 1685 | data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1686 | assert_int_equal(test_element_helper(state, data, rev, NULL, NULL), LY_EVALID); |
| 1687 | CHECK_LOG_CTX("Invalid value \"2000-50-05\" of \"revision-date\".", "Line number 1."); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | static void |
| 1691 | test_unique_elem(void **state) |
| 1692 | { |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1693 | const char *data; |
| 1694 | const char **values = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1695 | struct lysp_ext_instance *exts = NULL; |
| 1696 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1697 | data = ELEMENT_WRAPPER_START "<unique tag=\"tag\">"EXT_SUBELEM "</unique>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1698 | assert_int_equal(test_element_helper(state, data, &values, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1699 | assert_string_equal(*values, "tag"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1700 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_UNIQUE); |
| 1701 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1702 | lydict_remove(UTEST_LYCTX, *values); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1703 | LY_ARRAY_FREE(values); |
| 1704 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1705 | |
| 1706 | data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1707 | assert_int_equal(test_element_helper(state, data, &values, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1708 | assert_string_equal(*values, "tag"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1709 | lydict_remove(UTEST_LYCTX, *values); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1710 | LY_ARRAY_FREE(values); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1711 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | static void |
| 1715 | test_units_elem(void **state) |
| 1716 | { |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1717 | const char *data; |
| 1718 | const char *values = NULL; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1719 | struct lysp_ext_instance *exts = NULL; |
| 1720 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1721 | data = ELEMENT_WRAPPER_START "<units name=\"name\">"EXT_SUBELEM "</units>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1722 | assert_int_equal(test_element_helper(state, data, &values, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1723 | assert_string_equal(values, "name"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1724 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_UNITS); |
| 1725 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1726 | lydict_remove(UTEST_LYCTX, values); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1727 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1728 | |
| 1729 | data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1730 | assert_int_equal(test_element_helper(state, data, &values, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1731 | assert_string_equal(values, "name"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1732 | lydict_remove(UTEST_LYCTX, values); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1733 | values = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | static void |
| 1737 | test_when_elem(void **state) |
| 1738 | { |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1739 | const char *data; |
| 1740 | struct lysp_when *when = NULL; |
| 1741 | |
| 1742 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1743 | "<when condition=\"cond\">\n" |
| 1744 | " <description><text>desc</text></description>\n" |
| 1745 | " <reference><text>ref</text></reference>\n" |
| 1746 | EXT_SUBELEM |
| 1747 | "</when>" |
| 1748 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1749 | assert_int_equal(test_element_helper(state, data, &when, NULL, NULL), LY_SUCCESS); |
| 1750 | CHECK_LYSP_WHEN(when, "cond", "desc", 1, "ref"); |
| 1751 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(when->exts[0]), LYEXT_SUBSTMT_SELF); |
| 1752 | lysp_when_free(UTEST_LYCTX, when); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1753 | free(when); |
| 1754 | when = NULL; |
| 1755 | |
| 1756 | data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1757 | assert_int_equal(test_element_helper(state, data, &when, NULL, NULL), LY_SUCCESS); |
| 1758 | CHECK_LYSP_WHEN(when, "cond", NULL, 0, NULL); |
| 1759 | lysp_when_free(UTEST_LYCTX, when); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1760 | free(when); |
| 1761 | when = NULL; |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | static void |
| 1765 | test_yin_text_value_elem(void **state) |
| 1766 | { |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1767 | const char *data; |
| 1768 | const char *val; |
| 1769 | |
| 1770 | data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1771 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1772 | assert_string_equal(val, "text"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1773 | lydict_remove(UTEST_LYCTX, val); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1774 | |
| 1775 | data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1776 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1777 | assert_string_equal(val, "text"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1778 | lydict_remove(UTEST_LYCTX, val); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1779 | |
| 1780 | data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1781 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | 69f0161 | 2019-07-17 11:41:08 +0200 | [diff] [blame] | 1782 | assert_string_equal("", val); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 1783 | lydict_remove(UTEST_LYCTX, val); |
David Sedlák | 8e7bda8 | 2019-07-16 17:57:50 +0200 | [diff] [blame] | 1784 | } |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 1785 | |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1786 | static void |
| 1787 | test_type_elem(void **state) |
| 1788 | { |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1789 | const char *data; |
| 1790 | struct lysp_type type = {}; |
| 1791 | |
| 1792 | /* max subelems */ |
| 1793 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1794 | "<type name=\"type-name\">\n" |
| 1795 | " <base name=\"base-name\"/>\n" |
| 1796 | " <bit name=\"bit\"/>\n" |
| 1797 | " <enum name=\"enum\"/>\n" |
| 1798 | " <fraction-digits value=\"2\"/>\n" |
| 1799 | " <length value=\"length\"/>\n" |
| 1800 | " <path value=\"/path\"/>\n" |
| 1801 | " <pattern value=\"pattern\"/>\n" |
| 1802 | " <range value=\"range\" />\n" |
| 1803 | " <require-instance value=\"true\"/>\n" |
| 1804 | " <type name=\"sub-type-name\"/>\n" |
| 1805 | EXT_SUBELEM |
| 1806 | "</type>" |
| 1807 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1808 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1809 | assert_string_equal(type.name, "type-name"); |
| 1810 | assert_string_equal(*type.bases, "base-name"); |
| 1811 | assert_string_equal(type.bits->name, "bit"); |
| 1812 | assert_string_equal(type.enums->name, "enum"); |
| 1813 | assert_int_equal(type.fraction_digits, 2); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1814 | CHECK_LYSP_RESTR(type.length, "length", NULL, |
| 1815 | NULL, NULL, 0, NULL); |
Michal Vasko | cb8c6d4 | 2020-10-16 11:58:30 +0200 | [diff] [blame] | 1816 | assert_string_equal(type.path->expr, "/path"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1817 | CHECK_LYSP_RESTR(type.patterns, "\006pattern", NULL, |
| 1818 | NULL, NULL, 0, NULL); |
| 1819 | CHECK_LYSP_RESTR(type.range, "range", NULL, |
| 1820 | NULL, NULL, 0, NULL); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1821 | assert_int_equal(type.require_instance, 1); |
| 1822 | assert_string_equal(type.types->name, "sub-type-name"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1823 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]), LYEXT_SUBSTMT_SELF); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1824 | assert_true(type.flags & LYS_SET_BASE); |
| 1825 | assert_true(type.flags & LYS_SET_BIT); |
| 1826 | assert_true(type.flags & LYS_SET_ENUM); |
| 1827 | assert_true(type.flags & LYS_SET_FRDIGITS); |
| 1828 | assert_true(type.flags & LYS_SET_LENGTH); |
| 1829 | assert_true(type.flags & LYS_SET_PATH); |
| 1830 | assert_true(type.flags & LYS_SET_PATTERN); |
| 1831 | assert_true(type.flags & LYS_SET_RANGE); |
| 1832 | assert_true(type.flags & LYS_SET_REQINST); |
| 1833 | assert_true(type.flags & LYS_SET_TYPE); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1834 | lysp_type_free(UTEST_LYCTX, &type); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1835 | memset(&type, 0, sizeof(type)); |
| 1836 | |
| 1837 | /* min subelems */ |
| 1838 | data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1839 | assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS); |
| 1840 | lysp_type_free(UTEST_LYCTX, &type); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1841 | memset(&type, 0, sizeof(type)); |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1842 | } |
| 1843 | |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1844 | static void |
| 1845 | test_max_elems_elem(void **state) |
| 1846 | { |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1847 | const char *data; |
| 1848 | struct lysp_node_list list = {}; |
| 1849 | struct lysp_node_leaflist llist = {}; |
| 1850 | struct lysp_refine refine = {}; |
| 1851 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1852 | data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"unbounded\">"EXT_SUBELEM "</max-elements> </refine>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1853 | assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1854 | assert_int_equal(refine.max, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1855 | assert_true(refine.flags & LYS_SET_MAX); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1856 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refine.exts[0]), LYEXT_SUBSTMT_MAX); |
| 1857 | FREE_ARRAY(UTEST_LYCTX, refine.exts, lysp_ext_instance_free); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1858 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1859 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"5\">"EXT_SUBELEM "</max-elements> </list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1860 | assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_SUCCESS); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1861 | assert_int_equal(list.max, 5); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1862 | CHECK_LYSP_NODE(&list, NULL, 1, LYS_SET_MAX, 0, NULL, 0, LYS_UNKNOWN, NULL, NULL, 0); |
| 1863 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(list.exts[0]), LYEXT_SUBSTMT_MAX); |
| 1864 | FREE_ARRAY(UTEST_LYCTX, list.exts, lysp_ext_instance_free); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1865 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1866 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"85\">"EXT_SUBELEM "</max-elements> </leaf-list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1867 | assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_SUCCESS); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1868 | assert_int_equal(llist.max, 85); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1869 | CHECK_LYSP_NODE(&llist, NULL, 1, LYS_SET_MAX, 0, NULL, 0, LYS_UNKNOWN, NULL, NULL, 0); |
| 1870 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(llist.exts[0]), LYEXT_SUBSTMT_MAX); |
| 1871 | FREE_ARRAY(UTEST_LYCTX, llist.exts, lysp_ext_instance_free); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1872 | |
| 1873 | data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1874 | assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1875 | assert_int_equal(refine.max, 10); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1876 | assert_true(refine.flags & LYS_SET_MAX); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1877 | |
| 1878 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1879 | assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID); |
| 1880 | CHECK_LOG_CTX("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element.", "Line number 1."); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1881 | |
| 1882 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1883 | assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID); |
| 1884 | CHECK_LOG_CTX("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element.", "Line number 1."); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1885 | |
| 1886 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1887 | assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID); |
| 1888 | CHECK_LOG_CTX("Invalid value \"k\" of \"value\" attribute in \"max-elements\" element.", "Line number 1."); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1889 | |
| 1890 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1891 | assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID); |
| 1892 | CHECK_LOG_CTX("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element.", "Line number 1."); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1893 | } |
| 1894 | |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1895 | static void |
| 1896 | test_min_elems_elem(void **state) |
| 1897 | { |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1898 | const char *data; |
| 1899 | struct lysp_node_list list = {}; |
| 1900 | struct lysp_node_leaflist llist = {}; |
| 1901 | struct lysp_refine refine = {}; |
| 1902 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1903 | data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"0\">"EXT_SUBELEM "</min-elements> </refine>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1904 | assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1905 | assert_int_equal(refine.min, 0); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1906 | assert_true(refine.flags & LYS_SET_MIN); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1907 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refine.exts[0]), LYEXT_SUBSTMT_MIN); |
| 1908 | FREE_ARRAY(UTEST_LYCTX, refine.exts, lysp_ext_instance_free); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1909 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1910 | data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"41\">"EXT_SUBELEM "</min-elements> </list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1911 | assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_SUCCESS); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1912 | assert_int_equal(list.min, 41); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1913 | assert_true(list.flags & LYS_SET_MIN); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1914 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(list.exts[0]), LYEXT_SUBSTMT_MIN); |
| 1915 | FREE_ARRAY(UTEST_LYCTX, list.exts, lysp_ext_instance_free); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1916 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1917 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"50\">"EXT_SUBELEM "</min-elements> </leaf-list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1918 | assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_SUCCESS); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1919 | assert_int_equal(llist.min, 50); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1920 | assert_true(llist.flags & LYS_SET_MIN); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1921 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(llist.exts[0]), LYEXT_SUBSTMT_MIN); |
| 1922 | FREE_ARRAY(UTEST_LYCTX, llist.exts, lysp_ext_instance_free); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1923 | |
| 1924 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1925 | assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID); |
| 1926 | CHECK_LOG_CTX("Value \"-5\" of \"value\" attribute in \"min-elements\" element is out of bounds.", "Line number 1."); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1927 | |
| 1928 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1929 | assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID); |
| 1930 | CHECK_LOG_CTX("Value \"99999999999999999\" of \"value\" attribute in \"min-elements\" element is out of bounds.", "Line number 1."); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1931 | |
| 1932 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1933 | assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID); |
| 1934 | CHECK_LOG_CTX("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element.", "Line number 1."); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1935 | |
| 1936 | data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"05\"/> </leaf-list>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1937 | assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID); |
| 1938 | CHECK_LOG_CTX("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element.", "Line number 1."); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1939 | } |
| 1940 | |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1941 | static void |
| 1942 | test_ordby_elem(void **state) |
| 1943 | { |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1944 | const char *data; |
| 1945 | uint16_t flags = 0; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 1946 | struct lysp_ext_instance *exts = NULL; |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1947 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1948 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\">"EXT_SUBELEM "</ordered-by>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1949 | assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1950 | assert_true(flags & LYS_ORDBY_SYSTEM); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1951 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_ORDEREDBY); |
| 1952 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1953 | |
| 1954 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1955 | assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1956 | assert_true(flags & LYS_ORDBY_USER); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1957 | |
| 1958 | data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1959 | assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID); |
| 1960 | CHECK_LOG_CTX("Invalid value \"inv\" of \"value\" attribute in \"ordered-by\" element. " |
| 1961 | "Valid values are \"system\" and \"user\".", "Line number 1."); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1962 | } |
| 1963 | |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1964 | static void |
| 1965 | test_any_elem(void **state) |
| 1966 | { |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1967 | const char *data; |
| 1968 | struct lysp_node *siblings = NULL; |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1969 | struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings}; |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1970 | struct lysp_node_anydata *parsed = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1971 | uint16_t flags; |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1972 | |
| 1973 | /* anyxml max subelems */ |
| 1974 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 1975 | "<anyxml name=\"any-name\">\n" |
| 1976 | " <config value=\"true\" />\n" |
| 1977 | " <description><text>desc</text></description>\n" |
| 1978 | " <if-feature name=\"feature\" />\n" |
| 1979 | " <mandatory value=\"true\" />\n" |
| 1980 | " <must condition=\"must-cond\" />\n" |
| 1981 | " <reference><text>ref</text></reference>\n" |
| 1982 | " <status value=\"deprecated\"/>\n" |
| 1983 | " <when condition=\"when-cond\"/>\n" |
| 1984 | EXT_SUBELEM |
| 1985 | "</anyxml>" |
| 1986 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1987 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1988 | parsed = (struct lysp_node_anydata *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1989 | flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC; |
| 1990 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 1991 | "any-name", 0, LYS_ANYXML, 0, "ref", 1); |
| 1992 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1993 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1994 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LYEXT_SUBSTMT_SELF); |
| 1995 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1996 | siblings = NULL; |
| 1997 | |
| 1998 | /* anydata max subelems */ |
| 1999 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2000 | "<anydata name=\"any-name\">\n" |
| 2001 | " <config value=\"true\" />\n" |
| 2002 | " <description><text>desc</text></description>\n" |
| 2003 | " <if-feature name=\"feature\" />\n" |
| 2004 | " <mandatory value=\"true\" />\n" |
| 2005 | " <must condition=\"must-cond\" />\n" |
| 2006 | " <reference><text>ref</text></reference>\n" |
| 2007 | " <status value=\"deprecated\"/>\n" |
| 2008 | " <when condition=\"when-cond\"/>\n" |
| 2009 | EXT_SUBELEM |
| 2010 | "</anydata>" |
| 2011 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2012 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2013 | parsed = (struct lysp_node_anydata *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2014 | flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC; |
| 2015 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 2016 | "any-name", 0, LYS_ANYDATA, 0, "ref", 1); |
| 2017 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2018 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2019 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LYEXT_SUBSTMT_SELF); |
| 2020 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2021 | siblings = NULL; |
| 2022 | |
| 2023 | /* min subelems */ |
| 2024 | node_meta.parent = (void *)0x10; |
| 2025 | data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2026 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2027 | parsed = (struct lysp_node_anydata *)siblings; |
| 2028 | assert_ptr_equal(parsed->parent, node_meta.parent); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2029 | CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0, |
| 2030 | "any-name", 0, LYS_ANYDATA, 1, NULL, 0); |
| 2031 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 2032 | } |
| 2033 | |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2034 | static void |
| 2035 | test_leaf_elem(void **state) |
| 2036 | { |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2037 | const char *data; |
| 2038 | struct lysp_node *siblings = NULL; |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2039 | struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings}; |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2040 | struct lysp_node_leaf *parsed = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2041 | uint16_t flags; |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2042 | |
| 2043 | /* max elements */ |
| 2044 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2045 | "<leaf name=\"leaf\">\n" |
| 2046 | " <config value=\"true\" />\n" |
| 2047 | " <default value=\"def-val\"/>\n" |
| 2048 | " <description><text>desc</text></description>\n" |
| 2049 | " <if-feature name=\"feature\" />\n" |
| 2050 | " <mandatory value=\"true\" />\n" |
| 2051 | " <must condition=\"must-cond\" />\n" |
| 2052 | " <reference><text>ref</text></reference>\n" |
| 2053 | " <status value=\"deprecated\"/>\n" |
| 2054 | " <type name=\"type\"/>\n" |
| 2055 | " <units name=\"uni\"/>\n" |
| 2056 | " <when condition=\"when-cond\"/>\n" |
| 2057 | EXT_SUBELEM |
| 2058 | "</leaf>" |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2059 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2060 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2061 | parsed = (struct lysp_node_leaf *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2062 | flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC; |
| 2063 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 2064 | "leaf", 0, LYS_LEAF, 0, "ref", 1); |
| 2065 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2066 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2067 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LYEXT_SUBSTMT_SELF); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2068 | assert_string_equal(parsed->musts->arg.str, "must-cond"); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2069 | assert_string_equal(parsed->type.name, "type"); |
| 2070 | assert_string_equal(parsed->units, "uni"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2071 | assert_string_equal(parsed->dflt.str, "def-val"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2072 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2073 | siblings = NULL; |
| 2074 | |
| 2075 | /* min elements */ |
| 2076 | data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2077 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2078 | parsed = (struct lysp_node_leaf *)siblings; |
| 2079 | assert_string_equal(parsed->name, "leaf"); |
| 2080 | assert_string_equal(parsed->type.name, "type"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2081 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2082 | siblings = NULL; |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 2083 | } |
| 2084 | |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2085 | static void |
| 2086 | test_leaf_list_elem(void **state) |
| 2087 | { |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2088 | const char *data; |
| 2089 | struct lysp_node *siblings = NULL; |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2090 | struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings}; |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2091 | struct lysp_node_leaflist *parsed = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2092 | uint16_t flags; |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2093 | |
| 2094 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2095 | "<leaf-list name=\"llist\">\n" |
| 2096 | " <config value=\"true\" />\n" |
| 2097 | " <default value=\"def-val0\"/>\n" |
| 2098 | " <default value=\"def-val1\"/>\n" |
| 2099 | " <description><text>desc</text></description>\n" |
| 2100 | " <if-feature name=\"feature\"/>\n" |
| 2101 | " <max-elements value=\"5\"/>\n" |
| 2102 | " <must condition=\"must-cond\"/>\n" |
| 2103 | " <ordered-by value=\"user\" />\n" |
| 2104 | " <reference><text>ref</text></reference>\n" |
| 2105 | " <status value=\"current\"/>\n" |
| 2106 | " <type name=\"type\"/>\n" |
| 2107 | " <units name=\"uni\"/>\n" |
| 2108 | " <when condition=\"when-cond\"/>\n" |
| 2109 | EXT_SUBELEM |
| 2110 | "</leaf-list>" |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2111 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2112 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2113 | parsed = (struct lysp_node_leaflist *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2114 | flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MAX; |
| 2115 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 2116 | "llist", 0, LYS_LEAFLIST, 0, "ref", 1); |
| 2117 | CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2118 | assert_string_equal(parsed->dflts[0].str, "def-val0"); |
| 2119 | assert_string_equal(parsed->dflts[1].str, "def-val1"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2120 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2121 | assert_int_equal(parsed->max, 5); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2122 | assert_string_equal(parsed->type.name, "type"); |
| 2123 | assert_string_equal(parsed->units, "uni"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2124 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
| 2125 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LYEXT_SUBSTMT_SELF); |
| 2126 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2127 | siblings = NULL; |
| 2128 | |
| 2129 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2130 | "<leaf-list name=\"llist\">\n" |
| 2131 | " <config value=\"true\" />\n" |
| 2132 | " <description><text>desc</text></description>\n" |
| 2133 | " <if-feature name=\"feature\"/>\n" |
| 2134 | " <min-elements value=\"5\"/>\n" |
| 2135 | " <must condition=\"must-cond\"/>\n" |
| 2136 | " <ordered-by value=\"user\" />\n" |
| 2137 | " <reference><text>ref</text></reference>\n" |
| 2138 | " <status value=\"current\"/>\n" |
| 2139 | " <type name=\"type\"/>\n" |
| 2140 | " <units name=\"uni\"/>\n" |
| 2141 | " <when condition=\"when-cond\"/>\n" |
| 2142 | EXT_SUBELEM |
| 2143 | "</leaf-list>" |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2144 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2145 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2146 | parsed = (struct lysp_node_leaflist *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2147 | flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MIN; |
| 2148 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 2149 | "llist", 0, LYS_LEAFLIST, 0, "ref", 1); |
| 2150 | CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL); |
| 2151 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2152 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2153 | assert_int_equal(parsed->min, 5); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2154 | assert_string_equal(parsed->type.name, "type"); |
| 2155 | assert_string_equal(parsed->units, "uni"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2156 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LYEXT_SUBSTMT_SELF); |
| 2157 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2158 | siblings = NULL; |
| 2159 | |
| 2160 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2161 | "<leaf-list name=\"llist\">\n" |
| 2162 | " <config value=\"true\" />\n" |
| 2163 | " <description><text>desc</text></description>\n" |
| 2164 | " <if-feature name=\"feature\"/>\n" |
| 2165 | " <max-elements value=\"15\"/>\n" |
| 2166 | " <min-elements value=\"5\"/>\n" |
| 2167 | " <must condition=\"must-cond\"/>\n" |
| 2168 | " <ordered-by value=\"user\" />\n" |
| 2169 | " <reference><text>ref</text></reference>\n" |
| 2170 | " <status value=\"current\"/>\n" |
| 2171 | " <type name=\"type\"/>\n" |
| 2172 | " <units name=\"uni\"/>\n" |
| 2173 | " <when condition=\"when-cond\"/>\n" |
| 2174 | "</leaf-list>" |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2175 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2176 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2177 | parsed = (struct lysp_node_leaflist *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2178 | flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MIN | LYS_SET_MAX; |
| 2179 | CHECK_LYSP_NODE(parsed, "desc", 0, flags, 1, |
| 2180 | "llist", 0, LYS_LEAFLIST, 0, "ref", 1); |
| 2181 | CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL); |
| 2182 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2183 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2184 | assert_int_equal(parsed->min, 5); |
| 2185 | assert_int_equal(parsed->max, 15); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2186 | assert_string_equal(parsed->type.name, "type"); |
| 2187 | assert_string_equal(parsed->units, "uni"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2188 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2189 | siblings = NULL; |
| 2190 | |
| 2191 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2192 | "<leaf-list name=\"llist\">\n" |
| 2193 | " <type name=\"type\"/>\n" |
| 2194 | "</leaf-list>" |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2195 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2196 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2197 | parsed = (struct lysp_node_leaflist *)siblings; |
| 2198 | assert_string_equal(parsed->name, "llist"); |
| 2199 | assert_string_equal(parsed->type.name, "type"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2200 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2201 | siblings = NULL; |
| 2202 | |
| 2203 | /* invalid combinations */ |
| 2204 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2205 | "<leaf-list name=\"llist\">\n" |
| 2206 | " <max-elements value=\"5\"/>\n" |
| 2207 | " <min-elements value=\"15\"/>\n" |
| 2208 | " <type name=\"type\"/>" |
| 2209 | "</leaf-list>" |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2210 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2211 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID); |
| 2212 | CHECK_LOG_CTX("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5.", "Line number 4."); |
| 2213 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2214 | siblings = NULL; |
| 2215 | |
| 2216 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2217 | "<leaf-list name=\"llist\">\n" |
| 2218 | " <default value=\"def-val1\"/>\n" |
| 2219 | " <min-elements value=\"15\"/>\n" |
| 2220 | " <type name=\"type\"/>\n" |
| 2221 | "</leaf-list>" |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2222 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2223 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID); |
| 2224 | CHECK_LOG_CTX("Invalid combination of sub-elemnts \"min-elements\" and \"default\" in \"leaf-list\" element.", "Line number 5."); |
| 2225 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2226 | siblings = NULL; |
| 2227 | |
| 2228 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2229 | "<leaf-list name=\"llist\">" |
| 2230 | "</leaf-list>" |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2231 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2232 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID); |
| 2233 | CHECK_LOG_CTX("Missing mandatory sub-element \"type\" of \"leaf-list\" element.", "Line number 1."); |
| 2234 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2235 | siblings = NULL; |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 2236 | } |
| 2237 | |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2238 | static void |
| 2239 | test_presence_elem(void **state) |
| 2240 | { |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2241 | const char *data; |
| 2242 | const char *val; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2243 | struct lysp_ext_instance *exts = NULL; |
| 2244 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2245 | data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\">"EXT_SUBELEM "</presence>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2246 | assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2247 | assert_string_equal(val, "presence-val"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2248 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_PRESENCE); |
| 2249 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 2250 | lydict_remove(UTEST_LYCTX, val); |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2251 | |
| 2252 | data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2253 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2254 | assert_string_equal(val, "presence-val"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 2255 | lydict_remove(UTEST_LYCTX, val); |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2256 | |
| 2257 | data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2258 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID); |
| 2259 | CHECK_LOG_CTX("Missing mandatory attribute value of presence element.", "Line number 1."); |
David Sedlák | cb39f64 | 2019-07-19 13:19:55 +0200 | [diff] [blame] | 2260 | } |
| 2261 | |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2262 | static void |
| 2263 | test_key_elem(void **state) |
| 2264 | { |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2265 | const char *data; |
| 2266 | const char *val; |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2267 | struct lysp_ext_instance *exts = NULL; |
| 2268 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2269 | data = ELEMENT_WRAPPER_START "<key value=\"key-value\">"EXT_SUBELEM "</key>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2270 | assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS); |
David Sedlák | d114456 | 2019-08-06 12:36:14 +0200 | [diff] [blame] | 2271 | assert_string_equal(val, "key-value"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2272 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_KEY); |
| 2273 | FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 2274 | lydict_remove(UTEST_LYCTX, val); |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2275 | |
| 2276 | data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2277 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS); |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2278 | assert_string_equal(val, "key-value"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame^] | 2279 | lydict_remove(UTEST_LYCTX, val); |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2280 | |
| 2281 | data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2282 | assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID); |
| 2283 | CHECK_LOG_CTX("Missing mandatory attribute value of key element.", "Line number 1."); |
David Sedlák | 12470a8 | 2019-07-19 13:44:36 +0200 | [diff] [blame] | 2284 | } |
| 2285 | |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2286 | static void |
| 2287 | test_typedef_elem(void **state) |
| 2288 | { |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2289 | const char *data; |
| 2290 | struct lysp_tpdf *tpdfs = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 2291 | struct tree_node_meta typdef_meta = {NULL, (struct lysp_node **)&tpdfs}; |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2292 | |
| 2293 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2294 | "<typedef name=\"tpdf-name\">\n" |
| 2295 | " <default value=\"def-val\"/>\n" |
| 2296 | " <description><text>desc-text</text></description>\n" |
| 2297 | " <reference><text>ref-text</text></reference>\n" |
| 2298 | " <status value=\"current\"/>\n" |
| 2299 | " <type name=\"type\"/>\n" |
| 2300 | " <units name=\"uni\"/>\n" |
| 2301 | EXT_SUBELEM |
| 2302 | "</typedef>" |
| 2303 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2304 | assert_int_equal(test_element_helper(state, data, &typdef_meta, NULL, NULL), LY_SUCCESS); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2305 | assert_string_equal(tpdfs[0].dflt.str, "def-val"); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2306 | assert_string_equal(tpdfs[0].dsc, "desc-text"); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2307 | assert_string_equal(tpdfs[0].name, "tpdf-name"); |
| 2308 | assert_string_equal(tpdfs[0].ref, "ref-text"); |
| 2309 | assert_string_equal(tpdfs[0].type.name, "type"); |
| 2310 | assert_string_equal(tpdfs[0].units, "uni"); |
| 2311 | assert_true(tpdfs[0].flags & LYS_STATUS_CURR); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2312 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(tpdfs[0].exts[0]), LYEXT_SUBSTMT_SELF); |
| 2313 | FREE_ARRAY(UTEST_LYCTX, tpdfs, lysp_tpdf_free); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2314 | tpdfs = NULL; |
| 2315 | |
| 2316 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2317 | "<typedef name=\"tpdf-name\">\n" |
| 2318 | " <type name=\"type\"/>\n" |
| 2319 | "</typedef>" |
| 2320 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2321 | assert_int_equal(test_element_helper(state, data, &typdef_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2322 | assert_string_equal(tpdfs[0].name, "tpdf-name"); |
| 2323 | assert_string_equal(tpdfs[0].type.name, "type"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2324 | FREE_ARRAY(UTEST_LYCTX, tpdfs, lysp_tpdf_free); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2325 | tpdfs = NULL; |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 2326 | } |
| 2327 | |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2328 | static void |
| 2329 | test_refine_elem(void **state) |
| 2330 | { |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2331 | const char *data; |
| 2332 | struct lysp_refine *refines = NULL; |
| 2333 | |
| 2334 | /* max subelems */ |
| 2335 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2336 | "<refine target-node=\"target\">\n" |
| 2337 | " <if-feature name=\"feature\" />\n" |
| 2338 | " <must condition=\"cond\" />\n" |
| 2339 | " <presence value=\"presence\" />\n" |
| 2340 | " <default value=\"def\" />\n" |
| 2341 | " <config value=\"true\" />\n" |
| 2342 | " <mandatory value=\"true\" />\n" |
| 2343 | " <min-elements value=\"10\" />\n" |
| 2344 | " <max-elements value=\"20\" />\n" |
| 2345 | " <description><text>desc</text></description>\n" |
| 2346 | " <reference><text>ref</text></reference>\n" |
| 2347 | EXT_SUBELEM |
| 2348 | "</refine>" |
| 2349 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2350 | assert_int_equal(test_element_helper(state, data, &refines, NULL, NULL), LY_SUCCESS); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2351 | assert_string_equal(refines->nodeid, "target"); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2352 | assert_string_equal(refines->dflts[0].str, "def"); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2353 | assert_string_equal(refines->dsc, "desc"); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2354 | assert_true(refines->flags & LYS_CONFIG_W); |
| 2355 | assert_true(refines->flags & LYS_MAND_TRUE); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2356 | assert_string_equal(refines->iffeatures[0].str, "feature"); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2357 | assert_int_equal(refines->max, 20); |
| 2358 | assert_int_equal(refines->min, 10); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2359 | assert_string_equal(refines->musts->arg.str, "cond"); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2360 | assert_string_equal(refines->presence, "presence"); |
| 2361 | assert_string_equal(refines->ref, "ref"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2362 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refines->exts[0]), LYEXT_SUBSTMT_SELF); |
| 2363 | FREE_ARRAY(UTEST_LYCTX, refines, lysp_refine_free); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2364 | refines = NULL; |
| 2365 | |
| 2366 | /* min subelems */ |
| 2367 | data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2368 | assert_int_equal(test_element_helper(state, data, &refines, NULL, NULL), LY_SUCCESS); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2369 | assert_string_equal(refines->nodeid, "target"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2370 | FREE_ARRAY(UTEST_LYCTX, refines, lysp_refine_free); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2371 | refines = NULL; |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 2372 | } |
| 2373 | |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2374 | static void |
| 2375 | test_uses_elem(void **state) |
| 2376 | { |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2377 | const char *data; |
| 2378 | struct lysp_node *siblings = NULL; |
| 2379 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2380 | struct lysp_node_uses *parsed = NULL; |
| 2381 | |
| 2382 | /* max subelems */ |
| 2383 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2384 | "<uses name=\"uses-name\">\n" |
| 2385 | " <when condition=\"cond\" />\n" |
| 2386 | " <if-feature name=\"feature\" />\n" |
| 2387 | " <status value=\"obsolete\" />\n" |
| 2388 | " <description><text>desc</text></description>\n" |
| 2389 | " <reference><text>ref</text></reference>\n" |
| 2390 | " <refine target-node=\"target\"/>\n" |
| 2391 | " <augment target-node=\"target\" />\n" |
| 2392 | EXT_SUBELEM |
| 2393 | "</uses>" |
| 2394 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2395 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2396 | parsed = (struct lysp_node_uses *)&siblings[0]; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2397 | CHECK_LYSP_NODE(parsed, "desc", 1, LYS_STATUS_OBSLT, 1, |
| 2398 | "uses-name", 0, LYS_USES, 0, "ref", 1); |
| 2399 | CHECK_LYSP_WHEN(parsed->when, "cond", NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2400 | assert_string_equal(parsed->iffeatures[0].str, "feature"); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2401 | assert_string_equal(parsed->refines->nodeid, "target"); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2402 | assert_string_equal(parsed->augments->nodeid, "target"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2403 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LYEXT_SUBSTMT_SELF); |
| 2404 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2405 | siblings = NULL; |
| 2406 | |
| 2407 | /* min subelems */ |
| 2408 | data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2409 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2410 | assert_string_equal(siblings[0].name, "uses-name"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2411 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2412 | siblings = NULL; |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 2413 | } |
| 2414 | |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2415 | static void |
| 2416 | test_revision_elem(void **state) |
| 2417 | { |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2418 | const char *data; |
| 2419 | struct lysp_revision *revs = NULL; |
| 2420 | |
| 2421 | /* max subelems */ |
| 2422 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2423 | "<revision date=\"2018-12-25\">\n" |
| 2424 | " <description><text>desc</text></description>\n" |
| 2425 | " <reference><text>ref</text></reference>\n" |
| 2426 | EXT_SUBELEM |
| 2427 | "</revision>" |
| 2428 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2429 | assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_SUCCESS); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2430 | assert_string_equal(revs->date, "2018-12-25"); |
| 2431 | assert_string_equal(revs->dsc, "desc"); |
| 2432 | assert_string_equal(revs->ref, "ref"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2433 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(revs->exts[0]), LYEXT_SUBSTMT_SELF); |
| 2434 | FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2435 | revs = NULL; |
| 2436 | |
| 2437 | /* min subelems */ |
| 2438 | data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2439 | assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_SUCCESS); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2440 | assert_string_equal(revs->date, "2005-05-05"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2441 | FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2442 | revs = NULL; |
| 2443 | |
| 2444 | /* invalid value */ |
| 2445 | data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2446 | assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_EVALID); |
| 2447 | CHECK_LOG_CTX("Invalid value \"05-05-2005\" of \"revision\".", "Line number 1."); |
| 2448 | FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2449 | revs = NULL; |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 2450 | } |
| 2451 | |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2452 | static void |
| 2453 | test_include_elem(void **state) |
| 2454 | { |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2455 | const char *data; |
| 2456 | struct lysp_include *includes = NULL; |
| 2457 | struct include_meta inc_meta = {"module-name", &includes}; |
| 2458 | |
| 2459 | /* max subelems */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2460 | YCTX->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2461 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2462 | "<include module=\"mod\">\n" |
| 2463 | " <description><text>desc</text></description>\n" |
| 2464 | " <reference><text>ref</text></reference>\n" |
| 2465 | " <revision-date date=\"1999-09-09\"/>\n" |
| 2466 | EXT_SUBELEM |
| 2467 | "</include>" |
| 2468 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2469 | assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2470 | assert_string_equal(includes->name, "mod"); |
| 2471 | assert_string_equal(includes->dsc, "desc"); |
| 2472 | assert_string_equal(includes->ref, "ref"); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2473 | assert_string_equal(includes->rev, "1999-09-09"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2474 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(includes->exts[0]), LYEXT_SUBSTMT_SELF); |
| 2475 | FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2476 | includes = NULL; |
| 2477 | |
| 2478 | /* min subelems */ |
| 2479 | data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2480 | assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2481 | assert_string_equal(includes->name, "mod"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2482 | FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2483 | includes = NULL; |
| 2484 | |
| 2485 | /* invalid combinations */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2486 | YCTX->parsed_mod->version = LYS_VERSION_1_0; |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2487 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2488 | "<include module=\"mod\">\n" |
| 2489 | " <description><text>desc</text></description>\n" |
| 2490 | " <revision-date date=\"1999-09-09\"/>\n" |
| 2491 | "</include>" |
| 2492 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2493 | assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_EVALID); |
| 2494 | CHECK_LOG_CTX("Invalid sub-elemnt \"description\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer.", |
| 2495 | "Line number 2."); |
| 2496 | FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2497 | includes = NULL; |
| 2498 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2499 | YCTX->parsed_mod->version = LYS_VERSION_1_0; |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2500 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2501 | "<include module=\"mod\">\n" |
| 2502 | " <reference><text>ref</text></reference>\n" |
| 2503 | " <revision-date date=\"1999-09-09\"/>\n" |
| 2504 | "</include>" |
| 2505 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2506 | assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_EVALID); |
| 2507 | CHECK_LOG_CTX("Invalid sub-elemnt \"reference\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer.", |
| 2508 | "Line number 2."); |
| 2509 | FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2510 | includes = NULL; |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 2511 | } |
| 2512 | |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 2513 | static void |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2514 | test_list_elem(void **state) |
| 2515 | { |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2516 | const char *data; |
| 2517 | struct lysp_node *siblings = NULL; |
| 2518 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2519 | struct lysp_node_list *parsed = NULL; |
| 2520 | |
| 2521 | /* max subelems */ |
| 2522 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2523 | "<list name=\"list-name\">\n" |
| 2524 | " <when condition=\"when\"/>\n" |
| 2525 | " <if-feature name=\"iff\"/>\n" |
| 2526 | " <must condition=\"must-cond\"/>\n" |
| 2527 | " <key value=\"key\"/>\n" |
| 2528 | " <unique tag=\"utag\"/>\n" |
| 2529 | " <config value=\"true\"/>\n" |
| 2530 | " <min-elements value=\"10\"/>\n" |
| 2531 | " <ordered-by value=\"user\"/>\n" |
| 2532 | " <status value=\"deprecated\"/>\n" |
| 2533 | " <description><text>desc</text></description>\n" |
| 2534 | " <reference><text>ref</text></reference>\n" |
| 2535 | " <anydata name=\"anyd\"/>\n" |
| 2536 | " <anyxml name=\"anyx\"/>\n" |
| 2537 | " <container name=\"cont\"/>\n" |
| 2538 | " <choice name=\"choice\"/>\n" |
| 2539 | " <action name=\"action\"/>\n" |
| 2540 | " <grouping name=\"grp\"/>\n" |
| 2541 | " <notification name=\"notf\"/>\n" |
| 2542 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 2543 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 2544 | " <list name=\"sub-list\"/>\n" |
| 2545 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 2546 | " <uses name=\"uses-name\"/>\n" |
| 2547 | EXT_SUBELEM |
| 2548 | "</list>" |
| 2549 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2550 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2551 | parsed = (struct lysp_node_list *)&siblings[0]; |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2552 | assert_string_equal(parsed->child->name, "anyd"); |
| 2553 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 2554 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 2555 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2556 | assert_string_equal(parsed->child->next->next->name, "cont"); |
| 2557 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2558 | assert_string_equal(parsed->child->next->next->next->name, "choice"); |
| 2559 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2560 | assert_string_equal(parsed->child->next->next->next->next->name, "leaf"); |
| 2561 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAF); |
| 2562 | assert_string_equal(parsed->child->next->next->next->next->next->name, "llist"); |
| 2563 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2564 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "sub-list"); |
| 2565 | assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 2566 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name"); |
| 2567 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 2568 | assert_null(parsed->child->next->next->next->next->next->next->next->next); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2569 | uint16_t flags = LYS_ORDBY_USER | LYS_STATUS_DEPRC | LYS_CONFIG_W | LYS_SET_MIN; |
| 2570 | |
| 2571 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 2572 | "list-name", 0, LYS_LIST, 0, "ref", 1); |
| 2573 | CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL); |
| 2574 | CHECK_LYSP_WHEN(parsed->when, "when", NULL, 0, NULL); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2575 | assert_string_equal(parsed->groupings->name, "grp"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2576 | assert_string_equal(parsed->actions->name, "action"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2577 | assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2578 | assert_string_equal(parsed->notifs->name, "notf"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2579 | assert_string_equal(parsed->iffeatures[0].str, "iff"); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2580 | assert_string_equal(parsed->key, "key"); |
| 2581 | assert_int_equal(parsed->min, 10); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2582 | assert_string_equal(parsed->typedefs->name, "tpdf"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2583 | assert_string_equal(parsed->uniques->str, "utag"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2584 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LYEXT_SUBSTMT_SELF); |
| 2585 | lysp_node_free(UTEST_LYCTX, siblings); |
| 2586 | ly_set_erase(&YCTX->tpdfs_nodes, NULL); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2587 | siblings = NULL; |
| 2588 | |
| 2589 | /* min subelems */ |
| 2590 | data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2591 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2592 | parsed = (struct lysp_node_list *)&siblings[0]; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2593 | CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0, |
| 2594 | "list-name", 0, LYS_LIST, 0, NULL, 0); |
| 2595 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2596 | siblings = NULL; |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2597 | } |
| 2598 | |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2599 | static void |
| 2600 | test_notification_elem(void **state) |
| 2601 | { |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2602 | const char *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2603 | struct lysp_node_notif *notifs = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 2604 | struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)¬ifs}; |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2605 | |
| 2606 | /* max subelems */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2607 | YCTX->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2608 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2609 | "<notification name=\"notif-name\">\n" |
| 2610 | " <anydata name=\"anyd\"/>\n" |
| 2611 | " <anyxml name=\"anyx\"/>\n" |
| 2612 | " <description><text>desc</text></description>\n" |
| 2613 | " <if-feature name=\"iff\"/>\n" |
| 2614 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 2615 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 2616 | " <list name=\"sub-list\"/>\n" |
| 2617 | " <must condition=\"cond\"/>\n" |
| 2618 | " <reference><text>ref</text></reference>\n" |
| 2619 | " <status value=\"deprecated\"/>\n" |
| 2620 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 2621 | " <uses name=\"uses-name\"/>\n" |
| 2622 | " <container name=\"cont\"/>\n" |
| 2623 | " <choice name=\"choice\"/>\n" |
| 2624 | " <grouping name=\"grp\"/>\n" |
| 2625 | EXT_SUBELEM |
| 2626 | "</notification>" |
| 2627 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2628 | assert_int_equal(test_element_helper(state, data, ¬if_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2629 | assert_string_equal(notifs->name, "notif-name"); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2630 | assert_string_equal(notifs->child->name, "anyd"); |
| 2631 | assert_int_equal(notifs->child->nodetype, LYS_ANYDATA); |
| 2632 | assert_string_equal(notifs->child->next->name, "anyx"); |
| 2633 | assert_int_equal(notifs->child->next->nodetype, LYS_ANYXML); |
| 2634 | assert_string_equal(notifs->child->next->next->name, "leaf"); |
| 2635 | assert_int_equal(notifs->child->next->next->nodetype, LYS_LEAF); |
| 2636 | assert_string_equal(notifs->child->next->next->next->name, "llist"); |
| 2637 | assert_int_equal(notifs->child->next->next->next->nodetype, LYS_LEAFLIST); |
| 2638 | assert_string_equal(notifs->child->next->next->next->next->name, "sub-list"); |
| 2639 | assert_int_equal(notifs->child->next->next->next->next->nodetype, LYS_LIST); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2640 | assert_true(notifs->flags & LYS_STATUS_DEPRC); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2641 | assert_string_equal(notifs->groupings->name, "grp"); |
| 2642 | assert_int_equal(notifs->groupings->nodetype, LYS_GROUPING); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2643 | assert_string_equal(notifs->child->next->next->next->next->next->name, "uses-name"); |
| 2644 | assert_int_equal(notifs->child->next->next->next->next->next->nodetype, LYS_USES); |
| 2645 | assert_string_equal(notifs->child->next->next->next->next->next->next->name, "cont"); |
| 2646 | assert_int_equal(notifs->child->next->next->next->next->next->next->nodetype, LYS_CONTAINER); |
| 2647 | assert_int_equal(notifs->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 2648 | assert_string_equal(notifs->child->next->next->next->next->next->next->next->name, "choice"); |
| 2649 | assert_null(notifs->child->next->next->next->next->next->next->next->next); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2650 | assert_string_equal(notifs->iffeatures[0].str, "iff"); |
| 2651 | assert_string_equal(notifs->musts->arg.str, "cond"); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2652 | assert_int_equal(notifs->nodetype, LYS_NOTIF); |
| 2653 | assert_null(notifs->parent); |
| 2654 | assert_string_equal(notifs->ref, "ref"); |
| 2655 | assert_string_equal(notifs->typedefs->name, "tpdf"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2656 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(notifs->exts[0]), LYEXT_SUBSTMT_SELF); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2657 | lysp_node_free(UTEST_LYCTX, (struct lysp_node *)notifs); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2658 | notifs = NULL; |
| 2659 | |
| 2660 | /* min subelems */ |
| 2661 | data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2662 | assert_int_equal(test_element_helper(state, data, ¬if_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2663 | assert_string_equal(notifs->name, "notif-name"); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2664 | lysp_node_free(UTEST_LYCTX, (struct lysp_node *)notifs); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2665 | notifs = NULL; |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2666 | } |
| 2667 | |
| 2668 | static void |
| 2669 | test_grouping_elem(void **state) |
| 2670 | { |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2671 | const char *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2672 | struct lysp_node_grp *grps = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 2673 | struct tree_node_meta grp_meta = {NULL, (struct lysp_node **)&grps}; |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2674 | |
| 2675 | /* max subelems */ |
| 2676 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2677 | "<grouping name=\"grp-name\">\n" |
| 2678 | " <anydata name=\"anyd\"/>\n" |
| 2679 | " <anyxml name=\"anyx\"/>\n" |
| 2680 | " <description><text>desc</text></description>\n" |
| 2681 | " <grouping name=\"sub-grp\"/>\n" |
| 2682 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 2683 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 2684 | " <list name=\"list\"/>\n" |
| 2685 | " <notification name=\"notf\"/>\n" |
| 2686 | " <reference><text>ref</text></reference>\n" |
| 2687 | " <status value=\"current\"/>\n" |
| 2688 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 2689 | " <uses name=\"uses-name\"/>\n" |
| 2690 | " <action name=\"act\"/>\n" |
| 2691 | " <container name=\"cont\"/>\n" |
| 2692 | " <choice name=\"choice\"/>\n" |
| 2693 | EXT_SUBELEM |
| 2694 | "</grouping>" |
| 2695 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2696 | assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2697 | assert_string_equal(grps->name, "grp-name"); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2698 | assert_string_equal(grps->child->name, "anyd"); |
| 2699 | assert_string_equal(grps->child->next->name, "anyx"); |
| 2700 | assert_string_equal(grps->child->next->next->name, "leaf"); |
| 2701 | assert_string_equal(grps->child->next->next->next->name, "llist"); |
| 2702 | assert_string_equal(grps->child->next->next->next->next->name, "list"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2703 | assert_string_equal(grps->dsc, "desc"); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2704 | assert_true(grps->flags & LYS_STATUS_CURR); |
| 2705 | assert_string_equal(grps->groupings->name, "sub-grp"); |
| 2706 | assert_int_equal(grps->nodetype, LYS_GROUPING); |
| 2707 | assert_string_equal(grps->notifs->name, "notf"); |
| 2708 | assert_null(grps->parent); |
| 2709 | assert_string_equal(grps->ref, "ref"); |
| 2710 | assert_string_equal(grps->typedefs->name, "tpdf"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2711 | assert_string_equal(grps->actions->name, "act"); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2712 | assert_string_equal(grps->child->next->next->next->next->next->name, "uses-name"); |
| 2713 | assert_int_equal(grps->child->next->next->next->next->next->nodetype, LYS_USES); |
| 2714 | assert_string_equal(grps->child->next->next->next->next->next->next->name, "cont"); |
| 2715 | assert_int_equal(grps->child->next->next->next->next->next->next->nodetype, LYS_CONTAINER); |
| 2716 | assert_string_equal(grps->child->next->next->next->next->next->next->next->name, "choice"); |
| 2717 | assert_int_equal(grps->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2718 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(grps->exts[0]), LYEXT_SUBSTMT_SELF); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2719 | lysp_node_free(UTEST_LYCTX, &grps->node); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2720 | grps = NULL; |
| 2721 | |
| 2722 | /* min subelems */ |
| 2723 | data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2724 | assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2725 | assert_string_equal(grps->name, "grp-name"); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2726 | lysp_node_free(UTEST_LYCTX, &grps->node); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2727 | grps = NULL; |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2728 | } |
| 2729 | |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2730 | static void |
| 2731 | test_container_elem(void **state) |
| 2732 | { |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2733 | const char *data; |
| 2734 | struct lysp_node *siblings = NULL; |
| 2735 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2736 | struct lysp_node_container *parsed = NULL; |
| 2737 | |
| 2738 | /* max subelems */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2739 | YCTX->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 2740 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2741 | "<container name=\"cont-name\">\n" |
| 2742 | " <anydata name=\"anyd\"/>\n" |
| 2743 | " <anyxml name=\"anyx\"/>\n" |
| 2744 | " <config value=\"true\"/>\n" |
| 2745 | " <container name=\"subcont\"/>\n" |
| 2746 | " <description><text>desc</text></description>\n" |
| 2747 | " <grouping name=\"sub-grp\"/>\n" |
| 2748 | " <if-feature name=\"iff\"/>\n" |
| 2749 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 2750 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 2751 | " <list name=\"list\"/>\n" |
| 2752 | " <must condition=\"cond\"/>\n" |
| 2753 | " <notification name=\"notf\"/>\n" |
| 2754 | " <presence value=\"presence\"/>\n" |
| 2755 | " <reference><text>ref</text></reference>\n" |
| 2756 | " <status value=\"current\"/>\n" |
| 2757 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 2758 | " <uses name=\"uses-name\"/>\n" |
| 2759 | " <when condition=\"when-cond\"/>\n" |
| 2760 | " <action name=\"act\"/>\n" |
| 2761 | " <choice name=\"choice\"/>\n" |
| 2762 | EXT_SUBELEM |
| 2763 | "</container>" |
| 2764 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2765 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 2766 | parsed = (struct lysp_node_container *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2767 | uint16_t flags = LYS_CONFIG_W | LYS_STATUS_CURR; |
| 2768 | |
| 2769 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 2770 | "cont-name", 0, LYS_CONTAINER, 0, "ref", 1); |
| 2771 | CHECK_LYSP_RESTR(parsed->musts, "cond", NULL, NULL, NULL, 0, NULL); |
| 2772 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
| 2773 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2774 | assert_string_equal(parsed->iffeatures[0].str, "iff"); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 2775 | assert_string_equal(parsed->presence, "presence"); |
| 2776 | assert_string_equal(parsed->typedefs->name, "tpdf"); |
| 2777 | assert_string_equal(parsed->groupings->name, "sub-grp"); |
| 2778 | assert_string_equal(parsed->child->name, "anyd"); |
| 2779 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 2780 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 2781 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 2782 | assert_string_equal(parsed->child->next->next->name, "subcont"); |
| 2783 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
| 2784 | assert_string_equal(parsed->child->next->next->next->name, "leaf"); |
| 2785 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF); |
| 2786 | assert_string_equal(parsed->child->next->next->next->next->name, "llist"); |
| 2787 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2788 | assert_string_equal(parsed->child->next->next->next->next->next->name, "list"); |
| 2789 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST); |
| 2790 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name"); |
| 2791 | 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] | 2792 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice"); |
| 2793 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 2794 | 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] | 2795 | assert_string_equal(parsed->notifs->name, "notf"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2796 | assert_string_equal(parsed->actions->name, "act"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2797 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LYEXT_SUBSTMT_SELF); |
| 2798 | lysp_node_free(UTEST_LYCTX, siblings); |
| 2799 | ly_set_erase(&YCTX->tpdfs_nodes, NULL); |
David Sedlák | e2dc9e9 | 2019-07-24 09:59:21 +0200 | [diff] [blame] | 2800 | siblings = NULL; |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2801 | |
| 2802 | /* min subelems */ |
| 2803 | data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2804 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2805 | parsed = (struct lysp_node_container *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2806 | CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0, |
| 2807 | "cont-name", 0, LYS_CONTAINER, 0, NULL, 0); |
| 2808 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2809 | siblings = NULL; |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2810 | } |
| 2811 | |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2812 | static void |
| 2813 | test_case_elem(void **state) |
| 2814 | { |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2815 | const char *data; |
| 2816 | struct lysp_node *siblings = NULL; |
| 2817 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2818 | struct lysp_node_case *parsed = NULL; |
| 2819 | |
| 2820 | /* max subelems */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2821 | YCTX->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2822 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2823 | "<case name=\"case-name\">\n" |
| 2824 | " <anydata name=\"anyd\"/>\n" |
| 2825 | " <anyxml name=\"anyx\"/>\n" |
| 2826 | " <container name=\"subcont\"/>\n" |
| 2827 | " <description><text>desc</text></description>\n" |
| 2828 | " <if-feature name=\"iff\"/>\n" |
| 2829 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 2830 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 2831 | " <list name=\"list\"/>\n" |
| 2832 | " <reference><text>ref</text></reference>\n" |
| 2833 | " <status value=\"current\"/>\n" |
| 2834 | " <uses name=\"uses-name\"/>\n" |
| 2835 | " <when condition=\"when-cond\"/>\n" |
| 2836 | " <choice name=\"choice\"/>\n" |
| 2837 | EXT_SUBELEM |
| 2838 | "</case>" |
| 2839 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2840 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2841 | parsed = (struct lysp_node_case *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2842 | uint16_t flags = LYS_STATUS_CURR; |
| 2843 | |
| 2844 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 2845 | "case-name", 0, LYS_CASE, 0, "ref", 1); |
| 2846 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2847 | assert_string_equal(parsed->iffeatures[0].str, "iff"); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2848 | assert_string_equal(parsed->child->name, "anyd"); |
| 2849 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 2850 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 2851 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 2852 | assert_string_equal(parsed->child->next->next->name, "subcont"); |
| 2853 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CONTAINER); |
| 2854 | assert_string_equal(parsed->child->next->next->next->name, "leaf"); |
| 2855 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_LEAF); |
| 2856 | assert_string_equal(parsed->child->next->next->next->next->name, "llist"); |
| 2857 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2858 | assert_string_equal(parsed->child->next->next->next->next->next->name, "list"); |
| 2859 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LIST); |
| 2860 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "uses-name"); |
| 2861 | 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] | 2862 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice"); |
| 2863 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE); |
| 2864 | assert_null(parsed->child->next->next->next->next->next->next->next->next); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2865 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LYEXT_SUBSTMT_SELF); |
| 2866 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2867 | siblings = NULL; |
| 2868 | |
| 2869 | /* min subelems */ |
| 2870 | data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2871 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2872 | parsed = (struct lysp_node_case *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2873 | CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0, |
| 2874 | "case-name", 0, LYS_CASE, 0, NULL, 0); |
| 2875 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2876 | siblings = NULL; |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2877 | } |
| 2878 | |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2879 | static void |
| 2880 | test_choice_elem(void **state) |
| 2881 | { |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2882 | const char *data; |
| 2883 | struct lysp_node *siblings = NULL; |
| 2884 | struct tree_node_meta node_meta = {NULL, &siblings}; |
| 2885 | struct lysp_node_choice *parsed = NULL; |
| 2886 | |
| 2887 | /* max subelems */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2888 | YCTX->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2889 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2890 | "<choice name=\"choice-name\">\n" |
| 2891 | " <anydata name=\"anyd\"/>\n" |
| 2892 | " <anyxml name=\"anyx\"/>\n" |
| 2893 | " <case name=\"sub-case\"/>\n" |
| 2894 | " <choice name=\"choice\"/>\n" |
| 2895 | " <config value=\"true\"/>\n" |
| 2896 | " <container name=\"subcont\"/>\n" |
| 2897 | " <default value=\"def\"/>\n" |
| 2898 | " <description><text>desc</text></description>\n" |
| 2899 | " <if-feature name=\"iff\"/>\n" |
| 2900 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 2901 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 2902 | " <list name=\"list\"/>\n" |
| 2903 | " <mandatory value=\"true\" />\n" |
| 2904 | " <reference><text>ref</text></reference>\n" |
| 2905 | " <status value=\"current\"/>\n" |
| 2906 | " <when condition=\"when-cond\"/>\n" |
| 2907 | EXT_SUBELEM |
| 2908 | "</choice>" |
| 2909 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2910 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2911 | parsed = (struct lysp_node_choice *)siblings; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2912 | uint16_t flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_CURR; |
| 2913 | |
| 2914 | CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1, |
| 2915 | "choice-name", 0, LYS_CHOICE, 0, "ref", 1); |
| 2916 | CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2917 | assert_string_equal(parsed->iffeatures[0].str, "iff"); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2918 | assert_string_equal(parsed->child->name, "anyd"); |
| 2919 | assert_int_equal(parsed->child->nodetype, LYS_ANYDATA); |
| 2920 | assert_string_equal(parsed->child->next->name, "anyx"); |
| 2921 | assert_int_equal(parsed->child->next->nodetype, LYS_ANYXML); |
| 2922 | assert_string_equal(parsed->child->next->next->name, "sub-case"); |
| 2923 | assert_int_equal(parsed->child->next->next->nodetype, LYS_CASE); |
| 2924 | assert_string_equal(parsed->child->next->next->next->name, "choice"); |
| 2925 | assert_int_equal(parsed->child->next->next->next->nodetype, LYS_CHOICE); |
| 2926 | assert_string_equal(parsed->child->next->next->next->next->name, "subcont"); |
| 2927 | assert_int_equal(parsed->child->next->next->next->next->nodetype, LYS_CONTAINER); |
| 2928 | assert_string_equal(parsed->child->next->next->next->next->next->name, "leaf"); |
| 2929 | assert_int_equal(parsed->child->next->next->next->next->next->nodetype, LYS_LEAF); |
| 2930 | assert_string_equal(parsed->child->next->next->next->next->next->next->name, "llist"); |
| 2931 | assert_int_equal(parsed->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2932 | assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list"); |
| 2933 | assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 2934 | assert_null(parsed->child->next->next->next->next->next->next->next->next); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2935 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]), LYEXT_SUBSTMT_SELF); |
| 2936 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2937 | siblings = NULL; |
| 2938 | |
| 2939 | /* min subelems */ |
| 2940 | data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2941 | assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2942 | parsed = (struct lysp_node_choice *)siblings; |
| 2943 | assert_string_equal(parsed->name, "choice-name"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2944 | CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0, |
| 2945 | "choice-name", 0, LYS_CHOICE, 0, NULL, 0); |
| 2946 | lysp_node_free(UTEST_LYCTX, siblings); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2947 | siblings = NULL; |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2948 | } |
| 2949 | |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2950 | static void |
| 2951 | test_inout_elem(void **state) |
| 2952 | { |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2953 | const char *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2954 | struct lysp_node_action_inout inout = {}; |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2955 | struct inout_meta inout_meta = {NULL, &inout}; |
| 2956 | |
| 2957 | /* max subelements */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2958 | YCTX->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2959 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 2960 | "<input>\n" |
| 2961 | " <anydata name=\"anyd\"/>\n" |
| 2962 | " <anyxml name=\"anyx\"/>\n" |
| 2963 | " <choice name=\"choice\"/>\n" |
| 2964 | " <container name=\"subcont\"/>\n" |
| 2965 | " <grouping name=\"sub-grp\"/>\n" |
| 2966 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 2967 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 2968 | " <list name=\"list\"/>\n" |
| 2969 | " <must condition=\"cond\"/>\n" |
| 2970 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 2971 | " <uses name=\"uses-name\"/>\n" |
| 2972 | EXT_SUBELEM |
| 2973 | "</input>" |
| 2974 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2975 | assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS); |
| 2976 | CHECK_LYSP_ACTION_INOUT(&(inout), 1, 1, 1, 1, LYS_INPUT, 0, 1); |
| 2977 | CHECK_LYSP_RESTR(inout.musts, "cond", NULL, NULL, NULL, 0, NULL); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2978 | assert_string_equal(inout.typedefs->name, "tpdf"); |
| 2979 | assert_string_equal(inout.groupings->name, "sub-grp"); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2980 | assert_string_equal(inout.child->name, "anyd"); |
| 2981 | assert_int_equal(inout.child->nodetype, LYS_ANYDATA); |
| 2982 | assert_string_equal(inout.child->next->name, "anyx"); |
| 2983 | assert_int_equal(inout.child->next->nodetype, LYS_ANYXML); |
| 2984 | assert_string_equal(inout.child->next->next->name, "choice"); |
| 2985 | assert_int_equal(inout.child->next->next->nodetype, LYS_CHOICE); |
| 2986 | assert_string_equal(inout.child->next->next->next->name, "subcont"); |
| 2987 | assert_int_equal(inout.child->next->next->next->nodetype, LYS_CONTAINER); |
| 2988 | assert_string_equal(inout.child->next->next->next->next->name, "leaf"); |
| 2989 | assert_int_equal(inout.child->next->next->next->next->nodetype, LYS_LEAF); |
| 2990 | assert_string_equal(inout.child->next->next->next->next->next->name, "llist"); |
| 2991 | assert_int_equal(inout.child->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 2992 | assert_string_equal(inout.child->next->next->next->next->next->next->name, "list"); |
| 2993 | assert_int_equal(inout.child->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 2994 | assert_string_equal(inout.child->next->next->next->next->next->next->next->name, "uses-name"); |
| 2995 | assert_int_equal(inout.child->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 2996 | assert_null(inout.child->next->next->next->next->next->next->next->next); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 2997 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]), LYEXT_SUBSTMT_SELF); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2998 | lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2999 | memset(&inout, 0, sizeof inout); |
| 3000 | |
| 3001 | /* max subelements */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3002 | YCTX->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3003 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3004 | "<output>\n" |
| 3005 | " <anydata name=\"anyd\"/>\n" |
| 3006 | " <anyxml name=\"anyx\"/>\n" |
| 3007 | " <choice name=\"choice\"/>\n" |
| 3008 | " <container name=\"subcont\"/>\n" |
| 3009 | " <grouping name=\"sub-grp\"/>\n" |
| 3010 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 3011 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 3012 | " <list name=\"list\"/>\n" |
| 3013 | " <must condition=\"cond\"/>\n" |
| 3014 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 3015 | " <uses name=\"uses-name\"/>\n" |
| 3016 | EXT_SUBELEM |
| 3017 | "</output>" |
| 3018 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3019 | assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS); |
| 3020 | CHECK_LYSP_ACTION_INOUT(&(inout), 1, 1, 1, 1, LYS_OUTPUT, 0, 1); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3021 | assert_string_equal(inout.musts->arg.str, "cond"); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3022 | assert_string_equal(inout.typedefs->name, "tpdf"); |
| 3023 | assert_string_equal(inout.groupings->name, "sub-grp"); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 3024 | assert_string_equal(inout.child->name, "anyd"); |
| 3025 | assert_int_equal(inout.child->nodetype, LYS_ANYDATA); |
| 3026 | assert_string_equal(inout.child->next->name, "anyx"); |
| 3027 | assert_int_equal(inout.child->next->nodetype, LYS_ANYXML); |
| 3028 | assert_string_equal(inout.child->next->next->name, "choice"); |
| 3029 | assert_int_equal(inout.child->next->next->nodetype, LYS_CHOICE); |
| 3030 | assert_string_equal(inout.child->next->next->next->name, "subcont"); |
| 3031 | assert_int_equal(inout.child->next->next->next->nodetype, LYS_CONTAINER); |
| 3032 | assert_string_equal(inout.child->next->next->next->next->name, "leaf"); |
| 3033 | assert_int_equal(inout.child->next->next->next->next->nodetype, LYS_LEAF); |
| 3034 | assert_string_equal(inout.child->next->next->next->next->next->name, "llist"); |
| 3035 | assert_int_equal(inout.child->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3036 | assert_string_equal(inout.child->next->next->next->next->next->next->name, "list"); |
| 3037 | assert_int_equal(inout.child->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3038 | assert_string_equal(inout.child->next->next->next->next->next->next->next->name, "uses-name"); |
| 3039 | assert_int_equal(inout.child->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3040 | assert_null(inout.child->next->next->next->next->next->next->next->next); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3041 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]), LYEXT_SUBSTMT_SELF); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 3042 | lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3043 | memset(&inout, 0, sizeof inout); |
| 3044 | |
| 3045 | /* min subelems */ |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3046 | data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3047 | assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 3048 | lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3049 | memset(&inout, 0, sizeof inout); |
| 3050 | |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 3051 | data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3052 | assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 3053 | lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3054 | memset(&inout, 0, sizeof inout); |
| 3055 | |
| 3056 | /* invalid combinations */ |
| 3057 | data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3058 | assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_EVALID); |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 3059 | lysp_node_free(UTEST_LYCTX, (struct lysp_node *)&inout); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3060 | CHECK_LOG_CTX("Unexpected attribute \"name\" of \"input\" element.", "Line number 1."); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3061 | memset(&inout, 0, sizeof inout); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 3062 | } |
| 3063 | |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3064 | static void |
| 3065 | test_action_elem(void **state) |
| 3066 | { |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3067 | const char *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 3068 | struct lysp_node_action *actions = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 3069 | struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions}; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3070 | uint16_t flags; |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3071 | |
| 3072 | /* max subelems */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3073 | YCTX->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3074 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3075 | "<action name=\"act\">\n" |
| 3076 | " <description><text>desc</text></description>\n" |
| 3077 | " <grouping name=\"grouping\"/>\n" |
| 3078 | " <if-feature name=\"iff\"/>\n" |
| 3079 | " <input><uses name=\"uses-name\"/></input>\n" |
| 3080 | " <output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>\n" |
| 3081 | " <reference><text>ref</text></reference>\n" |
| 3082 | " <status value=\"deprecated\"/>\n" |
| 3083 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 3084 | EXT_SUBELEM |
| 3085 | "</action>" |
| 3086 | ELEMENT_WRAPPER_END; |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 3087 | /* there must be parent for action */ |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3088 | act_meta.parent = (void *)1; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3089 | assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS); |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 3090 | act_meta.parent = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3091 | flags = LYS_STATUS_DEPRC; |
| 3092 | CHECK_LYSP_ACTION(actions, "desc", 1, flags, 1, 1,\ |
| 3093 | 1, 0, 0, 0,\ |
| 3094 | 1, 0,\ |
| 3095 | "act", LYS_ACTION, \ |
| 3096 | 1, 0, 0, 1,\ |
| 3097 | 1, 0,\ |
| 3098 | 1, "ref", 1); |
| 3099 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3100 | assert_string_equal(actions->iffeatures[0].str, "iff"); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3101 | assert_string_equal(actions->typedefs->name, "tpdf"); |
| 3102 | assert_string_equal(actions->groupings->name, "grouping"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3103 | assert_string_equal(actions->output.musts->arg.str, "cond"); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 3104 | assert_string_equal(actions->input.child->name, "uses-name"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3105 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]), LYEXT_SUBSTMT_SELF); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 3106 | lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3107 | actions = NULL; |
| 3108 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3109 | YCTX->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3110 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3111 | "<rpc name=\"act\">\n" |
| 3112 | " <description><text>desc</text></description>\n" |
| 3113 | " <grouping name=\"grouping\"/>\n" |
| 3114 | " <if-feature name=\"iff\"/>\n" |
| 3115 | " <input><uses name=\"uses-name\"/></input>\n" |
| 3116 | " <output><must condition=\"cond\"/><leaf name=\"l\"><type name=\"type\"/></leaf></output>\n" |
| 3117 | " <reference><text>ref</text></reference>\n" |
| 3118 | " <status value=\"deprecated\"/>\n" |
| 3119 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 3120 | EXT_SUBELEM |
| 3121 | "</rpc>" |
| 3122 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3123 | assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS); |
| 3124 | flags = LYS_STATUS_DEPRC; |
| 3125 | CHECK_LYSP_ACTION(actions, "desc", 1, flags, 1, 1,\ |
| 3126 | 1, 0, 0, 0,\ |
| 3127 | 1, 0,\ |
| 3128 | "act", LYS_RPC, \ |
| 3129 | 1, 0, 0, 1,\ |
| 3130 | 1, 0,\ |
| 3131 | 0, "ref", 1); |
| 3132 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3133 | assert_string_equal(actions->iffeatures[0].str, "iff"); |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3134 | assert_string_equal(actions->typedefs->name, "tpdf"); |
| 3135 | assert_string_equal(actions->groupings->name, "grouping"); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 3136 | assert_string_equal(actions->input.child->name, "uses-name"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3137 | assert_string_equal(actions->output.musts->arg.str, "cond"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3138 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]), LYEXT_SUBSTMT_SELF); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 3139 | lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions); |
David Sedlák | eaa4579 | 2019-07-24 15:25:01 +0200 | [diff] [blame] | 3140 | actions = NULL; |
| 3141 | |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3142 | /* min subelems */ |
| 3143 | data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3144 | assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3145 | assert_string_equal(actions->name, "act"); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 3146 | lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3147 | actions = NULL; |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 3148 | } |
| 3149 | |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3150 | static void |
| 3151 | test_augment_elem(void **state) |
| 3152 | { |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3153 | const char *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 3154 | struct lysp_node_augment *augments = NULL; |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 3155 | struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments}; |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3156 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3157 | YCTX->parsed_mod->version = LYS_VERSION_1_1; |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3158 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3159 | "<augment target-node=\"target\">\n" |
| 3160 | " <action name=\"action\"/>\n" |
| 3161 | " <anydata name=\"anyd\"/>\n" |
| 3162 | " <anyxml name=\"anyx\"/>\n" |
| 3163 | " <case name=\"case\"/>\n" |
| 3164 | " <choice name=\"choice\"/>\n" |
| 3165 | " <container name=\"subcont\"/>\n" |
| 3166 | " <description><text>desc</text></description>\n" |
| 3167 | " <if-feature name=\"iff\"/>\n" |
| 3168 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 3169 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 3170 | " <list name=\"list\"/>\n" |
| 3171 | " <notification name=\"notif\"/>\n" |
| 3172 | " <reference><text>ref</text></reference>\n" |
| 3173 | " <status value=\"current\"/>\n" |
| 3174 | " <uses name=\"uses\"/>\n" |
| 3175 | " <when condition=\"when-cond\"/>\n" |
| 3176 | EXT_SUBELEM |
| 3177 | "</augment>" |
| 3178 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3179 | assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3180 | assert_string_equal(augments->nodeid, "target"); |
| 3181 | assert_null(augments->parent); |
| 3182 | assert_int_equal(augments->nodetype, LYS_AUGMENT); |
| 3183 | assert_true(augments->flags & LYS_STATUS_CURR); |
| 3184 | assert_string_equal(augments->dsc, "desc"); |
| 3185 | assert_string_equal(augments->ref, "ref"); |
| 3186 | assert_string_equal(augments->when->cond, "when-cond"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3187 | assert_string_equal(augments->iffeatures[0].str, "iff"); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3188 | assert_string_equal(augments->child->name, "anyd"); |
| 3189 | assert_int_equal(augments->child->nodetype, LYS_ANYDATA); |
| 3190 | assert_string_equal(augments->child->next->name, "anyx"); |
| 3191 | assert_int_equal(augments->child->next->nodetype, LYS_ANYXML); |
| 3192 | assert_string_equal(augments->child->next->next->name, "case"); |
| 3193 | assert_int_equal(augments->child->next->next->nodetype, LYS_CASE); |
| 3194 | assert_string_equal(augments->child->next->next->next->name, "choice"); |
| 3195 | assert_int_equal(augments->child->next->next->next->nodetype, LYS_CHOICE); |
| 3196 | assert_string_equal(augments->child->next->next->next->next->name, "subcont"); |
| 3197 | assert_int_equal(augments->child->next->next->next->next->nodetype, LYS_CONTAINER); |
| 3198 | assert_string_equal(augments->child->next->next->next->next->next->name, "leaf"); |
| 3199 | assert_int_equal(augments->child->next->next->next->next->next->nodetype, LYS_LEAF); |
| 3200 | assert_string_equal(augments->child->next->next->next->next->next->next->name, "llist"); |
| 3201 | assert_int_equal(augments->child->next->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3202 | assert_string_equal(augments->child->next->next->next->next->next->next->next->name, "list"); |
| 3203 | assert_int_equal(augments->child->next->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3204 | assert_string_equal(augments->child->next->next->next->next->next->next->next->next->name, "uses"); |
| 3205 | assert_int_equal(augments->child->next->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3206 | assert_null(augments->child->next->next->next->next->next->next->next->next->next); |
| 3207 | assert_string_equal(augments->actions->name, "action"); |
| 3208 | assert_string_equal(augments->notifs->name, "notif"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3209 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(augments->exts[0]), LYEXT_SUBSTMT_SELF); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 3210 | lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)augments); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3211 | augments = NULL; |
| 3212 | |
| 3213 | data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3214 | assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3215 | assert_string_equal(augments->nodeid, "target"); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 3216 | lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)augments); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3217 | augments = NULL; |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 3218 | } |
| 3219 | |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3220 | static void |
| 3221 | test_deviate_elem(void **state) |
| 3222 | { |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3223 | const char *data; |
| 3224 | struct lysp_deviate *deviates = NULL; |
| 3225 | struct lysp_deviate_add *d_add; |
| 3226 | struct lysp_deviate_rpl *d_rpl; |
| 3227 | struct lysp_deviate_del *d_del; |
| 3228 | |
| 3229 | /* all valid arguments with min subelems */ |
| 3230 | data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3231 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3232 | assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3233 | lysp_deviate_free(UTEST_LYCTX, deviates); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3234 | free(deviates); |
| 3235 | deviates = NULL; |
| 3236 | |
| 3237 | data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3238 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3239 | assert_int_equal(deviates->mod, LYS_DEV_ADD); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3240 | lysp_deviate_free(UTEST_LYCTX, deviates); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3241 | free(deviates); |
| 3242 | deviates = NULL; |
| 3243 | |
| 3244 | data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3245 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3246 | assert_int_equal(deviates->mod, LYS_DEV_REPLACE); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3247 | lysp_deviate_free(UTEST_LYCTX, deviates); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3248 | free(deviates); |
| 3249 | deviates = NULL; |
| 3250 | |
| 3251 | data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3252 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3253 | assert_int_equal(deviates->mod, LYS_DEV_DELETE); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3254 | lysp_deviate_free(UTEST_LYCTX, deviates); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3255 | free(deviates); |
| 3256 | deviates = NULL; |
| 3257 | |
| 3258 | /* max subelems and valid arguments */ |
| 3259 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3260 | "<deviate value=\"not-supported\">" |
| 3261 | EXT_SUBELEM |
| 3262 | "</deviate>" |
| 3263 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3264 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3265 | assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3266 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LYEXT_SUBSTMT_SELF); |
| 3267 | lysp_deviate_free(UTEST_LYCTX, deviates); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3268 | free(deviates); |
| 3269 | deviates = NULL; |
| 3270 | |
| 3271 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3272 | "<deviate value=\"add\">\n" |
| 3273 | " <units name=\"units\"/>\n" |
| 3274 | " <must condition=\"cond\"/>\n" |
| 3275 | " <unique tag=\"utag\"/>\n" |
| 3276 | " <default value=\"def\"/>\n" |
| 3277 | " <config value=\"true\"/>\n" |
| 3278 | " <mandatory value=\"true\"/>\n" |
| 3279 | " <min-elements value=\"5\"/>\n" |
| 3280 | " <max-elements value=\"15\"/>\n" |
| 3281 | EXT_SUBELEM |
| 3282 | "</deviate>" |
| 3283 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3284 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3285 | d_add = (struct lysp_deviate_add *)deviates; |
| 3286 | assert_int_equal(d_add->mod, LYS_DEV_ADD); |
| 3287 | assert_null(d_add->next); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3288 | assert_string_equal(d_add->units, "units"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3289 | assert_string_equal(d_add->musts->arg.str, "cond"); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3290 | assert_string_equal(d_add->uniques[0].str, "utag"); |
| 3291 | assert_string_equal(d_add->dflts[0].str, "def"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3292 | assert_true((d_add->flags & LYS_MAND_TRUE) && (d_add->flags & LYS_CONFIG_W)); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3293 | assert_int_equal(d_add->min, 5); |
| 3294 | assert_int_equal(d_add->max, 15); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3295 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LYEXT_SUBSTMT_SELF); |
| 3296 | lysp_deviate_free(UTEST_LYCTX, deviates); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3297 | free(deviates); |
| 3298 | deviates = NULL; |
| 3299 | |
| 3300 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3301 | "<deviate value=\"replace\">\n" |
| 3302 | " <type name=\"newtype\"/>\n" |
| 3303 | " <units name=\"uni\"/>\n" |
| 3304 | " <default value=\"def\"/>\n" |
| 3305 | " <config value=\"true\"/>\n" |
| 3306 | " <mandatory value=\"true\"/>\n" |
| 3307 | " <min-elements value=\"5\"/>\n" |
| 3308 | " <max-elements value=\"15\"/>\n" |
| 3309 | EXT_SUBELEM |
| 3310 | "</deviate>" |
| 3311 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3312 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3313 | d_rpl = (struct lysp_deviate_rpl *)deviates; |
| 3314 | assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE); |
| 3315 | assert_null(d_rpl->next); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3316 | assert_string_equal(d_rpl->type->name, "newtype"); |
| 3317 | assert_string_equal(d_rpl->units, "uni"); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3318 | assert_string_equal(d_rpl->dflt.str, "def"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3319 | assert_true((d_rpl->flags & LYS_MAND_TRUE) && (d_rpl->flags & LYS_CONFIG_W)); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3320 | assert_int_equal(d_rpl->min, 5); |
| 3321 | assert_int_equal(d_rpl->max, 15); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3322 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LYEXT_SUBSTMT_SELF); |
| 3323 | lysp_deviate_free(UTEST_LYCTX, deviates); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3324 | free(deviates); |
| 3325 | deviates = NULL; |
| 3326 | |
| 3327 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3328 | "<deviate value=\"delete\">\n" |
| 3329 | " <units name=\"u\"/>\n" |
| 3330 | " <must condition=\"c\"/>\n" |
| 3331 | " <unique tag=\"tag\"/>\n" |
| 3332 | " <default value=\"default\"/>\n" |
| 3333 | EXT_SUBELEM |
| 3334 | "</deviate>" |
| 3335 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3336 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3337 | d_del = (struct lysp_deviate_del *)deviates; |
| 3338 | assert_int_equal(d_del->mod, LYS_DEV_DELETE); |
| 3339 | assert_null(d_del->next); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3340 | assert_string_equal(d_del->units, "u"); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3341 | assert_string_equal(d_del->musts->arg.str, "c"); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3342 | assert_string_equal(d_del->uniques[0].str, "tag"); |
| 3343 | assert_string_equal(d_del->dflts[0].str, "default"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3344 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]), LYEXT_SUBSTMT_SELF); |
| 3345 | lysp_deviate_free(UTEST_LYCTX, deviates); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3346 | free(deviates); |
| 3347 | deviates = NULL; |
| 3348 | |
| 3349 | /* invalid arguments */ |
| 3350 | data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3351 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID); |
| 3352 | CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"deviate\" element. " |
| 3353 | "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3354 | deviates = NULL; |
| 3355 | |
| 3356 | data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3357 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID); |
| 3358 | CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"deviate\" element. " |
| 3359 | "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3360 | deviates = NULL; |
| 3361 | |
| 3362 | data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3363 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID); |
| 3364 | CHECK_LOG_CTX("Invalid value \"ad\" of \"value\" attribute in \"deviate\" element. " |
| 3365 | "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3366 | deviates = NULL; |
| 3367 | |
| 3368 | data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3369 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID); |
| 3370 | CHECK_LOG_CTX("Invalid value \"adds\" of \"value\" attribute in \"deviate\" element. " |
| 3371 | "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3372 | deviates = NULL; |
| 3373 | |
| 3374 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3375 | "<deviate value=\"not-supported\">\n" |
| 3376 | " <must condition=\"c\"/>\n" |
| 3377 | "</deviate>" |
| 3378 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3379 | assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID); |
| 3380 | CHECK_LOG_CTX("Deviate of this type doesn't allow \"must\" as it's sub-element.", "Line number 2."); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 3381 | } |
| 3382 | |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3383 | static void |
| 3384 | test_deviation_elem(void **state) |
| 3385 | { |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3386 | const char *data; |
| 3387 | struct lysp_deviation *deviations = NULL; |
| 3388 | |
| 3389 | /* min subelems */ |
| 3390 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3391 | "<deviation target-node=\"target\">\n" |
| 3392 | " <deviate value=\"not-supported\"/>\n" |
| 3393 | "</deviation>" |
| 3394 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3395 | assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3396 | assert_string_equal(deviations->nodeid, "target"); |
| 3397 | assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3398 | FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3399 | deviations = NULL; |
| 3400 | |
| 3401 | /* max subelems */ |
| 3402 | data = ELEMENT_WRAPPER_START |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3403 | "<deviation target-node=\"target\">\n" |
| 3404 | " <reference><text>ref</text></reference>\n" |
| 3405 | " <description><text>desc</text></description>\n" |
| 3406 | " <deviate value=\"add\"/>\n" |
| 3407 | EXT_SUBELEM |
| 3408 | "</deviation>" |
| 3409 | ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3410 | assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_SUCCESS); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3411 | assert_string_equal(deviations->nodeid, "target"); |
| 3412 | assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD); |
| 3413 | assert_string_equal(deviations->ref, "ref"); |
| 3414 | assert_string_equal(deviations->dsc, "desc"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3415 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviations->exts[0]), LYEXT_SUBSTMT_SELF); |
| 3416 | FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3417 | deviations = NULL; |
| 3418 | |
| 3419 | /* invalid */ |
| 3420 | data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3421 | assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_EVALID); |
| 3422 | FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3423 | deviations = NULL; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3424 | CHECK_LOG_CTX("Missing mandatory sub-element \"deviate\" of \"deviation\" element.", "Line number 1."); |
| 3425 | /* TODO */} |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 3426 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3427 | static struct lysp_module * |
| 3428 | mod_renew(struct lys_yin_parser_ctx *ctx) |
| 3429 | { |
| 3430 | struct ly_ctx *ly_ctx = ctx->parsed_mod->mod->ctx; |
| 3431 | |
| 3432 | lys_module_free(ctx->parsed_mod->mod, NULL); |
| 3433 | ctx->parsed_mod = calloc(1, sizeof *ctx->parsed_mod); |
| 3434 | ctx->parsed_mod->mod = calloc(1, sizeof *ctx->parsed_mod->mod); |
| 3435 | ctx->parsed_mod->mod->parsed = ctx->parsed_mod; |
| 3436 | ctx->parsed_mod->mod->ctx = ly_ctx; |
| 3437 | |
| 3438 | return ctx->parsed_mod; |
| 3439 | } |
| 3440 | |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3441 | static void |
| 3442 | test_module_elem(void **state) |
| 3443 | { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3444 | const char *data; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3445 | struct lysp_module *lysp_mod = mod_renew(YCTX); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3446 | |
| 3447 | /* max subelems */ |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3448 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3449 | " <yang-version value=\"1.1\"/>\n" |
| 3450 | " <namespace uri=\"ns\"/>\n" |
| 3451 | " <prefix value=\"pref\"/>\n" |
| 3452 | " <include module=\"b-mod\"/>\n" |
| 3453 | " <import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n" |
| 3454 | " <organization><text>org</text></organization>\n" |
| 3455 | " <contact><text>contact</text></contact>\n" |
| 3456 | " <description><text>desc</text></description>\n" |
| 3457 | " <reference><text>ref</text></reference>\n" |
| 3458 | " <revision date=\"2019-02-02\"/>\n" |
| 3459 | " <anydata name=\"anyd\"/>\n" |
| 3460 | " <anyxml name=\"anyx\"/>\n" |
| 3461 | " <choice name=\"choice\"/>\n" |
| 3462 | " <container name=\"cont\"/>\n" |
| 3463 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 3464 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 3465 | " <list name=\"sub-list\"/>\n" |
| 3466 | " <uses name=\"uses-name\"/>\n" |
| 3467 | " <augment target-node=\"target\"/>\n" |
| 3468 | " <deviation target-node=\"target\">\n" |
| 3469 | " <deviate value=\"not-supported\"/>\n" |
| 3470 | " </deviation>\n" |
| 3471 | " <extension name=\"ext\"/>\n" |
| 3472 | " <feature name=\"feature\"/>\n" |
| 3473 | " <grouping name=\"grp\"/>\n" |
| 3474 | " <identity name=\"ident-name\"/>\n" |
| 3475 | " <notification name=\"notf\"/>\n" |
| 3476 | " <rpc name=\"rpc-name\"/>\n" |
| 3477 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 3478 | EXT_SUBELEM "\n" |
| 3479 | "</module>\n"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3480 | assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS); |
| 3481 | assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3482 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3483 | assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_SUCCESS); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3484 | assert_string_equal(lysp_mod->mod->name, "mod"); |
| 3485 | assert_string_equal(lysp_mod->revs, "2019-02-02"); |
| 3486 | assert_string_equal(lysp_mod->mod->ns, "ns"); |
| 3487 | assert_string_equal(lysp_mod->mod->prefix, "pref"); |
| 3488 | assert_null(lysp_mod->mod->filepath); |
| 3489 | assert_string_equal(lysp_mod->mod->org, "org"); |
| 3490 | assert_string_equal(lysp_mod->mod->contact, "contact"); |
| 3491 | assert_string_equal(lysp_mod->mod->dsc, "desc"); |
| 3492 | assert_string_equal(lysp_mod->mod->ref, "ref"); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3493 | assert_int_equal(lysp_mod->version, LYS_VERSION_1_1); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3494 | CHECK_LYSP_IMPORT(lysp_mod->imports, NULL, 0, "a-mod", |
| 3495 | "imp-pref", NULL, ""); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3496 | assert_string_equal(lysp_mod->includes->name, "b-mod"); |
| 3497 | assert_string_equal(lysp_mod->extensions->name, "ext"); |
| 3498 | assert_string_equal(lysp_mod->features->name, "feature"); |
| 3499 | assert_string_equal(lysp_mod->identities->name, "ident-name"); |
| 3500 | assert_string_equal(lysp_mod->typedefs->name, "tpdf"); |
| 3501 | assert_string_equal(lysp_mod->groupings->name, "grp"); |
| 3502 | assert_string_equal(lysp_mod->data->name, "anyd"); |
| 3503 | assert_int_equal(lysp_mod->data->nodetype, LYS_ANYDATA); |
| 3504 | assert_string_equal(lysp_mod->data->next->name, "anyx"); |
| 3505 | assert_int_equal(lysp_mod->data->next->nodetype, LYS_ANYXML); |
| 3506 | assert_string_equal(lysp_mod->data->next->next->name, "choice"); |
| 3507 | assert_int_equal(lysp_mod->data->next->next->nodetype, LYS_CHOICE); |
| 3508 | assert_string_equal(lysp_mod->data->next->next->next->name, "cont"); |
| 3509 | assert_int_equal(lysp_mod->data->next->next->next->nodetype, LYS_CONTAINER); |
| 3510 | assert_string_equal(lysp_mod->data->next->next->next->next->name, "leaf"); |
| 3511 | assert_int_equal(lysp_mod->data->next->next->next->next->nodetype, LYS_LEAF); |
| 3512 | assert_string_equal(lysp_mod->data->next->next->next->next->next->name, "llist"); |
| 3513 | assert_int_equal(lysp_mod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3514 | assert_string_equal(lysp_mod->data->next->next->next->next->next->next->name, "sub-list"); |
| 3515 | assert_int_equal(lysp_mod->data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3516 | assert_string_equal(lysp_mod->data->next->next->next->next->next->next->next->name, "uses-name"); |
| 3517 | assert_int_equal(lysp_mod->data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3518 | assert_null(lysp_mod->data->next->next->next->next->next->next->next->next); |
| 3519 | assert_string_equal(lysp_mod->augments->nodeid, "target"); |
| 3520 | assert_string_equal(lysp_mod->rpcs->name, "rpc-name"); |
| 3521 | assert_string_equal(lysp_mod->notifs->name, "notf"); |
| 3522 | assert_string_equal(lysp_mod->deviations->nodeid, "target"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3523 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(lysp_mod->exts[0]), LYEXT_SUBSTMT_SELF); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3524 | |
| 3525 | /* min subelems */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3526 | ly_in_free(UTEST_IN, 0); |
| 3527 | lyxml_ctx_free(YCTX->xmlctx); |
| 3528 | lysp_mod = mod_renew(YCTX); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3529 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
| 3530 | " <namespace uri=\"ns\"/>\n" |
| 3531 | " <prefix value=\"pref\"/>\n" |
| 3532 | " <yang-version value=\"1.1\"/>\n" |
| 3533 | "</module>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3534 | assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS); |
| 3535 | assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS); |
| 3536 | assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3537 | assert_string_equal(lysp_mod->mod->name, "mod"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3538 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3539 | /* incorrect subelem order */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3540 | ly_in_free(UTEST_IN, 0); |
| 3541 | lyxml_ctx_free(YCTX->xmlctx); |
| 3542 | lysp_mod = mod_renew(YCTX); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3543 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
| 3544 | " <feature name=\"feature\"/>\n" |
| 3545 | " <namespace uri=\"ns\"/>\n" |
| 3546 | " <prefix value=\"pref\"/>\n" |
| 3547 | " <yang-version value=\"1.1\"/>\n" |
| 3548 | "</module>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3549 | assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS); |
| 3550 | assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS); |
| 3551 | assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_EVALID); |
| 3552 | CHECK_LOG_CTX("Invalid order of module\'s sub-elements \"namespace\" can\'t appear after \"feature\".", "Line number 3."); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3553 | } |
| 3554 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3555 | static struct lysp_submodule * |
| 3556 | submod_renew(struct lys_yin_parser_ctx *ctx, const char *belongs_to) |
| 3557 | { |
| 3558 | struct ly_ctx *ly_ctx = ctx->parsed_mod->mod->ctx; |
| 3559 | |
| 3560 | lys_module_free(ctx->parsed_mod->mod, NULL); |
| 3561 | ctx->parsed_mod = calloc(1, sizeof(struct lysp_submodule)); |
| 3562 | ctx->parsed_mod->mod = calloc(1, sizeof *ctx->parsed_mod->mod); |
| 3563 | lydict_insert(ly_ctx, belongs_to, 0, &ctx->parsed_mod->mod->name); |
| 3564 | ctx->parsed_mod->mod->parsed = ctx->parsed_mod; |
| 3565 | ctx->parsed_mod->mod->ctx = ly_ctx; |
| 3566 | |
| 3567 | return (struct lysp_submodule *)ctx->parsed_mod; |
| 3568 | } |
| 3569 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3570 | static void |
| 3571 | test_submodule_elem(void **state) |
| 3572 | { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3573 | const char *data; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3574 | struct lysp_submodule *lysp_submod = submod_renew(YCTX, "module-name"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3575 | |
| 3576 | /* max subelements */ |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3577 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3578 | " <yang-version value=\"1.1\"/>\n" |
| 3579 | " <belongs-to module=\"module-name\">\n" |
| 3580 | " <prefix value=\"pref\"/>\n" |
| 3581 | " </belongs-to>\n" |
| 3582 | " <include module=\"b-mod\"/>\n" |
| 3583 | " <import module=\"a-mod\"><prefix value=\"imp-pref\"/></import>\n" |
| 3584 | " <organization><text>org</text></organization>\n" |
| 3585 | " <contact><text>contact</text></contact>\n" |
| 3586 | " <description><text>desc</text></description>\n" |
| 3587 | " <reference><text>ref</text></reference>\n" |
| 3588 | " <revision date=\"2019-02-02\"/>\n" |
| 3589 | " <anydata name=\"anyd\"/>\n" |
| 3590 | " <anyxml name=\"anyx\"/>\n" |
| 3591 | " <choice name=\"choice\"/>\n" |
| 3592 | " <container name=\"cont\"/>\n" |
| 3593 | " <leaf name=\"leaf\"> <type name=\"type\"/> </leaf>\n" |
| 3594 | " <leaf-list name=\"llist\"> <type name=\"type\"/> </leaf-list>\n" |
| 3595 | " <list name=\"sub-list\"/>\n" |
| 3596 | " <uses name=\"uses-name\"/>\n" |
| 3597 | " <augment target-node=\"target\"/>\n" |
| 3598 | " <deviation target-node=\"target\">\n" |
| 3599 | " <deviate value=\"not-supported\"/>\n" |
| 3600 | " </deviation>\n" |
| 3601 | " <extension name=\"ext\"/>\n" |
| 3602 | " <feature name=\"feature\"/>\n" |
| 3603 | " <grouping name=\"grp\"/>\n" |
| 3604 | " <identity name=\"ident-name\"/>\n" |
| 3605 | " <notification name=\"notf\"/>\n" |
| 3606 | " <rpc name=\"rpc-name\"/>\n" |
| 3607 | " <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n" |
| 3608 | EXT_SUBELEM "\n" |
| 3609 | "</submodule>\n"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3610 | assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS); |
| 3611 | assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3612 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3613 | assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3614 | assert_string_equal(lysp_submod->name, "mod"); |
| 3615 | assert_string_equal(lysp_submod->revs, "2019-02-02"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3616 | assert_string_equal(lysp_submod->prefix, "pref"); |
| 3617 | assert_null(lysp_submod->filepath); |
| 3618 | assert_string_equal(lysp_submod->org, "org"); |
| 3619 | assert_string_equal(lysp_submod->contact, "contact"); |
| 3620 | assert_string_equal(lysp_submod->dsc, "desc"); |
| 3621 | assert_string_equal(lysp_submod->ref, "ref"); |
| 3622 | assert_int_equal(lysp_submod->version, LYS_VERSION_1_1); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3623 | CHECK_LYSP_IMPORT(lysp_submod->imports, NULL, 0, "a-mod", |
| 3624 | "imp-pref", NULL, ""); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3625 | assert_string_equal(lysp_submod->includes->name, "b-mod"); |
| 3626 | assert_string_equal(lysp_submod->extensions->name, "ext"); |
| 3627 | assert_string_equal(lysp_submod->features->name, "feature"); |
| 3628 | assert_string_equal(lysp_submod->identities->name, "ident-name"); |
| 3629 | assert_string_equal(lysp_submod->typedefs->name, "tpdf"); |
| 3630 | assert_string_equal(lysp_submod->groupings->name, "grp"); |
| 3631 | assert_string_equal(lysp_submod->data->name, "anyd"); |
| 3632 | assert_int_equal(lysp_submod->data->nodetype, LYS_ANYDATA); |
| 3633 | assert_string_equal(lysp_submod->data->next->name, "anyx"); |
| 3634 | assert_int_equal(lysp_submod->data->next->nodetype, LYS_ANYXML); |
| 3635 | assert_string_equal(lysp_submod->data->next->next->name, "choice"); |
| 3636 | assert_int_equal(lysp_submod->data->next->next->nodetype, LYS_CHOICE); |
| 3637 | assert_string_equal(lysp_submod->data->next->next->next->name, "cont"); |
| 3638 | assert_int_equal(lysp_submod->data->next->next->next->nodetype, LYS_CONTAINER); |
| 3639 | assert_string_equal(lysp_submod->data->next->next->next->next->name, "leaf"); |
| 3640 | assert_int_equal(lysp_submod->data->next->next->next->next->nodetype, LYS_LEAF); |
| 3641 | assert_string_equal(lysp_submod->data->next->next->next->next->next->name, "llist"); |
| 3642 | assert_int_equal(lysp_submod->data->next->next->next->next->next->nodetype, LYS_LEAFLIST); |
| 3643 | assert_string_equal(lysp_submod->data->next->next->next->next->next->next->name, "sub-list"); |
| 3644 | assert_int_equal(lysp_submod->data->next->next->next->next->next->next->nodetype, LYS_LIST); |
| 3645 | assert_string_equal(lysp_submod->data->next->next->next->next->next->next->next->name, "uses-name"); |
| 3646 | assert_int_equal(lysp_submod->data->next->next->next->next->next->next->next->nodetype, LYS_USES); |
| 3647 | assert_null(lysp_submod->data->next->next->next->next->next->next->next->next); |
| 3648 | assert_string_equal(lysp_submod->augments->nodeid, "target"); |
| 3649 | assert_string_equal(lysp_submod->rpcs->name, "rpc-name"); |
| 3650 | assert_string_equal(lysp_submod->notifs->name, "notf"); |
| 3651 | assert_string_equal(lysp_submod->deviations->nodeid, "target"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3652 | TEST_1_CHECK_LYSP_EXT_INSTANCE(&(lysp_submod->exts[0]), LYEXT_SUBSTMT_SELF); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3653 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3654 | /* min subelemnts */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3655 | ly_in_free(UTEST_IN, 0); |
| 3656 | lyxml_ctx_free(YCTX->xmlctx); |
| 3657 | lysp_submod = submod_renew(YCTX, "module-name"); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3658 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">\n" |
| 3659 | " <yang-version value=\"1\"/>\n" |
| 3660 | " <belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>\n" |
| 3661 | "</submodule>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3662 | assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS); |
| 3663 | assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS); |
| 3664 | assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_SUCCESS); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3665 | assert_string_equal(lysp_submod->prefix, "pref"); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3666 | assert_int_equal(lysp_submod->version, LYS_VERSION_1_0); |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3667 | |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3668 | /* incorrect subelem order */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3669 | ly_in_free(UTEST_IN, 0); |
| 3670 | lyxml_ctx_free(YCTX->xmlctx); |
| 3671 | lysp_submod = submod_renew(YCTX, "module-name"); |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3672 | data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">\n" |
| 3673 | " <yang-version value=\"1\"/>\n" |
| 3674 | " <reference><text>ref</text></reference>\n" |
| 3675 | " <belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>\n" |
| 3676 | "</submodule>"; |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3677 | assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS); |
| 3678 | assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS); |
| 3679 | assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_EVALID); |
| 3680 | CHECK_LOG_CTX("Invalid order of submodule's sub-elements \"belongs-to\" can't appear after \"reference\".", "Line number 4."); |
David Sedlák | 4f03b93 | 2019-07-26 13:01:47 +0200 | [diff] [blame] | 3681 | } |
| 3682 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3683 | static void |
| 3684 | test_yin_parse_module(void **state) |
| 3685 | { |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3686 | const char *data; |
| 3687 | struct lys_module *mod; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3688 | struct lys_yin_parser_ctx *yin_ctx = NULL; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3689 | struct ly_in *in = NULL; |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 3690 | struct lys_glob_unres unres = {0}; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3691 | |
| 3692 | mod = calloc(1, sizeof *mod); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3693 | mod->ctx = UTEST_LYCTX; |
David Sedlák | d284488 | 2019-09-13 16:01:22 +0200 | [diff] [blame] | 3694 | data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" name=\"a\"> \n" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3695 | " <yang-version value=\"1.1\"/>\n" |
| 3696 | " <namespace uri=\"urn:tests:extensions:metadata:a\"/>\n" |
| 3697 | " <prefix value=\"a\"/>\n" |
| 3698 | " <import module=\"ietf-yang-metadata\">\n" |
| 3699 | " <prefix value=\"md\"/>\n" |
| 3700 | " </import>\n" |
| 3701 | " <feature name=\"f\"/>\n" |
| 3702 | " <md:annotation name=\"x\">\n" |
| 3703 | " <description>\n" |
| 3704 | " <text>test</text>\n" |
| 3705 | " </description>\n" |
| 3706 | " <reference>\n" |
| 3707 | " <text>test</text>\n" |
| 3708 | " </reference>\n" |
| 3709 | " <if-feature name=\"f\"/>\n" |
| 3710 | " <status value=\"current\"/>\n" |
| 3711 | " <type name=\"uint8\"/>\n" |
| 3712 | " <units name=\"meters\"/>\n" |
| 3713 | " </md:annotation>\n" |
| 3714 | "</module>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3715 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 3716 | assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS); |
David Sedlák | d284488 | 2019-09-13 16:01:22 +0200 | [diff] [blame] | 3717 | assert_null(mod->parsed->exts->child->next->child); |
| 3718 | assert_string_equal(mod->parsed->exts->child->next->arg, "test"); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3719 | lys_compile_unres_glob_erase(UTEST_LYCTX, &unres); |
David Sedlák | d284488 | 2019-09-13 16:01:22 +0200 | [diff] [blame] | 3720 | lys_module_free(mod, NULL); |
| 3721 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3722 | ly_in_free(in, 0); |
David Sedlák | d284488 | 2019-09-13 16:01:22 +0200 | [diff] [blame] | 3723 | mod = NULL; |
| 3724 | yin_ctx = NULL; |
| 3725 | |
| 3726 | mod = calloc(1, sizeof *mod); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3727 | mod->ctx = UTEST_LYCTX; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3728 | data = "<module name=\"example-foo\"" |
| 3729 | " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"" |
| 3730 | " xmlns:foo=\"urn:example:foo\"" |
| 3731 | " xmlns:myext=\"urn:example:extensions\">\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3732 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3733 | " <yang-version value=\"1\"/>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3734 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3735 | " <namespace uri=\"urn:example:foo\"/>\n" |
| 3736 | " <prefix value=\"foo\"/>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3737 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3738 | " <import module=\"example-extensions\">\n" |
| 3739 | " <prefix value=\"myext\"/>\n" |
| 3740 | " </import>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3741 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3742 | " <list name=\"interface\">\n" |
| 3743 | " <key value=\"name\"/>\n" |
| 3744 | " <leaf name=\"name\">\n" |
| 3745 | " <type name=\"string\"/>\n" |
| 3746 | " </leaf>\n" |
| 3747 | " <leaf name=\"mtu\">\n" |
| 3748 | " <type name=\"uint32\"/>\n" |
| 3749 | " <description>\n" |
| 3750 | " <text>The MTU of the interface.</text>\n" |
| 3751 | " </description>\n" |
| 3752 | " <myext:c-define name=\"MY_MTU\"/>\n" |
| 3753 | " </leaf>\n" |
| 3754 | " </list>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3755 | "</module>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3756 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 3757 | assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3758 | lys_compile_unres_glob_erase(UTEST_LYCTX, &unres); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3759 | lys_module_free(mod, NULL); |
| 3760 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3761 | ly_in_free(in, 0); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3762 | mod = NULL; |
| 3763 | yin_ctx = NULL; |
| 3764 | |
| 3765 | mod = calloc(1, sizeof *mod); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3766 | mod->ctx = UTEST_LYCTX; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3767 | data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 3768 | " <yang-version value=\"1\"/>\n" |
| 3769 | " <namespace uri=\"urn:example:foo\"/>\n" |
| 3770 | " <prefix value=\"foo\"/>\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3771 | "</module>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3772 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 3773 | assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3774 | lys_compile_unres_glob_erase(UTEST_LYCTX, &unres); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3775 | lys_module_free(mod, NULL); |
| 3776 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3777 | ly_in_free(in, 0); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3778 | mod = NULL; |
| 3779 | yin_ctx = NULL; |
| 3780 | |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3781 | mod = calloc(1, sizeof *mod); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3782 | mod->ctx = UTEST_LYCTX; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3783 | data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3784 | "</submodule>\n"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3785 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 3786 | assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_EINVAL); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3787 | CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3788 | lys_module_free(mod, NULL); |
| 3789 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3790 | ly_in_free(in, 0); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3791 | |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3792 | mod = calloc(1, sizeof *mod); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3793 | mod->ctx = UTEST_LYCTX; |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3794 | data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 3795 | " <yang-version value=\"1\"/>\n" |
| 3796 | " <namespace uri=\"urn:example:foo\"/>\n" |
| 3797 | " <prefix value=\"foo\"/>\n" |
| 3798 | "</module>\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3799 | "<module>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3800 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 3801 | assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_EVALID); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3802 | CHECK_LOG_CTX("Trailing garbage \"<module>\" after module, expected end-of-input.", "Line number 6."); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3803 | lys_module_free(mod, NULL); |
| 3804 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3805 | ly_in_free(in, 0); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3806 | mod = NULL; |
| 3807 | yin_ctx = NULL; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | static void |
| 3811 | test_yin_parse_submodule(void **state) |
| 3812 | { |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3813 | const char *data; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3814 | struct lys_yin_parser_ctx *yin_ctx = NULL; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3815 | struct lysp_submodule *submod = NULL; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3816 | struct ly_in *in; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3817 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3818 | lydict_insert(UTEST_LYCTX, "a", 0, &YCTX->parsed_mod->mod->name); |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 3819 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3820 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3821 | "<submodule name=\"asub\"" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3822 | " xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"" |
| 3823 | " xmlns:a=\"urn:a\">\n" |
| 3824 | " <yang-version value=\"1\"/>\n" |
| 3825 | " <belongs-to module=\"a\">\n" |
| 3826 | " <prefix value=\"a_pref\"/>\n" |
| 3827 | " </belongs-to>\n" |
| 3828 | " <include module=\"atop\"/>\n" |
| 3829 | " <feature name=\"fox\"/>\n" |
| 3830 | " <notification name=\"bar-notif\">\n" |
| 3831 | " <if-feature name=\"bar\"/>\n" |
| 3832 | " </notification>\n" |
| 3833 | " <notification name=\"fox-notif\">\n" |
| 3834 | " <if-feature name=\"fox\"/>\n" |
| 3835 | " </notification>\n" |
| 3836 | " <augment target-node=\"/a_pref:top\">\n" |
| 3837 | " <if-feature name=\"bar\"/>\n" |
| 3838 | " <container name=\"bar-sub\"/>\n" |
| 3839 | " </augment>\n" |
| 3840 | " <augment target-node=\"/top\">\n" |
| 3841 | " <container name=\"bar-sub2\"/>\n" |
| 3842 | " </augment>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3843 | "</submodule>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3844 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3845 | assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_SUCCESS); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3846 | lysp_module_free((struct lysp_module *)submod); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3847 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3848 | ly_in_free(in, 0); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3849 | yin_ctx = NULL; |
| 3850 | submod = NULL; |
| 3851 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3852 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 3853 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 3854 | " <yang-version value=\"1\"/>\n" |
| 3855 | " <belongs-to module=\"a\">\n" |
| 3856 | " <prefix value=\"a_pref\"/>\n" |
| 3857 | " </belongs-to>\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3858 | "</submodule>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3859 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3860 | assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_SUCCESS); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3861 | lysp_module_free((struct lysp_module *)submod); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3862 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3863 | ly_in_free(in, 0); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3864 | yin_ctx = NULL; |
| 3865 | submod = NULL; |
| 3866 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3867 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3868 | "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">" |
| 3869 | "</module>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3870 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3871 | assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_EINVAL); |
| 3872 | CHECK_LOG_CTX("Input data contains module in situation when a submodule is expected.", NULL); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3873 | lysp_module_free((struct lysp_module *)submod); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3874 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3875 | ly_in_free(in, 0); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3876 | yin_ctx = NULL; |
| 3877 | submod = NULL; |
| 3878 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 3879 | data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 3880 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 3881 | " <yang-version value=\"1\"/>\n" |
| 3882 | " <belongs-to module=\"a\">\n" |
| 3883 | " <prefix value=\"a_pref\"/>\n" |
| 3884 | " </belongs-to>\n" |
| 3885 | "</submodule>\n" |
| 3886 | "<submodule name=\"asub\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n" |
| 3887 | " <yang-version value=\"1\"/>\n" |
| 3888 | " <belongs-to module=\"a\">\n" |
| 3889 | " <prefix value=\"a_pref\"/>\n" |
| 3890 | " </belongs-to>\n" |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3891 | "</submodule>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3892 | assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3893 | assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_EVALID); |
| 3894 | CHECK_LOG_CTX("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input.", "Line number 8."); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3895 | lysp_module_free((struct lysp_module *)submod); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3896 | yin_parser_ctx_free(yin_ctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3897 | ly_in_free(in, 0); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3898 | yin_ctx = NULL; |
| 3899 | submod = NULL; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3900 | } |
| 3901 | |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 3902 | int |
| 3903 | main(void) |
| 3904 | { |
| 3905 | |
| 3906 | const struct CMUnitTest tests[] = { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3907 | UTEST(test_yin_match_keyword, setup, teardown), |
| 3908 | UTEST(test_yin_parse_element_generic, setup, teardown), |
| 3909 | UTEST(test_yin_parse_extension_instance, setup, teardown), |
| 3910 | UTEST(test_yin_parse_content, setup, teardown), |
| 3911 | UTEST(test_validate_value, setup, teardown), |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 3912 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3913 | UTEST(test_yin_match_argument_name), |
| 3914 | cmocka_unit_test_setup_teardown(test_enum_elem, setup, teardown), |
| 3915 | cmocka_unit_test_setup_teardown(test_bit_elem, setup, teardown), |
| 3916 | cmocka_unit_test_setup_teardown(test_meta_elem, setup, teardown), |
| 3917 | cmocka_unit_test_setup_teardown(test_import_elem, setup, teardown), |
| 3918 | cmocka_unit_test_setup_teardown(test_status_elem, setup, teardown), |
| 3919 | cmocka_unit_test_setup_teardown(test_ext_elem, setup, teardown), |
| 3920 | cmocka_unit_test_setup_teardown(test_yin_element_elem, setup, teardown), |
| 3921 | cmocka_unit_test_setup_teardown(test_yangversion_elem, setup, teardown), |
| 3922 | cmocka_unit_test_setup_teardown(test_mandatory_elem, setup, teardown), |
| 3923 | cmocka_unit_test_setup_teardown(test_argument_elem, setup, teardown), |
| 3924 | cmocka_unit_test_setup_teardown(test_base_elem, setup, teardown), |
| 3925 | cmocka_unit_test_setup_teardown(test_belongsto_elem, setup, teardown), |
| 3926 | cmocka_unit_test_setup_teardown(test_config_elem, setup, teardown), |
| 3927 | cmocka_unit_test_setup_teardown(test_default_elem, setup, teardown), |
| 3928 | cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup, teardown), |
| 3929 | cmocka_unit_test_setup_teardown(test_err_msg_elem, setup, teardown), |
| 3930 | cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup, teardown), |
| 3931 | cmocka_unit_test_setup_teardown(test_iffeature_elem, setup, teardown), |
| 3932 | cmocka_unit_test_setup_teardown(test_length_elem, setup, teardown), |
| 3933 | cmocka_unit_test_setup_teardown(test_modifier_elem, setup, teardown), |
| 3934 | cmocka_unit_test_setup_teardown(test_namespace_elem, setup, teardown), |
| 3935 | cmocka_unit_test_setup_teardown(test_pattern_elem, setup, teardown), |
| 3936 | cmocka_unit_test_setup_teardown(test_value_position_elem, setup, teardown), |
| 3937 | cmocka_unit_test_setup_teardown(test_prefix_elem, setup, teardown), |
| 3938 | cmocka_unit_test_setup_teardown(test_range_elem, setup, teardown), |
| 3939 | cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup, teardown), |
| 3940 | cmocka_unit_test_setup_teardown(test_revision_date_elem, setup, teardown), |
| 3941 | cmocka_unit_test_setup_teardown(test_unique_elem, setup, teardown), |
| 3942 | cmocka_unit_test_setup_teardown(test_units_elem, setup, teardown), |
| 3943 | cmocka_unit_test_setup_teardown(test_when_elem, setup, teardown), |
| 3944 | cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup, teardown), |
| 3945 | cmocka_unit_test_setup_teardown(test_type_elem, setup, teardown), |
| 3946 | cmocka_unit_test_setup_teardown(test_max_elems_elem, setup, teardown), |
| 3947 | cmocka_unit_test_setup_teardown(test_min_elems_elem, setup, teardown), |
| 3948 | cmocka_unit_test_setup_teardown(test_ordby_elem, setup, teardown), |
| 3949 | cmocka_unit_test_setup_teardown(test_any_elem, setup, teardown), |
| 3950 | cmocka_unit_test_setup_teardown(test_leaf_elem, setup, teardown), |
| 3951 | cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup, teardown), |
| 3952 | cmocka_unit_test_setup_teardown(test_presence_elem, setup, teardown), |
| 3953 | cmocka_unit_test_setup_teardown(test_key_elem, setup, teardown), |
| 3954 | cmocka_unit_test_setup_teardown(test_typedef_elem, setup, teardown), |
| 3955 | cmocka_unit_test_setup_teardown(test_refine_elem, setup, teardown), |
| 3956 | cmocka_unit_test_setup_teardown(test_uses_elem, setup, teardown), |
| 3957 | cmocka_unit_test_setup_teardown(test_revision_elem, setup, teardown), |
| 3958 | cmocka_unit_test_setup_teardown(test_include_elem, setup, teardown), |
| 3959 | cmocka_unit_test_setup_teardown(test_list_elem, setup, teardown), |
| 3960 | cmocka_unit_test_setup_teardown(test_notification_elem, setup, teardown), |
| 3961 | cmocka_unit_test_setup_teardown(test_grouping_elem, setup, teardown), |
| 3962 | cmocka_unit_test_setup_teardown(test_container_elem, setup, teardown), |
| 3963 | cmocka_unit_test_setup_teardown(test_case_elem, setup, teardown), |
| 3964 | cmocka_unit_test_setup_teardown(test_choice_elem, setup, teardown), |
| 3965 | cmocka_unit_test_setup_teardown(test_inout_elem, setup, teardown), |
| 3966 | cmocka_unit_test_setup_teardown(test_action_elem, setup, teardown), |
| 3967 | cmocka_unit_test_setup_teardown(test_augment_elem, setup, teardown), |
| 3968 | cmocka_unit_test_setup_teardown(test_deviate_elem, setup, teardown), |
| 3969 | cmocka_unit_test_setup_teardown(test_deviation_elem, setup, teardown), |
| 3970 | cmocka_unit_test_setup_teardown(test_module_elem, setup, teardown), |
| 3971 | cmocka_unit_test_setup_teardown(test_submodule_elem, setup, teardown), |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3972 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3973 | cmocka_unit_test_setup_teardown(test_yin_parse_module, setup, teardown), |
| 3974 | cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup, teardown), |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 3975 | }; |
| 3976 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 3977 | return cmocka_run_group_tests(tests, NULL, NULL); |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 3978 | } |