nss: upgrade to release 3.73
[LibreOffice.git] / sc / qa / extras / scdatapilottablesobj.cxx
blob3095feee7e6386e7f11b017f262f5885e9a3fcd1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
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/.
8 */
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>
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>
35 using namespace css;
36 using namespace css::uno;
37 using namespace com::sun::star;
39 namespace sc_apitest
41 class ScDataPilotTablesObj : public CalcUnoApiTest,
42 public apitest::XDataPilotTables,
43 public apitest::XElementAccess,
44 public apitest::XEnumerationAccess,
45 public apitest::XIndexAccess,
46 public apitest::XNameAccess,
47 public apitest::XServiceInfo
49 public:
50 ScDataPilotTablesObj();
52 virtual uno::Reference<uno::XInterface> init() override;
53 virtual uno::Reference<uno::XInterface> getXSpreadsheet() override;
54 virtual void setUp() override;
55 virtual void tearDown() override;
57 CPPUNIT_TEST_SUITE(ScDataPilotTablesObj);
59 // XDataPilotTables
60 CPPUNIT_TEST(testXDataPilotTables);
62 // XElementAccess
63 CPPUNIT_TEST(testGetElementType);
64 CPPUNIT_TEST(testHasElements);
66 // XEnumerationAccess
67 CPPUNIT_TEST(testCreateEnumeration);
69 // XIndexAccess
70 CPPUNIT_TEST(testGetByIndex);
71 CPPUNIT_TEST(testGetCount);
73 // XNameAccess
74 CPPUNIT_TEST(testGetByName);
75 CPPUNIT_TEST(testGetElementNames);
76 CPPUNIT_TEST(testHasByName);
78 // XServiceInfo
79 CPPUNIT_TEST(testGetImplementationName);
80 CPPUNIT_TEST(testGetSupportedServiceNames);
81 CPPUNIT_TEST(testSupportsService);
83 CPPUNIT_TEST_SUITE_END();
85 private:
86 uno::Reference<lang::XComponent> mxComponent;
89 ScDataPilotTablesObj::ScDataPilotTablesObj()
90 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
91 , XElementAccess(cppu::UnoType<sheet::XDataPilotTable2>::get())
92 , XIndexAccess(1)
93 , XNameAccess("DataPilotTable")
94 , XServiceInfo("ScDataPilotTablesObj", "com.sun.star.sheet.DataPilotTables")
98 uno::Reference<uno::XInterface> ScDataPilotTablesObj::init()
100 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
102 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW);
103 uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), UNO_QUERY_THROW);
104 uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW);
106 for (auto i = 1; i < 4; i++)
108 xSheet->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i));
109 xSheet->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i));
112 uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet, UNO_QUERY_THROW);
113 uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), UNO_SET_THROW);
114 uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(),
115 UNO_SET_THROW);
116 xDPD->setSourceRange(table::CellRangeAddress(0, 0, 0, 4, 4));
117 xDPT->insertNewByName("DataPilotTable", table::CellAddress(0, 5, 5), xDPD);
119 return xDPT;
122 uno::Reference<uno::XInterface> ScDataPilotTablesObj::getXSpreadsheet()
124 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
126 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW);
127 uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), UNO_QUERY_THROW);
128 uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW);
130 return xSheet;
133 void ScDataPilotTablesObj::setUp()
135 CalcUnoApiTest::setUp();
136 // create a calc document
137 mxComponent = loadFromDesktop("private:factory/scalc");
140 void ScDataPilotTablesObj::tearDown()
142 closeDocument(mxComponent);
143 CalcUnoApiTest::tearDown();
146 CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotTablesObj);
148 } // namespace sc_apitest
150 CPPUNIT_PLUGIN_IMPLEMENT();
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */