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/unoapi_test.hxx>
11 #include <test/beans/xpropertyset.hxx>
12 #include <test/container/xnamed.hxx>
14 #include <com/sun/star/beans/XPropertySet.hpp>
15 #include <com/sun/star/container/XIndexAccess.hpp>
16 #include <com/sun/star/container/XNameAccess.hpp>
17 #include <com/sun/star/container/XNameContainer.hpp>
18 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
19 #include <com/sun/star/sheet/XSpreadsheet.hpp>
20 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
21 #include <com/sun/star/style/XStyle.hpp>
22 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
23 #include <com/sun/star/table/XCell.hpp>
24 #include <com/sun/star/uno/XInterface.hpp>
26 #include <com/sun/star/uno/Any.hxx>
27 #include <com/sun/star/uno/Reference.hxx>
33 class ScStyleObj
: public UnoApiTest
, public apitest::XNamed
, public apitest::XPropertySet
38 virtual void setUp() override
;
40 virtual uno::Reference
<uno::XInterface
> init() override
;
42 CPPUNIT_TEST_SUITE(ScStyleObj
);
45 CPPUNIT_TEST(testGetName
);
46 CPPUNIT_TEST(testSetName
);
49 CPPUNIT_TEST(testGetPropertySetInfo
);
50 CPPUNIT_TEST(testGetPropertyValue
);
51 CPPUNIT_TEST(testSetPropertyValue
);
52 CPPUNIT_TEST(testPropertyChangeListener
);
53 CPPUNIT_TEST(testVetoableChangeListener
);
55 CPPUNIT_TEST_SUITE_END();
58 ScStyleObj::ScStyleObj()
59 : UnoApiTest(u
"/sc/qa/extras/testdocuments"_ustr
)
60 , XNamed(u
"ScStyleObj"_ustr
)
61 , XPropertySet({ u
"BottomBorder"_ustr
,
62 u
"BottomBorder2"_ustr
,
63 u
"BottomBorderComplexColor"_ustr
,
64 u
"CellProtection"_ustr
,
66 u
"CharLocaleAsian"_ustr
,
67 u
"CharLocaleComplex"_ustr
,
69 u
"CharPostureAsian"_ustr
,
70 u
"CharPostureComplex"_ustr
,
72 u
"DiagonalBLTR2"_ustr
,
74 u
"DiagonalTLBR2"_ustr
,
78 u
"LeftBorderComplexColor"_ustr
,
83 u
"RightBorderComplexColor"_ustr
,
88 u
"TopBorderComplexColor"_ustr
,
89 u
"UserDefinedAttributes"_ustr
,
90 u
"CellBackgroundComplexColor"_ustr
})
94 uno::Reference
<uno::XInterface
> ScStyleObj::init()
96 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, uno::UNO_QUERY_THROW
);
98 uno::Reference
<style::XStyleFamiliesSupplier
> xSFS(xDoc
, uno::UNO_QUERY_THROW
);
99 uno::Reference
<container::XNameAccess
> xNA_StyleFamilies(xSFS
->getStyleFamilies(),
101 uno::Reference
<container::XIndexAccess
> xIA_StyleFamilies(xNA_StyleFamilies
,
102 uno::UNO_QUERY_THROW
);
103 uno::Reference
<container::XNameAccess
> xNA_StyleFamily(xIA_StyleFamilies
->getByIndex(0),
104 uno::UNO_QUERY_THROW
);
106 uno::Reference
<lang::XMultiServiceFactory
> xMSF(xDoc
, uno::UNO_QUERY_THROW
);
107 uno::Reference
<style::XStyle
> xStyle(xMSF
->createInstance(u
"com.sun.star.style.CellStyle"_ustr
),
108 uno::UNO_QUERY_THROW
);
109 uno::Reference
<container::XNameContainer
> xNC(xNA_StyleFamily
, uno::UNO_QUERY_THROW
);
110 if (xNC
->hasByName(u
"ScStyleObj"_ustr
))
112 xNC
->removeByName(u
"ScStyleObj"_ustr
);
114 xNC
->insertByName(u
"ScStyleObj"_ustr
, uno::Any(xStyle
));
116 uno::Reference
<container::XIndexAccess
> xIA_sheets(xDoc
->getSheets(), uno::UNO_QUERY_THROW
);
117 uno::Reference
<sheet::XSpreadsheet
> xSheet0(xIA_sheets
->getByIndex(0), uno::UNO_QUERY_THROW
);
118 uno::Reference
<table::XCell
> xCell
= xSheet0
->getCellByPosition(2, 3);
119 uno::Reference
<beans::XPropertySet
> xPS(xCell
, uno::UNO_QUERY_THROW
);
120 xPS
->setPropertyValue(u
"CellStyle"_ustr
, uno::Any(xStyle
->getName()));
125 void ScStyleObj::setUp()
128 // create calc document
129 loadFromURL(u
"private:factory/scalc"_ustr
);
132 CPPUNIT_TEST_SUITE_REGISTRATION(ScStyleObj
);
134 } // namespace sc_apitest
136 CPPUNIT_PLUGIN_IMPLEMENT();
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */