Example #1
0
/***************************************************************************
*
*  Função: LIS  &Destruir lista
*  ****/
LIS_tpCondRet LIS_DestruirLista ( LIS_tppLista * pLista )
{

	/* Tratar lista vazia */
	
	if ( (*pLista) == NULL )
	{
		return LIS_CondRetListaInexistente;
	} /* if */ 
	
	/* fim ativa: Tratar lista vazia */

	if ( (*pLista)->pOrigemLista != NULL )
	{
		LIS_EsvaziarLista ( &(*pLista) );
	}

	free ( (*pLista) );
	
	(*pLista) = NULL;

	pLista = NULL;

	return LIS_CondRetOK;

} /* Fim função: LIS  &Destruir lista */
Example #2
0
LIS_tpCondRet LIS_DestruirLista(LIS_tppLista pLista)
{

#ifdef _DEBUG
	assert(pLista != NULL);
#endif

	if (pLista != NULL)
	{
		LIS_tpCondRet CondRet;

		CondRet = LIS_EsvaziarLista(pLista);
		if (CondRet != LIS_CondRetOK)
		{
			return CondRet;
		} /* if */

	} /* if */

	free(pLista);

	pLista = NULL;

	return LIS_CondRetOK;

} /* Fim função: LIS  &Destruir lista */
Example #3
0
   void LIS_DestruirLista( LIS_tppLista pLista )
   {

      LIS_EsvaziarLista( pLista ) ;

      free( pLista ) ;

   } /* Fim função: LIS  &Destruir lista */
   void LIS_DestruirLista( LIS_tppLista pLista )
   {

      #ifdef _DEBUG
         assert( pLista != NULL ) ;
      #endif

      LIS_EsvaziarLista( pLista ) ;

      free( pLista ) ;

   } /* Fim função: LIS  &Destruir lista */
Example #5
0
   LIS_tpCondRet LIS_DestruirLista( LIS_tppLista pLista )
   {

      #ifdef _DEBUG
         assert( pLista != NULL ) ;
      #endif

      LIS_EsvaziarLista( pLista ) ;

      free( pLista ) ;

	  return LIS_CondRetOK ;

   } /* Fim função: LIS  &Destruir lista */
/***************************************************************************
*
*  Função: PIL  &Esvaziar Pilha Cartas
*  ****/
PIL_tpCondRet PIL_EsvaziarPilhaCartas(PIL_tpPilha pPilha) {
	LIS_tpCondRet condRet;
	
	if (pPilha == NULL)
		return PIL_CondRetPilhaNaoExiste;

	condRet = LIS_EsvaziarLista (pPilha->cabeca);

	if (condRet == LIS_CondRetListaNaoExiste)
		return PIL_CondRetPilhaVazia;
	else
		return PIL_CondRetOK;

}/* Fim função: PIL  &Esvaziar Pilha Cartas */
Example #7
0
File: LISTA.C Project: Rifeli/t4
void LIS_DestruirLista( LIS_tppLista pLista )
{
#ifdef _DEBUG
	CED_MarcarEspacoNaoAtivo(pLista);
#endif
#ifdef _DEBUG
	assert( pLista != NULL ) ;
#endif

	LIS_EsvaziarLista( pLista ) ;

	free( pLista ) ;

} /* Fim função: LIS  &Destruir lista */
Example #8
0
/***************************************************************************
*  Função: GRA Destruir vértice corrente
******/
GRA_tpCondRet GRA_DestruirVerticeCorrente(GRA_tppGrafo pGrafoParm)
{
	tpGrafo *pGrafo = NULL;
	tpVertice  *pVerticeOrigem = NULL, *pVertice = NULL;
	tpAresta *pAresta = NULL;
	int estaVazia = -1, numElemLista = 0;

	if (pGrafoParm == NULL)
	{
		return GRA_CondRetGrafoNaoFoiCriado;
	}

	pGrafo = (tpGrafo*) pGrafoParm;

	if (EstaVazio(pGrafo))
	{
		return GRA_CondRetGrafoVazio;
	}

	LIS_EstaVazia(pGrafo->pOrigens,&estaVazia);

	if (estaVazia)
	{
		return GRA_CondRetNaoAchou;
	}

	// remove corrente vai para origem
	// Navega para o inicio da lista de origens
	LIS_IrInicioLista(pGrafo->pOrigens);
	//Pega o valor do primeiro vértice de origem
	LIS_ObterValor(pGrafo->pOrigens,(void**)&pVerticeOrigem);

	//remove arestas do vertice corrente
	LIS_EsvaziarLista(pGrafo->pCorrente->pSucessores);

	// Para cada item da lista de anteressores, remover aresta que aponta para o corrente
	LIS_NumELementos(pGrafo->pCorrente->pAntecessores,&numElemLista);
	LIS_IrInicioLista(pGrafo->pCorrente->pAntecessores);

	while(numElemLista > 0)
	{
		int nElem = 0;
		LIS_ObterValor(pGrafo->pCorrente->pAntecessores,(void**)&pVertice);

		LIS_NumELementos(pVertice->pSucessores, &nElem);
		LIS_IrInicioLista(pVertice->pSucessores);

		while(nElem > 0)
		{
			LIS_ObterValor(pVertice->pSucessores,(void**)&pAresta);

			if(!strcmp(pAresta->pVertice->nome, pGrafo->pCorrente->nome))
			{
				LIS_ExcluirElemento(pVertice->pSucessores);
				break;
			}

			LIS_AvancarElementoCorrente(pVertice->pSucessores,1);
			nElem--;
		}
		LIS_AvancarElementoCorrente(pGrafo->pCorrente->pAntecessores,1);
		numElemLista--;
	}

	//Exclui elemento corrente
	LIS_IrInicioLista(pGrafo->pVertices);
	LIS_ProcurarValor(pGrafo->pVertices,pGrafo->pCorrente->nome);
	LIS_ExcluirElemento(pGrafo->pVertices);

	pGrafo->pCorrente = pVerticeOrigem;
	

	return GRA_CondRetOK;
}
Example #9
0
TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
{

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

    char   StringDado[  DIM_VALOR ] ;

    int ValEsp = -1 ;

    int i ;

    int numElem = -1 ;

    StringDado[ 0 ] = 0 ;

    /* 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( DestruirValor ) ;

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

    } /* fim ativa: Testar CriarLista */

    /* Testar Esvaziar lista 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 )
    {
        struct user *u = (struct user*) malloc (sizeof (struct user));
        LIS_tpCondRet lret;
        if (!u)
            return TST_CondRetMemoria;

        numLidos = LER_LerParametros( "isssi" ,
                                      &inxLista , u->nome, u->tel, u->ender , &CondRetEsp ) ;

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

        lret = LIS_InserirElementoAntes( vtListas[ inxLista ] , u ) ;

        if ( lret != LIS_CondRetOK )
        {
            free( u ) ;
        } /* if */

        return TST_CompararInt( CondRetEsp , lret ,
                                "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 )
    {
        struct user *u = (struct user *)malloc (sizeof (struct user));
        LIS_tpCondRet lret;
        if (!u)
            return TST_CondRetMemoria;

        numLidos = LER_LerParametros( "isssi",
                                      &inxLista, u->nome, u->tel, u->ender, &CondRetEsp ) ;

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

        lret = LIS_InserirElementoApos( vtListas[ inxLista ] , u ) ;

        if ( lret != LIS_CondRetOK )
        {
            free( u ) ;
        } /* if */

        return TST_CompararInt( CondRetEsp , lret,
                                "Condicao de retorno errada ao inserir antes.") ;
    } /* 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_NOME_CMD ) == 0 )
    {
        struct user *u;
        numLidos = LER_LerParametros( "isi" ,
                                      &inxLista , StringDado , &ValEsp ) ;

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

        u = (struct user*) LIS_ObterValor( vtListas[ inxLista ] ) ;

        if ( ValEsp == 0 )
        {
            return TST_CompararPonteiroNulo( 0 , u,
                                             "Valor não deveria existir." ) ;
        } /* if */

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

        return TST_CompararString( StringDado , u->nome,
                                   "Valor nome do elemento esta' errado." ) ;
    } /* fim ativa: Testar obter valor do elemento corrente */

    /* Testar obter valor do elemento corrente */
    else if ( strcmp( ComandoTeste, OBTER_TEL_CMD ) == 0 )
    {
        struct user *u;
        numLidos = LER_LerParametros( "isi" ,
                                      &inxLista , StringDado , &ValEsp ) ;

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

        u = (struct user*) LIS_ObterValor( vtListas[ inxLista ] ) ;

        if ( ValEsp == 0 )
        {
            return TST_CompararPonteiroNulo( 0 , u,
                                             "Valor não deveria existir." ) ;
        } /* if */

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

        return TST_CompararString( StringDado , u->tel,
                                   "Valor nome do elemento esta' errado." ) ;
    } /* fim ativa: Testar obter valor do elemento corrente */
    /* Testar obter valor do elemento corrente */
    else if ( strcmp( ComandoTeste , OBTER_ENDER_CMD ) == 0 )
    {
        struct user *u;
        numLidos = LER_LerParametros( "isi" ,
                                      &inxLista , StringDado , &ValEsp ) ;

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

        u = (struct user*) LIS_ObterValor( vtListas[ inxLista ] ) ;

        if ( ValEsp == 0 )
        {
            return TST_CompararPonteiroNulo( 0 , u,
                                             "Valor não deveria existir." ) ;
        } /* if */

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

        return TST_CompararString( StringDado , u->ender,
                                   "Valor nome do elemento esta' 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 */

        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 */

        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 */

    return TST_CondRetNaoConhec ;

} /* Fim função: TLIS &Testar lista */
Example #10
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 #11
0
TST_tpCondRet TST_EfetuarComando(char * ComandoTeste)
{
    int inxLista  = -1, numLidos   = -1, CondRetEsp = -1;

    TST_tpCondRet CondRet;

    char   StringDado[DIM_VALOR];
    char * pDado;

    int IntDado[DIM_VALOR_INT];
    int* pDadoInt;

    int ValEsp = -1;
    int i;
    int numElem = -1;

    int inxStoredPtr;

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

    /* Efetuar reset de teste de lista */
    if(strcmp(ComandoTeste, RESET_LISTA_CMD) == 0) {
        for(i = 0; i < DIM_VT_LISTA; i++) {
            vtListas[i] = NULL;
            storedPtrIndex[i] = 1;
        }

        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;

        vtListas[inxLista] = LIS_CriarLista(DestruirValor);

        return TST_CompararPonteiroNulo(1, vtListas[inxLista], "Erro em ponteiro de nova lista.");
    } /* fim ativa: Testar CriarLista */

    /* Testar Esvaziar lista lista */
    else if(strcmp(ComandoTeste, ESVAZIAR_LISTA_CMD) == 0) {
        numLidos = LER_LerParametros("i", &inxLista);

        if((numLidos != 1) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        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;

        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("isi", &inxLista, StringDado, &CondRetEsp);

        if((numLidos != 3) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        if(!ValidarInxStoredPtr(storedPtrIndex[inxLista]))
            return TST_CondRetMemoria;

        pDado = (char *) malloc(strlen(StringDado) + 1);
        if(pDado == NULL)
            return TST_CondRetMemoria;

        storedPtr[inxLista][storedPtrIndex[inxLista]++] = pDado;
        strcpy(pDado, StringDado);

        CondRet = LIS_InserirElementoAntes(vtListas[inxLista], pDado);
        if(CondRet != LIS_CondRetOK)
            free(pDado);

        return TST_CompararInt(CondRetEsp, CondRet, "Condicao de retorno errada ao inserir antes.");
    } /* fim ativa: Testar inserir elemento antes */

    /* Testar inserir elemento antes INTEIRO */
    else if(strcmp(ComandoTeste, INS_ELEM_ANTES_CMD_INT) == 0) {
        numLidos = LER_LerParametros("iiii", &inxLista, &IntDado[0], &IntDado[1], &CondRetEsp);

        if((numLidos != 4) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        if(!ValidarInxStoredPtr(storedPtrIndex[inxLista]))
            return TST_CondRetMemoria;

        pDadoInt = (int *) malloc(DIM_VALOR_INT*sizeof(int));
        if(pDadoInt == NULL)
            return TST_CondRetMemoria;

        storedPtr[inxLista][storedPtrIndex[inxLista]++] = pDadoInt;
        for(i=0;i<DIM_VALOR_INT;i++)
            pDadoInt[i]=IntDado[i];

        CondRet = LIS_InserirElementoAntes(vtListas[inxLista], pDadoInt);
        if(CondRet != LIS_CondRetOK)
            free(pDadoInt);

        return TST_CompararInt(CondRetEsp, CondRet, "Condicao de retorno errada ao inserir antes.");
    } /* fim ativa: Testar inserir elemento antes INTEIRO*/

    /* Testar inserir elemento apos */
    else if(strcmp(ComandoTeste, INS_ELEM_APOS_CMD) == 0) {
        numLidos = LER_LerParametros("isi", &inxLista, StringDado, &CondRetEsp);

        if((numLidos != 3) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        if(!ValidarInxStoredPtr(storedPtrIndex[inxLista]))
            return TST_CondRetMemoria;

        pDado = (char*)malloc(strlen(StringDado) + 1);
        if(pDado == NULL)
            return TST_CondRetMemoria;

        storedPtr[inxLista][storedPtrIndex[inxLista]++] = pDado;
        strcpy(pDado, StringDado);

        CondRet = LIS_InserirElementoApos(vtListas[inxLista], pDado);
        if(CondRet != LIS_CondRetOK)
            free(pDado);

        return TST_CompararInt(CondRetEsp, CondRet, "Condicao de retorno errada ao inserir apos.");
    } /* fim ativa: Testar inserir elemento apos */

    /* Testar inserir elemento apos INTEIRO*/
    else if(strcmp(ComandoTeste, INS_ELEM_APOS_CMD_INT) == 0) {
        numLidos = LER_LerParametros("iiii", &inxLista, &IntDado[0], &IntDado[1], &CondRetEsp);

        if((numLidos != 4) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        if(!ValidarInxStoredPtr(storedPtrIndex[inxLista]))
            return TST_CondRetMemoria;

        pDadoInt = (int *) malloc(DIM_VALOR_INT * sizeof(int));
        if(pDadoInt == NULL)
            return TST_CondRetMemoria;

        storedPtr[inxLista][storedPtrIndex[inxLista]++] = pDadoInt;
        for(i=0;i<DIM_VALOR_INT;i++)
            pDadoInt[i]=IntDado[i];

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

        if(CondRet != LIS_CondRetOK)
            free(pDadoInt);

        return TST_CompararInt(CondRetEsp, CondRet, "Condicao de retorno errada ao inserir apos.");
    } /* fim ativa: Testar inserir elemento apos INTEIRO*/

    /* 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;

        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("isi", &inxLista, StringDado, &ValEsp);

        if((numLidos != 3) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        pDado = (char *) LIS_ObterValor(vtListas[inxLista]);
        if(ValEsp == 0)
            return TST_CompararPonteiroNulo(0, pDado, "Valor não deveria existir.");

        if(pDado == NULL)
            return TST_CompararPonteiroNulo(1, pDado, "Dado tipo um deveria existir.");

        return TST_CompararString(StringDado, pDado, "Valor do elemento errado.");
    } /* fim ativa: Testar obter valor do elemento corrente */

    /* Testar obter valor do elemento corrente INTEIRO*/
    else if(strcmp(ComandoTeste, OBTER_VALOR_CMD_INT) == 0) {
        numLidos = LER_LerParametros("iiii", &inxLista, &IntDado[0], &IntDado[1], &ValEsp);

        if((numLidos != 4) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        pDadoInt = (int *)LIS_ObterValor(vtListas[inxLista]);
        if(ValEsp == 0)
            return TST_CompararPonteiroNulo(0, pDadoInt, "Valor não deveria existir.");

        if(pDadoInt == NULL)
            return TST_CompararPonteiroNulo(1, pDadoInt, "Dado tipo um deveria existir.");

        return TST_CompararEspaco(IntDado, pDadoInt, DIM_VALOR_INT * sizeof(int),
                                  "Valor do elemento errado.");
    } /* fim ativa: Testar obter valor do elemento corrente INTEIRO*/

    /* 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;

        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;

        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;

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

    } /* fim ativa: LIS  &Avançar elemento */

    /* Testar Ir Indice */
    else if(strcmp(ComandoTeste, IR_INDICE_CMD) == 0) {
        numLidos = LER_LerParametros("iii", &inxLista, &numElem, &CondRetEsp);
        if((numLidos != 3) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        return TST_CompararInt(CondRetEsp, LIS_IrIndice(vtListas[inxLista], numElem),
                               "Condicao de retorno errada ao ir para o índice");
    } /* fim ativa: Testar Ir Indice */

    /* Testar Setar Valor INTEIRO*/
    else if(strcmp(ComandoTeste, SETAR_VALOR_CMD_INT) == 0) {
        numLidos = LER_LerParametros("iiii", &inxLista, &IntDado[0], &IntDado[1], &CondRetEsp);
        if((numLidos != 4) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        if(!ValidarInxStoredPtr(storedPtrIndex[inxLista]))
            return TST_CondRetMemoria;

        pDadoInt = (int *) malloc(DIM_VALOR_INT * sizeof(int));
        if(pDadoInt == NULL)
            return TST_CondRetMemoria;

        storedPtr[inxLista][storedPtrIndex[inxLista]++] = pDadoInt;
        for(i=0;i<DIM_VALOR_INT;i++)
            pDadoInt[i]=IntDado[i];

        return TST_CompararInt(CondRetEsp, LIS_SetarValor(vtListas[inxLista], pDadoInt),
                               "Condicao de retorno errada ao ir marcar o valor");
    } /* fim ativa: LIS  Setar Valor INTEIRO*/

    /* Testar Procurar Valor */
    else if(strcmp(ComandoTeste, PROCURAR_VALOR_CMD) == 0) {
        numLidos = LER_LerParametros("iii", &inxLista, &inxStoredPtr, &CondRetEsp);
        if((numLidos != 3) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        if(!ValidarInxStoredPtr(inxStoredPtr))
            return TST_CondRetParm;

        return TST_CompararInt(CondRetEsp, LIS_ProcurarValor(vtListas[inxLista], storedPtr[inxLista][inxStoredPtr]),
                               "Condicao de retorno errada ao procurar valor");
    } /* fim ativa: LIS Procurar Valor */

    return TST_CondRetNaoConhec;
} /* Fim função: TLIS &Testar lista */
Example #12
0
   TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
   {

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

      TST_tpCondRet CondRet ;

	  int CondRetObtido = LIS_CondRetOK;
	  int det, falhasEsperadas, falhasObtidas;

      char   StringDado[  DIM_VALOR ] ;
      char * pDado ;

      int ValEsp = -1 ;

      int i,num ;

      int numElem = -1 ;

      StringDado[ 0 ] = 0 ;

      /* 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( DestruirValor ) ;

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

         } /* fim ativa: Testar CriarLista */

      /* Testar Esvaziar lista 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( "isi" ,
                       &inxLista , StringDado , &CondRetEsp ) ;

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

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

            strcpy( pDado , StringDado ) ;


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

            if ( CondRet != LIS_CondRetOK )
            {
               free( pDado ) ;
            } /* if */

            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( "isi" ,
                       &inxLista , StringDado , &CondRetEsp ) ;

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

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

            strcpy( pDado , StringDado ) ;


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

            if ( CondRet != LIS_CondRetOK )
            {
               free( pDado ) ;
            } /* if */

            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( "isi" ,
                       &inxLista , StringDado , &ValEsp ) ;

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

            pDado = ( char * ) LIS_ObterValor( vtListas[ inxLista ] ) ;

            if ( ValEsp == 0 )
            {
               return TST_CompararPonteiroNulo( 0 , pDado ,
                         "Valor não deveria existir." ) ;
            } /* if */

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

            return TST_CompararString( StringDado , pDado ,
                         "Valor do elemento 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 */

            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 */

            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 */
		 /* LIS &Testar Obter Tamanho Lista */
		 else if (strcmp ( ComandoTeste , OBTER_TAMANHO_CMD ) == 0 )
		 {
			 numLidos = LER_LerParametros( "iii" ,&inxLista,&ValEsp, &CondRetEsp ) ;

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

			CondRetObtido = LIS_ObterTamanho( vtListas[ inxLista ], &num );

			CondRet = TST_CompararInt( ValEsp , num ,"Valor do elemento errado, diferente do esperado" ) ;

			if ( CondRet != TST_CondRetOK )
               return CondRet ;

						return TST_CondRetOK;
		 }  /* Fim testar Obter Tamanho */
#ifdef _DEBUG
		 /* Testar Deturpar */
		 else if (strcmp ( ComandoTeste , DETURPA_CMD ) == 0 )
		 {
			 numLidos = LER_LerParametros( "ii" ,&inxLista, &det) ;

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

			DeturpaLista(vtListas[ inxLista ], det);

			return TST_CondRetOK;
		 }
		 else if (strcmp ( ComandoTeste , VERIFICA_CMD ) == 0 )
		 {
			 numLidos = LER_LerParametros( "ii" ,&inxLista, &falhasEsperadas) ;

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

			verificaLista(vtListas[ inxLista ], &falhasObtidas);

			CondRet = TST_CompararInt( falhasEsperadas , falhasObtidas ,"Numero de falhas esperadas diferente de obtida" ) ;
			if ( CondRet != TST_CondRetOK )
               return CondRet ;

			return TST_CondRetOK;
		 }
#endif
		 return TST_CondRetNaoConhec ;

   } /* Fim função: TLIS &Testar lista */
Example #13
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 */