summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammed Abdul Azeem <azeemmysore@gmail.com>2016-05-11 16:57:44 +0530
committerNoel Grandin <noelgrandin@gmail.com>2016-05-19 09:36:32 +0000
commite94deb06391f516ee9c1fa019b3521e222a5615b (patch)
tree9a11e20344c585db8db66e6b166081340c629dc8
parentc70a5937e3a2057886c01bc78ac5a6b42e8c702d (diff)
First cut at adding sax2/ unit tests.
This is a first-step towards implementing the legacy parser using the XFastParser. Change-Id: I37fc0419dbef1d6f067e45e0b1f2fd6051fb158d Reviewed-on: https://gerrit.libreoffice.org/24883 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
-rw-r--r--sax/CppunitTest_sax_xmlimport.mk48
-rw-r--r--sax/Module_sax.mk1
-rw-r--r--sax/qa/cppunit/xmlimport.cxx181
-rw-r--r--sax/qa/data/namespace.xml6
-rw-r--r--sax/qa/data/note.xml7
5 files changed, 243 insertions, 0 deletions
diff --git a/sax/CppunitTest_sax_xmlimport.mk b/sax/CppunitTest_sax_xmlimport.mk
new file mode 100644
index 000000000000..71e2792c9c65
--- /dev/null
+++ b/sax/CppunitTest_sax_xmlimport.mk
@@ -0,0 +1,48 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,sax_xmlimport))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sax_xmlimport, \
+sax/qa/cppunit/xmlimport \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sax_xmlimport, \
+ test \
+ cppu \
+ comphelper \
+ sal \
+ cppuhelper \
+ sax \
+ unotest \
+ utl \
+ $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sax_xmlimport,\
+ offapi \
+ udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_external,sax_xmlimport,boost_headers))
+
+$(eval $(call gb_CppunitTest_use_ure,sax_xmlimport))
+$(eval $(call gb_CppunitTest_use_vcl,sax_xmlimport))
+
+$(eval $(call gb_CppunitTest_use_components,sax_xmlimport,\
+ configmgr/source/configmgr \
+ sax/source/expatwrap/expwrap \
+ ucb/source/core/ucb1 \
+ ucb/source/ucp/file/ucpfile1 \
+))
+
+
+$(eval $(call gb_CppunitTest_use_configuration,sax_xmlimport))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sax/Module_sax.mk b/sax/Module_sax.mk
index ae8ab9c6db5e..4fca4efdc289 100644
--- a/sax/Module_sax.mk
+++ b/sax/Module_sax.mk
@@ -18,6 +18,7 @@ $(eval $(call gb_Module_add_check_targets,sax,\
CppunitTest_sax \
CppunitTest_sax_attributes \
CppunitTest_sax_parser \
+ CppunitTest_sax_xmlimport \
))
# vim: set noet sw=4 ts=4:
diff --git a/sax/qa/cppunit/xmlimport.cxx b/sax/qa/cppunit/xmlimport.cxx
new file mode 100644
index 000000000000..881b0cc121ba
--- /dev/null
+++ b/sax/qa/cppunit/xmlimport.cxx
@@ -0,0 +1,181 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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 .
+ */
+
+#include <sal/config.h>
+#include <sal/types.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+#include <test/bootstrapfixture.hxx>
+#include <cppuhelper/weak.hxx>
+#include <cppuhelper/implbase.hxx>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/xml/sax/Parser.hpp>
+#include <com/sun/star/xml/sax/XParser.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <osl/file.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <unotools/streamwrap.hxx>
+
+namespace {
+
+using namespace css;
+using namespace css::uno;
+using namespace css::io;
+
+Reference< XInputStream > createStreamFromFile (
+ const OUString filePath)
+{
+ Reference< XInputStream > xInputStream;
+ OUString aInStr;
+ osl::FileBase::getFileURLFromSystemPath(filePath, aInStr);
+ SvStream* pStream = utl::UcbStreamHelper::CreateStream(aInStr, StreamMode::READ);
+ if(pStream == NULL)
+ CPPUNIT_ASSERT(false);
+ uno::Reference<io::XStream> xStream(new utl::OStreamWrapper(*pStream));
+ xInputStream.set(xStream, uno::UNO_QUERY);
+ return xInputStream;
+}
+
+class TestDocumentHandler : public cppu::WeakImplHelper< xml::sax::XDocumentHandler >
+{
+private:
+ OUString m_aStr;
+
+public:
+ TestDocumentHandler() {}
+ OUString getString() { return m_aStr; }
+ // XDocumentHandler
+ virtual void SAL_CALL startDocument() throw (xml::sax::SAXException, RuntimeException, std::exception) override;
+ virtual void SAL_CALL endDocument() throw (xml::sax::SAXException, RuntimeException, std::exception) override;
+ virtual void SAL_CALL startElement( const OUString& aName, const Reference< xml::sax::XAttributeList >& xAttribs ) throw (xml::sax::SAXException, RuntimeException, std::exception) override;
+ virtual void SAL_CALL endElement( const OUString& aName ) throw (xml::sax::SAXException, RuntimeException, std::exception) override;
+ virtual void SAL_CALL characters( const OUString& aChars ) throw (xml::sax::SAXException, RuntimeException, std::exception) override;
+ virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces ) throw (xml::sax::SAXException, RuntimeException, std::exception) override;
+ virtual void SAL_CALL processingInstruction( const OUString& aTarget, const OUString& aData ) throw (xml::sax::SAXException, RuntimeException, std::exception) override;
+ virtual void SAL_CALL setDocumentLocator( const Reference< xml::sax::XLocator >& xLocator ) throw (xml::sax::SAXException, RuntimeException, std::exception) override;
+};
+
+void SAL_CALL TestDocumentHandler::startDocument()
+ throw(xml::sax::SAXException, RuntimeException, std::exception)
+{
+ // m_aStr.clear();
+}
+
+
+void SAL_CALL TestDocumentHandler::endDocument()
+ throw(xml::sax::SAXException, RuntimeException, std::exception)
+{
+}
+
+void SAL_CALL TestDocumentHandler::startElement( const OUString& /*aName*/, const Reference< xml::sax::XAttributeList >& /*xAttribs*/ )
+ throw( xml::sax::SAXException, RuntimeException, std::exception )
+{
+ // m_aStr = m_aStr + "<" + aName + "> ";
+}
+
+
+void SAL_CALL TestDocumentHandler::endElement( const OUString& /*aName*/ )
+ throw( xml::sax::SAXException, RuntimeException, std::exception )
+{
+ // m_aStr = m_aStr + "</" + aName + ">\n";
+}
+
+
+void SAL_CALL TestDocumentHandler::characters( const OUString& /*aChars*/ )
+ throw(xml::sax::SAXException, RuntimeException, std::exception)
+{
+ // m_aStr = m_aStr + aChars + " ";
+}
+
+
+void SAL_CALL TestDocumentHandler::ignorableWhitespace( const OUString& /*aWhitespaces*/ )
+ throw(xml::sax::SAXException, RuntimeException, std::exception)
+{
+}
+
+
+void SAL_CALL TestDocumentHandler::processingInstruction( const OUString& /*aTarget*/, const OUString& /*aData*/ )
+ throw(xml::sax::SAXException, RuntimeException, std::exception)
+{
+}
+
+
+void SAL_CALL TestDocumentHandler::setDocumentLocator( const Reference< xml::sax::XLocator >& /*xLocator*/ )
+ throw(xml::sax::SAXException, RuntimeException, std::exception)
+{
+}
+
+
+class XMLImportTest : public test::BootstrapFixture
+{
+private:
+ OUString m_sDirPath;
+ Reference< TestDocumentHandler > m_xDocumentHandler;
+ Reference< xml::sax::XParser > m_xParser;
+ Reference< lang::XMultiServiceFactory > m_xSMgr;
+
+public:
+ virtual void setUp() override;
+ virtual void tearDown() override;
+
+ XMLImportTest() : BootstrapFixture(true, false) {}
+ void parse();
+
+ CPPUNIT_TEST_SUITE( XMLImportTest );
+ CPPUNIT_TEST( parse );
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void XMLImportTest::setUp()
+{
+ test::BootstrapFixture::setUp();
+ m_xDocumentHandler.set( new TestDocumentHandler() );
+ m_xSMgr = getMultiServiceFactory();
+ m_xParser = xml::sax::Parser::create(
+ ::comphelper::getProcessComponentContext() );
+ m_xParser->setDocumentHandler( m_xDocumentHandler );
+ m_sDirPath = m_directories.getPathFromSrc( "/sax/qa/data/" );
+}
+
+void XMLImportTest::tearDown()
+{
+ test::BootstrapFixture::tearDown();
+}
+
+void XMLImportTest::parse()
+{
+ OUString fileName = "note.xml";
+ Reference< XInputStream > rIS = createStreamFromFile( m_sDirPath + fileName );
+ xml::sax::InputSource source;
+ source.aInputStream = rIS;
+ source.sSystemId = "internal";
+ m_xParser->parseStream(source);
+ // OUString aStr = m_xDocumentHandler->getString();
+ // OString o = OUStringToOString( aStr, RTL_TEXTENCODING_ASCII_US );
+ // CPPUNIT_ASSERT_MESSAGE( string(o.pData->buffer), false );
+ CPPUNIT_ASSERT(true);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION( XMLImportTest );
+} //namespace
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sax/qa/data/namespace.xml b/sax/qa/data/namespace.xml
new file mode 100644
index 000000000000..6abb6468e7f8
--- /dev/null
+++ b/sax/qa/data/namespace.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<html:html xmlns:html="http://www.w3.org/TR/REC-html40">
+ <html:head><html:title>Frobnostication</html:title></html:head>
+ <html:body><html:p>Moved to
+ <html:a href="http://frob.com">here.</html:a></html:p></html:body>
+</html:html> \ No newline at end of file
diff --git a/sax/qa/data/note.xml b/sax/qa/data/note.xml
new file mode 100644
index 000000000000..830b1c2d95ab
--- /dev/null
+++ b/sax/qa/data/note.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<note>
+ <to>ABC</to>
+ <from>XYZ</from>
+ <heading>Reminder</heading>
+ <body>Don't forget me this weekend!</body>
+</note> \ No newline at end of file