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(OUString("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
;
50 aValue
= xDBRange
->getDataArea();
51 CPPUNIT_ASSERT( aCellAddress
.Sheet
== aValue
.Sheet
);
52 CPPUNIT_ASSERT( aCellAddress
.StartRow
== aValue
.StartRow
);
53 CPPUNIT_ASSERT( aCellAddress
.EndRow
== aValue
.EndRow
);
54 CPPUNIT_ASSERT( aCellAddress
.StartColumn
== aValue
.StartColumn
);
55 CPPUNIT_ASSERT( aCellAddress
.EndColumn
== aValue
.EndColumn
);
58 void XDatabaseRange::testGetSubtotalDescriptor()
60 uno::Reference
< sheet::XDatabaseRange
> xDBRange(init(OUString("SubtotalDescriptor")), UNO_QUERY_THROW
);
61 uno::Reference
< sheet::XSubTotalDescriptor
> xSubtotalDescr
= xDBRange
->getSubTotalDescriptor();
62 CPPUNIT_ASSERT(xSubtotalDescr
.is());
65 void XDatabaseRange::testGetSortDescriptor()
67 uno::Reference
< sheet::XDatabaseRange
> xDBRange(init(OUString("SortDescriptor")), UNO_QUERY_THROW
);
68 uno::Sequence
< beans::PropertyValue
> xSortDescr
= xDBRange
->getSortDescriptor();
69 for (sal_Int32 i
= 0; i
< xSortDescr
.getLength(); ++i
)
71 beans::PropertyValue xProp
= xSortDescr
[i
];
72 //std::cout << "Prop " << i << " Name: " << OUString(xProp.Name) << std::endl;
74 if (xProp
.Name
== OUString("IsSortColumns"))
76 sal_Bool bIsSortColumns
= sal_True
;
77 xProp
.Value
>>= bIsSortColumns
;
78 CPPUNIT_ASSERT(bIsSortColumns
== sal_True
);
80 else if (xProp
.Name
== OUString("ContainsHeader"))
82 sal_Bool bContainsHeader
= sal_True
;
83 xProp
.Value
>>= bContainsHeader
;
84 CPPUNIT_ASSERT(bContainsHeader
== sal_True
);
86 else if (xProp
.Name
== OUString("MaxFieldCount"))
88 sal_Int32 nMaxFieldCount
= 0;
89 xProp
.Value
>>= nMaxFieldCount
;
90 std::cout
<< "Value: " << nMaxFieldCount
<< std::endl
;
93 else if (xProp
.Name
== OUString("SortFields"))
97 else if (xProp
.Name
== OUString("BindFormatsToContent"))
99 sal_Bool bBindFormatsToContent
= sal_False
;
100 xProp
.Value
>>= bBindFormatsToContent
;
101 CPPUNIT_ASSERT(bBindFormatsToContent
== sal_True
);
103 else if (xProp
.Name
== OUString("CopyOutputData"))
105 sal_Bool bCopyOutputData
= sal_True
;
106 xProp
.Value
>>= bCopyOutputData
;
107 CPPUNIT_ASSERT(bCopyOutputData
== sal_False
);
109 else if (xProp
.Name
== OUString("OutputPosition"))
113 else if (xProp
.Name
== OUString("IsUserListEnabled"))
115 sal_Bool bIsUserListEnabled
= sal_True
;
116 xProp
.Value
>>= bIsUserListEnabled
;
117 CPPUNIT_ASSERT(bIsUserListEnabled
== sal_False
);
120 else if (xProp
.Name
== OUString("UserListIndex"))
122 sal_Int32 nUserListIndex
= 1;
123 xProp
.Value
>>= nUserListIndex
;
124 CPPUNIT_ASSERT(nUserListIndex
== 0);
129 void XDatabaseRange::testGetFilterDescriptor()
131 uno::Reference
< sheet::XDatabaseRange
> xDBRange( init(OUString("FilterDescriptor")), UNO_QUERY_THROW
);
132 uno::Reference
< uno::XInterface
> xFilterDescr( xDBRange
->getFilterDescriptor(), UNO_QUERY_THROW
);
133 CPPUNIT_ASSERT(xFilterDescr
.is());
136 void XDatabaseRange::testGetImportDescriptor()
138 uno::Reference
< sheet::XDatabaseRange
> xDBRange( init(OUString("ImportDescriptor")), UNO_QUERY_THROW
);
139 uno::Sequence
< beans::PropertyValue
> xImportDescr
= xDBRange
->getImportDescriptor();
142 void XDatabaseRange::testRefresh()
144 uno::Reference
< sheet::XDatabaseRange
> xDBRange( init(OUString("Refresh")), UNO_QUERY_THROW
);
146 const sal_Int32 nCol
= 0;
147 OUString
aHidden("IsVisible");
148 uno::Reference
< sheet::XCellRangeReferrer
> xCellRangeReferrer(xDBRange
, UNO_QUERY_THROW
);
149 uno::Reference
< table::XCellRange
> xCellRange
= xCellRangeReferrer
->getReferredCells();
151 for (sal_Int32 i
= 1; i
< 5; ++i
)
153 uno::Reference
< table::XCell
> xCell
= xCellRange
->getCellByPosition(nCol
, i
);
157 for (sal_Int32 i
= 2; i
< 5; ++i
)
159 uno::Reference
< table::XColumnRowRange
> xColRowRange(xCellRange
, UNO_QUERY_THROW
);
160 uno::Reference
< table::XTableRows
> xRows
= xColRowRange
->getRows();
161 uno::Reference
< table::XCellRange
> xRow(xRows
->getByIndex(i
), UNO_QUERY_THROW
);
162 uno::Reference
< beans::XPropertySet
> xPropRow(xRow
, UNO_QUERY_THROW
);
163 Any aAny
= xPropRow
->getPropertyValue( aHidden
);
165 CPPUNIT_ASSERT(aAny
.get
<sal_Bool
>() == sal_True
);
169 std::cout
<< "after refresh" << std::endl
;
171 for (sal_Int32 i
= 1; i
< 5; ++i
)
173 uno::Reference
< table::XColumnRowRange
> xColRowRange(xCellRange
, UNO_QUERY_THROW
);
174 uno::Reference
< table::XTableRows
> xRows
= xColRowRange
->getRows();
175 uno::Reference
< table::XCellRange
> xRow(xRows
->getByIndex(i
), UNO_QUERY_THROW
);
176 uno::Reference
< beans::XPropertySet
> xPropRow(xRow
, UNO_QUERY_THROW
);
177 Any aAny
= xPropRow
->getPropertyValue( aHidden
);
179 CPPUNIT_ASSERT(aAny
.get
<sal_Bool
>() == sal_False
);
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */