Esempio n. 1
0
TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
{

    int inxGrafo  = -1 ,
        numLidos   = -1 ,
        CondRetEsp = -1 ,
        param, numErros;

    char idVertice;
    char idVertice2;

    char StringDado[ DIM_VALOR ];

    VER_tppVertice novoVertice;

    TST_tpCondRet CondRet ;

    void * pDado ;

    char * pValor;

    /* Testar criar Grafo */
    if ( strcmp( ComandoTeste , CRIAR_GRAFO_CMD  ) == 0 ) {

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

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

        CondRet = GRA_CriarGrafo( &vtGRAFO[ inxGrafo ], DestruirValor );

        return TST_CompararInt( CondRetEsp , CondRet ,
                                "Condicao de retorno errada ao criar grafo."  ) ;

    } /* fim ativa: Testar criar Grafo */

    /* Testar destruir Grafo */
    else if ( strcmp( ComandoTeste , DESTRUIR_GRAFO_CMD  ) == 0 ) {

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

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

        CondRet = GRA_DestruirGrafo( vtGRAFO[ inxGrafo ] );

        vtGRAFO[ inxGrafo ] = NULL;

        return TST_CompararInt( CondRetEsp , CondRet ,
                                "Condicao de retorno errada ao destruir grafo."  ) ;

    } /* fim ativa: Testar destruir Grafo */

    /* Testar esvaziar Grafo */
    else if ( strcmp( ComandoTeste , ESV_GRAFO_CMD  ) == 0 ) {

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

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

        CondRet = GRA_EsvaziarGrafo( vtGRAFO[ inxGrafo ] );

        return TST_CompararInt( CondRetEsp , CondRet ,
                                "Condicao de retorno errada ao esvaziar grafo."  ) ;

    } /* fim ativa: Testar esvaziar Grafo */

    /* Testar obter vertice corrente em Grafo */
    else if ( strcmp( ComandoTeste , CORR_GRAFO_CMD  ) == 0 ) {

        numLidos = LER_LerParametros( "isi" , &inxGrafo, StringDado, &CondRetEsp ) ;

        if ( ( numLidos != 3 ) || ( ValidarInxGrafo( inxGrafo , VAZIO ) ) )
        {
            return TST_CondRetParm ;
        } /* if */


        CondRet = GRA_ObterValorCorrente( vtGRAFO[ inxGrafo ], &novoVertice );

        if(CondRet != GRA_CondRetOK)
            return TST_CompararInt( CondRetEsp , CondRet ,
                                    "Condicao de retorno errada ao obter valor corrente."  ) ;

        VER_ObterValor( novoVertice, &pValor);

        return TST_CompararString( StringDado , pValor ,
                                   "Retorno errado ao obter valor corrente."  ) ;

    } /* fim ativa: Testar obter vertice corrente em Grafo */

    /* Testar alterar vertice corrente em Grafo */
    else if ( strcmp( ComandoTeste , ALTCORR_GRAFO_CMD  ) == 0 ) {

        numLidos = LER_LerParametros( "isi" , &inxGrafo, StringDado, &CondRetEsp ) ;

        if ( ( numLidos != 3 ) || ( ValidarInxGrafo( inxGrafo , VAZIO ) ) )
        {
            return TST_CondRetParm ;
        } /* if */

        VER_CriarVertice( &novoVertice );

#ifdef _DEBUG
        CED_DefinirTipoEspaco( novoVertice, ID_VER_tppVertice );
#endif

        VER_AtribuirValor( novoVertice, StringDado ) ;

        CondRet = GRA_AlterarValorCorrente( vtGRAFO[ inxGrafo ], novoVertice );

        if(CondRet != GRA_CondRetOK)
            VER_DestruirVertice(novoVertice);

        return TST_CompararInt( CondRetEsp , CondRet ,
                                "Condicao de retorno errada ao alterar corrente."  ) ;

    } /* fim ativa: Testar alterar vertice corrente em Grafo */

    /* Testar alterar vertice corrente para null em Grafo */
    else if ( strcmp( ComandoTeste , ALTCORRNULL_GRAFO_CMD  ) == 0 ) {

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

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


        CondRet = GRA_AlterarValorCorrente( vtGRAFO[ inxGrafo ], NULL );

        return TST_CompararInt( CondRetEsp , CondRet ,
                                "Condicao de retorno errada ao alterar corrente."  ) ;

    } /* fim ativa: Testar alterar vertice corrente em Grafo */

    /* Testar ir para vertice em Grafo */
    else if ( strcmp( ComandoTeste , IRVER_GRAFO_CMD  ) == 0 ) {

        numLidos = LER_LerParametros( "ici" , &inxGrafo, &idVertice, &CondRetEsp ) ;

        if ( ( numLidos != 3 ) || ( ValidarInxGrafo( inxGrafo , VAZIO ) ) )
        {
            return TST_CondRetParm ;
        } /* if */

        CondRet = GRA_IrParaVertice( vtGRAFO[ inxGrafo ], idVertice );

        return TST_CompararInt( CondRetEsp , CondRet ,
                                "Condicao de retorno errada ao ir para vertice."  ) ;

    } /* fim ativa: Testar ir para vertice em Grafo */

    /* Testar andar para vertice em Grafo */
    else if ( strcmp( ComandoTeste , ANDARVER_GRAFO_CMD  ) == 0 ) {

        numLidos = LER_LerParametros( "ici" , &inxGrafo, &idVertice, &CondRetEsp ) ;

        if ( ( numLidos != 3 ) || ( ValidarInxGrafo( inxGrafo , VAZIO ) ) )
        {
            return TST_CondRetParm ;
        } /* if */

        CondRet = GRA_AndarParaVertice( vtGRAFO[ inxGrafo ], idVertice );

        return TST_CompararInt( CondRetEsp , CondRet ,
                                "Condicao de retorno errada ao andar para vertice."  ) ;

    } /* fim ativa: Testar andar para vertice em Grafo */

    /* Testar inserir vertice em Grafo */
    else if ( strcmp( ComandoTeste , INSVER_GRAFO_CMD  ) == 0 ) {

        numLidos = LER_LerParametros( "isci" , &inxGrafo, StringDado, &idVertice, &CondRetEsp ) ;

        if ( ( numLidos != 4 ) || ( ValidarInxGrafo( inxGrafo , VAZIO ) ) )
        {
            return TST_CondRetParm ;
        } /* if */

        VER_CriarVertice( &novoVertice );

#ifdef _DEBUG
        CED_EhEspacoAtivo( novoVertice );
        CED_DefinirTipoEspaco( novoVertice, ID_VER_tppVertice );
#endif

        VER_AtribuirValor( novoVertice, StringDado ) ;

        CondRet = GRA_InserirVertice( vtGRAFO[ inxGrafo ], novoVertice, idVertice );

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

    } /* fim ativa: Testar inserir vertice em Grafo */

    /* Testar inserir vertice de valor null em Grafo */
    else if ( strcmp( ComandoTeste , INSVERNULL_GRAFO_CMD  ) == 0 ) {

        numLidos = LER_LerParametros( "ici" , &inxGrafo, &idVertice, &CondRetEsp ) ;

        if ( ( numLidos != 3 ) || ( ValidarInxGrafo( inxGrafo , VAZIO ) ) )
        {
            return TST_CondRetParm ;
        } /* if */

        CondRet = GRA_InserirVertice( vtGRAFO[ inxGrafo ], NULL, idVertice );

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

    } /* fim ativa: Testar inserir vertice de valor null em Grafo */

    /* Testar excluir vertice corrente em Grafo */
    else if ( strcmp( ComandoTeste , EXCCORR_GRAFO_CMD  ) == 0 ) {

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

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

        CondRet = GRA_ExcluirVerticeCorrente( vtGRAFO[ inxGrafo ] );

        return TST_CompararInt( CondRetEsp , CondRet ,
                                "Condicao de retorno errada ao excluir vertice corrente."  ) ;

    } /* fim ativa: Testar excluir vertice corrente em Grafo */

    /* Testar inserir aresta em Grafo */
    else if ( strcmp( ComandoTeste , INSAR_GRAFO_CMD  ) == 0 ) {

        numLidos = LER_LerParametros( "iccsi" , &inxGrafo, &idVertice, &idVertice2, StringDado, &CondRetEsp) ;

        if ( ( numLidos != 5 ) || ( ValidarInxGrafo( inxGrafo , VAZIO ) ) )
        {
            return TST_CondRetParm ;
        } /* if */

        CondRet = GRA_InserirAresta( vtGRAFO[ inxGrafo ], idVertice, idVertice2, StringDado );

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

    } /* fim ativa: Testar inserir aresta em Grafo */

    /* Testar inserir aresta em origem no Grafo */
    else if ( strcmp( ComandoTeste , INSARO_GRAFO_CMD  ) == 0 ) {

        numLidos = LER_LerParametros( "icsi" , &inxGrafo, &idVertice, StringDado, &CondRetEsp) ;

        if ( ( numLidos != 4 ) || ( ValidarInxGrafo( inxGrafo , VAZIO ) ) )
        {
            return TST_CondRetParm ;
        } /* if */

        CondRet = GRA_InserirArestaOrigemCorrente( vtGRAFO[ inxGrafo ], idVertice, StringDado );

        return TST_CompararInt( CondRetEsp , CondRet ,
                                "Condicao de retorno errada ao inserir aresta na origem corrente."  ) ;

    } /* fim ativa: Testar inserir aresta em origem no Grafo */

    /* Testar excluir aresta em Grafo */
    else if ( strcmp( ComandoTeste , EXCAR_GRAFO_CMD  ) == 0 ) {

        numLidos = LER_LerParametros( "isi" , &inxGrafo, StringDado, &CondRetEsp) ;

        if ( ( numLidos != 3 ) || ( ValidarInxGrafo( inxGrafo , VAZIO ) ) )
        {
            return TST_CondRetParm ;
        } /* if */

        CondRet = GRA_ExcluirAresta( vtGRAFO[ inxGrafo ], StringDado );

        return TST_CompararInt( CondRetEsp , CondRet ,
                                "Condicao de retorno errada ao excluir aresta."  ) ;

    } /* fim ativa: Testar excluir aresta em Grafo */

    /* Testar adicionar origem em Grafo */
    else if ( strcmp( ComandoTeste , ADDOR_GRAFO_CMD  ) == 0 ) {

        numLidos = LER_LerParametros( "ici" , &inxGrafo, &idVertice, &CondRetEsp) ;

        if ( ( numLidos != 3 ) || ( ValidarInxGrafo( inxGrafo , VAZIO ) ) )
        {
            return TST_CondRetParm ;
        } /* if */

        CondRet = GRA_AdicionarOrigem( vtGRAFO[ inxGrafo ], idVertice );

        return TST_CompararInt( CondRetEsp , CondRet ,
                                "Condicao de retorno errada ao adicionar origem."  ) ;

    } /* fim ativa: Testar adicionar origem em Grafo */

    /* Testar remover origem em Grafo */
    else if ( strcmp( ComandoTeste , RMVOR_GRAFO_CMD  ) == 0 ) {

        numLidos = LER_LerParametros( "ici" , &inxGrafo, &idVertice, &CondRetEsp) ;

        if ( ( numLidos != 3 ) || ( ValidarInxGrafo( inxGrafo , VAZIO ) ) )
        {
            return TST_CondRetParm ;
        } /* if */

        CondRet = GRA_RemoverOrigem( vtGRAFO[ inxGrafo ], idVertice );

        return TST_CompararInt( CondRetEsp , CondRet ,
                                "Condicao de retorno errada ao remover origem."  ) ;

    } /* fim ativa: Testar remover origem em Grafo */

#ifdef _DEBUG
    /* Realizar deturpacao */
    else if ( strcmp( ComandoTeste , DETURPAR_GRAFO_CMD  ) == 0 ) {

        numLidos = LER_LerParametros( "ii" , &inxGrafo, &param) ;

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

        return TST_CompararInt( GRA_CondRetOK , GRA_Deturpar(vtGRAFO[ inxGrafo ], param),
                                "Erro ao deturpar."  ) ;

    } /* fim ativa: Realizar deturpacao */

    /* Realizar verificao estrututral */
    else if ( strcmp( ComandoTeste , VERIFICAR_GRAFO_CMD  ) == 0 ) {

        numLidos = LER_LerParametros( "ii" , &inxGrafo, &param) ;

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

        GRA_VerificarEstrutura( vtGRAFO[ inxGrafo ], &numErros );

        return TST_CompararInt( param , numErros ,
                                "Total de erros errado ao verificar estrutura."  ) ;

    } /* fim ativa: Realizar verificao estrututral */

#endif

} /* Fim função: TGRA &Testar grafo */
Esempio n. 2
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 */
Esempio n. 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 */
Esempio n. 4
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 */
Esempio n. 5
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 */
Esempio n. 6
0
   TST_tpCondRet TST_EfetuarComando(char *ComandoTeste)
   {
      int numLidos   = -1,
          CondRetEsp = -1;

      TST_tpCondRet CondRet;

      /*Testar CriarGrafo */

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

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

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

            CondRet = GRA_CriarGrafo(&pGrafo, DestruirValor);

            if(CondRet ==  GRA_CondRetOK)
            {
               CondRet = TST_CompararPonteiroNulo(1, pGrafo, "Erro em ponteiro de nova lista.");
               return CondRet;
            }

            return TST_CondRetErro;

         }

     /*Testar Destruir grafo */

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

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

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

            CondRet = GRA_DestruirGrafo(&pGrafo);

            return TST_CompararInt(CondRetEsp, CondRet, "Erro ao destruir grafo");

         }
     
      /*Testar inserir vertice */

         else if (strcmp(ComandoTeste, INS_VERT_CMD) == 0)
         {
            char *nome = AlocarEspacoParaNome();
            char *pDado = AlocarEspacoParaNome();

            numLidos = LER_LerParametros("ssi", nome, pDado, &CondRetEsp);

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

            CondRet = GRA_InserirVertice(pGrafo, nome, pDado);

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

         }
    
      /*Testar inserir aresta */

         else if (strcmp(ComandoTeste, INS_ARESTA_CMD) == 0)
         {
            char *nomeAresta = AlocarEspacoParaNome();
            char *nomeVerticeOrig = AlocarEspacoParaNome();
            char *nomeVerticeDest = AlocarEspacoParaNome();

            numLidos = LER_LerParametros("sssi", nomeAresta, nomeVerticeOrig, nomeVerticeDest, &CondRetEsp);

            if (numLidos != 4)
            {
               return TST_CondRetParm;
            }
   
            CondRet = GRA_InserirAresta(pGrafo, nomeAresta, nomeVerticeOrig, nomeVerticeDest);

            MEM_Free(nomeVerticeOrig);
            MEM_Free(nomeVerticeDest);

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

      /*Testar obter valor do vértice corrente */

         else if (strcmp(ComandoTeste, OBTER_VALOR_CMD) == 0)
         {
            char *pDadoEsperado = AlocarEspacoParaNome();
            char *pDadoObtido;

            numLidos = LER_LerParametros("si", pDadoEsperado, &CondRetEsp);

            if (numLidos != 2)
            {
               MEM_Free(pDadoEsperado);
               return TST_CondRetParm;
            }

            if (strcmp(pDadoEsperado, SIMBOLO_PARA_NULL) == 0)
            {
               pDadoEsperado = NULL;
            }

            CondRet = GRA_ObterValorCorrente(pGrafo, (void**) &pDadoObtido);


            if (CondRetEsp == TST_CondRetOK)
            {
               CondRet = TST_CompararString(pDadoEsperado, pDadoObtido, "Valor do elemento errado.");
               MEM_Free(pDadoEsperado);
               return CondRet;
            }
            else
            {
               MEM_Free(pDadoEsperado);
               if (pDadoObtido != NULL)
               {
                  return TST_NotificarFalha("Não foi obtido null como conteudo ao ocorrer um erro."); 
               }

               return TST_CompararInt(CondRetEsp, CondRet, "Não ocorreu o erro esperado na obtenção do conteudo.");
            }
         }

       /*Testar alterar valor do vértice corrente */

         else if (strcmp(ComandoTeste, ALTER_VALOR_CMD) == 0)
         {
            char *pNovoValor = AlocarEspacoParaNome();
            char *pAntigoValor;

            numLidos = LER_LerParametros("si", pNovoValor, &CondRetEsp);

            if (numLidos != 2)
            {
               return TST_CondRetParm;
            }
            
            GRA_ObterValorCorrente(pGrafo, (void**) &pAntigoValor);
            MEM_Free(pAntigoValor);

            CondRet = GRA_AlterarValorCorrente(pGrafo, pNovoValor);

            return TST_CompararInt(CondRetEsp, CondRet, "Ocorreu um erro ao alterar o valor.");
         }


       /*Testar tornar corrente uma origem */

         else if (strcmp(ComandoTeste, TORNAR_ORIGEM_CMD) == 0)
         {
            numLidos = LER_LerParametros("i", &CondRetEsp);

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

            CondRet = GRA_TornarCorrenteUmaOrigem(pGrafo);

            return TST_CompararInt(CondRetEsp, CondRet, "Ocorreu um erro ao tornar o corrente uma origem.");
         }


       /*Testar tornar corrente uma origem */

         else if (strcmp(ComandoTeste, DEIXAR_ORIGEM_CMD) == 0)
         {
            numLidos = LER_LerParametros("i", &CondRetEsp);

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

            CondRet = GRA_DeixarDeSerOrigem(pGrafo);

            return TST_CompararInt(CondRetEsp, CondRet, "Ocorreu um erro remover uma origem.");
         }


        /*Testar seguir pela aresta */

       else if (strcmp(ComandoTeste, IR_ARESTA_CMD) == 0)
         {
            char *nomeDaAresta = AlocarEspacoParaNome();

            numLidos = LER_LerParametros("si", nomeDaAresta, &CondRetEsp);

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

            CondRet = GRA_SeguirPelaAresta(pGrafo, nomeDaAresta);

            MEM_Free(nomeDaAresta);

            return TST_CompararInt(CondRetEsp, CondRet, "Ocorreu um erro ao ir para vértice adjacente.");
         }

       /*Testar ir vertice adjacente */

       else if (strcmp(ComandoTeste, IR_VERTICE_CMD) == 0)
         {
            char *nomeVertice = AlocarEspacoParaNome();

            numLidos = LER_LerParametros("si", nomeVertice, &CondRetEsp);

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

            CondRet = GRA_IrParaVerticeAdjacente(pGrafo, nomeVertice);

            MEM_Free(nomeVertice);

            return TST_CompararInt(CondRetEsp, CondRet, "Ocorreu um erro ao ir para vértice adjacente.");
         }

        /*Testar ir para origem */

       else if (strcmp(ComandoTeste, IR_ORIGEM_CMD) == 0)
         {
            char *nomeVertice = AlocarEspacoParaNome();

            numLidos = LER_LerParametros("si", nomeVertice, &CondRetEsp);

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

            CondRet = GRA_IrParaAOrigem(pGrafo, nomeVertice);

            MEM_Free(nomeVertice);

            return TST_CompararInt(CondRetEsp, CondRet, "Ocorreu um erro ao ir para origem.");
         }

         /*Testar ir destruir aresta adjacente */

       else if (strcmp(ComandoTeste, DESTRUIR_ARESTA_CMD) == 0)
         {
            char *nomeAresta = AlocarEspacoParaNome();

            numLidos = LER_LerParametros("si", nomeAresta, &CondRetEsp);

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

            CondRet = GRA_DestruirArestaAdjacente(pGrafo, nomeAresta);

            MEM_Free(nomeAresta);

            return TST_CompararInt(CondRetEsp, CondRet, "Ocorreu um erro ao destruir aresta adjacente.");
         }

          /*Testar ir destruir aresta adjacente */

       else if (strcmp(ComandoTeste, DESTRUIR_VERT_CMD) == 0)
         {
            numLidos = LER_LerParametros("i", &CondRetEsp);

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

            CondRet = GRA_DestruirVerticeCorrente(pGrafo);

            return TST_CompararInt(CondRetEsp, CondRet, "Ocorreu um erro ao destruir vertice corrente.");
         }

        /* Finalizar o teste */

       else if (strcmp(ComandoTeste, FIM_CMD) == 0)
         {
            MEM_LiberarTodaMemoriaAlocada();

            return TST_CondRetOK;
         }

      return TST_CondRetNaoConhec;

   }
Esempio n. 7
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 */
Esempio n. 8
0
   TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
   {
	   GRA_tppGrafo epGrafo=NULL;


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

      TST_tpCondRet CondRet ;

      char   StringDado[  DIM_VALOR ] ;
      char * pDado ;

      int ValEsp = -1 ;

      int i ;
	  int j;
      int numElem = -1 ;

      StringDado[ 0 ] = 0 ;

      /* Efetuar reset de teste de grafo */

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

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

            return TST_CondRetOK ;

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

      /* Testar CriarGrafo */

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

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

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


                 GRA_CriarGrafo(&VTGRAFO[ inxGrafo ]) ;
				 //epgrafo retornado por ref

            return TST_CompararPonteiroNulo( 1 , VTGRAFO[ inxGrafo ] ,
               "Erro em ponteiro de nova grafo."  ) ;

         } /* fim ativa: Testar CriarGrafo */

      /* Testar Esvaziar grafo grafo */

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

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

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

            GRA_EsvaziarGrafo( &VTGRAFO[ inxGrafo ] ) ;

            return TST_CondRetOK ;

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

      /* Testar Destruir grafo */

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

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

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

            GRA_DestruirGrafo( &VTGRAFO[ inxGrafo ] ) ;
            VTGRAFO[ inxGrafo ] = NULL ;

            return TST_CondRetOK ;

         } /* fim ativa: Testar Destruir grafo */

      /* Testar inserir elemento antes */

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

            numLidos = LER_LerParametros( "iiii" ,
                       &inxGrafo , &i,&j , &CondRetEsp ) ;

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

           
            if ( pDado == NULL )
            {
               return TST_CondRetMemoria ;
            } /* if */

            strcpy( pDado , StringDado ) ;


            CondRet =(TST_tpCondRet) GRA_InserirAresta( &VTGRAFO[ inxGrafo ] , i,j,0,0 ) ;

            if ( CondRet != GRA_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" ,
                       &inxGrafo , StringDado , &CondRetEsp ) ;

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

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

            strcpy( pDado , StringDado ) ;


            CondRet = GRA_InserirElementoApos( VTGRAFO[ inxGrafo ] , pDado ) ;

            if ( CondRet != GRA_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" ,
                  &inxGrafo , &CondRetEsp ) ;

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

            return TST_CompararInt( CondRetEsp ,
                      GRA_ExcluirElemento( VTGRAFO[ inxGrafo ] ) ,
                     "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" ,
                       &inxGrafo , StringDado , &ValEsp ) ;

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

            pDado = ( char * ) GRA_ObterValor( VTGRAFO[ inxGrafo ] ) ;

            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" , &inxGrafo ) ;

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

            GRA_IrInicioGrafo( VTGRAFO[ inxGrafo ] ) ;

            return TST_CondRetOK ;

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

      /* GRA  &Ir para o elemento final */

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

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

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

            GRA_IrFinalGrafo( VTGRAFO[ inxGrafo ] ) ;

            return TST_CondRetOK ;

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

      /* GRA  &Avan�ar elemento */

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

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

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

            return TST_CompararInt( CondRetEsp ,
                      GRA_AvancarElementoCorrente( VTGRAFO[ inxGrafo ] , numElem ) ,
                      "Condicao de retorno errada ao avancar" ) ;

         } /* fim ativa: GRA  &Avan�ar elemento */

      return TST_CondRetNaoConhec ;

   } /* Fim fun��o: TGRA &Testar grafo */
Esempio n. 9
0
   TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
   {

      int  numLidos = -1, 
           indexMat = -1,
           dimMatriz = -1,
           CondRetEsperada = -1,
           direcao = -1 ;

	  char stringDada [ DIM_STR ] = {0};
	  char *stringObtida;

      LIS_tppLista listaAuxiliar ;     

      TST_tpCondRet CondRetObtido ;

      /* Testar MAT Criar Matriz */

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

            numLidos = LER_LerParametros( "iii" ,
                               &indexMat, &dimMatriz, &CondRetEsperada ) ;
            if ( numLidos != 3 )
            {
               return TST_CondRetParm ;
            } /* if */

            CondRetObtido = MAT_CriarMatriz( &(vtMatrizes[ indexMat ]), dimMatriz ) ;

            return TST_CompararInt( CondRetEsperada , CondRetObtido ,
                     "Condicao de retorno errada ao criar matriz." ) ;

         } /* fim ativa: Testar MAT Criar Matriz */

      /* Testar MAT andar na matriz */

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

            numLidos = LER_LerParametros( "iii" ,
                               &indexMat, &direcao , &CondRetEsperada ) ;
            if ( numLidos != 3 )
            {
               return TST_CondRetParm ;
            } /* if */

            CondRetObtido = MAT_AndarCorrente( vtMatrizes[indexMat], (MAT_tpDirecao) direcao ) ;

            return TST_CompararInt( CondRetEsperada , CondRetObtido ,
                                    "Retorno errado ao percorrer a matriz." );

         } /* fim ativa: Testar MAT andar na matriz */

      /* Testar MAT atribuir lista a célula corrente */

         else if ( strcmp( ComandoTeste , ATRIBUIR_LIS_CMD ) == 0 )
         {
            numLidos = LER_LerParametros( "isi" ,
                              &indexMat, stringDada, &CondRetEsperada ) ;
            if ( numLidos != 3 )
            {
               return TST_CondRetParm ;
            } /* if */
			
			listaAuxiliar = criarListaAPartirDeString(stringDada);

            CondRetObtido = MAT_AtribuirValorCorrente( vtMatrizes[ indexMat ], listaAuxiliar ) ;
			
			return TST_CompararInt( CondRetEsperada , CondRetObtido ,
                                "Retorno errado ao inserir lista no elemento corrente." );
	     } /* fim ativa: Testar MAT atribuir lista a célula corrente */

      /* Testar MAT obter valor da célula corrente */  
         else if ( strcmp( ComandoTeste , OBTER_LIS_CMD ) == 0 )
         {
			int pEsp;
			numLidos = LER_LerParametros( "isii" ,
                              &indexMat, stringDada, &pEsp, &CondRetEsperada ) ;
            if ( numLidos != 4 )
            {
               return TST_CondRetParm ;
            } /* if */

            CondRetObtido = MAT_ObterValorCorrente( vtMatrizes[ indexMat ], &listaAuxiliar ) ;
			
			if( CondRetObtido != CondRetEsperada || CondRetObtido == MAT_CondRetPonteiroNulo ){
				return TST_CompararInt( CondRetEsperada , CondRetObtido ,
                                    "Retorno errado ao obter lista no elemento corrente." );
			}

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

			stringObtida = obterStringAPartirDeLista( listaAuxiliar );

			return TST_CompararString(stringDada, stringObtida, 
									"Representação em string da lista obtida diferente do esperado."); 
         } /* fim ativa: Testar MAT obeter valor da célula corrente */

      /* Testar MAT destruir matriz */  
         else if ( strcmp( ComandoTeste , DESTROI_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ii" ,
                              &indexMat, &CondRetEsperada ) ;
            if ( numLidos != 2 )
            {
               return TST_CondRetParm ;
            } /* if */

            CondRetObtido = MAT_DestruirMatriz( vtMatrizes[ indexMat ] ) ;

            return TST_CompararInt( CondRetEsperada , CondRetObtido ,
                                    "Retorno errado ao destruir matriz" );

         } /* fim ativa: Testar MAT destruir matriz */

      /* Testar MAT esvaziar matriz */  
         else if ( strcmp( ComandoTeste , ESVAZIA_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ii" ,
                              &indexMat, &CondRetEsperada ) ;
            if ( numLidos != 2 )
            {
               return TST_CondRetParm ;
            } /* if */

            CondRetObtido = MAT_EsvaziarMatriz( vtMatrizes[ indexMat ] ) ;

            return TST_CompararInt( CondRetEsperada , CondRetObtido ,
                                    "Retorno errado ao esvaziar matriz" );

         } /* fim ativa: MAT esvaziar matriz */

      return TST_CondRetNaoConhec ;

   } /* Fim função: TARV Efetuar operações de teste específicas para árvore */