[glib] tests: Add a chain binding



commit f72f65643fb1d832e8296b26cff77dedbdac310f
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Wed Jun 16 14:47:06 2010 +0100

    tests: Add a chain binding
    
    Test the case with a chain like A â?? B, B â?? C, and what happens when
    switching to a direct A â?? C link.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=621782

 gobject/tests/binding.c |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/gobject/tests/binding.c b/gobject/tests/binding.c
index 15036fa..eef4590 100644
--- a/gobject/tests/binding.c
+++ b/gobject/tests/binding.c
@@ -312,6 +312,40 @@ binding_transform (void)
   g_object_unref (target);
 }
 
+static void
+binding_chain (void)
+{
+  BindingSource *a = g_object_new (binding_source_get_type (), NULL);
+  BindingSource *b = g_object_new (binding_source_get_type (), NULL);
+  BindingSource *c = g_object_new (binding_source_get_type (), NULL);
+  GBinding *binding_1, *binding_2;
+
+  /* A -> B, B -> C */
+  binding_1 = g_object_bind_property (a, "foo", b, "foo", G_BINDING_BIDIRECTIONAL);
+  binding_2 = g_object_bind_property (b, "foo", c, "foo", G_BINDING_BIDIRECTIONAL);
+
+  /* verify the chain */
+  g_object_set (a, "foo", 42, NULL);
+  g_assert_cmpint (a->foo, ==, b->foo);
+  g_assert_cmpint (b->foo, ==, c->foo);
+
+  /* unbind A -> B and B -> C */
+  g_object_unref (binding_1);
+  g_object_unref (binding_2);
+
+  /* bind A -> C directly */
+  binding_2 = g_object_bind_property (a, "foo", c, "foo", G_BINDING_BIDIRECTIONAL);
+
+  /* verify the chain is broken */
+  g_object_set (a, "foo", 47, NULL);
+  g_assert_cmpint (a->foo, !=, b->foo);
+  g_assert_cmpint (a->foo, ==, c->foo);
+
+  g_object_unref (a);
+  g_object_unref (b);
+  g_object_unref (c);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -321,6 +355,7 @@ main (int argc, char *argv[])
   g_test_add_func ("/binding/default", binding_default);
   g_test_add_func ("/binding/bidirectional", binding_bidirectional);
   g_test_add_func ("/binding/transform", binding_transform);
+  g_test_add_func ("/binding/chain", binding_chain);
 
   return g_test_run ();
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]