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

Generated by: LCOV version 1.10