1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <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>
16 #include <test/unoapi_property_testers.hxx>
17 #include <test/text/textsettings.hxx>
21 bool 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
);
29 bool 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;
44 // [property] string PrinterName;
45 void testPrinterName(css::uno::Reference
<css::beans::XPropertySet
> const& rxSettings
)
47 static const OUStringLiteral
rPropertyName(u
"PrinterName");
49 if (!extstsProperty(rxSettings
, rPropertyName
))
50 return; // Property is sometimes not set - bug? it is not defined as optional
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
);
67 // [optional, property] short PrinterIndependentLayout;
68 void testPrinterIndependentLayout(css::uno::Reference
<css::beans::XPropertySet
> const& rxSettings
)
70 static const OUStringLiteral
rPropertyName(u
"PrinterIndependentLayout");
72 if (!extstsProperty(rxSettings
, rPropertyName
))
73 return; // Property is optional
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
);
91 // [optional, property] com::sun::star::i18n::XForbiddenCharacters ForbiddenCharacters;
92 void testForbiddenCharacters(css::uno::Reference
<css::beans::XPropertySet
> const& rxSettings
)
94 static const OUStringLiteral
rPropertyName(u
"ForbiddenCharacters");
96 if (!extstsProperty(rxSettings
, rPropertyName
))
97 return; // Property is optional
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());
112 TextSettings::~TextSettings() {}
113 void TextSettings::testSettingsProperties()
115 css::uno::Reference
<css::beans::XPropertySet
> xSettings(init(), css::uno::UNO_QUERY_THROW
);
117 testForbiddenCharacters(xSettings
);
118 //testShortOptionalProperty(xSettings, "LinkUpdateMode");
119 testPrinterName(xSettings
);
120 // [property] sequence< byte > PrinterSetup;
121 testBooleanOptionalProperty(xSettings
, "IsKernAsianPunctuation");
122 //testShortOptionalProperty(xSettings, "CharacterCompressionType");
123 testBooleanOptionalProperty(xSettings
, "ApplyUserData");
124 testBooleanOptionalProperty(xSettings
, "SaveVersionOnClose");
125 testBooleanOptionalProperty(xSettings
, "UpdateFromTemplate");
126 testBooleanOptionalProperty(xSettings
, "FieldAutoUpdate");
127 testStringOptionalProperty(xSettings
, "CurrentDatabaseDataSource");
128 testStringOptionalProperty(xSettings
, "CurrentDatabaseCommand");
129 testLongOptionalProperty(xSettings
, "CurrentDatabaseCommandType");
130 testLongOptionalProperty(xSettings
, "DefaultTabStop");
131 testBooleanOptionalProperty(xSettings
, "IsPrintBooklet");
132 testBooleanOptionalProperty(xSettings
, "IsPrintBookletFront");
133 testBooleanOptionalProperty(xSettings
, "IsPrintBookletBack");
134 testLongOptionalProperty(xSettings
, "PrintQuality");
135 testStringOptionalProperty(xSettings
, "ColorTableURL");
136 testStringOptionalProperty(xSettings
, "DashTableURL");
137 testStringOptionalProperty(xSettings
, "LineEndTableURL");
138 testStringOptionalProperty(xSettings
, "HatchTableURL");
139 testStringOptionalProperty(xSettings
, "GradientTableURL");
140 testStringOptionalProperty(xSettings
, "BitmapTableURL");
141 testBooleanOptionalProperty(xSettings
, "AutoCalculate");
142 testPrinterIndependentLayout(xSettings
);
143 testBooleanOptionalProperty(xSettings
, "AddExternalLeading");
144 testBooleanOptionalProperty(xSettings
, "EmbedFonts");
145 testBooleanOptionalProperty(xSettings
, "EmbedSystemFonts");
146 testBooleanOptionalProperty(xSettings
, "EmbedOnlyUsedFonts");
147 testBooleanOptionalProperty(xSettings
, "EmbedLatinScriptFonts");
148 testBooleanOptionalProperty(xSettings
, "EmbedAsianScriptFonts");
149 testBooleanOptionalProperty(xSettings
, "EmbedComplexScriptFonts");
151 } // end namespace apitest
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */