From ed130c8d3bb73bea773448441de2f8c9c8ff75f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 8 Jul 2022 23:45:24 +0200 Subject: [PATCH 1/2] gobject/tests/custom-dispatch: Mark the foo property as explicit-notify We're calling g_object_notify so let's not make gobject to call it for us. This also allows to test that changing a property again doesn't lead to dispatch properties being called. --- gobject/tests/custom-dispatch.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gobject/tests/custom-dispatch.c b/gobject/tests/custom-dispatch.c index 3c6c1b8f4..ae56c0ae5 100644 --- a/gobject/tests/custom-dispatch.c +++ b/gobject/tests/custom-dispatch.c @@ -114,7 +114,9 @@ test_object_class_init (TestObjectClass *klass) properties[PROP_FOO] = g_param_spec_int ("foo", "Foo", "Foo", -1, G_MAXINT, 0, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS | + G_PARAM_EXPLICIT_NOTIFY); gobject_class->set_property = test_object_set_property; gobject_class->get_property = test_object_get_property; @@ -157,6 +159,8 @@ test_custom_dispatch (void) g_assert_cmpint (dispatch_properties_called, ==, 0); g_object_set (obj, "foo", 11, NULL); g_assert_cmpint (dispatch_properties_called, ==, 1); + g_object_set (obj, "foo", 11, NULL); + g_assert_cmpint (dispatch_properties_called, ==, 1); g_object_unref (obj); } From 28dc989fc14637ba9c665afe61f450f711f40314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 8 Jul 2022 23:50:48 +0200 Subject: [PATCH 2/2] gobject/tests: Add test to verify that custom dispatch is called on init As per this, rename the old test so that it's more in line with the new one and with what it does. --- gobject/tests/custom-dispatch.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/gobject/tests/custom-dispatch.c b/gobject/tests/custom-dispatch.c index ae56c0ae5..64120d269 100644 --- a/gobject/tests/custom-dispatch.c +++ b/gobject/tests/custom-dispatch.c @@ -139,6 +139,26 @@ object_has_notify_signal_handlers (gpointer instance) return g_signal_handler_find (instance, G_SIGNAL_MATCH_ID, signal_id, 0, NULL, NULL, NULL) != 0; } +static void +test_custom_dispatch_init (void) +{ + TestObject *obj; + + g_test_summary ("Test that custom dispatch_properties_changed is called " + "on initialization"); + + dispatch_properties_called = 0; + obj = g_object_new (test_object_get_type (), "foo", 5, NULL); + + g_assert_false (object_has_notify_signal_handlers (obj)); + + g_assert_cmpint (dispatch_properties_called, ==, 1); + g_object_set (obj, "foo", 11, NULL); + g_assert_cmpint (dispatch_properties_called, ==, 2); + + g_object_unref (obj); +} + /* This instance init behavior is the thing we are testing: * * 1. Don't connect any notify handlers @@ -146,12 +166,13 @@ object_has_notify_signal_handlers (gpointer instance) * 3. Verify that our custom dispatch_properties_changed is called */ static void -test_custom_dispatch (void) +test_custom_dispatch_set (void) { TestObject *obj; g_test_summary ("Test that custom dispatch_properties_changed is called regardless of connected notify handlers"); + dispatch_properties_called = 0; obj = g_object_new (test_object_get_type (), NULL); g_assert_false (object_has_notify_signal_handlers (obj)); @@ -170,7 +191,8 @@ main (int argc, char *argv[]) { g_test_init (&argc, &argv, NULL); - g_test_add_func ("/properties/custom-dispatch", test_custom_dispatch); + g_test_add_func ("/properties/custom-dispatch/init", test_custom_dispatch_init); + g_test_add_func ("/properties/custom-dispatch/set", test_custom_dispatch_set); return g_test_run (); }