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 | * Baranyi, Botond | |
11 | * Kovacs, Ferenc | |
12 | * Raduly, Csaba | |
13 | * Szabados, Kristof | |
14 | * | |
970ed795 EL |
15 | ******************************************************************************/ |
16 | module TobjidOper { | |
17 | ||
18 | type component objidOper_comptype { } | |
19 | ||
20 | external function enco(in objid oi) return octetstring | |
21 | with { extension "prototype(convert) encode(BER:BER_ENCODE_DER)" } | |
22 | ||
23 | external function deco(in octetstring oi) return objid | |
24 | with { extension "prototype(convert) decode(BER:BER_ACCEPT_ALL)" } | |
25 | ||
26 | type objid typedefbasic_myobjid; | |
27 | type objid MyObjids0 (objid{itu_t(0) identified_organization(4) etsi(0)}) | |
28 | type objid MyObjids1 (objid{itu_t identified_organization etsi(0)}) | |
29 | type objid MyObjids2 (objid{0 4 0}) | |
30 | const integer c_etsi := 0 | |
31 | template integer t_etsi := 0 | |
32 | const objid itu_idOrg := objid{itu_t identified_organization} | |
33 | const objid c_etsiMobNet := objid{itu_t identified_organization etsi(0) mobile_domain(0) umts_Network(1)} | |
34 | const objid c_etsiNet := objid{itu_t identified_organization etsi(0) inDomain(1) in_Network(1)} | |
35 | type objid MyObjids3 (objid{itu_idOrg c_etsi}) | |
36 | type objid MyObjids4 (objid{0 4 0 0}, objid{0 4 0 1}) | |
37 | type MyObjids4 MyObjids5 | |
38 | template MyObjids4 t_myobjids1 := objid{0 4 0 0} | |
39 | // These should be allowed as well: | |
40 | // type MyObjids MyNarrowerObjids (objid{0 4 0 0 1 0}, objid{0 4 1 1}, objid{0 4 1 3}) | |
41 | // type objid MyObjidRange (objid{0 4 0 0}..objid{0 4 0 5}) | |
42 | // But concatenation of object identifier doesn't seem to work at all... | |
43 | ||
44 | // Lots of '1' bits | |
45 | const objid c_bits := objid { | |
46 | 0 | |
47 | ||
48 | 1 | |
49 | 3 | |
50 | 7 | |
51 | 15 | |
52 | 31 | |
53 | 63 | |
54 | 127 | |
55 | 255 | |
56 | ||
57 | 511 | |
58 | 1023 | |
59 | 2047 | |
60 | 4095 | |
61 | 8191 | |
62 | 16383 | |
63 | 32767 | |
64 | 65535 | |
65 | ||
66 | 131071 | |
67 | 262143 | |
68 | 524287 | |
69 | 1048575 | |
70 | 2097151 | |
71 | 4194303 | |
72 | 8388607 | |
73 | 16777215 | |
74 | ||
75 | 33554431 | |
76 | 67108863 | |
77 | 134217727 | |
78 | 268435455 | |
79 | 536870911 | |
80 | 1073741823 | |
81 | 2147483647 | |
82 | 4294967295 | |
83 | // 4294967296 is too big | |
84 | // 8589934592 | |
85 | }; | |
86 | ||
87 | // Powers of two | |
88 | const objid c_pow2 := objid { | |
89 | 1 | |
90 | 2 | |
91 | 4 | |
92 | 8 | |
93 | 16 | |
94 | 32 | |
95 | 64 | |
96 | 128 | |
97 | 256 | |
98 | ||
99 | 512 | |
100 | 1024 | |
101 | 2048 | |
102 | 4096 | |
103 | 8192 | |
104 | 16384 | |
105 | 32768 | |
106 | 65536 | |
107 | ||
108 | 131072 | |
109 | 262144 | |
110 | 524288 | |
111 | 1048576 | |
112 | 2097152 | |
113 | 4194304 | |
114 | 8388608 | |
115 | 16777216 | |
116 | ||
117 | 33554432 | |
118 | 67108864 | |
119 | 134217728 | |
120 | 268435456 | |
121 | 536870912 | |
122 | 1073741824 | |
123 | 2147483648 | |
124 | ||
125 | // 4294967296 is too big | |
126 | // 8589934592 | |
127 | }; | |
128 | ||
129 | const objid c_0_1_infinity // for small values of infinity | |
130 | := objid { 0 1 4294967295 } | |
131 | ||
132 | const octetstring expected := '0606018FFFFFFF7F'O | |
133 | ||
134 | // encoding of { 0 1 70368744177663 } a.k.a. { 0 1 0x3FFFFFFFFFFF } | |
135 | const octetstring bigger := '0608018FFFFFFFFFFF7F'O | |
136 | ||
137 | ||
138 | testcase objidSubtypes() runs on objidOper_comptype { | |
139 | if (c_etsiMobNet != c_etsiNet) { setverdict(pass) } | |
140 | else { setverdict(fail) } | |
141 | } | |
142 | ||
143 | external function indexer(in objid o, in integer idx) return integer; | |
144 | ||
145 | testcase encdec() runs on objidOper_comptype | |
146 | { | |
147 | var octetstring os := enco(c_0_1_infinity); | |
148 | //action(os); | |
149 | if (os == expected) { setverdict(pass); } | |
150 | else { setverdict(fail, match(os, expected)); } | |
151 | ||
152 | var objid oi := deco(expected); | |
153 | //action(oi); | |
154 | if (oi == c_0_1_infinity) { setverdict(pass); } | |
155 | else { setverdict(fail, match(oi, c_0_1_infinity)); } | |
156 | ||
157 | // Decode the bigger objid. The value will overflow and it will be clamped | |
158 | // to 2**32-1 (4294967295) as long as objid is limited to 32bits. | |
159 | oi := deco(bigger); | |
160 | action(oi); | |
161 | ||
162 | if (sizeof(oi) != sizeof(c_0_1_infinity)) { | |
163 | setverdict(fail, "Number of objid components: ", | |
164 | match(sizeof(oi), sizeof(c_0_1_infinity))) | |
165 | } | |
166 | else { | |
167 | // All components should look equal | |
168 | for (var integer i := 0; i < sizeof(oi); i := i + 1) { | |
169 | if (indexer(oi, i) == indexer(c_0_1_infinity, i)) { /*setverdict(pass);*/ } | |
170 | else { | |
171 | setverdict(fail, "Mismatch at ", i, ": ", | |
172 | match(indexer(oi, i), indexer(c_0_1_infinity, i))); | |
173 | } | |
174 | } | |
175 | } | |
176 | ||
177 | // However, the (decoded) oi has an overflow whereas c_0_1_infinity does not, | |
178 | // therefore they (should) compare as not equal. | |
179 | if (oi != c_0_1_infinity) { setverdict(pass, match(oi, c_0_1_infinity)); } | |
180 | else { setverdict(fail, match(oi, c_0_1_infinity)); } | |
181 | ||
182 | os := enco(c_bits); | |
970ed795 | 183 | oi := deco(os); |
970ed795 EL |
184 | |
185 | if (sizeof(oi) != sizeof(c_bits)) { | |
186 | setverdict(fail, "Number of objid components: ", | |
187 | match(sizeof(oi), sizeof(c_bits))) | |
188 | } | |
189 | else { | |
190 | // All components should look equal | |
191 | for (var integer i := 0; i < sizeof(oi); i := i + 1) { | |
192 | if (indexer(oi, i) == indexer(c_bits, i)) { /*setverdict(pass);*/ } | |
193 | else { | |
194 | setverdict(fail, "Mismatch at ", i, ": ", | |
195 | match(indexer(oi, i), indexer(c_bits, i))); | |
196 | } | |
197 | } | |
198 | } | |
199 | ||
200 | os := enco(c_pow2); | |
970ed795 | 201 | oi := deco(os); |
970ed795 EL |
202 | |
203 | if (sizeof(oi) != sizeof(c_pow2)) { | |
204 | setverdict(fail, "Number of objid components: ", | |
205 | match(sizeof(oi), sizeof(c_pow2))) | |
206 | } | |
207 | else { | |
208 | // All components should look equal | |
209 | for (var integer i := 0; i < sizeof(oi); i := i + 1) { | |
210 | if (indexer(oi, i) == indexer(c_pow2, i)) { /*setverdict(pass);*/ } | |
211 | else { | |
212 | setverdict(fail, "Mismatch at ", i, ": ", | |
213 | match(indexer(oi, i), indexer(c_pow2, i))); | |
214 | } | |
215 | } | |
216 | } | |
217 | ||
218 | } | |
219 | ||
220 | testcase objidWithVars() runs on objidOper_comptype | |
221 | { | |
222 | var integer v1 := 1; | |
223 | var integer v2 := 20; | |
224 | var integer v3 := 300; | |
225 | var integer v4 := -87; | |
226 | const integer c1 := 0; | |
227 | var objid o1 := objid { c1 v1 }; | |
970ed795 EL |
228 | |
229 | if (o1 == objid { 0 1 }) { setverdict(pass); } | |
230 | else { setverdict(fail, o1, " != ", objid { 0 1 }); } | |
231 | ||
232 | if (objid { c1 3 v2 } == objid { 0 3 20 }) { setverdict(pass); } | |
233 | else { setverdict(fail, objid { c1 3 v2 }, " != ", objid { 0 3 20 }); } | |
234 | ||
235 | if (objid { c1 2 3 } == objid { 0 2 3 }) { setverdict(pass); } | |
236 | else { setverdict(fail, objid { c1 2 3 }, " != ", objid { 0 2 3 }); } | |
237 | ||
238 | var objid o2 := objid { 0 v1 }; | |
239 | if (o1 == o2) { setverdict(pass); } | |
240 | else { setverdict(fail, o1, " != ", o2); } | |
241 | ||
242 | @try { | |
243 | var objid o_bad := objid { v1 v2 v3 v4 }; | |
244 | setverdict(fail, "error expected when creating ", objid { v1 v2 v3 v4 }); | |
245 | } | |
246 | @catch (msg) { | |
247 | if (match(msg, pattern "*Dynamic test case error: An OBJECT IDENTIFIER component cannot be negative")) { setverdict(pass); } | |
248 | else { setverdict(fail, "unexpected error: ", msg); } | |
249 | } | |
250 | ||
251 | var template objid to1 := (objid { 0 1 6 }, objid { v1 6 v3 }); | |
970ed795 EL |
252 | |
253 | if (match(objid { 1 6 v3 }, to1)) { setverdict(pass); } | |
254 | else { setverdict(fail, objid { 1 6 v3 }, " doesn't match ", to1); } | |
255 | ||
256 | if (match(objid { 1 2 3 }, to1)) { setverdict(fail, objid { 1 2 3 }, " matches ", to1); } | |
257 | else { setverdict(pass); } | |
258 | } | |
259 | ||
260 | control { | |
261 | execute(objidSubtypes()); | |
262 | execute(encdec()); | |
263 | execute(objidWithVars()); | |
264 | } | |
265 | ||
266 | } |