summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-01-08 16:34:43 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-01-08 16:34:43 +0000
commit8cd0977a3688fa705c83867c57505a47b9269369 (patch)
treeb7b48711051299607077ed31fdf3b3f6dd6cc41f /test
parentTidy shadow map creation (diff)
downloadilt-8cd0977a3688fa705c83867c57505a47b9269369.tar.bz2
ilt-8cd0977a3688fa705c83867c57505a47b9269369.tar.xz
ilt-8cd0977a3688fa705c83867c57505a47b9269369.zip
Fix up all the static analyzer warnings
Diffstat (limited to 'test')
-rw-r--r--test/Jamfile.jam23
-rw-r--r--test/test-collection.cpp4
-rw-r--r--test/test-enumDetails.cpp11
-rw-r--r--test/test-geo.cpp16
-rw-r--r--test/test-glContextBhvr.cpp34
-rw-r--r--test/test-lib.cpp6
-rw-r--r--test/test-maths.cpp17
-rw-r--r--test/test-network.cpp4
-rw-r--r--test/test-obj.cpp4
-rw-r--r--test/test-render.cpp26
-rw-r--r--test/test-text.cpp6
-rw-r--r--test/testHelpers.cpp16
-rw-r--r--test/testHelpers.h (renamed from test/test-helpers.hpp)13
-rw-r--r--test/testMainWindow.cpp13
-rw-r--r--test/testRenderOutput.cpp2
15 files changed, 129 insertions, 66 deletions
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
<define>BOOST_TEST_DYN_LINK
<define>RESDIR=\\\"$(res)/\\\"
<define>FIXTURESDIR=\\\"$(fixtures)/\\\"
+ <variant>debug:<warnings>pedantic
+ <variant>debug:<warnings-as-errors>on
+ <variant>debug:<cflags>-Wnon-virtual-dtor
+ <variant>debug:<cflags>-Wcast-align
+ <variant>debug:<cflags>-Wunused
+ <variant>debug:<cflags>-Woverloaded-virtual
+ <variant>debug:<cflags>-Wpedantic
+ <variant>debug:<cflags>-Wconversion
+ <variant>debug:<cflags>-Wsign-conversion
+ <variant>debug:<cflags>-Wnull-dereference
+ <variant>debug:<cflags>-Wdouble-promotion
+ <variant>debug:<cflags>-Wformat=2
+ <toolset>gcc,<variant>debug:<cflags>-Wold-style-cast
+ <toolset>gcc,<variant>debug:<cflags>-Wduplicated-cond
+ <toolset>gcc,<variant>debug:<cflags>-Wduplicated-branches
+ <toolset>gcc,<variant>debug:<cflags>-Wlogical-op
+ <toolset>gcc,<variant>debug:<cflags>-Wuseless-cast
<library>boost_unit_test_framework
<library>..//ilt
- <toolset>tidy:<xcheckxx>hicpp-vararg
<toolset>tidy:<suppress>accessMoved
<toolset>tidy:<suppress>assertWithSideEffect
+ <toolset>tidy:<xcheckxx>bugprone-macro-parentheses
<toolset>tidy:<xcheckxx>bugprone-use-after-move
- <toolset>tidy:<xcheckxx>hicpp-invalid-access-moved
<toolset>tidy:<xcheckxx>clang-analyzer-cplusplus.Move
+ <toolset>tidy:<xcheckxx>clang-analyzer-security.FloatLoopCounter
+ <toolset>tidy:<xcheckxx>hicpp-invalid-access-moved
+ <toolset>tidy:<xcheckxx>hicpp-vararg
<toolset>tidy:<librarydef>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<FILE, &fclose>;
- 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<FILE, &fopen, &fclose>;
- 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 <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
#include <enumDetails.hpp>
@@ -32,14 +33,16 @@ constexpr std::array INVALID_VALUES {-1, 3, 20};
BOOST_DATA_TEST_CASE(valid_parse_##TYPE, VALID_NAMES ^ VALID_VALUES<TYPE>, in, out) \
{ \
const auto v = EnumDetails<TYPE>::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<TYPE> ^ VALID_NAMES, in, out) \
{ \
const auto v = EnumDetails<TYPE>::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 <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
#include <stream_support.hpp>
@@ -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 <boost/test/unit_test.hpp>
#include <gfx/gl/sceneRenderer.h>
@@ -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<Uint32>(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<SDL_WindowPtr> window1 {std::in_place, TEST_WINDOW_PARAMS};
- std::optional<SDL_WindowPtr> window2 {std::in_place, TEST_WINDOW_PARAMS};
+ const std::optional<SDL_WindowPtr> 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-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 <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
@@ -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 <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
#include <glm/gtx/transform.hpp>
@@ -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 <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
@@ -19,7 +19,7 @@
#include <vector>
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 <boost/test/data/test_case.hpp>
@@ -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 <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
#include <stream_support.hpp>
@@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE(initialize_chardata)
BOOST_CHECK_EQUAL(fontTextures.size(), 2);
}
-using CharDataTest = std::tuple<char, Font::CharData>;
+using CharDataTest = std::tuple<decltype(get_codepoint(nullptr)), Font::CharData>;
BOOST_DATA_TEST_CASE(initialize_chardata_A,
boost::unit_test::data::make<CharDataTest>({
{'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::size_t>(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 <cstdarg>
+
+std::unique_ptr<char, decltype(&free)>
+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<char, decltype(&free)> {buf, &free};
+}
diff --git a/test/test-helpers.hpp b/test/testHelpers.h
index 5ebbea9..54b7fc6 100644
--- a/test/test-helpers.hpp
+++ b/test/testHelpers.h
@@ -2,6 +2,9 @@
#include <boost/test/tools/context.hpp>
#include <boost/test/tools/interface.hpp>
+#include <memory>
+
+std::unique_ptr<char, decltype(&free)> uasprintf(const char * fmt, ...) __attribute__((format(printf, 1, 2)));
#define BOOST_CHECK_CLOSE_VEC(a_, b_) \
{ \
@@ -19,3 +22,13 @@
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 <boost/test/test_tools.hpp>
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);