Remove g_type_init() calls.
[platform/upstream/ibus.git] / src / tests / ibus-inputcontext-create.c
1 /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
2 /* vim:set et sts=4: */
3 /* ibus - The Input Bus
4  * Copyright (C) 2011 Google, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #include <string.h>
23 #include "ibus.h"
24
25 static IBusBus *bus = NULL;
26
27 static void
28 create_finish_success (GObject      *object,
29                        GAsyncResult *res,
30                        gpointer      user_data)
31 {
32     g_assert (object == (GObject *)bus);
33     g_assert (user_data == NULL);
34
35     GError *error = NULL;
36     IBusInputContext *context = NULL;
37     context = ibus_bus_create_input_context_async_finish (bus, res, &error);
38
39     g_assert (IBUS_IS_INPUT_CONTEXT (context));
40     g_object_unref (context);
41     ibus_quit ();
42 }
43
44 static void
45 create_finish_failed (GObject      *object,
46                       GAsyncResult *res,
47                       gpointer      user_data)
48 {
49     g_assert (object == (GObject *)bus);
50     g_assert (user_data == NULL);
51
52     GError *error = NULL;
53     IBusInputContext *context = NULL;
54     context = ibus_bus_create_input_context_async_finish (bus, res, &error);
55
56     g_assert (context == NULL);
57     g_assert (error != NULL);
58     g_debug ("error = %s", error->message);
59     g_error_free (error);
60     ibus_quit ();
61 }
62
63 static void
64 test_success (void)
65 {
66     ibus_bus_create_input_context_async (bus,
67                                          "test",
68                                          -1,
69                                          NULL,
70                                          create_finish_success,
71                                          NULL);
72     ibus_main ();
73
74 }
75
76 static void
77 test_failed (void)
78 {
79     ibus_bus_create_input_context_async (bus,
80                                          "test",
81                                          1000,
82                                          NULL,
83                                          create_finish_failed,
84                                          NULL);
85     GDBusConnection *connection = ibus_bus_get_connection (bus);
86     g_dbus_connection_flush_sync (connection, NULL, NULL);
87     g_dbus_connection_close_sync (connection, NULL, NULL);
88     ibus_main ();
89 }
90
91 gint
92 main (gint    argc,
93       gchar **argv)
94 {
95     gint result;
96     ibus_init ();
97     g_test_init (&argc, &argv, NULL);
98     bus = ibus_bus_new ();
99
100     g_test_add_func ("/ibus/input_context_async_create_success", test_success);
101     g_test_add_func ("/ibus/input_context_async_create_failed",  test_failed);
102
103     result = g_test_run ();
104     g_object_unref (bus);
105
106     return result;
107 }