-
Notifications
You must be signed in to change notification settings - Fork 1
/
Assertion.ipf
executable file
·380 lines (341 loc) · 9.78 KB
/
Assertion.ipf
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
#pragma rtGlobals=1 // Use modern global access method.
// Assertion -- a component of IgorUnit
// This data type represents a single assertion test
#ifndef IGORUNIT_ASSERTION
#define IGORUNIT_ASSERTION
// Assertion Status/Result Codes
Constant ASSERTION_UNKNOWN = 1
Constant ASSERTION_FAILURE = 2
Constant ASSERTION_SUCCESS = 3
Constant ASSERTION_IGNORETEST = 4
// Assertion Type Codes (ATC_*)
Constant ATC_ASSERT_UNKNOWN = 0
Constant ATC_ASSERT = 1
Constant ATC_EXPECT = 2
Constant ATC_ASSERT_TRUE = 3
Constant ATC_EXPECT_TRUE = 4
Constant ATC_ASSERT_FALSE = 5
Constant ATC_EXPECT_FALSE = 6
Constant ATC_ASSERT_EQ = 7
Constant ATC_EXPECT_EQ = 8
Constant ATC_ASSERT_NE = 9
Constant ATC_EXPECT_NE = 10
Constant ATC_ASSERT_LT = 11
Constant ATC_EXPECT_LT = 12
Constant ATC_ASSERT_LE = 13
Constant ATC_EXPECT_LE = 14
Constant ATC_ASSERT_GT = 15
Constant ATC_EXPECT_GT = 16
Constant ATC_ASSERT_GE = 17
Constant ATC_EXPECT_GE = 18
Constant ATC_ASSERT_EQ_C = 19
Constant ATC_EXPECT_EQ_C = 20
Constant ATC_ASSERT_NE_C = 21
Constant ATC_EXPECT_NE_C = 22
Constant ATC_ASSERT_STREQ = 23
Constant ATC_EXPECT_STREQ = 24
Constant ATC_ASSERT_STRNE = 25
Constant ATC_EXPECT_STRNE = 26
Constant ATC_ASSERT_STRCASEEQ = 27
Constant ATC_EXPECT_STRCASEEQ = 28
Constant ATC_ASSERT_STRCASENE = 29
Constant ATC_EXPECT_STRCASENE = 30
Constant ATC_SUCCEED = 31
Constant ATC_EXPECT_SUCCEED = 32
Constant ATC_FAIL = 33
Constant ATC_EXPECT_FAIL = 34
Constant ATC_IGNORE_TEST = 35
Structure Assertion
Variable assert_type
Variable result_code
String param_list
String stack_info
String message
String std_message
Variable test_idx
EndStructure
Function Assertion_init(a)
STRUCT Assertion &a
Assertion_set(a, ATC_ASSERT_UNKNOWN, "", "", "")
a.std_message = ""
a.result_code = ASSERTION_UNKNOWN
a.test_idx = -1
End
Function Assertion_set(a, assert_type, param_list, stack_info, message)
STRUCT Assertion &a
Variable assert_type
String param_list, stack_info, message
a.assert_type = assert_type
a.param_list = param_list
a.stack_info = stack_info
a.message = message
End
Function Assertion_initAuto(a)
STRUCT Assertion &a
String stack_info = Stack_getPartialNegativeIndex(1)
String assert_name = StackRow_getFunctionName(Stack_getLastRow(stack_info))
Assertion_init(a)
Assertion_setTypeName(a, assert_name)
Assertion_setStackInfo(a, stack_info)
End
Function Assertion_setResult(a, result_code)
STRUCT Assertion &a
Variable result_code
a.result_code = result_code
End
Function Assertion_setTestIndex(a, test_idx)
STRUCT Assertion &a
Variable test_idx
a.test_idx = test_idx
End
Function Assertion_setTest(a, test)
STRUCT Assertion &a
STRUCT UnitTest &test
a.test_idx = UnitTest_getIndex(test)
End
Function Assertion_setType(a, assert_type)
STRUCT Assertion &a
Variable assert_type
a.assert_type = assert_type
End
Function Assertion_setTypeName(a, assert_name)
STRUCT Assertion &a
String assert_name
a.assert_type = Assert_getTypeCode(assert_name)
End
Function Assertion_setStackInfo(a, stack_info)
STRUCT Assertion &a
String stack_info
a.stack_info = stack_info
End
Function Assertion_setMessage(a, message)
STRUCT Assertion &a
String message
a.message = message
End
Function Assertion_setStdMessage(a, message)
STRUCT Assertion &a
String message
a.std_message = message
End
Function Assertion_autosetStackInfo(a)
STRUCT Assertion &a
Assertion_setStackInfo(a, Stack_getPartialNegativeIndex(1))
End
Function Assertion_autosetType(a)
STRUCT Assertion &a
String stack_info = Stack_getPartialNegativeIndex(1)
String stack_row = Stack_getLastRow(stack_info)
Assertion_setTypeName(a, StackRow_getFunctionName(stack_row))
End
Function Assertion_setParams(a, param_list)
STRUCT Assertion &a
String param_list
a.param_list = param_list
End
Function Assertion_getType(a)
STRUCT Assertion &a
return a.assert_type
End
Function Assertion_getResult(a)
STRUCT Assertion &a
return a.result_code
End
Function/S Assertion_getParams(a)
STRUCT Assertion &a
return a.param_list
End
Function/S Assertion_getStack(a)
STRUCT Assertion &a
return a.stack_info
End
Function Assertion_getLineNumber(a)
STRUCT Assertion &a
String stack_info = Assertion_getStack(a)
Variable stack_len = Stack_getLength(stack_info)
String stack_row = Stack_getRow(stack_info, stack_len - 2)
return StackRow_getLineNumber(stack_row)
End
Function/S Assertion_getMessage(a)
STRUCT Assertion &a
return a.message
End
Function/S Assertion_getStdMessage(a)
STRUCT Assertion &a
return a.std_message
End
Function/S Assertion_getFullMessage(a)
STRUCT Assertion &a
String msg = Assertion_getMessage(a)
String std_msg = Assertion_getStdMessage(a)
String msg_out = msg
if (isStringExists(std_msg))
if (isStringExists(msg_out))
sprintf msg_out, "%s : %s", std_msg, msg_out
else
msg_out = std_msg
endif
endif
return msg_out
End
Function/S Assertion_getTypeName(a)
STRUCT Assertion &a
return Assert_getTypeName(Assertion_getType(a))
End
Function/S Assert_getTypeName(assert_type)
Variable assert_type
switch(assert_type)
case ATC_ASSERT:
return "ASSERT"
case ATC_EXPECT:
return "EXPECT"
case ATC_ASSERT_TRUE:
return "ASSERT_TRUE"
case ATC_EXPECT_TRUE:
return "EXPECT_TRUE"
case ATC_ASSERT_FALSE:
return "ASSERT_FALSE"
case ATC_EXPECT_FALSE:
return "EXPECT_FALSE"
case ATC_ASSERT_EQ:
return "ASSERT_EQ"
case ATC_EXPECT_EQ:
return "EXPECT_EQ"
case ATC_ASSERT_NE:
return "ASSERT_NE"
case ATC_EXPECT_NE:
return "EXPECT_NE"
case ATC_ASSERT_LT:
return "ASSERT_LT"
case ATC_EXPECT_LT:
return "EXPECT_LT"
case ATC_ASSERT_LE:
return "ASSERT_LE"
case ATC_EXPECT_LE:
return "EXPECT_LE"
case ATC_ASSERT_GT:
return "ASSERT_GT"
case ATC_EXPECT_GT:
return "EXPECT_GT"
case ATC_ASSERT_GE:
return "ASSERT_GE"
case ATC_EXPECT_GE:
return "EXPECT_GE"
case ATC_ASSERT_EQ_C:
return "ASSERT_EQ_C"
case ATC_EXPECT_EQ_C:
return "EXPECT_EQ_C"
case ATC_ASSERT_NE_C:
return "ASSERT_NE_C"
case ATC_EXPECT_NE_C:
return "EXPECT_NE_C"
case ATC_ASSERT_STREQ:
return "ASSERT_STREQ"
case ATC_EXPECT_STREQ:
return "EXPECT_STREQ"
case ATC_ASSERT_STRNE:
return "ASSERT_STRNE"
case ATC_EXPECT_STRNE:
return "EXPECT_STRNE"
case ATC_ASSERT_STRCASEEQ:
return "ASSERT_STRCASEEQ"
case ATC_EXPECT_STRCASEEQ:
return "EXPECT_STRCASEEQ"
case ATC_ASSERT_STRCASENE:
return "ASSERT_STRCASENE"
case ATC_EXPECT_STRCASENE:
return "EXPECT_STRCASENE"
case ATC_SUCCEED:
return "SUCCEED"
case ATC_EXPECT_SUCCEED:
return "EXPECT_SUCCEED"
case ATC_FAIL:
return "FAIL"
case ATC_EXPECT_FAIL:
return "EXPECT_FAIL"
case ATC_IGNORE_TEST:
return "IGNORE_TEST"
case ATC_ASSERT_UNKNOWN:
default:
return "UNKNOWN_ASSERT"
endswitch
End
Function Assert_getTypeCode(assert_name)
String assert_name
strswitch(assert_name)
case "ASSERT":
return ATC_ASSERT
case "EXPECT":
return ATC_EXPECT
case "ASSERT_TRUE":
return ATC_ASSERT_TRUE
case "EXPECT_TRUE":
return ATC_EXPECT_TRUE
case "ASSERT_FALSE":
return ATC_ASSERT_FALSE
case "EXPECT_FALSE":
return ATC_EXPECT_FALSE
case "ASSERT_EQ":
return ATC_ASSERT_EQ
case "EXPECT_EQ":
return ATC_EXPECT_EQ
case "ASSERT_NE":
return ATC_ASSERT_NE
case "EXPECT_NE":
return ATC_EXPECT_NE
case "ASSERT_LT":
return ATC_ASSERT_LT
case "EXPECT_LT":
return ATC_EXPECT_LT
case "ASSERT_LE":
return ATC_ASSERT_LE
case "EXPECT_LE":
return ATC_EXPECT_LE
case "ASSERT_GT":
return ATC_ASSERT_GT
case "EXPECT_GT":
return ATC_EXPECT_GT
case "ASSERT_GE":
return ATC_ASSERT_GE
case "EXPECT_GE":
return ATC_EXPECT_GE
case "ASSERT_EQ_C":
return ATC_ASSERT_EQ_C
case "EXPECT_EQ_C":
return ATC_EXPECT_EQ_C
case "ASSERT_NE_C":
return ATC_ASSERT_NE_C
case "EXPECT_NE_C":
return ATC_EXPECT_NE_C
case "ASSERT_STREQ":
return ATC_ASSERT_STREQ
case "EXPECT_STREQ":
return ATC_EXPECT_STREQ
case "ASSERT_STRNE":
return ATC_ASSERT_STRNE
case "EXPECT_STRNE":
return ATC_EXPECT_STRNE
case "ASSERT_STRCASEEQ":
return ATC_ASSERT_STRCASEEQ
case "EXPECT_STRCASEEQ":
return ATC_EXPECT_STRCASEEQ
case "ASSERT_STRCASENE":
return ATC_ASSERT_STRCASENE
case "EXPECT_STRCASENE":
return ATC_EXPECT_STRCASENE
case "SUCCEED":
return ATC_SUCCEED
case "EXPECT_SUCCEED":
return ATC_EXPECT_SUCCEED
case "FAIL":
return ATC_FAIL
case "EXPECT_FAIL":
return ATC_EXPECT_FAIL
case "IGNORE_TEST":
return ATC_IGNORE_TEST
case "ASSERT_UNKNOWN":
default:
return ATC_ASSERT_UNKNOWN
endswitch
End
#endif