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/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>
16 #include <test/sheet/xdatapilottables.hxx>
18 #include <com/sun/star/container/XIndexAccess.hpp>
19 #include <com/sun/star/lang/XComponent.hpp>
20 #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
21 #include <com/sun/star/sheet/XDataPilotTable2.hpp>
22 #include <com/sun/star/sheet/XDataPilotTables.hpp>
23 #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
24 #include <com/sun/star/sheet/XSpreadsheet.hpp>
25 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
26 #include <com/sun/star/sheet/XSpreadsheets.hpp>
27 #include <com/sun/star/table/CellAddress.hpp>
28 #include <com/sun/star/table/CellRangeAddress.hpp>
29 #include <com/sun/star/uno/XInterface.hpp>
31 #include <com/sun/star/uno/Reference.hxx>
33 #include <cppu/unotype.hxx>
36 using namespace css::uno
;
37 using namespace com::sun::star
;
41 class ScDataPilotTablesObj
: public UnoApiTest
,
42 public apitest::XDataPilotTables
,
43 public apitest::XElementAccess
,
44 public apitest::XEnumerationAccess
,
45 public apitest::XIndexAccess
,
46 public apitest::XNameAccess
,
47 public apitest::XServiceInfo
50 ScDataPilotTablesObj();
52 virtual uno::Reference
<uno::XInterface
> init() override
;
53 virtual uno::Reference
<uno::XInterface
> getXSpreadsheet() override
;
54 virtual void setUp() override
;
56 CPPUNIT_TEST_SUITE(ScDataPilotTablesObj
);
59 CPPUNIT_TEST(testXDataPilotTables
);
62 CPPUNIT_TEST(testGetElementType
);
63 CPPUNIT_TEST(testHasElements
);
66 CPPUNIT_TEST(testCreateEnumeration
);
69 CPPUNIT_TEST(testGetByIndex
);
70 CPPUNIT_TEST(testGetCount
);
73 CPPUNIT_TEST(testGetByName
);
74 CPPUNIT_TEST(testGetElementNames
);
75 CPPUNIT_TEST(testHasByName
);
78 CPPUNIT_TEST(testGetImplementationName
);
79 CPPUNIT_TEST(testGetSupportedServiceNames
);
80 CPPUNIT_TEST(testSupportsService
);
82 CPPUNIT_TEST_SUITE_END();
85 ScDataPilotTablesObj::ScDataPilotTablesObj()
86 : UnoApiTest("/sc/qa/extras/testdocuments")
87 , XElementAccess(cppu::UnoType
<sheet::XDataPilotTable2
>::get())
89 , XNameAccess("DataPilotTable")
90 , XServiceInfo("ScDataPilotTablesObj", "com.sun.star.sheet.DataPilotTables")
94 uno::Reference
<uno::XInterface
> ScDataPilotTablesObj::init()
96 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, UNO_QUERY_THROW
);
98 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), UNO_SET_THROW
);
99 uno::Reference
<container::XIndexAccess
> xIndex(xDoc
->getSheets(), UNO_QUERY_THROW
);
100 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIndex
->getByIndex(0), UNO_QUERY_THROW
);
102 for (auto i
= 1; i
< 4; i
++)
104 xSheet
->getCellByPosition(i
, 0)->setFormula("Col" + OUString::number(i
));
105 xSheet
->getCellByPosition(0, i
)->setFormula("Row" + OUString::number(i
));
108 uno::Reference
<sheet::XDataPilotTablesSupplier
> xDPTS(xSheet
, UNO_QUERY_THROW
);
109 uno::Reference
<sheet::XDataPilotTables
> xDPT(xDPTS
->getDataPilotTables(), UNO_SET_THROW
);
110 uno::Reference
<sheet::XDataPilotDescriptor
> xDPD(xDPT
->createDataPilotDescriptor(),
112 xDPD
->setSourceRange(table::CellRangeAddress(0, 0, 0, 4, 4));
113 xDPT
->insertNewByName("DataPilotTable", table::CellAddress(0, 5, 5), xDPD
);
118 uno::Reference
<uno::XInterface
> ScDataPilotTablesObj::getXSpreadsheet()
120 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, UNO_QUERY_THROW
);
122 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), UNO_SET_THROW
);
123 uno::Reference
<container::XIndexAccess
> xIndex(xDoc
->getSheets(), UNO_QUERY_THROW
);
124 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIndex
->getByIndex(0), UNO_QUERY_THROW
);
129 void ScDataPilotTablesObj::setUp()
132 // create a calc document
133 mxComponent
= loadFromDesktop("private:factory/scalc");
136 CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotTablesObj
);
138 } // namespace sc_apitest
140 CPPUNIT_PLUGIN_IMPLEMENT();
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */