[libhandy/wip/exalm/alpha-fixes: 6/8] tests: Fix leaks




commit b9ff81b628f2241aa25949b0c29c7cfc00c1d835
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Nov 12 00:23:38 2021 +0500

    tests: Fix leaks
    
    Backport parts of 
https://gitlab.gnome.org/GNOME/libadwaita/-/commit/466509f6120866005ea2e8c2cdb2ddb83a39cc40

 tests/test-avatar.c      | 13 +++++--------
 tests/test-carousel.c    | 16 ++++++++--------
 tests/test-deck.c        | 10 +++++-----
 tests/test-leaflet.c     | 10 +++++-----
 tests/test-status-page.c |  4 ++--
 tests/test-swipe-group.c |  4 ++--
 tests/test-tab-view.c    | 25 ++++++++-----------------
 7 files changed, 35 insertions(+), 47 deletions(-)
---
diff --git a/tests/test-avatar.c b/tests/test-avatar.c
index edba33e9..4e75c151 100644
--- a/tests/test-avatar.c
+++ b/tests/test-avatar.c
@@ -111,7 +111,7 @@ did_draw_something (GtkWidget *widget)
 static void
 test_hdy_avatar_generate (void)
 {
-  GtkWidget *avatar = hdy_avatar_new (TEST_SIZE, "", TRUE);
+  g_autoptr (GtkWidget) avatar = g_object_ref_sink (hdy_avatar_new (TEST_SIZE, "", TRUE));
   g_assert (HDY_IS_AVATAR (avatar));
 
   g_assert_true (did_draw_something (GTK_WIDGET (avatar)));
@@ -121,7 +121,7 @@ test_hdy_avatar_generate (void)
 static void
 test_hdy_avatar_icon_name (void)
 {
-  HdyAvatar *avatar = HDY_AVATAR (hdy_avatar_new (128, NULL, TRUE));
+  g_autoptr (HdyAvatar) avatar = g_object_ref_sink (HDY_AVATAR (hdy_avatar_new (128, NULL, TRUE)));
 
   g_assert_null (hdy_avatar_get_icon_name (avatar));
   hdy_avatar_set_icon_name (avatar, TEST_ICON_NAME);
@@ -133,7 +133,7 @@ test_hdy_avatar_icon_name (void)
 static void
 test_hdy_avatar_text (void)
 {
-  HdyAvatar *avatar = HDY_AVATAR (hdy_avatar_new (128, NULL, TRUE));
+  g_autoptr (HdyAvatar) avatar = g_object_ref_sink (HDY_AVATAR (hdy_avatar_new (128, NULL, TRUE)));
 
   g_assert_null (hdy_avatar_get_text (avatar));
   hdy_avatar_set_text (avatar, TEST_STRING);
@@ -145,7 +145,7 @@ test_hdy_avatar_text (void)
 static void
 test_hdy_avatar_size (void)
 {
-  HdyAvatar *avatar = HDY_AVATAR (hdy_avatar_new (TEST_SIZE, NULL, TRUE));
+  g_autoptr (HdyAvatar) avatar = g_object_ref_sink (HDY_AVATAR (hdy_avatar_new (TEST_SIZE, NULL, TRUE)));
 
   g_assert_cmpint (hdy_avatar_get_size (avatar), ==, TEST_SIZE);
   hdy_avatar_set_size (avatar, TEST_SIZE / 2);
@@ -224,15 +224,12 @@ draw_to_pixbuf_async (HdyAvatar    *avatar,
 
   g_assert_cmpint (gdk_pixbuf_get_width (pixbuf), ==, TEST_SIZE * 2);
   g_assert_cmpint (gdk_pixbuf_get_height (pixbuf), ==, TEST_SIZE * 2);
-  g_object_unref (avatar);
 }
 
 static void
 test_hdy_avatar_draw_to_pixbuf_async (void)
 {
-  HdyAvatar *avatar = NULL;
-
-  avatar = g_object_ref_sink (HDY_AVATAR (hdy_avatar_new (TEST_SIZE, NULL, TRUE)));
+  g_autoptr (HdyAvatar) avatar = g_object_ref_sink (HDY_AVATAR (hdy_avatar_new (TEST_SIZE, NULL, TRUE)));
 
   hdy_avatar_draw_to_pixbuf_async (avatar,
                                    TEST_SIZE * 2,
diff --git a/tests/test-carousel.c b/tests/test-carousel.c
index c9605857..09be4e95 100644
--- a/tests/test-carousel.c
+++ b/tests/test-carousel.c
@@ -20,7 +20,7 @@ test_hdy_carousel_add_remove (void)
   HdyCarousel *carousel;
   GtkWidget *child1, *child2, *child3;
 
-  carousel = HDY_CAROUSEL (hdy_carousel_new ());
+  carousel = g_object_ref_sink (HDY_CAROUSEL (hdy_carousel_new ()));
 
   child1 = gtk_label_new ("");
   child2 = gtk_label_new ("");
@@ -68,7 +68,7 @@ test_hdy_carousel_scroll_to (void)
   HdyCarousel *carousel;
   GtkWidget *child1, *child2, *child3;
 
-  carousel = HDY_CAROUSEL (hdy_carousel_new ());
+  carousel = g_object_ref_sink (HDY_CAROUSEL (hdy_carousel_new ()));
 
   child1 = gtk_label_new ("");
   child2 = gtk_label_new ("");
@@ -101,7 +101,7 @@ test_hdy_carousel_scroll_to (void)
 static void
 test_hdy_carousel_interactive (void)
 {
-  HdyCarousel *carousel = HDY_CAROUSEL (hdy_carousel_new ());
+  g_autoptr (HdyCarousel) carousel = g_object_ref_sink (HDY_CAROUSEL (hdy_carousel_new ()));
   gboolean interactive;
 
   notified = 0;
@@ -127,7 +127,7 @@ test_hdy_carousel_interactive (void)
 static void
 test_hdy_carousel_spacing (void)
 {
-  HdyCarousel *carousel = HDY_CAROUSEL (hdy_carousel_new ());
+  g_autoptr (HdyCarousel) carousel = g_object_ref_sink (HDY_CAROUSEL (hdy_carousel_new ()));
   guint spacing;
 
   notified = 0;
@@ -153,7 +153,7 @@ test_hdy_carousel_spacing (void)
 static void
 test_hdy_carousel_animation_duration (void)
 {
-  HdyCarousel *carousel = HDY_CAROUSEL (hdy_carousel_new ());
+  g_autoptr (HdyCarousel) carousel = g_object_ref_sink (HDY_CAROUSEL (hdy_carousel_new ()));
   guint duration;
 
   notified = 0;
@@ -179,7 +179,7 @@ test_hdy_carousel_animation_duration (void)
 static void
 test_hdy_carousel_allow_mouse_drag (void)
 {
-  HdyCarousel *carousel = HDY_CAROUSEL (hdy_carousel_new ());
+  g_autoptr (HdyCarousel) carousel = g_object_ref_sink (HDY_CAROUSEL (hdy_carousel_new ()));
   gboolean allow_mouse_drag;
 
   notified = 0;
@@ -205,7 +205,7 @@ test_hdy_carousel_allow_mouse_drag (void)
 static void
 test_hdy_carousel_allow_long_swipes (void)
 {
-  HdyCarousel *carousel = HDY_CAROUSEL (hdy_carousel_new ());
+  g_autoptr (HdyCarousel) carousel = g_object_ref_sink (HDY_CAROUSEL (hdy_carousel_new ()));
   gboolean allow_long_swipes;
 
   notified = 0;
@@ -231,7 +231,7 @@ test_hdy_carousel_allow_long_swipes (void)
 static void
 test_hdy_carousel_reveal_duration (void)
 {
-  HdyCarousel *carousel = HDY_CAROUSEL (hdy_carousel_new ());
+  g_autoptr (HdyCarousel) carousel = g_object_ref_sink (HDY_CAROUSEL (hdy_carousel_new ()));
   guint duration;
 
   notified = 0;
diff --git a/tests/test-deck.c b/tests/test-deck.c
index 51ef5129..2b892323 100644
--- a/tests/test-deck.c
+++ b/tests/test-deck.c
@@ -15,7 +15,7 @@ test_hdy_deck_adjacent_child (void)
   gint i;
   GtkWidget *result;
 
-  deck = HDY_DECK (hdy_deck_new ());
+  deck = g_object_ref_sink (HDY_DECK (hdy_deck_new ()));
   g_assert_nonnull (deck);
 
   for (i = 0; i < 2; i++) {
@@ -51,7 +51,7 @@ test_hdy_deck_navigate (void)
   gint i;
   gboolean result;
 
-  deck = HDY_DECK (hdy_deck_new ());
+  deck = g_object_ref_sink (HDY_DECK (hdy_deck_new ()));
   g_assert_nonnull (deck);
 
   result = hdy_deck_navigate (deck, HDY_NAVIGATION_DIRECTION_BACK);
@@ -93,7 +93,7 @@ test_hdy_deck_prepend (void)
   gint i;
   GList *children = NULL;
 
-  deck = HDY_DECK (hdy_deck_new ());
+  deck = g_object_ref_sink (HDY_DECK (hdy_deck_new ()));
   g_assert_nonnull (deck);
 
   for (i = 0; i < 2; i++) {
@@ -122,7 +122,7 @@ test_hdy_deck_insert_child_after (void)
   gint i;
   GList *children = NULL;
 
-  deck = HDY_DECK (hdy_deck_new ());
+  deck = g_object_ref_sink (HDY_DECK (hdy_deck_new ()));
   g_assert_nonnull (deck);
 
   for (i = 0; i < 3; i++) {
@@ -155,7 +155,7 @@ test_hdy_deck_reorder_child_after (void)
   gint i;
   GList *children = NULL;
 
-  deck = HDY_DECK (hdy_deck_new ());
+  deck = g_object_ref_sink (HDY_DECK (hdy_deck_new ()));
   g_assert_nonnull (deck);
 
   for (i = 0; i < 3; i++) {
diff --git a/tests/test-leaflet.c b/tests/test-leaflet.c
index f06ad9a3..ba73f0cc 100644
--- a/tests/test-leaflet.c
+++ b/tests/test-leaflet.c
@@ -15,7 +15,7 @@ test_hdy_leaflet_adjacent_child (void)
   gint i;
   GtkWidget *result;
 
-  leaflet = HDY_LEAFLET (hdy_leaflet_new ());
+  leaflet = g_object_ref_sink (HDY_LEAFLET (hdy_leaflet_new ()));
   g_assert_nonnull (leaflet);
 
   for (i = 0; i < 3; i++) {
@@ -63,7 +63,7 @@ test_hdy_leaflet_navigate (void)
   gint i;
   gboolean result;
 
-  leaflet = HDY_LEAFLET (hdy_leaflet_new ());
+  leaflet = g_object_ref_sink (HDY_LEAFLET (hdy_leaflet_new ()));
   g_assert_nonnull (leaflet);
 
   result = hdy_leaflet_navigate (leaflet, HDY_NAVIGATION_DIRECTION_BACK);
@@ -109,7 +109,7 @@ test_hdy_leaflet_prepend (void)
   gint i;
   GList *children = NULL;
 
-  leaflet = HDY_LEAFLET (hdy_leaflet_new ());
+  leaflet = g_object_ref_sink (HDY_LEAFLET (hdy_leaflet_new ()));
   g_assert_nonnull (leaflet);
 
   for (i = 0; i < 2; i++) {
@@ -138,7 +138,7 @@ test_hdy_leaflet_insert_child_after (void)
   gint i;
   GList *children = NULL;
 
-  leaflet = HDY_LEAFLET (hdy_leaflet_new ());
+  leaflet = g_object_ref_sink (HDY_LEAFLET (hdy_leaflet_new ()));
   g_assert_nonnull (leaflet);
 
   for (i = 0; i < 3; i++) {
@@ -171,7 +171,7 @@ test_hdy_leaflet_reorder_child_after (void)
   gint i;
   GList *children = NULL;
 
-  leaflet = HDY_LEAFLET (hdy_leaflet_new ());
+  leaflet = g_object_ref_sink (HDY_LEAFLET (hdy_leaflet_new ()));
   g_assert_nonnull (leaflet);
 
   for (i = 0; i < 3; i++) {
diff --git a/tests/test-status-page.c b/tests/test-status-page.c
index a3874cef..0ba22bb1 100644
--- a/tests/test-status-page.c
+++ b/tests/test-status-page.c
@@ -45,7 +45,7 @@ static void
 test_hdy_status_page_title (void)
 {
   g_autoptr (HdyStatusPage) status_page = NULL;
-  const gchar *title = NULL;
+  g_autofree gchar *title = NULL;
 
   status_page = HDY_STATUS_PAGE (g_object_ref_sink (hdy_status_page_new ()));
   g_assert_nonnull (status_page);
@@ -72,7 +72,7 @@ static void
 test_hdy_status_page_description (void)
 {
   g_autoptr (HdyStatusPage) status_page = NULL;
-  const gchar *description = NULL;
+  g_autofree gchar *description = NULL;
 
   status_page = HDY_STATUS_PAGE (g_object_ref_sink (hdy_status_page_new ()));
   g_assert_nonnull (status_page);
diff --git a/tests/test-swipe-group.c b/tests/test-swipe-group.c
index 09f263f1..75d31797 100644
--- a/tests/test-swipe-group.c
+++ b/tests/test-swipe-group.c
@@ -17,8 +17,8 @@ test_hdy_swipe_group_add_remove (void)
 
   group = hdy_swipe_group_new ();
 
-  swipeable1 = HDY_SWIPEABLE (hdy_carousel_new ());
-  swipeable2 = HDY_SWIPEABLE (hdy_carousel_new ());
+  swipeable1 = g_object_ref_sink (HDY_SWIPEABLE (hdy_carousel_new ()));
+  swipeable2 = g_object_ref_sink (HDY_SWIPEABLE (hdy_carousel_new ()));
 
   g_assert_cmpint (g_slist_length (hdy_swipe_group_get_swipeables (group)), ==, 0);
 
diff --git a/tests/test-tab-view.c b/tests/test-tab-view.c
index efa85743..108d88c2 100644
--- a/tests/test-tab-view.c
+++ b/tests/test-tab-view.c
@@ -138,7 +138,7 @@ static void
 test_hdy_tab_view_default_icon (void)
 {
   g_autoptr (HdyTabView) view = NULL;
-  GIcon *icon = NULL;
+  g_autoptr (GIcon) icon = NULL;
   g_autoptr (GIcon) icon1 = g_themed_icon_new ("go-previous-symbolic");
   g_autoptr (GIcon) icon2 = g_themed_icon_new ("go-next-symbolic");
   g_autofree gchar *icon_str = NULL;
@@ -155,8 +155,7 @@ test_hdy_tab_view_default_icon (void)
   g_assert_cmpint (notified, ==, 0);
 
   hdy_tab_view_set_default_icon (view, icon1);
-  g_object_get (view, "default-icon", &icon, NULL);
-  g_assert_true (icon == icon1);
+  g_assert_true (hdy_tab_view_get_default_icon (view) == icon1);
   g_assert_cmpint (notified, ==, 1);
 
   g_object_set (view, "default-icon", icon2, NULL);
@@ -183,8 +182,7 @@ test_hdy_tab_view_menu_model (void)
   g_assert_cmpint (notified, ==, 0);
 
   hdy_tab_view_set_menu_model (view, model1);
-  g_object_get (view, "menu-model", &model, NULL);
-  g_assert_true (model == model1);
+  g_assert_true (hdy_tab_view_get_menu_model (view) == model1);
   g_assert_cmpint (notified, ==, 1);
 
   g_object_set (view, "menu-model", model2, NULL);
@@ -211,8 +209,7 @@ test_hdy_tab_view_shortcut_widget (void)
   g_assert_cmpint (notified, ==, 0);
 
   hdy_tab_view_set_shortcut_widget (view, widget1);
-  g_object_get (view, "shortcut-widget", &widget, NULL);
-  g_assert_true (widget == widget1);
+  g_assert_true (hdy_tab_view_get_shortcut_widget (view) == widget1);
   g_assert_cmpint (notified, ==, 1);
 
   g_object_set (view, "shortcut-widget", widget2, NULL);
@@ -272,8 +269,6 @@ test_hdy_tab_view_select (void)
   g_assert_null (selected_page);
 
   page1 = hdy_tab_view_append (view, gtk_button_new ());
-  g_object_get (view, "selected-page", &selected_page, NULL);
-  g_assert_true (selected_page == page1);
   g_assert_true (hdy_tab_view_get_selected_page (view) == page1);
   g_assert_true (hdy_tab_page_get_selected (page1));
   g_assert_cmpint (notified, ==, 1);
@@ -914,8 +909,7 @@ test_hdy_tab_page_title (void)
   g_assert_cmpint (notified, ==, 0);
 
   hdy_tab_page_set_title (page, "Some title");
-  g_object_get (page, "title", &title, NULL);
-  g_assert_cmpstr (title, ==, "Some title");
+  g_assert_cmpstr (hdy_tab_page_get_title (page), ==, "Some title");
   g_assert_cmpint (notified, ==, 1);
 
   g_object_set (page, "title", "Some other title", NULL);
@@ -944,8 +938,7 @@ test_hdy_tab_page_tooltip (void)
   g_assert_cmpint (notified, ==, 0);
 
   hdy_tab_page_set_tooltip (page, "Some tooltip");
-  g_object_get (page, "tooltip", &tooltip, NULL);
-  g_assert_cmpstr (tooltip, ==, "Some tooltip");
+  g_assert_cmpstr (hdy_tab_page_get_tooltip (page), ==, "Some tooltip");
   g_assert_cmpint (notified, ==, 1);
 
   g_object_set (page, "tooltip", "Some other tooltip", NULL);
@@ -976,8 +969,7 @@ test_hdy_tab_page_icon (void)
   g_assert_cmpint (notified, ==, 0);
 
   hdy_tab_page_set_icon (page, icon1);
-  g_object_get (page, "icon", &icon, NULL);
-  g_assert_true (icon == icon1);
+  g_assert_true (hdy_tab_page_get_icon (page) == icon1);
   g_assert_cmpint (notified, ==, 1);
 
   g_object_set (page, "icon", icon2, NULL);
@@ -1038,8 +1030,7 @@ test_hdy_tab_page_indicator_icon (void)
   g_assert_cmpint (notified, ==, 0);
 
   hdy_tab_page_set_indicator_icon (page, icon1);
-  g_object_get (page, "indicator-icon", &icon, NULL);
-  g_assert_true (icon == icon1);
+  g_assert_true (hdy_tab_page_get_indicator_icon (page) == icon1);
   g_assert_cmpint (notified, ==, 1);
 
   g_object_set (page, "indicator-icon", icon2, NULL);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]