1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/config.h>
12 #include <com/sun/star/io/Pipe.hpp>
13 #include <com/sun/star/xml/sax/FastToken.hpp>
14 #include <com/sun/star/xml/sax/SAXParseException.hpp>
15 #include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
17 #include <cppuhelper/implbase1.hxx>
18 #include <sax/fastparser.hxx>
19 #include <test/bootstrapfixture.hxx>
22 using namespace css::xml::sax
;
26 class DummyTokenHandler
: public cppu::WeakImplHelper1
< xml::sax::XFastTokenHandler
>
29 DummyTokenHandler() {}
30 virtual ~DummyTokenHandler() {}
32 virtual sal_Int32 SAL_CALL
getTokenFromUTF8( const uno::Sequence
<sal_Int8
>& )
33 throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
35 return FastToken::DONTKNOW
;
37 virtual uno::Sequence
< sal_Int8
> SAL_CALL
getUTF8Identifier( sal_Int32
)
38 throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
40 CPPUNIT_ASSERT_MESSAGE( "getUTF8Identifier: unexpected call", false );
41 return uno::Sequence
<sal_Int8
>();
45 class ParserTest
: public test::BootstrapFixture
48 sax_fastparser::FastSaxParser maParser
;
49 uno::Reference
< XFastDocumentHandler
> mxDocumentHandler
;
50 uno::Reference
< DummyTokenHandler
> mxTokenHandler
;
53 virtual void setUp() SAL_OVERRIDE
;
54 virtual void tearDown() SAL_OVERRIDE
;
58 CPPUNIT_TEST_SUITE(ParserTest
);
60 CPPUNIT_TEST_SUITE_END();
63 uno::Reference
< io::XInputStream
> createStream(const OString
& sInput
);
66 void ParserTest::setUp()
68 test::BootstrapFixture::setUp();
69 mxTokenHandler
.set( new DummyTokenHandler() );
70 maParser
.setTokenHandler( mxTokenHandler
);
73 void ParserTest::tearDown()
75 test::BootstrapFixture::tearDown();
78 uno::Reference
< io::XInputStream
> ParserTest::createStream(const OString
& sInput
)
80 uno::Reference
< io::XOutputStream
> xPipe( io::Pipe::create(m_xContext
) );
81 uno::Reference
< io::XInputStream
> xInStream( xPipe
, uno::UNO_QUERY
);
82 uno::Sequence
< sal_Int8
> aSeq( reinterpret_cast<sal_Int8
const *>(sInput
.getStr()), sInput
.getLength() );
83 xPipe
->writeBytes( aSeq
);
89 void ParserTest::parse()
91 maInput
.aInputStream
= createStream("<a>...<b />..</a>");
92 maParser
.parseStream( maInput
);
94 maInput
.aInputStream
= createStream("<b></a>");
95 bool bException
= false;
98 maParser
.parseStream( maInput
);
100 catch (const SAXParseException
&)
104 CPPUNIT_ASSERT_MESSAGE("No Exception!", bException
);
107 CPPUNIT_TEST_SUITE_REGISTRATION(ParserTest
);
111 CPPUNIT_PLUGIN_IMPLEMENT();
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */