11#include <com/sun/star/sheet/XDataPilotTable2.hpp>
12#include <com/sun/star/sheet/DataPilotTableResultData.hpp>
13#include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
14#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
15#include <com/sun/star/sheet/DataPilotTablePositionType.hpp>
16#include <com/sun/star/sheet/DataPilotOutputRangeType.hpp>
17#include <com/sun/star/sheet/XSpreadsheets.hpp>
18#include <com/sun/star/sheet/XCellAddressable.hpp>
19#include <com/sun/star/table/XCellCursor.hpp>
20#include <com/sun/star/sheet/XCellRangeData.hpp>
21#include <com/sun/star/sheet/DataResult.hpp>
22#include <com/sun/star/beans/XPropertySet.hpp>
23#include <cppunit/TestAssert.h>
27using namespace css::uno;
37 uno::Reference< sheet::XDataPilotTable2 > xDPTable(
initDP2(), UNO_QUERY_THROW);
39 table::CellAddress aAddr;
49 sheet::DataPilotTablePositionData aPosData = xDPTable->getPositionData(aAddr);
50 if (aPosData.PositionType == sheet::DataPilotTablePositionType::NOT_IN_TABLE)
52 CPPUNIT_ASSERT(
false);
60 uno::Reference< sheet::XDataPilotTable2 > xDPTable(
initDP2(), UNO_QUERY_THROW);
68 sheet::DataPilotTablePositionData aPosData = xDPTable->getPositionData(rResultCell);
69 Any aTempAny = aPosData.PositionData;
70 sheet::DataPilotTableResultData aResData;
71 CPPUNIT_ASSERT(aTempAny >>= aResData);
73 sheet::DataResult aRes = aResData.Result;
74 double nVal = aRes.Value;
76 const Sequence< Sequence<Any> >
aData = xDPTable->getDrillDownData(rResultCell);
79 if(
aData.getLength() > 1 )
81 sum = std::accumulate(std::next(
aData.begin()),
aData.end(),
double(0),
82 [nDim](
double res,
const Sequence<Any>& rSeq) {
84 if (rSeq[nDim] >>= nValue)
90 CPPUNIT_ASSERT_DOUBLES_EQUAL(nVal, sum, 1
E-12);
98 uno::Reference< sheet::XDataPilotTable2 > xDPTable(
initDP2(), UNO_QUERY_THROW);
102 bool bCaught =
false;
105 xDPTable->getOutputRangeByType(-1);
107 catch (
const lang::IllegalArgumentException& )
111 CPPUNIT_ASSERT(bCaught);
116 xDPTable->getOutputRangeByType(100);
118 catch (
const lang::IllegalArgumentException& )
122 CPPUNIT_ASSERT(bCaught);
145 uno::Reference< sheet::XDataPilotTable2 > xDPTable(
initDP2(), UNO_QUERY_THROW);
148 uno::Reference< sheet::XSpreadsheets > xSheets(
getSheets(), UNO_QUERY_THROW);
149 uno::Reference< container::XIndexAccess > xIA(xSheets, UNO_QUERY_THROW);
150 sal_Int32 nSheetCount = xIA->getCount();
152 for (sal_Int32
i = 0;
i < nCellCount; ++
i)
155 uno::Sequence< uno::Sequence< Any > >
aData = xDPTable->getDrillDownData(aAddr);
156 xDPTable->insertDrillDownSheet(aAddr);
158 sal_Int32 nNewSheetCount= xIA->getCount();
159 if (nNewSheetCount == nSheetCount + 1)
161 CPPUNIT_ASSERT(
aData.getLength() >= 2);
162 uno::Reference< sheet::XSpreadsheet > xSheet(xIA->getByIndex(aAddr.Sheet),UNO_QUERY_THROW);
166 uno::Reference< container::XNamed > xNamed(xSheet, UNO_QUERY_THROW);
167 OUString
aName = xNamed->getName();
168 xSheets->removeByName(
aName);
170 else if (nNewSheetCount == nSheetCount)
172 if (
aData.getLength() > 1)
174 CPPUNIT_ASSERT(
false);
179 CPPUNIT_ASSERT(
false);
194 table::CellAddress aAddr;
198 sheet::DataPilotTablePositionData aPosData = xDPTable->getPositionData(aAddr);
199 if (aPosData.PositionType != sheet::DataPilotTablePositionType::RESULT)
201 CPPUNIT_ASSERT(
false);
210 maRangeWhole = xDPTable->getOutputRangeByType(sheet::DataPilotOutputRangeType::WHOLE);
211 maRangeTable = xDPTable->getOutputRangeByType(sheet::DataPilotOutputRangeType::TABLE);
212 maRangeResult = xDPTable->getOutputRangeByType(sheet::DataPilotOutputRangeType::RESULT);
217 uno::Reference< sheet::XDataPilotDescriptor > xDesc(xDPTable, UNO_QUERY_THROW);
218 uno::Reference< container::XIndexAccess > xIndex(xDesc->getDataPilotFields(), UNO_SET_THROW);
220 sal_Int32 nFieldCount = xIndex->getCount();
221 for( sal_Int32
i = 0;
i < nFieldCount; ++
i)
223 uno::Reference< beans::XPropertySet > xPropSet(xIndex->getByIndex(
i), UNO_QUERY_THROW);
224 Any aAny = xPropSet->getPropertyValue(
"Orientation");
225 sheet::DataPilotFieldOrientation aOrientation;
226 CPPUNIT_ASSERT( aAny >>= aOrientation );
228 if ( aOrientation == sheet::DataPilotFieldOrientation_DATA )
237table::CellAddress getLastUsedCellAddress( uno::Reference< sheet::XSpreadsheet >
const & xSheet, sal_Int32 nCol, sal_Int32 nRow )
239 uno::Reference< sheet::XSheetCellRange > xSheetRange( xSheet->getCellRangeByPosition(nCol, nRow, nCol, nRow), UNO_QUERY_THROW);
240 uno::Reference< sheet::XSheetCellCursor > xCursor = xSheet->createCursorByRange(xSheetRange);
241 uno::Reference< table::XCellCursor > xCellCursor(xCursor, UNO_QUERY_THROW);
242 xCellCursor->gotoEnd();
244 uno::Reference< sheet::XCellAddressable > xCellAddr(xCursor->getCellByPosition(0, 0), UNO_QUERY_THROW);
245 return xCellAddr->getCellAddress();
252 table::CellAddress aLastCell = getLastUsedCellAddress(xSheet, 0, 0);
253 CPPUNIT_ASSERT(
aData.hasElements());
254 CPPUNIT_ASSERT(aLastCell.Row);
255 CPPUNIT_ASSERT(aLastCell.Column);
257 CPPUNIT_ASSERT_EQUAL(
aData.getLength(), aLastCell.Row + 1);
260 uno::Reference< table::XCellRange > xCellRange = xSheet->getCellRangeByPosition(0, 0, aLastCell.Column, aLastCell.Row);
261 uno::Reference< sheet::XCellRangeData > xCellRangeData(xCellRange, UNO_QUERY_THROW);
263 uno::Sequence< uno::Sequence< Any > > aSheetData = xCellRangeData->getDataArray();
264 for (sal_Int32
x = 0;
x < aSheetData.getLength(); ++
x)
266 for(sal_Int32
y = 0;
y < aSheetData[
x].getLength(); ++
y)
268 const Any& aCell1 = aSheetData[
x][
y];
270 CPPUNIT_ASSERT_EQUAL(aCell2, aCell1);
std::vector< css::table::CellAddress > maResultCells
css::table::CellRangeAddress maRangeWhole
void testGetPositionData()
void getOutputRanges(css::uno::Reference< css::sheet::XDataPilotTable2 > const &)
css::table::CellRangeAddress maRangeResult
void buildDataFields(css::uno::Reference< css::sheet::XDataPilotTable2 > const &)
static void checkDrillDownSheetContent(css::uno::Reference< css::sheet::XSpreadsheet > const &xSheet, const css::uno::Sequence< css::uno::Sequence< css::uno::Any > > &aData)
virtual ~XDataPilotTable2()
void testGetDrillDownData()
void testGetOutputRangeByType()
virtual css::uno::Reference< css::uno::XInterface > initDP2()=0
void buildResultCells(css::uno::Reference< css::sheet::XDataPilotTable2 > const &)
virtual css::uno::Reference< css::uno::XInterface > getSheets()=0
css::table::CellRangeAddress maRangeTable
std::vector< sal_Int32 > maDataFieldDims
void testInsertDrillDownSheet()
constexpr OUStringLiteral aData
double getLength(const B2DPolygon &rCandidate)