#include
#include "process.h"
int process(int x, int y, int z){
int k=0;
int j=0;
if ((x>3) && (z<10)){
k=x*y-1;
j=k^2;
}
if((x==4) || (y>5)){
j=x*j+10;
}
j=j%3;
return k+j;
}
process.h
extern int process(int x, int y, int z);
test_main.c
#include
#include
#include
#include
#include
#include "process.h"
/* test cases */
void test_process_1(void)
{
CU_ASSERT(process(4,6,9)==24);
}
void test_process_2(void)
{
CU_ASSERT(process(4,5,10)==1);
}
void test_process_3(void)
{
CU_ASSERT(process(5,4,9)==21);
}
void test_process_4(void)
{
CU_ASSERT(process(2,5,10)==0);
}
CU_TestInfo tests[] = {
{"test 1", test_process_1 },
{"test 2", test_process_2 },
{"test 3", test_process_3 },
{"test 4", test_process_4 },
CU_TEST_INFO_NULL
};
/* suite init */
int suite_init(void)
{
return 0;
}
int suite_clean(void)
{
return 0;
}
void suite_setup(void)
{
}
void suite_teardown(void)
{
}
CU_SuiteInfo suites[] = {
{"suite 1", suite_init, suite_clean, suite_setup, suite_teardown, tests},
CU_SUITE_INFO_NULL
};
/* registry */
int main(int argc, char* argv[])
{
CU_ErrorCode err;
/* init */
printf("init\n");
err = CU_initialize_registry();
if( err ){
printf("CU_initialize_registry: %d\n", err);
return err;
}
/* add suites and tests */
printf("add suites and tests\n");
err = CU_register_suites(suites);
if( err )
{
printf("CU_register_suites: %d\n", err);
}
CU_pTestRegistry reg = CU_get_registry();
printf("CU_get_registry: %d/%d/%u\n", reg->uiNumberOfSuites, reg->uiNumberOfTests, (long)reg->pSuite);
/* run auto */
printf("run auto\n");
/**** Automated Mode *****************/
CU_set_output_filename("TestProcess");
CU_list_tests_to_file();
CU_automated_run_tests();
//************************************/
printf("run basic\n");
/***** Basice Mode *******************/
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
//************************************/
/*****Console Mode ********************
CU_console_run_tests();
/************************************/
/* end */
printf("end\n");
CU_cleanup_registry();
err = CU_get_error();
if( err )
{
printf("error: %d", err);
}
return err;
}