summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2011-01-13 23:10:37 -0500
committerKohei Yoshida <kyoshida@novell.com>2011-01-13 23:10:37 -0500
commitc88a779c43c98db1f93a28fe667e29e94b8918f5 (patch)
tree2b5e165b3c9be1d6d7ca588078aace5f6eacfb87
parentfb092f75bdc057437624e3f40268db4f7f1bbf3f (diff)
More on unittesting data pilot.
-rw-r--r--sc/inc/dpobject.hxx7
-rw-r--r--sc/inc/dpoutput.hxx2
-rw-r--r--sc/qa/unit/ucalc.cxx40
-rw-r--r--sc/source/core/data/dpobject.cxx3
-rw-r--r--sc/source/core/data/dpoutput.cxx2
-rw-r--r--sc/source/ui/docshell/dbdocfun.cxx2
6 files changed, 43 insertions, 13 deletions
diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx
index 95ebbd375b75..9b504516b483 100644
--- a/sc/inc/dpobject.hxx
+++ b/sc/inc/dpobject.hxx
@@ -132,6 +132,11 @@ public:
virtual ScDataObject* Clone() const;
+ /**
+ * When a DP object is "alive", it has table output on a sheet. This flag
+ * doesn't really change the behavior of the object, but is used only for
+ * testing purposes.
+ */
void SetAlive(BOOL bSet);
void SetAllowMove(BOOL bSet);
@@ -140,7 +145,7 @@ public:
void Output( const ScAddress& rPos );
- ScRange GetNewOutputRange( BOOL& rOverflow );
+ ScRange GetNewOutputRange( bool& rOverflow );
const ScRange GetOutputRangeByType( sal_Int32 nType );
void SetSaveData(const ScDPSaveData& rData);
diff --git a/sc/inc/dpoutput.hxx b/sc/inc/dpoutput.hxx
index 77c552ec7026..970445f64ba8 100644
--- a/sc/inc/dpoutput.hxx
+++ b/sc/inc/dpoutput.hxx
@@ -144,7 +144,7 @@ public:
void Output(); //! Refresh?
ScRange GetOutputRange( sal_Int32 nRegionType = ::com::sun::star::sheet::DataPilotOutputRangeType::WHOLE );
long GetHeaderRows();
- BOOL HasError(); // range overflow or exception from source
+ bool HasError(); // range overflow or exception from source
void GetPositionData(const ScAddress& rPos, ::com::sun::star::sheet::DataPilotTablePositionData& rPosData);
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 00d50c7f088f..4dd1edad9364 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -70,6 +70,7 @@
#include <dpsave.hxx>
#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
+#include <com/sun/star/sheet/GeneralFunction.hpp>
using namespace ::com::sun::star;
using ::rtl::OUString;
@@ -349,14 +350,19 @@ void Test::testMatrix()
checkMatrixElements<PartiallyFilledEmptyMatrix>(*pMat);
}
}
-
+#include <iostream>
+using namespace std;
void Test::testDataPilot()
{
m_pDoc->InsertTab(0, OUString(RTL_CONSTASCII_USTRINGPARAM("Data")));
m_pDoc->InsertTab(1, OUString(RTL_CONSTASCII_USTRINGPARAM("Table")));
- const char* aFields[] = {
- "Name", "Group", "Score"
+ struct {
+ const char* pName; sheet::DataPilotFieldOrientation eOrient;
+ } aFields[] = {
+ { "Name", sheet::DataPilotFieldOrientation_ROW },
+ { "Group", sheet::DataPilotFieldOrientation_COLUMN },
+ { "Score", sheet::DataPilotFieldOrientation_DATA }
};
struct {
@@ -375,7 +381,7 @@ void Test::testDataPilot()
// Insert field names in row 0.
for (sal_uInt32 i = 0; i < nFieldCount; ++i)
- m_pDoc->SetString(0, static_cast<SCCOL>(i), 0, OUString(RTL_CONSTASCII_USTRINGPARAM(aFields[i])));
+ m_pDoc->SetString(0, static_cast<SCCOL>(i), 0, OUString(RTL_CONSTASCII_USTRINGPARAM(aFields[i].pName)));
// Insert data into row 1 and downward.
for (sal_uInt32 i = 0; i < nDataCount; ++i)
@@ -408,17 +414,35 @@ void Test::testDataPilot()
aSaveData.SetFilterButton(false);
aSaveData.SetDrillDown(false);
+ // Generate the internal source structure.
pDPObj->GetSource();
+ // Set the dimension information.
for (sal_uInt32 i = 0; i < nFieldCount; ++i)
{
- OUString aDimName(RTL_CONSTASCII_USTRINGPARAM(aFields[i]));
+ OUString aDimName(RTL_CONSTASCII_USTRINGPARAM(aFields[i].pName));
ScDPSaveDimension* pDim = aSaveData.GetDimensionByName(aDimName);
- pDim->SetOrientation(sheet::DataPilotFieldOrientation_COLUMN);
+ pDim->SetOrientation(aFields[i].eOrient);
+ if (aFields[i].eOrient == sheet::DataPilotFieldOrientation_DATA)
+ {
+ pDim->SetFunction(sheet::GeneralFunction_SUM);
+ pDim->SetReferenceValue(NULL);
+ }
}
pDPObj->SetSaveData(aSaveData);
-
- delete pDPObj;
+ pDPObj->SetAlive(true);
+ ScDPCollection* pDPs = m_pDoc->GetDPCollection();
+ bool bSuccess = pDPs->InsertNewTable(pDPObj);
+ CPPUNIT_ASSERT_MESSAGE("failed to insert a new datapilot object", bSuccess);
+ CPPUNIT_ASSERT_MESSAGE("there should be only one data pilot table.", pDPs->GetCount() == 1);
+ pDPObj->InvalidateData();
+ pDPObj->SetName(pDPs->CreateNewName());
+ bool bOverFlow = false;
+ ScRange aOutRange = pDPObj->GetNewOutputRange(bOverFlow);
+
+ // Now, delete the datapilot object.
+ 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);
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index fab675e01755..2a7b95ba627d 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -530,7 +530,7 @@ void ScDPObject::InvalidateSource()
mpTableData.reset();
}
-ScRange ScDPObject::GetNewOutputRange( BOOL& rOverflow )
+ScRange ScDPObject::GetNewOutputRange( bool& rOverflow )
{
CreateOutput(); // create xSource and pOutput if not already done
@@ -2425,6 +2425,7 @@ ScDPCollection::ScDPCollection(const ScDPCollection& r) :
ScDPCollection::~ScDPCollection()
{
+ maTables.clear();
}
void ScDPCollection::DeleteOnTab( SCTAB nTab )
diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx
index b07f83362884..a5dd9a16baee 100644
--- a/sc/source/core/data/dpoutput.cxx
+++ b/sc/source/core/data/dpoutput.cxx
@@ -989,7 +989,7 @@ ScRange ScDPOutput::GetOutputRange( sal_Int32 nRegionType )
return ScRange(aStartPos.Col(), aStartPos.Row(), nTab, nTabEndCol, nTabEndRow, nTab);
}
-BOOL ScDPOutput::HasError()
+bool ScDPOutput::HasError()
{
CalcSizes();
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 22abe5f65a9a..1e4868eea978 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -1305,7 +1305,7 @@ BOOL ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb
if ( !pDestObj->GetName().Len() )
pDestObj->SetName( pDoc->GetDPCollection()->CreateNewName() );
- BOOL bOverflow = FALSE;
+ bool bOverflow = false;
ScRange aNewOut = pDestObj->GetNewOutputRange( bOverflow );
//! test for overlap with other data pilot tables