tests: remove unused valgrind stuff
[platform/upstream/gstreamer.git] / tests / check / gst / gstmeta.c
1 /* GStreamer
2  *
3  * unit test for GstMeta
4  *
5  * Copyright (C) <2009> Wim Taymans <wim.taymans@gmail.com>
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., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
26
27 #include <gst/check/gstcheck.h>
28
29 /* test metadata for PTS/DTS and duration */
30 typedef struct
31 {
32   GstMeta meta;
33
34   GstClockTime pts;
35   GstClockTime dts;
36   GstClockTime duration;
37   GstClockTime clock_rate;
38 } GstMetaTest;
39
40 static GType gst_meta_test_api_get_type (void);
41 #define GST_META_TEST_API_TYPE (gst_meta_test_api_get_type())
42
43 static const GstMetaInfo *gst_meta_test_get_info (void);
44 #define GST_META_TEST_INFO (gst_meta_test_get_info())
45
46 #define GST_META_TEST_GET(buf) ((GstMetaTest *)gst_buffer_get_meta(buf,GST_META_TEST_API_TYPE))
47 #define GST_META_TEST_ADD(buf) ((GstMetaTest *)gst_buffer_add_meta(buf,GST_META_TEST_INFO,NULL))
48
49 #if 0
50 /* unused currently. This is a user function to fill the metadata with default
51  * values. We don't call this from the init function because the user is mostly
52  * likely going to override the values immediately after */
53 static void
54 gst_meta_test_init (GstMetaTest * meta)
55 {
56   meta->pts = GST_CLOCK_TIME_NONE;
57   meta->dts = GST_CLOCK_TIME_NONE;
58   meta->duration = GST_CLOCK_TIME_NONE;
59   meta->clock_rate = GST_SECOND;
60 }
61 #endif
62
63 static gboolean
64 test_init_func (GstMeta * meta, gpointer params, GstBuffer * buffer)
65 {
66   GST_DEBUG ("init called on buffer %p, meta %p", buffer, meta);
67   /* nothing to init really, the init function is mostly for allocating
68    * additional memory or doing special setup as part of adding the metadata to
69    * the buffer*/
70   return TRUE;
71 }
72
73 static void
74 test_free_func (GstMeta * meta, GstBuffer * buffer)
75 {
76   GST_DEBUG ("free called on buffer %p, meta %p", buffer, meta);
77   /* nothing to free really */
78 }
79
80 static gboolean
81 test_transform_func (GstBuffer * transbuf, GstMeta * meta,
82     GstBuffer * buffer, GQuark type, gpointer data)
83 {
84   GstMetaTest *test, *tmeta = (GstMetaTest *) meta;
85
86   GST_DEBUG ("transform %s called from buffer %p to %p, meta %p",
87       g_quark_to_string (type), buffer, transbuf, meta);
88
89   if (GST_META_TRANSFORM_IS_COPY (type)) {
90     GstMetaTransformCopy *copy_data = data;
91
92     test = GST_META_TEST_ADD (transbuf);
93
94     if (copy_data->offset == 0) {
95       /* same offset, copy timestamps */
96       test->pts = tmeta->pts;
97       test->dts = tmeta->dts;
98       if (!copy_data->region) {
99         fail_unless (gst_buffer_get_size (buffer) == copy_data->size);
100         /* same size, copy duration */
101         test->duration = tmeta->duration;
102       } else {
103         fail_unless (gst_buffer_get_size (buffer) > copy_data->size);
104         /* else clear */
105         test->duration = GST_CLOCK_TIME_NONE;
106       }
107     } else {
108       fail_unless (copy_data->region == TRUE);
109       test->pts = -1;
110       test->dts = -1;
111       test->duration = -1;
112     }
113     test->clock_rate = tmeta->clock_rate;
114   } else {
115     /* return FALSE, if transform type is not supported */
116     return FALSE;
117   }
118   return TRUE;
119 }
120
121 static GType
122 gst_meta_test_api_get_type (void)
123 {
124   static volatile GType type;
125   static const gchar *tags[] = { "timing", NULL };
126
127   if (g_once_init_enter (&type)) {
128     GType _type = gst_meta_api_type_register ("GstMetaTestAPI", tags);
129     g_once_init_leave (&type, _type);
130   }
131   return type;
132 }
133
134 static const GstMetaInfo *
135 gst_meta_test_get_info (void)
136 {
137   static const GstMetaInfo *meta_test_info = NULL;
138
139   if (g_once_init_enter (&meta_test_info)) {
140     const GstMetaInfo *mi = gst_meta_register (GST_META_TEST_API_TYPE,
141         "GstMetaTest",
142         sizeof (GstMetaTest),
143         test_init_func, test_free_func, test_transform_func);
144     g_once_init_leave (&meta_test_info, mi);
145   }
146   return meta_test_info;
147 }
148
149 GST_START_TEST (test_meta_test)
150 {
151   GstBuffer *buffer, *copy, *subbuf;
152   GstMetaTest *meta;
153   GstMapInfo info;
154
155   buffer = gst_buffer_new_and_alloc (4);
156   fail_if (buffer == NULL);
157
158   fail_unless (gst_buffer_map (buffer, &info, GST_MAP_WRITE));
159   fail_if (info.data == NULL);
160   memset (info.data, 0, 4);
161   gst_buffer_unmap (buffer, &info);
162
163   /* add some metadata */
164   meta = GST_META_TEST_ADD (buffer);
165   fail_if (meta == NULL);
166   /* fill some values */
167   meta->pts = 1000;
168   meta->dts = 2000;
169   meta->duration = 1000;
170   meta->clock_rate = 1000;
171
172   /* copy of the buffer */
173   copy = gst_buffer_copy (buffer);
174   /* get metadata of the buffer */
175   meta = GST_META_TEST_GET (copy);
176   fail_if (meta == NULL);
177   fail_if (meta->pts != 1000);
178   fail_if (meta->dts != 2000);
179   fail_if (meta->duration != 1000);
180   fail_if (meta->clock_rate != 1000);
181   gst_buffer_unref (copy);
182
183   /* make subbuffer */
184   subbuf = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 0, 1);
185   /* get metadata of the buffer */
186   meta = GST_META_TEST_GET (subbuf);
187   fail_if (meta == NULL);
188   fail_if (meta->pts != 1000);
189   fail_if (meta->dts != 2000);
190   fail_if (meta->duration != -1);
191   fail_if (meta->clock_rate != 1000);
192   gst_buffer_unref (subbuf);
193
194   /* make another subbuffer */
195   subbuf = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 1, 3);
196   /* get metadata of the buffer */
197   meta = GST_META_TEST_GET (subbuf);
198   fail_if (meta == NULL);
199   fail_if (meta->pts != -1);
200   fail_if (meta->dts != -1);
201   fail_if (meta->duration != -1);
202   fail_if (meta->clock_rate != 1000);
203   gst_buffer_unref (subbuf);
204
205   /* clean up */
206   gst_buffer_unref (buffer);
207 }
208
209 GST_END_TEST;
210
211 static gboolean
212 foreach_meta (GstBuffer * buffer, GstMeta ** meta, gpointer user_data)
213 {
214   /* try to remove */
215   *meta = NULL;
216   return TRUE;
217 }
218
219 GST_START_TEST (test_meta_locked)
220 {
221   GstBuffer *buffer;
222   GstMetaTest *meta;
223
224   buffer = gst_buffer_new_and_alloc (4);
225   fail_if (buffer == NULL);
226
227   /* add some metadata */
228   meta = GST_META_TEST_ADD (buffer);
229   fail_if (meta == NULL);
230   GST_META_FLAG_SET (meta, GST_META_FLAG_LOCKED);
231
232   ASSERT_CRITICAL (gst_buffer_remove_meta (buffer, (GstMeta *) meta));
233   ASSERT_CRITICAL (gst_buffer_foreach_meta (buffer, foreach_meta, NULL));
234
235   GST_META_FLAG_UNSET (meta, GST_META_FLAG_LOCKED);
236
237   gst_buffer_remove_meta (buffer, (GstMeta *) meta);
238
239   /* clean up */
240   gst_buffer_unref (buffer);
241 }
242
243 GST_END_TEST;
244
245 static Suite *
246 gst_buffermeta_suite (void)
247 {
248   Suite *s = suite_create ("GstMeta");
249   TCase *tc_chain = tcase_create ("general");
250
251   suite_add_tcase (s, tc_chain);
252   tcase_add_test (tc_chain, test_meta_test);
253   tcase_add_test (tc_chain, test_meta_locked);
254
255   return s;
256 }
257
258 GST_CHECK_MAIN (gst_buffermeta);