glib/tests: fix leaks

https://bugzilla.gnome.org/show_bug.cgi?id=682560
This commit is contained in:
Dan Winship 2012-08-23 12:48:49 -04:00
parent 0c0cdfd9c4
commit 1a2c5e155d
19 changed files with 574 additions and 472 deletions

View File

@ -167,6 +167,8 @@ test_async_queue_threads (void)
g_assert_cmpint (s, ==, total);
g_assert_cmpint (c, ==, 1000);
g_async_queue_unref (q);
}
static void
@ -201,6 +203,8 @@ test_async_queue_timed (void)
diff = end - start;
g_assert_cmpint (diff, >=, G_USEC_PER_SEC / 10);
g_assert_cmpint (diff, <, G_USEC_PER_SEC);
g_async_queue_unref (q);
}
int

View File

@ -287,7 +287,8 @@ main (int argc, char *argv[])
while ((name = g_dir_read_name (dir)) != NULL)
{
path = g_strdup_printf ("/bookmarks/parse/%s", name);
g_test_add_data_func (path, g_build_filename (SRCDIR, "bookmarks", name, NULL), test_file);
g_test_add_data_func_full (path, g_build_filename (SRCDIR, "bookmarks", name, NULL),
test_file, g_free);
g_free (path);
}
g_dir_close (dir);

View File

@ -752,15 +752,18 @@ add_checksum_test (GChecksumType type,
{
ChecksumTest *test;
gchar *path;
test = g_new0 (ChecksumTest, 1);
test->checksum_type = type;
test->sum = sum;
test->length = length;
path = g_strdup_printf ("/checksum/%s/%d", type_name, length);
g_test_add_data_func (path, test, test_checksum);
g_free (path);
path = g_strdup_printf ("/checksum/%s/reset/%d", type_name, length);
g_test_add_data_func (path, test, test_checksum_reset);
g_test_add_data_func_full (path, test, test_checksum_reset, g_free);
g_free (path);
}
@ -771,11 +774,13 @@ add_checksum_string_test (GChecksumType type,
{
ChecksumComputeTest *test;
gchar *path;
test = g_new0 (ChecksumComputeTest, 1);
test->checksum_type = type;
test->sums = sums;
path = g_strdup_printf ("/checksum/%s/string", type_name);
g_test_add_data_func (path, test, test_checksum_string);
g_test_add_data_func_full (path, test, test_checksum_string, g_free);
g_free (path);
}
@ -786,11 +791,13 @@ add_checksum_bytes_test (GChecksumType type,
{
ChecksumComputeTest *test;
gchar *path;
test = g_new0 (ChecksumComputeTest, 1);
test->checksum_type = type;
test->sums = sums;
path = g_strdup_printf ("/checksum/%s/bytes", type_name);
g_test_add_data_func (path, test, test_checksum_bytes);
g_test_add_data_func_full (path, test, test_checksum_bytes, g_free);
g_free (path);
}

View File

@ -10,10 +10,16 @@ typedef struct {
} CollateTest;
typedef struct {
const gchar *key;
gchar *key;
const gchar *str;
} Line;
static void
clear_line (Line *line)
{
g_free (line->key);
}
static int
compare_collate (const void *a, const void *b)
{
@ -35,10 +41,13 @@ compare_key (const void *a, const void *b)
static void
do_collate (gboolean for_file, gboolean use_key, const CollateTest *test)
{
GArray *line_array = g_array_new (FALSE, FALSE, sizeof(Line));
GArray *line_array;
Line line;
gint i;
line_array = g_array_new (FALSE, FALSE, sizeof(Line));
g_array_set_clear_func (line_array, (GDestroyNotify)clear_line);
for (i = 0; test->input[i]; i++)
{
line.str = test->input[i];
@ -61,6 +70,8 @@ do_collate (gboolean for_file, gboolean use_key, const CollateTest *test)
else
g_assert_cmpstr (str, ==, test->sorted[i]);
}
g_array_free (line_array, TRUE);
}
static void

View File

@ -170,6 +170,13 @@ barrier_wait (Barrier *barrier)
return ret;
}
static void
barrier_clear (Barrier *barrier)
{
g_mutex_clear (&barrier->mutex);
g_cond_clear (&barrier->cond);
}
static Barrier b;
static gint check;
@ -220,6 +227,8 @@ test_cond2 (void)
g_thread_join (threads[i]);
g_assert_cmpint (g_atomic_int_get (&check), ==, 10);
barrier_clear (&b);
}
int

View File

@ -699,6 +699,7 @@ test_no_conv (void)
/* error code is unreliable, since we mishandle errno there */
g_assert (error && error->domain == G_CONVERT_ERROR);
g_error_free (error);
}
int

View File

@ -125,6 +125,8 @@ test_dataset_foreach (void)
g_dataset_set_data_full (location, "test3", "test3", notify);
g_dataset_foreach (location, foreach, &my_count);
g_assert (my_count == 3);
g_dataset_destroy (location);
}
static void

View File

@ -669,6 +669,7 @@ test_file_open_tmp (void)
g_assert_no_error (error);
g_assert (name != NULL);
unlink (name);
g_free (name);
close (fd);
fd = g_file_open_tmp (NULL, &name, &error);
@ -676,6 +677,7 @@ test_file_open_tmp (void)
g_assert_no_error (error);
g_assert (name != NULL);
g_unlink (name);
g_free (name);
close (fd);
name = NULL;

View File

@ -107,6 +107,7 @@ context_clear (struct context *ctx)
g_assert (ctx->pending_tokens == NULL);
g_assert (ctx->quit);
g_mutex_clear (&ctx->lock);
g_wakeup_free (ctx->wakeup);
}

View File

@ -247,6 +247,16 @@ test_priorities (void)
g_main_context_unref (ctx);
}
static gboolean
quit_loop (gpointer data)
{
GMainLoop *loop = data;
g_main_loop_quit (loop);
return G_SOURCE_REMOVE;
}
static gint count;
static gboolean
@ -276,9 +286,11 @@ static gpointer
thread_func (gpointer data)
{
GMainContext *ctx = data;
GMainLoop *loop;
GSource *source;
g_main_context_push_thread_default (ctx);
loop = g_main_loop_new (ctx, FALSE);
g_mutex_lock (&mutex);
thread_ready = TRUE;
@ -286,12 +298,14 @@ thread_func (gpointer data)
g_mutex_unlock (&mutex);
source = g_timeout_source_new (500);
g_source_set_callback (source, (GSourceFunc)g_thread_exit, NULL, NULL);
g_source_set_callback (source, quit_loop, loop, NULL);
g_source_attach (source, ctx);
g_source_unref (source);
while (TRUE)
g_main_context_iteration (ctx, TRUE);
g_main_loop_run (loop);
g_main_context_pop_thread_default (ctx);
g_main_loop_unref (loop);
return NULL;
}
@ -328,16 +342,8 @@ test_invoke (void)
g_thread_join (thread);
g_assert_cmpint (count, ==, 3);
}
static gboolean
quit_loop (gpointer data)
{
GMainLoop *loop = data;
g_main_loop_quit (loop);
return G_SOURCE_REMOVE;
g_main_context_unref (ctx);
}
static gboolean
@ -353,6 +359,7 @@ run_inner_loop (gpointer user_data)
timeout = g_timeout_source_new (100);
g_source_set_callback (timeout, quit_loop, inner, NULL);
g_source_attach (timeout, ctx);
g_source_unref (timeout);
g_main_loop_run (inner);
g_main_loop_unref (inner);
@ -429,6 +436,7 @@ test_child_sources (void)
g_assert_cmpint (b, ==, 3);
g_assert_cmpint (c, ==, 3);
g_source_destroy (parent);
g_source_unref (parent);
g_source_unref (child_b);
g_source_unref (child_c);
@ -485,6 +493,7 @@ test_recursive_child_sources (void)
g_assert_cmpint (b, ==, 9);
g_assert_cmpint (c, ==, 4);
g_source_destroy (parent);
g_source_unref (parent);
g_source_unref (child_b);
g_source_unref (child_c);

View File

@ -304,7 +304,8 @@ main (int argc, char *argv[])
continue;
path = g_strdup_printf ("/markup/parse/%s", name);
g_test_add_data_func (path, g_build_filename (SRCDIR, "markups", name, NULL), test_parse);
g_test_add_data_func_full (path, g_build_filename (SRCDIR, "markups", name, NULL),
test_parse, g_free);
g_free (path);
}
g_dir_close (dir);

View File

@ -2119,7 +2119,7 @@ test_group_parse (void)
{ "faz", 'z', 0, G_OPTION_ARG_STRING, &arg5, NULL, NULL },
{ NULL }
};
gchar **argv;
gchar **argv, **orig_argv;
gint argc;
GError *error = NULL;
gboolean retval;
@ -2131,7 +2131,10 @@ test_group_parse (void)
g_option_context_add_group (context, group);
argv = split_string ("program --test arg1 -f arg2 --group-test arg3 --frob arg4 -z arg5", &argc);
orig_argv = g_memdup (argv, (argc + 1) * sizeof (char *));
retval = g_option_context_parse (context, &argc, &argv, &error);
g_assert_no_error (error);
g_assert (retval);
g_assert_cmpstr (arg1, ==, "arg1");
@ -2145,6 +2148,9 @@ test_group_parse (void)
g_free (arg3);
g_free (arg4);
g_free (arg5);
g_free (argv);
g_strfreev (orig_argv);
g_option_context_free (context);
}

View File

@ -498,8 +498,9 @@ random_test (gconstpointer d)
case REMOVE:
if (!g_queue_is_empty (q))
g_queue_remove (q, qinf->tail->data);
/* qinf->head/qinf->tail may be invalid at this point */
if (!g_queue_is_empty (q))
g_queue_remove (q, qinf->head->data);
g_queue_remove (q, q->head->data);
if (!g_queue_is_empty (q))
g_queue_remove (q, g_queue_peek_nth (q, get_random_position (q, TRUE)));
@ -510,8 +511,9 @@ random_test (gconstpointer d)
case REMOVE_ALL:
if (!g_queue_is_empty (q))
g_queue_remove_all (q, qinf->tail->data);
/* qinf->head/qinf->tail may be invalid at this point */
if (!g_queue_is_empty (q))
g_queue_remove_all (q, qinf->head->data);
g_queue_remove_all (q, q->head->data);
if (!g_queue_is_empty (q))
g_queue_remove_all (q, g_queue_peek_nth (q, get_random_position (q, TRUE)));

View File

@ -92,7 +92,7 @@ test_new (gconstpointer d)
data->expected_error = 0; \
data->check_flags = FALSE; \
path = g_strdup_printf ("/regex/new/%d", ++total); \
g_test_add_data_func (path, data, test_new); \
g_test_add_data_func_full (path, data, test_new, g_free); \
g_free (path); \
}
@ -108,7 +108,7 @@ test_new (gconstpointer d)
data->real_compile_opts = _real_compile_opts; \
data->real_match_opts = _real_match_opts; \
path = g_strdup_printf ("/regex/new-check-flags/%d", ++total); \
g_test_add_data_func (path, data, test_new); \
g_test_add_data_func_full (path, data, test_new, g_free); \
g_free (path); \
}
@ -135,7 +135,7 @@ test_new_fail (gconstpointer d)
data->match_opts = 0; \
data->expected_error = _expected_error; \
path = g_strdup_printf ("/regex/new-fail/%d", ++total); \
g_test_add_data_func (path, data, test_new_fail); \
g_test_add_data_func_full (path, data, test_new_fail, g_free); \
g_free (path); \
}
@ -170,7 +170,7 @@ test_match_simple (gconstpointer d)
data->match_opts = _match_opts; \
data->expected = _expected; \
path = g_strdup_printf ("/regex/match-%s/%d", _name, ++total); \
g_test_add_data_func (path, data, test_match_simple); \
g_test_add_data_func_full (path, data, test_match_simple, g_free); \
g_free (path); \
}
@ -221,7 +221,7 @@ test_match (gconstpointer d)
data->match_opts2 = _match_opts2; \
data->expected = _expected; \
path = g_strdup_printf ("/regex/match/%d", ++total); \
g_test_add_data_func (path, data, test_match); \
g_test_add_data_func_full (path, data, test_match, g_free); \
g_free (path); \
}
@ -302,6 +302,15 @@ test_match_next (gconstpointer d)
g_slist_free_full (matches, free_match);
}
static void
free_match_next_data (gpointer _data)
{
TestMatchNextData *data = _data;
g_slist_free_full (data->expected, g_free);
g_free (data);
}
#define TEST_MATCH_NEXT0(_pattern, _string, _string_len, _start_position) { \
TestMatchNextData *data; \
gchar *path; \
@ -312,7 +321,7 @@ test_match_next (gconstpointer d)
data->start_position = _start_position; \
data->expected = NULL; \
path = g_strdup_printf ("/regex/match/next0/%d", ++total); \
g_test_add_data_func (path, data, test_match_next); \
g_test_add_data_func_full (path, data, test_match_next, free_match_next_data); \
g_free (path); \
}
@ -332,7 +341,7 @@ test_match_next (gconstpointer d)
match->end = e1; \
data->expected = g_slist_append (NULL, match); \
path = g_strdup_printf ("/regex/match/next1/%d", ++total); \
g_test_add_data_func (path, data, test_match_next); \
g_test_add_data_func_full (path, data, test_match_next, free_match_next_data); \
g_free (path); \
}
@ -357,7 +366,7 @@ test_match_next (gconstpointer d)
match->end = e2; \
data->expected = g_slist_append (data->expected, match); \
path = g_strdup_printf ("/regex/match/next2/%d", ++total); \
g_test_add_data_func (path, data, test_match_next); \
g_test_add_data_func_full (path, data, test_match_next, free_match_next_data); \
g_free (path); \
}
@ -387,7 +396,7 @@ test_match_next (gconstpointer d)
match->end = e3; \
data->expected = g_slist_append (data->expected, match); \
path = g_strdup_printf ("/regex/match/next3/%d", ++total); \
g_test_add_data_func (path, data, test_match_next); \
g_test_add_data_func_full (path, data, test_match_next, free_match_next_data); \
g_free (path); \
}
@ -422,7 +431,7 @@ test_match_next (gconstpointer d)
match->end = e4; \
data->expected = g_slist_append (data->expected, match); \
path = g_strdup_printf ("/regex/match/next4/%d", ++total); \
g_test_add_data_func (path, data, test_match_next); \
g_test_add_data_func_full (path, data, test_match_next, free_match_next_data); \
g_free (path); \
}
@ -468,7 +477,7 @@ test_match_count (gconstpointer d)
data->match_opts = _match_opts; \
data->expected_count = _expected_count; \
path = g_strdup_printf ("/regex/match/count/%d", ++total); \
g_test_add_data_func (path, data, test_match_count); \
g_test_add_data_func_full (path, data, test_match_count, g_free); \
g_free (path); \
}
@ -506,7 +515,7 @@ test_partial (gconstpointer d)
data->match_opts = _match_opts; \
data->expected = _expected; \
path = g_strdup_printf ("/regex/match/partial/%d", ++total); \
g_test_add_data_func (path, data, test_partial); \
g_test_add_data_func_full (path, data, test_partial, g_free); \
g_free (path); \
}
@ -562,7 +571,7 @@ test_sub_pattern (gconstpointer d)
data->expected_start = _expected_start; \
data->expected_end = _expected_end; \
path = g_strdup_printf ("/regex/match/subpattern/%d", ++total); \
g_test_add_data_func (path, data, test_sub_pattern); \
g_test_add_data_func_full (path, data, test_sub_pattern, g_free); \
g_free (path); \
}
@ -617,7 +626,7 @@ test_named_sub_pattern (gconstpointer d)
data->expected_start = _expected_start; \
data->expected_end = _expected_end; \
path = g_strdup_printf ("/regex/match/named/subpattern/%d", ++total); \
g_test_add_data_func (path, data, test_named_sub_pattern); \
g_test_add_data_func_full (path, data, test_named_sub_pattern, g_free); \
g_free (path); \
}
@ -635,7 +644,7 @@ test_named_sub_pattern (gconstpointer d)
data->expected_start = _expected_start; \
data->expected_end = _expected_end; \
path = g_strdup_printf ("/regex/match/subpattern/named/dupnames/%d", ++total); \
g_test_add_data_func (path, data, test_named_sub_pattern); \
g_test_add_data_func_full (path, data, test_named_sub_pattern, g_free); \
g_free (path); \
}
@ -682,6 +691,15 @@ test_fetch_all (gconstpointer d)
g_strfreev (matches);
}
static void
free_fetch_all_data (gpointer _data)
{
TestFetchAllData *data = _data;
g_slist_free (data->expected);
g_free (data);
}
#define TEST_FETCH_ALL0(_pattern, _string) { \
TestFetchAllData *data; \
gchar *path; \
@ -690,7 +708,7 @@ test_fetch_all (gconstpointer d)
data->string = _string; \
data->expected = NULL; \
path = g_strdup_printf ("/regex/fetch-all0/%d", ++total); \
g_test_add_data_func (path, data, test_fetch_all); \
g_test_add_data_func_full (path, data, test_fetch_all, free_fetch_all_data); \
g_free (path); \
}
@ -702,7 +720,7 @@ test_fetch_all (gconstpointer d)
data->string = _string; \
data->expected = g_slist_append (NULL, e1); \
path = g_strdup_printf ("/regex/fetch-all1/%d", ++total); \
g_test_add_data_func (path, data, test_fetch_all); \
g_test_add_data_func_full (path, data, test_fetch_all, free_fetch_all_data); \
g_free (path); \
}
@ -715,7 +733,7 @@ test_fetch_all (gconstpointer d)
data->expected = g_slist_append (NULL, e1); \
data->expected = g_slist_append (data->expected, e2); \
path = g_strdup_printf ("/regex/fetch-all2/%d", ++total); \
g_test_add_data_func (path, data, test_fetch_all); \
g_test_add_data_func_full (path, data, test_fetch_all, free_fetch_all_data); \
g_free (path); \
}
@ -729,7 +747,7 @@ test_fetch_all (gconstpointer d)
data->expected = g_slist_append (data->expected, e2); \
data->expected = g_slist_append (data->expected, e3); \
path = g_strdup_printf ("/regex/fetch-all3/%d", ++total); \
g_test_add_data_func (path, data, test_fetch_all); \
g_test_add_data_func_full (path, data, test_fetch_all, free_fetch_all_data); \
g_free (path); \
}
@ -767,7 +785,7 @@ test_split_simple (gconstpointer d)
data->string = _string; \
data->expected = NULL; \
path = g_strdup_printf ("/regex/split/simple0/%d", ++total); \
g_test_add_data_func (path, data, test_split_simple); \
g_test_add_data_func_full (path, data, test_split_simple, free_fetch_all_data); \
g_free (path); \
}
@ -779,7 +797,7 @@ test_split_simple (gconstpointer d)
data->string = _string; \
data->expected = g_slist_append (NULL, e1); \
path = g_strdup_printf ("/regex/split/simple1/%d", ++total); \
g_test_add_data_func (path, data, test_split_simple); \
g_test_add_data_func_full (path, data, test_split_simple, free_fetch_all_data); \
g_free (path); \
}
@ -792,7 +810,7 @@ test_split_simple (gconstpointer d)
data->expected = g_slist_append (NULL, e1); \
data->expected = g_slist_append (data->expected, e2); \
path = g_strdup_printf ("/regex/split/simple2/%d", ++total); \
g_test_add_data_func (path, data, test_split_simple); \
g_test_add_data_func_full (path, data, test_split_simple, free_fetch_all_data); \
g_free (path); \
}
@ -806,7 +824,7 @@ test_split_simple (gconstpointer d)
data->expected = g_slist_append (data->expected, e2); \
data->expected = g_slist_append (data->expected, e3); \
path = g_strdup_printf ("/regex/split/simple3/%d", ++total); \
g_test_add_data_func (path, data, test_split_simple); \
g_test_add_data_func_full (path, data, test_split_simple, free_fetch_all_data); \
g_free (path); \
}
@ -884,14 +902,14 @@ test_split (gconstpointer d)
data->start_position = _start_position; \
data->max_tokens = _max_tokens; \
data->expected = NULL; \
path = g_strdup_printf ("/regex/full-split0/%d", ++total); \
g_test_add_data_func (path, data, test_split_full); \
g_free (path); \
if (_start_position == 0 && _max_tokens <= 0) { \
path = g_strdup_printf ("/regex/split0/%d", ++total); \
g_test_add_data_func (path, data, test_split); \
g_free (path); \
} \
path = g_strdup_printf ("/regex/full-split0/%d", ++total); \
g_test_add_data_func_full (path, data, test_split_full, free_fetch_all_data); \
g_free (path); \
}
#define TEST_SPLIT1(_pattern, _string, _start_position, _max_tokens, e1) { \
@ -904,14 +922,14 @@ test_split (gconstpointer d)
data->max_tokens = _max_tokens; \
data->expected = NULL; \
data->expected = g_slist_append (data->expected, e1); \
path = g_strdup_printf ("/regex/full-split1/%d", ++total); \
g_test_add_data_func (path, data, test_split_full); \
g_free (path); \
if (_start_position == 0 && _max_tokens <= 0) { \
path = g_strdup_printf ("/regex/split1/%d", ++total); \
g_test_add_data_func (path, data, test_split); \
g_free (path); \
} \
path = g_strdup_printf ("/regex/full-split1/%d", ++total); \
g_test_add_data_func_full (path, data, test_split_full, free_fetch_all_data); \
g_free (path); \
}
#define TEST_SPLIT2(_pattern, _string, _start_position, _max_tokens, e1, e2) { \
@ -925,14 +943,14 @@ test_split (gconstpointer d)
data->expected = NULL; \
data->expected = g_slist_append (data->expected, e1); \
data->expected = g_slist_append (data->expected, e2); \
path = g_strdup_printf ("/regex/full-split2/%d", ++total); \
g_test_add_data_func (path, data, test_split_full); \
g_free (path); \
if (_start_position == 0 && _max_tokens <= 0) { \
path = g_strdup_printf ("/regex/split2/%d", ++total); \
g_test_add_data_func (path, data, test_split); \
g_free (path); \
} \
path = g_strdup_printf ("/regex/full-split2/%d", ++total); \
g_test_add_data_func_full (path, data, test_split_full, free_fetch_all_data); \
g_free (path); \
}
#define TEST_SPLIT3(_pattern, _string, _start_position, _max_tokens, e1, e2, e3) { \
@ -947,14 +965,14 @@ test_split (gconstpointer d)
data->expected = g_slist_append (data->expected, e1); \
data->expected = g_slist_append (data->expected, e2); \
data->expected = g_slist_append (data->expected, e3); \
path = g_strdup_printf ("/regex/full-split3/%d", ++total); \
g_test_add_data_func (path, data, test_split_full); \
g_free (path); \
if (_start_position == 0 && _max_tokens <= 0) { \
path = g_strdup_printf ("/regex/split3/%d", ++total); \
g_test_add_data_func (path, data, test_split); \
g_free (path); \
} \
path = g_strdup_printf ("/regex/full-split3/%d", ++total); \
g_test_add_data_func_full (path, data, test_split_full, free_fetch_all_data); \
g_free (path); \
}
typedef struct {
@ -985,7 +1003,7 @@ test_check_replacement (gconstpointer d)
data->expected = _expected; \
data->expected_refs = _expected_refs; \
path = g_strdup_printf ("/regex/check-repacement/%d", ++total); \
g_test_add_data_func (path, data, test_check_replacement); \
g_test_add_data_func_full (path, data, test_check_replacement, g_free); \
g_free (path); \
}
@ -1029,7 +1047,7 @@ test_expand (gconstpointer d)
data->raw = _raw; \
data->expected = _expected; \
path = g_strdup_printf ("/regex/expand/%d", ++total); \
g_test_add_data_func (path, data, test_expand); \
g_test_add_data_func_full (path, data, test_expand, g_free); \
g_free (path); \
}
@ -1067,7 +1085,7 @@ test_replace (gconstpointer d)
data->replacement = _replacement; \
data->expected = _expected; \
path = g_strdup_printf ("/regex/replace/%d", ++total); \
g_test_add_data_func (path, data, test_replace); \
g_test_add_data_func_full (path, data, test_replace, g_free); \
g_free (path); \
}
@ -1097,7 +1115,7 @@ test_replace_lit (gconstpointer d)
data->replacement = _replacement; \
data->expected = _expected; \
path = g_strdup_printf ("/regex/replace-literally/%d", ++total); \
g_test_add_data_func (path, data, test_replace_lit); \
g_test_add_data_func_full (path, data, test_replace_lit, g_free); \
g_free (path); \
}
@ -1129,7 +1147,7 @@ test_get_string_number (gconstpointer d)
data->name = _name; \
data->expected_num = _expected_num; \
path = g_strdup_printf ("/regex/string-number/%d", ++total); \
g_test_add_data_func (path, data, test_get_string_number); \
g_test_add_data_func_full (path, data, test_get_string_number, g_free); \
g_free (path); \
}
@ -1160,7 +1178,7 @@ test_escape (gconstpointer d)
data->length = _length; \
data->expected = _expected; \
path = g_strdup_printf ("/regex/escape/%d", ++total); \
g_test_add_data_func (path, data, test_escape); \
g_test_add_data_func_full (path, data, test_escape, g_free); \
g_free (path); \
}
@ -1185,7 +1203,7 @@ test_escape_nul (gconstpointer d)
data->length = _length; \
data->expected = _expected; \
path = g_strdup_printf ("/regex/escape_nul/%d", ++total); \
g_test_add_data_func (path, data, test_escape_nul); \
g_test_add_data_func_full (path, data, test_escape_nul, g_free); \
g_free (path); \
}
@ -1288,6 +1306,15 @@ test_match_all (gconstpointer d)
g_regex_unref (regex);
}
static void
free_match_all_data (gpointer _data)
{
TestMatchAllData *data = _data;
g_slist_free_full (data->expected, g_free);
g_free (data);
}
#define TEST_MATCH_ALL0(_pattern, _string, _string_len, _start_position) { \
TestMatchAllData *data; \
gchar *path; \
@ -1297,14 +1324,14 @@ test_match_all (gconstpointer d)
data->string_len = _string_len; \
data->start_position = _start_position; \
data->expected = NULL; \
path = g_strdup_printf ("/regex/match-all-full0/%d", ++total); \
g_test_add_data_func (path, data, test_match_all_full); \
g_free (path); \
if (_string_len == -1 && _start_position == 0) { \
path = g_strdup_printf ("/regex/match-all0/%d", ++total); \
g_test_add_data_func (path, data, test_match_all); \
g_free (path); \
} \
path = g_strdup_printf ("/regex/match-all-full0/%d", ++total); \
g_test_add_data_func_full (path, data, test_match_all_full, free_match_all_data); \
g_free (path); \
}
#define TEST_MATCH_ALL1(_pattern, _string, _string_len, _start_position, \
@ -1323,14 +1350,14 @@ test_match_all (gconstpointer d)
match->start = s1; \
match->end = e1; \
data->expected = g_slist_append (data->expected, match); \
path = g_strdup_printf ("/regex/match-all-full1/%d", ++total); \
g_test_add_data_func (path, data, test_match_all_full); \
g_free (path); \
if (_string_len == -1 && _start_position == 0) { \
path = g_strdup_printf ("/regex/match-all1/%d", ++total); \
g_test_add_data_func (path, data, test_match_all); \
g_free (path); \
} \
path = g_strdup_printf ("/regex/match-all-full1/%d", ++total); \
g_test_add_data_func_full (path, data, test_match_all_full, free_match_all_data); \
g_free (path); \
}
#define TEST_MATCH_ALL2(_pattern, _string, _string_len, _start_position, \
@ -1354,14 +1381,14 @@ test_match_all (gconstpointer d)
match->start = s2; \
match->end = e2; \
data->expected = g_slist_append (data->expected, match); \
path = g_strdup_printf ("/regex/match-all-full2/%d", ++total); \
g_test_add_data_func (path, data, test_match_all_full); \
g_free (path); \
if (_string_len == -1 && _start_position == 0) { \
path = g_strdup_printf ("/regex/match-all2/%d", ++total); \
g_test_add_data_func (path, data, test_match_all); \
g_free (path); \
} \
path = g_strdup_printf ("/regex/match-all-full2/%d", ++total); \
g_test_add_data_func_full (path, data, test_match_all_full, free_match_all_data); \
g_free (path); \
}
#define TEST_MATCH_ALL3(_pattern, _string, _string_len, _start_position, \
@ -1390,14 +1417,14 @@ test_match_all (gconstpointer d)
match->start = s3; \
match->end = e3; \
data->expected = g_slist_append (data->expected, match); \
path = g_strdup_printf ("/regex/match-all-full3/%d", ++total); \
g_test_add_data_func (path, data, test_match_all_full); \
g_free (path); \
if (_string_len == -1 && _start_position == 0) { \
path = g_strdup_printf ("/regex/match-all3/%d", ++total); \
g_test_add_data_func (path, data, test_match_all); \
g_free (path); \
} \
path = g_strdup_printf ("/regex/match-all-full3/%d", ++total); \
g_test_add_data_func_full (path, data, test_match_all_full, free_match_all_data); \
g_free (path); \
}
static void

View File

@ -215,6 +215,7 @@ main (int argc,
char *argv[])
{
char *dirname;
int ret;
g_test_init (&argc, &argv, NULL);
@ -232,5 +233,9 @@ main (int argc,
g_test_add_func ("/gthread/spawn-sync", test_spawn_sync_multithreaded);
g_test_add_func ("/gthread/spawn-async", test_spawn_async_multithreaded);
return g_test_run();
ret = g_test_run();
g_free (echo_prog_path);
return ret;
}

View File

@ -189,6 +189,7 @@ main (int argc,
char *argv[])
{
char *dirname;
int ret;
g_test_init (&argc, &argv, NULL);
@ -221,5 +222,10 @@ main (int argc,
g_test_add_func ("/gthread/spawn-single-async", test_spawn_async);
g_test_add_func ("/gthread/spawn-script", test_spawn_script);
return g_test_run();
ret = g_test_run();
g_free (echo_script_path);
g_free (echo_prog_path);
return ret;
}

View File

@ -490,6 +490,8 @@ test_string_to_bytes (void)
g_assert_cmpint (byte_len, ==, 7);
g_assert_cmpint (memcmp (byte_data, "foo-bar", byte_len), ==, 0);
g_bytes_unref (bytes);
}
int

View File

@ -22,6 +22,8 @@ function (gpointer data)
static void
test_seconds (void)
{
guint id;
/* Bug 642052 mentions that g_timeout_add_seconds(21475) schedules a
* job that runs once per second.
*
@ -40,10 +42,12 @@ test_seconds (void)
loop = g_main_loop_new (NULL, FALSE);
g_timeout_add (2100, stop_waiting, NULL);
g_timeout_add_seconds (21475, function, NULL);
id = g_timeout_add_seconds (21475, function, NULL);
g_main_loop_run (loop);
g_main_loop_unref (loop);
g_source_remove (id);
}
static gint64 last_time;

View File

@ -96,6 +96,7 @@ static void
test_signal (int signum)
{
GMainLoop *mainloop;
int id;
mainloop = g_main_loop_new (NULL, FALSE);
@ -103,10 +104,11 @@ test_signal (int signum)
g_unix_signal_add (signum, on_sig_received, mainloop);
kill (getpid (), signum);
g_assert (!sig_received);
g_timeout_add (5000, sig_not_received, mainloop);
id = g_timeout_add (5000, sig_not_received, mainloop);
g_main_loop_run (mainloop);
g_assert (sig_received);
sig_received = FALSE;
g_source_remove (id);
/* Ensure we don't get double delivery */
g_timeout_add (500, exit_mainloop, mainloop);