nss: upgrade to release 3.73
[LibreOffice.git] / sc / qa / extras / scdatapilotitemobj.cxx
blob217c28267c47174d5a1e2425ab7c1eaf85ba028e
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/xnamed.hxx>
12 #include <test/sheet/datapilotitem.hxx>
14 #include <com/sun/star/beans/XPropertySet.hpp>
15 #include <com/sun/star/container/XIndexAccess.hpp>
16 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
17 #include <com/sun/star/sheet/GeneralFunction.hpp>
18 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
19 #include <com/sun/star/sheet/XSpreadsheet.hpp>
20 #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
21 #include <com/sun/star/sheet/XDataPilotField.hpp>
22 #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
23 #include <com/sun/star/sheet/XDataPilotTables.hpp>
24 #include <com/sun/star/table/CellAddress.hpp>
25 #include <com/sun/star/table/CellRangeAddress.hpp>
26 #include <com/sun/star/uno/XInterface.hpp>
28 #include <com/sun/star/uno/Reference.hxx>
30 using namespace css;
32 namespace sc_apitest
34 class ScDataPilotItemObj : public CalcUnoApiTest,
35 public apitest::DataPilotItem,
36 public apitest::XNamed
38 public:
39 virtual void setUp() override;
40 virtual void tearDown() override;
41 virtual uno::Reference<uno::XInterface> init() override;
43 ScDataPilotItemObj();
45 CPPUNIT_TEST_SUITE(ScDataPilotItemObj);
47 // DataPilotItem
48 CPPUNIT_TEST(testProperties);
50 // XNamed
51 CPPUNIT_TEST(testGetName);
53 CPPUNIT_TEST_SUITE_END();
55 private:
56 static const int m_nMaxFieldIndex = 6;
57 uno::Reference<lang::XComponent> m_xComponent;
60 ScDataPilotItemObj::ScDataPilotItemObj()
61 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
62 , XNamed("2")
66 uno::Reference<uno::XInterface> ScDataPilotItemObj::init()
68 table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1);
69 table::CellAddress aCellAddress(0, 7, 8);
71 uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW);
72 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW);
74 xSheets->insertNewByName("Some Sheet", 0);
76 uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW);
77 uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
78 uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW);
80 for (auto i = 1; i < m_nMaxFieldIndex; i++)
82 xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i));
83 xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i));
84 xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i));
85 xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i));
88 for (auto i = 1; i < m_nMaxFieldIndex; i++)
89 for (auto j = 1; j < m_nMaxFieldIndex; j++)
91 xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1));
92 xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2));
95 xSheet0->getCellByPosition(1, 5);
96 xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3);
98 uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW);
99 uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW);
100 uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(),
101 uno::UNO_SET_THROW);
102 xDPD->setSourceRange(aCellRangeAddress);
104 uno::Reference<beans::XPropertySet> xDataPilotFieldProp(
105 xDPD->getDataPilotFields()->getByIndex(0), uno::UNO_QUERY_THROW);
106 xDataPilotFieldProp->setPropertyValue("Function", uno::makeAny(sheet::GeneralFunction_SUM));
107 xDataPilotFieldProp->setPropertyValue("Orientation",
108 uno::makeAny(sheet::DataPilotFieldOrientation_DATA));
110 if (xDPT->hasByName("DataPilotTable"))
111 xDPT->removeByName("DataPilotTable");
113 uno::Reference<container::XIndexAccess> xIA_DPF(xDPD->getDataPilotFields(), uno::UNO_SET_THROW);
115 xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD);
116 uno::Reference<sheet::XDataPilotField> xDPF(xIA_DPF->getByIndex(0), uno::UNO_QUERY_THROW);
117 uno::Reference<uno::XInterface> xReturn(xDPF->getItems()->getByIndex(0), uno::UNO_QUERY_THROW);
118 return xReturn;
121 void ScDataPilotItemObj::setUp()
123 CalcUnoApiTest::setUp();
124 // create calc document
125 m_xComponent = loadFromDesktop("private:factory/scalc");
128 void ScDataPilotItemObj::tearDown()
130 closeDocument(m_xComponent);
131 CalcUnoApiTest::tearDown();
134 CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotItemObj);
136 } // namespace sc_apitest
138 CPPUNIT_PLUGIN_IMPLEMENT();
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */