#include #define ITERS 100000 #include #include "mem.h" static GstElement* create_bin (void) { GstElement *bin; GstElement *element; bin = gst_bin_new ("testbin"); element = gst_element_factory_make ("fakesrc", NULL); gst_element_set_name (element, "test1"); gst_bin_add (GST_BIN (bin), element); element = gst_element_factory_make ("fakesrc", NULL); gst_element_set_name (element, "test2"); gst_bin_add (GST_BIN (bin), element); return bin; } static GstElement* create_bin_ghostpads (void) { GstElement *bin; GstElement *element1, *element2; bin = gst_bin_new ("testbin"); element1 = gst_element_factory_make ("identity", NULL); gst_bin_add (GST_BIN (bin), element1); element2 = gst_element_factory_make ("fakesink", NULL); gst_bin_add (GST_BIN (bin), element2); gst_element_link_pads (element1, "src", element2, "sink"); gst_element_add_ghost_pad (bin, gst_element_get_pad (element1, "sink"), "ghost_sink"); return bin; } static void add_remove_test1 (void) { GstElement *bin; GstElement *element; bin = gst_bin_new ("testbin"); element = gst_element_factory_make ("fakesrc", NULL); gst_element_set_name (element, "test1"); g_assert (GST_OBJECT_FLOATING (element)); gst_bin_add (GST_BIN (bin), element); g_assert (!GST_OBJECT_FLOATING (element)); gst_bin_remove (GST_BIN (bin), element); gst_object_unref (GST_OBJECT (bin)); } static void add_remove_test2 (void) { GstElement *bin; GstElement *element; bin = gst_bin_new ("testbin"); element = gst_element_factory_make ("fakesrc", NULL); gst_element_set_name (element, "test1"); gst_object_ref (GST_OBJECT (element)); g_assert (GST_OBJECT_FLOATING (element)); gst_bin_add (GST_BIN (bin), element); g_assert (!GST_OBJECT_FLOATING (element)); gst_bin_remove (GST_BIN (bin), element); g_assert (!GST_OBJECT_FLOATING (element)); g_assert (!GST_OBJECT_DESTROYED (element)); gst_object_unref (GST_OBJECT (element)); g_assert (GST_OBJECT_DESTROYED (element)); gst_object_unref (GST_OBJECT (element)); gst_object_unref (GST_OBJECT (bin)); } static void add_remove_test3 (void) { GstElement *bin; GstElement *element; bin = gst_bin_new ("testbin"); element = gst_element_factory_make ("fakesrc", NULL); gst_element_set_name (element, "test1"); g_assert (GST_OBJECT_FLOATING (element)); gst_bin_add (GST_BIN (bin), element); g_assert (!GST_OBJECT_FLOATING (element)); gst_object_unref (GST_OBJECT (element)); g_assert (gst_bin_get_by_name (GST_BIN (bin), "test1") == NULL); gst_object_unref (GST_OBJECT (bin)); } static void add_remove_test4 (void) { GstElement *bin, *bin2; GstElement *element; bin = gst_bin_new ("testbin"); element = gst_element_factory_make ("fakesrc", NULL); gst_element_set_name (element, "test1"); g_assert (GST_OBJECT_FLOATING (element)); gst_bin_add (GST_BIN (bin), element); g_assert (!GST_OBJECT_FLOATING (element)); bin2 = create_bin (); g_assert (GST_OBJECT_FLOATING (bin2)); gst_bin_add (GST_BIN (bin), bin2); g_assert (!GST_OBJECT_FLOATING (bin2)); gst_object_unref (GST_OBJECT (bin2)); g_assert (gst_bin_get_by_name (GST_BIN (bin), "testbin") == NULL); gst_object_unref (GST_OBJECT (element)); g_assert (gst_bin_get_by_name (GST_BIN (bin), "test1") == NULL); gst_object_unref (GST_OBJECT (bin)); } int main (int argc, gchar *argv[]) { GstElement *bin; long usage1; gint i, iters; gst_init (&argc, &argv); if (argc == 2) iters = atoi (argv[1]); else iters = ITERS; g_print ("starting test\n"); usage1 = vmsize(); bin = gst_bin_new ("somebin"); gst_object_unref (GST_OBJECT (bin)); g_print ("create/unref new bin %ld\n", vmsize()-usage1); for (i=0; i