Commit | Line | Data |
---|---|---|
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 | ******************************************************************************/ | |
8 | module TtemplateCharstr { | |
9 | type component templateCharstr_mycomp {}; | |
10 | type record templateCharstr_rec { | |
11 | charstring x1, | |
12 | charstring x2, | |
13 | charstring x3 optional }; | |
14 | template templateCharstr_rec templateCharstr_tSpec :={ //specific values | |
15 | x1:="00AA", | |
16 | x2:="01AA", | |
17 | x3:="10AA" }; | |
18 | template templateCharstr_rec templateCharstr_tList :={ //specific value and value list | |
19 | x1:="00AA", | |
20 | x2:=("01AA","01AB","11AC"), | |
21 | x3:="10AA" }; | |
22 | template templateCharstr_rec templateCharstr_tComp :={ //specific value and compl. list | |
23 | x1:="00AA", | |
24 | x2:=complement ("11","0A","1BC0"), | |
25 | x3:="10AA" }; | |
26 | template templateCharstr_rec templateCharstr_tOmit :={ //omitting values | |
27 | x1:="00AA", | |
28 | x2:="01AA", | |
29 | x3:=omit } ; | |
30 | template templateCharstr_rec templateCharstr_tAny :={ //specific and any value | |
31 | x1:="00AA", | |
32 | x2:="01AA", | |
33 | x3:=? } ; | |
34 | template templateCharstr_rec templateCharstr_tAnyorNone :={ //specific and AnyorNone value | |
35 | x1:="00AA", | |
36 | x2:="01AA", | |
37 | x3:=* }; | |
38 | template templateCharstr_rec templateCharstr_tLength1 :={ //specific value and fix length | |
39 | x1:="00AA", | |
40 | x2:="01AA", | |
41 | x3:=* length(3) }; | |
42 | template templateCharstr_rec templateCharstr_tLength2 :={ //specific value and length (range) | |
43 | x1:="00AA", | |
44 | x2:="01AA", | |
45 | x3:=? length(2..4) }; | |
46 | template templateCharstr_rec templateCharstr_tLength3 :={ //specific value and length (range, infinity) | |
47 | x1:="00AA", | |
48 | x2:="01AA", | |
49 | x3:=? length(2..infinity) }; | |
50 | template templateCharstr_rec templateCharstr_tIfpresent :={ //specific value and ifpresent | |
51 | x1:="00AA", | |
52 | x2:="01AA", | |
53 | x3:="10AA" ifpresent }; | |
54 | template templateCharstr_rec templateCharstr_tLengthIfp :={ //specific value and fix length and ifpresent | |
55 | x1:="00AA", | |
56 | x2:="01AA", | |
57 | x3:=? length(3) ifpresent}; | |
58 | template templateCharstr_rec templateCharstr_tAnyEl :={ //specific value and any element inside value | |
59 | x1:="00AA", | |
60 | x2:="01AA", | |
61 | x3:= pattern "10?" } ; | |
62 | template templateCharstr_rec templateCharstr_tAnyorNoneEl :={ //specific value and Any number of elements or none inside value | |
63 | x1:="00AA", | |
64 | x2:="01AA", | |
65 | x3:= pattern "10*" }; | |
66 | template templateCharstr_rec templateCharstr_tRange1 :={ //specific value and Range | |
67 | x1:="1", | |
68 | x2:=("2" .."4"), | |
69 | x3:="3" }; | |
70 | template templateCharstr_rec templateCharstr_tRange2 :={ //specific value and Range | |
71 | x1:="1", | |
72 | x2:=("2" .. "4"), | |
73 | x3:="3" }; | |
74 | template templateCharstr_rec templateCharstr_tRange3 :={ //specific value and Range | |
75 | x1:="1", | |
76 | x2:=("3" .. int2char(127)), | |
77 | x3:="3" }; | |
78 | template templateCharstr_rec templateCharstr_tRange4 :={ //specific value and Range | |
79 | x1:="1", | |
80 | x2:=(int2char(0) .. "4"), | |
81 | x3:="3" }; | |
82 | template templateCharstr_rec templateCharstr_tRepeat := { | |
83 | x1:= pattern "6#3", // precisely 3 | |
84 | x2:= pattern "6#(,)", // any number | |
85 | x3:= pattern "6#(3)" }; // precisely 3 | |
86 | template templateCharstr_rec templateCharstr_tRepeatFull := { | |
87 | x1:= pattern "6#(3,)", // at least 3 | |
88 | x2:= pattern "6#(,3)", // at most 3 | |
89 | x3:= pattern "6#(3,3)" }; // precisely 3 | |
feade998 | 90 | template templateCharstr_rec templateCharstr_tPattern := { |
91 | x1 := pattern "abc?xyz", | |
92 | x2 := pattern @nocase "abc?xyz", | |
93 | x3 := pattern @nocase "abc*xyz" }; | |
970ed795 EL |
94 | |
95 | testcase templateCharstrSpec() runs on templateCharstr_mycomp { | |
96 | var templateCharstr_rec x1,x2; //specific value | |
97 | x1:={ x1:="00AA", x2:="01AA", x3:="10AA" }; | |
98 | x2:={ x1:="00BC", x2:="01AA", x3:="10AA" }; | |
99 | //match | |
100 | if (match(x1,templateCharstr_tSpec)) {setverdict(pass);} | |
101 | else {setverdict(fail);} | |
102 | //no match | |
103 | if (not(match(x2,templateCharstr_tSpec))) {setverdict(pass);} | |
104 | else {setverdict(fail);} | |
105 | } | |
106 | ||
107 | testcase templateCharstrList() runs on templateCharstr_mycomp { | |
108 | var templateCharstr_rec x1,x2,x3; //value list | |
109 | x1:={ x1:="00AA", x2:="01AA", x3:="10AA" }; | |
110 | x2:={ x1:="00AA", x2:="00", x3:="10AA" }; | |
111 | x3:={ x1:="1D", x2:="01AA", x3:="10AA" }; | |
112 | //match | |
113 | if (match(x1,templateCharstr_tList)) {setverdict(pass);} | |
114 | else {setverdict(fail);} | |
115 | //no match: out of list | |
116 | if (not(match(x2,templateCharstr_tList))) {setverdict(pass);} | |
117 | else {setverdict(fail);} | |
118 | //no match: other field | |
119 | if (not(match(x3,templateCharstr_tList))) {setverdict(pass);} | |
120 | else {setverdict(fail);} | |
121 | } | |
122 | ||
123 | testcase templateCharstrComp() runs on templateCharstr_mycomp { | |
124 | var templateCharstr_rec x1,x2,x3; //complemented list | |
125 | x1:={ x1:="00AA", x2:="01AA", x3:="10AA" }; | |
126 | x2:={ x1:="00AA", x2:="0A", x3:="10AA" }; | |
127 | x3:={ x1:="11AA", x2:="01AA", x3:="10AA" }; | |
128 | //match | |
129 | if (match(x1,templateCharstr_tComp)) {setverdict(pass);} | |
130 | else {setverdict(fail);} | |
131 | //no match: in the list | |
132 | if (not(match(x2,templateCharstr_tComp))) {setverdict(pass);} | |
133 | else {setverdict(fail);} | |
134 | //no match: other field | |
135 | if (not(match(x3,templateCharstr_tComp))) {setverdict(pass);} | |
136 | else {setverdict(fail);} | |
137 | } | |
138 | ||
139 | testcase templateCharstrOmit() runs on templateCharstr_mycomp { | |
140 | var templateCharstr_rec x1,x2,x3; //omitting value | |
141 | x1:={ x1:="00AA", x2:="01AA", x3:=omit }; | |
142 | x2:={ x1:="00AA", x2:="01AA", x3:="AB" }; | |
143 | x3:={ x1:="00DE", x2:="01AA", x3:=omit }; | |
144 | //match | |
145 | if (match(x1,templateCharstr_tOmit)) {setverdict(pass);} | |
146 | else {setverdict(fail);} | |
147 | //no match: not omitted | |
148 | if (not(match(x2,templateCharstr_tOmit))) {setverdict(pass);} | |
149 | else {setverdict(fail);} | |
150 | //no match: other field | |
151 | if (not(match(x3,templateCharstr_tOmit))) {setverdict(pass);} | |
152 | else {setverdict(fail);} | |
153 | } | |
154 | ||
155 | testcase templateCharstrAny() runs on templateCharstr_mycomp { | |
156 | var templateCharstr_rec x1,x2,x3; //any value | |
157 | x1:={ x1:="00AA", x2:="01AA", x3:="ABCD" }; | |
158 | x2:={ x1:="00AA", x2:="01AA", x3:=omit }; | |
159 | x3:={ x1:="0A", x2:="01AA", x3:="ABCD" }; | |
160 | //match | |
161 | if (match(x1,templateCharstr_tAny)) {setverdict(pass);} | |
162 | else {setverdict(fail);} | |
163 | //no match: field omitted | |
164 | if (not(match(x2,templateCharstr_tAny))) {setverdict(pass);} | |
165 | else {setverdict(fail);} | |
166 | //no match: other field | |
167 | if (not(match(x3,templateCharstr_tAny))) {setverdict(pass);} | |
168 | else {setverdict(fail);} | |
169 | } | |
170 | ||
171 | testcase templateCharstrAnyorNone() runs on templateCharstr_mycomp { | |
172 | var templateCharstr_rec x1,x2,x3; //AnyorNone value | |
173 | x1:={ x1:="00AA", x2:="01AA", x3:=omit }; | |
174 | x2:={ x1:="00AA", x2:="01AA", x3:="10AB" }; | |
175 | x3:={ x1:="1C", x2:="01AA", x3:=omit }; | |
176 | //match: omitted | |
177 | if (match(x1,templateCharstr_tAnyorNone)) {setverdict(pass);} | |
178 | else {setverdict(fail);} | |
179 | //match: value | |
180 | if (match(x2,templateCharstr_tAnyorNone)) {setverdict(pass);} | |
181 | else {setverdict(fail);} | |
182 | //no match: other field | |
183 | if (not(match(x3,templateCharstr_tAnyorNone))) {setverdict(pass);} | |
184 | else {setverdict(fail);} | |
185 | } | |
186 | ||
187 | testcase templateCharstrLength1() runs on templateCharstr_mycomp { | |
188 | var templateCharstr_rec x1,x2,x3,x4; //length (fix) | |
189 | x1:={ x1:="00AA", x2:="01AA", x3:="abc" }; | |
190 | x2:={ x1:="00AA", x2:="01AA", x3:="abc" }; | |
191 | x3:={ x1:="00AA", x2:="01AA", x3:="1D" }; | |
192 | x4:={ x1:="001A", x2:="01AA", x3:="abc" }; | |
193 | //match: proper length | |
194 | if (match(x1,templateCharstr_tLength1)) {setverdict(pass);} | |
195 | else {setverdict(fail);} | |
196 | //match: omitted | |
197 | if (match(x2,templateCharstr_tLength1)) {setverdict(pass);} | |
198 | else {setverdict(fail);} | |
199 | // no match: not proper length | |
200 | if (not(match(x3,templateCharstr_tLength1))) {setverdict(pass);} | |
201 | else {setverdict(fail);} | |
202 | //no match: other field | |
203 | if (not(match(x4,templateCharstr_tLength1))) {setverdict(pass);} | |
204 | else {setverdict(fail);} | |
205 | } | |
206 | ||
207 | testcase templateCharstrLength2() runs on templateCharstr_mycomp { | |
208 | var templateCharstr_rec x1,x2,x3; //length (range) | |
209 | x1:={ x1:="00AA", x2:="01AA", x3:="abcd" }; | |
210 | x2:={ x1:="00AA", x2:="01AA", x3:="a" }; | |
211 | x3:={ x1:="001A", x2:="01AA", x3:="abc" }; | |
212 | //match | |
213 | if (match(x1,templateCharstr_tLength2)) {setverdict(pass);} | |
214 | else {setverdict(fail);} | |
215 | // no match: not proper length | |
216 | if (not(match(x2,templateCharstr_tLength2))) {setverdict(pass);} | |
217 | else {setverdict(fail);} | |
218 | //no match: other field | |
219 | if (not(match(x3,templateCharstr_tLength2))) {setverdict(pass);} | |
220 | else {setverdict(fail);} | |
221 | } | |
222 | ||
223 | testcase templateCharstrLength3() runs on templateCharstr_mycomp { | |
224 | var templateCharstr_rec x1,x2,x3; //length (range, infinity) | |
225 | x1:={ x1:="00AA", x2:="01AA", x3:="abcd" }; | |
226 | x2:={ x1:="00AA", x2:="01AA", x3:="a" }; | |
227 | x3:={ x1:="001A", x2:="01AA", x3:="abc" }; | |
228 | //match | |
229 | if (match(x1,templateCharstr_tLength3)) {setverdict(pass);} | |
230 | else {setverdict(fail);} | |
231 | // no match: not proper length | |
232 | if (not(match(x2,templateCharstr_tLength3))) {setverdict(pass);} | |
233 | else {setverdict(fail);} | |
234 | //no match: other field | |
235 | if (not(match(x3,templateCharstr_tLength3))) {setverdict(pass);} | |
236 | else {setverdict(fail);} | |
237 | } | |
238 | testcase templateCharstrIfpresent() runs on templateCharstr_mycomp { | |
239 | var templateCharstr_rec x1,x2,x3,x4; //ifpresent | |
240 | x1:={ x1:="00AA", x2:="01AA", x3:="10AA" }; | |
241 | x2:={ x1:="00AA", x2:="01AA", x3:=omit }; | |
242 | x3:={ x1:="00AA", x2:="01AA", x3:="00AA" }; | |
243 | x4:={ x1:="00", x2:="01AA", x3:=omit }; | |
244 | //match: present and match | |
245 | if (match(x1,templateCharstr_tIfpresent)) {setverdict(pass);} | |
246 | else {setverdict(fail);} | |
247 | //match: not present | |
248 | if (match(x2,templateCharstr_tIfpresent)) {setverdict(pass);} | |
249 | else {setverdict(fail);} | |
250 | //no match: present and not match | |
251 | if (not(match(x3,templateCharstr_tIfpresent))) {setverdict(pass);} | |
252 | else {setverdict(fail);} | |
253 | //no match: other field | |
254 | if (not(match(x4,templateCharstr_tIfpresent))) {setverdict(pass);} | |
255 | else {setverdict(fail);} | |
256 | } | |
257 | ||
258 | testcase templateCharstrLengthIfp() runs on templateCharstr_mycomp { | |
259 | var templateCharstr_rec x1,x2,x3,x4; //length (fix), ifpresent | |
260 | x1:={ x1:="00AA", x2:="01AA", x3:="abc" }; | |
261 | x2:={ x1:="00AA", x2:="01AA", x3:="abc" }; | |
262 | x3:={ x1:="00AA", x2:="01AA", x3:="1D" }; | |
263 | x4:={ x1:="001A", x2:="01AA", x3:="abc" }; | |
264 | //match: proper length | |
265 | if (match(x1,templateCharstr_tLengthIfp)) {setverdict(pass);} | |
266 | else {setverdict(fail);} | |
267 | //match: omitted | |
268 | if (match(x2,templateCharstr_tLengthIfp)) {setverdict(pass);} | |
269 | else {setverdict(fail);} | |
270 | // no match: not proper length | |
271 | if (not(match(x3,templateCharstr_tLengthIfp))) {setverdict(pass);} | |
272 | else {setverdict(fail);} | |
273 | //no match: other field | |
274 | if (not(match(x4,templateCharstr_tLengthIfp))) {setverdict(pass);} | |
275 | else {setverdict(fail);} | |
276 | } | |
277 | ||
278 | testcase templateCharstrAnyEl() runs on templateCharstr_mycomp { | |
279 | var templateCharstr_rec x1,x2,x3,x4,x5; //any element | |
280 | x1:={ x1:="00AA", x2:="01AA", x3:="10a" }; | |
281 | x2:={ x1:="00AA", x2:="01AA", x3:="10" }; | |
282 | x3:={ x1:="00AA", x2:="01AA", x3:="10Aa" }; | |
283 | x4:={ x1:="00AA", x2:="01AA", x3:="12A" }; | |
284 | x5:={ x1:="0A", x2:="01AA", x3:="10a" }; | |
285 | //match | |
286 | if (match(x1,templateCharstr_tAnyEl)) {setverdict(pass);} | |
287 | else {setverdict(fail);} | |
288 | //no match: no element | |
289 | if (not(match(x2,templateCharstr_tAnyEl))) {setverdict(pass);} | |
290 | else {setverdict(fail);} | |
291 | //no match: two element | |
292 | if (not(match(x3,templateCharstr_tAnyEl))) {setverdict(pass);} | |
293 | else {setverdict(fail);} | |
294 | //no match: wrong element | |
295 | if (not(match(x4,templateCharstr_tAnyEl))) {setverdict(pass);} | |
296 | else {setverdict(fail);} | |
297 | //no match: other field | |
298 | if (not(match(x5,templateCharstr_tAnyEl))) {setverdict(pass);} | |
299 | else {setverdict(fail);} | |
300 | } | |
301 | ||
302 | testcase templateCharstrAnyorNoneEl() runs on templateCharstr_mycomp { | |
303 | var templateCharstr_rec x1,x2,x3,x4,x5; //Any number of elements or none | |
304 | x1:={ x1:="00AA", x2:="01AA", x3:="10" }; | |
305 | x2:={ x1:="00AA", x2:="01AA", x3:="10k" }; | |
306 | x3:={ x1:="00AA", x2:="01AA", x3:="10Aa" }; | |
307 | x4:={ x1:="00AA", x2:="01AA", x3:="11a" }; | |
308 | x5:={ x1:="1A", x2:="01AA", x3:="10a" }; | |
309 | //match: no element | |
310 | if (match(x1,templateCharstr_tAnyorNoneEl)) {setverdict(pass);} | |
311 | else {setverdict(fail);} | |
312 | //match: one element | |
313 | if (match(x2,templateCharstr_tAnyorNoneEl)) {setverdict(pass);} | |
314 | else {setverdict(fail);} | |
315 | //match: two element | |
316 | if (match(x3,templateCharstr_tAnyorNoneEl)) {setverdict(pass);} | |
317 | else {setverdict(fail);} | |
318 | //no match: wrong element | |
319 | if (not(match(x4,templateCharstr_tAnyorNoneEl))) {setverdict(pass);} | |
320 | else {setverdict(fail);} | |
321 | //no match: other field | |
322 | if (not(match(x5,templateCharstr_tAnyorNoneEl))) {setverdict(pass);} | |
323 | else {setverdict(fail);} | |
324 | } | |
325 | ||
326 | ||
327 | testcase templateCharstrRange1() runs on templateCharstr_mycomp { | |
328 | var templateCharstr_rec x1,x2,x3; //Range ( .. ) | |
329 | x1:={ x1:="1", x2:="2", x3:="3" }; | |
330 | x2:={ x1:="1", x2:="5", x3:="3" }; | |
331 | x3:={ x1:="2", x2:="2", x3:="3" }; | |
332 | //match | |
333 | if (match(x1,templateCharstr_tRange1)) {setverdict(pass);} | |
334 | else {setverdict(fail);} | |
335 | //no match: out of range | |
336 | if (not(match(x2,templateCharstr_tRange1))) {setverdict(pass);} | |
337 | else {setverdict(fail);} | |
338 | //no match: other field | |
339 | if (not(match(x3,templateCharstr_tRange1))) {setverdict(pass);} | |
340 | else {setverdict(fail);} | |
341 | } | |
342 | ||
343 | testcase templateCharstrRange2() runs on templateCharstr_mycomp { | |
344 | var templateCharstr_rec x1,x2,x3; //Range ( to ) | |
345 | x1:={ x1:="1", x2:="2", x3:="3" }; | |
346 | x2:={ x1:="1", x2:="5", x3:="3"}; | |
347 | x3:={ x1:="2", x2:="2", x3:="3" }; | |
348 | //match | |
349 | if (match(x1,templateCharstr_tRange2)) {setverdict(pass);} | |
350 | else {setverdict(fail);} | |
351 | //no match: out of range | |
352 | if (not(match(x2,templateCharstr_tRange2))) {setverdict(pass);} | |
353 | else {setverdict(fail);} | |
354 | //no match: other field | |
355 | if (not(match(x3,templateCharstr_tRange2))) {setverdict(pass);} | |
356 | else {setverdict(fail);} | |
357 | } | |
358 | ||
359 | testcase templateCharstrRange3() runs on templateCharstr_mycomp { | |
360 | var templateCharstr_rec x1,x2,x3; //Range, with infinity | |
361 | x1:={ x1:="1", x2:="8", x3:="3" }; | |
362 | x2:={ x1:="1", x2:="2", x3:="3" }; | |
363 | x3:={ x1:="2", x2:="2", x3:="3" }; | |
364 | //match | |
365 | if (match(x1,templateCharstr_tRange3)) {setverdict(pass);} | |
366 | else {setverdict(fail);} | |
367 | //no match: out of range | |
368 | if (not(match(x2,templateCharstr_tRange3))) {setverdict(pass);} | |
369 | else {setverdict(fail);} | |
370 | //no match: other field | |
371 | if (not(match(x3,templateCharstr_tRange3))) {setverdict(pass);} | |
372 | else {setverdict(fail);} | |
373 | } | |
374 | ||
375 | testcase templateCharstrRange4() runs on templateCharstr_mycomp { | |
376 | var templateCharstr_rec x1,x2,x3; //Range with - infinity | |
377 | x1:={ x1:="1", x2:="2", x3:="3" }; | |
378 | x2:={ x1:="1", x2:="5", x3:="3" }; | |
379 | x3:={ x1:="2", x2:="2", x3:="3" }; | |
380 | //match | |
381 | if (match(x1,templateCharstr_tRange4)) {setverdict(pass);} | |
382 | else {setverdict(fail);} | |
383 | //no match: out of range | |
384 | if (not(match(x2,templateCharstr_tRange4))) {setverdict(pass);} | |
385 | else {setverdict(fail);} | |
386 | //no match: other field | |
387 | if (not(match(x3,templateCharstr_tRange4))) {setverdict(pass);} | |
388 | else {setverdict(fail);} | |
389 | } | |
390 | ||
391 | ||
392 | type record templateCharstr_myrec { | |
393 | charstring f1 optional, | |
394 | charstring f2 optional | |
395 | } | |
396 | ||
397 | const templateCharstr_myrec mr := { | |
398 | f1 := "b", | |
399 | f2 := "a" | |
400 | } | |
401 | ||
402 | type component templateCharstr_mycomp2 { | |
403 | const charstring x1 := ""; | |
404 | var charstring x2 := ""; | |
405 | const charstring x3 := "x"; | |
406 | var charstring x4 := "x"; | |
407 | } | |
408 | ||
409 | function tryPatternReferenceWithOptionalField(in templateCharstr_myrec p) runs on templateCharstr_mycomp2 | |
410 | { // regression test for TR 909 | |
411 | template charstring piecemeal := pattern "{p.f1}{p.f2}r"; | |
412 | if (match("bar", piecemeal)) { setverdict(pass); } | |
413 | else { setverdict(fail); } | |
414 | if (match("r", piecemeal)) { setverdict(fail); } | |
415 | else { setverdict(pass); } | |
416 | ||
417 | var template charstring piecemealv := pattern "{p.f1}{p.f2}r"; | |
418 | if (match("bar", piecemealv)) { setverdict(pass); } | |
419 | else { setverdict(fail); } | |
420 | if (match("r", piecemealv)) { setverdict(fail); } | |
421 | else { setverdict(pass); } | |
422 | } | |
423 | ||
424 | testcase templateCharstrEmptyPattern() runs on templateCharstr_mycomp2 | |
425 | { | |
426 | if (match("", pattern "")) { setverdict(pass); } | |
427 | else { setverdict(fail); } | |
428 | if (not match("x", pattern "{x1}{x2}")) { setverdict(pass); } | |
429 | else { setverdict(fail); } | |
430 | if (match("xxx", pattern "{x3}x{x4}")) { setverdict(pass); } | |
431 | else { setverdict(fail); } | |
432 | ||
433 | tryPatternReferenceWithOptionalField(mr); | |
434 | } | |
435 | ||
436 | testcase templateCharstrRepeat() runs on templateCharstr_mycomp { | |
437 | var templateCharstr_rec x1,x2,x3,x4; //repeat | |
438 | x1:={ x1:="666", x2:="", x3:="666" }; | |
439 | x2:={ x1:="6" , x2:="", x3:="666" }; | |
440 | x3:={ x1:="666", x2:="", x3:="6666" }; | |
441 | x4:={ x1:="666", x2:="6 6 6", x3:="666" }; | |
442 | //match | |
443 | if (match(x1,templateCharstr_tRepeat)) {setverdict(pass);} | |
444 | else {setverdict(fail);} | |
445 | //no match | |
446 | if (not(match(x2,templateCharstr_tRepeat))) {setverdict(pass);} | |
447 | else {setverdict(fail);} | |
448 | if (not(match(x3,templateCharstr_tRepeat))) {setverdict(pass);} | |
449 | else {setverdict(fail);} | |
450 | if (not(match(x4,templateCharstr_tRepeat))) {setverdict(pass);} | |
451 | else {setverdict(fail);} | |
452 | } | |
453 | ||
454 | testcase templateCharstrRepeatFull() runs on templateCharstr_mycomp { | |
455 | var templateCharstr_rec x0,x1,x2,x3,x4; //repeat | |
456 | x0:={ x1:="666", x2:="", x3:="666" }; // shortest possible | |
457 | x1:={ x1:="6666", x2:="666", x3:="666" }; // just over | |
458 | x2:={ x1:="6" , x2:="", x3:="666" }; // fail first | |
459 | x3:={ x1:="666", x2:="6666", x3:="6666" }; // fail second | |
460 | x4:={ x1:="666", x2:="", x3:="6" }; // fail third | |
461 | //match | |
462 | if (match(x0,templateCharstr_tRepeatFull)) {setverdict(pass);} | |
463 | else {setverdict(fail);} | |
464 | if (match(x1,templateCharstr_tRepeatFull)) {setverdict(pass);} | |
465 | else {setverdict(fail);} | |
466 | //no match | |
467 | if (not(match(x2,templateCharstr_tRepeatFull))) {setverdict(pass);} | |
468 | else {setverdict(fail);} | |
469 | if (not(match(x3,templateCharstr_tRepeatFull))) {setverdict(pass);} | |
470 | else {setverdict(fail);} | |
471 | if (not(match(x4,templateCharstr_tRepeatFull))) {setverdict(pass);} | |
472 | else {setverdict(fail);} | |
473 | } | |
474 | ||
feade998 | 475 | testcase templateCharstrPattern() runs on templateCharstr_mycomp { |
476 | var templateCharstr_rec x0, x1, x2, x3, x4; // pattern | |
477 | x0 := { x1 := "abc,xyz", x2 := "abc1xyz", x3 := "abcxyz" }; | |
478 | x1 := { x1 := "abcpxyz", x2 := "abcPxyz", x3 := "abc123abcJKL.? \txyz" }; | |
479 | x2 := { x1 := "abcxyz", x2 := "abcPxyz", x3 := "abc123xyz" }; // fail first | |
480 | x3 := { x1 := "abcpxyz", x2 := "abc123xyz", x3 := "abc123xyz" }; // fail second | |
481 | x4 := { x1 := "abcpxyz", x2 := "abcPxyz", x3 := "abc123xy z" }; // fail third | |
482 | ||
483 | // match | |
484 | if (match(x0, templateCharstr_tPattern)) { setverdict(pass); } | |
485 | else { setverdict(fail); } | |
486 | if (match(x1, templateCharstr_tPattern)) { setverdict(pass); } | |
487 | else { setverdict(fail); } | |
488 | ||
489 | // not match | |
490 | if (not match(x2, templateCharstr_tPattern)) { setverdict(pass); } | |
491 | else { setverdict(fail); } | |
492 | if (not match(x3, templateCharstr_tPattern)) { setverdict(pass); } | |
493 | else { setverdict(fail); } | |
494 | if (not match(x4, templateCharstr_tPattern)) { setverdict(pass); } | |
495 | else { setverdict(fail); } | |
496 | } | |
497 | ||
970ed795 EL |
498 | testcase TR920() runs on templateCharstr_mycomp { |
499 | var template charstring temp := pattern "[0-9]|[0-9][0-9]"; | |
500 | const charstring x := "10a"; | |
501 | ||
502 | if(match(x, temp)){ | |
503 | setverdict(fail); | |
504 | }else{ | |
505 | setverdict(pass); | |
506 | } | |
507 | } | |
508 | ||
509 | // http://t-ort.etsi.org/view.php?id=3761 | |
510 | testcase templateCharstrPatternCat() runs on templateCharstr_mycomp | |
511 | { | |
512 | if (match("aazz", pattern "a" & "*z")) { setverdict(pass); } | |
513 | else { setverdict(fail); } | |
514 | if (match("AAZZ", pattern "a*" & "z|" & "A*Z")) { setverdict(pass); } | |
515 | else { setverdict(fail); } | |
516 | if (match("AAZZ0123456789", pattern "(a*" & "z|" & "A*Z)" & "[0-9]+")) { setverdict(pass); } | |
517 | else { setverdict(fail); } | |
518 | } | |
519 | ||
520 | testcase CatBasic() runs on templateCharstr_mycomp { | |
521 | var charstring cs1 := "xyz" | |
522 | var charstring cs2 := "(xyz)*[abc]+" | |
523 | var charstring cs3 := "{xyz}" // No run-time references. | |
524 | var template charstring t1, t2, t3, t4, t5, t6, t7 | |
525 | t1 := pattern cs1 | |
526 | t2 := pattern cs2 | |
527 | t3 := pattern cs1 & "utoljara" | |
528 | t4 := pattern cs1 & "utoljar(a)+" & cs1 | |
529 | t5 := pattern "utoljara" & cs1 | |
530 | t6 := pattern "valami" & cs1 & "megegyszer" & "utoljara" | |
531 | t7 := pattern "valami" & cs3 & "megegyszer" & "utoljara" | |
532 | if (match("xyz", t1)) { setverdict(pass) } else { setverdict(fail) } | |
533 | if (match("xyzxyzxyza", t2)) { setverdict(pass) } else { setverdict(fail) } | |
534 | if (match("xyzabcaabbccac", t2)) { setverdict(pass) } else { setverdict(fail) } | |
535 | if (match("xyzutoljara", t3)) { setverdict(pass) } else { setverdict(fail) } | |
536 | if (match("xyzutoljaraaaaaaaaaaaxyz", t4)) { setverdict(pass) } else { setverdict(fail) } | |
537 | if (match("utoljaraxyz", t5)) { setverdict(pass) } else { setverdict(fail) } | |
538 | if (match("valamixyzmegegyszerutoljara", t6)) { setverdict(pass) } else { setverdict(fail) } | |
539 | if (match("valami{xyz}megegyszerutoljara", t7)) { setverdict(pass) } else { setverdict(fail) } | |
540 | } | |
541 | ||
542 | template srec pt1(in charstring sp) := { s := pattern sp } | |
543 | template srec pt2(in charstring sp) := { s := pattern sp & "megvalami" } | |
544 | template srec pt3(in charstring sp) := { s := pattern "valami" & sp } | |
545 | template srec pt4(in charstring sp) := { s := pattern "valami" & sp & "megvalami" } | |
546 | template srec pt5(in charstring sp) := { s := pattern sp & "valami" & sp } | |
547 | ||
548 | testcase CatParametrized() runs on templateCharstr_mycomp | |
549 | { | |
550 | var srec r1, r2, r3, r4, r5 | |
551 | r1 := { "xyz" } | |
552 | r2 := { "xyzmegvalami" } | |
553 | r3 := { "valamixyz" } | |
554 | r4 := { "valamixyzmegvalami" } | |
555 | r5 := { "xyzvalamixyz" } | |
556 | if (match(r1, pt1("xyz"))) { setverdict(pass) } else { setverdict(fail) } | |
557 | if (match(r2, pt2("xyz"))) { setverdict(pass) } else { setverdict(fail) } | |
558 | if (match(r3, pt3("xyz"))) { setverdict(pass) } else { setverdict(fail) } | |
559 | if (match(r4, pt4("xyz"))) { setverdict(pass) } else { setverdict(fail) } | |
560 | if (match(r5, pt5("xyz"))) { setverdict(pass) } else { setverdict(fail) } | |
561 | } | |
562 | ||
563 | function f1(in charstring s) return integer { | |
564 | var template charstring t := pattern s; if (match(s, t)) { return 0 } else { return 1 } | |
565 | } | |
566 | ||
567 | function f2(in charstring s) return integer { | |
568 | var template charstring t := pattern s & "megvalami"; if (match(s & "megvalami", t)) { return 0 } else { return 1 } | |
569 | } | |
570 | ||
571 | function f3(in charstring s) return integer { | |
572 | var template charstring t := pattern "valami" & s; if (match("valami" & s, t)) { return 0 } else { return 1 } | |
573 | } | |
574 | ||
575 | function f4(in charstring s) return integer { | |
576 | var template charstring t := pattern "valami" & s & "megvalami"; if (match("valami" & s & "megvalami", t)) { return 0 } else { return 1 } | |
577 | } | |
578 | ||
579 | function f5(in charstring s) return integer { | |
580 | var template charstring t := pattern s & "valami" & s; if (match(s & "valami" & s, t)) { return 0 } else { return 1 } | |
581 | } | |
582 | ||
583 | type record srec { charstring s } | |
584 | ||
585 | testcase CatFunctions() runs on templateCharstr_mycomp | |
586 | { | |
587 | if (f1("xyz") == 0) { setverdict(pass) } else { setverdict(fail) } | |
588 | if (f2("xyz") == 0) { setverdict(pass) } else { setverdict(fail) } | |
589 | if (f3("xyz") == 0) { setverdict(pass) } else { setverdict(fail) } | |
590 | if (f4("xyz") == 0) { setverdict(pass) } else { setverdict(fail) } | |
591 | if (f5("xyz") == 0) { setverdict(pass) } else { setverdict(fail) } | |
592 | } | |
593 | ||
594 | testcase CatStructured() runs on templateCharstr_mycomp | |
595 | { | |
596 | var srec r1 := { "xyz" } | |
597 | var template charstring t1, t2, t3, t4, t5 | |
598 | t1 := pattern r1.s | |
599 | t2 := pattern r1.s & "megvalami" | |
600 | t3 := pattern "valami" & r1.s | |
601 | t4 := pattern "valami" & r1.s & "megvalami" | |
602 | t5 := pattern r1.s & "valami" & r1.s | |
603 | if (match("xyz", t1)) { setverdict(pass) } else { setverdict(fail) } | |
604 | if (match("xyzmegvalami", t2)) { setverdict(pass) } else { setverdict(fail) } | |
605 | if (match("valamixyz", t3)) { setverdict(pass) } else { setverdict(fail) } | |
606 | if (match("valamixyzmegvalami", t4)) { setverdict(pass) } else { setverdict(fail) } | |
607 | if (match("xyzvalamixyz", t5)) { setverdict(pass) } else { setverdict(fail) } | |
608 | } | |
609 | ||
610 | ||
611 | const charstring base_1:= "ab?"; | |
612 | const charstring base_2 := "ab*"; | |
613 | ||
614 | template charstring p1:= pattern "{base_1}"; | |
615 | template charstring p2:= pattern base_1; | |
616 | ||
617 | template charstring p3 := pattern "{base_2}"; | |
618 | template charstring p4 := pattern base_2; | |
619 | ||
620 | template charstring p5 := pattern "{p3}{p3}"; | |
621 | template charstring p6 := pattern "{p3}" & "{p3}"; | |
622 | template charstring p7 := pattern p3 & p3; | |
623 | template charstring p8 := pattern "c{p4}d"; | |
624 | ||
625 | ||
626 | testcase pattern_reference() runs on templateCharstr_mycomp { | |
627 | ||
628 | var charstring string_1 := "abc"; | |
629 | var charstring string_2 := "ab" | |
630 | ||
631 | if (match(string_1, p1)) {setverdict(pass);} else {setverdict(fail);} | |
632 | if (match(base_1, p1)) {setverdict(pass);} else {setverdict(fail);} | |
633 | if (match(base_1, p2)) {setverdict(pass);} else {setverdict(fail);} | |
634 | ||
635 | if (match(string_2, p3)) {setverdict(pass);} else {setverdict(fail);} | |
636 | if (match(base_2, p3)) {setverdict(pass);} else {setverdict(fail);} | |
637 | if (match(base_2, p4)) {setverdict(pass);} else {setverdict(fail);} | |
638 | ||
639 | if (match("abnabn", p5)) {setverdict(pass);} else {setverdict(fail);} | |
640 | if (match("abnabn", p6)) {setverdict(pass);} else {setverdict(fail);} | |
641 | if (match("abnabn", p7)) {setverdict(pass);} else {setverdict(fail);} | |
642 | if (match("cabxd", p8)) {setverdict(pass);} else {setverdict(fail);} | |
643 | ||
644 | } | |
645 | ||
646 | type record of charstring Ss; | |
647 | ||
648 | type record ss_x | |
649 | { | |
650 | //integer a; | |
651 | charstring a, | |
652 | integer b | |
653 | }; | |
654 | ||
655 | ||
656 | type record ss_x2 | |
657 | { | |
658 | //integer a; | |
659 | ss_x a, | |
660 | integer b | |
661 | }; | |
662 | ||
663 | ||
664 | testcase HO30913_reference() runs on templateCharstr_mycomp { | |
665 | //test to check [1] reference | |
666 | ||
667 | var Ss ss; | |
668 | var charstring s; | |
669 | ||
670 | s := "s"; | |
671 | ss[0] := "0"; | |
672 | ss[1] := "1"; | |
673 | log(match(ss[0], pattern s)); // this compiles | |
674 | log(match(ss[0], pattern ss[1])); // this does not compile | |
675 | ||
676 | var ss_x xx; | |
677 | var ss_x2 xx2; | |
678 | ||
679 | xx.a := "a"; | |
680 | ||
681 | //log(match(ss[0], pattern x.a)); // this does not compile segmentation fault | |
682 | log(match(ss[0], pattern xx.a )); // this does not compile | |
683 | setverdict(pass); | |
684 | } | |
685 | ||
686 | testcase CR_TR00018474() runs on templateCharstr_mycomp { | |
687 | // Indexing of string template variables. | |
688 | var template charstring vtc1 := "fisherman" | |
689 | var template charstring vtc2 := "?*?****" // It's still a plain charstring. | |
690 | vtc1[0] := "F" // Normal usage. | |
691 | if (match("Fisherman", vtc1)) { setverdict(pass) } else { setverdict(fail) } | |
692 | vtc1[0] := "*" // Just an ASCII character. | |
693 | if (match("*isherman", vtc1)) { setverdict(pass) } else { setverdict(fail) } | |
694 | vtc1[1] := "?" // Just an ASCII character. | |
695 | if (match("*?sherman", vtc1)) { setverdict(pass) } else { setverdict(fail) } | |
696 | vtc1[0] := "F" // Indexed assignment notation cannot be used here. | |
697 | vtc1[1] := "i" // Still works, nothing special. | |
698 | if (match("Fisherman", vtc1)) { setverdict(pass) } else { setverdict(fail) } | |
699 | vtc2[0] := "*" | |
700 | if (match("**?****", vtc2)) { setverdict(pass) } else { setverdict(fail) } | |
701 | } | |
702 | ||
703 | control { | |
704 | execute(templateCharstrSpec()); | |
705 | execute(templateCharstrList()); | |
706 | execute(templateCharstrComp()); | |
707 | execute(templateCharstrOmit()); | |
708 | execute(templateCharstrAny()); | |
709 | execute(templateCharstrAnyorNone()); | |
710 | execute(templateCharstrLength1()); | |
711 | execute(templateCharstrLength2()); | |
712 | execute(templateCharstrLength3()); | |
713 | execute(templateCharstrIfpresent()); | |
714 | execute(templateCharstrLengthIfp()); | |
715 | execute(templateCharstrAnyEl()); | |
716 | execute(templateCharstrAnyorNoneEl()); | |
717 | execute(templateCharstrRange1()); | |
718 | execute(templateCharstrRange2()); | |
719 | execute(templateCharstrRange3()); | |
720 | execute(templateCharstrRange4()); | |
721 | execute(templateCharstrEmptyPattern()); | |
722 | execute(templateCharstrRepeat()); | |
723 | execute(templateCharstrRepeatFull()); | |
feade998 | 724 | execute(templateCharstrPattern()); |
970ed795 EL |
725 | execute(TR920()); |
726 | execute(templateCharstrPatternCat()); | |
727 | execute(CatBasic()) | |
728 | execute(CatParametrized()) | |
729 | execute(CatFunctions()) | |
730 | execute(CatStructured()) | |
731 | execute(pattern_reference()); | |
732 | execute(HO30913_reference()); | |
733 | execute(CR_TR00018474()); | |
734 | } | |
735 | } |