LCOV - code coverage report
Current view: top level - sax/qa/cppunit - parser.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 36 39 92.3 %
Date: 2014-11-03 Functions: 17 19 89.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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             :  */
       9             : 
      10             : #include <sal/config.h>
      11             : 
      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>
      16             : 
      17             : #include <cppuhelper/implbase1.hxx>
      18             : #include <sax/fastparser.hxx>
      19             : #include <test/bootstrapfixture.hxx>
      20             : 
      21             : using namespace css;
      22             : using namespace css::xml::sax;
      23             : 
      24             : namespace {
      25             : 
      26             : class DummyTokenHandler : public cppu::WeakImplHelper1< xml::sax::XFastTokenHandler >
      27             : {
      28             : public:
      29           2 :              DummyTokenHandler() {}
      30           4 :     virtual ~DummyTokenHandler() {}
      31             : 
      32           6 :     virtual sal_Int32 SAL_CALL getTokenFromUTF8( const uno::Sequence<sal_Int8>& )
      33             :         throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      34             :     {
      35           6 :         return FastToken::DONTKNOW;
      36             :     }
      37           0 :     virtual uno::Sequence< sal_Int8 > SAL_CALL getUTF8Identifier( sal_Int32 )
      38             :         throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      39             :     {
      40           0 :         CPPUNIT_ASSERT_MESSAGE( "getUTF8Identifier: unexpected call", false );
      41           0 :         return uno::Sequence<sal_Int8>();
      42             :     }
      43             : };
      44             : 
      45           6 : class ParserTest: public test::BootstrapFixture
      46             : {
      47             :     InputSource maInput;
      48             :     sax_fastparser::FastSaxParser maParser;
      49             :     uno::Reference< XFastDocumentHandler > mxDocumentHandler;
      50             :     uno::Reference< DummyTokenHandler > mxTokenHandler;
      51             : 
      52             : public:
      53             :     virtual void setUp() SAL_OVERRIDE;
      54             :     virtual void tearDown() SAL_OVERRIDE;
      55             : 
      56             :     void parse();
      57             : 
      58           4 :     CPPUNIT_TEST_SUITE(ParserTest);
      59           2 :     CPPUNIT_TEST(parse);
      60           4 :     CPPUNIT_TEST_SUITE_END();
      61             : 
      62             : private:
      63             :     uno::Reference< io::XInputStream > createStream(const OString& sInput);
      64             : };
      65             : 
      66           2 : void ParserTest::setUp()
      67             : {
      68           2 :     test::BootstrapFixture::setUp();
      69           2 :     mxTokenHandler.set( new DummyTokenHandler() );
      70           2 :     maParser.setTokenHandler( mxTokenHandler );
      71           2 : }
      72             : 
      73           2 : void ParserTest::tearDown()
      74             : {
      75           2 :     test::BootstrapFixture::tearDown();
      76           2 : }
      77             : 
      78           4 : uno::Reference< io::XInputStream > ParserTest::createStream(const OString& sInput)
      79             : {
      80           4 :     uno::Reference< io::XOutputStream > xPipe( io::Pipe::create(m_xContext) );
      81           4 :     uno::Reference< io::XInputStream > xInStream( xPipe, uno::UNO_QUERY );
      82           8 :     uno::Sequence< sal_Int8 > aSeq( (sal_Int8*)sInput.getStr(), sInput.getLength() );
      83           4 :     xPipe->writeBytes( aSeq );
      84           4 :     xPipe->flush();
      85           4 :     xPipe->closeOutput();
      86           8 :     return xInStream;
      87             : }
      88             : 
      89           2 : void ParserTest::parse()
      90             : {
      91           2 :     maInput.aInputStream = createStream("<a>...<b />..</a>");
      92           2 :     maParser.parseStream( maInput );
      93             : 
      94           2 :     maInput.aInputStream = createStream("<b></a>");
      95           2 :     bool bException = false;
      96             :     try
      97             :     {
      98           2 :         maParser.parseStream( maInput );
      99             :     }
     100           4 :     catch (const SAXParseException &)
     101             :     {
     102           2 :         bException = true;
     103             :     }
     104           2 :     CPPUNIT_ASSERT_MESSAGE("No Exception!", bException);
     105           2 : }
     106             : 
     107           2 : CPPUNIT_TEST_SUITE_REGISTRATION(ParserTest);
     108             : 
     109             : }
     110             : 
     111           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     112             : 
     113             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10