Initialize Tizen 2.3
[framework/multimedia/gstreamer0.10.git] / mobile / tests / check / elements / identity.c
1 /* GStreamer
2  *
3  * unit test for identity
4  *
5  * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #include <unistd.h>
24
25 #include <gst/check/gstcheck.h>
26
27 static gboolean have_eos = FALSE;
28
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;
33
34
35 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
36     GST_PAD_SINK,
37     GST_PAD_ALWAYS,
38     GST_STATIC_CAPS_ANY);
39 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
40     GST_PAD_SRC,
41     GST_PAD_ALWAYS,
42     GST_STATIC_CAPS_ANY);
43
44 static gboolean
45 event_func (GstPad * pad, GstEvent * event)
46 {
47   if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
48     have_eos = TRUE;
49     gst_event_unref (event);
50     return TRUE;
51   }
52
53   gst_event_unref (event);
54   return FALSE;
55 }
56
57 static GstElement *
58 setup_identity (void)
59 {
60   GstElement *identity;
61
62   GST_DEBUG ("setup_identity");
63
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);
70
71   return identity;
72 }
73
74 static void
75 cleanup_identity (GstElement * identity)
76 {
77   GST_DEBUG ("cleanup_identity");
78
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);
84 }
85
86 GST_START_TEST (test_one_buffer)
87 {
88   GstElement *identity;
89   GstBuffer *buffer;
90
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");
95
96   buffer = gst_buffer_new_and_alloc (4);
97   ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
98   memcpy (GST_BUFFER_DATA (buffer), "data", 4);
99
100   /* pushing gives away my reference ... */
101   fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK,
102       "Failed pushing buffer to identity");
103
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);
108
109   /* cleanup */
110   cleanup_identity (identity);
111 }
112
113 GST_END_TEST;
114
115 static Suite *
116 identity_suite (void)
117 {
118   Suite *s = suite_create ("identity");
119   TCase *tc_chain = tcase_create ("general");
120
121   suite_add_tcase (s, tc_chain);
122   tcase_add_test (tc_chain, test_one_buffer);
123
124   return s;
125 }
126
127 GST_CHECK_MAIN (identity);