Related: tdf#145722 need to clone userdata if we copy a module/dialog
[LibreOffice.git] / test / source / unoapi_property_testers.cxx
blobf261c4ce3736f38434acf09039dcb45139cf6f3e
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.
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 */
10 #include <test/unoapi_property_testers.hxx>
12 #include <com/sun/star/uno/Any.hxx>
13 #include <cppunit/TestAssert.h>
15 using namespace css;
17 namespace apitest
19 void testBooleanProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
20 const OUString& name)
22 uno::Any aNewValue;
24 bool bPropertyGet = false;
25 bool bPropertySet = false;
27 OString msgGet
28 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
29 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= bPropertyGet);
31 aNewValue <<= !bPropertyGet;
32 xPropertySet->setPropertyValue(name, aNewValue);
33 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= bPropertySet);
34 OString msgSet
35 = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
36 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), !bPropertyGet, bPropertySet);
39 void testBooleanOptionalProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
40 const OUString& rName)
42 try
44 testBooleanProperty(xPropertySet, rName);
46 catch (const css::beans::UnknownPropertyException& /*ex*/)
48 // ignore if the property is unknown as it is optional
52 void testBooleanReadonlyProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
53 const OUString& name)
55 uno::Any aNewValue;
57 bool bPropertyGet = false;
58 bool bPropertySet = false;
60 OString msgGet
61 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
62 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= bPropertyGet);
64 aNewValue <<= !bPropertyGet;
65 xPropertySet->setPropertyValue(name, aNewValue);
66 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= bPropertySet);
67 OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
68 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), bPropertyGet, bPropertySet);
71 void testDoubleProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
72 const OUString& name, const double& dValue)
74 uno::Any aNewValue;
76 double dPropertyGet;
77 double dPropertySet;
79 OString msgGet
80 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
81 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= dPropertyGet);
83 aNewValue <<= dValue;
84 xPropertySet->setPropertyValue(name, aNewValue);
85 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= dPropertySet);
86 OString msgSet
87 = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
88 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(msgSet.getStr(), dValue, dPropertySet, 0.5);
91 void testDoubleReadonlyProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
92 const OUString& name, const double& dValue)
94 uno::Any aNewValue;
96 double dPropertyGet;
97 double dPropertySet;
99 OString msgGet
100 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
101 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= dPropertyGet);
103 aNewValue <<= dValue;
104 xPropertySet->setPropertyValue(name, aNewValue);
105 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= dPropertySet);
106 OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
107 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(msgSet.getStr(), dPropertyGet, dPropertySet, 0.5);
110 void testLongProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, const OUString& name,
111 const sal_Int32& nValue)
113 uno::Any aNewValue;
115 sal_Int32 nPropertyGet;
116 sal_Int32 nPropertySet;
118 OString msgGet
119 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
120 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= nPropertyGet);
122 aNewValue <<= nValue;
123 xPropertySet->setPropertyValue(name, aNewValue);
124 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= nPropertySet);
125 OString msgSet
126 = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
127 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nValue, nPropertySet);
130 void testLongOptionalProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
131 const OUString& rName, const sal_Int32& rValue)
135 testLongProperty(xPropertySet, rName, rValue);
137 catch (const css::beans::UnknownPropertyException& /*ex*/)
139 // ignore if the property is unknown as it is optional
143 void testLongReadonlyProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
144 const OUString& name, const sal_Int32& nValue)
146 uno::Any aNewValue;
148 sal_Int32 nPropertyGet;
149 sal_Int32 nPropertySet;
151 OString msgGet
152 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
153 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= nPropertyGet);
155 aNewValue <<= nValue;
156 xPropertySet->setPropertyValue(name, aNewValue);
157 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= nPropertySet);
158 OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
159 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nPropertyGet, nPropertySet);
162 void testShortProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
163 const OUString& name, const sal_Int16& nValue)
165 uno::Any aNewValue;
167 sal_Int16 nPropertyGet;
168 sal_Int16 nPropertySet;
170 OString msgGet
171 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
172 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= nPropertyGet);
174 aNewValue <<= nValue;
175 xPropertySet->setPropertyValue(name, aNewValue);
176 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= nPropertySet);
177 OString msgSet
178 = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
179 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nValue, nPropertySet);
182 void testShortOptionalProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
183 const OUString& rName, const sal_Int16& rValue)
187 testShortProperty(xPropertySet, rName, rValue);
189 catch (const css::beans::UnknownPropertyException& /*ex*/)
191 // ignore if the property is unknown as it is optional
195 void testShortReadonlyProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
196 const OUString& name, const sal_Int16& nValue)
198 uno::Any aNewValue;
200 sal_Int16 nPropertyGet;
201 sal_Int16 nPropertySet;
203 OString msgGet
204 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
205 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= nPropertyGet);
207 aNewValue <<= nValue;
208 xPropertySet->setPropertyValue(name, aNewValue);
209 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= nPropertySet);
210 OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
211 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nPropertyGet, nPropertySet);
214 void testStringOptionalProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
215 const OUString& rName, const OUString& rValue)
219 testStringProperty(xPropertySet, rName, rValue);
221 catch (const css::beans::UnknownPropertyException& /*ex*/)
223 // ignore if the property is unknown as it is optional
227 void testStringProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
228 const OUString& name, const OUString& rValue)
230 uno::Any aNewValue;
232 OUString sPropertyGet;
233 OUString sPropertySet;
235 OString msgGet
236 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
237 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= sPropertyGet);
239 aNewValue <<= rValue;
240 xPropertySet->setPropertyValue(name, aNewValue);
241 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= sPropertySet);
242 OString msgSet
243 = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
244 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), rValue, sPropertySet);
247 void testStringReadonlyProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
248 const OUString& name, const OUString& rValue)
250 uno::Any aNewValue;
252 OUString sPropertyGet;
253 OUString sPropertySet;
255 OString msgGet
256 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
257 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= sPropertyGet);
259 aNewValue <<= rValue;
260 xPropertySet->setPropertyValue(name, aNewValue);
261 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= sPropertySet);
262 OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
263 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), sPropertyGet, sPropertySet);
266 void testColorProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
267 const OUString& name, const util::Color& rValue)
269 uno::Any aNewValue;
271 util::Color sPropertyGet;
272 util::Color sPropertySet;
274 OString msgGet
275 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
276 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= sPropertyGet);
278 aNewValue <<= rValue;
279 xPropertySet->setPropertyValue(name, aNewValue);
280 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= sPropertySet);
281 OString msgSet
282 = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8);
283 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), rValue, sPropertySet);
286 } // namespace apitest
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */