LCOV - code coverage report
Current view: top level - sc/qa/extras - scnamedrangeobj.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 46 46 100.0 %
Date: 2014-11-03 Functions: 14 15 93.3 %
Legend: Lines: hit not hit

          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          36 : 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           4 :     CPPUNIT_TEST_SUITE(ScNamedRangeObj);
      39           2 :     CPPUNIT_TEST(testGetContent);
      40           2 :     CPPUNIT_TEST(testSetContent);
      41           2 :     CPPUNIT_TEST(testGetType);
      42           2 :     CPPUNIT_TEST(testSetType);
      43           2 :     CPPUNIT_TEST(testGetReferencePosition);
      44           2 :     CPPUNIT_TEST(testSetReferencePosition);
      45           2 :     CPPUNIT_TEST(testSetName);
      46           2 :     CPPUNIT_TEST(testGetName);
      47           2 :     CPPUNIT_TEST(testGetReferredCells);
      48           4 :     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           2 : uno::Reference< lang::XComponent > ScNamedRangeObj::mxComponent;
      58             : 
      59          18 : ScNamedRangeObj::ScNamedRangeObj():
      60             :         CalcUnoApiTest("/sc/qa/extras/testdocuments"),
      61             :         apitest::XNamed(OUString("NamedRange")),
      62          18 :         apitest::XCellRangeReferrer(table::CellRangeAddress(0,1,7,1,7))
      63             : {
      64          18 : }
      65             : 
      66          18 : uno::Reference< sheet::XNamedRanges > ScNamedRangeObj::init_impl()
      67             : {
      68          18 :     OUString aFileURL;
      69          18 :     createFileURL(OUString("ScNamedRangeObj.ods"), aFileURL);
      70          18 :     if(!mxComponent.is())
      71           2 :         mxComponent = loadFromDesktop(aFileURL, "com.sun.star.sheet.SpreadsheetDocument");
      72          18 :     CPPUNIT_ASSERT(mxComponent.is());
      73             : 
      74          36 :     uno::Reference< beans::XPropertySet > xPropSet (mxComponent, UNO_QUERY_THROW);
      75          36 :     OUString aNamedRangesPropertyString("NamedRanges");
      76          18 :     uno::Reference< sheet::XNamedRanges > xNamedRanges(xPropSet->getPropertyValue(aNamedRangesPropertyString), UNO_QUERY_THROW);
      77          18 :     CPPUNIT_ASSERT(xNamedRanges.is());
      78             : 
      79          36 :     return xNamedRanges;
      80             : }
      81             : 
      82          18 : uno::Reference< sheet::XNamedRange> ScNamedRangeObj::getNamedRange(const OUString& rRangeName)
      83             : {
      84          18 :     uno::Reference< container::XNameAccess > xNamedAccess(init_impl(), UNO_QUERY_THROW);
      85          18 :     uno::Reference< sheet::XNamedRange > xNamedRange(xNamedAccess->getByName(rRangeName), UNO_QUERY_THROW);
      86          18 :     CPPUNIT_ASSERT(xNamedRange.is());
      87             : 
      88          18 :     return xNamedRange;
      89             : }
      90             : 
      91           6 : uno::Reference< uno::XInterface > ScNamedRangeObj::init()
      92             : {
      93           6 :     return getNamedRange(OUString("NamedRange"));
      94             : }
      95             : 
      96          18 : void ScNamedRangeObj::setUp()
      97             : {
      98          18 :     nTest++;
      99          18 :     CalcUnoApiTest::setUp();
     100          18 : }
     101             : 
     102          18 : void ScNamedRangeObj::tearDown()
     103             : {
     104          18 :     if (nTest == NUMBER_OF_TESTS)
     105             :     {
     106           2 :         closeDocument(mxComponent);
     107           2 :         mxComponent.clear();
     108             :     }
     109             : 
     110          18 :     CalcUnoApiTest::tearDown();
     111          18 : }
     112             : 
     113           2 : CPPUNIT_TEST_SUITE_REGISTRATION(ScNamedRangeObj);
     114             : 
     115             : }
     116             : 
     117           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     118             : 
     119             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10