1 /******************************************************************************
2 * Copyright (c) 2000-2016 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
12 ******************************************************************************/
14 // subtyping and the 'all from' clause
15 module all_from_subtype {
17 import from types all;
18 import from functions all;
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 };
25 template PosInt t_posint1 := (0, all from t_RoI1);
26 template PosInt t_posint1_exp := (0, 1, 2, (6..9));
28 template PosInt t_posint2 := (all from c_RoI, 50, 100);
29 template PosInt t_posint2_exp := (20, 21, 22, 50, 100);
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));
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 };
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) } );
40 testcase tc_all_from_subtype_integer() runs on A
42 if (log2str(t_posint1) != log2str(t_posint1_exp)) {
43 setverdict(fail, "Expected: ", t_posint1_exp, ", got: ", t_posint1);
45 if (log2str(t_posint2) != log2str(t_posint2_exp)) {
46 setverdict(fail, "Expected: ", t_posint2_exp, ", got: ", t_posint2);
48 if (log2str(t_posint3) != log2str(t_posint3_exp)) {
49 setverdict(fail, "Expected: ", t_posint3_exp, ", got: ", t_posint3);
51 if (log2str(t_sroi1) != log2str(t_sroi1_exp)) {
52 setverdict(fail, "Expected: ", t_sroi1_exp, ", got: ", t_sroi1);
54 if (log2str(t_sroi2) != log2str(t_sroi2_exp)) {
55 setverdict(fail, "Expected: ", t_sroi2_exp, ", got: ", t_sroi2);
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 };
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);
67 template ShortRoF t_srof := { permutation (all from c_RoF) };
68 template ShortRoF t_srof_exp := { permutation (-0.3, -0.2, -0.1) };
70 testcase tc_all_from_subtype_float() runs on A
72 if (log2str(t_negfloat) != log2str(t_negfloat_exp)) {
73 setverdict(fail, "Expected: ", t_negfloat_exp, ", got: ", t_negfloat);
75 if (log2str(t_srof) != log2str(t_srof_exp)) {
76 setverdict(fail, "Expected: ", t_srof_exp, ", got: ", t_srof);
81 /* * * * bitstring * * * */
82 template RoBS t_RoBS := { '1010'B, ? };
83 const RoBS c_RoBS := { '11011000'B, '00110011'B, '10101010'B };
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);
88 template ShortRoBS t_srobs := { '1'B, permutation (all from t_RoBS) };
89 template ShortRoBS t_srobs_exp := { '1'B, permutation ('1010'B, ?) };
91 testcase tc_all_from_subtype_bitstring() runs on A
93 if (log2str(t_bytestr) != log2str(t_bytestr_exp)) {
94 setverdict(fail, "Expected: ", t_bytestr_exp, ", got: ", t_bytestr);
96 if (log2str(t_srobs) != log2str(t_srobs_exp)) {
97 setverdict(fail, "Expected: ", t_srobs_exp, ", got: ", t_srobs);
102 /* * * * hexstring * * * */
103 template RoHS t_RoHS := { '100'H, 'ABC'H };
104 const RoHS c_RoHS := { '19A6'H, '999D'H, '1337'H };
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);
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) };
112 testcase tc_all_from_subtype_hexstring() runs on A
114 if (log2str(t_wordstr) != log2str(t_wordstr_exp)) {
115 setverdict(fail, "Expected: ", t_wordstr_exp, ", got: ", t_wordstr);
117 if (log2str(t_srohs) != log2str(t_srohs_exp)) {
118 setverdict(fail, "Expected: ", t_srohs_exp, ", got: ", t_srohs);
123 /* * * * octetstring * * * */
124 template RoOS t_RoOS := { '00'O, 'FF'O };
125 const RoOS c_RoOS := { 'E77FB41C'O, 'DEADBEEF'O, 'CDCDCDCD'O };
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);
130 template ShortRoOS t_sroos := { permutation (?, all from t_RoOS) };
131 template ShortRoOS t_sroos_exp := { permutation (?, '00'O, 'FF'O) };
133 testcase tc_all_from_subtype_octetstring() runs on A
135 if (log2str(t_dwordstr) != log2str(t_dwordstr_exp)) {
136 setverdict(fail, "Expected: ", t_dwordstr_exp, ", got: ", t_dwordstr);
138 if (log2str(t_sroos) != log2str(t_sroos_exp)) {
139 setverdict(fail, "Expected: ", t_sroos_exp, ", got: ", t_sroos);
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" };
148 template TtcnFileName t_ttcnfiles := (all from c_RoCS);
149 template TtcnFileName t_ttcnfiles_exp := ("all_from.ttcn", "types.ttcn", "functions.ttcn", "sapc.ttcn");
151 template ShortRoCS t_srocs := { permutation (all from t_RoCS) };
152 template ShortRoCS t_srocs_exp := { permutation (("a".."z"), ("0".."9"), ("A".."Z")) };
154 testcase tc_all_from_subtype_charstring() runs on A
156 if (log2str(t_ttcnfiles) != log2str(t_ttcnfiles_exp)) {
157 setverdict(fail, "Expected: ", t_ttcnfiles_exp, ", got: ", t_ttcnfiles);
159 if (log2str(t_srocs) != log2str(t_srocs_exp)) {
160 setverdict(fail, "Expected: ", t_srocs_exp, ", got: ", t_srocs);
165 /* * * * universal charstring * * * */
166 template RoUCS t_RoUCS := { "abc", ?, "cba" };
167 const RoUCS c_RoUCS := { "nothing", "special", "here" };
169 template XsdString t_xsdstr := (pattern "<*>", all from c_RoUCS);
170 template XsdString t_xsdstr_exp := (pattern "<*>", "nothing", "special", "here");
172 template ShortRoUCS t_sroucs := { all from t_RoUCS };
173 template ShortRoUCS t_sroucs_exp := { "abc", ?, "cba" };
175 testcase tc_all_from_subtype_universal_charstring() runs on A
177 if (log2str(t_xsdstr) != log2str(t_xsdstr_exp)) {
178 setverdict(fail, "Expected: ", t_xsdstr_exp, ", got: ", t_xsdstr);
180 if (log2str(t_sroucs) != log2str(t_sroucs_exp)) {
181 setverdict(fail, "Expected: ", t_sroucs_exp, ", got: ", t_sroucs);
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());