sc/qa/extras/macros-test.cxx             |   33 +++++++++++++++++++++++++++++++
 sc/qa/extras/testdocuments/tdf133889.ods |binary
 scripting/source/basprov/basscript.cxx   |   15 ++++++++++++++
 3 files changed, 48 insertions(+)

New commits:
commit 61d2014254a6bf1da68e2f13d3de2c099fcb8883
Author:     tushar <tusharrai...@gmail.com>
AuthorDate: Fri Jan 22 02:33:21 2021 +0530
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Jan 22 19:05:49 2021 +0100

    tdf#133889 Upcasting the type of actual parameter.
    
    Type of actual parameter is made same as formal parameter.This is done to 
undo the conversions made in sbxToUnoValueImpl.
    
    Change-Id: I8c7a880503d927eb43ad38eac4bf01451442834b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109773
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx
index 00c8474a38b6..7efa20e5f60f 100644
--- a/sc/qa/extras/macros-test.cxx
+++ b/sc/qa/extras/macros-test.cxx
@@ -53,6 +53,7 @@ public:
     void testTdf71271();
     void testTdf43003();
     void testTdf133887();
+    void testTdf133889();
 
     CPPUNIT_TEST_SUITE(ScMacrosTest);
     CPPUNIT_TEST(testStarBasic);
@@ -72,6 +73,7 @@ public:
     CPPUNIT_TEST(testTdf71271);
     CPPUNIT_TEST(testTdf43003);
     CPPUNIT_TEST(testTdf133887);
+    CPPUNIT_TEST(testTdf133889);
 
     CPPUNIT_TEST_SUITE_END();
 };
@@ -897,6 +899,37 @@ void ScMacrosTest::testTdf133887()
     xCloseable->close(true);
 }
 
+void ScMacrosTest::testTdf133889()
+{
+    OUString aFileName;
+    createFileURL(u"tdf133889.ods", aFileName);
+    auto xComponent = loadFromDesktop(aFileName, 
"com.sun.star.sheet.SpreadsheetDocument");
+
+    CPPUNIT_ASSERT_MESSAGE("Failed to load the doc", xComponent.is());
+
+    css::uno::Any aRet;
+    css::uno::Sequence<sal_Int16> aOutParamIndex;
+    css::uno::Sequence<css::uno::Any> aOutParam;
+    css::uno::Sequence<css::uno::Any> aParams{ css::uno::Any(sal_Int32(0)) };
+
+    SfxObjectShell::CallXScript(
+        xComponent,
+        
"vnd.sun.Star.script:Standard.Module1.TestInvoke?language=Basic&location=document",
 aParams,
+        aRet, aOutParamIndex, aOutParam);
+
+    sal_Int32 aReturnValue;
+    aOutParam[0] >>= aReturnValue;
+
+    // Without the fix in place, this test would have failed with
+    // - Expected: 100000
+    // - Actual  : 0
+
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(100000), aReturnValue);
+
+    css::uno::Reference<css::util::XCloseable> xCloseable(xComponent, 
css::uno::UNO_QUERY_THROW);
+    xCloseable->close(true);
+}
+
 ScMacrosTest::ScMacrosTest()
       : UnoApiTest("/sc/qa/extras/testdocuments")
 {
diff --git a/sc/qa/extras/testdocuments/tdf133889.ods 
b/sc/qa/extras/testdocuments/tdf133889.ods
new file mode 100644
index 000000000000..db87da6129a7
Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf133889.ods differ
diff --git a/scripting/source/basprov/basscript.cxx 
b/scripting/source/basprov/basscript.cxx
index 16ffeb9dc9ee..4d6f2477ed92 100644
--- a/scripting/source/basprov/basscript.cxx
+++ b/scripting/source/basprov/basscript.cxx
@@ -210,6 +210,21 @@ namespace basprov
                         if (auto* p = 
pInfo->GetParam(static_cast<sal_uInt16>(i) + 1))
                         {
                             SbxDataType t = static_cast<SbxDataType>(p->eType 
& 0x0FFF);
+                            // tdf#133889 Revert the downcasting performed in 
sbxToUnoValueImpl
+                            // to allow passing by reference.
+                            SbxDataType a = xSbxVar->GetType();
+                            if (t == SbxSINGLE && (a == SbxINTEGER || a == 
SbxLONG))
+                            {
+                                sal_Int32 val = xSbxVar->GetLong();
+                                if (val >= -16777216 && val <= 16777215)
+                                    xSbxVar->SetType(t);
+                            }
+                            else if (t == SbxDOUBLE && (a == SbxINTEGER || a 
== SbxLONG))
+                                xSbxVar->SetType(t);
+                            else if (t == SbxLONG && a == SbxINTEGER)
+                                xSbxVar->SetType(t);
+                            else if (t == SbxULONG && a == SbxUSHORT)
+                                xSbxVar->SetType(t);
                             // Enable passing by ref
                             if (t != SbxVARIANT)
                                 xSbxVar->SetFlag(SbxFlagBits::Fixed);
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to