editeng/CppunitTest_editeng_core.mk | 1 editeng/qa/unit/core-test.cxx | 74 ++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+)
New commits: commit 67abfa11b611dc4ed98a660ec238fe76475200fa Author: Tomaž Vajngerl <[email protected]> AuthorDate: Fri Jan 12 12:56:00 2024 +0900 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Sun Jan 14 04:51:36 2024 +0100 editeng: add simple test for CreateLines method Change-Id: I4fd13727a1edc20220a95dd4899b91bdef088111 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162011 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/editeng/CppunitTest_editeng_core.mk b/editeng/CppunitTest_editeng_core.mk index 3fc6d9bde688..9352ddbd83e2 100644 --- a/editeng/CppunitTest_editeng_core.mk +++ b/editeng/CppunitTest_editeng_core.mk @@ -56,6 +56,7 @@ $(eval $(call gb_CppunitTest_use_externals,editeng_core,\ $(eval $(call gb_CppunitTest_set_include,editeng_core,\ -I$(SRCDIR)/editeng/inc \ + -I$(SRCDIR)/editeng/source/editeng \ $$(INCLUDE) \ )) diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx index c17fccf1caef..e0fb7ada253c 100644 --- a/editeng/qa/unit/core-test.cxx +++ b/editeng/qa/unit/core-test.cxx @@ -14,6 +14,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <editdoc.hxx> +#include <impedit.hxx> #include <sfx2/app.hxx> #include <svl/itempool.hxx> @@ -114,6 +115,7 @@ public: void testSingleLine(); void testMoveParagraph(); + void testCreateLines(); DECL_STATIC_LINK( Test, CalcFieldValueHdl, EditFieldInfo*, void ); @@ -141,6 +143,7 @@ public: CPPUNIT_TEST(testTdf148148); CPPUNIT_TEST(testSingleLine); CPPUNIT_TEST(testMoveParagraph); + CPPUNIT_TEST(testCreateLines); CPPUNIT_TEST_SUITE_END(); private: @@ -2073,6 +2076,77 @@ void Test::testMoveParagraph() CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 5"), aEditEngine.GetText(4)); } +void Test::testCreateLines() +{ + ScopedVclPtrInstance<VirtualDevice> pVirtualDevice(DeviceFormat::WITHOUT_ALPHA); + + EditEngine aEditEngine(mpItemPool.get()); + aEditEngine.SetRefDevice(pVirtualDevice.get()); + aEditEngine.SetPaperSize(Size(500, 500)); + aEditEngine.SetText("ABC ABC DEF ABC DEFGH"); + + CPPUNIT_ASSERT_EQUAL(true, aEditEngine.IsFormatted()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aEditEngine.GetParagraphCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aEditEngine.GetLineCount(0)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aEditEngine.GetLineCount(1)); + + ParaPortionList& rParagraphPortionList = aEditEngine.GetParaPortions(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), rParagraphPortionList.Count()); + + { + EditLineList& rLines = rParagraphPortionList[0]->GetLines(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), rLines.Count()); + EditLine const& rLine = rLines[0]; + + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rLine.GetStart()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), rLine.GetEnd()); + + std::vector<sal_Int32> const& rArray = rLine.GetCharPosArray(); + CPPUNIT_ASSERT_EQUAL(size_t(3), rArray.size()); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(173), rArray[0]); + CPPUNIT_ASSERT_EQUAL(sal_Int32(333), rArray[1]); + CPPUNIT_ASSERT_EQUAL(sal_Int32(493), rArray[2]); + } + + { + EditLineList& rLines = rParagraphPortionList[1]->GetLines(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), rLines.Count()); + + { + EditLine const& rLine = rLines[0]; + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rLine.GetStart()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), rLine.GetEnd()); + } + + { + EditLine const& rLine = rLines[1]; + CPPUNIT_ASSERT_EQUAL(sal_Int32(4), rLine.GetStart()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(8), rLine.GetEnd()); + } + + { + EditLine const& rLine = rLines[2]; + CPPUNIT_ASSERT_EQUAL(sal_Int32(8), rLine.GetStart()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(12), rLine.GetEnd()); + } + + { + EditLine const& rLine = rLines[3]; + CPPUNIT_ASSERT_EQUAL(sal_Int32(12), rLine.GetStart()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(15), rLine.GetEnd()); + } + + { + EditLine const& rLine = rLines[4]; + CPPUNIT_ASSERT_EQUAL(sal_Int32(15), rLine.GetStart()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(17), rLine.GetEnd()); + } + } + + // CPPUNIT_ASSERT_MESSAGE("INTENTIONALLY FALSE", false); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); }
