2013-01-19 17:42:26 +04:00
|
|
|
#ifndef MC__TEST
|
|
|
|
#define MC__TEST
|
|
|
|
|
|
|
|
#include <config.h>
|
2015-04-07 11:52:58 +03:00
|
|
|
#include <stdlib.h>
|
2013-01-19 17:42:26 +04:00
|
|
|
#include <check.h>
|
|
|
|
|
|
|
|
#include "lib/global.h"
|
|
|
|
|
|
|
|
/*** typedefs(not structures) and defined constants **********************************************/
|
|
|
|
|
2022-12-30 10:42:27 +03:00
|
|
|
#define mctest_add_parameterized_test(tc_core, test_func, test_data_source) { \
|
2013-04-12 14:36:56 +04:00
|
|
|
tcase_add_loop_test (tc_core, test_func, 0, G_N_ELEMENTS (test_data_source)); \
|
2013-01-19 17:42:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define mctest_assert_str_eq(actual_result, etalon_result) { \
|
|
|
|
g_assert_cmpstr (actual_result, ==, etalon_result); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define mctest_assert_ptr_eq(actual_pointer, etalon_pointer) { \
|
2015-04-07 11:52:58 +03:00
|
|
|
ck_assert_msg ( actual_pointer == etalon_pointer, \
|
2013-01-19 17:42:26 +04:00
|
|
|
"%s(%p) pointer should be equal to %s(%p)\n", \
|
|
|
|
#actual_pointer, actual_pointer, #etalon_pointer , etalon_pointer \
|
2022-12-30 10:42:27 +03:00
|
|
|
); \
|
2013-01-19 17:42:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define mctest_assert_ptr_ne(actual_pointer, etalon_pointer) { \
|
2015-04-07 11:52:58 +03:00
|
|
|
ck_assert_msg ( actual_pointer != etalon_pointer, \
|
2013-01-19 17:42:26 +04:00
|
|
|
"%s(%p) pointer should not be equal to %s(%p)\n", \
|
|
|
|
#actual_pointer, actual_pointer, #etalon_pointer , etalon_pointer \
|
2022-12-30 10:42:27 +03:00
|
|
|
); \
|
2013-01-19 17:42:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define mctest_assert_null(actual_pointer) { \
|
2022-12-30 10:42:27 +03:00
|
|
|
ck_assert_msg ( \
|
2013-01-19 17:42:26 +04:00
|
|
|
(void *) actual_pointer == NULL, \
|
|
|
|
"%s(%p) variable should be NULL", #actual_pointer, actual_pointer \
|
|
|
|
); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define mctest_assert_not_null(actual_pointer) { \
|
2022-12-30 10:42:27 +03:00
|
|
|
ck_assert_msg ( \
|
2015-04-07 11:52:58 +03:00
|
|
|
(void *) actual_pointer != NULL, \
|
2013-01-19 17:42:26 +04:00
|
|
|
"%s(nil) variable should not be NULL", #actual_pointer \
|
|
|
|
); \
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:52:58 +03:00
|
|
|
#define mctest_assert_true(actual_pointer) { \
|
2022-12-30 10:42:27 +03:00
|
|
|
ck_assert_msg ( \
|
2015-04-07 11:52:58 +03:00
|
|
|
(int) actual_pointer != 0, \
|
|
|
|
"%s variable should be TRUE", #actual_pointer \
|
|
|
|
); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define mctest_assert_false(actual_pointer) { \
|
2022-12-30 10:42:27 +03:00
|
|
|
ck_assert_msg ( \
|
2015-04-07 11:52:58 +03:00
|
|
|
(int) actual_pointer == 0, \
|
2022-02-20 17:37:48 +03:00
|
|
|
"%s variable should be FALSE", #actual_pointer \
|
2015-04-07 11:52:58 +03:00
|
|
|
); \
|
|
|
|
}
|
|
|
|
|
2013-01-19 17:42:26 +04:00
|
|
|
/**
|
|
|
|
* Define header for a parameterized test.
|
|
|
|
* Declare 'data' variable for access to the parameters in current iteration
|
|
|
|
*/
|
2022-12-30 10:42:27 +03:00
|
|
|
#define START_PARAMETRIZED_TEST(name_test, struct_name) \
|
|
|
|
START_TEST (name_test) { \
|
|
|
|
const struct struct_name *data = &struct_name[_i];
|
2013-01-19 17:42:26 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Define footer for a parameterized test.
|
|
|
|
*/
|
2022-12-30 10:42:27 +03:00
|
|
|
#define END_PARAMETRIZED_TEST \
|
|
|
|
} END_TEST
|
2013-01-19 17:42:26 +04:00
|
|
|
|
|
|
|
/*** enums ***************************************************************************************/
|
|
|
|
|
|
|
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
|
|
|
|
|
|
|
/*** global variables defined in .c file *********************************************************/
|
|
|
|
|
|
|
|
/*** declarations of public functions ************************************************************/
|
|
|
|
|
|
|
|
/*** inline functions ****************************************************************************/
|
|
|
|
|
2020-12-30 18:23:26 +03:00
|
|
|
static inline int
|
2024-06-01 21:12:14 +03:00
|
|
|
mctest_run_all (TCase *tc_core)
|
2020-12-30 18:23:26 +03:00
|
|
|
{
|
|
|
|
Suite *s;
|
|
|
|
SRunner *sr;
|
|
|
|
int number_failed;
|
|
|
|
|
|
|
|
s = suite_create (TEST_SUITE_NAME);
|
|
|
|
suite_add_tcase (s, tc_core);
|
|
|
|
sr = srunner_create (s);
|
|
|
|
srunner_set_log (sr, "-");
|
|
|
|
srunner_run_all (sr, CK_ENV);
|
|
|
|
number_failed = srunner_ntests_failed (sr);
|
|
|
|
srunner_free (sr);
|
|
|
|
|
|
|
|
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-01-19 17:42:26 +04:00
|
|
|
#endif /* MC__TEST */
|