summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-01-03 09:47:01 -0500
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-01-03 09:49:49 -0500
commit724a8ccd81567a2ad93111a9cac257eb7ec7819f (patch)
treed73b1c546863101320324d28d551d12a4bd64797
parent6b8704d974abd4ab7fb58036a961fa0b7136aaa7 (diff)
fdo#73113: Write unit test for LOOKUP.
Change-Id: I1486b6ba9604c97601df142a32b211ce0aec7f09
-rw-r--r--sc/qa/unit/ucalc.hxx2
-rw-r--r--sc/qa/unit/ucalc_formula.cxx48
2 files changed, 50 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 5cf8306a34b8..9ccc85aa7c67 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -103,6 +103,7 @@ public:
void testFuncN();
void testFuncCOUNTIF();
void testFuncNUMBERVALUE();
+ void testFuncLOOKUP();
void testFuncVLOOKUP();
void testFuncMATCH();
void testFuncCELL();
@@ -317,6 +318,7 @@ public:
CPPUNIT_TEST(testFuncN);
CPPUNIT_TEST(testFuncCOUNTIF);
CPPUNIT_TEST(testFuncNUMBERVALUE);
+ CPPUNIT_TEST(testFuncLOOKUP);
CPPUNIT_TEST(testFuncVLOOKUP);
CPPUNIT_TEST(testFuncMATCH);
CPPUNIT_TEST(testFuncCELL);
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index b07fffcdc981..199494a7fced 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -2017,6 +2017,54 @@ void Test::testFuncNUMBERVALUE()
m_pDoc->DeleteTab(0);
}
+void Test::testFuncLOOKUP()
+{
+ FormulaGrammarSwitch aFGSwitch(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH_XL_R1C1);
+
+ m_pDoc->InsertTab(0, "Test");
+
+ // Raw data
+ const char* aData[][2] = {
+ { "=CONCATENATE(\"A\")", "1" },
+ { "=CONCATENATE(\"B\")", "2" },
+ { "=CONCATENATE(\"C\")", "3" },
+ { 0, 0 } // terminator
+ };
+
+ // Insert raw data into A1:B3.
+ for (SCROW i = 0; aData[i][0]; ++i)
+ {
+ m_pDoc->SetString(0, i, 0, OUString::createFromAscii(aData[i][0]));
+ m_pDoc->SetString(1, i, 0, OUString::createFromAscii(aData[i][1]));
+ }
+
+ const char* aData2[][2] = {
+ { "A", "=LOOKUP(RC[-1];R1C1:R3C1;R1C2:R3C2)" },
+ { "B", "=LOOKUP(RC[-1];R1C1:R3C1;R1C2:R3C2)" },
+ { "C", "=LOOKUP(RC[-1];R1C1:R3C1;R1C2:R3C2)" },
+ };
+
+ // Insert check formulas into A5:B7.
+ for (SCROW i = 0; aData2[i][0]; ++i)
+ {
+ m_pDoc->SetString(0, i+4, 0, OUString::createFromAscii(aData2[i][0]));
+ m_pDoc->SetString(1, i+4, 0, OUString::createFromAscii(aData2[i][1]));
+ }
+
+ printRange(m_pDoc, ScRange(0,4,0,1,6,0), "Data range for LOOKUP.");
+
+ // Values for B5:B7 should be 1, 2, and 3.
+ CPPUNIT_ASSERT_MESSAGE("This formula should not have an error code.", m_pDoc->GetErrCode(ScAddress(1,4,0)) == 0);
+ CPPUNIT_ASSERT_MESSAGE("This formula should not have an error code.", m_pDoc->GetErrCode(ScAddress(1,5,0)) == 0);
+ CPPUNIT_ASSERT_MESSAGE("This formula should not have an error code.", m_pDoc->GetErrCode(ScAddress(1,6,0)) == 0);
+
+ CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(ScAddress(1,4,0)));
+ CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(1,5,0)));
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(1,6,0)));
+
+ m_pDoc->DeleteTab(0);
+}
+
void Test::testFuncVLOOKUP()
{
// VLOOKUP