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 <xiscofauli@libreoffice.org>
This commit is contained in:
parent
b42b218bd7
commit
52f19726b4
5 changed files with 48 additions and 127 deletions
|
@ -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,\
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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() {}
|
||||
}
|
|
@ -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>
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue