1 #ifndef MC__TEST
2 #define MC__TEST
3
4 #include <config.h>
5 #include <stdlib.h>
6 #include <check.h>
7
8 #include "lib/global.h"
9
10 /*** typedefs(not structures) and defined constants **********************************************/
11
12 #define mctest_add_parameterized_test(tc_core, test_func, test_data_source) \
13 { \
14 tcase_add_loop_test (tc_core, test_func, 0, G_N_ELEMENTS (test_data_source)); \
15 }
16
17 #define mctest_assert_str_eq(actual_result, etalon_result) \
18 { \
19 g_assert_cmpstr (actual_result, ==, etalon_result); \
20 }
21
22 #define mctest_assert_ptr_eq(actual_pointer, etalon_pointer) \
23 { \
24 ck_assert_msg (actual_pointer == etalon_pointer, \
25 "%s(%p) pointer should be equal to %s(%p)\n", #actual_pointer, \
26 actual_pointer, #etalon_pointer, etalon_pointer); \
27 }
28
29 #define mctest_assert_ptr_ne(actual_pointer, etalon_pointer) \
30 { \
31 ck_assert_msg (actual_pointer != etalon_pointer, \
32 "%s(%p) pointer should not be equal to %s(%p)\n", #actual_pointer, \
33 actual_pointer, #etalon_pointer, etalon_pointer); \
34 }
35
36 #define mctest_assert_null(actual_pointer) \
37 { \
38 ck_assert_msg (((void *) actual_pointer) == NULL, "%s(%p) variable should be NULL", \
39 #actual_pointer, actual_pointer); \
40 }
41
42 #define mctest_assert_not_null(actual_pointer) \
43 { \
44 ck_assert_msg (((void *) actual_pointer) != NULL, "%s(nil) variable should not be NULL", \
45 #actual_pointer); \
46 }
47
48 #define mctest_assert_true(actual_pointer) \
49 { \
50 ck_assert_msg (((int) actual_pointer) != 0, "%s variable should be TRUE", \
51 #actual_pointer); \
52 }
53
54 #define mctest_assert_false(actual_pointer) \
55 { \
56 ck_assert_msg (((int) actual_pointer) == 0, "%s variable should be FALSE", \
57 #actual_pointer); \
58 }
59
60 /**
61 * Define header for a parameterized test.
62 * Declare 'data' variable for access to the parameters in current iteration
63 */
64 #define START_PARAMETRIZED_TEST(name_test, struct_name) \
65 START_TEST (name_test) \
66 { \
67 const struct struct_name *data = &struct_name[_i];
68
69 /**
70 * Define footer for a parameterized test.
71 */
72 #define END_PARAMETRIZED_TEST \
73 } \
74 END_TEST
75
76 /*** enums ***************************************************************************************/
77
78 /*** structures declarations (and typedefs of structures)*****************************************/
79
80 /*** global variables defined in .c file *********************************************************/
81
82 /*** declarations of public functions ************************************************************/
83
84 /*** inline functions ****************************************************************************/
85
86 static inline int
87 mctest_run_all (TCase *tc_core)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
88 {
89 Suite *s;
90 SRunner *sr;
91 int number_failed;
92
93 s = suite_create (TEST_SUITE_NAME);
94 suite_add_tcase (s, tc_core);
95 sr = srunner_create (s);
96 srunner_set_log (sr, "-");
97 srunner_run_all (sr, CK_ENV);
98 number_failed = srunner_ntests_failed (sr);
99 srunner_free (sr);
100
101 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
102 }
103
104 #endif