|
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 |
|
28 #include <gst/gst_global.h> |
|
29 #include "config.h" |
|
30 #include <gst/check/gstcheck.h> |
|
31 #include <unistd.h> |
|
32 #include <libgstreamer_wsd_solution.h> |
|
33 |
|
34 #include <sys/types.h> |
|
35 #include <sys/stat.h> |
|
36 #include <fcntl.h> |
|
37 //#include <unistd.h> |
|
38 //#include <stdio.h> |
|
39 //#include <sys/select.h> |
|
40 |
|
41 #define LOG_FILE "c:\\logs\\states_logs.txt" |
|
42 #include "std_log_result.h" |
|
43 #define LOG_FILENAME_LINE __FILE__, __LINE__ |
|
44 //char* xmlfile = "states"; |
|
45 int fd_new; |
|
46 void create_xml(int result) |
|
47 { |
|
48 if(result) |
|
49 assert_failed = 1; |
|
50 |
|
51 testResultXml(xmlfile); |
|
52 close_log_file(); |
|
53 } |
|
54 |
|
55 |
|
56 #if EMULATOR |
|
57 static GET_GLOBAL_VAR_FROM_TLS(threads_running,gstcheck,gboolean) |
|
58 #define _gst_check_threads_running (*GET_GSTREAMER_WSD_VAR_NAME(threads_running,gstcheck,g)()) |
|
59 #else |
|
60 extern gboolean _gst_check_threads_running; |
|
61 #endif |
|
62 #if EMULATOR |
|
63 static GET_GLOBAL_VAR_FROM_TLS(raised_critical,gstcheck,gboolean) |
|
64 #define _gst_check_raised_critical (*GET_GSTREAMER_WSD_VAR_NAME(raised_critical,gstcheck,g)()) |
|
65 #else |
|
66 extern gboolean _gst_check_raised_critical; |
|
67 #endif |
|
68 //gboolean _gst_check_raised_warning = FALSE; |
|
69 #if EMULATOR |
|
70 static GET_GLOBAL_VAR_FROM_TLS(raised_warning,gstcheck,gboolean) |
|
71 #define _gst_check_raised_warning (*GET_GSTREAMER_WSD_VAR_NAME(raised_warning,gstcheck,g)()) |
|
72 #else |
|
73 extern gboolean _gst_check_raised_warning; |
|
74 #endif |
|
75 //gboolean _gst_check_expecting_log = FALSE; |
|
76 #if EMULATOR |
|
77 static GET_GLOBAL_VAR_FROM_TLS(expecting_log,gstcheck,gboolean) |
|
78 #define _gst_check_expecting_log (*GET_GSTREAMER_WSD_VAR_NAME(expecting_log,gstcheck,g)()) |
|
79 #else |
|
80 extern gboolean _gst_check_expecting_log; |
|
81 #endif |
|
82 |
|
83 #if EMULATOR |
|
84 GET_GLOBAL_VAR_FROM_TLS(buffers,gstcheck,GList*) |
|
85 #define buffers (*GET_GSTREAMER_WSD_VAR_NAME(buffers,gstcheck,g)()) |
|
86 #else |
|
87 extern GList *buffers; |
|
88 #endif |
|
89 |
|
90 |
|
91 static GList *elements = NULL; |
|
92 |
|
93 static void |
|
94 setup (void) |
|
95 { |
|
96 GList *features, *f; |
|
97 GList *plugins, *p; |
|
98 gchar **ignorelist = NULL; |
|
99 const gchar *STATE_IGNORE_ELEMENTS = NULL; |
|
100 |
|
101 GST_DEBUG("getting elements for package %s", PACKAGE); |
|
102 STATE_IGNORE_ELEMENTS = g_getenv ("STATE_IGNORE_ELEMENTS"); |
|
103 if (STATE_IGNORE_ELEMENTS) { |
|
104 GST_DEBUG ("Will ignore element factories: '%s'", STATE_IGNORE_ELEMENTS); |
|
105 ignorelist = g_strsplit (STATE_IGNORE_ELEMENTS, " ", 0); |
|
106 } |
|
107 |
|
108 plugins = gst_registry_get_plugin_list (gst_registry_get_default ()); |
|
109 |
|
110 for (p = plugins; p; p = p->next) { |
|
111 GstPlugin *plugin = p->data; |
|
112 if (strcmp (gst_plugin_get_source (plugin), PACKAGE) != 0) |
|
113 continue; |
|
114 |
|
115 features = |
|
116 gst_registry_get_feature_list_by_plugin (gst_registry_get_default (), |
|
117 gst_plugin_get_name (plugin)); |
|
118 |
|
119 for (f = features; f; f = f->next) { |
|
120 GstPluginFeature *feature = f->data; |
|
121 const gchar *name = gst_plugin_feature_get_name (feature); |
|
122 gboolean ignore = FALSE; |
|
123 |
|
124 if (!GST_IS_ELEMENT_FACTORY (feature)) |
|
125 continue; |
|
126 |
|
127 if (ignorelist) { |
|
128 gchar **s; |
|
129 |
|
130 for (s = ignorelist; s && *s; ++s) { |
|
131 if (g_str_has_prefix (name, *s)) { |
|
132 GST_DEBUG ("ignoring element %s", name); |
|
133 ignore = TRUE; |
|
134 } |
|
135 } |
|
136 if (ignore) |
|
137 continue; |
|
138 } |
|
139 |
|
140 GST_DEBUG ("adding element %s", name); |
|
141 elements = g_list_prepend (elements, (gpointer) g_strdup (name)); |
|
142 } |
|
143 gst_plugin_feature_list_free (features); |
|
144 } |
|
145 gst_plugin_list_free (plugins); |
|
146 g_strfreev (ignorelist); |
|
147 |
|
148 |
|
149 } |
|
150 |
|
151 static void |
|
152 teardown (void) |
|
153 { |
|
154 GList *e; |
|
155 |
|
156 for (e = elements; e; e = e->next) { |
|
157 g_free (e->data); |
|
158 } |
|
159 g_list_free (elements); |
|
160 elements = NULL; |
|
161 |
|
162 } |
|
163 |
|
164 static void create_file() |
|
165 { |
|
166 fd_new = open("c:\\data\\testdata_states.txt",O_CREAT|O_RDWR , 0666); |
|
167 write(fd_new, "hello",5); |
|
168 close(fd_new); |
|
169 } |
|
170 |
|
171 static void change_fd(GstElement *element) |
|
172 { |
|
173 create_file(); |
|
174 fd_new = open("c:\\data\\testdata_states.txt",O_RDONLY , 0666); |
|
175 g_object_set (G_OBJECT (element), "fd", fd_new, NULL); |
|
176 } |
|
177 |
|
178 void test_state_changes_up_and_down_seq() |
|
179 { |
|
180 GstElement *element; |
|
181 GList *e; |
|
182 |
|
183 //xmlfile = "test_state_changes_up_and_down_seq"; |
|
184 std_log(LOG_FILENAME_LINE, "Test Started test_state_changes_up_and_down_seq"); |
|
185 |
|
186 setup(); |
|
187 for (e = elements; e; e = e->next) { |
|
188 const gchar *name = e->data; |
|
189 |
|
190 GST_DEBUG ("testing element %s", name); |
|
191 std_log(LOG_FILENAME_LINE, ">> testing element %s", name); |
|
192 element = gst_element_factory_make (name, name); |
|
193 fail_if (element == NULL, "Could not make element from factory %s", name); |
|
194 TEST_ASSERT_FAIL |
|
195 if (GST_IS_PIPELINE (element)) { |
|
196 GST_DEBUG ("element %s is a pipeline", name); |
|
197 } |
|
198 if(!strcmp(name,"fdsrc")) |
|
199 { |
|
200 change_fd(element); |
|
201 } |
|
202 std_log(LOG_FILENAME_LINE, ">> setting state"); |
|
203 std_log(LOG_FILENAME_LINE, ">> setting state GST_STATE_READY %s", name); |
|
204 gst_element_set_state (element, GST_STATE_READY); |
|
205 std_log(LOG_FILENAME_LINE, ">> setting state GST_STATE_PAUSED %s", name); |
|
206 gst_element_set_state (element, GST_STATE_PAUSED); |
|
207 std_log(LOG_FILENAME_LINE, ">> setting state GST_STATE_PLAYING %s", name); |
|
208 gst_element_set_state (element, GST_STATE_PLAYING); |
|
209 std_log(LOG_FILENAME_LINE, ">> setting state GST_STATE_PAUSED %s", name); |
|
210 gst_element_set_state (element, GST_STATE_PAUSED); |
|
211 std_log(LOG_FILENAME_LINE, ">> setting state GST_STATE_READY %s", name); |
|
212 gst_element_set_state (element, GST_STATE_READY); |
|
213 std_log(LOG_FILENAME_LINE, ">> setting state GST_STATE_NULL %s", name); |
|
214 gst_element_set_state (element, GST_STATE_NULL); |
|
215 std_log(LOG_FILENAME_LINE, ">> setting state GST_STATE_PAUSED %s", name); |
|
216 gst_element_set_state (element, GST_STATE_PAUSED); |
|
217 std_log(LOG_FILENAME_LINE, ">> setting state GST_STATE_READY %s", name); |
|
218 gst_element_set_state (element, GST_STATE_READY); |
|
219 std_log(LOG_FILENAME_LINE, ">> setting state GST_STATE_PLAYING %s", name); |
|
220 gst_element_set_state (element, GST_STATE_PLAYING); |
|
221 std_log(LOG_FILENAME_LINE, ">> setting state GST_STATE_PAUSED %s", name); |
|
222 gst_element_set_state (element, GST_STATE_PAUSED); |
|
223 std_log(LOG_FILENAME_LINE, ">> setting state GST_STATE_NULL %s", name); |
|
224 gst_element_set_state (element, GST_STATE_NULL); |
|
225 if(!strcmp(name,"fdsrc")) |
|
226 { |
|
227 close(fd_new); |
|
228 } |
|
229 gst_object_unref (GST_OBJECT (element)); |
|
230 } |
|
231 |
|
232 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
233 create_xml(0); |
|
234 } |
|
235 |
|
236 |
|
237 |
|
238 void test_state_changes_up_seq() |
|
239 { |
|
240 GstElement *element; |
|
241 GList *e; |
|
242 |
|
243 //xmlfile = "test_state_changes_up_seq"; |
|
244 std_log(LOG_FILENAME_LINE, "Test Started test_state_changes_up_seq"); |
|
245 setup(); |
|
246 for (e = elements; e; e = e->next) { |
|
247 const gchar *name = e->data; |
|
248 |
|
249 GST_DEBUG ("testing element %s", name); |
|
250 element = gst_element_factory_make (name, name); |
|
251 fail_if (element == NULL, "Could not make element from factory %s", name); |
|
252 TEST_ASSERT_FAIL |
|
253 |
|
254 if (GST_IS_PIPELINE (element)) { |
|
255 GST_DEBUG ("element %s is a pipeline", name); |
|
256 } |
|
257 if(!strcmp(name,"fdsrc")) |
|
258 { |
|
259 change_fd(element); |
|
260 } |
|
261 gst_element_set_state (element, GST_STATE_READY); |
|
262 |
|
263 gst_element_set_state (element, GST_STATE_PAUSED); |
|
264 gst_element_set_state (element, GST_STATE_READY); |
|
265 |
|
266 gst_element_set_state (element, GST_STATE_PAUSED); |
|
267 gst_element_set_state (element, GST_STATE_PLAYING); |
|
268 gst_element_set_state (element, GST_STATE_PAUSED); |
|
269 gst_element_set_state (element, GST_STATE_READY); |
|
270 |
|
271 gst_element_set_state (element, GST_STATE_NULL); |
|
272 if(!strcmp(name,"fdsrc")) |
|
273 { |
|
274 close(fd_new); |
|
275 } |
|
276 gst_object_unref (GST_OBJECT (element)); |
|
277 } |
|
278 |
|
279 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
280 create_xml(0); |
|
281 |
|
282 } |
|
283 |
|
284 |
|
285 |
|
286 void test_state_changes_down_seq() |
|
287 { |
|
288 GstElement *element; |
|
289 GList *e; |
|
290 |
|
291 //xmlfile = "test_state_changes_down_seq"; |
|
292 std_log(LOG_FILENAME_LINE, "test_state_changes_down_seq"); |
|
293 setup(); |
|
294 for (e = elements; e; e = e->next) { |
|
295 const gchar *name = e->data; |
|
296 |
|
297 GST_DEBUG ("testing element %s", name); |
|
298 element = gst_element_factory_make (name, name); |
|
299 fail_if (element == NULL, "Could not make element from factory %s", name); |
|
300 TEST_ASSERT_FAIL |
|
301 |
|
302 if (GST_IS_PIPELINE (element)) { |
|
303 GST_DEBUG ("element %s is a pipeline", name); |
|
304 } |
|
305 |
|
306 if(!strcmp(name,"fdsrc")) |
|
307 { |
|
308 change_fd(element); |
|
309 } |
|
310 gst_element_set_state (element, GST_STATE_READY); |
|
311 gst_element_set_state (element, GST_STATE_PAUSED); |
|
312 gst_element_set_state (element, GST_STATE_PLAYING); |
|
313 |
|
314 gst_element_set_state (element, GST_STATE_PAUSED); |
|
315 gst_element_set_state (element, GST_STATE_PLAYING); |
|
316 |
|
317 gst_element_set_state (element, GST_STATE_PAUSED); |
|
318 gst_element_set_state (element, GST_STATE_READY); |
|
319 gst_element_set_state (element, GST_STATE_PAUSED); |
|
320 gst_element_set_state (element, GST_STATE_PLAYING); |
|
321 |
|
322 gst_element_set_state (element, GST_STATE_PAUSED); |
|
323 gst_element_set_state (element, GST_STATE_READY); |
|
324 gst_element_set_state (element, GST_STATE_NULL); |
|
325 |
|
326 if(!strcmp(name,"fdsrc")) |
|
327 { |
|
328 close(fd_new); |
|
329 } |
|
330 gst_object_unref (GST_OBJECT (element)); |
|
331 } |
|
332 |
|
333 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
334 create_xml(0); |
|
335 |
|
336 } |
|
337 |
|
338 |
|
339 |
|
340 void (*fn[]) (void) = { |
|
341 test_state_changes_up_and_down_seq, |
|
342 test_state_changes_up_seq, |
|
343 test_state_changes_down_seq |
|
344 }; |
|
345 |
|
346 char *args[] = { |
|
347 "test_state_changes_up_and_down_seq", |
|
348 "test_state_changes_up_seq", |
|
349 "test_state_changes_down_seq" |
|
350 }; |
|
351 GST_CHECK_MAIN (states); |