LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/test/source/sheet - xdatapilotdescriptor.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 107 115 93.0 %
Date: 2013-07-09 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          15 : 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             :             default:
     134           0 :                 break;
     135             :         }
     136           6 :     }
     137             : }
     138             : 
     139           1 : void XDataPilotDescriptor::testGetDataPilotFields()
     140             : {
     141           1 :     uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
     142           1 :     testGetDataPilotFields_Impl( xDescr );
     143           1 : }
     144             : 
     145           1 : void XDataPilotDescriptor::testGetColumnFields()
     146             : {
     147           1 :     uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
     148           1 :     testGetDataPilotFields_Impl( xDescr );
     149           2 :     uno::Reference< container::XIndexAccess > xIndex(xDescr->getColumnFields(), UNO_QUERY_THROW);
     150             : 
     151           2 :     checkName( xIndex, 0 );
     152           1 : }
     153             : 
     154           1 : void XDataPilotDescriptor::testGetRowFields()
     155             : {
     156           1 :     uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
     157           1 :     testGetDataPilotFields_Impl( xDescr );
     158           1 :     uno::Reference< container::XIndexAccess > xIndex(xDescr->getRowFields(), UNO_QUERY_THROW);
     159             : 
     160             :     //checkName( xIndex, 1 );
     161           1 : }
     162             : 
     163           1 : void XDataPilotDescriptor::testGetPageFields()
     164             : {
     165           1 :     uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW);
     166           1 :     testGetDataPilotFields_Impl( xDescr );
     167           2 :     uno::Reference< container::XIndexAccess > xIndex(xDescr->getPageFields(), UNO_QUERY_THROW);
     168             : 
     169           2 :     checkName( xIndex, 4 );
     170           1 : }
     171             : 
     172           1 : void XDataPilotDescriptor::testGetDataFields()
     173             : {
     174           1 :     uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);
     175           1 :     testGetDataPilotFields_Impl( xDescr );
     176           2 :     uno::Reference< container::XIndexAccess > xIndex(xDescr->getDataFields(), UNO_QUERY_THROW);
     177             : 
     178           2 :     checkName( xIndex, 2 );
     179           1 : }
     180             : 
     181           0 : void XDataPilotDescriptor::testGetHiddenFields()
     182             : {
     183           0 :     std::cout << "testGetHiddenFields" <<std::endl;
     184           0 :     uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW);;
     185           0 :     testGetDataPilotFields_Impl( xDescr );
     186           0 :     uno::Reference< container::XIndexAccess > xIndex(xDescr->getHiddenFields(), UNO_QUERY_THROW);
     187             : 
     188           0 :     checkName( xIndex, 3 );
     189           0 : }
     190             : 
     191           3 : void XDataPilotDescriptor::checkName( uno::Reference< container::XIndexAccess > xIndex, sal_Int32 nIndex )
     192             : {
     193           3 :     CPPUNIT_ASSERT(xIndex.is());
     194           3 :     CPPUNIT_ASSERT(maFieldNames.size() >= static_cast<size_t>(nIndex));
     195             : 
     196           6 :     for (sal_Int32 i = 0; i < xIndex->getCount(); ++i)
     197             :     {
     198           3 :         uno::Reference< container::XNamed > xNamed( xIndex->getByIndex(i), UNO_QUERY_THROW);
     199           3 :         std::cout << "Expected: " << maFieldNames[nIndex] << " Got: " << xNamed->getName() << std::endl;
     200           3 :         CPPUNIT_ASSERT( xNamed->getName() == maFieldNames[nIndex] );
     201           3 :     }
     202           3 : }
     203             : 
     204          45 : }
     205             : 
     206             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10