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 AnyElementOptional
10 modulepar boolean AnyElement_verbose := false;
11 #define verbose AnyElement_verbose
12 #include "../macros.ttcnin"
16 type record AEProduct {
19 universal charstring info optional
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_aeopt() 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_aeopt() 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 optional
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_afopt() 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_afopt() 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 // ANY-ELEMENT as the only member of a record is a corner case
112 type record anys_and_only_anys {
113 record of universal charstring elements optional
116 variant (elements) "anyElement"
119 DECLARE_XER_ENCODERS(anys_and_only_anys, aaoa);
120 DECLARE_EXER_ENCODERS(anys_and_only_anys, aaoa);
122 const anys_and_only_anys noanys_empty := { elements := {} }
123 const anys_and_only_anys noanys_omit := { elements := omit }
125 // the empty array is encoded into this in basic XER
126 const universal charstring bstr_noanys :=
127 "<anys_and_only_anys>\n" &
129 "</anys_and_only_anys>\n\n";
131 // both the empty array and the omitted field are encoded into this in extended XER
132 // this is always decoded into an omitted field
133 const universal charstring estr_noanys :=
134 "<anys_and_only_anys/>\n\n";
136 const anys_and_only_anys marx := {
137 elements := {"<chico/>", "<groucho/>", "<karl></karl>"}
139 const universal charstring estr_marx :=
140 "<anys_and_only_anys>\n" &
143 "\t<karl></karl>\n" &
144 "</anys_and_only_anys>\n\n";
146 const universal charstring bstr_marx :=
147 "<anys_and_only_anys>\n" &
149 "\t\t<UNIVERSAL_CHARSTRING><chico/></UNIVERSAL_CHARSTRING>\n" &
150 "\t\t<UNIVERSAL_CHARSTRING><groucho/></UNIVERSAL_CHARSTRING>\n" &
151 "\t\t<UNIVERSAL_CHARSTRING><karl></karl></UNIVERSAL_CHARSTRING>\n" &
153 "</anys_and_only_anys>\n\n";
155 // When decoding EXER, karl becomes an empty element too (?)
156 const anys_and_only_anys marx_dec := {
157 elements := {"<chico/>", "<groucho/>", "<karl/>"}
160 testcase encode_only_opt() runs on AE
162 CHECK_METHOD(bxer_enc_aaoa, noanys_empty, bstr_noanys);
163 CHECK_METHOD(exer_enc_aaoa, noanys_empty, estr_noanys);
164 CHECK_METHOD(exer_enc_aaoa, noanys_omit, estr_noanys);
166 CHECK_METHOD(bxer_enc_aaoa, marx, bstr_marx);
167 CHECK_METHOD(exer_enc_aaoa, marx, estr_marx);
170 testcase decode_only_opt() runs on AE
172 CHECK_DECODE(bxer_dec_aaoa, bstr_noanys, anys_and_only_anys, noanys_empty);
173 CHECK_DECODE(exer_dec_aaoa, estr_noanys, anys_and_only_anys, noanys_omit);
175 CHECK_DECODE(bxer_dec_aaoa, bstr_marx, anys_and_only_anys, marx);
176 CHECK_DECODE(exer_dec_aaoa, estr_marx, anys_and_only_anys, marx_dec);
181 execute(encode_aeopt())
182 execute(decode_aeopt())
184 execute(encode_afopt())
185 execute(decode_afopt())
187 // execute(encode_anys())
188 // execute(decode_anys())
190 // execute(encode_utanys())
191 // execute(decode_utanys())
193 execute(encode_only_opt())
194 execute(decode_only_opt())