tizen 2.0 init
[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   if (state_ret == GST_STATE_CHANGE_ASYNC) {
66     /* make sure we wait for the actual success/failure to happen */
67     GstState state;
68     state_ret =
69         gst_element_get_state (pipeline, &state, &state, GST_CLOCK_TIME_NONE);
70   }
71   fail_unless (state_ret == GST_STATE_CHANGE_FAILURE,
72       "pipeline _set_state() to PAUSED succeeded but should have failed");
73
74   /* so, we hit an error and try to shut down the pipeline; this shouldn't
75    * deadlock or block anywhere when autovideosink resets the ghostpad
76    * targets etc. */
77   state_ret = gst_element_set_state (pipeline, GST_STATE_NULL);
78   fail_unless (state_ret == GST_STATE_CHANGE_SUCCESS,
79       "State change on pipeline failed");
80
81   /* clean up */
82   gst_object_unref (pipeline);
83 }
84
85 GST_END_TEST;
86
87 /* disable this for now, too many valgrind suppressions needed for libasound */
88 #if 0
89 GST_START_TEST (test_autoaudiosink_ghostpad_error_case)
90 {
91   GstStateChangeReturn state_ret;
92   GstElement *pipeline, *src, *filter, *sink;
93   GstCaps *caps;
94
95   /* check that there's a usable audio sink (think of build bot case) */
96   sink = gst_element_factory_make ("autoaudiosink", NULL);
97   state_ret = gst_element_set_state (sink, GST_STATE_READY);
98
99   /* need to set state back to NULL, or our test won't work since we
100    * already have detected the real caps in ready and then linking fails */
101   gst_element_set_state (sink, GST_STATE_NULL);
102
103   if (state_ret != GST_STATE_CHANGE_SUCCESS) {
104     GST_WARNING ("No usable audio sink, skipping test");
105     gst_object_unref (sink);
106     return;
107   }
108
109   pipeline = gst_pipeline_new ("pipeline");
110   src = gst_element_factory_make ("fakesrc", NULL);
111   filter = gst_element_factory_make ("capsfilter", NULL);
112
113   caps = gst_caps_new_simple ("audio/x-raw-int", "width", G_TYPE_INT, 42, NULL);
114
115   g_object_set (filter, "caps", caps, NULL);
116   gst_caps_unref (caps);
117
118   gst_bin_add_many (GST_BIN (pipeline), src, filter, sink, NULL);
119
120   fail_unless (gst_element_link (src, filter));
121   fail_unless (gst_element_link (filter, sink));
122
123   /* this should fail, there's no such width (hopefully) */
124   state_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
125   fail_unless (state_ret == GST_STATE_CHANGE_FAILURE,
126       "pipeline _set_state() to PAUSED succeeded but should have failed");
127
128   /* so, we hit an error and try to shut down the pipeline; this shouldn't
129    * deadlock or block anywhere when autoaudiosink resets the ghostpad
130    * targets etc. */
131   state_ret = gst_element_set_state (pipeline, GST_STATE_NULL);
132   fail_unless (state_ret == GST_STATE_CHANGE_SUCCESS);
133
134   /* clean up */
135   gst_object_unref (pipeline);
136 }
137
138 GST_END_TEST;
139 #endif
140
141 static Suite *
142 autodetect_suite (void)
143 {
144   guint maj, min, mic, nano;
145
146   Suite *s = suite_create ("autodetect");
147   TCase *tc_chain = tcase_create ("general");
148
149   suite_add_tcase (s, tc_chain);
150
151   gst_version (&maj, &min, &mic, &nano);
152
153   /* requires fixes from 0.10.10.1, but don't want to add a hard dependency
154    * in configure.ac just for this yet */
155   if (maj > 0 || min > 10 || mic > 10 || (mic == 10 && nano > 0)) {
156     tcase_add_test (tc_chain, test_autovideosink_ghostpad_error_case);
157     /* tcase_add_test (tc_chain, test_autoaudiosink_ghostpad_error_case); */
158   }
159
160   return s;
161 }
162
163 GST_CHECK_MAIN (autodetect);