nss: upgrade to release 3.73
[LibreOffice.git] / test / source / sheet / sheetcellrange.cxx
blob93d121b3b46de0bf6d53cedf779545be7b809268
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/sheetcellrange.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/uno/Any.hxx>
20 #include <com/sun/star/uno/Reference.hxx>
21 #include <com/sun/star/uno/Sequence.hxx>
23 #include <cppunit/TestAssert.h>
25 using namespace com::sun::star;
26 using namespace com::sun::star::uno;
28 namespace apitest
30 void SheetCellRange::testSheetCellRangeProperties()
32 uno::Reference<beans::XPropertySet> xSheetCellRange(init(), UNO_QUERY_THROW);
33 OUString propName;
34 uno::Any aNewValue;
36 propName = "Position";
37 awt::Point aPositionGet;
38 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Position",
39 xSheetCellRange->getPropertyValue(propName) >>= aPositionGet);
41 awt::Point aPositionSet(42, 42);
42 aNewValue <<= aPositionSet;
43 xSheetCellRange->setPropertyValue(propName, aNewValue);
44 CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aPositionSet);
45 CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue Position", aPositionGet, aPositionGet);
47 propName = "Size";
48 awt::Size aSizeGet;
49 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Size",
50 xSheetCellRange->getPropertyValue(propName) >>= aSizeGet);
52 awt::Size aSizeSet(42, 42);
53 aNewValue <<= aSizeGet;
54 xSheetCellRange->setPropertyValue(propName, aNewValue);
55 CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aSizeSet);
56 CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue Size", aSizeGet, aSizeSet);
58 uno::Sequence<beans::PropertyValue> aPropValue(1);
59 aPropValue[0].Name = "StyleName";
60 aPropValue[0].Value <<= OUString("Result2");
62 propName = "ConditionalFormat";
63 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatGet;
64 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatSet;
66 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormat",
67 xSheetCellRange->getPropertyValue(propName) >>= aConditionalFormatGet);
69 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatNew(aConditionalFormatGet,
70 UNO_SET_THROW);
71 aConditionalFormatNew->addNew(aPropValue);
73 aNewValue <<= aConditionalFormatNew;
74 xSheetCellRange->setPropertyValue(propName, aNewValue);
75 CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aConditionalFormatSet);
76 for (auto i = 0; i < aConditionalFormatSet->getCount(); i++)
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);
83 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ConditionalFormat["
84 + std::to_string(i) + "]",
85 xSCENew->getStyleName(), xSCESet->getStyleName());
88 propName = "ConditionalFormatLocal";
89 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalGet;
90 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalSet;
92 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormatLocal",
93 xSheetCellRange->getPropertyValue(propName)
94 >>= aConditionalFormatLocalGet);
96 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalNew(
97 aConditionalFormatLocalGet, UNO_SET_THROW);
98 aConditionalFormatLocalNew->addNew(aPropValue);
100 aNewValue <<= aConditionalFormatLocalNew;
101 xSheetCellRange->setPropertyValue(propName, aNewValue);
102 CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aConditionalFormatLocalSet);
103 for (auto i = 0; i < aConditionalFormatLocalSet->getCount(); i++)
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);
110 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ConditionalFormatLocal["
111 + std::to_string(i) + "]",
112 xSCENew->getStyleName(), xSCESet->getStyleName());
115 propName = "Validation";
116 uno::Reference<beans::XPropertySet> aValidationGet;
117 uno::Reference<beans::XPropertySet> aValidationSet;
119 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Validation",
120 xSheetCellRange->getPropertyValue(propName) >>= aValidationGet);
122 uno::Reference<beans::XPropertySet> aValidationNew(aValidationGet, UNO_SET_THROW);
123 uno::Any aValidationType;
124 aValidationType <<= sheet::ValidationType_WHOLE;
125 aValidationNew->setPropertyValue("Type", aValidationType);
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);
135 propName = "ValidationLocal";
136 uno::Reference<beans::XPropertySet> aValidationLocalGet;
137 uno::Reference<beans::XPropertySet> aValidationLocalSet;
139 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ValidationLocal",
140 xSheetCellRange->getPropertyValue(propName) >>= aValidationLocalGet);
142 uno::Reference<beans::XPropertySet> aValidationLocalNew(aValidationLocalGet, UNO_SET_THROW);
143 aValidationType <<= sheet::ValidationType_WHOLE;
144 aValidationLocalNew->setPropertyValue("Type", aValidationType);
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);
153 propName = "AbsoluteName";
154 OUString aAbsoluteNameGet = "";
155 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue AbsoluteName",
156 xSheetCellRange->getPropertyValue(propName) >>= aAbsoluteNameGet);
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);
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */