tests: Build idle test with ctest
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
4fb854d0b1
commit
10f81461d9
|
@ -8,3 +8,4 @@ core_unit_test(Version)
|
|||
core_unit_test(String)
|
||||
core_unit_test(File)
|
||||
core_unit_test(Date)
|
||||
core_unit_test(Idle)
|
||||
|
|
|
@ -27,7 +27,8 @@ Export("core_objs", "CoreTest")
|
|||
core_objs += [ env.Object("../../core/string.c") ]
|
||||
core_objs += [ env.Object("../../core/file.c") ]
|
||||
core_objs += [ env.Object("../../core/date.c") ]
|
||||
res += [ CoreTest("idle") ]
|
||||
core_objs += [ env.Object("../../core/idle.c") ]
|
||||
|
||||
res += [ CoreTest("database") ]
|
||||
|
||||
res += SConscript("tags/Sconscript")
|
||||
|
|
|
@ -3,70 +3,60 @@
|
|||
* Test the idle queue
|
||||
*/
|
||||
#include <core/idle.h>
|
||||
#include <core/string.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
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);
|
||||
g_assert_cmpuint(++cur, ==, GPOINTER_TO_UINT(data));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static void test_idle_queue(unsigned int n)
|
||||
static void test_idle(gconstpointer arg)
|
||||
{
|
||||
unsigned int n = GPOINTER_TO_UINT(arg);
|
||||
cur = -1;
|
||||
|
||||
idle_init();
|
||||
|
||||
test_equal(idle_progress(), (float)1.0);
|
||||
test_equal(idle_run_task(), (bool)false);
|
||||
g_assert_cmpfloat(idle_progress(), ==, 1.0);
|
||||
g_assert_false(idle_run_task());
|
||||
|
||||
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);
|
||||
g_assert_cmpfloat(idle_progress(), ==, 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();
|
||||
g_assert_true(idle_run_task());
|
||||
g_assert_cmpfloat(idle_progress(), ==, ((i + 1) / (float)n));
|
||||
}
|
||||
|
||||
test_equal(idle_run_task(), (bool)false);
|
||||
test_equal(idle_progress(), (float)1.0);
|
||||
g_assert_false(idle_run_task());
|
||||
g_assert_cmpfloat(idle_progress(), ==, 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);
|
||||
g_assert_cmpfloat(idle_progress(), ==, 1.0);
|
||||
g_assert_cmpuint(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);
|
||||
g_assert_cmpfloat(idle_progress(), ==, 0.0);
|
||||
|
||||
idle_deinit();
|
||||
test_equal(idle_progress(), (float)1.0);
|
||||
g_assert_cmpfloat(idle_progress(), ==, 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),
|
||||
);
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
g_test_add_data_func("/Core/Idle/n = 10", GUINT_TO_POINTER( 10), test_idle);
|
||||
g_test_add_data_func("/Core/Idle/n = 100", GUINT_TO_POINTER( 100), test_idle);
|
||||
g_test_add_data_func("/Core/Idle/n = 1,000", GUINT_TO_POINTER( 1000), test_idle);
|
||||
g_test_add_data_func("/Core/Idle/n = 10,000", GUINT_TO_POINTER( 10000), test_idle);
|
||||
g_test_add_data_func("/Core/Idle/n = 100,000", GUINT_TO_POINTER(100000), test_idle);
|
||||
return g_test_run();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue