Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ILogger level formatter #262

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
Loading