X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=gtest_sdl_main.cpp;h=f4a4d0540bc0cf5efc8c23d0f5491365f7c8c95b;hp=90a929edd7d330853c44a7d291ce7aeca3b24e7b;hb=e72d9577b3af42805d84a640c698853b11060476;hpb=fe36cdba16b02cab582f2d0516e98fcdb62f3807 diff --git a/gtest_sdl_main.cpp b/gtest_sdl_main.cpp index 90a929e..f4a4d05 100644 --- a/gtest_sdl_main.cpp +++ b/gtest_sdl_main.cpp @@ -1,13 +1,10 @@ #define GTEST_HAS_EXCEPTIONS 0 -#ifdef HAVE_SDL2 #include #include #include -#else -#include -#include -#include +#ifdef HAVE_BENCHMARK +#include #endif #include #include @@ -24,16 +21,10 @@ int main(int argc, char **argv) { SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); -#ifdef HAVE_SDL2 - // You can uncomment this if you want to try a core context. - // For Mesa, you can get the same effect by doing - // - // export MESA_GL_VERSION_OVERRIDE=3.1FC - // - // before running tests. -// 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); + // 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); @@ -44,14 +35,24 @@ int main(int argc, char **argv) { 32, 32, SDL_WINDOW_OPENGL); SDL_GLContext context = SDL_GL_CreateContext(window); - assert(context != NULL); + 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 - SDL_SetVideoMode(32, 32, 0, SDL_OPENGL); - SDL_WM_SetCaption("OpenGL window for unit test", NULL); + fprintf(stderr, "No support for microbenchmarks compiled in.\n"); + err = 1; #endif - - testing::InitGoogleTest(&argc, argv); - int err = RUN_ALL_TESTS(); + } else { + testing::InitGoogleTest(&argc, argv); + err = RUN_ALL_TESTS(); + } SDL_Quit(); - exit(err); + return err; }