GRA_tpCondRet GRA_DestruirGrafo( GRA_tppGrafo pGrafo ) { tpVertice* pVertice = NULL; #ifdef _DEBUG assert( pGrafo != NULL ) ; #endif LIS_DestruirLista(pGrafo->componentes); //Lista que não mexe com "ninguém" LIS_IrInicioLista(pGrafo->vertices); do { pVertice = (tpVertice *)LIS_ObterValor(pGrafo->vertices); if(pVertice == NULL) continue; if (pVertice->pNode->pValor != NULL && pGrafo->ExcluirValor != NULL) { pGrafo->ExcluirValor(pVertice->pNode->pValor); } LIS_DestruirLista(pVertice->pNode->arestas); free(pVertice->pNode); } while(LIS_AvancarElementoCorrente(pGrafo->vertices, 1) == LIS_CondRetOK); LIS_DestruirLista(pGrafo->vertices); free( pGrafo ) ; return GRA_CondRetOK; }
static int BFS(tpVertice* v, tpVertice* u) { LIS_tppLista V = NULL; // LISTA VERTICE VISITADOS LIS_tppLista Q = NULL; //FILA LIS_tppLista arestas = NULL; tpVertice* t = NULL; tpVertice* s = NULL; tpAresta* a = NULL; int achou = 0; int achou_V = 0; V = LIS_CriarLista(NULL); // dados são referenciados por outros, não devem ser apagados Q = LIS_CriarLista(NULL); // dados são referenciados por outros, não devem ser apagados LIS_InserirElementoApos(V, v); LIS_InserirElementoApos(Q, v); //Usado como uma Fila. while (LIS_NumeroDeElementos(Q) > 0) { LIS_IrInicioLista(Q); t = (tpVertice *)LIS_ObterValor(Q); LIS_ExcluirElemento(Q); if (t == u) { achou = 1; break; } arestas = t->pNode->arestas; LIS_IrInicioLista(arestas); do { a = (tpAresta *)LIS_ObterValor(arestas); if(a == NULL) continue; s = a->pVizinho; LIS_IrInicioLista(V); achou_V = 0; do { tpVertice * re = (tpVertice *)LIS_ObterValor(V); if (re == NULL) { continue; } if(re == s) achou_V = 1; } while(LIS_AvancarElementoCorrente(V, 1) == LIS_CondRetOK); if (!achou_V) { if(LIS_InserirElementoApos(V, s)!= LIS_CondRetOK){ achou = -1;break;} if(LIS_InserirElementoApos(Q, s)!= LIS_CondRetOK){ achou = -1;break;} } } while(LIS_AvancarElementoCorrente(arestas, 1) == LIS_CondRetOK); } LIS_DestruirLista(V); LIS_DestruirLista(Q); return achou; }
/*********************************************************************** * * Função: GRA Destruir vértice * * Descrição: * Função responsável por destruir vértices. Passada como ponteiro de funcao para listas de vértices. * ***********************************************************************/ void DestruirVertice(void *pVazio) { tpVertice *pVertice = (tpVertice*) pVazio; LIS_DestruirLista(pVertice->pAntecessores); LIS_DestruirLista(pVertice->pSucessores); pVertice->destruirValor(pVertice->pValor); MEM_Free(pVertice->nome); MEM_Free(pVertice); }
void GRA_Del (Graph *g) { #ifdef _DEBUG AssertGraph(g); #endif /* _DEBUG */ CNT_CONTAR("GRA_Del - Inicializao"); IrInicioLista ( g->nodes ); if ( !g->currentNode || !LIS_AvancarElementoCorrente ( g->nodes , 1)){ CNT_CONTAR("GRA_Del - Grafo vazio"); return; } IrInicioLista ( g->nodes ); do { CNT_CONTAR("GRA_Del - Deletando nos"); g->currentNode = LIS_ObterValor( g->nodes ); GRA_DelNode( g ); } while ( LIS_AvancarElementoCorrente ( g->nodes , 1) == LIS_CondRetOK ); /* == 0 ); */ CNT_CONTAR("GRA_Del - Destruindo, finalizao"); LIS_DestruirLista( g->nodes ); free(g); return; }
GRA_tppGrafo GRA_CriarGrafo( void (*ExcluirValor) (void* pDado) ) { GRA_tpGrafo * pGrafo = NULL ; LIS_tppLista l_vertice = NULL; LIS_tppLista l_componente = NULL; pGrafo = (GRA_tpGrafo*) calloc(1, sizeof(GRA_tpGrafo)) ; if (pGrafo == NULL) { return NULL ; } /* if */ l_vertice = LIS_CriarLista(free); //A Exclusão será manual, iterando sobre os elementos; if (l_vertice == NULL) { free(pGrafo); return NULL; } l_componente = LIS_CriarLista(NULL); //Controle interno e autocontido; Componentes não cuidam de dados do valor, só armazenam ponteiros. if (l_componente == NULL) { free(pGrafo); LIS_DestruirLista(l_vertice); return NULL; } pGrafo->vertices = l_vertice; pGrafo->componentes = l_componente; pGrafo->ExcluirValor = ExcluirValor ; pGrafo->corrente = -1; return pGrafo; }
LIS_tpCondRet LIS_CriarLista(LIS_tppLista *pLista, void(*ExcluirValor) (void * pDado)) { if (*pLista = NULL) { LIS_DestruirLista(*pLista); } *pLista = (LIS_tpLista *)malloc(sizeof(LIS_tpLista)); if (*pLista == NULL) { return LIS_CondRetFaltouMemoria; } /* if */ (*pLista)->pOrigemLista = NULL; (*pLista)->pFimLista = NULL; (*pLista)->pElemCorr = NULL; (*pLista)->numElem = 0; (*pLista)->ExcluirValor = ExcluirValor; return LIS_CondRetOK; } /* Fim função: LIS &Criar lista */
PIL_tpCondRet PIL_DestruirPilha( PIL_tppPilha pPilha ) { LIS_tpCondRet Ret ; if ( pPilha->pListaCartas == NULL ) { free( pPilha ) ; return PIL_CondRetOK ; } Ret = LIS_DestruirLista( pPilha->pListaCartas ) ; if( Ret != LIS_CondRetOK ) { return PIL_CondRetPilhaVazia ; } /* if */ free(pPilha) ; return PIL_CondRetOK ; }/* Fim função: PIL Destruir Pilha de Cartas */
/*********************************************************************** * $FC Função: NPE &Excluir Coluna ***********************************************************************/ NPE_tpCondRet NPE_ExcluirColunaNaipe(NPE_Coluna coluna){ if(coluna == NULL) return NPE_CondRetColunaNaoExiste; LIS_DestruirLista(coluna); return NPE_CondRetOK; }
/*************************************************************************** * * Função: TAB &Destruir tabuleiro * ****/ TAB_tpCondRet TAB_destruir(Tabuleiro *tabuleiro) { if(!tabuleiro) return TAB_CondRetTabuleiroInexistente; LIS_DestruirLista(tabuleiro->lista); free(tabuleiro); return TAB_CondRetOK; }/* Fim função: TAB &Destruir tabuleiro */
TAB_tpCondRet TAB_DestruirTabuleiro (TAB_tppTabuleiro pTab) { LIS_DestruirLista(pTab->Casas); // Libera o ponteiro para o tabuleiro free(pTab); return TAB_CondRetOK; }
/*************************************************************************** * Função: GRA Destruir grafo ******/ GRA_tpCondRet GRA_DestruirGrafo(GRA_tppGrafo *ppGrafo) { tpGrafo *pGrafo = (tpGrafo*) *ppGrafo; if (pGrafo == NULL) { return GRA_CondRetOK; } LIS_DestruirLista(pGrafo->pVertices); LIS_DestruirLista(pGrafo->pOrigens); MEM_Free(pGrafo); pGrafo = NULL; *ppGrafo = NULL; return GRA_CondRetOK; }
GRA_tpCondRet destruirValor(GRA_tppGrafo pGrafo) { if(pGrafo==NULL){ return GRA_CondRetGrafoNulo; } pGrafo->pCorrente = NULL; LIS_DestruirLista(pGrafo->pListaOrigens); LIS_DestruirLista(pGrafo->pListaVertices); free(pGrafo); pGrafo = NULL; return GRA_CondRetOK; } /* Fim função: GRA &Destruir valor do grafo */
GRA_tpCondRet GRA_DestruirGrafo(GRA_tppGrafo pGrafo) { int numElem = 0; tpVerticeGrafo * pVert ; GRA_tpCondRet RET; if(pGrafo==NULL){ return GRA_CondRetGrafoNulo; } /* if */ LIS_IrInicioLista(pGrafo->pListaVertices); LIS_NumElem(pGrafo->pListaVertices , &numElem); while(numElem > 0){ LIS_IrInicioLista(pGrafo->pListaVertices); LIS_ObterValor(pGrafo->pListaVertices , (void**)&pVert); pGrafo->pCorrente = pVert; GRA_ExcluirVerticeCorrente(pGrafo); LIS_NumElem(pGrafo->pListaVertices , &numElem); } /* while */ LIS_DestruirLista(pGrafo->pListaOrigens); LIS_DestruirLista(pGrafo->pListaVertices); free(pGrafo); pGrafo = NULL; return GRA_CondRetOK; }
CPC_tpCondRet CPC_DestruirClassePeca( CPC_tppClassePeca pClassePeca ) { if(pClassePeca == NULL) { return CPC_CondRetPonteiroNulo; } LIS_DestruirLista(pClassePeca->movimentos); free(pClassePeca->nome); free(pClassePeca); return CPC_CondRetOK; }
PILHA_tpCondRet PILHA_DestroiPilha(PILHA_tppPilha p){ if(!p){ return PILHA_CondRetPilhaInexistente; } #ifdef _DEBUG CED_MarcarEspacoNaoAtivo(p); #endif LIS_DestruirLista(p->topo); free(p); return PILHA_CondRetOK; }
/*************************************************************************** * * Função: PIL &Destruir Pilha Cartas * ****/ PIL_tpCondRet PIL_DestruirPilhaCartas (PIL_tpPilha pPilha) { LIS_tpCondRet condRet; if (pPilha == NULL) return PIL_CondRetPilhaNaoExiste; condRet = LIS_DestruirLista( pPilha->cabeca ); free(pPilha); pPilha = NULL; return PIL_CondRetOK; }/* Fim função: PIL &Destruir Pilha Cartas */
void delNode (Graph *g, void *n_) { Node * n=n_; CNT_CONTAR("delNode - Destruindo lista de links"); LIS_DestruirLista( n->links ); if ( g->delData ){ CNT_CONTAR("delNode - Existe g->delData"); ( *g->delData )( n->data ); } #ifdef _DEBUG IrFinalLista( g->currentNode ); free(LIS_ObterValor( g->currentNode )); IrInicioLista( g->currentNode ); #endif /* _DEBUG */ CNT_CONTAR("delNode - Finalizando"); free (n); }
static GRA_tpCondRet ExcluirVertice (GRA_tppGrafo pGrafo, tpVertice* pVertice) { tpAresta** vizinhos = NULL; tpNode* no = NULL; tpVertice * pVerticeVizinho = NULL; int i = 0; no = pVertice->pNode; LIS_IrInicioLista(pGrafo->componentes); LIS_ProcurarValor(pGrafo->componentes, pVertice); LIS_ExcluirElemento(pGrafo->componentes); if (LIS_NumeroDeElementos(no->arestas) > 0) { vizinhos = (tpAresta**)calloc(LIS_NumeroDeElementos(no->arestas), sizeof(tpAresta*)); LIS_IrInicioLista(no->arestas); do { vizinhos[i] = (tpAresta *)LIS_ObterValor(no->arestas); i++; } while ( LIS_AvancarElementoCorrente(no->arestas,1) == LIS_CondRetOK); for (i; i; i--) { ExcluirAresta(pGrafo, pVertice, vizinhos[i-1]->pVizinho); } if (pGrafo->ExcluirValor != NULL && no->pValor != NULL) { pGrafo->ExcluirValor(no->pValor); no->pValor = NULL; } free(vizinhos); } LIS_DestruirLista(no->arestas); no->arestas = NULL; pVertice->pNode = NULL; free(no); LIS_IrInicioLista(pGrafo->vertices); LIS_ProcurarValor(pGrafo->vertices, pVertice); LIS_ExcluirElemento(pGrafo->vertices); return GRA_CondRetOK; }
/*********************************************************************** * * $FC Função: MEN CriarMenu * ***********************************************************************/ MEN_tpCondRet MEN_CriarMenu(MEN_tppMenus menus, int id, char* nome,int idpai) { MEN_tpCondRet cr; MEN_tppMenu m = (MEN_tppMenu)malloc(sizeof(Menu)); if(m==NULL) return MEN_CondRetFaltouMemoria; m->opcoes = LIS_CriarLista(free); if(m->opcoes==NULL){ free(m); return MEN_CondRetFaltouMemoria; } m->nome = nome; m->id = id; m->pai = idpai; GRA_InserirVertice(menus->grafo,m,m->id); cr = MEN_CriarOpcao(menus, m->id,'0', "Ir para o menu acima\n\t\t (encerrar o programa caso o menu atual seja Inicio)",volta); if(cr!=MEN_CondRetOK) { LIS_DestruirLista(m->opcoes); free(m); } //tratar cond ret return cr; }
//cria um vertice e sua estrutura interna static tpVertice* CriarVertice(GRA_tppGrafo grafo, void* pValor, int id) { tpVertice* v = NULL; tpNode* no = NULL; LIS_tppLista arestas = NULL; tpVertice* t = NULL; v = (tpVertice*) malloc( sizeof(tpVertice) ); if (v == NULL) { return NULL; } no = (tpNode*) malloc( sizeof(tpNode) ); if (no == NULL) { free(v); return NULL; } arestas = LIS_CriarLista(free); if(arestas == NULL) { free(v); free(no); return NULL; } no->arestas = arestas; no->pValor = pValor; v->pNode = no; v->id = id; if( LIS_InserirElementoApos (grafo->componentes, v) != LIS_CondRetOK) { free(v); free(no); LIS_DestruirLista(arestas); return NULL ; } return v; }
GRA_tpCondRet GRA_ObterVizinhos ( GRA_tppGrafo pGrafo, int idVertice, LIS_tppLista* pLista) { tpVertice * pVertice = get_by_id(pGrafo,idVertice); LIS_tppLista vizinhos = NULL; LIS_tppLista Ret_vizinhos = NULL; tpAresta* aresta = NULL; int* idVerticeVizinho = NULL; if (pVertice == NULL) return GRA_CondRetNaoEhVertice; Ret_vizinhos = LIS_CriarLista(free); if (Ret_vizinhos == NULL) { return GRA_CondRetFaltouMemoria; } vizinhos = pVertice->pNode->arestas; LIS_IrInicioLista(vizinhos); if (LIS_NumeroDeElementos(vizinhos) > 0) { do { idVerticeVizinho = (int*) calloc(1, sizeof(int)); aresta = (tpAresta *)LIS_ObterValor(vizinhos); (*idVerticeVizinho) = aresta->pVizinho->id; if (LIS_InserirElementoApos( Ret_vizinhos, idVerticeVizinho) != LIS_CondRetOK ) { LIS_DestruirLista(Ret_vizinhos); return GRA_CondRetFaltouMemoria; } } while(LIS_AvancarElementoCorrente(vizinhos, 1) == LIS_CondRetOK); } *pLista = Ret_vizinhos; return GRA_CondRetOK; }
LIS_tppLista FRC_ComecarJogo( ) { int i, j; EXT_tppExtras pAuxExt; VIS_tppVisivel pAuxVis; ORD_tppOrdenada pAuxOrd; LIS_tppLista pBaralho; LIS_tppLista pMesa = LIS_CriarLista( NULL ) ; /* Não foi possível criar a lista de listas */ if( pMesa == NULL ){ return NULL; } /* if */ /* Cria um baralho com 52 cartas e as embaralha */ pBaralho = FRC_CriarBaralho(); if(pBaralho == NULL){ return NULL ; } /* if */ EMB_Embaralhar( pBaralho ) ; /* Primeiro, cria cada uma das colunas que ira compor o jogo, na ordem: 4 ordenadas , 1 de extras , 8 de visiveis */ for( i = 0 ; i < FRC_NUM_COLS ; i++ ) { if( i > 4 ) { pAuxVis = VIS_CriarVisivel( ) ; LIS_InserirElementoApos( pMesa , ( void *) pAuxVis ) ; } else if( i < 4 ) { pAuxOrd = ORD_CriarOrdenada( ) ; LIS_InserirElementoApos( pMesa , ( void *) pAuxOrd ) ; } else { pAuxExt = EXT_CriarExtras( ) ; LIS_InserirElementoApos( pMesa , ( void *) pAuxExt ) ; } /* if */ } /* Agora, insere as cartas nas colunas visiveis */ IrInicioLista( pBaralho ) ; IrInicioLista( pMesa ) ; LIS_AvancarElementoCorrente( pMesa , 5 ) ; for( j = 0 ; j < 8 ; j++ ) { /* Primeiras 4 colunas, que recebem 7 cartas cada */ if( j < 4 ) { for( i = 0 ; i < 7 ; i++ ) { VIS_InserirCarta( ( VIS_tppVisivel ) ( LIS_ObterValor( pMesa ) ) , ( CAR_tppCarta ) ( LIS_ObterValor( pBaralho ) ) , VIS_ModoSemOrdem ) ; LIS_AvancarElementoCorrente( pBaralho , 1 ) ; } /* for */ } /* Últimas 4 colunas, que recebem 6 cartas cada */ else { for( i = 0 ; i < 6 ; i++ ) { VIS_InserirCarta( ( VIS_tppVisivel ) LIS_ObterValor( pMesa ) , ( CAR_tppCarta ) LIS_ObterValor( pBaralho ) , VIS_ModoSemOrdem ) ; LIS_AvancarElementoCorrente( pBaralho , 1 ) ; } /* for */ } /* if */ LIS_AvancarElementoCorrente( pMesa , 1 ) ; } /* for */ LIS_DestruirLista( pBaralho ); return pMesa; }
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 */
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 */
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 */
void FIL_apagaFila (FIL_tppFila fila) { LIS_DestruirLista(fila->lista); free(fila); return; }
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 */
GRA_tpCondRet GRA_ExcluirVerticeCorrente(GRA_tppGrafo pGrafo) { int ts; tpVerticeGrafo * pVertOrigem; tpVerticeGrafo * pVerticeCaminho; GRA_tppArestaGrafo pAres; pVertOrigem = pGrafo->pCorrente; LIS_IrInicioLista(pVertOrigem->pVerAnt); ListaRet = LIS_CondRetOK ; ListaRetCaminho = LIS_CondRetOK; LIS_NumElem(pVertOrigem->pVerAnt,&ts); if(ts > 0 ){ while(ListaRet!=LIS_CondRetListaVazia) { LIS_ObterValor (pVertOrigem->pVerAnt , (void**)&pVerticeCaminho); ListaRetCaminho = LIS_IrInicioLista(pVerticeCaminho->pVerSuc); while(ListaRetCaminho==LIS_CondRetOK || ListaRetCaminho==LIS_CondRetFimLista){ LIS_ObterValor (pVerticeCaminho->pVerSuc , (void**)&pAres); if(pAres->pVerticeDest->pIdVertice == pVertOrigem->pIdVertice){ GRA_ExcluirAresta(pVerticeCaminho->pIdVertice , pVertOrigem->pIdVertice , pGrafo); } /* if */ if(ListaRetCaminho == LIS_CondRetFimLista){ break; } /* if */ ListaRetCaminho = LIS_AvancarElementoCorrente(pVerticeCaminho->pVerSuc, 1); } /* while */ ListaRet = LIS_ChecaOrigemNulo(pVertOrigem->pVerAnt); } /* while */ } /* if */ ListaRet = LIS_IrInicioLista(pVertOrigem->pVerSuc); ListaRet = LIS_CondRetOK ; LIS_NumElem(pVertOrigem->pVerSuc,&ts); if(ts > 0 ){ while(ListaRet!=LIS_CondRetListaVazia) { LIS_ObterValor (pVertOrigem->pVerSuc , (void**)&pAres); ListaRetCaminho = LIS_IrInicioLista((LIS_tppLista)pAres->pVerticeDest->pVerAnt); while(ListaRetCaminho==LIS_CondRetOK || ListaRetCaminho==LIS_CondRetFimLista){ LIS_ObterValor (pAres->pVerticeDest->pVerAnt , (void**)&pVerticeCaminho); if(pVerticeCaminho->pIdVertice == pVertOrigem->pIdVertice){ GRA_ExcluirAresta(pVertOrigem->pIdVertice , pAres->pVerticeDest->pIdVertice , pGrafo); break; } /* if */ if(ListaRetCaminho == LIS_CondRetFimLista){ break; } /* if */ ListaRetCaminho = LIS_AvancarElementoCorrente(pAres->pVerticeDest->pVerAnt, 1); } /* while */ ListaRet = LIS_ChecaOrigemNulo(pVertOrigem->pVerAnt); } /* while */ } /* if */ LIS_DestruirLista (pVertOrigem->pVerAnt); /* Destroi a lista de antecessores após eliminar as referencias */ LIS_DestruirLista (pVertOrigem->pVerSuc); /* Destroi a lista de antecessores após eliminar as referencias */ GRA_ExcluirdeVertices(pGrafo,pVertOrigem); /* Destroi a referência da lista de origens */ GRA_ExcluirdeOrigens(pGrafo,pVertOrigem); /* Destroi a referência da lista de vértices */ pGrafo->pCorrente->destruirValorV(pVertOrigem->pConteudo); ListaRet = LIS_IrInicioLista(pGrafo->pListaVertices); if(ListaRet == LIS_CondRetOK){ LIS_ObterValor(pGrafo->pListaVertices , (void**)&pVerticeCaminho); pGrafo->pCorrente = pVerticeCaminho; } free (pVertOrigem); pVertOrigem->pIdVertice = '\0'; pVertOrigem->pConteudo = NULL; pVertOrigem = NULL; return GRA_CondRetOK; }
/*********************************************************************** * * $FC Função: MEN ExcluirMenu * ***********************************************************************/ static void ExcluirMenu(void* menu) { LIS_tppLista l = ((MEN_tppMenu)menu)->opcoes; LIS_DestruirLista(l); free(menu); }
enum GRA_Ret GRA_NewNode (Graph *g, void *data) { Node *n; #ifdef _DEBUG Node *mirror; void *offset; #endif /* _DEBUG */ LIS_tppLista ln; CNT_CONTAR("GRA_NewNode - Inicio"); #ifdef _DEBUG AssertGraph(g); #endif /* _DEBUG */ /* Inicio do bloco de codigo com tratamento de excecao */ if (!data){ CNT_CONTAR("GRA_NewMode - Nao existe data a ser inserida"); return GRA_NullData; } CNT_CONTAR("GRA_NewMode - Alocao de no"); n = (Node *) malloc(sizeof(Node)); if (!n){ CNT_CONTAR("GRA_NewMode - Nao alocou no"); return GRA_MemoryError; } CNT_CONTAR("GRA_NewMode - Criando Lista"); ln = LIS_CriarLista(NULL); /* Para que ln possa se tornar heterogeneo, uso NULL */ if (!ln){ CNT_CONTAR("GRA_NewMode - Nao criou a Lista"); free (n); return GRA_MemoryError; } CNT_CONTAR("GRA_NewMode - Inserindo elemento apos"); if (LIS_CondRetOK != LIS_InserirElementoApos( ln, n )){ CNT_CONTAR("GRA_NewMode - Nao inseriu elemento apos"); free (n); LIS_DestruirLista( ln ); return GRA_MemoryError; } CNT_CONTAR("GRA_NewMode - Criando lista de Links"); n->links = LIS_CriarLista((FDelData) delLink ); if (!n->links){ CNT_CONTAR("GRA_NewMode - Nao criou lista de Links"); free (n); LIS_DestruirLista( ln ); return GRA_MemoryError; } CNT_CONTAR("GRA_NewMode - Inserindo no final da lista"); IrFinalLista( g->nodes ); if ( LIS_CondRetOK != LIS_InserirElementoApos( g->nodes , ln) ){ CNT_CONTAR("GRA_NewMode - Nao inseriu no final da lista"); LIS_DestruirLista( n->links ); free (n); LIS_DestruirLista( ln ); return GRA_MemoryError; } /* Fim do bloco de codigo com tratamento de excecao */ CNT_CONTAR("GRA_NewMode - Atribuicao, finalizacao"); n->data = data; n->delData = g->delData; g->currentNode = ln; #ifdef _DEBUG offset = malloc( 0x200 ); /* Apenas para que o proximo malloc esteja longe do dado replicado*/ mirror = (Node *) malloc(sizeof(Node)); free(offset); memcpy(mirror,n, sizeof(Node)); LIS_InserirElementoApos( ln, mirror ); IrInicioLista( ln ); g->nOfNodes++; AssertGraph(g); AssertNode(n,g); CNT_CONTAR("267 GRA_NewNode - Finalizacao"); #endif /* _DEBUG */ return GRA_Ok; }