filter/source/msfilter/msvbahelper.cxx | 13 include/oox/ole/vbamodule.hxx | 13 oovbaapi/ooo/vba/excel/XApplication.idl | 1 oox/source/ole/vbamodule.cxx | 29 sc/qa/extras/macros-test.cxx | 329 ------ sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm |binary sc/qa/extras/testdocuments/VariousTestMacros.xlsm |binary sc/qa/extras/vba-macro-test.cxx | 574 ++++++++++++ sc/source/ui/vba/vbaapplication.cxx | 10 sc/source/ui/vba/vbaapplication.hxx | 2 sfx2/source/view/lokhelper.cxx | 11 11 files changed, 630 insertions(+), 352 deletions(-)
New commits: commit 71b420b61637dc59ec8ee1b765d55d6a913962ba Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Mon Jan 31 15:35:38 2022 +0900 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Mon Feb 14 22:31:36 2022 +0100 vba: fix registering shortcuts keys defined by the vba macros On issue with registering was that the registering happened when the macro source was in the process to be read into the library, which is just a bit too early, because the macro wasn't found and not registered. Another issue was with searching for the macro method (hasMacro), which doesn't search the same when the module name is known and when it isn't. This was changed so we just iterate through the modules and call the same "FindMethod" method without any extra restrictions. Change-Id: I2f4f2f6d8186b289867456ebdccad27ce8eee231 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129197 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/filter/source/msfilter/msvbahelper.cxx b/filter/source/msfilter/msvbahelper.cxx index f413af1db651..872b7b863942 100644 --- a/filter/source/msfilter/msvbahelper.cxx +++ b/filter/source/msfilter/msvbahelper.cxx @@ -201,18 +201,17 @@ static bool hasMacro( SfxObjectShell const * pShell, const OUString& sLibrary, O SbModule* pModule = pBasic->FindModule( sMod ); if ( pModule && pModule->FindMethod( sMacro, SbxClassType::Method )) { - bFound = true; + return true; } } - else if( SbMethod* pMethod = dynamic_cast< SbMethod* >( pBasic->Find( sMacro, SbxClassType::Method ) ) ) + else { - if( SbModule* pModule = pMethod->GetModule() ) + for (auto const& rModuleRef : pBasic->GetModules()) { - // when searching for a macro without module name, do not search in class/document/form modules - if( pModule->GetModuleType() == script::ModuleType::NORMAL ) + if (rModuleRef && rModuleRef->FindMethod(sMacro, SbxClassType::Method)) { - sMod = pModule->GetName(); - bFound = true; + sMod = rModuleRef->GetName(); + return true; } } } diff --git a/include/oox/ole/vbamodule.hxx b/include/oox/ole/vbamodule.hxx index b6a615ef6ba6..3028136375bc 100644 --- a/include/oox/ole/vbamodule.hxx +++ b/include/oox/ole/vbamodule.hxx @@ -24,6 +24,7 @@ #include <rtl/textenc.h> #include <rtl/ustring.hxx> #include <sal/types.h> +#include <vector> namespace com::sun::star { namespace container { class XNameAccess; } @@ -39,6 +40,11 @@ namespace oox { namespace oox::ole { +struct VbaKeyBinding +{ + OUString msApiKey; + OUString msMethodName; +}; class VbaModule { @@ -67,15 +73,17 @@ public: void createAndImportModule( StorageBase& rVbaStrg, const css::uno::Reference< css::container::XNameContainer >& rxBasicLib, - const css::uno::Reference< css::container::XNameAccess >& rxDocObjectNA ) const; + const css::uno::Reference< css::container::XNameAccess >& rxDocObjectNA ); /** Creates an empty Basic module in the passed Basic library. */ void createEmptyModule( const css::uno::Reference< css::container::XNameContainer >& rxBasicLib, const css::uno::Reference< css::container::XNameAccess >& rxDocObjectNA ) const; + void registerShortcutKeys(); + private: /** Reads and returns the VBA source code from the passed storage. */ - OUString readSourceCode( StorageBase& rVbaStrg ) const; + OUString readSourceCode( StorageBase& rVbaStrg ); /** Creates a new Basic module and inserts it into the passed Basic library. */ void createModule( @@ -97,6 +105,7 @@ private: bool mbReadOnly; bool mbPrivate; bool mbExecutable; + std::vector<VbaKeyBinding> maKeyBindings; }; diff --git a/oox/source/ole/vbamodule.cxx b/oox/source/ole/vbamodule.cxx index ade0bd97aeae..0fc9609653f3 100644 --- a/oox/source/ole/vbamodule.cxx +++ b/oox/source/ole/vbamodule.cxx @@ -127,10 +127,26 @@ void VbaModule::importDirRecords( BinaryInputStream& rDirStrm ) void VbaModule::createAndImportModule( StorageBase& rVbaStrg, const Reference< container::XNameContainer >& rxBasicLib, - const Reference< container::XNameAccess >& rxDocObjectNA ) const + const Reference< container::XNameAccess >& rxDocObjectNA ) { OUString aVBASourceCode = readSourceCode( rVbaStrg ); createModule( aVBASourceCode, rxBasicLib, rxDocObjectNA ); + registerShortcutKeys(); +} + +void VbaModule::registerShortcutKeys() +{ + for (VbaKeyBinding const& rKeyBinding : maKeyBindings) + { + try + { + KeyEvent aKeyEvent = ooo::vba::parseKeyEvent(rKeyBinding.msApiKey); + ooo::vba::applyShortCutKeyBinding(mxDocModel, aKeyEvent, rKeyBinding.msMethodName); + } + catch (const Exception&) + { + } + } } void VbaModule::createEmptyModule( const Reference< container::XNameContainer >& rxBasicLib, @@ -139,7 +155,7 @@ void VbaModule::createEmptyModule( const Reference< container::XNameContainer >& createModule( u"", rxBasicLib, rxDocObjectNA ); } -OUString VbaModule::readSourceCode( StorageBase& rVbaStrg ) const +OUString VbaModule::readSourceCode( StorageBase& rVbaStrg ) { OUStringBuffer aSourceCode(512); static const char sUnmatchedRemovedTag[] = "Rem removed unmatched Sub/End: "; @@ -189,14 +205,7 @@ OUString VbaModule::readSourceCode( StorageBase& rVbaStrg ) const // cntrl modifier is explicit ( but could be cntrl+shift ), parseKeyEvent // will handle and uppercase letter appropriately OUString sApiKey = "^" + sKey; - try - { - KeyEvent aKeyEvent = ooo::vba::parseKeyEvent( sApiKey ); - ooo::vba::applyShortCutKeyBinding( mxDocModel, aKeyEvent, sProc ); - } - catch (const Exception&) - { - } + maKeyBindings.push_back({sApiKey, sProc}); } } } commit 09eecfd6a66c4f41d77a291b9b6a7aa579cb35e1 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Wed Jan 26 16:54:12 2022 +0900 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Mon Feb 14 22:31:14 2022 +0100 vba: add tests for scrolling, range selecting, print area This adds various tests involving scrolling to a particular cell in the document, selecting whole ranges or ranges o filled cells and setting the print area. VBA functions: ActiveWindow.ScrollColumn ActiveWindow.ScrollRow Selection Selection.End(xlToRight) ActiveSheet.PageSetup.PrintArea Change-Id: Iacde9c513b41571e98234c12cc3b42a16de4b833 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129014 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/sc/qa/extras/vba-macro-test.cxx b/sc/qa/extras/vba-macro-test.cxx index 51d8c36cbded..ac93cf181d0b 100644 --- a/sc/qa/extras/vba-macro-test.cxx +++ b/sc/qa/extras/vba-macro-test.cxx @@ -21,6 +21,8 @@ #include <scitems.hxx> #include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XPrintAreas.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> using namespace css; @@ -48,7 +50,11 @@ public: void testSimpleCopyAndPaste(); void testMultiDocumentCopyAndPaste(); void testSheetAndColumnSelectAndHide(); + void testPrintArea(); + void testSelectAllChaged(); + void testRangeSelect(); void testWindowState(); + void testScroll(); void testVba(); void testTdf107885(); @@ -60,7 +66,11 @@ public: CPPUNIT_TEST(testSimpleCopyAndPaste); CPPUNIT_TEST(testMultiDocumentCopyAndPaste); CPPUNIT_TEST(testSheetAndColumnSelectAndHide); + CPPUNIT_TEST(testPrintArea); + CPPUNIT_TEST(testSelectAllChaged); + CPPUNIT_TEST(testRangeSelect); CPPUNIT_TEST(testWindowState); + CPPUNIT_TEST(testScroll); CPPUNIT_TEST(testVba); CPPUNIT_TEST(testTdf107885); @@ -233,6 +243,126 @@ void VBAMacroTest::testSheetAndColumnSelectAndHide() CPPUNIT_ASSERT_EQUAL(SCTAB(0), rViewData.GetTabNo()); } +void VBAMacroTest::testPrintArea() +{ + // Sets the print area to A1:B5 + // ActiveSheet.PageSetup.PrintArea = "$A$1:$B$5" + + OUString aFileName; + createFileURL(u"VariousTestMacros.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XPrintAreas> xPrintAreas(xSheet, uno::UNO_QUERY_THROW); + + { + const uno::Sequence<table::CellRangeAddress> aSequence = xPrintAreas->getPrintAreas(); + CPPUNIT_ASSERT_EQUAL(false, aSequence.hasElements()); + } + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + uno::Sequence<uno::Any> aParams; + + SfxObjectShell::CallXScript(mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testPrintArea?" + "language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + { + const uno::Sequence<table::CellRangeAddress> aSequence = xPrintAreas->getPrintAreas(); + CPPUNIT_ASSERT_EQUAL(true, aSequence.hasElements()); + } +} + +void VBAMacroTest::testSelectAllChaged() +{ + // Columns("A:A").Select + // Range(Selection, Selection.End(xlToRight)).Select + + OUString aFileName; + createFileURL(u"VariousTestMacros.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScTabViewShell* pView = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pView != nullptr); + auto const& pViewData = pView->GetViewData(); + + { + ScRange aRange; + pViewData.GetMarkData().GetMarkArea(aRange); + CPPUNIT_ASSERT_EQUAL(ScRange(), aRange); + } + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + uno::Sequence<uno::Any> aParams; + + SfxObjectShell::CallXScript(mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testSelectAll?" + "language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + { + ScRange aRange; + pViewData.GetMarkData().GetMarkArea(aRange); + // A1:E1048576 + CPPUNIT_ASSERT_EQUAL(ScRange(0, 0, 0, 4, MAXROW, 0), aRange); + } +} + +void VBAMacroTest::testRangeSelect() +{ + // Range("B2").Select + // Range(Selection, Selection.End(xlToRight)).Select + + OUString aFileName; + createFileURL(u"VariousTestMacros.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScTabViewShell* pView = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pView != nullptr); + auto const& pViewData = pView->GetViewData(); + + { + ScRange aRange; + pViewData.GetMarkData().GetMarkArea(aRange); + CPPUNIT_ASSERT_EQUAL(ScRange(), aRange); + } + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + uno::Sequence<uno::Any> aParams; + + SfxObjectShell::CallXScript(mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testRangeSelect?" + "language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + { + ScRange aRange; + pViewData.GetMarkData().GetMarkArea(aRange); + // B2:E5 + CPPUNIT_ASSERT_EQUAL(ScRange(1, 1, 0, 4, 1, 0), aRange); + } +} + void VBAMacroTest::testWindowState() { // Application.WindowState = xlMinimized @@ -254,6 +384,42 @@ void VBAMacroTest::testWindowState() aParams, aRet, aOutParamIndex, aOutParam); } +void VBAMacroTest::testScroll() +{ + // ActiveWindow.ScrollColumn = 30 + // ActiveWindow.ScrollRow = 100 + + OUString aFileName; + createFileURL(u"VariousTestMacros.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScTabViewShell* pView = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pView != nullptr); + auto const& rViewData = pView->GetViewData(); + + CPPUNIT_ASSERT_EQUAL(ScSplitPos::SC_SPLIT_BOTTOMLEFT, rViewData.GetActivePart()); + CPPUNIT_ASSERT_EQUAL(SCCOL(0), rViewData.GetPosX(ScHSplitPos::SC_SPLIT_LEFT)); + CPPUNIT_ASSERT_EQUAL(SCROW(0), rViewData.GetPosY(ScVSplitPos::SC_SPLIT_BOTTOM)); + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + uno::Sequence<uno::Any> aParams; + + SfxObjectShell::CallXScript( + mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testScroll?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + CPPUNIT_ASSERT_EQUAL(ScSplitPos::SC_SPLIT_BOTTOMLEFT, rViewData.GetActivePart()); + CPPUNIT_ASSERT_EQUAL(SCCOL(29), rViewData.GetPosX(ScHSplitPos::SC_SPLIT_LEFT)); + CPPUNIT_ASSERT_EQUAL(SCROW(99), rViewData.GetPosY(ScVSplitPos::SC_SPLIT_BOTTOM)); +} + void VBAMacroTest::testVba() { TestMacroInfo testInfo[] = { commit 8a095bdb62be32c3c3a2b7705627f7ff348e50c1 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Wed Jan 26 16:50:41 2022 +0900 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Mon Feb 14 22:31:09 2022 +0100 vba: add support for Application.WindowState + test This just delegates the get/set calls to ActiveWindow.WindowState which is already supported, but calling it directly on Application is also possible. Change-Id: Ibf6f55581a5c66a47ec4dd21cc8d0fe3558330ac Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129013 Tested-by: Tomaž Vajngerl <qui...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/oovbaapi/ooo/vba/excel/XApplication.idl b/oovbaapi/ooo/vba/excel/XApplication.idl index b1bcf46336be..ab6f79655696 100644 --- a/oovbaapi/ooo/vba/excel/XApplication.idl +++ b/oovbaapi/ooo/vba/excel/XApplication.idl @@ -47,6 +47,7 @@ interface XApplication [attribute] boolean DisplayFormulaBar; [attribute] any CutCopyMode; [attribute] any StatusBar; + [attribute] any WindowState; [attribute] long Cursor; [attribute] boolean EnableEvents; [attribute] boolean EnableCancelKey; diff --git a/sc/qa/extras/testdocuments/VariousTestMacros.xlsm b/sc/qa/extras/testdocuments/VariousTestMacros.xlsm new file mode 100644 index 000000000000..455dad654eea Binary files /dev/null and b/sc/qa/extras/testdocuments/VariousTestMacros.xlsm differ diff --git a/sc/qa/extras/vba-macro-test.cxx b/sc/qa/extras/vba-macro-test.cxx index 89639ceb1863..51d8c36cbded 100644 --- a/sc/qa/extras/vba-macro-test.cxx +++ b/sc/qa/extras/vba-macro-test.cxx @@ -48,6 +48,8 @@ public: void testSimpleCopyAndPaste(); void testMultiDocumentCopyAndPaste(); void testSheetAndColumnSelectAndHide(); + void testWindowState(); + void testVba(); void testTdf107885(); void testTdf131562(); @@ -58,6 +60,7 @@ public: CPPUNIT_TEST(testSimpleCopyAndPaste); CPPUNIT_TEST(testMultiDocumentCopyAndPaste); CPPUNIT_TEST(testSheetAndColumnSelectAndHide); + CPPUNIT_TEST(testWindowState); CPPUNIT_TEST(testVba); CPPUNIT_TEST(testTdf107885); @@ -230,6 +233,27 @@ void VBAMacroTest::testSheetAndColumnSelectAndHide() CPPUNIT_ASSERT_EQUAL(SCTAB(0), rViewData.GetTabNo()); } +void VBAMacroTest::testWindowState() +{ + // Application.WindowState = xlMinimized + // Application.WindowState = xlMaximized + // Application.WindowState = xlNormal + + OUString aFileName; + createFileURL(u"VariousTestMacros.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + uno::Sequence<uno::Any> aParams; + + SfxObjectShell::CallXScript(mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testWindowState?" + "language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); +} + void VBAMacroTest::testVba() { TestMacroInfo testInfo[] = { diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx index 494ee9c27b97..67ebacfb6ad9 100644 --- a/sc/source/ui/vba/vbaapplication.cxx +++ b/sc/source/ui/vba/vbaapplication.cxx @@ -488,6 +488,16 @@ ScVbaApplication::getStatusBar() return uno::makeAny( !getDisplayStatusBar() ); } +css::uno::Any SAL_CALL ScVbaApplication::getWindowState() +{ + return getActiveWindow()->getWindowState(); +} + +void SAL_CALL ScVbaApplication::setWindowState(const css::uno::Any& rWindowState) +{ + getActiveWindow()->setWindowState(rWindowState); +} + void SAL_CALL ScVbaApplication::setStatusBar( const uno::Any& _statusbar ) { diff --git a/sc/source/ui/vba/vbaapplication.hxx b/sc/source/ui/vba/vbaapplication.hxx index 09d2b02d3b59..db9c91cdd677 100644 --- a/sc/source/ui/vba/vbaapplication.hxx +++ b/sc/source/ui/vba/vbaapplication.hxx @@ -109,6 +109,8 @@ public: virtual void SAL_CALL setCutCopyMode( const css::uno::Any& _cutcopymode ) override; virtual css::uno::Any SAL_CALL getStatusBar() override; virtual void SAL_CALL setStatusBar( const css::uno::Any& _statusbar ) override; + virtual css::uno::Any SAL_CALL getWindowState() override; + virtual void SAL_CALL setWindowState(const css::uno::Any& rWindowState) override; virtual ::sal_Int32 SAL_CALL getCursor() override; virtual void SAL_CALL setCursor( ::sal_Int32 _cursor ) override; virtual void SAL_CALL OnKey( const OUString& Key, const css::uno::Any& Procedure ) override; commit 751c2d8f5cb6c19c59a94ca8991bb3d9cbcaa703 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Jan 25 16:14:32 2022 +0900 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Mon Feb 14 22:31:02 2022 +0100 vba: test for selcting and hiding columns from a VBA Macro Change-Id: Ib954a98e3cf91253c416f358a114bf6b6eb549b3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129012 Tested-by: Tomaž Vajngerl <qui...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm b/sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm new file mode 100644 index 000000000000..684480c3ff04 Binary files /dev/null and b/sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm differ diff --git a/sc/qa/extras/vba-macro-test.cxx b/sc/qa/extras/vba-macro-test.cxx index b4736fc689cc..89639ceb1863 100644 --- a/sc/qa/extras/vba-macro-test.cxx +++ b/sc/qa/extras/vba-macro-test.cxx @@ -12,6 +12,8 @@ #include <osl/file.hxx> #include <sal/log.hxx> #include <vcl/svapp.hxx> +#include <viewdata.hxx> +#include <tabvwsh.hxx> #include <docsh.hxx> #include <document.hxx> @@ -45,6 +47,7 @@ public: void testSimpleCopyAndPaste(); void testMultiDocumentCopyAndPaste(); + void testSheetAndColumnSelectAndHide(); void testVba(); void testTdf107885(); void testTdf131562(); @@ -54,6 +57,8 @@ public: CPPUNIT_TEST_SUITE(VBAMacroTest); CPPUNIT_TEST(testSimpleCopyAndPaste); CPPUNIT_TEST(testMultiDocumentCopyAndPaste); + CPPUNIT_TEST(testSheetAndColumnSelectAndHide); + CPPUNIT_TEST(testVba); CPPUNIT_TEST(testTdf107885); CPPUNIT_TEST(testTdf131562); @@ -153,6 +158,78 @@ void VBAMacroTest::testMultiDocumentCopyAndPaste() CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(1, 3, 0))); } +void VBAMacroTest::testSheetAndColumnSelectAndHide() +{ + OUString aFileName; + createFileURL(u"SheetAndColumnSelectAndHide.xlsm", aFileName); + mxComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(mxComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + ScTabViewShell* pView = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pView != nullptr); + auto const& rViewData = pView->GetViewData(); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(1, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(2, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(3, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(4, 1)); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(1, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(2, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(3, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(4, 2)); + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + uno::Sequence<uno::Any> aParams; + + SfxObjectShell::CallXScript( + mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testHide?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 1)); + CPPUNIT_ASSERT(rDoc.ColHidden(1, 1)); + CPPUNIT_ASSERT(rDoc.ColHidden(2, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(3, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(4, 1)); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(1, 2)); + CPPUNIT_ASSERT(rDoc.ColHidden(2, 2)); + CPPUNIT_ASSERT(rDoc.ColHidden(3, 2)); + CPPUNIT_ASSERT(rDoc.ColHidden(4, 2)); + + CPPUNIT_ASSERT_EQUAL(SCTAB(0), rViewData.GetTabNo()); + + SfxObjectShell::CallXScript( + mxComponent, + "vnd.sun.Star.script:VBAProject.ThisWorkbook.testUnhide?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(1, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(2, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(3, 1)); + CPPUNIT_ASSERT(!rDoc.ColHidden(4, 1)); + + CPPUNIT_ASSERT(!rDoc.ColHidden(0, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(1, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(2, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(3, 2)); + CPPUNIT_ASSERT(!rDoc.ColHidden(4, 2)); + + CPPUNIT_ASSERT_EQUAL(SCTAB(0), rViewData.GetTabNo()); +} + void VBAMacroTest::testVba() { TestMacroInfo testInfo[] = { commit 2046f91283b2505cb7b9daa72c1f6213d9a2afb8 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Fri Jan 21 16:04:42 2022 +0100 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Mon Feb 14 22:30:52 2022 +0100 sc: move vba tests to the new vba-macro-test file Change-Id: Iaec40b8a1d5bce5d9a96447fee5102dc18a16f59 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128736 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx index cf732e2dd294..a774129f5ae7 100644 --- a/sc/qa/extras/macros-test.cxx +++ b/sc/qa/extras/macros-test.cxx @@ -45,17 +45,13 @@ public: const OUString& rFilter); void testStarBasic(); - void testVba(); void testMSP(); void testPasswordProtectedStarBasic(); void testTdf114427(); - void testTdf107885(); void testRowColumn(); void testTdf142033(); - void testTdf131562(); void testPasswordProtectedUnicodeString(); void testPasswordProtectedArrayInUserType(); - void testTdf107902(); void testTdf131296_legacy(); void testTdf131296_new(); void testTdf46119(); @@ -67,7 +63,6 @@ public: void testTdf144970(); void testTdf138646(); void testTdf105558(); - void testTdf90278(); void testTdf143582(); void testTdf144085(); void testTdf130307(); @@ -77,16 +72,12 @@ public: CPPUNIT_TEST_SUITE(ScMacrosTest); CPPUNIT_TEST(testStarBasic); CPPUNIT_TEST(testMSP); - CPPUNIT_TEST(testVba); CPPUNIT_TEST(testPasswordProtectedStarBasic); CPPUNIT_TEST(testTdf114427); - CPPUNIT_TEST(testTdf107885); CPPUNIT_TEST(testRowColumn); CPPUNIT_TEST(testTdf142033); - CPPUNIT_TEST(testTdf131562); CPPUNIT_TEST(testPasswordProtectedUnicodeString); CPPUNIT_TEST(testPasswordProtectedArrayInUserType); - CPPUNIT_TEST(testTdf107902); CPPUNIT_TEST(testTdf131296_legacy); CPPUNIT_TEST(testTdf131296_new); CPPUNIT_TEST(testTdf46119); @@ -99,7 +90,6 @@ public: CPPUNIT_TEST(testTdf144970); CPPUNIT_TEST(testTdf138646); CPPUNIT_TEST(testTdf105558); - CPPUNIT_TEST(testTdf90278); CPPUNIT_TEST(testTdf143582); CPPUNIT_TEST(testTdf144085); CPPUNIT_TEST(testTdf130307); @@ -243,221 +233,6 @@ void ScMacrosTest::testStarBasic() pDocSh->DoClose(); } -void ScMacrosTest::testVba() -{ - TestMacroInfo testInfo[] = { - { - OUString("TestAddress."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("vba."), - OUString("vnd.sun.Star.script:VBAProject.Modul1.Modul1?language=Basic&location=document"), - }, - { - OUString("MiscRangeTests."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("bytearraystring."), - OUString("vnd.sun.Star.script:VBAProject.testMacro.test?language=Basic&location=document") - }, - { - OUString("AutoFilter."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("CalcFont."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("TestIntersection."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("TestUnion."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("range-4."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("Ranges-3."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("TestCalc_Rangetest."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("TestCalc_Rangetest2."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("Ranges-2."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("pagesetup."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("Window."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("window2."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("PageBreaks."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("Shapes."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("Ranges."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("CheckOptionToggleValue."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("GeneratedEventTest."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("MiscControlTests."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("Workbooks."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("Names."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("NamesSheetLocal."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("vba_endFunction."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - { - OUString("vba_findFunction."), - OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") - }, - }; - OUString sTempDir; - OUString sTempDirURL; - osl::FileBase:: getTempDirURL( sTempDirURL ); - osl::FileBase::getSystemPathFromFileURL( sTempDirURL, sTempDir ); - sTempDir += OUStringChar(SAL_PATHDELIMITER); - OUString sTestFileName("My Test WorkBook.xls"); - Sequence< uno::Any > aParams; - for (const auto& rTestInfo : testInfo) - { - OUString aFileName; - createFileURL(OUStringConcatenation(rTestInfo.sFileBaseName + "xls"), aFileName); - uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); - - // process all events such as OnLoad events etc. - // otherwise the tend to arrive later at a random - // time - while processing other StarBasic methods. - Application::Reschedule(true); - - Any aRet; - Sequence< sal_Int16 > aOutParamIndex; - Sequence< Any > aOutParam; - bool bWorkbooksHandling = rTestInfo.sFileBaseName == "Workbooks." && !sTempDir.isEmpty() ; - - if ( bWorkbooksHandling ) - { - aParams = { uno::Any(sTempDir), uno::Any(sTestFileName) }; - } - - SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); - - CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); - SAL_INFO("sc.qa", "about to invoke vba test in " << aFileName << " with url " << rTestInfo.sMacroUrl); - - SfxObjectShell::CallXScript( - xComponent, rTestInfo.sMacroUrl, aParams, aRet, aOutParamIndex, - aOutParam); - OUString aStringRes; - aRet >>= aStringRes; - CPPUNIT_ASSERT_EQUAL_MESSAGE( - OUString("script reported failure in file " + rTestInfo.sFileBaseName + "xls") - .toUtf8() - .getStr(), - OUString("OK"), aStringRes); - pFoundShell->DoClose(); - if ( bWorkbooksHandling ) - { - OUString sFileUrl; - OUString sFilePath = sTempDir + sTestFileName; - osl::FileBase::getFileURLFromSystemPath( sFilePath, sFileUrl ); - if ( !sFileUrl.isEmpty() ) - osl::File::remove( sFileUrl ); - } - } -} - -void ScMacrosTest::testTdf107885() -{ - OUString aFileName; - createFileURL(u"tdf107885.xlsm", aFileName); - uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); - - 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<ScDocShell*>(pFoundShell); - ScDocument& rDoc = pDocSh->GetDocument(); - - CPPUNIT_ASSERT(!rDoc.RowHidden(1,0)); - CPPUNIT_ASSERT(!rDoc.RowHidden(2,0)); - CPPUNIT_ASSERT(!rDoc.RowHidden(3,0)); - CPPUNIT_ASSERT(!rDoc.RowHidden(4,0)); - - // Call auto filter macro using a string condition - SfxObjectShell::CallXScript( - xComponent, - "vnd.sun.Star.script:VBAProject.Module1.AFString?language=Basic&location=document", - aParams, aRet, aOutParamIndex, aOutParam); - - //Without the fix in place, all rows in autofilter would have been hidden - CPPUNIT_ASSERT(rDoc.RowHidden(1,0)); - CPPUNIT_ASSERT(!rDoc.RowHidden(2,0)); - CPPUNIT_ASSERT(!rDoc.RowHidden(3,0)); - CPPUNIT_ASSERT(!rDoc.RowHidden(4,0)); - - // Call auto filter macro using a numeric condition without any locale - SfxObjectShell::CallXScript( - xComponent, - "vnd.sun.Star.script:VBAProject.Module1.AFNumeric?language=Basic&location=document", - aParams, aRet, aOutParamIndex, aOutParam); - - 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::testRowColumn() { OUString aFileName; @@ -592,38 +367,6 @@ void ScMacrosTest::testTdf142033() xCloseable->close(true); } -void ScMacrosTest::testTdf131562() -{ - OUString aFileName; - createFileURL(u"tdf131562.xlsm", aFileName); - uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); - - 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<ScDocShell*>(pFoundShell); - ScDocument& rDoc = pDocSh->GetDocument(); - - CPPUNIT_ASSERT_EQUAL(OUString("1"), rDoc.GetString(ScAddress(0,2,0))); - CPPUNIT_ASSERT_EQUAL(OUString(""), rDoc.GetString(ScAddress(0,3,0))); - - SfxObjectShell::CallXScript( - xComponent, - "vnd.sun.Star.script:VBAProject.Munka1.numberconcat?language=Basic&location=document", - aParams, aRet, aOutParamIndex, aOutParam); - - //Without the fix in place, the macro wouldn't have concatenated 1 and " ." - CPPUNIT_ASSERT_EQUAL(OUString("1 ."), rDoc.GetString(ScAddress(0,2,0))); - CPPUNIT_ASSERT_EQUAL(OUString("1 .cat"), rDoc.GetString(ScAddress(0,3,0))); - - pDocSh->DoClose(); -} - void ScMacrosTest::testPasswordProtectedUnicodeString() { const OUString sCorrectString(u"English Русский 中文"); @@ -775,46 +518,6 @@ void ScMacrosTest::testTdf114427() pDocSh->DoClose(); } -void ScMacrosTest::testTdf107902() -{ - OUString aFileName; - createFileURL(u"tdf107902.xlsm", aFileName); - uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); - - 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<ScDocShell*>(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, @@ -1261,38 +964,6 @@ void ScMacrosTest::testTdf105558() xCloseable->close(true); } -void ScMacrosTest::testTdf90278() -{ - OUString aFileName; - createFileURL(u"tdf90278.xls", aFileName); - auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); - - SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); - CPPUNIT_ASSERT(pFoundShell); - - ScDocShellRef xDocSh = dynamic_cast<ScDocShell*>(pFoundShell); - CPPUNIT_ASSERT(xDocSh); - - Any aRet; - Sequence<sal_Int16> aOutParamIndex; - Sequence<Any> aOutParam; - Sequence<uno::Any> aParams; - - // Without the fix in place, changing the border weight - // would cause a Basic exception/error in the following script. - SfxObjectShell::CallXScript( - xComponent, - "vnd.sun.Star.script:VBAProject.Module1.BorderWeight?language=Basic&location=document", - aParams, aRet, aOutParamIndex, aOutParam); - - // Check the border weight of the corresponding cell in the test document - sal_Int32 aReturnValue; - aRet >>= aReturnValue; - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aReturnValue); - - xDocSh->DoClose(); -} - ScMacrosTest::ScMacrosTest() : UnoApiTest("/sc/qa/extras/testdocuments") { diff --git a/sc/qa/extras/vba-macro-test.cxx b/sc/qa/extras/vba-macro-test.cxx index 36aa84badd2d..b4736fc689cc 100644 --- a/sc/qa/extras/vba-macro-test.cxx +++ b/sc/qa/extras/vba-macro-test.cxx @@ -45,10 +45,20 @@ public: void testSimpleCopyAndPaste(); void testMultiDocumentCopyAndPaste(); + void testVba(); + void testTdf107885(); + void testTdf131562(); + void testTdf107902(); + void testTdf90278(); CPPUNIT_TEST_SUITE(VBAMacroTest); CPPUNIT_TEST(testSimpleCopyAndPaste); CPPUNIT_TEST(testMultiDocumentCopyAndPaste); + CPPUNIT_TEST(testVba); + CPPUNIT_TEST(testTdf107885); + CPPUNIT_TEST(testTdf131562); + CPPUNIT_TEST(testTdf107902); + CPPUNIT_TEST(testTdf90278); CPPUNIT_TEST_SUITE_END(); }; @@ -143,6 +153,303 @@ void VBAMacroTest::testMultiDocumentCopyAndPaste() CPPUNIT_ASSERT_EQUAL(0.0, rDoc.GetValue(ScAddress(1, 3, 0))); } +void VBAMacroTest::testVba() +{ + TestMacroInfo testInfo[] = { + { OUString("TestAddress."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { + OUString("vba."), + OUString( + "vnd.sun.Star.script:VBAProject.Modul1.Modul1?language=Basic&location=document"), + }, + { OUString("MiscRangeTests."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("bytearraystring."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacro.test?language=Basic&location=document") }, + { OUString("AutoFilter."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("CalcFont."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("TestIntersection."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("TestUnion."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("range-4."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Ranges-3."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("TestCalc_Rangetest."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("TestCalc_Rangetest2."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Ranges-2."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("pagesetup."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Window."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("window2."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("PageBreaks."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Shapes."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Ranges."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("CheckOptionToggleValue."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("GeneratedEventTest."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("MiscControlTests."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Workbooks."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("Names."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("NamesSheetLocal."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("vba_endFunction."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { OUString("vba_findFunction."), + OUString( + "vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + }; + OUString sTempDir; + OUString sTempDirURL; + osl::FileBase::getTempDirURL(sTempDirURL); + osl::FileBase::getSystemPathFromFileURL(sTempDirURL, sTempDir); + sTempDir += OUStringChar(SAL_PATHDELIMITER); + OUString sTestFileName("My Test WorkBook.xls"); + uno::Sequence<uno::Any> aParams; + for (const auto& rTestInfo : testInfo) + { + OUString aFileName; + createFileURL(OUStringConcatenation(rTestInfo.sFileBaseName + "xls"), aFileName); + uno::Reference<css::lang::XComponent> xComponent + = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + // process all events such as OnLoad events etc. + // otherwise the tend to arrive later at a random + // time - while processing other StarBasic methods. + Application::Reschedule(true); + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + bool bWorkbooksHandling = rTestInfo.sFileBaseName == "Workbooks." && !sTempDir.isEmpty(); + + if (bWorkbooksHandling) + { + aParams = { uno::Any(sTempDir), uno::Any(sTestFileName) }; + } + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + SAL_INFO("sc.qa", "about to invoke vba test in " << aFileName << " with url " + << rTestInfo.sMacroUrl); + + SfxObjectShell::CallXScript(xComponent, rTestInfo.sMacroUrl, aParams, aRet, aOutParamIndex, + aOutParam); + OUString aStringRes; + aRet >>= aStringRes; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + OUString("script reported failure in file " + rTestInfo.sFileBaseName + "xls") + .toUtf8() + .getStr(), + OUString("OK"), aStringRes); + pFoundShell->DoClose(); + if (bWorkbooksHandling) + { + OUString sFileUrl; + OUString sFilePath = sTempDir + sTestFileName; + osl::FileBase::getFileURLFromSystemPath(sFilePath, sFileUrl); + if (!sFileUrl.isEmpty()) + osl::File::remove(sFileUrl); + } + } +} + +void VBAMacroTest::testTdf107885() +{ + OUString aFileName; + createFileURL(u"tdf107885.xlsm", aFileName); + uno::Reference<css::lang::XComponent> xComponent + = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + uno::Sequence<uno::Any> aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + CPPUNIT_ASSERT(!rDoc.RowHidden(1, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(2, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(3, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(4, 0)); + + // Call auto filter macro using a string condition + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:VBAProject.Module1.AFString?language=Basic&location=document", aParams, + aRet, aOutParamIndex, aOutParam); + + //Without the fix in place, all rows in autofilter would have been hidden + CPPUNIT_ASSERT(rDoc.RowHidden(1, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(2, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(3, 0)); + CPPUNIT_ASSERT(!rDoc.RowHidden(4, 0)); + + // Call auto filter macro using a numeric condition without any locale + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:VBAProject.Module1.AFNumeric?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + 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 VBAMacroTest::testTdf131562() +{ + OUString aFileName; + createFileURL(u"tdf131562.xlsm", aFileName); + uno::Reference<css::lang::XComponent> xComponent + = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + uno::Sequence<uno::Any> aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(OUString("1"), rDoc.GetString(ScAddress(0, 2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), rDoc.GetString(ScAddress(0, 3, 0))); + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:VBAProject.Munka1.numberconcat?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + //Without the fix in place, the macro wouldn't have concatenated 1 and " ." + CPPUNIT_ASSERT_EQUAL(OUString("1 ."), rDoc.GetString(ScAddress(0, 2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("1 .cat"), rDoc.GetString(ScAddress(0, 3, 0))); + + pDocSh->DoClose(); +} + +void VBAMacroTest::testTdf107902() +{ + OUString aFileName; + createFileURL(u"tdf107902.xlsm", aFileName); + uno::Reference<css::lang::XComponent> xComponent + = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + uno::Sequence<uno::Any> aParams; + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(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 VBAMacroTest::testTdf90278() +{ + OUString aFileName; + createFileURL(u"tdf90278.xls", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT(pFoundShell); + + ScDocShellRef xDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(xDocSh); + + uno::Any aRet; + uno::Sequence<sal_Int16> aOutParamIndex; + uno::Sequence<uno::Any> aOutParam; + uno::Sequence<uno::Any> aParams; + + // Without the fix in place, changing the border weight + // would cause a Basic exception/error in the following script. + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:VBAProject.Module1.BorderWeight?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + // Check the border weight of the corresponding cell in the test document + sal_Int32 aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aReturnValue); + + xDocSh->DoClose(); +} + CPPUNIT_TEST_SUITE_REGISTRATION(VBAMacroTest); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 7c2b04152c5e7e76870fc644ba6eff5da796ca52 Author: Michael Meeks <michael.me...@collabora.com> AuthorDate: Mon Jan 3 14:15:49 2022 +0000 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Mon Feb 14 16:02:18 2022 +0100 lokit: double check for disposed windows & fix leak. it seems we can get windows disposed before we get to the emission. <segv> vcl::Window::IsTracking() const vcl/source/window/window2.cxx:341 (anonymous namespace)::LOKPostAsyncEvent(void*, void*) sfx2/source/view/lokhelper.cxx:725 LokChartHelper::postMouseEvent(int, int, int, int, int, int, double, double) include/rtl/ref.hxx:112 SwXTextDocument::postMouseEvent(int, int, int, int, int, int) sw/source/uibase/uno/unotxdoc.cxx:3561 Change-Id: I93aea931dad1e7f43d3d610568424c53d2b22fbc Signed-off-by: Michael Meeks <michael.me...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127907 diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index cd93f9b4dd55..cb8194c1cabf 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -679,9 +679,7 @@ namespace { std::unique_ptr<LOKAsyncEventData> pLOKEv(static_cast<LOKAsyncEventData*>(pEv)); if (pLOKEv->mpWindow->isDisposed()) - { return; - } int nView = SfxLokHelper::getView(nullptr); if (nView != pLOKEv->mnView) @@ -700,6 +698,9 @@ namespace if (!pFocusWindow) pFocusWindow = pLOKEv->mpWindow; + if (pLOKEv->mpWindow->isDisposed()) + return; + switch (pLOKEv->mnEvent) { case VclEventId::WindowKeyInput: @@ -708,11 +709,13 @@ namespace KeyEvent singlePress(pLOKEv->maKeyEvent.GetCharCode(), pLOKEv->maKeyEvent.GetKeyCode()); for (sal_uInt16 i = 0; i <= nRepeat; ++i) - pFocusWindow->KeyInput(singlePress); + if (!pFocusWindow->isDisposed()) + pFocusWindow->KeyInput(singlePress); break; } case VclEventId::WindowKeyUp: - pFocusWindow->KeyUp(pLOKEv->maKeyEvent); + if (!pFocusWindow->isDisposed()) + pFocusWindow->KeyUp(pLOKEv->maKeyEvent); break; case VclEventId::WindowMouseButtonDown: pLOKEv->mpWindow->LogicMouseButtonDown(pLOKEv->maMouseEvent);