]> Pileus Git - ~andy/gtk/blob - gtk/tests/expander.c
853b20aada74f87396f7f5c7c85dcb8e0df98158
[~andy/gtk] / gtk / tests / expander.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2001.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26 #include <gtk/gtk.h>
27
28 static void
29 test_click_expander (void)
30 {
31   GtkWidget *window = gtk_test_create_simple_window ("Test Window", "Test click on expander");
32   GtkWidget *expander = gtk_expander_new ("Test Expander");
33   GtkWidget *label = gtk_label_new ("Test Label");
34   gboolean expanded;
35   gboolean simsuccess;
36   gtk_container_add (GTK_CONTAINER (expander), label);
37   gtk_container_add (GTK_CONTAINER (GTK_BIN (window)->child), expander);
38   gtk_widget_show (expander);
39   gtk_widget_show (label);
40   gtk_widget_show_now (window);
41   /* check initial expander state */
42   expanded = gtk_expander_get_expanded (GTK_EXPANDER (expander));
43   g_assert (!expanded);
44   /* check expanding */
45   simsuccess = gtk_test_widget_click (expander, 1, 0);
46   g_assert (simsuccess == TRUE);
47   while (gtk_events_pending ()) /* let expander timeout/idle handlers update */
48     gtk_main_iteration ();
49   expanded = gtk_expander_get_expanded (GTK_EXPANDER (expander));
50   g_assert (expanded);
51   /* check collapsing */
52   simsuccess = gtk_test_widget_click (expander, 1, 0);
53   g_assert (simsuccess == TRUE);
54   while (gtk_events_pending ()) /* let expander timeout/idle handlers update */
55     gtk_main_iteration ();
56   expanded = gtk_expander_get_expanded (GTK_EXPANDER (expander));
57   g_assert (!expanded);
58 }
59
60 static void
61 test_click_content_widget (void)
62 {
63   GtkWidget *window = gtk_test_create_simple_window ("Test Window", "Test click on content widget");
64   GtkWidget *expander = gtk_expander_new ("Test Expander");
65   GtkWidget *entry = gtk_entry_new ();
66   gboolean expanded;
67   gboolean simsuccess;
68   gtk_container_add (GTK_CONTAINER (expander), entry);
69   gtk_container_add (GTK_CONTAINER (GTK_BIN (window)->child), expander);
70   gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
71   gtk_widget_show (expander);
72   gtk_widget_show (entry);
73   gtk_widget_show_now (window);
74
75   /* check click on content with expander open */
76   expanded = gtk_expander_get_expanded (GTK_EXPANDER (expander));
77   g_assert (expanded);
78   simsuccess = gtk_test_widget_click (entry, 1, 0);
79   g_assert (simsuccess == TRUE);
80   while (gtk_events_pending ()) /* let expander timeout/idle handlers update */
81     gtk_main_iteration ();
82   expanded = gtk_expander_get_expanded (GTK_EXPANDER (expander));
83   g_assert (expanded);
84 }
85
86 int
87 main (int   argc,
88       char *argv[])
89 {
90   gtk_test_init (&argc, &argv);
91   g_test_add_func ("/expander/click-expander", test_click_expander);
92   g_test_add_func ("/expander/click-content-widget", test_click_content_widget);
93   return g_test_run();
94 }