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