1 /* GStreamer
2 *
3 * unit test for state changes on all elements
4 *
5 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
6 *
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.
11 *
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.
16 *
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.
21 */
22
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
26
27 #include <gmodule.h>
28
29 #include <gst/check/gstcheck.h>
30
31 static GList *elements = NULL;
32
33 static void
setup(void)34 setup (void)
35 {
36 GList *features, *f;
37 GList *plugins, *p;
38 gchar **ignorelist = NULL;
39 const gchar *STATE_IGNORE_ELEMENTS = NULL;
40
41 GST_DEBUG ("getting elements for package %s", PACKAGE);
42 STATE_IGNORE_ELEMENTS = g_getenv ("GST_STATE_IGNORE_ELEMENTS");
43 if (!g_getenv ("GST_NO_STATE_IGNORE_ELEMENTS") && STATE_IGNORE_ELEMENTS) {
44 GST_DEBUG ("Will ignore element factories: '%s'", STATE_IGNORE_ELEMENTS);
45 ignorelist = g_strsplit (STATE_IGNORE_ELEMENTS, " ", 0);
46 }
47
48 plugins = gst_registry_get_plugin_list (gst_registry_get ());
49
50 for (p = plugins; p; p = p->next) {
51 GstPlugin *plugin = p->data;
52
53 if (strcmp (gst_plugin_get_source (plugin), PACKAGE) != 0)
54 continue;
55
56 features =
57 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
58 gst_plugin_get_name (plugin));
59
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;
64
65 if (!GST_IS_ELEMENT_FACTORY (feature))
66 continue;
67
68 if (ignorelist) {
69 gchar **s;
70
71 for (s = ignorelist; s && *s; ++s) {
72 if (g_str_has_prefix (name, *s)) {
73 GST_DEBUG ("ignoring element %s", name);
74 ignore = TRUE;
75 }
76 }
77 if (ignore)
78 continue;
79 }
80
81 GST_DEBUG ("adding element %s", name);
82 elements = g_list_prepend (elements, (gpointer) g_strdup (name));
83 }
84 gst_plugin_feature_list_free (features);
85 }
86 gst_plugin_list_free (plugins);
87 g_strfreev (ignorelist);
88 }
89
90 static void
teardown(void)91 teardown (void)
92 {
93 GList *e;
94
95 for (e = elements; e; e = e->next) {
96 g_free (e->data);
97 }
98 g_list_free (elements);
99 elements = NULL;
100 }
101
102
GST_START_TEST(test_state_changes_up_and_down_seq)103 GST_START_TEST (test_state_changes_up_and_down_seq)
104 {
105 GstElement *element;
106 GList *e;
107
108 for (e = elements; e; e = e->next) {
109 const gchar *name = e->data;
110
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);
114
115 if (GST_IS_PIPELINE (element)) {
116 GST_DEBUG ("element %s is a pipeline", name);
117 }
118
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));
131 }
132 }
133
134 GST_END_TEST;
135
GST_START_TEST(test_state_changes_up_seq)136 GST_START_TEST (test_state_changes_up_seq)
137 {
138 GstElement *element;
139 GList *e;
140
141 for (e = elements; e; e = e->next) {
142 const gchar *name = e->data;
143
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);
147
148 if (GST_IS_PIPELINE (element)) {
149 GST_DEBUG ("element %s is a pipeline", name);
150 }
151
152 gst_element_set_state (element, GST_STATE_READY);
153
154 gst_element_set_state (element, GST_STATE_PAUSED);
155 gst_element_set_state (element, GST_STATE_READY);
156
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);
161
162 gst_element_set_state (element, GST_STATE_NULL);
163 gst_object_unref (GST_OBJECT (element));
164 }
165 }
166
167 GST_END_TEST;
168
GST_START_TEST(test_state_changes_down_seq)169 GST_START_TEST (test_state_changes_down_seq)
170 {
171 GstElement *element;
172 GList *e;
173
174 for (e = elements; e; e = e->next) {
175 const gchar *name = e->data;
176
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);
180
181 if (GST_IS_PIPELINE (element)) {
182 GST_DEBUG ("element %s is a pipeline", name);
183 }
184
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);
188
189 gst_element_set_state (element, GST_STATE_PAUSED);
190 gst_element_set_state (element, GST_STATE_PLAYING);
191
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);
196
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));
201 }
202 }
203
204 GST_END_TEST;
205
206 /* Separate function because XInitThreads leaks, but valgrind
207 * gets confused when a dynamically loaded symbol leaks, and
208 * shows it as a ??? symbol in an unrelated library, making
209 * it awkward to ignore in the suppression files
210 */
211 static void
call_xinitthreads(void)212 call_xinitthreads (void)
213 {
214 GModule *libx11;
215
216 libx11 =
217 g_module_open ("libX11.so.6", G_MODULE_BIND_LOCAL | G_MODULE_BIND_LAZY);
218 if (libx11) {
219 void (*xinitthreads) (void);
220 if (g_module_symbol (libx11, "XInitThreads", (gpointer *) & xinitthreads)) {
221 xinitthreads ();
222 }
223 g_module_close (libx11);
224 }
225 }
226
227 static Suite *
states_suite(void)228 states_suite (void)
229 {
230 Suite *s = suite_create ("states_base");
231 TCase *tc_chain = tcase_create ("general");
232
233 call_xinitthreads ();
234
235 suite_add_tcase (s, tc_chain);
236 tcase_add_checked_fixture (tc_chain, setup, teardown);
237 tcase_add_test (tc_chain, test_state_changes_up_and_down_seq);
238 tcase_add_test (tc_chain, test_state_changes_up_seq);
239 tcase_add_test (tc_chain, test_state_changes_down_seq);
240
241 return s;
242 }
243
244 GST_CHECK_MAIN (states);
245