LCOV - code coverage report
Current view: top level - test/source/sheet - xnamedrange.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 64 64 100.0 %
Date: 2014-11-03 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           2 : void XNamedRange::testGetContent()
      37             : {
      38           2 :     OUString aTestedNamedRangeString("initial1");
      39           4 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
      40             : 
      41           4 :     OUString aExpectedContent("$Sheet1.$B$1");
      42           4 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 on GetContent", xNamedRange->getContent().equals(aExpectedContent));
      43           2 : }
      44             : 
      45           2 : void XNamedRange::testSetContent()
      46             : {
      47           2 :     OUString aTestedNamedRangeString("initial1");
      48           4 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
      49             : 
      50           4 :     OUString aExpectedContent;
      51             : 
      52             :     // test a cell
      53           2 :     aExpectedContent = "D1";
      54           2 :     xNamedRange->setContent(aExpectedContent);
      55           2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 after SetContent a cell", xNamedRange->getContent().equals(aExpectedContent));
      56             : 
      57             :     // test a cellrange
      58           2 :     aExpectedContent = "D1:D10";
      59           2 :     xNamedRange->setContent(aExpectedContent);
      60           2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 after SetContent a cellrange", xNamedRange->getContent().equals(aExpectedContent));
      61             : 
      62             :     // test a formula
      63           2 :     aExpectedContent = "=D10";
      64           2 :     xNamedRange->setContent(aExpectedContent);
      65           2 :     aExpectedContent = "D10";
      66           4 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 after SetContent a formula", xNamedRange->getContent().equals(aExpectedContent));
      67             : 
      68           2 : }
      69             : 
      70           2 : void XNamedRange::testGetType()
      71             : {
      72           2 :     OUString aTestedNamedRangeString("initial1");
      73           4 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
      74           4 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type", xNamedRange->getType() == 0);
      75           2 : }
      76             : 
      77           2 : void XNamedRange::testSetType()
      78             : {
      79           2 :     OUString aTestedNamedRangeString("initial1");
      80           4 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
      81             : 
      82           2 :     sal_Int32 nType = ::sheet::NamedRangeFlag::ROW_HEADER;;
      83           2 :     xNamedRange->setType(nType);
      84           2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type ROW_HEADER after setting it", xNamedRange->getType() == nType);
      85             : 
      86           2 :     nType = ::sheet::NamedRangeFlag::COLUMN_HEADER;
      87           2 :     xNamedRange->setType(nType);
      88           2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type COLUMN_HEADER after setting it", xNamedRange->getType() == nType);
      89             : 
      90           2 :     nType = ::sheet::NamedRangeFlag::FILTER_CRITERIA;
      91           2 :     xNamedRange->setType(nType);
      92           2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type FILTER_CRITERIA after setting it", xNamedRange->getType() == nType);
      93             : 
      94           2 :     nType = ::sheet::NamedRangeFlag::PRINT_AREA;
      95           2 :     xNamedRange->setType(nType);
      96           2 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type PRINT_AREA after setting it", xNamedRange->getType() == nType);
      97             : 
      98           2 :     nType = 0;
      99           2 :     xNamedRange->setType(nType);
     100           4 :     CPPUNIT_ASSERT_MESSAGE("Wrong expected Type 0 after setting it", xNamedRange->getType() == nType);
     101           2 : }
     102             : 
     103           2 : void XNamedRange::testGetReferencePosition()
     104             : {
     105           2 :     OUString aTestedNamedRangeString("initial2");
     106           4 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
     107             : 
     108           2 :     table::CellAddress xCellAddress = xNamedRange->getReferencePosition();
     109             :     // the expeted address is on B1, as it was the active cell when intial2 created
     110           2 :     CPPUNIT_ASSERT_MESSAGE("Wrong SHEET reference position", xCellAddress.Sheet == 0);
     111           2 :     CPPUNIT_ASSERT_MESSAGE("Wrong COLUMN reference position", xCellAddress.Column == 1);
     112           4 :     CPPUNIT_ASSERT_MESSAGE("Wrong ROW reference position", xCellAddress.Row == 0);
     113           2 : }
     114             : 
     115           2 : void XNamedRange::testSetReferencePosition()
     116             : {
     117           2 :     OUString aTestedNamedRangeString("initial1");
     118           4 :     uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
     119             : 
     120           2 :     table::CellAddress aBaseAddress = table::CellAddress(1,2,3);
     121             : 
     122           2 :     xNamedRange->setReferencePosition(aBaseAddress);
     123             : 
     124           2 :     table::CellAddress xCellAddress = xNamedRange->getReferencePosition();
     125           2 :     CPPUNIT_ASSERT_MESSAGE("Wrong SHEET reference position after setting it", xCellAddress.Sheet == 1);
     126           2 :     CPPUNIT_ASSERT_MESSAGE("Wrong COLUMN reference position after setting it", xCellAddress.Column == 2);
     127           4 :     CPPUNIT_ASSERT_MESSAGE("Wrong ROW reference position after setting it", xCellAddress.Row == 3);
     128           2 : }
     129             : 
     130         144 : }
     131             : 
     132             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10