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