Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / qa / extras / scdatabaserangesobj.cxx
blob7926cb6ecf0befec5d407e7c4f565c915b4baa2a
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/xenumerationaccess.hxx>
13 #include <test/container/xindexaccess.hxx>
14 #include <test/container/xnameaccess.hxx>
15 #include <test/lang/xserviceinfo.hxx>
16 #include <test/sheet/xdatabaseranges.hxx>
18 #include <com/sun/star/beans/XPropertySet.hpp>
19 #include <com/sun/star/lang/XComponent.hpp>
20 #include <com/sun/star/sheet/XDatabaseRange.hpp>
21 #include <com/sun/star/sheet/XDatabaseRanges.hpp>
22 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
23 #include <com/sun/star/table/CellRangeAddress.hpp>
24 #include <com/sun/star/uno/XInterface.hpp>
26 #include <com/sun/star/uno/Reference.hxx>
28 #include <cppu/unotype.hxx>
30 using namespace css;
31 using namespace css::uno;
32 using namespace com::sun::star;
34 namespace sc_apitest
36 class ScDatabaseRangesObj : public UnoApiTest,
37 public apitest::XDatabaseRanges,
38 public apitest::XElementAccess,
39 public apitest::XEnumerationAccess,
40 public apitest::XIndexAccess,
41 public apitest::XNameAccess,
42 public apitest::XServiceInfo
44 public:
45 ScDatabaseRangesObj();
47 virtual uno::Reference<uno::XInterface> init() override;
48 virtual void setUp() override;
50 CPPUNIT_TEST_SUITE(ScDatabaseRangesObj);
52 // XDatabaseRanges
53 CPPUNIT_TEST(testAddRemoveDbRanges);
55 // XElementAccess
56 CPPUNIT_TEST(testGetElementType);
57 CPPUNIT_TEST(testHasElements);
59 // XEnumerationAccess
60 CPPUNIT_TEST(testCreateEnumeration);
62 // XIndexAccess
63 CPPUNIT_TEST(testGetByIndex);
64 CPPUNIT_TEST(testGetCount);
66 // XNameAccess
67 CPPUNIT_TEST(testGetByName);
68 CPPUNIT_TEST(testGetElementNames);
69 CPPUNIT_TEST(testHasByName);
71 // XServiceInfo
72 CPPUNIT_TEST(testGetImplementationName);
73 CPPUNIT_TEST(testGetSupportedServiceNames);
74 CPPUNIT_TEST(testSupportsService);
76 CPPUNIT_TEST_SUITE_END();
79 ScDatabaseRangesObj::ScDatabaseRangesObj()
80 : UnoApiTest("/sc/qa/extras/testdocuments")
81 , XElementAccess(cppu::UnoType<sheet::XDatabaseRange>::get())
82 , XIndexAccess(1)
83 , XNameAccess("DbRange")
84 , XServiceInfo("ScDatabaseRangesObj", "com.sun.star.sheet.DatabaseRanges")
88 uno::Reference<uno::XInterface> ScDatabaseRangesObj::init()
90 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
92 uno::Reference<beans::XPropertySet> xPropSet(xDoc, UNO_QUERY_THROW);
93 uno::Reference<sheet::XDatabaseRanges> xDbRanges(xPropSet->getPropertyValue("DatabaseRanges"),
94 UNO_QUERY_THROW);
96 if (!xDbRanges->hasByName("DbRange"))
97 xDbRanges->addNewByName("DbRange", table::CellRangeAddress(0, 2, 4, 5, 6));
99 return xDbRanges;
102 void ScDatabaseRangesObj::setUp()
104 UnoApiTest::setUp();
105 // create a calc document
106 mxComponent = loadFromDesktop("private:factory/scalc");
109 CPPUNIT_TEST_SUITE_REGISTRATION(ScDatabaseRangesObj);
111 } // namespace sc_apitest
113 CPPUNIT_PLUGIN_IMPLEMENT();
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */