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 
20 using namespace css;
21 using namespace css::uno;
22 
23 namespace apitest {
24 
25 namespace {
26 
27 void setValues(uno::Sequence< uno::Sequence < Any > >& rColRow, double nOffset)
28 {
29  for (sal_Int32 i = 0; i < 4; ++i)
30  {
31  rColRow[i].realloc(4);
32  for (sal_Int32 j = 0; j < 4; ++j)
33  {
34  Any& aAny = rColRow[i][j];
35  double nValue = i + j + nOffset;
36  aAny <<= nValue;
37  }
38  }
39 }
40 
41 }
42 
43 void XCellRangeData::testSetDataArray()
44 {
45  uno::Reference< sheet::XCellRangeData > xCellRangeData( getXCellRangeData(), UNO_QUERY_THROW);
46 
47  uno::Sequence< uno::Sequence < Any > > aColRow;
48  aColRow.realloc(4);
49  setValues(aColRow, 1);
50  xCellRangeData->setDataArray(aColRow);
51 
52  for ( sal_Int32 i = 0; i < aColRow.getLength(); ++i)
53  {
54  for ( sal_Int32 j = 0; j < aColRow[i].getLength(); ++j)
55  {
56  Any& aAny = aColRow[i][j];
57  double nValue = 0.0;
58  CPPUNIT_ASSERT( aAny >>= nValue);
59  CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<double>(i+j+1), nValue, 0.000001);
60  }
61  }
62 
63  // set old values
64  setValues(aColRow, 0);
65  xCellRangeData->setDataArray(aColRow);
66 }
67 
68 void XCellRangeData::testGetDataArray()
69 {
70  uno::Reference< sheet::XCellRangeData > xCellRangeData( getXCellRangeData(), UNO_QUERY_THROW);
71  uno::Sequence< uno::Sequence < Any > > aColRow = xCellRangeData->getDataArray();
72  CPPUNIT_ASSERT(aColRow.hasElements());
73 }
74 
75 void XCellRangeData::testGetDataArrayOnTableSheet()
76 {
77  uno::Reference< sheet::XCellRangeData > xCellRangeData( getXCellRangeData(), UNO_QUERY_THROW);
78  CPPUNIT_ASSERT_THROW_MESSAGE("No RuntimeException thrown", xCellRangeData->getDataArray(),
79  css::uno::RuntimeException);
80 }
81 
82 void XCellRangeData::testSetDataArrayOnTableSheet()
83 {
84  uno::Reference< sheet::XCellRangeData > xCellRangeData( getXCellRangeData(), UNO_QUERY_THROW);
85 
86  uno::Sequence< uno::Sequence < Any > > aColRow;
87  aColRow.realloc(4);
88  setValues(aColRow, 1);
89  CPPUNIT_ASSERT_THROW_MESSAGE("No RuntimeException thrown", xCellRangeData->setDataArray(aColRow),
90  css::uno::RuntimeException);
91 }
92 }
93 
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
int i
sal_Int16 nValue