Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / qa / extras / scindexenumeration_tablechartsenumeration.cxx
blob725aa2f982834d4c42cbd6b5a9fe3ce300836764
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/xenumeration.hxx>
13 #include <com/sun/star/awt/Rectangle.hpp>
14 #include <com/sun/star/container/XEnumerationAccess.hpp>
15 #include <com/sun/star/container/XIndexAccess.hpp>
16 #include <com/sun/star/lang/XComponent.hpp>
17 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
18 #include <com/sun/star/sheet/XSpreadsheet.hpp>
19 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
20 #include <com/sun/star/sheet/XSpreadsheets.hpp>
21 #include <com/sun/star/table/XCellRange.hpp>
22 #include <com/sun/star/table/XTableCharts.hpp>
23 #include <com/sun/star/table/XTableChartsSupplier.hpp>
24 #include <com/sun/star/uno/XInterface.hpp>
26 #include <com/sun/star/uno/Sequence.hxx>
27 #include <com/sun/star/uno/Reference.hxx>
29 using namespace css;
30 using namespace css::uno;
32 namespace sc_apitest
34 class ScIndexEnumeration_TableChartsEnumeration : public UnoApiTest, public apitest::XEnumeration
36 public:
37 ScIndexEnumeration_TableChartsEnumeration();
39 virtual uno::Reference<uno::XInterface> init() override;
40 virtual void setUp() override;
42 CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableChartsEnumeration);
44 // XEnumeration
45 CPPUNIT_TEST(testHasMoreElements);
46 CPPUNIT_TEST(testNextElement);
48 CPPUNIT_TEST_SUITE_END();
51 ScIndexEnumeration_TableChartsEnumeration::ScIndexEnumeration_TableChartsEnumeration()
52 : UnoApiTest("/sc/qa/extras/testdocuments")
56 uno::Reference<uno::XInterface> ScIndexEnumeration_TableChartsEnumeration::init()
58 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
59 CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is());
61 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW);
62 uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW);
63 uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
65 xSheet0->getCellByPosition(1, 0)->setFormula("JAN");
66 xSheet0->getCellByPosition(2, 0)->setFormula("FEB");
67 xSheet0->getCellByPosition(3, 0)->setFormula("MAR");
68 xSheet0->getCellByPosition(4, 0)->setFormula("APR");
69 xSheet0->getCellByPosition(5, 0)->setFormula("MAY");
70 xSheet0->getCellByPosition(6, 0)->setFormula("JUN");
71 xSheet0->getCellByPosition(7, 0)->setFormula("JUL");
72 xSheet0->getCellByPosition(8, 0)->setFormula("AUG");
73 xSheet0->getCellByPosition(9, 0)->setFormula("SEP");
74 xSheet0->getCellByPosition(10, 0)->setFormula("OCT");
75 xSheet0->getCellByPosition(11, 0)->setFormula("NOV");
76 xSheet0->getCellByPosition(12, 0)->setFormula("DEC");
77 xSheet0->getCellByPosition(13, 0)->setFormula("SUM");
79 xSheet0->getCellByPosition(0, 1)->setFormula("Smith");
80 xSheet0->getCellByPosition(1, 1)->setValue(42);
81 xSheet0->getCellByPosition(2, 1)->setValue(58.9);
82 xSheet0->getCellByPosition(3, 1)->setValue(-66.5);
83 xSheet0->getCellByPosition(4, 1)->setValue(43.4);
84 xSheet0->getCellByPosition(5, 1)->setValue(44.5);
85 xSheet0->getCellByPosition(6, 1)->setValue(45.3);
86 xSheet0->getCellByPosition(7, 1)->setValue(-67.3);
87 xSheet0->getCellByPosition(8, 1)->setValue(30.5);
88 xSheet0->getCellByPosition(9, 1)->setValue(23.2);
89 xSheet0->getCellByPosition(10, 1)->setValue(-97.3);
90 xSheet0->getCellByPosition(11, 1)->setValue(22.4);
91 xSheet0->getCellByPosition(11, 1)->setValue(23.5);
92 xSheet0->getCellByPosition(13, 1)->setFormula("SUM(B2:M2");
94 xSheet0->getCellByPosition(0, 2)->setFormula("Jones");
95 xSheet0->getCellByPosition(1, 2)->setValue(21);
96 xSheet0->getCellByPosition(2, 2)->setValue(40.9);
97 xSheet0->getCellByPosition(3, 2)->setValue(-57.5);
98 xSheet0->getCellByPosition(4, 2)->setValue(-23.4);
99 xSheet0->getCellByPosition(5, 2)->setValue(34.5);
100 xSheet0->getCellByPosition(6, 2)->setValue(59.3);
101 xSheet0->getCellByPosition(7, 2)->setValue(27.3);
102 xSheet0->getCellByPosition(8, 2)->setValue(-38.5);
103 xSheet0->getCellByPosition(9, 2)->setValue(43.2);
104 xSheet0->getCellByPosition(10, 2)->setValue(57.3);
105 xSheet0->getCellByPosition(11, 2)->setValue(25.4);
106 xSheet0->getCellByPosition(11, 2)->setValue(28.5);
107 xSheet0->getCellByPosition(13, 2)->setFormula("SUM(B3:M3");
109 xSheet0->getCellByPosition(0, 3)->setFormula("Brown");
110 xSheet0->getCellByPosition(1, 3)->setValue(31.45);
111 xSheet0->getCellByPosition(2, 3)->setValue(-20.9);
112 xSheet0->getCellByPosition(3, 3)->setValue(-117.5);
113 xSheet0->getCellByPosition(4, 3)->setValue(23.4);
114 xSheet0->getCellByPosition(5, 3)->setValue(-114.5);
115 xSheet0->getCellByPosition(6, 3)->setValue(115.3);
116 xSheet0->getCellByPosition(7, 3)->setValue(-171.3);
117 xSheet0->getCellByPosition(8, 3)->setValue(89.5);
118 xSheet0->getCellByPosition(9, 3)->setValue(41.2);
119 xSheet0->getCellByPosition(10, 3)->setValue(71.3);
120 xSheet0->getCellByPosition(11, 3)->setValue(25.4);
121 xSheet0->getCellByPosition(11, 3)->setValue(38.5);
122 xSheet0->getCellByPosition(13, 3)->setFormula("SUM(A4:L4");
124 uno::Reference<table::XCellRange> xCellRange0(xSheet0, uno::UNO_QUERY_THROW);
125 uno::Reference<table::XCellRange> xCellRange1(xCellRange0->getCellRangeByName("A1:N4"),
126 uno::UNO_SET_THROW);
127 uno::Reference<sheet::XCellRangeAddressable> xCRA(xCellRange1, uno::UNO_QUERY_THROW);
129 uno::Reference<table::XTableChartsSupplier> xTCS(xSheet0, uno::UNO_QUERY_THROW);
130 uno::Reference<table::XTableCharts> xTC = xTCS->getCharts();
131 xTC->addNewByName("ScChartObj", awt::Rectangle(500, 3000, 25000, 11000),
132 { xCRA->getRangeAddress() }, true, false);
134 uno::Reference<container::XEnumerationAccess> xEA(xTC, uno::UNO_QUERY_THROW);
136 return xEA->createEnumeration();
139 void ScIndexEnumeration_TableChartsEnumeration::setUp()
141 UnoApiTest::setUp();
142 mxComponent = loadFromDesktop("private:factory/scalc");
145 CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_TableChartsEnumeration);
147 } // namespace sc_apitest
149 CPPUNIT_PLUGIN_IMPLEMENT();
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */