sc/qa/extras/vba-macro-test.cxx |  166 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 166 insertions(+)

New commits:
commit 9a46a203515779ae40b7cfac36dbc22990e23290
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Wed Jan 26 16:54:12 2022 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Jan 27 07:38:21 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[] = {

Reply via email to