fdo#66969: Add test to ensure we import page field's visibility correctly.

Change-Id: I407b1f552ce089c0ff1d6bdadc1cc618fb713646
This commit is contained in:
Kohei Yoshida 2013-12-10 20:53:44 -05:00
parent b3977983e9
commit e8fff12af2
4 changed files with 73 additions and 3 deletions

View file

@ -531,7 +531,7 @@ public:
bool HasPivotTable() const;
SC_DLLPUBLIC ScDPCollection* GetDPCollection();
SC_DLLPUBLIC const ScDPCollection* GetDPCollection() const;
ScDPObject* GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const;
SC_DLLPUBLIC ScDPObject* GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const;
ScDPObject* GetDPAtBlock( const ScRange& rBlock ) const;
SC_DLLPUBLIC ScChartCollection* GetChartCollection() const;

View file

@ -282,7 +282,7 @@ public:
SheetCaches(ScDocument* pDoc);
bool hasCache(const ScRange& rRange) const;
const ScDPCache* getCache(const ScRange& rRange, const ScDPDimensionSaveData* pDimData);
size_t size() const;
SC_DLLPUBLIC size_t size() const;
void updateReference(
UpdateRefMode eMode, const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz);
@ -397,7 +397,7 @@ public:
void FreeTable(ScDPObject* pDPObj);
SC_DLLPUBLIC bool InsertNewTable(ScDPObject* pDPObj);
SheetCaches& GetSheetCaches();
SC_DLLPUBLIC SheetCaches& GetSheetCaches();
NameCaches& GetNameCaches();
DBCaches& GetDBCaches();

View file

@ -45,6 +45,7 @@
#include "editutil.hxx"
#include "cellvalue.hxx"
#include "attrib.hxx"
#include "dpsave.hxx"
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
#include <com/sun/star/drawing/XControlShape.hpp>
@ -138,6 +139,8 @@ public:
void testCellAnchoredShapesODS();
void testPivotTableBasicODS();
void testPivotTableSharedCacheGroupODS();
void testFormulaDependency();
void testRowHeightODS();
@ -198,6 +201,7 @@ public:
CPPUNIT_TEST(testCellAnchoredShapesODS);
CPPUNIT_TEST(testPivotTableBasicODS);
CPPUNIT_TEST(testPivotTableSharedCacheGroupODS);
CPPUNIT_TEST(testRowHeightODS);
CPPUNIT_TEST(testFormulaDependency);
CPPUNIT_TEST(testRichTextContentODS);
@ -1646,6 +1650,72 @@ void ScFiltersTest::testPivotTableBasicODS()
xDocSh->DoClose();
}
namespace {
bool checkVisiblePageFieldMember( const ScDPSaveDimension::MemberList& rMembers, const OUString& rVisibleMember )
{
ScDPSaveDimension::MemberList::const_iterator it = rMembers.begin(), itEnd = rMembers.end();
bool bFound = false;
for (; it != itEnd; ++it)
{
const ScDPSaveMember* pMem = *it;
if (pMem->GetName() == rVisibleMember)
{
bFound = true;
if (!pMem->GetIsVisible())
// This member is supposed to be visible. Fail.
return false;
}
else
{
if (pMem->GetIsVisible())
// This member is supposed to be hidden. Not good.
return false;
}
}
return bFound;
}
}
void ScFiltersTest::testPivotTableSharedCacheGroupODS()
{
ScDocShellRef xDocSh = loadDoc("pivot-table-shared-cache-with-group.", ODS);
CPPUNIT_ASSERT_MESSAGE("Failed to load file", xDocSh.Is());
ScDocument* pDoc = xDocSh->GetDocument();
// Make sure that page field's visibility settings are loaded correctly.
ScDPObject* pDPObj = pDoc->GetDPAtCursor(0, 0, 1); // A1 on 2nd sheet
CPPUNIT_ASSERT_MESSAGE("There should be a pivot table here.", pDPObj);
ScDPSaveData* pSaveData = pDPObj->GetSaveData();
CPPUNIT_ASSERT_MESSAGE("Save data is expected.", pSaveData);
ScDPSaveDimension* pDim = pSaveData->GetExistingDimensionByName("Project Name");
CPPUNIT_ASSERT_MESSAGE("Failed to get page field named 'Project Name'.", pDim);
const ScDPSaveDimension::MemberList* pMembers = &pDim->GetMembers();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(14), pMembers->size());
CPPUNIT_ASSERT_MESSAGE("Incorrect member visibility.", checkVisiblePageFieldMember(*pMembers, "APL-01-1"));
pDPObj = pDoc->GetDPAtCursor(0, 1, 2); // A2 on 3rd sheet
CPPUNIT_ASSERT_MESSAGE("There should be a pivot table here.", pDPObj);
pSaveData = pDPObj->GetSaveData();
CPPUNIT_ASSERT_MESSAGE("Save data is expected.", pSaveData);
pDim = pSaveData->GetExistingDimensionByName("Project Name");
CPPUNIT_ASSERT_MESSAGE("Failed to get page field named 'Project Name'.", pDim);
pMembers = &pDim->GetMembers();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(14), pMembers->size());
CPPUNIT_ASSERT_MESSAGE("Incorrect member visibility.", checkVisiblePageFieldMember(*pMembers, "VEN-01-1"));
// These two pivot tables shared the same data range. We should only have
// one pivot cache.
ScDPCollection* pDPs = pDoc->GetDPCollection();
ScDPCollection::SheetCaches& rSheetCaches = pDPs->GetSheetCaches();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rSheetCaches.size());
xDocSh->DoClose();
}
void ScFiltersTest::testRowHeightODS()
{
ScDocShellRef xDocSh = loadDoc("row-height-import.", ODS);