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.
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;
/* 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;
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;
#include "test-utils.h"
#include <gio/gio.h>
+typedef struct _DestroyedObjectStruct
+{
+ GObject *object;
+ gboolean destroyed;
+} DestroyedObjectStruct;
+
gchar *
ges_test_get_audio_only_uri (void)
{
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);
+
+}
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; \
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;
(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;