diff --git a/sc/CppunitTest_sc_dynamic_array_functions_test.mk b/sc/CppunitTest_sc_dynamic_array_functions_test.mk new file mode 100644 index 000000000000..36ea8374aa98 --- /dev/null +++ b/sc/CppunitTest_sc_dynamic_array_functions_test.mk @@ -0,0 +1,14 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; fill-column: 100 -*- +# +# Copyright the LibreOffice contributors. +# +# SPDX-License-Identifier: MPL-2.0 +# +# 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 sc_functions_test,dynamic_array)) + +# vim: set noet sw=4 ts=4: diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk index 67a9b16769b3..2cffd84db342 100644 --- a/sc/Module_sc.mk +++ b/sc/Module_sc.mk @@ -140,6 +140,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sc, \ CppunitTest_sc_spreadsheet_functions_test \ CppunitTest_sc_statistical_functions_test \ CppunitTest_sc_text_functions_test \ + CppunitTest_sc_dynamic_array_functions_test \ CppunitTest_sc_annotationobj \ CppunitTest_sc_annotationshapeobj \ CppunitTest_sc_annotationsobj \ diff --git a/sc/functions_setup.mk b/sc/functions_setup.mk index 2a0c78c8fca9..80ea4d57b4ff 100644 --- a/sc/functions_setup.mk +++ b/sc/functions_setup.mk @@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_use_externals,sc_$(1)_functions_test, \ boost_headers \ mdds_headers \ md4c \ + libxml2 \ )) $(eval $(call gb_CppunitTest_use_libraries,sc_$(1)_functions_test, \ @@ -44,6 +45,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_$(1)_functions_test, \ scqahelper \ sfx \ sot \ + subsequenttest \ svl \ svt \ svx \ diff --git a/sc/qa/unit/data/functions/dynamic_array/xlsx/DynamicArrayFixture.xlsx b/sc/qa/unit/data/functions/dynamic_array/xlsx/DynamicArrayFixture.xlsx new file mode 100644 index 000000000000..e3c262cece91 Binary files /dev/null and b/sc/qa/unit/data/functions/dynamic_array/xlsx/DynamicArrayFixture.xlsx differ diff --git a/sc/qa/unit/functions_dynamic_array.cxx b/sc/qa/unit/functions_dynamic_array.cxx new file mode 100644 index 000000000000..9a4c75002c11 --- /dev/null +++ b/sc/qa/unit/functions_dynamic_array.cxx @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * Copyright the LibreOffice contributors. + * + * SPDX-License-Identifier: MPL-2.0 + * + * 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 "helper/qahelper.hxx" + +#include +#include +#include + +class DynamicArrayTest : public ScModelTestBase +{ +public: + DynamicArrayTest() + : ScModelTestBase(u"sc/qa/unit/data"_ustr) + { + } +}; + +namespace +{ +// Walk column C from row 5 down to nLastRow on the given sheet. +// Every non-empty C cell is a per-row equality comparison that the +// fixture expects to evaluate to 1. A failure reports the row that +// disagreed so the offending scenario is easy to spot. +void assertRowChecks(ScDocument& rDocument, SCTAB nTab, SCROW nLastRow) +{ + for (SCROW nRow = 4; nRow <= nLastRow; ++nRow) + { + ScAddress aPosition(2, nRow, nTab); + if (rDocument.GetCellType(aPosition) == CELLTYPE_NONE) + continue; + const double fValue = rDocument.GetValue(aPosition); + if (fValue == 1.0) + continue; + const OString aLabel = "Sheet" + OString::number(nTab + 1) + " C" + + OString::number(nRow + 1) + + " verdict cell did not evaluate to TRUE"; + CPPUNIT_ASSERT_EQUAL_MESSAGE(aLabel.getStr(), 1.0, fValue); + } +} +} + +CPPUNIT_TEST_FIXTURE(DynamicArrayTest, testDynamicArrayXlsxRoundTrip) +{ + createScDoc("functions/dynamic_array/xlsx/DynamicArrayFixture.xlsx"); + + auto checkVerdicts = [this]() { + ScDocument* pDocument = getScDoc(); + // Sheet 1 "CSE Array Spill Cases", master cell A3 = AND(C5:C400). + assertRowChecks(*pDocument, 0, 399); + CPPUNIT_ASSERT_EQUAL(1.0, pDocument->GetValue(ScAddress(0, 2, 0))); + // Sheet 2 "Implicit intersection Operator", master cell A3 = AND(C5:C200). + assertRowChecks(*pDocument, 1, 199); + CPPUNIT_ASSERT_EQUAL(1.0, pDocument->GetValue(ScAddress(0, 2, 1))); + // Sheet 3 "Spill Operator", master cell A3 = AND(C5:C508). + assertRowChecks(*pDocument, 2, 507); + CPPUNIT_ASSERT_EQUAL(1.0, pDocument->GetValue(ScAddress(0, 2, 2))); + }; + + // The self-checking workbook holds after import, and again after an + // XLSX save and reload. + checkVerdicts(); + saveAndReload(TestFilter::XLSX); + checkVerdicts(); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */