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/xenumeration.hxx>
13 #include <com/sun/star/container/XEnumerationAccess.hpp>
14 #include <com/sun/star/container/XIndexAccess.hpp>
15 #include <com/sun/star/lang/XComponent.hpp>
16 #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
17 #include <com/sun/star/sheet/XDataPilotTables.hpp>
18 #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
19 #include <com/sun/star/sheet/XSpreadsheet.hpp>
20 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
21 #include <com/sun/star/sheet/XSpreadsheets.hpp>
22 #include <com/sun/star/table/CellAddress.hpp>
23 #include <com/sun/star/table/CellRangeAddress.hpp>
24 #include <com/sun/star/uno/XInterface.hpp>
26 #include <com/sun/star/uno/Reference.hxx>
29 using namespace css::uno
;
33 class ScIndexEnumeration_DataPilotFieldsEnumeration
: public CalcUnoApiTest
,
34 public apitest::XEnumeration
37 ScIndexEnumeration_DataPilotFieldsEnumeration();
39 virtual uno::Reference
<uno::XInterface
> init() override
;
40 virtual void setUp() override
;
41 virtual void tearDown() override
;
43 CPPUNIT_TEST_SUITE(ScIndexEnumeration_DataPilotFieldsEnumeration
);
46 CPPUNIT_TEST(testHasMoreElements
);
47 CPPUNIT_TEST(testNextElement
);
49 CPPUNIT_TEST_SUITE_END();
52 uno::Reference
<lang::XComponent
> m_xComponent
;
55 ScIndexEnumeration_DataPilotFieldsEnumeration::ScIndexEnumeration_DataPilotFieldsEnumeration()
56 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
60 uno::Reference
<uno::XInterface
> ScIndexEnumeration_DataPilotFieldsEnumeration::init()
62 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(m_xComponent
, uno::UNO_QUERY_THROW
);
63 CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc
.is());
65 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), uno::UNO_SET_THROW
);
66 uno::Reference
<container::XIndexAccess
> xIA(xSheets
, uno::UNO_QUERY_THROW
);
67 uno::Reference
<sheet::XSpreadsheet
> xSheet0(xIA
->getByIndex(0), uno::UNO_QUERY_THROW
);
69 for (auto i
= 1; i
< 4; ++i
)
71 xSheet0
->getCellByPosition(i
, 0)->setFormula("Col" + OUString::number(i
));
72 xSheet0
->getCellByPosition(0, i
)->setFormula("Row" + OUString::number(i
));
75 for (auto x
= 1; x
< 4; ++x
)
76 for (auto y
= 1; y
< 4; ++y
)
77 xSheet0
->getCellByPosition(x
, y
)->setValue(x
* (y
+ 1));
79 uno::Reference
<sheet::XDataPilotTablesSupplier
> xDPTS(xSheet0
, uno::UNO_QUERY_THROW
);
80 uno::Reference
<sheet::XDataPilotTables
> xDPT(xDPTS
->getDataPilotTables(), uno::UNO_SET_THROW
);
81 uno::Reference
<sheet::XDataPilotDescriptor
> xDPD(xDPT
->createDataPilotDescriptor(),
83 xDPD
->setSourceRange(table::CellRangeAddress(0, 0, 0, 4, 4));
84 xDPT
->insertNewByName("DataPilotTable", table::CellAddress(0, 5, 5), xDPD
);
86 uno::Reference
<container::XEnumerationAccess
> xEA(xDPD
->getDataPilotFields(),
87 uno::UNO_QUERY_THROW
);
89 return xEA
->createEnumeration();
92 void ScIndexEnumeration_DataPilotFieldsEnumeration::setUp()
94 CalcUnoApiTest::setUp();
95 m_xComponent
= loadFromDesktop("private:factory/scalc");
96 CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent
.is());
99 void ScIndexEnumeration_DataPilotFieldsEnumeration::tearDown()
101 closeDocument(m_xComponent
);
102 CalcUnoApiTest::tearDown();
105 CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_DataPilotFieldsEnumeration
);
107 } // namespace sc_apitest
109 CPPUNIT_PLUGIN_IMPLEMENT();
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */