diff --git a/ChangeLog b/ChangeLog index f977f8b963..9dcdf81713 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2006-05-10 Thomas Vander Stichele + + * gst/gstevent.c: (_gst_event_initialize): + * gst/gstformat.c: (_gst_format_initialize): + make sure some essential types used by events are registered + as part of gst_init() + * gst/gstvalue.c: (gst_value_serialize_flags): + if no flags are set, serialize them to a value that represents NONE + so that deserializing them works + * tests/check/gst/gstvalue.c: (GST_START_TEST), (gst_value_suite): + add tests for serialization and deserialization of flags + 2006-05-10 Wim Taymans * libs/gst/base/gstcollectpads.c: (gst_collect_pads_collect), diff --git a/gst/gstevent.c b/gst/gstevent.c index c9ffbe91fd..ab7f6b8066 100644 --- a/gst/gstevent.c +++ b/gst/gstevent.c @@ -93,6 +93,8 @@ void _gst_event_initialize (void) { gst_event_get_type (); + gst_seek_flags_get_type (); + gst_seek_type_get_type (); } typedef struct diff --git a/gst/gstformat.c b/gst/gstformat.c index 3ae8f3eb26..3e00061c72 100644 --- a/gst/gstformat.c +++ b/gst/gstformat.c @@ -35,6 +35,7 @@ #include "gst_private.h" #include #include "gstformat.h" +#include "gstenumtypes.h" static GStaticMutex mutex = G_STATIC_MUTEX_INIT; static GList *_gst_formats = NULL; @@ -72,6 +73,8 @@ _gst_format_initialize (void) standards++; _n_values++; } + /* getting the type registers the enum */ + gst_format_get_type (); g_static_mutex_unlock (&mutex); } diff --git a/gst/gstvalue.c b/gst/gstvalue.c index 8d7e4b3301..deb9a32dae 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -1921,6 +1921,14 @@ gst_value_serialize_flags (const GValue * value) result = g_strdup (""); flags = g_value_get_flags (value); + + /* if no flags are set, try to serialize to the _NONE string */ + if (!flags) { + fl = gst_flags_get_first_value (klass, flags); + return g_strdup (fl->value_name); + } + + /* some flags are set, so serialize one by one */ while (flags) { fl = gst_flags_get_first_value (klass, flags); if (fl != NULL) { diff --git a/tests/check/gst/gstvalue.c b/tests/check/gst/gstvalue.c index 6b4ddf1ba0..066abd790b 100644 --- a/tests/check/gst/gstvalue.c +++ b/tests/check/gst/gstvalue.c @@ -319,6 +319,69 @@ GST_START_TEST (test_deserialize_guint_failures) GST_END_TEST; +GST_START_TEST (test_serialize_flags) +{ + GValue value = { 0 }; + gchar *string; + GstSeekFlags flags[] = { + 0, + GST_SEEK_FLAG_NONE, + GST_SEEK_FLAG_FLUSH, + GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, + }; + const char *results[] = { + "GST_SEEK_FLAG_NONE", + "GST_SEEK_FLAG_NONE", + "GST_SEEK_FLAG_FLUSH", + "GST_SEEK_FLAG_FLUSH+GST_SEEK_FLAG_ACCURATE", + }; + int i; + + g_value_init (&value, GST_TYPE_SEEK_FLAGS); + + for (i = 0; i < G_N_ELEMENTS (flags); ++i) { + g_value_set_flags (&value, flags[i]); + string = gst_value_serialize (&value); + fail_if (string == NULL, "could not serialize flags %d", i); + fail_unless (strcmp (string, results[i]) == 0, + "resulting value is %s, not %s, for flags #%d", string, results[i], i); + } +} + +GST_END_TEST; + + +GST_START_TEST (test_deserialize_flags) +{ + GValue value = { 0 }; + const char *strings[] = { + "", + "0", + "GST_SEEK_FLAG_NONE", + "GST_SEEK_FLAG_FLUSH", + "GST_SEEK_FLAG_FLUSH+GST_SEEK_FLAG_ACCURATE", + }; + GstSeekFlags results[] = { + GST_SEEK_FLAG_NONE, + GST_SEEK_FLAG_NONE, + GST_SEEK_FLAG_NONE, + GST_SEEK_FLAG_FLUSH, + GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, + }; + int i; + + g_value_init (&value, GST_TYPE_SEEK_FLAGS); + + for (i = 0; i < G_N_ELEMENTS (strings); ++i) { + fail_unless (gst_value_deserialize (&value, strings[i]), + "could not deserialize %s (%d)", strings[i], i); + fail_unless (g_value_get_flags (&value) == results[i], + "resulting value is %d, not %d, for string %s (%d)", + g_value_get_flags (&value), results[i], strings[i], i); + } +} + +GST_END_TEST; GST_START_TEST (test_string) { @@ -1431,6 +1494,8 @@ gst_value_suite (void) tcase_add_test (tc_chain, test_deserialize_guint_failures); tcase_add_test (tc_chain, test_deserialize_gint64); tcase_add_test (tc_chain, test_deserialize_gstfraction); + tcase_add_test (tc_chain, test_serialize_flags); + tcase_add_test (tc_chain, test_deserialize_flags); tcase_add_test (tc_chain, test_string); tcase_add_test (tc_chain, test_deserialize_string); tcase_add_test (tc_chain, test_value_compare);