Commit | Line | Data |
---|---|---|
970ed795 | 1 | /****************************************************************************** |
d44e3c4f | 2 | * Copyright (c) 2000-2016 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 | |
d44e3c4f | 7 | * |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Raduly, Csaba | |
11 | * | |
970ed795 EL |
12 | ******************************************************************************/ |
13 | module exer_rec { | |
14 | import from ReadXml all; | |
15 | import from rec { type Neg; function check_match } | |
16 | ||
17 | // -- -- -- -- -- -- -- -- -- -- -- EMBED-VALUES | |
18 | ||
19 | type record Emb1 { | |
20 | record of universal charstring emb, | |
21 | charstring name, | |
22 | float price | |
23 | } | |
24 | with { | |
25 | variant "embedValues" | |
26 | } | |
27 | ||
28 | external function encEmb1(in Emb1 e) return octetstring | |
29 | with { | |
30 | extension "prototype(convert) encode(XER:XER_EXTENDED)" | |
31 | } | |
32 | ||
33 | const Emb1 c_emb1_plain := { | |
34 | emb := { "I bring you delicious", " for the price of ", " only" }, | |
35 | name := "pie", | |
36 | price:= 3.141592 | |
37 | } | |
38 | ||
39 | template Nodes t_plain := { | |
40 | // node_type , depth, name, value, namespace | |
41 | { XML_READER_TYPE_ELEMENT , 0, "Emb1" , "", "" }, //0 | |
42 | { XML_READER_TYPE_TEXT , 1, "#text", "I bring you delicious", "" }, //1 | |
43 | ||
44 | { XML_READER_TYPE_ELEMENT , 1, "name" , "", ""}, //2 | |
45 | { XML_READER_TYPE_TEXT , 2, "#text", "pie", "" }, //3 | |
46 | { XML_READER_TYPE_END_ELEMENT, 1, "name" , "", ""}, //4 | |
47 | ||
48 | { XML_READER_TYPE_TEXT , 1, "#text", " for the price of ", "" }, //5 | |
49 | ||
50 | { XML_READER_TYPE_ELEMENT , 1, "price", "", ""}, //6 | |
51 | { XML_READER_TYPE_TEXT , 2, "#text", "3.141592", "" }, //7 | |
52 | { XML_READER_TYPE_END_ELEMENT, 1, "price", "", ""}, //8 | |
53 | ||
54 | { XML_READER_TYPE_TEXT , 1, "#text", " only", "" }, //9 | |
55 | { XML_READER_TYPE_END_ELEMENT, 0, "Emb1" , "", "" } //10 | |
56 | } | |
57 | ||
58 | testcase exer_rec_plain() runs on Neg | |
59 | { | |
60 | var octetstring o; | |
61 | var Nodes nodes; | |
62 | ||
63 | o := encEmb1(c_emb1_plain); | |
64 | nodes := gather(o); | |
65 | check_match(nodes, t_plain); | |
66 | } | |
67 | ||
68 | // -- -- -- -- -- -- -- -- -- -- BEFORE | |
69 | ||
70 | const Emb1 c_emb1_before := c_emb1_plain | |
71 | with { | |
72 | erroneous (price) "before := 'C0FFEE'O " | |
73 | } | |
74 | ||
75 | template Nodes t_before modifies t_plain := { | |
76 | -,-, | |
77 | -,-,-, | |
78 | -, | |
79 | { XML_READER_TYPE_ELEMENT , 1, "OCTET_STRING", "", "" }, | |
80 | { XML_READER_TYPE_TEXT , 2, "#text" , "C0FFEE", "" }, | |
81 | { XML_READER_TYPE_END_ELEMENT, 1, "OCTET_STRING", "", "" }, | |
82 | t_plain[6], t_plain[7], t_plain[8], t_plain[9], t_plain[10] | |
83 | } | |
84 | ||
85 | const Emb1 c_emb1_before2 := c_emb1_plain | |
86 | with { | |
87 | erroneous (emb[2]) "before := 'C0FFEE'O " | |
88 | } | |
89 | ||
90 | template Nodes t_before2 modifies t_plain := { | |
91 | -,-, | |
92 | -,-,-, | |
93 | -, | |
94 | -,-,-, | |
95 | { XML_READER_TYPE_TEXT , 1, "#text" , "C0FFEE only", "" }, | |
96 | t_plain[10] | |
97 | } | |
98 | ||
99 | testcase exer_rec_before() runs on Neg | |
100 | { | |
101 | var octetstring o; | |
102 | var Nodes nodes; | |
103 | ||
104 | o := encEmb1(c_emb1_before); | |
105 | nodes := gather(o); | |
106 | check_match(nodes, t_before); | |
107 | ||
108 | o := encEmb1(c_emb1_before2); | |
109 | nodes := gather(o); | |
110 | check_match(nodes, t_before2); | |
111 | } | |
112 | ||
113 | // -- -- -- -- -- -- -- -- ATTRIBUTE -- -- -- -- -- -- -- -- | |
114 | ||
115 | type record RA { | |
116 | charstring a1, | |
117 | integer a2, | |
118 | charstring content | |
119 | } | |
120 | with { | |
121 | variant (a1,a2) "attribute" | |
122 | } | |
123 | ||
124 | external function encAtr(in RA r) return octetstring | |
125 | with { | |
126 | extension "prototype(convert) encode(XER:XER_EXTENDED)" | |
127 | } | |
128 | ||
129 | const RA c_atr_plain := { | |
130 | a1 := "first", a2 := 42, content := "stuff" | |
131 | } | |
132 | ||
133 | template Nodes t_atr_plain := { | |
134 | // node_type , depth, name, value, ns | |
135 | { XML_READER_TYPE_ELEMENT , 0, "RA" , "" , ""}, //0 | |
136 | { XML_READER_TYPE_ATTRIBUTE , 1, "a1" , "first", ""}, | |
137 | { XML_READER_TYPE_ATTRIBUTE , 1, "a2" , "42" , ""}, //2 | |
138 | { XML_READER_TYPE_ELEMENT , 1, "content", "" , ""}, | |
139 | { XML_READER_TYPE_TEXT , 2, "#text" , "stuff", ""}, //4 | |
140 | { XML_READER_TYPE_END_ELEMENT, 1, "content", "" , ""}, | |
141 | { XML_READER_TYPE_END_ELEMENT, 0, "RA" , "" , ""} //6 | |
142 | } | |
143 | ||
144 | testcase exer_attr() runs on Neg | |
145 | { | |
146 | var octetstring o; | |
147 | var Nodes nodes; | |
148 | ||
149 | o := encAtr(c_atr_plain); | |
150 | nodes := gather(o, ignore_ws); | |
151 | check_match(nodes, t_atr_plain); | |
152 | } | |
153 | ||
154 | // -- -- -- -- -- -- -- -- before | |
155 | ||
156 | type charstring abefore | |
157 | with { | |
158 | variant "attribute" | |
159 | } | |
160 | ||
161 | const RA c_atr_before1 := c_atr_plain | |
162 | with { | |
163 | erroneous (a1) "before := abefore:""b4"" " | |
164 | } | |
165 | // The abefore type supplies the name. The "attribute" variant of abefore ensures | |
166 | // that it doesn't write an element amongst the attributes, like this: | |
167 | // <RA <abefore>b4</abefore> a1='first' a2='42'> ... | |
168 | // The decoder chokes badly on this invalid XML. | |
169 | ||
170 | template Nodes t_atr_before1 /*modifies t_atr_plain*/ := | |
171 | { | |
172 | t_atr_plain[0], | |
173 | { XML_READER_TYPE_ATTRIBUTE , 1, "abefore", "b4", ""}, | |
174 | t_atr_plain[1], | |
175 | t_atr_plain[2], | |
176 | t_atr_plain[3], | |
177 | t_atr_plain[4], | |
178 | t_atr_plain[5], | |
179 | t_atr_plain[6] | |
180 | } | |
181 | ||
182 | testcase exer_attr_before1() runs on Neg | |
183 | { | |
184 | var octetstring o; | |
185 | var Nodes nodes; | |
186 | ||
187 | o := encAtr(c_atr_before1); | |
188 | nodes := gather(o, ignore_ws); | |
189 | check_match(nodes, t_atr_before1); | |
190 | } | |
191 | ||
192 | // . . . . . raw before | |
193 | ||
194 | const RA c_atr_before1raw := c_atr_plain | |
195 | with { | |
196 | erroneous (a1) "before(raw) := "" b4='beef ore'"" " | |
197 | } // need space here---------------^ to produce well-formed XML | |
198 | ||
199 | template Nodes t_atr_before1raw := | |
200 | { | |
201 | t_atr_plain[0], | |
202 | { XML_READER_TYPE_ATTRIBUTE , 1, "b4", "beef ore", ""}, | |
203 | t_atr_plain[1], | |
204 | t_atr_plain[2], | |
205 | t_atr_plain[3], | |
206 | t_atr_plain[4], | |
207 | t_atr_plain[5], | |
208 | t_atr_plain[6] | |
209 | } | |
210 | ||
211 | testcase exer_attr_before1raw() runs on Neg | |
212 | { | |
213 | var octetstring o; | |
214 | var Nodes nodes; | |
215 | ||
216 | o := encAtr(c_atr_before1raw); | |
217 | nodes := gather(o, ignore_ws); | |
218 | check_match(nodes, t_atr_before1raw); | |
219 | } | |
220 | ||
221 | // -- -- -- -- -- -- -- -- replace | |
222 | ||
223 | type charstring replacement | |
224 | with { variant "attribute" } | |
225 | ||
226 | const RA c_atr_replace2 := c_atr_plain | |
227 | with { | |
228 | erroneous (a2) "value := replacement : ""substitute"" " | |
229 | } | |
230 | ||
231 | template Nodes t_atr_replace2 modifies t_atr_plain := { | |
232 | -,-, | |
233 | { XML_READER_TYPE_ATTRIBUTE , 1, "replacement", "substitute", ""}, | |
234 | -,-,-,- | |
235 | } | |
236 | ||
237 | testcase exer_attr_replace2() runs on Neg | |
238 | { | |
239 | var octetstring o; | |
240 | var Nodes nodes; | |
241 | ||
242 | o := encAtr(c_atr_replace2); | |
243 | nodes := gather(o, ignore_ws); | |
244 | check_match(nodes, t_atr_replace2); | |
245 | } | |
246 | ||
247 | // . . . . . raw replace | |
248 | ||
249 | const RA c_atr_replace2raw := c_atr_plain | |
250 | with { | |
251 | erroneous (a2) "value(raw) := "" foo='bar'"" " | |
252 | } // space needed here------------^ for well-formed XML | |
253 | ||
254 | template Nodes t_atr_replace2raw modifies t_atr_plain := { | |
255 | -,-, // start-element, attribute a1 | |
256 | // then the replacement | |
257 | { XML_READER_TYPE_ATTRIBUTE , 1, "foo", "bar", ""}, | |
258 | -,-,-,- | |
259 | } | |
260 | ||
261 | testcase exer_attr_replace2raw() runs on Neg | |
262 | { | |
263 | var octetstring o; | |
264 | var Nodes nodes; | |
265 | ||
266 | o := encAtr(c_atr_replace2raw); | |
267 | nodes := gather(o, ignore_ws); | |
268 | check_match(nodes, t_atr_replace2raw); | |
269 | } | |
270 | ||
271 | // -- -- -- -- -- -- -- -- after | |
272 | ||
273 | const RA c_atr_after2 := c_atr_plain | |
274 | with { | |
275 | erroneous (a2) "after := abefore : ""a-fter"" " | |
276 | } | |
277 | ||
278 | template Nodes t_atr_after2 modifies t_atr_plain := | |
279 | { | |
280 | -,-,-, // start-element, attribute a1, attribute a2 | |
281 | // then the extra attribute after | |
282 | { XML_READER_TYPE_ATTRIBUTE, 1, "abefore", "a-fter", "" }, | |
283 | t_atr_plain[3], | |
284 | t_atr_plain[4], | |
285 | t_atr_plain[5], | |
286 | t_atr_plain[6] | |
287 | } | |
288 | ||
289 | testcase exer_attr_after2() runs on Neg | |
290 | { | |
291 | var octetstring o; | |
292 | var Nodes nodes; | |
293 | ||
294 | o := encAtr(c_atr_after2); | |
295 | nodes := gather(o, ignore_ws); | |
296 | check_match(nodes, t_atr_after2); | |
297 | } | |
298 | ||
299 | // . . . . . raw after | |
300 | ||
301 | const RA c_atr_after2raw := c_atr_plain | |
302 | with { | |
303 | erroneous (a2) "after(raw) := "" after='shave'"" " | |
304 | } // space needed here------------^ for well-formed XML | |
305 | ||
306 | template Nodes t_atr_after2raw modifies t_atr_plain := | |
307 | { | |
308 | -,-,-, // start-element, attribute a1, attribute a2 | |
309 | // then the extra attribute after | |
310 | { XML_READER_TYPE_ATTRIBUTE, 1, "after", "shave", "" }, | |
311 | t_atr_plain[3], | |
312 | t_atr_plain[4], | |
313 | t_atr_plain[5], | |
314 | t_atr_plain[6] | |
315 | } | |
316 | ||
317 | testcase exer_attr_after2raw() runs on Neg | |
318 | { | |
319 | var octetstring o; | |
320 | var Nodes nodes; | |
321 | ||
322 | o := encAtr(c_atr_after2raw); | |
323 | nodes := gather(o, ignore_ws); | |
324 | check_match(nodes, t_atr_after2raw); | |
325 | } | |
326 | ||
327 | // -- -- -- -- -- -- -- -- omit | |
328 | ||
329 | const RA c_atr_omit1 := c_atr_plain | |
330 | with { | |
331 | erroneous (a1) "value := omit" | |
332 | } | |
333 | ||
334 | template Nodes t_atr_omit1 := | |
335 | { | |
336 | t_atr_plain[0], // start-element | |
337 | //t_atr_plain[1], // attribute a1 omitted | |
338 | t_atr_plain[2], // attribute a2 | |
339 | t_atr_plain[3], | |
340 | t_atr_plain[4], | |
341 | t_atr_plain[5], | |
342 | t_atr_plain[6] | |
343 | } | |
344 | ||
345 | const RA c_atr_omit2 := c_atr_plain | |
346 | with { | |
347 | erroneous (a2) "value := omit" | |
348 | } | |
349 | ||
350 | template Nodes t_atr_omit2 modifies t_atr_omit1 := | |
351 | { | |
352 | -, | |
353 | t_atr_plain[1], // instead of a1 being omitted and a2 present, here a1 is present | |
354 | -,-,-,- | |
355 | } | |
356 | ||
357 | testcase exer_attr_omit1() runs on Neg | |
358 | { | |
359 | var octetstring o; | |
360 | var Nodes nodes; | |
361 | ||
362 | o := encAtr(c_atr_omit1); | |
363 | nodes := gather(o, ignore_ws); | |
364 | check_match(nodes, t_atr_omit1); | |
365 | ||
366 | o := encAtr(c_atr_omit2); | |
367 | nodes := gather(o, ignore_ws); | |
368 | check_match(nodes, t_atr_omit2); | |
369 | } | |
370 | ||
371 | // . . . . . . . omit all before | |
372 | ||
373 | const RA c_atr_omit_all_before2 := c_atr_plain | |
374 | with { | |
375 | erroneous (a2) "before := omit all" | |
376 | } | |
377 | ||
378 | template Nodes t_atr_omit_all_before2 := | |
379 | { | |
380 | t_atr_plain[0], // start-element | |
381 | //t_atr_plain[1], // attribute a1 omitted | |
382 | t_atr_plain[2], // attribute a2 | |
383 | t_atr_plain[3], | |
384 | t_atr_plain[4], | |
385 | t_atr_plain[5], | |
386 | t_atr_plain[6] | |
387 | } | |
388 | ||
389 | const RA c_atr_omit_all_before3 := c_atr_plain | |
390 | with { | |
391 | erroneous (content) "before := omit all" | |
392 | } | |
393 | ||
394 | template Nodes t_atr_omit_all_before3 := | |
395 | { | |
396 | t_atr_plain[0], // start-element | |
397 | //t_atr_plain[1], // attribute a1 omitted | |
398 | //t_atr_plain[2], // attribute a2 omitted | |
399 | t_atr_plain[3], | |
400 | t_atr_plain[4], | |
401 | t_atr_plain[5], | |
402 | t_atr_plain[6] | |
403 | } | |
404 | ||
405 | testcase exer_attr_omit_all_before() runs on Neg | |
406 | { | |
407 | var octetstring o; | |
408 | var Nodes nodes; | |
409 | ||
410 | o := encAtr(c_atr_omit_all_before2); | |
411 | nodes := gather(o, ignore_ws); | |
412 | check_match(nodes, t_atr_omit_all_before2); | |
413 | ||
414 | o := encAtr(c_atr_omit_all_before3); | |
415 | nodes := gather(o, ignore_ws); | |
416 | check_match(nodes, t_atr_omit_all_before3); | |
417 | } | |
418 | ||
419 | // . . . . . . . omit all after | |
420 | ||
421 | const RA c_atr_omit_all_after2 := c_atr_plain | |
422 | with { | |
423 | erroneous (a2) "after := omit all" | |
424 | } | |
425 | ||
426 | template Nodes t_atr_omit_all_after2 := | |
427 | { | |
428 | t_atr_plain[0], // start-element | |
429 | t_atr_plain[1], // attribute a1 | |
430 | t_atr_plain[2] // attribute a2 | |
431 | //t_atr_plain[3], \\ | |
432 | //t_atr_plain[4], >> content element omitted | |
433 | //t_atr_plain[5], // | |
434 | //t_atr_plain[6] // RA end tag omitted: empty element | |
435 | } | |
436 | ||
437 | const RA c_atr_omit_all_after1 := c_atr_plain | |
438 | with { | |
439 | erroneous (a1) "after := omit all" | |
440 | } | |
441 | ||
442 | template Nodes t_atr_omit_all_after1 := | |
443 | { | |
444 | t_atr_plain[0], // start-element | |
445 | t_atr_plain[1] // attribute a1 | |
446 | //t_atr_plain[2], // attribute a2 omitted | |
447 | //t_atr_plain[3], \\ | |
448 | //t_atr_plain[4], >> content element omitted | |
449 | //t_atr_plain[5], // | |
450 | //t_atr_plain[6] // RA end tag omitted: empty element | |
451 | } | |
452 | ||
453 | testcase exer_attr_omit_all_after() runs on Neg | |
454 | { | |
455 | var octetstring o; | |
456 | var Nodes nodes; | |
457 | ||
458 | o := encAtr(c_atr_omit_all_after2); | |
459 | nodes := gather(o, ignore_ws); | |
460 | check_match(nodes, t_atr_omit_all_after2); | |
461 | ||
462 | o := encAtr(c_atr_omit_all_after1); | |
463 | nodes := gather(o, ignore_ws); | |
464 | check_match(nodes, t_atr_omit_all_after1); | |
465 | } | |
466 | ||
467 | ||
468 | ||
469 | // -- -- -- -- -- -- -- -- USE-QNAME -- -- -- -- -- -- -- -- | |
470 | ||
471 | type record QN { | |
472 | universal charstring uri optional, | |
473 | universal charstring name | |
474 | } | |
475 | with { | |
476 | variant "XSD:QName" | |
477 | } | |
478 | ||
479 | external function encQN(in QN q) return octetstring | |
480 | with { | |
481 | extension "prototype(convert) encode(XER:XER_EXTENDED)" | |
482 | } | |
483 | ||
484 | const QN c_qn := { "uri", "nm" } | |
485 | const QN c_uqn:= { omit , "nm" } | |
486 | ||
487 | // <QN xmlns:b0='uri'>b0:nm</QN> | |
488 | template Nodes t_qn := | |
489 | { | |
490 | { XML_READER_TYPE_ELEMENT , 0, "QN", "", "" }, | |
491 | { XML_READER_TYPE_ATTRIBUTE , 1, "xmlns:b0", "uri", "http://www.w3.org/2000/xmlns/" }, | |
492 | { XML_READER_TYPE_TEXT , 1, "#text", "b0:nm", "" }, | |
493 | { XML_READER_TYPE_END_ELEMENT, 0, "QN", "", "" } | |
494 | } | |
495 | ||
496 | // <QN>nm</QN> | |
497 | template Nodes t_uqn := | |
498 | { | |
499 | { XML_READER_TYPE_ELEMENT , 0, "QN", "", "" }, | |
500 | // no namespace | |
501 | { XML_READER_TYPE_TEXT , 1, "#text", "nm", "" }, | |
502 | { XML_READER_TYPE_END_ELEMENT, 0, "QN", "", "" } | |
503 | } | |
504 | ||
505 | testcase exer_qname_plain() runs on Neg | |
506 | { | |
507 | var octetstring o; | |
508 | var Nodes nodes; | |
509 | ||
510 | o := encQN(c_qn); | |
511 | nodes := gather(o, ignore_ws); | |
512 | check_match(nodes, t_qn); | |
513 | ||
514 | o := encQN(c_uqn); | |
515 | nodes := gather(o, ignore_ws); | |
516 | check_match(nodes, t_uqn); | |
517 | } | |
518 | ||
519 | // .. .. .. .. before | |
520 | ||
521 | const QN c_qn_before0 := c_qn | |
522 | with { | |
523 | erroneous (uri) "before := abefore : ""mae ni"" " | |
524 | } | |
525 | ||
526 | template Nodes t_qn_before0 modifies t_qn := | |
527 | { | |
528 | -,-, | |
529 | { XML_READER_TYPE_ATTRIBUTE , 1, "abefore", "mae ni", "" }, | |
530 | t_qn[2], | |
531 | t_qn[3] | |
532 | } | |
533 | ||
534 | const QN c_qn_before0raw := c_qn | |
535 | with { | |
536 | erroneous (uri) "before(raw) := "" rawbefore='hi!'"" " | |
537 | } // spece for well-formed XML------^ | |
538 | ||
539 | template Nodes t_qn_before0raw modifies t_qn := | |
540 | { | |
541 | -,-, | |
542 | { XML_READER_TYPE_ATTRIBUTE , 1, "rawbefore", "hi!", "" }, | |
543 | t_qn[2], | |
544 | t_qn[3] | |
545 | } | |
546 | ||
547 | const QN c_uqn_before0 := c_uqn | |
548 | with { | |
549 | erroneous (uri) "before := abefore : ""mae ni"" " | |
550 | } | |
551 | ||
552 | template Nodes t_uqn_before0 modifies t_uqn := | |
553 | { | |
554 | -, | |
555 | { XML_READER_TYPE_ATTRIBUTE , 1, "abefore", "mae ni", "" }, | |
556 | t_uqn[1], | |
557 | t_uqn[2] | |
558 | } | |
559 | ||
560 | const QN c_uqn_before0raw := c_uqn | |
561 | with { | |
562 | erroneous (uri) "before(raw) := "" rawbefore='hi!'"" " | |
563 | } // spece for well-formed XML------^ | |
564 | ||
565 | template Nodes t_uqn_before0raw modifies t_uqn := | |
566 | { | |
567 | -, | |
568 | { XML_READER_TYPE_ATTRIBUTE , 1, "rawbefore", "hi!", "" }, | |
569 | t_uqn[1], | |
570 | t_uqn[2] | |
571 | } | |
572 | ||
573 | ||
574 | //// | |
575 | const QN c_qn_before1 := c_qn | |
576 | with { | |
577 | erroneous (name) "before := ""mae ni"" " | |
578 | } | |
579 | ||
580 | template Nodes t_qn_before1 modifies t_qn := | |
581 | { | |
582 | -,-, | |
583 | { XML_READER_TYPE_ELEMENT , 1, "CHARSTRING", "", "" }, | |
584 | { XML_READER_TYPE_TEXT , 2, "#text" , "mae ni", "" }, | |
585 | { XML_READER_TYPE_END_ELEMENT, 1, "CHARSTRING", "", "" }, | |
586 | { XML_READER_TYPE_TEXT , 1, "#text" , "\nb0:nm", "" }, //almost t_qn[2], | |
587 | t_qn[3] | |
588 | } | |
589 | ||
590 | const QN c_qn_before1raw := c_qn | |
591 | with { | |
592 | erroneous (name) "before(raw) := ""rawb4,"" " | |
593 | } | |
594 | ||
595 | template Nodes t_qn_before1raw modifies t_qn := | |
596 | { | |
597 | -,-, | |
598 | { XML_READER_TYPE_TEXT , 1, "#text" , "rawb4,b0:nm", "" }, //almost t_qn[2] | |
599 | t_qn[3] | |
600 | } | |
601 | ||
602 | const QN c_uqn_before1 := c_uqn | |
603 | with { | |
604 | erroneous (name) "before := ""mae ni"" " | |
605 | } | |
606 | ||
607 | template Nodes t_uqn_before1 modifies t_uqn := | |
608 | { | |
609 | -, | |
610 | { XML_READER_TYPE_ELEMENT , 1, "CHARSTRING", "", "" }, | |
611 | { XML_READER_TYPE_TEXT , 2, "#text" , "mae ni", "" }, | |
612 | { XML_READER_TYPE_END_ELEMENT, 1, "CHARSTRING", "", "" }, | |
613 | { XML_READER_TYPE_TEXT , 1, "#text" , "\nnm", "" }, //almost t_uqn[2], | |
614 | t_uqn[2] | |
615 | } | |
616 | ||
617 | const QN c_uqn_before1raw := c_uqn | |
618 | with { | |
619 | erroneous (name) "before(raw) := ""rawb4,"" " | |
620 | } | |
621 | ||
622 | template Nodes t_uqn_before1raw modifies t_uqn := | |
623 | { | |
624 | -, | |
625 | { -,-,-, "rawb4,nm",- }, | |
626 | t_uqn[2] | |
627 | } | |
628 | ||
629 | ||
630 | testcase exer_qname_before() runs on Neg | |
631 | { | |
632 | var octetstring o; | |
633 | var Nodes nodes; | |
634 | ||
635 | o := encQN(c_qn_before0); | |
636 | nodes := gather(o, ignore_ws); | |
637 | check_match(nodes, t_qn_before0); | |
638 | ||
639 | o := encQN(c_qn_before0raw); | |
640 | nodes := gather(o, ignore_ws); | |
641 | check_match(nodes, t_qn_before0raw); | |
642 | ||
643 | o := encQN(c_uqn_before0); | |
644 | nodes := gather(o, ignore_ws); | |
645 | check_match(nodes, t_uqn_before0); | |
646 | ||
647 | o := encQN(c_uqn_before0raw); | |
648 | nodes := gather(o, ignore_ws); | |
649 | check_match(nodes, t_uqn_before0raw); | |
650 | ||
651 | o := encQN(c_qn_before1); | |
652 | nodes := gather(o, ignore_ws); | |
653 | check_match(nodes, t_qn_before1); | |
654 | ||
655 | o := encQN(c_qn_before1raw); | |
656 | nodes := gather(o, ignore_ws); | |
657 | check_match(nodes, t_qn_before1raw); | |
658 | ||
659 | o := encQN(c_uqn_before1); | |
660 | nodes := gather(o, ignore_ws); | |
661 | check_match(nodes, t_uqn_before1); | |
662 | ||
663 | o := encQN(c_uqn_before1raw); | |
664 | nodes := gather(o, ignore_ws); | |
665 | check_match(nodes, t_uqn_before1raw); | |
666 | } | |
667 | ||
668 | // .. .. .. .. replace | |
669 | ||
670 | const QN c_qn_replace0 := c_qn | |
671 | with { | |
672 | erroneous (uri) "value := replacement : ""nagara"" " | |
673 | } | |
674 | ||
675 | template Nodes t_qn_replace0 modifies t_qn := | |
676 | { | |
677 | -, // start element | |
678 | { XML_READER_TYPE_ATTRIBUTE , 1, "replacement", "nagara", "" }, | |
679 | -,- // #text, end element | |
680 | } | |
681 | ||
682 | const QN c_qn_replace0raw := c_qn | |
683 | with { | |
684 | erroneous (uri) "value(raw) := "" nagara='1'"" " | |
685 | } | |
686 | ||
687 | template Nodes t_qn_replace0raw modifies t_qn := | |
688 | { | |
689 | -, // start element | |
690 | { XML_READER_TYPE_ATTRIBUTE , 1, "nagara", "1", "" }, | |
691 | -,- // #text, end element | |
692 | } | |
693 | ||
694 | const QN c_qn_replace1 := c_qn | |
695 | with { | |
696 | erroneous (name) "value := ""nagara"" " | |
697 | } | |
698 | ||
699 | template Nodes t_qn_replace1 modifies t_qn := | |
700 | { | |
701 | -,-, | |
702 | { XML_READER_TYPE_ELEMENT , 1, "CHARSTRING", "", "" }, | |
703 | { XML_READER_TYPE_TEXT , 2, "#text" , "nagara", "" }, | |
704 | { XML_READER_TYPE_END_ELEMENT, 1, "CHARSTRING", "", "" }, | |
705 | t_qn[3] | |
706 | } | |
707 | ||
708 | const QN c_qn_replace1raw := c_qn | |
709 | with { | |
710 | erroneous (name) "value(raw) := ""nagara"" " | |
711 | } | |
712 | ||
713 | template Nodes t_qn_replace1raw modifies t_qn := | |
714 | { | |
715 | -,-, | |
716 | { XML_READER_TYPE_TEXT , 1, "#text", "nagara", "" }, | |
717 | - | |
718 | } | |
719 | ||
720 | const QN c_uqn_replace0 := c_uqn | |
721 | with { | |
722 | erroneous (uri) "value := replacement : ""nagara"" " | |
723 | } | |
724 | ||
725 | template Nodes t_uqn_replace0 modifies t_uqn := | |
726 | { | |
727 | -, // start element | |
728 | { XML_READER_TYPE_ATTRIBUTE , 1, "replacement", "nagara", "" }, | |
729 | t_uqn[1], t_uqn[2] // #text, end element | |
730 | } | |
731 | ||
732 | const QN c_uqn_replace0raw := c_uqn | |
733 | with { | |
734 | erroneous (uri) "value(raw) := "" nagara='1'"" " | |
735 | } | |
736 | ||
737 | template Nodes t_uqn_replace0raw modifies t_uqn := | |
738 | { | |
739 | -, // start element | |
740 | { XML_READER_TYPE_ATTRIBUTE , 1, "nagara", "1", "" }, | |
741 | t_uqn[1], t_uqn[2] // #text, end element | |
742 | } | |
743 | ||
744 | const QN c_uqn_replace1 := c_uqn | |
745 | with { | |
746 | erroneous (name) "value := ""nagara"" " | |
747 | } | |
748 | ||
749 | template Nodes t_uqn_replace1 modifies t_uqn := | |
750 | { | |
751 | -, | |
752 | { XML_READER_TYPE_ELEMENT , 1, "CHARSTRING", "", "" }, | |
753 | { XML_READER_TYPE_TEXT , 2, "#text" , "nagara", "" }, | |
754 | { XML_READER_TYPE_END_ELEMENT, 1, "CHARSTRING", "", "" }, | |
755 | t_uqn[2] | |
756 | } | |
757 | ||
758 | const QN c_uqn_replace1raw := c_uqn | |
759 | with { | |
760 | erroneous (name) "value(raw) := ""nagara"" " | |
761 | } | |
762 | ||
763 | template Nodes t_uqn_replace1raw modifies t_uqn := | |
764 | { | |
765 | -, | |
766 | { XML_READER_TYPE_TEXT , 1, "#text", "nagara", "" }, | |
767 | - | |
768 | } | |
769 | ||
770 | testcase exer_qname_replace() runs on Neg | |
771 | { | |
772 | var octetstring o; | |
773 | var Nodes nodes; | |
774 | ||
775 | o := encQN(c_qn_replace0); | |
776 | nodes := gather(o, ignore_ws); | |
777 | check_match(nodes, t_qn_replace0); | |
778 | ||
779 | o := encQN(c_qn_replace0raw); | |
780 | nodes := gather(o, ignore_ws); | |
781 | check_match(nodes, t_qn_replace0raw); | |
782 | ||
783 | o := encQN(c_qn_replace1); | |
784 | nodes := gather(o, ignore_ws); | |
785 | check_match(nodes, t_qn_replace1); | |
786 | ||
787 | o := encQN(c_qn_replace1raw); | |
788 | nodes := gather(o, ignore_ws); | |
789 | check_match(nodes, t_qn_replace1raw); | |
790 | ||
791 | o := encQN(c_uqn_replace0); | |
792 | nodes := gather(o, ignore_ws); | |
793 | check_match(nodes, t_uqn_replace0); | |
794 | ||
795 | o := encQN(c_uqn_replace0raw); | |
796 | nodes := gather(o, ignore_ws); | |
797 | check_match(nodes, t_uqn_replace0raw); | |
798 | ||
799 | o := encQN(c_uqn_replace1); | |
800 | nodes := gather(o, ignore_ws); | |
801 | check_match(nodes, t_uqn_replace1); | |
802 | ||
803 | o := encQN(c_uqn_replace1raw); | |
804 | nodes := gather(o, ignore_ws); | |
805 | check_match(nodes, t_uqn_replace1raw); | |
806 | } | |
807 | ||
808 | // .. .. .. .. after | |
809 | ||
810 | const QN c_qn_after0 := c_qn | |
811 | with { | |
812 | erroneous (uri) "after := abefore : ""ato de"" " | |
813 | } | |
814 | ||
815 | template Nodes t_qn_after0 modifies t_qn := | |
816 | { | |
817 | -,-, | |
818 | { XML_READER_TYPE_ATTRIBUTE , 1, "abefore", "ato de", "" }, | |
819 | t_qn[2], t_qn[3] | |
820 | } | |
821 | ||
822 | const QN c_qn_after0raw := c_qn | |
823 | with { | |
824 | erroneous (uri) "after(raw) := "" rawafter='Rafter'"" " | |
825 | } // space needed here ------------^ for well-formed XML | |
826 | ||
827 | template Nodes t_qn_after0raw modifies t_qn := | |
828 | { | |
829 | -,-, | |
830 | { XML_READER_TYPE_ATTRIBUTE , 1, "rawafter", "Rafter", "" }, | |
831 | t_qn[2], t_qn[3] | |
832 | } | |
833 | ||
834 | const QN c_qn_after1 := c_qn | |
835 | with { | |
836 | erroneous (name) "after := abefore : ""ato de"" " | |
837 | } | |
838 | ||
839 | template Nodes t_qn_after1 modifies t_qn := | |
840 | { | |
841 | -,-, | |
842 | { XML_READER_TYPE_TEXT , 1, "#text", "b0:nm abefore='ato de'", "" }, | |
843 | - | |
844 | } | |
845 | ||
846 | const QN c_qn_after1raw := c_qn | |
847 | with { | |
848 | erroneous (name) "after(raw) := "" is hot!"" " | |
849 | } | |
850 | ||
851 | template Nodes t_qn_after1raw modifies t_qn := | |
852 | { | |
853 | -,-, | |
854 | { XML_READER_TYPE_TEXT , 1, "#text", "b0:nm is hot!", "" }, | |
855 | - | |
856 | } | |
857 | ||
858 | const QN c_uqn_after0 := c_uqn | |
859 | with { | |
860 | erroneous (uri) "after := abefore : ""ato de"" " | |
861 | } | |
862 | ||
863 | template Nodes t_uqn_after0 modifies t_uqn := | |
864 | { | |
865 | -, | |
866 | { XML_READER_TYPE_ATTRIBUTE , 1, "abefore", "ato de", "" }, | |
867 | t_uqn[1], t_uqn[2] | |
868 | } | |
869 | ||
870 | const QN c_uqn_after0raw := c_uqn | |
871 | with { | |
872 | erroneous (uri) "after(raw) := "" rawafter='Rafter'"" " | |
873 | } // space needed here ------------^ for well-formed XML | |
874 | ||
875 | template Nodes t_uqn_after0raw modifies t_uqn := | |
876 | { | |
877 | -, | |
878 | { XML_READER_TYPE_ATTRIBUTE , 1, "rawafter", "Rafter", "" }, | |
879 | t_uqn[1], t_uqn[2] | |
880 | } | |
881 | ||
882 | const QN c_uqn_after1 := c_uqn | |
883 | with { | |
884 | erroneous (name) "after := abefore : ""ato de"" " | |
885 | } | |
886 | ||
887 | template Nodes t_uqn_after1 modifies t_uqn := | |
888 | { | |
889 | -, | |
890 | { XML_READER_TYPE_TEXT , 1, "#text", "nm abefore='ato de'", "" }, | |
891 | - | |
892 | } | |
893 | ||
894 | const QN c_uqn_after1raw := c_uqn | |
895 | with { | |
896 | erroneous (name) "after(raw) := "" is hot!"" " | |
897 | } | |
898 | ||
899 | template Nodes t_uqn_after1raw modifies t_uqn := | |
900 | { | |
901 | -, | |
902 | { XML_READER_TYPE_TEXT , 1, "#text", "nm is hot!", "" }, | |
903 | - | |
904 | } | |
905 | ||
906 | testcase exer_qname_after() runs on Neg | |
907 | { | |
908 | var octetstring o; | |
909 | var Nodes nodes; | |
910 | ||
911 | o := encQN(c_qn_after0); | |
912 | nodes := gather(o, ignore_ws); | |
913 | check_match(nodes, t_qn_after0); | |
914 | ||
915 | o := encQN(c_qn_after0raw); | |
916 | nodes := gather(o, ignore_ws); | |
917 | check_match(nodes, t_qn_after0raw); | |
918 | ||
919 | o := encQN(c_qn_after1); | |
920 | nodes := gather(o, ignore_ws); | |
921 | check_match(nodes, t_qn_after1); | |
922 | ||
923 | o := encQN(c_qn_after1raw); | |
924 | nodes := gather(o, ignore_ws); | |
925 | check_match(nodes, t_qn_after1raw); | |
926 | ||
927 | o := encQN(c_uqn_after0); | |
928 | nodes := gather(o, ignore_ws); | |
929 | check_match(nodes, t_uqn_after0); | |
930 | ||
931 | o := encQN(c_uqn_after0raw); | |
932 | nodes := gather(o, ignore_ws); | |
933 | check_match(nodes, t_uqn_after0raw); | |
934 | ||
935 | o := encQN(c_uqn_after1); | |
936 | nodes := gather(o, ignore_ws); | |
937 | check_match(nodes, t_uqn_after1); | |
938 | ||
939 | o := encQN(c_uqn_after1raw); | |
940 | nodes := gather(o, ignore_ws); | |
941 | check_match(nodes, t_uqn_after1raw); | |
942 | } | |
943 | ||
944 | // -- -- -- -- -- -- -- -- USE-ORDER -- -- -- -- -- -- -- -- | |
945 | ||
946 | // "Plain" USE-ORDER | |
947 | type record UO { | |
948 | record of enumerated { id, name, price, color } order, | |
949 | ||
950 | integer id, | |
951 | charstring name, | |
952 | float price, | |
953 | charstring color | |
954 | } | |
955 | with { | |
956 | variant "element"; | |
957 | variant "useOrder"; | |
958 | variant "namespace as 'http://www.example.com' prefix 'exm'"; | |
959 | } | |
960 | ||
961 | external function encUO(in UO u) return octetstring | |
962 | with { | |
963 | extension "prototype(convert) encode(XER:XER_EXTENDED)" | |
964 | } | |
965 | ||
966 | const UO c_uo_plain := { | |
967 | order := { id, name, color, price }, // color before price | |
968 | id := 1, | |
969 | name := "shoes", | |
970 | price := 9.99, | |
971 | color := "brown" | |
972 | } | |
973 | ||
974 | template Nodes t_uo_plain := | |
975 | { | |
976 | { XML_READER_TYPE_ELEMENT , 0, "exm:UO", "", "http://www.example.com" }, //0 | |
977 | { XML_READER_TYPE_ATTRIBUTE , 1, "xmlns:exm", "http://www.example.com", "http://www.w3.org/2000/xmlns/"}, | |
978 | ||
979 | { XML_READER_TYPE_ELEMENT , 1, "id" , "", "" }, //2 | |
980 | { XML_READER_TYPE_TEXT , 2, "#text", "1", "" }, | |
981 | { XML_READER_TYPE_END_ELEMENT, 1, "id" , "", "" }, | |
982 | ||
983 | { XML_READER_TYPE_ELEMENT , 1, "name" , "", "" }, //5 | |
984 | { XML_READER_TYPE_TEXT , 2, "#text", "shoes", "" }, | |
985 | { XML_READER_TYPE_END_ELEMENT, 1, "name" , "", "" }, | |
986 | ||
987 | { XML_READER_TYPE_ELEMENT , 1, "color", "", "" }, //8 | |
988 | { XML_READER_TYPE_TEXT , 2, "#text", "brown", "" }, | |
989 | { XML_READER_TYPE_END_ELEMENT, 1, "color", "", "" }, | |
990 | ||
991 | { XML_READER_TYPE_ELEMENT , 1, "price", "", "" }, //11 | |
992 | { XML_READER_TYPE_TEXT , 2, "#text", "9.990000", "" }, | |
993 | { XML_READER_TYPE_END_ELEMENT, 1, "price", "", "" }, | |
994 | ||
995 | { XML_READER_TYPE_END_ELEMENT, 0, "exm:UO", "", "http://www.example.com" } //14 | |
996 | } | |
997 | ||
998 | testcase uo_plain() runs on Neg | |
999 | { | |
1000 | var octetstring o; | |
1001 | var Nodes nodes; | |
1002 | ||
1003 | o := encUO(c_uo_plain); | |
1004 | nodes := gather(o, ignore_ws); | |
1005 | check_match(nodes, t_uo_plain); | |
1006 | } | |
1007 | ||
1008 | const UO c_uo_omit_order := c_uo_plain | |
1009 | with { | |
1010 | erroneous (order) "value := omit" | |
1011 | } | |
1012 | // Omitting the controller member of USE-ORDER has no effect | |
1013 | // (the order field itself is not written to the output). | |
1014 | ||
1015 | const UO c_uo_omit_name := c_uo_plain | |
1016 | with { | |
1017 | erroneous (name) "value := omit" | |
1018 | } | |
1019 | ||
1020 | template Nodes t_uo_omit_name modifies t_uo_plain := { | |
1021 | -,-, -,-,-, // 0-4 (start element and <id>) | |
1022 | // omit 5-7 (name) | |
1023 | t_uo_plain[8], | |
1024 | t_uo_plain[9], | |
1025 | t_uo_plain[10], // <color> | |
1026 | t_uo_plain[11], | |
1027 | t_uo_plain[12], | |
1028 | t_uo_plain[13], // <price> | |
1029 | t_uo_plain[14] // end element | |
1030 | } | |
1031 | ||
1032 | const UO c_uo_omit_price := c_uo_plain | |
1033 | with { | |
1034 | erroneous (price) "value := omit" | |
1035 | } | |
1036 | ||
1037 | template Nodes t_uo_omit_price modifies t_uo_plain := { | |
1038 | -,-, -,-,-, -,-,-, -,-,-, // 0-10 (start element, <id>, <name>, <color>) | |
1039 | // omit 11-13 (price) | |
1040 | t_uo_plain[14] | |
1041 | } | |
1042 | ||
1043 | const UO c_uo_omit_color := c_uo_plain | |
1044 | with { | |
1045 | erroneous (color) "value := omit" | |
1046 | } | |
1047 | ||
1048 | template Nodes t_uo_omit_color modifies t_uo_plain := { | |
1049 | -,-, -,-,-, -,-,-, // 0-7 (start element, <id>, <name>) | |
1050 | // omit 8-10 (color) | |
1051 | t_uo_plain[11], | |
1052 | t_uo_plain[12], | |
1053 | t_uo_plain[13], // price | |
1054 | t_uo_plain[14] | |
1055 | } | |
1056 | ||
1057 | ||
1058 | testcase uo_omit() runs on Neg | |
1059 | { | |
1060 | var octetstring o; | |
1061 | var Nodes nodes; | |
1062 | ||
1063 | o := encUO(c_uo_omit_order); | |
1064 | nodes := gather(o, ignore_ws); | |
1065 | check_match(nodes, t_uo_plain); | |
1066 | ||
1067 | o := encUO(c_uo_omit_name); | |
1068 | nodes := gather(o, ignore_ws); | |
1069 | check_match(nodes, t_uo_omit_name); | |
1070 | ||
1071 | o := encUO(c_uo_omit_price); | |
1072 | nodes := gather(o, ignore_ws); | |
1073 | check_match(nodes, t_uo_omit_price); | |
1074 | ||
1075 | o := encUO(c_uo_omit_color); | |
1076 | nodes := gather(o, ignore_ws); | |
1077 | check_match(nodes, t_uo_omit_color); | |
1078 | } | |
1079 | ||
1080 | // fields: id, name, price, color | |
1081 | // output: id, name, color, price | |
1082 | // 2-4 5-7 8-10 11-13 | |
1083 | ||
1084 | const UO c_uo_omit_after_order := c_uo_plain | |
1085 | with { | |
1086 | erroneous (order) "after := omit all" // after order: that's everything! | |
1087 | } | |
1088 | ||
1089 | template Nodes t_uo_omit_after_order modifies t_uo_plain := { | |
1090 | -,- // just the (empty) start element with the namespace attribute | |
1091 | } | |
1092 | ||
1093 | const UO c_uo_omit_after_name := c_uo_plain | |
1094 | with { | |
1095 | erroneous (name) "after := omit all" // after name: price, color | |
1096 | } | |
1097 | ||
1098 | template Nodes t_uo_omit_after_name modifies t_uo_plain := { | |
1099 | -,-, -,-,-, -,-,-, // 0-7 (start element, <id>, <name>) | |
1100 | // omit 8-13 (price, color) | |
1101 | t_uo_plain[14] | |
1102 | } | |
1103 | ||
1104 | const UO c_uo_omit_after_price := c_uo_plain | |
1105 | with { | |
1106 | erroneous (price) "after := omit all" // after price: that's just color | |
1107 | } | |
1108 | ||
1109 | template Nodes t_uo_omit_after_price modifies t_uo_plain := { | |
1110 | -,-, -,-,-, -,-,-, // 0-7 (start element, <id>, <name>) | |
1111 | // omit 8-10 | |
1112 | t_uo_plain[11], | |
1113 | t_uo_plain[12], | |
1114 | t_uo_plain[13], // <price> | |
1115 | t_uo_plain[14] | |
1116 | } | |
1117 | ||
1118 | testcase uo_omit_after() runs on Neg | |
1119 | { | |
1120 | var octetstring o; | |
1121 | var Nodes nodes; | |
1122 | ||
1123 | ||
1124 | o := encUO(c_uo_omit_after_name); | |
1125 | nodes := gather(o, ignore_ws); | |
1126 | check_match(nodes, t_uo_omit_after_name); | |
1127 | ||
1128 | o := encUO(c_uo_omit_after_price); | |
1129 | nodes := gather(o, ignore_ws); | |
1130 | check_match(nodes, t_uo_omit_after_price); | |
1131 | ||
1132 | o := encUO(c_uo_omit_after_order); | |
1133 | nodes := gather(o, ignore_ws); | |
1134 | check_match(nodes, t_uo_omit_after_order); | |
1135 | } | |
1136 | ||
1137 | // -- -- -- -- -- -- -- -- -- -- USE-NIL | |
1138 | ||
1139 | type enumerated ProductColor0 { red(0), green(1), blue(2) } | |
1140 | ||
1141 | // useNil on the type (record) | |
1142 | type record Size { | |
1143 | integer sizeval optional | |
1144 | } | |
1145 | with { variant "useNil" } | |
1146 | ||
1147 | type record NilProduct { | |
1148 | charstring name, | |
1149 | ProductColor0 color, | |
1150 | Size size | |
1151 | } | |
1152 | ||
1153 | external function encNP(in NilProduct n) return octetstring | |
1154 | with { | |
1155 | extension "prototype(convert) encode(XER:XER_EXTENDED)" | |
1156 | } | |
1157 | ||
1158 | const NilProduct c_np_present := | |
1159 | { | |
1160 | name := "shirt", | |
1161 | color := red, | |
1162 | size := { 10 } | |
1163 | } | |
1164 | ||
1165 | /* | |
1166 | "<NilProduct>\n" & | |
1167 | "\t<name>shirt</name>\n" & | |
1168 | "\t<color>red</color>\n" & | |
1169 | "\t<size>10</size>\n" & | |
1170 | "</NilProduct>\n" & | |
1171 | */ | |
1172 | template Nodes t_np_present := | |
1173 | { | |
1174 | { XML_READER_TYPE_ELEMENT , 0, "NilProduct", "", ""}, //0 | |
1175 | ||
1176 | { XML_READER_TYPE_ELEMENT , 1, "name", "", ""}, //1 | |
1177 | { XML_READER_TYPE_TEXT , 2, "#text", "shirt", ""}, | |
1178 | { XML_READER_TYPE_END_ELEMENT, 1, "name", "", ""}, | |
1179 | ||
1180 | { XML_READER_TYPE_ELEMENT , 1, "color", "", ""}, //4 | |
1181 | { XML_READER_TYPE_TEXT , 2, "#text", "red", ""}, | |
1182 | { XML_READER_TYPE_END_ELEMENT, 1, "color", "", ""}, | |
1183 | ||
1184 | { XML_READER_TYPE_ELEMENT , 1, "size", "", ""}, //7 | |
1185 | { XML_READER_TYPE_TEXT , 2, "#text", "10", ""}, | |
1186 | { XML_READER_TYPE_END_ELEMENT, 1, "size", "", ""}, | |
1187 | ||
1188 | { XML_READER_TYPE_END_ELEMENT, 0, "NilProduct", "", ""} //10 | |
1189 | } | |
1190 | //template integer n_np_present := lengthof(t_np_present); | |
1191 | ||
1192 | const NilProduct c_np_absent := | |
1193 | { | |
1194 | name := "no shirt", | |
1195 | color := red, | |
1196 | size := { omit } | |
1197 | } | |
1198 | ||
1199 | /* | |
1200 | "<NilProduct xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\'>\n" & // 0-1 | |
1201 | "\t<name>no shirt</name>\n" & //2-4 | |
1202 | "\t<color>red</color>\n" & //5-7 | |
1203 | "\t<size xsi:nil=\'true\'/>\n" & //8-9 | |
1204 | "</NilProduct>\n" & //10 | |
1205 | */ | |
1206 | template Nodes t_np_absent := | |
1207 | { // type depth, name, value, ns | |
1208 | { XML_READER_TYPE_ELEMENT , 0, "NilProduct", "", ""}, //0 | |
1209 | { XML_READER_TYPE_ATTRIBUTE , 1, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/2000/xmlns/"}, | |
1210 | ||
1211 | { XML_READER_TYPE_ELEMENT , 1, "name", "", ""}, //2 | |
1212 | { XML_READER_TYPE_TEXT , 2, "#text", "no shirt", ""}, | |
1213 | { XML_READER_TYPE_END_ELEMENT, 1, "name", "", ""}, | |
1214 | ||
1215 | { XML_READER_TYPE_ELEMENT , 1, "color", "", ""}, //5 | |
1216 | { XML_READER_TYPE_TEXT , 2, "#text", "red", ""}, | |
1217 | { XML_READER_TYPE_END_ELEMENT, 1, "color", "", ""}, | |
1218 | ||
1219 | { XML_READER_TYPE_ELEMENT , 1, "size", "", ""}, //8 | |
1220 | { XML_READER_TYPE_ATTRIBUTE , 2, "xsi:nil", "true", "http://www.w3.org/2001/XMLSchema-instance"}, | |
1221 | ||
1222 | { XML_READER_TYPE_END_ELEMENT, 0, "NilProduct", "", ""} //10 | |
1223 | } | |
1224 | ||
1225 | ||
1226 | testcase unil_plain() runs on Neg | |
1227 | { | |
1228 | var octetstring o; | |
1229 | var Nodes nodes; | |
1230 | ||
1231 | o := encNP(c_np_present); | |
1232 | nodes := gather(o, ignore_ws); | |
1233 | check_match(nodes, t_np_present); | |
1234 | ||
1235 | o := encNP(c_np_absent); | |
1236 | nodes := gather(o, ignore_ws); | |
1237 | check_match(nodes, t_np_absent); | |
1238 | ||
1239 | } | |
1240 | ||
1241 | // -- -- -- -- -- -- -- -- -- -- -- REPLACE | |
1242 | ||
1243 | const NilProduct c_np_present_omit := c_np_present | |
1244 | with { | |
1245 | erroneous (size) "value := omit" | |
1246 | } | |
1247 | ||
1248 | /* | |
1249 | <NilProduct> | |
1250 | <name>shirt</name> | |
1251 | <color>red</color> <!-- size missing completely --> | |
1252 | </NilProduct> | |
1253 | */ | |
1254 | template Nodes t_np_present_omit modifies t_np_present := { | |
1255 | -,-,-,-,-,-,-, // 0-6 | |
1256 | // 7-9 omit: <size> #text </size> | |
1257 | t_np_present[10] | |
1258 | } | |
1259 | ||
1260 | const NilProduct c_np_present_omit_raw := c_np_present | |
1261 | with { | |
1262 | erroneous (size) "value(raw) := ""<size/>"" " | |
1263 | } | |
1264 | ||
1265 | template Nodes t_np_present_omit_raw modifies t_np_present := { | |
1266 | -, -,-,-, -,-,-, // 0-6, | |
1267 | ||
1268 | -, // <size> start element | |
1269 | ||
1270 | // 8-9 omit: no #text or </size> | |
1271 | ||
1272 | t_np_present[10] | |
1273 | } | |
1274 | ||
1275 | const NilProduct c_np_present_omit_member := c_np_present | |
1276 | with { | |
1277 | erroneous (size.sizeval) "value := omit" | |
1278 | } | |
1279 | ||
1280 | /* | |
1281 | <NilProduct> | |
1282 | <name>shirt</name> | |
1283 | <color>red</color> | |
1284 | <size xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true'/> | |
1285 | </NilProduct> | |
1286 | */ | |
1287 | template Nodes t_np_present_omit_member modifies t_np_present := { | |
1288 | -, -,-,-, -,-,-, // 0-6, | |
1289 | -, // <size> start element | |
1290 | { XML_READER_TYPE_ATTRIBUTE , 2, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/2000/xmlns/"}, | |
1291 | t_np_absent[9], // xsi:nil=true | |
1292 | // 8-9 omit: no #text or </size> | |
1293 | t_np_present[10] | |
1294 | } | |
1295 | ||
1296 | const NilProduct c_np_present_omit_member_raw := c_np_present | |
1297 | with { | |
1298 | erroneous (size.sizeval) "value(raw) := ""cool!"" " | |
1299 | } | |
1300 | ||
1301 | template Nodes t_np_present_omit_member_raw modifies t_np_present := { | |
1302 | -, -,-,-, -,-,-, // 0-6, | |
1303 | -, // <size> start element | |
1304 | { XML_READER_TYPE_TEXT , 2, "#text", "\ncool!", ""}, // #text changed | |
1305 | -, // </size> | |
1306 | - // </NilProduct> | |
1307 | } | |
1308 | ||
1309 | ||
1310 | // making a "present" disappear | |
1311 | testcase unil_present_to_omit() runs on Neg | |
1312 | { | |
1313 | var octetstring o; | |
1314 | var Nodes nodes; | |
1315 | ||
1316 | o := encNP(c_np_present_omit); | |
1317 | nodes := gather(o, ignore_ws); | |
1318 | check_match(nodes, t_np_present_omit); | |
1319 | ||
1320 | o := encNP(c_np_present_omit_raw); | |
1321 | nodes := gather(o, ignore_ws); | |
1322 | check_match(nodes, t_np_present_omit_raw); | |
1323 | ||
1324 | o := encNP(c_np_present_omit_member); | |
1325 | nodes := gather(o, ignore_ws); | |
1326 | check_match(nodes, t_np_present_omit_member); | |
1327 | ||
1328 | o := encNP(c_np_present_omit_member_raw); | |
1329 | nodes := gather(o, ignore_ws); | |
1330 | check_match(nodes, t_np_present_omit_member_raw); | |
1331 | } | |
1332 | ||
1333 | ||
1334 | const NilProduct c_np_absent_rez := c_np_absent | |
1335 | with { | |
1336 | erroneous (size) "value := Size : { 42 }" | |
1337 | } | |
1338 | ||
1339 | template Nodes t_np_absent_rez modifies t_np_absent := | |
1340 | { | |
1341 | -,-, //0-1: start-element, xsi namespace | |
1342 | -,-,-, -,-,-, // 2-7: name and color | |
1343 | ||
1344 | { XML_READER_TYPE_ELEMENT , 1, "Size", "", ""}, // should be same as t_np_absent[8] | |
1345 | { XML_READER_TYPE_TEXT , 2, "#text", "42", "" }, // text | |
1346 | { XML_READER_TYPE_END_ELEMENT, 1, "Size", "", ""}, | |
1347 | t_np_absent[10] // end element | |
1348 | } | |
1349 | ||
1350 | const NilProduct c_np_absent_rez_member := c_np_absent | |
1351 | with { | |
1352 | erroneous (size.sizeval) "value := 1" | |
1353 | } | |
1354 | ||
1355 | template Nodes t_np_absent_rez_member modifies t_np_absent := | |
1356 | { | |
1357 | -,-, //0-1: start-element, xsi namespace | |
1358 | -,-,-, -,-,-, // 2-7: name and color | |
1359 | ||
1360 | { XML_READER_TYPE_ELEMENT , 1, "size", "", ""}, // should be same as t_np_absent[8] | |
1361 | { XML_READER_TYPE_TEXT , 2, "#text", "1", "" }, // text | |
1362 | { XML_READER_TYPE_END_ELEMENT, 1, "size", "", ""}, | |
1363 | t_np_absent[10] // end element | |
1364 | } | |
1365 | ||
1366 | // making an "omit" reappear | |
1367 | testcase unil_absent_to_present() runs on Neg | |
1368 | { | |
1369 | var octetstring o; | |
1370 | var Nodes nodes; | |
1371 | ||
1372 | o := encNP(c_np_absent_rez); | |
1373 | nodes := gather(o, ignore_ws); | |
1374 | check_match(nodes, t_np_absent_rez); | |
1375 | ||
1376 | o := encNP(c_np_absent_rez_member); | |
1377 | nodes := gather(o, ignore_ws); | |
1378 | check_match(nodes, t_np_absent_rez_member); | |
1379 | } | |
1380 | ||
1381 | } | |
1382 | with { | |
1383 | encode "XML"; | |
1384 | variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'" | |
1385 | } |