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/xnamedranges.hxx>
31 :
32 : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
33 : #include <com/sun/star/beans/XPropertySet.hpp>
34 : #include <com/sun/star/sheet/XNamedRanges.hpp>
35 :
36 : namespace sc_apitest {
37 :
38 : #define NUMBER_OF_TESTS 3
39 :
40 18 : class ScNamedRangesObj : public UnoApiTest, apitest::XNamedRanges
41 : {
42 : public:
43 : virtual void setUp();
44 : virtual void tearDown();
45 :
46 : virtual uno::Reference< uno::XInterface > init(sal_Int32 nSheet);
47 :
48 4 : CPPUNIT_TEST_SUITE(ScNamedRangesObj);
49 2 : CPPUNIT_TEST(testAddNewByName);
50 2 : CPPUNIT_TEST(testAddNewFromTitles);
51 : //CPPUNIT_TEST_EXCEPTION(testRemoveByName, uno::RuntimeException);
52 2 : CPPUNIT_TEST(testOutputList);
53 4 : CPPUNIT_TEST_SUITE_END();
54 :
55 : private:
56 : static sal_Int32 nTest;
57 : static uno::Reference< lang::XComponent > mxComponent;
58 : };
59 :
60 : sal_Int32 ScNamedRangesObj::nTest = 0;
61 2 : uno::Reference< lang::XComponent > ScNamedRangesObj::mxComponent;
62 :
63 10 : uno::Reference< uno::XInterface > ScNamedRangesObj::init(sal_Int32 nSheet)
64 : {
65 10 : rtl::OUString aFileURL;
66 10 : createFileURL(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScNamedRangeObj.ods")), aFileURL);
67 10 : if(!mxComponent.is())
68 2 : mxComponent = loadFromDesktop(aFileURL);
69 10 : CPPUNIT_ASSERT(mxComponent.is());
70 :
71 10 : uno::Reference< beans::XPropertySet > xPropSet (mxComponent, UNO_QUERY_THROW);
72 10 : rtl::OUString aNamedRangesPropertyString(RTL_CONSTASCII_USTRINGPARAM("NamedRanges"));
73 10 : uno::Reference< sheet::XNamedRanges > xNamedRanges(xPropSet->getPropertyValue(aNamedRangesPropertyString), UNO_QUERY_THROW);
74 :
75 : //set value from xnamedranges.hxx
76 10 : uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW);
77 10 : uno::Reference< container::XIndexAccess > xIndexAccess(xDoc->getSheets(), UNO_QUERY_THROW);
78 10 : xSheet = uno::Reference< sheet::XSpreadsheet >(xIndexAccess->getByIndex(nSheet),UNO_QUERY_THROW);
79 :
80 10 : return xNamedRanges;
81 : }
82 :
83 6 : void ScNamedRangesObj::setUp()
84 : {
85 6 : nTest++;
86 6 : UnoApiTest::setUp();
87 6 : }
88 :
89 6 : void ScNamedRangesObj::tearDown()
90 : {
91 6 : if (nTest == NUMBER_OF_TESTS)
92 2 : closeDocument(mxComponent);
93 :
94 6 : UnoApiTest::tearDown();
95 6 : }
96 :
97 2 : CPPUNIT_TEST_SUITE_REGISTRATION(ScNamedRangesObj);
98 :
99 2 : CPPUNIT_PLUGIN_IMPLEMENT();
100 :
101 6 : }
102 :
103 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|