From 2fa01ae540e174452bf5cd763c1464cfe37af076 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Tue, 29 Mar 2022 16:41:56 +0200 Subject: tdf#125800: sc_macros: Add unittest Change-Id: I9286264bbfa1e59e51d2a94417f7e8526357f821 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132277 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- sc/qa/extras/macros-test.cxx | 48 +++++++++++++++++++++++++++++++ sc/qa/extras/testdocuments/tdf125800.ods | Bin 0 -> 14245 bytes 2 files changed, 48 insertions(+) create mode 100644 sc/qa/extras/testdocuments/tdf125800.ods (limited to 'sc') diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx index 88195ac74153..98c469ee2217 100644 --- a/sc/qa/extras/macros-test.cxx +++ b/sc/qa/extras/macros-test.cxx @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -67,6 +68,7 @@ public: void testTdf105558(); void testTdf143582(); void testTdf144085(); + void testTdf125800(); void testTdf130307(); void testTdf146742(); void testMacroButtonFormControlXlsxExport(); @@ -100,6 +102,7 @@ public: CPPUNIT_TEST(testTdf105558); CPPUNIT_TEST(testTdf143582); CPPUNIT_TEST(testTdf144085); + CPPUNIT_TEST(testTdf125800); CPPUNIT_TEST(testTdf130307); CPPUNIT_TEST(testTdf146742); CPPUNIT_TEST(testMacroButtonFormControlXlsxExport); @@ -925,6 +928,51 @@ void ScMacrosTest::testTdf144085() xCloseable->close(true); } +void ScMacrosTest::testTdf125800() +{ + OUString aFileName; + createFileURL(u"tdf125800.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + css::uno::Any aRet; + css::uno::Sequence aParams; + css::uno::Sequence aOutParam; + css::uno::Sequence aOutParamIndex; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + ScConditionalFormat* pFormat = rDoc.GetCondFormat(1, 2, 0); + CPPUNIT_ASSERT(!pFormat); + + // Without the fix in place, this test would have failed with + // - Expression: false + // - Unexpected dialog: Error: Inadmissible value or data type. Index out of defined range. + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.cf.doItForThisSheetindexThisRange?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + OUString aReturnValue; + aRet >>= aReturnValue; + + pFormat = rDoc.GetCondFormat(1, 2, 0); + CPPUNIT_ASSERT(pFormat); + + const ScFormatEntry* pEntry = pFormat->GetEntry(0); + CPPUNIT_ASSERT(pEntry); + CPPUNIT_ASSERT_EQUAL(ScFormatEntry::Type::Condition, pEntry->GetType()); + + const ScCondFormatEntry* pCondition = static_cast(pEntry); + CPPUNIT_ASSERT_EQUAL(ScConditionMode::Direct, pCondition->GetOperation()); + + css::uno::Reference xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + void ScMacrosTest::testTdf130307() { OUString aFileName; diff --git a/sc/qa/extras/testdocuments/tdf125800.ods b/sc/qa/extras/testdocuments/tdf125800.ods new file mode 100644 index 000000000000..91f000d749ab Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf125800.ods differ -- cgit