LibreOffice Module test (master) 1
xsheetcellrangecontainer.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
12
13#include <com/sun/star/sheet/XSheetCellRangeContainer.hpp>
14
15#include <com/sun/star/uno/Reference.hxx>
16#include <com/sun/star/uno/Sequence.hxx>
17
18#include <cppunit/TestAssert.h>
19
20using namespace com::sun::star;
21using namespace com::sun::star::uno;
22
23namespace apitest
24{
26{
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();
30
31 sal_Int32 cnt = xSCRC->getCount();
32 xSCRC->addRangeAddress(aAddr[0], false);
33 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddress (count)", cnt + 1,
34 xSCRC->getCount());
35
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]);
40
41 xSCRC->removeRangeAddress(aAddr[0]);
42 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove CellRangeAddress (count)", cnt - 1,
43 xSCRC->getCount());
44
45 const uno::Sequence<table::CellRangeAddress> aAfterRemoveAddr = xSCRC->getRangeAddresses();
46 for (auto const& addr : aAfterRemoveAddr)
47 {
48 CPPUNIT_ASSERT_MESSAGE("Unable to remove CellRangeAddress (entry)", aAddr[0] != addr);
49 }
50}
51
53{
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();
57
58 sal_Int32 cnt = xSCRC->getCount();
59 xSCRC->addRangeAddresses(aAddr, false);
60 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddress (count)", cnt + 2,
61 xSCRC->getCount());
62
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]);
69
70 xSCRC->removeRangeAddresses(aAddr);
71 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove CellRangeAddresses (count)", cnt - 2,
72 xSCRC->getCount());
73
74 const uno::Sequence<table::CellRangeAddress> aAfterRemoveAddr = xSCRC->getRangeAddresses();
75 for (auto const& addr : aAfterRemoveAddr)
76 {
77 CPPUNIT_ASSERT_MESSAGE("Unable to remove CellRangeAddresses (entry: first)",
78 aAddr[0] != addr);
79 CPPUNIT_ASSERT_MESSAGE("Unable to remove CellRangeAddresses (entry: second)",
80 aAddr[1] != addr);
81 }
82}
83
84uno::Sequence<table::CellRangeAddress> XSheetCellRangeContainer::createCellRangeAddresses()
85{
86 uno::Sequence<table::CellRangeAddress> aAddr(2);
87 auto pAddr = aAddr.getArray();
88 for (unsigned int i = 0; i < 2; i++)
89 {
90 pAddr[i].Sheet = i;
91 pAddr[i].StartColumn = i;
92 pAddr[i].StartRow = i;
93 pAddr[i].EndColumn = i + 3;
94 pAddr[i].EndRow = i + 3;
95 }
96
97 return aAddr;
98}
99}
100
101/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual css::uno::Reference< css::uno::XInterface > init()=0
static css::uno::Sequence< com::sun::star::table::CellRangeAddress > createCellRangeAddresses()
int i