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