1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <test/unoapi_property_testers.hxx>
12 #include <com/sun/star/uno/Any.hxx>
13 #include <cppunit/TestAssert.h>
19 void testBooleanProperty(uno::Reference
<beans::XPropertySet
> const& xPropertySet
,
24 bool bPropertyGet
= false;
25 bool bPropertySet
= false;
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
);
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
)
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
,
57 bool bPropertyGet
= false;
58 bool bPropertySet
= false;
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
)
80 = "Unable to get PropertyValue: " + OUStringToOString(name
, RTL_TEXTENCODING_UTF8
);
81 CPPUNIT_ASSERT_MESSAGE(msgGet
.getStr(), xPropertySet
->getPropertyValue(name
) >>= dPropertyGet
);
84 xPropertySet
->setPropertyValue(name
, aNewValue
);
85 CPPUNIT_ASSERT(xPropertySet
->getPropertyValue(name
) >>= dPropertySet
);
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
)
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
)
115 sal_Int32 nPropertyGet
;
116 sal_Int32 nPropertySet
;
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
);
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
)
148 sal_Int32 nPropertyGet
;
149 sal_Int32 nPropertySet
;
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
)
167 sal_Int16 nPropertyGet
;
168 sal_Int16 nPropertySet
;
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
);
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
)
200 sal_Int16 nPropertyGet
;
201 sal_Int16 nPropertySet
;
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
)
232 OUString sPropertyGet
;
233 OUString sPropertySet
;
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
);
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
)
252 OUString sPropertyGet
;
253 OUString sPropertySet
;
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
)
271 util::Color sPropertyGet
;
272 util::Color sPropertySet
;
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
);
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: */