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/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>
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
45 virtual uno::Reference
<uno::XInterface
> init() override
;
46 virtual void setUp() override
;
48 CPPUNIT_TEST_SUITE(ScStyleFamilyObj
);
51 CPPUNIT_TEST(testGetElementType
);
52 CPPUNIT_TEST(testHasElements
);
55 CPPUNIT_TEST(testGetByIndex
);
56 CPPUNIT_TEST(testGetCount
);
59 CPPUNIT_TEST(testGetByName
);
60 CPPUNIT_TEST(testGetElementNames
);
61 CPPUNIT_TEST(testHasByName
);
64 CPPUNIT_TEST(testInsertByName
);
65 CPPUNIT_TEST(testInsertByNameDuplicate
);
66 CPPUNIT_TEST(testInsertByNameEmptyName
);
67 CPPUNIT_TEST(testRemoveByName
);
68 CPPUNIT_TEST(testRemoveByNameNoneExistingElement
);
71 CPPUNIT_TEST(testReplaceByName
);
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
),
109 XNameContainer::setElement(
110 uno::Any(xMSF
->createInstance(u
"com.sun.star.style.CellStyle"_ustr
)));
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
));
120 void ScStyleFamilyObj::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: */