xref: /trunk/main/basegfx/test/basegfxtools.cxx (revision 131e08e2)
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 "gtest/gtest.h"
31 #include "postextstl.h"
32 
33 #include <basegfx/tools/keystoplerp.hxx>
34 #include <basegfx/numeric/ftools.hxx>
35 
36 #include <boost/tuple/tuple.hpp>
37 
38 using namespace ::basegfx;
39 using namespace ::boost::tuples;
40 
41 namespace basegfxtools
42 {
43 
44 class KeyStopLerpTest : public ::testing::Test
45 {
46 protected:
47     tools::KeyStopLerp maKeyStops;
48 
getTestVector()49     static std::vector<double> getTestVector()
50     {
51         std::vector<double> aStops(3);
52         aStops[0] = 0.1;
53         aStops[1] = 0.5;
54         aStops[2] = 0.9;
55         return aStops;
56     }
57 
58 public:
KeyStopLerpTest()59     KeyStopLerpTest() :
60         maKeyStops(getTestVector())
61     {}
62 
SetUp()63     virtual void SetUp()
64     {}
65 
TearDown()66     virtual void TearDown()
67     {}
68 };
69 
TEST_F(KeyStopLerpTest,test)70 TEST_F(KeyStopLerpTest, test)
71 {
72     double fAlpha;
73     std::ptrdiff_t nIndex;
74 
75     tie(nIndex,fAlpha) = maKeyStops.lerp(-1.0);
76     ASSERT_TRUE(nIndex==0 && fAlpha==0.0) << "-1.0";
77 
78     tie(nIndex,fAlpha) = maKeyStops.lerp(0.1);
79     ASSERT_TRUE(nIndex==0 && fAlpha==0.0) << "0.1";
80 
81     tie(nIndex,fAlpha) = maKeyStops.lerp(0.3);
82     ASSERT_TRUE(nIndex==0 && fTools::equal(fAlpha,0.5)) << "0.3";
83 
84     tie(nIndex,fAlpha) = maKeyStops.lerp(0.5);
85     ASSERT_TRUE(nIndex==0 && fTools::equal(fAlpha,1.0)) << "0.5";
86 
87     tie(nIndex,fAlpha) = maKeyStops.lerp(0.51);
88     ASSERT_TRUE(nIndex==1 && fTools::equal(fAlpha,0.025)) << "0.51";
89 
90     tie(nIndex,fAlpha) = maKeyStops.lerp(0.9);
91     ASSERT_TRUE(nIndex==1 && fTools::equal(fAlpha,1.0)) << "0.51";
92 
93     tie(nIndex,fAlpha) = maKeyStops.lerp(1.0);
94     ASSERT_TRUE(nIndex==1 && fAlpha==1.0) << "0.51";
95 }
96 
97 // -----------------------------------------------------------------------------
98 
99 } // namespace basegfxtools
100