aboutsummaryrefslogtreecommitdiff
path: root/tests/main.vala
diff options
context:
space:
mode:
Diffstat (limited to 'tests/main.vala')
-rw-r--r--tests/main.vala402
1 files changed, 186 insertions, 216 deletions
diff --git a/tests/main.vala b/tests/main.vala
index eac5316e..64ed7a74 100644
--- a/tests/main.vala
+++ b/tests/main.vala
@@ -1,5 +1,5 @@
-const int LONG_TIMEOUT = 1;
-const int SHORT_TIMEOUT = 1000;
+const int TIMEOUT_S = 1;
+const int TIMEOUT_MS = 1000;
[DBus (name = "com.canonical.indicator.keyboard.test")]
public class Service : Object {
@@ -82,7 +82,7 @@ static void begin_test (void *data) {
loop.run ();
if (fixture.connection == null) {
- Test.message ("Unable to connect to 'com.canonical.indicator.keyboard.test'.");
+ Test.message ("error: Unable to connect to com.canonical.indicator.keyboard.test.");
Test.fail ();
}
}
@@ -113,7 +113,7 @@ static void test_activate_input_source (void *data) {
var fixture = (Fixture *) data;
if (fixture.object_name == 0) {
- Test.message ("Invalid test fixture.");
+ Test.message ("error: Test fixture not initialized.");
Test.fail ();
return;
}
@@ -129,69 +129,11 @@ static void test_activate_input_source (void *data) {
return;
}
- var cancellable = new Cancellable ();
- DBusProxy action_proxy;
- DBusProxy menu_proxy;
-
- var source = Timeout.add_seconds (LONG_TIMEOUT, () => { cancellable.cancel (); return false; });
-
- try {
- action_proxy = new DBusProxy.for_bus_sync (BusType.SESSION,
- DBusProxyFlags.NONE,
- null,
- "com.canonical.indicator.keyboard",
- "/com/canonical/indicator/keyboard",
- "org.gtk.Actions",
- cancellable);
- } catch (Error error) {
- Test.message ("error: %s", error.message);
- Test.fail ();
- return;
- }
-
- Source.remove (source);
-
- if (cancellable.is_cancelled ()) {
- Test.message ("Unable to connect to 'com.canonical.indicator.keyboard'.\n");
- Test.fail ();
- return;
- }
-
- source = Timeout.add_seconds (LONG_TIMEOUT, () => { cancellable.cancel (); return false; });
-
- try {
- menu_proxy = new DBusProxy.for_bus_sync (BusType.SESSION,
- DBusProxyFlags.NONE,
- null,
- "com.canonical.indicator.keyboard",
- "/com/canonical/indicator/keyboard/desktop",
- "org.gtk.Menus",
- cancellable);
- } catch (Error error) {
- Test.message ("error: %s", error.message);
- Test.fail ();
- return;
- }
-
- Source.remove (source);
-
- if (cancellable.is_cancelled ()) {
- Test.message ("Unable to connect to 'com.canonical.indicator.keyboard'.\n");
- Test.fail ();
- return;
- }
-
- try {
- var builder = new VariantBuilder (new VariantType ("(sava{sv})"));
- builder.add ("s", "current");
- builder.add_value (new Variant.parsed ("[<@u 2>]"));
- builder.add_value (new Variant.parsed ("@a{sv} {}"));
- action_proxy.call_sync ("Activate", builder.end (), DBusCallFlags.NONE, SHORT_TIMEOUT);
- } catch (Error error) {
- Test.message ("error: %s", error.message);
- Test.fail ();
- return;
- }
+ var action_group = DBusActionGroup.get ((!) fixture.connection,
+ "com.canonical.indicator.keyboard",
+ "/com/canonical/indicator/keyboard");
+ action_group.activate_action ("current", new Variant.uint32 (2));
+ Posix.sleep (TIMEOUT_S);
try {
string current;
@@ -208,59 +150,75 @@ static void test_activate_character_map (void *data) {
var fixture = (Fixture *) data;
if (fixture.object_name == 0) {
- Test.message ("Invalid test fixture.");
+ Test.message ("error: Test fixture not initialized.");
Test.fail ();
return;
}
- var cancellable = new Cancellable ();
- DBusProxy action_proxy;
- DBusProxy menu_proxy;
+ var loop = new MainLoop (null, false);
- var source = Timeout.add_seconds (LONG_TIMEOUT, () => { cancellable.cancel (); return false; });
+ var signal_name = ((!) fixture.service).notify["command"].connect ((pspec) => {
+ loop.quit ();
+ });
- try {
- action_proxy = new DBusProxy.for_bus_sync (BusType.SESSION,
- DBusProxyFlags.NONE,
- null,
- "com.canonical.indicator.keyboard",
- "/com/canonical/indicator/keyboard",
- "org.gtk.Actions",
- cancellable);
- } catch (Error error) {
- Test.message ("error: %s", error.message);
- Test.fail ();
- return;
- }
+ var action_group = DBusActionGroup.get ((!) fixture.connection,
+ "com.canonical.indicator.keyboard",
+ "/com/canonical/indicator/keyboard");
+ action_group.activate_action ("map", null);
+ var source = Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return false; });
+ loop.run ();
Source.remove (source);
+ ((!) fixture.service).disconnect (signal_name);
+
+ assert (strcmp ((!) ((!) fixture.service).command, "'gucharmap '") == 0);
+}
- if (cancellable.is_cancelled ()) {
- Test.message ("Unable to connect to 'com.canonical.indicator.keyboard'.\n");
+static void test_activate_keyboard_layout_chart (void *data) {
+ var fixture = (Fixture *) data;
+
+ if (fixture.object_name == 0) {
+ Test.message ("error: Test fixture not initialized.");
Test.fail ();
return;
}
- source = Timeout.add_seconds (LONG_TIMEOUT, () => { cancellable.cancel (); return false; });
-
try {
- menu_proxy = new DBusProxy.for_bus_sync (BusType.SESSION,
- DBusProxyFlags.NONE,
- null,
- "com.canonical.indicator.keyboard",
- "/com/canonical/indicator/keyboard/desktop",
- "org.gtk.Menus",
- cancellable);
- } catch (Error error) {
+ var current = 1;
+ var sources = "[('xkb', 'us'), ('xkb', 'ca+eng'), ('xkb', 'epo'), ('ibus', 'pinyin')]";
+ Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources current $current");
+ Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\"");
+ } catch (SpawnError error) {
Test.message ("error: %s", error.message);
Test.fail ();
return;
}
+ var loop = new MainLoop (null, false);
+
+ var signal_name = ((!) fixture.service).notify["command"].connect ((pspec) => {
+ loop.quit ();
+ });
+
+ var action_group = DBusActionGroup.get ((!) fixture.connection,
+ "com.canonical.indicator.keyboard",
+ "/com/canonical/indicator/keyboard");
+
+ action_group.activate_action ("chart", null);
+
+ var source = Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return false; });
+ loop.run ();
Source.remove (source);
+ ((!) fixture.service).disconnect (signal_name);
+
+ assert (strcmp ((!) ((!) fixture.service).command, "'gkbd-keyboard-display -l ca\teng'") == 0);
+}
+
+static void test_activate_text_entry_settings (void *data) {
+ var fixture = (Fixture *) data;
- if (cancellable.is_cancelled ()) {
- Test.message ("Unable to connect to 'com.canonical.indicator.keyboard'.\n");
+ if (fixture.object_name == 0) {
+ Test.message ("error: Test fixture not initialized.");
Test.fail ();
return;
}
@@ -271,215 +229,226 @@ static void test_activate_character_map (void *data) {
loop.quit ();
});
- try {
- var builder = new VariantBuilder (new VariantType ("(sava{sv})"));
- builder.add ("s", "map");
- builder.add_value (new Variant.parsed ("@av []"));
- builder.add_value (new Variant.parsed ("@a{sv} {}"));
- action_proxy.call_sync ("Activate", builder.end (), DBusCallFlags.NONE, SHORT_TIMEOUT);
- } catch (Error error) {
- Test.message ("error: %s", error.message);
- Test.fail ();
- return;
- }
+ var action_group = DBusActionGroup.get ((!) fixture.connection,
+ "com.canonical.indicator.keyboard",
+ "/com/canonical/indicator/keyboard");
+
+ action_group.activate_action ("settings", null);
- source = Timeout.add_seconds (LONG_TIMEOUT, () => { loop.quit (); return false; });
+ var source = Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return false; });
loop.run ();
Source.remove (source);
((!) fixture.service).disconnect (signal_name);
- assert (strcmp ((!) ((!) fixture.service).command, "'gucharmap '") == 0);
+ assert (strcmp ((!) ((!) fixture.service).command, "'gnome-control-center region layouts'") == 0);
}
-static void test_activate_keyboard_layout_chart (void *data) {
+static void test_migration (void *data) {
var fixture = (Fixture *) data;
if (fixture.object_name == 0) {
- Test.message ("Invalid test fixture.");
+ Test.message ("error: Test fixture not initialized.");
Test.fail ();
return;
}
try {
- var current = 1;
- var sources = "[('xkb', 'us'), ('xkb', 'ca+eng'), ('xkb', 'epo'), ('ibus', 'pinyin')]";
- Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources current $current");
+ var migrated = false;
+ var sources = "[('xkb', 'us')]";
+ var layouts = "['us', 'ca\teng', 'epo']";
+ Process.spawn_command_line_sync (@"gsettings set com.canonical.indicator.keyboard migrated $migrated");
Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\"");
+ Process.spawn_command_line_sync (@"gsettings set org.gnome.libgnomekbd.keyboard layouts \"$layouts\"");
} catch (SpawnError error) {
Test.message ("error: %s", error.message);
Test.fail ();
return;
}
- var cancellable = new Cancellable ();
- DBusProxy action_proxy;
- DBusProxy menu_proxy;
+ try {
+ var cancellable = new Cancellable ();
- var source = Timeout.add_seconds (LONG_TIMEOUT, () => { cancellable.cancel (); return false; });
+ var source = Timeout.add_seconds (TIMEOUT_S, () => { cancellable.cancel (); return false; });
- try {
- action_proxy = new DBusProxy.for_bus_sync (BusType.SESSION,
- DBusProxyFlags.NONE,
- null,
- "com.canonical.indicator.keyboard",
- "/com/canonical/indicator/keyboard",
- "org.gtk.Actions",
- cancellable);
+ var dbus_proxy = new DBusProxy.sync ((!) fixture.connection,
+ DBusProxyFlags.NONE,
+ null,
+ "org.freedesktop.DBus",
+ "/",
+ "org.freedesktop.DBus",
+ cancellable);
+
+ Source.remove (source);
+
+ if (cancellable.is_cancelled ()) {
+ Test.message ("error: Unable to connect to org.freedesktop.DBus.");
+ Test.fail ();
+ return;
+ }
+
+ dbus_proxy.call_sync ("StartServiceByName", new Variant ("(su)", "com.canonical.indicator.keyboard", 0), DBusCallFlags.NONE, TIMEOUT_MS);
} catch (Error error) {
Test.message ("error: %s", error.message);
Test.fail ();
return;
}
- Source.remove (source);
-
- if (cancellable.is_cancelled ()) {
- Test.message ("Unable to connect to 'com.canonical.indicator.keyboard'.\n");
+ try {
+ string sources;
+ Process.spawn_command_line_sync ("gsettings get org.gnome.desktop.input-sources sources", out sources);
+ assert (strcmp (sources, "[('xkb', 'us'), ('xkb', 'ca+eng'), ('xkb', 'epo')]\n") == 0);
+ } catch (SpawnError error) {
+ Test.message ("error: %s", error.message);
Test.fail ();
return;
}
+}
- source = Timeout.add_seconds (LONG_TIMEOUT, () => { cancellable.cancel (); return false; });
+static void test_no_migration (void *data) {
+ var fixture = (Fixture *) data;
- try {
- menu_proxy = new DBusProxy.for_bus_sync (BusType.SESSION,
- DBusProxyFlags.NONE,
- null,
- "com.canonical.indicator.keyboard",
- "/com/canonical/indicator/keyboard/desktop",
- "org.gtk.Menus",
- cancellable);
- } catch (Error error) {
- Test.message ("error: %s", error.message);
+ if (fixture.object_name == 0) {
+ Test.message ("error: Test fixture not initialized.");
Test.fail ();
return;
}
- Source.remove (source);
-
- if (cancellable.is_cancelled ()) {
- Test.message ("Unable to connect to 'com.canonical.indicator.keyboard'.\n");
+ try {
+ var migrated = true;
+ var sources = "[('xkb', 'us')]";
+ var layouts = "['us', 'ca\teng', 'epo']";
+ Process.spawn_command_line_sync (@"gsettings set com.canonical.indicator.keyboard migrated $migrated");
+ Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\"");
+ Process.spawn_command_line_sync (@"gsettings set org.gnome.libgnomekbd.keyboard layouts \"$layouts\"");
+ } catch (SpawnError error) {
+ Test.message ("error: %s", error.message);
Test.fail ();
return;
}
- var loop = new MainLoop (null, false);
+ try {
+ var cancellable = new Cancellable ();
- var signal_name = ((!) fixture.service).notify["command"].connect ((pspec) => {
- loop.quit ();
- });
+ var source = Timeout.add_seconds (TIMEOUT_S, () => { cancellable.cancel (); return false; });
- try {
- var builder = new VariantBuilder (new VariantType ("(sava{sv})"));
- builder.add ("s", "chart");
- builder.add_value (new Variant.parsed ("@av []"));
- builder.add_value (new Variant.parsed ("@a{sv} {}"));
- action_proxy.call_sync ("Activate", builder.end (), DBusCallFlags.NONE, SHORT_TIMEOUT);
+ var dbus_proxy = new DBusProxy.sync ((!) fixture.connection,
+ DBusProxyFlags.NONE,
+ null,
+ "org.freedesktop.DBus",
+ "/",
+ "org.freedesktop.DBus",
+ cancellable);
+
+ Source.remove (source);
+
+ if (cancellable.is_cancelled ()) {
+ Test.message ("error: Unable to connect to org.freedesktop.DBus.");
+ Test.fail ();
+ return;
+ }
+
+ dbus_proxy.call_sync ("StartServiceByName", new Variant ("(su)", "com.canonical.indicator.keyboard", 0), DBusCallFlags.NONE, TIMEOUT_MS);
} catch (Error error) {
Test.message ("error: %s", error.message);
Test.fail ();
return;
}
- source = Timeout.add_seconds (LONG_TIMEOUT, () => { loop.quit (); return false; });
- loop.run ();
- Source.remove (source);
- ((!) fixture.service).disconnect (signal_name);
-
- assert (strcmp ((!) ((!) fixture.service).command, "'gkbd-keyboard-display -l ca\teng'") == 0);
+ try {
+ string sources;
+ Process.spawn_command_line_sync ("gsettings get org.gnome.desktop.input-sources sources", out sources);
+ assert (strcmp (sources, "[('xkb', 'us')]\n") == 0);
+ } catch (SpawnError error) {
+ Test.message ("error: %s", error.message);
+ Test.fail ();
+ return;
+ }
}
-static void test_activate_text_entry_settings (void *data) {
+static void test_update_visible (void *data) {
var fixture = (Fixture *) data;
if (fixture.object_name == 0) {
- Test.message ("Invalid test fixture.");
+ Test.message ("error: Test fixture not initialized.");
Test.fail ();
return;
}
- var cancellable = new Cancellable ();
- DBusProxy action_proxy;
- DBusProxy menu_proxy;
-
- var source = Timeout.add_seconds (LONG_TIMEOUT, () => { cancellable.cancel (); return false; });
+ bool visible;
try {
- action_proxy = new DBusProxy.for_bus_sync (BusType.SESSION,
- DBusProxyFlags.NONE,
- null,
- "com.canonical.indicator.keyboard",
- "/com/canonical/indicator/keyboard",
- "org.gtk.Actions",
- cancellable);
- } catch (Error error) {
+ visible = true;
+ Process.spawn_command_line_sync (@"gsettings set com.canonical.indicator.keyboard visible $visible");
+ } catch (SpawnError error) {
Test.message ("error: %s", error.message);
Test.fail ();
return;
}
+ var loop = new MainLoop (null, false);
+
+ var action_group = DBusActionGroup.get ((!) fixture.connection,
+ "com.canonical.indicator.keyboard",
+ "/com/canonical/indicator/keyboard");
+ var signal_name = action_group.action_added["indicator"].connect ((action) => {
+ loop.quit ();
+ });
+ action_group.list_actions ();
+
+ var source = Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return false; });
+ loop.run ();
Source.remove (source);
+ action_group.disconnect (signal_name);
- if (cancellable.is_cancelled ()) {
- Test.message ("Unable to connect to 'com.canonical.indicator.keyboard'.\n");
- Test.fail ();
- return;
- }
+ var state = action_group.get_action_state ("indicator");
+ assert (((!) state).lookup ("visible", "b", out visible));
+ assert (visible);
- source = Timeout.add_seconds (LONG_TIMEOUT, () => { cancellable.cancel (); return false; });
+ loop = new MainLoop (null, false);
+ signal_name = action_group.action_state_changed["indicator"].connect ((action, state) => {
+ loop.quit ();
+ });
try {
- menu_proxy = new DBusProxy.for_bus_sync (BusType.SESSION,
- DBusProxyFlags.NONE,
- null,
- "com.canonical.indicator.keyboard",
- "/com/canonical/indicator/keyboard/desktop",
- "org.gtk.Menus",
- cancellable);
- } catch (Error error) {
+ visible = false;
+ Process.spawn_command_line_sync (@"gsettings set com.canonical.indicator.keyboard visible $visible");
+ } catch (SpawnError error) {
Test.message ("error: %s", error.message);
Test.fail ();
return;
}
+ source = Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return false; });
+ loop.run ();
Source.remove (source);
+ action_group.disconnect (signal_name);
- if (cancellable.is_cancelled ()) {
- Test.message ("Unable to connect to 'com.canonical.indicator.keyboard'.\n");
- Test.fail ();
- return;
- }
+ state = action_group.get_action_state ("indicator");
+ assert (((!) state).lookup ("visible", "b", out visible));
+ assert (!visible);
- var loop = new MainLoop (null, false);
-
- var signal_name = ((!) fixture.service).notify["command"].connect ((pspec) => {
+ loop = new MainLoop (null, false);
+ signal_name = action_group.action_state_changed["indicator"].connect ((action, state) => {
loop.quit ();
});
try {
- var builder = new VariantBuilder (new VariantType ("(sava{sv})"));
- builder.add ("s", "settings");
- builder.add_value (new Variant.parsed ("@av []"));
- builder.add_value (new Variant.parsed ("@a{sv} {}"));
- action_proxy.call_sync ("Activate", builder.end (), DBusCallFlags.NONE, SHORT_TIMEOUT);
- } catch (Error error) {
+ visible = true;
+ Process.spawn_command_line_sync (@"gsettings set com.canonical.indicator.keyboard visible $visible");
+ } catch (SpawnError error) {
Test.message ("error: %s", error.message);
Test.fail ();
return;
}
- source = Timeout.add_seconds (LONG_TIMEOUT, () => { loop.quit (); return false; });
+ source = Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return false; });
loop.run ();
Source.remove (source);
- ((!) fixture.service).disconnect (signal_name);
-
- assert (strcmp ((!) ((!) fixture.service).command, "'gnome-control-center region layouts'") == 0);
-}
+ action_group.disconnect (signal_name);
-static void test_migration (void *data) {
-}
-
-static void test_update_visible (void *data) {
+ state = action_group.get_action_state ("indicator");
+ assert (((!) state).lookup ("visible", "b", out visible));
+ assert (visible);
}
static void test_update_input_source (void *data) {
@@ -500,6 +469,7 @@ public int main (string[] args) {
suite.add (new TestCase ("activate-keyboard-layout-chart", begin_test, test_activate_keyboard_layout_chart, end_test, sizeof (Fixture)));
suite.add (new TestCase ("activate-text-entry-settings", begin_test, test_activate_text_entry_settings, end_test, sizeof (Fixture)));
suite.add (new TestCase ("migration", begin_test, test_migration, end_test, sizeof (Fixture)));
+ suite.add (new TestCase ("no-migration", begin_test, test_no_migration, end_test, sizeof (Fixture)));
suite.add (new TestCase ("update-visible", begin_test, test_update_visible, end_test, sizeof (Fixture)));
suite.add (new TestCase ("update-input-source", begin_test, test_update_input_source, end_test, sizeof (Fixture)));
suite.add (new TestCase ("update-input-sources", begin_test, test_update_input_sources, end_test, sizeof (Fixture)));