LibreOffice Module test (master)  1
sheetcellrange.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 
12 
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>
22 
23 #include <cppunit/TestAssert.h>
24 
25 using namespace com::sun::star;
26 using namespace com::sun::star::uno;
27 
28 namespace apitest
29 {
30 void SheetCellRange::testSheetCellRangeProperties()
31 {
32  uno::Reference<beans::XPropertySet> xSheetCellRange(init(), UNO_QUERY_THROW);
33  OUString propName;
34  uno::Any aNewValue;
35 
36  propName = "Position";
37  awt::Point aPositionGet;
38  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Position",
39  xSheetCellRange->getPropertyValue(propName) >>= aPositionGet);
40 
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);
46 
47  propName = "Size";
48  awt::Size aSizeGet;
49  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Size",
50  xSheetCellRange->getPropertyValue(propName) >>= aSizeGet);
51 
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);
57 
58  uno::Sequence<beans::PropertyValue> aPropValue(1);
59  aPropValue[0].Name = "StyleName";
60  aPropValue[0].Value <<= OUString("Result2");
61 
62  propName = "ConditionalFormat";
63  uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatGet;
64  uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatSet;
65 
66  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormat",
67  xSheetCellRange->getPropertyValue(propName) >>= aConditionalFormatGet);
68 
69  uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatNew(aConditionalFormatGet,
70  UNO_SET_THROW);
71  aConditionalFormatNew->addNew(aPropValue);
72 
73  aNewValue <<= aConditionalFormatNew;
74  xSheetCellRange->setPropertyValue(propName, aNewValue);
75  CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aConditionalFormatSet);
76  for (auto i = 0; i < aConditionalFormatSet->getCount(); i++)
77  {
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);
82 
83  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ConditionalFormat["
84  + std::to_string(i) + "]",
85  xSCENew->getStyleName(), xSCESet->getStyleName());
86  }
87 
88  propName = "ConditionalFormatLocal";
89  uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalGet;
90  uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalSet;
91 
92  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormatLocal",
93  xSheetCellRange->getPropertyValue(propName)
94  >>= aConditionalFormatLocalGet);
95 
96  uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalNew(
97  aConditionalFormatLocalGet, UNO_SET_THROW);
98  aConditionalFormatLocalNew->addNew(aPropValue);
99 
100  aNewValue <<= aConditionalFormatLocalNew;
101  xSheetCellRange->setPropertyValue(propName, aNewValue);
102  CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aConditionalFormatLocalSet);
103  for (auto i = 0; i < aConditionalFormatLocalSet->getCount(); i++)
104  {
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);
109 
110  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ConditionalFormatLocal["
111  + std::to_string(i) + "]",
112  xSCENew->getStyleName(), xSCESet->getStyleName());
113  }
114 
115  propName = "Validation";
116  uno::Reference<beans::XPropertySet> aValidationGet;
117  uno::Reference<beans::XPropertySet> aValidationSet;
118 
119  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Validation",
120  xSheetCellRange->getPropertyValue(propName) >>= aValidationGet);
121 
122  uno::Reference<beans::XPropertySet> aValidationNew(aValidationGet, UNO_SET_THROW);
123  uno::Any aValidationType;
124  aValidationType <<= sheet::ValidationType_WHOLE;
125  aValidationNew->setPropertyValue("Type", aValidationType);
126 
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);
134 
135  propName = "ValidationLocal";
136  uno::Reference<beans::XPropertySet> aValidationLocalGet;
137  uno::Reference<beans::XPropertySet> aValidationLocalSet;
138 
139  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ValidationLocal",
140  xSheetCellRange->getPropertyValue(propName) >>= aValidationLocalGet);
141 
142  uno::Reference<beans::XPropertySet> aValidationLocalNew(aValidationLocalGet, UNO_SET_THROW);
143  aValidationType <<= sheet::ValidationType_WHOLE;
144  aValidationLocalNew->setPropertyValue("Type", aValidationType);
145 
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);
152 
153  propName = "AbsoluteName";
154  OUString aAbsoluteNameGet = "";
155  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue AbsoluteName",
156  xSheetCellRange->getPropertyValue(propName) >>= aAbsoluteNameGet);
157 
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);
164 }
165 }
166 
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
int i
FILE * init(int, char **)