a11y: add a treeview performance test

This test creates a treeview with a few columns and a liststore,
and then populates it with a 1000 rows.
This commit is contained in:
Matthias Clasen 2011-06-22 17:39:38 -04:00
parent 430957b036
commit 23bc606c79
2 changed files with 248 additions and 9 deletions

View File

@ -5,22 +5,41 @@ TEST_PROGS += accessibility-dump
check_PROGRAMS = $(TEST_PROGS)
accessibility_dump_CFLAGS = \
-I$(top_srcdir) \
-I$(top_builddir)/gdk \
-I$(top_srcdir)/gdk \
-DGDK_DISABLE_DEPRECATED \
-DGTK_DISABLE_DEPRECATED \
$(GTK_DEBUG_FLAGS) \
$(GTK_DEP_CFLAGS)
-I$(top_srcdir) \
-I$(top_builddir)/gdk \
-I$(top_srcdir)/gdk \
-DGDK_DISABLE_DEPRECATED \
-DGTK_DISABLE_DEPRECATED \
$(GTK_DEBUG_FLAGS) \
$(GTK_DEP_CFLAGS)
accessibility_dump_LDADD = \
$(top_builddir)/gdk/libgdk-3.la \
$(top_builddir)/gtk/libgtk-3.la \
$(top_builddir)/gdk/libgdk-3.la \
$(top_builddir)/gtk/libgtk-3.la \
$(GTK_DEP_LIBS)
accessibility_dump_SOURCES = \
accessibility-dump.c
TEST_PROGS += tree-performance
tree_performance_CFLAGS = \
-I$(top_srcdir) \
-I$(top_builddir)/gdk \
-I$(top_srcdir)/gdk \
-DGDK_DISABLE_DEPRECATED \
-DGTK_DISABLE_DEPRECATED \
$(GTK_DEBUG_FLAGS) \
$(GTK_DEP_CFLAGS)
tree_performance_LDADD = \
$(top_builddir)/gdk/libgdk-3.la \
$(top_builddir)/gtk/libgtk-3.la \
$(GTK_DEP_LIBS)
tree_performance_SOURCES = \
tree-performance.c
EXTRA_DIST += \
hello-world.ui hello-world.txt \
mnemonic.ui mnemonic.txt \

View File

@ -0,0 +1,220 @@
/*
* Copyright (C) 2011 Red Hat Inc.
*
* Author:
* Matthias Clasen <mclasen@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <gtk/gtk.h>
const gchar treeui[] =
"<interface>"
" <object class='GtkListStore' id='liststore1'>"
" <columns>"
" <column type='gchararray'/>"
" <column type='gchararray'/>"
" <column type='gchararray'/>"
" <column type='gboolean'/>"
" <column type='gint'/>"
" <column type='gint'/>"
" </columns>"
" <data>"
" <row><col id='0'>One</col><col id='1'>Two</col><col id='2'>Three</col><col id='3'>True</col><col id='4'>50</col><col id='5'>50</col></row>"
" </data>"
" </object>"
" <object class='GtkWindow' id='window1'>"
" <child>"
" <object class='GtkTreeView' id='treeview1'>"
" <property name='visible'>True</property>"
" <property name='model'>liststore1</property>"
" <child>"
" <object class='GtkTreeViewColumn' id='column1'>"
" <property name='title' translatable='yes'>First column</property>"
" <child>"
" <object class='GtkCellRendererText' id='renderer1'>"
" </object>"
" <attributes>"
" <attribute name='text'>0</attribute>"
" </attributes>"
" </child>"
" <child>"
" <object class='GtkCellRendererToggle' id='renderer2'>"
" </object>"
" <attributes>"
" <attribute name='active'>3</attribute>"
" </attributes>"
" </child>"
" </object>"
" </child>"
" <child>"
" <object class='GtkTreeViewColumn' id='column2'>"
" <property name='title' translatable='yes'>Second column</property>"
" <child>"
" <object class='GtkCellRendererText' id='renderer3'>"
" </object>"
" <attributes>"
" <attribute name='text'>1</attribute>"
" </attributes>"
" </child>"
" <child>"
" <object class='GtkCellRendererProgress' id='renderer4'>"
" </object>"
" <attributes>"
" <attribute name='value'>4</attribute>"
" </attributes>"
" </child>"
" </object>"
" </child>"
" </object>"
" </child>"
" </object>"
"</interface>";
static void
walk_accessible_tree (AtkObject *accessible,
gpointer data)
{
gint *count = data;
gint i;
(*count)++;
for (i = 0; i < atk_object_get_n_accessible_children (accessible); i++)
{
AtkObject *child = atk_object_ref_accessible_child (accessible, i);
walk_accessible_tree (child, data);
g_object_unref (child);
}
}
static GtkWidget *
builder_get_toplevel (GtkBuilder *builder)
{
GSList *list, *walk;
GtkWidget *window = NULL;
list = gtk_builder_get_objects (builder);
for (walk = list; walk; walk = walk->next)
{
if (GTK_IS_WINDOW (walk->data) &&
gtk_widget_get_parent (walk->data) == NULL)
{
window = walk->data;
break;
}
}
g_slist_free (list);
return window;
}
static void
populate_tree (GtkBuilder *builder)
{
GtkTreeView *tv;
GtkListStore *store;
GtkTreeIter iter;
gint i;
tv = (GtkTreeView *)gtk_builder_get_object (builder, "treeview1");
store = (GtkListStore *)gtk_tree_view_get_model (tv);
/* append a thousand rows */
for (i = 0; i < 1000; i++)
{
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, "Bla", 1, "Bla bla", 2, "Bla bla bla", 3, i % 2 == 0 ? TRUE : FALSE, 4, i % 100, 5, i, -1);
}
}
static void
test_performance_tree (void)
{
GtkBuilder *builder;
gdouble elapsed;
GtkWidget *window;
GError *error = NULL;
builder = gtk_builder_new ();
gtk_builder_add_from_string (builder, treeui, -1, &error);
g_assert_no_error (error);
window = builder_get_toplevel (builder);
g_assert (window);
gtk_widget_show (window);
g_test_timer_start ();
populate_tree (builder);
elapsed = g_test_timer_elapsed ();
g_test_minimized_result (elapsed, "large tree test: %gsec", elapsed);
g_object_unref (builder);
}
static void
test_a11y_performance_tree (void)
{
GtkBuilder *builder;
gdouble elapsed;
GtkWidget *window;
GError *error = NULL;
gint count_before;
gint count_after;
builder = gtk_builder_new ();
gtk_builder_add_from_string (builder, treeui, -1, &error);
g_assert_no_error (error);
window = builder_get_toplevel (builder);
g_assert (window);
gtk_widget_show (window);
g_test_timer_start ();
/* make sure all accessibles exist */
count_before = 0;
walk_accessible_tree (gtk_widget_get_accessible (window), &count_before);
populate_tree (builder);
/* for good measure, do this again */
count_after = 0;
walk_accessible_tree (gtk_widget_get_accessible (window), &count_after);
elapsed = g_test_timer_elapsed ();
g_test_minimized_result (elapsed, "large tree test with a11y: %gsec", elapsed);
g_object_unref (builder);
g_test_message ("%d accessibles before, %d after\n", count_before, count_after);
}
int
main (int argc, char *argv[])
{
gtk_test_init (&argc, &argv, NULL);
if (!g_test_perf ())
return 0;
g_test_add_func ("/performance/tree", test_performance_tree);
g_test_add_func ("/a11y/performance/tree", test_a11y_performance_tree);
return g_test_run ();
}