editeng/CppunitTest_editeng_core.mk |    1 
 editeng/inc/EditPaM.hxx             |   18 +++++---
 editeng/qa/unit/EditPaMTest.cxx     |   74 ++++++++++++++++++++++++++++++++++++
 editeng/source/editeng/editdoc.cxx  |   20 ---------
 4 files changed, 86 insertions(+), 27 deletions(-)

New commits:
commit ac481d5df48c9db1f662903af52a5dd50bbe66df
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon Dec 25 00:41:53 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Sun Dec 31 07:49:39 2023 +0100

    editeng: cleanup operators and constructors for EditPaM + test
    
    Move the constructors into class body, cleanup operators so they
    use more standard class based operators and use default for !=
    as it will just be a neagtion of ==.
    
    Change-Id: I6534db60dcb23cb3daefb91d5f27579a690a9637
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161364
    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 d28c7fcb4365..47be49fbcd96 100644
--- a/editeng/CppunitTest_editeng_core.mk
+++ b/editeng/CppunitTest_editeng_core.mk
@@ -16,6 +16,7 @@ $(eval $(call 
gb_CppunitTest_add_exception_objects,editeng_core, \
     editeng/qa/unit/ESelectionTest \
     editeng/qa/unit/EPaMTest \
     editeng/qa/unit/EditLineTest \
+    editeng/qa/unit/EditPaMTest \
 ))
 
 $(eval $(call gb_CppunitTest_use_library_objects,editeng_core,editeng))
diff --git a/editeng/inc/EditPaM.hxx b/editeng/inc/EditPaM.hxx
index 2aa733f5ea74..9a33ad5a0990 100644
--- a/editeng/inc/EditPaM.hxx
+++ b/editeng/inc/EditPaM.hxx
@@ -26,24 +26,28 @@ class EditDoc;
 class EditPaM
 {
 private:
-    ContentNode* pNode;
-    sal_Int32 nIndex;
+    ContentNode* pNode = nullptr;
+    sal_Int32 nIndex = 0;
 
 public:
-    EditPaM();
-    EditPaM(ContentNode* p, sal_Int32 n);
+    EditPaM() = default;
+    EditPaM(ContentNode* p, sal_Int32 n)
+        : pNode(p)
+        , nIndex(n)
+    {
+    }
 
     const ContentNode* GetNode() const { return pNode; }
     ContentNode* GetNode() { return pNode; }
-    void SetNode(ContentNode* p);
+    void SetNode(ContentNode* p) { pNode = p; }
 
     sal_Int32 GetIndex() const { return nIndex; }
     void SetIndex(sal_Int32 n) { nIndex = n; }
 
     bool DbgIsBuggy(EditDoc const& rDoc) const;
 
-    friend bool operator==(const EditPaM& r1, const EditPaM& r2);
-    friend bool operator!=(const EditPaM& r1, const EditPaM& r2);
+    bool operator==(const EditPaM& rOther) const = default;
+
     bool operator!() const { return !pNode && !nIndex; }
 };
 
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/source/editeng/editdoc.cxx 
b/editeng/source/editeng/editdoc.cxx
index 153cc25dfc1f..d61683619a84 100644
--- a/editeng/source/editeng/editdoc.cxx
+++ b/editeng/source/editeng/editdoc.cxx
@@ -890,15 +890,6 @@ void ConvertAndPutItems( SfxItemSet& rDest, const 
SfxItemSet& rSource, const Map
     }
 }
 
-EditPaM::EditPaM() : pNode(nullptr), nIndex(0) {}
-EditPaM::EditPaM(ContentNode* p, sal_Int32 n) : pNode(p), nIndex(n) {}
-
-
-void EditPaM::SetNode(ContentNode* p)
-{
-    pNode = p;
-}
-
 bool EditPaM::DbgIsBuggy( EditDoc const & rDoc ) const
 {
     return !pNode ||
@@ -960,17 +951,6 @@ void EditSelection::Adjust( const EditDoc& rNodes )
     }
 }
 
-bool operator == ( const EditPaM& r1, const EditPaM& r2 )
-{
-    return ( r1.GetNode() == r2.GetNode() ) &&
-           ( r1.GetIndex() == r2.GetIndex() );
-}
-
-bool operator != ( const EditPaM& r1, const EditPaM& r2 )
-{
-    return !( r1 == r2 );
-}
-
 EditDoc::EditDoc( SfxItemPool* pPool ) :
     nLastCache(0),
     pItemPool(pPool ? pPool : new EditEngineItemPool()),

Reply via email to