Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #103604

CUnit zombie code

From MehdiAmini <atorrses@gmail.com>
Newsgroups comp.lang.c
Subject CUnit zombie code
Date 2017-02-10 17:35 +0330
Organization A noiseless patient Spider
Message-ID <o7kh88$k9d$1@dont-email.me> (permalink)

Show all headers | View raw


// This is a demonstration of how to use CUnit testing library.

#include <stdlib.h>
#include <stdio.h>

#include <CUnit/CUnit.h>
#include <CUnit/Basic.h>
#include <CUnit/Console.h>

_Noreturn void my_err(const char*);
int maxi(int , int );
void test_maxi(void);

_Noreturn void my_err(const char *s)
{
     if( (s==NULL) || ( *s=='\0') )
     {
         fprintf(stderr,"Please provide a proper message for my_err 
function\n");
         exit(EXIT_FAILURE);
     }
     fprintf(stderr,"%s",s);
     fprintf(stderr,"\n");
     exit(EXIT_FAILURE);
}

int maxi(int i1, int i2)
{
     return (i1 > i2) ? i1 : i2;
}

void test_maxi(void)
{
     CU_ASSERT(maxi(0,2) == 2);
     CU_ASSERT(maxi(0,-2) == 0);
     CU_ASSERT(maxi(2,2) == 2);
}

int main(void)
{
     int ir;

     ir = CU_initialize_registry();
     if (ir == CUE_NOMEMORY)
         my_err("Initialization failed.");

     CU_pSuite suite1 = CU_add_suite("maxi_test", NULL, NULL);
     if (suite1 == NULL)
         my_err("suite1 creation failed.");
     CU_pTest test1 = CU_add_test(suite1, "maxi_fun", test_maxi);
     if (test1 == NULL)
         my_err("test1 creation failed.");

     CU_basic_set_mode(CU_BRM_VERBOSE); // Any alternatives to this?

     CU_console_run_tests();
     //CU_automated_run_tests();
     //CU_basic_run_tests();

     CU_cleanup_registry();

     return EXIT_SUCCESS;
}



-- 
Farewell.

Back to comp.lang.c | Previous | Next | Find similar | Unroll thread


Thread

CUnit zombie code MehdiAmini <atorrses@gmail.com> - 2017-02-10 17:35 +0330

csiph-web