1 /******************************************************************************
2 * Copyright (c) 2000-2015 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 ******************************************************************************/
9 import from ReadXml all;
10 import from rec { type Neg; function check_match }
25 external function encUT(in UT u) return octetstring
27 extension "prototype(convert) encode(XER:XER_EXTENDED)"
34 template Nodes t_ut_i := {
35 { XML_READER_TYPE_ELEMENT , 0, "UT", "", "" },
36 { XML_READER_TYPE_TEXT , 1, "#text", "42", "" },
37 { XML_READER_TYPE_END_ELEMENT, 0, "UT", "", "" }
44 template Nodes t_ut_s := {
45 // node_type , depth, name, value, namespace
46 { XML_READER_TYPE_ELEMENT , 0, "UT", "", "" },
47 { XML_READER_TYPE_ATTRIBUTE , 1, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/2000/xmlns/" },
48 // this is the value for "xmlns:xsi" ------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49 // this is the namespace for "xsi:type" ------------vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
50 { XML_READER_TYPE_ATTRIBUTE , 1, "xsi:type" , "s", "http://www.w3.org/2001/XMLSchema-instance" },
51 { XML_READER_TYPE_TEXT , 1, "#text", "Hello, world!", "" },
52 { XML_READER_TYPE_END_ELEMENT, 0, "UT", "", "" }
56 r := { b := true, f := 3.141592 }
60 <UT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='r'>
65 template Nodes t_ut_rf := {
66 // node_type , depth, name, value, namespace
67 { XML_READER_TYPE_ELEMENT , 0, "UT", "", "" },
68 { XML_READER_TYPE_ATTRIBUTE , 1, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/2000/xmlns/" },
69 { XML_READER_TYPE_ATTRIBUTE , 1, "xsi:type" , "r", "http://www.w3.org/2001/XMLSchema-instance" },
71 { XML_READER_TYPE_ELEMENT , 1, "b", "", "" },
72 { XML_READER_TYPE_TEXT , 2, "#text", "true", "" },
73 { XML_READER_TYPE_END_ELEMENT, 1, "b", "", "" },
75 { XML_READER_TYPE_ELEMENT , 1, "f", "", "" },
76 { XML_READER_TYPE_TEXT , 2, "#text", "3.141592", "" },
77 { XML_READER_TYPE_END_ELEMENT, 1, "f", "", "" },
79 { XML_READER_TYPE_END_ELEMENT, 0, "UT", "", "" }
82 testcase ut_plain() runs on Neg
88 nodes := gather(o, ignore_ws);
89 check_match(nodes, t_ut_i);
92 nodes := gather(o, ignore_ws);
93 check_match(nodes, t_ut_s);
96 nodes := gather(o, ignore_ws);
97 check_match(nodes, t_ut_rf);
102 const UT c_ut_i_replace := c_ut_i
104 erroneous (i) "value := ""fourty-two"" "
107 template Nodes t_ut_i_replace modifies t_ut_i := {
109 { XML_READER_TYPE_TEXT , 1, "#text", "fourty-two", "" },
113 const UT c_ut_s_replace := c_ut_s
115 erroneous (s) "value := 'DECAFBAD'O"
116 } // '4548 4c4c 2c4f 5720 524f 444c'O
118 template Nodes t_ut_s_replace modifies t_ut_s := {
120 { XML_READER_TYPE_TEXT , 1, "#text", "DECAFBAD", "" },
124 const UT c_ut_s_replace_raw := c_ut_s
126 erroneous (s) "value(raw) := '48454c4c4f2c20574f524c44'O"
129 template Nodes t_ut_s_replace_raw modifies t_ut_s := {
131 { XML_READER_TYPE_TEXT , 1, "#text", "HELLO, WORLD", "" },
135 const UT c_ut_rf_replace := c_ut_rf
137 erroneous (r) "value := UT.r : { b := true, f := 2.71828 }"
140 template Nodes t_ut_rf_replace modifies t_ut_rf := {
144 { XML_READER_TYPE_TEXT , 2, "#text", "2.718280", "" },
148 testcase ut_replace() runs on Neg
153 o := encUT(c_ut_i_replace);
154 nodes := gather(o, ignore_ws);
155 check_match(nodes, t_ut_i_replace);
157 o := encUT(c_ut_s_replace);
158 nodes := gather(o, ignore_ws);
159 check_match(nodes, t_ut_s_replace);
161 o := encUT(c_ut_s_replace_raw);
162 nodes := gather(o, ignore_ws);
163 check_match(nodes, t_ut_s_replace_raw);
165 o := encUT(c_ut_rf_replace);
166 nodes := gather(o, ignore_ws);
167 check_match(nodes, t_ut_rf_replace);
170 // -- -- -- -- -- -- -- -- -- -- -- -- USE-TYPE
176 variant (available) "attribute"
189 external function encUT2(in UT2 u) return octetstring
190 with { extension "prototype(convert) encode(XER:XER_EXTENDED)" }
192 const UT2 c_ut_r := {
193 r := { available := true }
196 template Nodes t_ut_r := {
197 // node_type , depth, name, value, namespace
198 { XML_READER_TYPE_ELEMENT , 0, "UT2", "", "" },
199 { XML_READER_TYPE_ATTRIBUTE , 1, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/2000/xmlns/" },
200 // this is the value for "xmlns:xsi" ------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
201 // this is the namespace for "xsi:type" ------------vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
202 { XML_READER_TYPE_ATTRIBUTE , 1, "xsi:type" , "r", "http://www.w3.org/2001/XMLSchema-instance" },
203 { XML_READER_TYPE_ATTRIBUTE , 1, "available", "true", "" },
204 //{ XML_READER_TYPE_TEXT , 1, "#text", "\n", "" },
205 { XML_READER_TYPE_END_ELEMENT, 0, "UT2", "", "" }
209 testcase ut_nested_plain() runs on Neg
215 nodes := gather(o, ignore_ws);
216 check_match(nodes, t_ut_r);
219 const UT2 c_ut_r_replace := c_ut_r
221 erroneous (r) "value := R : { available := false } ";
224 template Nodes t_ut_r_replace modifies t_ut_r := {
225 -,-,-, // start element, xmlns:xsi, xsi:type
226 { XML_READER_TYPE_ATTRIBUTE , 1, "available", "false", "" },
230 testcase ut_nested_replace() runs on Neg
235 o := encUT2(c_ut_r_replace);
236 nodes := gather(o, ignore_ws);
237 check_match(nodes, t_ut_r_replace);
240 // -- -- -- -- -- -- -- -- -- -- -- -- -- --
242 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- USE-UNION
253 external function encUU(in UU u) return octetstring
255 extension "prototype(convert) encode(XER:XER_EXTENDED)"
262 template Nodes t_uu_i := {
263 { XML_READER_TYPE_ELEMENT , 0, "UU", "", "" },
264 { XML_READER_TYPE_ATTRIBUTE , 1, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/2000/xmlns/" },
265 // this is the value for "xmlns:xsi" ------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
266 // this is the namespace for "xsi:type" ------------vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
267 { XML_READER_TYPE_ATTRIBUTE , 1, "xsi:type" , "i", "http://www.w3.org/2001/XMLSchema-instance" },
268 { XML_READER_TYPE_TEXT , 1, "#text", "42", "" },
269 { XML_READER_TYPE_END_ELEMENT, 0, "UU", "", "" }
276 template Nodes t_uu_s := {
277 // node_type , depth, name, value, namespace
278 { XML_READER_TYPE_ELEMENT , 0, "UU", "", "" },
279 { XML_READER_TYPE_ATTRIBUTE , 1, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/2000/xmlns/" },
280 // this is the value for "xmlns:xsi" ------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
281 // this is the namespace for "xsi:type" ------------vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
282 { XML_READER_TYPE_ATTRIBUTE , 1, "xsi:type" , "s", "http://www.w3.org/2001/XMLSchema-instance" },
283 { XML_READER_TYPE_TEXT , 1, "#text", "Hello, world!", "" },
284 { XML_READER_TYPE_END_ELEMENT, 0, "UU", "", "" }
288 testcase uu_plain() runs on Neg
294 nodes := gather(o, ignore_ws);
295 check_match(nodes, t_uu_i);
298 nodes := gather(o, ignore_ws);
299 check_match(nodes, t_uu_s);
305 variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'"