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/calc_unoapi_test.hxx>
11 #include <test/container/xelementaccess.hxx>
12 #include <test/container/xindexaccess.hxx>
13 #include <test/container/xnameaccess.hxx>
14 #include <test/container/xnamecontainer.hxx>
15 #include <test/container/xnamereplace.hxx>
16 #include <test/lang/xserviceinfo.hxx>
17 #include <cppu/unotype.hxx>
19 #include <com/sun/star/container/XIndexAccess.hpp>
20 #include <com/sun/star/container/XNameAccess.hpp>
21 #include <com/sun/star/container/XNameContainer.hpp>
22 #include <com/sun/star/lang/XComponent.hpp>
23 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
25 #include <com/sun/star/style/XStyle.hpp>
26 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
27 #include <com/sun/star/uno/XInterface.hpp>
29 #include <com/sun/star/uno/Reference.hxx>
35 class ScStyleFamilyObj
: public CalcUnoApiTest
,
36 public apitest::XElementAccess
,
37 public apitest::XIndexAccess
,
38 public apitest::XNameAccess
,
39 public apitest::XNameContainer
,
40 public apitest::XNameReplace
,
41 public apitest::XServiceInfo
46 virtual uno::Reference
<uno::XInterface
> init() override
;
47 virtual void setUp() override
;
48 virtual void tearDown() override
;
50 CPPUNIT_TEST_SUITE(ScStyleFamilyObj
);
53 CPPUNIT_TEST(testGetElementType
);
54 CPPUNIT_TEST(testHasElements
);
57 CPPUNIT_TEST(testGetByIndex
);
58 CPPUNIT_TEST(testGetCount
);
61 CPPUNIT_TEST(testGetByName
);
62 CPPUNIT_TEST(testGetElementNames
);
63 CPPUNIT_TEST(testHasByName
);
66 CPPUNIT_TEST(testInsertByName
);
67 CPPUNIT_TEST(testInsertByNameDuplicate
);
68 CPPUNIT_TEST(testInsertByNameEmptyName
);
69 CPPUNIT_TEST(testRemoveByName
);
70 CPPUNIT_TEST(testRemoveByNameNoneExistingElement
);
73 CPPUNIT_TEST(testReplaceByName
);
76 CPPUNIT_TEST(testGetImplementationName
);
77 CPPUNIT_TEST(testGetSupportedServiceNames
);
78 CPPUNIT_TEST(testSupportsService
);
80 CPPUNIT_TEST_SUITE_END();
83 uno::Reference
<lang::XComponent
> m_xComponent
;
86 ScStyleFamilyObj::ScStyleFamilyObj()
87 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
88 , XElementAccess(cppu::UnoType
<style::XStyle
>::get())
90 , XNameAccess("ScStyleFamilyObj")
91 , XNameContainer("ScStyleFamilyObj")
92 , XNameReplace("ScStyleFamilyObj")
93 , XServiceInfo("ScStyleFamilyObj", "com.sun.star.style.StyleFamily")
97 uno::Reference
<uno::XInterface
> ScStyleFamilyObj::init()
99 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(m_xComponent
, uno::UNO_QUERY_THROW
);
101 uno::Reference
<style::XStyleFamiliesSupplier
> xSFS(xDoc
, uno::UNO_QUERY_THROW
);
102 uno::Reference
<container::XNameAccess
> xNA(xSFS
->getStyleFamilies(), uno::UNO_SET_THROW
);
103 uno::Reference
<container::XIndexAccess
> xIA(xNA
, uno::UNO_QUERY_THROW
);
104 uno::Reference
<container::XNameAccess
> xNA_SF(xIA
->getByIndex(0), uno::UNO_QUERY_THROW
);
106 uno::Reference
<lang::XMultiServiceFactory
> xMSF(m_xComponent
, uno::UNO_QUERY_THROW
);
107 uno::Reference
<uno::XInterface
> xCS(xMSF
->createInstance("com.sun.star.style.CellStyle"),
110 setElement(uno::makeAny(xMSF
->createInstance("com.sun.star.style.CellStyle")));
112 setReplacementElement(uno::makeAny(xMSF
->createInstance("com.sun.star.style.CellStyle")));
114 uno::Reference
<container::XNameContainer
> xNC(xNA_SF
, uno::UNO_QUERY_THROW
);
115 xNC
->insertByName("ScStyleFamilyObj", uno::makeAny(xCS
));
120 void ScStyleFamilyObj::setUp()
122 CalcUnoApiTest::setUp();
123 // create calc document
124 m_xComponent
= loadFromDesktop("private:factory/scalc");
127 void ScStyleFamilyObj::tearDown()
129 closeDocument(m_xComponent
);
130 CalcUnoApiTest::tearDown();
133 CPPUNIT_TEST_SUITE_REGISTRATION(ScStyleFamilyObj
);
135 } // namespace sc_apitest
137 CPPUNIT_PLUGIN_IMPLEMENT();
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */