Sync with 5.1.0
[deliverable/titan.core.git] / regression_test / slider / slider.ttcn
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 slider {
9
10 type component Nothing {};
11
12 group rawr {
13
14 type union E {
15 record {
16 integer i
17 } a,
18 record of universal charstring strs
19 }
20 with {
21 variant "" // to force RAW encoding
22 }
23
24 external function enc_r(in E e, out octetstring o)
25 with { extension "prototype(fast) encode(RAW)" }
26
27 external function dec_r(inout octetstring o, out E e) return integer
28 with { extension "prototype(sliding) decode(RAW)" }
29
30 }
31 with {
32 encode "RAW";
33 }
34
35 /* * * * * * * * * * */
36
37 group text {
38
39 type union Et {
40 record {
41 integer i
42 } a,
43 record of universal charstring strs
44 }
45 with {
46 variant "BEGIN('Header: ')"
47 variant "SEPARATOR(';')"
48 //variant "BEGIN(1)" // to force TEXT encoding
49 }
50
51 external function enc_t(in Et e, out charstring o)
52 with { extension "prototype(fast) encode(TEXT)" }
53
54 external function dec_t(inout charstring o, out Et e) return integer
55 with { extension "prototype(sliding) decode(TEXT)" }
56
57 }
58 with {
59 encode "TEXT";
60 }
61
62 /* * * * * * * * * * */
63 type record Data {
64 integer int,
65 universal charstring str
66 } with {
67 encode "JSON"
68 }
69
70 external function f_enc_data(in Data d) return octetstring
71 with { extension "prototype(convert) encode(JSON)" }
72
73 external function f_dec_data(inout octetstring x, out Data d) return integer
74 with { extension "prototype(sliding) decode(JSON)" }
75
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);
81
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);
88
89 // Attempt to decode part 1 -> incomplete value
90 buffer := part1;
91 var Data ret_val;
92 var integer ret_code := f_dec_data(buffer, ret_val);
93 if (ret_code != 2) {
94 setverdict(fail, "Unexpected return code ", ret_code, " while decoding part 1 (expected 2).");
95 mtc.stop;
96 }
97
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);
101 if (ret_code != 0) {
102 setverdict(fail, "Unexpected return code ", ret_code, " while decoding parts 1 & 2 (expected 0).");
103 mtc.stop;
104 }
105 if (ret_val != val1) {
106 setverdict(fail, "Unexpected value ", ret_val, " while decoding parts 1 & 2 (expected ", val1, ").");
107 mtc.stop;
108 }
109
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)."); }
113
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);
117 if (ret_code != 0) {
118 setverdict(fail, "Unexpected return code ", ret_code, " while decoding the remains plus part 3 (expected 0).");
119 mtc.stop;
120 }
121 if (ret_val != val2) {
122 setverdict(fail, "Unexpected value ", ret_val, " while decoding the remains plus part 3 (expected ", val2, ").");
123 mtc.stop;
124 }
125 if (lengthof(buffer) != 0) { setverdict(fail, "The buffer is not empty after both values were extracted. Contains: ", buffer); }
126
127 setverdict(pass);
128 }
129
130 control {
131 execute(tc_slider());
132 }
133
134 }
This page took 0.043909 seconds and 5 git commands to generate.