tests/gui: Add a generic way to run a main loop
I've had to code this in several places, so creating a generic function is long overdue. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
90b80fc8a7
commit
f9238c34e4
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* 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 */
|
|
@ -9,11 +9,11 @@
|
||||||
#include <gui/view.h>
|
#include <gui/view.h>
|
||||||
#include <gui/window.h>
|
#include <gui/window.h>
|
||||||
#include <tests/test.h>
|
#include <tests/test.h>
|
||||||
|
#include <tests/gui.h>
|
||||||
|
|
||||||
static const unsigned int N = 100;
|
static const unsigned int N = 100;
|
||||||
static unsigned int cur = -1;
|
static unsigned int cur = -1;
|
||||||
struct core_init_data init_data;
|
struct core_init_data init_data;
|
||||||
static GMainLoop *main_loop;
|
|
||||||
|
|
||||||
static bool inc_cur(void *data)
|
static bool inc_cur(void *data)
|
||||||
{
|
{
|
||||||
|
@ -22,21 +22,12 @@ static bool inc_cur(void *data)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int test_on_idle()
|
|
||||||
{
|
|
||||||
g_main_loop_quit(main_loop);
|
|
||||||
return G_SOURCE_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_idle()
|
static void test_idle()
|
||||||
{
|
{
|
||||||
GtkProgressBar *progress;
|
GtkProgressBar *progress;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
float fraction;
|
float fraction;
|
||||||
|
|
||||||
main_loop = g_main_loop_new(NULL, FALSE);
|
|
||||||
g_idle_add(test_on_idle, gui_window());
|
|
||||||
|
|
||||||
progress = GTK_PROGRESS_BAR(gui_builder_widget("o_idle_progress"));
|
progress = GTK_PROGRESS_BAR(gui_builder_widget("o_idle_progress"));
|
||||||
g_assert_false(gtk_widget_is_visible(GTK_WIDGET(progress)));
|
g_assert_false(gtk_widget_is_visible(GTK_WIDGET(progress)));
|
||||||
|
|
||||||
|
@ -47,7 +38,7 @@ static void test_idle()
|
||||||
|
|
||||||
for (i = 0; i < N; i++) {
|
for (i = 0; i < N; i++) {
|
||||||
g_assert_true(gtk_widget_is_visible(GTK_WIDGET(progress)));
|
g_assert_true(gtk_widget_is_visible(GTK_WIDGET(progress)));
|
||||||
g_main_loop_run(main_loop);
|
gui_test_main_loop();
|
||||||
g_assert_cmpfloat(idle_progress(), ==, (float)(i + 1) / N);
|
g_assert_cmpfloat(idle_progress(), ==, (float)(i + 1) / N);
|
||||||
if (i != (N - 1)) {
|
if (i != (N - 1)) {
|
||||||
fraction = gtk_progress_bar_get_fraction(progress);
|
fraction = gtk_progress_bar_get_fraction(progress);
|
||||||
|
@ -66,12 +57,14 @@ int main(int argc, char **argv)
|
||||||
core_init(&argc, NULL, &init_data);
|
core_init(&argc, NULL, &init_data);
|
||||||
gui_builder_init("share/ocarina/ocarina.ui");
|
gui_builder_init("share/ocarina/ocarina.ui");
|
||||||
gui_view_init();
|
gui_view_init();
|
||||||
|
gui_test_init();
|
||||||
while (idle_run_task()) {}
|
while (idle_run_task()) {}
|
||||||
|
|
||||||
g_test_init(&argc, &argv, NULL);
|
g_test_init(&argc, &argv, NULL);
|
||||||
g_test_add_func("/Gui/Idle", test_idle);
|
g_test_add_func("/Gui/Idle", test_idle);
|
||||||
ret = g_test_run();
|
ret = g_test_run();
|
||||||
|
|
||||||
|
gui_test_deinit();
|
||||||
gui_builder_deinit();
|
gui_builder_deinit();
|
||||||
core_deinit();
|
core_deinit();
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <gui/model.h>
|
#include <gui/model.h>
|
||||||
#include <gui/view.h>
|
#include <gui/view.h>
|
||||||
#include <tests/test.h>
|
#include <tests/test.h>
|
||||||
|
#include <tests/gui.h>
|
||||||
|
|
||||||
const gchar *QUEUE_SETTINGS[Q_MODEL_N_COLUMNS] = {
|
const gchar *QUEUE_SETTINGS[Q_MODEL_N_COLUMNS] = {
|
||||||
[Q_MODEL_TRACK_NR] = "gui.queue.track",
|
[Q_MODEL_TRACK_NR] = "gui.queue.track",
|
||||||
|
@ -25,7 +26,6 @@ const gchar *QUEUE_SETTINGS[Q_MODEL_N_COLUMNS] = {
|
||||||
[Q_MODEL_FONT] = "gui.queue.font",
|
[Q_MODEL_FONT] = "gui.queue.font",
|
||||||
};
|
};
|
||||||
|
|
||||||
GMainLoop *main_loop;
|
|
||||||
unsigned int load_count = 0;
|
unsigned int load_count = 0;
|
||||||
|
|
||||||
static void test_load(struct track *track) { load_count++; }
|
static void test_load(struct track *track) { load_count++; }
|
||||||
|
@ -42,12 +42,6 @@ struct core_init_data init_data = {
|
||||||
.audio_ops = &test_audio_ops,
|
.audio_ops = &test_audio_ops,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int test_on_idle(gpointer data)
|
|
||||||
{
|
|
||||||
g_main_loop_quit(main_loop);
|
|
||||||
return G_SOURCE_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_treeview()
|
static void test_treeview()
|
||||||
{
|
{
|
||||||
GtkTreeViewColumn *col;
|
GtkTreeViewColumn *col;
|
||||||
|
@ -63,8 +57,6 @@ static void test_treeview()
|
||||||
filter = GTK_TREE_MODEL(gui_view_get_filter());
|
filter = GTK_TREE_MODEL(gui_view_get_filter());
|
||||||
|
|
||||||
treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
|
treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
|
||||||
main_loop = g_main_loop_new(NULL, FALSE);
|
|
||||||
g_idle_add(test_on_idle, NULL);
|
|
||||||
|
|
||||||
for (i = 0; i < Q_MODEL_N_COLUMNS; i++)
|
for (i = 0; i < Q_MODEL_N_COLUMNS; i++)
|
||||||
g_assert_false(settings_has(QUEUE_SETTINGS[i]));
|
g_assert_false(settings_has(QUEUE_SETTINGS[i]));
|
||||||
|
@ -76,7 +68,7 @@ static void test_treeview()
|
||||||
gtk_tree_view_column_set_fixed_width(col, (i + 2) * 10);
|
gtk_tree_view_column_set_fixed_width(col, (i + 2) * 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_main_loop_run(main_loop);
|
gui_test_main_loop();
|
||||||
for (i = 0; i < Q_MODEL_N_COLUMNS; i++) {
|
for (i = 0; i < Q_MODEL_N_COLUMNS; i++) {
|
||||||
bool has = (i < Q_MODEL_LAST_PLAY);
|
bool has = (i < Q_MODEL_LAST_PLAY);
|
||||||
g_assert(settings_has(QUEUE_SETTINGS[i]) == has);
|
g_assert(settings_has(QUEUE_SETTINGS[i]) == has);
|
||||||
|
@ -107,6 +99,7 @@ static void test_treeview()
|
||||||
gtk_tree_path_free(path);
|
gtk_tree_path_free(path);
|
||||||
|
|
||||||
gui_view_set_queue(NULL);
|
gui_view_set_queue(NULL);
|
||||||
|
gui_test_deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
@ -116,6 +109,7 @@ int main(int argc, char **argv)
|
||||||
gui_builder_init("share/ocarina/ocarina.ui");
|
gui_builder_init("share/ocarina/ocarina.ui");
|
||||||
gui_queue_model_init();
|
gui_queue_model_init();
|
||||||
gui_view_init();
|
gui_view_init();
|
||||||
|
gui_test_init();
|
||||||
while (idle_run_task()) {};
|
while (idle_run_task()) {};
|
||||||
|
|
||||||
g_test_init(&argc, &argv, NULL);
|
g_test_init(&argc, &argv, NULL);
|
||||||
|
|
|
@ -3,29 +3,18 @@
|
||||||
*/
|
*/
|
||||||
#include <core/settings.h>
|
#include <core/settings.h>
|
||||||
#include <gui/window.h>
|
#include <gui/window.h>
|
||||||
|
#include <tests/gui.h>
|
||||||
#include <tests/test.h>
|
#include <tests/test.h>
|
||||||
|
|
||||||
GMainLoop *main_loop;
|
|
||||||
|
|
||||||
static int test_on_idle(gpointer data)
|
|
||||||
{
|
|
||||||
g_main_loop_quit(main_loop);
|
|
||||||
return G_SOURCE_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_window()
|
static void test_window()
|
||||||
{
|
{
|
||||||
GtkWindow *window;
|
GtkWindow *window = gui_window();
|
||||||
|
|
||||||
main_loop = g_main_loop_new(NULL, FALSE);
|
|
||||||
window = gui_window();
|
|
||||||
g_idle_add(test_on_idle, window);
|
|
||||||
|
|
||||||
g_assert_false(settings_has("gui.window.width"));
|
g_assert_false(settings_has("gui.window.width"));
|
||||||
g_assert_false(settings_has("gui.window.height"));
|
g_assert_false(settings_has("gui.window.height"));
|
||||||
g_assert_cmpstr(gtk_window_get_title(window), ==, "Ocarina " CONFIG_VERSION);
|
g_assert_cmpstr(gtk_window_get_title(window), ==, "Ocarina " CONFIG_VERSION);
|
||||||
|
|
||||||
g_main_loop_run(main_loop);
|
gui_test_main_loop();
|
||||||
g_assert_true(settings_has("gui.window.width"));
|
g_assert_true(settings_has("gui.window.width"));
|
||||||
g_assert_true(settings_has("gui.window.height"));
|
g_assert_true(settings_has("gui.window.height"));
|
||||||
|
|
||||||
|
@ -33,11 +22,9 @@ static void test_window()
|
||||||
settings_set("gui.window.height", 600);
|
settings_set("gui.window.height", 600);
|
||||||
gui_window_init("share/ocarina/ocarina.png");
|
gui_window_init("share/ocarina/ocarina.png");
|
||||||
|
|
||||||
g_main_loop_run(main_loop);
|
gui_test_main_loop();
|
||||||
g_assert_cmpuint(settings_get("gui.window.width"), ==, 800);
|
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.height"), ==, 600);
|
||||||
|
|
||||||
g_main_loop_unref(main_loop);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
@ -48,11 +35,13 @@ int main(int argc, char **argv)
|
||||||
gtk_init(&argc, NULL);
|
gtk_init(&argc, NULL);
|
||||||
gui_builder_init("share/ocarina/ocarina.ui");
|
gui_builder_init("share/ocarina/ocarina.ui");
|
||||||
gui_window_init("share/ocarina/ocarina.png");
|
gui_window_init("share/ocarina/ocarina.png");
|
||||||
|
gui_test_init();
|
||||||
|
|
||||||
g_test_init(&argc, &argv, NULL);
|
g_test_init(&argc, &argv, NULL);
|
||||||
g_test_add_func("/Gui/Window", test_window);
|
g_test_add_func("/Gui/Window", test_window);
|
||||||
ret = g_test_run();
|
ret = g_test_run();
|
||||||
|
|
||||||
|
gui_test_deinit();
|
||||||
gui_window_deinit();
|
gui_window_deinit();
|
||||||
gui_builder_deinit();
|
gui_builder_deinit();
|
||||||
settings_deinit();
|
settings_deinit();
|
||||||
|
|
Loading…
Reference in New Issue