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/table/CellContentType.hpp>
20#include <com/sun/star/uno/Any.hxx>
21#include <com/sun/star/uno/Reference.hxx>
22#include <com/sun/star/uno/Sequence.hxx>
25#include <cppunit/TestAssert.h>
34 uno::Reference<beans::XPropertySet> xSheetCell(
init(), UNO_QUERY_THROW);
38 propName =
"Position";
39 awt::Point aPositionGet;
40 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue Position",
41 xSheetCell->getPropertyValue(propName) >>= aPositionGet);
43 awt::Point aPositionSet(42, 42);
44 aNewValue <<= aPositionSet;
45 xSheetCell->setPropertyValue(propName, aNewValue);
46 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aPositionSet);
47 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Able to set PropertyValue Position", aPositionGet, aPositionGet);
51 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue Size",
52 xSheetCell->getPropertyValue(propName) >>= aSizeGet);
54 awt::Size aSizeSet(42, 42);
55 aNewValue <<= aSizeGet;
56 xSheetCell->setPropertyValue(propName, aNewValue);
57 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aSizeSet);
58 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Able to set PropertyValue Size", aSizeGet, aSizeSet);
60 propName =
"FormulaLocal";
61 OUString aFormulaLocal =
"";
62 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue FormulaLocal",
63 xSheetCell->getPropertyValue(propName) >>= aFormulaLocal);
65 aNewValue <<= OUString(
"FormulaLocal");
66 xSheetCell->setPropertyValue(propName, aNewValue);
67 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aFormulaLocal);
68 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Unable to set PropertyValue FormulaLocal",
69 OUString(
"FormulaLocal"), aFormulaLocal);
71 propName =
"CellContentType";
72 table::CellContentType aCellContentTypeGet;
73 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue CellContentType",
74 xSheetCell->getPropertyValue(propName) >>= aCellContentTypeGet);
76 table::CellContentType aCellContentTypeSet = table::CellContentType_TEXT;
77 aNewValue <<= aCellContentTypeSet;
78 xSheetCell->setPropertyValue(propName, aNewValue);
79 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aCellContentTypeSet);
80 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Able to set PropertyValue CellContentType", aCellContentTypeGet,
84 propName =
"FormulaResultType";
85 table::CellContentType aFormulaResultTypeGet;
86 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue FormulaResultType",
87 xSheetCell->getPropertyValue(propName) >>= aFormulaResultTypeGet);
89 table::CellContentType aFormulaResultTypeSet = table::CellContentType_TEXT;
90 aNewValue <<= aFormulaResultTypeSet;
91 xSheetCell->setPropertyValue(propName, aNewValue);
92 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aFormulaResultTypeSet);
93 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Able to set PropertyValue FormulaResultType",
94 aFormulaResultTypeGet, aFormulaResultTypeSet);
96 propName =
"FormulaResultType2";
97 sal_Int32 aFormulaResultType2Get = 42;
98 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue FormulaResultType2",
99 xSheetCell->getPropertyValue(propName) >>= aFormulaResultType2Get);
101 sal_Int32 aFormulaResultType2Set = 42;
102 aNewValue <<= aFormulaResultType2Set;
103 xSheetCell->setPropertyValue(propName, aNewValue);
104 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aFormulaResultType2Set);
105 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Able to set PropertyValue FormulaResultType2",
106 aFormulaResultType2Get, aFormulaResultType2Set);
109 "StyleName", OUString(
"Result2")) };
111 propName =
"ConditionalFormat";
112 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatGet;
113 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatSet;
115 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue ConditionalFormat",
116 xSheetCell->getPropertyValue(propName) >>= aConditionalFormatGet);
118 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatNew(aConditionalFormatGet,
120 aConditionalFormatNew->addNew(aPropValue);
122 aNewValue <<= aConditionalFormatNew;
123 xSheetCell->setPropertyValue(propName, aNewValue);
124 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aConditionalFormatSet);
125 for (
auto i = 0;
i < aConditionalFormatSet->getCount();
i++)
127 uno::Reference<sheet::XSheetConditionalEntry> xSCENew(aConditionalFormatNew->getByIndex(
i),
129 uno::Reference<sheet::XSheetConditionalEntry> xSCESet(aConditionalFormatSet->getByIndex(
i),
132 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Unable to set PropertyValue ConditionalFormat["
133 + std::to_string(
i) +
"]",
134 xSCENew->getStyleName(), xSCESet->getStyleName());
137 propName =
"ConditionalFormatLocal";
138 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalGet;
139 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalSet;
141 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue ConditionalFormatLocal",
142 xSheetCell->getPropertyValue(propName) >>= aConditionalFormatLocalGet);
144 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalNew(
145 aConditionalFormatLocalGet, UNO_SET_THROW);
146 aConditionalFormatLocalNew->addNew(aPropValue);
148 aNewValue <<= aConditionalFormatLocalNew;
149 xSheetCell->setPropertyValue(propName, aNewValue);
150 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aConditionalFormatLocalSet);
151 for (
auto i = 0;
i < aConditionalFormatLocalSet->getCount();
i++)
153 uno::Reference<sheet::XSheetConditionalEntry> xSCENew(
154 aConditionalFormatLocalNew->getByIndex(
i), UNO_QUERY_THROW);
155 uno::Reference<sheet::XSheetConditionalEntry> xSCESet(
156 aConditionalFormatLocalSet->getByIndex(
i), UNO_QUERY_THROW);
158 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Unable to set PropertyValue ConditionalFormatLocal["
159 + std::to_string(
i) +
"]",
160 xSCENew->getStyleName(), xSCESet->getStyleName());
163 propName =
"Validation";
164 uno::Reference<beans::XPropertySet> aValidationGet;
165 uno::Reference<beans::XPropertySet> aValidationSet;
167 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue Validation",
168 xSheetCell->getPropertyValue(propName) >>= aValidationGet);
170 uno::Reference<beans::XPropertySet> aValidationNew(aValidationGet, UNO_SET_THROW);
172 aValidationType <<= sheet::ValidationType_WHOLE;
173 aValidationNew->setPropertyValue(
"Type", aValidationType);
175 aNewValue <<= aValidationNew;
176 xSheetCell->setPropertyValue(propName, aNewValue);
177 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aValidationSet);
178 sheet::ValidationType aType;
179 aValidationSet->getPropertyValue(
"Type") >>= aType;
180 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Unable to set PropertyValue Validation",
181 sheet::ValidationType_WHOLE, aType);
183 propName =
"ValidationLocal";
184 uno::Reference<beans::XPropertySet> aValidationLocalGet;
185 uno::Reference<beans::XPropertySet> aValidationLocalSet;
187 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue ValidationLocal",
188 xSheetCell->getPropertyValue(propName) >>= aValidationLocalGet);
190 uno::Reference<beans::XPropertySet> aValidationLocalNew(aValidationLocalGet, UNO_SET_THROW);
191 aValidationType <<= sheet::ValidationType_WHOLE;
192 aValidationLocalNew->setPropertyValue(
"Type", aValidationType);
194 aNewValue <<= aValidationLocalNew;
195 xSheetCell->setPropertyValue(propName, aNewValue);
196 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aValidationLocalSet);
197 aValidationLocalSet->getPropertyValue(
"Type") >>= aType;
198 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Unable to set PropertyValue ValidationLocal",
199 sheet::ValidationType_WHOLE, aType);
201 propName =
"AbsoluteName";
202 OUString aAbsoluteNameGet =
"";
203 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue AbsoluteName",
204 xSheetCell->getPropertyValue(propName) >>= aAbsoluteNameGet);
206 OUString aAbsoluteNameSet =
"$Sheet1.$C$3";
207 aNewValue <<= aAbsoluteNameSet;
208 xSheetCell->setPropertyValue(propName, aNewValue);
209 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aAbsoluteNameSet);
210 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Able to set PropertyValue AbsoluteName", aAbsoluteNameGet,
void testSheetCellProperties()
virtual css::uno::Reference< css::uno::XInterface > init()=0
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)