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