1 /******************************************************************************
2 * Copyright (c) 2000-2016 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
13 ******************************************************************************/
14 module AnytypeTest . objid { 6 6 6 } {
16 //import from Supplier all;
18 type record of charstring rof_string;
20 type anytype other_anytype;
22 type record of anytype anysequence;
24 type integer AT_integer;
26 template integer pi_t := 3+14+15+926;
28 type union anytype_dup {
31 rof_string foobar_dup,
34 integer another_integer
38 charstring a optional,
42 type component and_on {}
44 template anytype anytemplate := { integer := 42 }
45 template anytype_dup anytemplate_dup := { integer_dup := 42 }
48 function foonction(in charstring input) return charstring
50 var integer e := lengthof(input);
54 with { extension override "" }
56 type function fooref(in charstring input) return charstring;
58 function pi() return float
63 type function pifunc() return float;
65 /// No XER encoding for anytype
66 ///external function enc_anytype(in anytype at) return charstring
67 ///with { extension override "prototype(convert) encode(XER)" }
69 testcase t1() runs on and_on
72 var anytype_dup anyvar_dup;
74 // this is not accepted by the compiler because it wants three components: if (ischosen(anyvar.integer)) {}
76 anyvar.rof_string := {};
78 anyvar .integer := 42;
79 if (ischosen(anyvar.integer)) { setverdict(pass)}
80 else { setverdict(fail); }
82 anyvar_dup.integer_dup := 42;
83 if (ischosen(anyvar_dup.foobar_dup)) { setverdict(fail)}
84 else { setverdict(pass); }
86 //DON'T DO THIS: triggers TR940
87 //anyvar_dup.another_integer := anyvar_dup.integer_dup;
89 if (anyvar.integer == anyvar_dup.integer_dup) { setverdict(pass); }
90 else { setverdict(fail); }
92 if (match (anyvar_dup, anytemplate_dup)) { setverdict(pass); }
93 else { setverdict(fail); }
94 if (match (anyvar, anytemplate)) { setverdict(pass); }
95 else { setverdict(fail); }
97 // Triggers TR940: anyvar.AT_integer := anyvar.integer ; // fields of same type
98 //if (ischosen(anyvar.integer)) { setverdict(fail)}
99 //else { setverdict(pass); }
100 //if (ischosen(anyvar.AT_integer)) { setverdict(pass)}
101 //else { setverdict(fail); }
104 anyvar.objid := objid { 2 2 2 }
105 anyvar_dup.objid_dup := objid { 2 2 2 }
107 if (anyvar.objid == anyvar_dup.objid_dup) { setverdict(pass); }
108 else { setverdict(fail); }
110 // now it shouldn't match
111 if (not match (anyvar_dup, anytemplate_dup)) { setverdict(pass); }
112 else { setverdict(fail); }
113 if (not match (anyvar, anytemplate)) { setverdict(pass); }
114 else { setverdict(fail); }
116 var anytype anys[2] := { {integer := 37}, {objid := objid{0 3 14 15 9}} }
117 //var anysequence aseq;
118 var integer thirty_seven := anys[0].integer;
120 if (thirty_seven == 37) { setverdict(pass); }
121 else { setverdict(fail); }
123 anyvar.bitstring := '010010001'B;
124 anyvar.boolean := true;
125 anyvar.charstring := "How are you gentlemen?";
126 anyvar.universal charstring := "All your base are belong to us";
127 // integer already fiddled with
128 anyvar.octetstring := 'DEADBEEF'O;
129 // anyvar.hexstring := 'DECAFBAD'H;
130 // anyvar.verdicttype := inconc;
131 anyvar.float := 2.718281828;
133 // anyvar.default := null;
134 // objid already fiddled with
135 anyvar.address.a := "For great justice";
136 anyvar.address.u.w := true;
137 //semantic error: "@AnytypeTest.address cannot be indexed" : var boolean bbb := anyvar.address[0];
138 //that's because address in this module is a record, not a record-of
140 //anyvar.fooref(charstring input) := foonction;
141 var pifunc pf := refers(pi);
142 var fooref fo := refers( foonction );
144 anyvar.fooref := refers( foonction );
146 anyvar.pifunc := refers(pi);
147 anyvar_dup.pifunc_dup := refers(pi);
148 anyvar.objid := objid{0 3 14 15 9}
150 //var float pie := anyvar.pifunc();
152 /* This gives the same "Unbound left operand of integer comparison" error
153 as anyvar_dup. Non-const strikes again!
154 I think it should be "wrong alternative" !
156 if (anyvar.integer == 42) { setverdict(pass); }
157 else { setverdict(fail); }
158 // same for "right operand"
159 if (42 == anyvar.integer) { setverdict(pass); }
160 else { setverdict(fail); }
162 // misidentified as module.something:
163 //anyvar.pifunc( 3+2 );
165 // anyvar.octetstring := Supplier.epdv.data_value;
168 // Examples from "An Introduction to TTCN-3"
169 const anytype c := { integer := 42 }
170 testcase t2(in anytype pa) runs on and_on
172 var anytype anyvar := { integer := 42 }
173 var integer x1 := anyvar.integer;
175 anyvar.charstring := "fourty-two";
176 anyvar.float := 42.0;
178 //x1 := anyvar.integer; // would result in a dynamic testcase error.
179 // However! The error message ("Assignment of an unbound integer value")
180 // betrays incorrect operation: anyvar has become converted to integer
184 //x1 := pa.integer; // would result in a dynamic testcase error (non-selected field)
185 var charstring pacs := pa.charstring;
186 // compile-time error (inactive field): anyvar.float := c.float;
187 if (ischosen(anyvar.integer)) { setverdict(fail,"Not integer but float should be chosen"); }
188 else { setverdict(pass); }
189 var integer x2 := float2int( anyvar.float );
191 var anytype x_any := { charstring := "All your base are belong to us" }
192 //var charstring str := x_any; // a value of type charstring was expected instead of anytype
193 //var anytype x_str := x_any.charstring; // a value of type anytype was expected instead of charstring
194 var anytype x_any1 := x_any;
198 /* This is how it would look if type parameterization was supported: */
199 //const integer p := 7;
200 type record myrecord /* (integer p) */ {
201 integer f1 /*( 0.. p )*/
222 testcase t3() runs on and_on
225 //misidentified as ModuleName.something:
226 //anyvar.myrecord(3).f1 := 3;
229 template anytype t_at := { integer := 3 };
230 type record of anytype rat;
231 testcase t4() runs on and_on
234 patkany[0].integer := 3;
235 // patkany[1].myrecord("WTF is this ?").f1 := 7; // Bingo! 7719
236 patkany[2].myrecord.f1 := 4;
237 var anytype ratt := patkany[0];
244 isit := ischosen(vl_l.s0);
245 isit := ischosen(vl2.l1.s0);
246 isit := ischosen(patkany[0] /* anytype */ .address /* a record */ .u /* a union */ .w /* a boolean */ );
248 isit := ischosen(ratt /* anytype */ .address /* a record */ .u /* a union */ .w /* a boolean */ ); // Bingo ! 7990 anytype ispresent arg
250 if ( ischosen(patkany[0] /* anytype */ . level4 . l3 . l2 . l1 . f0) ) {
258 var anytype la := { charstring := "Fourty-foo" }
265 extension "anytype bitstring,boolean,charstring,universal charstring,integer,octetstring,/*hexstring,verdicttype,*/float,/*default,*/objid,address, rof_string,fooref,pifunc,myrecord,level4, AT_integer"
266 // \-- predefined types, in the order of PredefinedType in compiler.y:6179 (address is missing here ^^) ---------/