2013-10-15 17:28:35 +02:00
|
|
|
/* -*- 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>
|
2013-12-19 13:35:28 +01:00
|
|
|
#include <com/sun/star/xml/sax/FastParser.hpp>
|
2014-09-18 10:03:50 +02:00
|
|
|
#include <com/sun/star/xml/sax/FastToken.hpp>
|
2013-10-15 17:28:35 +02:00
|
|
|
#include <com/sun/star/xml/sax/SAXParseException.hpp>
|
|
|
|
#include <com/sun/star/xml/sax/XFastParser.hpp>
|
|
|
|
|
2014-09-18 10:03:50 +02:00
|
|
|
#include <cppuhelper/implbase1.hxx>
|
2013-10-15 17:28:35 +02:00
|
|
|
#include <test/bootstrapfixture.hxx>
|
|
|
|
|
|
|
|
using namespace css;
|
|
|
|
using namespace css::xml::sax;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2014-09-18 10:03:50 +02:00
|
|
|
class DummyTokenHandler : public cppu::WeakImplHelper1< xml::sax::XFastTokenHandler >
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DummyTokenHandler() {}
|
|
|
|
virtual ~DummyTokenHandler() {}
|
|
|
|
|
|
|
|
virtual sal_Int32 SAL_CALL getToken( const OUString& )
|
|
|
|
throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "getToken: unexpected call", false );
|
|
|
|
return FastToken::DONTKNOW;
|
|
|
|
}
|
|
|
|
virtual OUString SAL_CALL getIdentifier( sal_Int32 )
|
|
|
|
throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "getIdentifier: unexpected call", false );
|
|
|
|
return OUString();
|
|
|
|
}
|
|
|
|
virtual sal_Int32 SAL_CALL getTokenFromUTF8( const uno::Sequence<sal_Int8>& )
|
|
|
|
throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
|
|
|
|
{
|
|
|
|
return FastToken::DONTKNOW;
|
|
|
|
}
|
|
|
|
virtual uno::Sequence< sal_Int8 > SAL_CALL getUTF8Identifier( sal_Int32 )
|
|
|
|
throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "getUTF8Identifier: unexpected call", false );
|
|
|
|
return uno::Sequence<sal_Int8>();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-15 17:28:35 +02:00
|
|
|
class ParserTest: public test::BootstrapFixture
|
|
|
|
{
|
|
|
|
InputSource maInput;
|
|
|
|
uno::Reference< XFastParser > mxParser;
|
|
|
|
uno::Reference< XFastDocumentHandler > mxDocumentHandler;
|
2014-09-18 10:03:50 +02:00
|
|
|
uno::Reference< DummyTokenHandler > mxTokenHandler;
|
2013-10-15 17:28:35 +02:00
|
|
|
|
|
|
|
public:
|
2014-03-26 16:37:00 +01:00
|
|
|
virtual void setUp() SAL_OVERRIDE;
|
|
|
|
virtual void tearDown() SAL_OVERRIDE;
|
2013-10-15 17:28:35 +02:00
|
|
|
|
|
|
|
void parse();
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(ParserTest);
|
|
|
|
CPPUNIT_TEST(parse);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
private:
|
2014-03-06 15:29:08 +02:00
|
|
|
uno::Reference< io::XInputStream > createStream(const OString& sInput);
|
2013-10-15 17:28:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
void ParserTest::setUp()
|
|
|
|
{
|
|
|
|
test::BootstrapFixture::setUp();
|
2013-12-19 13:35:28 +01:00
|
|
|
mxParser = css::xml::sax::FastParser::create(m_xContext);
|
2014-09-18 10:03:50 +02:00
|
|
|
mxTokenHandler.set( new DummyTokenHandler() );
|
|
|
|
mxParser->setTokenHandler( mxTokenHandler );
|
2013-10-15 17:28:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ParserTest::tearDown()
|
|
|
|
{
|
|
|
|
test::BootstrapFixture::tearDown();
|
|
|
|
}
|
|
|
|
|
2014-03-06 15:29:08 +02:00
|
|
|
uno::Reference< io::XInputStream > ParserTest::createStream(const OString& sInput)
|
2013-10-15 17:28:35 +02:00
|
|
|
{
|
|
|
|
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: */
|