MovieState.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <boost/test/unit_test.hpp>
  16. #include "core/MovieState.h"
  17. BOOST_AUTO_TEST_CASE(TestMovieStateReportsAHighFrameIfThereIsNoMovie){
  18. MovieState movie;
  19. BOOST_CHECK(!movie.IsPlaying());
  20. BOOST_CHECK_EQUAL(movie.GetFrame(), MovieState::NO_MOVIE_FRAME);
  21. // A movie without frames is a movie that isn't installed.
  22. movie.Start(0, 15.0f);
  23. BOOST_CHECK(!movie.IsPlaying());
  24. BOOST_CHECK_EQUAL(movie.GetFrame(), MovieState::NO_MOVIE_FRAME);
  25. }
  26. BOOST_AUTO_TEST_CASE(TestMovieStateShowsTheFrameOfTheElapsedTime){
  27. MovieState movie;
  28. movie.Start(30, 15.0f);
  29. BOOST_CHECK(movie.IsPlaying());
  30. BOOST_CHECK_EQUAL(movie.GetFrame(), 0);
  31. BOOST_CHECK(!movie.Advance(0.5f));
  32. BOOST_CHECK_EQUAL(movie.GetFrame(), 7);
  33. BOOST_CHECK(!movie.Advance(0.5f));
  34. BOOST_CHECK_EQUAL(movie.GetFrame(), 15);
  35. }
  36. BOOST_AUTO_TEST_CASE(TestMovieStateEndsAfterTheLastFrame){
  37. MovieState movie;
  38. movie.Start(30, 15.0f);
  39. BOOST_CHECK(!movie.Advance(1.9f));
  40. BOOST_CHECK(movie.IsPlaying());
  41. BOOST_CHECK(movie.Advance(0.2f));
  42. BOOST_CHECK(!movie.IsPlaying());
  43. // The frame stays at the number of frames, and the end is only reported once.
  44. BOOST_CHECK_EQUAL(movie.GetFrame(), 30);
  45. BOOST_CHECK(!movie.Advance(5.0f));
  46. BOOST_CHECK_EQUAL(movie.GetFrame(), 30);
  47. }
  48. BOOST_AUTO_TEST_CASE(TestMovieStateStopKeepsTheFrame){
  49. MovieState movie;
  50. movie.Start(300, 15.0f);
  51. movie.Advance(2.0f);
  52. movie.Stop();
  53. BOOST_CHECK(!movie.IsPlaying());
  54. BOOST_CHECK_EQUAL(movie.GetFrame(), 30);
  55. BOOST_CHECK(!movie.Advance(1.0f));
  56. BOOST_CHECK_EQUAL(movie.GetFrame(), 30);
  57. }
  58. BOOST_AUTO_TEST_CASE(TestMovieStateStartRestarts){
  59. MovieState movie;
  60. movie.Start(30, 15.0f);
  61. movie.Advance(1.0f);
  62. movie.Start(60, 30.0f);
  63. BOOST_CHECK(movie.IsPlaying());
  64. BOOST_CHECK_EQUAL(movie.GetFrame(), 0);
  65. movie.Advance(0.5f);
  66. BOOST_CHECK_EQUAL(movie.GetFrame(), 15);
  67. }
  68. BOOST_AUTO_TEST_CASE(TestMovieStatePreparedMovieIsAtFrameZeroUntilItStarts){
  69. MovieState movie;
  70. movie.Prepare();
  71. BOOST_CHECK(!movie.IsPlaying());
  72. BOOST_CHECK_EQUAL(movie.GetFrame(), 0);
  73. BOOST_CHECK(!movie.Advance(5.0f));
  74. BOOST_CHECK_EQUAL(movie.GetFrame(), 0);
  75. movie.Start(30, 15.0f);
  76. movie.Advance(1.0f);
  77. BOOST_CHECK_EQUAL(movie.GetFrame(), 15);
  78. // Choosing another movie afterwards starts again from frame 0.
  79. movie.Stop();
  80. movie.Prepare();
  81. BOOST_CHECK_EQUAL(movie.GetFrame(), 0);
  82. }