|
6 | 6 | #include <scratchcpp/variable.h> |
7 | 7 | #include <scratchcpp/list.h> |
8 | 8 | #include <scratchcpp/keyevent.h> |
| 9 | +#include <scratch/sound_p.h> |
9 | 10 | #include <timermock.h> |
10 | 11 | #include <clockmock.h> |
| 12 | +#include <audioplayerfactorymock.h> |
| 13 | +#include <audioplayermock.h> |
11 | 14 | #include <thread> |
12 | 15 |
|
13 | 16 | #include "../common.h" |
@@ -70,6 +73,35 @@ TEST(EngineTest, IsRunning) |
70 | 73 | ASSERT_FALSE(engine.isRunning()); |
71 | 74 | } |
72 | 75 |
|
| 76 | +TEST(EngineTest, StopSounds) |
| 77 | +{ |
| 78 | + AudioPlayerFactoryMock factory; |
| 79 | + auto player1 = std::make_shared<AudioPlayerMock>(); |
| 80 | + auto player2 = std::make_shared<AudioPlayerMock>(); |
| 81 | + auto player3 = std::make_shared<AudioPlayerMock>(); |
| 82 | + SoundPrivate::playerFactory = &factory; |
| 83 | + EXPECT_CALL(factory, create()).WillOnce(Return(player1)).WillOnce(Return(player2)).WillOnce(Return(player3)); |
| 84 | + EXPECT_CALL(*player1, load).WillOnce(Return(true)); |
| 85 | + EXPECT_CALL(*player2, load).WillOnce(Return(true)); |
| 86 | + EXPECT_CALL(*player3, load).WillOnce(Return(true)); |
| 87 | + EXPECT_CALL(*player1, setVolume).Times(2); |
| 88 | + EXPECT_CALL(*player2, setVolume).Times(2); |
| 89 | + EXPECT_CALL(*player3, setVolume).Times(2); |
| 90 | + Project p("sounds.sb3"); |
| 91 | + ASSERT_TRUE(p.load()); |
| 92 | + |
| 93 | + auto engine = p.engine(); |
| 94 | + |
| 95 | + EXPECT_CALL(*player1, isPlaying()).WillOnce(Return(false)); |
| 96 | + EXPECT_CALL(*player2, isPlaying()).WillOnce(Return(true)); |
| 97 | + EXPECT_CALL(*player3, isPlaying()).WillOnce(Return(true)); |
| 98 | + EXPECT_CALL(*player2, stop()); |
| 99 | + EXPECT_CALL(*player3, stop()); |
| 100 | + engine->stopSounds(); |
| 101 | + |
| 102 | + SoundPrivate::playerFactory = nullptr; |
| 103 | +} |
| 104 | + |
73 | 105 | TEST(EngineTest, Step) |
74 | 106 | { |
75 | 107 | Project p("step.sb3"); |
|
0 commit comments