tests: add check for leaking signal return value

https://bugzilla.gnome.org/show_bug.cgi?id=674800
This commit is contained in:
Mark Nauwelaerts 2012-07-19 16:38:59 +02:00 committed by Tim-Philipp Müller
parent 13a1154b4c
commit 24b9f61ee4
2 changed files with 30 additions and 1 deletions

View File

@ -21,7 +21,8 @@ test_programs = \
properties4 \
signal1 \
signal2 \
signal3
signal3 \
signal4
@ -31,6 +32,8 @@ signal2_SOURCES = signals.c
signal2_CFLAGS = -DTESTNUM=2 $(AM_CFLAGS)
signal3_SOURCES = signals.c
signal3_CFLAGS = -DTESTNUM=3 $(AM_CFLAGS)
signal4_SOURCES = signals.c
signal4_CFLAGS = -DTESTNUM=4 $(AM_CFLAGS)
check_PROGRAMS = $(test_programs)

View File

@ -27,6 +27,7 @@ struct _GTestClass
void (*test_signal1) (GTest * test, gint an_int);
void (*test_signal2) (GTest * test, gint an_int);
gchar * (*test_signal3) (GTest * test, gint an_int);
};
static GType my_test_get_type (void);
@ -37,6 +38,7 @@ enum
{
TEST_SIGNAL1,
TEST_SIGNAL2,
TEST_SIGNAL3,
/* add more above */
LAST_SIGNAL
};
@ -52,6 +54,7 @@ static void my_test_init (GTest * test);
static void my_test_dispose (GObject * object);
static void signal2_handler (GTest * test, gint anint);
static gchar * signal3_handler (GTest * test, gint anint);
static void my_test_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
@ -110,12 +113,17 @@ my_test_class_init (GTestClass * klass)
g_signal_new ("test-signal2", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GTestClass, test_signal2), NULL,
NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
my_test_signals[TEST_SIGNAL3] =
g_signal_new ("test-signal3", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GTestClass, test_signal3), NULL,
NULL, g_cclosure_marshal_generic, G_TYPE_STRING, 1, G_TYPE_INT);
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TEST_PROP,
g_param_spec_int ("test-prop", "Test Prop", "Test property",
0, 1, 0, G_PARAM_READWRITE));
klass->test_signal2 = signal2_handler;
klass->test_signal3 = signal3_handler;
}
static void
@ -191,6 +199,22 @@ my_test_do_signal2 (GTest * test)
g_signal_emit (G_OBJECT (test), my_test_signals[TEST_SIGNAL2], 0, 0);
}
static gchar *
signal3_handler (GTest * test, gint anint)
{
return g_strdup ("test");
}
static void
my_test_do_signal3 (GTest * test)
{
gchar *res;
g_signal_emit (G_OBJECT (test), my_test_signals[TEST_SIGNAL3], 0, 0, &res);
g_assert (res);
g_free (res);
}
static void
my_test_do_prop (GTest * test)
{
@ -210,6 +234,8 @@ run_thread (GTest * test)
my_test_do_signal2 (test);
if (TESTNUM == 3)
my_test_do_prop (test);
if (TESTNUM == 4)
my_test_do_signal3 (test);
if ((i++ % 10000) == 0) {
g_print (".");
g_thread_yield(); /* force context switch */