~ubuntu-branches/ubuntu/quantal/ibus/quantal

« back to all changes in this revision

Viewing changes to src/test-bus.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry Warsaw
  • Date: 2011-08-11 17:00:57 UTC
  • mfrom: (6.2.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110811170057-6dmbfs4s3cchzl7x
Tags: 1.3.99.20110419-1ubuntu1
* Merge with Debian unstable.  Remaining Ubuntu changes:
  - Indicator support:
    + Add 05_appindicator.patch: Use an indicator rather than a notification
      icon.
    + debian/control: Recommend python-appindicator.
  - debian/control: Install im-switch instead of im-config by default.
  - debian/README.source: Removed, it was outdated and no longer correct
  - debian/patches/01_ubuntu_desktop: Fix "Desktop entry needs the
    X-Ubuntu-Gettext-Domain key"  (LP: #457632)
  - debian/patches/02_title_update.patch: Rename "IBus Preferences" to
    "Keyboard Input Methods"
  - debian/patches/06_locale_parser.patch: Cherry-picked from upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
2
 
#include <string.h>
3
 
#include "ibus.h"
4
 
 
5
 
static gchar *
6
 
get_last_engine_id (const GList *engines)
7
 
{
8
 
    g_assert (engines);
9
 
    const char *result = NULL;
10
 
    for (; engines; engines = g_list_next (engines)) {
11
 
        IBusEngineDesc *engine_desc = IBUS_ENGINE_DESC (engines->data);
12
 
        g_assert (engine_desc);
13
 
        result = engine_desc->name;
14
 
    }
15
 
    g_assert (result);
16
 
    return g_strdup (result);
17
 
}
18
 
 
19
 
static void
20
 
print_engines (const GList *engines)
21
 
{
22
 
    g_assert (engines);
23
 
    for (; engines; engines = g_list_next (engines)) {
24
 
        IBusEngineDesc *engine_desc = IBUS_ENGINE_DESC (engines->data);
25
 
        g_assert (engine_desc);
26
 
        g_debug ("%s (id:%s, icon:%s)", engine_desc->longname, engine_desc->name, engine_desc->icon);
27
 
        g_object_unref (engine_desc);
28
 
    }
29
 
}
30
 
 
31
 
int main()
32
 
{
33
 
        g_type_init ();
34
 
 
35
 
        IBusBus *bus;
36
 
        GList *engines;
37
 
        gchar *active_engine_name;
38
 
 
39
 
        bus = ibus_bus_new ();
40
 
 
41
 
        /* Test ibusbus.c */
42
 
        g_debug ("===== Active engines:");
43
 
        engines = ibus_bus_list_active_engines (bus);
44
 
        g_assert (engines);
45
 
        active_engine_name = get_last_engine_id (engines);
46
 
        print_engines (engines);
47
 
        g_list_free (engines);
48
 
 
49
 
        g_debug ("===== All engines:");
50
 
        engines = ibus_bus_list_engines (bus);
51
 
        g_assert (engines);
52
 
        print_engines (engines);
53
 
        g_list_free (engines);
54
 
 
55
 
        g_debug ("===== Global engine:");
56
 
        if (ibus_bus_get_use_global_engine (bus)) {
57
 
            g_debug ("use_global_engine is true.");
58
 
            if (ibus_bus_is_global_engine_enabled (bus)) {
59
 
                g_debug ("Global engine is enabled.");
60
 
                IBusEngineDesc *global_engine = ibus_bus_get_global_engine (bus);
61
 
                g_assert (global_engine);
62
 
                g_debug ("%s (id:%s, icon:%s)", global_engine->longname,
63
 
                         global_engine->name, global_engine->icon);
64
 
                g_object_unref (global_engine);
65
 
            }
66
 
        }
67
 
 
68
 
        g_debug ("===== Use system layout:%s", ibus_bus_get_use_sys_layout (bus) ? "true" : "false");
69
 
 
70
 
        g_debug ("Test ibusbus.c: passed.");
71
 
 
72
 
        /* Test ibusinputcontext.c */
73
 
#if 1
74
 
    {
75
 
            IBusInputContext *context;
76
 
            IBusEngineDesc *engine_desc;
77
 
            gchar *current_ic;
78
 
            context = ibus_bus_create_input_context (bus, "test");
79
 
            ibus_input_context_set_capabilities (context, IBUS_CAP_FOCUS);
80
 
            ibus_input_context_disable (context);
81
 
            g_assert (ibus_input_context_is_enabled (context) == FALSE);
82
 
            ibus_input_context_enable (context);
83
 
            g_assert (ibus_input_context_is_enabled (context) == TRUE);
84
 
            ibus_input_context_focus_in (context);
85
 
            ibus_input_context_set_engine (context, active_engine_name);
86
 
            current_ic = ibus_bus_current_input_context (bus);
87
 
            g_assert (!strcmp (current_ic, ibus_proxy_get_path (IBUS_PROXY (context))));
88
 
            engine_desc = ibus_input_context_get_engine (context);
89
 
            g_assert (engine_desc);
90
 
            g_assert (!strcmp (active_engine_name, engine_desc->name));
91
 
            g_debug ("Test ibusinputcontext.c: passed.");
92
 
 
93
 
            g_free (active_engine_name);
94
 
            g_free (current_ic);
95
 
            g_object_unref (engine_desc);
96
 
            g_object_unref (context);
97
 
    }
98
 
#endif
99
 
        g_object_unref (bus);
100
 
 
101
 
        return 0;
102
 
}