sc/qa/extras/macros-test.cxx    |  329 ----------------------------------------
 sc/qa/extras/vba-macro-test.cxx |  307 +++++++++++++++++++++++++++++++++++++
 2 files changed, 307 insertions(+), 329 deletions(-)

New commits:
commit ab234f749cc4a213711e389d29ced9a169bfa090
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Fri Jan 21 16:04:42 2022 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri Jan 21 18:26:27 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 b18bb7ab52a1..2326f101626e 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();
@@ -76,16 +71,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);
@@ -98,7 +89,6 @@ public:
     CPPUNIT_TEST(testTdf144970);
     CPPUNIT_TEST(testTdf138646);
     CPPUNIT_TEST(testTdf105558);
-    CPPUNIT_TEST(testTdf90278);
     CPPUNIT_TEST(testTdf143582);
     CPPUNIT_TEST(testTdf144085);
     CPPUNIT_TEST(testTdf130307);
@@ -241,221 +231,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;
@@ -562,38 +337,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 Русский 中文");
@@ -745,46 +488,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,
@@ -1231,38 +934,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: */

Reply via email to