editeng/CppunitTest_editeng_core.mk |    1 
 editeng/inc/editdoc.hxx             |   24 --------
 editeng/qa/unit/EPaMTest.cxx        |  103 ++++++++++++++++++++++++++++++++++++
 include/editeng/EPaM.hxx            |   69 ++++++++++++++++++++++++
 4 files changed, 174 insertions(+), 23 deletions(-)

New commits:
commit ff0a9cb65ae5d862575b091c44e114c117e9f3b5
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Tue Dec 5 23:13:42 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Dec 28 08:05:43 2023 +0100

    editeng: add EPaM unit tests
    
    Change-Id: Icc15746bf2712bae446f16fd378f94f8be5ec61e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161342
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/editeng/CppunitTest_editeng_core.mk 
b/editeng/CppunitTest_editeng_core.mk
index 67a3c949555b..43df48cbe38a 100644
--- a/editeng/CppunitTest_editeng_core.mk
+++ b/editeng/CppunitTest_editeng_core.mk
@@ -14,6 +14,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,editeng_core))
 $(eval $(call gb_CppunitTest_add_exception_objects,editeng_core, \
     editeng/qa/unit/core-test \
     editeng/qa/unit/ESelectionTest \
+    editeng/qa/unit/EPaMTest \
 ))
 
 $(eval $(call gb_CppunitTest_use_library_objects,editeng_core,editeng))
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/include/editeng/EPaM.hxx b/include/editeng/EPaM.hxx
index c61d77577cbf..85ad4bd2b6ee 100644
--- a/include/editeng/EPaM.hxx
+++ b/include/editeng/EPaM.hxx
@@ -59,4 +59,11 @@ inline bool EPaM::operator==(const EPaM& r) const
     return (nPara == r.nPara) && (nIndex == r.nIndex);
 }
 
+template <typename charT, typename traits>
+inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, 
traits>& stream,
+                                                     EPaM const& aPaM)
+{
+    return stream << "EPaM(" << aPaM.nPara << ',' << aPaM.nIndex << ")";
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 9c40b820280843450cab4287d7cfbdc0988064e4
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Tue Dec 5 23:12:09 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Dec 28 08:05:35 2023 +0100

    editeng: move EPaM in its own header file
    
    Change-Id: Ib3682dd5df09162748aad4402108b2b3cec3a853
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161341
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/editeng/inc/editdoc.hxx b/editeng/inc/editdoc.hxx
index 16eaf157a91f..1450cc560833 100644
--- a/editeng/inc/editdoc.hxx
+++ b/editeng/inc/editdoc.hxx
@@ -23,6 +23,7 @@
 #include "edtspell.hxx"
 #include "eerdll2.hxx"
 #include <editeng/svxfont.hxx>
+#include <editeng/EPaM.hxx>
 #include <svl/itemset.hxx>
 #include <svl/style.hxx>
 #include <svl/itempool.hxx>
@@ -52,29 +53,6 @@ EditCharAttrib* MakeCharAttrib( SfxItemPool& rPool, const 
SfxPoolItem& rAttr, sa
 class ContentNode;
 class EditDoc;
 
-struct EPaM
-{
-    sal_Int32  nPara;
-    sal_Int32  nIndex;
-
-    EPaM() : nPara(0), nIndex(0) {}
-    EPaM( sal_Int32 nP, sal_Int32 nI ) : nPara(nP), nIndex(nI) {}
-    EPaM( const EPaM& r) : nPara(r.nPara), nIndex(r.nIndex) {}
-    EPaM& operator = ( const EPaM& r )  { nPara = r.nPara; nIndex = r.nIndex; 
return *this; }
-    inline bool operator == ( const EPaM& r ) const;
-    inline bool operator < ( const EPaM& r ) const;
-};
-
-inline bool EPaM::operator < ( const EPaM& r ) const
-{
-    return ( nPara < r.nPara ) || ( ( nPara == r.nPara ) && nIndex < r.nIndex 
);
-}
-
-inline bool EPaM::operator == ( const EPaM& r ) const
-{
-    return ( nPara == r.nPara ) && ( nIndex == r.nIndex );
-}
-
 struct ScriptTypePosInfo
 {
     short   nScriptType;
diff --git a/include/editeng/EPaM.hxx b/include/editeng/EPaM.hxx
new file mode 100644
index 000000000000..c61d77577cbf
--- /dev/null
+++ b/include/editeng/EPaM.hxx
@@ -0,0 +1,62 @@
+/* -*- 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+struct EPaM
+{
+    sal_Int32 nPara;
+    sal_Int32 nIndex;
+
+    EPaM()
+        : nPara(0)
+        , nIndex(0)
+    {
+    }
+    EPaM(sal_Int32 nP, sal_Int32 nI)
+        : nPara(nP)
+        , nIndex(nI)
+    {
+    }
+    EPaM(const EPaM& r)
+        : nPara(r.nPara)
+        , nIndex(r.nIndex)
+    {
+    }
+    EPaM& operator=(const EPaM& r)
+    {
+        nPara = r.nPara;
+        nIndex = r.nIndex;
+        return *this;
+    }
+    inline bool operator==(const EPaM& r) const;
+    inline bool operator<(const EPaM& r) const;
+};
+
+inline bool EPaM::operator<(const EPaM& r) const
+{
+    return (nPara < r.nPara) || ((nPara == r.nPara) && nIndex < r.nIndex);
+}
+
+inline bool EPaM::operator==(const EPaM& r) const
+{
+    return (nPara == r.nPara) && (nIndex == r.nIndex);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to