Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License or as specified alternatively below. You may obtain a copy of
8 : * the License at http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * Major Contributor(s):
16 : * Copyright (C) 2012 Markus Mohrhard <markus.mohrhard@googlemail.com> (initial developer)
17 : *
18 : * All Rights Reserved.
19 : *
20 : * For minor contributions see the git repository.
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : * instead of those above.
27 : */
28 :
29 : #include <test/unoapi_test.hxx>
30 : #include <test/sheet/xnamedrange.hxx>
31 : #include <test/container/xnamed.hxx>
32 : #include <test/sheet/xcellrangereferrer.hxx>
33 :
34 : #include <com/sun/star/beans/XPropertySet.hpp>
35 : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
36 : #include <com/sun/star/sheet/XSpreadsheet.hpp>
37 : #include <com/sun/star/sheet/XNamedRanges.hpp>
38 :
39 : namespace sc_apitest {
40 :
41 : #define NUMBER_OF_TESTS 9
42 :
43 36 : class ScNamedRangeObj : public UnoApiTest, apitest::XNamedRange, apitest::XNamed, apitest::XCellRangeReferrer
44 : {
45 : public:
46 : ScNamedRangeObj();
47 :
48 : virtual void setUp();
49 : virtual void tearDown();
50 :
51 : virtual uno::Reference< uno::XInterface > init();
52 : virtual uno::Reference< sheet::XNamedRange > getNamedRange(const rtl::OUString& rRangeName);
53 :
54 4 : CPPUNIT_TEST_SUITE(ScNamedRangeObj);
55 2 : CPPUNIT_TEST(testGetContent);
56 2 : CPPUNIT_TEST(testSetContent);
57 2 : CPPUNIT_TEST(testGetType);
58 2 : CPPUNIT_TEST(testSetType);
59 2 : CPPUNIT_TEST(testGetReferencePosition);
60 2 : CPPUNIT_TEST(testSetReferencePosition);
61 2 : CPPUNIT_TEST(testSetName);
62 2 : CPPUNIT_TEST(testGetName);
63 2 : CPPUNIT_TEST(testGetReferredCells);
64 4 : CPPUNIT_TEST_SUITE_END();
65 : private:
66 : uno::Reference< sheet::XNamedRanges > init_impl();
67 :
68 : static sal_Int32 nTest;
69 : static uno::Reference< lang::XComponent > mxComponent;
70 : };
71 :
72 : sal_Int32 ScNamedRangeObj::nTest = 0;
73 2 : uno::Reference< lang::XComponent > ScNamedRangeObj::mxComponent;
74 :
75 18 : ScNamedRangeObj::ScNamedRangeObj():
76 : apitest::XNamed(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NamedRange"))),
77 18 : apitest::XCellRangeReferrer(table::CellRangeAddress(0,1,7,1,7))
78 : {
79 :
80 18 : }
81 :
82 18 : uno::Reference< sheet::XNamedRanges > ScNamedRangeObj::init_impl()
83 : {
84 18 : rtl::OUString aFileURL;
85 18 : createFileURL(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScNamedRangeObj.ods")), aFileURL);
86 18 : if(!mxComponent.is())
87 2 : mxComponent = loadFromDesktop(aFileURL);
88 18 : CPPUNIT_ASSERT(mxComponent.is());
89 :
90 18 : uno::Reference< beans::XPropertySet > xPropSet (mxComponent, UNO_QUERY_THROW);
91 18 : rtl::OUString aNamedRangesPropertyString(RTL_CONSTASCII_USTRINGPARAM("NamedRanges"));
92 18 : uno::Reference< sheet::XNamedRanges > xNamedRanges(xPropSet->getPropertyValue(aNamedRangesPropertyString), UNO_QUERY_THROW);
93 18 : CPPUNIT_ASSERT(xNamedRanges.is());
94 :
95 18 : return xNamedRanges;
96 : }
97 :
98 18 : uno::Reference< sheet::XNamedRange> ScNamedRangeObj::getNamedRange(const rtl::OUString& rRangeName)
99 : {
100 18 : uno::Reference< container::XNameAccess > xNamedAccess(init_impl(), UNO_QUERY_THROW);
101 18 : uno::Reference< sheet::XNamedRange > xNamedRange(xNamedAccess->getByName(rRangeName), UNO_QUERY_THROW);
102 18 : CPPUNIT_ASSERT(xNamedRange.is());
103 :
104 18 : return xNamedRange;
105 : }
106 :
107 6 : uno::Reference< uno::XInterface > ScNamedRangeObj::init()
108 : {
109 6 : return getNamedRange(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NamedRange")));
110 : }
111 :
112 18 : void ScNamedRangeObj::setUp()
113 : {
114 18 : nTest++;
115 18 : UnoApiTest::setUp();
116 18 : }
117 :
118 18 : void ScNamedRangeObj::tearDown()
119 : {
120 18 : if (nTest == NUMBER_OF_TESTS)
121 2 : closeDocument(mxComponent);
122 :
123 18 : UnoApiTest::tearDown();
124 18 : }
125 :
126 2 : CPPUNIT_TEST_SUITE_REGISTRATION(ScNamedRangeObj);
127 :
128 2 : CPPUNIT_PLUGIN_IMPLEMENT();
129 :
130 6 : }
131 :
132 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|