1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/xdatabaserange.hxx>
12 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
13 #include <com/sun/star/sheet/XSpreadsheet.hpp>
14 #include <com/sun/star/sheet/XSubTotalDescriptor.hpp>
15 #include <com/sun/star/beans/PropertyValue.hpp>
16 #include <com/sun/star/sheet/XDatabaseRange.hpp>
17 #include <com/sun/star/sheet/XDatabaseRanges.hpp>
18 #include <com/sun/star/table/CellRangeAddress.hpp>
19 #include <com/sun/star/util/XCloseable.hpp>
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
22 #include <com/sun/star/table/XCell.hpp>
23 #include <com/sun/star/table/XTableRows.hpp>
24 #include <com/sun/star/table/XColumnRowRange.hpp>
26 #include <rtl/ustring.hxx>
27 #include <cppunit/extensions/HelperMacros.h>
31 using namespace css::uno
;
36 * tests setDataArea and getDataArea
38 void XDatabaseRange::testDataArea()
40 uno::Reference
< sheet::XDatabaseRange
> xDBRange(init("DataArea"), UNO_QUERY_THROW
);
42 table::CellRangeAddress aCellAddress
;
43 aCellAddress
.Sheet
= 0;
44 aCellAddress
.StartColumn
= 1;
45 aCellAddress
.EndColumn
= 4;
46 aCellAddress
.StartRow
= 2;
47 aCellAddress
.EndRow
= 5;
48 xDBRange
->setDataArea(aCellAddress
);
49 table::CellRangeAddress aValue
= xDBRange
->getDataArea();
50 CPPUNIT_ASSERT_EQUAL( aCellAddress
.Sheet
, aValue
.Sheet
);
51 CPPUNIT_ASSERT_EQUAL( aCellAddress
.StartRow
, aValue
.StartRow
);
52 CPPUNIT_ASSERT_EQUAL( aCellAddress
.EndRow
, aValue
.EndRow
);
53 CPPUNIT_ASSERT_EQUAL( aCellAddress
.StartColumn
, aValue
.StartColumn
);
54 CPPUNIT_ASSERT_EQUAL( aCellAddress
.EndColumn
, aValue
.EndColumn
);
57 void XDatabaseRange::testGetSubtotalDescriptor()
59 uno::Reference
< sheet::XDatabaseRange
> xDBRange(init("SubtotalDescriptor"), UNO_QUERY_THROW
);
60 uno::Reference
< sheet::XSubTotalDescriptor
> xSubtotalDescr
= xDBRange
->getSubTotalDescriptor();
61 CPPUNIT_ASSERT(xSubtotalDescr
.is());
64 void XDatabaseRange::testGetSortDescriptor()
66 uno::Reference
< sheet::XDatabaseRange
> xDBRange(init("SortDescriptor"), UNO_QUERY_THROW
);
67 const uno::Sequence
< beans::PropertyValue
> xSortDescr
= xDBRange
->getSortDescriptor();
68 for (const beans::PropertyValue
& aProp
: xSortDescr
)
70 //std::cout << "Prop " << i << " Name: " << OUString(aProp.Name) << std::endl;
72 if (aProp
.Name
== "IsSortColumns")
74 bool bIsSortColumns
= true;
75 aProp
.Value
>>= bIsSortColumns
;
76 CPPUNIT_ASSERT(bIsSortColumns
);
78 else if (aProp
.Name
== "ContainsHeader")
80 bool bContainsHeader
= true;
81 aProp
.Value
>>= bContainsHeader
;
82 CPPUNIT_ASSERT(bContainsHeader
);
84 else if (aProp
.Name
== "MaxFieldCount")
86 sal_Int32 nMaxFieldCount
= 0;
87 aProp
.Value
>>= nMaxFieldCount
;
88 std::cout
<< "Value: " << nMaxFieldCount
<< std::endl
;
91 else if (aProp
.Name
== "SortFields")
95 else if (aProp
.Name
== "BindFormatsToContent")
97 bool bBindFormatsToContent
= false;
98 aProp
.Value
>>= bBindFormatsToContent
;
99 CPPUNIT_ASSERT(bBindFormatsToContent
);
101 else if (aProp
.Name
== "CopyOutputData")
103 bool bCopyOutputData
= true;
104 aProp
.Value
>>= bCopyOutputData
;
105 CPPUNIT_ASSERT(!bCopyOutputData
);
107 else if (aProp
.Name
== "OutputPosition")
111 else if (aProp
.Name
== "IsUserListEnabled")
113 bool bIsUserListEnabled
= true;
114 aProp
.Value
>>= bIsUserListEnabled
;
115 CPPUNIT_ASSERT(!bIsUserListEnabled
);
118 else if (aProp
.Name
== "UserListIndex")
120 sal_Int32 nUserListIndex
= 1;
121 aProp
.Value
>>= nUserListIndex
;
122 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nUserListIndex
);
127 void XDatabaseRange::testGetFilterDescriptor()
129 uno::Reference
< sheet::XDatabaseRange
> xDBRange( init("FilterDescriptor"), UNO_QUERY_THROW
);
130 uno::Reference
< uno::XInterface
> xFilterDescr( xDBRange
->getFilterDescriptor(), UNO_QUERY_THROW
);
133 void XDatabaseRange::testGetImportDescriptor()
135 uno::Reference
< sheet::XDatabaseRange
> xDBRange( init("ImportDescriptor"), UNO_QUERY_THROW
);
136 uno::Sequence
< beans::PropertyValue
> xImportDescr
= xDBRange
->getImportDescriptor();
140 void XDatabaseRange::testRefresh()
142 uno::Reference
< sheet::XDatabaseRange
> xDBRange( init("Refresh"), UNO_QUERY_THROW
);
144 const sal_Int32 nCol
= 0;
145 OUString
aHidden("IsVisible");
146 uno::Reference
< sheet::XCellRangeReferrer
> xCellRangeReferrer(xDBRange
, UNO_QUERY_THROW
);
147 uno::Reference
< table::XCellRange
> xCellRange
= xCellRangeReferrer
->getReferredCells();
149 for (sal_Int32 i
= 1; i
< 5; ++i
)
151 uno::Reference
< table::XCell
> xCell
= xCellRange
->getCellByPosition(nCol
, i
);
155 for (sal_Int32 i
= 2; i
< 5; ++i
)
157 uno::Reference
< table::XColumnRowRange
> xColRowRange(xCellRange
, UNO_QUERY_THROW
);
158 uno::Reference
< table::XTableRows
> xRows
= xColRowRange
->getRows();
159 uno::Reference
< table::XCellRange
> xRow(xRows
->getByIndex(i
), UNO_QUERY_THROW
);
160 uno::Reference
< beans::XPropertySet
> xPropRow(xRow
, UNO_QUERY_THROW
);
161 Any aAny
= xPropRow
->getPropertyValue( aHidden
);
163 CPPUNIT_ASSERT(aAny
.get
<bool>());
167 std::cout
<< "after refresh" << std::endl
;
169 for (sal_Int32 i
= 1; i
< 5; ++i
)
171 uno::Reference
< table::XColumnRowRange
> xColRowRange(xCellRange
, UNO_QUERY_THROW
);
172 uno::Reference
< table::XTableRows
> xRows
= xColRowRange
->getRows();
173 uno::Reference
< table::XCellRange
> xRow(xRows
->getByIndex(i
), UNO_QUERY_THROW
);
174 uno::Reference
< beans::XPropertySet
> xPropRow(xRow
, UNO_QUERY_THROW
);
175 Any aAny
= xPropRow
->getPropertyValue( aHidden
);
177 CPPUNIT_ASSERT(!aAny
.get
<bool>());
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */