1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/beans/xpropertyset.hxx>
12 #include <test/container/xelementaccess.hxx>
13 #include <test/container/xenumerationaccess.hxx>
14 #include <test/container/xindexaccess.hxx>
15 #include <test/container/xnameaccess.hxx>
16 #include <test/document/xactionlockable.hxx>
17 #include <test/lang/xserviceinfo.hxx>
18 #include <test/sheet/xnamedranges.hxx>
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/sheet/XNamedRange.hpp>
22 #include <com/sun/star/sheet/XNamedRanges.hpp>
23 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
24 #include <com/sun/star/uno/XInterface.hpp>
26 #include <com/sun/star/uno/Reference.hxx>
28 #include <cppu/unotype.hxx>
31 using namespace css::uno
;
35 class ScNamedRangesObj
: public UnoApiTest
,
36 public apitest::XActionLockable
,
37 public apitest::XElementAccess
,
38 public apitest::XEnumerationAccess
,
39 public apitest::XIndexAccess
,
40 public apitest::XNameAccess
,
41 public apitest::XNamedRanges
,
42 public apitest::XPropertySet
,
43 public apitest::XServiceInfo
48 virtual void setUp() override
;
50 virtual uno::Reference
<uno::XInterface
> init() override
;
51 virtual uno::Reference
<uno::XInterface
> getXNamedRanges(sal_Int32 nSheet
= 0) override
;
53 CPPUNIT_TEST_SUITE(ScNamedRangesObj
);
56 CPPUNIT_TEST(testAddRemoveActionLock
);
57 CPPUNIT_TEST(testSetResetActionLock
);
60 CPPUNIT_TEST(testGetElementType
);
61 CPPUNIT_TEST(testHasElements
);
64 CPPUNIT_TEST(testCreateEnumeration
);
67 CPPUNIT_TEST(testGetByIndex
);
68 CPPUNIT_TEST(testGetCount
);
71 CPPUNIT_TEST(testGetByName
);
72 CPPUNIT_TEST(testGetElementNames
);
73 CPPUNIT_TEST(testHasByName
);
76 CPPUNIT_TEST(testAddNewByName
);
77 CPPUNIT_TEST(testAddNewFromTitles
);
78 //CPPUNIT_TEST_EXCEPTION(testRemoveByName, uno::RuntimeException);
79 CPPUNIT_TEST(testOutputList
);
82 CPPUNIT_TEST(testGetPropertySetInfo
);
83 CPPUNIT_TEST(testGetPropertyValue
);
84 CPPUNIT_TEST(testSetPropertyValue
);
85 CPPUNIT_TEST(testPropertyChangeListener
);
86 CPPUNIT_TEST(testVetoableChangeListener
);
89 CPPUNIT_TEST(testGetImplementationName
);
90 CPPUNIT_TEST(testGetSupportedServiceNames
);
91 CPPUNIT_TEST(testSupportsService
);
93 CPPUNIT_TEST_SUITE_END();
96 ScNamedRangesObj::ScNamedRangesObj()
97 : UnoApiTest(u
"/sc/qa/extras/testdocuments"_ustr
)
98 , XElementAccess(cppu::UnoType
<sheet::XNamedRange
>::get())
100 , XNameAccess(u
"initial1"_ustr
)
101 , XServiceInfo(u
"ScNamedRangesObj"_ustr
, u
"com.sun.star.sheet.NamedRanges"_ustr
)
105 uno::Reference
<uno::XInterface
> ScNamedRangesObj::init()
107 uno::Reference
<beans::XPropertySet
> xPropSet(mxComponent
, UNO_QUERY_THROW
);
108 uno::Reference
<sheet::XNamedRanges
> xNamedRanges(
109 xPropSet
->getPropertyValue(u
"NamedRanges"_ustr
), UNO_QUERY_THROW
);
111 //set value from xnamedranges.hxx
112 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, UNO_QUERY_THROW
);
113 uno::Reference
<container::XIndexAccess
> xIndexAccess(xDoc
->getSheets(), UNO_QUERY_THROW
);
114 xSheet
.set(xIndexAccess
->getByIndex(0), UNO_QUERY_THROW
);
119 uno::Reference
<uno::XInterface
> ScNamedRangesObj::getXNamedRanges(sal_Int32 nSheet
)
121 uno::Reference
<beans::XPropertySet
> xPropSet(mxComponent
, UNO_QUERY_THROW
);
122 uno::Reference
<sheet::XNamedRanges
> xNamedRanges(
123 xPropSet
->getPropertyValue(u
"NamedRanges"_ustr
), UNO_QUERY_THROW
);
125 //set value from xnamedranges.hxx
126 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, UNO_QUERY_THROW
);
127 uno::Reference
<container::XIndexAccess
> xIndexAccess(xDoc
->getSheets(), UNO_QUERY_THROW
);
128 xSheet
.set(xIndexAccess
->getByIndex(nSheet
), UNO_QUERY_THROW
);
133 void ScNamedRangesObj::setUp()
136 // create a calc document
137 loadFromFile(u
"ScNamedRangeObj.ods");
140 CPPUNIT_TEST_SUITE_REGISTRATION(ScNamedRangesObj
);
142 } // namespace sc_apitest
144 CPPUNIT_PLUGIN_IMPLEMENT();
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */