/* GLib testing framework examples and tests
 *
 * Copyright (C) 2010 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <gio/gio.h>

static void
test_disconnect_from_handler_on_cancelled (GCancellable *cancellable,
                                           gpointer      user_data)
{
  gulong *id = user_data;

  g_assert_cmpint (*id, !=, 0);

  g_cancellable_disconnect (cancellable, *id);

  *id = 0;
}

static void
test_disconnect_from_handler (void)
{
  GCancellable *c;
  gulong id;

  c = g_cancellable_new ();
  id = g_cancellable_connect (c,
                              G_CALLBACK (test_disconnect_from_handler_on_cancelled),
                              &id,   /* user_data */
                              NULL); /* user_data_destroy_func */
  g_assert_cmpint (id, !=, 0);
  g_cancellable_cancel (c);
  g_assert_cmpint (id, ==, 0);
  g_object_unref (c);
}

int
main (int   argc,
      char *argv[])
{
  g_type_init ();
  g_test_init (&argc, &argv, NULL);

  g_test_add_func ("/cancellable/disconnect_from_handler", test_disconnect_from_handler);

  return g_test_run();
}

