-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcunit_fileA.c
55 lines (45 loc) · 1.43 KB
/
cunit_fileA.c
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
/*
* Simple example of a CUnit unit test.
*
* compile with -lcunit :
* gcc -o fileA.tests cunit_fileA.c fileA_suite.c fileA.c -lcunit
*
* the complete list of the CU_* can be found at
* http://cunit.sourceforge.net/doc/writing_tests.html#assertions
*/
/* use the basic interface */
#include "CUnit/Basic.h"
/* the file to test */
#include "fileA.h"
/* the suite to test */
#include "fileA_suite.h"
/* The main() function for setting up and running the tests.
* Returns a CUE_SUCCESS on successful running, another
* CUnit error code on failure.
*/
int main() {
CU_pSuite pSuite = NULL;
/* initialize the CUnit test registry */
if (CUE_SUCCESS != CU_initialize_registry())
return CU_get_error();
/* add a suite to the registry */
pSuite = CU_add_suite("Suite fileA", init_suite_fileA, clean_suite_fileA);
if (NULL == pSuite) {
CU_cleanup_registry();
return CU_get_error();
}
/* add the tests to the suite */
/* all the functions in fileA_suite.h must be added */
if ((NULL == CU_add_test(pSuite,
"test of simpleDivision() in classic cases", testNormalValues)) ||
(NULL == CU_add_test(pSuite,
"test of simpleDivision() in pathologic cases", testErrorValues))) {
CU_cleanup_registry();
return CU_get_error();
}
/* Run all tests using the CUnit Basic interface */
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
CU_cleanup_registry();
return CU_get_error();
}