[glib/gobject-speedups4: 3/3] Add some tests around properties




commit d6267836ca33f5789ef0c88f47a1b749d2bb4c00
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jun 7 12:02:58 2022 -0400

    Add some tests around properties
    
    Install the properties with a mixture of
    g_object_class_install_properties and
    g_object_class_install_properties, and verify
    that finding them still works, regardless of
    whether we use string literals or not.

 gobject/tests/properties.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/gobject/tests/properties.c b/gobject/tests/properties.c
index 3695ee123d..534dec38d7 100644
--- a/gobject/tests/properties.c
+++ b/gobject/tests/properties.c
@@ -180,15 +180,18 @@ test_object_class_init (TestObjectClass *klass)
   properties[PROP_BAZ] = g_param_spec_string ("baz", "Baz", "Baz",
                                               NULL,
                                               G_PARAM_READWRITE);
-  properties[PROP_QUUX] = g_param_spec_string ("quux", "quux", "quux",
-                                               NULL,
-                                               G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
   gobject_class->set_property = test_object_set_property;
   gobject_class->get_property = test_object_get_property;
   gobject_class->finalize = test_object_finalize;
 
-  g_object_class_install_properties (gobject_class, N_PROPERTIES, properties);
+  g_object_class_install_properties (gobject_class, N_PROPERTIES - 1, properties);
+
+  properties[PROP_QUUX] = g_param_spec_string ("quux", "quux", "quux",
+                                               NULL,
+                                               G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
+  g_object_class_install_property (gobject_class, PROP_QUUX, properties[PROP_QUUX]);
 }
 
 static void
@@ -205,12 +208,21 @@ properties_install (void)
 {
   TestObject *obj = g_object_new (test_object_get_type (), NULL);
   GParamSpec *pspec;
+  char *name;
 
   g_assert (properties[PROP_FOO] != NULL);
 
   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (obj), "foo");
   g_assert (properties[PROP_FOO] == pspec);
 
+  name = g_strdup ("bar");
+  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (obj), name);
+  g_assert (properties[PROP_BAR] == pspec);
+  g_free (name);
+
+  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (obj), "quux");
+  g_assert (properties[PROP_QUUX] == pspec);
+
   g_object_unref (obj);
 }
 


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