include/test/unoapi_test.hxx |    3 +++
 sc/qa/unit/uicalc/uicalc.cxx |   34 ++++++++++++++++++++++++++++++++++
 test/source/unoapi_test.cxx  |    6 ++++++
 3 files changed, 43 insertions(+)

New commits:
commit fc3993c6794e2749400755ecd032165a61d5d959
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Tue Nov 22 13:42:06 2022 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Nov 22 16:49:36 2022 +0100

    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 <xiscofa...@libreoffice.org>

diff --git a/include/test/unoapi_test.hxx b/include/test/unoapi_test.hxx
index ece36abdb149..1f14f6a21f77 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 518a219e3a92..4976c19c17f0 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 a1c0580cfd61..ff566c8ffa10 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();

Reply via email to