[shotwell/wip/phako/external-gstreamer] WIP
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell/wip/phako/external-gstreamer] WIP
- Date: Wed, 31 Jul 2019 14:34:08 +0000 (UTC)
commit 6b1a2ee41c2a509205f455855cc8f70841a76f41
Author: Jens Georg <mail jensge org>
Date: Thu Jul 11 23:42:50 2019 +0200
WIP
src/ExternalHelper.vala | 2 +
test/ExternalHelper.vala | 1 +
test/ExternalHelperTest.vala | 66 +++++++++++++++++++++++++++
test/ExternalHelperTestExecutable.vala | 83 ++++++++++++++++++++++++++++++++++
test/meson.build | 18 ++++++++
5 files changed, 170 insertions(+)
---
diff --git a/src/ExternalHelper.vala b/src/ExternalHelper.vala
index ce5903d3..a3f4c52e 100644
--- a/src/ExternalHelper.vala
+++ b/src/ExternalHelper.vala
@@ -66,6 +66,8 @@ public class ExternalProxy<G> : Object, Initable {
Source.remove(startup_timeout);
startup_timeout = 0;
+ debug ("Got new connection, trying to get object for path %s", dbus_path);
+
try {
remote = connection.get_proxy_sync(null, dbus_path, DBusProxyFlags.DO_NOT_LOAD_PROPERTIES |
DBusProxyFlags.DO_NOT_CONNECT_SIGNALS,
diff --git a/test/ExternalHelper.vala b/test/ExternalHelper.vala
new file mode 120000
index 00000000..8c3c0f02
--- /dev/null
+++ b/test/ExternalHelper.vala
@@ -0,0 +1 @@
+../src/ExternalHelper.vala
\ No newline at end of file
diff --git a/test/ExternalHelperTest.vala b/test/ExternalHelperTest.vala
new file mode 100644
index 00000000..00c9fa55
--- /dev/null
+++ b/test/ExternalHelperTest.vala
@@ -0,0 +1,66 @@
+[DBus (name = "org.gnome.Shotwell.ExternalHelperTest1")]
+public interface TestInterface : Object {
+ public abstract async uint64 get_uint64(uint64 in_value) throws Error;
+ //public abstract uint64 get_uint64_sync() throws Error;
+}
+
+internal class TestExternalProxy : ExternalProxy<TestInterface>, TestInterface {
+ public TestExternalProxy(string helper) throws Error {
+ Object(dbus_path : "/org/gnome/Shotwell/ExternalHelperTest1", remote_helper_path : helper);
+ init();
+ }
+
+ public async uint64 get_uint64(uint64 in_value) throws Error {
+ var r = yield get_remote();
+
+ var d = yield r.get_uint64(in_value);
+
+ return d;
+ }
+}
+
+extern const string EXTERNAL_HELPER_EXECUTABLE;
+
+void test_proxy_creation() {
+ var p = new TestExternalProxy("does-not-exist-never");
+ var loop = new MainLoop(null, false);
+ AsyncResult? res = null;
+ p.get_uint64.begin(10, (s, r) => {
+ loop.quit();
+ res = r;
+ });
+
+ loop.run();
+ assert (res != null);
+
+ // We get NOENT if the helper is not executable
+ try {
+ assert(p.get_uint64.end(res) == 20);
+ assert_not_reached();
+ } catch (Error error) {
+ assert_error(error, SpawnError.quark(), SpawnError.NOENT);
+ }
+
+ p = new TestExternalProxy(EXTERNAL_HELPER_EXECUTABLE);
+ p.get_uint64.begin(10, (s, r) => {
+ loop.quit();
+ res = r;
+ });
+
+ loop.run();
+ assert (res != null);
+
+ // We get NOENT if the helper is not executable
+ try {
+ assert(p.get_uint64.end(res) == 20);
+ } catch (Error error) {
+ critical("Got error %s", error.message);
+ assert_not_reached();
+ }
+}
+
+void main(string[] args) {
+ Test.init (ref args);
+ Test.add_func("/creation", test_proxy_creation);
+ Test.run();
+}
diff --git a/test/ExternalHelperTestExecutable.vala b/test/ExternalHelperTestExecutable.vala
new file mode 100644
index 00000000..1411a529
--- /dev/null
+++ b/test/ExternalHelperTestExecutable.vala
@@ -0,0 +1,83 @@
+static string address;
+static string uri;
+static MainLoop loop;
+
+const OptionEntry[] options = {
+ { "address", 'a', 0, OptionArg.STRING, ref address, "ADDRESS of private bus", "ADDRESS" },
+ { null }
+};
+
+[DBus (name = "org.gnome.Shotwell.ExternalHelperTest1")]
+internal class TestInterface : GLib.Object {
+ public async uint64 get_uint64(uint64 in_value) throws Error {
+ Idle.add (() => {
+ get_uint64.callback();
+ return false;
+ });
+
+ yield;
+
+ return in_value + 10;
+ }
+
+ public async void terminate() throws Error {
+ loop.quit();
+ }
+}
+
+private bool on_authorize_peer(DBusAuthObserver observer, IOStream stream, Credentials? credentials) {
+ critical("helper: Observer trying to authorize for %s", credentials.to_string());
+
+ if (credentials == null) {
+ critical ("Invalid credentials");
+ return false;
+ }
+
+ try {
+ if (!credentials.is_same_user(new Credentials())) {
+ critical ("different user");
+ return false;
+ }
+
+ return true;
+ } catch (Error error) {
+ critical ("Error %s", error.message);
+ return false;
+ }
+}
+
+int main(string[] args) {
+ var option_context = new OptionContext("- shotwell video metadata reader helper binary");
+ option_context.set_help_enabled(true);
+ option_context.add_main_entries(options, null);
+
+ try {
+ option_context.parse (ref args);
+
+ if (address == null && uri == null) {
+ error("Must either provide --uri or --address");
+ }
+
+ if (address != null) {
+ critical("=> Creating new connection");
+ var observer = new DBusAuthObserver();
+ observer.authorize_authenticated_peer.connect(on_authorize_peer);
+ var connection = new DBusConnection.for_address_sync(address,
DBusConnectionFlags.AUTHENTICATION_CLIENT,
+ observer, null);
+
+ critical("=> Registering object");
+ connection.register_object ("/org/gnome/Shotwell/ExternalHelperTest1", new TestInterface());
+
+ }
+
+ loop = new MainLoop(null, false);
+ loop.run();
+
+ } catch (Error error) {
+ critical("Failed to parse options: %s", error.message);
+
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/test/meson.build b/test/meson.build
index de1f0128..0dc482ab 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -1,5 +1,23 @@
+external_helper_test_executable = executable(
+ 'external_helper',
+ files([
+ 'ExternalHelperTestExecutable.vala',
+ ]),
+ dependencies : gio
+)
+
+external_helper_test = executable(
+ 'external-helper-test',
+ files([
+ 'ExternalHelperTest.vala',
+ 'ExternalHelper.vala'
+ ]),
+ dependencies: gio,
+ c_args : [ '-DEXTERNAL_HELPER_EXECUTABLE="@0@"'.format(external_helper_test_executable.full_path()) ]
+)
natural_collate_test = executable('natural-collate-test',
['NaturalCollate-Test.vala', 'NaturalCollate.vala'],
dependencies : gio)
test('natural-collate', natural_collate_test)
+test('external-helper-test', external_helper_test)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]