Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / XML / EXER-whitepaper / Qname.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 Qname {
9 modulepar boolean Qname_verbose := false;
10 #define verbose Qname_verbose
11 #include "../macros.ttcnin"
12
13 type component Q {}
14
15 type record QProductName {
16 universal charstring uri optional,
17 universal charstring name
18 }
19 with {
20 variant "XSD:QName"
21 }
22
23 type record QProduct {
24 QProductName prname,
25 float cost
26 }
27 with {
28 variant "namespace as 'http://www.example.com' prefix 'exm'";
29 variant "element";
30 }
31
32 DECLARE_XER_ENCODERS(QProduct, prodQ);
33 DECLARE_EXER_ENCODERS(QProduct, prodQ);
34
35 // Example when the URI is present and different from the target namespace
36 const QProduct table := {
37 prname := {
38 uri := "http://www.furniture.com",
39 name := "table"
40 },
41 cost := 199.95
42 }
43
44 const universal charstring str_table_b :=
45 "<QProduct>\n" &
46 "\t<prname>\n" &
47 "\t\t<uri>http://www.furniture.com</uri>\n" &
48 "\t\t<name>table</name>\n" &
49 "\t</prname>\n" &
50 "\t<cost>199.950000</cost>\n" &
51 "</QProduct>\n" &
52 "\n";
53
54 const universal charstring str_table_e_input :=
55 "<exm:QProduct xmlns:exm='http://www.example.com'>\n" &
56 "\t<prname xmlns:b0='http://www.furniture.com'>" &
57 "<!-- Here's a comment to try to confuse the parser -->b0:table</prname>\n" &
58 "\t<cost>199.950000</cost>\n" &
59 "</exm:QProduct>\n" &
60 "\n";
61
62 const universal charstring str_table_e :=
63 "<exm:QProduct xmlns:exm='http://www.example.com'>\n" &
64 "\t<prname xmlns:b0='http://www.furniture.com'>b0:table</prname>\n" &
65 "\t<cost>199.950000</cost>\n" &
66 "</exm:QProduct>\n" &
67 "\n";
68
69 // Here's a superfluous namespace, which would confuse the old decoder
70 const universal charstring str_table_e_xml :=
71 "<exm:QProduct xmlns:exm='http://www.example.com'>\n" &
72 "\t<prname xmlns:xml='http://www.w3.org/XML/1998/namespace' xmlns:b0='http://www.furniture.com'>b0:table</prname>\n" &
73 "\t<cost>199.950000</cost>\n" &
74 "</exm:QProduct>\n" &
75 "\n";
76
77
78 // Example when the URI is missing
79 const QProduct chair := {
80 prname := {
81 uri := omit,
82 name := "chair"
83 },
84 cost := 89.99
85 }
86
87 const universal charstring str_chair_b :=
88 "<QProduct>\n" &
89 "\t<prname>\n" &
90 "\t\t<name>chair</name>\n" &
91 "\t</prname>\n" &
92 "\t<cost>89.990000</cost>\n" &
93 "</QProduct>\n" &
94 "\n";
95
96 const universal charstring str_chair_e :=
97 "<exm:QProduct xmlns:exm='http://www.example.com'>\n" &
98 "\t<prname>chair</prname>\n" &
99 "\t<cost>89.990000</cost>\n" &
100 "</exm:QProduct>\n" &
101 "\n";
102
103 // Example when the URI is present but matches the target namespace
104 const QProduct feather := {
105 prname := {
106 uri := "http://www.example.com",
107 name := "feather"
108 },
109 cost := 0.1
110 }
111
112 const universal charstring str_feather_b :=
113 "<QProduct>\n" &
114 "\t<prname>\n" &
115 "\t\t<uri>http://www.example.com</uri>\n" &
116 "\t\t<name>feather</name>\n" &
117 "\t</prname>\n" &
118 "\t<cost>0.100000</cost>\n" &
119 "</QProduct>\n" &
120 "\n";
121
122 const universal charstring str_feather_e :=
123 "<exm:QProduct xmlns:exm='http://www.example.com'>\n" &
124 "\t<prname xmlns:b0='http://www.example.com'>b0:feather</prname>\n" &
125 "\t<cost>0.100000</cost>\n" &
126 "</exm:QProduct>\n" &
127 "\n";
128 // ^__ this is what we do
129 //
130 // v-- this is what we should do
131 const universal charstring str_feather_e_correct :=
132 "<exm:QProduct xmlns:exm='http://www.example.com'>\n" &
133 "\t<prname>exm:feather</prname>\n" &
134 "\t<cost>0.100000</cost>\n" &
135 "</exm:QProduct>\n" &
136 "\n";
137
138 testcase enc_qn() runs on Q {
139 CHECK_METHOD(bxer_enc_prodQ, table, str_table_b);
140 CHECK_METHOD(exer_enc_prodQ, table, str_table_e);
141
142 CHECK_METHOD(bxer_enc_prodQ, chair, str_chair_b);
143 CHECK_METHOD(exer_enc_prodQ, chair, str_chair_e);
144
145 CHECK_METHOD(bxer_enc_prodQ, feather, str_feather_b);
146 //optimization not performed
147 CHECK_METHOD(exer_enc_prodQ, feather, str_feather_e);
148 }
149
150 testcase dec_qn() runs on Q {
151 CHECK_DECODE(bxer_dec_prodQ, str_table_b , QProduct, table);
152 CHECK_DECODE(bxer_dec_prodQ, str_chair_b , QProduct, chair);
153 CHECK_DECODE(bxer_dec_prodQ, str_feather_b, QProduct, feather);
154
155 CHECK_DECODE(exer_dec_prodQ, str_table_e , QProduct, table);
156 CHECK_DECODE(exer_dec_prodQ, str_table_e_input , QProduct, table);
157 CHECK_DECODE(exer_dec_prodQ, str_table_e_xml , QProduct, table);
158
159 CHECK_DECODE(exer_dec_prodQ, str_chair_e , QProduct, chair);
160
161 CHECK_DECODE(exer_dec_prodQ, str_feather_e , QProduct, feather);
162 CHECK_DECODE(exer_dec_prodQ, str_feather_e_correct, QProduct, feather);
163 }
164
165 /* * * * * * * * * * * * * * * * * * * * * * * * * * */
166
167 type record AProduct {
168 QProductName name,
169 float cost
170 }
171 with {
172 variant "namespace as 'http://www.example.com' prefix 'exm'";
173 variant "element";
174 variant (name) "attribute"
175 }
176
177 DECLARE_XER_ENCODERS(AProduct, prodA);
178 DECLARE_EXER_ENCODERS(AProduct, prodA);
179
180 // Example when the URI is present and different from the target namespace
181 const AProduct atable := {
182 name := {
183 uri := "http://www.furniture.com",
184 name := "table"
185 },
186 cost := 199.99
187 }
188
189 const universal charstring str_atable_b :=
190 "<AProduct>\n" &
191 "\t<name>\n" &
192 "\t\t<uri>http://www.furniture.com</uri>\n" &
193 "\t\t<name>table</name>\n" &
194 "\t</name>\n" &
195 "\t<cost>199.990000</cost>\n" &
196 "</AProduct>\n" &
197 "\n";
198
199 const universal charstring str_atable_e :=
200 "<exm:AProduct xmlns:exm='http://www.example.com' xmlns:b0='http://www.furniture.com' name='b0:table'>\n" &
201 "\t<cost>199.990000</cost>\n" &
202 "</exm:AProduct>\n" &
203 "\n";
204
205 // A spurious but harmless extra namespace
206 const universal charstring str_atable_e_xml :=
207 "<exm:AProduct xmlns:xml='http://www.w3.org/XML/1998/namespace'" &
208 " xmlns:exm='http://www.example.com' xmlns:b0='http://www.furniture.com' name='b0:table'>\n" &
209 "\t<cost>199.990000</cost>\n" &
210 "</exm:AProduct>\n" &
211 "\n";
212
213
214 // Example when the URI is missing
215 const AProduct achair := {
216 name := {
217 uri := omit,
218 name := "chair"
219 },
220 cost := 69.99
221 }
222
223 const universal charstring str_achair_b :=
224 "<AProduct>\n" &
225 "\t<name>\n" &
226 "\t\t<name>chair</name>\n" &
227 "\t</name>\n" &
228 "\t<cost>69.990000</cost>\n" &
229 "</AProduct>\n" &
230 "\n";
231
232 const universal charstring str_achair_e :=
233 "<exm:AProduct xmlns:exm='http://www.example.com' name='chair'>\n" &
234 "\t<cost>69.990000</cost>\n" &
235 "</exm:AProduct>\n" &
236 "\n";
237
238 // Example when the URI is present but matches the target namespace
239 const AProduct afeather := {
240 name := {
241 uri := "http://www.example.com",
242 name := "feather"
243 },
244 cost := 0.111
245 }
246
247 const universal charstring str_afeather_b :=
248 "<AProduct>\n" &
249 "\t<name>\n" &
250 "\t\t<uri>http://www.example.com</uri>\n" &
251 "\t\t<name>feather</name>\n" &
252 "\t</name>\n" &
253 "\t<cost>0.111000</cost>\n" &
254 "</AProduct>\n" &
255 "\n";
256
257 const universal charstring str_afeather_e :=
258 "<exm:AProduct xmlns:exm='http://www.example.com' xmlns:b0='http://www.example.com' name='b0:feather'>\n" &
259 "\t<cost>0.111000</cost>\n" &
260 "</exm:AProduct>\n" &
261 "\n";
262 // ^__ this is what we do
263 //
264 // v-- this is what we should do
265 const universal charstring str_afeather_e_correct :=
266 "<exm:AProduct xmlns:exm='http://www.example.com' name='exm:feather'>\n" &
267 "\t<cost>0.111000</cost>\n" &
268 "</exm:AProduct>\n" &
269 "\n";
270
271
272 testcase enc_qn_a() runs on Q {
273 CHECK_METHOD(bxer_enc_prodA, atable, str_atable_b);
274 CHECK_METHOD(exer_enc_prodA, atable, str_atable_e);
275
276 CHECK_METHOD(bxer_enc_prodA, achair, str_achair_b);
277 CHECK_METHOD(exer_enc_prodA, achair, str_achair_e);
278
279 CHECK_METHOD(bxer_enc_prodA, afeather, str_afeather_b);
280 CHECK_METHOD(exer_enc_prodA, afeather, str_afeather_e);
281 }
282
283 testcase dec_qn_a() runs on Q {
284 CHECK_DECODE(bxer_dec_prodA, str_atable_b, AProduct, atable);
285 CHECK_DECODE(bxer_dec_prodA, str_achair_b, AProduct, achair);
286 CHECK_DECODE(bxer_dec_prodA, str_afeather_b, AProduct, afeather);
287
288 CHECK_DECODE(exer_dec_prodA, str_atable_e, AProduct, atable);
289 CHECK_DECODE(exer_dec_prodA, str_atable_e_xml, AProduct, atable);
290
291 CHECK_DECODE(exer_dec_prodA, str_achair_e, AProduct, achair);
292
293 CHECK_DECODE(exer_dec_prodA, str_afeather_e, AProduct, afeather);
294 CHECK_DECODE(exer_dec_prodA, str_afeather_e_correct, AProduct, afeather);
295 }
296
297 control {
298 execute(enc_qn());
299 execute(dec_qn());
300
301 execute(enc_qn_a());
302 execute(dec_qn_a());
303 }
304
305 }
306 with {
307 encode "XML";
308
309 }
This page took 0.039366 seconds and 6 git commands to generate.