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