Add vala test for config module
authorPeng Huang <shawn.p.huang@gmail.com>
Tue, 26 Oct 2010 04:50:36 +0000 (13:50 +0900)
committerPeng Huang <shawn.p.huang@gmail.com>
Wed, 3 Nov 2010 01:54:58 +0000 (10:54 +0900)
bindings/vala/test/Makefile
bindings/vala/test/config.vala [new file with mode: 0644]
memconf/main.cc

index fc65585..20c311a 100644 (file)
@@ -1,3 +1,14 @@
+TARGETS = \
+    ibus-engine-enchant \
+    ibus-config \
+    $(NULL)
+
+all: $(TARGETS)
+
 ibus-engine-enchant: enchant.vala
        valac --vapidir .. --pkg ibus-1.0 --pkg enchant $^ -C
        valac -g --vapidir .. --pkg ibus-1.0 --pkg enchant $^ -o $@
+
+ibus-config: config.vala
+       valac --vapidir .. --pkg ibus-1.0 --pkg gio-2.0 --pkg vala-0.10 $^ -C
+       valac -g --vapidir .. --pkg ibus-1.0 --pkg gio-2.0 --pkg vala-0.10 $^ -o $@
diff --git a/bindings/vala/test/config.vala b/bindings/vala/test/config.vala
new file mode 100644 (file)
index 0000000..aa4ceb3
--- /dev/null
@@ -0,0 +1,50 @@
+/* vim:set et sts=4 ai: */
+using Vala;
+using GLib;
+using IBus;
+
+class MemoryConfig : ConfigService {
+    private HashMap<string, HashMap<string, Variant>> values;
+    private Variant tmp;
+
+    construct {
+        values = new HashMap<string, HashMap<string, Variant>> (str_hash, str_equal);
+    }
+
+    public override bool set_value (string section,
+                                    string name,
+                                    Variant _value) {
+        if (!values.contains (section))
+            values[section] = new HashMap<string, Variant> (str_hash, str_equal);
+        values[section][name] = _value;
+        value_changed (section, name, _value);
+        return true;
+    }
+
+    public override unowned Variant get_value (string section,
+                                               string name) throws GLib.Error {
+        if (!values.contains (section) || !values[section].contains(name))
+            throw new DBusError.FAILED("Can not get value %s", name);
+        tmp = values[section][name];
+        return tmp;
+    }
+
+    public static void main (string []argv) {
+        var bus = new IBus.Bus();
+
+        if (!bus.is_connected ()) {
+            stderr.printf ("Can not connect to ibus-daemon!\n");
+            return;
+        }
+
+        Type type = typeof (MemoryConfig);
+        ConfigService config =
+            (ConfigService) GLib.Object.new (type,
+                                             "connection", bus.get_connection (),
+                                             "object-path", "/org/freedesktop/IBus/Config");
+        bus.request_name ("org.freedesktop.IBus.Config", 0);
+        IBus.main ();
+        config = null;
+    }
+
+}
index a4d29ea..b1100aa 100644 (file)
@@ -1,3 +1,4 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
 /* vim:set et sts=4: */
 
 #include <ibus.h>
@@ -24,7 +25,6 @@ static void
 ibus_disconnected_cb (IBusBus  *bus,
                       gpointer  user_data)
 {
-    g_debug ("bus disconnected");
     ibus_quit ();
 }