LibreOffice Module test (master) 1
databaserange.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
12
13#include <com/sun/star/beans/XPropertySet.hpp>
14#include <com/sun/star/sheet/XDatabaseRange.hpp>
15#include <com/sun/star/table/CellRangeAddress.hpp>
16#include <com/sun/star/uno/Reference.hxx>
17
18#include <cppunit/TestAssert.h>
19
20using namespace com::sun::star;
21using namespace com::sun::star::uno;
22
23namespace apitest
24{
26{
27 uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW);
28
29 static constexpr OUStringLiteral propName(u"MoveCells");
30
31 bool bMoveCells = true;
32 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bMoveCells);
33 CPPUNIT_ASSERT_MESSAGE("Default MoveCells already changed", !bMoveCells);
34
35 uno::Any aNewMoveCells;
36 aNewMoveCells <<= true;
37 xDatabaseRange->setPropertyValue(propName, aNewMoveCells);
38 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bMoveCells);
39 CPPUNIT_ASSERT_MESSAGE("Value of MoveCells wasn't changed", bMoveCells);
40}
41
43{
44 uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW);
45
46 static constexpr OUStringLiteral propName(u"KeepFormats");
47
48 bool bKeepFormats = true;
49 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bKeepFormats);
50 CPPUNIT_ASSERT_MESSAGE("Default KeepFormats already changed", !bKeepFormats);
51
52 uno::Any aNewKeepFormats;
53 aNewKeepFormats <<= true;
54 xDatabaseRange->setPropertyValue(propName, aNewKeepFormats);
55 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bKeepFormats);
56 CPPUNIT_ASSERT_MESSAGE("Value of KeepFormats wasn't changed", bKeepFormats);
57}
58
60{
61 uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW);
62
63 static constexpr OUStringLiteral propName(u"StripData");
64
65 bool bStripData = true;
66 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bStripData);
67 CPPUNIT_ASSERT_MESSAGE("Default StripData already changed", !bStripData);
68
69 uno::Any aNewStripData;
70 aNewStripData <<= true;
71 xDatabaseRange->setPropertyValue(propName, aNewStripData);
72 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bStripData);
73 CPPUNIT_ASSERT_MESSAGE("Value of StripData wasn't changed", bStripData);
74}
75
77{
78 uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW);
79
80 static constexpr OUStringLiteral propName(u"AutoFilter");
81
82 bool bAutoFilter = true;
83 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bAutoFilter);
84 CPPUNIT_ASSERT_MESSAGE("Default AutoFilter already changed", !bAutoFilter);
85
86 uno::Any aNewAutoFilter;
87 aNewAutoFilter <<= true;
88 xDatabaseRange->setPropertyValue(propName, aNewAutoFilter);
89 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bAutoFilter);
90 CPPUNIT_ASSERT_MESSAGE("Value of AutoFilter wasn't changed", bAutoFilter);
91}
92
94{
95 uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW);
96
97 static constexpr OUStringLiteral propName(u"UseFilterCriteriaSource");
98
99 bool bUseFilterCriteriaSource = true;
100 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bUseFilterCriteriaSource);
101 CPPUNIT_ASSERT_MESSAGE("Default UseFilterCriteriaSource already changed",
102 !bUseFilterCriteriaSource);
103
104 uno::Any aNewUseFilterCriteriaSource;
105 aNewUseFilterCriteriaSource <<= true;
106 xDatabaseRange->setPropertyValue(propName, aNewUseFilterCriteriaSource);
107 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bUseFilterCriteriaSource);
108 CPPUNIT_ASSERT_MESSAGE("Value of UseFilterCriteriaSource wasn't changed",
109 bUseFilterCriteriaSource);
110}
111
113{
114 uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW);
115
116 static constexpr OUStringLiteral propName(u"FilterCriteriaSource");
117
118 table::CellRangeAddress cellRangeAddress;
119 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= cellRangeAddress);
120 CPPUNIT_ASSERT_EQUAL_MESSAGE("Default RefreshPeriod already changed",
121 table::CellRangeAddress(0, 0, 0, 0, 0), cellRangeAddress);
122
123 uno::Any aFilterCriteriaSource;
124 aFilterCriteriaSource <<= table::CellRangeAddress(1, 1, 1, 1, 1);
125 xDatabaseRange->setPropertyValue(propName, aFilterCriteriaSource);
126 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= cellRangeAddress);
127 CPPUNIT_ASSERT_EQUAL_MESSAGE("Value of FilterCriteriaSource wasn't changed",
128 table::CellRangeAddress(1, 1, 1, 1, 1), cellRangeAddress);
129}
130
132{
133 uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW);
134
135 static constexpr OUStringLiteral propName(u"RefreshPeriod");
136
137 sal_Int32 aRefreshPeriod = 1;
138 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= aRefreshPeriod);
139 CPPUNIT_ASSERT_EQUAL_MESSAGE("Default RefreshPeriod already changed", sal_Int32(0),
140 aRefreshPeriod);
141
142 uno::Any aNewRefreshPeriod;
143 aNewRefreshPeriod <<= static_cast<sal_Int32>(42);
144 xDatabaseRange->setPropertyValue(propName, aNewRefreshPeriod);
145 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= aRefreshPeriod);
146 CPPUNIT_ASSERT_EQUAL_MESSAGE("Value of RefreshPeriod wasn't changed", sal_Int32(42),
147 aRefreshPeriod);
148}
149
151{
152 uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW);
153
154 static constexpr OUStringLiteral propName(u"FromSelection");
155
156 bool bFromSelection = true;
157 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bFromSelection);
158 CPPUNIT_ASSERT_MESSAGE("Default FromSelection already changed", !bFromSelection);
159
160 uno::Any aNewFromSelection;
161 aNewFromSelection <<= true;
162 xDatabaseRange->setPropertyValue(propName, aNewFromSelection);
163 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bFromSelection);
164 CPPUNIT_ASSERT_MESSAGE("Value of FromSelection wasn't changed", bFromSelection);
165}
166
168{
169 uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW);
170
171 static constexpr OUStringLiteral propName(u"TokenIndex");
172
173 sal_Int32 aTokenIndex = 0;
174 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= aTokenIndex);
175 CPPUNIT_ASSERT_EQUAL_MESSAGE("Default TotalIndex already changed", sal_Int32(1), aTokenIndex);
176
177 uno::Any aNewTokenIndex;
178 aNewTokenIndex <<= static_cast<sal_Int32>(42);
179 xDatabaseRange->setPropertyValue(propName, aNewTokenIndex);
180 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= aTokenIndex);
181 CPPUNIT_ASSERT_EQUAL_MESSAGE("Value of TotalIndex was changed", sal_Int32(1), aTokenIndex);
182}
183
185{
186 uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW);
187
188 static constexpr OUStringLiteral propName(u"TotalsRow");
189
190 bool bTotalsRow = true;
191 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bTotalsRow);
192 CPPUNIT_ASSERT_MESSAGE("Default TotalsRow already changed", !bTotalsRow);
193
194 uno::Any aNewTotalsRow;
195 aNewTotalsRow <<= true;
196 xDatabaseRange->setPropertyValue(propName, aNewTotalsRow);
197 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bTotalsRow);
198 CPPUNIT_ASSERT_MESSAGE("Value of TotalsRow wasn't changed", bTotalsRow);
199}
200
202{
203 uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW);
204
205 static constexpr OUStringLiteral propName(u"ContainsHeader");
206
207 bool bContainsHeader = false;
208 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bContainsHeader);
209 CPPUNIT_ASSERT_MESSAGE("Default ContainsHeader already changed", bContainsHeader);
210
211 uno::Any aNewContainsHeader;
212 aNewContainsHeader <<= false;
213 xDatabaseRange->setPropertyValue(propName, aNewContainsHeader);
214 CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bContainsHeader);
215 CPPUNIT_ASSERT_MESSAGE("Value of ContainsHeader wasn't changed", !bContainsHeader);
216}
217}
218
219/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual css::uno::Reference< css::uno::XInterface > init(const OUString &rDBName)=0
float u