LibreOffice Module test (master) 1
sheetcellranges.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
11
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>
19
21#include <cppunit/TestAssert.h>
22
23using namespace com::sun::star;
24using namespace com::sun::star::uno;
25
26namespace apitest
27{
29{
30 uno::Reference<beans::XPropertySet> xSheetCellRanges(init(), UNO_QUERY_THROW);
31 OUString propName;
32 uno::Any aNewValue;
33
34 uno::Sequence<beans::PropertyValue> aPropValue{ comphelper::makePropertyValue(
35 "StyleName", OUString("Result2")) };
36
37 propName = "ConditionalFormat";
38 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatGet;
39 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatSet;
40
41 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormat",
42 xSheetCellRanges->getPropertyValue(propName) >>= aConditionalFormatGet);
43
44 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatNew(aConditionalFormatGet,
45 UNO_SET_THROW);
46 aConditionalFormatNew->addNew(aPropValue);
47
48 aNewValue <<= aConditionalFormatNew;
49 xSheetCellRanges->setPropertyValue(propName, aNewValue);
50 CPPUNIT_ASSERT(xSheetCellRanges->getPropertyValue(propName) >>= aConditionalFormatSet);
51 for (auto i = 0; i < aConditionalFormatSet->getCount(); i++)
52 {
53 uno::Reference<sheet::XSheetConditionalEntry> xSCENew(aConditionalFormatNew->getByIndex(i),
54 UNO_QUERY_THROW);
55 uno::Reference<sheet::XSheetConditionalEntry> xSCESet(aConditionalFormatSet->getByIndex(i),
56 UNO_QUERY_THROW);
57
58 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ConditionalFormat["
59 + std::to_string(i) + "]",
60 xSCENew->getStyleName(), xSCESet->getStyleName());
61 }
62
63 propName = "ConditionalFormatLocal";
64 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalGet;
65 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalSet;
66
67 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormatLocal",
68 xSheetCellRanges->getPropertyValue(propName)
69 >>= aConditionalFormatLocalGet);
70
71 uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalNew(
72 aConditionalFormatLocalGet, UNO_SET_THROW);
73 aConditionalFormatLocalNew->addNew(aPropValue);
74
75 aNewValue <<= aConditionalFormatLocalNew;
76 xSheetCellRanges->setPropertyValue(propName, aNewValue);
77 CPPUNIT_ASSERT(xSheetCellRanges->getPropertyValue(propName) >>= aConditionalFormatLocalSet);
78 for (auto i = 0; i < aConditionalFormatLocalSet->getCount(); i++)
79 {
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);
84
85 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ConditionalFormatLocal["
86 + std::to_string(i) + "]",
87 xSCENew->getStyleName(), xSCESet->getStyleName());
88 }
89
90 propName = "Validation";
91 uno::Reference<beans::XPropertySet> aValidationGet;
92 uno::Reference<beans::XPropertySet> aValidationSet;
93
94 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Validation",
95 xSheetCellRanges->getPropertyValue(propName) >>= aValidationGet);
96
97 uno::Reference<beans::XPropertySet> aValidationNew(aValidationGet, UNO_SET_THROW);
98 uno::Any aValidationType;
99 aValidationType <<= sheet::ValidationType_WHOLE;
100 aValidationNew->setPropertyValue("Type", aValidationType);
101
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);
109
110 propName = "ValidationLocal";
111 uno::Reference<beans::XPropertySet> aValidationLocalGet;
112 uno::Reference<beans::XPropertySet> aValidationLocalSet;
113
114 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ValidationLocal",
115 xSheetCellRanges->getPropertyValue(propName) >>= aValidationLocalGet);
116
117 uno::Reference<beans::XPropertySet> aValidationLocalNew(aValidationLocalGet, UNO_SET_THROW);
118 aValidationType <<= sheet::ValidationType_WHOLE;
119 aValidationLocalNew->setPropertyValue("Type", aValidationType);
120
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);
127
128 propName = "AbsoluteName";
129 OUString aAbsoluteNameGet = "";
130 CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue AbsoluteName",
131 xSheetCellRanges->getPropertyValue(propName) >>= aAbsoluteNameGet);
132
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,
138 aAbsoluteNameSet);
139}
140}
141
142/* 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