1

I want to test in eclipse with cunit test framework one structure, but it looks like the stream is still opened, and I can't get results. Here is my code. Thanks for help.

void test_is_male()
{
person* test_person= (person*)malloc(sizeof(person));
test_person->sex = 'M';
CU_ASSERT(is_male(test_person));

test_person->sex = 'F';
CU_ASSERT_FALSE(is_male(test_person));
}
void test_is_female()
{
person* test_person= (person*)malloc(sizeof(person));
test_person->sex = 'F';
CU_ASSERT(is_female(test_person));
test_person->sex = 'M';
CU_ASSERT_FALSE(is_female(test_person));

}

void test_is_surname_AL()
{
person* test_person= (person*)malloc(sizeof(person));
strcpy(test_person->surname, "ARSENE");
CU_ASSERT(is_surname_AL(test_person));

strcpy(test_person->surname, "PI");
CU_ASSERT_FALSE(is_surname_AL(test_person));
}

void test_is_surname_MZ()
{
person* test_person= (person*)malloc(sizeof(person));
strcpy(test_person->surname, "MINE");
CU_ASSERT(is_surname_MZ(test_person));

strcpy(test_person->surname, "ISHIKAWA");
CU_ASSERT_FALSE(is_surname_MZ(test_person));

}

void test_read_person(){
char* argv;
int argc;
FILE* ptr_test_opeople = fopen(argv[1], "r");
person* p = read_person(ptr_test_opeople);
fclose(ptr_test_opeople);
CU_ASSERT_STRING_EQUAL(p->surname, "TOPO");
CU_ASSERT_STRING_EQUAL(p->name, "LINO");
CU_ASSERT_STRING_EQUAL(p->birth_date, "01/02/1903");
CU_ASSERT_STRING_EQUAL(p->birth_place, "ROMA");
CU_ASSERT_STRING_EQUAL(p->sex, "M");
CU_ASSERT_STRING_EQUAL(p->cf, "/0");

}


/*
 * Funzioni di inizializzazione e pulizia delle suite.
 * Di default sono funzioni vuote.
 */
int init_suite_default(void) {
return 0;
}

int clean_suite_default(void) {
return 0;
}


/* **************************************************
*   TEST di UNITA'
*/

int main() {
/* inizializza registro - e' la prima istruzione */
CU_initialize_registry();

/* Aggiungi le suite al test registry */
CU_pSuite pSuite_FILTER_TEST = CU_add_suite("Suite_FILTER",             
init_suite_default, clean_suite_default);
CU_pSuite pSuite_B = CU_add_suite("Suite_B", init_suite_default,                  clean_suite_default);

/* Aggiungi i test alle suite
 * NOTA - L'ORDINE DI INSERIMENTO E' IMPORTANTE
 */
CU_add_test(pSuite_FILTER_TEST, "test of is_male", test_is_male);

CU_add_test(pSuite_FILTER_TEST, "test of is_female", test_is_female);

CU_add_test(pSuite_FILTER_TEST, "test of is_surname_AL", test_is_surname_AL);

CU_add_test(pSuite_FILTER_TEST, "test of is_surname_MZ", test_is_surname_MZ);

CU_add_test(pSuite_B, "test of read_person", test_read_person);

/* Esegue tutti i casi di test con output sulla console */
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();

/* Pulisce il registro e termina lo unit test */
CU_cleanup_registry();

return CU_get_error();
}

I think I need to use a macro instead of using the argv and argc parameters, that are used to pass a path to the test file. But I need an example if is possible. Sorry for my English guys, and thanks a lot.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Met
  • 11
  • 1

0 Answers0