Update git submodules
[LibreOffice.git] / sc / qa / extras / scstyleobj.cxx
blobb8a220126673005f85121d81db137a74517d21d7
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.
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 */
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>
29 using namespace css;
31 namespace sc_apitest
33 class ScStyleObj : public UnoApiTest, public apitest::XNamed, public apitest::XPropertySet
35 public:
36 ScStyleObj();
38 virtual void setUp() override;
40 virtual uno::Reference<uno::XInterface> init() override;
42 CPPUNIT_TEST_SUITE(ScStyleObj);
44 // XNamed
45 CPPUNIT_TEST(testGetName);
46 CPPUNIT_TEST(testSetName);
48 // XPropertySet
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,
65 u"CharLocale"_ustr,
66 u"CharLocaleAsian"_ustr,
67 u"CharLocaleComplex"_ustr,
68 u"CharPosture"_ustr,
69 u"CharPostureAsian"_ustr,
70 u"CharPostureComplex"_ustr,
71 u"DiagonalBLTR"_ustr,
72 u"DiagonalBLTR2"_ustr,
73 u"DiagonalTLBR"_ustr,
74 u"DiagonalTLBR2"_ustr,
75 u"HoriJustify"_ustr,
76 u"LeftBorder"_ustr,
77 u"LeftBorder2"_ustr,
78 u"LeftBorderComplexColor"_ustr,
79 u"NumberFormat"_ustr,
80 u"Orientation"_ustr,
81 u"RightBorder"_ustr,
82 u"RightBorder2"_ustr,
83 u"RightBorderComplexColor"_ustr,
84 u"ShadowFormat"_ustr,
85 u"TableBorder"_ustr,
86 u"TopBorder"_ustr,
87 u"TopBorder2"_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(),
100 uno::UNO_SET_THROW);
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()));
122 return xStyle;
125 void ScStyleObj::setUp()
127 UnoApiTest::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: */