Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffaello committed Nov 9, 2023
1 parent d9a3449 commit 706bfb1
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <cstdint>
#include <memory>
#include <HyperSonicDrivers/utils/sound.hpp>
#include <HyperSonicDrivers/audio/PCMSound.hpp>

namespace HyperSonicDrivers::utils
{
using audio::mixer::eChannelGroup;
using audio::PCMSound;

TEST(utils, makeMono0)
{
const uint32_t size = 100;
auto data = std::make_shared<int16_t[]>(size);

auto s1 = std::make_shared<PCMSound>(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<int16_t[]>(size);

auto s1 = std::make_shared<PCMSound>(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<int16_t[]>(size);

auto s1 = std::make_shared<PCMSound>(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<int16_t[]>(size);

auto s1 = std::make_shared<PCMSound>(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();
}

0 comments on commit 706bfb1

Please sign in to comment.