#include <gtk/gtk.h>

/* gcc atk_refcount_test.c `pkg-config --libs --cflags gtk+-3.0` */

int
main (int argc, char **argv)
{
  GtkWidget *win, *scrollbar;

  gtk_init (&argc, &argv);

  /* Create a scrolled window */
  win = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (win), GTK_POLICY_ALWAYS,GTK_POLICY_ALWAYS);
  g_object_ref_sink (win);

  /* Keep a reference to the scrollbar, this could easily happen in GJS GC */
  scrollbar = gtk_scrolled_window_get_hscrollbar (GTK_SCROLLED_WINDOW (win));
  g_object_ref (scrollbar);

  /* Make sure atk object is created */
  g_message ("atk object: %p", gtk_widget_get_accessible (win));

  g_object_unref (win);

  /* Unref the scrollbar after the scrolled window */
  g_object_unref (scrollbar);

  return 0;
}
