sc/Library_scqahelper.mk | 1 sc/qa/unit/helper/qahelper.cxx | 58 ++++++++++++++++++++++++++++++++++++ sc/qa/unit/helper/qahelper.hxx | 5 +++ sc/qa/unit/opencl-test-1.cxx | 66 ----------------------------------------- sc/qa/unit/opencl-test-2.cxx | 66 ----------------------------------------- 5 files changed, 64 insertions(+), 132 deletions(-)
New commits: commit 14c12d7a0672148522f0773146f41bb0648f6caa Author: Xisco Fauli <[email protected]> AuthorDate: Tue May 9 16:18:33 2023 +0200 Commit: Xisco Fauli <[email protected]> CommitDate: Tue May 9 19:28:13 2023 +0200 CppunitTest_sc_opencl: factor out common code Change-Id: I5da3d3a0e0f9f18033d8695081501a52aea5bd60 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151586 Tested-by: Jenkins Reviewed-by: Xisco Fauli <[email protected]> diff --git a/sc/Library_scqahelper.mk b/sc/Library_scqahelper.mk index 07d769b77b4d..a4a6814203bd 100644 --- a/sc/Library_scqahelper.mk +++ b/sc/Library_scqahelper.mk @@ -20,6 +20,7 @@ $(eval $(call gb_Library_use_externals,scqahelper, \ mdds_headers \ cppunit \ libxml2 \ + $(call gb_Helper_optional,OPENCL,clew) \ )) ifneq ($(SYSTEM_LIBORCUS),) diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx index af8e5ad8dca1..b5236da1f89e 100644 --- a/sc/qa/unit/helper/qahelper.cxx +++ b/sc/qa/unit/helper/qahelper.cxx @@ -19,6 +19,7 @@ #include <conditio.hxx> #include <stlsheet.hxx> #include <formulacell.hxx> +#include <formulagroup.hxx> #include <svx/svdpage.hxx> #include <svx/svdoole2.hxx> #include <tools/UnitConversion.hxx> @@ -45,6 +46,7 @@ #include <com/sun/star/chart2/XChartDocument.hpp> #include <com/sun/star/chart2/data/XDataReceiver.hpp> +#include <com/sun/star/document/MacroExecMode.hpp> using namespace com::sun::star; using namespace ::com::sun::star::uno; @@ -546,6 +548,13 @@ ScDocument* ScModelTestBase::getScDoc() return pModelObj->GetDocument(); } +ScDocument* ScModelTestBase::getScDoc2() +{ + ScModelObj* pModelObj = comphelper::getFromUnoTunnel<ScModelObj>(mxComponent2); + CPPUNIT_ASSERT(pModelObj); + return pModelObj->GetDocument(); +} + ScDocShell* ScModelTestBase::getScDocShell() { SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); @@ -600,6 +609,55 @@ void ScModelTestBase::miscRowHeightsTest( TestParam const * aTestValues, unsigne } } +void ScModelTestBase::enableOpenCL() +{ + /** + * Turn on OpenCL group interpreter. Call this after the document is + * loaded and before performing formula calculation. + */ + sc::FormulaGroupInterpreter::enableOpenCL_UnitTestsOnly(); +} + +void ScModelTestBase::disableOpenCL() +{ + sc::FormulaGroupInterpreter::disableOpenCL_UnitTestsOnly(); +} + +void ScModelTestBase::initTestEnv(std::u16string_view fileName) +{ + // Some documents contain macros, disable them, otherwise + // the "Error, BASIC runtime error." dialog is prompted + // and it crashes in tearDown + std::vector<beans::PropertyValue> args; + beans::PropertyValue aMacroValue; + aMacroValue.Name = "MacroExecutionMode"; + aMacroValue.Handle = -1; + aMacroValue.Value <<= document::MacroExecMode::NEVER_EXECUTE; + aMacroValue.State = beans::PropertyState_DIRECT_VALUE; + args.push_back(aMacroValue); + + disableOpenCL(); + CPPUNIT_ASSERT(!ScCalcConfig::isOpenCLEnabled()); + + // Open the document with OpenCL disabled + mxComponent = mxDesktop->loadComponentFromURL( + createFileURL(fileName), "_default", 0, comphelper::containerToSequence(args)); + + enableOpenCL(); + CPPUNIT_ASSERT(ScCalcConfig::isOpenCLEnabled()); + + // it's not possible to open the same document twice, thus, create a temp file + createTempCopy(fileName); + + // Open the document with OpenCL enabled + mxComponent2 = mxDesktop->loadComponentFromURL( + maTempFile.GetURL(), "_default", 0, comphelper::containerToSequence(args)); + + // Check there are 2 documents + uno::Reference<frame::XFrames> xFrames = mxDesktop->getFrames(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xFrames->getCount()); +} + ScRange ScUcalcTestBase::insertRangeData( ScDocument* pDoc, const ScAddress& rPos, const std::vector<std::vector<const char*>>& rData ) { diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx index fecf88a6ad0e..4b95451c96d1 100644 --- a/sc/qa/unit/helper/qahelper.hxx +++ b/sc/qa/unit/helper/qahelper.hxx @@ -156,10 +156,15 @@ public: void createScDoc(const char* pName = nullptr, const char* pPassword = nullptr, bool bCheckErrorCode = true); ScDocument* getScDoc(); + ScDocument* getScDoc2(); ScDocShell* getScDocShell(); ScTabViewShell* getViewShell(); void miscRowHeightsTest( TestParam const * aTestValues, unsigned int numElems); + void enableOpenCL(); + void disableOpenCL(); + void initTestEnv(std::u16string_view fileName); + void testFile(const OUString& aFileName, ScDocument& rDoc, SCTAB nTab, StringType aStringFormat = StringType::StringValue); //need own handler because conditional formatting strings must be generated diff --git a/sc/qa/unit/opencl-test-1.cxx b/sc/qa/unit/opencl-test-1.cxx index 773c576b40db..3352ab3e4ad6 100644 --- a/sc/qa/unit/opencl-test-1.cxx +++ b/sc/qa/unit/opencl-test-1.cxx @@ -8,9 +8,7 @@ #include <docsh.hxx> #include <document.hxx> -#include <formulagroup.hxx> -#include <com/sun/star/document/MacroExecMode.hpp> #include <comphelper/sequence.hxx> #include <comphelper/servicehelper.hxx> @@ -23,13 +21,6 @@ class ScOpenCLTest1 public: ScOpenCLTest1(); - /** - * Turn on OpenCL group interpreter. Call this after the document is - * loaded and before performing formula calculation. - */ - void enableOpenCL(); - void disableOpenCL(); - void testSystematic(); void testSharedFormulaXLS(); #if 0 @@ -269,65 +260,8 @@ public: CPPUNIT_TEST(testMathFormulaCoth); CPPUNIT_TEST(testFinacialNPER1Formula); CPPUNIT_TEST_SUITE_END(); - -private: - void initTestEnv(std::u16string_view fileName); - - ScDocument* getScDoc2(); }; -void ScOpenCLTest1::initTestEnv(std::u16string_view fileName) -{ - // Some documents contain macros, disable them, otherwise - // the "Error, BASIC runtime error." dialog is prompted - // and it crashes in tearDown - std::vector<beans::PropertyValue> args; - beans::PropertyValue aMacroValue; - aMacroValue.Name = "MacroExecutionMode"; - aMacroValue.Handle = -1; - aMacroValue.Value <<= document::MacroExecMode::NEVER_EXECUTE; - aMacroValue.State = beans::PropertyState_DIRECT_VALUE; - args.push_back(aMacroValue); - - disableOpenCL(); - CPPUNIT_ASSERT(!ScCalcConfig::isOpenCLEnabled()); - - // Open the document with OpenCL disabled - mxComponent = mxDesktop->loadComponentFromURL( - createFileURL(fileName), "_default", 0, comphelper::containerToSequence(args)); - - enableOpenCL(); - CPPUNIT_ASSERT(ScCalcConfig::isOpenCLEnabled()); - - // it's not possible to open the same document twice, thus, create a temp file - createTempCopy(fileName); - - // Open the document with OpenCL enabled - mxComponent2 = mxDesktop->loadComponentFromURL( - maTempFile.GetURL(), "_default", 0, comphelper::containerToSequence(args)); - - // Check there are 2 documents - uno::Reference<frame::XFrames> xFrames = mxDesktop->getFrames(); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xFrames->getCount()); -} - -ScDocument* ScOpenCLTest1::getScDoc2() -{ - ScModelObj* pModelObj = comphelper::getFromUnoTunnel<ScModelObj>(mxComponent2); - CPPUNIT_ASSERT(pModelObj); - return pModelObj->GetDocument(); -} - -void ScOpenCLTest1::enableOpenCL() -{ - sc::FormulaGroupInterpreter::enableOpenCL_UnitTestsOnly(); -} - -void ScOpenCLTest1::disableOpenCL() -{ - sc::FormulaGroupInterpreter::disableOpenCL_UnitTestsOnly(); -} - void ScOpenCLTest1::testCompilerHorizontal() { initTestEnv(u"ods/opencl/compiler/horizontal.ods"); diff --git a/sc/qa/unit/opencl-test-2.cxx b/sc/qa/unit/opencl-test-2.cxx index a99808da19c4..a53613560e71 100644 --- a/sc/qa/unit/opencl-test-2.cxx +++ b/sc/qa/unit/opencl-test-2.cxx @@ -8,9 +8,7 @@ #include <docsh.hxx> #include <document.hxx> -#include <formulagroup.hxx> -#include <com/sun/star/document/MacroExecMode.hpp> #include <comphelper/sequence.hxx> #include <comphelper/servicehelper.hxx> @@ -23,13 +21,6 @@ class ScOpenCLTest2 public: ScOpenCLTest2(); - /** - * Turn on OpenCL group interpreter. Call this after the document is - * loaded and before performing formula calculation. - */ - void enableOpenCL(); - void disableOpenCL(); - void testStatisticalFormulaFDist(); void testStatisticalFormulaVar(); void testStatisticalFormulaChiDist(); @@ -257,65 +248,8 @@ public: CPPUNIT_TEST(testStatisticalFormulaStDevPA1); CPPUNIT_TEST(testFinancialMDurationFormula1); CPPUNIT_TEST_SUITE_END(); - -private: - void initTestEnv(std::u16string_view fileName); - - ScDocument* getScDoc2(); }; -void ScOpenCLTest2::initTestEnv(std::u16string_view fileName) -{ - // Some documents contain macros, disable them, otherwise - // the "Error, BASIC runtime error." dialog is prompted - // and it crashes in tearDown - std::vector<beans::PropertyValue> args; - beans::PropertyValue aMacroValue; - aMacroValue.Name = "MacroExecutionMode"; - aMacroValue.Handle = -1; - aMacroValue.Value <<= document::MacroExecMode::NEVER_EXECUTE; - aMacroValue.State = beans::PropertyState_DIRECT_VALUE; - args.push_back(aMacroValue); - - disableOpenCL(); - CPPUNIT_ASSERT(!ScCalcConfig::isOpenCLEnabled()); - - // Open the document with OpenCL disabled - mxComponent = mxDesktop->loadComponentFromURL( - createFileURL(fileName), "_default", 0, comphelper::containerToSequence(args)); - - enableOpenCL(); - CPPUNIT_ASSERT(ScCalcConfig::isOpenCLEnabled()); - - // it's not possible to open the same document twice, thus, create a temp file - createTempCopy(fileName); - - // Open the document with OpenCL enabled - mxComponent2 = mxDesktop->loadComponentFromURL( - maTempFile.GetURL(), "_default", 0, comphelper::containerToSequence(args)); - - // Check there are 2 documents - uno::Reference<frame::XFrames> xFrames = mxDesktop->getFrames(); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xFrames->getCount()); -} - -ScDocument* ScOpenCLTest2::getScDoc2() -{ - ScModelObj* pModelObj = comphelper::getFromUnoTunnel<ScModelObj>(mxComponent2); - CPPUNIT_ASSERT(pModelObj); - return pModelObj->GetDocument(); -} - -void ScOpenCLTest2::enableOpenCL() -{ - sc::FormulaGroupInterpreter::enableOpenCL_UnitTestsOnly(); -} - -void ScOpenCLTest2::disableOpenCL() -{ - sc::FormulaGroupInterpreter::disableOpenCL_UnitTestsOnly(); -} - void ScOpenCLTest2::testMathFormulaPi() { initTestEnv(u"xls/opencl/math/pi.xls");
