tdf#133326: sc: Add unittest
Change-Id: I2436822fa289ae1bf10643cfc5232f4db6df2e29
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97150
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/sc/qa/unit/uicalc/data/tdf133326.ods b/sc/qa/unit/uicalc/data/tdf133326.ods
new file mode 100644
index 0000000..102f169
--- /dev/null
+++ b/sc/qa/unit/uicalc/data/tdf133326.ods
Binary files differ
diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx
index 46e4b24..84b1652 100644
--- a/sc/qa/unit/uicalc/uicalc.cxx
+++ b/sc/qa/unit/uicalc/uicalc.cxx
@@ -12,6 +12,7 @@
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <vcl/scheduler.hxx>
#include <comphelper/propertysequence.hxx>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/frame/Desktop.hpp>
#include <document.hxx>
@@ -89,6 +90,62 @@
checkCurrentCell(2, 6);
}
CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf133326)
{
ScModelObj* pModelObj = createDoc("tdf133326.ods");
ScDocument* pDoc = pModelObj->GetDocument();
CPPUNIT_ASSERT(pDoc);
dispatchCommand(mxComponent, ".uno:SelectAll", {});
dispatchCommand(mxComponent, ".uno:Copy", {});
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(static_cast<SCTAB>(1), pDoc->GetTableCount());
uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
{ { "Name", uno::Any(OUString("")) }, { "Index", uno::Any(sal_Int32(2)) } }));
dispatchCommand(mxComponent, ".uno:Insert", aArgs);
OUString aFormula;
pDoc->GetFormula(0, 0, 1, aFormula);
CPPUNIT_ASSERT_EQUAL(OUString(""), aFormula);
CPPUNIT_ASSERT_EQUAL(static_cast<SCTAB>(2), pDoc->GetTableCount());
dispatchCommand(mxComponent, ".uno:Paste", {});
Scheduler::ProcessEventsToIdle();
pDoc->GetFormula(0, 0, 1, aFormula);
CPPUNIT_ASSERT_EQUAL(OUString("=RAND()*1000000"), aFormula);
CPPUNIT_ASSERT_EQUAL(static_cast<SCTAB>(2), pDoc->GetTableCount());
dispatchCommand(mxComponent, ".uno:Undo", {});
Scheduler::ProcessEventsToIdle();
pDoc->GetFormula(0, 0, 1, aFormula);
CPPUNIT_ASSERT_EQUAL(OUString(""), aFormula);
CPPUNIT_ASSERT_EQUAL(static_cast<SCTAB>(2), pDoc->GetTableCount());
dispatchCommand(mxComponent, ".uno:Undo", {});
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(static_cast<SCTAB>(1), pDoc->GetTableCount());
dispatchCommand(mxComponent, ".uno:Redo", {});
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(static_cast<SCTAB>(2), pDoc->GetTableCount());
pDoc->GetFormula(0, 0, 1, aFormula);
CPPUNIT_ASSERT_EQUAL(OUString(""), aFormula);
// Without the fix in place, it would have crashed here
dispatchCommand(mxComponent, ".uno:Redo", {});
Scheduler::ProcessEventsToIdle();
pDoc->GetFormula(0, 0, 1, aFormula);
CPPUNIT_ASSERT_EQUAL(OUString("=RAND()*1000000"), aFormula);
CPPUNIT_ASSERT_EQUAL(static_cast<SCTAB>(2), pDoc->GetTableCount());
}
CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf126904)
{
ScModelObj* pModelObj = createDoc("tdf126904.ods");