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