]> git.sesse.net Git - movit/blob - gtest_sdl_main.cpp
Release Movit 1.6.1.
[movit] / gtest_sdl_main.cpp
1 #define GTEST_HAS_EXCEPTIONS 0
2
3 #include <SDL2/SDL.h>
4 #include <SDL2/SDL_error.h>
5 #include <SDL2/SDL_video.h>
6 #ifdef HAVE_BENCHMARK
7 #include <benchmark/benchmark.h>
8 #endif
9 #include <stdio.h>
10 #include <stdlib.h>
11
12 #include "gtest/gtest.h"
13
14 int main(int argc, char **argv) {
15         // Set up an OpenGL context using SDL.
16         if (SDL_Init(SDL_INIT_VIDEO) == -1) {
17                 fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
18                 exit(1);
19         }
20         SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
21         SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
22         SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
23
24         // Use a core context, because Mesa only allows certain OpenGL versions in core.
25         SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
26         SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
27         SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
28
29         // See also init.cpp for how to enable debugging.
30 //      SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
31
32         SDL_Window *window = SDL_CreateWindow("OpenGL window for unit test",
33                 SDL_WINDOWPOS_UNDEFINED,
34                 SDL_WINDOWPOS_UNDEFINED,
35                 32, 32,
36                 SDL_WINDOW_OPENGL);
37         SDL_GLContext context = SDL_GL_CreateContext(window);
38         assert(context != nullptr);
39
40         int err;
41         if (argc >= 2 && strcmp(argv[1], "--benchmark") == 0) {
42 #ifdef HAVE_BENCHMARK
43                 --argc;
44                 ::benchmark::Initialize(&argc, argv + 1);
45                 if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1;
46                 ::benchmark::RunSpecifiedBenchmarks();
47                 err = 0;
48 #else
49                 fprintf(stderr, "No support for microbenchmarks compiled in.\n");
50                 err = 1;
51 #endif
52         } else {
53                 testing::InitGoogleTest(&argc, argv);
54                 err = RUN_ALL_TESTS();
55         }
56         SDL_Quit();
57         return err;
58 }