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., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, 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, NULL);
52 mysinkpad = gst_check_setup_sink_pad (capssetter, &sinktemplate, NULL);
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_pad_set_active (mysrcpad, FALSE);
65 gst_pad_set_active (mysinkpad, FALSE);
66 gst_check_teardown_src_pad (capssetter);
67 gst_check_teardown_sink_pad (capssetter);
68 gst_check_teardown_element (capssetter);
72 push_and_test (GstCaps * prop_caps, gboolean join, gboolean replace,
73 GstCaps * in_caps, GstCaps * out_caps)
75 GstElement *capssetter;
78 capssetter = setup_capssetter ();
79 fail_unless (gst_element_set_state (capssetter,
80 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
81 "could not set to playing");
83 buffer = gst_buffer_new_and_alloc (4);
84 ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
85 memcpy (GST_BUFFER_DATA (buffer), "data", 4);
87 gst_buffer_set_caps (buffer, in_caps);
88 gst_caps_unref (in_caps);
90 g_object_set (capssetter, "join", join, NULL);
91 g_object_set (capssetter, "replace", replace, NULL);
92 g_object_set (capssetter, "caps", prop_caps, NULL);
93 gst_caps_unref (prop_caps);
95 /* pushing gives away my reference ... */
96 fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK,
97 "Failed pushing buffer to capssetter");
99 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()) == TRUE);
101 /* ... but it should end up being collected on the global buffer list */
102 fail_unless (g_list_length (buffers) == 1);
103 buffer = g_list_first (buffers)->data;
104 ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
106 fail_unless (gst_caps_is_equal (out_caps, GST_BUFFER_CAPS (buffer)));
107 gst_caps_unref (out_caps);
110 cleanup_capssetter (capssetter);
114 #define SRC_HEIGHT 12
119 return gst_caps_new_simple ("video/x-raw-yuv", "width", G_TYPE_INT, SRC_WIDTH,
120 "height", G_TYPE_INT, SRC_HEIGHT, NULL);
123 /* don't try these caps mutations at home, folks */
125 GST_START_TEST (test_n_join_n_replace)
127 GstCaps *in_caps, *prop_caps, *out_caps;
129 in_caps = make_src_caps ();
130 prop_caps = gst_caps_new_simple ("video/x-raw-rgb",
131 "width", G_TYPE_INT, 2 * SRC_WIDTH, NULL);
132 out_caps = gst_caps_new_simple ("video/x-raw-rgb",
133 "width", G_TYPE_INT, 2 * SRC_WIDTH,
134 "height", G_TYPE_INT, SRC_HEIGHT, NULL);
135 push_and_test (prop_caps, FALSE, FALSE, in_caps, out_caps);
140 GST_START_TEST (test_n_join_replace)
142 GstCaps *in_caps, *prop_caps, *out_caps;
144 in_caps = make_src_caps ();
145 prop_caps = gst_caps_new_simple ("video/x-raw-rgb",
146 "width", G_TYPE_INT, 2 * SRC_WIDTH, NULL);
147 out_caps = gst_caps_copy (prop_caps);
148 push_and_test (prop_caps, FALSE, TRUE, in_caps, out_caps);
153 GST_START_TEST (test_join_n_replace_n_match)
155 GstCaps *in_caps, *prop_caps, *out_caps;
157 /* non joining caps */
158 in_caps = make_src_caps ();
159 prop_caps = gst_caps_new_simple ("video/x-raw-rgb",
160 "width", G_TYPE_INT, 2 * SRC_WIDTH, NULL);
161 out_caps = gst_caps_copy (in_caps);
162 push_and_test (prop_caps, TRUE, FALSE, in_caps, out_caps);
167 GST_START_TEST (test_join_n_replace_match)
169 GstCaps *in_caps, *prop_caps, *out_caps;
172 in_caps = make_src_caps ();
173 prop_caps = gst_caps_new_simple ("video/x-raw-yuv",
174 "width", G_TYPE_INT, 2 * SRC_WIDTH, NULL);
175 out_caps = gst_caps_new_simple ("video/x-raw-yuv",
176 "width", G_TYPE_INT, 2 * SRC_WIDTH,
177 "height", G_TYPE_INT, SRC_HEIGHT, NULL);
178 push_and_test (prop_caps, TRUE, FALSE, in_caps, out_caps);
183 GST_START_TEST (test_join_replace_n_match)
185 GstCaps *in_caps, *prop_caps, *out_caps;
187 /* non joining caps */
188 in_caps = make_src_caps ();
189 prop_caps = gst_caps_new_simple ("video/x-raw-rgb",
190 "width", G_TYPE_INT, 2 * SRC_WIDTH, NULL);
191 out_caps = gst_caps_copy (in_caps);
192 push_and_test (prop_caps, TRUE, TRUE, in_caps, out_caps);
197 GST_START_TEST (test_join_replace_match)
199 GstCaps *in_caps, *prop_caps, *out_caps;
202 in_caps = make_src_caps ();
203 prop_caps = gst_caps_new_simple ("video/x-raw-yuv",
204 "width", G_TYPE_INT, 2 * SRC_WIDTH, NULL);
205 out_caps = gst_caps_copy (prop_caps);
206 push_and_test (prop_caps, TRUE, TRUE, in_caps, out_caps);
212 capssetter_suite (void)
214 Suite *s = suite_create ("capssetter");
215 TCase *tc_chain = tcase_create ("general");
217 suite_add_tcase (s, tc_chain);
218 tcase_add_test (tc_chain, test_n_join_n_replace);
219 tcase_add_test (tc_chain, test_n_join_replace);
220 tcase_add_test (tc_chain, test_join_n_replace_n_match);
221 tcase_add_test (tc_chain, test_join_n_replace_match);
222 tcase_add_test (tc_chain, test_join_replace_n_match);
223 tcase_add_test (tc_chain, test_join_replace_match);
228 GST_CHECK_MAIN (capssetter);