diff options
author | Jens Carl <j.carl43@gmx.de> | 2018-04-06 04:31:52 +0000 |
---|---|---|
committer | Jens Carl <j.carl43@gmx.de> | 2018-04-06 17:32:47 +0200 |
commit | 7dcda19e4a5580dd526eeab07feba12f4212e4f1 (patch) | |
tree | e237db11c5301dcd2f75b0acc48721861aa8308e /test | |
parent | 8ed2fb306ffa8c7fef336b858fc5074c309c3c9f (diff) |
tdf#45904 Move _XCellRangeMovement Java tests to C++
Change-Id: I8d3697b9c409e4fd9f9d28b8598b8807b91c5363
Reviewed-on: https://gerrit.libreoffice.org/52485
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Jens Carl <j.carl43@gmx.de>
Diffstat (limited to 'test')
-rw-r--r-- | test/Library_subsequenttest.mk | 3 | ||||
-rw-r--r-- | test/source/sheet/xcellrangemovement.cxx | 123 |
2 files changed, 125 insertions, 1 deletions
diff --git a/test/Library_subsequenttest.mk b/test/Library_subsequenttest.mk index fe8729b40c9f..dd6509ce81c9 100644 --- a/test/Library_subsequenttest.mk +++ b/test/Library_subsequenttest.mk @@ -77,8 +77,9 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\ test/source/sheet/xcelladdressable \ test/source/sheet/xcellformatrangessupplier \ test/source/sheet/xcellrangeaddressable \ - test/source/sheet/xcellrangeformula \ test/source/sheet/xcellrangedata \ + test/source/sheet/xcellrangeformula \ + test/source/sheet/xcellrangemovement \ test/source/sheet/xcellrangereferrer \ test/source/sheet/xcellrangesquery \ test/source/sheet/xcellseries \ diff --git a/test/source/sheet/xcellrangemovement.cxx b/test/source/sheet/xcellrangemovement.cxx new file mode 100644 index 000000000000..93fa2dd2a1cc --- /dev/null +++ b/test/source/sheet/xcellrangemovement.cxx @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <test/sheet/xcellrangemovement.hxx> + +#include <com/sun/star/sheet/CellDeleteMode.hpp> +#include <com/sun/star/sheet/CellInsertMode.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XCellRangeMovement.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/table/XTableRows.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/extensions/HelperMacros.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XCellRangeMovement::testInsertCells() +{ + uno::Reference<sheet::XCellRangeMovement> xCRM(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xCRM, UNO_QUERY_THROW); + + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCRM, UNO_QUERY_THROW); + const sal_Int16 nSheet = xCRA->getRangeAddress().Sheet; + + xSheet->getCellByPosition(0, 20)->setValue(100); + xSheet->getCellByPosition(1, 20)->setValue(100); + xSheet->getCellByPosition(2, 20)->setValue(100); + xSheet->getCellByPosition(3, 20)->setValue(100); + xSheet->getCellByPosition(0, 21)->setValue(200); + xSheet->getCellByPosition(1, 21)->setValue(200); + xSheet->getCellByPosition(2, 21)->setValue(200); + xSheet->getCellByPosition(3, 21)->setValue(200); + + table::CellRangeAddress aSrcCellRangeAddr(nSheet, 0, 21, 5, 21); + xCRM->insertCells(aSrcCellRangeAddr, sheet::CellInsertMode_DOWN); + + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Unable to insert cells", 0.0, + xSheet->getCellByPosition(1, 21)->getValue(), 0.0); +} + +void XCellRangeMovement::testCopyRange() +{ + uno::Reference<sheet::XCellRangeMovement> xCRM(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xCRM, UNO_QUERY_THROW); + + xSheet->getCellByPosition(1, 1)->setValue(100); + xSheet->getCellByPosition(1, 2)->setValue(200); + xSheet->getCellByPosition(2, 1)->setValue(300); + xSheet->getCellByPosition(2, 2)->setValue(400); + + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCRM, UNO_QUERY_THROW); + const sal_Int16 nSheet = xCRA->getRangeAddress().Sheet; + + table::CellRangeAddress aSrcCellRangeAddr(nSheet, 1, 1, 2, 2); + table::CellAddress aDstCellAddr(nSheet, 1, 10); + + xCRM->copyRange(aDstCellAddr, aSrcCellRangeAddr); + + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value was not copied from position 1,1 to 1,10", 100.0, + xSheet->getCellByPosition(1, 10)->getValue(), 0.1); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value was not copied from position 1,2 to 1,11", 200.0, + xSheet->getCellByPosition(1, 11)->getValue(), 0.1); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value was not copied from position 2,1 to 2,10", 300.0, + xSheet->getCellByPosition(2, 10)->getValue(), 0.1); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value was not copied from position 2,2 to 2,11", 400.0, + xSheet->getCellByPosition(2, 11)->getValue(), 0.1); +} +void XCellRangeMovement::testMoveRange() +{ + uno::Reference<sheet::XCellRangeMovement> xCRM(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xCRM, UNO_QUERY_THROW); + + xSheet->getCellByPosition(4, 0)->setValue(111); + xSheet->getCellByPosition(4, 1)->setValue(222); + + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCRM, UNO_QUERY_THROW); + const sal_Int16 nSheet = xCRA->getRangeAddress().Sheet; + + table::CellRangeAddress aSrcCellRangeAddr(nSheet, 4, 0, 4, 1); + table::CellAddress aDstCellAddr(nSheet, 4, 4); + + xCRM->moveRange(aDstCellAddr, aSrcCellRangeAddr); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Unable to move range", 333.0, + xSheet->getCellByPosition(4, 4)->getValue() + + xSheet->getCellByPosition(4, 5)->getValue(), + 0.0); +} +void XCellRangeMovement::testRemoveRange() +{ + uno::Reference<sheet::XCellRangeMovement> xCRM(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xCRM, UNO_QUERY_THROW); + + xSheet->getCellByPosition(5, 0)->setValue(333); + xSheet->getCellByPosition(5, 1)->setValue(444); + + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCRM, UNO_QUERY_THROW); + const sal_Int16 nSheet = xCRA->getRangeAddress().Sheet; + + table::CellRangeAddress aSrcCellRangeAddr(nSheet, 5, 0, 5, 1); + + xCRM->removeRange(aSrcCellRangeAddr, sheet::CellDeleteMode_UP); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Unable to remove range", 0.0, + xSheet->getCellByPosition(5, 0)->getValue() + + xSheet->getCellByPosition(5, 1)->getValue(), + 0.0); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |