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