1 /* stresstest-toolbar.c
3 * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 #undef GTK_DISABLE_DEPRECATED
24 typedef struct _Info Info;
33 add_random (GtkToolbar *toolbar, gint n)
36 gchar *label = g_strdup_printf ("Button %d", n);
38 GtkWidget *widget = gtk_button_new_with_label (label);
41 gtk_widget_show_all (widget);
43 if (g_list_length (toolbar->children) == 0)
46 position = g_random_int_range (0, g_list_length (toolbar->children));
48 gtk_toolbar_insert_widget (toolbar, widget, "Bar", "Baz", position);
52 remove_random (GtkToolbar *toolbar)
54 GtkToolbarChild *child;
57 if (!toolbar->children)
60 position = g_random_int_range (0, g_list_length (toolbar->children));
62 child = g_list_nth_data (toolbar->children, position);
64 gtk_container_remove (GTK_CONTAINER (toolbar), child->widget);
68 stress_test_old_api (gpointer data)
79 if (info->counter++ == 200)
87 info->toolbar = GTK_TOOLBAR (gtk_toolbar_new ());
88 gtk_container_add (GTK_CONTAINER (info->window),
89 GTK_WIDGET (info->toolbar));
90 gtk_widget_show (GTK_WIDGET (info->toolbar));
93 if (!info->toolbar->children)
95 add_random (info->toolbar, info->counter);
98 else if (g_list_length (info->toolbar->children) > 50)
101 for (i = 0; i < 25; i++)
102 remove_random (info->toolbar);
106 action = g_random_int_range (0, LAST_ACTION);
111 add_random (info->toolbar, info->counter);
115 remove_random (info->toolbar);
119 g_assert_not_reached();
128 main (gint argc, gchar **argv)
132 gtk_init (&argc, &argv);
136 info.window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL));
138 gtk_widget_show (GTK_WIDGET (info.window));
140 g_idle_add (stress_test_old_api, &info);
142 gtk_widget_show_all (GTK_WIDGET (info.window));
146 gtk_widget_destroy (GTK_WIDGET (info.window));