1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package complex.unoxml;
25 
26 import lib.TestParameters;
27 import helper.StreamSimulator;
28 
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.uno.XComponentContext;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.beans.XPropertySet;
33 import com.sun.star.io.XInputStream;
34 import com.sun.star.xml.dom.*;
35 import static com.sun.star.xml.dom.DOMExceptionType.*;
36 import static com.sun.star.xml.dom.NodeType.*;
37 import com.sun.star.xml.dom.events.*;
38 import com.sun.star.xml.xpath.*;
39 import static com.sun.star.xml.xpath.XPathObjectType.*;
40 
41 import org.junit.After;
42 import org.junit.AfterClass;
43 import org.junit.Before;
44 import org.junit.BeforeClass;
45 import org.junit.Test;
46 import org.openoffice.test.OfficeConnection;
47 import static org.junit.Assert.*;
48 
49 /**
50  * Test for com.sun.star.xml.dom.*, com.sun.star.xml.xpath.*
51  */
52 public class DOMTest
53 {
54     private static final OfficeConnection connection = new OfficeConnection();
55 
56     // setup and close connections
setUpConnection()57     @BeforeClass public static void setUpConnection() throws Exception {
58         System.out.println("setUpConnection()");
59         connection.setUp();
60     }
61 
tearDownConnection()62     @AfterClass public static void tearDownConnection()
63         throws InterruptedException, com.sun.star.uno.Exception
64     {
65         System.out.println("tearDownConnection()");
66         connection.tearDown();
67     }
68 
69     XComponentContext m_xContext;
70     XMultiServiceFactory m_xMSF;
71     TestParameters m_params;
72 
before()73     @Before public void before() throws Exception
74     {
75         final XMultiServiceFactory xMSF = UnoRuntime.queryInterface(
76                 XMultiServiceFactory.class,
77                 connection.getComponentContext().getServiceManager());
78         assertNotNull("could not create MultiServiceFactory.", xMSF);
79         m_params = new TestParameters();
80         m_params.put("ServiceFactory", xMSF);
81         XPropertySet xPropertySet =
82             UnoRuntime.queryInterface(XPropertySet.class, xMSF);
83         m_xContext = UnoRuntime.queryInterface(XComponentContext.class,
84                 xPropertySet.getPropertyValue("DefaultContext"));
85         assertNotNull("could not get component context.", m_xContext);
86         m_xMSF = xMSF;
87     }
88 
testXSAXDocumentBuilder()89     @Test public void testXSAXDocumentBuilder() throws Exception
90     {
91         XSAXDocumentBuilder xSAXBuilder =
92             UnoRuntime.queryInterface(XSAXDocumentBuilder.class,
93             m_xMSF.createInstance("com.sun.star.xml.dom.SAXDocumentBuilder"));
94         //FIXME TODO
95     }
96 
testXDocumentBuilder()97     @Test public void testXDocumentBuilder() throws Exception
98     {
99         XDocumentBuilder xBuilder =
100             UnoRuntime.queryInterface(XDocumentBuilder.class,
101             m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
102 
103         XDOMImplementation xDomImpl = xBuilder.getDOMImplementation();
104 //FIXME fails        assertNotNull("getDOMImplementation", xDomImpl);
105 
106         xBuilder.isNamespaceAware();
107         xBuilder.isValidating();
108 
109         {
110             XDocument xDoc = xBuilder.newDocument();
111             assertNotNull("newDocument", xDoc);
112         }
113 
114         try {
115             xBuilder.parse(null);
116             fail("XDocumentBuilder.parse(null)");
117         } catch (Exception e) { /* expected */ }
118         {
119             XInputStream xIn = new StreamSimulator(
120                     TestDocument.getUrl("example.rdf"), true, m_params);
121             XDocument xDoc = xBuilder.parse(xIn);
122             assertNotNull("XDocumentBuilder.parse", xDoc);
123         }
124         try {
125             xBuilder.parseURI("");
126             fail("XDocumentBuilder.parseURI(\"\")");
127         } catch (Exception e) { /* expected */ }
128         {
129             XDocument xDoc =
130                 xBuilder.parseURI(TestDocument.getUrl("example.rdf"));
131             assertNotNull("XDocumentBuilder.parseURI", xDoc);
132         }
133 
134         xBuilder.setEntityResolver(null);
135         /* FIXME TODO
136         XEntityResolver xER;
137         xBuilder.setEntityResolver(xER);
138         */
139 
140         xBuilder.setErrorHandler(null);
141         /* FIXME TODO
142         XErrorHandler xEH;
143         xBuilder.setErrorHandler(xEH);
144         */
145     }
146 
testXDocument()147     @Test public void testXDocument() throws Exception
148     {
149         XDocumentBuilder xBuilder =
150             UnoRuntime.queryInterface(XDocumentBuilder.class,
151             m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
152         XDocument xDoc = xBuilder.newDocument();
153 
154         /* FIXME
155         try {
156             xDoc.createAttribute("&");
157             fail("XDocument.createAttribute");
158         } catch (DOMException e) {
159             assertTrue("XDocument.createAttribute",
160                     INVALID_CHARACTER_ERR == e.Code);
161         }*/
162         {
163             XAttr xAttr = xDoc.createAttribute("foo");
164             assertNotNull("XDocument.createAttribute", xAttr);
165             assertEquals("XDocument.createAttribute",
166                     "foo", xAttr.getNodeName());
167         }
168 
169         String ns = "http://example.com/";
170         /* FIXME
171         try {
172             xDoc.createAttributeNS(ns, "&");
173             fail("XDocument.createAttributeNS");
174         } catch (DOMException e) {
175             assertTrue("XDocument.createAttributeNS",
176                     INVALID_CHARACTER_ERR == e.Code);
177         }
178         */
179         {
180             XAttr xAttr = xDoc.createAttributeNS(ns, "e:foo");
181             assertNotNull("XDocument.createAttributeNS", xAttr);
182             assertEquals("XDocument.createAttributeNS", "foo",
183                     xAttr.getNodeName());
184         }
185 
186         XCDATASection xCDS = xDoc.createCDATASection("foo");
187         assertNotNull("XDocument.createCDATASection", xCDS);
188 
189         XComment xComment = xDoc.createComment("foo");
190         assertNotNull("XDocument.createComment", xComment);
191 
192         XDocumentFragment xDF = xDoc.createDocumentFragment();
193         assertNotNull("XDocument.createDocumentFragment", xDF);
194 
195         /* FIXME
196         try {
197             xDoc.createElement("&");
198             fail("XDocument.createElement(\"&\")");
199         } catch (DOMException e) {
200             assertTrue("XDocument.createElement(\"&\")",
201                     INVALID_CHARACTER_ERR == e.Code);
202         }
203         */
204         XElement xElemFoo = xDoc.createElement("foo");
205         assertNotNull("XDocument.createElement(\"foo\")", xElemFoo);
206         assertEquals("XDocument.createElement(\"foo\")",
207                 "foo", xElemFoo.getNodeName());
208 
209         /* FIXME
210         try {
211             xDoc.createElementNS(ns, "&");
212             fail("XDocument.createElementNS(\"&\")");
213         } catch (DOMException e) {
214             assertTrue("XDocument.createElementNS(\"&\")",
215                     INVALID_CHARACTER_ERR == e.Code);
216         }
217         */
218         XElement xElemFooNs = xDoc.createElementNS(ns, "foo");
219         assertNotNull("XDocument.createElementNS(\"foo\")", xElemFooNs);
220         assertEquals("XDocument.createElementNS(\"foo\")",
221                 "foo", xElemFooNs.getNodeName());
222 
223         XEntityReference xER = xDoc.createEntityReference("foo");
224         assertNotNull("XDocument.createEntityReference", xER);
225 
226         XProcessingInstruction xPI =
227             xDoc.createProcessingInstruction("foo", "bar");
228         assertNotNull("XDocument.createProcessingInstruction", xPI);
229 
230         XText xText = xDoc.createTextNode("foo");
231         assertNotNull("XDocument.createTextNode", xText);
232 
233         XDocumentType xDT = xDoc.getDoctype();
234         assertNull("XDocument.getDoctype", xDT);
235 
236         {
237             XElement xDE = xDoc.getDocumentElement();
238             assertNull("XDocument.getDocumentElement", xDE);
239         }
240         {
241             XElement xById = xDoc.getElementById("foo");
242             assertNull("XDocument.getDocumentElement", xById);
243         }
244 
245         {
246             XNodeList xNodeList = xDoc.getElementsByTagName("foo");
247             assertNotNull("XDocument.getElementsByTagName", xNodeList);
248             assertTrue("XDocument.getElementsByTagName",
249                     0 == xNodeList.getLength());
250         }
251 
252         {
253             XNodeList xNodeList = xDoc.getElementsByTagNameNS(ns, "foo");
254             assertNotNull("XDocument.getElementsByTagNameNS", xNodeList);
255             assertTrue("XDocument.getElementsByTagNameNS",
256                     0 == xNodeList.getLength());
257         }
258 
259         XDOMImplementation xDOMImpl = xDoc.getImplementation();
260         assertNotNull("XDocument.getImplementation", xDOMImpl);
261 
262         {
263             XNode xRet = xElemFooNs.appendChild(xElemFoo);
264             assertEquals("XElement.appendChild(xElemFoo)", xElemFoo, xRet);
265         }
266         {
267             XNode xRet = xDoc.appendChild(xElemFooNs);
268             assertTrue("XDocument.appendChild(xElemFooNs)",
269                     xElemFooNs.equals(xRet));
270         }
271 
272         XElement xDE = xDoc.getDocumentElement();
273         assertNotNull("XDocument.getDocumentElement", xDE);
274         assertEquals("XDocument.getDocumentElement", xElemFooNs, xDE);
275 
276         {
277             XNodeList xNodeList = xDoc.getElementsByTagName("foo");
278             assertNotNull("XDocument.getElementsByTagName", xNodeList);
279             assertTrue("XDocument.getElementsByTagName",
280                     2 == xNodeList.getLength());
281             assertEquals("XDocument.getElementsByTagNameNS",
282                     xElemFooNs, xNodeList.item(0));
283             assertEquals("XDocument.getElementsByTagName",
284                     xElemFoo, xNodeList.item(1));
285         }
286 
287         {
288             XNodeList xNodeList = xDoc.getElementsByTagNameNS(ns, "foo");
289             assertNotNull("XDocument.getElementsByTagNameNS", xNodeList);
290             assertTrue("XDocument.getElementsByTagNameNS",
291                     1 == xNodeList.getLength());
292             assertEquals("XDocument.getElementsByTagNameNS",
293                     xElemFooNs, xNodeList.item(0));
294         }
295 
296         xElemFoo.setAttributeNS("http://www.w3.org/XML/1998/namespace",
297                 "xml:id", "bar");
298 
299         XElement xById = xDoc.getElementById("bar");
300         assertNotNull("XDocument.getDocumentElement", xById);
301         assertEquals("XDocument.getDocumentElement", xElemFoo, xById);
302 
303         try {
304             xDoc.importNode(null, false);
305             fail("XDocument.importNode(null)");
306         } catch (Exception e) { /* expected */ }
307         {
308             XNode xImported = xDoc.importNode(xElemFoo, false);
309             assertNotNull("XDocument.importNode()", xImported);
310             assertEquals("XDocument.importNode()", xElemFoo, xImported);
311         }
312         {
313             MockAttr xMockAttrBar = new MockAttr("bar", "blah");
314             MockAttr xMockAttrBaz = new MockAttr("baz", "quux");
315             MockElement xMockElemFoo = new MockElement("foo",
316                     new MockAttr[] { xMockAttrBar, xMockAttrBaz });
317             MockElement xMockElemBar = new MockElement("bar",
318                     new MockAttr[] { });
319             MockElement xMockElemRoot =
320                 new MockElement("root", new MockAttr[] { });
321             MockDoc xMockDoc = new MockDoc();
322             xMockDoc.init(new MockNode[] { xMockElemRoot });
323             xMockElemRoot.init(xMockDoc, xMockDoc, null, null,
324                     new MockNode[] { xMockElemFoo, xMockElemBar });
325             xMockElemFoo.init(xMockDoc, xMockElemRoot, null, xMockElemBar,
326                     new MockNode[] { });
327             xMockElemBar.init(xMockDoc, xMockElemRoot, xMockElemFoo, null,
328                     new MockNode[] { });
329 
330             {
331                 XNode xImported = xDoc.importNode(xMockElemRoot, false);
332                 assertNotNull("XDocument.importNode(false)", xImported);
333                 XElement xE =
334                     UnoRuntime.queryInterface(XElement.class, xImported);
335                 assertNotNull("XDocument.importNode(false)", xE);
336                 assertEquals("XDocument.importNode(false)",
337                         "root", xE.getLocalName());
338                 assertFalse("XDocument.importNode(false)", xE.hasAttributes());
339                 assertFalse("XDocument.importNode(false)", xE.hasChildNodes());
340             }
341 
342             {
343                 XNode xImported = xDoc.importNode(xMockElemRoot, true);
344                 assertNotNull("XDocument.importNode(true)", xImported);
345                 XElement xImpRoot =
346                     UnoRuntime.queryInterface(XElement.class, xImported);
347                 assertNotNull("XDocument.importNode(true)", xImpRoot);
348                 assertEquals("XDocument.importNode(true)",
349                         "root", xImpRoot.getLocalName());
350                 assertFalse("XDocument.importNode(true)",
351                         xImpRoot.hasAttributes());
352                 assertTrue("XDocument.importNode(true)",
353                         xImpRoot.hasChildNodes());
354                 assertEquals("XDocument.importNode(true)",
355                         "root", xImpRoot.getNodeName());
356 
357                 XNode xImpFooN = xImpRoot.getFirstChild();
358                 assertNotNull("XDocument.importNode(true)", xImpFooN);
359                 XElement xImpFoo =
360                     UnoRuntime.queryInterface(XElement.class, xImpFooN);
361                 assertNotNull("XDocument.importNode(true)", xImpFoo);
362                 assertTrue("XDocument.importNode(true)",
363                         xImpFoo.hasAttributes());
364                 assertFalse("XDocument.importNode(true)",
365                         xImpFoo.hasChildNodes());
366                 assertEquals("XDocument.importNode(true)",
367                         "foo", xImpFoo.getNodeName());
368                 assertEquals("XDocument.importNode(true)",
369                         "blah", xImpFoo.getAttribute("bar"));
370                 assertEquals("XDocument.importNode(true)",
371                         "quux", xImpFoo.getAttribute("baz"));
372                 XNode xImpBarN = xImpFooN.getNextSibling();
373                 assertNotNull("XDocument.importNode(true)", xImpBarN);
374                 XElement xImpBar =
375                     UnoRuntime.queryInterface(XElement.class, xImpBarN);
376                 assertNotNull("XDocument.importNode(true)", xImpBar);
377                 assertFalse("XDocument.importNode(true)",
378                         xImpBar.hasAttributes());
379                 assertFalse("XDocument.importNode(true)",
380                         xImpBar.hasChildNodes());
381                 assertEquals("XDocument.importNode(true)",
382                         "bar", xImpBar.getNodeName());
383                 assertNull("XDocument.importNode(true)",
384                         xImpBar.getNextSibling());
385             }
386         }
387 
388         // XNode ////////////////////////////////////////////////////
389 
390         {
391             XNode xDocCloneN = xDoc.cloneNode(false);
392             assertNotNull("XDocument.cloneNode(false)", xDocCloneN);
393             XDocument xDocClone =
394                 UnoRuntime.queryInterface(XDocument.class, xDocCloneN);
395             assertNotNull("XDocument.cloneNode(false)", xDocClone);
396             assertFalse("XDocument.cloneNode(false)",
397                     xDocClone.hasChildNodes());
398             assertNull("XDocument.cloneNode(false)", xDocClone.getFirstChild());
399             assertNull("XDocument.cloneNode(false)",
400                     xDocClone.getDocumentElement());
401         }
402         {
403             XNode xDocCloneN = xDoc.cloneNode(true);
404             assertNotNull("XDocument.cloneNode(true)", xDocCloneN);
405             XDocument xDocClone =
406                 UnoRuntime.queryInterface(XDocument.class, xDocCloneN);
407             assertNotNull("XDocument.cloneNode(true)", xDocClone);
408             assertTrue("XDocument.cloneNode(true)", xDocClone.hasChildNodes());
409             assertNotNull("XDocument.cloneNode(true)",
410                     xDocClone.getFirstChild());
411             XElement xE = xDocClone.getDocumentElement();
412             assertNotNull("XDocument.cloneNode(true)", xE);
413             assertFalse("XDocument.cloneNode(true)", xElemFooNs.equals(xE));
414             assertEquals("XDocument.cloneNode(true)", "foo", xE.getLocalName());
415             assertEquals("XDocument.cloneNode(true)", ns, xE.getNamespaceURI());
416         }
417 
418         assertNull("XDocument.getAttributes()", xDoc.getAttributes());
419 
420         {
421             XNodeList xChildren = xDoc.getChildNodes();
422             assertTrue("XDocument.getChildNodes()", 1 == xChildren.getLength());
423             assertEquals("XDocument.getChildNodes()",
424                     xElemFooNs, xChildren.item(0));
425 
426             XNode xFirst = xDoc.getFirstChild();
427             assertEquals("XDocument.getFirstChild()", xElemFooNs, xFirst);
428             XNode xLast = xDoc.getLastChild();
429             assertEquals("XDocument.getLastChild()", xElemFooNs, xLast);
430         }
431 
432         assertEquals("XDocument.getLocalName()", "", xDoc.getLocalName());
433 
434         assertEquals("XDocument.getNamespaceURI()", "", xDoc.getNamespaceURI());
435 
436         assertNull("XDocument.getNextSibling()", xDoc.getNextSibling());
437 
438         assertEquals("XDocument.getNodeName()",
439                 "#document", xDoc.getNodeName());
440 
441         assertTrue("XDocument.getNodeType()",
442                 DOCUMENT_NODE == xDoc.getNodeType());
443 
444         assertEquals("XDocument.getNodeValue()", "", xDoc.getNodeValue());
445 
446         assertEquals("XDocument.getOwnerDocument()",
447                 xDoc, xDoc.getOwnerDocument());
448 
449         assertNull("XDocument.getParentNode()", xDoc.getParentNode());
450 
451         assertEquals("XDocument.getPrefix()", "", xDoc.getPrefix());
452 
453         assertNull("XDocument.getPreviousSibling()", xDoc.getPreviousSibling());
454 
455         assertFalse("XDocument.hasAttributes()", xDoc.hasAttributes());
456 
457         assertTrue("XDocument.hasChildNodes()", xDoc.hasChildNodes());
458 
459         assertFalse("XDocument.isSupported()",
460                 xDoc.isSupported("frobnication", "v99.33.0.0.0.1"));
461 
462         xDoc.normalize();
463 
464         try {
465             xDoc.setNodeValue("42");
466             fail("XDocument.setNodeValue()");
467         } catch (DOMException e) {
468             assertTrue("XDocument.setNodeValue()",
469                     NO_MODIFICATION_ALLOWED_ERR == e.Code);
470         }
471 
472         try {
473             xDoc.setPrefix("foo");
474             fail("XDocument.setPrefix()");
475         } catch (DOMException e) {
476             assertTrue("XDocument.setPrefix()",
477                     NO_MODIFICATION_ALLOWED_ERR == e.Code);
478         }
479 
480         try {
481             xDoc.appendChild(null);
482             fail("XDocument.appendChild(null)");
483         } catch (Exception e) { /* expected */ }
484 
485 
486         try {
487             xDoc.insertBefore(null, xText);
488             fail("XDocument.insertBefore(null,)");
489         } catch (Exception e) { /* expected */ }
490         try {
491             xDoc.insertBefore(xText, null);
492             fail("XDocument.insertBefore(, null)");
493         } catch (Exception e) { /* expected */ }
494         try {
495             xDoc.insertBefore(xText, xText);
496             fail("XDocument.insertBefore(x, x)");
497         } catch (DOMException e) {
498             assertTrue("XDocument.insertBefore(x, x)",
499                     HIERARCHY_REQUEST_ERR == e.Code);
500         }
501 
502         {
503             XNode xRet = xDoc.insertBefore(xComment, xElemFooNs);
504             assertEquals("XDocument.insertBefore(xComment, xElemFooNs)",
505                     xRet, xElemFooNs); // why does this return the old node?
506             assertEquals("XDocument.insertBefore(xComment, xElemFooNs)",
507                     xComment, xDoc.getFirstChild());
508             assertEquals("XDocument.insertBefore(xComment, xElemFooNs)",
509                     xDoc, xComment.getParentNode());
510             assertEquals("XDocument.insertBefore(xCommnet, xElemFooNs)",
511                     xElemFooNs, xDoc.getLastChild());
512         }
513 
514         try {
515             xDoc.replaceChild(null, xText);
516             fail("XDocument.replaceChild(null, )");
517         } catch (Exception e) { /* expected */ }
518         try {
519             xDoc.replaceChild(xText, null);
520             fail("XDocument.replaceChild(, null)");
521         } catch (Exception e) { /* expected */ }
522         try {
523             xDoc.replaceChild(xElemFoo, xElemFoo); // not child
524             fail("XDocument.replaceChild(xElemFoo, xElemFoo)");
525         } catch (DOMException e) {
526             assertTrue("XDocument.replaceChild(xElemFoo, xElemFoo)",
527                     HIERARCHY_REQUEST_ERR == e.Code);
528         }
529         try {
530             xDoc.replaceChild(xElemFooNs, xElemFooNs); // child
531             assertFalse("XDocument.replaceChild(xElemFooNs, xElemFooNs)",
532                     false);
533         } catch (DOMException e) {
534             assertTrue("XDocument.replaceChild(xElemFooNs, xElemFooNs)",
535                     HIERARCHY_REQUEST_ERR == e.Code);
536         }
537         XNode xReplaced = xDoc.replaceChild(xPI, xComment);
538         assertEquals("XDocument.replaceChild(xPI, xComment)",
539                 xReplaced, xComment);
540         assertEquals("XDocument.replaceChild(xPI, xComment)",
541                 xPI, xDoc.getFirstChild());
542         assertEquals("XDocument.replaceChild(xPI, xComment)",
543                 xElemFooNs, xDoc.getLastChild());
544 
545         try {
546             xDoc.removeChild(null);
547             fail("XDocument.removeChild(null)");
548         } catch (Exception e) { /* expected */ }
549         try {
550             xDoc.removeChild(xElemFoo);
551             fail("XDocument.removeChild()");
552         } catch (DOMException e) {
553             assertTrue("XDocument.removeChild()",
554                     HIERARCHY_REQUEST_ERR == e.Code);
555         }
556 
557         XNode xRemoved = xDoc.removeChild(xPI);
558         assertEquals("XDocument.removeChild(xPI)", xRemoved, xPI);
559         assertTrue("XDocument.removeChild(xPI)", xDoc.hasChildNodes());
560         assertEquals("XDocument.removeChild(xPI)",
561                 xElemFooNs, xDoc.getFirstChild());
562         assertEquals("XDocument.removeChild(xPI)",
563                 xElemFooNs, xDoc.getLastChild());
564     }
565 
testXDocumentFragment()566     @Test public void testXDocumentFragment() throws Exception
567     {
568         XDocumentBuilder xBuilder =
569             UnoRuntime.queryInterface(XDocumentBuilder.class,
570             m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
571         XDocument xDoc = xBuilder.newDocument();
572 
573         XDocumentFragment xDF = xDoc.createDocumentFragment();
574         assertNotNull("XDocument.createDocumentFragment", xDF);
575 
576         XElement xElemFoo = xDoc.createElement("foo");
577         assertNotNull("XDocument.createElement", xElemFoo);
578 
579         xDF.appendChild(xElemFoo);
580 
581         // XNode ////////////////////////////////////////////////////
582 
583         XText xText = xDoc.createTextNode("foo");
584         XComment xComment = xDoc.createComment("foo");
585 
586         {
587             XNode xDFCloneN = xDF.cloneNode(false);
588             assertNotNull("XDocumentFragment.cloneNode(false)", xDFCloneN);
589             XDocumentFragment xDFClone =
590                 UnoRuntime.queryInterface(XDocumentFragment.class, xDFCloneN);
591             assertNotNull("XDocumentFragment.cloneNode(false)", xDFClone);
592             assertFalse("XDocumentFragment.cloneNode(false)",
593                     xDFClone.hasChildNodes());
594             assertNull("XDocumentFragment.cloneNode(false)",
595                     xDFClone.getFirstChild());
596         }
597         {
598             XNode xDFCloneN = xDF.cloneNode(true);
599             assertNotNull("XDocumentFragment.cloneNode(true)", xDFCloneN);
600             XDocumentFragment xDFClone =
601                 UnoRuntime.queryInterface(XDocumentFragment.class, xDFCloneN);
602             assertNotNull("XDocumentFragment.cloneNode(true)", xDFClone);
603             assertTrue("XDocumentFragment.cloneNode(true)",
604                     xDFClone.hasChildNodes());
605             XNode xChild = xDFClone.getFirstChild();
606             assertNotNull("XDocumentFragment.cloneNode(true)", xChild);
607             XElement xE = UnoRuntime.queryInterface(XElement.class, xChild);
608             assertFalse("XDocumentFragment.cloneNode(true)",
609                     xElemFoo.equals(xE));
610             assertEquals("XDocumentFragment.cloneNode(true)",
611                     "foo", xE.getLocalName());
612         }
613 
614         assertNull("XDocumentFragment.getAttributes()", xDF.getAttributes());
615 
616         {
617             XNodeList xChildren = xDF.getChildNodes();
618             assertTrue("XDocumentFragment.getChildNodes()",
619                     1 == xChildren.getLength());
620             assertEquals("XDocumentFragment.getChildNodes()",
621                     xElemFoo, xChildren.item(0));
622 
623             XNode xFirst = xDF.getFirstChild();
624             assertEquals("XDocumentFragment.getFirstChild()",
625                     xElemFoo, xFirst);
626             XNode xLast = xDF.getLastChild();
627             assertEquals("XDocumentFragment.getLastChild()", xElemFoo, xLast);
628         }
629 
630         assertEquals("XDocumentFragment.getLocalName()",
631                 "", xDF.getLocalName());
632 
633         assertEquals("XDocumentFragment.getNamespaceURI()",
634                 "", xDF.getNamespaceURI());
635 
636         assertNull("XDocumentFragment.getNextSibling()", xDF.getNextSibling());
637 
638         assertEquals("XDocumentFragment.getNodeName()",
639                 "#document-fragment", xDF.getNodeName());
640 
641         assertTrue("XDocumentFragment.getNodeType()",
642                 DOCUMENT_FRAGMENT_NODE == xDF.getNodeType());
643 
644         assertEquals("XDocumentFragment.getNodeValue()",
645                 "", xDF.getNodeValue());
646 
647         assertEquals("XDocumentFragment.getOwnerDocument()",
648                 xDoc, xDF.getOwnerDocument());
649 
650         assertNull("XDocumentFragment.getParentNode()", xDF.getParentNode());
651 
652         assertEquals("XDocumentFragment.getPrefix()", "", xDF.getPrefix());
653 
654         assertNull("XDocumentFragment.getPreviousSibling()",
655                 xDF.getPreviousSibling());
656 
657         assertFalse("XDocumentFragment.hasAttributes()", xDF.hasAttributes());
658 
659         assertTrue("XDocumentFragment.hasChildNodes()", xDF.hasChildNodes());
660 
661         assertFalse("XDocumentFragment.isSupported()",
662                 xDF.isSupported("frobnication", "v99.33.0.0.0.1"));
663 
664         xDF.normalize();
665 
666         try {
667             xDF.setNodeValue("42");
668             fail("XDocumentFragment.setNodeValue()");
669         } catch (DOMException e) {
670             assertTrue("XDocumentFragment.setNodeValue()",
671                     NO_MODIFICATION_ALLOWED_ERR == e.Code);
672         }
673 
674         try {
675             xDF.setPrefix("foo");
676             fail("XDocumentFragment.setPrefix()");
677         } catch (DOMException e) {
678             assertTrue("XDocumentFragment.setPrefix()",
679                     NO_MODIFICATION_ALLOWED_ERR == e.Code);
680         }
681 
682         try {
683             xDF.appendChild(null);
684             fail("XDocumentFragment.appendChild(null)");
685         } catch (Exception e) { /* expected */ }
686 
687 
688         try {
689             xDF.insertBefore(null, xText);
690             fail("XDocumentFragment.insertBefore(null,)");
691         } catch (Exception e) { /* expected */ }
692         try {
693             xDF.insertBefore(xText, null);
694             fail("XDocumentFragment.insertBefore(, null)");
695         } catch (Exception e) { /* expected */ }
696         try {
697             xDF.insertBefore(xText, xText);
698             fail("XDocumentFragment.insertBefore(x, x)");
699         } catch (DOMException e) {
700             assertTrue("XDocumentFragment.insertBefore(x, x)",
701                     HIERARCHY_REQUEST_ERR == e.Code);
702         }
703 
704         {
705             XNode xRet = xDF.insertBefore(xComment, xElemFoo);
706             assertEquals("XDocumentFragment.insertBefore(xComment, xElemFoo)",
707                     xRet, xElemFoo); // why does this return the old node?
708             assertEquals("XDocumentFragment.insertBefore(xComment, xElemFoo)",
709                     xComment, xDF.getFirstChild());
710             assertEquals("XDocumentFragment.insertBefore(xComment, xElemFoo)",
711                     xDF, xComment.getParentNode());
712             assertEquals("XDocumentFragment.insertBefore(xCommnet, xElemFoo)",
713                     xElemFoo, xDF.getLastChild());
714         }
715 
716         try {
717             xDF.replaceChild(null, xText);
718             fail("XDocumentFragment.replaceChild(null, )");
719         } catch (Exception e) { /* expected */ }
720         try {
721             xDF.replaceChild(xText, null);
722             fail("XDocumentFragment.replaceChild(, null)");
723         } catch (Exception e) { /* expected */ }
724         try {
725             xDF.replaceChild(xElemFoo, xElemFoo); // not child
726             fail("XDocumentFragment.replaceChild(xElemFoo, xElemFoo)");
727         } catch (DOMException e) {
728             assertTrue("XDocumentFragment.replaceChild(xElemFoo, xElemFoo)",
729                     HIERARCHY_REQUEST_ERR == e.Code);
730         }
731         try {
732             xDF.replaceChild(xElemFoo, xElemFoo); // child
733             assertFalse("XDocumentFragment.replaceChild(xElemFoo, xElemFoo)",
734                     false);
735         } catch (DOMException e) {
736             assertTrue("XDocumentFragment.replaceChild(xElemFoo, xElemFoo)",
737                     HIERARCHY_REQUEST_ERR == e.Code);
738         }
739         XNode xReplaced = xDF.replaceChild(xText, xComment);
740         assertEquals("XDocumentFragment.replaceChild(xText, xComment)",
741                 xReplaced, xComment);
742         assertEquals("XDocumentFragment.replaceChild(xText, xComment)",
743                 xText, xDF.getFirstChild());
744         assertEquals("XDocumentFragment.replaceChild(xText, xComment)",
745                 xElemFoo, xDF.getLastChild());
746 
747         try {
748             xDF.removeChild(null);
749             fail("XDocumentFragment.removeChild(null)");
750         } catch (Exception e) { /* expected */ }
751         try {
752             xDF.removeChild(xComment);
753             fail("XDocumentFragment.removeChild()");
754         } catch (DOMException e) {
755             assertTrue("XDocumentFragment.removeChild()",
756                     HIERARCHY_REQUEST_ERR == e.Code);
757         }
758 
759         XNode xRemoved = xDF.removeChild(xText);
760         assertEquals("XDocumentFragment.removeChild(xText)", xRemoved, xText);
761         assertTrue("XDocumentFragment.removeChild(xText)", xDF.hasChildNodes());
762         assertEquals("XDocumentFragment.removeChild(xText)",
763                 xElemFoo, xDF.getFirstChild());
764         assertEquals("XDocumentFragment.removeChild(xText)",
765                 xElemFoo, xDF.getLastChild());
766     }
767 
testXElement()768     @Test public void testXElement() throws Exception
769     {
770         XDocumentBuilder xBuilder =
771             UnoRuntime.queryInterface(XDocumentBuilder.class,
772             m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
773         XDocument xDoc = xBuilder.newDocument();
774 
775         String ns = "http://example.com/";
776 
777         XElement xElemFoo = xDoc.createElement("foo");
778         assertNotNull("XDocument.createElement(\"foo\")", xElemFoo);
779 
780         XElement xElemFooNs = xDoc.createElementNS(ns, "e:foo");
781         assertNotNull("XDocument.createElementNs(\"foo\")", xElemFooNs);
782 
783         assertEquals("XElement.getTagName", "foo", xElemFoo.getTagName());
784 
785         {
786             XNodeList xNodeList = xElemFoo.getElementsByTagName("bar");
787             assertNotNull("XElement.getElementsByTagName", xNodeList);
788             assertTrue("XElement.getElementsByTagName",
789                     0 == xNodeList.getLength());
790         }
791 
792         {
793             XNodeList xNodeList = xElemFoo.getElementsByTagNameNS(ns, "bar");
794             assertNotNull("XElement.getElementsByTagNameNS", xNodeList);
795             assertTrue("XElement.getElementsByTagNameNS",
796                     0 == xNodeList.getLength());
797         }
798 
799         xElemFoo.appendChild(xElemFooNs);
800 
801         {
802             XNodeList xNodeList = xElemFoo.getElementsByTagName("foo");
803             assertNotNull("XElement.getElementsByTagName", xNodeList);
804             assertTrue("XElement.getElementsByTagName",
805                     2 == xNodeList.getLength());
806             assertEquals("XElement.getElementsByTagName",
807                     xElemFoo, xNodeList.item(0));
808             assertEquals("XElement.getElementsByTagName",
809                     xElemFooNs, xNodeList.item(1));
810         }
811         {
812             XNodeList xNodeList = xElemFoo.getElementsByTagNameNS(ns, "foo");
813             assertNotNull("XElement.getElementsByTagNameNS", xNodeList);
814             assertTrue("XElement.getElementsByTagNameNS",
815                     1 == xNodeList.getLength());
816             assertEquals("XElement.getElementsByTagNameNS",
817                     xElemFooNs, xNodeList.item(0));
818         }
819 
820         {
821             String ret = xElemFoo.getAttribute("foo");
822             assertEquals("XElement.getAttribute", "", ret);
823         }
824         {
825             String ret = xElemFoo.getAttributeNS(ns, "foo");
826             assertEquals("XElement.getAttributeNS", "", ret);
827         }
828         {
829             XNode xAttr = xElemFoo.getAttributeNode("foo");
830             assertNull("XElement.getAttributeNode", xAttr);
831         }
832         {
833             XNode xAttr = xElemFoo.getAttributeNodeNS(ns, "foo");
834             assertNull("XElement.getAttributeNodeNS", xAttr);
835         }
836         assertFalse("XElement.hasAttribute", xElemFoo.hasAttribute("foo"));
837         assertFalse("XElement.hasAttributeNS",
838                 xElemFoo.hasAttributeNS(ns, "foo"));
839 
840         // surprisingly this does not throw?
841         xElemFoo.removeAttribute("foo");
842         xElemFoo.removeAttributeNS(ns, "foo");
843 
844         XAttr xAttr = xDoc.createAttribute("foo");
845         XAttr xAttrNs = xDoc.createAttributeNS(ns, "foo");
846 
847         try {
848             xElemFoo.removeAttributeNode(null);
849             fail("XElement.removeAttributeNode(null)");
850         } catch (Exception e) { /* expected */ }
851 
852         try {
853             xElemFoo.removeAttributeNode(xAttr);
854             fail("XElement.removeAttributeNode(xAttr)");
855         } catch (DOMException e) {
856             assertTrue("XElement.removeAttributeNode(xAttr)",
857                     HIERARCHY_REQUEST_ERR == e.Code);
858         }
859 
860         /* FIXME
861         try {
862             xElemFoo.setAttribute("&", "foo");
863             fail("XElement.setAttribute(\"&\")");
864         } catch (DOMException e) {
865             assertTrue("XElement.setAttribute(\"&\")",
866                     INVALID_CHARACTER_ERR == e.Code);
867         }
868         try {
869             xElemFoo.setAttributeNS(ns, "&", "foo");
870             fail("XElement.setAttributeNS(\"&\")");
871         } catch (DOMException e) {
872             assertTrue("XElement.setAttributeNS(\"&\")",
873                     INVALID_CHARACTER_ERR == e.Code);
874         }
875         */
876 
877         XAttr xAttrSet = xElemFoo.setAttributeNode(xAttr);
878         assertEquals("XElement.setAttributeNode(xAttr)",
879                 xAttrSet, xElemFoo.getAttributeNode("foo"));
880         assertEquals("XElement.setAttributeNode(xAttr)",
881                 xElemFoo, xAttrSet.getOwnerElement());
882         try {
883             xElemFooNs.setAttributeNode(xAttrSet);
884             fail("XElement.setAttributeNode(xAttrSet)");
885         } catch (DOMException e) {
886             assertTrue("XElement.setAttributeNode(xAttrSet)",
887                     INUSE_ATTRIBUTE_ERR == e.Code);
888         }
889 
890         XAttr xAttrNsSet = xElemFooNs.setAttributeNodeNS(xAttrNs);
891         assertEquals("XElement.setAttributeNodeNS(xAttr)",
892                 xAttrNsSet, xElemFooNs.getAttributeNodeNS(ns, "foo"));
893         assertEquals("XElement.setAttributeNodeNS(xAttrNs)",
894                 xElemFooNs, xAttrNsSet.getOwnerElement());
895         try {
896             xElemFooNs.setAttributeNodeNS(xAttrNsSet);
897             fail("XElement.setAttributeNodeNS(xAttrNsSet)");
898         } catch (DOMException e) {
899             assertTrue("XElement.setAttributeNodeNS(xAttrNsSet)",
900                     INUSE_ATTRIBUTE_ERR == e.Code);
901         }
902 
903         XAttr xAttrRemoved = xElemFoo.removeAttributeNode(xAttrSet);
904         assertNotNull("XElement.removeAttributeNode(xAttrSet)", xAttrRemoved);
905         assertEquals("XElement.removeAttributeNode(xAttrSet)",
906                 "foo", xAttrRemoved.getName());
907         assertNull("XElement.removeAttributeNode(xAttrSet)",
908                 xAttrRemoved.getOwnerElement());
909 
910         XAttr xAttrNsRemoved = xElemFooNs.removeAttributeNode(xAttrNsSet);
911         assertNotNull("XElement.removeAttributeNode(xAttrNsSet)",
912                 xAttrNsRemoved);
913         assertEquals("XElement.removeAttributeNode(xAttrNsSet)",
914                 "foo", xAttrNsRemoved.getName());
915         assertNull("XElement.removeAttributeNode(xAttrNsSet)",
916                 xAttrNsRemoved.getOwnerElement());
917 
918 
919         xElemFoo.setAttribute("foo", "bar");
920         assertEquals("XElement.setAttribute()",
921                 "bar", xElemFoo.getAttribute("foo"));
922 
923         xElemFooNs.setAttributeNS(ns, "foo", "bar");
924         assertEquals("XElement.setAttributeNS()",
925                 "bar", xElemFooNs.getAttributeNS(ns, "foo"));
926 
927         xElemFoo.removeAttribute("foo");
928         assertNull("XElement.removeAttribute",
929                 xElemFoo.getAttributeNode("foo"));
930 
931         xElemFooNs.removeAttributeNS(ns, "foo");
932         assertNull("XElement.removeAttributeNS",
933                 xElemFooNs.getAttributeNodeNS(ns, "foo"));
934 
935         // XNode ////////////////////////////////////////////////////
936 
937         XText xText = xDoc.createTextNode("foo");
938         XComment xComment = xDoc.createComment("foo");
939 
940         {
941             XNamedNodeMap xAttrMap = xElemFoo.getAttributes();
942             assertNotNull("XElement.getAttributes", xAttrMap);
943             assertTrue("XElement.getAttributes", 0 == xAttrMap.getLength());
944             assertFalse("XElement.hasAttributes()", xElemFoo.hasAttributes());
945         }
946 
947         xElemFooNs.setAttribute("foo", "bar");
948         xElemFoo.setAttributeNS(ns, "foo", "bar");
949 
950         {
951             XNamedNodeMap xAttrMap = xElemFoo.getAttributes();
952             assertNotNull("XElement.getAttributes", xAttrMap);
953             assertTrue("XElement.getAttributes", 1 == xAttrMap.getLength());
954             XNode xAttr_ = xAttrMap.getNamedItemNS(ns, "foo");
955             assertNotNull("XElement.getAttributes", xAttr_);
956         }
957         {
958             XNamedNodeMap xAttrMap = xElemFooNs.getAttributes();
959             assertNotNull("XElement.getAttributes", xAttrMap);
960             assertTrue("XElement.getAttributes", 1 == xAttrMap.getLength());
961             XNode xAttr_ = xAttrMap.getNamedItem("foo");
962             assertNotNull("XElement.getAttributes", xAttr_);
963         }
964 
965         {
966             XNode xElemFooCloneN = xElemFoo.cloneNode(false);
967             assertNotNull("XElement.cloneNode(false)", xElemFooCloneN);
968             XElement xElemFooClone =
969                 UnoRuntime.queryInterface(XElement.class, xElemFooCloneN);
970             assertNotNull("XElement.cloneNode(false)", xElemFooClone);
971             assertFalse("XElement.cloneNode(false)",
972                     xElemFooClone.hasChildNodes());
973             assertNull("XElement.cloneNode(false)",
974                     xElemFooClone.getFirstChild());
975         }
976         {
977             XNode xElemFooCloneN = xElemFoo.cloneNode(true);
978             assertNotNull("XElement.cloneNode(true)", xElemFooCloneN);
979             XElement xElemFooClone =
980                 UnoRuntime.queryInterface(XElement.class, xElemFooCloneN);
981             assertNotNull("XElement.cloneNode(true)", xElemFooClone);
982             assertTrue("XElement.cloneNode(true)",
983                     xElemFooClone.hasChildNodes());
984             assertTrue("XElement.cloneNode(true)",
985                     xElemFooClone.hasAttributeNS(ns, "foo"));
986             XNode xChild = xElemFooClone.getFirstChild();
987             assertNotNull("XElement.cloneNode(true)", xChild);
988             XElement xElemFooNsClone =
989                 UnoRuntime.queryInterface(XElement.class, xChild);
990             assertNotNull("XElement.cloneNode(true)", xElemFooNsClone);
991             assertEquals("XElement.cloneNode(true)", "foo",
992                     xElemFooNsClone.getLocalName());
993             assertEquals("XElement.cloneNode(true)", ns,
994                     xElemFooNsClone.getNamespaceURI());
995             assertTrue("XElement.cloneNode(true)",
996                     xElemFooNsClone.hasAttribute("foo"));
997         }
998 
999         {
1000             XNodeList xChildren = xElemFoo.getChildNodes();
1001             assertTrue("XElement.getChildNodes()", 1 == xChildren.getLength());
1002             assertEquals("XElement.getChildNodes()",
1003                     xElemFooNs, xChildren.item(0));
1004 
1005             XNode xFirst = xElemFoo.getFirstChild();
1006             assertEquals("XDocument.getFirstChild()", xElemFooNs, xFirst);
1007             XNode xLast = xElemFoo.getLastChild();
1008             assertEquals("XDocument.getLastChild()", xElemFooNs, xLast);
1009         }
1010 
1011         assertEquals("XElement.getLocalName()", "foo", xElemFoo.getLocalName());
1012         assertEquals("XElement.getLocalName()", "foo",
1013                 xElemFooNs.getLocalName());
1014 
1015         assertEquals("XElement.getNamespaceURI()", "",
1016                 xElemFoo.getNamespaceURI());
1017         assertEquals("XElement.getNamespaceURI()", ns,
1018                 xElemFooNs.getNamespaceURI());
1019 
1020         assertNull("XElement.getNextSibling()", xElemFoo.getNextSibling());
1021 
1022         assertEquals("XElement.getNodeName()", "foo", xElemFoo.getNodeName());
1023         assertEquals("XElement.getNodeName()", "foo",
1024                 xElemFooNs.getNodeName());
1025 
1026         assertTrue("XElement.getNodeType()",
1027                 ELEMENT_NODE == xElemFoo.getNodeType());
1028 
1029         assertEquals("XElement.getNodeValue()", "", xElemFoo.getNodeValue());
1030 
1031         assertEquals("XElement.getOwnerDocument()",
1032                 xDoc, xElemFoo.getOwnerDocument());
1033 
1034         assertNull("XElement.getParentNode()", xElemFoo.getParentNode());
1035         assertEquals("XElement.getParentNode()",
1036                 xElemFoo, xElemFooNs.getParentNode());
1037 
1038         assertEquals("XElement.getPrefix()", "", xElemFoo.getPrefix());
1039         assertEquals("XElement.getPrefix()", "e", xElemFooNs.getPrefix());
1040 
1041         assertNull("XElement.getPreviousSibling()",
1042                 xElemFoo.getPreviousSibling());
1043 
1044         assertTrue("XElement.hasAttributes()", xElemFoo.hasAttributes());
1045 
1046         assertTrue("XElement.hasChildNodes()", xElemFoo.hasChildNodes());
1047         assertFalse("XElement.hasChildNodes()", xElemFooNs.hasChildNodes());
1048 
1049         assertFalse("XElement.isSupported()",
1050                 xElemFoo.isSupported("frobnication", "v99.33.0.0.0.1"));
1051 
1052         xElemFoo.normalize();
1053 
1054         try {
1055             xElemFoo.setNodeValue("42");
1056             fail("XElement.setNodeValue()");
1057         } catch (DOMException e) {
1058             assertTrue("XElement.setNodeValue()",
1059                     NO_MODIFICATION_ALLOWED_ERR == e.Code);
1060         }
1061 
1062         xElemFooNs.setPrefix("f");
1063         assertEquals("XElement.getPrefix()", "f", xElemFooNs.getPrefix());
1064 
1065         try {
1066             xElemFoo.appendChild(null);
1067             fail("XElement.appendChild(null)");
1068         } catch (Exception e) { /* expected */ }
1069 
1070         try {
1071             xElemFoo.insertBefore(null, xText);
1072             fail("XElemFoo.insertBefore(null,)");
1073         } catch (Exception e) { /* expected */ }
1074         try {
1075             xElemFoo.insertBefore(xText, null);
1076             fail("XElemFoo.insertBefore(, null)");
1077         } catch (Exception e) { /* expected */ }
1078         try {
1079             xElemFoo.insertBefore(xText, xText);
1080             fail("XElement.insertBefore(x, x)");
1081         } catch (DOMException e) {
1082             assertTrue("XDocument.insertBefore(x, x)",
1083                     HIERARCHY_REQUEST_ERR == e.Code);
1084         }
1085 
1086         {
1087             XNode xRet = xElemFoo.insertBefore(xText, xElemFooNs);
1088             assertEquals("XElement.insertBefore(xText, xElemFooNs)",
1089                     xRet, xElemFooNs); // why does this return the old node?
1090             assertEquals("XElement.insertBefore(xText, xElemFooNs)",
1091                     xText, xElemFoo.getFirstChild());
1092             assertEquals("XElement.insertBefore(xText, xElemFooNs)",
1093                     xElemFoo, xText.getParentNode());
1094             assertEquals("XElement.insertBefore(xText, xElemFooNs)",
1095                     xElemFooNs, xElemFoo.getLastChild());
1096         }
1097 
1098         try {
1099             xElemFoo.replaceChild(null, xText);
1100             fail("XElement.replaceChild(null, )");
1101         } catch (Exception e) { /* expected */ }
1102         try {
1103             xElemFoo.replaceChild(xText, null);
1104             fail("XElement.replaceChild(, null)");
1105         } catch (Exception e) { /* expected */ }
1106         try {
1107             xElemFoo.replaceChild(xElemFoo, xElemFoo); // not child
1108             fail("XElement.replaceChild(xElemFoo, xElemFoo)");
1109         } catch (DOMException e) {
1110             assertTrue("XElement.replaceChild(xElemFoo, xElemFoo)",
1111                     HIERARCHY_REQUEST_ERR == e.Code);
1112         }
1113         try {
1114             xElemFoo.replaceChild(xElemFooNs, xElemFooNs); // child
1115             assertFalse("XElement.replaceChild(xElemFooNs, xElemFooNs)",
1116                     false);
1117         } catch (DOMException e) {
1118             assertTrue("XElement.replaceChild(xElemFooNs, xElemFooNs)",
1119                     HIERARCHY_REQUEST_ERR == e.Code);
1120         }
1121         XNode xReplaced = xElemFoo.replaceChild(xComment, xText);
1122         assertEquals("XElement.replaceChild(xComment, xText)",
1123                 xReplaced, xText);
1124         assertEquals("XElement.replaceChild(xComment, xText)",
1125                 xComment, xElemFoo.getFirstChild());
1126         assertEquals("XElement.replaceChild(xComment, xText)",
1127                 xElemFooNs, xElemFoo.getLastChild());
1128 
1129         try {
1130             xElemFoo.removeChild(null);
1131             fail("XElement.removeChild(null)");
1132         } catch (Exception e) { /* expected */ }
1133         try {
1134             xElemFoo.removeChild(xElemFoo);
1135             fail("XElement.removeChild()");
1136         } catch (DOMException e) {
1137             assertTrue("XElement.removeChild()",
1138                     HIERARCHY_REQUEST_ERR == e.Code);
1139         }
1140 
1141         XNode xRemoved = xElemFoo.removeChild(xComment);
1142         assertEquals("XElement.removeChild(xComment)", xRemoved, xComment);
1143         assertTrue("XElement.removeChild(xComment)", xElemFoo.hasChildNodes());
1144         assertEquals("XElement.removeChild(xComment)",
1145                 xElemFooNs, xElemFoo.getFirstChild());
1146         assertEquals("XElement.removeChild(xComment)",
1147                 xElemFooNs, xElemFoo.getLastChild());
1148     }
1149 
testXAttr()1150     @Test public void testXAttr() throws Exception
1151     {
1152         XDocumentBuilder xBuilder =
1153             UnoRuntime.queryInterface(XDocumentBuilder.class,
1154             m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
1155         XDocument xDoc = xBuilder.newDocument();
1156 
1157         String ns = "http://example.com/";
1158 
1159         XAttr xAttr = xDoc.createAttribute("foo");
1160         assertNotNull("XDocument.createAttribute", xAttr);
1161 
1162         XAttr xAttrNs = xDoc.createAttributeNS(ns, "e:foo");
1163         assertNotNull("XDocument.createAttribute", xAttr);
1164 
1165         assertTrue("XAttr.getSpecified", xAttr.getSpecified());
1166 
1167         assertEquals("XAttr.getName()", "foo", xAttr.getName());
1168 
1169         assertNull("XAttr.getOwnerElement()", xAttr.getOwnerElement());
1170 
1171         XElement xElemFoo = xDoc.createElement("foo");
1172         XNode xInserted = xElemFoo.appendChild(xAttr);
1173         XAttr xAttrIns =
1174             UnoRuntime.queryInterface(XAttr.class, xInserted);
1175         assertNotNull(xAttrIns);
1176         assertEquals("XAttr.getOwnerElement()",
1177                 xElemFoo, xAttrIns.getOwnerElement());
1178 
1179         assertEquals("XAttr.getValue()", "", xAttr.getValue());
1180 
1181         xAttr.setValue("bar");
1182         assertEquals("XAttr.setValue()", "bar", xAttr.getValue());
1183 
1184         // XNode ////////////////////////////////////////////////////
1185 
1186         {
1187             XNode xAttrCloneN = xAttr.cloneNode(false);
1188             assertNotNull("XAttr.cloneNode(false)", xAttrCloneN);
1189             XAttr xAttrClone =
1190                 UnoRuntime.queryInterface(XAttr.class, xAttrCloneN);
1191             assertNotNull("XAttr.cloneNode(false)", xAttrClone);
1192             // actually the children are copied even if bDeep=false
1193             // does that make sense for attributes?
1194             /*
1195             assertFalse("XAttr.cloneNode(false)", xAttrClone.hasChildNodes());
1196             assertNull("XAttr.cloneNode(false)", xAttrClone.getFirstChild());
1197             */
1198             assertTrue("XAttr.cloneNode(true)", xAttrClone.hasChildNodes());
1199             XNode xChild = xAttrClone.getFirstChild();
1200             assertNotNull("XAttr.cloneNode(true)", xChild);
1201             XText xText = UnoRuntime.queryInterface(XText.class, xChild);
1202             assertNotNull("XAttr.cloneNode(true)", xText);
1203             assertEquals("XAttr.cloneNode(true)", "bar", xText.getNodeValue());
1204         }
1205         {
1206             XNode xAttrCloneN = xAttr.cloneNode(true);
1207             assertNotNull("XAttr.cloneNode(true)", xAttrCloneN);
1208             XAttr xAttrClone =
1209                 UnoRuntime.queryInterface(XAttr.class, xAttrCloneN);
1210             assertNotNull("XAttr.cloneNode(true)", xAttrClone);
1211             assertTrue("XAttr.cloneNode(true)", xAttrClone.hasChildNodes());
1212             XNode xChild = xAttrClone.getFirstChild();
1213             assertNotNull("XAttr.cloneNode(true)", xChild);
1214             XText xText = UnoRuntime.queryInterface(XText.class, xChild);
1215             assertNotNull("XAttr.cloneNode(true)", xText);
1216             assertEquals("XAttr.cloneNode(true)", "bar", xText.getNodeValue());
1217         }
1218 
1219         assertNull("XAttr.getAttributes()", xAttr.getAttributes());
1220 
1221         {
1222             XNodeList xChildren = xAttr.getChildNodes();
1223             assertTrue("XAttr.getChildNodes()", 1 == xChildren.getLength());
1224             XNode xChild = xChildren.item(0);
1225             assertNotNull("XAttr.getChildNodes()", xChild);
1226             XText xText = UnoRuntime.queryInterface(XText.class, xChild);
1227             assertNotNull("XAttr.getChildNodes()", xText);
1228 
1229             XNode xFirst = xAttr.getFirstChild();
1230             assertEquals("XAttr.getFirstChild()", xText, xFirst);
1231             XNode xLast = xAttr.getLastChild();
1232             assertEquals("XAttr.getLastChild()", xText, xLast);
1233         }
1234 
1235         assertEquals("XAttr.getLocalName()", "foo", xAttr.getLocalName());
1236         assertEquals("XAttr.getLocalName()", "foo", xAttrNs.getLocalName());
1237 
1238         assertEquals("XAttr.getNamespaceURI()", "", xAttr.getNamespaceURI());
1239         assertEquals("XAttr.getNamespaceURI()", ns, xAttrNs.getNamespaceURI());
1240 
1241         assertNull("XAttr.getNextSibling()", xAttr.getNextSibling());
1242 
1243         assertEquals("XAttr.getNodeName()", "foo", xAttr.getNodeName());
1244         assertEquals("XAttr.getNodeName()", "foo", xAttrNs.getNodeName());
1245 
1246         assertTrue("XAttr.getNodeType()",
1247                 ATTRIBUTE_NODE == xAttr.getNodeType());
1248 
1249         assertEquals("XAttr.getNodeValue()", "bar", xAttr.getNodeValue());
1250         assertEquals("XAttr.getNodeValue()", "", xAttrNs.getNodeValue());
1251 
1252         assertEquals("XAttr.getOwnerDocument()",
1253                 xDoc, xDoc.getOwnerDocument());
1254 
1255         assertNull("XAttr.getParentNode()", xAttr.getParentNode());
1256 
1257         assertEquals("XAttr.getPrefix()", "", xAttr.getPrefix());
1258         assertEquals("XAttr.getPrefix()", "e", xAttrNs.getPrefix());
1259 
1260         assertNull("XAttr.getPreviousSibling()", xAttr.getPreviousSibling());
1261 
1262         assertFalse("XAttr.hasAttributes()", xAttr.hasAttributes());
1263 
1264         assertTrue("XAttr.hasChildNodes()", xAttr.hasChildNodes());
1265 
1266         assertFalse("XAttr.isSupported()",
1267                 xAttr.isSupported("frobnication", "v99.33.0.0.0.1"));
1268 
1269         xAttr.normalize();
1270 
1271         xAttr.setNodeValue("42");
1272         assertEquals("XAttr.setNodeValue()", "42", xAttr.getNodeValue());
1273 
1274         xAttrNs.setPrefix("f");
1275         assertEquals("XAttr.setPrefix()", "f", xAttrNs.getPrefix());
1276 
1277         XText xText = xDoc.createTextNode("baz");
1278         XText xTextNew = xDoc.createTextNode("quux");
1279 
1280         try {
1281             xAttr.appendChild(null);
1282             fail("XAttr.appendChild(null)");
1283         } catch (Exception e) { /* expected */ }
1284 
1285         try {
1286             xAttr.insertBefore(null, xText);
1287             fail("XAttr.insertBefore(null,)");
1288         } catch (Exception e) { /* expected */ }
1289         try {
1290             xAttr.insertBefore(xText, null);
1291             fail("XAttr.insertBefore(, null)");
1292         } catch (Exception e) { /* expected */ }
1293         try {
1294             xAttr.insertBefore(xText, xText);
1295             fail("XAttr.insertBefore(x, x)");
1296         } catch (DOMException e) {
1297             assertTrue("XAttr.insertBefore(x, x)",
1298                     HIERARCHY_REQUEST_ERR == e.Code);
1299         }
1300 
1301         XNode xChild = xAttr.getFirstChild();
1302         assertNotNull(xChild);
1303 
1304         {
1305             XNode xRet = xAttr.insertBefore(xText, xChild);
1306             assertEquals("XAttr.insertBefore(xText, xChild)",
1307                     xRet, xChild); // why does this return the old node?
1308             assertEquals("XAttr.insertBefore(xText, xChild)",
1309                     xText, xAttr.getFirstChild());
1310             assertEquals("XAttr.insertBefore(xText, xChild)",
1311                     xAttr, xText.getParentNode());
1312             assertEquals("XAttr.insertBefore(xText, xChild)",
1313                     xChild, xAttr.getLastChild());
1314         }
1315 
1316         try {
1317             xAttr.replaceChild(null, xText);
1318             fail("XAttr.replaceChild(null, )");
1319         } catch (Exception e) { /* expected */ }
1320         try {
1321             xAttr.replaceChild(xText, null);
1322             fail("XAttr.replaceChild(, null)");
1323         } catch (Exception e) { /* expected */ }
1324         try {
1325             xAttr.replaceChild(xAttrNs, xAttrNs); // not child
1326             fail("XAttr.replaceChild(xAttrNs, xAttrNs)");
1327         } catch (DOMException e) {
1328             assertTrue("XAttr.replaceChild(xAttrNs, xAttrNs)",
1329                     HIERARCHY_REQUEST_ERR == e.Code);
1330         }
1331         try {
1332             xAttr.replaceChild(xChild, xChild); // child
1333             assertFalse("XAttr.replaceChild(xChild, xChild)",
1334                     false);
1335         } catch (DOMException e) {
1336             assertTrue("XAttr.replaceChild(xChild, xChild)",
1337                     HIERARCHY_REQUEST_ERR == e.Code);
1338         }
1339         XNode xReplaced = xAttr.replaceChild(xTextNew, xChild);
1340         assertEquals("XAttr.replaceChild(xTextNew, xChild)", xChild, xReplaced);
1341         assertEquals("XAttr.replaceChild(xTextNew, xChild)",
1342                 xText, xAttr.getFirstChild());
1343         assertEquals("XAttr.replaceChild(xTextNew, xChild)",
1344                 xTextNew, xAttr.getLastChild());
1345 
1346         try {
1347             xAttr.removeChild(null);
1348             fail("XAttr.removeChild(null)");
1349         } catch (Exception e) { /* expected */ }
1350         try {
1351             xAttr.removeChild(xAttrNs);
1352             fail("XAttr.removeChild()");
1353         } catch (DOMException e) {
1354             assertTrue("XAttr.removeChild()", HIERARCHY_REQUEST_ERR == e.Code);
1355         }
1356 
1357         XNode xRemoved = xAttr.removeChild(xTextNew);
1358         assertEquals("XAttr.removeChild(xText)", xRemoved, xTextNew);
1359         assertTrue("XAttr.removeChild(xText)", xAttr.hasChildNodes());
1360         assertEquals("XAttr.removeChild(xText)",
1361                 xText, xAttr.getFirstChild());
1362         assertEquals("XAttr.removeChild(xText)",
1363                 xText, xAttr.getLastChild());
1364     }
1365 
testXText()1366     @Test public void testXText() throws Exception
1367     {
1368         XDocumentBuilder xBuilder =
1369             UnoRuntime.queryInterface(XDocumentBuilder.class,
1370             m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
1371         XDocument xDoc = xBuilder.newDocument();
1372 
1373         XText xText = xDoc.createTextNode("foobar");
1374         assertNotNull(xText);
1375 
1376         assertEquals("XText.getData", "foobar", xText.getData());
1377         assertEquals("XText.getLength", 6, xText.getLength());
1378 
1379         /* FIXME
1380         try {
1381             xText.splitText(9999);
1382             fail("XText.splitText(9999)");
1383         } catch (DOMException e) {
1384             assertTrue("XText.splitText(9999)", INDEX_SIZE_ERR == e.Code);
1385         }
1386 
1387         {
1388             XText xTextBar = xText.splitText(2);
1389             assertNotNull("XText.splitText", xTextBar);
1390             assertEquals("XText.splitText", "foo", xText.getData());
1391             assertEquals("XText.splitText", "bar", xTextBar.getData());
1392         }
1393         */
1394         xText.setData("foo");
1395 
1396         xText.appendData("baz");
1397         assertEquals("XText.appendData", "foobaz", xText.getData());
1398 
1399         try {
1400             xText.deleteData(999,999);
1401             fail("XText.deleteData(999,999)");
1402         } catch (DOMException e) {
1403             assertTrue("XText.deleteData(999,999)", INDEX_SIZE_ERR == e.Code);
1404         }
1405         xText.deleteData(0, 3);
1406         assertEquals("XText.deleteData", "baz", xText.getData());
1407 
1408         try {
1409             xText.insertData(999,"blah");
1410             fail("XText.insertData(999,\"blah\")");
1411         } catch (DOMException e) {
1412             assertTrue("XText.insertData(999,\"blah\")",
1413                 INDEX_SIZE_ERR == e.Code);
1414         }
1415         xText.insertData(1, "arb");
1416         assertEquals("XText.insertData", "barbaz", xText.getData());
1417 
1418         try {
1419             xText.replaceData(999,999,"x");
1420             fail("XText.replaceData(999,999,\"x\")");
1421         } catch (DOMException e) {
1422             assertTrue("XText.replaceData(999,999,\"x\")",
1423                     INDEX_SIZE_ERR == e.Code);
1424         }
1425         xText.replaceData(3, 3, "foo");
1426         assertEquals("XText.replaceData", "barfoo", xText.getData());
1427 
1428         xText.setData("quux");
1429         assertEquals("XText.setData", "quux", xText.getData());
1430 
1431         try {
1432             xText.subStringData(999,999);
1433             fail("XText.subStringData(999,999)");
1434         } catch (DOMException e) {
1435             assertTrue("XText.subStringData(999,999)",
1436                 INDEX_SIZE_ERR == e.Code);
1437         }
1438         assertEquals("XText.subStringData", "x", xText.subStringData(3, 1));
1439 
1440         // XNode ////////////////////////////////////////////////////
1441 
1442         {
1443             XNode xTextCloneN = xText.cloneNode(false);
1444             assertNotNull("XText.cloneNode(false)", xTextCloneN);
1445             XText xTextClone =
1446                 UnoRuntime.queryInterface(XText.class, xTextCloneN);
1447             assertNotNull("XText.cloneNode(false)", xTextClone);
1448             assertFalse("XText.cloneNode(false)",
1449                     xTextClone.hasChildNodes());
1450         }
1451         {
1452             XNode xTextCloneN = xText.cloneNode(true);
1453             assertNotNull("XText.cloneNode(true)", xTextCloneN);
1454             XText xTextClone =
1455                 UnoRuntime.queryInterface(XText.class, xTextCloneN);
1456             assertNotNull("XText.cloneNode(true)", xTextClone);
1457             assertFalse("XText.cloneNode(true)", xTextClone.hasChildNodes());
1458         }
1459 
1460         assertNull("XText.getAttributes()", xText.getAttributes());
1461 
1462         {
1463             XNodeList xChildren = xText.getChildNodes();
1464             assertTrue("XText.getChildNodes()", 0 == xChildren.getLength());
1465         }
1466 
1467         assertEquals("XText.getLocalName()", "", xText.getLocalName());
1468 
1469         assertEquals("XText.getNamespaceURI()", "", xText.getNamespaceURI());
1470 
1471         assertNull("XText.getNextSibling()", xText.getNextSibling());
1472 
1473         assertEquals("XText.getNodeName()", "#text", xText.getNodeName());
1474 
1475         assertTrue("XText.getNodeType()",
1476                 TEXT_NODE == xText.getNodeType());
1477 
1478         assertEquals("XText.getNodeValue()", "quux", xText.getNodeValue());
1479 
1480         assertEquals("XText.getOwnerDocument()",
1481                 xDoc, xText.getOwnerDocument());
1482 
1483         assertNull("XText.getParentNode()", xText.getParentNode());
1484 
1485         assertEquals("XText.getPrefix()", "", xText.getPrefix());
1486 
1487         assertNull("XText.getPreviousSibling()", xText.getPreviousSibling());
1488 
1489         assertFalse("XText.hasAttributes()", xText.hasAttributes());
1490 
1491         assertFalse("XText.hasChildNodes()", xText.hasChildNodes());
1492 
1493         assertFalse("XText.isSupported()",
1494                 xText.isSupported("frobnication", "v99.33.0.0.0.1"));
1495 
1496         xText.normalize();
1497 
1498         xText.setNodeValue("42");
1499         assertEquals("XText.setNodeValue()", "42", xText.getNodeValue());
1500 
1501         try {
1502             xText.setPrefix("foo");
1503             fail("XText.setPrefix()");
1504         } catch (DOMException e) {
1505             assertTrue("XText.setPrefix()",
1506                     NO_MODIFICATION_ALLOWED_ERR == e.Code);
1507         }
1508 
1509         XText xText2 = xDoc.createTextNode("foobar");
1510         XText xText3 = xDoc.createTextNode("foobar");
1511 
1512         try {
1513             xText.appendChild(null);
1514             fail("XText.appendChild(null)");
1515         } catch (Exception e) { /* expected */ }
1516         try {
1517             xText.appendChild(xText2);
1518             fail("XText.appendChild(xText2)");
1519         } catch (DOMException e) {
1520             assertTrue("XText.appendChild(xText2)",
1521                     HIERARCHY_REQUEST_ERR == e.Code);
1522         }
1523 
1524         try {
1525             xText.insertBefore(xText2, xText3);
1526             fail("XText.insertBefore");
1527         } catch (Exception e) { /* expected */ }
1528 
1529         try {
1530             xText.replaceChild(xText2, xText3);
1531             fail("XText.insertBefore");
1532         } catch (Exception e) { /* expected */ }
1533 
1534         try {
1535             xText.removeChild(null);
1536             fail("XText.removeChild(null)");
1537         } catch (Exception e) { /* expected */ }
1538 
1539         try {
1540             xText.removeChild(xText2);
1541             fail("XText.removeChild");
1542         } catch (DOMException e) {
1543             assertTrue("XText.removeChild", HIERARCHY_REQUEST_ERR == e.Code);
1544         }
1545     }
1546 
testXCDataSection()1547     @Test public void testXCDataSection() throws Exception
1548     {
1549         XDocumentBuilder xBuilder =
1550             UnoRuntime.queryInterface(XDocumentBuilder.class,
1551             m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
1552         XDocument xDoc = xBuilder.newDocument();
1553 
1554         XCDATASection xCDS = xDoc.createCDATASection("foobar");
1555         assertNotNull(xCDS);
1556 
1557         assertEquals("XCDATASection.getData", "foobar", xCDS.getData());
1558         assertEquals("XCDATASection.getLength", 6, xCDS.getLength());
1559 
1560         /* FIXME
1561         try {
1562             xCDS.splitText(9999);
1563             fail("XCDATASection.splitText(9999)");
1564         } catch (DOMException e) {
1565             assertTrue("XCDATASection.splitText(9999)",
1566                 INDEX_SIZE_ERR == e.Code);
1567         }
1568 
1569         {
1570             XCDATASection xCDSBar = xCDS.splitText(2);
1571             assertNotNull("XCDATASection.splitText", xCDSBar);
1572             assertEquals("XCDATASection.splitText", "foo", xCDS.getData());
1573             assertEquals("XCDATASection.splitText", "bar", xCDSBar.getData());
1574         }
1575         */
1576         xCDS.setData("foo");
1577 
1578         xCDS.appendData("baz");
1579         assertEquals("XCDATASection.appendData", "foobaz", xCDS.getData());
1580 
1581         try {
1582             xCDS.deleteData(999,999);
1583             fail("XCDATASection.deleteData(999,999)");
1584         } catch (DOMException e) {
1585             assertTrue("XCDATASection.deleteData(999,999)",
1586                     INDEX_SIZE_ERR == e.Code);
1587         }
1588         xCDS.deleteData(0, 3);
1589         assertEquals("XCDATASection.deleteData", "baz", xCDS.getData());
1590 
1591         try {
1592             xCDS.insertData(999,"blah");
1593             fail("XCDATASection.insertData(999,\"blah\")");
1594         } catch (DOMException e) {
1595             assertTrue("XCDATASection.insertData(999,\"blah\")",
1596                 INDEX_SIZE_ERR == e.Code);
1597         }
1598         xCDS.insertData(1, "arb");
1599         assertEquals("XCDATASection.insertData", "barbaz", xCDS.getData());
1600 
1601         try {
1602             xCDS.replaceData(999,999,"x");
1603             fail("XCDATASection.replaceData(999,999,\"x\")");
1604         } catch (DOMException e) {
1605             assertTrue("XCDATASection.replaceData(999,999,\"x\")",
1606                     INDEX_SIZE_ERR == e.Code);
1607         }
1608         xCDS.replaceData(3, 3, "foo");
1609         assertEquals("XCDATASection.replaceData", "barfoo", xCDS.getData());
1610 
1611         xCDS.setData("quux");
1612         assertEquals("XCDATASection.setData", "quux", xCDS.getData());
1613 
1614         try {
1615             xCDS.subStringData(999,999);
1616             fail("XCDATASection.subStringData(999,999)");
1617         } catch (DOMException e) {
1618             assertTrue("XCDATASection.subStringData(999,999)",
1619                 INDEX_SIZE_ERR == e.Code);
1620         }
1621         assertEquals("XCDATASection.subStringData", "x",
1622                 xCDS.subStringData(3, 1));
1623 
1624         // XNode ////////////////////////////////////////////////////
1625 
1626         {
1627             XNode xCDSCloneN = xCDS.cloneNode(false);
1628             assertNotNull("XCDATASection.cloneNode(false)", xCDSCloneN);
1629             XCDATASection xCDSClone =
1630                 UnoRuntime.queryInterface(XCDATASection.class, xCDSCloneN);
1631             assertNotNull("XCDATASection.cloneNode(false)", xCDSClone);
1632             assertFalse("XCDATASection.cloneNode(false)",
1633                     xCDSClone.hasChildNodes());
1634         }
1635         {
1636             XNode xCDSCloneN = xCDS.cloneNode(true);
1637             assertNotNull("XCDATASection.cloneNode(true)", xCDSCloneN);
1638             XCDATASection xCDSClone =
1639                 UnoRuntime.queryInterface(XCDATASection.class, xCDSCloneN);
1640             assertNotNull("XCDATASection.cloneNode(true)", xCDSClone);
1641             assertFalse("XCDATASection.cloneNode(true)",
1642                     xCDSClone.hasChildNodes());
1643         }
1644 
1645         assertNull("XCDATASection.getAttributes()", xCDS.getAttributes());
1646 
1647         {
1648             XNodeList xChildren = xCDS.getChildNodes();
1649             assertTrue("XCDATASection.getChildNodes()",
1650                     0 == xChildren.getLength());
1651         }
1652 
1653         assertEquals("XCDATASection.getLocalName()", "", xCDS.getLocalName());
1654 
1655         assertEquals("XCDATASection.getNamespaceURI()", "",
1656                 xCDS.getNamespaceURI());
1657 
1658         assertNull("XCDATASection.getNextSibling()", xCDS.getNextSibling());
1659 
1660         assertEquals("XCDATASection.getNodeName()", "#cdata-section",
1661                 xCDS.getNodeName());
1662 
1663         assertTrue("XCDATASection.getNodeType()",
1664                 CDATA_SECTION_NODE == xCDS.getNodeType());
1665 
1666         assertEquals("XCDATASection.getNodeValue()", "quux",
1667                 xCDS.getNodeValue());
1668 
1669         assertEquals("XCDATASection.getOwnerDocument()",
1670                 xDoc, xCDS.getOwnerDocument());
1671 
1672         assertNull("XCDATASection.getParentNode()", xCDS.getParentNode());
1673 
1674         assertEquals("XCDATASection.getPrefix()", "", xCDS.getPrefix());
1675 
1676         assertNull("XCDATASection.getPreviousSibling()",
1677                 xCDS.getPreviousSibling());
1678 
1679         assertFalse("XCDATASection.hasAttributes()", xCDS.hasAttributes());
1680 
1681         assertFalse("XCDATASection.hasChildNodes()", xCDS.hasChildNodes());
1682 
1683         assertFalse("XCDATASection.isSupported()",
1684                 xCDS.isSupported("frobnication", "v99.33.0.0.0.1"));
1685 
1686         xCDS.normalize();
1687 
1688         xCDS.setNodeValue("42");
1689         assertEquals("XCDATASection.setNodeValue()", "42", xCDS.getNodeValue());
1690 
1691         try {
1692             xCDS.setPrefix("foo");
1693             fail("XCDATASection.setPrefix()");
1694         } catch (DOMException e) {
1695             assertTrue("XCDATASection.setPrefix()",
1696                     NO_MODIFICATION_ALLOWED_ERR == e.Code);
1697         }
1698 
1699         XCDATASection xCDS2 = xDoc.createCDATASection("foobar");
1700         XCDATASection xCDS3 = xDoc.createCDATASection("foobar");
1701 
1702         try {
1703             xCDS.appendChild(null);
1704             fail("XCDATASection.appendChild(null)");
1705         } catch (Exception e) { /* expected */ }
1706         try {
1707             xCDS.appendChild(xCDS2);
1708             fail("XCDATASection.appendChild(xCDS2)");
1709         } catch (DOMException e) {
1710             assertTrue("XCDATASection.appendChild(xCDS2)",
1711                     HIERARCHY_REQUEST_ERR == e.Code);
1712         }
1713 
1714         try {
1715             xCDS.insertBefore(xCDS2, xCDS3);
1716             fail("XCDATASection.insertBefore");
1717         } catch (Exception e) { /* expected */ }
1718 
1719         try {
1720             xCDS.replaceChild(xCDS2, xCDS3);
1721             fail("XCDATASection.insertBefore");
1722         } catch (Exception e) { /* expected */ }
1723 
1724         try {
1725             xCDS.removeChild(null);
1726             fail("XCDATASection.removeChild(null)");
1727         } catch (Exception e) { /* expected */ }
1728 
1729         try {
1730             xCDS.removeChild(xCDS2);
1731             fail("XCDATASection.removeChild");
1732         } catch (DOMException e) {
1733             assertTrue("XCDATASection.removeChild",
1734                     HIERARCHY_REQUEST_ERR == e.Code);
1735         }
1736 
1737     }
1738 
testXComment()1739     @Test public void testXComment() throws Exception
1740     {
1741         XDocumentBuilder xBuilder =
1742             UnoRuntime.queryInterface(XDocumentBuilder.class,
1743             m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
1744         XDocument xDoc = xBuilder.newDocument();
1745 
1746         XComment xComment = xDoc.createComment("foo");
1747         assertNotNull(xComment);
1748 
1749         assertEquals("XComment.getData", "foo", xComment.getData());
1750         assertEquals("XComment.getLength", 3, xComment.getLength());
1751 
1752         xComment.appendData("baz");
1753         assertEquals("XComment.appendData", "foobaz", xComment.getData());
1754 
1755         try {
1756             xComment.deleteData(999,999);
1757             fail("XComment.deleteData(999,999)");
1758         } catch (DOMException e) {
1759             assertTrue("XComment.deleteData(999,999)",
1760                     INDEX_SIZE_ERR == e.Code);
1761         }
1762         xComment.deleteData(0, 3);
1763         assertEquals("XComment.deleteData", "baz", xComment.getData());
1764 
1765         try {
1766             xComment.insertData(999,"blah");
1767             fail("XComment.insertData(999,\"blah\")");
1768         } catch (DOMException e) {
1769             assertTrue("XComment.insertData(999,\"blah\")",
1770                 INDEX_SIZE_ERR == e.Code);
1771         }
1772         xComment.insertData(1, "arb");
1773         assertEquals("XComment.insertData", "barbaz", xComment.getData());
1774 
1775         try {
1776             xComment.replaceData(999,999,"x");
1777             fail("XComment.replaceData(999,999,\"x\")");
1778         } catch (DOMException e) {
1779             assertTrue("XComment.replaceData(999,999,\"x\")",
1780                     INDEX_SIZE_ERR == e.Code);
1781         }
1782         xComment.replaceData(3, 3, "foo");
1783         assertEquals("XComment.replaceData", "barfoo", xComment.getData());
1784 
1785         xComment.setData("quux");
1786         assertEquals("XComment.setData", "quux", xComment.getData());
1787 
1788         try {
1789             xComment.subStringData(999,999);
1790             fail("XComment.subStringData(999,999)");
1791         } catch (DOMException e) {
1792             assertTrue("XComment.subStringData(999,999)",
1793                 INDEX_SIZE_ERR == e.Code);
1794         }
1795         assertEquals("XComment.subStringData", "x",
1796                 xComment.subStringData(3, 1));
1797 
1798         // XNode ////////////////////////////////////////////////////
1799 
1800         {
1801             XNode xCommentCloneN = xComment.cloneNode(false);
1802             assertNotNull("XComment.cloneNode(false)", xCommentCloneN);
1803             XComment xCommentClone =
1804                 UnoRuntime.queryInterface(XComment.class, xCommentCloneN);
1805             assertNotNull("XComment.cloneNode(false)", xCommentClone);
1806             assertFalse("XComment.cloneNode(false)",
1807                     xCommentClone.hasChildNodes());
1808         }
1809         {
1810             XNode xCommentCloneN = xComment.cloneNode(true);
1811             assertNotNull("XComment.cloneNode(true)", xCommentCloneN);
1812             XComment xCommentClone =
1813                 UnoRuntime.queryInterface(XComment.class, xCommentCloneN);
1814             assertNotNull("XComment.cloneNode(true)", xCommentClone);
1815             assertFalse("XComment.cloneNode(true)",
1816                     xCommentClone.hasChildNodes());
1817         }
1818 
1819         assertNull("XComment.getAttributes()", xComment.getAttributes());
1820 
1821         {
1822             XNodeList xChildren = xComment.getChildNodes();
1823             assertTrue("XComment.getChildNodes()", 0 == xChildren.getLength());
1824         }
1825 
1826         assertEquals("XComment.getLocalName()", "", xComment.getLocalName());
1827 
1828         assertEquals("XComment.getNamespaceURI()", "",
1829                 xComment.getNamespaceURI());
1830 
1831         assertNull("XComment.getNextSibling()", xComment.getNextSibling());
1832 
1833         assertEquals("XComment.getNodeName()", "#comment",
1834                 xComment.getNodeName());
1835 
1836         assertTrue("XComment.getNodeType()",
1837                 COMMENT_NODE == xComment.getNodeType());
1838 
1839         assertEquals("XComment.getNodeValue()", "quux",
1840                 xComment.getNodeValue());
1841 
1842         assertEquals("XComment.getOwnerDocument()",
1843                 xDoc, xComment.getOwnerDocument());
1844 
1845         assertNull("XComment.getParentNode()", xComment.getParentNode());
1846 
1847         assertEquals("XComment.getPrefix()", "", xComment.getPrefix());
1848 
1849         assertNull("XComment.getPreviousSibling()",
1850                 xComment.getPreviousSibling());
1851 
1852         assertFalse("XComment.hasAttributes()", xComment.hasAttributes());
1853 
1854         assertFalse("XComment.hasChildNodes()", xComment.hasChildNodes());
1855 
1856         assertFalse("XComment.isSupported()",
1857                 xComment.isSupported("frobnication", "v99.33.0.0.0.1"));
1858 
1859         xComment.normalize();
1860 
1861         xComment.setNodeValue("42");
1862         assertEquals("XComment.setNodeValue()", "42", xComment.getNodeValue());
1863 
1864         try {
1865             xComment.setPrefix("foo");
1866             fail("XComment.setPrefix()");
1867         } catch (DOMException e) {
1868             assertTrue("XComment.setPrefix()",
1869                     NO_MODIFICATION_ALLOWED_ERR == e.Code);
1870         }
1871 
1872         XComment xComment2 = xDoc.createComment("foobar");
1873         XComment xComment3 = xDoc.createComment("foobar");
1874 
1875         try {
1876             xComment.appendChild(null);
1877             fail("XComment.appendChild(null)");
1878         } catch (Exception e) { /* expected */ }
1879         try {
1880             xComment.appendChild(xComment2);
1881             fail("XComment.appendChild(xComment2)");
1882         } catch (DOMException e) {
1883             assertTrue("XComment.appendChild(xComment2)",
1884                     HIERARCHY_REQUEST_ERR == e.Code);
1885         }
1886 
1887         try {
1888             xComment.insertBefore(xComment2, xComment3);
1889             fail("XComment.insertBefore");
1890         } catch (Exception e) { /* expected */ }
1891 
1892         try {
1893             xComment.replaceChild(xComment2, xComment3);
1894             fail("XComment.insertBefore");
1895         } catch (Exception e) { /* expected */ }
1896 
1897         try {
1898             xComment.removeChild(null);
1899             fail("XComment.removeChild(null)");
1900         } catch (Exception e) { /* expected */ }
1901 
1902         try {
1903             xComment.removeChild(xComment2);
1904             fail("XComment.removeChild");
1905         } catch (DOMException e) {
1906             assertTrue("XComment.removeChild", HIERARCHY_REQUEST_ERR == e.Code);
1907         }
1908     }
1909 
testXEntityReference()1910     @Test public void testXEntityReference() throws Exception
1911     {
1912         XDocumentBuilder xBuilder =
1913             UnoRuntime.queryInterface(XDocumentBuilder.class,
1914             m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
1915         XDocument xDoc = xBuilder.newDocument();
1916 
1917         XEntityReference xER = xDoc.createEntityReference("foobar");
1918         assertNotNull(xER);
1919 
1920         XEntityReference xERChild = xDoc.createEntityReference("baz");
1921         assertNotNull(xERChild);
1922 
1923         xER.appendChild(xERChild);
1924 
1925         // XNode ////////////////////////////////////////////////////
1926 
1927         XText xText = xDoc.createTextNode("foo");
1928         XComment xComment = xDoc.createComment("foo");
1929 
1930         {
1931             XNode xERCloneN = xER.cloneNode(false);
1932             assertNotNull("XEntityReference.cloneNode(false)", xERCloneN);
1933             XEntityReference xERClone =
1934                 UnoRuntime.queryInterface(XEntityReference.class, xERCloneN);
1935             assertNotNull("XEntityReference.cloneNode(false)", xERClone);
1936             assertFalse("XEntityReference.cloneNode(false)",
1937                     xERClone.hasChildNodes());
1938             assertNull("XEntityReference.cloneNode(false)",
1939                     xERClone.getFirstChild());
1940         }
1941         {
1942             XNode xERCloneN = xER.cloneNode(true);
1943             assertNotNull("XEntityReference.cloneNode(true)", xERCloneN);
1944             XEntityReference xERClone =
1945                 UnoRuntime.queryInterface(XEntityReference.class, xERCloneN);
1946             assertNotNull("XEntityReference.cloneNode(true)", xERClone);
1947             /* FIXME this is actually in libxml2: children are not copied
1948             assertTrue("XEntityReference.cloneNode(true)",
1949                     xERClone.hasChildNodes());
1950             XNode xChild = xERClone.getFirstChild();
1951             assertNotNull("XEntityReference.cloneNode(true)", xChild);
1952             XEntityReference xChildER =
1953                 UnoRuntime.queryInterface(XEntityReference.class, xChild);
1954             assertNotNull("XEntityReference.cloneNode(true)", xChildER);
1955             assertFalse("XEntityReference.cloneNode(true)",
1956                     xChildER.equals(xERChild));
1957             assertEquals("XEntityReference.cloneNode(true)",
1958                     "baz", xChildER.getLocalName());
1959             */
1960         }
1961 
1962         assertNull("XEntityReference.getAttributes()", xER.getAttributes());
1963 
1964         {
1965             XNodeList xChildren = xER.getChildNodes();
1966             assertTrue("XEntityReference.getChildNodes()",
1967                     1 == xChildren.getLength());
1968             assertEquals("XEntityReference.getChildNodes()",
1969                     xERChild, xChildren.item(0));
1970 
1971             XNode xFirst = xER.getFirstChild();
1972             assertEquals("XEntityReference.getFirstChild()",
1973                     xERChild, xFirst);
1974             XNode xLast = xER.getLastChild();
1975             assertEquals("XEntityReference.getLastChild()", xERChild, xLast);
1976         }
1977 
1978         assertEquals("XEntityReference.getLocalName()", "", xER.getLocalName());
1979 
1980         assertEquals("XEntityReference.getNamespaceURI()", "",
1981                 xER.getNamespaceURI());
1982 
1983         assertNull("XEntityReference.getNextSibling()", xER.getNextSibling());
1984 
1985         assertEquals("XEntityReference.getNodeName()",
1986                 "foobar", xER.getNodeName());
1987 
1988         assertTrue("XEntityReference.getNodeType()",
1989                 ENTITY_REFERENCE_NODE == xER.getNodeType());
1990 
1991         assertEquals("XEntityReference.getNodeValue()", "", xER.getNodeValue());
1992 
1993         assertEquals("XEntityReference.getOwnerDocument()",
1994                 xDoc, xER.getOwnerDocument());
1995 
1996         assertNull("XEntityReference.getParentNode()", xER.getParentNode());
1997 
1998         assertEquals("XEntityReference.getPrefix()", "", xER.getPrefix());
1999 
2000         assertNull("XEntityReference.getPreviousSibling()",
2001                 xER.getPreviousSibling());
2002 
2003         assertFalse("XEntityReference.hasAttributes()", xER.hasAttributes());
2004 
2005         assertTrue("XEntityReference.hasChildNodes()", xER.hasChildNodes());
2006 
2007         assertFalse("XEntityReference.isSupported()",
2008                 xER.isSupported("frobnication", "v99.33.0.0.0.1"));
2009 
2010         xER.normalize();
2011 
2012         try {
2013             xER.setNodeValue("42");
2014             fail("XEntityReference.setNodeValue()");
2015         } catch (DOMException e) {
2016             assertTrue("XEntityReference.setNodeValue()",
2017                     NO_MODIFICATION_ALLOWED_ERR == e.Code);
2018         }
2019 
2020         try {
2021             xER.setPrefix("foo");
2022             fail("XEntityReference.setPrefix()");
2023         } catch (DOMException e) {
2024             assertTrue("XEntityReference.setPrefix()",
2025                     NO_MODIFICATION_ALLOWED_ERR == e.Code);
2026         }
2027 
2028         try {
2029             xER.appendChild(null);
2030             fail("XEntityReference.appendChild(null)");
2031         } catch (Exception e) { /* expected */ }
2032 
2033         try {
2034             xER.insertBefore(null, xText);
2035             fail("XEntityReference.insertBefore(null,)");
2036         } catch (Exception e) { /* expected */ }
2037         try {
2038             xER.insertBefore(xText, null);
2039             fail("XEntityReference.insertBefore(, null)");
2040         } catch (Exception e) { /* expected */ }
2041         try {
2042             xER.insertBefore(xText, xText);
2043             fail("XEntityReference.insertBefore(x, x)");
2044         } catch (DOMException e) {
2045             assertTrue("XEntityReference.insertBefore(x, x)",
2046                     HIERARCHY_REQUEST_ERR == e.Code);
2047         }
2048 
2049         {
2050             XNode xRet = xER.insertBefore(xComment, xERChild);
2051             assertEquals("XEntityReference.insertBefore(xComment, xERChild)",
2052                     xRet, xERChild); // why does this return the old node?
2053             assertEquals("XEntityReference.insertBefore(xComment, xERChild)",
2054                     xComment, xER.getFirstChild());
2055             assertEquals("XEntityReference.insertBefore(xComment, xERChild)",
2056                     xER, xComment.getParentNode());
2057             assertEquals("XEntityReference.insertBefore(xCommnet, xERChild)",
2058                     xERChild, xER.getLastChild());
2059         }
2060 
2061         try {
2062             xER.replaceChild(null, xText);
2063             fail("XEntityReference.replaceChild(null, )");
2064         } catch (Exception e) { /* expected */ }
2065         try {
2066             xER.replaceChild(xText, null);
2067             fail("XEntityReference.replaceChild(, null)");
2068         } catch (Exception e) { /* expected */ }
2069         try {
2070             xER.replaceChild(xText, xText); // not child
2071             fail("XEntityReference.replaceChild(xElemFoo, xElemFoo)");
2072         } catch (DOMException e) {
2073             assertTrue("XEntityReference.replaceChild(xElemFoo, xElemFoo)",
2074                     HIERARCHY_REQUEST_ERR == e.Code);
2075         }
2076         try {
2077             xER.replaceChild(xERChild, xERChild); // child
2078             assertFalse("XEntityReference.replaceChild(xERChild, xERChild)",
2079                     false);
2080         } catch (DOMException e) {
2081             assertTrue("XEntityReference.replaceChild(xERChild, xERChild)",
2082                     HIERARCHY_REQUEST_ERR == e.Code);
2083         }
2084         XNode xReplaced = xER.replaceChild(xText, xComment);
2085         assertEquals("XEntityReference.replaceChild(xText, xComment)",
2086                 xReplaced, xComment);
2087         assertEquals("XEntityReference.replaceChild(xText, xComment)",
2088                 xText, xER.getFirstChild());
2089         assertEquals("XEntityReference.replaceChild(xText, xComment)",
2090                 xERChild, xER.getLastChild());
2091 
2092         try {
2093             xER.removeChild(null);
2094             fail("XEntityReference.removeChild(null)");
2095         } catch (Exception e) { /* expected */ }
2096         try {
2097             xER.removeChild(xER);
2098             fail("XEntityReference.removeChild()");
2099         } catch (DOMException e) {
2100             assertTrue("XEntityReference.removeChild()",
2101                     HIERARCHY_REQUEST_ERR == e.Code);
2102         }
2103 
2104         XNode xRemoved = xER.removeChild(xText);
2105         assertEquals("XEntityReference.removeChild(xText)", xRemoved, xText);
2106         assertTrue("XEntityReference.removeChild(xText)", xER.hasChildNodes());
2107         assertEquals("XEntityReference.removeChild(xText)",
2108                 xERChild, xER.getFirstChild());
2109         assertEquals("XEntityReference.removeChild(xText)",
2110                 xERChild, xER.getLastChild());
2111     }
2112 
testXProcessingInstruction()2113     @Test public void testXProcessingInstruction() throws Exception
2114     {
2115         XDocumentBuilder xBuilder =
2116             UnoRuntime.queryInterface(XDocumentBuilder.class,
2117             m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
2118         XDocument xDoc = xBuilder.newDocument();
2119 
2120         XProcessingInstruction xPI =
2121             xDoc.createProcessingInstruction("foo", "bar");
2122         assertNotNull(xPI);
2123 
2124         assertEquals("XProcessingInstruction.getTarget",
2125                 "foo", xPI.getTarget());
2126 
2127         assertEquals("XProcessingInstruction.getData", "bar", xPI.getData());
2128 
2129         xPI.setData("baz");
2130         assertEquals("XProcessingInstruction.setData", "baz", xPI.getData());
2131 
2132         // XNode ////////////////////////////////////////////////////
2133 
2134         {
2135             XNode xPICloneN = xPI.cloneNode(false);
2136             assertNotNull("XProcessingInstruction.cloneNode(false)", xPICloneN);
2137             XProcessingInstruction xPIClone = UnoRuntime.queryInterface(
2138                     XProcessingInstruction.class, xPICloneN);
2139             assertNotNull("XProcessingInstruction.cloneNode(false)", xPIClone);
2140             assertFalse("XProcessingInstruction.cloneNode(false)",
2141                     xPIClone.hasChildNodes());
2142         }
2143         {
2144             XNode xPICloneN = xPI.cloneNode(true);
2145             assertNotNull("XProcessingInstruction.cloneNode(true)", xPICloneN);
2146             XProcessingInstruction xPIClone = UnoRuntime.queryInterface(
2147                     XProcessingInstruction.class, xPICloneN);
2148             assertNotNull("XProcessingInstruction.cloneNode(true)", xPIClone);
2149             assertFalse("XProcessingInstruction.cloneNode(true)",
2150                     xPIClone.hasChildNodes());
2151         }
2152 
2153         assertNull("XProcessingInstruction.getAttributes()",
2154                 xPI.getAttributes());
2155 
2156         {
2157             XNodeList xChildren = xPI.getChildNodes();
2158             assertTrue("XProcessingInstruction.getChildNodes()",
2159                     0 == xChildren.getLength());
2160         }
2161 
2162         assertEquals("XProcessingInstruction.getLocalName()",
2163                 "", xPI.getLocalName());
2164 
2165         assertEquals("XProcessingInstruction.getNamespaceURI()",
2166                 "", xPI.getNamespaceURI());
2167 
2168         assertNull("XProcessingInstruction.getNextSibling()",
2169                 xPI.getNextSibling());
2170 
2171         assertEquals("XProcessingInstruction.getNodeName()",
2172                 "foo", xPI.getNodeName());
2173 
2174         assertTrue("XProcessingInstruction.getNodeType()",
2175                 PROCESSING_INSTRUCTION_NODE == xPI.getNodeType());
2176 
2177         assertEquals("XProcessingInstruction.getNodeValue()",
2178                 "baz", xPI.getNodeValue());
2179 
2180         assertEquals("XProcessingInstruction.getOwnerDocument()",
2181                 xDoc, xPI.getOwnerDocument());
2182 
2183         assertNull("XProcessingInstruction.getParentNode()",
2184                 xPI.getParentNode());
2185 
2186         assertEquals("XProcessingInstruction.getPrefix()", "", xPI.getPrefix());
2187 
2188         assertNull("XProcessingInstruction.getPreviousSibling()",
2189                 xPI.getPreviousSibling());
2190 
2191         assertFalse("XProcessingInstruction.hasAttributes()",
2192                 xPI.hasAttributes());
2193 
2194         assertFalse("XProcessingInstruction.hasChildNodes()",
2195                 xPI.hasChildNodes());
2196 
2197         assertFalse("XProcessingInstruction.isSupported()",
2198                 xPI.isSupported("frobnication", "v99.33.0.0.0.1"));
2199 
2200         xPI.normalize();
2201 
2202         xPI.setNodeValue("42");
2203         assertEquals("XProcessingInstruction.setNodeValue()",
2204                 "42", xPI.getNodeValue());
2205 
2206         try {
2207             xPI.setPrefix("foo");
2208             fail("XProcessingInstruction.setPrefix()");
2209         } catch (DOMException e) {
2210             assertTrue("XProcessingInstruction.setPrefix()",
2211                     NO_MODIFICATION_ALLOWED_ERR == e.Code);
2212         }
2213 
2214         XText xText2 = xDoc.createTextNode("foobar");
2215         XText xText3 = xDoc.createTextNode("foobar");
2216 
2217         try {
2218             xPI.appendChild(null);
2219             fail("XProcessingInstruction.appendChild(null)");
2220         } catch (Exception e) { /* expected */ }
2221         try {
2222             xPI.appendChild(xText2);
2223             fail("XProcessingInstruction.appendChild(xText2)");
2224         } catch (DOMException e) {
2225             assertTrue("XProcessingInstruction.appendChild(xText2)",
2226                     HIERARCHY_REQUEST_ERR == e.Code);
2227         }
2228 
2229         try {
2230             xPI.insertBefore(xText2, xText3);
2231             fail("XProcessingInstruction.insertBefore");
2232         } catch (Exception e) { /* expected */ }
2233 
2234         try {
2235             xPI.replaceChild(xText2, xText3);
2236             fail("XProcessingInstruction.insertBefore");
2237         } catch (Exception e) { /* expected */ }
2238 
2239         try {
2240             xPI.removeChild(null);
2241             fail("XProcessingInstruction.removeChild(null)");
2242         } catch (Exception e) { /* expected */ }
2243 
2244         try {
2245             xPI.removeChild(xText2);
2246             fail("XProcessingInstruction.removeChild");
2247         } catch (DOMException e) {
2248             assertTrue("XProcessingInstruction.removeChild",
2249                     HIERARCHY_REQUEST_ERR == e.Code);
2250         }
2251     }
2252 
2253     /*
2254     @Test public void testXEntity() throws Exception
2255     {
2256         XEntity xEntity = FIXME  how to get at this shy creature?
2257     }
2258     */
2259 
2260     /*
2261     @Test public void testXNotation() throws Exception
2262     {
2263         XNotation xNotation = FIXME how to create?
2264     }
2265     */
2266 
2267     /*
2268     @Test public void testXDocumentType() throws Exception
2269     {
2270         XDocumentType xDT = FIXME how to create?
2271     }
2272     */
2273 
testXNodeList_ChildList()2274     @Test public void testXNodeList_ChildList() throws Exception
2275     {
2276         XDocumentBuilder xBuilder =
2277             UnoRuntime.queryInterface(XDocumentBuilder.class,
2278             m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
2279         XDocument xDoc = xBuilder.newDocument();
2280 
2281         XElement xRoot = xDoc.createElement("root");
2282         XElement xFoo = xDoc.createElement("foo");
2283         XElement xBar = xDoc.createElement("bar");
2284         XElement xBaz = xDoc.createElement("baz");
2285 
2286         xDoc.appendChild(xRoot);
2287 
2288         XNodeList xChildList = xRoot.getChildNodes();
2289         assertNotNull(xChildList);
2290         assertSame("ChildList.getLength()", 0, xChildList.getLength());
2291 
2292         try {
2293             xChildList.item(4);
2294         } catch (Exception e) { /* expected */ }
2295 
2296         xRoot.appendChild(xFoo);
2297         assertSame("ChildList.getLength()", 1, xChildList.getLength());
2298         assertEquals("ChildList.item", xFoo, xChildList.item(0));
2299 
2300         xRoot.appendChild(xBar);
2301         assertSame("ChildList.getLength()", 2, xChildList.getLength());
2302         assertEquals("ChildList.item", xFoo, xChildList.item(0));
2303         assertEquals("ChildList.item", xBar, xChildList.item(1));
2304 
2305         xRoot.appendChild(xBaz);
2306         assertSame("ChildList.getLength()", 3, xChildList.getLength());
2307         assertEquals("ChildList.item", xFoo, xChildList.item(0));
2308         assertEquals("ChildList.item", xBar, xChildList.item(1));
2309         assertEquals("ChildList.item", xBaz, xChildList.item(2));
2310 
2311         xRoot.removeChild(xBar);
2312         assertSame("ChildList.getLength()", 2, xChildList.getLength());
2313         assertEquals("ChildList.item", xFoo, xChildList.item(0));
2314         assertEquals("ChildList.item", xBaz, xChildList.item(1));
2315     }
2316 
testXNodeList_ElementList()2317     @Test public void testXNodeList_ElementList() throws Exception
2318     {
2319         XDocumentBuilder xBuilder =
2320             UnoRuntime.queryInterface(XDocumentBuilder.class,
2321             m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
2322         XDocument xDoc = xBuilder.newDocument();
2323 
2324         XElement xRoot = xDoc.createElement("root");
2325         XElement xBar = xDoc.createElement("bar");
2326         XElement xFoo1 = xDoc.createElement("foo");
2327         XElement xFoo2 = xDoc.createElement("foo");
2328         XElement xFoo3 = xDoc.createElement("foo");
2329 
2330         xDoc.appendChild(xRoot);
2331 
2332         XNodeList xElementList = xRoot.getElementsByTagName("foo");
2333         assertNotNull(xElementList);
2334         assertSame("ElementList.getLength()", 0, xElementList.getLength());
2335 
2336         try {
2337             xElementList.item(4);
2338         } catch (Exception e) { /* expected */ }
2339 
2340         xRoot.appendChild(xFoo1);
2341         assertSame("ElementList.getLength()", 1, xElementList.getLength());
2342         assertEquals("ElementList.item", xFoo1, xElementList.item(0));
2343 
2344         xFoo1.appendChild(xBar);
2345         assertSame("ElementList.getLength()", 1, xElementList.getLength());
2346         assertEquals("ElementList.item", xFoo1, xElementList.item(0));
2347 
2348         xRoot.appendChild(xFoo3);
2349         assertSame("ElementList.getLength()", 2, xElementList.getLength());
2350         assertEquals("ElementList.item", xFoo1, xElementList.item(0));
2351         assertEquals("ElementList.item", xFoo3, xElementList.item(1));
2352 
2353         xBar.appendChild(xFoo2);
2354         assertSame("ElementList.getLength()", 3, xElementList.getLength());
2355         assertEquals("ElementList.item", xFoo1, xElementList.item(0));
2356         assertEquals("ElementList.item", xFoo2, xElementList.item(1));
2357         assertEquals("ElementList.item", xFoo3, xElementList.item(2));
2358 
2359         xRoot.removeChild(xFoo1);
2360         assertSame("ElementList.getLength()", 1, xElementList.getLength());
2361         assertEquals("ElementList.item", xFoo3, xElementList.item(0));
2362     }
2363 
testXNamedNodeMap_AttributesMap()2364     @Test public void testXNamedNodeMap_AttributesMap() throws Exception
2365     {
2366         XDocumentBuilder xBuilder =
2367             UnoRuntime.queryInterface(XDocumentBuilder.class,
2368             m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
2369         XDocument xDoc = xBuilder.newDocument();
2370 
2371         String ns = "http://example.com/";
2372 
2373         XElement xElem = xDoc.createElement("foo");
2374 
2375         XNamedNodeMap xAttributes = xElem.getAttributes();
2376         assertNotNull(xAttributes);
2377         assertSame("AttributesMap.getLength()", 0, xAttributes.getLength());
2378 
2379         try {
2380             xAttributes.item(4);
2381         } catch (Exception e) { /* expected */ }
2382 
2383         xElem.setAttribute("bar", "42");
2384         XAttr xAttrBar = xElem.getAttributeNode("bar");
2385         assertSame("AttributesMap.getLength()", 1, xAttributes.getLength());
2386         assertEquals("AttributesMap.item", xAttrBar, xAttributes.item(0));
2387         assertEquals("AttributesMap.getNamedItem",
2388                 xAttrBar, xAttributes.getNamedItem("bar"));
2389 
2390         xElem.setAttributeNS(ns, "n:bar", "43");
2391         XAttr xAttrBarNs = xElem.getAttributeNodeNS(ns, "bar");
2392         assertSame("AttributesMap.getLength()", 2, xAttributes.getLength());
2393         assertEquals("AttributesMap.item", xAttrBar, xAttributes.item(0));
2394         assertEquals("AttributesMap.item", xAttrBarNs, xAttributes.item(1));
2395         assertEquals("AttributesMap.getNamedItem",
2396                 xAttrBar, xAttributes.getNamedItem("bar"));
2397         assertEquals("AttributesMap.getNamedItemNS",
2398                 xAttrBarNs, xAttributes.getNamedItemNS(ns, "bar"));
2399 
2400         XNode xAttrBarNsRem = xAttributes.removeNamedItemNS(ns, "bar");
2401         assertSame("AttributesMap.getLength()", 1, xAttributes.getLength());
2402         assertEquals("AttributesMap.removeNamedItemNS",
2403                 xAttrBar, xAttributes.item(0));
2404         assertEquals("AttributesMap.removeNamedItemNS",
2405                 xAttrBar, xAttributes.getNamedItem("bar"));
2406         assertNull("AttributesMap.removeNamedItemNS",
2407                 xAttrBarNsRem.getParentNode());
2408 
2409         XNode xAttrBarRem = xAttributes.removeNamedItem("bar");
2410         assertSame("AttributesMap.getLength()", 0, xAttributes.getLength());
2411         assertNull("AttributesMap.removeNamedItem",
2412                 xAttrBarRem.getParentNode());
2413 
2414         XNode xAttrBarSetN = xAttributes.setNamedItem(xAttrBarRem);
2415         assertNotNull("AttributesMap.setNamedItem", xAttrBarSetN);
2416         XAttr xAttrBarSet =
2417             UnoRuntime.queryInterface(XAttr.class, xAttrBarSetN);
2418         assertNotNull("AttributesMap.setNamedItem", xAttrBarSet);
2419         assertEquals("AttributesMap.setNamedItem",
2420                 xAttrBarSet, xAttributes.getNamedItem("bar"));
2421 
2422         XNode xAttrBarNsSetN = xAttributes.setNamedItemNS(xAttrBarNsRem);
2423         assertNotNull("AttributesMap.setNamedItemNS", xAttrBarNsSetN);
2424         XAttr xAttrBarNsSet =
2425             UnoRuntime.queryInterface(XAttr.class, xAttrBarNsSetN);
2426         assertNotNull("AttributesMap.setNamedItemNS", xAttrBarNsSet);
2427         assertEquals("AttributesMap.setNamedItemNS",
2428                 xAttrBarNsSet, xAttributes.getNamedItemNS(ns, "bar"));
2429         assertSame("AttributesMap.getLength()", 2, xAttributes.getLength());
2430     }
2431 
2432     /*
2433     @Test public void testXNamedNodeMap_EntitiesMap() throws Exception
2434     {
2435         XNamedNodeMap xEntities = FIXME
2436     }
2437     */
2438 
2439     /*
2440     @Test public void testXNamedNodeMap_NotationsMap() throws Exception
2441     {
2442         XNamedNodeMap xNotations = FIXME
2443     }
2444     */
2445 
testXXPathAPI()2446     @Test public void testXXPathAPI() throws Exception
2447     {
2448         XXPathAPI xXPathAPI =
2449             UnoRuntime.queryInterface(XXPathAPI.class,
2450             m_xMSF.createInstance("com.sun.star.xml.xpath.XPathAPI"));
2451         XDocumentBuilder xBuilder =
2452             UnoRuntime.queryInterface(XDocumentBuilder.class,
2453             m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
2454 
2455         String ns = "http://example.com/";
2456 
2457         XDocument xDoc = xBuilder.newDocument();
2458 
2459         XElement xRoot = xDoc.createElement("root");
2460 
2461         XElement xFoo1 = xDoc.createElement("foo");
2462         XElement xFoo2 = xDoc.createElement("foo");
2463         XElement xFooNs = xDoc.createElementNS(ns, "ns:foo");
2464         XElement xBar = xDoc.createElement("bar");
2465 
2466         xDoc.appendChild(xRoot);
2467         xRoot.appendChild(xFoo1);
2468         xFoo1.appendChild(xBar);
2469         xBar.appendChild(xFoo2);
2470         xRoot.appendChild(xFooNs);
2471 
2472         try {
2473             xXPathAPI.eval(xRoot, "~/-$+&#_");
2474             fail("XXPathAPI.eval");
2475         } catch (XPathException e) { /* expected */ }
2476         try {
2477             xXPathAPI.evalNS(xRoot, "~/-$+&#_", xRoot);
2478             fail("XXPathAPI.evalNS");
2479         } catch (XPathException e) { /* expected */ }
2480         try {
2481             xXPathAPI.selectNodeList(xRoot, "~/-$+&#_");
2482             fail("XXPathAPI.selectNodeList");
2483         } catch (XPathException e) { /* expected */ }
2484         try {
2485             xXPathAPI.selectNodeListNS(xRoot, "~/-$+&#_", xRoot);
2486             fail("XXPathAPI.selectNodeListNS");
2487         } catch (XPathException e) { /* expected */ }
2488         try {
2489             xXPathAPI.selectSingleNode(xRoot, "~/-$+&#_");
2490             fail("XXPathAPI.selectSingleNode");
2491         } catch (XPathException e) { /* expected */ }
2492         try {
2493             xXPathAPI.selectSingleNodeNS(xRoot, "~/-$+&#_", xRoot);
2494             fail("XXPathAPI.selectSingleNodeNS");
2495         } catch (XPathException e) { /* expected */ }
2496         try {
2497             xXPathAPI.eval(null, "child::foo");
2498             fail("XXPathAPI.eval(null)");
2499         } catch (Exception e) { /* expected */ }
2500         try {
2501             xXPathAPI.evalNS(null, "child::foo", xRoot);
2502             fail("XXPathAPI.evalNS(null)");
2503         } catch (Exception e) { /* expected */ }
2504         try {
2505             xXPathAPI.selectNodeList(null, "child::foo");
2506             fail("XXPathAPI.selectNodeList(null)");
2507         } catch (Exception e) { /* expected */ }
2508         try {
2509             xXPathAPI.selectNodeListNS(null, "child::foo", xRoot);
2510             fail("XXPathAPI.selectNodeListNS(null)");
2511         } catch (Exception e) { /* expected */ }
2512         try {
2513             xXPathAPI.selectSingleNode(null, "child::foo");
2514             fail("XXPathAPI.selectSingleNode(null)");
2515         } catch (Exception e) { /* expected */ }
2516         try {
2517             xXPathAPI.selectSingleNodeNS(null, "child::foo", xRoot);
2518             fail("XXPathAPI.selectSingleNodeNS(null)");
2519         } catch (Exception e) { /* expected */ }
2520 
2521         {
2522             XXPathObject xResult = xXPathAPI.eval(xRoot, "count(child::foo)");
2523             assertNotNull("XXPathAPI.eval", xResult);
2524             assertEquals("XXPathAPI.eval",
2525                     XPATH_NUMBER, xResult.getObjectType());
2526             assertEquals("XXPathAPI.eval", 1, xResult.getLong());
2527         }
2528         {
2529             XXPathObject xResult =
2530                 xXPathAPI.evalNS(xRoot, "count(//ns:foo)", xFooNs);
2531             assertNotNull("XXPathAPI.evalNS", xResult);
2532             assertEquals("XXPathAPI.evalNS",
2533                     XPATH_NUMBER, xResult.getObjectType());
2534             assertEquals("XXPathAPI.evalNS", 1, xResult.getLong());
2535         }
2536         {
2537             XNodeList xResult = xXPathAPI.selectNodeList(xRoot, "child::foo");
2538             assertNotNull("XXPathAPI.selectNodeList", xResult);
2539             assertEquals("XXPathAPI.selectNodeList", 1, xResult.getLength());
2540             assertEquals("XXPathAPI.selectNodeList", xFoo1, xResult.item(0));
2541         }
2542         {
2543             XNodeList xResult =
2544                 xXPathAPI.selectNodeListNS(xRoot, ".//ns:foo", xFooNs);
2545             assertNotNull("XXPathAPI.selectNodeListNS", xResult);
2546             assertEquals("XXPathAPI.selectNodeListNS", 1, xResult.getLength());
2547             assertEquals("XXPathAPI.selectNodeListNS", xFooNs, xResult.item(0));
2548         }
2549         {
2550             XNode xResult = xXPathAPI.selectSingleNode(xBar, "child::foo");
2551             assertNotNull("XXPathAPI.selectSingleNode", xResult);
2552             assertEquals("XXPathAPI.selectSingleNode", xFoo2, xResult);
2553         }
2554         {
2555             XNode xResult =
2556                 xXPathAPI.selectSingleNodeNS(xFoo2, "//ns:foo", xFooNs);
2557             assertNotNull("XXPathAPI.selectSingleNodeNS", xResult);
2558             assertEquals("XXPathAPI.selectSingleNodeNS", xFooNs, xResult);
2559         }
2560 
2561         try {
2562             XNode xResult = xXPathAPI.selectSingleNode(xDoc, "//pre:foo");
2563             fail("XXPathAPI.selectSingleNode");
2564         } catch (XPathException e) { /* expected */ }
2565         xXPathAPI.registerNS("pre", ns);
2566         {
2567             XNode xResult = xXPathAPI.selectSingleNode(xDoc, "//pre:foo");
2568             assertNotNull("XXPathAPI.registerNS", xResult);
2569             assertEquals("XXPathAPI.registerNS", xFooNs, xResult);
2570         }
2571 
2572         xXPathAPI.unregisterNS("pre", ns);
2573         try {
2574             XNode xResult = xXPathAPI.selectSingleNode(xDoc, "//pre:foo");
2575             fail("XXPathAPI.unregisterNS");
2576         } catch (XPathException e) { /* expected */ }
2577 
2578         /* FIXME
2579         registerExtension("");
2580         registerExtensionInstance(xExtension);
2581         */
2582     }
2583 
testXXPathObject()2584     @Test public void testXXPathObject() throws Exception
2585     {
2586         XXPathAPI xXPathAPI =
2587             UnoRuntime.queryInterface(XXPathAPI.class,
2588             m_xMSF.createInstance("com.sun.star.xml.xpath.XPathAPI"));
2589         XDocumentBuilder xBuilder =
2590             UnoRuntime.queryInterface(XDocumentBuilder.class,
2591             m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
2592 
2593         String ns = "http://example.com/";
2594 
2595         XDocument xDoc = xBuilder.newDocument();
2596 
2597         XElement xRoot = xDoc.createElement("root");
2598 
2599         XElement xFoo1 = xDoc.createElement("foo");
2600         XElement xFoo2 = xDoc.createElement("foo");
2601         XElement xFooNs = xDoc.createElementNS(ns, "ns:foo");
2602         XElement xBar = xDoc.createElement("bar");
2603 
2604         xDoc.appendChild(xRoot);
2605         xRoot.appendChild(xFoo1);
2606         xFoo1.appendChild(xBar);
2607         xBar.appendChild(xFoo2);
2608         xRoot.appendChild(xFooNs);
2609 
2610         {
2611             XXPathObject xResult = xXPathAPI.eval(xRoot, "count(//foo)");
2612             assertNotNull("XXPathAPI.eval", xResult);
2613             assertEquals("XXPathObject.getObjectType",
2614                     XPATH_NUMBER, xResult.getObjectType());
2615             assertEquals("XXPathObject.getByte", 2, xResult.getByte());
2616             assertEquals("XXPathObject.getShort", 2, xResult.getShort());
2617             assertEquals("XXPathObject.getLong", 2, xResult.getLong());
2618             assertEquals("XXPathObject.getHyper", 2, xResult.getHyper());
2619             assertEquals("XXPathObject.getFloat", 2.0, xResult.getFloat(), 0.0);
2620             assertEquals("XXPathObject.getDouble",
2621                     2.0, xResult.getDouble(), 0.0);
2622             assertEquals("XXPathObject.getString", "2", xResult.getString());
2623         }
2624         {
2625             XXPathObject xResult = xXPathAPI.eval(xRoot, "count(//foo) = 2");
2626             assertNotNull("XXPathAPI.eval", xResult);
2627             assertEquals("XXPathObject.getObjectType",
2628                     XPATH_BOOLEAN, xResult.getObjectType());
2629             assertEquals("XXPathObject.getBoolean", true, xResult.getBoolean());
2630             assertEquals("XXPathObject.getString", "true", xResult.getString());
2631         }
2632         {
2633             XXPathObject xResult = xXPathAPI.eval(xRoot, "count(//foo) = 2");
2634             assertNotNull("XXPathAPI.eval", xResult);
2635             assertEquals("XXPathObject.getObjectType",
2636                     XPATH_BOOLEAN, xResult.getObjectType());
2637             assertEquals("XXPathObject.getBoolean", true, xResult.getBoolean());
2638             assertEquals("XXPathObject.getString", "true", xResult.getString());
2639         }
2640         {
2641             XXPathObject xResult = xXPathAPI.eval(xRoot, "local-name(foo)");
2642             assertNotNull("XXPathAPI.eval", xResult);
2643             assertEquals("XXPathObject.getObjectType",
2644                     XPATH_STRING, xResult.getObjectType());
2645             assertEquals("XXPathObject.getString", "foo", xResult.getString());
2646         }
2647         {
2648             XXPathObject xResult = xXPathAPI.eval(xRoot, "//foo");
2649             assertNotNull("XXPathAPI.eval", xResult);
2650             assertEquals("XXPathObject.getObjectType",
2651                     XPATH_NODESET, xResult.getObjectType());
2652             assertNotNull("XXPathObject.getNodeList", xResult.getNodeList());
2653         }
2654     }
2655 
testXNodeList_NodeList()2656     @Test public void testXNodeList_NodeList() throws Exception
2657     {
2658         XXPathAPI xXPathAPI =
2659             UnoRuntime.queryInterface(XXPathAPI.class,
2660             m_xMSF.createInstance("com.sun.star.xml.xpath.XPathAPI"));
2661         XDocumentBuilder xBuilder =
2662             UnoRuntime.queryInterface(XDocumentBuilder.class,
2663             m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
2664 
2665         String ns = "http://example.com/";
2666 
2667         XDocument xDoc = xBuilder.newDocument();
2668 
2669         XElement xRoot = xDoc.createElement("root");
2670 
2671         XElement xFoo1 = xDoc.createElement("foo");
2672         XElement xFoo2 = xDoc.createElement("foo");
2673         XElement xFooNs = xDoc.createElementNS(ns, "ns:foo");
2674         XElement xBar = xDoc.createElement("bar");
2675 
2676         xDoc.appendChild(xRoot);
2677         xRoot.appendChild(xFoo1);
2678         xFoo1.appendChild(xBar);
2679         xBar.appendChild(xFoo2);
2680         xRoot.appendChild(xFooNs);
2681 
2682         {
2683             XXPathObject xResult = xXPathAPI.eval(xRoot, "//foo");
2684             assertNotNull("XXPathAPI.eval", xResult);
2685             assertEquals("XXPathObject.getObjectType",
2686                     XPATH_NODESET, xResult.getObjectType());
2687             XNodeList xNodeList = xResult.getNodeList();
2688             assertNotNull("XXPathObject.getNodeList", xNodeList);
2689             assertEquals("NodeList.getLength", 2, xNodeList.getLength());
2690             assertEquals("NodeList.item", xFoo1, xNodeList.item(0));
2691             assertEquals("NodeList.item", xFoo2, xNodeList.item(1));
2692         }
2693     }
2694 
2695 
2696     // just for importNode...
2697     abstract class MockNode implements XNode
2698     {
2699         MockDoc  m_document;
2700         MockNode m_parent;
2701         MockNode m_prev;
2702         MockNode m_next;
2703         MockNode[] m_children;
2704         String m_localname;
2705 
2706 //        MockNode() { ; }
init(MockDoc doc, MockNode parent, MockNode prev, MockNode next, MockNode[] children)2707         void init(MockDoc doc, MockNode parent, MockNode prev, MockNode next,
2708                 MockNode[] children)
2709         {
2710             m_document = doc;
2711             m_parent = parent; m_prev = prev; m_next = next;
2712             m_children = children;
2713         }
2714 
appendChild(XNode c)2715         public XNode appendChild(XNode c) throws DOMException {
2716             fail("MockNode.appendChild called?");
2717             return null;
2718         }
cloneNode(boolean b)2719         public XNode cloneNode(boolean b) {
2720             fail("MockNode.cloneNode called?");
2721             return null;
2722         }
getAttributes()2723         public XNamedNodeMap getAttributes() {
2724             fail("MockNode.getAttributes not implemented");
2725             return null;
2726         }
getChildNodes()2727         public XNodeList getChildNodes() {
2728             fail("MockNode.getChildList not implemented");
2729             return null;
2730         }
getFirstChild()2731         public XNode getFirstChild() {
2732             return (m_children.length != 0) ? m_children[0] : null;
2733         }
getLastChild()2734         public XNode getLastChild() {
2735             return (m_children.length != 0)
2736                 ? m_children[m_children.length-1] : null;
2737         }
getLocalName()2738         public String getLocalName() { return m_localname; }
getNamespaceURI()2739         public String getNamespaceURI() { return ""; }
getNextSibling()2740         public XNode getNextSibling() { return m_next; }
getNodeName()2741         public String getNodeName() { return m_localname; }
2742 //        NodeType getNodeType() { return m_type; }
getNodeValue()2743         public String getNodeValue() throws DOMException { return ""; }
getOwnerDocument()2744         public XDocument getOwnerDocument() { return m_document; }
getParentNode()2745         public XNode getParentNode() { return m_parent; }
getPrefix()2746         public String getPrefix() { return ""; }
getPreviousSibling()2747         public XNode getPreviousSibling() { return m_prev; }
hasAttributes()2748         public boolean hasAttributes() { return false; }
hasChildNodes()2749         public boolean hasChildNodes() { return m_children.length != 0; }
insertBefore(XNode c, XNode r)2750         public XNode insertBefore(XNode c, XNode r)  throws DOMException {
2751             fail("MockNode.insertBefore called?");
2752             return null;
2753         }
isSupported(String a, String b)2754         public boolean isSupported(String a, String b) { return false; }
normalize()2755         public void normalize() {
2756             fail("MockNode.normalize called?");
2757         }
removeChild(XNode c)2758         public XNode removeChild(XNode c) throws DOMException {
2759             fail("MockNode.removeChild called?");
2760             return null;
2761         }
replaceChild(XNode c, XNode o)2762         public XNode replaceChild(XNode c, XNode o) throws DOMException {
2763             fail("MockNode.replaceChild called?");
2764             return null;
2765         }
setNodeValue(String v)2766         public void setNodeValue(String v) throws DOMException {
2767             fail("MockNode.setNodeValue called?");
2768         }
setPrefix(String p)2769         public void setPrefix(String p) throws DOMException {
2770             fail("MockNode.setPrefix called?");
2771         }
2772     }
2773     class MockDoc extends MockNode implements XDocument
2774     {
2775 //        MockDoc() { }
init(MockNode[] children)2776         void init(MockNode[] children) {
2777             super.init(this, null, null, null, children);
2778         }
2779 
getNodeType()2780         public NodeType getNodeType() { return DOCUMENT_NODE; }
2781 
createAttribute(String n)2782         public XAttr createAttribute(String n) throws DOMException {
2783             fail("MockNode.createAttribute called?");
2784             return null;
2785         }
createAttributeNS(String n, String q)2786         public XAttr createAttributeNS(String n, String q) throws DOMException {
2787             fail("MockNode.createAttributeNS called?");
2788             return null;
2789         }
createCDATASection(String s)2790         public XCDATASection createCDATASection(String s) throws DOMException {
2791             fail("MockNode.createCDATASection called?");
2792             return null;
2793         }
createComment(String s)2794         public XComment createComment(String s) {
2795             fail("MockNode.createCDATASection called?");
2796             return null;
2797         }
createDocumentFragment()2798         public XDocumentFragment createDocumentFragment() {
2799             fail("MockNode.createDocumentFragment called?");
2800             return null;
2801         }
createElement(String n)2802         public XElement createElement(String n) {
2803             fail("MockNode.createElement called?");
2804             return null;
2805         }
createElementNS(String n, String q)2806         public XElement createElementNS(String n, String q) {
2807             fail("MockNode.createElementNS called?");
2808             return null;
2809         }
createEntityReference(String n)2810         public XEntityReference createEntityReference(String n)
2811                 throws DOMException {
2812             fail("MockNode.createEntityReference called?");
2813             return null;
2814         }
createProcessingInstruction(String t, String d)2815         public XProcessingInstruction createProcessingInstruction(String t,
2816                 String d) throws DOMException {
2817             fail("MockNode.createEntityReference called?");
2818             return null;
2819         }
createTextNode(String d)2820         public XText createTextNode(String d) {
2821             fail("MockNode.createTextNode called?");
2822             return null;
2823         }
getDoctype()2824         public XDocumentType getDoctype() {
2825             fail("MockNode.getDoctype called?");
2826             return null;
2827         }
getDocumentElement()2828         public XElement getDocumentElement() {
2829             fail("MockNode.getDocumentElement called?");
2830             return null;
2831         }
getElementById(String id)2832         public XElement getElementById(String id) {
2833             fail("MockNode.getElementById called?");
2834             return null;
2835         }
getElementsByTagName(String n)2836         public XNodeList getElementsByTagName(String n) {
2837             fail("MockNode.getElementsByTagName called?");
2838             return null;
2839         }
getElementsByTagNameNS(String n, String q)2840         public XNodeList getElementsByTagNameNS(String n, String q) {
2841             fail("MockNode.getElementsByTagNameNS called?");
2842             return null;
2843         }
getImplementation()2844         public XDOMImplementation getImplementation() {
2845             fail("MockNode.getImplementation called?");
2846             return null;
2847         }
importNode(XNode i, boolean b)2848         public XNode importNode(XNode i, boolean b) throws DOMException {
2849             fail("MockNode.importNode called?");
2850             return null;
2851         }
2852     }
2853     class MockNodeMap implements XNamedNodeMap
2854     {
2855         MockAttr[] m_attributes;
2856 
MockNodeMap(MockAttr[] attrs)2857         MockNodeMap(MockAttr[] attrs) { m_attributes = attrs; }
2858 
getLength()2859         public int getLength() { return m_attributes.length; }
getNamedItem(String name)2860         public XNode getNamedItem(String name) {
2861             fail("MockNodeMap.getNamedItem not implemented");
2862             return null;
2863         }
getNamedItemNS(String n, String l)2864         public XNode getNamedItemNS(String n, String l) {
2865             fail("MockNodeMap.getNamedItemNS not implemented");
2866             return null;
2867         }
item(int index)2868         public XNode item(int index) {
2869             return m_attributes[index];
2870         }
removeNamedItem(String n)2871         public XNode removeNamedItem(String n) throws DOMException {
2872             fail("MockNodeMap.removeNamedItem called?");
2873             return null;
2874         }
removeNamedItemNS(String n, String l)2875         public XNode removeNamedItemNS(String n, String l) throws DOMException {
2876             fail("MockNodeMap.removeNamedItemNS called?");
2877             return null;
2878         }
setNamedItem(XNode n)2879         public XNode setNamedItem(XNode n) throws DOMException {
2880             fail("MockNodeMap.setNamedItem called?");
2881             return null;
2882         }
setNamedItemNS(XNode n)2883         public XNode setNamedItemNS(XNode n) throws DOMException {
2884             fail("MockNodeMap.setNamedItemNS called?");
2885             return null;
2886         }
2887     }
2888     class MockElement extends MockNode implements XElement
2889     {
2890         MockAttr[] m_attributes;
2891 
MockElement(String name, MockAttr[] attrs)2892         MockElement(String name, MockAttr[] attrs) {
2893             m_localname = name; m_attributes = attrs;
2894         }
2895 
getNodeType()2896         public NodeType getNodeType() { return ELEMENT_NODE; }
getAttributes()2897         public XNamedNodeMap getAttributes() {
2898             return new MockNodeMap(m_attributes);
2899         }
hasAttributes()2900         public boolean hasAttributes() { return m_attributes.length != 0; }
2901 
getAttribute(String n)2902         public String getAttribute(String n) {
2903             fail("MockNode.getAttribute not implemented");
2904             return null;
2905         }
getAttributeNode(String n)2906         public XAttr getAttributeNode(String n) {
2907             fail("MockNode.getAttributeNode not implemented");
2908             return null;
2909         }
getAttributeNodeNS(String n, String l)2910         public XAttr getAttributeNodeNS(String n, String l) {
2911             fail("MockNode.getAttributeNodeNS not implemented");
2912             return null;
2913         }
getAttributeNS(String n, String q)2914         public String getAttributeNS(String n, String q) {
2915             fail("MockNode.getAttributeNS not implemented");
2916             return null;
2917         }
getElementsByTagName(String n)2918         public XNodeList getElementsByTagName(String n) {
2919             fail("MockNode.getElementsByTagName called?");
2920             return null;
2921         }
getElementsByTagNameNS(String n, String l)2922         public XNodeList getElementsByTagNameNS(String n, String l) {
2923             fail("MockNode.getElementsByTagNameNS called?");
2924             return null;
2925         }
getTagName()2926         public String getTagName() {
2927             return getLocalName();
2928         }
hasAttribute(String n)2929         public boolean hasAttribute(String n) {
2930             fail("MockNode.hasAttribute not implemented");
2931             return false;
2932         }
hasAttributeNS(String n, String l)2933         public boolean hasAttributeNS(String n, String l) {
2934             fail("MockNode.hasAttributeNS not implemented");
2935             return false;
2936         }
removeAttribute(String n)2937         public void removeAttribute(String n) throws DOMException {
2938             fail("MockNode.removeAttribute called?");
2939         }
removeAttributeNode(XAttr o)2940         public XAttr removeAttributeNode(XAttr o) throws DOMException {
2941             fail("MockNode.removeAttributeNode called?");
2942             return null;
2943         }
removeAttributeNS(String n, String l)2944         public void removeAttributeNS(String n, String l) throws DOMException {
2945             fail("MockNode.removeAttributeNS called?");
2946         }
setAttribute(String n, String v)2947         public void setAttribute(String n, String v) throws DOMException {
2948             fail("MockNode.setAttribute called?");
2949         }
setAttributeNode(XAttr n)2950         public XAttr setAttributeNode(XAttr n) throws DOMException {
2951             fail("MockNode.setAttributeNode called?");
2952             return null;
2953         }
setAttributeNodeNS(XAttr n)2954         public XAttr setAttributeNodeNS(XAttr n) throws DOMException {
2955             fail("MockNode.setAttributeNodeNS called?");
2956             return null;
2957         }
setAttributeNS(String n, String q, String v)2958         public void setAttributeNS(String n, String q, String v)
2959                 throws DOMException {
2960             fail("MockNode.setAttributeNS called?");
2961         }
2962     }
2963     class MockAttr extends MockNode implements XAttr
2964     {
2965         String m_value;
2966 
MockAttr(String name, String value)2967         MockAttr(String name, String value) {
2968             m_localname = name; m_value = value;
2969         }
2970 
getNodeType()2971         public NodeType getNodeType() { return ATTRIBUTE_NODE; }
2972 
getName()2973         public String getName() { return m_localname; }
getOwnerElement()2974         public XElement getOwnerElement() { return (XElement) m_parent; }
getSpecified()2975         public boolean getSpecified() { return true; }
getValue()2976         public String getValue() { return m_value; }
setValue(String v)2977         public void setValue(String v) {
2978             fail("MockNode.setValue called?");
2979         }
2980     }
2981 }
2982 
2983