summaryrefslogtreecommitdiff
path: root/sw/qa/api/SettingsTest.hxx
blob: 73cfcfddecf2469d03f5f54fbbca1c6d48a5ceba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef INCLUDED_SW_QA_API_SETTINGSTEST_HXX
#define INCLUDED_SW_QA_API_SETTINGSTEST_HXX

#include "ApiTestBase.hxx"

#include <cppunit/TestAssert.h>
#include <test/unoapi_property_testers.hxx>

#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/i18n/XForbiddenCharacters.hpp>

namespace apitest
{
class SettingsTest : public ApiTestBase
{
    // [property] string PrinterName;
    static void testPrinterName(css::uno::Reference<css::beans::XPropertySet> const& rxSettings)
    {
        const OUString rPropertyName("PrinterName");

        if (!extstsProperty(rxSettings, rPropertyName))
            return; // Property is sometimes not set - bug? it is not defined as optional

        OUString aPrinterName_Get;

        CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue",
                               rxSettings->getPropertyValue(rPropertyName) >>= aPrinterName_Get);

        OUString aPrinterName_Set;
        css::uno::Any aNewValue;
        aNewValue <<= aPrinterName_Get;
        rxSettings->setPropertyValue(rPropertyName, aNewValue);

        CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue",
                               rxSettings->getPropertyValue(rPropertyName) >>= aPrinterName_Set);
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue", aPrinterName_Get,
                                     aPrinterName_Set);
    }

    // [optional, property] short PrinterIndependentLayout;
    static void
    testPrinterIndependentLayout(css::uno::Reference<css::beans::XPropertySet> const& rxSettings)
    {
        const OUString rPropertyName("PrinterIndependentLayout");

        if (!extstsProperty(rxSettings, rPropertyName))
            return; // Property is optional

        sal_Int16 aValue_Get;

        CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue",
                               rxSettings->getPropertyValue(rPropertyName) >>= aValue_Get);

        sal_Int16 aValue_New;
        aValue_New = (aValue_Get == 1 ? 3 : 1);
        rxSettings->setPropertyValue(rPropertyName, css::uno::Any(aValue_New));

        sal_Int16 aValue_Set;

        CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue",
                               rxSettings->getPropertyValue(rPropertyName) >>= aValue_Set);
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue", aValue_New, aValue_Set);
    }

    // [optional, property] com::sun::star::i18n::XForbiddenCharacters ForbiddenCharacters;
    static void
    testForbiddenCharacters(css::uno::Reference<css::beans::XPropertySet> const& rxSettings)
    {
        const OUString rPropertyName("ForbiddenCharacters");

        if (!extstsProperty(rxSettings, rPropertyName))
            return; // Property is optional

        CPPUNIT_ASSERT_MESSAGE("Property is read-only but shouldn't be",
                               !isPropertyReadOnly(rxSettings, rPropertyName));

        css::uno::Reference<css::i18n::XForbiddenCharacters> aValue_Get;

        CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue",
                               rxSettings->getPropertyValue(rPropertyName) >>= aValue_Get);
        CPPUNIT_ASSERT_MESSAGE("Empty reference to XForbiddenCharacters", aValue_Get.is());
    }

public:
    void testSettingsProperties()
    {
        auto map = init();

        css::uno::Reference<css::beans::XPropertySet> xSettings(map["document::Settings"],
                                                                css::uno::UNO_QUERY_THROW);

        testForbiddenCharacters(xSettings);
        //testShortOptionalProperty(xSettings, "LinkUpdateMode");
        testPrinterName(xSettings);
        // [property] sequence< byte > PrinterSetup;
        testBooleanOptionalProperty(xSettings, "IsKernAsianPunctuation");
        //testShortOptionalProperty(xSettings, "CharacterCompressionType");
        testBooleanOptionalProperty(xSettings, "ApplyUserData");
        testBooleanOptionalProperty(xSettings, "SaveVersionOnClose");
        testBooleanOptionalProperty(xSettings, "UpdateFromTemplate");
        testBooleanOptionalProperty(xSettings, "FieldAutoUpdate");
        testStringOptionalProperty(xSettings, "CurrentDatabaseDataSource");
        testStringOptionalProperty(xSettings, "CurrentDatabaseCommand");
        testLongOptionalProperty(xSettings, "CurrentDatabaseCommandType");
        testLongOptionalProperty(xSettings, "DefaultTabStop");
        testBooleanOptionalProperty(xSettings, "IsPrintBooklet");
        testBooleanOptionalProperty(xSettings, "IsPrintBookletFront");
        testBooleanOptionalProperty(xSettings, "IsPrintBookletBack");
        testLongOptionalProperty(xSettings, "PrintQuality");
        testStringOptionalProperty(xSettings, "ColorTableURL");
        testStringOptionalProperty(xSettings, "DashTableURL");
        testStringOptionalProperty(xSettings, "LineEndTableURL");
        testStringOptionalProperty(xSettings, "HatchTableURL");
        testStringOptionalProperty(xSettings, "GradientTableURL");
        testStringOptionalProperty(xSettings, "BitmapTableURL");
        testBooleanOptionalProperty(xSettings, "AutoCalculate");
        testPrinterIndependentLayout(xSettings);
        testBooleanOptionalProperty(xSettings, "AddExternalLeading");
        testBooleanOptionalProperty(xSettings, "EmbedFonts");
        testBooleanOptionalProperty(xSettings, "EmbedSystemFonts");
        testBooleanOptionalProperty(xSettings, "EmbedOnlyUsedFonts");
        testBooleanOptionalProperty(xSettings, "EmbedLatinScriptFonts");
        testBooleanOptionalProperty(xSettings, "EmbedAsianScriptFonts");
        testBooleanOptionalProperty(xSettings, "EmbedComplexScriptFonts");
    }
};
} // end namespace apitest

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */