10#include <cppunit/TestAssert.h>
12#include <com/sun/star/beans/PropertyAttribute.hpp>
13#include <com/sun/star/beans/XPropertySet.hpp>
14#include <com/sun/star/i18n/XForbiddenCharacters.hpp>
21bool extstsProperty(css::uno::Reference<css::beans::XPropertySet>
const& rxPropertySet,
22 OUString
const& rPropertyName)
24 css::uno::Reference<css::beans::XPropertySetInfo> xPropertySetInfo(
25 rxPropertySet->getPropertySetInfo());
26 return xPropertySetInfo->hasPropertyByName(rPropertyName);
29bool isPropertyReadOnly(css::uno::Reference<css::beans::XPropertySet>
const& rxPropertySet,
30 std::u16string_view rPropertyName)
32 css::uno::Reference<css::beans::XPropertySetInfo> xPropertySetInfo(
33 rxPropertySet->getPropertySetInfo());
34 const css::uno::Sequence<css::beans::Property> xProperties = xPropertySetInfo->getProperties();
36 for (
auto const& rProperty : xProperties)
38 if (rProperty.Name == rPropertyName)
39 return (rProperty.Attributes & com::sun::star::beans::PropertyAttribute::READONLY) != 0;
45void testPrinterName(css::uno::Reference<css::beans::XPropertySet>
const& rxSettings)
47 static constexpr OUStringLiteral rPropertyName(u
"PrinterName");
49 if (!extstsProperty(rxSettings, rPropertyName))
52 OUString aPrinterName_Get;
54 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue",
55 rxSettings->getPropertyValue(rPropertyName) >>= aPrinterName_Get);
57 OUString aPrinterName_Set;
58 css::uno::Any aNewValue;
59 aNewValue <<= aPrinterName_Get;
60 rxSettings->setPropertyValue(rPropertyName, aNewValue);
62 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue",
63 rxSettings->getPropertyValue(rPropertyName) >>= aPrinterName_Set);
64 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Unable to set PropertyValue", aPrinterName_Get, aPrinterName_Set);
68void testPrinterIndependentLayout(css::uno::Reference<css::beans::XPropertySet>
const& rxSettings)
70 static constexpr OUStringLiteral rPropertyName(u
"PrinterIndependentLayout");
72 if (!extstsProperty(rxSettings, rPropertyName))
75 sal_Int16 aValue_Get = {};
77 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue",
78 rxSettings->getPropertyValue(rPropertyName) >>= aValue_Get);
81 aValue_New = (aValue_Get == 1 ? 3 : 1);
82 rxSettings->setPropertyValue(rPropertyName, css::uno::Any(aValue_New));
86 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue",
87 rxSettings->getPropertyValue(rPropertyName) >>= aValue_Set);
88 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Unable to set PropertyValue", aValue_New, aValue_Set);
92void testForbiddenCharacters(css::uno::Reference<css::beans::XPropertySet>
const& rxSettings)
94 static constexpr OUStringLiteral rPropertyName(u
"ForbiddenCharacters");
96 if (!extstsProperty(rxSettings, rPropertyName))
99 CPPUNIT_ASSERT_MESSAGE(
"Property is read-only but shouldn't be",
100 !isPropertyReadOnly(rxSettings, rPropertyName));
102 css::uno::Reference<css::i18n::XForbiddenCharacters> aValue_Get;
104 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue",
105 rxSettings->getPropertyValue(rPropertyName) >>= aValue_Get);
106 CPPUNIT_ASSERT_MESSAGE(
"Empty reference to XForbiddenCharacters", aValue_Get.is());
115 css::uno::Reference<css::beans::XPropertySet> xSettings(
init(), css::uno::UNO_QUERY_THROW);
117 testForbiddenCharacters(xSettings);
119 testPrinterName(xSettings);
142 testPrinterIndependentLayout(xSettings);
void testSettingsProperties()
virtual css::uno::Reference< css::uno::XInterface > init()=0
void testStringOptionalProperty(uno::Reference< beans::XPropertySet > const &xPropertySet, const OUString &rName, const OUString &rValue)
void testBooleanOptionalProperty(uno::Reference< beans::XPropertySet > const &xPropertySet, const OUString &rName)
void testLongOptionalProperty(uno::Reference< beans::XPropertySet > const &xPropertySet, const OUString &rName, const sal_Int32 &rValue)