summaryrefslogtreecommitdiffstats
path: root/editeng/qa
diff options
context:
space:
mode:
Diffstat (limited to 'editeng/qa')
-rw-r--r--editeng/qa/items/borderline_test.cxx23
-rw-r--r--editeng/qa/lookuptree/lookuptree_test.cxx48
-rw-r--r--editeng/qa/unit/EPaMTest.cxx103
-rw-r--r--editeng/qa/unit/ESelectionTest.cxx185
-rw-r--r--editeng/qa/unit/EditLineListTest.cxx173
-rw-r--r--editeng/qa/unit/EditLineTest.cxx111
-rw-r--r--editeng/qa/unit/EditPaMTest.cxx74
-rw-r--r--editeng/qa/unit/EditSelectionTest.cxx143
-rw-r--r--editeng/qa/unit/core-test.cxx507
9 files changed, 1290 insertions, 77 deletions
diff --git a/editeng/qa/items/borderline_test.cxx b/editeng/qa/items/borderline_test.cxx
index 0499c7087984..a72ac14f4c78 100644
--- a/editeng/qa/items/borderline_test.cxx
+++ b/editeng/qa/items/borderline_test.cxx
@@ -28,24 +28,13 @@ using namespace ::com::sun::star::table::BorderLineStyle;
using namespace editeng;
-CPPUNIT_NS_BEGIN
-
-template<> struct assertion_traits<SvxBorderLineStyle>
+template<> inline std::string CPPUNIT_NS::assertion_traits<SvxBorderLineStyle>::toString(
+ SvxBorderLineStyle const & x )
{
- static bool equal( SvxBorderLineStyle x, SvxBorderLineStyle y )
- {
- return x == y;
- }
-
- static std::string toString( SvxBorderLineStyle x )
- {
- OStringStream ost;
- ost << static_cast<unsigned int>(x);
- return ost.str();
- }
-};
-
-CPPUNIT_NS_END
+ OStringStream ost;
+ ost << static_cast<unsigned int>(x);
+ return ost.str();
+}
namespace {
diff --git a/editeng/qa/lookuptree/lookuptree_test.cxx b/editeng/qa/lookuptree/lookuptree_test.cxx
index 7d5e9647b00c..486c871ca09f 100644
--- a/editeng/qa/lookuptree/lookuptree_test.cxx
+++ b/editeng/qa/lookuptree/lookuptree_test.cxx
@@ -44,69 +44,69 @@ void LookupTreeTest::testTrie()
editeng::Trie trie;
std::vector<OUString> suggestions;
- trie.findSuggestions( OUString(), suggestions);
+ trie.findSuggestions( u"", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(0), suggestions.size() );
- trie.insert( OUString() );
- trie.findSuggestions( OUString(), suggestions);
+ trie.insert( u"" );
+ trie.findSuggestions( u"", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(0), suggestions.size() );
- trie.findSuggestions( "a", suggestions);
+ trie.findSuggestions( u"a", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(0), suggestions.size() );
- trie.insert( "abc" );
- trie.insert( "abcdefghijklmnopqrstuvwxyz" );
- trie.findSuggestions( "a", suggestions);
+ trie.insert( u"abc" );
+ trie.insert( u"abcdefghijklmnopqrstuvwxyz" );
+ trie.findSuggestions( u"a", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(2), suggestions.size() );
CPPUNIT_ASSERT_EQUAL( OUString("abc"), suggestions[0] );
CPPUNIT_ASSERT_EQUAL( OUString("abcdefghijklmnopqrstuvwxyz"), suggestions[1] );
suggestions.clear();
- trie.findSuggestions( "abc", suggestions);
+ trie.findSuggestions( u"abc", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(1), suggestions.size() );
CPPUNIT_ASSERT_EQUAL( OUString("abcdefghijklmnopqrstuvwxyz"), suggestions[0] );
suggestions.clear();
- trie.findSuggestions( "abe", suggestions);
+ trie.findSuggestions( u"abe", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(0), suggestions.size() );
suggestions.clear();
- trie.insert( "abe" );
- trie.findSuggestions( "", suggestions);
+ trie.insert( u"abe" );
+ trie.findSuggestions( u"", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(3), suggestions.size() );
CPPUNIT_ASSERT_EQUAL( OUString("abc"), suggestions[0] );
CPPUNIT_ASSERT_EQUAL( OUString("abcdefghijklmnopqrstuvwxyz"), suggestions[1] );
CPPUNIT_ASSERT_EQUAL( OUString("abe"), suggestions[2] );
suggestions.clear();
- trie.insert( "H31l0" );
- trie.findSuggestions( "H", suggestions);
+ trie.insert( u"H31l0" );
+ trie.findSuggestions( u"H", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(1), suggestions.size() );
CPPUNIT_ASSERT_EQUAL( OUString("H31l0"), suggestions[0] );
suggestions.clear();
- trie.insert( "H1" );
- trie.findSuggestions( "H", suggestions);
+ trie.insert( u"H1" );
+ trie.findSuggestions( u"H", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(2), suggestions.size() );
CPPUNIT_ASSERT_EQUAL( OUString("H31l0"), suggestions[0] );
CPPUNIT_ASSERT_EQUAL( OUString("H1"), suggestions[1] );
suggestions.clear();
- trie.findSuggestions( "H3", suggestions);
+ trie.findSuggestions( u"H3", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(1), suggestions.size() );
CPPUNIT_ASSERT_EQUAL( OUString("H31l0"), suggestions[0] );
suggestions.clear();
trie.insert( OStringToOUString( "H\xC3\xA4llo", RTL_TEXTENCODING_UTF8 ) );
- trie.findSuggestions( "H", suggestions );
+ trie.findSuggestions( u"H", suggestions );
CPPUNIT_ASSERT_EQUAL( size_t(3), suggestions.size() );
CPPUNIT_ASSERT_EQUAL( OUString("H31l0"), suggestions[0] );
CPPUNIT_ASSERT_EQUAL( OUString("H1"), suggestions[1] );
CPPUNIT_ASSERT_EQUAL( OStringToOUString( "H\xC3\xA4llo", RTL_TEXTENCODING_UTF8 ), suggestions[2] );
suggestions.clear();
- trie.findSuggestions( "H3", suggestions );
+ trie.findSuggestions( u"H3", suggestions );
CPPUNIT_ASSERT_EQUAL( size_t(1), suggestions.size() );
CPPUNIT_ASSERT_EQUAL( OUString("H31l0"), suggestions[0] );
suggestions.clear();
@@ -116,7 +116,7 @@ void LookupTreeTest::testTrie()
CPPUNIT_ASSERT_EQUAL( OStringToOUString("H\xC3\xA4llo", RTL_TEXTENCODING_UTF8), suggestions[0] );
suggestions.clear();
- trie.findSuggestions( "", suggestions);
+ trie.findSuggestions( u"", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(6), suggestions.size() );
suggestions.clear();
}
@@ -127,15 +127,15 @@ void LookupTreeTest::testTrieGetAllEntries()
CPPUNIT_ASSERT_EQUAL( size_t(0), trie.size() );
- trie.insert("A");
+ trie.insert(u"A");
CPPUNIT_ASSERT_EQUAL( size_t(1), trie.size() );
- trie.insert("B");
- trie.insert("C");
+ trie.insert(u"B");
+ trie.insert(u"C");
CPPUNIT_ASSERT_EQUAL( size_t(3), trie.size() );
- trie.insert("AA");
- trie.insert("AAA");
+ trie.insert(u"AA");
+ trie.insert(u"AAA");
CPPUNIT_ASSERT_EQUAL( size_t(5), trie.size() );
}
diff --git a/editeng/qa/unit/EPaMTest.cxx b/editeng/qa/unit/EPaMTest.cxx
new file mode 100644
index 000000000000..509f08720aa0
--- /dev/null
+++ b/editeng/qa/unit/EPaMTest.cxx
@@ -0,0 +1,103 @@
+/* -*- 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 <test/bootstrapfixture.hxx>
+#include <editeng/EPaM.hxx>
+
+namespace
+{
+class EPaMTest : public test::BootstrapFixture
+{
+};
+
+CPPUNIT_TEST_FIXTURE(EPaMTest, testConstruction)
+{
+ {
+ EPaM aNew;
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNew.nPara);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNew.nIndex);
+ }
+
+ {
+ EPaM aNew(1, 2);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNew.nPara);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNew.nIndex);
+ }
+
+ {
+ EPaM aNew = { 1, 2 };
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNew.nPara);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNew.nIndex);
+ }
+
+ {
+ EPaM aNew{ 1, 2 };
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNew.nPara);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNew.nIndex);
+ }
+}
+
+CPPUNIT_TEST_FIXTURE(EPaMTest, testAssign)
+{
+ EPaM aPaM1;
+ EPaM aPaM2;
+
+ // set PaM 2
+ aPaM2 = EPaM{ 2, 1 };
+
+ // selections are not equal
+ CPPUNIT_ASSERT(aPaM2 != aPaM1);
+
+ // assign PaM 1 with PaM 2 content
+ aPaM1 = aPaM2;
+
+ // expect selections to be equal
+ CPPUNIT_ASSERT_EQUAL(aPaM2, aPaM1);
+}
+
+CPPUNIT_TEST_FIXTURE(EPaMTest, testEquals)
+{
+ EPaM aPaM1;
+ EPaM aPaM2;
+
+ // both empty = equal
+ CPPUNIT_ASSERT_EQUAL(aPaM1, aPaM2);
+
+ // set PaM 1
+ aPaM1 = { 1, 2 };
+
+ // expect them to be not equal
+ CPPUNIT_ASSERT(aPaM1 != aPaM2);
+
+ // set PaM 2 to the same value
+ aPaM2 = { 1, 2 };
+
+ // equal again
+ CPPUNIT_ASSERT_EQUAL(aPaM1, aPaM2);
+}
+
+CPPUNIT_TEST_FIXTURE(EPaMTest, testLess)
+{
+ // Both equal
+ CPPUNIT_ASSERT_EQUAL(false, EPaM(0, 0) < EPaM(0, 0));
+
+ // Obviously not less
+ CPPUNIT_ASSERT_EQUAL(false, EPaM(0, 2) < EPaM(0, 1));
+
+ // Strictly "<"
+ CPPUNIT_ASSERT_EQUAL(true, EPaM(0, 0) < EPaM(0, 1));
+
+ // Check if paragraph taken into account
+ CPPUNIT_ASSERT_EQUAL(false, EPaM(1, 0) < EPaM(0, 1));
+ CPPUNIT_ASSERT_EQUAL(true, EPaM(1, 0) < EPaM(2, 0));
+}
+
+} // end anonymous namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/editeng/qa/unit/ESelectionTest.cxx b/editeng/qa/unit/ESelectionTest.cxx
new file mode 100644
index 000000000000..27b9256b29d7
--- /dev/null
+++ b/editeng/qa/unit/ESelectionTest.cxx
@@ -0,0 +1,185 @@
+/* -*- 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 <test/bootstrapfixture.hxx>
+#include <editeng/ESelection.hxx>
+
+namespace
+{
+class ESelectionTest : public test::BootstrapFixture
+{
+};
+
+CPPUNIT_TEST_FIXTURE(ESelectionTest, testConstruction)
+{
+ {
+ ESelection aNewSelection;
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewSelection.nStartPara);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewSelection.nStartPos);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewSelection.nEndPara);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewSelection.nEndPos);
+ }
+
+ {
+ ESelection aNewSelection(1, 2, 3, 4);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewSelection.nStartPara);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewSelection.nStartPos);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aNewSelection.nEndPara);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aNewSelection.nEndPos);
+ }
+
+ {
+ ESelection aNewSelection = { 1, 2, 3, 4 };
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewSelection.nStartPara);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewSelection.nStartPos);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aNewSelection.nEndPara);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aNewSelection.nEndPos);
+ }
+
+ {
+ ESelection aNewSelection{ 1, 2, 3, 4 };
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewSelection.nStartPara);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewSelection.nStartPos);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aNewSelection.nEndPara);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aNewSelection.nEndPos);
+ }
+
+ {
+ ESelection aNewSelection(1, 2);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewSelection.nStartPara);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewSelection.nStartPos);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewSelection.nEndPara);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewSelection.nEndPos);
+ }
+}
+
+CPPUNIT_TEST_FIXTURE(ESelectionTest, testAssign)
+{
+ ESelection aSelection1;
+ ESelection aSelection2;
+
+ // set selection2
+ aSelection2 = ESelection{ 1, 1, 2, 1 };
+
+ // selections are not equal
+ CPPUNIT_ASSERT(aSelection2 != aSelection1);
+
+ // assign selection1 with selection2 content
+ aSelection1 = aSelection2;
+
+ // expect selections to be equal
+ CPPUNIT_ASSERT_EQUAL(aSelection2, aSelection1);
+}
+
+CPPUNIT_TEST_FIXTURE(ESelectionTest, testEquals)
+{
+ ESelection aSelection1;
+ ESelection aSelection2;
+
+ // both empty = equal
+ CPPUNIT_ASSERT_EQUAL(aSelection1, aSelection2);
+
+ // set selection1
+ aSelection1 = { 1, 2, 3, 4 };
+
+ // expect them to be not equal
+ CPPUNIT_ASSERT(aSelection1 != aSelection2);
+
+ // set selection 2 to the same value
+ aSelection2 = { 1, 2, 3, 4 };
+
+ // equal again
+ CPPUNIT_ASSERT_EQUAL(aSelection1, aSelection2);
+}
+
+CPPUNIT_TEST_FIXTURE(ESelectionTest, testIsZero)
+{
+ ESelection aEmpty;
+ CPPUNIT_ASSERT_EQUAL(true, aEmpty.IsZero());
+
+ CPPUNIT_ASSERT_EQUAL(false, ESelection(1, 2, 1, 2).IsZero());
+ CPPUNIT_ASSERT_EQUAL(true, ESelection(0, 0, 0, 0).IsZero());
+}
+
+CPPUNIT_TEST_FIXTURE(ESelectionTest, testLess)
+{
+ // Both equal
+ CPPUNIT_ASSERT_EQUAL(false, ESelection(0, 0, 1, 1) < ESelection(0, 0, 1, 1));
+
+ // Obviously not less
+ CPPUNIT_ASSERT_EQUAL(false, ESelection(0, 2, 0, 2) < ESelection(0, 1, 0, 1));
+
+ // Equal at a point therefore not strictly "<"
+ CPPUNIT_ASSERT_EQUAL(false, ESelection(0, 0, 0, 0) < ESelection(0, 0, 0, 1));
+
+ // Strictly "<"
+ CPPUNIT_ASSERT_EQUAL(true, ESelection(0, 0, 0, 0) < ESelection(0, 1, 0, 1));
+
+ // Check if paragraph taken into account
+ CPPUNIT_ASSERT_EQUAL(false, ESelection(1, 0, 1, 0) < ESelection(0, 1, 0, 1));
+ CPPUNIT_ASSERT_EQUAL(true, ESelection(1, 0, 1, 0) < ESelection(2, 0, 2, 0));
+}
+
+CPPUNIT_TEST_FIXTURE(ESelectionTest, testGreater)
+{
+ // Both equal
+ CPPUNIT_ASSERT_EQUAL(false, ESelection(0, 0, 1, 1) > ESelection(0, 0, 1, 1));
+
+ // Obviously not greater
+ CPPUNIT_ASSERT_EQUAL(false, ESelection(0, 1, 0, 1) > ESelection(0, 2, 0, 2));
+
+ // Equal at a point therefore not strictly ">"
+ CPPUNIT_ASSERT_EQUAL(false, ESelection(0, 0, 0, 1) > ESelection(0, 0, 0, 0));
+
+ // Strictly ">"
+ CPPUNIT_ASSERT_EQUAL(true, ESelection(0, 1, 0, 1) > ESelection(0, 0, 0, 0));
+
+ // Check if paragraph taken into account
+ CPPUNIT_ASSERT_EQUAL(false, ESelection(0, 1, 0, 1) > ESelection(1, 0, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(true, ESelection(2, 0, 2, 0) > ESelection(1, 0, 1, 0));
+}
+
+CPPUNIT_TEST_FIXTURE(ESelectionTest, testAdjust)
+{
+ // Scenarios where Adjust doesn't change the selection
+ ESelection aSelection;
+ aSelection.Adjust();
+ CPPUNIT_ASSERT_EQUAL(ESelection(), aSelection);
+
+ aSelection = { 1, 1, 1, 1 };
+ aSelection.Adjust();
+ CPPUNIT_ASSERT_EQUAL(ESelection(1, 1, 1, 1), aSelection);
+
+ aSelection = { 1, 1, 1, 2 };
+ aSelection.Adjust();
+ CPPUNIT_ASSERT_EQUAL(ESelection(1, 1, 1, 2), aSelection);
+
+ aSelection = { 1, 1, 2, 1 };
+ aSelection.Adjust();
+ CPPUNIT_ASSERT_EQUAL(ESelection(1, 1, 2, 1), aSelection);
+
+ // Position is greater - flip
+ aSelection = { 1, 2, 1, 1 };
+ aSelection.Adjust();
+ CPPUNIT_ASSERT_EQUAL(ESelection(1, 1, 1, 2), aSelection);
+
+ // Paragraph is greater - flip
+ aSelection = { 2, 1, 1, 1 };
+ aSelection.Adjust();
+ CPPUNIT_ASSERT_EQUAL(ESelection(1, 1, 2, 1), aSelection);
+
+ // Both are greater - flip
+ aSelection = { 2, 2, 1, 1 };
+ aSelection.Adjust();
+ CPPUNIT_ASSERT_EQUAL(ESelection(1, 1, 2, 2), aSelection);
+}
+
+} // end anonymous namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/editeng/qa/unit/EditLineListTest.cxx b/editeng/qa/unit/EditLineListTest.cxx
new file mode 100644
index 000000000000..c6240c4e055c
--- /dev/null
+++ b/editeng/qa/unit/EditLineListTest.cxx
@@ -0,0 +1,173 @@
+/* -*- 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 <test/bootstrapfixture.hxx>
+#include <EditLineList.hxx>
+
+namespace
+{
+class EditLineListTest : public test::BootstrapFixture
+{
+};
+
+CPPUNIT_TEST_FIXTURE(EditLineListTest, testConstruction)
+{
+ EditLineList aNewList;
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.Count());
+}
+
+CPPUNIT_TEST_FIXTURE(EditLineListTest, testAppendAndInsert)
+{
+ // Test case:
+ // Append EditLine1
+ // Append EditLine3
+ // Insert EditLine2 in-between EditLine1 and pEditLine3
+
+ EditLineList aNewList;
+
+ EditLine* pEditLine1 = new EditLine;
+ EditLine* pEditLine2 = new EditLine;
+ EditLine* pEditLine3 = new EditLine;
+
+ aNewList.Append(std::unique_ptr<EditLine>(pEditLine1));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewList.Count());
+
+ aNewList.Append(std::unique_ptr<EditLine>(pEditLine3));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.Count());
+
+ CPPUNIT_ASSERT_EQUAL(pEditLine1, &aNewList[0]);
+ CPPUNIT_ASSERT_EQUAL(pEditLine3, &aNewList[1]);
+
+ aNewList.Insert(1, std::unique_ptr<EditLine>(pEditLine2));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aNewList.Count());
+
+ CPPUNIT_ASSERT_EQUAL(pEditLine1, &aNewList[0]);
+ CPPUNIT_ASSERT_EQUAL(pEditLine2, &aNewList[1]);
+ CPPUNIT_ASSERT_EQUAL(pEditLine3, &aNewList[2]);
+}
+
+CPPUNIT_TEST_FIXTURE(EditLineListTest, testReset)
+{
+ EditLineList aNewList;
+
+ aNewList.Append(std::make_unique<EditLine>());
+ aNewList.Append(std::make_unique<EditLine>());
+ aNewList.Append(std::make_unique<EditLine>());
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aNewList.Count());
+
+ aNewList.Reset();
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.Count());
+}
+
+CPPUNIT_TEST_FIXTURE(EditLineListTest, testDeleteFrom)
+{
+ EditLineList aNewList;
+
+ aNewList.Append(std::make_unique<EditLine>());
+ aNewList.Append(std::make_unique<EditLine>());
+ aNewList.Append(std::make_unique<EditLine>());
+ aNewList.Append(std::make_unique<EditLine>());
+ aNewList.Append(std::make_unique<EditLine>());
+
+ aNewList[0].SetStart(10);
+ aNewList[1].SetStart(11);
+ aNewList[2].SetStart(12);
+ aNewList[3].SetStart(13);
+ aNewList[4].SetStart(14);
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aNewList.Count());
+
+ aNewList.DeleteFromLine(2);
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.Count());
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(10), aNewList[0].GetStart());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(11), aNewList[1].GetStart());
+
+ aNewList.Append(std::make_unique<EditLine>());
+ aNewList.Append(std::make_unique<EditLine>());
+ aNewList.Append(std::make_unique<EditLine>());
+ aNewList.Append(std::make_unique<EditLine>());
+
+ aNewList[2].SetStart(15);
+ aNewList[3].SetStart(16);
+ aNewList[4].SetStart(17);
+ aNewList[5].SetStart(18);
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(6), aNewList.Count());
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(10), aNewList[0].GetStart());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(11), aNewList[1].GetStart());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(15), aNewList[2].GetStart());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(16), aNewList[3].GetStart());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(17), aNewList[4].GetStart());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(18), aNewList[5].GetStart());
+
+ aNewList.DeleteFromLine(4);
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aNewList.Count());
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(10), aNewList[0].GetStart());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(11), aNewList[1].GetStart());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(15), aNewList[2].GetStart());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(16), aNewList[3].GetStart());
+}
+
+CPPUNIT_TEST_FIXTURE(EditLineListTest, testFindLine)
+{
+ EditLineList aNewList;
+ EditLine* pEditLine1 = new EditLine;
+ pEditLine1->SetStart(0);
+ pEditLine1->SetEnd(10);
+ aNewList.Append(std::unique_ptr<EditLine>(pEditLine1));
+
+ EditLine* pEditLine2 = new EditLine;
+ pEditLine2->SetStart(10);
+ pEditLine2->SetEnd(20);
+ aNewList.Append(std::unique_ptr<EditLine>(pEditLine2));
+
+ EditLine* pEditLine3 = new EditLine;
+ pEditLine3->SetStart(20);
+ pEditLine3->SetEnd(30);
+ aNewList.Append(std::unique_ptr<EditLine>(pEditLine3));
+
+ // Exclude end
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(-1, false));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(0, false));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(5, false));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(9, false));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewList.FindLine(10, false));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewList.FindLine(15, false));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewList.FindLine(19, false));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(20, false));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(25, false));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(30, false));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(31, false));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(10000, false));
+
+ // Include end
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(-1, true));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(0, true));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(5, true));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(9, true));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(10, true));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewList.FindLine(15, true));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewList.FindLine(19, true));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewList.FindLine(20, true));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(25, true));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(30, true));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(31, true));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(10000, true));
+}
+
+} // end anonymous namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/editeng/qa/unit/EditLineTest.cxx b/editeng/qa/unit/EditLineTest.cxx
new file mode 100644
index 000000000000..6991ba67755c
--- /dev/null
+++ b/editeng/qa/unit/EditLineTest.cxx
@@ -0,0 +1,111 @@
+/* -*- 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 <test/bootstrapfixture.hxx>
+#include <EditLine.hxx>
+
+namespace
+{
+class EditLineTest : public test::BootstrapFixture
+{
+};
+
+CPPUNIT_TEST_FIXTURE(EditLineTest, testConstruction)
+{
+ EditLine aNew;
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNew.GetStart());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNew.GetEnd());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNew.GetStartPortion());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNew.GetEndPortion());
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), aNew.GetMaxAscent());
+ CPPUNIT_ASSERT_EQUAL(false, aNew.IsValid());
+}
+
+CPPUNIT_TEST_FIXTURE(EditLineTest, testCopyConstructor)
+{
+ EditLine aLine1;
+ aLine1.SetStart(1);
+ aLine1.SetEnd(2);
+ aLine1.SetStartPortion(10);
+ aLine1.SetEndPortion(20);
+ aLine1.SetMaxAscent(200);
+ aLine1.SetValid();
+
+ // set Line2
+ EditLine aLine2(aLine1);
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aLine2.GetStart());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aLine2.GetEnd());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(10), aLine2.GetStartPortion());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(20), aLine2.GetEndPortion());
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), aLine2.GetMaxAscent());
+ CPPUNIT_ASSERT_EQUAL(false, aLine2.IsValid());
+}
+
+CPPUNIT_TEST_FIXTURE(EditLineTest, testAssign)
+{
+ EditLine aLine1;
+ aLine1.SetStart(1);
+ aLine1.SetEnd(2);
+ aLine1.SetStartPortion(10);
+ aLine1.SetEndPortion(20);
+ aLine1.SetMaxAscent(200);
+ aLine1.SetValid();
+
+ // set Line2
+ EditLine aLine2;
+ aLine2 = aLine1;
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aLine2.GetStart());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aLine2.GetEnd());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(10), aLine2.GetStartPortion());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(20), aLine2.GetEndPortion());
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), aLine2.GetMaxAscent());
+ CPPUNIT_ASSERT_EQUAL(false, aLine2.IsValid());
+}
+
+CPPUNIT_TEST_FIXTURE(EditLineTest, testEquals)
+{
+ EditLine aLine1;
+ EditLine aLine2;
+
+ // both empty = equal
+ CPPUNIT_ASSERT_EQUAL(true, aLine1 == aLine2);
+
+ aLine1.SetStart(10);
+ CPPUNIT_ASSERT_EQUAL(false, aLine1 == aLine2);
+
+ aLine2.SetStart(10);
+ CPPUNIT_ASSERT_EQUAL(true, aLine1 == aLine2);
+
+ aLine1.SetEnd(20);
+ CPPUNIT_ASSERT_EQUAL(false, aLine1 == aLine2);
+
+ aLine2.SetEnd(20);
+ CPPUNIT_ASSERT_EQUAL(true, aLine1 == aLine2);
+
+ aLine1.SetStartPortion(100);
+ CPPUNIT_ASSERT_EQUAL(false, aLine1 == aLine2);
+
+ aLine2.SetStartPortion(100);
+ CPPUNIT_ASSERT_EQUAL(true, aLine1 == aLine2);
+
+ aLine1.SetEndPortion(200);
+ CPPUNIT_ASSERT_EQUAL(false, aLine1 == aLine2);
+
+ aLine2.SetEndPortion(200);
+ CPPUNIT_ASSERT_EQUAL(true, aLine1 == aLine2);
+
+ aLine2.SetMaxAscent(200); // doesn't influence equality
+ CPPUNIT_ASSERT_EQUAL(true, aLine1 == aLine2);
+}
+
+} // end anonymous namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/editeng/qa/unit/EditPaMTest.cxx b/editeng/qa/unit/EditPaMTest.cxx
new file mode 100644
index 000000000000..12f0fa9741c9
--- /dev/null
+++ b/editeng/qa/unit/EditPaMTest.cxx
@@ -0,0 +1,74 @@
+/* -*- 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 <test/bootstrapfixture.hxx>
+#include <EditPaM.hxx>
+#include <editdoc.hxx>
+
+namespace
+{
+class EditPaMTest : public test::BootstrapFixture
+{
+protected:
+ rtl::Reference<EditEngineItemPool> mpItemPool;
+
+public:
+ void setUp() override
+ {
+ test::BootstrapFixture::setUp();
+ mpItemPool = new EditEngineItemPool();
+ }
+
+ void tearDown() override
+ {
+ mpItemPool.clear();
+ test::BootstrapFixture::tearDown();
+ }
+};
+
+CPPUNIT_TEST_FIXTURE(EditPaMTest, testConstruction)
+{
+ EditPaM aEmpty;
+ CPPUNIT_ASSERT(aEmpty.GetNode() == nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aEmpty.GetIndex());
+
+ ContentNode aContentNode(*mpItemPool);
+ EditPaM aNew(&aContentNode, 10);
+
+ CPPUNIT_ASSERT(aNew.GetNode() != nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(10), aNew.GetIndex());
+}
+
+CPPUNIT_TEST_FIXTURE(EditPaMTest, testEquals)
+{
+ ContentNode aContentNode(*mpItemPool);
+
+ EditPaM aEditPaMEmpty1;
+ EditPaM aEditPaMEmpty2;
+
+ CPPUNIT_ASSERT_EQUAL(true, aEditPaMEmpty1 == aEditPaMEmpty2);
+ CPPUNIT_ASSERT_EQUAL(false, aEditPaMEmpty1 != aEditPaMEmpty2);
+
+ EditPaM aEditPaM1(&aContentNode, 10);
+
+ CPPUNIT_ASSERT_EQUAL(false, aEditPaMEmpty1 == aEditPaM1);
+ CPPUNIT_ASSERT_EQUAL(true, aEditPaMEmpty1 != aEditPaM1);
+
+ EditPaM aEditPaM2(&aContentNode, 15);
+ CPPUNIT_ASSERT_EQUAL(false, aEditPaM2 == aEditPaM1);
+ CPPUNIT_ASSERT_EQUAL(true, aEditPaM2 != aEditPaM1);
+
+ EditPaM aEditPaM3(&aContentNode, 10);
+ CPPUNIT_ASSERT_EQUAL(true, aEditPaM3 == aEditPaM1);
+ CPPUNIT_ASSERT_EQUAL(false, aEditPaM3 != aEditPaM1);
+}
+
+} // end anonymous namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/editeng/qa/unit/EditSelectionTest.cxx b/editeng/qa/unit/EditSelectionTest.cxx
new file mode 100644
index 000000000000..b3308fbc2fa9
--- /dev/null
+++ b/editeng/qa/unit/EditSelectionTest.cxx
@@ -0,0 +1,143 @@
+/* -*- 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 <test/bootstrapfixture.hxx>
+#include <EditSelection.hxx>
+#include <editdoc.hxx>
+
+namespace
+{
+class EditSelectionTest : public test::BootstrapFixture
+{
+protected:
+ rtl::Reference<EditEngineItemPool> mpItemPool;
+
+public:
+ void setUp() override
+ {
+ test::BootstrapFixture::setUp();
+ mpItemPool = new EditEngineItemPool();
+ }
+
+ void tearDown() override
+ {
+ mpItemPool.clear();
+ test::BootstrapFixture::tearDown();
+ }
+};
+
+CPPUNIT_TEST_FIXTURE(EditSelectionTest, testConstruction)
+{
+ // Check empty selections
+ EditSelection aEmpty;
+ CPPUNIT_ASSERT(aEmpty.Min().GetNode() == nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aEmpty.Min().GetIndex());
+
+ CPPUNIT_ASSERT(aEmpty.Max().GetNode() == nullptr);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aEmpty.Max().GetIndex());
+
+ // Create content nodes
+ ContentNode aContentNode1(*mpItemPool);
+ ContentNode* pContentNode1 = &aContentNode1;
+ ContentNode aContentNode2(*mpItemPool);
+ ContentNode* pContentNode2 = &aContentNode2;
+
+ // Check selection with (node1 10, node1 20)
+ {
+ EditSelection aNew(EditPaM(&aContentNode1, 10), EditPaM(&aContentNode1, 20));
+
+ CPPUNIT_ASSERT_EQUAL(true, aNew.Min().GetNode() == pContentNode1);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(10), aNew.Min().GetIndex());
+
+ CPPUNIT_ASSERT_EQUAL(true, aNew.Max().GetNode() == pContentNode1);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(20), aNew.Max().GetIndex());
+ }
+
+ // Check selection with (node1 10, node2 10)
+ {
+ EditSelection aNew(EditPaM(&aContentNode1, 10), EditPaM(&aContentNode2, 10));
+
+ CPPUNIT_ASSERT_EQUAL(true, aNew.Min().GetNode() == pContentNode1);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(10), aNew.Min().GetIndex());
+
+ CPPUNIT_ASSERT_EQUAL(true, aNew.Max().GetNode() == pContentNode2);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(10), aNew.Max().GetIndex());
+ }
+}
+
+CPPUNIT_TEST_FIXTURE(EditSelectionTest, testEquals)
+{
+ // Check empty equality
+ EditSelection aEditSelectionEmpty1;
+ EditSelection aEditSelectionEmpty2;
+
+ CPPUNIT_ASSERT_EQUAL(true, aEditSelectionEmpty1 == aEditSelectionEmpty2);
+ CPPUNIT_ASSERT_EQUAL(false, aEditSelectionEmpty1 != aEditSelectionEmpty2);
+
+ // Check equal, in-equal
+ ContentNode aContentNode(*mpItemPool);
+
+ EditSelection aEditSelection1(EditPaM(&aContentNode, 10), EditPaM(&aContentNode, 20));
+
+ CPPUNIT_ASSERT_EQUAL(false, aEditSelectionEmpty1 == aEditSelection1);
+ CPPUNIT_ASSERT_EQUAL(true, aEditSelectionEmpty1 != aEditSelection1);
+
+ EditSelection aEditSelection2(EditPaM(&aContentNode, 15), EditPaM(&aContentNode, 20));
+ CPPUNIT_ASSERT_EQUAL(false, aEditSelection1 == aEditSelection2);
+ CPPUNIT_ASSERT_EQUAL(true, aEditSelection1 != aEditSelection2);
+
+ EditSelection aEditSelection3(EditPaM(&aContentNode, 10), EditPaM(&aContentNode, 20));
+ CPPUNIT_ASSERT_EQUAL(true, aEditSelection1 == aEditSelection3);
+ CPPUNIT_ASSERT_EQUAL(false, aEditSelection1 != aEditSelection3);
+}
+
+CPPUNIT_TEST_FIXTURE(EditSelectionTest, testAssign)
+{
+ ContentNode aContentNode(*mpItemPool);
+ ContentNode* pContentNode = &aContentNode;
+
+ EditSelection aEditSelection1(EditPaM(&aContentNode, 20), EditPaM(&aContentNode, 20));
+ EditSelection aEditSelection2;
+
+ // Check selection1 == selection2 (empty)
+ CPPUNIT_ASSERT_EQUAL(false, aEditSelection1 == aEditSelection2);
+ CPPUNIT_ASSERT_EQUAL(true, aEditSelection1 != aEditSelection2);
+
+ // Assign with selection2 with (15, 20)
+ aEditSelection2 = EditSelection(EditPaM(pContentNode, 15), EditPaM(pContentNode, 20));
+
+ // Check if it matches aEditSelection1 (20, 20) -> no
+ CPPUNIT_ASSERT_EQUAL(false, aEditSelection1 == aEditSelection2);
+ CPPUNIT_ASSERT_EQUAL(true, aEditSelection1 != aEditSelection2);
+
+ // Check if selection2 vales are set correctly
+ CPPUNIT_ASSERT_EQUAL(true, aEditSelection2.Min().GetNode() == pContentNode);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(15), aEditSelection2.Min().GetIndex());
+
+ CPPUNIT_ASSERT_EQUAL(true, aEditSelection2.Max().GetNode() == pContentNode);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(20), aEditSelection2.Max().GetIndex());
+
+ // Assign EditPaM value (20)
+ aEditSelection2 = EditPaM(pContentNode, 20);
+
+ // Check if it matches aEditSelection1 (20, 20) -> yes
+ CPPUNIT_ASSERT_EQUAL(true, aEditSelection1 == aEditSelection2);
+ CPPUNIT_ASSERT_EQUAL(false, aEditSelection1 != aEditSelection2);
+
+ // Check if selection2 vales are set correctly - expect selection min and max == the EditPaM (20)
+ CPPUNIT_ASSERT_EQUAL(true, aEditSelection2.Min().GetNode() == pContentNode);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(20), aEditSelection2.Min().GetIndex());
+
+ CPPUNIT_ASSERT_EQUAL(true, aEditSelection2.Max().GetNode() == pContentNode);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(20), aEditSelection2.Max().GetIndex());
+}
+
+} // end anonymous namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx
index 896fa59810eb..14ce66ef55a3 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>
@@ -29,6 +30,7 @@
#include <editeng/flditem.hxx>
#include <editeng/udlnitem.hxx>
#include <svl/srchitem.hxx>
+#include <svl/voiditem.hxx>
#include <editeng/fontitem.hxx>
#include <editeng/fhgtitem.hxx>
@@ -44,10 +46,20 @@ namespace {
class Test : public test::BootstrapFixture
{
public:
- Test();
+ Test() {}
- virtual void setUp() override;
- virtual void tearDown() override;
+ void setUp() override
+ {
+ test::BootstrapFixture::setUp();
+ mpItemPool = new EditEngineItemPool();
+ SfxApplication::GetOrCreate();
+ }
+
+ void tearDown() override
+ {
+ mpItemPool.clear();
+ test::BootstrapFixture::tearDown();
+ }
#if HAVE_MORE_FONTS
/// Test text portions position when percentage line spacing is set
@@ -68,6 +80,12 @@ public:
/// Test Copy/Paste using Legacy Format
void testCopyPaste();
+ /// Test Paste using HTML
+ void testHTMLPaste();
+
+ /// Test Paste using an HTML fragment
+ void testHTMLFragmentPaste();
+
/// Test Copy/Paste with selective selection over multiple paragraphs
void testMultiParaSelCopyPaste();
@@ -97,6 +115,15 @@ public:
void testTransliterate();
+ void testTdf147196();
+
+ void testTdf148148();
+
+ void testSingleLine();
+ void testMoveParagraph();
+ void testCreateLines();
+ void testTdf154248MultilineFieldWrapping();
+
DECL_STATIC_LINK( Test, CalcFieldValueHdl, EditFieldInfo*, void );
CPPUNIT_TEST_SUITE(Test);
@@ -108,6 +135,8 @@ public:
CPPUNIT_TEST(testAutocorrect);
CPPUNIT_TEST(testHyperlinkCopyPaste);
CPPUNIT_TEST(testCopyPaste);
+ CPPUNIT_TEST(testHTMLPaste);
+ CPPUNIT_TEST(testHTMLFragmentPaste);
CPPUNIT_TEST(testMultiParaSelCopyPaste);
CPPUNIT_TEST(testTabsCopyPaste);
CPPUNIT_TEST(testHyperlinkSearch);
@@ -119,29 +148,18 @@ public:
CPPUNIT_TEST(testSectionAttributes);
CPPUNIT_TEST(testLargeParaCopyPaste);
CPPUNIT_TEST(testTransliterate);
+ CPPUNIT_TEST(testTdf147196);
+ CPPUNIT_TEST(testTdf148148);
+ CPPUNIT_TEST(testSingleLine);
+ CPPUNIT_TEST(testMoveParagraph);
+ CPPUNIT_TEST(testCreateLines);
+ CPPUNIT_TEST(testTdf154248MultilineFieldWrapping);
CPPUNIT_TEST_SUITE_END();
private:
rtl::Reference<EditEngineItemPool> mpItemPool;
};
-Test::Test() {}
-
-void Test::setUp()
-{
- test::BootstrapFixture::setUp();
-
- mpItemPool = new EditEngineItemPool();
-
- SfxApplication::GetOrCreate();
-}
-
-void Test::tearDown()
-{
- mpItemPool.clear();
- test::BootstrapFixture::tearDown();
-}
-
#if HAVE_MORE_FONTS
void Test::testLineSpacing()
{
@@ -191,7 +209,7 @@ void Test::testLineSpacing()
aEditEngine.QuickSetAttribs(*pSet, aSelection);
// Assert changes
- ParaPortion& rParaPortion = aEditEngine.GetParaPortions()[0];
+ ParaPortion const& rParaPortion = aEditEngine.GetParaPortions().getRef(0);
ContentNode* const pNode = rParaPortion.GetNode();
const SvxLineSpacingItem& rLSItem = pNode->GetContentAttribs().GetItem(EE_PARA_SBL);
CPPUNIT_ASSERT_EQUAL(SvxInterLineSpaceRule::Prop, rLSItem.GetInterLineSpaceRule());
@@ -552,8 +570,7 @@ IMPL_STATIC_LINK( Test, CalcFieldValueHdl, EditFieldInfo*, pInfo, void )
void Test::testHyperlinkCopyPaste()
{
// Create Outliner instance
- Outliner aOutliner(mpItemPool.get(), OutlinerMode
-::TextObject);
+ Outliner aOutliner(mpItemPool.get(), OutlinerMode::TextObject);
aOutliner.SetCalcFieldValueHdl( LINK( nullptr, Test, CalcFieldValueHdl ) );
// Create EditEngine's instance
@@ -705,6 +722,89 @@ void Test::testCopyPaste()
CPPUNIT_ASSERT_EQUAL( OUString(aText + aText), rDoc.GetParaAsString(sal_Int32(0)) );
}
+/// XTransferable implementation that provides simple HTML content.
+class TestHTMLTransferable : public cppu::WeakImplHelper<datatransfer::XTransferable>
+{
+ OString m_aHTML;
+public:
+ TestHTMLTransferable(const OString& rHTML);
+ uno::Any SAL_CALL getTransferData(const datatransfer::DataFlavor& rFlavor) override;
+ uno::Sequence<datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override;
+ sal_Bool SAL_CALL isDataFlavorSupported(const datatransfer::DataFlavor& rFlavor) override;
+};
+
+TestHTMLTransferable::TestHTMLTransferable(const OString& rHTML)
+ : m_aHTML(rHTML)
+{
+}
+
+uno::Any TestHTMLTransferable::getTransferData(const datatransfer::DataFlavor& rFlavor)
+{
+ if (rFlavor.MimeType != "text/html")
+ {
+ return {};
+ }
+
+ uno::Any aRet;
+ SvMemoryStream aStream;
+ aStream.WriteOString(m_aHTML);
+ aRet <<= uno::Sequence<sal_Int8>(static_cast<const sal_Int8*>(aStream.GetData()), aStream.GetSize());
+ return aRet;
+}
+
+uno::Sequence<datatransfer::DataFlavor> TestHTMLTransferable::getTransferDataFlavors()
+{
+ datatransfer::DataFlavor aFlavor;
+ aFlavor.DataType = cppu::UnoType<uno::Sequence<sal_Int8>>::get();
+ aFlavor.MimeType = "text/html";
+ aFlavor.HumanPresentableName = aFlavor.MimeType;
+ return { aFlavor };
+}
+
+sal_Bool TestHTMLTransferable::isDataFlavorSupported(const datatransfer::DataFlavor& rFlavor)
+{
+ return rFlavor.MimeType == "text/html"
+ && rFlavor.DataType == cppu::UnoType<uno::Sequence<sal_Int8>>::get();
+}
+
+void Test::testHTMLPaste()
+{
+ // Given an empty editeng document:
+ EditEngine aEditEngine(mpItemPool.get());
+ EditDoc &rDoc = aEditEngine.GetEditDoc();
+ OString aHTML("<!DOCTYPE html>\n<html><body>test</body></html>"_ostr);
+ uno::Reference< datatransfer::XTransferable > xData(new TestHTMLTransferable(aHTML));
+
+ // When trying to paste HTML:
+ aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true);
+
+ // Then make sure the text gets pasted:
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: test
+ // - Actual :
+ // i.e. RTF and plain text paste worked, but not HTML.
+ CPPUNIT_ASSERT_EQUAL(OUString("test"), rDoc.GetParaAsString(static_cast<sal_Int32>(0)));
+}
+
+void Test::testHTMLFragmentPaste()
+{
+ // Given an empty editeng document:
+ EditEngine aEditEngine(mpItemPool.get());
+ EditDoc &rDoc = aEditEngine.GetEditDoc();
+ OString aHTML("a<b>b</b>c"_ostr);
+ uno::Reference< datatransfer::XTransferable > xData(new TestHTMLTransferable(aHTML));
+
+ // When trying to paste an HTML fragment:
+ aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true);
+
+ // Then make sure the text gets pasted:
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: abc
+ // - Actual :
+ // i.e. a HTML fragment without a proper header was ignored on paste.
+ CPPUNIT_ASSERT_EQUAL(OUString("abc"), rDoc.GetParaAsString(static_cast<sal_Int32>(0)));
+}
+
void Test::testMultiParaSelCopyPaste()
{
// Create EditEngine's instance
@@ -808,7 +908,7 @@ class UrlEditEngine : public EditEngine
public:
explicit UrlEditEngine(SfxItemPool *pPool) : EditEngine(pPool) {}
- virtual OUString CalcFieldValue( const SvxFieldItem&, sal_Int32, sal_Int32, std::optional<Color>&, std::optional<Color>& ) override
+ virtual OUString CalcFieldValue( const SvxFieldItem&, sal_Int32, sal_Int32, std::optional<Color>&, std::optional<Color>&, std::optional<FontLineStyle>& ) override
{
return "jim@bob.com"; // a sophisticated view of value:
}
@@ -1140,7 +1240,7 @@ void Test::testUnderlineCopyPaste()
aEditEngine.InsertText( xData, OUString(), rDoc.GetEndPaM(), true );
// Assert changes
- CPPUNIT_ASSERT_EQUAL( aTextLen + (OUString("textforunder")).getLength(), rDoc.GetTextLen() );
+ CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(aTextLen + strlen("textforunder")), rDoc.GetTextLen() );
CPPUNIT_ASSERT_EQUAL( OUString(aParaText + "textforunder" ), rDoc.GetParaAsString(sal_Int32(0)) );
// Check updated text for appropriate Underline
@@ -1764,18 +1864,19 @@ void Test::testTransliterate()
CPPUNIT_ASSERT_EQUAL(OUString("One (Two) Three"), editEng.GetText());
using TF = TransliterationFlags;
- const OUString sText2 = "Mary Jones met joe Smith. Time Passed.";
+ constexpr OUString sText2 = u"Mary Jones met joe Smith. Time Passed."_ustr;
int selStart = 12;
int selEnd = 12;
ESelection esel(0, selStart, 0, selEnd);
+ ESelection eSentenSel(0, 0, 0, 25);
/* DocumentContentOperationsManager checks if the cursor is inside of a word before transliterating,
* but Edit Engine has no such check. Therefore, behavior is different between these two when the
* cursor is on a word boundary. */
- /* No selection tests. Cursor between the ' ' and 'm' before 'met'. */
+ /* No selection tests. Cursor between the ' ' and 'm' before 'met' - except in SENTENCE_CASE where the complete sentence is selected.*/
CPPUNIT_ASSERT_EQUAL(OUString(""), editEng.GetText(esel));
- CPPUNIT_ASSERT_EQUAL(OUString("Mary jones met joe smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::SENTENCE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("Mary jones met joe smith. Time Passed."), lcl_translitTest(editEng, sText2, eSentenSel, TF::SENTENCE_CASE));
CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones Met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones MET joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
@@ -1785,9 +1886,8 @@ void Test::testTransliterate()
selEnd = 14;
esel = ESelection(0, selStart, 0, selEnd);
CPPUNIT_ASSERT_EQUAL(OUString(""), editEng.GetText(esel));
- CPPUNIT_ASSERT_EQUAL(OUString("Mary jones met joe smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::SENTENCE_CASE));
- CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
- CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones Met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones MET joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
/* No selection tests. Cursor between the 'h' and the '.' after 'Smith'. */
@@ -1795,7 +1895,6 @@ void Test::testTransliterate()
selEnd = 24;
esel = ESelection(0, selStart, 0, selEnd);
CPPUNIT_ASSERT_EQUAL(OUString(""), editEng.GetText(esel));
- CPPUNIT_ASSERT_EQUAL(OUString("Mary jones met joe smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::SENTENCE_CASE));
CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
@@ -1805,7 +1904,6 @@ void Test::testTransliterate()
selEnd = 12;
esel = ESelection(0, selStart, 0, selEnd);
CPPUNIT_ASSERT_EQUAL(OUString(""), editEng.GetText(esel));
- CPPUNIT_ASSERT_EQUAL(OUString("Mary jones met joe smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::SENTENCE_CASE));
CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones Met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones MET joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
@@ -1815,18 +1913,36 @@ void Test::testTransliterate()
selEnd = 14;
esel = ESelection(0, selStart, 0, selEnd);
CPPUNIT_ASSERT_EQUAL(OUString("met"), editEng.GetText(esel));
- CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones Met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::SENTENCE_CASE));
CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones Met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones MET joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
+ /* Test behavior when there is a selection that does not begin at a word boundary: "et" */
+ selStart = 12;
+ selEnd = 14;
+ esel = ESelection(0, selStart, 0, selEnd);
+ CPPUNIT_ASSERT_EQUAL(OUString("et"), editEng.GetText(esel));
+ CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones mEt joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones mET joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
+
+ /* Test behavior when there is a selection that ends in the middle of a word */
+ selStart = 11;
+ selEnd = 13;
+ esel = ESelection(0, selStart, 0, selEnd);
+ CPPUNIT_ASSERT_EQUAL(OUString("me"), editEng.GetText(esel));
+ CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones Met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones MEt joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
+
+
/* Test behavior when there is a selection that crosses a word boundary: "nes met joe Sm" */
selStart = 7;
selEnd = 21;
esel = ESelection(0, selStart, 0, selEnd);
CPPUNIT_ASSERT_EQUAL(OUString("nes met joe Sm"), editEng.GetText(esel));
CPPUNIT_ASSERT_EQUAL(OUString("Mary JoNes met joe smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::SENTENCE_CASE));
- CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones Met Joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("Mary JoNes Met Joe Smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
CPPUNIT_ASSERT_EQUAL(OUString("Mary JoNES MET JOE SMith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(OUString("Mary Jones met joe smith. Time Passed."), lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
@@ -1846,7 +1962,7 @@ void Test::testTransliterate()
selStart = 0;
selEnd = 19;
esel = ESelection(0, selStart, 0, selEnd);
- const OUString sText3("CURRENT IS EQUAL TO 10 A");
+ constexpr OUString sText3(u"CURRENT IS EQUAL TO 10 A"_ustr);
editEng.SetText(sText3);
CPPUNIT_ASSERT_EQUAL(OUString("CURRENT IS EQUAL TO"), editEng.GetText(esel));
@@ -1855,7 +1971,326 @@ void Test::testTransliterate()
CPPUNIT_ASSERT_EQUAL(OUString("CURRENT IS EQUAL TO 10 A"), lcl_translitTest(editEng, sText3, esel, TF::LOWERCASE_UPPERCASE));
CPPUNIT_ASSERT_EQUAL(OUString("current is equal to 10 A"), lcl_translitTest(editEng, sText3, esel, TF::UPPERCASE_LOWERCASE));
+}
+
+void Test::testTdf147196()
+{
+ EditEngine editEng( mpItemPool.get() );
+ editEng.SetText("2.2 Publication of information - CAA\nSection 4.2 of a CA\'s Certificate Policy and/or Certification Practice Statement SHALL state the CA\'s policy or practice on processing CAA Records for Fully Qualified Domain Names; that policy shall be consistent with these Requirements. \n\nIt shall clearly specify the set of Issuer Domain Names that the CA recognises in CAA \"issue\" or \"issuewild\" records as permitting it to issue. The CA SHALL log all actions taken, if any, consistent with its processing practice.");
+ editEng.TransliterateText(ESelection(0, 0, 3, 232), TransliterationFlags::TITLE_CASE);
+ CPPUNIT_ASSERT_EQUAL(OUString("2.2 Publication Of Information - Caa\nSection 4.2 Of A Ca\'s Certificate Policy And/Or Certification Practice Statement Shall State The Ca\'s Policy Or Practice On Processing Caa Records For Fully Qualified Domain Names; That Policy Shall Be Consistent With These Requirements. \n\nIt Shall Clearly Specify The Set Of Issuer Domain Names That The Ca Recognises In Caa \"Issue\" Or \"Issuewild\" Records As Permitting It To Issue. The Ca Shall Log All Actions Taken, If Any, Consistent With Its Processing Practice."), editEng.GetText());
+}
+
+void Test::testTdf148148()
+{
+ using TF = TransliterationFlags;
+ EditEngine editEng( mpItemPool.get() );
+
+ /* Test what happens when node contains text but selection does not contain any text */
+ int selStart = 0;
+ int selEnd = 3;
+ ESelection esel(0, selStart, 0, selEnd);
+ constexpr OUString sText1(u" text"_ustr);
+ editEng.SetText(sText1);
+ CPPUNIT_ASSERT_EQUAL(OUString(" "), editEng.GetText(esel));
+
+ CPPUNIT_ASSERT_EQUAL(OUString(" text"), lcl_translitTest(editEng, sText1, esel, TF::SENTENCE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString(" text"), lcl_translitTest(editEng, sText1, esel, TF::TITLE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString(" text"), lcl_translitTest(editEng, sText1, esel, TF::LOWERCASE_UPPERCASE));
+ CPPUNIT_ASSERT_EQUAL(OUString(" text"), lcl_translitTest(editEng, sText1, esel, TF::UPPERCASE_LOWERCASE));
+
+ selStart = 4;
+ selEnd = 8;
+ esel = ESelection(0, selStart, 0, selEnd);
+ constexpr OUString sText2(u"text "_ustr);
+ editEng.SetText(sText2);
+ CPPUNIT_ASSERT_EQUAL(OUString(" "), editEng.GetText(esel));
+
+ CPPUNIT_ASSERT_EQUAL(OUString("text "), lcl_translitTest(editEng, sText2, esel, TF::SENTENCE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("text "), lcl_translitTest(editEng, sText2, esel, TF::TITLE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("text "), lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("text "), lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE));
+
+ /* Test what happens when node contains only non-word text but selection does not contain any text */
+ selStart = 0;
+ selEnd = 3;
+ esel = ESelection(0, selStart, 0, selEnd);
+ constexpr OUString sText3(u" -1"_ustr);
+ editEng.SetText(sText3);
+ CPPUNIT_ASSERT_EQUAL(OUString(" "), editEng.GetText(esel));
+
+ CPPUNIT_ASSERT_EQUAL(OUString(" -1"), lcl_translitTest(editEng, sText3, esel, TF::SENTENCE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString(" -1"), lcl_translitTest(editEng, sText3, esel, TF::TITLE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString(" -1"), lcl_translitTest(editEng, sText3, esel, TF::LOWERCASE_UPPERCASE));
+ CPPUNIT_ASSERT_EQUAL(OUString(" -1"), lcl_translitTest(editEng, sText3, esel, TF::UPPERCASE_LOWERCASE));
+
+ selStart = 2;
+ selEnd = 6;
+ esel = ESelection(0, selStart, 0, selEnd);
+ constexpr OUString sText4(u"-1 "_ustr);
+ editEng.SetText(sText4);
+ CPPUNIT_ASSERT_EQUAL(OUString(" "), editEng.GetText(esel));
+
+ CPPUNIT_ASSERT_EQUAL(OUString("-1 "), lcl_translitTest(editEng, sText4, esel, TF::SENTENCE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("-1 "), lcl_translitTest(editEng, sText4, esel, TF::TITLE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("-1 "), lcl_translitTest(editEng, sText4, esel, TF::LOWERCASE_UPPERCASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("-1 "), lcl_translitTest(editEng, sText4, esel, TF::UPPERCASE_LOWERCASE));
+
+ /* Test what happens when node and selection contains only non-word text */
+ selStart = 0;
+ selEnd = 5;
+ esel = ESelection(0, selStart, 0, selEnd);
+ constexpr OUString sText5(u" -1"_ustr);
+ editEng.SetText(sText3);
+ CPPUNIT_ASSERT_EQUAL(OUString(" -1"), editEng.GetText(esel));
+
+ CPPUNIT_ASSERT_EQUAL(OUString(" -1"), lcl_translitTest(editEng, sText5, esel, TF::SENTENCE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString(" -1"), lcl_translitTest(editEng, sText5, esel, TF::TITLE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString(" -1"), lcl_translitTest(editEng, sText5, esel, TF::LOWERCASE_UPPERCASE));
+ CPPUNIT_ASSERT_EQUAL(OUString(" -1"), lcl_translitTest(editEng, sText5, esel, TF::UPPERCASE_LOWERCASE));
+
+ selStart = 0;
+ selEnd = 5;
+ esel = ESelection(0, selStart, 0, selEnd);
+ constexpr OUString sText6(u"-1 "_ustr);
+ editEng.SetText(sText4);
+ CPPUNIT_ASSERT_EQUAL(OUString("-1 "), editEng.GetText(esel));
+
+ CPPUNIT_ASSERT_EQUAL(OUString("-1 "), lcl_translitTest(editEng, sText6, esel, TF::SENTENCE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("-1 "), lcl_translitTest(editEng, sText6, esel, TF::TITLE_CASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("-1 "), lcl_translitTest(editEng, sText6, esel, TF::LOWERCASE_UPPERCASE));
+ CPPUNIT_ASSERT_EQUAL(OUString("-1 "), lcl_translitTest(editEng, sText6, esel, TF::UPPERCASE_LOWERCASE));
+
+
+}
+
+void Test::testSingleLine()
+{
+ EditEngine aEditEngine( mpItemPool.get() );
+
+ aEditEngine.SetSingleLine(true);
+ aEditEngine.SetText("Bolivian\nSanta Cruz de la Sierra");
+ aEditEngine.QuickFormatDoc(true);
+ CPPUNIT_ASSERT_EQUAL(true, aEditEngine.IsFormatted());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aEditEngine.GetParagraphCount());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aEditEngine.GetLineCount(0));
+}
+
+void Test::testMoveParagraph()
+{
+ EditEngine aEditEngine(mpItemPool.get());
+ aEditEngine.SetPaperSize(Size(5000, 5000));
+ aEditEngine.SetText("Paragraph 1\nParagraph 2\nParagraph 3\nParagraph 4\nParagraph 5");
+
+ CPPUNIT_ASSERT_EQUAL(true, aEditEngine.IsFormatted());
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aEditEngine.GetParagraphCount());
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 1"), aEditEngine.GetText(0));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 2"), aEditEngine.GetText(1));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 3"), aEditEngine.GetText(2));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 4"), aEditEngine.GetText(3));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 5"), aEditEngine.GetText(4));
+
+ aEditEngine.MoveParagraphs(Range(1, 1), 4); // Move paragraph 2 (index 1) -> to before index 4
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aEditEngine.GetParagraphCount());
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 1"), aEditEngine.GetText(0));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 3"), aEditEngine.GetText(1));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 4"), aEditEngine.GetText(2));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 2"), aEditEngine.GetText(3));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 5"), aEditEngine.GetText(4));
+
+ aEditEngine.MoveParagraphs(Range(3, 3), 1); // Move paragraph 2 (index 3) -> to before index 1
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aEditEngine.GetParagraphCount());
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 1"), aEditEngine.GetText(0));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 2"), aEditEngine.GetText(1));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 3"), aEditEngine.GetText(2));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 4"), aEditEngine.GetText(3));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 5"), aEditEngine.GetText(4));
+
+ aEditEngine.MoveParagraphs(Range(1, 2), 4); // Move paragraph 2, 3 -> to before index 4
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aEditEngine.GetParagraphCount());
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 1"), aEditEngine.GetText(0));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 4"), aEditEngine.GetText(1));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 2"), aEditEngine.GetText(2));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 3"), aEditEngine.GetText(3));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 5"), aEditEngine.GetText(4));
+
+ aEditEngine.MoveParagraphs(Range(2, 3), 1); // Move paragraph 2, 3 -> to before index 2
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aEditEngine.GetParagraphCount());
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 1"), aEditEngine.GetText(0));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 2"), aEditEngine.GetText(1));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 3"), aEditEngine.GetText(2));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 4"), aEditEngine.GetText(3));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 5"), aEditEngine.GetText(4));
+
+ aEditEngine.MoveParagraphs(Range(2, 4), 0); // Move paragraph 3, 4, 5 -> to before index 0
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aEditEngine.GetParagraphCount());
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 3"), aEditEngine.GetText(0));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 4"), aEditEngine.GetText(1));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 5"), aEditEngine.GetText(2));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 1"), aEditEngine.GetText(3));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 2"), aEditEngine.GetText(4));
+
+ aEditEngine.MoveParagraphs(Range(0, 2), 5); // Move paragraph 3, 4, 5 -> to before index 0
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aEditEngine.GetParagraphCount());
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 1"), aEditEngine.GetText(0));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 2"), aEditEngine.GetText(1));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 3"), aEditEngine.GetText(2));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 4"), aEditEngine.GetText(3));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 5"), aEditEngine.GetText(4));
+
+ aEditEngine.MoveParagraphs(Range(0, 0), 8); // Move paragraph 1 -> to before index 8 but 8 is out of bounds
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aEditEngine.GetParagraphCount());
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 2"), aEditEngine.GetText(0));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 3"), aEditEngine.GetText(1));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 4"), aEditEngine.GetText(2));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 5"), aEditEngine.GetText(3));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 1"), aEditEngine.GetText(4));
+
+ aEditEngine.MoveParagraphs(Range(4, 4), 0); // Move paragraph 1 -> to before index 0
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aEditEngine.GetParagraphCount());
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 1"), aEditEngine.GetText(0));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 2"), aEditEngine.GetText(1));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 3"), aEditEngine.GetText(2));
+ CPPUNIT_ASSERT_EQUAL(OUString("Paragraph 4"), aEditEngine.GetText(3));
+ 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\nABC 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.getRef(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.getRef(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);
+}
+
+void Test::testTdf154248MultilineFieldWrapping()
+{
+ // If field wrapping changes, this test may need to be updated
+
+ // Create Outliner instance
+ Outliner aOutliner(mpItemPool.get(), OutlinerMode::TextObject);
+ aOutliner.SetCalcFieldValueHdl(LINK(nullptr, Test, CalcFieldValueHdl));
+
+ // Create EditEngine's instance
+ EditEngine& aEditEngine = const_cast<EditEngine&>(aOutliner.GetEditEngine());
+ aEditEngine.SetPaperSize(Size(2000, 2000));
+ aEditEngine.SetText("ABC DEF ABC DEFGH");
+ // Positions Ref ....*4............
+
+ // Get Field Item for inserting URLs in text
+ SvxURLField aURLField("http://not.a.real.link",
+ "Really long hyperlink text that won't fit in 1 line, no matter what.",
+ SvxURLFormat::Repr);
+ SvxFieldItem aField(aURLField, EE_FEATURE_FIELD);
+
+ // Insert URL
+ EditDoc& rDoc = aEditEngine.GetEditDoc();
+ ContentNode* pNode = rDoc.GetObject(0);
+ EditSelection aSel(EditPaM(pNode, 4), EditPaM(pNode, 4));
+ aEditEngine.InsertField(aSel, aField);
+
+ // Assert Field Count
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), aEditEngine.GetFieldCount(0));
+
+ aEditEngine.QuickFormatDoc(false);
+ CPPUNIT_ASSERT_EQUAL(true, aEditEngine.IsFormatted());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aEditEngine.GetParagraphCount());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aEditEngine.GetLineCount(0));
+
+ ParaPortionList& rParagraphPortionList = aEditEngine.GetParaPortions();
+ EditLineList& rLines = rParagraphPortionList.getRef(0).GetLines();
+ {
+ EditLine const& rLine = rLines[0];
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rLine.GetStart());
+ // Line 1 contains the beginning of the link.
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), rLine.GetEnd());
+ }
+
+ {
+ EditLine const& rLine = rLines[1];
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), rLine.GetStart());
+ //Line 2 contains the end of the link and the text that follows it
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(14), rLine.GetEnd());
+ }
+
+ {
+ EditLine const& rLine = rLines[2];
+ //line 3 contains the last word that does not fit in line 2
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(14), rLine.GetStart());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(19), rLine.GetEnd());
+ }
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);