#include #include #include #include "Mot.h" #define TRUE 1 #define FALSE 0 int init_suite_success(void) { return 0; } int clean_suite_success(void) { return 0; } // void test_MOT_creationMot(void) { // MOT_Mot motSansFonction; // MOT_Mot motAvecFonction; // char m[] = "manger"; // // strcpy(motSansFonction.mot,m); // motSansFonction.longueur = 6; // // motAvecFonction = MOT_creationMot(m); // CU_ASSERT_TRUE((motSansFonction.mot == motAvecFonction.mot) // && (motSansFonction.longueur == motAvecFonction.longueur)); // } void test_MOT_longueur(void) { char uneChaine[] = "jeanDO"; MOT_Mot unMot = MOT_creationMot(uneChaine); CU_ASSERT_TRUE(MOT_longueur(unMot) == 6); } void test_MOT_iEmeLettre(void) { MOT_Mot unMot; char uneChaine[] = "hello"; int bonneReponse = TRUE; unsigned int i = 0; strcpy(unMot.mot,uneChaine); unMot.longueur = 5; while (bonneReponse == TRUE && i < strlen(uneChaine)) { i = i+1; if (uneChaine[i] != unMot.mot[i]) { bonneReponse = FALSE; } } CU_ASSERT_TRUE(bonneReponse); } void test_MOT_insererCaractere(void) { MOT_Mot unMot; unMot.mot = NULL; strcpy(unMot.mot,"car"); unMot.longueur=3; MOT_insererCaractere(&unMot,'t',2); CU_ASSERT_TRUE( !strcmp("ctar", unMot.mot) && unMot.longueur==4); } void test_MOT_supprimerCaractere(void) { MOT_Mot unMot; unMot.mot = NULL; strcpy(unMot.mot,"joyeuxNoel"); unMot.longueur=10; MOT_supprimerCaractere(&unMot,9); CU_ASSERT_TRUE(!strcmp(unMot.mot,"joyeuxnoe") && unMot.longueur==9); } void test_MOT_echangerCaractere(void) { MOT_Mot unMot; unMot.mot = NULL; strcpy(unMot.mot,"vacances"); unMot.longueur=8; MOT_echangerCaractere(&unMot,1,7); CU_ASSERT_TRUE(!strcmp(unMot.mot,"vscancea") && unMot.longueur==3); } void test_MOT_estIdentique(void) { MOT_Mot unMot,unSecondMot; unMot.mot = NULL; unSecondMot.mot = NULL; strcpy(unMot.mot,"cadeaux"); strcpy(unSecondMot.mot,"cadeaux"); unMot.longueur=7; unSecondMot.longueur=7; CU_ASSERT_TRUE(MOT_estIdentique(unMot,unSecondMot)); } // void test_MOT_motEnChaine(void) { // char chaineInitiale[] = "neige"; // MOT_Mot unMot; // unMot.mot = NULL; // strcpy(unMot.mot,chaineInitiale); // unMot.longueur=5; // CU_ASSERT_TRUE(!strcmp(chaineInitiale,MOT_motEnChaine(unMot))); // } int main(int argc, char** argv){ CU_pSuite pSuite = NULL; /* initialisation du registre de tests */ if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error(); /* ajout d'une suite de test */ pSuite = CU_add_suite("Tests boite noire : Mot", init_suite_success, clean_suite_success); if (NULL == pSuite) { CU_cleanup_registry(); return CU_get_error(); } /* Ajout des tests à la suite de tests boite noire */ if ((//NULL == CU_add_test(pSuite, "MOT_creationMot", test_MOT_creationMot)) //|| (NULL == CU_add_test(pSuite, "MOT_longueur", test_MOT_longueur)) || (NULL == CU_add_test(pSuite, "MOT_iEmeLettre", test_MOT_iEmeLettre)) || (NULL == CU_add_test(pSuite, "MOT_insererCaractere", test_MOT_insererCaractere)) || (NULL == CU_add_test(pSuite, "MOT_supprimerCaractere", test_MOT_supprimerCaractere)) || (NULL == CU_add_test(pSuite, "MOT_echangerCaractere", test_MOT_echangerCaractere)) || (NULL == CU_add_test(pSuite, "MOT_estIdentique", test_MOT_estIdentique)) /*|| (NULL == CU_add_test(pSuite, "MOT_motEnChaine", test_MOT_motEnChaine))*/ ) { CU_cleanup_registry(); return CU_get_error(); } /* Lancement des tests */ CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_tests(); printf("\n"); CU_basic_show_failures(CU_get_failure_list()); printf("\n\n"); /* Nettoyage du registre */ CU_cleanup_registry(); return CU_get_error(); }