コード例 #1
0
ファイル: LISTA.C プロジェクト: lucas-borges/Modular-T4
   LIS_tpCondRet VerificaLista (LIS_tppLista pLista)
   {
	   LIS_tppLista ant = NULL;
	   tpElemLista * aux;
	   int elementosPercorridos = 1 ;
	   printf("verificar lista 1\n");
	   if( pLista == NULL )
	   {
		   return LIS_CondRetOK;
	   }/*if*/

	   aux = pLista->pOrigemLista;
	   printf("verificar lista 2\n");
	   if( aux->pAnt != NULL )
	   {
		   CNT_CONTAR ("LIS_ErroPrimeiro") ;

		    CNT_CONTAR (CONTADOR_FALHAS_ESTRUTURA) ; //algo antes do primeiro elemento
	   }/* if */
	    printf("verificar lista 3\n");
	   do
	   {
		   printf("HAHAHA: %d, %d\n",LIS_TipoEspacoElemento,CED_ObterTipoEspaco(aux));
			if(TST_CompararInt(LIS_TipoEspacoElemento,CED_ObterTipoEspaco(aux),"Tipo de espaço do elemento não é elemento da lista")!=TST_CondRetOK)
			{
				CNT_CONTAR(CONTADOR_FALHAS_ESTRUTURA);
				printf("vai retornar\n");
				return LIS_CondRetErroEstrutura;
			}
			printf("--\n");
		   if(TST_CompararPonteiro(aux->pProx->pAnt,aux,"Erro no ponteiro para proximo")!=TST_CondRetOK)
		   {
			   CNT_CONTAR ("LIS_ErroProximo") ;

			   CNT_CONTAR (CONTADOR_FALHAS_ESTRUTURA) ;
		   }/*if*/

		   aux=aux->pProx ;

		   elementosPercorridos++;

	   } while(aux->pProx!=NULL);
	    printf("verificar lista 4\n");
	   if(elementosPercorridos!=pLista->numElem)
	   {
		   CNT_CONTAR ("LIS_ErroNumElem") ;

		   CNT_CONTAR (CONTADOR_FALHAS_ESTRUTURA) ; //numero de elementos percorridos é diferente do numero da cabeça da lista
	   }/* if */

	    printf("verificar lista 5\n");

	   if(TST_CompararPonteiro(pLista->pFimLista,aux,"Ultimo elemento nao e o esperado.")!=TST_CondRetOK)
	   {
		   CNT_CONTAR ("LIS_ErroUltimo") ;

		   CNT_CONTAR (CONTADOR_FALHAS_ESTRUTURA) ;
	   }/* if */
	   return LIS_CondRetOK;
   }
コード例 #2
0
ファイル: TESTPIL.C プロジェクト: jpaldi91/modular-TRAB2
   TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
   {

      int inxPilha  = -1 ,
		  inxDado	= -1,
          numLidos   = -1 ,
          CondRetEsp = -1  ;

      PIL_tpCondRet CondRet ;

      char   StringDado [ DIM_VALOR ] ;
	  char   vetDado[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'} ;
	  char   teste = '\0' ;

      int ValEsp = -1 ;

      int i ;

      int numElem = -1 ;

	  void *EndObtido = NULL;
	  void *EndEsperado = NULL;

      StringDado[ 0 ] = 0 ;

      /* Efetuar reset de teste de pilha */

         if ( strcmp( ComandoTeste , RESET_PILHA_CMD ) == 0 )
         {

            for( i = 0 ; i < DIM_VT_PILHA ; i++ )
            {
               vtPilhas[ i ] = NULL ;
            } /* for */

            return TST_CondRetOK ;

         } /* fim ativa: Efetuar reset de teste de pilha */

      /* Testar CriarPilha */

         else if ( strcmp( ComandoTeste , CRIAR_PILHA_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ii" ,
				&inxPilha, &CondRetEsp ) ;

            if ( ( numLidos != 2 )
              || ( ! ValidarInxPilha( inxPilha , VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

			CondRet = PIL_CriarPilha( &vtPilhas[ inxPilha ] ) ;

            return TST_CompararInt( CondRetEsp , CondRet ,
               "Erro ao criar pilha."  ) ;

         } /* fim ativa: Testar CriarPilha */

      /* Testar Esvaziar pilha */

         else if ( strcmp( ComandoTeste , ESVAZIAR_PILHA_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ii" ,
                               &inxPilha, &CondRetEsp ) ;

            if ( ( numLidos != 2 )
              || ( ! ValidarInxPilha( inxPilha , NAO_VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararInt( CondRetEsp, PIL_EsvaziarPilha( vtPilhas[ inxPilha ] ),
					"Retorno inesperado." );

         } /* fim ativa: Testar Esvaziar pilha */

      /* Testar Destruir pilha */

         else if ( strcmp( ComandoTeste , DESTRUIR_PILHA_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ii" ,
                               &inxPilha, &CondRetEsp ) ;

            if ( ( numLidos != 2 )
              || ( ! ValidarInxPilha( inxPilha , NAO_VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

			CondRet = PIL_DestruirPilha( vtPilhas[ inxPilha ] ) ;
            vtPilhas[ inxPilha ] = NULL ;

            return TST_CompararInt( CondRetEsp , CondRet , "Retorno inesperado." ) ;

         } /* fim ativa: Testar Destruir pilha */

      /* Testar inserir elemento */

         else if ( strcmp( ComandoTeste , EMPILHAR_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "iii" ,
                       &inxPilha , &inxDado , &CondRetEsp ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxPilha( inxPilha , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

			CondRet = PIL_Empilha( vtPilhas[ inxPilha ], &vetDado[inxDado]);

            return TST_CompararInt( CondRetEsp , CondRet ,
                     "Condicao de retorno errada ao inserir antes."                   ) ;

         } /* fim ativa: Testar inserir elemento */

      /* Testar excluir elemento */

         else if ( strcmp( ComandoTeste , DESEMPILHAR_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ii" ,
                  &inxPilha , &CondRetEsp ) ;

            if ( ( numLidos != 2 )
              || ( ! ValidarInxPilha( inxPilha , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararInt( CondRetEsp ,
                      PIL_Desempilha( vtPilhas[ inxPilha ] ) ,
                     "Condição de retorno errada ao excluir."   ) ;

         } /* fim ativa: Testar excluir elemento */

      /* Testar obter valor do elemento corrente */

         else if ( strcmp( ComandoTeste , OBTER_VALOR_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "iici" ,
                       &inxPilha , &inxDado , &teste , &ValEsp ) ;

            if ( numLidos != 4 )
            {
               return TST_CondRetParm ;
            } /* if */

			CondRet = PIL_ObterValor( vtPilhas[ inxPilha ], &EndObtido );
            
			if ( CondRet != PIL_CondRetOK )
            {
               return TST_CompararInt( ValEsp , CondRet ,
                         "Erro ao obter endereço do elemento." ) ;
            } /* if */

			EndEsperado = &vetDado[inxDado];

			if ( EndEsperado != EndObtido ) 
			{
				return TST_CompararPonteiro( EndEsperado, EndObtido, "Endereço obtido errado." );
			} /*if*/

            return TST_CompararChar( teste , *(char*)EndObtido ,
                         "Valor do elemento errado." ) ;

         } /* fim ativa: Testar obter valor do elemento corrente */

	  return TST_CondRetNaoConhec ;

   } /* Fim função: TPIL &Testar pilha */