nss: upgrade to release 3.73
[LibreOffice.git] / sc / qa / extras / scstylefamilyobj.cxx
blob8597d22b0f71e8087f880686a8e4322823f17c6c
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 /* TODO: this c/should be derived/defined from the real style count, default
87 * implemented plus sc/res/xml/styles.xml */
88 constexpr sal_Int32 kScStyleFamilyObjCount = 20;
90 ScStyleFamilyObj::ScStyleFamilyObj()
91 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
92 , XElementAccess(cppu::UnoType<style::XStyle>::get())
93 , XIndexAccess(kScStyleFamilyObjCount)
94 , XNameAccess("ScStyleFamilyObj")
95 , XNameContainer("ScStyleFamilyObj")
96 , XNameReplace("ScStyleFamilyObj")
97 , XServiceInfo("ScStyleFamilyObj", "com.sun.star.style.StyleFamily")
101 uno::Reference<uno::XInterface> ScStyleFamilyObj::init()
103 uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW);
105 uno::Reference<style::XStyleFamiliesSupplier> xSFS(xDoc, uno::UNO_QUERY_THROW);
106 uno::Reference<container::XNameAccess> xNA(xSFS->getStyleFamilies(), uno::UNO_SET_THROW);
107 uno::Reference<container::XIndexAccess> xIA(xNA, uno::UNO_QUERY_THROW);
108 uno::Reference<container::XNameAccess> xNA_SF(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
110 uno::Reference<lang::XMultiServiceFactory> xMSF(m_xComponent, uno::UNO_QUERY_THROW);
111 uno::Reference<uno::XInterface> xCS(xMSF->createInstance("com.sun.star.style.CellStyle"),
112 uno::UNO_SET_THROW);
113 // XNameContainer
114 XNameContainer::setElement(uno::makeAny(xMSF->createInstance("com.sun.star.style.CellStyle")));
115 // XNameReplace
116 XNameReplace::setElement(uno::makeAny(xMSF->createInstance("com.sun.star.style.CellStyle")));
118 uno::Reference<container::XNameContainer> xNC(xNA_SF, uno::UNO_QUERY_THROW);
119 xNC->insertByName("ScStyleFamilyObj", uno::makeAny(xCS));
121 return xNA_SF;
124 void ScStyleFamilyObj::setUp()
126 CalcUnoApiTest::setUp();
127 // create calc document
128 m_xComponent = loadFromDesktop("private:factory/scalc");
131 void ScStyleFamilyObj::tearDown()
133 closeDocument(m_xComponent);
134 CalcUnoApiTest::tearDown();
137 CPPUNIT_TEST_SUITE_REGISTRATION(ScStyleFamilyObj);
139 } // namespace sc_apitest
141 CPPUNIT_PLUGIN_IMPLEMENT();
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */