|
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., 59 Temple Place - Suite 330, |
|
20 * Boston, MA 02111-1307, USA. |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 # include "config.h" |
|
25 #endif |
|
26 |
|
27 #include <unistd.h> |
|
28 |
|
29 #include <gst/check/gstcheck.h> |
|
30 |
|
31 static GList *elements = NULL; |
|
32 |
|
33 static 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 ("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); |
|
46 } |
|
47 |
|
48 plugins = gst_registry_get_plugin_list (gst_registry_get_default ()); |
|
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_default (), |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
207 static Suite * |
|
208 states_suite (void) |
|
209 { |
|
210 Suite *s = suite_create ("states"); |
|
211 TCase *tc_chain = tcase_create ("general"); |
|
212 |
|
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); |
|
218 |
|
219 return s; |
|
220 } |
|
221 |
|
222 GST_CHECK_MAIN (states); |