Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / test / source / sheet / xdatapilotdescriptor.cxx
blobd6bb683511a33204d2220466ec888679cf75fe9d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License or as specified alternatively below. You may obtain a copy of
8 * the License at http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * Major Contributor(s):
16 * Copyright (C) 2012 Markus Mohrhard <markus.mohrhard@googlemail.com> (initial developer)
18 * All Rights Reserved.
20 * For minor contributions see the git repository.
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 * instead of those above.
29 #include "test/sheet/xdatapilotdescriptor.hxx"
31 #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
32 #include <com/sun/star/table/CellRangeAddress.hpp>
33 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include "cppunit/extensions/HelperMacros.h"
38 #include <rtl/ustring.hxx>
40 using namespace com::sun::star::uno;
42 namespace apitest {
44 std::vector< rtl::OUString > XDataPilotDescriptor::maFieldNames;
46 void XDataPilotDescriptor::testTag()
48 rtl::OUString aTag(RTL_CONSTASCII_USTRINGPARAM("DataPilotDescriptor_Tag"));
49 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
50 xDescr->setTag(aTag);
51 rtl::OUString aNewTag = xDescr->getTag();
52 CPPUNIT_ASSERT( aTag == aNewTag );
55 void XDataPilotDescriptor::testSourceRange()
57 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
58 table::CellRangeAddress aOldAddress = xDescr->getSourceRange();
60 table::CellRangeAddress aAddress;
61 aAddress.Sheet = 1;
62 aAddress.StartColumn = 1;
63 aAddress.StartRow = 1;
64 aAddress.EndColumn = 5;
65 aAddress.EndRow = 5;
66 xDescr->setSourceRange(aAddress);
68 table::CellRangeAddress aReturn;
69 aReturn = xDescr->getSourceRange();
71 CPPUNIT_ASSERT(aAddress.Sheet == aReturn.Sheet);
72 CPPUNIT_ASSERT(aAddress.StartColumn == aReturn.StartColumn);
73 CPPUNIT_ASSERT(aAddress.StartRow == aReturn.StartRow);
74 CPPUNIT_ASSERT(aAddress.EndColumn == aReturn.EndColumn);
75 CPPUNIT_ASSERT(aAddress.EndRow == aReturn.EndRow);
77 //restore old settings
78 xDescr->setSourceRange(aOldAddress);
81 void XDataPilotDescriptor::testGetFilterDescriptor()
83 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
84 uno::Reference< sheet::XSheetFilterDescriptor > xSheetFilterDescr = xDescr->getFilterDescriptor();
85 CPPUNIT_ASSERT(xSheetFilterDescr.is());
88 void XDataPilotDescriptor::testGetDataPilotFields_Impl( uno::Reference< sheet::XDataPilotDescriptor > xDescr)
90 //this method should only be called once but needs to be called before any of the other tests
91 static bool bCalled = false;
92 if (bCalled)
93 return;
94 else
95 bCalled = true;
97 uno::Reference< container::XIndexAccess > xIndex(xDescr->getDataPilotFields(), UNO_QUERY_THROW);
98 CPPUNIT_ASSERT( xIndex.is());
100 sal_Int32 nCount = xIndex->getCount();
102 rtl::OUString aOrientation(RTL_CONSTASCII_USTRINGPARAM("Orientation"));
103 for (sal_Int32 i = 0; i < nCount && i < 5; ++i)
105 uno::Reference< container::XNamed > xNamed( xIndex->getByIndex( i ), UNO_QUERY_THROW);
106 CPPUNIT_ASSERT(xNamed.is());
107 rtl::OUString aName = xNamed->getName();
108 maFieldNames.push_back(aName);
109 CPPUNIT_ASSERT( aName != "Data" );
111 uno::Reference< beans::XPropertySet > xPropSet( xNamed, UNO_QUERY_THROW);
112 CPPUNIT_ASSERT( xPropSet.is() );
114 switch ( i % 5 )
116 case 0:
118 uno::Any aAny;
119 aAny<<= sheet::DataPilotFieldOrientation_COLUMN;
120 xPropSet->setPropertyValue(aOrientation, aAny);
122 break;
123 case 1:
125 uno::Any aAny;
126 aAny<<= sheet::DataPilotFieldOrientation_ROW;
127 xPropSet->setPropertyValue(aOrientation, aAny);
129 break;
130 case 2:
132 uno::Any aAny;
133 aAny<<= sheet::DataPilotFieldOrientation_DATA;
134 xPropSet->setPropertyValue(aOrientation, aAny);
136 break;
137 case 3:
139 uno::Any aAny;
140 aAny<<= sheet::DataPilotFieldOrientation_HIDDEN;
141 xPropSet->setPropertyValue(aOrientation, aAny);
143 break;
144 case 4:
146 uno::Any aAny;
147 aAny<<= sheet::DataPilotFieldOrientation_PAGE;
148 xPropSet->setPropertyValue(aOrientation, aAny);
150 break;
151 default:
152 break;
157 void XDataPilotDescriptor::testGetDataPilotFields()
159 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
160 testGetDataPilotFields_Impl( xDescr );
163 void XDataPilotDescriptor::testGetColumnFields()
165 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
166 testGetDataPilotFields_Impl( xDescr );
167 uno::Reference< container::XIndexAccess > xIndex(xDescr->getColumnFields(), UNO_QUERY_THROW);
169 checkName( xIndex, 0 );
172 void XDataPilotDescriptor::testGetRowFields()
174 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
175 testGetDataPilotFields_Impl( xDescr );
176 uno::Reference< container::XIndexAccess > xIndex(xDescr->getRowFields(), UNO_QUERY_THROW);
178 //checkName( xIndex, 1 );
181 void XDataPilotDescriptor::testGetPageFields()
183 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
184 testGetDataPilotFields_Impl( xDescr );
185 uno::Reference< container::XIndexAccess > xIndex(xDescr->getPageFields(), UNO_QUERY_THROW);
187 checkName( xIndex, 4 );
190 void XDataPilotDescriptor::testGetDataFields()
192 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
193 testGetDataPilotFields_Impl( xDescr );
194 uno::Reference< container::XIndexAccess > xIndex(xDescr->getDataFields(), UNO_QUERY_THROW);
196 checkName( xIndex, 2 );
199 void XDataPilotDescriptor::testGetHiddenFields()
201 std::cout << "testGetHiddenFields" <<std::endl;
202 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);;
203 testGetDataPilotFields_Impl( xDescr );
204 uno::Reference< container::XIndexAccess > xIndex(xDescr->getHiddenFields(), UNO_QUERY_THROW);
206 checkName( xIndex, 3 );
209 void XDataPilotDescriptor::checkName( uno::Reference< container::XIndexAccess > xIndex, sal_Int32 nIndex )
211 CPPUNIT_ASSERT(xIndex.is());
212 CPPUNIT_ASSERT(maFieldNames.size() >= static_cast<size_t>(nIndex));
214 for (sal_Int32 i = 0; i < xIndex->getCount(); ++i)
216 uno::Reference< container::XNamed > xNamed( xIndex->getByIndex(i), UNO_QUERY_THROW);
217 std::cout << "Expected: " << maFieldNames[nIndex] << " Got: " << xNamed->getName() << std::endl;
218 CPPUNIT_ASSERT( xNamed->getName() == maFieldNames[nIndex] );
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */