From 6895daa6766b9b4c466ff0d2d5dd5018583bd81a Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Wed, 9 Sep 2026 00:05:05 +0200 Subject: [PATCH] VulkanFormatters --- .../GraphicsVulkan/VulkanFormatters.hpp | 51 ++++++++++++++ .../GraphicsVulkan/VulkanFormatters.cpp | 67 +++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 Bigfoot/Libs/Graphics/GraphicsVulkan/Include/GraphicsVulkan/VulkanFormatters.hpp create mode 100644 Bigfoot/Tests/Graphics/GraphicsVulkan/VulkanFormatters.cpp diff --git a/Bigfoot/Libs/Graphics/GraphicsVulkan/Include/GraphicsVulkan/VulkanFormatters.hpp b/Bigfoot/Libs/Graphics/GraphicsVulkan/Include/GraphicsVulkan/VulkanFormatters.hpp new file mode 100644 index 0000000..198b201 --- /dev/null +++ b/Bigfoot/Libs/Graphics/GraphicsVulkan/Include/GraphicsVulkan/VulkanFormatters.hpp @@ -0,0 +1,51 @@ +/********************************************************************* + * \file VulkanFormatters.hpp + * + * \author Romain BOULLARD + * \date September 2026 + *********************************************************************/ +#ifndef BIGFOOT_GRAPHICSVULKAN_VULKANFORMATTERS_HPP +#define BIGFOOT_GRAPHICSVULKAN_VULKANFORMATTERS_HPP +#include + +#include + +#include + +template<> +struct fmt::formatter +{ + static constexpr auto parse(format_parse_context& ctx) + { + return ctx.begin(); + } + + static auto format(const vk::Result p_result, format_context& ctx) + { + return fmt::format_to(ctx.out(), "{}", vk::to_string(p_result)); + } +}; + +#ifdef BIGFOOT_NOT_OPTIMIZED +#include + +template<> +struct fmtquill::formatter +{ + static constexpr auto parse(format_parse_context& ctx) + { + return ctx.begin(); + } + + static auto format(const vk::Result p_result, format_context& ctx) + { + return fmtquill::format_to(ctx.out(), "{}", vk::to_string(p_result)); + } +}; + +template<> +struct quill::Codec: quill::DeferredFormatCodec +{ +}; +#endif +#endif diff --git a/Bigfoot/Tests/Graphics/GraphicsVulkan/VulkanFormatters.cpp b/Bigfoot/Tests/Graphics/GraphicsVulkan/VulkanFormatters.cpp new file mode 100644 index 0000000..465616c --- /dev/null +++ b/Bigfoot/Tests/Graphics/GraphicsVulkan/VulkanFormatters.cpp @@ -0,0 +1,67 @@ +/********************************************************************* + * \file VulkanFormatters.cpp + * + * \author Romain BOULLARD + * \date September 2026 + *********************************************************************/ +#include + +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include + +namespace Bigfoot::Vulkan +{ +class VulkanFormattersFixture: public ::testing::Test +{ +}; + +/****************************************************************************************/ + +TEST_F(VulkanFormattersFixture, FormatsASuccessResultAsItsToString) +{ + EXPECT_EQ(fmt::format("{}", vk::Result::eSuccess), vk::to_string(vk::Result::eSuccess)); +} + +/****************************************************************************************/ + +TEST_F(VulkanFormattersFixture, FormatsAnErrorResultAsItsToString) +{ + EXPECT_EQ(fmt::format("{}", vk::Result::eErrorDeviceLost), vk::to_string(vk::Result::eErrorDeviceLost)); +} + +/****************************************************************************************/ + +#ifdef BIGFOOT_NOT_OPTIMIZED +class VulkanFormattersLogFixture: public ::testing::Test +{ + protected: + static std::string ReadFileSinkContent() + { + Singleton::GetInstance().Flush(); + + std::ifstream file {std::string {Log::FILE_SINK_PATH.data()}}; + std::stringstream buffer; + buffer << file.rdbuf(); + return buffer.str(); + } +}; + +/****************************************************************************************/ + +TEST_F(VulkanFormattersLogFixture, LogsAResultArgumentAsItsToString) +{ + BIGFOOT_LOG_INFO(GRAPHICSVULKAN_LOGGER, "{}", vk::Result::eErrorOutOfHostMemory); + EXPECT_THAT(ReadFileSinkContent(), ::testing::HasSubstr(vk::to_string(vk::Result::eErrorOutOfHostMemory))); +} +#endif +} // namespace Bigfoot::Vulkan