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