summaryrefslogtreecommitdiff
path: root/vcl/qa
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2022-10-02 19:11:11 +1100
committerخالد حسني <khaled@aliftype.com>2022-11-20 16:25:25 +0100
commite535da3b6d72c0aca312dcf1ca38a3fcc3532a38 (patch)
tree0e28cdf2e185aa39a70125e64d4d4a381e672127 /vcl/qa
parent9a0a7ae8f62cc8233b71057caa6bc88c69ee94a1 (diff)
vcl: add unit tests for OutputDevice::GetTextRect()
Change-Id: Ic36d42b0b38083c6a9ce3b6af4d80d5acf3e96e3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140906 Tested-by: Jenkins Reviewed-by: خالد حسني <khaled@aliftype.com>
Diffstat (limited to 'vcl/qa')
-rw-r--r--vcl/qa/cppunit/text.cxx102
1 files changed, 102 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/text.cxx b/vcl/qa/cppunit/text.cxx
index a450c99ee3df..ee7ab8cd5859 100644
--- a/vcl/qa/cppunit/text.cxx
+++ b/vcl/qa/cppunit/text.cxx
@@ -66,6 +66,13 @@ public:
void testGetStringWithEndEllpsis();
void testGetStringWithNewsEllpsis();
void testGetTextBreak();
+ void testGetSingleLineTextRect();
+ void testGetSingleLineTextRectWithEndEllipsis();
+ void testGetRightBottomAlignedSingleLineTextRect();
+ void testGetMultiLineTextRect();
+ void testGetMultiLineTextRectWithEndEllipsis();
+ void testGetRightBottomAlignedMultiLineTextRect();
+ void testGetRotatedSingleLineTextRect();
CPPUNIT_TEST_SUITE(VclTextTest);
CPPUNIT_TEST(testSimpleText);
@@ -82,6 +89,13 @@ public:
CPPUNIT_TEST(testGetStringWithEndEllpsis);
CPPUNIT_TEST(testGetStringWithNewsEllpsis);
CPPUNIT_TEST(testGetTextBreak);
+ CPPUNIT_TEST(testGetSingleLineTextRect);
+ CPPUNIT_TEST(testGetSingleLineTextRectWithEndEllipsis);
+ CPPUNIT_TEST(testGetRightBottomAlignedSingleLineTextRect);
+ CPPUNIT_TEST(testGetMultiLineTextRect);
+ CPPUNIT_TEST(testGetMultiLineTextRectWithEndEllipsis);
+ CPPUNIT_TEST(testGetRightBottomAlignedMultiLineTextRect);
+ CPPUNIT_TEST(testGetRotatedSingleLineTextRect);
CPPUNIT_TEST_SUITE_END();
};
@@ -671,6 +685,94 @@ void VclTextTest::testGetTextBreak()
device->GetTextBreak(sTestStr, nTextWidth, 13, nLen));
}
+void VclTextTest::testGetSingleLineTextRect()
+{
+ ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT);
+ device->SetOutputSizePixel(Size(1000, 1000));
+ device->SetFont(vcl::Font("Liberation Sans", Size(0, 11)));
+
+ CPPUNIT_ASSERT_EQUAL(
+ tools::Rectangle(Point(), Size(75, 12)),
+ device->GetTextRect(tools::Rectangle(Point(), Point(100, 100)), "This is test text"));
+}
+
+void VclTextTest::testGetSingleLineTextRectWithEndEllipsis()
+{
+ ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT);
+ device->SetOutputSizePixel(Size(1000, 1000));
+ device->SetFont(vcl::Font("Liberation Sans", Size(0, 11)));
+
+ CPPUNIT_ASSERT_EQUAL(
+ tools::Rectangle(Point(), Size(52, 12)),
+ device->GetTextRect(tools::Rectangle(Point(), Point(50, 50)), "This is test text",
+ DrawTextFlags::WordBreak | DrawTextFlags::EndEllipsis));
+}
+
+void VclTextTest::testGetRightBottomAlignedSingleLineTextRect()
+{
+ ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT);
+ device->SetOutputSizePixel(Size(1000, 1000));
+ device->SetFont(vcl::Font("Liberation Sans", Size(0, 11)));
+
+ CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(926, 989), Size(75, 12)),
+ device->GetTextRect(tools::Rectangle(Point(), Point(1000, 1000)),
+ "This is test text",
+ DrawTextFlags::Right | DrawTextFlags::Bottom));
+}
+
+void VclTextTest::testGetRotatedSingleLineTextRect()
+{
+ ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT);
+ device->SetOutputSizePixel(Size(1000, 1000));
+ device->SetFont(vcl::Font("Liberation Sans", Size(0, 11)));
+
+ vcl::Font aFont(device->GetFont());
+ aFont.SetOrientation(45_deg10);
+ device->SetFont(aFont);
+
+ CPPUNIT_ASSERT_EQUAL(
+ tools::Rectangle(Point(0, -3), Size(75, 18)),
+ device->GetTextRect(tools::Rectangle(Point(), Point(100, 100)), "This is test text"));
+}
+
+void VclTextTest::testGetMultiLineTextRect()
+{
+ ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT);
+ device->SetOutputSizePixel(Size(1000, 1000));
+ device->SetFont(vcl::Font("Liberation Sans", Size(0, 11)));
+
+ CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(), Size(75, 12)),
+ device->GetTextRect(tools::Rectangle(Point(), Point(100, 100)),
+ "This is test text",
+ DrawTextFlags::WordBreak | DrawTextFlags::MultiLine));
+}
+
+void VclTextTest::testGetMultiLineTextRectWithEndEllipsis()
+{
+ ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT);
+ device->SetOutputSizePixel(Size(1000, 1000));
+ device->SetFont(vcl::Font("Liberation Sans", Size(0, 11)));
+
+ CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(), Size(52, 48)),
+ device->GetTextRect(tools::Rectangle(Point(), Point(50, 50)),
+ "This is test text xyzabc123abcdefghijk",
+ DrawTextFlags::WordBreak | DrawTextFlags::EndEllipsis
+ | DrawTextFlags::MultiLine));
+}
+
+void VclTextTest::testGetRightBottomAlignedMultiLineTextRect()
+{
+ ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT);
+ device->SetOutputSizePixel(Size(1000, 1000));
+ device->SetFont(vcl::Font("Liberation Sans", Size(0, 11)));
+
+ CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(926, 989), Size(75, 12)),
+ device->GetTextRect(tools::Rectangle(Point(), Point(1000, 1000)),
+ "This is test text",
+ DrawTextFlags::Right | DrawTextFlags::Bottom
+ | DrawTextFlags::MultiLine));
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(VclTextTest);
CPPUNIT_PLUGIN_IMPLEMENT();