LCOV - code coverage report
Current view: top level - sc/qa/extras - scannotationsobj.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 38 38 100.0 %
Date: 2014-11-03 Functions: 13 14 92.9 %
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/xsheetannotations.hxx>
      12             : 
      13             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      14             : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      15             : 
      16             : #include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
      17             : 
      18             : using namespace css;
      19             : using namespace css::uno;
      20             : 
      21             : namespace sc_apitest {
      22             : 
      23             : #define NUMBER_OF_TESTS 4
      24             : 
      25          16 : class ScAnnontationsObj : public CalcUnoApiTest, apitest::XSheetAnnotations
      26             : {
      27             : public:
      28             :     ScAnnontationsObj();
      29             : 
      30             :     virtual void setUp() SAL_OVERRIDE;
      31             :     virtual void tearDown() SAL_OVERRIDE;
      32             : 
      33             :     virtual uno::Reference< uno::XInterface > init() SAL_OVERRIDE;
      34             :     virtual uno::Reference< sheet::XSheetAnnotations > getAnnotations(long nIndex) SAL_OVERRIDE;
      35             : 
      36           4 :     CPPUNIT_TEST_SUITE(ScAnnontationsObj);
      37           2 :     CPPUNIT_TEST(testInsertNew);
      38           2 :     CPPUNIT_TEST(testRemoveByIndex);
      39           2 :     CPPUNIT_TEST(testCount);
      40           2 :     CPPUNIT_TEST(testGetByIndex);
      41           4 :     CPPUNIT_TEST_SUITE_END();
      42             : private:
      43             : 
      44             :     static sal_Int32 nTest;
      45             :     static uno::Reference< lang::XComponent > mxComponent;
      46             : };
      47             : 
      48             : sal_Int32 ScAnnontationsObj::nTest = 0;
      49           2 : uno::Reference< lang::XComponent > ScAnnontationsObj::mxComponent;
      50             : 
      51           8 : ScAnnontationsObj::ScAnnontationsObj()
      52           8 :        : CalcUnoApiTest("/sc/qa/extras/testdocuments")
      53             : {
      54           8 : }
      55             : 
      56          14 : uno::Reference< sheet::XSheetAnnotations> ScAnnontationsObj::getAnnotations(long nIndex)
      57             : {
      58             :     // get the sheet
      59          14 :     uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW);
      60          28 :     uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), UNO_QUERY_THROW);
      61          28 :     uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(nIndex), UNO_QUERY_THROW);
      62             : 
      63             :     // get the annotations collection
      64          28 :     uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnotationSupplier(xSheet, UNO_QUERY_THROW);
      65          14 :     uno::Reference< sheet::XSheetAnnotations > xSheetAnnotations( xAnnotationSupplier->getAnnotations(), UNO_QUERY_THROW);
      66             : 
      67          14 :     CPPUNIT_ASSERT(xSheetAnnotations.is());
      68             : 
      69          28 :     return xSheetAnnotations;
      70             : }
      71             : 
      72           8 : uno::Reference< uno::XInterface > ScAnnontationsObj::init()
      73             : {
      74             :     // get the test file
      75           8 :     OUString aFileURL;
      76           8 :     createFileURL(OUString("ScAnnotationObj.ods"), aFileURL);
      77           8 :     if(!mxComponent.is())
      78           2 :         mxComponent = loadFromDesktop(aFileURL);
      79           8 :     CPPUNIT_ASSERT_MESSAGE("Component not loaded",mxComponent.is());
      80             : 
      81           8 :     return getAnnotations(0);
      82             : }
      83           8 : void ScAnnontationsObj::setUp()
      84             : {
      85           8 :     nTest++;
      86           8 :     CalcUnoApiTest::setUp();
      87           8 : }
      88             : 
      89           8 : void ScAnnontationsObj::tearDown()
      90             : {
      91           8 :     if (nTest == NUMBER_OF_TESTS)
      92             :     {
      93           2 :         closeDocument(mxComponent);
      94           2 :         mxComponent.clear();
      95             :     }
      96             : 
      97           8 :     CalcUnoApiTest::tearDown();
      98           8 : }
      99             : 
     100           2 : CPPUNIT_TEST_SUITE_REGISTRATION(ScAnnontationsObj);
     101             : 
     102             : }
     103             : 
     104           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     105             : 
     106             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10