LibreOffice Module test (master) 1
textsettings.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
10#include <cppunit/TestAssert.h>
11
12#include <com/sun/star/beans/PropertyAttribute.hpp>
13#include <com/sun/star/beans/XPropertySet.hpp>
14#include <com/sun/star/i18n/XForbiddenCharacters.hpp>
15
18
19namespace
20{
21bool extstsProperty(css::uno::Reference<css::beans::XPropertySet> const& rxPropertySet,
22 OUString const& rPropertyName)
23{
24 css::uno::Reference<css::beans::XPropertySetInfo> xPropertySetInfo(
25 rxPropertySet->getPropertySetInfo());
26 return xPropertySetInfo->hasPropertyByName(rPropertyName);
27}
28
29bool isPropertyReadOnly(css::uno::Reference<css::beans::XPropertySet> const& rxPropertySet,
30 std::u16string_view rPropertyName)
31{
32 css::uno::Reference<css::beans::XPropertySetInfo> xPropertySetInfo(
33 rxPropertySet->getPropertySetInfo());
34 const css::uno::Sequence<css::beans::Property> xProperties = xPropertySetInfo->getProperties();
35
36 for (auto const& rProperty : xProperties)
37 {
38 if (rProperty.Name == rPropertyName)
39 return (rProperty.Attributes & com::sun::star::beans::PropertyAttribute::READONLY) != 0;
40 }
41
42 return false;
43}
44// [property] string PrinterName;
45void testPrinterName(css::uno::Reference<css::beans::XPropertySet> const& rxSettings)
46{
47 static constexpr OUStringLiteral rPropertyName(u"PrinterName");
48
49 if (!extstsProperty(rxSettings, rPropertyName))
50 return; // Property is sometimes not set - bug? it is not defined as optional
51
52 OUString aPrinterName_Get;
53
54 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue",
55 rxSettings->getPropertyValue(rPropertyName) >>= aPrinterName_Get);
56
57 OUString aPrinterName_Set;
58 css::uno::Any aNewValue;
59 aNewValue <<= aPrinterName_Get;
60 rxSettings->setPropertyValue(rPropertyName, aNewValue);
61
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);
65}
66
67// [optional, property] short PrinterIndependentLayout;
68void testPrinterIndependentLayout(css::uno::Reference<css::beans::XPropertySet> const& rxSettings)
69{
70 static constexpr OUStringLiteral rPropertyName(u"PrinterIndependentLayout");
71
72 if (!extstsProperty(rxSettings, rPropertyName))
73 return; // Property is optional
74
75 sal_Int16 aValue_Get = {};
76
77 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue",
78 rxSettings->getPropertyValue(rPropertyName) >>= aValue_Get);
79
80 sal_Int16 aValue_New;
81 aValue_New = (aValue_Get == 1 ? 3 : 1);
82 rxSettings->setPropertyValue(rPropertyName, css::uno::Any(aValue_New));
83
84 sal_Int16 aValue_Set;
85
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);
89}
90
91// [optional, property] com::sun::star::i18n::XForbiddenCharacters ForbiddenCharacters;
92void testForbiddenCharacters(css::uno::Reference<css::beans::XPropertySet> const& rxSettings)
93{
94 static constexpr OUStringLiteral rPropertyName(u"ForbiddenCharacters");
95
96 if (!extstsProperty(rxSettings, rPropertyName))
97 return; // Property is optional
98
99 CPPUNIT_ASSERT_MESSAGE("Property is read-only but shouldn't be",
100 !isPropertyReadOnly(rxSettings, rPropertyName));
101
102 css::uno::Reference<css::i18n::XForbiddenCharacters> aValue_Get;
103
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());
107}
108}
109
110namespace apitest
111{
114{
115 css::uno::Reference<css::beans::XPropertySet> xSettings(init(), css::uno::UNO_QUERY_THROW);
116
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");
150}
151} // end namespace apitest
152
153/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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)