cunit
A Unit Testing Framework for C
SlackBuild
Sample test
1 man CUnit
Compile cc
1 cunitSample.c -o cunitSample -lcunit
cunitSample.c
1 /*
2 * cc cunitSample.c -o cunitSample -lcunit
3 * ./cunitSample
4 */
5 #include <CUnit/Basic.h>
6
7 int sum(int a,int b){
8 return a+b+1;
9 }
10
11 void testSum(void){
12 CU_ASSERT(5 == sum(2,3) );
13 }
14
15 int init_suite(void){
16 return 0;
17 }
18
19 int clean_suite(void){
20 return 0;
21 }
22
23 int main()
24 {
25 CU_pSuite pSuite = NULL;
26
27 /* initialize the CUnit test registry */
28 if (CUE_SUCCESS != CU_initialize_registry())
29 return CU_get_error();
30
31 /* add a suite to the registry */
32 pSuite = CU_add_suite("Suite", init_suite, clean_suite);
33 if (NULL == pSuite) {
34 CU_cleanup_registry();
35 return CU_get_error();
36 }
37
38 /* add the tests to the suite */
39 if (NULL == CU_add_test(pSuite, "test of sum()", testSum))
40 {
41 CU_cleanup_registry();
42 return CU_get_error();
43 }
44
45 /* Run all tests using the CUnit Basic interface */
46 CU_basic_set_mode(CU_BRM_VERBOSE);
47 CU_basic_run_tests();
48 CU_cleanup_registry();
49 return CU_get_error();
50 }