static gchar *test_run_seedstr = NULL;
static GRand *test_run_rand = NULL;
static gchar *test_run_name = "";
+static GTimer *test_run_timer = NULL;
+static GTimer *test_user_timer = NULL;
+static double test_user_stamp = 0;
static GSList *test_paths = NULL;
static GTestSuite *test_suite_root = NULL;
static GSList *test_run_free_queue = NULL;
test_run_seed (test_run_seedstr);
if (test_run_seedstr == seedstr)
g_printerr ("NOTE: random-seed: %s\n", test_run_seedstr);
+
+ /* misc setups */
+ test_run_timer = g_timer_new();
}
static void
return g_rand_double_range (test_run_rand, range_start, range_end);
}
+void
+g_test_timer_start (void)
+{
+ if (!test_user_timer)
+ test_user_timer = g_timer_new();
+ test_user_stamp = 0;
+ g_timer_start (test_user_timer);
+}
+
+double
+g_test_timer_elapsed (void)
+{
+ test_user_stamp = test_user_timer ? g_timer_elapsed (test_user_timer, NULL) : 0;
+ return test_user_stamp;
+}
+
+double
+g_test_timer_last (void)
+{
+ return test_user_stamp;
+}
+
GTestSuite*
g_test_get_root (void)
{
static int
test_case_run (GTestCase *tc)
{
- gchar *old_name = test_run_name;
+ gchar *old_name;
+ g_timer_start (test_run_timer);
+ old_name = test_run_name;
test_run_name = g_strconcat (old_name, "/", tc->name, NULL);
if (test_run_list)
g_print ("%s\n", test_run_name);
}
g_free (test_run_name);
test_run_name = old_name;
+ g_timer_stop (test_run_timer);
+ /* FIXME: need reporting here */
return 0;
}
g_assert_cmpstr ("fzz", ==, "fzz");
}
+/* test g_test_timer* API */
+static void
+test_timer (void)
+{
+ double ttime;
+ g_test_timer_start();
+ g_assert_cmpfloat (g_test_timer_last(), ==, 0);
+ g_usleep (25 * 1000);
+ ttime = g_test_timer_elapsed();
+ g_assert_cmpfloat (ttime, >, 0);
+ g_assert_cmpfloat (g_test_timer_last(), ==, ttime);
+}
+
/* fork out for a failing test */
static void
test_fork_fail (void)
g_test_add_func ("/random-generator/rand-2", test_rand2);
g_test_add_func ("/misc/assertions", test_assertions);
g_test_add ("/misc/primetoul", Fixturetest, fixturetest_setup, fixturetest_test, fixturetest_teardown);
+ g_test_add_func ("/misc/timer", test_timer);
g_test_add_func ("/forking/fail assertion", test_fork_fail);
g_test_add_func ("/forking/patterns", test_fork_patterns);
g_test_add_func ("/forking/timeout", test_fork_timeout);