summaryrefslogtreecommitdiff
path: root/vcl/qa
diff options
context:
space:
mode:
Diffstat (limited to 'vcl/qa')
-rw-r--r--vcl/qa/cppunit/text.cxx15
-rw-r--r--vcl/qa/cppunit/textlayout.cxx58
2 files changed, 73 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/text.cxx b/vcl/qa/cppunit/text.cxx
index cabe502db462..371783759b65 100644
--- a/vcl/qa/cppunit/text.cxx
+++ b/vcl/qa/cppunit/text.cxx
@@ -719,6 +719,21 @@ CPPUNIT_TEST_FIXTURE(VclTextTest, testGetStringWithNewsEllpsis)
device->GetEllipsisString(u"ab. cde. x y z"_ustr, 50, DrawTextFlags::NewsEllipsis));
}
+CPPUNIT_TEST_FIXTURE(VclTextTest, testGetTextBreak_invalid_index)
+{
+ ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::WITHOUT_ALPHA);
+ device->SetOutputSizePixel(Size(1000, 1000));
+ device->SetFont(vcl::Font("DejaVu Sans", "Book", Size(0, 11)));
+
+ const OUString sTestStr(u"textline_ text_"_ustr);
+ const auto nLen = sTestStr.getLength();
+ const auto nTextWidth = device->GetTextWidth("text");
+ const auto nInvalidIndex = sTestStr.getLength() + 2;
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1),
+ device->GetTextBreak(sTestStr, nTextWidth, nInvalidIndex, nLen));
+}
+
CPPUNIT_TEST_FIXTURE(VclTextTest, testGetTextBreak)
{
ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::WITHOUT_ALPHA);
diff --git a/vcl/qa/cppunit/textlayout.cxx b/vcl/qa/cppunit/textlayout.cxx
new file mode 100644
index 000000000000..147826f19842
--- /dev/null
+++ b/vcl/qa/cppunit/textlayout.cxx
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * 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/.
+ */
+
+#include <config_features.h>
+#include <config_fonts.h>
+
+#include <test/bootstrapfixture.hxx>
+
+#include <vcl/unohelp.hxx>
+#include <vcl/virdev.hxx>
+
+#include <textlayout.hxx>
+
+class VclTextLayoutTest : public test::BootstrapFixture
+{
+public:
+ VclTextLayoutTest()
+ : BootstrapFixture(true, false)
+ {
+ }
+};
+
+#if HAVE_MORE_FONTS
+
+CPPUNIT_TEST_FIXTURE(VclTextLayoutTest, testBreakLinesWithIterator_invalid_softbreak)
+{
+ ScopedVclPtr<VirtualDevice> device = VclPtr<VirtualDevice>::Create(DeviceFormat::WITHOUT_ALPHA);
+ device->SetOutputSizePixel(Size(1000, 1000));
+ device->SetFont(vcl::Font("DejaVu Sans", "Book", Size(0, 11)));
+
+ vcl::DefaultTextLayout aTextLayout(*device);
+
+ const OUString sTestStr = u"textline_ text_"_ustr;
+ const auto nTextWidth = device->GetTextWidth("text");
+
+ css::uno::Reference<css::linguistic2::XHyphenator> xHyph;
+ css::uno::Reference<css::i18n::XBreakIterator> xBI = vcl::unohelper::CreateBreakIterator();
+
+ // softbreak cannot be greater than the string length
+
+ const auto nTextLen = 13;
+
+ CPPUNIT_ASSERT_EQUAL(
+ static_cast<sal_Int32>(13),
+ aTextLayout.BreakLinesWithIterator(nTextWidth, sTestStr, xHyph, xBI, false, nTextLen, 15));
+}
+
+#endif
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */