LibreOffice Module test (master)  1
spreadsheet.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/beans/XPropertySet.hpp>
14 #include <com/sun/star/container/XIndexAccess.hpp>
15 #include <com/sun/star/container/XNameContainer.hpp>
16 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
17 #include <com/sun/star/sheet/XConditionalFormats.hpp>
18 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
19 #include <com/sun/star/sheet/XSpreadsheet.hpp>
20 #include <com/sun/star/text/WritingMode2.hpp>
21 #include <com/sun/star/util/Color.hpp>
22 #include <com/sun/star/uno/Any.hxx>
23 #include <com/sun/star/uno/Reference.hxx>
24 
25 #include <cppunit/TestAssert.h>
26 
27 using namespace com::sun::star;
28 using namespace com::sun::star::uno;
29 
30 namespace apitest
31 {
32 void Spreadsheet::testSpreadsheetProperties()
33 {
34  uno::Reference<beans::XPropertySet> xSpreadsheet(init(), UNO_QUERY_THROW);
35  OUString propName;
36  uno::Any aNewValue;
37 
38  propName = "IsVisible";
39  testBooleanProperty(xSpreadsheet, propName);
40 
41  propName = "PageStyle";
42  testStringProperty(xSpreadsheet, propName, "Report");
43 
44  propName = "TableLayout";
45  testShortProperty(xSpreadsheet, propName, text::WritingMode2::RL_TB);
46 
47  propName = "AutomaticPrintArea";
48  testBooleanProperty(xSpreadsheet, propName);
49 
50  propName = "TabColor";
51  util::Color aColorGet;
52  util::Color aColorSet;
53  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue: TabColor",
54  xSpreadsheet->getPropertyValue(propName) >>= aColorGet);
55 
56  aNewValue <<= util::Color(42);
57  xSpreadsheet->setPropertyValue(propName, aNewValue);
58  CPPUNIT_ASSERT(xSpreadsheet->getPropertyValue(propName) >>= aColorSet);
59  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue: TabColor", util::Color(42),
60  aColorSet);
61 
62  propName = "ConditionalFormats";
63  uno::Reference<sheet::XConditionalFormats> xConditionalFormatsGet;
64  uno::Reference<sheet::XConditionalFormats> xConditionalFormatsSet;
65  CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue: ConditionalFormats",
66  xSpreadsheet->getPropertyValue(propName) >>= xConditionalFormatsGet);
67 
68  uno::Reference<sheet::XSpreadsheetDocument> xDoc(getXSpreadsheetDocument(), UNO_QUERY_THROW);
69  uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW);
70  uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW);
71 
72  uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, UNO_QUERY_THROW);
73  uno::Reference<container::XNameContainer> xRanges(
74  xMSF->createInstance("com.sun.star.sheet.SheetCellRanges"), UNO_QUERY_THROW);
75  uno::Reference<sheet::XSheetCellRanges> xSheetCellRanges(xRanges, UNO_QUERY_THROW);
76 
77  uno::Any xCellRange;
78  xCellRange <<= xSheet->getCellRangeByName("C1:D4");
79  xRanges->insertByName("Range1", xCellRange);
80  xConditionalFormatsGet->createByRange(xSheetCellRanges);
81 
82  aNewValue <<= xConditionalFormatsGet;
83  xSpreadsheet->setPropertyValue(propName, aNewValue);
84  CPPUNIT_ASSERT(xSpreadsheet->getPropertyValue(propName) >>= xConditionalFormatsSet);
85  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue: ConditionalFormats", sal_Int32(1),
86  xConditionalFormatsSet->getLength());
87 }
88 }
89 
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
void testShortProperty(uno::Reference< beans::XPropertySet > const &xPropertySet, const OUString &name, const sal_Int16 &nValue)
void testBooleanProperty(uno::Reference< beans::XPropertySet > const &xPropertySet, const OUString &name)
FILE * init(int, char **)
void testStringProperty(uno::Reference< beans::XPropertySet > const &xPropertySet, const OUString &name, const OUString &rValue)