LibreOffice Module test (master)  1
globalsheetsettings.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 
11 
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/uno/Any.hxx>
14 #include <com/sun/star/uno/Reference.hxx>
15 
16 #include <cppunit/TestAssert.h>
17 
18 using namespace com::sun::star;
19 using namespace com::sun::star::uno;
20 
21 namespace apitest
22 {
23 void GlobalSheetSettings::testGlobalSheetSettingsProperties()
24 {
25  uno::Reference<beans::XPropertySet> xGlobalSheetSettings(init(), UNO_QUERY_THROW);
26  OUString propName;
27  uno::Any aNewValue;
28 
29  propName = "MoveSelection";
30  bool aMoveSelection = false;
31  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aMoveSelection);
32  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue MoveSelection", aMoveSelection);
33 
34  aNewValue <<= false;
35  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
36  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aMoveSelection);
37  CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue MoveSelection", !aMoveSelection);
38 
39  propName = "MoveDirection";
40  sal_Int16 aMoveDirection = 42;
41  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aMoveDirection);
42  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue MoveDirection", sal_Int16(0),
43  aMoveDirection);
44 
45  aNewValue <<= sal_Int16(1);
46  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
47  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aMoveDirection);
48  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue MoveDirection", sal_Int16(1),
49  aMoveDirection);
50 
51  propName = "EnterEdit";
52  bool aEnterEdit = true;
53  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aEnterEdit);
54  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue EnterEdit", !aEnterEdit);
55 
56  aNewValue <<= true;
57  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
58  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aEnterEdit);
59  CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue EnterEdit", aEnterEdit);
60 
61  propName = "ExtendFormat";
62  bool aExtendFormat = true;
63  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aExtendFormat);
64  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ExtendFormat", !aExtendFormat);
65 
66  aNewValue <<= true;
67  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
68  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aExtendFormat);
69  CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ExtendFormat", aExtendFormat);
70 
71  propName = "RangeFinder";
72  bool aRangeFinder = false;
73  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aRangeFinder);
74  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue RangeFinder", aRangeFinder);
75 
76  aNewValue <<= false;
77  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
78  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aRangeFinder);
79  CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue RangeFinder", !aRangeFinder);
80 
81  propName = "ExpandReferences";
82  bool aExpandReferences = true;
83  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aExpandReferences);
84  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ExpandReferences", !aExpandReferences);
85 
86  aNewValue <<= true;
87  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
88  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aExpandReferences);
89  CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ExpandReferences", aExpandReferences);
90 
91  propName = "MarkHeader";
92  bool aMarkHeader = false;
93  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aMarkHeader);
94  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue MarkHeader", aMarkHeader);
95 
96  aNewValue <<= false;
97  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
98  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aMarkHeader);
99  CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue MarkHeader", !aMarkHeader);
100 
101  propName = "UseTabCol";
102  bool aUseTabCol = true;
103  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aUseTabCol);
104  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue UseTabCol", !aUseTabCol);
105 
106  aNewValue <<= true;
107  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
108  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aUseTabCol);
109  CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue UseTabCol", aUseTabCol);
110 
111  propName = "Metric";
112  sal_Int16 aMetric = 42;
113  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aMetric);
114  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue Metric", sal_Int16(8), aMetric);
115 
116  aNewValue <<= sal_Int16(1);
117  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
118  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aMetric);
119  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue Metric", sal_Int16(1), aMetric);
120 
121  propName = "Scale";
122  sal_Int16 aScale = 42;
123  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aScale);
124  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue Scale", sal_Int16(100), aScale);
125 
126  aNewValue <<= sal_Int16(-1);
127  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
128  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aScale);
129  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue Scale", sal_Int16(-1), aScale);
130 
131  propName = "DoAutoComplete";
132  bool aDoAutoComplete = false;
133  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aDoAutoComplete);
134  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue DoAutoComplete", aDoAutoComplete);
135 
136  aNewValue <<= false;
137  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
138  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aDoAutoComplete);
139  CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue DoAutoComplete", !aDoAutoComplete);
140 
141  propName = "StatusBarFunction";
142  sal_Int16 aStatusBarFunction = 42;
143  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aStatusBarFunction);
144  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue StatusBarFunction", sal_Int16(514),
145  aStatusBarFunction);
146 
147  aNewValue <<= sal_Int16(1);
148  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
149  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aStatusBarFunction);
150  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue StatusBarFunction", sal_Int16(1),
151  aStatusBarFunction);
152 
153  propName = "UserLists";
154  uno::Sequence<OUString> aSeq(6);
155  aSeq[0] = "Sun,Mon,Tue,Wed,Thu,Fri,Sat";
156  aSeq[1] = "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday";
157  aSeq[2] = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";
158  aSeq[3]
159  = "January,February,March,April,May,June,July,August,September,October,November,December";
160  aSeq[4] = "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Shabbat";
161  aSeq[5] = "Nissan,Iyar,Sivan,Tammuz,Av,Elul,Tishri,Heshvan,Kislev,Tevet,Shevat,Adar,Adar B";
162 
163  uno::Sequence<OUString> aUserLists;
164  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aUserLists);
165  for (auto i = 0; i < aUserLists.getLength(); i++)
166  {
167  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue UserLists[" + std::to_string(i)
168  + "]",
169  aSeq[i], aUserLists[i]);
170  }
171 
172  aNewValue <<= uno::Sequence<OUString>();
173  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
174  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aUserLists);
175  CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue UserLists", !aUserLists.hasElements());
176 
177  propName = "LinkUpdateMode";
178  sal_Int16 aLinkUpdateMode = 42;
179  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aLinkUpdateMode);
180  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue LinkUpdateMode", sal_Int16(2),
181  aLinkUpdateMode);
182 
183  aNewValue <<= sal_Int16(1);
184  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
185  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aLinkUpdateMode);
186  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue LinkUpdateMode", sal_Int16(1),
187  aLinkUpdateMode);
188 
189  propName = "PrintAllSheets";
190  bool aPrintAllSheets = true;
191  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aPrintAllSheets);
192  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue PrintAllSheets", !aPrintAllSheets);
193 
194  aNewValue <<= true;
195  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
196  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aPrintAllSheets);
197  CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue PrintAllSheets", aPrintAllSheets);
198 
199  propName = "PrintEmptyPages";
200  bool aPrintEmptyPages = true;
201  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aPrintEmptyPages);
202  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue PrintEmptyPages", !aPrintEmptyPages);
203 
204  aNewValue <<= true;
205  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
206  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aPrintEmptyPages);
207  CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue PrintEmptyPages", aPrintEmptyPages);
208 
209  propName = "UsePrinterMetrics";
210  bool aUsePrinterMetrics = true;
211  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aUsePrinterMetrics);
212  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue UsePrinterMetrics", !aUsePrinterMetrics);
213 
214  aNewValue <<= true;
215  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
216  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aUsePrinterMetrics);
217  CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue UsePrinterMetrics", aUsePrinterMetrics);
218 
219  propName = "ReplaceCellsWarning";
220  bool aReplaceCellsWarning = false;
221  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aReplaceCellsWarning);
222  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ReplaceCellsWarning", aReplaceCellsWarning);
223 
224  aNewValue <<= false;
225  xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
226  CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aReplaceCellsWarning);
227  CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ReplaceCellsWarning",
228  !aReplaceCellsWarning);
229 }
230 }
231 
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
int i
Sequence< sal_Int8 > aSeq
FILE * init(int, char **)