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, see <http://www.gnu.org/licenses/>.
21 typedef struct _Info Info;
30 add_random (GtkToolbar *toolbar, gint n)
34 gchar *label = g_strdup_printf ("Button %d", n);
36 GtkToolItem *toolitem = gtk_tool_button_new (NULL, label);
37 gtk_tool_item_set_tooltip_text (toolitem, "Bar");
40 gtk_widget_show_all (GTK_WIDGET (toolitem));
42 n_items = gtk_toolbar_get_n_items (toolbar);
46 position = g_random_int_range (0, n_items);
48 gtk_toolbar_insert (toolbar, toolitem, position);
52 remove_random (GtkToolbar *toolbar)
54 GtkToolItem *tool_item;
58 n_items = gtk_toolbar_get_n_items (toolbar);
63 position = g_random_int_range (0, n_items);
65 tool_item = gtk_toolbar_get_nth_item (toolbar, position);
67 gtk_container_remove (GTK_CONTAINER (toolbar),
68 GTK_WIDGET (tool_item));
72 stress_test_old_api (gpointer data)
84 if (info->counter++ == 200)
92 info->toolbar = GTK_TOOLBAR (gtk_toolbar_new ());
93 gtk_container_add (GTK_CONTAINER (info->window),
94 GTK_WIDGET (info->toolbar));
95 gtk_widget_show (GTK_WIDGET (info->toolbar));
98 n_items = gtk_toolbar_get_n_items (info->toolbar);
101 add_random (info->toolbar, info->counter);
104 else if (n_items > 50)
107 for (i = 0; i < 25; i++)
108 remove_random (info->toolbar);
112 action = g_random_int_range (0, LAST_ACTION);
117 add_random (info->toolbar, info->counter);
121 remove_random (info->toolbar);
125 g_assert_not_reached();
134 main (gint argc, gchar **argv)
138 gtk_init (&argc, &argv);
142 info.window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL));
144 gtk_widget_show (GTK_WIDGET (info.window));
146 gdk_threads_add_idle (stress_test_old_api, &info);
148 gtk_widget_show_all (GTK_WIDGET (info.window));
152 gtk_widget_destroy (GTK_WIDGET (info.window));