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