aboutsummaryrefslogtreecommitdiff
path: root/tests/main.vala
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2013-06-25 17:22:15 -0400
committerWilliam Hua <william.hua@canonical.com>2013-06-25 17:22:15 -0400
commita8b6bb97a86e61844e34a99d35a7c4b7e3f2ee05 (patch)
tree9346b816733f705a189de7b617bc9e39e4da8abc /tests/main.vala
parent900fadf5e6e12f21d3dedf4b0bd0636cbfca6313 (diff)
downloadayatana-indicator-keyboard-a8b6bb97a86e61844e34a99d35a7c4b7e3f2ee05.tar.gz
ayatana-indicator-keyboard-a8b6bb97a86e61844e34a99d35a7c4b7e3f2ee05.tar.bz2
ayatana-indicator-keyboard-a8b6bb97a86e61844e34a99d35a7c4b7e3f2ee05.zip
Tests work-in-progress.
Diffstat (limited to 'tests/main.vala')
-rw-r--r--tests/main.vala219
1 files changed, 219 insertions, 0 deletions
diff --git a/tests/main.vala b/tests/main.vala
new file mode 100644
index 00000000..20704001
--- /dev/null
+++ b/tests/main.vala
@@ -0,0 +1,219 @@
+const int LONG_TIMEOUT = 10;
+const int SHORT_TIMEOUT = 1000;
+
+[DBus (name = "com.canonical.indicator.keyboard.test")]
+public class Service : Object {
+
+ [DBus (visible = false)]
+ private string? _command;
+
+ [DBus (visible = false)]
+ public string? command {
+ get { return _command; }
+ }
+
+ public void execute (string command) {
+ this._command = command;
+
+ var pspec = this.get_class ().find_property ("command");
+
+ if (pspec != null) {
+ this.notify["command"] ((!) pspec);
+ }
+ }
+}
+
+struct Fixture {
+ TestDBus? bus;
+ uint service_name;
+ DBusConnection? connection;
+ Service? service;
+ uint object_name;
+}
+
+static void begin_test (void *data) {
+ var fixture = (Fixture *) data;
+
+ fixture.bus = new TestDBus (TestDBusFlags.NONE);
+ ((!) fixture.bus).add_service_dir (SERVICE_DIR);
+ ((!) fixture.bus).up ();
+
+ var loop = new MainLoop (null, false);
+
+ fixture.service_name = Bus.own_name (BusType.SESSION,
+ "com.canonical.indicator.keyboard.test",
+ BusNameOwnerFlags.ALLOW_REPLACEMENT | BusNameOwnerFlags.REPLACE,
+ (connection, name) => {
+ if (loop.is_running ()) {
+ fixture.connection = connection;
+ loop.quit ();
+ }
+ },
+ null,
+ (connection, name) => {
+ if (loop.is_running ()) {
+ fixture.connection = null;
+ loop.quit ();
+ }
+ });
+
+ loop.run ();
+
+ if (fixture.connection != null) {
+ try {
+ fixture.service = new Service ();
+ fixture.object_name = ((!) fixture.connection).register_object ("/com/canonical/indicator/keyboard/test", fixture.service);
+ } catch (IOError error) {
+ fixture.object_name = 0;
+ fixture.service = null;
+
+ Test.message ("error: %s", error.message);
+ Test.fail ();
+ }
+ } else {
+ fixture.service = null;
+ fixture.object_name = 0;
+
+ Test.message ("Unable to connect to 'com.canonical.indicator.keyboard.test'.");
+ Test.fail ();
+ }
+}
+
+static void end_test (void *data) {
+ var fixture = (Fixture *) data;
+
+ if (fixture.object_name != 0) {
+ ((!) fixture.connection).unregister_object (fixture.object_name);
+ fixture.object_name = 0;
+ }
+
+ fixture.service = null;
+ fixture.connection = null;
+
+ if (fixture.service_name != 0) {
+ Bus.unown_name (fixture.service_name);
+ fixture.service_name = 0;
+ }
+
+ if (fixture.bus != null) {
+ ((!) fixture.bus).down ();
+ fixture.bus = null;
+ }
+}
+
+static void test_activate_input_source (void *data) {
+}
+
+static void test_activate_character_map (void *data) {
+ var fixture = (Fixture *) data;
+
+ if (fixture.object_name == 0) {
+ Test.message ("Invalid test fixture.");
+ Test.fail ();
+ 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;
+ }
+
+ var loop = new MainLoop (null, false);
+
+ var signal_name = ((!) fixture.service).notify["command"].connect ((pspec) => {
+ loop.quit ();
+ });
+
+ 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);
+ } 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);
+}
+
+static void test_activate_keyboard_layout_chart (void *data) {
+}
+
+static void test_activate_text_entry_settings (void *data) {
+}
+
+static void test_update_input_source (void *data) {
+}
+
+static void test_update_input_sources (void *data) {
+}
+
+public int main (string[] args) {
+ Test.init (ref args, null);
+
+ var suite = new TestSuite ("indicator-keyboard");
+
+ suite.add (new TestCase ("activate-input-source", begin_test, test_activate_input_source, end_test, sizeof (Fixture)));
+ suite.add (new TestCase ("activate-character-map", begin_test, test_activate_character_map, end_test, sizeof (Fixture)));
+ 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 ("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)));
+
+ TestSuite.get_root ().add_suite (suite);
+
+ return Test.run ();
+}