2 * Copyright © 2009 Ryan Lortie
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; either version 2 of the licence or (at
7 * your option) any later version.
9 * See the included COPYING file for more information.
12 #include <glib/glib.h>
17 static GObject *got_source;
18 static GAsyncResult *got_result;
19 static gpointer got_user_data;
22 ensure_destroyed (gpointer obj)
24 g_object_add_weak_pointer (obj, &obj);
26 g_assert (obj == NULL);
35 ensure_destroyed (got_result);
42 check (gpointer a, gpointer b, gpointer c)
44 g_assert (a == got_source);
45 g_assert (b == got_result);
46 g_assert (c == got_user_data);
50 callback_func (GObject *source,
55 got_result = g_object_ref (result);
56 got_user_data = user_data;
60 test_simple_async (void)
62 GSimpleAsyncResult *result;
65 a = g_object_new (G_TYPE_OBJECT, NULL);
66 b = g_object_new (G_TYPE_OBJECT, NULL);
67 c = g_object_new (G_TYPE_OBJECT, NULL);
69 result = g_simple_async_result_new (a, callback_func, b, test_simple_async);
70 check (NULL, NULL, NULL);
71 g_simple_async_result_complete (result);
73 g_object_unref (result);
75 g_assert (g_simple_async_result_is_valid (got_result, a, test_simple_async));
76 g_assert (!g_simple_async_result_is_valid (got_result, b, test_simple_async));
77 g_assert (!g_simple_async_result_is_valid (got_result, c, test_simple_async));
78 g_assert (!g_simple_async_result_is_valid (got_result, b, callback_func));
79 g_assert (!g_simple_async_result_is_valid ((gpointer) a, NULL, NULL));
84 result = g_simple_async_result_new (a, callback_func, b, test_simple_async);
85 check (NULL, NULL, NULL);
86 g_simple_async_result_complete_in_idle (result);
87 g_object_unref (result);
88 check (NULL, NULL, NULL);
89 g_main_context_iteration (NULL, FALSE);
99 main (int argc, char **argv)
102 g_test_init (&argc, &argv, NULL);
104 g_test_add_func ("/gio/simple-async-result/test", test_simple_async);