Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / XML / TTCNandXML / NamespaceTest.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 NamespaceTest {
9
10 import from NamespaceDef all;
11
12 modulepar boolean NamespaceTest_verbose := false;
13 #define verbose NamespaceTest_verbose
14 #include "../macros.ttcnin"
15
16 type component water {}
17
18 DECLARE_XER_ENCODERS(MyRecordType, rec);
19 DECLARE_EXER_ENCODERS(MyRecordType, rec);
20
21 const universal charstring etalon := // for E-XER
22 "<ns0:MyRecordType xmlns:ns0=\'http://www.example.org/\' xmlns:ns1=\'http://www.example.org/example1\'>\n" &
23 "\t<ns1:field1>3</ns1:field1>\n" &
24 "\t<ns0:field2>four</ns0:field2>\n" &
25 "</ns0:MyRecordType>\n\n";
26
27 /* and not like this, with the namespace declaration for nsl in the field1 tag:
28
29 //<?xml version="1.0" encoding="UTF-8"?>
30 "<ns0:MyRecordType xmlns:ns0=http://www.example.org/>\n" &
31 "\t<ns1:field1 xmlns:ns1=http://www.example.org/example1>3</ns1:field1>\n" &
32 "\t<ns0:field2>four</ ns0:field2>\n" &
33 "</ns0:MyRecordType>\n\n";
34 */
35
36 // MyRecordType requires a namespace, decoding this should fail
37 const universal charstring etalon_nons := // for E-XER
38 "<MyRecordType xmlns:ns0=\'http://www.example.org/\' xmlns:ns1=\'http://www.example.org/example1\'>\n" &
39 "\t<ns1:field1>3</ns1:field1>\n" &
40 "\t<ns0:field2>four</ns0:field2>\n" &
41 "</MyRecordType>\n\n";
42
43
44 const universal charstring etalon_b := // for B-XER
45 "<MyRecordType>\n" &
46 "\t<field1>3</field1>\n" &
47 "\t<field2>four</field2>\n" &
48 "</MyRecordType>\n\n";
49
50 const universal charstring etalon_c := // for C-XER (no indenting)
51 "<MyRecordType>" &
52 "<field1>3</field1>" &
53 "<field2>four</field2>" &
54 "</MyRecordType>\n";
55
56 testcase enc_ns() runs on water
57 {
58 CHECK_METHOD(bxer_enc_rec, valueof(NamespaceDef.MyTemplate), etalon_b);
59 CHECK_METHOD(cxer_enc_rec, valueof(NamespaceDef.MyTemplate), etalon_c);
60 CHECK_METHOD(exer_enc_rec, valueof(NamespaceDef.MyTemplate), etalon);
61 }
62
63 /*
64 template charstring etalon_b := pattern
65 "<MyRecordType>\n#(,1)" &
66 "\t#(,1)<field1>3</field1>\n#(,1)" &
67 "\t#(,1)<field2>four</field2>\n#(,1)" &
68 "</MyRecordType>\n#(,1)\n";
69
70 testcase enc_ns() runs on water
71 {
72 CHECK_METHOD(bxer_enc_rec, valueof(NamespaceDef.MyTemplate), etalon_b);
73 CHECK_METHOD(cxer_enc_rec, valueof(NamespaceDef.MyTemplate), etalon_b);
74 CHECK_METHOD(exer_enc_rec, valueof(NamespaceDef.MyTemplate), etalon);
75 }
76
77 */
78
79 // Alternative representation: different prefix for the same namespace.
80 // The prefix is just a shorthand and can be anything. This should be decoded
81 // exactly the same as "etalon". Regression test for HK86210.
82 const universal charstring etalon_2 :=
83 "<myns:MyRecordType xmlns:myns=\'http://www.example.org/\' xmlns:ns1=\'http://www.example.org/example1\'>\n" &
84 "\t<ns1:field1>3</ns1:field1>\n" &
85 "\t<myns:field2>four</myns:field2>\n" &
86 "</myns:MyRecordType>\n\n";
87
88
89
90 testcase dec_ns() runs on water
91 {
92 var MyRecordType expected := valueof(NamespaceDef.MyTemplate);
93
94 CHECK_DECODE(bxer_dec_rec, etalon_b, MyRecordType, expected);
95 CHECK_DECODE(cxer_dec_rec, etalon_c, MyRecordType, expected);
96 CHECK_DECODE(exer_dec_rec, etalon , MyRecordType, expected);
97
98 CHECK_DECODE(exer_dec_rec, etalon_2, MyRecordType, expected);
99 //this is expected to fail: CHECK_DECODE(exer_dec_rec, etalon_nons, MyRecordType, expected);
100 }
101
102 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
103
104 type record of MyRecordType ManyRecords;
105
106 DECLARE_XER_ENCODERS(ManyRecords, recs);
107 DECLARE_EXER_ENCODERS(ManyRecords, recs);
108
109 /*
110 const ManyRecords recs := {
111 valueof(MyTemplate),
112 // semantic error above: Reference to a constant value was expected instead of template `@NamespaceDef.MyTemplate'
113 // probably because of const
114 { 2, "second" }
115 }
116 */
117
118 const ManyRecords myrecs := {
119 { 3, "four" },
120 { 2, "second" }
121 }
122
123
124 const universal charstring str_recs_b :=
125 "<ManyRecords>\n" &
126 "\t<MyRecordType>\n" &
127 "\t\t<field1>3</field1>\n" &
128 "\t\t<field2>four</field2>\n" &
129 "\t</MyRecordType>\n" &
130 "\t<MyRecordType>\n" &
131 "\t\t<field1>2</field1>\n" &
132 "\t\t<field2>second</field2>\n" &
133 "\t</MyRecordType>\n" &
134 "</ManyRecords>\n\n";
135
136 const universal charstring str_recs_e :=
137 "<ManyRecords xmlns:ns0=\'http://www.example.org/\' xmlns:ns1=\'http://www.example.org/example1\'>\n" &
138 "\t<ns0:MyRecordType>\n" &
139 "\t\t<ns1:field1>3</ns1:field1>\n" &
140 "\t\t<ns0:field2>four</ns0:field2>\n" &
141 "\t</ns0:MyRecordType>\n" &
142 "\t<ns0:MyRecordType>\n" &
143 "\t\t<ns1:field1>2</ns1:field1>\n" &
144 "\t\t<ns0:field2>second</ns0:field2>\n" &
145 "\t</ns0:MyRecordType>\n" &
146 "</ManyRecords>\n\n";
147
148 const ManyRecords norecs := {}
149
150 const universal charstring str_norecs_b :=
151 "<ManyRecords/>\n\n";
152
153 const universal charstring str_norecs_e :=
154 "<ManyRecords/>\n\n";
155 //"<ManyRecords xmlns:ns0=\'http://www.example.org/\' xmlns:ns1=\'http://www.example.org/example1\'/>\n\n";
156
157 // NsRecords is an imported "record of MyRecordType"
158 DECLARE_XER_ENCODERS(NsRecords, nsrecs);
159 DECLARE_EXER_ENCODERS(NsRecords, nsrecs);
160
161 const NsRecords /* the imported record-of */ nsrecs := {
162 { 3, "four" },
163 { 2, "second" }
164 }
165
166 const universal charstring str_nsrecs_b :=
167 "<NsRecords>\n" &
168 "\t<MyRecordType>\n" &
169 "\t\t<field1>3</field1>\n" &
170 "\t\t<field2>four</field2>\n" &
171 "\t</MyRecordType>\n" &
172 "\t<MyRecordType>\n" &
173 "\t\t<field1>2</field1>\n" &
174 "\t\t<field2>second</field2>\n" &
175 "\t</MyRecordType>\n" &
176 "</NsRecords>\n\n";
177
178
179 const universal charstring str_nsrecs_e :=
180 "<ns0:NsRecords xmlns:ns0=\'http://www.example.org/\' xmlns:ns1=\'http://www.example.org/example1\'>\n" &
181 "\t<ns0:MyRecordType>\n" &
182 "\t\t<ns1:field1>3</ns1:field1>\n" &
183 "\t\t<ns0:field2>four</ns0:field2>\n" &
184 "\t</ns0:MyRecordType>\n" &
185 "\t<ns0:MyRecordType>\n" &
186 "\t\t<ns1:field1>2</ns1:field1>\n" &
187 "\t\t<ns0:field2>second</ns0:field2>\n" &
188 "\t</ns0:MyRecordType>\n" &
189 "</ns0:NsRecords>\n\n";
190
191
192 const NsRecords nsnorecs := {}
193
194 const universal charstring str_nsnorecs_b :=
195 "<NsRecords/>\n\n";
196
197 const universal charstring str_nsnorecs_e :=
198 "<ns0:NsRecords xmlns:ns0=\'http://www.example.org/\'/>\n\n";
199
200 testcase enc_recs() runs on water
201 {
202 CHECK_METHOD(bxer_enc_recs, myrecs, str_recs_b);
203 CHECK_METHOD(exer_enc_recs, myrecs, str_recs_e);
204
205 CHECK_METHOD(bxer_enc_recs, norecs, str_norecs_b);
206 CHECK_METHOD(exer_enc_recs, norecs, str_norecs_e);
207
208 CHECK_METHOD(bxer_enc_nsrecs, nsrecs, str_nsrecs_b);
209 CHECK_METHOD(exer_enc_nsrecs, nsrecs, str_nsrecs_e);
210
211 CHECK_METHOD(bxer_enc_nsrecs, nsnorecs, str_nsnorecs_b);
212 CHECK_METHOD(exer_enc_nsrecs, nsnorecs, str_nsnorecs_e);
213 }
214
215 testcase dec_recs() runs on water
216 {
217
218 CHECK_DECODE(bxer_dec_recs, str_recs_b, ManyRecords, myrecs);
219 CHECK_DECODE(exer_dec_recs, str_recs_e, ManyRecords, myrecs);
220
221 CHECK_DECODE(bxer_dec_recs, str_norecs_b, ManyRecords, norecs);
222 CHECK_DECODE(exer_dec_recs, str_norecs_e, ManyRecords, norecs);
223
224 CHECK_DECODE(bxer_dec_nsrecs, str_nsrecs_b, NsRecords, nsrecs);
225 CHECK_DECODE(exer_dec_nsrecs, str_nsrecs_e, NsRecords, nsrecs);
226
227 CHECK_DECODE(bxer_dec_nsrecs, str_nsnorecs_b, NsRecords, nsnorecs);
228 CHECK_DECODE(exer_dec_nsrecs, str_nsnorecs_e, NsRecords, nsnorecs);
229 }
230
231 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
232 // Check that alternatives are correctly identified based on name+namespace,
233 // not just name alone (i.e. if names match but the namespace is empty => mismatch)
234
235 type charstring MyOtherType
236 with { variant "name as 'MyRecordType'" }
237
238 type union MyUnionType {
239 MyRecordType myrecord,
240 MyOtherType spy
241 };
242
243 DECLARE_XER_ENCODERS(MyUnionType, u);
244 DECLARE_EXER_ENCODERS(MyUnionType, u);
245
246 const MyUnionType uni_rec := {
247 myrecord := { 3, "four" }
248 }
249
250 const universal charstring bstr_unirec :=
251 "<MyUnionType>\n" &
252 "\t<myrecord>\n" &
253 "\t\t<field1>3</field1>\n" &
254 "\t\t<field2>four</field2>\n" &
255 "\t</myrecord>\n" &
256 "</MyUnionType>\n\n";
257
258 const universal charstring estr_unirec :=
259 "<MyUnionType xmlns:ns0='http://www.example.org/' xmlns:ns1='http://www.example.org/example1'>\n" &
260 "\t<ns0:myrecord>\n" &
261 "\t\t<ns1:field1>3</ns1:field1>\n" &
262 "\t\t<ns0:field2>four</ns0:field2>\n" &
263 "\t</ns0:myrecord>\n" &
264 "</MyUnionType>\n\n";
265
266 // Same thing with different namespace prefix (and order) (decoding only)
267 const universal charstring estr_unirec_2 :=
268 "<MyUnionType xmlns:ns-zero='http://www.example.org/' xmlns:ns-one='http://www.example.org/example1'>\n" &
269 "\t<ns-zero:myrecord>\n" &
270 "\t\t<ns-one:field1>3</ns-one:field1>\n" &
271 "\t\t<ns-zero:field2>four</ns-zero:field2>\n" &
272 "\t</ns-zero:myrecord>\n" &
273 "</MyUnionType>\n\n";
274
275 const MyUnionType uni_str := {
276 spy := "I spy with my little eye"
277 }
278
279 const universal charstring bstr_unistr :=
280 "<MyUnionType>\n" &
281 "\t<spy>I spy with my little eye</spy>\n" &
282 "</MyUnionType>\n\n";
283
284 const universal charstring estr_unistr :=
285 "<MyUnionType>\n" &
286 "\t<spy>I spy with my little eye</spy>\n" &
287 "</MyUnionType>\n\n";
288
289 testcase enc_union() runs on water
290 {
291 CHECK_METHOD(bxer_enc_u, uni_rec, bstr_unirec);
292 CHECK_METHOD(exer_enc_u, uni_rec, estr_unirec);
293
294 CHECK_METHOD(bxer_enc_u, uni_str, bstr_unistr);
295 CHECK_METHOD(exer_enc_u, uni_str, estr_unistr);
296 }
297
298 testcase dec_union() runs on water
299 {
300 CHECK_DECODE(bxer_dec_u, bstr_unirec, MyUnionType, uni_rec);
301 CHECK_DECODE(exer_dec_u, estr_unirec, MyUnionType, uni_rec);
302 CHECK_DECODE(exer_dec_u, estr_unirec_2, MyUnionType, uni_rec);
303
304 CHECK_DECODE(bxer_dec_u, bstr_unistr, MyUnionType, uni_str);
305 CHECK_DECODE(exer_dec_u, estr_unistr, MyUnionType, uni_str);
306 // No alternative for the spy
307 }
308
309 control {
310 execute(enc_ns());
311 execute(dec_ns());
312
313 execute(enc_recs());
314 execute(dec_recs());
315
316 execute(enc_union());
317 execute(dec_union());
318 }
319
320 }
321 with { encode "XML" }
This page took 0.078035 seconds and 5 git commands to generate.