FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
libfocunit.h
1 /* **************************************************************
2  Copyright (C) 2011 Hewlett-Packard Development Company, L.P.
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License
6  version 2 as published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 ************************************************************** */
17 #ifndef LIBFOCUNIT_H
18 #define LIBFOCUNIT_H
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <assert.h>
23 #include <getopt.h>
24 #include "CUnit/CUnit.h"
25 #include "CUnit/Automated.h"
26 
27 int focunit_main(int argc, char **argv, char *test_name, CU_SuiteInfo *suites);
28 
43 #define FO_PASS(msg) CU_PASS(msg)
44 
48 #define FO_ASSERT(value) CU_ASSERT(value)
49 
53 #define FO_ASSERT_FATAL(value) CU_ASSERT_FATAL(value)
54 
58 #define FO_TEST(value) CU_TEST(value)
59 
63 #define FO_TEST_FATAL(value) CU_TEST_FATAL(value)
64 
66 #define FO_FAIL(msg) CU_FAIL(msg)
67 
69 #define FO_FAIL_FATAL(msg) CU_FAIL_FATAL(msg)
70 
74 #define FO_ASSERT_TRUE(value) CU_ASSERT_TRUE(value)
75 
79 #define FO_ASSERT_TRUE_FATAL(value) CU_ASSERT_TRUE_FATAL(value)
80 
84 #define FO_ASSERT_FALSE(value) CU_ASSERT_FALSE(value)
85 
89 #define FO_ASSERT_FALSE_FATAL(value) CU_ASSERT_FALSE_FATAL(value)
90 
94 #define FO_ASSERT_EQUAL(actual, expected) \
95  { \
96  if (actual != expected) printf("%s(%d) Expected %d, got %d\n",\
97  __FILE__,__LINE__, expected, actual);\
98  CU_ASSERT_EQUAL(actual, expected)\
99  }
100 
104 #define FO_ASSERT_EQUAL_FATAL(actual, expected) \
105  { \
106  if (actual != expected) printf("FATAL: %s(%d) Expected %d, got %d\n",\
107  __FILE__,__LINE__, expected, actual);\
108  CU_ASSERT_EQUAL_FATAL(actual, expected)\
109  }
110 
114 #define FO_ASSERT_NOT_EQUAL(actual, expected) \
115  { \
116  if (actual == expected) printf("%s(%d) Expected != %d got %d\n",\
117  __FILE__,__LINE__, expected, actual);\
118  CU_ASSERT_NOT_EQUAL(actual, expected)\
119  }
120 
124 #define FO_ASSERT_NOT_EQUAL_FATAL(actual, expected) \
125  { \
126  if (actual == expected) printf("FATAL: %s(%d) Expected != %d, got %d\n",\
127  __FILE__,__LINE__, expected, actual);\
128  CU_ASSERT_NOT_EQUAL_FATAL(actual, expected)\
129  }
130 
134 #define FO_ASSERT_PTR_EQUAL(actual, expected) \
135  { \
136  if (actual != expected) printf("%s(%d) Expected %p, got %p\n",\
137  __FILE__,__LINE__, expected, actual);\
138  CU_ASSERT_PTR_EQUAL(actual, expected)\
139  }
140 
144 #define FO_ASSERT_PTR_EQUAL_FATAL(actual, expected) \
145  { \
146  if (actual != expected) printf("FATAL: %s(%d) Expected %p, got %p\n",\
147  __FILE__,__LINE__, expected, actual);\
148  CU_ASSERT_PTR_EQUAL_FATAL(actual, expected)\
149  }
150 
154 #define FO_ASSERT_PTR_NOT_EQUAL(actual, expected) \
155  { \
156  if (actual == expected) printf("%s(%d) Expected != %p got %p\n",\
157  __FILE__,__LINE__, expected, actual);\
158  CU_ASSERT_PTR_NOT_EQUAL(actual, expected)\
159  }
160 
164 #define FO_ASSERT_PTR_NOT_EQUAL_FATAL(actual, expected) \
165  { \
166  if (actual == expected) printf("FATAL: %s(%d) Expected != %p, got %p\n",\
167  __FILE__,__LINE__, expected, actual);\
168  CU_ASSERT_PTR_NOT_EQUAL_FATAL(actual, expected)\
169  }
170 
174 #define FO_ASSERT_PTR_NULL(value) CU_ASSERT_PTR_NULL(value)
175 
179 #define FO_ASSERT_PTR_NULL_FATAL(value) CU_ASSERT_PTR_NULL_FATAL(value)
180 
184 #define FO_ASSERT_PTR_NOT_NULL(value) CU_ASSERT_PTR_NOT_NULL(value)
185 
189 #define FO_ASSERT_PTR_NOT_NULL_FATAL(value) CU_ASSERT_PTR_NOT_NULL_FATAL(value)
190 
194 #define FO_ASSERT_STRING_EQUAL(actual, expected) \
195  { \
196  FO_ASSERT_PTR_NOT_NULL_FATAL(actual); \
197  if (0 != (strcmp((const char*)(actual), (const char*)(expected)))) \
198  printf("%s(%d) Expected (%s), got (%s)\n", __FILE__,__LINE__, expected, actual);\
199  CU_ASSERT_STRING_EQUAL(actual, expected)\
200  }
201 
205 #define FO_ASSERT_STRING_EQUAL_FATAL(actual, expected) \
206  { \
207  if (0 != (strcmp((const char*)(actual), (const char*)(expected)))) \
208  printf("FATAL: %s(%d) Expected (%s), got (%s)\n", __FILE__,__LINE__, expected, actual);\
209  CU_ASSERT_STRING_EQUAL_FATAL(actual, expected)\
210  }
211 
215 #define FO_ASSERT_STRING_NOT_EQUAL(actual, expected) \
216  { \
217  if (0 == strcmp((const char*)(actual), (const char*)(expected))) \
218  printf("%s(%d) Expected != (%s), got (%s)\n", __FILE__,__LINE__, expected, actual);\
219  CU_ASSERT_STRING_NOT_EQUAL(actual, expected)\
220  }
221 
225 #define FO_ASSERT_STRING_NOT_EQUAL_FATAL(actual, expected) \
226  { \
227  if (0 == strcmp((const char*)(actual), (const char*)(expected))) \
228  printf("FATAL: %s(%d) Expected != (%s), got (%s)\n", __FILE__,__LINE__, expected, actual);\
229  CU_ASSERT_STRING_NOT_EQUAL_FATAL(actual, expected)\
230  }
231 
236 #define FO_ASSERT_NSTRING_EQUAL(actual, expected, count) \
237  { \
238  if (0 != strcmp((const char*)(actual), (const char*)(expected), (size_t)(count))) \
239  printf("%s(%d) Expected (%s), got (%s)\n", __FILE__,__LINE__, expected, actual);\
240  CU_ASSERT_NSTRING_EQUAL(actual, expected, count)\
241  }
242 
247 #define FO_ASSERT_NSTRING_EQUAL_FATAL(actual, expected, count) \
248  { \
249  if (0 != strcmp((const char*)(actual), (const char*)(expected), (size_t)(count))) \
250  printf("FATAL: %s(%d) Expected (%s), got (%s)\n", __FILE__,__LINE__, expected, actual);\
251  CU_ASSERT_NSTRING_EQUAL_FATAL(actual, expected, count)\
252  }
253 
258 #define FO_ASSERT_NSTRING_NOT_EQUAL(actual, expected, count) \
259  { \
260  if (0 == strcmp((const char*)(actual), (const char*)(expected), (size_t)(count))) \
261  printf("%s(%d) Expected (%s), got (%s)\n", __FILE__,__LINE__, expected, actual);\
262  CU_ASSERT_NSTRING_NOT_EQUAL(actual, expected, count)\
263  }
264 
269 #define FO_ASSERT_NSTRING_NOT_EQUAL_FATAL(actual, expected, count) \
270  { \
271  if (0 == strcmp((const char*)(actual), (const char*)(expected), (size_t)(count))) \
272  printf("FATAL: %s(%d) Expected (%s), got (%s)\n", __FILE__,__LINE__, expected, actual);\
273  CU_ASSERT_NSTRING_NOT_EQUAL_FATAL(actual, expected, count)\
274  }
275 
280 #define FO_ASSERT_DOUBLE_EQUAL(actual, expected, granularity) \
281  { \
282  if (fabs((double)(actual) - (expected)) >= fabs((double)(granularity))) \
283  printf("%s(%d) Expected %f, got %f\n", __FILE__,__LINE__, expected, actual);\
284  CU_ASSERT_DOUBLE_EQUAL(actual, expected, granularity)\
285  }
286 
291 #define FO_ASSERT_DOUBLE_EQUAL_FATAL(actual, expected, granularity) \
292  { \
293  if (fabs((double)(actual) - (expected)) >= fabs((double)(granularity))) \
294  printf("FATAL: %s(%d) Expected %f, got %f\n", __FILE__,__LINE__, expected, actual);\
295  CU_ASSERT_DOUBLE_EQUAL_FATAL(actual, expected, granularity)\
296  }
297 
302 #define FO_ASSERT_DOUBLE_NOT_EQUAL(actual, expected, granularity) \
303  { \
304  if (fabs((double)(actual) - (expected)) <= fabs((double)(granularity)))\
305  printf("%s(%d) Expected %f, got %f\n", __FILE__,__LINE__, expected, actual);\
306  CU_ASSERT_DOUBLE_NOT_EQUAL(actual, expected, granularity)\
307  }
308 
313 #define FO_ASSERT_DOUBLE_NOT_EQUAL_FATAL(actual, expected, granularity) \
314  { \
315  if (fabs((double)(actual) - (expected)) <= fabs((double)(granularity))) \
316  printf("FATAL: %s(%d) Expected %f, got %f\n", __FILE__,__LINE__, expected, actual);\
317  CU_ASSERT_DOUBLE_NOT_EQUAL_FATAL(actual, expected, granularity)\
318  }
319 
320 #endif
CU_SuiteInfo suites[]
all test suites for delagent
Definition: testRun.h:54