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 4 : class KeyStopLerpTest : public CppUnit::TestFixture
37 : {
38 : tools::KeyStopLerp maKeyStops;
39 :
40 2 : static std::vector<double> getTestVector()
41 : {
42 2 : std::vector<double> aStops(3);
43 2 : aStops[0] = 0.1;
44 2 : aStops[1] = 0.5;
45 2 : aStops[2] = 0.9;
46 2 : return aStops;
47 : }
48 :
49 : public:
50 2 : KeyStopLerpTest() :
51 2 : maKeyStops(getTestVector())
52 2 : {}
53 :
54 2 : void setUp() SAL_OVERRIDE
55 2 : {}
56 :
57 2 : void tearDown() SAL_OVERRIDE
58 2 : {}
59 :
60 2 : void test()
61 : {
62 : double fAlpha;
63 : std::ptrdiff_t nIndex;
64 :
65 2 : tie(nIndex,fAlpha) = maKeyStops.lerp(-1.0);
66 2 : CPPUNIT_ASSERT_MESSAGE("-1.0", nIndex==0 && fAlpha==0.0);
67 :
68 2 : tie(nIndex,fAlpha) = maKeyStops.lerp(0.1);
69 2 : CPPUNIT_ASSERT_MESSAGE("0.1", nIndex==0 && fAlpha==0.0);
70 :
71 2 : tie(nIndex,fAlpha) = maKeyStops.lerp(0.3);
72 2 : CPPUNIT_ASSERT_MESSAGE("0.3", nIndex==0 && fTools::equal(fAlpha,0.5));
73 :
74 2 : tie(nIndex,fAlpha) = maKeyStops.lerp(0.5);
75 2 : CPPUNIT_ASSERT_MESSAGE("0.5", nIndex==0 && fTools::equal(fAlpha,1.0));
76 :
77 2 : tie(nIndex,fAlpha) = maKeyStops.lerp(0.51);
78 2 : CPPUNIT_ASSERT_MESSAGE("0.51", nIndex==1 && fTools::equal(fAlpha,0.025));
79 :
80 2 : tie(nIndex,fAlpha) = maKeyStops.lerp(0.9);
81 2 : CPPUNIT_ASSERT_MESSAGE("0.51", nIndex==1 && fTools::equal(fAlpha,1.0));
82 :
83 2 : tie(nIndex,fAlpha) = maKeyStops.lerp(1.0);
84 2 : CPPUNIT_ASSERT_MESSAGE("0.51", nIndex==1 && fAlpha==1.0);
85 2 : }
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 4 : CPPUNIT_TEST_SUITE(KeyStopLerpTest);
92 2 : CPPUNIT_TEST(test);
93 4 : CPPUNIT_TEST_SUITE_END();
94 : };
95 :
96 2 : CPPUNIT_TEST_SUITE_REGISTRATION(basegfxtools::KeyStopLerpTest);
97 6 : } // namespace basegfxtools
98 :
99 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|