[glib] gbinding: warn on failed value transformation
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gbinding: warn on failed value transformation
- Date: Mon, 17 Mar 2014 21:43:22 +0000 (UTC)
commit d8c14f1378b9b5362e84220cf52415c316534a9a
Author: Dan Winship <danw gnome org>
Date: Mon Mar 17 15:11:31 2014 -0400
gbinding: warn on failed value transformation
GBinding warned if g_value_transform() returned FALSE, but it didn't
warn if there was no transformation available at all. Fix that and
test it.
https://bugzilla.gnome.org/show_bug.cgi?id=726574
gobject/gbinding.c | 14 +++++++-------
gobject/tests/binding.c | 24 ++++++++++++++++++++++++
2 files changed, 31 insertions(+), 7 deletions(-)
---
diff --git a/gobject/gbinding.c b/gobject/gbinding.c
index 0e17b89..2237e5e 100644
--- a/gobject/gbinding.c
+++ b/gobject/gbinding.c
@@ -294,15 +294,15 @@ default_transform (const GValue *value_a,
{
if (g_value_transform (value_a, value_b))
goto done;
+ }
- g_warning ("%s: Unable to convert a value of type %s to a "
- "value of type %s",
- G_STRLOC,
- g_type_name (G_VALUE_TYPE (value_a)),
- g_type_name (G_VALUE_TYPE (value_b)));
+ g_warning ("%s: Unable to convert a value of type %s to a "
+ "value of type %s",
+ G_STRLOC,
+ g_type_name (G_VALUE_TYPE (value_a)),
+ g_type_name (G_VALUE_TYPE (value_b)));
- return FALSE;
- }
+ return FALSE;
}
else
g_value_copy (value_a, value_b);
diff --git a/gobject/tests/binding.c b/gobject/tests/binding.c
index 5f87e84..f79640b 100644
--- a/gobject/tests/binding.c
+++ b/gobject/tests/binding.c
@@ -612,6 +612,29 @@ binding_unbind (void)
g_object_unref (target);
}
+static void
+binding_fail (void)
+{
+ BindingSource *source = g_object_new (binding_source_get_type (), NULL);
+ BindingTarget *target = g_object_new (binding_target_get_type (), NULL);
+ GBinding *binding;
+
+ /* double -> boolean is not supported */
+ binding = g_object_bind_property (source, "value",
+ target, "toggle",
+ G_BINDING_DEFAULT);
+ g_object_add_weak_pointer (G_OBJECT (binding), (gpointer *) &binding);
+
+ g_test_expect_message ("GLib-GObject", G_LOG_LEVEL_WARNING,
+ "*Unable to convert*double*boolean*");
+ g_object_set (source, "value", 1.0, NULL);
+ g_test_assert_expected_messages ();
+
+ g_object_unref (source);
+ g_object_unref (target);
+ g_assert (binding == NULL);
+}
+
int
main (int argc, char *argv[])
{
@@ -629,6 +652,7 @@ main (int argc, char *argv[])
g_test_add_func ("/binding/invert-boolean", binding_invert_boolean);
g_test_add_func ("/binding/same-object", binding_same_object);
g_test_add_func ("/binding/unbind", binding_unbind);
+ g_test_add_func ("/binding/fail", binding_fail);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]