11e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)/*
21e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * Copyright (c) 2013, Google Inc. All rights reserved.
31e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) *
41e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without
51e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * modification, are permitted provided that the following conditions are
61e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * met:
71e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) *
81e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) *     * Redistributions of source code must retain the above copyright
91e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * notice, this list of conditions and the following disclaimer.
101e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) *     * Redistributions in binary form must reproduce the above
111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer
121e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * in the documentation and/or other materials provided with the
131e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * distribution.
141e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) *     * Neither the name of Google Inc. nor the names of its
151e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * contributors may be used to endorse or promote products derived from
161e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * this software without specific prior written permission.
171e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) *
181e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
201e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
231e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
241e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
271e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) */
301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "config.h"
32197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/animation/animatable/AnimatableDouble.h"
331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include <gtest/gtest.h>
351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
36c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)using namespace blink;
371e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)namespace {
391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST(AnimationAnimatableDoubleTest, Create)
411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
421e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_TRUE(static_cast<bool>(AnimatableDouble::create(5).get()));
431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_TRUE(static_cast<bool>(AnimatableDouble::create(10).get()));
441e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
451e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST(AnimationAnimatableDoubleTest, Equal)
471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
481e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_TRUE(AnimatableDouble::create(10)->equals(AnimatableDouble::create(10).get()));
491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_FALSE(AnimatableDouble::create(5)->equals(AnimatableDouble::create(10).get()));
501e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST(AnimationAnimatableDoubleTest, ToDouble)
531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(5.9, AnimatableDouble::create(5.9)->toDouble());
551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(-10, AnimatableDouble::create(-10)->toDouble());
561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST(AnimationAnimatableDoubleTest, Interpolate)
601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
6107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    RefPtrWillBeRawPtr<AnimatableDouble> from10 = AnimatableDouble::create(10);
6207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    RefPtrWillBeRawPtr<AnimatableDouble> to20 = AnimatableDouble::create(20);
631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(5, toAnimatableDouble(AnimatableValue::interpolate(from10.get(), to20.get(), -0.5).get())->toDouble());
641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(10, toAnimatableDouble(AnimatableValue::interpolate(from10.get(), to20.get(), 0).get())->toDouble());
651e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(14, toAnimatableDouble(AnimatableValue::interpolate(from10.get(), to20.get(), 0.4).get())->toDouble());
661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(15, toAnimatableDouble(AnimatableValue::interpolate(from10.get(), to20.get(), 0.5).get())->toDouble());
671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(16, toAnimatableDouble(AnimatableValue::interpolate(from10.get(), to20.get(), 0.6).get())->toDouble());
681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(20, toAnimatableDouble(AnimatableValue::interpolate(from10.get(), to20.get(), 1).get())->toDouble());
691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(25, toAnimatableDouble(AnimatableValue::interpolate(from10.get(), to20.get(), 1.5).get())->toDouble());
701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
711e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
72d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)TEST(AnimationAnimatableDoubleTest, Distance)
73d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
7407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    RefPtrWillBeRawPtr<AnimatableDouble> first = AnimatableDouble::create(-1.5);
7507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    RefPtrWillBeRawPtr<AnimatableDouble> second = AnimatableDouble::create(2.25);
7607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    RefPtrWillBeRawPtr<AnimatableDouble> third = AnimatableDouble::create(3);
77d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
78d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    EXPECT_DOUBLE_EQ(3.75, AnimatableValue::distance(first.get(), second.get()));
79d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    EXPECT_DOUBLE_EQ(0.75, AnimatableValue::distance(second.get(), third.get()));
80d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    EXPECT_DOUBLE_EQ(4.5, AnimatableValue::distance(third.get(), first.get()));
81d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
82d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
831e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
84