Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/sheet/xnamedrange.hxx>
12 : #include <test/container/xnamed.hxx>
13 : #include <test/sheet/xcellrangereferrer.hxx>
14 :
15 : #include <com/sun/star/beans/XPropertySet.hpp>
16 : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
17 : #include <com/sun/star/sheet/XSpreadsheet.hpp>
18 : #include <com/sun/star/sheet/XNamedRanges.hpp>
19 :
20 : using namespace css;
21 : using namespace css::uno;
22 :
23 : namespace sc_apitest {
24 :
25 : #define NUMBER_OF_TESTS 9
26 :
27 18 : class ScNamedRangeObj : public CalcUnoApiTest, apitest::XNamedRange, apitest::XNamed, apitest::XCellRangeReferrer
28 : {
29 : public:
30 : ScNamedRangeObj();
31 :
32 : virtual void setUp() SAL_OVERRIDE;
33 : virtual void tearDown() SAL_OVERRIDE;
34 :
35 : virtual uno::Reference< uno::XInterface > init() SAL_OVERRIDE;
36 : virtual uno::Reference< sheet::XNamedRange > getNamedRange(const OUString& rRangeName) SAL_OVERRIDE;
37 :
38 2 : CPPUNIT_TEST_SUITE(ScNamedRangeObj);
39 1 : CPPUNIT_TEST(testGetContent);
40 1 : CPPUNIT_TEST(testSetContent);
41 1 : CPPUNIT_TEST(testGetType);
42 1 : CPPUNIT_TEST(testSetType);
43 1 : CPPUNIT_TEST(testGetReferencePosition);
44 1 : CPPUNIT_TEST(testSetReferencePosition);
45 1 : CPPUNIT_TEST(testSetName);
46 1 : CPPUNIT_TEST(testGetName);
47 1 : CPPUNIT_TEST(testGetReferredCells);
48 5 : CPPUNIT_TEST_SUITE_END();
49 : private:
50 : uno::Reference< sheet::XNamedRanges > init_impl();
51 :
52 : static sal_Int32 nTest;
53 : static uno::Reference< lang::XComponent > mxComponent;
54 : };
55 :
56 : sal_Int32 ScNamedRangeObj::nTest = 0;
57 1 : uno::Reference< lang::XComponent > ScNamedRangeObj::mxComponent;
58 :
59 9 : ScNamedRangeObj::ScNamedRangeObj():
60 : CalcUnoApiTest("/sc/qa/extras/testdocuments"),
61 : apitest::XNamed(OUString("NamedRange")),
62 9 : apitest::XCellRangeReferrer(table::CellRangeAddress(0,1,7,1,7))
63 : {
64 9 : }
65 :
66 9 : uno::Reference< sheet::XNamedRanges > ScNamedRangeObj::init_impl()
67 : {
68 9 : OUString aFileURL;
69 9 : createFileURL(OUString("ScNamedRangeObj.ods"), aFileURL);
70 9 : if(!mxComponent.is())
71 1 : mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument");
72 9 : CPPUNIT_ASSERT(mxComponent.is());
73 :
74 18 : uno::Reference< beans::XPropertySet > xPropSet (mxComponent, UNO_QUERY_THROW);
75 18 : OUString aNamedRangesPropertyString("NamedRanges");
76 9 : uno::Reference< sheet::XNamedRanges > xNamedRanges(xPropSet->getPropertyValue(aNamedRangesPropertyString), UNO_QUERY_THROW);
77 9 : CPPUNIT_ASSERT(xNamedRanges.is());
78 :
79 18 : return xNamedRanges;
80 : }
81 :
82 9 : uno::Reference< sheet::XNamedRange> ScNamedRangeObj::getNamedRange(const OUString& rRangeName)
83 : {
84 9 : uno::Reference< container::XNameAccess > xNamedAccess(init_impl(), UNO_QUERY_THROW);
85 9 : uno::Reference< sheet::XNamedRange > xNamedRange(xNamedAccess->getByName(rRangeName), UNO_QUERY_THROW);
86 9 : CPPUNIT_ASSERT(xNamedRange.is());
87 :
88 9 : return xNamedRange;
89 : }
90 :
91 3 : uno::Reference< uno::XInterface > ScNamedRangeObj::init()
92 : {
93 3 : return getNamedRange(OUString("NamedRange"));
94 : }
95 :
96 9 : void ScNamedRangeObj::setUp()
97 : {
98 9 : nTest++;
99 9 : CalcUnoApiTest::setUp();
100 9 : }
101 :
102 9 : void ScNamedRangeObj::tearDown()
103 : {
104 9 : if (nTest == NUMBER_OF_TESTS)
105 : {
106 1 : closeDocument(mxComponent);
107 1 : mxComponent.clear();
108 : }
109 :
110 9 : CalcUnoApiTest::tearDown();
111 9 : }
112 :
113 1 : CPPUNIT_TEST_SUITE_REGISTRATION(ScNamedRangeObj);
114 :
115 : }
116 :
117 4 : CPPUNIT_PLUGIN_IMPLEMENT();
118 :
119 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|