a38c6d4c |
1 | /****************************************************************************** |
d44e3c4f |
2 | * Copyright (c) 2000-2016 Ericsson Telecom AB |
a38c6d4c |
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 |
d44e3c4f |
7 | * |
8 | * Contributors: |
9 | * Balasko, Jeno |
10 | * Baranyi, Botond |
11 | * |
a38c6d4c |
12 | ******************************************************************************/ |
13 | |
14 | // subtyping and the 'all from' clause |
15 | module all_from_subtype { |
16 | |
17 | import from types all; |
18 | import from functions all; |
19 | |
20 | /* * * * integer * * * */ |
21 | template RoI t_RoI1 := { 1, 2, (6..9) }; |
22 | template RoI t_RoI2 := { 1, ?, 3 }; |
23 | const RoI c_RoI := { 20, 21, 22 }; |
24 | |
25 | template PosInt t_posint1 := (0, all from t_RoI1); |
26 | template PosInt t_posint1_exp := (0, 1, 2, (6..9)); |
27 | |
28 | template PosInt t_posint2 := (all from c_RoI, 50, 100); |
29 | template PosInt t_posint2_exp := (20, 21, 22, 50, 100); |
30 | |
31 | template PosInt t_posint3 := (10, all from c_RoI, 30, all from t_RoI1); |
32 | template PosInt t_posint3_exp := (10, 20, 21, 22, 30, 1, 2, (6..9)); |
33 | |
34 | template ShortRoI t_sroi1 := { 0, (all from t_RoI1, 10), 20 }; |
35 | template ShortRoI t_sroi1_exp := { 0, (1, 2, (6..9), 10), 20 }; |
36 | |
37 | template ShortRoI t_sroi2 := ( { 1, 2, 3 }, { permutation (all from t_RoI2) } ); |
38 | template ShortRoI t_sroi2_exp := ( { 1, 2, 3 }, { permutation (1, ?, 3) } ); |
39 | |
40 | testcase tc_all_from_subtype_integer() runs on A |
41 | { |
42 | if (log2str(t_posint1) != log2str(t_posint1_exp)) { |
43 | setverdict(fail, "Expected: ", t_posint1_exp, ", got: ", t_posint1); |
44 | } |
45 | if (log2str(t_posint2) != log2str(t_posint2_exp)) { |
46 | setverdict(fail, "Expected: ", t_posint2_exp, ", got: ", t_posint2); |
47 | } |
48 | if (log2str(t_posint3) != log2str(t_posint3_exp)) { |
49 | setverdict(fail, "Expected: ", t_posint3_exp, ", got: ", t_posint3); |
50 | } |
51 | if (log2str(t_sroi1) != log2str(t_sroi1_exp)) { |
52 | setverdict(fail, "Expected: ", t_sroi1_exp, ", got: ", t_sroi1); |
53 | } |
54 | if (log2str(t_sroi2) != log2str(t_sroi2_exp)) { |
55 | setverdict(fail, "Expected: ", t_sroi2_exp, ", got: ", t_sroi2); |
56 | } |
57 | setverdict(pass); |
58 | } |
59 | |
60 | /* * * * float * * * */ |
61 | template RoF t_RoF := { (-10.0..-2.5), -1.0, 0.0 }; |
62 | const RoF c_RoF := { -0.3, -0.2, -0.1 }; |
63 | |
64 | template NegFloat t_negfloat := (all from t_RoF, -2.0, all from c_RoF, -100.0); |
65 | template NegFloat t_negfloat_exp := ((-10.0..-2.5), -1.0, 0.0, -2.0, -0.3, -0.2, -0.1, -100.0); |
66 | |
67 | template ShortRoF t_srof := { permutation (all from c_RoF) }; |
68 | template ShortRoF t_srof_exp := { permutation (-0.3, -0.2, -0.1) }; |
69 | |
70 | testcase tc_all_from_subtype_float() runs on A |
71 | { |
72 | if (log2str(t_negfloat) != log2str(t_negfloat_exp)) { |
73 | setverdict(fail, "Expected: ", t_negfloat_exp, ", got: ", t_negfloat); |
74 | } |
75 | if (log2str(t_srof) != log2str(t_srof_exp)) { |
76 | setverdict(fail, "Expected: ", t_srof_exp, ", got: ", t_srof); |
77 | } |
78 | setverdict(pass); |
79 | } |
80 | |
81 | /* * * * bitstring * * * */ |
82 | template RoBS t_RoBS := { '1010'B, ? }; |
83 | const RoBS c_RoBS := { '11011000'B, '00110011'B, '10101010'B }; |
84 | |
85 | template ByteString t_bytestr := ('00000000'B, all from c_RoBS, '11111111'B); |
86 | template ByteString t_bytestr_exp := ('00000000'B, '11011000'B, '00110011'B, '10101010'B, '11111111'B); |
87 | |
88 | template ShortRoBS t_srobs := { '1'B, permutation (all from t_RoBS) }; |
89 | template ShortRoBS t_srobs_exp := { '1'B, permutation ('1010'B, ?) }; |
90 | |
91 | testcase tc_all_from_subtype_bitstring() runs on A |
92 | { |
93 | if (log2str(t_bytestr) != log2str(t_bytestr_exp)) { |
94 | setverdict(fail, "Expected: ", t_bytestr_exp, ", got: ", t_bytestr); |
95 | } |
96 | if (log2str(t_srobs) != log2str(t_srobs_exp)) { |
97 | setverdict(fail, "Expected: ", t_srobs_exp, ", got: ", t_srobs); |
98 | } |
99 | setverdict(pass); |
100 | } |
101 | |
102 | /* * * * hexstring * * * */ |
103 | template RoHS t_RoHS := { '100'H, 'ABC'H }; |
104 | const RoHS c_RoHS := { '19A6'H, '999D'H, '1337'H }; |
105 | |
106 | template WordString t_wordstr := ('A000'H, 'FFFF'H, all from c_RoHS, '0000'H); |
107 | template WordString t_wordstr_exp := ('A000'H, 'FFFF'H, '19A6'H, '999D'H, '1337'H, '0000'H); |
108 | |
109 | template ShortRoHS t_srohs := { permutation (all from t_RoHS, '180DD'H) }; |
110 | template ShortRoHS t_srohs_exp := { permutation ('100'H, 'ABC'H, '180DD'H) }; |
111 | |
112 | testcase tc_all_from_subtype_hexstring() runs on A |
113 | { |
114 | if (log2str(t_wordstr) != log2str(t_wordstr_exp)) { |
115 | setverdict(fail, "Expected: ", t_wordstr_exp, ", got: ", t_wordstr); |
116 | } |
117 | if (log2str(t_srohs) != log2str(t_srohs_exp)) { |
118 | setverdict(fail, "Expected: ", t_srohs_exp, ", got: ", t_srohs); |
119 | } |
120 | setverdict(pass); |
121 | } |
122 | |
123 | /* * * * octetstring * * * */ |
124 | template RoOS t_RoOS := { '00'O, 'FF'O }; |
125 | const RoOS c_RoOS := { 'E77FB41C'O, 'DEADBEEF'O, 'CDCDCDCD'O }; |
126 | |
127 | template DWordString t_dwordstr := (all from c_RoOS, '0FFFFFFF'O); |
128 | template DWordString t_dwordstr_exp := ('E77FB41C'O, 'DEADBEEF'O, 'CDCDCDCD'O, '0FFFFFFF'O); |
129 | |
130 | template ShortRoOS t_sroos := { permutation (?, all from t_RoOS) }; |
131 | template ShortRoOS t_sroos_exp := { permutation (?, '00'O, 'FF'O) }; |
132 | |
133 | testcase tc_all_from_subtype_octetstring() runs on A |
134 | { |
135 | if (log2str(t_dwordstr) != log2str(t_dwordstr_exp)) { |
136 | setverdict(fail, "Expected: ", t_dwordstr_exp, ", got: ", t_dwordstr); |
137 | } |
138 | if (log2str(t_sroos) != log2str(t_sroos_exp)) { |
139 | setverdict(fail, "Expected: ", t_sroos_exp, ", got: ", t_sroos); |
140 | } |
141 | setverdict(pass); |
142 | } |
143 | |
144 | /* * * * charstring * * * */ |
145 | template RoCS t_RoCS := { ("a".."z"), ("0".."9"), ("A".."Z") }; |
146 | const RoCS c_RoCS := { "all_from.ttcn", "types.ttcn", "functions.ttcn", "sapc.ttcn" }; |
147 | |
148 | template TtcnFileName t_ttcnfiles := (all from c_RoCS); |
149 | template TtcnFileName t_ttcnfiles_exp := ("all_from.ttcn", "types.ttcn", "functions.ttcn", "sapc.ttcn"); |
150 | |
151 | template ShortRoCS t_srocs := { permutation (all from t_RoCS) }; |
152 | template ShortRoCS t_srocs_exp := { permutation (("a".."z"), ("0".."9"), ("A".."Z")) }; |
153 | |
154 | testcase tc_all_from_subtype_charstring() runs on A |
155 | { |
156 | if (log2str(t_ttcnfiles) != log2str(t_ttcnfiles_exp)) { |
157 | setverdict(fail, "Expected: ", t_ttcnfiles_exp, ", got: ", t_ttcnfiles); |
158 | } |
159 | if (log2str(t_srocs) != log2str(t_srocs_exp)) { |
160 | setverdict(fail, "Expected: ", t_srocs_exp, ", got: ", t_srocs); |
161 | } |
162 | setverdict(pass); |
163 | } |
164 | |
165 | /* * * * universal charstring * * * */ |
166 | template RoUCS t_RoUCS := { "abc", ?, "cba" }; |
167 | const RoUCS c_RoUCS := { "nothing", "special", "here" }; |
168 | |
169 | template XsdString t_xsdstr := (pattern "<*>", all from c_RoUCS); |
170 | template XsdString t_xsdstr_exp := (pattern "<*>", "nothing", "special", "here"); |
171 | |
172 | template ShortRoUCS t_sroucs := { all from t_RoUCS }; |
173 | template ShortRoUCS t_sroucs_exp := { "abc", ?, "cba" }; |
174 | |
175 | testcase tc_all_from_subtype_universal_charstring() runs on A |
176 | { |
177 | if (log2str(t_xsdstr) != log2str(t_xsdstr_exp)) { |
178 | setverdict(fail, "Expected: ", t_xsdstr_exp, ", got: ", t_xsdstr); |
179 | } |
180 | if (log2str(t_sroucs) != log2str(t_sroucs_exp)) { |
181 | setverdict(fail, "Expected: ", t_sroucs_exp, ", got: ", t_sroucs); |
182 | } |
183 | setverdict(pass); |
184 | } |
185 | |
186 | control { |
187 | execute(tc_all_from_subtype_integer()); |
188 | execute(tc_all_from_subtype_float()); |
189 | execute(tc_all_from_subtype_bitstring()); |
190 | execute(tc_all_from_subtype_hexstring()); |
191 | execute(tc_all_from_subtype_octetstring()); |
192 | execute(tc_all_from_subtype_charstring()); |
193 | execute(tc_all_from_subtype_universal_charstring()); |
194 | } |
195 | |
196 | } |