Commit | Line | Data |
---|---|---|
970ed795 EL |
1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2014 Ericsson Telecom AB | |
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 TassignmentNotation | |
9 | { | |
10 | import from ASN_Definitions language "ASN.1 : 1997" all | |
11 | type component empty { } | |
12 | type record tri | |
13 | { | |
14 | integer a, | |
15 | integer b, | |
16 | integer c | |
17 | } | |
18 | function f1 () return integer { return 100 } | |
19 | type record of tri tritri | |
20 | type record of tritri tritritri | |
21 | modulepar tritri tsp_param := | |
22 | { | |
23 | { 0, 1, 2 }, | |
24 | { 4, 5, 6 } | |
25 | } | |
26 | modulepar tritritri tsp_param_param := | |
27 | { | |
28 | { { 10, 11, 12 }, { 13, 14, 15 } }, | |
29 | { { 16, 17, 18 }, { 19, 20, 21 } } | |
30 | } | |
31 | modulepar integer tsp_index := 0 | |
32 | modulepar charstring tsp_editor := "mcedit" | |
33 | testcase asns () runs on empty | |
34 | { | |
35 | template ASN_SEQ_R asn_temp := { asn_seq_i := { 0, 1, 2 } } | |
36 | template ASN_SEQ_R asn_temp_mod modifies asn_temp := { asn_seq_i := { [1] := 0, [2] := 0 } } | |
37 | var ASN_SEQ_R asn_temp_exp := { asn_seq_i := { 0, 0, 0 } } | |
38 | if (match (asn_temp_exp, asn_temp_mod)) { setverdict (pass) } | |
39 | else { setverdict (fail, __LINE__) } | |
40 | var integer index := 1 | |
41 | var ASN_SEQ_I v1 := { 1, 2, 3 } | |
42 | var ASN_SEQ_I v2 := { [0] := 100, [index] := 200, [index + 1] := 300 } | |
43 | var ASN_SEQ_I v1_exp := { 100, 200, 300 } | |
44 | v1[0] := 100 * v1[0] | |
45 | v1[index] := 100 * v1[index + 1 - 1] | |
46 | v1[index + 1] := v2[2] | |
47 | if (v1 != v2) { setverdict (fail, __LINE__) } | |
48 | else { setverdict (pass) } | |
49 | v1 := { 100 } | |
50 | /* Evaluated from left to right. */ | |
51 | v1 := { [sizeof (v1)] := 200, [sizeof (v1)] := 300 } | |
52 | if (v1 != v1_exp) { setverdict (fail, __LINE__) } | |
53 | else { setverdict (pass) } | |
54 | var ASN_SEQ_R v3 := { asn_seq_i := { 1, 2, 3 } } | |
55 | var ASN_SEQ_R v4 := { asn_seq_i := { [index] := 111 } } | |
56 | var ASN_SEQ_R v3_exp := { asn_seq_i := { 11, 22, 33 } } | |
57 | var ASN_SEQ_R v5 := { asn_seq_i := { [1000 + index + sizeof (v3.asn_seq_i)] := 1000 } } | |
58 | v4.asn_seq_i[index] := 22 | |
59 | v4 := { asn_seq_i := { [index - 1] := index + 10, [2] := 33 } } | |
60 | v3 := v4 | |
61 | v3 := { asn_seq_i := { [index - 1] := 11 } } | |
62 | if (v3 != v3_exp) { setverdict (fail, __LINE__) } | |
63 | else { setverdict (pass) } | |
64 | v4.asn_seq_i[0] := v3.asn_seq_i[0] | |
65 | if (v4 != v3_exp) { setverdict (fail, __LINE__) } | |
66 | else { setverdict (pass) } | |
67 | if (isvalue (v4)) { setverdict (pass) } | |
68 | else { setverdict (fail, __LINE__) } | |
69 | if (isvalue (v4.asn_seq_i[index])) { setverdict (pass) } | |
70 | else { setverdict (fail, __LINE__) } | |
71 | if (isvalue (v2[valueof (asn_temp_mod.asn_seq_i[0])])) { setverdict (pass) } | |
72 | else { setverdict (fail, __LINE__) } | |
73 | if (sizeof (v5.asn_seq_i) == 1005) { setverdict (pass) } | |
74 | else { setverdict (fail, __LINE__) } | |
75 | if (isvalue (asn_temp_mod)) { setverdict (pass) } | |
76 | else { setverdict (fail, __LINE__) } | |
77 | /* Template with uninitialized elements. */ | |
78 | template ASN_SEQ_R mod2 modifies asn_temp_mod := { asn_seq_i := { [100] := 0, [200] := 0 } } | |
79 | if (not isvalue (mod2)) { setverdict (pass) } | |
80 | else { setverdict (fail, __LINE__) } | |
81 | if (not isvalue (mod2.asn_seq_i)) { setverdict (pass) } | |
82 | else { setverdict (fail, __LINE__) } | |
83 | } | |
84 | type record array_element { integer a, integer b } | |
85 | type array_element array_elements[4] | |
86 | type record of array_element array_record_of | |
87 | type record of integer intlist | |
88 | type set of integer intset | |
89 | testcase arrays () runs on empty | |
90 | { | |
91 | var integer first := 0 | |
92 | var integer second := 1 | |
93 | var integer third := 2 | |
94 | var array_element arr2[4] | |
95 | var array_element arr3[14] | |
96 | var array_elements array := | |
97 | { | |
98 | [first] := { first, 0 }, | |
99 | [second] := { 1, second }, | |
100 | [third] := { third, 2 }, | |
101 | [third + 1] := { 3, third + 1 } | |
102 | } | |
103 | arr2 := array | |
104 | arr2 := { [3] := { 100, third } } | |
105 | arr3 := { [10] := arr2[1] } | |
106 | var array_elements array_expected := { { 0, 0 }, { 1, 1 }, { 2, 2 }, { 3, third + 1 } } | |
107 | if (array == array_expected) { setverdict (pass) } | |
108 | else { setverdict (fail, __LINE__) } | |
109 | template array_elements array_base := { { 100, 200 }, { -1, -2 }, { 1000, 2000 }, { -10, -20 } } | |
110 | template array_elements array_modified modifies array_base := | |
111 | { | |
112 | [0] := { 0, 0 }, | |
113 | [2] := { third, third }, | |
114 | [second] := { 1, first + 1 }, | |
115 | [third + 1] := { third + 1, 3 } | |
116 | } | |
117 | if (match (array_expected, array_modified)) { setverdict (pass) } | |
118 | else { setverdict (fail, __LINE__) } | |
119 | /* "array[500 + f1 ()]" is a dynamic test case error. */ | |
120 | if (isvalue (array[500 + f1 () - 599])) { setverdict (pass) } | |
121 | else { setverdict (fail, __LINE__) } | |
122 | if (isvalue (array)) { setverdict (pass) } | |
123 | else { setverdict (fail, __LINE__) } | |
124 | if (isvalue (array[f1 () - f1 () + 1].a)) { setverdict (pass) } | |
125 | else { setverdict (fail, __LINE__) } | |
126 | if (isvalue (arr2[500 + f1 () - 598])) { setverdict (pass) } | |
127 | else { setverdict (fail, __LINE__) } | |
128 | if (isvalue (arr2)) { setverdict (pass) } | |
129 | else { setverdict (fail, __LINE__) } | |
130 | if (not isvalue (arr3)) { setverdict (pass) } | |
131 | else { setverdict (fail, __LINE__) } | |
132 | if (isvalue (arr2[f1 () - f1 () + 1].a)) { setverdict (pass) } | |
133 | else { setverdict (fail, __LINE__) } | |
134 | if (sizeof (arr3) == 14) { setverdict (pass) } | |
135 | else { setverdict (fail, __LINE__) } | |
136 | /* Creating holes in arrays is not possible. (Without dynamic test case | |
137 | error.) */ | |
138 | } | |
139 | testcase configs () runs on empty | |
140 | { | |
141 | template tritri tsp_param_expected := | |
142 | { | |
143 | { 0, 1, 2 }, | |
144 | { 3, 4, 5 }, | |
145 | { 33, 22, 11 }, | |
146 | { 100, 100, 100 } | |
147 | } | |
148 | var tritri tsp_param_exp2 := | |
149 | { | |
150 | [0] := { 0, 1, 2 }, | |
151 | [1] := { 3, 4, 5 }, | |
152 | [2] := { 33, 22, 11 }, | |
153 | [3] := { 100, 100, 100 } | |
154 | } | |
155 | var tritri tsp_param_exp3 := | |
156 | { | |
157 | [0] := { 0, 1, 2 }, | |
158 | [3] := { 3, 4, 5 }, | |
159 | [2] := { 33, 22, 11 }, | |
160 | [1] := { 100, 100, 100 } | |
161 | } | |
162 | if (match (tsp_param, tsp_param_expected)) { setverdict (pass) } | |
163 | else { setverdict (fail, __LINE__) } | |
164 | if (tsp_param == tsp_param_exp2) { setverdict (pass) } | |
165 | else { setverdict (fail, __LINE__) } | |
166 | if (tsp_param != tsp_param_exp3) { setverdict (pass) } | |
167 | else { setverdict (fail, __LINE__) } | |
168 | } | |
169 | type record of my mylist | |
170 | type set of my_set myset | |
171 | type record my { intlist ilist, integer i } | |
172 | type record my_set { intset iset, integer i } | |
173 | type record dummy { mylist mlist } | |
174 | type record dummy_set { myset mset } | |
175 | testcase recofs () runs on empty | |
176 | { | |
177 | template dummy t1 := { mlist := { { ilist := { 0 }, i := 0 } } } | |
178 | template dummy t1_mod1 modifies t1 := { mlist := { [0] := { ilist := { 1 } } } } | |
179 | var dummy t1_mod_exp := { mlist := { { ilist := { 1 }, i := 0 } } } | |
180 | if (match (t1_mod_exp, t1_mod1)) { setverdict (pass) } | |
181 | else { setverdict (fail, __LINE__) } | |
182 | var integer index := 0 | |
183 | /* An index like "index + 1 - 1" caused circular reference with previous | |
184 | versions. The name was not set correctly. */ | |
185 | template dummy t1_mod2 modifies t1 := { mlist := { [index + 1 - index - 1] := { ilist := { [0 - index] := index + 1 } } } } | |
186 | if (match (t1_mod_exp, t1_mod2)) { setverdict (pass) } | |
187 | else { setverdict (fail, __LINE__) } | |
188 | var intlist v1 := { [0] := 0, [index + 1] := 1 } | |
189 | var intlist v1_exp := { 100, 1 } | |
190 | var intlist v3 := { [100 + f1 ()] := 100 } | |
191 | v1[1] := index + 1 | |
192 | v1 := { [0] := 100 } | |
193 | if (v1 == v1_exp) { setverdict (pass) } | |
194 | else { setverdict (fail, __LINE__) } | |
195 | var dummy v2 := { mlist := { { ilist := { 1, 2 }, i := 500 } } } | |
196 | v2 := { mlist := { { ilist := { [index + 2] := 3 }, i := v2.mlist[index].i - 100 } } } | |
197 | var dummy v2_exp := { mlist := { { ilist := { -, -, 3 }, i := 400 } } } | |
198 | if (v2 == v2_exp) { setverdict (pass) } | |
199 | else { setverdict (fail, __LINE__, ": ", match(v2, v2_exp)) } | |
200 | if (not isvalue (t1_mod2.mlist[500])) { setverdict (pass) } | |
201 | else { setverdict (fail, __LINE__) } | |
202 | if (isvalue (t1_mod2.mlist[0])) { setverdict (pass) } | |
203 | else { setverdict (fail, __LINE__) } | |
204 | if (not isvalue (t1_mod2.mlist[1])) { setverdict (pass) } | |
205 | else { setverdict (fail, __LINE__) } | |
206 | if (not isvalue (v2)) { setverdict (pass) } | |
207 | else { setverdict (fail, __LINE__) } | |
208 | if (not isvalue (v2.mlist[index].ilist[1])) { setverdict (pass) } | |
209 | else { setverdict (fail, __LINE__) } | |
210 | if (isvalue (v1)) { setverdict (pass) } | |
211 | else { setverdict (fail, __LINE__) } | |
212 | if (isvalue (v1[0])) { setverdict (pass) } | |
213 | else { setverdict (fail, __LINE__) } | |
214 | if (not isvalue (v3)) { setverdict (pass) } | |
215 | else { setverdict (fail, __LINE__) } | |
216 | if (isvalue (v3[200])) { setverdict (pass) } | |
217 | else { setverdict (fail, __LINE__) } | |
218 | if (sizeof (v3) == 201) { setverdict (pass) } | |
219 | else { setverdict (fail, __LINE__) } | |
220 | } | |
221 | testcase setofs () runs on empty | |
222 | { /* Same as the previous. */ | |
223 | template dummy_set t1 := { mset := { { iset := { 0 }, i := 0 } } } | |
224 | template dummy_set t1_mod1 modifies t1 := { mset := { [0] := { iset := { 1 } } } } | |
225 | var dummy_set t1_mod_exp := { mset := { { iset := { 1 }, i := 0 } } } | |
226 | if (match (t1_mod_exp, t1_mod1)) { setverdict (pass) } | |
227 | else { setverdict (fail, __LINE__) } | |
228 | var integer index := 0 | |
229 | template dummy_set t1_mod2 modifies t1 := { mset := { [index + 1 - index - 1] := { iset := { [0 - index] := index + 1 } } } } | |
230 | if (match (t1_mod_exp, t1_mod2)) { setverdict (pass) } | |
231 | else { setverdict (fail, __LINE__) } | |
232 | var intset v1 := { [0] := 0, [index + 1] := 1 } | |
233 | var intset v1_exp := { 100, 1 } | |
234 | v1[1] := index + 1 | |
235 | v1 := { [0] := 100 } | |
236 | if (v1 == v1_exp) { setverdict (pass) } | |
237 | else { setverdict (fail, __LINE__) } | |
238 | var dummy_set v2 := { mset := { { iset := { 1, 2 }, i := 500 } } } | |
239 | var dummy_set v2_exp := { mset := { { iset := { -, -, 3 }, i := 400 } } } | |
240 | var intset v3 := { [100 + f1 ()] := 100 } | |
241 | v2 := { mset := { { iset := { [index + 2] := 3 }, i := v2.mset[index].i - 100 } } } | |
242 | if (v2 == v2_exp) { setverdict (pass) } | |
243 | else { setverdict (fail, __LINE__, ": ", match(v2, v2_exp)) } | |
244 | /* It should be a compile only test. */ | |
245 | var ASN_CSTR asnstr | |
246 | asnstr := { { fixed := NULL }, "{ itu-t identified-organization etsi(0) reserved(127) etsi-identified-organization(0) ericsson(5) }", 'abcd'O }; | |
247 | var objid oi := objid { itu_t (0) 1 2 } | |
248 | /* Using isvalue. */ | |
249 | if (isvalue (t1_mod2)) { setverdict (pass) } | |
250 | else { setverdict (fail, __LINE__) } | |
251 | if (isvalue (t1_mod2.mset)) { setverdict (pass) } | |
252 | else { setverdict (fail, __LINE__) } | |
253 | /* Indexing with constants was a problem with INDEXED_TEMPLATE_LIST | |
254 | nodes. */ | |
255 | if (not isvalue (t1_mod2.mset[500])) { setverdict (pass) } | |
256 | else { setverdict (fail, __LINE__) } | |
257 | if (isvalue (t1_mod2.mset[0])) { setverdict (pass) } | |
258 | else { setverdict (fail, __LINE__) } | |
259 | if (not isvalue (t1_mod2.mset[1])) { setverdict (pass) } | |
260 | else { setverdict (fail, __LINE__) } | |
261 | if (not isvalue (v2)) { setverdict (pass) } | |
262 | else { setverdict (fail, __LINE__) } | |
263 | if (not isvalue (v2.mset[index].iset[1])) { setverdict (pass) } | |
264 | else { setverdict (fail, __LINE__) } | |
265 | if (isvalue (v1)) { setverdict (pass) } | |
266 | else { setverdict (fail, __LINE__) } | |
267 | if (isvalue (v1[0])) { setverdict (pass) } | |
268 | else { setverdict (fail, __LINE__) } | |
269 | if (not isvalue (v3)) { setverdict (pass) } | |
270 | else { setverdict (fail, __LINE__) } | |
271 | if (isvalue (v3[200])) { setverdict (pass) } | |
272 | else { setverdict (fail, __LINE__) } | |
273 | if (sizeof (v3) == 201) { setverdict (pass) } | |
274 | else { setverdict (fail, __LINE__) } | |
275 | } | |
276 | ||
277 | type integer intarr[2..5] | |
278 | ||
279 | testcase tc_TR938_939() runs on empty { | |
280 | // Constants with the same base-types, but initialized in different ways. | |
281 | // All the same. Evaluated during CP. It's specific to the mentioned | |
282 | // TR939, but the restructuring for TR938 should make this obsolete. | |
283 | const intlist il1 := { [0] := 0, [1] := 1 } | |
284 | const intlist il2 := { [0] := 0, [1] := 1 } | |
285 | const intlist il3 := { [1] := 1, [0] := 0 } | |
286 | const intlist il4 := { 0, 1 } | |
287 | const intlist il5 := { 1, 0 } | |
288 | const intlist il6 := { 0, 1, 2 } | |
289 | const intlist il7 := { [0] := 0, [1] := 1, [2] := 2 } | |
290 | const intlist il8 := { [2] := 2, [1] := 1, [0] := 0 } | |
291 | if (il1 == il1) { setverdict(pass) } else { setverdict(fail, __LINE__) } | |
292 | if (il1 == il2) { setverdict(pass) } else { setverdict(fail, __LINE__) } | |
293 | if (il1 == il3) { setverdict(pass) } else { setverdict(fail, __LINE__) } | |
294 | if (il1 == il4) { setverdict(pass) } else { setverdict(fail, __LINE__) } | |
295 | if (il1 == il2 and il2 == il3 | |
296 | and il3 == il4) { setverdict(pass) } else { setverdict(fail, __LINE__) } | |
297 | if (il1 != il5) { setverdict(pass) } else { setverdict(fail, __LINE__) } | |
298 | if (il1 != il6) { setverdict(pass) } else { setverdict(fail, __LINE__) } | |
299 | if (il1 != il7) { setverdict(pass) } else { setverdict(fail, __LINE__) } | |
300 | if (il1 != il8) { setverdict(pass) } else { setverdict(fail, __LINE__) } | |
301 | // Initializing value-range arrays. | |
302 | var intarr ia1 := { [2] := 2, [3] := 3, [4] := 4, [5] := 5 } | |
303 | var intarr ia2 := { 2, 3, 4, 5 } | |
304 | if (ia1 == ia2) { setverdict(pass) } else { setverdict(fail, __LINE__) } | |
305 | // Initializing arrays using dynamic index values. | |
306 | var integer i := 2 | |
307 | var intarr ia3 := { [i] := 2, [i] := 2 } | |
308 | ia3[i + 1] := 3; ia3[i + 2] := 4; ia3[i + 3] := 5 | |
309 | var intarr ia4 := { [i] := 2, [i] := 2 } | |
310 | ia4[i + 1] := 3; ia4[i + 2] := 4; ia4[i + 3] := 5 | |
311 | if (ia3 == ia4) { setverdict(pass) } else { setverdict(fail, __LINE__) } | |
312 | } | |
313 | ||
314 | // Test for TR943. The code section was not set correctly for references from | |
315 | // different modules. The module of the referenced index should come after | |
316 | // this module. Otherwise, the test is useless. | |
317 | template intlist t_intlist := { 0 } | |
318 | template intlist tm_intlist modifies t_intlist := { [idx_ASN] := 1 } | |
319 | testcase tc_TR943() runs on empty { | |
320 | // Same for values. | |
321 | var intlist il1 := { [idx_ASN] := 1 } | |
322 | if (il1 == { 1 }) { setverdict(pass) } else { setverdict(fail, __LINE__) } | |
323 | if (match(il1, tm_intlist)) { setverdict(pass) } else { setverdict(fail, __LINE__) } | |
324 | } | |
325 | ||
326 | control | |
327 | { | |
328 | execute (asns ()) | |
329 | execute (recofs ()) | |
330 | execute (setofs ()) | |
331 | execute (arrays ()) | |
332 | execute (configs ()) | |
333 | execute (tc_TR938_939 ()) | |
334 | execute (tc_TR943 ()) | |
335 | } | |
336 | } |