Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / XML / XER / Txerboolean.ttcnpp
1 /******************************************************************************
2 * Copyright (c) 2000-2015 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 Txerboolean {
9
10 modulepar boolean Txerboolean_verbose := false;
11 #define verbose Txerboolean_verbose
12
13 #include "../macros.ttcnin"
14
15 import from AsnValues all;
16 type component Tboolean {}
17
18 external function flatten(inout universal charstring par) ;
19
20 DECLARE_XER_ENCODERS(boolean , boolean);
21 DECLARE_EXER_ENCODERS(boolean,boolean)
22 DECLARE_XER_ENCODERS(rboolean, rboolean);
23 DECLARE_EXER_ENCODERS(rboolean,rboolean)
24 DECLARE_XER_ENCODERS(uboolean, uboolean);
25 DECLARE_EXER_ENCODERS(uboolean,uboolean)
26 DECLARE_XER_ENCODERS(rofboolean, rofboolean);
27 DECLARE_EXER_ENCODERS(rofboolean,rofboolean)
28
29 type record rboolean {
30 boolean b optional
31 }
32
33 type union uboolean {
34 boolean b
35 }
36
37 type record of boolean rofboolean; // NOT roflboolean !
38
39 testcase encode_bool() runs on Tboolean
40 {
41 var boolean plain := false;
42 var universal charstring expected := "<BOOLEAN><false/></BOOLEAN>";
43 CHECK_METHOD(cxer_enc_boolean, plain, expected);
44 CHECK_METHOD(bxer_enc_boolean, plain, expected & lf);
45 expected := "<BOOLEAN>false</BOOLEAN>";
46 CHECK_METHOD(exer_enc_boolean, plain, expected & lf);
47
48 plain := true;
49 expected := "<BOOLEAN><true/></BOOLEAN>"
50 CHECK_METHOD(cxer_enc_boolean, plain, expected);
51 CHECK_METHOD(bxer_enc_boolean, plain, expected & lf);
52 expected := "<BOOLEAN>true</BOOLEAN>";
53 CHECK_METHOD(exer_enc_boolean, plain, expected & lf);
54 }
55
56 testcase decode_bool() runs on Tboolean
57 {
58 var universal charstring input := "<BOOLEAN><false/></BOOLEAN>";
59 var boolean expected := false;
60 CHECK_DECODE(cxer_dec_boolean, input, boolean, expected);
61
62 input := "<BOOLEAN><true/></BOOLEAN>";
63 expected := true;
64 CHECK_DECODE(cxer_dec_boolean, input, boolean, expected);
65 }
66
67 testcase decode_textbool() runs on Tboolean
68 {
69 var universal charstring input := "<BOOLEAN>0</BOOLEAN>";
70 var boolean expected := false;
71 CHECK_DECODE(cxer_dec_boolean, input, boolean, expected);
72
73 input := "<BOOLEAN>1</BOOLEAN>";
74 expected := true;
75 CHECK_DECODE(cxer_dec_boolean, input, boolean, expected);
76 }
77
78 testcase encode_bool_omit() runs on Tboolean
79 {
80 var rboolean rec := { omit }
81 var universal charstring expected, unexpected;
82
83 expected := "<rboolean/>\n";
84 CHECK_METHOD(cxer_enc_rboolean, rec, expected);
85 CHECK_METHOD(bxer_enc_rboolean, rec, expected & lf);
86 CHECK_METHOD(exer_enc_rboolean, rec, expected & lf);
87
88 rec.b := true; // not omit anymore
89 expected := "<rboolean><b><true/></b></rboolean>\n";
90 CHECK_METHOD(cxer_enc_rboolean, rec, expected);
91 expected := "<rboolean>\n\t<b><true/></b>\n</rboolean>\n\n"
92 CHECK_METHOD(bxer_enc_rboolean, rec, expected);
93 expected := "<rboolean>\n\t<b>true</b>\n</rboolean>\n\n"
94 CHECK_METHOD(exer_enc_rboolean, rec, expected);
95 }
96
97 testcase decode_bool_omit() runs on Tboolean
98 {
99 var rboolean expected := { omit };
100 const charstring rbool_empty := "<rboolean/>\n";
101 CHECK_DECODE(cxer_dec_rboolean, rbool_empty, rboolean, expected);
102 CHECK_DECODE(bxer_dec_rboolean, rbool_empty, rboolean, expected);
103
104 const charstring rbool_t := "<rboolean><b><true/></b></rboolean>\n";
105 expected := { true };
106 CHECK_DECODE(cxer_dec_rboolean, rbool_t, rboolean, expected);
107 CHECK_DECODE(bxer_dec_rboolean, rbool_t, rboolean, expected);
108
109 const charstring rbool_f := "<rboolean><b><false/></b></rboolean>\n";
110 expected := { false };
111 CHECK_DECODE(cxer_dec_rboolean, rbool_f, rboolean, expected);
112 CHECK_DECODE(bxer_dec_rboolean, rbool_f, rboolean, expected);
113 }
114
115 testcase encode_bool_choice() runs on Tboolean
116 {
117 var uboolean rec := { b := false }
118 var universal charstring expected;
119
120 expected := "<uboolean>\n\t<b><false/></b>\n</uboolean>\n\n";
121 CHECK_METHOD(bxer_enc_uboolean, rec, expected);
122 flatten(expected);
123 CHECK_METHOD(cxer_enc_uboolean, rec, expected & lf);
124 expected := "<uboolean>\n\t<b>false</b>\n</uboolean>\n\n";
125 CHECK_METHOD(exer_enc_uboolean, rec, expected);
126
127 rec.b := true; // not omit anymore
128 expected := "<uboolean>\n\t<b><true/></b>\n</uboolean>\n\n";
129 CHECK_METHOD(bxer_enc_uboolean, rec, expected);
130 flatten(expected);
131 CHECK_METHOD(cxer_enc_uboolean, rec, expected & lf);
132 expected := "<uboolean>\n\t<b>true</b>\n</uboolean>\n\n";
133 CHECK_METHOD(exer_enc_uboolean, rec, expected);
134 }
135
136 testcase decode_bool_choice() runs on Tboolean
137 {
138 const charstring x0 := "<uboolean>\n\t<b><false/></b>\n</uboolean>\n\n";
139 var uboolean expected := { b := false }
140 CHECK_DECODE(bxer_dec_uboolean, x0, uboolean, expected);
141 CHECK_DECODE(cxer_dec_uboolean, x0, uboolean, expected);
142
143 const charstring x1 := "<uboolean>\n\t<b><true/></b>\n</uboolean>\n\n";
144 expected := { b := true }
145 CHECK_DECODE(bxer_dec_uboolean, x1, uboolean, expected);
146 CHECK_DECODE(cxer_dec_uboolean, x1, uboolean, expected);
147 }
148
149 const rofboolean a0 := {};
150 const charstring abstr_empty := "<rofboolean/>\n\n";
151
152 const rofboolean a1 := { false }
153 const charstring abstr1 :=
154 "<rofboolean>\n" &
155 "\t<false/>\n" &
156 "</rofboolean>\n\n";
157 const charstring abstr1_exer :=
158 "<rofboolean>\n" &
159 "\t<BOOLEAN>false</BOOLEAN>\n" &
160 "</rofboolean>\n\n";
161
162 const rofboolean a3 := { true, false, true }
163 const charstring abstr3 :=
164 "<rofboolean>\n" &
165 "\t<true/><false/><true/>\n" &
166 "</rofboolean>\n\n";
167 const charstring abstr3_exer :=
168 "<rofboolean>\n" &
169 "\t<BOOLEAN>true</BOOLEAN>\n" &
170 "\t<BOOLEAN>false</BOOLEAN>\n" &
171 "\t<BOOLEAN>true</BOOLEAN>\n" &
172 "</rofboolean>\n\n";
173
174
175 testcase encode_bool_array() runs on Tboolean
176 {
177 var universal charstring expected := abstr_empty;
178 CHECK_METHOD(bxer_enc_rofboolean, a0, expected);
179 CHECK_METHOD(exer_enc_rofboolean, a0, expected);
180 flatten(expected);
181 CHECK_METHOD(cxer_enc_rofboolean, a0, expected & lf);
182
183 expected := abstr1;
184 CHECK_METHOD(bxer_enc_rofboolean, a1, expected);
185 flatten(expected);
186 CHECK_METHOD(cxer_enc_rofboolean, a1, expected & lf);
187 expected := abstr1_exer;
188 CHECK_METHOD(exer_enc_rofboolean, a1, expected);
189
190 expected := abstr3;
191 CHECK_METHOD(bxer_enc_rofboolean, a3, expected);
192 flatten(expected);
193 CHECK_METHOD(cxer_enc_rofboolean, a3, expected & lf);
194 expected := abstr3_exer;
195 CHECK_METHOD(exer_enc_rofboolean, a3, expected);
196 }
197
198 testcase decode_bool_array() runs on Tboolean
199 {
200 var rofboolean expected := a0;
201 CHECK_DECODE2 (rofboolean, abstr_empty, rofboolean, expected);
202 CHECK_DECODE(exer_dec_rofboolean, abstr_empty, rofboolean, expected);
203
204 expected := a1;
205 CHECK_DECODE2( rofboolean, abstr1 , rofboolean, expected);
206 CHECK_DECODE(exer_dec_rofboolean, abstr1_exer, rofboolean, expected);
207
208 expected := a3;
209 CHECK_DECODE2 (rofboolean, abstr3 , rofboolean, expected);
210 CHECK_DECODE(exer_dec_rofboolean, abstr3_exer, rofboolean, expected);
211 }
212
213 control {
214
215 execute(encode_bool());
216 execute(decode_bool());
217 execute(decode_textbool());
218 execute(encode_bool_omit());
219 execute(decode_bool_omit());
220 execute(encode_bool_choice());
221 execute(decode_bool_choice());
222 execute(encode_bool_array());
223 execute(decode_bool_array());
224 }
225
226 }
227 with {
228 encode "XML";
229 extension "version R8B";
230 }
This page took 0.036484 seconds and 5 git commands to generate.