1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <test/sheet/sheetcellranges.hxx>
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/sheet/ValidationType.hpp>
14 #include <com/sun/star/sheet/XSheetConditionalEntry.hpp>
15 #include <com/sun/star/sheet/XSheetConditionalEntries.hpp>
16 #include <com/sun/star/uno/Any.hxx>
17 #include <com/sun/star/uno/Reference.hxx>
18 #include <com/sun/star/uno/Sequence.hxx>
20 #include <cppunit/TestAssert.h>
22 using namespace com::sun::star
;
23 using namespace com::sun::star::uno
;
27 void SheetCellRanges::testSheetCellRangesProperties()
29 uno::Reference
<beans::XPropertySet
> xSheetCellRanges(init(), UNO_QUERY_THROW
);
33 uno::Sequence
<beans::PropertyValue
> aPropValue(1);
34 aPropValue
[0].Name
= "StyleName";
35 aPropValue
[0].Value
<<= OUString("Result2");
37 propName
= "ConditionalFormat";
38 uno::Reference
<sheet::XSheetConditionalEntries
> aConditionalFormatGet
;
39 uno::Reference
<sheet::XSheetConditionalEntries
> aConditionalFormatSet
;
41 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormat",
42 xSheetCellRanges
->getPropertyValue(propName
) >>= aConditionalFormatGet
);
44 uno::Reference
<sheet::XSheetConditionalEntries
> aConditionalFormatNew(aConditionalFormatGet
,
46 aConditionalFormatNew
->addNew(aPropValue
);
48 aNewValue
<<= aConditionalFormatNew
;
49 xSheetCellRanges
->setPropertyValue(propName
, aNewValue
);
50 CPPUNIT_ASSERT(xSheetCellRanges
->getPropertyValue(propName
) >>= aConditionalFormatSet
);
51 for (auto i
= 0; i
< aConditionalFormatSet
->getCount(); i
++)
53 uno::Reference
<sheet::XSheetConditionalEntry
> xSCENew(aConditionalFormatNew
->getByIndex(i
),
55 uno::Reference
<sheet::XSheetConditionalEntry
> xSCESet(aConditionalFormatSet
->getByIndex(i
),
58 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ConditionalFormat["
59 + std::to_string(i
) + "]",
60 xSCENew
->getStyleName(), xSCESet
->getStyleName());
63 propName
= "ConditionalFormatLocal";
64 uno::Reference
<sheet::XSheetConditionalEntries
> aConditionalFormatLocalGet
;
65 uno::Reference
<sheet::XSheetConditionalEntries
> aConditionalFormatLocalSet
;
67 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormatLocal",
68 xSheetCellRanges
->getPropertyValue(propName
)
69 >>= aConditionalFormatLocalGet
);
71 uno::Reference
<sheet::XSheetConditionalEntries
> aConditionalFormatLocalNew(
72 aConditionalFormatLocalGet
, UNO_SET_THROW
);
73 aConditionalFormatLocalNew
->addNew(aPropValue
);
75 aNewValue
<<= aConditionalFormatLocalNew
;
76 xSheetCellRanges
->setPropertyValue(propName
, aNewValue
);
77 CPPUNIT_ASSERT(xSheetCellRanges
->getPropertyValue(propName
) >>= aConditionalFormatLocalSet
);
78 for (auto i
= 0; i
< aConditionalFormatLocalSet
->getCount(); i
++)
80 uno::Reference
<sheet::XSheetConditionalEntry
> xSCENew(
81 aConditionalFormatLocalNew
->getByIndex(i
), UNO_QUERY_THROW
);
82 uno::Reference
<sheet::XSheetConditionalEntry
> xSCESet(
83 aConditionalFormatLocalSet
->getByIndex(i
), UNO_QUERY_THROW
);
85 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ConditionalFormatLocal["
86 + std::to_string(i
) + "]",
87 xSCENew
->getStyleName(), xSCESet
->getStyleName());
90 propName
= "Validation";
91 uno::Reference
<beans::XPropertySet
> aValidationGet
;
92 uno::Reference
<beans::XPropertySet
> aValidationSet
;
94 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Validation",
95 xSheetCellRanges
->getPropertyValue(propName
) >>= aValidationGet
);
97 uno::Reference
<beans::XPropertySet
> aValidationNew(aValidationGet
, UNO_SET_THROW
);
98 uno::Any aValidationType
;
99 aValidationType
<<= sheet::ValidationType_WHOLE
;
100 aValidationNew
->setPropertyValue("Type", aValidationType
);
102 aNewValue
<<= aValidationNew
;
103 xSheetCellRanges
->setPropertyValue(propName
, aNewValue
);
104 CPPUNIT_ASSERT(xSheetCellRanges
->getPropertyValue(propName
) >>= aValidationSet
);
105 sheet::ValidationType aType
;
106 aValidationSet
->getPropertyValue("Type") >>= aType
;
107 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue Validation",
108 sheet::ValidationType_WHOLE
, aType
);
110 propName
= "ValidationLocal";
111 uno::Reference
<beans::XPropertySet
> aValidationLocalGet
;
112 uno::Reference
<beans::XPropertySet
> aValidationLocalSet
;
114 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ValidationLocal",
115 xSheetCellRanges
->getPropertyValue(propName
) >>= aValidationLocalGet
);
117 uno::Reference
<beans::XPropertySet
> aValidationLocalNew(aValidationLocalGet
, UNO_SET_THROW
);
118 aValidationType
<<= sheet::ValidationType_WHOLE
;
119 aValidationLocalNew
->setPropertyValue("Type", aValidationType
);
121 aNewValue
<<= aValidationLocalNew
;
122 xSheetCellRanges
->setPropertyValue(propName
, aNewValue
);
123 CPPUNIT_ASSERT(xSheetCellRanges
->getPropertyValue(propName
) >>= aValidationLocalSet
);
124 aValidationLocalSet
->getPropertyValue("Type") >>= aType
;
125 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ValidationLocal",
126 sheet::ValidationType_WHOLE
, aType
);
128 propName
= "AbsoluteName";
129 OUString aAbsoluteNameGet
= "";
130 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue AbsoluteName",
131 xSheetCellRanges
->getPropertyValue(propName
) >>= aAbsoluteNameGet
);
133 OUString aAbsoluteNameSet
= "$Sheet1.$C$3";
134 aNewValue
<<= aAbsoluteNameSet
;
135 xSheetCellRanges
->setPropertyValue(propName
, aNewValue
);
136 CPPUNIT_ASSERT(xSheetCellRanges
->getPropertyValue(propName
) >>= aAbsoluteNameSet
);
137 CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue AbsoluteName", aAbsoluteNameGet
,
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */