LibreOffice Module test (master) 1
xcellrangemovement.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/CellDeleteMode.hpp>
13#include <com/sun/star/sheet/CellInsertMode.hpp>
14#include <com/sun/star/sheet/XCellRangeAddressable.hpp>
15#include <com/sun/star/sheet/XCellRangeMovement.hpp>
16#include <com/sun/star/sheet/XSpreadsheet.hpp>
17#include <com/sun/star/table/CellAddress.hpp>
18#include <com/sun/star/table/CellRangeAddress.hpp>
19#include <com/sun/star/uno/Reference.hxx>
20
21#include <cppunit/TestAssert.h>
22
23using namespace com::sun::star;
24using namespace com::sun::star::uno;
25
26namespace apitest
27{
29{
30 uno::Reference<sheet::XCellRangeMovement> xCRM(init(), UNO_QUERY_THROW);
31 uno::Reference<sheet::XSpreadsheet> xSheet(xCRM, UNO_QUERY_THROW);
32
33 uno::Reference<sheet::XCellRangeAddressable> xCRA(xCRM, UNO_QUERY_THROW);
34 const sal_Int16 nSheet = xCRA->getRangeAddress().Sheet;
35
36 xSheet->getCellByPosition(0, 20)->setValue(100);
37 xSheet->getCellByPosition(1, 20)->setValue(100);
38 xSheet->getCellByPosition(2, 20)->setValue(100);
39 xSheet->getCellByPosition(3, 20)->setValue(100);
40 xSheet->getCellByPosition(0, 21)->setValue(200);
41 xSheet->getCellByPosition(1, 21)->setValue(200);
42 xSheet->getCellByPosition(2, 21)->setValue(200);
43 xSheet->getCellByPosition(3, 21)->setValue(200);
44
45 table::CellRangeAddress aSrcCellRangeAddr(nSheet, 0, 21, 5, 21);
46 xCRM->insertCells(aSrcCellRangeAddr, sheet::CellInsertMode_DOWN);
47
48 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Unable to insert cells", 0.0,
49 xSheet->getCellByPosition(1, 21)->getValue(), 0.0);
50}
51
53{
54 uno::Reference<sheet::XCellRangeMovement> xCRM(init(), UNO_QUERY_THROW);
55 uno::Reference<sheet::XSpreadsheet> xSheet(xCRM, UNO_QUERY_THROW);
56
57 xSheet->getCellByPosition(1, 1)->setValue(100);
58 xSheet->getCellByPosition(1, 2)->setValue(200);
59 xSheet->getCellByPosition(2, 1)->setValue(300);
60 xSheet->getCellByPosition(2, 2)->setValue(400);
61
62 uno::Reference<sheet::XCellRangeAddressable> xCRA(xCRM, UNO_QUERY_THROW);
63 const sal_Int16 nSheet = xCRA->getRangeAddress().Sheet;
64
65 table::CellRangeAddress aSrcCellRangeAddr(nSheet, 1, 1, 2, 2);
66 table::CellAddress aDstCellAddr(nSheet, 1, 10);
67
68 xCRM->copyRange(aDstCellAddr, aSrcCellRangeAddr);
69
70 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value was not copied from position 1,1 to 1,10", 100.0,
71 xSheet->getCellByPosition(1, 10)->getValue(), 0.1);
72 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value was not copied from position 1,2 to 1,11", 200.0,
73 xSheet->getCellByPosition(1, 11)->getValue(), 0.1);
74 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value was not copied from position 2,1 to 2,10", 300.0,
75 xSheet->getCellByPosition(2, 10)->getValue(), 0.1);
76 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value was not copied from position 2,2 to 2,11", 400.0,
77 xSheet->getCellByPosition(2, 11)->getValue(), 0.1);
78}
80{
81 uno::Reference<sheet::XCellRangeMovement> xCRM(init(), UNO_QUERY_THROW);
82 uno::Reference<sheet::XSpreadsheet> xSheet(xCRM, UNO_QUERY_THROW);
83
84 xSheet->getCellByPosition(4, 0)->setValue(111);
85 xSheet->getCellByPosition(4, 1)->setValue(222);
86
87 uno::Reference<sheet::XCellRangeAddressable> xCRA(xCRM, UNO_QUERY_THROW);
88 const sal_Int16 nSheet = xCRA->getRangeAddress().Sheet;
89
90 table::CellRangeAddress aSrcCellRangeAddr(nSheet, 4, 0, 4, 1);
91 table::CellAddress aDstCellAddr(nSheet, 4, 4);
92
93 xCRM->moveRange(aDstCellAddr, aSrcCellRangeAddr);
94 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Unable to move range", 333.0,
95 xSheet->getCellByPosition(4, 4)->getValue()
96 + xSheet->getCellByPosition(4, 5)->getValue(),
97 0.0);
98}
100{
101 uno::Reference<sheet::XCellRangeMovement> xCRM(init(), UNO_QUERY_THROW);
102 uno::Reference<sheet::XSpreadsheet> xSheet(xCRM, UNO_QUERY_THROW);
103
104 xSheet->getCellByPosition(5, 0)->setValue(333);
105 xSheet->getCellByPosition(5, 1)->setValue(444);
106
107 uno::Reference<sheet::XCellRangeAddressable> xCRA(xCRM, UNO_QUERY_THROW);
108 const sal_Int16 nSheet = xCRA->getRangeAddress().Sheet;
109
110 table::CellRangeAddress aSrcCellRangeAddr(nSheet, 5, 0, 5, 1);
111
112 xCRM->removeRange(aSrcCellRangeAddr, sheet::CellDeleteMode_UP);
113 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Unable to remove range", 0.0,
114 xSheet->getCellByPosition(5, 0)->getValue()
115 + xSheet->getCellByPosition(5, 1)->getValue(),
116 0.0);
117}
118} // namespace apitest
119
120/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual css::uno::Reference< css::uno::XInterface > init()=0