| 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 TrecofParamRef { |
| 9 | |
| 10 | import from BerType language "ASN.1:1997" all with { encode "DER:1997" }; |
| 11 | |
| 12 | // This module contains test cases, where a record of/set of and one of its elements are passed |
| 13 | // as inout parameters to a function. Inside this function modifications to the element will also modify |
| 14 | // the record of, while modifications to the record of may (in our case WILL) modify the element. |
| 15 | |
| 16 | type component CT_Empty {}; |
| 17 | |
| 18 | // 1. Assignment |
| 19 | type record of integer RoI; |
| 20 | |
| 21 | function f_param_ref_assign(inout RoI p_roi, inout integer p_elem) runs on CT_Empty |
| 22 | { |
| 23 | p_roi := { 10 }; |
| 24 | |
| 25 | if (p_roi == { 10 }) { setverdict(pass); }\r |
| 26 | else { setverdict(fail, "@1 got: ", p_roi, ", expected: { 10 }"); } |
| 27 | |
| 28 | if (log2str(p_elem) == "<unbound>") { setverdict(pass); }\r |
| 29 | else { setverdict(fail, "@2 got: ", p_elem, ", expected: <unbound>"); } |
| 30 | |
| 31 | p_elem := 20; |
| 32 | |
| 33 | if (log2str(p_roi) == "{ 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }") { setverdict(pass); } |
| 34 | else { setverdict(fail, "@3 got: ", p_roi, ", expected: { 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }"); } |
| 35 | } |
| 36 | |
| 37 | testcase tc_param_ref_assign() runs on CT_Empty |
| 38 | { |
| 39 | var RoI v_roi := { 0, 1, 2, 3, 4, 5 }; |
| 40 | f_param_ref_assign(v_roi, v_roi[5]); |
| 41 | |
| 42 | if (log2str(v_roi) == "{ 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }") { setverdict(pass); } |
| 43 | else { setverdict(fail, "@4 got: ", v_roi, ", expected: { 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }"); } |
| 44 | } |
| 45 | |
| 46 | // 2. Concatenation |
| 47 | function f_param_ref_concat(inout RoI p_roi, inout integer p_elem) runs on CT_Empty |
| 48 | { |
| 49 | const RoI c := { 9, 8, 7 }; |
| 50 | |
| 51 | p_roi := c & { 4, 5 }; |
| 52 | |
| 53 | if (p_roi == { 9, 8, 7, 4, 5 }) { setverdict(pass); }\r |
| 54 | else { setverdict(fail, "@1 got: ", p_roi, ", expected: { 9, 8, 7, 4, 5 }"); } |
| 55 | |
| 56 | if (log2str(p_elem) == "<unbound>") { setverdict(pass); }\r |
| 57 | else { setverdict(fail, "@2 got: ", p_elem, ", expected: <unbound>"); } |
| 58 | |
| 59 | p_elem := 20; |
| 60 | |
| 61 | if (log2str(p_roi) == "{ 9, 8, 7, 4, 5, 20 }") { setverdict(pass); } |
| 62 | else { setverdict(fail, "@3 got: ", p_roi, ", expected: { 9, 8, 7, 4, 5, 20 }"); } |
| 63 | |
| 64 | p_roi := p_roi & { 6, 7 }; |
| 65 | |
| 66 | if (p_roi == { 9, 8, 7, 4, 5, 20, 6, 7 }) { setverdict(pass); }\r |
| 67 | else { setverdict(fail, "@4 got: ", p_roi, ", expected: { 9, 8, 7, 4, 5, 20, 6, 7 }"); } |
| 68 | } |
| 69 | |
| 70 | testcase tc_param_ref_concat() runs on CT_Empty |
| 71 | { |
| 72 | var RoI v_roi := { 0, 1, 2, 3, 4, 5 }; |
| 73 | f_param_ref_concat(v_roi, v_roi[5]); |
| 74 | |
| 75 | if (log2str(v_roi) == "{ 9, 8, 7, 4, 5, 20, 6, 7 }") { setverdict(pass); } |
| 76 | else { setverdict(fail, "@5 got: ", v_roi, ", expected: { 9, 8, 7, 4, 5, 20, 6, 7 }"); } |
| 77 | } |
| 78 | |
| 79 | // 3. Replacing |
| 80 | function f_param_ref_replace(inout RoI p_roi, inout integer p_elem) runs on CT_Empty |
| 81 | { |
| 82 | const RoI c1 := { 7, 6 }; |
| 83 | const RoI c2 := { 5, 4, 3 }; |
| 84 | |
| 85 | p_roi := replace(p_roi, 2, 4, c1); |
| 86 | |
| 87 | if (p_roi == { 0, 1, 7, 6 }) { setverdict(pass); }\r |
| 88 | else { setverdict(fail, "@1 got: ", p_roi, ", expected: { 0, 1, 7, 6 }"); } |
| 89 | |
| 90 | if (log2str(p_elem) == "<unbound>") { setverdict(pass); }\r |
| 91 | else { setverdict(fail, "@2 got: ", p_elem, ", expected: <unbound>"); } |
| 92 | |
| 93 | p_elem := 20; |
| 94 | |
| 95 | if (log2str(p_roi) == "{ 0, 1, 7, 6, <unbound>, 20 }") { setverdict(pass); } |
| 96 | else { setverdict(fail, "@3 got: ", p_roi, ", expected: { 0, 1, 7, 6, <unbound>, 20 }"); } |
| 97 | |
| 98 | p_roi := replace(p_roi, 4, 2, c2); |
| 99 | |
| 100 | if (p_roi == { 0, 1, 7, 6, 5, 4, 3 }) { setverdict(pass); }\r |
| 101 | else { setverdict(fail, "@4 got: ", p_roi, ", expected: { 0, 1, 7, 6, 5, 4, 3 }"); } |
| 102 | |
| 103 | if (p_elem == 4) { setverdict(pass); }\r |
| 104 | else { setverdict(fail, "@5 got: ", p_elem, ", expected: 4"); } |
| 105 | } |
| 106 | |
| 107 | testcase tc_param_ref_replace() runs on CT_Empty |
| 108 | { |
| 109 | var RoI v_roi := { 0, 1, 2, 3, 4, 5 }; |
| 110 | f_param_ref_replace(v_roi, v_roi[5]); |
| 111 | |
| 112 | if (log2str(v_roi) == "{ 0, 1, 7, 6, 5, 4, 3 }") { setverdict(pass); } |
| 113 | else { setverdict(fail, "@6 got: ", v_roi, ", expected: { 0, 1, 7, 6, 5, 4, 3 }"); } |
| 114 | } |
| 115 | |
| 116 | // 4. JSON decoding |
| 117 | type record of integer RoI_json with { encode "JSON" }; |
| 118 | |
| 119 | external function f_enc_json(in RoI_json x) return octetstring |
| 120 | with { extension "prototype(convert) encode(JSON)" } |
| 121 | |
| 122 | external function f_dec_json(in octetstring os, out RoI_json x) |
| 123 | with { extension "prototype(fast) decode(JSON)" } |
| 124 | |
| 125 | function f_param_ref_json(inout RoI_json p_roi, inout integer p_elem) runs on CT_Empty |
| 126 | { |
| 127 | var RoI_json enc_val := { 10, 16 }; |
| 128 | var octetstring os := f_enc_json(enc_val); |
| 129 | f_dec_json(os, p_roi); |
| 130 | |
| 131 | if (p_roi == enc_val) { setverdict(pass); }\r |
| 132 | else { setverdict(fail, "@1 got: ", p_roi, ", expected: ", enc_val); } |
| 133 | |
| 134 | if (log2str(p_elem) == "<unbound>") { setverdict(pass); }\r |
| 135 | else { setverdict(fail, "@2 got: ", p_elem, ", expected: <unbound>"); } |
| 136 | |
| 137 | p_elem := 20; |
| 138 | |
| 139 | if (log2str(p_roi) == "{ 10, 16, <unbound>, <unbound>, <unbound>, 20 }") { setverdict(pass); } |
| 140 | else { setverdict(fail, "@3 got: ", p_roi, ", expected: { 10, 16, <unbound>, <unbound>, <unbound>, 20 }"); } |
| 141 | |
| 142 | enc_val := { 3, 2, 1, 9, 8, 7, 6 }; |
| 143 | os := f_enc_json(enc_val); |
| 144 | f_dec_json(os, p_roi); |
| 145 | |
| 146 | if (p_roi == enc_val) { setverdict(pass); }\r |
| 147 | else { setverdict(fail, "@4 got: ", p_roi, ", expected: ", enc_val); } |
| 148 | |
| 149 | if (p_elem == 7) { setverdict(pass); }\r |
| 150 | else { setverdict(fail, "@5 got: ", p_elem, ", expected: 7"); } |
| 151 | } |
| 152 | |
| 153 | testcase tc_param_ref_json() runs on CT_Empty |
| 154 | { |
| 155 | var RoI_json v_roi := { 0, 1, 2, 3, 4, 5 }; |
| 156 | f_param_ref_json(v_roi, v_roi[5]); |
| 157 | |
| 158 | if (log2str(v_roi) == "{ 3, 2, 1, 9, 8, 7, 6 }") { setverdict(pass); } |
| 159 | else { setverdict(fail, "@6 got: ", v_roi, ", expected: { 3, 2, 1, 9, 8, 7, 6 }"); } |
| 160 | } |
| 161 | |
| 162 | // 5. XER decoding |
| 163 | type record of integer RoI_xer with { encode "XML" }; |
| 164 | |
| 165 | external function f_enc_xer(in RoI_xer x) return octetstring |
| 166 | with { extension "prototype(convert) encode(XER:XER_EXTENDED)" } |
| 167 | |
| 168 | external function f_dec_xer(in octetstring os, out RoI_xer x) |
| 169 | with { extension "prototype(fast) decode(XER:XER_EXTENDED)" } |
| 170 | |
| 171 | function f_param_ref_xer(inout RoI_xer p_roi, inout integer p_elem) runs on CT_Empty |
| 172 | { |
| 173 | var RoI_xer enc_val := { 10, 16 }; |
| 174 | var octetstring os := f_enc_xer(enc_val); |
| 175 | f_dec_xer(os, p_roi); |
| 176 | |
| 177 | if (p_roi == enc_val) { setverdict(pass); }\r |
| 178 | else { setverdict(fail, "@1 got: ", p_roi, ", expected: ", enc_val); } |
| 179 | |
| 180 | if (log2str(p_elem) == "<unbound>") { setverdict(pass); }\r |
| 181 | else { setverdict(fail, "@2 got: ", p_elem, ", expected: <unbound>"); } |
| 182 | |
| 183 | p_elem := 20; |
| 184 | |
| 185 | if (log2str(p_roi) == "{ 10, 16, <unbound>, <unbound>, <unbound>, 20 }") { setverdict(pass); } |
| 186 | else { setverdict(fail, "@3 got: ", p_roi, ", expected: { 10, 16, <unbound>, <unbound>, <unbound>, 20 }"); } |
| 187 | |
| 188 | enc_val := { 3, 2, 1, 9, 8, 7, 6 }; |
| 189 | os := f_enc_xer(enc_val); |
| 190 | f_dec_xer(os, p_roi); |
| 191 | |
| 192 | if (p_roi == enc_val) { setverdict(pass); }\r |
| 193 | else { setverdict(fail, "@4 got: ", p_roi, ", expected: ", enc_val); } |
| 194 | |
| 195 | if (p_elem == 7) { setverdict(pass); }\r |
| 196 | else { setverdict(fail, "@5 got: ", p_elem, ", expected: 7"); } |
| 197 | } |
| 198 | |
| 199 | testcase tc_param_ref_xer() runs on CT_Empty |
| 200 | { |
| 201 | var RoI_xer v_roi := { 0, 1, 2, 3, 4, 5 }; |
| 202 | f_param_ref_xer(v_roi, v_roi[5]); |
| 203 | |
| 204 | if (log2str(v_roi) == "{ 3, 2, 1, 9, 8, 7, 6 }") { setverdict(pass); } |
| 205 | else { setverdict(fail, "@6 got: ", v_roi, ", expected: { 3, 2, 1, 9, 8, 7, 6 }"); } |
| 206 | } |
| 207 | |
| 208 | // 6. TEXT decoding |
| 209 | type record of integer RoI_text with { encode "TEXT"; variant "BEGIN('numbrz:'),END(';'),SEPARATOR(' ')"; }; |
| 210 | |
| 211 | external function f_enc_text(in RoI_text x) return charstring |
| 212 | with { extension "prototype(convert) encode(TEXT)" } |
| 213 | |
| 214 | external function f_dec_text(in charstring cs, out RoI_text x) |
| 215 | with { extension "prototype(fast) decode(TEXT)" } |
| 216 | |
| 217 | function f_param_ref_text(inout RoI_text p_roi, inout integer p_elem) runs on CT_Empty |
| 218 | { |
| 219 | var RoI_text enc_val := { 10, 16 }; |
| 220 | var charstring cs := f_enc_text(enc_val); |
| 221 | f_dec_text(cs, p_roi); |
| 222 | |
| 223 | if (p_roi == enc_val) { setverdict(pass); }\r |
| 224 | else { setverdict(fail, "@1 got: ", p_roi, ", expected: ", enc_val); } |
| 225 | |
| 226 | if (log2str(p_elem) == "<unbound>") { setverdict(pass); }\r |
| 227 | else { setverdict(fail, "@2 got: ", p_elem, ", expected: <unbound>"); } |
| 228 | |
| 229 | p_elem := 20; |
| 230 | |
| 231 | if (log2str(p_roi) == "{ 10, 16, <unbound>, <unbound>, <unbound>, 20 }") { setverdict(pass); } |
| 232 | else { setverdict(fail, "@3 got: ", p_roi, ", expected: { 10, 16, <unbound>, <unbound>, <unbound>, 20 }"); } |
| 233 | |
| 234 | enc_val := { 3, 2, 1, 9, 8, 7, 6 }; |
| 235 | cs := f_enc_text(enc_val); |
| 236 | f_dec_text(cs, p_roi); |
| 237 | |
| 238 | if (p_roi == enc_val) { setverdict(pass); }\r |
| 239 | else { setverdict(fail, "@4 got: ", p_roi, ", expected: ", enc_val); } |
| 240 | |
| 241 | if (p_elem == 7) { setverdict(pass); }\r |
| 242 | else { setverdict(fail, "@5 got: ", p_elem, ", expected: 7"); } |
| 243 | } |
| 244 | |
| 245 | testcase tc_param_ref_text() runs on CT_Empty |
| 246 | { |
| 247 | var RoI_text v_roi := { 0, 1, 2, 3, 4, 5 }; |
| 248 | f_param_ref_text(v_roi, v_roi[5]); |
| 249 | |
| 250 | if (log2str(v_roi) == "{ 3, 2, 1, 9, 8, 7, 6 }") { setverdict(pass); } |
| 251 | else { setverdict(fail, "@6 got: ", v_roi, ", expected: { 3, 2, 1, 9, 8, 7, 6 }"); } |
| 252 | } |
| 253 | |
| 254 | // 7. RAW decoding |
| 255 | type record of integer RoI_raw with { encode "RAW"; variant "" }; |
| 256 | |
| 257 | external function f_enc_raw(in RoI_raw x) return octetstring |
| 258 | with { extension "prototype(convert) encode(RAW)" } |
| 259 | |
| 260 | external function f_dec_raw(in octetstring os, out RoI_raw x) |
| 261 | with { extension "prototype(fast) decode(RAW)" } |
| 262 | |
| 263 | function f_param_ref_raw(inout RoI_raw p_roi, inout integer p_elem) runs on CT_Empty |
| 264 | { |
| 265 | var RoI_raw enc_val := { 10, 16 }; |
| 266 | var octetstring os := f_enc_raw(enc_val); |
| 267 | f_dec_raw(os, p_roi); |
| 268 | |
| 269 | if (p_roi == enc_val) { setverdict(pass); }\r |
| 270 | else { setverdict(fail, "@1 got: ", p_roi, ", expected: ", enc_val); } |
| 271 | |
| 272 | if (log2str(p_elem) == "<unbound>") { setverdict(pass); }\r |
| 273 | else { setverdict(fail, "@2 got: ", p_elem, ", expected: <unbound>"); } |
| 274 | |
| 275 | p_elem := 20; |
| 276 | |
| 277 | if (log2str(p_roi) == "{ 10, 16, <unbound>, <unbound>, <unbound>, 20 }") { setverdict(pass); } |
| 278 | else { setverdict(fail, "@3 got: ", p_roi, ", expected: { 10, 16, <unbound>, <unbound>, <unbound>, 20 }"); } |
| 279 | |
| 280 | enc_val := { 3, 2, 1, 9, 8, 7, 6 }; |
| 281 | os := f_enc_raw(enc_val); |
| 282 | f_dec_raw(os, p_roi); |
| 283 | |
| 284 | if (p_roi == enc_val) { setverdict(pass); }\r |
| 285 | else { setverdict(fail, "@4 got: ", p_roi, ", expected: ", enc_val); } |
| 286 | |
| 287 | if (p_elem == 7) { setverdict(pass); }\r |
| 288 | else { setverdict(fail, "@5 got: ", p_elem, ", expected: 7"); } |
| 289 | } |
| 290 | |
| 291 | testcase tc_param_ref_raw() runs on CT_Empty |
| 292 | { |
| 293 | var RoI_raw v_roi := { 0, 1, 2, 3, 4, 5 }; |
| 294 | f_param_ref_raw(v_roi, v_roi[5]); |
| 295 | |
| 296 | if (log2str(v_roi) == "{ 3, 2, 1, 9, 8, 7, 6 }") { setverdict(pass); } |
| 297 | else { setverdict(fail, "@6 got: ", v_roi, ", expected: { 3, 2, 1, 9, 8, 7, 6 }"); } |
| 298 | } |
| 299 | |
| 300 | // 8. BER decoding, using record of integer type defined in BerType.asn |
| 301 | |
| 302 | external function f_enc_ber(in RoI_ber x) return octetstring |
| 303 | with { extension "prototype(convert) encode(BER:BER_ENCODE_DER)" } |
| 304 | |
| 305 | external function f_dec_ber(in octetstring os, out RoI_ber x) |
| 306 | with { extension "prototype(fast) decode(BER:BER_ACCEPT_ALL)" } |
| 307 | |
| 308 | function f_param_ref_ber(inout RoI_ber p_roi, inout integer p_elem) runs on CT_Empty |
| 309 | { |
| 310 | var RoI_ber enc_val := { 10, 16 }; |
| 311 | var octetstring os := f_enc_ber(enc_val); |
| 312 | f_dec_ber(os, p_roi); |
| 313 | |
| 314 | if (p_roi == enc_val) { setverdict(pass); }\r |
| 315 | else { setverdict(fail, "@1 got: ", p_roi, ", expected: ", enc_val); } |
| 316 | |
| 317 | if (log2str(p_elem) == "<unbound>") { setverdict(pass); }\r |
| 318 | else { setverdict(fail, "@2 got: ", p_elem, ", expected: <unbound>"); } |
| 319 | |
| 320 | p_elem := 20; |
| 321 | |
| 322 | if (log2str(p_roi) == "{ 10, 16, <unbound>, <unbound>, <unbound>, 20 }") { setverdict(pass); } |
| 323 | else { setverdict(fail, "@3 got: ", p_roi, ", expected: { 10, 16, <unbound>, <unbound>, <unbound>, 20 }"); } |
| 324 | |
| 325 | enc_val := { 3, 2, 1, 9, 8, 7, 6 }; |
| 326 | os := f_enc_ber(enc_val); |
| 327 | f_dec_ber(os, p_roi); |
| 328 | |
| 329 | if (p_roi == enc_val) { setverdict(pass); }\r |
| 330 | else { setverdict(fail, "@4 got: ", p_roi, ", expected: ", enc_val); } |
| 331 | |
| 332 | if (p_elem == 7) { setverdict(pass); }\r |
| 333 | else { setverdict(fail, "@5 got: ", p_elem, ", expected: 7"); } |
| 334 | } |
| 335 | |
| 336 | testcase tc_param_ref_ber() runs on CT_Empty |
| 337 | { |
| 338 | var RoI_ber v_roi := { 0, 1, 2, 3, 4, 5 }; |
| 339 | f_param_ref_ber(v_roi, v_roi[5]); |
| 340 | |
| 341 | if (log2str(v_roi) == "{ 3, 2, 1, 9, 8, 7, 6 }") { setverdict(pass); } |
| 342 | else { setverdict(fail, "@6 got: ", v_roi, ", expected: { 3, 2, 1, 9, 8, 7, 6 }"); } |
| 343 | } |
| 344 | |
| 345 | // 9. The record of is embedded in another structure |
| 346 | type record EmbRec { |
| 347 | charstring text, |
| 348 | RoI numbers |
| 349 | } |
| 350 | |
| 351 | function f_param_ref_emb_recof(inout EmbRec p_rec, inout integer p_elem) runs on CT_Empty |
| 352 | { |
| 353 | p_rec := { "second", { 10 } }; |
| 354 | |
| 355 | if (p_rec == { "second", { 10 } }) { setverdict(pass); }\r |
| 356 | else { setverdict(fail, "@1 got: ", p_rec, ", expected: { text := \"second\", numbers := { 10 } }"); } |
| 357 | |
| 358 | if (log2str(p_elem) == "<unbound>") { setverdict(pass); }\r |
| 359 | else { setverdict(fail, "@2 got: ", p_elem, ", expected: <unbound>"); } |
| 360 | |
| 361 | p_elem := 20; |
| 362 | |
| 363 | if (log2str(p_rec) == "{ text := \"second\", numbers := { 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 } }") { setverdict(pass); } |
| 364 | else { setverdict(fail, "@3 got: ", p_rec, ", expected: { text := \"second\", numbers := { 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 } }"); } |
| 365 | } |
| 366 | |
| 367 | testcase tc_param_ref_emb_recof() runs on CT_Empty |
| 368 | { |
| 369 | var EmbRec v_rec := { "first", { 0, 1, 2, 3, 4, 5 } }; |
| 370 | f_param_ref_emb_recof(v_rec, v_rec.numbers[5]); |
| 371 | |
| 372 | if (log2str(v_rec) == "{ text := \"second\", numbers := { 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 } }") { setverdict(pass); } |
| 373 | else { setverdict(fail, "@4 got: ", v_rec, ", expected: { text := \"second\", numbers := { 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 } }"); } |
| 374 | } |
| 375 | |
| 376 | // 10. The second parameter is not the whole element type, just a part of it |
| 377 | type record ElemType { |
| 378 | integer num, |
| 379 | charstring str |
| 380 | } |
| 381 | |
| 382 | type record of ElemType Elems; |
| 383 | |
| 384 | function f_param_ref_emb_elem(inout Elems p_elems, inout integer p_num) runs on CT_Empty |
| 385 | { |
| 386 | p_elems := { { 10, "ten" } }; |
| 387 | |
| 388 | if (p_elems == { { 10, "ten" } }) { setverdict(pass); }\r |
| 389 | else { setverdict(fail, "@1 got: ", p_elems, ", expected: { { num := 10, str := \"ten\" } }"); } |
| 390 | |
| 391 | if (log2str(p_num) == "<unbound>") { setverdict(pass); }\r |
| 392 | else { setverdict(fail, "@2 got: ", p_num, ", expected: <unbound>"); } |
| 393 | |
| 394 | p_num := 20; |
| 395 | |
| 396 | if (log2str(p_elems) == "{ { num := 10, str := \"ten\" }, <unbound>, { num := 20, str := <unbound> } }") { setverdict(pass); } |
| 397 | else { setverdict(fail, "@3 got: ", p_elems, ", expected: { { num := 10, str := \"ten\" }, <unbound>, { num := 20, str := <unbound> } }"); } |
| 398 | } |
| 399 | |
| 400 | testcase tc_param_ref_emb_elem() runs on CT_Empty |
| 401 | { |
| 402 | var Elems v_elems := { { 1, "one" }, { 2, "two" }, { 3, "three" }, { 4, "four" } }; |
| 403 | f_param_ref_emb_elem(v_elems, v_elems[2].num); |
| 404 | |
| 405 | if (log2str(v_elems) == "{ { num := 10, str := \"ten\" }, <unbound>, { num := 20, str := <unbound> } }") { setverdict(pass); } |
| 406 | else { setverdict(fail, "@4 got: ", v_elems, ", expected: { { num := 10, str := \"ten\" }, <unbound>, { num := 20, str := <unbound> } }"); } |
| 407 | } |
| 408 | |
| 409 | // 11. Two embedded functions, each called with a reference to one of the elements in the record of |
| 410 | function f_param_ref_emb_inner(inout RoI p_roi, inout integer p_elem) runs on CT_Empty |
| 411 | { |
| 412 | p_roi := { 10 }; |
| 413 | |
| 414 | if (p_roi == { 10 }) { setverdict(pass); }\r |
| 415 | else { setverdict(fail, "@1 got: ", p_roi, ", expected: { 10 }"); } |
| 416 | |
| 417 | if (log2str(p_elem) == "<unbound>") { setverdict(pass); }\r |
| 418 | else { setverdict(fail, "@2 got: ", p_elem, ", expected: <unbound>"); } |
| 419 | |
| 420 | p_elem := 20; |
| 421 | |
| 422 | if (log2str(p_roi) == "{ 10, <unbound>, <unbound>, 20 }") { setverdict(pass); } |
| 423 | else { setverdict(fail, "@3 got: ", p_roi, ", expected: { 10, <unbound>, <unbound>, 20 }"); } |
| 424 | } |
| 425 | |
| 426 | function f_param_ref_emb_outer(inout RoI p_roi, inout integer p_elem) runs on CT_Empty |
| 427 | { |
| 428 | f_param_ref_emb_inner(p_roi, p_roi[3]); |
| 429 | |
| 430 | if (log2str(p_elem) == "<unbound>") { setverdict(pass); }\r |
| 431 | else { setverdict(fail, "@4 got: ", p_elem, ", expected: <unbound>"); } |
| 432 | |
| 433 | p_elem := 30; |
| 434 | |
| 435 | if (log2str(p_roi) == "{ 10, <unbound>, <unbound>, 20, <unbound>, 30 }") { setverdict(pass); } |
| 436 | else { setverdict(fail, "@5 got: ", p_roi, ", expected: { 10, <unbound>, <unbound>, 20, <unbound>, 30 }"); } |
| 437 | } |
| 438 | |
| 439 | testcase tc_param_ref_emb_func() runs on CT_Empty |
| 440 | { |
| 441 | var RoI v_roi := { 0, 1, 2, 3, 4, 5 }; |
| 442 | f_param_ref_emb_outer(v_roi, v_roi[5]); |
| 443 | |
| 444 | if (log2str(v_roi) == "{ 10, <unbound>, <unbound>, 20, <unbound>, 30 }") { setverdict(pass); } |
| 445 | else { setverdict(fail, "@6 got: ", v_roi, ", expected: { 10, <unbound>, <unbound>, 20, <unbound>, 30 }"); } |
| 446 | } |
| 447 | |
| 448 | // 12. The element as out parameter instead of inout (it will be set to unbound at the begining of the function) |
| 449 | function f_param_ref_out_par(inout RoI p_roi, out integer p_elem) runs on CT_Empty |
| 450 | { |
| 451 | if (log2str(p_roi) == "{ 0, 1, 2, 3, <unbound>, 5 }") { setverdict(pass); } |
| 452 | else { setverdict(fail, "@1 got: ", p_roi, ", expected: { 0, 1, 2, 3, <unbound>, 5 }"); } |
| 453 | |
| 454 | p_roi := { 9, 8, 7, 6, 5 }; |
| 455 | |
| 456 | if (p_elem == 5) { setverdict(pass); }\r |
| 457 | else { setverdict(fail, "@2 got: ", p_elem, ", expected: 5"); } |
| 458 | |
| 459 | p_elem := 20; |
| 460 | |
| 461 | if (log2str(p_roi) == "{ 9, 8, 7, 6, 20 }") { setverdict(pass); } |
| 462 | else { setverdict(fail, "@3 got: ", p_roi, ", expected: { 9, 8, 7, 6, 20 }"); } |
| 463 | } |
| 464 | |
| 465 | testcase tc_param_ref_out_par() runs on CT_Empty |
| 466 | { |
| 467 | var RoI v_roi := { 0, 1, 2, 3, 4, 5 }; |
| 468 | f_param_ref_out_par(v_roi, v_roi[4]); |
| 469 | |
| 470 | if (log2str(v_roi) == "{ 9, 8, 7, 6, 20 }") { setverdict(pass); } |
| 471 | else { setverdict(fail, "@4 got: ", v_roi, ", expected: { 9, 8, 7, 6, 20 }"); } |
| 472 | } |
| 473 | |
| 474 | // 13. Copying the array |
| 475 | function f_param_ref_copy(inout RoI p_roi, inout integer p_elem) runs on CT_Empty |
| 476 | { |
| 477 | var RoI v_copy := p_roi; |
| 478 | p_roi := { 10 }; |
| 479 | |
| 480 | if (p_roi == { 10 }) { setverdict(pass); }\r |
| 481 | else { setverdict(fail, "@1 got: ", p_roi, ", expected: { 10 }"); } |
| 482 | |
| 483 | if (log2str(p_elem) == "<unbound>") { setverdict(pass); }\r |
| 484 | else { setverdict(fail, "@2 got: ", p_elem, ", expected: <unbound>"); } |
| 485 | |
| 486 | p_elem := 20; |
| 487 | |
| 488 | if (log2str(p_roi) == "{ 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }") { setverdict(pass); } |
| 489 | else { setverdict(fail, "@3 got: ", p_roi, ", expected: { 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }"); } |
| 490 | |
| 491 | if (v_copy == { 0, 1, 2, 3, 4, 5 }) { setverdict(pass); } |
| 492 | else { setverdict(fail, "@4 got: ", v_copy, ", expected: { 0, 1, 2, 3, 4, 5 }"); } |
| 493 | |
| 494 | v_copy := p_roi; |
| 495 | v_copy[5] := 11; |
| 496 | v_copy[2] := 3; |
| 497 | |
| 498 | if (log2str(p_roi) == "{ 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }") { setverdict(pass); } |
| 499 | else { setverdict(fail, "@5 got: ", p_roi, ", expected: { 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }"); } |
| 500 | } |
| 501 | |
| 502 | testcase tc_param_ref_copy() runs on CT_Empty |
| 503 | { |
| 504 | var RoI v_roi := { 0, 1, 2, 3, 4, 5 }; |
| 505 | var RoI v_copy := v_roi; |
| 506 | f_param_ref_copy(v_roi, v_roi[5]); |
| 507 | |
| 508 | if (log2str(v_roi) == "{ 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }") { setverdict(pass); } |
| 509 | else { setverdict(fail, "@6 got: ", v_roi, ", expected: { 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }"); } |
| 510 | |
| 511 | if (v_copy == { 0, 1, 2, 3, 4, 5 }) { setverdict(pass); } |
| 512 | else { setverdict(fail, "@7 got: ", v_copy, ", expected: { 0, 1, 2, 3, 4, 5 }"); } |
| 513 | } |
| 514 | |
| 515 | // 14. Arrays |
| 516 | type integer Ints[6]; |
| 517 | function f_param_ref_array(inout Ints p_arr, inout integer p_elem) runs on CT_Empty |
| 518 | { |
| 519 | p_arr := { 10, 12, 14, 16, 18, 20 }; |
| 520 | |
| 521 | if (p_elem == 20) { setverdict(pass); }\r |
| 522 | else { setverdict(fail, "@1 got: ", p_elem, ", expected: 20"); } |
| 523 | |
| 524 | p_elem := 7; |
| 525 | |
| 526 | if (log2str(p_arr) == "{ 10, 12, 14, 16, 18, 7 }") { setverdict(pass); } |
| 527 | else { setverdict(fail, "@2 got: ", p_arr, ", expected: { 10, 12, 14, 16, 18, 7 }"); } |
| 528 | } |
| 529 | |
| 530 | testcase tc_param_ref_array() runs on CT_Empty |
| 531 | { |
| 532 | var Ints v_arr := { 0, 1, 2, 3, 4, 5 }; |
| 533 | f_param_ref_array(v_arr, v_arr[5]); |
| 534 | |
| 535 | if (log2str(v_arr) == "{ 10, 12, 14, 16, 18, 7 }") { setverdict(pass); } |
| 536 | else { setverdict(fail, "@3 got: ", v_arr, ", expected: { 10, 12, 14, 16, 18, 7 }"); } |
| 537 | } |
| 538 | |
| 539 | // 15. Multiple array indexes |
| 540 | type record of EmbRec EmbRecs; |
| 541 | |
| 542 | function f_param_ref_multi(inout EmbRecs p_recs, inout integer p_elem) runs on CT_Empty |
| 543 | { |
| 544 | p_recs := { { "just one", { 10 } } }; |
| 545 | |
| 546 | if (p_recs == { { "just one", { 10 } } }) { setverdict(pass); }\r |
| 547 | else { setverdict(fail, "@1 got: ", p_recs, ", expected: { { text := \"just one\", numbers := { 10 } } }"); } |
| 548 | |
| 549 | if (log2str(p_elem) == "<unbound>") { setverdict(pass); }\r |
| 550 | else { setverdict(fail, "@2 got: ", p_elem, ", expected: <unbound>"); } |
| 551 | |
| 552 | p_elem := 20; |
| 553 | |
| 554 | if (log2str(p_recs) == "{ { text := \"just one\", numbers := { 10 } }, <unbound>, { text := <unbound>, numbers := { <unbound>, 20 } } }") { setverdict(pass); } |
| 555 | else { setverdict(fail, "@3 got: ", p_recs, ", expected: { { text := \"just one\", numbers := { 10 } }, <unbound>, { text := <unbound>, numbers := { <unbound>, 20 } } }"); } |
| 556 | } |
| 557 | |
| 558 | testcase tc_param_ref_multi() runs on CT_Empty |
| 559 | { |
| 560 | var EmbRecs v_recs := { { "first", { 5, 10, 15 } }, { "second", { 7 } }, { "third", { 1, 2, 3 } } }; |
| 561 | f_param_ref_multi(v_recs, v_recs[2].numbers[1]); |
| 562 | |
| 563 | if (log2str(v_recs) == "{ { text := \"just one\", numbers := { 10 } }, <unbound>, { text := <unbound>, numbers := { <unbound>, 20 } } }") { setverdict(pass); } |
| 564 | else { setverdict(fail, "@4 got: ", v_recs, ", expected: { { text := \"just one\", numbers := { 10 } }, <unbound>, { text := <unbound>, numbers := { <unbound>, 20 } } }"); } |
| 565 | } |
| 566 | |
| 567 | // 16. Template parameter |
| 568 | function f_param_ref_templ8(inout template RoI pt_roi, inout template integer pt_elem) runs on CT_Empty |
| 569 | { |
| 570 | pt_roi := { 10 }; |
| 571 | |
| 572 | if (log2str(pt_roi) == "{ 10 }") { setverdict(pass); }\r |
| 573 | else { setverdict(fail, "@1 got: ", pt_roi, ", expected: { 10 }"); } |
| 574 | |
| 575 | if (log2str(pt_elem) == "<unbound>") { setverdict(pass); }\r |
| 576 | else { setverdict(fail, "@2 got: ", pt_elem, ", expected: <unbound>"); } |
| 577 | |
| 578 | pt_elem := 20; |
| 579 | |
| 580 | if (log2str(pt_roi) == "{ 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }") { setverdict(pass); } |
| 581 | else { setverdict(fail, "@3 got: ", pt_roi, ", expected: { 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }"); } |
| 582 | } |
| 583 | |
| 584 | testcase tc_param_ref_templ8() runs on CT_Empty |
| 585 | { |
| 586 | var template RoI vt_roi := { 0, 1, 2, 3, 4, 5 }; |
| 587 | f_param_ref_templ8(vt_roi, vt_roi[5]); |
| 588 | |
| 589 | if (log2str(vt_roi) == "{ 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }") { setverdict(pass); } |
| 590 | else { setverdict(fail, "@4 got: ", vt_roi, ", expected: { 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }"); } |
| 591 | } |
| 592 | |
| 593 | // 17. Same as no. 9 (record of embedded in a record) but with the record of field being optional |
| 594 | type record EmbRecOpt { |
| 595 | charstring text, |
| 596 | RoI numbers optional |
| 597 | } |
| 598 | |
| 599 | function f_param_ref_emb_recof_opt(inout EmbRecOpt p_rec, inout integer p_elem) runs on CT_Empty |
| 600 | { |
| 601 | p_rec := { "second", omit }; |
| 602 | |
| 603 | if (p_rec == { "second", omit }) { setverdict(pass); }\r |
| 604 | else { setverdict(fail, "@1 got: ", p_rec, ", expected: { text := \"second\", numbers := omit }"); } |
| 605 | |
| 606 | if (log2str(p_elem) == "<unbound>") { setverdict(pass); }\r |
| 607 | else { setverdict(fail, "@2 got: ", p_elem, ", expected: <unbound>"); } |
| 608 | |
| 609 | p_elem := 20; |
| 610 | |
| 611 | if (log2str(p_rec) == "{ text := \"second\", numbers := { <unbound>, <unbound>, <unbound>, <unbound>, <unbound>, 20 } }") { setverdict(pass); } |
| 612 | else { setverdict(fail, "@3 got: ", p_rec, ", expected: { text := \"second\", numbers := { <unbound>, <unbound>, <unbound>, <unbound>, <unbound>, 20 } }"); } |
| 613 | } |
| 614 | |
| 615 | testcase tc_param_ref_emb_recof_opt() runs on CT_Empty |
| 616 | { |
| 617 | var EmbRecOpt v_rec := { "first", { 0, 1, 2, 3, 4, 5 } }; |
| 618 | f_param_ref_emb_recof_opt(v_rec, v_rec.numbers[5]); |
| 619 | |
| 620 | if (log2str(v_rec) == "{ text := \"second\", numbers := { <unbound>, <unbound>, <unbound>, <unbound>, <unbound>, 20 } }") { setverdict(pass); } |
| 621 | else { setverdict(fail, "@4 got: ", v_rec, ", expected: { text := \"second\", numbers := { <unbound>, <unbound>, <unbound>, <unbound>, <unbound>, 20 } }"); } |
| 622 | } |
| 623 | |
| 624 | // 18. The function call is part of a lazy parameter expression |
| 625 | function f_param_ref_emb_lazy(inout RoI p_roi, inout integer p_elem) runs on CT_Empty return charstring |
| 626 | { |
| 627 | p_roi := { 10 }; |
| 628 | |
| 629 | if (p_roi == { 10 }) { setverdict(pass); }\r |
| 630 | else { setverdict(fail, "@1 got: ", p_roi, ", expected: { 10 }"); } |
| 631 | |
| 632 | if (log2str(p_elem) == "<unbound>") { setverdict(pass); }\r |
| 633 | else { setverdict(fail, "@2 got: ", p_elem, ", expected: <unbound>"); } |
| 634 | |
| 635 | p_elem := 20; |
| 636 | |
| 637 | if (log2str(p_roi) == "{ 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }") { setverdict(pass); } |
| 638 | else { setverdict(fail, "@3 got: ", p_roi, ", expected: { 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }"); } |
| 639 | |
| 640 | return int2str(p_elem); |
| 641 | } |
| 642 | |
| 643 | function f_lazy(in integer p_val, in @lazy charstring p_str) runs on CT_Empty |
| 644 | { |
| 645 | if (isbound(p_val)) { |
| 646 | log(p_str); |
| 647 | setverdict(pass); |
| 648 | } |
| 649 | else { |
| 650 | setverdict(fail, "lazy expression evaluated too soon"); |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | testcase tc_param_ref_emb_lazy() runs on CT_Empty |
| 655 | { |
| 656 | var RoI v_roi := { 0, 1, 2, 3, 4, 5 }; |
| 657 | f_lazy(v_roi[1], f_param_ref_emb_lazy(v_roi, v_roi[5])); |
| 658 | |
| 659 | if (log2str(v_roi) == "{ 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }") { setverdict(pass); } |
| 660 | else { setverdict(fail, "@4 got: ", v_roi, ", expected: { 10, <unbound>, <unbound>, <unbound>, <unbound>, 20 }"); } |
| 661 | } |
| 662 | |
| 663 | // 19. The function call is interrupted by a DTE, the reference to the element should be cleaned up (HT47424) |
| 664 | function f_dte(in RoI p_roi, inout integer p_val) runs on CT_Empty |
| 665 | { |
| 666 | var integer bad_index := -1; |
| 667 | if (p_val < p_roi[bad_index]) { |
| 668 | setverdict(fail, "expected DTE in if clause"); |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | testcase tc_param_ref_dte() runs on CT_Empty |
| 673 | { |
| 674 | var RoI v_roi := { 0, 1, 2, 3 }; |
| 675 | @try { |
| 676 | f_dte(v_roi, v_roi[2]); |
| 677 | setverdict(fail, "expected DTE in function call"); |
| 678 | } |
| 679 | @catch (dummy) {} |
| 680 | v_roi := { }; |
| 681 | var RoI v_copy := v_roi; |
| 682 | var charstring log_exp := "{ }"; |
| 683 | if (log2str(v_roi) == log_exp) { setverdict(pass); } |
| 684 | else { setverdict(fail, "@1 got: ", v_roi, ", expected: ", log_exp); } |
| 685 | if (log2str(v_copy) == log_exp) { setverdict(pass); } |
| 686 | else { setverdict(fail, "@2 got: ", v_copy, ", expected: ", log_exp); } |
| 687 | } |
| 688 | |
| 689 | control { |
| 690 | execute(tc_param_ref_assign()); |
| 691 | execute(tc_param_ref_concat()); |
| 692 | execute(tc_param_ref_replace()); |
| 693 | |
| 694 | execute(tc_param_ref_json()); |
| 695 | execute(tc_param_ref_xer()); |
| 696 | execute(tc_param_ref_text()); |
| 697 | execute(tc_param_ref_raw()); |
| 698 | execute(tc_param_ref_ber()); |
| 699 | |
| 700 | execute(tc_param_ref_emb_recof()); |
| 701 | execute(tc_param_ref_emb_elem()); |
| 702 | execute(tc_param_ref_emb_func()); |
| 703 | |
| 704 | execute(tc_param_ref_out_par()); |
| 705 | execute(tc_param_ref_copy()); |
| 706 | execute(tc_param_ref_array()); |
| 707 | execute(tc_param_ref_multi()); |
| 708 | |
| 709 | //execute(tc_param_ref_templ8()); Doesn't work for templates |
| 710 | |
| 711 | execute(tc_param_ref_emb_recof_opt()); |
| 712 | execute(tc_param_ref_emb_lazy()); |
| 713 | |
| 714 | execute(tc_param_ref_dte()); |
| 715 | } |
| 716 | |
| 717 | } // end of module |