Imported Upstream version 0.10.36
[profile/ivi/gstreamer.git] / tests / check / elements / capsfilter.c
1 /* GStreamer unit test for capsfilter
2  * Copyright (C) <2008> Tim-Philipp Müller <tim centricular net>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <gst/check/gstcheck.h>
21
22 #define CAPS_TEMPLATE_STRING            \
23     "audio/x-raw-int, "                 \
24     "channels = (int) [ 1, 2], "        \
25     "rate = (int) [ 1,  MAX ]"
26
27 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
28     GST_PAD_SINK,
29     GST_PAD_ALWAYS,
30     GST_STATIC_CAPS (CAPS_TEMPLATE_STRING)
31     );
32
33 GST_START_TEST (test_unfixed_downstream_caps)
34 {
35   GstElement *pipe, *src, *filter;
36   GstCaps *filter_caps;
37   GstPad *mysinkpad;
38   GstMessage *msg;
39
40   pipe = gst_check_setup_element ("pipeline");
41
42   src = gst_check_setup_element ("fakesrc");
43   g_object_set (src, "sizetype", 2, "sizemax", 1024, "num-buffers", 1, NULL);
44
45   filter = gst_check_setup_element ("capsfilter");
46   filter_caps = gst_caps_from_string ("audio/x-raw-int, rate=(int)44100");
47   fail_unless (filter_caps != NULL);
48   g_object_set (filter, "caps", filter_caps, NULL);
49
50   gst_bin_add_many (GST_BIN (pipe), src, filter, NULL);
51   fail_unless (gst_element_link (src, filter));
52
53   mysinkpad = gst_check_setup_sink_pad (filter, &sinktemplate, NULL);
54   gst_pad_set_active (mysinkpad, TRUE);
55
56   fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_PLAYING),
57       GST_STATE_CHANGE_SUCCESS);
58
59   /* wait for error on bus */
60   msg = gst_bus_poll (GST_ELEMENT_BUS (pipe),
61       GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
62
63   fail_if (GST_MESSAGE_TYPE (msg) != GST_MESSAGE_ERROR,
64       "Expected ERROR message, got EOS message");
65   gst_message_unref (msg);
66
67   /* We don't expect any output buffers unless the check fails */
68   fail_unless (buffers == NULL);
69
70   /* cleanup */
71   GST_DEBUG ("cleanup");
72
73   gst_pad_set_active (mysinkpad, FALSE);
74   gst_check_teardown_sink_pad (filter);
75   gst_check_teardown_element (pipe);
76   gst_caps_unref (filter_caps);
77 }
78
79 GST_END_TEST;
80
81 static Suite *
82 capsfilter_suite (void)
83 {
84   Suite *s = suite_create ("capsfilter");
85   TCase *tc_chain = tcase_create ("general");
86
87   suite_add_tcase (s, tc_chain);
88   tcase_add_test (tc_chain, test_unfixed_downstream_caps);
89
90   return s;
91 }
92
93 GST_CHECK_MAIN (capsfilter)