[Libreoffice-commits] .: sc/qa

Kohei Yoshida kohei at kemper.freedesktop.org
Tue Nov 1 09:49:09 PDT 2011


 sc/qa/unit/ucalc.cxx |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

New commits:
commit 61f74ecffe8e0685a022e5d224595891de64bb2c
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Tue Nov 1 12:48:59 2011 -0400

    Unit test for testing cell functions referencing external ranges.

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 21db934..6c1ab75 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -127,6 +127,7 @@ public:
     void testSheetCopy();
     void testSheetMove();
     void testExternalRef();
+    void testExternalRefFunctions();
     void testDataArea();
     void testAutofilter();
     void testCopyPaste();
@@ -169,6 +170,7 @@ public:
     CPPUNIT_TEST(testSheetCopy);
     CPPUNIT_TEST(testSheetMove);
     CPPUNIT_TEST(testExternalRef);
+    CPPUNIT_TEST(testExternalRefFunctions);
     CPPUNIT_TEST(testDataArea);
     CPPUNIT_TEST(testGraphicsInGroup);
     CPPUNIT_TEST(testStreamValid);
@@ -1498,6 +1500,60 @@ void Test::testExternalRef()
     m_pDoc->DeleteTab(0);
 }
 
+void Test::testExternalRefFunctions()
+{
+    ScDocShellRef xExtDocSh = new ScDocShell;
+    OUString aExtDocName(RTL_CONSTASCII_USTRINGPARAM("file:///extdata.fake"));
+    SfxMedium* pMed = new SfxMedium(aExtDocName, STREAM_STD_READWRITE);
+    xExtDocSh->DoInitNew(pMed);
+    CPPUNIT_ASSERT_MESSAGE("external document instance not loaded.",
+                           findLoadedDocShellByName(aExtDocName) != NULL);
+
+    // Populate the external source document.
+    ScDocument* pExtDoc = xExtDocSh->GetDocument();
+    pExtDoc->InsertTab(0, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Data")));
+    double val = 1;
+    pExtDoc->SetValue(0, 0, 0, val);
+    // leave cell B1 empty.
+    val = 2;
+    pExtDoc->SetValue(0, 1, 0, val);
+    pExtDoc->SetValue(1, 1, 0, val);
+    val = 3;
+    pExtDoc->SetValue(0, 2, 0, val);
+    pExtDoc->SetValue(1, 2, 0, val);
+    val = 4;
+    pExtDoc->SetValue(0, 3, 0, val);
+    pExtDoc->SetValue(1, 3, 0, val);
+
+    m_pDoc->InsertTab(0, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Test")));
+
+    struct {
+        const char* pFormula; double fResult;
+    } aChecks[] = {
+        { "=SUM('file:///extdata.fake'#Data.A1:A4)",     10 },
+        { "=SUM('file:///extdata.fake'#Data.B1:B4)",     9 },
+        { "=AVERAGE('file:///extdata.fake'#Data.A1:A4)", 2.5 },
+        { "=AVERAGE('file:///extdata.fake'#Data.B1:B4)", 3 },
+        { "=COUNT('file:///extdata.fake'#Data.A1:A4)",   4 },
+        { "=COUNT('file:///extdata.fake'#Data.B1:B4)",   3 }
+    };
+
+    for (size_t i = 0; i < SAL_N_ELEMENTS(aChecks); ++i)
+    {
+        m_pDoc->SetString(0, 0, 0, rtl::OUString::createFromAscii(aChecks[i].pFormula));
+        m_pDoc->CalcAll();
+        m_pDoc->GetValue(0, 0, 0, val);
+        CPPUNIT_ASSERT_MESSAGE("unexpected result involving external ranges.", val == aChecks[i].fResult);
+    }
+
+    // Unload the external document shell.
+    xExtDocSh->DoClose();
+    CPPUNIT_ASSERT_MESSAGE("external document instance should have been unloaded.",
+                           findLoadedDocShellByName(aExtDocName) == NULL);
+
+    m_pDoc->DeleteTab(0);
+}
+
 void Test::testDataArea()
 {
     m_pDoc->InsertTab(0, OUString(RTL_CONSTASCII_USTRINGPARAM("Data")));


More information about the Libreoffice-commits mailing list