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-17 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          12 :     static bool equal( const SvxBorderStyle& x, const SvxBorderStyle& y )
      56             :     {
      57          12 :         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          36 : 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           4 :     CPPUNIT_TEST_SUITE(BorderLineTest);
      83           2 :     CPPUNIT_TEST(testGuessWidthDouble);
      84           2 :     CPPUNIT_TEST(testGuessWidthNoMatch);
      85           2 :     CPPUNIT_TEST(testGuessWidthThinthickSmallgap);
      86           2 :     CPPUNIT_TEST(testGuessWidthThinthickLargegap);
      87           2 :     CPPUNIT_TEST(testGuessWidthNostyleDouble);
      88           2 :     CPPUNIT_TEST(testGuessWidthNostyleSingle);
      89           4 :     CPPUNIT_TEST_SUITE_END();
      90             : };
      91             : 
      92           2 : CPPUNIT_TEST_SUITE_REGISTRATION(BorderLineTest);
      93             : 
      94           2 : void BorderLineTest::testGuessWidthDouble()
      95             : {
      96             :     // Normal double case
      97           2 :     SvxBorderLine line;
      98           2 :     line.GuessLinesWidths( DOUBLE, TEST_WIDTH, TEST_WIDTH, TEST_WIDTH );
      99           2 :     CPPUNIT_ASSERT_EQUAL( DOUBLE, line.GetBorderLineStyle() );
     100           2 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetOutWidth()) );
     101           2 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetInWidth()) );
     102           2 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetDistance()) );
     103           2 :     CPPUNIT_ASSERT_EQUAL( 3*TEST_WIDTH, line.GetWidth() );
     104           2 : }
     105             : 
     106           2 : void BorderLineTest::testGuessWidthNoMatch()
     107             : {
     108           2 :     SvxBorderLine line;
     109             :     line.GuessLinesWidths( DOUBLE,
     110           2 :             TEST_WIDTH + 1, TEST_WIDTH + 2, TEST_WIDTH + 3 );
     111           2 :     CPPUNIT_ASSERT_EQUAL( DOUBLE, line.GetBorderLineStyle() );
     112           2 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+1, static_cast<long>(line.GetOutWidth()) );
     113           2 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+2, static_cast<long>(line.GetInWidth()) );
     114           2 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+3, static_cast<long>(line.GetDistance()));
     115           2 :     CPPUNIT_ASSERT_EQUAL( long( (3 * TEST_WIDTH) + 6 ), line.GetWidth() );
     116           2 : }
     117             : 
     118           2 : void BorderLineTest::testGuessWidthThinthickSmallgap()
     119             : {
     120           2 :     SvxBorderLine line;
     121             :     line.GuessLinesWidths( DOUBLE,
     122             :             THINTHICKSG_OUT_WIDTH,
     123             :             THINTHICKSG_IN_WIDTH,
     124           2 :             THINTHICKSG_DIST_WIDTH );
     125           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICK_SMALLGAP, line.GetBorderLineStyle() );
     126           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKSG_OUT_WIDTH,
     127           2 :             static_cast<long>(line.GetOutWidth()) );
     128           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKSG_IN_WIDTH,
     129           2 :             static_cast<long>(line.GetInWidth()) );
     130           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKSG_DIST_WIDTH,
     131           2 :             static_cast<long>(line.GetDistance()) );
     132           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKSG_OUT_WIDTH + THINTHICKSG_IN_WIDTH
     133           2 :             + THINTHICKSG_DIST_WIDTH, line.GetWidth() );
     134           2 : }
     135             : 
     136           2 : void BorderLineTest::testGuessWidthThinthickLargegap()
     137             : {
     138           2 :     SvxBorderLine line;
     139             :     line.GuessLinesWidths( DOUBLE,
     140             :             THINTHICKLG_OUT_WIDTH,
     141             :             THINTHICKLG_IN_WIDTH,
     142           2 :             THINTHICKLG_DIST_WIDTH );
     143           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICK_LARGEGAP, line.GetBorderLineStyle() );
     144           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH,
     145           2 :             static_cast<long>(line.GetOutWidth()) );
     146           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_IN_WIDTH,
     147           2 :             static_cast<long>(line.GetInWidth()) );
     148           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_DIST_WIDTH,
     149           2 :             static_cast<long>(line.GetDistance()) );
     150           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH + THINTHICKLG_IN_WIDTH
     151           2 :             + THINTHICKLG_DIST_WIDTH, line.GetWidth() );
     152           2 : }
     153             : 
     154           2 : void BorderLineTest::testGuessWidthNostyleDouble()
     155             : {
     156           2 :     SvxBorderLine line;
     157             :     line.GuessLinesWidths( NONE,
     158             :             THINTHICKLG_OUT_WIDTH,
     159             :             THINTHICKLG_IN_WIDTH,
     160           2 :             THINTHICKLG_DIST_WIDTH );
     161           2 :     CPPUNIT_ASSERT_EQUAL( THINTHICK_LARGEGAP, line.GetBorderLineStyle() );
     162           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH,
     163           2 :             static_cast<long>(line.GetOutWidth()) );
     164           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_IN_WIDTH,
     165           2 :             static_cast<long>(line.GetInWidth()) );
     166           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_DIST_WIDTH,
     167           2 :             static_cast<long>(line.GetDistance()) );
     168           4 :     CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH + THINTHICKLG_IN_WIDTH
     169           2 :             + THINTHICKLG_DIST_WIDTH, line.GetWidth() );
     170           2 : }
     171             : 
     172           2 : void BorderLineTest::testGuessWidthNostyleSingle()
     173             : {
     174           2 :     SvxBorderLine line;
     175           2 :     line.GuessLinesWidths( NONE, TEST_WIDTH );
     176           2 :     CPPUNIT_ASSERT_EQUAL( SOLID, line.GetBorderLineStyle() );
     177           2 :     CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, line.GetWidth() );
     178           2 : }
     179             : 
     180             : }
     181             : 
     182           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     183             : 
     184             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10