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