Last sync 2016.04.01
[deliverable/titan.core.git] / regression_test / templateUnion / TtemplateUnion.ttcn
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
7 *
8 * Contributors:
9 * Balasko, Jeno
10 * Delic, Adam
11 * Raduly, Csaba
12 * Szabados, Kristof
13 * Szabo, Janos Zoltan – initial implementation
14 *
15 ******************************************************************************/
16 module TtemplateUnion {
17 type component templateUnion_mycomp {};
18 type union templateUnion_myunion {
19 integer f1,
20 float f2 };
21 type record templateUnion_rec {
22 templateUnion_myunion x1,
23 templateUnion_myunion x2,
24 templateUnion_myunion x3 optional };
25 template templateUnion_rec templateUnion_tSpec :={ //specific values
26 x1:={f2:=1.2},
27 x2:={f1:=2},
28 x3:={f1:=3} };
29 template templateUnion_rec templateUnion_tList :={ //specific value and value list
30 x1:={f2:=1.2},
31 x2:=({f1:=2},{f1:=3},{f2:=1.2}),
32 x3:={f1:=3} };
33 template templateUnion_rec templateUnion_tComp :={ //specific value and compl. list
34 x1:={f2:=1.2},
35 x2:=complement ({f1:=2},{f2:=1.2},{f1:=6}),
36 x3:={f1:=3} };
37 template templateUnion_rec templateUnion_tOmit :={ //omitting values
38 x1:={f2:=1.2},
39 x2:={f1:=2},
40 x3:=omit } ;
41 template templateUnion_rec templateUnion_tAny :={ //specific and any value
42 x1:={f2:=1.2},
43 x2:={f1:=2},
44 x3:=? } ;
45 template templateUnion_rec templateUnion_tAnyorNone :={ //specific and AnyorNone value
46 x1:={f2:=1.2},
47 x2:={f1:=2},
48 x3:=* };
49 //template templateUnion_rec templateUnion_tIfpresent :={ //specific value and ifpresent
50 // x1:={f2:=1.2},
51 // x2:={f1:=2},
52 // x3:={f1:=3} ifpresent };
53
54 testcase templateUnionSpec() runs on templateUnion_mycomp {
55 var templateUnion_myunion temp:={f1:=3};
56 var templateUnion_rec x1,x2; //specific value
57 x1:={ x1:={f2:=1.2}, x2:={f1:=2}, x3:=temp };
58 x2:={ x1:={f2:=1.3}, x2:={f1:=2}, x3:=temp };
59 //match
60 if (match(x1,templateUnion_tSpec)) {setverdict(pass);}
61 else {setverdict(fail);}
62 //no match
63 if (not(match(x2,templateUnion_tSpec))) {setverdict(pass);}
64 else {setverdict(fail);}
65 }
66
67 testcase templateUnionList() runs on templateUnion_mycomp {
68 var templateUnion_myunion temp:={f1:=3};
69 var templateUnion_rec x1,x2,x3; //value list
70 x1:={ x1:={f2:=1.2}, x2:={f1:=3}, x3:=temp };
71 x2:={ x1:={f2:=1.2}, x2:={f1:=7}, x3:=temp };
72 x3:={ x1:={f1:=8}, x2:={f1:=3}, x3:=temp };
73 //match
74 if (match(x1,templateUnion_tList)) {setverdict(pass);}
75 else {setverdict(fail);}
76 //no match: out of list
77 if (not(match(x2,templateUnion_tList))) {setverdict(pass);}
78 else {setverdict(fail);}
79 //no match: other field
80 if (not(match(x3,templateUnion_tList))) {setverdict(pass);}
81 else {setverdict(fail);}
82 }
83
84 testcase templateUnionComp() runs on templateUnion_mycomp {
85 var templateUnion_myunion temp:={f1:=3};
86 var templateUnion_rec x1,x2,x3; //complemented list
87 x1:={ x1:={f2:=1.2}, x2:={f1:=7}, x3:=temp };
88 x2:={ x1:={f2:=1.2}, x2:={f1:=6}, x3:=temp };
89 x3:={ x1:={f2:=1.3}, x2:={f1:=7}, x3:=temp };
90 //match
91 if (match(x1,templateUnion_tComp)) {setverdict(pass);}
92 else {setverdict(fail);}
93 //no match: in the list
94 if (not(match(x2,templateUnion_tComp))) {setverdict(pass);}
95 else {setverdict(fail);}
96 //no match: other field
97 if (not(match(x3,templateUnion_tComp))) {setverdict(pass);}
98 else {setverdict(fail);}
99 }
100
101 testcase templateUnionOmit() runs on templateUnion_mycomp {
102 var templateUnion_myunion temp:={f1:=3};
103 var templateUnion_rec x1,x2,x3; //omitting value
104 x1:={ x1:={f2:=1.2}, x2:={f1:=2}, x3:=omit };
105 x2:={ x1:={f2:=1.2}, x2:={f1:=2}, x3:=temp };
106 x3:={ x1:={f1:=2}, x2:={f1:=2}, x3:=omit };
107 //match
108 if (match(x1,templateUnion_tOmit)) {setverdict(pass);}
109 else {setverdict(fail);}
110 //no match: not omitted
111 if (not(match(x2,templateUnion_tOmit))) {setverdict(pass);}
112 else {setverdict(fail);}
113 //no match: other field
114 if (not(match(x3,templateUnion_tOmit))) {setverdict(pass);}
115 else {setverdict(fail);}
116 }
117
118 testcase templateUnionAny() runs on templateUnion_mycomp {
119 var templateUnion_myunion temp:={f1:=3};
120 var templateUnion_rec x1,x2,x3; //any value
121 x1:={ x1:={f2:=1.2}, x2:={f1:=2}, x3:=temp };
122 x2:={ x1:={f2:=1.2}, x2:={f1:=2}, x3:=omit };
123 x3:={ x1:={f1:=2}, x2:={f1:=2}, x3:=temp };
124 //match
125 if (match(x1,templateUnion_tAny)) {setverdict(pass);}
126 else {setverdict(fail);}
127 //no match: field omitted
128 if (not(match(x2,templateUnion_tAny))) {setverdict(pass);}
129 else {setverdict(fail);}
130 //no match: other field
131 if (not(match(x3,templateUnion_tAny))) {setverdict(pass);}
132 else {setverdict(fail);}
133 }
134
135 testcase templateUnionAnyorNone() runs on templateUnion_mycomp {
136 var templateUnion_myunion temp:={f1:=3};
137 var templateUnion_rec x1,x2,x3; //AnyorNone value
138 x1:={ x1:={f2:=1.2}, x2:={f1:=2}, x3:=omit };
139 x2:={ x1:={f2:=1.2}, x2:={f1:=2}, x3:=temp };
140 x3:={ x1:={f1:=2}, x2:={f1:=2}, x3:=omit };
141 //match: omitted
142 if (match(x1,templateUnion_tAnyorNone)) {setverdict(pass);}
143 else {setverdict(fail);}
144 //match: value
145 if (match(x2,templateUnion_tAnyorNone)) {setverdict(pass);}
146 else {setverdict(fail);}
147 //no match: other field
148 if (not(match(x3,templateUnion_tAnyorNone))) {setverdict(pass);}
149 else {setverdict(fail);}
150 }
151
152 //testcase templateUnionIfpresent() runs on templateInt_mycomp {
153 //var templateUnion_myunion temp1:={f1:=3}; //ifpresent
154 //var templateUnion_myunion temp2:={f1:=4};
155 //var templateUnion_rec x1,x2,x3,x4;
156 //x1:={ x1:={f2:=1.2}, x2:={f1:=2}, x3:=temp1 };
157 //x2:={ x1:={f2:=1.2}, x2:={f1:=2}, x3:=omit };
158 //x3:={ x1:={f2:=1.2}, x2:={f1:=2}, x3:=temp2 };
159 //x4:={ x1:={f2:=1.4}, x2:={f1:=2}, x3:=omit };
160 //match: present and match
161 //if (match(x1,templateUnion_tIfpresent)) {setverdict(pass);}
162 // else {setverdict(fail);}
163 //match: not present
164 //if (match(x2,templateUnion_tIfpresent)) {setverdict(pass);}
165 // else {setverdict(fail);}
166 //no match: present and not match
167 //if (not(match(x3,templateUnion_tIfpresent))) {setverdict(pass);}
168 // else {setverdict(fail);}
169 //no match: other field
170 //if (not(match(x4,templateUnion_tIfpresent))) {setverdict(pass);}
171 // else {setverdict(fail);}
172 //}
173
174 type record MyRec2{
175 ROC roc optional,
176 ROI roi optional,
177 MyUnion1 u optional,
178 MyRecord1 r optional
179 }
180
181 type record of charstring ROC;
182 type record of integer ROI;
183 type record MyRecord1 {
184 integer i optional,
185 float x optional,
186 charstring c
187 }
188
189 type union MyUnion1 {
190 ROC roc,
191 integer i,
192 ROI roi,
193 MyRecord1 r
194 }
195
196 testcase tc_record_withWildCard3E() runs on templateUnion_mycomp {
197 var template MyRec2 vtl_rec2;
198 vtl_rec2:={ u := ? }
199 //log("The value of the record:",vtl_rec2.u);
200 if(ispresent(vtl_rec2.u.i)){setverdict(fail)}else {setverdict(pass)};
201 }
202
203 control {
204 execute(templateUnionSpec());
205 execute(templateUnionList());
206 execute(templateUnionComp());
207 execute(templateUnionOmit());
208 execute(templateUnionAny());
209 execute(templateUnionAnyorNone());
210 // execute(templateUnionIfpresent());
211 execute(tc_record_withWildCard3E());
212 }
213 }
This page took 0.03589 seconds and 5 git commands to generate.