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/xdatapilotdescriptor.hxx>
12 #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
13 #include <com/sun/star/table/CellRangeAddress.hpp>
14 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
15 #include <com/sun/star/beans/XPropertySet.hpp>
17 #include <cppunit/TestAssert.h>
19 #include <o3tl/safeint.hxx>
20 #include <rtl/ustring.hxx>
23 using namespace css::uno
;
27 std::vector
< OUString
> XDataPilotDescriptor::maFieldNames
;
29 void XDataPilotDescriptor::testTag()
31 OUString
aTag("DataPilotDescriptor_Tag");
32 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(), UNO_QUERY_THROW
);
34 OUString aNewTag
= xDescr
->getTag();
35 CPPUNIT_ASSERT_EQUAL( aTag
, aNewTag
);
38 void XDataPilotDescriptor::testSourceRange()
40 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(), UNO_QUERY_THROW
);
41 table::CellRangeAddress aOldAddress
= xDescr
->getSourceRange();
43 table::CellRangeAddress aAddress
;
45 aAddress
.StartColumn
= 1;
46 aAddress
.StartRow
= 1;
47 aAddress
.EndColumn
= 5;
49 xDescr
->setSourceRange(aAddress
);
51 table::CellRangeAddress aReturn
= xDescr
->getSourceRange();
53 CPPUNIT_ASSERT_EQUAL(aAddress
.Sheet
, aReturn
.Sheet
);
54 CPPUNIT_ASSERT_EQUAL(aAddress
.StartColumn
, aReturn
.StartColumn
);
55 CPPUNIT_ASSERT_EQUAL(aAddress
.StartRow
, aReturn
.StartRow
);
56 CPPUNIT_ASSERT_EQUAL(aAddress
.EndColumn
, aReturn
.EndColumn
);
57 CPPUNIT_ASSERT_EQUAL(aAddress
.EndRow
, aReturn
.EndRow
);
59 //restore old settings
60 xDescr
->setSourceRange(aOldAddress
);
63 void XDataPilotDescriptor::testGetFilterDescriptor()
65 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(), UNO_QUERY_THROW
);
66 uno::Reference
< sheet::XSheetFilterDescriptor
> xSheetFilterDescr
= xDescr
->getFilterDescriptor();
67 CPPUNIT_ASSERT(xSheetFilterDescr
.is());
70 void XDataPilotDescriptor::testGetDataPilotFields_Impl( uno::Reference
< sheet::XDataPilotDescriptor
> const & xDescr
)
72 uno::Reference
< container::XIndexAccess
> xIndex(xDescr
->getDataPilotFields(), UNO_SET_THROW
);
74 sal_Int32 nCount
= xIndex
->getCount();
76 OUString
aOrientation("Orientation");
77 for (sal_Int32 i
= 0; i
< nCount
&& i
< 5; ++i
)
79 uno::Reference
< container::XNamed
> xNamed( xIndex
->getByIndex( i
), UNO_QUERY_THROW
);
80 OUString aName
= xNamed
->getName();
81 maFieldNames
.push_back(aName
);
82 CPPUNIT_ASSERT( aName
!= "Data" );
84 uno::Reference
< beans::XPropertySet
> xPropSet( xNamed
, UNO_QUERY_THROW
);
91 aAny
<<= sheet::DataPilotFieldOrientation_COLUMN
;
92 xPropSet
->setPropertyValue(aOrientation
, aAny
);
98 aAny
<<= sheet::DataPilotFieldOrientation_ROW
;
99 xPropSet
->setPropertyValue(aOrientation
, aAny
);
105 aAny
<<= sheet::DataPilotFieldOrientation_DATA
;
106 xPropSet
->setPropertyValue(aOrientation
, aAny
);
112 aAny
<<= sheet::DataPilotFieldOrientation_HIDDEN
;
113 xPropSet
->setPropertyValue(aOrientation
, aAny
);
119 aAny
<<= sheet::DataPilotFieldOrientation_PAGE
;
120 xPropSet
->setPropertyValue(aOrientation
, aAny
);
127 void XDataPilotDescriptor::testGetDataPilotFields()
129 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(), UNO_QUERY_THROW
);
130 testGetDataPilotFields_Impl( xDescr
);
133 void XDataPilotDescriptor::testGetColumnFields()
135 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(),UNO_QUERY_THROW
);
136 testGetDataPilotFields_Impl( xDescr
);
137 uno::Reference
< container::XIndexAccess
> xIndex(xDescr
->getColumnFields(), UNO_SET_THROW
);
139 checkName( xIndex
, 0 );
142 void XDataPilotDescriptor::testGetRowFields()
144 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(),UNO_QUERY_THROW
);
145 testGetDataPilotFields_Impl( xDescr
);
146 uno::Reference
< container::XIndexAccess
> xIndex(xDescr
->getRowFields(), UNO_SET_THROW
);
148 //checkName( xIndex, 1 );
151 void XDataPilotDescriptor::testGetPageFields()
153 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(), UNO_QUERY_THROW
);
154 testGetDataPilotFields_Impl( xDescr
);
155 uno::Reference
< container::XIndexAccess
> xIndex(xDescr
->getPageFields(), UNO_SET_THROW
);
157 checkName( xIndex
, 4 );
160 void XDataPilotDescriptor::testGetDataFields()
162 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(),UNO_QUERY_THROW
);
163 testGetDataPilotFields_Impl( xDescr
);
164 uno::Reference
< container::XIndexAccess
> xIndex(xDescr
->getDataFields(), UNO_SET_THROW
);
166 checkName( xIndex
, 2 );
169 void XDataPilotDescriptor::testGetHiddenFields()
171 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(),UNO_QUERY_THROW
);
172 testGetDataPilotFields_Impl( xDescr
);
173 uno::Reference
< container::XIndexAccess
> xIndex(xDescr
->getHiddenFields(), UNO_SET_THROW
);
175 checkName( xIndex
, 3 );
178 void XDataPilotDescriptor::checkName( uno::Reference
< container::XIndexAccess
> const & xIndex
, sal_Int32 nIndex
)
180 CPPUNIT_ASSERT(xIndex
.is());
181 CPPUNIT_ASSERT(maFieldNames
.size() >= o3tl::make_unsigned(nIndex
));
183 for (sal_Int32 i
= 0; i
< xIndex
->getCount(); ++i
)
185 uno::Reference
< container::XNamed
> xNamed( xIndex
->getByIndex(i
), UNO_QUERY_THROW
);
186 CPPUNIT_ASSERT_EQUAL(maFieldNames
[nIndex
], xNamed
->getName());
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */