tdf#164627 docx export: consolidate getWordCompatibilityMode()
[LibreOffice.git] / sc / qa / extras / scdatapilotfieldgroupitemobj.cxx
blobc461d6e7b5634b923c508d21d5232c0ca2727e55
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/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/sheet/DataPilotFieldGroupInfo.hpp>
18 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
19 #include <com/sun/star/sheet/GeneralFunction.hpp>
20 #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
21 #include <com/sun/star/sheet/XDataPilotFieldGrouping.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>
32 #include <com/sun/star/uno/Sequence.hxx>
34 #include <comphelper/types.hxx>
36 using namespace css;
38 namespace sc_apitest
40 class ScDataPilotFieldGroupItemObj : public UnoApiTest,
41 public apitest::XNamed,
42 public apitest::XServiceInfo
44 public:
45 ScDataPilotFieldGroupItemObj();
47 virtual uno::Reference<uno::XInterface> init() override;
48 virtual void setUp() override;
50 CPPUNIT_TEST_SUITE(ScDataPilotFieldGroupItemObj);
52 // XNamed
53 CPPUNIT_TEST(testGetName);
54 CPPUNIT_TEST(testSetName);
56 // XServiceInfo
57 CPPUNIT_TEST(testGetImplementationName);
58 CPPUNIT_TEST(testGetSupportedServiceNames);
59 CPPUNIT_TEST(testSupportsService);
61 CPPUNIT_TEST_SUITE_END();
63 private:
64 static const int m_nMaxFieldIndex = 6;
67 ScDataPilotFieldGroupItemObj::ScDataPilotFieldGroupItemObj()
68 : UnoApiTest(u"/sc/qa/extras/testdocuments"_ustr)
69 , XNamed(u"aName"_ustr)
70 , XServiceInfo(u"ScDataPilotFieldGroupItemObj"_ustr,
71 u"com.sun.star.sheet.DataPilotFieldGroupItem"_ustr)
75 uno::Reference<uno::XInterface> ScDataPilotFieldGroupItemObj::init()
77 table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1);
78 table::CellAddress aCellAddress(0, 7, 8);
80 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
81 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW);
82 uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW);
83 xSheets->insertNewByName(u"Some Sheet"_ustr, 0);
85 uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
86 uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW);
88 for (auto i = 1; i < m_nMaxFieldIndex; ++i)
90 xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i));
91 xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i));
92 xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i));
93 xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i));
96 for (auto i = 1; i < m_nMaxFieldIndex; ++i)
98 for (auto j = 1; j < m_nMaxFieldIndex; ++j)
100 xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1));
101 xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2));
105 xSheet0->getCellByPosition(1, 1)->setFormula(u"aName"_ustr);
106 xSheet0->getCellByPosition(1, 2)->setFormula(u"otherName"_ustr);
107 xSheet0->getCellByPosition(1, 3)->setFormula(u"una"_ustr);
108 xSheet0->getCellByPosition(1, 4)->setFormula(u"otherName"_ustr);
109 xSheet0->getCellByPosition(1, 5)->setFormula(u"somethingelse"_ustr);
111 xSheet0->getCellByPosition(1, 5);
112 xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3);
114 uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW);
115 uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW);
116 uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(),
117 uno::UNO_SET_THROW);
119 xDPD->setSourceRange(aCellRangeAddress);
121 uno::Reference<beans::XPropertySet> xPropertySet0(xDPD->getDataPilotFields()->getByIndex(0),
122 uno::UNO_QUERY_THROW);
123 xPropertySet0->setPropertyValue(u"Orientation"_ustr,
124 uno::Any(sheet::DataPilotFieldOrientation_ROW));
126 uno::Reference<beans::XPropertySet> xPropertySet1(xDPD->getDataPilotFields()->getByIndex(1),
127 uno::UNO_QUERY_THROW);
128 xPropertySet1->setPropertyValue(u"Function"_ustr, uno::Any(sheet::GeneralFunction_SUM));
129 xPropertySet1->setPropertyValue(u"Orientation"_ustr,
130 uno::Any(sheet::DataPilotFieldOrientation_DATA));
132 uno::Reference<beans::XPropertySet> xPropertySet2(xDPD->getDataPilotFields()->getByIndex(2),
133 uno::UNO_QUERY_THROW);
134 xPropertySet2->setPropertyValue(u"Orientation"_ustr,
135 uno::Any(sheet::DataPilotFieldOrientation_COLUMN));
137 xDPT->insertNewByName(u"DataPilotTable"_ustr, aCellAddress, xDPD);
139 uno::Reference<container::XIndexAccess> xIA_DPT0(xDPTS->getDataPilotTables(),
140 uno::UNO_QUERY_THROW);
141 uno::Reference<sheet::XDataPilotDescriptor> xDPD0(xIA_DPT0->getByIndex(0),
142 uno::UNO_QUERY_THROW);
143 uno::Reference<container::XIndexAccess> xIA_RF0(xDPD0->getRowFields(), uno::UNO_SET_THROW);
145 uno::Reference<sheet::XDataPilotFieldGrouping> xDPFG(xIA_RF0->getByIndex(0),
146 uno::UNO_QUERY_THROW);
147 xDPFG->createNameGroup({ u"aName"_ustr, u"otherName"_ustr });
149 uno::Reference<container::XIndexAccess> xIA_DPT1(xDPTS->getDataPilotTables(),
150 uno::UNO_QUERY_THROW);
151 uno::Reference<sheet::XDataPilotDescriptor> xDPD1(xIA_DPT1->getByIndex(0),
152 uno::UNO_QUERY_THROW);
153 uno::Reference<container::XIndexAccess> xIA_RF1(xDPD1->getRowFields(), uno::UNO_SET_THROW);
155 sheet::DataPilotFieldGroupInfo aDPFGI;
156 for (auto i = 0; i < xIA_RF1->getCount(); ++i)
158 uno::Reference<beans::XPropertySet> xPropertySet(xIA_RF1->getByIndex(i),
159 uno::UNO_QUERY_THROW);
160 if (::comphelper::getBOOL(xPropertySet->getPropertyValue(u"IsGroupField"_ustr)))
162 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(u"GroupInfo"_ustr) >>= aDPFGI);
166 uno::Reference<container::XIndexAccess> xIA_GI(aDPFGI.Groups, uno::UNO_QUERY_THROW);
167 uno::Reference<container::XNameAccess> xNA_GN(xIA_GI->getByIndex(0), uno::UNO_QUERY_THROW);
169 uno::Reference<uno::XInterface> xReturn(xNA_GN->getByName(u"aName"_ustr), uno::UNO_QUERY_THROW);
170 return xReturn;
173 void ScDataPilotFieldGroupItemObj::setUp()
175 UnoApiTest::setUp();
176 // create a calc document
177 loadFromURL(u"private:factory/scalc"_ustr);
180 CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldGroupItemObj);
182 } // namespace sc_apitest
184 CPPUNIT_PLUGIN_IMPLEMENT();
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */