LCOV - code coverage report
Current view: top level - editeng/qa/items - borderline_test.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 76 80 95.0 %
Date: 2014-11-03 Functions: 16 18 88.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             : #include <cppunit/TestFixture.h>
      12             : #include <cppunit/extensions/HelperMacros.h>
      13             : #include <cppunit/plugin/TestPlugIn.h>
      14             : 
      15             : #include <editeng/borderline.hxx>
      16             : 
      17             : using namespace ::com::sun::star::table::BorderLineStyle;
      18             : 
      19             : #define TEST_WIDTH long( 40 )
      20             : 
      21             : #define THINTHICKSG_IN_WIDTH long( 15 )
      22             : #define THINTHICKSG_OUT_WIDTH long( 40 )
      23             : #define THINTHICKSG_DIST_WIDTH long( 15 )
      24             : 
      25             : #define THINTHICKLG_IN_WIDTH long( 15 )
      26             : #define THINTHICKLG_OUT_WIDTH long( 30 )
      27             : #define THINTHICKLG_DIST_WIDTH long( 40 )
      28             : 
      29             : using namespace editeng;
      30             : 
      31             : CPPUNIT_NS_BEGIN
      32             : 
      33             : template<> struct assertion_traits<SvxBorderStyle>
      34             : {
      35          12 :     static bool equal( const SvxBorderStyle& x, const SvxBorderStyle& y )
      36             :     {
      37          12 :         return x == y;
      38             :     }
      39             : 
      40           0 :     static std::string toString( const SvxBorderStyle& x )
      41             :     {
      42           0 :         OStringStream ost;
      43           0 :         ost << static_cast<unsigned int>(x);
      44           0 :         return ost.str();
      45             :     }
      46             : };
      47             : 
      48             : CPPUNIT_NS_END
      49             : 
      50             : namespace {
      51             : 
      52          36 : class BorderLineTest : public CppUnit::TestFixture
      53             : {
      54             :     public:
      55             :         void testGuessWidthDouble();
      56             :         void testGuessWidthNoMatch();
      57             :         void testGuessWidthThinthickSmallgap();
      58             :         void testGuessWidthThinthickLargegap();
      59             :         void testGuessWidthNostyleDouble();
      60             :         void testGuessWidthNostyleSingle();
      61             : 
      62           4 :     CPPUNIT_TEST_SUITE(BorderLineTest);
      63           2 :     CPPUNIT_TEST(testGuessWidthDouble);
      64           2 :     CPPUNIT_TEST(testGuessWidthNoMatch);
      65           2 :     CPPUNIT_TEST(testGuessWidthThinthickSmallgap);
      66           2 :     CPPUNIT_TEST(testGuessWidthThinthickLargegap);
      67           2 :     CPPUNIT_TEST(testGuessWidthNostyleDouble);
      68           2 :     CPPUNIT_TEST(testGuessWidthNostyleSingle);
      69           4 :     CPPUNIT_TEST_SUITE_END();
      70             : };
      71             : 
      72           2 : CPPUNIT_TEST_SUITE_REGISTRATION(BorderLineTest);
      73             : 
      74           2 : void BorderLineTest::testGuessWidthDouble()
      75             : {
      76             :     // Normal double case
      77           2 :     SvxBorderLine line;
      78           2 :     line.GuessLinesWidths( DOUBLE, TEST_WIDTH, TEST_WIDTH, TEST_WIDTH );
      79           2 :     CPPUNIT_ASSERT_EQUAL( DOUBLE, line.GetBorderLineStyle() );
      80           2 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetOutWidth()) );
      81           2 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetInWidth()) );
      82           2 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetDistance()) );
      83           2 :     CPPUNIT_ASSERT_EQUAL( 3*TEST_WIDTH, line.GetWidth() );
      84           2 : }
      85             : 
      86           2 : void BorderLineTest::testGuessWidthNoMatch()
      87             : {
      88           2 :     SvxBorderLine line;
      89             :     line.GuessLinesWidths( DOUBLE,
      90           2 :             TEST_WIDTH + 1, TEST_WIDTH + 2, TEST_WIDTH + 3 );
      91           2 :     CPPUNIT_ASSERT_EQUAL( DOUBLE, line.GetBorderLineStyle() );
      92           2 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+1, static_cast<long>(line.GetOutWidth()) );
      93           2 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+2, static_cast<long>(line.GetInWidth()) );
      94           2 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+3, static_cast<long>(line.GetDistance()));
      95           2 :     CPPUNIT_ASSERT_EQUAL( long( (3 * TEST_WIDTH) + 6 ), line.GetWidth() );
      96           2 : }
      97             : 
      98           2 : void BorderLineTest::testGuessWidthThinthickSmallgap()
      99             : {
     100           2 :     SvxBorderLine line;
     101             :     line.GuessLinesWidths( DOUBLE,
     102             :             THINTHICKSG_OUT_WIDTH,
     103             :             THINTHICKSG_IN_WIDTH,
     104           2 :             THINTHICKSG_DIST_WIDTH );
     105           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICK_SMALLGAP, line.GetBorderLineStyle() );
     106           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKSG_OUT_WIDTH,
     107           2 :             static_cast<long>(line.GetOutWidth()) );
     108           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKSG_IN_WIDTH,
     109           2 :             static_cast<long>(line.GetInWidth()) );
     110           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKSG_DIST_WIDTH,
     111           2 :             static_cast<long>(line.GetDistance()) );
     112           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKSG_OUT_WIDTH + THINTHICKSG_IN_WIDTH
     113           2 :             + THINTHICKSG_DIST_WIDTH, line.GetWidth() );
     114           2 : }
     115             : 
     116           2 : void BorderLineTest::testGuessWidthThinthickLargegap()
     117             : {
     118           2 :     SvxBorderLine line;
     119             :     line.GuessLinesWidths( DOUBLE,
     120             :             THINTHICKLG_OUT_WIDTH,
     121             :             THINTHICKLG_IN_WIDTH,
     122           2 :             THINTHICKLG_DIST_WIDTH );
     123           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICK_LARGEGAP, line.GetBorderLineStyle() );
     124           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH,
     125           2 :             static_cast<long>(line.GetOutWidth()) );
     126           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_IN_WIDTH,
     127           2 :             static_cast<long>(line.GetInWidth()) );
     128           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_DIST_WIDTH,
     129           2 :             static_cast<long>(line.GetDistance()) );
     130           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH + THINTHICKLG_IN_WIDTH
     131           2 :             + THINTHICKLG_DIST_WIDTH, line.GetWidth() );
     132           2 : }
     133             : 
     134           2 : void BorderLineTest::testGuessWidthNostyleDouble()
     135             : {
     136           2 :     SvxBorderLine line;
     137             :     line.GuessLinesWidths( css::table::BorderLineStyle::NONE,
     138             :             THINTHICKLG_OUT_WIDTH,
     139             :             THINTHICKLG_IN_WIDTH,
     140           2 :             THINTHICKLG_DIST_WIDTH );
     141           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICK_LARGEGAP, line.GetBorderLineStyle() );
     142           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH,
     143           2 :             static_cast<long>(line.GetOutWidth()) );
     144           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_IN_WIDTH,
     145           2 :             static_cast<long>(line.GetInWidth()) );
     146           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_DIST_WIDTH,
     147           2 :             static_cast<long>(line.GetDistance()) );
     148           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH + THINTHICKLG_IN_WIDTH
     149           2 :             + THINTHICKLG_DIST_WIDTH, line.GetWidth() );
     150           2 : }
     151             : 
     152           2 : void BorderLineTest::testGuessWidthNostyleSingle()
     153             : {
     154           2 :     SvxBorderLine line;
     155           2 :     line.GuessLinesWidths( css::table::BorderLineStyle::NONE, TEST_WIDTH );
     156           2 :     CPPUNIT_ASSERT_EQUAL( SOLID, line.GetBorderLineStyle() );
     157           2 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, line.GetWidth() );
     158           2 : }
     159             : 
     160             : }
     161             : 
     162           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     163             : 
     164             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10