1 /*
2 * Copyright (C) 2019 Alexander Mikhaylenko <exalm7659@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1+
5 */
6
7 #include <adwaita.h>
8
9 int notified;
10
11 static void
notify_cb(GtkWidget * widget,gpointer data)12 notify_cb (GtkWidget *widget, gpointer data)
13 {
14 notified++;
15 }
16
17 static void
test_adw_carousel_add_remove(void)18 test_adw_carousel_add_remove (void)
19 {
20 AdwCarousel *carousel;
21 GtkWidget *child1, *child2, *child3;
22
23 carousel = ADW_CAROUSEL (adw_carousel_new ());
24
25 child1 = gtk_label_new ("");
26 child2 = gtk_label_new ("");
27 child3 = gtk_label_new ("");
28
29 notified = 0;
30 g_signal_connect (carousel, "notify::n-pages", G_CALLBACK (notify_cb), NULL);
31
32 g_assert_cmpuint (adw_carousel_get_n_pages (carousel), ==, 0);
33
34 adw_carousel_append (carousel, child1);
35 g_assert_cmpuint (adw_carousel_get_n_pages (carousel), ==, 1);
36 g_assert_cmpint (notified, ==, 1);
37
38 adw_carousel_prepend (carousel, child2);
39 g_assert_cmpuint (adw_carousel_get_n_pages (carousel), ==, 2);
40 g_assert_cmpint (notified, ==, 2);
41
42 adw_carousel_insert (carousel, child3, 1);
43 g_assert_cmpuint (adw_carousel_get_n_pages (carousel), ==, 3);
44 g_assert_cmpint (notified, ==, 3);
45
46 adw_carousel_reorder (carousel, child3, 0);
47 g_assert_cmpuint (adw_carousel_get_n_pages (carousel), ==, 3);
48 g_assert_cmpint (notified, ==, 3);
49
50 adw_carousel_remove (carousel, child1);
51 g_assert_cmpuint (adw_carousel_get_n_pages (carousel), ==, 2);
52 g_assert_cmpint (notified, ==, 4);
53
54 adw_carousel_remove (carousel, child2);
55 g_assert_cmpuint (adw_carousel_get_n_pages (carousel), ==, 1);
56 g_assert_cmpint (notified, ==, 5);
57
58 adw_carousel_remove (carousel, child3);
59 g_assert_cmpuint (adw_carousel_get_n_pages (carousel), ==, 0);
60 g_assert_cmpint (notified, ==, 6);
61
62 g_object_unref (carousel);
63 }
64
65 static void
test_adw_carousel_interactive(void)66 test_adw_carousel_interactive (void)
67 {
68 AdwCarousel *carousel = ADW_CAROUSEL (adw_carousel_new ());
69 gboolean interactive;
70
71 notified = 0;
72 g_signal_connect (carousel, "notify::interactive", G_CALLBACK (notify_cb), NULL);
73
74 /* Accessors */
75 g_assert_true (adw_carousel_get_interactive (carousel));
76 adw_carousel_set_interactive (carousel, FALSE);
77 g_assert_false (adw_carousel_get_interactive (carousel));
78 g_assert_cmpint (notified, ==, 1);
79
80 /* Property */
81 g_object_set (carousel, "interactive", TRUE, NULL);
82 g_object_get (carousel, "interactive", &interactive, NULL);
83 g_assert_true (interactive);
84 g_assert_cmpint (notified, ==, 2);
85
86 /* Setting the same value should not notify */
87 adw_carousel_set_interactive (carousel, TRUE);
88 g_assert_cmpint (notified, ==, 2);
89 }
90
91 static void
test_adw_carousel_spacing(void)92 test_adw_carousel_spacing (void)
93 {
94 AdwCarousel *carousel = ADW_CAROUSEL (adw_carousel_new ());
95 guint spacing;
96
97 notified = 0;
98 g_signal_connect (carousel, "notify::spacing", G_CALLBACK (notify_cb), NULL);
99
100 /* Accessors */
101 g_assert_cmpuint (adw_carousel_get_spacing (carousel), ==, 0);
102 adw_carousel_set_spacing (carousel, 12);
103 g_assert_cmpuint (adw_carousel_get_spacing (carousel), ==, 12);
104 g_assert_cmpint (notified, ==, 1);
105
106 /* Property */
107 g_object_set (carousel, "spacing", 6, NULL);
108 g_object_get (carousel, "spacing", &spacing, NULL);
109 g_assert_cmpuint (spacing, ==, 6);
110 g_assert_cmpint (notified, ==, 2);
111
112 /* Setting the same value should not notify */
113 adw_carousel_set_spacing (carousel, 6);
114 g_assert_cmpint (notified, ==, 2);
115 }
116
117 static void
test_adw_carousel_animation_duration(void)118 test_adw_carousel_animation_duration (void)
119 {
120 AdwCarousel *carousel = ADW_CAROUSEL (adw_carousel_new ());
121 guint duration;
122
123 notified = 0;
124 g_signal_connect (carousel, "notify::animation-duration", G_CALLBACK (notify_cb), NULL);
125
126 /* Accessors */
127 g_assert_cmpuint (adw_carousel_get_animation_duration (carousel), ==, 250);
128 adw_carousel_set_animation_duration (carousel, 200);
129 g_assert_cmpuint (adw_carousel_get_animation_duration (carousel), ==, 200);
130 g_assert_cmpint (notified, ==, 1);
131
132 /* Property */
133 g_object_set (carousel, "animation-duration", 500, NULL);
134 g_object_get (carousel, "animation-duration", &duration, NULL);
135 g_assert_cmpuint (duration, ==, 500);
136 g_assert_cmpint (notified, ==, 2);
137
138 /* Setting the same value should not notify */
139 adw_carousel_set_animation_duration (carousel, 500);
140 g_assert_cmpint (notified, ==, 2);
141 }
142
143 static void
test_adw_carousel_allow_mouse_drag(void)144 test_adw_carousel_allow_mouse_drag (void)
145 {
146 AdwCarousel *carousel = ADW_CAROUSEL (adw_carousel_new ());
147 gboolean allow_mouse_drag;
148
149 notified = 0;
150 g_signal_connect (carousel, "notify::allow-mouse-drag", G_CALLBACK (notify_cb), NULL);
151
152 /* Accessors */
153 g_assert_true (adw_carousel_get_allow_mouse_drag (carousel));
154 adw_carousel_set_allow_mouse_drag (carousel, FALSE);
155 g_assert_false (adw_carousel_get_allow_mouse_drag (carousel));
156 g_assert_cmpint (notified, ==, 1);
157
158 /* Property */
159 g_object_set (carousel, "allow-mouse-drag", TRUE, NULL);
160 g_object_get (carousel, "allow-mouse-drag", &allow_mouse_drag, NULL);
161 g_assert_true (allow_mouse_drag);
162 g_assert_cmpint (notified, ==, 2);
163
164 /* Setting the same value should not notify */
165 adw_carousel_set_allow_mouse_drag (carousel, TRUE);
166 g_assert_cmpint (notified, ==, 2);
167 }
168
169 static void
test_adw_carousel_allow_long_swipes(void)170 test_adw_carousel_allow_long_swipes (void)
171 {
172 AdwCarousel *carousel = ADW_CAROUSEL (adw_carousel_new ());
173 gboolean allow_long_swipes;
174
175 notified = 0;
176 g_signal_connect (carousel, "notify::allow-long-swipes", G_CALLBACK (notify_cb), NULL);
177
178 /* Accessors */
179 g_assert_false (adw_carousel_get_allow_long_swipes (carousel));
180 adw_carousel_set_allow_long_swipes (carousel, TRUE);
181 g_assert_true (adw_carousel_get_allow_long_swipes (carousel));
182 g_assert_cmpint (notified, ==, 1);
183
184 /* Property */
185 g_object_set (carousel, "allow-long-swipes", FALSE, NULL);
186 g_object_get (carousel, "allow-long-swipes", &allow_long_swipes, NULL);
187 g_assert_false (allow_long_swipes);
188 g_assert_cmpint (notified, ==, 2);
189
190 /* Setting the same value should not notify */
191 adw_carousel_set_allow_long_swipes (carousel, FALSE);
192 g_assert_cmpint (notified, ==, 2);
193 }
194
195 static void
test_adw_carousel_reveal_duration(void)196 test_adw_carousel_reveal_duration (void)
197 {
198 AdwCarousel *carousel = ADW_CAROUSEL (adw_carousel_new ());
199 guint duration;
200
201 notified = 0;
202 g_signal_connect (carousel, "notify::reveal-duration", G_CALLBACK (notify_cb), NULL);
203
204 /* Accessors */
205 g_assert_cmpuint (adw_carousel_get_reveal_duration (carousel), ==, 0);
206 adw_carousel_set_reveal_duration (carousel, 200);
207 g_assert_cmpuint (adw_carousel_get_reveal_duration (carousel), ==, 200);
208 g_assert_cmpint (notified, ==, 1);
209
210 /* Property */
211 g_object_set (carousel, "reveal-duration", 500, NULL);
212 g_object_get (carousel, "reveal-duration", &duration, NULL);
213 g_assert_cmpuint (duration, ==, 500);
214 g_assert_cmpint (notified, ==, 2);
215
216 /* Setting the same value should not notify */
217 adw_carousel_set_reveal_duration (carousel, 500);
218 g_assert_cmpint (notified, ==, 2);
219 }
220
221 int
main(int argc,char * argv[])222 main (int argc,
223 char *argv[])
224 {
225 gtk_test_init (&argc, &argv, NULL);
226 adw_init ();
227
228 g_test_add_func("/Adwaita/Carousel/add_remove", test_adw_carousel_add_remove);
229 g_test_add_func("/Adwaita/Carousel/interactive", test_adw_carousel_interactive);
230 g_test_add_func("/Adwaita/Carousel/spacing", test_adw_carousel_spacing);
231 g_test_add_func("/Adwaita/Carousel/animation_duration", test_adw_carousel_animation_duration);
232 g_test_add_func("/Adwaita/Carousel/allow_mouse_drag", test_adw_carousel_allow_mouse_drag);
233 g_test_add_func("/Adwaita/Carousel/allow_long_swipes", test_adw_carousel_allow_long_swipes);
234 g_test_add_func("/Adwaita/Carousel/reveal_duration", test_adw_carousel_reveal_duration);
235 return g_test_run();
236 }
237