LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/qa/unit/helper - shared_test_impl.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 65 65 100.0 %
Date: 2013-07-09 Functions: 5 5 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             : #ifndef SC_SHARED_TEST_IMPL_HXX
      11             : #define SC_SHARED_TEST_IMPL_HXX
      12             : 
      13             : #include "colorscale.hxx"
      14             : #include "conditio.hxx"
      15             : 
      16             : struct FindCondFormatByEnclosingRange
      17             : {
      18          34 :     FindCondFormatByEnclosingRange(const ScRange& rRange):
      19          34 :         mrRange(rRange) {}
      20             : 
      21          78 :     bool operator()(const ScConditionalFormat& rFormat)
      22             :     {
      23          78 :         if(rFormat.GetRange().Combine() == mrRange)
      24          34 :             return true;
      25             : 
      26          44 :         return false;
      27             :     }
      28             : 
      29             : private:
      30             :     const ScRange& mrRange;
      31             : };
      32             : 
      33             : struct DataBarData
      34             : {
      35             :     ScRange aRange;
      36             :     ScColorScaleEntryType eLowerLimitType;
      37             :     ScColorScaleEntryType eUpperLimitType;
      38             :     databar::ScAxisPosition eAxisPosition;
      39             : };
      40             : 
      41           2 : DataBarData aData[] = {
      42             :     { ScRange(1,2,0,1,5,0), COLORSCALE_AUTO, COLORSCALE_AUTO, databar::AUTOMATIC },
      43             :     { ScRange(3,2,0,3,5,0), COLORSCALE_MIN, COLORSCALE_MAX, databar::AUTOMATIC },
      44             :     { ScRange(5,2,0,5,5,0), COLORSCALE_PERCENTILE, COLORSCALE_PERCENT, databar::AUTOMATIC },
      45             :     { ScRange(7,2,0,7,5,0), COLORSCALE_VALUE, COLORSCALE_FORMULA, databar::AUTOMATIC },
      46             :     { ScRange(1,9,0,1,12,0), COLORSCALE_AUTO, COLORSCALE_AUTO, databar::MIDDLE }
      47           2 : };
      48             : 
      49           2 : void testDataBar_Impl(ScDocument* pDoc)
      50             : {
      51           2 :     ScConditionalFormatList* pList = pDoc->GetCondFormList(0);
      52           2 :     CPPUNIT_ASSERT(pList);
      53             : 
      54          12 :     for(size_t i = 0; i < SAL_N_ELEMENTS(aData); ++i)
      55             :     {
      56             :         ScConditionalFormatList::const_iterator itr = std::find_if(pList->begin(),
      57          10 :                 pList->end(), FindCondFormatByEnclosingRange(aData[i].aRange));
      58          10 :         CPPUNIT_ASSERT(itr != pList->end());
      59          10 :         CPPUNIT_ASSERT_EQUAL(size_t(1), itr->size());
      60             : 
      61          10 :         const ScFormatEntry* pFormatEntry = itr->GetEntry(0);
      62          10 :         CPPUNIT_ASSERT_EQUAL(pFormatEntry->GetType(), condformat::DATABAR);
      63          10 :         const ScDataBarFormat* pDataBar = static_cast<const ScDataBarFormat*>(pFormatEntry);
      64          10 :         CPPUNIT_ASSERT(pDataBar);
      65          10 :         const ScDataBarFormatData* pDataBarData = pDataBar->GetDataBarData();
      66          10 :         CPPUNIT_ASSERT_EQUAL(aData[i].eLowerLimitType, pDataBarData->mpLowerLimit->GetType());
      67          10 :         CPPUNIT_ASSERT_EQUAL(aData[i].eUpperLimitType, pDataBarData->mpUpperLimit->GetType());
      68             : 
      69          10 :         CPPUNIT_ASSERT_EQUAL(aData[i].eAxisPosition, pDataBarData->meAxisPosition);
      70             :     }
      71           2 : }
      72             : 
      73             : struct ColorScale2EntryData
      74             : {
      75             :     ScRange aRange;
      76             :     ScColorScaleEntryType eLowerType;
      77             :     ScColorScaleEntryType eUpperType;
      78             : };
      79             : 
      80           2 : ColorScale2EntryData aData2Entry[] = {
      81             :     { ScRange(1,2,0,1,5,0), COLORSCALE_MIN, COLORSCALE_MAX },
      82             :     { ScRange(3,2,0,3,5,0), COLORSCALE_PERCENTILE, COLORSCALE_PERCENT },
      83             :     { ScRange(5,2,0,5,5,0), COLORSCALE_VALUE, COLORSCALE_FORMULA }
      84           2 : };
      85             : 
      86           4 : void testColorScale2Entry_Impl(ScDocument* pDoc)
      87             : {
      88           4 :     const ScConditionalFormatList* pList = pDoc->GetCondFormList(0);
      89           4 :     CPPUNIT_ASSERT(pList);
      90             : 
      91          16 :     for(size_t i = 0; i < SAL_N_ELEMENTS(aData2Entry); ++i)
      92             :     {
      93             :         ScConditionalFormatList::const_iterator itr = std::find_if(pList->begin(),
      94          12 :                             pList->end(), FindCondFormatByEnclosingRange(aData2Entry[i].aRange));
      95          12 :         CPPUNIT_ASSERT(itr != pList->end());
      96          12 :         CPPUNIT_ASSERT_EQUAL(size_t(1), itr->size());
      97             : 
      98          12 :         const ScFormatEntry* pFormatEntry = itr->GetEntry(0);
      99          12 :         CPPUNIT_ASSERT_EQUAL(pFormatEntry->GetType(), condformat::COLORSCALE);
     100          12 :         const ScColorScaleFormat* pColFormat = static_cast<const ScColorScaleFormat*>(pFormatEntry);
     101          12 :         CPPUNIT_ASSERT_EQUAL(size_t(2), pColFormat->size());
     102             : 
     103          12 :         ScColorScaleFormat::const_iterator format_itr = pColFormat->begin();
     104          12 :         CPPUNIT_ASSERT_EQUAL(aData2Entry[i].eLowerType, format_itr->GetType());
     105          12 :         ++format_itr;
     106          12 :         CPPUNIT_ASSERT(format_itr != pColFormat->end());
     107          12 :         CPPUNIT_ASSERT_EQUAL(aData2Entry[i].eUpperType, format_itr->GetType());
     108             :     }
     109           4 : }
     110             : 
     111             : struct ColorScale3EntryData
     112             : {
     113             :     ScRange aRange;
     114             :     ScColorScaleEntryType eLowerType;
     115             :     ScColorScaleEntryType eMiddleType;
     116             :     ScColorScaleEntryType eUpperType;
     117             : };
     118             : 
     119           2 : ColorScale3EntryData aData3Entry[] = {
     120             :     { ScRange(1,1,1,1,6,1), COLORSCALE_MIN, COLORSCALE_PERCENTILE, COLORSCALE_MAX },
     121             :     { ScRange(3,1,1,3,6,1), COLORSCALE_PERCENTILE, COLORSCALE_VALUE, COLORSCALE_PERCENT },
     122             :     { ScRange(5,1,1,5,6,1), COLORSCALE_VALUE, COLORSCALE_VALUE, COLORSCALE_FORMULA }
     123           2 : };
     124             : 
     125           4 : void testColorScale3Entry_Impl(ScDocument* pDoc)
     126             : {
     127           4 :     ScConditionalFormatList* pList = pDoc->GetCondFormList(1);
     128           4 :     CPPUNIT_ASSERT(pList);
     129             : 
     130          16 :     for(size_t i = 0; i < SAL_N_ELEMENTS(aData3Entry); ++i)
     131             :     {
     132             :         ScConditionalFormatList::const_iterator itr = std::find_if(pList->begin(),
     133          12 :                             pList->end(), FindCondFormatByEnclosingRange(aData3Entry[i].aRange));
     134          12 :         CPPUNIT_ASSERT(itr != pList->end());
     135          12 :         CPPUNIT_ASSERT_EQUAL(size_t(1), itr->size());
     136             : 
     137          12 :         const ScFormatEntry* pFormatEntry = itr->GetEntry(0);
     138          12 :         CPPUNIT_ASSERT_EQUAL(pFormatEntry->GetType(), condformat::COLORSCALE);
     139          12 :         const ScColorScaleFormat* pColFormat = static_cast<const ScColorScaleFormat*>(pFormatEntry);
     140          12 :         CPPUNIT_ASSERT_EQUAL(size_t(3), pColFormat->size());
     141             : 
     142          12 :         ScColorScaleFormat::const_iterator format_itr = pColFormat->begin();
     143          12 :         CPPUNIT_ASSERT_EQUAL(aData3Entry[i].eLowerType, format_itr->GetType());
     144          12 :         ++format_itr;
     145          12 :         CPPUNIT_ASSERT(format_itr != pColFormat->end());
     146          12 :         CPPUNIT_ASSERT_EQUAL(aData3Entry[i].eMiddleType, format_itr->GetType());
     147          12 :         ++format_itr;
     148          12 :         CPPUNIT_ASSERT(format_itr != pColFormat->end());
     149          12 :         CPPUNIT_ASSERT_EQUAL(aData3Entry[i].eUpperType, format_itr->GetType());
     150             :     }
     151           4 : }
     152             : 
     153             : #endif
     154             : 
     155             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10