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