static gpointer
value_as_pointer (GValue *value)
{ if (g_value_fits_pointer (value)) return g_value_peek_pointer (value); if (G_VALUE_HOLDS_BOOLEAN (value)) return GINT_TO_POINTER(g_value_get_boolean (value)); if (G_VALUE_HOLDS_CHAR (value)) return (void*) (gssize) g_value_get_schar (value); if (G_VALUE_HOLDS_UCHAR (value)) return (void*) (gsize) g_value_get_uchar (value); if (G_VALUE_HOLDS_INT (value)) return GINT_TO_POINTER(g_value_get_int (value)); if (G_VALUE_HOLDS_UINT (value)) return GUINT_TO_POINTER(g_value_get_uint (value)); if (G_VALUE_HOLDS_LONG (value)) return GSIZE_TO_POINTER ((gssize) g_value_get_long (value)); if (G_VALUE_HOLDS_ULONG (value)) return GSIZE_TO_POINTER (g_value_get_ulong (value)); if (G_VALUE_HOLDS_FLOAT (value)) return (void*) (gssize) g_value_get_float (value); if (G_VALUE_HOLDS_DOUBLE (value)) return (void*) (gssize) g_value_get_double (value); if (G_VALUE_HOLDS_ENUM (value)) return (void*) (gssize) g_value_get_enum (value); if (G_VALUE_HOLDS_FLAGS (value)) return (void*) (gsize) g_value_get_flags (value); return (void*) 0x1373babe;
}
staticvoid
object_test_property (GObject *object,
GParamSpec *pspec, double dvalue)
{ /* test setting of a normal writable property */ if (pspec->flags & G_PARAM_WRITABLE &&
!(pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)))
{
GValue value = G_VALUE_INIT;
guint i; const IgnoreProperty *ignore_properties; /* select value to set */
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
pspec_select_value (pspec, &value, dvalue); /* ignore untestable properties */
ignore_properties = list_ignore_properties (FALSE); for (i = 0; ignore_properties[i].name; i++) if (g_strcmp0 ("", ignore_properties[i].name) != 0 ||
(g_type_is_a (G_OBJECT_TYPE (object), g_type_from_name (ignore_properties[i].type_name)) &&
strcmp (pspec->name, ignore_properties[i].name) == 0 &&
(MATCH_ANY_VALUE == ignore_properties[i].value ||
value_as_pointer (&value) == ignore_properties[i].value ||
(G_VALUE_HOLDS_STRING (&value) &&
g_strcmp0 (g_value_get_string (&value), ignore_properties[i].value) == 0)))) break; /* ignore known property bugs if not testing thoroughly */ if (ignore_properties[i].name == NULL && !g_test_thorough ())
{
ignore_properties = list_ignore_properties (TRUE); for (i = 0; ignore_properties[i].name; i++) if (g_type_is_a (G_OBJECT_TYPE (object), g_type_from_name (ignore_properties[i].type_name)) &&
strcmp (pspec->name, ignore_properties[i].name) == 0 &&
(MATCH_ANY_VALUE == ignore_properties[i].value ||
value_as_pointer (&value) == ignore_properties[i].value ||
(G_VALUE_HOLDS_STRING (&value) &&
g_strcmp0 (g_value_get_string (&value), ignore_properties[i].value) == 0))) break;
} /* assign unignored properties */ if (ignore_properties[i].name == NULL)
{ if (g_test_verbose ())
g_print ("PropertyTest: %s::%s := (%s value (%s): %p)\n",
g_type_name (G_OBJECT_TYPE (object)), pspec->name,
SELECT_NAME (dvalue), g_type_name (G_VALUE_TYPE (&value)),
value_as_pointer (&value));
g_object_set_property (object, pspec->name, &value);
} /* cleanups */
g_value_unset (&value);
}
}
staticvoid
widget_test_properties (GtkWidget *widget, double dvalue)
{ /* try setting all possible properties, according to dvalue */
guint i, n_pspecs = 0;
GParamSpec **pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (widget), &n_pspecs); for (i = 0; i < n_pspecs; i++)
{
GParamSpec *pspec = pspecs[i]; /* we want to test if the nick is null, but the getter defaults to the name */
g_assert_cmpstr (g_param_spec_get_nick (pspec), ==, g_param_spec_get_name (pspec));
g_assert_cmpstr (g_param_spec_get_blurb (pspec), ==, NULL); if (pspec->flags & G_PARAM_WRITABLE &&
!(pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)))
object_test_property (G_OBJECT (widget), pspecs[i], dvalue);
}
g_free (pspecs);
}
staticvoid
widget_fixups (GtkWidget *widget)
{
G_GNUC_BEGIN_IGNORE_DEPRECATIONS /* post-constructor for widgets that need additional settings to work correctly */ if (GTK_IS_COMBO_BOX_TEXT (widget))
{
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "test text");
}
G_GNUC_END_IGNORE_DEPRECATIONS
}
staticvoid
widget_property_tests (gconstpointer test_data)
{
GType wtype = (GType) test_data; /* create widget */
GtkWidget *widget = g_object_new (wtype, NULL);
g_object_ref_sink (widget);
widget_fixups (widget); /* test property values */
widget_test_properties (widget, +2); /* test default_value */
widget_test_properties (widget, 0); /* test minimum */
widget_test_properties (widget, 0.5); /* test medium */
widget_test_properties (widget, 1); /* test maximum */
widget_test_properties (widget, -1); /* test random value */ /* cleanup */ if (GTK_IS_WINDOW (widget))
gtk_window_destroy (GTK_WINDOW (widget));
g_object_unref (widget);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.