Skip to content

Commit

Permalink
fix test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffaello committed Oct 15, 2023
1 parent d9196ae commit 4071287
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace HyperSonicDrivers::devices
{
enum class eDeviceType
{
Opl,
Opl = 0,
Mt32,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,18 @@ namespace HyperSonicDrivers::drivers

bool MIDDriver::resetBankOP2() noexcept
{
if (m_device->type == devices::eDeviceType::Opl)
switch (m_device->type)
{
using enum devices::eDeviceType;
case Opl:
m_midiDriver = std::make_unique<drivers::midi::scummvm::MidiDriver_ADLIB>(std::dynamic_pointer_cast<devices::Opl>(m_device));
}
else
{
// must be mt32 (TODO)
break;
case Mt32:
m_midiDriver = std::make_unique<drivers::midi::mt32::MT32Driver>(std::dynamic_pointer_cast<devices::MT32>(m_device));
break;
default:
utils::throwLogC<std::invalid_argument>(std::format("unknown device type {:d}", static_cast<int>(m_device->type)));
break;
}

return open_();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
#include <HyperSonicDrivers/audio/midi/MIDIEvent.hpp>
#include <HyperSonicDrivers/devices/IDevice.hpp>
#include <HyperSonicDrivers/audio/stubs/StubMixer.hpp>
#include <type_traits>

namespace HyperSonicDrivers::devices
{
class SpyDevice : public IDevice
template<class T>
class SpyDevice : public T
{
public:
SpyDevice(const std::shared_ptr<audio::IMixer>& mixer, const eDeviceType type) : IDevice(mixer, type) {};
SpyDevice() : IDevice(audio::make_mixer<audio::stubs::StubMixer>(), eDeviceType::Opl) {};
SpyDevice(const std::shared_ptr<audio::IMixer>& mixer) : T(mixer) {
static_assert(std::is_base_of_v<IDevice, T>);
};
SpyDevice() : T(audio::make_mixer<audio::stubs::StubMixer>()) {
static_assert(std::is_base_of_v<IDevice, T>);
};

bool init() noexcept override { return true; };
bool shutdown() noexcept override { return true; };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <gmock/gmock.h>
#include <HyperSonicDrivers/devices/IDevice.hpp>
#include <HyperSonicDrivers/devices/SpyDevice.hpp>
#include <HyperSonicDrivers/devices/Adlib.hpp>
#include <HyperSonicDrivers/drivers/MIDDriverMock.hpp>

namespace HyperSonicDrivers::devices
Expand All @@ -10,15 +11,15 @@ namespace HyperSonicDrivers::devices

TEST(IDevice, double_acquire)
{
auto device = std::make_shared<SpyDevice>();
auto device = std::make_shared<SpyDevice<Adlib>>();

MIDDriverMock middrv(device);
EXPECT_THROW(MIDDriverMock middrv2(device), std::runtime_error);
}

TEST(IDevice, acquire_release)
{
auto device = std::make_shared<SpyDevice>();
auto device = std::make_shared<SpyDevice<Adlib>>();

MIDDriverMock middrv(device);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <HyperSonicDrivers/audio/midi/types.hpp>
#include <HyperSonicDrivers/drivers/MIDDriver.hpp>
#include <HyperSonicDrivers/devices/SpyDevice.hpp>
#include <HyperSonicDrivers/devices/Adlib.hpp>
#include <HyperSonicDrivers/drivers/MIDDriverMock.hpp>
#include <HyperSonicDrivers/files/MIDFile.hpp>
#include <HyperSonicDrivers/utils/algorithms.hpp>
Expand All @@ -26,7 +27,7 @@ namespace HyperSonicDrivers::drivers

TEST(MIDDriver, SEQUENCE_NAME_META_EVENT)
{
auto device = std::make_shared<devices::SpyDevice>();
auto device = std::make_shared<devices::SpyDevice<devices::Adlib>>();

ILogger::instance->setLevel(ILogger::eLevel::Trace, ILogger::eCategory::Audio);

Expand Down Expand Up @@ -54,7 +55,7 @@ namespace HyperSonicDrivers::drivers

TEST(MIDDriver, force_stop_on_long_delta_time_delay)
{
auto device = std::make_shared<devices::SpyDevice>();
auto device = std::make_shared<devices::SpyDevice<devices::Adlib>>();
{

MIDIEvent e;
Expand Down Expand Up @@ -104,7 +105,7 @@ namespace HyperSonicDrivers::drivers
TEST(MIDDriver, getTempo)
{
auto mf = files::MIDFile("../fixtures/midifile_sample.mid");
auto device = std::make_shared<devices::SpyDevice>();
auto device = std::make_shared<devices::SpyDevice<devices::Adlib>>();
MIDDriverMock md(device);
EXPECT_EQ(md.getTempo(), 0);
EXPECT_FALSE(md.isTempoChanged());
Expand Down

0 comments on commit 4071287

Please sign in to comment.