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