tdf#152014: sc_uicalc: Add unittest

Change-Id: I7be721d9409890fe1f26125f06561e85cb1ddb27
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143113
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/include/test/unoapi_test.hxx b/include/test/unoapi_test.hxx
index ece36ab..1f14f6a 100644
--- a/include/test/unoapi_test.hxx
+++ b/include/test/unoapi_test.hxx
@@ -60,6 +60,9 @@ protected:
    // reference to document component that we are testing
    css::uno::Reference<css::lang::XComponent> mxComponent;

    // In case the test needs to work with two documents at the same time
    css::uno::Reference<css::lang::XComponent> mxComponent2;

    utl::TempFileNamed maTempFile;

    SvMemoryStream maMemory; // Underlying memory for parsed PDF files.
diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx
index 518a219..4976c19c 100644
--- a/sc/qa/unit/uicalc/uicalc.cxx
+++ b/sc/qa/unit/uicalc/uicalc.cxx
@@ -2903,6 +2903,40 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf149378)
    CPPUNIT_ASSERT_EQUAL(OUString("{=ABS({-1;-2})}"), pDoc->GetFormula(8, 0, 0));
}

CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf152014)
{
    createScDoc();

    insertStringToCell("A1", u"=MATCH(1,A2,0)");
    insertStringToCell("A2", u"1");

    ScDocument* pDoc = getScDoc();
    CPPUNIT_ASSERT_EQUAL(OUString("1"), pDoc->GetString(ScAddress(0, 0, 0)));

    goToCell("A1");

    dispatchCommand(mxComponent, ".uno:Copy", {});
    Scheduler::ProcessEventsToIdle();

    // Create a second document
    mxComponent2 = loadFromDesktop("private:factory/scalc");

    uno::Reference<frame::XFrames> xFrames = mxDesktop->getFrames();
    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xFrames->getCount());

    dispatchCommand(mxComponent2, ".uno:Paste", {});
    Scheduler::ProcessEventsToIdle();

    ScModelObj* pModelObj2 = dynamic_cast<ScModelObj*>(mxComponent2.get());
    CPPUNIT_ASSERT(pModelObj2);
    ScDocument* pDoc2 = pModelObj2->GetDocument();

    // Without the fix in place, this test would have failed with
    // - Expected: #N/A
    // - Actual  : 1
    CPPUNIT_ASSERT_EQUAL(OUString("#N/A"), pDoc2->GetString(ScAddress(0, 0, 0)));
}

CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf126926)
{
    createScDoc();
diff --git a/test/source/unoapi_test.cxx b/test/source/unoapi_test.cxx
index a1c0580..ff566c8 100644
--- a/test/source/unoapi_test.cxx
+++ b/test/source/unoapi_test.cxx
@@ -43,6 +43,12 @@ void UnoApiTest::setUp()

void UnoApiTest::tearDown()
{
    if (mxComponent2.is())
    {
        mxComponent2->dispose();
        mxComponent2.clear();
    }

    if (mxComponent.is())
    {
        mxComponent->dispose();