tests/check/: use the new macro
[platform/upstream/gstreamer.git] / tests / check / libs / typefindhelper.c
1 /* GStreamer
2  *
3  * unit test for typefind helper
4  *
5  * Copyright (C) 2006 Tim-Philipp Müller  <tim centricular net>
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 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <gst/check/gstcheck.h>
28
29 #include <gst/base/gsttypefindhelper.h>
30
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
34 };
35
36 static GstStaticCaps foobar_caps = GST_STATIC_CAPS ("foo/x-bar");
37
38 #define FOOBAR_CAPS (gst_static_caps_get (&foobar_caps))
39
40 /* make sure the entire data in the buffer is available for peeking */
41 GST_START_TEST (test_buffer_range)
42 {
43   GstStructure *s;
44   GstBuffer *buf;
45   GstCaps *caps;
46
47   buf = gst_buffer_new ();
48   fail_unless (buf != NULL);
49   GST_BUFFER_DATA (buf) = (guint8 *) vorbisid;
50   GST_BUFFER_SIZE (buf) = 30;
51   GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_READONLY);
52
53   caps = gst_type_find_helper_for_buffer (NULL, buf, NULL);
54   fail_unless (caps != NULL);
55   fail_unless (GST_CAPS_IS_SIMPLE (caps));
56   fail_unless (gst_caps_is_fixed (caps));
57
58   s = gst_caps_get_structure (caps, 0);
59   fail_unless (s != NULL);
60   fail_unless (gst_structure_has_name (s, "foo/x-bar"));
61
62   gst_caps_unref (caps);
63   gst_buffer_unref (buf);
64 }
65
66 GST_END_TEST;
67
68 Suite *
69 gst_typefindhelper_suite (void)
70 {
71   Suite *s = suite_create ("typefindhelper");
72   TCase *tc_chain = tcase_create ("general");
73
74   suite_add_tcase (s, tc_chain);
75   tcase_add_test (tc_chain, test_buffer_range);
76
77   return s;
78 }
79
80 GST_CHECK_MAIN (gst_typefindhelper);
81
82 static void
83 foobar_typefind (GstTypeFind * tf, gpointer unused)
84 {
85   guint8 *data;
86
87   data = gst_type_find_peek (tf, 0, 10);
88   fail_unless (data != NULL);
89   fail_unless (memcmp (data, vorbisid, 10) == 0);
90
91   data = gst_type_find_peek (tf, 0, 20);
92   fail_unless (data != NULL);
93   fail_unless (memcmp (data, vorbisid, 20) == 0);
94
95   data = gst_type_find_peek (tf, 0, 30);
96   fail_unless (data != NULL);
97   fail_unless (memcmp (data, vorbisid, 30) == 0);
98
99   fail_unless (gst_type_find_peek (tf, 0, 31) == NULL);
100   fail_unless (gst_type_find_peek (tf, 1, 30) == NULL);
101   fail_unless (gst_type_find_peek (tf, 25, 6) == NULL);
102
103   data = gst_type_find_peek (tf, 1, 29);
104   fail_unless (data != NULL);
105   fail_unless (memcmp (data, vorbisid + 1, 29) == 0);
106
107   data = gst_type_find_peek (tf, 25, 4);
108   fail_unless (data != NULL);
109   fail_unless (memcmp (data, vorbisid + 25, 4) == 0);
110
111   fail_unless (gst_type_find_peek (tf, -1, 29) == NULL);
112   fail_unless (gst_type_find_peek (tf, -1, 1) == NULL);
113   fail_unless (gst_type_find_peek (tf, -1, 0) == NULL);
114
115   gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FOOBAR_CAPS);
116 }
117
118 static gboolean
119 plugin_init (GstPlugin * plugin)
120 {
121   static gchar *foobar_exts[] = { "foobar", NULL };
122
123   if (!gst_type_find_register (plugin, "foo/x-bar", GST_RANK_PRIMARY + 50,
124           foobar_typefind, foobar_exts, FOOBAR_CAPS, NULL, NULL)) {
125     return FALSE;
126   }
127
128   return TRUE;
129 }
130
131 GST_PLUGIN_DEFINE_STATIC (GST_VERSION_MAJOR,
132     GST_VERSION_MINOR,
133     "dummy typefind functions",
134     "dummy typefind functions",
135     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)