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 <o3tl/safeint.hxx>
20 #include <rtl/ustring.hxx>
21 
22 using namespace css;
23 using namespace css::uno;
24 
25 namespace apitest {
26 
27 std::vector< OUString > XDataPilotDescriptor::maFieldNames;
28 
29 void XDataPilotDescriptor::testTag()
30 {
31  OUString aTag("DataPilotDescriptor_Tag");
32  uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
33  xDescr->setTag(aTag);
34  OUString aNewTag = xDescr->getTag();
35  CPPUNIT_ASSERT_EQUAL( aTag, aNewTag );
36 }
37 
38 void XDataPilotDescriptor::testSourceRange()
39 {
40  uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
41  table::CellRangeAddress aOldAddress = xDescr->getSourceRange();
42 
43  table::CellRangeAddress aAddress;
44  aAddress.Sheet = 1;
45  aAddress.StartColumn = 1;
46  aAddress.StartRow = 1;
47  aAddress.EndColumn = 5;
48  aAddress.EndRow = 5;
49  xDescr->setSourceRange(aAddress);
50 
51  table::CellRangeAddress aReturn = xDescr->getSourceRange();
52 
53  CPPUNIT_ASSERT_EQUAL(aAddress.Sheet, aReturn.Sheet);
54  CPPUNIT_ASSERT_EQUAL(aAddress.StartColumn, aReturn.StartColumn);
55  CPPUNIT_ASSERT_EQUAL(aAddress.StartRow, aReturn.StartRow);
56  CPPUNIT_ASSERT_EQUAL(aAddress.EndColumn, aReturn.EndColumn);
57  CPPUNIT_ASSERT_EQUAL(aAddress.EndRow, aReturn.EndRow);
58 
59  //restore old settings
60  xDescr->setSourceRange(aOldAddress);
61 }
62 
63 void XDataPilotDescriptor::testGetFilterDescriptor()
64 {
65  uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
66  uno::Reference< sheet::XSheetFilterDescriptor > xSheetFilterDescr = xDescr->getFilterDescriptor();
67  CPPUNIT_ASSERT(xSheetFilterDescr.is());
68 }
69 
70 void XDataPilotDescriptor::testGetDataPilotFields_Impl( uno::Reference< sheet::XDataPilotDescriptor > const & xDescr)
71 {
72  uno::Reference< container::XIndexAccess > xIndex(xDescr->getDataPilotFields(), UNO_SET_THROW);
73 
74  sal_Int32 nCount = xIndex->getCount();
75 
76  OUString aOrientation("Orientation");
77  for (sal_Int32 i = 0; i < nCount && i < 5; ++i)
78  {
79  uno::Reference< container::XNamed > xNamed( xIndex->getByIndex( i ), UNO_QUERY_THROW);
80  OUString aName = xNamed->getName();
81  maFieldNames.push_back(aName);
82  CPPUNIT_ASSERT( aName != "Data" );
83 
84  uno::Reference< beans::XPropertySet > xPropSet( xNamed, UNO_QUERY_THROW);
85 
86  switch ( i % 5 )
87  {
88  case 0:
89  {
90  uno::Any aAny;
91  aAny<<= sheet::DataPilotFieldOrientation_COLUMN;
92  xPropSet->setPropertyValue(aOrientation, aAny);
93  }
94  break;
95  case 1:
96  {
97  uno::Any aAny;
98  aAny<<= sheet::DataPilotFieldOrientation_ROW;
99  xPropSet->setPropertyValue(aOrientation, aAny);
100  }
101  break;
102  case 2:
103  {
104  uno::Any aAny;
105  aAny<<= sheet::DataPilotFieldOrientation_DATA;
106  xPropSet->setPropertyValue(aOrientation, aAny);
107  }
108  break;
109  case 3:
110  {
111  uno::Any aAny;
112  aAny<<= sheet::DataPilotFieldOrientation_HIDDEN;
113  xPropSet->setPropertyValue(aOrientation, aAny);
114  }
115  break;
116  case 4:
117  {
118  uno::Any aAny;
119  aAny<<= sheet::DataPilotFieldOrientation_PAGE;
120  xPropSet->setPropertyValue(aOrientation, aAny);
121  }
122  break;
123  }
124  }
125 }
126 
127 void XDataPilotDescriptor::testGetDataPilotFields()
128 {
129  uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
130  testGetDataPilotFields_Impl( xDescr );
131 }
132 
133 void XDataPilotDescriptor::testGetColumnFields()
134 {
135  uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
136  testGetDataPilotFields_Impl( xDescr );
137  uno::Reference< container::XIndexAccess > xIndex(xDescr->getColumnFields(), UNO_SET_THROW);
138 
139  checkName( xIndex, 0 );
140 }
141 
142 void XDataPilotDescriptor::testGetRowFields()
143 {
144  uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
145  testGetDataPilotFields_Impl( xDescr );
146  uno::Reference< container::XIndexAccess > xIndex(xDescr->getRowFields(), UNO_SET_THROW);
147 
148  //checkName( xIndex, 1 );
149 }
150 
151 void XDataPilotDescriptor::testGetPageFields()
152 {
153  uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
154  testGetDataPilotFields_Impl( xDescr );
155  uno::Reference< container::XIndexAccess > xIndex(xDescr->getPageFields(), UNO_SET_THROW);
156 
157  checkName( xIndex, 4 );
158 }
159 
160 void XDataPilotDescriptor::testGetDataFields()
161 {
162  uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
163  testGetDataPilotFields_Impl( xDescr );
164  uno::Reference< container::XIndexAccess > xIndex(xDescr->getDataFields(), UNO_SET_THROW);
165 
166  checkName( xIndex, 2 );
167 }
168 
169 void XDataPilotDescriptor::testGetHiddenFields()
170 {
171  uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
172  testGetDataPilotFields_Impl( xDescr );
173  uno::Reference< container::XIndexAccess > xIndex(xDescr->getHiddenFields(), UNO_SET_THROW);
174 
175  checkName( xIndex, 3 );
176 }
177 
178 void XDataPilotDescriptor::checkName( uno::Reference< container::XIndexAccess > const & xIndex, sal_Int32 nIndex )
179 {
180  CPPUNIT_ASSERT(xIndex.is());
181  CPPUNIT_ASSERT(maFieldNames.size() >= o3tl::make_unsigned(nIndex));
182 
183  for (sal_Int32 i = 0; i < xIndex->getCount(); ++i)
184  {
185  uno::Reference< container::XNamed > xNamed( xIndex->getByIndex(i), UNO_QUERY_THROW);
186  CPPUNIT_ASSERT_EQUAL(maFieldNames[nIndex], xNamed->getName());
187  }
188 }
189 
190 }
191 
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
int nCount
int i
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
OUString aName
FILE * init(int, char **)