1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.scenario.animation.shared;
  27 
  28 
  29 import com.sun.javafx.tk.Toolkit;
  30 import javafx.animation.Animation;
  31 import javafx.animation.Animation.Status;
  32 import javafx.animation.AnimationMock;
  33 import javafx.animation.AnimationMock.Command;
  34 import javafx.util.Duration;
  35 import org.junit.Before;
  36 import org.junit.Test;
  37 
  38 import static org.junit.Assert.*;
  39 
  40 public class FiniteClipEnvelopeTest {
  41 
  42     private final long CYCLE_TICKS = Math.round(6.0 * AnimationMock.DEFAULT_DURATION.toMillis());
  43 
  44     private ClipEnvelope clip;
  45     private AnimationMock animation;
  46     
  47     @Before
  48     public void setUp() {
  49         animation = new AnimationMock(Toolkit.getToolkit().getMasterTimer(), AnimationMock.DEFAULT_DURATION, AnimationMock.DEFAULT_RATE, 9, AnimationMock.DEFAULT_AUTOREVERSE);
  50         clip = new FiniteClipEnvelope(animation);
  51     }
  52     
  53     @Test
  54     public void testSetValues() {
  55         ClipEnvelope c;
  56         
  57         // Setting cycleCount to 1
  58         animation.setCycleCount(1);
  59         animation.mockCycleDuration(AnimationMock.DEFAULT_DURATION);
  60         c = clip.setCycleCount(1);
  61         assertNotSame(clip, c);
  62         assertTrue(c instanceof SingleLoopClipEnvelope);
  63         
  64         // Setting cycleCount to INDEFINITE
  65         animation.setCycleCount(Animation.INDEFINITE);
  66         animation.mockCycleDuration(AnimationMock.DEFAULT_DURATION);
  67         c = clip.setCycleCount(Animation.INDEFINITE);
  68         assertNotSame(clip, c);
  69         assertTrue(c instanceof InfiniteClipEnvelope);
  70         
  71         // Setting cycleDuration to INDEFINITE
  72         animation.setCycleCount(9);
  73         animation.mockCycleDuration(Duration.INDEFINITE);
  74         c = clip.setCycleDuration(Duration.INDEFINITE);
  75         assertNotSame(clip, c);
  76         assertTrue(c instanceof SingleLoopClipEnvelope);
  77 
  78     }
  79 
  80     @Test
  81     public void testJump() {
  82         clip.jumpTo(6 * 300);
  83         animation.check(Command.JUMP, 6 * 300, CYCLE_TICKS);
  84         
  85         clip.jumpTo(0);
  86         animation.check(Command.JUMP, 0, CYCLE_TICKS);
  87         
  88         clip.jumpTo(6 * 1000);
  89         animation.check(Command.JUMP, 6 * 1000, CYCLE_TICKS);
  90         
  91         clip.jumpTo(-1);
  92         animation.check(Command.JUMP, 0, CYCLE_TICKS);
  93         
  94         clip.jumpTo(6 * 1000 + 1);
  95         animation.check(Command.JUMP, 1, CYCLE_TICKS);
  96         
  97         clip.jumpTo(6 * 9000 + 1);
  98         animation.check(Command.JUMP, 6 * 1000, CYCLE_TICKS);
  99     }
 100         
 101     @Test
 102     public void testTimePulseForward() {
 103         animation.mockStatus(Status.RUNNING);
 104         clip.start();
 105         
 106         clip.timePulse(1);
 107         animation.check(Command.PLAY, 1, CYCLE_TICKS);
 108         assertFalse(animation.finishCalled());
 109         
 110         clip.timePulse(6 * 500);
 111         animation.check(Command.PLAY, 6 * 500, CYCLE_TICKS);
 112         assertFalse(animation.finishCalled());
 113 
 114         clip.timePulse(6 * 700);
 115         animation.check(Command.PLAY, 6 * 700, CYCLE_TICKS);
 116         assertFalse(animation.finishCalled());
 117 
 118         clip.timePulse(6 * 1000 - 1);
 119         animation.check(Command.PLAY, 6 * 1000 - 1, CYCLE_TICKS);
 120         assertFalse(animation.finishCalled());
 121 
 122         clip.timePulse(6 * 1000 + 1);
 123         animation.check(Command.PLAY, 1, CYCLE_TICKS);
 124         assertFalse(animation.finishCalled());
 125 
 126         clip.timePulse(6 * 2200);
 127         animation.check(Command.PLAY, 6 * 200, CYCLE_TICKS);
 128         assertFalse(animation.finishCalled());
 129 
 130         clip.timePulse(6 * 4300);
 131         animation.check(Command.PLAY, 6 * 300, CYCLE_TICKS);
 132         assertFalse(animation.finishCalled());
 133 
 134         // pulse close to the end
 135         clip.timePulse(6 * 9000 - 1);
 136         animation.check(Command.PLAY, 6 * 1000 - 1, CYCLE_TICKS);
 137         assertFalse(animation.finishCalled());
 138       
 139         // pulse at the end
 140         clip.timePulse(6 * 9000);
 141         animation.check(Command.PLAY, 6 * 1000, CYCLE_TICKS);
 142         assertTrue(animation.finishCalled());
 143     }
 144     
 145     @Test
 146     public void testTimePulseBackward() {
 147         clip.setRate(-1.0);
 148         clip.jumpTo(6 * 9000);
 149         animation.mockStatus(Status.RUNNING);
 150         clip.start();
 151         
 152         clip.timePulse(1);
 153         animation.check(Command.PLAY, 6 * 1000 - 1, CYCLE_TICKS);
 154         assertFalse(animation.finishCalled());
 155         
 156         clip.timePulse(6 * 500);
 157         animation.check(Command.PLAY, 6 * 500, CYCLE_TICKS);
 158         assertFalse(animation.finishCalled());
 159 
 160         clip.timePulse(6 * 700);
 161         animation.check(Command.PLAY, 6 * 300, CYCLE_TICKS);
 162         assertFalse(animation.finishCalled());
 163 
 164         clip.timePulse(6 * 1000 - 1);
 165         animation.check(Command.PLAY, 1, CYCLE_TICKS);
 166         assertFalse(animation.finishCalled());
 167 
 168         clip.timePulse(6 * 1000 + 1);
 169         animation.check(Command.PLAY, 6 * 1000 - 1, CYCLE_TICKS);
 170         assertFalse(animation.finishCalled());
 171 
 172         clip.timePulse(6 * 2200);
 173         animation.check(Command.PLAY, 6 * 800, CYCLE_TICKS);
 174         assertFalse(animation.finishCalled());
 175 
 176         clip.timePulse(6 * 4300);
 177         animation.check(Command.PLAY, 6 * 700, CYCLE_TICKS);
 178         assertFalse(animation.finishCalled());
 179 
 180         // pulse close to the end
 181         clip.timePulse(6 * 9000 - 1);
 182         animation.check(Command.PLAY, 1, CYCLE_TICKS);
 183         assertFalse(animation.finishCalled());
 184       
 185         // pulse at the end
 186         clip.timePulse(6 * 9000);
 187         animation.check(Command.PLAY, 0, CYCLE_TICKS);
 188         assertTrue(animation.finishCalled());
 189     }
 190     
 191     @Test
 192     public void testTimePulseForwardAutoReverse() {
 193         animation.mockStatus(Status.RUNNING);
 194         clip.setAutoReverse(true);
 195         clip.start();
 196 
 197         clip.timePulse(1);
 198         animation.check(Command.PLAY, 1, CYCLE_TICKS);
 199         assertFalse(animation.finishCalled());
 200         
 201         clip.timePulse(6 * 200);
 202         animation.check(Command.PLAY, 6 * 200, CYCLE_TICKS);
 203         assertFalse(animation.finishCalled());
 204 
 205         clip.timePulse(6 * 1000 - 1);
 206         animation.check(Command.PLAY, 6 * 1000 - 1, CYCLE_TICKS);
 207         assertFalse(animation.finishCalled());
 208 
 209         clip.timePulse(6 * 1000 + 1);
 210         animation.check(Command.PLAY, 6 * 1000 - 1, CYCLE_TICKS);
 211         assertFalse(animation.finishCalled());
 212 
 213         // pulse one cycle ahead
 214         clip.timePulse(6 * 2200);
 215         animation.check(Command.PLAY, 6 * 200, CYCLE_TICKS);
 216         assertFalse(animation.finishCalled());
 217 
 218         // pulse two cycles ahead
 219         clip.timePulse(6 * 4300);
 220         animation.check(Command.PLAY, 6 * 300, CYCLE_TICKS);
 221         assertFalse(animation.finishCalled());
 222 
 223         // another pulse one cycle ahead
 224         clip.timePulse(6 * 5400);
 225         animation.check(Command.PLAY, 6 * 600, CYCLE_TICKS);
 226         assertFalse(animation.finishCalled());
 227 
 228         // another pulse two cycles ahead
 229         clip.timePulse(6 * 7100);
 230         animation.check(Command.PLAY, 6 * 900, CYCLE_TICKS);
 231         assertFalse(animation.finishCalled());
 232 
 233         // pulse close to the end
 234         clip.timePulse(6 * 9000 - 1);
 235         animation.check(Command.PLAY, 6 * 1000 - 1, CYCLE_TICKS);
 236         assertFalse(animation.finishCalled());
 237       
 238         // pulse at the end
 239         clip.timePulse(6 * 9000);
 240         animation.check(Command.PLAY, 6 * 1000, CYCLE_TICKS);
 241         assertTrue(animation.finishCalled());
 242     }
 243     
 244     @Test
 245     public void testTimePulseBackwardAutoReverse() {
 246         animation.mockStatus(Status.RUNNING);
 247         clip.jumpTo(6 * 9000);
 248         clip.start();
 249         clip.setAutoReverse(true);
 250         clip.setRate(-1);
 251 
 252         clip.timePulse(1);
 253         animation.check(Command.PLAY, 6 * 1000 - 1, CYCLE_TICKS);
 254         assertFalse(animation.finishCalled());
 255         
 256         clip.timePulse(6 * 200);
 257         animation.check(Command.PLAY, 6 * 800, CYCLE_TICKS);
 258         assertFalse(animation.finishCalled());
 259 
 260         clip.timePulse(6 * 1000 - 1);
 261         animation.check(Command.PLAY, 1, CYCLE_TICKS);
 262         assertFalse(animation.finishCalled());
 263 
 264         clip.timePulse(6 * 1000 + 1);
 265         animation.check(Command.PLAY, 1, CYCLE_TICKS);
 266         assertFalse(animation.finishCalled());
 267 
 268         // pulse one cycle ahead
 269         clip.timePulse(6 * 2200);
 270         animation.check(Command.PLAY, 6 * 800, CYCLE_TICKS);
 271         assertFalse(animation.finishCalled());
 272 
 273         // pulse two cycles ahead
 274         clip.timePulse(6 * 4300);
 275         animation.check(Command.PLAY, 6 * 700, CYCLE_TICKS);
 276         assertFalse(animation.finishCalled());
 277 
 278         // another pulse one cycle ahead
 279         clip.timePulse(6 * 5400);
 280         animation.check(Command.PLAY, 6 * 400, CYCLE_TICKS);
 281         assertFalse(animation.finishCalled());
 282 
 283         // another pulse two cycles ahead
 284         clip.timePulse(6 * 7100);
 285         animation.check(Command.PLAY, 6 * 100, CYCLE_TICKS);
 286         assertFalse(animation.finishCalled());
 287 
 288         // pulse close to the end
 289         clip.timePulse(6 * 9000 - 1);
 290         animation.check(Command.PLAY, 1, CYCLE_TICKS);
 291         assertFalse(animation.finishCalled());
 292       
 293         // pulse at the end
 294         clip.timePulse(6 * 9000);
 295         animation.check(Command.PLAY, 0, CYCLE_TICKS);
 296         assertTrue(animation.finishCalled());
 297     }
 298 
 299     @Test
 300     public void testJumpAndPulseForward() {
 301         animation.mockStatus(Status.RUNNING);
 302         clip.start();
 303         
 304         clip.jumpTo(6 * 300);
 305         animation.check(Command.JUMP, 6 * 300, CYCLE_TICKS);
 306 
 307         clip.timePulse(6 * 800);
 308         animation.check(Command.PLAY, 6 * 100, CYCLE_TICKS);
 309         assertFalse(animation.finishCalled());
 310 
 311         clip.jumpTo(6 * 50);
 312         animation.check(Command.JUMP, 6 * 50, CYCLE_TICKS);
 313 
 314         clip.timePulse(6 * 1850);
 315         animation.check(Command.PLAY, 6 * 100, CYCLE_TICKS);
 316         assertFalse(animation.finishCalled());
 317         
 318         clip.jumpTo(0);
 319         animation.check(Command.JUMP, 6 * 0, CYCLE_TICKS);
 320 
 321         clip.timePulse(6 * 2000);
 322         animation.check(Command.PLAY, 6 * 150, CYCLE_TICKS);
 323         assertFalse(animation.finishCalled());
 324         
 325         clip.jumpTo(6 * 1000);
 326         animation.check(Command.JUMP, 6 * 1000, CYCLE_TICKS);
 327 
 328         clip.timePulse(6 * 2200);
 329         animation.check(Command.PLAY, 6 * 200, CYCLE_TICKS);
 330         assertFalse(animation.finishCalled());
 331         
 332         clip.jumpTo(6 * 3400);
 333         animation.check(Command.JUMP, 6 * 400, CYCLE_TICKS);
 334 
 335         clip.timePulse(6 * 2400);
 336         animation.check(Command.PLAY, 6 * 600, CYCLE_TICKS);
 337         assertFalse(animation.finishCalled());
 338         
 339         clip.jumpTo(6 * 1100);
 340         animation.check(Command.JUMP, 6 * 100, CYCLE_TICKS);
 341 
 342         clip.timePulse(6 * 2500);
 343         animation.check(Command.PLAY, 6 * 200, CYCLE_TICKS);
 344         assertFalse(animation.finishCalled());
 345 
 346         // pulse close to the end
 347         clip.timePulse(6 * 10300 - 1);
 348         animation.check(Command.PLAY, 6 * 1000 - 1, CYCLE_TICKS);
 349         assertFalse(animation.finishCalled());
 350       
 351         // pulse at the end
 352         clip.timePulse(6 * 10300);
 353         animation.check(Command.PLAY, 6 * 1000, CYCLE_TICKS);
 354         assertTrue(animation.finishCalled());
 355     }
 356 
 357     @Test
 358     public void testJumpAndPulseBackward() {
 359         animation.mockStatus(Status.RUNNING);
 360         clip.jumpTo(6 * 9000);
 361         clip.setRate(-1);
 362         clip.start();
 363         
 364         // jump forward
 365         clip.jumpTo(6 * 8300);
 366         animation.check(Command.JUMP, 6 * 300, CYCLE_TICKS);
 367         assertFalse(animation.finishCalled());
 368 
 369         // pulse in next cycle
 370         clip.timePulse(6 * 700);
 371         animation.check(Command.PLAY, 6 * 600, CYCLE_TICKS);
 372         assertFalse(animation.finishCalled());
 373 
 374         // jump backward
 375         clip.jumpTo(6 * 7900);
 376         animation.check(Command.JUMP, 6 * 900, CYCLE_TICKS);
 377         assertFalse(animation.finishCalled());
 378 
 379         // pulse one cycle ahead
 380         clip.timePulse(6 * 1750);
 381         animation.check(Command.PLAY, 6 * 850, CYCLE_TICKS);
 382         assertFalse(animation.finishCalled());
 383 
 384         // jump to same position at end
 385         clip.jumpTo(6 * 7000);
 386         animation.check(Command.JUMP, 6 * 1000, CYCLE_TICKS);
 387         assertFalse(animation.finishCalled());
 388 
 389         // normal pulse
 390         clip.timePulse(6 * 2000);
 391         animation.check(Command.PLAY, 6 * 750, CYCLE_TICKS);
 392         assertFalse(animation.finishCalled());
 393 
 394         // jump to start
 395         clip.jumpTo(6 * 6000);
 396         animation.check(Command.JUMP, 6 * 1000, CYCLE_TICKS);
 397         assertFalse(animation.finishCalled());
 398 
 399         // normal pulse
 400         clip.timePulse(6 * 2200);
 401         animation.check(Command.PLAY, 6 * 800, CYCLE_TICKS);
 402         assertFalse(animation.finishCalled());
 403         
 404         clip.jumpTo(6 * 3400);
 405         animation.check(Command.JUMP, 6 * 400, CYCLE_TICKS);
 406 
 407         clip.timePulse(6 * 2400);
 408         animation.check(Command.PLAY, 6 * 200, CYCLE_TICKS);
 409         assertFalse(animation.finishCalled());
 410         
 411         clip.jumpTo(6 * 5100);
 412         animation.check(Command.JUMP, 6 * 100, CYCLE_TICKS);
 413 
 414         clip.timePulse(6 * 2700);
 415         animation.check(Command.PLAY, 6 * 800, CYCLE_TICKS);
 416         assertFalse(animation.finishCalled());
 417 
 418         // pulse close to the end
 419         clip.timePulse(6 * 7500 - 1);
 420         animation.check(Command.PLAY, 1, CYCLE_TICKS);
 421         assertFalse(animation.finishCalled());
 422       
 423         // pulse at the end
 424         clip.timePulse(6 * 7500);
 425         animation.check(Command.PLAY, 0, CYCLE_TICKS);
 426         assertTrue(animation.finishCalled());
 427     }
 428 
 429     @Test
 430     public void testJumpAndPulseForwardAutoReverse() {
 431         animation.mockStatus(Status.RUNNING);
 432         clip.setAutoReverse(true);
 433         clip.start();
 434         
 435         // jump forward
 436         clip.jumpTo(6 * 300);
 437         animation.check(Command.JUMP, 6 * 300, CYCLE_TICKS);
 438 
 439         // pulse in next cycle
 440         clip.timePulse(6 * 900);
 441         animation.check(Command.PLAY, 6 * 800, CYCLE_TICKS);
 442         assertFalse(animation.finishCalled());
 443 
 444         // jump backward
 445         clip.jumpTo(6 * 900);
 446         animation.check(Command.JUMP, 6 * 900, CYCLE_TICKS);
 447 
 448         // pulse one cycle ahead
 449         clip.timePulse(6 * 1850);
 450         animation.check(Command.PLAY, 6 * 150, CYCLE_TICKS);
 451         assertFalse(animation.finishCalled());
 452         
 453         // jump to start
 454         clip.jumpTo(6 * 0);
 455         animation.check(Command.JUMP, 0, CYCLE_TICKS);
 456 
 457         // normal pulse
 458         clip.timePulse(6 * 2000);
 459         animation.check(Command.PLAY, 6 * 150, CYCLE_TICKS);
 460         assertFalse(animation.finishCalled());
 461         
 462         // jump to end
 463         clip.jumpTo(6 * 1000);
 464         animation.check(Command.JUMP, 6 * 1000, CYCLE_TICKS);
 465 
 466         // normal pulse
 467         clip.timePulse(6 * 2200);
 468         animation.check(Command.PLAY, 6 * 800, CYCLE_TICKS);
 469         assertFalse(animation.finishCalled());
 470 
 471         clip.jumpTo(6 * 3400);
 472         animation.check(Command.JUMP, 6 * 600, CYCLE_TICKS);
 473 
 474         clip.timePulse(6 * 2400);
 475         animation.check(Command.PLAY, 6 * 400, CYCLE_TICKS);
 476         assertFalse(animation.finishCalled());
 477         
 478         clip.jumpTo(6 * 1100);
 479         animation.check(Command.JUMP, 6 * 900, CYCLE_TICKS);
 480 
 481         clip.timePulse(6 * 2500);
 482         animation.check(Command.PLAY, 6 * 800, CYCLE_TICKS);
 483         assertFalse(animation.finishCalled());
 484 
 485         // pulse close to the end
 486         clip.timePulse(6 * 10300 - 1);
 487         animation.check(Command.PLAY, 6 * 1000 - 1, CYCLE_TICKS);
 488         assertFalse(animation.finishCalled());
 489       
 490         // pulse at the end
 491         clip.timePulse(6 * 10300);
 492         animation.check(Command.PLAY, 6 * 1000, CYCLE_TICKS);
 493         assertTrue(animation.finishCalled());
 494     }
 495 
 496     @Test
 497     public void testJumpAndPulseBackwardAutoReverse() {
 498         animation.mockStatus(Status.RUNNING);
 499         clip.setAutoReverse(true);
 500         clip.setRate(-1);
 501         clip.start();
 502         
 503         // jump forward
 504         clip.jumpTo(6 * 8300);
 505         animation.check(Command.JUMP, 6 * 300, CYCLE_TICKS);
 506         assertFalse(animation.finishCalled());
 507 
 508         // pulse in next cycle
 509         clip.timePulse(6 * 700);
 510         animation.check(Command.PLAY, 6 * 400, CYCLE_TICKS);
 511         assertFalse(animation.finishCalled());
 512 
 513         // jump backward
 514         clip.jumpTo(6 * 7900);
 515         animation.check(Command.JUMP, 6 * 100, CYCLE_TICKS);
 516         assertFalse(animation.finishCalled());
 517 
 518         // pulse one cycle ahead
 519         clip.timePulse(6 * 1750);
 520         animation.check(Command.PLAY, 6 * 850, CYCLE_TICKS);
 521         assertFalse(animation.finishCalled());
 522 
 523         // jump to same position at end
 524         clip.jumpTo(6 * 7000);
 525         animation.check(Command.JUMP, 6 * 1000, CYCLE_TICKS);
 526         assertFalse(animation.finishCalled());
 527 
 528         // normal pulse
 529         clip.timePulse(6 * 2000);
 530         animation.check(Command.PLAY, 6 * 750, CYCLE_TICKS);
 531         assertFalse(animation.finishCalled());
 532 
 533         // jump to start
 534         clip.jumpTo(6 * 6000);
 535         animation.check(Command.JUMP, 6 * 0, CYCLE_TICKS);
 536         assertFalse(animation.finishCalled());
 537 
 538         // normal pulse
 539         clip.timePulse(6 * 2200);
 540         animation.check(Command.PLAY, 6 * 200, CYCLE_TICKS);
 541         assertFalse(animation.finishCalled());
 542         
 543         clip.jumpTo(6 * 3400);
 544         animation.check(Command.JUMP, 6 * 600, CYCLE_TICKS);
 545 
 546         clip.timePulse(6 * 2400);
 547         animation.check(Command.PLAY, 6 * 800, CYCLE_TICKS);
 548         assertFalse(animation.finishCalled());
 549         
 550         clip.jumpTo(6 * 5100);
 551         animation.check(Command.JUMP, 6 * 900, CYCLE_TICKS);
 552 
 553         clip.timePulse(6 * 2700);
 554         animation.check(Command.PLAY, 6 * 800, CYCLE_TICKS);
 555         assertFalse(animation.finishCalled());
 556 
 557         // pulse close to the end
 558         clip.timePulse(6 * 7500 - 1);
 559         animation.check(Command.PLAY, 1, CYCLE_TICKS);
 560         assertFalse(animation.finishCalled());
 561       
 562         // pulse at the end
 563         clip.timePulse(6 * 7500);
 564         animation.check(Command.PLAY, 0, CYCLE_TICKS);
 565         assertTrue(animation.finishCalled());
 566     }
 567     
 568     @Test
 569     public void testPositiveFastForwardRate() {
 570         animation.mockStatus(Status.RUNNING);
 571         clip.setRate(2.5);
 572         clip.start();
 573         
 574         clip.timePulse(6 * 300);
 575         animation.check(Command.PLAY, 6 * 750, CYCLE_TICKS);
 576         assertFalse(animation.finishCalled());
 577         
 578         clip.timePulse(6 * 3600 - 2); // 9000 / 2.5
 579         animation.check(Command.PLAY, 6 * 1000 - 5, CYCLE_TICKS);
 580         assertFalse(animation.finishCalled());
 581 
 582         clip.timePulse(6 * 3600); // 9000 / 2.5
 583         animation.check(Command.PLAY, 6 * 1000, CYCLE_TICKS);
 584         assertTrue(animation.finishCalled());
 585     }
 586         
 587     @Test
 588     public void testPositiveSlowDownRate() {
 589         animation.mockStatus(Status.RUNNING);
 590         clip.setRate(0.2);
 591         clip.start();
 592         
 593         clip.timePulse(6 * 300);
 594         animation.check(Command.PLAY, 6 * 60, CYCLE_TICKS);
 595         assertFalse(animation.finishCalled());
 596         
 597         clip.timePulse(6 * 45000 - 5); // 9000 / 0.2
 598         animation.check(Command.PLAY, 6 * 1000 - 1, CYCLE_TICKS);
 599         assertFalse(animation.finishCalled());
 600 
 601         clip.timePulse(6 * 45000); // 9000 / 0.2
 602         animation.check(Command.PLAY, 6 * 1000, CYCLE_TICKS);
 603         assertTrue(animation.finishCalled());
 604     }
 605     
 606     @Test
 607     public void testNegativeFastForwardRate() {
 608         clip.jumpTo(6 * 9000);
 609         clip.setRate(-2.5);
 610         animation.mockStatus(Status.RUNNING);
 611         clip.start();
 612         
 613         clip.timePulse(6 * 300);
 614         animation.check(Command.PLAY, 6 * 250, CYCLE_TICKS);
 615         assertFalse(animation.finishCalled());
 616         
 617         clip.timePulse(6 * 3600 - 2); // 9000 / 2.5
 618         animation.check(Command.PLAY, 5, CYCLE_TICKS);
 619         assertFalse(animation.finishCalled());
 620 
 621         clip.timePulse(6 * 3600); // 9000 / 2.5
 622         animation.check(Command.PLAY, 0, CYCLE_TICKS);
 623         assertTrue(animation.finishCalled());
 624     }
 625         
 626     @Test
 627     public void testNegativeSlowDownRate() {
 628         clip.jumpTo(6 * 9000);
 629         clip.setRate(-0.2);
 630         animation.mockStatus(Status.RUNNING);
 631         clip.start();
 632         
 633         clip.timePulse(6 * 300);
 634         animation.check(Command.PLAY, 6 * 940, CYCLE_TICKS);
 635         assertFalse(animation.finishCalled());
 636         
 637         clip.timePulse(6 * 45000 - 5); // 9000 / 0.2
 638         animation.check(Command.PLAY, 1, CYCLE_TICKS);
 639         assertFalse(animation.finishCalled());
 640 
 641         clip.timePulse(6 * 45000); // 9000 / 0.2
 642         animation.check(Command.PLAY, 0, CYCLE_TICKS);
 643         assertTrue(animation.finishCalled());
 644     }
 645   
 646     @Test
 647     public void testChangeRateWhilePlaying() {
 648         animation.mockStatus(Status.RUNNING);
 649         clip.setRate(0.5);
 650         clip.start();
 651         
 652         clip.timePulse(6 * 200);
 653         animation.check(Command.PLAY, 6 * 100, CYCLE_TICKS);
 654         
 655         clip.setRate(3.0);
 656         clip.timePulse(6 * 300);
 657         animation.check(Command.PLAY, 6 * 400, CYCLE_TICKS);
 658         
 659         clip.setRate(2.0);
 660         clip.timePulse(6 * 500);
 661         animation.check(Command.PLAY, 6 * 800, CYCLE_TICKS);
 662         
 663         clip.setRate(-0.5);
 664         clip.timePulse(6 * 1100);
 665         animation.check(Command.PLAY, 6 * 500, CYCLE_TICKS);
 666         
 667         clip.setRate(-3.0);
 668         clip.timePulse(6 * 1200);
 669         animation.check(Command.PLAY, 6 * 200, CYCLE_TICKS);
 670         
 671         clip.setRate(0.5);
 672         clip.timePulse(6 * 2100);
 673         animation.check(Command.PLAY, 6 * 650, CYCLE_TICKS);
 674         
 675         clip.setRate(1.5);
 676         clip.timePulse(6 * 2600);
 677         animation.check(Command.PLAY, 6 * 400, CYCLE_TICKS);
 678         
 679         clip.setRate(-2.0);
 680         clip.timePulse(6 * 3000);
 681         animation.check(Command.PLAY, 6 * 600, CYCLE_TICKS);
 682     }
 683     
 684     @Test
 685     public void testRateAutoReverse() {
 686         animation.mockStatus(Status.RUNNING);
 687         clip.setAutoReverse(true);
 688         clip.setRate(0.5);
 689         clip.start();
 690         
 691         clip.timePulse(6 * 200);
 692         animation.check(Command.PLAY, 6 * 100, CYCLE_TICKS);
 693         
 694         clip.setRate(3.0);
 695         clip.timePulse(6 * 300);
 696         animation.check(Command.PLAY, 6 * 400, CYCLE_TICKS);
 697         
 698         clip.setRate(2.0);
 699         clip.timePulse(6 * 500);
 700         animation.check(Command.PLAY, 6 * 800, CYCLE_TICKS);
 701         
 702         clip.setRate(-0.5);
 703         clip.timePulse(6 * 1100);
 704         animation.check(Command.PLAY, 6 * 500, CYCLE_TICKS);
 705         
 706         clip.setRate(-3.0);
 707         clip.timePulse(6 * 1200);
 708         animation.check(Command.PLAY, 6 * 200, CYCLE_TICKS);
 709         
 710         clip.setRate(0.5);
 711         clip.timePulse(6 * 2100);
 712         animation.check(Command.PLAY, 6 * 650, CYCLE_TICKS);
 713         
 714         clip.setRate(1.5);
 715         clip.timePulse(6 * 2600);
 716         animation.check(Command.PLAY, 6 * 600, CYCLE_TICKS);
 717         
 718         clip.setRate(-2.0);
 719         clip.timePulse(6 * 3000);
 720         animation.check(Command.PLAY, 6 * 600, CYCLE_TICKS);
 721     }
 722 
 723 }