diff --git a/include/tests/gui.h b/include/tests/gui.h deleted file mode 100644 index 74d48049..00000000 --- a/include/tests/gui.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2016 (c) Anna Schumaker. - */ -#ifndef OCARINA_TESTS_GUI_H -#define OCARINA_TESTS_GUI_H - -static GMainLoop *__gui_test_main_loop; - -static int __gui_test_on_idle(gpointer data) -{ - g_main_loop_quit(__gui_test_main_loop); - return G_SOURCE_CONTINUE; -} - -static void gui_test_init() -{ - __gui_test_main_loop = g_main_loop_new(NULL, FALSE); - g_idle_add(__gui_test_on_idle, NULL); -} - -static void gui_test_deinit() -{ - g_main_loop_unref(__gui_test_main_loop); -} - -static void gui_test_main_loop() -{ - g_main_loop_run(__gui_test_main_loop); -} -#endif /* OCARINA_TESTS_GUI_H */ diff --git a/include/tests/loop.h b/include/tests/loop.h new file mode 100644 index 00000000..55909e49 --- /dev/null +++ b/include/tests/loop.h @@ -0,0 +1,30 @@ +/* + * Copyright 2016 (c) Anna Schumaker. + */ +#ifndef OCARINA_TESTS_LOOP_H +#define OCARINA_TESTS_LOOP_H + +static GMainLoop *__test_main_loop; + +static int __test_loop_on_idle(gpointer data) +{ + g_main_loop_quit(__test_main_loop); + return G_SOURCE_CONTINUE; +} + +static void test_loop_init() +{ + __test_main_loop = g_main_loop_new(NULL, FALSE); + g_idle_add(__test_loop_on_idle, NULL); +} + +static void test_loop_deinit() +{ + g_main_loop_unref(__test_main_loop); +} + +static void test_main_loop() +{ + g_main_loop_run(__test_main_loop); +} +#endif /* OCARINA_TESTS_LOOP_H */ diff --git a/tests/gui/idle.c b/tests/gui/idle.c index 24ddd7e3..924d6404 100644 --- a/tests/gui/idle.c +++ b/tests/gui/idle.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include static const unsigned int N = 100; static unsigned int cur = -1; @@ -28,14 +28,14 @@ static void test_idle() g_assert_false(gtk_widget_is_visible(GTK_WIDGET(progress))); for (i = 0; i < (N - 1); i++) { - gui_test_main_loop(); + test_main_loop(); g_assert_true(gtk_widget_is_visible(GTK_WIDGET(progress))); g_assert_cmpfloat(idle_progress(), ==, (float)(i + 1) / N); g_assert_cmpfloat(gtk_progress_bar_get_fraction(progress), ==, (float)(i + 1) / N); } - gui_test_main_loop(); + test_main_loop(); g_assert_false(gtk_widget_is_visible(GTK_WIDGET(progress))); } @@ -46,14 +46,14 @@ int main(int argc, char **argv) gtk_init(&argc, NULL); core_init(&argc, NULL, NULL, NULL, IDLE_SYNC); gui_builder_init("share/ocarina/ocarina.ui"); - gui_test_init(); + test_loop_init(); while (idle_run_task()) {} g_test_init(&argc, &argv, NULL); g_test_add_func("/Gui/Idle", test_idle); ret = g_test_run(); - gui_test_deinit(); + test_loop_deinit(); gui_builder_deinit(); core_deinit(); return ret; diff --git a/tests/gui/treeview.c b/tests/gui/treeview.c index c2f9ea2a..155d0798 100644 --- a/tests/gui/treeview.c +++ b/tests/gui/treeview.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include const gchar *GUI_COL_SETTINGS[GUI_MODEL_N_COLUMNS] = { [GUI_MODEL_TRACK_NR] = "gui.queue.track", @@ -199,7 +199,7 @@ void test_treeview_columns() gtk_tree_view_column_set_fixed_width(col, (i + 2) * 10); } - gui_test_main_loop(); + test_main_loop(); for (i = 0; i < GUI_MODEL_N_COLUMNS; i++) { col = gtk_tree_view_get_column(gui_treeview(), i); if (!col || (i == GUI_MODEL_LAST_PLAY)) @@ -221,7 +221,7 @@ int main(int argc, char **argv) gui_model_init(); gui_filter_init(); gui_treeview_init(); - gui_test_init(); + test_loop_init(); playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony"); while (idle_run_task()) {} @@ -234,7 +234,7 @@ int main(int argc, char **argv) ret = g_test_run(); core_deinit(); - gui_test_deinit(); + test_loop_deinit(); gui_treeview_deinit(); gui_filter_deinit(); gui_model_deinit(); diff --git a/tests/gui/window.c b/tests/gui/window.c index 9cab321e..670ec32c 100644 --- a/tests/gui/window.c +++ b/tests/gui/window.c @@ -3,7 +3,7 @@ */ #include #include -#include +#include #include static void test_window() @@ -16,7 +16,7 @@ static void test_window() g_assert_false(settings_has("gui.window.y")); g_assert_cmpstr(gtk_window_get_title(window), ==, "Ocarina " CONFIG_VERSION); - gui_test_main_loop(); + test_main_loop(); g_assert_true(settings_has("gui.window.width")); g_assert_true(settings_has("gui.window.height")); g_assert_true(settings_has("gui.window.x")); @@ -28,7 +28,7 @@ static void test_window() settings_set("gui.window.y", 42); gui_window_init("share/ocarina/ocarina.png"); - gui_test_main_loop(); + test_main_loop(); g_assert_cmpuint(settings_get("gui.window.width"), ==, 800); g_assert_cmpuint(settings_get("gui.window.height"), ==, 600); g_assert_cmpuint(settings_get("gui.window.x"), ==, 42); @@ -43,13 +43,13 @@ int main(int argc, char **argv) gtk_init(&argc, NULL); gui_builder_init("share/ocarina/ocarina.ui"); gui_window_init("share/ocarina/ocarina.png"); - gui_test_init(); + test_loop_init(); g_test_init(&argc, &argv, NULL); g_test_add_func("/Gui/Window", test_window); ret = g_test_run(); - gui_test_deinit(); + test_loop_deinit(); gui_window_deinit(); gui_builder_deinit(); settings_deinit();