Kaydet (Commit) dffb0782 authored tarafından Matúš Kukan's avatar Matúš Kukan

sax: add unit test for FastSaxParser

Adapt FastSaxParser so that it does not require XFastDocumentHandler.

Change-Id: I7af49752dfbb4b55b8dde094fe6b762bd179be78
üst 7082efee
# -*- 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:
......@@ -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:
/* -*- 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: */
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment