2016-02-18 08:34:28 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <core/core.h>
|
|
|
|
#include <gui/idle.h>
|
|
|
|
#include <tests/test.h>
|
2017-04-05 15:38:56 -04:00
|
|
|
#include <tests/loop.h>
|
2016-02-18 08:34:28 -05:00
|
|
|
|
2016-08-20 09:01:29 -04:00
|
|
|
static const unsigned int N = 100;
|
|
|
|
static unsigned int cur = -1;
|
2016-02-18 08:34:28 -05:00
|
|
|
|
2016-05-02 18:42:38 -04:00
|
|
|
static bool inc_cur(void *data)
|
2016-02-18 08:34:28 -05:00
|
|
|
{
|
2016-08-20 09:01:29 -04:00
|
|
|
g_assert_cmpuint(++cur, ==, GPOINTER_TO_UINT(data));
|
2016-05-02 18:42:38 -04:00
|
|
|
return true;
|
2016-02-18 08:34:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_idle()
|
|
|
|
{
|
2016-08-20 09:01:29 -04:00
|
|
|
GtkProgressBar *progress = gui_progress_bar();
|
2016-02-18 08:34:28 -05:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < N; i++)
|
2016-04-30 09:16:02 -04:00
|
|
|
idle_schedule(IDLE_SYNC, inc_cur, GINT_TO_POINTER(i));
|
2016-02-18 08:34:28 -05:00
|
|
|
|
2016-08-20 09:01:29 -04:00
|
|
|
g_assert_false(gtk_widget_is_visible(GTK_WIDGET(progress)));
|
2016-02-18 08:34:28 -05:00
|
|
|
gui_idle_enable();
|
2016-08-20 09:01:29 -04:00
|
|
|
g_assert_false(gtk_widget_is_visible(GTK_WIDGET(progress)));
|
2016-02-18 08:34:28 -05:00
|
|
|
|
2016-08-20 09:01:29 -04:00
|
|
|
for (i = 0; i < (N - 1); i++) {
|
2017-04-05 15:38:56 -04:00
|
|
|
test_main_loop();
|
2016-08-20 09:01:29 -04:00
|
|
|
g_assert_true(gtk_widget_is_visible(GTK_WIDGET(progress)));
|
2016-03-24 09:25:02 -04:00
|
|
|
g_assert_cmpfloat(idle_progress(), ==, (float)(i + 1) / N);
|
2016-08-20 09:01:29 -04:00
|
|
|
g_assert_cmpfloat(gtk_progress_bar_get_fraction(progress),
|
|
|
|
==, (float)(i + 1) / N);
|
2016-03-24 09:25:02 -04:00
|
|
|
}
|
2016-02-18 08:34:28 -05:00
|
|
|
|
2017-04-05 15:38:56 -04:00
|
|
|
test_main_loop();
|
2016-03-24 09:25:02 -04:00
|
|
|
g_assert_false(gtk_widget_is_visible(GTK_WIDGET(progress)));
|
2016-02-18 08:34:28 -05:00
|
|
|
}
|
|
|
|
|
2016-03-24 09:25:02 -04:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
gtk_init(&argc, NULL);
|
2016-09-24 10:53:25 -04:00
|
|
|
core_init(&argc, NULL, NULL, NULL, IDLE_SYNC);
|
2016-08-18 14:07:28 -04:00
|
|
|
gui_builder_init("share/ocarina/ocarina.ui");
|
2017-04-05 15:38:56 -04:00
|
|
|
test_loop_init();
|
2016-03-24 09:25:02 -04:00
|
|
|
while (idle_run_task()) {}
|
|
|
|
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
g_test_add_func("/Gui/Idle", test_idle);
|
|
|
|
ret = g_test_run();
|
|
|
|
|
2017-04-05 15:38:56 -04:00
|
|
|
test_loop_deinit();
|
2016-03-24 09:25:02 -04:00
|
|
|
gui_builder_deinit();
|
|
|
|
core_deinit();
|
|
|
|
return ret;
|
|
|
|
}
|