LCOV - code coverage report
Current view: top level - sax/qa/cppunit - parser.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 36 39 92.3 %
Date: 2015-06-13 12:38:46 Functions: 20 22 90.9 %
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           1 :              DummyTokenHandler() {}
      30           2 :     virtual ~DummyTokenHandler() {}
      31             : 
      32           3 :     virtual sal_Int32 SAL_CALL getTokenFromUTF8( const uno::Sequence<sal_Int8>& )
      33             :         throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      34             :     {
      35           3 :         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           3 : 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           2 :     CPPUNIT_TEST_SUITE(ParserTest);
      59           1 :     CPPUNIT_TEST(parse);
      60           5 :     CPPUNIT_TEST_SUITE_END();
      61             : 
      62             : private:
      63             :     uno::Reference< io::XInputStream > createStream(const OString& sInput);
      64             : };
      65             : 
      66           1 : void ParserTest::setUp()
      67             : {
      68           1 :     test::BootstrapFixture::setUp();
      69           1 :     mxTokenHandler.set( new DummyTokenHandler() );
      70           1 :     maParser.setTokenHandler( mxTokenHandler );
      71           1 : }
      72             : 
      73           1 : void ParserTest::tearDown()
      74             : {
      75           1 :     test::BootstrapFixture::tearDown();
      76           1 : }
      77             : 
      78           2 : uno::Reference< io::XInputStream > ParserTest::createStream(const OString& sInput)
      79             : {
      80           2 :     uno::Reference< io::XOutputStream > xPipe( io::Pipe::create(m_xContext) );
      81           2 :     uno::Reference< io::XInputStream > xInStream( xPipe, uno::UNO_QUERY );
      82           4 :     uno::Sequence< sal_Int8 > aSeq( reinterpret_cast<sal_Int8 const *>(sInput.getStr()), sInput.getLength() );
      83           2 :     xPipe->writeBytes( aSeq );
      84           2 :     xPipe->flush();
      85           2 :     xPipe->closeOutput();
      86           4 :     return xInStream;
      87             : }
      88             : 
      89           1 : void ParserTest::parse()
      90             : {
      91           1 :     maInput.aInputStream = createStream("<a>...<b />..</a>");
      92           1 :     maParser.parseStream( maInput );
      93             : 
      94           1 :     maInput.aInputStream = createStream("<b></a>");
      95           1 :     bool bException = false;
      96             :     try
      97             :     {
      98           1 :         maParser.parseStream( maInput );
      99             :     }
     100           2 :     catch (const SAXParseException &)
     101             :     {
     102           1 :         bException = true;
     103             :     }
     104           1 :     CPPUNIT_ASSERT_MESSAGE("No Exception!", bException);
     105           1 : }
     106             : 
     107           1 : CPPUNIT_TEST_SUITE_REGISTRATION(ParserTest);
     108             : 
     109             : }
     110             : 
     111           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     112             : 
     113             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11