tests: Build idle test with ctest

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-03-07 08:28:11 -05:00 committed by Anna Schumaker
parent 4fb854d0b1
commit 10f81461d9
3 changed files with 28 additions and 36 deletions

View File

@ -8,3 +8,4 @@ core_unit_test(Version)
core_unit_test(String) core_unit_test(String)
core_unit_test(File) core_unit_test(File)
core_unit_test(Date) core_unit_test(Date)
core_unit_test(Idle)

View File

@ -27,7 +27,8 @@ Export("core_objs", "CoreTest")
core_objs += [ env.Object("../../core/string.c") ] core_objs += [ env.Object("../../core/string.c") ]
core_objs += [ env.Object("../../core/file.c") ] core_objs += [ env.Object("../../core/file.c") ]
core_objs += [ env.Object("../../core/date.c") ] core_objs += [ env.Object("../../core/date.c") ]
res += [ CoreTest("idle") ] core_objs += [ env.Object("../../core/idle.c") ]
res += [ CoreTest("database") ] res += [ CoreTest("database") ]
res += SConscript("tags/Sconscript") res += SConscript("tags/Sconscript")

View File

@ -3,70 +3,60 @@
* Test the idle queue * Test the idle queue
*/ */
#include <core/idle.h> #include <core/idle.h>
#include <core/string.h>
#include <tests/test.h> #include <tests/test.h>
static unsigned int cur = -1; static unsigned int cur = -1;
static bool func_passed = false;
static bool inc_cur(void *data) static bool inc_cur(void *data)
{ {
unsigned int expected = GPOINTER_TO_INT(data); g_assert_cmpuint(++cur, ==, GPOINTER_TO_UINT(data));
cur++;
func_passed = (cur == expected);
return true; return true;
} }
static void test_idle(gconstpointer arg)
static void test_idle_queue(unsigned int n)
{ {
unsigned int n = GPOINTER_TO_UINT(arg);
cur = -1; cur = -1;
idle_init(); idle_init();
test_equal(idle_progress(), (float)1.0); g_assert_cmpfloat(idle_progress(), ==, 1.0);
test_equal(idle_run_task(), (bool)false); g_assert_false(idle_run_task());
for (unsigned int i = 0; i < n; i++) for (unsigned int i = 0; i < n; i++)
idle_schedule(IDLE_SYNC, inc_cur, GINT_TO_POINTER(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++) { for (unsigned int i = 0; i < (n - 1); i++) {
test_loop_equal(idle_run_task(), (bool)true, i); g_assert_true(idle_run_task());
test_loop_equal(idle_progress(), ((i + 1) / (float)n), i); g_assert_cmpfloat(idle_progress(), ==, ((i + 1) / (float)n));
test_loop_equal(func_passed, (bool)true, i); }
} test_loop_passed();
test_equal(idle_run_task(), (bool)false); g_assert_false(idle_run_task());
test_equal(idle_progress(), (float)1.0); g_assert_cmpfloat(idle_progress(), ==, 1.0);
for (unsigned int i = n; i < (2 * n); i++) for (unsigned int i = n; i < (2 * n); i++)
idle_schedule(IDLE_ASYNC, inc_cur, GINT_TO_POINTER(i)); idle_schedule(IDLE_ASYNC, inc_cur, GINT_TO_POINTER(i));
while (idle_run_task()) {} while (idle_run_task()) {}
test_equal(idle_progress(), (float)1.0); g_assert_cmpfloat(idle_progress(), ==, 1.0);
test_equal(func_passed, (bool)true); g_assert_cmpuint(cur, ==, (2 * n) - 1);
test_equal(cur, (2 * n) - 1);
for (unsigned int i = 0; i < n; i++) for (unsigned int i = 0; i < n; i++)
idle_schedule(IDLE_SYNC, inc_cur, GINT_TO_POINTER(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(); 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); } int main(int argc, char **argv)
static void test_idle_queue_100() { test_idle_queue(100); } {
static void test_idle_queue_1000() { test_idle_queue(1000); } g_test_init(&argc, &argv, NULL);
static void test_idle_queue_10000() { test_idle_queue(10000); } g_test_add_data_func("/Core/Idle/n = 10", GUINT_TO_POINTER( 10), test_idle);
static void test_idle_queue_100000() { test_idle_queue(100000); } 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);
DECLARE_UNIT_TESTS( g_test_add_data_func("/Core/Idle/n = 100,000", GUINT_TO_POINTER(100000), test_idle);
UNIT_TEST("Idle Queue (n = 10)", test_idle_queue_10), return g_test_run();
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),
);