forked from raulvfp/catchException
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_catchException.prg
More file actions
114 lines (96 loc) · 4.17 KB
/
Copy pathtest_catchException.prg
File metadata and controls
114 lines (96 loc) · 4.17 KB
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
*/
* @since: 1.0
*
* @author: Raúl Juárez <raul.jrz@gmail.com>
* @date: 2018.05.15;21.00
*/
DEFINE CLASS test_catchException as FxuTestCase OF FxuTestCase.prg
*----------------------------------------------------------------------
#IF .f.
LOCAL THIS AS test_catchException OF test_catchException.PRG
#ENDIF
oObject = '' &&Este es el objecto que va a ser evaluado
oldPath = ''
oldProcedure = ''
oldDefault = ''
*--------------------------------------------------------------------
FUNCTION Setup
* Configuración base de todos los Test de esta clase
*--------------------------------------------------------------------
*SET PATH TO E:\Shared\Project\librery\catchException
THIS.oldPath =SET('PATH')
THIS.oldProcedure=SET('PROCEDURE')
THIS.oldDefault =SET('DEFAULT')
*THIS.MessageOut('Procedures: '+SET("PROCEDURE"))
*THIS.MessageOut('Path......: '+SET("PATH"))
*THIS.MessageOut('Default...: '+SET("DEFAULT"))
*THIS.MessageOut('============================================================')
SET PROCEDURE TO (ADDBS(SYS(5)+CURDIR())+'src\catchException.prg') ADDITIVE
SET PATH TO (THIS.oldPath +";"+ADDBS(SYS(5)+CURDIR())+'src ')
THIS.MessageOut('Procedures: '+STRTRAN(SET("PROCEDURE"),";",CHR(13)+SPACE(12)))
THIS.MessageOut('Path......: '+STRTRAN(SET("PATH"),";",CHR(13)+SPACE(12)))
THIS.MessageOut('Default...: '+SET("DEFAULT"))
THIS.MessageOut('============================================================')
THIS.MessageOut('')
*THIS.oObject = CREATEOBJECT('catchException')
ENDFUNC
*---------------------------------------------------------------------
FUNCTION testCatch_Exception()
* Verifica que se lance el objeto que controla la excepcion
*---------------------------------------------------------------------
TRY
*--- Este es una excepcion y que lanza el CATCH para controlarla
lnStatus = lcNoExisteLaVariable
CATCH TO loEx
loTmp = CREATEOBJECT('catchException', .F.)
THIS.MessageOut('Esto me indica si es un error o algo generador por el programador: ' +loEx.Message)
THIS.MessageOut('Valor de userValue: '+loEx.UserValue)
ENDTRY
THIS.AssertNotNull('No existe el objecto',loEx)
ENDFUNC
*--------------------------------------------------------------------
FUNCTION TearDown
* Restaura el estado anterior del ambiente de desarrollo
*--------------------------------------------------------------------
SET PATH TO (THIS.oldPath)
SET PROCEDURE TO (THIS.oldProcedure)
SET DEFAULT TO (THIS.oldDefault)
ENDFUNC
*--------------------------------------------------------------------
FUNCTION test_GenerounExecptionThrow
* Note: Pruebo la generacion de Exceptiones con THROW
*--------------------------------------------------------------------
LOCAL lcExpectedValue, lcFileLog
lcExpectedValue = 'My_Exception'
lcFileLog = 'error.log' && Es el archivo de salida con el log de la Exception
IF FILE(lcFileLog) THEN
DELETE FILE (lcFileLog)
ENDIF
TRY
*--- Este es una excepcion generada con THROW
THROW lcExpectedValue
CATCH TO loEx
loTmp = CREATEOBJECT('catchException', .F.)
THIS.MessageOut('Esto me indica si es un error o algo generador por el programador: ' +loEx.Message)
THIS.MessageOut('Valor de userValue: '+loEx.UserValue)
ENDTRY
THIS.AssertNotNull('No existe el objecto',loEx)
THIS.AssertEquals(lcExpectedValue, loEx.UserValue, 'ERROR, se experaba otro valor')
THIS.AssertTrue(FILE(lcFileLog), 'Error, no se encontro el archivo log: '+lcFileLog)
ENDFUNC
ENDDEFINE
*----------------------------------------------------------------------
* The three base class methods to call from your test methods are:
*
* THIS.AssertTrue (<Expression>, "Failure message")
* THIS.AssertEquals (<ExpectedValue>, <Expression>, "Failure message")
* THIS.AssertNotNull (<Expression>, "Failure message")
* THIS.MessageOut (<Expression>)
*
* Test methods (through their assertions) either pass or fail.
*----------------------------------------------------------------------
* AssertNotNullOrEmpty() example.
*------------------------------
*FUNCTION TestObjectWasCreated
* THIS.AssertNotNullOrEmpty(THIS.oObjectToBeTested, "Test Object was not created")
*ENDFUNC