summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-01-26 16:54:12 +0900
committerTomaž Vajngerl <quikee@gmail.com>2022-01-31 03:45:43 +0100
commit58d74724631425b083c4bd3d316a0a4bc1af4eb3 (patch)
tree476bb05f16f4ef839af733378ddeb15e8bbf9073 /sc
parentb0999355c9314125a233ef386f590faf025dc97e (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> (cherry picked from commit 9a46a203515779ae40b7cfac36dbc22990e23290) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129020 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/vba-macro-test.cxx166
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 174e2e7229b6..b256eb373036 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,13 +50,21 @@ public:
void testSimpleCopyAndPaste();
void testMultiDocumentCopyAndPaste();
void testSheetAndColumnSelectAndHide();
+ void testPrintArea();
+ void testSelectAllChaged();
+ void testRangeSelect();
void testWindowState();
+ void testScroll();
CPPUNIT_TEST_SUITE(VBAMacroTest);
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_SUITE_END();
};
@@ -221,6 +231,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
@@ -242,6 +372,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));
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(VBAMacroTest);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */