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>
21#include <cppunit/TestAssert.h>
30 uno::Reference<beans::XPropertySet> xGlobalSheetSettings(
init(), UNO_QUERY_THROW);
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);
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);
53 CPPUNIT_ASSERT_EQUAL_MESSAGE(
sMessage.getStr(), aOrigValue,
54 xGlobalSheetSettings->getPropertyValue(propName));
55 CPPUNIT_ASSERT_EQUAL_MESSAGE(
sMessage.getStr(), aOrigValue,
56 xRegNodeRO->getPropertyValue(regValueName));
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));
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));
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");
85 node =
"/org.openoffice.Office.Calc/Layout/Other/MeasureUnit";
86 DoCheck(
"Metric", sal_Int16(8), sal_Int16(1), node,
"NonMetric");
88 node =
"/org.openoffice.Office.Calc/Input";
89 DoCheck(
"DoAutoComplete",
true,
false, node,
"AutoInput");
91 node =
"/org.openoffice.Office.Calc/Content/Update";
92 DoCheck(
"LinkUpdateMode", sal_Int16(2), sal_Int16(1), node,
"Link");
94 node =
"/org.openoffice.Office.Calc/Print/";
95 DoCheck(
"PrintAllSheets",
false,
true, node +
"Other",
"AllSheets");
96 DoCheck(
"PrintEmptyPages",
false,
true, node +
"Page",
"EmptyPages");
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);
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);
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),
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),
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"
133 uno::Sequence<OUString> aUserLists;
134 CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aUserLists);
135 for (
auto i = 0;
i < aUserLists.getLength();
i++)
137 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Unable to get PropertyValue UserLists[" + std::to_string(
i)
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());
virtual css::uno::Reference< css::uno::XInterface > init()=0
void testGlobalSheetSettingsProperties()
Sequence< sal_Int8 > aSeq
Reference< XComponentContext > getProcessComponentContext()