Last sync 2016.04.01
[deliverable/titan.core.git] / regression_test / slider / dual2.ttcn
1 /******************************************************************************
2 * Copyright (c) 2000-2016 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 * Contributors:
9 * Balasko, Jeno
10 * Raduly, Csaba
11 *
12 ******************************************************************************/
13 module dual2
14 {
15
16 /*** *** *** *** PDU *** *** *** ***/
17 type record PDU1 {
18 charstring s
19 }
20 with { variant "" }
21
22 type record PDU2 {
23 charstring s
24 }
25 with { variant (s) "FIELDLENGTH(8)" }
26
27 /*** *** *** *** Ports *** *** *** ***/
28 type port UNDER message {
29 inout octetstring
30 }
31 with { extension "provider" }
32
33 type port SENDER message {
34 out PDU1;
35 }
36 with { extension "user UNDER
37 out(PDU1 -> octetstring : function(p1o))
38 in (octetstring -> - : discard)
39 " }
40
41 type port RECEIVER message {
42 in PDU2
43 }
44 with { extension "user UNDER
45 //out(PDU1 -> - : discard)
46 in (octetstring -> PDU2 : function(op2sl))
47 " }
48
49 /*** *** *** *** mapper functions *** *** *** ***/
50
51 // A "prototype(fast)" implemented in TTCN
52 function p1o(in PDU1 p, out octetstring o) {
53 o:= char2oct(p.s);
54 }
55 with { extension "prototype(fast)" }
56
57 function op2(in octetstring o, out PDU2 p) {
58 p.s := oct2char(o);
59 }
60 with { extension "prototype(fast)" }
61
62 // A "prototype(sliding)" implemented in TTCN
63 function op2sl(inout octetstring o, out PDU2 p) return integer {
64 //log(">>> op2sl ", o);
65 var integer lo := lengthof(o); // octets, 'ABCD' = 2
66 if (lo < 8) {
67 //log("<<< return 2: not enough:", lo)
68 return 2;
69 }
70 //else { log("=== length is ", lo) }
71 p.s := oct2char(substr(o, 0, 8)); // "decode" the PDU
72 o := substr(o, 8, lo-8); // return the rest
73 //log(">>> res=", p.s);
74 //log(">>> rem=", o);
75 //log(">>> return 0");
76 return 0;
77 }
78 with { extension "prototype(sliding)" }
79
80 /*** *** *** *** Components *** *** *** ***/
81 type component D2 {
82 port SENDER stringport;
83 port RECEIVER reverseport;
84 port SENDER another_stringport;
85 }
86
87 type component SYS {
88 //port PT1 SYSTEM_PORT2;
89 }
90
91 /*** *** *** *** Testcases *** *** *** ***/
92
93 // Intrernal communication with mapped ports
94 testcase intern() runs on D2
95 {
96 connect (mtc:stringport, mtc:reverseport);
97 var PDU1 cr := { "howdy!" }
98 stringport.send(cr);
99 alt {
100 [] reverseport.receive /* anything */ { setverdict(fail, "premature receive"); }
101 [else] { setverdict(pass); } // less than eight bytes: shouldn't receive anything
102 }
103
104 stringport.send(PDU1 : { "??" }) // the missing two bytes
105 alt {
106 [] reverseport.receive(PDU2 : {"howdy!??"}) { setverdict(pass); }
107 [] reverseport.receive { setverdict(fail, "wrong receive"); }
108 [else] { setverdict(fail, "no receive"); }
109 }
110 disconnect(mtc:stringport, mtc:reverseport);
111 }
112
113 type set PDU3 {
114 //charstring s,
115 octetstring s, // EXTENSION_BIT not implemented for charstring
116 integer i
117 }
118 with { variant ""; /*FIELDLENGTH(8)*/
119 variant (s) "EXTENSION_BIT(yes)";
120 variant (i) "FIELDLENGTH(24)"; // bits
121 }
122
123 external function enc3(in PDU3 p) return octetstring
124 with { extension "prototype(convert) encode(RAW)" }
125
126 external function dec3(in octetstring o) return PDU3
127 with { extension "prototype(convert) decode(RAW)" }
128
129 external function dec3sl(inout octetstring o, out PDU3 p) return integer
130 with { extension "prototype(sliding) decode(RAW) errorbehavior(INVAL_MSG:WARNING,INCOMPL_MSG:WARNING)" }
131
132 // Try to elicit various return values from the decoder function
133 testcase errored() runs on D2 system D2
134 {
135 connect(mtc:stringport, mtc:reverseport);
136 var PDU1 p1 := { "yay....." }
137 stringport.send(p1);
138
139 alt {
140 [] reverseport.receive(PDU2 : ?) { setverdict(pass, "got PDU2"); }
141 [else] { setverdict(fail, "no receive at ", __LINE__); }
142 }
143
144 var octetstring three := char2oct("three!!!");
145 var PDU3 p0 := { s := three, i := 3 };
146 var octetstring o := enc3(p0);
147 var octetstring incompl;
148 var integer retval;
149 {
150 var PDU3 p;
151 log("=== === === === encoded as ", o);
152 incompl := '74687265652121A11B0000'O; // "three!!!"
153 //p := dec3(incompl);
154 retval := dec3sl(incompl, p);
155
156 if (retval == 0) { setverdict(pass) }
157 else { setverdict(fail, "nonzero at ", __LINE__); }
158 }
159
160 {
161 var PDU3 p;
162 log("___ string only ___");
163 incompl := '74687265652121A1'O;
164 retval := dec3sl(incompl, p);
165
166 if (retval == 2) { setverdict(pass) }
167 else { setverdict(fail, "not 2 at ", __LINE__); }
168 }
169
170 {
171 var PDU3 p;
172 log("___ plus nine ___");
173 incompl := hex2oct('74687265652121A130'H);
174 retval := dec3sl(incompl, p);
175
176 if (retval == 1) { setverdict(pass) }
177 else { setverdict(fail, "not 1 at ", __LINE__); }
178 }
179 disconnect(mtc:stringport, mtc:reverseport);
180 }
181
182 // Test sliding decoding with multiple connections
183 testcase two_conn() runs on D2
184 {
185 connect(mtc:stringport, mtc:reverseport);
186 connect(mtc:another_stringport, mtc:reverseport);
187
188 var PDU1 p1a := { "ABCD" }, p1e := { "EFGH" }
189
190 stringport.send(p1a); // first half
191 alt {
192 [] reverseport.receive /* anything */{
193 setverdict(fail, "It wasn't supposed to receive anything yet");
194 }
195 [else] /* nothing received */ { setverdict(pass); }
196 }
197
198 another_stringport.send(p1a); // send first half on another connection
199 alt {
200 [] reverseport.receive /* anything */{
201 // If the different connections were not properly separated,
202 // a message would appear at this point (eight characters => one message)
203 setverdict(fail, "It STILL wasn't supposed to receive anything yet");
204 }
205 [else] /* nothing received */ { setverdict(pass); }
206 }
207
208 stringport.send(p1e); // send second half on the first connection
209 alt {
210 [] reverseport.receive( PDU2 : {"ABCDEFGH"} ) { setverdict(pass); }
211 [else] { setverdict(fail, "no receive"); }
212 }
213
214 another_stringport.send(p1e); // send second half on the second connection
215 alt {
216 [] reverseport.receive( PDU2 : {"ABCDEFGH"} ) { setverdict(pass); }
217 [else] { setverdict(fail, "no receive"); }
218 }
219
220 disconnect(mtc:stringport, mtc:reverseport);
221 disconnect(mtc:another_stringport, mtc:reverseport);
222 }
223
224 control {
225 execute(intern());
226 execute(errored());
227 execute(two_conn());
228 }
229
230 } // end of module
231 with {
232 encode "RAW"
233 }
This page took 0.046309 seconds and 5 git commands to generate.