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




commit 2e8b51aaa8561e2edee029ee2fd444e3bdae136a
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 | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/gobject/tests/properties.c b/gobject/tests/properties.c
index 3695ee123d..581ebb8446 100644
--- a/gobject/tests/properties.c
+++ b/gobject/tests/properties.c
@@ -173,22 +173,29 @@ 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_READWRITE | G_PARAM_STATIC_STRINGS);
   properties[PROP_BAR] = g_param_spec_boolean ("bar", "Bar", "Bar",
                                                FALSE,
-                                               G_PARAM_READWRITE);
+                                               G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
   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);
+
+  /* We intentionally install this property separately, to test
+   * that that works, and that property lookup works regardless
+   * how the property was installed.
+   */
+  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 +212,24 @@ 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), "baz");
+  g_assert (properties[PROP_BAZ] == pspec);
+
+  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]