LCOV - code coverage report
Current view: top level - test/source/sheet - xdatapilotdescriptor.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 107 114 93.9 %
Date: 2014-04-11 Functions: 12 13 92.3 %
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/xdatapilotdescriptor.hxx"
      11             : 
      12             : #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
      13             : #include <com/sun/star/table/CellRangeAddress.hpp>
      14             : #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
      15             : #include <com/sun/star/beans/XPropertySet.hpp>
      16             : 
      17             : #include "cppunit/extensions/HelperMacros.h"
      18             : 
      19             : #include <rtl/ustring.hxx>
      20             : 
      21             : using namespace css;
      22             : using namespace css::uno;
      23             : 
      24             : namespace apitest {
      25             : 
      26          20 : std::vector< OUString > XDataPilotDescriptor::maFieldNames;
      27             : 
      28           1 : void XDataPilotDescriptor::testTag()
      29             : {
      30           1 :     OUString aTag("DataPilotDescriptor_Tag");
      31           2 :     uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
      32           1 :     xDescr->setTag(aTag);
      33           2 :     OUString aNewTag = xDescr->getTag();
      34           2 :     CPPUNIT_ASSERT( aTag == aNewTag );
      35           1 : }
      36             : 
      37           1 : void XDataPilotDescriptor::testSourceRange()
      38             : {
      39           1 :     uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
      40           1 :     table::CellRangeAddress aOldAddress = xDescr->getSourceRange();
      41             : 
      42           1 :     table::CellRangeAddress aAddress;
      43           1 :     aAddress.Sheet = 1;
      44           1 :     aAddress.StartColumn = 1;
      45           1 :     aAddress.StartRow = 1;
      46           1 :     aAddress.EndColumn = 5;
      47           1 :     aAddress.EndRow = 5;
      48           1 :     xDescr->setSourceRange(aAddress);
      49             : 
      50           1 :     table::CellRangeAddress aReturn;
      51           1 :     aReturn = xDescr->getSourceRange();
      52             : 
      53           1 :     CPPUNIT_ASSERT(aAddress.Sheet == aReturn.Sheet);
      54           1 :     CPPUNIT_ASSERT(aAddress.StartColumn == aReturn.StartColumn);
      55           1 :     CPPUNIT_ASSERT(aAddress.StartRow == aReturn.StartRow);
      56           1 :     CPPUNIT_ASSERT(aAddress.EndColumn == aReturn.EndColumn);
      57           1 :     CPPUNIT_ASSERT(aAddress.EndRow == aReturn.EndRow);
      58             : 
      59             :     //restore old settings
      60           1 :     xDescr->setSourceRange(aOldAddress);
      61           1 : }
      62             : 
      63           1 : void XDataPilotDescriptor::testGetFilterDescriptor()
      64             : {
      65           1 :     uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
      66           2 :     uno::Reference< sheet::XSheetFilterDescriptor > xSheetFilterDescr = xDescr->getFilterDescriptor();
      67           2 :     CPPUNIT_ASSERT(xSheetFilterDescr.is());
      68           1 : }
      69             : 
      70           5 : void XDataPilotDescriptor::testGetDataPilotFields_Impl( uno::Reference< sheet::XDataPilotDescriptor > xDescr)
      71             : {
      72             :     //this method should only be called once but needs to be called before any of the other tests
      73             :     static bool bCalled = false;
      74           5 :     if (bCalled)
      75           9 :         return;
      76             :     else
      77           1 :         bCalled = true;
      78             : 
      79           1 :     uno::Reference< container::XIndexAccess > xIndex(xDescr->getDataPilotFields(), UNO_QUERY_THROW);
      80           1 :     CPPUNIT_ASSERT( xIndex.is());
      81             : 
      82           1 :     sal_Int32 nCount = xIndex->getCount();
      83             : 
      84           2 :     OUString aOrientation("Orientation");
      85           6 :     for (sal_Int32 i = 0; i < nCount && i < 5; ++i)
      86             :     {
      87           5 :         uno::Reference< container::XNamed > xNamed( xIndex->getByIndex( i ), UNO_QUERY_THROW);
      88           5 :         CPPUNIT_ASSERT(xNamed.is());
      89          10 :         OUString aName = xNamed->getName();
      90           5 :         maFieldNames.push_back(aName);
      91           5 :         CPPUNIT_ASSERT( aName != "Data" );
      92             : 
      93          10 :         uno::Reference< beans::XPropertySet > xPropSet( xNamed, UNO_QUERY_THROW);
      94           5 :         CPPUNIT_ASSERT( xPropSet.is() );
      95             : 
      96           5 :         switch ( i % 5 )
      97             :         {
      98             :             case 0:
      99             :                 {
     100           1 :                     uno::Any aAny;
     101           1 :                     aAny<<= sheet::DataPilotFieldOrientation_COLUMN;
     102           1 :                     xPropSet->setPropertyValue(aOrientation, aAny);
     103             :                 }
     104           1 :                 break;
     105             :             case 1:
     106             :                 {
     107           1 :                     uno::Any aAny;
     108           1 :                     aAny<<= sheet::DataPilotFieldOrientation_ROW;
     109           1 :                     xPropSet->setPropertyValue(aOrientation, aAny);
     110             :                 }
     111           1 :                 break;
     112             :             case 2:
     113             :                 {
     114           1 :                     uno::Any aAny;
     115           1 :                     aAny<<= sheet::DataPilotFieldOrientation_DATA;
     116           1 :                     xPropSet->setPropertyValue(aOrientation, aAny);
     117             :                 }
     118           1 :                 break;
     119             :             case 3:
     120             :                 {
     121           1 :                     uno::Any aAny;
     122           1 :                     aAny<<= sheet::DataPilotFieldOrientation_HIDDEN;
     123           1 :                     xPropSet->setPropertyValue(aOrientation, aAny);
     124             :                 }
     125           1 :                 break;
     126             :             case 4:
     127             :                 {
     128           1 :                     uno::Any aAny;
     129           1 :                     aAny<<= sheet::DataPilotFieldOrientation_PAGE;
     130           1 :                     xPropSet->setPropertyValue(aOrientation, aAny);
     131             :                 }
     132           1 :                 break;
     133             :         }
     134           6 :     }
     135             : }
     136             : 
     137           1 : void XDataPilotDescriptor::testGetDataPilotFields()
     138             : {
     139           1 :     uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
     140           1 :     testGetDataPilotFields_Impl( xDescr );
     141           1 : }
     142             : 
     143           1 : void XDataPilotDescriptor::testGetColumnFields()
     144             : {
     145           1 :     uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
     146           1 :     testGetDataPilotFields_Impl( xDescr );
     147           2 :     uno::Reference< container::XIndexAccess > xIndex(xDescr->getColumnFields(), UNO_QUERY_THROW);
     148             : 
     149           2 :     checkName( xIndex, 0 );
     150           1 : }
     151             : 
     152           1 : void XDataPilotDescriptor::testGetRowFields()
     153             : {
     154           1 :     uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
     155           1 :     testGetDataPilotFields_Impl( xDescr );
     156           1 :     uno::Reference< container::XIndexAccess > xIndex(xDescr->getRowFields(), UNO_QUERY_THROW);
     157             : 
     158             :     //checkName( xIndex, 1 );
     159           1 : }
     160             : 
     161           1 : void XDataPilotDescriptor::testGetPageFields()
     162             : {
     163           1 :     uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
     164           1 :     testGetDataPilotFields_Impl( xDescr );
     165           2 :     uno::Reference< container::XIndexAccess > xIndex(xDescr->getPageFields(), UNO_QUERY_THROW);
     166             : 
     167           2 :     checkName( xIndex, 4 );
     168           1 : }
     169             : 
     170           1 : void XDataPilotDescriptor::testGetDataFields()
     171             : {
     172           1 :     uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
     173           1 :     testGetDataPilotFields_Impl( xDescr );
     174           2 :     uno::Reference< container::XIndexAccess > xIndex(xDescr->getDataFields(), UNO_QUERY_THROW);
     175             : 
     176           2 :     checkName( xIndex, 2 );
     177           1 : }
     178             : 
     179           0 : void XDataPilotDescriptor::testGetHiddenFields()
     180             : {
     181           0 :     std::cout << "testGetHiddenFields" <<std::endl;
     182           0 :     uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);;
     183           0 :     testGetDataPilotFields_Impl( xDescr );
     184           0 :     uno::Reference< container::XIndexAccess > xIndex(xDescr->getHiddenFields(), UNO_QUERY_THROW);
     185             : 
     186           0 :     checkName( xIndex, 3 );
     187           0 : }
     188             : 
     189           3 : void XDataPilotDescriptor::checkName( uno::Reference< container::XIndexAccess > xIndex, sal_Int32 nIndex )
     190             : {
     191           3 :     CPPUNIT_ASSERT(xIndex.is());
     192           3 :     CPPUNIT_ASSERT(maFieldNames.size() >= static_cast<size_t>(nIndex));
     193             : 
     194           6 :     for (sal_Int32 i = 0; i < xIndex->getCount(); ++i)
     195             :     {
     196           3 :         uno::Reference< container::XNamed > xNamed( xIndex->getByIndex(i), UNO_QUERY_THROW);
     197           3 :         std::cout << "Expected: " << maFieldNames[nIndex] << " Got: " << xNamed->getName() << std::endl;
     198           3 :         CPPUNIT_ASSERT( xNamed->getName() == maFieldNames[nIndex] );
     199           3 :     }
     200           3 : }
     201             : 
     202          60 : }
     203             : 
     204             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10