3 * unit test for state changes on all elements
5 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
27 #include <gst/check/gstcheck.h>
29 static GList *elements = NULL;
36 gchar **ignorelist = NULL;
37 const gchar *STATE_IGNORE_ELEMENTS = NULL;
40 GST_DEBUG ("getting elements for package %s", PACKAGE);
41 STATE_IGNORE_ELEMENTS = g_getenv ("GST_STATE_IGNORE_ELEMENTS");
42 if (!g_getenv ("GST_NO_STATE_IGNORE_ELEMENTS") && STATE_IGNORE_ELEMENTS) {
43 GST_DEBUG ("Will ignore element factories: '%s'", STATE_IGNORE_ELEMENTS);
44 ignorelist = g_strsplit (STATE_IGNORE_ELEMENTS, " ", 0);
47 def = gst_registry_get ();
49 plugins = gst_registry_get_plugin_list (def);
51 for (p = plugins; p; p = p->next) {
52 GstPlugin *plugin = p->data;
54 if (strcmp (gst_plugin_get_source (plugin), PACKAGE) != 0)
58 gst_registry_get_feature_list_by_plugin (def,
59 gst_plugin_get_name (plugin));
61 for (f = features; f; f = f->next) {
62 GstPluginFeature *feature = f->data;
63 const gchar *name = gst_plugin_feature_get_name (feature);
64 gboolean ignore = FALSE;
66 if (!GST_IS_ELEMENT_FACTORY (feature))
72 for (s = ignorelist; s && *s; ++s) {
73 if (g_str_has_prefix (name, *s)) {
74 GST_DEBUG ("ignoring element %s", name);
82 GST_DEBUG ("adding element %s", name);
83 elements = g_list_prepend (elements, (gpointer) g_strdup (name));
85 gst_plugin_feature_list_free (features);
87 gst_plugin_list_free (plugins);
88 g_strfreev (ignorelist);
96 for (e = elements; e; e = e->next) {
99 g_list_free (elements);
104 GST_START_TEST (test_state_changes_up_and_down_seq)
109 for (e = elements; e; e = e->next) {
110 const gchar *name = e->data;
112 GST_INFO ("testing element %s", name);
113 element = gst_element_factory_make (name, name);
114 fail_if (element == NULL, "Could not make element from factory %s", name);
116 if (GST_IS_PIPELINE (element)) {
117 GST_DEBUG ("element %s is a pipeline", name);
120 gst_element_set_state (element, GST_STATE_READY);
121 gst_element_set_state (element, GST_STATE_PAUSED);
122 gst_element_set_state (element, GST_STATE_PLAYING);
123 gst_element_set_state (element, GST_STATE_PAUSED);
124 gst_element_set_state (element, GST_STATE_READY);
125 gst_element_set_state (element, GST_STATE_NULL);
126 gst_element_set_state (element, GST_STATE_PAUSED);
127 gst_element_set_state (element, GST_STATE_READY);
128 gst_element_set_state (element, GST_STATE_PLAYING);
129 gst_element_set_state (element, GST_STATE_PAUSED);
130 gst_element_set_state (element, GST_STATE_NULL);
131 gst_object_unref (GST_OBJECT (element));
137 GST_START_TEST (test_state_changes_up_seq)
142 for (e = elements; e; e = e->next) {
143 const gchar *name = e->data;
145 GST_INFO ("testing element %s", name);
146 element = gst_element_factory_make (name, name);
147 fail_if (element == NULL, "Could not make element from factory %s", name);
149 if (GST_IS_PIPELINE (element)) {
150 GST_DEBUG ("element %s is a pipeline", name);
153 gst_element_set_state (element, GST_STATE_READY);
155 gst_element_set_state (element, GST_STATE_PAUSED);
156 gst_element_set_state (element, GST_STATE_READY);
158 gst_element_set_state (element, GST_STATE_PAUSED);
159 gst_element_set_state (element, GST_STATE_PLAYING);
160 gst_element_set_state (element, GST_STATE_PAUSED);
161 gst_element_set_state (element, GST_STATE_READY);
163 gst_element_set_state (element, GST_STATE_NULL);
164 gst_object_unref (GST_OBJECT (element));
170 GST_START_TEST (test_state_changes_down_seq)
175 for (e = elements; e; e = e->next) {
176 const gchar *name = e->data;
178 GST_INFO ("testing element %s", name);
179 element = gst_element_factory_make (name, name);
180 fail_if (element == NULL, "Could not make element from factory %s", name);
182 if (GST_IS_PIPELINE (element)) {
183 GST_DEBUG ("element %s is a pipeline", name);
186 gst_element_set_state (element, GST_STATE_READY);
187 gst_element_set_state (element, GST_STATE_PAUSED);
188 gst_element_set_state (element, GST_STATE_PLAYING);
190 gst_element_set_state (element, GST_STATE_PAUSED);
191 gst_element_set_state (element, GST_STATE_PLAYING);
193 gst_element_set_state (element, GST_STATE_PAUSED);
194 gst_element_set_state (element, GST_STATE_READY);
195 gst_element_set_state (element, GST_STATE_PAUSED);
196 gst_element_set_state (element, GST_STATE_PLAYING);
198 gst_element_set_state (element, GST_STATE_PAUSED);
199 gst_element_set_state (element, GST_STATE_READY);
200 gst_element_set_state (element, GST_STATE_NULL);
201 gst_object_unref (GST_OBJECT (element));
211 Suite *s = suite_create ("states_good");
212 TCase *tc_chain = tcase_create ("general");
214 suite_add_tcase (s, tc_chain);
215 tcase_add_checked_fixture (tc_chain, setup, teardown);
216 tcase_add_test (tc_chain, test_state_changes_up_and_down_seq);
217 tcase_add_test (tc_chain, test_state_changes_up_seq);
218 tcase_add_test (tc_chain, test_state_changes_down_seq);
223 GST_CHECK_MAIN (states);