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/calc_unoapi_test.hxx>
11 #include <test/container/xelementaccess.hxx>
12 #include <test/container/xenumerationaccess.hxx>
13 #include <test/container/xindexaccess.hxx>
14 #include <test/container/xnameaccess.hxx>
15 #include <test/lang/xserviceinfo.hxx>
17 #include <com/sun/star/beans/XPropertySet.hpp>
18 #include <com/sun/star/container/XIndexAccess.hpp>
19 #include <com/sun/star/lang/XComponent.hpp>
20 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
21 #include <com/sun/star/sheet/GeneralFunction.hpp>
22 #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
23 #include <com/sun/star/sheet/XDataPilotField.hpp>
24 #include <com/sun/star/sheet/XDataPilotTables.hpp>
25 #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
26 #include <com/sun/star/sheet/XSpreadsheet.hpp>
27 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
28 #include <com/sun/star/sheet/XSpreadsheets.hpp>
29 #include <com/sun/star/table/CellAddress.hpp>
30 #include <com/sun/star/table/CellRangeAddress.hpp>
31 #include <com/sun/star/uno/XInterface.hpp>
33 #include <com/sun/star/uno/Reference.hxx>
39 class ScDataPilotItemsObj
: public CalcUnoApiTest
,
40 public apitest::XElementAccess
,
41 public apitest::XEnumerationAccess
,
42 public apitest::XIndexAccess
,
43 public apitest::XNameAccess
,
44 public apitest::XServiceInfo
47 ScDataPilotItemsObj();
49 virtual uno::Reference
<uno::XInterface
> init() override
;
50 virtual void setUp() override
;
51 virtual void tearDown() override
;
53 CPPUNIT_TEST_SUITE(ScDataPilotItemsObj
);
56 CPPUNIT_TEST(testGetElementType
);
57 CPPUNIT_TEST(testHasElements
);
60 CPPUNIT_TEST(testCreateEnumeration
);
63 CPPUNIT_TEST(testGetByIndex
);
64 CPPUNIT_TEST(testGetCount
);
67 CPPUNIT_TEST(testGetByName
);
68 CPPUNIT_TEST(testGetElementNames
);
69 CPPUNIT_TEST(testHasByName
);
72 CPPUNIT_TEST(testGetImplementationName
);
73 CPPUNIT_TEST(testGetSupportedServiceNames
);
74 CPPUNIT_TEST(testSupportsService
);
76 CPPUNIT_TEST_SUITE_END();
79 static const int m_nMaxFieldIndex
= 6;
80 uno::Reference
<lang::XComponent
> m_xComponent
;
83 ScDataPilotItemsObj::ScDataPilotItemsObj()
84 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
85 , XElementAccess(cppu::UnoType
<beans::XPropertySet
>::get())
88 , XServiceInfo("ScDataPilotItemsObj", "com.sun.star.sheet.DataPilotItems")
92 uno::Reference
<uno::XInterface
> ScDataPilotItemsObj::init()
94 table::CellRangeAddress
aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex
- 1, m_nMaxFieldIndex
- 1);
95 table::CellAddress
aCellAddress(0, 7, 8);
97 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(m_xComponent
, uno::UNO_QUERY_THROW
);
98 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), uno::UNO_SET_THROW
);
99 uno::Reference
<container::XIndexAccess
> xIA(xSheets
, uno::UNO_QUERY_THROW
);
100 xSheets
->insertNewByName("Some Sheet", 0);
102 uno::Reference
<sheet::XSpreadsheet
> xSheet0(xIA
->getByIndex(0), uno::UNO_QUERY_THROW
);
103 uno::Reference
<sheet::XSpreadsheet
> xSheet1(xIA
->getByIndex(1), uno::UNO_QUERY_THROW
);
105 for (auto i
= 1; i
< m_nMaxFieldIndex
; ++i
)
107 xSheet0
->getCellByPosition(i
, 0)->setFormula("Col" + OUString::number(i
));
108 xSheet0
->getCellByPosition(0, i
)->setFormula("Row" + OUString::number(i
));
109 xSheet1
->getCellByPosition(i
, 0)->setFormula("Col" + OUString::number(i
));
110 xSheet1
->getCellByPosition(0, i
)->setFormula("Row" + OUString::number(i
));
113 for (auto i
= 1; i
< m_nMaxFieldIndex
; ++i
)
115 for (auto j
= 1; j
< m_nMaxFieldIndex
; ++j
)
117 xSheet0
->getCellByPosition(i
, j
)->setValue(i
* (j
+ 1));
118 xSheet1
->getCellByPosition(i
, j
)->setValue(i
* (j
+ 2));
122 xSheet0
->getCellByPosition(1, 5);
123 xSheet0
->getCellByPosition(aCellAddress
.Column
, aCellAddress
.Row
+ 3);
125 uno::Reference
<sheet::XDataPilotTablesSupplier
> xDPTS(xSheet0
, uno::UNO_QUERY_THROW
);
126 uno::Reference
<sheet::XDataPilotTables
> xDPT(xDPTS
->getDataPilotTables(), uno::UNO_SET_THROW
);
127 uno::Reference
<sheet::XDataPilotDescriptor
> xDPD(xDPT
->createDataPilotDescriptor(),
130 xDPD
->setSourceRange(aCellRangeAddress
);
132 uno::Reference
<beans::XPropertySet
> xPropertySet(xDPD
->getDataPilotFields()->getByIndex(1),
133 uno::UNO_QUERY_THROW
);
134 xPropertySet
->setPropertyValue("Function", uno::makeAny(sheet::GeneralFunction_SUM
));
135 xPropertySet
->setPropertyValue("Orientation",
136 uno::makeAny(sheet::DataPilotFieldOrientation_DATA
));
138 xDPT
->insertNewByName("DataPilotTable", aCellAddress
, xDPD
);
140 uno::Reference
<container::XIndexAccess
> xIA_DPF(xDPD
->getDataPilotFields(), uno::UNO_SET_THROW
);
141 uno::Reference
<sheet::XDataPilotField
> xDPF(xIA_DPF
->getByIndex(0), uno::UNO_QUERY_THROW
);
143 return xDPF
->getItems();
146 void ScDataPilotItemsObj::setUp()
148 CalcUnoApiTest::setUp();
149 // create a calc document
150 m_xComponent
= loadFromDesktop("private:factory/scalc");
153 void ScDataPilotItemsObj::tearDown()
155 closeDocument(m_xComponent
);
156 CalcUnoApiTest::tearDown();
159 CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotItemsObj
);
161 } // namespace sc_apitest
163 CPPUNIT_PLUGIN_IMPLEMENT();
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */