summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--basic/source/runtime/runtime.cxx10
-rw-r--r--sc/qa/extras/testdocuments/ForEachInSelection.odsbin0 -> 9819 bytes
-rw-r--r--sc/qa/extras/vba-macro-test.cxx39
3 files changed, 48 insertions, 1 deletions
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index 52efd4aea837..729bf652a21e 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -1170,7 +1170,15 @@ void SbiRuntime::PushForEach()
pForStk = p;
SbxVariableRef xObjVar = PopVar();
- SbxBase* pObj = xObjVar && xObjVar->GetFullType() == SbxOBJECT ? xObjVar->GetObject() : nullptr;
+ SbxBase* pObj(nullptr);
+ if (xObjVar)
+ {
+ SbxValues v(SbxVARIANT);
+ // Here it may retrieve the value, and change the type from SbxEMPTY to SbxOBJECT
+ xObjVar->Get(v);
+ if (v.eType == SbxOBJECT)
+ pObj = v.pObj;
+ }
if (SbxDimArray* pArray = dynamic_cast<SbxDimArray*>(pObj))
{
diff --git a/sc/qa/extras/testdocuments/ForEachInSelection.ods b/sc/qa/extras/testdocuments/ForEachInSelection.ods
new file mode 100644
index 000000000000..7996c86eb953
--- /dev/null
+++ b/sc/qa/extras/testdocuments/ForEachInSelection.ods
Binary files differ
diff --git a/sc/qa/extras/vba-macro-test.cxx b/sc/qa/extras/vba-macro-test.cxx
index 261ee3943a0a..15dfe9c874c0 100644
--- a/sc/qa/extras/vba-macro-test.cxx
+++ b/sc/qa/extras/vba-macro-test.cxx
@@ -55,6 +55,7 @@ public:
void testTdf131562();
void testTdf107902();
void testTdf90278();
+ void testForEachInSelection();
CPPUNIT_TEST_SUITE(VBAMacroTest);
CPPUNIT_TEST(testSimpleCopyAndPaste);
@@ -72,6 +73,7 @@ public:
CPPUNIT_TEST(testTdf131562);
CPPUNIT_TEST(testTdf107902);
CPPUNIT_TEST(testTdf90278);
+ CPPUNIT_TEST(testForEachInSelection);
CPPUNIT_TEST_SUITE_END();
private:
@@ -760,6 +762,43 @@ void VBAMacroTest::testTdf90278()
xCloseable->close(true);
}
+void VBAMacroTest::testForEachInSelection()
+{
+ OUString aFileName;
+ createFileURL(u"ForEachInSelection.ods", 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);
+ ScDocument& rDoc = pDocSh->GetDocument();
+
+ uno::Any aRet;
+ uno::Sequence<sal_Int16> aOutParamIndex;
+ uno::Sequence<uno::Any> aOutParam;
+ uno::Sequence<uno::Any> aParams;
+
+ CPPUNIT_ASSERT_EQUAL(OUString("foo"), rDoc.GetString(ScAddress(0, 0, 0)));
+ CPPUNIT_ASSERT_EQUAL(OUString("bar"), rDoc.GetString(ScAddress(0, 1, 0)));
+ CPPUNIT_ASSERT_EQUAL(OUString("baz"), rDoc.GetString(ScAddress(0, 2, 0)));
+
+ // tdf#153724: without the fix, this would fail with
+ // assertion failed
+ // - Expression: false
+ // - Unexpected dialog: Error: BASIC runtime error.
+ // '13'
+ // Data type mismatch.
+ SfxObjectShell::CallXScript(mxComponent,
+ "vnd.sun.Star.script:Standard.Module1.TestForEachInSelection?"
+ "language=Basic&location=document",
+ aParams, aRet, aOutParamIndex, aOutParam);
+
+ CPPUNIT_ASSERT_EQUAL(OUString("oof"), rDoc.GetString(ScAddress(0, 0, 0)));
+ CPPUNIT_ASSERT_EQUAL(OUString("rab"), rDoc.GetString(ScAddress(0, 1, 0)));
+ CPPUNIT_ASSERT_EQUAL(OUString("zab"), rDoc.GetString(ScAddress(0, 2, 0)));
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(VBAMacroTest);
CPPUNIT_PLUGIN_IMPLEMENT();