tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / sc / qa / extras / scchartsobj.cxx
blob378fd325c19abe120877f28839331c4211709535
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/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/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/XCell.hpp>
26 #include <com/sun/star/table/XCellRange.hpp>
27 #include <com/sun/star/table/XTableChart.hpp>
28 #include <com/sun/star/table/XTableCharts.hpp>
29 #include <com/sun/star/table/XTableChartsSupplier.hpp>
30 #include <com/sun/star/uno/XInterface.hpp>
32 #include <com/sun/star/uno/Reference.hxx>
33 #include <com/sun/star/uno/Sequence.hxx>
35 using namespace css;
37 namespace sc_apitest
39 class ScChartsObj : public UnoApiTest,
40 public apitest::XEnumerationAccess,
41 public apitest::XElementAccess,
42 public apitest::XIndexAccess,
43 public apitest::XNameAccess,
44 public apitest::XServiceInfo,
45 public apitest::XTableCharts
47 public:
48 ScChartsObj();
50 virtual uno::Reference<uno::XInterface> init() override;
51 virtual void setUp() override;
53 CPPUNIT_TEST_SUITE(ScChartsObj);
55 // XEnumerationAccess
56 CPPUNIT_TEST(testCreateEnumeration);
58 // XElementAccess
59 CPPUNIT_TEST(testGetElementType);
60 CPPUNIT_TEST(testHasElements);
62 // XIndexAccess
63 CPPUNIT_TEST(testGetByIndex);
64 CPPUNIT_TEST(testGetCount);
66 // XNameAccess
67 CPPUNIT_TEST(testGetByName);
68 CPPUNIT_TEST(testGetElementNames);
69 CPPUNIT_TEST(testHasByName);
71 // XServiceInfo
72 CPPUNIT_TEST(testGetImplementationName);
73 CPPUNIT_TEST(testGetSupportedServiceNames);
74 CPPUNIT_TEST(testSupportsService);
76 // XTableCharts
77 CPPUNIT_TEST(testAddNewRemoveByName);
79 CPPUNIT_TEST_SUITE_END();
82 ScChartsObj::ScChartsObj()
83 : UnoApiTest(u"/sc/qa/extras/testdocuments"_ustr)
84 , XElementAccess(cppu::UnoType<table::XTableChart>::get())
85 , XIndexAccess(1)
86 , XNameAccess(u"ScChartsObj"_ustr)
87 , XServiceInfo(u"ScChartsObj"_ustr, u"com.sun.star.table.TableCharts"_ustr)
91 uno::Reference<uno::XInterface> ScChartsObj::init()
93 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
94 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW);
95 uno::Reference<container::XIndexAccess> xIA(xSheets, uno::UNO_QUERY_THROW);
96 uno::Reference<sheet::XSpreadsheet> xSheet0(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
98 xSheet0->getCellByPosition(1, 0)->setFormula(u"JAN"_ustr);
99 xSheet0->getCellByPosition(2, 0)->setFormula(u"FEB"_ustr);
100 xSheet0->getCellByPosition(3, 0)->setFormula(u"MAR"_ustr);
101 xSheet0->getCellByPosition(4, 0)->setFormula(u"APR"_ustr);
102 xSheet0->getCellByPosition(5, 0)->setFormula(u"MAY"_ustr);
103 xSheet0->getCellByPosition(6, 0)->setFormula(u"JUN"_ustr);
104 xSheet0->getCellByPosition(7, 0)->setFormula(u"JUL"_ustr);
105 xSheet0->getCellByPosition(8, 0)->setFormula(u"AUG"_ustr);
106 xSheet0->getCellByPosition(9, 0)->setFormula(u"SEP"_ustr);
107 xSheet0->getCellByPosition(10, 0)->setFormula(u"OCT"_ustr);
108 xSheet0->getCellByPosition(11, 0)->setFormula(u"NOV"_ustr);
109 xSheet0->getCellByPosition(12, 0)->setFormula(u"DEC"_ustr);
110 xSheet0->getCellByPosition(13, 0)->setFormula(u"SUM"_ustr);
112 xSheet0->getCellByPosition(0, 1)->setFormula(u"Smith"_ustr);
113 xSheet0->getCellByPosition(1, 1)->setValue(42);
114 xSheet0->getCellByPosition(2, 1)->setValue(58.9);
115 xSheet0->getCellByPosition(3, 1)->setValue(-66.5);
116 xSheet0->getCellByPosition(4, 1)->setValue(43.4);
117 xSheet0->getCellByPosition(5, 1)->setValue(44.5);
118 xSheet0->getCellByPosition(6, 1)->setValue(45.3);
119 xSheet0->getCellByPosition(7, 1)->setValue(-67.3);
120 xSheet0->getCellByPosition(8, 1)->setValue(30.5);
121 xSheet0->getCellByPosition(9, 1)->setValue(23.2);
122 xSheet0->getCellByPosition(10, 1)->setValue(-97.3);
123 xSheet0->getCellByPosition(11, 1)->setValue(22.4);
124 xSheet0->getCellByPosition(11, 1)->setValue(23.5);
125 xSheet0->getCellByPosition(13, 1)->setFormula(u"SUM(B2:M2"_ustr);
127 xSheet0->getCellByPosition(0, 2)->setFormula(u"Jones"_ustr);
128 xSheet0->getCellByPosition(1, 2)->setValue(21);
129 xSheet0->getCellByPosition(2, 2)->setValue(40.9);
130 xSheet0->getCellByPosition(3, 2)->setValue(-57.5);
131 xSheet0->getCellByPosition(4, 2)->setValue(-23.4);
132 xSheet0->getCellByPosition(5, 2)->setValue(34.5);
133 xSheet0->getCellByPosition(6, 2)->setValue(59.3);
134 xSheet0->getCellByPosition(7, 2)->setValue(27.3);
135 xSheet0->getCellByPosition(8, 2)->setValue(-38.5);
136 xSheet0->getCellByPosition(9, 2)->setValue(43.2);
137 xSheet0->getCellByPosition(10, 2)->setValue(57.3);
138 xSheet0->getCellByPosition(11, 2)->setValue(25.4);
139 xSheet0->getCellByPosition(11, 2)->setValue(28.5);
140 xSheet0->getCellByPosition(13, 2)->setFormula(u"SUM(B3:M3"_ustr);
142 xSheet0->getCellByPosition(0, 3)->setFormula(u"Brown"_ustr);
143 xSheet0->getCellByPosition(1, 3)->setValue(31.45);
144 xSheet0->getCellByPosition(2, 3)->setValue(-20.9);
145 xSheet0->getCellByPosition(3, 3)->setValue(-117.5);
146 xSheet0->getCellByPosition(4, 3)->setValue(23.4);
147 xSheet0->getCellByPosition(5, 3)->setValue(-114.5);
148 xSheet0->getCellByPosition(6, 3)->setValue(115.3);
149 xSheet0->getCellByPosition(7, 3)->setValue(-171.3);
150 xSheet0->getCellByPosition(8, 3)->setValue(89.5);
151 xSheet0->getCellByPosition(9, 3)->setValue(41.2);
152 xSheet0->getCellByPosition(10, 3)->setValue(71.3);
153 xSheet0->getCellByPosition(11, 3)->setValue(25.4);
154 xSheet0->getCellByPosition(11, 3)->setValue(38.5);
155 xSheet0->getCellByPosition(13, 3)->setFormula(u"SUM(A4:L4"_ustr);
157 uno::Reference<table::XCellRange> xCellRange0(xSheet0, uno::UNO_QUERY_THROW);
158 uno::Reference<table::XCellRange> xCellRange1(xCellRange0->getCellRangeByName(u"A1:N4"_ustr),
159 uno::UNO_SET_THROW);
160 uno::Reference<sheet::XCellRangeAddressable> xCRA(xCellRange1, uno::UNO_QUERY_THROW);
162 uno::Reference<table::XTableChartsSupplier> xTCS(xSheet0, uno::UNO_QUERY_THROW);
163 uno::Reference<table::XTableCharts> xTC = xTCS->getCharts();
164 xTC->addNewByName(u"ScChartsObj"_ustr, awt::Rectangle(500, 3000, 25000, 11000),
165 { xCRA->getRangeAddress() }, true, true);
167 return xTC;
170 void ScChartsObj::setUp()
172 UnoApiTest::setUp();
173 // create calc document
174 loadFromURL(u"private:factory/scalc"_ustr);
177 CPPUNIT_TEST_SUITE_REGISTRATION(ScChartsObj);
179 } // namespace sc_apitest
181 CPPUNIT_PLUGIN_IMPLEMENT();
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */