cunit

http://cunit.sourceforge.net/

A Unit Testing Framework for C

SlackBuild

   1 cd /tmp
   2 wget http://slackbuilds.org/slackbuilds/14.1/development/cunit.tar.gz
   3 tar xvzf cunit.tar.gz
   4 cd cunit
   5 wget http://sourceforge.net/projects/cunit/files/CUnit/2.1-3/CUnit-2.1-3.tar.bz2
   6 ./cunit.SlackBuild
   7 installpkg /tmp/cunit-2.1_3-i486-1_SBo.tgz

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 }

c/cunit (last edited 2023-05-26 13:45:12 by 127)