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/beans/xpropertyset.hxx>
12 #include <test/container/xnamed.hxx>
13 #include <test/document/xembeddedobjectsupplier.hxx>
14 #include <test/table/xtablechart.hxx>
15 #include <test/lang/xserviceinfo.hxx>
17 #include <com/sun/star/awt/Rectangle.hpp>
18 #include <com/sun/star/container/XIndexAccess.hpp>
19 #include <com/sun/star/container/XNameAccess.hpp>
20 #include <com/sun/star/lang/XComponent.hpp>
21 #include <com/sun/star/sheet/XCellRangeAddressable.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/CellRangeAddress.hpp>
26 #include <com/sun/star/table/XCell.hpp>
27 #include <com/sun/star/table/XCellRange.hpp>
28 #include <com/sun/star/table/XTableChart.hpp>
29 #include <com/sun/star/table/XTableCharts.hpp>
30 #include <com/sun/star/table/XTableChartsSupplier.hpp>
31 #include <com/sun/star/uno/XInterface.hpp>
33 #include <com/sun/star/uno/Reference.hxx>
34 #include <com/sun/star/uno/Sequence.hxx>
40 class ScChartObj
: public CalcUnoApiTest
,
41 public apitest::XEmbeddedObjectSupplier
,
42 public apitest::XNamed
,
43 public apitest::XPropertySet
,
44 public apitest::XServiceInfo
,
45 public apitest::XTableChart
50 virtual uno::Reference
<uno::XInterface
> init() override
;
51 virtual void setUp() override
;
52 virtual void tearDown() override
;
54 CPPUNIT_TEST_SUITE(ScChartObj
);
56 // XEmbeddedObjectSupplier
57 CPPUNIT_TEST(testGetEmbeddedObject
);
60 CPPUNIT_TEST(testGetName
);
61 CPPUNIT_TEST(testSetNameThrowsException
);
64 CPPUNIT_TEST(testGetPropertySetInfo
);
67 CPPUNIT_TEST(testGetImplementationName
);
68 CPPUNIT_TEST(testGetSupportedServiceNames
);
69 CPPUNIT_TEST(testSupportsService
);
72 CPPUNIT_TEST(testGetSetHasColumnHeaders
);
73 CPPUNIT_TEST(testGetSetHasRowHeaders
);
74 CPPUNIT_TEST(testGetSetRanges
);
76 CPPUNIT_TEST_SUITE_END();
79 uno::Reference
<lang::XComponent
> m_xComponent
;
82 ScChartObj::ScChartObj()
83 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
84 , XNamed("ScChartObj")
85 , XServiceInfo("ScChartObj", "com.sun.star.table.TableChart")
89 uno::Reference
<uno::XInterface
> ScChartObj::init()
91 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(m_xComponent
, uno::UNO_QUERY_THROW
);
92 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), uno::UNO_SET_THROW
);
93 uno::Reference
<container::XIndexAccess
> xIA(xSheets
, uno::UNO_QUERY_THROW
);
94 uno::Reference
<sheet::XSpreadsheet
> xSheet0(xIA
->getByIndex(0), uno::UNO_QUERY_THROW
);
96 xSheet0
->getCellByPosition(1, 0)->setFormula("JAN");
97 xSheet0
->getCellByPosition(2, 0)->setFormula("FEB");
98 xSheet0
->getCellByPosition(3, 0)->setFormula("MAR");
99 xSheet0
->getCellByPosition(4, 0)->setFormula("APR");
100 xSheet0
->getCellByPosition(5, 0)->setFormula("MAY");
101 xSheet0
->getCellByPosition(6, 0)->setFormula("JUN");
102 xSheet0
->getCellByPosition(7, 0)->setFormula("JUL");
103 xSheet0
->getCellByPosition(8, 0)->setFormula("AUG");
104 xSheet0
->getCellByPosition(9, 0)->setFormula("SEP");
105 xSheet0
->getCellByPosition(10, 0)->setFormula("OCT");
106 xSheet0
->getCellByPosition(11, 0)->setFormula("NOV");
107 xSheet0
->getCellByPosition(12, 0)->setFormula("DEC");
108 xSheet0
->getCellByPosition(13, 0)->setFormula("SUM");
110 xSheet0
->getCellByPosition(0, 1)->setFormula("Smith");
111 xSheet0
->getCellByPosition(1, 1)->setValue(42);
112 xSheet0
->getCellByPosition(2, 1)->setValue(58.9);
113 xSheet0
->getCellByPosition(3, 1)->setValue(-66.5);
114 xSheet0
->getCellByPosition(4, 1)->setValue(43.4);
115 xSheet0
->getCellByPosition(5, 1)->setValue(44.5);
116 xSheet0
->getCellByPosition(6, 1)->setValue(45.3);
117 xSheet0
->getCellByPosition(7, 1)->setValue(-67.3);
118 xSheet0
->getCellByPosition(8, 1)->setValue(30.5);
119 xSheet0
->getCellByPosition(9, 1)->setValue(23.2);
120 xSheet0
->getCellByPosition(10, 1)->setValue(-97.3);
121 xSheet0
->getCellByPosition(11, 1)->setValue(22.4);
122 xSheet0
->getCellByPosition(11, 1)->setValue(23.5);
123 xSheet0
->getCellByPosition(13, 1)->setFormula("SUM(B2:M2");
125 xSheet0
->getCellByPosition(0, 2)->setFormula("Jones");
126 xSheet0
->getCellByPosition(1, 2)->setValue(21);
127 xSheet0
->getCellByPosition(2, 2)->setValue(40.9);
128 xSheet0
->getCellByPosition(3, 2)->setValue(-57.5);
129 xSheet0
->getCellByPosition(4, 2)->setValue(-23.4);
130 xSheet0
->getCellByPosition(5, 2)->setValue(34.5);
131 xSheet0
->getCellByPosition(6, 2)->setValue(59.3);
132 xSheet0
->getCellByPosition(7, 2)->setValue(27.3);
133 xSheet0
->getCellByPosition(8, 2)->setValue(-38.5);
134 xSheet0
->getCellByPosition(9, 2)->setValue(43.2);
135 xSheet0
->getCellByPosition(10, 2)->setValue(57.3);
136 xSheet0
->getCellByPosition(11, 2)->setValue(25.4);
137 xSheet0
->getCellByPosition(11, 2)->setValue(28.5);
138 xSheet0
->getCellByPosition(13, 2)->setFormula("SUM(B3:M3");
140 xSheet0
->getCellByPosition(0, 3)->setFormula("Brown");
141 xSheet0
->getCellByPosition(1, 3)->setValue(31.45);
142 xSheet0
->getCellByPosition(2, 3)->setValue(-20.9);
143 xSheet0
->getCellByPosition(3, 3)->setValue(-117.5);
144 xSheet0
->getCellByPosition(4, 3)->setValue(23.4);
145 xSheet0
->getCellByPosition(5, 3)->setValue(-114.5);
146 xSheet0
->getCellByPosition(6, 3)->setValue(115.3);
147 xSheet0
->getCellByPosition(7, 3)->setValue(-171.3);
148 xSheet0
->getCellByPosition(8, 3)->setValue(89.5);
149 xSheet0
->getCellByPosition(9, 3)->setValue(41.2);
150 xSheet0
->getCellByPosition(10, 3)->setValue(71.3);
151 xSheet0
->getCellByPosition(11, 3)->setValue(25.4);
152 xSheet0
->getCellByPosition(11, 3)->setValue(38.5);
153 xSheet0
->getCellByPosition(13, 3)->setFormula("SUM(A4:L4");
155 uno::Reference
<table::XCellRange
> xCellRange0(xSheet0
, uno::UNO_QUERY_THROW
);
156 uno::Reference
<table::XCellRange
> xCellRange1(xCellRange0
->getCellRangeByName("A1:N4"),
158 uno::Reference
<sheet::XCellRangeAddressable
> xCRA(xCellRange1
, uno::UNO_QUERY_THROW
);
160 uno::Sequence
<table::CellRangeAddress
> aCRA(1);
161 aCRA
[0] = xCRA
->getRangeAddress();
163 uno::Reference
<table::XTableChartsSupplier
> xTCS(xSheet0
, uno::UNO_QUERY_THROW
);
164 uno::Reference
<table::XTableCharts
> xTC
= xTCS
->getCharts();
165 xTC
->addNewByName("ScChartObj", awt::Rectangle(500, 3000, 25000, 11000), aCRA
, true, true);
167 uno::Reference
<container::XNameAccess
> xNA(xTC
, uno::UNO_QUERY_THROW
);
168 uno::Reference
<table::XTableChart
> xChart(xNA
->getByName("ScChartObj"), uno::UNO_QUERY_THROW
);
172 void ScChartObj::setUp()
174 CalcUnoApiTest::setUp();
175 // create a calc document
176 m_xComponent
= loadFromDesktop("private:factory/scalc");
179 void ScChartObj::tearDown()
181 closeDocument(m_xComponent
);
182 CalcUnoApiTest::tearDown();
185 CPPUNIT_TEST_SUITE_REGISTRATION(ScChartObj
);
187 } // namespace sc_apitest
189 CPPUNIT_PLUGIN_IMPLEMENT();
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */