sc/qa/unit/uicalc/uicalc.cxx |   37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

New commits:
commit 312cf9580c4b7846d217ce241c36f327a81f6cea
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu Mar 24 10:41:57 2022 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Mar 24 12:51:14 2022 +0100

    tdf#100847: sc_uicalc: Add unittest
    
    Change-Id: I0bd79a0b3bc6d92ec83ecd86c4ca631e65528c35
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132057
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx
index fe90247e16ce..b9823ff02bb5 100644
--- a/sc/qa/unit/uicalc/uicalc.cxx
+++ b/sc/qa/unit/uicalc/uicalc.cxx
@@ -232,6 +232,43 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf36387)
     CPPUNIT_ASSERT_EQUAL(OUString("TRUE"), pDoc->GetString(ScAddress(1, 0, 
0)));
 }
 
+CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf100847)
+{
+    mxComponent = loadFromDesktop("private:factory/scalc");
+    ScModelObj* pModelObj = dynamic_cast<ScModelObj*>(mxComponent.get());
+    CPPUNIT_ASSERT(pModelObj);
+    ScDocument* pDoc = pModelObj->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+
+    // Save the document
+    utl::TempFile aTempFile = save(mxComponent, "calc8");
+
+    // Open a new document
+    mxComponent = loadFromDesktop("private:factory/scalc");
+    pModelObj = dynamic_cast<ScModelObj*>(mxComponent.get());
+    CPPUNIT_ASSERT(pModelObj);
+    pDoc = pModelObj->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+
+    // Insert the reference to the external document
+    OUString aFormula = "=+'" + aTempFile.GetURL() + "'#$Sheet1.A1";
+    insertStringToCell(*pModelObj, "A1", aFormula.toUtf8().getStr());
+
+    aFormula = "=+'" + aTempFile.GetURL() + "'#$Sheet1.A1*1";
+    insertStringToCell(*pModelObj, "B1", aFormula.toUtf8().getStr());
+
+    aFormula = "=+N('" + aTempFile.GetURL() + "'#$Sheet1.A1)*1";
+    insertStringToCell(*pModelObj, "C1", aFormula.toUtf8().getStr());
+
+    CPPUNIT_ASSERT_EQUAL(OUString("0"), pDoc->GetString(ScAddress(0, 0, 0)));
+
+    // Without the fix in place, this test would have failed with
+    // - Expected: 0
+    // - Actual  : #VALUE!
+    CPPUNIT_ASSERT_EQUAL(OUString("0"), pDoc->GetString(ScAddress(1, 0, 0)));
+    CPPUNIT_ASSERT_EQUAL(OUString("0"), pDoc->GetString(ScAddress(2, 0, 0)));
+}
+
 CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf103994)
 {
     mxComponent = loadFromDesktop("private:factory/scalc");

Reply via email to