diff --git a/ChangeLog b/ChangeLog index 8aa6bac38a..4553b958cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ (gst_value_serialize_enum), (gst_value_deserialize_enum), (gst_value_can_compare), (gst_value_compare): * testsuite/Makefile.am: + * testsuite/enumcaps/Makefile.am: + * testsuite/enumcaps/enumcaps.c: Fix enum serialization, deserialization, comparison in caps, add a test to ensure that this continues working in the future. diff --git a/tests/old/testsuite/enumcaps/Makefile.am b/tests/old/testsuite/enumcaps/Makefile.am new file mode 100644 index 0000000000..8d12cd0104 --- /dev/null +++ b/tests/old/testsuite/enumcaps/Makefile.am @@ -0,0 +1,7 @@ +include ../Rules + +tests_pass = enumcaps +tests_fail = +tests_ignore = + + diff --git a/tests/old/testsuite/enumcaps/enumcaps.c b/tests/old/testsuite/enumcaps/enumcaps.c new file mode 100644 index 0000000000..7585333733 --- /dev/null +++ b/tests/old/testsuite/enumcaps/enumcaps.c @@ -0,0 +1,95 @@ +/* GStreamer test + * (c) 2004 Ronald Bultje + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +typedef enum +{ + TEST_YES, + TEST_NO +} +TestBool; + +#define TEST_BOOL_TYPE (test_bool_get_type ()) +GType +test_bool_get_type (void) +{ + static GType etype = 0; + + if (etype == 0) { + static const GEnumValue values[] = { + {TEST_YES, "TEST_YES", "yes"}, + {TEST_NO, "TEST_NO", "no"}, + {0, NULL, NULL} + }; + + etype = g_enum_register_static ("TestBool", values); + } + return etype; +} + +gint +main (gint argc, gchar * argv[]) +{ + gchar *str; + GstCaps *caps, *res_caps; + GstStructure *strc; + GValue value = { 0 }; + TestBool yes, no; + + /* register multichannel type */ + gst_init (&argc, &argv); + test_bool_get_type (); + + /* test some caps */ + caps = gst_caps_new_simple ("application/x-gst-test", NULL); + str = gst_caps_to_string (caps); + g_assert (str); + g_free (str); + + /* set enums in list */ + strc = gst_caps_get_structure (caps, 0); + g_value_init (&value, TEST_BOOL_TYPE); + g_value_set_enum (&value, TEST_YES); + gst_structure_set_value (strc, "yes", &value); + g_value_set_enum (&value, TEST_NO); + gst_structure_set_value (strc, "no", &value); + g_value_unset (&value); + + /* test to-/from-string conversions for enums */ + str = gst_caps_to_string (caps); + g_assert (str); + res_caps = gst_caps_from_string (str); + g_free (str); + + /* see if all worked */ + strc = gst_caps_get_structure (res_caps, 0); + yes = g_value_get_enum (gst_structure_get_value (strc, "yes")); + no = g_value_get_enum (gst_structure_get_value (strc, "no")); + g_assert (yes == TEST_YES && no == TEST_NO); + gst_caps_free (caps); + gst_caps_free (res_caps); + + /* yes */ + return 0; +} diff --git a/testsuite/enumcaps/Makefile.am b/testsuite/enumcaps/Makefile.am new file mode 100644 index 0000000000..8d12cd0104 --- /dev/null +++ b/testsuite/enumcaps/Makefile.am @@ -0,0 +1,7 @@ +include ../Rules + +tests_pass = enumcaps +tests_fail = +tests_ignore = + + diff --git a/testsuite/enumcaps/enumcaps.c b/testsuite/enumcaps/enumcaps.c new file mode 100644 index 0000000000..7585333733 --- /dev/null +++ b/testsuite/enumcaps/enumcaps.c @@ -0,0 +1,95 @@ +/* GStreamer test + * (c) 2004 Ronald Bultje + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +typedef enum +{ + TEST_YES, + TEST_NO +} +TestBool; + +#define TEST_BOOL_TYPE (test_bool_get_type ()) +GType +test_bool_get_type (void) +{ + static GType etype = 0; + + if (etype == 0) { + static const GEnumValue values[] = { + {TEST_YES, "TEST_YES", "yes"}, + {TEST_NO, "TEST_NO", "no"}, + {0, NULL, NULL} + }; + + etype = g_enum_register_static ("TestBool", values); + } + return etype; +} + +gint +main (gint argc, gchar * argv[]) +{ + gchar *str; + GstCaps *caps, *res_caps; + GstStructure *strc; + GValue value = { 0 }; + TestBool yes, no; + + /* register multichannel type */ + gst_init (&argc, &argv); + test_bool_get_type (); + + /* test some caps */ + caps = gst_caps_new_simple ("application/x-gst-test", NULL); + str = gst_caps_to_string (caps); + g_assert (str); + g_free (str); + + /* set enums in list */ + strc = gst_caps_get_structure (caps, 0); + g_value_init (&value, TEST_BOOL_TYPE); + g_value_set_enum (&value, TEST_YES); + gst_structure_set_value (strc, "yes", &value); + g_value_set_enum (&value, TEST_NO); + gst_structure_set_value (strc, "no", &value); + g_value_unset (&value); + + /* test to-/from-string conversions for enums */ + str = gst_caps_to_string (caps); + g_assert (str); + res_caps = gst_caps_from_string (str); + g_free (str); + + /* see if all worked */ + strc = gst_caps_get_structure (res_caps, 0); + yes = g_value_get_enum (gst_structure_get_value (strc, "yes")); + no = g_value_get_enum (gst_structure_get_value (strc, "no")); + g_assert (yes == TEST_YES && no == TEST_NO); + gst_caps_free (caps); + gst_caps_free (res_caps); + + /* yes */ + return 0; +}