LibreOffice Module test (master) 1
sheetcellrange.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
12
13#include <com/sun/star/awt/Point.hpp>
14#include <com/sun/star/awt/Size.hpp>
15#include <com/sun/star/beans/XPropertySet.hpp>
16#include <com/sun/star/sheet/ValidationType.hpp>
17#include <com/sun/star/sheet/XSheetConditionalEntry.hpp>
18#include <com/sun/star/sheet/XSheetConditionalEntries.hpp>
19#include <com/sun/star/uno/Any.hxx>
20#include <com/sun/star/uno/Reference.hxx>
21#include <com/sun/star/uno/Sequence.hxx>
22
24#include <cppunit/TestAssert.h>
25
26using namespace com::sun::star;
27using namespace com::sun::star::uno;
28
29namespace apitest
30{
32{
33 uno::Reference<beans::XPropertySet> xSheetCellRange(init(), UNO_QUERY_THROW);
34 OUString propName;
35 uno::Any aNewValue;
36
37 propName = "Position";
38 awt::Point aPositionGet;
39 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Position",
40 xSheetCellRange->getPropertyValue(propName) >>= aPositionGet);
41
42 awt::Point aPositionSet(42, 42);
43 aNewValue <<= aPositionSet;
44 xSheetCellRange->setPropertyValue(propName, aNewValue);
45 CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aPositionSet);
46 CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue Position", aPositionGet, aPositionGet);
47
48 propName = "Size";
49 awt::Size aSizeGet;
50 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Size",
51 xSheetCellRange->getPropertyValue(propName) >>= aSizeGet);
52
53 awt::Size aSizeSet(42, 42);
54 aNewValue <<= aSizeGet;
55 xSheetCellRange->setPropertyValue(propName, aNewValue);
56 CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aSizeSet);
57 CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue Size", aSizeGet, aSizeSet);
58
59 uno::Sequence<beans::PropertyValue> aPropValue{ comphelper::makePropertyValue(
60 "StyleName", OUString("Result2")) };
61
62 propName = "ConditionalFormat";
63 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatGet;
64 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatSet;
65
66 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormat",
67 xSheetCellRange->getPropertyValue(propName) >>= aConditionalFormatGet);
68
69 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatNew(aConditionalFormatGet,
70 UNO_SET_THROW);
71 aConditionalFormatNew->addNew(aPropValue);
72
73 aNewValue <<= aConditionalFormatNew;
74 xSheetCellRange->setPropertyValue(propName, aNewValue);
75 CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aConditionalFormatSet);
76 for (auto i = 0; i < aConditionalFormatSet->getCount(); i++)
77 {
78 uno::Reference<sheet::XSheetConditionalEntry> xSCENew(aConditionalFormatNew->getByIndex(i),
79 UNO_QUERY_THROW);
80 uno::Reference<sheet::XSheetConditionalEntry> xSCESet(aConditionalFormatSet->getByIndex(i),
81 UNO_QUERY_THROW);
82
83 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ConditionalFormat["
84 + std::to_string(i) + "]",
85 xSCENew->getStyleName(), xSCESet->getStyleName());
86 }
87
88 propName = "ConditionalFormatLocal";
89 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalGet;
90 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalSet;
91
92 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormatLocal",
93 xSheetCellRange->getPropertyValue(propName)
94 >>= aConditionalFormatLocalGet);
95
96 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalNew(
97 aConditionalFormatLocalGet, UNO_SET_THROW);
98 aConditionalFormatLocalNew->addNew(aPropValue);
99
100 aNewValue <<= aConditionalFormatLocalNew;
101 xSheetCellRange->setPropertyValue(propName, aNewValue);
102 CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aConditionalFormatLocalSet);
103 for (auto i = 0; i < aConditionalFormatLocalSet->getCount(); i++)
104 {
105 uno::Reference<sheet::XSheetConditionalEntry> xSCENew(
106 aConditionalFormatLocalNew->getByIndex(i), UNO_QUERY_THROW);
107 uno::Reference<sheet::XSheetConditionalEntry> xSCESet(
108 aConditionalFormatLocalSet->getByIndex(i), UNO_QUERY_THROW);
109
110 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ConditionalFormatLocal["
111 + std::to_string(i) + "]",
112 xSCENew->getStyleName(), xSCESet->getStyleName());
113 }
114
115 propName = "Validation";
116 uno::Reference<beans::XPropertySet> aValidationGet;
117 uno::Reference<beans::XPropertySet> aValidationSet;
118
119 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Validation",
120 xSheetCellRange->getPropertyValue(propName) >>= aValidationGet);
121
122 uno::Reference<beans::XPropertySet> aValidationNew(aValidationGet, UNO_SET_THROW);
123 uno::Any aValidationType;
124 aValidationType <<= sheet::ValidationType_WHOLE;
125 aValidationNew->setPropertyValue("Type", aValidationType);
126
127 aNewValue <<= aValidationNew;
128 xSheetCellRange->setPropertyValue(propName, aNewValue);
129 CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aValidationSet);
130 sheet::ValidationType aType;
131 aValidationSet->getPropertyValue("Type") >>= aType;
132 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue Validation",
133 sheet::ValidationType_WHOLE, aType);
134
135 propName = "ValidationLocal";
136 uno::Reference<beans::XPropertySet> aValidationLocalGet;
137 uno::Reference<beans::XPropertySet> aValidationLocalSet;
138
139 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ValidationLocal",
140 xSheetCellRange->getPropertyValue(propName) >>= aValidationLocalGet);
141
142 uno::Reference<beans::XPropertySet> aValidationLocalNew(aValidationLocalGet, UNO_SET_THROW);
143 aValidationType <<= sheet::ValidationType_WHOLE;
144 aValidationLocalNew->setPropertyValue("Type", aValidationType);
145
146 aNewValue <<= aValidationLocalNew;
147 xSheetCellRange->setPropertyValue(propName, aNewValue);
148 CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aValidationLocalSet);
149 aValidationLocalSet->getPropertyValue("Type") >>= aType;
150 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ValidationLocal",
151 sheet::ValidationType_WHOLE, aType);
152
153 propName = "AbsoluteName";
154 OUString aAbsoluteNameGet = "";
155 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue AbsoluteName",
156 xSheetCellRange->getPropertyValue(propName) >>= aAbsoluteNameGet);
157
158 OUString aAbsoluteNameSet = "$Sheet1.$C$3";
159 aNewValue <<= aAbsoluteNameSet;
160 xSheetCellRange->setPropertyValue(propName, aNewValue);
161 CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aAbsoluteNameSet);
162 CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue AbsoluteName", aAbsoluteNameGet,
163 aAbsoluteNameSet);
164}
165}
166
167/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual css::uno::Reference< css::uno::XInterface > init()=0
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
int i