Debian Codegraph @

tests/check/generic/states.c

raw symbols SCIP
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 <gst/check/gstcheck.h>
28
29 static GList *elements = NULL;
30
31 static void
32 setup ()
33 {
34 GList *features, *f;
35 GList *plugins, *p;
36 gchar **ignorelist = NULL;
37 const gchar *STATE_IGNORE_ELEMENTS = NULL;
38
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);
44 }
45
46 plugins = gst_registry_get_plugin_list (gst_registry_get ());
47
48 for (p = plugins; p; p = p->next) {
49 GstPlugin *plugin = p->data;
50
51 if (strcmp (gst_plugin_get_source (plugin), PACKAGE) != 0)
52 continue;
53
54 features =
55 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
56 gst_plugin_get_name (plugin));
57
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;
62
63 if (!GST_IS_ELEMENT_FACTORY (feature))
64 continue;
65
66 if (ignorelist) {
67 gchar **s;
68
69 for (s = ignorelist; s && *s; ++s) {
70 if (g_str_has_prefix (name, *s)) {
71 GST_DEBUG ("ignoring element %s", name);
72 ignore = TRUE;
73 }
74 }
75 if (ignore)
76 continue;
77 }
78
79 GST_DEBUG ("adding element %s", name);
80 elements = g_list_prepend (elements, (gpointer) g_strdup (name));
81 }
82 gst_plugin_feature_list_free (features);
83 }
84 gst_plugin_list_free (plugins);
85 g_strfreev (ignorelist);
86 }
87
88 static void
89 teardown ()
90 {
91 GList *e;
92
93 for (e = elements; e; e = e->next) {
94 g_free (e->data);
95 }
96 g_list_free (elements);
97 elements = NULL;
98 }
99
100
101 GST_START_TEST (test_state_changes_up_and_down_seq)
102 {
103 GstElement *element;
104 GList *e;
105
106 for (e = elements; e; e = e->next) {
107 const gchar *name = e->data;
108
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);
112
113 if (GST_IS_PIPELINE (element)) {
114 GST_DEBUG ("element %s is a pipeline", name);
115 }
116
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));
129 }
130 }
131
132 GST_END_TEST;
133
134 GST_START_TEST (test_state_changes_up_seq)
135 {
136 GstElement *element;
137 GList *e;
138
139 for (e = elements; e; e = e->next) {
140 const gchar *name = e->data;
141
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);
145
146 if (GST_IS_PIPELINE (element)) {
147 GST_DEBUG ("element %s is a pipeline", name);
148 }
149
150 gst_element_set_state (element, GST_STATE_READY);
151
152 gst_element_set_state (element, GST_STATE_PAUSED);
153 gst_element_set_state (element, GST_STATE_READY);
154
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);
159
160 gst_element_set_state (element, GST_STATE_NULL);
161 gst_object_unref (GST_OBJECT (element));
162 }
163 }
164
165 GST_END_TEST;
166
167 GST_START_TEST (test_state_changes_down_seq)
168 {
169 GstElement *element;
170 GList *e;
171
172 for (e = elements; e; e = e->next) {
173 const gchar *name = e->data;
174
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);
178
179 if (GST_IS_PIPELINE (element)) {
180 GST_DEBUG ("element %s is a pipeline", name);
181 }
182
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);
186
187 gst_element_set_state (element, GST_STATE_PAUSED);
188 gst_element_set_state (element, GST_STATE_PLAYING);
189
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);
194
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));
199 }
200 }
201
202 GST_END_TEST;
203
204 Suite *
205 states_suite (void)
206 {
207 Suite *s = suite_create ("states_ugly");
208 TCase *tc_chain = tcase_create ("general");
209
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);
215
216 return s;
217 }
218
219 GST_CHECK_MAIN (states);