Commit | Line | Data |
---|---|---|
970ed795 | 1 | /****************************************************************************** |
d44e3c4f | 2 | * Copyright (c) 2000-2016 Ericsson Telecom AB |
970ed795 EL |
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 | * Raduly, Csaba | |
12 | * | |
970ed795 EL |
13 | ******************************************************************************/ |
14 | module AnyElementOptional | |
15 | { | |
16 | modulepar boolean AnyElement_verbose := false; | |
17 | #define verbose AnyElement_verbose | |
18 | #include "../macros.ttcnin" | |
19 | ||
20 | type component AE {} | |
21 | ||
22 | type record AEProduct { | |
23 | charstring name, | |
24 | integer price, | |
25 | universal charstring info optional | |
26 | } | |
27 | with { | |
28 | variant (info) "anyElement from 'http://www.example.com/A', " | |
29 | "'http://www.example.com/B', unqualified" | |
30 | } | |
31 | ||
32 | DECLARE_XER_ENCODERS(AEProduct, ae); | |
33 | DECLARE_EXER_ENCODERS(AEProduct, ae); | |
34 | ||
35 | const AEProduct aep := { | |
36 | name := "Trousers", | |
37 | price := 20, | |
38 | info := "<xyz:color xmlns:xyz=""http://www.example.com/A"" available=""true"">red</xyz:color>" | |
39 | } | |
40 | ||
41 | const universal charstring str_ae_e := | |
42 | "<AEProduct>\n" & | |
43 | "\t<name>Trousers</name>\n" & | |
44 | "\t<price>20</price>\n" & | |
45 | "\t<xyz:color xmlns:xyz=\"http://www.example.com/A\" available=\"true\">red</xyz:color>\n" & | |
46 | "</AEProduct>\n\n"; | |
47 | ||
48 | const universal charstring str_ae_b := | |
49 | "<AEProduct>\n" & | |
50 | "\t<name>Trousers</name>\n" & | |
51 | "\t<price>20</price>\n" & | |
52 | "\t<info><xyz:color xmlns:xyz="http://www.example.com/A" available="true">red</xyz:color></info>\n" & | |
53 | "</AEProduct>\n\n"; | |
54 | ||
55 | testcase encode_aeopt() runs on AE | |
56 | { | |
57 | CHECK_METHOD(bxer_enc_ae, aep, str_ae_b); | |
58 | CHECK_METHOD(exer_enc_ae, aep, str_ae_e); | |
59 | } | |
60 | ||
61 | testcase decode_aeopt() runs on AE | |
62 | { | |
63 | CHECK_DECODE(bxer_dec_ae, str_ae_b, AEProduct, aep); | |
64 | CHECK_DECODE(exer_dec_ae, str_ae_e, AEProduct, aep); | |
65 | } | |
66 | ||
67 | // .- -. -.. / -. --- .-- / ..-. --- .-. / ... --- -- . - .... .. -. --. | |
68 | // -.-. --- -- .--. .-.. . - . .-.. -.-- / -.. .. ..-. ..-. . .-. . -. - | |
69 | ||
70 | type record AFProduct { | |
71 | charstring name, | |
72 | integer price, | |
73 | universal charstring info optional | |
74 | } | |
75 | with { | |
76 | variant (info) "anyElement except 'http://www.example.com/A', 'http://www.example.com/B', unqualified" | |
77 | } | |
78 | ||
79 | DECLARE_XER_ENCODERS(AFProduct, af); | |
80 | DECLARE_EXER_ENCODERS(AFProduct, af); | |
81 | ||
82 | const AFProduct afp := { | |
83 | name := "Trousers", | |
84 | price := 20, | |
85 | info := "<xyz:color xmlns:xyz=""http://www.example.com/C"" available=""true"">red</xyz:color>" | |
86 | } | |
87 | ||
88 | const universal charstring str_af_e := | |
89 | "<AFProduct>\n" & | |
90 | "\t<name>Trousers</name>\n" & | |
91 | "\t<price>20</price>\n" & | |
92 | "\t<xyz:color xmlns:xyz=\"http://www.example.com/C\" available=\"true\">red</xyz:color>\n" & | |
93 | "</AFProduct>\n\n"; | |
94 | ||
95 | const universal charstring str_af_b := | |
96 | "<AFProduct>\n" & | |
97 | "\t<name>Trousers</name>\n" & | |
98 | "\t<price>20</price>\n" & | |
99 | "\t<info><xyz:color xmlns:xyz="http://www.example.com/C" available="true">red</xyz:color></info>\n" & | |
100 | "</AFProduct>\n\n"; | |
101 | ||
102 | testcase encode_afopt() runs on AE | |
103 | { | |
104 | CHECK_METHOD(bxer_enc_af, afp, str_af_b); | |
105 | CHECK_METHOD(exer_enc_af, afp, str_af_e); | |
106 | } | |
107 | ||
108 | testcase decode_afopt() runs on AE | |
109 | { | |
110 | CHECK_DECODE(bxer_dec_af, str_af_b, AFProduct, afp); | |
111 | CHECK_DECODE(exer_dec_af, str_af_e, AFProduct, afp); | |
112 | } | |
113 | ||
114 | // .- -. -.. / -. --- .-- / ..-. --- .-. / ... --- -- . - .... .. -. --. | |
115 | // -.-. --- -- .--. .-.. . - . .-.. -.-- / -.. .. ..-. ..-. . .-. . -. - | |
116 | ||
117 | // ANY-ELEMENT as the only member of a record is a corner case | |
118 | type record anys_and_only_anys { | |
119 | record of universal charstring elements optional | |
120 | } | |
121 | with { | |
122 | variant (elements) "anyElement" | |
123 | } | |
124 | ||
125 | DECLARE_XER_ENCODERS(anys_and_only_anys, aaoa); | |
126 | DECLARE_EXER_ENCODERS(anys_and_only_anys, aaoa); | |
127 | ||
51fa56b9 | 128 | const anys_and_only_anys noanys_empty := { elements := {} } |
129 | const anys_and_only_anys noanys_omit := { elements := omit } | |
130 | ||
131 | // the empty array is encoded into this in basic XER | |
970ed795 EL |
132 | const universal charstring bstr_noanys := |
133 | "<anys_and_only_anys>\n" & | |
134 | "\t<elements/>\n" & | |
135 | "</anys_and_only_anys>\n\n"; | |
51fa56b9 | 136 | |
137 | // both the empty array and the omitted field are encoded into this in extended XER | |
138 | // this is always decoded into an omitted field | |
970ed795 EL |
139 | const universal charstring estr_noanys := |
140 | "<anys_and_only_anys/>\n\n"; | |
141 | ||
142 | const anys_and_only_anys marx := { | |
143 | elements := {"<chico/>", "<groucho/>", "<karl></karl>"} | |
144 | } | |
145 | const universal charstring estr_marx := | |
146 | "<anys_and_only_anys>\n" & | |
147 | "\t<chico/>\n" & | |
148 | "\t<groucho/>\n" & | |
149 | "\t<karl></karl>\n" & | |
150 | "</anys_and_only_anys>\n\n"; | |
151 | ||
152 | const universal charstring bstr_marx := | |
153 | "<anys_and_only_anys>\n" & | |
154 | "\t<elements>\n" & | |
155 | "\t\t<UNIVERSAL_CHARSTRING><chico/></UNIVERSAL_CHARSTRING>\n" & | |
156 | "\t\t<UNIVERSAL_CHARSTRING><groucho/></UNIVERSAL_CHARSTRING>\n" & | |
157 | "\t\t<UNIVERSAL_CHARSTRING><karl></karl></UNIVERSAL_CHARSTRING>\n" & | |
158 | "\t</elements>\n" & | |
159 | "</anys_and_only_anys>\n\n"; | |
160 | ||
161 | // When decoding EXER, karl becomes an empty element too (?) | |
162 | const anys_and_only_anys marx_dec := { | |
163 | elements := {"<chico/>", "<groucho/>", "<karl/>"} | |
164 | } | |
165 | ||
166 | testcase encode_only_opt() runs on AE | |
167 | { | |
51fa56b9 | 168 | CHECK_METHOD(bxer_enc_aaoa, noanys_empty, bstr_noanys); |
169 | CHECK_METHOD(exer_enc_aaoa, noanys_empty, estr_noanys); | |
170 | CHECK_METHOD(exer_enc_aaoa, noanys_omit, estr_noanys); | |
970ed795 EL |
171 | |
172 | CHECK_METHOD(bxer_enc_aaoa, marx, bstr_marx); | |
173 | CHECK_METHOD(exer_enc_aaoa, marx, estr_marx); | |
174 | } | |
175 | ||
176 | testcase decode_only_opt() runs on AE | |
177 | { | |
51fa56b9 | 178 | CHECK_DECODE(bxer_dec_aaoa, bstr_noanys, anys_and_only_anys, noanys_empty); |
179 | CHECK_DECODE(exer_dec_aaoa, estr_noanys, anys_and_only_anys, noanys_omit); | |
970ed795 EL |
180 | |
181 | CHECK_DECODE(bxer_dec_aaoa, bstr_marx, anys_and_only_anys, marx); | |
182 | CHECK_DECODE(exer_dec_aaoa, estr_marx, anys_and_only_anys, marx_dec); | |
183 | } | |
184 | ||
185 | control | |
186 | { | |
187 | execute(encode_aeopt()) | |
188 | execute(decode_aeopt()) | |
189 | ||
190 | execute(encode_afopt()) | |
191 | execute(decode_afopt()) | |
192 | ||
193 | // execute(encode_anys()) | |
194 | // execute(decode_anys()) | |
195 | ||
196 | // execute(encode_utanys()) | |
197 | // execute(decode_utanys()) | |
198 | ||
199 | execute(encode_only_opt()) | |
200 | execute(decode_only_opt()) | |
201 | } | |
202 | ||
203 | } | |
204 | with { | |
205 | encode "XML" | |
206 | } | |
207 |