3 * unit test for typefind helper
5 * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
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.
27 #include <gst/check/gstcheck.h>
29 #include <gst/base/gsttypefindhelper.h>
31 static const guint8 vorbisid[30] = { 0x01, 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73,
32 0x00, 0x00, 0x00, 0x00, 0x02, 0x44, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00,
33 0x00, 0x03, 0xf4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0x01
36 static void foobar_typefind (GstTypeFind * tf, gpointer unused);
38 static GstStaticCaps foobar_caps = GST_STATIC_CAPS ("foo/x-bar");
40 #define FOOBAR_CAPS (gst_static_caps_get (&foobar_caps))
42 /* make sure the entire data in the buffer is available for peeking */
43 GST_START_TEST (test_buffer_range)
45 static gchar *foobar_exts[] = { (char *) "foobar", NULL };
51 fail_unless (gst_type_find_register (NULL, "foo/x-bar",
52 GST_RANK_PRIMARY + 50, foobar_typefind, (gchar **) foobar_exts,
53 FOOBAR_CAPS, NULL, NULL));
55 buf = gst_buffer_new ();
56 fail_unless (buf != NULL);
58 gst_buffer_take_memory (buf, -1,
59 gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
60 (gpointer) vorbisid, NULL, 30, 0, 30));
62 caps = gst_type_find_helper_for_buffer (NULL, buf, NULL);
63 fail_unless (caps != NULL);
64 fail_unless (GST_CAPS_IS_SIMPLE (caps));
65 fail_unless (gst_caps_is_fixed (caps));
67 s = gst_caps_get_structure (caps, 0);
68 fail_unless (s != NULL);
69 fail_unless (gst_structure_has_name (s, "foo/x-bar"));
71 gst_caps_unref (caps);
72 gst_buffer_unref (buf);
78 gst_typefindhelper_suite (void)
80 Suite *s = suite_create ("typefindhelper");
81 TCase *tc_chain = tcase_create ("general");
83 suite_add_tcase (s, tc_chain);
84 tcase_add_test (tc_chain, test_buffer_range);
89 GST_CHECK_MAIN (gst_typefindhelper);
92 foobar_typefind (GstTypeFind * tf, gpointer unused)
96 data = gst_type_find_peek (tf, 0, 10);
97 fail_unless (data != NULL);
98 fail_unless (memcmp (data, vorbisid, 10) == 0);
100 data = gst_type_find_peek (tf, 0, 20);
101 fail_unless (data != NULL);
102 fail_unless (memcmp (data, vorbisid, 20) == 0);
104 data = gst_type_find_peek (tf, 0, 30);
105 fail_unless (data != NULL);
106 fail_unless (memcmp (data, vorbisid, 30) == 0);
108 fail_unless (gst_type_find_peek (tf, 0, 31) == NULL);
109 fail_unless (gst_type_find_peek (tf, 1, 30) == NULL);
110 fail_unless (gst_type_find_peek (tf, 25, 6) == NULL);
112 data = gst_type_find_peek (tf, 1, 29);
113 fail_unless (data != NULL);
114 fail_unless (memcmp (data, vorbisid + 1, 29) == 0);
116 data = gst_type_find_peek (tf, 25, 4);
117 fail_unless (data != NULL);
118 fail_unless (memcmp (data, vorbisid + 25, 4) == 0);
120 fail_unless (gst_type_find_peek (tf, -1, 29) == NULL);
121 fail_unless (gst_type_find_peek (tf, -1, 1) == NULL);
122 fail_unless (gst_type_find_peek (tf, -1, 0) == NULL);
124 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FOOBAR_CAPS);