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 <quikee@gmail.com>
This commit is contained in:
Tomaž Vajngerl
2023-12-31 07:49:39 +01:00
committed by Tomaž Vajngerl
parent 5c1f9ec049
commit ac481d5df4
4 changed files with 86 additions and 27 deletions
+1
View File
@@ -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))
+11 -7
View File
@@ -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; }
};
+74
View File
@@ -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: */
-20
View File
@@ -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()),