1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 <cppu/unotype.hxx>
19 #include <com/sun/star/beans/XPropertySet.hpp>
20 #include <com/sun/star/container/XIndexAccess.hpp>
21 #include <com/sun/star/lang/XComponent.hpp>
22 #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
23 #include <com/sun/star/sheet/XDataPilotTables.hpp>
24 #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
25 #include <com/sun/star/sheet/XSpreadsheet.hpp>
26 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
27 #include <com/sun/star/sheet/XSpreadsheets.hpp>
28 #include <com/sun/star/table/CellAddress.hpp>
29 #include <com/sun/star/table/CellRangeAddress.hpp>
31 #include <com/sun/star/uno/Reference.hxx>
36 class ScDataPilotFieldsObj
: public CalcUnoApiTest
,
37 public apitest::XElementAccess
,
38 public apitest::XEnumerationAccess
,
39 public apitest::XIndexAccess
,
40 public apitest::XNameAccess
,
41 public apitest::XServiceInfo
44 ScDataPilotFieldsObj();
45 virtual uno::Reference
<uno::XInterface
> init() override
;
46 virtual void setUp() override
;
47 virtual void tearDown() override
;
49 CPPUNIT_TEST_SUITE(ScDataPilotFieldsObj
);
52 CPPUNIT_TEST(testHasElements
);
53 CPPUNIT_TEST(testGetElementType
);
56 CPPUNIT_TEST(testCreateEnumeration
);
59 CPPUNIT_TEST(testGetByIndex
);
60 CPPUNIT_TEST(testGetCount
);
63 CPPUNIT_TEST(testGetByName
);
64 CPPUNIT_TEST(testGetElementNames
);
65 CPPUNIT_TEST(testHasByName
);
68 CPPUNIT_TEST(testGetImplementationName
);
69 CPPUNIT_TEST(testGetSupportedServiceNames
);
70 CPPUNIT_TEST(testSupportsService
);
72 CPPUNIT_TEST_SUITE_END();
75 uno::Reference
<lang::XComponent
> m_xComponent
;
78 ScDataPilotFieldsObj::ScDataPilotFieldsObj()
79 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
80 , XElementAccess(cppu::UnoType
<beans::XPropertySet
>::get())
83 , XServiceInfo("ScDataPilotFieldsObj", "com.sun.star.sheet.DataPilotFields")
87 uno::Reference
<uno::XInterface
> ScDataPilotFieldsObj::init()
89 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(m_xComponent
, uno::UNO_QUERY_THROW
);
90 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), uno::UNO_SET_THROW
);
91 uno::Reference
<container::XIndexAccess
> xIA(xSheets
, uno::UNO_QUERY_THROW
);
93 uno::Reference
<sheet::XSpreadsheet
> xSheet0(xIA
->getByIndex(0), uno::UNO_QUERY_THROW
);
95 for (int i
= 1; i
< 4; ++i
)
97 xSheet0
->getCellByPosition(i
, 0)->setFormula("Col" + OUString::number(i
));
98 xSheet0
->getCellByPosition(0, i
)->setFormula("Row" + OUString::number(i
));
101 for (int i
= 1; i
< 4; ++i
)
103 for (int j
= 1; j
< 4; ++j
)
105 xSheet0
->getCellByPosition(i
, j
)->setValue(i
* (j
+ 1));
109 uno::Reference
<sheet::XDataPilotTablesSupplier
> xDPTS(xSheet0
, uno::UNO_QUERY_THROW
);
110 uno::Reference
<sheet::XDataPilotTables
> xDPT(xDPTS
->getDataPilotTables(), uno::UNO_SET_THROW
);
111 uno::Reference
<sheet::XDataPilotDescriptor
> xDPD(xDPT
->createDataPilotDescriptor(),
114 xDPD
->setSourceRange(table::CellRangeAddress(0, 0, 0, 4, 4));
115 xDPT
->insertNewByName("DataPilotTable", table::CellAddress(0, 5, 5), xDPD
);
117 return xDPD
->getDataPilotFields();
120 void ScDataPilotFieldsObj::setUp()
122 CalcUnoApiTest::setUp();
123 // create a calc document
124 m_xComponent
= loadFromDesktop("private:factory/scalc");
127 void ScDataPilotFieldsObj::tearDown()
129 closeDocument(m_xComponent
);
130 CalcUnoApiTest::tearDown();
133 CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldsObj
);
135 } // namespace sc_apitest
137 CPPUNIT_PLUGIN_IMPLEMENT();
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */