2 * Copyright (C) <2004> Benjamin Otte <otte@gnome.org>
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.
24 #define RETURN_NAME(x) ((x) == GST_STATE_SUCCESS ? "GST_STATE_SUCCESS" : \
25 (x) == GST_STATE_ASYNC ? "GST_STATE_ASYNC" : "GST_STATE_FAILURE")
27 assert_state (GstElement * element, GstElementState state)
29 if (gst_element_get_state (element) != state) {
30 g_printerr ("%s: state is %s instead of %s",
31 GST_OBJECT_NAME (element),
32 gst_element_state_get_name (GST_STATE (element)),
33 gst_element_state_get_name (state));
34 g_assert_not_reached ();
39 assert_state_change (GstElement * element, GstElementState new_state,
40 GstElementStateReturn result, GstElementState result_state)
42 GstElementStateReturn ret = gst_element_set_state (element, new_state);
45 g_printerr ("%s: change state to %s returned %s instead of %s",
46 GST_OBJECT_NAME (element), gst_element_state_get_name (new_state),
47 RETURN_NAME (ret), RETURN_NAME (result));
48 g_assert_not_reached ();
50 assert_state (element, result_state);
54 empty_bin (gchar * bin_name)
56 /* Test the behaviour of empty bins. Since a bin's state is always the state
57 * of its highest child, nothing should change in here
58 * Return values when no error occured but the state didn't change should be
60 GstElement *bin = gst_element_factory_make (bin_name, NULL);
63 assert_state (bin, GST_STATE_NULL);
65 assert_state_change (bin, GST_STATE_READY, GST_STATE_ASYNC, GST_STATE_NULL);
66 assert_state_change (bin, GST_STATE_PAUSED, GST_STATE_ASYNC, GST_STATE_NULL);
67 assert_state_change (bin, GST_STATE_PLAYING, GST_STATE_ASYNC, GST_STATE_NULL);
71 test_adding_one_element (GstElement * bin)
73 /* Tests behaviour of adding/removing elements to/from bins. It makes sure the
74 * state of the bin is always the highest of all contained children. */
75 GstElementState test_states[] = { GST_STATE_READY, GST_STATE_PAUSED,
76 GST_STATE_PLAYING, GST_STATE_PAUSED, GST_STATE_READY, GST_STATE_NULL
78 GstElement *test = gst_element_factory_make ("identity", NULL);
79 GstElementState bin_state = gst_element_get_state (bin);
83 gst_object_ref (test);
84 assert_state (test, GST_STATE_NULL);
85 gst_bin_add (GST_BIN (bin), test);
86 assert_state (bin, MAX (bin_state, GST_STATE_NULL));
87 for (i = 0; i < G_N_ELEMENTS (test_states); i++) {
88 GstElementState test_state = test_states[i];
90 assert_state_change (test, test_state, GST_STATE_SUCCESS, test_state);
91 assert_state (test, test_state);
92 assert_state (bin, MAX (bin_state, test_state));
93 gst_bin_remove (GST_BIN (bin), test);
94 assert_state (bin, bin_state);
95 gst_bin_add (GST_BIN (bin), test);
96 assert_state (test, test_state);
97 assert_state (bin, MAX (bin_state, test_state));
99 gst_bin_remove (GST_BIN (bin), test);
100 gst_object_unref (test);
101 assert_state (bin, bin_state);
105 test_element_in_bin (gchar * bin_name)
108 GstElementState test_states[] = { GST_STATE_NULL, GST_STATE_READY,
109 GST_STATE_PAUSED, GST_STATE_PLAYING
111 GstElement *id, *bin = gst_element_factory_make (bin_name, NULL);
115 /* test correct behaviour in empty bins */
116 test_adding_one_element (bin);
118 id = gst_element_factory_make ("identity", NULL);
120 assert_state (id, GST_STATE_NULL);
121 gst_bin_add (GST_BIN (bin), id);
122 /* test correct behaviour in bins which contain elements in various states */
123 for (i = 0; i < G_N_ELEMENTS (test_states); i++) {
124 GstElementState test_state = test_states[i];
126 assert_state_change (bin, test_state, GST_STATE_SUCCESS, test_state);
127 assert_state (id, test_state);
128 test_adding_one_element (bin);
131 gst_object_unref (bin);
135 main (gint argc, gchar * argv[])
137 gst_init (&argc, &argv);
139 /* test behaviour of empty bins */
141 empty_bin ("thread");
142 empty_bin ("pipeline");
144 /* test behaviour of adding/removing elements to/from all core bin types */
145 test_element_in_bin ("bin");
146 test_element_in_bin ("thread");
147 test_element_in_bin ("pipeline");