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