sc/CppunitTest_sc_basic_types_test.mk | 36 ++++++++++++ sc/Module_sc.mk | 1 sc/inc/SheetView.hxx | 2 sc/qa/unit/types/SortOrderReverserTest.cxx | 81 +++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 1 deletion(-)
New commits: commit 1beb44f601667af3424e0f665e97accf3bfb4ca4 Author: Tomaž Vajngerl <[email protected]> AuthorDate: Fri Sep 12 23:14:52 2025 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Jan 23 10:34:59 2026 +0100 sc: add unit test for SortOrderReverser Add the unit test to the basic types test suite. The unit test checks the unsort function when using different sort orders. It also checks combining the sort orders with addOrderIndices function. Change-Id: I298918b971e3386b8ea513c09879045e25010ad9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190911 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197821 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/sc/CppunitTest_sc_basic_types_test.mk b/sc/CppunitTest_sc_basic_types_test.mk new file mode 100644 index 000000000000..b04bc25ea13f --- /dev/null +++ b/sc/CppunitTest_sc_basic_types_test.mk @@ -0,0 +1,36 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# 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/. +# +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,sc_basic_types_test)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sc_basic_types_test,\ + sc/qa/unit/types/SortOrderReverserTest \ +)) + +$(eval $(call gb_CppunitTest_use_external,sc_basic_types_test,boost_headers)) + +$(eval $(call gb_CppunitTest_set_include,sc_basic_types_test,\ + -I$(SRCDIR)/sc/source/ui/inc \ + -I$(SRCDIR)/sc/source/core/inc \ + -I$(SRCDIR)/sc/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sc_basic_types_test,\ + sc \ + scui \ +)) + +# Needed for include/test/cppunitasserthelper.hxx +$(eval $(call gb_CppunitTest_use_sdk_api,sc_basic_types_test)) + + +# vim: set noet sw=4 ts=4: diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk index 723eba9acbf1..7046e10e2918 100644 --- a/sc/Module_sc.mk +++ b/sc/Module_sc.mk @@ -61,6 +61,7 @@ $(eval $(call gb_Module_add_check_targets,sc,\ CppunitTest_sc_filters_test \ CppunitTest_sc_mark_test \ CppunitTest_sc_core \ + CppunitTest_sc_basic_types_test \ CppunitTest_sc_dataprovider \ CppunitTest_sc_cache_test \ CppunitTest_sc_parallelism \ 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..a6808d5c6a87 --- /dev/null +++ b/sc/qa/unit/types/SortOrderReverserTest.cxx @@ -0,0 +1,81 @@ +/* -*- 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())); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
