Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / qa / extras / scdatapilotfieldgroupobj.cxx
blobe59ccf713adc30db52d77b3200fb7b713a6a7ec9
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/container/xnamed.hxx>
16 #include <test/lang/xserviceinfo.hxx>
17 #include <comphelper/types.hxx>
19 #include <com/sun/star/beans/XPropertySet.hpp>
20 #include <com/sun/star/container/XIndexAccess.hpp>
21 #include <com/sun/star/container/XNamed.hpp>
22 #include <com/sun/star/lang/XComponent.hpp>
23 #include <com/sun/star/sheet/DataPilotFieldGroupInfo.hpp>
24 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
25 #include <com/sun/star/sheet/GeneralFunction.hpp>
26 #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
27 #include <com/sun/star/sheet/XDataPilotFieldGrouping.hpp>
28 #include <com/sun/star/sheet/XDataPilotTables.hpp>
29 #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
30 #include <com/sun/star/sheet/XSpreadsheet.hpp>
31 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
32 #include <com/sun/star/sheet/XSpreadsheets.hpp>
33 #include <com/sun/star/table/CellAddress.hpp>
34 #include <com/sun/star/table/CellRangeAddress.hpp>
35 #include <com/sun/star/uno/XInterface.hpp>
37 #include <com/sun/star/uno/Reference.hxx>
38 #include <com/sun/star/uno/Sequence.hxx>
40 using namespace css;
42 namespace sc_apitest
44 class ScDataPilotFieldGroupObj : public CalcUnoApiTest,
45 public apitest::XElementAccess,
46 public apitest::XEnumerationAccess,
47 public apitest::XIndexAccess,
48 public apitest::XNameAccess,
49 public apitest::XNamed,
50 public apitest::XServiceInfo
52 public:
53 ScDataPilotFieldGroupObj();
55 virtual uno::Reference<uno::XInterface> init() override;
56 virtual void setUp() override;
57 virtual void tearDown() override;
59 CPPUNIT_TEST_SUITE(ScDataPilotFieldGroupObj);
61 // XElementAccess
62 CPPUNIT_TEST(testGetElementType);
63 CPPUNIT_TEST(testHasElements);
65 // XEnumerationAccess
66 CPPUNIT_TEST(testCreateEnumeration);
68 // XIndexAccess
69 CPPUNIT_TEST(testGetByIndex);
70 CPPUNIT_TEST(testGetCount);
72 // XNameAccess
73 CPPUNIT_TEST(testGetByName);
74 CPPUNIT_TEST(testGetElementNames);
75 CPPUNIT_TEST(testHasByName);
77 // XNamed
78 CPPUNIT_TEST(testGetName);
79 CPPUNIT_TEST(testSetName);
81 // XServiceInfo
82 CPPUNIT_TEST(testGetImplementationName);
83 CPPUNIT_TEST(testGetSupportedServiceNames);
84 CPPUNIT_TEST(testSupportsService);
86 CPPUNIT_TEST_SUITE_END();
88 private:
89 static const int m_nMaxFieldIndex = 6;
90 uno::Reference<lang::XComponent> m_xComponent;
93 ScDataPilotFieldGroupObj::ScDataPilotFieldGroupObj()
94 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
95 , XElementAccess(cppu::UnoType<container::XNamed>::get())
96 , XIndexAccess(2)
97 , XNameAccess("aName")
98 , XNamed("Group1")
99 , XServiceInfo("ScDataPilotFieldGroupObj", "com.sun.star.sheet.DataPilotFieldGroup")
103 uno::Reference<uno::XInterface> ScDataPilotFieldGroupObj::init()
105 table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1);
106 table::CellAddress aCellAddress(0, 7, 8);
108 uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW);
109 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW);
110 uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW);
111 xSheets->insertNewByName("Some Sheet", 0);
113 uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
114 uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW);
116 for (auto i = 1; i < m_nMaxFieldIndex; ++i)
118 xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i));
119 xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i));
120 xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i));
121 xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i));
124 for (auto i = 1; i < m_nMaxFieldIndex; ++i)
126 for (auto j = 1; j < m_nMaxFieldIndex; ++j)
128 xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1));
129 xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2));
133 xSheet0->getCellByPosition(1, 1)->setFormula("aName");
134 xSheet0->getCellByPosition(1, 2)->setFormula("otherName");
135 xSheet0->getCellByPosition(1, 3)->setFormula("una");
136 xSheet0->getCellByPosition(1, 4)->setFormula("otherName");
137 xSheet0->getCellByPosition(1, 5)->setFormula("somethingelse");
139 xSheet0->getCellByPosition(1, 5);
140 xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3);
142 uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW);
143 uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW);
144 uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(),
145 uno::UNO_SET_THROW);
147 xDPD->setSourceRange(aCellRangeAddress);
149 uno::Reference<beans::XPropertySet> xPropertySet0(xDPD->getDataPilotFields()->getByIndex(0),
150 uno::UNO_QUERY_THROW);
151 xPropertySet0->setPropertyValue("Orientation",
152 uno::makeAny(sheet::DataPilotFieldOrientation_ROW));
154 uno::Reference<beans::XPropertySet> xPropertySet1(xDPD->getDataPilotFields()->getByIndex(1),
155 uno::UNO_QUERY_THROW);
156 xPropertySet1->setPropertyValue("Function", uno::makeAny(sheet::GeneralFunction_SUM));
157 xPropertySet1->setPropertyValue("Orientation",
158 uno::makeAny(sheet::DataPilotFieldOrientation_DATA));
160 uno::Reference<beans::XPropertySet> xPropertySet2(xDPD->getDataPilotFields()->getByIndex(2),
161 uno::UNO_QUERY_THROW);
162 xPropertySet2->setPropertyValue("Orientation",
163 uno::makeAny(sheet::DataPilotFieldOrientation_COLUMN));
165 xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD);
167 uno::Reference<container::XIndexAccess> xIA_DPT0(xDPTS->getDataPilotTables(),
168 uno::UNO_QUERY_THROW);
169 uno::Reference<sheet::XDataPilotDescriptor> xDPD0(xIA_DPT0->getByIndex(0),
170 uno::UNO_QUERY_THROW);
171 uno::Reference<container::XIndexAccess> xIA_RF0(xDPD0->getRowFields(), uno::UNO_SET_THROW);
173 uno::Reference<sheet::XDataPilotFieldGrouping> xDPFG(xIA_RF0->getByIndex(0),
174 uno::UNO_QUERY_THROW);
175 uno::Sequence<OUString> aElements(2);
176 aElements[0] = "aName";
177 aElements[1] = "otherName";
178 xDPFG->createNameGroup(aElements);
180 uno::Reference<container::XNameAccess> xNA_GroupNames;
182 uno::Reference<container::XIndexAccess> xIA_DPT1(xDPTS->getDataPilotTables(),
183 uno::UNO_QUERY_THROW);
184 uno::Reference<sheet::XDataPilotDescriptor> xDPD1(xIA_DPT1->getByIndex(0),
185 uno::UNO_QUERY_THROW);
186 uno::Reference<container::XIndexAccess> xIA_RF1(xDPD1->getRowFields(), uno::UNO_SET_THROW);
188 sheet::DataPilotFieldGroupInfo aDPFGI;
189 for (auto i = 0; i < xIA_RF1->getCount(); ++i)
191 uno::Reference<beans::XPropertySet> xPropertySet(xIA_RF1->getByIndex(i),
192 uno::UNO_QUERY_THROW);
193 if (::comphelper::getBOOL(xPropertySet->getPropertyValue("IsGroupField")))
195 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("GroupInfo") >>= aDPFGI);
199 uno::Reference<container::XIndexAccess> xIA_GI(aDPFGI.Groups, uno::UNO_QUERY_THROW);
200 uno::Reference<container::XNameAccess> xNA_GN(xIA_GI->getByIndex(0), uno::UNO_QUERY_THROW);
202 return xNA_GN;
205 void ScDataPilotFieldGroupObj::setUp()
207 CalcUnoApiTest::setUp();
208 // create calc document
209 m_xComponent = loadFromDesktop("private:factory/scalc");
212 void ScDataPilotFieldGroupObj::tearDown()
214 closeDocument(m_xComponent);
215 CalcUnoApiTest::tearDown();
218 CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldGroupObj);
220 } // namespace sc_apitest
222 CPPUNIT_PLUGIN_IMPLEMENT();
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */