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 ******************************************************************************/
10 modulepar boolean AnyElement_verbose := false;
11 #define verbose AnyElement_verbose
12 #include "../macros.ttcnin"
16 type record AEProduct {
19 universal charstring info
22 variant (info) "anyElement from 'http://www.example.com/A', "
23 "'http://www.example.com/B', unqualified"
26 DECLARE_XER_ENCODERS(AEProduct, ae);
27 DECLARE_EXER_ENCODERS(AEProduct, ae);
29 const AEProduct aep := {
32 info := "<xyz:color xmlns:xyz=""http://www.example.com/A"" available=""true"">red</xyz:color>"
35 const universal charstring str_ae_e :=
37 "\t<name>Trousers</name>\n" &
38 "\t<price>20</price>\n" &
39 "\t<xyz:color xmlns:xyz=\"http://www.example.com/A\" available=\"true\">red</xyz:color>\n" &
42 const universal charstring str_ae_b :=
44 "\t<name>Trousers</name>\n" &
45 "\t<price>20</price>\n" &
46 "\t<info><xyz:color xmlns:xyz="http://www.example.com/A" available="true">red</xyz:color></info>\n" &
49 testcase encode_ae() runs on AE
51 CHECK_METHOD(bxer_enc_ae, aep, str_ae_b);
52 CHECK_METHOD(exer_enc_ae, aep, str_ae_e);
55 testcase decode_ae() runs on AE
57 CHECK_DECODE(bxer_dec_ae, str_ae_b, AEProduct, aep);
58 CHECK_DECODE(exer_dec_ae, str_ae_e, AEProduct, aep);
61 // .- -. -.. / -. --- .-- / ..-. --- .-. / ... --- -- . - .... .. -. --.
62 // -.-. --- -- .--. .-.. . - . .-.. -.-- / -.. .. ..-. ..-. . .-. . -. -
64 type record AFProduct {
67 universal charstring info
70 variant (info) "anyElement except 'http://www.example.com/A', 'http://www.example.com/B', unqualified"
73 DECLARE_XER_ENCODERS(AFProduct, af);
74 DECLARE_EXER_ENCODERS(AFProduct, af);
76 const AFProduct afp := {
79 info := "<xyz:color xmlns:xyz=""http://www.example.com/C"" available=""true"">red</xyz:color>"
82 const universal charstring str_af_e :=
84 "\t<name>Trousers</name>\n" &
85 "\t<price>20</price>\n" &
86 "\t<xyz:color xmlns:xyz=\"http://www.example.com/C\" available=\"true\">red</xyz:color>\n" &
89 const universal charstring str_af_b :=
91 "\t<name>Trousers</name>\n" &
92 "\t<price>20</price>\n" &
93 "\t<info><xyz:color xmlns:xyz="http://www.example.com/C" available="true">red</xyz:color></info>\n" &
96 testcase encode_af() runs on AE
98 CHECK_METHOD(bxer_enc_af, afp, str_af_b);
99 CHECK_METHOD(exer_enc_af, afp, str_af_e);
102 testcase decode_af() runs on AE
104 CHECK_DECODE(bxer_dec_af, str_af_b, AFProduct, afp);
105 CHECK_DECODE(exer_dec_af, str_af_e, AFProduct, afp);
108 // .- -. -.. / -. --- .-- / ..-. --- .-. / ... --- -- . - .... .. -. --.
109 // -.-. --- -- .--. .-.. . - . .-.. -.-- / -.. .. ..-. ..-. . .-. . -. -
111 type record of universal charstring anys
113 variant ([-]) "anyElement from unqualified";
116 DECLARE_XER_ENCODERS(anys, anys);
117 DECLARE_EXER_ENCODERS(anys, anys);
120 "<captain>You know what you doing</captain>",
121 "<move>all ZIG</move>",
122 "<for>Great justice!</for>"
127 const universal charstring estr_a3 :=
129 "\t<captain>You know what you doing</captain>\n" &
130 "\t<move>all ZIG</move>\n" &
131 "\t<for>Great justice!</for>\n" &
134 const universal charstring bstr_a3 :=
136 "\t<UNIVERSAL_CHARSTRING><captain>You know what you doing</captain></UNIVERSAL_CHARSTRING>\n" &
137 "\t<UNIVERSAL_CHARSTRING><move>all ZIG</move></UNIVERSAL_CHARSTRING>\n" &
138 "\t<UNIVERSAL_CHARSTRING><for>Great justice!</for></UNIVERSAL_CHARSTRING>\n" &
141 const universal charstring estr_a0empty :=
144 const universal charstring bstr_a0empty :=
147 // not empty-element, for decoding only
148 const universal charstring estr_a0 :=
152 const universal charstring bstr_a0 :=
157 testcase encode_anys() runs on AE
159 CHECK_METHOD(bxer_enc_anys, a3, bstr_a3);
160 CHECK_METHOD(exer_enc_anys, a3, estr_a3);
162 CHECK_METHOD(bxer_enc_anys, a0, bstr_a0empty);
163 CHECK_METHOD(exer_enc_anys, a0, estr_a0empty);
166 testcase decode_anys() runs on AE
168 CHECK_DECODE(bxer_dec_anys, bstr_a3, anys, a3);
169 CHECK_DECODE(exer_dec_anys, estr_a3, anys, a3);
171 CHECK_DECODE(bxer_dec_anys, bstr_a0empty, anys, a0);
172 CHECK_DECODE(exer_dec_anys, estr_a0empty, anys, a0);
173 CHECK_DECODE(bxer_dec_anys, bstr_a0, anys, a0);
174 CHECK_DECODE(exer_dec_anys, estr_a0, anys, a0);
177 // .- -. -.. / -. --- .-- / ..-. --- .-. / ... --- -- . - .... .. -. --.
178 // -.-. --- -- .--. .-.. . - . .-.. -.-- / -.. .. ..-. ..-. . .-. . -. -
181 record of universal charstring any_list,
182 charstring enemy optional,
183 integer zigs optional
186 variant (any_list) "untagged";
187 variant (any_list[-]) "anyElement from unqualified";
190 DECLARE_XER_ENCODERS(utanys, utanys);
191 DECLARE_EXER_ENCODERS(utanys, utanys);
193 const utanys ua3 := { any_list := {
194 "<captain>You know what you doing</captain>",
195 "<move>all ZIG</move>",
196 "<for>Great justice!</for>"
202 const utanys ua7 := { any_list := {
203 "<all/>", "<your/>", "<base/>", "<are/>", "<belong/>", "<to/>", "<us/>"
209 const utanys ua0 := {{}, omit, omit}
211 const universal charstring estr_ua3 :=
213 "\t<captain>You know what you doing</captain>\n" &
214 "\t<move>all ZIG</move>\n" &
215 "\t<for>Great justice!</for>\n" &
216 "\t<enemy>CATS</enemy>\n" &
219 const universal charstring estr_ua7 :=
228 "\t<enemy>CATS</enemy>\n" &
231 const universal charstring bstr_ua3 :=
234 "\t\t<UNIVERSAL_CHARSTRING><captain>You know what you doing</captain></UNIVERSAL_CHARSTRING>\n" &
235 "\t\t<UNIVERSAL_CHARSTRING><move>all ZIG</move></UNIVERSAL_CHARSTRING>\n" &
236 "\t\t<UNIVERSAL_CHARSTRING><for>Great justice!</for></UNIVERSAL_CHARSTRING>\n" &
238 "\t<enemy>CATS</enemy>\n" &
241 const universal charstring estr_ua0empty :=
244 const universal charstring bstr_ua0empty :=
250 // not empty-element, for decoding only
251 const universal charstring estr_ua0 :=
255 const universal charstring bstr_ua0 :=
262 testcase encode_utanys() runs on AE
264 CHECK_METHOD(bxer_enc_utanys, ua3, bstr_ua3);
265 CHECK_METHOD(exer_enc_utanys, ua3, estr_ua3);
266 CHECK_METHOD(exer_enc_utanys, ua7, estr_ua7);
268 CHECK_METHOD(bxer_enc_utanys, ua0, bstr_ua0empty);
269 CHECK_METHOD(exer_enc_utanys, ua0, estr_ua0empty);
272 testcase decode_utanys() runs on AE
274 CHECK_DECODE(bxer_dec_utanys, bstr_ua3, utanys, ua3);
275 CHECK_DECODE(exer_dec_utanys, estr_ua3, utanys, ua3);
276 CHECK_DECODE(exer_dec_utanys, estr_ua7, utanys, ua7);
278 CHECK_DECODE(bxer_dec_utanys, bstr_ua0empty, utanys, ua0);
279 CHECK_DECODE(exer_dec_utanys, estr_ua0empty, utanys, ua0);
280 CHECK_DECODE(bxer_dec_utanys, bstr_ua0, utanys, ua0);
281 CHECK_DECODE(exer_dec_utanys, estr_ua0, utanys, ua0);
285 /* * * * * * * * * * * * */
287 // ANY-ELEMENT as the only member of a record is a corner case
288 type record anys_and_only_anys {
289 record of universal charstring elements
292 variant (elements) "anyElement"
295 DECLARE_XER_ENCODERS(anys_and_only_anys, aaoa);
296 DECLARE_EXER_ENCODERS(anys_and_only_anys, aaoa);
298 const anys_and_only_anys noanys := { elements := {} }
299 const universal charstring bstr_noanys :=
300 "<anys_and_only_anys>\n" &
302 "</anys_and_only_anys>\n\n";
303 const universal charstring estr_noanys :=
304 "<anys_and_only_anys/>\n\n";
306 const anys_and_only_anys marx := {
307 elements := {"<chico/>", "<groucho/>", "<karl></karl>"}
309 const universal charstring estr_marx :=
310 "<anys_and_only_anys>\n" &
313 "\t<karl></karl>\n" &
314 "</anys_and_only_anys>\n\n";
316 const universal charstring bstr_marx :=
317 "<anys_and_only_anys>\n" &
319 "\t\t<UNIVERSAL_CHARSTRING><chico/></UNIVERSAL_CHARSTRING>\n" &
320 "\t\t<UNIVERSAL_CHARSTRING><groucho/></UNIVERSAL_CHARSTRING>\n" &
321 "\t\t<UNIVERSAL_CHARSTRING><karl></karl></UNIVERSAL_CHARSTRING>\n" &
323 "</anys_and_only_anys>\n\n";
325 // When decoding EXER, karl becomes an empty element too (?)
326 const anys_and_only_anys marx_dec := {
327 elements := {"<chico/>", "<groucho/>", "<karl/>"}
330 testcase encode_only() runs on AE
332 CHECK_METHOD(bxer_enc_aaoa, noanys, bstr_noanys);
333 CHECK_METHOD(exer_enc_aaoa, noanys, estr_noanys);
335 CHECK_METHOD(bxer_enc_aaoa, marx, bstr_marx);
336 CHECK_METHOD(exer_enc_aaoa, marx, estr_marx);
339 testcase decode_only() runs on AE
341 CHECK_DECODE(bxer_dec_aaoa, bstr_noanys, anys_and_only_anys, noanys);
342 CHECK_DECODE(exer_dec_aaoa, estr_noanys, anys_and_only_anys, noanys);
344 CHECK_DECODE(bxer_dec_aaoa, bstr_marx, anys_and_only_anys, marx);
345 CHECK_DECODE(exer_dec_aaoa, estr_marx, anys_and_only_anys, marx_dec);
356 execute(encode_anys())
357 execute(decode_anys())
359 execute(encode_utanys())
360 execute(decode_utanys())
362 execute(encode_only())
363 execute(decode_only())