blob: 7e85a66edd09f6c8981e8c9b84295d8332b9c90c [file] [log] [blame]
Radek Iša56ca9e42020-09-08 18:42:00 +02001/**
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šaa9ff2b82021-01-13 21:44:13 +01007 * Copyright (c) 2021 CESNET, z.s.p.o.
Radek Iša56ca9e42020-09-08 18:42:00 +02008 *
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 Krejcib4ac5a92020-11-23 17:54:33 +010021#include <setjmp.h>
22#include <stdarg.h>
23#include <stddef.h>
Michal Vasko86421632021-05-04 13:11:25 +020024#include <stdlib.h>
Radek Krejcib4ac5a92020-11-23 17:54:33 +010025
26#include <cmocka.h>
Radek Iša56ca9e42020-09-08 18:42:00 +020027
28#include <string.h>
29
30#include "libyang.h"
Radek Krejci3e6632f2021-03-22 22:08:21 +010031#include "plugins_internal.h"
Radek Išaa9ff2b82021-01-13 21:44:13 +010032#include "plugins_types.h"
Radek Krejcief5f7672021-04-01 17:04:12 +020033#include "tests_config.h"
Radek Išaa9ff2b82021-01-13 21:44:13 +010034#include "tree_schema_internal.h"
Radek Iša56ca9e42020-09-08 18:42:00 +020035
36/**
37 * TESTS OVERVIEW
38 *
39 * To include utest's environment, just include "utests.h" in the test's source
40 * code. In case it is the main source code for a cmocka test group (there is a
41 * main() function), define _UTEST_MAIN_ before including this header.
42 *
43 * TESTS VARIABLES
44 *
45 * Checking macros use internal storage to store various variables necessary
46 * during the checking. It is possible to access these variables using the
47 * following macros:
48 *
49 * UTEST_LYCTX - libyang context
50 * UTEST_IN - input handler
51 * UTEST_OUT - output handler
52 *
53 * All these variables are cleaned with test's teardown.
54 *
55 * TESTS SETUP
56 *
57 * CMocka's CMUnitTest list definition macros (cmoka_unit_test*()) are replaced
58 * by UTEST macro with possibility to specify own setup and teardown functions:
59 *
60 * UTEST(test_func) - only implicit setup and teardown functions are used
61 * UTEST(test_func, setup) - implicit teardown but own setup
62 * UTEST(test_func, setup, teardown) - both setup and teardown are test-specific
63 *
64 * Note that the tests environment always provide (and need) internal setup and
65 * teardown functions. In case the test-specific setup or teardown are used, they
66 * are supposed to include UTEST_SETUP at the setup beginning and UTEST_TEARDOWN
67 * at the teardown end.
68 *
69 * Libyang context is part of the prepared environment. To add a schema into the
70 * context (despite it is in the test-specific setup or in test function itself),
71 * use UTEST_ADD_MODULE macro.
72 *
73 * LOGGING
74 *
75 * There are 2 macros to check content of the log from the previously called
76 * libyang function. CHECK_LOG macro test only the last error message and path
77 * stored directly via logging callback. CHECK_LOG_CTX gets error message and
78 * path from the libyang context (in case the function does not store the error
79 * information into the libyang context, the message cannot be checked this way).
80 * libyang is set to store multiple error information, so multiple couples of
81 * error message and path can be provided to be checked (the first couple
82 * corresponds to the latest error). The macro also cleanups the errors list, so
83 * it is fine to check that there is no error after succeeding successful
84 * function call.
85 */
86
87/**
88 * @brief Test's context to provide common storage for various variables.
89 */
90struct utest_context {
91 struct ly_ctx *ctx; /**< libyang context */
92
93 char *err_msg; /**< Directly logged error message */
94 char *err_path; /**< Directly logged error path */
95
96 struct ly_in *in; /**< Input handler */
97 struct ly_out *out; /**< Outpu handler */
Michal Vasko86421632021-05-04 13:11:25 +020098
99 char *orig_tz; /**< Original "TZ" environment variable value */
Radek Iša56ca9e42020-09-08 18:42:00 +0200100};
101
102/**
103 * @brief Shortcut to access utest_context.
104 */
105#define _UC ((struct utest_context *)*state)
106
107/**
108 * @brief libyang context provider.
109 */
110#define UTEST_LYCTX (_UC->ctx)
111
112/**
113 * @brief Context's input handler provider
114 */
115#define UTEST_IN (_UC->in)
116
117/**
118 * @brief Context's input handler provider
119 */
120#define UTEST_OUT (_UC->out)
121
122/**
123 * @brief Parse (and validate) data from the input handler as a YANG data tree.
124 *
125 * @param[in] INPUT The input data in the specified @p format to parse (and validate)
126 * @param[in] INPUT_FORMAT Format of the input data to be parsed. Can be 0 to try to detect format from the input handler.
127 * @param[in] PARSE_OPTIONS Options for parser, see @ref dataparseroptions.
128 * @param[in] VALIDATE_OPTIONS Options for the validation phase, see @ref datavalidationoptions.
Michal Vaskoddd76592022-01-17 13:34:48 +0100129 * @param[in] RET expected return status
130 * @param[out] OUT_NODE Resulting data tree built from the input data. Note that NULL can be a valid result as a
131 * representation of an empty YANG data tree.
Radek Iša56ca9e42020-09-08 18:42:00 +0200132 */
Michal Vaskoddd76592022-01-17 13:34:48 +0100133#define CHECK_PARSE_LYD_PARAM(INPUT, INPUT_FORMAT, PARSE_OPTIONS, VALIDATE_OPTIONS, RET, OUT_NODE) \
134 { \
135 LY_ERR _r = lyd_parse_data_mem(_UC->ctx, INPUT, INPUT_FORMAT, PARSE_OPTIONS, VALIDATE_OPTIONS, &OUT_NODE); \
136 if (_r != RET) { \
137 if (_r) { \
138 fail_msg("%s != 0x%d; MSG: %s", #RET, _r, ly_err_last(_UC->ctx)->msg); \
139 } else { \
140 fail_msg("%s != 0x%d", #RET, _r); \
141 } \
142 } \
143 if (RET == LY_SUCCESS) { \
144 assert_non_null(OUT_NODE); \
145 } else { \
146 assert_null(OUT_NODE); \
147 } \
Radek Iša56ca9e42020-09-08 18:42:00 +0200148 }
149
150/**
151 * @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.
152 * @param[in] NODE pointer to lyd_node
153 * @param[in] TEXT expected output string in json or xml format.
154 * @param[in] FORMAT format of input text. LYD_JSON, LYD_XML
155 * @param[in] PARAM options [Data printer flags](@ref dataprinterflags).
156 */
157#define CHECK_LYD_STRING_PARAM(NODE, TEXT, FORMAT, PARAM) \
158 { \
Michal Vaskoddd76592022-01-17 13:34:48 +0100159 char *str; \
160 LY_ERR _r = lyd_print_mem(&str, NODE, FORMAT, PARAM); \
161 if (_r) { \
162 fail_msg("Print err 0x%d; MSG: %s", _r, ly_err_last(_UC->ctx)->msg); \
163 } \
164 assert_string_equal(str, TEXT); \
165 free(str); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200166 }
167
168/**
169 * @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;
170 * @param[in] NODE_1 pointer to lyd_node
171 * @param[in] NODE_2 pointer to lyd_node
172 */
173#define CHECK_LYD(NODE_1, NODE_2) \
174 { \
Michal Vaskoddd76592022-01-17 13:34:48 +0100175 char *str1; \
176 char *str2; \
177 assert_int_equal(LY_SUCCESS, lyd_print_mem(&str1, NODE_1, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK)); \
178 assert_int_equal(LY_SUCCESS, lyd_print_mem(&str2, NODE_2, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK)); \
179 assert_non_null(str1); \
180 assert_non_null(str2); \
181 assert_string_equal(str1, str2); \
182 free(str1); \
183 free(str2); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200184 }
185
186/*
187 * SUPPORT MACROS
188 */
189
190/**
191 * @brief Internal macro witch assert that two given string are equal or are both null.
192 *
193 * @param[in] STRING string to check
194 * @param[in] TEXT string to compare
195 */
196#define CHECK_STRING(STRING, TEXT)\
197 if (TEXT == NULL) { \
198 assert_null(STRING); \
199 } else { \
200 assert_non_null(STRING); \
201 assert_string_equal(STRING, TEXT); \
202 }
203
204/**
205 * @brief Internal macro witch assert that pointer is null when flag is 0.
206 *
207 * @param[in] POINTER pointer to check
208 * @param[in] FLAG 0 -> pointer is NULL, 1 -> pointer is not null
209 */
210#define CHECK_POINTER(POINTER, FLAG) \
211 assert_true(FLAG == 0 ? POINTER == NULL : POINTER != NULL)
212
213/**
214 * @brief Internal macro check size of [sized array](@ref sizedarrays)'s
215 *
216 * @param[in] ARRAY pointer to [sized array](@ref sizedarrays)
217 * @param[in] SIZE expected [sized array](@ref sizedarrays) size of array
218 */
219#define CHECK_ARRAY(ARRAY, SIZE) \
220 assert_true((SIZE == 0) ? \
221 (ARRAY == NULL) : \
222 (ARRAY != NULL && SIZE == LY_ARRAY_COUNT(ARRAY)));
223
224/*
225 * LIBYANG NODE CHECKING
226 */
227
228/**
Radek Išaa9ff2b82021-01-13 21:44:13 +0100229 * @brief check compileted type
Michal Vaskoddd76592022-01-17 13:34:48 +0100230 *
Radek Išaa9ff2b82021-01-13 21:44:13 +0100231 * @param[in] NODE pointer to lysc_type value
232 * @param[in] TYPE expected type [LY_DATA_TYPE](@ref LY_DATA_TYPE)
233 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
234 */
235#define CHECK_LYSC_TYPE(NODE, TYPE, EXTS) \
236 assert_non_null(NODE); \
237 assert_int_equal((NODE)->basetype, TYPE); \
238 CHECK_ARRAY((NODE)->exts, EXTS); \
Radek Krejci3e6632f2021-03-22 22:08:21 +0100239 assert_ptr_equal((NODE)->plugin, lyplg_find(LYPLG_TYPE, "", NULL, ly_data_type2str[TYPE]))
Radek Išaa9ff2b82021-01-13 21:44:13 +0100240
Michal Vaskoddd76592022-01-17 13:34:48 +0100241/**
242 * @brief check compileted numeric type
243 *
Radek Išaa9ff2b82021-01-13 21:44:13 +0100244 * @param[in] NODE pointer to lysc_type_num value
245 * @param[in] TYPE expected type [LY_DATA_TYPE](@ref LY_DATA_TYPE)
246 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
247 * @warning only integer types INT, UINT, NUM
248 */
249#define CHECK_LYSC_TYPE_NUM(NODE, TYPE, EXTS, RANGE) \
250 CHECK_LYSC_TYPE(NODE, TYPE, EXTS);\
251 CHECK_POINTER((NODE)->range, RANGE)
252
Michal Vaskoddd76592022-01-17 13:34:48 +0100253/**
254 * @brief check compiled string type
255 *
Radek Išaa9ff2b82021-01-13 21:44:13 +0100256 * @param[in] NODE pointer to lysc_type_num value
257 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
258 * @param[in] LENGTH 0 -> node dosnt have length limitation, 1 -> node have length limitation
259 * @param[in] PATTERNS expected number of patterns [sized array](@ref sizedarrays)
260 * @warning only integer types INT, UINT, NUM
261 */
262#define CHECK_LYSC_TYPE_STR(NODE, EXTS, LENGTH, PATTERNS) \
263 CHECK_LYSC_TYPE(NODE, LY_TYPE_STRING, EXTS); \
264 CHECK_POINTER((NODE)->length, LENGTH); \
265 CHECK_ARRAY((NODE)->patterns, PATTERNS)
266
Michal Vaskoddd76592022-01-17 13:34:48 +0100267/**
268 * @brief check compiled bits type
269 *
Radek Išaded31052021-03-10 13:22:53 +0100270 * @param[in] NODE pointer to lysc_type_num value
271 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
272 * @param[in] BITS expected number of bits
273 * @warning only integer types INT, UINT, NUM
274 */
275#define CHECK_LYSC_TYPE_BITS(NODE, EXTS, BITS) \
276 CHECK_LYSC_TYPE(NODE, LY_TYPE_BITS, EXTS); \
277 CHECK_ARRAY((NODE)->bits, BITS)
278
Radek Išaded31052021-03-10 13:22:53 +0100279#define CHECK_LYSC_TYPE_BITENUM_ITEM(NODE, POSITION, DSC, EXTS, FLAGS, NAME, REF)\
280 assert_non_null(NODE); \
281 assert_int_equal((NODE)->position, POSITION); \
282 CHECK_STRING((NODE)->dsc, DSC); \
283 CHECK_ARRAY((NODE)->exts, EXTS); \
284 assert_int_equal((NODE)->flags, FLAGS); \
285 CHECK_STRING((NODE)->name, NAME); \
286 CHECK_STRING((NODE)->ref, REF) \
287
Michal Vaskoddd76592022-01-17 13:34:48 +0100288/**
289 * @brief check range
290 *
Radek Išaa9ff2b82021-01-13 21:44:13 +0100291 * @param[in] NODE pointer to lysc_range value
292 * @param[in] DSC expected descriptin (string)
293 * @param[in] EAPPTAG expected string reprezenting error-app-tag value
294 * @param[in] EMSG expected string reprezenting error message
295 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
296 * @param[in] PARTS expected [sized array](@ref sizedarrays) number of rang limitations
297 * @param[in] REF expected reference
298 */
299#define CHECK_LYSC_RANGE(NODE, DSC, EAPPTAG, EMSG, EXTS, PARTS, REF) \
300 assert_non_null(NODE); \
301 CHECK_STRING((NODE)->dsc, DSC); \
302 CHECK_STRING((NODE)->eapptag, EAPPTAG); \
303 CHECK_STRING((NODE)->emsg, EMSG); \
304 CHECK_ARRAY((NODE)->exts, EXTS); \
305 CHECK_ARRAY((NODE)->parts, PARTS); \
306 CHECK_STRING((NODE)->ref, REF)
307
Michal Vaskoddd76592022-01-17 13:34:48 +0100308/**
309 * @brief check pattern
310 *
Radek Išaa9ff2b82021-01-13 21:44:13 +0100311 * @param[in] NODE pointer to lysc_pattern value
312 * @param[in] DSC expected descriptin (string)
313 * @param[in] EAPPTAG expected string reprezenting error-app-tag value
314 * @param[in] EMSG expected string reprezenting error message
315 * @param[in] EEXPR expected string reprezenting original, not compiled, regular expression
316 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
317 * @param[in] INVERTED if regular expression is inverted.
318 * @param[in] REF expected reference
319 */
320#define CHECK_LYSC_PATTERN(NODE, DSC, EAPPTAG, EMSG, EXPR, EXTS, INVERTED, REF) \
321 assert_non_null(NODE); \
322 assert_non_null((NODE)->code); \
323 CHECK_STRING((NODE)->dsc, DSC); \
324 CHECK_STRING((NODE)->eapptag, EAPPTAG); \
325 CHECK_STRING((NODE)->emsg, EMSG); \
326 CHECK_STRING((NODE)->expr, EXPR); \
327 CHECK_ARRAY((NODE)->exts, EXTS); \
328 assert_int_equal((NODE)->inverted, INVERTED); \
329 CHECK_STRING((NODE)->ref, REF)
330
331/**
Radek Iša56ca9e42020-09-08 18:42:00 +0200332 * @brief assert that lysp_action_inout structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100333 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200334 * @param[in] NODE pointer to lysp_action_inout variable
335 * @param[in] DATA 0 -> check if pointer to data is NULL, 1 -> check if pointer to data is not null
336 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
337 * @param[in] GROUPINGS expected [sized array](@ref sizedarrays) size of grouping list
338 * @param[in] MUSTS expected [sized array](@ref sizedarrays) size of must restriction list
339 * @param[in] NODETYPE node type. LYS_INPUT or LYS_OUTPUT
340 * @param[in] PARENT 0 -> check if node is root, 1 -> check if node is not root
341 * @param[in] TYPEDEFS expected [sized array](@ref sizedarrays) size of typedefs list
342 */
343#define CHECK_LYSP_ACTION_INOUT(NODE, DATA, EXTS, GROUPINGS, MUSTS, NODETYPE, PARENT, TYPEDEFS) \
344 assert_non_null(NODE); \
Radek Krejci01180ac2021-01-27 08:48:22 +0100345 CHECK_POINTER((NODE)->child, DATA); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200346 CHECK_ARRAY((NODE)->exts, EXTS); \
Radek Krejci2a9fc652021-01-22 17:44:34 +0100347 CHECK_POINTER((NODE)->groupings, GROUPINGS); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200348 CHECK_ARRAY((NODE)->musts, MUSTS); \
349 assert_int_equal((NODE)->nodetype, NODETYPE); \
350 CHECK_POINTER((NODE)->parent, PARENT); \
351 CHECK_ARRAY((NODE)->typedefs, TYPEDEFS);
352
353/**
354 * @brief assert that lysp_action structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100355 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200356 * @param[in] NODE pointer to lysp_action variable
357 * @param[in] DSC expected description
358 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extension list
359 * @param[in] FLAGS expected [schema node flags](@ref snodeflags)
360 * @param[in] GROUPINGS expected [sized array](@ref sizedarrays) size of grouping list
361 * @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of if-feature expressions list
362 * @param[in] INPUT_* ::LYSP_ACTION_INOUT_CHECK
363 * @param[in] NAME expected name
364 * @param[in] NODETYPE node type. LYS_RPC or LYS_ACTION
365 * @param[in] OUTPUT_* ::LYSP_ACTION_INOUT_CHECK
366 * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
367 * @param[in] REF expected reference
368 * @param[in] TYPEDEFS expected [sized array](@ref sizedarrays) size of list of typedefs
369 */
370#define CHECK_LYSP_ACTION(NODE, DSC, EXTS, FLAGS, GROUPINGS, IFFEATURES, \
371 INPUT_DATA, INPUT_EXTS, INPUT_GROUPINGS, INPUT_MUSTS, \
372 INPUT_PARENT, INPUT_TYPEDEFS, \
373 NAME, NODETYPE, \
374 OUTPUT_DATA, OUTPUT_EXTS, OUTPUT_GROUPINGS, OUTPUT_MUSTS, \
375 OUTPUT_PARENT, OUTPUT_TYPEDEFS, \
376 PARENT, REF, TYPEDEFS) \
377 assert_non_null(NODE); \
378 CHECK_STRING((NODE)->dsc, DSC); \
379 CHECK_ARRAY((NODE)->exts, EXTS); \
380 assert_int_equal((NODE)->flags, FLAGS); \
Radek Krejci2a9fc652021-01-22 17:44:34 +0100381 CHECK_POINTER((NODE)->groupings, GROUPINGS); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200382 CHECK_ARRAY((NODE)->iffeatures, IFFEATURES); \
383 CHECK_LYSP_ACTION_INOUT(&((NODE)->input), INPUT_DATA, INPUT_EXTS, INPUT_GROUPINGS, \
384 INPUT_MUSTS, LYS_INPUT, INPUT_PARENT, INPUT_TYPEDEFS); \
385 assert_string_equal((NODE)->name, NAME); \
386 assert_int_equal((NODE)->nodetype, NODETYPE); \
387 CHECK_LYSP_ACTION_INOUT(&((NODE)->output), OUTPUT_DATA, OUTPUT_EXTS, OUTPUT_GROUPINGS, \
388 OUTPUT_MUSTS, LYS_OUTPUT, OUTPUT_PARENT, OUTPUT_TYPEDEFS); \
389 CHECK_POINTER((NODE)->parent, PARENT); \
390 CHECK_STRING((NODE)->ref, REF); \
391 CHECK_ARRAY((NODE)->typedefs, TYPEDEFS) \
392
393/**
394 * @brief assert that lysp_when structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100395 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200396 * @param[in] NODE pointer to lysp_when variable
397 * @param[in] COND expected string specifid condition
398 * @param[in] DSC expected string description statement
399 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension array
400 * @param[in] REF expected string reference
401 */
402#define CHECK_LYSP_WHEN(NODE, COND, DSC, EXTS, REF) \
403 assert_non_null(NODE); \
404 assert_string_equal((NODE)->cond, COND); \
405 CHECK_STRING((NODE)->dsc, DSC); \
406 CHECK_ARRAY((NODE)->exts, EXTS); \
407 if (REF == NULL) { \
408 assert_null((NODE)->ref); \
409 } else { \
410 assert_non_null((NODE)->ref); \
411 assert_string_equal((NODE)->ref, REF); \
412 }
413
414/**
415 * @brief assert that lysp_restr structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100416 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200417 * @param[in] NODE pointer to lysp_restr variable
418 * @param[in] ARG_STR expected string. The restriction expression/value
419 * @param[in] DSC expected descrition
420 * @param[in] EAPPTAG expected string reprezenting error-app-tag value
421 * @param[in] EMSG expected string reprezenting error message
422 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension array
423 * @param[in] REF expected reference
424 */
425
426#define CHECK_LYSP_RESTR(NODE, ARG_STR, DSC, EAPPTAG, EMSG, EXTS, REF) \
427 assert_non_null(NODE); \
428 assert_non_null((NODE)->arg.mod); \
429 assert_string_equal((NODE)->arg.str, ARG_STR); \
430 CHECK_STRING((NODE)->dsc, DSC); \
431 CHECK_STRING((NODE)->eapptag, EAPPTAG); \
432 CHECK_STRING((NODE)->emsg, EMSG); \
433 CHECK_ARRAY((NODE)->exts, EXTS); \
434 CHECK_STRING((NODE)->ref, REF);
435
436/**
437 * @brief assert that lysp_import structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100438 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200439 * @param[in] NODE pointer to lysp_import variable
440 * @param[in] DSC expected description or NULL
441 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extensions
442 * @param[in] NAME expected name of imported module
443 * @param[in] PREFIX expected prefix for the data from the imported schema
444 * @param[in] REF expected reference
445 * @prame[in] REV expected reprezenting date in format "11-10-2020"
446 */
447#define CHECK_LYSP_IMPORT(NODE, DSC, EXTS, NAME, PREFIX, REF, REV) \
448 assert_non_null(NODE); \
449 CHECK_STRING((NODE)->dsc, DSC); \
450 CHECK_ARRAY((NODE)->exts, EXTS); \
451 /*assert_non_null((NODE)->module); // ?? it is mandatory but in some test it doesnt work */ \
452 assert_string_equal((NODE)->name, NAME); \
453 assert_string_equal((NODE)->prefix, PREFIX); \
454 CHECK_STRING((NODE)->ref, REF); \
455 CHECK_STRING((NODE)->rev, REV); \
456
457/**
458 * @brief assert that lysp_ext structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100459 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200460 * @param[in] NODE pointer to lysp_ext_instance variable
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100461 * @param[in] ARGNAME expected argument name
Radek Iša56ca9e42020-09-08 18:42:00 +0200462 * @param[in] COMPILED 0 -> compiled data dosnt exists, 1 -> compiled data exists
463 * @param[in] DSC expected string reprezent description
464 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension instances
465 * @param[in] FLAGS expected LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags)
466 * @param[in] NAME expected name
467 * @param[in] REF expected ref
468 */
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100469#define CHECK_LYSP_EXT(NODE, ARGNAME, COMPILED, DSC, EXTS, FLAGS, NAME, REF) \
Radek Iša56ca9e42020-09-08 18:42:00 +0200470 assert_non_null(NODE); \
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100471 CHECK_STRING((NODE)->argname, ARGNAME); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200472 CHECK_POINTER((NODE)->compiled, COMPILED); \
473 CHECK_STRING((NODE)->dsc, DSC); \
474 CHECK_ARRAY((NODE)->exts, EXTS); \
475 assert_int_equal((NODE)->flags, FLAGS); \
476 assert_string_equal((NODE)->name, NAME); \
477 CHECK_STRING((NODE)->ref, REF);
478
479/**
480 * @brief assert that lysp_ext_instance structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100481 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200482 * @param[in] NODE pointer to lysp_ext_instance variable
483 * @param[in] ARGUMENT expected optional value of the extension's argument
484 * @param[in] CHILD 0 -> node doesnt have child, 1 -> node have children
Radek Krejciab430862021-03-02 20:13:40 +0100485 * @param[in] PARENT_STMT expected value identifying placement of the extension instance
486 * @param[in] PARENT_STMT_INDEX expected indentifi index
Michal Vaskofc2cd072021-02-24 13:17:17 +0100487 * @param[in] FORMAT expected format
Radek Iša56ca9e42020-09-08 18:42:00 +0200488 */
Radek Krejci85ac8312021-03-03 20:21:33 +0100489#define CHECK_LYSP_EXT_INSTANCE(NODE, ARGUMENT, CHILD, PARENT_STMT, PARENT_STMT_INDEX, NAME, FORMAT) \
Radek Iša56ca9e42020-09-08 18:42:00 +0200490 assert_non_null(NODE); \
491 CHECK_STRING((NODE)->argument, ARGUMENT); \
492 CHECK_POINTER((NODE)->child, CHILD); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200493 /*assert_int_equal((NODE)->flags, LYS_INTERNAL);*/ \
Radek Krejciab430862021-03-02 20:13:40 +0100494 assert_int_equal((NODE)->parent_stmt, PARENT_STMT); \
495 assert_int_equal((NODE)->parent_stmt_index, PARENT_STMT_INDEX); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200496 assert_string_equal((NODE)->name, NAME); \
Michal Vaskofc2cd072021-02-24 13:17:17 +0100497 assert_int_equal((NODE)->format, FORMAT);
Radek Iša56ca9e42020-09-08 18:42:00 +0200498
499/**
500 * @brief assert that lysp_stmt structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100501 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200502 * @param[in] NODE pointer to lysp_stmt variable
503 * @param[in] ARG expected statemet argumet
504 * @param[in] CHILD 0 -> node doesnt have child, 1 -> node have children
505 * @param[in] FLAGS expected statement flags, can be set to LYS_YIN_ATTR
506 * @param[in] KW expected numeric respresentation of the stmt value
507 * @param[in] NEXT 0 -> pointer is NULL, 1 -> pointer is not null
508 * @param[in] STMS expected identifier of the statement
509 */
510#define CHECK_LYSP_STMT(NODE, ARG, CHILD, FLAGS, KW, NEXT, STMT) \
511 assert_non_null(NODE); \
512 CHECK_STRING((NODE)->arg, ARG); \
513 CHECK_POINTER((NODE)->child, CHILD); \
514 assert_int_equal((NODE)->flags, FLAGS); \
515 assert_int_equal((NODE)->kw, KW); \
516 CHECK_POINTER((NODE)->next, NEXT); \
517 assert_string_equal((NODE)->stmt, STMT); \
518
519/**
520 * @brief assert that lysp_type_enum structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100521 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200522 * @param[in] NODE pointer to lysp_type_enum variable
523 * @param[in] DSC expected description
524 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
525 * @param[in] FLAGS only LYS_STATUS_ and LYS_SET_VALUE values are allowed
526 * @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of list of the extension instances
527 * @param[in] NAME expected name
528 * @param[in] REF expected reference statement
529 * @param[in] VALUE expected enum's value or bit's position
530 */
531#define CHECK_LYSP_TYPE_ENUM(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, REF, VALUE) \
532 assert_non_null(NODE); \
533 CHECK_STRING((NODE)->dsc, DSC); \
534 CHECK_ARRAY((NODE)->exts, EXTS); \
535 assert_int_equal((NODE)->flags, FLAGS); \
536 CHECK_ARRAY((NODE)->iffeatures, IFFEATURES); \
537 CHECK_STRING((NODE)->name, NAME); \
538 CHECK_STRING((NODE)->ref, REF); \
539 assert_int_equal(VALUE, (NODE)->value);
540
541/**
Radek Išaa9ff2b82021-01-13 21:44:13 +0100542 * @brief assert that lysp_type_enum structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100543 *
Radek Išaa9ff2b82021-01-13 21:44:13 +0100544 * @param[in] NODE pointer to lysp_type variable
545 * @param[in] BASES expected [sized array](@ref sizedarrays) size of list of indentifiers
546 * @param[in] BITS expected [sized array](@ref sizedarrays) size of list of bits
547 * @param[in] COMPILED 0 -> pointer to compiled type is null, 1 -> pointer to compilet type is valid
548 * @param[in] ENUMS expected [sized array](@ref sizedarrays) size of list of enums-stmts
549 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension instances
550 * @param[in] FLAGS expected flags
551 * @param[in] FRACTION_DIGITS expected number of fraction digits decimal64
552 * @param[in] LENGTH expected 0 -> there isnt any restriction on length, 1 -> type is restricted on length (string, binary)
553 * @param[in] NAME expected name of type
554 * @param[in] PATH 0 -> no pointer to parsed path, 1 -> pointer to parsed path is valid
555 * @param[in] PATTERNS expected [sized array](@ref sizedarrays) size of list of patterns for string
556 * @param[in] PMOD expected submodule where type is defined 0 -> pointer is null, 1 -> pointer is not null
557 * @param[in] RANGE expected [sized array](@ref sizedarrays) size of list of range restriction
558 * @param[in] REQUIRE_INSTANCE expected require instance flag
559 * @param[in] TYPES expected [sized array](@ref sizedarrays) size of list of sub-types
560 */
561#define CHECK_LYSP_TYPE(NODE, BASES, BITS, COMPILED, ENUMS, EXTS, FLAGS, FRACTIONS_DIGITS, \
562 LENGTH, NAME, PATH, PATTERNS, PMOD, RANGE, REQUIRE_INSTANCE, TYPES) \
563 assert_non_null(NODE);\
564 CHECK_ARRAY((NODE)->bases, BASES); \
565 CHECK_ARRAY((NODE)->bits, BITS); \
566 CHECK_POINTER((NODE)->compiled, COMPILED); \
567 CHECK_ARRAY((NODE)->enums, ENUMS); \
568 CHECK_ARRAY((NODE)->exts, EXTS); \
569 assert_int_equal((NODE)->flags, FLAGS); \
570 assert_int_equal((NODE)->fraction_digits, FRACTIONS_DIGITS); \
571 CHECK_POINTER((NODE)->length, LENGTH); \
572 CHECK_STRING((NODE)->name, NAME); \
573 CHECK_POINTER((NODE)->path, PATH); \
574 CHECK_ARRAY((NODE)->patterns, PATTERNS); \
575 CHECK_POINTER((NODE)->pmod, PMOD); \
576 CHECK_POINTER((NODE)->range, RANGE); \
577 assert_int_equal((NODE)->require_instance, REQUIRE_INSTANCE); \
578 CHECK_ARRAY((NODE)->types , TYPES)
579
580/**
Radek Iša56ca9e42020-09-08 18:42:00 +0200581 * @brief assert that lysp_node structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100582 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200583 * @param[in] NODE pointer to lysp_node variable
584 * @param[in] DSC expected description statement
585 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
586 * @param[in] FLAGS [schema node flags](@ref snodeflags)
587 * @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of list of the extension instances
588 * @param[in] NAME expected name
589 * @param[in] NEXT 0 pointer is null, 1 pointer is not null
590 * @param[in] NODETYPE node type LYS_UNKNOWN, LYS_CONTAINER, LYS_CHOICE, LYS_LEAF, LYS_LEAFLIST,
591 * LYS_LIST, LYS_ANYXML, LYS_ANYDATA, LYS_CASE, LYS_RPC, LYS_ACTION, LYS_NOTIF,
592 * LYS_USES, LYS_INPUT, LYS_OUTPUT, LYS_GROUPING, LYS_AUGMENT
593 * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
594 * @param[in] REF expected reference statement
595 * @param[in] WHEN 0-> pointer is null, 1 -> pointer is not null
596 */
597#define CHECK_LYSP_NODE(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, NEXT, NODETYPE, PARENT, REF, WHEN) \
598 assert_non_null(NODE); \
599 CHECK_STRING((NODE)->dsc, DSC); \
600 CHECK_ARRAY((NODE)->exts, EXTS); \
601 assert_int_equal((NODE)->flags, FLAGS); \
602 CHECK_ARRAY((NODE)->iffeatures, IFFEATURES); \
603 CHECK_STRING((NODE)->name, NAME); \
604 CHECK_POINTER((NODE)->next, NEXT); \
605 assert_int_equal((NODE)->nodetype, NODETYPE); \
606 CHECK_POINTER((NODE)->parent, PARENT); \
607 CHECK_STRING((NODE)->ref, REF); \
Radek Krejci9a3823e2021-01-27 20:26:46 +0100608 CHECK_POINTER(lysp_node_when((struct lysp_node *)NODE), WHEN);
Radek Iša56ca9e42020-09-08 18:42:00 +0200609
610/**
Radek Išaa9ff2b82021-01-13 21:44:13 +0100611 * @brief assert that lysp_node structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100612 *
Radek Išaa9ff2b82021-01-13 21:44:13 +0100613 * @param[in] NODE pointer to lysp_node variable
614 * @param[in] DSC expected description statement
615 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
616 * @param[in] FLAGS [schema node flags](@ref snodeflags)
617 * @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of list of the extension instances
618 * @param[in] NAME expected name
619 * @param[in] NEXT 0 pointer is null, 1 pointer is not null
620 * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
621 * @param[in] REF expected reference statement
622 * @param[in] WHEN 0-> pointer is null, 1 -> pointer is not null
623 * @param[in] MUSTS expected [sized array](@ref sizedarrays) size of list of must restriction
624 * @param[in] UNITS expected string reprezenting units
625 * @param[in] DFLT 0-> node dosn't have default value. 1 -> node have default value
626 */
627#define CHECK_LYSP_NODE_LEAF(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, NEXT, \
628 PARENT, REF, WHEN, MUSTS, UNITS, DFLT) \
629 CHECK_LYSP_NODE(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, NEXT, LYS_LEAF, PARENT, REF, WHEN); \
630 CHECK_ARRAY((NODE)->musts, MUSTS); \
631 CHECK_STRING((NODE)->units, UNITS); \
632 CHECK_STRING((NODE)->dflt.str, DFLT);
633
634/**
Radek Iša56ca9e42020-09-08 18:42:00 +0200635 * @brief assert that lysc_notif structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100636 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200637 * @param[in] NODE pointer to lysp_notif variable
638 * @param[in] DATA 0 pointer is null, 1 pointer is not null
639 * @param[in] DSC expected description
640 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
641 * @param[in] FLAGS [schema node flags](@ref snodeflags)
642 * @param[in] MODULE 0 pointer is null, 1 pointer is not null
643 * @param[in] MUSTS expected [sized array](@ref sizedarrays) size of list of must restriction
644 * @param[in] NAME expected name
645 * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
646 * @param[in] PRIV 0-> pointer is null, 1-> pointer is not null
647 * @param[in] REF expected reference
648 * @param[in] WHEN expected [sized array](@ref sizedarrays) size of list of pointers to when statements
649 */
650#define CHECK_LYSC_NOTIF(NODE, DATA, DSC, EXTS, FLAGS, MODULE, MUSTS, NAME, PARENT, PRIV, REF, WHEN) \
651 assert_non_null(NODE); \
Radek Krejci01180ac2021-01-27 08:48:22 +0100652 CHECK_POINTER((NODE)->child, DATA); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200653 CHECK_STRING((NODE)->dsc, DSC); \
654 CHECK_ARRAY((NODE)->exts, EXTS); \
655 assert_int_equal((NODE)->flags, FLAGS); \
656 CHECK_POINTER((NODE)->module, MODULE); \
657 CHECK_ARRAY((NODE)->musts, MUSTS); \
658 assert_string_equal((NODE)->name, NAME); \
659 assert_int_equal((NODE)->nodetype, LYS_NOTIF); \
660 CHECK_POINTER((NODE)->parent, PARENT); \
661 CHECK_POINTER((NODE)->priv, PRIV); \
662 CHECK_STRING((NODE)->ref, REF); \
Radek Išaa9ff2b82021-01-13 21:44:13 +0100663 CHECK_ARRAY(lysc_node_when((const struct lysc_node *)NODE), WHEN);
Radek Iša56ca9e42020-09-08 18:42:00 +0200664
665/**
666 * @brief assert that lysc_action_inout structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100667 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200668 * @param[in] NODE pointer to lysp_notif variable
669 * @param[in] DATA 0 pointer is null, 1 pointer is not null
670 * @param[in] MUST expected [sized array](@ref sizedarrays) size of list of must restrictions
671 * @param[in] NODETYPE LYS_INPUT or LYS_OUTPUT
672 */
673#define CHECK_LYSC_ACTION_INOUT(NODE, DATA, MUST, NODETYPE) \
674 assert_non_null(NODE); \
Radek Krejci01180ac2021-01-27 08:48:22 +0100675 CHECK_POINTER((NODE)->child, DATA); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200676 CHECK_ARRAY((NODE)->musts, MUST); \
677 assert_int_equal((NODE)->nodetype, NODETYPE);
678
679/**
680 * @brief assert that lysc_action structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100681 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200682 * @param[in] NODE pointer to lysp_action variable
683 * @param[in] DSC string description statement
684 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
685 * @param[in] FLAGS [schema node flags](@ref snodeflags)
686 * @param[in] INPUT_DATA 0 pointer is null, 1 pointer is not null
687 * @param[in] INPUT_MUST expected [sized array](@ref sizedarrays) size of input list of must restrictions
688 * @param[in] INPUT_EXTS expected [sized array](@ref sizedarrays) size of the input extension instances of input
689 * @param[in] MODULE 0 pointer is null, 1 pointer is not null
690 * @param[in] NAME expected name
691 * @param[in] NODETYPE LYS_RPC, LYS_ACTION
692 * @param[in] OUTPUT_DATA 0 pointer is null, 1 pointer is not null
693 * @param[in] OUTPUT_MUST expected [sized array](@ref sizedarrays) size of output list of must restrictions
694 * @param[in] OUTPUT_EXTS expected [sized array](@ref sizedarrays) size of the output extension instances of input
695 * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
696 * @param[in] PRIV 0-> pointer is null, 1-> pointer is not null
697 * @param[in] REF expected reference
698 * @param[in] WHEN expected [sized array](@ref sizedarrays) size of list of pointers to when statements
699 */
700#define CHECK_LYSC_ACTION(NODE, DSC, EXTS, FLAGS, INPUT_DATA, INPUT_MUST, INPUT_EXTS, MODULE, NAME, NODETYPE, \
701 OUTPUT_DATA, OUTPUT_MUST, OUTPUT_EXTS, PARENT, PRIV, REF, WHEN) \
702 assert_non_null(NODE); \
703 CHECK_STRING((NODE)->dsc, DSC); \
704 CHECK_ARRAY((NODE)->exts, EXTS); \
705 assert_int_equal((NODE)->flags, FLAGS); \
706 CHECK_LYSC_ACTION_INOUT(&(NODE)->input, INPUT_DATA, INPUT_MUST, LYS_INPUT); \
Radek Krejci2a9fc652021-01-22 17:44:34 +0100707 CHECK_ARRAY((NODE)->input.exts, INPUT_EXTS); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200708 CHECK_POINTER((NODE)->module, MODULE); \
709 assert_string_equal((NODE)->name, NAME); \
710 assert_int_equal((NODE)->nodetype, NODETYPE); \
711 CHECK_LYSC_ACTION_INOUT(&(NODE)->output, OUTPUT_DATA, OUTPUT_MUST, LYS_OUTPUT); \
Radek Krejci2a9fc652021-01-22 17:44:34 +0100712 CHECK_ARRAY((NODE)->output.exts, OUTPUT_EXTS); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200713 CHECK_POINTER((NODE)->parent, PARENT); \
714 CHECK_POINTER((NODE)->priv, PRIV); \
715 CHECK_STRING((NODE)->ref, REF); \
Radek Išaa9ff2b82021-01-13 21:44:13 +0100716 CHECK_ARRAY(lysc_node_when((const struct lysc_node *)NODE), WHEN);
Radek Iša56ca9e42020-09-08 18:42:00 +0200717
718/**
719 * @brief assert that lysc_node structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100720 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200721 * @param[in] NODE pointer to lysc_node variable
722 * @param[in] DSC expected description
723 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
724 * @param[in] FLAGS [schema node flags](@ref snodeflags)
725 * @param[in] MODULE 0 pointer is null, 1 pointer is not null
726 * @param[in] NAME expected name
727 * @param[in] NEXT 0 pointer is null, 1 pointer is not null
728 * @param[in] NODETYPE type of the node LYS_UNKNOWN, LYS_CONTAINER, LYS_CHOICE, LYS_LEAF,
729 * LYS_LEAFLIST, LYS_LIST, LYS_ANYXML, LYS_ANYDATA, LYS_CASE, LYS_RPC,
730 * LYS_ACTION, LYS_NOTIF, LYS_USES, LYS_INPUT, LYS_OUTPUT, LYS_GROUPING,
731 * LYS_AUGMENT
732 * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
733 * @param[in] PRIV 0-> pointer is null, 1-> pointer is not null
734 * @param[in] REF expected reference
735 * @param[in] WHEN expected [sized array](@ref sizedarrays) size of list of pointers to when statements
736 */
737#define CHECK_LYSC_NODE(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, NODETYPE, PARENT, PRIV, REF, WHEN) \
738 assert_non_null(NODE); \
739 CHECK_STRING((NODE)->dsc, DSC); \
740 CHECK_ARRAY((NODE)->exts, EXTS); \
741 assert_int_equal((NODE)->flags, FLAGS); \
742 CHECK_POINTER((NODE)->module, MODULE); \
743 assert_string_equal((NODE)->name, NAME); \
744 CHECK_POINTER((NODE)->next, NEXT); \
745 assert_int_equal((NODE)->nodetype, NODETYPE); \
746 CHECK_POINTER((NODE)->parent, PARENT); \
747 assert_non_null((NODE)->prev); \
748 CHECK_POINTER((NODE)->priv, PRIV); \
749 CHECK_STRING((NODE)->ref, REF); \
Radek Išaa9ff2b82021-01-13 21:44:13 +0100750 CHECK_ARRAY(lysc_node_when((const struct lysc_node *)NODE), WHEN);
751
752/**
753 * @brief assert that lysc_node_leaf structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100754 *
Radek Išaa9ff2b82021-01-13 21:44:13 +0100755 * @param[in] NODE pointer to lysc_node variable
756 * @param[in] DSC expected description
757 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
758 * @param[in] FLAGS [schema node flags](@ref snodeflags)
759 * @param[in] MODULE 0 pointer is null, 1 pointer is not null
760 * @param[in] NAME expected name
761 * @param[in] NEXT 0 pointer is null, 1 pointer is not null
762 * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
763 * @param[in] PRIV 0-> pointer is null, 1-> pointer is not null
764 * @param[in] REF expected reference
Radek Išaa76902f2021-03-29 08:52:51 +0200765 * @param[in] ACTIONS 1 if is set pointer to structure lysc_node_action other 0
766 * @param[in] CHILD 1 if is set pointer to child other 0
767 * @param[in] MAX possible maximum elements in list
768 * @param[in] MIN possible minimum elements in list
769 * @param[in] MUSTS [sized array](@ref sizedarrays) number of must node elements in array
770 * @param[in] NOTIFS 1 if is set pointer to any notifs node
771 * @param[in] UNIQUES [sized array](@ref sizedarrays) number of unique nodes element in array
772 * @param[in] WHEN [sized array](@ref sizedarrays) size of when node array
773 */
774#define CHECK_LYSC_NODE_LIST(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, \
775 PARENT, PRIV, REF, ACTIONS, CHILD, MAX, MIN, MUSTS, NOTIFS, UNIQUES, WHEN) \
776 CHECK_LYSC_NODE(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, LYS_LIST, PARENT, PRIV, REF, WHEN); \
777 CHECK_POINTER((NODE)->actions, ACTIONS); \
778 CHECK_POINTER((NODE)->child, CHILD); \
779 assert_int_equal((NODE)->max, MAX); \
780 assert_int_equal((NODE)->min, MIN); \
781 CHECK_ARRAY((NODE)->musts, MUSTS); \
782 CHECK_POINTER((NODE)->notifs, NOTIFS); \
783 CHECK_ARRAY((NODE)->uniques, UNIQUES); \
784 CHECK_ARRAY(lysc_node_when((const struct lysc_node *)NODE), WHEN)
785
786/**
787 * @brief assert that lysc_node_leaf structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100788 *
Radek Išaa76902f2021-03-29 08:52:51 +0200789 * @param[in] NODE pointer to lysc_node variable
790 * @param[in] DSC expected description
791 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
792 * @param[in] FLAGS [schema node flags](@ref snodeflags)
793 * @param[in] MODULE 0 pointer is null, 1 pointer is not null
794 * @param[in] NAME expected name
795 * @param[in] NEXT 0 pointer is null, 1 pointer is not null
796 * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
797 * @param[in] PRIV 0-> pointer is null, 1-> pointer is not null
798 * @param[in] REF expected reference
799 * @param[in] WHEN expected [sized array](@ref sizedarrays) size of list of pointers to when statements
Radek Išaa9ff2b82021-01-13 21:44:13 +0100800 * @param[in] MUSTS expected [sized array](@ref sizedarrays) size of list of must restriction
801 * @param[in] UNITS expected string reprezenting units
802 * @param[in] DFLT 0-> node dosn't have default value. 1 -> node have default value
803 */
804#define CHECK_LYSC_NODE_LEAF(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, \
805 PARENT, PRIV, REF, WHEN, MUSTS, UNITS, DFLT) \
806 CHECK_LYSC_NODE(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, LYS_LEAF, PARENT, PRIV, REF, WHEN); \
807 CHECK_ARRAY((NODE)->musts, MUSTS); \
808 assert_non_null((NODE)->type); \
809 CHECK_STRING((NODE)->units, UNITS); \
810 CHECK_POINTER((NODE)->dflt, DFLT);
Radek Iša56ca9e42020-09-08 18:42:00 +0200811
812/**
813 * @brief assert that lyd_meta structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100814 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200815 * @param[in] NODE pointer to lyd_meta variable
816 * @param[in] ANNOTATION 0 pointer is null, 1 pointer is not null
817 * @param[in] NAME expected name
818 * @param[in] NEXT 0 pointer is null, 1 pointer is not null
819 * @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT
820 * part of text reprezenting LY_DATA_TYPE.
821 * @param[in] ... ::CHECK_LYD_VALUE
822 */
823#define CHECK_LYD_META(NODE, ANNOTATION, NAME, NEXT, PARENT, TYPE_VAL, ...) \
824 assert_non_null(NODE); \
825 CHECK_POINTER((NODE)->annotation, ANNOTATION); \
826 assert_string_equal((NODE)->name, NAME); \
827 CHECK_POINTER((NODE)->next, NEXT); \
828 CHECK_POINTER((NODE)->parent, PARENT); \
Michal Vasko151ae6c2021-09-23 08:23:51 +0200829 CHECK_LYD_VALUE((NODE)->value, TYPE_VAL, __VA_ARGS__);
Radek Iša56ca9e42020-09-08 18:42:00 +0200830
831/**
832 * @brief assert that lyd_node_term structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100833 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200834 * @param[in] NODE pointer to lyd_node_term variable
835 * @param[in] FLAGS expected [data node flags](@ref dnodeflags)
836 * @param[in] META 0 -> meta is not prezent, 1 -> meta is prezent
837 * @param[in] NEXT 0 -> next node is not prezent, 1 -> next node is prezent
838 * @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT
839 * part of text reprezenting LY_DATA_TYPE.
840 * @param[in] ... ::CHECK_LYD_VALUE
841 */
842#define CHECK_LYD_NODE_TERM(NODE, FLAGS, META, NEXT, PARENT, SCHEMA, VALUE_TYPE, ...) \
843 assert_non_null(NODE); \
844 assert_int_equal((NODE)->flags, FLAGS); \
845 CHECK_POINTER((NODE)->meta, META); \
846 CHECK_POINTER((NODE)->next, NEXT); \
847 CHECK_POINTER((NODE)->parent, PARENT); \
848 assert_non_null((NODE)->prev); \
849 CHECK_POINTER((NODE)->schema, SCHEMA); \
Michal Vasko151ae6c2021-09-23 08:23:51 +0200850 CHECK_LYD_VALUE((NODE)->value, VALUE_TYPE, __VA_ARGS__);
Radek Iša56ca9e42020-09-08 18:42:00 +0200851
852/**
853 * @brief assert that lyd_node_any structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100854 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200855 * @param[in] NODE pointer to lyd_node_term variable
856 * @param[in] FLAGS expected [data node flags](@ref dnodeflags)
857 * @param[in] META 0 meta isnt present , 1 meta is present
858 * @param[in] PARENT 0 it is root node , 1 node have parent
859 * @param[in] VALUE_TYPE value type ::lyd_node_any.value
860 */
861#define CHECK_LYD_NODE_ANY(NODE, FLAGS, META, PARENT, VALUE_TYPE) \
862 assert_non_null(NODE); \
863 assert_int_equal((NODE)->flags, FLAGS); \
864 CHECK_POINTER((NODE)->meta, META); \
865 CHECK_POINTER((NODE)->meta, PARENT); \
866 assert_non_null((NODE)->prev); \
867 assert_non_null((NODE)->schema); \
868 assert_int_equal((NODE)->value_type, VALUE_TYPE);
869
870/**
871 * @brief assert that lyd_node_opaq structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100872 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200873 * @param[in] NODE pointer to lyd_node_opaq variable
874 * @param[in] ATTR 0 if pointer is null ,1 if pointer is not null
875 * @param[in] CHILD 0 if pointer is null ,1 if pointer is not null
876 * @param[in] FORMAT LY_PREF_XML or LY_PREF_JSON
877 * @param[in] VAL_PREFS 0 if pointer is null ,1 if pointer is not null
878 * @param[in] NAME expected name
879 * @param[in] value expected orignal value
880 */
881#define CHECK_LYD_NODE_OPAQ(NODE, ATTR, CHILD, FORMAT, NAME, NEXT, PARENT, PREFIX, VAL_PREFS, VALUE) \
882 assert_non_null(NODE); \
883 CHECK_POINTER((NODE)->attr, ATTR); \
884 CHECK_POINTER((NODE)->child, CHILD); \
885 assert_ptr_equal((NODE)->ctx, UTEST_LYCTX); \
886 assert_int_equal((NODE)->flags, 0); \
887 assert_true((NODE)->format == FORMAT); \
888 assert_int_equal((NODE)->hash, 0); \
889 assert_string_equal((NODE)->name.name, NAME); \
890 assert_non_null((NODE)->prev); \
891 assert_null((NODE)->schema); \
892 CHECK_POINTER((NODE)->val_prefix_data, VAL_PREFS); \
893 assert_string_equal((NODE)->value, VALUE);
894
895/**
Radek Išaa76902f2021-03-29 08:52:51 +0200896 * @brief assert that lyd_node_opaq structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100897 *
Radek Išaa76902f2021-03-29 08:52:51 +0200898 * @param[in] NODE pointer to lyd_node_opaq variable
899 * @param[in] CHILD 1 if node has children other 0
900 * @param[in] HILD_HT 1 if node has children hash table other 0
901 * @param[in] META 1 if node has metadata other 0
902 * @param[in] FLAGS expected flag
903 * @param[in] NEXT 1 if next node is present other 0
904 * @param[in] PARENT 1 if node has parent other 0
905 * @param[in] PRIV 1 if node has private data other 0
906 * @param[in] SCHEMA 1 if node has schema other 0
907*/
908#define CHECK_LYD_NODE_INNER(NODE, CHILD, CHILD_HT, META, FLAGS, NEXT, PARENT, PRIV, SCHEMA) \
909 assert_non_null(NODE); \
910 CHECK_POINTER((NODE)->child, CHILD); \
911 CHECK_POINTER((NODE)->children_ht, CHILD_HT); \
912 CHECK_POINTER((NODE)->meta, META); \
913 assert_int_equal((NODE)->flags, FLAGS); \
914 CHECK_POINTER((NODE)->parent, PARENT); \
915 assert_non_null((NODE)->prev); \
916 CHECK_POINTER((NODE)->next, NEXT); \
917 CHECK_POINTER((NODE)->priv, PRIV); \
918 CHECK_POINTER((NODE)->schema, SCHEMA)
919
920/**
Radek Iša56ca9e42020-09-08 18:42:00 +0200921 * @brief assert that lyd_value structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100922 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200923 * @param[in] NODE lyd_value
924 * @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT
925 * part of text reprezenting LY_DATA_TYPE.
926 * @param[in] ... Unspecified parameters. Type and numbers of parameters are specified
927 * by type of value. These parameters are passed to macro
928 * CHECK_LYD_VALUE_ ## TYPE_VAL.
929 */
930#define CHECK_LYD_VALUE(NODE, TYPE_VAL, ...) \
Michal Vasko151ae6c2021-09-23 08:23:51 +0200931 CHECK_LYD_VALUE_ ## TYPE_VAL (NODE, __VA_ARGS__);
Radek Iša56ca9e42020-09-08 18:42:00 +0200932
933/*
934 * LYD VALUES CHECKING SPECIALIZATION
935 */
936
937/**
938 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type EMPTY
939 * Example CHECK_LYD_VALUE(node->value, EMPTY, "");
Michal Vaskoddd76592022-01-17 13:34:48 +0100940 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200941 * @param[in] NODE lyd_value variable
942 * @param[in] CANNONICAL_VAL expected cannonical value
943 */
944#define CHECK_LYD_VALUE_EMPTY(NODE, CANNONICAL_VAL) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +0200945 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +0200946 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200947 assert_non_null((NODE).realtype); \
948 assert_int_equal((NODE).realtype->basetype, LY_TYPE_EMPTY);
949
950/**
951 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type UNION
952 * Example CHECK_LYD_VALUE(node->value, UNION, "12", INT8, "12", 12);
953 * @warning type of subvalue cannot be UNION. Example of calling
Michal Vaskoddd76592022-01-17 13:34:48 +0100954 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200955 * @param[in] NODE lyd_value variable
956 * @param[in] CANNONICAL_VAL expected cannonical value
957 * @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT
958 * @param[in] ... Unspecified parameters. Type and numbers of parameters are specified
959 * by type of value. These parameters are passed to macro
960 * CHECK_LYD_VALUE_ ## TYPE_VAL.
961 */
962#define CHECK_LYD_VALUE_UNION(NODE, CANNONICAL_VAL, TYPE_VAL, ...) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +0200963 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +0200964 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200965 assert_non_null((NODE).realtype); \
966 assert_int_equal(LY_TYPE_UNION, (NODE).realtype->basetype); \
967 assert_non_null((NODE).subvalue); \
968 assert_non_null((NODE).subvalue->prefix_data); \
Michal Vasko151ae6c2021-09-23 08:23:51 +0200969 CHECK_LYD_VALUE_ ## TYPE_VAL ((NODE).subvalue->value, __VA_ARGS__)
970
971/**
972 * @brief Internal macro. Get 1st variadic argument.
973 */
974#define _GETARG1(ARG1, ...) ARG1
Radek Iša56ca9e42020-09-08 18:42:00 +0200975
976/**
977 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type BITS
978 * Example arr[] = {"a", "b"}; CHECK_LYD_VALUE(node->value, BITS, "a b", arr);
Michal Vaskoddd76592022-01-17 13:34:48 +0100979 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200980 * @param[in] NODE lyd_value variable
981 * @param[in] CANNONICAL_VAL expected cannonical value
982 * @param[in] VALUE expected array of bits names
983 */
Michal Vasko151ae6c2021-09-23 08:23:51 +0200984#define CHECK_LYD_VALUE_BITS(NODE, ...) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +0200985 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Michal Vasko151ae6c2021-09-23 08:23:51 +0200986 assert_string_equal((NODE)._canonical, _GETARG1(__VA_ARGS__, DUMMY)); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200987 assert_non_null((NODE).realtype); \
988 assert_int_equal(LY_TYPE_BITS, (NODE).realtype->basetype); \
989 { \
Radek Išaded31052021-03-10 13:22:53 +0100990 const char *arr[] = { __VA_ARGS__ }; \
Michal Vasko151ae6c2021-09-23 08:23:51 +0200991 LY_ARRAY_COUNT_TYPE arr_size = (sizeof(arr) / sizeof(arr[0])) - 1; \
Michal Vaskoaa0ee622021-05-11 09:29:25 +0200992 struct lyd_value_bits *_val; \
993 LYD_VALUE_GET(&(NODE), _val); \
994 assert_int_equal(arr_size, LY_ARRAY_COUNT(_val->items)); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200995 for (LY_ARRAY_COUNT_TYPE it = 0; it < arr_size; it++) { \
Michal Vasko151ae6c2021-09-23 08:23:51 +0200996 assert_string_equal(arr[it + 1], _val->items[it]->name); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200997 } \
998 }
999
1000/**
1001 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type INST
Michal Vaskoddd76592022-01-17 13:34:48 +01001002 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001003 * @param[in] NODE lyd_value variable
1004 * @param[in] CANNONICAL_VAL expected cannonical value
1005 * @param[in] VALUE expected array of enum ly_path_pred_type
1006 * @brief Example enum arr[] = {0x0, 0x1}; CHECK_LYD_VALUE(node->value, INST, "test/d", arr);
1007 */
1008#define CHECK_LYD_VALUE_INST(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001009 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001010 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001011 assert_non_null((NODE).realtype); \
1012 assert_int_equal(LY_TYPE_INST, (NODE).realtype->basetype); \
1013 { \
Michal Vasko79135ae2020-12-16 10:08:35 +01001014 LY_ARRAY_COUNT_TYPE arr_size = sizeof(VALUE) / sizeof(VALUE[0]); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001015 assert_int_equal(arr_size, LY_ARRAY_COUNT((NODE).target)); \
1016 for (LY_ARRAY_COUNT_TYPE it = 0; it < arr_size; it++) { \
1017 assert_int_equal(VALUE[it], (NODE).target[it].pred_type); \
1018 } \
1019 }
1020
1021/**
1022 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type ENUM.
1023 * Example CHECK_LYD_VALUE(node->value, ENUM, "item_name", "item_name");
Michal Vaskoddd76592022-01-17 13:34:48 +01001024 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001025 * @param[in] NODE lyd_value variable
1026 * @param[in] CANNONICAL_VAL expected cannonical value
1027 * @param[in] VALUE expected enum item name
1028 */
1029#define CHECK_LYD_VALUE_ENUM(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001030 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001031 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001032 assert_non_null((NODE).realtype); \
1033 assert_int_equal(LY_TYPE_ENUM, (NODE).realtype->basetype); \
1034 assert_string_equal(VALUE, (NODE).enum_item->name);
1035
1036/**
1037 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type INT8
1038 * Example CHECK_LYD_VALUE(node->value, INT8, "12", 12);
Michal Vaskoddd76592022-01-17 13:34:48 +01001039 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001040 * @param[in] NODE lyd_value variable
1041 * @param[in] CANNONICAL_VAL expected cannonical value
1042 * @param[in] VALUE expected inteager value (-128 to 127).
1043 */
1044#define CHECK_LYD_VALUE_INT8(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001045 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001046 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001047 assert_non_null((NODE).realtype); \
1048 assert_int_equal(LY_TYPE_INT8, (NODE).realtype->basetype); \
1049 assert_int_equal(VALUE, (NODE).int8);
1050
1051/**
1052 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type INT16
1053 * Example CHECK_LYD_VALUE(node->value, INT8, "12", 12);
Michal Vaskoddd76592022-01-17 13:34:48 +01001054 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001055 * @param[in] NODE lyd_value variable
1056 * @param[in] CANNONICAL_VAL expected cannonical value
1057 * @param[in] VALUE expected inteager value.
1058 */
1059#define CHECK_LYD_VALUE_INT16(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001060 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001061 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001062 assert_non_null((NODE).realtype); \
1063 assert_int_equal(LY_TYPE_INT16, (NODE).realtype->basetype); \
1064 assert_int_equal(VALUE, (NODE).int16);
1065
1066/**
1067 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type UINT8.
1068 * Example CHECK_LYD_VALUE(node->value, UINT8, "12", 12);
Michal Vaskoddd76592022-01-17 13:34:48 +01001069 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001070 * @param[in] NODE lyd_value variable
1071 * @param[in] CANNONICAL_VAL expected cannonical value
1072 * @param[in] VALUE expected inteager (0 to 255).
1073 */
1074#define CHECK_LYD_VALUE_UINT8(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001075 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001076 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001077 assert_non_null((NODE).realtype); \
1078 assert_int_equal(LY_TYPE_UINT8, (NODE).realtype->basetype); \
1079 assert_int_equal(VALUE, (NODE).uint8);
1080
1081/**
Radek Išaa76902f2021-03-29 08:52:51 +02001082 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type UINT32.
1083 * Example CHECK_LYD_VALUE(node->value, UINT32, "12", 12);
Michal Vaskoddd76592022-01-17 13:34:48 +01001084 *
Radek Išaa76902f2021-03-29 08:52:51 +02001085 * @param[in] NODE lyd_value variable
1086 * @param[in] CANNONICAL_VAL expected cannonical value
1087 * @param[in] VALUE expected inteager (0 to MAX_UINT32).
1088 */
1089#define CHECK_LYD_VALUE_UINT32(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001090 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001091 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Išaa76902f2021-03-29 08:52:51 +02001092 assert_non_null((NODE).realtype); \
1093 assert_int_equal(LY_TYPE_UINT32, (NODE).realtype->basetype); \
1094 assert_int_equal(VALUE, (NODE).uint32);
1095
1096/**
Radek Iša56ca9e42020-09-08 18:42:00 +02001097 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type STRING.
1098 * Example CHECK_LYD_VALUE(node->value, STRING, "text");
Michal Vaskoddd76592022-01-17 13:34:48 +01001099 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001100 * @param[in] NODE lyd_value variable
1101 * @param[in] CANNONICAL_VAL expected cannonical value
1102 */
1103#define CHECK_LYD_VALUE_STRING(NODE, CANNONICAL_VAL) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001104 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001105 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001106 assert_non_null((NODE).realtype); \
1107 assert_int_equal(LY_TYPE_STRING, (NODE).realtype->basetype);
1108
1109/**
1110 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type LEAFREF
Michal Vaskoddd76592022-01-17 13:34:48 +01001111 * Example CHECK_LYD_VALUE(node->value, LEAFREF, "");
1112 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001113 * @param[in] NODE lyd_value variable
1114 * @param[in] CANNONICAL_VAL expected cannonical value
1115 */
1116#define CHECK_LYD_VALUE_LEAFREF(NODE, CANNONICAL_VAL) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001117 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001118 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001119 assert_non_null((NODE).realtype); \
1120 assert_int_equal(LY_TYPE_LEAFREF, (NODE).realtype->basetype); \
1121 assert_non_null((NODE).ptr)
1122
1123/**
1124 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type DEC64
1125 * Example CHECK_LYD_VALUE(node->value, DEC64, "125", 125);
Michal Vaskoddd76592022-01-17 13:34:48 +01001126 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001127 * @param[in] NODE lyd_value variable
1128 * @param[in] CANNONICAL_VAL expected cannonical value
1129 * @param[in] VALUE expected value 64bit inteager
1130*/
1131#define CHECK_LYD_VALUE_DEC64(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001132 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001133 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001134 assert_non_null((NODE).realtype); \
1135 assert_int_equal(LY_TYPE_DEC64, (NODE).realtype->basetype); \
1136 assert_int_equal(VALUE, (NODE).dec64);
1137
1138/**
1139 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type BINARY.
1140 * Example CHECK_LYD_VALUE(node->value, BINARY, "aGVs\nbG8=");
Michal Vaskoddd76592022-01-17 13:34:48 +01001141 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001142 * @param[in] NODE lyd_value variable
1143 * @param[in] CANNONICAL_VAL expected cannonical value
Michal Vasko495f4502021-04-27 14:48:05 +02001144 * @param[in] VALUE expected value data
1145 * @param[in] SIZE expected value data size
Radek Iša56ca9e42020-09-08 18:42:00 +02001146*/
Michal Vasko495f4502021-04-27 14:48:05 +02001147#define CHECK_LYD_VALUE_BINARY(NODE, CANNONICAL_VAL, VALUE, SIZE) \
Michal Vaskoaa0ee622021-05-11 09:29:25 +02001148 { \
1149 struct lyd_value_binary *_val; \
1150 LYD_VALUE_GET(&(NODE), _val); \
1151 assert_int_equal(_val->size, SIZE); \
1152 assert_int_equal(0, memcmp(_val->data, VALUE, SIZE)); \
1153 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
1154 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
1155 assert_non_null((NODE).realtype); \
1156 assert_int_equal(LY_TYPE_BINARY, (NODE).realtype->basetype); \
1157 }
Radek Iša56ca9e42020-09-08 18:42:00 +02001158
1159/**
1160 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type BOOL.
1161 * Example CHECK_LYD_VALUE(node->value, BOOL, "true", 1);
Michal Vaskoddd76592022-01-17 13:34:48 +01001162 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001163 * @param[in] NODE lyd_value variable
1164 * @param[in] CANNONICAL_VAL expected cannonical value
1165 * @param[in] VALUE expected boolean value 0,1
1166*/
1167#define CHECK_LYD_VALUE_BOOL(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001168 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001169 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001170 assert_non_null((NODE).realtype); \
1171 assert_int_equal(LY_TYPE_BOOL, (NODE).realtype->basetype); \
1172 assert_int_equal(VALUE, (NODE).boolean);
1173
1174/**
1175 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type IDENT.
1176 * Example CHECK_LYD_VALUE(node->value, IDENT, "types:gigabit-ethernet", "gigabit-ethernet");
Michal Vaskoddd76592022-01-17 13:34:48 +01001177 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001178 * @param[in] NODE lyd_value variable
1179 * @param[in] CANNONICAL_VAL expected cannonical value
1180 * @param[in] VALUE expected ident name
1181*/
1182#define CHECK_LYD_VALUE_IDENT(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001183 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001184 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001185 assert_non_null((NODE).realtype); \
1186 assert_int_equal(LY_TYPE_IDENT, (NODE).realtype->basetype); \
1187 assert_string_equal(VALUE, (NODE).ident->name);
1188
1189/**
Radek Išaa9ff2b82021-01-13 21:44:13 +01001190 * @brief Macro testing parser when parsing incorrect module;
Michal Vaskoddd76592022-01-17 13:34:48 +01001191 *
Radek Išaa9ff2b82021-01-13 21:44:13 +01001192 * @param[in] DATA String storing the schema module representation.
1193 * @param[in] FORMAT Schema format of the @p DATA
1194 * @param[in] FEATURES Array of module's features to enable
1195 * @param[in] RET_VAL ly_in_new_memory return error value
1196 */
1197#define UTEST_INVALID_MODULE(DATA, FORMAT, FEATURES, RET_VAL) \
1198 { \
Michal Vasko4de7d072021-07-09 09:13:18 +02001199 struct lys_module *mod; \
Radek Išaa9ff2b82021-01-13 21:44:13 +01001200 assert_int_equal(LY_SUCCESS, ly_in_new_memory(DATA, &_UC->in)); \
1201 assert_int_equal(RET_VAL, lys_parse(_UC->ctx, _UC->in, FORMAT, FEATURES, &mod)); \
1202 assert_null(mod); \
1203 } \
1204 ly_in_free(_UC->in, 0); \
1205 _UC->in = NULL; \
1206
1207/**
Radek Iša56ca9e42020-09-08 18:42:00 +02001208 * @brief Add module (from a string) into the used libyang context.
Michal Vaskoddd76592022-01-17 13:34:48 +01001209 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001210 * @param[in] DATA String storing the schema module representation.
1211 * @param[in] FORMAT Schema format of the @p DATA
1212 * @param[in] FEATURES Array of module's features to enable
1213 * @param[out] MOD Optional parameter as a pointer to variable to store the resulting module.
1214 */
1215#define UTEST_ADD_MODULE(DATA, FORMAT, FEATURES, MOD) \
1216 assert_int_equal(LY_SUCCESS, ly_in_new_memory(DATA, &_UC->in)); \
1217 assert_int_equal(LY_SUCCESS, lys_parse(_UC->ctx, _UC->in, FORMAT, FEATURES, MOD)); \
1218 ly_in_free(_UC->in, 0); \
1219 _UC->in = NULL
1220
1221/**
1222 * @brief Internal macro to compare error info record with the expected error message and path.
1223 * If NULL is provided as MSG, no error info record (NULL) is expected.
Michal Vaskoddd76592022-01-17 13:34:48 +01001224 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001225 * @param[in] ERR Error information record from libyang context.
1226 * @param[in] MSG Expected error message.
1227 * @param[in] PATH Expected error path.
1228 *
1229 */
1230#define _CHECK_LOG_CTX(ERR, MSG, PATH) \
1231 if (!MSG) { \
1232 assert_null(ERR); \
1233 } else { \
1234 assert_non_null(ERR); \
1235 CHECK_STRING((ERR)->msg, MSG); \
1236 CHECK_STRING((ERR)->path, PATH); \
1237 }
1238
1239/**`
1240 * @brief Internal macro to check the last libyang's context error.
1241 */
1242#define _CHECK_LOG_CTX1(MSG, PATH) \
1243 _CHECK_LOG_CTX(ly_err_last(_UC->ctx), MSG, PATH)
1244
1245/**
1246 * @brief Internal macro to check the last two libyang's context error.
1247 */
1248#define _CHECK_LOG_CTX2(MSG1, PATH1, MSG2, PATH2) \
1249 _CHECK_LOG_CTX(ly_err_last(_UC->ctx), MSG1, PATH1); \
1250 _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev, MSG2, PATH2)
1251
1252/**
1253 * @brief Internal macro to check the last three libyang's context error.
1254 */
1255#define _CHECK_LOG_CTX3(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3) \
1256 _CHECK_LOG_CTX2(MSG1, PATH1, MSG2, PATH2); \
1257 _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev, MSG3, PATH3)
1258
1259/**
Radek Krejcife6ec262021-01-20 10:28:28 +01001260 * @brief Internal macro to check the last three libyang's context error.
1261 */
1262#define _CHECK_LOG_CTX4(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4) \
1263 _CHECK_LOG_CTX3(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3); \
1264 _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev, MSG4, PATH4)
1265
1266/**
1267 * @brief Internal macro to check the last three libyang's context error.
1268 */
1269#define _CHECK_LOG_CTX5(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5) \
1270 _CHECK_LOG_CTX4(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4); \
1271 _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev->prev, MSG5, PATH5)
1272
1273/**
Radek Krejci8297b792020-08-16 14:49:05 +02001274 * @brief Internal macro to check the last three libyang's context error.
1275 */
1276#define _CHECK_LOG_CTX6(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6) \
1277 _CHECK_LOG_CTX5(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5); \
1278 _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev->prev->prev, MSG6, PATH6)
1279
1280/**
1281 * @brief Internal macro to check the last three libyang's context error.
1282 */
1283#define _CHECK_LOG_CTX7(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6, MSG7, PATH7) \
1284 _CHECK_LOG_CTX6(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6); \
1285 _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev->prev->prev->prev, MSG7, PATH7)
1286
1287/**
1288 * @brief Internal macro to check the last three libyang's context error.
1289 */
1290#define _CHECK_LOG_CTX8(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6, MSG7, PATH7, MSG8, PATH8) \
1291 _CHECK_LOG_CTX7(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6, MSG7, PATH7); \
1292 _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev->prev->prev->prev->prev, MSG8, PATH8)
1293
1294/**
Radek Iša56ca9e42020-09-08 18:42:00 +02001295 * @brief Internal helper macro to select _CHECK_LOG_CTX* macro according to the provided parameters.
1296 */
Radek Krejci8297b792020-08-16 14:49:05 +02001297#define _GET_CHECK_LOG_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, NAME, ...) NAME
Radek Iša56ca9e42020-09-08 18:42:00 +02001298
1299/**
1300 * @brief Check expected error(s) in libyang context.
1301 *
1302 * Macro has variadic parameters expected to be provided in pairs of error message and error path starting
1303 * from the latest error. Current limit is checking at most 3 last errors. After checking, macro cleans up
1304 * all the errors from the libyang context.
1305 *
1306 * @param[in] MSG Expected error message.
1307 * @param[in] PATH Expected error path.
1308 */
1309#define CHECK_LOG_CTX(...) \
Radek Krejci8297b792020-08-16 14:49:05 +02001310 _GET_CHECK_LOG_MACRO(__VA_ARGS__, _CHECK_LOG_CTX8, _INVAL, _CHECK_LOG_CTX7, _INVAL, \
1311 _CHECK_LOG_CTX6, _INVAL, _CHECK_LOG_CTX5, _INVAL, _CHECK_LOG_CTX4, _INVAL, \
Michal Vasko151ae6c2021-09-23 08:23:51 +02001312 _CHECK_LOG_CTX3, _INVAL, _CHECK_LOG_CTX2, _INVAL, _CHECK_LOG_CTX1, DUMMY)(__VA_ARGS__); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001313 ly_err_clean(_UC->ctx, NULL)
1314
1315/**
Michal Vaskoe9391c72021-10-05 10:04:56 +02001316 * @brief Check expected error in libyang context including error-app-tag.
1317 *
1318 * @param[in] MSG Expected error message.
1319 * @param[in] PATH Expected error path.
1320 * @param[in] APPTAG Expected error-app-tag.
1321 */
1322#define CHECK_LOG_CTX_APPTAG(MSG, PATH, APPTAG) \
1323 if (!MSG) { \
1324 assert_null(ly_err_last(_UC->ctx)); \
1325 } else { \
1326 assert_non_null(ly_err_last(_UC->ctx)); \
1327 CHECK_STRING(ly_err_last(_UC->ctx)->msg, MSG); \
1328 CHECK_STRING(ly_err_last(_UC->ctx)->path, PATH); \
1329 CHECK_STRING(ly_err_last(_UC->ctx)->apptag, APPTAG); \
1330 } \
1331 ly_err_clean(_UC->ctx, NULL)
1332
1333/**
Radek Iša56ca9e42020-09-08 18:42:00 +02001334 * @brief Clean up the logging callback's storage.
1335 */
1336#define UTEST_LOG_CLEAN \
1337 free(_UC->err_msg); \
1338 free(_UC->err_path); \
1339 _UC->err_msg = NULL; \
1340 _UC->err_path = NULL;
1341
1342/**
1343 * @brief Check expected error directly logged via logging callback.
1344 * Useful mainly for messages logged by functions without access to libyang context.
1345 * @param[in] MSG Expected error message.
1346 * @param[in] PATH Expected error path.
1347 */
1348#define CHECK_LOG(MSG, PATH) \
1349 CHECK_STRING(_UC->err_msg, MSG); \
1350 CHECK_STRING(_UC->err_path, PATH); \
1351 UTEST_LOG_CLEAN
1352
1353#ifdef _UTEST_MAIN_
1354/*
1355 * Functions inlined into each C source file including this header with _UTEST_MAIN_ defined
1356 */
1357
1358/**
1359 * @brief Global variable holding the tests context to simplify access to it.
1360 */
1361struct utest_context *current_utest_context;
1362
1363/* set to 0 to printing error messages to stderr instead of checking them in code */
1364#define ENABLE_LOGGER_CHECKING 1
1365
1366/**
1367 * @brief Logging callback for libyang.
1368 */
1369static void
1370_utest_logger(LY_LOG_LEVEL level, const char *msg, const char *path)
1371{
1372 (void) level; /* unused */
1373
1374 if (ENABLE_LOGGER_CHECKING == 0) {
Radek Išaa9ff2b82021-01-13 21:44:13 +01001375 printf("\tERROR:\n\t\tMESSAGE: %s\n\t\tPATH: %s\n\t\tLEVEL: %i\n", msg, path, level);
Radek Iša56ca9e42020-09-08 18:42:00 +02001376 } else {
1377 free(current_utest_context->err_msg);
1378 current_utest_context->err_msg = msg ? strdup(msg) : NULL;
1379 free(current_utest_context->err_path);
1380 current_utest_context->err_path = path ? strdup(path) : NULL;
1381 }
1382}
1383
1384/**
1385 * @brief Generic utest's setup
1386 */
1387static int
1388utest_setup(void **state)
1389{
Michal Vasko86421632021-05-04 13:11:25 +02001390 char *cur_tz;
1391
Radek Iša56ca9e42020-09-08 18:42:00 +02001392 /* setup the logger */
1393 ly_set_log_clb(_utest_logger, 1);
1394 ly_log_options(LY_LOLOG | LY_LOSTORE);
1395
1396 current_utest_context = calloc(1, sizeof *current_utest_context);
1397 assert_non_null(current_utest_context);
1398 *state = current_utest_context;
1399
1400 /* libyang context */
1401 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &current_utest_context->ctx));
1402
Radek Krejci968d7552021-03-26 20:33:51 +01001403 /* clean all errors from the setup - usually warnings regarding the plugins directories */
1404 UTEST_LOG_CLEAN;
1405
Michal Vasko86421632021-05-04 13:11:25 +02001406 /* backup timezone, if any */
1407 cur_tz = getenv("TZ");
1408 if (cur_tz) {
1409 current_utest_context->orig_tz = strdup(cur_tz);
1410 }
1411
1412 /* set CET */
1413 setenv("TZ", "CET+02:00", 1);
1414
Radek Iša56ca9e42020-09-08 18:42:00 +02001415 return 0;
1416}
1417
1418/**
1419 * @brief macro to include generic utest's setup into the test-specific setup.
1420 *
1421 * Place at the beginning of the test-specific setup
1422 */
1423#define UTEST_SETUP \
1424 assert_int_equal(0, utest_setup(state))
1425
1426/**
1427 * @brief Generic utest's teardown
1428 */
1429static int
1430utest_teardown(void **state)
1431{
1432 *state = NULL;
1433
1434 /* libyang context */
Radek Krejci90ed21e2021-04-12 14:47:46 +02001435 ly_ctx_destroy(current_utest_context->ctx);
Radek Iša56ca9e42020-09-08 18:42:00 +02001436
Michal Vasko86421632021-05-04 13:11:25 +02001437 if (current_utest_context->orig_tz) {
1438 /* restore TZ */
1439 setenv("TZ", current_utest_context->orig_tz, 1);
1440 }
1441
Radek Iša56ca9e42020-09-08 18:42:00 +02001442 /* utest context */
1443 ly_in_free(current_utest_context->in, 0);
1444 free(current_utest_context->err_msg);
1445 free(current_utest_context->err_path);
Michal Vasko86421632021-05-04 13:11:25 +02001446 free(current_utest_context->orig_tz);
Radek Iša56ca9e42020-09-08 18:42:00 +02001447 free(current_utest_context);
1448 current_utest_context = NULL;
1449
1450 return 0;
1451}
1452
1453/**
1454 * @brief macro to include generic utest's teardown into the test-specific teardown.
1455 *
1456 * Place at the end of the test-specific teardown
1457 */
1458#define UTEST_TEARDOWN \
1459 assert_int_equal(0, utest_teardown(state))
1460
1461/**
1462 * @brief Internal macro for utest setup with test-specific setup and teardown
1463 */
1464#define _UTEST_SETUP_TEARDOWN(FUNC, SETUP, TEARDOWN) \
1465 cmocka_unit_test_setup_teardown(FUNC, SETUP, TEARDOWN)
1466
1467/**
1468 * @brief Internal macro for utest setup with test-specific setup and generic teardown
1469 */
1470#define _UTEST_SETUP(FUNC, SETUP) \
1471 cmocka_unit_test_setup_teardown(FUNC, SETUP, utest_teardown)
1472
1473/**
1474 * @brief Internal macro for utest setup with generic setup and teardown
1475 */
1476#define _UTEST(FUNC) \
1477 cmocka_unit_test_setup_teardown(FUNC, utest_setup, utest_teardown)
1478
1479/**
1480 * @brief Internal helper macro to select _UTEST* macro according to the provided parameters.
1481 */
1482#define _GET_UTEST_MACRO(_1, _2, _3, NAME, ...) NAME
1483
1484/**
1485 * @brief Macro to specify test function using utest environment. Macro has variadic parameters
1486 * to provide test-specific setup/teardown functions:
1487 *
1488 * UTEST(test_func) - only implicit setup and teardown functions are used
1489 * UTEST(test_func, setup) - implicit teardown but own setup
1490 * UTEST(test_func, setup, teardown) - both setup and teardown are test-specific
1491 */
1492#define UTEST(...) \
Michal Vasko151ae6c2021-09-23 08:23:51 +02001493 _GET_UTEST_MACRO(__VA_ARGS__, _UTEST_SETUP_TEARDOWN, _UTEST_SETUP, _UTEST, DUMMY)(__VA_ARGS__)
Radek Iša56ca9e42020-09-08 18:42:00 +02001494
1495#else /* _UTEST_MAIN_ */
1496
1497extern struct utest_context *current_utest_context;
1498
1499#endif /* _UTEST_MAIN_ */
1500
1501#endif /* _UTESTS_H_ */