From dcff97abcd4e8d31032c316892cb09b5742ca1ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Vajngerl?= Date: Mon, 15 Jan 2024 12:39:54 +0900 Subject: [PATCH] editeng: add EditLineList test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iaec97999ae9ea0a01251e4449d3c7b74aa3539d0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162072 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- editeng/CppunitTest_editeng_core.mk | 1 + editeng/qa/unit/EditLineListTest.cxx | 173 +++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 editeng/qa/unit/EditLineListTest.cxx diff --git a/editeng/CppunitTest_editeng_core.mk b/editeng/CppunitTest_editeng_core.mk index 9352ddbd83e2..46a232d97f38 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/EditLineListTest \ editeng/qa/unit/EditPaMTest \ editeng/qa/unit/EditSelectionTest \ )) 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 +#include + +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(pEditLine1)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewList.Count()); + + aNewList.Append(std::unique_ptr(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(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()); + aNewList.Append(std::make_unique()); + aNewList.Append(std::make_unique()); + + 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()); + aNewList.Append(std::make_unique()); + aNewList.Append(std::make_unique()); + aNewList.Append(std::make_unique()); + aNewList.Append(std::make_unique()); + + 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()); + aNewList.Append(std::make_unique()); + aNewList.Append(std::make_unique()); + aNewList.Append(std::make_unique()); + + 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(pEditLine1)); + + EditLine* pEditLine2 = new EditLine; + pEditLine2->SetStart(10); + pEditLine2->SetEnd(20); + aNewList.Append(std::unique_ptr(pEditLine2)); + + EditLine* pEditLine3 = new EditLine; + pEditLine3->SetStart(20); + pEditLine3->SetEnd(30); + aNewList.Append(std::unique_ptr(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: */