summaryrefslogtreecommitdiff
path: root/sax/qa
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@gmail.com>2013-10-15 17:28:35 +0200
committerMatúš Kukan <matus.kukan@gmail.com>2013-10-17 21:38:33 +0200
commitdffb0782bb40337e32f3a22b3827b1d47e0acd72 (patch)
tree21568f714cc028950053aa232f2209dae16808c3 /sax/qa
parent7082efee96e1f165b30b1266376bb95db006e25e (diff)
sax: add unit test for FastSaxParser
Adapt FastSaxParser so that it does not require XFastDocumentHandler. Change-Id: I7af49752dfbb4b55b8dde094fe6b762bd179be78
Diffstat (limited to 'sax/qa')
-rw-r--r--sax/qa/cppunit/parser.cxx98
1 files changed, 98 insertions, 0 deletions
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: */