From 88424a4adca388c8708b164751a4144a62814224 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Fri, 10 Jul 2020 14:59:43 +0200 Subject: tdf#107902: sc_macros_test: Add unittest Change-Id: I6fb494944c51a06ffec955e900f146e748f8f2f9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98522 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- sc/qa/extras/macros-test.cxx | 46 ++++++++++++++++++++++++++++++ sc/qa/extras/testdocuments/tdf107902.xlsm | Bin 0 -> 13948 bytes 2 files changed, 46 insertions(+) create mode 100644 sc/qa/extras/testdocuments/tdf107902.xlsm diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx index 502b9ba6d8ee..2630484e4122 100644 --- a/sc/qa/extras/macros-test.cxx +++ b/sc/qa/extras/macros-test.cxx @@ -16,6 +16,8 @@ #include #include +#include +#include #include @@ -39,6 +41,7 @@ public: void testRowColumn(); void testTdf131562(); void testPasswordProtectedUnicodeString(); + void testTdf107902(); void testTdf131296_legacy(); void testTdf131296_new(); @@ -51,6 +54,7 @@ public: CPPUNIT_TEST(testRowColumn); CPPUNIT_TEST(testTdf131562); CPPUNIT_TEST(testPasswordProtectedUnicodeString); + CPPUNIT_TEST(testTdf107902); CPPUNIT_TEST(testTdf131296_legacy); CPPUNIT_TEST(testTdf131296_new); @@ -529,6 +533,48 @@ void ScMacrosTest::testPasswordProtectedUnicodeString() xCloseable->close(true); } +void ScMacrosTest::testTdf107902() +{ + OUString aFileName; + createFileURL("tdf107902.xlsm", aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + CPPUNIT_ASSERT_MESSAGE("Failed to load the doc", xComponent.is()); + + Any aRet; + Sequence< sal_Int16 > aOutParamIndex; + Sequence< Any > aOutParam; + Sequence< uno::Any > aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + //Without the fix in place, it would have failed with 'Unexpected dialog: Error: BASIC runtime error.' + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:VBAProject.Module1.AF?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + //Check the autofilter was created + const ScPatternAttr* pPattern = rDoc.GetPattern(0, 0, 0); + CPPUNIT_ASSERT(pPattern); + + const ScMergeFlagAttr& rAttr = pPattern->GetItem(ATTR_MERGE_FLAG); + CPPUNIT_ASSERT_MESSAGE("Autofilter was not created", rAttr.HasAutoFilter()); + + //Check the last row is hidden + CPPUNIT_ASSERT(!rDoc.RowHidden(0,0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(1,0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(2,0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(3,0)); + CPPUNIT_ASSERT(rDoc.RowHidden(4,0)); + + pDocSh->DoClose(); +} + void ScMacrosTest::testTdf131296_legacy() { // For legacy password-protected library images, we must correctly get the constants' values, diff --git a/sc/qa/extras/testdocuments/tdf107902.xlsm b/sc/qa/extras/testdocuments/tdf107902.xlsm new file mode 100644 index 000000000000..f5333959b0e5 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf107902.xlsm differ -- cgit