summaryrefslogtreecommitdiff
path: root/editeng/qa
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2018-01-03 11:25:23 +0100
committerSzymon Kłos <szymon.klos@collabora.com>2018-01-07 11:15:22 +0100
commit2bd27176356c1c670fde1a59d3ffafd10ad0e4ee (patch)
tree0a20669849bd6ebad987934cb1fd44ef0019cbb0 /editeng/qa
parente1fb3d95ac6d58b60448981e82d90621cad7fea5 (diff)
tdf#114628 unit test for line spacing
* two cases 60% and 150% line spacing Change-Id: I2ce66cd19f459b738243052b5c12da0bbb883ebe Reviewed-on: https://gerrit.libreoffice.org/47303 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'editeng/qa')
-rw-r--r--editeng/qa/unit/core-test.cxx92
1 files changed, 92 insertions, 0 deletions
diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx
index c23e94a0f60f..6f527440fcca 100644
--- a/editeng/qa/unit/core-test.cxx
+++ b/editeng/qa/unit/core-test.cxx
@@ -21,6 +21,7 @@
#include <editeng/editeng.hxx>
#include <editeng/eeitem.hxx>
#include <editeng/editids.hrc>
+#include <editeng/lspcitem.hxx>
#include <editeng/svxacorr.hxx>
#include <editeng/unofield.hxx>
#include <editeng/wghtitem.hxx>
@@ -30,6 +31,8 @@
#include <editeng/flditem.hxx>
#include <editeng/udlnitem.hxx>
#include <svl/srchitem.hxx>
+#include <editeng/fontitem.hxx>
+#include <editeng/fhgtitem.hxx>
#include <com/sun/star/text/textfield/Type.hpp>
@@ -48,6 +51,9 @@ public:
virtual void setUp() override;
virtual void tearDown() override;
+ /// Test text portions position when percentage line spacing is set
+ void testLineSpacing();
+
void testConstruction();
/// Test UNO service class that implements text field items.
@@ -94,6 +100,7 @@ public:
DECL_STATIC_LINK( Test, CalcFieldValueHdl, EditFieldInfo*, void );
CPPUNIT_TEST_SUITE(Test);
+ CPPUNIT_TEST(testLineSpacing);
CPPUNIT_TEST(testConstruction);
CPPUNIT_TEST(testUnoTextFields);
CPPUNIT_TEST(testAutocorrect);
@@ -133,6 +140,91 @@ void Test::tearDown()
test::BootstrapFixture::tearDown();
}
+void Test::testLineSpacing()
+{
+ // Create EditEngine's instance
+ EditEngine aEditEngine(mpItemPool);
+
+ if(aEditEngine.GetRefDevice()->GetDPIY() != 96
+ || aEditEngine.GetRefDevice()->GetDPIScaleFactor() != 1.0)
+ return;
+
+ // Get EditDoc for current EditEngine's instance
+ EditDoc &rDoc = aEditEngine.GetEditDoc();
+
+ // Initially no text should be there
+ CPPUNIT_ASSERT_EQUAL(sal_uLong(0), rDoc.GetTextLen());
+ CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0)));
+
+ // Set initial text
+ OUString aText = "This is multi-line paragraph";
+
+ sal_Int32 aTextLen = aText.getLength();
+ aEditEngine.SetText(aText);
+
+ // Assert changes - text insertion
+ CPPUNIT_ASSERT_EQUAL(sal_uLong(aTextLen), rDoc.GetTextLen());
+ CPPUNIT_ASSERT_EQUAL(aText, rDoc.GetParaAsString(sal_Int32(0)));
+
+ // Get ItemSet for line spacing - 60%
+ std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(aEditEngine.GetEmptyItemSet()));
+ SvxLineSpacingItem aLineSpacing(LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL);
+ aLineSpacing.SetPropLineSpace(60);
+ pSet->Put(aLineSpacing);
+
+ // Set font
+ SvxFontItem aFont(EE_CHAR_FONTINFO);
+ aFont.SetFamilyName("Liberation Sans");
+ pSet->Put(aFont);
+ SvxFontHeightItem aFontSize(240, 100, EE_CHAR_FONTHEIGHT);
+ pSet->Put(aFontSize);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(3), pSet->Count());
+
+ // Select all paragraphs and set spacing
+ ESelection aSelection(0, 0, 0, aTextLen);
+ aEditEngine.QuickSetAttribs(*pSet, aSelection);
+
+ // Force multiple lines
+ aEditEngine.SetPaperSize(Size(1000, 6000));
+ CPPUNIT_ASSERT_EQUAL((sal_Int32)4, aEditEngine.GetLineCount(0));
+
+ // Assert changes
+ ParaPortion* pParaPortion = aEditEngine.GetParaPortions()[0];
+ ContentNode* const pNode = pParaPortion->GetNode();
+ const SvxLineSpacingItem& rLSItem = pNode->GetContentAttribs().GetItem(EE_PARA_SBL);
+ CPPUNIT_ASSERT_EQUAL(SvxInterLineSpaceRule::Prop, rLSItem.GetInterLineSpaceRule());
+ CPPUNIT_ASSERT_EQUAL((sal_uInt16)60, rLSItem.GetPropLineSpace());
+
+ // Check the first line
+ ParagraphInfos aInfo = aEditEngine.GetParagraphInfos(0);
+ CPPUNIT_ASSERT_EQUAL((sal_uInt16)122, aInfo.nFirstLineMaxAscent);
+ CPPUNIT_ASSERT_EQUAL((sal_uInt16)153, (sal_uInt16)aEditEngine.GetLineHeight(0));
+
+ // Prepare second case - 150%
+ std::unique_ptr<SfxItemSet> pSet2(new SfxItemSet(aEditEngine.GetEmptyItemSet()));
+ SvxLineSpacingItem aLineSpacing2(LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL);
+ aLineSpacing2.SetPropLineSpace(150);
+ pSet2->Put(aLineSpacing2);
+ pSet2->Put(aFont);
+ pSet2->Put(aFontSize);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(3), pSet2->Count());
+
+ // Select all paragraphs and set spacing
+ aEditEngine.QuickSetAttribs(*pSet2, aSelection);
+
+ // Assert changes
+ const SvxLineSpacingItem& rLSItem2 = pNode->GetContentAttribs().GetItem(EE_PARA_SBL);
+ CPPUNIT_ASSERT_EQUAL(SvxInterLineSpaceRule::Prop, rLSItem2.GetInterLineSpaceRule());
+ CPPUNIT_ASSERT_EQUAL((sal_uInt16)150, rLSItem2.GetPropLineSpace());
+
+ // Check the first line
+ ParagraphInfos aInfo2 = aEditEngine.GetParagraphInfos(0);
+ CPPUNIT_ASSERT_EQUAL((sal_uInt16)269, aInfo2.nFirstLineMaxAscent);
+ CPPUNIT_ASSERT_EQUAL((sal_uInt16)382, (sal_uInt16)aEditEngine.GetLineHeight(0));
+}
+
void Test::testConstruction()
{
EditEngine aEngine(mpItemPool);