Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <sal/types.h>
30 : : #include "cppunit/TestAssert.h"
31 : : #include "cppunit/TestFixture.h"
32 : : #include "cppunit/extensions/HelperMacros.h"
33 : :
34 : : #include <basegfx/tools/keystoplerp.hxx>
35 : : #include <basegfx/numeric/ftools.hxx>
36 : :
37 : : #include <boost/tuple/tuple.hpp>
38 : :
39 : : using namespace ::basegfx;
40 : : using namespace ::boost::tuples;
41 : :
42 : : namespace basegfxtools
43 : : {
44 : :
45 [ - + ]: 10 : class KeyStopLerpTest : public CppUnit::TestFixture
46 : : {
47 : : tools::KeyStopLerp maKeyStops;
48 : :
49 : 5 : static std::vector<double> getTestVector()
50 : : {
51 : 5 : std::vector<double> aStops(3);
52 [ + - ]: 5 : aStops[0] = 0.1;
53 [ + - ]: 5 : aStops[1] = 0.5;
54 [ + - ]: 5 : aStops[2] = 0.9;
55 : 5 : return aStops;
56 : : }
57 : :
58 : : public:
59 : 5 : KeyStopLerpTest() :
60 [ + - ][ + - ]: 5 : maKeyStops(getTestVector())
61 : 5 : {}
62 : :
63 : 5 : void setUp()
64 : 5 : {}
65 : :
66 : 5 : void tearDown()
67 : 5 : {}
68 : :
69 : 5 : void test()
70 : : {
71 : : double fAlpha;
72 : : std::ptrdiff_t nIndex;
73 : :
74 [ + - ][ + - ]: 5 : tie(nIndex,fAlpha) = maKeyStops.lerp(-1.0);
75 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("-1.0", nIndex==0 && fAlpha==0.0);
[ + - ][ + - ]
[ + - ][ + - ]
[ - + ][ + - ]
[ + - ][ + - ]
[ + - ]
76 : :
77 [ + - ][ + - ]: 5 : tie(nIndex,fAlpha) = maKeyStops.lerp(0.1);
78 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("0.1", nIndex==0 && fAlpha==0.0);
[ + - ][ + - ]
[ + - ][ + - ]
[ - + ][ + - ]
[ + - ][ + - ]
[ + - ]
79 : :
80 [ + - ][ + - ]: 5 : tie(nIndex,fAlpha) = maKeyStops.lerp(0.3);
81 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("0.3", nIndex==0 && fTools::equal(fAlpha,0.5));
[ + - ][ + - ]
[ + - ][ + - ]
[ - + ][ + - ]
[ + - ][ + - ]
[ + - ][ # # ]
[ + - ]
82 : :
83 [ + - ][ + - ]: 5 : tie(nIndex,fAlpha) = maKeyStops.lerp(0.5);
84 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("0.5", nIndex==0 && fTools::equal(fAlpha,1.0));
[ + - ][ + - ]
[ + - ][ + - ]
[ - + ][ + - ]
[ + - ][ + - ]
[ + - ][ # # ]
[ + - ]
85 : :
86 [ + - ][ + - ]: 5 : tie(nIndex,fAlpha) = maKeyStops.lerp(0.51);
87 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("0.51", nIndex==1 && fTools::equal(fAlpha,0.025));
[ + - ][ + - ]
[ + - ][ + - ]
[ - + ][ + - ]
[ + - ][ + - ]
[ + - ][ # # ]
[ + - ]
88 : :
89 [ + - ][ + - ]: 5 : tie(nIndex,fAlpha) = maKeyStops.lerp(0.9);
90 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("0.51", nIndex==1 && fTools::equal(fAlpha,1.0));
[ + - ][ + - ]
[ + - ][ + - ]
[ - + ][ + - ]
[ + - ][ + - ]
[ + - ][ # # ]
[ + - ]
91 : :
92 [ + - ][ + - ]: 5 : tie(nIndex,fAlpha) = maKeyStops.lerp(1.0);
93 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("0.51", nIndex==1 && fAlpha==1.0);
[ + - ][ + - ]
[ + - ][ + - ]
[ - + ][ + - ]
[ + - ][ + - ]
[ + - ]
94 : 5 : }
95 : :
96 : : // Change the following lines only, if you add, remove or rename
97 : : // member functions of the current class,
98 : : // because these macros are need by auto register mechanism.
99 : :
100 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE(KeyStopLerpTest);
[ + - ][ + - ]
[ # # ]
101 [ + - ][ + - ]: 5 : CPPUNIT_TEST(test);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
102 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE_END();
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
103 : : };
104 : :
105 : : // -----------------------------------------------------------------------------
106 : 5 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfxtools::KeyStopLerpTest);
107 [ + - ][ + - ]: 15 : } // namespace basegfxtools
108 : :
109 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|