[libadwaita/wip/exalm/carousel-fix: 13/13] carousel: Add proper tests for insert()
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/carousel-fix: 13/13] carousel: Add proper tests for insert()
- Date: Wed, 29 Dec 2021 08:13:02 +0000 (UTC)
commit ea1573cf40ee2f71cb2a6ddfcebdfd4e2b18aa7a
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Wed Dec 29 13:13:00 2021 +0500
carousel: Add proper tests for insert()
Check that the widgets are in the correct order and position shifting
works.
tests/test-carousel.c | 40 ++++++++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 14 deletions(-)
---
diff --git a/tests/test-carousel.c b/tests/test-carousel.c
index 44cdb9b2..1bc87c33 100644
--- a/tests/test-carousel.c
+++ b/tests/test-carousel.c
@@ -14,6 +14,18 @@ notify_cb (GtkWidget *widget, gpointer data)
notified++;
}
+static void
+allocate_carousel (AdwCarousel *carousel)
+{
+ int width, height;
+
+ gtk_widget_measure (GTK_WIDGET (carousel), GTK_ORIENTATION_HORIZONTAL, -1,
+ NULL, &width, NULL, NULL);
+ gtk_widget_measure (GTK_WIDGET (carousel), GTK_ORIENTATION_VERTICAL, -1,
+ NULL, &height, NULL, NULL);
+ gtk_widget_allocate (GTK_WIDGET (carousel), width, height, 0, NULL);
+}
+
static void
test_adw_carousel_add_remove (void)
{
@@ -34,36 +46,36 @@ test_adw_carousel_add_remove (void)
g_assert_cmpint (notified, ==, 1);
adw_carousel_prepend (carousel, child2);
+ allocate_carousel (carousel);
g_assert_cmpuint (adw_carousel_get_n_pages (carousel), ==, 2);
+ g_assert_true (adw_carousel_get_nth_page (carousel, 0) == child2);
+ g_assert_true (adw_carousel_get_nth_page (carousel, 1) == child1);
+ g_assert_cmpfloat (adw_carousel_get_position (carousel), ==, 1);
g_assert_cmpint (notified, ==, 2);
adw_carousel_insert (carousel, child3, 1);
+ allocate_carousel (carousel);
g_assert_cmpuint (adw_carousel_get_n_pages (carousel), ==, 3);
+ g_assert_true (adw_carousel_get_nth_page (carousel, 0) == child2);
+ g_assert_true (adw_carousel_get_nth_page (carousel, 1) == child3);
+ g_assert_true (adw_carousel_get_nth_page (carousel, 2) == child1);
+ g_assert_cmpfloat (adw_carousel_get_position (carousel), ==, 2);
g_assert_cmpint (notified, ==, 3);
- adw_carousel_remove (carousel, child1);
+ adw_carousel_scroll_to (carousel, child3, FALSE);
+ adw_carousel_remove (carousel, child2);
+ allocate_carousel (carousel);
g_assert_cmpuint (adw_carousel_get_n_pages (carousel), ==, 2);
+ g_assert_cmpfloat (adw_carousel_get_position (carousel), ==, 0);
g_assert_cmpint (notified, ==, 4);
- adw_carousel_remove (carousel, child2);
+ adw_carousel_remove (carousel, child1);
g_assert_cmpuint (adw_carousel_get_n_pages (carousel), ==, 1);
g_assert_cmpint (notified, ==, 5);
g_assert_finalize_object (carousel);
}
-static void
-allocate_carousel (AdwCarousel *carousel)
-{
- int width, height;
-
- gtk_widget_measure (GTK_WIDGET (carousel), GTK_ORIENTATION_HORIZONTAL, -1,
- NULL, &width, NULL, NULL);
- gtk_widget_measure (GTK_WIDGET (carousel), GTK_ORIENTATION_VERTICAL, -1,
- NULL, &height, NULL, NULL);
- gtk_widget_allocate (GTK_WIDGET (carousel), width, height, 0, NULL);
-}
-
static void
assert_carousel_positions (AdwCarousel *carousel,
GtkWidget *child1,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]