LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/basegfx/test - basegfxtools.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 35 35 100.0 %
Date: 2013-07-09 Functions: 12 12 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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/types.h>
      21             : #include "cppunit/TestAssert.h"
      22             : #include "cppunit/TestFixture.h"
      23             : #include "cppunit/extensions/HelperMacros.h"
      24             : 
      25             : #include <basegfx/tools/keystoplerp.hxx>
      26             : #include <basegfx/numeric/ftools.hxx>
      27             : 
      28             : #include <boost/tuple/tuple.hpp>
      29             : 
      30             : using namespace ::basegfx;
      31             : using namespace ::boost::tuples;
      32             : 
      33             : namespace basegfxtools
      34             : {
      35             : 
      36           2 : class KeyStopLerpTest : public CppUnit::TestFixture
      37             : {
      38             :     tools::KeyStopLerp maKeyStops;
      39             : 
      40           1 :     static std::vector<double> getTestVector()
      41             :     {
      42           1 :         std::vector<double> aStops(3);
      43           1 :         aStops[0] = 0.1;
      44           1 :         aStops[1] = 0.5;
      45           1 :         aStops[2] = 0.9;
      46           1 :         return aStops;
      47             :     }
      48             : 
      49             : public:
      50           1 :     KeyStopLerpTest() :
      51           1 :         maKeyStops(getTestVector())
      52           1 :     {}
      53             : 
      54           1 :     void setUp()
      55           1 :     {}
      56             : 
      57           1 :     void tearDown()
      58           1 :     {}
      59             : 
      60           1 :     void test()
      61             :     {
      62             :         double fAlpha;
      63             :         std::ptrdiff_t nIndex;
      64             : 
      65           1 :         tie(nIndex,fAlpha) = maKeyStops.lerp(-1.0);
      66           1 :         CPPUNIT_ASSERT_MESSAGE("-1.0", nIndex==0 && fAlpha==0.0);
      67             : 
      68           1 :         tie(nIndex,fAlpha) = maKeyStops.lerp(0.1);
      69           1 :         CPPUNIT_ASSERT_MESSAGE("0.1", nIndex==0 && fAlpha==0.0);
      70             : 
      71           1 :         tie(nIndex,fAlpha) = maKeyStops.lerp(0.3);
      72           1 :         CPPUNIT_ASSERT_MESSAGE("0.3", nIndex==0 && fTools::equal(fAlpha,0.5));
      73             : 
      74           1 :         tie(nIndex,fAlpha) = maKeyStops.lerp(0.5);
      75           1 :         CPPUNIT_ASSERT_MESSAGE("0.5", nIndex==0 && fTools::equal(fAlpha,1.0));
      76             : 
      77           1 :         tie(nIndex,fAlpha) = maKeyStops.lerp(0.51);
      78           1 :         CPPUNIT_ASSERT_MESSAGE("0.51", nIndex==1 && fTools::equal(fAlpha,0.025));
      79             : 
      80           1 :         tie(nIndex,fAlpha) = maKeyStops.lerp(0.9);
      81           1 :         CPPUNIT_ASSERT_MESSAGE("0.51", nIndex==1 && fTools::equal(fAlpha,1.0));
      82             : 
      83           1 :         tie(nIndex,fAlpha) = maKeyStops.lerp(1.0);
      84           1 :         CPPUNIT_ASSERT_MESSAGE("0.51", nIndex==1 && fAlpha==1.0);
      85           1 :     }
      86             : 
      87             :     // Change the following lines only, if you add, remove or rename
      88             :     // member functions of the current class,
      89             :     // because these macros are need by auto register mechanism.
      90             : 
      91           2 :     CPPUNIT_TEST_SUITE(KeyStopLerpTest);
      92           1 :     CPPUNIT_TEST(test);
      93           2 :     CPPUNIT_TEST_SUITE_END();
      94             : };
      95             : 
      96             : // -----------------------------------------------------------------------------
      97           1 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfxtools::KeyStopLerpTest);
      98           3 : } // namespace basegfxtools
      99             : 
     100             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10