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>
16 #include <sax/fastparser.hxx>
17 #include <sax/fastattribs.hxx>
18 #include <test/bootstrapfixture.hxx>
19 #include <rtl/ref.hxx>
22 using namespace css::xml::sax
;
26 class DummyTokenHandler
: public sax_fastparser::FastTokenHandlerBase
29 DummyTokenHandler() {}
31 virtual sal_Int32 SAL_CALL
getTokenFromUTF8( const uno::Sequence
<sal_Int8
>& ) override
33 return FastToken::DONTKNOW
;
35 virtual uno::Sequence
< sal_Int8
> SAL_CALL
getUTF8Identifier( sal_Int32
) override
37 CPPUNIT_ASSERT_MESSAGE( "getUTF8Identifier: unexpected call", false );
38 return uno::Sequence
<sal_Int8
>();
40 virtual sal_Int32
getTokenDirect(std::string_view
/* token */) const override
46 class ParserTest
: public test::BootstrapFixture
49 rtl::Reference
< sax_fastparser::FastSaxParser
> mxParser
;
50 rtl::Reference
< DummyTokenHandler
> mxTokenHandler
;
53 virtual void setUp() override
;
57 CPPUNIT_TEST_SUITE(ParserTest
);
59 CPPUNIT_TEST_SUITE_END();
62 uno::Reference
< io::XInputStream
> createStream(const OString
& sInput
);
65 void ParserTest::setUp()
67 test::BootstrapFixture::setUp();
68 mxTokenHandler
.set( new DummyTokenHandler() );
69 mxParser
.set( new sax_fastparser::FastSaxParser() );
70 mxParser
->setTokenHandler( mxTokenHandler
);
73 uno::Reference
< io::XInputStream
> ParserTest::createStream(const OString
& sInput
)
75 uno::Reference
< io::XOutputStream
> xPipe( io::Pipe::create(m_xContext
) );
76 uno::Reference
< io::XInputStream
> xInStream( xPipe
, uno::UNO_QUERY
);
77 uno::Sequence
< sal_Int8
> aSeq( reinterpret_cast<sal_Int8
const *>(sInput
.getStr()), sInput
.getLength() );
78 xPipe
->writeBytes( aSeq
);
84 void ParserTest::parse()
86 maInput
.aInputStream
= createStream("<a>...<b />..</a>"_ostr
);
87 mxParser
->parseStream( maInput
);
89 maInput
.aInputStream
= createStream("<b></a>"_ostr
);
90 CPPUNIT_ASSERT_THROW( mxParser
->parseStream( maInput
), css::xml::sax::SAXParseException
);
93 CPPUNIT_TEST_SUITE_REGISTRATION(ParserTest
);
97 CPPUNIT_PLUGIN_IMPLEMENT();
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */