add test for frames and bytes properties of empty movies
[swfdec.git] / test / trace / xml-node.as
blobe5c5e146494f1c6d2f96033b01728c2719b2bf14
1 // makeswf -v 7 -r 1 -o xml-node-7.swf xml-node.as
3 #include "values.as"
5 // Test XMLNode issues that are not handled by xml-parse test
7 function test_childNodes ()
9 var x = new XML ("<root><a/><b/>c<d/></root>");
10 var root = x.firstChild;
12 // normal
13 trace (root);
14 trace (root.childNodes);
16 // add fake elements to childNodes array and test what methods reset the array
17 root.childNodes.push ("fake");
18 trace (root.childNodes);
19 root.firstChild.removeNode ();
20 trace (root.childNodes);
21 root.childNodes.push (new XMLNode (1, "fake"));
22 trace (root.childNodes);
23 root.appendChild (new XMLNode (1, "e"));
24 trace (root.childNodes);
25 ASSetPropFlags (root.childNodes, "0", 0, 4); // remove write-protection
26 root.childNodes[0] = new XMLNode (3, "fake");
27 trace (root.childNodes);
28 root.insertBefore (new XMLNode (1, "f"), root.lastChild);
29 trace (root.childNodes);
32 function test_references ()
34 var x = new XML ("<parent><previoussibling/><root><firstchild/><middlechild/><lastchild/></root><nextsibling/></parent>");
35 var root = x.firstChild.firstChild.nextSibling;
37 // normal
38 trace (root.parentNode.nodeName);
39 trace (root.firstChild.nodeName);
40 trace (root.lastChild.nodeName);
41 trace (root.nextSibling.nodeName);
42 trace (root.previousSibling.nodeName);
43 trace (root.hasChildNodes ());
45 // writing
46 root.parentNode = new XMLNode (1, "test");
47 root.firstChild = new XMLNode (1, "test");
48 root.lastChild = new XMLNode (1, "test");
49 root.nextSibling = new XMLNode (1, "test");
50 root.previousSibling = new XMLNode (1, "test");
51 trace (root.parentNode.nodeName);
52 trace (root.firstChild.nodeName);
53 trace (root.lastChild.nodeName);
54 trace (root.nextSibling.nodeName);
55 trace (root.previousSibling.nodeName);
56 trace (root.hasChildNodes ());
58 // not found
59 root = new XMLNode (1, "root");
60 trace (root.parentNode);
61 trace (root.firstChild);
62 trace (root.lastChild);
63 trace (root.nextSibling);
64 trace (root.previousSibling);
65 trace (root.hasChildNodes ());
67 // fake elements in childNodes array
68 root.childNodes.push (new XMLNode (1, "fake"));
69 trace (root.parentNode);
70 trace (root.firstChild);
71 trace (root.lastChild);
72 trace (root.nextSibling);
73 trace (root.previousSibling);
74 trace (root.hasChildNodes ());
77 function test_cloneNode ()
79 var x = new XML ("<root><a/><b/>c<d/></root>");
80 var root = x.firstChild;
82 // normal
83 var root2 = root.cloneNode ();
84 trace (root2.childNodes);
85 root2 = root.cloneNode (false);
86 trace (root2.childNodes);
87 root2 = root.cloneNode (true);
88 trace (root2.childNodes);
90 // fake elements in childNodes array
91 root.childNodes.push (new XMLNode (1, "fake"));
92 root2 = root.cloneNode (true);
93 trace (root2.childNodes);
96 function test_nodeName ()
98 var a = new XMLNode (1, "a:b");
100 // normal
101 trace (a.nodeName);
102 trace (a.prefix);
103 trace (a.localName);
104 a.nodeName = "c:d";
105 trace (a.nodeName);
106 trace (a.prefix);
107 trace (a.localName);
108 // these are read-only
109 a.prefix = "e";
110 trace (a.nodeName);
111 trace (a.prefix);
112 trace (a.localName);
113 a.localName = "f";
114 trace (a.nodeName);
115 trace (a.prefix);
116 trace (a.localName);
118 // weird values
119 var testvalues = ["", ":", ":b", "a:", "a::b", "a::", "::b", "::" ];
120 testvalues = testvalues.concat (values);
121 for (var i = 0; i < testvalues.length; i++) {
122 a.nodeName = testvalues[i];
123 trace (a.nodeName);
124 trace (a.prefix);
125 trace (a.localName);
129 function test_namespace ()
131 var x = new XML ();
132 x.ignoreWhite = true;
133 x.parseXML ("
134 <root:root xmlns='nsdefault' xmlns:a='nsa'>
135 <child xmlns='nsdefault_at_child' xmlns:d='nsd'>
136 <a:a/>
137 <b:b/>
138 </child>
140 <d:d/>
141 <e:e/>
142 </root:root>
144 var root = x.firstChild;
146 // normal
147 var ele = root.firstChild.firstChild;
148 trace (ele.namespaceURI);
149 trace (ele.getNamespaceForPrefix ());
150 trace (ele.getNamespaceForPrefix (""));
151 trace (ele.getNamespaceForPrefix ("a"));
152 ele = ele.nextSibling;
153 trace (ele.namespaceURI);
154 trace (ele.getNamespaceForPrefix ());
155 trace (ele.getNamespaceForPrefix (""));
156 trace (ele.getNamespaceForPrefix ("a"));
157 ele = root.lastChild.previousSibling;
158 trace (ele.namespaceURI);
159 trace (ele.getNamespaceForPrefix ());
160 trace (ele.getNamespaceForPrefix (""));
161 trace (ele.getNamespaceForPrefix ("a"));
162 ele = ele.nextSibling;
163 trace (ele.namespaceURI);
164 trace (ele.getNamespaceForPrefix ());
165 trace (ele.getNamespaceForPrefix (""));
166 trace (ele.getNamespaceForPrefix ("a"));
168 // writing
169 ele = root.firstChild.firstChild;
170 ele.namespaceURI = "fake";
171 trace (ele.namespaceURI);
174 function trace_attributes (attrs)
176 var props = new Array ();
177 for (var prop in attrs) {
178 props.push (prop);
180 props.sort ();
181 var str = "";
182 for (var i = 0; i < props.length; i++) {
183 var prop = props[i];
184 str += "&" + prop + "=" + attrs[prop];
186 trace (str.substr(1));
189 function test_attributes ()
191 var x = new XML ("<root a='a' b='b' c='' &amp;='&amp;' g='&'/>");
192 var root = x.firstChild;
194 // normal
195 trace_attributes (root.attributes);
196 root.attributes["d"] = "d";
197 trace_attributes (root.attributes);
198 root.attributes["a"] = "A";
199 trace_attributes (root.attributes);
200 delete root.attributes["b"];
201 trace_attributes (root.attributes);
203 // evil characters
204 root.attributes["'"] = "'";
205 root.attributes["\""] = "\"";
206 root.attributes["&"] = "&";
207 root.attributes["&amp;"] = "&amp;";
208 trace_attributes (root.attributes);
211 function test_modify ()
213 var x = new XML ("<root><a/><b/>c<d/></root>");
214 var root = x.firstChild;
216 // normal
217 trace (x);
218 trace (root);
219 root.removeNode ();
220 trace (x);
221 trace (root);
222 x.appendChild (root);
223 trace (x);
224 trace (root);
225 root.insertBefore (new XMLNode (1, "f"));
226 trace (root);
227 root.insertBefore (new XMLNode (1, "f"), root.lastChild);
228 trace (root);
229 root.appendChild (new XMLNode (1, "g"), new XMLNode (1, "h"));
230 trace (root);
232 // weird cases
233 root.appendChild (root.firstChild);
234 trace (root);
235 root.insertBefore (root.lastChild, root.lastChild);
236 trace (root);
237 root.appendChild (root);
238 trace (root.lastChild.nodeName);
239 root.firstChild.appendChild (root);
240 trace (root.firstChild.parentNode.nodeName);
241 trace (root.firstChild.lastChild.nodeName);
244 function test_constructor ()
246 // normal
247 trace (new XMLNode (1, "name"));
248 trace (new XMLNode (3, "value"));
250 for (var i = 0; i < values.length; i++) {
251 trace ("Creating with: " + names[i]);
252 trace (new XMLNode (1, values[i]));
253 trace (new XMLNode (3, values[i]));
254 trace (new XMLNode (values[i], "value"));
258 test_childNodes ();
259 test_references ();
260 test_cloneNode ();
261 test_nodeName ();
262 test_namespace ();
263 test_attributes ();
264 test_modify ();
265 test_constructor ();
267 loadMovie ("FSCommand:quit", "");