From 46fb6990bfcd07497229a5081b8e38287054be01 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 17 Nov 2022 19:44:40 +0000 Subject: Move OpenGL context behaviour tests into their own app For our own sanity :) --- test/Jamfile.jam | 1 + test/test-glContextBhvr.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++ test/test-render.cpp | 71 --------------------------------------- 3 files changed, 83 insertions(+), 71 deletions(-) create mode 100644 test/test-glContextBhvr.cpp (limited to 'test') diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 3f3150d..32c522b 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -31,4 +31,5 @@ run test-persistence.cpp : -- : [ sequence.insertion-sort [ glob fixtures/json/* run test-text.cpp ; run test-enumDetails.cpp ; run test-render.cpp ; +run test-glContextBhvr.cpp ; compile test-static-enumDetails.cpp ; diff --git a/test/test-glContextBhvr.cpp b/test/test-glContextBhvr.cpp new file mode 100644 index 0000000..0ee45d6 --- /dev/null +++ b/test/test-glContextBhvr.cpp @@ -0,0 +1,82 @@ +#define BOOST_TEST_MODULE test_glcontextbehaviour + +#include "test-helpers.hpp" +#include + +#include +#include +#include +#include + +BOOST_GLOBAL_FIXTURE(ApplicationBase); + +#define TEST_WINDOW_PARAMS __FILE__, 0, 0, 640, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN +static void +CreateProgramTest() +{ + ProgramRef p; + BOOST_REQUIRE(p); +} +BOOST_AUTO_TEST_CASE(windowContextThingsBehaviour1) +{ + BOOST_REQUIRE(!glCreateProgram); // Init not called yet + { + 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}; + BOOST_REQUIRE(context); + BOOST_REQUIRE(!glCreateProgram); + BOOST_REQUIRE_EQUAL(glewInit(), GLEW_OK); + BOOST_REQUIRE(glCreateProgram); + CreateProgramTest(); + } // Context destroyed + BOOST_REQUIRE(glCreateProgram); // Functions still set + BOOST_REQUIRE_THROW({ ProgramRef p; }, std::exception); // Get fails with no context + { + SDL_GLContextPtr context {window}; + BOOST_REQUIRE(context); + CreateProgramTest(); + } + } + { + SDL_WindowPtr window {TEST_WINDOW_PARAMS}; + BOOST_REQUIRE(window); + SDL_GLContextPtr context {window}; + BOOST_REQUIRE(context); + CreateProgramTest(); + } +} + +BOOST_AUTO_TEST_CASE(windowContextThingsBehaviour2) +{ + SDL_WindowPtr window1 {TEST_WINDOW_PARAMS}; + BOOST_REQUIRE(window1); + { + SDL_WindowPtr window2 {TEST_WINDOW_PARAMS}; + BOOST_REQUIRE(window2); + SDL_GLContextPtr context {window2}; + BOOST_REQUIRE(context); + CreateProgramTest(); + } + BOOST_REQUIRE_THROW({ 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}; + BOOST_REQUIRE(window1); + BOOST_REQUIRE(window1.value()); + 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 + 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 +} diff --git a/test/test-render.cpp b/test/test-render.cpp index 590f8b3..89b2d90 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -48,77 +48,6 @@ public: BOOST_GLOBAL_FIXTURE(ApplicationBase); -#define TEST_WINDOW_PARAMS __FILE__, 0, 0, 640, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN -static void -CreateProgramTest() -{ - ProgramRef p; - BOOST_REQUIRE(p); -} -BOOST_AUTO_TEST_CASE(windowContextThingsBehaviour1) -{ - BOOST_REQUIRE(!glCreateProgram); // Init not called yet - { - 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}; - BOOST_REQUIRE(context); - BOOST_REQUIRE(!glCreateProgram); - BOOST_REQUIRE_EQUAL(glewInit(), GLEW_OK); - BOOST_REQUIRE(glCreateProgram); - CreateProgramTest(); - } // Context destroyed - BOOST_REQUIRE(glCreateProgram); // Functions still set - BOOST_REQUIRE_THROW({ ProgramRef p; }, std::exception); // Get fails with no context - { - SDL_GLContextPtr context {window}; - BOOST_REQUIRE(context); - CreateProgramTest(); - } - } - { - SDL_WindowPtr window {TEST_WINDOW_PARAMS}; - BOOST_REQUIRE(window); - SDL_GLContextPtr context {window}; - BOOST_REQUIRE(context); - CreateProgramTest(); - } -} - -BOOST_AUTO_TEST_CASE(windowContextThingsBehaviour2) -{ - SDL_WindowPtr window1 {TEST_WINDOW_PARAMS}; - BOOST_REQUIRE(window1); - { - SDL_WindowPtr window2 {TEST_WINDOW_PARAMS}; - BOOST_REQUIRE(window2); - SDL_GLContextPtr context {window2}; - BOOST_REQUIRE(context); - CreateProgramTest(); - } - BOOST_REQUIRE_THROW({ 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}; - BOOST_REQUIRE(window1); - BOOST_REQUIRE(window1.value()); - 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 - 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_FIXTURE_TEST_SUITE(w, TestRenderWindow); BOOST_AUTO_TEST_CASE(basic) -- cgit v1.2.3