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