tdf#149325, tdf#149531: sc_macros_test: Add unittest
Change-Id: Ie6d9f75f2dd3ecb92eed4d464b4c36fd993076f1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135819
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/sc/qa/extras/testdocuments/tdf149531.xls b/sc/qa/extras/testdocuments/tdf149531.xls
new file mode 100644
index 0000000..e79c16b
--- /dev/null
+++ b/sc/qa/extras/testdocuments/tdf149531.xls
Binary files differ
diff --git a/sc/qa/extras/vba-macro-test.cxx b/sc/qa/extras/vba-macro-test.cxx
index bd2ebe1..78f5b1c 100644
--- a/sc/qa/extras/vba-macro-test.cxx
+++ b/sc/qa/extras/vba-macro-test.cxx
@@ -66,6 +66,7 @@ public:
void testTdf131562();
void testTdf107902();
void testTdf90278();
void testTdf149531();
CPPUNIT_TEST_SUITE(VBAMacroTest);
CPPUNIT_TEST(testSimpleCopyAndPaste);
@@ -83,6 +84,7 @@ public:
CPPUNIT_TEST(testTdf131562);
CPPUNIT_TEST(testTdf107902);
CPPUNIT_TEST(testTdf90278);
CPPUNIT_TEST(testTdf149531);
CPPUNIT_TEST_SUITE_END();
};
@@ -743,6 +745,40 @@ void VBAMacroTest::testTdf90278()
xDocSh->DoClose();
}
void VBAMacroTest::testTdf149531()
{
OUString aFileName;
createFileURL(u"tdf149531.xls", aFileName);
auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument");
SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
CPPUNIT_ASSERT(pFoundShell);
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;
for (sal_Int32 i = 0; i < 5; ++i)
{
// Without the fix in place, this test would have crashed
// also check the test doesn't crash when the macro is executed a few times in a row
SfxObjectShell::CallXScript(xComponent,
"vnd.sun.Star.script:VBAProject.Module1.SetColumnWidth?"
"language=Basic&location=document",
aParams, aRet, aOutParamIndex, aOutParam);
}
sal_uInt16 nWidth
= o3tl::convert(rDoc.GetColWidth(0, 0), o3tl::Length::twip, o3tl::Length::mm100);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(25749), nWidth);
pDocSh->DoClose();
}
CPPUNIT_TEST_SUITE_REGISTRATION(VBAMacroTest);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */