2 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
4 * cleanup.c: Unit test for cleanup of pipelines
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #include <gst/check/gstcheck.h>
27 setup_pipeline (gchar * pipe_descr)
31 pipeline = gst_parse_launch (pipe_descr, NULL);
32 g_return_val_if_fail (GST_IS_PIPELINE (pipeline), NULL);
36 /* events is a mask of expected events. tevent is the expected terminal event.
37 the poll call will time out after half a second.
40 run_pipeline (GstElement * pipeline, gchar * descr,
41 GstMessageType events, GstMessageType tevent)
44 GstMessageType revent;
46 bus = gst_element_get_bus (pipeline);
48 gst_element_set_state (pipeline, GST_STATE_PLAYING);
51 GstMessage *message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 2);
54 revent = GST_MESSAGE_TYPE (message);
55 gst_message_unref (message);
57 revent = GST_MESSAGE_UNKNOWN;
60 if (revent == tevent) {
62 } else if (revent == GST_MESSAGE_UNKNOWN) {
63 g_critical ("Unexpected timeout in gst_bus_poll, looking for %d: %s",
66 } else if (revent & events) {
69 g_critical ("Unexpected message received of type %d, looking for %d: %s",
70 revent, tevent, descr);
73 gst_element_set_state (pipeline, GST_STATE_NULL);
74 gst_object_unref (pipeline);
75 gst_object_unref (bus);
78 GST_START_TEST (test_pipeline_unref)
81 GstElement *pipeline, *src, *sink;
83 s = "fakesrc name=src num-buffers=20 ! fakesink name=sink";
84 pipeline = setup_pipeline (s);
85 /* get_by_name takes a ref */
86 src = gst_bin_get_by_name (GST_BIN (pipeline), "src");
87 fail_if (src == NULL);
88 sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
89 fail_if (sink == NULL);
91 run_pipeline (pipeline, s, GST_MESSAGE_NEW_CLOCK | GST_MESSAGE_STATE_CHANGED,
93 while (GST_OBJECT_REFCOUNT_VALUE (src) > 1)
95 ASSERT_OBJECT_REFCOUNT (src, "src", 1);
96 ASSERT_OBJECT_REFCOUNT (sink, "sink", 1);
97 gst_object_unref (src);
98 gst_object_unref (sink);
106 Suite *s = suite_create ("Pipeline cleanup");
107 TCase *tc_chain = tcase_create ("linear");
109 /* time out after 20s, not the default 3 */
110 tcase_set_timeout (tc_chain, 20);
112 suite_add_tcase (s, tc_chain);
113 tcase_add_test (tc_chain, test_pipeline_unref);
117 GST_CHECK_MAIN (cleanup);