tdf#164627 docx export: consolidate getWordCompatibilityMode()
[LibreOffice.git] / sc / qa / extras / scnamedrangesobj.cxx
blob5215e84355aa1f10cef444639aaa024416cffb60
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/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>
30 using namespace css;
31 using namespace css::uno;
33 namespace sc_apitest
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
45 public:
46 ScNamedRangesObj();
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);
55 // XActionLockable
56 CPPUNIT_TEST(testAddRemoveActionLock);
57 CPPUNIT_TEST(testSetResetActionLock);
59 // XElementAccess
60 CPPUNIT_TEST(testGetElementType);
61 CPPUNIT_TEST(testHasElements);
63 // XEnumerationAccess
64 CPPUNIT_TEST(testCreateEnumeration);
66 // XIndexAccess
67 CPPUNIT_TEST(testGetByIndex);
68 CPPUNIT_TEST(testGetCount);
70 // XNamedRanges
71 CPPUNIT_TEST(testGetByName);
72 CPPUNIT_TEST(testGetElementNames);
73 CPPUNIT_TEST(testHasByName);
75 // XNamedRanges
76 CPPUNIT_TEST(testAddNewByName);
77 CPPUNIT_TEST(testAddNewFromTitles);
78 //CPPUNIT_TEST_EXCEPTION(testRemoveByName, uno::RuntimeException);
79 CPPUNIT_TEST(testOutputList);
81 // XPropertySet
82 CPPUNIT_TEST(testGetPropertySetInfo);
83 CPPUNIT_TEST(testGetPropertyValue);
84 CPPUNIT_TEST(testSetPropertyValue);
85 CPPUNIT_TEST(testPropertyChangeListener);
86 CPPUNIT_TEST(testVetoableChangeListener);
88 // XServiceInfo
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())
99 , XIndexAccess(4)
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);
116 return xNamedRanges;
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);
130 return xNamedRanges;
133 void ScNamedRangesObj::setUp()
135 UnoApiTest::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: */