-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestLIS.c
426 lines (300 loc) · 12.5 KB
/
TestLIS.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/***************************************************************************
* $MCI Módulo de implementação: TLIS Teste lista de símbolos
*
* Arquivo gerado: TestLIS.c
* Letras identificadoras: TLIS
*
* Nome da base de software: Arcabouço para a automação de testes de programas redigidos em C
* Arquivo da base de software: D:\AUTOTEST\PROJETOS\LISTA.BSW
*
* Projeto: INF 1301 / 1628 Automatização dos testes de módulos C
* Gestor: LES/DI/PUC-Rio
* Autores: avs
*
* $HA Histórico de evolução:
* Versão Autor Data Observações
* 4 avs 01/fev/2006 criar linguagem script simbólica
* 3 avs 08/dez/2004 uniformização dos exemplos
* 2 avs 07/jul/2003 unificação de todos os módulos em um só projeto
* 1 avs 16/abr/2003 início desenvolvimento
*
***************************************************************************/
#include <string.h>
#include <stdio.h>
#include <malloc.h>
#include "TST_Espc.h"
#include "Generico.h"
#include "LerParm.h"
#include "Lista.h"
static const char RESET_LISTA_CMD [ ] = "=resetteste" ;
static const char CRIAR_LISTA_CMD [ ] = "=criarlista" ;
static const char DESTRUIR_LISTA_CMD [ ] = "=destruirlista" ;
static const char ESVAZIAR_LISTA_CMD [ ] = "=esvaziarlista" ;
static const char INS_ELEM_ANTES_CMD [ ] = "=inselemantes" ;
static const char INS_ELEM_APOS_CMD [ ] = "=inselemapos" ;
static const char OBTER_VALOR_CMD [ ] = "=obtervalorelem" ;
static const char EXC_ELEM_CMD [ ] = "=excluirelem" ;
static const char IR_INICIO_CMD [ ] = "=irinicio" ;
static const char IR_FIM_CMD [ ] = "=irfinal" ;
static const char AVANCAR_ELEM_CMD [ ] = "=avancarelem" ;
#define TRUE 1
#define FALSE 0
#define VAZIO 0
#define NAO_VAZIO 1
#define DIM_VT_LISTA 10
#define DIM_VALOR 100
LIS_tppLista vtListas[ DIM_VT_LISTA ] ;
/***** Protótipos das funções encapuladas no módulo *****/
static void DestruirValor( void * pValor ) ;
static int ValidarInxLista( int inxLista , int Modo ) ;
/***** Código das funções exportadas pelo módulo *****/
/***********************************************************************
*
* $FC Função: TLIS &Testar lista
*
* $ED Descrição da função
* Podem ser criadas até 10 listas, identificadas pelos índices 0 a 10
*
* Comandos disponíveis:
*
* =resetteste
* - anula o vetor de listas. Provoca vazamento de memória
* =criarlista inxLista
* =destruirlista inxLista
* =esvaziarlista inxLista
* =inselemantes inxLista string CondRetEsp
* =inselemapos inxLista string CondRetEsp
* =obtervalorelem inxLista string CondretPonteiro
* =excluirelem inxLista CondRetEsp
* =irinicio inxLista
* =irfinal inxLista
* =avancarelem inxLista numElem CondRetEsp
*
***********************************************************************/
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 */
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 */
/***** Código das funções encapsuladas no módulo *****/
/***********************************************************************
*
* $FC Função: TLIS -Destruir valor
*
***********************************************************************/
void DestruirValor( void * pValor )
{
free( pValor ) ;
} /* Fim função: TLIS -Destruir valor */
/***********************************************************************
*
* $FC Função: TLIS -Validar indice de lista
*
***********************************************************************/
int ValidarInxLista( int inxLista , int Modo )
{
if ( ( inxLista < 0 )
|| ( inxLista >= DIM_VT_LISTA ))
{
return FALSE ;
} /* if */
if ( Modo == VAZIO )
{
if ( vtListas[ inxLista ] != 0 )
{
return FALSE ;
} /* if */
} else
{
if ( vtListas[ inxLista ] == 0 )
{
return FALSE ;
} /* if */
} /* if */
return TRUE ;
} /* Fim função: TLIS -Validar indice de lista */
/********** Fim do módulo de implementação: TLIS Teste lista de símbolos **********/