2 * Copyright (C) 2004 Benjamin Otte <otte@gnome.org>
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.
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.
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.
25 #include <gst/base/gstbasesink.h>
28 GST_DEBUG_CATEGORY_STATIC (gst_test_debug);
29 #define GST_CAT_DEFAULT gst_test_debug
31 /* This plugin does all the tests registered in the tests.h file
34 #define GST_TYPE_TEST \
36 #define GST_TEST(obj) \
37 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_TEST,GstTest))
38 #define GST_TEST_CLASS(klass) \
39 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_TEST,GstTestClass))
40 #define GST_TEST_GET_CLASS(obj) \
41 (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_TEST,GstTestClass))
42 #define GST_IS_TEST(obj) \
43 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_TEST))
44 #define GST_IS_TEST_CLASS(klass) \
45 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_TEST))
47 typedef struct _GstTest GstTest;
48 typedef struct _GstTestClass GstTestClass;
54 gpointer tests[TESTS_COUNT];
55 GValue values[TESTS_COUNT];
60 GstBaseSinkClass parent_class;
62 gchar *param_names[2 * TESTS_COUNT];
65 static void gst_test_finalize (GstTest * test);
67 static gboolean gst_test_start (GstBaseSink * trans);
68 static gboolean gst_test_stop (GstBaseSink * trans);
69 static gboolean gst_test_sink_event (GstBaseSink * basesink, GstEvent * event);
70 static GstFlowReturn gst_test_render_buffer (GstBaseSink * basesink,
73 static void gst_test_set_property (GObject * object, guint prop_id,
74 const GValue * value, GParamSpec * pspec);
75 static void gst_test_get_property (GObject * object, guint prop_id,
76 GValue * value, GParamSpec * pspec);
78 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
84 static const GstElementDetails details = GST_ELEMENT_DETAILS ("Test plugin",
86 "perform a number of tests",
87 "Benjamin Otte <otte@gnome>");
89 #define DEBUG_INIT(bla) \
90 GST_DEBUG_CATEGORY_INIT (gst_test_debug, "testsink", 0, \
91 "debugging category for testsink element");
93 GST_BOILERPLATE_FULL (GstTest, gst_test, GstBaseSink, GST_TYPE_BASE_SINK,
98 gst_test_base_init (gpointer g_class)
100 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
102 gst_element_class_add_pad_template (gstelement_class,
103 gst_static_pad_template_get (&sinktemplate));
105 gst_element_class_set_details (gstelement_class, &details);
109 gst_test_class_init (GstTestClass * klass)
111 GstBaseSinkClass *basesink_class = GST_BASE_SINK_CLASS (klass);
112 GObjectClass *object_class = G_OBJECT_CLASS (klass);
115 object_class->set_property = GST_DEBUG_FUNCPTR (gst_test_set_property);
116 object_class->get_property = GST_DEBUG_FUNCPTR (gst_test_get_property);
118 object_class->finalize = (GObjectFinalizeFunc) gst_test_finalize;
120 for (i = 0; i < TESTS_COUNT; i++) {
123 spec = tests[i].get_spec (&tests[i], FALSE);
124 klass->param_names[2 * i] = g_strdup (g_param_spec_get_name (spec));
125 g_object_class_install_property (object_class, 2 * i + 1, spec);
126 spec = tests[i].get_spec (&tests[i], TRUE);
127 klass->param_names[2 * i + 1] = g_strdup (g_param_spec_get_name (spec));
128 g_object_class_install_property (object_class, 2 * i + 2, spec);
131 basesink_class->preroll = GST_DEBUG_FUNCPTR (gst_test_render_buffer);
132 basesink_class->render = GST_DEBUG_FUNCPTR (gst_test_render_buffer);
133 basesink_class->event = GST_DEBUG_FUNCPTR (gst_test_sink_event);
134 basesink_class->start = GST_DEBUG_FUNCPTR (gst_test_start);
135 basesink_class->stop = GST_DEBUG_FUNCPTR (gst_test_stop);
139 gst_test_init (GstTest * test, GstTestClass * g_class)
144 klass = GST_TEST_GET_CLASS (test);
145 for (i = 0; i < TESTS_COUNT; i++) {
146 GParamSpec *spec = g_object_class_find_property (G_OBJECT_CLASS (klass),
147 klass->param_names[2 * i + 1]);
149 g_value_init (&test->values[i], G_PARAM_SPEC_VALUE_TYPE (spec));
154 gst_test_finalize (GstTest * test)
158 for (i = 0; i < TESTS_COUNT; i++) {
159 g_value_unset (&test->values[i]);
162 G_OBJECT_CLASS (parent_class)->finalize ((GObject *) test);
166 tests_unset (GstTest * test)
170 for (i = 0; i < TESTS_COUNT; i++) {
171 if (test->tests[i]) {
172 tests[i].free (test->tests[i]);
173 test->tests[i] = NULL;
179 tests_set (GstTest * test)
183 for (i = 0; i < TESTS_COUNT; i++) {
184 g_assert (test->tests[i] == NULL);
185 test->tests[i] = tests[i].new (&tests[i]);
190 gst_test_sink_event (GstBaseSink * basesink, GstEvent * event)
192 GstTestClass *klass = GST_TEST_GET_CLASS (basesink);
193 GstTest *test = GST_TEST (basesink);
194 gboolean ret = FALSE;
196 switch (GST_EVENT_TYPE (event)) {
198 case GST_EVENT_NEWSEGMENT:
199 if (GST_EVENT_DISCONT_NEW_MEDIA (event)) {
208 g_object_freeze_notify (G_OBJECT (test));
209 for (i = 0; i < TESTS_COUNT; i++) {
210 if (test->tests[i]) {
211 if (!tests[i].finish (test->tests[i], &test->values[i])) {
213 gchar *real, *expected;
215 expected = gst_value_serialize (&test->values[i]);
216 g_value_init (&v, G_VALUE_TYPE (&test->values[i]));
217 g_object_get_property (G_OBJECT (test), klass->param_names[2 * i],
219 real = gst_value_serialize (&v);
221 GST_ELEMENT_ERROR (test, STREAM, FORMAT, (NULL),
222 ("test %s returned value \"%s\" and not expected value \"%s\"",
223 klass->param_names[2 * i], real, expected));
227 g_object_notify (G_OBJECT (test), klass->param_names[2 * i]);
230 g_object_thaw_notify (G_OBJECT (test));
242 gst_test_render_buffer (GstBaseSink * basesink, GstBuffer * buf)
244 GstTest *test = GST_TEST (basesink);
247 for (i = 0; i < TESTS_COUNT; i++) {
248 if (test->tests[i]) {
249 tests[i].add (test->tests[i], buf);
256 gst_test_start (GstBaseSink * sink)
258 GstTest *test = GST_TEST (sink);
265 gst_test_stop (GstBaseSink * sink)
267 GstTest *test = GST_TEST (sink);
274 gst_test_set_property (GObject * object, guint prop_id,
275 const GValue * value, GParamSpec * pspec)
277 GstTest *test = GST_TEST (object);
279 if (prop_id == 0 || prop_id > 2 * TESTS_COUNT) {
280 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
285 /* real values can't be set */
286 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
288 /* expected values */
289 GST_OBJECT_LOCK (test);
290 g_value_copy (value, &test->values[prop_id / 2 - 1]);
291 GST_OBJECT_UNLOCK (test);
296 gst_test_get_property (GObject * object, guint prop_id, GValue * value,
299 GstTest *test = GST_TEST (object);
300 guint id = (prop_id - 1) / 2;
302 if (prop_id == 0 || prop_id > 2 * TESTS_COUNT) {
303 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
307 GST_OBJECT_LOCK (test);
311 tests[id].get_value (test->tests[id], value);
313 /* expected values */
314 g_value_copy (&test->values[id], value);
317 GST_OBJECT_UNLOCK (test);