unoxml/JunitTest_unoxml_complex.mk                 |    1 
 unoxml/qa/complex/unoxml/DOMTest.java              |   51 ---------------------
 unoxml/qa/complex/unoxml/TestDocument.java         |   31 ------------
 unoxml/qa/complex/unoxml/testdocuments/example.rdf |   44 ------------------
 unoxml/qa/unit/domtest.cxx                         |   48 +++++++++++++++++++
 5 files changed, 48 insertions(+), 127 deletions(-)

New commits:
commit 52f19726b4ac5e06a47c188e2ec90d85426716a8
Author:     Xisco Fauli <[email protected]>
AuthorDate: Tue Sep 17 17:13:10 2024 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Wed Sep 18 08:51:15 2024 +0200

    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 <[email protected]>

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 @@
-<?xml version="1.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 .
--->
-<rdf:RDF
- xmlns:pkg="http://docs.oasis-open.org/opendocument/meta/package/common#";
- xmlns:odf="http://docs.oasis-open.org/opendocument/meta/package/odf#";
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";>
-<pkg:Package rdf:about="urn:uuid:224ab023-77b8-4396-a75a-8cecd85b81e3">
-    <pkg:hasPart>
-        <odf:ContentFile pkg:path="content.xml">
-            <pkg:hasPart>
-                               <odf:Element rdf:about="uri:example-element-1"
-                                       pkg:idref="ID_A"/>
-            </pkg:hasPart>
-            <pkg:hasPart>
-                               <odf:Element rdf:about="uri:example-element-2"
-                                       pkg:idref="ID_B"/>
-            </pkg:hasPart>
-               </odf:ContentFile>
-    </pkg:hasPart>
-    <pkg:hasPart>
-        <odf:MetadataFile rdf:about="http://hospital-employee/doctor";
-                       pkg:path="meta/hospital/doctor.rdf">
-            <rdf:type rdf:resource="http://medical-employee/data"/>
-            <rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#"/>
-        </odf:MetadataFile>
-    </pkg:hasPart>
-</pkg:Package>
-</rdf:RDF>
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 <sax/fastattribs.hxx>
 #include <comphelper/seqstream.hxx>
 #include <cppuhelper/implbase.hxx>
+#include <comphelper/processfactory.hxx>
 #include <cppunit/extensions/HelperMacros.h>
 #include <cppunit/plugin/TestPlugIn.h>
 #include <test/bootstrapfixture.hxx>
 
+#include <com/sun/star/ucb/ContentCreationException.hpp>
+#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
 #include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
 #include <com/sun/star/xml/sax/FastToken.hpp>
 #include <com/sun/star/xml/sax/XSAXSerializable.hpp>
@@ -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<uno::XComponentContext> 
xContext(comphelper::getProcessComponentContext(), css::uno::UNO_SET_THROW);
+        const uno::Reference<com::sun::star::ucb::XSimpleFileAccess> 
xFileAccess(
+        xContext->getServiceManager()->createInstanceWithContext(
+            u"com.sun.star.ucb.SimpleFileAccess"_ustr, xContext),
+        uno::UNO_QUERY_THROW);
+        uno::Reference<io::XInputStream> 
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();
 };
 

Reply via email to