3 * unit test for GstMessage
5 * Copyright (C) <2005> Wim Taymans <wim at fluendo dot com>
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>
27 GST_START_TEST (test_parsing)
31 domain = g_quark_from_static_string ("test");
35 message = gst_message_new_eos (NULL);
36 fail_if (message == NULL);
37 fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_EOS);
38 fail_unless (GST_MESSAGE_SRC (message) == NULL);
39 gst_message_unref (message);
41 /* GST_MESSAGE_ERROR */
46 error = g_error_new (domain, 10, "test error");
47 fail_if (error == NULL);
48 message = gst_message_new_error (NULL, error, "error string");
49 fail_if (message == NULL);
50 fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
51 fail_unless (GST_MESSAGE_SRC (message) == NULL);
57 gst_message_parse_error (message, &error, &debug);
58 fail_if (error == NULL);
59 fail_if (debug == NULL);
60 fail_unless (strcmp (error->message, "test error") == 0);
61 fail_unless (error->domain == domain);
62 fail_unless (error->code == 10);
63 fail_unless (strcmp (debug, "error string") == 0);
65 gst_message_unref (message);
69 /* GST_MESSAGE_WARNING */
71 GError *warning = NULL;
74 warning = g_error_new (domain, 10, "test warning");
75 fail_if (warning == NULL);
76 message = gst_message_new_warning (NULL, warning, "warning string");
77 fail_if (message == NULL);
78 fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
79 fail_unless (GST_MESSAGE_SRC (message) == NULL);
81 g_error_free (warning);
85 gst_message_parse_warning (message, &warning, &debug);
86 fail_if (warning == NULL);
87 fail_if (debug == NULL);
88 fail_unless (strcmp (warning->message, "test warning") == 0);
89 fail_unless (warning->domain == domain);
90 fail_unless (warning->code == 10);
91 fail_unless (strcmp (debug, "warning string") == 0);
93 gst_message_unref (message);
94 g_error_free (warning);
97 /* GST_MESSAGE_INFO */
100 /* GST_MESSAGE_TAG */
104 /* FIXME, do some more tag adding */
105 tag = gst_tag_list_new ();
106 fail_if (tag == NULL);
107 message = gst_message_new_tag (NULL, tag);
108 fail_if (message == NULL);
109 fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
110 fail_unless (GST_MESSAGE_SRC (message) == NULL);
112 gst_message_parse_tag (message, &tag);
113 fail_if (tag == NULL);
114 /* FIXME, check the actual tags */
115 gst_message_unref (message);
116 gst_tag_list_free (tag);
118 /* GST_MESSAGE_BUFFERING */
121 /* GST_MESSAGE_STATE_CHANGED */
123 GstState oldstate, newstate, pending;
125 oldstate = GST_STATE_PAUSED;
126 newstate = GST_STATE_PLAYING;
127 pending = GST_STATE_VOID_PENDING;
129 message = gst_message_new_state_changed (NULL, oldstate, newstate, pending);
130 fail_if (message == NULL);
131 fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
132 fail_unless (GST_MESSAGE_SRC (message) == NULL);
134 /* set some wrong values to check if the parse method overwrites them
135 * with the good values */
136 oldstate = GST_STATE_READY;
137 newstate = GST_STATE_READY;
138 pending = GST_STATE_READY;
139 gst_message_parse_state_changed (message, &oldstate, &newstate, &pending);
140 fail_unless (oldstate == GST_STATE_PAUSED);
141 fail_unless (newstate == GST_STATE_PLAYING);
142 fail_unless (pending == GST_STATE_VOID_PENDING);
144 gst_message_unref (message);
146 /* GST_MESSAGE_STEP_DONE */
149 /* GST_MESSAGE_NEW_CLOCK */
152 /* GST_MESSAGE_STRUCTURE_CHANGE */
155 /* GST_MESSAGE_STREAM_STATUS */
158 /* GST_MESSAGE_APPLICATION */
160 GstStructure *structure;
161 const GstStructure *struc;
165 structure = gst_structure_new ("test_struct",
166 "some_int", G_TYPE_INT, 10,
167 "a_double", G_TYPE_DOUBLE, (gdouble) 1.8, NULL);
168 fail_if (structure == NULL);
169 message = gst_message_new_application (NULL, structure);
170 fail_if (message == NULL);
171 struc = gst_message_get_structure (message);
172 fail_if (struc == NULL);
173 fail_unless (gst_structure_get_int (struc, "some_int", &some_int));
174 fail_unless (gst_structure_get_double (struc, "a_double", &a_double));
175 fail_unless (some_int == 10);
176 fail_unless (a_double == 1.8);
178 gst_message_unref (message);
182 void gst_message_parse_tag (GstMessage *message, GstTagList **tag_list);
183 void gst_message_parse_state_changed (GstMessage *message, GstState *old_state,
184 GstState *new_state);
185 void gst_message_parse_error (GstMessage *message, GError **gerror, gchar **debug);
186 void gst_message_parse_warning (GstMessage *message, GError **gerror, gchar **debug);
189 /* GST_MESSAGE_STREAM_STATUS */
191 GstStreamStatusType type;
192 GstTask *task, *task2;
193 GValue value = { 0 };
197 gst_message_new_stream_status (NULL, GST_STREAM_STATUS_TYPE_ENTER,
199 fail_if (message == NULL);
200 fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
201 fail_unless (GST_MESSAGE_SRC (message) == NULL);
203 /* set some wrong values to check if the parse method overwrites them
204 * with the good values */
205 type = GST_STREAM_STATUS_TYPE_START;
206 gst_message_parse_stream_status (message, &type, NULL);
207 fail_unless (type == GST_STREAM_STATUS_TYPE_ENTER);
209 /* create a task with some dummy function, we're not actually going to run
211 task = gst_task_create ((GstTaskFunction) gst_object_unref, NULL);
213 ASSERT_OBJECT_REFCOUNT (task, "task", 1);
216 g_value_init (&value, GST_TYPE_TASK);
217 g_value_set_object (&value, task);
219 ASSERT_OBJECT_REFCOUNT (task, "task", 2);
221 gst_message_set_stream_status_object (message, &value);
222 ASSERT_OBJECT_REFCOUNT (task, "task", 3);
223 g_value_unset (&value);
224 ASSERT_OBJECT_REFCOUNT (task, "task", 2);
225 gst_object_unref (task);
226 ASSERT_OBJECT_REFCOUNT (task, "task", 1);
228 /* get the object back, no refcount is changed */
229 val = gst_message_get_stream_status_object (message);
230 ASSERT_OBJECT_REFCOUNT (task, "task", 1);
232 task2 = g_value_get_object (val);
234 fail_unless (GST_IS_TASK (task2));
235 fail_unless (task2 == task);
237 ASSERT_OBJECT_REFCOUNT (task, "task", 1);
238 ASSERT_OBJECT_REFCOUNT (task2, "task", 1);
240 gst_message_unref (message);
243 /* GST_MESSAGE_REQUEST_STATE */
247 state = GST_STATE_PAUSED;
249 message = gst_message_new_request_state (NULL, state);
250 fail_if (message == NULL);
251 fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REQUEST_STATE);
252 fail_unless (GST_MESSAGE_SRC (message) == NULL);
254 /* set some wrong values to check if the parse method overwrites them
255 * with the good values */
256 state = GST_STATE_READY;
257 gst_message_parse_request_state (message, &state);
258 fail_unless (state == GST_STATE_PAUSED);
260 gst_message_unref (message);
262 /* GST_MESSAGE_QOS */
265 GstClockTime running_time;
266 GstClockTime stream_time;
267 GstClockTime timestamp, duration;
275 running_time = 1 * GST_SECOND;
276 stream_time = 2 * GST_SECOND;
277 timestamp = 3 * GST_SECOND;
278 duration = 4 * GST_SECOND;
281 gst_message_new_qos (NULL, TRUE, running_time, stream_time, timestamp,
283 fail_if (message == NULL);
284 fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
285 fail_unless (GST_MESSAGE_SRC (message) == NULL);
288 gst_message_parse_qos_values (message, &jitter, &proportion, &quality);
289 fail_unless (jitter == 0);
290 fail_unless (proportion == 1.0);
291 fail_unless (quality == 1000000);
293 gst_message_parse_qos_stats (message, &format, &processed, &dropped);
294 fail_unless (format == GST_FORMAT_UNDEFINED);
295 fail_unless (processed == -1);
296 fail_unless (dropped == -1);
298 /* set some wrong values to check if the parse method overwrites them
299 * with the good values */
300 running_time = stream_time = timestamp = duration = 5 * GST_SECOND;
302 gst_message_parse_qos (message, &live, &running_time, &stream_time,
303 ×tamp, &duration);
304 fail_unless (live == TRUE);
305 fail_unless (running_time == 1 * GST_SECOND);
306 fail_unless (stream_time == 2 * GST_SECOND);
307 fail_unless (timestamp == 3 * GST_SECOND);
308 fail_unless (duration == 4 * GST_SECOND);
310 /* change some values */
311 gst_message_set_qos_values (message, -10, 2.0, 5000);
312 gst_message_parse_qos_values (message, &jitter, &proportion, &quality);
313 fail_unless (jitter == -10);
314 fail_unless (proportion == 2.0);
315 fail_unless (quality == 5000);
317 gst_message_set_qos_stats (message, GST_FORMAT_DEFAULT, 1030, 65);
318 gst_message_parse_qos_stats (message, &format, &processed, &dropped);
319 fail_unless (format == GST_FORMAT_DEFAULT);
320 fail_unless (processed == 1030);
321 fail_unless (dropped == 65);
323 gst_message_unref (message);
325 /* GST_MESSAGE_PROGRESS */
327 GstProgressType type;
328 gchar *category, *text;
331 gst_message_new_progress (NULL, GST_PROGRESS_TYPE_START, "connecting",
332 "Connecting to youtbue.com");
333 fail_if (message == NULL);
334 fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_PROGRESS);
335 fail_unless (GST_MESSAGE_SRC (message) == NULL);
337 /* set some wrong values to check if the parse method overwrites them
338 * with the good values */
339 type = GST_PROGRESS_TYPE_ERROR;
340 gst_message_parse_progress (message, &type, &category, &text);
341 fail_unless (type == GST_PROGRESS_TYPE_START);
342 fail_unless (!strcmp (category, "connecting"));
343 fail_unless (!strcmp (text, "Connecting to youtbue.com"));
347 gst_message_unref (message);
354 gst_message_suite (void)
356 Suite *s = suite_create ("GstMessage");
357 TCase *tc_chain = tcase_create ("general");
359 suite_add_tcase (s, tc_chain);
360 tcase_add_test (tc_chain, test_parsing);
365 GST_CHECK_MAIN (gst_message);