Branch data 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/oustringostreaminserter.hxx>
39 : :
40 : : using namespace com::sun::star::uno;
41 : :
42 : : namespace apitest {
43 : :
44 : 22 : std::vector< rtl::OUString > XDataPilotDescriptor::maFieldNames;
45 : :
46 : 2 : void XDataPilotDescriptor::testTag()
47 : : {
48 [ + - ]: 2 : rtl::OUString aTag(RTL_CONSTASCII_USTRINGPARAM("DataPilotDescriptor_Tag"));
49 [ + - ][ + - ]: 2 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
50 [ + - ][ + - ]: 2 : xDescr->setTag(aTag);
51 [ + - ][ + - ]: 2 : rtl::OUString aNewTag = xDescr->getTag();
52 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT( aTag == aNewTag );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
53 : 2 : }
54 : :
55 : 2 : void XDataPilotDescriptor::testSourceRange()
56 : : {
57 [ + - ][ + - ]: 2 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
58 [ + - ][ + - ]: 2 : table::CellRangeAddress aOldAddress = xDescr->getSourceRange();
59 : :
60 : 2 : table::CellRangeAddress aAddress;
61 : 2 : aAddress.Sheet = 1;
62 : 2 : aAddress.StartColumn = 1;
63 : 2 : aAddress.StartRow = 1;
64 : 2 : aAddress.EndColumn = 5;
65 : 2 : aAddress.EndRow = 5;
66 [ + - ][ + - ]: 2 : xDescr->setSourceRange(aAddress);
67 : :
68 : 2 : table::CellRangeAddress aReturn;
69 [ + - ][ + - ]: 2 : aReturn = xDescr->getSourceRange();
70 : :
71 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT(aAddress.Sheet == aReturn.Sheet);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
72 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT(aAddress.StartColumn == aReturn.StartColumn);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
73 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT(aAddress.StartRow == aReturn.StartRow);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
74 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT(aAddress.EndColumn == aReturn.EndColumn);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
75 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT(aAddress.EndRow == aReturn.EndRow);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
76 : :
77 : : //restore old settings
78 [ + - ][ + - ]: 2 : xDescr->setSourceRange(aOldAddress);
79 : 2 : }
80 : :
81 : 2 : void XDataPilotDescriptor::testGetFilterDescriptor()
82 : : {
83 [ + - ][ + - ]: 2 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
84 [ + - ][ + - ]: 2 : uno::Reference< sheet::XSheetFilterDescriptor > xSheetFilterDescr = xDescr->getFilterDescriptor();
85 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT(xSheetFilterDescr.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
86 : 2 : }
87 : :
88 : 10 : 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 [ + + ]: 10 : if (bCalled)
93 : 10 : return;
94 : : else
95 : 2 : bCalled = true;
96 : :
97 [ + - ][ + - ]: 2 : uno::Reference< container::XIndexAccess > xIndex(xDescr->getDataPilotFields(), UNO_QUERY_THROW);
[ + - ]
98 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT( xIndex.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
99 : :
100 [ + - ][ + - ]: 2 : sal_Int32 nCount = xIndex->getCount();
101 : :
102 [ + - ]: 2 : rtl::OUString aOrientation(RTL_CONSTASCII_USTRINGPARAM("Orientation"));
103 [ + - ][ + + ]: 12 : for (sal_Int32 i = 0; i < nCount && i < 5; ++i)
[ + + ]
104 : : {
105 [ + - ][ + - ]: 10 : uno::Reference< container::XNamed > xNamed( xIndex->getByIndex( i ), UNO_QUERY_THROW);
[ + - ]
106 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT(xNamed.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
107 [ + - ][ + - ]: 10 : rtl::OUString aName = xNamed->getName();
108 [ + - ]: 10 : maFieldNames.push_back(aName);
109 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( aName != "Data" );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
110 : :
111 [ + - ]: 10 : uno::Reference< beans::XPropertySet > xPropSet( xNamed, UNO_QUERY_THROW);
112 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT( xPropSet.is() );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
113 : :
114 [ + + + + : 10 : switch ( i % 5 )
+ - ]
115 : : {
116 : : case 0:
117 : : {
118 : 2 : uno::Any aAny;
119 [ + - ]: 2 : aAny<<= sheet::DataPilotFieldOrientation_COLUMN;
120 [ + - ][ + - ]: 2 : xPropSet->setPropertyValue(aOrientation, aAny);
121 : : }
122 : 2 : break;
123 : : case 1:
124 : : {
125 : 2 : uno::Any aAny;
126 [ + - ]: 2 : aAny<<= sheet::DataPilotFieldOrientation_ROW;
127 [ + - ][ + - ]: 2 : xPropSet->setPropertyValue(aOrientation, aAny);
128 : : }
129 : 2 : break;
130 : : case 2:
131 : : {
132 : 2 : uno::Any aAny;
133 [ + - ]: 2 : aAny<<= sheet::DataPilotFieldOrientation_DATA;
134 [ + - ][ + - ]: 2 : xPropSet->setPropertyValue(aOrientation, aAny);
135 : : }
136 : 2 : break;
137 : : case 3:
138 : : {
139 : 2 : uno::Any aAny;
140 [ + - ]: 2 : aAny<<= sheet::DataPilotFieldOrientation_HIDDEN;
141 [ + - ][ + - ]: 2 : xPropSet->setPropertyValue(aOrientation, aAny);
142 : : }
143 : 2 : break;
144 : : case 4:
145 : : {
146 : 2 : uno::Any aAny;
147 [ + - ]: 2 : aAny<<= sheet::DataPilotFieldOrientation_PAGE;
148 [ + - ][ + - ]: 2 : xPropSet->setPropertyValue(aOrientation, aAny);
149 : : }
150 : 2 : break;
151 : : default:
152 : 0 : break;
153 : : }
154 : 20 : }
155 : : }
156 : :
157 : 2 : void XDataPilotDescriptor::testGetDataPilotFields()
158 : : {
159 [ + - ][ + - ]: 2 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
160 [ + - ]: 2 : testGetDataPilotFields_Impl( xDescr );
161 : 2 : }
162 : :
163 : 2 : void XDataPilotDescriptor::testGetColumnFields()
164 : : {
165 [ + - ][ + - ]: 2 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
166 [ + - ]: 2 : testGetDataPilotFields_Impl( xDescr );
167 [ + - ][ + - ]: 2 : uno::Reference< container::XIndexAccess > xIndex(xDescr->getColumnFields(), UNO_QUERY_THROW);
[ + - ]
168 : :
169 [ + - ]: 2 : checkName( xIndex, 0 );
170 : 2 : }
171 : :
172 : 2 : void XDataPilotDescriptor::testGetRowFields()
173 : : {
174 [ + - ][ + - ]: 2 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
175 [ + - ]: 2 : testGetDataPilotFields_Impl( xDescr );
176 [ + - ][ + - ]: 2 : uno::Reference< container::XIndexAccess > xIndex(xDescr->getRowFields(), UNO_QUERY_THROW);
[ + - ]
177 : :
178 : : //checkName( xIndex, 1 );
179 : 2 : }
180 : :
181 : 2 : void XDataPilotDescriptor::testGetPageFields()
182 : : {
183 [ + - ][ + - ]: 2 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
184 [ + - ]: 2 : testGetDataPilotFields_Impl( xDescr );
185 [ + - ][ + - ]: 2 : uno::Reference< container::XIndexAccess > xIndex(xDescr->getPageFields(), UNO_QUERY_THROW);
[ + - ]
186 : :
187 [ + - ]: 2 : checkName( xIndex, 4 );
188 : 2 : }
189 : :
190 : 2 : void XDataPilotDescriptor::testGetDataFields()
191 : : {
192 [ + - ][ + - ]: 2 : uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
193 [ + - ]: 2 : testGetDataPilotFields_Impl( xDescr );
194 [ + - ][ + - ]: 2 : uno::Reference< container::XIndexAccess > xIndex(xDescr->getDataFields(), UNO_QUERY_THROW);
[ + - ]
195 : :
196 [ + - ]: 2 : checkName( xIndex, 2 );
197 : 2 : }
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 : 6 : void XDataPilotDescriptor::checkName( uno::Reference< container::XIndexAccess > xIndex, sal_Int32 nIndex )
210 : : {
211 [ + - ][ + - ]: 6 : CPPUNIT_ASSERT(xIndex.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
212 [ + - ][ + - ]: 6 : CPPUNIT_ASSERT(maFieldNames.size() >= static_cast<size_t>(nIndex));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
213 : :
214 [ + + ]: 12 : for (sal_Int32 i = 0; i < xIndex->getCount(); ++i)
215 : : {
216 [ + - ][ + - ]: 6 : uno::Reference< container::XNamed > xNamed( xIndex->getByIndex(i), UNO_QUERY_THROW);
[ + - ]
217 [ + - ][ + - ]: 6 : std::cout << "Expected: " << maFieldNames[nIndex] << " Got: " << xNamed->getName() << std::endl;
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
218 [ + - ][ + - ]: 6 : CPPUNIT_ASSERT( xNamed->getName() == maFieldNames[nIndex] );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
219 : 6 : }
220 : 6 : }
221 : :
222 [ + - ][ + - ]: 66 : }
223 : :
224 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|