LibreOffice Module test (master) 1
xdatapilotdescriptor.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
11
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>
16
17#include <cppunit/TestAssert.h>
18
19#include <rtl/ustring.hxx>
20
21using namespace css;
22using namespace css::uno;
23
24namespace apitest {
25
26std::vector< OUString > XDataPilotDescriptor::maFieldNames;
27
29{
30 OUString aTag("DataPilotDescriptor_Tag");
31 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
32 xDescr->setTag(aTag);
33 OUString aNewTag = xDescr->getTag();
34 CPPUNIT_ASSERT_EQUAL( aTag, aNewTag );
35}
36
38{
39 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
40 table::CellRangeAddress aOldAddress = xDescr->getSourceRange();
41
42 table::CellRangeAddress aAddress;
43 aAddress.Sheet = 1;
44 aAddress.StartColumn = 1;
45 aAddress.StartRow = 1;
46 aAddress.EndColumn = 5;
47 aAddress.EndRow = 5;
48 xDescr->setSourceRange(aAddress);
49
50 table::CellRangeAddress aReturn = xDescr->getSourceRange();
51
52 CPPUNIT_ASSERT_EQUAL(aAddress.Sheet, aReturn.Sheet);
53 CPPUNIT_ASSERT_EQUAL(aAddress.StartColumn, aReturn.StartColumn);
54 CPPUNIT_ASSERT_EQUAL(aAddress.StartRow, aReturn.StartRow);
55 CPPUNIT_ASSERT_EQUAL(aAddress.EndColumn, aReturn.EndColumn);
56 CPPUNIT_ASSERT_EQUAL(aAddress.EndRow, aReturn.EndRow);
57
58 //restore old settings
59 xDescr->setSourceRange(aOldAddress);
60}
61
63{
64 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
65 uno::Reference< sheet::XSheetFilterDescriptor > xSheetFilterDescr = xDescr->getFilterDescriptor();
66 CPPUNIT_ASSERT(xSheetFilterDescr.is());
67}
68
69void XDataPilotDescriptor::testGetDataPilotFields_Impl( uno::Reference< sheet::XDataPilotDescriptor > const & xDescr)
70{
71 uno::Reference< container::XIndexAccess > xIndex(xDescr->getDataPilotFields(), UNO_SET_THROW);
72
73 sal_Int32 nCount = xIndex->getCount();
74
75 OUString aOrientation("Orientation");
76 for (sal_Int32 i = 0; i < nCount && i < 5; ++i)
77 {
78 uno::Reference< container::XNamed > xNamed( xIndex->getByIndex( i ), UNO_QUERY_THROW);
79 OUString aName = xNamed->getName();
80 maFieldNames.push_back(aName);
81 CPPUNIT_ASSERT( aName != "Data" );
82
83 uno::Reference< beans::XPropertySet > xPropSet( xNamed, UNO_QUERY_THROW);
84
85 switch ( i % 5 )
86 {
87 case 0:
88 {
89 uno::Any aAny;
90 aAny<<= sheet::DataPilotFieldOrientation_COLUMN;
91 xPropSet->setPropertyValue(aOrientation, aAny);
92 }
93 break;
94 case 1:
95 {
96 uno::Any aAny;
97 aAny<<= sheet::DataPilotFieldOrientation_ROW;
98 xPropSet->setPropertyValue(aOrientation, aAny);
99 }
100 break;
101 case 2:
102 {
103 uno::Any aAny;
104 aAny<<= sheet::DataPilotFieldOrientation_DATA;
105 xPropSet->setPropertyValue(aOrientation, aAny);
106 }
107 break;
108 case 3:
109 {
110 uno::Any aAny;
111 aAny<<= sheet::DataPilotFieldOrientation_HIDDEN;
112 xPropSet->setPropertyValue(aOrientation, aAny);
113 }
114 break;
115 case 4:
116 {
117 uno::Any aAny;
118 aAny<<= sheet::DataPilotFieldOrientation_PAGE;
119 xPropSet->setPropertyValue(aOrientation, aAny);
120 }
121 break;
122 }
123 }
124}
125
127{
128 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
130}
131
133{
134 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
136 uno::Reference< container::XIndexAccess > xIndex(xDescr->getColumnFields(), UNO_SET_THROW);
137
138 checkName( xIndex, 0 );
139}
140
142{
143 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
145 uno::Reference< container::XIndexAccess > xIndex(xDescr->getRowFields(), UNO_SET_THROW);
146
147 //checkName( xIndex, 1 );
148}
149
151{
152 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
154 uno::Reference< container::XIndexAccess > xIndex(xDescr->getPageFields(), UNO_SET_THROW);
155
156 checkName( xIndex, 4 );
157}
158
160{
161 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
163 uno::Reference< container::XIndexAccess > xIndex(xDescr->getDataFields(), UNO_SET_THROW);
164
165 checkName( xIndex, 2 );
166}
167
169{
170 uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
172 uno::Reference< container::XIndexAccess > xIndex(xDescr->getHiddenFields(), UNO_SET_THROW);
173
174 checkName( xIndex, 3 );
175}
176
177void XDataPilotDescriptor::checkName( uno::Reference< container::XIndexAccess > const & xIndex, std::size_t nIndex )
178{
179 CPPUNIT_ASSERT(xIndex.is());
180 CPPUNIT_ASSERT(maFieldNames.size() >= nIndex);
181
182 for (sal_Int32 i = 0; i < xIndex->getCount(); ++i)
183 {
184 uno::Reference< container::XNamed > xNamed( xIndex->getByIndex(i), UNO_QUERY_THROW);
185 CPPUNIT_ASSERT_EQUAL(maFieldNames[nIndex], xNamed->getName());
186 }
187}
188
189}
190
191/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void checkName(css::uno::Reference< css::container::XIndexAccess > const &xIndex, std::size_t nIndex)
static std::vector< OUString > maFieldNames
virtual css::uno::Reference< css::uno::XInterface > init()=0
static void testGetDataPilotFields_Impl(css::uno::Reference< css::sheet::XDataPilotDescriptor > const &xDescr)
int nCount
sal_Int32 nIndex
OUString aName
int i