tests: Build gui idle test with ctest
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
4e9c5e0a00
commit
0470c6efa6
|
@ -10,3 +10,4 @@ gui_unit_test(Model)
|
|||
gui_unit_test(View)
|
||||
gui_unit_test(Queue)
|
||||
gui_unit_test(Window)
|
||||
gui_unit_test(Idle)
|
||||
|
|
|
@ -30,7 +30,7 @@ gui_objs += [ env.Object("../../gui/model.c") ]
|
|||
gui_objs += [ env.Object("../../gui/view.c") ]
|
||||
gui_objs += [ env.Object("../../gui/queue.c") ]
|
||||
gui_objs += [ env.Object("../../gui/window.c") ]
|
||||
res += [ GuiTest("idle") ]
|
||||
gui_objs += [ env.Object("../../gui/idle.c") ]
|
||||
res += [ GuiTest("sidebar") ]
|
||||
res += [ GuiTest("playlist") ]
|
||||
gui_objs += [ env.Object("../../gui/collection.c") ]
|
||||
|
|
|
@ -1,28 +1,24 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#define TEST_NEED_AUDIO
|
||||
#define TEST_NEED_COLLECTION
|
||||
#define TEST_NEED_PLAYLIST
|
||||
#define TEST_NEED_SIDEBAR
|
||||
#include <core/core.h>
|
||||
#include <core/idle.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/idle.h>
|
||||
#include <gui/settings.h>
|
||||
#include <gui/view.h>
|
||||
#include <tests/gui.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
static const unsigned int N = 100;
|
||||
static unsigned int cur = -1;
|
||||
static bool func_passed = false;
|
||||
struct core_init_data init_data;
|
||||
static GMainLoop *main_loop;
|
||||
|
||||
static bool inc_cur(void *data)
|
||||
{
|
||||
unsigned int expected = GPOINTER_TO_INT(data);
|
||||
cur++;
|
||||
func_passed = (cur == expected);
|
||||
g_assert_cmpuint(cur, ==, GPOINTER_TO_UINT(data));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -38,19 +34,13 @@ static void test_idle()
|
|||
GtkWindow *window;
|
||||
unsigned int i;
|
||||
float fraction;
|
||||
int argc = 0;
|
||||
|
||||
gtk_init(&argc, NULL);
|
||||
gui_builder_init("share/ocarina/ocarina6.glade");
|
||||
core_init(&argc, NULL, &init_data);
|
||||
while (idle_run_task()) {}
|
||||
|
||||
main_loop = g_main_loop_new(NULL, FALSE);
|
||||
window = GTK_WINDOW(gui_builder_widget("o_window"));
|
||||
g_idle_add(test_on_idle, window);
|
||||
|
||||
progress = GTK_PROGRESS_BAR(gui_builder_widget("o_idle_progress"));
|
||||
test_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), false);
|
||||
g_assert_false(gtk_widget_is_visible(GTK_WIDGET(progress)));
|
||||
|
||||
for (i = 0; i < N; i++)
|
||||
idle_schedule(IDLE_SYNC, inc_cur, GINT_TO_POINTER(i));
|
||||
|
@ -58,19 +48,35 @@ static void test_idle()
|
|||
gui_idle_enable();
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
test_loop_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), true, i);
|
||||
g_assert_true(gtk_widget_is_visible(GTK_WIDGET(progress)));
|
||||
g_main_loop_run(main_loop);
|
||||
test_loop_equal(idle_progress(), ((i + 1) / (float)N), i);
|
||||
test_loop_equal(func_passed, (bool)true, i);
|
||||
g_assert_cmpfloat(idle_progress(), ==, (float)(i + 1) / N);
|
||||
if (i != (N - 1)) {
|
||||
fraction = gtk_progress_bar_get_fraction(progress);
|
||||
test_loop_equal(fraction, idle_progress(), i);
|
||||
g_assert_cmpfloat(fraction, ==, idle_progress());
|
||||
}
|
||||
} test_loop_passed();
|
||||
}
|
||||
|
||||
test_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), false);
|
||||
g_assert_false(gtk_widget_is_visible(GTK_WIDGET(progress)));
|
||||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
UNIT_TEST("Idle Progress Bar", test_idle),
|
||||
);
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
|
||||
gtk_init(&argc, NULL);
|
||||
core_init(&argc, NULL, &init_data);
|
||||
gui_builder_init("share/ocarina/ocarina6.glade");
|
||||
gui_settings_init();
|
||||
gui_view_init();
|
||||
while (idle_run_task()) {}
|
||||
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
g_test_add_func("/Gui/Idle", test_idle);
|
||||
ret = g_test_run();
|
||||
|
||||
gui_settings_deinit();
|
||||
gui_builder_deinit();
|
||||
core_deinit();
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue