~libpspio-developers/libpspio/trunk

« back to all changes in this revision

Viewing changes to fortran/src/tests/m_error_test.F90

  • Committer: Yann Pouillon (Rigel)
  • Date: 2016-06-08 18:58:01 UTC
  • mfrom: (422.1.22 pouillon)
  • Revision ID: yann.pouillon@ehu.es-20160608185801-5zcczzn0igqpu1io
MergedĀ pouillon/444

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
contains
30
30
 
31
 
  subroutine test_error_add()
 
31
  subroutine test_error_empty()
 
32
 
 
33
    implicit none
 
34
 
 
35
    character(len=1), parameter :: noroutine = " "
 
36
 
 
37
    call fpspio_error_free()
 
38
 
 
39
    call assert_equals(0, fpspio_error_len(), "Empty error chain length")
 
40
    call assert_equals(PSPIO_SUCCESS, fpspio_error_get_last(noroutine), &
 
41
&     "Empty error chain last code")
 
42
 
 
43
  end subroutine test_error_empty
 
44
 
 
45
  subroutine test_error_fetchall()
32
46
 
33
47
    implicit none
34
48
 
35
49
    character(len=*), parameter :: err_file = "test_1_1.F90"
36
50
    character(len=*), parameter :: err_func = "dummy1"
37
 
    integer, parameter :: err_refcode = PSPIO_EVALUE
38
 
 
39
 
    integer :: err_code
40
 
 
41
 
    err_code = &
42
 
&     fpspio_error_add(err_refcode, err_file, 1234, err_func)
43
 
 
44
 
    call assert_equals(err_refcode, err_code, "Add EVALUE error")
45
 
 
46
 
  end subroutine test_error_add
47
 
 
48
 
  subroutine test_error_fetchall()
49
 
 
50
 
    implicit none
51
 
 
52
51
    character(len=1), parameter :: ch10 = achar(10)
53
52
    character(len=*), parameter :: err_refmsg = &
54
53
&     "libpspio: ERROR:" // ch10 // "  * in test_1_1.F90(dummy1):1234:" &
55
54
&     // ch10 // "      value error: bad value found (PSPIO_EVALUE)" // ch10
 
55
    integer, parameter :: err_refcode = PSPIO_EVALUE
 
56
 
56
57
    character(len=PSPIO_STRLEN_ERROR) :: err_msg
 
58
    integer :: err_code
57
59
 
 
60
    call fpspio_error_free()
 
61
    err_code = &
 
62
&     fpspio_error_add(err_refcode, err_file, 1234, err_func)
58
63
    err_msg = fpspio_error_fetchall()
 
64
 
59
65
    call assert_equals(err_refmsg, err_msg, "Retrieve EVALUE error message")
60
66
 
61
67
  end subroutine test_error_fetchall
62
68
 
 
69
  subroutine test_error_get_last()
 
70
 
 
71
    implicit none
 
72
 
 
73
    character(len=*), parameter :: err_file1 = "test_4_1.F90"
 
74
    character(len=*), parameter :: err_file2 = "test_4_2.F90"
 
75
    character(len=*), parameter :: err_file3 = "test_4_3.F90"
 
76
    character(len=*), parameter :: err_func1 = "dummy41"
 
77
    character(len=*), parameter :: err_func2 = "dummy42"
 
78
    character(len=*), parameter :: err_func3 = "dummy43"
 
79
    character(len=*), parameter :: err_func4 = "dummy44"
 
80
    integer, parameter :: err_line1 = 411
 
81
    integer, parameter :: err_line2 = 422
 
82
    integer, parameter :: err_line3 = 433
 
83
    integer, parameter :: err_refcode1 = PSPIO_EGSL
 
84
    integer, parameter :: err_refcode2 = PSPIO_ENOFILE
 
85
    integer, parameter :: err_refcode3 = PSPIO_ERROR
 
86
 
 
87
    integer :: err_code1, err_code2, err_code3
 
88
 
 
89
    call fpspio_error_free()
 
90
    err_code1 = &
 
91
&     fpspio_error_add(err_refcode1, err_file1, err_line1, err_func1)
 
92
    err_code2 = &
 
93
&     fpspio_error_add(err_refcode2, err_file2, err_line2, err_func2)
 
94
    err_code3 = &
 
95
&     fpspio_error_add(err_refcode3, err_file3, err_line3, err_func3)
 
96
 
 
97
    call assert_equals(3, fpspio_error_len(), &
 
98
&     "Last error - Chain length")
 
99
    call assert_equals(err_refcode1, err_code1, "Last error - Insertion 1")
 
100
    call assert_equals(err_refcode2, err_code2, "Last error - Insertion 2")
 
101
    call assert_equals(err_refcode3, err_code3, "Last error - Insertion 3")
 
102
    call assert_equals(err_refcode1, &
 
103
&     fpspio_error_get_last(err_func1), "Last error - Function 1")
 
104
    call assert_equals(err_refcode2, &
 
105
&     fpspio_error_get_last(err_func2), "Last error - Function 2")
 
106
    call assert_equals(err_refcode3, &
 
107
&     fpspio_error_get_last(err_func3), "Last error - Function 3")
 
108
    call assert_equals(PSPIO_SUCCESS, &
 
109
&     fpspio_error_get_last(err_func4), "Last error - Unknown function")
 
110
 
 
111
  end subroutine test_error_get_last
 
112
 
 
113
  subroutine test_error_single()
 
114
 
 
115
    implicit none
 
116
 
 
117
    character(len=*), parameter :: err_file1 = "test_1_1.F90"
 
118
    character(len=*), parameter :: err_func1 = "dummy1"
 
119
    integer, parameter :: err_line1 = 1234
 
120
    integer, parameter :: err_refcode1 = PSPIO_EVALUE
 
121
 
 
122
    integer :: err_code1
 
123
 
 
124
    call fpspio_error_free()
 
125
    err_code1 = &
 
126
&     fpspio_error_add(err_refcode1, err_file1, err_line1, err_func1)
 
127
 
 
128
    call assert_equals(1, fpspio_error_len(), &
 
129
&     "Single error - Chain length")
 
130
    call assert_equals(err_refcode1, err_code1, "Single error - Insertion")
 
131
    call assert_equals(err_refcode1, fpspio_error_get_last(err_func1), &
 
132
&     "Single error - Function last code")
 
133
 
 
134
  end subroutine test_error_single
 
135
 
 
136
  subroutine test_error_double()
 
137
 
 
138
    implicit none
 
139
 
 
140
    character(len=*), parameter :: err_file1 = "test_2_1.F90"
 
141
    character(len=*), parameter :: err_file2 = "test_2_2.F90"
 
142
    character(len=*), parameter :: err_func1 = "dummy21"
 
143
    character(len=*), parameter :: err_func2 = "dummy22"
 
144
    integer, parameter :: err_line1 = 1234
 
145
    integer, parameter :: err_line2 = 202
 
146
    integer, parameter :: err_refcode1 = PSPIO_EGSL
 
147
    integer, parameter :: err_refcode2 = PSPIO_ENOSUPPORT
 
148
 
 
149
    integer :: err_code1, err_code2
 
150
 
 
151
    call fpspio_error_free()
 
152
    err_code1 = &
 
153
&     fpspio_error_add(err_refcode1, err_file1, err_line1, err_func1)
 
154
    err_code2 = &
 
155
&     fpspio_error_add(err_refcode2, err_file2, err_line2, err_func2)
 
156
 
 
157
    call assert_equals(2, fpspio_error_len(), &
 
158
&     "Double error - Chain length")
 
159
    call assert_equals(err_refcode1, err_code1, "Double error - Insertion 1")
 
160
    call assert_equals(err_refcode1, &
 
161
&     fpspio_error_get_last(err_func1), "Double error - Function 1")
 
162
    call assert_equals(err_refcode2, err_code2, "Double error - Insertion 2")
 
163
    call assert_equals(err_refcode2, &
 
164
&     fpspio_error_get_last(err_func2), "Double error - Function 2")
 
165
 
 
166
  end subroutine test_error_double
 
167
 
 
168
  subroutine test_error_triple()
 
169
 
 
170
    implicit none
 
171
 
 
172
    character(len=*), parameter :: err_file1 = "test_3_1.F90"
 
173
    character(len=*), parameter :: err_file2 = "test_3_2.F90"
 
174
    character(len=*), parameter :: err_file3 = "test_3_3.F90"
 
175
    character(len=*), parameter :: err_func1 = "dummy31"
 
176
    character(len=*), parameter :: err_func2 = "dummy32"
 
177
    character(len=*), parameter :: err_func3 = "dummy33"
 
178
    integer, parameter :: err_line1 = 311
 
179
    integer, parameter :: err_line2 = 322
 
180
    integer, parameter :: err_line3 = 333
 
181
    integer, parameter :: err_refcode1 = PSPIO_EVALUE
 
182
    integer, parameter :: err_refcode2 = PSPIO_ENOFILE
 
183
    integer, parameter :: err_refcode3 = PSPIO_ERROR
 
184
 
 
185
    integer :: err_code1, err_code2, err_code3
 
186
 
 
187
    call fpspio_error_free()
 
188
    err_code1 = &
 
189
&     fpspio_error_add(err_refcode1, err_file1, err_line1, err_func1)
 
190
    err_code2 = &
 
191
&     fpspio_error_add(err_refcode2, err_file2, err_line2, err_func2)
 
192
    err_code3 = &
 
193
&     fpspio_error_add(err_refcode3, err_file3, err_line3, err_func3)
 
194
 
 
195
    call assert_equals(3, fpspio_error_len(), &
 
196
&     "Triple error - Chain length")
 
197
    call assert_equals(err_refcode1, err_code1, "Triple error - Insertion 1")
 
198
    call assert_equals(err_refcode1, &
 
199
&     fpspio_error_get_last(err_func1), "Triple error - Function 1")
 
200
    call assert_equals(err_refcode2, err_code2, "Triple error - Insertion 2")
 
201
    call assert_equals(err_refcode2, &
 
202
&     fpspio_error_get_last(err_func2), "Triple error - Function 2")
 
203
    call assert_equals(err_refcode3, err_code3, "Triple error - Insertion 3")
 
204
    call assert_equals(err_refcode3, &
 
205
&     fpspio_error_get_last(err_func3), "Triple error - Function 3")
 
206
 
 
207
  end subroutine test_error_triple
 
208
 
63
209
end module m_error_test