Commit | Line | Data |
---|---|---|
970ed795 | 1 | /****************************************************************************** |
d44e3c4f | 2 | * Copyright (c) 2000-2016 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 | |
d44e3c4f | 7 | * |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Kovacs, Ferenc | |
11 | * Raduly, Csaba | |
12 | * Szabados, Kristof | |
13 | * Szabo, Janos Zoltan – initial implementation | |
14 | * | |
970ed795 EL |
15 | ******************************************************************************/ |
16 | module TtemplateBitstr { | |
17 | type component templateBitstr_mycomp {}; | |
18 | type record templateBitstr_rec { | |
19 | bitstring x1, | |
20 | bitstring x2, | |
21 | bitstring x3 optional }; | |
22 | template templateBitstr_rec templateBitstr_tSpec :={ //specific values | |
23 | x1:='001'B, | |
24 | x2:='010'B, | |
25 | x3:='100'B }; | |
26 | template templateBitstr_rec templateBitstr_tList :={ //specific value and value list | |
27 | x1:='001'B, | |
28 | x2:=('010'B,'011'B,'1100'B), | |
29 | x3:='100'B }; | |
30 | template templateBitstr_rec templateBitstr_tComp :={ //specific value and compl. list | |
31 | x1:='001'B, | |
32 | x2:=complement ('11'B,'00'B,'1000'B), | |
33 | x3:='100'B }; | |
34 | template templateBitstr_rec templateBitstr_tOmit :={ //omitting values | |
35 | x1:='001'B, | |
36 | x2:='010'B, | |
37 | x3:=omit } ; | |
38 | template templateBitstr_rec templateBitstr_tAny :={ //specific and any value | |
39 | x1:='001'B, | |
40 | x2:='010'B, | |
41 | x3:=? } ; | |
42 | template templateBitstr_rec templateBitstr_tAnyorNone :={ //specific and AnyorNone value | |
43 | x1:='001'B, | |
44 | x2:='010'B, | |
45 | x3:=* }; | |
46 | template templateBitstr_rec templateBitstr_tLength1 :={ //specific value and fix length | |
47 | x1:='001'B, | |
48 | x2:='010'B, | |
49 | x3:=* length(3) }; | |
50 | template templateBitstr_rec templateBitstr_tLength2 :={ //specific value and length (range) | |
51 | x1:='001'B, | |
52 | x2:='010'B, | |
53 | x3:=? length(2..4) }; | |
54 | template templateBitstr_rec templateBitstr_tLength3 :={ //specific value and length (range, infinity) | |
55 | x1:='001'B, | |
56 | x2:='010'B, | |
57 | x3:=? length(2..infinity) }; | |
58 | template templateBitstr_rec templateBitstr_tIfpresent :={ //specific value and ifpresent | |
59 | x1:='001'B, | |
60 | x2:='010'B, | |
61 | x3:='100'B ifpresent }; | |
62 | template templateBitstr_rec templateBitstr_tLengthIfp :={ //specific value and fix length and ifpresent | |
63 | x1:='001'B, | |
64 | x2:='010'B, | |
65 | x3:= ? length(3) ifpresent}; | |
66 | template templateBitstr_rec templateBitstr_tAnyEl :={ //specific value and any element inside value | |
67 | x1:='001'B, | |
68 | x2:='010'B, | |
69 | x3:='10?'B } ; | |
70 | template templateBitstr_rec templateBitstr_tAnyorNoneEl :={ //specific value and Any number of elements or none inside value | |
71 | x1:='001'B, | |
72 | x2:='010'B, | |
73 | x3:='10*'B }; | |
74 | ||
75 | template bitstring t_param1(templateBitstr_rec par) := substr(par.x1, 0, 1); // parameterised template | |
76 | ||
77 | testcase templateBitstrSpec() runs on templateBitstr_mycomp { | |
78 | var templateBitstr_rec x1,x2; //specific value | |
79 | x1:={ x1:='001'B, x2:='010'B, x3:='100'B }; | |
80 | x2:={ x1:='00'B, x2:='010'B, x3:='100'B }; | |
81 | //match | |
82 | if (match(x1,templateBitstr_tSpec)) {setverdict(pass);} | |
83 | else {setverdict(fail);} | |
84 | //no match | |
85 | if (not(match(x2,templateBitstr_tSpec))) {setverdict(pass);} | |
86 | else {setverdict(fail);} | |
87 | } | |
88 | ||
89 | testcase templateBitstrList() runs on templateBitstr_mycomp { | |
90 | var templateBitstr_rec x1,x2,x3; //value list | |
91 | x1:={ x1:='001'B, x2:='010'B, x3:='100'B }; | |
92 | x2:={ x1:='001'B, x2:='00'B, x3:='100'B }; | |
93 | x3:={ x1:='1'B, x2:='010'B, x3:='100'B }; | |
94 | //match | |
95 | if (match(x1,templateBitstr_tList)) {setverdict(pass);} | |
96 | else {setverdict(fail);} | |
97 | //no match: out of list | |
98 | if (not(match(x2,templateBitstr_tList))) {setverdict(pass);} | |
99 | else {setverdict(fail);} | |
100 | //no match: other field | |
101 | if (not(match(x3,templateBitstr_tList))) {setverdict(pass);} | |
102 | else {setverdict(fail);} | |
103 | } | |
104 | ||
105 | testcase templateBitstrComp() runs on templateBitstr_mycomp { | |
106 | var templateBitstr_rec x1,x2,x3; //complemented list | |
107 | x1:={ x1:='001'B, x2:='010'B, x3:='100'B }; | |
108 | x2:={ x1:='001'B, x2:='11'B, x3:='100'B }; | |
109 | x3:={ x1:='11'B, x2:='010'B, x3:='100'B }; | |
110 | //match | |
111 | if (match(x1,templateBitstr_tComp)) {setverdict(pass);} | |
112 | else {setverdict(fail);} | |
113 | //no match: in the list | |
114 | if (not(match(x2,templateBitstr_tComp))) {setverdict(pass);} | |
115 | else {setverdict(fail);} | |
116 | //no match: other field | |
117 | if (not(match(x3,templateBitstr_tComp))) {setverdict(pass);} | |
118 | else {setverdict(fail);} | |
119 | } | |
120 | ||
121 | testcase templateBitstrOmit() runs on templateBitstr_mycomp { | |
122 | var templateBitstr_rec x1,x2,x3; //omitting value | |
123 | x1:={ x1:='001'B, x2:='010'B, x3:=omit }; | |
124 | x2:={ x1:='001'B, x2:='010'B, x3:='000'B }; | |
125 | x3:={ x1:='00'B, x2:='010'B, x3:=omit }; | |
126 | //match | |
127 | if (match(x1,templateBitstr_tOmit)) {setverdict(pass);} | |
128 | else {setverdict(fail);} | |
129 | //no match: not omitted | |
130 | if (not(match(x2,templateBitstr_tOmit))) {setverdict(pass);} | |
131 | else {setverdict(fail);} | |
132 | //no match: other field | |
133 | if (not(match(x3,templateBitstr_tOmit))) {setverdict(pass);} | |
134 | else {setverdict(fail);} | |
135 | } | |
136 | ||
137 | testcase templateBitstrAny() runs on templateBitstr_mycomp { | |
138 | var templateBitstr_rec x1,x2,x3; //any value | |
139 | x1:={ x1:='001'B, x2:='010'B, x3:='111'B }; | |
140 | x2:={ x1:='001'B, x2:='010'B, x3:=omit }; | |
141 | x3:={ x1:='0'B, x2:='010'B, x3:='10'B }; | |
142 | //match | |
143 | if (match(x1,templateBitstr_tAny)) {setverdict(pass);} | |
144 | else {setverdict(fail);} | |
145 | //no match: field omitted | |
146 | if (not(match(x2,templateBitstr_tAny))) {setverdict(pass);} | |
147 | else {setverdict(fail);} | |
148 | //no match: other field | |
149 | if (not(match(x3,templateBitstr_tAny))) {setverdict(pass);} | |
150 | else {setverdict(fail);} | |
151 | } | |
152 | ||
153 | testcase templateBitstrAnyorNone() runs on templateBitstr_mycomp { | |
154 | var templateBitstr_rec x1,x2,x3; //AnyorNone value | |
155 | x1:={ x1:='001'B, x2:='010'B, x3:=omit }; | |
156 | x2:={ x1:='001'B, x2:='010'B, x3:='100'B }; | |
157 | x3:={ x1:='1'B, x2:='010'B, x3:=omit }; | |
158 | //match: omitted | |
159 | if (match(x1,templateBitstr_tAnyorNone)) {setverdict(pass);} | |
160 | else {setverdict(fail);} | |
161 | //match: value | |
162 | if (match(x2,templateBitstr_tAnyorNone)) {setverdict(pass);} | |
163 | else {setverdict(fail);} | |
164 | //no match: other field | |
165 | if (not(match(x3,templateBitstr_tAnyorNone))) {setverdict(pass);} | |
166 | else {setverdict(fail);} | |
167 | } | |
168 | ||
169 | testcase templateBitstrLength1() runs on templateBitstr_mycomp { | |
170 | var templateBitstr_rec x1,x2,x3,x4; //length (fix) | |
171 | x1:={ x1:='001'B, x2:='010'B, x3:='111'B }; | |
172 | x2:={ x1:='001'B, x2:='010'B, x3:=omit }; | |
173 | x3:={ x1:='001'B, x2:='010'B, x3:='10'B }; | |
174 | x4:={ x1:='0010'B, x2:='010'B, x3:='111'B }; | |
175 | //match: proper length | |
176 | if (match(x1,templateBitstr_tLength1)) {setverdict(pass);} | |
177 | else {setverdict(fail);} | |
178 | //match: omitted | |
179 | if (match(x2,templateBitstr_tLength1)) {setverdict(pass);} | |
180 | else {setverdict(fail);} | |
181 | // no match: not proper length | |
182 | if (not(match(x3,templateBitstr_tLength1))) {setverdict(pass);} | |
183 | else {setverdict(fail);} | |
184 | //no match: other field | |
185 | if (not(match(x4,templateBitstr_tLength1))) {setverdict(pass);} | |
186 | else {setverdict(fail);} | |
187 | } | |
188 | ||
189 | testcase templateBitstrLength2() runs on templateBitstr_mycomp { | |
190 | var templateBitstr_rec x1,x2,x3; //length (range) | |
191 | x1:={ x1:='001'B, x2:='010'B, x3:='111'B }; | |
192 | x2:={ x1:='001'B, x2:='010'B, x3:='1'B }; | |
193 | x3:={ x1:='0010'B, x2:='010'B, x3:='111'B }; | |
194 | //match | |
195 | if (match(x1,templateBitstr_tLength2)) {setverdict(pass);} | |
196 | else {setverdict(fail);} | |
197 | // no match: not proper length | |
198 | if (not(match(x2,templateBitstr_tLength2))) {setverdict(pass);} | |
199 | else {setverdict(fail);} | |
200 | //no match: other field | |
201 | if (not(match(x3,templateBitstr_tLength2))) {setverdict(pass);} | |
202 | else {setverdict(fail);} | |
203 | } | |
204 | ||
205 | testcase templateBitstrLength3() runs on templateBitstr_mycomp { | |
206 | var templateBitstr_rec x1,x2,x3; //length (range, infinity) | |
207 | x1:={ x1:='001'B, x2:='010'B, x3:='111'B }; | |
208 | x2:={ x1:='001'B, x2:='010'B, x3:='1'B }; | |
209 | x3:={ x1:='0010'B, x2:='010'B, x3:='111'B }; | |
210 | //match | |
211 | if (match(x1,templateBitstr_tLength3)) {setverdict(pass);} | |
212 | else {setverdict(fail);} | |
213 | // no match: not proper length | |
214 | if (not(match(x2,templateBitstr_tLength3))) {setverdict(pass);} | |
215 | else {setverdict(fail);} | |
216 | //no match: other field | |
217 | if (not(match(x3,templateBitstr_tLength3))) {setverdict(pass);} | |
218 | else {setverdict(fail);} | |
219 | } | |
220 | ||
221 | testcase templateBitstrIfpresent() runs on templateBitstr_mycomp { | |
222 | var templateBitstr_rec x1,x2,x3,x4; //ifpresent | |
223 | x1:={ x1:='001'B, x2:='010'B, x3:='100'B }; | |
224 | x2:={ x1:='001'B, x2:='010'B, x3:=omit }; | |
225 | x3:={ x1:='001'B, x2:='010'B, x3:='000'B }; | |
226 | x4:={ x1:='00'B, x2:='010'B, x3:=omit }; | |
227 | //match: present and match | |
228 | if (match(x1,templateBitstr_tIfpresent)) {setverdict(pass);} | |
229 | else {setverdict(fail);} | |
230 | //match: not present | |
231 | if (match(x2,templateBitstr_tIfpresent)) {setverdict(pass);} | |
232 | else {setverdict(fail);} | |
233 | //no match: present and not match | |
234 | if (not(match(x3,templateBitstr_tIfpresent))) {setverdict(pass);} | |
235 | else {setverdict(fail);} | |
236 | //no match: other field | |
237 | if (not(match(x4,templateBitstr_tIfpresent))) {setverdict(pass);} | |
238 | else {setverdict(fail);} | |
239 | } | |
240 | ||
241 | testcase templateBitstrLengthIfp() runs on templateBitstr_mycomp { | |
242 | var templateBitstr_rec x1,x2,x3,x4; //length (fix), ifpresent | |
243 | x1:={ x1:='001'B, x2:='010'B, x3:='111'B }; | |
244 | x2:={ x1:='001'B, x2:='010'B, x3:=omit }; | |
245 | x3:={ x1:='001'B, x2:='010'B, x3:='10'B }; | |
246 | x4:={ x1:='0010'B, x2:='010'B, x3:='111'B }; | |
247 | //match: proper length | |
248 | if (match(x1,templateBitstr_tLengthIfp)) {setverdict(pass);} | |
249 | else {setverdict(fail);} | |
250 | //match: omitted | |
251 | if (match(x2,templateBitstr_tLengthIfp)) {setverdict(pass);} | |
252 | else {setverdict(fail);} | |
253 | // no match: not proper length | |
254 | if (not(match(x3,templateBitstr_tLengthIfp))) {setverdict(pass);} | |
255 | else {setverdict(fail);} | |
256 | //no match: other field | |
257 | if (not(match(x4,templateBitstr_tLengthIfp))) {setverdict(pass);} | |
258 | else {setverdict(fail);} | |
259 | } | |
260 | ||
261 | testcase templateBitstrAnyEl() runs on templateBitstr_mycomp { | |
262 | var templateBitstr_rec x1,x2,x3,x4,x5; //any element | |
263 | x1:={ x1:='001'B, x2:='010'B, x3:='101'B }; | |
264 | x2:={ x1:='001'B, x2:='010'B, x3:='10'B }; | |
265 | x3:={ x1:='001'B, x2:='010'B, x3:='1000'B }; | |
266 | x4:={ x1:='001'B, x2:='010'B, x3:='001'B }; | |
267 | x5:={ x1:='0'B, x2:='010'B, x3:='101'B }; | |
268 | //match | |
269 | if (match(x1,templateBitstr_tAnyEl)) {setverdict(pass);} | |
270 | else {setverdict(fail);} | |
271 | //no match: no element | |
272 | if (not(match(x2,templateBitstr_tAnyEl))) {setverdict(pass);} | |
273 | else {setverdict(fail);} | |
274 | //no match: two element | |
275 | if (not(match(x3,templateBitstr_tAnyEl))) {setverdict(pass);} | |
276 | else {setverdict(fail);} | |
277 | //no match: wrong element | |
278 | if (not(match(x4,templateBitstr_tAnyEl))) {setverdict(pass);} | |
279 | else {setverdict(fail);} | |
280 | //no match: other field | |
281 | if (not(match(x5,templateBitstr_tAnyEl))) {setverdict(pass);} | |
282 | else {setverdict(fail);} | |
283 | } | |
284 | ||
285 | testcase templateBitstrAnyorNoneEl() runs on templateBitstr_mycomp { | |
286 | var templateBitstr_rec x1,x2,x3,x4,x5; //Any number of elements or none | |
287 | x1:={ x1:='001'B, x2:='010'B, x3:='10'B }; | |
288 | x2:={ x1:='001'B, x2:='010'B, x3:='100'B }; | |
289 | x3:={ x1:='001'B, x2:='010'B, x3:='1011'B }; | |
290 | x4:={ x1:='001'B, x2:='010'B, x3:='110'B }; | |
291 | x5:={ x1:='1'B, x2:='010'B, x3:='100'B }; | |
292 | //match: no element | |
293 | if (match(x1,templateBitstr_tAnyorNoneEl)) {setverdict(pass);} | |
294 | else {setverdict(fail);} | |
295 | //match: one element | |
296 | if (match(x2,templateBitstr_tAnyorNoneEl)) {setverdict(pass);} | |
297 | else {setverdict(fail);} | |
298 | //match: two element | |
299 | if (match(x3,templateBitstr_tAnyorNoneEl)) {setverdict(pass);} | |
300 | else {setverdict(fail);} | |
301 | //no match: other element | |
302 | if (not(match(x4,templateBitstr_tAnyorNoneEl))) {setverdict(pass);} | |
303 | else {setverdict(fail);} | |
304 | //no match: other field | |
305 | if (not(match(x5,templateBitstr_tAnyorNoneEl))) {setverdict(pass);} | |
306 | else {setverdict(fail);} | |
307 | } | |
308 | ||
309 | testcase CR_TR00018474() runs on templateBitstr_mycomp { | |
310 | // Indexing of string template variables. | |
311 | var template bitstring vtb1 := '0011110000'B | |
312 | var template bitstring vtb2 := '0*?1'B // It's a pattern, cannot be indexed, runtime error. | |
313 | vtb1[0] := '1'B | |
314 | if (match('1011110000'B, vtb1)) { setverdict(pass) } else { setverdict(fail) } | |
315 | vtb1[0] := '1'B // Indexed assignment notation cannot be used here. | |
316 | vtb1[1] := '0'B // Still works, nothing special. | |
317 | if (match('1011110000'B, vtb1)) { setverdict(pass) } else { setverdict(fail) } | |
318 | } | |
319 | ||
320 | control { | |
321 | execute(templateBitstrSpec()); | |
322 | execute(templateBitstrList()); | |
323 | execute(templateBitstrComp()); | |
324 | execute(templateBitstrOmit()); | |
325 | execute(templateBitstrAny()); | |
326 | execute(templateBitstrAnyorNone()); | |
327 | execute(templateBitstrLength1()); | |
328 | execute(templateBitstrLength2()); | |
329 | execute(templateBitstrLength3()); | |
330 | execute(templateBitstrIfpresent()); | |
331 | execute(templateBitstrLengthIfp()); | |
332 | execute(templateBitstrAnyEl()); | |
333 | execute(templateBitstrAnyorNoneEl()); | |
334 | execute(CR_TR00018474()); | |
335 | } | |
336 | } |