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;
39 GST_DEBUG ("getting elements for package %s", PACKAGE);
40 STATE_IGNORE_ELEMENTS = g_getenv ("GST_STATE_IGNORE_ELEMENTS");
41 if (!g_getenv ("GST_NO_STATE_IGNORE_ELEMENTS") && STATE_IGNORE_ELEMENTS) {
42 GST_DEBUG ("Will ignore element factories: '%s'", STATE_IGNORE_ELEMENTS);
43 ignorelist = g_strsplit (STATE_IGNORE_ELEMENTS, " ", 0);
46 plugins = gst_registry_get_plugin_list (gst_registry_get ());
48 for (p = plugins; p; p = p->next) {
49 GstPlugin *plugin = p->data;
51 if (strcmp (gst_plugin_get_source (plugin), PACKAGE) != 0)
55 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
56 gst_plugin_get_name (plugin));
58 for (f = features; f; f = f->next) {
59 GstPluginFeature *feature = f->data;
60 const gchar *name = gst_plugin_feature_get_name (feature);
61 gboolean ignore = FALSE;
63 if (!GST_IS_ELEMENT_FACTORY (feature))
69 for (s = ignorelist; s && *s; ++s) {
70 if (g_str_has_prefix (name, *s)) {
71 GST_DEBUG ("ignoring element %s", name);
79 GST_DEBUG ("adding element %s", name);
80 elements = g_list_prepend (elements, (gpointer) g_strdup (name));
82 gst_plugin_feature_list_free (features);
84 gst_plugin_list_free (plugins);
85 g_strfreev (ignorelist);
93 for (e = elements; e; e = e->next) {
96 g_list_free (elements);
101 GST_START_TEST (test_state_changes_up_and_down_seq)
106 for (e = elements; e; e = e->next) {
107 const gchar *name = e->data;
109 GST_INFO ("testing element %s", name);
110 element = gst_element_factory_make (name, name);
111 fail_if (element == NULL, "Could not make element from factory %s", name);
113 if (GST_IS_PIPELINE (element)) {
114 GST_DEBUG ("element %s is a pipeline", name);
117 gst_element_set_state (element, GST_STATE_READY);
118 gst_element_set_state (element, GST_STATE_PAUSED);
119 gst_element_set_state (element, GST_STATE_PLAYING);
120 gst_element_set_state (element, GST_STATE_PAUSED);
121 gst_element_set_state (element, GST_STATE_READY);
122 gst_element_set_state (element, GST_STATE_NULL);
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_PLAYING);
126 gst_element_set_state (element, GST_STATE_PAUSED);
127 gst_element_set_state (element, GST_STATE_NULL);
128 gst_object_unref (GST_OBJECT (element));
134 GST_START_TEST (test_state_changes_up_seq)
139 for (e = elements; e; e = e->next) {
140 const gchar *name = e->data;
142 GST_INFO ("testing element %s", name);
143 element = gst_element_factory_make (name, name);
144 fail_if (element == NULL, "Could not make element from factory %s", name);
146 if (GST_IS_PIPELINE (element)) {
147 GST_DEBUG ("element %s is a pipeline", name);
150 gst_element_set_state (element, GST_STATE_READY);
152 gst_element_set_state (element, GST_STATE_PAUSED);
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_PLAYING);
157 gst_element_set_state (element, GST_STATE_PAUSED);
158 gst_element_set_state (element, GST_STATE_READY);
160 gst_element_set_state (element, GST_STATE_NULL);
161 gst_object_unref (GST_OBJECT (element));
167 GST_START_TEST (test_state_changes_down_seq)
172 for (e = elements; e; e = e->next) {
173 const gchar *name = e->data;
175 GST_INFO ("testing element %s", name);
176 element = gst_element_factory_make (name, name);
177 fail_if (element == NULL, "Could not make element from factory %s", name);
179 if (GST_IS_PIPELINE (element)) {
180 GST_DEBUG ("element %s is a pipeline", name);
183 gst_element_set_state (element, GST_STATE_READY);
184 gst_element_set_state (element, GST_STATE_PAUSED);
185 gst_element_set_state (element, GST_STATE_PLAYING);
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_READY);
192 gst_element_set_state (element, GST_STATE_PAUSED);
193 gst_element_set_state (element, GST_STATE_PLAYING);
195 gst_element_set_state (element, GST_STATE_PAUSED);
196 gst_element_set_state (element, GST_STATE_READY);
197 gst_element_set_state (element, GST_STATE_NULL);
198 gst_object_unref (GST_OBJECT (element));
207 Suite *s = suite_create ("states_ugly");
208 TCase *tc_chain = tcase_create ("general");
210 suite_add_tcase (s, tc_chain);
211 tcase_add_checked_fixture (tc_chain, setup, teardown);
212 tcase_add_test (tc_chain, test_state_changes_up_and_down_seq);
213 tcase_add_test (tc_chain, test_state_changes_up_seq);
214 tcase_add_test (tc_chain, test_state_changes_down_seq);
219 GST_CHECK_MAIN (states);