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