summaryrefslogtreecommitdiff
path: root/sc/qa/unit
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@suse.com>2011-11-01 12:48:59 -0400
committerKohei Yoshida <kohei.yoshida@suse.com>2011-11-01 12:49:25 -0400
commit61f74ecffe8e0685a022e5d224595891de64bb2c (patch)
treea44568f20fdc2dd9862e422fe9cf727e2984b8ce /sc/qa/unit
parent54760dfdc26fcded5c62bbad05429db5c9cee935 (diff)
Unit test for testing cell functions referencing external ranges.
Diffstat (limited to 'sc/qa/unit')
-rw-r--r--sc/qa/unit/ucalc.cxx56
1 files changed, 56 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 21db934c46e4..6c1ab7554900 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")));