VulkanFormatters
This commit is contained in:
@@ -0,0 +1,51 @@
|
|||||||
|
/*********************************************************************
|
||||||
|
* \file VulkanFormatters.hpp
|
||||||
|
*
|
||||||
|
* \author Romain BOULLARD
|
||||||
|
* \date September 2026
|
||||||
|
*********************************************************************/
|
||||||
|
#ifndef BIGFOOT_GRAPHICSVULKAN_VULKANFORMATTERS_HPP
|
||||||
|
#define BIGFOOT_GRAPHICSVULKAN_VULKANFORMATTERS_HPP
|
||||||
|
#include <GraphicsVulkan/VulkanInclude.hpp>
|
||||||
|
|
||||||
|
#include <Utils/TargetMacros.h>
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct fmt::formatter<vk::Result>
|
||||||
|
{
|
||||||
|
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 <quill/DeferredFormatCodec.h>
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct fmtquill::formatter<vk::Result>
|
||||||
|
{
|
||||||
|
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<vk::Result>: quill::DeferredFormatCodec<vk::Result>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/*********************************************************************
|
||||||
|
* \file VulkanFormatters.cpp
|
||||||
|
*
|
||||||
|
* \author Romain BOULLARD
|
||||||
|
* \date September 2026
|
||||||
|
*********************************************************************/
|
||||||
|
#include <GraphicsVulkan/VulkanFormatters.hpp>
|
||||||
|
|
||||||
|
#include <Utils/Log/LogMacros.hpp>
|
||||||
|
#include <Utils/Singleton.hpp>
|
||||||
|
|
||||||
|
#include <GraphicsVulkan/GraphicsVulkanLogger_generated.hpp>
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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<Log>::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
|
||||||
Reference in New Issue
Block a user