1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/xcellrangemovement.hxx>
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/table/XColumnRowRange.hpp>
20 #include <com/sun/star/table/XTableRows.hpp>
21 #include <com/sun/star/uno/Reference.hxx>
22 #include <com/sun/star/uno/Sequence.hxx>
24 #include <cppunit/extensions/HelperMacros.h>
26 using namespace com::sun::star
;
27 using namespace com::sun::star::uno
;
31 void XCellRangeMovement::testInsertCells()
33 uno::Reference
<sheet::XCellRangeMovement
> xCRM(init(), UNO_QUERY_THROW
);
34 uno::Reference
<sheet::XSpreadsheet
> xSheet(xCRM
, UNO_QUERY_THROW
);
36 uno::Reference
<sheet::XCellRangeAddressable
> xCRA(xCRM
, UNO_QUERY_THROW
);
37 const sal_Int16 nSheet
= xCRA
->getRangeAddress().Sheet
;
39 xSheet
->getCellByPosition(0, 20)->setValue(100);
40 xSheet
->getCellByPosition(1, 20)->setValue(100);
41 xSheet
->getCellByPosition(2, 20)->setValue(100);
42 xSheet
->getCellByPosition(3, 20)->setValue(100);
43 xSheet
->getCellByPosition(0, 21)->setValue(200);
44 xSheet
->getCellByPosition(1, 21)->setValue(200);
45 xSheet
->getCellByPosition(2, 21)->setValue(200);
46 xSheet
->getCellByPosition(3, 21)->setValue(200);
48 table::CellRangeAddress
aSrcCellRangeAddr(nSheet
, 0, 21, 5, 21);
49 xCRM
->insertCells(aSrcCellRangeAddr
, sheet::CellInsertMode_DOWN
);
51 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Unable to insert cells", 0.0,
52 xSheet
->getCellByPosition(1, 21)->getValue(), 0.0);
55 void XCellRangeMovement::testCopyRange()
57 uno::Reference
<sheet::XCellRangeMovement
> xCRM(init(), UNO_QUERY_THROW
);
58 uno::Reference
<sheet::XSpreadsheet
> xSheet(xCRM
, UNO_QUERY_THROW
);
60 xSheet
->getCellByPosition(1, 1)->setValue(100);
61 xSheet
->getCellByPosition(1, 2)->setValue(200);
62 xSheet
->getCellByPosition(2, 1)->setValue(300);
63 xSheet
->getCellByPosition(2, 2)->setValue(400);
65 uno::Reference
<sheet::XCellRangeAddressable
> xCRA(xCRM
, UNO_QUERY_THROW
);
66 const sal_Int16 nSheet
= xCRA
->getRangeAddress().Sheet
;
68 table::CellRangeAddress
aSrcCellRangeAddr(nSheet
, 1, 1, 2, 2);
69 table::CellAddress
aDstCellAddr(nSheet
, 1, 10);
71 xCRM
->copyRange(aDstCellAddr
, aSrcCellRangeAddr
);
73 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value was not copied from position 1,1 to 1,10", 100.0,
74 xSheet
->getCellByPosition(1, 10)->getValue(), 0.1);
75 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value was not copied from position 1,2 to 1,11", 200.0,
76 xSheet
->getCellByPosition(1, 11)->getValue(), 0.1);
77 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value was not copied from position 2,1 to 2,10", 300.0,
78 xSheet
->getCellByPosition(2, 10)->getValue(), 0.1);
79 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value was not copied from position 2,2 to 2,11", 400.0,
80 xSheet
->getCellByPosition(2, 11)->getValue(), 0.1);
82 void XCellRangeMovement::testMoveRange()
84 uno::Reference
<sheet::XCellRangeMovement
> xCRM(init(), UNO_QUERY_THROW
);
85 uno::Reference
<sheet::XSpreadsheet
> xSheet(xCRM
, UNO_QUERY_THROW
);
87 xSheet
->getCellByPosition(4, 0)->setValue(111);
88 xSheet
->getCellByPosition(4, 1)->setValue(222);
90 uno::Reference
<sheet::XCellRangeAddressable
> xCRA(xCRM
, UNO_QUERY_THROW
);
91 const sal_Int16 nSheet
= xCRA
->getRangeAddress().Sheet
;
93 table::CellRangeAddress
aSrcCellRangeAddr(nSheet
, 4, 0, 4, 1);
94 table::CellAddress
aDstCellAddr(nSheet
, 4, 4);
96 xCRM
->moveRange(aDstCellAddr
, aSrcCellRangeAddr
);
97 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Unable to move range", 333.0,
98 xSheet
->getCellByPosition(4, 4)->getValue()
99 + xSheet
->getCellByPosition(4, 5)->getValue(),
102 void XCellRangeMovement::testRemoveRange()
104 uno::Reference
<sheet::XCellRangeMovement
> xCRM(init(), UNO_QUERY_THROW
);
105 uno::Reference
<sheet::XSpreadsheet
> xSheet(xCRM
, UNO_QUERY_THROW
);
107 xSheet
->getCellByPosition(5, 0)->setValue(333);
108 xSheet
->getCellByPosition(5, 1)->setValue(444);
110 uno::Reference
<sheet::XCellRangeAddressable
> xCRA(xCRM
, UNO_QUERY_THROW
);
111 const sal_Int16 nSheet
= xCRA
->getRangeAddress().Sheet
;
113 table::CellRangeAddress
aSrcCellRangeAddr(nSheet
, 5, 0, 5, 1);
115 xCRM
->removeRange(aSrcCellRangeAddr
, sheet::CellDeleteMode_UP
);
116 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Unable to remove range", 0.0,
117 xSheet
->getCellByPosition(5, 0)->getValue()
118 + xSheet
->getCellByPosition(5, 1)->getValue(),
121 } // namespace apitest
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */