Blame gtk/tests/object.c

Packit Service fb6fa5
/* Gtk+ object tests
Packit Service fb6fa5
 * Copyright (C) 2007 Imendio AB
Packit Service fb6fa5
 * Authors: Tim Janik
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is free software; you can redistribute it and/or
Packit Service fb6fa5
 * modify it under the terms of the GNU Lesser General Public
Packit Service fb6fa5
 * License as published by the Free Software Foundation; either
Packit Service fb6fa5
 * version 2 of the License, or (at your option) any later version.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is distributed in the hope that it will be useful,
Packit Service fb6fa5
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fb6fa5
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service fb6fa5
 * Lesser General Public License for more details.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * You should have received a copy of the GNU Lesser General Public
Packit Service fb6fa5
 * License along with this library; if not, write to the
Packit Service fb6fa5
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit Service fb6fa5
 * Boston, MA 02111-1307, USA.
Packit Service fb6fa5
 */
Packit Service fb6fa5
#include <gtk/gtk.h>
Packit Service fb6fa5
#include <string.h>
Packit Service fb6fa5
Packit Service fb6fa5
/* --- helper macros for property value generation --- */
Packit Service fb6fa5
/* dvalue=+0: generate minimum value
Packit Service fb6fa5
 * dvalue=.x: generate value within value range proportional to x.
Packit Service fb6fa5
 * dvalue=+1: generate maximum value
Packit Service fb6fa5
 * dvalue=-1: generate random value within value range
Packit Service fb6fa5
 * dvalue=+2: initialize value from default_value
Packit Service fb6fa5
 */
Packit Service fb6fa5
#define ASSIGN_VALUE(__g_value_set_func, __value, PSPECTYPE, __pspec, __default_value, __minimum, __maximum, __dvalue) do { \
Packit Service fb6fa5
  PSPECTYPE __p = (PSPECTYPE) __pspec; \
Packit Service fb6fa5
  __g_value_set_func (__value, SELECT_VALUE (__dvalue, __p->__default_value, __p->__minimum, __p->__maximum)); \
Packit Service fb6fa5
} while (0)
Packit Service fb6fa5
#define SELECT_VALUE(__dvalue, __default_value, __minimum, __maximum) ( \
Packit Service fb6fa5
  __dvalue >= 0 && __dvalue <= 1 ? __minimum * (1 - __dvalue) + __dvalue * __maximum : \
Packit Service fb6fa5
    __dvalue <= -1 ? g_test_rand_double_range (__minimum, __maximum) : \
Packit Service fb6fa5
      __default_value)
Packit Service fb6fa5
#define SELECT_NAME(__dvalue) ( \
Packit Service fb6fa5
  __dvalue == 0 ? "minimum" : \
Packit Service fb6fa5
    __dvalue == 1 ? "maximum" : \
Packit Service fb6fa5
      __dvalue >= +2 ? "default" : \
Packit Service fb6fa5
        __dvalue == 0.5 ? "medium" : \
Packit Service fb6fa5
          __dvalue > 0 && __dvalue < 1 ? "fractional" : \
Packit Service fb6fa5
            "random")
Packit Service fb6fa5
#define MATCH_ANY_VALUE         ((void*) 0xf1874c23)
Packit Service fb6fa5
Packit Service fb6fa5
/* --- property blacklists --- */
Packit Service fb6fa5
typedef struct {
Packit Service fb6fa5
  const char   *type_name;
Packit Service fb6fa5
  const char   *name;
Packit Service fb6fa5
  gconstpointer value;
Packit Service fb6fa5
} IgnoreProperty;
Packit Service fb6fa5
static const IgnoreProperty*
Packit Service fb6fa5
list_ignore_properties (gboolean buglist)
Packit Service fb6fa5
{
Packit Service fb6fa5
  /* currently untestable properties */
Packit Service fb6fa5
  static const IgnoreProperty ignore_properties[] = {
Packit Service fb6fa5
    { "GtkCurve",               "",                     NULL, },                        /* Just ignore it, not worth fixing */
Packit Service fb6fa5
    { "GtkContainer",           "child",                NULL, },                        /* needs working child widget */
Packit Service fb6fa5
    { "GtkRadioMenuItem",       "group",                NULL, },                        /* needs working sibling */
Packit Service fb6fa5
    { "GtkWidget",              "parent",               NULL, },                        /* needs working parent widget */
Packit Service fb6fa5
    { "GtkCList",               "selection-mode",       (void*) GTK_SELECTION_NONE, },
Packit Service fb6fa5
    { "GtkWidget",              "has-default",          (void*) TRUE, },                /* conflicts with toplevel-less widgets */
Packit Service fb6fa5
    { "GtkWidget",              "screen",               NULL, },
Packit Service fb6fa5
    { "GtkWindow",              "type-hint",            (void*) GDK_WINDOW_TYPE_HINT_DND, }, /* conflicts with ::visible=TRUE */
Packit Service fb6fa5
    { "GtkCellView",            "background",           (void*) "", },                  /* "" is not a valid background color */
Packit Service fb6fa5
    { "GtkColorButton",         "color",                (void*) NULL, },                /* not a valid boxed color */
Packit Service fb6fa5
    { "GtkInputDialog",         "has-separator",        (void*) MATCH_ANY_VALUE, },     /* property disabled */
Packit Service fb6fa5
    { "GtkMessageDialog",       "has-separator",        (void*) MATCH_ANY_VALUE, },     /* property disabled */
Packit Service fb6fa5
    { "GtkFontSelectionDialog", "has-separator",        (void*) MATCH_ANY_VALUE, },     /* property disabled */
Packit Service fb6fa5
    { "GtkColorSelectionDialog","has-separator",        (void*) MATCH_ANY_VALUE, },     /* property disabled */
Packit Service fb6fa5
    { "GtkColorSelection",      "child",                NULL, },
Packit Service fb6fa5
    { "GtkColorSelection",      "current-color",        (void*) NULL, },                /* not a valid boxed color */
Packit Service fb6fa5
    { "GtkComboBox",            "row-span-column",      (void*) MATCH_ANY_VALUE },      /* GtkComboBoxEntry needs a tree model for this */
Packit Service fb6fa5
    { "GtkComboBox",            "column-span-column",   (void*) MATCH_ANY_VALUE },      /* GtkComboBoxEntry needs a tree model for this */
Packit Service fb6fa5
    { "GtkFileChooserButton",   "select-multiple",      (void*) MATCH_ANY_VALUE },      /* property disabled */
Packit Service fb6fa5
    { "GtkFileChooserButton",   "action",               (void*) GTK_FILE_CHOOSER_ACTION_SAVE },
Packit Service fb6fa5
    { "GtkFileChooserButton",   "action",               (void*) GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER },
Packit Service fb6fa5
    { "GtkFileChooserWidget",   "select-multiple",      (void*) 0x1 },                  /* property conflicts */
Packit Service fb6fa5
    { "GtkFileChooserDialog",   "select-multiple",      (void*) MATCH_ANY_VALUE },      /* property disabled */
Packit Service fb6fa5
    { "GtkMenu",                "accel-path",           (void*) MATCH_ANY_VALUE },      /* has odd restrictions in the setter */
Packit Service fb6fa5
    { "GtkMenuItem",            "accel-path",           (void*) MATCH_ANY_VALUE },      /* has odd restrictions in the setter */
Packit Service fb6fa5
    { "GtkRecentChooserMenu",   "select-multiple",      (void*) MATCH_ANY_VALUE },      /* property disabled */
Packit Service fb6fa5
    { "GtkTextView",            "overwrite",            (void*) MATCH_ANY_VALUE },      /* needs text buffer */
Packit Service fb6fa5
    { "GtkToolbar",             "icon-size",            (void*) GTK_ICON_SIZE_INVALID },
Packit Service fb6fa5
    { NULL, NULL, NULL }
Packit Service fb6fa5
  };
Packit Service fb6fa5
  /* properties suspected to be Gdk/Gtk+ bugs */
Packit Service fb6fa5
  static const IgnoreProperty bug_properties[] = {
Packit Service fb6fa5
    { "GtkComboBox",            "active",               (void*) MATCH_ANY_VALUE },      /* FIXME: triggers NULL model bug */
Packit Service fb6fa5
    { "GtkCTree",               "spacing",              (void*) MATCH_ANY_VALUE },      /* FIXME: triggers signedness bug */
Packit Service fb6fa5
    { "GtkFileChooserButton",   "local-only",           (void*) MATCH_ANY_VALUE },      /* FIXME: triggers NULL path assertion */
Packit Service fb6fa5
    { "GtkFileChooserDialog",   "local-only",           (void*) MATCH_ANY_VALUE },      /* FIXME: triggers NULL path assertion */
Packit Service fb6fa5
    { "GtkFileChooserWidget",   "local-only",           (void*) MATCH_ANY_VALUE },      /* FIXME: triggers NULL path assertion */
Packit Service fb6fa5
    { "GtkMenu",                "tearoff-state",        (void*) MATCH_ANY_VALUE },      /* FIXME: triggers NULL widget cast */
Packit Service fb6fa5
    { "GtkText",                "text-position",        (void*) MATCH_ANY_VALUE },      /* FIXME: segfaults, fix property minimum/maximum */
Packit Service fb6fa5
    { NULL, NULL, NULL }
Packit Service fb6fa5
  };
Packit Service fb6fa5
  if (buglist)
Packit Service fb6fa5
    return bug_properties;
Packit Service fb6fa5
  else
Packit Service fb6fa5
    return ignore_properties;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* --- test functions --- */
Packit Service fb6fa5
static void
Packit Service fb6fa5
pspec_select_value (GParamSpec *pspec,
Packit Service fb6fa5
                    GValue     *value,
Packit Service fb6fa5
                    double      dvalue)
Packit Service fb6fa5
{
Packit Service fb6fa5
  /* generate a value suitable for pspec */
Packit Service fb6fa5
  if (G_IS_PARAM_SPEC_CHAR (pspec))
Packit Service fb6fa5
    ASSIGN_VALUE (g_value_set_char, value, GParamSpecChar*, pspec, default_value, minimum, maximum, dvalue);
Packit Service fb6fa5
  else if (G_IS_PARAM_SPEC_UCHAR (pspec))
Packit Service fb6fa5
    ASSIGN_VALUE (g_value_set_uchar, value, GParamSpecUChar*, pspec, default_value, minimum, maximum, dvalue);
Packit Service fb6fa5
  else if (G_IS_PARAM_SPEC_INT (pspec))
Packit Service fb6fa5
    ASSIGN_VALUE (g_value_set_int, value, GParamSpecInt*, pspec, default_value, minimum, maximum, dvalue);
Packit Service fb6fa5
  else if (G_IS_PARAM_SPEC_UINT (pspec))
Packit Service fb6fa5
    ASSIGN_VALUE (g_value_set_uint, value, GParamSpecUInt*, pspec, default_value, minimum, maximum, dvalue);
Packit Service fb6fa5
  else if (G_IS_PARAM_SPEC_LONG (pspec))
Packit Service fb6fa5
    ASSIGN_VALUE (g_value_set_long, value, GParamSpecLong*, pspec, default_value, minimum, maximum, dvalue);
Packit Service fb6fa5
  else if (G_IS_PARAM_SPEC_ULONG (pspec))
Packit Service fb6fa5
    ASSIGN_VALUE (g_value_set_ulong, value, GParamSpecULong*, pspec, default_value, minimum, maximum, dvalue);
Packit Service fb6fa5
  else if (G_IS_PARAM_SPEC_INT64 (pspec))
Packit Service fb6fa5
    ASSIGN_VALUE (g_value_set_int64, value, GParamSpecInt64*, pspec, default_value, minimum, maximum, dvalue);
Packit Service fb6fa5
  else if (G_IS_PARAM_SPEC_UINT64 (pspec))
Packit Service fb6fa5
    ASSIGN_VALUE (g_value_set_uint64, value, GParamSpecUInt64*, pspec, default_value, minimum, maximum, dvalue);
Packit Service fb6fa5
  else if (G_IS_PARAM_SPEC_FLOAT (pspec))
Packit Service fb6fa5
    ASSIGN_VALUE (g_value_set_float, value, GParamSpecFloat*, pspec, default_value, minimum, maximum, dvalue);
Packit Service fb6fa5
  else if (G_IS_PARAM_SPEC_DOUBLE (pspec))
Packit Service fb6fa5
    ASSIGN_VALUE (g_value_set_double, value, GParamSpecDouble*, pspec, default_value, minimum, maximum, dvalue);
Packit Service fb6fa5
  else if (G_IS_PARAM_SPEC_BOOLEAN (pspec))
Packit Service fb6fa5
    g_value_set_boolean (value, SELECT_VALUE (dvalue, ((GParamSpecBoolean*) pspec)->default_value, FALSE, TRUE));
Packit Service fb6fa5
  else if (G_IS_PARAM_SPEC_UNICHAR (pspec))
Packit Service fb6fa5
    g_value_set_uint (value, SELECT_VALUE (dvalue, ((GParamSpecUnichar*) pspec)->default_value, FALSE, TRUE));
Packit Service fb6fa5
  else if (G_IS_PARAM_SPEC_GTYPE (pspec))
Packit Service fb6fa5
    g_value_set_gtype (value, SELECT_VALUE ((int) dvalue, ((GParamSpecGType*) pspec)->is_a_type, 0, GTK_TYPE_WIDGET));
Packit Service fb6fa5
  else if (G_IS_PARAM_SPEC_STRING (pspec))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      GParamSpecString *sspec = (GParamSpecString*) pspec;
Packit Service fb6fa5
      if (dvalue >= +2)
Packit Service fb6fa5
        g_value_set_string (value, sspec->default_value);
Packit Service fb6fa5
      if (dvalue > 0 && sspec->cset_first && sspec->cset_nth)
Packit Service fb6fa5
        g_value_take_string (value, g_strdup_printf ("%c%c", sspec->cset_first[0], sspec->cset_nth[0]));
Packit Service fb6fa5
      else /* if (sspec->ensure_non_null) */
Packit Service fb6fa5
        g_value_set_string (value, "");
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else if (G_IS_PARAM_SPEC_ENUM (pspec))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      GParamSpecEnum *espec = (GParamSpecEnum*) pspec;
Packit Service fb6fa5
      if (dvalue >= +2)
Packit Service fb6fa5
        g_value_set_enum (value, espec->default_value);
Packit Service fb6fa5
      if (dvalue >= 0 && dvalue <= 1)
Packit Service fb6fa5
        g_value_set_enum (value, espec->enum_class->values[(int) ((espec->enum_class->n_values - 1) * dvalue)].value);
Packit Service fb6fa5
      else if (dvalue <= -1)
Packit Service fb6fa5
        g_value_set_enum (value, espec->enum_class->values[g_test_rand_int_range (0, espec->enum_class->n_values)].value);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else if (G_IS_PARAM_SPEC_FLAGS (pspec))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      GParamSpecFlags *fspec = (GParamSpecFlags*) pspec;
Packit Service fb6fa5
      if (dvalue >= +2)
Packit Service fb6fa5
        g_value_set_flags (value, fspec->default_value);
Packit Service fb6fa5
      if (dvalue >= 0 && dvalue <= 1)
Packit Service fb6fa5
        g_value_set_flags (value, fspec->flags_class->values[(int) ((fspec->flags_class->n_values - 1) * dvalue)].value);
Packit Service fb6fa5
      else if (dvalue <= -1)
Packit Service fb6fa5
        g_value_set_flags (value, fspec->flags_class->values[g_test_rand_int_range (0, fspec->flags_class->n_values)].value);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  /* unimplemented:
Packit Service fb6fa5
   * G_IS_PARAM_SPEC_PARAM
Packit Service fb6fa5
   * G_IS_PARAM_SPEC_BOXED
Packit Service fb6fa5
   * G_IS_PARAM_SPEC_POINTER
Packit Service fb6fa5
   * G_IS_PARAM_SPEC_VALUE_ARRAY
Packit Service fb6fa5
   * G_IS_PARAM_SPEC_OBJECT
Packit Service fb6fa5
   */
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static gpointer
Packit Service fb6fa5
value_as_pointer (GValue *value)
Packit Service fb6fa5
{
Packit Service fb6fa5
  if (g_value_fits_pointer (value))
Packit Service fb6fa5
    return g_value_peek_pointer (value);
Packit Service fb6fa5
  if (G_VALUE_HOLDS_BOOLEAN (value))
Packit Service fb6fa5
    return GINT_TO_POINTER(g_value_get_boolean (value));
Packit Service fb6fa5
  if (G_VALUE_HOLDS_CHAR (value))
Packit Service fb6fa5
    return (void*) (gssize) g_value_get_char (value);
Packit Service fb6fa5
  if (G_VALUE_HOLDS_UCHAR (value))
Packit Service fb6fa5
    return (void*) (gsize) g_value_get_uchar (value);
Packit Service fb6fa5
  if (G_VALUE_HOLDS_INT (value))
Packit Service fb6fa5
    return GINT_TO_POINTER(g_value_get_int (value));
Packit Service fb6fa5
  if (G_VALUE_HOLDS_UINT (value))
Packit Service fb6fa5
    return GUINT_TO_POINTER(g_value_get_uint (value));
Packit Service fb6fa5
  if (G_VALUE_HOLDS_LONG (value))
Packit Service fb6fa5
    return (void*) g_value_get_long (value);
Packit Service fb6fa5
  if (G_VALUE_HOLDS_ULONG (value))
Packit Service fb6fa5
    return (void*) g_value_get_ulong (value);
Packit Service fb6fa5
  if (G_VALUE_HOLDS_FLOAT (value))
Packit Service fb6fa5
    return (void*) (gssize) g_value_get_float (value);
Packit Service fb6fa5
  if (G_VALUE_HOLDS_DOUBLE (value))
Packit Service fb6fa5
    return (void*) (gssize) g_value_get_double (value);
Packit Service fb6fa5
  if (G_VALUE_HOLDS_ENUM (value))
Packit Service fb6fa5
    return (void*) (gssize) g_value_get_enum (value);
Packit Service fb6fa5
  if (G_VALUE_HOLDS_FLAGS (value))
Packit Service fb6fa5
    return (void*) (gsize) g_value_get_flags (value);
Packit Service fb6fa5
  return (void*) 0x1373babe;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
object_test_property (GObject           *object,
Packit Service fb6fa5
                      GParamSpec        *pspec,
Packit Service fb6fa5
                      double             dvalue)
Packit Service fb6fa5
{
Packit Service fb6fa5
  /* test setting of a normal writable property */
Packit Service fb6fa5
  if (pspec->flags & G_PARAM_WRITABLE &&
Packit Service fb6fa5
      !(pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      GValue value = { 0, };
Packit Service fb6fa5
      guint i;
Packit Service fb6fa5
      const IgnoreProperty *ignore_properties;
Packit Service fb6fa5
      /* select value to set */
Packit Service fb6fa5
      g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
Packit Service fb6fa5
      pspec_select_value (pspec, &value, dvalue);
Packit Service fb6fa5
      /* ignore untestable properties */
Packit Service fb6fa5
      ignore_properties = list_ignore_properties (FALSE);
Packit Service fb6fa5
      for (i = 0; ignore_properties[i].name; i++)
Packit Service fb6fa5
        if (g_strcmp0 ("", ignore_properties[i].name) ||
Packit Service fb6fa5
            (g_type_is_a (G_OBJECT_TYPE (object), g_type_from_name (ignore_properties[i].type_name)) &&
Packit Service fb6fa5
             strcmp (pspec->name, ignore_properties[i].name) == 0 &&
Packit Service fb6fa5
             (MATCH_ANY_VALUE == ignore_properties[i].value ||
Packit Service fb6fa5
              value_as_pointer (&value) == ignore_properties[i].value ||
Packit Service fb6fa5
              (G_VALUE_HOLDS_STRING (&value) &&
Packit Service fb6fa5
               strcmp (g_value_get_string (&value), ignore_properties[i].value) == 0))))
Packit Service fb6fa5
          break;
Packit Service fb6fa5
      /* ignore known property bugs if not testing thoroughly */
Packit Service fb6fa5
      if (ignore_properties[i].name == NULL && !g_test_thorough ())
Packit Service fb6fa5
        {
Packit Service fb6fa5
          ignore_properties = list_ignore_properties (TRUE);
Packit Service fb6fa5
          for (i = 0; ignore_properties[i].name; i++)
Packit Service fb6fa5
            if (g_type_is_a (G_OBJECT_TYPE (object), g_type_from_name (ignore_properties[i].type_name)) &&
Packit Service fb6fa5
                strcmp (pspec->name, ignore_properties[i].name) == 0 &&
Packit Service fb6fa5
                (MATCH_ANY_VALUE == ignore_properties[i].value ||
Packit Service fb6fa5
                 value_as_pointer (&value) == ignore_properties[i].value ||
Packit Service fb6fa5
                 (G_VALUE_HOLDS_STRING (&value) &&
Packit Service fb6fa5
                  strcmp (g_value_get_string (&value), ignore_properties[i].value) == 0)))
Packit Service fb6fa5
              break;
Packit Service fb6fa5
        }
Packit Service fb6fa5
      /* assign unignored properties */
Packit Service fb6fa5
      if (ignore_properties[i].name == NULL)
Packit Service fb6fa5
        {
Packit Service fb6fa5
          if (g_test_verbose ())
Packit Service fb6fa5
            g_print ("PropertyTest: %s::%s := (%s value (%s): %p)\n",
Packit Service fb6fa5
                     g_type_name (G_OBJECT_TYPE (object)), pspec->name,
Packit Service fb6fa5
                     SELECT_NAME (dvalue), g_type_name (G_VALUE_TYPE (&value)),
Packit Service fb6fa5
                     value_as_pointer (&value));
Packit Service fb6fa5
          g_object_set_property (object, pspec->name, &value);
Packit Service fb6fa5
        }
Packit Service fb6fa5
      /* cleanups */
Packit Service fb6fa5
      g_value_unset (&value);
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
widget_test_properties (GtkWidget   *widget,
Packit Service fb6fa5
                        double       dvalue)
Packit Service fb6fa5
{
Packit Service fb6fa5
  /* try setting all possible properties, according to dvalue */
Packit Service fb6fa5
  guint i, n_pspecs = 0;
Packit Service fb6fa5
  GParamSpec **pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (widget), &n_pspecs);
Packit Service fb6fa5
  for (i = 0; i < n_pspecs; i++)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      GParamSpec *pspec = pspecs[i];
Packit Service fb6fa5
      if (pspec->flags & G_PARAM_WRITABLE &&
Packit Service fb6fa5
          !(pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)))
Packit Service fb6fa5
        object_test_property (G_OBJECT (widget), pspecs[i], dvalue);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  g_free (pspecs);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
widget_property_tests (gconstpointer test_data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GType wtype = (GType) test_data;
Packit Service fb6fa5
  /* create widget */
Packit Service fb6fa5
  GtkWidget *widget = gtk_widget_new (wtype, NULL);
Packit Service fb6fa5
  g_object_ref_sink (widget);
Packit Service fb6fa5
  /* test property values */
Packit Service fb6fa5
  widget_test_properties (widget,  +2); /* test default_value */
Packit Service fb6fa5
  widget_test_properties (widget,   0); /* test minimum */
Packit Service fb6fa5
  widget_test_properties (widget, 0.5); /* test medium */
Packit Service fb6fa5
  widget_test_properties (widget,   1); /* test maximum */
Packit Service fb6fa5
  widget_test_properties (widget,  -1); /* test random value */
Packit Service fb6fa5
  /* cleanup */
Packit Service fb6fa5
  gtk_widget_destroy (widget);
Packit Service fb6fa5
  g_object_unref (widget);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
extern void pixbuf_init (void);
Packit Service fb6fa5
Packit Service fb6fa5
/* --- main test program --- */
Packit Service fb6fa5
int
Packit Service fb6fa5
main (int   argc,
Packit Service fb6fa5
      char *argv[])
Packit Service fb6fa5
{
Packit Service fb6fa5
  const GType *otypes;
Packit Service fb6fa5
  guint i;
Packit Service fb6fa5
  /* initialize test program */
Packit Service fb6fa5
  pixbuf_init ();
Packit Service fb6fa5
  gtk_test_init (&argc, &argv);
Packit Service fb6fa5
  gtk_test_register_all_types ();
Packit Service fb6fa5
  /* install a property test for each widget type */
Packit Service fb6fa5
  otypes = gtk_test_list_all_types (NULL);
Packit Service fb6fa5
  for (i = 0; otypes[i]; i++)
Packit Service fb6fa5
    if (g_type_is_a (otypes[i], GTK_TYPE_WIDGET) &&
Packit Service fb6fa5
        G_TYPE_IS_OBJECT (otypes[i]) &&
Packit Service fb6fa5
        !G_TYPE_IS_ABSTRACT (otypes[i]))
Packit Service fb6fa5
      {
Packit Service fb6fa5
        gchar *testpath = g_strdup_printf ("/properties/%s", g_type_name (otypes[i]));
Packit Service fb6fa5
        g_test_add_data_func (testpath, (void*) otypes[i], widget_property_tests);
Packit Service fb6fa5
        g_free (testpath);
Packit Service fb6fa5
      }
Packit Service fb6fa5
  return g_test_run ();
Packit Service fb6fa5
}