Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / qa / extras / scstylefamilyobj.cxx
blob627e755cada491206280812353074ba59322b576
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/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 UnoApiTest,
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;
49 CPPUNIT_TEST_SUITE(ScStyleFamilyObj);
51 // XElementAccess
52 CPPUNIT_TEST(testGetElementType);
53 CPPUNIT_TEST(testHasElements);
55 // XIndexAccess
56 CPPUNIT_TEST(testGetByIndex);
57 CPPUNIT_TEST(testGetCount);
59 // XNameAccess
60 CPPUNIT_TEST(testGetByName);
61 CPPUNIT_TEST(testGetElementNames);
62 CPPUNIT_TEST(testHasByName);
64 // XNameContainer
65 CPPUNIT_TEST(testInsertByName);
66 CPPUNIT_TEST(testInsertByNameDuplicate);
67 CPPUNIT_TEST(testInsertByNameEmptyName);
68 CPPUNIT_TEST(testRemoveByName);
69 CPPUNIT_TEST(testRemoveByNameNoneExistingElement);
71 // XNameReplace
72 CPPUNIT_TEST(testReplaceByName);
74 // XServiceInfo
75 CPPUNIT_TEST(testGetImplementationName);
76 CPPUNIT_TEST(testGetSupportedServiceNames);
77 CPPUNIT_TEST(testSupportsService);
79 CPPUNIT_TEST_SUITE_END();
82 /* TODO: this c/should be derived/defined from the real style count, default
83 * implemented plus sc/res/xml/styles.xml */
84 constexpr sal_Int32 kScStyleFamilyObjCount = 20;
86 ScStyleFamilyObj::ScStyleFamilyObj()
87 : UnoApiTest("/sc/qa/extras/testdocuments")
88 , XElementAccess(cppu::UnoType<style::XStyle>::get())
89 , XIndexAccess(kScStyleFamilyObjCount)
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(mxComponent, 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(mxComponent, 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 XNameContainer::setElement(uno::Any(xMSF->createInstance("com.sun.star.style.CellStyle")));
111 // XNameReplace
112 XNameReplace::setElement(uno::Any(xMSF->createInstance("com.sun.star.style.CellStyle")));
114 uno::Reference<container::XNameContainer> xNC(xNA_SF, uno::UNO_QUERY_THROW);
115 xNC->insertByName("ScStyleFamilyObj", uno::Any(xCS));
117 return xNA_SF;
120 void ScStyleFamilyObj::setUp()
122 UnoApiTest::setUp();
123 // create calc document
124 mxComponent = loadFromDesktop("private:factory/scalc");
127 CPPUNIT_TEST_SUITE_REGISTRATION(ScStyleFamilyObj);
129 } // namespace sc_apitest
131 CPPUNIT_PLUGIN_IMPLEMENT();
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */