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 ******************************************************************************/
10 type component Nothing {};
18 record of universal charstring strs
21 variant "" // to force RAW encoding
24 external function enc_r(in E e, out octetstring o)
25 with { extension "prototype(fast) encode(RAW)" }
27 external function dec_r(inout octetstring o, out E e) return integer
28 with { extension "prototype(sliding) decode(RAW)" }
35 /* * * * * * * * * * */
43 record of universal charstring strs
46 variant "BEGIN('Header: ')"
47 variant "SEPARATOR(';')"
48 //variant "BEGIN(1)" // to force TEXT encoding
51 external function enc_t(in Et e, out charstring o)
52 with { extension "prototype(fast) encode(TEXT)" }
54 external function dec_t(inout charstring o, out Et e) return integer
55 with { extension "prototype(sliding) decode(TEXT)" }
62 /* * * * * * * * * * */
65 universal charstring str
70 external function f_enc_data(in Data d) return octetstring
71 with { extension "prototype(convert) encode(JSON)" }
73 external function f_dec_data(inout octetstring x, out Data d) return integer
74 with { extension "prototype(sliding) decode(JSON)" }
76 testcase tc_slider() runs on Nothing {
77 // Encode 2 values and put them in the same buffer (one after the other)
78 var Data val1 := { 71, "hello" };
79 var Data val2 := { 19, "goodbye" };
80 var octetstring buffer := f_enc_data(val1) & f_enc_data(val2);
82 // Cut the buffer into 3 parts
83 var integer buf_len := lengthof(buffer);
84 var integer frag_len := buf_len / 3;
85 var octetstring part1 := substr(buffer, 0, frag_len);
86 var octetstring part2 := substr(buffer, frag_len, frag_len);
87 var octetstring part3 := substr(buffer, 2 * frag_len, buf_len - 2 * frag_len);
89 // Attempt to decode part 1 -> incomplete value
92 var integer ret_code := f_dec_data(buffer, ret_val);
94 setverdict(fail, "Unexpected return code ", ret_code, " while decoding part 1 (expected 2).");
98 // Attempt to decode the first 2 parts -> val1 will be extracted and removed from the buffer
99 buffer := part1 & part2;
100 ret_code := f_dec_data(buffer, ret_val);
102 setverdict(fail, "Unexpected return code ", ret_code, " while decoding parts 1 & 2 (expected 0).");
105 if (ret_val != val1) {
106 setverdict(fail, "Unexpected value ", ret_val, " while decoding parts 1 & 2 (expected ", val1, ").");
110 // Attempt to decode what remains of parts 1 and 2 -> incomplete value
111 ret_code := f_dec_data(buffer, ret_val);
112 if (ret_code != 2) { setverdict(fail, "Unexpected return code ", ret_code, " while decoding the remains (expected 2)."); }
114 // Append part 3 to our buffer and decode it -> val2 will be extracted and removed from the buffer (the buffer will be empty in the end)
115 buffer := buffer & part3;
116 ret_code := f_dec_data(buffer, ret_val);
118 setverdict(fail, "Unexpected return code ", ret_code, " while decoding the remains plus part 3 (expected 0).");
121 if (ret_val != val2) {
122 setverdict(fail, "Unexpected value ", ret_val, " while decoding the remains plus part 3 (expected ", val2, ").");
125 if (lengthof(buffer) != 0) { setverdict(fail, "The buffer is not empty after both values were extracted. Contains: ", buffer); }
131 execute(tc_slider());