caps: improve _do_simplify
[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     segment.rate = 1.0;
131     segment.applied_rate = 2.0;
132     segment.start = 0;
133     segment.stop = 5 * 60 * GST_SECOND;
134     segment.time = 0;
135
136     segment.position = 2 * GST_SECOND;
137     segment.duration = 90 * 60 * GST_SECOND;
138
139     GST_LOG ("TIME: %" GST_SEGMENT_FORMAT, &segment);
140   }
141
142   /* BYTE segment */
143   {
144     GstSegment segment;
145
146     gst_segment_init (&segment, GST_FORMAT_BYTES);
147
148     segment.rate = 1.0;
149     segment.applied_rate = 1.0;
150     segment.start = 0;
151     segment.stop = 9999999;
152     segment.time = 0;
153
154     GST_LOG ("BYTE: %" GST_SEGMENT_FORMAT, &segment);
155   }
156
157   /* UNKNOWN format segment (format numbers are consecutive from 0) */
158   {
159     GstSegment segment;
160
161     gst_segment_init (&segment, 98765432);
162
163     segment.rate = 1.0;
164     segment.applied_rate = 1.0;
165     segment.start = 0;
166     segment.stop = 987654321;
167     segment.time = 0;
168
169     GST_LOG ("UNKNOWN: %" GST_SEGMENT_FORMAT, &segment);
170   }
171
172   /* UNDEFINED format segment */
173   {
174     GstSegment segment;
175
176     gst_segment_init (&segment, GST_FORMAT_UNDEFINED);
177
178     GST_LOG ("UNDEFINED: %" GST_SEGMENT_FORMAT, &segment);
179   }
180
181   /* NULL segment */
182   GST_LOG ("NULL: %" GST_SEGMENT_FORMAT, (GstSegment *) NULL);
183
184   /* clean up */
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);
188 }
189
190 GST_END_TEST;
191
192 GST_START_TEST (info_log_handler)
193 {
194   guint removed;
195
196   removed = gst_debug_remove_log_function (gst_debug_log_default);
197   fail_unless (removed == 1);
198 }
199
200 GST_END_TEST;
201
202 GST_START_TEST (info_dump_mem)
203 {
204   GstDebugCategory *cat = NULL;
205   GstElement *e;
206
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'
215   };
216
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);
225 }
226
227 GST_END_TEST;
228
229 GST_START_TEST (info_fixme)
230 {
231   GstDebugCategory *cat = NULL;
232   GstElement *e;
233
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);
241 }
242
243 GST_END_TEST;
244 #endif
245
246 static Suite *
247 gst_info_suite (void)
248 {
249   Suite *s = suite_create ("GstInfo");
250   TCase *tc_chain = tcase_create ("info");
251
252   tcase_set_timeout (tc_chain, 30);
253
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);
261 #endif
262
263   return s;
264 }
265
266 GST_CHECK_MAIN (gst_info);