diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-01-26 16:54:12 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-01-27 07:38:21 +0100 |
commit | 9a46a203515779ae40b7cfac36dbc22990e23290 (patch) | |
tree | 7e9b0b21fe43124272abc0cdb209cac1219a2ffd /sc | |
parent | 93806a2831c93154981e3a6ef933270d0d5a6021 (diff) |
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 <quikee@gmail.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/extras/vba-macro-test.cxx | 166 |
1 files changed, 166 insertions, 0 deletions
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[] = { |