Sync with 5.4.1
[deliverable/titan.core.git] / regression_test / XML / EXER-whitepaper / AnyElementOptional.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 AnyElementOptional
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 optional
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_aeopt() 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_aeopt() 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 optional
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_afopt() 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_afopt() 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 // 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
114 }
115 with {
116 variant (elements) "anyElement"
117 }
118
119 DECLARE_XER_ENCODERS(anys_and_only_anys, aaoa);
120 DECLARE_EXER_ENCODERS(anys_and_only_anys, aaoa);
121
122 const anys_and_only_anys noanys_empty := { elements := {} }
123 const anys_and_only_anys noanys_omit := { elements := omit }
124
125 // the empty array is encoded into this in basic XER
126 const universal charstring bstr_noanys :=
127 "<anys_and_only_anys>\n" &
128 "\t<elements/>\n" &
129 "</anys_and_only_anys>\n\n";
130
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";
135
136 const anys_and_only_anys marx := {
137 elements := {"<chico/>", "<groucho/>", "<karl></karl>"}
138 }
139 const universal charstring estr_marx :=
140 "<anys_and_only_anys>\n" &
141 "\t<chico/>\n" &
142 "\t<groucho/>\n" &
143 "\t<karl></karl>\n" &
144 "</anys_and_only_anys>\n\n";
145
146 const universal charstring bstr_marx :=
147 "<anys_and_only_anys>\n" &
148 "\t<elements>\n" &
149 "\t\t<UNIVERSAL_CHARSTRING>&lt;chico/&gt;</UNIVERSAL_CHARSTRING>\n" &
150 "\t\t<UNIVERSAL_CHARSTRING>&lt;groucho/&gt;</UNIVERSAL_CHARSTRING>\n" &
151 "\t\t<UNIVERSAL_CHARSTRING>&lt;karl&gt;&lt;/karl&gt;</UNIVERSAL_CHARSTRING>\n" &
152 "\t</elements>\n" &
153 "</anys_and_only_anys>\n\n";
154
155 // When decoding EXER, karl becomes an empty element too (?)
156 const anys_and_only_anys marx_dec := {
157 elements := {"<chico/>", "<groucho/>", "<karl/>"}
158 }
159
160 testcase encode_only_opt() runs on AE
161 {
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);
165
166 CHECK_METHOD(bxer_enc_aaoa, marx, bstr_marx);
167 CHECK_METHOD(exer_enc_aaoa, marx, estr_marx);
168 }
169
170 testcase decode_only_opt() runs on AE
171 {
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);
174
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);
177 }
178
179 control
180 {
181 execute(encode_aeopt())
182 execute(decode_aeopt())
183
184 execute(encode_afopt())
185 execute(decode_afopt())
186
187 // execute(encode_anys())
188 // execute(decode_anys())
189
190 // execute(encode_utanys())
191 // execute(decode_utanys())
192
193 execute(encode_only_opt())
194 execute(decode_only_opt())
195 }
196
197 }
198 with {
199 encode "XML"
200 }
201
This page took 0.048854 seconds and 5 git commands to generate.