Commit | Line | Data |
---|---|---|
970ed795 | 1 | /****************************************************************************** |
3abe9331 | 2 | * Copyright (c) 2000-2015 Ericsson Telecom AB |
970ed795 EL |
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 AnyAttributes | |
9 | { | |
10 | modulepar boolean AnyAttributes_verbose := false; | |
11 | #define verbose AnyAttributes_verbose | |
12 | #include "../macros.ttcnin" | |
13 | ||
14 | type component AA {} | |
15 | ||
16 | type record of universal charstring AttrList; | |
17 | ||
18 | type record AAProduct { | |
19 | AttrList info, // a record of universal charstring | |
20 | charstring name, | |
21 | integer price | |
22 | } | |
23 | with { | |
24 | variant (info) "anyAttributes from 'http://www.example.com/A', " | |
25 | "'http://www.example.com/B', unqualified" // 'absent' is used by ASN.1 | |
26 | } | |
27 | ||
28 | DECLARE_XER_ENCODERS(AAProduct, aap); | |
29 | DECLARE_EXER_ENCODERS(AAProduct, aap); | |
30 | ||
31 | const AAProduct aap := { | |
32 | info := { | |
33 | "http://www.example.com/A size=""small""", | |
34 | "http://www.example.com/B color=""red""", | |
35 | "http://www.example.com/B x=""spot""", | |
36 | "available=""yes"""}, | |
37 | name := "Trousers", | |
38 | price:= 20 | |
39 | } | |
40 | ||
41 | const AAProduct aap_trouble := { | |
42 | info := { | |
43 | "http://www.example.com/A size=""small""", // too many spaces | |
44 | "http://www.example.com/B color=""red"" ", // spaces after | |
45 | "http://www.example.com/B x=""spot"" ", // spaces before and after | |
46 | "available=""yes"""}, | |
47 | name := "Trousers", | |
48 | price:= 20 | |
49 | } | |
50 | ||
51 | const AAProduct aap_tabs := { | |
52 | info := { | |
53 | "http://www.example.com/A\t\t size=""small""", // too many spaces | |
54 | "http://www.example.com/B\tcolor=""red""\t\t", // spaces after | |
55 | "http://www.example.com/B\t\tx=""spot"" \t ", // spaces before and after | |
56 | "available=""yes"""}, | |
57 | name := "Trousers", | |
58 | price:= 20 | |
59 | } | |
60 | ||
61 | const AAProduct aap_jumbled := { | |
62 | info := { | |
63 | "http://www.example.com/B color=""red""", | |
64 | "http://www.example.com/A size=""small""", | |
65 | "available=""yes"""}, | |
66 | name := "Trousers", | |
67 | price:= 20 | |
68 | } | |
69 | ||
70 | /* _e is for EXER, _b is for BXER */ | |
71 | ||
72 | const universal charstring str_aap_e := | |
73 | "<AAProduct " & | |
74 | "xmlns:b0=\'http://www.example.com/A\' b0:size=\"small\" " & | |
75 | "xmlns:b1=\'http://www.example.com/B\' b1:color=\"red\" " & | |
76 | "xmlns:b2=\'http://www.example.com/B\' b2:x=\"spot\" " & | |
77 | "available=\"yes\">\n" & | |
78 | "\t<name>Trousers</name>\n" & | |
79 | "\t<price>20</price>\n" & | |
80 | "</AAProduct>\n\n"; | |
81 | ||
82 | const universal charstring str_aap_e_jumbled := | |
83 | "<AAProduct xmlns:b0=\'http://www.example.com/A\' xmlns:b1=\'http://www.example.com/B\' b1:color=\"red\" b0:size=\"small\" available=\"yes\">\n" & | |
84 | "\t<name>Trousers</name>\n" & | |
85 | "\t<price>20</price>\n" & | |
86 | "</AAProduct>\n\n"; | |
87 | ||
88 | const universal charstring str_aap_b := | |
89 | "<AAProduct>\n" & | |
90 | "\t<info>\n" & | |
91 | "\t\t<UNIVERSAL_CHARSTRING>http://www.example.com/A size="small"</UNIVERSAL_CHARSTRING>\n" & | |
92 | "\t\t<UNIVERSAL_CHARSTRING>http://www.example.com/B color="red"</UNIVERSAL_CHARSTRING>\n" & | |
93 | "\t\t<UNIVERSAL_CHARSTRING>http://www.example.com/B x="spot"</UNIVERSAL_CHARSTRING>\n" & | |
94 | "\t\t<UNIVERSAL_CHARSTRING>available="yes"</UNIVERSAL_CHARSTRING>\n" & | |
95 | "\t</info>\n" & | |
96 | "\t<name>Trousers</name>\n" & | |
97 | "\t<price>20</price>\n" & | |
98 | "</AAProduct>\n\n"; | |
99 | ||
100 | testcase encode_aa() runs on AA | |
101 | { | |
102 | CHECK_METHOD(bxer_enc_aap, aap, str_aap_b); | |
103 | CHECK_METHOD(exer_enc_aap, aap, str_aap_e); | |
104 | CHECK_METHOD(exer_enc_aap, aap_trouble, str_aap_e); | |
105 | CHECK_METHOD(exer_enc_aap, aap_tabs , str_aap_e); | |
106 | } | |
107 | ||
108 | testcase decode_aa() runs on AA | |
109 | { | |
110 | CHECK_DECODE(bxer_dec_aap, str_aap_b, AAProduct, aap); | |
111 | CHECK_DECODE(exer_dec_aap, str_aap_e, AAProduct, aap); | |
112 | CHECK_DECODE(exer_dec_aap, str_aap_e_jumbled, AAProduct, aap_jumbled); | |
113 | } | |
114 | ||
115 | // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | |
116 | ||
117 | type record ABProduct { | |
118 | AttrList info, // a record of universal charstring | |
119 | charstring name, | |
120 | integer price | |
121 | } | |
122 | with { | |
123 | variant (info) "anyAttributes except 'http://www.example.com/C', unqualified" | |
124 | } | |
125 | ||
126 | DECLARE_XER_ENCODERS(ABProduct, abp); | |
127 | DECLARE_EXER_ENCODERS(ABProduct, abp); | |
128 | ||
129 | const ABProduct abp := { | |
130 | info := { | |
131 | "http://www.example.com/A size=""small""", | |
132 | "http://www.example.com/B color=""red""", | |
133 | "http://www.example.com/B available=""yes"""}, | |
134 | name := "Trousers", | |
135 | price:= 20 | |
136 | } | |
137 | ||
138 | const universal charstring str_abp_e := | |
139 | //"<ABProduct xmlns:b0=\'http://www.example.com/A\' b0:size=\"small\" xmlns:b1=\'http://www.example.com/B\' b1:color=\"red\" b1:available=\"yes\">\n" & | |
140 | // this one below is a workaround because the encoder doesn't recognize that namespace b1 has already been declared :( | |
141 | "<ABProduct xmlns:b0=\'http://www.example.com/A\' b0:size=\"small\" xmlns:b1=\'http://www.example.com/B\' b1:color=\"red\" xmlns:b2=\'http://www.example.com/B\' b2:available=\"yes\">\n" & | |
142 | "\t<name>Trousers</name>\n" & | |
143 | "\t<price>20</price>\n" & | |
144 | "</ABProduct>\n\n"; | |
145 | ||
146 | const universal charstring str_abp_b := | |
147 | "<ABProduct>\n" & | |
148 | "\t<info>\n" & | |
149 | "\t\t<UNIVERSAL_CHARSTRING>http://www.example.com/A size="small"</UNIVERSAL_CHARSTRING>\n" & | |
150 | "\t\t<UNIVERSAL_CHARSTRING>http://www.example.com/B color="red"</UNIVERSAL_CHARSTRING>\n" & | |
151 | "\t\t<UNIVERSAL_CHARSTRING>http://www.example.com/B available="yes"</UNIVERSAL_CHARSTRING>\n" & | |
152 | //originally: "\t\t<UNIVERSAL_CHARSTRING>available=\"yes\"</UNIVERSAL_CHARSTRING>\n" & | |
153 | "\t</info>\n" & | |
154 | "\t<name>Trousers</name>\n" & | |
155 | "\t<price>20</price>\n" & | |
156 | "</ABProduct>\n\n"; | |
157 | ||
158 | testcase encode_ab() runs on AA | |
159 | { | |
160 | CHECK_METHOD(bxer_enc_abp, abp, str_abp_b); | |
161 | CHECK_METHOD(exer_enc_abp, abp, str_abp_e); | |
162 | } | |
163 | ||
164 | testcase decode_ab() runs on AA | |
165 | { | |
166 | CHECK_DECODE(bxer_dec_abp, str_abp_b, ABProduct, abp); | |
167 | CHECK_DECODE(exer_dec_abp, str_abp_e, ABProduct, abp); | |
168 | } | |
169 | ||
170 | type record ouch { | |
171 | record of universal charstring embed, | |
172 | AttrList aa // a record of universal charstring | |
173 | } | |
174 | with { | |
175 | variant "embedValues" | |
176 | } | |
177 | ||
178 | // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | |
179 | // ANY-ATTRIBUTES and "normal" ATTRIBUTES | |
180 | ||
181 | ||
182 | type record AXProduct { | |
183 | charstring name, | |
184 | AttrList info, // a record of universal charstring | |
185 | boolean available, | |
186 | integer price | |
187 | } | |
188 | with { | |
189 | variant (info) "anyAttributes from 'http://www.example.com/X', unqualified"; | |
190 | variant (name) "attribute"; | |
191 | variant (available) "attribute" | |
192 | } | |
193 | ||
194 | DECLARE_XER_ENCODERS(AXProduct, axp); | |
195 | DECLARE_EXER_ENCODERS(AXProduct, axp); | |
196 | ||
197 | const AXProduct axp := { | |
198 | name := "Trousers", | |
199 | info := { | |
200 | "http://www.example.com/X size=""small""", | |
201 | "http://www.example.com/X color=""red""", | |
202 | "http://www.example.com/X available=""yes"""}, | |
203 | available := false, | |
204 | price:= 20 | |
205 | } | |
206 | ||
207 | const universal charstring estr_axp := | |
208 | //"<AXProduct xmlns:b0=\'http://www.example.com/A\' b0:size=\"small\" | |
209 | // xmlns:b1=\'http://www.example.com/B\' b1:color=\"red\" | |
210 | // b1:available=\"yes\">\n" & | |
211 | // this one below is a workaround because the encoder doesn't recognize that namespace b1 has already been declared :( | |
212 | "<AXProduct name='Trousers' xmlns:b0=\'http://www.example.com/X\' b0:size=\"small\" " & | |
213 | "xmlns:b1=\'http://www.example.com/X\' b1:color=\"red\" " & | |
214 | "xmlns:b2=\'http://www.example.com/X\' b2:available=\"yes\" available='false'>\n" & | |
215 | "\t<price>20</price>\n" & | |
216 | "</AXProduct>\n\n"; | |
217 | ||
218 | const universal charstring bstr_axp := | |
219 | "<AXProduct>\n" & | |
220 | "\t<name>Trousers</name>\n" & | |
221 | "\t<info>\n" & | |
222 | "\t\t<UNIVERSAL_CHARSTRING>http://www.example.com/X size="small"</UNIVERSAL_CHARSTRING>\n" & | |
223 | "\t\t<UNIVERSAL_CHARSTRING>http://www.example.com/X color="red"</UNIVERSAL_CHARSTRING>\n" & | |
224 | "\t\t<UNIVERSAL_CHARSTRING>http://www.example.com/X available="yes"</UNIVERSAL_CHARSTRING>\n" & | |
225 | //originally: "\t\t<UNIVERSAL_CHARSTRING>available=\"yes\"</UNIVERSAL_CHARSTRING>\n" & | |
226 | "\t</info>\n" & | |
227 | "\t<available><false/></available>\n" & | |
228 | "\t<price>20</price>\n" & | |
229 | "</AXProduct>\n\n"; | |
230 | ||
231 | testcase encode_ax() runs on AA | |
232 | { | |
233 | CHECK_METHOD(bxer_enc_axp, axp, bstr_axp); | |
234 | CHECK_METHOD(exer_enc_axp, axp, estr_axp); | |
235 | } | |
236 | ||
237 | testcase decode_ax() runs on AA | |
238 | { | |
239 | CHECK_DECODE(bxer_dec_axp, bstr_axp, AXProduct, axp); | |
240 | //not quite right yet: | |
241 | CHECK_DECODE(exer_dec_axp, estr_axp, AXProduct, axp); | |
242 | } | |
243 | ||
244 | // Negative tests for namespace restrinctions in ANY-ATTRIBUTES | |
245 | // 1. anyAttributes from ... | |
246 | ||
247 | type record AAFProduct { | |
248 | AttrList info, // a record of universal charstring | |
249 | charstring name | |
250 | } | |
251 | with { | |
252 | variant (info) "anyAttributes from 'http://www.example.com/X', unqualified" | |
253 | } | |
254 | ||
255 | DECLARE_EXER_ENCODERS(AAFProduct, aaf); | |
256 | ||
257 | const AAFProduct aaf := { | |
258 | info := { | |
259 | "http://www.example.com/X size=""small""", | |
260 | "http://www.example.com/Y color=""red""", | |
261 | "available=""yes"""}, | |
262 | name := "Trousers" | |
263 | } | |
264 | ||
265 | const octetstring str_aaf := unichar2oct( | |
266 | "<AAFProduct xmlns:b0=\'http://www.example.com/X\' b0:size=\"small\" " & | |
267 | "xmlns:b1=\'http://www.example.com/Y\' b1:color=\"red\" " & | |
268 | "available=\"yes\">\n" & | |
269 | "\t<name>Trousers</name>\n" & | |
270 | "</AAFProduct>\n\n", "UTF-8"); | |
271 | ||
272 | template charstring error_aaf := pattern "*XML namespace \"http://www.example.com/Y\" is not in the allowed namespace list."; | |
273 | ||
274 | testcase encode_aaf() runs on AA | |
275 | { | |
276 | CHECK_METHOD_ERROR(exer_enc_aaf, aaf, octetstring, error_aaf); | |
277 | } | |
278 | ||
279 | testcase decode_aaf() runs on AA | |
280 | { | |
281 | CHECK_METHOD_ERROR(exer_dec_aaf, str_aaf, AAFProduct, error_aaf); | |
282 | } | |
283 | ||
284 | // 2. anyAttributes except ... | |
285 | ||
286 | type record AAEProduct { | |
287 | AttrList info, // a record of universal charstring | |
288 | charstring name | |
289 | } | |
290 | with { | |
291 | variant (info) "anyAttributes except 'http://www.example.com/X', unqualified" | |
292 | } | |
293 | ||
294 | DECLARE_EXER_ENCODERS(AAEProduct, aae); | |
295 | ||
296 | const AAEProduct aae1 := { | |
297 | info := { | |
298 | "http://www.example.com/X size=""small""", | |
299 | "http://www.example.com/Y color=""red""", | |
300 | "http://www.example.com/Z available=""yes"""}, | |
301 | name := "Trousers" | |
302 | } | |
303 | ||
304 | const AAEProduct aae2 := { | |
305 | info := { | |
306 | "http://www.example.com/Y size=""medium""", | |
307 | "http://www.example.com/Z color=""green""", | |
308 | "available=""no"""}, | |
309 | name := "Shirt" | |
310 | } | |
311 | ||
312 | const octetstring str_aae1 := unichar2oct( | |
313 | "<AAEProduct xmlns:b0=\'http://www.example.com/X\' b0:size=\"small\" " & | |
314 | "xmlns:b1=\'http://www.example.com/Y\' b1:color=\"red\" " & | |
315 | "xmlns:b2=\'http://www.example.com/Z\' b2:available=\"yes\">\n" & | |
316 | "\t<name>Trousers</name>\n" & | |
317 | "</AAEProduct>\n\n", "UTF-8"); | |
318 | ||
319 | const octetstring str_aae2 := unichar2oct( | |
320 | "<AAEProduct xmlns:b0=\'http://www.example.com/Y\' b0:size=\"medium\" " & | |
321 | "xmlns:b1=\'http://www.example.com/Z\' b1:color=\"green\" " & | |
322 | "available=\"no\">\n" & | |
323 | "\t<name>Shirt</name>\n" & | |
324 | "</AAEProduct>\n\n", "UTF-8"); | |
325 | ||
326 | template charstring error_aae1 := pattern "*XML namespace \"http://www.example.com/X\" is in the excluded namespace list."; | |
327 | ||
328 | template charstring error_aae2 := pattern "*The unqualified XML namespace is in the excluded namespace list."; | |
329 | ||
330 | testcase encode_aae() runs on AA | |
331 | { | |
332 | CHECK_METHOD_ERROR(exer_enc_aae, aae1, octetstring, error_aae1); | |
333 | CHECK_METHOD_ERROR(exer_enc_aae, aae2, octetstring, error_aae2); | |
334 | } | |
335 | ||
336 | testcase decode_aae() runs on AA | |
337 | { | |
338 | CHECK_METHOD_ERROR(exer_dec_aae, str_aae1, AAEProduct, error_aae1); | |
339 | CHECK_METHOD_ERROR(exer_dec_aae, str_aae2, AAEProduct, error_aae2); | |
340 | } | |
341 | ||
342 | // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | |
343 | ||
344 | control | |
345 | { | |
346 | execute(encode_aa()); | |
347 | execute(decode_aa()); | |
348 | ||
349 | execute(encode_ab()); | |
350 | execute(decode_ab()); | |
351 | ||
352 | execute(encode_ax()); | |
353 | execute(decode_ax()); | |
354 | ||
355 | execute(encode_aaf()); | |
356 | execute(decode_aaf()); | |
357 | ||
358 | execute(encode_aae()); | |
359 | execute(decode_aae()); | |
360 | } | |
361 | ||
362 | } | |
363 | with { | |
364 | encode "XML" | |
365 | } |