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