80da6a68617777ee9ad5f72bf0243bf1e6c2de16
[platform/upstream/gstreamer.git] / tests / check / gst / gstinfo.c
1 /* GStreamer
2  *
3  * Unit tests for GstInfo
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 #include <gst/check/gstcheck.h>
24
25 #ifndef GST_DISABLE_GST_DEBUG
26
27 static void
28 printf_extension_log_func (GstDebugCategory * category,
29     GstDebugLevel level, const gchar * file, const gchar * function,
30     gint line, GObject * object, GstDebugMessage * message, gpointer unused)
31 {
32   const gchar *dbg_msg;
33
34   dbg_msg = gst_debug_message_get (message);
35   fail_unless (dbg_msg != NULL);
36
37   /* g_print ("%s\n", dbg_msg); */
38
39   /* quick hack to still get stuff to show if GST_DEBUG is set */
40   if (g_getenv ("GST_DEBUG")) {
41     gst_debug_log_default (category, level, file, function, line, object,
42         message, unused);
43   }
44 }
45
46 /* check our GST_PTR_FORMAT printf extension stuff */
47 GST_START_TEST (info_ptr_format_printf_extension)
48 {
49   /* set up our own log function to make sure the code in gstinfo is actually
50    * executed without GST_DEBUG being set or it being output to stdout */
51   gst_debug_remove_log_function (gst_debug_log_default);
52   gst_debug_add_log_function (printf_extension_log_func, NULL);
53
54   gst_debug_set_default_threshold (GST_LEVEL_LOG);
55
56   /* NULL object */
57   GST_LOG ("NULL: %" GST_PTR_FORMAT, (gpointer) NULL);
58
59   /* structure */
60   {
61     GstStructure *s;
62
63     s = gst_structure_new ("foo/bar", "number", G_TYPE_INT, 1,
64         "string", G_TYPE_STRING, "s", "float-number", G_TYPE_DOUBLE,
65         (gdouble) 424242.42, NULL);
66
67     GST_LOG ("STRUCTURE: %" GST_PTR_FORMAT, s);
68     gst_structure_free (s);
69   }
70
71   /* message */
72   {
73     GstMessage *msg;
74
75     msg = gst_message_new_element (NULL,
76         gst_structure_new ("redirect", "new-location", G_TYPE_STRING,
77             "http://foobar.com/r0x0r.ogg", "minimum-bitrate", G_TYPE_INT,
78             56000, NULL));
79
80     GST_LOG ("MESSAGE: %" GST_PTR_FORMAT, msg);
81     gst_message_unref (msg);
82   }
83
84 #if 0
85   /* TODO: GObject */
86   {
87     GST_LOG ("GOBJECT: %" GST_PTR_FORMAT, obj);
88   }
89
90   /* TODO: GstObject */
91   {
92     GST_LOG ("GSTOBJECT: %" GST_PTR_FORMAT, obj);
93   }
94
95   /* TODO: GstPad */
96   {
97     GST_LOG ("PAD: %" GST_PTR_FORMAT, pad);
98   }
99
100   /* TODO: GstCaps */
101   {
102     GST_LOG ("PAD: %" GST_PTR_FORMAT, pad);
103   }
104 #endif
105
106   /* clean up */
107   gst_debug_set_default_threshold (GST_LEVEL_NONE);
108   gst_debug_add_log_function (gst_debug_log_default, NULL);
109   gst_debug_remove_log_function (printf_extension_log_func);
110 }
111
112 GST_END_TEST;
113
114 /* check our GST_SEGMENT_FORMAT printf extension stuff */
115 GST_START_TEST (info_segment_format_printf_extension)
116 {
117   /* set up our own log function to make sure the code in gstinfo is actually
118    * executed without GST_DEBUG being set or it being output to stdout */
119   gst_debug_remove_log_function (gst_debug_log_default);
120   gst_debug_add_log_function (printf_extension_log_func, NULL);
121
122   gst_debug_set_default_threshold (GST_LEVEL_LOG);
123
124   /* TIME segment */
125   {
126     GstSegment segment;
127
128     gst_segment_init (&segment, GST_FORMAT_TIME);
129
130     gst_segment_set_newsegment (&segment, FALSE, 1.0, 2.0,
131         GST_FORMAT_TIME, 0, 5 * 60 * GST_SECOND, 0);
132
133     segment.last_stop = 2 * GST_SECOND;
134     segment.duration = 90 * 60 * GST_SECOND;
135
136     GST_LOG ("TIME: %" GST_SEGMENT_FORMAT, &segment);
137   }
138
139   /* BYTE segment */
140   {
141     GstSegment segment;
142
143     gst_segment_init (&segment, GST_FORMAT_BYTES);
144
145     gst_segment_set_newsegment (&segment, FALSE, 1.0, 1.0,
146         GST_FORMAT_BYTES, 0, 9999999, 0);
147
148     GST_LOG ("BYTE: %" GST_SEGMENT_FORMAT, &segment);
149   }
150
151   /* UNKNOWN format segment (format numbers are consecutive from 0) */
152   {
153     GstSegment segment;
154
155     gst_segment_init (&segment, 98765432);
156
157     gst_segment_set_newsegment (&segment, FALSE, 1.0, 1.0,
158         GST_FORMAT_BYTES, 0, 987654321, 0);
159
160     GST_LOG ("UNKNOWN: %" GST_SEGMENT_FORMAT, &segment);
161   }
162
163   /* UNDEFINED format segment */
164   {
165     GstSegment segment;
166
167     gst_segment_init (&segment, GST_FORMAT_UNDEFINED);
168
169     GST_LOG ("UNDEFINED: %" GST_SEGMENT_FORMAT, &segment);
170   }
171
172   /* NULL segment */
173   GST_LOG ("NULL: %" GST_SEGMENT_FORMAT, (GstSegment *) NULL);
174
175   /* clean up */
176   gst_debug_set_default_threshold (GST_LEVEL_NONE);
177   gst_debug_add_log_function (gst_debug_log_default, NULL);
178   gst_debug_remove_log_function (printf_extension_log_func);
179 }
180
181 GST_END_TEST;
182
183 GST_START_TEST (info_log_handler)
184 {
185   guint removed;
186
187   removed = gst_debug_remove_log_function (gst_debug_log_default);
188   fail_unless (removed == 1);
189 }
190
191 GST_END_TEST;
192
193 GST_START_TEST (info_dump_mem)
194 {
195   GstDebugCategory *cat = NULL;
196   GstElement *e;
197
198   const guint8 data[] = { 0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70,
199     0x71, 0x74, 0x20, 0x20, 0x20, 0x05, 0x03, 0x00, 0x71, 0x74, 0x20, 0x20,
200     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
201     0x00, 0x00, 0xef, 0xe1, 0x6d, 0x6f, 0x6f, 0x76, 0x00, 0x00, 0x00, 0x6c,
202     0x6d, 0x76, 0x68, 0x64, 0x00, 0x00, 0x00, 0x00, 0xbf, 0xd1, 0x00, 0x1d,
203     0xbf, 0xd1, 0x00, 0x1e, 0x00, 0x00, 0x0b, 0xb5, 0x00, 0x04, 0x59, 0xc5,
204     0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
205     0x00, 0x00, 0x00, 0x00, 0x00, 0x01, '%', 's', '%', 's'
206   };
207
208   e = gst_element_factory_make ("fakesink", NULL);
209   GST_DEBUG_CATEGORY_INIT (cat, "dumpcat", 0, "data dump debug category");
210   GST_MEMDUMP ("quicktime header", data, sizeof (data));
211   GST_MEMDUMP (NULL, data, sizeof (data));
212   GST_CAT_MEMDUMP (cat, "quicktime header", data, sizeof (data));
213   GST_MEMDUMP_OBJECT (e, "object stuff", data, sizeof (data));
214   GST_CAT_MEMDUMP_OBJECT (cat, e, "object/cat stuff", data, sizeof (data));
215   gst_object_unref (e);
216 }
217
218 GST_END_TEST;
219
220 GST_START_TEST (info_fixme)
221 {
222   GstDebugCategory *cat = NULL;
223   GstElement *e;
224
225   e = gst_element_factory_make ("fakesink", NULL);
226   GST_DEBUG_CATEGORY_INIT (cat, "fixcat", 0, "FIXME debug category");
227   GST_FIXME ("fix %s thing", "this");
228   GST_FIXME_OBJECT (e, "fix %s object", "this");
229   GST_CAT_FIXME (cat, "fix some%s in this category", "thing");
230   GST_CAT_FIXME_OBJECT (cat, e, "fix some%s in this cat and object", "thing");
231   gst_object_unref (e);
232 }
233
234 GST_END_TEST;
235 #endif
236
237 static Suite *
238 gst_info_suite (void)
239 {
240   Suite *s = suite_create ("GstInfo");
241   TCase *tc_chain = tcase_create ("info");
242
243   tcase_set_timeout (tc_chain, 30);
244
245   suite_add_tcase (s, tc_chain);
246 #ifndef GST_DISABLE_GST_DEBUG
247   tcase_add_test (tc_chain, info_segment_format_printf_extension);
248   tcase_add_test (tc_chain, info_ptr_format_printf_extension);
249   tcase_add_test (tc_chain, info_log_handler);
250   tcase_add_test (tc_chain, info_dump_mem);
251   tcase_add_test (tc_chain, info_fixme);
252 #endif
253
254   return s;
255 }
256
257 GST_CHECK_MAIN (gst_info);