2011-01-03 14:08:36 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
2013-04-24 17:14:03 +01:00
|
|
|
* This file is part of the LibreOffice project.
|
2011-01-03 14:08:36 +01:00
|
|
|
*
|
2013-04-24 17:14:03 +01:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2011-01-03 14:08:36 +01:00
|
|
|
*/
|
|
|
|
|
2012-06-27 16:05:04 +01:00
|
|
|
#include <sal/types.h>
|
2011-01-03 14:08:36 +01:00
|
|
|
#include <cppunit/TestFixture.h>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
#include <cppunit/plugin/TestPlugIn.h>
|
|
|
|
|
|
|
|
#include <editeng/borderline.hxx>
|
|
|
|
|
2012-07-03 21:26:13 +02:00
|
|
|
using namespace ::com::sun::star::table::BorderLineStyle;
|
|
|
|
|
2011-01-04 13:41:02 +01:00
|
|
|
#define TEST_WIDTH long( 40 )
|
2011-01-03 14:08:36 +01:00
|
|
|
|
2011-01-04 13:41:02 +01:00
|
|
|
#define THINTHICKSG_IN_WIDTH long( 15 )
|
|
|
|
#define THINTHICKSG_OUT_WIDTH long( 40 )
|
|
|
|
#define THINTHICKSG_DIST_WIDTH long( 15 )
|
2011-01-03 14:08:36 +01:00
|
|
|
|
2011-01-04 13:41:02 +01:00
|
|
|
#define THINTHICKLG_IN_WIDTH long( 15 )
|
|
|
|
#define THINTHICKLG_OUT_WIDTH long( 30 )
|
|
|
|
#define THINTHICKLG_DIST_WIDTH long( 40 )
|
2011-01-03 14:08:36 +01:00
|
|
|
|
2011-03-25 15:51:50 +01:00
|
|
|
using namespace editeng;
|
|
|
|
|
2011-10-09 21:23:17 +01:00
|
|
|
CPPUNIT_NS_BEGIN
|
|
|
|
|
|
|
|
template<> struct assertion_traits<SvxBorderStyle>
|
|
|
|
{
|
|
|
|
static bool equal( const SvxBorderStyle& x, const SvxBorderStyle& y )
|
|
|
|
{
|
|
|
|
return x == y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string toString( const SvxBorderStyle& x )
|
|
|
|
{
|
|
|
|
OStringStream ost;
|
|
|
|
ost << static_cast<unsigned int>(x);
|
|
|
|
return ost.str();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
CPPUNIT_NS_END
|
|
|
|
|
2011-01-03 14:08:36 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class BorderLineTest : public CppUnit::TestFixture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void testGuessWidthDouble();
|
|
|
|
void testGuessWidthNoMatch();
|
|
|
|
void testGuessWidthThinthickSmallgap();
|
|
|
|
void testGuessWidthThinthickLargegap();
|
2011-01-07 13:40:44 +01:00
|
|
|
void testGuessWidthNostyleDouble();
|
|
|
|
void testGuessWidthNostyleSingle();
|
2011-01-03 14:08:36 +01:00
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(BorderLineTest);
|
|
|
|
CPPUNIT_TEST(testGuessWidthDouble);
|
|
|
|
CPPUNIT_TEST(testGuessWidthNoMatch);
|
|
|
|
CPPUNIT_TEST(testGuessWidthThinthickSmallgap);
|
|
|
|
CPPUNIT_TEST(testGuessWidthThinthickLargegap);
|
2011-01-07 13:40:44 +01:00
|
|
|
CPPUNIT_TEST(testGuessWidthNostyleDouble);
|
|
|
|
CPPUNIT_TEST(testGuessWidthNostyleSingle);
|
2011-01-03 14:08:36 +01:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
};
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(BorderLineTest);
|
|
|
|
|
|
|
|
void BorderLineTest::testGuessWidthDouble()
|
|
|
|
{
|
|
|
|
// Normal double case
|
|
|
|
SvxBorderLine line;
|
2011-01-07 13:40:44 +01:00
|
|
|
line.GuessLinesWidths( DOUBLE, TEST_WIDTH, TEST_WIDTH, TEST_WIDTH );
|
2012-07-03 21:26:13 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( DOUBLE, line.GetBorderLineStyle() );
|
refactor handling of double border widths:
Word uses a completely different definition of "width" of a double border
than OOo and ODF: for Word the width is apparently the largest of the 3
component widths, while OOo and ODF define the width as the total with of
all 3 components. The new border implementation in LO 3.4 was apparently
inspired by Word's double border definition, which resulted in
various import filter regressions, see the previous fixes:
36e43b52992735c622833e923faa63774b9e2f76
e2ffb71305c5f085eec6d396651c76d6daee3406
70a6a4d425558340bb49507975343a3e0a1bdde8
These fixes set the ScaleMetrics, which actually seems sub-optimal as
there is a ScaleItemSet function somewhere that apparently re-scales
all items in an itemset, which could undo the fixes.
Also, one of the fixes actually managed to break RTF/DOCX import
of double borders, as that ended up in the same code via the API.
This commit now reverses the change, so that the width of a border is
now always the total with of all components, which is (imho) much more
intutitive, and also leads to a consistent UI where selecting say 3pt
width has predictable results, no matter what the border style.
The border widths are now converted in the Word format import/export
filters (writerfilter and sw/source/filter/ww8), and various tests
were adapted to the new handling.
Change-Id: I50456c49b1a298569607e6c88f19f18441348ac3
2012-07-04 17:47:22 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetOutWidth()) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetInWidth()) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, static_cast<long>(line.GetDistance()) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 3*TEST_WIDTH, line.GetWidth() );
|
2011-01-03 14:08:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BorderLineTest::testGuessWidthNoMatch()
|
|
|
|
{
|
|
|
|
SvxBorderLine line;
|
2011-01-07 13:40:44 +01:00
|
|
|
line.GuessLinesWidths( DOUBLE,
|
2011-01-20 15:22:01 +01:00
|
|
|
TEST_WIDTH + 1, TEST_WIDTH + 2, TEST_WIDTH + 3 );
|
2012-07-03 21:26:13 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( DOUBLE, line.GetBorderLineStyle() );
|
refactor handling of double border widths:
Word uses a completely different definition of "width" of a double border
than OOo and ODF: for Word the width is apparently the largest of the 3
component widths, while OOo and ODF define the width as the total with of
all 3 components. The new border implementation in LO 3.4 was apparently
inspired by Word's double border definition, which resulted in
various import filter regressions, see the previous fixes:
36e43b52992735c622833e923faa63774b9e2f76
e2ffb71305c5f085eec6d396651c76d6daee3406
70a6a4d425558340bb49507975343a3e0a1bdde8
These fixes set the ScaleMetrics, which actually seems sub-optimal as
there is a ScaleItemSet function somewhere that apparently re-scales
all items in an itemset, which could undo the fixes.
Also, one of the fixes actually managed to break RTF/DOCX import
of double borders, as that ended up in the same code via the API.
This commit now reverses the change, so that the width of a border is
now always the total with of all components, which is (imho) much more
intutitive, and also leads to a consistent UI where selecting say 3pt
width has predictable results, no matter what the border style.
The border widths are now converted in the Word format import/export
filters (writerfilter and sw/source/filter/ww8), and various tests
were adapted to the new handling.
Change-Id: I50456c49b1a298569607e6c88f19f18441348ac3
2012-07-04 17:47:22 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+1, static_cast<long>(line.GetOutWidth()) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+2, static_cast<long>(line.GetInWidth()) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( TEST_WIDTH+3, static_cast<long>(line.GetDistance()));
|
2012-01-25 22:43:39 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( long( (3 * TEST_WIDTH) + 6 ), line.GetWidth() );
|
2011-01-03 14:08:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BorderLineTest::testGuessWidthThinthickSmallgap()
|
|
|
|
{
|
|
|
|
SvxBorderLine line;
|
2011-01-07 13:40:44 +01:00
|
|
|
line.GuessLinesWidths( DOUBLE,
|
2011-01-03 14:08:36 +01:00
|
|
|
THINTHICKSG_OUT_WIDTH,
|
2011-01-07 13:40:44 +01:00
|
|
|
THINTHICKSG_IN_WIDTH,
|
2011-01-03 14:08:36 +01:00
|
|
|
THINTHICKSG_DIST_WIDTH );
|
2012-07-03 21:26:13 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( THINTHICK_SMALLGAP, line.GetBorderLineStyle() );
|
refactor handling of double border widths:
Word uses a completely different definition of "width" of a double border
than OOo and ODF: for Word the width is apparently the largest of the 3
component widths, while OOo and ODF define the width as the total with of
all 3 components. The new border implementation in LO 3.4 was apparently
inspired by Word's double border definition, which resulted in
various import filter regressions, see the previous fixes:
36e43b52992735c622833e923faa63774b9e2f76
e2ffb71305c5f085eec6d396651c76d6daee3406
70a6a4d425558340bb49507975343a3e0a1bdde8
These fixes set the ScaleMetrics, which actually seems sub-optimal as
there is a ScaleItemSet function somewhere that apparently re-scales
all items in an itemset, which could undo the fixes.
Also, one of the fixes actually managed to break RTF/DOCX import
of double borders, as that ended up in the same code via the API.
This commit now reverses the change, so that the width of a border is
now always the total with of all components, which is (imho) much more
intutitive, and also leads to a consistent UI where selecting say 3pt
width has predictable results, no matter what the border style.
The border widths are now converted in the Word format import/export
filters (writerfilter and sw/source/filter/ww8), and various tests
were adapted to the new handling.
Change-Id: I50456c49b1a298569607e6c88f19f18441348ac3
2012-07-04 17:47:22 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( THINTHICKSG_OUT_WIDTH,
|
|
|
|
static_cast<long>(line.GetOutWidth()) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( THINTHICKSG_IN_WIDTH,
|
|
|
|
static_cast<long>(line.GetInWidth()) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( THINTHICKSG_DIST_WIDTH,
|
|
|
|
static_cast<long>(line.GetDistance()) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( THINTHICKSG_OUT_WIDTH + THINTHICKSG_IN_WIDTH
|
|
|
|
+ THINTHICKSG_DIST_WIDTH, line.GetWidth() );
|
2011-01-03 14:08:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BorderLineTest::testGuessWidthThinthickLargegap()
|
|
|
|
{
|
|
|
|
SvxBorderLine line;
|
2011-01-07 13:40:44 +01:00
|
|
|
line.GuessLinesWidths( DOUBLE,
|
|
|
|
THINTHICKLG_OUT_WIDTH,
|
2011-01-03 14:08:36 +01:00
|
|
|
THINTHICKLG_IN_WIDTH,
|
2011-01-07 13:40:44 +01:00
|
|
|
THINTHICKLG_DIST_WIDTH );
|
2012-07-03 21:26:13 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( THINTHICK_LARGEGAP, line.GetBorderLineStyle() );
|
refactor handling of double border widths:
Word uses a completely different definition of "width" of a double border
than OOo and ODF: for Word the width is apparently the largest of the 3
component widths, while OOo and ODF define the width as the total with of
all 3 components. The new border implementation in LO 3.4 was apparently
inspired by Word's double border definition, which resulted in
various import filter regressions, see the previous fixes:
36e43b52992735c622833e923faa63774b9e2f76
e2ffb71305c5f085eec6d396651c76d6daee3406
70a6a4d425558340bb49507975343a3e0a1bdde8
These fixes set the ScaleMetrics, which actually seems sub-optimal as
there is a ScaleItemSet function somewhere that apparently re-scales
all items in an itemset, which could undo the fixes.
Also, one of the fixes actually managed to break RTF/DOCX import
of double borders, as that ended up in the same code via the API.
This commit now reverses the change, so that the width of a border is
now always the total with of all components, which is (imho) much more
intutitive, and also leads to a consistent UI where selecting say 3pt
width has predictable results, no matter what the border style.
The border widths are now converted in the Word format import/export
filters (writerfilter and sw/source/filter/ww8), and various tests
were adapted to the new handling.
Change-Id: I50456c49b1a298569607e6c88f19f18441348ac3
2012-07-04 17:47:22 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH,
|
|
|
|
static_cast<long>(line.GetOutWidth()) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( THINTHICKLG_IN_WIDTH,
|
|
|
|
static_cast<long>(line.GetInWidth()) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( THINTHICKLG_DIST_WIDTH,
|
|
|
|
static_cast<long>(line.GetDistance()) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH + THINTHICKLG_IN_WIDTH
|
|
|
|
+ THINTHICKLG_DIST_WIDTH, line.GetWidth() );
|
2011-01-07 13:40:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BorderLineTest::testGuessWidthNostyleDouble()
|
|
|
|
{
|
|
|
|
SvxBorderLine line;
|
2014-10-06 14:48:16 +02:00
|
|
|
line.GuessLinesWidths( css::table::BorderLineStyle::NONE,
|
2011-01-03 14:08:36 +01:00
|
|
|
THINTHICKLG_OUT_WIDTH,
|
2011-01-07 13:40:44 +01:00
|
|
|
THINTHICKLG_IN_WIDTH,
|
2011-01-03 14:08:36 +01:00
|
|
|
THINTHICKLG_DIST_WIDTH );
|
2012-07-03 21:26:13 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( THINTHICK_LARGEGAP, line.GetBorderLineStyle() );
|
refactor handling of double border widths:
Word uses a completely different definition of "width" of a double border
than OOo and ODF: for Word the width is apparently the largest of the 3
component widths, while OOo and ODF define the width as the total with of
all 3 components. The new border implementation in LO 3.4 was apparently
inspired by Word's double border definition, which resulted in
various import filter regressions, see the previous fixes:
36e43b52992735c622833e923faa63774b9e2f76
e2ffb71305c5f085eec6d396651c76d6daee3406
70a6a4d425558340bb49507975343a3e0a1bdde8
These fixes set the ScaleMetrics, which actually seems sub-optimal as
there is a ScaleItemSet function somewhere that apparently re-scales
all items in an itemset, which could undo the fixes.
Also, one of the fixes actually managed to break RTF/DOCX import
of double borders, as that ended up in the same code via the API.
This commit now reverses the change, so that the width of a border is
now always the total with of all components, which is (imho) much more
intutitive, and also leads to a consistent UI where selecting say 3pt
width has predictable results, no matter what the border style.
The border widths are now converted in the Word format import/export
filters (writerfilter and sw/source/filter/ww8), and various tests
were adapted to the new handling.
Change-Id: I50456c49b1a298569607e6c88f19f18441348ac3
2012-07-04 17:47:22 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH,
|
|
|
|
static_cast<long>(line.GetOutWidth()) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( THINTHICKLG_IN_WIDTH,
|
|
|
|
static_cast<long>(line.GetInWidth()) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( THINTHICKLG_DIST_WIDTH,
|
|
|
|
static_cast<long>(line.GetDistance()) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( THINTHICKLG_OUT_WIDTH + THINTHICKLG_IN_WIDTH
|
|
|
|
+ THINTHICKLG_DIST_WIDTH, line.GetWidth() );
|
2011-01-03 14:08:36 +01:00
|
|
|
}
|
|
|
|
|
2011-01-07 13:40:44 +01:00
|
|
|
void BorderLineTest::testGuessWidthNostyleSingle()
|
|
|
|
{
|
|
|
|
SvxBorderLine line;
|
2014-10-06 14:48:16 +02:00
|
|
|
line.GuessLinesWidths( css::table::BorderLineStyle::NONE, TEST_WIDTH );
|
2012-07-03 21:26:13 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL( SOLID, line.GetBorderLineStyle() );
|
2011-01-07 13:40:44 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( TEST_WIDTH, line.GetWidth() );
|
|
|
|
}
|
|
|
|
|
2011-01-03 14:08:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|