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 ******************************************************************************/
9 modulepar boolean Qname_verbose := false;
10 #define verbose Qname_verbose
11 #include "../macros.ttcnin"
15 type record QProductName {
16 universal charstring uri optional,
17 universal charstring name
23 type record QProduct {
28 variant "namespace as 'http://www.example.com' prefix 'exm'";
32 DECLARE_XER_ENCODERS(QProduct, prodQ);
33 DECLARE_EXER_ENCODERS(QProduct, prodQ);
35 // Example when the URI is present and different from the target namespace
36 const QProduct table := {
38 uri := "http://www.furniture.com",
44 const universal charstring str_table_b :=
47 "\t\t<uri>http://www.furniture.com</uri>\n" &
48 "\t\t<name>table</name>\n" &
50 "\t<cost>199.950000</cost>\n" &
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" &
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" &
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" &
78 // Example when the URI is missing
79 const QProduct chair := {
87 const universal charstring str_chair_b :=
90 "\t\t<name>chair</name>\n" &
92 "\t<cost>89.990000</cost>\n" &
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" &
103 // Example when the URI is present but matches the target namespace
104 const QProduct feather := {
106 uri := "http://www.example.com",
112 const universal charstring str_feather_b :=
115 "\t\t<uri>http://www.example.com</uri>\n" &
116 "\t\t<name>feather</name>\n" &
118 "\t<cost>0.100000</cost>\n" &
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" &
128 // ^__ this is what we do
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" &
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);
142 CHECK_METHOD(bxer_enc_prodQ, chair, str_chair_b);
143 CHECK_METHOD(exer_enc_prodQ, chair, str_chair_e);
145 CHECK_METHOD(bxer_enc_prodQ, feather, str_feather_b);
146 //optimization not performed
147 CHECK_METHOD(exer_enc_prodQ, feather, str_feather_e);
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);
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);
159 CHECK_DECODE(exer_dec_prodQ, str_chair_e , QProduct, chair);
161 CHECK_DECODE(exer_dec_prodQ, str_feather_e , QProduct, feather);
162 CHECK_DECODE(exer_dec_prodQ, str_feather_e_correct, QProduct, feather);
165 /* * * * * * * * * * * * * * * * * * * * * * * * * * */
167 type record AProduct {
172 variant "namespace as 'http://www.example.com' prefix 'exm'";
174 variant (name) "attribute"
177 DECLARE_XER_ENCODERS(AProduct, prodA);
178 DECLARE_EXER_ENCODERS(AProduct, prodA);
180 // Example when the URI is present and different from the target namespace
181 const AProduct atable := {
183 uri := "http://www.furniture.com",
189 const universal charstring str_atable_b :=
192 "\t\t<uri>http://www.furniture.com</uri>\n" &
193 "\t\t<name>table</name>\n" &
195 "\t<cost>199.990000</cost>\n" &
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" &
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" &
214 // Example when the URI is missing
215 const AProduct achair := {
223 const universal charstring str_achair_b :=
226 "\t\t<name>chair</name>\n" &
228 "\t<cost>69.990000</cost>\n" &
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" &
238 // Example when the URI is present but matches the target namespace
239 const AProduct afeather := {
241 uri := "http://www.example.com",
247 const universal charstring str_afeather_b :=
250 "\t\t<uri>http://www.example.com</uri>\n" &
251 "\t\t<name>feather</name>\n" &
253 "\t<cost>0.111000</cost>\n" &
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" &
262 // ^__ this is what we do
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" &
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);
276 CHECK_METHOD(bxer_enc_prodA, achair, str_achair_b);
277 CHECK_METHOD(exer_enc_prodA, achair, str_achair_e);
279 CHECK_METHOD(bxer_enc_prodA, afeather, str_afeather_b);
280 CHECK_METHOD(exer_enc_prodA, afeather, str_afeather_e);
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);
288 CHECK_DECODE(exer_dec_prodA, str_atable_e, AProduct, atable);
289 CHECK_DECODE(exer_dec_prodA, str_atable_e_xml, AProduct, atable);
291 CHECK_DECODE(exer_dec_prodA, str_achair_e, AProduct, achair);
293 CHECK_DECODE(exer_dec_prodA, str_afeather_e, AProduct, afeather);
294 CHECK_DECODE(exer_dec_prodA, str_afeather_e_correct, AProduct, afeather);