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.
4  *
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  */
9 
10 #include <test/calc_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>
17 
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>
25 
26 #include <com/sun/star/uno/Reference.hxx>
27 
28 #include <cppu/unotype.hxx>
29 
30 using namespace css;
31 using namespace css::uno;
32 using namespace com::sun::star;
33 
34 namespace sc_apitest
35 {
36 class ScDatabaseRangesObj : public CalcUnoApiTest,
37                             public apitest::XDatabaseRanges,
38                             public apitest::XElementAccess,
39                             public apitest::XEnumerationAccess,
40                             public apitest::XIndexAccess,
41                             public apitest::XNameAccess,
42                             public apitest::XServiceInfo
43 {
44 public:
45     ScDatabaseRangesObj();
46 
47     virtual uno::Reference<uno::XInterface> init() override;
48     virtual void setUp() override;
49     virtual void tearDown() override;
50 
51     CPPUNIT_TEST_SUITE(ScDatabaseRangesObj);
52 
53     // XDatabaseRanges
54     CPPUNIT_TEST(testAddRemoveDbRanges);
55 
56     // XElementAccess
57     CPPUNIT_TEST(testGetElementType);
58     CPPUNIT_TEST(testHasElements);
59 
60     // XEnumerationAccess
61     CPPUNIT_TEST(testCreateEnumeration);
62 
63     // XIndexAccess
64     CPPUNIT_TEST(testGetByIndex);
65     CPPUNIT_TEST(testGetCount);
66 
67     // XNameAccess
68     CPPUNIT_TEST(testGetByName);
69     CPPUNIT_TEST(testGetElementNames);
70     CPPUNIT_TEST(testHasByName);
71 
72     // XServiceInfo
73     CPPUNIT_TEST(testGetImplementationName);
74     CPPUNIT_TEST(testGetSupportedServiceNames);
75     CPPUNIT_TEST(testSupportsService);
76 
77     CPPUNIT_TEST_SUITE_END();
78 
79 private:
80     uno::Reference<lang::XComponent> mxComponent;
81 };
82 
ScDatabaseRangesObj()83 ScDatabaseRangesObj::ScDatabaseRangesObj()
84     : CalcUnoApiTest("/sc/qa/extras/testdocuments")
85     , XElementAccess(cppu::UnoType<sheet::XDatabaseRange>::get())
86     , XIndexAccess(1)
87     , XNameAccess("DbRange")
88     , XServiceInfo("ScDatabaseRangesObj", "com.sun.star.sheet.DatabaseRanges")
89 {
90 }
91 
init()92 uno::Reference<uno::XInterface> ScDatabaseRangesObj::init()
93 {
94     uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
95 
96     uno::Reference<beans::XPropertySet> xPropSet(xDoc, UNO_QUERY_THROW);
97     uno::Reference<sheet::XDatabaseRanges> xDbRanges(xPropSet->getPropertyValue("DatabaseRanges"),
98                                                      UNO_QUERY_THROW);
99 
100     if (!xDbRanges->hasByName("DbRange"))
101         xDbRanges->addNewByName("DbRange", table::CellRangeAddress(0, 2, 4, 5, 6));
102 
103     return xDbRanges;
104 }
105 
setUp()106 void ScDatabaseRangesObj::setUp()
107 {
108     CalcUnoApiTest::setUp();
109     // create a calc document
110     mxComponent = loadFromDesktop("private:factory/scalc");
111 }
112 
tearDown()113 void ScDatabaseRangesObj::tearDown()
114 {
115     closeDocument(mxComponent);
116     CalcUnoApiTest::tearDown();
117 }
118 
119 CPPUNIT_TEST_SUITE_REGISTRATION(ScDatabaseRangesObj);
120 
121 } // namespace sc_apitest
122 
123 CPPUNIT_PLUGIN_IMPLEMENT();
124 
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
126