[Libreoffice-commits] .: sc/inc sc/qa sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Thu Jan 13 20:11:16 PST 2011


 sc/inc/dpobject.hxx                |    7 +++++-
 sc/inc/dpoutput.hxx                |    2 -
 sc/qa/unit/ucalc.cxx               |   40 +++++++++++++++++++++++++++++--------
 sc/source/core/data/dpobject.cxx   |    3 +-
 sc/source/core/data/dpoutput.cxx   |    2 -
 sc/source/ui/docshell/dbdocfun.cxx |    2 -
 6 files changed, 43 insertions(+), 13 deletions(-)

New commits:
commit 377c1fa61a3afb5e7eb3d9e24a548903e05d9986
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Thu Jan 13 23:10:37 2011 -0500

    More on unittesting data pilot.

diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx
index 8dd5645..9982089 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 523146d..4e0e75c 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 65b9f38..1f9b7f3 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 2f1d65e..674b88b 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 50c7c75..795b5a0 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 e3ef979..fb74592 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


More information about the Libreoffice-commits mailing list