1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
/*
* Copyright (C) 2019 Alexander Mikhaylenko <exalm7659@gmail.com>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <handy.h>
gint notified;
static void
notify_cb (GtkWidget *widget, gpointer data)
{
notified++;
}
static void
test_hdy_carousel_add_remove (void)
{
HdyCarousel *carousel;
GtkWidget *child1, *child2, *child3;
carousel = g_object_ref_sink (HDY_CAROUSEL (hdy_carousel_new ()));
child1 = gtk_label_new ("");
child2 = gtk_label_new ("");
child3 = gtk_label_new ("");
notified = 0;
g_signal_connect (carousel, "notify::n-pages", G_CALLBACK (notify_cb), NULL);
g_assert_cmpuint (hdy_carousel_get_n_pages (carousel), ==, 0);
gtk_container_add (GTK_CONTAINER (carousel), child1);
g_assert_cmpuint (hdy_carousel_get_n_pages (carousel), ==, 1);
g_assert_cmpint (notified, ==, 1);
hdy_carousel_prepend (carousel, child2);
g_assert_cmpuint (hdy_carousel_get_n_pages (carousel), ==, 2);
g_assert_cmpint (notified, ==, 2);
hdy_carousel_insert (carousel, child3, 1);
g_assert_cmpuint (hdy_carousel_get_n_pages (carousel), ==, 3);
g_assert_cmpint (notified, ==, 3);
hdy_carousel_reorder (carousel, child3, 0);
g_assert_cmpuint (hdy_carousel_get_n_pages (carousel), ==, 3);
g_assert_cmpint (notified, ==, 3);
gtk_container_remove (GTK_CONTAINER (carousel), child2);
g_assert_cmpuint (hdy_carousel_get_n_pages (carousel), ==, 2);
g_assert_cmpint (notified, ==, 4);
gtk_container_remove (GTK_CONTAINER (carousel), child1);
g_assert_cmpuint (hdy_carousel_get_n_pages (carousel), ==, 1);
g_assert_cmpint (notified, ==, 5);
gtk_container_remove (GTK_CONTAINER (carousel), child3);
g_assert_cmpuint (hdy_carousel_get_n_pages (carousel), ==, 0);
g_assert_cmpint (notified, ==, 6);
g_object_unref (carousel);
}
static void
test_hdy_carousel_scroll_to (void)
{
HdyCarousel *carousel;
GtkWidget *child1, *child2, *child3;
carousel = g_object_ref_sink (HDY_CAROUSEL (hdy_carousel_new ()));
child1 = gtk_label_new ("");
child2 = gtk_label_new ("");
child3 = gtk_label_new ("");
notified = 0;
g_signal_connect (carousel, "notify::position", G_CALLBACK (notify_cb), NULL);
gtk_container_add (GTK_CONTAINER (carousel), child1);
gtk_container_add (GTK_CONTAINER (carousel), child2);
gtk_container_add (GTK_CONTAINER (carousel), child3);
/* Since tests are done synchronously, avoid animations */
hdy_carousel_set_animation_duration (carousel, 0);
g_assert_cmpfloat(hdy_carousel_get_position (carousel), ==, 0);
g_assert_cmpint (notified, ==, 0);
hdy_carousel_scroll_to (carousel, child3);
g_assert_cmpfloat(hdy_carousel_get_position (carousel), ==, 2);
g_assert_cmpint (notified, ==, 1);
hdy_carousel_scroll_to (carousel, child2);
g_assert_cmpfloat(hdy_carousel_get_position (carousel), ==, 1);
g_assert_cmpint (notified, ==, 2);
g_object_unref (carousel);
}
static void
test_hdy_carousel_interactive (void)
{
g_autoptr (HdyCarousel) carousel = g_object_ref_sink (HDY_CAROUSEL (hdy_carousel_new ()));
gboolean interactive;
notified = 0;
g_signal_connect (carousel, "notify::interactive", G_CALLBACK (notify_cb), NULL);
/* Accessors */
g_assert_true (hdy_carousel_get_interactive (carousel));
hdy_carousel_set_interactive (carousel, FALSE);
g_assert_false (hdy_carousel_get_interactive (carousel));
g_assert_cmpint (notified, ==, 1);
/* Property */
g_object_set (carousel, "interactive", TRUE, NULL);
g_object_get (carousel, "interactive", &interactive, NULL);
g_assert_true (interactive);
g_assert_cmpint (notified, ==, 2);
/* Setting the same value should not notify */
hdy_carousel_set_interactive (carousel, TRUE);
g_assert_cmpint (notified, ==, 2);
}
static void
test_hdy_carousel_spacing (void)
{
g_autoptr (HdyCarousel) carousel = g_object_ref_sink (HDY_CAROUSEL (hdy_carousel_new ()));
guint spacing;
notified = 0;
g_signal_connect (carousel, "notify::spacing", G_CALLBACK (notify_cb), NULL);
/* Accessors */
g_assert_cmpuint (hdy_carousel_get_spacing (carousel), ==, 0);
hdy_carousel_set_spacing (carousel, 12);
g_assert_cmpuint (hdy_carousel_get_spacing (carousel), ==, 12);
g_assert_cmpint (notified, ==, 1);
/* Property */
g_object_set (carousel, "spacing", 6, NULL);
g_object_get (carousel, "spacing", &spacing, NULL);
g_assert_cmpuint (spacing, ==, 6);
g_assert_cmpint (notified, ==, 2);
/* Setting the same value should not notify */
hdy_carousel_set_spacing (carousel, 6);
g_assert_cmpint (notified, ==, 2);
}
static void
test_hdy_carousel_animation_duration (void)
{
g_autoptr (HdyCarousel) carousel = g_object_ref_sink (HDY_CAROUSEL (hdy_carousel_new ()));
guint duration;
notified = 0;
g_signal_connect (carousel, "notify::animation-duration", G_CALLBACK (notify_cb), NULL);
/* Accessors */
g_assert_cmpuint (hdy_carousel_get_animation_duration (carousel), ==, 250);
hdy_carousel_set_animation_duration (carousel, 200);
g_assert_cmpuint (hdy_carousel_get_animation_duration (carousel), ==, 200);
g_assert_cmpint (notified, ==, 1);
/* Property */
g_object_set (carousel, "animation-duration", 500, NULL);
g_object_get (carousel, "animation-duration", &duration, NULL);
g_assert_cmpuint (duration, ==, 500);
g_assert_cmpint (notified, ==, 2);
/* Setting the same value should not notify */
hdy_carousel_set_animation_duration (carousel, 500);
g_assert_cmpint (notified, ==, 2);
}
static void
test_hdy_carousel_allow_mouse_drag (void)
{
g_autoptr (HdyCarousel) carousel = g_object_ref_sink (HDY_CAROUSEL (hdy_carousel_new ()));
gboolean allow_mouse_drag;
notified = 0;
g_signal_connect (carousel, "notify::allow-mouse-drag", G_CALLBACK (notify_cb), NULL);
/* Accessors */
g_assert_true (hdy_carousel_get_allow_mouse_drag (carousel));
hdy_carousel_set_allow_mouse_drag (carousel, FALSE);
g_assert_false (hdy_carousel_get_allow_mouse_drag (carousel));
g_assert_cmpint (notified, ==, 1);
/* Property */
g_object_set (carousel, "allow-mouse-drag", TRUE, NULL);
g_object_get (carousel, "allow-mouse-drag", &allow_mouse_drag, NULL);
g_assert_true (allow_mouse_drag);
g_assert_cmpint (notified, ==, 2);
/* Setting the same value should not notify */
hdy_carousel_set_allow_mouse_drag (carousel, TRUE);
g_assert_cmpint (notified, ==, 2);
}
static void
test_hdy_carousel_allow_long_swipes (void)
{
g_autoptr (HdyCarousel) carousel = g_object_ref_sink (HDY_CAROUSEL (hdy_carousel_new ()));
gboolean allow_long_swipes;
notified = 0;
g_signal_connect (carousel, "notify::allow-long-swipes", G_CALLBACK (notify_cb), NULL);
/* Accessors */
g_assert_false (hdy_carousel_get_allow_long_swipes (carousel));
hdy_carousel_set_allow_long_swipes (carousel, TRUE);
g_assert_true (hdy_carousel_get_allow_long_swipes (carousel));
g_assert_cmpint (notified, ==, 1);
/* Property */
g_object_set (carousel, "allow-long-swipes", FALSE, NULL);
g_object_get (carousel, "allow-long-swipes", &allow_long_swipes, NULL);
g_assert_false (allow_long_swipes);
g_assert_cmpint (notified, ==, 2);
/* Setting the same value should not notify */
hdy_carousel_set_allow_long_swipes (carousel, FALSE);
g_assert_cmpint (notified, ==, 2);
}
static void
test_hdy_carousel_reveal_duration (void)
{
g_autoptr (HdyCarousel) carousel = g_object_ref_sink (HDY_CAROUSEL (hdy_carousel_new ()));
guint duration;
notified = 0;
g_signal_connect (carousel, "notify::reveal-duration", G_CALLBACK (notify_cb), NULL);
/* Accessors */
g_assert_cmpuint (hdy_carousel_get_reveal_duration (carousel), ==, 0);
hdy_carousel_set_reveal_duration (carousel, 200);
g_assert_cmpuint (hdy_carousel_get_reveal_duration (carousel), ==, 200);
g_assert_cmpint (notified, ==, 1);
/* Property */
g_object_set (carousel, "reveal-duration", 500, NULL);
g_object_get (carousel, "reveal-duration", &duration, NULL);
g_assert_cmpuint (duration, ==, 500);
g_assert_cmpint (notified, ==, 2);
/* Setting the same value should not notify */
hdy_carousel_set_reveal_duration (carousel, 500);
g_assert_cmpint (notified, ==, 2);
}
gint
main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
hdy_init ();
g_test_add_func("/Handy/Carousel/add_remove", test_hdy_carousel_add_remove);
g_test_add_func("/Handy/Carousel/scroll_to", test_hdy_carousel_scroll_to);
g_test_add_func("/Handy/Carousel/interactive", test_hdy_carousel_interactive);
g_test_add_func("/Handy/Carousel/spacing", test_hdy_carousel_spacing);
g_test_add_func("/Handy/Carousel/animation_duration", test_hdy_carousel_animation_duration);
g_test_add_func("/Handy/Carousel/allow_mouse_drag", test_hdy_carousel_allow_mouse_drag);
g_test_add_func("/Handy/Carousel/allow_long_swipes", test_hdy_carousel_allow_long_swipes);
g_test_add_func("/Handy/Carousel/reveal_duration", test_hdy_carousel_reveal_duration);
return g_test_run();
}
|