fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sax / qa / cppunit / parser.cxx
blob824d5ecd7078a7438bd9a6095a600fb38cd4ad9a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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>
21 using namespace css;
22 using namespace css::xml::sax;
24 namespace {
26 class DummyTokenHandler : public cppu::WeakImplHelper1< xml::sax::XFastTokenHandler >
28 public:
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
47 InputSource maInput;
48 sax_fastparser::FastSaxParser maParser;
49 uno::Reference< XFastDocumentHandler > mxDocumentHandler;
50 uno::Reference< DummyTokenHandler > mxTokenHandler;
52 public:
53 virtual void setUp() SAL_OVERRIDE;
54 virtual void tearDown() SAL_OVERRIDE;
56 void parse();
58 CPPUNIT_TEST_SUITE(ParserTest);
59 CPPUNIT_TEST(parse);
60 CPPUNIT_TEST_SUITE_END();
62 private:
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 );
84 xPipe->flush();
85 xPipe->closeOutput();
86 return xInStream;
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;
96 try
98 maParser.parseStream( maInput );
100 catch (const SAXParseException &)
102 bException = true;
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: */