aboutsummaryrefslogtreecommitdiff
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
parent900fadf5e6e12f21d3dedf4b0bd0636cbfca6313 (diff)
downloadayatana-indicator-keyboard-a8b6bb97a86e61844e34a99d35a7c4b7e3f2ee05.tar.gz
ayatana-indicator-keyboard-a8b6bb97a86e61844e34a99d35a7c4b7e3f2ee05.tar.bz2
ayatana-indicator-keyboard-a8b6bb97a86e61844e34a99d35a7c4b7e3f2ee05.zip
Tests work-in-progress.
-rw-r--r--.bzrignore5
-rw-r--r--configure.ac10
-rw-r--r--data/main.vala16
-rw-r--r--lib/main.vala20
-rw-r--r--po/indicator-keyboard.pot8
-rw-r--r--tests/Makefile.am16
-rw-r--r--tests/config.vala.in1
-rwxr-xr-xtests/external/com.canonical.indicator.keyboard.test.Execute3
l---------tests/external/gkbd-keyboard-display1
-rw-r--r--tests/indicator-keyboard-service.in4
-rw-r--r--tests/main.vala219
-rw-r--r--tests/services/indicator-keyboard.service.in3
12 files changed, 281 insertions, 25 deletions
diff --git a/.bzrignore b/.bzrignore
index 945be416..86f8dccb 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -3,6 +3,7 @@
*.m4
*.pyc
*.stamp
+*.stamp-t
*.substvars
*.valid
.deps
@@ -27,3 +28,7 @@ lib/indicator-keyboard-service
libtool
po/POTFILES
po/stamp-it
+tests/config.vala
+tests/indicator-keyboard-service
+tests/indicator-keyboard-test
+tests/services/indicator-keyboard.service
diff --git a/configure.ac b/configure.ac
index dd582f47..e9bb7592 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,6 +37,10 @@ PKG_CHECK_MODULES([GEE], [gee-1.0])
AC_SUBST([GEE_CFLAGS])
AC_SUBST([GEE_LIBS])
+PKG_CHECK_MODULES([GIO], [gio-2.0])
+AC_SUBST([GIO_CFLAGS])
+AC_SUBST([GIO_LIBS])
+
PKG_CHECK_MODULES([GTK], [gtk+-3.0])
AC_SUBST([GTK_CFLAGS])
AC_SUBST([GTK_LIBS])
@@ -73,6 +77,10 @@ AC_CONFIG_FILES([Makefile
data/Makefile
lib/Makefile
po/Makefile.in
- tests/Makefile])
+ tests/Makefile
+ tests/config.vala
+ tests/indicator-keyboard-service
+ tests/services/indicator-keyboard.service],
+ [chmod +x tests/indicator-keyboard-service])
AC_OUTPUT
diff --git a/data/main.vala b/data/main.vala
index 862f88a1..e229ba3f 100644
--- a/data/main.vala
+++ b/data/main.vala
@@ -37,13 +37,11 @@ int main (string[] args) {
context.set_help_enabled (true);
context.parse (ref args);
} catch (OptionError error) {
- stderr.printf ("error: %s\n", error.message);
- return 1;
+ GLib.error ("error: %s", error.message);
}
if (no_subscript_path == null && with_subscript_path == null) {
- stderr.printf ("error: No icon template\n");
- return 2;
+ error ("error: No icon template");
} else if (no_subscript_path == null) {
no_subscript_path = with_subscript_path;
} else if (with_subscript_path == null) {
@@ -57,8 +55,7 @@ int main (string[] args) {
try {
file.make_directory_with_parents (null);
} catch (Error error) {
- stderr.printf ("error: %s\n", error.message);
- return 3;
+ GLib.error ("error: %s", error.message);
}
}
} else {
@@ -126,8 +123,7 @@ int main (string[] args) {
with_subscript_data = with_subscript_data.replace ("@LAYOUT_FONT@", layout_font);
with_subscript_data = with_subscript_data.replace ("@SUBSCRIPT_FONT@", subscript_font);
} catch (Error error) {
- stderr.printf ("error: %s\n", error.message);
- return 4;
+ GLib.error ("error: %s", error.message);
}
var font_map = new PangoFT2.FontMap ();
@@ -173,7 +169,7 @@ int main (string[] args) {
try {
file.replace_contents (output_data.data, null, false, FileCreateFlags.REPLACE_DESTINATION, null, null);
} catch (Error error) {
- stderr.printf ("error: %s\n", error.message);
+ GLib.error ("error: %s", error.message);
}
}
@@ -217,7 +213,7 @@ int main (string[] args) {
try {
file.replace_contents (output_data.data, null, false, FileCreateFlags.REPLACE_DESTINATION, null, null);
} catch (Error error) {
- stderr.printf ("error: %s\n", error.message);
+ GLib.error ("error: %s", error.message);
}
}
}
diff --git a/lib/main.vala b/lib/main.vala
index c74dfc05..6df1b069 100644
--- a/lib/main.vala
+++ b/lib/main.vala
@@ -418,8 +418,8 @@ public class Indicator.Keyboard.Service : Object {
try {
this.icons[index] = Icon.new_for_string (engine.get_icon ());
- } catch {
- warn_if_reached ();
+ } catch (Error error) {
+ warning ("error: %s", error.message);
}
}
}
@@ -640,8 +640,8 @@ public class Indicator.Keyboard.Service : Object {
private void handle_activate_map (Variant? parameter) {
try {
Process.spawn_command_line_async ("gucharmap");
- } catch {
- warn_if_reached ();
+ } catch (SpawnError error) {
+ warning ("error: %s", error.message);
}
}
@@ -686,8 +686,8 @@ public class Indicator.Keyboard.Service : Object {
}
Process.spawn_command_line_async (command);
- } catch {
- warn_if_reached ();
+ } catch (SpawnError error) {
+ warning ("error: %s", error.message);
}
}
@@ -695,8 +695,8 @@ public class Indicator.Keyboard.Service : Object {
private void handle_activate_settings (Variant? parameter) {
try {
Process.spawn_command_line_async ("gnome-control-center region layouts");
- } catch {
- warn_if_reached ();
+ } catch (SpawnError error) {
+ warning ("error: %s", error.message);
}
}
@@ -705,8 +705,8 @@ public class Indicator.Keyboard.Service : Object {
try {
connection.export_action_group ("/com/canonical/indicator/keyboard", get_action_group ());
connection.export_menu_model ("/com/canonical/indicator/keyboard/desktop", get_menu_model ());
- } catch {
- warn_if_reached ();
+ } catch (Error error) {
+ warning ("error: %s", error.message);
}
}
diff --git a/po/indicator-keyboard.pot b/po/indicator-keyboard.pot
index 1750f5d5..c6d3d44f 100644
--- a/po/indicator-keyboard.pot
+++ b/po/indicator-keyboard.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-05-31 09:17-0400\n"
+"POT-Creation-Date: 2013-06-25 16:02-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -17,14 +17,14 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
-#: ../lib/main.vala:364
+#: ../lib/main.c:2209 ../lib/main.vala:501
msgid "Character Map"
msgstr ""
-#: ../lib/main.vala:365
+#: ../lib/main.c:2211 ../lib/main.vala:502
msgid "Keyboard Layout Chart"
msgstr ""
-#: ../lib/main.vala:366
+#: ../lib/main.c:2213 ../lib/main.vala:503
msgid "Text Entry Settings..."
msgstr ""
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e69de29b..a2143607 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -0,0 +1,16 @@
+AM_CFLAGS = -w
+AM_LDFLAGS = -lm
+AM_VALAFLAGS = --enable-experimental-non-null \
+ --metadatadir $(top_srcdir)/deps \
+ --vapidir $(top_srcdir)/deps
+
+check_PROGRAMS = indicator-keyboard-test
+
+indicator_keyboard_test_SOURCES = main.vala \
+ config.vala
+indicator_keyboard_test_VALAFLAGS = $(AM_VALAFLAGS) \
+ --pkg gio-2.0
+indicator_keyboard_test_CFLAGS = $(AM_CFLAGS) \
+ $(GIO_CFLAGS)
+indicator_keyboard_test_LDFLAGS = $(AM_LDFLAGS) \
+ $(GIO_LIBS)
diff --git a/tests/config.vala.in b/tests/config.vala.in
new file mode 100644
index 00000000..a3c4aeb8
--- /dev/null
+++ b/tests/config.vala.in
@@ -0,0 +1 @@
+const string SERVICE_DIR = "@abs_top_builddir@/tests/services";
diff --git a/tests/external/com.canonical.indicator.keyboard.test.Execute b/tests/external/com.canonical.indicator.keyboard.test.Execute
new file mode 100755
index 00000000..ad73fd24
--- /dev/null
+++ b/tests/external/com.canonical.indicator.keyboard.test.Execute
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+gdbus call -e -d com.canonical.indicator.keyboard.test -o /com/canonical/indicator/keyboard/test -m com.canonical.indicator.keyboard.test.Execute "\'`basename $0` $*\'"
diff --git a/tests/external/gkbd-keyboard-display b/tests/external/gkbd-keyboard-display
new file mode 120000
index 00000000..849e205e
--- /dev/null
+++ b/tests/external/gkbd-keyboard-display
@@ -0,0 +1 @@
+com.canonical.indicator.keyboard.test.Execute \ No newline at end of file
diff --git a/tests/indicator-keyboard-service.in b/tests/indicator-keyboard-service.in
new file mode 100644
index 00000000..bc2d12eb
--- /dev/null
+++ b/tests/indicator-keyboard-service.in
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+PATH="@abs_top_builddir@/tests/external:$PATH"
+@abs_top_builddir@/lib/indicator-keyboard-service
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 ();
+}
diff --git a/tests/services/indicator-keyboard.service.in b/tests/services/indicator-keyboard.service.in
new file mode 100644
index 00000000..8b04a464
--- /dev/null
+++ b/tests/services/indicator-keyboard.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=com.canonical.indicator.keyboard
+Exec=@abs_top_builddir@/tests/indicator-keyboard-service