2 * Copyright (C) 2005 Thomas Vander Stichele <thomas at apestaart dot org>
4 * gstelement.c: Unit test for GstElement
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.
22 #include <gst/check/gstcheck.h>
24 GST_START_TEST (test_add_remove_pad)
29 /* getting an existing element class is cheating, but easier */
30 e = gst_element_factory_make ("fakesrc", "source");
32 /* create a new floating pad with refcount 1 */
33 p = gst_pad_new ("source", GST_PAD_SRC);
34 ASSERT_OBJECT_REFCOUNT (p, "pad", 1);
35 /* ref it for ourselves */
37 ASSERT_OBJECT_REFCOUNT (p, "pad", 2);
38 /* adding it sinks the pad -> not floating, same refcount */
39 gst_element_add_pad (e, p);
40 ASSERT_OBJECT_REFCOUNT (p, "pad", 2);
42 /* removing it reduces the refcount */
43 gst_element_remove_pad (e, p);
44 ASSERT_OBJECT_REFCOUNT (p, "pad", 1);
46 /* clean up our own reference */
52 GST_START_TEST (test_add_pad_unref_element)
57 /* getting an existing element class is cheating, but easier */
58 e = gst_element_factory_make ("fakesrc", "source");
60 /* create a new floating pad with refcount 1 */
61 p = gst_pad_new ("source", GST_PAD_SRC);
62 ASSERT_OBJECT_REFCOUNT (p, "pad", 1);
63 /* ref it for ourselves */
65 ASSERT_OBJECT_REFCOUNT (p, "pad", 2);
66 /* adding it sinks the pad -> not floating, same refcount */
67 gst_element_add_pad (e, p);
68 ASSERT_OBJECT_REFCOUNT (p, "pad", 2);
70 /* unreffing the element should clean it up */
71 gst_object_unref (GST_OBJECT (e));
73 ASSERT_OBJECT_REFCOUNT (p, "pad", 1);
75 /* clean up our own reference */
81 GST_START_TEST (test_error_no_bus)
85 e = gst_element_factory_make ("fakesrc", "source");
87 /* I don't want errors shown */
88 gst_debug_set_default_threshold (GST_LEVEL_NONE);
90 GST_ELEMENT_ERROR (e, RESOURCE, OPEN_READ, ("I could not read"), ("debug"));
97 /* link and run two elements without putting them in a
99 GST_START_TEST (test_link)
101 GstElement *src, *sink;
103 src = gst_element_factory_make ("fakesrc", "source");
104 sink = gst_element_factory_make ("fakesink", "sink");
106 fail_unless (gst_element_link_pads (src, "src", sink, "sink"));
108 /* do sink to source state change */
109 gst_element_set_state (sink, GST_STATE_PAUSED);
110 gst_element_set_state (src, GST_STATE_PAUSED);
112 /* wait for preroll */
113 gst_element_get_state (sink, NULL, NULL, NULL);
116 gst_element_set_state (sink, GST_STATE_PLAYING);
117 gst_element_set_state (src, GST_STATE_PLAYING);
119 g_usleep (G_USEC_PER_SEC);
122 gst_element_set_state (sink, GST_STATE_PAUSED);
123 gst_element_set_state (src, GST_STATE_PAUSED);
125 /* wait for preroll */
126 gst_element_get_state (sink, NULL, NULL, NULL);
128 gst_element_set_state (sink, GST_STATE_NULL);
129 gst_element_set_state (src, GST_STATE_NULL);
135 gst_element_suite (void)
137 Suite *s = suite_create ("GstElement");
138 TCase *tc_chain = tcase_create ("element tests");
140 suite_add_tcase (s, tc_chain);
141 tcase_add_test (tc_chain, test_add_remove_pad);
142 tcase_add_test (tc_chain, test_add_pad_unref_element);
143 tcase_add_test (tc_chain, test_error_no_bus);
144 tcase_add_test (tc_chain, test_link);
150 main (int argc, char **argv)
154 Suite *s = gst_element_suite ();
155 SRunner *sr = srunner_create (s);
157 gst_check_init (&argc, &argv);
159 srunner_run_all (sr, CK_NORMAL);
160 nf = srunner_ntests_failed (sr);