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