oop.ttcn 22 KB
Newer Older
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
/******************************************************************************
 * Copyright (c) 2000-2021 Ericsson Telecom AB
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
 *
 * Contributors:
 *   Baranyi, Botond
 *
 ******************************************************************************/
module oop {

type component CT {
  port PT pt;
}

type port PT message { inout integer; } with { extension "internal" }

type record of integer IntList;

///////////////////////////////////////////////////
///////////////////// CLASSES /////////////////////
///////////////////////////////////////////////////

type record Rec {
  charstring str,
  IntList list
}

type union Uni {
  integer i,
  charstring cs
}

function f_this_as_param(object p) {
  log(p);
}

type class BaseClass runs on CT mtc CT system CT {
  /*protected*/ const integer m_const := 1;
  private const IntList m_const2 := { 1, 2, 3 };
  /*protected*/ var charstring m_var;
  private template octetstring m_temp := ? length (1..4);
  /*protected*/ var template float m_var_temp;
  //private PT m_port; // port members not supported
  /*protected*/ timer m_timer;
  private timer m_timer_array[3];
  
  //public template integer m_temp_pard(integer p) := p; // parameterized template members not supported
  
  // this would also be the implicit constructor's header:
  create(integer p_const, IntList p_const2, charstring p_var,
         template octetstring p_temp, template float p_var_temp) {
    m_const := p_const;
    m_const := 2;
    m_var := p_var;
    m_const2[2] := p_const2[0];
    m_temp := p_temp;
    m_temp := *;
    m_var_temp := p_var_temp;
    //m_port := p_port;
    //m_timer := p_timer;
  }
  
  public function f(in integer x) return integer {
    m_var := m_var & int2str(x);
    return x;
  }
  
  public function f2(in integer x) return Rec {
    var Rec ret_val := { str := int2str(x), list := {} };
    for (var integer i := 0; i < x; i := i + 1) {
      ret_val.list[i] := i;
    }
    return ret_val;
  }
  
  public function get_var() return charstring {
    return m_var;
  }
  
  public function get_var_temp() return template float {
    return m_var_temp;
  }
  
  public function members_and_methods_test() {
    var BaseClass v_base := BaseClass.create(4, { 1, 2, 4 }, "a", 'FF'O, (0.0 .. 10.0));
    var IntList il := { 1, 2, 4 };
    var template float tf := (0.0 .. 10.0);
    var BaseClass v_sub := SubClass.create(4, il, "a", 'FF'O, tf);
    var BaseClass v_final := FinalClass.create(4, il, "a", 'FF'O, tf, 8, "x", -1.5, *);
    
    log(v_base.f(6));
    log(v_sub.f(6));
    log(v_final.f(6));
    
    log(v_base.m_const);
    log(v_sub.m_var_temp);
    log(v_final.get_var());
    log(v_final.f2(3).list[1]);
    
    if (v_base.f(6) != 6) {
      setverdict(fail, "v_base.f(6) = ", v_base.f(6));
    }
    if (v_sub.f(6) != 5) {
      setverdict(fail, "v_sub.f(6) = ", v_sub.f(6));
    }
    if (v_final.f(6) != 14) {
      setverdict(fail, "v_final.f(6) = ", v_final.f(6));
    }
    
    if (log2str(v_base.f(6)) != "6") {
      setverdict(fail, "log2str(v_base.f(6)) = ", log2str(v_base.f(6)));
    }
    
    if (v_base.m_const != 2) {
      setverdict(fail, "v_base.m_const = ", v_base.m_const);
    }
    if (log2str(v_sub.m_var_temp) != "(0.000000 .. 10.000000)") {
      setverdict(fail, "v_sub.m_var_temp = ", v_sub.m_var_temp);
    }
    if (v_final.get_var() != "ax66") {
      setverdict(fail, "v_final.get_var() = ", v_final.get_var());
    }
    if (v_final.f2(3).list[1] != 1) {
      setverdict(fail, "v_final.f2(3).list[1] = ", v_final.f2(3).list[1]);
    }
  }
  
  public function this_test(in integer get_var, in charstring p_log_str) {
    var integer m_const := 9;
    if (this.m_const != 2) {
      setverdict(fail, "this.m_const = ", this.m_const);
    }
    if (this.get_var() != m_var) {
      setverdict(fail, "this.get_var() = ", this.get_var(), ", m_var = ", m_var);
    }
    if (log2str(this) != p_log_str) {
      setverdict(fail, "this = ", this, ", expected: ", p_log_str);
    }
    var BaseClass v_ref := this;
    if (not v_ref == this) {
      setverdict(fail, "equality failed");
    }
    var BaseClass v_ref2;
    v_ref2 := this;
    if (this != v_ref2) {
      setverdict(fail, "inequality failed");
    }
    f_this_as_param(this);
  }
}
finally {
  //pt.send(-1);
  log(m_var);
  log(this);
  log(this);
  log(this);
  log(this);
}

type class SubClass extends BaseClass {  
  create(integer p_const := 1, IntList p_const2, charstring p_var,
         template octetstring p_temp, template float p_var_temp)
         : BaseClass(p_const, p_const2, p_var, p_temp, p_var_temp) {
    m_const3 := 'FFFF'O;
    m_var := m_var & "x";
  }
  
  const octetstring m_const3 := 'AB'O; // the parser currently doesn't accept constants without initial value
  
  public function f(in integer x) return integer {
    return super.f(x) - 1;
  }
}

type class @final FinalClass extends SubClass {
  private const integer m_final_const := 1;
  private template charstring m_final_temp := ? length (1..4);
  private var float m_final_var := 1.0;
  private var template octetstring m_final_var_temp := ''O;
  
  public function @final f(in integer x) return integer {
    return super.f(x) + m_final_const + 1;
  }
  
  public function get_uni() return Uni {
    return { i := m_final_const };
  }
  
  public function get_uni_temp() return template Uni {
    return { cs := m_final_temp };
  }
}


type class @abstract AbstractClass {
  public function @abstract f_abs(inout integer x) return boolean;
  public function f_con(in charstring x) {
    log(x);
  }
}

type class ConcreteClass extends AbstractClass {
  create(octetstring p_const := 'AB'O) {
    // for compilation only, to make sure there are no name clashes between parameter default values
    log(p_const);
  }
  public function f_abs(inout integer x) return boolean {
    x := x + 1;
    return x > 0;
  }
}


type external class ExternalClass {
  public external function f_ext(in integer x) return charstring;
}

type class InternalClass extends ExternalClass {
  public function f_int() return integer {
    return 0;
  }
  public external function f_ext2();
}

testcase tc_members_and_methods() runs on CT {
  var BaseClass v_base := BaseClass.create(4, { 1, 2, 4 }, "a", 'FF'O, (0.0 .. 10.0));
  v_base.members_and_methods_test();
  setverdict(pass);
}

testcase tc_logging() runs on CT {
  var BaseClass v_base := BaseClass.create(4, { 1, 2, 4 }, "a", 'FF'O, (0.0 .. 10.0));
  var IntList il := { 1, 2, 4 };
  var template float tf := (0.0 .. 10.0);
  var BaseClass v_sub := SubClass.create(4, il, "a", 'FF'O, tf);
  var BaseClass v_final := FinalClass.create(4, il, "a", 'FF'O, tf, 8, "x", -1.5, *);

  log(v_base);
  log(v_sub);
  log(v_final);
  
  var charstring v_base_str := "BaseClass: { m_const := 2, m_const2 := { 1, 2, 1 }, m_var := \"a\", m_temp := *, m_var_temp := (0.000000 .. 10.000000), m_timer := timer: { name: m_timer, default duration: none, state: inactive }, m_timer_array := { timer: { name: m_timer_array[0], default duration: none, state: inactive }, timer: { name: m_timer_array[1], default duration: none, state: inactive }, timer: { name: m_timer_array[2], default duration: none, state: inactive } } }";
  var charstring v_sub_str := "SubClass: { BaseClass: { m_const := 2, m_const2 := { 1, 2, 1 }, m_var := \"ax\", m_temp := *, m_var_temp := (0.000000 .. 10.000000), m_timer := timer: { name: m_timer, default duration: none, state: inactive }, m_timer_array := { timer: { name: m_timer_array[0], default duration: none, state: inactive }, timer: { name: m_timer_array[1], default duration: none, state: inactive }, timer: { name: m_timer_array[2], default duration: none, state: inactive } } }, m_const3 := 'FFFF'O }";
  var charstring v_final_str := "FinalClass: { SubClass: { BaseClass: { m_const := 2, m_const2 := { 1, 2, 1 }, m_var := \"ax\", m_temp := *, m_var_temp := (0.000000 .. 10.000000), m_timer := timer: { name: m_timer, default duration: none, state: inactive }, m_timer_array := { timer: { name: m_timer_array[0], default duration: none, state: inactive }, timer: { name: m_timer_array[1], default duration: none, state: inactive }, timer: { name: m_timer_array[2], default duration: none, state: inactive } } }, m_const3 := 'FFFF'O }, m_final_const := 8, m_final_temp := \"x\", m_final_var := -1.500000, m_final_var_temp := * }";
  
  if (log2str(v_base) != v_base_str) {
    setverdict(fail, "v_base: ", v_base);
  }
  if (log2str(v_sub) != v_sub_str) {
    setverdict(fail, "v_sub: ", v_sub);
  }
  if (log2str(v_final) != v_final_str) {
    setverdict(fail, "v_final: ", v_final);
  }
  setverdict(pass);
}

testcase tc_equality() runs on CT {
  var BaseClass v_base := BaseClass.create(4, { 1, 2, 4 }, "a", 'FF'O, (0.0 .. 10.0));
  var BaseClass v_base2 := BaseClass.create(4, { 1, 2, 4 }, "a", 'FF'O, (0.0 .. 10.0));
  if (v_base == v_base2) {
    setverdict(fail, "Equality of different objects failed");
  }
  if (not v_base != v_base2) {
    setverdict(fail, "Inquality of different objects failed");
  }
  
  var BaseClass v_ref := v_base;
  if (not v_ref == v_base) {
    setverdict(fail, "Equality of object and reference to object failed");
  }
  if (v_ref != v_base) {
    setverdict(fail, "Inequality of object and reference to object failed");
  }
  
  var BaseClass v_ref2 := v_ref;
  if (not v_ref2 == v_base) {
    setverdict(fail, "Equality of object and indirect reference to object failed");
  }
  if (v_ref2 != v_base) {
    setverdict(fail, "Inequality of object and indirect reference to object failed");
  }
  
  var SubClass v_sub := SubClass.create(4, { 1, 2, 4 }, "a", 'FF'O, (0.0 .. 10.0));
  var BaseClass v_ref3 := v_sub;
  if (not v_ref3 == v_sub) {
    setverdict(fail, "Equality of subclass object and superclass reference failed");
  }
  if (v_ref3 != v_sub) {
    setverdict(fail, "Inquality of subclass object and superclass reference failed");
  }
  setverdict(pass);
}

testcase tc_null() runs on CT {
  var BaseClass v_base := BaseClass.create(4, { 1, 2, 4 }, "a", 'FF'O, (0.0 .. 10.0));
  var IntList il := { 1, 2, 4 };
  var template float tf := (0.0 .. 10.0);
  var SubClass v_sub := SubClass.create(4, il, "a", 'FF'O, tf);
  var FinalClass v_final := FinalClass.create(4, il, "a", 'FF'O, tf, 8, "x", -1.5, *);
  
  var BaseClass v_null := null;
  var BaseClass v_empty;
  
  log(v_null);
  log(v_empty);
  
  if (v_base == v_null) {
    setverdict(fail, "BaseClass equality with null reference failed");
  }
  if (v_base == v_empty) {
    setverdict(fail, "BaseClass equality with empty reference failed");
  }
  if (v_null != v_empty) {
    setverdict(fail, "null reference equality with empty reference failed");
  }
  if (v_base == null) {
    setverdict(fail, "BaseClass equality with null value failed");
  }
  if (null == v_final) {
    setverdict(fail, "FinalClass equality with null value failed");
  }
  if (v_null != null) {
    setverdict(fail, "null reference equality with null value failed");
  }
  if (null != v_empty) {
    setverdict(fail, "null value equality with empty reference failed");
  }
  setverdict(pass);
}

testcase tc_this() runs on CT {
  var BaseClass v_base := BaseClass.create(4, { 1, 2, 4 }, "a", 'FF'O, (0.0 .. 10.0));
  v_base.this_test(10, log2str(v_base));
  setverdict(pass);
}

testcase tc_references() runs on CT {
  var BaseClass v_base := BaseClass.create(4, { 1, 2, 4 }, "a", 'FF'O, 1.0);
  var SubClass v_sub := SubClass.create(4, { 1, 2, 4 }, "a", 'FF'O, 1.0);
  var FinalClass v_final := FinalClass.create(4, { 1, 2, 4 }, "a", 'FF'O, 1.0, 8, "x", -1.5, *);
  var BaseClass v_null := null;
  
  var BaseClass v_ref1;
  if (v_ref1 != null) {
    setverdict(fail, "#1");
  }
  v_ref1 := v_base;
  if (v_ref1 != v_base) {
    setverdict(fail, "#2");
  }
  var integer v_int := v_final.f(1);
  if (v_int != 9) {
    setverdict(fail, "#3, ", v_final.f(1));
  }
  v_int := v_final.f(2);
  if (v_int != 10) {
    setverdict(fail, "#4, ", v_final.f(2));
  }
  if (not isbound(v_final.f2(3).list[1])) {
    setverdict(fail, "#5");
  }
  if (not isvalue(v_base.get_var_temp())) {
    setverdict(fail, "#6");
  }
  if (not ispresent(v_base.get_var_temp())) {
    setverdict(fail, "#7");
  }
  if (ischosen(v_final.get_uni().cs)) {
    setverdict(fail, "#8");
  }
  if (not ischosen(v_final.get_uni_temp().cs)) {
    setverdict(fail, "#9");
  }
  if (v_final.f2(3).list[1] + v_final.f(-6) != v_base.f(3) * float2int(valueof(v_sub.get_var_temp()))) {
    setverdict(fail, "#10, ", v_final.f2(3).list[1] + v_final.f(-6), " != ", v_base.f(3) * float2int(valueof(v_sub.get_var_temp())));
  }
  if (match(v_final.get_uni(), v_final.get_uni_temp())) {
    setverdict(fail, "#11, ", match(v_final.get_uni(), v_final.get_uni_temp()));
  }
  if (not isbound(v_sub)) {
    setverdict(fail, "#12");
  }
  if (isbound(v_null)) {
    setverdict(fail, "#13");
  }
  if (not isvalue(v_final)) {
    setverdict(fail, "#14");
  }
  if (isvalue(v_null)) {
    setverdict(fail, "#15");
  }
  if (not ispresent(v_base)) {
    setverdict(fail, "#16");
  }
  if (ispresent(v_null)) {
    setverdict(fail, "#17");
  }
  var BaseClass v_base2 := v_null;
  if (v_base2 != null) {
    setverdict(fail, "#18");
  }
  setverdict(pass);
}


type class Node {
  var integer data;
  var Node next;
  public function get_next() return Node { return next; }
  public function f() return integer { return 1; }
}

function f_test(in Node p1, inout Node p2, out Node p3,
                in charstring p1_str, in charstring p2_str) return Node {
  if (log2str(p1) != p1_str) {
    setverdict(fail, "Invalid 'in' parameter value at start: ", p1, ", expected: ", p1_str);
  }
  if (log2str(p2) != p2_str) {
    setverdict(fail, "Invalid 'inout' parameter value at start: ", p2, ", expected: ", p2_str);
  }
  if (p3 != null) {
    setverdict(fail, "Invalid 'out' parameter value at start: ", p3, ", expected: null");
  }
  var integer i := p1.f();
  if (i != 1) {
    setverdict(fail, "Invalid value returned by function call of 'in' parameter: ", i);
  }
  var Node tmp := p2;
  p3 := p1;
  p1 := null;
  p2 := null;
  return tmp;
}

testcase tc_function_pars_and_retval() runs on CT {
  var Node x := Node.create(1, Node.create(2, Node.create(3, null)));
  var Node y := Node.create(0, null);
  var Node z := Node.create(-1, null);
  var charstring x_str := log2str(x);
  var charstring y_str := log2str(y);
  var Node res := f_test(x, y, z, x_str, y_str);
  if (log2str(x) != x_str) {
    setverdict(fail, "Invalid 'in' parameter value at end: ", x, ", expected: ", x_str);
  }
  if (y != null) {
    setverdict(fail, "Invalid 'inout' parameter value at end: ", y, ", expected: null");
  }
  if (log2str(z) != x_str) {
    setverdict(fail, "Invalid 'out' parameter value at end: ", z, ", expected: ", x_str);
  }
  if (log2str(res) != y_str) {
    setverdict(fail, "Invalid return value: ", res, ", expected: ", y_str);
  }
  
  setverdict(pass);
}

type class Node2 {
  var object data;
  var Node2 next;
  public function get_data() return object { return data; }
  public function f(in object p) { data := p; }
}

function f_test_in(Node p1, Node2 p2) {
  p2.f(p1.get_next());
}

type class InParTester {
  public function test(object x) return boolean {
    return x of Node;
  }
}

testcase tc_function_pars_in() runs on CT {
  var Node n1 := Node.create(1, Node.create(2, null));
  var Node2 n2 := Node2.create(null, null);
  f_test_in(n1, n2);
  if (log2str(n2.get_data()) != log2str(n1.get_next())) {
    setverdict(fail, "Expected: ", n1.get_next(), ", got: ", n2.get_data());
  }
  var InParTester t := InParTester.create;
  if (not t.test(n1.get_next())) {
    setverdict(fail, "InParTester failed");
  }
  setverdict(pass);
}

type class Something {
  public function toString() return universal charstring {
    return "Something";
  }
}

testcase tc_object() runs on CT {
  var object v_obj := Node.create(3, null);
  var Node v_node := Node.create(3, null);
  if (log2str(v_obj) != log2str(v_node)) {
    setverdict(fail, "v_obj: ", v_obj, ", v_node: ", v_node);
  }
  if (v_obj.toString() != "Object") {
    setverdict(fail, "v_obj.toString(): ", v_obj.toString());
  }
  if (v_obj.toString() != v_node.toString()) {
    setverdict(fail, "v_obj.toString(): ", v_obj.toString(), ", v_node.toString(): ", v_node.toString());
  }
  var object v_obj2 := Something.create;
  var Something v_smthn := Something.create;
  if (v_obj2.toString() != "Something") {
    setverdict(fail, "v_obj2.toString(): ", v_obj2.toString());
  }
  if (v_obj2.toString() != v_smthn.toString()) {
    setverdict(fail, "v_obj2.toString(): ", v_obj2.toString(), ", v_smthn.toString(): ", v_smthn.toString());
  }
  if (v_obj2.toString()[3] != "e") {
    setverdict(fail, "v_obj2.toString()[3]: ", v_obj2.toString()[3]);
  }
  var Node2 v_node2 := Node2.create(Something.create, Node2.create(Node.create(1, null), null));
  if (log2str(v_node2) != "Node2: { data := Something: {  }, next := Node2: { data := Node: { data := 1, next := null }, next := null } }") {
    setverdict(fail, "v_node2: ", v_node2);
  }
  setverdict(pass);
}

type class Order {
  var integer b;
  var integer d;
  var integer c;
  var integer a;
}

testcase tc_order() runs on CT {
  var Order x := Order.create(1, 2, 3, 4);
  if (log2str(x) == "Order: { b := 1, d := 2, c := 3, a := 4 }") {
    setverdict(pass);
  }
  else {
    setverdict(fail, x);
  }
}

testcase tc_abstract() runs on CT {
  var AbstractClass v := ConcreteClass.create;
  var integer x := 0;
  if (v.f_abs(x) and x == 1) {
    setverdict(pass);
  }
  else {
    setverdict(fail);
  }
}

type class Destructor { }
finally {
  setverdict(pass);
}

testcase tc_destructor() runs on CT {
  var Destructor x := Destructor.create;
}

testcase tc_of_operator() runs on CT {
  var SubClass v_sub := SubClass.create(4, { 1, 2, 4 }, "a", 'FF'O, 1.0);
  var SubClass v_final := FinalClass.create(4, { 1, 2, 4 }, "a", 'FF'O, 1.0, 8, "x", -1.5, *);
  var object v_obj := Node.create(3, null);
  var BaseClass v_null := null;
  
  if (not v_sub of BaseClass) {
    setverdict(fail, "#1");
  }
  if (not v_sub of SubClass) {
    setverdict(fail, "#2");
  }
  if (v_sub of FinalClass) {
    setverdict(fail, "#3");
  }
  if (not v_final of BaseClass) {
    setverdict(fail, "#4");
  }
  if (not v_final of SubClass) {
    setverdict(fail, "#5");
  }
  if (not v_final of FinalClass) {
    setverdict(fail, "#6");
  }
  if (v_sub of Node) {
    setverdict(fail, "#7");
  }
  if (not v_sub of object) {
    setverdict(fail, "#8");
  }
  if (not v_obj of object) {
    setverdict(fail, "#9");
  }
  if (not v_obj of Node) {
    setverdict(fail, "#10");
  }
  if (v_obj of AbstractClass) {
    setverdict(fail, "#11");
  }
  if (v_null of BaseClass) {
    setverdict(fail, "#12");
  }
  if (v_null of object) {
    setverdict(fail, "#13");
  }
  setverdict(pass);
}

testcase tc_select_class() runs on CT {
  var SubClass v_sub := SubClass.create(4, { 1, 2, 4 }, "a", 'FF'O, 1.0);
  var SubClass v_final := FinalClass.create(4, { 1, 2, 4 }, "a", 'FF'O, 1.0, 8, "x", -1.5, *);
  var object v_obj := Node.create(3, null);
  var BaseClass v_null := null;
  
  select class (v_sub) {
    case (FinalClass) {
      setverdict(fail, "#1 FinalClass");
    }
    case (SubClass) {
      setverdict(pass);
    }
    case (BaseClass) {
      setverdict(fail, "#1 BaseClass");
    }
  }
  
  select class (v_final) {
    case (FinalClass) {
      setverdict(pass);
    }
    case (SubClass) {
      setverdict(fail, "#2 SubClass");
    }
    case (BaseClass) {
      setverdict(fail, "#2 BaseClass");
    }
  }
  
  select class (v_obj) {
    case (object) {
      setverdict(pass);
    }
    case (Node) {
      setverdict(fail, "#3 Node");
    }
    case else {
      setverdict(fail, "#3 else");
    }
  }
  
  select class (v_null) {
    case (BaseClass) {
      setverdict(fail, "#4 BaseClass");
    }
    case (Node) {
      setverdict(fail, "#4 Node");
    }
    case (object) {
      setverdict(fail, "#4 object");
    }
    case else {
      setverdict(pass);
    }
  }
}

testcase tc_casting() runs on CT {
  var SubClass v_sub := SubClass.create(4, { 1, 2, 4 }, "a", 'FF'O, 1.0);
  var SubClass v_final := FinalClass.create(4, { 1, 2, 4 }, "a", 'FF'O, 1.0, 8, "x", -1.5, *);
  var object v_obj := Node.create(3, null);
  var BaseClass v_null := null;
  var Node v_null2 := null;
  var object v_con := ConcreteClass.create;
  
  var BaseClass v_base := v_sub => BaseClass;
  if (log2str(v_base) != log2str(v_sub)) {
    setverdict(fail, "#1: ", v_base);
  }
  var FinalClass v_final2 := v_final => FinalClass;
  if (log2str(v_final2) != log2str(v_final)) {
    setverdict(fail, "#2: ", v_final2);
  }
  var Node v_node := v_obj => (v_null2);
  if (log2str(v_node) != log2str(v_obj)) {
    setverdict(fail, "#3: ", v_node);
  }
  var SubClass v_sub2 := v_sub => SubClass;
  if (log2str(v_sub2) != log2str(v_sub)) {
    setverdict(fail, "#4: ", v_sub2);
  }
  var object v_obj2 := v_sub => object;
  if (log2str(v_obj2) != log2str(v_sub)) {
    setverdict(fail, "#5: ", v_obj2);
  }
  var AbstractClass v_abs := v_con => AbstractClass;
  if (log2str(v_abs) != log2str(v_con)) {
    setverdict(fail, "#6: ", v_abs);
  }
  @try {
    var SubClass v_bad := v_null => SubClass;
    setverdict(fail, "#7: Error expected");
  }
  @catch(msg) {
    if (not match(msg, pattern "*Casting a null reference")) {
      setverdict(fail, "#7: Invalid error: ", msg);
    }
  }
  @try {
    var FinalClass v_bad2 := v_sub => FinalClass;
    setverdict(fail, "#8: Error expected");
  }
  @catch(msg) {
    if (not match(msg, pattern "*Invalid casting to class type `FinalClass'")) {
      setverdict(fail, "#8: Invalid error: ", msg);
    }
  }
  /*var integer v_int := (v_obj => Node).data;
  if (v_int != 3) {
    setverdict(fail, "#9: ", v_int);
  }*/
  setverdict(pass);
}


control {
  execute(tc_members_and_methods());
  execute(tc_logging());
  execute(tc_equality());
  execute(tc_null());
  execute(tc_this());
  execute(tc_references());
  execute(tc_function_pars_and_retval());
  execute(tc_function_pars_in());
  execute(tc_object());
  execute(tc_order());
  execute(tc_abstract());
  execute(tc_destructor());
  execute(tc_of_operator());
  execute(tc_select_class());
  execute(tc_casting());
}

}