Merge remote-tracking branch 'origin/master' into 0.11
[platform/upstream/gst-plugins-good.git] / tests / check / generic / states.c
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   GstRegistry *def;
41
42   GST_DEBUG ("getting elements for package %s", PACKAGE);
43   STATE_IGNORE_ELEMENTS = g_getenv ("GST_STATE_IGNORE_ELEMENTS");
44   if (!g_getenv ("GST_NO_STATE_IGNORE_ELEMENTS") && STATE_IGNORE_ELEMENTS) {
45     GST_DEBUG ("Will ignore element factories: '%s'", STATE_IGNORE_ELEMENTS);
46     ignorelist = g_strsplit (STATE_IGNORE_ELEMENTS, " ", 0);
47   }
48
49   def = gst_registry_get ();
50
51   plugins = gst_registry_get_plugin_list (def);
52
53   for (p = plugins; p; p = p->next) {
54     GstPlugin *plugin = p->data;
55
56     if (strcmp (gst_plugin_get_source (plugin), PACKAGE) != 0)
57       continue;
58
59     features =
60         gst_registry_get_feature_list_by_plugin (def,
61         gst_plugin_get_name (plugin));
62
63     for (f = features; f; f = f->next) {
64       GstPluginFeature *feature = f->data;
65       const gchar *name = gst_plugin_feature_get_name (feature);
66       gboolean ignore = FALSE;
67
68       if (!GST_IS_ELEMENT_FACTORY (feature))
69         continue;
70
71       if (ignorelist) {
72         gchar **s;
73
74         for (s = ignorelist; s && *s; ++s) {
75           if (g_str_has_prefix (name, *s)) {
76             GST_DEBUG ("ignoring element %s", name);
77             ignore = TRUE;
78           }
79         }
80         if (ignore)
81           continue;
82       }
83
84       GST_DEBUG ("adding element %s", name);
85       elements = g_list_prepend (elements, (gpointer) g_strdup (name));
86     }
87     gst_plugin_feature_list_free (features);
88   }
89   gst_plugin_list_free (plugins);
90   g_strfreev (ignorelist);
91 }
92
93 static void
94 teardown (void)
95 {
96   GList *e;
97
98   for (e = elements; e; e = e->next) {
99     g_free (e->data);
100   }
101   g_list_free (elements);
102   elements = NULL;
103 }
104
105
106 GST_START_TEST (test_state_changes_up_and_down_seq)
107 {
108   GstElement *element;
109   GList *e;
110
111   for (e = elements; e; e = e->next) {
112     const gchar *name = e->data;
113
114     GST_INFO ("testing element %s", name);
115     element = gst_element_factory_make (name, name);
116     fail_if (element == NULL, "Could not make element from factory %s", name);
117
118     if (GST_IS_PIPELINE (element)) {
119       GST_DEBUG ("element %s is a pipeline", name);
120     }
121
122     gst_element_set_state (element, GST_STATE_READY);
123     gst_element_set_state (element, GST_STATE_PAUSED);
124     gst_element_set_state (element, GST_STATE_PLAYING);
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_NULL);
128     gst_element_set_state (element, GST_STATE_PAUSED);
129     gst_element_set_state (element, GST_STATE_READY);
130     gst_element_set_state (element, GST_STATE_PLAYING);
131     gst_element_set_state (element, GST_STATE_PAUSED);
132     gst_element_set_state (element, GST_STATE_NULL);
133     gst_object_unref (GST_OBJECT (element));
134   }
135 }
136
137 GST_END_TEST;
138
139 GST_START_TEST (test_state_changes_up_seq)
140 {
141   GstElement *element;
142   GList *e;
143
144   for (e = elements; e; e = e->next) {
145     const gchar *name = e->data;
146
147     GST_INFO ("testing element %s", name);
148     element = gst_element_factory_make (name, name);
149     fail_if (element == NULL, "Could not make element from factory %s", name);
150
151     if (GST_IS_PIPELINE (element)) {
152       GST_DEBUG ("element %s is a pipeline", name);
153     }
154
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_READY);
159
160     gst_element_set_state (element, GST_STATE_PAUSED);
161     gst_element_set_state (element, GST_STATE_PLAYING);
162     gst_element_set_state (element, GST_STATE_PAUSED);
163     gst_element_set_state (element, GST_STATE_READY);
164
165     gst_element_set_state (element, GST_STATE_NULL);
166     gst_object_unref (GST_OBJECT (element));
167   }
168 }
169
170 GST_END_TEST;
171
172 GST_START_TEST (test_state_changes_down_seq)
173 {
174   GstElement *element;
175   GList *e;
176
177   for (e = elements; e; e = e->next) {
178     const gchar *name = e->data;
179
180     GST_INFO ("testing element %s", name);
181     element = gst_element_factory_make (name, name);
182     fail_if (element == NULL, "Could not make element from factory %s", name);
183
184     if (GST_IS_PIPELINE (element)) {
185       GST_DEBUG ("element %s is a pipeline", name);
186     }
187
188     gst_element_set_state (element, GST_STATE_READY);
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_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_PAUSED);
198     gst_element_set_state (element, GST_STATE_PLAYING);
199
200     gst_element_set_state (element, GST_STATE_PAUSED);
201     gst_element_set_state (element, GST_STATE_READY);
202     gst_element_set_state (element, GST_STATE_NULL);
203     gst_object_unref (GST_OBJECT (element));
204   }
205 }
206
207 GST_END_TEST;
208
209
210 static Suite *
211 states_suite (void)
212 {
213   Suite *s = suite_create ("states");
214   TCase *tc_chain = tcase_create ("general");
215
216   suite_add_tcase (s, tc_chain);
217   tcase_add_checked_fixture (tc_chain, setup, teardown);
218   tcase_add_test (tc_chain, test_state_changes_up_and_down_seq);
219   tcase_add_test (tc_chain, test_state_changes_up_seq);
220   tcase_add_test (tc_chain, test_state_changes_down_seq);
221
222   return s;
223 }
224
225 GST_CHECK_MAIN (states);