Bump version to 4.1-6
[LibreOffice.git] / editeng / qa / items / borderline_test.cxx
blob14322762081d7fb17dbd4102fa3cb3ccf303bc1c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <sal/types.h>
11 #include <cppunit/TestFixture.h>
12 #include <cppunit/extensions/HelperMacros.h>
13 #include <cppunit/plugin/TestPlugIn.h>
15 #include <editeng/borderline.hxx>
17 using namespace ::com::sun::star::table::BorderLineStyle;
19 #define TEST_WIDTH long( 40 )
21 #define THINTHICKSG_IN_WIDTH long( 15 )
22 #define THINTHICKSG_OUT_WIDTH long( 40 )
23 #define THINTHICKSG_DIST_WIDTH long( 15 )
25 #define THINTHICKLG_IN_WIDTH long( 15 )
26 #define THINTHICKLG_OUT_WIDTH long( 30 )
27 #define THINTHICKLG_DIST_WIDTH long( 40 )
29 using namespace editeng;
31 CPPUNIT_NS_BEGIN
33 template<> struct assertion_traits<SvxBorderStyle>
35 static bool equal( const SvxBorderStyle& x, const SvxBorderStyle& y )
37 return x == y;
40 static std::string toString( const SvxBorderStyle& x )
42 OStringStream ost;
43 ost << static_cast<unsigned int>(x);
44 return ost.str();
48 CPPUNIT_NS_END
50 namespace {
52 class BorderLineTest : public CppUnit::TestFixture
54 public:
55 void testGuessWidthDouble();
56 void testGuessWidthNoMatch();
57 void testGuessWidthThinthickSmallgap();
58 void testGuessWidthThinthickLargegap();
59 void testGuessWidthNostyleDouble();
60 void testGuessWidthNostyleSingle();
62 CPPUNIT_TEST_SUITE(BorderLineTest);
63 CPPUNIT_TEST(testGuessWidthDouble);
64 CPPUNIT_TEST(testGuessWidthNoMatch);
65 CPPUNIT_TEST(testGuessWidthThinthickSmallgap);
66 CPPUNIT_TEST(testGuessWidthThinthickLargegap);
67 CPPUNIT_TEST(testGuessWidthNostyleDouble);
68 CPPUNIT_TEST(testGuessWidthNostyleSingle);
69 CPPUNIT_TEST_SUITE_END();
72 CPPUNIT_TEST_SUITE_REGISTRATION(BorderLineTest);
74 void BorderLineTest::testGuessWidthDouble()
76 // Normal double case
77 SvxBorderLine line;
78 line.GuessLinesWidths( DOUBLE, TEST_WIDTH, TEST_WIDTH, TEST_WIDTH );
79 CPPUNIT_ASSERT_EQUAL( DOUBLE, line.GetBorderLineStyle() );
80 CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetOutWidth()) );
81 CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetInWidth()) );
82 CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetDistance()) );
83 CPPUNIT_ASSERT_EQUAL( 3*TEST_WIDTH, line.GetWidth() );
86 void BorderLineTest::testGuessWidthNoMatch()
88 SvxBorderLine line;
89 line.GuessLinesWidths( DOUBLE,
90 TEST_WIDTH + 1, TEST_WIDTH + 2, TEST_WIDTH + 3 );
91 CPPUNIT_ASSERT_EQUAL( DOUBLE, line.GetBorderLineStyle() );
92 CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+1, static_cast<long>(line.GetOutWidth()) );
93 CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+2, static_cast<long>(line.GetInWidth()) );
94 CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+3, static_cast<long>(line.GetDistance()));
95 CPPUNIT_ASSERT_EQUAL( long( (3 * TEST_WIDTH) + 6 ), line.GetWidth() );
98 void BorderLineTest::testGuessWidthThinthickSmallgap()
100 SvxBorderLine line;
101 line.GuessLinesWidths( DOUBLE,
102 THINTHICKSG_OUT_WIDTH,
103 THINTHICKSG_IN_WIDTH,
104 THINTHICKSG_DIST_WIDTH );
105 CPPUNIT_ASSERT_EQUAL( THINTHICK_SMALLGAP, line.GetBorderLineStyle() );
106 CPPUNIT_ASSERT_EQUAL( THINTHICKSG_OUT_WIDTH,
107 static_cast<long>(line.GetOutWidth()) );
108 CPPUNIT_ASSERT_EQUAL( THINTHICKSG_IN_WIDTH,
109 static_cast<long>(line.GetInWidth()) );
110 CPPUNIT_ASSERT_EQUAL( THINTHICKSG_DIST_WIDTH,
111 static_cast<long>(line.GetDistance()) );
112 CPPUNIT_ASSERT_EQUAL( THINTHICKSG_OUT_WIDTH + THINTHICKSG_IN_WIDTH
113 + THINTHICKSG_DIST_WIDTH, line.GetWidth() );
116 void BorderLineTest::testGuessWidthThinthickLargegap()
118 SvxBorderLine line;
119 line.GuessLinesWidths( DOUBLE,
120 THINTHICKLG_OUT_WIDTH,
121 THINTHICKLG_IN_WIDTH,
122 THINTHICKLG_DIST_WIDTH );
123 CPPUNIT_ASSERT_EQUAL( THINTHICK_LARGEGAP, line.GetBorderLineStyle() );
124 CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH,
125 static_cast<long>(line.GetOutWidth()) );
126 CPPUNIT_ASSERT_EQUAL( THINTHICKLG_IN_WIDTH,
127 static_cast<long>(line.GetInWidth()) );
128 CPPUNIT_ASSERT_EQUAL( THINTHICKLG_DIST_WIDTH,
129 static_cast<long>(line.GetDistance()) );
130 CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH + THINTHICKLG_IN_WIDTH
131 + THINTHICKLG_DIST_WIDTH, line.GetWidth() );
134 void BorderLineTest::testGuessWidthNostyleDouble()
136 SvxBorderLine line;
137 line.GuessLinesWidths( NONE,
138 THINTHICKLG_OUT_WIDTH,
139 THINTHICKLG_IN_WIDTH,
140 THINTHICKLG_DIST_WIDTH );
141 CPPUNIT_ASSERT_EQUAL( THINTHICK_LARGEGAP, line.GetBorderLineStyle() );
142 CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH,
143 static_cast<long>(line.GetOutWidth()) );
144 CPPUNIT_ASSERT_EQUAL( THINTHICKLG_IN_WIDTH,
145 static_cast<long>(line.GetInWidth()) );
146 CPPUNIT_ASSERT_EQUAL( THINTHICKLG_DIST_WIDTH,
147 static_cast<long>(line.GetDistance()) );
148 CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH + THINTHICKLG_IN_WIDTH
149 + THINTHICKLG_DIST_WIDTH, line.GetWidth() );
152 void BorderLineTest::testGuessWidthNostyleSingle()
154 SvxBorderLine line;
155 line.GuessLinesWidths( NONE, TEST_WIDTH );
156 CPPUNIT_ASSERT_EQUAL( SOLID, line.GetBorderLineStyle() );
157 CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, line.GetWidth() );
162 CPPUNIT_PLUGIN_IMPLEMENT();
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */