[Libreoffice-commits] core.git: sc/qa
Eike Rathke
erack at redhat.com
Wed Nov 27 17:00:03 PST 2013
sc/qa/unit/ucalc_formula.cxx | 48 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 47 insertions(+), 1 deletion(-)
New commits:
commit 7d1c2f227d9e0eeb518b52c9a8251c043927d76e
Author: Eike Rathke <erack at redhat.com>
Date: Thu Nov 28 01:58:59 2013 +0100
added unit test for horizontal MATCH, fdo#71589
Change-Id: Ib3195870e708db49448d68d262611561c68ddcc6
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index a51308c..b07fffc 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -2158,13 +2158,53 @@ void runTestMATCH(ScDocument* pDoc, const char* aData[_DataSize], StrStrCheck aC
}
}
+template<size_t _DataSize, size_t _FormulaSize, int _Type>
+void runTestHorizontalMATCH(ScDocument* pDoc, const char* aData[_DataSize], StrStrCheck aChecks[_FormulaSize])
+{
+ size_t nDataSize = _DataSize;
+ for (size_t i = 0; i < nDataSize; ++i)
+ pDoc->SetString(i, 0, 0, OUString::createFromAscii(aData[i]));
+
+ for (size_t i = 0; i < _FormulaSize; ++i)
+ {
+ pDoc->SetString(i, 1, 0, OUString::createFromAscii(aChecks[i].pVal));
+
+ // Assume we don't have more than 26 data columns..
+ OUStringBuffer aBuf;
+ aBuf.appendAscii("=MATCH(");
+ aBuf.append(static_cast<sal_Unicode>('A'+i));
+ aBuf.appendAscii("2;A1:");
+ aBuf.append(static_cast<sal_Unicode>('A'+nDataSize));
+ aBuf.appendAscii("1;");
+ aBuf.append(static_cast<sal_Int32>(_Type));
+ aBuf.appendAscii(")");
+ OUString aFormula = aBuf.makeStringAndClear();
+ pDoc->SetString(i, 2, 0, aFormula);
+ }
+
+ pDoc->CalcAll();
+ Test::printRange(pDoc, ScRange(0, 0, 0, _FormulaSize-1, 2, 0), "MATCH");
+
+ // verify the results.
+ for (size_t i = 0; i < _FormulaSize; ++i)
+ {
+ OUString aStr = pDoc->GetString(i, 2, 0);
+ if (!aStr.equalsAscii(aChecks[i].pRes))
+ {
+ cerr << "column " << char('A'+i) << ": expected='" << aChecks[i].pRes << "' actual='" << aStr << "'"
+ << " criterion='" << aChecks[i].pVal << "'" << endl;
+ CPPUNIT_ASSERT_MESSAGE("Unexpected result for horizontal MATCH", false);
+ }
+ }
+}
+
void Test::testFuncMATCH()
{
OUString aTabName("foo");
CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
m_pDoc->InsertTab (0, aTabName));
- clearRange(m_pDoc, ScRange(0, 0, 0, 4, 40, 0));
+ clearRange(m_pDoc, ScRange(0, 0, 0, 40, 40, 0));
{
// Ascending in-exact match
@@ -2204,6 +2244,9 @@ void Test::testFuncMATCH()
};
runTestMATCH<SAL_N_ELEMENTS(aData),SAL_N_ELEMENTS(aChecks),1>(m_pDoc, aData, aChecks);
+ clearRange(m_pDoc, ScRange(0, 0, 0, 4, 40, 0));
+ runTestHorizontalMATCH<SAL_N_ELEMENTS(aData),SAL_N_ELEMENTS(aChecks),1>(m_pDoc, aData, aChecks);
+ clearRange(m_pDoc, ScRange(0, 0, 0, 40, 4, 0));
}
{
@@ -2246,6 +2289,9 @@ void Test::testFuncMATCH()
};
runTestMATCH<SAL_N_ELEMENTS(aData),SAL_N_ELEMENTS(aChecks),-1>(m_pDoc, aData, aChecks);
+ clearRange(m_pDoc, ScRange(0, 0, 0, 4, 40, 0));
+ runTestHorizontalMATCH<SAL_N_ELEMENTS(aData),SAL_N_ELEMENTS(aChecks),-1>(m_pDoc, aData, aChecks);
+ clearRange(m_pDoc, ScRange(0, 0, 0, 40, 4, 0));
}
m_pDoc->DeleteTab(0);
More information about the Libreoffice-commits
mailing list