LibreOffice Module test (master) 1
xmultipleoperation.cxx
Go to the documentation of this file.
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.
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/TableOperationMode.hpp>
13#include <com/sun/star/sheet/XCellAddressable.hpp>
14#include <com/sun/star/sheet/XCellRangeAddressable.hpp>
15#include <com/sun/star/sheet/XMultipleOperation.hpp>
16#include <com/sun/star/sheet/XSpreadsheet.hpp>
17#include <com/sun/star/table/XCell.hpp>
18#include <com/sun/star/table/XCellRange.hpp>
19#include <com/sun/star/uno/Reference.hxx>
20
21#include <cppunit/TestAssert.h>
22
23using namespace css;
24using namespace css::uno;
25
26namespace apitest
27{
29{
30 uno::Reference<sheet::XMultipleOperation> xMultipleOperation(init(), UNO_QUERY_THROW);
31
32 uno::Reference<sheet::XSpreadsheet> xSheet(getXSpreadsheet(), UNO_QUERY_THROW);
33 uno::Reference<table::XCellRange> xCellRange(xSheet->getCellRangeByName("$A$20:$A$20"),
34 UNO_SET_THROW);
35 uno::Reference<sheet::XCellRangeAddressable> xCellRangeAddr(xCellRange, UNO_QUERY_THROW);
36
37 uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 19);
38 xCell->setFormula("=a18+a19");
39
40 uno::Reference<table::XCell> xCell1 = xSheet->getCellByPosition(0, 17);
41 uno::Reference<sheet::XCellAddressable> xCellAddr1(xCell1, UNO_QUERY_THROW);
42
43 uno::Reference<table::XCell> xCell2 = xSheet->getCellByPosition(0, 18);
44 uno::Reference<sheet::XCellAddressable> xCellAddr2(xCell2, UNO_QUERY_THROW);
45
46 fillCells(xSheet);
47 xMultipleOperation->setTableOperation(
48 xCellRangeAddr->getRangeAddress(), sheet::TableOperationMode_ROW,
49 xCellAddr1->getCellAddress(), xCellAddr2->getCellAddress());
50
51 CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 1,1 (OpMode: ROW)", 5.0,
52 xSheet->getCellByPosition(1, 1)->getValue());
53 CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 2,1 (OpMode: ROW)", 10.0,
54 xSheet->getCellByPosition(2, 1)->getValue());
55 CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 3,1 (OpMode: ROW)", 15.0,
56 xSheet->getCellByPosition(3, 1)->getValue());
57
58 fillCells(xSheet);
59 xMultipleOperation->setTableOperation(
60 xCellRangeAddr->getRangeAddress(), sheet::TableOperationMode_COLUMN,
61 xCellAddr1->getCellAddress(), xCellAddr2->getCellAddress());
62
63 CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 1,1 (OpMode: COLUMN)", 12.0,
64 xSheet->getCellByPosition(1, 1)->getValue());
65 CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 1,2 (OpMode: COLUMN)", 24.0,
66 xSheet->getCellByPosition(1, 2)->getValue());
67 CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 1,3 (OpMode: COLUMN)", 36.0,
68 xSheet->getCellByPosition(1, 3)->getValue());
69
70 fillCells(xSheet);
71 xMultipleOperation->setTableOperation(
72 xCellRangeAddr->getRangeAddress(), sheet::TableOperationMode_BOTH,
73 xCellAddr1->getCellAddress(), xCellAddr2->getCellAddress());
74
75 CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 1,1 (OpMode: BOTH)", 17.0,
76 xSheet->getCellByPosition(1, 1)->getValue());
77 CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 2,2 (OpMode: BOTH)", 34.0,
78 xSheet->getCellByPosition(2, 2)->getValue());
79 CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 3,3 (OpMode: BOTH)", 51.0,
80 xSheet->getCellByPosition(3, 3)->getValue());
81}
82
83void XMultipleOperation::fillCells(uno::Reference<sheet::XSpreadsheet> const& xSheet)
84{
85 for (unsigned int i = 1; i < 5; i++)
86 {
87 uno::Reference<table::XCell> xCellFill = xSheet->getCellByPosition(0, i);
88 xCellFill->setValue(i * 12);
89 xCellFill = xSheet->getCellByPosition(i, 0);
90 xCellFill->setValue(i * 5);
91 }
92}
93}
94
95/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
static void fillCells(css::uno::Reference< css::sheet::XSpreadsheet > const &)
virtual css::uno::Reference< css::uno::XInterface > init()=0
virtual css::uno::Reference< css::uno::XInterface > getXSpreadsheet()=0
int i