Example #1
0
TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
{

	int numLidos   = -1 , 
		CondRetEsp = -1 ,
		CondRetObt = -1 ;
	/* Inicializa para qualquer coisa */

	
	/* Testar Criar Grafo */
	if( strcmp( ComandoTeste , CRIAR_GRAFO_CMD ) == 0 )
	{
		numLidos = LER_LerParametros ( "i" ,
			 &CondRetEsp ) ;
		
		if ( numLidos != 1 )
		{
			return TST_CondRetParm ;
		}/* if */

		CondRetObt = GRF_CriarGrafo ( &pGrafo , CHR_DestruirCaracter ) ;

		return TST_CompararInt ( CondRetEsp , CondRetObt , 
				"Retorno errado ao criar grafo.") ;

	} /* fim ativa: Testar Criar Grafo */

	/* Testar Destroi Grafo */
	else if ( strcmp( ComandoTeste , DESTROI_GRAFO_CMD ) == 0 )
	{

		numLidos = LER_LerParametros( "i" ,
			&CondRetEsp ) ;

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

		GRF_DestroiGrafo ( pGrafo ) ;
		CondRetObt=GRF_CondRetOK;
		pGrafo = NULL ;

		return TST_CompararInt( CondRetEsp , CondRetObt ,
			"Retorno errado ao destruir o Grafo." );

	} /* fim ativa: Testar Destroi Grafo */

	/* Testar Insere Vertice */
	else if ( strcmp( ComandoTeste , INSERE_VERTICE_CMD ) == 0 )
	{

		CHR_tppCaracter pCaracter ;
		char ValorVertice ;
		int ChaveVertice;
	
		numLidos = LER_LerParametros( "ici" ,
			&ChaveVertice, &ValorVertice , &CondRetEsp ) ;

		if ( numLidos != 3 || ChaveVertice<0 )
		{
			return TST_CondRetParm ;
		} /* if */

		pCaracter = CHR_CriarCaracter ( ValorVertice ) ;

		if ( pCaracter == NULL )
		{
			return TST_CondRetMemoria ;
		}

		CondRetObt = GRF_CriaVertice ( pGrafo , pCaracter, ChaveVertice ) ;

		return TST_CompararInt( CondRetEsp , CondRetObt ,
			"Retorno errado ao criar o vertice." );

	} /* fim ativa: Testar Cria Vertice */

	/* Testar Cria Aresta */
	else if ( strcmp( ComandoTeste , CRIA_ARESTA_CMD ) == 0 )
	{
		int verticeA , verticeB ;
		
		numLidos = LER_LerParametros( "iii" ,
			&verticeA , &verticeB , &CondRetEsp ) ;

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


		CondRetObt = GRF_CriaAresta ( pGrafo, verticeA , verticeB ) ;

		return TST_CompararInt( CondRetEsp , CondRetObt ,
			"Retorno errado ao criar a aresta." );

	} /* fim ativa: Testar Cria Aresta */

	/*Testar Remove Aresta */
	else if ( strcmp( ComandoTeste, REMOVE_ARESTA_CMD) ==0)
	{
		int verticeA , verticeB ;
		
		numLidos = LER_LerParametros( "iii" ,
			&verticeA , &verticeB , &CondRetEsp ) ;

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


		CondRetObt = GRF_RemoveAresta ( pGrafo,verticeA , verticeB) ;

		return TST_CompararInt( CondRetEsp , CondRetObt ,
			"Retorno errado ao remover a aresta." );
	}

	/* fim ativa: Testar Criar Aresta */

	/* Testar Obtem Caminho */
	else if ( strcmp( ComandoTeste , EXISTE_CAMINHO_CMD ) == 0 )
	{
		int verticeOrigem , verticeDestino ;
		

		numLidos = LER_LerParametros( "iii" ,
			&verticeOrigem , &verticeDestino , &CondRetEsp ) ;

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


		CondRetObt=GRF_ObtemCaminho ( pGrafo , verticeOrigem, verticeDestino,NULL) ;
		
		return TST_CompararInt( CondRetEsp , CondRetObt ,
			"Retorno errado ao verificar se existe caminho entre os vertices." );

	} /* fim ativa: Testar Obtem Caminho */

	/* Testar Existe Vertice */
	else if ( strcmp( ComandoTeste , EXISTE_VERTICE_CMD ) == 0 )
	{
		int chaveVertice ;


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

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

		CondRetObt = GRF_ExisteVertice ( pGrafo , chaveVertice  ) ;


		return TST_CompararInt( CondRetEsp , CondRetObt ,
			"Retorno errado ao verificar se existe vertice." );

	} /* fim ativa: Testar Existe Vertice */

	/* Testar Esvazia Grafo */
	else if ( strcmp( ComandoTeste , ESVAZIA_GRAFO_CMD ) == 0 )
	{

		numLidos = LER_LerParametros( "i" ,
			&CondRetEsp ) ;

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

		CondRetObt=GRF_EsvaziaGrafo ( pGrafo ) ;

		return TST_CompararInt( CondRetEsp , CondRetObt ,
			"Retorno errado ao esvaziar o grafo." );

	} /* fim ativa: Testar Esvazia Grafo */

	/* Testar Altera Corrente */
	else if ( strcmp( ComandoTeste, ALTERA_CORR_CMD ) == 0 )
	{
		int vertice;

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

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

		CondRetObt = GRF_AlteraCorrente ( pGrafo, vertice );

		return TST_CompararInt( CondRetEsp, CondRetObt, 
			"Retorno errado ao alterar a corrente" );

	}/* fim ativa: Testar Altera Corrente */

	/* Testar Existe Aresta */
	else if( strcmp( ComandoTeste, EXISTE_ARESTA_CMD ) == 0 )
	{
		int verticeA, verticeB;

		numLidos = LER_LerParametros ( "iii", &verticeA, &verticeB, &CondRetEsp);

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

		CondRetObt = GRF_ExisteAresta ( pGrafo, verticeA, verticeB);

		return TST_CompararInt( CondRetEsp, CondRetObt,
			"Retorno errado na existe aresta");

	}/* fim ativa: Testar Altera Corrente */

	/* Testar Ir Vizinho*/
	else if( strcmp( ComandoTeste, IR_VIZINHO_CMD ) == 0 )
	{
		int vertice;

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

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

		CondRetObt = GRF_IrVizinho ( pGrafo, vertice );

		return TST_CompararInt( CondRetEsp , CondRetObt,
			"Retorno errado ao ir vizinho");

	}/* fim ativa: Testar Ir Vizinho */

	/* Testar Obter Corrente*/
	else if( strcmp(ComandoTeste, OBTER_CORR_CMD ) == 0)
	{
		int verticeEsperado, verticeObtido;
		char valorEsperado;
		void* temp;
		char valorObtido;
		TST_tpCondRet Ret;

		numLidos = LER_LerParametros( "ici", &verticeEsperado, &valorEsperado, &CondRetEsp);

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

		CondRetObt = GRF_ObterCorr ( pGrafo, &verticeObtido, &temp);

		Ret =  TST_CompararInt( CondRetEsp , CondRetObt,
			"Retorno errado ao obter corrente");

		if ( Ret != TST_CondRetOK)
		{
			return Ret;
		}/*if*/

		if ( CondRetEsp != GRF_CondRetOK )
		{
			return TST_CondRetOK;
		}/*if*/

		Ret = TST_CompararInt( verticeEsperado, verticeObtido,
			"Retorno errado ao obter corrente");

		if ( Ret != TST_CondRetOK)
		{
			return Ret;
		}/*if*/

		valorObtido = CHR_ObterValor((CHR_tppCaracter)temp);

		return TST_CompararChar( valorEsperado, valorObtido,
			"Retorno errado ao obter corrente");

	}/* fim ativa: Testar Obter Corrente */

	/* Testar Alterar Valor Corr*/
	else if ( strcmp( ComandoTeste, ALTERA_VALOR_CORR_CMD ) == 0 )
	{
		char valor;
		CHR_tppCaracter pCaracter;

		numLidos = LER_LerParametros( "ci", &valor, &CondRetEsp);

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

		pCaracter = CHR_CriarCaracter (valor);

		CondRetObt = GRF_AlterarValorCorr ( pGrafo, (void*)pCaracter);

		return TST_CompararInt ( CondRetEsp, CondRetObt, 
			"Retorno errado ao alterar valor corrente");

	}/* fim ativa: Testar Alterar Valor Corr */

	/* Testar Caminhar*/
	else if( strcmp( ComandoTeste, CAMINHAR_CMD ) == 0 )
	{
		int vertice;

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

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

		CondRetObt = GRF_Caminhar( pGrafo , vertice );

		return TST_CompararInt( CondRetEsp, CondRetObt,
			"Retorno errado ao caminhar");

	}/* fim ativa: Testar Caminhar */


	return TST_CondRetNaoConhec;

} /* Fim função: TGRF &Testar Grafo */
Example #2
0
   TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
   {

      /* Variáveis para retorno de operações com lista */
	  /* Devem ser inicializadas com qualquer valor */

      LIS_tpCondRet LIS_CondRetObtido   = LIS_CondRetOK ;
      LIS_tpCondRet LIS_CondRetEsperada = LIS_CondRetFaltouMemoria ;
	  
	  int indexFocoLista = '0';

      int  NumLidos = -1 ;
	  
	  int i = 0;
	  int resposta = 0;
	  int numPassos = 0;

	  char * caracter;
	  char stringDado [2] ;				
	  
      TST_tpCondRet Ret = TST_CondRetOK ;

	  stringDado[1]='\0';

	  /* Efetuar reset de teste de lista */

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

			for ( i = 0; i < DIM_VT_LISTA; i++ )
			vtListas[ i ] = NULL;

			return TST_CondRetOK;

	  } /* Fim ativa: Efetuar reset de teste de lista */

	 /* Testar LIS Criar lista */
	 
	  else if ( strcmp( ComandoTeste , CRIAR_LIS_CMD ) == 0 )
      {

			NumLidos = LER_LerParametros( "ii" ,
										  &indexFocoLista,
										  &LIS_CondRetEsperada ) ;

            if ( NumLidos != 2 || !ValidarIndex ( indexFocoLista, DIM_VT_LISTA ) )
            {
               return TST_CondRetParm ;
            } /* if */

			LIS_CondRetObtido = LIS_CriarLista( &vtListas[ indexFocoLista ], DestruirConteudoLista );
			
            return TST_CompararInt( LIS_CondRetEsperada , LIS_CondRetObtido ,
                                    "Retorno errado ao criar lista." );

      } /* Fim ativa: Testar LIS Criar lista */


	 /* Testar LIS Inserir elemento na lista antes do elemento corrente */
	  
	  else if ( strcmp( ComandoTeste , INSERIR_ANTES_CMD ) == 0 )
      {

			NumLidos = LER_LerParametros( "ici" , 
										  &indexFocoLista, 
										  stringDado,
										  &LIS_CondRetEsperada ) ;
            
			if ( NumLidos != 3 || !ValidarIndex ( indexFocoLista, DIM_VT_LISTA ) )
            {
               return TST_CondRetParm ;
            } /* if */

			caracter = ( char * ) malloc( strlen( stringDado ) + 1 ) ;
            if ( caracter == NULL )
            {
               return TST_CondRetMemoria ;
            } /* if */

            strcpy( caracter , stringDado ) ;

			LIS_CondRetObtido = LIS_InserirElementoAntes ( vtListas[ indexFocoLista ], caracter );

            return TST_CompararInt( LIS_CondRetEsperada , LIS_CondRetObtido ,
                                    "Retorno errado ao inserir à esquerda (antes do elemento corrente da lista)." );

         } /* fim ativa: Testar LIS Inserir elemento na lista antes do elemento corrente */


	 /* Testar LIS Inserir elemento na lista depois do elemento corrente */
	  
	  else if ( strcmp( ComandoTeste , INSERIR_APOS_CMD ) == 0 )
      {

            NumLidos = LER_LerParametros( "ici" , 
										  &indexFocoLista, 
										  stringDado,
										  &LIS_CondRetEsperada ) ;

            if ( NumLidos != 3 || !ValidarIndex ( indexFocoLista, DIM_VT_LISTA ) )
            {
               return TST_CondRetParm ;
            } /* if */

			caracter = ( char * ) malloc( strlen( stringDado ) + 1 ) ;
            if ( caracter == NULL )
            {
               return TST_CondRetMemoria ;
            } /* if */

            strcpy( caracter , stringDado ) ;

			LIS_CondRetObtido = LIS_InserirElementoApos ( vtListas[ indexFocoLista ], caracter );
			
            return TST_CompararInt( LIS_CondRetEsperada , LIS_CondRetObtido ,
                                    "Retorno errado ao inserir à direita (após elemento corrente)." );

      } /* fim ativa: Testar LIS Inserir elemento na lista depois do elemento corrente  */


	 /* Testar LIS Ir para elemento inicial (origem da lista) */
      
	  else if ( strcmp( ComandoTeste , IR_INICIOLISTA_CMD ) == 0 )
      {

            NumLidos = LER_LerParametros( "ii" ,
										  &indexFocoLista,
										  &LIS_CondRetEsperada ) ;

            if ( NumLidos != 2 || !ValidarIndex ( indexFocoLista, DIM_VT_LISTA ) )
            {
               return TST_CondRetParm ;
            } /* if */

			LIS_CondRetObtido = LIS_IrInicioLista( vtListas[ indexFocoLista ] ) ;

            return TST_CompararInt( LIS_CondRetEsperada , LIS_CondRetObtido ,
                                    "Retorno errado ao ir para o início da lista." );

      } /* fim ativa: Testar LIS Ir para elemento inicial (origem da lista)  */


	 /* Testar LIS Ir para elemento final (fim da lista) */
     
	  else if ( strcmp( ComandoTeste , IR_FIMLISTA_CMD ) == 0 )
      {

            NumLidos = LER_LerParametros( "ii" ,
										  &indexFocoLista,
										  &LIS_CondRetEsperada ) ;

            if ( NumLidos != 2 || !ValidarIndex ( indexFocoLista, DIM_VT_LISTA ) )
            {
               return TST_CondRetParm ;
            } /* if */
			
			LIS_CondRetObtido = LIS_IrFinalLista( vtListas[ indexFocoLista ] ) ;

            return TST_CompararInt( LIS_CondRetEsperada , LIS_CondRetObtido ,
                                    "Retorno errado ao ir para o fim da lista." );

      } /* fim ativa: Testar LIS Ir para elemento final (fim da lista) */


	 /* Testar LIS Percorre lista */

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

            NumLidos = LER_LerParametros( "iii" ,
										  &indexFocoLista,
										  &numPassos,
										  &LIS_CondRetEsperada ) ;

            if ( NumLidos != 3 || !ValidarIndex ( indexFocoLista, DIM_VT_LISTA ) )
            {
               return TST_CondRetParm ;
            } /* if */

			LIS_CondRetObtido = LIS_PercorreLista( vtListas[ indexFocoLista ], numPassos ) ;

            return TST_CompararInt( LIS_CondRetEsperada , LIS_CondRetObtido ,
                                    "Retorno errado ao percorrer a lista." );

      } /* fim ativa: Testar LIS Percorre lista */


	 /* Testar LIS Obter elementos existentes na lista */

	  else if ( strcmp ( ComandoTeste, OBTER_NUMELEMLISTA_CMD ) == 0 )
	  {
			NumLidos = LER_LerParametros ( "ii", 
											&indexFocoLista,
											&LIS_CondRetEsperada ) ;

			if ( NumLidos != 2 || !ValidarIndex ( indexFocoLista, DIM_VT_LISTA ) )
			{
				 return TST_CondRetParm;
			}

			LIS_CondRetObtido = LIS_ObterNumeroElementos ( vtListas[ indexFocoLista ], &resposta );

			if ( LIS_CondRetObtido == LIS_CondRetOK )
			{
				 printf ( "\nNumero de elementos na lista: %d\n", resposta );
			}

			return TST_CompararInt( LIS_CondRetEsperada , LIS_CondRetObtido ,
                                    "Retorno errado ao requisitar número de elementos de lista." );
	  
	  } /* fim ativa: Testar LIS Obter elementos existentes na lista */


	 /* Testar LIS Excluir elemento corrente da lista */

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

			 NumLidos = LER_LerParametros ( "ii",
											&indexFocoLista,
											&LIS_CondRetEsperada );

			 if ( NumLidos != 2 || !ValidarIndex ( indexFocoLista, DIM_VT_LISTA ))
			 {
				 return TST_CondRetParm;
			 }
			 
			 LIS_CondRetObtido = LIS_ExcluirElementoCorrente ( vtListas[ indexFocoLista ] );

			 return TST_CompararInt( LIS_CondRetEsperada , LIS_CondRetObtido ,
                                    "Retorno errado ao excluir elemento corrente da lista." );

	  } /* fim ativa: Testar LIS Excluir elemento corrente da lista */


	 /* Testar LIS Procurar valor nos elementos da lista */

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

			 NumLidos = LER_LerParametros ( "ici",
											&indexFocoLista,
											stringDado,
											&LIS_CondRetEsperada );

			 if ( NumLidos != 3 || !ValidarIndex ( indexFocoLista, DIM_VT_LISTA ))
			 {
				 return TST_CondRetParm;
			 }

			 LIS_CondRetObtido = LIS_ProcurarValor ( vtListas[ indexFocoLista ], (void**)&stringDado, ComparaConteudo );

			 return TST_CompararInt( LIS_CondRetEsperada , LIS_CondRetObtido ,
                                    "Retorno errado ao procurar elemento da lista." );

	  } /* fim ativa: Testar LIS Procurar valor nos elementos da lista */


	 /* Testar LIS Obter valor armazenado no elemento corrente */

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

            NumLidos = LER_LerParametros( "ici" ,
										  &indexFocoLista,
										  stringDado,
										  &LIS_CondRetEsperada );
			
            if ( NumLidos != 3 || !ValidarIndex( indexFocoLista, DIM_VT_LISTA ) )
            {
               return TST_CondRetParm ;
            } /* if */

            LIS_CondRetObtido = LIS_ObterValorCorrente ( vtListas[ indexFocoLista ], (void**)&caracter ) ;
			
            if ( LIS_CondRetObtido == LIS_CondRetOK )
			{
				printf ("\nCaracter obtido: %c \n", *caracter );
				return TST_CompararChar( stringDado[0], *caracter, "Caracteres diferentes" );
			}
			else
			{
				return TST_CompararInt( LIS_CondRetEsperada, LIS_CondRetObtido, "Retorno errado para obter elemento do elemento corrente da lista." );
			}
			
      } /* fim ativa: Testar LIS Obter valor armazenado no elemento corrente */


	  /* Testar LIS Esvaziar lista */

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

			NumLidos = LER_LerParametros ( "ii", 
										   &indexFocoLista,
										   &LIS_CondRetEsperada );

			if (NumLidos != 2 || !ValidarIndex ( indexFocoLista, DIM_VT_LISTA ) )
			{
				return TST_CondRetParm;
			}

			LIS_CondRetObtido = LIS_EsvaziarLista ( vtListas[ indexFocoLista ] ) ;
			
			return TST_CompararInt ( LIS_CondRetEsperada, LIS_CondRetObtido, "Retorno de erro ao esvaziar lista." );

      } /* fim ativa: Testar LIS Esvaziar lista */


	 /* Testar LIS Destruir lista */

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

			NumLidos = LER_LerParametros ( "ii", 
										   &indexFocoLista,
										   &LIS_CondRetEsperada );
			if ( NumLidos != 2 || !ValidarIndex ( indexFocoLista, DIM_VT_LISTA ) )
			{
				return TST_CondRetParm;
			}

			LIS_CondRetObtido = LIS_DestruirLista( &vtListas[ indexFocoLista ] ) ;

            return TST_CompararInt( LIS_CondRetEsperada , LIS_CondRetObtido ,
                                   "Retorno errado ao destruir lista." );

      } /* fim ativa: Testar LIS Destruir lista */

      return TST_CondRetNaoConhec ;

   } /* Fim função: TLIS Efetuar operações de teste específicas para lista de caracteres */
Example #3
0
   TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
   {

      int inxTabela  = -1 ,
          idTipo     = -1 ,
          numLidos   = -1 ,
          CondRetEsp = -1  ;

      TST_tpCondRet CondRet ;

      char StringDado[  DIM_SIMB ] ;
      char StringValor[ DIM_SIMB ] ;

      int i ;

      int tamTabela = -1 ;

      int ValInt = -1 ;

      tpTipo1 * pDado1 ;

      char ValChar = '\0' ;

      tpTipo2 * pDado2 ;

      tpTipo3 * pDado3 ;

      int ValIntEsp = -1 ;

      char ValCharEsp = '*' ;

      StringDado[ 0 ] = 0 ;

      /* Efetuar reset de teste de tabela */

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

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

            return TST_CondRetOK ;

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

      /* Testar CriarTabela */

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

            numLidos = LER_LerParametros( "iii" ,
                       &inxTabela , &tamTabela , &idTipo ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxTabela( inxTabela , VAZIO ))
              || ( ! ValidarIdTipo( idTipo ))
              || ( tamTabela <= 1 ))
            {
               return TST_CondRetParm ;
            } /* if */

            if ( idTipo == ID_TIPO_1 )
            {
               vtTabelas[ inxTabela ] =
                    TBS_CriarTabela( tamTabela , ObterSimboloTipoUm , NULL ) ;
            } else if ( idTipo == ID_TIPO_2 )
            {
               vtTabelas[ inxTabela ] =
                    TBS_CriarTabela( tamTabela , ObterSimboloTipoDois , NULL ) ;
            } else
            {
               vtTabelas[ inxTabela ] =
                    TBS_CriarTabela( tamTabela , ObterSimboloTipoTres ,
                                                 LiberarDadoTipoTres    ) ;
            } /* if */

            return TST_CompararPonteiroNulo( 1 , vtTabelas[ inxTabela ] ,
               "Erro em ponteiro de nova tabela."  ) ;

         } /* fim ativa: Testar CriarTabela */

      /* Testar Destruir tabela */

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

            numLidos = LER_LerParametros( "i" ,
                               &inxTabela ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxTabela( inxTabela , NAO_VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            TBS_DestruirTabela( vtTabelas[ inxTabela ] ) ;
            vtTabelas[ inxTabela ] = NULL ;

            return TST_CondRetOK ;

         } /* fim ativa: Testar Destruir tabela */

      /* Testar Inserir simbolo tipo um */

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

            numLidos = LER_LerParametros( "iisi" ,
                       &inxTabela , &ValInt , StringDado , &CondRetEsp ) ;

            if ( ( numLidos != 4 )
              || ( ! ValidarInxTabela( inxTabela , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            pDado1 = ( tpTipo1 * ) malloc( sizeof( tpTipo1 )) ;
            if ( pDado1 == NULL )
            {
               return TST_CondRetMemoria ;
            } /* if */

            pDado1->Conta   = ValInt ;
            strcpy( pDado1->SimboloUm , StringDado ) ;


            CondRet = (TST_tpCondRet) TBS_InserirSimbolo( vtTabelas[ inxTabela ] , pDado1 ) ;

            if ( CondRet != TBS_CondRetOK )
            {
               free( pDado1 ) ;
            } /* if */

            return TST_CompararInt( CondRetEsp , CondRet ,
                     "Condição de retorno errada em símbolo tipo um."                   ) ;

         } /* fim ativa: Testar Inserir simbolo tipo um */

      /* Testar Inserir simbolo tipo dois */

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

            numLidos = LER_LerParametros( "icsi" ,
                       &inxTabela , &ValChar , StringDado , &CondRetEsp ) ;

            if ( ( numLidos != 4 )
              || ( ! ValidarInxTabela( inxTabela , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            pDado2 = ( tpTipo2 * ) malloc( sizeof( tpTipo2 )) ;
            if ( pDado2 == NULL )
            {
               return TST_CondRetMemoria ;
            } /* if */
            pDado2->Id   = ValChar ;
            strcpy( pDado2->SimboloDois , StringDado ) ;

            return TST_CompararInt( CondRetEsp ,
                          TBS_InserirSimbolo( vtTabelas[ inxTabela ] , pDado2 ) ,
                     "Condição de retorno errada em símbolo tipo dois."                   ) ;

         } /* fim ativa: Testar Inserir simbolo tipo dois */

      /* Testar Inserir simbolo tipo tres */

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

            numLidos = LER_LerParametros( "issi" ,
                       &inxTabela , StringDado , StringValor , &CondRetEsp ) ;

            if ( ( numLidos != 4 )
              || ( ! ValidarInxTabela( inxTabela , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            pDado3 = ( tpTipo3 * ) malloc( sizeof( tpTipo3 )) ;
            if ( pDado3 == NULL )
            {
               return TST_CondRetMemoria ;
            } /* if */

            pDado3->pString = (char*) malloc( strlen( StringValor ) + 1 ) ;
            strcpy( pDado3->pString , StringValor ) ;

            strcpy( pDado3->SimboloTres , StringDado ) ;

            return TST_CompararInt( CondRetEsp ,
                          TBS_InserirSimbolo( vtTabelas[ inxTabela ] , pDado3 ) ,
                     "Condição de retorno errada em símbolo tipo dois."                   ) ;

         } /* fim ativa: Testar Inserir simbolo tipo tres */

      /* Testar excluir simbolo */

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

            numLidos = LER_LerParametros( (char*)  "isi" ,
                  (char*) &inxTabela , (char*) StringDado , (char*) &CondRetEsp ) ;

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

            return TST_CompararInt( CondRetEsp ,
                      TBS_ExcluirSimbolo( vtTabelas[ inxTabela ] , StringDado ) ,
                     "Condição de retorno errada ao excluir."                   ) ;

         } /* fim ativa: Testar excluir simbolo */

      /* Testar procurar símbolo tipo 1 */

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

            numLidos = LER_LerParametros( "isi" ,
                       &inxTabela , StringDado , &ValIntEsp ) ;

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

            pDado1 = ( tpTipo1 * ) TBS_ProcurarSimbolo( vtTabelas[ inxTabela ] ,
                                            StringDado ) ;
            if ( ValIntEsp == -1 )
            {
               return TST_CompararPonteiroNulo( 0 , pDado1 ,
                         "Dado tipo um não deveria existir." ) ;
            } /* if */

            if ( pDado1 == NULL )
            {
               return TST_CompararPonteiroNulo( 1 , pDado1 ,
                         "Dado tipo um deveria existir." ) ;
            } /* if */

            return TST_CompararInt( ValIntEsp , pDado1->Conta ,
                         "Valor tipo um errado." ) ;

         } /* fim ativa: Testar procurar símbolo tipo 1 */

      /* Testar procurar símbolo tipo 2 */

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

            numLidos = LER_LerParametros( "isc" ,
                       &inxTabela , StringDado , &ValCharEsp ) ;

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

            pDado2 = ( tpTipo2 * ) TBS_ProcurarSimbolo( vtTabelas[ inxTabela ] ,
                                            StringDado ) ;
            if ( ValCharEsp == '*' )
            {
               return TST_CompararPonteiroNulo( 0 , pDado2 ,
                         "Dado tipo dois não deveria existir." ) ;
            } /* if */

            if ( pDado2 == NULL )
            {
               return TST_CompararPonteiroNulo( 1 , pDado2 ,
                         "Dado tipo dois deveria existir." ) ;
            } /* if */

            return TST_CompararChar( ValCharEsp , pDado2->Id ,
                         "Valor tipo dois errado." ) ;

         } /* fim ativa: Testar procurar símbolo tipo 2 */

      /* Testar procurar símbolo tipo 3 */

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

            numLidos = LER_LerParametros( "iss" ,
                       &inxTabela , StringDado , StringValor ) ;

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

            pDado3 = ( tpTipo3 * ) TBS_ProcurarSimbolo( vtTabelas[ inxTabela ] ,
                                            StringDado ) ;

            if ( pDado3 == NULL )
            {
               return TST_CompararPonteiroNulo( 1 , pDado3 ,
                         "Dado tipo três deveria existir." ) ;
            } /* if */

            return TST_CompararString( StringValor , pDado3->pString ,
                         "Valor tipo três errado." ) ;

         } /* fim ativa: Testar procurar símbolo tipo 3 */

      /* Testar validar Tabela de símbolos */
      #ifdef _DEBUG

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

            numLidos = LER_LerParametros( "i" ,
                               &inxTabela ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxTabela( inxTabela , NAO_VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            return TBS_ValidarTabela( vtTabelas[ inxTabela ] ) ;

         } /* fim ativa: Testar validar Tabela de símbolos */
      #endif

      return TST_CondRetNaoConhec ;

   } /* Fim função: TTBS &Testar tabela de símbolos */
Example #4
0
   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 */
Example #5
0
   TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
   {

      int  NumLidos      = -1 ;

      int IntEsperado,
          IntObtido ;

      char CharEsperado,
           CharObtido ;

      long LongEsperado,
           LongObtido ;

      double FloatEsperado ,
             FloatObtido   ,
             Tolerancia     ;

      char StringEsperado[ 250 ] ,
           StringObtido[   250 ] ;

      char EspacEsperado[ 100 ] ;
      char EspacObtido[   100 ] ;

      /* Testar Booleano */

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

            NumLidos = LER_LerParametros( "ii" ,
                               &IntEsperado , &IntObtido ) ;
            if ( NumLidos != 2 )
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararBool( IntEsperado , IntObtido ,
                                     "Booleanos não são iguais." ) ;

         } /* fim ativa: Testar Booleano */

      /* Testar caractere */

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

            NumLidos = LER_LerParametros( "cc" ,
                               &CharEsperado , &CharObtido ) ;
            if ( NumLidos != 2 )
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararChar( CharEsperado , CharObtido ,
                                     "Caracteres não são iguais." ) ;

         } /* fim ativa: Testar caractere */

      /* Testar inteiro normal */

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

            NumLidos = LER_LerParametros( "ii" ,
                               &IntEsperado , &IntObtido ) ;
            if ( NumLidos != 2 )
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararInt( IntEsperado , IntObtido ,
                                    "Inteiros não são iguais." ) ;

         } /* fim ativa: Testar inteiro normal */

      /* Testar inteiro longo */

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

            NumLidos = LER_LerParametros( "ii" ,
                               &LongEsperado , &LongObtido ) ;
            if ( NumLidos != 2 )
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararInt( LongEsperado , LongObtido ,
                                    "Inteiros longos não são iguais." ) ;

         } /* fim ativa: Testar inteiro longo */

      /* Testar flutuante */

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

            NumLidos = LER_LerParametros( "fff" ,
                               &FloatEsperado , &FloatObtido , &Tolerancia ) ;
            if ( NumLidos != 3 )
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararFloat( FloatEsperado , FloatObtido , Tolerancia ,
                                      "Flutuantes fora da tolerância." ) ;

         } /* fim ativa: Testar flutuante */

      /* Testar string */

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

            NumLidos = LER_LerParametros( "ss" ,
                               StringEsperado , StringObtido ) ;
            if ( NumLidos != 2 )
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararString( StringEsperado , StringObtido ,
                                       "Strings não são iguais." ) ;

         } /* fim ativa: Testar string */

      /* Testar acesso a espaços */

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

            NumLidos = LER_LerParametros( "ss" ,
                               EspacEsperado , EspacObtido ) ;
            if ( NumLidos != 2 )
            {
               return TST_CondRetParm ;
            } /* if */

            if ( EspacEsperado[ 0 ] == '.' )   /* gera string vazio */
            {
               EspacEsperado[ 0 ] = 0 ;
            } /* if */

            if ( EspacObtido[ 0 ] == '.' )     /* gera string com algum lixo */
            {
               memcpy( EspacObtido , &NumLidos , 20 ) ; /* força espaco errado contendo resíduo da pilha */
            } /* if */

            return TST_CompararEspaco( EspacEsperado , EspacObtido ,
                                       strlen( EspacEsperado ) ,
                                       "Espaços não são iguais." ) ;

         } /* fim ativa: Testar acesso a espaços */

      return TST_CondRetNaoConhec ;

   } /* Fim função: TGEN &Testar módulo TesteGen */
   TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
   {

      /* Variáveis para retorno de operações com lista */
	  /* Devem ser inicializadas com qualquer valor */

	  LBT_tpCondRet LBT_CondRetObtido   = LBT_CondRetOK ;
      LBT_tpCondRet LBT_CondRetEsperada = LBT_CondRetFaltouMemoria ;

	  int indexFocoLista = '0';
	  int indexFocoGrafo = '0';
	  int indexFocoLabirinto = '0';

	  int afastamentoHorizontal = 0;
	  int afastamentoVertical = 0;

      int  NumLidos = -1 ;
	  
	  int i = 0;
	  int resposta = 0;
	  int quantidade = 0;
	  int numPassos = 0;
	  int real = 0;
	  LBT_tpSentido sentido;

	  char filePath[200];

	  int vertice = 0;
	  int aresta = 0;

	  char * caracter;
	  char stringDado [2] ;				
	  
      TST_tpCondRet Ret = TST_CondRetOK ;

	  stringDado[1]='\0';

	  caracter = (char*) malloc ( sizeof(char) );

	   /* Efetuar reset de teste de labirinto */

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

			for ( i = 0; i < DIM_VT_LABIRINTO; i++ )
			{
				vtLabirintos[ i ] = NULL;
			}

			return TST_CondRetOK;

	  } /* Fim ativa: Efetuar reset de teste de labirinto */


	  /* Testar LBT Criar Labirinto */

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

		  NumLidos = LER_LerParametros( "ii" ,
										  &indexFocoLabirinto,
										  &LBT_CondRetEsperada ) ;

          if ( NumLidos != 2 || !ValidarIndex ( indexFocoLabirinto, DIM_VT_LABIRINTO ) )
          {
			return TST_CondRetParm ;
          } /* if */
		  
		  LBT_CondRetObtido = LBT_CriarLabirinto( &vtLabirintos[ indexFocoLabirinto ] );

          return TST_CompararInt( LBT_CondRetEsperada , LBT_CondRetObtido ,
                                    "Retorno errado ao criar labirinto." );

	  } /* Fim ativa: Testar LBT Criar Labirinto */

	  /* Testar LBT Destruir Labirinto */

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

		  NumLidos = LER_LerParametros( "ii" ,
										  &indexFocoLabirinto,
										  &LBT_CondRetEsperada ) ;

          if ( NumLidos != 2 || !ValidarIndex ( indexFocoLabirinto, DIM_VT_LABIRINTO ) )
          {
			return TST_CondRetParm ;
          } /* if */
		  
		  LBT_CondRetObtido = LBT_DestruirLabirinto( &vtLabirintos[ indexFocoLabirinto ] );

          return TST_CompararInt( LBT_CondRetEsperada , LBT_CondRetObtido ,
                                    "Retorno errado ao destruir labirinto." );

	  } /* Fim ativa: Testar LBT Destruir Labirinto */

	  /* Testar LBT Construir Labirinto */

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

		  NumLidos = LER_LerParametros( "iii" ,
								         &indexFocoLabirinto,
										 &sentido,
										 &LBT_CondRetEsperada ) ;

          if ( NumLidos != 3 || !ValidarIndex ( indexFocoLabirinto, DIM_VT_LABIRINTO ) )
          {
			return TST_CondRetParm ;
          } /* if */
		  
		  LBT_CondRetObtido = LBT_ConstruirLabirinto( vtLabirintos[ indexFocoLabirinto ], sentido );

          return TST_CompararInt( LBT_CondRetEsperada , LBT_CondRetObtido ,
                                    "Retorno errado ao construir labirinto." );

	  } /* Fim ativa: Testar LBT Construir Labirinto */

	  /* Testar LBT Desenhar Labirinto */

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

		  NumLidos = LER_LerParametros( "iiii" ,
										 &indexFocoLabirinto,
										 &numPassos,
										 &resposta,
										 &LBT_CondRetEsperada ) ;

          if ( NumLidos != 4 || !ValidarIndex ( indexFocoLabirinto, DIM_VT_LABIRINTO ) )
          {
			return TST_CondRetParm ;
          } /* if */
		  
		  printf("\n\n");

		  LBT_CondRetObtido = LBT_DesenharLabirinto( vtLabirintos[ indexFocoLabirinto ], numPassos, resposta );

          return TST_CompararInt( LBT_CondRetEsperada , LBT_CondRetObtido ,
                                    "Retorno errado ao desenhar labirinto." );

	  } /* Fim ativa: Testar LBT Desenhar Labirinto */

	  /* Testar LBT Percorrer Labirinto */

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

		  NumLidos = LER_LerParametros( "iii" ,
										 &indexFocoLabirinto,
										 &sentido,
										 &LBT_CondRetEsperada ) ;

          if ( NumLidos != 3 || !ValidarIndex ( indexFocoLabirinto, DIM_VT_LABIRINTO ) )
          {
			return TST_CondRetParm ;
          } /* if */
		  
		  LBT_CondRetObtido = LBT_PercorrerLabirinto( vtLabirintos[ indexFocoLabirinto ], sentido );

          return TST_CompararInt( LBT_CondRetEsperada , LBT_CondRetObtido ,
                                    "Retorno errado ao percorrer labirinto no sentido." );

	  } /* Fim ativa: Testar LBT Percorrer Labirinto */

	  /* Testar LBT Terminar Labirinto */

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

		  NumLidos = LER_LerParametros( "ii" ,
										 &indexFocoLabirinto,
										 &LBT_CondRetEsperada ) ;

          if ( NumLidos != 2 || !ValidarIndex ( indexFocoLabirinto, DIM_VT_LABIRINTO ) )
          {
			return TST_CondRetParm ;
          } /* if */
		  
		  LBT_CondRetObtido = LBT_TerminarLabirinto( vtLabirintos[ indexFocoLabirinto ] );

          return TST_CompararInt( LBT_CondRetEsperada , LBT_CondRetObtido ,
                                    "Retorno errado ao marcar posicao corrente como posicao de saída do labirinto." );

	  } /* Fim ativa: Testar LBT Terminar Labirinto */

	  /* Testar LBT Iniciar Labirinto */

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

		  NumLidos = LER_LerParametros( "ii" ,
										 &indexFocoLabirinto,
										 &LBT_CondRetEsperada ) ;

          if ( NumLidos != 2 || !ValidarIndex ( indexFocoLabirinto, DIM_VT_LABIRINTO ) )
          {
			return TST_CondRetParm ;
          } /* if */
		  
		  LBT_CondRetObtido = LBT_IniciarLabirinto( vtLabirintos[ indexFocoLabirinto ] );

          return TST_CompararInt( LBT_CondRetEsperada , LBT_CondRetObtido ,
                                    "Retorno errado ao marcar posicao corrente como posicao de entrada do labirinto." );

	  } /* Fim ativa: Testar LBT Iniciar Labirinto */

	  /* Testar LBT Excluir Corrente */

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

		  NumLidos = LER_LerParametros( "ii" ,
										 &indexFocoLabirinto,
										 &LBT_CondRetEsperada ) ;

          if ( NumLidos != 2 || !ValidarIndex ( indexFocoLabirinto, DIM_VT_LABIRINTO ) )
          {
			return TST_CondRetParm ;
          } /* if */
		  
		  LBT_CondRetObtido = LBT_ExcluirCorrente( vtLabirintos[ indexFocoLabirinto ] );

          return TST_CompararInt( LBT_CondRetEsperada , LBT_CondRetObtido ,
                                    "Retorno errado ao excluir posicao corrente do labirinto." );

	  } /* Fim ativa: Testar LBT Excluir Corrente */

	  /* Testar LBT Validar Labirinto */

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

		  NumLidos = LER_LerParametros( "ii" ,
										 &indexFocoLabirinto,
										 &LBT_CondRetEsperada ) ;

          if ( NumLidos != 2 || !ValidarIndex ( indexFocoLabirinto, DIM_VT_LABIRINTO ) )
          {
			return TST_CondRetParm ;
          } /* if */

		  LBT_CondRetObtido = LBT_ValidarLabirinto( vtLabirintos[ indexFocoLabirinto ] );

          return TST_CompararInt( LBT_CondRetEsperada , LBT_CondRetObtido ,
                                    "Retorno errado ao validar labirinto." );

	  } /* Fim ativa: Testar LBT Validar Labirinto */

	  /* Testar LBT Salvar Labirinto */

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

		  NumLidos = LER_LerParametros( "isi" ,
										 &indexFocoLabirinto,
										 filePath,
										 &LBT_CondRetEsperada ) ;

          if ( NumLidos != 3 || !ValidarIndex ( indexFocoLabirinto, DIM_VT_LABIRINTO ) )
          {
			return TST_CondRetParm ;
          } /* if */
		  
		  LBT_CondRetObtido = LBT_SalvarLabirinto( vtLabirintos[ indexFocoLabirinto ], filePath );

          return TST_CompararInt( LBT_CondRetEsperada , LBT_CondRetObtido ,
                                    "Retorno errado ao salvar labirinto." );

	  } /* Fim ativa: Testar LBT Salvar Labirinto */

	  /* Testar LBT Carregar Labirinto */

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

		  NumLidos = LER_LerParametros( "isi" ,
										 &indexFocoLabirinto,
										 filePath,
										 &LBT_CondRetEsperada ) ;

          if ( NumLidos != 3 || !ValidarIndex ( indexFocoLabirinto, DIM_VT_LABIRINTO ) )
          {
			return TST_CondRetParm ;
          } /* if */
		  
		  LBT_CondRetObtido = LBT_CarregarLabirinto( vtLabirintos[ indexFocoLabirinto ], filePath );

          return TST_CompararInt( LBT_CondRetEsperada , LBT_CondRetObtido ,
                                    "Retorno errado ao carregar labirinto." );

	  } /* Fim ativa: Testar LBT Carregar Labirinto */

	  /* Testar LBT Ir Entrada Labirinto */

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

		  NumLidos = LER_LerParametros( "ii" ,
										 &indexFocoLabirinto,
										 &LBT_CondRetEsperada ) ;

          if ( NumLidos != 2 || !ValidarIndex ( indexFocoLabirinto, DIM_VT_LABIRINTO ) )
          {
			return TST_CondRetParm ;
          } /* if */

		  LBT_CondRetObtido = LBT_IrEntradaLabirinto( vtLabirintos[ indexFocoLabirinto ] );

          return TST_CompararInt( LBT_CondRetEsperada , LBT_CondRetObtido ,
                                    "Retorno errado ao ir para a posicao de entrada do labirinto." );

	  } /* Fim ativa: Testar LBT Ir Entrada Labirinto */

	  /* Testar LBT Obter Valor Corrente */

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

		    NumLidos = LER_LerParametros( "ici" ,
										   &indexFocoLabirinto,
										   caracter,
										   &LBT_CondRetEsperada );
			
            if ( NumLidos != 3 || !ValidarIndex( indexFocoGrafo, DIM_VT_GRAFO ) )
            {
               return TST_CondRetParm ;
            } /* if */

			LBT_CondRetObtido = LBT_ObterValorCorrente( vtLabirintos[ indexFocoLabirinto ], (char*)&stringDado[0] );

			if( LBT_CondRetObtido == LBT_CondRetOK && LBT_CondRetObtido == LBT_CondRetEsperada  )
			{
				return TST_CompararChar( *caracter, stringDado[0], "Valor obtido diferente do valor esperado na posicao corrente do labirinto. " );
			}

			return TST_CompararInt( LBT_CondRetEsperada, LBT_CondRetObtido, "Retorno errado ao obter valor da posicao corrente do labirinto. " );

	  } /* fim da ativa: Testar Obter Valor Corrente */

	  /* Testar LBT Obter Entrada */

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

		    NumLidos = LER_LerParametros( "iii" ,
										   &indexFocoLabirinto,
										   &resposta,
										   &LBT_CondRetEsperada );
			
            if ( NumLidos != 3 || !ValidarIndex( indexFocoGrafo, DIM_VT_GRAFO ) )
            {
               return TST_CondRetParm ;
            } /* if */

			LBT_CondRetObtido = LBT_ObterEntrada( vtLabirintos[ indexFocoLabirinto ], &real );

			if( LBT_CondRetObtido == LBT_CondRetOK && LBT_CondRetObtido == LBT_CondRetEsperada )
			{
				return TST_CompararInt( resposta, real, "Valor obtido diferente do valor esperado da posicao de entrada do labirinto" );
			}

			return TST_CompararInt( LBT_CondRetEsperada, LBT_CondRetObtido, " Retorno errado ao obter entrada do labirinto. " );

	  } /* fim da ativa: Testar LBT	Obter Entrada */

	  /* Testar LBT Obter Saida */

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

		    NumLidos = LER_LerParametros( "iii" ,
										   &indexFocoLabirinto,
										   &resposta,
										   &LBT_CondRetEsperada );
			
            if ( NumLidos != 3 || !ValidarIndex( indexFocoGrafo, DIM_VT_GRAFO ) )
            {
               return TST_CondRetParm ;
            } /* if */

			LBT_CondRetObtido = LBT_ObterSaida( vtLabirintos[ indexFocoLabirinto ], &real );

			if( LBT_CondRetObtido == LBT_CondRetOK && LBT_CondRetObtido == LBT_CondRetEsperada )
			{
				return TST_CompararInt( resposta, real, "Valor obtido diferente do valor esperado da posicao de entrada do labirinto" );
			}

			return TST_CompararInt( LBT_CondRetEsperada, LBT_CondRetObtido, "Retorno errado ao obter saida do labirinto. " );

	  } /* fim da ativa: Testar LBT Obter Saida */

	   /* Testar LBT Obter Posicao Corrente */

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

		    NumLidos = LER_LerParametros( "iii" ,
										   &indexFocoLabirinto,
										   &resposta,
										   &LBT_CondRetEsperada );
			
            if ( NumLidos != 3 || !ValidarIndex( indexFocoGrafo, DIM_VT_GRAFO ) )
            {
               return TST_CondRetParm ;
            } /* if */

			LBT_CondRetObtido = LBT_ObterPosicaoCorrente( vtLabirintos[ indexFocoLabirinto ], &real );

			if( LBT_CondRetObtido == LBT_CondRetOK && LBT_CondRetObtido == LBT_CondRetEsperada )
			{
				return TST_CompararInt( resposta, real, "Valor obtido diferente do valor esperado da posicao corrente do labirinto" );
			}

			return TST_CompararInt( LBT_CondRetEsperada, LBT_CondRetObtido, "Retorno errado ao obter posicao corrente do labirinto. " );

	  } /* fim da ativa: Testar Obter Posicao Corrente */

	   /* Testar LBT Obter Solucao */

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

		    NumLidos = LER_LerParametros( "iii" ,
										   &indexFocoLabirinto,
										   &indexFocoLista,
										   &LBT_CondRetEsperada );
			
            if ( NumLidos != 3 || !ValidarIndex( indexFocoGrafo, DIM_VT_GRAFO ) )
            {
               return TST_CondRetParm ;
            } /* if */

			LBT_CondRetObtido = LBT_ObterSolucao( vtLabirintos[ indexFocoLabirinto ], &vtListas [ indexFocoLista ] );

			return TST_CompararInt( LBT_CondRetEsperada, LBT_CondRetObtido, "Retorno errado ao obter lista de solucao do labirinto. " );

	  } /* fim da ativa: Testar LBT Obter Solucao */

	   /* Testar LBT Obter afastamento da Entrada à Saída do Labirinto */

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

		    NumLidos = LER_LerParametros( "iiii" ,
										   &indexFocoLabirinto,
										   &resposta,
										   &numPassos,
										   &LBT_CondRetEsperada );
			
            if ( NumLidos != 4 || !ValidarIndex( indexFocoGrafo, DIM_VT_GRAFO ) )
            {
               return TST_CondRetParm ;
            } /* if */

			LBT_CondRetObtido = LBT_ObterAfastamentoEntradaSaida( vtLabirintos[ indexFocoLabirinto ], &real, &quantidade );

			if( LBT_CondRetObtido == LBT_CondRetOK && LBT_CondRetObtido == LBT_CondRetEsperada )
			{
				if( TST_CompararInt( resposta, real, "Valor obtido diferente do valor esperado para o afastamento horizontal do labirinto." ) != TST_CondRetErro )
				{
					return TST_CompararInt( numPassos, quantidade, "Valor obtido diferente do valor esperado para o afastamento vertical do labirinto." );
				}
			}

			return TST_CompararInt( LBT_CondRetEsperada, LBT_CondRetObtido, "Retorno errado ao obter afastamentos horizontal e vertical do labirinto. " );

	  } /* fim da ativa: Testar LBT Obter afastamento da Entrada à Saída do Labirinto */

	   /* Testar LBT Solucionar Labirinto */

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

		    NumLidos = LER_LerParametros( "iii" ,
										   &indexFocoLabirinto,
										   &numPassos,
										   &LBT_CondRetEsperada );
			
            if ( NumLidos != 3 || !ValidarIndex( indexFocoGrafo, DIM_VT_GRAFO ) )
            {
               return TST_CondRetParm ;
            } /* if */

			LBT_CondRetObtido = LBT_SolucionarLabirinto( vtLabirintos[ indexFocoLabirinto ], &numPassos );

			return TST_CompararInt( LBT_CondRetEsperada, LBT_CondRetObtido, "Retorno errado ao solucionar labirinto. " );

	  } /* fim da ativa: Testar LBT Solucionar Labirinto */

      return TST_CondRetNaoConhec ;

   } /* Fim função: TLBT Efetuar operações de teste específicas para labirinto */
Example #7
0
   TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
   {

      int inxLista  = -1 ,
          numLidos   = -1 ,
          CondRetEsp = -1  ;

      TST_tpCondRet CondRet ;

      char   CharDado ;

      int ValEsp = -1 ;

      int i ;

      int numElem = -1 ;

      /* Efetuar reset de teste de lista */

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

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

            return TST_CondRetOK ;

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

      /* Testar CriarLista */

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

            numLidos = LER_LerParametros( "i" ,
                       &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            vtListas[ inxLista ] =
                 LIS_CriarLista( ) ;

            return TST_CompararPonteiroNulo( 1 , vtListas[ inxLista ] ,
               "Erro em ponteiro de nova lista."  ) ;

         } /* fim ativa: Testar CriarLista */

      /* Testar Esvaziar lista */

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

            numLidos = LER_LerParametros( "i" ,
                               &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            LIS_EsvaziarLista( vtListas[ inxLista ] ) ;

            return TST_CondRetOK ;

         } /* fim ativa: Testar Esvaziar lista lista */

      /* Testar Destruir lista */

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

            numLidos = LER_LerParametros( "i" ,
                               &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            LIS_DestruirLista( vtListas[ inxLista ] ) ;
            vtListas[ inxLista ] = NULL ;

            return TST_CondRetOK ;

         } /* fim ativa: Testar Destruir lista */

      /* Testar inserir elemento antes */

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

            numLidos = LER_LerParametros( "ici" ,
                       &inxLista , &CharDado , &CondRetEsp ) ;

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

            CondRet = LIS_InserirElementoAntes( vtListas[ inxLista ] , CharDado ) ;

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

         } /* fim ativa: Testar inserir elemento antes */

      /* Testar inserir elemento apos */

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

            numLidos = LER_LerParametros( "ici" ,
                       &inxLista , &CharDado , &CondRetEsp ) ;

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

            CondRet = LIS_InserirElementoApos( vtListas[ inxLista ] , CharDado ) ;

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

         } /* fim ativa: Testar inserir elemento apos */

      /* Testar excluir simbolo */

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

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

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

            return TST_CompararInt( CondRetEsp ,
                      LIS_ExcluirElemento( vtListas[ inxLista ] ) ,
                     "Condição de retorno errada ao excluir."   ) ;

         } /* fim ativa: Testar excluir simbolo */

      /* Testar obter valor do elemento corrente */

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

            numLidos = LER_LerParametros( "ic" ,
                       &inxLista , &CharDado ) ;

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

			return TST_CompararChar( CharDado,
					LIS_ObterValor( vtListas[ inxLista ] ),
					"Valor do elemento corrente está errado." );

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

      /* Testar ir para o elemento inicial */

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

            numLidos = LER_LerParametros( "i" , &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            LIS_IrInicioLista( vtListas[ inxLista ] ) ;

            return TST_CondRetOK ;

         } /* fim ativa: Testar ir para o elemento inicial */

      /* LIS  &Ir para o elemento final */

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

            numLidos = LER_LerParametros( "i" , &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            LIS_IrFinalLista( vtListas[ inxLista ] ) ;

            return TST_CondRetOK ;

         } /* fim ativa: LIS  &Ir para o elemento final */

      /* LIS  &Avançar elemento */

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

            numLidos = LER_LerParametros( "iii" , &inxLista , &numElem ,
                                &CondRetEsp ) ;

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

            return TST_CompararInt( CondRetEsp ,
                      LIS_AvancarElementoCorrente( vtListas[ inxLista ] , numElem ) ,
                      "Condicao de retorno errada ao avancar" ) ;

         } /* fim ativa: LIS  &Avançar elemento */
		 
      /* Testar obter numero de elementos */

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

            numLidos = LER_LerParametros( "ii" ,
                       &inxLista , &ValEsp ) ;

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

			return TST_CompararInt( ValEsp,
					LIS_ObterNumElem( vtListas[ inxLista ] ),
					"Numero de elementos da lista esta errado." );

         } /* fim ativa: Testar obter numero de elementos */
     

      return TST_CondRetNaoConhec ;

   } /* Fim função: TLIS &Testar lista */