diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-11-14 20:30:32 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-11-14 23:46:14 +0000 |
commit | 5044a05aa16e6bb957fc40fca19ac8dd29c47a35 (patch) | |
tree | 8e0503413c4083ba6668b952f84a809fd24ef32a /test/test-render.cpp | |
parent | Add a basic if clunky render test (diff) | |
download | ilt-5044a05aa16e6bb957fc40fca19ac8dd29c47a35.tar.bz2 ilt-5044a05aa16e6bb957fc40fca19ac8dd29c47a35.tar.xz ilt-5044a05aa16e6bb957fc40fca19ac8dd29c47a35.zip |
Add some tests over the behaviour of windows and contexts and glStuff
Diffstat (limited to 'test/test-render.cpp')
-rw-r--r-- | test/test-render.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/test/test-render.cpp b/test/test-render.cpp index f2f658f..590f8b3 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -47,6 +47,78 @@ 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<SDL_WindowPtr> window1 {std::in_place, TEST_WINDOW_PARAMS}; + std::optional<SDL_WindowPtr> 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) |