int main() { err_t noerr = OK; obj1_t * o1 = NULL ; obj1_t * o2 = NULL ; printf( "Debut du programme des test sur les objets de type obj1_t\n" ) ; printf( "Test d'existance sur un obj1_t inexistant\n" ) ; ( obj1_existe(o1) ? printf("-->KO\n") : printf ("-->OK\n") ) ; printf( "Test creation obj1_t\n" ) ; o1 = obj1_creer() ; printf( "Test affichage o1\n" ) ; obj1_afficher( o1 ) ; printf( "\n"); printf( "Test d'existance sur un obj1_t existant\n" ) ; ( obj1_existe(o1) ? printf("-->OK\n") : printf ("-->KO\n") ) ; printf( "Test copie de: o2 <-- o1\n" ) ; if( ( noerr = obj1_copier( &o2 , o1 ) ) ) { printf("Sortie avec code erreur = %d\n" , noerr ) ; return(noerr) ; } printf( "Test affichage o2\n" ) ; obj1_afficher( o2 ) ; printf( "\n"); printf( "Test destruction o1\n" ) ; if( ( noerr = obj1_detruire( &o1 ) ) ) { printf("Sortie avec code erreur = %d\n" , noerr ) ; return(noerr) ; } printf( "Test destruction o2\n" ) ; if( ( noerr = obj1_detruire( &o2 ) ) ) { printf("Sortie avec code erreur = %d\n" , noerr ) ; return(noerr) ; } printf( "Fin du programme des test sur les objets de type obj1_t\n" ) ; return(0) ; }
extern obj2_t * obj2_creer( const int nb_obj1 ) { obj2_t * obj2 = NULL ; static unsigned long int cpt = 0 ; int i = 0 ; if( ( obj2 = malloc(sizeof(obj2_t)) ) == NULL ) { fprintf( stderr , "obj2_creer: debordement memoire lors de la creation d'un objet de type obj2_t (%lu demandes)\n", (unsigned long int)sizeof(obj2_t) ) ; return((obj2_t *)NULL); } if( ( obj2->liste_objets = obj1s_creer(nb_obj1) ) == NULL ) { fprintf( stderr , "obj2_creer: debordement memoire lors de la creation de la liste des obj1 d'un obj2_t\n" ) ; return((obj2_t *)NULL); } if( ( obj2->attributs = malloc( sizeof(char)*TAILLE ) ) == NULL ) { fprintf( stderr , "obj2_creer: debordement memoire lors de la creation des attributs d'un obj2_t (%lu demandes)\n", (unsigned long int)sizeof(char)*TAILLE ) ; return((obj2_t *)NULL); } /* Initialisation des attributs */ for( i=0 ; i<nb_obj1 ; i++ ) { if( ( obj2->liste_objets->liste[i] = obj1_creer() ) == NULL ) { fprintf( stderr , "obj2_creer: debordement memoire lors de l'initialisation de la liste des obj1 d'un obj2_t\n" ) ; return((obj2_t *)NULL); } } cpt++ ; compteur_obj2++; char w[TAILLE] ; sprintf( w , "[objet2] %lu" , cpt ); strcpy( obj2->attributs , w ); return( obj2 ) ; }
extern err_t obj1_copier( obj1_t ** obj1_cible , obj1_t * const obj1_source ) { if( ! obj1_existe( (*obj1_cible) ) ) { if( ( (*obj1_cible) = obj1_creer() ) == NULL ) { fprintf( stderr , "obj1_copier: debordement memoire lors de la creation d'un objet cible \n " ) ; return(ERR_DEB_MEMOIRE); } } strcpy( (*obj1_cible)->attributs , obj1_source->attributs ) ; return(OK) ; }