From 10f81461d993692b85edf67ed0d367c6c599e41a Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 7 Mar 2016 08:28:11 -0500 Subject: [PATCH] tests: Build idle test with ctest Signed-off-by: Anna Schumaker --- tests/core/CMakeLists.txt | 1 + tests/core/Sconscript | 3 +- tests/core/idle.c | 60 ++++++++++++++++----------------------- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index 35ba1fd3..3b19ba45 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -8,3 +8,4 @@ core_unit_test(Version) core_unit_test(String) core_unit_test(File) core_unit_test(Date) +core_unit_test(Idle) diff --git a/tests/core/Sconscript b/tests/core/Sconscript index 911582e7..90b60283 100644 --- a/tests/core/Sconscript +++ b/tests/core/Sconscript @@ -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") diff --git a/tests/core/idle.c b/tests/core/idle.c index fe77156e..85ddd32d 100644 --- a/tests/core/idle.c +++ b/tests/core/idle.c @@ -3,70 +3,60 @@ * 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); + 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(); +}