]> git.sesse.net Git - movit/blob - gtest_sdl_main.cpp
Fix deletion of compute shaders.
[movit] / gtest_sdl_main.cpp
1 #define GTEST_HAS_EXCEPTIONS 0
2
3 #ifdef HAVE_SDL2
4 #include <SDL2/SDL.h>
5 #include <SDL2/SDL_error.h>
6 #include <SDL2/SDL_video.h>
7 #else
8 #include <SDL/SDL.h>
9 #include <SDL/SDL_error.h>
10 #include <SDL/SDL_video.h>
11 #endif
12 #ifdef HAVE_BENCHMARK
13 #include <benchmark/benchmark.h>
14 #endif
15 #include <stdio.h>
16 #include <stdlib.h>
17
18 #include "gtest/gtest.h"
19
20 int main(int argc, char **argv) {
21         // Set up an OpenGL context using SDL.
22         if (SDL_Init(SDL_INIT_VIDEO) == -1) {
23                 fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
24                 exit(1);
25         }
26         SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
27         SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
28         SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
29
30 #ifdef HAVE_SDL2
31         // You can uncomment this if you want to try a core context.
32         // For Mesa, you can get the same effect by doing
33         //
34         //   export MESA_GL_VERSION_OVERRIDE=3.1FC
35         //
36         // before running tests.
37 //      SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
38 //      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
39 //      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
40
41         // See also init.cpp for how to enable debugging.
42 //      SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
43
44         SDL_Window *window = SDL_CreateWindow("OpenGL window for unit test",
45                 SDL_WINDOWPOS_UNDEFINED,
46                 SDL_WINDOWPOS_UNDEFINED,
47                 32, 32,
48                 SDL_WINDOW_OPENGL);
49         SDL_GLContext context = SDL_GL_CreateContext(window);
50         assert(context != nullptr);
51 #else
52         SDL_SetVideoMode(32, 32, 0, SDL_OPENGL);
53         SDL_WM_SetCaption("OpenGL window for unit test", nullptr);
54 #endif
55
56         int err;
57         if (argc >= 2 && strcmp(argv[1], "--benchmark") == 0) {
58 #ifdef HAVE_BENCHMARK
59                 --argc;
60                 ::benchmark::Initialize(&argc, argv + 1);
61                 if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1;
62                 ::benchmark::RunSpecifiedBenchmarks();
63                 err = 0;
64 #else
65                 fprintf(stderr, "No support for microbenchmarks compiled in.\n");
66                 err = 1;
67 #endif
68         } else {
69                 testing::InitGoogleTest(&argc, argv);
70                 err = RUN_ALL_TESTS();
71         }
72         SDL_Quit();
73         return err;
74 }