plug test leak
[platform/upstream/gstreamer.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 GST_START_TEST (test_state_changes)
32 {
33   GstElement *element;
34   GList *features, *f;
35   GList *plugins, *p;
36   gchar **ignorelist = NULL;
37   const gchar *STATE_IGNORE_ELEMENTS = NULL;
38
39   GST_DEBUG ("testing elements from source %s", PACKAGE);
40   STATE_IGNORE_ELEMENTS = g_getenv ("STATE_IGNORE_ELEMENTS");
41   if (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_default ());
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_default (),
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 ("testing element %s", name);
80       element = gst_element_factory_make (name, name);
81       fail_if (element == NULL, "Could not make element from factory %s", name);
82
83       if (GST_IS_PIPELINE (element)) {
84         GST_DEBUG ("element %s is a pipeline", name);
85       }
86
87       gst_element_set_state (element, GST_STATE_READY);
88       gst_element_set_state (element, GST_STATE_PAUSED);
89       gst_element_set_state (element, GST_STATE_PLAYING);
90       gst_element_set_state (element, GST_STATE_PAUSED);
91       gst_element_set_state (element, GST_STATE_READY);
92       gst_element_set_state (element, GST_STATE_NULL);
93       gst_element_set_state (element, GST_STATE_PAUSED);
94       gst_element_set_state (element, GST_STATE_READY);
95       gst_element_set_state (element, GST_STATE_PLAYING);
96       gst_element_set_state (element, GST_STATE_PAUSED);
97       gst_element_set_state (element, GST_STATE_NULL);
98       gst_object_unref (GST_OBJECT (element));
99     }
100     gst_plugin_feature_list_free (features);
101   }
102   gst_plugin_list_free (plugins);
103   g_strfreev (ignorelist);
104 }
105
106 GST_END_TEST;
107
108 Suite *
109 states_suite (void)
110 {
111   Suite *s = suite_create ("states");
112   TCase *tc_chain = tcase_create ("general");
113
114   suite_add_tcase (s, tc_chain);
115   tcase_add_test (tc_chain, test_state_changes);
116
117   return s;
118 }
119
120 GST_CHECK_MAIN (states);