PIL_tpCondRet PIL_VerCarta( PIL_tppPilha pPilha , CAR_tppCarta * pCarta , int posicao ) { LIS_tpCondRet Ret ; *pCarta = NULL ; if ( posicao < 0 ) { return PIL_CondRetParamIncorreto ; } LIS_IrFinalLista( pPilha->pListaCartas ) ; Ret = LIS_AvancarElementoCorrente( pPilha->pListaCartas , - posicao ) ; if ( Ret == LIS_CondRetFimLista ) { return PIL_CondRetFimPilha ; } if ( Ret == LIS_CondRetListaVazia ) { return PIL_CondRetPilhaVazia ; } LIS_ObterValor( pPilha->pListaCartas , pCarta ) ; return PIL_CondRetOK ; }/* Fim função: PIL VerCarta */
/*************************************************************************** * * Função: TAB &Imprimir estado atual de um tabuleiro * ****/ void TAB_imprimir(Tabuleiro *tabuleiro) { int x, y; //Assertivas de entrada #ifdef _DEBUG if(tabuleiro == NULL) printf("\n Não foi possível imprimir o tabuleiro (não existe) \n"); #endif LIS_IrFinalLista(tabuleiro->lista); for(y = TabuleiroAltura - 1; y >= 0; --y) { LIS_tppLista lista; printf("%d|", y+1); lista = (LIS_tppLista)LIS_ObterValor(tabuleiro->lista); LIS_IrInicioLista(lista); for(x = 0; x < TabuleiroLargura; ++x) { Peca *peca = LIS_ObterValor(lista); if(peca) PEC_imprimir(peca); else printf(" |"); LIS_AvancarElementoCorrente(lista, 1); } printf("\n"); LIS_AvancarElementoCorrente(tabuleiro->lista, -1); } printf(" |A|B|C|D|E|F|G|H|\n"); }/* Fim função: TAB &Imprimir estado atual de um tabuleiro */
CPC_tpCondRet CPC_AdicionarMovimento( CPC_tppClassePeca pClassePeca , int movI , int movJ ) { CPC_tpMovimento * movimento; int resp; if(pClassePeca == NULL) { return CPC_CondRetPonteiroNulo; } CPC_ChecarMovimento(pClassePeca, movI, movJ, &resp); if(resp == 1) { return CPC_CondRetArgumentosInvalidos; } movimento = (CPC_tpMovimento*)malloc(sizeof(CPC_tpMovimento)); if(movimento == NULL) { return CPC_CondRetFaltouMemoria; } movimento->movI = movI; movimento->movJ = movJ; LIS_IrFinalLista(pClassePeca->movimentos); if( LIS_InserirElementoApos(pClassePeca->movimentos, movimento) == LIS_CondRetFaltouMemoria ) { return CPC_CondRetFaltouMemoria; } return CPC_CondRetOK; }
int FIL_insereElem (FIL_tppFila fila,void* pValor) { if(fila->capacidade==LIS_ObtemNumElementos(fila->lista)) { printf("\nFila cheia!"); return 0; } LIS_IrFinalLista( fila->lista ) ; LIS_InserirElementoApos(fila->lista,pValor); return 1; }
/***** Código das funções encapsuladas no módulo *****/ LIS_tppLista criarListaAPartirDeString( char * str ){ int i, len = strlen(str); LIS_tppLista lista = LIS_CriarLista(); for( i = 0 ; i <= len ; i++) { LIS_InserirElementoApos( lista, str[i] ); LIS_IrFinalLista( lista ); } return lista; }
PIL_tpCondRet PIL_PushCarta( PIL_tppPilha pPilha , CAR_tppCarta pCarta ) { LIS_tpCondRet Ret ; LIS_IrFinalLista( pPilha->pListaCartas ) ; Ret = LIS_InserirElementoApos( pPilha->pListaCartas , pCarta ) ; if( Ret != LIS_CondRetOK ) { return PIL_CondRetFaltouMemoria ; } /* if */ return PIL_CondRetOK ; }/* Fim função: PIL Push Carta */
/*************************************************************************** * * Função: TAB &mover uma peça no tabuleiro * ****/ int TAB_verificaVencedor(Tabuleiro *tabuleiro, char idJogador1, char idJogador2) { int x, y; int existe1 = 0, existe2 = 0; //Assertivas de entrada #ifdef _DEBUG if(!tabuleiro) printf("\n tabuleiro não existe \n"); if(idJogador1 != 'x' || idJogador2 != 'o') printf("\n Erro na associação de caracteres correspondentes ao jogador1 e/ou jogador2 \n"); #endif LIS_IrFinalLista(tabuleiro->lista); for(y = TabuleiroAltura - 1; y >= 0; --y) { LIS_tppLista lista = (LIS_tppLista)LIS_ObterValor(tabuleiro->lista); LIS_IrInicioLista(lista); for(x = 0; x < TabuleiroLargura; ++x) { Peca *peca = LIS_ObterValor(lista); if(peca) { if(PEC_obterCaracter(peca) == idJogador1) existe1 = 1; else if(PEC_obterCaracter(peca) == idJogador2) existe2 = 1; if(existe1 && existe2) // existe peca dos 2 jogadores no tabuleiro. jogo continua return -1; } LIS_AvancarElementoCorrente(lista, 1); } LIS_AvancarElementoCorrente(tabuleiro->lista, -1); } if(existe1 && !existe2) // so ha pecas do jogador 1 presentes. ele ganhou return 0; if(!existe1 && existe2) // so ha pecas do jogador 2 presentes. ele ganhou return 1; //Assertivas de saida #ifdef _DEBUG printf("Caso indefinido em TAB_verificaVencedor"); #endif return -2; }/* Fim função: TAB verifica vencedor */
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 */
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 */
TST_tpCondRet TST_EfetuarComando( char * ComandoTeste ) { int inxLista = -1 , numLidos = -1 , CondRetEsp = -1 ; TST_tpCondRet CondRet ; char StringDado[ DIM_VALOR ] ; char * pDado ; 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 ) { 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 */ LIS_IrInicioLista( vtListas[ inxLista ] ) ; return TST_CondRetOK ; } /* fim ativa: Testar ir para o elemento inicial */ /* LIS &Ir para o elemento final */ else if ( strcmp( ComandoTeste , IR_FIM_CMD ) == 0 ) { numLidos = LER_LerParametros( "i" , &inxLista ) ; if ( ( numLidos != 1 ) || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) ) { return TST_CondRetParm ; } /* if */ LIS_IrFinalLista( vtListas[ inxLista ] ) ; return TST_CondRetOK ; } /* fim ativa: LIS &Ir para o elemento final */ /* LIS &Avançar elemento */ else if ( strcmp( ComandoTeste , AVANCAR_ELEM_CMD ) == 0 ) { numLidos = LER_LerParametros( "iii" , &inxLista , &numElem , &CondRetEsp ) ; if ( ( numLidos != 3 ) || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) ) { return TST_CondRetParm ; } /* if */ return TST_CompararInt( CondRetEsp , LIS_AvancarElementoCorrente( vtListas[ inxLista ] , numElem ) , "Condicao de retorno errada ao avancar" ) ; } /* fim ativa: LIS &Avançar elemento */ return TST_CondRetNaoConhec ; } /* Fim função: TLIS &Testar lista */