Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
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/
9 : *
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.
14 : *
15 : * Major Contributor(s):
16 : * Copyright (C) 2012 Markus Mohrhard <markus.mohrhard@googlemail.com> (initial developer)
17 : *
18 : * All Rights Reserved.
19 : *
20 : * For minor contributions see the git repository.
21 : *
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.
27 : */
28 :
29 : #include "test/sheet/xdatapilotdescriptor.hxx"
30 :
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>
35 :
36 : #include "cppunit/extensions/HelperMacros.h"
37 :
38 : #include <rtl/ustring.hxx>
39 :
40 : using namespace com::sun::star::uno;
41 :
42 : namespace apitest {
43 :
44 0 : std::vector< rtl::OUString > XDataPilotDescriptor::maFieldNames;
45 :
46 0 : void XDataPilotDescriptor::testTag()
47 : {
48 0 : rtl::OUString aTag(RTL_CONSTASCII_USTRINGPARAM("DataPilotDescriptor_Tag"));
49 0 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
50 0 : xDescr->setTag(aTag);
51 0 : rtl::OUString aNewTag = xDescr->getTag();
52 0 : CPPUNIT_ASSERT( aTag == aNewTag );
53 0 : }
54 :
55 0 : void XDataPilotDescriptor::testSourceRange()
56 : {
57 0 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
58 0 : table::CellRangeAddress aOldAddress = xDescr->getSourceRange();
59 :
60 0 : table::CellRangeAddress aAddress;
61 0 : aAddress.Sheet = 1;
62 0 : aAddress.StartColumn = 1;
63 0 : aAddress.StartRow = 1;
64 0 : aAddress.EndColumn = 5;
65 0 : aAddress.EndRow = 5;
66 0 : xDescr->setSourceRange(aAddress);
67 :
68 0 : table::CellRangeAddress aReturn;
69 0 : aReturn = xDescr->getSourceRange();
70 :
71 0 : CPPUNIT_ASSERT(aAddress.Sheet == aReturn.Sheet);
72 0 : CPPUNIT_ASSERT(aAddress.StartColumn == aReturn.StartColumn);
73 0 : CPPUNIT_ASSERT(aAddress.StartRow == aReturn.StartRow);
74 0 : CPPUNIT_ASSERT(aAddress.EndColumn == aReturn.EndColumn);
75 0 : CPPUNIT_ASSERT(aAddress.EndRow == aReturn.EndRow);
76 :
77 : //restore old settings
78 0 : xDescr->setSourceRange(aOldAddress);
79 0 : }
80 :
81 0 : void XDataPilotDescriptor::testGetFilterDescriptor()
82 : {
83 0 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
84 0 : uno::Reference< sheet::XSheetFilterDescriptor > xSheetFilterDescr = xDescr->getFilterDescriptor();
85 0 : CPPUNIT_ASSERT(xSheetFilterDescr.is());
86 0 : }
87 :
88 0 : void XDataPilotDescriptor::testGetDataPilotFields_Impl( uno::Reference< sheet::XDataPilotDescriptor > xDescr)
89 : {
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 0 : if (bCalled)
93 0 : return;
94 : else
95 0 : bCalled = true;
96 :
97 0 : uno::Reference< container::XIndexAccess > xIndex(xDescr->getDataPilotFields(), UNO_QUERY_THROW);
98 0 : CPPUNIT_ASSERT( xIndex.is());
99 :
100 0 : sal_Int32 nCount = xIndex->getCount();
101 :
102 0 : rtl::OUString aOrientation(RTL_CONSTASCII_USTRINGPARAM("Orientation"));
103 0 : for (sal_Int32 i = 0; i < nCount && i < 5; ++i)
104 : {
105 0 : uno::Reference< container::XNamed > xNamed( xIndex->getByIndex( i ), UNO_QUERY_THROW);
106 0 : CPPUNIT_ASSERT(xNamed.is());
107 0 : rtl::OUString aName = xNamed->getName();
108 0 : maFieldNames.push_back(aName);
109 0 : CPPUNIT_ASSERT( aName != "Data" );
110 :
111 0 : uno::Reference< beans::XPropertySet > xPropSet( xNamed, UNO_QUERY_THROW);
112 0 : CPPUNIT_ASSERT( xPropSet.is() );
113 :
114 0 : switch ( i % 5 )
115 : {
116 : case 0:
117 : {
118 0 : uno::Any aAny;
119 0 : aAny<<= sheet::DataPilotFieldOrientation_COLUMN;
120 0 : xPropSet->setPropertyValue(aOrientation, aAny);
121 : }
122 0 : break;
123 : case 1:
124 : {
125 0 : uno::Any aAny;
126 0 : aAny<<= sheet::DataPilotFieldOrientation_ROW;
127 0 : xPropSet->setPropertyValue(aOrientation, aAny);
128 : }
129 0 : break;
130 : case 2:
131 : {
132 0 : uno::Any aAny;
133 0 : aAny<<= sheet::DataPilotFieldOrientation_DATA;
134 0 : xPropSet->setPropertyValue(aOrientation, aAny);
135 : }
136 0 : break;
137 : case 3:
138 : {
139 0 : uno::Any aAny;
140 0 : aAny<<= sheet::DataPilotFieldOrientation_HIDDEN;
141 0 : xPropSet->setPropertyValue(aOrientation, aAny);
142 : }
143 0 : break;
144 : case 4:
145 : {
146 0 : uno::Any aAny;
147 0 : aAny<<= sheet::DataPilotFieldOrientation_PAGE;
148 0 : xPropSet->setPropertyValue(aOrientation, aAny);
149 : }
150 0 : break;
151 : default:
152 0 : break;
153 : }
154 0 : }
155 : }
156 :
157 0 : void XDataPilotDescriptor::testGetDataPilotFields()
158 : {
159 0 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
160 0 : testGetDataPilotFields_Impl( xDescr );
161 0 : }
162 :
163 0 : void XDataPilotDescriptor::testGetColumnFields()
164 : {
165 0 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
166 0 : testGetDataPilotFields_Impl( xDescr );
167 0 : uno::Reference< container::XIndexAccess > xIndex(xDescr->getColumnFields(), UNO_QUERY_THROW);
168 :
169 0 : checkName( xIndex, 0 );
170 0 : }
171 :
172 0 : void XDataPilotDescriptor::testGetRowFields()
173 : {
174 0 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
175 0 : testGetDataPilotFields_Impl( xDescr );
176 0 : uno::Reference< container::XIndexAccess > xIndex(xDescr->getRowFields(), UNO_QUERY_THROW);
177 :
178 : //checkName( xIndex, 1 );
179 0 : }
180 :
181 0 : void XDataPilotDescriptor::testGetPageFields()
182 : {
183 0 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
184 0 : testGetDataPilotFields_Impl( xDescr );
185 0 : uno::Reference< container::XIndexAccess > xIndex(xDescr->getPageFields(), UNO_QUERY_THROW);
186 :
187 0 : checkName( xIndex, 4 );
188 0 : }
189 :
190 0 : void XDataPilotDescriptor::testGetDataFields()
191 : {
192 0 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
193 0 : testGetDataPilotFields_Impl( xDescr );
194 0 : uno::Reference< container::XIndexAccess > xIndex(xDescr->getDataFields(), UNO_QUERY_THROW);
195 :
196 0 : checkName( xIndex, 2 );
197 0 : }
198 :
199 0 : void XDataPilotDescriptor::testGetHiddenFields()
200 : {
201 0 : std::cout << "testGetHiddenFields" <<std::endl;
202 0 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);;
203 0 : testGetDataPilotFields_Impl( xDescr );
204 0 : uno::Reference< container::XIndexAccess > xIndex(xDescr->getHiddenFields(), UNO_QUERY_THROW);
205 :
206 0 : checkName( xIndex, 3 );
207 0 : }
208 :
209 0 : void XDataPilotDescriptor::checkName( uno::Reference< container::XIndexAccess > xIndex, sal_Int32 nIndex )
210 : {
211 0 : CPPUNIT_ASSERT(xIndex.is());
212 0 : CPPUNIT_ASSERT(maFieldNames.size() >= static_cast<size_t>(nIndex));
213 :
214 0 : for (sal_Int32 i = 0; i < xIndex->getCount(); ++i)
215 : {
216 0 : uno::Reference< container::XNamed > xNamed( xIndex->getByIndex(i), UNO_QUERY_THROW);
217 0 : std::cout << "Expected: " << maFieldNames[nIndex] << " Got: " << xNamed->getName() << std::endl;
218 0 : CPPUNIT_ASSERT( xNamed->getName() == maFieldNames[nIndex] );
219 0 : }
220 0 : }
221 :
222 0 : }
223 :
224 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|