sc/CppunitTest_sc_basic_types_test.mk | 4 + sc/inc/SheetView.hxx | 2 sc/qa/unit/types/SortOrderReverserTest.cxx | 79 +++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-)
New commits: commit a8dcbc862b4c77b3dc9142f5e4598adb5681e9a7 Author: Tomaž Vajngerl <[email protected]> AuthorDate: Fri Sep 12 23:14:52 2025 +0200 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Wed Dec 17 07:16:49 2025 +0100 sc: add unit test for SortOrderReverser Add the unit test to the basic types test suite. The unit test checks the unosrt function when using different sort orders. It also checks combining the sort orders with addOrderIndices function. Additionally move the existing ScAddressTest to the "types" folder. Change-Id: I298918b971e3386b8ea513c09879045e25010ad9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190911 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/sc/CppunitTest_sc_basic_types_test.mk b/sc/CppunitTest_sc_basic_types_test.mk index c9ef8faaaa1a..5a417a22b7c8 100644 --- a/sc/CppunitTest_sc_basic_types_test.mk +++ b/sc/CppunitTest_sc_basic_types_test.mk @@ -13,6 +13,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,sc_basic_types_test)) $(eval $(call gb_CppunitTest_add_exception_objects,sc_basic_types_test,\ sc/qa/unit/types/ScAddressTest \ + sc/qa/unit/types/SortOrderReverserTest \ )) $(eval $(call gb_CppunitTest_use_external,sc_basic_types_test,boost_headers)) @@ -25,7 +26,8 @@ $(eval $(call gb_CppunitTest_set_include,sc_basic_types_test,\ )) $(eval $(call gb_CppunitTest_use_libraries,sc_basic_types_test,\ - sal \ + sc \ + scui \ )) # Needed for include/test/cppunitasserthelper.hxx diff --git a/sc/inc/SheetView.hxx b/sc/inc/SheetView.hxx index 3a45450c9d79..9cbc5d7489f7 100644 --- a/sc/inc/SheetView.hxx +++ b/sc/inc/SheetView.hxx @@ -20,7 +20,7 @@ class ScTable; namespace sc { /** Stores the sort order and can reverse the sorting of rows (unsorting). */ -struct SortOrderReverser +struct SC_DLLPUBLIC SortOrderReverser { public: SCROW mnFirstRow; diff --git a/sc/qa/unit/types/SortOrderReverserTest.cxx b/sc/qa/unit/types/SortOrderReverserTest.cxx new file mode 100644 index 000000000000..0e550e1742cf --- /dev/null +++ b/sc/qa/unit/types/SortOrderReverserTest.cxx @@ -0,0 +1,79 @@ +/* -*- 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 <cppunit/plugin/TestPlugIn.h> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +#include <SheetView.hxx> + +class SortOrderReverserTest : public CppUnit::TestFixture +{ +}; + +CPPUNIT_TEST_FIXTURE(SortOrderReverserTest, testUnsort) +{ + // Unchanged order - output rows should be the same as input + { + sc::SortOrderReverser aReverser; + aReverser.addOrderIndices({ 1, 2, 3, 4 }, 5, 8); + + CPPUNIT_ASSERT_EQUAL(SCROW(5), aReverser.unsort(5)); + CPPUNIT_ASSERT_EQUAL(SCROW(6), aReverser.unsort(6)); + CPPUNIT_ASSERT_EQUAL(SCROW(7), aReverser.unsort(7)); + CPPUNIT_ASSERT_EQUAL(SCROW(8), aReverser.unsort(8)); + } + + // Reversed order - output rows should be in reverse order than input + { + sc::SortOrderReverser aReverser; + aReverser.addOrderIndices({ 4, 3, 2, 1 }, 5, 8); + + CPPUNIT_ASSERT_EQUAL(SCROW(8), aReverser.unsort(5)); + CPPUNIT_ASSERT_EQUAL(SCROW(7), aReverser.unsort(6)); + CPPUNIT_ASSERT_EQUAL(SCROW(6), aReverser.unsort(7)); + CPPUNIT_ASSERT_EQUAL(SCROW(5), aReverser.unsort(8)); + } + + // Some random order - output rows should follow the order + { + sc::SortOrderReverser aReverser; + aReverser.addOrderIndices({ 3, 1, 4, 2 }, 5, 8); + + CPPUNIT_ASSERT_EQUAL(SCROW(7), aReverser.unsort(5)); + CPPUNIT_ASSERT_EQUAL(SCROW(5), aReverser.unsort(6)); + CPPUNIT_ASSERT_EQUAL(SCROW(8), aReverser.unsort(7)); + CPPUNIT_ASSERT_EQUAL(SCROW(6), aReverser.unsort(8)); + } +} + +CPPUNIT_TEST_FIXTURE(SortOrderReverserTest, testCombiningSortOrder) +{ + sc::SortOrderReverser aReverser; + + // first sorting order + aReverser.addOrderIndices({ 3, 1, 4, 2 }, 5, 8); + + // second sorting order - only reverses the order + aReverser.addOrderIndices({ 4, 3, 2, 1 }, 5, 8); + + // check + CPPUNIT_ASSERT_EQUAL(SCROW(6), aReverser.unsort(5)); + CPPUNIT_ASSERT_EQUAL(SCROW(8), aReverser.unsort(6)); + CPPUNIT_ASSERT_EQUAL(SCROW(5), aReverser.unsort(7)); + CPPUNIT_ASSERT_EQUAL(SCROW(7), aReverser.unsort(8)); + + // directly compare the order + std::vector<SCCOLROW> aExpectedOrder{ 2, 4, 1, 3 }; + CPPUNIT_ASSERT( + std::equal(aExpectedOrder.begin(), aExpectedOrder.end(), aReverser.maOrder.begin())); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
