summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-12-29 23:25:25 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-12-29 23:25:25 +0000
commit94e99a5a9ded01e8184543b7ddf5cdfa39573ded (patch)
treeca6dd314da3c3d29fd8fc8d36f53d578c8c48be6
parentAdd missing explicit on constructors (diff)
downloadilt-94e99a5a9ded01e8184543b7ddf5cdfa39573ded.tar.bz2
ilt-94e99a5a9ded01e8184543b7ddf5cdfa39573ded.tar.xz
ilt-94e99a5a9ded01e8184543b7ddf5cdfa39573ded.zip
Move test render helpers into a new test library
-rw-r--r--test/Jamfile.jam3
-rw-r--r--test/test-render.cpp64
-rw-r--r--test/testMainWindow.cpp24
-rw-r--r--test/testMainWindow.h14
-rw-r--r--test/testRenderOutput.cpp26
-rw-r--r--test/testRenderOutput.h13
6 files changed, 81 insertions, 63 deletions
diff --git a/test/Jamfile.jam b/test/Jamfile.jam
index 6a83f9c..72ec0e3 100644
--- a/test/Jamfile.jam
+++ b/test/Jamfile.jam
@@ -20,6 +20,7 @@ project : requirements
<toolset>tidy:<xcheckxx>clang-analyzer-cplusplus.Move
<toolset>tidy:<librarydef>boost
;
+lib test : [ glob *.cpp : test-*.cpp ] ;
run test-collection.cpp ;
run test-obj.cpp ;
@@ -30,7 +31,7 @@ run test-network.cpp ;
run test-persistence.cpp : -- : [ sequence.insertion-sort [ glob fixtures/json/*.json fixtures/json/bad/*.json ] ] ;
run test-text.cpp ;
run test-enumDetails.cpp ;
-run test-render.cpp ;
+run test-render.cpp : : : <library>test ;
run test-glContextBhvr.cpp ;
compile test-static-enumDetails.cpp ;
compile test-static-stream_support.cpp ;
diff --git a/test/test-render.cpp b/test/test-render.cpp
index ef4dcc6..8f8fd06 100644
--- a/test/test-render.cpp
+++ b/test/test-render.cpp
@@ -1,6 +1,8 @@
#define BOOST_TEST_MODULE test_render
#include "test-helpers.hpp"
+#include "testMainWindow.h"
+#include "testRenderOutput.h"
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
@@ -16,68 +18,6 @@
#include <ui/applicationBase.h>
#include <ui/window.h>
-class TestRenderOutput {
-public:
- TestRenderOutput() : size {640, 480}
- {
- glBindFramebuffer(GL_FRAMEBUFFER, output);
- 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);
- 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);
- };
- configuregdata(outImage, GL_RGBA, GL_UNSIGNED_BYTE, GL_COLOR_ATTACHMENT0);
- glDrawBuffer(GL_COLOR_ATTACHMENT0);
-
- glBindRenderbuffer(GL_RENDERBUFFER, depth);
- glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, size.x, size.y);
- glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
-
- // finally check if framebuffer is complete
- if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
- throw std::runtime_error("Framebuffer not complete!");
- }
- }
- const glm::ivec2 size;
- glFrameBuffer output;
- glRenderBuffer depth;
- glTexture outImage;
-};
-
-class TestMainWindow : public Window {
- // This exists only to hold an OpenGL context open for the duration of the tests,
- // in the same way a real main window would always exist.
-public:
- 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",
- (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, message);
- switch (type) {
- case GL_DEBUG_TYPE_ERROR:
- case GL_DEBUG_TYPE_PERFORMANCE:
- case GL_DEBUG_TYPE_PORTABILITY:
- case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
- case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
- BOOST_TEST_ERROR(buf);
- }
- BOOST_TEST_MESSAGE(buf);
- },
- nullptr);
- }
- void
- tick(TickDuration) override
- {
- }
-};
-
class TestScene : public SceneProvider {
RailVehicleClass train {"brush47"};
Terrain terrain {[]() {
diff --git a/test/testMainWindow.cpp b/test/testMainWindow.cpp
new file mode 100644
index 0000000..66e8832
--- /dev/null
+++ b/test/testMainWindow.cpp
@@ -0,0 +1,24 @@
+#include "testMainWindow.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",
+ (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, message);
+ switch (type) {
+ case GL_DEBUG_TYPE_ERROR:
+ case GL_DEBUG_TYPE_PERFORMANCE:
+ case GL_DEBUG_TYPE_PORTABILITY:
+ case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
+ case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
+ BOOST_TEST_ERROR(buf);
+ }
+ BOOST_TEST_MESSAGE(buf);
+ },
+ nullptr);
+}
diff --git a/test/testMainWindow.h b/test/testMainWindow.h
new file mode 100644
index 0000000..bc9c0bd
--- /dev/null
+++ b/test/testMainWindow.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "ui/window.h"
+
+class TestMainWindow : public Window {
+ // This exists only to hold an OpenGL context open for the duration of the tests,
+ // in the same way a real main window would always exist.
+public:
+ TestMainWindow();
+ void
+ tick(TickDuration) override
+ {
+ }
+};
diff --git a/test/testRenderOutput.cpp b/test/testRenderOutput.cpp
new file mode 100644
index 0000000..7a96e96
--- /dev/null
+++ b/test/testRenderOutput.cpp
@@ -0,0 +1,26 @@
+#include "testRenderOutput.h"
+#include <stdexcept>
+
+TestRenderOutput::TestRenderOutput() : size {640, 480}
+{
+ glBindFramebuffer(GL_FRAMEBUFFER, output);
+ 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);
+ 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);
+ };
+ configuregdata(outImage, GL_RGBA, GL_UNSIGNED_BYTE, GL_COLOR_ATTACHMENT0);
+ glDrawBuffer(GL_COLOR_ATTACHMENT0);
+
+ glBindRenderbuffer(GL_RENDERBUFFER, depth);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, size.x, size.y);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
+
+ // finally check if framebuffer is complete
+ if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
+ throw std::runtime_error("Framebuffer not complete!");
+ }
+}
diff --git a/test/testRenderOutput.h b/test/testRenderOutput.h
new file mode 100644
index 0000000..0d97ef1
--- /dev/null
+++ b/test/testRenderOutput.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include "glArrays.h"
+#include <glm/vec2.hpp>
+
+class TestRenderOutput {
+public:
+ TestRenderOutput();
+ const glm::ivec2 size;
+ glFrameBuffer output;
+ glRenderBuffer depth;
+ glTexture outImage;
+};