upload tizen1.0 source
[framework/multimedia/gst-plugins-good0.10.git] / tests / check / elements / autodetect.c
1 /* GStreamer unit test for the autodetect elements
2  *
3  * Copyright (C) <2006> Tim-Philipp Müller <tim centricular net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24
25 #include <gst/check/gstcheck.h>
26
27 GST_START_TEST (test_autovideosink_ghostpad_error_case)
28 {
29   GstStateChangeReturn state_ret;
30   GstElement *pipeline, *src, *filter, *sink;
31   GstCaps *caps;
32
33   /* check that there's a usable video sink (think of build bot case) */
34   sink = gst_element_factory_make ("autovideosink", NULL);
35   state_ret = gst_element_set_state (sink, GST_STATE_READY);
36
37   /* need to set state back to NULL, or our test won't work since we
38    * already have detected the real caps in ready and then linking fails */
39   gst_element_set_state (sink, GST_STATE_NULL);
40
41   if (state_ret != GST_STATE_CHANGE_SUCCESS) {
42     GST_WARNING ("No usable video sink, skipping test");
43     gst_object_unref (sink);
44     return;
45   }
46
47   pipeline = gst_pipeline_new ("pipeline");
48   src = gst_element_factory_make ("fakesrc", NULL);
49   filter = gst_element_factory_make ("capsfilter", NULL);
50
51   caps = gst_caps_new_simple ("video/x-raw-yuv", "format", GST_TYPE_FOURCC,
52       GST_MAKE_FOURCC ('A', 'C', 'D', 'C'), NULL);
53
54   g_object_set (filter, "caps", caps, NULL);
55   gst_caps_unref (caps);
56
57   gst_bin_add_many (GST_BIN (pipeline), src, filter, sink, NULL);
58
59   fail_unless (gst_element_link (src, filter), "Failed to link src to filter");
60   fail_unless (gst_element_link (filter, sink),
61       "Failed to link filter to sink");
62
63   /* this should fail, there's no such format */
64   state_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
65   fail_unless (state_ret == GST_STATE_CHANGE_FAILURE,
66       "pipeline _set_state() to PAUSED succeeded but should have failed");
67
68   /* so, we hit an error and try to shut down the pipeline; this shouldn't
69    * deadlock or block anywhere when autovideosink resets the ghostpad
70    * targets etc. */
71   state_ret = gst_element_set_state (pipeline, GST_STATE_NULL);
72   fail_unless (state_ret == GST_STATE_CHANGE_SUCCESS,
73       "State change on pipeline failed");
74
75   /* clean up */
76   gst_object_unref (pipeline);
77 }
78
79 GST_END_TEST;
80
81 /* disable this for now, too many valgrind suppressions needed for libasound */
82 #if 0
83 GST_START_TEST (test_autoaudiosink_ghostpad_error_case)
84 {
85   GstStateChangeReturn state_ret;
86   GstElement *pipeline, *src, *filter, *sink;
87   GstCaps *caps;
88
89   /* check that there's a usable audio sink (think of build bot case) */
90   sink = gst_element_factory_make ("autoaudiosink", NULL);
91   state_ret = gst_element_set_state (sink, GST_STATE_READY);
92
93   /* need to set state back to NULL, or our test won't work since we
94    * already have detected the real caps in ready and then linking fails */
95   gst_element_set_state (sink, GST_STATE_NULL);
96
97   if (state_ret != GST_STATE_CHANGE_SUCCESS) {
98     GST_WARNING ("No usable audio sink, skipping test");
99     gst_object_unref (sink);
100     return;
101   }
102
103   pipeline = gst_pipeline_new ("pipeline");
104   src = gst_element_factory_make ("fakesrc", NULL);
105   filter = gst_element_factory_make ("capsfilter", NULL);
106
107   caps = gst_caps_new_simple ("audio/x-raw-int", "width", G_TYPE_INT, 42, NULL);
108
109   g_object_set (filter, "caps", caps, NULL);
110   gst_caps_unref (caps);
111
112   gst_bin_add_many (GST_BIN (pipeline), src, filter, sink, NULL);
113
114   fail_unless (gst_element_link (src, filter));
115   fail_unless (gst_element_link (filter, sink));
116
117   /* this should fail, there's no such width (hopefully) */
118   state_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
119   fail_unless (state_ret == GST_STATE_CHANGE_FAILURE,
120       "pipeline _set_state() to PAUSED succeeded but should have failed");
121
122   /* so, we hit an error and try to shut down the pipeline; this shouldn't
123    * deadlock or block anywhere when autoaudiosink resets the ghostpad
124    * targets etc. */
125   state_ret = gst_element_set_state (pipeline, GST_STATE_NULL);
126   fail_unless (state_ret == GST_STATE_CHANGE_SUCCESS);
127
128   /* clean up */
129   gst_object_unref (pipeline);
130 }
131
132 GST_END_TEST;
133 #endif
134
135 static Suite *
136 autodetect_suite (void)
137 {
138   guint maj, min, mic, nano;
139
140   Suite *s = suite_create ("autodetect");
141   TCase *tc_chain = tcase_create ("general");
142
143   suite_add_tcase (s, tc_chain);
144
145   gst_version (&maj, &min, &mic, &nano);
146
147   /* requires fixes from 0.10.10.1, but don't want to add a hard dependency
148    * in configure.ac just for this yet */
149   if (maj > 0 || min > 10 || mic > 10 || (mic == 10 && nano > 0)) {
150     tcase_add_test (tc_chain, test_autovideosink_ghostpad_error_case);
151     /* tcase_add_test (tc_chain, test_autoaudiosink_ghostpad_error_case); */
152   }
153
154   return s;
155 }
156
157 GST_CHECK_MAIN (autodetect);