1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <test/unoapi_test.hxx>
11 #include <test/container/xenumeration.hxx>
13 #include <com/sun/star/beans/XPropertySet.hpp>
14 #include <com/sun/star/container/XIndexAccess.hpp>
15 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
16 #include <com/sun/star/sheet/GeneralFunction.hpp>
17 #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
18 #include <com/sun/star/sheet/XDataPilotField.hpp>
19 #include <com/sun/star/sheet/XDataPilotTables.hpp>
20 #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
21 #include <com/sun/star/sheet/XSpreadsheet.hpp>
22 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
23 #include <com/sun/star/sheet/XSpreadsheets.hpp>
24 #include <com/sun/star/table/CellAddress.hpp>
25 #include <com/sun/star/table/CellRangeAddress.hpp>
26 #include <com/sun/star/uno/XInterface.hpp>
28 #include <com/sun/star/uno/Reference.hxx>
31 using namespace css::uno
;
32 using namespace com::sun::star
;
36 class ScIndexEnumeration_DataPilotItemsEnumeration
: public UnoApiTest
, public apitest::XEnumeration
39 ScIndexEnumeration_DataPilotItemsEnumeration();
41 virtual uno::Reference
<uno::XInterface
> init() override
;
42 virtual void setUp() override
;
44 CPPUNIT_TEST_SUITE(ScIndexEnumeration_DataPilotItemsEnumeration
);
47 CPPUNIT_TEST(testHasMoreElements
);
48 CPPUNIT_TEST(testNextElement
);
50 CPPUNIT_TEST_SUITE_END();
53 static const int m_nMaxFieldIndex
= 6;
56 ScIndexEnumeration_DataPilotItemsEnumeration::ScIndexEnumeration_DataPilotItemsEnumeration()
57 : UnoApiTest(u
"/sc/qa/extras/testdocuments"_ustr
)
61 uno::Reference
<uno::XInterface
> ScIndexEnumeration_DataPilotItemsEnumeration::init()
63 table::CellRangeAddress
aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex
- 1, m_nMaxFieldIndex
- 1);
64 table::CellAddress
aCellAddress(0, 7, 8);
66 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, uno::UNO_QUERY_THROW
);
67 CPPUNIT_ASSERT_MESSAGE("no document", xDoc
.is());
68 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), uno::UNO_SET_THROW
);
70 uno::Reference
<container::XIndexAccess
> xIA(xSheets
, uno::UNO_QUERY_THROW
);
71 xSheets
->insertNewByName(u
"Some Sheet"_ustr
, 0);
73 uno::Reference
<sheet::XSpreadsheet
> xSheet0(xIA
->getByIndex(0), uno::UNO_QUERY_THROW
);
74 uno::Reference
<sheet::XSpreadsheet
> xSheet1(xIA
->getByIndex(1), uno::UNO_QUERY_THROW
);
76 for (auto i
= 1; i
< m_nMaxFieldIndex
; ++i
)
78 xSheet0
->getCellByPosition(i
, 0)->setFormula("Col" + OUString::number(i
));
79 xSheet0
->getCellByPosition(0, i
)->setFormula("Row" + OUString::number(i
));
80 xSheet1
->getCellByPosition(i
, 0)->setFormula("Col" + OUString::number(i
));
81 xSheet1
->getCellByPosition(0, i
)->setFormula("Row" + OUString::number(i
));
84 for (auto i
= 1; i
< m_nMaxFieldIndex
; ++i
)
86 for (auto j
= 1; j
< m_nMaxFieldIndex
; ++j
)
88 xSheet0
->getCellByPosition(i
, j
)->setValue(i
* (j
+ 1));
89 xSheet1
->getCellByPosition(i
, j
)->setValue(i
* (j
+ 2));
93 xSheet0
->getCellByPosition(1, 5);
94 xSheet0
->getCellByPosition(aCellAddress
.Column
, aCellAddress
.Row
+ 3);
96 uno::Reference
<sheet::XDataPilotTablesSupplier
> xDPTS(xSheet0
, uno::UNO_QUERY_THROW
);
97 uno::Reference
<sheet::XDataPilotTables
> xDPT(xDPTS
->getDataPilotTables(), uno::UNO_SET_THROW
);
98 uno::Reference
<sheet::XDataPilotDescriptor
> xDPD(xDPT
->createDataPilotDescriptor(),
101 xDPD
->setSourceRange(aCellRangeAddress
);
104 uno::Reference
<beans::XPropertySet
> xPropertySet(xDPD
->getDataPilotFields()->getByIndex(0),
105 uno::UNO_QUERY_THROW
);
106 aValue
<<= sheet::DataPilotFieldOrientation_DATA
;
107 xPropertySet
->setPropertyValue(u
"Orientation"_ustr
, aValue
);
108 aValue
<<= sheet::GeneralFunction_SUM
;
109 xPropertySet
->setPropertyValue(u
"Function"_ustr
, aValue
);
111 xDPT
->insertNewByName(u
"DataPilotTable"_ustr
, aCellAddress
, xDPD
);
113 uno::Reference
<sheet::XDataPilotField
> xDPF(xDPD
->getDataPilotFields()->getByIndex(0),
114 uno::UNO_QUERY_THROW
);
115 uno::Reference
<container::XEnumerationAccess
> xEA(xDPF
->getItems(), uno::UNO_QUERY_THROW
);
116 return xEA
->createEnumeration();
119 void ScIndexEnumeration_DataPilotItemsEnumeration::setUp()
122 // create a calc document
123 loadFromURL(u
"private:factory/scalc"_ustr
);
126 CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_DataPilotItemsEnumeration
);
127 } // namespace sc_apitest
129 CPPUNIT_PLUGIN_IMPLEMENT();
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */