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., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
29 #include <gst/check/gstcheck.h>
31 static GList *elements = NULL;
38 gchar **ignorelist = NULL;
39 const gchar *STATE_IGNORE_ELEMENTS = NULL;
42 GST_DEBUG ("getting elements for package %s", PACKAGE);
43 STATE_IGNORE_ELEMENTS = g_getenv ("GST_STATE_IGNORE_ELEMENTS");
44 if (!g_getenv ("GST_NO_STATE_IGNORE_ELEMENTS") && STATE_IGNORE_ELEMENTS) {
45 GST_DEBUG ("Will ignore element factories: '%s'", STATE_IGNORE_ELEMENTS);
46 ignorelist = g_strsplit (STATE_IGNORE_ELEMENTS, " ", 0);
49 def = gst_registry_get ();
51 plugins = gst_registry_get_plugin_list (def);
53 for (p = plugins; p; p = p->next) {
54 GstPlugin *plugin = p->data;
56 if (strcmp (gst_plugin_get_source (plugin), PACKAGE) != 0)
60 gst_registry_get_feature_list_by_plugin (def,
61 gst_plugin_get_name (plugin));
63 for (f = features; f; f = f->next) {
64 GstPluginFeature *feature = f->data;
65 const gchar *name = gst_plugin_feature_get_name (feature);
66 gboolean ignore = FALSE;
68 if (!GST_IS_ELEMENT_FACTORY (feature))
74 for (s = ignorelist; s && *s; ++s) {
75 if (g_str_has_prefix (name, *s)) {
76 GST_DEBUG ("ignoring element %s", name);
84 GST_DEBUG ("adding element %s", name);
85 elements = g_list_prepend (elements, (gpointer) g_strdup (name));
87 gst_plugin_feature_list_free (features);
89 gst_plugin_list_free (plugins);
90 g_strfreev (ignorelist);
98 for (e = elements; e; e = e->next) {
101 g_list_free (elements);
106 GST_START_TEST (test_state_changes_up_and_down_seq)
111 for (e = elements; e; e = e->next) {
112 const gchar *name = e->data;
114 GST_INFO ("testing element %s", name);
115 element = gst_element_factory_make (name, name);
116 fail_if (element == NULL, "Could not make element from factory %s", name);
118 if (GST_IS_PIPELINE (element)) {
119 GST_DEBUG ("element %s is a pipeline", name);
122 gst_element_set_state (element, GST_STATE_READY);
123 gst_element_set_state (element, GST_STATE_PAUSED);
124 gst_element_set_state (element, GST_STATE_PLAYING);
125 gst_element_set_state (element, GST_STATE_PAUSED);
126 gst_element_set_state (element, GST_STATE_READY);
127 gst_element_set_state (element, GST_STATE_NULL);
128 gst_element_set_state (element, GST_STATE_PAUSED);
129 gst_element_set_state (element, GST_STATE_READY);
130 gst_element_set_state (element, GST_STATE_PLAYING);
131 gst_element_set_state (element, GST_STATE_PAUSED);
132 gst_element_set_state (element, GST_STATE_NULL);
133 gst_object_unref (GST_OBJECT (element));
139 GST_START_TEST (test_state_changes_up_seq)
144 for (e = elements; e; e = e->next) {
145 const gchar *name = e->data;
147 GST_INFO ("testing element %s", name);
148 element = gst_element_factory_make (name, name);
149 fail_if (element == NULL, "Could not make element from factory %s", name);
151 if (GST_IS_PIPELINE (element)) {
152 GST_DEBUG ("element %s is a pipeline", name);
155 gst_element_set_state (element, GST_STATE_READY);
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_PAUSED);
161 gst_element_set_state (element, GST_STATE_PLAYING);
162 gst_element_set_state (element, GST_STATE_PAUSED);
163 gst_element_set_state (element, GST_STATE_READY);
165 gst_element_set_state (element, GST_STATE_NULL);
166 gst_object_unref (GST_OBJECT (element));
172 GST_START_TEST (test_state_changes_down_seq)
177 for (e = elements; e; e = e->next) {
178 const gchar *name = e->data;
180 GST_INFO ("testing element %s", name);
181 element = gst_element_factory_make (name, name);
182 fail_if (element == NULL, "Could not make element from factory %s", name);
184 if (GST_IS_PIPELINE (element)) {
185 GST_DEBUG ("element %s is a pipeline", name);
188 gst_element_set_state (element, GST_STATE_READY);
189 gst_element_set_state (element, GST_STATE_PAUSED);
190 gst_element_set_state (element, GST_STATE_PLAYING);
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_PAUSED);
198 gst_element_set_state (element, GST_STATE_PLAYING);
200 gst_element_set_state (element, GST_STATE_PAUSED);
201 gst_element_set_state (element, GST_STATE_READY);
202 gst_element_set_state (element, GST_STATE_NULL);
203 gst_object_unref (GST_OBJECT (element));
213 Suite *s = suite_create ("states");
214 TCase *tc_chain = tcase_create ("general");
216 suite_add_tcase (s, tc_chain);
217 tcase_add_checked_fixture (tc_chain, setup, teardown);
218 tcase_add_test (tc_chain, test_state_changes_up_and_down_seq);
219 tcase_add_test (tc_chain, test_state_changes_up_seq);
220 tcase_add_test (tc_chain, test_state_changes_down_seq);
225 GST_CHECK_MAIN (states);