blob: 2a5e8a2efc462d588601a60ac0f5f53cc3cc33ef [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 } \
Radek Iša56ca9e42020-09-08 18:42:00 +0200143 }
144
145/**
146 * @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.
147 * @param[in] NODE pointer to lyd_node
148 * @param[in] TEXT expected output string in json or xml format.
149 * @param[in] FORMAT format of input text. LYD_JSON, LYD_XML
150 * @param[in] PARAM options [Data printer flags](@ref dataprinterflags).
151 */
152#define CHECK_LYD_STRING_PARAM(NODE, TEXT, FORMAT, PARAM) \
153 { \
Michal Vaskoddd76592022-01-17 13:34:48 +0100154 char *str; \
155 LY_ERR _r = lyd_print_mem(&str, NODE, FORMAT, PARAM); \
156 if (_r) { \
157 fail_msg("Print err 0x%d; MSG: %s", _r, ly_err_last(_UC->ctx)->msg); \
158 } \
159 assert_string_equal(str, TEXT); \
160 free(str); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200161 }
162
163/**
164 * @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;
165 * @param[in] NODE_1 pointer to lyd_node
166 * @param[in] NODE_2 pointer to lyd_node
167 */
168#define CHECK_LYD(NODE_1, NODE_2) \
169 { \
Michal Vaskoddd76592022-01-17 13:34:48 +0100170 char *str1; \
171 char *str2; \
172 assert_int_equal(LY_SUCCESS, lyd_print_mem(&str1, NODE_1, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK)); \
173 assert_int_equal(LY_SUCCESS, lyd_print_mem(&str2, NODE_2, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK)); \
174 assert_non_null(str1); \
175 assert_non_null(str2); \
176 assert_string_equal(str1, str2); \
177 free(str1); \
178 free(str2); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200179 }
180
181/*
182 * SUPPORT MACROS
183 */
184
185/**
186 * @brief Internal macro witch assert that two given string are equal or are both null.
187 *
188 * @param[in] STRING string to check
189 * @param[in] TEXT string to compare
190 */
191#define CHECK_STRING(STRING, TEXT)\
192 if (TEXT == NULL) { \
193 assert_null(STRING); \
194 } else { \
195 assert_non_null(STRING); \
196 assert_string_equal(STRING, TEXT); \
197 }
198
199/**
200 * @brief Internal macro witch assert that pointer is null when flag is 0.
201 *
202 * @param[in] POINTER pointer to check
203 * @param[in] FLAG 0 -> pointer is NULL, 1 -> pointer is not null
204 */
205#define CHECK_POINTER(POINTER, FLAG) \
206 assert_true(FLAG == 0 ? POINTER == NULL : POINTER != NULL)
207
208/**
209 * @brief Internal macro check size of [sized array](@ref sizedarrays)'s
210 *
211 * @param[in] ARRAY pointer to [sized array](@ref sizedarrays)
212 * @param[in] SIZE expected [sized array](@ref sizedarrays) size of array
213 */
214#define CHECK_ARRAY(ARRAY, SIZE) \
215 assert_true((SIZE == 0) ? \
216 (ARRAY == NULL) : \
217 (ARRAY != NULL && SIZE == LY_ARRAY_COUNT(ARRAY)));
218
219/*
220 * LIBYANG NODE CHECKING
221 */
222
223/**
Radek Išaa9ff2b82021-01-13 21:44:13 +0100224 * @brief check compileted type
Michal Vaskoddd76592022-01-17 13:34:48 +0100225 *
Radek Išaa9ff2b82021-01-13 21:44:13 +0100226 * @param[in] NODE pointer to lysc_type value
227 * @param[in] TYPE expected type [LY_DATA_TYPE](@ref LY_DATA_TYPE)
228 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
229 */
230#define CHECK_LYSC_TYPE(NODE, TYPE, EXTS) \
231 assert_non_null(NODE); \
232 assert_int_equal((NODE)->basetype, TYPE); \
233 CHECK_ARRAY((NODE)->exts, EXTS); \
Radek Krejci3e6632f2021-03-22 22:08:21 +0100234 assert_ptr_equal((NODE)->plugin, lyplg_find(LYPLG_TYPE, "", NULL, ly_data_type2str[TYPE]))
Radek Išaa9ff2b82021-01-13 21:44:13 +0100235
Michal Vaskoddd76592022-01-17 13:34:48 +0100236/**
237 * @brief check compileted numeric type
238 *
Radek Išaa9ff2b82021-01-13 21:44:13 +0100239 * @param[in] NODE pointer to lysc_type_num value
240 * @param[in] TYPE expected type [LY_DATA_TYPE](@ref LY_DATA_TYPE)
241 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
242 * @warning only integer types INT, UINT, NUM
243 */
244#define CHECK_LYSC_TYPE_NUM(NODE, TYPE, EXTS, RANGE) \
245 CHECK_LYSC_TYPE(NODE, TYPE, EXTS);\
246 CHECK_POINTER((NODE)->range, RANGE)
247
Michal Vaskoddd76592022-01-17 13:34:48 +0100248/**
249 * @brief check compiled string type
250 *
Radek Išaa9ff2b82021-01-13 21:44:13 +0100251 * @param[in] NODE pointer to lysc_type_num value
252 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
253 * @param[in] LENGTH 0 -> node dosnt have length limitation, 1 -> node have length limitation
254 * @param[in] PATTERNS expected number of patterns [sized array](@ref sizedarrays)
255 * @warning only integer types INT, UINT, NUM
256 */
257#define CHECK_LYSC_TYPE_STR(NODE, EXTS, LENGTH, PATTERNS) \
258 CHECK_LYSC_TYPE(NODE, LY_TYPE_STRING, EXTS); \
259 CHECK_POINTER((NODE)->length, LENGTH); \
260 CHECK_ARRAY((NODE)->patterns, PATTERNS)
261
Michal Vaskoddd76592022-01-17 13:34:48 +0100262/**
263 * @brief check compiled bits type
264 *
Radek Išaded31052021-03-10 13:22:53 +0100265 * @param[in] NODE pointer to lysc_type_num value
266 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
267 * @param[in] BITS expected number of bits
268 * @warning only integer types INT, UINT, NUM
269 */
270#define CHECK_LYSC_TYPE_BITS(NODE, EXTS, BITS) \
271 CHECK_LYSC_TYPE(NODE, LY_TYPE_BITS, EXTS); \
272 CHECK_ARRAY((NODE)->bits, BITS)
273
Radek Išaded31052021-03-10 13:22:53 +0100274#define CHECK_LYSC_TYPE_BITENUM_ITEM(NODE, POSITION, DSC, EXTS, FLAGS, NAME, REF)\
275 assert_non_null(NODE); \
276 assert_int_equal((NODE)->position, POSITION); \
277 CHECK_STRING((NODE)->dsc, DSC); \
278 CHECK_ARRAY((NODE)->exts, EXTS); \
279 assert_int_equal((NODE)->flags, FLAGS); \
280 CHECK_STRING((NODE)->name, NAME); \
281 CHECK_STRING((NODE)->ref, REF) \
282
Michal Vaskoddd76592022-01-17 13:34:48 +0100283/**
284 * @brief check range
285 *
Radek Išaa9ff2b82021-01-13 21:44:13 +0100286 * @param[in] NODE pointer to lysc_range value
287 * @param[in] DSC expected descriptin (string)
288 * @param[in] EAPPTAG expected string reprezenting error-app-tag value
289 * @param[in] EMSG expected string reprezenting error message
290 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
291 * @param[in] PARTS expected [sized array](@ref sizedarrays) number of rang limitations
292 * @param[in] REF expected reference
293 */
294#define CHECK_LYSC_RANGE(NODE, DSC, EAPPTAG, EMSG, EXTS, PARTS, REF) \
295 assert_non_null(NODE); \
296 CHECK_STRING((NODE)->dsc, DSC); \
297 CHECK_STRING((NODE)->eapptag, EAPPTAG); \
298 CHECK_STRING((NODE)->emsg, EMSG); \
299 CHECK_ARRAY((NODE)->exts, EXTS); \
300 CHECK_ARRAY((NODE)->parts, PARTS); \
301 CHECK_STRING((NODE)->ref, REF)
302
Michal Vaskoddd76592022-01-17 13:34:48 +0100303/**
304 * @brief check pattern
305 *
Radek Išaa9ff2b82021-01-13 21:44:13 +0100306 * @param[in] NODE pointer to lysc_pattern value
307 * @param[in] DSC expected descriptin (string)
308 * @param[in] EAPPTAG expected string reprezenting error-app-tag value
309 * @param[in] EMSG expected string reprezenting error message
310 * @param[in] EEXPR expected string reprezenting original, not compiled, regular expression
311 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
312 * @param[in] INVERTED if regular expression is inverted.
313 * @param[in] REF expected reference
314 */
315#define CHECK_LYSC_PATTERN(NODE, DSC, EAPPTAG, EMSG, EXPR, EXTS, INVERTED, REF) \
316 assert_non_null(NODE); \
317 assert_non_null((NODE)->code); \
318 CHECK_STRING((NODE)->dsc, DSC); \
319 CHECK_STRING((NODE)->eapptag, EAPPTAG); \
320 CHECK_STRING((NODE)->emsg, EMSG); \
321 CHECK_STRING((NODE)->expr, EXPR); \
322 CHECK_ARRAY((NODE)->exts, EXTS); \
323 assert_int_equal((NODE)->inverted, INVERTED); \
324 CHECK_STRING((NODE)->ref, REF)
325
326/**
Radek Iša56ca9e42020-09-08 18:42:00 +0200327 * @brief assert that lysp_action_inout structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100328 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200329 * @param[in] NODE pointer to lysp_action_inout variable
330 * @param[in] DATA 0 -> check if pointer to data is NULL, 1 -> check if pointer to data is not null
331 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
332 * @param[in] GROUPINGS expected [sized array](@ref sizedarrays) size of grouping list
333 * @param[in] MUSTS expected [sized array](@ref sizedarrays) size of must restriction list
334 * @param[in] NODETYPE node type. LYS_INPUT or LYS_OUTPUT
335 * @param[in] PARENT 0 -> check if node is root, 1 -> check if node is not root
336 * @param[in] TYPEDEFS expected [sized array](@ref sizedarrays) size of typedefs list
337 */
338#define CHECK_LYSP_ACTION_INOUT(NODE, DATA, EXTS, GROUPINGS, MUSTS, NODETYPE, PARENT, TYPEDEFS) \
339 assert_non_null(NODE); \
Radek Krejci01180ac2021-01-27 08:48:22 +0100340 CHECK_POINTER((NODE)->child, DATA); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200341 CHECK_ARRAY((NODE)->exts, EXTS); \
Radek Krejci2a9fc652021-01-22 17:44:34 +0100342 CHECK_POINTER((NODE)->groupings, GROUPINGS); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200343 CHECK_ARRAY((NODE)->musts, MUSTS); \
344 assert_int_equal((NODE)->nodetype, NODETYPE); \
345 CHECK_POINTER((NODE)->parent, PARENT); \
346 CHECK_ARRAY((NODE)->typedefs, TYPEDEFS);
347
348/**
349 * @brief assert that lysp_action structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100350 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200351 * @param[in] NODE pointer to lysp_action variable
352 * @param[in] DSC expected description
353 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of extension list
354 * @param[in] FLAGS expected [schema node flags](@ref snodeflags)
355 * @param[in] GROUPINGS expected [sized array](@ref sizedarrays) size of grouping list
356 * @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of if-feature expressions list
357 * @param[in] INPUT_* ::LYSP_ACTION_INOUT_CHECK
358 * @param[in] NAME expected name
359 * @param[in] NODETYPE node type. LYS_RPC or LYS_ACTION
360 * @param[in] OUTPUT_* ::LYSP_ACTION_INOUT_CHECK
361 * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
362 * @param[in] REF expected reference
363 * @param[in] TYPEDEFS expected [sized array](@ref sizedarrays) size of list of typedefs
364 */
365#define CHECK_LYSP_ACTION(NODE, DSC, EXTS, FLAGS, GROUPINGS, IFFEATURES, \
366 INPUT_DATA, INPUT_EXTS, INPUT_GROUPINGS, INPUT_MUSTS, \
367 INPUT_PARENT, INPUT_TYPEDEFS, \
368 NAME, NODETYPE, \
369 OUTPUT_DATA, OUTPUT_EXTS, OUTPUT_GROUPINGS, OUTPUT_MUSTS, \
370 OUTPUT_PARENT, OUTPUT_TYPEDEFS, \
371 PARENT, REF, TYPEDEFS) \
372 assert_non_null(NODE); \
373 CHECK_STRING((NODE)->dsc, DSC); \
374 CHECK_ARRAY((NODE)->exts, EXTS); \
375 assert_int_equal((NODE)->flags, FLAGS); \
Radek Krejci2a9fc652021-01-22 17:44:34 +0100376 CHECK_POINTER((NODE)->groupings, GROUPINGS); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200377 CHECK_ARRAY((NODE)->iffeatures, IFFEATURES); \
378 CHECK_LYSP_ACTION_INOUT(&((NODE)->input), INPUT_DATA, INPUT_EXTS, INPUT_GROUPINGS, \
379 INPUT_MUSTS, LYS_INPUT, INPUT_PARENT, INPUT_TYPEDEFS); \
380 assert_string_equal((NODE)->name, NAME); \
381 assert_int_equal((NODE)->nodetype, NODETYPE); \
382 CHECK_LYSP_ACTION_INOUT(&((NODE)->output), OUTPUT_DATA, OUTPUT_EXTS, OUTPUT_GROUPINGS, \
383 OUTPUT_MUSTS, LYS_OUTPUT, OUTPUT_PARENT, OUTPUT_TYPEDEFS); \
384 CHECK_POINTER((NODE)->parent, PARENT); \
385 CHECK_STRING((NODE)->ref, REF); \
386 CHECK_ARRAY((NODE)->typedefs, TYPEDEFS) \
387
388/**
389 * @brief assert that lysp_when structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100390 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200391 * @param[in] NODE pointer to lysp_when variable
392 * @param[in] COND expected string specifid condition
393 * @param[in] DSC expected string description statement
394 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension array
395 * @param[in] REF expected string reference
396 */
397#define CHECK_LYSP_WHEN(NODE, COND, DSC, EXTS, REF) \
398 assert_non_null(NODE); \
399 assert_string_equal((NODE)->cond, COND); \
400 CHECK_STRING((NODE)->dsc, DSC); \
401 CHECK_ARRAY((NODE)->exts, EXTS); \
402 if (REF == NULL) { \
403 assert_null((NODE)->ref); \
404 } else { \
405 assert_non_null((NODE)->ref); \
406 assert_string_equal((NODE)->ref, REF); \
407 }
408
409/**
410 * @brief assert that lysp_restr structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100411 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200412 * @param[in] NODE pointer to lysp_restr variable
413 * @param[in] ARG_STR expected string. The restriction expression/value
414 * @param[in] DSC expected descrition
415 * @param[in] EAPPTAG expected string reprezenting error-app-tag value
416 * @param[in] EMSG expected string reprezenting error message
417 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension array
418 * @param[in] REF expected reference
419 */
420
421#define CHECK_LYSP_RESTR(NODE, ARG_STR, DSC, EAPPTAG, EMSG, EXTS, REF) \
422 assert_non_null(NODE); \
423 assert_non_null((NODE)->arg.mod); \
424 assert_string_equal((NODE)->arg.str, ARG_STR); \
425 CHECK_STRING((NODE)->dsc, DSC); \
426 CHECK_STRING((NODE)->eapptag, EAPPTAG); \
427 CHECK_STRING((NODE)->emsg, EMSG); \
428 CHECK_ARRAY((NODE)->exts, EXTS); \
429 CHECK_STRING((NODE)->ref, REF);
430
431/**
432 * @brief assert that lysp_import structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100433 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200434 * @param[in] NODE pointer to lysp_import variable
435 * @param[in] DSC expected description or NULL
436 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extensions
437 * @param[in] NAME expected name of imported module
438 * @param[in] PREFIX expected prefix for the data from the imported schema
439 * @param[in] REF expected reference
440 * @prame[in] REV expected reprezenting date in format "11-10-2020"
441 */
442#define CHECK_LYSP_IMPORT(NODE, DSC, EXTS, NAME, PREFIX, REF, REV) \
443 assert_non_null(NODE); \
444 CHECK_STRING((NODE)->dsc, DSC); \
445 CHECK_ARRAY((NODE)->exts, EXTS); \
446 /*assert_non_null((NODE)->module); // ?? it is mandatory but in some test it doesnt work */ \
447 assert_string_equal((NODE)->name, NAME); \
448 assert_string_equal((NODE)->prefix, PREFIX); \
449 CHECK_STRING((NODE)->ref, REF); \
450 CHECK_STRING((NODE)->rev, REV); \
451
452/**
453 * @brief assert that lysp_ext structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100454 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200455 * @param[in] NODE pointer to lysp_ext_instance variable
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100456 * @param[in] ARGNAME expected argument name
Radek Iša56ca9e42020-09-08 18:42:00 +0200457 * @param[in] COMPILED 0 -> compiled data dosnt exists, 1 -> compiled data exists
458 * @param[in] DSC expected string reprezent description
459 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension instances
460 * @param[in] FLAGS expected LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags)
461 * @param[in] NAME expected name
462 * @param[in] REF expected ref
463 */
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100464#define CHECK_LYSP_EXT(NODE, ARGNAME, COMPILED, DSC, EXTS, FLAGS, NAME, REF) \
Radek Iša56ca9e42020-09-08 18:42:00 +0200465 assert_non_null(NODE); \
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100466 CHECK_STRING((NODE)->argname, ARGNAME); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200467 CHECK_POINTER((NODE)->compiled, COMPILED); \
468 CHECK_STRING((NODE)->dsc, DSC); \
469 CHECK_ARRAY((NODE)->exts, EXTS); \
470 assert_int_equal((NODE)->flags, FLAGS); \
471 assert_string_equal((NODE)->name, NAME); \
472 CHECK_STRING((NODE)->ref, REF);
473
474/**
475 * @brief assert that lysp_ext_instance structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100476 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200477 * @param[in] NODE pointer to lysp_ext_instance variable
478 * @param[in] ARGUMENT expected optional value of the extension's argument
479 * @param[in] CHILD 0 -> node doesnt have child, 1 -> node have children
Radek Krejciab430862021-03-02 20:13:40 +0100480 * @param[in] PARENT_STMT expected value identifying placement of the extension instance
481 * @param[in] PARENT_STMT_INDEX expected indentifi index
Michal Vaskofc2cd072021-02-24 13:17:17 +0100482 * @param[in] FORMAT expected format
Radek Iša56ca9e42020-09-08 18:42:00 +0200483 */
Radek Krejci85ac8312021-03-03 20:21:33 +0100484#define CHECK_LYSP_EXT_INSTANCE(NODE, ARGUMENT, CHILD, PARENT_STMT, PARENT_STMT_INDEX, NAME, FORMAT) \
Radek Iša56ca9e42020-09-08 18:42:00 +0200485 assert_non_null(NODE); \
486 CHECK_STRING((NODE)->argument, ARGUMENT); \
487 CHECK_POINTER((NODE)->child, CHILD); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200488 /*assert_int_equal((NODE)->flags, LYS_INTERNAL);*/ \
Radek Krejciab430862021-03-02 20:13:40 +0100489 assert_int_equal((NODE)->parent_stmt, PARENT_STMT); \
490 assert_int_equal((NODE)->parent_stmt_index, PARENT_STMT_INDEX); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200491 assert_string_equal((NODE)->name, NAME); \
Michal Vaskofc2cd072021-02-24 13:17:17 +0100492 assert_int_equal((NODE)->format, FORMAT);
Radek Iša56ca9e42020-09-08 18:42:00 +0200493
494/**
495 * @brief assert that lysp_stmt structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100496 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200497 * @param[in] NODE pointer to lysp_stmt variable
498 * @param[in] ARG expected statemet argumet
499 * @param[in] CHILD 0 -> node doesnt have child, 1 -> node have children
500 * @param[in] FLAGS expected statement flags, can be set to LYS_YIN_ATTR
501 * @param[in] KW expected numeric respresentation of the stmt value
502 * @param[in] NEXT 0 -> pointer is NULL, 1 -> pointer is not null
503 * @param[in] STMS expected identifier of the statement
504 */
505#define CHECK_LYSP_STMT(NODE, ARG, CHILD, FLAGS, KW, NEXT, STMT) \
506 assert_non_null(NODE); \
507 CHECK_STRING((NODE)->arg, ARG); \
508 CHECK_POINTER((NODE)->child, CHILD); \
509 assert_int_equal((NODE)->flags, FLAGS); \
510 assert_int_equal((NODE)->kw, KW); \
511 CHECK_POINTER((NODE)->next, NEXT); \
512 assert_string_equal((NODE)->stmt, STMT); \
513
514/**
515 * @brief assert that lysp_type_enum structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100516 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200517 * @param[in] NODE pointer to lysp_type_enum variable
518 * @param[in] DSC expected description
519 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
520 * @param[in] FLAGS only LYS_STATUS_ and LYS_SET_VALUE values are allowed
521 * @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of list of the extension instances
522 * @param[in] NAME expected name
523 * @param[in] REF expected reference statement
524 * @param[in] VALUE expected enum's value or bit's position
525 */
526#define CHECK_LYSP_TYPE_ENUM(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, REF, VALUE) \
527 assert_non_null(NODE); \
528 CHECK_STRING((NODE)->dsc, DSC); \
529 CHECK_ARRAY((NODE)->exts, EXTS); \
530 assert_int_equal((NODE)->flags, FLAGS); \
531 CHECK_ARRAY((NODE)->iffeatures, IFFEATURES); \
532 CHECK_STRING((NODE)->name, NAME); \
533 CHECK_STRING((NODE)->ref, REF); \
534 assert_int_equal(VALUE, (NODE)->value);
535
536/**
Radek Išaa9ff2b82021-01-13 21:44:13 +0100537 * @brief assert that lysp_type_enum structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100538 *
Radek Išaa9ff2b82021-01-13 21:44:13 +0100539 * @param[in] NODE pointer to lysp_type variable
540 * @param[in] BASES expected [sized array](@ref sizedarrays) size of list of indentifiers
541 * @param[in] BITS expected [sized array](@ref sizedarrays) size of list of bits
542 * @param[in] COMPILED 0 -> pointer to compiled type is null, 1 -> pointer to compilet type is valid
543 * @param[in] ENUMS expected [sized array](@ref sizedarrays) size of list of enums-stmts
544 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension instances
545 * @param[in] FLAGS expected flags
546 * @param[in] FRACTION_DIGITS expected number of fraction digits decimal64
547 * @param[in] LENGTH expected 0 -> there isnt any restriction on length, 1 -> type is restricted on length (string, binary)
548 * @param[in] NAME expected name of type
549 * @param[in] PATH 0 -> no pointer to parsed path, 1 -> pointer to parsed path is valid
550 * @param[in] PATTERNS expected [sized array](@ref sizedarrays) size of list of patterns for string
551 * @param[in] PMOD expected submodule where type is defined 0 -> pointer is null, 1 -> pointer is not null
552 * @param[in] RANGE expected [sized array](@ref sizedarrays) size of list of range restriction
553 * @param[in] REQUIRE_INSTANCE expected require instance flag
554 * @param[in] TYPES expected [sized array](@ref sizedarrays) size of list of sub-types
555 */
556#define CHECK_LYSP_TYPE(NODE, BASES, BITS, COMPILED, ENUMS, EXTS, FLAGS, FRACTIONS_DIGITS, \
557 LENGTH, NAME, PATH, PATTERNS, PMOD, RANGE, REQUIRE_INSTANCE, TYPES) \
558 assert_non_null(NODE);\
559 CHECK_ARRAY((NODE)->bases, BASES); \
560 CHECK_ARRAY((NODE)->bits, BITS); \
561 CHECK_POINTER((NODE)->compiled, COMPILED); \
562 CHECK_ARRAY((NODE)->enums, ENUMS); \
563 CHECK_ARRAY((NODE)->exts, EXTS); \
564 assert_int_equal((NODE)->flags, FLAGS); \
565 assert_int_equal((NODE)->fraction_digits, FRACTIONS_DIGITS); \
566 CHECK_POINTER((NODE)->length, LENGTH); \
567 CHECK_STRING((NODE)->name, NAME); \
568 CHECK_POINTER((NODE)->path, PATH); \
569 CHECK_ARRAY((NODE)->patterns, PATTERNS); \
570 CHECK_POINTER((NODE)->pmod, PMOD); \
571 CHECK_POINTER((NODE)->range, RANGE); \
572 assert_int_equal((NODE)->require_instance, REQUIRE_INSTANCE); \
573 CHECK_ARRAY((NODE)->types , TYPES)
574
575/**
Radek Iša56ca9e42020-09-08 18:42:00 +0200576 * @brief assert that lysp_node structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100577 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200578 * @param[in] NODE pointer to lysp_node variable
579 * @param[in] DSC expected description statement
580 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
581 * @param[in] FLAGS [schema node flags](@ref snodeflags)
582 * @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of list of the extension instances
583 * @param[in] NAME expected name
584 * @param[in] NEXT 0 pointer is null, 1 pointer is not null
585 * @param[in] NODETYPE node type LYS_UNKNOWN, LYS_CONTAINER, LYS_CHOICE, LYS_LEAF, LYS_LEAFLIST,
586 * LYS_LIST, LYS_ANYXML, LYS_ANYDATA, LYS_CASE, LYS_RPC, LYS_ACTION, LYS_NOTIF,
587 * LYS_USES, LYS_INPUT, LYS_OUTPUT, LYS_GROUPING, LYS_AUGMENT
588 * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
589 * @param[in] REF expected reference statement
590 * @param[in] WHEN 0-> pointer is null, 1 -> pointer is not null
591 */
592#define CHECK_LYSP_NODE(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, NEXT, NODETYPE, PARENT, REF, WHEN) \
593 assert_non_null(NODE); \
594 CHECK_STRING((NODE)->dsc, DSC); \
595 CHECK_ARRAY((NODE)->exts, EXTS); \
596 assert_int_equal((NODE)->flags, FLAGS); \
597 CHECK_ARRAY((NODE)->iffeatures, IFFEATURES); \
598 CHECK_STRING((NODE)->name, NAME); \
599 CHECK_POINTER((NODE)->next, NEXT); \
600 assert_int_equal((NODE)->nodetype, NODETYPE); \
601 CHECK_POINTER((NODE)->parent, PARENT); \
602 CHECK_STRING((NODE)->ref, REF); \
Radek Krejci9a3823e2021-01-27 20:26:46 +0100603 CHECK_POINTER(lysp_node_when((struct lysp_node *)NODE), WHEN);
Radek Iša56ca9e42020-09-08 18:42:00 +0200604
605/**
Radek Išaa9ff2b82021-01-13 21:44:13 +0100606 * @brief assert that lysp_node structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100607 *
Radek Išaa9ff2b82021-01-13 21:44:13 +0100608 * @param[in] NODE pointer to lysp_node variable
609 * @param[in] DSC expected description statement
610 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
611 * @param[in] FLAGS [schema node flags](@ref snodeflags)
612 * @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of list of the extension instances
613 * @param[in] NAME expected name
614 * @param[in] NEXT 0 pointer is null, 1 pointer is not null
615 * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
616 * @param[in] REF expected reference statement
617 * @param[in] WHEN 0-> pointer is null, 1 -> pointer is not null
618 * @param[in] MUSTS expected [sized array](@ref sizedarrays) size of list of must restriction
619 * @param[in] UNITS expected string reprezenting units
620 * @param[in] DFLT 0-> node dosn't have default value. 1 -> node have default value
621 */
622#define CHECK_LYSP_NODE_LEAF(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, NEXT, \
623 PARENT, REF, WHEN, MUSTS, UNITS, DFLT) \
624 CHECK_LYSP_NODE(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, NEXT, LYS_LEAF, PARENT, REF, WHEN); \
625 CHECK_ARRAY((NODE)->musts, MUSTS); \
626 CHECK_STRING((NODE)->units, UNITS); \
627 CHECK_STRING((NODE)->dflt.str, DFLT);
628
629/**
Radek Iša56ca9e42020-09-08 18:42:00 +0200630 * @brief assert that lysc_notif structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100631 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200632 * @param[in] NODE pointer to lysp_notif variable
633 * @param[in] DATA 0 pointer is null, 1 pointer is not null
634 * @param[in] DSC expected description
635 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
636 * @param[in] FLAGS [schema node flags](@ref snodeflags)
637 * @param[in] MODULE 0 pointer is null, 1 pointer is not null
638 * @param[in] MUSTS expected [sized array](@ref sizedarrays) size of list of must restriction
639 * @param[in] NAME expected name
640 * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
641 * @param[in] PRIV 0-> pointer is null, 1-> pointer is not null
642 * @param[in] REF expected reference
643 * @param[in] WHEN expected [sized array](@ref sizedarrays) size of list of pointers to when statements
644 */
645#define CHECK_LYSC_NOTIF(NODE, DATA, DSC, EXTS, FLAGS, MODULE, MUSTS, NAME, PARENT, PRIV, REF, WHEN) \
646 assert_non_null(NODE); \
Radek Krejci01180ac2021-01-27 08:48:22 +0100647 CHECK_POINTER((NODE)->child, DATA); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200648 CHECK_STRING((NODE)->dsc, DSC); \
649 CHECK_ARRAY((NODE)->exts, EXTS); \
650 assert_int_equal((NODE)->flags, FLAGS); \
651 CHECK_POINTER((NODE)->module, MODULE); \
652 CHECK_ARRAY((NODE)->musts, MUSTS); \
653 assert_string_equal((NODE)->name, NAME); \
654 assert_int_equal((NODE)->nodetype, LYS_NOTIF); \
655 CHECK_POINTER((NODE)->parent, PARENT); \
656 CHECK_POINTER((NODE)->priv, PRIV); \
657 CHECK_STRING((NODE)->ref, REF); \
Radek Išaa9ff2b82021-01-13 21:44:13 +0100658 CHECK_ARRAY(lysc_node_when((const struct lysc_node *)NODE), WHEN);
Radek Iša56ca9e42020-09-08 18:42:00 +0200659
660/**
661 * @brief assert that lysc_action_inout structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100662 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200663 * @param[in] NODE pointer to lysp_notif variable
664 * @param[in] DATA 0 pointer is null, 1 pointer is not null
665 * @param[in] MUST expected [sized array](@ref sizedarrays) size of list of must restrictions
666 * @param[in] NODETYPE LYS_INPUT or LYS_OUTPUT
667 */
668#define CHECK_LYSC_ACTION_INOUT(NODE, DATA, MUST, NODETYPE) \
669 assert_non_null(NODE); \
Radek Krejci01180ac2021-01-27 08:48:22 +0100670 CHECK_POINTER((NODE)->child, DATA); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200671 CHECK_ARRAY((NODE)->musts, MUST); \
672 assert_int_equal((NODE)->nodetype, NODETYPE);
673
674/**
675 * @brief assert that lysc_action structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100676 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200677 * @param[in] NODE pointer to lysp_action variable
678 * @param[in] DSC string description statement
679 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
680 * @param[in] FLAGS [schema node flags](@ref snodeflags)
681 * @param[in] INPUT_DATA 0 pointer is null, 1 pointer is not null
682 * @param[in] INPUT_MUST expected [sized array](@ref sizedarrays) size of input list of must restrictions
683 * @param[in] INPUT_EXTS expected [sized array](@ref sizedarrays) size of the input extension instances of input
684 * @param[in] MODULE 0 pointer is null, 1 pointer is not null
685 * @param[in] NAME expected name
686 * @param[in] NODETYPE LYS_RPC, LYS_ACTION
687 * @param[in] OUTPUT_DATA 0 pointer is null, 1 pointer is not null
688 * @param[in] OUTPUT_MUST expected [sized array](@ref sizedarrays) size of output list of must restrictions
689 * @param[in] OUTPUT_EXTS expected [sized array](@ref sizedarrays) size of the output extension instances of input
690 * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
691 * @param[in] PRIV 0-> pointer is null, 1-> pointer is not null
692 * @param[in] REF expected reference
693 * @param[in] WHEN expected [sized array](@ref sizedarrays) size of list of pointers to when statements
694 */
695#define CHECK_LYSC_ACTION(NODE, DSC, EXTS, FLAGS, INPUT_DATA, INPUT_MUST, INPUT_EXTS, MODULE, NAME, NODETYPE, \
696 OUTPUT_DATA, OUTPUT_MUST, OUTPUT_EXTS, PARENT, PRIV, REF, WHEN) \
697 assert_non_null(NODE); \
698 CHECK_STRING((NODE)->dsc, DSC); \
699 CHECK_ARRAY((NODE)->exts, EXTS); \
700 assert_int_equal((NODE)->flags, FLAGS); \
701 CHECK_LYSC_ACTION_INOUT(&(NODE)->input, INPUT_DATA, INPUT_MUST, LYS_INPUT); \
Radek Krejci2a9fc652021-01-22 17:44:34 +0100702 CHECK_ARRAY((NODE)->input.exts, INPUT_EXTS); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200703 CHECK_POINTER((NODE)->module, MODULE); \
704 assert_string_equal((NODE)->name, NAME); \
705 assert_int_equal((NODE)->nodetype, NODETYPE); \
706 CHECK_LYSC_ACTION_INOUT(&(NODE)->output, OUTPUT_DATA, OUTPUT_MUST, LYS_OUTPUT); \
Radek Krejci2a9fc652021-01-22 17:44:34 +0100707 CHECK_ARRAY((NODE)->output.exts, OUTPUT_EXTS); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200708 CHECK_POINTER((NODE)->parent, PARENT); \
709 CHECK_POINTER((NODE)->priv, PRIV); \
710 CHECK_STRING((NODE)->ref, REF); \
Radek Išaa9ff2b82021-01-13 21:44:13 +0100711 CHECK_ARRAY(lysc_node_when((const struct lysc_node *)NODE), WHEN);
Radek Iša56ca9e42020-09-08 18:42:00 +0200712
713/**
714 * @brief assert that lysc_node structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100715 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200716 * @param[in] NODE pointer to lysc_node variable
717 * @param[in] DSC expected description
718 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
719 * @param[in] FLAGS [schema node flags](@ref snodeflags)
720 * @param[in] MODULE 0 pointer is null, 1 pointer is not null
721 * @param[in] NAME expected name
722 * @param[in] NEXT 0 pointer is null, 1 pointer is not null
723 * @param[in] NODETYPE type of the node LYS_UNKNOWN, LYS_CONTAINER, LYS_CHOICE, LYS_LEAF,
724 * LYS_LEAFLIST, LYS_LIST, LYS_ANYXML, LYS_ANYDATA, LYS_CASE, LYS_RPC,
725 * LYS_ACTION, LYS_NOTIF, LYS_USES, LYS_INPUT, LYS_OUTPUT, LYS_GROUPING,
726 * LYS_AUGMENT
727 * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
728 * @param[in] PRIV 0-> pointer is null, 1-> pointer is not null
729 * @param[in] REF expected reference
730 * @param[in] WHEN expected [sized array](@ref sizedarrays) size of list of pointers to when statements
731 */
732#define CHECK_LYSC_NODE(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, NODETYPE, PARENT, PRIV, REF, WHEN) \
733 assert_non_null(NODE); \
734 CHECK_STRING((NODE)->dsc, DSC); \
735 CHECK_ARRAY((NODE)->exts, EXTS); \
736 assert_int_equal((NODE)->flags, FLAGS); \
737 CHECK_POINTER((NODE)->module, MODULE); \
738 assert_string_equal((NODE)->name, NAME); \
739 CHECK_POINTER((NODE)->next, NEXT); \
740 assert_int_equal((NODE)->nodetype, NODETYPE); \
741 CHECK_POINTER((NODE)->parent, PARENT); \
742 assert_non_null((NODE)->prev); \
743 CHECK_POINTER((NODE)->priv, PRIV); \
744 CHECK_STRING((NODE)->ref, REF); \
Radek Išaa9ff2b82021-01-13 21:44:13 +0100745 CHECK_ARRAY(lysc_node_when((const struct lysc_node *)NODE), WHEN);
746
747/**
748 * @brief assert that lysc_node_leaf structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100749 *
Radek Išaa9ff2b82021-01-13 21:44:13 +0100750 * @param[in] NODE pointer to lysc_node variable
751 * @param[in] DSC expected description
752 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
753 * @param[in] FLAGS [schema node flags](@ref snodeflags)
754 * @param[in] MODULE 0 pointer is null, 1 pointer is not null
755 * @param[in] NAME expected name
756 * @param[in] NEXT 0 pointer is null, 1 pointer is not null
757 * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
758 * @param[in] PRIV 0-> pointer is null, 1-> pointer is not null
759 * @param[in] REF expected reference
Radek Išaa76902f2021-03-29 08:52:51 +0200760 * @param[in] ACTIONS 1 if is set pointer to structure lysc_node_action other 0
761 * @param[in] CHILD 1 if is set pointer to child other 0
762 * @param[in] MAX possible maximum elements in list
763 * @param[in] MIN possible minimum elements in list
764 * @param[in] MUSTS [sized array](@ref sizedarrays) number of must node elements in array
765 * @param[in] NOTIFS 1 if is set pointer to any notifs node
766 * @param[in] UNIQUES [sized array](@ref sizedarrays) number of unique nodes element in array
767 * @param[in] WHEN [sized array](@ref sizedarrays) size of when node array
768 */
769#define CHECK_LYSC_NODE_LIST(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, \
770 PARENT, PRIV, REF, ACTIONS, CHILD, MAX, MIN, MUSTS, NOTIFS, UNIQUES, WHEN) \
771 CHECK_LYSC_NODE(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, LYS_LIST, PARENT, PRIV, REF, WHEN); \
772 CHECK_POINTER((NODE)->actions, ACTIONS); \
773 CHECK_POINTER((NODE)->child, CHILD); \
774 assert_int_equal((NODE)->max, MAX); \
775 assert_int_equal((NODE)->min, MIN); \
776 CHECK_ARRAY((NODE)->musts, MUSTS); \
777 CHECK_POINTER((NODE)->notifs, NOTIFS); \
778 CHECK_ARRAY((NODE)->uniques, UNIQUES); \
779 CHECK_ARRAY(lysc_node_when((const struct lysc_node *)NODE), WHEN)
780
781/**
782 * @brief assert that lysc_node_leaf structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100783 *
Radek Išaa76902f2021-03-29 08:52:51 +0200784 * @param[in] NODE pointer to lysc_node variable
785 * @param[in] DSC expected description
786 * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
787 * @param[in] FLAGS [schema node flags](@ref snodeflags)
788 * @param[in] MODULE 0 pointer is null, 1 pointer is not null
789 * @param[in] NAME expected name
790 * @param[in] NEXT 0 pointer is null, 1 pointer is not null
791 * @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
792 * @param[in] PRIV 0-> pointer is null, 1-> pointer is not null
793 * @param[in] REF expected reference
794 * @param[in] WHEN expected [sized array](@ref sizedarrays) size of list of pointers to when statements
Radek Išaa9ff2b82021-01-13 21:44:13 +0100795 * @param[in] MUSTS expected [sized array](@ref sizedarrays) size of list of must restriction
796 * @param[in] UNITS expected string reprezenting units
797 * @param[in] DFLT 0-> node dosn't have default value. 1 -> node have default value
798 */
799#define CHECK_LYSC_NODE_LEAF(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, \
800 PARENT, PRIV, REF, WHEN, MUSTS, UNITS, DFLT) \
801 CHECK_LYSC_NODE(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, LYS_LEAF, PARENT, PRIV, REF, WHEN); \
802 CHECK_ARRAY((NODE)->musts, MUSTS); \
803 assert_non_null((NODE)->type); \
804 CHECK_STRING((NODE)->units, UNITS); \
805 CHECK_POINTER((NODE)->dflt, DFLT);
Radek Iša56ca9e42020-09-08 18:42:00 +0200806
807/**
808 * @brief assert that lyd_meta structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100809 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200810 * @param[in] NODE pointer to lyd_meta variable
811 * @param[in] ANNOTATION 0 pointer is null, 1 pointer is not null
812 * @param[in] NAME expected name
813 * @param[in] NEXT 0 pointer is null, 1 pointer is not null
814 * @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT
815 * part of text reprezenting LY_DATA_TYPE.
816 * @param[in] ... ::CHECK_LYD_VALUE
817 */
818#define CHECK_LYD_META(NODE, ANNOTATION, NAME, NEXT, PARENT, TYPE_VAL, ...) \
819 assert_non_null(NODE); \
820 CHECK_POINTER((NODE)->annotation, ANNOTATION); \
821 assert_string_equal((NODE)->name, NAME); \
822 CHECK_POINTER((NODE)->next, NEXT); \
823 CHECK_POINTER((NODE)->parent, PARENT); \
Michal Vasko151ae6c2021-09-23 08:23:51 +0200824 CHECK_LYD_VALUE((NODE)->value, TYPE_VAL, __VA_ARGS__);
Radek Iša56ca9e42020-09-08 18:42:00 +0200825
826/**
827 * @brief assert that lyd_node_term structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100828 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200829 * @param[in] NODE pointer to lyd_node_term variable
830 * @param[in] FLAGS expected [data node flags](@ref dnodeflags)
831 * @param[in] META 0 -> meta is not prezent, 1 -> meta is prezent
832 * @param[in] NEXT 0 -> next node is not prezent, 1 -> next node is prezent
833 * @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT
834 * part of text reprezenting LY_DATA_TYPE.
835 * @param[in] ... ::CHECK_LYD_VALUE
836 */
837#define CHECK_LYD_NODE_TERM(NODE, FLAGS, META, NEXT, PARENT, SCHEMA, VALUE_TYPE, ...) \
838 assert_non_null(NODE); \
839 assert_int_equal((NODE)->flags, FLAGS); \
840 CHECK_POINTER((NODE)->meta, META); \
841 CHECK_POINTER((NODE)->next, NEXT); \
842 CHECK_POINTER((NODE)->parent, PARENT); \
843 assert_non_null((NODE)->prev); \
844 CHECK_POINTER((NODE)->schema, SCHEMA); \
Michal Vasko151ae6c2021-09-23 08:23:51 +0200845 CHECK_LYD_VALUE((NODE)->value, VALUE_TYPE, __VA_ARGS__);
Radek Iša56ca9e42020-09-08 18:42:00 +0200846
847/**
848 * @brief assert that lyd_node_any structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100849 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200850 * @param[in] NODE pointer to lyd_node_term variable
851 * @param[in] FLAGS expected [data node flags](@ref dnodeflags)
852 * @param[in] META 0 meta isnt present , 1 meta is present
853 * @param[in] PARENT 0 it is root node , 1 node have parent
854 * @param[in] VALUE_TYPE value type ::lyd_node_any.value
855 */
856#define CHECK_LYD_NODE_ANY(NODE, FLAGS, META, PARENT, VALUE_TYPE) \
857 assert_non_null(NODE); \
858 assert_int_equal((NODE)->flags, FLAGS); \
859 CHECK_POINTER((NODE)->meta, META); \
860 CHECK_POINTER((NODE)->meta, PARENT); \
861 assert_non_null((NODE)->prev); \
862 assert_non_null((NODE)->schema); \
863 assert_int_equal((NODE)->value_type, VALUE_TYPE);
864
865/**
866 * @brief assert that lyd_node_opaq structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100867 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200868 * @param[in] NODE pointer to lyd_node_opaq variable
869 * @param[in] ATTR 0 if pointer is null ,1 if pointer is not null
870 * @param[in] CHILD 0 if pointer is null ,1 if pointer is not null
871 * @param[in] FORMAT LY_PREF_XML or LY_PREF_JSON
872 * @param[in] VAL_PREFS 0 if pointer is null ,1 if pointer is not null
873 * @param[in] NAME expected name
874 * @param[in] value expected orignal value
875 */
876#define CHECK_LYD_NODE_OPAQ(NODE, ATTR, CHILD, FORMAT, NAME, NEXT, PARENT, PREFIX, VAL_PREFS, VALUE) \
877 assert_non_null(NODE); \
878 CHECK_POINTER((NODE)->attr, ATTR); \
879 CHECK_POINTER((NODE)->child, CHILD); \
880 assert_ptr_equal((NODE)->ctx, UTEST_LYCTX); \
881 assert_int_equal((NODE)->flags, 0); \
882 assert_true((NODE)->format == FORMAT); \
883 assert_int_equal((NODE)->hash, 0); \
884 assert_string_equal((NODE)->name.name, NAME); \
885 assert_non_null((NODE)->prev); \
886 assert_null((NODE)->schema); \
887 CHECK_POINTER((NODE)->val_prefix_data, VAL_PREFS); \
888 assert_string_equal((NODE)->value, VALUE);
889
890/**
Radek Išaa76902f2021-03-29 08:52:51 +0200891 * @brief assert that lyd_node_opaq structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100892 *
Radek Išaa76902f2021-03-29 08:52:51 +0200893 * @param[in] NODE pointer to lyd_node_opaq variable
894 * @param[in] CHILD 1 if node has children other 0
895 * @param[in] HILD_HT 1 if node has children hash table other 0
896 * @param[in] META 1 if node has metadata other 0
897 * @param[in] FLAGS expected flag
898 * @param[in] NEXT 1 if next node is present other 0
899 * @param[in] PARENT 1 if node has parent other 0
900 * @param[in] PRIV 1 if node has private data other 0
901 * @param[in] SCHEMA 1 if node has schema other 0
902*/
903#define CHECK_LYD_NODE_INNER(NODE, CHILD, CHILD_HT, META, FLAGS, NEXT, PARENT, PRIV, SCHEMA) \
904 assert_non_null(NODE); \
905 CHECK_POINTER((NODE)->child, CHILD); \
906 CHECK_POINTER((NODE)->children_ht, CHILD_HT); \
907 CHECK_POINTER((NODE)->meta, META); \
908 assert_int_equal((NODE)->flags, FLAGS); \
909 CHECK_POINTER((NODE)->parent, PARENT); \
910 assert_non_null((NODE)->prev); \
911 CHECK_POINTER((NODE)->next, NEXT); \
912 CHECK_POINTER((NODE)->priv, PRIV); \
913 CHECK_POINTER((NODE)->schema, SCHEMA)
914
915/**
Radek Iša56ca9e42020-09-08 18:42:00 +0200916 * @brief assert that lyd_value structure members are correct
Michal Vaskoddd76592022-01-17 13:34:48 +0100917 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200918 * @param[in] NODE lyd_value
919 * @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT
920 * part of text reprezenting LY_DATA_TYPE.
921 * @param[in] ... Unspecified parameters. Type and numbers of parameters are specified
922 * by type of value. These parameters are passed to macro
923 * CHECK_LYD_VALUE_ ## TYPE_VAL.
924 */
925#define CHECK_LYD_VALUE(NODE, TYPE_VAL, ...) \
Michal Vasko151ae6c2021-09-23 08:23:51 +0200926 CHECK_LYD_VALUE_ ## TYPE_VAL (NODE, __VA_ARGS__);
Radek Iša56ca9e42020-09-08 18:42:00 +0200927
928/*
929 * LYD VALUES CHECKING SPECIALIZATION
930 */
931
932/**
933 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type EMPTY
934 * Example CHECK_LYD_VALUE(node->value, EMPTY, "");
Michal Vaskoddd76592022-01-17 13:34:48 +0100935 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200936 * @param[in] NODE lyd_value variable
937 * @param[in] CANNONICAL_VAL expected cannonical value
938 */
939#define CHECK_LYD_VALUE_EMPTY(NODE, CANNONICAL_VAL) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +0200940 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +0200941 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200942 assert_non_null((NODE).realtype); \
943 assert_int_equal((NODE).realtype->basetype, LY_TYPE_EMPTY);
944
945/**
946 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type UNION
947 * Example CHECK_LYD_VALUE(node->value, UNION, "12", INT8, "12", 12);
948 * @warning type of subvalue cannot be UNION. Example of calling
Michal Vaskoddd76592022-01-17 13:34:48 +0100949 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200950 * @param[in] NODE lyd_value variable
951 * @param[in] CANNONICAL_VAL expected cannonical value
952 * @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT
953 * @param[in] ... Unspecified parameters. Type and numbers of parameters are specified
954 * by type of value. These parameters are passed to macro
955 * CHECK_LYD_VALUE_ ## TYPE_VAL.
956 */
957#define CHECK_LYD_VALUE_UNION(NODE, CANNONICAL_VAL, TYPE_VAL, ...) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +0200958 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +0200959 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200960 assert_non_null((NODE).realtype); \
961 assert_int_equal(LY_TYPE_UNION, (NODE).realtype->basetype); \
962 assert_non_null((NODE).subvalue); \
963 assert_non_null((NODE).subvalue->prefix_data); \
Michal Vasko151ae6c2021-09-23 08:23:51 +0200964 CHECK_LYD_VALUE_ ## TYPE_VAL ((NODE).subvalue->value, __VA_ARGS__)
965
966/**
967 * @brief Internal macro. Get 1st variadic argument.
968 */
969#define _GETARG1(ARG1, ...) ARG1
Radek Iša56ca9e42020-09-08 18:42:00 +0200970
971/**
972 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type BITS
973 * Example arr[] = {"a", "b"}; CHECK_LYD_VALUE(node->value, BITS, "a b", arr);
Michal Vaskoddd76592022-01-17 13:34:48 +0100974 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200975 * @param[in] NODE lyd_value variable
976 * @param[in] CANNONICAL_VAL expected cannonical value
977 * @param[in] VALUE expected array of bits names
978 */
Michal Vasko151ae6c2021-09-23 08:23:51 +0200979#define CHECK_LYD_VALUE_BITS(NODE, ...) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +0200980 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Michal Vasko151ae6c2021-09-23 08:23:51 +0200981 assert_string_equal((NODE)._canonical, _GETARG1(__VA_ARGS__, DUMMY)); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200982 assert_non_null((NODE).realtype); \
983 assert_int_equal(LY_TYPE_BITS, (NODE).realtype->basetype); \
984 { \
Radek Išaded31052021-03-10 13:22:53 +0100985 const char *arr[] = { __VA_ARGS__ }; \
Michal Vasko151ae6c2021-09-23 08:23:51 +0200986 LY_ARRAY_COUNT_TYPE arr_size = (sizeof(arr) / sizeof(arr[0])) - 1; \
Michal Vaskoaa0ee622021-05-11 09:29:25 +0200987 struct lyd_value_bits *_val; \
988 LYD_VALUE_GET(&(NODE), _val); \
989 assert_int_equal(arr_size, LY_ARRAY_COUNT(_val->items)); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200990 for (LY_ARRAY_COUNT_TYPE it = 0; it < arr_size; it++) { \
Michal Vasko151ae6c2021-09-23 08:23:51 +0200991 assert_string_equal(arr[it + 1], _val->items[it]->name); \
Radek Iša56ca9e42020-09-08 18:42:00 +0200992 } \
993 }
994
995/**
996 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type INST
Michal Vaskoddd76592022-01-17 13:34:48 +0100997 *
Radek Iša56ca9e42020-09-08 18:42:00 +0200998 * @param[in] NODE lyd_value variable
999 * @param[in] CANNONICAL_VAL expected cannonical value
1000 * @param[in] VALUE expected array of enum ly_path_pred_type
1001 * @brief Example enum arr[] = {0x0, 0x1}; CHECK_LYD_VALUE(node->value, INST, "test/d", arr);
1002 */
1003#define CHECK_LYD_VALUE_INST(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001004 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001005 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001006 assert_non_null((NODE).realtype); \
1007 assert_int_equal(LY_TYPE_INST, (NODE).realtype->basetype); \
1008 { \
Michal Vasko79135ae2020-12-16 10:08:35 +01001009 LY_ARRAY_COUNT_TYPE arr_size = sizeof(VALUE) / sizeof(VALUE[0]); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001010 assert_int_equal(arr_size, LY_ARRAY_COUNT((NODE).target)); \
1011 for (LY_ARRAY_COUNT_TYPE it = 0; it < arr_size; it++) { \
1012 assert_int_equal(VALUE[it], (NODE).target[it].pred_type); \
1013 } \
1014 }
1015
1016/**
1017 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type ENUM.
1018 * Example CHECK_LYD_VALUE(node->value, ENUM, "item_name", "item_name");
Michal Vaskoddd76592022-01-17 13:34:48 +01001019 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001020 * @param[in] NODE lyd_value variable
1021 * @param[in] CANNONICAL_VAL expected cannonical value
1022 * @param[in] VALUE expected enum item name
1023 */
1024#define CHECK_LYD_VALUE_ENUM(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001025 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001026 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001027 assert_non_null((NODE).realtype); \
1028 assert_int_equal(LY_TYPE_ENUM, (NODE).realtype->basetype); \
1029 assert_string_equal(VALUE, (NODE).enum_item->name);
1030
1031/**
1032 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type INT8
1033 * Example CHECK_LYD_VALUE(node->value, INT8, "12", 12);
Michal Vaskoddd76592022-01-17 13:34:48 +01001034 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001035 * @param[in] NODE lyd_value variable
1036 * @param[in] CANNONICAL_VAL expected cannonical value
1037 * @param[in] VALUE expected inteager value (-128 to 127).
1038 */
1039#define CHECK_LYD_VALUE_INT8(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001040 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001041 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001042 assert_non_null((NODE).realtype); \
1043 assert_int_equal(LY_TYPE_INT8, (NODE).realtype->basetype); \
1044 assert_int_equal(VALUE, (NODE).int8);
1045
1046/**
1047 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type INT16
1048 * Example CHECK_LYD_VALUE(node->value, INT8, "12", 12);
Michal Vaskoddd76592022-01-17 13:34:48 +01001049 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001050 * @param[in] NODE lyd_value variable
1051 * @param[in] CANNONICAL_VAL expected cannonical value
1052 * @param[in] VALUE expected inteager value.
1053 */
1054#define CHECK_LYD_VALUE_INT16(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001055 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001056 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001057 assert_non_null((NODE).realtype); \
1058 assert_int_equal(LY_TYPE_INT16, (NODE).realtype->basetype); \
1059 assert_int_equal(VALUE, (NODE).int16);
1060
1061/**
1062 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type UINT8.
1063 * Example CHECK_LYD_VALUE(node->value, UINT8, "12", 12);
Michal Vaskoddd76592022-01-17 13:34:48 +01001064 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001065 * @param[in] NODE lyd_value variable
1066 * @param[in] CANNONICAL_VAL expected cannonical value
1067 * @param[in] VALUE expected inteager (0 to 255).
1068 */
1069#define CHECK_LYD_VALUE_UINT8(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001070 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001071 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001072 assert_non_null((NODE).realtype); \
1073 assert_int_equal(LY_TYPE_UINT8, (NODE).realtype->basetype); \
1074 assert_int_equal(VALUE, (NODE).uint8);
1075
1076/**
Radek Išaa76902f2021-03-29 08:52:51 +02001077 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type UINT32.
1078 * Example CHECK_LYD_VALUE(node->value, UINT32, "12", 12);
Michal Vaskoddd76592022-01-17 13:34:48 +01001079 *
Radek Išaa76902f2021-03-29 08:52:51 +02001080 * @param[in] NODE lyd_value variable
1081 * @param[in] CANNONICAL_VAL expected cannonical value
1082 * @param[in] VALUE expected inteager (0 to MAX_UINT32).
1083 */
1084#define CHECK_LYD_VALUE_UINT32(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001085 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001086 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Išaa76902f2021-03-29 08:52:51 +02001087 assert_non_null((NODE).realtype); \
1088 assert_int_equal(LY_TYPE_UINT32, (NODE).realtype->basetype); \
1089 assert_int_equal(VALUE, (NODE).uint32);
1090
1091/**
Radek Iša56ca9e42020-09-08 18:42:00 +02001092 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type STRING.
1093 * Example CHECK_LYD_VALUE(node->value, STRING, "text");
Michal Vaskoddd76592022-01-17 13:34:48 +01001094 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001095 * @param[in] NODE lyd_value variable
1096 * @param[in] CANNONICAL_VAL expected cannonical value
1097 */
1098#define CHECK_LYD_VALUE_STRING(NODE, CANNONICAL_VAL) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001099 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001100 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001101 assert_non_null((NODE).realtype); \
1102 assert_int_equal(LY_TYPE_STRING, (NODE).realtype->basetype);
1103
1104/**
1105 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type LEAFREF
Michal Vaskoddd76592022-01-17 13:34:48 +01001106 * Example CHECK_LYD_VALUE(node->value, LEAFREF, "");
1107 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001108 * @param[in] NODE lyd_value variable
1109 * @param[in] CANNONICAL_VAL expected cannonical value
1110 */
1111#define CHECK_LYD_VALUE_LEAFREF(NODE, CANNONICAL_VAL) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001112 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001113 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001114 assert_non_null((NODE).realtype); \
1115 assert_int_equal(LY_TYPE_LEAFREF, (NODE).realtype->basetype); \
1116 assert_non_null((NODE).ptr)
1117
1118/**
1119 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type DEC64
1120 * Example CHECK_LYD_VALUE(node->value, DEC64, "125", 125);
Michal Vaskoddd76592022-01-17 13:34:48 +01001121 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001122 * @param[in] NODE lyd_value variable
1123 * @param[in] CANNONICAL_VAL expected cannonical value
1124 * @param[in] VALUE expected value 64bit inteager
1125*/
1126#define CHECK_LYD_VALUE_DEC64(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001127 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001128 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001129 assert_non_null((NODE).realtype); \
1130 assert_int_equal(LY_TYPE_DEC64, (NODE).realtype->basetype); \
1131 assert_int_equal(VALUE, (NODE).dec64);
1132
1133/**
1134 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type BINARY.
1135 * Example CHECK_LYD_VALUE(node->value, BINARY, "aGVs\nbG8=");
Michal Vaskoddd76592022-01-17 13:34:48 +01001136 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001137 * @param[in] NODE lyd_value variable
1138 * @param[in] CANNONICAL_VAL expected cannonical value
Michal Vasko495f4502021-04-27 14:48:05 +02001139 * @param[in] VALUE expected value data
1140 * @param[in] SIZE expected value data size
Radek Iša56ca9e42020-09-08 18:42:00 +02001141*/
Michal Vasko495f4502021-04-27 14:48:05 +02001142#define CHECK_LYD_VALUE_BINARY(NODE, CANNONICAL_VAL, VALUE, SIZE) \
Michal Vaskoaa0ee622021-05-11 09:29:25 +02001143 { \
1144 struct lyd_value_binary *_val; \
1145 LYD_VALUE_GET(&(NODE), _val); \
1146 assert_int_equal(_val->size, SIZE); \
1147 assert_int_equal(0, memcmp(_val->data, VALUE, SIZE)); \
1148 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
1149 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
1150 assert_non_null((NODE).realtype); \
1151 assert_int_equal(LY_TYPE_BINARY, (NODE).realtype->basetype); \
1152 }
Radek Iša56ca9e42020-09-08 18:42:00 +02001153
1154/**
1155 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type BOOL.
1156 * Example CHECK_LYD_VALUE(node->value, BOOL, "true", 1);
Michal Vaskoddd76592022-01-17 13:34:48 +01001157 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001158 * @param[in] NODE lyd_value variable
1159 * @param[in] CANNONICAL_VAL expected cannonical value
1160 * @param[in] VALUE expected boolean value 0,1
1161*/
1162#define CHECK_LYD_VALUE_BOOL(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001163 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001164 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001165 assert_non_null((NODE).realtype); \
1166 assert_int_equal(LY_TYPE_BOOL, (NODE).realtype->basetype); \
1167 assert_int_equal(VALUE, (NODE).boolean);
1168
1169/**
1170 * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type IDENT.
1171 * Example CHECK_LYD_VALUE(node->value, IDENT, "types:gigabit-ethernet", "gigabit-ethernet");
Michal Vaskoddd76592022-01-17 13:34:48 +01001172 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001173 * @param[in] NODE lyd_value variable
1174 * @param[in] CANNONICAL_VAL expected cannonical value
1175 * @param[in] VALUE expected ident name
1176*/
1177#define CHECK_LYD_VALUE_IDENT(NODE, CANNONICAL_VAL, VALUE) \
Radek Krejci6d5ba0c2021-04-26 07:49:59 +02001178 assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
Radek Krejci995784f2021-04-26 08:02:13 +02001179 assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001180 assert_non_null((NODE).realtype); \
1181 assert_int_equal(LY_TYPE_IDENT, (NODE).realtype->basetype); \
1182 assert_string_equal(VALUE, (NODE).ident->name);
1183
1184/**
Radek Išaa9ff2b82021-01-13 21:44:13 +01001185 * @brief Macro testing parser when parsing incorrect module;
Michal Vaskoddd76592022-01-17 13:34:48 +01001186 *
Radek Išaa9ff2b82021-01-13 21:44:13 +01001187 * @param[in] DATA String storing the schema module representation.
1188 * @param[in] FORMAT Schema format of the @p DATA
1189 * @param[in] FEATURES Array of module's features to enable
1190 * @param[in] RET_VAL ly_in_new_memory return error value
1191 */
1192#define UTEST_INVALID_MODULE(DATA, FORMAT, FEATURES, RET_VAL) \
1193 { \
Michal Vasko4de7d072021-07-09 09:13:18 +02001194 struct lys_module *mod; \
Radek Išaa9ff2b82021-01-13 21:44:13 +01001195 assert_int_equal(LY_SUCCESS, ly_in_new_memory(DATA, &_UC->in)); \
1196 assert_int_equal(RET_VAL, lys_parse(_UC->ctx, _UC->in, FORMAT, FEATURES, &mod)); \
1197 assert_null(mod); \
1198 } \
1199 ly_in_free(_UC->in, 0); \
1200 _UC->in = NULL; \
1201
1202/**
Radek Iša56ca9e42020-09-08 18:42:00 +02001203 * @brief Add module (from a string) into the used libyang context.
Michal Vaskoddd76592022-01-17 13:34:48 +01001204 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001205 * @param[in] DATA String storing the schema module representation.
1206 * @param[in] FORMAT Schema format of the @p DATA
1207 * @param[in] FEATURES Array of module's features to enable
1208 * @param[out] MOD Optional parameter as a pointer to variable to store the resulting module.
1209 */
1210#define UTEST_ADD_MODULE(DATA, FORMAT, FEATURES, MOD) \
1211 assert_int_equal(LY_SUCCESS, ly_in_new_memory(DATA, &_UC->in)); \
1212 assert_int_equal(LY_SUCCESS, lys_parse(_UC->ctx, _UC->in, FORMAT, FEATURES, MOD)); \
1213 ly_in_free(_UC->in, 0); \
1214 _UC->in = NULL
1215
1216/**
1217 * @brief Internal macro to compare error info record with the expected error message and path.
1218 * If NULL is provided as MSG, no error info record (NULL) is expected.
Michal Vaskoddd76592022-01-17 13:34:48 +01001219 *
Radek Iša56ca9e42020-09-08 18:42:00 +02001220 * @param[in] ERR Error information record from libyang context.
1221 * @param[in] MSG Expected error message.
1222 * @param[in] PATH Expected error path.
1223 *
1224 */
1225#define _CHECK_LOG_CTX(ERR, MSG, PATH) \
1226 if (!MSG) { \
1227 assert_null(ERR); \
1228 } else { \
1229 assert_non_null(ERR); \
1230 CHECK_STRING((ERR)->msg, MSG); \
1231 CHECK_STRING((ERR)->path, PATH); \
1232 }
1233
1234/**`
1235 * @brief Internal macro to check the last libyang's context error.
1236 */
1237#define _CHECK_LOG_CTX1(MSG, PATH) \
1238 _CHECK_LOG_CTX(ly_err_last(_UC->ctx), MSG, PATH)
1239
1240/**
1241 * @brief Internal macro to check the last two libyang's context error.
1242 */
1243#define _CHECK_LOG_CTX2(MSG1, PATH1, MSG2, PATH2) \
1244 _CHECK_LOG_CTX(ly_err_last(_UC->ctx), MSG1, PATH1); \
1245 _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev, MSG2, PATH2)
1246
1247/**
1248 * @brief Internal macro to check the last three libyang's context error.
1249 */
1250#define _CHECK_LOG_CTX3(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3) \
1251 _CHECK_LOG_CTX2(MSG1, PATH1, MSG2, PATH2); \
1252 _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev, MSG3, PATH3)
1253
1254/**
Radek Krejcife6ec262021-01-20 10:28:28 +01001255 * @brief Internal macro to check the last three libyang's context error.
1256 */
1257#define _CHECK_LOG_CTX4(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4) \
1258 _CHECK_LOG_CTX3(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3); \
1259 _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev, MSG4, PATH4)
1260
1261/**
1262 * @brief Internal macro to check the last three libyang's context error.
1263 */
1264#define _CHECK_LOG_CTX5(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5) \
1265 _CHECK_LOG_CTX4(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4); \
1266 _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev->prev, MSG5, PATH5)
1267
1268/**
Radek Krejci8297b792020-08-16 14:49:05 +02001269 * @brief Internal macro to check the last three libyang's context error.
1270 */
1271#define _CHECK_LOG_CTX6(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6) \
1272 _CHECK_LOG_CTX5(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5); \
1273 _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev->prev->prev, MSG6, PATH6)
1274
1275/**
1276 * @brief Internal macro to check the last three libyang's context error.
1277 */
1278#define _CHECK_LOG_CTX7(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6, MSG7, PATH7) \
1279 _CHECK_LOG_CTX6(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6); \
1280 _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev->prev->prev->prev, MSG7, PATH7)
1281
1282/**
1283 * @brief Internal macro to check the last three libyang's context error.
1284 */
1285#define _CHECK_LOG_CTX8(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6, MSG7, PATH7, MSG8, PATH8) \
1286 _CHECK_LOG_CTX7(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6, MSG7, PATH7); \
1287 _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev->prev->prev->prev->prev, MSG8, PATH8)
1288
1289/**
Radek Iša56ca9e42020-09-08 18:42:00 +02001290 * @brief Internal helper macro to select _CHECK_LOG_CTX* macro according to the provided parameters.
1291 */
Radek Krejci8297b792020-08-16 14:49:05 +02001292#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 +02001293
1294/**
1295 * @brief Check expected error(s) in libyang context.
1296 *
1297 * Macro has variadic parameters expected to be provided in pairs of error message and error path starting
1298 * from the latest error. Current limit is checking at most 3 last errors. After checking, macro cleans up
1299 * all the errors from the libyang context.
1300 *
1301 * @param[in] MSG Expected error message.
1302 * @param[in] PATH Expected error path.
1303 */
1304#define CHECK_LOG_CTX(...) \
Radek Krejci8297b792020-08-16 14:49:05 +02001305 _GET_CHECK_LOG_MACRO(__VA_ARGS__, _CHECK_LOG_CTX8, _INVAL, _CHECK_LOG_CTX7, _INVAL, \
1306 _CHECK_LOG_CTX6, _INVAL, _CHECK_LOG_CTX5, _INVAL, _CHECK_LOG_CTX4, _INVAL, \
Michal Vasko151ae6c2021-09-23 08:23:51 +02001307 _CHECK_LOG_CTX3, _INVAL, _CHECK_LOG_CTX2, _INVAL, _CHECK_LOG_CTX1, DUMMY)(__VA_ARGS__); \
Radek Iša56ca9e42020-09-08 18:42:00 +02001308 ly_err_clean(_UC->ctx, NULL)
1309
1310/**
Michal Vaskoe9391c72021-10-05 10:04:56 +02001311 * @brief Check expected error in libyang context including error-app-tag.
1312 *
1313 * @param[in] MSG Expected error message.
1314 * @param[in] PATH Expected error path.
1315 * @param[in] APPTAG Expected error-app-tag.
1316 */
1317#define CHECK_LOG_CTX_APPTAG(MSG, PATH, APPTAG) \
1318 if (!MSG) { \
1319 assert_null(ly_err_last(_UC->ctx)); \
1320 } else { \
1321 assert_non_null(ly_err_last(_UC->ctx)); \
1322 CHECK_STRING(ly_err_last(_UC->ctx)->msg, MSG); \
1323 CHECK_STRING(ly_err_last(_UC->ctx)->path, PATH); \
1324 CHECK_STRING(ly_err_last(_UC->ctx)->apptag, APPTAG); \
1325 } \
1326 ly_err_clean(_UC->ctx, NULL)
1327
1328/**
Radek Iša56ca9e42020-09-08 18:42:00 +02001329 * @brief Clean up the logging callback's storage.
1330 */
1331#define UTEST_LOG_CLEAN \
1332 free(_UC->err_msg); \
1333 free(_UC->err_path); \
1334 _UC->err_msg = NULL; \
1335 _UC->err_path = NULL;
1336
1337/**
1338 * @brief Check expected error directly logged via logging callback.
1339 * Useful mainly for messages logged by functions without access to libyang context.
1340 * @param[in] MSG Expected error message.
1341 * @param[in] PATH Expected error path.
1342 */
1343#define CHECK_LOG(MSG, PATH) \
1344 CHECK_STRING(_UC->err_msg, MSG); \
1345 CHECK_STRING(_UC->err_path, PATH); \
1346 UTEST_LOG_CLEAN
1347
1348#ifdef _UTEST_MAIN_
1349/*
1350 * Functions inlined into each C source file including this header with _UTEST_MAIN_ defined
1351 */
1352
1353/**
1354 * @brief Global variable holding the tests context to simplify access to it.
1355 */
1356struct utest_context *current_utest_context;
1357
1358/* set to 0 to printing error messages to stderr instead of checking them in code */
1359#define ENABLE_LOGGER_CHECKING 1
1360
1361/**
1362 * @brief Logging callback for libyang.
1363 */
1364static void
1365_utest_logger(LY_LOG_LEVEL level, const char *msg, const char *path)
1366{
1367 (void) level; /* unused */
1368
1369 if (ENABLE_LOGGER_CHECKING == 0) {
Radek Išaa9ff2b82021-01-13 21:44:13 +01001370 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 +02001371 } else {
1372 free(current_utest_context->err_msg);
1373 current_utest_context->err_msg = msg ? strdup(msg) : NULL;
1374 free(current_utest_context->err_path);
1375 current_utest_context->err_path = path ? strdup(path) : NULL;
1376 }
1377}
1378
1379/**
1380 * @brief Generic utest's setup
1381 */
1382static int
1383utest_setup(void **state)
1384{
Michal Vasko86421632021-05-04 13:11:25 +02001385 char *cur_tz;
1386
Radek Iša56ca9e42020-09-08 18:42:00 +02001387 /* setup the logger */
1388 ly_set_log_clb(_utest_logger, 1);
1389 ly_log_options(LY_LOLOG | LY_LOSTORE);
1390
1391 current_utest_context = calloc(1, sizeof *current_utest_context);
1392 assert_non_null(current_utest_context);
1393 *state = current_utest_context;
1394
1395 /* libyang context */
1396 assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &current_utest_context->ctx));
1397
Radek Krejci968d7552021-03-26 20:33:51 +01001398 /* clean all errors from the setup - usually warnings regarding the plugins directories */
1399 UTEST_LOG_CLEAN;
1400
Michal Vasko86421632021-05-04 13:11:25 +02001401 /* backup timezone, if any */
1402 cur_tz = getenv("TZ");
1403 if (cur_tz) {
1404 current_utest_context->orig_tz = strdup(cur_tz);
1405 }
1406
1407 /* set CET */
1408 setenv("TZ", "CET+02:00", 1);
1409
Radek Iša56ca9e42020-09-08 18:42:00 +02001410 return 0;
1411}
1412
1413/**
1414 * @brief macro to include generic utest's setup into the test-specific setup.
1415 *
1416 * Place at the beginning of the test-specific setup
1417 */
1418#define UTEST_SETUP \
1419 assert_int_equal(0, utest_setup(state))
1420
1421/**
1422 * @brief Generic utest's teardown
1423 */
1424static int
1425utest_teardown(void **state)
1426{
1427 *state = NULL;
1428
1429 /* libyang context */
Radek Krejci90ed21e2021-04-12 14:47:46 +02001430 ly_ctx_destroy(current_utest_context->ctx);
Radek Iša56ca9e42020-09-08 18:42:00 +02001431
Michal Vasko86421632021-05-04 13:11:25 +02001432 if (current_utest_context->orig_tz) {
1433 /* restore TZ */
1434 setenv("TZ", current_utest_context->orig_tz, 1);
1435 }
1436
Radek Iša56ca9e42020-09-08 18:42:00 +02001437 /* utest context */
1438 ly_in_free(current_utest_context->in, 0);
1439 free(current_utest_context->err_msg);
1440 free(current_utest_context->err_path);
Michal Vasko86421632021-05-04 13:11:25 +02001441 free(current_utest_context->orig_tz);
Radek Iša56ca9e42020-09-08 18:42:00 +02001442 free(current_utest_context);
1443 current_utest_context = NULL;
1444
1445 return 0;
1446}
1447
1448/**
1449 * @brief macro to include generic utest's teardown into the test-specific teardown.
1450 *
1451 * Place at the end of the test-specific teardown
1452 */
1453#define UTEST_TEARDOWN \
1454 assert_int_equal(0, utest_teardown(state))
1455
1456/**
1457 * @brief Internal macro for utest setup with test-specific setup and teardown
1458 */
1459#define _UTEST_SETUP_TEARDOWN(FUNC, SETUP, TEARDOWN) \
1460 cmocka_unit_test_setup_teardown(FUNC, SETUP, TEARDOWN)
1461
1462/**
1463 * @brief Internal macro for utest setup with test-specific setup and generic teardown
1464 */
1465#define _UTEST_SETUP(FUNC, SETUP) \
1466 cmocka_unit_test_setup_teardown(FUNC, SETUP, utest_teardown)
1467
1468/**
1469 * @brief Internal macro for utest setup with generic setup and teardown
1470 */
1471#define _UTEST(FUNC) \
1472 cmocka_unit_test_setup_teardown(FUNC, utest_setup, utest_teardown)
1473
1474/**
1475 * @brief Internal helper macro to select _UTEST* macro according to the provided parameters.
1476 */
1477#define _GET_UTEST_MACRO(_1, _2, _3, NAME, ...) NAME
1478
1479/**
1480 * @brief Macro to specify test function using utest environment. Macro has variadic parameters
1481 * to provide test-specific setup/teardown functions:
1482 *
1483 * UTEST(test_func) - only implicit setup and teardown functions are used
1484 * UTEST(test_func, setup) - implicit teardown but own setup
1485 * UTEST(test_func, setup, teardown) - both setup and teardown are test-specific
1486 */
1487#define UTEST(...) \
Michal Vasko151ae6c2021-09-23 08:23:51 +02001488 _GET_UTEST_MACRO(__VA_ARGS__, _UTEST_SETUP_TEARDOWN, _UTEST_SETUP, _UTEST, DUMMY)(__VA_ARGS__)
Radek Iša56ca9e42020-09-08 18:42:00 +02001489
1490#else /* _UTEST_MAIN_ */
1491
1492extern struct utest_context *current_utest_context;
1493
1494#endif /* _UTEST_MAIN_ */
1495
1496#endif /* _UTESTS_H_ */