tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / sc / qa / extras / scstylefamilyobj.cxx
blobfce3eb6a619e50d814f2dcae9010a1077243e1a3
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/XMultiServiceFactory.hpp>
23 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
24 #include <com/sun/star/style/XStyle.hpp>
25 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
26 #include <com/sun/star/uno/XInterface.hpp>
28 #include <com/sun/star/uno/Reference.hxx>
30 using namespace css;
32 namespace sc_apitest
34 class ScStyleFamilyObj : public UnoApiTest,
35 public apitest::XElementAccess,
36 public apitest::XIndexAccess,
37 public apitest::XNameAccess,
38 public apitest::XNameContainer,
39 public apitest::XNameReplace,
40 public apitest::XServiceInfo
42 public:
43 ScStyleFamilyObj();
45 virtual uno::Reference<uno::XInterface> init() override;
46 virtual void setUp() override;
48 CPPUNIT_TEST_SUITE(ScStyleFamilyObj);
50 // XElementAccess
51 CPPUNIT_TEST(testGetElementType);
52 CPPUNIT_TEST(testHasElements);
54 // XIndexAccess
55 CPPUNIT_TEST(testGetByIndex);
56 CPPUNIT_TEST(testGetCount);
58 // XNameAccess
59 CPPUNIT_TEST(testGetByName);
60 CPPUNIT_TEST(testGetElementNames);
61 CPPUNIT_TEST(testHasByName);
63 // XNameContainer
64 CPPUNIT_TEST(testInsertByName);
65 CPPUNIT_TEST(testInsertByNameDuplicate);
66 CPPUNIT_TEST(testInsertByNameEmptyName);
67 CPPUNIT_TEST(testRemoveByName);
68 CPPUNIT_TEST(testRemoveByNameNoneExistingElement);
70 // XNameReplace
71 CPPUNIT_TEST(testReplaceByName);
73 // XServiceInfo
74 CPPUNIT_TEST(testGetImplementationName);
75 CPPUNIT_TEST(testGetSupportedServiceNames);
76 CPPUNIT_TEST(testSupportsService);
78 CPPUNIT_TEST_SUITE_END();
81 /* TODO: this c/should be derived/defined from the real style count, default
82 * implemented plus sc/res/xml/styles.xml */
83 constexpr sal_Int32 kScStyleFamilyObjCount = 20;
85 ScStyleFamilyObj::ScStyleFamilyObj()
86 : UnoApiTest(u"/sc/qa/extras/testdocuments"_ustr)
87 , XElementAccess(cppu::UnoType<style::XStyle>::get())
88 , XIndexAccess(kScStyleFamilyObjCount)
89 , XNameAccess(u"ScStyleFamilyObj"_ustr)
90 , XNameContainer(u"ScStyleFamilyObj"_ustr)
91 , XNameReplace(u"ScStyleFamilyObj"_ustr)
92 , XServiceInfo(u"ScStyleFamilyObj"_ustr, u"com.sun.star.style.StyleFamily"_ustr)
96 uno::Reference<uno::XInterface> ScStyleFamilyObj::init()
98 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
100 uno::Reference<style::XStyleFamiliesSupplier> xSFS(xDoc, uno::UNO_QUERY_THROW);
101 uno::Reference<container::XNameAccess> xNA(xSFS->getStyleFamilies(), uno::UNO_SET_THROW);
102 uno::Reference<container::XIndexAccess> xIA(xNA, uno::UNO_QUERY_THROW);
103 uno::Reference<container::XNameAccess> xNA_SF(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
105 uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY_THROW);
106 uno::Reference<uno::XInterface> xCS(xMSF->createInstance(u"com.sun.star.style.CellStyle"_ustr),
107 uno::UNO_SET_THROW);
108 // XNameContainer
109 XNameContainer::setElement(
110 uno::Any(xMSF->createInstance(u"com.sun.star.style.CellStyle"_ustr)));
111 // XNameReplace
112 XNameReplace::setElement(uno::Any(xMSF->createInstance(u"com.sun.star.style.CellStyle"_ustr)));
114 uno::Reference<container::XNameContainer> xNC(xNA_SF, uno::UNO_QUERY_THROW);
115 xNC->insertByName(u"ScStyleFamilyObj"_ustr, uno::Any(xCS));
117 return xNA_SF;
120 void ScStyleFamilyObj::setUp()
122 UnoApiTest::setUp();
123 // create calc document
124 loadFromURL(u"private:factory/scalc"_ustr);
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: */