/* * Copyright 2014 (c) Anna Schumaker. * Test the idle queue */ #include #include #include static unsigned int cur = -1; static bool func_passed = false; static bool inc_cur(void *data) { unsigned int expected = GPOINTER_TO_INT(data); cur++; func_passed = (cur == expected); return true; } static void test_idle_queue(unsigned int n) { cur = -1; idle_init(); test_equal(idle_progress(), (float)1.0); test_equal(idle_run_task(), (bool)false); for (unsigned int i = 0; i < n; i++) idle_schedule(IDLE_SYNC, inc_cur, GINT_TO_POINTER(i)); test_equal(idle_progress(), (float)0.0); for (unsigned int i = 0; i < (n - 1); i++) { test_loop_equal(idle_run_task(), (bool)true, i); test_loop_equal(idle_progress(), ((i + 1) / (float)n), i); test_loop_equal(func_passed, (bool)true, i); } test_loop_passed(); test_equal(idle_run_task(), (bool)false); test_equal(idle_progress(), (float)1.0); for (unsigned int i = n; i < (2 * n); i++) idle_schedule(IDLE_ASYNC, inc_cur, GINT_TO_POINTER(i)); while (idle_run_task()) {} test_equal(idle_progress(), (float)1.0); test_equal(func_passed, (bool)true); test_equal(cur, (2 * n) - 1); for (unsigned int i = 0; i < n; i++) idle_schedule(IDLE_SYNC, inc_cur, GINT_TO_POINTER(i)); test_equal(idle_progress(), (float)0.0); idle_deinit(); test_equal(idle_progress(), (float)1.0); } static void test_idle_queue_10() { test_idle_queue(10); } static void test_idle_queue_100() { test_idle_queue(100); } static void test_idle_queue_1000() { test_idle_queue(1000); } static void test_idle_queue_10000() { test_idle_queue(10000); } static void test_idle_queue_100000() { test_idle_queue(100000); } DECLARE_UNIT_TESTS( UNIT_TEST("Idle Queue (n = 10)", test_idle_queue_10), UNIT_TEST("Idle Queue (n = 100)", test_idle_queue_100), UNIT_TEST("Idle Queue (n = 1000)", test_idle_queue_1000), UNIT_TEST("Idle Queue (n = 10000)", test_idle_queue_10000), UNIT_TEST("Idle Queue (n = 100000)", test_idle_queue_100000), );