LibreOffice Module test (master) 1
xcellrangedata.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
11
12#include <com/sun/star/sheet/XCellRangeData.hpp>
13#include <com/sun/star/uno/Any.hxx>
14#include <com/sun/star/uno/Reference.hxx>
15#include <com/sun/star/uno/RuntimeException.hpp>
16#include <com/sun/star/uno/Sequence.hxx>
17
18#include <cppunit/TestAssert.h>
19
20using namespace css;
21using namespace css::uno;
22
23namespace apitest {
24
25namespace {
26
27void setValues(uno::Sequence< uno::Sequence < Any > >& rColRow, double nOffset)
28{
29 auto pColRow = rColRow.getArray();
30 for (sal_Int32 i = 0; i < 4; ++i)
31 {
32 pColRow[i].realloc(4);
33 auto pCol = pColRow[i].getArray();
34 for (sal_Int32 j = 0; j < 4; ++j)
35 {
36 Any& aAny = pCol[j];
37 double nValue = i + j + nOffset;
38 aAny <<= nValue;
39 }
40 }
41}
42
43}
44
46{
47 uno::Reference< sheet::XCellRangeData > xCellRangeData( getXCellRangeData(), UNO_QUERY_THROW);
48
49 uno::Sequence< uno::Sequence < Any > > aColRow(4);
50 setValues(aColRow, 1);
51 xCellRangeData->setDataArray(aColRow);
52
53 for ( sal_Int32 i = 0; i < aColRow.getLength(); ++i)
54 {
55 for ( sal_Int32 j = 0; j < aColRow[i].getLength(); ++j)
56 {
57 const Any& aAny = aColRow[i][j];
58 double nValue = 0.0;
59 CPPUNIT_ASSERT( aAny >>= nValue);
60 CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<double>(i+j+1), nValue, 0.000001);
61 }
62 }
63
64 // set old values
65 setValues(aColRow, 0);
66 xCellRangeData->setDataArray(aColRow);
67}
68
70{
71 uno::Reference< sheet::XCellRangeData > xCellRangeData( getXCellRangeData(), UNO_QUERY_THROW);
72 uno::Sequence< uno::Sequence < Any > > aColRow = xCellRangeData->getDataArray();
73 CPPUNIT_ASSERT(aColRow.hasElements());
74}
75
77{
78 uno::Reference< sheet::XCellRangeData > xCellRangeData( getXCellRangeData(), UNO_QUERY_THROW);
79 CPPUNIT_ASSERT_THROW_MESSAGE("No RuntimeException thrown", xCellRangeData->getDataArray(),
80 css::uno::RuntimeException);
81}
82
84{
85 uno::Reference< sheet::XCellRangeData > xCellRangeData( getXCellRangeData(), UNO_QUERY_THROW);
86
87 uno::Sequence< uno::Sequence < Any > > aColRow;
88 aColRow.realloc(4);
89 setValues(aColRow, 1);
90 CPPUNIT_ASSERT_THROW_MESSAGE("No RuntimeException thrown", xCellRangeData->setDataArray(aColRow),
91 css::uno::RuntimeException);
92}
93}
94
95/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::uno::XInterface > getXCellRangeData()=0
sal_Int16 nValue
int i