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