1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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 tools::Long( 40 )
21 #define THINTHICKSG_IN_WIDTH tools::Long( 15 )
22 #define THINTHICKSG_OUT_WIDTH tools::Long( 40 )
23 #define THINTHICKSG_DIST_WIDTH tools::Long( 15 )
25 #define THINTHICKLG_IN_WIDTH tools::Long( 15 )
26 #define THINTHICKLG_OUT_WIDTH tools::Long( 30 )
27 #define THINTHICKLG_DIST_WIDTH tools::Long( 40 )
29 using namespace editeng
;
31 template<> inline std::string
CPPUNIT_NS::assertion_traits
<SvxBorderLineStyle
>::toString(
32 SvxBorderLineStyle
const & x
)
35 ost
<< static_cast<unsigned int>(x
);
41 class BorderLineTest
: public CppUnit::TestFixture
44 void testGuessWidthDouble();
45 void testGuessWidthNoMatch();
46 void testGuessWidthThinthickSmallgap();
47 void testGuessWidthThinthickLargegap();
48 void testGuessWidthNostyleDouble();
49 void testGuessWidthNostyleSingle();
51 CPPUNIT_TEST_SUITE(BorderLineTest
);
52 CPPUNIT_TEST(testGuessWidthDouble
);
53 CPPUNIT_TEST(testGuessWidthNoMatch
);
54 CPPUNIT_TEST(testGuessWidthThinthickSmallgap
);
55 CPPUNIT_TEST(testGuessWidthThinthickLargegap
);
56 CPPUNIT_TEST(testGuessWidthNostyleDouble
);
57 CPPUNIT_TEST(testGuessWidthNostyleSingle
);
58 CPPUNIT_TEST_SUITE_END();
61 CPPUNIT_TEST_SUITE_REGISTRATION(BorderLineTest
);
63 void BorderLineTest::testGuessWidthDouble()
67 line
.GuessLinesWidths( SvxBorderLineStyle::DOUBLE
, TEST_WIDTH
, TEST_WIDTH
, TEST_WIDTH
);
68 CPPUNIT_ASSERT_EQUAL( SvxBorderLineStyle::DOUBLE
, line
.GetBorderLineStyle() );
69 CPPUNIT_ASSERT_EQUAL( TEST_WIDTH
, static_cast<tools::Long
>(line
.GetOutWidth()) );
70 CPPUNIT_ASSERT_EQUAL( TEST_WIDTH
, static_cast<tools::Long
>(line
.GetInWidth()) );
71 CPPUNIT_ASSERT_EQUAL( TEST_WIDTH
, static_cast<tools::Long
>(line
.GetDistance()) );
72 CPPUNIT_ASSERT_EQUAL( 3*TEST_WIDTH
, line
.GetWidth() );
75 void BorderLineTest::testGuessWidthNoMatch()
78 line
.GuessLinesWidths( SvxBorderLineStyle::DOUBLE
,
79 TEST_WIDTH
+ 1, TEST_WIDTH
+ 2, TEST_WIDTH
+ 3 );
80 CPPUNIT_ASSERT_EQUAL( SvxBorderLineStyle::DOUBLE
, line
.GetBorderLineStyle() );
81 CPPUNIT_ASSERT_EQUAL( TEST_WIDTH
+1, static_cast<tools::Long
>(line
.GetOutWidth()) );
82 CPPUNIT_ASSERT_EQUAL( TEST_WIDTH
+2, static_cast<tools::Long
>(line
.GetInWidth()) );
83 CPPUNIT_ASSERT_EQUAL( TEST_WIDTH
+3, static_cast<tools::Long
>(line
.GetDistance()));
84 CPPUNIT_ASSERT_EQUAL( tools::Long( (3 * TEST_WIDTH
) + 6 ), line
.GetWidth() );
87 void BorderLineTest::testGuessWidthThinthickSmallgap()
90 line
.GuessLinesWidths( SvxBorderLineStyle::DOUBLE
,
91 THINTHICKSG_OUT_WIDTH
,
93 THINTHICKSG_DIST_WIDTH
);
94 CPPUNIT_ASSERT_EQUAL( SvxBorderLineStyle::THINTHICK_SMALLGAP
, line
.GetBorderLineStyle() );
95 CPPUNIT_ASSERT_EQUAL( THINTHICKSG_OUT_WIDTH
,
96 static_cast<tools::Long
>(line
.GetOutWidth()) );
97 CPPUNIT_ASSERT_EQUAL( THINTHICKSG_IN_WIDTH
,
98 static_cast<tools::Long
>(line
.GetInWidth()) );
99 CPPUNIT_ASSERT_EQUAL( THINTHICKSG_DIST_WIDTH
,
100 static_cast<tools::Long
>(line
.GetDistance()) );
101 CPPUNIT_ASSERT_EQUAL( THINTHICKSG_OUT_WIDTH
+ THINTHICKSG_IN_WIDTH
102 + THINTHICKSG_DIST_WIDTH
, line
.GetWidth() );
105 void BorderLineTest::testGuessWidthThinthickLargegap()
108 line
.GuessLinesWidths( SvxBorderLineStyle::DOUBLE
,
109 THINTHICKLG_OUT_WIDTH
,
110 THINTHICKLG_IN_WIDTH
,
111 THINTHICKLG_DIST_WIDTH
);
112 CPPUNIT_ASSERT_EQUAL( SvxBorderLineStyle::THINTHICK_LARGEGAP
, line
.GetBorderLineStyle() );
113 CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH
,
114 static_cast<tools::Long
>(line
.GetOutWidth()) );
115 CPPUNIT_ASSERT_EQUAL( THINTHICKLG_IN_WIDTH
,
116 static_cast<tools::Long
>(line
.GetInWidth()) );
117 CPPUNIT_ASSERT_EQUAL( THINTHICKLG_DIST_WIDTH
,
118 static_cast<tools::Long
>(line
.GetDistance()) );
119 CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH
+ THINTHICKLG_IN_WIDTH
120 + THINTHICKLG_DIST_WIDTH
, line
.GetWidth() );
123 void BorderLineTest::testGuessWidthNostyleDouble()
126 line
.GuessLinesWidths( SvxBorderLineStyle::NONE
,
127 THINTHICKLG_OUT_WIDTH
,
128 THINTHICKLG_IN_WIDTH
,
129 THINTHICKLG_DIST_WIDTH
);
130 CPPUNIT_ASSERT_EQUAL( SvxBorderLineStyle::THINTHICK_LARGEGAP
, line
.GetBorderLineStyle() );
131 CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH
,
132 static_cast<tools::Long
>(line
.GetOutWidth()) );
133 CPPUNIT_ASSERT_EQUAL( THINTHICKLG_IN_WIDTH
,
134 static_cast<tools::Long
>(line
.GetInWidth()) );
135 CPPUNIT_ASSERT_EQUAL( THINTHICKLG_DIST_WIDTH
,
136 static_cast<tools::Long
>(line
.GetDistance()) );
137 CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH
+ THINTHICKLG_IN_WIDTH
138 + THINTHICKLG_DIST_WIDTH
, line
.GetWidth() );
141 void BorderLineTest::testGuessWidthNostyleSingle()
144 line
.GuessLinesWidths( SvxBorderLineStyle::NONE
, TEST_WIDTH
);
145 CPPUNIT_ASSERT_EQUAL( SvxBorderLineStyle::SOLID
, line
.GetBorderLineStyle() );
146 CPPUNIT_ASSERT_EQUAL( TEST_WIDTH
, line
.GetWidth() );
151 CPPUNIT_PLUGIN_IMPLEMENT();
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */