From 52f19726b4ac5e06a47c188e2ec90d85426716a8 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Tue, 17 Sep 2024 17:13:10 +0200 Subject: [PATCH] unoxml: move testXDocumentBuilder from Java to CppUnittest Change-Id: I15996b72745dd9d3f00e917cc6b459094ec51f30 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173569 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- unoxml/JunitTest_unoxml_complex.mk | 1 - unoxml/qa/complex/unoxml/DOMTest.java | 51 ------------------- unoxml/qa/complex/unoxml/TestDocument.java | 31 ----------- .../complex/unoxml/testdocuments/example.rdf | 44 ---------------- unoxml/qa/unit/domtest.cxx | 48 +++++++++++++++++ 5 files changed, 48 insertions(+), 127 deletions(-) delete mode 100644 unoxml/qa/complex/unoxml/TestDocument.java delete mode 100644 unoxml/qa/complex/unoxml/testdocuments/example.rdf diff --git a/unoxml/JunitTest_unoxml_complex.mk b/unoxml/JunitTest_unoxml_complex.mk index 4b98f2fd2d51..9186ea7f9fc2 100644 --- a/unoxml/JunitTest_unoxml_complex.mk +++ b/unoxml/JunitTest_unoxml_complex.mk @@ -28,7 +28,6 @@ $(eval $(call gb_JunitTest_use_unoapi_jars,unoxml_complex)) $(eval $(call gb_JunitTest_add_sourcefiles,unoxml_complex,\ unoxml/qa/complex/unoxml/DOMTest \ - unoxml/qa/complex/unoxml/TestDocument \ )) $(eval $(call gb_JunitTest_add_classes,unoxml_complex,\ diff --git a/unoxml/qa/complex/unoxml/DOMTest.java b/unoxml/qa/complex/unoxml/DOMTest.java index f630b9335faf..ce4fb4b17d48 100644 --- a/unoxml/qa/complex/unoxml/DOMTest.java +++ b/unoxml/qa/complex/unoxml/DOMTest.java @@ -93,57 +93,6 @@ public class DOMTest //FIXME TODO } - @Test - public void testXDocumentBuilder() throws Exception - { - XDocumentBuilder xBuilder = - UnoRuntime.queryInterface(XDocumentBuilder.class, - m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder")); - - XDOMImplementation xDomImpl = xBuilder.getDOMImplementation(); -//FIXME fails assertNotNull("getDOMImplementation", xDomImpl); - - xBuilder.isNamespaceAware(); - xBuilder.isValidating(); - - { - XDocument xDoc = xBuilder.newDocument(); - assertNotNull("newDocument", xDoc); - } - - try { - xBuilder.parse(null); - fail("XDocumentBuilder.parse(null)"); - } catch (Exception e) { /* expected */ } - { - XInputStream xIn = new StreamSimulator( - TestDocument.getUrl("example.rdf"), true, m_params); - XDocument xDoc = xBuilder.parse(xIn); - assertNotNull("XDocumentBuilder.parse", xDoc); - } - try { - xBuilder.parseURI(""); - fail("XDocumentBuilder.parseURI(\"\")"); - } catch (Exception e) { /* expected */ } - { - XDocument xDoc = - xBuilder.parseURI(TestDocument.getUrl("example.rdf")); - assertNotNull("XDocumentBuilder.parseURI", xDoc); - } - - xBuilder.setEntityResolver(null); - /* FIXME TODO - XEntityResolver xER; - xBuilder.setEntityResolver(xER); - */ - - xBuilder.setErrorHandler(null); - /* FIXME TODO - XErrorHandler xEH; - xBuilder.setErrorHandler(xEH); - */ - } - @Test public void testXDocument() throws Exception { XDocumentBuilder xBuilder = diff --git a/unoxml/qa/complex/unoxml/TestDocument.java b/unoxml/qa/complex/unoxml/TestDocument.java deleted file mode 100644 index 740660964292..000000000000 --- a/unoxml/qa/complex/unoxml/TestDocument.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -package complex.unoxml; - -import java.io.File; -import org.openoffice.test.OfficeFileUrl; -import org.openoffice.test.Argument; - -final class TestDocument { - public static String getUrl(String name) { - return OfficeFileUrl.getAbsolute(new File(Argument.get("tdoc"), name)); - } - - private TestDocument() {} -} diff --git a/unoxml/qa/complex/unoxml/testdocuments/example.rdf b/unoxml/qa/complex/unoxml/testdocuments/example.rdf deleted file mode 100644 index d20a75ba2b10..000000000000 --- a/unoxml/qa/complex/unoxml/testdocuments/example.rdf +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/unoxml/qa/unit/domtest.cxx b/unoxml/qa/unit/domtest.cxx index 5cc4235c8bbd..2c40b5a4acdb 100644 --- a/unoxml/qa/unit/domtest.cxx +++ b/unoxml/qa/unit/domtest.cxx @@ -22,10 +22,13 @@ #include #include #include +#include #include #include #include +#include +#include #include #include #include @@ -262,6 +265,50 @@ struct BasicTest : public test::BootstrapFixture mxErrHandler->mnErrCount /*&& !mxErrHandler->mnFatalCount*/); } + void testXDocumentBuilder() + { + mxDomBuilder->isNamespaceAware(); + mxDomBuilder->isValidating(); + + Reference< xml::dom::XDocument > xDocument = mxDomBuilder->newDocument(); + CPPUNIT_ASSERT(xDocument); + + try + { + mxDomBuilder->parse(nullptr); + CPPUNIT_FAIL("XDocumentBuilder.parse(null)"); + } + catch (css::uno::RuntimeException&) + { + } + + uno::Reference xContext(comphelper::getProcessComponentContext(), css::uno::UNO_SET_THROW); + const uno::Reference xFileAccess( + xContext->getServiceManager()->createInstanceWithContext( + u"com.sun.star.ucb.SimpleFileAccess"_ustr, xContext), + uno::UNO_QUERY_THROW); + uno::Reference xInputStream(xFileAccess->openFileRead(m_directories.getURLFromSrc(u"/unoxml/qa/unit/data/example.rdf")), + uno::UNO_SET_THROW); + + xDocument = mxDomBuilder->parse(xInputStream); + CPPUNIT_ASSERT(xDocument); + + try + { + mxDomBuilder->parseURI(u""_ustr); + CPPUNIT_FAIL("XDocumentBuilder.parseURI(\"\")"); + } + catch (com::sun::star::ucb::ContentCreationException&) + { + } + + xDocument = mxDomBuilder->parseURI(m_directories.getURLFromSrc(u"/unoxml/qa/unit/data/example.rdf")); + CPPUNIT_ASSERT(xDocument); + + mxDomBuilder->setEntityResolver(nullptr); + mxDomBuilder->setErrorHandler(nullptr); + } + // Change the following lines only, if you add, remove or rename // member functions of the current class, // because these macros are need by auto register mechanism. @@ -269,6 +316,7 @@ struct BasicTest : public test::BootstrapFixture CPPUNIT_TEST(validInputTest); CPPUNIT_TEST(warningInputTest); CPPUNIT_TEST(errorInputTest); + CPPUNIT_TEST(testXDocumentBuilder); CPPUNIT_TEST_SUITE_END(); };