Skip to content

Commit

Permalink
IDeviceTypesFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffaello committed Oct 31, 2023
1 parent 5515e03 commit b24bbdd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
38 changes: 38 additions & 0 deletions sdl2-hyper-sonic-drivers/src/std/IDeviceTypesFormatter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include <string>
#include <format>
#include <HyperSonicDrivers/devices/types.hpp>

namespace std
{
template<>
struct formatter<HyperSonicDrivers::devices::eDeviceName> : formatter<string_view>
{
template<typename FormatContext>
auto format(HyperSonicDrivers::devices::eDeviceName device_name, FormatContext& fc) const
{
string str;

switch (device_name)
{
using enum HyperSonicDrivers::devices::eDeviceName;

case Adlib:
str = "Adlib";
break;
case SbPro:
str = "SbPro";
break;
case SbPro2:
str = "SbPro2";
break;
case MT32:
str = "MT32";
break;
}

return formatter<std::string_view>::format(str, fc);
}
};
}
4 changes: 4 additions & 0 deletions sdl2-hyper-sonic-drivers/test/std/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ macro_test(
FILES "ILoggerFormatterTest.cpp"
)

macro_test(
EXE TestIDeviceFormatter
FILES "IDeviceTypesFormatterTest.cpp"
)
17 changes: 17 additions & 0 deletions sdl2-hyper-sonic-drivers/test/std/IDeviceTypesFormatterTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <std/IDeviceTypesFormatter.hpp>

namespace std
{
TEST(IDeviceTypesFormatter, Music)
{
ASSERT_STRCASEEQ(std::format("{}", HyperSonicDrivers::devices::eDeviceName::Adlib).c_str(), "Adlib");
}
}

int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit b24bbdd

Please sign in to comment.