gtestframework.[hc]: implemented g_test_queue_destroy() and g_test_queue_unref().

svn path=/trunk/; revision=5907
This commit is contained in:
Tim Janik 2007-11-20 15:00:57 +00:00
parent 515c53474a
commit f3d2520702
3 changed files with 31 additions and 7 deletions

View File

@ -1265,6 +1265,7 @@ g_test_log_type_name
g_test_maximized_result g_test_maximized_result
g_test_message g_test_message
g_test_minimized_result g_test_minimized_result
g_test_queue_destroy
g_test_queue_free g_test_queue_free
g_test_rand_double g_test_rand_double
g_test_rand_double_range g_test_rand_double_range

View File

@ -46,6 +46,13 @@ struct GTestSuite
GSList *suites; GSList *suites;
GSList *cases; GSList *cases;
}; };
typedef struct DestroyEntry DestroyEntry;
struct DestroyEntry
{
DestroyEntry *next;
GDestroyNotify destroy_func;
gpointer destroy_data;
};
/* --- prototypes --- */ /* --- prototypes --- */
static void test_run_seed (const gchar *rseed); static void test_run_seed (const gchar *rseed);
@ -68,13 +75,13 @@ static GTimer *test_user_timer = NULL;
static double test_user_stamp = 0; static double test_user_stamp = 0;
static GSList *test_paths = NULL; static GSList *test_paths = NULL;
static GTestSuite *test_suite_root = NULL; static GTestSuite *test_suite_root = NULL;
static GSList *test_run_free_queue = NULL;
static int test_trap_last_status = 0; static int test_trap_last_status = 0;
static int test_trap_last_pid = 0; static int test_trap_last_pid = 0;
static char *test_trap_last_stdout = NULL; static char *test_trap_last_stdout = NULL;
static char *test_trap_last_stderr = NULL; static char *test_trap_last_stderr = NULL;
static char *test_uri_base = NULL; static char *test_uri_base = NULL;
static gboolean test_debug_log = FALSE; static gboolean test_debug_log = FALSE;
static DestroyEntry *test_destroy_queue = NULL;
const GTestConfig *g_test_config_vars = NULL; const GTestConfig *g_test_config_vars = NULL;
static GTestConfig mutable_test_config_vars = { static GTestConfig mutable_test_config_vars = {
TRUE, /* test_quick */ TRUE, /* test_quick */
@ -648,7 +655,20 @@ void
g_test_queue_free (gpointer gfree_pointer) g_test_queue_free (gpointer gfree_pointer)
{ {
if (gfree_pointer) if (gfree_pointer)
test_run_free_queue = g_slist_prepend (test_run_free_queue, gfree_pointer); g_test_queue_destroy (g_free, gfree_pointer);
}
void
g_test_queue_destroy (GDestroyNotify destroy_func,
gpointer destroy_data)
{
DestroyEntry *dentry;
g_return_if_fail (destroy_func != NULL);
dentry = g_slice_new0 (DestroyEntry);
dentry->destroy_func = destroy_func;
dentry->destroy_data = destroy_data;
dentry->next = test_destroy_queue;
test_destroy_queue = dentry;
} }
static int static int
@ -676,11 +696,12 @@ test_case_run (GTestCase *tc)
tc->fixture_setup (fixture); tc->fixture_setup (fixture);
tc->fixture_test (fixture); tc->fixture_test (fixture);
test_trap_clear(); test_trap_clear();
while (test_run_free_queue) while (test_destroy_queue)
{ {
gpointer freeme = test_run_free_queue->data; DestroyEntry *dentry = test_destroy_queue;
test_run_free_queue = g_slist_delete_link (test_run_free_queue, test_run_free_queue); test_destroy_queue = dentry->next;
g_free (freeme); dentry->destroy_func (dentry->destroy_data);
g_slice_free (DestroyEntry, dentry);
} }
if (tc->fixture_teardown) if (tc->fixture_teardown)
tc->fixture_teardown (fixture); tc->fixture_teardown (fixture);

View File

@ -95,7 +95,9 @@ double g_test_timer_last (void); // repeat last elapsed() result
/* automatically g_free or g_object_unref upon teardown */ /* automatically g_free or g_object_unref upon teardown */
void g_test_queue_free (gpointer gfree_pointer); void g_test_queue_free (gpointer gfree_pointer);
void g_test_queue_unref (gpointer gobjectunref_pointer); void g_test_queue_destroy (GDestroyNotify destroy_func,
gpointer destroy_data);
#define g_test_queue_unref(gobject) g_test_queue_destroy (g_object_unref, gobject)
/* test traps are guards used around forked tests */ /* test traps are guards used around forked tests */
typedef enum { typedef enum {