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_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 GstElementState oldstate, newstate;
125 oldstate = GST_STATE_PAUSED;
126 newstate = GST_STATE_PLAYING;
128 message = gst_message_new_state_changed (NULL, oldstate, newstate);
129 fail_if (message == NULL);
130 fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
131 fail_unless (GST_MESSAGE_SRC (message) == NULL);
133 oldstate = GST_STATE_READY;
134 newstate = GST_STATE_READY;
135 gst_message_parse_state_changed (message, &oldstate, &newstate);
136 fail_unless (oldstate == GST_STATE_PAUSED);
137 fail_unless (newstate == GST_STATE_PLAYING);
139 gst_message_unref (message);
141 /* GST_MESSAGE_STEP_DONE */
144 /* GST_MESSAGE_NEW_CLOCK */
147 /* GST_MESSAGE_STRUCTURE_CHANGE */
150 /* GST_MESSAGE_STREAM_STATUS */
153 /* GST_MESSAGE_APPLICATION */
155 GstStructure *structure;
156 const GstStructure *struc;
160 structure = gst_structure_new ("test_struct",
161 "some_int", G_TYPE_INT, 10,
162 "a_double", G_TYPE_DOUBLE, (gdouble) 1.8, NULL);
163 fail_if (structure == NULL);
164 message = gst_message_new_application (NULL, structure);
165 fail_if (message == NULL);
166 struc = gst_message_get_structure (message);
167 fail_if (struc == NULL);
168 fail_unless (gst_structure_get_int (struc, "some_int", &some_int));
169 fail_unless (gst_structure_get_double (struc, "a_double", &a_double));
170 fail_unless (some_int == 10);
171 fail_unless (a_double == 1.8);
173 gst_message_unref (message);
177 void gst_message_parse_tag (GstMessage *message, GstTagList **tag_list);
178 void gst_message_parse_state_changed (GstMessage *message, GstElementState *old_state,
179 GstElementState *new_state);
180 void gst_message_parse_error (GstMessage *message, GError **gerror, gchar **debug);
181 void gst_message_parse_warning (GstMessage *message, GError **gerror, gchar **debug);
189 gst_data_suite (void)
191 Suite *s = suite_create ("GstMessage");
192 TCase *tc_chain = tcase_create ("general");
194 suite_add_tcase (s, tc_chain);
195 tcase_add_test (tc_chain, test_parsing);
201 main (int argc, char **argv)
205 Suite *s = gst_data_suite ();
206 SRunner *sr = srunner_create (s);
208 gst_check_init (&argc, &argv);
210 srunner_run_all (sr, CK_NORMAL);
211 nf = srunner_ntests_failed (sr);