Sync with 5.1.0
[deliverable/titan.core.git] / regression_test / implicitMsgEncoding / TimplicitEnc.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 TimplicitEnc
9 {
10 type record MyPDU {
11 integer i,
12 float f
13 } with { encode "RAW"; variant "" }
14
15 type record Errorneous_PDU {
16 integer fi optional,
17 octetstring fo optional
18 }
19 with {
20 encode "RAW";
21 variant (fo) "PRESENCE(fi=1)"
22 };
23
24
25 type port PCOType message
26 {
27 inout octetstring;
28 inout charstring;
29 }
30 with
31 {
32 extension "provider"
33 }
34
35 type boolean Bool with { encode "TEXT" variant "TEXT_CODING(length=5)" }
36
37 function f_encode_int(in integer i, out charstring cs)
38 {
39 cs := int2str(i);
40 }
41 with
42 {
43 extension "prototype(fast)"
44 }
45
46 function f_encode_float(in float f) return charstring
47 {
48 return float2str(f);
49 }
50 with
51 {
52 extension "prototype(convert)"
53 }
54
55 type port UserPort message
56 {
57 inout charstring;
58 inout MyPDU;
59 out integer, boolean, float, bitstring, octetstring;
60 }
61 with
62 {
63 extension "user PCOType
64 in ( charstring -> charstring : simple;
65 octetstring -> MyPDU : decode(RAW) errorbehavior(ALL:WARNING),
66 - : discard )
67 out ( charstring -> charstring : simple;
68 integer -> charstring : function(f_encode_int);
69 Bool -> charstring : encode(TEXT);
70 float -> charstring : function(f_encode_float);
71 octetstring -> -:discard;
72 MyPDU -> octetstring : encode(RAW);
73 bitstring -> charstring : function(f_encode_bitstr)
74 )"
75 }
76
77 type port UserPort2 message
78 {
79 inout charstring;
80 out Errorneous_PDU, octetstring;
81 }
82 with
83 {
84 extension "user PCOType
85 in ( charstring -> charstring : simple;
86 octetstring -> - : discard )
87 out ( charstring -> charstring : simple;
88 octetstring -> - : discard;
89 Errorneous_PDU -> octetstring : encode(RAW) errorbehavior (ALL:WARNING)
90 )"
91 }
92
93
94 function f_encode_bitstr(in bitstring bs := ''B) return charstring
95 {
96 return "Bit string = " & bit2str(bs);
97 }
98 with
99 {
100 extension "prototype(convert)"
101 }
102
103 type component MTCType
104 {
105 port PCOType MyPCO;
106 }
107
108 type component MyComp extends MTCType
109 {
110 port UserPort P;
111 }
112
113 type component MyComp2 extends MTCType
114 {
115 port UserPort2 P2;
116 }
117
118 external function decode_MyPDU(in octetstring os, out MyPDU pdu) return integer
119 with {
120 extension "prototype(backtrack)"
121 extension "decode(RAW)"
122 extension "errorbehavior(ALL:WARNING)"
123 }
124
125
126 function f_PReceiveCharstring(charstring p_message, float p_time) runs on MyComp
127 {
128 timer t := p_time;
129
130 t.start;
131
132 alt
133 {
134 [] P.receive(p_message)
135 {
136 t.stop;
137 setverdict(pass);
138 }
139 [] P.receive
140 {
141 t.stop;
142 setverdict(fail);
143 }
144 [] t.timeout
145 {
146 setverdict(fail);
147 }
148 }
149 }
150
151 function f_PReceiveNone(float p_time) runs on MyComp
152 {
153 timer t := p_time;
154 t.start;
155
156 alt{
157 [] P.receive
158 {
159 t.stop;
160 setverdict(fail);
161 }
162 [] t.timeout
163 {
164 setverdict(pass);
165 }
166 }
167 }
168
169 testcase ImplicitMsgEnc1() runs on MyComp system MTCType
170 {
171 var MyPDU mypdu := {i := 10, f := 3.14};
172
173 map(mtc:P, system:MyPCO);
174
175 //the TLV of first octetstring has error -> the
176 //octetstring needs to be discarded.
177 //see user_map for more details
178 f_PReceiveNone(1.0);
179
180 P.send("Hello, world!");
181 f_PReceiveCharstring("Hello, world!", 1.0);
182 P.send(123);
183 f_PReceiveCharstring("123", 1.0);
184 P.send(false);
185 f_PReceiveCharstring("false", 1.0);
186 P.send(true);
187 f_PReceiveCharstring("true", 1.0);
188 P.send(3.14);
189 f_PReceiveCharstring("3.140000", 1.0);
190 P.send(mypdu);
191 P.receive(?) -> value mypdu;
192
193
194
195 //octetstring to send must be discarded
196 P.send('ABCDEF'O);
197 f_PReceiveNone(1.0);
198
199 P.send('1010101010'B);
200 f_PReceiveCharstring("Bit string = 1010101010", 1.0);
201
202 // f_PReceiveCharstring("Hello, TTCN-3!", 4.0);
203
204 unmap(mtc:P, system:MyPCO);
205 }
206
207 testcase ImplicitMsgEnc2() runs on MyComp2 system MTCType
208 {
209 var Errorneous_PDU myErrPDU := {fi := omit, fo := 'AA'O};
210 timer t := 1.0;
211
212 map(mtc:P2, system:MyPCO);
213
214 P2.send(myErrPDU);
215 t.start;
216 alt{
217 [] P2.receive {t.stop; setverdict(fail);}
218 [] t.timeout {setverdict(pass)}
219 }
220
221 unmap(mtc:P2, system:MyPCO);
222 }
223
224 control
225 {
226 execute(ImplicitMsgEnc1());
227 execute(ImplicitMsgEnc2());
228 }
229 }
This page took 0.034985 seconds and 5 git commands to generate.