Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file utests.h |
| 3 | * @author Radek Iša <isa@cesnet.cz> |
| 4 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Michal Vasko | b475096 | 2022-10-06 15:33:35 +0200 | [diff] [blame] | 5 | * @author Michal Vasko <mvasko@cesnet.cz> |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 6 | * @brief this file contains macros for simplification test writing |
| 7 | * |
Michal Vasko | b475096 | 2022-10-06 15:33:35 +0200 | [diff] [blame] | 8 | * Copyright (c) 2021 - 2022 CESNET, z.s.p.o. |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 9 | * |
| 10 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 11 | * You may not use this file except in compliance with the License. |
| 12 | * You may obtain a copy of the License at |
| 13 | * |
| 14 | * https://opensource.org/licenses/BSD-3-Clause |
| 15 | */ |
| 16 | |
| 17 | #ifndef _UTESTS_H_ |
| 18 | #define _UTESTS_H_ |
| 19 | |
| 20 | #define _POSIX_C_SOURCE 200809L /* strdup */ |
| 21 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 22 | #include <setjmp.h> |
| 23 | #include <stdarg.h> |
| 24 | #include <stddef.h> |
Antonio Prcela | fe12828 | 2022-08-24 11:36:34 +0200 | [diff] [blame] | 25 | #include <stdint.h> |
Michal Vasko | 8642163 | 2021-05-04 13:11:25 +0200 | [diff] [blame] | 26 | #include <stdlib.h> |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 27 | |
| 28 | #include <cmocka.h> |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 29 | |
| 30 | #include <string.h> |
| 31 | |
| 32 | #include "libyang.h" |
Michal Vasko | b475096 | 2022-10-06 15:33:35 +0200 | [diff] [blame] | 33 | #include "plugins_exts/metadata.h" |
Radek Krejci | 3e6632f | 2021-03-22 22:08:21 +0100 | [diff] [blame] | 34 | #include "plugins_internal.h" |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 35 | #include "plugins_types.h" |
Radek Krejci | ef5f767 | 2021-04-01 17:04:12 +0200 | [diff] [blame] | 36 | #include "tests_config.h" |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 37 | #include "tree_schema_internal.h" |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * TESTS OVERVIEW |
| 41 | * |
| 42 | * To include utest's environment, just include "utests.h" in the test's source |
| 43 | * code. In case it is the main source code for a cmocka test group (there is a |
| 44 | * main() function), define _UTEST_MAIN_ before including this header. |
| 45 | * |
| 46 | * TESTS VARIABLES |
| 47 | * |
| 48 | * Checking macros use internal storage to store various variables necessary |
| 49 | * during the checking. It is possible to access these variables using the |
| 50 | * following macros: |
| 51 | * |
| 52 | * UTEST_LYCTX - libyang context |
| 53 | * UTEST_IN - input handler |
| 54 | * UTEST_OUT - output handler |
| 55 | * |
| 56 | * All these variables are cleaned with test's teardown. |
| 57 | * |
| 58 | * TESTS SETUP |
| 59 | * |
| 60 | * CMocka's CMUnitTest list definition macros (cmoka_unit_test*()) are replaced |
| 61 | * by UTEST macro with possibility to specify own setup and teardown functions: |
| 62 | * |
| 63 | * UTEST(test_func) - only implicit setup and teardown functions are used |
| 64 | * UTEST(test_func, setup) - implicit teardown but own setup |
| 65 | * UTEST(test_func, setup, teardown) - both setup and teardown are test-specific |
| 66 | * |
| 67 | * Note that the tests environment always provide (and need) internal setup and |
| 68 | * teardown functions. In case the test-specific setup or teardown are used, they |
| 69 | * are supposed to include UTEST_SETUP at the setup beginning and UTEST_TEARDOWN |
| 70 | * at the teardown end. |
| 71 | * |
| 72 | * Libyang context is part of the prepared environment. To add a schema into the |
| 73 | * context (despite it is in the test-specific setup or in test function itself), |
| 74 | * use UTEST_ADD_MODULE macro. |
| 75 | * |
| 76 | * LOGGING |
| 77 | * |
| 78 | * There are 2 macros to check content of the log from the previously called |
| 79 | * libyang function. CHECK_LOG macro test only the last error message and path |
| 80 | * stored directly via logging callback. CHECK_LOG_CTX gets error message and |
| 81 | * path from the libyang context (in case the function does not store the error |
| 82 | * information into the libyang context, the message cannot be checked this way). |
| 83 | * libyang is set to store multiple error information, so multiple couples of |
| 84 | * error message and path can be provided to be checked (the first couple |
| 85 | * corresponds to the latest error). The macro also cleanups the errors list, so |
| 86 | * it is fine to check that there is no error after succeeding successful |
| 87 | * function call. |
| 88 | */ |
| 89 | |
| 90 | /** |
| 91 | * @brief Test's context to provide common storage for various variables. |
| 92 | */ |
| 93 | struct utest_context { |
| 94 | struct ly_ctx *ctx; /**< libyang context */ |
| 95 | |
| 96 | char *err_msg; /**< Directly logged error message */ |
| 97 | char *err_path; /**< Directly logged error path */ |
| 98 | |
| 99 | struct ly_in *in; /**< Input handler */ |
| 100 | struct ly_out *out; /**< Outpu handler */ |
Michal Vasko | 8642163 | 2021-05-04 13:11:25 +0200 | [diff] [blame] | 101 | |
| 102 | char *orig_tz; /**< Original "TZ" environment variable value */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | /** |
| 106 | * @brief Shortcut to access utest_context. |
| 107 | */ |
| 108 | #define _UC ((struct utest_context *)*state) |
| 109 | |
| 110 | /** |
| 111 | * @brief libyang context provider. |
| 112 | */ |
| 113 | #define UTEST_LYCTX (_UC->ctx) |
| 114 | |
| 115 | /** |
| 116 | * @brief Context's input handler provider |
| 117 | */ |
| 118 | #define UTEST_IN (_UC->in) |
| 119 | |
| 120 | /** |
| 121 | * @brief Context's input handler provider |
| 122 | */ |
| 123 | #define UTEST_OUT (_UC->out) |
| 124 | |
| 125 | /** |
| 126 | * @brief Parse (and validate) data from the input handler as a YANG data tree. |
| 127 | * |
| 128 | * @param[in] INPUT The input data in the specified @p format to parse (and validate) |
| 129 | * @param[in] INPUT_FORMAT Format of the input data to be parsed. Can be 0 to try to detect format from the input handler. |
| 130 | * @param[in] PARSE_OPTIONS Options for parser, see @ref dataparseroptions. |
| 131 | * @param[in] VALIDATE_OPTIONS Options for the validation phase, see @ref datavalidationoptions. |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 132 | * @param[in] RET expected return status |
| 133 | * @param[out] OUT_NODE Resulting data tree built from the input data. Note that NULL can be a valid result as a |
| 134 | * representation of an empty YANG data tree. |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 135 | */ |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 136 | #define CHECK_PARSE_LYD_PARAM(INPUT, INPUT_FORMAT, PARSE_OPTIONS, VALIDATE_OPTIONS, RET, OUT_NODE) \ |
| 137 | { \ |
| 138 | LY_ERR _r = lyd_parse_data_mem(_UC->ctx, INPUT, INPUT_FORMAT, PARSE_OPTIONS, VALIDATE_OPTIONS, &OUT_NODE); \ |
| 139 | if (_r != RET) { \ |
| 140 | if (_r) { \ |
| 141 | fail_msg("%s != 0x%d; MSG: %s", #RET, _r, ly_err_last(_UC->ctx)->msg); \ |
| 142 | } else { \ |
| 143 | fail_msg("%s != 0x%d", #RET, _r); \ |
| 144 | } \ |
| 145 | } \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /** |
| 149 | * @brief Check if lyd_node and his subnodes have correct values. Print lyd_node and his sunodes int o string in json or xml format. |
| 150 | * @param[in] NODE pointer to lyd_node |
| 151 | * @param[in] TEXT expected output string in json or xml format. |
| 152 | * @param[in] FORMAT format of input text. LYD_JSON, LYD_XML |
| 153 | * @param[in] PARAM options [Data printer flags](@ref dataprinterflags). |
| 154 | */ |
| 155 | #define CHECK_LYD_STRING_PARAM(NODE, TEXT, FORMAT, PARAM) \ |
| 156 | { \ |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 157 | char *str; \ |
| 158 | LY_ERR _r = lyd_print_mem(&str, NODE, FORMAT, PARAM); \ |
| 159 | if (_r) { \ |
| 160 | fail_msg("Print err 0x%d; MSG: %s", _r, ly_err_last(_UC->ctx)->msg); \ |
| 161 | } \ |
| 162 | assert_string_equal(str, TEXT); \ |
| 163 | free(str); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | /** |
| 167 | * @brief Compare two lyd_node structure. Macro print lyd_node structure into string and then compare string. Print function use these two parameters. LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK; |
| 168 | * @param[in] NODE_1 pointer to lyd_node |
| 169 | * @param[in] NODE_2 pointer to lyd_node |
| 170 | */ |
| 171 | #define CHECK_LYD(NODE_1, NODE_2) \ |
| 172 | { \ |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 173 | char *str1; \ |
| 174 | char *str2; \ |
| 175 | assert_int_equal(LY_SUCCESS, lyd_print_mem(&str1, NODE_1, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK)); \ |
| 176 | assert_int_equal(LY_SUCCESS, lyd_print_mem(&str2, NODE_2, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK)); \ |
| 177 | assert_non_null(str1); \ |
| 178 | assert_non_null(str2); \ |
| 179 | assert_string_equal(str1, str2); \ |
| 180 | free(str1); \ |
| 181 | free(str2); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /* |
| 185 | * SUPPORT MACROS |
| 186 | */ |
| 187 | |
| 188 | /** |
| 189 | * @brief Internal macro witch assert that two given string are equal or are both null. |
| 190 | * |
| 191 | * @param[in] STRING string to check |
| 192 | * @param[in] TEXT string to compare |
| 193 | */ |
| 194 | #define CHECK_STRING(STRING, TEXT)\ |
| 195 | if (TEXT == NULL) { \ |
| 196 | assert_null(STRING); \ |
| 197 | } else { \ |
| 198 | assert_non_null(STRING); \ |
| 199 | assert_string_equal(STRING, TEXT); \ |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * @brief Internal macro witch assert that pointer is null when flag is 0. |
| 204 | * |
| 205 | * @param[in] POINTER pointer to check |
| 206 | * @param[in] FLAG 0 -> pointer is NULL, 1 -> pointer is not null |
| 207 | */ |
| 208 | #define CHECK_POINTER(POINTER, FLAG) \ |
| 209 | assert_true(FLAG == 0 ? POINTER == NULL : POINTER != NULL) |
| 210 | |
| 211 | /** |
| 212 | * @brief Internal macro check size of [sized array](@ref sizedarrays)'s |
| 213 | * |
| 214 | * @param[in] ARRAY pointer to [sized array](@ref sizedarrays) |
| 215 | * @param[in] SIZE expected [sized array](@ref sizedarrays) size of array |
| 216 | */ |
| 217 | #define CHECK_ARRAY(ARRAY, SIZE) \ |
| 218 | assert_true((SIZE == 0) ? \ |
| 219 | (ARRAY == NULL) : \ |
| 220 | (ARRAY != NULL && SIZE == LY_ARRAY_COUNT(ARRAY))); |
| 221 | |
| 222 | /* |
| 223 | * LIBYANG NODE CHECKING |
| 224 | */ |
| 225 | |
| 226 | /** |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 227 | * @brief check compileted type |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 228 | * |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 229 | * @param[in] NODE pointer to lysc_type value |
| 230 | * @param[in] TYPE expected type [LY_DATA_TYPE](@ref LY_DATA_TYPE) |
| 231 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list |
| 232 | */ |
| 233 | #define CHECK_LYSC_TYPE(NODE, TYPE, EXTS) \ |
| 234 | assert_non_null(NODE); \ |
| 235 | assert_int_equal((NODE)->basetype, TYPE); \ |
| 236 | CHECK_ARRAY((NODE)->exts, EXTS); \ |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 237 | assert_ptr_equal((NODE)->plugin, lyplg_type_plugin_find("", NULL, ly_data_type2str[TYPE])) |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 238 | |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 239 | /** |
| 240 | * @brief check compileted numeric type |
| 241 | * |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 242 | * @param[in] NODE pointer to lysc_type_num value |
| 243 | * @param[in] TYPE expected type [LY_DATA_TYPE](@ref LY_DATA_TYPE) |
| 244 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list |
| 245 | * @warning only integer types INT, UINT, NUM |
| 246 | */ |
| 247 | #define CHECK_LYSC_TYPE_NUM(NODE, TYPE, EXTS, RANGE) \ |
| 248 | CHECK_LYSC_TYPE(NODE, TYPE, EXTS);\ |
| 249 | CHECK_POINTER((NODE)->range, RANGE) |
| 250 | |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 251 | /** |
| 252 | * @brief check compiled string type |
| 253 | * |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 254 | * @param[in] NODE pointer to lysc_type_num value |
| 255 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list |
| 256 | * @param[in] LENGTH 0 -> node dosnt have length limitation, 1 -> node have length limitation |
| 257 | * @param[in] PATTERNS expected number of patterns [sized array](@ref sizedarrays) |
| 258 | * @warning only integer types INT, UINT, NUM |
| 259 | */ |
| 260 | #define CHECK_LYSC_TYPE_STR(NODE, EXTS, LENGTH, PATTERNS) \ |
| 261 | CHECK_LYSC_TYPE(NODE, LY_TYPE_STRING, EXTS); \ |
| 262 | CHECK_POINTER((NODE)->length, LENGTH); \ |
| 263 | CHECK_ARRAY((NODE)->patterns, PATTERNS) |
| 264 | |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 265 | /** |
| 266 | * @brief check compiled bits type |
| 267 | * |
Radek Iša | ded3105 | 2021-03-10 13:22:53 +0100 | [diff] [blame] | 268 | * @param[in] NODE pointer to lysc_type_num value |
| 269 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list |
| 270 | * @param[in] BITS expected number of bits |
| 271 | * @warning only integer types INT, UINT, NUM |
| 272 | */ |
| 273 | #define CHECK_LYSC_TYPE_BITS(NODE, EXTS, BITS) \ |
| 274 | CHECK_LYSC_TYPE(NODE, LY_TYPE_BITS, EXTS); \ |
| 275 | CHECK_ARRAY((NODE)->bits, BITS) |
| 276 | |
Radek Iša | ded3105 | 2021-03-10 13:22:53 +0100 | [diff] [blame] | 277 | #define CHECK_LYSC_TYPE_BITENUM_ITEM(NODE, POSITION, DSC, EXTS, FLAGS, NAME, REF)\ |
| 278 | assert_non_null(NODE); \ |
| 279 | assert_int_equal((NODE)->position, POSITION); \ |
| 280 | CHECK_STRING((NODE)->dsc, DSC); \ |
| 281 | CHECK_ARRAY((NODE)->exts, EXTS); \ |
| 282 | assert_int_equal((NODE)->flags, FLAGS); \ |
| 283 | CHECK_STRING((NODE)->name, NAME); \ |
| 284 | CHECK_STRING((NODE)->ref, REF) \ |
| 285 | |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 286 | /** |
| 287 | * @brief check range |
| 288 | * |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 289 | * @param[in] NODE pointer to lysc_range value |
| 290 | * @param[in] DSC expected descriptin (string) |
| 291 | * @param[in] EAPPTAG expected string reprezenting error-app-tag value |
| 292 | * @param[in] EMSG expected string reprezenting error message |
| 293 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list |
| 294 | * @param[in] PARTS expected [sized array](@ref sizedarrays) number of rang limitations |
| 295 | * @param[in] REF expected reference |
| 296 | */ |
| 297 | #define CHECK_LYSC_RANGE(NODE, DSC, EAPPTAG, EMSG, EXTS, PARTS, REF) \ |
| 298 | assert_non_null(NODE); \ |
| 299 | CHECK_STRING((NODE)->dsc, DSC); \ |
| 300 | CHECK_STRING((NODE)->eapptag, EAPPTAG); \ |
| 301 | CHECK_STRING((NODE)->emsg, EMSG); \ |
| 302 | CHECK_ARRAY((NODE)->exts, EXTS); \ |
| 303 | CHECK_ARRAY((NODE)->parts, PARTS); \ |
| 304 | CHECK_STRING((NODE)->ref, REF) |
| 305 | |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 306 | /** |
| 307 | * @brief check pattern |
| 308 | * |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 309 | * @param[in] NODE pointer to lysc_pattern value |
| 310 | * @param[in] DSC expected descriptin (string) |
| 311 | * @param[in] EAPPTAG expected string reprezenting error-app-tag value |
| 312 | * @param[in] EMSG expected string reprezenting error message |
| 313 | * @param[in] EEXPR expected string reprezenting original, not compiled, regular expression |
| 314 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list |
| 315 | * @param[in] INVERTED if regular expression is inverted. |
| 316 | * @param[in] REF expected reference |
| 317 | */ |
| 318 | #define CHECK_LYSC_PATTERN(NODE, DSC, EAPPTAG, EMSG, EXPR, EXTS, INVERTED, REF) \ |
| 319 | assert_non_null(NODE); \ |
| 320 | assert_non_null((NODE)->code); \ |
| 321 | CHECK_STRING((NODE)->dsc, DSC); \ |
| 322 | CHECK_STRING((NODE)->eapptag, EAPPTAG); \ |
| 323 | CHECK_STRING((NODE)->emsg, EMSG); \ |
| 324 | CHECK_STRING((NODE)->expr, EXPR); \ |
| 325 | CHECK_ARRAY((NODE)->exts, EXTS); \ |
| 326 | assert_int_equal((NODE)->inverted, INVERTED); \ |
| 327 | CHECK_STRING((NODE)->ref, REF) |
| 328 | |
| 329 | /** |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 330 | * @brief assert that lysp_action_inout structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 331 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 332 | * @param[in] NODE pointer to lysp_action_inout variable |
| 333 | * @param[in] DATA 0 -> check if pointer to data is NULL, 1 -> check if pointer to data is not null |
| 334 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list |
| 335 | * @param[in] GROUPINGS expected [sized array](@ref sizedarrays) size of grouping list |
| 336 | * @param[in] MUSTS expected [sized array](@ref sizedarrays) size of must restriction list |
| 337 | * @param[in] NODETYPE node type. LYS_INPUT or LYS_OUTPUT |
| 338 | * @param[in] PARENT 0 -> check if node is root, 1 -> check if node is not root |
| 339 | * @param[in] TYPEDEFS expected [sized array](@ref sizedarrays) size of typedefs list |
| 340 | */ |
| 341 | #define CHECK_LYSP_ACTION_INOUT(NODE, DATA, EXTS, GROUPINGS, MUSTS, NODETYPE, PARENT, TYPEDEFS) \ |
| 342 | assert_non_null(NODE); \ |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 343 | CHECK_POINTER((NODE)->child, DATA); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 344 | CHECK_ARRAY((NODE)->exts, EXTS); \ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 345 | CHECK_POINTER((NODE)->groupings, GROUPINGS); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 346 | CHECK_ARRAY((NODE)->musts, MUSTS); \ |
| 347 | assert_int_equal((NODE)->nodetype, NODETYPE); \ |
| 348 | CHECK_POINTER((NODE)->parent, PARENT); \ |
| 349 | CHECK_ARRAY((NODE)->typedefs, TYPEDEFS); |
| 350 | |
| 351 | /** |
| 352 | * @brief assert that lysp_action structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 353 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 354 | * @param[in] NODE pointer to lysp_action variable |
| 355 | * @param[in] DSC expected description |
| 356 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extension list |
| 357 | * @param[in] FLAGS expected [schema node flags](@ref snodeflags) |
| 358 | * @param[in] GROUPINGS expected [sized array](@ref sizedarrays) size of grouping list |
| 359 | * @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of if-feature expressions list |
| 360 | * @param[in] INPUT_* ::LYSP_ACTION_INOUT_CHECK |
| 361 | * @param[in] NAME expected name |
| 362 | * @param[in] NODETYPE node type. LYS_RPC or LYS_ACTION |
| 363 | * @param[in] OUTPUT_* ::LYSP_ACTION_INOUT_CHECK |
| 364 | * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root |
| 365 | * @param[in] REF expected reference |
| 366 | * @param[in] TYPEDEFS expected [sized array](@ref sizedarrays) size of list of typedefs |
| 367 | */ |
| 368 | #define CHECK_LYSP_ACTION(NODE, DSC, EXTS, FLAGS, GROUPINGS, IFFEATURES, \ |
| 369 | INPUT_DATA, INPUT_EXTS, INPUT_GROUPINGS, INPUT_MUSTS, \ |
| 370 | INPUT_PARENT, INPUT_TYPEDEFS, \ |
| 371 | NAME, NODETYPE, \ |
| 372 | OUTPUT_DATA, OUTPUT_EXTS, OUTPUT_GROUPINGS, OUTPUT_MUSTS, \ |
| 373 | OUTPUT_PARENT, OUTPUT_TYPEDEFS, \ |
| 374 | PARENT, REF, TYPEDEFS) \ |
| 375 | assert_non_null(NODE); \ |
| 376 | CHECK_STRING((NODE)->dsc, DSC); \ |
| 377 | CHECK_ARRAY((NODE)->exts, EXTS); \ |
| 378 | assert_int_equal((NODE)->flags, FLAGS); \ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 379 | CHECK_POINTER((NODE)->groupings, GROUPINGS); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 380 | CHECK_ARRAY((NODE)->iffeatures, IFFEATURES); \ |
| 381 | CHECK_LYSP_ACTION_INOUT(&((NODE)->input), INPUT_DATA, INPUT_EXTS, INPUT_GROUPINGS, \ |
| 382 | INPUT_MUSTS, LYS_INPUT, INPUT_PARENT, INPUT_TYPEDEFS); \ |
| 383 | assert_string_equal((NODE)->name, NAME); \ |
| 384 | assert_int_equal((NODE)->nodetype, NODETYPE); \ |
| 385 | CHECK_LYSP_ACTION_INOUT(&((NODE)->output), OUTPUT_DATA, OUTPUT_EXTS, OUTPUT_GROUPINGS, \ |
| 386 | OUTPUT_MUSTS, LYS_OUTPUT, OUTPUT_PARENT, OUTPUT_TYPEDEFS); \ |
| 387 | CHECK_POINTER((NODE)->parent, PARENT); \ |
| 388 | CHECK_STRING((NODE)->ref, REF); \ |
| 389 | CHECK_ARRAY((NODE)->typedefs, TYPEDEFS) \ |
| 390 | |
| 391 | /** |
| 392 | * @brief assert that lysp_when structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 393 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 394 | * @param[in] NODE pointer to lysp_when variable |
| 395 | * @param[in] COND expected string specifid condition |
| 396 | * @param[in] DSC expected string description statement |
| 397 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension array |
| 398 | * @param[in] REF expected string reference |
| 399 | */ |
| 400 | #define CHECK_LYSP_WHEN(NODE, COND, DSC, EXTS, REF) \ |
| 401 | assert_non_null(NODE); \ |
| 402 | assert_string_equal((NODE)->cond, COND); \ |
| 403 | CHECK_STRING((NODE)->dsc, DSC); \ |
| 404 | CHECK_ARRAY((NODE)->exts, EXTS); \ |
| 405 | if (REF == NULL) { \ |
| 406 | assert_null((NODE)->ref); \ |
| 407 | } else { \ |
| 408 | assert_non_null((NODE)->ref); \ |
| 409 | assert_string_equal((NODE)->ref, REF); \ |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * @brief assert that lysp_restr structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 414 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 415 | * @param[in] NODE pointer to lysp_restr variable |
| 416 | * @param[in] ARG_STR expected string. The restriction expression/value |
| 417 | * @param[in] DSC expected descrition |
| 418 | * @param[in] EAPPTAG expected string reprezenting error-app-tag value |
| 419 | * @param[in] EMSG expected string reprezenting error message |
| 420 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension array |
| 421 | * @param[in] REF expected reference |
| 422 | */ |
| 423 | |
| 424 | #define CHECK_LYSP_RESTR(NODE, ARG_STR, DSC, EAPPTAG, EMSG, EXTS, REF) \ |
| 425 | assert_non_null(NODE); \ |
| 426 | assert_non_null((NODE)->arg.mod); \ |
| 427 | assert_string_equal((NODE)->arg.str, ARG_STR); \ |
| 428 | CHECK_STRING((NODE)->dsc, DSC); \ |
| 429 | CHECK_STRING((NODE)->eapptag, EAPPTAG); \ |
| 430 | CHECK_STRING((NODE)->emsg, EMSG); \ |
| 431 | CHECK_ARRAY((NODE)->exts, EXTS); \ |
| 432 | CHECK_STRING((NODE)->ref, REF); |
| 433 | |
| 434 | /** |
| 435 | * @brief assert that lysp_import structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 436 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 437 | * @param[in] NODE pointer to lysp_import variable |
| 438 | * @param[in] DSC expected description or NULL |
| 439 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extensions |
| 440 | * @param[in] NAME expected name of imported module |
| 441 | * @param[in] PREFIX expected prefix for the data from the imported schema |
| 442 | * @param[in] REF expected reference |
| 443 | * @prame[in] REV expected reprezenting date in format "11-10-2020" |
| 444 | */ |
| 445 | #define CHECK_LYSP_IMPORT(NODE, DSC, EXTS, NAME, PREFIX, REF, REV) \ |
| 446 | assert_non_null(NODE); \ |
| 447 | CHECK_STRING((NODE)->dsc, DSC); \ |
| 448 | CHECK_ARRAY((NODE)->exts, EXTS); \ |
| 449 | /*assert_non_null((NODE)->module); // ?? it is mandatory but in some test it doesnt work */ \ |
| 450 | assert_string_equal((NODE)->name, NAME); \ |
| 451 | assert_string_equal((NODE)->prefix, PREFIX); \ |
| 452 | CHECK_STRING((NODE)->ref, REF); \ |
| 453 | CHECK_STRING((NODE)->rev, REV); \ |
| 454 | |
| 455 | /** |
| 456 | * @brief assert that lysp_ext structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 457 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 458 | * @param[in] NODE pointer to lysp_ext_instance variable |
Radek Krejci | 9f87b0c | 2021-03-05 14:45:26 +0100 | [diff] [blame] | 459 | * @param[in] ARGNAME expected argument name |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 460 | * @param[in] COMPILED 0 -> compiled data dosnt exists, 1 -> compiled data exists |
| 461 | * @param[in] DSC expected string reprezent description |
| 462 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension instances |
| 463 | * @param[in] FLAGS expected LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags) |
| 464 | * @param[in] NAME expected name |
| 465 | * @param[in] REF expected ref |
| 466 | */ |
Radek Krejci | 9f87b0c | 2021-03-05 14:45:26 +0100 | [diff] [blame] | 467 | #define CHECK_LYSP_EXT(NODE, ARGNAME, COMPILED, DSC, EXTS, FLAGS, NAME, REF) \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 468 | assert_non_null(NODE); \ |
Radek Krejci | 9f87b0c | 2021-03-05 14:45:26 +0100 | [diff] [blame] | 469 | CHECK_STRING((NODE)->argname, ARGNAME); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 470 | CHECK_POINTER((NODE)->compiled, COMPILED); \ |
| 471 | CHECK_STRING((NODE)->dsc, DSC); \ |
| 472 | CHECK_ARRAY((NODE)->exts, EXTS); \ |
| 473 | assert_int_equal((NODE)->flags, FLAGS); \ |
| 474 | assert_string_equal((NODE)->name, NAME); \ |
| 475 | CHECK_STRING((NODE)->ref, REF); |
| 476 | |
| 477 | /** |
| 478 | * @brief assert that lysp_ext_instance structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 479 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 480 | * @param[in] NODE pointer to lysp_ext_instance variable |
| 481 | * @param[in] ARGUMENT expected optional value of the extension's argument |
| 482 | * @param[in] CHILD 0 -> node doesnt have child, 1 -> node have children |
Radek Krejci | ab43086 | 2021-03-02 20:13:40 +0100 | [diff] [blame] | 483 | * @param[in] PARENT_STMT expected value identifying placement of the extension instance |
| 484 | * @param[in] PARENT_STMT_INDEX expected indentifi index |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 485 | * @param[in] FORMAT expected format |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 486 | */ |
Radek Krejci | 85ac831 | 2021-03-03 20:21:33 +0100 | [diff] [blame] | 487 | #define CHECK_LYSP_EXT_INSTANCE(NODE, ARGUMENT, CHILD, PARENT_STMT, PARENT_STMT_INDEX, NAME, FORMAT) \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 488 | assert_non_null(NODE); \ |
| 489 | CHECK_STRING((NODE)->argument, ARGUMENT); \ |
| 490 | CHECK_POINTER((NODE)->child, CHILD); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 491 | /*assert_int_equal((NODE)->flags, LYS_INTERNAL);*/ \ |
Radek Krejci | ab43086 | 2021-03-02 20:13:40 +0100 | [diff] [blame] | 492 | assert_int_equal((NODE)->parent_stmt, PARENT_STMT); \ |
| 493 | assert_int_equal((NODE)->parent_stmt_index, PARENT_STMT_INDEX); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 494 | assert_string_equal((NODE)->name, NAME); \ |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 495 | assert_int_equal((NODE)->format, FORMAT); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 496 | |
| 497 | /** |
| 498 | * @brief assert that lysp_stmt structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 499 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 500 | * @param[in] NODE pointer to lysp_stmt variable |
| 501 | * @param[in] ARG expected statemet argumet |
| 502 | * @param[in] CHILD 0 -> node doesnt have child, 1 -> node have children |
| 503 | * @param[in] FLAGS expected statement flags, can be set to LYS_YIN_ATTR |
| 504 | * @param[in] KW expected numeric respresentation of the stmt value |
| 505 | * @param[in] NEXT 0 -> pointer is NULL, 1 -> pointer is not null |
| 506 | * @param[in] STMS expected identifier of the statement |
| 507 | */ |
| 508 | #define CHECK_LYSP_STMT(NODE, ARG, CHILD, FLAGS, KW, NEXT, STMT) \ |
| 509 | assert_non_null(NODE); \ |
| 510 | CHECK_STRING((NODE)->arg, ARG); \ |
| 511 | CHECK_POINTER((NODE)->child, CHILD); \ |
| 512 | assert_int_equal((NODE)->flags, FLAGS); \ |
| 513 | assert_int_equal((NODE)->kw, KW); \ |
| 514 | CHECK_POINTER((NODE)->next, NEXT); \ |
| 515 | assert_string_equal((NODE)->stmt, STMT); \ |
| 516 | |
| 517 | /** |
| 518 | * @brief assert that lysp_type_enum structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 519 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 520 | * @param[in] NODE pointer to lysp_type_enum variable |
| 521 | * @param[in] DSC expected description |
| 522 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances |
| 523 | * @param[in] FLAGS only LYS_STATUS_ and LYS_SET_VALUE values are allowed |
| 524 | * @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of list of the extension instances |
| 525 | * @param[in] NAME expected name |
| 526 | * @param[in] REF expected reference statement |
| 527 | * @param[in] VALUE expected enum's value or bit's position |
| 528 | */ |
| 529 | #define CHECK_LYSP_TYPE_ENUM(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, REF, VALUE) \ |
| 530 | assert_non_null(NODE); \ |
| 531 | CHECK_STRING((NODE)->dsc, DSC); \ |
| 532 | CHECK_ARRAY((NODE)->exts, EXTS); \ |
| 533 | assert_int_equal((NODE)->flags, FLAGS); \ |
| 534 | CHECK_ARRAY((NODE)->iffeatures, IFFEATURES); \ |
| 535 | CHECK_STRING((NODE)->name, NAME); \ |
| 536 | CHECK_STRING((NODE)->ref, REF); \ |
| 537 | assert_int_equal(VALUE, (NODE)->value); |
| 538 | |
| 539 | /** |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 540 | * @brief assert that lysp_type_enum structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 541 | * |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 542 | * @param[in] NODE pointer to lysp_type variable |
| 543 | * @param[in] BASES expected [sized array](@ref sizedarrays) size of list of indentifiers |
| 544 | * @param[in] BITS expected [sized array](@ref sizedarrays) size of list of bits |
| 545 | * @param[in] COMPILED 0 -> pointer to compiled type is null, 1 -> pointer to compilet type is valid |
| 546 | * @param[in] ENUMS expected [sized array](@ref sizedarrays) size of list of enums-stmts |
| 547 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension instances |
| 548 | * @param[in] FLAGS expected flags |
| 549 | * @param[in] FRACTION_DIGITS expected number of fraction digits decimal64 |
| 550 | * @param[in] LENGTH expected 0 -> there isnt any restriction on length, 1 -> type is restricted on length (string, binary) |
| 551 | * @param[in] NAME expected name of type |
| 552 | * @param[in] PATH 0 -> no pointer to parsed path, 1 -> pointer to parsed path is valid |
| 553 | * @param[in] PATTERNS expected [sized array](@ref sizedarrays) size of list of patterns for string |
| 554 | * @param[in] PMOD expected submodule where type is defined 0 -> pointer is null, 1 -> pointer is not null |
| 555 | * @param[in] RANGE expected [sized array](@ref sizedarrays) size of list of range restriction |
| 556 | * @param[in] REQUIRE_INSTANCE expected require instance flag |
| 557 | * @param[in] TYPES expected [sized array](@ref sizedarrays) size of list of sub-types |
| 558 | */ |
| 559 | #define CHECK_LYSP_TYPE(NODE, BASES, BITS, COMPILED, ENUMS, EXTS, FLAGS, FRACTIONS_DIGITS, \ |
| 560 | LENGTH, NAME, PATH, PATTERNS, PMOD, RANGE, REQUIRE_INSTANCE, TYPES) \ |
| 561 | assert_non_null(NODE);\ |
| 562 | CHECK_ARRAY((NODE)->bases, BASES); \ |
| 563 | CHECK_ARRAY((NODE)->bits, BITS); \ |
| 564 | CHECK_POINTER((NODE)->compiled, COMPILED); \ |
| 565 | CHECK_ARRAY((NODE)->enums, ENUMS); \ |
| 566 | CHECK_ARRAY((NODE)->exts, EXTS); \ |
| 567 | assert_int_equal((NODE)->flags, FLAGS); \ |
| 568 | assert_int_equal((NODE)->fraction_digits, FRACTIONS_DIGITS); \ |
| 569 | CHECK_POINTER((NODE)->length, LENGTH); \ |
| 570 | CHECK_STRING((NODE)->name, NAME); \ |
| 571 | CHECK_POINTER((NODE)->path, PATH); \ |
| 572 | CHECK_ARRAY((NODE)->patterns, PATTERNS); \ |
| 573 | CHECK_POINTER((NODE)->pmod, PMOD); \ |
| 574 | CHECK_POINTER((NODE)->range, RANGE); \ |
| 575 | assert_int_equal((NODE)->require_instance, REQUIRE_INSTANCE); \ |
| 576 | CHECK_ARRAY((NODE)->types , TYPES) |
| 577 | |
| 578 | /** |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 579 | * @brief assert that lysp_node structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 580 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 581 | * @param[in] NODE pointer to lysp_node variable |
| 582 | * @param[in] DSC expected description statement |
| 583 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances |
| 584 | * @param[in] FLAGS [schema node flags](@ref snodeflags) |
| 585 | * @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of list of the extension instances |
| 586 | * @param[in] NAME expected name |
| 587 | * @param[in] NEXT 0 pointer is null, 1 pointer is not null |
| 588 | * @param[in] NODETYPE node type LYS_UNKNOWN, LYS_CONTAINER, LYS_CHOICE, LYS_LEAF, LYS_LEAFLIST, |
| 589 | * LYS_LIST, LYS_ANYXML, LYS_ANYDATA, LYS_CASE, LYS_RPC, LYS_ACTION, LYS_NOTIF, |
| 590 | * LYS_USES, LYS_INPUT, LYS_OUTPUT, LYS_GROUPING, LYS_AUGMENT |
| 591 | * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root |
| 592 | * @param[in] REF expected reference statement |
| 593 | * @param[in] WHEN 0-> pointer is null, 1 -> pointer is not null |
| 594 | */ |
| 595 | #define CHECK_LYSP_NODE(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, NEXT, NODETYPE, PARENT, REF, WHEN) \ |
| 596 | assert_non_null(NODE); \ |
| 597 | CHECK_STRING((NODE)->dsc, DSC); \ |
| 598 | CHECK_ARRAY((NODE)->exts, EXTS); \ |
| 599 | assert_int_equal((NODE)->flags, FLAGS); \ |
| 600 | CHECK_ARRAY((NODE)->iffeatures, IFFEATURES); \ |
| 601 | CHECK_STRING((NODE)->name, NAME); \ |
| 602 | CHECK_POINTER((NODE)->next, NEXT); \ |
| 603 | assert_int_equal((NODE)->nodetype, NODETYPE); \ |
| 604 | CHECK_POINTER((NODE)->parent, PARENT); \ |
| 605 | CHECK_STRING((NODE)->ref, REF); \ |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 606 | CHECK_POINTER(lysp_node_when((struct lysp_node *)NODE), WHEN); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 607 | |
| 608 | /** |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 609 | * @brief assert that lysp_node structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 610 | * |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 611 | * @param[in] NODE pointer to lysp_node variable |
| 612 | * @param[in] DSC expected description statement |
| 613 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances |
| 614 | * @param[in] FLAGS [schema node flags](@ref snodeflags) |
| 615 | * @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of list of the extension instances |
| 616 | * @param[in] NAME expected name |
| 617 | * @param[in] NEXT 0 pointer is null, 1 pointer is not null |
| 618 | * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root |
| 619 | * @param[in] REF expected reference statement |
| 620 | * @param[in] WHEN 0-> pointer is null, 1 -> pointer is not null |
| 621 | * @param[in] MUSTS expected [sized array](@ref sizedarrays) size of list of must restriction |
| 622 | * @param[in] UNITS expected string reprezenting units |
| 623 | * @param[in] DFLT 0-> node dosn't have default value. 1 -> node have default value |
| 624 | */ |
| 625 | #define CHECK_LYSP_NODE_LEAF(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, NEXT, \ |
| 626 | PARENT, REF, WHEN, MUSTS, UNITS, DFLT) \ |
| 627 | CHECK_LYSP_NODE(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, NEXT, LYS_LEAF, PARENT, REF, WHEN); \ |
| 628 | CHECK_ARRAY((NODE)->musts, MUSTS); \ |
| 629 | CHECK_STRING((NODE)->units, UNITS); \ |
| 630 | CHECK_STRING((NODE)->dflt.str, DFLT); |
| 631 | |
| 632 | /** |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 633 | * @brief assert that lysc_notif structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 634 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 635 | * @param[in] NODE pointer to lysp_notif variable |
| 636 | * @param[in] DATA 0 pointer is null, 1 pointer is not null |
| 637 | * @param[in] DSC expected description |
| 638 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances |
| 639 | * @param[in] FLAGS [schema node flags](@ref snodeflags) |
| 640 | * @param[in] MODULE 0 pointer is null, 1 pointer is not null |
| 641 | * @param[in] MUSTS expected [sized array](@ref sizedarrays) size of list of must restriction |
| 642 | * @param[in] NAME expected name |
| 643 | * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root |
| 644 | * @param[in] PRIV 0-> pointer is null, 1-> pointer is not null |
| 645 | * @param[in] REF expected reference |
| 646 | * @param[in] WHEN expected [sized array](@ref sizedarrays) size of list of pointers to when statements |
| 647 | */ |
| 648 | #define CHECK_LYSC_NOTIF(NODE, DATA, DSC, EXTS, FLAGS, MODULE, MUSTS, NAME, PARENT, PRIV, REF, WHEN) \ |
| 649 | assert_non_null(NODE); \ |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 650 | CHECK_POINTER((NODE)->child, DATA); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 651 | CHECK_STRING((NODE)->dsc, DSC); \ |
| 652 | CHECK_ARRAY((NODE)->exts, EXTS); \ |
| 653 | assert_int_equal((NODE)->flags, FLAGS); \ |
| 654 | CHECK_POINTER((NODE)->module, MODULE); \ |
| 655 | CHECK_ARRAY((NODE)->musts, MUSTS); \ |
| 656 | assert_string_equal((NODE)->name, NAME); \ |
| 657 | assert_int_equal((NODE)->nodetype, LYS_NOTIF); \ |
| 658 | CHECK_POINTER((NODE)->parent, PARENT); \ |
| 659 | CHECK_POINTER((NODE)->priv, PRIV); \ |
| 660 | CHECK_STRING((NODE)->ref, REF); \ |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 661 | CHECK_ARRAY(lysc_node_when((const struct lysc_node *)NODE), WHEN); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 662 | |
| 663 | /** |
| 664 | * @brief assert that lysc_action_inout structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 665 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 666 | * @param[in] NODE pointer to lysp_notif variable |
| 667 | * @param[in] DATA 0 pointer is null, 1 pointer is not null |
| 668 | * @param[in] MUST expected [sized array](@ref sizedarrays) size of list of must restrictions |
| 669 | * @param[in] NODETYPE LYS_INPUT or LYS_OUTPUT |
| 670 | */ |
| 671 | #define CHECK_LYSC_ACTION_INOUT(NODE, DATA, MUST, NODETYPE) \ |
| 672 | assert_non_null(NODE); \ |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 673 | CHECK_POINTER((NODE)->child, DATA); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 674 | CHECK_ARRAY((NODE)->musts, MUST); \ |
| 675 | assert_int_equal((NODE)->nodetype, NODETYPE); |
| 676 | |
| 677 | /** |
| 678 | * @brief assert that lysc_action structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 679 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 680 | * @param[in] NODE pointer to lysp_action variable |
| 681 | * @param[in] DSC string description statement |
| 682 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances |
| 683 | * @param[in] FLAGS [schema node flags](@ref snodeflags) |
| 684 | * @param[in] INPUT_DATA 0 pointer is null, 1 pointer is not null |
| 685 | * @param[in] INPUT_MUST expected [sized array](@ref sizedarrays) size of input list of must restrictions |
| 686 | * @param[in] INPUT_EXTS expected [sized array](@ref sizedarrays) size of the input extension instances of input |
| 687 | * @param[in] MODULE 0 pointer is null, 1 pointer is not null |
| 688 | * @param[in] NAME expected name |
| 689 | * @param[in] NODETYPE LYS_RPC, LYS_ACTION |
| 690 | * @param[in] OUTPUT_DATA 0 pointer is null, 1 pointer is not null |
| 691 | * @param[in] OUTPUT_MUST expected [sized array](@ref sizedarrays) size of output list of must restrictions |
| 692 | * @param[in] OUTPUT_EXTS expected [sized array](@ref sizedarrays) size of the output extension instances of input |
| 693 | * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root |
| 694 | * @param[in] PRIV 0-> pointer is null, 1-> pointer is not null |
| 695 | * @param[in] REF expected reference |
| 696 | * @param[in] WHEN expected [sized array](@ref sizedarrays) size of list of pointers to when statements |
| 697 | */ |
| 698 | #define CHECK_LYSC_ACTION(NODE, DSC, EXTS, FLAGS, INPUT_DATA, INPUT_MUST, INPUT_EXTS, MODULE, NAME, NODETYPE, \ |
| 699 | OUTPUT_DATA, OUTPUT_MUST, OUTPUT_EXTS, PARENT, PRIV, REF, WHEN) \ |
| 700 | assert_non_null(NODE); \ |
| 701 | CHECK_STRING((NODE)->dsc, DSC); \ |
| 702 | CHECK_ARRAY((NODE)->exts, EXTS); \ |
| 703 | assert_int_equal((NODE)->flags, FLAGS); \ |
| 704 | CHECK_LYSC_ACTION_INOUT(&(NODE)->input, INPUT_DATA, INPUT_MUST, LYS_INPUT); \ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 705 | CHECK_ARRAY((NODE)->input.exts, INPUT_EXTS); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 706 | CHECK_POINTER((NODE)->module, MODULE); \ |
| 707 | assert_string_equal((NODE)->name, NAME); \ |
| 708 | assert_int_equal((NODE)->nodetype, NODETYPE); \ |
| 709 | CHECK_LYSC_ACTION_INOUT(&(NODE)->output, OUTPUT_DATA, OUTPUT_MUST, LYS_OUTPUT); \ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 710 | CHECK_ARRAY((NODE)->output.exts, OUTPUT_EXTS); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 711 | CHECK_POINTER((NODE)->parent, PARENT); \ |
| 712 | CHECK_POINTER((NODE)->priv, PRIV); \ |
| 713 | CHECK_STRING((NODE)->ref, REF); \ |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 714 | CHECK_ARRAY(lysc_node_when((const struct lysc_node *)NODE), WHEN); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 715 | |
| 716 | /** |
| 717 | * @brief assert that lysc_node structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 718 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 719 | * @param[in] NODE pointer to lysc_node variable |
| 720 | * @param[in] DSC expected description |
| 721 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances |
| 722 | * @param[in] FLAGS [schema node flags](@ref snodeflags) |
| 723 | * @param[in] MODULE 0 pointer is null, 1 pointer is not null |
| 724 | * @param[in] NAME expected name |
| 725 | * @param[in] NEXT 0 pointer is null, 1 pointer is not null |
| 726 | * @param[in] NODETYPE type of the node LYS_UNKNOWN, LYS_CONTAINER, LYS_CHOICE, LYS_LEAF, |
| 727 | * LYS_LEAFLIST, LYS_LIST, LYS_ANYXML, LYS_ANYDATA, LYS_CASE, LYS_RPC, |
| 728 | * LYS_ACTION, LYS_NOTIF, LYS_USES, LYS_INPUT, LYS_OUTPUT, LYS_GROUPING, |
| 729 | * LYS_AUGMENT |
| 730 | * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root |
| 731 | * @param[in] PRIV 0-> pointer is null, 1-> pointer is not null |
| 732 | * @param[in] REF expected reference |
| 733 | * @param[in] WHEN expected [sized array](@ref sizedarrays) size of list of pointers to when statements |
| 734 | */ |
| 735 | #define CHECK_LYSC_NODE(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, NODETYPE, PARENT, PRIV, REF, WHEN) \ |
| 736 | assert_non_null(NODE); \ |
| 737 | CHECK_STRING((NODE)->dsc, DSC); \ |
| 738 | CHECK_ARRAY((NODE)->exts, EXTS); \ |
| 739 | assert_int_equal((NODE)->flags, FLAGS); \ |
| 740 | CHECK_POINTER((NODE)->module, MODULE); \ |
| 741 | assert_string_equal((NODE)->name, NAME); \ |
| 742 | CHECK_POINTER((NODE)->next, NEXT); \ |
| 743 | assert_int_equal((NODE)->nodetype, NODETYPE); \ |
| 744 | CHECK_POINTER((NODE)->parent, PARENT); \ |
| 745 | assert_non_null((NODE)->prev); \ |
| 746 | CHECK_POINTER((NODE)->priv, PRIV); \ |
| 747 | CHECK_STRING((NODE)->ref, REF); \ |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 748 | CHECK_ARRAY(lysc_node_when((const struct lysc_node *)NODE), WHEN); |
| 749 | |
| 750 | /** |
| 751 | * @brief assert that lysc_node_leaf structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 752 | * |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 753 | * @param[in] NODE pointer to lysc_node variable |
| 754 | * @param[in] DSC expected description |
| 755 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances |
| 756 | * @param[in] FLAGS [schema node flags](@ref snodeflags) |
| 757 | * @param[in] MODULE 0 pointer is null, 1 pointer is not null |
| 758 | * @param[in] NAME expected name |
| 759 | * @param[in] NEXT 0 pointer is null, 1 pointer is not null |
| 760 | * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root |
| 761 | * @param[in] PRIV 0-> pointer is null, 1-> pointer is not null |
| 762 | * @param[in] REF expected reference |
Radek Iša | a76902f | 2021-03-29 08:52:51 +0200 | [diff] [blame] | 763 | * @param[in] ACTIONS 1 if is set pointer to structure lysc_node_action other 0 |
| 764 | * @param[in] CHILD 1 if is set pointer to child other 0 |
| 765 | * @param[in] MAX possible maximum elements in list |
| 766 | * @param[in] MIN possible minimum elements in list |
| 767 | * @param[in] MUSTS [sized array](@ref sizedarrays) number of must node elements in array |
| 768 | * @param[in] NOTIFS 1 if is set pointer to any notifs node |
| 769 | * @param[in] UNIQUES [sized array](@ref sizedarrays) number of unique nodes element in array |
| 770 | * @param[in] WHEN [sized array](@ref sizedarrays) size of when node array |
| 771 | */ |
| 772 | #define CHECK_LYSC_NODE_LIST(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, \ |
| 773 | PARENT, PRIV, REF, ACTIONS, CHILD, MAX, MIN, MUSTS, NOTIFS, UNIQUES, WHEN) \ |
| 774 | CHECK_LYSC_NODE(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, LYS_LIST, PARENT, PRIV, REF, WHEN); \ |
| 775 | CHECK_POINTER((NODE)->actions, ACTIONS); \ |
| 776 | CHECK_POINTER((NODE)->child, CHILD); \ |
| 777 | assert_int_equal((NODE)->max, MAX); \ |
| 778 | assert_int_equal((NODE)->min, MIN); \ |
| 779 | CHECK_ARRAY((NODE)->musts, MUSTS); \ |
| 780 | CHECK_POINTER((NODE)->notifs, NOTIFS); \ |
| 781 | CHECK_ARRAY((NODE)->uniques, UNIQUES); \ |
| 782 | CHECK_ARRAY(lysc_node_when((const struct lysc_node *)NODE), WHEN) |
| 783 | |
| 784 | /** |
| 785 | * @brief assert that lysc_node_leaf structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 786 | * |
Radek Iša | a76902f | 2021-03-29 08:52:51 +0200 | [diff] [blame] | 787 | * @param[in] NODE pointer to lysc_node variable |
| 788 | * @param[in] DSC expected description |
| 789 | * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances |
| 790 | * @param[in] FLAGS [schema node flags](@ref snodeflags) |
| 791 | * @param[in] MODULE 0 pointer is null, 1 pointer is not null |
| 792 | * @param[in] NAME expected name |
| 793 | * @param[in] NEXT 0 pointer is null, 1 pointer is not null |
| 794 | * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root |
| 795 | * @param[in] PRIV 0-> pointer is null, 1-> pointer is not null |
| 796 | * @param[in] REF expected reference |
| 797 | * @param[in] WHEN expected [sized array](@ref sizedarrays) size of list of pointers to when statements |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 798 | * @param[in] MUSTS expected [sized array](@ref sizedarrays) size of list of must restriction |
| 799 | * @param[in] UNITS expected string reprezenting units |
| 800 | * @param[in] DFLT 0-> node dosn't have default value. 1 -> node have default value |
| 801 | */ |
| 802 | #define CHECK_LYSC_NODE_LEAF(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, \ |
| 803 | PARENT, PRIV, REF, WHEN, MUSTS, UNITS, DFLT) \ |
| 804 | CHECK_LYSC_NODE(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, LYS_LEAF, PARENT, PRIV, REF, WHEN); \ |
| 805 | CHECK_ARRAY((NODE)->musts, MUSTS); \ |
| 806 | assert_non_null((NODE)->type); \ |
| 807 | CHECK_STRING((NODE)->units, UNITS); \ |
| 808 | CHECK_POINTER((NODE)->dflt, DFLT); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 809 | |
| 810 | /** |
| 811 | * @brief assert that lyd_meta structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 812 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 813 | * @param[in] NODE pointer to lyd_meta variable |
| 814 | * @param[in] ANNOTATION 0 pointer is null, 1 pointer is not null |
| 815 | * @param[in] NAME expected name |
| 816 | * @param[in] NEXT 0 pointer is null, 1 pointer is not null |
| 817 | * @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT |
| 818 | * part of text reprezenting LY_DATA_TYPE. |
| 819 | * @param[in] ... ::CHECK_LYD_VALUE |
| 820 | */ |
| 821 | #define CHECK_LYD_META(NODE, ANNOTATION, NAME, NEXT, PARENT, TYPE_VAL, ...) \ |
| 822 | assert_non_null(NODE); \ |
| 823 | CHECK_POINTER((NODE)->annotation, ANNOTATION); \ |
| 824 | assert_string_equal((NODE)->name, NAME); \ |
| 825 | CHECK_POINTER((NODE)->next, NEXT); \ |
| 826 | CHECK_POINTER((NODE)->parent, PARENT); \ |
Michal Vasko | 151ae6c | 2021-09-23 08:23:51 +0200 | [diff] [blame] | 827 | CHECK_LYD_VALUE((NODE)->value, TYPE_VAL, __VA_ARGS__); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 828 | |
| 829 | /** |
| 830 | * @brief assert that lyd_node_term structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 831 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 832 | * @param[in] NODE pointer to lyd_node_term variable |
| 833 | * @param[in] FLAGS expected [data node flags](@ref dnodeflags) |
| 834 | * @param[in] META 0 -> meta is not prezent, 1 -> meta is prezent |
| 835 | * @param[in] NEXT 0 -> next node is not prezent, 1 -> next node is prezent |
| 836 | * @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT |
| 837 | * part of text reprezenting LY_DATA_TYPE. |
| 838 | * @param[in] ... ::CHECK_LYD_VALUE |
| 839 | */ |
| 840 | #define CHECK_LYD_NODE_TERM(NODE, FLAGS, META, NEXT, PARENT, SCHEMA, VALUE_TYPE, ...) \ |
| 841 | assert_non_null(NODE); \ |
| 842 | assert_int_equal((NODE)->flags, FLAGS); \ |
| 843 | CHECK_POINTER((NODE)->meta, META); \ |
| 844 | CHECK_POINTER((NODE)->next, NEXT); \ |
| 845 | CHECK_POINTER((NODE)->parent, PARENT); \ |
| 846 | assert_non_null((NODE)->prev); \ |
| 847 | CHECK_POINTER((NODE)->schema, SCHEMA); \ |
Michal Vasko | 151ae6c | 2021-09-23 08:23:51 +0200 | [diff] [blame] | 848 | CHECK_LYD_VALUE((NODE)->value, VALUE_TYPE, __VA_ARGS__); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 849 | |
| 850 | /** |
| 851 | * @brief assert that lyd_node_any structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 852 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 853 | * @param[in] NODE pointer to lyd_node_term variable |
| 854 | * @param[in] FLAGS expected [data node flags](@ref dnodeflags) |
| 855 | * @param[in] META 0 meta isnt present , 1 meta is present |
| 856 | * @param[in] PARENT 0 it is root node , 1 node have parent |
| 857 | * @param[in] VALUE_TYPE value type ::lyd_node_any.value |
| 858 | */ |
| 859 | #define CHECK_LYD_NODE_ANY(NODE, FLAGS, META, PARENT, VALUE_TYPE) \ |
| 860 | assert_non_null(NODE); \ |
| 861 | assert_int_equal((NODE)->flags, FLAGS); \ |
| 862 | CHECK_POINTER((NODE)->meta, META); \ |
| 863 | CHECK_POINTER((NODE)->meta, PARENT); \ |
| 864 | assert_non_null((NODE)->prev); \ |
| 865 | assert_non_null((NODE)->schema); \ |
| 866 | assert_int_equal((NODE)->value_type, VALUE_TYPE); |
| 867 | |
| 868 | /** |
| 869 | * @brief assert that lyd_node_opaq structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 870 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 871 | * @param[in] NODE pointer to lyd_node_opaq variable |
| 872 | * @param[in] ATTR 0 if pointer is null ,1 if pointer is not null |
| 873 | * @param[in] CHILD 0 if pointer is null ,1 if pointer is not null |
| 874 | * @param[in] FORMAT LY_PREF_XML or LY_PREF_JSON |
| 875 | * @param[in] VAL_PREFS 0 if pointer is null ,1 if pointer is not null |
| 876 | * @param[in] NAME expected name |
| 877 | * @param[in] value expected orignal value |
| 878 | */ |
| 879 | #define CHECK_LYD_NODE_OPAQ(NODE, ATTR, CHILD, FORMAT, NAME, NEXT, PARENT, PREFIX, VAL_PREFS, VALUE) \ |
| 880 | assert_non_null(NODE); \ |
| 881 | CHECK_POINTER((NODE)->attr, ATTR); \ |
| 882 | CHECK_POINTER((NODE)->child, CHILD); \ |
| 883 | assert_ptr_equal((NODE)->ctx, UTEST_LYCTX); \ |
| 884 | assert_int_equal((NODE)->flags, 0); \ |
| 885 | assert_true((NODE)->format == FORMAT); \ |
| 886 | assert_int_equal((NODE)->hash, 0); \ |
| 887 | assert_string_equal((NODE)->name.name, NAME); \ |
| 888 | assert_non_null((NODE)->prev); \ |
| 889 | assert_null((NODE)->schema); \ |
| 890 | CHECK_POINTER((NODE)->val_prefix_data, VAL_PREFS); \ |
| 891 | assert_string_equal((NODE)->value, VALUE); |
| 892 | |
| 893 | /** |
Radek Iša | a76902f | 2021-03-29 08:52:51 +0200 | [diff] [blame] | 894 | * @brief assert that lyd_node_opaq structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 895 | * |
Radek Iša | a76902f | 2021-03-29 08:52:51 +0200 | [diff] [blame] | 896 | * @param[in] NODE pointer to lyd_node_opaq variable |
| 897 | * @param[in] CHILD 1 if node has children other 0 |
| 898 | * @param[in] HILD_HT 1 if node has children hash table other 0 |
| 899 | * @param[in] META 1 if node has metadata other 0 |
| 900 | * @param[in] FLAGS expected flag |
| 901 | * @param[in] NEXT 1 if next node is present other 0 |
| 902 | * @param[in] PARENT 1 if node has parent other 0 |
| 903 | * @param[in] PRIV 1 if node has private data other 0 |
| 904 | * @param[in] SCHEMA 1 if node has schema other 0 |
| 905 | */ |
| 906 | #define CHECK_LYD_NODE_INNER(NODE, CHILD, CHILD_HT, META, FLAGS, NEXT, PARENT, PRIV, SCHEMA) \ |
| 907 | assert_non_null(NODE); \ |
| 908 | CHECK_POINTER((NODE)->child, CHILD); \ |
| 909 | CHECK_POINTER((NODE)->children_ht, CHILD_HT); \ |
| 910 | CHECK_POINTER((NODE)->meta, META); \ |
| 911 | assert_int_equal((NODE)->flags, FLAGS); \ |
| 912 | CHECK_POINTER((NODE)->parent, PARENT); \ |
| 913 | assert_non_null((NODE)->prev); \ |
| 914 | CHECK_POINTER((NODE)->next, NEXT); \ |
| 915 | CHECK_POINTER((NODE)->priv, PRIV); \ |
| 916 | CHECK_POINTER((NODE)->schema, SCHEMA) |
| 917 | |
| 918 | /** |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 919 | * @brief assert that lyd_value structure members are correct |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 920 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 921 | * @param[in] NODE lyd_value |
| 922 | * @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT |
| 923 | * part of text reprezenting LY_DATA_TYPE. |
| 924 | * @param[in] ... Unspecified parameters. Type and numbers of parameters are specified |
| 925 | * by type of value. These parameters are passed to macro |
| 926 | * CHECK_LYD_VALUE_ ## TYPE_VAL. |
| 927 | */ |
| 928 | #define CHECK_LYD_VALUE(NODE, TYPE_VAL, ...) \ |
Michal Vasko | 151ae6c | 2021-09-23 08:23:51 +0200 | [diff] [blame] | 929 | CHECK_LYD_VALUE_ ## TYPE_VAL (NODE, __VA_ARGS__); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 930 | |
| 931 | /* |
| 932 | * LYD VALUES CHECKING SPECIALIZATION |
| 933 | */ |
| 934 | |
| 935 | /** |
| 936 | * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type EMPTY |
| 937 | * Example CHECK_LYD_VALUE(node->value, EMPTY, ""); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 938 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 939 | * @param[in] NODE lyd_value variable |
| 940 | * @param[in] CANNONICAL_VAL expected cannonical value |
| 941 | */ |
| 942 | #define CHECK_LYD_VALUE_EMPTY(NODE, CANNONICAL_VAL) \ |
Radek Krejci | 6d5ba0c | 2021-04-26 07:49:59 +0200 | [diff] [blame] | 943 | assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ |
Radek Krejci | 995784f | 2021-04-26 08:02:13 +0200 | [diff] [blame] | 944 | assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 945 | assert_non_null((NODE).realtype); \ |
| 946 | assert_int_equal((NODE).realtype->basetype, LY_TYPE_EMPTY); |
| 947 | |
| 948 | /** |
| 949 | * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type UNION |
| 950 | * Example CHECK_LYD_VALUE(node->value, UNION, "12", INT8, "12", 12); |
| 951 | * @warning type of subvalue cannot be UNION. Example of calling |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 952 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 953 | * @param[in] NODE lyd_value variable |
| 954 | * @param[in] CANNONICAL_VAL expected cannonical value |
| 955 | * @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT |
| 956 | * @param[in] ... Unspecified parameters. Type and numbers of parameters are specified |
| 957 | * by type of value. These parameters are passed to macro |
| 958 | * CHECK_LYD_VALUE_ ## TYPE_VAL. |
| 959 | */ |
| 960 | #define CHECK_LYD_VALUE_UNION(NODE, CANNONICAL_VAL, TYPE_VAL, ...) \ |
Radek Krejci | 6d5ba0c | 2021-04-26 07:49:59 +0200 | [diff] [blame] | 961 | assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ |
Radek Krejci | 995784f | 2021-04-26 08:02:13 +0200 | [diff] [blame] | 962 | assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 963 | assert_non_null((NODE).realtype); \ |
| 964 | assert_int_equal(LY_TYPE_UNION, (NODE).realtype->basetype); \ |
| 965 | assert_non_null((NODE).subvalue); \ |
| 966 | assert_non_null((NODE).subvalue->prefix_data); \ |
Michal Vasko | 151ae6c | 2021-09-23 08:23:51 +0200 | [diff] [blame] | 967 | CHECK_LYD_VALUE_ ## TYPE_VAL ((NODE).subvalue->value, __VA_ARGS__) |
| 968 | |
| 969 | /** |
| 970 | * @brief Internal macro. Get 1st variadic argument. |
| 971 | */ |
| 972 | #define _GETARG1(ARG1, ...) ARG1 |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 973 | |
| 974 | /** |
| 975 | * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type BITS |
| 976 | * Example arr[] = {"a", "b"}; CHECK_LYD_VALUE(node->value, BITS, "a b", arr); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 977 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 978 | * @param[in] NODE lyd_value variable |
| 979 | * @param[in] CANNONICAL_VAL expected cannonical value |
| 980 | * @param[in] VALUE expected array of bits names |
| 981 | */ |
Michal Vasko | 151ae6c | 2021-09-23 08:23:51 +0200 | [diff] [blame] | 982 | #define CHECK_LYD_VALUE_BITS(NODE, ...) \ |
Radek Krejci | 6d5ba0c | 2021-04-26 07:49:59 +0200 | [diff] [blame] | 983 | assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ |
Michal Vasko | 151ae6c | 2021-09-23 08:23:51 +0200 | [diff] [blame] | 984 | assert_string_equal((NODE)._canonical, _GETARG1(__VA_ARGS__, DUMMY)); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 985 | assert_non_null((NODE).realtype); \ |
| 986 | assert_int_equal(LY_TYPE_BITS, (NODE).realtype->basetype); \ |
| 987 | { \ |
Radek Iša | ded3105 | 2021-03-10 13:22:53 +0100 | [diff] [blame] | 988 | const char *arr[] = { __VA_ARGS__ }; \ |
Michal Vasko | 151ae6c | 2021-09-23 08:23:51 +0200 | [diff] [blame] | 989 | LY_ARRAY_COUNT_TYPE arr_size = (sizeof(arr) / sizeof(arr[0])) - 1; \ |
Michal Vasko | aa0ee62 | 2021-05-11 09:29:25 +0200 | [diff] [blame] | 990 | struct lyd_value_bits *_val; \ |
| 991 | LYD_VALUE_GET(&(NODE), _val); \ |
| 992 | assert_int_equal(arr_size, LY_ARRAY_COUNT(_val->items)); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 993 | for (LY_ARRAY_COUNT_TYPE it = 0; it < arr_size; it++) { \ |
Michal Vasko | 151ae6c | 2021-09-23 08:23:51 +0200 | [diff] [blame] | 994 | assert_string_equal(arr[it + 1], _val->items[it]->name); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 995 | } \ |
| 996 | } |
| 997 | |
| 998 | /** |
| 999 | * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type INST |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1000 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1001 | * @param[in] NODE lyd_value variable |
| 1002 | * @param[in] CANNONICAL_VAL expected cannonical value |
| 1003 | * @param[in] VALUE expected array of enum ly_path_pred_type |
| 1004 | * @brief Example enum arr[] = {0x0, 0x1}; CHECK_LYD_VALUE(node->value, INST, "test/d", arr); |
| 1005 | */ |
| 1006 | #define CHECK_LYD_VALUE_INST(NODE, CANNONICAL_VAL, VALUE) \ |
Radek Krejci | 6d5ba0c | 2021-04-26 07:49:59 +0200 | [diff] [blame] | 1007 | assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ |
Radek Krejci | 995784f | 2021-04-26 08:02:13 +0200 | [diff] [blame] | 1008 | assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1009 | assert_non_null((NODE).realtype); \ |
| 1010 | assert_int_equal(LY_TYPE_INST, (NODE).realtype->basetype); \ |
| 1011 | { \ |
Michal Vasko | 79135ae | 2020-12-16 10:08:35 +0100 | [diff] [blame] | 1012 | LY_ARRAY_COUNT_TYPE arr_size = sizeof(VALUE) / sizeof(VALUE[0]); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1013 | assert_int_equal(arr_size, LY_ARRAY_COUNT((NODE).target)); \ |
| 1014 | for (LY_ARRAY_COUNT_TYPE it = 0; it < arr_size; it++) { \ |
| 1015 | assert_int_equal(VALUE[it], (NODE).target[it].pred_type); \ |
| 1016 | } \ |
| 1017 | } |
| 1018 | |
| 1019 | /** |
| 1020 | * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type ENUM. |
| 1021 | * Example CHECK_LYD_VALUE(node->value, ENUM, "item_name", "item_name"); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1022 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1023 | * @param[in] NODE lyd_value variable |
| 1024 | * @param[in] CANNONICAL_VAL expected cannonical value |
| 1025 | * @param[in] VALUE expected enum item name |
| 1026 | */ |
| 1027 | #define CHECK_LYD_VALUE_ENUM(NODE, CANNONICAL_VAL, VALUE) \ |
Radek Krejci | 6d5ba0c | 2021-04-26 07:49:59 +0200 | [diff] [blame] | 1028 | assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ |
Radek Krejci | 995784f | 2021-04-26 08:02:13 +0200 | [diff] [blame] | 1029 | assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1030 | assert_non_null((NODE).realtype); \ |
| 1031 | assert_int_equal(LY_TYPE_ENUM, (NODE).realtype->basetype); \ |
| 1032 | assert_string_equal(VALUE, (NODE).enum_item->name); |
| 1033 | |
| 1034 | /** |
| 1035 | * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type INT8 |
| 1036 | * Example CHECK_LYD_VALUE(node->value, INT8, "12", 12); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1037 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1038 | * @param[in] NODE lyd_value variable |
| 1039 | * @param[in] CANNONICAL_VAL expected cannonical value |
| 1040 | * @param[in] VALUE expected inteager value (-128 to 127). |
| 1041 | */ |
| 1042 | #define CHECK_LYD_VALUE_INT8(NODE, CANNONICAL_VAL, VALUE) \ |
Radek Krejci | 6d5ba0c | 2021-04-26 07:49:59 +0200 | [diff] [blame] | 1043 | assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ |
Radek Krejci | 995784f | 2021-04-26 08:02:13 +0200 | [diff] [blame] | 1044 | assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1045 | assert_non_null((NODE).realtype); \ |
| 1046 | assert_int_equal(LY_TYPE_INT8, (NODE).realtype->basetype); \ |
| 1047 | assert_int_equal(VALUE, (NODE).int8); |
| 1048 | |
| 1049 | /** |
| 1050 | * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type INT16 |
| 1051 | * Example CHECK_LYD_VALUE(node->value, INT8, "12", 12); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1052 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1053 | * @param[in] NODE lyd_value variable |
| 1054 | * @param[in] CANNONICAL_VAL expected cannonical value |
| 1055 | * @param[in] VALUE expected inteager value. |
| 1056 | */ |
| 1057 | #define CHECK_LYD_VALUE_INT16(NODE, CANNONICAL_VAL, VALUE) \ |
Radek Krejci | 6d5ba0c | 2021-04-26 07:49:59 +0200 | [diff] [blame] | 1058 | assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ |
Radek Krejci | 995784f | 2021-04-26 08:02:13 +0200 | [diff] [blame] | 1059 | assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1060 | assert_non_null((NODE).realtype); \ |
| 1061 | assert_int_equal(LY_TYPE_INT16, (NODE).realtype->basetype); \ |
| 1062 | assert_int_equal(VALUE, (NODE).int16); |
| 1063 | |
| 1064 | /** |
| 1065 | * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type UINT8. |
| 1066 | * Example CHECK_LYD_VALUE(node->value, UINT8, "12", 12); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1067 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1068 | * @param[in] NODE lyd_value variable |
| 1069 | * @param[in] CANNONICAL_VAL expected cannonical value |
| 1070 | * @param[in] VALUE expected inteager (0 to 255). |
| 1071 | */ |
| 1072 | #define CHECK_LYD_VALUE_UINT8(NODE, CANNONICAL_VAL, VALUE) \ |
Radek Krejci | 6d5ba0c | 2021-04-26 07:49:59 +0200 | [diff] [blame] | 1073 | assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ |
Radek Krejci | 995784f | 2021-04-26 08:02:13 +0200 | [diff] [blame] | 1074 | assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1075 | assert_non_null((NODE).realtype); \ |
| 1076 | assert_int_equal(LY_TYPE_UINT8, (NODE).realtype->basetype); \ |
| 1077 | assert_int_equal(VALUE, (NODE).uint8); |
| 1078 | |
| 1079 | /** |
Radek Iša | a76902f | 2021-03-29 08:52:51 +0200 | [diff] [blame] | 1080 | * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type UINT32. |
| 1081 | * Example CHECK_LYD_VALUE(node->value, UINT32, "12", 12); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1082 | * |
Radek Iša | a76902f | 2021-03-29 08:52:51 +0200 | [diff] [blame] | 1083 | * @param[in] NODE lyd_value variable |
| 1084 | * @param[in] CANNONICAL_VAL expected cannonical value |
| 1085 | * @param[in] VALUE expected inteager (0 to MAX_UINT32). |
| 1086 | */ |
| 1087 | #define CHECK_LYD_VALUE_UINT32(NODE, CANNONICAL_VAL, VALUE) \ |
Radek Krejci | 6d5ba0c | 2021-04-26 07:49:59 +0200 | [diff] [blame] | 1088 | assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ |
Radek Krejci | 995784f | 2021-04-26 08:02:13 +0200 | [diff] [blame] | 1089 | assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ |
Radek Iša | a76902f | 2021-03-29 08:52:51 +0200 | [diff] [blame] | 1090 | assert_non_null((NODE).realtype); \ |
| 1091 | assert_int_equal(LY_TYPE_UINT32, (NODE).realtype->basetype); \ |
| 1092 | assert_int_equal(VALUE, (NODE).uint32); |
| 1093 | |
| 1094 | /** |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1095 | * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type STRING. |
| 1096 | * Example CHECK_LYD_VALUE(node->value, STRING, "text"); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1097 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1098 | * @param[in] NODE lyd_value variable |
| 1099 | * @param[in] CANNONICAL_VAL expected cannonical value |
| 1100 | */ |
| 1101 | #define CHECK_LYD_VALUE_STRING(NODE, CANNONICAL_VAL) \ |
Radek Krejci | 6d5ba0c | 2021-04-26 07:49:59 +0200 | [diff] [blame] | 1102 | assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ |
Radek Krejci | 995784f | 2021-04-26 08:02:13 +0200 | [diff] [blame] | 1103 | assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1104 | assert_non_null((NODE).realtype); \ |
| 1105 | assert_int_equal(LY_TYPE_STRING, (NODE).realtype->basetype); |
| 1106 | |
| 1107 | /** |
| 1108 | * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type LEAFREF |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1109 | * Example CHECK_LYD_VALUE(node->value, LEAFREF, ""); |
| 1110 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1111 | * @param[in] NODE lyd_value variable |
| 1112 | * @param[in] CANNONICAL_VAL expected cannonical value |
| 1113 | */ |
| 1114 | #define CHECK_LYD_VALUE_LEAFREF(NODE, CANNONICAL_VAL) \ |
Radek Krejci | 6d5ba0c | 2021-04-26 07:49:59 +0200 | [diff] [blame] | 1115 | assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ |
Radek Krejci | 995784f | 2021-04-26 08:02:13 +0200 | [diff] [blame] | 1116 | assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1117 | assert_non_null((NODE).realtype); \ |
| 1118 | assert_int_equal(LY_TYPE_LEAFREF, (NODE).realtype->basetype); \ |
| 1119 | assert_non_null((NODE).ptr) |
| 1120 | |
| 1121 | /** |
| 1122 | * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type DEC64 |
| 1123 | * Example CHECK_LYD_VALUE(node->value, DEC64, "125", 125); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1124 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1125 | * @param[in] NODE lyd_value variable |
| 1126 | * @param[in] CANNONICAL_VAL expected cannonical value |
| 1127 | * @param[in] VALUE expected value 64bit inteager |
| 1128 | */ |
| 1129 | #define CHECK_LYD_VALUE_DEC64(NODE, CANNONICAL_VAL, VALUE) \ |
Radek Krejci | 6d5ba0c | 2021-04-26 07:49:59 +0200 | [diff] [blame] | 1130 | assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ |
Radek Krejci | 995784f | 2021-04-26 08:02:13 +0200 | [diff] [blame] | 1131 | assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1132 | assert_non_null((NODE).realtype); \ |
| 1133 | assert_int_equal(LY_TYPE_DEC64, (NODE).realtype->basetype); \ |
| 1134 | assert_int_equal(VALUE, (NODE).dec64); |
| 1135 | |
| 1136 | /** |
| 1137 | * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type BINARY. |
| 1138 | * Example CHECK_LYD_VALUE(node->value, BINARY, "aGVs\nbG8="); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1139 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1140 | * @param[in] NODE lyd_value variable |
| 1141 | * @param[in] CANNONICAL_VAL expected cannonical value |
Michal Vasko | 495f450 | 2021-04-27 14:48:05 +0200 | [diff] [blame] | 1142 | * @param[in] VALUE expected value data |
| 1143 | * @param[in] SIZE expected value data size |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1144 | */ |
Michal Vasko | 495f450 | 2021-04-27 14:48:05 +0200 | [diff] [blame] | 1145 | #define CHECK_LYD_VALUE_BINARY(NODE, CANNONICAL_VAL, VALUE, SIZE) \ |
Michal Vasko | aa0ee62 | 2021-05-11 09:29:25 +0200 | [diff] [blame] | 1146 | { \ |
| 1147 | struct lyd_value_binary *_val; \ |
| 1148 | LYD_VALUE_GET(&(NODE), _val); \ |
| 1149 | assert_int_equal(_val->size, SIZE); \ |
| 1150 | assert_int_equal(0, memcmp(_val->data, VALUE, SIZE)); \ |
| 1151 | assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ |
| 1152 | assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ |
| 1153 | assert_non_null((NODE).realtype); \ |
| 1154 | assert_int_equal(LY_TYPE_BINARY, (NODE).realtype->basetype); \ |
| 1155 | } |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1156 | |
| 1157 | /** |
| 1158 | * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type BOOL. |
| 1159 | * Example CHECK_LYD_VALUE(node->value, BOOL, "true", 1); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1160 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1161 | * @param[in] NODE lyd_value variable |
| 1162 | * @param[in] CANNONICAL_VAL expected cannonical value |
| 1163 | * @param[in] VALUE expected boolean value 0,1 |
| 1164 | */ |
| 1165 | #define CHECK_LYD_VALUE_BOOL(NODE, CANNONICAL_VAL, VALUE) \ |
Radek Krejci | 6d5ba0c | 2021-04-26 07:49:59 +0200 | [diff] [blame] | 1166 | assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ |
Radek Krejci | 995784f | 2021-04-26 08:02:13 +0200 | [diff] [blame] | 1167 | assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1168 | assert_non_null((NODE).realtype); \ |
| 1169 | assert_int_equal(LY_TYPE_BOOL, (NODE).realtype->basetype); \ |
| 1170 | assert_int_equal(VALUE, (NODE).boolean); |
| 1171 | |
| 1172 | /** |
| 1173 | * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type IDENT. |
| 1174 | * Example CHECK_LYD_VALUE(node->value, IDENT, "types:gigabit-ethernet", "gigabit-ethernet"); |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1175 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1176 | * @param[in] NODE lyd_value variable |
| 1177 | * @param[in] CANNONICAL_VAL expected cannonical value |
| 1178 | * @param[in] VALUE expected ident name |
| 1179 | */ |
| 1180 | #define CHECK_LYD_VALUE_IDENT(NODE, CANNONICAL_VAL, VALUE) \ |
Radek Krejci | 6d5ba0c | 2021-04-26 07:49:59 +0200 | [diff] [blame] | 1181 | assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \ |
Radek Krejci | 995784f | 2021-04-26 08:02:13 +0200 | [diff] [blame] | 1182 | assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1183 | assert_non_null((NODE).realtype); \ |
| 1184 | assert_int_equal(LY_TYPE_IDENT, (NODE).realtype->basetype); \ |
| 1185 | assert_string_equal(VALUE, (NODE).ident->name); |
| 1186 | |
| 1187 | /** |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 1188 | * @brief Macro testing parser when parsing incorrect module; |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1189 | * |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 1190 | * @param[in] DATA String storing the schema module representation. |
| 1191 | * @param[in] FORMAT Schema format of the @p DATA |
| 1192 | * @param[in] FEATURES Array of module's features to enable |
| 1193 | * @param[in] RET_VAL ly_in_new_memory return error value |
| 1194 | */ |
| 1195 | #define UTEST_INVALID_MODULE(DATA, FORMAT, FEATURES, RET_VAL) \ |
| 1196 | { \ |
Michal Vasko | 4de7d07 | 2021-07-09 09:13:18 +0200 | [diff] [blame] | 1197 | struct lys_module *mod; \ |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 1198 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(DATA, &_UC->in)); \ |
| 1199 | assert_int_equal(RET_VAL, lys_parse(_UC->ctx, _UC->in, FORMAT, FEATURES, &mod)); \ |
| 1200 | assert_null(mod); \ |
| 1201 | } \ |
| 1202 | ly_in_free(_UC->in, 0); \ |
| 1203 | _UC->in = NULL; \ |
| 1204 | |
| 1205 | /** |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1206 | * @brief Add module (from a string) into the used libyang context. |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1207 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1208 | * @param[in] DATA String storing the schema module representation. |
| 1209 | * @param[in] FORMAT Schema format of the @p DATA |
| 1210 | * @param[in] FEATURES Array of module's features to enable |
| 1211 | * @param[out] MOD Optional parameter as a pointer to variable to store the resulting module. |
| 1212 | */ |
| 1213 | #define UTEST_ADD_MODULE(DATA, FORMAT, FEATURES, MOD) \ |
| 1214 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(DATA, &_UC->in)); \ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1215 | { \ |
| 1216 | LY_ERR __r = lys_parse(_UC->ctx, _UC->in, FORMAT, FEATURES, MOD); \ |
| 1217 | if (__r != LY_SUCCESS) { \ |
| 1218 | print_message("[ MSG ] Module parsing failed:\n"); \ |
| 1219 | for (struct ly_err_item *e = ly_err_first(_UC->ctx); e; e = e->next) { \ |
| 1220 | print_message("[ MSG ] \t%s Path %s\n", e->msg, e->path); \ |
| 1221 | } \ |
| 1222 | fail(); \ |
| 1223 | } \ |
| 1224 | } \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1225 | ly_in_free(_UC->in, 0); \ |
| 1226 | _UC->in = NULL |
| 1227 | |
| 1228 | /** |
| 1229 | * @brief Internal macro to compare error info record with the expected error message and path. |
| 1230 | * If NULL is provided as MSG, no error info record (NULL) is expected. |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 1231 | * |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1232 | * @param[in] ERR Error information record from libyang context. |
| 1233 | * @param[in] MSG Expected error message. |
| 1234 | * @param[in] PATH Expected error path. |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1235 | */ |
| 1236 | #define _CHECK_LOG_CTX(ERR, MSG, PATH) \ |
| 1237 | if (!MSG) { \ |
| 1238 | assert_null(ERR); \ |
| 1239 | } else { \ |
| 1240 | assert_non_null(ERR); \ |
| 1241 | CHECK_STRING((ERR)->msg, MSG); \ |
| 1242 | CHECK_STRING((ERR)->path, PATH); \ |
| 1243 | } |
| 1244 | |
| 1245 | /**` |
| 1246 | * @brief Internal macro to check the last libyang's context error. |
| 1247 | */ |
| 1248 | #define _CHECK_LOG_CTX1(MSG, PATH) \ |
| 1249 | _CHECK_LOG_CTX(ly_err_last(_UC->ctx), MSG, PATH) |
| 1250 | |
| 1251 | /** |
| 1252 | * @brief Internal macro to check the last two libyang's context error. |
| 1253 | */ |
| 1254 | #define _CHECK_LOG_CTX2(MSG1, PATH1, MSG2, PATH2) \ |
| 1255 | _CHECK_LOG_CTX(ly_err_last(_UC->ctx), MSG1, PATH1); \ |
| 1256 | _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev, MSG2, PATH2) |
| 1257 | |
| 1258 | /** |
| 1259 | * @brief Internal macro to check the last three libyang's context error. |
| 1260 | */ |
| 1261 | #define _CHECK_LOG_CTX3(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3) \ |
| 1262 | _CHECK_LOG_CTX2(MSG1, PATH1, MSG2, PATH2); \ |
| 1263 | _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev, MSG3, PATH3) |
| 1264 | |
| 1265 | /** |
Radek Krejci | fe6ec26 | 2021-01-20 10:28:28 +0100 | [diff] [blame] | 1266 | * @brief Internal macro to check the last three libyang's context error. |
| 1267 | */ |
| 1268 | #define _CHECK_LOG_CTX4(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4) \ |
| 1269 | _CHECK_LOG_CTX3(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3); \ |
| 1270 | _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev, MSG4, PATH4) |
| 1271 | |
| 1272 | /** |
| 1273 | * @brief Internal macro to check the last three libyang's context error. |
| 1274 | */ |
| 1275 | #define _CHECK_LOG_CTX5(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5) \ |
| 1276 | _CHECK_LOG_CTX4(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4); \ |
| 1277 | _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev->prev, MSG5, PATH5) |
| 1278 | |
| 1279 | /** |
Radek Krejci | 8297b79 | 2020-08-16 14:49:05 +0200 | [diff] [blame] | 1280 | * @brief Internal macro to check the last three libyang's context error. |
| 1281 | */ |
| 1282 | #define _CHECK_LOG_CTX6(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6) \ |
| 1283 | _CHECK_LOG_CTX5(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5); \ |
| 1284 | _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev->prev->prev, MSG6, PATH6) |
| 1285 | |
| 1286 | /** |
| 1287 | * @brief Internal macro to check the last three libyang's context error. |
| 1288 | */ |
| 1289 | #define _CHECK_LOG_CTX7(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6, MSG7, PATH7) \ |
| 1290 | _CHECK_LOG_CTX6(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6); \ |
| 1291 | _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev->prev->prev->prev, MSG7, PATH7) |
| 1292 | |
| 1293 | /** |
| 1294 | * @brief Internal macro to check the last three libyang's context error. |
| 1295 | */ |
| 1296 | #define _CHECK_LOG_CTX8(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6, MSG7, PATH7, MSG8, PATH8) \ |
| 1297 | _CHECK_LOG_CTX7(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6, MSG7, PATH7); \ |
| 1298 | _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev->prev->prev->prev->prev, MSG8, PATH8) |
| 1299 | |
| 1300 | /** |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1301 | * @brief Internal helper macro to select _CHECK_LOG_CTX* macro according to the provided parameters. |
| 1302 | */ |
Radek Krejci | 8297b79 | 2020-08-16 14:49:05 +0200 | [diff] [blame] | 1303 | #define _GET_CHECK_LOG_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, NAME, ...) NAME |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1304 | |
| 1305 | /** |
| 1306 | * @brief Check expected error(s) in libyang context. |
| 1307 | * |
| 1308 | * Macro has variadic parameters expected to be provided in pairs of error message and error path starting |
| 1309 | * from the latest error. Current limit is checking at most 3 last errors. After checking, macro cleans up |
| 1310 | * all the errors from the libyang context. |
| 1311 | * |
| 1312 | * @param[in] MSG Expected error message. |
| 1313 | * @param[in] PATH Expected error path. |
| 1314 | */ |
| 1315 | #define CHECK_LOG_CTX(...) \ |
Radek Krejci | 8297b79 | 2020-08-16 14:49:05 +0200 | [diff] [blame] | 1316 | _GET_CHECK_LOG_MACRO(__VA_ARGS__, _CHECK_LOG_CTX8, _INVAL, _CHECK_LOG_CTX7, _INVAL, \ |
| 1317 | _CHECK_LOG_CTX6, _INVAL, _CHECK_LOG_CTX5, _INVAL, _CHECK_LOG_CTX4, _INVAL, \ |
Michal Vasko | 151ae6c | 2021-09-23 08:23:51 +0200 | [diff] [blame] | 1318 | _CHECK_LOG_CTX3, _INVAL, _CHECK_LOG_CTX2, _INVAL, _CHECK_LOG_CTX1, DUMMY)(__VA_ARGS__); \ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1319 | ly_err_clean(_UC->ctx, NULL) |
| 1320 | |
| 1321 | /** |
Michal Vasko | e9391c7 | 2021-10-05 10:04:56 +0200 | [diff] [blame] | 1322 | * @brief Check expected error in libyang context including error-app-tag. |
| 1323 | * |
| 1324 | * @param[in] MSG Expected error message. |
| 1325 | * @param[in] PATH Expected error path. |
| 1326 | * @param[in] APPTAG Expected error-app-tag. |
| 1327 | */ |
| 1328 | #define CHECK_LOG_CTX_APPTAG(MSG, PATH, APPTAG) \ |
| 1329 | if (!MSG) { \ |
| 1330 | assert_null(ly_err_last(_UC->ctx)); \ |
| 1331 | } else { \ |
| 1332 | assert_non_null(ly_err_last(_UC->ctx)); \ |
| 1333 | CHECK_STRING(ly_err_last(_UC->ctx)->msg, MSG); \ |
| 1334 | CHECK_STRING(ly_err_last(_UC->ctx)->path, PATH); \ |
| 1335 | CHECK_STRING(ly_err_last(_UC->ctx)->apptag, APPTAG); \ |
| 1336 | } \ |
| 1337 | ly_err_clean(_UC->ctx, NULL) |
| 1338 | |
| 1339 | /** |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1340 | * @brief Clean up the logging callback's storage. |
| 1341 | */ |
| 1342 | #define UTEST_LOG_CLEAN \ |
| 1343 | free(_UC->err_msg); \ |
| 1344 | free(_UC->err_path); \ |
| 1345 | _UC->err_msg = NULL; \ |
| 1346 | _UC->err_path = NULL; |
| 1347 | |
| 1348 | /** |
| 1349 | * @brief Check expected error directly logged via logging callback. |
| 1350 | * Useful mainly for messages logged by functions without access to libyang context. |
| 1351 | * @param[in] MSG Expected error message. |
| 1352 | * @param[in] PATH Expected error path. |
| 1353 | */ |
| 1354 | #define CHECK_LOG(MSG, PATH) \ |
| 1355 | CHECK_STRING(_UC->err_msg, MSG); \ |
| 1356 | CHECK_STRING(_UC->err_path, PATH); \ |
| 1357 | UTEST_LOG_CLEAN |
| 1358 | |
| 1359 | #ifdef _UTEST_MAIN_ |
| 1360 | /* |
| 1361 | * Functions inlined into each C source file including this header with _UTEST_MAIN_ defined |
| 1362 | */ |
| 1363 | |
| 1364 | /** |
| 1365 | * @brief Global variable holding the tests context to simplify access to it. |
| 1366 | */ |
| 1367 | struct utest_context *current_utest_context; |
| 1368 | |
| 1369 | /* set to 0 to printing error messages to stderr instead of checking them in code */ |
| 1370 | #define ENABLE_LOGGER_CHECKING 1 |
| 1371 | |
| 1372 | /** |
| 1373 | * @brief Logging callback for libyang. |
| 1374 | */ |
| 1375 | static void |
| 1376 | _utest_logger(LY_LOG_LEVEL level, const char *msg, const char *path) |
| 1377 | { |
| 1378 | (void) level; /* unused */ |
| 1379 | |
| 1380 | if (ENABLE_LOGGER_CHECKING == 0) { |
Radek Iša | a9ff2b8 | 2021-01-13 21:44:13 +0100 | [diff] [blame] | 1381 | printf("\tERROR:\n\t\tMESSAGE: %s\n\t\tPATH: %s\n\t\tLEVEL: %i\n", msg, path, level); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1382 | } else { |
| 1383 | free(current_utest_context->err_msg); |
| 1384 | current_utest_context->err_msg = msg ? strdup(msg) : NULL; |
| 1385 | free(current_utest_context->err_path); |
| 1386 | current_utest_context->err_path = path ? strdup(path) : NULL; |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | /** |
| 1391 | * @brief Generic utest's setup |
| 1392 | */ |
| 1393 | static int |
| 1394 | utest_setup(void **state) |
| 1395 | { |
Michal Vasko | 8642163 | 2021-05-04 13:11:25 +0200 | [diff] [blame] | 1396 | char *cur_tz; |
| 1397 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1398 | /* setup the logger */ |
| 1399 | ly_set_log_clb(_utest_logger, 1); |
| 1400 | ly_log_options(LY_LOLOG | LY_LOSTORE); |
| 1401 | |
| 1402 | current_utest_context = calloc(1, sizeof *current_utest_context); |
| 1403 | assert_non_null(current_utest_context); |
| 1404 | *state = current_utest_context; |
| 1405 | |
| 1406 | /* libyang context */ |
| 1407 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, ¤t_utest_context->ctx)); |
| 1408 | |
Radek Krejci | 968d755 | 2021-03-26 20:33:51 +0100 | [diff] [blame] | 1409 | /* clean all errors from the setup - usually warnings regarding the plugins directories */ |
| 1410 | UTEST_LOG_CLEAN; |
| 1411 | |
Michal Vasko | 8642163 | 2021-05-04 13:11:25 +0200 | [diff] [blame] | 1412 | /* backup timezone, if any */ |
| 1413 | cur_tz = getenv("TZ"); |
| 1414 | if (cur_tz) { |
| 1415 | current_utest_context->orig_tz = strdup(cur_tz); |
| 1416 | } |
| 1417 | |
| 1418 | /* set CET */ |
| 1419 | setenv("TZ", "CET+02:00", 1); |
| 1420 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1421 | return 0; |
| 1422 | } |
| 1423 | |
| 1424 | /** |
| 1425 | * @brief macro to include generic utest's setup into the test-specific setup. |
| 1426 | * |
| 1427 | * Place at the beginning of the test-specific setup |
| 1428 | */ |
| 1429 | #define UTEST_SETUP \ |
| 1430 | assert_int_equal(0, utest_setup(state)) |
| 1431 | |
| 1432 | /** |
| 1433 | * @brief Generic utest's teardown |
| 1434 | */ |
| 1435 | static int |
| 1436 | utest_teardown(void **state) |
| 1437 | { |
| 1438 | *state = NULL; |
| 1439 | |
| 1440 | /* libyang context */ |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 1441 | ly_ctx_destroy(current_utest_context->ctx); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1442 | |
Michal Vasko | 8642163 | 2021-05-04 13:11:25 +0200 | [diff] [blame] | 1443 | if (current_utest_context->orig_tz) { |
| 1444 | /* restore TZ */ |
| 1445 | setenv("TZ", current_utest_context->orig_tz, 1); |
| 1446 | } |
| 1447 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1448 | /* utest context */ |
| 1449 | ly_in_free(current_utest_context->in, 0); |
| 1450 | free(current_utest_context->err_msg); |
| 1451 | free(current_utest_context->err_path); |
Michal Vasko | 8642163 | 2021-05-04 13:11:25 +0200 | [diff] [blame] | 1452 | free(current_utest_context->orig_tz); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1453 | free(current_utest_context); |
| 1454 | current_utest_context = NULL; |
| 1455 | |
| 1456 | return 0; |
| 1457 | } |
| 1458 | |
| 1459 | /** |
| 1460 | * @brief macro to include generic utest's teardown into the test-specific teardown. |
| 1461 | * |
| 1462 | * Place at the end of the test-specific teardown |
| 1463 | */ |
| 1464 | #define UTEST_TEARDOWN \ |
| 1465 | assert_int_equal(0, utest_teardown(state)) |
| 1466 | |
| 1467 | /** |
| 1468 | * @brief Internal macro for utest setup with test-specific setup and teardown |
| 1469 | */ |
| 1470 | #define _UTEST_SETUP_TEARDOWN(FUNC, SETUP, TEARDOWN) \ |
| 1471 | cmocka_unit_test_setup_teardown(FUNC, SETUP, TEARDOWN) |
| 1472 | |
| 1473 | /** |
| 1474 | * @brief Internal macro for utest setup with test-specific setup and generic teardown |
| 1475 | */ |
| 1476 | #define _UTEST_SETUP(FUNC, SETUP) \ |
| 1477 | cmocka_unit_test_setup_teardown(FUNC, SETUP, utest_teardown) |
| 1478 | |
| 1479 | /** |
| 1480 | * @brief Internal macro for utest setup with generic setup and teardown |
| 1481 | */ |
| 1482 | #define _UTEST(FUNC) \ |
| 1483 | cmocka_unit_test_setup_teardown(FUNC, utest_setup, utest_teardown) |
| 1484 | |
| 1485 | /** |
| 1486 | * @brief Internal helper macro to select _UTEST* macro according to the provided parameters. |
| 1487 | */ |
| 1488 | #define _GET_UTEST_MACRO(_1, _2, _3, NAME, ...) NAME |
| 1489 | |
| 1490 | /** |
| 1491 | * @brief Macro to specify test function using utest environment. Macro has variadic parameters |
| 1492 | * to provide test-specific setup/teardown functions: |
| 1493 | * |
| 1494 | * UTEST(test_func) - only implicit setup and teardown functions are used |
| 1495 | * UTEST(test_func, setup) - implicit teardown but own setup |
| 1496 | * UTEST(test_func, setup, teardown) - both setup and teardown are test-specific |
| 1497 | */ |
| 1498 | #define UTEST(...) \ |
Michal Vasko | 151ae6c | 2021-09-23 08:23:51 +0200 | [diff] [blame] | 1499 | _GET_UTEST_MACRO(__VA_ARGS__, _UTEST_SETUP_TEARDOWN, _UTEST_SETUP, _UTEST, DUMMY)(__VA_ARGS__) |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 1500 | |
| 1501 | #else /* _UTEST_MAIN_ */ |
| 1502 | |
| 1503 | extern struct utest_context *current_utest_context; |
| 1504 | |
| 1505 | #endif /* _UTEST_MAIN_ */ |
| 1506 | |
| 1507 | #endif /* _UTESTS_H_ */ |