tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / sc / qa / extras / scdatapilotfieldgroupobj.cxx
blobe80da20f14a364eee7996f5a95e730e46f44e55b
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/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/sheet/DataPilotFieldGroupInfo.hpp>
23 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
24 #include <com/sun/star/sheet/GeneralFunction.hpp>
25 #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
26 #include <com/sun/star/sheet/XDataPilotFieldGrouping.hpp>
27 #include <com/sun/star/sheet/XDataPilotTables.hpp>
28 #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
29 #include <com/sun/star/sheet/XSpreadsheet.hpp>
30 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
31 #include <com/sun/star/sheet/XSpreadsheets.hpp>
32 #include <com/sun/star/table/CellAddress.hpp>
33 #include <com/sun/star/table/CellRangeAddress.hpp>
34 #include <com/sun/star/uno/XInterface.hpp>
36 #include <com/sun/star/uno/Reference.hxx>
37 #include <com/sun/star/uno/Sequence.hxx>
39 using namespace css;
41 namespace sc_apitest
43 class ScDataPilotFieldGroupObj : public UnoApiTest,
44 public apitest::XElementAccess,
45 public apitest::XEnumerationAccess,
46 public apitest::XIndexAccess,
47 public apitest::XNameAccess,
48 public apitest::XNamed,
49 public apitest::XServiceInfo
51 public:
52 ScDataPilotFieldGroupObj();
54 virtual uno::Reference<uno::XInterface> init() override;
55 virtual void setUp() override;
57 CPPUNIT_TEST_SUITE(ScDataPilotFieldGroupObj);
59 // XElementAccess
60 CPPUNIT_TEST(testGetElementType);
61 CPPUNIT_TEST(testHasElements);
63 // XEnumerationAccess
64 CPPUNIT_TEST(testCreateEnumeration);
66 // XIndexAccess
67 CPPUNIT_TEST(testGetByIndex);
68 CPPUNIT_TEST(testGetCount);
70 // XNameAccess
71 CPPUNIT_TEST(testGetByName);
72 CPPUNIT_TEST(testGetElementNames);
73 CPPUNIT_TEST(testHasByName);
75 // XNamed
76 CPPUNIT_TEST(testGetName);
77 CPPUNIT_TEST(testSetName);
79 // XServiceInfo
80 CPPUNIT_TEST(testGetImplementationName);
81 CPPUNIT_TEST(testGetSupportedServiceNames);
82 CPPUNIT_TEST(testSupportsService);
84 CPPUNIT_TEST_SUITE_END();
86 private:
87 static const int m_nMaxFieldIndex = 6;
90 ScDataPilotFieldGroupObj::ScDataPilotFieldGroupObj()
91 : UnoApiTest(u"/sc/qa/extras/testdocuments"_ustr)
92 , XElementAccess(cppu::UnoType<container::XNamed>::get())
93 , XIndexAccess(2)
94 , XNameAccess(u"aName"_ustr)
95 , XNamed(u"Group1"_ustr)
96 , XServiceInfo(u"ScDataPilotFieldGroupObj"_ustr, u"com.sun.star.sheet.DataPilotFieldGroup"_ustr)
100 uno::Reference<uno::XInterface> ScDataPilotFieldGroupObj::init()
102 table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1);
103 table::CellAddress aCellAddress(0, 7, 8);
105 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
106 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW);
107 uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW);
108 xSheets->insertNewByName(u"Some Sheet"_ustr, 0);
110 uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
111 uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW);
113 for (auto i = 1; i < m_nMaxFieldIndex; ++i)
115 xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i));
116 xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i));
117 xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i));
118 xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i));
121 for (auto i = 1; i < m_nMaxFieldIndex; ++i)
123 for (auto j = 1; j < m_nMaxFieldIndex; ++j)
125 xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1));
126 xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2));
130 xSheet0->getCellByPosition(1, 1)->setFormula(u"aName"_ustr);
131 xSheet0->getCellByPosition(1, 2)->setFormula(u"otherName"_ustr);
132 xSheet0->getCellByPosition(1, 3)->setFormula(u"una"_ustr);
133 xSheet0->getCellByPosition(1, 4)->setFormula(u"otherName"_ustr);
134 xSheet0->getCellByPosition(1, 5)->setFormula(u"somethingelse"_ustr);
136 xSheet0->getCellByPosition(1, 5);
137 xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3);
139 uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW);
140 uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW);
141 uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(),
142 uno::UNO_SET_THROW);
144 xDPD->setSourceRange(aCellRangeAddress);
146 uno::Reference<beans::XPropertySet> xPropertySet0(xDPD->getDataPilotFields()->getByIndex(0),
147 uno::UNO_QUERY_THROW);
148 xPropertySet0->setPropertyValue(u"Orientation"_ustr,
149 uno::Any(sheet::DataPilotFieldOrientation_ROW));
151 uno::Reference<beans::XPropertySet> xPropertySet1(xDPD->getDataPilotFields()->getByIndex(1),
152 uno::UNO_QUERY_THROW);
153 xPropertySet1->setPropertyValue(u"Function"_ustr, uno::Any(sheet::GeneralFunction_SUM));
154 xPropertySet1->setPropertyValue(u"Orientation"_ustr,
155 uno::Any(sheet::DataPilotFieldOrientation_DATA));
157 uno::Reference<beans::XPropertySet> xPropertySet2(xDPD->getDataPilotFields()->getByIndex(2),
158 uno::UNO_QUERY_THROW);
159 xPropertySet2->setPropertyValue(u"Orientation"_ustr,
160 uno::Any(sheet::DataPilotFieldOrientation_COLUMN));
162 xDPT->insertNewByName(u"DataPilotTable"_ustr, aCellAddress, xDPD);
164 uno::Reference<container::XIndexAccess> xIA_DPT0(xDPTS->getDataPilotTables(),
165 uno::UNO_QUERY_THROW);
166 uno::Reference<sheet::XDataPilotDescriptor> xDPD0(xIA_DPT0->getByIndex(0),
167 uno::UNO_QUERY_THROW);
168 uno::Reference<container::XIndexAccess> xIA_RF0(xDPD0->getRowFields(), uno::UNO_SET_THROW);
170 uno::Reference<sheet::XDataPilotFieldGrouping> xDPFG(xIA_RF0->getByIndex(0),
171 uno::UNO_QUERY_THROW);
172 xDPFG->createNameGroup({ u"aName"_ustr, u"otherName"_ustr });
174 uno::Reference<container::XIndexAccess> xIA_DPT1(xDPTS->getDataPilotTables(),
175 uno::UNO_QUERY_THROW);
176 uno::Reference<sheet::XDataPilotDescriptor> xDPD1(xIA_DPT1->getByIndex(0),
177 uno::UNO_QUERY_THROW);
178 uno::Reference<container::XIndexAccess> xIA_RF1(xDPD1->getRowFields(), uno::UNO_SET_THROW);
180 sheet::DataPilotFieldGroupInfo aDPFGI;
181 for (auto i = 0; i < xIA_RF1->getCount(); ++i)
183 uno::Reference<beans::XPropertySet> xPropertySet(xIA_RF1->getByIndex(i),
184 uno::UNO_QUERY_THROW);
185 if (::comphelper::getBOOL(xPropertySet->getPropertyValue(u"IsGroupField"_ustr)))
187 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(u"GroupInfo"_ustr) >>= aDPFGI);
191 uno::Reference<container::XIndexAccess> xIA_GI(aDPFGI.Groups, uno::UNO_QUERY_THROW);
192 uno::Reference<container::XNameAccess> xNA_GN(xIA_GI->getByIndex(0), uno::UNO_QUERY_THROW);
194 return xNA_GN;
197 void ScDataPilotFieldGroupObj::setUp()
199 UnoApiTest::setUp();
200 // create calc document
201 loadFromURL(u"private:factory/scalc"_ustr);
204 CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldGroupObj);
206 } // namespace sc_apitest
208 CPPUNIT_PLUGIN_IMPLEMENT();
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */