Titan Core Initial Contribution
[deliverable/titan.core.git] / regression_test / XML / EXER-whitepaper / AnyElement.ttcnpp
1 /******************************************************************************
2 * Copyright (c) 2000-2014 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 AnyElement
9 {
10 modulepar boolean AnyElement_verbose := false;
11 #define verbose AnyElement_verbose
12 #include "../macros.ttcnin"
13
14 type component AE {}
15
16 type record AEProduct {
17 charstring name,
18 integer price,
19 universal charstring info
20 }
21 with {
22 variant (info) "anyElement from 'http://www.example.com/A', "
23 "'http://www.example.com/B', unqualified"
24 }
25
26 DECLARE_XER_ENCODERS(AEProduct, ae);
27 DECLARE_EXER_ENCODERS(AEProduct, ae);
28
29 const AEProduct aep := {
30 name := "Trousers",
31 price := 20,
32 info := "<xyz:color xmlns:xyz=""http://www.example.com/A"" available=""true"">red</xyz:color>"
33 }
34
35 const universal charstring str_ae_e :=
36 "<AEProduct>\n" &
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" &
40 "</AEProduct>\n\n";
41
42 const universal charstring str_ae_b :=
43 "<AEProduct>\n" &
44 "\t<name>Trousers</name>\n" &
45 "\t<price>20</price>\n" &
46 "\t<info>&lt;xyz:color xmlns:xyz=&quot;http://www.example.com/A&quot; available=&quot;true&quot;&gt;red&lt;/xyz:color&gt;</info>\n" &
47 "</AEProduct>\n\n";
48
49 testcase encode_ae() runs on AE
50 {
51 CHECK_METHOD(bxer_enc_ae, aep, str_ae_b);
52 CHECK_METHOD(exer_enc_ae, aep, str_ae_e);
53 }
54
55 testcase decode_ae() runs on AE
56 {
57 CHECK_DECODE(bxer_dec_ae, str_ae_b, AEProduct, aep);
58 CHECK_DECODE(exer_dec_ae, str_ae_e, AEProduct, aep);
59 }
60
61 // .- -. -.. / -. --- .-- / ..-. --- .-. / ... --- -- . - .... .. -. --.
62 // -.-. --- -- .--. .-.. . - . .-.. -.-- / -.. .. ..-. ..-. . .-. . -. -
63
64 type record AFProduct {
65 charstring name,
66 integer price,
67 universal charstring info
68 }
69 with {
70 variant (info) "anyElement except 'http://www.example.com/A', 'http://www.example.com/B', unqualified"
71 }
72
73 DECLARE_XER_ENCODERS(AFProduct, af);
74 DECLARE_EXER_ENCODERS(AFProduct, af);
75
76 const AFProduct afp := {
77 name := "Trousers",
78 price := 20,
79 info := "<xyz:color xmlns:xyz=""http://www.example.com/C"" available=""true"">red</xyz:color>"
80 }
81
82 const universal charstring str_af_e :=
83 "<AFProduct>\n" &
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" &
87 "</AFProduct>\n\n";
88
89 const universal charstring str_af_b :=
90 "<AFProduct>\n" &
91 "\t<name>Trousers</name>\n" &
92 "\t<price>20</price>\n" &
93 "\t<info>&lt;xyz:color xmlns:xyz=&quot;http://www.example.com/C&quot; available=&quot;true&quot;&gt;red&lt;/xyz:color&gt;</info>\n" &
94 "</AFProduct>\n\n";
95
96 testcase encode_af() runs on AE
97 {
98 CHECK_METHOD(bxer_enc_af, afp, str_af_b);
99 CHECK_METHOD(exer_enc_af, afp, str_af_e);
100 }
101
102 testcase decode_af() runs on AE
103 {
104 CHECK_DECODE(bxer_dec_af, str_af_b, AFProduct, afp);
105 CHECK_DECODE(exer_dec_af, str_af_e, AFProduct, afp);
106 }
107
108 // .- -. -.. / -. --- .-- / ..-. --- .-. / ... --- -- . - .... .. -. --.
109 // -.-. --- -- .--. .-.. . - . .-.. -.-- / -.. .. ..-. ..-. . .-. . -. -
110
111 type record of universal charstring anys
112 with {
113 variant ([-]) "anyElement from unqualified";
114 }
115
116 DECLARE_XER_ENCODERS(anys, anys);
117 DECLARE_EXER_ENCODERS(anys, anys);
118
119 const anys a3 := {
120 "<captain>You know what you doing</captain>",
121 "<move>all ZIG</move>",
122 "<for>Great justice!</for>"
123 }
124
125 const anys a0 := {}
126
127 const universal charstring estr_a3 :=
128 "<anys>\n" &
129 "\t<captain>You know what you doing</captain>\n" &
130 "\t<move>all ZIG</move>\n" &
131 "\t<for>Great justice!</for>\n" &
132 "</anys>\n\n";
133
134 const universal charstring bstr_a3 :=
135 "<anys>\n" &
136 "\t<UNIVERSAL_CHARSTRING>&lt;captain&gt;You know what you doing&lt;/captain&gt;</UNIVERSAL_CHARSTRING>\n" &
137 "\t<UNIVERSAL_CHARSTRING>&lt;move&gt;all ZIG&lt;/move&gt;</UNIVERSAL_CHARSTRING>\n" &
138 "\t<UNIVERSAL_CHARSTRING>&lt;for&gt;Great justice!&lt;/for&gt;</UNIVERSAL_CHARSTRING>\n" &
139 "</anys>\n\n";
140
141 const universal charstring estr_a0empty :=
142 "<anys/>\n\n";
143
144 const universal charstring bstr_a0empty :=
145 "<anys/>\n\n";
146
147 // not empty-element, for decoding only
148 const universal charstring estr_a0 :=
149 "<anys>\n" &
150 "</anys>\n\n";
151
152 const universal charstring bstr_a0 :=
153 "<anys>\n" &
154 "</anys>\n\n";
155
156
157 testcase encode_anys() runs on AE
158 {
159 CHECK_METHOD(bxer_enc_anys, a3, bstr_a3);
160 CHECK_METHOD(exer_enc_anys, a3, estr_a3);
161
162 CHECK_METHOD(bxer_enc_anys, a0, bstr_a0empty);
163 CHECK_METHOD(exer_enc_anys, a0, estr_a0empty);
164 }
165
166 testcase decode_anys() runs on AE
167 {
168 CHECK_DECODE(bxer_dec_anys, bstr_a3, anys, a3);
169 CHECK_DECODE(exer_dec_anys, estr_a3, anys, a3);
170
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);
175 }
176
177 // .- -. -.. / -. --- .-- / ..-. --- .-. / ... --- -- . - .... .. -. --.
178 // -.-. --- -- .--. .-.. . - . .-.. -.-- / -.. .. ..-. ..-. . .-. . -. -
179
180 type record utanys {
181 record of universal charstring any_list,
182 charstring enemy optional,
183 integer zigs optional
184 }
185 with {
186 variant (any_list) "untagged";
187 variant (any_list[-]) "anyElement from unqualified";
188 }
189
190 DECLARE_XER_ENCODERS(utanys, utanys);
191 DECLARE_EXER_ENCODERS(utanys, utanys);
192
193 const utanys ua3 := { any_list := {
194 "<captain>You know what you doing</captain>",
195 "<move>all ZIG</move>",
196 "<for>Great justice!</for>"
197 },
198 enemy := "CATS",
199 zigs := omit
200 }
201
202 const utanys ua7 := { any_list := {
203 "<all/>", "<your/>", "<base/>", "<are/>", "<belong/>", "<to/>", "<us/>"
204 },
205 enemy := "CATS",
206 zigs := omit
207 }
208
209 const utanys ua0 := {{}, omit, omit}
210
211 const universal charstring estr_ua3 :=
212 "<utanys>\n" &
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" &
217 "</utanys>\n\n";
218
219 const universal charstring estr_ua7 :=
220 "<utanys>\n" &
221 "\t<all/>\n" &
222 "\t<your/>\n" &
223 "\t<base/>\n" &
224 "\t<are/>\n" &
225 "\t<belong/>\n" &
226 "\t<to/>\n" &
227 "\t<us/>\n" &
228 "\t<enemy>CATS</enemy>\n" &
229 "</utanys>\n\n";
230
231 const universal charstring bstr_ua3 :=
232 "<utanys>\n" &
233 "\t<any_list>\n" &
234 "\t\t<UNIVERSAL_CHARSTRING>&lt;captain&gt;You know what you doing&lt;/captain&gt;</UNIVERSAL_CHARSTRING>\n" &
235 "\t\t<UNIVERSAL_CHARSTRING>&lt;move&gt;all ZIG&lt;/move&gt;</UNIVERSAL_CHARSTRING>\n" &
236 "\t\t<UNIVERSAL_CHARSTRING>&lt;for&gt;Great justice!&lt;/for&gt;</UNIVERSAL_CHARSTRING>\n" &
237 "\t</any_list>\n" &
238 "\t<enemy>CATS</enemy>\n" &
239 "</utanys>\n\n";
240
241 const universal charstring estr_ua0empty :=
242 "<utanys/>\n\n";
243
244 const universal charstring bstr_ua0empty :=
245 "<utanys>\n" &
246 "\t<any_list/>\n" &
247 // "\t<enemy/>\n" &
248 "</utanys>\n\n";
249
250 // not empty-element, for decoding only
251 const universal charstring estr_ua0 :=
252 "<utanys>\n" &
253 "</utanys>\n\n";
254
255 const universal charstring bstr_ua0 :=
256 "<utanys>\n" &
257 "\t<any_list>\n" &
258 "\t</any_list>\n" &
259 "</utanys>\n\n";
260
261
262 testcase encode_utanys() runs on AE
263 {
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);
267
268 CHECK_METHOD(bxer_enc_utanys, ua0, bstr_ua0empty);
269 CHECK_METHOD(exer_enc_utanys, ua0, estr_ua0empty);
270 }
271
272 testcase decode_utanys() runs on AE
273 {
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);
277
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);
282
283 }
284
285 /* * * * * * * * * * * * */
286
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
290 }
291 with {
292 variant (elements) "anyElement"
293 }
294
295 DECLARE_XER_ENCODERS(anys_and_only_anys, aaoa);
296 DECLARE_EXER_ENCODERS(anys_and_only_anys, aaoa);
297
298 const anys_and_only_anys noanys := { elements := {} }
299 const universal charstring bstr_noanys :=
300 "<anys_and_only_anys>\n" &
301 "\t<elements/>\n" &
302 "</anys_and_only_anys>\n\n";
303 const universal charstring estr_noanys :=
304 "<anys_and_only_anys/>\n\n";
305
306 const anys_and_only_anys marx := {
307 elements := {"<chico/>", "<groucho/>", "<karl></karl>"}
308 }
309 const universal charstring estr_marx :=
310 "<anys_and_only_anys>\n" &
311 "\t<chico/>\n" &
312 "\t<groucho/>\n" &
313 "\t<karl></karl>\n" &
314 "</anys_and_only_anys>\n\n";
315
316 const universal charstring bstr_marx :=
317 "<anys_and_only_anys>\n" &
318 "\t<elements>\n" &
319 "\t\t<UNIVERSAL_CHARSTRING>&lt;chico/&gt;</UNIVERSAL_CHARSTRING>\n" &
320 "\t\t<UNIVERSAL_CHARSTRING>&lt;groucho/&gt;</UNIVERSAL_CHARSTRING>\n" &
321 "\t\t<UNIVERSAL_CHARSTRING>&lt;karl&gt;&lt;/karl&gt;</UNIVERSAL_CHARSTRING>\n" &
322 "\t</elements>\n" &
323 "</anys_and_only_anys>\n\n";
324
325 // When decoding EXER, karl becomes an empty element too (?)
326 const anys_and_only_anys marx_dec := {
327 elements := {"<chico/>", "<groucho/>", "<karl/>"}
328 }
329
330 testcase encode_only() runs on AE
331 {
332 CHECK_METHOD(bxer_enc_aaoa, noanys, bstr_noanys);
333 CHECK_METHOD(exer_enc_aaoa, noanys, estr_noanys);
334
335 CHECK_METHOD(bxer_enc_aaoa, marx, bstr_marx);
336 CHECK_METHOD(exer_enc_aaoa, marx, estr_marx);
337 }
338
339 testcase decode_only() runs on AE
340 {
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);
343
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);
346 }
347
348 control
349 {
350 execute(encode_ae())
351 execute(decode_ae())
352
353 execute(encode_af())
354 execute(decode_af())
355
356 execute(encode_anys())
357 execute(decode_anys())
358
359 execute(encode_utanys())
360 execute(decode_utanys())
361
362 execute(encode_only())
363 execute(decode_only())
364 }
365
366 }
367 with {
368 encode "XML"
369 }
This page took 0.039554 seconds and 6 git commands to generate.