Debian Codegraph @

testsuite/gtk/revealer-size.c

raw
1 #include <gtk/gtk.h>
2
3 const int KEEP_HEIGHT = 1 << 0;
4 const int KEEP_WIDTH = 1 << 1;
5
6 static void
7 keep_size (int direction,
8 guint transition_type,
9 gboolean animations)
10 {
11 gboolean animations_before;
12 int min_height, min_width;
13 int min_child_width, min_child_height;
14 GtkRevealer *revealer = GTK_REVEALER (gtk_revealer_new ());
15 GtkWidget *child = gtk_button_new_with_label ("Some Text!");
16 GtkSettings *settings = gtk_settings_get_default ();
17
18 g_object_get (settings, "gtk-enable-animations", &animations_before, NULL);
19 g_object_set (settings, "gtk-enable-animations", animations, NULL);
20
21 gtk_container_add (GTK_CONTAINER (revealer), child);
22 gtk_widget_show_all (GTK_WIDGET (revealer));
23
24 gtk_revealer_set_transition_type (revealer, transition_type);
25
26 gtk_revealer_set_reveal_child (revealer, TRUE);
27
28 gtk_widget_get_preferred_width (GTK_WIDGET (child), &min_child_width, NULL);
29 gtk_widget_get_preferred_height (GTK_WIDGET (child), &min_child_height, NULL);
30
31 gtk_widget_get_preferred_width (GTK_WIDGET (revealer), &min_width, NULL);
32 gtk_widget_get_preferred_height (GTK_WIDGET (revealer), &min_height, NULL);
33
34 g_assert_cmpint (min_width, ==, min_child_width);
35 g_assert_cmpint (min_height, ==, min_child_height);
36
37
38 gtk_revealer_set_reveal_child (revealer, FALSE);
39 gtk_widget_get_preferred_width (GTK_WIDGET (revealer), &min_width, NULL);
40 gtk_widget_get_preferred_height (GTK_WIDGET (revealer), &min_height, NULL);
41
42 if (direction & KEEP_WIDTH)
43 g_assert_cmpint (min_width, ==, min_child_width);
44 else
45 g_assert_cmpint (min_width, ==, 0);
46
47 if (direction & KEEP_HEIGHT)
48 g_assert_cmpint (min_height, ==, min_child_height);
49 else
50 g_assert_cmpint (min_height, ==, 0);
51
52 g_object_set (settings, "gtk-enable-animations", animations_before, NULL);
53 }
54
55
56 static void
57 slide_right_animations ()
58 {
59 keep_size (KEEP_HEIGHT, GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT, TRUE);
60 }
61
62 static void
63 slide_right_no_animations ()
64 {
65 keep_size (KEEP_HEIGHT, GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT, FALSE);
66 }
67
68 static void
69 slide_left_animations ()
70 {
71 keep_size (KEEP_HEIGHT, GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT, TRUE);
72 }
73
74 static void
75 slide_left_no_animations ()
76 {
77 keep_size (KEEP_HEIGHT, GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT, FALSE);
78 }
79
80 static void
81 none_animations ()
82 {
83 keep_size (0, GTK_REVEALER_TRANSITION_TYPE_NONE, TRUE);
84 }
85
86 static void
87 none_no_animations ()
88 {
89 keep_size (0, GTK_REVEALER_TRANSITION_TYPE_NONE, FALSE);
90 }
91
92 static void
93 crossfade_animations()
94 {
95 keep_size (KEEP_WIDTH | KEEP_HEIGHT, GTK_REVEALER_TRANSITION_TYPE_CROSSFADE, TRUE);
96 }
97
98 static void
99 crossfade_no_animations ()
100 {
101 keep_size (KEEP_WIDTH | KEEP_HEIGHT, GTK_REVEALER_TRANSITION_TYPE_CROSSFADE, FALSE);
102 }
103
104 static void
105 slide_down_animations ()
106 {
107 keep_size (KEEP_WIDTH, GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN, TRUE);
108 }
109
110 static void
111 slide_down_no_animations ()
112 {
113 keep_size (KEEP_WIDTH, GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN, FALSE);
114 }
115
116 static void
117 slide_up_animations ()
118 {
119 keep_size (KEEP_WIDTH, GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP, TRUE);
120 }
121
122 static void
123 slide_up_no_animations ()
124 {
125 keep_size (KEEP_WIDTH, GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP, FALSE);
126 }
127
128 int
129 main (int argc, char **argv)
130 {
131 gtk_init (&argc, &argv);
132 g_test_init (&argc, &argv, NULL);
133
134 g_test_add_func ("/sizing/revealer/slide_right_animations", slide_right_animations);
135 g_test_add_func ("/sizing/revealer/slide_right_no_animations", slide_right_no_animations);
136
137 g_test_add_func ("/sizing/revealer/slide_left_animations", slide_left_animations);
138 g_test_add_func ("/sizing/revealer/slide_left_no_animations", slide_left_no_animations);
139
140 g_test_add_func ("/sizing/revealer/none_animations", none_animations);
141 g_test_add_func ("/sizing/revealer/none_no_animations", none_no_animations);
142
143 g_test_add_func ("/sizing/revealer/crossfade_animations", crossfade_animations);
144 g_test_add_func ("/sizing/revealer/crossfade_no_animations", crossfade_no_animations);
145
146 g_test_add_func ("/sizing/revealer/slide_down_animations", slide_down_animations);
147 g_test_add_func ("/sizing/revealer/slide_down_no_animations", slide_down_no_animations);
148
149 g_test_add_func ("/sizing/revealer/slide_up_animations", slide_up_animations);
150 g_test_add_func ("/sizing/revealer/slide_up_no_animations", slide_up_no_animations);
151
152 return g_test_run ();
153 }