/*  Test case to reproduce warning
 *  GLib-CRITICAL **: g_main_context_push_thread_default: assertion `acquired_context' failed
 *
 *  Compile it like this:
 *    gcc -g -o test-case test-case.c `pkg-config --cflags --libs gio-2.0`
 */

#include <stdlib.h>
#include <gio/gio.h>


#define NUM_THREADS 10

static void
enumerate_children (const gchar *uri)
{
  GFile           *file;
  GFileEnumerator *enumerator;
  GFileInfo       *info;
  GError          *error = NULL;

  file = g_file_new_for_uri (uri);

  enumerator = g_file_enumerate_children (file, "*", G_FILE_QUERY_INFO_NONE,
                                          NULL, &error);

  while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)))
    {
      g_print ("%s\n", g_file_info_get_name (info));
      g_object_unref (info);
    }

  g_object_unref (enumerator);
  g_object_unref (file);
}

static void
make_warnings_fatal (void)
{
  GLogLevelFlags fatal_mask;

  fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
  fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;

  g_log_set_always_fatal (fatal_mask);
}

int
main (int   argc,
      char *argv[])
{
  GThreadPool *pool;

  if (argc < 2)
    {
      g_printerr ("usage: %s smb://...\n", argv[0]);
      return EXIT_FAILURE;
    }

  make_warnings_fatal ();

  pool = g_thread_pool_new ((GFunc) enumerate_children, NULL,
                            NUM_THREADS, TRUE, NULL);

  while (g_thread_pool_push (pool, argv[1], NULL));

  return EXIT_FAILURE;
}
