1 /* GStreamer unit test for the autodetect elements
3 * Copyright (C) <2006> Tim-Philipp Müller <tim centricular net>
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.
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.
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.
25 #include <gst/check/gstcheck.h>
27 GST_START_TEST (test_autovideosink_ghostpad_error_case)
29 GstStateChangeReturn state_ret;
30 GstElement *pipeline, *src, *filter, *sink;
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);
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);
41 if (state_ret != GST_STATE_CHANGE_SUCCESS) {
42 GST_WARNING ("No usable video sink, skipping test");
43 gst_object_unref (sink);
47 pipeline = gst_pipeline_new ("pipeline");
48 src = gst_element_factory_make ("fakesrc", NULL);
49 filter = gst_element_factory_make ("capsfilter", NULL);
51 caps = gst_caps_new_simple ("video/x-raw-yuv", "format", GST_TYPE_FOURCC,
52 GST_MAKE_FOURCC ('A', 'C', 'D', 'C'), NULL);
54 g_object_set (filter, "caps", caps, NULL);
55 gst_caps_unref (caps);
57 gst_bin_add_many (GST_BIN (pipeline), src, filter, sink, NULL);
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");
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 */
69 gst_element_get_state (pipeline, &state, &state, GST_CLOCK_TIME_NONE);
71 fail_unless (state_ret == GST_STATE_CHANGE_FAILURE,
72 "pipeline _set_state() to PAUSED succeeded but should have failed");
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
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");
82 gst_object_unref (pipeline);
87 /* disable this for now, too many valgrind suppressions needed for libasound */
89 GST_START_TEST (test_autoaudiosink_ghostpad_error_case)
91 GstStateChangeReturn state_ret;
92 GstElement *pipeline, *src, *filter, *sink;
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);
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);
103 if (state_ret != GST_STATE_CHANGE_SUCCESS) {
104 GST_WARNING ("No usable audio sink, skipping test");
105 gst_object_unref (sink);
109 pipeline = gst_pipeline_new ("pipeline");
110 src = gst_element_factory_make ("fakesrc", NULL);
111 filter = gst_element_factory_make ("capsfilter", NULL);
113 caps = gst_caps_new_simple ("audio/x-raw-int", "width", G_TYPE_INT, 42, NULL);
115 g_object_set (filter, "caps", caps, NULL);
116 gst_caps_unref (caps);
118 gst_bin_add_many (GST_BIN (pipeline), src, filter, sink, NULL);
120 fail_unless (gst_element_link (src, filter));
121 fail_unless (gst_element_link (filter, sink));
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");
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
131 state_ret = gst_element_set_state (pipeline, GST_STATE_NULL);
132 fail_unless (state_ret == GST_STATE_CHANGE_SUCCESS);
135 gst_object_unref (pipeline);
142 autodetect_suite (void)
144 guint maj, min, mic, nano;
146 Suite *s = suite_create ("autodetect");
147 TCase *tc_chain = tcase_create ("general");
149 suite_add_tcase (s, tc_chain);
151 gst_version (&maj, &min, &mic, &nano);
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); */
163 GST_CHECK_MAIN (autodetect);