| OLD | NEW |
| (Empty) | |
| 1 /* |
| 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 30 |
| 31 #include "config.h" |
| 32 #include "core/animation/AnimatableDouble.h" |
| 33 |
| 34 #include "core/css/CSSPrimitiveValue.h" |
| 35 |
| 36 #include <gtest/gtest.h> |
| 37 |
| 38 using namespace WebCore; |
| 39 |
| 40 namespace { |
| 41 |
| 42 TEST(AnimatableDoubleTest, Create) |
| 43 { |
| 44 EXPECT_TRUE(static_cast<bool>(AnimatableDouble::create(5).get())); |
| 45 EXPECT_TRUE(static_cast<bool>(AnimatableDouble::create(10).get())); |
| 46 } |
| 47 |
| 48 TEST(AnimatableDoubleTest, ToCSSValue) |
| 49 { |
| 50 RefPtr<CSSValue> cssValue5 = CSSPrimitiveValue::create(5, CSSPrimitiveValue:
:CSS_NUMBER); |
| 51 RefPtr<CSSValue> cssValue10 = CSSPrimitiveValue::create(10, CSSPrimitiveValu
e::CSS_NUMBER); |
| 52 EXPECT_TRUE(AnimatableDouble::create(5)->toCSSValue()->equals(*cssValue5.get
())); |
| 53 EXPECT_FALSE(AnimatableDouble::create(5)->toCSSValue()->equals(*cssValue10.g
et())); |
| 54 } |
| 55 |
| 56 TEST(AnimatableDoubleTest, ToDouble) |
| 57 { |
| 58 EXPECT_EQ(5, AnimatableDouble::create(5)->toDouble()); |
| 59 EXPECT_EQ(10, AnimatableDouble::create(10)->toDouble()); |
| 60 } |
| 61 |
| 62 |
| 63 TEST(AnimatableDoubleTest, Interpolate) |
| 64 { |
| 65 RefPtr<AnimatableDouble> from10 = AnimatableDouble::create(10); |
| 66 RefPtr<AnimatableDouble> to20 = AnimatableDouble::create(20); |
| 67 EXPECT_EQ(5, toAnimatableDouble(AnimatableValue::interpolate(from10.get(), t
o20.get(), -0.5).get())->toDouble()); |
| 68 EXPECT_EQ(10, toAnimatableDouble(AnimatableValue::interpolate(from10.get(),
to20.get(), 0).get())->toDouble()); |
| 69 EXPECT_EQ(14, toAnimatableDouble(AnimatableValue::interpolate(from10.get(),
to20.get(), 0.4).get())->toDouble()); |
| 70 EXPECT_EQ(15, toAnimatableDouble(AnimatableValue::interpolate(from10.get(),
to20.get(), 0.5).get())->toDouble()); |
| 71 EXPECT_EQ(16, toAnimatableDouble(AnimatableValue::interpolate(from10.get(),
to20.get(), 0.6).get())->toDouble()); |
| 72 EXPECT_EQ(20, toAnimatableDouble(AnimatableValue::interpolate(from10.get(),
to20.get(), 1).get())->toDouble()); |
| 73 EXPECT_EQ(25, toAnimatableDouble(AnimatableValue::interpolate(from10.get(),
to20.get(), 1.5).get())->toDouble()); |
| 74 } |
| 75 |
| 76 TEST(AnimatableDoubleTest, Add) |
| 77 { |
| 78 EXPECT_EQ(-10, toAnimatableDouble(AnimatableValue::add(AnimatableDouble::cre
ate(-2).get(), AnimatableDouble::create(-8).get()).get())->toDouble()); |
| 79 EXPECT_EQ(0, toAnimatableDouble(AnimatableValue::add(AnimatableDouble::creat
e(50).get(), AnimatableDouble::create(-50).get()).get())->toDouble()); |
| 80 EXPECT_EQ(10, toAnimatableDouble(AnimatableValue::add(AnimatableDouble::crea
te(4).get(), AnimatableDouble::create(6).get()).get())->toDouble()); |
| 81 } |
| 82 |
| 83 } |
| OLD | NEW |