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 TtemplateInt { | |
3abe9331 | 9 | |
51fa56b9 | 10 | import from ImportedTemplates all; |
11 | ||
970ed795 EL |
12 | type component templateInt_mycomp {}; |
13 | type record templateInt_rec { | |
14 | integer x1, | |
15 | integer x2, | |
16 | integer x3 optional }; | |
3abe9331 | 17 | type integer templateInt_subtype (0..1457664); |
18 | ||
970ed795 EL |
19 | template templateInt_rec templateInt_tSpec :={ //specific values |
20 | x1:=1, | |
21 | x2:=2, | |
22 | x3:=3 }; | |
23 | template templateInt_rec templateInt_tList :={ //specific value and value list | |
24 | x1:=1, | |
25 | x2:=(2,3,6), | |
26 | x3:=3 }; | |
27 | template templateInt_rec templateInt_tComp :={ //specific value and compl. list | |
28 | x1:=1, | |
29 | x2:=complement (2,3,6), | |
30 | x3:=3 }; | |
31 | template templateInt_rec templateInt_tOmit :={ //omitting values | |
32 | x1:=1, | |
33 | x2:=2, | |
34 | x3:=omit } ; | |
35 | template templateInt_rec templateInt_tAny :={ //specific and any value | |
36 | x1:=1, | |
37 | x2:=2, | |
38 | x3:=? } ; | |
39 | template templateInt_rec templateInt_tAnyorNone :={ //specific and AnyorNone value | |
40 | x1:=1, | |
41 | x2:=2, | |
42 | x3:=* }; | |
43 | template templateInt_rec templateInt_tRange1 :={ //specific value and Range | |
44 | x1:=1, | |
45 | x2:=(2 ..4), | |
46 | x3:=3 }; | |
47 | template templateInt_rec templateInt_tRange2 :={ //specific value and Range | |
48 | x1:=1, | |
49 | x2:=(2 .. 4), | |
50 | x3:=3 }; | |
51 | template templateInt_rec templateInt_tRange3 :={ //specific value and Range | |
52 | x1:=1, | |
53 | x2:=(2 .. infinity), | |
54 | x3:=3 }; | |
55 | template templateInt_rec templateInt_tRange4 :={ //specific value and Range | |
56 | x1:=1, | |
57 | x2:=(-infinity .. 4), | |
58 | x3:=3 }; | |
59 | template templateInt_rec templateInt_tIfpresent :={ //specific value and ifpresent | |
60 | x1:=1, | |
61 | x2:=2, | |
62 | x3:=3 ifpresent }; | |
63 | ||
64 | testcase templateIntSpec() runs on templateInt_mycomp { | |
65 | var templateInt_rec x1,x2; //specific value | |
66 | x1:={ x1:=1, x2:=2, x3:=3 }; | |
67 | x2:={ x1:=2, x2:=2, x3:=3 }; | |
68 | //match | |
69 | if (match(x1,templateInt_tSpec)) {setverdict(pass);} | |
70 | else {setverdict(fail);} | |
71 | //no match | |
72 | if (not(match(x2,templateInt_tSpec))) {setverdict(pass);} | |
73 | else {setverdict(fail);} | |
74 | } | |
75 | ||
76 | testcase templateIntList() runs on templateInt_mycomp { | |
77 | var templateInt_rec x1,x2,x3; //value list | |
78 | x1:={ x1:=1, x2:=6, x3:=3 }; | |
79 | x2:={ x1:=1, x2:=7, x3:=3 }; | |
80 | x3:={ x1:=2, x2:=6, x3:=3 }; | |
81 | //match | |
82 | if (match(x1,templateInt_tList)) {setverdict(pass);} | |
83 | else {setverdict(fail);} | |
84 | //no match: out of list | |
85 | if (not(match(x2,templateInt_tList))) {setverdict(pass);} | |
86 | else {setverdict(fail);} | |
87 | //no match: other field | |
88 | if (not(match(x3,templateInt_tList))) {setverdict(pass);} | |
89 | else {setverdict(fail);} | |
90 | } | |
91 | ||
92 | testcase templateIntComp() runs on templateInt_mycomp { | |
93 | var templateInt_rec x1,x2,x3; //complemented list | |
94 | x1:={ x1:=1, x2:=7, x3:=3 }; | |
95 | x2:={ x1:=1, x2:=6, x3:=3 }; | |
96 | x3:={ x1:=2, x2:=7, x3:=3 }; | |
97 | //match | |
98 | if (match(x1,templateInt_tComp)) {setverdict(pass);} | |
99 | else {setverdict(fail);} | |
100 | //no match: in the list | |
101 | if (not(match(x2,templateInt_tComp))) {setverdict(pass);} | |
102 | else {setverdict(fail);} | |
103 | //no match: other field | |
104 | if (not(match(x3,templateInt_tComp))) {setverdict(pass);} | |
105 | else {setverdict(fail);} | |
106 | } | |
107 | ||
108 | testcase templateIntOmit() runs on templateInt_mycomp { | |
109 | var templateInt_rec x1,x2,x3; //omitting value | |
110 | x1:={ x1:=1, x2:=2, x3:=omit }; | |
111 | x2:={ x1:=1, x2:=2, x3:=3 }; | |
112 | x3:={ x1:=2, x2:=2, x3:=omit }; | |
113 | //match | |
114 | if (match(x1,templateInt_tOmit)) {setverdict(pass);} | |
115 | else {setverdict(fail);} | |
116 | //no match: not omitted | |
117 | if (not(match(x2,templateInt_tOmit))) {setverdict(pass);} | |
118 | else {setverdict(fail);} | |
119 | //no match: other field | |
120 | if (not(match(x3,templateInt_tOmit))) {setverdict(pass);} | |
121 | else {setverdict(fail);} | |
122 | } | |
123 | ||
124 | testcase templateIntAny() runs on templateInt_mycomp { | |
125 | var templateInt_rec x1,x2,x3; //any value | |
126 | x1:={ x1:=1, x2:=2, x3:=3 }; | |
127 | x2:={ x1:=1, x2:=2, x3:=omit }; | |
128 | x3:={ x1:=2, x2:=2, x3:=3 }; | |
129 | //match | |
130 | if (match(x1,templateInt_tAny)) {setverdict(pass);} | |
131 | else {setverdict(fail);} | |
132 | //no match: field omitted | |
133 | if (not(match(x2,templateInt_tAny))) {setverdict(pass);} | |
134 | else {setverdict(fail);} | |
135 | //no match: other field | |
136 | if (not(match(x3,templateInt_tAny))) {setverdict(pass);} | |
137 | else {setverdict(fail);} | |
138 | } | |
139 | ||
140 | testcase templateIntAnyorNone() runs on templateInt_mycomp { | |
141 | var templateInt_rec x1,x2,x3; //AnyorNone value | |
142 | x1:={ x1:=1, x2:=2, x3:=omit }; | |
143 | x2:={ x1:=1, x2:=2, x3:=3 }; | |
144 | x3:={ x1:=2, x2:=2, x3:=omit }; | |
145 | //match: omitted | |
146 | if (match(x1,templateInt_tAnyorNone)) {setverdict(pass);} | |
147 | else {setverdict(fail);} | |
148 | //match: value | |
149 | if (match(x2,templateInt_tAnyorNone)) {setverdict(pass);} | |
150 | else {setverdict(fail);} | |
151 | //no match: other field | |
152 | if (not(match(x3,templateInt_tAnyorNone))) {setverdict(pass);} | |
153 | else {setverdict(fail);} | |
154 | } | |
155 | ||
156 | testcase templateIntRange1() runs on templateInt_mycomp { | |
157 | var templateInt_rec x1,x2,x3; //Range (x .. y) | |
158 | x1:={ x1:=1, x2:=2, x3:=3 }; | |
159 | x2:={ x1:=1, x2:=5, x3:=3 }; | |
160 | x3:={ x1:=2, x2:=2, x3:=3 }; | |
161 | //match | |
162 | if (match(x1,templateInt_tRange1)) {setverdict(pass);} | |
163 | else {setverdict(fail);} | |
164 | //no match: out of range | |
165 | if (not(match(x2,templateInt_tRange1))) {setverdict(pass);} | |
166 | else {setverdict(fail);} | |
167 | //no match: other field | |
168 | if (not(match(x3,templateInt_tRange1))) {setverdict(pass);} | |
169 | else {setverdict(fail);} | |
170 | } | |
171 | ||
172 | testcase templateIntRange2() runs on templateInt_mycomp { | |
173 | var templateInt_rec x1,x2,x3; //Range (x to y) | |
174 | x1:={ x1:=1, x2:=2, x3:=3 }; | |
175 | x2:={ x1:=1, x2:=5, x3:=3 }; | |
176 | x3:={ x1:=2, x2:=2, x3:=3 }; | |
177 | //match | |
178 | if (match(x1,templateInt_tRange2)) {setverdict(pass);} | |
179 | else {setverdict(fail);} | |
180 | //no match: out of range | |
181 | if (not(match(x2,templateInt_tRange2))) {setverdict(pass);} | |
182 | else {setverdict(fail);} | |
183 | //no match: other field | |
184 | if (not(match(x3,templateInt_tRange2))) {setverdict(pass);} | |
185 | else {setverdict(fail);} | |
186 | } | |
187 | ||
188 | testcase templateIntRange3() runs on templateInt_mycomp { | |
189 | var templateInt_rec x1,x2,x3; //Range, with infinity | |
190 | x1:={ x1:=1, x2:=8, x3:=3 }; | |
191 | x2:={ x1:=1, x2:=-5, x3:=3 }; | |
192 | x3:={ x1:=2, x2:=2, x3:=3 }; | |
193 | //match | |
194 | if (match(x1,templateInt_tRange3)) {setverdict(pass);} | |
195 | else {setverdict(fail);} | |
196 | //no match: out of range | |
197 | if (not(match(x2,templateInt_tRange3))) {setverdict(pass);} | |
198 | else {setverdict(fail);} | |
199 | //no match: other field | |
200 | if (not(match(x3,templateInt_tRange3))) {setverdict(pass);} | |
201 | else {setverdict(fail);} | |
202 | } | |
203 | ||
204 | testcase templateIntRange4() runs on templateInt_mycomp { | |
205 | var templateInt_rec x1,x2,x3; //Range with - infinity | |
206 | x1:={ x1:=1, x2:=-2, x3:=3 }; | |
207 | x2:={ x1:=1, x2:=5, x3:=3 }; | |
208 | x3:={ x1:=2, x2:=2, x3:=3 }; | |
209 | //match | |
210 | if (match(x1,templateInt_tRange4)) {setverdict(pass);} | |
211 | else {setverdict(fail);} | |
212 | //no match: out of range | |
213 | if (not(match(x2,templateInt_tRange4))) {setverdict(pass);} | |
214 | else {setverdict(fail);} | |
215 | //no match: other field | |
216 | if (not(match(x3,templateInt_tRange4))) {setverdict(pass);} | |
217 | else {setverdict(fail);} | |
218 | } | |
219 | ||
220 | testcase templateIntIfpresent() runs on templateInt_mycomp { | |
221 | var templateInt_rec x1,x2,x3,x4; //ifpresent | |
222 | x1:={ x1:=1, x2:=2, x3:=3 }; | |
223 | x2:={ x1:=1, x2:=2, x3:=omit }; | |
224 | x3:={ x1:=1, x2:=2, x3:=4 }; | |
225 | x4:={ x1:=2, x2:=2, x3:=omit }; | |
226 | //match: present and match | |
227 | if (match(x1,templateInt_tIfpresent)) {setverdict(pass);} | |
228 | else {setverdict(fail);} | |
229 | //match: not present | |
230 | if (match(x2,templateInt_tIfpresent)) {setverdict(pass);} | |
231 | else {setverdict(fail);} | |
232 | //no match: present and not match | |
233 | if (not(match(x3,templateInt_tIfpresent))) {setverdict(pass);} | |
234 | else {setverdict(fail);} | |
235 | //no match: other field | |
236 | if (not(match(x4,templateInt_tIfpresent))) {setverdict(pass);} | |
237 | else {setverdict(fail);} | |
238 | } | |
239 | ||
240 | // Types for TR_HJ94652. | |
241 | type record TR_HJ94652_myrec { | |
242 | integer myrecint | |
243 | } | |
244 | ||
245 | template TR_HJ94652_myrec TR_HJ94652_mytemp(integer myint) := { | |
246 | myrecint := (myint - 100 .. myint) | |
247 | } | |
248 | ||
249 | type record of TR_HJ94652_myrec TR_HJ94652_mylist | |
250 | ||
251 | testcase TR_HJ94652() runs on templateInt_mycomp { | |
252 | // INTEGER_template::copy_template() was not implemented correctly for | |
253 | // VALUE_RANGE templates. | |
254 | var template TR_HJ94652_mylist myownlist := { } | |
255 | for (var integer i := 1; i <= 3; i := i + 1) { | |
256 | myownlist[i] := TR_HJ94652_mytemp(i * 100) | |
257 | } | |
258 | for (var integer i := 1; i <= 3; i := i + 1) { | |
259 | var charstring s1 := log2str(myownlist[i]) | |
260 | var charstring s2 := log2str(TR_HJ94652_mytemp(i * 100)) | |
261 | if (s1 == s2) { setverdict(pass) } | |
262 | else { setverdict(fail) } | |
263 | } | |
264 | } | |
265 | ||
3abe9331 | 266 | testcase templateIntSubtype() runs on templateInt_mycomp { |
267 | // this tests the use of inline templates (value ranges) | |
268 | // with subtypes and variables | |
269 | var templateInt_subtype x := 312; | |
270 | var templateInt_subtype lower_limit := 100; | |
271 | var templateInt_subtype upper_limit := 65535; | |
272 | if (not match(x, templateInt_subtype:(0..upper_limit))) { // TR: artf602477 | |
273 | setverdict(fail); | |
274 | } | |
275 | if (not match(x, integer:(100..upper_limit))) { | |
276 | setverdict(fail); | |
277 | } | |
278 | if (not match(312, templateInt_subtype:(100..upper_limit))) { | |
279 | setverdict(fail); | |
280 | } | |
281 | if (not match(x, templateInt_subtype:(100..65535))) { | |
282 | setverdict(fail); | |
283 | } | |
284 | if (not match(x, templateInt_subtype:(lower_limit..65535))) { | |
285 | setverdict(fail); | |
286 | } | |
287 | if (not match(x, templateInt_subtype:(lower_limit..upper_limit))) { | |
288 | setverdict(fail); | |
289 | } | |
290 | setverdict(pass); | |
291 | } | |
292 | ||
51fa56b9 | 293 | // test case: using a parameterized template with no actual parameters (using default values) |
294 | // before its declaration | |
295 | template integer tReverse := tPard; | |
296 | ||
297 | template integer tPard(integer p := 6) := p; | |
298 | ||
299 | testcase templateIntReverseOrder() runs on templateInt_mycomp { | |
300 | var template integer vtExpected := 6; | |
301 | if (log2str(tReverse) == log2str(vtExpected)) { | |
302 | setverdict(pass); | |
303 | } | |
304 | else { | |
305 | setverdict(fail, "Expected: ", vtExpected, ", got: ", tReverse); | |
306 | } | |
307 | } | |
308 | ||
309 | // same test, but the parameterized template is passed as a parameter to | |
310 | // an imported parameterized template | |
311 | template integer tReverse2 := tImported(tPard2); | |
312 | ||
313 | template integer tPard2(integer p := 4) := p; | |
314 | ||
315 | testcase templateIntReverseOrderImported() runs on templateInt_mycomp { | |
316 | var template integer vtExpected := 4; | |
317 | if (log2str(tReverse2) == log2str(vtExpected)) { | |
318 | setverdict(pass); | |
319 | } | |
320 | else { | |
321 | setverdict(fail, "Expected: ", vtExpected, ", got: ", tReverse2); | |
322 | } | |
323 | } | |
324 | ||
325 | // same as the previous test, but with a non-parameterized template | |
326 | template integer tReverse3 := tImported(tNonPard); | |
327 | ||
328 | template integer tNonPard := (1, 2); | |
329 | ||
330 | testcase templateIntReverseOrderImported2() runs on templateInt_mycomp { | |
331 | var template integer vtExpected := (1, 2); | |
332 | if (log2str(tReverse3) == log2str(vtExpected)) { | |
333 | setverdict(pass); | |
334 | } | |
335 | else { | |
336 | setverdict(fail, "Expected: ", vtExpected, ", got: ", tReverse3); | |
337 | } | |
338 | } | |
339 | ||
970ed795 EL |
340 | control { |
341 | execute(templateIntSpec()); | |
342 | execute(templateIntList()); | |
343 | execute(templateIntComp()); | |
344 | execute(templateIntOmit()); | |
345 | execute(templateIntAny()); | |
346 | execute(templateIntAnyorNone()); | |
347 | execute(templateIntRange1()); | |
348 | execute(templateIntRange2()); | |
349 | execute(templateIntRange3()); | |
350 | execute(templateIntRange4()); | |
351 | execute(templateIntIfpresent()); | |
352 | execute(TR_HJ94652()); | |
3abe9331 | 353 | execute(templateIntSubtype()); |
51fa56b9 | 354 | execute(templateIntReverseOrder()); |
355 | execute(templateIntReverseOrderImported()); | |
356 | execute(templateIntReverseOrderImported2()); | |
970ed795 EL |
357 | } |
358 | } |