diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-01-25 16:14:32 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-01-31 03:45:12 +0100 |
commit | ba4365fb28597294c20d8f3581cbfcafa761d3aa (patch) | |
tree | bb4f751277e3236eaf4a933240c3d74a951a8f17 /sc | |
parent | 6482694c3d23f94a8d7fec4edbbe1fb3b1055df8 (diff) |
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 <quikee@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit cfa4867b0b66b0d4fb3aee52ca40d380e50de9ef)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129018
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm | bin | 0 -> 17286 bytes | |||
-rw-r--r-- | sc/qa/extras/vba-macro-test.cxx | 76 |
2 files changed, 76 insertions, 0 deletions
diff --git a/sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm b/sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm Binary files differnew file mode 100644 index 000000000000..684480c3ff04 --- /dev/null +++ b/sc/qa/extras/testdocuments/SheetAndColumnSelectAndHide.xlsm diff --git a/sc/qa/extras/vba-macro-test.cxx b/sc/qa/extras/vba-macro-test.cxx index 36aa84badd2d..532e47d14ad5 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,10 +47,12 @@ public: void testSimpleCopyAndPaste(); void testMultiDocumentCopyAndPaste(); + void testSheetAndColumnSelectAndHide(); CPPUNIT_TEST_SUITE(VBAMacroTest); CPPUNIT_TEST(testSimpleCopyAndPaste); CPPUNIT_TEST(testMultiDocumentCopyAndPaste); + CPPUNIT_TEST(testSheetAndColumnSelectAndHide); CPPUNIT_TEST_SUITE_END(); }; @@ -143,6 +147,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()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(VBAMacroTest); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |