bump product version to 7.2.5.1
[LibreOffice.git] / test / source / sheet / sheetcell.cxx
blobe30847367b7d90ddbc437bb6859fcc8959518829
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.
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 */
10 #include <test/cppunitasserthelper.hxx>
11 #include <test/sheet/sheetcell.hxx>
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>
24 #include <cppunit/TestAssert.h>
26 using namespace com::sun::star;
27 using namespace com::sun::star::uno;
29 namespace apitest
31 void SheetCell::testSheetCellProperties()
33 uno::Reference<beans::XPropertySet> xSheetCell(init(), UNO_QUERY_THROW);
34 OUString propName;
35 uno::Any aNewValue;
37 propName = "Position";
38 awt::Point aPositionGet;
39 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Position",
40 xSheetCell->getPropertyValue(propName) >>= aPositionGet);
42 awt::Point aPositionSet(42, 42);
43 aNewValue <<= aPositionSet;
44 xSheetCell->setPropertyValue(propName, aNewValue);
45 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aPositionSet);
46 CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue Position", aPositionGet, aPositionGet);
48 propName = "Size";
49 awt::Size aSizeGet;
50 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Size",
51 xSheetCell->getPropertyValue(propName) >>= aSizeGet);
53 awt::Size aSizeSet(42, 42);
54 aNewValue <<= aSizeGet;
55 xSheetCell->setPropertyValue(propName, aNewValue);
56 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aSizeSet);
57 CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue Size", aSizeGet, aSizeSet);
59 propName = "FormulaLocal";
60 OUString aFormulaLocal = "";
61 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue FormulaLocal",
62 xSheetCell->getPropertyValue(propName) >>= aFormulaLocal);
64 aNewValue <<= OUString("FormulaLocal");
65 xSheetCell->setPropertyValue(propName, aNewValue);
66 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aFormulaLocal);
67 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue FormulaLocal",
68 OUString("FormulaLocal"), aFormulaLocal);
70 propName = "CellContentType";
71 table::CellContentType aCellContentTypeGet;
72 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue CellContentType",
73 xSheetCell->getPropertyValue(propName) >>= aCellContentTypeGet);
75 table::CellContentType aCellContentTypeSet = table::CellContentType_TEXT;
76 aNewValue <<= aCellContentTypeSet;
77 xSheetCell->setPropertyValue(propName, aNewValue);
78 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aCellContentTypeSet);
79 CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue CellContentType", aCellContentTypeGet,
80 aCellContentTypeSet);
82 // Special case, because the API returns the wrong type.
83 propName = "FormulaResultType";
84 table::CellContentType aFormulaResultTypeGet;
85 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue FormulaResultType",
86 xSheetCell->getPropertyValue(propName) >>= aFormulaResultTypeGet);
88 table::CellContentType aFormulaResultTypeSet = table::CellContentType_TEXT;
89 aNewValue <<= aFormulaResultTypeSet;
90 xSheetCell->setPropertyValue(propName, aNewValue);
91 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aFormulaResultTypeSet);
92 CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue FormulaResultType",
93 aFormulaResultTypeGet, aFormulaResultTypeSet);
95 propName = "FormulaResultType2";
96 sal_Int32 aFormulaResultType2Get = 42;
97 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue FormulaResultType2",
98 xSheetCell->getPropertyValue(propName) >>= aFormulaResultType2Get);
100 sal_Int32 aFormulaResultType2Set = 42;
101 aNewValue <<= aFormulaResultType2Set;
102 xSheetCell->setPropertyValue(propName, aNewValue);
103 CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aFormulaResultType2Set);
104 CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue FormulaResultType2",
105 aFormulaResultType2Get, aFormulaResultType2Set);
107 uno::Sequence<beans::PropertyValue> aPropValue(1);
108 aPropValue[0].Name = "StyleName";
109 aPropValue[0].Value <<= 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,
119 UNO_SET_THROW);
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),
128 UNO_QUERY_THROW);
129 uno::Reference<sheet::XSheetConditionalEntry> xSCESet(aConditionalFormatSet->getByIndex(i),
130 UNO_QUERY_THROW);
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);
171 uno::Any aValidationType;
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,
211 aAbsoluteNameSet);
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */