コード例 #1
0
int
main()
{
  err_t noerr = OK ; 
  obj2_t * objet = NULL ; 
  obj2s_t * liste = NULL ; 
  obj2s_t * copie_liste = NULL ; 
  int i = 0 ; 
  int taille = 0 ; 
  
  printf( "Debut programme pour colmater les fuites memoire\n"); 
  srand( (unsigned int) getpid() ) ; 

  liste = obj2s_creer(0) ; 

  while(VRAI) 
    {
      taille = rand() % MAX2 ;

      printf( "Creation + copie liste de %d objets obj2_t..." , taille ) ; fflush(stdout ) ; 

      liste = obj2s_creer(taille) ;
      for( i=0 ; i<taille ; i++ ) 
	{
	  objet = obj2_creer(rand()%MAX1) ;
	  if( ( noerr = obj2s_obj2_ecrire( liste, objet , i ) ) )
	    {
	      printf( "Sortie avec code erreur %d\n" , noerr ) ;
	      return(noerr) ; 
	    }
	  obj2_detruire(&objet) ;
	}
 
      if( ( noerr = obj2s_copier( &copie_liste , liste ) ) )
	{
	  printf( "Sortie avec code erreur %d\n" , noerr ) ;
	  return(noerr) ; 
	}
      printf("...OK\n" ) ; 

      if( ( noerr = obj2s_detruire( &liste ) ) )
	{
	  printf( "Sortie avec code erreur %d\n" , noerr ) ;
	  return(noerr) ; 
	}

      if( ( noerr = obj2s_detruire( &copie_liste ) ) )
	{
	  printf( "Sortie avec code erreur %d\n" , noerr ) ;
	  return(noerr) ; 
	}

    }

  printf( "Fin programme de colmatage\n"); 

  return(OK); 
}
コード例 #2
0
ファイル: prog2.c プロジェクト: tp5spi2012/Semestre4
int
main()
{
  err_t noerr = OK ; 
  obj2_t * objet = NULL ; 
  obj2s_t * liste = NULL ; 
  obj2s_t * copie_liste = NULL ; 
  int i = 0 ; 
  int taille = 0 ; 
  int b = 0 ;
  
  printf( "Debut programme pour colmater les fuites memoire\n"); 
  srand( (unsigned int) getpid() ) ; 

  liste = obj2s_creer(0) ; 
      if( ( noerr = obj2s_detruire( &liste ) ) )
	{
	  printf( "Sortie avec code erreur %d\n" , noerr ) ;
	  return(noerr) ; 
	}

  for( b=0 ; b<BOUCLE ; b++ ) 
    {
      taille = rand() % MAX2 ;
      taille = 10;

      printf( "%3d : Creation + copie liste de %6d objets obj2_t..." , b , taille ) ; fflush(stdout ) ; 

      liste = obj2s_creer(taille) ;
      for( i=0 ; i<taille ; i++ ) 
	{
	  objet = obj2_creer(rand()%MAX1) ;
	  if( ( noerr = obj2s_obj2_ecrire( liste, objet , i ) ) )
	    {
	      printf( "Sortie avec code erreur %d\n" , noerr ) ;
	      return(noerr) ; 
	    }
	  obj2_detruire(&objet) ;
	}
 
      if( ( noerr = obj2s_copier( &copie_liste , liste ) ) )
	{
	  printf( "Sortie avec code erreur %d\n" , noerr ) ;
	  return(noerr) ; 
	}
      printf("...OK\n" ) ; 

      /* obj2s_afficher( copie_liste ) ; */

      if( ( noerr = obj2s_detruire( &liste ) ) )
	{
	  printf( "Sortie avec code erreur %d\n" , noerr ) ;
	  return(noerr) ; 
	}

      if( ( noerr = obj2s_detruire( &copie_liste ) ) )
	{
	  printf( "Sortie avec code erreur %d\n" , noerr ) ;
	  return(noerr) ; 
	}
      
    }

  printf( "Fin programme de colmatage\n"); 

	  printf("COMPTEUR delta obj2s : %i\n", count_obj2s);
	  printf("COMPTEUR delta obj2  : %i\n", count_obj2);
	  printf("COMPTEUR delta obj1s : %i\n", count_obj1s);
	  printf("COMPTEUR delta obj1  : %i\n", count_obj1);
  return(OK); 
}
コード例 #3
0
ファイル: test_obj2s.c プロジェクト: Bingo8/Prg-avance
int
main()
{
  err_t noerr = OK ; 
  obj2_t * objet = NULL ; 
  obj2s_t * liste = NULL ; 
  obj2s_t * copie_liste = NULL ; 
  int i = 0 ; 

  printf( "Debut programme de test des listes d'objets obj2_t\n"); 

  printf( "Test existance sur liste inexistante\n");
  ( obj2s_existe( liste )  ? printf("-->KO\n") : printf("-->OK\n") ) ;

  liste = obj2s_creer(0);

  printf( "Test existance sur liste existante\n");
  ( obj2s_existe( liste )  ? printf("-->OK\n") : printf("-->KO\n") ) ;

  printf( "Test vide sur liste vide\n");
  ( obj2s_vide( liste )  ? printf("-->OK\n") : printf("-->KO\n") ) ;

  liste = obj2s_creer(N2) ;
  for( i=0 ; i<N2 ; i++ ) 
    {
      objet = obj2_creer(N1) ;
      if( ( noerr = obj2s_obj2_ecrire( liste, objet , i ) ) )
	{
	  printf( "Sortie avec code erreur %d\n" , noerr ) ;
	  return(noerr) ; 
	}
      obj2_detruire(&objet) ;
    }
  
  printf( "Test vide sur liste vide\n");
  ( obj2s_vide( liste )  ? printf("-->KO\n") : printf("-->OK\n") ) ;

  printf( "Test affichage d'une liste\n");
  obj2s_afficher( liste ) ; 

  printf( "Test copie de la liste\n");
  if( ( noerr = obj2s_copier( &copie_liste , liste ) ) )
    {
      printf( "Sortie avec code erreur %d\n" , noerr ) ;
      return(noerr) ; 
    }

  printf( "Affichage liste copiee\n");
  obj2s_afficher( copie_liste ) ; 

  printf( "Test destruction liste "); fflush(stdout) ; 
  if( ( noerr = obj2s_detruire( &liste ) ) )
    {
      printf( "Sortie avec code erreur %d\n" , noerr ) ;
	  return(noerr) ; 
    }
  printf("-->OK\n" ) ;

  printf( "Test destruction liste copiee"); fflush(stdout) ; 
  if( ( noerr = obj2s_detruire( &copie_liste ) ) )
    {
      printf( "Sortie avec code erreur %d\n" , noerr ) ;
	  return(noerr) ; 
    }
  printf("-->OK\n" ) ; 

  printf( "Fin programme de test des listes d'objets obj2_t\n"); 

  return(OK); 
}