Skip to content

Commit

Permalink
ILogger level formatter (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffaello authored Oct 25, 2023
1 parent 8270aa2 commit 6688ff5
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
endif()


project ("sdl2-hyper-sonic-drivers" VERSION 0.12.2 DESCRIPTION "SDL2 based Hyper-Sonic Drivers for emulating old soundcards")
project ("sdl2-hyper-sonic-drivers" VERSION 0.12.3 DESCRIPTION "SDL2 based Hyper-Sonic Drivers for emulating old soundcards")
include (TestBigEndian)
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
if(IS_BIG_ENDIAN)
Expand Down
47 changes: 47 additions & 0 deletions sdl2-hyper-sonic-drivers/src/std/ILoggerFormatter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include <string>
#include <format>
#include <HyperSonicDrivers/utils/ILogger.hpp>

namespace std
{
template<>
struct formatter<HyperSonicDrivers::utils::ILogger::eLevel> : formatter<string_view>
{
template<typename FormatContext>
auto format(HyperSonicDrivers::utils::ILogger::eLevel level, FormatContext& fc) const
{
string str;

switch (level)
{
using enum HyperSonicDrivers::utils::ILogger::eLevel;

case Trace:
str = "Trace";
break;
case Debug:
str = "Debug";
break;
case Info:
str = "Info";
break;
case Warning:
str = "Warning";
break;
case Error:
str = "Error";
break;
case Critical:
str = "Critical";
break;
case Off:
str = "Off";
break;
}

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

macro_test(
EXE TestIloggerFormatter
FILES "ILoggerFormatterTest.cpp"
)

17 changes: 17 additions & 0 deletions sdl2-hyper-sonic-drivers/test/std/ILoggerFormatterTest.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/ILoggerFormatter.hpp>

namespace std
{
TEST(ILoggerFormatter, Music)
{
ASSERT_STRCASEEQ(std::format("{}", HyperSonicDrivers::utils::ILogger::eLevel::Critical).c_str(), "Critical");
}
}

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

0 comments on commit 6688ff5

Please sign in to comment.