Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / qa / extras / scstylefamilyobj.cxx
blobfe5d8fb2ec191900c51a6ccd6ba4ee52ed4def7d
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/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>
31 using namespace css;
33 namespace sc_apitest
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
43 public:
44 ScStyleFamilyObj();
46 virtual uno::Reference<uno::XInterface> init() override;
47 virtual void setUp() override;
48 virtual void tearDown() override;
50 CPPUNIT_TEST_SUITE(ScStyleFamilyObj);
52 // XElementAccess
53 CPPUNIT_TEST(testGetElementType);
54 CPPUNIT_TEST(testHasElements);
56 // XIndexAccess
57 CPPUNIT_TEST(testGetByIndex);
58 CPPUNIT_TEST(testGetCount);
60 // XNameAccess
61 CPPUNIT_TEST(testGetByName);
62 CPPUNIT_TEST(testGetElementNames);
63 CPPUNIT_TEST(testHasByName);
65 // XNameContainer
66 CPPUNIT_TEST(testInsertByName);
67 CPPUNIT_TEST(testInsertByNameDuplicate);
68 CPPUNIT_TEST(testInsertByNameEmptyName);
69 CPPUNIT_TEST(testRemoveByName);
70 CPPUNIT_TEST(testRemoveByNameNoneExistingElement);
72 // XNameReplace
73 CPPUNIT_TEST(testReplaceByName);
75 // XServiceInfo
76 CPPUNIT_TEST(testGetImplementationName);
77 CPPUNIT_TEST(testGetSupportedServiceNames);
78 CPPUNIT_TEST(testSupportsService);
80 CPPUNIT_TEST_SUITE_END();
82 private:
83 uno::Reference<lang::XComponent> m_xComponent;
86 ScStyleFamilyObj::ScStyleFamilyObj()
87 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
88 , XElementAccess(cppu::UnoType<style::XStyle>::get())
89 , XIndexAccess(19)
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"),
108 uno::UNO_SET_THROW);
109 // XNameContainer
110 setElement(uno::makeAny(xMSF->createInstance("com.sun.star.style.CellStyle")));
111 // XNameReplace
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));
117 return xNA_SF;
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: */