3 * Unit tests for GstInfo
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.
23 #include <gst/check/gstcheck.h>
25 #ifndef GST_DISABLE_GST_DEBUG
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)
34 dbg_msg = gst_debug_message_get (message);
35 fail_unless (dbg_msg != NULL);
37 /* g_print ("%s\n", dbg_msg); */
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,
46 /* check our GST_PTR_FORMAT printf extension stuff */
47 GST_START_TEST (info_ptr_format_printf_extension)
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);
54 gst_debug_set_default_threshold (GST_LEVEL_LOG);
57 GST_LOG ("NULL: %" GST_PTR_FORMAT, (gpointer) NULL);
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);
67 GST_LOG ("STRUCTURE: %" GST_PTR_FORMAT, s);
68 gst_structure_free (s);
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,
80 GST_LOG ("MESSAGE: %" GST_PTR_FORMAT, msg);
81 gst_message_unref (msg);
87 GST_LOG ("GOBJECT: %" GST_PTR_FORMAT, obj);
92 GST_LOG ("GSTOBJECT: %" GST_PTR_FORMAT, obj);
97 GST_LOG ("PAD: %" GST_PTR_FORMAT, pad);
102 GST_LOG ("PAD: %" GST_PTR_FORMAT, pad);
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);
114 /* check our GST_SEGMENT_FORMAT printf extension stuff */
115 GST_START_TEST (info_segment_format_printf_extension)
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);
122 gst_debug_set_default_threshold (GST_LEVEL_LOG);
128 gst_segment_init (&segment, GST_FORMAT_TIME);
131 segment.applied_rate = 2.0;
133 segment.stop = 5 * 60 * GST_SECOND;
136 segment.position = 2 * GST_SECOND;
137 segment.duration = 90 * 60 * GST_SECOND;
139 GST_LOG ("TIME: %" GST_SEGMENT_FORMAT, &segment);
146 gst_segment_init (&segment, GST_FORMAT_BYTES);
149 segment.applied_rate = 1.0;
151 segment.stop = 9999999;
154 GST_LOG ("BYTE: %" GST_SEGMENT_FORMAT, &segment);
157 /* UNKNOWN format segment (format numbers are consecutive from 0) */
161 gst_segment_init (&segment, 98765432);
164 segment.applied_rate = 1.0;
166 segment.stop = 987654321;
169 GST_LOG ("UNKNOWN: %" GST_SEGMENT_FORMAT, &segment);
172 /* UNDEFINED format segment */
176 gst_segment_init (&segment, GST_FORMAT_UNDEFINED);
178 GST_LOG ("UNDEFINED: %" GST_SEGMENT_FORMAT, &segment);
182 GST_LOG ("NULL: %" GST_SEGMENT_FORMAT, (GstSegment *) NULL);
185 gst_debug_set_default_threshold (GST_LEVEL_NONE);
186 gst_debug_add_log_function (gst_debug_log_default, NULL);
187 gst_debug_remove_log_function (printf_extension_log_func);
192 GST_START_TEST (info_log_handler)
196 removed = gst_debug_remove_log_function (gst_debug_log_default);
197 fail_unless (removed == 1);
202 GST_START_TEST (info_dump_mem)
204 GstDebugCategory *cat = NULL;
207 const guint8 data[] = { 0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70,
208 0x71, 0x74, 0x20, 0x20, 0x20, 0x05, 0x03, 0x00, 0x71, 0x74, 0x20, 0x20,
209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
210 0x00, 0x00, 0xef, 0xe1, 0x6d, 0x6f, 0x6f, 0x76, 0x00, 0x00, 0x00, 0x6c,
211 0x6d, 0x76, 0x68, 0x64, 0x00, 0x00, 0x00, 0x00, 0xbf, 0xd1, 0x00, 0x1d,
212 0xbf, 0xd1, 0x00, 0x1e, 0x00, 0x00, 0x0b, 0xb5, 0x00, 0x04, 0x59, 0xc5,
213 0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, '%', 's', '%', 's'
217 e = gst_element_factory_make ("fakesink", NULL);
218 GST_DEBUG_CATEGORY_INIT (cat, "dumpcat", 0, "data dump debug category");
219 GST_MEMDUMP ("quicktime header", data, sizeof (data));
220 GST_MEMDUMP (NULL, data, sizeof (data));
221 GST_CAT_MEMDUMP (cat, "quicktime header", data, sizeof (data));
222 GST_MEMDUMP_OBJECT (e, "object stuff", data, sizeof (data));
223 GST_CAT_MEMDUMP_OBJECT (cat, e, "object/cat stuff", data, sizeof (data));
224 gst_object_unref (e);
229 GST_START_TEST (info_fixme)
231 GstDebugCategory *cat = NULL;
234 e = gst_element_factory_make ("fakesink", NULL);
235 GST_DEBUG_CATEGORY_INIT (cat, "fixcat", 0, "FIXME debug category");
236 GST_FIXME ("fix %s thing", "this");
237 GST_FIXME_OBJECT (e, "fix %s object", "this");
238 GST_CAT_FIXME (cat, "fix some%s in this category", "thing");
239 GST_CAT_FIXME_OBJECT (cat, e, "fix some%s in this cat and object", "thing");
240 gst_object_unref (e);
247 gst_info_suite (void)
249 Suite *s = suite_create ("GstInfo");
250 TCase *tc_chain = tcase_create ("info");
252 tcase_set_timeout (tc_chain, 30);
254 suite_add_tcase (s, tc_chain);
255 #ifndef GST_DISABLE_GST_DEBUG
256 tcase_add_test (tc_chain, info_segment_format_printf_extension);
257 tcase_add_test (tc_chain, info_ptr_format_printf_extension);
258 tcase_add_test (tc_chain, info_log_handler);
259 tcase_add_test (tc_chain, info_dump_mem);
260 tcase_add_test (tc_chain, info_fixme);
266 GST_CHECK_MAIN (gst_info);