LCOV - code coverage report
Current view: top level - test/source/sheet - xsheetannotations.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 72 0.0 %
Date: 2014-04-14 Functions: 0 5 0.0 %
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/sheet/xsheetannotations.hxx>
      11             : 
      12             : #include <com/sun/star/table/CellAddress.hpp>
      13             : #include <com/sun/star/container/XIndexAccess.hpp>
      14             : #include <com/sun/star/sheet/XSheetAnnotation.hpp>
      15             : #include <com/sun/star/text/XTextRange.hpp>
      16             : 
      17             : #include "cppunit/extensions/HelperMacros.h"
      18             : #include <rtl/ustring.hxx>
      19             : 
      20             : using namespace css;
      21             : using namespace css::uno;
      22             : 
      23             : namespace apitest {
      24             : 
      25           0 : void XSheetAnnotations::testCount()
      26             : {
      27           0 :     uno::Reference< sheet::XSheetAnnotations > aSheetAnnotations (init(), UNO_QUERY_THROW);
      28             : 
      29             :     // count on sheet 1 before inserting
      30           0 :     uno::Reference< container::XIndexAccess > xAnnotationsIndex (aSheetAnnotations, UNO_QUERY_THROW);
      31           0 :     sal_Int32 nBefore = xAnnotationsIndex->getCount();
      32             : 
      33             :     // get Sheet 2 annotations
      34           0 :     uno::Reference< sheet::XSheetAnnotations > xSheet2Annotations( getAnnotations(1), UNO_QUERY_THROW);
      35             : 
      36             :     // insert a note on sheet 2
      37           0 :     table::CellAddress xTargetCellAddress (1,0,0);
      38           0 :     xSheet2Annotations->insertNew(xTargetCellAddress, "an inserted annotation on sheet 2");
      39             : 
      40             :     // count again on sheet 1
      41           0 :     sal_Int32 nAfter = xAnnotationsIndex->getCount();
      42             : 
      43           0 :     CPPUNIT_ASSERT_EQUAL_MESSAGE( "Annotations count should not change on sheet 1", nBefore, nAfter);
      44           0 : }
      45             : 
      46           0 : void XSheetAnnotations::testInsertNew()
      47             : {
      48           0 :     uno::Reference< sheet::XSheetAnnotations > aSheetAnnotations (init(), UNO_QUERY_THROW);
      49             : 
      50             :     // count before inserting
      51           0 :     uno::Reference< container::XIndexAccess > xAnnotationsIndex (aSheetAnnotations, UNO_QUERY_THROW);
      52           0 :     sal_Int32 nBefore = xAnnotationsIndex->getCount();
      53             : 
      54           0 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
      55           0 :         "There should already be one note", sal_Int32(1), nBefore );
      56             : 
      57             :     // insert the annotation
      58           0 :     table::CellAddress xTargetCellAddress (0,3,4);
      59           0 :     aSheetAnnotations->insertNew(xTargetCellAddress, "an inserted annotation");
      60             : 
      61             :     // count after inserting
      62             :     //uno::Reference< container::XIndexAccess > xAnnotationsIndexAfter (aSheetAnnotations, UNO_QUERY_THROW);
      63           0 :     sal_Int32 nAfter = xAnnotationsIndex->getCount();
      64             : 
      65           0 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
      66           0 :         "Annotations index not updated", nBefore + 1, nAfter);
      67             : 
      68             :     // is the position ok ?
      69           0 :     uno::Reference< sheet::XSheetAnnotation > aLastSheetAnnotation (xAnnotationsIndex->getByIndex(nAfter-1), UNO_QUERY_THROW);
      70           0 :     table::CellAddress xResultCellAddress = aLastSheetAnnotation->getPosition();
      71             : 
      72           0 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
      73             :         "Insert Annotation - Wrong SHEET reference position",
      74           0 :         xTargetCellAddress.Sheet, xResultCellAddress.Sheet);
      75           0 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
      76             :         "Insert Annotation - Wrong COLUMN reference position",
      77           0 :         xTargetCellAddress.Column, xResultCellAddress.Column);
      78           0 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
      79             :         "Insert Annotation - Wrong ROW reference position",
      80           0 :         xTargetCellAddress.Row, xResultCellAddress.Row);
      81             : 
      82             :     // is the string ok ?
      83           0 :     uno::Reference< text::XTextRange > aTextSheetAnnotation(aLastSheetAnnotation, UNO_QUERY_THROW);
      84           0 :     OUString aString = aTextSheetAnnotation->getString();
      85             : 
      86           0 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
      87             :         "Insert Annotation - Wrong string", OUString("an inserted annotation"),
      88           0 :         aString);
      89             : 
      90           0 : }
      91             : 
      92           0 : void XSheetAnnotations::testRemoveByIndex()
      93             : {
      94           0 :     uno::Reference< sheet::XSheetAnnotations > aSheetAnnotations (init(), UNO_QUERY_THROW);
      95             : 
      96             :     // insert some annotations
      97           0 :     table::CellAddress xTargetCellAddress (0,4,5);
      98           0 :     aSheetAnnotations->insertNew(xTargetCellAddress, "an inserted annotation 1");
      99           0 :     table::CellAddress xToBeRemovedCellAddress (0,5,6);
     100           0 :     aSheetAnnotations->insertNew(xToBeRemovedCellAddress, "an inserted annotation 2");
     101           0 :     table::CellAddress xOtherCellAddress (0,7,8);
     102           0 :     aSheetAnnotations->insertNew(xOtherCellAddress, "an inserted annotation 3");
     103             : 
     104             :     // count before removing
     105           0 :     uno::Reference< container::XIndexAccess > xAnnotationsIndex (aSheetAnnotations, UNO_QUERY_THROW);
     106           0 :     sal_Int32 nBefore = xAnnotationsIndex->getCount();
     107             : 
     108             :     // remove the xToBeRemovedCellAddress
     109           0 :     aSheetAnnotations->removeByIndex(nBefore-2);
     110             : 
     111             :     // count after removing
     112             :     //uno::Reference< container::XIndexAccess > xAnnotationsIndex (aSheetAnnotations, UNO_QUERY_THROW);
     113           0 :     sal_Int32 nAfter = xAnnotationsIndex->getCount();
     114             : 
     115             :     // the last position should be xOtherCellAddress
     116           0 :     uno::Reference< sheet::XSheetAnnotation > aLastSheetAnnotation (xAnnotationsIndex->getByIndex(nAfter-1), UNO_QUERY_THROW);
     117           0 :     table::CellAddress xResultCellAddress = aLastSheetAnnotation->getPosition();
     118             : 
     119           0 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     120             :         "Remove Annotation - Wrong SHEET reference position",
     121           0 :         xOtherCellAddress.Sheet, xResultCellAddress.Sheet);
     122           0 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     123             :         "Remove Annotation - Wrong COLUMN reference position",
     124           0 :         xOtherCellAddress.Column, xResultCellAddress.Column);
     125           0 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     126             :         "Remove Annotation - Wrong ROW reference position",
     127           0 :         xOtherCellAddress.Row, xResultCellAddress.Row);
     128             : 
     129             :     // is the string ok ?
     130           0 :     uno::Reference< text::XTextRange > aLastTextSheetAnnotation(aLastSheetAnnotation, UNO_QUERY_THROW);
     131           0 :     OUString aLastString = aLastTextSheetAnnotation->getString();
     132             : 
     133           0 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     134             :         "Remove Annotation - Wrong string",
     135           0 :         OUString("an inserted annotation 3"), aLastString);
     136             : 
     137             :     // the previous should be xTargetCellAddress
     138           0 :     uno::Reference< sheet::XSheetAnnotation > aPreviousSheetAnnotation (xAnnotationsIndex->getByIndex(nAfter-2), UNO_QUERY_THROW);
     139           0 :     table::CellAddress xPreviousCellAddress = aPreviousSheetAnnotation->getPosition();
     140             : 
     141           0 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     142             :         "Remove Annotation - Wrong SHEET reference position",
     143           0 :         xTargetCellAddress.Sheet, xPreviousCellAddress.Sheet);
     144           0 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     145             :         "Remove Annotation - Wrong COLUMN reference position",
     146           0 :         xTargetCellAddress.Column, xPreviousCellAddress.Column);
     147           0 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     148             :         "Remove Annotation - Wrong ROW reference position",
     149           0 :         xTargetCellAddress.Row, xPreviousCellAddress.Row);
     150             : 
     151             :     // is the string ok ?
     152           0 :     uno::Reference< text::XTextRange > aPreviousTextSheetAnnotation(aPreviousSheetAnnotation, UNO_QUERY_THROW);
     153           0 :     OUString aPreviousString = aPreviousTextSheetAnnotation->getString();
     154             : 
     155           0 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     156             :         "Remove Annotation - Wrong string",
     157           0 :         OUString("an inserted annotation 1"), aPreviousString);
     158             : 
     159           0 : }
     160             : 
     161           0 : }
     162             : 
     163             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10