1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/sheet/xcellseries.hxx>
12 #include <com/sun/star/sheet/XCellSeries.hpp>
13 #include <com/sun/star/table/XCellRange.hpp>
15 #include <cppunit/TestAssert.h>
17 using namespace com::sun::star
;
18 using namespace com::sun::star::uno
;
22 void XCellSeries::testFillAuto()
24 uno::Reference
<table::XCellRange
> xCellRange(init(), UNO_QUERY_THROW
);
25 sal_Int32 maValue
= xCellRange
->getCellByPosition(maStartX
, maStartY
)->getValue();
27 uno::Reference
<table::XCellRange
> xCellRangeH(xCellRange
->getCellRangeByPosition(maStartX
, maStartY
, maStartX
+ 2, maStartY
), UNO_SET_THROW
);
28 uno::Reference
<sheet::XCellSeries
> xCellSeriesH(xCellRangeH
, UNO_QUERY_THROW
);
29 xCellSeriesH
->fillAuto(sheet::FillDirection_TO_RIGHT
, 1);
31 for(sal_Int32 i
= 0; i
< 3; i
++) {
32 uno::Reference
<table::XCell
> xCellResultH(xCellRange
->getCellByPosition(maStartX
+ i
, maStartY
), UNO_SET_THROW
);
33 sumH
+= xCellResultH
->getValue();
35 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillAuto with TO_RIGHT", maValue
* 3 + 3, sumH
);
37 uno::Reference
<table::XCellRange
> xCellRangeV(xCellRange
->getCellRangeByPosition(maStartX
, maStartY
, maStartX
, maStartY
+ 2), UNO_SET_THROW
);
38 uno::Reference
<sheet::XCellSeries
> xCellSeriesV(xCellRangeV
, UNO_QUERY_THROW
);
39 xCellSeriesV
->fillAuto(sheet::FillDirection_TO_BOTTOM
, 1);
41 for(sal_Int32 i
= 0; i
< 3; i
++) {
42 uno::Reference
<table::XCell
> xCellResultV(xCellRange
->getCellByPosition(maStartX
, maStartY
+ i
), UNO_SET_THROW
);
43 sumV
+= xCellResultV
->getValue();
45 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillAuto with TO_BOTTOM", maValue
* 3 + 3, sumV
);
47 for(sal_Int32 i
= 1; i
< 3; i
++) {
48 uno::Reference
<table::XCell
> xCellResultH(xCellRange
->getCellByPosition(maStartX
+ i
, maStartY
), UNO_SET_THROW
);
49 xCellResultH
->setFormula("");
50 uno::Reference
<table::XCell
> xCellResultV(xCellRange
->getCellByPosition(maStartX
, maStartY
+ i
), UNO_SET_THROW
);
51 xCellResultV
->setFormula("");
55 void XCellSeries::testFillSeries()
57 uno::Reference
<table::XCellRange
> xCellRange(init(), UNO_QUERY_THROW
);
58 sal_Int32 maValue
= xCellRange
->getCellByPosition(maStartX
, maStartY
)->getValue();
60 uno::Reference
<table::XCellRange
> xCellRangeH(xCellRange
->getCellRangeByPosition(maStartX
, maStartY
, maStartX
+ 2, maStartY
), UNO_SET_THROW
);
61 uno::Reference
<sheet::XCellSeries
> xCellSeriesH(xCellRangeH
, UNO_QUERY_THROW
);
62 xCellSeriesH
->fillSeries(sheet::FillDirection_TO_RIGHT
,
63 sheet::FillMode_LINEAR
,
64 sheet::FillDateMode_FILL_DATE_DAY
, 2, 1000);
66 for(sal_Int32 i
= 0; i
< 3; i
++) {
67 uno::Reference
<table::XCell
> xCellResultH(xCellRange
->getCellByPosition(maStartX
+ i
, maStartY
), UNO_SET_THROW
);
68 sumH
+= xCellResultH
->getValue();
70 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillSeries with TO_RIGHT and LINEAR", maValue
* 3 + 6, sumH
);
72 xCellSeriesH
->fillSeries(sheet::FillDirection_TO_RIGHT
,
73 sheet::FillMode_GROWTH
,
74 sheet::FillDateMode_FILL_DATE_DAY
, 2, 1000);
76 for(sal_Int32 i
= 0; i
< 3; i
++) {
77 uno::Reference
<table::XCell
> xCellResultH(xCellRange
->getCellByPosition(maStartX
+ i
, maStartY
), UNO_SET_THROW
);
78 sumH
+= xCellResultH
->getValue();
80 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillSeries with TO_RIGHT and GROWTH", maValue
+ maValue
* 2 + maValue
* 4, sumH
);
82 uno::Reference
<table::XCellRange
> xCellRangeV(xCellRange
->getCellRangeByPosition(maStartX
, maStartY
, maStartX
, maStartY
+ 2), UNO_SET_THROW
);
83 uno::Reference
<sheet::XCellSeries
> xCellSeriesV(xCellRangeV
, UNO_QUERY_THROW
);
84 xCellSeriesV
->fillSeries(sheet::FillDirection_TO_BOTTOM
,
85 sheet::FillMode_LINEAR
,
86 sheet::FillDateMode_FILL_DATE_DAY
, 2, 1000);
88 for(sal_Int32 i
= 0; i
< 3; i
++) {
89 uno::Reference
<table::XCell
> xCellResultV(xCellRange
->getCellByPosition(maStartX
, maStartY
+ i
), UNO_SET_THROW
);
90 sumV
+= xCellResultV
->getValue();
92 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillSeries with TO_BOTTOM and LINEAR", maValue
* 3 + 6, sumV
);
94 xCellSeriesV
->fillSeries(sheet::FillDirection_TO_BOTTOM
,
95 sheet::FillMode_GROWTH
,
96 sheet::FillDateMode_FILL_DATE_DAY
, 2, 1000);
98 for(sal_Int32 i
= 0; i
< 3; i
++) {
99 uno::Reference
<table::XCell
> xCellResultV(xCellRange
->getCellByPosition(maStartX
, maStartY
+ i
), UNO_SET_THROW
);
100 sumV
+= xCellResultV
->getValue();
102 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillSeries with TO_BOTTOM and GROWTH", maValue
+ maValue
* 2 + maValue
* 4, sumV
);
104 for(sal_Int32 i
= 1; i
< 3; i
++) {
105 uno::Reference
<table::XCell
> xCellResultH(xCellRange
->getCellByPosition(maStartX
+ i
, maStartY
), UNO_SET_THROW
);
106 xCellResultH
->setFormula("");
107 uno::Reference
<table::XCell
> xCellResultV(xCellRange
->getCellByPosition(maStartX
, maStartY
+ i
), UNO_SET_THROW
);
108 xCellResultV
->setFormula("");
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */