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;
41 GST_DEBUG ("getting elements for package %s", PACKAGE);
42 STATE_IGNORE_ELEMENTS = g_getenv ("STATE_IGNORE_ELEMENTS");
43 if (STATE_IGNORE_ELEMENTS) {
44 GST_DEBUG ("Will ignore element factories: '%s'", STATE_IGNORE_ELEMENTS);
45 ignorelist = g_strsplit (STATE_IGNORE_ELEMENTS, " ", 0);
48 plugins = gst_registry_get_plugin_list (gst_registry_get_default ());
50 for (p = plugins; p; p = p->next) {
51 GstPlugin *plugin = p->data;
53 if (strcmp (gst_plugin_get_source (plugin), PACKAGE) != 0)
57 gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
58 gst_plugin_get_name (plugin));
60 for (f = features; f; f = f->next) {
61 GstPluginFeature *feature = f->data;
62 const gchar *name = gst_plugin_feature_get_name (feature);
63 gboolean ignore = FALSE;
65 if (!GST_IS_ELEMENT_FACTORY (feature))
71 for (s = ignorelist; s && *s; ++s) {
72 if (g_str_has_prefix (name, *s)) {
73 GST_DEBUG ("ignoring element %s", name);
81 GST_DEBUG ("adding element %s", name);
82 elements = g_list_prepend (elements, (gpointer) g_strdup (name));
84 gst_plugin_feature_list_free (features);
86 gst_plugin_list_free (plugins);
87 g_strfreev (ignorelist);
95 for (e = elements; e; e = e->next) {
98 g_list_free (elements);
103 GST_START_TEST (test_state_changes_up_and_down_seq)
108 for (e = elements; e; e = e->next) {
109 const gchar *name = e->data;
111 GST_DEBUG ("testing element %s", name);
112 element = gst_element_factory_make (name, name);
113 fail_if (element == NULL, "Could not make element from factory %s", name);
115 if (GST_IS_PIPELINE (element)) {
116 GST_DEBUG ("element %s is a pipeline", name);
119 gst_element_set_state (element, GST_STATE_READY);
120 gst_element_set_state (element, GST_STATE_PAUSED);
121 gst_element_set_state (element, GST_STATE_PLAYING);
122 gst_element_set_state (element, GST_STATE_PAUSED);
123 gst_element_set_state (element, GST_STATE_READY);
124 gst_element_set_state (element, GST_STATE_NULL);
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_PLAYING);
128 gst_element_set_state (element, GST_STATE_PAUSED);
129 gst_element_set_state (element, GST_STATE_NULL);
130 gst_object_unref (GST_OBJECT (element));
136 GST_START_TEST (test_state_changes_up_seq)
141 for (e = elements; e; e = e->next) {
142 const gchar *name = e->data;
144 GST_DEBUG ("testing element %s", name);
145 element = gst_element_factory_make (name, name);
146 fail_if (element == NULL, "Could not make element from factory %s", name);
148 if (GST_IS_PIPELINE (element)) {
149 GST_DEBUG ("element %s is a pipeline", name);
152 gst_element_set_state (element, GST_STATE_READY);
154 gst_element_set_state (element, GST_STATE_PAUSED);
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_PLAYING);
159 gst_element_set_state (element, GST_STATE_PAUSED);
160 gst_element_set_state (element, GST_STATE_READY);
162 gst_element_set_state (element, GST_STATE_NULL);
163 gst_object_unref (GST_OBJECT (element));
169 GST_START_TEST (test_state_changes_down_seq)
174 for (e = elements; e; e = e->next) {
175 const gchar *name = e->data;
177 GST_DEBUG ("testing element %s", name);
178 element = gst_element_factory_make (name, name);
179 fail_if (element == NULL, "Could not make element from factory %s", name);
181 if (GST_IS_PIPELINE (element)) {
182 GST_DEBUG ("element %s is a pipeline", name);
185 gst_element_set_state (element, GST_STATE_READY);
186 gst_element_set_state (element, GST_STATE_PAUSED);
187 gst_element_set_state (element, GST_STATE_PLAYING);
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_READY);
194 gst_element_set_state (element, GST_STATE_PAUSED);
195 gst_element_set_state (element, GST_STATE_PLAYING);
197 gst_element_set_state (element, GST_STATE_PAUSED);
198 gst_element_set_state (element, GST_STATE_READY);
199 gst_element_set_state (element, GST_STATE_NULL);
200 gst_object_unref (GST_OBJECT (element));
210 Suite *s = suite_create ("states");
211 TCase *tc_chain = tcase_create ("general");
213 suite_add_tcase (s, tc_chain);
214 tcase_add_checked_fixture (tc_chain, setup, teardown);
215 tcase_add_test (tc_chain, test_state_changes_up_and_down_seq);
216 tcase_add_test (tc_chain, test_state_changes_up_seq);
217 tcase_add_test (tc_chain, test_state_changes_down_seq);
222 GST_CHECK_MAIN (states);