1 /******************************************************************************
2 * Copyright (c) 2000-2014 Ericsson Telecom AB
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 AnytypeTest . objid { 6 6 6 } {
10 //import from Supplier all;
12 type record of charstring rof_string;
14 type anytype other_anytype;
16 type record of anytype anysequence;
18 type integer AT_integer;
20 template integer pi_t := 3+14+15+926;
22 type union anytype_dup {
25 rof_string foobar_dup,
28 integer another_integer
32 charstring a optional,
36 type component and_on {}
38 template anytype anytemplate := { integer := 42 }
39 template anytype_dup anytemplate_dup := { integer_dup := 42 }
42 function foonction(in charstring input) return charstring
44 var integer e := lengthof(input);
48 with { extension override "" }
50 type function fooref(in charstring input) return charstring;
52 function pi() return float
57 type function pifunc() return float;
59 /// No XER encoding for anytype
60 ///external function enc_anytype(in anytype at) return charstring
61 ///with { extension override "prototype(convert) encode(XER)" }
63 testcase t1() runs on and_on
66 var anytype_dup anyvar_dup;
68 // this is not accepted by the compiler because it wants three components: if (ischosen(anyvar.integer)) {}
70 anyvar.rof_string := {};
72 anyvar .integer := 42;
73 if (ischosen(anyvar.integer)) { setverdict(pass)}
74 else { setverdict(fail); }
76 anyvar_dup.integer_dup := 42;
77 if (ischosen(anyvar_dup.foobar_dup)) { setverdict(fail)}
78 else { setverdict(pass); }
80 //DON'T DO THIS: triggers TR940
81 //anyvar_dup.another_integer := anyvar_dup.integer_dup;
83 if (anyvar.integer == anyvar_dup.integer_dup) { setverdict(pass); }
84 else { setverdict(fail); }
86 if (match (anyvar_dup, anytemplate_dup)) { setverdict(pass); }
87 else { setverdict(fail); }
88 if (match (anyvar, anytemplate)) { setverdict(pass); }
89 else { setverdict(fail); }
91 // Triggers TR940: anyvar.AT_integer := anyvar.integer ; // fields of same type
92 //if (ischosen(anyvar.integer)) { setverdict(fail)}
93 //else { setverdict(pass); }
94 //if (ischosen(anyvar.AT_integer)) { setverdict(pass)}
95 //else { setverdict(fail); }
98 anyvar.objid := objid { 2 2 2 }
99 anyvar_dup.objid_dup := objid { 2 2 2 }
101 if (anyvar.objid == anyvar_dup.objid_dup) { setverdict(pass); }
102 else { setverdict(fail); }
104 // now it shouldn't match
105 if (not match (anyvar_dup, anytemplate_dup)) { setverdict(pass); }
106 else { setverdict(fail); }
107 if (not match (anyvar, anytemplate)) { setverdict(pass); }
108 else { setverdict(fail); }
110 var anytype anys[2] := { {integer := 37}, {objid := objid{0 3 14 15 9}} }
111 //var anysequence aseq;
112 var integer thirty_seven := anys[0].integer;
114 if (thirty_seven == 37) { setverdict(pass); }
115 else { setverdict(fail); }
117 anyvar.bitstring := '010010001'B;
118 anyvar.boolean := true;
119 anyvar.charstring := "How are you gentlemen?";
120 anyvar.universal charstring := "All your base are belong to us";
121 // integer already fiddled with
122 anyvar.octetstring := 'DEADBEEF'O;
123 // anyvar.hexstring := 'DECAFBAD'H;
124 // anyvar.verdicttype := inconc;
125 anyvar.float := 2.718281828;
127 // anyvar.default := null;
128 // objid already fiddled with
129 anyvar.address.a := "For great justice";
130 anyvar.address.u.w := true;
131 //semantic error: "@AnytypeTest.address cannot be indexed" : var boolean bbb := anyvar.address[0];
132 //that's because address in this module is a record, not a record-of
134 //anyvar.fooref(charstring input) := foonction;
135 var pifunc pf := refers(pi);
136 var fooref fo := refers( foonction );
138 anyvar.fooref := refers( foonction );
140 anyvar.pifunc := refers(pi);
141 anyvar_dup.pifunc_dup := refers(pi);
142 anyvar.objid := objid{0 3 14 15 9}
144 //var float pie := anyvar.pifunc();
146 /* This gives the same "Unbound left operand of integer comparison" error
147 as anyvar_dup. Non-const strikes again!
148 I think it should be "wrong alternative" !
150 if (anyvar.integer == 42) { setverdict(pass); }
151 else { setverdict(fail); }
152 // same for "right operand"
153 if (42 == anyvar.integer) { setverdict(pass); }
154 else { setverdict(fail); }
156 // misidentified as module.something:
157 //anyvar.pifunc( 3+2 );
159 // anyvar.octetstring := Supplier.epdv.data_value;
162 // Examples from "An Introduction to TTCN-3"
163 const anytype c := { integer := 42 }
164 testcase t2(in anytype pa) runs on and_on
166 var anytype anyvar := { integer := 42 }
167 var integer x1 := anyvar.integer;
169 anyvar.charstring := "fourty-two";
170 anyvar.float := 42.0;
172 //x1 := anyvar.integer; // would result in a dynamic testcase error.
173 // However! The error message ("Assignment of an unbound integer value")
174 // betrays incorrect operation: anyvar has become converted to integer
178 //x1 := pa.integer; // would result in a dynamic testcase error (non-selected field)
179 var charstring pacs := pa.charstring;
180 // compile-time error (inactive field): anyvar.float := c.float;
181 if (ischosen(anyvar.integer)) { setverdict(fail,"Not integer but float should be chosen"); }
182 else { setverdict(pass); }
183 var integer x2 := float2int( anyvar.float );
185 var anytype x_any := { charstring := "All your base are belong to us" }
186 //var charstring str := x_any; // a value of type charstring was expected instead of anytype
187 //var anytype x_str := x_any.charstring; // a value of type anytype was expected instead of charstring
188 var anytype x_any1 := x_any;
192 /* This is how it would look if type parameterization was supported: */
193 //const integer p := 7;
194 type record myrecord /* (integer p) */ {
195 integer f1 /*( 0.. p )*/
216 testcase t3() runs on and_on
219 //misidentified as ModuleName.something:
220 //anyvar.myrecord(3).f1 := 3;
223 template anytype t_at := { integer := 3 };
224 type record of anytype rat;
225 testcase t4() runs on and_on
228 patkany[0].integer := 3;
229 // patkany[1].myrecord("WTF is this ?").f1 := 7; // Bingo! 7719
230 patkany[2].myrecord.f1 := 4;
231 var anytype ratt := patkany[0];
238 isit := ischosen(vl_l.s0);
239 isit := ischosen(vl2.l1.s0);
240 isit := ischosen(patkany[0] /* anytype */ .address /* a record */ .u /* a union */ .w /* a boolean */ );
242 isit := ischosen(ratt /* anytype */ .address /* a record */ .u /* a union */ .w /* a boolean */ ); // Bingo ! 7990 anytype ispresent arg
244 if ( ischosen(patkany[0] /* anytype */ . level4 . l3 . l2 . l1 . f0) ) {
252 var anytype la := { charstring := "Fourty-foo" }
259 extension "anytype bitstring,boolean,charstring,universal charstring,integer,octetstring,/*hexstring,verdicttype,*/float,/*default,*/objid,address, rof_string,fooref,pifunc,myrecord,level4, AT_integer"
260 // \-- predefined types, in the order of PredefinedType in compiler.y:6179 (address is missing here ^^) ---------/