nss: upgrade to release 3.73
[LibreOffice.git] / sc / qa / extras / scdatapilotfieldgroupitemobj.cxx
blobe40170e5198c8b2fc27242ab878ed1b4b16a3cd4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/xnamed.hxx>
12 #include <test/lang/xserviceinfo.hxx>
14 #include <com/sun/star/beans/XPropertySet.hpp>
15 #include <com/sun/star/container/XIndexAccess.hpp>
16 #include <com/sun/star/container/XNameAccess.hpp>
17 #include <com/sun/star/lang/XComponent.hpp>
18 #include <com/sun/star/sheet/DataPilotFieldGroupInfo.hpp>
19 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
20 #include <com/sun/star/sheet/GeneralFunction.hpp>
21 #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
22 #include <com/sun/star/sheet/XDataPilotFieldGrouping.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>
30 #include <com/sun/star/uno/XInterface.hpp>
32 #include <com/sun/star/uno/Reference.hxx>
33 #include <com/sun/star/uno/Sequence.hxx>
35 #include <comphelper/types.hxx>
37 using namespace css;
39 namespace sc_apitest
41 class ScDataPilotFieldGroupItemObj : public CalcUnoApiTest,
42 public apitest::XNamed,
43 public apitest::XServiceInfo
45 public:
46 ScDataPilotFieldGroupItemObj();
48 virtual uno::Reference<uno::XInterface> init() override;
49 virtual void setUp() override;
50 virtual void tearDown() override;
52 CPPUNIT_TEST_SUITE(ScDataPilotFieldGroupItemObj);
54 // XNamed
55 CPPUNIT_TEST(testGetName);
56 CPPUNIT_TEST(testSetName);
58 // XServiceInfo
59 CPPUNIT_TEST(testGetImplementationName);
60 CPPUNIT_TEST(testGetSupportedServiceNames);
61 CPPUNIT_TEST(testSupportsService);
63 CPPUNIT_TEST_SUITE_END();
65 private:
66 static const int m_nMaxFieldIndex = 6;
67 uno::Reference<lang::XComponent> m_xComponent;
70 ScDataPilotFieldGroupItemObj::ScDataPilotFieldGroupItemObj()
71 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
72 , XNamed("aName")
73 , XServiceInfo("ScDataPilotFieldGroupItemObj", "com.sun.star.sheet.DataPilotFieldGroupItem")
77 uno::Reference<uno::XInterface> ScDataPilotFieldGroupItemObj::init()
79 table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1);
80 table::CellAddress aCellAddress(0, 7, 8);
82 uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW);
83 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW);
84 uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW);
85 xSheets->insertNewByName("Some Sheet", 0);
87 uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
88 uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW);
90 for (auto i = 1; i < m_nMaxFieldIndex; ++i)
92 xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i));
93 xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i));
94 xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i));
95 xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i));
98 for (auto i = 1; i < m_nMaxFieldIndex; ++i)
100 for (auto j = 1; j < m_nMaxFieldIndex; ++j)
102 xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1));
103 xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2));
107 xSheet0->getCellByPosition(1, 1)->setFormula("aName");
108 xSheet0->getCellByPosition(1, 2)->setFormula("otherName");
109 xSheet0->getCellByPosition(1, 3)->setFormula("una");
110 xSheet0->getCellByPosition(1, 4)->setFormula("otherName");
111 xSheet0->getCellByPosition(1, 5)->setFormula("somethingelse");
113 xSheet0->getCellByPosition(1, 5);
114 xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3);
116 uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW);
117 uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW);
118 uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(),
119 uno::UNO_SET_THROW);
121 xDPD->setSourceRange(aCellRangeAddress);
123 uno::Reference<beans::XPropertySet> xPropertySet0(xDPD->getDataPilotFields()->getByIndex(0),
124 uno::UNO_QUERY_THROW);
125 xPropertySet0->setPropertyValue("Orientation",
126 uno::makeAny(sheet::DataPilotFieldOrientation_ROW));
128 uno::Reference<beans::XPropertySet> xPropertySet1(xDPD->getDataPilotFields()->getByIndex(1),
129 uno::UNO_QUERY_THROW);
130 xPropertySet1->setPropertyValue("Function", uno::makeAny(sheet::GeneralFunction_SUM));
131 xPropertySet1->setPropertyValue("Orientation",
132 uno::makeAny(sheet::DataPilotFieldOrientation_DATA));
134 uno::Reference<beans::XPropertySet> xPropertySet2(xDPD->getDataPilotFields()->getByIndex(2),
135 uno::UNO_QUERY_THROW);
136 xPropertySet2->setPropertyValue("Orientation",
137 uno::makeAny(sheet::DataPilotFieldOrientation_COLUMN));
139 xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD);
141 uno::Reference<container::XIndexAccess> xIA_DPT0(xDPTS->getDataPilotTables(),
142 uno::UNO_QUERY_THROW);
143 uno::Reference<sheet::XDataPilotDescriptor> xDPD0(xIA_DPT0->getByIndex(0),
144 uno::UNO_QUERY_THROW);
145 uno::Reference<container::XIndexAccess> xIA_RF0(xDPD0->getRowFields(), uno::UNO_SET_THROW);
147 uno::Reference<sheet::XDataPilotFieldGrouping> xDPFG(xIA_RF0->getByIndex(0),
148 uno::UNO_QUERY_THROW);
149 uno::Sequence<OUString> aElements(2);
150 aElements[0] = "aName";
151 aElements[1] = "otherName";
152 xDPFG->createNameGroup(aElements);
154 uno::Reference<container::XIndexAccess> xIA_DPT1(xDPTS->getDataPilotTables(),
155 uno::UNO_QUERY_THROW);
156 uno::Reference<sheet::XDataPilotDescriptor> xDPD1(xIA_DPT1->getByIndex(0),
157 uno::UNO_QUERY_THROW);
158 uno::Reference<container::XIndexAccess> xIA_RF1(xDPD1->getRowFields(), uno::UNO_SET_THROW);
160 sheet::DataPilotFieldGroupInfo aDPFGI;
161 for (auto i = 0; i < xIA_RF1->getCount(); ++i)
163 uno::Reference<beans::XPropertySet> xPropertySet(xIA_RF1->getByIndex(i),
164 uno::UNO_QUERY_THROW);
165 if (::comphelper::getBOOL(xPropertySet->getPropertyValue("IsGroupField")))
167 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("GroupInfo") >>= aDPFGI);
171 uno::Reference<container::XIndexAccess> xIA_GI(aDPFGI.Groups, uno::UNO_QUERY_THROW);
172 uno::Reference<container::XNameAccess> xNA_GN(xIA_GI->getByIndex(0), uno::UNO_QUERY_THROW);
174 uno::Reference<uno::XInterface> xReturn(xNA_GN->getByName("aName"), uno::UNO_QUERY_THROW);
175 return xReturn;
178 void ScDataPilotFieldGroupItemObj::setUp()
180 CalcUnoApiTest::setUp();
181 // create a calc document
182 m_xComponent = loadFromDesktop("private:factory/scalc");
185 void ScDataPilotFieldGroupItemObj::tearDown()
187 closeDocument(m_xComponent);
188 CalcUnoApiTest::tearDown();
191 CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldGroupItemObj);
193 } // namespace sc_apitest
195 CPPUNIT_PLUGIN_IMPLEMENT();
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */