1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <test/calc_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/lang/xserviceinfo.hxx>
16 #include <test/table/xtablecharts.hxx>
17 #include <cppu/unotype.hxx>
19 #include <com/sun/star/awt/Rectangle.hpp>
20 #include <com/sun/star/container/XIndexAccess.hpp>
21 #include <com/sun/star/lang/XComponent.hpp>
22 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
23 #include <com/sun/star/sheet/XSpreadsheet.hpp>
24 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
25 #include <com/sun/star/sheet/XSpreadsheets.hpp>
26 #include <com/sun/star/table/CellRangeAddress.hpp>
27 #include <com/sun/star/table/XCell.hpp>
28 #include <com/sun/star/table/XCellRange.hpp>
29 #include <com/sun/star/table/XTableChart.hpp>
30 #include <com/sun/star/table/XTableCharts.hpp>
31 #include <com/sun/star/table/XTableChartsSupplier.hpp>
32 #include <com/sun/star/uno/XInterface.hpp>
34 #include <com/sun/star/uno/Reference.hxx>
35 #include <com/sun/star/uno/Sequence.hxx>
41 class ScChartsObj
: public CalcUnoApiTest
,
42 public apitest::XEnumerationAccess
,
43 public apitest::XElementAccess
,
44 public apitest::XIndexAccess
,
45 public apitest::XNameAccess
,
46 public apitest::XServiceInfo
,
47 public apitest::XTableCharts
52 virtual uno::Reference
<uno::XInterface
> init() override
;
53 virtual void setUp() override
;
54 virtual void tearDown() override
;
56 CPPUNIT_TEST_SUITE(ScChartsObj
);
59 CPPUNIT_TEST(testCreateEnumeration
);
62 CPPUNIT_TEST(testGetElementType
);
63 CPPUNIT_TEST(testHasElements
);
66 CPPUNIT_TEST(testGetByIndex
);
67 CPPUNIT_TEST(testGetCount
);
70 CPPUNIT_TEST(testGetByName
);
71 CPPUNIT_TEST(testGetElementNames
);
72 CPPUNIT_TEST(testHasByName
);
75 CPPUNIT_TEST(testGetImplementationName
);
76 CPPUNIT_TEST(testGetSupportedServiceNames
);
77 CPPUNIT_TEST(testSupportsService
);
80 CPPUNIT_TEST(testAddNewRemoveByName
);
82 CPPUNIT_TEST_SUITE_END();
85 uno::Reference
<lang::XComponent
> m_xComponent
;
88 ScChartsObj::ScChartsObj()
89 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
90 , XElementAccess(cppu::UnoType
<table::XTableChart
>::get())
92 , XNameAccess("ScChartsObj")
93 , XServiceInfo("ScChartsObj", "com.sun.star.table.TableCharts")
97 uno::Reference
<uno::XInterface
> ScChartsObj::init()
99 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(m_xComponent
, uno::UNO_QUERY_THROW
);
100 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), uno::UNO_SET_THROW
);
101 uno::Reference
<container::XIndexAccess
> xIA(xSheets
, uno::UNO_QUERY_THROW
);
102 uno::Reference
<sheet::XSpreadsheet
> xSheet0(xIA
->getByIndex(0), uno::UNO_QUERY_THROW
);
104 xSheet0
->getCellByPosition(1, 0)->setFormula("JAN");
105 xSheet0
->getCellByPosition(2, 0)->setFormula("FEB");
106 xSheet0
->getCellByPosition(3, 0)->setFormula("MAR");
107 xSheet0
->getCellByPosition(4, 0)->setFormula("APR");
108 xSheet0
->getCellByPosition(5, 0)->setFormula("MAY");
109 xSheet0
->getCellByPosition(6, 0)->setFormula("JUN");
110 xSheet0
->getCellByPosition(7, 0)->setFormula("JUL");
111 xSheet0
->getCellByPosition(8, 0)->setFormula("AUG");
112 xSheet0
->getCellByPosition(9, 0)->setFormula("SEP");
113 xSheet0
->getCellByPosition(10, 0)->setFormula("OCT");
114 xSheet0
->getCellByPosition(11, 0)->setFormula("NOV");
115 xSheet0
->getCellByPosition(12, 0)->setFormula("DEC");
116 xSheet0
->getCellByPosition(13, 0)->setFormula("SUM");
118 xSheet0
->getCellByPosition(0, 1)->setFormula("Smith");
119 xSheet0
->getCellByPosition(1, 1)->setValue(42);
120 xSheet0
->getCellByPosition(2, 1)->setValue(58.9);
121 xSheet0
->getCellByPosition(3, 1)->setValue(-66.5);
122 xSheet0
->getCellByPosition(4, 1)->setValue(43.4);
123 xSheet0
->getCellByPosition(5, 1)->setValue(44.5);
124 xSheet0
->getCellByPosition(6, 1)->setValue(45.3);
125 xSheet0
->getCellByPosition(7, 1)->setValue(-67.3);
126 xSheet0
->getCellByPosition(8, 1)->setValue(30.5);
127 xSheet0
->getCellByPosition(9, 1)->setValue(23.2);
128 xSheet0
->getCellByPosition(10, 1)->setValue(-97.3);
129 xSheet0
->getCellByPosition(11, 1)->setValue(22.4);
130 xSheet0
->getCellByPosition(11, 1)->setValue(23.5);
131 xSheet0
->getCellByPosition(13, 1)->setFormula("SUM(B2:M2");
133 xSheet0
->getCellByPosition(0, 2)->setFormula("Jones");
134 xSheet0
->getCellByPosition(1, 2)->setValue(21);
135 xSheet0
->getCellByPosition(2, 2)->setValue(40.9);
136 xSheet0
->getCellByPosition(3, 2)->setValue(-57.5);
137 xSheet0
->getCellByPosition(4, 2)->setValue(-23.4);
138 xSheet0
->getCellByPosition(5, 2)->setValue(34.5);
139 xSheet0
->getCellByPosition(6, 2)->setValue(59.3);
140 xSheet0
->getCellByPosition(7, 2)->setValue(27.3);
141 xSheet0
->getCellByPosition(8, 2)->setValue(-38.5);
142 xSheet0
->getCellByPosition(9, 2)->setValue(43.2);
143 xSheet0
->getCellByPosition(10, 2)->setValue(57.3);
144 xSheet0
->getCellByPosition(11, 2)->setValue(25.4);
145 xSheet0
->getCellByPosition(11, 2)->setValue(28.5);
146 xSheet0
->getCellByPosition(13, 2)->setFormula("SUM(B3:M3");
148 xSheet0
->getCellByPosition(0, 3)->setFormula("Brown");
149 xSheet0
->getCellByPosition(1, 3)->setValue(31.45);
150 xSheet0
->getCellByPosition(2, 3)->setValue(-20.9);
151 xSheet0
->getCellByPosition(3, 3)->setValue(-117.5);
152 xSheet0
->getCellByPosition(4, 3)->setValue(23.4);
153 xSheet0
->getCellByPosition(5, 3)->setValue(-114.5);
154 xSheet0
->getCellByPosition(6, 3)->setValue(115.3);
155 xSheet0
->getCellByPosition(7, 3)->setValue(-171.3);
156 xSheet0
->getCellByPosition(8, 3)->setValue(89.5);
157 xSheet0
->getCellByPosition(9, 3)->setValue(41.2);
158 xSheet0
->getCellByPosition(10, 3)->setValue(71.3);
159 xSheet0
->getCellByPosition(11, 3)->setValue(25.4);
160 xSheet0
->getCellByPosition(11, 3)->setValue(38.5);
161 xSheet0
->getCellByPosition(13, 3)->setFormula("SUM(A4:L4");
163 uno::Reference
<table::XCellRange
> xCellRange0(xSheet0
, uno::UNO_QUERY_THROW
);
164 uno::Reference
<table::XCellRange
> xCellRange1(xCellRange0
->getCellRangeByName("A1:N4"),
166 uno::Reference
<sheet::XCellRangeAddressable
> xCRA(xCellRange1
, uno::UNO_QUERY_THROW
);
168 uno::Sequence
<table::CellRangeAddress
> aCRA(1);
169 aCRA
[0] = xCRA
->getRangeAddress();
171 uno::Reference
<table::XTableChartsSupplier
> xTCS(xSheet0
, uno::UNO_QUERY_THROW
);
172 uno::Reference
<table::XTableCharts
> xTC
= xTCS
->getCharts();
173 xTC
->addNewByName("ScChartsObj", awt::Rectangle(500, 3000, 25000, 11000), aCRA
, true, true);
178 void ScChartsObj::setUp()
180 CalcUnoApiTest::setUp();
181 // create calc document
182 m_xComponent
= loadFromDesktop("private:factory/scalc");
185 void ScChartsObj::tearDown()
187 closeDocument(m_xComponent
);
188 CalcUnoApiTest::tearDown();
191 CPPUNIT_TEST_SUITE_REGISTRATION(ScChartsObj
);
193 } // namespace sc_apitest
195 CPPUNIT_PLUGIN_IMPLEMENT();
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */