From 706bfb19e4e60dbdc63d16a27426791046acf408 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Thu, 9 Nov 2023 20:47:25 +0000 Subject: [PATCH] add test --- .../test/HyperSonicDrivers/CMakeLists.txt | 8 +++ .../HyperSonicDrivers/utils/TestSound.cpp | 72 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/utils/TestSound.cpp diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/CMakeLists.txt b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/CMakeLists.txt index 24362b88..c035a76c 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/CMakeLists.txt +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/CMakeLists.txt @@ -73,6 +73,14 @@ macro_test( LINKS_PRIVATE hyper-sonic-drivers-static ) +macro_test( + EXE TestSound + FILES "utils/TestSound.cpp" + LINKS_PRIVATE hyper-sonic-drivers-static + FIXTURES + "../fixtures/Wav_868kb.wav" +) + macro_test( EXE TestPCSpeaker FILES "hardware/TestPCSpeaker.cpp" diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/utils/TestSound.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/utils/TestSound.cpp new file mode 100644 index 00000000..f5a06410 --- /dev/null +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/utils/TestSound.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include + +namespace HyperSonicDrivers::utils +{ + using audio::mixer::eChannelGroup; + using audio::PCMSound; + + TEST(utils, makeMono0) + { + const uint32_t size = 100; + auto data = std::make_shared(size); + + auto s1 = std::make_shared(eChannelGroup::Plain, true, 44100, size, data); + auto s2 = makeMono(s1); + + EXPECT_TRUE(s1->stereo); + EXPECT_FALSE(s2->stereo); + EXPECT_EQ(s1->group, s2->group); + EXPECT_EQ(s1->freq, s2->freq); + EXPECT_EQ(s1->dataSize, size); + EXPECT_EQ(s2->dataSize, size / 2); + } + + TEST(utils, makeMono1) + { + const uint32_t size = 100; + auto data = std::make_shared(size); + + auto s1 = std::make_shared(eChannelGroup::Plain, false, 44100, size, data); + auto s2 = makeMono(s1); + + ASSERT_EQ(s1, s2); + } + + TEST(utils, makeStereo0) + { + const uint32_t size = 100; + auto data = std::make_shared(size); + + auto s1 = std::make_shared(eChannelGroup::Plain, false, 44100, size, data); + auto s2 = makeStereo(s1); + + EXPECT_FALSE(s1->stereo); + EXPECT_TRUE(s2->stereo); + EXPECT_EQ(s1->group, s2->group); + EXPECT_EQ(s1->freq, s2->freq); + EXPECT_EQ(s1->dataSize, size); + EXPECT_EQ(s2->dataSize, size * 2); + } + + TEST(utils, makeStereo1) + { + const uint32_t size = 100; + auto data = std::make_shared(size); + + auto s1 = std::make_shared(eChannelGroup::Plain, true, 44100, size, data); + auto s2 = makeStereo(s1); + + ASSERT_EQ(s1, s2); + } +} + +int main(int argc, char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}