xref: /aoo4110/main/basegfx/test/basegfxtools.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 
25 // MARKER(update_precomp.py): autogen include statement, do not remove
26 #include "precompiled_basegfx.hxx"
27 // autogenerated file with codegen.pl
28 
29 #include "preextstl.h"
30 #include "cppunit/TestAssert.h"
31 #include "cppunit/TestFixture.h"
32 #include "cppunit/extensions/HelperMacros.h"
33 #include "postextstl.h"
34 
35 #include <basegfx/tools/keystoplerp.hxx>
36 #include <basegfx/numeric/ftools.hxx>
37 
38 #include <boost/tuple/tuple.hpp>
39 
40 using namespace ::basegfx;
41 using namespace ::boost::tuples;
42 
43 namespace basegfxtools
44 {
45 
46 class KeyStopLerpTest : public CppUnit::TestFixture
47 {
48     tools::KeyStopLerp maKeyStops;
49 
getTestVector()50     static std::vector<double> getTestVector()
51     {
52         std::vector<double> aStops(3);
53         aStops[0] = 0.1;
54         aStops[1] = 0.5;
55         aStops[2] = 0.9;
56         return aStops;
57     }
58 
59 public:
KeyStopLerpTest()60     KeyStopLerpTest() :
61         maKeyStops(getTestVector())
62     {}
63 
setUp()64     void setUp()
65     {}
66 
tearDown()67     void tearDown()
68     {}
69 
test()70     void test()
71     {
72         double fAlpha;
73         std::ptrdiff_t nIndex;
74 
75         tie(nIndex,fAlpha) = maKeyStops.lerp(-1.0);
76         CPPUNIT_ASSERT_MESSAGE("-1.0", nIndex==0 && fAlpha==0.0);
77 
78         tie(nIndex,fAlpha) = maKeyStops.lerp(0.1);
79         CPPUNIT_ASSERT_MESSAGE("0.1", nIndex==0 && fAlpha==0.0);
80 
81         tie(nIndex,fAlpha) = maKeyStops.lerp(0.3);
82         CPPUNIT_ASSERT_MESSAGE("0.3", nIndex==0 && fTools::equal(fAlpha,0.5));
83 
84         tie(nIndex,fAlpha) = maKeyStops.lerp(0.5);
85         CPPUNIT_ASSERT_MESSAGE("0.5", nIndex==0 && fTools::equal(fAlpha,1.0));
86 
87         tie(nIndex,fAlpha) = maKeyStops.lerp(0.51);
88         CPPUNIT_ASSERT_MESSAGE("0.51", nIndex==1 && fTools::equal(fAlpha,0.025));
89 
90         tie(nIndex,fAlpha) = maKeyStops.lerp(0.9);
91         CPPUNIT_ASSERT_MESSAGE("0.51", nIndex==1 && fTools::equal(fAlpha,1.0));
92 
93         tie(nIndex,fAlpha) = maKeyStops.lerp(1.0);
94         CPPUNIT_ASSERT_MESSAGE("0.51", nIndex==1 && fAlpha==1.0);
95     }
96 
97     // Change the following lines only, if you add, remove or rename
98     // member functions of the current class,
99     // because these macros are need by auto register mechanism.
100 
101     CPPUNIT_TEST_SUITE(KeyStopLerpTest);
102     CPPUNIT_TEST(test);
103     CPPUNIT_TEST_SUITE_END();
104 };
105 
106 // -----------------------------------------------------------------------------
107 CPPUNIT_TEST_SUITE_REGISTRATION(basegfxtools::KeyStopLerpTest);
108 } // namespace basegfxtools
109