LCOV - code coverage report
Current view: top level - test/source/sheet - xnamedrange.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 64 64 100.0 %
Date: 2012-08-25 Functions: 8 8 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 205 410 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4                 :            :  *
       5                 :            :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :            :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :            :  * the License or as specified alternatively below. You may obtain a copy of
       8                 :            :  * the License at http://www.mozilla.org/MPL/
       9                 :            :  *
      10                 :            :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :            :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :            :  * for the specific language governing rights and limitations under the
      13                 :            :  * License.
      14                 :            :  *
      15                 :            :  * Major Contributor(s):
      16                 :            :  * Copyright (C) 2011 Laurent Godard lgodard.libre@laposte.net (initial developer)
      17                 :            :  *
      18                 :            :  * All Rights Reserved.
      19                 :            :  *
      20                 :            :  * For minor contributions see the git repository.
      21                 :            :  *
      22                 :            :  * Alternatively, the contents of this file may be used under the terms of
      23                 :            :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24                 :            :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25                 :            :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26                 :            :  * instead of those above.
      27                 :            :  */
      28                 :            : 
      29                 :            : #include <test/sheet/xnamedrange.hxx>
      30                 :            : 
      31                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      32                 :            : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      33                 :            : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      34                 :            : #include <com/sun/star/table/XCellRange.hpp>
      35                 :            : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
      36                 :            : #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
      37                 :            : #include <com/sun/star/sheet/XNamedRanges.hpp>
      38                 :            : #include <com/sun/star/sheet/XNamedRange.hpp>
      39                 :            : #include <com/sun/star/table/XCell.hpp>
      40                 :            : #include <com/sun/star/text/XTextRange.hpp>
      41                 :            : 
      42                 :            : #include <com/sun/star/table/CellAddress.hpp>
      43                 :            : #include <com/sun/star/table/CellRangeAddress.hpp>
      44                 :            : #include <com/sun/star/sheet/Border.hpp>
      45                 :            : #include <com/sun/star/sheet/NamedRangeFlag.hpp>
      46                 :            : 
      47                 :            : #include "cppunit/extensions/HelperMacros.h"
      48                 :            : #include <rtl/oustringostreaminserter.hxx>
      49                 :            : 
      50                 :            : using namespace com::sun::star::uno;
      51                 :            : 
      52                 :            : namespace apitest {
      53                 :            : 
      54                 :          2 : void XNamedRange::testGetContent()
      55                 :            : {
      56         [ +  - ]:          2 :     rtl::OUString aTestedNamedRangeString(RTL_CONSTASCII_USTRINGPARAM("initial1"));
      57         [ +  - ]:          2 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
      58                 :            : 
      59         [ +  - ]:          2 :     rtl::OUString aExpectedContent(RTL_CONSTASCII_USTRINGPARAM("$Sheet1.$B$1"));
      60 [ +  - ][ +  - ]:          2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 on GetContent", xNamedRange->getContent().equals(aExpectedContent));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      61                 :          2 : }
      62                 :            : 
      63                 :          2 : void XNamedRange::testSetContent()
      64                 :            : {
      65         [ +  - ]:          2 :     rtl::OUString aTestedNamedRangeString(RTL_CONSTASCII_USTRINGPARAM("initial1"));
      66         [ +  - ]:          2 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
      67                 :            : 
      68                 :          2 :     rtl::OUString aExpectedContent;
      69                 :            : 
      70                 :            :     // test a cell
      71         [ +  - ]:          2 :     aExpectedContent = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("D1"));
      72 [ +  - ][ +  - ]:          2 :     xNamedRange->setContent(aExpectedContent);
      73 [ +  - ][ +  - ]:          2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 after SetContent a cell", xNamedRange->getContent().equals(aExpectedContent));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      74                 :            : 
      75                 :            :     // test a cellrange
      76         [ +  - ]:          2 :     aExpectedContent = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("D1:D10"));
      77 [ +  - ][ +  - ]:          2 :     xNamedRange->setContent(aExpectedContent);
      78 [ +  - ][ +  - ]:          2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 after SetContent a cellrange", xNamedRange->getContent().equals(aExpectedContent));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      79                 :            : 
      80                 :            :     // test a formula
      81         [ +  - ]:          2 :     aExpectedContent = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("=D10"));
      82 [ +  - ][ +  - ]:          2 :     xNamedRange->setContent(aExpectedContent);
      83         [ +  - ]:          2 :     aExpectedContent = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("D10"));
      84 [ +  - ][ +  - ]:          2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 after SetContent a formula", xNamedRange->getContent().equals(aExpectedContent));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      85                 :            : 
      86                 :          2 : }
      87                 :            : 
      88                 :          2 : void XNamedRange::testGetType()
      89                 :            : {
      90         [ +  - ]:          2 :     rtl::OUString aTestedNamedRangeString(RTL_CONSTASCII_USTRINGPARAM("initial1"));
      91         [ +  - ]:          2 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
      92 [ +  - ][ +  - ]:          2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type", xNamedRange->getType() == 0);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      93                 :          2 : }
      94                 :            : 
      95                 :          2 : void XNamedRange::testSetType()
      96                 :            : {
      97         [ +  - ]:          2 :     rtl::OUString aTestedNamedRangeString(RTL_CONSTASCII_USTRINGPARAM("initial1"));
      98         [ +  - ]:          2 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
      99                 :            : 
     100                 :          2 :     sal_Int32 nType = ::sheet::NamedRangeFlag::ROW_HEADER;;
     101 [ +  - ][ +  - ]:          2 :     xNamedRange->setType(nType);
     102 [ +  - ][ +  - ]:          2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type ROW_HEADER after setting it", xNamedRange->getType() == nType);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     103                 :            : 
     104                 :          2 :     nType = ::sheet::NamedRangeFlag::COLUMN_HEADER;
     105 [ +  - ][ +  - ]:          2 :     xNamedRange->setType(nType);
     106 [ +  - ][ +  - ]:          2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type COLUMN_HEADER after setting it", xNamedRange->getType() == nType);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     107                 :            : 
     108                 :          2 :     nType = ::sheet::NamedRangeFlag::FILTER_CRITERIA;
     109 [ +  - ][ +  - ]:          2 :     xNamedRange->setType(nType);
     110 [ +  - ][ +  - ]:          2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type FILTER_CRITERIA after setting it", xNamedRange->getType() == nType);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     111                 :            : 
     112                 :          2 :     nType = ::sheet::NamedRangeFlag::PRINT_AREA;
     113 [ +  - ][ +  - ]:          2 :     xNamedRange->setType(nType);
     114 [ +  - ][ +  - ]:          2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type PRINT_AREA after setting it", xNamedRange->getType() == nType);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     115                 :            : 
     116                 :          2 :     nType = 0;
     117 [ +  - ][ +  - ]:          2 :     xNamedRange->setType(nType);
     118 [ +  - ][ +  - ]:          2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type 0 after setting it", xNamedRange->getType() == nType);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     119                 :          2 : }
     120                 :            : 
     121                 :          2 : void XNamedRange::testGetReferencePosition()
     122                 :            : {
     123         [ +  - ]:          2 :     rtl::OUString aTestedNamedRangeString(RTL_CONSTASCII_USTRINGPARAM("initial2"));
     124         [ +  - ]:          2 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
     125                 :            : 
     126 [ +  - ][ +  - ]:          2 :     table::CellAddress xCellAddress = xNamedRange->getReferencePosition();
     127                 :            :     // the expeted address is on B1, as it was the active cell when intial2 created
     128 [ +  - ][ +  - ]:          2 :     CPPUNIT_ASSERT_MESSAGE("Wrong SHEET reference position", xCellAddress.Sheet == 0);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     129 [ +  - ][ +  - ]:          2 :     CPPUNIT_ASSERT_MESSAGE("Wrong COLUMN reference position", xCellAddress.Column == 1);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     130 [ +  - ][ +  - ]:          2 :     CPPUNIT_ASSERT_MESSAGE("Wrong ROW reference position", xCellAddress.Row == 0);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     131                 :          2 : }
     132                 :            : 
     133                 :          2 : void XNamedRange::testSetReferencePosition()
     134                 :            : {
     135         [ +  - ]:          2 :     rtl::OUString aTestedNamedRangeString(RTL_CONSTASCII_USTRINGPARAM("initial1"));
     136         [ +  - ]:          2 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
     137                 :            : 
     138                 :          2 :     table::CellAddress aBaseAddress = table::CellAddress(1,2,3);
     139                 :            : 
     140 [ +  - ][ +  - ]:          2 :     xNamedRange->setReferencePosition(aBaseAddress);
     141                 :            : 
     142 [ +  - ][ +  - ]:          2 :     table::CellAddress xCellAddress = xNamedRange->getReferencePosition();
     143 [ +  - ][ +  - ]:          2 :     CPPUNIT_ASSERT_MESSAGE("Wrong SHEET reference position after setting it", xCellAddress.Sheet == 1);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     144 [ +  - ][ +  - ]:          2 :     CPPUNIT_ASSERT_MESSAGE("Wrong COLUMN reference position after setting it", xCellAddress.Column == 2);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     145 [ +  - ][ +  - ]:          2 :     CPPUNIT_ASSERT_MESSAGE("Wrong ROW reference position after setting it", xCellAddress.Row == 3);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     146                 :          2 : }
     147                 :            : 
     148                 :            : 
     149                 :            : 
     150 [ +  - ][ +  - ]:         66 : }
     151                 :            : 
     152                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10