From 6688ff59aa7a6d5448c294d34aefa8f49143c393 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Wed, 25 Oct 2023 06:33:24 +0100 Subject: [PATCH] ILogger level formatter (#262) --- CMakeLists.txt | 2 +- .../src/std/ILoggerFormatter.hpp | 47 +++++++++++++++++++ .../test/std/CMakeLists.txt | 5 ++ .../test/std/ILoggerFormatterTest.cpp | 17 +++++++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 sdl2-hyper-sonic-drivers/src/std/ILoggerFormatter.hpp create mode 100644 sdl2-hyper-sonic-drivers/test/std/ILoggerFormatterTest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cf37b37..e85d7f4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/sdl2-hyper-sonic-drivers/src/std/ILoggerFormatter.hpp b/sdl2-hyper-sonic-drivers/src/std/ILoggerFormatter.hpp new file mode 100644 index 00000000..5bb54b81 --- /dev/null +++ b/sdl2-hyper-sonic-drivers/src/std/ILoggerFormatter.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include +#include +#include + +namespace std +{ + template<> + struct formatter : formatter + { + template + 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::format(str, fc); + } + }; +} diff --git a/sdl2-hyper-sonic-drivers/test/std/CMakeLists.txt b/sdl2-hyper-sonic-drivers/test/std/CMakeLists.txt index 799ae0bc..e29adebc 100644 --- a/sdl2-hyper-sonic-drivers/test/std/CMakeLists.txt +++ b/sdl2-hyper-sonic-drivers/test/std/CMakeLists.txt @@ -61,3 +61,8 @@ macro_test( FILES "eChannelGroupFormatterTest.cpp" ) +macro_test( + EXE TestIloggerFormatter + FILES "ILoggerFormatterTest.cpp" +) + diff --git a/sdl2-hyper-sonic-drivers/test/std/ILoggerFormatterTest.cpp b/sdl2-hyper-sonic-drivers/test/std/ILoggerFormatterTest.cpp new file mode 100644 index 00000000..82d53cbd --- /dev/null +++ b/sdl2-hyper-sonic-drivers/test/std/ILoggerFormatterTest.cpp @@ -0,0 +1,17 @@ +#include +#include +#include + +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(); +}