source: trunk/t3q-examples/CodeFormatting/Generic/generic.ttcn3 @ 12

Last change on this file since 12 was 4, checked in by phdmakk, 15 years ago
File size: 5.2 KB
Line 
1module generic {
2       
3
4//module parameters
5modulepar boolean mp_boolean := true;
6modulepar { integer mp_int1, mp_int2 := 2; integer mp_int3 := 3;}
7
8
9//full function body with multiple parameters, including passing modes, runs on clause and return value
10function f_sample2 (
11  template R3Msg p_radiusAccntReq,
12  out template R3Msg p_radiusAccntRsp )
13runs on R3Comp
14return FncRetCode {
15  var FncRetCode v_ret := e_success;
16
17  alt {
18    [] r3Port.receive ( m_r3MonitorInd ( p_radiusAccntReq ) ) {
19      v_ret := e_success;
20    }
21    [] r3Port.receive ( m_r3MonitorInd (
22                          e_RadiusAccountingRequest,
23                          p_radiusAccntReq ) ) {
24      v_ret := e_success;
25    }
26    [] r3Port.receive ( m_r3MonitorInd (
27                          e_RadiusAccountingRequest,
28                          m_radiusAccntReq_any ) ) {
29      return e_error;
30    }
31  }
32  return v_ret;
33}   
34//function skeleton with a single parameter, including a passing mode, with a runs on clause
35function f_sample1 (in template R3Msg p_radiusAccntReq)
36        runs on R3Comp {
37}
38
39//function skeleton with a single parameter, with a runs on clause
40function f_sample11 (template R3Msg p_radiusAccntReq)
41        runs on R3Comp {
42}
43
44//function skeleton without parameters, with a return value
45function f_sample ()
46        return r {
47}
48
49//full function body with multiple parameters, including passing modes, no further clauses
50function f_sample21(
51  template R3Msg p_radiusAccntReq,
52  out template R3Msg p_radiusAccntRsp ) {
53
54  var integer v_var1 := 0;
55  var integer v_var2 := 10;
56 
57  while (v_var1 < v_var2){
58        v_var1:=v_var1+1;
59  }
60 
61}
62
63
64//altstep skeleton without parameters
65altstep a_sample ()
66        runs on R3Comp {
67}
68
69//altstep with full body, multiple parameters, with passing modes and a runs on clause
70
71altstep a_sample2 ( template R3Msg p_radiusAccntReq, inout template R3Msg p_radiusAccntRsp )
72        runs on R3Comp {
73
74[] r3Port.receive ( m_r3MonitorInd ( p_radiusAccntReq ) ) {
75      v_ret := e_success;
76    }
77    [] r3Port.receive ( m_r3MonitorInd (
78                          e_RadiusAccountingRequest,
79                          p_radiusAccntReq ) ) {
80      v_ret := e_success;
81    }
82 }
83
84
85//altstep skeleton with a single parameter
86altstep a_sample1 (template R3Msg p_radiusAccntReq) {
87}
88
89//sample test case with full body, multiple parameters, with modifiers, runs on and system clauses
90testcase tc_sample2 (
91  template R3Msg p_radiusAccntReq,
92  out template R3Msg p_radiusAccntRsp )
93runs on R3Comp
94system R3System {
95  var FncRetCode v_ret := e_success;
96
97  alt {
98    [] r3Port.receive ( m_r3MonitorInd ( p_radiusAccntReq ) ) {
99      v_ret := e_success;
100    }
101    [] r3Port.receive ( m_r3MonitorInd (
102                          e_RadiusAccountingRequest,
103                          p_radiusAccntReq ) ) {
104      v_ret := e_success;
105    }
106    [] r3Port.receive ( m_r3MonitorInd (
107                          e_RadiusAccountingRequest,
108                          m_radiusAccntReq_any ) ) {
109    }
110    [] a_sample2 (m_r3MonitorInd,m_r3MonitorInd);
111    [] a_sample1 (m_r3MonitorInd);
112    [] a_sample0 ();
113  }
114
115}   
116//sample test case skeleton with a single parameter, including a passing mode, with a runs on clause
117testcase tc_sample1 (in template R3Msg p_radiusAccntReq)
118        runs on R3Comp {
119}
120
121//test tcase skeleton with a single parameter, with a runs on clause and a system clause
122testcase tc_sample11 (template R3Msg p_radiusAccntReq)
123        runs on R3Comp system R3System {
124        f_sample();
125        f_sample1(p_radiusAccntReq);
126        f_sample2(p_radiusAccntReq,p_radiusAccntRsp)
127}
128
129//test case skeleton without parameters, with a runs on clause
130testcase tc_sample ()
131        runs on R3Comp {
132}
133
134        //template with a single parameter
135        template type1 template1 (integer i) :={
136                int1 :=i,
137                int2 :=2
138        }
139
140        template type1 template11 (integer i) modifies template1 :={
141                int1 :=i,
142                int2 :=4
143        }
144
145
146
147        //template with multiple parameters
148        template type1 template2 (integer i1, integer i2) :={
149                int1 :=i1,
150                int2 :=i2
151        }
152
153       
154        signature s_lookup () return charstring exception (e_NotFound);
155
156        signature s_accept () return charstring exception (e_NotFound);
157
158       
159        signature s_lookup1 (in charstring key) return charstring exception (e_NotFound);
160       
161        signature s_lookup2 (in charstring key, in charstring id) return charstring exception (e_NotFound);
162       
163        signature s_lookup3 (in charstring key, in charstring id, inout integer state) return charstring exception (e_NotFound);
164       
165        //not clear if legal, or useful...
166        //parser seems to fail
167        //it is legal
168        type record type2 (integer i1, integer i2) {
169                integer range (i1 .. i2)
170        }
171
172        type integer range2 (1 .. 10);
173
174        //this should also be legal although maybe not in the current version
175        //the above is an indirect version
176        //type integer intRange (integer min, integer max ) (min .. max);
177        const type2(1,10) c_range := 3;
178       
179        //type integer binary (0,1);
180        //type integer octary (0 .. 7);
181
182        //illegal
183        //type record type3 (integer i1, integer i2) {
184        //      i1 binary,
185        //      i2 octary
186        //}
187       
188        testcase tc_sample_procedurebased() runs on sampleComponent system systemComponent{
189                port1.call(s_lookup:{x}) {
190                        []port1.getreply(s_accept:{y}) {
191                       
192                        }
193                }
194        }
195       
196        control{
197                execute(tc_sample1(template_sample1));
198                execute(tc_sample2(template_sample1,template_sample2));
199                execute(tc_sample());
200        }
201       
202
203       
204}
Note: See TracBrowser for help on using the repository browser.