This source file includes following definitions.
- mctest_run_all
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
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", #actual_pointer); \
51 }
52
53 #define mctest_assert_false(actual_pointer) \
54 { \
55 ck_assert_msg ((int) actual_pointer == 0, "%s variable should be FALSE", #actual_pointer); \
56 }
57
58
59
60
61
62 #define START_PARAMETRIZED_TEST(name_test, struct_name) \
63 START_TEST (name_test) \
64 { \
65 const struct struct_name *data = &struct_name[_i];
66
67
68
69
70 #define END_PARAMETRIZED_TEST \
71 } \
72 END_TEST
73
74
75
76
77
78
79
80
81
82
83
84 static inline int
85 mctest_run_all (TCase *tc_core)
86 {
87 Suite *s;
88 SRunner *sr;
89 int number_failed;
90
91 s = suite_create (TEST_SUITE_NAME);
92 suite_add_tcase (s, tc_core);
93 sr = srunner_create (s);
94 srunner_set_log (sr, "-");
95 srunner_run_all (sr, CK_ENV);
96 number_failed = srunner_ntests_failed (sr);
97 srunner_free (sr);
98
99 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
100 }
101
102 #endif