From 9051371877cf22a7f26d23c2ec8beb56af7ea7f0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 22 Mar 2005 14:23:49 +0000 Subject: [PATCH] Activated more tests. Original commit message from CVS: * check/Makefile.am: * check/gst/gstmessage.c: (START_TEST), (gst_data_suite), (main): * gst/gststructure.c: (gst_structure_set_valist), (gst_structure_copy_conditional): Activated more tests. Added message test. Added G_TYPE_POINTER to GstStructure. --- ChangeLog | 11 +++ check/Makefile.am | 4 +- check/gst/gstmessage.c | 202 +++++++++++++++++++++++++++++++++++++++++++ gst/gststructure.c | 7 ++ tests/check/Makefile.am | 4 +- tests/check/gst/gstmessage.c | 202 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 428 insertions(+), 2 deletions(-) create mode 100644 check/gst/gstmessage.c create mode 100644 tests/check/gst/gstmessage.c diff --git a/ChangeLog b/ChangeLog index 82ddf75..c27b9d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2005-03-22 Wim Taymans + * check/Makefile.am: + * check/gst/gstmessage.c: (START_TEST), (gst_data_suite), (main): + * gst/gststructure.c: (gst_structure_set_valist), + (gst_structure_copy_conditional): + Activated more tests. + Added message test. + Added G_TYPE_POINTER to GstStructure. + + +2005-03-22 Wim Taymans + * docs/design/part-TODO.txt: * docs/design/part-events.txt: * docs/design/part-gstbin.txt: diff --git a/check/Makefile.am b/check/Makefile.am index 37b4525..e25ada7 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -20,11 +20,13 @@ CLEANFILES = core.* TESTS = $(top_builddir)/tools/gst-register-@GST_MAJORMINOR@ \ gst/gstbin \ - gst/gstbus \ + gst/gstbus \ gst/gstcaps \ gst/gstdata \ gst/gstiterator \ + gst/gstmessage \ gst/gstobject \ + gst/gstpad \ gst/gstsystemclock \ gst-libs/gdp diff --git a/check/gst/gstmessage.c b/check/gst/gstmessage.c new file mode 100644 index 0000000..84c0e8e --- /dev/null +++ b/check/gst/gstmessage.c @@ -0,0 +1,202 @@ +/* GStreamer + * + * unit test for GstMessage + * + * Copyright (C) <2005> Wim Taymans + * + * 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. + */ + +#include "../gstcheck.h" + +static GQuark domain; + +START_TEST (test_parsing) +{ + GstMessage *message; + + domain = g_quark_from_string ("test"); + + /* 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); + error = NULL; + debug = NULL; + 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); + gst_message_unref (message); + } + /* 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); + warning = NULL; + debug = NULL; + 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); + gst_message_unref (message); + } + /* 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); + } + /* GST_MESSAGE_BUFFERING */ + { + } + /* GST_MESSAGE_STATE_CHANGED */ + { + GstElementState oldstate, newstate; + + oldstate = GST_STATE_PAUSED; + newstate = GST_STATE_PLAYING; + + message = gst_message_new_state_changed (NULL, oldstate, newstate); + fail_if (message == NULL); + fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED); + fail_unless (GST_MESSAGE_SRC (message) == NULL); + + oldstate = GST_STATE_READY; + newstate = GST_STATE_READY; + gst_message_parse_state_changed (message, &oldstate, &newstate); + fail_unless (oldstate == GST_STATE_PAUSED); + fail_unless (newstate == GST_STATE_PLAYING); + + 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); + message = gst_message_new_application (structure); + 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); + void gst_message_parse_state_changed (GstMessage *message, GstElementState *old_state, + GstElementState *new_state); + void gst_message_parse_error (GstMessage *message, GError **gerror, gchar **debug); + void gst_message_parse_warning (GstMessage *message, GError **gerror, gchar **debug); + */ + + + +} + +END_TEST Suite * +gst_data_suite (void) +{ + 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; +} + +int +main (int argc, char **argv) +{ + int nf; + + Suite *s = gst_data_suite (); + SRunner *sr = srunner_create (s); + + gst_check_init (&argc, &argv); + + srunner_run_all (sr, CK_NORMAL); + nf = srunner_ntests_failed (sr); + srunner_free (sr); + + return nf; +} diff --git a/gst/gststructure.c b/gst/gststructure.c index cc3a590..3018a74 100644 --- a/gst/gststructure.c +++ b/gst/gststructure.c @@ -404,6 +404,7 @@ gst_structure_set_valist (GstStructure * structure, int i; double d; char *s; + gpointer p; g_return_if_fail (structure != NULL); g_return_if_fail (IS_MUTABLE (structure)); @@ -440,6 +441,12 @@ gst_structure_set_valist (GstStructure * structure, g_value_init (&field.value, G_TYPE_STRING); g_value_set_string (&field.value, s); break; + case G_TYPE_POINTER: + p = va_arg (varargs, gpointer); + + g_value_init (&field.value, G_TYPE_POINTER); + g_value_set_pointer (&field.value, p); + break; default: if (type == GST_TYPE_FOURCC) { i = va_arg (varargs, int); diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 37b4525..e25ada7 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -20,11 +20,13 @@ CLEANFILES = core.* TESTS = $(top_builddir)/tools/gst-register-@GST_MAJORMINOR@ \ gst/gstbin \ - gst/gstbus \ + gst/gstbus \ gst/gstcaps \ gst/gstdata \ gst/gstiterator \ + gst/gstmessage \ gst/gstobject \ + gst/gstpad \ gst/gstsystemclock \ gst-libs/gdp diff --git a/tests/check/gst/gstmessage.c b/tests/check/gst/gstmessage.c new file mode 100644 index 0000000..84c0e8e --- /dev/null +++ b/tests/check/gst/gstmessage.c @@ -0,0 +1,202 @@ +/* GStreamer + * + * unit test for GstMessage + * + * Copyright (C) <2005> Wim Taymans + * + * 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. + */ + +#include "../gstcheck.h" + +static GQuark domain; + +START_TEST (test_parsing) +{ + GstMessage *message; + + domain = g_quark_from_string ("test"); + + /* 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); + error = NULL; + debug = NULL; + 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); + gst_message_unref (message); + } + /* 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); + warning = NULL; + debug = NULL; + 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); + gst_message_unref (message); + } + /* 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); + } + /* GST_MESSAGE_BUFFERING */ + { + } + /* GST_MESSAGE_STATE_CHANGED */ + { + GstElementState oldstate, newstate; + + oldstate = GST_STATE_PAUSED; + newstate = GST_STATE_PLAYING; + + message = gst_message_new_state_changed (NULL, oldstate, newstate); + fail_if (message == NULL); + fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED); + fail_unless (GST_MESSAGE_SRC (message) == NULL); + + oldstate = GST_STATE_READY; + newstate = GST_STATE_READY; + gst_message_parse_state_changed (message, &oldstate, &newstate); + fail_unless (oldstate == GST_STATE_PAUSED); + fail_unless (newstate == GST_STATE_PLAYING); + + 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); + message = gst_message_new_application (structure); + 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); + void gst_message_parse_state_changed (GstMessage *message, GstElementState *old_state, + GstElementState *new_state); + void gst_message_parse_error (GstMessage *message, GError **gerror, gchar **debug); + void gst_message_parse_warning (GstMessage *message, GError **gerror, gchar **debug); + */ + + + +} + +END_TEST Suite * +gst_data_suite (void) +{ + 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; +} + +int +main (int argc, char **argv) +{ + int nf; + + Suite *s = gst_data_suite (); + SRunner *sr = srunner_create (s); + + gst_check_init (&argc, &argv); + + srunner_run_all (sr, CK_NORMAL); + nf = srunner_ntests_failed (sr); + srunner_free (sr); + + return nf; +} -- 2.7.4