1 #define GTEST_HAS_EXCEPTIONS 0
4 #include <SDL2/SDL_error.h>
5 #include <SDL2/SDL_video.h>
7 #include <benchmark/benchmark.h>
12 #include "gtest/gtest.h"
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());
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);
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);
29 // See also init.cpp for how to enable debugging.
30 // SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
32 SDL_Window *window = SDL_CreateWindow("OpenGL window for unit test",
33 SDL_WINDOWPOS_UNDEFINED,
34 SDL_WINDOWPOS_UNDEFINED,
37 SDL_GLContext context = SDL_GL_CreateContext(window);
38 assert(context != nullptr);
41 if (argc >= 2 && strcmp(argv[1], "--benchmark") == 0) {
44 ::benchmark::Initialize(&argc, argv + 1);
45 if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1;
46 ::benchmark::RunSpecifiedBenchmarks();
49 fprintf(stderr, "No support for microbenchmarks compiled in.\n");
53 testing::InitGoogleTest(&argc, argv);
54 err = RUN_ALL_TESTS();