From 2c87aa33dfde23920d1dccd04c472c8884118b90 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 4 Jun 2024 18:01:10 +0100 Subject: Replace messy uasprintf with std::format --- test/testHelpers.cpp | 16 ---------------- test/testHelpers.h | 3 --- test/testMainWindow.cpp | 10 +++++----- 3 files changed, 5 insertions(+), 24 deletions(-) delete mode 100644 test/testHelpers.cpp diff --git a/test/testHelpers.cpp b/test/testHelpers.cpp deleted file mode 100644 index c69e5f3..0000000 --- a/test/testHelpers.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "testHelpers.h" -#include - -std::unique_ptr -uasprintf(const char * fmt, ...) -{ - char * buf {}; - va_list args; - va_start(args, fmt); - if (vasprintf(&buf, fmt, args) < 0) { - va_end(args); - return {nullptr, &free}; - } - va_end(args); - return std::unique_ptr {buf, &free}; -} diff --git a/test/testHelpers.h b/test/testHelpers.h index 58e4372..c9fd6dc 100644 --- a/test/testHelpers.h +++ b/test/testHelpers.h @@ -6,9 +6,6 @@ #include #include // IWYU pragma: keep std::setprecision #include -#include - -std::unique_ptr uasprintf(const char * fmt, ...) __attribute__((format(printf, 1, 2))); template decltype(auto) diff --git a/test/testMainWindow.cpp b/test/testMainWindow.cpp index 57e3473..d0b674c 100644 --- a/test/testMainWindow.cpp +++ b/test/testMainWindow.cpp @@ -1,6 +1,6 @@ #include "testMainWindow.h" -#include "testHelpers.h" #include +#include TestMainWindow::TestMainWindow() : Window {1, 1, __FILE__, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN} { @@ -8,18 +8,18 @@ TestMainWindow::TestMainWindow() : Window {1, 1, __FILE__, SDL_WINDOW_OPENGL | S glDebugMessageCallback( [](GLenum /*source*/, GLenum type, GLuint /*id*/, GLenum severity, GLsizei /*length*/, const GLchar * message, const void *) { - const auto msg = uasprintf("GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s", + const auto msg = std::format("GL CALLBACK: {} type = 0x{:x}, severity = 0x{:x}, message = {}", (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, message); switch (type) { case GL_DEBUG_TYPE_ERROR: case GL_DEBUG_TYPE_PORTABILITY: case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: - BOOST_TEST_ERROR(msg.get()); + BOOST_TEST_ERROR(msg); case GL_DEBUG_TYPE_PERFORMANCE: - BOOST_TEST_WARN(msg.get()); + BOOST_TEST_WARN(msg.c_str()); default: - BOOST_TEST_MESSAGE(msg.get()); + BOOST_TEST_MESSAGE(msg); } }, nullptr); -- cgit v1.2.3