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