Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / all_from / everything.ttcn
CommitLineData
970ed795 1/******************************************************************************
3abe9331 2 * Copyright (c) 2000-2015 Ericsson Telecom AB
970ed795
EL
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 ******************************************************************************/
8module everything
9{
10type record of integer RoI;
11type set of integer SoI;
12
13type set of integer MySetOfType (0 .. 10);
14
15type component A {}
16
17/****************************************************************/
18
19// B 1.2.1 Template List
20
21template RoI t_RoI1 := {1, 2, (6..9)};
22template RoI t_RoI2 := {1, *, 3};
23
24template integer t_i1 := (all from t_RoI1, 100);
25// equivalent to (1, 2, (6..9) , 100);
26
27testcase tc1() runs on A
28{
29 var integer v_i;
30 action("t_i1=", t_i1);
31
32 v_i := 1;
33 if (match(v_i, t_i1)) { setverdict(pass); }
34 else { setverdict(fail, v_i, " should match ", t_i1); }
35
36 v_i := 2;
37 if (match(v_i, t_i1)) { setverdict(pass); }
38 else { setverdict(fail, v_i, " should match ", t_i1); }
39
40 v_i := 3;
41 if (not match(v_i, t_i1)) { setverdict(pass); }
42 else { setverdict(fail, v_i, " should NOT match ", t_i1); }
43
44 v_i := 4;
45 if (not match(v_i, t_i1)) { setverdict(pass); }
46 else { setverdict(fail, v_i, " should NOT match ", t_i1); }
47
48 v_i := 5;
49 if (not match(v_i, t_i1)) { setverdict(pass); }
50 else { setverdict(fail, v_i, " should NOT match ", t_i1); }
51
52 v_i := 6;
53 if (match(v_i, t_i1)) { setverdict(pass); }
54 else { setverdict(fail, v_i, " should match ", t_i1); }
55
56 v_i := 10;
57 if (not match(v_i, t_i1)) { setverdict(pass); }
58 else { setverdict(fail, v_i, " should NOT match ", t_i1); }
59
60 v_i := 100;
61 if (match(v_i, t_i1)) { setverdict(pass); }
62 else { setverdict(fail, v_i, " should match ", t_i1); }
63}
64
65// now correctly reported by Titan
66//template integer t_i2 := (0, all from t_RoI2); // causes an error because t_RoI2 contains AnyElementsOrNone
67
68//testcase tc2() runs on A
69//{
70// action ("t_i2=", t_i2)
71//}
72
73/* TODO: different errors are reported
74template RoI t_RoI3 := (all from t_RoI1); // causes an error because member type of
75 // t_RoI1 (integer) is not compatible with the list template type (RoI)
76
77template RoI t_RoI4 := ?;
78
79template RoI t_RoI5 := (all from t_RoI4); // causes an error because t_RoI4 resolves into a matching mechanism
80*/
81
82//template RoI t_RoI1 := {1, 2, (6..9)};
83//template RoI t_RoI2 := {1, *, 3};
84
85// B 1.2.2 Complemented Template List
86/*
87template RoI t_RoI1c := {1, 2, (6..9)};
88template RoI t_RoI2c := {1, *, 3};
89*/
90template integer t_i1c := complement(all from t_RoI1, 100); // results in (1, 2, (6..9), 100)
91
92// This is exactly the opposite of the testcase in all_from
93testcase tc_compl() runs on A
94{
95 var integer v_i;
96 action("t_i1c=", t_i1c);
97
98 v_i := 1;
99 if (not match(v_i, t_i1c)) { setverdict(pass); }
100 else { setverdict(fail, v_i, " should NOT match ", t_i1c); }
101
102 v_i := 2;
103 if (not match(v_i, t_i1c)) { setverdict(pass); }
104 else { setverdict(fail, v_i, " should NOT match ", t_i1c); }
105
106 v_i := 3;
107 if (match(v_i, t_i1c)) { setverdict(pass); }
108 else { setverdict(fail, v_i, " should match ", t_i1c); }
109
110 v_i := 4;
111 if (match(v_i, t_i1c)) { setverdict(pass); }
112 else { setverdict(fail, v_i, " should match ", t_i1c); }
113
114 v_i := 5;
115 if (match(v_i, t_i1c)) { setverdict(pass); }
116 else { setverdict(fail, v_i, " should match ", t_i1c); }
117
118 v_i := 6;
119 if (not match(v_i, t_i1c)) { setverdict(pass); }
120 else { setverdict(fail, v_i, " should NOT match ", t_i1c); }
121
122 v_i := 10;
123 if (match(v_i, t_i1c)) { setverdict(pass); }
124 else { setverdict(fail, v_i, " should match ", t_i1c); }
125
126 v_i := 100;
127 if (not match(v_i, t_i1c)) { setverdict(pass); }
128 else { setverdict(fail, v_i, " should NOT match ", t_i1c); }
129}
130
131// correctly diagnosed by Titan
132//template integer t_i2c := complement(0, all from t_RoI2); // causes an error because t_RoI2 contains AnyElementsOrNone
133
134//template RoI t_RoI3c := complement(all from t_RoI1); // causes an error because member type of t_RoI1 (integer) is not compatible
135// // with the complemented list template type (RoI)
136//
137// The errors for the above are the same as the errors for the one below :)
138//
139//template RoI t_RoI3c_direct := complement(1, 2, (6..9))
140
141/*
142template RoI t_RoI4c := ?;
143template RoI t_RoI5c := complement (all from t_RoI4c);
144 // causes an error because t_RoI4 resolves into a matching mechanism
145 // now correctly signalled by titan
146*/
147//template RoI t_RoI1 := {1, 2, (6..9)};
148//template RoI t_RoI2 := {1, *, 3};
149
150// B 1.2.6 Superset
151
152//EXAMPLE 1:
153
154 template MySetOfType MyTemplate1 := superset (1, 2, 3);
155 // matches any sequence of integers which contains at least one occurrences of the numbers
156 // 1, 2 and 3 in any order and position
157
158 template MySetOfType MyTemplate2_AnyValue := superset (1, 2, ?);
159 // matches any sequence of integers which contains at least one occurrences of the numbers
160 // 1, 2 and at least one more valid integer value (i.e. between 0 and 10, inclusively), in any
161 // order and position
162
163 template MySetOfType MyTemplate3 := superset (1, 2, (3, 4));
164 // matches any sequence of integers which contains at least one occurrences of the numbers
165 // 1, 2 and a number with the value 3 or 4, in any order and position
166
167 template MySetOfType MyTemplate4 := superset (1, 2, complement(3, 4));
168 // any sequence of integers matches which contains at least one occurrences of the numbers
169 // 1, 2 and a valid integer value which is not 3 or 4, in any order and position
170
171 template MySetOfType MyTemplate6 := superset (1, 2, 3) length (7);
172 // matches any sequence of 7 integers which contains at least one occurrences of the numbers
173 // 1, 2 and 3 in any order and position
174
175 template MySetOfType MyTemplate7 := superset (1, 2, ?) length (7 .. infinity);
176 // matches any sequence of at least 7 integers which contains at least one occurrences of the
177 // numbers 1, 2 and 3 in any order and position
178
179 template MySetOfType MyTemplate8 := superset (1, 2, 3) length (2 .. 7);
180 // causes an error, the lower bound of the length attribute contradicts to the minimum number
181 // of elements imposed by the superset argument
182
183//EXAMPLE 2:
184 template RoI t_RoI1s := {1, 2, ?};
185 template SoI t_SoI1s := superset(all from t_RoI1s);
186 // results in superset(1, 2, ?)
187
188testcase tc_superset() runs on A
189{
190 action("superset: ", t_SoI1s);
191}
192
193//template RoI t_RoI1 := {1, 2, (6..9)};
194//template RoI t_RoI2 := {1, *, 3};
195
196// B.1.2.7 SubSet
197//EXAMPLE 1:
198 template MySetOfType MyTemplate1_ := subset (1, 2, 3);
199 // matches any sequence of integers which contains zero or one occurrences of the numbers
200 // 1, 2 and 3 in any order and position
201
202 template MySetOfType MyTemplate2_ := subset (1, 2, ?);
203 // matches any sequence of integers which contains zero or one occurrences of the numbers
204 // 1, 2 and a valid integer value (i.e. between 0 and 10, inclusive) in any order and position
205
206 template MySetOfType MyTemplate3_ := subset (1, 2, (3, 4));
207 // matches any sequence of integers which contains zero or one occurrences of the numbers
208 // 1, 2 and one of the numbers 3 or 4, in any order and position
209
210 template MySetOfType MyTemplate4_ := subset (1, 2, complement (3, 4));
211 // matches any sequence of integers which contains zero or one occurrences of the numbers
212 // 1, 2 and a valid integer number which is not 3 or 4, in any order and position
213
214 template MySetOfType MyTemplate5_ := subset (1, 2, 3) length (2);
215 // matches any sequence of two integers which contains zero or one occurrences of
216 // the numbers 1, 2 and 3, in any order and position
217
218 template MySetOfType MyTemplate6_ := subset (1, 2, ?) length (0 .. 2);
219 // matches any sequence of zero, one or two integers which contains zero or one occurrences of
220 // the numbers 1, 2 and of a valid integer value, in any order and position
221
222 template MySetOfType MyTemplate7_ := subset (1, 2, 3) length (0 .. 4);
223 // causes an error, the upper bound of length attribute contradicts to the maximum number of
224 // elements imposed by the subset argument
225
226//EXAMPLE 2:
227 template RoI t_RoI1_ := {1, 2, ?};
228 template SoI t_SoI1_ := subset(all from t_RoI1_);
229 // results in subset(1, 2, ?)
230
231testcase tc_subset() runs on A
232{
233 action("subset: ", t_SoI1_);
234}
235
236//template RoI t_RoI1 := {1, 2, (6..9)};
237//template RoI t_RoI2 := {1, *, 3};
238
239// B.1.3.3 Permutation
240//EXAMPLE 1:
241 type RoI MySequenceOfType;
242
243 template MySequenceOfType MyTemplate1p := { permutation ( 1, 2, 3 ), 5 };
244 // matches any of the following sequences of 4 integers: 1,2,3,5; 1,3,2,5; 2,1,3,5;
245 // 2,3,1,5; 3,1,2,5; or 3,2,1,5
246
247 template MySequenceOfType MyTemplate2p := { permutation ( 1, 2, ? ), 5 };
248 // matches any sequence of 4 integers that ends with 5 and contains 1 and 2 at least once in
249 // other positions
250
251 template MySequenceOfType MyTemplate3p := { permutation ( 1, 2, 3 ), * };
252 // matches any sequence of integers starting with 1,2,3; 1,3,2; 2,1,3; 2,3,1; 3,1,2 or 3,2,1
253
254 template MySequenceOfType MyTemplate4p := { *, permutation ( 1, 2, 3 )};
255 // matches any sequence of integers ending with 1,2,3; 1,3,2; 2,1,3; 2,3,1; 3,1,2 or 3,2,1
256
257 template MySequenceOfType MyTemplate5p := { *, permutation ( 1, 2, 3 ),* };
258 // matches any sequence of integers containing any of the following substrings at any position:
259 // 1,2,3; 1,3,2; 2,1,3; 2,3,1; 3,1,2 or 3,2,1
260
261 template MySequenceOfType MyTemplate6p := { permutation ( 1, 2, * ), 5 };
262 // matches any sequence of integers that ends with 5 and containing 1 and 2 at least once in
263 // other positions
264
265//error by Titan: Length restriction cannot be used in a template of type `integer'
266// template MySequenceOfType MyTemplate7p := { permutation ( 1, 2, 3 ), * length (0..5) };
267 // matches any sequence of three to eight integers starting with 1,2,3; 1,3,2; 2,1,3; 2,3,1;
268 // 3,1,2 or 3,2,1
269
270 template integer MyInt1 := (1,2,3);
271 template integer MyInt2 := (1,2,?);
272 template integer MyInt3 := ?;
273 template integer MyInt4 := *;
274
275 template MySequenceOfType MyTemplate10 := { permutation (MyInt1, 2, 3 ), 5 };
276 // matches any of the sequences of 4 integers:
277 // 1,3,2,5; 2,1,3,5; 2,3,1,5; 3,1,2,5; or 3,2,1,5;
278 // 2,3,2,5; 2,2,3,5; 2,3,2,5; 3,2,2,5; or 3,2,2,5;
279 // 3,3,2,5; 2,3,3,5; 2,3,3,5; 3,3,2,5; or 3,2,3,5;
280
281 template MySequenceOfType MyTemplate11 := { permutation (MyInt2, 2, 3 ), 5 };
282 // matches any sequence of 4 integers that ends with 5 and contains 2 and 3 at least once in
283 // other positions
284
285 template MySequenceOfType MyTemplate12 := { permutation (MyInt3, 2, 3 ), 5 };
286 // matches any sequence of 4 integers that ends with 5 and contains 2 and 3 at least once in
287 // other positions
288
289 template MySequenceOfType MyTemplate13 := { permutation (MyInt4, 2, 3 ), 5 };
290 // matches any sequence of integers that ends with 5 and containing 2 and 3 at least once in
291 // other positions
292
293 template MySequenceOfType MyTemplate14 := { permutation (MyInt3, 2, ? ), 5 };
294 // matches any sequence of 4 integers that ends with 5 and contains 2 at least once in
295 // other positions
296
297 template MySequenceOfType MyTemplate15 := { permutation (MyInt4, 2, * ), 5 };
298 // matches any sequence of integers that ends with 5 and contains 2 at least once in
299 // other positions
300
301//EXAMPLE 2:
302 template RoI t_RoI1p := {1, 2, *};
303 template RoI t_RoI2p := {permutation(0, all from t_RoI1p), 4, 5};
304 // results in {permutation(0, 1, 2, *), 4, 5}
305
306testcase tc_permut() runs on A
307{
308 action("permut: ", t_RoI2p);
309}
310
311
312} // end of module
This page took 0.036017 seconds and 5 git commands to generate.