Commit | Line | Data |
---|---|---|
970ed795 | 1 | /****************************************************************************** |
3abe9331 | 2 | * Copyright (c) 2000-2015 Ericsson Telecom AB |
970ed795 EL |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | ******************************************************************************/ | |
8 | module tryCatch_Testcases { | |
9 | ||
10 | import from tryCatch_Functions all; | |
11 | ||
12 | external function throw(in charstring msg); | |
13 | ||
14 | type port MyInternal_PT message { | |
15 | inout charstring; | |
16 | } with { extension "internal"} | |
17 | ||
18 | ||
19 | type port PCOType message | |
20 | { | |
21 | inout charstring; | |
22 | } | |
23 | ||
24 | type component MyComp { | |
25 | port MyInternal_PT PCO; | |
26 | port PCOType ExternalPCO; | |
27 | var integer v_funcCallCounter; //for lazy | |
28 | } | |
29 | ||
30 | type record of integer RoI; | |
31 | ||
32 | const RoI c_roi3:={1,2,3} | |
33 | ||
34 | //Based on funtion_test :) | |
35 | type union UnionType1{ | |
36 | UnionType2 girl, | |
37 | integer numero | |
38 | } | |
39 | ||
40 | type union UnionType2{ | |
41 | Emma emma, | |
42 | Eszter eszter | |
43 | } | |
44 | ||
45 | type record Emma { charstring name} | |
46 | type record Eszter { charstring name} | |
47 | ||
48 | ||
49 | ||
50 | //This template cannot be sent: | |
51 | template charstring tr_recv := pattern "*"; | |
52 | ||
53 | //This template can be sent: | |
54 | template charstring t_send := "This is the message"; | |
55 | ||
56 | //******* Types *************** | |
57 | type integer MySmallInt(1..10); | |
58 | //******* Constants *********** | |
59 | ||
60 | //******* Functions *********** | |
61 | ||
62 | function f_divByZero() { | |
63 | var integer i :=10, j:=0; | |
64 | @try { | |
65 | i:=i/j | |
66 | } | |
67 | @catch(dte_str){ | |
68 | setverdict(pass); | |
69 | stop; | |
70 | } | |
71 | setverdict(fail); //never reach this line | |
72 | } | |
73 | ||
74 | function f_setverdict_str(in charstring pl_str, in template charstring pl_expected) { | |
75 | if(match(pl_str,pl_expected)) { | |
76 | setverdict(pass) | |
77 | } else { | |
78 | setverdict(fail, match(pl_str,pl_expected)); | |
79 | } | |
80 | } with { extension "transparent" } | |
81 | ||
82 | ||
83 | function f_tryCatch_conv() runs on MyComp { | |
84 | var charstring vl_ch1:="H" , vl_ch2:="E"; | |
85 | @try{ | |
86 | var hexstring vl_h:=str2hex(vl_ch1&vl_ch2); | |
87 | } | |
88 | @catch(e){ | |
89 | if(match(e, pattern "*The argument of function str2hex\(\) shall contain hexadecimal digits only,*")) | |
90 | { setverdict(pass) } else {setverdict(fail)}; | |
91 | } | |
92 | ||
93 | //normal case: | |
94 | vl_ch1:=vl_ch2&vl_ch2 | |
95 | @try{ | |
96 | var hexstring vl_h:= str2hex(vl_ch1); | |
97 | setverdict(pass); | |
98 | } | |
99 | @catch(e) { | |
100 | setverdict(fail,"exception for normal value"); | |
101 | } | |
102 | } | |
103 | ||
104 | function f_tryCatch_conv_imported() runs on MyComp { | |
105 | var charstring vl_ch1:="H" , vl_ch2:="E"; | |
106 | template charstring tl_expected := | |
107 | pattern "*The argument of function str2hex\(\) shall contain hexadecimal digits only,*"; | |
108 | @try{ | |
109 | var hexstring vl_h:=str2hex(vl_ch1&vl_ch2); | |
110 | } | |
111 | @catch(e){ | |
112 | f_matchAndVerdict(e,tl_expected); //imported function | |
113 | } | |
114 | } | |
115 | ||
116 | function f_tryCatch_conv_throw() runs on MyComp { | |
117 | var charstring vl_ch1:="H" , vl_ch2:="E"; | |
118 | @try{ | |
119 | var hexstring vl_h:=str2hex(vl_ch1&vl_ch2); | |
120 | } | |
121 | @catch(e){ | |
122 | throw(e); | |
123 | } | |
124 | } | |
125 | ||
126 | altstep as_tryCatch_conv() runs on MyComp { | |
127 | [] PCO.receive {setverdict(pass);} | |
128 | [else] { | |
129 | log("altstep reached the else-branch"); | |
130 | var charstring vl_ch1:="H" , vl_ch2:="E"; | |
131 | @try{ | |
132 | var hexstring vl_h:=str2hex(vl_ch1&vl_ch2); | |
133 | setverdict(fail, "Catched DTE didn't stopped the running"); | |
134 | } | |
135 | @catch(e){ | |
136 | log("Catched DTE:",e); | |
137 | setverdict(pass); | |
138 | ||
139 | } | |
140 | } | |
141 | } | |
142 | ||
143 | ||
144 | function f_behavior_sending(in template charstring pl_msg) runs on MyComp { | |
145 | @try { | |
146 | PCO.send(pl_msg); | |
147 | if(isvalue(pl_msg) ) { | |
148 | setverdict(pass, "no exception for sending real value template[sending template]") | |
149 | } else { | |
150 | setverdict(fail, "no exception for sending not real value template"); | |
151 | } | |
152 | } | |
153 | @catch(e) { | |
154 | if( match(e, pattern "*Port PCO has neither connections nor mappings. Message cannot be sent on it.*")) | |
155 | { | |
156 | setverdict(pass); | |
157 | } else { | |
158 | log("Catched error msg:", e); | |
159 | if( isvalue(pl_msg) ) { setverdict(fail, "exception for sending real value");} | |
160 | f_setverdict_str(e, pattern "*Performing valueof or send operation on a non-specific charstring template."); | |
161 | @try { | |
162 | PCO.send("Default msg"); | |
163 | } | |
164 | @catch(f) { | |
165 | log("Catched DTE:",f); | |
166 | } | |
167 | } | |
168 | } | |
169 | // side-effect???? : | |
170 | @try { | |
171 | var charstring vl_msg:= valueof(pl_msg); | |
172 | } | |
173 | @catch(e) { | |
174 | log("Catched DTE:",e); | |
175 | f_setverdict_str(e, pattern "*Performing valueof or send operation on a non-specific charstring template."); | |
176 | ||
177 | if(isvalue(pl_msg) ) { | |
178 | setverdict(fail, "exception for valueof(real value template)"); | |
179 | } else { | |
180 | setverdict(pass, "exception for valueof( not real value template[receiving template])"); | |
181 | } | |
182 | } | |
183 | } | |
184 | ||
185 | modulepar integer tsp_counterLimit := 10000 | |
186 | function f_behavior_sendingInfinite(in template charstring pl_msg) runs on MyComp { | |
187 | var integer vl_counter:=0; | |
188 | while(vl_counter < tsp_counterLimit) { | |
189 | @try { | |
190 | PCO.send(valueof(pl_msg)&int2str(vl_counter)); | |
191 | } | |
192 | @catch(e) { | |
193 | log("Catched DTE:",e); | |
194 | break; | |
195 | } | |
196 | vl_counter:=vl_counter+1; | |
197 | ||
198 | if ( (vl_counter mod 10000) ==0) { log(">>>Counter:",vl_counter); } | |
199 | } | |
200 | log("Bye"); | |
201 | } | |
202 | ||
203 | ||
204 | function f_behavior_receiving(in template charstring pl_expected) runs on MyComp { | |
205 | timer T := 2.0; | |
206 | T.start; | |
207 | alt { | |
208 | [] PCO.receive { log("msg received"); setverdict(pass) }; | |
209 | [] T.timeout { setverdict(none, "timeout"); } | |
210 | } | |
211 | } | |
212 | ||
213 | function f_behavior_notReceiving(in template charstring pl_expected) runs on MyComp { | |
214 | timer T := 10.0; | |
215 | T.start; | |
216 | alt { | |
217 | //[] PCO.receive { log("msg received"); setverdict(pass) }; | |
218 | [] T.timeout { setverdict(none, "timeout"); } | |
219 | } | |
220 | } | |
221 | ||
222 | //sending on external port (i.e not internal port) | |
223 | function f_behavior_externalSending(in template charstring pl_msg) runs on MyComp { | |
224 | @try { | |
225 | ExternalPCO.send(pl_msg); | |
226 | if(isvalue(pl_msg) ) { | |
227 | setverdict(pass, "no exception for sending real value template[sending template]") | |
228 | } else { | |
229 | setverdict(fail, "no exception for sending not real value template"); | |
230 | } | |
231 | } | |
232 | @catch(e) { | |
233 | log("Catched DTE:",e); | |
234 | if( match(e, pattern "*Port PCO has neither connections nor mappings. Message cannot be sent on it.*")) | |
235 | { | |
236 | setverdict(pass); | |
237 | } else { | |
238 | if( isvalue(pl_msg) ) { | |
239 | setverdict(fail, "exception for sending real value"); | |
240 | } else { | |
241 | setverdict(pass, "exception for sending not real value"); | |
242 | } | |
243 | } | |
244 | } | |
245 | } | |
246 | ||
247 | function f_behavior_externalReceiving(in template charstring pl_expected) runs on MyComp { | |
248 | timer T := 10.0; | |
249 | T.start; | |
250 | alt { | |
251 | [] PCO.receive { log("msg received"); setverdict(pass) }; | |
252 | [] T.timeout { setverdict(none, "timeout"); } | |
253 | } | |
254 | } | |
255 | ||
256 | function f_valueof(in template charstring pl_msg) runs on MyComp { | |
257 | @try { | |
258 | var charstring vl_msg:= valueof(pl_msg); | |
259 | if(isvalue(pl_msg) ) { | |
260 | setverdict(pass, "no exception for valueof( real value template[sending template])") | |
261 | } else { | |
262 | setverdict(fail, "no exception for valueof(not real value template)"); | |
263 | } | |
264 | } | |
265 | @catch(e) { | |
266 | log("Catched DTE:", e); | |
267 | f_setverdict_str(e, pattern "*Performing valueof or send operation on a non-specific charstring template."); | |
268 | ||
269 | if(isvalue(pl_msg) ) { | |
270 | setverdict(fail, "exception for valueof of real value template"); | |
271 | } else { | |
272 | setverdict(pass, "exception for valueof of not real value template[receiving template]"); | |
273 | } | |
274 | } | |
275 | } | |
276 | ||
277 | function f_assignment_int(inout integer pl_left, in integer pl_right ) { | |
278 | @try { | |
279 | pl_left:=pl_right; | |
280 | if( not isbound(pl_right) ) { | |
281 | log("right value:",pl_right); | |
282 | setverdict(fail, "no exception for Assignment of an unbound value " ) | |
283 | } else { | |
284 | setverdict(pass, "exception for Assignment of a bound value");//this line never reached | |
285 | } | |
286 | } | |
287 | @catch(m){ | |
288 | log("Catched DTE:",m); | |
289 | if( not isbound(pl_right) ) { | |
290 | setverdict(pass, "exception for Assignment of an unbound value." ) | |
291 | } else { | |
292 | setverdict(fail,"no exception for Assignment of a bound value.") } | |
293 | f_setverdict_str(m, pattern "*Assignment of an unbound integer value."); | |
294 | } | |
295 | } | |
296 | ||
297 | //counter counts the number of function calls | |
298 | //ther is no evaluation in try-catch and there is one evaluation if pl_evalFlag is true | |
299 | function f_returnsThreeAndCounts() runs on MyComp return integer{ | |
300 | v_funcCallCounter:=v_funcCallCounter+1; | |
301 | return 1; | |
302 | } | |
303 | ||
304 | function f_lazy_withTryCatch_exprNotEval( in @lazy integer pl_i, in boolean pl_evalFlag) runs on MyComp { | |
305 | var integer vl_i:=0; | |
306 | var RoI vl_roi1:={1,2}; | |
307 | @try { | |
308 | vl_i:=vl_roi1[10]; //DTE!!! | |
309 | vl_i:= pl_i; //expression is not evaluated | |
310 | setverdict(fail); | |
311 | } | |
312 | @catch(e) { | |
313 | log("Catched DTE:",e); | |
314 | setverdict(pass); | |
315 | } | |
316 | if(pl_evalFlag) { | |
317 | vl_i:= pl_i; | |
318 | } | |
319 | ||
320 | log("Inside lazy:", vl_i); | |
321 | } | |
322 | ||
323 | ||
324 | //******* Testcases *********** | |
325 | ||
326 | //The exception is thrown by date conversion DTE | |
327 | group g_divByZero { | |
328 | testcase tc_tryCatchInTc_divByZero() runs on MyComp { | |
329 | var integer i :=10, j:=0; | |
330 | @try { | |
331 | i:=i/j | |
332 | } | |
333 | @catch(dte_str){ | |
334 | setverdict(pass); | |
335 | stop; | |
336 | } | |
337 | setverdict(fail); //never reach this line | |
338 | } | |
339 | ||
340 | testcase tc_tryCatchInFunc_divByZero() runs on MyComp { | |
341 | f_divByZero(); | |
342 | } | |
343 | ||
344 | }//g_divByZero | |
345 | ||
346 | group g_indexOverflow { | |
347 | ||
348 | testcase tc_tryCatchInTc_indexOverflow1() runs on MyComp { | |
349 | var RoI vl_roi :={} | |
350 | @try{ | |
351 | log(vl_roi[0]); | |
352 | } | |
353 | @catch(dte_str){ | |
354 | log("Catched DTE:",dte_str); | |
355 | setverdict(pass); | |
356 | stop; | |
357 | } | |
358 | setverdict(fail); | |
359 | } | |
360 | ||
361 | testcase tc_tryCatchInTc_indexOverflow2() runs on MyComp { | |
362 | var RoI vl_roi :={1,2,3} | |
363 | @try{ | |
364 | log(vl_roi[3]); | |
365 | setverdict(fail); | |
366 | } | |
367 | @catch(dte_str){ | |
368 | log("Catched DTE:",dte_str); | |
369 | setverdict(pass); | |
370 | stop; | |
371 | } | |
372 | setverdict(fail); | |
373 | } | |
374 | ||
375 | testcase tc_tryCatchInTc_indexNegative() runs on MyComp { | |
376 | var RoI vl_roi :={1,2,3} | |
377 | var integer vl_i :=-1; | |
378 | @try{ | |
379 | log(vl_roi[vl_i]); | |
380 | setverdict(fail); | |
381 | } | |
382 | @catch(dte_str){ | |
383 | log("Catched DTE:",dte_str); | |
384 | setverdict(pass); | |
385 | stop; | |
386 | } | |
387 | setverdict(fail); | |
388 | } | |
389 | ||
390 | ||
391 | }//g_indexOverflow | |
392 | ||
393 | group g_union { | |
394 | ||
395 | testcase tc_tryCatchInTc_unionInvalidAccess1() runs on MyComp { | |
396 | var UnionType1 vl_e := {girl := {emma := {name := "Emma"}}}; | |
397 | @try { | |
398 | log(log2str("numero: ",vl_e.numero)); | |
399 | setverdict(fail, "no exception at Using non-selected union field"); | |
400 | } | |
401 | @catch(e) { | |
402 | log("Catched DTE:",e); | |
403 | setverdict(pass, "exception at Using non-selected union field"); | |
404 | } | |
405 | ||
406 | } | |
407 | ||
408 | testcase tc_tryCatchInTc_unionInvalidAccess2() runs on MyComp { | |
409 | var UnionType1 vl_e := {girl := {emma := {name := "Emma"}}}; | |
410 | var integer i:=1; | |
411 | @try { | |
412 | i:= vl_e.numero; | |
413 | setverdict(fail, "no exception at Using non-selected union field" ); | |
414 | } | |
415 | @catch(e) { | |
416 | log("Catched DTE:",e); | |
417 | setverdict(pass, "exception at Using non-selected union field"); | |
418 | } | |
419 | ||
420 | } | |
421 | ||
422 | testcase tc_tryCatchInTc_templatePatternInvalidAccess_hex() runs on MyComp { | |
423 | var template hexstring vth := 'AABB?CC'H // It's a pattern, cannot be indexed, runtime error. | |
424 | @try { | |
425 | vth[0] := 'B'H; | |
426 | setverdict(fail); | |
427 | } | |
428 | @catch(e) { | |
429 | log("Catched DTE:",e); | |
430 | setverdict(pass, "exception at Accessing a hexstring element of a non-specific hexstring template"); | |
431 | } | |
432 | } | |
433 | ||
434 | }//g_union | |
435 | ||
436 | group g_conversion { | |
437 | ||
438 | //this testcase checks if a try-catch works within a testcase | |
439 | testcase tc_tryCatchInTc_conv() runs on MyComp { | |
440 | var charstring vl_ch1:= "11", vl_ch2:="a"; | |
441 | @try{ | |
442 | var integer vl_i:= str2int(vl_ch1&vl_ch2); | |
443 | } | |
444 | @catch(e) { | |
445 | log("Catched DTE:",e); | |
446 | setverdict(pass); | |
447 | } | |
448 | ||
449 | //normal case: | |
450 | @try{ | |
451 | var integer vl_i:= str2int(vl_ch1); | |
452 | setverdict(pass); | |
453 | } | |
454 | @catch(e) { | |
455 | log("Catched DTE:",e); | |
456 | setverdict(fail,"exception for normal value"); | |
457 | } | |
458 | ||
459 | } | |
460 | ||
461 | //this testcase checks if a try-catch works within a function | |
462 | testcase tc_tryCatchInFunc_conv() runs on MyComp { | |
463 | f_tryCatch_conv(); | |
464 | } | |
465 | ||
466 | //this testcase checks if a catch block can call imported functions | |
467 | testcase tc_tryCatchInFunc_conv_imported() runs on MyComp { | |
468 | f_tryCatch_conv_imported(); | |
469 | } | |
470 | ||
471 | //this testcase checks if an exception thrown from another function will be catched or not | |
472 | testcase tc_tryCatchInFunc_conv_throw() runs on MyComp { | |
473 | @try{ | |
474 | f_tryCatch_conv_throw(); | |
475 | } | |
476 | @catch(f){ | |
477 | if(match(f, pattern "*The argument of function str2hex\(\) shall contain hexadecimal digits only,*")) | |
478 | { | |
479 | setverdict(pass); | |
480 | stop; | |
481 | } else | |
482 | { | |
483 | setverdict(fail) | |
484 | }; | |
485 | } | |
486 | setverdict(fail); //this line must not reached! | |
487 | } | |
488 | ||
489 | //this testcase checks if a try-catch works within an altstep | |
490 | testcase tc_tryCatchInAltstep_conv() runs on MyComp { | |
491 | as_tryCatch_conv(); | |
492 | } | |
493 | ||
494 | }//g_conversion | |
495 | ||
496 | //***** send-recv ******** | |
497 | ||
498 | //this testcase checks if a try-catch without DTE work or not for sending & receiving | |
499 | ||
500 | group g_send_recv { | |
501 | ||
502 | testcase tc_tryCatchInTc_send_positive() runs on MyComp { | |
503 | var MyComp vc_A:=MyComp.create("Sending1"); | |
504 | var MyComp vc_B:=MyComp.create("Receiving1"); | |
505 | connect(vc_A:PCO,vc_B:PCO); | |
506 | vc_B.start(f_behavior_receiving(tr_recv)); | |
507 | vc_A.start(f_behavior_sending(t_send)); | |
508 | all component.done; | |
509 | setverdict(pass); | |
510 | ||
511 | } | |
512 | ||
513 | testcase tc_tryCatchInTc_send_neg() runs on MyComp { | |
514 | var MyComp vc_A:=MyComp.create("Sending2"); | |
515 | var MyComp vc_B:=MyComp.create("Receiving2"); | |
516 | connect(vc_A:PCO,vc_B:PCO); | |
517 | vc_B.start(f_behavior_receiving(tr_recv)); | |
518 | vc_A.start(f_behavior_sending(tr_recv)); | |
519 | all component.done; | |
520 | setverdict(pass); | |
521 | } | |
522 | ||
523 | testcase tc_tryCatchInTc_send_positive_notConnected() runs on MyComp { | |
524 | var MyComp vc_A:=MyComp.create("Sending3"); | |
525 | var MyComp vc_B:=MyComp.create("Receiving3"); | |
526 | //>>>>>>>>>>>connect(vc_A:PCO,vc_B:PCO); | |
527 | vc_B.start(f_behavior_receiving(tr_recv)); | |
528 | vc_A.start(f_behavior_sending(t_send)); | |
529 | all component.done; | |
530 | setverdict(pass); | |
531 | ||
532 | } | |
533 | ||
534 | testcase tc_tryCatchInTc_send_positive_noReceivingSide() runs on MyComp { | |
535 | var MyComp vc_A:=MyComp.create("Sending4"); | |
536 | var MyComp vc_B:=MyComp.create("Receiving4"); | |
537 | connect(vc_A:PCO,vc_B:PCO); | |
538 | //vc_B.start(f_behavior_receiving(tr_recv)); | |
539 | vc_A.start(f_behavior_sending(t_send)); | |
540 | all component.done; | |
541 | disconnect(vc_A:PCO,vc_B:PCO); | |
542 | setverdict(pass); | |
543 | ||
544 | } | |
545 | ||
546 | testcase tc_tryCatchInTc_send_positive_noReceivingSide_InfiniteSending() runs on MyComp { | |
547 | var MyComp vc_A:=MyComp.create("Sending5"); | |
548 | var MyComp vc_B:=MyComp.create("Receiving5"); | |
549 | connect(vc_A:PCO,vc_B:PCO); | |
550 | vc_B.start(f_behavior_notReceiving(tr_recv)); | |
551 | vc_A.start(f_behavior_sendingInfinite(t_send)); | |
552 | all component.done; | |
553 | disconnect(vc_A:PCO,vc_B:PCO); | |
554 | setverdict(pass); | |
555 | ||
556 | } | |
557 | ||
558 | testcase tc_tryCatchInTc_mapping() runs on MyComp { | |
559 | var MyComp vc_A:=MyComp.create("Sending6"); | |
560 | var MyComp vc_B:=MyComp.create("Receiving6"); | |
561 | @try { | |
562 | map(vc_A:ExternalPCO,vc_B:ExternalPCO); | |
563 | } | |
564 | @catch(e){ | |
565 | log("Catched DTE:",e); | |
566 | setverdict(pass); | |
567 | stop; | |
568 | } | |
569 | setverdict(fail); | |
570 | } | |
571 | ||
572 | testcase tc_tryCatchInTc_unmapping() runs on MyComp { | |
573 | var MyComp vc_A:=MyComp.create("Sending6"); | |
574 | var MyComp vc_B:=MyComp.create("Receiving6"); | |
575 | connect(vc_A:PCO,vc_B:PCO); | |
576 | map(vc_A:ExternalPCO,system:ExternalPCO); | |
577 | map(vc_B:ExternalPCO,system:ExternalPCO); | |
578 | @try { | |
579 | unmap(vc_A:ExternalPCO,vc_B:ExternalPCO); | |
580 | setverdict(fail); | |
581 | } | |
582 | @catch(e){ | |
583 | log("Catched DTE:",e); | |
584 | setverdict(pass) | |
585 | } | |
586 | } | |
587 | ||
588 | testcase tc_tryCatchInTc_externalSend_positive() runs on MyComp { | |
589 | var MyComp vc_A:=MyComp.create("Sending6"); | |
590 | var MyComp vc_B:=MyComp.create("Receiving6"); | |
591 | connect(vc_A:PCO,vc_B:PCO); | |
592 | map(vc_A:ExternalPCO,system:ExternalPCO); | |
593 | map(vc_B:ExternalPCO,system:ExternalPCO); | |
594 | vc_B.start(f_behavior_externalReceiving(tr_recv)); | |
595 | vc_A.start(f_behavior_externalSending(t_send)); | |
596 | all component.done; | |
597 | unmap(vc_A:ExternalPCO,system:ExternalPCO); | |
598 | unmap(vc_B:ExternalPCO,system:ExternalPCO); | |
599 | disconnect(vc_A:PCO,vc_B:PCO); | |
600 | setverdict(pass); | |
601 | } | |
602 | ||
603 | //this testcase checks if exception is thrown when the sending puffer is overloaded | |
604 | testcase tc_tryCatchInTc_externalSend_noReceiving_InfiniteSending() runs on MyComp { | |
605 | map(self:ExternalPCO,system:ExternalPCO); | |
606 | var integer i; | |
607 | @try { | |
608 | for(i:=0; i<1000000; i:=i+1) { | |
609 | ExternalPCO.send("Hello"&int2str(i)); | |
610 | } | |
611 | setverdict(pass, "No stack overflow happened"); | |
612 | } | |
613 | @catch(e){ | |
614 | log("Catched DTE:",e); | |
615 | setverdict(pass) | |
616 | } | |
617 | //f_behavior_externalSending(t_send); | |
618 | unmap(self:ExternalPCO,system:ExternalPCO); | |
619 | } | |
620 | ||
621 | }//g_send_recv | |
622 | ||
623 | group g_valueof { | |
624 | ||
625 | testcase tc_tryCatchInFunc_valueof_pos() runs on MyComp { | |
626 | f_valueof(t_send); | |
627 | } | |
628 | ||
629 | testcase tc_tryCatchInFunc_valueof_neg() runs on MyComp { | |
630 | f_valueof(tr_recv); | |
631 | } | |
632 | ||
633 | }//g_valueof | |
634 | ||
635 | ||
636 | group g_assignment { | |
637 | ||
638 | testcase tc_tryCatchInTc_assignment_integer() runs on MyComp { | |
639 | var integer i,j; | |
640 | @try { | |
641 | j:=i; //uninitialized right value | |
642 | setverdict(fail,"no exception for Assignment of an unbound value" ); //do not executed! | |
643 | } | |
644 | @catch(m) { | |
645 | log("Catched DTE:",m); | |
646 | f_setverdict_str(m, pattern "*Assignment of an unbound integer value."); | |
647 | //setverdict(pass); | |
648 | } | |
649 | //normal case: | |
650 | i:=1; | |
651 | @try { | |
652 | j:=i; | |
653 | setverdict(pass,"no exception for Assignment of a not unbound value" ); | |
654 | } | |
655 | @catch(m) { | |
656 | log("Catched DTE:",m); | |
657 | setverdict(fail, "exception for Assignment of an unbound value"); | |
658 | } | |
659 | } | |
660 | ||
661 | testcase tc_tryCatchInFunc_assignment_integer() runs on MyComp { | |
662 | var integer i,j; | |
663 | f_assignment_int(i,j);//unbound assignment | |
664 | j:=1; | |
665 | f_assignment_int(i,j);//bound assignment | |
666 | } | |
667 | ||
668 | }//g_assignment | |
669 | ||
670 | ||
671 | //this testcase checks the cooperation of the @lazy and the @try-catch functionality | |
672 | testcase tc_tryCatchInFunc_lazy1() runs on MyComp { | |
673 | v_funcCallCounter:=0; | |
674 | f_lazy_withTryCatch_exprNotEval(2*f_returnsThreeAndCounts(), true); | |
675 | if(v_funcCallCounter==1) {setverdict(pass)} else {setverdict(fail)}; | |
676 | } | |
677 | ||
678 | testcase tc_tryCatchInFunc_lazy2() runs on MyComp { | |
679 | v_funcCallCounter:=0; | |
680 | f_lazy_withTryCatch_exprNotEval(2*f_returnsThreeAndCounts(), false); | |
681 | if(v_funcCallCounter==0) {setverdict(pass)} else {setverdict(fail)}; | |
682 | } | |
683 | ||
684 | ||
685 | //******* Control Part ******** | |
686 | control { | |
687 | var integer vl_i:=3, vl_j:=6; | |
688 | var MySmallInt vl_s := vl_i*vl_j;// run-time not checked | |
689 | var charstring vl_ch1:= "11", vl_ch2:="a"; | |
690 | @try{ | |
691 | vl_i:= str2int(vl_ch1&vl_ch2); | |
692 | } | |
693 | @catch(e) { | |
694 | log("Catched DTE:",e); | |
695 | //no setverdict can be applied here | |
696 | } | |
697 | ||
698 | execute(tc_tryCatchInTc_divByZero()); | |
699 | execute(tc_tryCatchInFunc_divByZero()); | |
700 | execute(tc_tryCatchInTc_indexOverflow1()); | |
701 | execute(tc_tryCatchInTc_indexOverflow2()); | |
702 | execute(tc_tryCatchInTc_indexNegative()); | |
703 | execute(tc_tryCatchInTc_unionInvalidAccess1()); | |
704 | execute(tc_tryCatchInTc_unionInvalidAccess2()); | |
705 | execute(tc_tryCatchInTc_templatePatternInvalidAccess_hex()); | |
706 | execute(tc_tryCatchInTc_conv()); | |
707 | execute(tc_tryCatchInFunc_conv()); | |
708 | execute(tc_tryCatchInFunc_conv_imported()); | |
709 | execute(tc_tryCatchInFunc_conv_throw()); | |
710 | execute(tc_tryCatchInAltstep_conv()); | |
711 | execute(tc_tryCatchInTc_send_positive()); | |
712 | execute(tc_tryCatchInTc_send_neg()); | |
713 | execute(tc_tryCatchInTc_send_positive_notConnected()); | |
714 | execute(tc_tryCatchInTc_send_positive_noReceivingSide()); | |
715 | //execute(tc_tryCatchInTc_send_positive_noReceivingSide_InfiniteSending()); | |
716 | execute(tc_tryCatchInTc_mapping()); | |
717 | execute(tc_tryCatchInTc_unmapping()); | |
718 | execute(tc_tryCatchInTc_externalSend_positive()); | |
719 | //execute(tc_tryCatchInTc_externalSend_noReceiving_InfiniteSending()); | |
720 | execute(tc_tryCatchInFunc_valueof_pos()); | |
721 | execute(tc_tryCatchInFunc_valueof_neg()); | |
722 | execute(tc_tryCatchInTc_assignment_integer()); | |
723 | execute(tc_tryCatchInFunc_assignment_integer()); | |
724 | execute(tc_tryCatchInFunc_lazy1()); | |
725 | execute(tc_tryCatchInFunc_lazy2()); | |
726 | } | |
727 | ||
728 | } |