| 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 "sky/engine/core/animation/TimingCalculations.h" | |
| 32 | |
| 33 #include <gtest/gtest.h> | |
| 34 | |
| 35 using namespace blink; | |
| 36 | |
| 37 namespace { | |
| 38 | |
| 39 TEST(AnimationTimingCalculationsTest, ActiveTime) | |
| 40 { | |
| 41 Timing timing; | |
| 42 | |
| 43 // calculateActiveTime(activeDuration, fillMode, localTime, parentPhase, pha
se, timing) | |
| 44 | |
| 45 // Before Phase | |
| 46 timing.startDelay = 10; | |
| 47 EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeForwards, 0, Anim
ationNode::PhaseActive, AnimationNode::PhaseBefore, timing))); | |
| 48 EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeNone, 0, Animatio
nNode::PhaseActive, AnimationNode::PhaseBefore, timing))); | |
| 49 EXPECT_EQ(0, calculateActiveTime(20, Timing::FillModeBackwards, 0, Animation
Node::PhaseActive, AnimationNode::PhaseBefore, timing)); | |
| 50 EXPECT_EQ(0, calculateActiveTime(20, Timing::FillModeBoth, 0, AnimationNode:
:PhaseActive, AnimationNode::PhaseBefore, timing)); | |
| 51 | |
| 52 // Active Phase | |
| 53 timing.startDelay = 10; | |
| 54 // Active, and parent Before | |
| 55 EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeNone, 15, Animati
onNode::PhaseBefore, AnimationNode::PhaseActive, timing))); | |
| 56 EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeForwards, 15, Ani
mationNode::PhaseBefore, AnimationNode::PhaseActive, timing))); | |
| 57 // Active, and parent After | |
| 58 EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeNone, 15, Animati
onNode::PhaseAfter, AnimationNode::PhaseActive, timing))); | |
| 59 EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeBackwards, 15, An
imationNode::PhaseAfter, AnimationNode::PhaseActive, timing))); | |
| 60 // Active, and parent Active | |
| 61 EXPECT_EQ(5, calculateActiveTime(20, Timing::FillModeForwards, 15, Animation
Node::PhaseActive, AnimationNode::PhaseActive, timing)); | |
| 62 | |
| 63 // After Phase | |
| 64 timing.startDelay = 10; | |
| 65 EXPECT_EQ(21, calculateActiveTime(21, Timing::FillModeForwards, 45, Animatio
nNode::PhaseActive, AnimationNode::PhaseAfter, timing)); | |
| 66 EXPECT_EQ(21, calculateActiveTime(21, Timing::FillModeBoth, 45, AnimationNod
e::PhaseActive, AnimationNode::PhaseAfter, timing)); | |
| 67 EXPECT_TRUE(isNull(calculateActiveTime(21, Timing::FillModeBackwards, 45, An
imationNode::PhaseActive, AnimationNode::PhaseAfter, timing))); | |
| 68 EXPECT_TRUE(isNull(calculateActiveTime(21, Timing::FillModeNone, 45, Animati
onNode::PhaseActive, AnimationNode::PhaseAfter, timing))); | |
| 69 | |
| 70 // None | |
| 71 EXPECT_TRUE(isNull(calculateActiveTime(32, Timing::FillModeNone, nullValue()
, AnimationNode::PhaseNone, AnimationNode::PhaseNone, timing))); | |
| 72 } | |
| 73 | |
| 74 TEST(AnimationTimingCalculationsTest, ScaledActiveTime) | |
| 75 { | |
| 76 Timing timing; | |
| 77 | |
| 78 // calculateScaledActiveTime(activeDuration, activeTime, startOffset, timing
) | |
| 79 | |
| 80 // if the active time is null | |
| 81 EXPECT_TRUE(isNull(calculateScaledActiveTime(4, nullValue(), 5, timing))); | |
| 82 | |
| 83 // if the playback rate is negative | |
| 84 timing.playbackRate = -1; | |
| 85 EXPECT_EQ(35, calculateScaledActiveTime(40, 10, 5, timing)); | |
| 86 | |
| 87 // otherwise | |
| 88 timing.playbackRate = 0; | |
| 89 EXPECT_EQ(5, calculateScaledActiveTime(40, 10, 5, timing)); | |
| 90 timing.playbackRate = 1; | |
| 91 EXPECT_EQ(15, calculateScaledActiveTime(40, 10, 5, timing)); | |
| 92 | |
| 93 // infinte activeTime | |
| 94 timing.playbackRate = 0; | |
| 95 EXPECT_EQ(0, calculateScaledActiveTime(std::numeric_limits<double>::infinity
(), std::numeric_limits<double>::infinity(), 0, timing)); | |
| 96 timing.playbackRate = 1; | |
| 97 EXPECT_EQ(std::numeric_limits<double>::infinity(), calculateScaledActiveTime
(std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity(
), 0, timing)); | |
| 98 } | |
| 99 | |
| 100 TEST(AnimationTimingCalculationsTest, IterationTime) | |
| 101 { | |
| 102 Timing timing; | |
| 103 | |
| 104 // calculateIterationTime(iterationDuration, repeatedDuration, scaledActiveT
ime, startOffset, timing) | |
| 105 | |
| 106 // if the scaled active time is null | |
| 107 EXPECT_TRUE(isNull(calculateIterationTime(1, 1, nullValue(), 1, timing))); | |
| 108 | |
| 109 // if (complex-conditions)... | |
| 110 EXPECT_EQ(12, calculateIterationTime(12, 12, 12, 0, timing)); | |
| 111 | |
| 112 // otherwise | |
| 113 timing.iterationCount = 10; | |
| 114 EXPECT_EQ(5, calculateIterationTime(10, 100, 25, 4, timing)); | |
| 115 EXPECT_EQ(7, calculateIterationTime(11, 110, 29, 1, timing)); | |
| 116 timing.iterationStart = 1.1; | |
| 117 EXPECT_EQ(8, calculateIterationTime(12, 120, 20, 7, timing)); | |
| 118 } | |
| 119 | |
| 120 TEST(AnimationTimingCalculationsTest, CurrentIteration) | |
| 121 { | |
| 122 Timing timing; | |
| 123 | |
| 124 // calculateCurrentIteration(iterationDuration, iterationTime, scaledActiveT
ime, timing) | |
| 125 | |
| 126 // if the scaled active time is null | |
| 127 EXPECT_TRUE(isNull(calculateCurrentIteration(1, 1, nullValue(), timing))); | |
| 128 | |
| 129 // if the scaled active time is zero | |
| 130 EXPECT_EQ(0, calculateCurrentIteration(1, 1, 0, timing)); | |
| 131 | |
| 132 // if the iteration time equals the iteration duration | |
| 133 timing.iterationStart = 4; | |
| 134 timing.iterationCount = 7; | |
| 135 EXPECT_EQ(10, calculateCurrentIteration(5, 5, 9, timing)); | |
| 136 | |
| 137 // otherwise | |
| 138 EXPECT_EQ(3, calculateCurrentIteration(3.2, 3.1, 10, timing)); | |
| 139 } | |
| 140 | |
| 141 TEST(AnimationTimingCalculationsTest, DirectedTime) | |
| 142 { | |
| 143 Timing timing; | |
| 144 | |
| 145 // calculateDirectedTime(currentIteration, iterationDuration, iterationTime,
timing) | |
| 146 | |
| 147 // if the iteration time is null | |
| 148 EXPECT_TRUE(isNull(calculateDirectedTime(1, 2, nullValue(), timing))); | |
| 149 | |
| 150 // forwards | |
| 151 EXPECT_EQ(17, calculateDirectedTime(0, 20, 17, timing)); | |
| 152 EXPECT_EQ(17, calculateDirectedTime(1, 20, 17, timing)); | |
| 153 timing.direction = Timing::PlaybackDirectionAlternate; | |
| 154 EXPECT_EQ(17, calculateDirectedTime(0, 20, 17, timing)); | |
| 155 EXPECT_EQ(17, calculateDirectedTime(2, 20, 17, timing)); | |
| 156 timing.direction = Timing::PlaybackDirectionAlternateReverse; | |
| 157 EXPECT_EQ(17, calculateDirectedTime(1, 20, 17, timing)); | |
| 158 EXPECT_EQ(17, calculateDirectedTime(3, 20, 17, timing)); | |
| 159 | |
| 160 // reverse | |
| 161 timing.direction = Timing::PlaybackDirectionReverse; | |
| 162 EXPECT_EQ(3, calculateDirectedTime(0, 20, 17, timing)); | |
| 163 EXPECT_EQ(3, calculateDirectedTime(1, 20, 17, timing)); | |
| 164 timing.direction = Timing::PlaybackDirectionAlternate; | |
| 165 EXPECT_EQ(3, calculateDirectedTime(1, 20, 17, timing)); | |
| 166 EXPECT_EQ(3, calculateDirectedTime(3, 20, 17, timing)); | |
| 167 timing.direction = Timing::PlaybackDirectionAlternateReverse; | |
| 168 EXPECT_EQ(3, calculateDirectedTime(0, 20, 17, timing)); | |
| 169 EXPECT_EQ(3, calculateDirectedTime(2, 20, 17, timing)); | |
| 170 } | |
| 171 | |
| 172 TEST(AnimationTimingCalculationsTest, TransformedTime) | |
| 173 { | |
| 174 Timing timing; | |
| 175 | |
| 176 // calculateTransformedTime(currentIteration, iterationDuration, iterationTi
me, timing) | |
| 177 | |
| 178 // Iteration time is null | |
| 179 EXPECT_TRUE(isNull(calculateTransformedTime(1, 2, nullValue(), timing))); | |
| 180 | |
| 181 // PlaybackDirectionForwards | |
| 182 EXPECT_EQ(12, calculateTransformedTime(0, 20, 12, timing)); | |
| 183 EXPECT_EQ(12, calculateTransformedTime(1, 20, 12, timing)); | |
| 184 | |
| 185 // PlaybackDirectionForwards with timing function | |
| 186 timing.timingFunction = StepsTimingFunction::create(4, StepsTimingFunction::
StepAtEnd); | |
| 187 EXPECT_EQ(10, calculateTransformedTime(0, 20, 12, timing)); | |
| 188 EXPECT_EQ(10, calculateTransformedTime(1, 20, 12, timing)); | |
| 189 | |
| 190 // PlaybackDirectionReverse | |
| 191 timing.timingFunction = Timing::defaults().timingFunction; | |
| 192 timing.direction = Timing::PlaybackDirectionReverse; | |
| 193 EXPECT_EQ(8, calculateTransformedTime(0, 20, 12, timing)); | |
| 194 EXPECT_EQ(8, calculateTransformedTime(1, 20, 12, timing)); | |
| 195 | |
| 196 // PlaybackDirectionReverse with timing function | |
| 197 timing.timingFunction = StepsTimingFunction::create(4, StepsTimingFunction::
StepAtEnd); | |
| 198 EXPECT_EQ(5, calculateTransformedTime(0, 20, 12, timing)); | |
| 199 EXPECT_EQ(5, calculateTransformedTime(1, 20, 12, timing)); | |
| 200 | |
| 201 // Timing function when directed time is null. | |
| 202 EXPECT_TRUE(isNull(calculateTransformedTime(1, 2, nullValue(), timing))); | |
| 203 | |
| 204 // Timing function when iterationDuration is infinity | |
| 205 timing.direction = Timing::PlaybackDirectionNormal; | |
| 206 EXPECT_EQ(0, calculateTransformedTime(0, std::numeric_limits<double>::infini
ty(), 0, timing)); | |
| 207 EXPECT_EQ(1, calculateTransformedTime(0, std::numeric_limits<double>::infini
ty(), 1, timing)); | |
| 208 timing.direction = Timing::PlaybackDirectionReverse; | |
| 209 EXPECT_EQ(std::numeric_limits<double>::infinity(), calculateTransformedTime(
0, std::numeric_limits<double>::infinity(), 0, timing)); | |
| 210 EXPECT_EQ(std::numeric_limits<double>::infinity(), calculateTransformedTime(
0, std::numeric_limits<double>::infinity(), 1, timing)); | |
| 211 } | |
| 212 | |
| 213 } | |
| OLD | NEW |