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/XSubTotalDescriptor.hpp>
13 #include <com/sun/star/beans/PropertyValue.hpp>
14 #include <com/sun/star/sheet/XDatabaseRange.hpp>
15 #include <com/sun/star/table/CellRangeAddress.hpp>
16 #include <com/sun/star/beans/XPropertySet.hpp>
17 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
18 #include <com/sun/star/table/XCell.hpp>
19 #include <com/sun/star/table/XTableRows.hpp>
20 #include <com/sun/star/table/XColumnRowRange.hpp>
22 #include <rtl/ustring.hxx>
23 #include <cppunit/TestAssert.h>
27 using namespace css::uno
;
32 * tests setDataArea and getDataArea
34 void XDatabaseRange::testDataArea()
36 uno::Reference
<sheet::XDatabaseRange
> xDBRange(init("DataArea"), UNO_QUERY_THROW
);
38 table::CellRangeAddress aCellAddress
;
39 aCellAddress
.Sheet
= 0;
40 aCellAddress
.StartColumn
= 1;
41 aCellAddress
.EndColumn
= 4;
42 aCellAddress
.StartRow
= 2;
43 aCellAddress
.EndRow
= 5;
44 xDBRange
->setDataArea(aCellAddress
);
45 table::CellRangeAddress aValue
= xDBRange
->getDataArea();
46 CPPUNIT_ASSERT_EQUAL(aCellAddress
.Sheet
, aValue
.Sheet
);
47 CPPUNIT_ASSERT_EQUAL(aCellAddress
.StartRow
, aValue
.StartRow
);
48 CPPUNIT_ASSERT_EQUAL(aCellAddress
.EndRow
, aValue
.EndRow
);
49 CPPUNIT_ASSERT_EQUAL(aCellAddress
.StartColumn
, aValue
.StartColumn
);
50 CPPUNIT_ASSERT_EQUAL(aCellAddress
.EndColumn
, aValue
.EndColumn
);
53 void XDatabaseRange::testGetSubtotalDescriptor()
55 uno::Reference
<sheet::XDatabaseRange
> xDBRange(init("SubtotalDescriptor"), UNO_QUERY_THROW
);
56 uno::Reference
<sheet::XSubTotalDescriptor
> xSubtotalDescr
= xDBRange
->getSubTotalDescriptor();
57 CPPUNIT_ASSERT(xSubtotalDescr
.is());
60 void XDatabaseRange::testGetSortDescriptor()
62 uno::Reference
<sheet::XDatabaseRange
> xDBRange(init("SortDescriptor"), UNO_QUERY_THROW
);
63 const uno::Sequence
<beans::PropertyValue
> xSortDescr
= xDBRange
->getSortDescriptor();
64 for (const beans::PropertyValue
& aProp
: xSortDescr
)
66 //std::cout << "Prop " << i << " Name: " << OUString(aProp.Name) << std::endl;
68 if (aProp
.Name
== "IsSortColumns")
70 bool bIsSortColumns
= true;
71 aProp
.Value
>>= bIsSortColumns
;
72 CPPUNIT_ASSERT(bIsSortColumns
);
74 else if (aProp
.Name
== "ContainsHeader")
76 bool bContainsHeader
= true;
77 aProp
.Value
>>= bContainsHeader
;
78 CPPUNIT_ASSERT(bContainsHeader
);
80 else if (aProp
.Name
== "MaxFieldCount")
82 sal_Int32 nMaxFieldCount
= 0;
83 aProp
.Value
>>= nMaxFieldCount
;
84 std::cout
<< "Value: " << nMaxFieldCount
<< std::endl
;
86 else if (aProp
.Name
== "SortFields")
89 else if (aProp
.Name
== "BindFormatsToContent")
91 bool bBindFormatsToContent
= false;
92 aProp
.Value
>>= bBindFormatsToContent
;
93 CPPUNIT_ASSERT(bBindFormatsToContent
);
95 else if (aProp
.Name
== "CopyOutputData")
97 bool bCopyOutputData
= true;
98 aProp
.Value
>>= bCopyOutputData
;
99 CPPUNIT_ASSERT(!bCopyOutputData
);
101 else if (aProp
.Name
== "OutputPosition")
104 else if (aProp
.Name
== "IsUserListEnabled")
106 bool bIsUserListEnabled
= true;
107 aProp
.Value
>>= bIsUserListEnabled
;
108 CPPUNIT_ASSERT(!bIsUserListEnabled
);
110 else if (aProp
.Name
== "UserListIndex")
112 sal_Int32 nUserListIndex
= 1;
113 aProp
.Value
>>= nUserListIndex
;
114 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nUserListIndex
);
119 void XDatabaseRange::testGetFilterDescriptor()
121 uno::Reference
<sheet::XDatabaseRange
> xDBRange(init("FilterDescriptor"), UNO_QUERY_THROW
);
122 uno::Reference
<uno::XInterface
> xFilterDescr(xDBRange
->getFilterDescriptor(), UNO_QUERY_THROW
);
125 void XDatabaseRange::testGetImportDescriptor()
127 uno::Reference
<sheet::XDatabaseRange
> xDBRange(init("ImportDescriptor"), UNO_QUERY_THROW
);
128 uno::Sequence
<beans::PropertyValue
> xImportDescr
= xDBRange
->getImportDescriptor();
132 void XDatabaseRange::testRefresh()
134 uno::Reference
<sheet::XDatabaseRange
> xDBRange(init("Refresh"), UNO_QUERY_THROW
);
136 const sal_Int32 nCol
= 0;
137 OUString
aHidden("IsVisible");
138 uno::Reference
<sheet::XCellRangeReferrer
> xCellRangeReferrer(xDBRange
, UNO_QUERY_THROW
);
139 uno::Reference
<table::XCellRange
> xCellRange
= xCellRangeReferrer
->getReferredCells();
141 for (sal_Int32 i
= 1; i
< 5; ++i
)
143 uno::Reference
<table::XCell
> xCell
= xCellRange
->getCellByPosition(nCol
, i
);
147 for (sal_Int32 i
= 2; i
< 5; ++i
)
149 uno::Reference
<table::XColumnRowRange
> xColRowRange(xCellRange
, UNO_QUERY_THROW
);
150 uno::Reference
<table::XTableRows
> xRows
= xColRowRange
->getRows();
151 uno::Reference
<table::XCellRange
> xRow(xRows
->getByIndex(i
), UNO_QUERY_THROW
);
152 uno::Reference
<beans::XPropertySet
> xPropRow(xRow
, UNO_QUERY_THROW
);
153 Any aAny
= xPropRow
->getPropertyValue(aHidden
);
155 CPPUNIT_ASSERT(aAny
.get
<bool>());
159 std::cout
<< "after refresh" << std::endl
;
161 for (sal_Int32 i
= 1; i
< 5; ++i
)
163 uno::Reference
<table::XColumnRowRange
> xColRowRange(xCellRange
, UNO_QUERY_THROW
);
164 uno::Reference
<table::XTableRows
> xRows
= xColRowRange
->getRows();
165 uno::Reference
<table::XCellRange
> xRow(xRows
->getByIndex(i
), UNO_QUERY_THROW
);
166 uno::Reference
<beans::XPropertySet
> xPropRow(xRow
, UNO_QUERY_THROW
);
167 Any aAny
= xPropRow
->getPropertyValue(aHidden
);
169 CPPUNIT_ASSERT(!aAny
.get
<bool>());
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */