LCOV - code coverage report
Current view: top level - test/source/sheet - xsheetannotations.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 102 102 100.0 %
Date: 2014-11-03 Functions: 6 6 100.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           2 : void XSheetAnnotations::testCount()
      26             : {
      27           2 :     uno::Reference< sheet::XSheetAnnotations > aSheetAnnotations (init(), UNO_QUERY_THROW);
      28             : 
      29             :     // count on sheet 1 before inserting
      30           4 :     uno::Reference< container::XIndexAccess > xAnnotationsIndex (aSheetAnnotations, UNO_QUERY_THROW);
      31           2 :     sal_Int32 nBefore = xAnnotationsIndex->getCount();
      32             : 
      33             :     // get Sheet 2 annotations
      34           4 :     uno::Reference< sheet::XSheetAnnotations > xSheet2Annotations( getAnnotations(1), UNO_QUERY_THROW);
      35             : 
      36             :     // insert a note on sheet 2
      37           2 :     table::CellAddress xTargetCellAddress (1,0,0);
      38           2 :     xSheet2Annotations->insertNew(xTargetCellAddress, "an inserted annotation on sheet 2");
      39             : 
      40             :     // count again on sheet 1
      41           2 :     sal_Int32 nAfter = xAnnotationsIndex->getCount();
      42             : 
      43           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE( "Annotations count should not change on sheet 1", nBefore, nAfter);
      44           2 : }
      45             : 
      46           2 : void XSheetAnnotations::testInsertNew()
      47             : {
      48           2 :     uno::Reference< sheet::XSheetAnnotations > aSheetAnnotations (init(), UNO_QUERY_THROW);
      49             : 
      50             :     // count before inserting
      51           4 :     uno::Reference< container::XIndexAccess > xAnnotationsIndex (aSheetAnnotations, UNO_QUERY_THROW);
      52           2 :     sal_Int32 nBefore = xAnnotationsIndex->getCount();
      53             : 
      54           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
      55           2 :         "There should already be one note", sal_Int32(1), nBefore );
      56             : 
      57             :     // insert the annotation
      58           2 :     table::CellAddress xTargetCellAddress (0,3,4);
      59           2 :     aSheetAnnotations->insertNew(xTargetCellAddress, "an inserted annotation");
      60             : 
      61             :     // count after inserting
      62             :     //uno::Reference< container::XIndexAccess > xAnnotationsIndexAfter (aSheetAnnotations, UNO_QUERY_THROW);
      63           2 :     sal_Int32 nAfter = xAnnotationsIndex->getCount();
      64             : 
      65           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
      66           2 :         "Annotations index not updated", nBefore + 1, nAfter);
      67             : 
      68             :     // is the position ok ?
      69           4 :     uno::Reference< sheet::XSheetAnnotation > aLastSheetAnnotation (xAnnotationsIndex->getByIndex(nAfter-1), UNO_QUERY_THROW);
      70           2 :     table::CellAddress xResultCellAddress = aLastSheetAnnotation->getPosition();
      71             : 
      72           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
      73             :         "Insert Annotation - Wrong SHEET reference position",
      74           2 :         xTargetCellAddress.Sheet, xResultCellAddress.Sheet);
      75           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
      76             :         "Insert Annotation - Wrong COLUMN reference position",
      77           2 :         xTargetCellAddress.Column, xResultCellAddress.Column);
      78           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
      79             :         "Insert Annotation - Wrong ROW reference position",
      80           2 :         xTargetCellAddress.Row, xResultCellAddress.Row);
      81             : 
      82             :     // is the string ok ?
      83           4 :     uno::Reference< text::XTextRange > aTextSheetAnnotation(aLastSheetAnnotation, UNO_QUERY_THROW);
      84           4 :     OUString aString = aTextSheetAnnotation->getString();
      85             : 
      86           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
      87             :         "Insert Annotation - Wrong string", OUString("an inserted annotation"),
      88           4 :         aString);
      89             : 
      90           2 : }
      91             : 
      92           2 : void XSheetAnnotations::testRemoveByIndex()
      93             : {
      94           2 :     uno::Reference< sheet::XSheetAnnotations > aSheetAnnotations (init(), UNO_QUERY_THROW);
      95             : 
      96             :     // insert some annotations
      97           2 :     table::CellAddress xTargetCellAddress (0,4,5);
      98           2 :     aSheetAnnotations->insertNew(xTargetCellAddress, "an inserted annotation 1");
      99           2 :     table::CellAddress xToBeRemovedCellAddress (0,5,6);
     100           2 :     aSheetAnnotations->insertNew(xToBeRemovedCellAddress, "an inserted annotation 2");
     101           2 :     table::CellAddress xOtherCellAddress (0,7,8);
     102           2 :     aSheetAnnotations->insertNew(xOtherCellAddress, "an inserted annotation 3");
     103             : 
     104             :     // count before removing
     105           4 :     uno::Reference< container::XIndexAccess > xAnnotationsIndex (aSheetAnnotations, UNO_QUERY_THROW);
     106           2 :     sal_Int32 nBefore = xAnnotationsIndex->getCount();
     107             : 
     108             :     // remove the xToBeRemovedCellAddress
     109           2 :     aSheetAnnotations->removeByIndex(nBefore-2);
     110             : 
     111             :     // count after removing
     112             :     //uno::Reference< container::XIndexAccess > xAnnotationsIndex (aSheetAnnotations, UNO_QUERY_THROW);
     113           2 :     sal_Int32 nAfter = xAnnotationsIndex->getCount();
     114             : 
     115             :     // the last position should be xOtherCellAddress
     116           4 :     uno::Reference< sheet::XSheetAnnotation > aLastSheetAnnotation (xAnnotationsIndex->getByIndex(nAfter-1), UNO_QUERY_THROW);
     117           2 :     table::CellAddress xResultCellAddress = aLastSheetAnnotation->getPosition();
     118             : 
     119           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     120             :         "Remove Annotation - Wrong SHEET reference position",
     121           2 :         xOtherCellAddress.Sheet, xResultCellAddress.Sheet);
     122           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     123             :         "Remove Annotation - Wrong COLUMN reference position",
     124           2 :         xOtherCellAddress.Column, xResultCellAddress.Column);
     125           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     126             :         "Remove Annotation - Wrong ROW reference position",
     127           2 :         xOtherCellAddress.Row, xResultCellAddress.Row);
     128             : 
     129             :     // is the string ok ?
     130           4 :     uno::Reference< text::XTextRange > aLastTextSheetAnnotation(aLastSheetAnnotation, UNO_QUERY_THROW);
     131           4 :     OUString aLastString = aLastTextSheetAnnotation->getString();
     132             : 
     133           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     134             :         "Remove Annotation - Wrong string",
     135           2 :         OUString("an inserted annotation 3"), aLastString);
     136             : 
     137             :     // the previous should be xTargetCellAddress
     138           4 :     uno::Reference< sheet::XSheetAnnotation > aPreviousSheetAnnotation (xAnnotationsIndex->getByIndex(nAfter-2), UNO_QUERY_THROW);
     139           2 :     table::CellAddress xPreviousCellAddress = aPreviousSheetAnnotation->getPosition();
     140             : 
     141           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     142             :         "Remove Annotation - Wrong SHEET reference position",
     143           2 :         xTargetCellAddress.Sheet, xPreviousCellAddress.Sheet);
     144           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     145             :         "Remove Annotation - Wrong COLUMN reference position",
     146           2 :         xTargetCellAddress.Column, xPreviousCellAddress.Column);
     147           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     148             :         "Remove Annotation - Wrong ROW reference position",
     149           2 :         xTargetCellAddress.Row, xPreviousCellAddress.Row);
     150             : 
     151             :     // is the string ok ?
     152           4 :     uno::Reference< text::XTextRange > aPreviousTextSheetAnnotation(aPreviousSheetAnnotation, UNO_QUERY_THROW);
     153           4 :     OUString aPreviousString = aPreviousTextSheetAnnotation->getString();
     154             : 
     155           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     156             :         "Remove Annotation - Wrong string",
     157           4 :         OUString("an inserted annotation 1"), aPreviousString);
     158           2 : }
     159             : 
     160           2 : void XSheetAnnotations::testGetByIndex()
     161             : {
     162             : 
     163             :     // testing #fdo80551 - getByIndex not on the first sheet
     164             : 
     165             :     // insert annotations in first sheet
     166           2 :     uno::Reference< sheet::XSheetAnnotations > aSheet0Annotations (init(), UNO_QUERY_THROW);
     167           2 :     table::CellAddress xTargetCellAddress0 (0,0,1);
     168           2 :     aSheet0Annotations->insertNew(xTargetCellAddress0, "an inserted annotation 1 on sheet 1");
     169           2 :     table::CellAddress xSecondTargetCellAddress0 (0,0,2);
     170           2 :     aSheet0Annotations->insertNew(xSecondTargetCellAddress0, "an inserted annotation 2 on sheet 1");
     171           2 :     table::CellAddress xThirdCellAddress0 (0,0,3);
     172           2 :     aSheet0Annotations->insertNew(xThirdCellAddress0, "an inserted annotation 3 on sheet 1");
     173             : 
     174             :     // insert annotations in third sheet
     175           4 :     uno::Reference< sheet::XSheetAnnotations > aSheet2Annotations (getAnnotations(2), UNO_QUERY_THROW);
     176           2 :     table::CellAddress xTargetCellAddress2 (2,4,5);
     177           2 :     aSheet2Annotations->insertNew(xTargetCellAddress2, "an inserted annotation 1 on sheet 3");
     178           2 :     table::CellAddress xSecondTargetCellAddress2 (2,5,6);
     179           2 :     aSheet2Annotations->insertNew(xSecondTargetCellAddress2, "an inserted annotation 2 on sheet 3");
     180           2 :     table::CellAddress xThirdCellAddress2 (2,7,8);
     181           2 :     aSheet2Annotations->insertNew(xThirdCellAddress2, "an inserted annotation 3 on sheet 3");
     182             : 
     183             :     // get second annotation for second sheet
     184           4 :     uno::Reference< sheet::XSheetAnnotations > aSheetAnnotations (getAnnotations(2), UNO_QUERY_THROW);
     185           4 :     uno::Reference< container::XIndexAccess > xAnnotationsIndex (aSheetAnnotations, UNO_QUERY_THROW);
     186           4 :     uno::Reference< sheet::XSheetAnnotation > aAnnotation (xAnnotationsIndex->getByIndex(1), UNO_QUERY_THROW);
     187             : 
     188           2 :     table::CellAddress xToBeAnalyzedCellAddress = aAnnotation->getPosition();
     189             : 
     190             :     // is the CellAddress ok ?
     191           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     192             :         "GetByIndex Annotation - Wrong SHEET reference position",
     193           2 :         xSecondTargetCellAddress2.Sheet, xToBeAnalyzedCellAddress.Sheet);
     194           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     195             :         "GetByIndex Annotation - Wrong COLUMN reference position",
     196           2 :         xSecondTargetCellAddress2.Column, xToBeAnalyzedCellAddress.Column);
     197           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     198             :         "GetByIndex Annotation - Wrong ROW reference position",
     199           2 :         xSecondTargetCellAddress2.Row, xToBeAnalyzedCellAddress.Row);
     200             : 
     201             :     // is the string ok ?
     202           4 :     uno::Reference< text::XTextRange > aTextSheetAnnotation(aAnnotation, UNO_QUERY_THROW);
     203           4 :     OUString aString = aTextSheetAnnotation->getString();
     204             : 
     205           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE(
     206             :         "GetByIndex Annotation - Wrong string",
     207           4 :         OUString("an inserted annotation 2 on sheet 3"), aString);
     208           2 : }
     209             : 
     210         144 : }
     211             : 
     212             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10