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