X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=gtest_sdl_main.cpp;h=f4a4d0540bc0cf5efc8c23d0f5491365f7c8c95b;hp=47d7c679107c093cdda8530ef4d9ce42cee6a71a;hb=7fe13b8616177d997dde4539349338d5ceb325da;hpb=2c8eabbbad9eb99409ef03970cbb0b5b46dda025 diff --git a/gtest_sdl_main.cpp b/gtest_sdl_main.cpp index 47d7c67..f4a4d05 100644 --- a/gtest_sdl_main.cpp +++ b/gtest_sdl_main.cpp @@ -1,15 +1,58 @@ -#include +#define GTEST_HAS_EXCEPTIONS 0 + +#include +#include +#include +#ifdef HAVE_BENCHMARK +#include +#endif +#include +#include + #include "gtest/gtest.h" int main(int argc, char **argv) { // Set up an OpenGL context using SDL. - SDL_Init(SDL_INIT_VIDEO); + if (SDL_Init(SDL_INIT_VIDEO) == -1) { + fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError()); + exit(1); + } SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_SetVideoMode(32, 32, 0, SDL_OPENGL); - SDL_WM_SetCaption("OpenGL window for unit test", NULL); - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + // Use a core context, because Mesa only allows certain OpenGL versions in core. + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + + // See also init.cpp for how to enable debugging. +// SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); + + SDL_Window *window = SDL_CreateWindow("OpenGL window for unit test", + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + 32, 32, + SDL_WINDOW_OPENGL); + SDL_GLContext context = SDL_GL_CreateContext(window); + assert(context != nullptr); + + int err; + if (argc >= 2 && strcmp(argv[1], "--benchmark") == 0) { +#ifdef HAVE_BENCHMARK + --argc; + ::benchmark::Initialize(&argc, argv + 1); + if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1; + ::benchmark::RunSpecifiedBenchmarks(); + err = 0; +#else + fprintf(stderr, "No support for microbenchmarks compiled in.\n"); + err = 1; +#endif + } else { + testing::InitGoogleTest(&argc, argv); + err = RUN_ALL_TESTS(); + } + SDL_Quit(); + return err; }