diff options
-rw-r--r-- | milkway/test/main-loop-test.c | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/milkway/test/main-loop-test.c b/milkway/test/main-loop-test.c index e50b078..fc5735b 100644 --- a/milkway/test/main-loop-test.c +++ b/milkway/test/main-loop-test.c @@ -22,6 +22,7 @@ #include <milkway/milkway.h> #include <milkway/mw-main-loop.h> #include <milkway/mw-timeout-source.h> +#include <milkway/mw-idle-source.h> #include <string.h> #include <stdio.h> @@ -42,6 +43,22 @@ timeout_cb (mw_source_t *source, mw_pointer_t data) return MW_TRUE; } +static mw_bool_t +idle_cb (mw_source_t *source, mw_pointer_t data) +{ + static int times = 1; + + printf ("%d...", times++); + if (times > 10) { + printf ("DONE.\n"); + mw_main_loop_quit(data); + } else { + fflush(stdout); + } + + return MW_TRUE; +} + typedef struct test_a_type test_a_type_t; typedef struct test_a test_a_t; #define TEST_A_TYPE test_a_get_type() @@ -63,7 +80,7 @@ static test_a_t* test_a_init(test_a_t *self, mw_main_loop_t *loop) { - if (!mw_timeout_source_init(&self->base, 500, 0)) + if (!mw_timeout_source_init(&self->base, 300, 0)) return NULL; self->loop = loop; self->count = 1; @@ -122,7 +139,7 @@ test_callback(void) ctx = mw_main_context_new(); loop = mw_main_loop_new(ctx); - source = (mw_source_t*)mw_timeout_source_new(500); + source = (mw_source_t*)mw_timeout_source_new(300); mw_source_set_callback(source, timeout_cb, loop, NULL); mw_main_context_add_source(ctx, source); mw_object_unref(source); @@ -149,10 +166,30 @@ test_subsource(void) mw_object_unref(ctx); } +static void +test_idle(void) +{ + mw_main_context_t *ctx; + mw_main_loop_t *loop; + mw_source_t *source; + + ctx = mw_main_context_new(); + loop = mw_main_loop_new(ctx); + + source = (mw_source_t*)mw_idle_source_new(); + mw_source_set_callback(source, idle_cb, loop, NULL); + mw_main_context_add_source(ctx, source); + mw_object_unref(source); + + mw_main_loop_run(loop); + mw_object_unref(ctx); +} + int main(int argc, char **argv) { test_callback(); test_subsource(); + test_idle(); printf ("main loop test: PASS\n"); |