3 * unit test for capssetter
5 * Copyright (C) <2009> Mark Nauwelaerts <mnauw@users.sourceforge.net>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
25 #include <gst/check/gstcheck.h>
28 /* For ease of programming we use globals to keep refs for our floating
29 * src and sink pads we create; otherwise we always have to do get_pad,
30 * get_peer, and then remove references in every test function */
31 static GstPad *mysrcpad, *mysinkpad;
34 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
38 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
44 setup_capssetter (void)
46 GstElement *capssetter;
48 GST_DEBUG ("setup_capssetter");
50 capssetter = gst_check_setup_element ("capssetter");
51 mysrcpad = gst_check_setup_src_pad (capssetter, &srctemplate);
52 mysinkpad = gst_check_setup_sink_pad (capssetter, &sinktemplate);
53 gst_pad_set_active (mysrcpad, TRUE);
54 gst_pad_set_active (mysinkpad, TRUE);
60 cleanup_capssetter (GstElement * capssetter)
62 GST_DEBUG ("cleanup_capssetter");
64 gst_check_drop_buffers ();
65 gst_pad_set_active (mysrcpad, FALSE);
66 gst_pad_set_active (mysinkpad, FALSE);
67 gst_check_teardown_src_pad (capssetter);
68 gst_check_teardown_sink_pad (capssetter);
69 gst_check_teardown_element (capssetter);
73 push_and_test (GstCaps * prop_caps, gboolean join, gboolean replace,
74 GstCaps * in_caps, GstCaps * out_caps)
76 GstElement *capssetter;
80 capssetter = setup_capssetter ();
81 fail_unless (gst_element_set_state (capssetter,
82 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
83 "could not set to playing");
85 g_object_set (capssetter, "join", join, NULL);
86 g_object_set (capssetter, "replace", replace, NULL);
87 g_object_set (capssetter, "caps", prop_caps, NULL);
88 gst_caps_unref (prop_caps);
90 buffer = gst_buffer_new_and_alloc (4);
91 ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
92 gst_buffer_fill (buffer, 0, "data", 4);
94 gst_check_setup_events (mysrcpad, capssetter, in_caps, GST_FORMAT_TIME);
95 gst_caps_unref (in_caps);
97 /* pushing gives away my reference ... */
98 fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK,
99 "Failed pushing buffer to capssetter");
101 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()) == TRUE);
103 /* ... but it should end up being collected on the global buffer list */
104 fail_unless (g_list_length (buffers) == 1);
105 buffer = g_list_first (buffers)->data;
106 ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
108 current_out = gst_pad_get_current_caps (mysinkpad);
109 fail_unless (gst_caps_is_equal (out_caps, current_out));
110 gst_caps_unref (current_out);
111 gst_caps_unref (out_caps);
114 cleanup_capssetter (capssetter);
118 #define SRC_HEIGHT 12
123 return gst_caps_new_simple ("video/x-foo", "width", G_TYPE_INT, SRC_WIDTH,
124 "height", G_TYPE_INT, SRC_HEIGHT, NULL);
127 /* don't try these caps mutations at home, folks */
129 GST_START_TEST (test_n_join_n_replace)
131 GstCaps *in_caps, *prop_caps, *out_caps;
133 in_caps = make_src_caps ();
134 prop_caps = gst_caps_new_simple ("video/x-bar",
135 "width", G_TYPE_INT, 2 * SRC_WIDTH, NULL);
136 out_caps = gst_caps_new_simple ("video/x-bar",
137 "width", G_TYPE_INT, 2 * SRC_WIDTH,
138 "height", G_TYPE_INT, SRC_HEIGHT, NULL);
139 push_and_test (prop_caps, FALSE, FALSE, in_caps, out_caps);
144 GST_START_TEST (test_n_join_replace)
146 GstCaps *in_caps, *prop_caps, *out_caps;
148 in_caps = make_src_caps ();
149 prop_caps = gst_caps_new_simple ("video/x-bar",
150 "width", G_TYPE_INT, 2 * SRC_WIDTH, NULL);
151 out_caps = gst_caps_copy (prop_caps);
152 push_and_test (prop_caps, FALSE, TRUE, in_caps, out_caps);
157 GST_START_TEST (test_join_n_replace_n_match)
159 GstCaps *in_caps, *prop_caps, *out_caps;
161 /* non joining caps */
162 in_caps = make_src_caps ();
163 prop_caps = gst_caps_new_simple ("video/x-bar",
164 "width", G_TYPE_INT, 2 * SRC_WIDTH, NULL);
165 out_caps = gst_caps_copy (in_caps);
166 push_and_test (prop_caps, TRUE, FALSE, in_caps, out_caps);
171 GST_START_TEST (test_join_n_replace_match)
173 GstCaps *in_caps, *prop_caps, *out_caps;
176 in_caps = make_src_caps ();
177 prop_caps = gst_caps_new_simple ("video/x-foo",
178 "width", G_TYPE_INT, 2 * SRC_WIDTH, NULL);
179 out_caps = gst_caps_new_simple ("video/x-foo",
180 "width", G_TYPE_INT, 2 * SRC_WIDTH,
181 "height", G_TYPE_INT, SRC_HEIGHT, NULL);
182 push_and_test (prop_caps, TRUE, FALSE, in_caps, out_caps);
187 GST_START_TEST (test_join_replace_n_match)
189 GstCaps *in_caps, *prop_caps, *out_caps;
191 /* non joining caps */
192 in_caps = make_src_caps ();
193 prop_caps = gst_caps_new_simple ("video/x-bar",
194 "width", G_TYPE_INT, 2 * SRC_WIDTH, NULL);
195 out_caps = gst_caps_copy (in_caps);
196 push_and_test (prop_caps, TRUE, TRUE, in_caps, out_caps);
201 GST_START_TEST (test_join_replace_match)
203 GstCaps *in_caps, *prop_caps, *out_caps;
206 in_caps = make_src_caps ();
207 prop_caps = gst_caps_new_simple ("video/x-foo",
208 "width", G_TYPE_INT, 2 * SRC_WIDTH, NULL);
209 out_caps = gst_caps_copy (prop_caps);
210 push_and_test (prop_caps, TRUE, TRUE, in_caps, out_caps);
216 capssetter_suite (void)
218 Suite *s = suite_create ("capssetter");
219 TCase *tc_chain = tcase_create ("general");
221 suite_add_tcase (s, tc_chain);
222 tcase_add_test (tc_chain, test_n_join_n_replace);
223 tcase_add_test (tc_chain, test_n_join_replace);
224 tcase_add_test (tc_chain, test_join_n_replace_n_match);
225 tcase_add_test (tc_chain, test_join_n_replace_match);
226 tcase_add_test (tc_chain, test_join_replace_n_match);
227 tcase_add_test (tc_chain, test_join_replace_match);
232 GST_CHECK_MAIN (capssetter);