From 8cd0977a3688fa705c83867c57505a47b9269369 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 8 Jan 2023 16:34:43 +0000 Subject: Fix up all the static analyzer warnings --- test/Jamfile.jam | 23 +++++++++++++++++++++-- test/test-collection.cpp | 4 ++-- test/test-enumDetails.cpp | 11 +++++++---- test/test-geo.cpp | 16 +++++++++------- test/test-glContextBhvr.cpp | 34 +++++++++++++++++----------------- test/test-helpers.hpp | 21 --------------------- test/test-lib.cpp | 6 +++--- test/test-maths.cpp | 17 +++++++++++++---- test/test-network.cpp | 4 ++-- test/test-obj.cpp | 4 ++-- test/test-render.cpp | 26 +++++++++++++------------- test/test-text.cpp | 6 +++--- test/testHelpers.cpp | 16 ++++++++++++++++ test/testHelpers.h | 34 ++++++++++++++++++++++++++++++++++ test/testMainWindow.cpp | 13 +++++++------ test/testRenderOutput.cpp | 2 +- 16 files changed, 150 insertions(+), 87 deletions(-) delete mode 100644 test/test-helpers.hpp create mode 100644 test/testHelpers.cpp create mode 100644 test/testHelpers.h (limited to 'test') diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 72ec0e3..cefad7b 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -10,14 +10,33 @@ project : requirements BOOST_TEST_DYN_LINK RESDIR=\\\"$(res)/\\\" FIXTURESDIR=\\\"$(fixtures)/\\\" + debug:pedantic + debug:on + debug:-Wnon-virtual-dtor + debug:-Wcast-align + debug:-Wunused + debug:-Woverloaded-virtual + debug:-Wpedantic + debug:-Wconversion + debug:-Wsign-conversion + debug:-Wnull-dereference + debug:-Wdouble-promotion + debug:-Wformat=2 + gcc,debug:-Wold-style-cast + gcc,debug:-Wduplicated-cond + gcc,debug:-Wduplicated-branches + gcc,debug:-Wlogical-op + gcc,debug:-Wuseless-cast boost_unit_test_framework ..//ilt - tidy:hicpp-vararg tidy:accessMoved tidy:assertWithSideEffect + tidy:bugprone-macro-parentheses tidy:bugprone-use-after-move - tidy:hicpp-invalid-access-moved tidy:clang-analyzer-cplusplus.Move + tidy:clang-analyzer-security.FloatLoopCounter + tidy:hicpp-invalid-access-moved + tidy:hicpp-vararg tidy:boost ; lib test : [ glob *.cpp : test-*.cpp ] ; diff --git a/test/test-collection.cpp b/test/test-collection.cpp index f31b3a6..9884812 100644 --- a/test/test-collection.cpp +++ b/test/test-collection.cpp @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_CASE(wrapped_ptr_file_cons) { using FilePtr = wrapped_ptr; - FilePtr fp {fopen, "/dev/null", "r"}; + const FilePtr fp {fopen, "/dev/null", "r"}; BOOST_REQUIRE(fp); BOOST_CHECK_NO_THROW(fflush(fp)); @@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(wrapped_ptr_file_move) BOOST_AUTO_TEST_CASE(wrapped_ptr_file_typed) { using FilePtr = wrapped_ptrt; - FilePtr fp {"/dev/null", "r"}; + const FilePtr fp {"/dev/null", "r"}; BOOST_REQUIRE(fp); BOOST_CHECK_NO_THROW(fflush(fp)); } diff --git a/test/test-enumDetails.cpp b/test/test-enumDetails.cpp index c803cf8..db2d6d0 100644 --- a/test/test-enumDetails.cpp +++ b/test/test-enumDetails.cpp @@ -1,6 +1,7 @@ #define BOOST_TEST_MODULE test_enumDetails #include "enumDetailsData.hpp" +#include "testHelpers.h" #include #include #include @@ -32,14 +33,16 @@ constexpr std::array INVALID_VALUES {-1, 3, 20}; BOOST_DATA_TEST_CASE(valid_parse_##TYPE, VALID_NAMES ^ VALID_VALUES, in, out) \ { \ const auto v = EnumDetails::parse(in); \ - BOOST_REQUIRE(v.has_value()); \ - BOOST_CHECK_EQUAL(v.value(), out); \ + BOOST_CHECK_IF(vo, v.has_value()) { \ + BOOST_CHECK_EQUAL(v.value(), out); \ + } \ } \ BOOST_DATA_TEST_CASE(valid_to_string_##TYPE, VALID_VALUES ^ VALID_NAMES, in, out) \ { \ const auto v = EnumDetails::to_string(in); \ - BOOST_CHECK(v.has_value()); \ - BOOST_CHECK_EQUAL(v.value(), out); \ + BOOST_CHECK_IF(vo, v.has_value()) { \ + BOOST_CHECK_EQUAL(v.value(), out); \ + } \ } TESTS_FOR_TYPE(GlobalScoped) diff --git a/test/test-geo.cpp b/test/test-geo.cpp index 7f072bc..bc442e9 100644 --- a/test/test-geo.cpp +++ b/test/test-geo.cpp @@ -1,6 +1,6 @@ #define BOOST_TEST_MODULE test_geo -#include "test-helpers.hpp" +#include "testHelpers.h" #include #include #include @@ -169,8 +169,9 @@ BOOST_DATA_TEST_CASE(intersect_ray, nodes[at(1, 1)].height = 4; const auto intersect = intersectRay({start, glm::normalize(dir)}); - BOOST_REQUIRE(intersect); - BOOST_CHECK_CLOSE_VEC(*intersect, pos); + BOOST_CHECK_IF(has_intersect, intersect) { + BOOST_CHECK_CLOSE_VEC(*intersect, pos); + } } auto xs = boost::unit_test::data::xrange(-20.F, 0.F, 0.6F), ys = boost::unit_test::data::xrange(-20.F, 0.F, 0.7F); @@ -185,13 +186,14 @@ BOOST_DATA_TEST_CASE(intersect_ray_many, xs * ys * targetsx * targetsy, x, y, ta nodes[at(0, 1)].height = 3; nodes[at(1, 1)].height = 4; - glm::vec3 start {x, y, 10}; + const glm::vec3 start {x, y, 10}; const auto target {this->positionAt({targetx, targety})}; - Ray ray {start, glm::normalize(target - start)}; + const Ray ray {start, glm::normalize(target - start)}; BOOST_TEST_CONTEXT(ray) { const auto intersect = intersectRay(ray); - BOOST_REQUIRE(intersect); - BOOST_CHECK_CLOSE_VEC(*intersect, target); + BOOST_CHECK_IF(has_intersect, intersect) { + BOOST_CHECK_CLOSE_VEC(*intersect, target); + } } } diff --git a/test/test-glContextBhvr.cpp b/test/test-glContextBhvr.cpp index b37a072..9716f54 100644 --- a/test/test-glContextBhvr.cpp +++ b/test/test-glContextBhvr.cpp @@ -1,6 +1,6 @@ #define BOOST_TEST_MODULE test_glcontextbehaviour -#include "test-helpers.hpp" +#include "testHelpers.h" #include #include @@ -10,23 +10,23 @@ BOOST_GLOBAL_FIXTURE(ApplicationBase); -#define TEST_WINDOW_PARAMS __FILE__, 0, 0, 640, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN +#define TEST_WINDOW_PARAMS __FILE__, 0, 0, 640, 480, static_cast(SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN) static void CreateProgramTest() { - ProgramRef p; + const ProgramRef p; BOOST_REQUIRE(p); } BOOST_AUTO_TEST_CASE(windowContextThingsBehaviour1) { BOOST_REQUIRE(!glCreateProgram); // Init not called yet { - SDL_WindowPtr window {TEST_WINDOW_PARAMS}; + const SDL_WindowPtr window {TEST_WINDOW_PARAMS}; BOOST_REQUIRE(window); BOOST_REQUIRE(!glCreateProgram); BOOST_REQUIRE_NE(glewInit(), GLEW_OK); // No context yet { - SDL_GLContextPtr context {window}; + const SDL_GLContextPtr context {window}; BOOST_REQUIRE(context); BOOST_REQUIRE(!glCreateProgram); BOOST_REQUIRE_EQUAL(glewInit(), GLEW_OK); @@ -34,17 +34,17 @@ BOOST_AUTO_TEST_CASE(windowContextThingsBehaviour1) CreateProgramTest(); } // Context destroyed BOOST_REQUIRE(glCreateProgram); // Functions still set - BOOST_REQUIRE_THROW({ ProgramRef p; }, std::exception); // Get fails with no context + BOOST_REQUIRE_THROW({ const ProgramRef p; }, std::exception); // Get fails with no context { - SDL_GLContextPtr context {window}; + const SDL_GLContextPtr context {window}; BOOST_REQUIRE(context); CreateProgramTest(); } } { - SDL_WindowPtr window {TEST_WINDOW_PARAMS}; + const SDL_WindowPtr window {TEST_WINDOW_PARAMS}; BOOST_REQUIRE(window); - SDL_GLContextPtr context {window}; + const SDL_GLContextPtr context {window}; BOOST_REQUIRE(context); CreateProgramTest(); } @@ -52,31 +52,31 @@ BOOST_AUTO_TEST_CASE(windowContextThingsBehaviour1) BOOST_AUTO_TEST_CASE(windowContextThingsBehaviour2) { - SDL_WindowPtr window1 {TEST_WINDOW_PARAMS}; + const SDL_WindowPtr window1 {TEST_WINDOW_PARAMS}; BOOST_REQUIRE(window1); { - SDL_WindowPtr window2 {TEST_WINDOW_PARAMS}; + const SDL_WindowPtr window2 {TEST_WINDOW_PARAMS}; BOOST_REQUIRE(window2); - SDL_GLContextPtr context {window2}; + const SDL_GLContextPtr context {window2}; BOOST_REQUIRE(context); CreateProgramTest(); } - BOOST_REQUIRE_THROW({ ProgramRef p; }, std::exception); // Get fails with no context + BOOST_REQUIRE_THROW({ const ProgramRef p; }, std::exception); // Get fails with no context } BOOST_AUTO_TEST_CASE(windowContextThingsBehaviour3) { std::optional window1 {std::in_place, TEST_WINDOW_PARAMS}; - std::optional window2 {std::in_place, TEST_WINDOW_PARAMS}; + const std::optional window2 {std::in_place, TEST_WINDOW_PARAMS}; BOOST_REQUIRE(window1); BOOST_REQUIRE(window1.value()); - SDL_GLContextPtr context {window1.value()}; + const SDL_GLContextPtr context {window1.value()}; BOOST_REQUIRE(context); CreateProgramTest(); window1.reset(); - BOOST_REQUIRE_THROW({ ProgramRef p; }, std::exception); // Get fails with context's window gone + BOOST_REQUIRE_THROW({ const ProgramRef p; }, std::exception); // Get fails with context's window gone window1.emplace(TEST_WINDOW_PARAMS); BOOST_REQUIRE(window1); BOOST_REQUIRE(window1.value()); - BOOST_REQUIRE_THROW({ ProgramRef p; }, std::exception); // Get still fails with context's window gone + BOOST_REQUIRE_THROW({ const ProgramRef p; }, std::exception); // Get still fails with context's window gone } diff --git a/test/test-helpers.hpp b/test/test-helpers.hpp deleted file mode 100644 index 5ebbea9..0000000 --- a/test/test-helpers.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include -#include - -#define BOOST_CHECK_CLOSE_VEC(a_, b_) \ - { \ - const auto a {a_}, b {b_}; \ - BOOST_TEST_CONTEXT("BOOST_CHECK_CLOSE_VEC(" << a << ", " << b << ")") { \ - BOOST_CHECK_LT(glm::length(a - b), 0.1F); \ - } \ - } - -#define BOOST_CHECK_BETWEEN(a_, b_, c_) \ - { \ - const auto a {a_}, b {b_}, c {c_}; \ - BOOST_TEST_CONTEXT("BOOST_CHECK_BETWEEN(" << a << ", " << b << ", " << c << ")") { \ - BOOST_CHECK_LE(b, a); \ - BOOST_CHECK_GE(c, a); \ - } \ - } diff --git a/test/test-lib.cpp b/test/test-lib.cpp index e464f2f..73ed53a 100644 --- a/test/test-lib.cpp +++ b/test/test-lib.cpp @@ -1,6 +1,6 @@ #define BOOST_TEST_MODULE test_lib -#include "test-helpers.hpp" +#include "testHelpers.h" #include #include @@ -33,7 +33,7 @@ using TestArray = glArrays<5, &generator, &deleter>; BOOST_AUTO_TEST_CASE(generate_and_delete) { { - TestArray a; + const TestArray a; } BOOST_CHECK(active.empty()); } @@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(generate_move_and_delete) { TestArray a; BOOST_CHECK_EQUAL(TestArray::size, active.size()); - TestArray b {std::move(a)}; + const TestArray b {std::move(a)}; BOOST_CHECK_EQUAL(TestArray::size, active.size()); } BOOST_CHECK(active.empty()); diff --git a/test/test-maths.cpp b/test/test-maths.cpp index d6c0fc1..6ee2113 100644 --- a/test/test-maths.cpp +++ b/test/test-maths.cpp @@ -1,6 +1,6 @@ #define BOOST_TEST_MODULE test_maths -#include "test-helpers.hpp" +#include "testHelpers.h" #include #include #include @@ -187,7 +187,7 @@ BOOST_DATA_TEST_CASE(straight1, }), v, angFor, angBack) { - TestLinkStraight l(v); + const TestLinkStraight l(v); { const auto p = l.positionAt(0, 0); BOOST_CHECK_EQUAL(p.pos, origin); @@ -220,7 +220,7 @@ BOOST_DATA_TEST_CASE(curve1, e1, ctr, angFor, angBack) { { // One-way... - TestLinkCurve l(origin, e1, ctr); + const TestLinkCurve l(origin, e1, ctr); BOOST_CHECK_EQUAL(l.radius, 1.F); { const auto p = l.positionAt(0, 0); @@ -235,7 +235,7 @@ BOOST_DATA_TEST_CASE(curve1, } { // The other way... - TestLinkCurve l(e1, origin, ctr); + const TestLinkCurve l(e1, origin, ctr); BOOST_CHECK_EQUAL(l.radius, 1.F); { const auto p = l.positionAt(0, 0); @@ -307,6 +307,15 @@ BOOST_DATA_TEST_CASE(rayLineDistance, n_test_points_between(), // cz i1, n1x, i2, n1y, i3, n1z, i4, n2x, i5, n2y, i6, n2z, i7, cx, i8, cy, i9, cz) { + (void)i1; + (void)i2; + (void)i3; + (void)i4; + (void)i5; + (void)i6; + (void)i7; + (void)i8; + (void)i9; const glm::vec3 n1 {n1x, n1y, n1z}, n2 {n2x, n2y, n2z}, c {cx, cy, cz}; const auto nstep = n2 - n1; diff --git a/test/test-network.cpp b/test/test-network.cpp index dc2b52f..19c0977 100644 --- a/test/test-network.cpp +++ b/test/test-network.cpp @@ -1,6 +1,6 @@ #define BOOST_TEST_MODULE network -#include "test-helpers.hpp" +#include "testHelpers.h" #include #include @@ -19,7 +19,7 @@ #include struct TestLink : public LinkStraight { - TestLink(Node::Ptr a, Node::Ptr b) : TestLink {a, b, (a->pos - b->pos)} { } + TestLink(const Node::Ptr & a, const Node::Ptr & b) : TestLink {a, b, (a->pos - b->pos)} { } TestLink(Node::Ptr a, Node::Ptr b, glm::vec2 l) : Link {{std::move(a), 0}, {std::move(b), pi}, glm::length(l)} { } TestLink(Node::Ptr a, Node::Ptr b, float l) : Link {{std::move(a), 0}, {std::move(b), pi}, l} { } using StraightLink = TestLink; diff --git a/test/test-obj.cpp b/test/test-obj.cpp index c7bd6ce..e6e725d 100644 --- a/test/test-obj.cpp +++ b/test/test-obj.cpp @@ -12,7 +12,7 @@ BOOST_AUTO_TEST_CASE(objparse) { - ObjParser op {RESDIR "/brush47.obj"}; + const ObjParser op {RESDIR "/brush47.obj"}; BOOST_CHECK_EQUAL(75, op.vertices.size()); BOOST_CHECK_EQUAL(112, op.texCoords.size()); BOOST_CHECK_EQUAL(31, op.normals.size()); @@ -27,7 +27,7 @@ BOOST_AUTO_TEST_CASE(objparse) BOOST_AUTO_TEST_CASE(create_meshes) { - ObjParser op {RESDIR "/brush47.obj"}; + const ObjParser op {RESDIR "/brush47.obj"}; const auto ms = op.createMeshData(); BOOST_REQUIRE_EQUAL(3, ms.size()); BOOST_REQUIRE_EQUAL("Body", ms.begin()->first); diff --git a/test/test-render.cpp b/test/test-render.cpp index 09aa9fb..7db847d 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -1,6 +1,6 @@ #define BOOST_TEST_MODULE test_render -#include "test-helpers.hpp" +#include "testHelpers.h" #include "testMainWindow.h" #include "testRenderOutput.h" #include @@ -26,18 +26,18 @@ class TestScene : public SceneProvider { return gd; }()}; void - content(const SceneShader & shader) const + content(const SceneShader & shader) const override { terrain.render(shader); train.render(shader, Location {{52, 50, 2}}, {Location {}, Location {}}); train.render(shader, Location {{52, 30, 2}}, {Location {}, Location {}}); } void - lights(const SceneShader &) const + lights(const SceneShader &) const override { } void - shadows(const ShadowMapper & shadowMapper) const + shadows(const ShadowMapper & shadowMapper) const override { terrain.shadows(shadowMapper); train.shadows(shadowMapper, Location {{52, 50, 2}}); @@ -54,7 +54,7 @@ BOOST_DATA_TEST_CASE(cam, dist, near, far) { static constexpr glm::vec4 pos {-10, -10, 60, 0}; - Camera cam {pos, half_pi, 1.f, near, far}; + const Camera cam {pos, half_pi, 1.F, near, far}; const auto e = cam.extentsAtDist(dist); @@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(basic) { SceneRenderer ss {size, output}; ss.camera.setView({-10, -10, 60}, glm::normalize(glm::vec3 {1, 1, -0.5F})); - TestScene scene; + const TestScene scene; ss.render(scene); glDisable(GL_DEBUG_OUTPUT); Texture::save(outImage, size, "/tmp/basic.tga"); @@ -93,12 +93,12 @@ BOOST_AUTO_TEST_CASE(pointlight) { for (int x = 50; x < 100; x += 20) { for (int y = 50; y < 2000; y += 20) { - shader.pointLight.add({x, y, 4}, {1.0, 1.0, 1.0}, 0.1); + shader.pointLight.add({x, y, 4}, {1.0, 1.0, 1.0}, 0.1F); } } } }; - PointLightScene scene; + const PointLightScene scene; ss.render(scene); glDisable(GL_DEBUG_OUTPUT); Texture::save(outImage, size, "/tmp/pointlight.tga"); @@ -119,13 +119,13 @@ BOOST_AUTO_TEST_CASE(spotlight) void lights(const SceneShader & shader) const override { - shader.spotLight.add({50, 50, 15}, down, {1.0, 1.0, 1.0}, 0.01, 1); - shader.spotLight.add({51, 59.5, 1}, north, {1.0, 1.0, 1.0}, 0.001, .5); - shader.spotLight.add({53, 59.5, 1}, north, {1.0, 1.0, 1.0}, 0.001, .5); - shader.spotLight.add({60, 50, 3}, north + east, {1.0, 1.0, 1.0}, 0.0001, .7); + shader.spotLight.add({50, 50, 15}, down, {1.0, 1.0, 1.0}, 0.01F, 1); + shader.spotLight.add({51, 59.5, 1}, north, {1.0, 1.0, 1.0}, 0.001F, .5); + shader.spotLight.add({53, 59.5, 1}, north, {1.0, 1.0, 1.0}, 0.001F, .5); + shader.spotLight.add({60, 50, 3}, north + east, {1.0, 1.0, 1.0}, 0.0001F, .7F); } }; - PointLightScene scene; + const PointLightScene scene; ss.render(scene); glDisable(GL_DEBUG_OUTPUT); Texture::save(outImage, size, "/tmp/spotlight.tga"); diff --git a/test/test-text.cpp b/test/test-text.cpp index 0df6885..0c73021 100644 --- a/test/test-text.cpp +++ b/test/test-text.cpp @@ -1,6 +1,6 @@ #define BOOST_TEST_MODULE test_text -#include "test-helpers.hpp" +#include "testHelpers.h" #include #include #include @@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE(initialize_chardata) BOOST_CHECK_EQUAL(fontTextures.size(), 2); } -using CharDataTest = std::tuple; +using CharDataTest = std::tuple; BOOST_DATA_TEST_CASE(initialize_chardata_A, boost::unit_test::data::make({ {'A', {0, {34, 35}, {627, 0}, {-1, 35}, 32}}, @@ -82,7 +82,7 @@ static_assert(glm::vec2 {866, 35} / glm::vec2 {2048, 64} == glm::vec2 {0.4228515 BOOST_AUTO_TEST_CASE(render_text) { constexpr std::string_view text {"I Like Trains"}; - const auto spaces = std::count_if(text.begin(), text.end(), isspace); + const auto spaces = static_cast(std::count_if(text.begin(), text.end(), isspace)); const auto tqs = render(text); BOOST_REQUIRE_EQUAL(tqs.size(), 1); const auto & t1 = tqs.begin(); diff --git a/test/testHelpers.cpp b/test/testHelpers.cpp new file mode 100644 index 0000000..c69e5f3 --- /dev/null +++ b/test/testHelpers.cpp @@ -0,0 +1,16 @@ +#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 new file mode 100644 index 0000000..54b7fc6 --- /dev/null +++ b/test/testHelpers.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include +#include + +std::unique_ptr uasprintf(const char * fmt, ...) __attribute__((format(printf, 1, 2))); + +#define BOOST_CHECK_CLOSE_VEC(a_, b_) \ + { \ + const auto a {a_}, b {b_}; \ + BOOST_TEST_CONTEXT("BOOST_CHECK_CLOSE_VEC(" << a << ", " << b << ")") { \ + BOOST_CHECK_LT(glm::length(a - b), 0.1F); \ + } \ + } + +#define BOOST_CHECK_BETWEEN(a_, b_, c_) \ + { \ + const auto a {a_}, b {b_}, c {c_}; \ + BOOST_TEST_CONTEXT("BOOST_CHECK_BETWEEN(" << a << ", " << b << ", " << c << ")") { \ + BOOST_CHECK_LE(b, a); \ + BOOST_CHECK_GE(c, a); \ + } \ + } +#define BOOST_REQUIRE_THEN(VAR, EXPR) \ + if (const auto VAR = (EXPR); !(VAR)) { \ + BOOST_REQUIRE(VAR); \ + } \ + else +#define BOOST_CHECK_IF(VAR, EXPR) \ + if (const auto VAR = (EXPR); !(VAR)) { \ + BOOST_CHECK(VAR); \ + } \ + else diff --git a/test/testMainWindow.cpp b/test/testMainWindow.cpp index 66e8832..49e18f1 100644 --- a/test/testMainWindow.cpp +++ b/test/testMainWindow.cpp @@ -1,14 +1,14 @@ #include "testMainWindow.h" +#include "testHelpers.h" #include TestMainWindow::TestMainWindow() : Window {1, 1, __FILE__, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN} { glEnable(GL_DEBUG_OUTPUT); glDebugMessageCallback( - [](GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar * message, - const void *) { - char buf[BUFSIZ]; - snprintf(buf, BUFSIZ, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s", + [](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", (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, message); switch (type) { case GL_DEBUG_TYPE_ERROR: @@ -16,9 +16,10 @@ TestMainWindow::TestMainWindow() : Window {1, 1, __FILE__, SDL_WINDOW_OPENGL | S case GL_DEBUG_TYPE_PORTABILITY: case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: - BOOST_TEST_ERROR(buf); + BOOST_TEST_ERROR(msg.get()); + default: + BOOST_TEST_MESSAGE(msg.get()); } - BOOST_TEST_MESSAGE(buf); }, nullptr); } diff --git a/test/testRenderOutput.cpp b/test/testRenderOutput.cpp index 7a96e96..2a94a1b 100644 --- a/test/testRenderOutput.cpp +++ b/test/testRenderOutput.cpp @@ -7,7 +7,7 @@ TestRenderOutput::TestRenderOutput() : size {640, 480} const auto configuregdata = [this](const GLuint data, const GLint format, const GLenum type, const GLenum attachment) { glBindTexture(GL_TEXTURE_2D, data); - glTexImage2D(GL_TEXTURE_2D, 0, format, size.x, size.y, 0, GL_RGBA, type, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, format, size.x, size.y, 0, GL_RGBA, type, nullptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, data, 0); -- cgit v1.2.3