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);
130 gst_segment_set_newsegment (&segment, FALSE, 1.0, 2.0,
131 GST_FORMAT_TIME, 0, 5 * 60 * GST_SECOND, 0);
133 segment.last_stop = 2 * GST_SECOND;
134 segment.duration = 90 * 60 * GST_SECOND;
136 GST_LOG ("TIME: %" GST_SEGMENT_FORMAT, &segment);
143 gst_segment_init (&segment, GST_FORMAT_BYTES);
145 gst_segment_set_newsegment (&segment, FALSE, 1.0, 1.0,
146 GST_FORMAT_BYTES, 0, 9999999, 0);
148 GST_LOG ("BYTE: %" GST_SEGMENT_FORMAT, &segment);
151 /* UNKNOWN format segment (format numbers are consecutive from 0) */
155 gst_segment_init (&segment, 98765432);
157 gst_segment_set_newsegment (&segment, FALSE, 1.0, 1.0,
158 GST_FORMAT_BYTES, 0, 987654321, 0);
160 GST_LOG ("UNKNOWN: %" GST_SEGMENT_FORMAT, &segment);
163 /* UNDEFINED format segment */
167 gst_segment_init (&segment, GST_FORMAT_UNDEFINED);
169 GST_LOG ("UNDEFINED: %" GST_SEGMENT_FORMAT, &segment);
173 GST_LOG ("NULL: %" GST_SEGMENT_FORMAT, (GstSegment *) NULL);
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);
183 GST_START_TEST (info_log_handler)
187 removed = gst_debug_remove_log_function (gst_debug_log_default);
188 fail_unless (removed == 1);
193 GST_START_TEST (info_dump_mem)
195 GstDebugCategory *cat = NULL;
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'
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);
220 GST_START_TEST (info_fixme)
222 GstDebugCategory *cat = NULL;
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);
238 gst_info_suite (void)
240 Suite *s = suite_create ("GstInfo");
241 TCase *tc_chain = tcase_create ("info");
243 tcase_set_timeout (tc_chain, 30);
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);
257 GST_CHECK_MAIN (gst_info);