-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* pcmDriver stop methods * code rev * update version * sdl2 mixer callback, small improvement * code rev * sonarcloud code rev * code rev * PCMDriverTest init | TestIMusicDriver -> TestIAudioDriver * PCMDriverTest play/stop basic scenarios * code rev * sonarcloud code rev
- Loading branch information
Showing
10 changed files
with
208 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestPCMDriver.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#include <gtest/gtest.h> | ||
#include <gmock/gmock.h> | ||
#include <HyperSonicDrivers/drivers/PCMDriver.hpp> | ||
#include <HyperSonicDrivers/audio/IMixerMock.hpp> | ||
#include <HyperSonicDrivers/audio/PCMSound.hpp> | ||
#include <HyperSonicDrivers/audio/mixer/ChannelGroup.hpp> | ||
#include <memory> | ||
#include <cstdint> | ||
|
||
namespace HyperSonicDrivers::drivers | ||
{ | ||
TEST(PCMDriver, play_stop0) | ||
{ | ||
auto mixer = audio::make_mixer<audio::IMixerMock>(); | ||
auto drv = PCMDriver(mixer); | ||
|
||
EXPECT_EQ(drv.max_streams, mixer->max_channels); | ||
|
||
auto sound_data = std::make_shared<int16_t[]>(1); | ||
auto sound = std::make_shared<audio::PCMSound>(audio::mixer::eChannelGroup::Plain, true, 44100, 1, sound_data); | ||
auto ch_id = drv.play(sound); | ||
|
||
ASSERT_TRUE(drv.isPlaying(sound)); | ||
ASSERT_TRUE(drv.isPlaying()); | ||
ASSERT_TRUE(ch_id.has_value()); | ||
EXPECT_EQ(ch_id.value(), 0); | ||
|
||
drv.stop(ch_id.value()); | ||
EXPECT_FALSE(drv.isPlaying(sound)); | ||
EXPECT_FALSE(drv.isPlaying()); | ||
} | ||
|
||
TEST(PCMDriver, play_stop1) | ||
{ | ||
auto mixer = audio::make_mixer<audio::IMixerMock>(); | ||
auto drv = PCMDriver(mixer); | ||
|
||
EXPECT_EQ(drv.max_streams, mixer->max_channels); | ||
|
||
auto sound_data = std::make_shared<int16_t[]>(1); | ||
auto sound = std::make_shared<audio::PCMSound>(audio::mixer::eChannelGroup::Plain, true, 44100, 1, sound_data); | ||
auto ch_id = drv.play(sound); | ||
|
||
ASSERT_TRUE(drv.isPlaying(sound)); | ||
ASSERT_TRUE(drv.isPlaying()); | ||
ASSERT_TRUE(ch_id.has_value()); | ||
EXPECT_EQ(ch_id.value(), 0); | ||
|
||
drv.stop(sound); | ||
EXPECT_FALSE(drv.isPlaying(sound)); | ||
EXPECT_FALSE(drv.isPlaying()); | ||
} | ||
|
||
TEST(PCMDriver, play_stop2) | ||
{ | ||
auto mixer = audio::make_mixer<audio::IMixerMock>(); | ||
auto drv = PCMDriver(mixer); | ||
|
||
EXPECT_EQ(drv.max_streams, mixer->max_channels); | ||
|
||
auto sound_data = std::make_shared<int16_t[]>(1); | ||
auto sound = std::make_shared<audio::PCMSound>(audio::mixer::eChannelGroup::Plain, true, 44100, 1, sound_data); | ||
auto ch_id = drv.play(sound); | ||
|
||
ASSERT_TRUE(drv.isPlaying(sound)); | ||
ASSERT_TRUE(drv.isPlaying()); | ||
ASSERT_TRUE(ch_id.has_value()); | ||
EXPECT_EQ(ch_id.value(), 0); | ||
|
||
drv.stop(); | ||
EXPECT_FALSE(drv.isPlaying(sound)); | ||
EXPECT_FALSE(drv.isPlaying()); | ||
} | ||
|
||
TEST(PCMDriver, play_stop_complex) | ||
{ | ||
auto mixer = audio::make_mixer<audio::IMixerMock>(); | ||
auto drv = PCMDriver(mixer); | ||
|
||
EXPECT_EQ(drv.max_streams, mixer->max_channels); | ||
|
||
auto sound_data = std::make_shared<int16_t[]>(1); | ||
auto sound = std::make_shared<audio::PCMSound>(audio::mixer::eChannelGroup::Plain, true, 44100, 1, sound_data); | ||
auto sound_data2 = std::make_shared<int16_t[]>(1); | ||
auto sound2 = std::make_shared<audio::PCMSound>(audio::mixer::eChannelGroup::Unknown, true, 22050, 1, sound_data2); | ||
|
||
auto ch_id = drv.play(sound); | ||
EXPECT_TRUE(drv.play(sound2).has_value()); | ||
EXPECT_TRUE(drv.play(sound2).has_value()); | ||
EXPECT_TRUE(drv.play(sound2).has_value()); | ||
|
||
ASSERT_TRUE(drv.isPlaying(sound)); | ||
ASSERT_TRUE(drv.isPlaying()); | ||
ASSERT_TRUE(ch_id.has_value()); | ||
EXPECT_EQ(ch_id.value(), 0); | ||
|
||
drv.stop(ch_id.value()); | ||
EXPECT_FALSE(drv.isPlaying(sound)); | ||
EXPECT_TRUE(drv.isPlaying()); | ||
} | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
::testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |