]> git.sesse.net Git - movit/blobdiff - gtest_sdl_main.cpp
Drop support for SDL1, which is no longer maintained.
[movit] / gtest_sdl_main.cpp
index cd68777721e19cc92b300920fd094473ef5d5a7d..be8bdd4d372054f68c81cf28968dcb40a88f8c4e 100644 (file)
@@ -1,13 +1,10 @@
 #define GTEST_HAS_EXCEPTIONS 0
 
-#ifdef HAVE_SDL2
 #include <SDL2/SDL.h>
 #include <SDL2/SDL_error.h>
 #include <SDL2/SDL_video.h>
-#else
-#include <SDL/SDL.h>
-#include <SDL/SDL_error.h>
-#include <SDL/SDL_video.h>
+#ifdef HAVE_BENCHMARK
+#include <benchmark/benchmark.h>
 #endif
 #include <stdio.h>
 #include <stdlib.h>
@@ -24,7 +21,6 @@ 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
        //
@@ -34,20 +30,34 @@ int main(int argc, char **argv) {
 //     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 != 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;
 }