Sync with 5.3.0
[deliverable/titan.core.git] / regression_test / all_from / all_from_with_functions.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 all_from_with_functions {
9
10 //for TR: HR91302 - compiler core dump if function called in "all from"
11
12 external function f_ext(in template RoI r) return template RoI;
13
14 type record of integer RoI with { encode "JSON" };
15 type set of integer SoI;
16
17 type record Rec {
18 integer i,
19 charstring s
20 }
21 type record of Rec RoRec;
22
23 function f_dummy(in template RoI r) return template RoI
24 {
25 return r;
26 }
27
28 function f_dummy2(in template RoI r, in template RoI p) return template RoI
29 {
30 return p;
31 }
32
33 function f_set(in template SoI s) return template SoI
34 {
35 return s;
36 }
37
38 function f_rec(in template RoRec tr) return template RoRec
39 {
40 return tr;
41 }
42
43 type port PT_Empty message
44 {
45 inout integer;
46 } with {extension "internal"}
47
48 type component CT_Empty {
49 port PT_Empty pt;
50 }
51
52 function square(in integer i) return integer {
53 return i * i;
54 }
55
56 template RoI t_roi(integer i) := { 1, 2, 3, i };
57 template RoI t_roi2(integer i) := { 1, 2, 3, square(i) }
58
59 testcase tc_all_from_with_functions() runs on CT_Empty {
60 var template RoI t1 := { permutation ( all from f_dummy2( {1, 2}, {3, 4} ) ) };
61 var template RoI t2 := f_dummy2( { 1, 2}, {3, 4} );
62 var template RoI t3 := { permutation (all from t2) };
63 var template RoI t4 := { permutation ( all from f_ext( {1, 2} ) ) };
64 var template integer t5 := (1, 2, all from f_dummy( {1, 2, (6..9)} ), 10);
65 var template integer t6 := complement (1, 2, all from f_dummy( {1, 2, (6..9)} ), 10);
66 var template SoI t7 := subset (1, 2, all from f_dummy( {3, 4} ), 5) length (2..3);
67 var template SoI t8 := superset (1, 2, all from f_dummy( {3, 4} ), 5) length (6..8);
68 var template integer t9 := (1, 2, all from f_set( {3, 4} ), 6);
69 var template SoI t10 := { t9, ( all from f_set( { (20..30) } ) ) };
70 var template Rec t11 := ( {10, "ten"}, all from f_rec( { {1, "one"}, {2, "two"}, {3, "three"} } ) );
71 var template integer t12 := ( all from t_roi(6) );
72 var template integer t13 := ( all from t_roi2(4) );
73
74 //log("t1=", t1);
75 //log("t2=", t2);
76 //log("t3=", t3);
77 //log("t4=", t4);
78 //log("t5=", t5);
79 //log("t6=", t6);
80 //log("t7=", t7);
81 //log("t8=", t8);
82 //log("t9=", t9);
83 //log("t10=", t10);
84 //log("t11=", t11);
85 //log("t12=", t12);
86 //log("t13=", t13);
87
88 if (log2str(t1) == "{ permutation(3, 4) }" and log2str(t2) == "{ 3, 4 }" and
89 log2str(t3) == "{ permutation(3, 4) }" and log2str(t4) == "{ permutation(1, 2) }" and
90 log2str(t5) == "(1, 2, 1, 2, (6 .. 9), 10)" and
91 log2str(t6) == "complement (1, 2, 1, 2, (6 .. 9), 10)" and
92 log2str(t7) == "subset(1, 2, 3, 4, 5) length (2 .. 3)" and
93 log2str(t8) == "superset(1, 2, 3, 4, 5) length (6 .. 8)" and
94 log2str(t9) == "(1, 2, 3, 4, 6)" and log2str(t10) == "{ (1, 2, 3, 4, 6), ((20 .. 30)) }" and
95 log2str(t11) == "({ i := 10, s := \"ten\" }, { i := 1, s := \"one\" }, " &
96 "{ i := 2, s := \"two\" }, { i := 3, s := \"three\" })" and
97 log2str(t12) == "(1, 2, 3, 6)" and log2str(t13) == "(1, 2, 3, 16)")
98 { setverdict(pass) }
99 else { setverdict(fail) }
100 }
101
102 // all from with function parameters
103 function f_all_from_params(in RoI p_in, inout RoI p_inout,
104 in template RoI pt_in, inout template RoI pt_inout)
105 runs on CT_Empty
106 return template integer {
107 return (1, 2, all from p_in, all from p_inout, all from pt_in, all from pt_inout);
108 }
109
110 testcase tc_all_from_func_params() runs on CT_Empty {
111 const RoI c_twenties := { 20, 21, 22 };
112 var RoI v_thirties := { 30, 31, 32, 33 };
113 template RoI t_fifties := { 50, 56, 59 };
114 var template RoI vt_sixties := { 63, 64, 66, 67 };
115
116 var template integer vt_res := f_all_from_params(c_twenties, v_thirties, t_fifties, vt_sixties);
117 const charstring c_res_log := "(1, 2, 20, 21, 22, 30, 31, 32, 33, 50, 56, 59, 63, 64, 66, 67)";
118 if (log2str(vt_res) == c_res_log) { setverdict(pass); }
119 else { setverdict(fail, "Expected: ", c_res_log, ", got: ", vt_res); }
120 }
121
122 function f_non_templ(in RoI x) return RoI
123 {
124 return x;
125 }
126
127 external function f_dec_roi(in octetstring os) return RoI
128 with { extension "prototype(convert) decode(JSON)" }
129
130 // all from used on regular (non-template) functions
131 testcase tc_all_from_with_functions2() runs on CT_Empty
132 {
133 var template RoI vt_func_roi := { permutation ( all from f_non_templ( { 1, 4, 7, 10 } ) ) };
134 var template integer vt_func_int := ( 0, 1, all from f_non_templ( { 3, 6, 9 } ) );
135
136 var octetstring v_enc := char2oct("[ 4, 2, 10, 100 ]");
137 var template RoI vt_ext_func_roi := { permutation ( all from f_dec_roi(v_enc) ) };
138 var template integer vt_ext_func_int := ( 0, 1, all from f_dec_roi(v_enc) );
139
140 var charstring v_res_log := "{ permutation(1, 4, 7, 10) }";
141 if (log2str(vt_func_roi) != v_res_log) {
142 setverdict(fail, "Expected: ", v_res_log, ", got: ", vt_func_roi);
143 }
144
145 v_res_log := "(0, 1, 3, 6, 9)";
146 if (log2str(vt_func_int) != v_res_log) {
147 setverdict(fail, "Expected: ", v_res_log, ", got: ", vt_func_int);
148 }
149
150 v_res_log := "{ permutation(4, 2, 10, 100) }";
151 if (log2str(vt_ext_func_roi) != v_res_log) {
152 setverdict(fail, "Expected: ", v_res_log, ", got: ", vt_ext_func_roi);
153 }
154
155 v_res_log := "(0, 1, 4, 2, 10, 100)";
156 if (log2str(vt_ext_func_int) != v_res_log) {
157 setverdict(fail, "Expected: ", v_res_log, ", got: ", vt_ext_func_int);
158 }
159
160 setverdict(pass);
161 }
162
163
164 control {
165 execute(tc_all_from_with_functions());
166 execute(tc_all_from_func_params());
167 execute(tc_all_from_with_functions2());
168 }
169
170 }
This page took 0.03628 seconds and 5 git commands to generate.