sc/inc/dpcache.hxx | 2 sc/qa/unit/ucalc.cxx | 139 ++++++++++++++++++++++++++++++++++++++++ sc/source/core/data/dpcache.cxx | 2 3 files changed, 141 insertions(+), 2 deletions(-)
New commits: commit 8cd1517e5e414e339085554d93e447cc0cc85213 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Fri Mar 16 12:34:40 2012 -0400 New unit test for testing pivot cache. diff --git a/sc/inc/dpcache.hxx b/sc/inc/dpcache.hxx index bd2fa5a..839f64b 100644 --- a/sc/inc/dpcache.hxx +++ b/sc/inc/dpcache.hxx @@ -134,7 +134,7 @@ public: SCCOL GetDimensionIndex(const rtl::OUString& sName) const; sal_uLong GetNumberFormat( long nDim ) const; bool IsDateDimension( long nDim ) const ; - SCROW GetDimMemberCount( SCCOL nDim ) const; + long GetDimMemberCount(long nDim) const; SCROW GetOrder( long nDim, SCROW nIndex ) const; const ItemsType& GetDimMemberValues( SCCOL nDim ) const; diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index cf1526f..5d71971 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -59,6 +59,7 @@ #include "dpshttab.hxx" #include "dpobject.hxx" #include "dpsave.hxx" +#include "dpcache.hxx" #include "formula/IFunctionDescription.hxx" @@ -146,6 +147,8 @@ public: */ void testPivotTableNamedSource(); + void testPivotTableCache(); + void testSheetCopy(); void testSheetMove(); void testExternalRef(); @@ -200,6 +203,7 @@ public: CPPUNIT_TEST(testPivotTableDateLabels); CPPUNIT_TEST(testPivotTableFilters); CPPUNIT_TEST(testPivotTableNamedSource); + CPPUNIT_TEST(testPivotTableCache); CPPUNIT_TEST(testSheetCopy); CPPUNIT_TEST(testSheetMove); CPPUNIT_TEST(testExternalRef); @@ -1099,6 +1103,26 @@ struct DPFieldDef }; template<size_t _Size> +ScRange insertRangeData(ScDocument* pDoc, const ScAddress& rPos, const char* aData[][_Size], size_t nRowCount) +{ + for (size_t i = 0; i < _Size; ++i) + { + for (size_t j = 0; j < nRowCount; ++j) + { + SCCOL nCol = i + rPos.Col(); + SCROW nRow = j + rPos.Row(); + pDoc->SetString(nCol, nRow, rPos.Tab(), OUString(aData[j][i], strlen(aData[j][i]), RTL_TEXTENCODING_UTF8)); + } + } + + ScRange aRange(rPos); + aRange.aEnd.SetCol(rPos.Col()+_Size-1); + aRange.aEnd.SetRow(rPos.Row()+nRowCount-1); + printRange(pDoc, aRange, "Range data content"); + return aRange; +} + +template<size_t _Size> ScRange insertDPSourceData(ScDocument* pDoc, DPFieldDef aFields[], size_t nFieldCount, const char* aData[][_Size], size_t nDataCount) { // Insert field names in row 0. @@ -1850,6 +1874,121 @@ void Test::testPivotTableNamedSource() m_pDoc->DeleteTab(0); } +void Test::testPivotTableCache() +{ + m_pDoc->InsertTab(0, OUString(RTL_CONSTASCII_USTRINGPARAM("Data"))); + + // Raw data + const char* aData[][3] = { + { "F1", "F2", "F3" }, + { "Z", "A", "30" }, + { "R", "A", "20" }, + { "A", "B", "45" }, + { "F", "B", "12" }, + { "Y", "C", "8" }, + { "12", "C", "15" }, + }; + + ScAddress aPos(1,1,0); + ScRange aDataRange = insertRangeData(m_pDoc, aPos, aData, SAL_N_ELEMENTS(aData)); + CPPUNIT_ASSERT_MESSAGE("failed to insert range data at correct position", aDataRange.aStart == aPos); + + ScDPCache aCache(m_pDoc); + aCache.InitFromDoc(m_pDoc, aDataRange); + long nDimCount = aCache.GetColumnCount(); + CPPUNIT_ASSERT_MESSAGE("wrong dimension count.", nDimCount == 3); + rtl::OUString aDimName = aCache.GetDimensionName(0); + CPPUNIT_ASSERT_MESSAGE("wrong dimension name", aDimName.equalsAscii("F1")); + aDimName = aCache.GetDimensionName(1); + CPPUNIT_ASSERT_MESSAGE("wrong dimension name", aDimName.equalsAscii("F2")); + aDimName = aCache.GetDimensionName(2); + CPPUNIT_ASSERT_MESSAGE("wrong dimension name", aDimName.equalsAscii("F3")); + + // In each dimension, member ID values also represent their order; + // dimension members are sorted in ascending order. And values come + // before strings. Also, no duplicate dimension members exist. + + // Dimension 0 - a mix of strings and values. + long nMemCount = aCache.GetDimMemberCount(0); + CPPUNIT_ASSERT_MESSAGE("wrong dimension member count", nMemCount == 6); + const ScDPItemData* pItem = aCache.GetItemDataById(0, 0); + CPPUNIT_ASSERT_MESSAGE("wrong item value", pItem && + pItem->GetType() == ScDPItemData::Value && + pItem->GetValue() == 12); + pItem = aCache.GetItemDataById(0, 1); + CPPUNIT_ASSERT_MESSAGE("wrong item value", pItem && + pItem->GetType() == ScDPItemData::String && + pItem->GetString().equalsAscii("A")); + pItem = aCache.GetItemDataById(0, 2); + CPPUNIT_ASSERT_MESSAGE("wrong item value", pItem && + pItem->GetType() == ScDPItemData::String && + pItem->GetString().equalsAscii("F")); + pItem = aCache.GetItemDataById(0, 3); + CPPUNIT_ASSERT_MESSAGE("wrong item value", pItem && + pItem->GetType() == ScDPItemData::String && + pItem->GetString().equalsAscii("R")); + pItem = aCache.GetItemDataById(0, 4); + CPPUNIT_ASSERT_MESSAGE("wrong item value", pItem && + pItem->GetType() == ScDPItemData::String && + pItem->GetString().equalsAscii("Y")); + pItem = aCache.GetItemDataById(0, 5); + CPPUNIT_ASSERT_MESSAGE("wrong item value", pItem && + pItem->GetType() == ScDPItemData::String && + pItem->GetString().equalsAscii("Z")); + pItem = aCache.GetItemDataById(0, 6); + CPPUNIT_ASSERT_MESSAGE("wrong item value", !pItem); + + // Dimension 1 - duplicate values in source. + nMemCount = aCache.GetDimMemberCount(1); + CPPUNIT_ASSERT_MESSAGE("wrong dimension member count", nMemCount == 3); + pItem = aCache.GetItemDataById(1, 0); + CPPUNIT_ASSERT_MESSAGE("wrong item value", pItem && + pItem->GetType() == ScDPItemData::String && + pItem->GetString().equalsAscii("A")); + pItem = aCache.GetItemDataById(1, 1); + CPPUNIT_ASSERT_MESSAGE("wrong item value", pItem && + pItem->GetType() == ScDPItemData::String && + pItem->GetString().equalsAscii("B")); + pItem = aCache.GetItemDataById(1, 2); + CPPUNIT_ASSERT_MESSAGE("wrong item value", pItem && + pItem->GetType() == ScDPItemData::String && + pItem->GetString().equalsAscii("C")); + pItem = aCache.GetItemDataById(1, 3); + CPPUNIT_ASSERT_MESSAGE("wrong item value", !pItem); + + // Dimension 2 - values only. + nMemCount = aCache.GetDimMemberCount(2); + CPPUNIT_ASSERT_MESSAGE("wrong dimension member count", nMemCount == 6); + pItem = aCache.GetItemDataById(2, 0); + CPPUNIT_ASSERT_MESSAGE("wrong item value", pItem && + pItem->GetType() == ScDPItemData::Value && + pItem->GetValue() == 8); + pItem = aCache.GetItemDataById(2, 1); + CPPUNIT_ASSERT_MESSAGE("wrong item value", pItem && + pItem->GetType() == ScDPItemData::Value && + pItem->GetValue() == 12); + pItem = aCache.GetItemDataById(2, 2); + CPPUNIT_ASSERT_MESSAGE("wrong item value", pItem && + pItem->GetType() == ScDPItemData::Value && + pItem->GetValue() == 15); + pItem = aCache.GetItemDataById(2, 3); + CPPUNIT_ASSERT_MESSAGE("wrong item value", pItem && + pItem->GetType() == ScDPItemData::Value && + pItem->GetValue() == 20); + pItem = aCache.GetItemDataById(2, 4); + CPPUNIT_ASSERT_MESSAGE("wrong item value", pItem && + pItem->GetType() == ScDPItemData::Value && + pItem->GetValue() == 30); + pItem = aCache.GetItemDataById(2, 5); + CPPUNIT_ASSERT_MESSAGE("wrong item value", pItem && + pItem->GetType() == ScDPItemData::Value && + pItem->GetValue() == 45); + pItem = aCache.GetItemDataById(2, 6); + CPPUNIT_ASSERT_MESSAGE("wrong item value", !pItem); + + m_pDoc->DeleteTab(0); +} + void Test::testSheetCopy() { OUString aTabName(RTL_CONSTASCII_USTRINGPARAM("TestTab")); diff --git a/sc/source/core/data/dpcache.cxx b/sc/source/core/data/dpcache.cxx index 3e5b433..216c2ff 100644 --- a/sc/source/core/data/dpcache.cxx +++ b/sc/source/core/data/dpcache.cxx @@ -848,7 +848,7 @@ bool ScDPCache::IsDateDimension( long nDim ) const return (eType == NUMBERFORMAT_DATE) || (eType == NUMBERFORMAT_DATETIME); } -SCROW ScDPCache::GetDimMemberCount( SCCOL nDim ) const +long ScDPCache::GetDimMemberCount(long nDim) const { OSL_ENSURE( nDim>=0 && nDim < mnColumnCount ," ScDPTableDataCache::GetDimMemberCount : out of bound "); return maFields[nDim].maItems.size(); _______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits