Size: 376
Comment:
|
Size: 1519
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 14: | Line 14: |
== Sample test == * man CUnit Compile cc cunitSample.c -o cunitSample -lcunit File cunitSample.c: {{{#!highlight c /* * cc cunitSample.c -o cunitSample -lcunit * ./cunitSample */ #include <CUnit/Basic.h> int sum(int a,int b){ return a+b+1; } void testSum(void){ CU_ASSERT(5 == sum(2,3) ); } int init_suite(void){ return 0; } int clean_suite(void){ return 0; } 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", init_suite, clean_suite); if (NULL == pSuite) { CU_cleanup_registry(); return CU_get_error(); } /* add the tests to the suite */ if (NULL == CU_add_test(pSuite, "test of sum()", testSum)) { 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(); } }}} |
cunit
A Unit Testing Framework for C
SlackBuild
- cd /tmp
wget http://slackbuilds.org/slackbuilds/14.1/development/cunit.tar.gz
- tar xvzf cunit.tar.gz
- cd cunit
wget http://sourceforge.net/projects/cunit/files/CUnit/2.1-3/CUnit-2.1-3.tar.bz2
./cunit.SlackBuild
- installpkg /tmp/cunit-2.1_3-i486-1_SBo.tgz
Sample test
- man CUnit
Compile cc cunitSample.c -o cunitSample -lcunit
File 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 }