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/xsheetcellrangecontainer.hxx>
11 #include <test/cppunitasserthelper.hxx>
13 #include <com/sun/star/sheet/XSheetCellRangeContainer.hpp>
15 #include <com/sun/star/uno/Reference.hxx>
16 #include <com/sun/star/uno/Sequence.hxx>
18 #include <cppunit/TestAssert.h>
20 using namespace com::sun::star
;
21 using namespace com::sun::star::uno
;
25 void XSheetCellRangeContainer::testAddRemoveRangeAddress()
27 uno::Reference
<sheet::XSheetCellRangeContainer
> xSCRC(init(), UNO_QUERY_THROW
);
28 xSCRC
->removeRangeAddresses(xSCRC
->getRangeAddresses()); // prepare a clean slate
29 uno::Sequence
<table::CellRangeAddress
> aAddr
= createCellRangeAddresses();
31 sal_Int32 cnt
= xSCRC
->getCount();
32 xSCRC
->addRangeAddress(aAddr
[0], false);
33 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddress (count)", cnt
+ 1,
36 uno::Sequence
<table::CellRangeAddress
> aAfterAddAddr
= xSCRC
->getRangeAddresses();
37 cnt
= xSCRC
->getCount();
38 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddress (entry)", aAddr
[0],
39 aAfterAddAddr
[cnt
- 1]);
41 xSCRC
->removeRangeAddress(aAddr
[0]);
42 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove CellRangeAddress (count)", cnt
- 1,
45 const uno::Sequence
<table::CellRangeAddress
> aAfterRemoveAddr
= xSCRC
->getRangeAddresses();
46 for (auto const& addr
: aAfterRemoveAddr
)
48 CPPUNIT_ASSERT_MESSAGE("Unable to remove CellRangeAddress (entry)", aAddr
[0] != addr
);
52 void XSheetCellRangeContainer::testAddRemoveRangeAddresses()
54 uno::Reference
<sheet::XSheetCellRangeContainer
> xSCRC(init(), UNO_QUERY_THROW
);
55 xSCRC
->removeRangeAddresses(xSCRC
->getRangeAddresses()); // prepare a clean slate
56 uno::Sequence
<table::CellRangeAddress
> aAddr
= createCellRangeAddresses();
58 sal_Int32 cnt
= xSCRC
->getCount();
59 xSCRC
->addRangeAddresses(aAddr
, false);
60 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddress (count)", cnt
+ 2,
63 uno::Sequence
<table::CellRangeAddress
> aAfterAddAddr
= xSCRC
->getRangeAddresses();
64 cnt
= xSCRC
->getCount();
65 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddresses (entry: first)", aAddr
[0],
66 aAfterAddAddr
[cnt
- 2]);
67 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddresses (entry: second)", aAddr
[1],
68 aAfterAddAddr
[cnt
- 1]);
70 xSCRC
->removeRangeAddresses(aAddr
);
71 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove CellRangeAddresses (count)", cnt
- 2,
74 const uno::Sequence
<table::CellRangeAddress
> aAfterRemoveAddr
= xSCRC
->getRangeAddresses();
75 for (auto const& addr
: aAfterRemoveAddr
)
77 CPPUNIT_ASSERT_MESSAGE("Unable to remove CellRangeAddresses (entry: first)",
79 CPPUNIT_ASSERT_MESSAGE("Unable to remove CellRangeAddresses (entry: second)",
84 uno::Sequence
<table::CellRangeAddress
> XSheetCellRangeContainer::createCellRangeAddresses()
86 uno::Sequence
<table::CellRangeAddress
> aAddr(2);
87 for (unsigned int i
= 0; i
< 2; i
++)
90 aAddr
[i
].StartColumn
= i
;
91 aAddr
[i
].StartRow
= i
;
92 aAddr
[i
].EndColumn
= i
+ 3;
93 aAddr
[i
].EndRow
= i
+ 3;
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */