Skip to content

Commit cb35102

Browse files
committed
DPL GUI: add headless test for ImGUI
Framework/DebugGUI package is a red-herring in terms of coverage, due to the imported imgui. While the proper solution would be to manage to compile imgui outside AliceO2, this should increase a bit the actual coverage.
1 parent acbc6a8 commit cb35102

File tree

5 files changed

+83
-18
lines changed

5 files changed

+83
-18
lines changed

Framework/DebugGUI/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,15 @@ O2_GENERATE_EXECUTABLE(
5959
)
6060
endif()
6161

62+
O2_GENERATE_EXECUTABLE(
63+
EXE_NAME "test_DebugGUI_test_ImGUIHeadless"
64+
SOURCES test/test_ImGUIHeadless.cpp test/imgui_demo.cpp
65+
66+
MODULE_LIBRARY_NAME ${LIBRARY_NAME}
67+
BUCKET_NAME ${MODULE_BUCKET_NAME}
68+
)
69+
add_test(NAME test_DebugGUI_test_ImGUIHeadless COMMAND test_DebugGUI_test_ImGUIHeadless)
70+
target_link_libraries(test_DebugGUI_test_ImGUIHeadless Boost::unit_test_framework)
71+
set_tests_properties(test_DebugGUI_test_ImGUIHeadless PROPERTIES TIMEOUT 30)
72+
6273
target_compile_options(DebugGUI PUBLIC -O0 -g -fno-omit-frame-pointer)

Framework/DebugGUI/include/DebugGUI/imgui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ namespace ImGui
161161
IMGUI_API void EndFrame(); // ends the ImGui frame. automatically called by Render(), so most likely don't need to ever call that yourself directly. If you don't need to render you may call EndFrame() but you'll have wasted CPU already. If you don't need to render, better to not create any imgui windows instead!
162162

163163
// Demo, Debug, Information
164-
IMGUI_API void ShowDemoWindow(bool* p_open = NULL); // create demo/test window (previously called ShowTestWindow). demonstrate most ImGui features. call this to learn about the library! try to make it always available in your application!
164+
IMGUI_API void ShowDemoWindow(bool* p_open = NULL, bool def_open = false); // create demo/test window (previously called ShowTestWindow). demonstrate most ImGui features. call this to learn about the library! try to make it always available in your application!
165165
IMGUI_API void ShowMetricsWindow(bool* p_open = NULL); // create metrics window. display ImGui internals: draw commands (with individual draw calls and vertices), window list, basic internal state, etc.
166166
IMGUI_API void ShowStyleEditor(ImGuiStyle* ref = NULL); // add style editor block (not a window). you can pass in a reference ImGuiStyle structure to compare to, revert to and save to (else it uses the default style)
167167
IMGUI_API bool ShowStyleSelector(const char* label); // add style selector block (not a window), essentially a combo listing the default styles.

Framework/DebugGUI/test/imgui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ namespace ImGui
161161
IMGUI_API void EndFrame(); // ends the ImGui frame. automatically called by Render(), so most likely don't need to ever call that yourself directly. If you don't need to render you may call EndFrame() but you'll have wasted CPU already. If you don't need to render, better to not create any imgui windows instead!
162162

163163
// Demo, Debug, Information
164-
IMGUI_API void ShowDemoWindow(bool* p_open = NULL); // create demo/test window (previously called ShowTestWindow). demonstrate most ImGui features. call this to learn about the library! try to make it always available in your application!
164+
IMGUI_API void ShowDemoWindow(bool* p_open = NULL, bool def_open = false); // create demo/test window (previously called ShowTestWindow). demonstrate most ImGui features. call this to learn about the library! try to make it always available in your application!
165165
IMGUI_API void ShowMetricsWindow(bool* p_open = NULL); // create metrics window. display ImGui internals: draw commands (with individual draw calls and vertices), window list, basic internal state, etc.
166166
IMGUI_API void ShowStyleEditor(ImGuiStyle* ref = NULL); // add style editor block (not a window). you can pass in a reference ImGuiStyle structure to compare to, revert to and save to (else it uses the default style)
167167
IMGUI_API bool ShowStyleSelector(const char* label); // add style selector block (not a window), essentially a combo listing the default styles.

Framework/DebugGUI/test/imgui_demo.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,24 @@ void ImGui::ShowUserGuide()
125125
}
126126

127127
// Demonstrate most ImGui features (big function!)
128-
void ImGui::ShowDemoWindow(bool* p_open)
128+
void ImGui::ShowDemoWindow(bool* p_open, bool def_open)
129129
{
130130
// Examples apps
131-
static bool show_app_main_menu_bar = false;
132-
static bool show_app_console = false;
133-
static bool show_app_log = false;
134-
static bool show_app_layout = false;
135-
static bool show_app_property_editor = false;
136-
static bool show_app_long_text = false;
137-
static bool show_app_auto_resize = false;
138-
static bool show_app_constrained_resize = false;
139-
static bool show_app_simple_overlay = false;
140-
static bool show_app_window_titles = false;
141-
static bool show_app_custom_rendering = false;
142-
static bool show_app_style_editor = false;
143-
144-
static bool show_app_metrics = false;
145-
static bool show_app_about = false;
131+
static bool show_app_main_menu_bar = def_open;
132+
static bool show_app_console = def_open;
133+
static bool show_app_log = def_open;
134+
static bool show_app_layout = def_open;
135+
static bool show_app_property_editor = def_open;
136+
static bool show_app_long_text = def_open;
137+
static bool show_app_auto_resize = def_open;
138+
static bool show_app_constrained_resize = def_open;
139+
static bool show_app_simple_overlay = def_open;
140+
static bool show_app_window_titles = def_open;
141+
static bool show_app_custom_rendering = def_open;
142+
static bool show_app_style_editor = def_open;
143+
144+
static bool show_app_metrics = def_open;
145+
static bool show_app_about = def_open;
146146

147147
if (show_app_main_menu_bar) ShowExampleAppMainMenuBar();
148148
if (show_app_console) ShowExampleAppConsole(&show_app_console);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "DebugGUI/imgui.h"
2+
#include <stdio.h>
3+
4+
static void error_callback(int error, const char* description)
5+
{
6+
fprintf(stderr, "Error %d: %s\n", error, description);
7+
}
8+
9+
int main(int, char**)
10+
{
11+
IMGUI_CHECKVERSION();
12+
ImGui::CreateContext();
13+
ImGuiIO& io = ImGui::GetIO();
14+
15+
// Build atlas
16+
unsigned char* tex_pixels = nullptr;
17+
int tex_w, tex_h;
18+
io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_w, &tex_h);
19+
20+
bool show_test_window = true;
21+
bool show_another_window = true;
22+
ImVec4 clear_color = ImColor(114, 144, 154);
23+
24+
for (int n = 0; n < 50; n++) {
25+
io.DisplaySize = ImVec2(1920, 1080);
26+
io.DeltaTime = 1.0f / 60.0f;
27+
ImGui::NewFrame();
28+
29+
// 1. Show a simple window
30+
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
31+
static float f = 0.0f;
32+
ImGui::Text("Hello, world!");
33+
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
34+
ImGui::ColorEdit3("clear color", (float*)&clear_color);
35+
if (ImGui::Button("Test Window")) show_test_window ^= 1;
36+
if (ImGui::Button("Another Window")) show_another_window ^= 1;
37+
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
38+
39+
// 2. Show another simple window, this time using an explicit Begin/End pair
40+
ImGui::SetNextWindowSize(ImVec2(200,100), ImGuiSetCond_FirstUseEver);
41+
ImGui::Begin("Another Window", &show_another_window);
42+
ImGui::Text("Hello");
43+
ImGui::End();
44+
45+
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
46+
ImGui::ShowDemoWindow(nullptr, true);
47+
48+
ImGui::Render();
49+
}
50+
51+
ImGui::DestroyContext();
52+
53+
return 0;
54+
}

0 commit comments

Comments
 (0)