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