LCOV - code coverage report
Current view: top level - editeng/qa/items - borderline_test.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 76 80 95.0 %
Date: 2015-06-13 12:38:46 Functions: 19 21 90.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/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           6 :     static bool equal( const SvxBorderStyle& x, const SvxBorderStyle& y )
      36             :     {
      37           6 :         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          18 : 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           2 :     CPPUNIT_TEST_SUITE(BorderLineTest);
      63           1 :     CPPUNIT_TEST(testGuessWidthDouble);
      64           1 :     CPPUNIT_TEST(testGuessWidthNoMatch);
      65           1 :     CPPUNIT_TEST(testGuessWidthThinthickSmallgap);
      66           1 :     CPPUNIT_TEST(testGuessWidthThinthickLargegap);
      67           1 :     CPPUNIT_TEST(testGuessWidthNostyleDouble);
      68           1 :     CPPUNIT_TEST(testGuessWidthNostyleSingle);
      69           5 :     CPPUNIT_TEST_SUITE_END();
      70             : };
      71             : 
      72           1 : CPPUNIT_TEST_SUITE_REGISTRATION(BorderLineTest);
      73             : 
      74           1 : void BorderLineTest::testGuessWidthDouble()
      75             : {
      76             :     // Normal double case
      77           1 :     SvxBorderLine line;
      78           1 :     line.GuessLinesWidths( DOUBLE, TEST_WIDTH, TEST_WIDTH, TEST_WIDTH );
      79           1 :     CPPUNIT_ASSERT_EQUAL( DOUBLE, line.GetBorderLineStyle() );
      80           1 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetOutWidth()) );
      81           1 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetInWidth()) );
      82           1 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetDistance()) );
      83           1 :     CPPUNIT_ASSERT_EQUAL( 3*TEST_WIDTH, line.GetWidth() );
      84           1 : }
      85             : 
      86           1 : void BorderLineTest::testGuessWidthNoMatch()
      87             : {
      88           1 :     SvxBorderLine line;
      89             :     line.GuessLinesWidths( DOUBLE,
      90           1 :             TEST_WIDTH + 1, TEST_WIDTH + 2, TEST_WIDTH + 3 );
      91           1 :     CPPUNIT_ASSERT_EQUAL( DOUBLE, line.GetBorderLineStyle() );
      92           1 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+1, static_cast<long>(line.GetOutWidth()) );
      93           1 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+2, static_cast<long>(line.GetInWidth()) );
      94           1 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+3, static_cast<long>(line.GetDistance()));
      95           1 :     CPPUNIT_ASSERT_EQUAL( long( (3 * TEST_WIDTH) + 6 ), line.GetWidth() );
      96           1 : }
      97             : 
      98           1 : void BorderLineTest::testGuessWidthThinthickSmallgap()
      99             : {
     100           1 :     SvxBorderLine line;
     101             :     line.GuessLinesWidths( DOUBLE,
     102             :             THINTHICKSG_OUT_WIDTH,
     103             :             THINTHICKSG_IN_WIDTH,
     104           1 :             THINTHICKSG_DIST_WIDTH );
     105           1 :     CPPUNIT_ASSERT_EQUAL( THINTHICK_SMALLGAP, line.GetBorderLineStyle() );
     106           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKSG_OUT_WIDTH,
     107           1 :             static_cast<long>(line.GetOutWidth()) );
     108           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKSG_IN_WIDTH,
     109           1 :             static_cast<long>(line.GetInWidth()) );
     110           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKSG_DIST_WIDTH,
     111           1 :             static_cast<long>(line.GetDistance()) );
     112           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKSG_OUT_WIDTH + THINTHICKSG_IN_WIDTH
     113           1 :             + THINTHICKSG_DIST_WIDTH, line.GetWidth() );
     114           1 : }
     115             : 
     116           1 : void BorderLineTest::testGuessWidthThinthickLargegap()
     117             : {
     118           1 :     SvxBorderLine line;
     119             :     line.GuessLinesWidths( DOUBLE,
     120             :             THINTHICKLG_OUT_WIDTH,
     121             :             THINTHICKLG_IN_WIDTH,
     122           1 :             THINTHICKLG_DIST_WIDTH );
     123           1 :     CPPUNIT_ASSERT_EQUAL( THINTHICK_LARGEGAP, line.GetBorderLineStyle() );
     124           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH,
     125           1 :             static_cast<long>(line.GetOutWidth()) );
     126           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_IN_WIDTH,
     127           1 :             static_cast<long>(line.GetInWidth()) );
     128           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_DIST_WIDTH,
     129           1 :             static_cast<long>(line.GetDistance()) );
     130           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH + THINTHICKLG_IN_WIDTH
     131           1 :             + THINTHICKLG_DIST_WIDTH, line.GetWidth() );
     132           1 : }
     133             : 
     134           1 : void BorderLineTest::testGuessWidthNostyleDouble()
     135             : {
     136           1 :     SvxBorderLine line;
     137             :     line.GuessLinesWidths( css::table::BorderLineStyle::NONE,
     138             :             THINTHICKLG_OUT_WIDTH,
     139             :             THINTHICKLG_IN_WIDTH,
     140           1 :             THINTHICKLG_DIST_WIDTH );
     141           1 :     CPPUNIT_ASSERT_EQUAL( THINTHICK_LARGEGAP, line.GetBorderLineStyle() );
     142           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH,
     143           1 :             static_cast<long>(line.GetOutWidth()) );
     144           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_IN_WIDTH,
     145           1 :             static_cast<long>(line.GetInWidth()) );
     146           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_DIST_WIDTH,
     147           1 :             static_cast<long>(line.GetDistance()) );
     148           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH + THINTHICKLG_IN_WIDTH
     149           1 :             + THINTHICKLG_DIST_WIDTH, line.GetWidth() );
     150           1 : }
     151             : 
     152           1 : void BorderLineTest::testGuessWidthNostyleSingle()
     153             : {
     154           1 :     SvxBorderLine line;
     155           1 :     line.GuessLinesWidths( css::table::BorderLineStyle::NONE, TEST_WIDTH );
     156           1 :     CPPUNIT_ASSERT_EQUAL( SOLID, line.GetBorderLineStyle() );
     157           1 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, line.GetWidth() );
     158           1 : }
     159             : 
     160             : }
     161             : 
     162           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     163             : 
     164             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11