vcl/qa/cppunit/text.cxx | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+)
New commits: commit 5c2e1c894e6d0ef846d3643ef96c56ab548ef0d0 Author: Chris Sherlock <chris.sherloc...@gmail.com> AuthorDate: Sun Oct 2 18:33:12 2022 +1100 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sat Oct 15 12:55:43 2022 +0200 vcl: test generating ellipses Change-Id: Ic985bd9bbee4319243c01fff6dffa46e860581a1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140905 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/vcl/qa/cppunit/text.cxx b/vcl/qa/cppunit/text.cxx index 8ec7597e6a65..a450c99ee3df 100644 --- a/vcl/qa/cppunit/text.cxx +++ b/vcl/qa/cppunit/text.cxx @@ -62,6 +62,9 @@ public: void testImplLayoutArgsBiDiRtl(); void testImplLayoutArgsRightAlign(); void testImplLayoutArgs_PrepareFallback_precalculatedglyphs(); + void testGetStringWithCenterEllpsis(); + void testGetStringWithEndEllpsis(); + void testGetStringWithNewsEllpsis(); void testGetTextBreak(); CPPUNIT_TEST_SUITE(VclTextTest); @@ -75,6 +78,9 @@ public: CPPUNIT_TEST(testImplLayoutArgsBiDiRtl); CPPUNIT_TEST(testImplLayoutArgsRightAlign); CPPUNIT_TEST(testImplLayoutArgs_PrepareFallback_precalculatedglyphs); + CPPUNIT_TEST(testGetStringWithCenterEllpsis); + CPPUNIT_TEST(testGetStringWithEndEllpsis); + CPPUNIT_TEST(testGetStringWithNewsEllpsis); CPPUNIT_TEST(testGetTextBreak); CPPUNIT_TEST_SUITE_END(); }; @@ -576,6 +582,71 @@ void VclTextTest::testImplLayoutArgs_PrepareFallback_precalculatedglyphs() CPPUNIT_ASSERT(!bRTL); } +void VclTextTest::testGetStringWithCenterEllpsis() +{ + ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT); + device->SetOutputSizePixel(Size(1000, 1000)); + device->SetFont(vcl::Font("DejaVu Sans", "Book", Size(0, 11))); + + CPPUNIT_ASSERT_EQUAL( + OUString(u"a b c d ...v w x y z"), + device->GetEllipsisString(u"a b c d e f g h i j k l m n o p q r s t u v w x y z", 100, + DrawTextFlags::CenterEllipsis)); +} + +void VclTextTest::testGetStringWithEndEllpsis() +{ + ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT); + device->SetOutputSizePixel(Size(1000, 1000)); + device->SetFont(vcl::Font("DejaVu Sans", "Book", Size(0, 11))); + + CPPUNIT_ASSERT_EQUAL(OUString(u"a"), device->GetEllipsisString(u"abcde. f g h i j ...", 10, + DrawTextFlags::EndEllipsis)); + + CPPUNIT_ASSERT_EQUAL( + OUString(u"a b c d e f g h i j ..."), + device->GetEllipsisString(u"a b c d e f g h i j k l m n o p q r s t u v w x y z", 100, + DrawTextFlags::EndEllipsis)); + + CPPUNIT_ASSERT_EQUAL(OUString(u"a"), device->GetEllipsisString(u"abcde. f g h i j ...", 1, + DrawTextFlags::EndEllipsis + | DrawTextFlags::Clip)); +} + +void VclTextTest::testGetStringWithNewsEllpsis() +{ + ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT); + device->SetOutputSizePixel(Size(1000, 1000)); + device->SetFont(vcl::Font("DejaVu Sans", "Book", Size(0, 11))); + + CPPUNIT_ASSERT_EQUAL(OUString(u"a"), device->GetEllipsisString(u"abcde. f g h i j ...", 10, + DrawTextFlags::NewsEllipsis)); + + CPPUNIT_ASSERT_EQUAL( + OUString(u"a b .... x y z"), + device->GetEllipsisString(u"a b c d. e f g. h i j k l m n o p q r s t u v w. x y z", 100, + DrawTextFlags::NewsEllipsis)); + + CPPUNIT_ASSERT_EQUAL( + OUString(u"a b .... x y z"), + device->GetEllipsisString(u"a b c d. e f g h i j k l m n o p q r s t u v w. x y z", 100, + DrawTextFlags::NewsEllipsis)); + + CPPUNIT_ASSERT_EQUAL( + OUString(u"a b c d e f g h i j ..."), + device->GetEllipsisString(u"a b c d e f g h i j k l m n o p q r s t u v w. x y z", 100, + DrawTextFlags::NewsEllipsis)); + + CPPUNIT_ASSERT_EQUAL( + OUString(u"a..... x y z"), + device->GetEllipsisString(u"a. b c d e f g h i j k l m n o p q r s t u v w. x y z", 100, + DrawTextFlags::NewsEllipsis)); + + CPPUNIT_ASSERT_EQUAL( + OUString(u"ab. cde..."), + device->GetEllipsisString(u"ab. cde. x y z", 50, DrawTextFlags::NewsEllipsis)); +} + void VclTextTest::testGetTextBreak() { ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT);