2005-03-22 14:23:49 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* unit test for GstMessage
|
|
|
|
*
|
|
|
|
* Copyright (C) <2005> Wim Taymans <wim at fluendo dot com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2005-08-20 12:14:28 +00:00
|
|
|
#include <gst/check/gstcheck.h>
|
2005-03-22 14:23:49 +00:00
|
|
|
|
|
|
|
static GQuark domain;
|
|
|
|
|
2005-07-09 16:36:18 +00:00
|
|
|
GST_START_TEST (test_parsing)
|
2005-03-22 14:23:49 +00:00
|
|
|
{
|
|
|
|
GstMessage *message;
|
|
|
|
|
2007-11-17 17:50:21 +00:00
|
|
|
domain = g_quark_from_static_string ("test");
|
2005-03-22 14:23:49 +00:00
|
|
|
|
|
|
|
/* GST_MESSAGE_EOS */
|
|
|
|
{
|
|
|
|
message = gst_message_new_eos (NULL);
|
|
|
|
fail_if (message == NULL);
|
|
|
|
fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_EOS);
|
|
|
|
fail_unless (GST_MESSAGE_SRC (message) == NULL);
|
|
|
|
gst_message_unref (message);
|
|
|
|
}
|
|
|
|
/* GST_MESSAGE_ERROR */
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar *debug;
|
|
|
|
|
|
|
|
error = g_error_new (domain, 10, "test error");
|
|
|
|
fail_if (error == NULL);
|
|
|
|
message = gst_message_new_error (NULL, error, "error string");
|
|
|
|
fail_if (message == NULL);
|
|
|
|
fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
|
|
|
|
fail_unless (GST_MESSAGE_SRC (message) == NULL);
|
2005-07-12 16:28:36 +00:00
|
|
|
|
|
|
|
g_error_free (error);
|
2005-03-22 14:23:49 +00:00
|
|
|
error = NULL;
|
|
|
|
debug = NULL;
|
2005-07-12 16:28:36 +00:00
|
|
|
|
2005-03-22 14:23:49 +00:00
|
|
|
gst_message_parse_error (message, &error, &debug);
|
|
|
|
fail_if (error == NULL);
|
|
|
|
fail_if (debug == NULL);
|
|
|
|
fail_unless (strcmp (error->message, "test error") == 0);
|
|
|
|
fail_unless (error->domain == domain);
|
|
|
|
fail_unless (error->code == 10);
|
|
|
|
fail_unless (strcmp (debug, "error string") == 0);
|
2005-07-12 16:28:36 +00:00
|
|
|
|
2005-03-22 14:23:49 +00:00
|
|
|
gst_message_unref (message);
|
2005-07-12 16:28:36 +00:00
|
|
|
g_error_free (error);
|
|
|
|
g_free (debug);
|
2005-03-22 14:23:49 +00:00
|
|
|
}
|
|
|
|
/* GST_MESSAGE_WARNING */
|
|
|
|
{
|
|
|
|
GError *warning = NULL;
|
|
|
|
gchar *debug;
|
|
|
|
|
|
|
|
warning = g_error_new (domain, 10, "test warning");
|
|
|
|
fail_if (warning == NULL);
|
|
|
|
message = gst_message_new_warning (NULL, warning, "warning string");
|
|
|
|
fail_if (message == NULL);
|
|
|
|
fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
|
|
|
|
fail_unless (GST_MESSAGE_SRC (message) == NULL);
|
2005-07-12 16:28:36 +00:00
|
|
|
|
|
|
|
g_error_free (warning);
|
2005-03-22 14:23:49 +00:00
|
|
|
warning = NULL;
|
|
|
|
debug = NULL;
|
2005-07-12 16:28:36 +00:00
|
|
|
|
2005-03-22 14:23:49 +00:00
|
|
|
gst_message_parse_warning (message, &warning, &debug);
|
|
|
|
fail_if (warning == NULL);
|
|
|
|
fail_if (debug == NULL);
|
|
|
|
fail_unless (strcmp (warning->message, "test warning") == 0);
|
|
|
|
fail_unless (warning->domain == domain);
|
|
|
|
fail_unless (warning->code == 10);
|
|
|
|
fail_unless (strcmp (debug, "warning string") == 0);
|
2005-07-12 16:28:36 +00:00
|
|
|
|
2005-03-22 14:23:49 +00:00
|
|
|
gst_message_unref (message);
|
2005-07-12 16:28:36 +00:00
|
|
|
g_error_free (warning);
|
|
|
|
g_free (debug);
|
2005-03-22 14:23:49 +00:00
|
|
|
}
|
|
|
|
/* GST_MESSAGE_INFO */
|
|
|
|
{
|
|
|
|
}
|
|
|
|
/* GST_MESSAGE_TAG */
|
|
|
|
{
|
|
|
|
GstTagList *tag;
|
|
|
|
|
|
|
|
/* FIXME, do some more tag adding */
|
|
|
|
tag = gst_tag_list_new ();
|
|
|
|
fail_if (tag == NULL);
|
|
|
|
message = gst_message_new_tag (NULL, tag);
|
|
|
|
fail_if (message == NULL);
|
|
|
|
fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
|
|
|
|
fail_unless (GST_MESSAGE_SRC (message) == NULL);
|
|
|
|
tag = NULL;
|
|
|
|
gst_message_parse_tag (message, &tag);
|
|
|
|
fail_if (tag == NULL);
|
|
|
|
/* FIXME, check the actual tags */
|
|
|
|
gst_message_unref (message);
|
2005-07-12 16:28:36 +00:00
|
|
|
gst_tag_list_free (tag);
|
2005-03-22 14:23:49 +00:00
|
|
|
}
|
|
|
|
/* GST_MESSAGE_BUFFERING */
|
|
|
|
{
|
|
|
|
}
|
|
|
|
/* GST_MESSAGE_STATE_CHANGED */
|
|
|
|
{
|
2005-10-08 08:58:45 +00:00
|
|
|
GstState oldstate, newstate, pending;
|
2005-03-22 14:23:49 +00:00
|
|
|
|
|
|
|
oldstate = GST_STATE_PAUSED;
|
|
|
|
newstate = GST_STATE_PLAYING;
|
2005-10-08 08:58:45 +00:00
|
|
|
pending = GST_STATE_VOID_PENDING;
|
2005-03-22 14:23:49 +00:00
|
|
|
|
Seriously, this is better than a previous commit as we only need to notify the fact that an element changed state in ...
Original commit message from CVS:
* check/gst/gstbin.c: (GST_START_TEST):
* check/gst/gstmessage.c: (GST_START_TEST):
* check/gst/gstpipeline.c: (GST_START_TEST), (message_received):
* gst/gstbin.c: (gst_bin_class_init), (gst_bin_recalc_func),
(bin_bus_handler):
* gst/gstelement.c: (gst_element_abort_state),
(gst_element_commit_state), (gst_element_lost_state):
* gst/gstmessage.c: (gst_message_new_state_changed),
(gst_message_new_state_dirty), (gst_message_new_segment_start),
(gst_message_new_segment_done), (gst_message_new_duration),
(gst_message_parse_state_changed),
(gst_message_parse_segment_start),
(gst_message_parse_segment_done), (gst_message_parse_duration):
* gst/gstmessage.h:
* tools/gst-launch.c: (event_loop):
Seriously, this is better than a previous commit as we only need
to notify the fact that an element changed state in a streaming
thread, marking the state of the parents dirty, hence the
STATE_DIRTY message instead of abusing a boolean in a STATE_CHANGE
message.
2005-10-18 16:25:38 +00:00
|
|
|
message = gst_message_new_state_changed (NULL, oldstate, newstate, pending);
|
2005-03-22 14:23:49 +00:00
|
|
|
fail_if (message == NULL);
|
|
|
|
fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
|
|
|
|
fail_unless (GST_MESSAGE_SRC (message) == NULL);
|
|
|
|
|
2005-10-08 08:58:45 +00:00
|
|
|
/* set some wrong values to check if the parse method overwrites them
|
|
|
|
* with the good values */
|
2005-03-22 14:23:49 +00:00
|
|
|
oldstate = GST_STATE_READY;
|
|
|
|
newstate = GST_STATE_READY;
|
2005-10-08 08:58:45 +00:00
|
|
|
pending = GST_STATE_READY;
|
Seriously, this is better than a previous commit as we only need to notify the fact that an element changed state in ...
Original commit message from CVS:
* check/gst/gstbin.c: (GST_START_TEST):
* check/gst/gstmessage.c: (GST_START_TEST):
* check/gst/gstpipeline.c: (GST_START_TEST), (message_received):
* gst/gstbin.c: (gst_bin_class_init), (gst_bin_recalc_func),
(bin_bus_handler):
* gst/gstelement.c: (gst_element_abort_state),
(gst_element_commit_state), (gst_element_lost_state):
* gst/gstmessage.c: (gst_message_new_state_changed),
(gst_message_new_state_dirty), (gst_message_new_segment_start),
(gst_message_new_segment_done), (gst_message_new_duration),
(gst_message_parse_state_changed),
(gst_message_parse_segment_start),
(gst_message_parse_segment_done), (gst_message_parse_duration):
* gst/gstmessage.h:
* tools/gst-launch.c: (event_loop):
Seriously, this is better than a previous commit as we only need
to notify the fact that an element changed state in a streaming
thread, marking the state of the parents dirty, hence the
STATE_DIRTY message instead of abusing a boolean in a STATE_CHANGE
message.
2005-10-18 16:25:38 +00:00
|
|
|
gst_message_parse_state_changed (message, &oldstate, &newstate, &pending);
|
2005-03-22 14:23:49 +00:00
|
|
|
fail_unless (oldstate == GST_STATE_PAUSED);
|
|
|
|
fail_unless (newstate == GST_STATE_PLAYING);
|
2005-10-08 08:58:45 +00:00
|
|
|
fail_unless (pending == GST_STATE_VOID_PENDING);
|
2005-03-22 14:23:49 +00:00
|
|
|
|
|
|
|
gst_message_unref (message);
|
|
|
|
}
|
|
|
|
/* GST_MESSAGE_STEP_DONE */
|
|
|
|
{
|
|
|
|
}
|
|
|
|
/* GST_MESSAGE_NEW_CLOCK */
|
|
|
|
{
|
|
|
|
}
|
|
|
|
/* GST_MESSAGE_STRUCTURE_CHANGE */
|
|
|
|
{
|
|
|
|
}
|
|
|
|
/* GST_MESSAGE_STREAM_STATUS */
|
|
|
|
{
|
|
|
|
}
|
|
|
|
/* GST_MESSAGE_APPLICATION */
|
|
|
|
{
|
|
|
|
GstStructure *structure;
|
|
|
|
const GstStructure *struc;
|
|
|
|
gint some_int;
|
|
|
|
gdouble a_double;
|
|
|
|
|
|
|
|
structure = gst_structure_new ("test_struct",
|
|
|
|
"some_int", G_TYPE_INT, 10,
|
|
|
|
"a_double", G_TYPE_DOUBLE, (gdouble) 1.8, NULL);
|
|
|
|
fail_if (structure == NULL);
|
2005-07-05 08:47:40 +00:00
|
|
|
message = gst_message_new_application (NULL, structure);
|
2005-03-22 14:23:49 +00:00
|
|
|
fail_if (message == NULL);
|
|
|
|
struc = gst_message_get_structure (message);
|
|
|
|
fail_if (struc == NULL);
|
|
|
|
fail_unless (gst_structure_get_int (struc, "some_int", &some_int));
|
|
|
|
fail_unless (gst_structure_get_double (struc, "a_double", &a_double));
|
|
|
|
fail_unless (some_int == 10);
|
|
|
|
fail_unless (a_double == 1.8);
|
|
|
|
|
|
|
|
gst_message_unref (message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
void gst_message_parse_tag (GstMessage *message, GstTagList **tag_list);
|
2005-09-02 15:42:00 +00:00
|
|
|
void gst_message_parse_state_changed (GstMessage *message, GstState *old_state,
|
|
|
|
GstState *new_state);
|
2005-03-22 14:23:49 +00:00
|
|
|
void gst_message_parse_error (GstMessage *message, GError **gerror, gchar **debug);
|
|
|
|
void gst_message_parse_warning (GstMessage *message, GError **gerror, gchar **debug);
|
|
|
|
*/
|
|
|
|
|
2009-02-18 14:31:55 +00:00
|
|
|
/* GST_MESSAGE_REQUEST_STATE */
|
|
|
|
{
|
|
|
|
GstState state;
|
2005-03-22 14:23:49 +00:00
|
|
|
|
2009-02-18 14:31:55 +00:00
|
|
|
state = GST_STATE_PAUSED;
|
2005-03-22 14:23:49 +00:00
|
|
|
|
2009-02-18 14:31:55 +00:00
|
|
|
message = gst_message_new_request_state (NULL, state);
|
|
|
|
fail_if (message == NULL);
|
|
|
|
fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REQUEST_STATE);
|
|
|
|
fail_unless (GST_MESSAGE_SRC (message) == NULL);
|
|
|
|
|
|
|
|
/* set some wrong values to check if the parse method overwrites them
|
|
|
|
* with the good values */
|
|
|
|
state = GST_STATE_READY;
|
|
|
|
gst_message_parse_request_state (message, &state);
|
|
|
|
fail_unless (state == GST_STATE_PAUSED);
|
|
|
|
|
|
|
|
gst_message_unref (message);
|
|
|
|
}
|
2005-03-22 14:23:49 +00:00
|
|
|
}
|
|
|
|
|
2006-07-01 20:56:56 +00:00
|
|
|
GST_END_TEST;
|
|
|
|
|
2008-02-29 13:59:24 +00:00
|
|
|
static Suite *
|
2006-07-01 20:56:56 +00:00
|
|
|
gst_message_suite (void)
|
2005-03-22 14:23:49 +00:00
|
|
|
{
|
|
|
|
Suite *s = suite_create ("GstMessage");
|
|
|
|
TCase *tc_chain = tcase_create ("general");
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc_chain);
|
|
|
|
tcase_add_test (tc_chain, test_parsing);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2006-07-01 20:56:56 +00:00
|
|
|
GST_CHECK_MAIN (gst_message);
|