Size: 1519
Comment:
|
← Revision 6 as of 2023-05-26 13:45:12 ⇥
Size: 1603
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
## page was renamed from cunit | |
Line 7: | Line 8: |
* 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 |
{{{#!highlight sh 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 }}} |
Line 16: | Line 19: |
* man CUnit | {{{#!highlight sh man CUnit }}} |
Line 18: | Line 23: |
Compile cc cunitSample.c -o cunitSample -lcunit | Compile cc {{{#!highlight sh cunitSample.c -o cunitSample -lcunit }}} |
Line 20: | Line 28: |
File cunitSample.c: | === cunitSample.c === |
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 }