Welcome to mirror list, hosted at ThFree Co, Russian Federation.

zbxcunit.h « zbxcunit « libs « src - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2ce2be7425819e7575e667c27f48da558380600c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
** Zabbix
** Copyright (C) 2001-2019 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/

#ifndef ZABBIX_ZBXCUNIT_H
#define ZABBIX_ZBXCUNIT_H

#ifdef ZBX_CUNIT

#include <malloc.h>
#include <CUnit/Basic.h>
#include <CUnit/Automated.h>

#include "zbxalgo.h"

#define ZBX_CU_STR2(str)		#str
#define ZBX_CU_STR(str)			ZBX_CU_STR2(str)
#define ZBX_CU_SUITE_PREFIX		zbx_cu_init_
#define ZBX_CU_SUITE_PREFIX_STR		ZBX_CU_STR(ZBX_CU_SUITE_PREFIX)

#define ZBX_CU_DECLARE3(prefix, suite)	prefix ## suite(void)
#define ZBX_CU_DECLARE2(prefix, suite)	ZBX_CU_DECLARE3(prefix, suite)
#define ZBX_CU_DECLARE(suite)		ZBX_CU_DECLARE2(ZBX_CU_SUITE_PREFIX, suite)

typedef int (*zbx_cu_init_suite_func_t)(void);

#define ZBX_CU_LEAK_CHECK_START()	struct mallinfo zbx_cu_minfo = mallinfo()
#define ZBX_CU_LEAK_CHECK_END()	{						\
		struct mallinfo minfo_local;					\
		minfo_local = mallinfo(); 					\
		CU_ASSERT_EQUAL(minfo_local.uordblks, zbx_cu_minfo.uordblks);	\
	}

#define ZBX_CU_ADD_TEST(suite, function)					\
	if (NULL == CU_add_test(suite, #function, function))		\
	{										\
		fprintf(stderr, "Error adding test suite \"" #function "\"\n");		\
		return CU_get_error();							\
	}

#define ZBX_CU_ASSERT_STRING_EQ(desc, actual, expected) {							\
		CU_assertImplementation(!(strcmp((const char*)(actual), (const char*)(expected))), __LINE__,	\
			zbx_cu_assert_args_str(desc, "==", #actual, actual, #expected, expected),	\
			__FILE__, "", CU_FALSE);								\
		}

#define ZBX_CU_ASSERT_STRING_EQ_FATAL(desc, actual, expected) {							\
		CU_assertImplementation(!(strcmp((const char*)(actual), (const char*)(expected))), __LINE__,	\
			zbx_cu_assert_args_str(desc, "==", #actual, actual, #expected, expected),		\
			__FILE__, "", CU_TRUE);									\
		}

#define ZBX_CU_ASSERT_STRINGN_EQ(desc, actual, expected, n) {							\
		CU_assertImplementation(!(strncmp((const char*)(actual), (const char*)(expected), n)), __LINE__,\
			zbx_cu_assert_args_str_n(desc, "==", #actual, actual, #expected, expected, n),		\
			__FILE__, "", CU_FALSE);								\
		}

#define ZBX_CU_ASSERT_STRINGN_EQ_FATAL(desc, actual, expected, n) {						\
		CU_assertImplementation(!(strncmp((const char*)(actual), (const char*)(expected), n)), __LINE__,\
			zbx_cu_assert_args_str_n(desc, "==", #actual, actual, #expected, expected, n),\
			__FILE__, "", CU_TRUE);									\
		}

#define ZBX_CU_ASSERT_INT_EQ(desc, actual, expected) {								\
		CU_assertImplementation((actual == expected) , __LINE__,					\
			zbx_cu_assert_args_int(desc, "==", #actual, actual, #expected, expected),	\
			__FILE__, "", CU_FALSE);								\
		}

#define ZBX_CU_ASSERT_INT_EQ_FATAL(desc, actual, expected) {							\
		CU_assertImplementation((actual == expected) , __LINE__,					\
			zbx_cu_assert_args_int(desc, "==", #actual, actual, #expected, expected),		\
			__FILE__, "", CU_TRUE);									\
		}

#define ZBX_CU_ASSERT_INT_NE(desc, actual, expected) {								\
		CU_assertImplementation((actual != expected) , __LINE__,					\
			zbx_cu_assert_args_int(desc, "!=", #actual, actual, #expected, expected),		\
			__FILE__, "", CU_FALSE);								\
		}

#define ZBX_CU_ASSERT_INT_NE_FATAL(desc, actual, expected) {							\
		CU_assertImplementation((actual != expected) , __LINE__,					\
			zbx_cu_assert_args_int(desc, "!=", #actual, actual, #expected, expected),		\
			__FILE__, "", CU_TRUE);									\
		}

#define ZBX_CU_ASSERT_UINT64_EQ(desc, actual, expected) {							\
		CU_assertImplementation((actual == expected) , __LINE__,					\
			zbx_cu_assert_args_ui64(desc, "==", #actual, actual, #expected, expected),		\
			__FILE__, "", CU_FALSE);								\
		}

#define ZBX_CU_ASSERT_UINT64_EQ_FATAL(desc, actual, expected) {							\
		CU_assertImplementation((actual == expected) , __LINE__,					\
			zbx_cu_assert_args_ui64(desc, "==", #actual, actual, #expected, expected),		\
			__FILE__, "", CU_TRUE);									\
		}


#define ZBX_CU_ASSERT_DOUBLE_EQ(desc, actual, expected) {							\
		CU_assertImplementation((actual == expected) , __LINE__,					\
			zbx_cu_assert_args_dbl(desc, "==", #actual, actual, #expected, expected),		\
			__FILE__, "", CU_FALSE);								\
		}

#define ZBX_CU_ASSERT_DOUBLE_EQ_FATAL(desc, actual, expected) {							\
		CU_assertImplementation((actual == expected) , __LINE__,					\
			zbx_cu_assert_args_dbl(desc, "==", #actual, actual, #expected, expected),		\
			__FILE__, "", CU_FALSE);								\
		}

#define ZBX_CU_ASSERT_CHAR_EQ(desc, actual, expected) {								\
		CU_assertImplementation((actual == expected) , __LINE__,					\
			zbx_cu_assert_args_char(desc, "==", #actual, actual, #expected, expected),		\
			__FILE__, "", CU_FALSE);								\
		}

#define ZBX_CU_ASSERT_CHAR_EQ_FATAL(desc, actual, expected) {							\
		CU_assertImplementation((actual == expected) , __LINE__,					\
			zbx_cu_assert_args_char(desc, "==", #actual, actual, #expected, expected),		\
			__FILE__, "", CU_TRUE);									\
		}

#define ZBX_CU_ASSERT_CHAR_NE(desc, actual, expected) {								\
		CU_assertImplementation((actual != expected) , __LINE__,					\
			zbx_cu_assert_args_char(desc, "!=", #actual, actual, #expected, expected),		\
			__FILE__, "", CU_FALSE);								\
		}

#define ZBX_CU_ASSERT_CHAR_NE_FATAL(desc, actual, expected) {							\
		CU_assertImplementation((actual != expected) , __LINE__,					\
			zbx_cu_assert_args_char(desc, "!=", #actual, actual, #expected, expected),		\
			__FILE__, "", CU_TRUE);									\
		}

#define ZBX_CU_ASSERT_PTR_NULL_FATAL(desc, ptr) {								\
		CU_assertImplementation((ptr == NULL) , __LINE__,						\
			zbx_cu_assert_args_str(desc, "==", #ptr, "", "NULL", ""),				\
			__FILE__, "", CU_TRUE);									\
		}

#define ZBX_CU_ASSERT_PTR_NOT_NULL_FATAL(desc, ptr) {								\
		CU_assertImplementation((ptr != NULL) , __LINE__,						\
			zbx_cu_assert_args_str(desc, "!=", #ptr, "", "NULL", ""),				\
			__FILE__, "", CU_TRUE);									\
		}

const char	*zbx_cu_assert_args_str(const char *description, const char *operation, const char *expression1,
		const char *actual, const char *expression2, const char *expected);

const char	*zbx_cu_assert_args_str_n(const char *description, const char *operation, const char *expression1,
		const char *actual, const char *expression2, const char *expected, size_t n);

const char	*zbx_cu_assert_args_ui64(const char *description, const char *operation, const char *expression1,
		zbx_uint64_t actual, const char *expression2, zbx_uint64_t expected);

const char	*zbx_cu_assert_args_dbl(const char *description, const char *operation, const char *expression1,
		double actual, const char *expression2, double expected);

const char	*zbx_cu_assert_args_int(const char *description, const char *operation, const char *expression1,
		int actual, const char *expression2, int expected);

const char	*zbx_cu_assert_args_char(const char *description, const char *operation, const char *expression1,
		char actual, const char *expression2, char expected);

void	zbx_cu_run(int args, char *argv[]);

void	*zbx_cu_galloc(void *old, size_t size);

const char	*zbx_cu_item_type_string(zbx_item_type_t item_type);
const char	*zbx_cu_poller_type_string(unsigned char poller_type);

#endif

#endif