LibreOffice Module test (master) 1
xcellseries.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
11
12#include <com/sun/star/sheet/XCellSeries.hpp>
13#include <com/sun/star/table/XCellRange.hpp>
14
15#include <cppunit/TestAssert.h>
16
17using namespace com::sun::star;
18using namespace com::sun::star::uno;
19
20namespace apitest {
21
23{
24 uno::Reference<table::XCellRange> xCellRange(init(), UNO_QUERY_THROW);
25 sal_Int32 maValue = xCellRange->getCellByPosition(maStartX, maStartY)->getValue();
26
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);
30 sal_Int32 sumH = 0;
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();
34 }
35 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillAuto with TO_RIGHT", maValue * 3 + 3, sumH);
36
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);
40 sal_Int32 sumV = 0;
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();
44 }
45 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillAuto with TO_BOTTOM", maValue * 3 + 3, sumV);
46
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("");
52 }
53}
54
56{
57 uno::Reference<table::XCellRange> xCellRange(init(), UNO_QUERY_THROW);
58 sal_Int32 maValue = xCellRange->getCellByPosition(maStartX, maStartY)->getValue();
59
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);
65 sal_Int32 sumH = 0;
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();
69 }
70 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillSeries with TO_RIGHT and LINEAR", maValue * 3 + 6, sumH);
71
72 xCellSeriesH->fillSeries(sheet::FillDirection_TO_RIGHT,
73 sheet::FillMode_GROWTH,
74 sheet::FillDateMode_FILL_DATE_DAY, 2, 1000);
75 sumH = 0;
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();
79 }
80 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillSeries with TO_RIGHT and GROWTH", maValue + maValue * 2 + maValue * 4, sumH);
81
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);
87 sal_Int32 sumV = 0;
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();
91 }
92 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillSeries with TO_BOTTOM and LINEAR", maValue * 3 + 6, sumV);
93
94 xCellSeriesV->fillSeries(sheet::FillDirection_TO_BOTTOM,
95 sheet::FillMode_GROWTH,
96 sheet::FillDateMode_FILL_DATE_DAY, 2, 1000);
97 sumV = 0;
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();
101 }
102 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillSeries with TO_BOTTOM and GROWTH", maValue + maValue * 2 + maValue * 4, sumV);
103
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("");
109 }
110}
111
112}
113
114/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::uno::XInterface > init()=0
double maValue
int i