diff options
author | Richard Hughes <richard@hughsie.com> | 2008-03-04 19:51:49 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2008-03-04 19:51:49 +0000 |
commit | 9414accac316da02b07cb91990801a93313cffec (patch) | |
tree | f9e15acb82fa3e69beb94bbe46a828cbe274849d | |
parent | 65a9e7769ee1384ee39f7675927318da455cf4ab (diff) |
use the new libst_elapsed functionality to avoid creating and destroying a GTimer in each self test
-rw-r--r-- | src/pk-backend-dbus.c | 15 | ||||
-rw-r--r-- | src/pk-backend-thread.c | 26 |
2 files changed, 14 insertions, 27 deletions
diff --git a/src/pk-backend-dbus.c b/src/pk-backend-dbus.c index 920d51534..d0c8c165f 100644 --- a/src/pk-backend-dbus.c +++ b/src/pk-backend-dbus.c @@ -1299,13 +1299,11 @@ libst_backend_dbus (LibSelfTest *test) { PkBackendDbus *backend_dbus; gboolean ret; - gdouble time; - GTimer *timer; + guint elapsed; if (libst_start (test, "PkBackendDbus", CLASS_AUTO) == FALSE) { return; } - timer = g_timer_new (); loop = g_main_loop_new (NULL, FALSE); /************************************************************/ @@ -1330,9 +1328,8 @@ libst_backend_dbus (LibSelfTest *test) /************************************************************/ libst_title (test, "set the name and activate"); - g_timer_reset (timer); ret = pk_backend_dbus_set_name (backend_dbus, "org.freedesktop.PackageKitTestBackend"); - time = g_timer_elapsed (timer, NULL); + elapsed = libst_elapsed (test); if (ret == TRUE) { libst_success (test, NULL); } else { @@ -1344,7 +1341,7 @@ libst_backend_dbus (LibSelfTest *test) /************************************************************/ libst_title (test, "check we actually did something and didn't fork"); - if (time > 0.0002) { + if (elapsed > 1) { libst_success (test, "time = %lfs", time); } else { libst_failed (test, "time = %lfs", time); @@ -1355,9 +1352,8 @@ libst_backend_dbus (LibSelfTest *test) /************************************************************/ libst_title (test, "search by name"); - g_timer_reset (timer); ret = pk_backend_dbus_search_file (backend_dbus, "none", "power"); - time = g_timer_elapsed (timer, NULL); + elapsed = libst_elapsed (test); if (ret == TRUE) { libst_success (test, NULL); } else { @@ -1366,7 +1362,7 @@ libst_backend_dbus (LibSelfTest *test) /************************************************************/ libst_title (test, "check we forked and didn't block"); - if (time < 0.1) { + if (elapsed < 100) { libst_success (test, "time = %lfs", time); } else { libst_failed (test, "time = %lfs", time); @@ -1399,7 +1395,6 @@ libst_backend_dbus (LibSelfTest *test) } chicken_out: - g_timer_destroy (timer); g_main_loop_unref (loop); g_object_unref (backend_dbus); diff --git a/src/pk-backend-thread.c b/src/pk-backend-thread.c index 389af3744..a94af6b3e 100644 --- a/src/pk-backend-thread.c +++ b/src/pk-backend-thread.c @@ -187,12 +187,8 @@ libst_backend_thread (LibSelfTest *test) { PkBackendThread *backend_thread; PkBackend *backend; - gboolean ret; - gdouble elapsed; - GTimer *timer; - - timer = g_timer_new (); + guint elapsed; if (libst_start (test, "PkBackendThread", CLASS_AUTO) == FALSE) { return; @@ -222,7 +218,6 @@ libst_backend_thread (LibSelfTest *test) /************************************************************/ libst_title (test, "wait for a thread to return true"); - g_timer_start (timer); ret = pk_backend_thread_create (backend_thread, pk_backend_thread_test_func_true, NULL); if (ret == TRUE) { libst_success (test, NULL); @@ -232,14 +227,14 @@ libst_backend_thread (LibSelfTest *test) /* wait */ pk_thread_list_wait (backend_thread->priv->thread_list); + elapsed = libst_elapsed (test); /************************************************************/ libst_title (test, "did we wait the correct time?"); - elapsed = g_timer_elapsed (timer, NULL); - if (elapsed < 1.1 && elapsed > 0.9) { + if (elapsed < 1100 && elapsed > 900) { libst_success (test, NULL); } else { - libst_failed (test, "did not wait for thread timeout"); + libst_failed (test, "did not wait for thread timeout %ims", elapsed); } /* reset the backend */ @@ -253,7 +248,6 @@ libst_backend_thread (LibSelfTest *test) /************************************************************/ libst_title (test, "wait for a thread to return false"); - g_timer_start (timer); ret = pk_backend_thread_create (backend_thread, pk_backend_thread_test_func_false, NULL); if (ret == TRUE) { libst_success (test, NULL); @@ -263,14 +257,14 @@ libst_backend_thread (LibSelfTest *test) /* wait */ pk_thread_list_wait (backend_thread->priv->thread_list); + elapsed = libst_elapsed (test); /************************************************************/ libst_title (test, "did we wait the correct time2?"); - elapsed = g_timer_elapsed (timer, NULL); - if (elapsed < 1.1 && elapsed > 0.9) { + if (elapsed < 1100 && elapsed > 900) { libst_success (test, NULL); } else { - libst_failed (test, "did not wait for thread timeout"); + libst_failed (test, "did not wait for thread timeout %ims", elapsed); } /* reset the backend */ @@ -284,25 +278,23 @@ libst_backend_thread (LibSelfTest *test) /************************************************************/ libst_title (test, "wait for a thread to return false (straight away)"); - g_timer_start (timer); ret = pk_backend_thread_create (backend_thread, pk_backend_thread_test_func_immediate_false, NULL); if (ret == TRUE) { libst_success (test, NULL); } else { libst_failed (test, "returned false!"); } + elapsed = libst_elapsed (test); /************************************************************/ libst_title (test, "did we wait the correct time2?"); - elapsed = g_timer_elapsed (timer, NULL); - if (elapsed < 0.1) { + if (elapsed < 100) { libst_success (test, NULL); } else { libst_failed (test, "did not wait for thread timeout2"); } g_object_unref (backend_thread); - g_timer_destroy (timer); libst_end (test); } |