3 * unit test for identity
5 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
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>
27 static gboolean have_eos = FALSE;
29 /* For ease of programming we use globals to keep refs for our floating
30 * src and sink pads we create; otherwise we always have to do get_pad,
31 * get_peer, and then remove references in every test function */
32 static GstPad *mysrcpad, *mysinkpad;
35 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
39 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
45 event_func (GstPad * pad, GstEvent * event)
47 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
49 gst_event_unref (event);
53 gst_event_unref (event);
62 GST_DEBUG ("setup_identity");
64 identity = gst_check_setup_element ("identity");
65 mysrcpad = gst_check_setup_src_pad (identity, &srctemplate, NULL);
66 mysinkpad = gst_check_setup_sink_pad (identity, &sinktemplate, NULL);
67 gst_pad_set_event_function (mysinkpad, event_func);
68 gst_pad_set_active (mysrcpad, TRUE);
69 gst_pad_set_active (mysinkpad, TRUE);
75 cleanup_identity (GstElement * identity)
77 GST_DEBUG ("cleanup_identity");
79 gst_pad_set_active (mysrcpad, FALSE);
80 gst_pad_set_active (mysinkpad, FALSE);
81 gst_check_teardown_src_pad (identity);
82 gst_check_teardown_sink_pad (identity);
83 gst_check_teardown_element (identity);
86 GST_START_TEST (test_one_buffer)
91 identity = setup_identity ();
92 fail_unless (gst_element_set_state (identity,
93 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
94 "could not set to playing");
96 buffer = gst_buffer_new_and_alloc (4);
97 ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
98 memcpy (GST_BUFFER_DATA (buffer), "data", 4);
100 /* pushing gives away my reference ... */
101 fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK,
102 "Failed pushing buffer to identity");
104 /* ... but it should end up being collected on the global buffer list */
105 fail_unless (g_list_length (buffers) == 1);
106 fail_unless ((GstBuffer *) (g_list_first (buffers)->data) == buffer);
107 ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
110 cleanup_identity (identity);
116 identity_suite (void)
118 Suite *s = suite_create ("identity");
119 TCase *tc_chain = tcase_create ("general");
121 suite_add_tcase (s, tc_chain);
122 tcase_add_test (tc_chain, test_one_buffer);
127 GST_CHECK_MAIN (identity);