nss: upgrade to release 3.73
[LibreOffice.git] / sc / qa / extras / scstyleobj.cxx
blob3ba41df3042f2b8ab4b582c2ec866c3b57d351d2
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/calc_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/XComponent.hpp>
19 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
20 #include <com/sun/star/sheet/XSpreadsheet.hpp>
21 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
22 #include <com/sun/star/style/XStyle.hpp>
23 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
24 #include <com/sun/star/table/XCell.hpp>
25 #include <com/sun/star/uno/XInterface.hpp>
27 #include <com/sun/star/uno/Any.hxx>
28 #include <com/sun/star/uno/Reference.hxx>
30 using namespace css;
32 namespace sc_apitest
34 class ScStyleObj : public CalcUnoApiTest, public apitest::XNamed, public apitest::XPropertySet
36 public:
37 ScStyleObj();
39 virtual void setUp() override;
40 virtual void tearDown() override;
42 virtual uno::Reference<uno::XInterface> init() override;
44 CPPUNIT_TEST_SUITE(ScStyleObj);
46 // XNamed
47 CPPUNIT_TEST(testGetName);
48 CPPUNIT_TEST(testSetName);
50 // XPropertySet
51 CPPUNIT_TEST(testGetPropertySetInfo);
52 CPPUNIT_TEST(testGetPropertyValue);
53 CPPUNIT_TEST(testSetPropertyValue);
54 CPPUNIT_TEST(testPropertyChangeListener);
55 CPPUNIT_TEST(testVetoableChangeListener);
57 CPPUNIT_TEST_SUITE_END();
59 private:
60 uno::Reference<lang::XComponent> m_xComponent;
63 ScStyleObj::ScStyleObj()
64 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
65 , XNamed("ScStyleObj")
66 , XPropertySet({
67 "BottomBorder", "BottomBorder2", "CellProtection", "CharLocale",
68 "CharLocaleAsian", "CharLocaleComplex", "CharPosture", "CharPostureAsian",
69 "CharPostureComplex", "DiagonalBLTR", "DiagonalBLTR2", "DiagonalTLBR",
70 "DiagonalTLBR2", "HoriJustify", "LeftBorder", "LeftBorder2",
71 "NumberFormat", "Orientation", "RightBorder", "RightBorder2",
72 "ShadowFormat", "TableBorder", "TopBorder", "TopBorder2",
73 "UserDefinedAttributes",
78 uno::Reference<uno::XInterface> ScStyleObj::init()
80 uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW);
82 uno::Reference<style::XStyleFamiliesSupplier> xSFS(xDoc, uno::UNO_QUERY_THROW);
83 uno::Reference<container::XNameAccess> xNA_StyleFamilies(xSFS->getStyleFamilies(),
84 uno::UNO_SET_THROW);
85 uno::Reference<container::XIndexAccess> xIA_StyleFamilies(xNA_StyleFamilies,
86 uno::UNO_QUERY_THROW);
87 uno::Reference<container::XNameAccess> xNA_StyleFamily(xIA_StyleFamilies->getByIndex(0),
88 uno::UNO_QUERY_THROW);
90 uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, uno::UNO_QUERY_THROW);
91 uno::Reference<style::XStyle> xStyle(xMSF->createInstance("com.sun.star.style.CellStyle"),
92 uno::UNO_QUERY_THROW);
93 uno::Reference<container::XNameContainer> xNC(xNA_StyleFamily, uno::UNO_QUERY_THROW);
94 if (xNC->hasByName("ScStyleObj"))
96 xNC->removeByName("ScStyleObj");
98 xNC->insertByName("ScStyleObj", uno::makeAny(xStyle));
100 uno::Reference<container::XIndexAccess> xIA_sheets(xDoc->getSheets(), uno::UNO_QUERY_THROW);
101 uno::Reference<sheet::XSpreadsheet> xSheet0(xIA_sheets->getByIndex(0), uno::UNO_QUERY_THROW);
102 uno::Reference<table::XCell> xCell = xSheet0->getCellByPosition(2, 3);
103 uno::Reference<beans::XPropertySet> xPS(xCell, uno::UNO_QUERY_THROW);
104 xPS->setPropertyValue("CellStyle", uno::makeAny(xStyle->getName()));
106 return xStyle;
109 void ScStyleObj::setUp()
111 CalcUnoApiTest::setUp();
112 // create calc document
113 m_xComponent = loadFromDesktop("private:factory/scalc");
116 void ScStyleObj::tearDown()
118 closeDocument(m_xComponent);
119 CalcUnoApiTest::tearDown();
122 CPPUNIT_TEST_SUITE_REGISTRATION(ScStyleObj);
124 } // namespace sc_apitest
126 CPPUNIT_PLUGIN_IMPLEMENT();
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */