sc/qa/unit/helper/shared_test_impl.hxx | 159 --------------------------------- sc/qa/unit/subsequent_export_test3.cxx | 105 ++++++++++++++++++++- sc/qa/unit/subsequent_filters_test.cxx | 19 --- solenv/clang-format/excludelist | 1 4 files changed, 98 insertions(+), 186 deletions(-)
New commits: commit a8ab9597b481c7e8e8ab8e672fa4f99c036bed55 Author: Xisco Fauli <[email protected]> AuthorDate: Tue Jul 1 09:56:57 2025 +0200 Commit: Xisco Fauli <[email protected]> CommitDate: Tue Jul 1 11:49:46 2025 +0200 sc: drop shared_test_impl and move code together also test import and export in one place Change-Id: I0137b4f218b12ef94fe7046c863db35a7b216d41 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187224 Tested-by: Jenkins Reviewed-by: Xisco Fauli <[email protected]> diff --git a/sc/qa/unit/helper/shared_test_impl.hxx b/sc/qa/unit/helper/shared_test_impl.hxx deleted file mode 100644 index 1d016329a508..000000000000 --- a/sc/qa/unit/helper/shared_test_impl.hxx +++ /dev/null @@ -1,159 +0,0 @@ -/* -*- 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/. - */ - -#pragma once - -#include <memory> -#include <document.hxx> -#include <formulacell.hxx> -#include "qahelper.hxx" -#include <formula/errorcodes.hxx> - -bool isFormulaWithoutError(ScDocument& rDoc, const ScAddress& rPos) -{ - ScFormulaCell* pFC = rDoc.GetFormulaCell(rPos); - if (!pFC) - return false; - - return pFC->GetErrCode() == FormulaError::NONE; -} - -void testFunctionsExcel2010_Impl( ScDocument& rDoc ) -{ - // Original test case document is functions-excel-2010.xlsx - // Which test rows to evaluate, 1-based as in UI to ease maintenance. - static struct - { - SCROW nRow; - bool bEvaluate; - } const aTests[] = { - { 2, false }, // name=[ AGGREGATE ], result=0, expected=1 - { 3, true }, - { 4, true }, - { 5, true }, - { 6, true }, - { 7, true }, - { 8, true }, - { 9, true }, - { 10, true }, - { 11, true }, - { 12, true }, - { 13, true }, - { 14, true }, - { 15, true }, - { 16, true }, - { 17, true }, - { 18, true }, - { 19, true }, - { 20, true }, - { 21, true }, - { 22, true }, - { 23, true }, - { 24, true }, - { 25, true }, - { 26, true }, - { 27, true }, - { 28, true }, - { 29, true }, - { 30, true }, - { 31, true }, - { 32, true }, - { 33, true }, - { 34, true }, - { 35, true }, - { 36, true }, - { 37, true }, - { 38, true }, - { 39, true }, - { 40, true }, - { 41, true }, - { 42, true }, - { 43, true }, - { 44, true }, - { 45, false }, // name=[ NETWORKDAYS.INTL ], result=18, expected=19 - { 46, true }, - { 47, true }, - { 48, true }, - { 49, true }, - { 50, true }, - { 51, true }, - { 52, true }, - { 53, true }, - { 54, true }, - { 55, true }, - { 56, true }, - { 57, true }, - { 58, true }, - { 59, true }, - { 60, true }, - { 61, true }, - { 62, true }, - { 63, true }, - { 64, true }, - { 65, true }, - { 66, true }, - { 67, true }, - { 68, true }, - { 69, true }, - { 70, true }, - { 71, true }, - { 72, true }, - { 73, true }, - { 74, true }, - { 75, true }, - { 76, true }, - { 77, true }, - { 78, true }, - { 79, false }, // name=[ WORKDAY.INTL ], result=41755 , expected=41754 - { 80, true } - }; - - for (size_t i=0; i < std::size(aTests); ++i) - { - if (aTests[i].bEvaluate) - { - // Column 0 is description, 1 is formula, 2 is Excel result, 3 is - // comparison. - SCROW nRow = aTests[i].nRow - 1; // 0-based - - OString aStr = OString::number( aTests[i].nRow) + - ", function name=[ " + - OUStringToOString( rDoc.GetString( ScAddress( 0, nRow, 0)), RTL_TEXTENCODING_UTF8 ) + - " ], result=" + - OString::number( rDoc.GetValue( ScAddress( 1, nRow, 0)) ) + - ", expected=" + - OString::number( rDoc.GetValue( ScAddress( 2, nRow, 0)) ); - - ScFormulaCell* pFC = rDoc.GetFormulaCell( ScAddress( 1, nRow, 0) ); - if ( pFC && pFC->GetErrCode() != FormulaError::NONE ) - aStr += ", error code =" + OString::number( static_cast<int>(pFC->GetErrCode()) ); - - CPPUNIT_ASSERT_MESSAGE( OString( "Expected a formula cell without error at row " + - aStr ).getStr(), isFormulaWithoutError( rDoc, ScAddress( 1, nRow, 0))); - CPPUNIT_ASSERT_MESSAGE( OString( "Expected a TRUE value at row " + - aStr ).getStr(), 0 != rDoc.GetValue( ScAddress( 3, nRow, 0))); - - } - } -} - -void testCeilingFloor_Impl( ScDocument& rDoc ) -{ - // Original test case document is ceiling-floor.xlsx - // Sheet1.K1 has =AND(K3:K81) to evaluate all results. - static constexpr OUString pORef = u"Sheet1.K1"_ustr; - ScAddress aPos; - aPos.Parse(pORef, rDoc); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong formula.", u"=AND(K3:K81)"_ustr, rDoc.GetFormula(aPos.Col(), aPos.Row(), aPos.Tab())); - CPPUNIT_ASSERT_MESSAGE( OUString( pORef + " result is error.").toUtf8().getStr(), - isFormulaWithoutError( rDoc, aPos)); - CPPUNIT_ASSERT_EQUAL(1.0, rDoc.GetValue(aPos)); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/unit/subsequent_export_test3.cxx b/sc/qa/unit/subsequent_export_test3.cxx index 7cbbda4192c6..efc5cd7ea231 100644 --- a/sc/qa/unit/subsequent_export_test3.cxx +++ b/sc/qa/unit/subsequent_export_test3.cxx @@ -8,13 +8,14 @@ */ #include "helper/qahelper.hxx" -#include "helper/shared_test_impl.hxx" +#include <formulacell.hxx> #include <userdat.hxx> #include <tokenstringcontext.hxx> #include <chgtrack.hxx> #include <scmod.hxx> +#include <formula/errorcodes.hxx> #include <svx/svdpage.hxx> #include <svx/svdograf.hxx> #include <svx/svdomeas.hxx> @@ -871,15 +872,100 @@ CPPUNIT_TEST_FIXTURE(ScExportTest3, testSharedFormulaStringResultExportXLSX) CPPUNIT_ASSERT_MESSAGE("Content check on the reloaded document failed.", bRes); } +namespace +{ +bool isFormulaWithoutError(ScDocument& rDoc, const ScAddress& rPos) +{ + ScFormulaCell* pFC = rDoc.GetFormulaCell(rPos); + if (!pFC) + return false; + + return pFC->GetErrCode() == FormulaError::NONE; +} + +void testFunctionsExcel2010_Impl(ScDocument& rDoc) +{ + // Original test case document is functions-excel-2010.xlsx + // Which test rows to evaluate, 1-based as in UI to ease maintenance. + static struct + { + SCROW nRow; + bool bEvaluate; + } const aTests[] = { + { 2, false }, // name=[ AGGREGATE ], result=0, expected=1 + { 3, true }, { 4, true }, { 5, true }, { 6, true }, { 7, true }, { 8, true }, + { 9, true }, { 10, true }, { 11, true }, { 12, true }, { 13, true }, { 14, true }, + { 15, true }, { 16, true }, { 17, true }, { 18, true }, { 19, true }, { 20, true }, + { 21, true }, { 22, true }, { 23, true }, { 24, true }, { 25, true }, { 26, true }, + { 27, true }, { 28, true }, { 29, true }, { 30, true }, { 31, true }, { 32, true }, + { 33, true }, { 34, true }, { 35, true }, { 36, true }, { 37, true }, { 38, true }, + { 39, true }, { 40, true }, { 41, true }, { 42, true }, { 43, true }, { 44, true }, + { 45, false }, // name=[ NETWORKDAYS.INTL ], result=18, expected=19 + { 46, true }, { 47, true }, { 48, true }, { 49, true }, { 50, true }, { 51, true }, + { 52, true }, { 53, true }, { 54, true }, { 55, true }, { 56, true }, { 57, true }, + { 58, true }, { 59, true }, { 60, true }, { 61, true }, { 62, true }, { 63, true }, + { 64, true }, { 65, true }, { 66, true }, { 67, true }, { 68, true }, { 69, true }, + { 70, true }, { 71, true }, { 72, true }, { 73, true }, { 74, true }, { 75, true }, + { 76, true }, { 77, true }, { 78, true }, { 79, false }, // name=[ WORKDAY.INTL ], result=41755 , expected=41754 + { 80, true } + }; + + for (size_t i = 0; i < std::size(aTests); ++i) + { + if (aTests[i].bEvaluate) + { + // Column 0 is description, 1 is formula, 2 is Excel result, 3 is + // comparison. + SCROW nRow = aTests[i].nRow - 1; // 0-based + + OString aStr + = OString::number(aTests[i].nRow) + ", function name=[ " + + OUStringToOString(rDoc.GetString(ScAddress(0, nRow, 0)), RTL_TEXTENCODING_UTF8) + + " ], result=" + OString::number(rDoc.GetValue(ScAddress(1, nRow, 0))) + + ", expected=" + OString::number(rDoc.GetValue(ScAddress(2, nRow, 0))); + + ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(1, nRow, 0)); + if (pFC && pFC->GetErrCode() != FormulaError::NONE) + aStr += ", error code =" + OString::number(static_cast<int>(pFC->GetErrCode())); + + CPPUNIT_ASSERT_MESSAGE( + OString("Expected a formula cell without error at row " + aStr).getStr(), + isFormulaWithoutError(rDoc, ScAddress(1, nRow, 0))); + CPPUNIT_ASSERT_MESSAGE(OString("Expected a TRUE value at row " + aStr).getStr(), + 0 != rDoc.GetValue(ScAddress(3, nRow, 0))); + } + } +} + +void testCeilingFloor_Impl(ScDocument& rDoc) +{ + // Original test case document is ceiling-floor.xlsx + // Sheet1.K1 has =AND(K3:K81) to evaluate all results. + static constexpr OUString pORef = u"Sheet1.K1"_ustr; + ScAddress aPos; + aPos.Parse(pORef, rDoc); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong formula.", u"=AND(K3:K81)"_ustr, + rDoc.GetFormula(aPos.Col(), aPos.Row(), aPos.Tab())); + CPPUNIT_ASSERT_MESSAGE(OUString(pORef + " result is error.").toUtf8().getStr(), + isFormulaWithoutError(rDoc, aPos)); + CPPUNIT_ASSERT_EQUAL(1.0, rDoc.GetValue(aPos)); +} +} + void ScExportTest3::testFunctionsExcel2010(const OUString& sFormatType) { createScDoc("xlsx/functions-excel-2010.xlsx"); - saveAndReload(sFormatType); ScDocument* pDoc = getScDoc(); pDoc->CalcAll(); // perform hard re-calculation. testFunctionsExcel2010_Impl(*pDoc); + + saveAndReload(sFormatType); + pDoc = getScDoc(); + pDoc->CalcAll(); // perform hard re-calculation. + + testFunctionsExcel2010_Impl(*pDoc); } CPPUNIT_TEST_FIXTURE(ScExportTest3, testFunctionsExcel2010XLSX) @@ -898,11 +984,16 @@ void ScExportTest3::testCeilingFloor(const OUString& sFormatType) { createScDoc("xlsx/ceiling-floor.xlsx"); - saveAndReload(sFormatType); ScDocument* pDoc = getScDoc(); pDoc->CalcAll(); // perform hard re-calculation. testCeilingFloor_Impl(*pDoc); + + saveAndReload(sFormatType); + pDoc = getScDoc(); + pDoc->CalcAll(); // perform hard re-calculation. + + testCeilingFloor_Impl(*pDoc); } CPPUNIT_TEST_FIXTURE(ScExportTest3, testCeilingFloorXLSX) @@ -910,6 +1001,10 @@ CPPUNIT_TEST_FIXTURE(ScExportTest3, testCeilingFloorXLSX) testCeilingFloor(u"Calc Office Open XML"_ustr); } +CPPUNIT_TEST_FIXTURE(ScExportTest3, testCeilingFloorXLS) { testCeilingFloor(u"MS Excel 97"_ustr); } + +CPPUNIT_TEST_FIXTURE(ScExportTest3, testCeilingFloorODS) { testCeilingFloor(u"calc8"_ustr); } + CPPUNIT_TEST_FIXTURE(ScExportTest3, testCeilingFloorODSToXLSX) { // tdf#100011 - Cannot open sheet containing FLOOR/CEILING functions by MS Excel, after export to .xlsx @@ -923,10 +1018,6 @@ CPPUNIT_TEST_FIXTURE(ScExportTest3, testCeilingFloorODSToXLSX) assertXPath(pSheet, "/x:workbook/x:definedNames", 0); } -CPPUNIT_TEST_FIXTURE(ScExportTest3, testCeilingFloorXLS) { testCeilingFloor(u"MS Excel 97"_ustr); } - -CPPUNIT_TEST_FIXTURE(ScExportTest3, testCeilingFloorODS) { testCeilingFloor(u"calc8"_ustr); } - CPPUNIT_TEST_FIXTURE(ScExportTest3, testCustomXml) { // Load document and export it to a temporary file diff --git a/sc/qa/unit/subsequent_filters_test.cxx b/sc/qa/unit/subsequent_filters_test.cxx index 4dcf73791f12..b229f9060018 100644 --- a/sc/qa/unit/subsequent_filters_test.cxx +++ b/sc/qa/unit/subsequent_filters_test.cxx @@ -27,7 +27,6 @@ #include <com/sun/star/sheet/NamedRangeFlag.hdl> #include "helper/qahelper.hxx" -#include "helper/shared_test_impl.hxx" using namespace ::com::sun::star; @@ -672,24 +671,6 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest, testFunctionsODS) testFile(aCSVPath, *pDoc, 0); } -CPPUNIT_TEST_FIXTURE(ScFiltersTest, testFunctionsExcel2010) -{ - createScDoc("xlsx/functions-excel-2010.xlsx"); - ScDocument* pDoc = getScDoc(); - pDoc->CalcAll(); // perform hard re-calculation. - - testFunctionsExcel2010_Impl(*pDoc); -} - -CPPUNIT_TEST_FIXTURE(ScFiltersTest, testCeilingFloorXLSX) -{ - createScDoc("xlsx/ceiling-floor.xlsx"); - ScDocument* pDoc = getScDoc(); - pDoc->CalcAll(); // perform hard re-calculation. - - testCeilingFloor_Impl(*pDoc); -} - CPPUNIT_TEST_FIXTURE(ScFiltersTest, testCachedFormulaResultsODS) { { diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist index 4c870069fac2..14baa4309f5a 100644 --- a/solenv/clang-format/excludelist +++ b/solenv/clang-format/excludelist @@ -7815,7 +7815,6 @@ sc/qa/unit/functions_text.cxx sc/qa/unit/helper/csv_handler.hxx sc/qa/unit/helper/qahelper.cxx sc/qa/unit/helper/qahelper.hxx -sc/qa/unit/helper/shared_test_impl.hxx sc/qa/unit/helper/sorthelper.hxx sc/qa/unit/helper/xpath.cxx sc/qa/unit/helper/xpath.hxx
