tests: videorate: remove obsolete color-matrix caps field
[platform/upstream/gstreamer.git] / tests / check / elements / appsrc.c
1 /* GStreamer
2  *
3  * Copyright (C) 2010, Thiago Santos <thiago.sousa.santos@collabora.co.uk>
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 #include <gst/check/gstcheck.h>
22 #include <gst/app/gstappsrc.h>
23
24 #define SAMPLE_CAPS "application/x-gst-check-test"
25
26 static GstPad *mysinkpad;
27
28 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
29     GST_PAD_SINK,
30     GST_PAD_ALWAYS,
31     GST_STATIC_CAPS_ANY);
32
33 static GstElement *
34 setup_appsrc (void)
35 {
36   GstElement *appsrc;
37
38   GST_DEBUG ("setup_appsrc");
39   appsrc = gst_check_setup_element ("appsrc");
40   mysinkpad = gst_check_setup_sink_pad (appsrc, &sinktemplate);
41
42   gst_pad_set_active (mysinkpad, TRUE);
43
44   return appsrc;
45 }
46
47 static void
48 cleanup_appsrc (GstElement * appsrc)
49 {
50   GST_DEBUG ("cleanup_appsrc");
51
52   gst_check_teardown_sink_pad (appsrc);
53   gst_check_teardown_element (appsrc);
54 }
55
56 /*
57  * Pushes 4 buffers into appsrc and checks the caps on them on the output.
58  *
59  * Appsrc is configured with caps=SAMPLE_CAPS, so the buffers should have the
60  * same caps that they were pushed with.
61  *
62  * The 4 buffers have NULL, SAMPLE_CAPS, NULL, SAMPLE_CAPS caps,
63  * respectively.
64  */
65 GST_START_TEST (test_appsrc_non_null_caps)
66 {
67   GstElement *src;
68   GstBuffer *buffer;
69   GstCaps *caps, *ccaps;
70
71   src = setup_appsrc ();
72
73   caps = gst_caps_from_string (SAMPLE_CAPS);
74   g_object_set (src, "caps", caps, NULL);
75
76   ASSERT_SET_STATE (src, GST_STATE_PLAYING, GST_STATE_CHANGE_SUCCESS);
77
78   buffer = gst_buffer_new_and_alloc (4);
79   fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
80           buffer) == GST_FLOW_OK);
81
82   buffer = gst_buffer_new_and_alloc (4);
83   fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
84           buffer) == GST_FLOW_OK);
85
86   buffer = gst_buffer_new_and_alloc (4);
87   fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
88           buffer) == GST_FLOW_OK);
89
90   buffer = gst_buffer_new_and_alloc (4);
91   fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
92           buffer) == GST_FLOW_OK);
93
94   fail_unless (gst_app_src_end_of_stream (GST_APP_SRC (src)) == GST_FLOW_OK);
95
96   /* Give some time to the appsrc loop to push the buffers */
97   g_usleep (G_USEC_PER_SEC * 3);
98
99   /* Check the output caps */
100   fail_unless (g_list_length (buffers) == 4);
101
102   ccaps = gst_pad_get_current_caps (mysinkpad);
103   fail_unless (gst_caps_is_equal (ccaps, caps));
104   gst_caps_unref (ccaps);
105
106   ASSERT_SET_STATE (src, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS);
107   gst_caps_unref (caps);
108   cleanup_appsrc (src);
109 }
110
111 GST_END_TEST;
112
113
114 static Suite *
115 appsrc_suite (void)
116 {
117   Suite *s = suite_create ("appsrc");
118   TCase *tc_chain = tcase_create ("general");
119
120   tcase_add_test (tc_chain, test_appsrc_non_null_caps);
121
122   suite_add_tcase (s, tc_chain);
123
124   return s;
125 }
126
127 GST_CHECK_MAIN (appsrc);