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

Generated by: LCOV version 1.10