[Libreoffice-commits] .: Branch 'libreoffice-3-4' - sc/qa
Kohei Yoshida
kohei at kemper.freedesktop.org
Mon May 2 22:27:09 PDT 2011
sc/qa/unit/ucalc.cxx | 147 +++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 143 insertions(+), 4 deletions(-)
New commits:
commit aada201fe2d421c567a21b9903254d25c9b1c9be
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Tue May 3 01:26:21 2011 -0400
Added another unit test to test filtering in data pilot tables.
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 31e7eb9..ba213af 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -88,7 +88,7 @@
#define MDDS_HASH_CONTAINER_BOOST 1
#include <mdds/mixed_type_matrix.hpp>
-#define UCALC_DEBUG_OUTPUT 0
+#define UCALC_DEBUG_OUTPUT 1
using namespace ::com::sun::star;
using ::rtl::OUString;
@@ -231,6 +231,7 @@ public:
void testCSV();
void testMatrix();
void testDataPilot();
+ void testDataPilotFilters();
void testSheetCopy();
void testExternalRef();
void testDataArea();
@@ -270,6 +271,7 @@ public:
CPPUNIT_TEST(testCSV);
CPPUNIT_TEST(testMatrix);
CPPUNIT_TEST(testDataPilot);
+ CPPUNIT_TEST(testDataPilotFilters);
CPPUNIT_TEST(testSheetCopy);
CPPUNIT_TEST(testExternalRef);
CPPUNIT_TEST(testDataArea);
@@ -714,7 +716,9 @@ struct DPFieldDef
sheet::DataPilotFieldOrientation eOrient;
};
-ScDPObject* createDPFromRange(ScDocument* pDoc, const ScRange& rRange, DPFieldDef aFields[], size_t nFieldCount)
+ScDPObject* createDPFromRange(
+ ScDocument* pDoc, const ScRange& rRange, DPFieldDef aFields[], size_t nFieldCount,
+ bool bFilterButton)
{
SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row();
SCCOL nCol1 = rRange.aStart.Col();
@@ -738,7 +742,7 @@ ScDPObject* createDPFromRange(ScDocument* pDoc, const ScRange& rRange, DPFieldDe
aSaveData.SetRepeatIfEmpty(false);
aSaveData.SetColumnGrand(true);
aSaveData.SetRowGrand(true);
- aSaveData.SetFilterButton(false);
+ aSaveData.SetFilterButton(bFilterButton);
aSaveData.SetDrillDown(true);
// Check the sanity of the source range.
@@ -870,7 +874,7 @@ void Test::testDataPilot()
printer.clear();
ScDPObject* pDPObj = createDPFromRange(
- m_pDoc, ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0), aFields, nFieldCount);
+ m_pDoc, ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0), aFields, nFieldCount, false);
ScDPCollection* pDPs = m_pDoc->GetDPCollection();
bool bSuccess = pDPs->InsertNewTable(pDPObj);
@@ -986,6 +990,141 @@ void Test::testDataPilot()
m_pDoc->DeleteTab(0);
}
+void Test::testDataPilotFilters()
+{
+ m_pDoc->InsertTab(0, OUString(RTL_CONSTASCII_USTRINGPARAM("Data")));
+ m_pDoc->InsertTab(1, OUString(RTL_CONSTASCII_USTRINGPARAM("Table")));
+
+ // Dimension definition
+ DPFieldDef aFields[] = {
+ { "Name", sheet::DataPilotFieldOrientation_HIDDEN },
+ { "Group1", sheet::DataPilotFieldOrientation_HIDDEN },
+ { "Group2", sheet::DataPilotFieldOrientation_PAGE },
+ { "Val1", sheet::DataPilotFieldOrientation_DATA },
+ { "Val2", sheet::DataPilotFieldOrientation_DATA }
+ };
+
+ // Raw data
+ const char* aData[][5] = {
+ { "A", "1", "A", "1", "10" },
+ { "B", "1", "A", "1", "10" },
+ { "C", "1", "B", "1", "10" },
+ { "D", "1", "B", "1", "10" },
+ { "E", "2", "A", "1", "10" },
+ { "F", "2", "A", "1", "10" },
+ { "G", "2", "B", "1", "10" },
+ { "H", "2", "B", "1", "10" }
+ };
+
+ size_t nFieldCount = SAL_N_ELEMENTS(aFields);
+ size_t nDataCount = SAL_N_ELEMENTS(aData);
+
+ // Insert field names in row 0.
+ for (size_t i = 0; i < nFieldCount; ++i)
+ m_pDoc->SetString(static_cast<SCCOL>(i), 0, 0, OUString(aFields[i].pName, strlen(aFields[i].pName), RTL_TEXTENCODING_UTF8));
+
+ // Insert data into row 1 and downward.
+ for (size_t i = 0; i < nDataCount; ++i)
+ {
+ SCROW nRow = static_cast<SCROW>(i) + 1;
+ for (size_t j = 0; j < nFieldCount; ++j)
+ {
+ SCCOL nCol = static_cast<SCCOL>(j);
+ m_pDoc->SetString(
+ nCol, nRow, 0, OUString(aData[i][j], strlen(aData[i][j]), RTL_TEXTENCODING_UTF8));
+ }
+ }
+
+ SCROW nRow1 = 0, nRow2 = 0;
+ SCCOL nCol1 = 0, nCol2 = 0;
+ m_pDoc->GetDataArea(0, nCol1, nRow1, nCol2, nRow2, true, false);
+ CPPUNIT_ASSERT_MESSAGE("Data is expected to start from (col=0,row=0).", nCol1 == 0 && nRow1 == 0);
+ CPPUNIT_ASSERT_MESSAGE("Unexpected data range.",
+ nCol2 == static_cast<SCCOL>(nFieldCount - 1) && nRow2 == static_cast<SCROW>(nDataCount));
+
+ SheetPrinter printer(nRow2 - nRow1 + 1, nCol2 - nCol1 + 1);
+ for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
+ {
+ for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
+ {
+ String aVal;
+ m_pDoc->GetString(nCol, nRow, 0, aVal);
+ printer.set(nRow, nCol, aVal);
+ }
+ }
+ printer.print("Data sheet content");
+ printer.clear();
+
+ ScDPObject* pDPObj = createDPFromRange(
+ m_pDoc, ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0), aFields, nFieldCount, true);
+
+ ScDPCollection* pDPs = m_pDoc->GetDPCollection();
+ bool bSuccess = pDPs->InsertNewTable(pDPObj);
+ CPPUNIT_ASSERT_MESSAGE("failed to insert a new datapilot object into document", bSuccess);
+ CPPUNIT_ASSERT_MESSAGE("there should be only one data pilot table.",
+ pDPs->GetCount() == 1);
+ pDPObj->SetName(pDPs->CreateNewName());
+
+ bool bOverFlow = false;
+ ScRange aOutRange = pDPObj->GetNewOutputRange(bOverFlow);
+ CPPUNIT_ASSERT_MESSAGE("Table overflow!?", !bOverFlow);
+
+ pDPObj->Output(aOutRange.aStart);
+ aOutRange = pDPObj->GetOutRange();
+ {
+ // Expected output table content. 0 = empty cell
+ const char* aOutputCheck[][2] = {
+ { "Filter", 0 },
+ { "Group2", "- all -" },
+ { 0, 0 },
+ { "Data", 0 },
+ { "Sum - Val1", "8" },
+ { "Sum - Val2", "80" },
+ { "Total Sum - Val1", "8" },
+ { "Total Sum - Val2", "80" }
+ };
+
+ bSuccess = checkDPTableOutput<2>(m_pDoc, aOutRange, aOutputCheck, "DataPilot table output");
+ CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
+ }
+
+ // Set current page of 'Group2' to 'A'.
+ ScDPSaveData aSaveData(*pDPObj->GetSaveData());
+ ScDPSaveDimension* pDim = aSaveData.GetDimensionByName(
+ OUString(RTL_CONSTASCII_USTRINGPARAM("Group2")));
+ CPPUNIT_ASSERT_MESSAGE("Dimension not found", pDim);
+ OUString aPage(RTL_CONSTASCII_USTRINGPARAM("A"));
+ pDim->SetCurrentPage(&aPage);
+ pDPObj->SetSaveData(aSaveData);
+ pDPObj->Output(aOutRange.aStart);
+ aOutRange = pDPObj->GetOutRange();
+ {
+ // Expected output table content. 0 = empty cell
+ const char* aOutputCheck[][2] = {
+ { "Filter", 0 },
+ { "Group2", "A" },
+ { 0, 0 },
+ { "Data", 0 },
+ { "Sum - Val1", "4" },
+ { "Sum - Val2", "40" },
+ { "Total Sum - Val1", "4" },
+ { "Total Sum - Val2", "40" }
+ };
+
+ bSuccess = checkDPTableOutput<2>(m_pDoc, aOutRange, aOutputCheck, "DataPilot table output");
+ CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess);
+ }
+
+ // TODO: Find out how to set standard filter and test it.
+
+ pDPs->FreeTable(pDPObj);
+ CPPUNIT_ASSERT_MESSAGE("There shouldn't be any data pilot table stored with the document.",
+ pDPs->GetCount() == 0);
+
+ m_pDoc->DeleteTab(1);
+ m_pDoc->DeleteTab(0);
+}
+
void Test::testSheetCopy()
{
OUString aTabName(RTL_CONSTASCII_USTRINGPARAM("TestTab"));
More information about the Libreoffice-commits
mailing list