LCOV - code coverage report
Current view: top level - sax/qa/cppunit - attributes.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 31 31 100.0 %
Date: 2015-06-13 12:38:46 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/types.h>
      11             : 
      12             : #include <cppunit/TestFixture.h>
      13             : #include <cppunit/extensions/HelperMacros.h>
      14             : #include <cppunit/plugin/TestPlugIn.h>
      15             : 
      16             : #include <sax/fastattribs.hxx>
      17             : 
      18             : using namespace css;
      19             : using namespace css::xml;
      20             : 
      21             : namespace {
      22             : 
      23           3 : class AttributesTest: public CppUnit::TestFixture
      24             : {
      25             :     bool mbException;
      26             : 
      27             : public:
      28             :     void test();
      29             : 
      30           2 :     CPPUNIT_TEST_SUITE( AttributesTest );
      31           1 :     CPPUNIT_TEST( test );
      32           5 :     CPPUNIT_TEST_SUITE_END();
      33             : };
      34             : 
      35           1 : void AttributesTest::test()
      36             : {
      37           1 :     sax_fastparser::FastAttributeList aAttributeList( NULL );
      38           1 :     aAttributeList.add(1, "1");
      39           1 :     aAttributeList.add(2, OString("2"));
      40             : 
      41             :     // We can't test getValueToken() and getOptionalValueToken()
      42             :     // without XFastTokenHandler :-(
      43             :     // Uncomment to get segmantation fault:
      44             :     // aAttributeList.getOptionalValueToken(1, 0);
      45             :     // aAttributeList.getValueToken(2);
      46             : 
      47           1 :     CPPUNIT_ASSERT( aAttributeList.hasAttribute(1) );
      48           1 :     CPPUNIT_ASSERT( !aAttributeList.hasAttribute(3) );
      49             : 
      50           1 :     CPPUNIT_ASSERT_EQUAL( aAttributeList.getOptionalValue(2), OUString("2") );
      51           1 :     CPPUNIT_ASSERT_EQUAL( aAttributeList.getOptionalValue(3), OUString() );
      52             : 
      53           1 :     CPPUNIT_ASSERT_EQUAL( aAttributeList.getValue(1), OUString("1") );
      54           1 :     mbException = false;
      55             : 
      56           1 :     try { aAttributeList.getValue(3); }
      57           2 :     catch (const sax::SAXException& )
      58             :     {
      59           1 :         mbException = true;
      60             :     }
      61           1 :     CPPUNIT_ASSERT( mbException );
      62             : 
      63           1 :     aAttributeList.addUnknown("a", "a");
      64           1 :     aAttributeList.addUnknown("b", "b", "b");
      65           1 :     aAttributeList.addUnknown("c", "c");
      66           1 :     CPPUNIT_ASSERT_EQUAL( (sal_Int32) 3, aAttributeList.getUnknownAttributes().getLength() );
      67             : 
      68           1 :     CPPUNIT_ASSERT_EQUAL( (sal_Int32) 2, aAttributeList.getFastAttributes().getLength() );
      69             : 
      70           1 :     aAttributeList.clear();
      71           1 :     CPPUNIT_ASSERT( !aAttributeList.hasAttribute(1) );
      72           1 :     CPPUNIT_ASSERT_EQUAL( (sal_Int32) 0, aAttributeList.getFastAttributes().getLength() );
      73           1 :     aAttributeList.addUnknown("c", "c");
      74           1 :     CPPUNIT_ASSERT_EQUAL( (sal_Int32) 1, aAttributeList.getUnknownAttributes().getLength() );
      75           1 : }
      76             : 
      77           1 : CPPUNIT_TEST_SUITE_REGISTRATION( AttributesTest );
      78             : 
      79             : }
      80             : 
      81           4 : CPPUNIT_PLUGIN_IMPLEMENT();
      82             : 
      83             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11