mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-22 14:06:23 +00:00
tests: More safely check if objects where destroyed
Check if an object rthat has already been freed has been destroyed is not safe. Add a helper function that uses weak reference to check that objects that are expected to be destroyed when unrefing an object are actually destroyed.
This commit is contained in:
parent
2b9606437c
commit
4e51b347ff
6 changed files with 58 additions and 27 deletions
|
@ -514,11 +514,7 @@ GST_START_TEST (test_ges_timeline_remove_track)
|
|||
tmp = ges_layer_get_clips (layer);
|
||||
assert_equals_int (g_list_length (tmp), 3);
|
||||
|
||||
gst_object_unref (timeline);
|
||||
fail_if (G_IS_OBJECT (layer));
|
||||
fail_if (G_IS_OBJECT (t1));
|
||||
fail_if (G_IS_OBJECT (t2));
|
||||
fail_if (G_IS_OBJECT (t3));
|
||||
check_destroyed (G_OBJECT (timeline), G_OBJECT (layer), t1, t2, t3, NULL);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
|
|
@ -203,10 +203,8 @@ GST_START_TEST (test_split_object)
|
|||
/* 1 ref for the Clip, 1 ref for the Track and 1 ref for the timeline */
|
||||
ASSERT_OBJECT_REFCOUNT (splittrackelement, "splittrackelement", 3);
|
||||
|
||||
g_object_unref (timeline);
|
||||
fail_if (G_IS_OBJECT (splitclip));
|
||||
fail_if (G_IS_OBJECT (clip));
|
||||
fail_if (G_IS_OBJECT (splittrackelement));
|
||||
check_destroyed (G_OBJECT (timeline), G_OBJECT (splitclip), clip,
|
||||
splittrackelement, NULL);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
@ -367,10 +365,8 @@ GST_START_TEST (test_clip_refcount_remove_child)
|
|||
fail_unless (called == TRUE);
|
||||
fail_if (G_IS_OBJECT (effect));
|
||||
|
||||
gst_object_unref (track);
|
||||
gst_object_unref (clip);
|
||||
fail_if (G_IS_OBJECT (track));
|
||||
fail_if (G_IS_OBJECT (clip));
|
||||
check_destroyed (G_OBJECT (track), NULL, NULL);
|
||||
check_destroyed (G_OBJECT (clip), NULL, NULL);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
|
|
@ -22,6 +22,12 @@
|
|||
#include "test-utils.h"
|
||||
#include <gio/gio.h>
|
||||
|
||||
typedef struct _DestroyedObjectStruct
|
||||
{
|
||||
GObject *object;
|
||||
gboolean destroyed;
|
||||
} DestroyedObjectStruct;
|
||||
|
||||
gchar *
|
||||
ges_test_get_audio_only_uri (void)
|
||||
{
|
||||
|
@ -100,3 +106,46 @@ ges_test_create_pipeline (GESTimeline * timeline)
|
|||
return pipeline;
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
weak_notify (DestroyedObjectStruct * destroyed, GObject ** object)
|
||||
{
|
||||
destroyed->destroyed = TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
check_destroyed (GObject * object_to_unref, GObject * first_object, ...)
|
||||
{
|
||||
GObject *object;
|
||||
GList *objs = NULL, *tmp;
|
||||
DestroyedObjectStruct *destroyed = g_slice_new0 (DestroyedObjectStruct);
|
||||
|
||||
destroyed->object = object_to_unref;
|
||||
g_object_weak_ref (object_to_unref, (GWeakNotify) weak_notify, destroyed);
|
||||
objs = g_list_prepend (objs, destroyed);
|
||||
|
||||
if (first_object) {
|
||||
va_list varargs;
|
||||
|
||||
object = first_object;
|
||||
|
||||
va_start (varargs, first_object);
|
||||
while (object) {
|
||||
destroyed = g_slice_new0 (DestroyedObjectStruct);
|
||||
destroyed->object = object;
|
||||
g_object_weak_ref (object, (GWeakNotify) weak_notify, destroyed);
|
||||
objs = g_list_prepend (objs, destroyed);
|
||||
object = va_arg (varargs, GObject *);
|
||||
}
|
||||
va_end (varargs);
|
||||
}
|
||||
gst_object_unref (object_to_unref);
|
||||
|
||||
for (tmp = objs; tmp; tmp = tmp->next) {
|
||||
fail_unless (((DestroyedObjectStruct *) tmp->data)->destroyed == TRUE,
|
||||
"%p is not destroyed", ((DestroyedObjectStruct *) tmp->data)->object);
|
||||
g_slice_free (DestroyedObjectStruct, tmp->data);
|
||||
}
|
||||
g_list_free (objs);
|
||||
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ gchar * ges_test_get_audio_only_uri (void);
|
|||
gchar * ges_test_get_audio_video_uri (void);
|
||||
gchar * ges_test_get_image_uri (void);
|
||||
gchar * ges_test_file_uri (const gchar *filename);
|
||||
void check_destroyed (GObject *object_to_unref, GObject *first_object, ...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
#define gnl_object_check(gnlobj, start, duration, mstart, mduration, priority, active) { \
|
||||
guint64 pstart, pdur, inpoint, pprio, pact; \
|
||||
|
|
|
@ -470,17 +470,8 @@ GST_START_TEST (test_snapping)
|
|||
ASSERT_OBJECT_REFCOUNT (clip1, "Second clip", 1);
|
||||
ASSERT_OBJECT_REFCOUNT (clip2, "Third clip", 1);
|
||||
|
||||
gst_object_unref (timeline);
|
||||
|
||||
/* Check we destroyed everything */
|
||||
fail_if (G_IS_OBJECT (timeline));
|
||||
fail_if (G_IS_OBJECT (trackelement));
|
||||
fail_if (G_IS_OBJECT (trackelement1));
|
||||
fail_if (G_IS_OBJECT (trackelement2));
|
||||
fail_if (G_IS_OBJECT (clip));
|
||||
fail_if (G_IS_OBJECT (clip1));
|
||||
fail_if (G_IS_OBJECT (clip2));
|
||||
fail_if (G_IS_OBJECT (layer));
|
||||
check_destroyed (G_OBJECT (timeline), G_OBJECT (trackelement),
|
||||
trackelement1, trackelement2, clip, clip1, clip2, layer, NULL);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
|
|
@ -165,9 +165,7 @@ GST_START_TEST (test_transition_properties)
|
|||
(GES_VIDEO_TRANSITION (trackelement)), 1);
|
||||
assert_equals_int (GES_TRANSITION_CLIP (clip)->vtype, 1);
|
||||
|
||||
gst_object_unref (timeline);
|
||||
fail_if (G_IS_OBJECT (track));
|
||||
fail_if (G_IS_OBJECT (clip));
|
||||
check_destroyed (G_OBJECT (timeline), G_OBJECT (track), clip, NULL);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
|
Loading…
Reference in a new issue