LCOV - code coverage report
Current view: top level - test/source/sheet - xnamedrange.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 64 64 100.0 %
Date: 2015-06-13 12:38:46 Functions: 8 8 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/xnamedrange.hxx>
      11             : 
      12             : #include <com/sun/star/beans/XPropertySet.hpp>
      13             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      14             : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      15             : #include <com/sun/star/table/XCellRange.hpp>
      16             : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
      17             : #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
      18             : #include <com/sun/star/sheet/XNamedRanges.hpp>
      19             : #include <com/sun/star/sheet/XNamedRange.hpp>
      20             : #include <com/sun/star/table/XCell.hpp>
      21             : #include <com/sun/star/text/XTextRange.hpp>
      22             : 
      23             : #include <com/sun/star/table/CellAddress.hpp>
      24             : #include <com/sun/star/table/CellRangeAddress.hpp>
      25             : #include <com/sun/star/sheet/Border.hpp>
      26             : #include <com/sun/star/sheet/NamedRangeFlag.hpp>
      27             : 
      28             : #include "cppunit/extensions/HelperMacros.h"
      29             : #include <rtl/ustring.hxx>
      30             : 
      31             : using namespace css;
      32             : using namespace css::uno;
      33             : 
      34             : namespace apitest {
      35             : 
      36           1 : void XNamedRange::testGetContent()
      37             : {
      38           1 :     OUString aTestedNamedRangeString("initial1");
      39           2 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
      40             : 
      41           2 :     OUString aExpectedContent("$Sheet1.$B$1");
      42           2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 on GetContent", xNamedRange->getContent().equals(aExpectedContent));
      43           1 : }
      44             : 
      45           1 : void XNamedRange::testSetContent()
      46             : {
      47           1 :     OUString aTestedNamedRangeString("initial1");
      48           2 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
      49             : 
      50           2 :     OUString aExpectedContent;
      51             : 
      52             :     // test a cell
      53           1 :     aExpectedContent = "D1";
      54           1 :     xNamedRange->setContent(aExpectedContent);
      55           1 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 after SetContent a cell", xNamedRange->getContent().equals(aExpectedContent));
      56             : 
      57             :     // test a cellrange
      58           1 :     aExpectedContent = "D1:D10";
      59           1 :     xNamedRange->setContent(aExpectedContent);
      60           1 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 after SetContent a cellrange", xNamedRange->getContent().equals(aExpectedContent));
      61             : 
      62             :     // test a formula
      63           1 :     aExpectedContent = "=D10";
      64           1 :     xNamedRange->setContent(aExpectedContent);
      65           1 :     aExpectedContent = "D10";
      66           2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 after SetContent a formula", xNamedRange->getContent().equals(aExpectedContent));
      67             : 
      68           1 : }
      69             : 
      70           1 : void XNamedRange::testGetType()
      71             : {
      72           1 :     OUString aTestedNamedRangeString("initial1");
      73           2 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
      74           2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type", xNamedRange->getType() == 0);
      75           1 : }
      76             : 
      77           1 : void XNamedRange::testSetType()
      78             : {
      79           1 :     OUString aTestedNamedRangeString("initial1");
      80           2 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
      81             : 
      82           1 :     sal_Int32 nType = ::sheet::NamedRangeFlag::ROW_HEADER;;
      83           1 :     xNamedRange->setType(nType);
      84           1 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type ROW_HEADER after setting it", xNamedRange->getType() == nType);
      85             : 
      86           1 :     nType = ::sheet::NamedRangeFlag::COLUMN_HEADER;
      87           1 :     xNamedRange->setType(nType);
      88           1 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type COLUMN_HEADER after setting it", xNamedRange->getType() == nType);
      89             : 
      90           1 :     nType = ::sheet::NamedRangeFlag::FILTER_CRITERIA;
      91           1 :     xNamedRange->setType(nType);
      92           1 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type FILTER_CRITERIA after setting it", xNamedRange->getType() == nType);
      93             : 
      94           1 :     nType = ::sheet::NamedRangeFlag::PRINT_AREA;
      95           1 :     xNamedRange->setType(nType);
      96           1 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type PRINT_AREA after setting it", xNamedRange->getType() == nType);
      97             : 
      98           1 :     nType = 0;
      99           1 :     xNamedRange->setType(nType);
     100           2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type 0 after setting it", xNamedRange->getType() == nType);
     101           1 : }
     102             : 
     103           1 : void XNamedRange::testGetReferencePosition()
     104             : {
     105           1 :     OUString aTestedNamedRangeString("initial2");
     106           2 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
     107             : 
     108           1 :     table::CellAddress xCellAddress = xNamedRange->getReferencePosition();
     109             :     // the expected address is on B1, as it was the active cell when intial2 created
     110           1 :     CPPUNIT_ASSERT_MESSAGE("Wrong SHEET reference position", xCellAddress.Sheet == 0);
     111           1 :     CPPUNIT_ASSERT_MESSAGE("Wrong COLUMN reference position", xCellAddress.Column == 1);
     112           2 :     CPPUNIT_ASSERT_MESSAGE("Wrong ROW reference position", xCellAddress.Row == 0);
     113           1 : }
     114             : 
     115           1 : void XNamedRange::testSetReferencePosition()
     116             : {
     117           1 :     OUString aTestedNamedRangeString("initial1");
     118           2 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
     119             : 
     120           1 :     table::CellAddress aBaseAddress = table::CellAddress(1,2,3);
     121             : 
     122           1 :     xNamedRange->setReferencePosition(aBaseAddress);
     123             : 
     124           1 :     table::CellAddress xCellAddress = xNamedRange->getReferencePosition();
     125           1 :     CPPUNIT_ASSERT_MESSAGE("Wrong SHEET reference position after setting it", xCellAddress.Sheet == 1);
     126           1 :     CPPUNIT_ASSERT_MESSAGE("Wrong COLUMN reference position after setting it", xCellAddress.Column == 2);
     127           2 :     CPPUNIT_ASSERT_MESSAGE("Wrong ROW reference position after setting it", xCellAddress.Row == 3);
     128           1 : }
     129             : 
     130          90 : }
     131             : 
     132             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11