Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / compileonly / styleGuide / MySample_module.ttcn
CommitLineData
970ed795 1/******************************************************************************
3abe9331 2 * Copyright (c) 2000-2015 Ericsson Telecom AB
970ed795
EL
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 ******************************************************************************/
8module MySample_module.objid{ itu_t(0) identified_organization(4) etsi(0)
9 identified_organization(127) ericsson(5) testing(0) /*<further nodes>*/}
10{
11
12//=========================================================================
13// Import Part
14//=========================================================================
15
16import from Another_module.objid{0 4 0 127 5 0 /*<further nodes>*/} all;
17
18import from MyASN1_module.objid{0 4 0 127 5 0 /*<further nodes>*/} language
19 "ASN.1:2002" all;
20
21external const ExtConsType c_ExtConstName;
22
23external function f_ExtFuncName (in InParType pl_formalPar1, out OutParType
24 pl_formalPar2, inout InoutParType pl_formalPar3, in template MyMessageType
25 pl_formalPar4) return MyExtReturnType
26
27//=========================================================================
28// Module parameters
29//=========================================================================
30
31modulepar
32{
33 integer tsp_MyIntegerModulePar1 := 1;
34 integer tspc_MyIntegerModulePar2;
35 float tspx_MyIUTMaxResponseTime := 1.0
36}
37
38//=========================================================================
39// Data Types
40//=========================================================================
41
42//Simple data types
43type integer MyIntegerType (0..255) with {variant "COMP(2scompl)"};
44type charstring MyCharType1 length(0..7);
45type charstring MyCharType2 length(0..infinity);
46type charstring MyCharType3 ("a".."z");
47type MyCharType3 MyCharType4 length(0..7);
48type integer MySimpleReturnType with {extension "done"};
49
50//Structured data types
51type record MyMessageType
52{
53 MyEnumType header,
54 MyRecordType data,
55 integer footer optional
56}
57
58type enumerated MyEnumType
59{
60 enumValue1 (101),
61 enumValue2 (102)
62} with
63{
64 variant "FIELDLENGTH(16)";
65 variant "COMP(signbit)"
66}
67
68type record MyRecordType
69{
70 integer field1 (0..255),
71 bitstring field2 length(8),
72 MySetOfIntegerType field3 optional,
73 MyCharType4 field4 optional
74}
75
76type set length(0..7) of integer MySetOfIntegerType;
77
78type record MyStructuredReturnType
79{
80 integer field1 (0..255),
81 boolean field2 optional
82} with
83{
84 extension "done"
85}
86
87//Address type
88type octetstring address;
89
90//=========================================================================
91// Signatures
92//=========================================================================
93
94signature s_MyProcedureSignature(
95 in InParType pl_inPar,
96 out OutParType pl_outPar,
97 inout InoutParType pl_inoutPar)
98return MySignReturnType
99exception( integer, boolean, MyExceptionType1, MyExceptionType2,
100 MyExceptionType3, MyExceptionType4)
101
102//=========================================================================
103//Port types
104//=========================================================================
105
106type port MyTestPortmsg_PT message
107{
108 in MyCharType4, MyIntegerType;
109 out MyCharType2, MyEnumType;
110 inout MyMessageType;
111} with
112{
113 extension "address"
114}
115
116type port MyTestPortproc_PT procedure
117{
118 inout s_MyProcedureSignature;
119} with
120{
121 extension "address"
122}
123
124type port MyCoordPortType_PT message
125{
126 inout charstring;
127} with
128{
129 extension "internal"
130}
131
132//=========================================================================
133//Component types
134//=========================================================================
135
136type component Dummy_CT {}
137
138type component MyMTC_CT
139{
140 const float c_MyPi := 3.1415;
141 var integer v_MyComponentVar1;
142 var integer v_MyComponentVar2 := 0;
143 timer T_MyComponentTimer;
144 port MyCoordPortType_PT COORD;
145}
146
147type component MyPTC_CT
148{
149 const integer c_LAPD_N201 := 3;
150 var charstring v_CoordMessage;
151
152 var MyMessageType v_MyMessage;
153 var address v_AddressVar := 'DEADBEEF'O;
154 timer T_MyComponentTimer := tspx_MyIUTMaxResponseTime;
155 port MyTestPortmsg_PT PORT1, PORT2;
156 port MyTestPortproc_PT PORT3;
157
158 port MyCoordPortType_PT COORD;
159}
160
161type component MySystem_SCT
162{
163 port MyTestPortmsg_PT PORT1, PORT2;
164 port MyTestPortproc_PT PORT3;
165
166}
167
168type MyPTC_CT MyAlias_SCT;
169
170//=========================================================================
171// Constants
172//=========================================================================
173
174const integer cg_MyInt := 5;
175
176const octetstring cg_3octets := 'FABABA'O;
177
178const MyMessageType cg_MyMessageType :=
179{
180 header := enumValue1,
181 data :=
182 {
183 field1 := 0,
184 field2 := '10001000'B,
185 field3 := {1,2,3,4,5},
186 field4 := omit
187 },
188 footer := omit
189}
190
191//=========================================================================
192// Templates
193//=========================================================================
194
195//Message templates
196template MyCharType4 t_MySimpleTemplate := "baba";
197
198template MyCharType4 tr_MySimpleTemplate := ("baba", "abba");
199
200template MyCharType4 tr_MySimpleTemplatePard(
201 charstring pl_charValue) := ("baba", "abba", pl_charValue);
202
203template MyRecordType tr_MyRecord :=
204{
205 field1 := (1,2,3),
206 field2 := ?,
207 field3 := {1,2,?},
208 field4 := t_MySimpleTemplate ifpresent
209};
210
211template MyRecordType t_MyRecordPard (
212 template integer pl_formalPar1,
213 template charstring pl_formalPar2) :=
214{
215 field1 := pl_formalPar1,
216 field2 := '10001000'B,
217 field3 := {1,2,3},
218 field4 := pl_formalPar2
219};
220
221template MyRecordType tr_MyRecordPard (
222 template integer pl_formalPar1,
223 template charstring pl_formalPar2)
224modifies t_MyRecordPard :=
225{
226 field3 := *
227};
228
229template MyMessageType t_MyMessage :=
230{
231 header := enumValue1,
232 data := t_MyRecordPard(1,"abba"),
233 footer := omit
234}
235
236template MyMessageType tr_MyMessagePard(
237 template MyRecordType pl_formalPar1,
238 integer pl_formalPar2) :=
239{
240 header := ?,
241 data := pl_formalPar1,
242 footer := pl_formalPar2
243}
244
245//Procedure templates
246template s_MyProcedureSignature t_MyProcedure :=
247{
248 pl_inPar := 1,
249 pl_outPar := ?,
250 pl_inoutPar := 'BABA'O
251}
252
253template s_MyProcedureSignature tr_MyProcedure :=
254{
255 pl_inPar := ?,
256 pl_outPar := ?,
257 pl_inoutPar := ?
258}
259
260template s_MyProcedureSignature t_MyProcedureReply :=
261{
262 pl_inPar := 1,
263 pl_outPar := 2,
264 pl_inoutPar := 'ABBA'O
265}
266
267//=========================================================================
268// Altsteps
269//=========================================================================
270
271altstep as_MyAltStep1()
272runs on MyPTC_CT
273{
274 [] T_MyComponentTimer.timeout
275 {
276 setverdict(fail);
277 }
278} // altstep as_MyAltStep1
279
280altstep as_MyAltStep2(
281 timer pl_timerPar)
282{
283 [] pl_timerPar.timeout
284 {
285 repeat;
286 }
287} // altstep as_MyAltStep2
288
289altstep as_MyAltStep3(
290 MyTestPortmsg_PT pl_portPar)
291{
292 [] pl_portPar.receive
293 {
294 // statements
295 stop
296 }
297} // altstep as_MyAltStep3
298
299//=========================================================================
300// Functions
301//=========================================================================
302
303function f_MyFunction(
304 in template InParType pl_formalPar1,
305 out OutParType pl_formalPar2,
306 inout InoutParType pl_formalPar3,
307 timer pl_timerFormalPar,
308 MyCoordPortType_PT pl_portFormalPar)
309{
310 //function body
311}
312
313function f_MyPTCFunction1(
314 in InParType pl_formalPar)
315runs on MyPTC_CT
316return MySimpleReturnType
317{
318 //local definitions
319 const integer cl_zero := 0;
320 var boolean flag := true;
321 var MyMessageType vl_MyMessage;
322 var Dummy_CT vl_MyCompReference;
323 var default vl_defaultReference1, vl_defaultReference2, vl_defaultReference3;
324 timer Tl_MyLocalTimer := 5.0;
325
326 vl_defaultReference1 := activate(as_MyAltStep1());
327 vl_defaultReference2 := activate(as_MyAltStep2(T_MyComponentTimer));
328 vl_defaultReference3 := activate(as_MyAltStep3(PORT2));
329
330 Tl_MyLocalTimer.start;
331
332 //example alt statement
333 alt
334 {
335 [] // Entire heading fit into one line
336 PORT1.receive(MyMessageType:?) from v_AddressVar -> value vl_MyMessage
337 {
338 // 1st statement body
339 }
340 [] PORT1.trigger(t_MyMessage)
341 -> value v_MyMessage sender v_AddressVar
342 {
343 // 2nd statement body
344 }
345 [booleanCondition] // More complicated alternative
346 PORT2.receive(tr_MyMessagePard(
347 tr_MyRecordPard(
348 ?,
349 tr_MySimpleTemplatePard("baab")),
350 c_LAPD_N201))
351 from v_AddressVar
352 -> value v_MyMessage
353 {
354 // 3rd statement body
355 }
356 [] COORD.receive(charstring:?)
357 -> value v_CoordMessage sender vl_MyCompReference
358 {
359 // 4th statement body
360 }
361 } // alt
362
363 //simple if example
364 if (Tl_MyLocalTimer.running){ Tl_MyLocalTimer.stop};
365
366 // if-else and do-while example
367 do
368 {
369 PORT1.send (t_MyMessage) to v_AddressVar;
370 PORT2.receive(MyMessageType:?) -> value vl_MyMessage;
371 if (match(vl_MyMessage,t_MyMessage))
372 {
373 // statements
374 setverdict(pass);
375 flag := false;
376 }
377 else
378 {
379 log ("MyFunc(W):IUT is not transparent")
380 }
381 } while (flag)
382
383 //for loop example
384 for(var integer i := 0; i<8; i := i+1)
385 {
386 PORT1.send(t_MyMessage);
387 PORT2.receive(t_MyMessage);
388 };
389
390 // label-goto example
391 COORD.receive(charstring:"START");
392
393label sendNextMessage;
394 PORT1.send (t_MyMessage);
395 PORT2.receive (t_MyMessage);
396 goto sendNextMessage;
397
398 // return example
399 return 0;
400} // function f_MyPTCFunction1
401
402function f_MyPTCFunction2()
403runs on MyPTC_CT
404{
405 //local definitions
406 var MySignReturnType vl_ReturnValue;
407 var InParType vl_inParValue;
408 var OutParType vl_outParValue;
409 var InoutParType vl_inoutParValue;
410
411 //infinite loop example
412 while(true)
413 {
414 //procedure based communication example
415 //handling outgoing blocking call
416 PORT3.call(t_MyProcedure, tspx_MyIUTMaxResponseTime) to v_AddressVar
417 {
418 [] PORT3.getreply(tr_MyProcedure)
419 from v_AddressVar
420 -> value vl_ReturnValue param(vl_outParValue,vl_inoutParValue)
421 sender v_AddressVar
422 {
423 // statements
424 }
425 [] PORT3.catch(s_MyProcedureSignature, MyExceptionType1:?)
426 {
427 // statements
428 }
429 [] PORT3.catch(timeout)
430 {
431 // statements
432 }
433 } // call
434
435 //handling incoming blocking call
436 PORT3.getcall(tr_MyProcedure)
437 from v_AddressVar
438 -> param(vl_inParValue, vl_inoutParValue) sender v_AddressVar;
439 if (booleanCondition)
440 {
441 PORT3.reply(t_MyProcedureReply value vl_ReturnValue) to v_AddressVar;
442 }
443 else
444 {
445 PORT3.raise(s_MyProcedureSignature, MyExceptionType1:cg_errorCodeOne)
446 to v_AddressVar;
447 } } // while
448} // function f_MyPTCFunction2
449
450//=========================================================================
451// Testcases
452//=========================================================================
453
454testcase tc_ReceiveACK_Inopportune(
455 inout InoutParType pl_formalPar)
456runs on MyMTC_CT
457system MySystem_SCT
458{
459 //local definitions
460 const InParType cl_zero := 0;
461 var OutParType vl_OutParVar;
462 var MyPTC_CT vl_MyPTC;
463 var Dummy_CT vl_MyAlternPTCReference;
464 timer Tl_GUARD := 10.0;
465
466 // Test configuration setup example
467 vl_MyPTC := MyPTC_CT.create;
468 connect(vl_MyPTC:COORD, mtc:COORD);
469 map(vl_MyPTC:PORT1, system:PORT1);
470 map(vl_MyPTC:PORT2, system:PORT2);
471 map(vl_MyPTC:PORT3, system:PORT3);
472 vl_MyPTC.start(f_MyPTCFunction1(cl_zero));
473
474 // Single-line function call example
475 f_MyFunction(cl_zero, vl_OutParVar, pl_formalPar, Tl_GUARD, COORD);
476
477 // Handling termination of a PTC with return value
478 alt
479 {
480 [] vl_MyPTC.done (MySimpleReturnType:?) {setverdict(pass)}
481 [] vl_MyPTC.done {setverdict (inconc)}
482 }
483} // testcase tc_ReceiveACK_Inopportune
484
485//=========================================================================
486// Control
487//=========================================================================
488
489control
490{
491//local definitions
492var InoutParType vl_CR := c_nullCR;
493
494if (execute (tc_MyPreviousTestCase(vl_CR)) != error)
495{
496 execute(tc_ReceiveACK_Inopportune(vl_CR))
497}
498else
499{
500 execute(tc_RestoreSUT())
501}
502} // control
503} // module
504with {encode "RAW"}
This page took 0.068839 seconds and 5 git commands to generate.