Blame tests/properties.c

Christian Dywan 787dec
/*
Christian Dywan 787dec
 Copyright (C) 2009 Christian Dywan <christian@twotoasts.de>
Christian Dywan 787dec
Christian Dywan 787dec
 This library is free software; you can redistribute it and/or
Christian Dywan 787dec
 modify it under the terms of the GNU Lesser General Public
Christian Dywan 787dec
 License as published by the Free Software Foundation; either
Christian Dywan 787dec
 version 2.1 of the License, or (at your option) any later version.
Christian Dywan 787dec
Christian Dywan 787dec
 See the file COPYING for the full license text.
Christian Dywan 787dec
*/
Christian Dywan 787dec
Christian Dywan 787dec
#include "midori.h"
Christian Dywan 787dec
Christian Dywan 787dec
#define pspec_is_writable(pspec) (pspec->flags & G_PARAM_WRITABLE \
Christian Dywan 787dec
    && !(pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)))
Christian Dywan 787dec
Christian Dywan 787dec
static void
Christian Dywan 787dec
properties_object_get_set (GObject* object)
Christian Dywan 787dec
{
Christian Dywan 787dec
    GObjectClass* class;
Christian Dywan 787dec
    GParamSpec** pspecs;
Christian Dywan 787dec
    guint i, n_properties;
Christian Dywan 787dec
Christian Dywan 787dec
    class = G_OBJECT_GET_CLASS (object);
Christian Dywan 787dec
    pspecs = g_object_class_list_properties (class, &n_properties);
Christian Dywan 787dec
    for (i = 0; i < n_properties; i++)
Christian Dywan 787dec
    {
Christian Dywan 787dec
        GParamSpec *pspec = pspecs[i];
Christian Dywan f4d19b
        guint j;
Christian Dywan 787dec
Christian Dywan 787dec
        /* Skip properties of parent classes */
Christian Dywan 787dec
        if (pspec->owner_type != G_OBJECT_TYPE (object))
Christian Dywan 787dec
            continue;
Christian Dywan 787dec
Christian Dywan f4d19b
        /* Verify that the ID is unique */
Christian Dywan f4d19b
        if (pspecs[i]->owner_type == G_OBJECT_TYPE (object))
Christian Dywan f4d19b
        for (j = 0; j < n_properties; j++)
Christian Dywan f4d19b
            if (i != j && pspecs[j]->owner_type == G_OBJECT_TYPE (object))
Christian Dywan f4d19b
                if (pspec->param_id == pspecs[j]->param_id)
Christian Dywan f4d19b
                    g_error ("Duplicate ID %d of %s and %s",
Christian Dywan f4d19b
                        pspec->param_id,
Christian Dywan f4d19b
                        g_param_spec_get_name (pspec),
Christian Dywan f4d19b
                        g_param_spec_get_name (pspecs[j]));
Christian Dywan 787dec
    }
Christian Dywan 787dec
  g_free (pspecs);
Christian Dywan 787dec
}
Christian Dywan 787dec
Christian Dywan 787dec
static void
Christian Dywan 787dec
properties_object_test (gconstpointer object)
Christian Dywan 787dec
{
Ryan Niebur 50549d
    if (GTK_IS_WIDGET (object))
Christian Dywan 787dec
        g_object_ref_sink ((GObject*)object);
Christian Dywan 787dec
Christian Dywan 787dec
    properties_object_get_set ((GObject*)object);
Christian Dywan 787dec
Ryan Niebur 50549d
    if (GTK_IS_WIDGET (object))
Ryan Niebur 50549d
        gtk_widget_destroy (GTK_WIDGET (object));
Christian Dywan 787dec
    g_object_unref ((GObject*)object);
Christian Dywan 787dec
}
Christian Dywan 787dec
Christian Dywan 787dec
static void
Christian Dywan 787dec
properties_type_test (gconstpointer type)
Christian Dywan 787dec
{
Christian Dywan 787dec
    GObject* object;
Christian Dywan 787dec
Ryan Niebur 50549d
    midori_test_log_set_fatal_handler_for_icons ();
Christian Dywan 787dec
    object = g_object_new ((GType)type, NULL);
Christian Dywan 787dec
    properties_object_test ((gconstpointer)object);
Christian Dywan 787dec
}
Christian Dywan 787dec
Christian Dywan 787dec
GtkWidget*
Christian Dywan 787dec
midori_dummy_viewable_new (const gchar* stock_id,
Christian Dywan 787dec
                           const gchar* label,
Christian Dywan 787dec
                           GtkWidget*   toolbar);
Christian Dywan 787dec
Christian Dywan 787dec
GtkWidget* dummy_viewable_new (void)
Christian Dywan 787dec
{
Christian Dywan 787dec
    GtkWidget* toolbar = gtk_toolbar_new ();
Christian Dywan 787dec
    return midori_dummy_viewable_new (GTK_STOCK_ABOUT, "Test", toolbar);
Christian Dywan 787dec
}
Christian Dywan 787dec
Christian Dywan 787dec
int
Christian Dywan 787dec
main (int    argc,
Christian Dywan 787dec
      char** argv)
Christian Dywan 787dec
{
Ryan Niebur 50549d
    g_test_init (&argc, &argv, NULL);
Ryan Niebur 50549d
    midori_app_setup (&argc, &argv, NULL);
Ryan Niebur 50549d
    midori_paths_init (MIDORI_RUNTIME_MODE_PRIVATE, NULL);
Ryan Niebur 50549d
Ryan Niebur 50549d
    #ifndef HAVE_WEBKIT2
Christian Dywan 35dfeb
    g_object_set_data (G_OBJECT (webkit_get_default_session ()),
Christian Dywan 35dfeb
                       "midori-session-initialized", (void*)1);
Ryan Niebur 50549d
    #endif
Christian Dywan 35dfeb
Christian Dywan 787dec
    g_test_add_data_func ("/properties/app",
Christian Dywan 787dec
        (gconstpointer)MIDORI_TYPE_APP, properties_type_test);
Christian Dywan ba9d7d
    g_test_add_data_func ("/properties/browser",
Christian Dywan ba9d7d
        (gconstpointer)MIDORI_TYPE_BROWSER, properties_type_test);
Christian Dywan 787dec
    g_test_add_data_func ("/properties/extension",
Christian Dywan 787dec
        (gconstpointer)MIDORI_TYPE_EXTENSION, properties_type_test);
Christian Dywan 787dec
    g_test_add_data_func ("/properties/location-action",
Christian Dywan 787dec
        (gconstpointer)MIDORI_TYPE_LOCATION_ACTION, properties_type_test);
Christian Dywan 787dec
    g_test_add_data_func ("/properties/panel",
Christian Dywan 787dec
        (gconstpointer)MIDORI_TYPE_PANEL, properties_type_test);
Christian Dywan 787dec
    g_test_add_data_func ("/properties/preferences",
Christian Dywan 787dec
        (gconstpointer)MIDORI_TYPE_PREFERENCES, properties_type_test);
Christian Dywan 787dec
    g_test_add_data_func ("/properties/search-action",
Christian Dywan 787dec
        (gconstpointer)MIDORI_TYPE_SEARCH_ACTION, properties_type_test);
Christian Dywan 787dec
    g_test_add_data_func ("/properties/view",
Christian Dywan 787dec
        (gconstpointer)MIDORI_TYPE_VIEW, properties_type_test);
Christian Dywan 787dec
    g_test_add_data_func ("/properties/viewable",
Christian Dywan 787dec
        (gconstpointer)dummy_viewable_new (), properties_object_test);
Christian Dywan 787dec
    g_test_add_data_func ("/properties/web-settings",
Christian Dywan 787dec
        (gconstpointer)MIDORI_TYPE_WEB_SETTINGS, properties_type_test);
Christian Dywan 787dec
Christian Dywan 787dec
    return g_test_run ();
Christian Dywan 787dec
}