From 8146687110cb557773afaf64534d5c8488d536a5 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Tue, 26 Dec 2017 17:06:08 -0600 Subject: [PATCH] Don't create a window when testing We do this by creating the notion of a "headless" mode, and skip window creation in SDL. --- src/vm_screen.c | 6 +++++- tests/CMakeLists.txt | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/vm_screen.c b/src/vm_screen.c index 63ea86e..5495d3d 100644 --- a/src/vm_screen.c +++ b/src/vm_screen.c @@ -74,6 +74,7 @@ vm_screen_set_logical_coords(vm_screen *screen, int xcoords, int ycoords) int vm_screen_add_window(vm_screen *screen, int width, int height) { +#ifndef HEADLESS SDL_CreateWindowAndRenderer( width, height, 0, &screen->window, &screen->render); @@ -81,6 +82,7 @@ vm_screen_add_window(vm_screen *screen, int width, int height) log_critical("Could not create window: %s", SDL_GetError()); return ERR_GFXINIT; } +#endif // We plan to draw onto a surface that is xcoords x ycoords in area, // regardless of the actual size of the window. @@ -150,7 +152,9 @@ vm_screen_set_color(vm_screen *screen, uint8_t blue, uint8_t alpha) { - SDL_SetRenderDrawColor(screen->render, red, green, blue, alpha); + if (screen->render) { + SDL_SetRenderDrawColor(screen->render, red, green, blue, alpha); + } } /* diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f740453..dae0332 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,6 +4,8 @@ project(erc-test) set(CMAKE_BUILD_TYPE Debug) +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHEADLESS") + if(DEFINED ENV{STATIC_ANALYSIS}) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --analyze") endif()