我想用cunit测试框架一结构在eclipse中进行测试,但是看起来流还是打开的,拿不到结果。这是我的代码。感谢帮助。
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();
}
我想我需要使用宏而不是使用 argv 和 argc 参数,它们用于将路径传递给测试文件。但如果可能的话,我需要一个例子。对不起我的英语家伙,非常感谢。