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/extensions/HelperMacros.h"
19 #include <rtl/ustring.hxx>
22 using namespace css::uno
;
26 std::vector
< OUString
> XDataPilotDescriptor::maFieldNames
;
28 void XDataPilotDescriptor::testTag()
30 OUString
aTag("DataPilotDescriptor_Tag");
31 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(), UNO_QUERY_THROW
);
33 OUString aNewTag
= xDescr
->getTag();
34 CPPUNIT_ASSERT( aTag
== aNewTag
);
37 void XDataPilotDescriptor::testSourceRange()
39 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(), UNO_QUERY_THROW
);
40 table::CellRangeAddress aOldAddress
= xDescr
->getSourceRange();
42 table::CellRangeAddress aAddress
;
44 aAddress
.StartColumn
= 1;
45 aAddress
.StartRow
= 1;
46 aAddress
.EndColumn
= 5;
48 xDescr
->setSourceRange(aAddress
);
50 table::CellRangeAddress aReturn
;
51 aReturn
= xDescr
->getSourceRange();
53 CPPUNIT_ASSERT(aAddress
.Sheet
== aReturn
.Sheet
);
54 CPPUNIT_ASSERT(aAddress
.StartColumn
== aReturn
.StartColumn
);
55 CPPUNIT_ASSERT(aAddress
.StartRow
== aReturn
.StartRow
);
56 CPPUNIT_ASSERT(aAddress
.EndColumn
== aReturn
.EndColumn
);
57 CPPUNIT_ASSERT(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
> xDescr
)
72 //this method should only be called once but needs to be called before any of the other tests
73 static bool bCalled
= false;
79 uno::Reference
< container::XIndexAccess
> xIndex(xDescr
->getDataPilotFields(), UNO_QUERY_THROW
);
80 CPPUNIT_ASSERT( xIndex
.is());
82 sal_Int32 nCount
= xIndex
->getCount();
84 OUString
aOrientation("Orientation");
85 for (sal_Int32 i
= 0; i
< nCount
&& i
< 5; ++i
)
87 uno::Reference
< container::XNamed
> xNamed( xIndex
->getByIndex( i
), UNO_QUERY_THROW
);
88 CPPUNIT_ASSERT(xNamed
.is());
89 OUString aName
= xNamed
->getName();
90 maFieldNames
.push_back(aName
);
91 CPPUNIT_ASSERT( aName
!= "Data" );
93 uno::Reference
< beans::XPropertySet
> xPropSet( xNamed
, UNO_QUERY_THROW
);
94 CPPUNIT_ASSERT( xPropSet
.is() );
101 aAny
<<= sheet::DataPilotFieldOrientation_COLUMN
;
102 xPropSet
->setPropertyValue(aOrientation
, aAny
);
108 aAny
<<= sheet::DataPilotFieldOrientation_ROW
;
109 xPropSet
->setPropertyValue(aOrientation
, aAny
);
115 aAny
<<= sheet::DataPilotFieldOrientation_DATA
;
116 xPropSet
->setPropertyValue(aOrientation
, aAny
);
122 aAny
<<= sheet::DataPilotFieldOrientation_HIDDEN
;
123 xPropSet
->setPropertyValue(aOrientation
, aAny
);
129 aAny
<<= sheet::DataPilotFieldOrientation_PAGE
;
130 xPropSet
->setPropertyValue(aOrientation
, aAny
);
137 void XDataPilotDescriptor::testGetDataPilotFields()
139 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(), UNO_QUERY_THROW
);
140 testGetDataPilotFields_Impl( xDescr
);
143 void XDataPilotDescriptor::testGetColumnFields()
145 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(),UNO_QUERY_THROW
);
146 testGetDataPilotFields_Impl( xDescr
);
147 uno::Reference
< container::XIndexAccess
> xIndex(xDescr
->getColumnFields(), UNO_QUERY_THROW
);
149 checkName( xIndex
, 0 );
152 void XDataPilotDescriptor::testGetRowFields()
154 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(),UNO_QUERY_THROW
);
155 testGetDataPilotFields_Impl( xDescr
);
156 uno::Reference
< container::XIndexAccess
> xIndex(xDescr
->getRowFields(), UNO_QUERY_THROW
);
158 //checkName( xIndex, 1 );
161 void XDataPilotDescriptor::testGetPageFields()
163 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(), UNO_QUERY_THROW
);
164 testGetDataPilotFields_Impl( xDescr
);
165 uno::Reference
< container::XIndexAccess
> xIndex(xDescr
->getPageFields(), UNO_QUERY_THROW
);
167 checkName( xIndex
, 4 );
170 void XDataPilotDescriptor::testGetDataFields()
172 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(),UNO_QUERY_THROW
);
173 testGetDataPilotFields_Impl( xDescr
);
174 uno::Reference
< container::XIndexAccess
> xIndex(xDescr
->getDataFields(), UNO_QUERY_THROW
);
176 checkName( xIndex
, 2 );
179 void XDataPilotDescriptor::testGetHiddenFields()
181 std::cout
<< "testGetHiddenFields" <<std::endl
;
182 uno::Reference
< sheet::XDataPilotDescriptor
> xDescr(init(),UNO_QUERY_THROW
);
183 testGetDataPilotFields_Impl( xDescr
);
184 uno::Reference
< container::XIndexAccess
> xIndex(xDescr
->getHiddenFields(), UNO_QUERY_THROW
);
186 checkName( xIndex
, 3 );
189 void XDataPilotDescriptor::checkName( uno::Reference
< container::XIndexAccess
> xIndex
, sal_Int32 nIndex
)
191 CPPUNIT_ASSERT(xIndex
.is());
192 CPPUNIT_ASSERT(maFieldNames
.size() >= static_cast<size_t>(nIndex
));
194 for (sal_Int32 i
= 0; i
< xIndex
->getCount(); ++i
)
196 uno::Reference
< container::XNamed
> xNamed( xIndex
->getByIndex(i
), UNO_QUERY_THROW
);
197 std::cout
<< "Expected: " << maFieldNames
[nIndex
] << " Got: " << xNamed
->getName() << std::endl
;
198 CPPUNIT_ASSERT( xNamed
->getName() == maFieldNames
[nIndex
] );
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */