| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include "config.h" |
| 23 |
|
| 24 |
#include <libdex.h> |
| 25 |
|
| 26 |
typedef struct |
| 27 |
{ |
| 28 |
GMainLoop *main_loop; |
| 29 |
GObject *object; |
| 30 |
GError *error; |
| 31 |
int value; |
| 32 |
} State; |
| 33 |
|
| 34 |
static void |
| 35 |
test_async_result_await_cb (GObject *object, |
| 36 |
GAsyncResult *result, |
| 37 |
gpointer user_data) |
| 38 |
{ |
| 39 |
State *state = user_data; |
| 40 |
|
| 41 |
g_assert_true (G_IS_MENU (object)); |
| 42 |
g_assert_true (DEX_IS_ASYNC_RESULT (result)); |
| 43 |
g_assert_nonnull (state); |
| 44 |
g_assert_true (object == state->object); |
| 45 |
|
| 46 |
state->value = dex_async_result_propagate_int (DEX_ASYNC_RESULT (result), &state->error); |
| 47 |
|
| 48 |
g_main_loop_quit (state->main_loop); |
| 49 |
} |
| 50 |
|
| 51 |
static void |
| 52 |
test_async_result_await (void) |
| 53 |
{ |
| 54 |
GMainLoop *main_loop = g_main_loop_new (NULL, FALSE); |
| 55 |
DexPromise *future = dex_promise_new (); |
| 56 |
GMenu *obj = g_menu_new (); |
| 57 |
State state = {0}; |
| 58 |
DexAsyncResult *async_result = dex_async_result_new (obj, NULL, test_async_result_await_cb, &state); |
| 59 |
|
| 60 |
state.main_loop = main_loop; |
| 61 |
state.object = G_OBJECT (obj); |
| 62 |
|
| 63 |
dex_async_result_await (async_result, dex_ref (future)); |
| 64 |
g_clear_object (&async_result); |
| 65 |
|
| 66 |
dex_promise_resolve_int (future, 123); |
| 67 |
|
| 68 |
g_main_loop_run (main_loop); |
| 69 |
|
| 70 |
g_assert_cmpint (state.value, ==, 123); |
| 71 |
|
| 72 |
g_object_unref (obj); |
| 73 |
dex_unref (future); |
| 74 |
|
| 75 |
while (g_main_context_pending (NULL)) |
| 76 |
g_main_context_iteration (NULL, FALSE); |
| 77 |
|
| 78 |
g_main_loop_unref (main_loop); |
| 79 |
} |
| 80 |
|
| 81 |
int |
| 82 |
main (int argc, |
| 83 |
char *argv[]) |
| 84 |
{ |
| 85 |
dex_init (); |
| 86 |
g_test_init (&argc, &argv, NULL); |
| 87 |
g_test_add_func ("/Dex/TestSuite/AsyncResult/await", test_async_result_await); |
| 88 |
return g_test_run (); |
| 89 |
} |