LCOV - code coverage report
Current view: top level - sax/qa/cppunit - parser.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 33 33 100.0 %
Date: 2014-04-11 Functions: 13 14 92.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/FastParser.hpp>
      14             : #include <com/sun/star/xml/sax/FastTokenHandler.hpp>
      15             : #include <com/sun/star/xml/sax/SAXParseException.hpp>
      16             : #include <com/sun/star/xml/sax/XFastParser.hpp>
      17             : 
      18             : #include <test/bootstrapfixture.hxx>
      19             : 
      20             : using namespace css;
      21             : using namespace css::xml::sax;
      22             : 
      23             : namespace {
      24             : 
      25           3 : class ParserTest: public test::BootstrapFixture
      26             : {
      27             :     InputSource maInput;
      28             :     uno::Reference< XFastParser > mxParser;
      29             :     uno::Reference< XFastDocumentHandler > mxDocumentHandler;
      30             : 
      31             : public:
      32             :     virtual void setUp() SAL_OVERRIDE;
      33             :     virtual void tearDown() SAL_OVERRIDE;
      34             : 
      35             :     void parse();
      36             : 
      37           2 :     CPPUNIT_TEST_SUITE(ParserTest);
      38           1 :     CPPUNIT_TEST(parse);
      39           2 :     CPPUNIT_TEST_SUITE_END();
      40             : 
      41             : private:
      42             :     uno::Reference< io::XInputStream > createStream(const OString& sInput);
      43             : };
      44             : 
      45           1 : void ParserTest::setUp()
      46             : {
      47           1 :     test::BootstrapFixture::setUp();
      48           1 :     mxParser = css::xml::sax::FastParser::create(m_xContext);
      49           1 :     mxParser->setTokenHandler(
      50           1 :         css::xml::sax::FastTokenHandler::create(m_xContext));
      51           1 : }
      52             : 
      53           1 : void ParserTest::tearDown()
      54             : {
      55           1 :     test::BootstrapFixture::tearDown();
      56           1 : }
      57             : 
      58           2 : uno::Reference< io::XInputStream > ParserTest::createStream(const OString& sInput)
      59             : {
      60           2 :     uno::Reference< io::XOutputStream > xPipe( io::Pipe::create(m_xContext) );
      61           2 :     uno::Reference< io::XInputStream > xInStream( xPipe, uno::UNO_QUERY );
      62           4 :     uno::Sequence< sal_Int8 > aSeq( (sal_Int8*)sInput.getStr(), sInput.getLength() );
      63           2 :     xPipe->writeBytes( aSeq );
      64           2 :     xPipe->flush();
      65           2 :     xPipe->closeOutput();
      66           4 :     return xInStream;
      67             : }
      68             : 
      69           1 : void ParserTest::parse()
      70             : {
      71           1 :     maInput.aInputStream = createStream("<a>...<b />..</a>");
      72           1 :     mxParser->parseStream( maInput );
      73             : 
      74           1 :     maInput.aInputStream = createStream("<b></a>");
      75           1 :     bool bException = false;
      76             :     try
      77             :     {
      78           1 :         mxParser->parseStream( maInput );
      79             :     }
      80           2 :     catch (const SAXParseException &)
      81             :     {
      82           1 :         bException = true;
      83             :     }
      84           1 :     CPPUNIT_ASSERT_MESSAGE("No Exception!", bException);
      85           1 : }
      86             : 
      87           1 : CPPUNIT_TEST_SUITE_REGISTRATION(ParserTest);
      88             : 
      89             : }
      90             : 
      91           4 : CPPUNIT_PLUGIN_IMPLEMENT();
      92             : 
      93             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10