2 * Copyright (C) 2004 Benjamin Otte <otte@gnome.org>
4 * includes code based on glibc 2.2.3's crypt/md5.c,
5 * Copyright (C) 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
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., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
44 length_get_spec (const GstTestInfo * info, gboolean compare_value)
47 return g_param_spec_int64 ("expected-length", "expected length",
48 "expected length of stream", -1, G_MAXINT64, -1,
49 G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
51 return g_param_spec_int64 ("length", "length", "length of stream",
52 -1, G_MAXINT64, -1, G_PARAM_READABLE);
57 length_new (const GstTestInfo * info)
59 return g_new0 (LengthTest, 1);
63 length_add (gpointer test, GstBuffer * buffer)
67 t->value += gst_buffer_get_size (buffer);
71 length_finish (gpointer test, GValue * value)
75 if (g_value_get_int64 (value) == -1)
78 return t->value == g_value_get_int64 (value);
82 length_get_value (gpointer test, GValue * value)
86 g_value_set_int64 (value, t ? t->value : -1);
94 buffer_count_get_spec (const GstTestInfo * info, gboolean compare_value)
97 return g_param_spec_int64 ("expected-buffer-count", "expected buffer count",
98 "expected number of buffers in stream",
99 -1, G_MAXINT64, -1, G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
101 return g_param_spec_int64 ("buffer-count", "buffer count",
102 "number of buffers in stream", -1, G_MAXINT64, -1, G_PARAM_READABLE);
107 buffer_count_add (gpointer test, GstBuffer * buffer)
109 LengthTest *t = test;
115 *** TIMESTAMP / DURATION MATCHING ***
122 GstClockTime expected;
127 timedur_get_spec (const GstTestInfo * info, gboolean compare_value)
130 return g_param_spec_int64 ("allowed-timestamp-deviation",
131 "allowed timestamp deviation",
132 "allowed average difference in usec between timestamp of next buffer "
133 "and expected timestamp from analyzing last buffer",
134 -1, G_MAXINT64, -1, G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
136 return g_param_spec_int64 ("timestamp-deviation",
137 "timestamp deviation",
138 "average difference in usec between timestamp of next buffer "
139 "and expected timestamp from analyzing last buffer",
140 -1, G_MAXINT64, -1, G_PARAM_READABLE);
145 timedur_new (const GstTestInfo * info)
147 TimeDurTest *ret = g_new0 (TimeDurTest, 1);
149 ret->expected = GST_CLOCK_TIME_NONE;
155 timedur_add (gpointer test, GstBuffer * buffer)
157 TimeDurTest *t = test;
159 if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer) &&
160 GST_CLOCK_TIME_IS_VALID (t->expected)) {
162 ABS (GST_CLOCK_DIFF (t->expected, GST_BUFFER_TIMESTAMP (buffer)));
165 if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer) &&
166 GST_BUFFER_DURATION_IS_VALID (buffer)) {
167 t->expected = GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer);
169 t->expected = GST_CLOCK_TIME_NONE;
174 timedur_finish (gpointer test, GValue * value)
176 TimeDurTest *t = test;
178 if (g_value_get_int64 (value) == -1)
181 return (t->diff / MAX (1, t->count)) <= g_value_get_int64 (value);
185 timedur_get_value (gpointer test, GValue * value)
187 TimeDurTest *t = test;
189 g_value_set_int64 (value, t ? (t->diff / MAX (1, t->count)) : -1);
197 md5_get_spec (const GstTestInfo * info, gboolean compare_value)
200 return g_param_spec_string ("expected-md5", "expected md5",
201 "expected md5 of processing the whole data",
202 "---", G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
204 return g_param_spec_string ("md5", "md5",
205 "md5 of processing the whole data", "---", G_PARAM_READABLE);
210 md5_new (const GstTestInfo * info)
212 return g_checksum_new (G_CHECKSUM_MD5);
216 md5_add (gpointer checksum, GstBuffer * buffer)
220 gst_buffer_map (buffer, &map, GST_MAP_READ);
221 g_checksum_update (checksum, map.data, map.size);
222 gst_buffer_unmap (buffer, &map);
226 md5_finish (gpointer checksum, GValue * value)
228 const gchar *expected, *result;
230 expected = g_value_get_string (value);
231 result = g_checksum_get_string (checksum);
233 if (g_str_equal (expected, "---"))
235 if (g_str_equal (expected, result))
241 md5_get_value (gpointer checksum, GValue * value)
244 g_value_set_string (value, "---");
246 g_value_set_string (value, g_checksum_get_string (checksum));
251 md5_free (gpointer checksum)
253 g_checksum_free (checksum);
260 const GstTestInfo tests[] = {
261 {length_get_spec, length_new, length_add,
262 length_finish, length_get_value, g_free},
263 {buffer_count_get_spec, length_new, buffer_count_add,
264 length_finish, length_get_value, g_free},
265 {timedur_get_spec, timedur_new, timedur_add,
266 timedur_finish, timedur_get_value, g_free},
267 {md5_get_spec, md5_new, md5_add,
268 md5_finish, md5_get_value, md5_free}