calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / sc / qa / extras / scindexenumeration_datapilotitemsenumeration.cxx
blob628b916a7081582d81bfeaf132f02365ba2d3613
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/xenumeration.hxx>
13 #include <com/sun/star/beans/XPropertySet.hpp>
14 #include <com/sun/star/container/XIndexAccess.hpp>
15 #include <com/sun/star/lang/XComponent.hpp>
16 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
17 #include <com/sun/star/sheet/GeneralFunction.hpp>
18 #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
19 #include <com/sun/star/sheet/XDataPilotField.hpp>
20 #include <com/sun/star/sheet/XDataPilotTables.hpp>
21 #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
22 #include <com/sun/star/sheet/XSpreadsheet.hpp>
23 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
24 #include <com/sun/star/sheet/XSpreadsheets.hpp>
25 #include <com/sun/star/table/CellAddress.hpp>
26 #include <com/sun/star/table/CellRangeAddress.hpp>
27 #include <com/sun/star/uno/XInterface.hpp>
29 #include <com/sun/star/uno/Reference.hxx>
31 using namespace css;
32 using namespace css::uno;
33 using namespace com::sun::star;
35 namespace sc_apitest
37 class ScIndexEnumeration_DataPilotItemsEnumeration : public UnoApiTest, public apitest::XEnumeration
39 public:
40 ScIndexEnumeration_DataPilotItemsEnumeration();
42 virtual uno::Reference<uno::XInterface> init() override;
43 virtual void setUp() override;
45 CPPUNIT_TEST_SUITE(ScIndexEnumeration_DataPilotItemsEnumeration);
47 // XEnumeration
48 CPPUNIT_TEST(testHasMoreElements);
49 CPPUNIT_TEST(testNextElement);
51 CPPUNIT_TEST_SUITE_END();
53 private:
54 static const int m_nMaxFieldIndex = 6;
57 ScIndexEnumeration_DataPilotItemsEnumeration::ScIndexEnumeration_DataPilotItemsEnumeration()
58 : UnoApiTest("/sc/qa/extras/testdocuments")
62 uno::Reference<uno::XInterface> ScIndexEnumeration_DataPilotItemsEnumeration::init()
64 table::CellRangeAddress aCellRangeAddress(0, 1, 0, m_nMaxFieldIndex - 1, m_nMaxFieldIndex - 1);
65 table::CellAddress aCellAddress(0, 7, 8);
67 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
68 CPPUNIT_ASSERT_MESSAGE("no document", xDoc.is());
69 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW);
71 uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW);
72 xSheets->insertNewByName("Some Sheet", 0);
74 uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
75 uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(1), uno::UNO_QUERY_THROW);
77 for (auto i = 1; i < m_nMaxFieldIndex; ++i)
79 xSheet0->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i));
80 xSheet0->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i));
81 xSheet1->getCellByPosition(i, 0)->setFormula("Col" + OUString::number(i));
82 xSheet1->getCellByPosition(0, i)->setFormula("Row" + OUString::number(i));
85 for (auto i = 1; i < m_nMaxFieldIndex; ++i)
87 for (auto j = 1; j < m_nMaxFieldIndex; ++j)
89 xSheet0->getCellByPosition(i, j)->setValue(i * (j + 1));
90 xSheet1->getCellByPosition(i, j)->setValue(i * (j + 2));
94 xSheet0->getCellByPosition(1, 5);
95 xSheet0->getCellByPosition(aCellAddress.Column, aCellAddress.Row + 3);
97 uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(xSheet0, uno::UNO_QUERY_THROW);
98 uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), uno::UNO_SET_THROW);
99 uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(),
100 uno::UNO_SET_THROW);
102 xDPD->setSourceRange(aCellRangeAddress);
104 uno::Any aValue;
105 uno::Reference<beans::XPropertySet> xPropertySet(xDPD->getDataPilotFields()->getByIndex(0),
106 uno::UNO_QUERY_THROW);
107 aValue <<= sheet::DataPilotFieldOrientation_DATA;
108 xPropertySet->setPropertyValue("Orientation", aValue);
109 aValue <<= sheet::GeneralFunction_SUM;
110 xPropertySet->setPropertyValue("Function", aValue);
112 xDPT->insertNewByName("DataPilotTable", aCellAddress, xDPD);
114 uno::Reference<sheet::XDataPilotField> xDPF(xDPD->getDataPilotFields()->getByIndex(0),
115 uno::UNO_QUERY_THROW);
116 uno::Reference<container::XEnumerationAccess> xEA(xDPF->getItems(), uno::UNO_QUERY_THROW);
117 return xEA->createEnumeration();
120 void ScIndexEnumeration_DataPilotItemsEnumeration::setUp()
122 UnoApiTest::setUp();
123 // create a calc document
124 mxComponent = loadFromDesktop("private:factory/scalc");
127 CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_DataPilotItemsEnumeration);
128 } // namespace sc_apitest
130 CPPUNIT_PLUGIN_IMPLEMENT();
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */