[geary/wip/application-cleanup: 3/3] Add unit tests for app path accessors



commit d4c29c72d7075bc5ec23bb9b1605451f62965016
Author: Michael Gratton <mike vee net>
Date:   Sun Apr 21 11:13:01 2019 +1000

    Add unit tests for app path accessors

 src/client/application/geary-application.vala      |  7 +++-
 .../client/application/geary-application-test.vala | 49 ++++++++++++++++++++++
 .../components/client-web-view-test-case.vala      |  2 -
 test/meson.build                                   |  1 +
 test/test-client.vala                              |  5 ++-
 5 files changed, 60 insertions(+), 4 deletions(-)
---
diff --git a/src/client/application/geary-application.vala b/src/client/application/geary-application.vala
index ed6a0fa0..f229d30d 100644
--- a/src/client/application/geary-application.vala
+++ b/src/client/application/geary-application.vala
@@ -363,9 +363,14 @@ public class GearyApplication : Gtk.Application {
     public override bool local_command_line(ref unowned string[] args,
                                             out int exit_status) {
         this.binary = args[0];
-        string current_path = Posix.realpath(
+        string? current_path = Posix.realpath(
             GLib.Environment.find_program_in_path(this.binary)
         );
+        if (current_path == null) {
+            // Couldn't find the path, are being run as a unit test?
+            // Probably should deal with the null either way though.
+            current_path = this.binary;
+        }
         this.exec_dir = GLib.File.new_for_path(current_path).get_parent();
 
         return base.local_command_line(ref args, out exit_status);
diff --git a/test/client/application/geary-application-test.vala 
b/test/client/application/geary-application-test.vala
new file mode 100644
index 00000000..544a69b3
--- /dev/null
+++ b/test/client/application/geary-application-test.vala
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2019 Michael Gratton <mike vee net>
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+
+class GearyApplicationTest : TestCase {
+
+
+    private GearyApplication? test_article = null;
+
+
+    public GearyApplicationTest() {
+        base("GearyApplicationTest");
+        add_test("paths_when_installed", paths_when_installed);
+    }
+
+    public override void set_up() {
+        this.test_article = new GearyApplication();
+    }
+
+    public override void tear_down() {
+        this.test_article = null;
+    }
+
+    public void paths_when_installed() throws GLib.Error {
+        string[] args = new string[] {
+            _INSTALL_PREFIX + "/bin/geary",
+            // Specifiy this so the app doesn't actually attempt
+            // to start up
+            "-v"
+        };
+        unowned string[] unowned_args = args;
+        int status;
+        this.test_article.local_command_line(ref unowned_args, out status);
+
+        assert_string(
+            _INSTALL_PREFIX + "/share/geary",
+            this.test_article.get_resource_directory().get_path()
+        );
+        assert_string(
+            _INSTALL_PREFIX + "/share/applications",
+            this.test_article.get_desktop_directory().get_path()
+        );
+    }
+
+}
diff --git a/test/client/components/client-web-view-test-case.vala 
b/test/client/components/client-web-view-test-case.vala
index 50203047..f2900f3b 100644
--- a/test/client/components/client-web-view-test-case.vala
+++ b/test/client/components/client-web-view-test-case.vala
@@ -5,8 +5,6 @@
  * (version 2.1 or later). See the COPYING file in this distribution.
  */
 
-// Defined by CMake build script.
-extern const string _BUILD_ROOT_DIR;
 
 public abstract class ClientWebViewTestCase<V> : TestCase {
 
diff --git a/test/meson.build b/test/meson.build
index 143d40fd..50767183 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -75,6 +75,7 @@ geary_test_client_sources = [
   'engine/api/geary-credentials-mediator-mock.vala',
 
   'client/accounts/accounts-manager-test.vala',
+  'client/application/geary-application-test.vala',
   'client/application/geary-configuration-test.vala',
   'client/components/client-web-view-test.vala',
   'client/components/client-web-view-test-case.vala',
diff --git a/test/test-client.vala b/test/test-client.vala
index fe408374..8aaa3ff5 100644
--- a/test/test-client.vala
+++ b/test/test-client.vala
@@ -5,7 +5,9 @@
  * (version 2.1 or later). See the COPYING file in this distribution.
  */
 
-// Defined by CMake build script.
+
+extern const string _INSTALL_PREFIX;
+extern const string _BUILD_ROOT_DIR;
 extern const string _GSETTINGS_DIR;
 
 int main(string[] args) {
@@ -43,6 +45,7 @@ int main(string[] args) {
     client.add_suite(new ClientWebViewTest().get_suite());
     client.add_suite(new ComposerWebViewTest().get_suite());
     client.add_suite(new ConfigurationTest().get_suite());
+    client.add_suite(new GearyApplicationTest().get_suite());
     client.add_suite(new Util.Avatar.Test().get_suite());
     client.add_suite(new Util.Cache.Test().get_suite());
     client.add_suite(new Util.Email.Test().get_suite());


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]