diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-12-24 22:34:40 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-12-30 14:16:43 +0100 |
commit | 72fde57386eb7b53f4b1a0954a1595e36cf17e5f (patch) | |
tree | 2322902c6976c0e056d12019366444b5b9fcae56 /editeng | |
parent | 7de4661827c5bed7beaf2c286242e48cfe4154e8 (diff) |
editeng: EditLine test and refactor constructors, operators
Change-Id: Ia60ce07073725bf66bf299edaf7b3cd24cfe59c0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161358
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/CppunitTest_editeng_core.mk | 1 | ||||
-rw-r--r-- | editeng/inc/EditLine.hxx | 58 | ||||
-rw-r--r-- | editeng/qa/unit/EditLineTest.cxx | 111 | ||||
-rw-r--r-- | editeng/source/editeng/editdoc.cxx | 63 |
4 files changed, 154 insertions, 79 deletions
diff --git a/editeng/CppunitTest_editeng_core.mk b/editeng/CppunitTest_editeng_core.mk index 43df48cbe38a..d28c7fcb4365 100644 --- a/editeng/CppunitTest_editeng_core.mk +++ b/editeng/CppunitTest_editeng_core.mk @@ -15,6 +15,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,editeng_core, \ editeng/qa/unit/core-test \ editeng/qa/unit/ESelectionTest \ editeng/qa/unit/EPaMTest \ + editeng/qa/unit/EditLineTest \ )) $(eval $(call gb_CppunitTest_use_library_objects,editeng_core,editeng)) diff --git a/editeng/inc/EditLine.hxx b/editeng/inc/EditLine.hxx index 2b6bc2a71efb..df1dec9f0ae2 100644 --- a/editeng/inc/EditLine.hxx +++ b/editeng/inc/EditLine.hxx @@ -29,22 +29,29 @@ public: private: CharPosArrayType aPositions; std::vector<sal_Bool> aKashidaPositions; - sal_Int32 nTxtWidth; - sal_Int32 nStartPosX; - sal_Int32 nStart; // could be replaced by nStartPortion - sal_Int32 nEnd; // could be replaced by nEndPortion - sal_Int32 nStartPortion; - sal_Int32 nEndPortion; - sal_uInt16 nHeight; // Total height of the line - sal_uInt16 nTxtHeight; // Pure Text height - sal_uInt16 nMaxAscent; - bool bHangingPunctuation : 1; - bool bInvalid : 1; // for skillful formatting + sal_Int32 nTxtWidth = 0; + sal_Int32 nStartPosX = 0; + sal_Int32 nStart = 0; // could be replaced by nStartPortion + sal_Int32 nEnd = 0; // could be replaced by nEndPortion + sal_Int32 nStartPortion = 0; + sal_Int32 nEndPortion = 0; + sal_uInt16 nHeight = 0; // Total height of the line + sal_uInt16 nTxtHeight = 0; // Pure Text height + sal_uInt16 nMaxAscent = 0; + bool bHangingPunctuation : 1 = false; + bool bInvalid : 1 = true; // for skillful formatting public: - EditLine(); - EditLine(const EditLine&); - ~EditLine(); + EditLine() = default; + EditLine(const EditLine& rEditLine) + : nStart(rEditLine.nStart) + , nEnd(rEditLine.nEnd) + , nStartPortion(rEditLine.nStartPortion) + , nEndPortion(rEditLine.nEndPortion) + , bHangingPunctuation(rEditLine.bHangingPunctuation) + , bInvalid(true) + { + } bool IsIn(sal_Int32 nIndex) const { return ((nIndex >= nStart) && (nIndex < nEnd)); } @@ -103,8 +110,27 @@ public: EditLine* Clone() const; - EditLine& operator=(const EditLine& rLine); - friend bool operator==(const EditLine& r1, const EditLine& r2); + EditLine& operator=(const EditLine& rLine) + { + nEnd = rLine.nEnd; + nStart = rLine.nStart; + nEndPortion = rLine.nEndPortion; + nStartPortion = rLine.nStartPortion; + return *this; + } + + bool operator==(const EditLine& rLine) const + { + return nStart == rLine.nStart && nEnd == rLine.nEnd && nStartPortion == rLine.nStartPortion + && nEndPortion == rLine.nEndPortion; + } }; +template <typename charT, typename traits> +inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& stream, + EditLine const& rLine) +{ + return stream << "EditLine(" << rLine.GetStart() << ", " << rLine.GetEnd() << ")"; +} + /* 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/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx index 0d6ce0f315c4..313648d24277 100644 --- a/editeng/source/editeng/editdoc.cxx +++ b/editeng/source/editeng/editdoc.cxx @@ -890,42 +890,6 @@ void ConvertAndPutItems( SfxItemSet& rDest, const SfxItemSet& rSource, const Map } } -EditLine::EditLine() : - nTxtWidth(0), - nStartPosX(0), - nStart(0), - nEnd(0), - nStartPortion(0), // to be able to tell the difference between a line - // without Portions from one with the Portion number 0 - nEndPortion(0), - nHeight(0), - nTxtHeight(0), - nMaxAscent(0), - bHangingPunctuation(false), - bInvalid(true) -{ -} - -EditLine::EditLine( const EditLine& r ) : - nTxtWidth(0), - nStartPosX(0), - nStart(r.nStart), - nEnd(r.nEnd), - nStartPortion(r.nStartPortion), - nEndPortion(r.nEndPortion), - nHeight(0), - nTxtHeight(0), - nMaxAscent(0), - bHangingPunctuation(r.bHangingPunctuation), - bInvalid(true) -{ -} - -EditLine::~EditLine() -{ -} - - EditLine* EditLine::Clone() const { EditLine* pL = new EditLine; @@ -943,33 +907,6 @@ EditLine* EditLine::Clone() const return pL; } -bool operator == ( const EditLine& r1, const EditLine& r2 ) -{ - if ( r1.nStart != r2.nStart ) - return false; - - if ( r1.nEnd != r2.nEnd ) - return false; - - if ( r1.nStartPortion != r2.nStartPortion ) - return false; - - if ( r1.nEndPortion != r2.nEndPortion ) - return false; - - return true; -} - -EditLine& EditLine::operator = ( const EditLine& r ) -{ - nEnd = r.nEnd; - nStart = r.nStart; - nEndPortion = r.nEndPortion; - nStartPortion = r.nStartPortion; - return *this; -} - - void EditLine::SetHeight( sal_uInt16 nH, sal_uInt16 nTxtH ) { nHeight = nH; |