2 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
3 * Copyright (C) <2006> Tim-Philipp Müller <tim centricular net>
5 * gstutils.c: Unit test for functions in gstutils
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.
27 #include <gst/check/gstcheck.h>
29 #define SPECIAL_POINTER(x) ((void*)(19283847+(x)))
31 static int n_data_probes = 0;
32 static int n_buffer_probes = 0;
33 static int n_event_probes = 0;
35 static GstPadProbeReturn
36 probe_do_nothing (GstPad * pad, GstPadProbeInfo * info, gpointer data)
38 GstMiniObject *obj = GST_PAD_PROBE_INFO_DATA (info);
39 GST_DEBUG_OBJECT (pad, "is buffer:%d", GST_IS_BUFFER (obj));
40 return GST_PAD_PROBE_OK;
43 static GstPadProbeReturn
44 data_probe (GstPad * pad, GstPadProbeInfo * info, gpointer data)
46 GstMiniObject *obj = GST_PAD_PROBE_INFO_DATA (info);
48 GST_DEBUG_OBJECT (pad, "data probe %d", n_data_probes);
49 g_assert (GST_IS_BUFFER (obj) || GST_IS_EVENT (obj));
50 g_assert (data == SPECIAL_POINTER (0));
51 return GST_PAD_PROBE_OK;
54 static GstPadProbeReturn
55 buffer_probe (GstPad * pad, GstPadProbeInfo * info, gpointer data)
57 GstBuffer *obj = GST_PAD_PROBE_INFO_BUFFER (info);
59 GST_DEBUG_OBJECT (pad, "buffer probe %d", n_buffer_probes);
60 g_assert (GST_IS_BUFFER (obj));
61 g_assert (data == SPECIAL_POINTER (1));
62 return GST_PAD_PROBE_OK;
65 static GstPadProbeReturn
66 event_probe (GstPad * pad, GstPadProbeInfo * info, gpointer data)
68 GstEvent *obj = GST_PAD_PROBE_INFO_EVENT (info);
70 GST_DEBUG_OBJECT (pad, "event probe %d [%s]",
71 n_event_probes, GST_EVENT_TYPE_NAME (obj));
72 g_assert (GST_IS_EVENT (obj));
73 g_assert (data == SPECIAL_POINTER (2));
74 return GST_PAD_PROBE_OK;
77 GST_START_TEST (test_buffer_probe_n_times)
79 GstElement *pipeline, *fakesrc, *fakesink;
84 pipeline = gst_element_factory_make ("pipeline", NULL);
85 fakesrc = gst_element_factory_make ("fakesrc", NULL);
86 fakesink = gst_element_factory_make ("fakesink", NULL);
88 g_object_set (fakesrc, "num-buffers", (int) 10, NULL);
90 gst_bin_add_many (GST_BIN (pipeline), fakesrc, fakesink, NULL);
91 gst_element_link (fakesrc, fakesink);
93 pad = gst_element_get_static_pad (fakesink, "sink");
95 /* add the probes we need for the test */
96 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_DATA_BOTH, data_probe,
97 SPECIAL_POINTER (0), NULL);
98 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER, buffer_probe,
99 SPECIAL_POINTER (1), NULL);
100 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_EVENT_BOTH, event_probe,
101 SPECIAL_POINTER (2), NULL);
103 /* add some string probes just to test that the data is free'd
104 * properly as it should be */
105 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_DATA_BOTH, probe_do_nothing,
106 g_strdup ("data probe string"), (GDestroyNotify) g_free);
107 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER, probe_do_nothing,
108 g_strdup ("buffer probe string"), (GDestroyNotify) g_free);
109 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_EVENT_BOTH, probe_do_nothing,
110 g_strdup ("event probe string"), (GDestroyNotify) g_free);
112 gst_object_unref (pad);
114 gst_element_set_state (pipeline, GST_STATE_PLAYING);
116 bus = gst_element_get_bus (pipeline);
117 message = gst_bus_poll (bus, GST_MESSAGE_EOS, -1);
118 gst_message_unref (message);
119 gst_object_unref (bus);
121 g_assert (n_buffer_probes == 10); /* one for every buffer */
122 g_assert (n_event_probes == 4); /* stream-start, new segment, latency and eos */
123 g_assert (n_data_probes == 14); /* duh */
125 gst_element_set_state (pipeline, GST_STATE_NULL);
126 gst_object_unref (pipeline);
128 /* make sure nothing was sent in addition to the above when shutting down */
129 g_assert (n_buffer_probes == 10); /* one for every buffer */
130 g_assert (n_event_probes == 4); /* stream-start, new segment, latency and eos */
131 g_assert (n_data_probes == 14); /* duh */
134 static int n_data_probes_once = 0;
135 static int n_buffer_probes_once = 0;
136 static int n_event_probes_once = 0;
138 static GstPadProbeReturn
139 data_probe_once (GstPad * pad, GstPadProbeInfo * info, guint * data)
141 GstMiniObject *obj = GST_PAD_PROBE_INFO_DATA (info);
143 n_data_probes_once++;
144 g_assert (GST_IS_BUFFER (obj) || GST_IS_EVENT (obj));
146 gst_pad_remove_probe (pad, *data);
148 return GST_PAD_PROBE_OK;
151 static GstPadProbeReturn
152 buffer_probe_once (GstPad * pad, GstPadProbeInfo * info, guint * data)
154 GstBuffer *obj = GST_PAD_PROBE_INFO_BUFFER (info);
156 n_buffer_probes_once++;
157 g_assert (GST_IS_BUFFER (obj));
159 gst_pad_remove_probe (pad, *data);
161 return GST_PAD_PROBE_OK;
164 static GstPadProbeReturn
165 event_probe_once (GstPad * pad, GstPadProbeInfo * info, guint * data)
167 GstEvent *obj = GST_PAD_PROBE_INFO_EVENT (info);
169 n_event_probes_once++;
170 g_assert (GST_IS_EVENT (obj));
172 gst_pad_remove_probe (pad, *data);
174 return GST_PAD_PROBE_OK;
177 GST_START_TEST (test_buffer_probe_once)
179 GstElement *pipeline, *fakesrc, *fakesink;
185 pipeline = gst_element_factory_make ("pipeline", NULL);
186 fakesrc = gst_element_factory_make ("fakesrc", NULL);
187 fakesink = gst_element_factory_make ("fakesink", NULL);
189 g_object_set (fakesrc, "num-buffers", (int) 10, NULL);
191 gst_bin_add_many (GST_BIN (pipeline), fakesrc, fakesink, NULL);
192 gst_element_link (fakesrc, fakesink);
194 pad = gst_element_get_static_pad (fakesink, "sink");
196 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_DATA_BOTH,
197 (GstPadProbeCallback) data_probe_once, &id1, NULL);
199 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER,
200 (GstPadProbeCallback) buffer_probe_once, &id2, NULL);
202 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_EVENT_BOTH,
203 (GstPadProbeCallback) event_probe_once, &id3, NULL);
204 gst_object_unref (pad);
206 gst_element_set_state (pipeline, GST_STATE_PLAYING);
208 bus = gst_element_get_bus (pipeline);
209 message = gst_bus_poll (bus, GST_MESSAGE_EOS, -1);
210 gst_message_unref (message);
211 gst_object_unref (bus);
213 gst_element_set_state (pipeline, GST_STATE_NULL);
214 gst_object_unref (pipeline);
216 g_assert (n_buffer_probes_once == 1); /* can we hit it and quit? */
217 g_assert (n_event_probes_once == 1); /* i said, can we hit it and quit? */
218 g_assert (n_data_probes_once == 1); /* let's hit it and quit!!! */
221 GST_START_TEST (test_math_scale)
223 fail_if (gst_util_uint64_scale_int (1, 1, 1) != 1);
225 fail_if (gst_util_uint64_scale_int (10, 10, 1) != 100);
226 fail_if (gst_util_uint64_scale_int (10, 10, 2) != 50);
228 fail_if (gst_util_uint64_scale_int (0, 10, 2) != 0);
229 fail_if (gst_util_uint64_scale_int (0, 0, 2) != 0);
231 fail_if (gst_util_uint64_scale_int (G_MAXUINT32, 5, 1) != G_MAXUINT32 * 5LL);
232 fail_if (gst_util_uint64_scale_int (G_MAXUINT32, 10, 2) != G_MAXUINT32 * 5LL);
234 fail_if (gst_util_uint64_scale_int (G_MAXUINT32, 1, 5) != G_MAXUINT32 / 5LL);
235 fail_if (gst_util_uint64_scale_int (G_MAXUINT32, 2, 10) != G_MAXUINT32 / 5LL);
237 /* not quite overflow */
238 fail_if (gst_util_uint64_scale_int (G_MAXUINT64 - 1, 10,
239 10) != G_MAXUINT64 - 1);
240 fail_if (gst_util_uint64_scale_int (G_MAXUINT64 - 1, G_MAXINT32,
241 G_MAXINT32) != G_MAXUINT64 - 1);
242 fail_if (gst_util_uint64_scale_int (G_MAXUINT64 - 100, G_MAXINT32,
243 G_MAXINT32) != G_MAXUINT64 - 100);
246 fail_if (gst_util_uint64_scale_int (G_MAXUINT64 - 1, 10, 1) != G_MAXUINT64);
247 fail_if (gst_util_uint64_scale_int (G_MAXUINT64 - 1, G_MAXINT32,
252 GST_START_TEST (test_math_scale_round)
254 fail_if (gst_util_uint64_scale_int_round (2, 1, 2) != 1);
255 fail_if (gst_util_uint64_scale_int_round (3, 1, 2) != 2);
256 fail_if (gst_util_uint64_scale_int_round (4, 1, 2) != 2);
258 fail_if (gst_util_uint64_scale_int_round (200, 100, 20000) != 1);
259 fail_if (gst_util_uint64_scale_int_round (299, 100, 20000) != 1);
260 fail_if (gst_util_uint64_scale_int_round (300, 100, 20000) != 2);
261 fail_if (gst_util_uint64_scale_int_round (301, 100, 20000) != 2);
262 fail_if (gst_util_uint64_scale_int_round (400, 100, 20000) != 2);
265 GST_START_TEST (test_math_scale_ceil)
267 fail_if (gst_util_uint64_scale_int_ceil (2, 1, 2) != 1);
268 fail_if (gst_util_uint64_scale_int_ceil (3, 1, 2) != 2);
269 fail_if (gst_util_uint64_scale_int_ceil (4, 1, 2) != 2);
271 fail_if (gst_util_uint64_scale_int_ceil (200, 100, 20000) != 1);
272 fail_if (gst_util_uint64_scale_int_ceil (299, 100, 20000) != 2);
273 fail_if (gst_util_uint64_scale_int_ceil (300, 100, 20000) != 2);
274 fail_if (gst_util_uint64_scale_int_ceil (301, 100, 20000) != 2);
275 fail_if (gst_util_uint64_scale_int_ceil (400, 100, 20000) != 2);
278 GST_START_TEST (test_math_scale_uint64)
280 fail_if (gst_util_uint64_scale (1, 1, 1) != 1);
282 fail_if (gst_util_uint64_scale (10, 10, 1) != 100);
283 fail_if (gst_util_uint64_scale (10, 10, 2) != 50);
285 fail_if (gst_util_uint64_scale (0, 10, 2) != 0);
286 fail_if (gst_util_uint64_scale (0, 0, 2) != 0);
288 fail_if (gst_util_uint64_scale (G_MAXUINT32, 5, 1) != G_MAXUINT32 * 5LL);
289 fail_if (gst_util_uint64_scale (G_MAXUINT32, 10, 2) != G_MAXUINT32 * 5LL);
291 fail_if (gst_util_uint64_scale (G_MAXUINT32, 1, 5) != G_MAXUINT32 / 5LL);
292 fail_if (gst_util_uint64_scale (G_MAXUINT32, 2, 10) != G_MAXUINT32 / 5LL);
294 /* not quite overflow */
295 fail_if (gst_util_uint64_scale (G_MAXUINT64 - 1, 10, 10) != G_MAXUINT64 - 1);
296 fail_if (gst_util_uint64_scale (G_MAXUINT64 - 1, G_MAXUINT32,
297 G_MAXUINT32) != G_MAXUINT64 - 1);
298 fail_if (gst_util_uint64_scale (G_MAXUINT64 - 100, G_MAXUINT32,
299 G_MAXUINT32) != G_MAXUINT64 - 100);
301 fail_if (gst_util_uint64_scale (G_MAXUINT64 - 1, 10, 10) != G_MAXUINT64 - 1);
302 fail_if (gst_util_uint64_scale (G_MAXUINT64 - 1, G_MAXUINT64,
303 G_MAXUINT64) != G_MAXUINT64 - 1);
304 fail_if (gst_util_uint64_scale (G_MAXUINT64 - 100, G_MAXUINT64,
305 G_MAXUINT64) != G_MAXUINT64 - 100);
308 fail_if (gst_util_uint64_scale (G_MAXUINT64 - 1, 10, 1) != G_MAXUINT64);
309 fail_if (gst_util_uint64_scale (G_MAXUINT64 - 1, G_MAXUINT64,
314 GST_START_TEST (test_math_scale_random)
316 guint64 val, num, denom, res;
320 rand = g_rand_new ();
326 val = ((guint64) g_rand_int (rand)) << 32 | g_rand_int (rand);
327 num = ((guint64) g_rand_int (rand)) << 32 | g_rand_int (rand);
328 denom = ((guint64) g_rand_int (rand)) << 32 | g_rand_int (rand);
330 res = gst_util_uint64_scale (val, num, denom);
331 check = gst_gdouble_to_guint64 (gst_guint64_to_gdouble (val) *
332 gst_guint64_to_gdouble (num) / gst_guint64_to_gdouble (denom));
334 if (res < G_MAXUINT64 && check < G_MAXUINT64) {
340 /* some arbitrary value, really.. someone do the proper math to get
343 fail_if (diff > 20000);
352 GST_START_TEST (test_guint64_to_gdouble)
354 guint64 from[] = { 0, 1, 100, 10000, (guint64) (1) << 63,
355 ((guint64) (1) << 63) + 1,
356 ((guint64) (1) << 63) + (G_GINT64_CONSTANT (1) << 62)
358 gdouble to[] = { 0., 1., 100., 10000., 9223372036854775808.,
359 9223372036854775809., 13835058055282163712.
361 gdouble tolerance[] = { 0., 0., 0., 0., 0., 1., 1. };
366 for (i = 0; i < G_N_ELEMENTS (from); ++i) {
367 result = gst_util_guint64_to_gdouble (from[i]);
368 delta = ABS (to[i] - result);
369 fail_unless (delta <= tolerance[i],
370 "Could not convert %d: %" G_GUINT64_FORMAT
371 " -> %f, got %f instead, delta of %e with tolerance of %e",
372 i, from[i], to[i], result, delta, tolerance[i]);
378 GST_START_TEST (test_gdouble_to_guint64)
380 gdouble from[] = { 0., 1., 100., 10000., 9223372036854775808.,
381 9223372036854775809., 13835058055282163712.
383 guint64 to[] = { 0, 1, 100, 10000, (guint64) (1) << 63,
384 ((guint64) (1) << 63) + 1,
385 ((guint64) (1) << 63) + (G_GINT64_CONSTANT (1) << 62)
387 guint64 tolerance[] = { 0, 0, 0, 0, 0, 1, 1 };
392 for (i = 0; i < G_N_ELEMENTS (from); ++i) {
393 result = gst_util_gdouble_to_guint64 (from[i]);
394 delta = ABS (to[i] - result);
395 fail_unless (delta <= tolerance[i],
396 "Could not convert %f: %" G_GUINT64_FORMAT
397 " -> %d, got %d instead, delta of %e with tolerance of %e",
398 i, from[i], to[i], result, delta, tolerance[i]);
404 #ifndef GST_DISABLE_PARSE
405 GST_START_TEST (test_parse_bin_from_description)
409 const gchar *bin_desc;
410 const gchar *pad_names;
413 "identity", "identity0/sink,identity0/src"}, {
414 "identity ! identity ! identity", "identity1/sink,identity3/src"}, {
415 "identity ! fakesink", "identity4/sink"}, {
416 "fakesrc ! identity", "identity5/src"}, {
417 "fakesrc ! fakesink", ""}
421 for (i = 0; i < G_N_ELEMENTS (bin_tests); ++i) {
422 GstElement *bin, *parent;
424 GstPad *ghost_pad, *target_pad;
427 bin = gst_parse_bin_from_description (bin_tests[i].bin_desc, TRUE, &err);
429 g_error ("ERROR in gst_parse_bin_from_description (%s): %s",
430 bin_tests[i].bin_desc, err->message);
432 g_assert (bin != NULL);
434 s = g_string_new ("");
435 if ((ghost_pad = gst_element_get_static_pad (bin, "sink"))) {
436 g_assert (GST_IS_GHOST_PAD (ghost_pad));
438 target_pad = gst_ghost_pad_get_target (GST_GHOST_PAD (ghost_pad));
439 g_assert (target_pad != NULL);
440 g_assert (GST_IS_PAD (target_pad));
442 parent = gst_pad_get_parent_element (target_pad);
443 g_assert (parent != NULL);
445 g_string_append_printf (s, "%s/sink", GST_ELEMENT_NAME (parent));
447 gst_object_unref (parent);
448 gst_object_unref (target_pad);
449 gst_object_unref (ghost_pad);
452 if ((ghost_pad = gst_element_get_static_pad (bin, "src"))) {
453 g_assert (GST_IS_GHOST_PAD (ghost_pad));
455 target_pad = gst_ghost_pad_get_target (GST_GHOST_PAD (ghost_pad));
456 g_assert (target_pad != NULL);
457 g_assert (GST_IS_PAD (target_pad));
459 parent = gst_pad_get_parent_element (target_pad);
460 g_assert (parent != NULL);
463 g_string_append (s, ",");
466 g_string_append_printf (s, "%s/src", GST_ELEMENT_NAME (parent));
468 gst_object_unref (parent);
469 gst_object_unref (target_pad);
470 gst_object_unref (ghost_pad);
473 if (strcmp (s->str, bin_tests[i].pad_names) != 0) {
474 g_error ("FAILED: expected '%s', got '%s' for bin '%s'",
475 bin_tests[i].pad_names, s->str, bin_tests[i].bin_desc);
477 g_string_free (s, TRUE);
479 gst_object_unref (bin);
486 GST_START_TEST (test_element_found_tags)
488 GstElement *pipeline, *fakesrc, *fakesink;
494 pipeline = gst_element_factory_make ("pipeline", NULL);
495 fakesrc = gst_element_factory_make ("fakesrc", NULL);
496 fakesink = gst_element_factory_make ("fakesink", NULL);
497 list = gst_tag_list_new_empty ();
499 g_object_set (fakesrc, "num-buffers", (int) 10, NULL);
501 gst_bin_add_many (GST_BIN (pipeline), fakesrc, fakesink, NULL);
502 gst_element_link (fakesrc, fakesink);
504 gst_element_set_state (pipeline, GST_STATE_PLAYING);
506 srcpad = gst_element_get_static_pad (fakesrc, "src");
507 gst_pad_push_event (srcpad, gst_event_new_tag (list));
508 gst_object_unref (srcpad);
510 bus = gst_element_get_bus (pipeline);
511 message = gst_bus_poll (bus, GST_MESSAGE_EOS, -1);
512 gst_message_unref (message);
513 gst_object_unref (bus);
515 /* FIXME: maybe also check if the fakesink receives the message */
517 gst_element_set_state (pipeline, GST_STATE_NULL);
518 gst_object_unref (pipeline);
523 GST_START_TEST (test_element_unlink)
525 GstElement *src, *sink;
527 src = gst_element_factory_make ("fakesrc", NULL);
528 sink = gst_element_factory_make ("fakesink", NULL);
529 fail_unless (gst_element_link (src, sink) != FALSE);
530 gst_element_unlink (src, sink);
531 gst_object_unref (src);
532 gst_object_unref (sink);
537 GST_START_TEST (test_set_value_from_string)
541 /* g_return_if_fail */
542 ASSERT_CRITICAL (gst_util_set_value_from_string (NULL, "xyz"));
544 g_value_init (&val, G_TYPE_STRING);
545 ASSERT_CRITICAL (gst_util_set_value_from_string (&val, NULL));
546 g_value_unset (&val);
548 /* string => string */
549 g_value_init (&val, G_TYPE_STRING);
550 gst_util_set_value_from_string (&val, "Y00");
551 fail_unless (g_value_get_string (&val) != NULL);
552 fail_unless_equals_string (g_value_get_string (&val), "Y00");
553 g_value_unset (&val);
556 g_value_init (&val, G_TYPE_INT);
557 gst_util_set_value_from_string (&val, "987654321");
558 fail_unless (g_value_get_int (&val) == 987654321);
559 g_value_unset (&val);
561 g_value_init (&val, G_TYPE_INT);
562 ASSERT_CRITICAL (gst_util_set_value_from_string (&val, "xyz"));
563 g_value_unset (&val);
566 g_value_init (&val, G_TYPE_UINT);
567 gst_util_set_value_from_string (&val, "987654321");
568 fail_unless (g_value_get_uint (&val) == 987654321);
569 g_value_unset (&val);
571 /* CHECKME: is this really desired behaviour? (tpm) */
572 g_value_init (&val, G_TYPE_UINT);
573 gst_util_set_value_from_string (&val, "-999");
574 fail_unless (g_value_get_uint (&val) == ((guint) 0 - (guint) 999));
575 g_value_unset (&val);
577 g_value_init (&val, G_TYPE_UINT);
578 ASSERT_CRITICAL (gst_util_set_value_from_string (&val, "xyz"));
579 g_value_unset (&val);
582 g_value_init (&val, G_TYPE_LONG);
583 gst_util_set_value_from_string (&val, "987654321");
584 fail_unless (g_value_get_long (&val) == 987654321);
585 g_value_unset (&val);
587 g_value_init (&val, G_TYPE_LONG);
588 ASSERT_CRITICAL (gst_util_set_value_from_string (&val, "xyz"));
589 g_value_unset (&val);
591 /* string => ulong */
592 g_value_init (&val, G_TYPE_ULONG);
593 gst_util_set_value_from_string (&val, "987654321");
594 fail_unless (g_value_get_ulong (&val) == 987654321);
595 g_value_unset (&val);
597 /* CHECKME: is this really desired behaviour? (tpm) */
598 g_value_init (&val, G_TYPE_ULONG);
599 gst_util_set_value_from_string (&val, "-999");
600 fail_unless (g_value_get_ulong (&val) == ((gulong) 0 - (gulong) 999));
601 g_value_unset (&val);
603 g_value_init (&val, G_TYPE_ULONG);
604 ASSERT_CRITICAL (gst_util_set_value_from_string (&val, "xyz"));
605 g_value_unset (&val);
607 /* string => boolean */
608 g_value_init (&val, G_TYPE_BOOLEAN);
609 gst_util_set_value_from_string (&val, "true");
610 fail_unless_equals_int (g_value_get_boolean (&val), TRUE);
611 g_value_unset (&val);
613 g_value_init (&val, G_TYPE_BOOLEAN);
614 gst_util_set_value_from_string (&val, "TRUE");
615 fail_unless_equals_int (g_value_get_boolean (&val), TRUE);
616 g_value_unset (&val);
618 g_value_init (&val, G_TYPE_BOOLEAN);
619 gst_util_set_value_from_string (&val, "false");
620 fail_unless_equals_int (g_value_get_boolean (&val), FALSE);
621 g_value_unset (&val);
623 g_value_init (&val, G_TYPE_BOOLEAN);
624 gst_util_set_value_from_string (&val, "FALSE");
625 fail_unless_equals_int (g_value_get_boolean (&val), FALSE);
626 g_value_unset (&val);
628 g_value_init (&val, G_TYPE_BOOLEAN);
629 gst_util_set_value_from_string (&val, "bleh");
630 fail_unless_equals_int (g_value_get_boolean (&val), FALSE);
631 g_value_unset (&val);
634 /* string => float (yay, localisation issues involved) */
635 g_value_init (&val, G_TYPE_FLOAT);
636 gst_util_set_value_from_string (&val, "987.654");
637 fail_unless (g_value_get_float (&val) >= 987.653 &&
638 g_value_get_float (&val) <= 987.655);
639 g_value_unset (&val);
641 g_value_init (&val, G_TYPE_FLOAT);
642 gst_util_set_value_from_string (&val, "987,654");
643 fail_unless (g_value_get_float (&val) >= 987.653 &&
644 g_value_get_float (&val) <= 987.655);
645 g_value_unset (&val);
647 /* string => double (yay, localisation issues involved) */
648 g_value_init (&val, G_TYPE_DOUBLE);
649 gst_util_set_value_from_string (&val, "987.654");
650 fail_unless (g_value_get_double (&val) >= 987.653 &&
651 g_value_get_double (&val) <= 987.655);
652 g_value_unset (&val);
654 g_value_init (&val, G_TYPE_DOUBLE);
655 gst_util_set_value_from_string (&val, "987,654");
656 fail_unless (g_value_get_double (&val) >= 987.653 &&
657 g_value_get_double (&val) <= 987.655);
658 g_value_unset (&val);
665 _binary_search_compare (guint32 * a, guint32 * b)
670 GST_START_TEST (test_binary_search)
674 guint32 search_element = 121 * 2;
677 for (i = 0; i < 257; i++)
678 data[i] = (i + 1) * 2;
681 (guint32 *) gst_util_array_binary_search (data, 257, sizeof (guint32),
682 (GCompareDataFunc) _binary_search_compare, GST_SEARCH_MODE_EXACT,
683 &search_element, NULL);
684 fail_unless (match != NULL);
685 fail_unless_equals_int (match - data, 120);
688 (guint32 *) gst_util_array_binary_search (data, 257, sizeof (guint32),
689 (GCompareDataFunc) _binary_search_compare, GST_SEARCH_MODE_BEFORE,
690 &search_element, NULL);
691 fail_unless (match != NULL);
692 fail_unless_equals_int (match - data, 120);
695 (guint32 *) gst_util_array_binary_search (data, 257, sizeof (guint32),
696 (GCompareDataFunc) _binary_search_compare, GST_SEARCH_MODE_AFTER,
697 &search_element, NULL);
698 fail_unless (match != NULL);
699 fail_unless_equals_int (match - data, 120);
703 (guint32 *) gst_util_array_binary_search (data, 257, sizeof (guint32),
704 (GCompareDataFunc) _binary_search_compare, GST_SEARCH_MODE_EXACT,
705 &search_element, NULL);
706 fail_unless (match == NULL);
709 (guint32 *) gst_util_array_binary_search (data, 257, sizeof (guint32),
710 (GCompareDataFunc) _binary_search_compare, GST_SEARCH_MODE_AFTER,
711 &search_element, NULL);
712 fail_unless (match != NULL);
713 fail_unless_equals_int (match - data, 0);
716 (guint32 *) gst_util_array_binary_search (data, 257, sizeof (guint32),
717 (GCompareDataFunc) _binary_search_compare, GST_SEARCH_MODE_BEFORE,
718 &search_element, NULL);
719 fail_unless (match == NULL);
721 search_element = 1000;
723 (guint32 *) gst_util_array_binary_search (data, 257, sizeof (guint32),
724 (GCompareDataFunc) _binary_search_compare, GST_SEARCH_MODE_EXACT,
725 &search_element, NULL);
726 fail_unless (match == NULL);
729 (guint32 *) gst_util_array_binary_search (data, 257, sizeof (guint32),
730 (GCompareDataFunc) _binary_search_compare, GST_SEARCH_MODE_AFTER,
731 &search_element, NULL);
732 fail_unless (match == NULL);
735 (guint32 *) gst_util_array_binary_search (data, 257, sizeof (guint32),
736 (GCompareDataFunc) _binary_search_compare, GST_SEARCH_MODE_BEFORE,
737 &search_element, NULL);
738 fail_unless (match != NULL);
739 fail_unless_equals_int (match - data, 256);
741 search_element = 121 * 2 - 1;
743 (guint32 *) gst_util_array_binary_search (data, 257, sizeof (guint32),
744 (GCompareDataFunc) _binary_search_compare, GST_SEARCH_MODE_EXACT,
745 &search_element, NULL);
746 fail_unless (match == NULL);
749 (guint32 *) gst_util_array_binary_search (data, 257, sizeof (guint32),
750 (GCompareDataFunc) _binary_search_compare, GST_SEARCH_MODE_AFTER,
751 &search_element, NULL);
752 fail_unless (match != NULL);
753 fail_unless_equals_int (match - data, 120);
756 (guint32 *) gst_util_array_binary_search (data, 257, sizeof (guint32),
757 (GCompareDataFunc) _binary_search_compare, GST_SEARCH_MODE_BEFORE,
758 &search_element, NULL);
759 fail_unless (match != NULL);
760 fail_unless_equals_int (match - data, 119);
769 #include <gsl/gsl_rng.h>
773 randguint64 (gsl_rng * rng, guint64 n)
783 x.parts.a = gsl_rng_uniform_int (rng, 1 << 16);
784 x.parts.b = gsl_rng_uniform_int (rng, 1 << 16);
785 x.parts.c = gsl_rng_uniform_int (rng, 1 << 16);
786 x.parts.d = gsl_rng_uniform_int (rng, 1 << 16);
799 gmp_set_uint64 (mpz_t mp, guint64 x)
806 mpz_ui_pow_ui (two_32, 2, 32);
807 mpz_set_ui (mp, (unsigned long) ((x >> 32) & G_MAXUINT32));
808 mpz_mul (tmp, mp, two_32);
809 mpz_add_ui (mp, tmp, (unsigned long) (x & G_MAXUINT32));
815 gmp_get_uint64 (mpz_t mp)
817 mpz_t two_64, two_32, tmp;
824 mpz_ui_pow_ui (two_64, 2, 64);
825 mpz_ui_pow_ui (two_32, 2, 32);
826 if (mpz_cmp (tmp, two_64) >= 0)
830 mpz_tdiv_q (tmp, mp, two_32);
831 ret = mpz_get_ui (tmp);
833 ret |= mpz_get_ui (mp);
841 gmp_scale (guint64 x, guint64 a, guint64 b, enum round_t mode)
851 gmp_set_uint64 (mp1, x);
852 gmp_set_uint64 (mp3, a);
853 mpz_mul (mp2, mp1, mp3);
855 case ROUND_TONEAREST:
856 gmp_set_uint64 (mp1, b);
857 mpz_tdiv_q_ui (mp3, mp1, 2);
858 mpz_add (mp1, mp2, mp3);
862 gmp_set_uint64 (mp1, b);
863 mpz_sub_ui (mp3, mp1, 1);
864 mpz_add (mp1, mp2, mp3);
870 gmp_set_uint64 (mp3, b);
871 mpz_tdiv_q (mp1, mp2, mp3);
872 x = gmp_get_uint64 (mp1);
880 _gmp_test_scale (gsl_rng * rng)
882 guint64 bygst, bygmp;
883 guint64 a = randguint64 (rng, gsl_rng_uniform_int (rng,
884 2) ? G_MAXUINT64 : G_MAXUINT32);
885 guint64 b = randguint64 (rng, gsl_rng_uniform_int (rng, 2) ? G_MAXUINT64 - 1 : G_MAXUINT32 - 1) + 1; /* 0 not allowed */
886 guint64 val = randguint64 (rng, gmp_scale (G_MAXUINT64, b, a, ROUND_DOWN));
887 enum round_t mode = gsl_rng_uniform_int (rng, 3);
890 bygmp = gmp_scale (val, a, b, mode);
892 case ROUND_TONEAREST:
893 bygst = gst_util_uint64_scale_round (val, a, b);
894 func = "gst_util_uint64_scale_round";
897 bygst = gst_util_uint64_scale_ceil (val, a, b);
898 func = "gst_util_uint64_scale_ceil";
901 bygst = gst_util_uint64_scale (val, a, b);
902 func = "gst_util_uint64_scale";
905 g_assert_not_reached ();
908 fail_unless (bygst == bygmp,
909 "error: %s(): %" G_GUINT64_FORMAT " * %" G_GUINT64_FORMAT " / %"
910 G_GUINT64_FORMAT " = %" G_GUINT64_FORMAT ", correct = %" G_GUINT64_FORMAT
911 "\n", func, val, a, b, bygst, bygmp);
915 _gmp_test_scale_int (gsl_rng * rng)
917 guint64 bygst, bygmp;
918 gint32 a = randguint64 (rng, G_MAXINT32);
919 gint32 b = randguint64 (rng, G_MAXINT32 - 1) + 1; /* 0 not allowed */
920 guint64 val = randguint64 (rng, gmp_scale (G_MAXUINT64, b, a, ROUND_DOWN));
921 enum round_t mode = gsl_rng_uniform_int (rng, 3);
924 bygmp = gmp_scale (val, a, b, mode);
926 case ROUND_TONEAREST:
927 bygst = gst_util_uint64_scale_int_round (val, a, b);
928 func = "gst_util_uint64_scale_int_round";
931 bygst = gst_util_uint64_scale_int_ceil (val, a, b);
932 func = "gst_util_uint64_scale_int_ceil";
935 bygst = gst_util_uint64_scale_int (val, a, b);
936 func = "gst_util_uint64_scale_int";
939 g_assert_not_reached ();
942 fail_unless (bygst == bygmp,
943 "error: %s(): %" G_GUINT64_FORMAT " * %d / %d = %" G_GUINT64_FORMAT
944 ", correct = %" G_GUINT64_FORMAT "\n", func, val, a, b, bygst, bygmp);
947 #define GMP_TEST_RUNS 100000
949 GST_START_TEST (test_math_scale_gmp)
951 gsl_rng *rng = gsl_rng_alloc (gsl_rng_mt19937);
954 for (n = 0; n < GMP_TEST_RUNS; n++)
955 _gmp_test_scale (rng);
962 GST_START_TEST (test_math_scale_gmp_int)
964 gsl_rng *rng = gsl_rng_alloc (gsl_rng_mt19937);
967 for (n = 0; n < GMP_TEST_RUNS; n++)
968 _gmp_test_scale_int (rng);
978 GST_START_TEST (test_pad_proxy_query_caps_aggregation)
980 GstElement *tee, *sink1, *sink2;
982 GstPad *tee_src1, *tee_src2, *tee_sink, *sink1_sink, *sink2_sink;
984 tee = gst_element_factory_make ("tee", "tee");
986 sink1 = gst_element_factory_make ("fakesink", "sink1");
987 tee_src1 = gst_element_get_request_pad (tee, "src_%u");
988 sink1_sink = gst_element_get_static_pad (sink1, "sink");
989 fail_unless_equals_int (gst_pad_link (tee_src1, sink1_sink), GST_PAD_LINK_OK);
991 sink2 = gst_element_factory_make ("fakesink", "sink2");
992 tee_src2 = gst_element_get_request_pad (tee, "src_%u");
993 sink2_sink = gst_element_get_static_pad (sink2, "sink");
994 fail_unless_equals_int (gst_pad_link (tee_src2, sink2_sink), GST_PAD_LINK_OK);
996 tee_sink = gst_element_get_static_pad (tee, "sink");
998 gst_element_set_state (sink1, GST_STATE_PAUSED);
999 gst_element_set_state (sink2, GST_STATE_PAUSED);
1000 gst_element_set_state (tee, GST_STATE_PAUSED);
1002 /* by default, ANY caps should intersect to ANY */
1003 caps = gst_pad_query_caps (tee_sink, NULL);
1004 GST_INFO ("got caps: %" GST_PTR_FORMAT, caps);
1005 fail_unless (caps != NULL);
1006 fail_unless (gst_caps_is_any (caps));
1007 gst_caps_unref (caps);
1009 /* these don't intersect we should get empty caps */
1010 caps = gst_caps_new_empty_simple ("foo/bar");
1011 fail_unless (gst_pad_set_caps (sink1_sink, caps));
1012 gst_pad_use_fixed_caps (sink1_sink);
1013 gst_caps_unref (caps);
1015 caps = gst_caps_new_empty_simple ("bar/ter");
1016 fail_unless (gst_pad_set_caps (sink2_sink, caps));
1017 gst_pad_use_fixed_caps (sink2_sink);
1018 gst_caps_unref (caps);
1020 caps = gst_pad_query_caps (tee_sink, NULL);
1021 GST_INFO ("got caps: %" GST_PTR_FORMAT, caps);
1022 fail_unless (caps != NULL);
1023 fail_unless (gst_caps_is_empty (caps));
1024 gst_caps_unref (caps);
1026 /* test intersection */
1027 caps = gst_caps_new_simple ("foo/bar", "barversion", G_TYPE_INT, 1, NULL);
1028 GST_OBJECT_FLAG_UNSET (sink2_sink, GST_PAD_FLAG_FIXED_CAPS);
1029 fail_unless (gst_pad_set_caps (sink2_sink, caps));
1030 gst_pad_use_fixed_caps (sink2_sink);
1031 gst_caps_unref (caps);
1033 caps = gst_pad_query_caps (tee_sink, NULL);
1034 GST_INFO ("got caps: %" GST_PTR_FORMAT, caps);
1035 fail_unless (caps != NULL);
1036 fail_if (gst_caps_is_empty (caps));
1038 GstStructure *s = gst_caps_get_structure (caps, 0);
1040 fail_unless_equals_string (gst_structure_get_name (s), "foo/bar");
1041 fail_unless (gst_structure_has_field_typed (s, "barversion", G_TYPE_INT));
1043 gst_caps_unref (caps);
1045 gst_element_set_state (sink1, GST_STATE_NULL);
1046 gst_element_set_state (sink2, GST_STATE_NULL);
1047 gst_element_set_state (tee, GST_STATE_NULL);
1050 gst_element_release_request_pad (tee, tee_src1);
1051 gst_object_unref (tee_src1);
1052 gst_element_release_request_pad (tee, tee_src2);
1053 gst_object_unref (tee_src2);
1054 gst_object_unref (tee_sink);
1055 gst_object_unref (tee);
1056 gst_object_unref (sink1_sink);
1057 gst_object_unref (sink1);
1058 gst_object_unref (sink2_sink);
1059 gst_object_unref (sink2);
1064 GST_START_TEST (test_greatest_common_divisor)
1066 fail_if (gst_util_greatest_common_divisor (1, 1) != 1);
1067 fail_if (gst_util_greatest_common_divisor (2, 3) != 1);
1068 fail_if (gst_util_greatest_common_divisor (3, 5) != 1);
1069 fail_if (gst_util_greatest_common_divisor (-1, 1) != 1);
1070 fail_if (gst_util_greatest_common_divisor (-2, 3) != 1);
1071 fail_if (gst_util_greatest_common_divisor (-3, 5) != 1);
1072 fail_if (gst_util_greatest_common_divisor (-1, -1) != 1);
1073 fail_if (gst_util_greatest_common_divisor (-2, -3) != 1);
1074 fail_if (gst_util_greatest_common_divisor (-3, -5) != 1);
1075 fail_if (gst_util_greatest_common_divisor (1, -1) != 1);
1076 fail_if (gst_util_greatest_common_divisor (2, -3) != 1);
1077 fail_if (gst_util_greatest_common_divisor (3, -5) != 1);
1078 fail_if (gst_util_greatest_common_divisor (2, 2) != 2);
1079 fail_if (gst_util_greatest_common_divisor (2, 4) != 2);
1080 fail_if (gst_util_greatest_common_divisor (1001, 11) != 11);
1086 GST_START_TEST (test_read_macros)
1088 guint8 carray[] = "ABCDEFGH"; /* 0x41 ... 0x48 */
1092 memcpy (uarray, carray, 8);
1096 /* First try the standard pointer variants */
1097 fail_unless_equals_int_hex (GST_READ_UINT16_BE (cpointer), 0x4142);
1098 fail_unless_equals_int_hex (GST_READ_UINT16_BE (cpointer + 1), 0x4243);
1099 fail_unless_equals_int_hex (GST_READ_UINT16_BE (cpointer + 2), 0x4344);
1100 fail_unless_equals_int_hex (GST_READ_UINT16_BE (cpointer + 3), 0x4445);
1101 fail_unless_equals_int_hex (GST_READ_UINT16_BE (cpointer + 4), 0x4546);
1102 fail_unless_equals_int_hex (GST_READ_UINT16_BE (cpointer + 5), 0x4647);
1103 fail_unless_equals_int_hex (GST_READ_UINT16_BE (cpointer + 6), 0x4748);
1105 fail_unless_equals_int_hex (GST_READ_UINT16_LE (cpointer), 0x4241);
1106 fail_unless_equals_int_hex (GST_READ_UINT16_LE (cpointer + 1), 0x4342);
1107 fail_unless_equals_int_hex (GST_READ_UINT16_LE (cpointer + 2), 0x4443);
1108 fail_unless_equals_int_hex (GST_READ_UINT16_LE (cpointer + 3), 0x4544);
1109 fail_unless_equals_int_hex (GST_READ_UINT16_LE (cpointer + 4), 0x4645);
1110 fail_unless_equals_int_hex (GST_READ_UINT16_LE (cpointer + 5), 0x4746);
1111 fail_unless_equals_int_hex (GST_READ_UINT16_LE (cpointer + 6), 0x4847);
1113 /* On an array of guint8 */
1114 fail_unless_equals_int_hex (GST_READ_UINT16_BE (carray), 0x4142);
1115 fail_unless_equals_int_hex (GST_READ_UINT16_BE (carray + 1), 0x4243);
1116 fail_unless_equals_int_hex (GST_READ_UINT16_BE (carray + 2), 0x4344);
1117 fail_unless_equals_int_hex (GST_READ_UINT16_BE (carray + 3), 0x4445);
1118 fail_unless_equals_int_hex (GST_READ_UINT16_BE (carray + 4), 0x4546);
1119 fail_unless_equals_int_hex (GST_READ_UINT16_BE (carray + 5), 0x4647);
1120 fail_unless_equals_int_hex (GST_READ_UINT16_BE (carray + 6), 0x4748);
1122 fail_unless_equals_int_hex (GST_READ_UINT16_LE (carray), 0x4241);
1123 fail_unless_equals_int_hex (GST_READ_UINT16_LE (carray + 1), 0x4342);
1124 fail_unless_equals_int_hex (GST_READ_UINT16_LE (carray + 2), 0x4443);
1125 fail_unless_equals_int_hex (GST_READ_UINT16_LE (carray + 3), 0x4544);
1126 fail_unless_equals_int_hex (GST_READ_UINT16_LE (carray + 4), 0x4645);
1127 fail_unless_equals_int_hex (GST_READ_UINT16_LE (carray + 5), 0x4746);
1128 fail_unless_equals_int_hex (GST_READ_UINT16_LE (carray + 6), 0x4847);
1130 /* On an array of guint32 */
1131 fail_unless_equals_int_hex (GST_READ_UINT16_BE (uarray), 0x4142);
1132 fail_unless_equals_int_hex (GST_READ_UINT16_BE (uarray + 1), 0x4546);
1134 fail_unless_equals_int_hex (GST_READ_UINT16_LE (uarray), 0x4241);
1135 fail_unless_equals_int_hex (GST_READ_UINT16_LE (uarray + 1), 0x4645);
1139 /* First try the standard pointer variants */
1140 fail_unless_equals_int_hex (GST_READ_UINT24_BE (cpointer), 0x414243);
1141 fail_unless_equals_int_hex (GST_READ_UINT24_BE (cpointer + 1), 0x424344);
1142 fail_unless_equals_int_hex (GST_READ_UINT24_BE (cpointer + 2), 0x434445);
1143 fail_unless_equals_int_hex (GST_READ_UINT24_BE (cpointer + 3), 0x444546);
1144 fail_unless_equals_int_hex (GST_READ_UINT24_BE (cpointer + 4), 0x454647);
1145 fail_unless_equals_int_hex (GST_READ_UINT24_BE (cpointer + 5), 0x464748);
1147 fail_unless_equals_int_hex (GST_READ_UINT24_LE (cpointer), 0x434241);
1148 fail_unless_equals_int_hex (GST_READ_UINT24_LE (cpointer + 1), 0x444342);
1149 fail_unless_equals_int_hex (GST_READ_UINT24_LE (cpointer + 2), 0x454443);
1150 fail_unless_equals_int_hex (GST_READ_UINT24_LE (cpointer + 3), 0x464544);
1151 fail_unless_equals_int_hex (GST_READ_UINT24_LE (cpointer + 4), 0x474645);
1152 fail_unless_equals_int_hex (GST_READ_UINT24_LE (cpointer + 5), 0x484746);
1154 /* On an array of guint8 */
1155 fail_unless_equals_int_hex (GST_READ_UINT24_BE (carray), 0x414243);
1156 fail_unless_equals_int_hex (GST_READ_UINT24_BE (carray + 1), 0x424344);
1157 fail_unless_equals_int_hex (GST_READ_UINT24_BE (carray + 2), 0x434445);
1158 fail_unless_equals_int_hex (GST_READ_UINT24_BE (carray + 3), 0x444546);
1159 fail_unless_equals_int_hex (GST_READ_UINT24_BE (carray + 4), 0x454647);
1160 fail_unless_equals_int_hex (GST_READ_UINT24_BE (carray + 5), 0x464748);
1162 fail_unless_equals_int_hex (GST_READ_UINT24_LE (carray), 0x434241);
1163 fail_unless_equals_int_hex (GST_READ_UINT24_LE (carray + 1), 0x444342);
1164 fail_unless_equals_int_hex (GST_READ_UINT24_LE (carray + 2), 0x454443);
1165 fail_unless_equals_int_hex (GST_READ_UINT24_LE (carray + 3), 0x464544);
1166 fail_unless_equals_int_hex (GST_READ_UINT24_LE (carray + 4), 0x474645);
1167 fail_unless_equals_int_hex (GST_READ_UINT24_LE (carray + 5), 0x484746);
1169 /* On an array of guint32 */
1170 fail_unless_equals_int_hex (GST_READ_UINT24_BE (uarray), 0x414243);
1171 fail_unless_equals_int_hex (GST_READ_UINT24_BE (uarray + 1), 0x454647);
1173 fail_unless_equals_int_hex (GST_READ_UINT24_LE (uarray), 0x434241);
1174 fail_unless_equals_int_hex (GST_READ_UINT24_LE (uarray + 1), 0x474645);
1178 /* First try the standard pointer variants */
1179 fail_unless_equals_int_hex (GST_READ_UINT32_BE (cpointer), 0x41424344);
1180 fail_unless_equals_int_hex (GST_READ_UINT32_BE (cpointer + 1), 0x42434445);
1181 fail_unless_equals_int_hex (GST_READ_UINT32_BE (cpointer + 2), 0x43444546);
1182 fail_unless_equals_int_hex (GST_READ_UINT32_BE (cpointer + 3), 0x44454647);
1183 fail_unless_equals_int_hex (GST_READ_UINT32_BE (cpointer + 4), 0x45464748);
1185 fail_unless_equals_int_hex (GST_READ_UINT32_LE (cpointer), 0x44434241);
1186 fail_unless_equals_int_hex (GST_READ_UINT32_LE (cpointer + 1), 0x45444342);
1187 fail_unless_equals_int_hex (GST_READ_UINT32_LE (cpointer + 2), 0x46454443);
1188 fail_unless_equals_int_hex (GST_READ_UINT32_LE (cpointer + 3), 0x47464544);
1189 fail_unless_equals_int_hex (GST_READ_UINT32_LE (cpointer + 4), 0x48474645);
1191 /* On an array of guint8 */
1192 fail_unless_equals_int_hex (GST_READ_UINT32_BE (carray), 0x41424344);
1193 fail_unless_equals_int_hex (GST_READ_UINT32_BE (carray + 1), 0x42434445);
1194 fail_unless_equals_int_hex (GST_READ_UINT32_BE (carray + 2), 0x43444546);
1195 fail_unless_equals_int_hex (GST_READ_UINT32_BE (carray + 3), 0x44454647);
1196 fail_unless_equals_int_hex (GST_READ_UINT32_BE (carray + 4), 0x45464748);
1198 fail_unless_equals_int_hex (GST_READ_UINT32_LE (carray), 0x44434241);
1199 fail_unless_equals_int_hex (GST_READ_UINT32_LE (carray + 1), 0x45444342);
1200 fail_unless_equals_int_hex (GST_READ_UINT32_LE (carray + 2), 0x46454443);
1201 fail_unless_equals_int_hex (GST_READ_UINT32_LE (carray + 3), 0x47464544);
1202 fail_unless_equals_int_hex (GST_READ_UINT32_LE (carray + 4), 0x48474645);
1204 /* On an array of guint32 */
1205 fail_unless_equals_int_hex (GST_READ_UINT32_BE (uarray), 0x41424344);
1206 fail_unless_equals_int_hex (GST_READ_UINT32_BE (uarray + 1), 0x45464748);
1208 fail_unless_equals_int_hex (GST_READ_UINT32_LE (uarray), 0x44434241);
1209 fail_unless_equals_int_hex (GST_READ_UINT32_LE (uarray + 1), 0x48474645);
1213 fail_unless_equals_int64_hex (GST_READ_UINT64_BE (cpointer),
1214 0x4142434445464748);
1215 fail_unless_equals_int64_hex (GST_READ_UINT64_LE (cpointer),
1216 0x4847464544434241);
1218 fail_unless_equals_int64_hex (GST_READ_UINT64_BE (carray),
1219 0x4142434445464748);
1220 fail_unless_equals_int64_hex (GST_READ_UINT64_LE (carray),
1221 0x4847464544434241);
1223 fail_unless_equals_int64_hex (GST_READ_UINT64_BE (uarray),
1224 0x4142434445464748);
1225 fail_unless_equals_int64_hex (GST_READ_UINT64_LE (uarray),
1226 0x4847464544434241);
1232 gst_utils_suite (void)
1234 Suite *s = suite_create ("GstUtils");
1235 TCase *tc_chain = tcase_create ("general");
1237 suite_add_tcase (s, tc_chain);
1238 tcase_add_test (tc_chain, test_buffer_probe_n_times);
1239 tcase_add_test (tc_chain, test_buffer_probe_once);
1240 tcase_add_test (tc_chain, test_math_scale);
1241 tcase_add_test (tc_chain, test_math_scale_round);
1242 tcase_add_test (tc_chain, test_math_scale_ceil);
1243 tcase_add_test (tc_chain, test_math_scale_uint64);
1244 tcase_add_test (tc_chain, test_math_scale_random);
1247 tcase_add_test (tc_chain, test_math_scale_gmp);
1248 tcase_add_test (tc_chain, test_math_scale_gmp_int);
1252 tcase_add_test (tc_chain, test_guint64_to_gdouble);
1253 tcase_add_test (tc_chain, test_gdouble_to_guint64);
1254 #ifndef GST_DISABLE_PARSE
1255 tcase_add_test (tc_chain, test_parse_bin_from_description);
1257 tcase_add_test (tc_chain, test_element_found_tags);
1258 tcase_add_test (tc_chain, test_element_unlink);
1259 tcase_add_test (tc_chain, test_set_value_from_string);
1260 tcase_add_test (tc_chain, test_binary_search);
1262 tcase_add_test (tc_chain, test_pad_proxy_query_caps_aggregation);
1263 tcase_add_test (tc_chain, test_greatest_common_divisor);
1265 tcase_add_test (tc_chain, test_read_macros);
1269 GST_CHECK_MAIN (gst_utils);