LCOV - code coverage report
Current view: top level - libreoffice/editeng/qa/items - borderline_test.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 76 80 95.0 %
Date: 2012-12-27 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             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License. You may obtain a copy of the License at
       8             :  * http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * The Initial Developer of the Original Code is
      16             :  *       [ insert your name / company etc. here eg. Jim Bob <jim@bob.org> ]
      17             :  * Portions created by the Initial Developer are Copyright (C) 2010 the
      18             :  * Initial Developer. All Rights Reserved.
      19             :  *
      20             :  * Contributor(s): Jim Bob <jim@bob.org>
      21             :  *                 Ted <ted@bear.com>
      22             :  *
      23             :  * Alternatively, the contents of this file may be used under the terms of
      24             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      25             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      26             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      27             :  * instead of those above.
      28             :  */
      29             : 
      30             : #include <sal/types.h>
      31             : #include <cppunit/TestFixture.h>
      32             : #include <cppunit/extensions/HelperMacros.h>
      33             : #include <cppunit/plugin/TestPlugIn.h>
      34             : 
      35             : #include <editeng/borderline.hxx>
      36             : 
      37             : using namespace ::com::sun::star::table::BorderLineStyle;
      38             : 
      39             : #define TEST_WIDTH long( 40 )
      40             : 
      41             : #define THINTHICKSG_IN_WIDTH long( 15 )
      42             : #define THINTHICKSG_OUT_WIDTH long( 40 )
      43             : #define THINTHICKSG_DIST_WIDTH long( 15 )
      44             : 
      45             : #define THINTHICKLG_IN_WIDTH long( 15 )
      46             : #define THINTHICKLG_OUT_WIDTH long( 30 )
      47             : #define THINTHICKLG_DIST_WIDTH long( 40 )
      48             : 
      49             : using namespace editeng;
      50             : 
      51             : CPPUNIT_NS_BEGIN
      52             : 
      53             : template<> struct assertion_traits<SvxBorderStyle>
      54             : {
      55           6 :     static bool equal( const SvxBorderStyle& x, const SvxBorderStyle& y )
      56             :     {
      57           6 :         return x == y;
      58             :     }
      59             : 
      60           0 :     static std::string toString( const SvxBorderStyle& x )
      61             :     {
      62           0 :         OStringStream ost;
      63           0 :         ost << static_cast<unsigned int>(x);
      64           0 :         return ost.str();
      65             :     }
      66             : };
      67             : 
      68             : CPPUNIT_NS_END
      69             : 
      70             : namespace {
      71             : 
      72          18 : class BorderLineTest : public CppUnit::TestFixture
      73             : {
      74             :     public:
      75             :         void testGuessWidthDouble();
      76             :         void testGuessWidthNoMatch();
      77             :         void testGuessWidthThinthickSmallgap();
      78             :         void testGuessWidthThinthickLargegap();
      79             :         void testGuessWidthNostyleDouble();
      80             :         void testGuessWidthNostyleSingle();
      81             : 
      82           2 :     CPPUNIT_TEST_SUITE(BorderLineTest);
      83           1 :     CPPUNIT_TEST(testGuessWidthDouble);
      84           1 :     CPPUNIT_TEST(testGuessWidthNoMatch);
      85           1 :     CPPUNIT_TEST(testGuessWidthThinthickSmallgap);
      86           1 :     CPPUNIT_TEST(testGuessWidthThinthickLargegap);
      87           1 :     CPPUNIT_TEST(testGuessWidthNostyleDouble);
      88           1 :     CPPUNIT_TEST(testGuessWidthNostyleSingle);
      89           2 :     CPPUNIT_TEST_SUITE_END();
      90             : };
      91             : 
      92           1 : CPPUNIT_TEST_SUITE_REGISTRATION(BorderLineTest);
      93             : 
      94           1 : void BorderLineTest::testGuessWidthDouble()
      95             : {
      96             :     // Normal double case
      97           1 :     SvxBorderLine line;
      98           1 :     line.GuessLinesWidths( DOUBLE, TEST_WIDTH, TEST_WIDTH, TEST_WIDTH );
      99           1 :     CPPUNIT_ASSERT_EQUAL( DOUBLE, line.GetBorderLineStyle() );
     100           1 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetOutWidth()) );
     101           1 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetInWidth()) );
     102           1 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetDistance()) );
     103           1 :     CPPUNIT_ASSERT_EQUAL( 3*TEST_WIDTH, line.GetWidth() );
     104           1 : }
     105             : 
     106           1 : void BorderLineTest::testGuessWidthNoMatch()
     107             : {
     108           1 :     SvxBorderLine line;
     109             :     line.GuessLinesWidths( DOUBLE,
     110           1 :             TEST_WIDTH + 1, TEST_WIDTH + 2, TEST_WIDTH + 3 );
     111           1 :     CPPUNIT_ASSERT_EQUAL( DOUBLE, line.GetBorderLineStyle() );
     112           1 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+1, static_cast<long>(line.GetOutWidth()) );
     113           1 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+2, static_cast<long>(line.GetInWidth()) );
     114           1 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+3, static_cast<long>(line.GetDistance()));
     115           1 :     CPPUNIT_ASSERT_EQUAL( long( (3 * TEST_WIDTH) + 6 ), line.GetWidth() );
     116           1 : }
     117             : 
     118           1 : void BorderLineTest::testGuessWidthThinthickSmallgap()
     119             : {
     120           1 :     SvxBorderLine line;
     121             :     line.GuessLinesWidths( DOUBLE,
     122             :             THINTHICKSG_OUT_WIDTH,
     123             :             THINTHICKSG_IN_WIDTH,
     124           1 :             THINTHICKSG_DIST_WIDTH );
     125           1 :     CPPUNIT_ASSERT_EQUAL( THINTHICK_SMALLGAP, line.GetBorderLineStyle() );
     126           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKSG_OUT_WIDTH,
     127           1 :             static_cast<long>(line.GetOutWidth()) );
     128           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKSG_IN_WIDTH,
     129           1 :             static_cast<long>(line.GetInWidth()) );
     130           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKSG_DIST_WIDTH,
     131           1 :             static_cast<long>(line.GetDistance()) );
     132           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKSG_OUT_WIDTH + THINTHICKSG_IN_WIDTH
     133           1 :             + THINTHICKSG_DIST_WIDTH, line.GetWidth() );
     134           1 : }
     135             : 
     136           1 : void BorderLineTest::testGuessWidthThinthickLargegap()
     137             : {
     138           1 :     SvxBorderLine line;
     139             :     line.GuessLinesWidths( DOUBLE,
     140             :             THINTHICKLG_OUT_WIDTH,
     141             :             THINTHICKLG_IN_WIDTH,
     142           1 :             THINTHICKLG_DIST_WIDTH );
     143           1 :     CPPUNIT_ASSERT_EQUAL( THINTHICK_LARGEGAP, line.GetBorderLineStyle() );
     144           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH,
     145           1 :             static_cast<long>(line.GetOutWidth()) );
     146           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_IN_WIDTH,
     147           1 :             static_cast<long>(line.GetInWidth()) );
     148           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_DIST_WIDTH,
     149           1 :             static_cast<long>(line.GetDistance()) );
     150           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH + THINTHICKLG_IN_WIDTH
     151           1 :             + THINTHICKLG_DIST_WIDTH, line.GetWidth() );
     152           1 : }
     153             : 
     154           1 : void BorderLineTest::testGuessWidthNostyleDouble()
     155             : {
     156           1 :     SvxBorderLine line;
     157             :     line.GuessLinesWidths( NONE,
     158             :             THINTHICKLG_OUT_WIDTH,
     159             :             THINTHICKLG_IN_WIDTH,
     160           1 :             THINTHICKLG_DIST_WIDTH );
     161           1 :     CPPUNIT_ASSERT_EQUAL( THINTHICK_LARGEGAP, line.GetBorderLineStyle() );
     162           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH,
     163           1 :             static_cast<long>(line.GetOutWidth()) );
     164           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_IN_WIDTH,
     165           1 :             static_cast<long>(line.GetInWidth()) );
     166           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_DIST_WIDTH,
     167           1 :             static_cast<long>(line.GetDistance()) );
     168           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH + THINTHICKLG_IN_WIDTH
     169           1 :             + THINTHICKLG_DIST_WIDTH, line.GetWidth() );
     170           1 : }
     171             : 
     172           1 : void BorderLineTest::testGuessWidthNostyleSingle()
     173             : {
     174           1 :     SvxBorderLine line;
     175           1 :     line.GuessLinesWidths( NONE, TEST_WIDTH );
     176           1 :     CPPUNIT_ASSERT_EQUAL( SOLID, line.GetBorderLineStyle() );
     177           1 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, line.GetWidth() );
     178           1 : }
     179             : 
     180             : }
     181             : 
     182           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     183             : 
     184             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10