summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sax/CppunitTest_sax_parser.mk41
-rw-r--r--sax/Module_sax.mk9
-rw-r--r--sax/qa/cppunit/parser.cxx98
-rw-r--r--sax/source/fastparser/fastparser.cxx4
4 files changed, 146 insertions, 6 deletions
diff --git a/sax/CppunitTest_sax_parser.mk b/sax/CppunitTest_sax_parser.mk
new file mode 100644
index 000000000000..fd31c1079ca6
--- /dev/null
+++ b/sax/CppunitTest_sax_parser.mk
@@ -0,0 +1,41 @@
+# -*- 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_parser))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sax_parser, \
+ sax/qa/cppunit/parser \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sax_parser, \
+ comphelper \
+ cppu \
+ sal \
+ test \
+ $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,sax_parser))
+
+$(eval $(call gb_CppunitTest_use_ure,sax_parser))
+
+$(eval $(call gb_CppunitTest_use_components,sax_parser,\
+ configmgr/source/configmgr \
+ framework/util/fwk \
+ i18npool/util/i18npool \
+ oox/util/oox \
+ sax/source/fastparser/fastsax \
+ sfx2/util/sfx \
+ ucb/source/core/ucb1 \
+ ucb/source/ucp/file/ucpfile1 \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sax_parser))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sax/Module_sax.mk b/sax/Module_sax.mk
index 17c98c0d7cf4..4352282ff3ea 100644
--- a/sax/Module_sax.mk
+++ b/sax/Module_sax.mk
@@ -10,14 +10,15 @@
$(eval $(call gb_Module_Module,sax))
$(eval $(call gb_Module_add_targets,sax,\
- Library_expwrap \
- Library_fastsax \
- Library_sax \
+ Library_expwrap \
+ Library_fastsax \
+ Library_sax \
StaticLibrary_sax_shared \
))
$(eval $(call gb_Module_add_check_targets,sax,\
- CppunitTest_sax \
+ CppunitTest_sax \
+ CppunitTest_sax_parser \
))
# vim: set noet sw=4 ts=4:
diff --git a/sax/qa/cppunit/parser.cxx b/sax/qa/cppunit/parser.cxx
new file mode 100644
index 000000000000..ac4ac5311658
--- /dev/null
+++ b/sax/qa/cppunit/parser.cxx
@@ -0,0 +1,98 @@
+/* -*- 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/.
+ */
+
+#include <sal/config.h>
+
+#include <com/sun/star/io/Pipe.hpp>
+#include <com/sun/star/xml/sax/SAXParseException.hpp>
+#include <com/sun/star/xml/sax/XFastParser.hpp>
+#include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
+
+#include <test/bootstrapfixture.hxx>
+#include <comphelper/componentcontext.hxx>
+
+using namespace css;
+using namespace css::xml::sax;
+
+namespace {
+
+class ParserTest: public test::BootstrapFixture
+{
+ InputSource maInput;
+ uno::Reference< XFastParser > mxParser;
+ uno::Reference< XFastTokenHandler > mxTokenHandler;
+ uno::Reference< XFastDocumentHandler > mxDocumentHandler;
+
+public:
+ virtual void setUp();
+ virtual void tearDown();
+
+ void parse();
+
+ CPPUNIT_TEST_SUITE(ParserTest);
+ CPPUNIT_TEST(parse);
+ CPPUNIT_TEST_SUITE_END();
+
+private:
+ uno::Reference< io::XInputStream > createStream(OString sInput);
+};
+
+void ParserTest::setUp()
+{
+ test::BootstrapFixture::setUp();
+ mxParser.set( comphelper::ComponentContext(m_xContext).createComponent(
+ "com.sun.star.xml.sax.FastParser"), uno::UNO_QUERY );
+ CPPUNIT_ASSERT_MESSAGE("No FastParser!", mxParser.is());
+ mxTokenHandler.set( comphelper::ComponentContext(m_xContext).createComponent(
+ "com.sun.star.xml.sax.FastTokenHandler"), uno::UNO_QUERY );
+ CPPUNIT_ASSERT_MESSAGE("No TokenHandler!", mxTokenHandler.is());
+ mxParser->setTokenHandler( mxTokenHandler );
+}
+
+void ParserTest::tearDown()
+{
+ test::BootstrapFixture::tearDown();
+}
+
+uno::Reference< io::XInputStream > ParserTest::createStream(OString sInput)
+{
+ uno::Reference< io::XOutputStream > xPipe( io::Pipe::create(m_xContext) );
+ uno::Reference< io::XInputStream > xInStream( xPipe, uno::UNO_QUERY );
+ uno::Sequence< sal_Int8 > aSeq( (sal_Int8*)sInput.getStr(), sInput.getLength() );
+ xPipe->writeBytes( aSeq );
+ xPipe->flush();
+ xPipe->closeOutput();
+ return xInStream;
+}
+
+void ParserTest::parse()
+{
+ maInput.aInputStream = createStream("<a>...<b />..</a>");
+ mxParser->parseStream( maInput );
+
+ maInput.aInputStream = createStream("<b></a>");
+ bool bException = false;
+ try
+ {
+ mxParser->parseStream( maInput );
+ }
+ catch (const SAXParseException &)
+ {
+ bException = true;
+ }
+ CPPUNIT_ASSERT_MESSAGE("No Exception!", bException);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ParserTest);
+
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 6b793db1793e..cc1134b63cdf 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -835,7 +835,7 @@ void FastSaxParser::callbackStartElement( const XML_Char* pwName, const XML_Char
if( xParentContext.is() )
xContext = xParentContext->createUnknownChildContext( aNamespace, aElementName, xAttr );
- else
+ else if( rEntity.mxDocumentHandler.is() )
xContext = rEntity.mxDocumentHandler->createUnknownChildContext( aNamespace, aElementName, xAttr );
if( xContext.is() )
@@ -848,7 +848,7 @@ void FastSaxParser::callbackStartElement( const XML_Char* pwName, const XML_Char
{
if( xParentContext.is() )
xContext = xParentContext->createFastChildContext( nElementToken, xAttr );
- else
+ else if( rEntity.mxDocumentHandler.is() )
xContext = rEntity.mxDocumentHandler->createFastChildContext( nElementToken, xAttr );