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 exer_rec_of { | |
9 | ||
10 | type record of charstring stringlist | |
11 | with { variant "list" } | |
12 | ||
13 | external function encSL(in stringlist pars) return octetstring | |
14 | with { extension "prototype(convert) encode(XER:XER_EXTENDED)" } | |
15 | ||
16 | ||
17 | import from ReadXml all; | |
18 | import from rec { type Neg; function check_match } | |
19 | ||
20 | const stringlist c_marx_plain := { "chico", "groucho", "harpo" } | |
21 | ||
22 | template Nodes t_plain := { | |
23 | // node_type, depth, name, value | |
24 | { XML_READER_TYPE_ELEMENT , 0, "stringlist", "", "" }, | |
25 | { XML_READER_TYPE_TEXT , 1, "#text" , "chico groucho harpo", "" }, | |
26 | { XML_READER_TYPE_END_ELEMENT, 0, "stringlist", "", "" } | |
27 | }; | |
28 | ||
29 | const stringlist c_marx_before0 := { "chico", "groucho", "harpo" } | |
30 | with { erroneous ([0]) "before := ""karl"" " } | |
31 | ||
32 | template Nodes t_before0 modifies t_plain := { | |
33 | [1] := { XML_READER_TYPE_TEXT, 1, "#text", "karl chico groucho harpo", "" } | |
34 | }; | |
35 | ||
36 | const stringlist c_marx_before0raw := { "chico", "groucho", "harpo" } | |
37 | with { erroneous ([0]) "before(raw) := ""karl,"" " } | |
38 | ||
39 | template Nodes t_before0raw modifies t_plain := { | |
40 | [1] := { XML_READER_TYPE_TEXT, 1, "#text", "karl,chico groucho harpo", "" } | |
41 | // Note: no space after ``karl,'' ---------------^ | |
42 | }; | |
43 | ||
44 | testcase exer_recof_plain() runs on Neg | |
45 | { | |
46 | var octetstring o; | |
47 | var Nodes nodes; | |
48 | ||
49 | o := encSL(c_marx_plain); | |
50 | nodes := gather(o, ignore_ws); | |
51 | check_match(nodes, t_plain); | |
52 | } | |
53 | ||
54 | testcase exer_recof_before0() runs on Neg | |
55 | { | |
56 | var octetstring o; | |
57 | var Nodes nodes; | |
58 | ||
59 | o := encSL(c_marx_before0); | |
60 | nodes := gather(o, ignore_ws); | |
61 | check_match(nodes, t_before0); | |
62 | ||
63 | o := encSL(c_marx_before0raw); | |
64 | nodes := gather(o, ignore_ws); | |
65 | check_match(nodes, t_before0raw); | |
66 | } | |
67 | ||
68 | // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | |
69 | ||
70 | type record Container { | |
71 | record of universal charstring aa | |
72 | } | |
73 | with { | |
74 | variant (aa) "anyAttributes" | |
75 | } | |
76 | ||
77 | external function enc_aa(in Container c) return octetstring | |
78 | with { | |
79 | extension "prototype(convert) encode(XER:XER_EXTENDED)" | |
80 | } | |
81 | ||
82 | const Container c_aa_plain := { | |
83 | aa := { | |
84 | // AnyAttributeFormat: | |
85 | // "URI(optional), space, NCName, equals, \"xmlcstring\"" | |
86 | "uri:geller bender=""true""", // Apostrophe does not work :( | |
87 | "Randi=""sceptic""", | |
88 | "http://www.matrix.org neo=""1""" | |
89 | } | |
90 | } | |
91 | ||
92 | const Container c_aa_plain_trouble := { | |
93 | aa := { | |
94 | // AnyAttributeFormat: | |
95 | // "URI(optional), space, NCName, equals, \"xmlcstring\"" | |
96 | "uri:geller\t\tbender=""true""", // Apostrophe does not work :( | |
97 | "Randi=""sceptic""", | |
98 | "http://www.matrix.org neo=""1"" " | |
99 | } | |
100 | } | |
101 | ||
102 | template Nodes t_aa_plain := { | |
103 | // node_type , depth, name, value | |
104 | { XML_READER_TYPE_ELEMENT , 0, "Container", "", "" }, | |
105 | { XML_READER_TYPE_ATTRIBUTE , 1, "xmlns:b0", "uri:geller", "http://www.w3.org/2000/xmlns/" }, | |
106 | { XML_READER_TYPE_ATTRIBUTE , 1, "xmlns:b2", "http://www.matrix.org", "http://www.w3.org/2000/xmlns/" }, | |
107 | { XML_READER_TYPE_ATTRIBUTE , 1, "b0:bender", "true", "uri:geller" }, | |
108 | { XML_READER_TYPE_ATTRIBUTE , 1, "Randi", "sceptic", "" }, | |
109 | { XML_READER_TYPE_ATTRIBUTE , 1, "b2:neo", "1", "http://www.matrix.org" } | |
110 | // no { XML_READER_TYPE_END_ELEMENT, 0, "Container", "" } | |
111 | } | |
112 | ||
113 | testcase aa_plain() runs on Neg | |
114 | { | |
115 | var octetstring o; | |
116 | var Nodes nodes; | |
117 | ||
118 | o := enc_aa(c_aa_plain); | |
119 | nodes := gather(o, ignore_ws); | |
120 | check_match(nodes, t_aa_plain); | |
121 | ||
122 | o := enc_aa(c_aa_plain_trouble); | |
123 | nodes := gather(o, ignore_ws); | |
124 | check_match(nodes, t_aa_plain); | |
125 | } | |
126 | ||
127 | //-------------------------------------- BEFORE | |
128 | ||
129 | type charstring main_screen | |
130 | with { variant "attribute" } | |
131 | ||
132 | const Container c_aa_before0 := c_aa_plain | |
133 | with { | |
134 | erroneous (aa[0]) "before := main_screen:""on"" " | |
135 | } | |
136 | ||
137 | template Nodes t_aa_before0 modifies t_aa_plain := { | |
138 | -, //0. element | |
139 | -, //1. attribute (ns) | |
140 | -, //2. attribute (ns) | |
141 | // here comes the disturbance: an extra attribute | |
142 | { XML_READER_TYPE_ATTRIBUTE , 1, "main_screen", "on", "" }, //3. | |
143 | t_aa_plain[3], | |
144 | t_aa_plain[4], | |
145 | t_aa_plain[5] | |
146 | } | |
147 | ||
148 | const Container c_aa_before0raw := c_aa_plain | |
149 | with { | |
150 | erroneous (aa[0]) "before(raw) := "" move='zig'"" " | |
151 | // the space here ------------------^ | |
152 | // ensures that we get a well-formed XML | |
153 | } | |
154 | ||
155 | template Nodes t_aa_before0raw modifies t_aa_plain := { | |
156 | -, //0. element | |
157 | -, //1. attribute (ns) | |
158 | -, //2. attribute (ns) | |
159 | // here comes the disturbance: an extra attribute | |
160 | { XML_READER_TYPE_ATTRIBUTE , 1, "move", "zig", "" }, //3. | |
161 | t_aa_plain[3], | |
162 | t_aa_plain[4], | |
163 | t_aa_plain[5] | |
164 | } | |
165 | ||
166 | ||
167 | testcase aa_before0() runs on Neg | |
168 | { | |
169 | var octetstring o; | |
170 | var Nodes nodes; | |
171 | ||
172 | o := enc_aa(c_aa_before0); | |
173 | nodes := gather(o, ignore_ws); | |
174 | check_match(nodes, t_aa_before0); | |
175 | ||
176 | o := enc_aa(c_aa_before0raw); | |
177 | nodes := gather(o, ignore_ws); | |
178 | check_match(nodes, t_aa_before0raw); | |
179 | } | |
180 | ||
181 | //-------------------------------------- REPLACE | |
182 | ||
183 | const Container c_aa_replace0 := c_aa_plain | |
184 | with { | |
185 | erroneous (aa[0]) "value := main_screen:""off"" " | |
186 | } | |
187 | ||
188 | template Nodes t_aa_replace0 modifies t_aa_plain := { | |
189 | // node_type , depth, name, value | |
190 | { XML_READER_TYPE_ELEMENT , 0, "Container", "", "" }, | |
191 | //namespace for #0, not written { XML_READER_TYPE_ATTRIBUTE , 1, "xmlns:b0", "uri:geller", "http://www.w3.org/2000/xmlns/" }, | |
192 | { XML_READER_TYPE_ATTRIBUTE , 1, "xmlns:b2", "http://www.matrix.org", "http://www.w3.org/2000/xmlns/" }, | |
193 | ||
194 | //element #0 replaced { XML_READER_TYPE_ATTRIBUTE , 1, "b0:bender", "true", "uri:geller" }, | |
195 | { XML_READER_TYPE_ATTRIBUTE , 1, "main_screen", "off", "" }, | |
196 | ||
197 | { XML_READER_TYPE_ATTRIBUTE , 1, "Randi", "sceptic", "" }, | |
198 | { XML_READER_TYPE_ATTRIBUTE , 1, "b2:neo", "1", "http://www.matrix.org" } | |
199 | // no { XML_READER_TYPE_END_ELEMENT, 0, "Container", "" } | |
200 | } | |
201 | ||
202 | const Container c_aa_replace0raw := c_aa_plain | |
203 | with { | |
204 | erroneous (aa[0]) "value(raw) := "" main_screen='off'"" " | |
205 | // again, space here --------------^ for well-formed XML | |
206 | } | |
207 | ||
208 | ||
209 | testcase aa_replace0() runs on Neg | |
210 | { | |
211 | var octetstring o; | |
212 | var Nodes nodes; | |
213 | ||
214 | o := enc_aa(c_aa_replace0); | |
215 | nodes := gather(o, ignore_ws); | |
216 | check_match(nodes, t_aa_replace0); | |
217 | ||
218 | o := enc_aa(c_aa_replace0raw); | |
219 | nodes := gather(o, ignore_ws); | |
220 | check_match(nodes, t_aa_replace0); | |
221 | } | |
222 | ||
223 | //-------------------------------------- AFTER | |
224 | ||
225 | const Container c_aa_after2 := c_aa_plain | |
226 | with { | |
227 | erroneous (aa[2]) "after := main_screen : ""turn on"" " | |
228 | } | |
229 | ||
230 | template Nodes t_aa_after2 modifies t_aa_plain := { | |
231 | -,-,-,-,-,-, | |
232 | { XML_READER_TYPE_ATTRIBUTE, 1, "main_screen", "turn on", "" } | |
233 | } | |
234 | ||
235 | const Container c_aa_after2raw := c_aa_plain | |
236 | with { | |
237 | erroneous (aa[2]) "after(raw) := "" main_screen='turn on'"" " | |
238 | } | |
239 | ||
240 | testcase aa_after() runs on Neg | |
241 | { | |
242 | var octetstring o; | |
243 | var Nodes nodes; | |
244 | ||
245 | o := enc_aa(c_aa_after2); | |
246 | nodes := gather(o, ignore_ws); | |
247 | check_match(nodes, t_aa_after2); | |
248 | ||
249 | o := enc_aa(c_aa_after2raw); | |
250 | nodes := gather(o, ignore_ws); | |
251 | check_match(nodes, t_aa_after2); | |
252 | } | |
253 | ||
254 | } | |
255 | with { | |
256 | encode "XML"; | |
257 | optional "implicit omit"; | |
258 | } |