LibreOffice Module test (master) 1
globalsheetsettings.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
11
12#include <com/sun/star/beans/NamedValue.hpp>
13#include <com/sun/star/beans/XPropertySet.hpp>
14#include <com/sun/star/configuration/theDefaultProvider.hpp>
15#include <com/sun/star/uno/Any.hxx>
16#include <com/sun/star/uno/Reference.hxx>
17#include <com/sun/star/util/XChangesBatch.hpp>
18
20
21#include <cppunit/TestAssert.h>
22
23using namespace com::sun::star;
24using namespace com::sun::star::uno;
25
26namespace apitest
27{
29{
30 uno::Reference<beans::XPropertySet> xGlobalSheetSettings(init(), UNO_QUERY_THROW);
31 auto configProvider
32 = css::configuration::theDefaultProvider::get(comphelper::getProcessComponentContext());
33
34 auto DoCheck = [&xGlobalSheetSettings, &configProvider](
35 const OUString& propName, const auto& origValue, const auto& newValue,
36 const OUString& regNodeName, const OUString& regValueName) {
37 OString sMessage = "PropertyValue " + propName.toUtf8();
38 css::uno::Any aOrigValue(origValue), aNewValue(newValue);
39
40 css::uno::Sequence<css::uno::Any> args{ css::uno::Any(
41 css::beans::NamedValue("nodepath", css::uno::Any(regNodeName))) };
42 css::uno::Reference<beans::XPropertySet> xRegNodeRO(
43 configProvider->createInstanceWithArguments(
44 "com.sun.star.configuration.ConfigurationAccess", args),
45 css::uno::UNO_QUERY_THROW);
46 css::uno::Reference<beans::XPropertySet> xRegNodeRW(
47 configProvider->createInstanceWithArguments(
48 "com.sun.star.configuration.ConfigurationUpdateAccess", args),
49 css::uno::UNO_QUERY_THROW);
50 css::uno::Reference<css::util::XChangesBatch> xBatch(xRegNodeRW, css::uno::UNO_QUERY_THROW);
51
52 // 1. Check initial value
53 CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aOrigValue,
54 xGlobalSheetSettings->getPropertyValue(propName));
55 CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aOrigValue,
56 xRegNodeRO->getPropertyValue(regValueName));
57
58 // 2. Check setting the value through GlobalSheetSettings
59 xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
60 CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aNewValue,
61 xGlobalSheetSettings->getPropertyValue(propName));
62 CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aNewValue,
63 xRegNodeRO->getPropertyValue(regValueName));
64
65 // 3. Check setting the value through ConfigurationUpdateAccess
66 xRegNodeRW->setPropertyValue(regValueName, aOrigValue);
67 xBatch->commitChanges();
68 CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aOrigValue,
69 xRegNodeRO->getPropertyValue(regValueName));
70 CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aOrigValue,
71 xGlobalSheetSettings->getPropertyValue(propName));
72 };
73
74 OUString node = "/org.openoffice.Office.Calc/Input";
75 DoCheck("MoveSelection", true, false, node, "MoveSelection");
76 DoCheck("MoveDirection", sal_Int16(0), sal_Int16(1), node, "MoveSelectionDirection");
77 DoCheck("EnterEdit", false, true, node, "SwitchToEditMode");
78 DoCheck("ExtendFormat", false, true, node, "ExpandFormatting");
79 DoCheck("RangeFinder", true, false, node, "ShowReference");
80 DoCheck("ExpandReferences", false, true, node, "ExpandReference");
81 DoCheck("MarkHeader", true, false, node, "HighlightSelection");
82 DoCheck("UseTabCol", false, true, node, "UseTabCol");
83 DoCheck("ReplaceCellsWarning", true, false, node, "ReplaceCellsWarning");
84
85 node = "/org.openoffice.Office.Calc/Layout/Other/MeasureUnit";
86 DoCheck("Metric", sal_Int16(8), sal_Int16(1), node, "NonMetric"); // Test uses en-US locale
87
88 node = "/org.openoffice.Office.Calc/Input";
89 DoCheck("DoAutoComplete", true, false, node, "AutoInput");
90
91 node = "/org.openoffice.Office.Calc/Content/Update";
92 DoCheck("LinkUpdateMode", sal_Int16(2), sal_Int16(1), node, "Link");
93
94 node = "/org.openoffice.Office.Calc/Print/";
95 DoCheck("PrintAllSheets", false, true, node + "Other", "AllSheets");
96 DoCheck("PrintEmptyPages", false, true, node + "Page", "EmptyPages");
97
98 OUString propName;
99 uno::Any aNewValue;
100
101 propName = "Scale";
102 sal_Int16 aScale = 42;
103 CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aScale);
104 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue Scale", sal_Int16(100), aScale);
105
106 aNewValue <<= sal_Int16(-1);
107 xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
108 CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aScale);
109 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue Scale", sal_Int16(-1), aScale);
110
111 propName = "StatusBarFunction";
112 sal_Int16 aStatusBarFunction = 42;
113 CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aStatusBarFunction);
114 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue StatusBarFunction", sal_Int16(514),
115 aStatusBarFunction);
116
117 aNewValue <<= sal_Int16(1);
118 xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
119 CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aStatusBarFunction);
120 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue StatusBarFunction", sal_Int16(1),
121 aStatusBarFunction);
122
123 propName = "UserLists";
124 uno::Sequence<OUString> aSeq{
125 "Sun,Mon,Tue,Wed,Thu,Fri,Sat",
126 "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday",
127 "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",
128 "January,February,March,April,May,June,July,August,September,October,November,December",
129 "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Shabbat",
130 "Nissan,Iyar,Sivan,Tammuz,Av,Elul,Tishri,Heshvan,Kislev,Tevet,Shevat,Adar,Adar B"
131 };
132
133 uno::Sequence<OUString> aUserLists;
134 CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aUserLists);
135 for (auto i = 0; i < aUserLists.getLength(); i++)
136 {
137 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue UserLists[" + std::to_string(i)
138 + "]",
139 aSeq[i], aUserLists[i]);
140 }
141
142 aNewValue <<= uno::Sequence<OUString>();
143 xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
144 CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aUserLists);
145 CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue UserLists", !aUserLists.hasElements());
146}
147}
148
149/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual css::uno::Reference< css::uno::XInterface > init()=0
Sequence< sal_Int8 > aSeq
Reference< XComponentContext > getProcessComponentContext()
int i
args
OUString sMessage