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/uno/Reference.hxx>
21 #include <cppunit/TestAssert.h>
23 using namespace com::sun::star
;
24 using namespace com::sun::star::uno
;
28 void XCellRangeMovement::testInsertCells()
30 uno::Reference
<sheet::XCellRangeMovement
> xCRM(init(), UNO_QUERY_THROW
);
31 uno::Reference
<sheet::XSpreadsheet
> xSheet(xCRM
, UNO_QUERY_THROW
);
33 uno::Reference
<sheet::XCellRangeAddressable
> xCRA(xCRM
, UNO_QUERY_THROW
);
34 const sal_Int16 nSheet
= xCRA
->getRangeAddress().Sheet
;
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);
45 table::CellRangeAddress
aSrcCellRangeAddr(nSheet
, 0, 21, 5, 21);
46 xCRM
->insertCells(aSrcCellRangeAddr
, sheet::CellInsertMode_DOWN
);
48 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Unable to insert cells", 0.0,
49 xSheet
->getCellByPosition(1, 21)->getValue(), 0.0);
52 void XCellRangeMovement::testCopyRange()
54 uno::Reference
<sheet::XCellRangeMovement
> xCRM(init(), UNO_QUERY_THROW
);
55 uno::Reference
<sheet::XSpreadsheet
> xSheet(xCRM
, UNO_QUERY_THROW
);
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);
62 uno::Reference
<sheet::XCellRangeAddressable
> xCRA(xCRM
, UNO_QUERY_THROW
);
63 const sal_Int16 nSheet
= xCRA
->getRangeAddress().Sheet
;
65 table::CellRangeAddress
aSrcCellRangeAddr(nSheet
, 1, 1, 2, 2);
66 table::CellAddress
aDstCellAddr(nSheet
, 1, 10);
68 xCRM
->copyRange(aDstCellAddr
, aSrcCellRangeAddr
);
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);
79 void XCellRangeMovement::testMoveRange()
81 uno::Reference
<sheet::XCellRangeMovement
> xCRM(init(), UNO_QUERY_THROW
);
82 uno::Reference
<sheet::XSpreadsheet
> xSheet(xCRM
, UNO_QUERY_THROW
);
84 xSheet
->getCellByPosition(4, 0)->setValue(111);
85 xSheet
->getCellByPosition(4, 1)->setValue(222);
87 uno::Reference
<sheet::XCellRangeAddressable
> xCRA(xCRM
, UNO_QUERY_THROW
);
88 const sal_Int16 nSheet
= xCRA
->getRangeAddress().Sheet
;
90 table::CellRangeAddress
aSrcCellRangeAddr(nSheet
, 4, 0, 4, 1);
91 table::CellAddress
aDstCellAddr(nSheet
, 4, 4);
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(),
99 void XCellRangeMovement::testRemoveRange()
101 uno::Reference
<sheet::XCellRangeMovement
> xCRM(init(), UNO_QUERY_THROW
);
102 uno::Reference
<sheet::XSpreadsheet
> xSheet(xCRM
, UNO_QUERY_THROW
);
104 xSheet
->getCellByPosition(5, 0)->setValue(333);
105 xSheet
->getCellByPosition(5, 1)->setValue(444);
107 uno::Reference
<sheet::XCellRangeAddressable
> xCRA(xCRM
, UNO_QUERY_THROW
);
108 const sal_Int16 nSheet
= xCRA
->getRangeAddress().Sheet
;
110 table::CellRangeAddress
aSrcCellRangeAddr(nSheet
, 5, 0, 5, 1);
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(),
118 } // namespace apitest
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */