[geary/mjog/composer-context-loading-fixes: 1/14] test: Break out engine mock objects into their own name-space




commit 4cb27b35f1d134a2710c3951c28f7eeec483f591
Author: Michael Gratton <mike vee net>
Date:   Mon Aug 10 16:13:57 2020 +1000

    test: Break out engine mock objects into their own name-space
    
    Engine mocks don't need to be in the `Geary` namespace, and including
    them there makes it difficult to use them in client tests, so put them
    all in their own name-space and corresponding directory.

 test/client/accounts/accounts-manager-test.vala    |   2 +-
 test/client/util/util-email-test.vala              |   2 +-
 .../engine/api/geary-account-information-test.vala |  12 +-
 test/engine/api/geary-account-mock.vala            | 294 ---------------------
 test/engine/api/geary-email-test.vala              |   4 +-
 test/engine/api/geary-engine-test.vala             |   2 +-
 test/engine/app/app-conversation-monitor-test.vala |  18 +-
 test/engine/app/app-conversation-set-test.vala     |   6 +-
 test/engine/app/app-conversation-test.vala         |   6 +-
 .../common/common-contact-harvester-test.vala      |   4 +-
 test/engine/imap-db/imap-db-account-test.vala      |   2 +-
 test/engine/imap-db/imap-db-folder-test.vala       |   2 +-
 .../engine/imap-engine/account-processor-test.vala |   4 +-
 .../imap-engine-generic-account-test.vala          |   2 +-
 test/meson.build                                   |  41 ++-
 test/mock/mock-account.vala                        | 270 +++++++++++++++++++
 test/mock/mock-client-service.vala                 |  35 +++
 .../mock-contact-store.vala}                       |  24 +-
 .../mock-credentials-mediator.vala}                |  12 +-
 .../mock-email-identifier.vala}                    |   8 +-
 .../mock-email-properties.vala}                    |   6 +-
 .../mock-folder-properties.vala}                   |  10 +-
 .../mock-folder.vala}                              |  70 ++---
 test/mock/mock-search-query.vala                   |  14 +
 24 files changed, 436 insertions(+), 414 deletions(-)
---
diff --git a/test/client/accounts/accounts-manager-test.vala b/test/client/accounts/accounts-manager-test.vala
index f4d89636c..4c3072f29 100644
--- a/test/client/accounts/accounts-manager-test.vala
+++ b/test/client/accounts/accounts-manager-test.vala
@@ -47,7 +47,7 @@ class Accounts.ManagerTest : TestCase {
             null, "test1 example com"
         );
 
-        this.mediator = new Geary.MockCredentialsMediator();
+        this.mediator = new Mock.CredentialsMediator();
         this.account = new Geary.AccountInformation(
             TEST_ID,
             Geary.ServiceProvider.OTHER,
diff --git a/test/client/util/util-email-test.vala b/test/client/util/util-email-test.vala
index a7161146d..fb3c365f5 100644
--- a/test/client/util/util-email-test.vala
+++ b/test/client/util/util-email-test.vala
@@ -99,7 +99,7 @@ public class Util.Email.Test : TestCase {
                                   Geary.RFC822.MailboxAddress? sender,
                                   Geary.RFC822.MailboxAddress? reply_to)
         throws GLib.Error {
-        Geary.Email email = new Geary.Email(new Geary.MockEmailIdentifer(1));
+        Geary.Email email = new Geary.Email(new Mock.EmailIdentifer(1));
         email.set_originators(
             from != null
             ? new Geary.RFC822.MailboxAddresses(Geary.Collection.single(from))
diff --git a/test/engine/api/geary-account-information-test.vala 
b/test/engine/api/geary-account-information-test.vala
index 3157fd4be..365ba92dc 100644
--- a/test/engine/api/geary-account-information-test.vala
+++ b/test/engine/api/geary-account-information-test.vala
@@ -20,7 +20,7 @@ class Geary.AccountInformationTest : TestCase {
             new AccountInformation(
                 "test",
                 ServiceProvider.OTHER,
-                new MockCredentialsMediator(),
+                new Mock.CredentialsMediator(),
                 new RFC822.MailboxAddress(null, "test1 example com")
             ).save_sent
         );
@@ -28,7 +28,7 @@ class Geary.AccountInformationTest : TestCase {
             new AccountInformation(
                 "test",
                 ServiceProvider.GMAIL,
-                new MockCredentialsMediator(),
+                new Mock.CredentialsMediator(),
                 new RFC822.MailboxAddress(null, "test1 example com")
             ).save_sent
         );
@@ -36,7 +36,7 @@ class Geary.AccountInformationTest : TestCase {
             new AccountInformation(
                 "test",
                 ServiceProvider.OUTLOOK,
-                new MockCredentialsMediator(),
+                new Mock.CredentialsMediator(),
                 new RFC822.MailboxAddress(null, "test1 example com")
             ).save_sent
         );
@@ -44,7 +44,7 @@ class Geary.AccountInformationTest : TestCase {
             new AccountInformation(
                 "test",
                 ServiceProvider.YAHOO,
-                new MockCredentialsMediator(),
+                new Mock.CredentialsMediator(),
                 new RFC822.MailboxAddress(null, "test1 example com")
             ).save_sent
         );
@@ -54,7 +54,7 @@ class Geary.AccountInformationTest : TestCase {
         AccountInformation test = new AccountInformation(
             "test",
             ServiceProvider.OTHER,
-            new MockCredentialsMediator(),
+            new Mock.CredentialsMediator(),
             new RFC822.MailboxAddress(null, "test1 example com")
         );
 
@@ -124,7 +124,7 @@ class Geary.AccountInformationTest : TestCase {
         return new AccountInformation(
             "test",
             provider,
-            new MockCredentialsMediator(),
+            new Mock.CredentialsMediator(),
             new RFC822.MailboxAddress(null, "test1 example com")
         );
     }
diff --git a/test/engine/api/geary-email-test.vala b/test/engine/api/geary-email-test.vala
index d52f929d3..8a80a94ac 100644
--- a/test/engine/api/geary-email-test.vala
+++ b/test/engine/api/geary-email-test.vala
@@ -21,7 +21,7 @@ class Geary.EmailTest: TestCase {
 
     public void email_from_basic_message() throws GLib.Error {
         var message = resource_to_message(BASIC_TEXT_PLAIN);
-        var email = new Email.from_message(new MockEmailIdentifer(0), message);
+        var email = new Email.from_message(new Mock.EmailIdentifer(0), message);
 
         assert_non_null(email);
         assert_non_null(email.subject);
@@ -30,7 +30,7 @@ class Geary.EmailTest: TestCase {
 
     public void email_from_multipart() throws GLib.Error {
         var message = resource_to_message(BASIC_MULTIPART_ALTERNATIVE);
-        var email = new Email.from_message(new MockEmailIdentifer(0), message);
+        var email = new Email.from_message(new Mock.EmailIdentifer(0), message);
 
         assert_non_null(email);
         assert_non_null(email.subject);
diff --git a/test/engine/api/geary-engine-test.vala b/test/engine/api/geary-engine-test.vala
index a671ee0df..f103186f1 100644
--- a/test/engine/api/geary-engine-test.vala
+++ b/test/engine/api/geary-engine-test.vala
@@ -49,7 +49,7 @@ class Geary.EngineTest : TestCase {
         this.account = new AccountInformation(
             "test",
             ServiceProvider.OTHER,
-            new MockCredentialsMediator(),
+            new Mock.CredentialsMediator(),
             new RFC822.MailboxAddress(null, "test1 example com")
         );
         this.account.set_account_directories(this.tmp, this.tmp);
diff --git a/test/engine/app/app-conversation-monitor-test.vala 
b/test/engine/app/app-conversation-monitor-test.vala
index 2d813d310..ca8dd3477 100644
--- a/test/engine/app/app-conversation-monitor-test.vala
+++ b/test/engine/app/app-conversation-monitor-test.vala
@@ -10,10 +10,10 @@ class Geary.App.ConversationMonitorTest : TestCase {
 
 
     AccountInformation? account_info = null;
-    MockAccount? account = null;
+    Mock.Account? account = null;
     FolderRoot? folder_root = null;
-    MockFolder? base_folder = null;
-    MockFolder? other_folder = null;
+    Mock.Folder? base_folder = null;
+    Mock.Folder? other_folder = null;
 
 
     public ConversationMonitorTest() {
@@ -35,19 +35,19 @@ class Geary.App.ConversationMonitorTest : TestCase {
         this.account_info = new AccountInformation(
             "account_01",
             ServiceProvider.OTHER,
-            new MockCredentialsMediator(),
+            new Mock.CredentialsMediator(),
             new RFC822.MailboxAddress(null, "test1 example com")
         );
-        this.account = new MockAccount(this.account_info);
+        this.account = new Mock.Account(this.account_info);
         this.folder_root = new FolderRoot("#test", false);
-        this.base_folder = new MockFolder(
+        this.base_folder = new Mock.Folder(
             this.account,
             null,
             this.folder_root.get_child("base"),
             NONE,
             null
         );
-        this.other_folder = new MockFolder(
+        this.other_folder = new Mock.Folder(
             this.account,
             null,
             this.folder_root.get_child("other"),
@@ -425,7 +425,7 @@ class Geary.App.ConversationMonitorTest : TestCase {
     }
 
     private Email setup_email(int id, Email? references = null) {
-        Email email = new Email(new MockEmailIdentifer(id));
+        Email email = new Email(new Mock.EmailIdentifer(id));
         DateTime now = new DateTime.now_local();
         Geary.RFC822.MessageID mid = new Geary.RFC822.MessageID(
             "test%d@localhost".printf(id)
@@ -438,7 +438,7 @@ class Geary.App.ConversationMonitorTest : TestCase {
             );
         }
         email.set_send_date(new RFC822.Date(now));
-        email.set_email_properties(new MockEmailProperties(now));
+        email.set_email_properties(new Mock.EmailProperties(now));
         email.set_full_references(mid, null, refs_list);
         return email;
     }
diff --git a/test/engine/app/app-conversation-set-test.vala b/test/engine/app/app-conversation-set-test.vala
index 37801b9b7..30149bc17 100644
--- a/test/engine/app/app-conversation-set-test.vala
+++ b/test/engine/app/app-conversation-set-test.vala
@@ -29,7 +29,7 @@ class Geary.App.ConversationSetTest : TestCase {
 
     public override void set_up() {
         this.folder_root = new FolderRoot("#test", false);
-        this.base_folder = new MockFolder(
+        this.base_folder = new Mock.Folder(
             null,
             null,
             this.folder_root.get_child("test"),
@@ -477,7 +477,7 @@ class Geary.App.ConversationSetTest : TestCase {
     }
 
     private Email setup_email(int id, Email? references = null) {
-        Email email = new Email(new MockEmailIdentifer(id));
+        Email email = new Email(new Mock.EmailIdentifer(id));
         DateTime now = new DateTime.now_local();
         Geary.RFC822.MessageID mid = new Geary.RFC822.MessageID(
             "test%d@localhost".printf(id)
@@ -490,7 +490,7 @@ class Geary.App.ConversationSetTest : TestCase {
             );
         }
         email.set_send_date(new RFC822.Date(now));
-        email.set_email_properties(new MockEmailProperties(now));
+        email.set_email_properties(new Mock.EmailProperties(now));
         email.set_full_references(mid, null, refs_list);
         return email;
     }
diff --git a/test/engine/app/app-conversation-test.vala b/test/engine/app/app-conversation-test.vala
index 98a519fd2..014aa4d22 100644
--- a/test/engine/app/app-conversation-test.vala
+++ b/test/engine/app/app-conversation-test.vala
@@ -29,7 +29,7 @@ class Geary.App.ConversationTest : TestCase {
 
     public override void set_up() {
         this.folder_root = new FolderRoot("#test", false);
-        this.base_folder = new MockFolder(
+        this.base_folder = new Mock.Folder(
             null,
             null,
             this.folder_root.get_child("test"),
@@ -243,13 +243,13 @@ class Geary.App.ConversationTest : TestCase {
 
 
     private Email setup_email(int id) {
-        Email email = new Email(new MockEmailIdentifer(id));
+        Email email = new Email(new Mock.EmailIdentifer(id));
         DateTime now = new DateTime.now_local();
         Geary.RFC822.MessageID mid = new Geary.RFC822.MessageID(
             "test%d@localhost".printf(id)
         );
         email.set_full_references(mid, null, null);
-        email.set_email_properties(new MockEmailProperties(now));
+        email.set_email_properties(new Mock.EmailProperties(now));
         email.set_send_date(new RFC822.Date(now));
         return email;
     }
diff --git a/test/engine/common/common-contact-harvester-test.vala 
b/test/engine/common/common-contact-harvester-test.vala
index c4901b552..75ea85f83 100644
--- a/test/engine/common/common-contact-harvester-test.vala
+++ b/test/engine/common/common-contact-harvester-test.vala
@@ -9,7 +9,7 @@
 class Geary.ContactHarvesterImplTest : TestCase {
 
 
-    private ContactStoreMock? store = null;
+    private Mock.ContactStore? store = null;
     private Email? email = null;
     private RFC822.MailboxAddress test_address = null;
     private RFC822.MailboxAddress sender_address = null;
@@ -26,7 +26,7 @@ class Geary.ContactHarvesterImplTest : TestCase {
     }
 
     public override void set_up() throws GLib.Error {
-        this.store = new ContactStoreMock();
+        this.store = new Mock.ContactStore();
         this.email = new Email(
             new ImapDB.EmailIdentifier.no_message_id(new Imap.UID(1))
         );
diff --git a/test/engine/imap-db/imap-db-account-test.vala b/test/engine/imap-db/imap-db-account-test.vala
index 49234c6b8..9d699fc31 100644
--- a/test/engine/imap-db/imap-db-account-test.vala
+++ b/test/engine/imap-db/imap-db-account-test.vala
@@ -37,7 +37,7 @@ class Geary.ImapDB.AccountTest : TestCase {
         this.config = new Geary.AccountInformation(
             "test",
             ServiceProvider.OTHER,
-            new MockCredentialsMediator(),
+            new Mock.CredentialsMediator(),
             new Geary.RFC822.MailboxAddress(null, "test example com")
         );
 
diff --git a/test/engine/imap-db/imap-db-folder-test.vala b/test/engine/imap-db/imap-db-folder-test.vala
index 23da46690..be02bcb5e 100644
--- a/test/engine/imap-db/imap-db-folder-test.vala
+++ b/test/engine/imap-db/imap-db-folder-test.vala
@@ -37,7 +37,7 @@ class Geary.ImapDB.FolderTest : TestCase {
         this.config = new Geary.AccountInformation(
             "test",
             ServiceProvider.OTHER,
-            new MockCredentialsMediator(),
+            new Mock.CredentialsMediator(),
             new Geary.RFC822.MailboxAddress(null, "test example com")
         );
 
diff --git a/test/engine/imap-engine/account-processor-test.vala 
b/test/engine/imap-engine/account-processor-test.vala
index 37456ff3d..f51ed00ca 100644
--- a/test/engine/imap-engine/account-processor-test.vala
+++ b/test/engine/imap-engine/account-processor-test.vala
@@ -67,10 +67,10 @@ public class Geary.ImapEngine.AccountProcessorTest : TestCase {
         this.info = new Geary.AccountInformation(
             "test-info",
             ServiceProvider.OTHER,
-            new MockCredentialsMediator(),
+            new Mock.CredentialsMediator(),
             new RFC822.MailboxAddress(null, "test1 example com")
         );
-        this.account = new Geary.MockAccount(this.info);
+        this.account = new Mock.Account(this.info);
         this.processor = new AccountProcessor();
 
         this.succeeded = 0;
diff --git a/test/engine/imap-engine/imap-engine-generic-account-test.vala 
b/test/engine/imap-engine/imap-engine-generic-account-test.vala
index 6225970f6..6bc8246ae 100644
--- a/test/engine/imap-engine/imap-engine-generic-account-test.vala
+++ b/test/engine/imap-engine/imap-engine-generic-account-test.vala
@@ -48,7 +48,7 @@ public class Geary.ImapEngine.GenericAccountTest : TestCase {
         this.config = new Geary.AccountInformation(
             "test",
             ServiceProvider.OTHER,
-            new MockCredentialsMediator(),
+            new Mock.CredentialsMediator(),
             new Geary.RFC822.MailboxAddress(null, "test example com")
         );
 
diff --git a/test/meson.build b/test/meson.build
index 4ccfbd0f5..b529ab464 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -1,22 +1,27 @@
 subdir('data')
 
+# Mock classes should be compiled into a stand-alone test lib for
+# re-use by both client and engine test suites, but we can't since
+# that would depend on geary-engine.vapi, and the engine test sute
+# needs to depend geary-engine_internal.vapi, which leads to duplicate
+# symbols when linking. So just duplicate the sources in both.
+libmock_sources = [
+  'mock/mock-account.vala',
+  'mock/mock-contact-store.vala',
+  'mock/mock-client-service.vala',
+  'mock/mock-credentials-mediator.vala',
+  'mock/mock-email-identifier.vala',
+  'mock/mock-email-properties.vala',
+  'mock/mock-folder.vala',
+  'mock/mock-folder-properties.vala',
+  'mock/mock-search-query.vala',
+]
+
 geary_test_engine_sources = [
   'test-case.vala',
   'test-server.vala',
   'test-engine.vala',
 
-  # These should be included in the test lib sources, but we can't
-  # since that would make the test lib depend on geary-engine.vapi,
-  # and the engine test sute needs to depend
-  # geary-engine_internal.vapi, which leads to duplicate symbols when
-  # linking
-  'engine/api/geary-account-mock.vala',
-  'engine/api/geary-contact-store-mock.vala',
-  'engine/api/geary-credentials-mediator-mock.vala',
-  'engine/api/geary-email-identifier-mock.vala',
-  'engine/api/geary-email-properties-mock.vala',
-  'engine/api/geary-folder-mock.vala',
-  'engine/api/geary-folder-properties-mock.vala',
   'engine/common/common-contact-harvester-mock.vala',
 
   'engine/api/geary-account-information-test.vala',
@@ -72,14 +77,6 @@ geary_test_client_sources = [
   'test-case.vala',
   'test-client.vala',
 
-  # These should be included in the test lib sources, but we can't
-  # since that would make the test lib depend on geary-engine.vapi,
-  # and the engine test sute needs to depend
-  # geary-engine_internal.vapi, which leads to duplicate symbols when
-  # linking
-  'engine/api/geary-email-identifier-mock.vala',
-  'engine/api/geary-credentials-mediator-mock.vala',
-
   'client/accounts/accounts-manager-test.vala',
   'client/application/application-client-test.vala',
   'client/application/application-configuration-test.vala',
@@ -126,7 +123,7 @@ if get_option('tnef-support')
 endif
 
 geary_test_engine_bin = executable('test-engine',
-  geary_test_engine_sources,
+  geary_test_engine_sources + libmock_sources,
   dependencies: geary_test_engine_dependencies,
   include_directories: config_h_dir,
   vala_args: geary_test_engine_vala_args,
@@ -142,7 +139,7 @@ geary_test_client_dependencies = [
 geary_test_client_dependencies += geary_client_dependencies
 
 geary_test_client_bin = executable('test-client',
-  geary_test_client_sources,
+  geary_test_client_sources + libmock_sources,
   dependencies: geary_test_client_dependencies,
   include_directories: config_h_dir,
   vala_args: geary_vala_args,
diff --git a/test/mock/mock-account.vala b/test/mock/mock-account.vala
new file mode 100644
index 000000000..7d598a0aa
--- /dev/null
+++ b/test/mock/mock-account.vala
@@ -0,0 +1,270 @@
+/*
+ * Copyright © 2017-2020 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.
+ */
+
+public class Mock.Account : Geary.Account,
+    ValaUnit.TestAssertions,
+    ValaUnit.MockObject {
+
+
+    protected Gee.Queue<ValaUnit.ExpectedCall> expected {
+        get; set; default = new Gee.LinkedList<ValaUnit.ExpectedCall>();
+    }
+
+
+    public Account(Geary.AccountInformation config) {
+        base(config,
+             new ClientService(
+                 config,
+                 config.incoming,
+                 new Geary.Endpoint(
+                     new GLib.NetworkAddress(
+                         config.incoming.host, config.incoming.port
+                     ),
+                     0, 0
+                 )
+             ),
+             new ClientService(
+                 config,
+                 config.outgoing,
+                 new Geary.Endpoint(
+                     new GLib.NetworkAddress(
+                         config.outgoing.host, config.outgoing.port
+                     ),
+                     0, 0
+                 )
+             )
+        );
+    }
+
+    public override async void open_async(GLib.Cancellable? cancellable = null)
+        throws GLib.Error {
+        void_call("open_async", { cancellable });
+    }
+
+    public override async void close_async(GLib.Cancellable? cancellable = null)
+        throws GLib.Error {
+        void_call("close_async", { cancellable });
+    }
+
+    public override bool is_open() {
+        try {
+            return boolean_call("is_open", {}, false);
+        } catch (GLib.Error err) {
+            return false;
+        }
+    }
+
+    public override async void rebuild_async(GLib.Cancellable? cancellable = null)
+        throws GLib.Error {
+        void_call("rebuild_async", { cancellable });
+    }
+
+    public override Gee.Collection<Geary.Folder>
+        list_matching_folders(Geary.FolderPath? parent) {
+        try {
+            return object_call<Gee.Collection<Geary.Folder>>(
+                "get_containing_folders_async",
+                {parent},
+                Gee.List.empty<Geary.Folder>()
+            );
+        } catch (GLib.Error err) {
+            return Gee.Collection.empty<Geary.Folder>();
+        }
+    }
+
+    public override async Geary.Folder create_personal_folder(
+        string name,
+        Geary.Folder.SpecialUse use = NONE,
+        GLib.Cancellable? cancellable = null
+    ) throws GLib.Error {
+        return object_call<Folder>(
+            "create_personal_folder",
+            { box_arg(name), box_arg(use), cancellable },
+            new Folder(null, null, null, use, null)
+        );
+    }
+
+    public override Geary.EmailIdentifier to_email_identifier(GLib.Variant serialised)
+        throws Geary.EngineError.BAD_PARAMETERS {
+        try {
+            return object_or_throw_call<Geary.EmailIdentifier>(
+                "to_email_identifier",
+                { box_arg(serialised) },
+                new Geary.EngineError.BAD_PARAMETERS("Mock error")
+            );
+        } catch (Geary.EngineError.BAD_PARAMETERS err) {
+            throw err;
+        } catch (GLib.Error err) {
+            return new EmailIdentifer(0);
+        }
+    }
+
+    public override Geary.FolderPath to_folder_path(GLib.Variant serialised)
+        throws Geary.EngineError.BAD_PARAMETERS {
+        try {
+            return object_or_throw_call<Geary.FolderPath>(
+                "to_folder_path",
+                { box_arg(serialised) },
+                new Geary.EngineError.BAD_PARAMETERS("Mock error")
+            );
+        } catch (Geary.EngineError.BAD_PARAMETERS err) {
+            throw err;
+        } catch (GLib.Error err) {
+            return new Geary.FolderRoot("#mock", false);
+        }
+    }
+
+    public override Geary.Folder get_folder(Geary.FolderPath path)
+        throws Geary.EngineError.NOT_FOUND {
+        try {
+            return object_or_throw_call<Folder>(
+                "get_folder",
+                { path },
+                new Geary.EngineError.NOT_FOUND("Mock error")
+            );
+        } catch (Geary.EngineError.NOT_FOUND err) {
+            throw err;
+        } catch (GLib.Error err) {
+            return new Folder(null, null, null, NONE, null);
+        }
+    }
+
+    public override Gee.Collection<Geary.Folder> list_folders() {
+        try {
+            return object_call<Gee.Collection<Geary.Folder>>(
+                "list_folders", {}, Gee.List.empty<Geary.Folder>()
+            );
+        } catch (GLib.Error err) {
+            return Gee.List.empty<Geary.Folder>();
+        }
+    }
+
+    public override Geary.Folder? get_special_folder(Geary.Folder.SpecialUse special) {
+        try {
+            return object_call<Geary.Folder?>(
+                "get_special_folder", {box_arg(special)}, null
+            );
+        } catch (GLib.Error err) {
+            return null;
+        }
+    }
+
+    public override async Geary.Folder
+        get_required_special_folder_async(Geary.Folder.SpecialUse special,
+                                          GLib.Cancellable? cancellable = null)
+    throws GLib.Error {
+        return object_or_throw_call<Geary.Folder>(
+            "get_required_special_folder_async",
+            { box_arg(special), cancellable },
+            new Geary.EngineError.NOT_FOUND("Mock call")
+        );
+    }
+
+    public override async Gee.MultiMap<Geary.Email,Geary.FolderPath?>?
+        local_search_message_id_async(Geary.RFC822.MessageID message_id,
+                                      Geary.Email.Field requested_fields,
+                                      bool partial_ok,
+                                      Gee.Collection<Geary.FolderPath?>? folder_blacklist,
+                                      Geary.EmailFlags? flag_blacklist,
+                                      GLib.Cancellable? cancellable = null)
+        throws GLib.Error {
+        return object_call<Gee.MultiMap<Geary.Email,Geary.FolderPath?>?>(
+            "local_search_message_id_async",
+            {
+                message_id,
+                box_arg(requested_fields),
+                box_arg(partial_ok),
+                folder_blacklist,
+                flag_blacklist,
+                cancellable
+            },
+            null
+        );
+    }
+
+    public override async Gee.List<Geary.Email> list_local_email_async(
+        Gee.Collection<Geary.EmailIdentifier> ids,
+        Geary.Email.Field required_fields,
+        GLib.Cancellable? cancellable = null
+    ) throws GLib.Error {
+        return object_or_throw_call<Gee.List<Geary.Email>>(
+            "list_local_email_async",
+            {ids, box_arg(required_fields), cancellable},
+            new Geary.EngineError.NOT_FOUND("Mock call")
+        );
+    }
+
+    public override async Geary.Email
+        local_fetch_email_async(Geary.EmailIdentifier email_id,
+                                Geary.Email.Field required_fields,
+                                GLib.Cancellable? cancellable = null)
+        throws GLib.Error {
+        return object_or_throw_call<Geary.Email>(
+            "local_fetch_email_async",
+            {email_id, box_arg(required_fields), cancellable},
+            new Geary.EngineError.NOT_FOUND("Mock call")
+        );
+    }
+
+    public override async Geary.SearchQuery
+        new_search_query(string raw,
+                         Geary.SearchQuery.Strategy strategy,
+                         GLib.Cancellable? cancellable)
+        throws GLib.Error {
+        return new SearchQuery(this, raw);
+    }
+
+    public override async Gee.Collection<Geary.EmailIdentifier>?
+        local_search_async(Geary.SearchQuery query,
+                           int limit = 100,
+                           int offset = 0,
+                           Gee.Collection<Geary.FolderPath?>? folder_blacklist = null,
+                           Gee.Collection<Geary.EmailIdentifier>? search_ids = null,
+                           GLib.Cancellable? cancellable = null)
+        throws GLib.Error {
+        return object_call<Gee.Collection<Geary.EmailIdentifier>?>(
+            "local_search_async",
+            {
+                query,
+                box_arg(limit),
+                box_arg(offset),
+                folder_blacklist,
+                search_ids,
+                cancellable
+            },
+            null
+        );
+    }
+
+    public override async Gee.Set<string>?
+        get_search_matches_async(Geary.SearchQuery query,
+                                 Gee.Collection<Geary.EmailIdentifier> ids,
+                                 GLib.Cancellable? cancellable = null)
+        throws GLib.Error {
+        return object_call<Gee.Set<string>?>(
+            "get_search_matches_async", {query, ids, cancellable}, null
+        );
+    }
+
+    public override async Gee.MultiMap<Geary.EmailIdentifier,Geary.FolderPath>?
+        get_containing_folders_async(Gee.Collection<Geary.EmailIdentifier> ids,
+                                     GLib.Cancellable? cancellable)
+        throws GLib.Error {
+        return object_call<Gee.MultiMap<Geary.EmailIdentifier, Geary.FolderPath>?>(
+            "get_containing_folders_async", {ids, cancellable}, null
+        );
+    }
+
+    public override async void cleanup_storage(GLib.Cancellable? cancellable) {
+        try {
+            void_call("cleanup_storage", {cancellable});
+        } catch (GLib.Error err) {
+            // fine
+        }
+    }
+
+}
diff --git a/test/mock/mock-client-service.vala b/test/mock/mock-client-service.vala
new file mode 100644
index 000000000..e7737cfe8
--- /dev/null
+++ b/test/mock/mock-client-service.vala
@@ -0,0 +1,35 @@
+/*
+ * Copyright © 2017-2020 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.
+ */
+
+public class Mock.ClientService : Geary.ClientService {
+
+
+    public ClientService(Geary.AccountInformation account,
+                         Geary.ServiceInformation configuration,
+                         Geary.Endpoint remote) {
+        base(account, configuration, remote);
+    }
+
+    public override async void start(GLib.Cancellable? cancellable = null)
+        throws GLib.Error {
+        throw new Geary.EngineError.UNSUPPORTED("Mock method");
+    }
+
+    public override async void stop(GLib.Cancellable? cancellable = null)
+        throws GLib.Error {
+        throw new Geary.EngineError.UNSUPPORTED("Mock method");
+    }
+
+    public override void became_reachable() {
+
+    }
+
+    public override void became_unreachable() {
+
+    }
+
+}
diff --git a/test/engine/api/geary-contact-store-mock.vala b/test/mock/mock-contact-store.vala
similarity index 51%
rename from test/engine/api/geary-contact-store-mock.vala
rename to test/mock/mock-contact-store.vala
index 2dbf4271d..c2c57979c 100644
--- a/test/engine/api/geary-contact-store-mock.vala
+++ b/test/mock/mock-contact-store.vala
@@ -5,27 +5,27 @@
  * (version 2.1 or later). See the COPYING file in this distribution.
  */
 
-internal class Geary.ContactStoreMock : GLib.Object,
-    ContactStore, ValaUnit.TestAssertions, ValaUnit.MockObject {
+internal class Mock.ContactStore : GLib.Object,
+    Geary.ContactStore, ValaUnit.TestAssertions, ValaUnit.MockObject {
 
     protected Gee.Queue<ValaUnit.ExpectedCall> expected {
         get; set; default = new Gee.LinkedList<ValaUnit.ExpectedCall>();
     }
 
-    public async Contact? get_by_rfc822(Geary.RFC822.MailboxAddress address,
-                                        GLib.Cancellable? cancellable)
+    public async Geary.Contact? get_by_rfc822(Geary.RFC822.MailboxAddress address,
+                                              GLib.Cancellable? cancellable)
         throws GLib.Error {
-        return object_call<Contact?>(
+        return object_call<Geary.Contact?>(
             "get_by_rfc822", { address, cancellable }, null
         );
     }
 
-    public async Gee.Collection<Contact> search(string query,
-                                                uint min_importance,
-                                                uint limit,
-                                                GLib.Cancellable? cancellable)
+    public async Gee.Collection<Geary.Contact> search(string query,
+                                                      uint min_importance,
+                                                      uint limit,
+                                                      GLib.Cancellable? cancellable)
         throws GLib.Error {
-        return object_call<Gee.Collection<Contact>>(
+        return object_call<Gee.Collection<Geary.Contact>>(
             "search",
             {
                 box_arg(query),
@@ -33,11 +33,11 @@ internal class Geary.ContactStoreMock : GLib.Object,
                 uint_arg(limit),
                 cancellable
             },
-            Gee.Collection.empty<Contact>()
+            Gee.Collection.empty<Geary.Contact>()
         );
     }
 
-    public async void update_contacts(Gee.Collection<Contact> updated,
+    public async void update_contacts(Gee.Collection<Geary.Contact> updated,
                                       GLib.Cancellable? cancellable)
         throws GLib.Error {
         void_call("update_contacts", { updated, cancellable });
diff --git a/test/engine/api/geary-credentials-mediator-mock.vala b/test/mock/mock-credentials-mediator.vala
similarity index 76%
rename from test/engine/api/geary-credentials-mediator-mock.vala
rename to test/mock/mock-credentials-mediator.vala
index 0604ea775..08e43bd1b 100644
--- a/test/engine/api/geary-credentials-mediator-mock.vala
+++ b/test/mock/mock-credentials-mediator.vala
@@ -5,9 +5,9 @@
  * (version 2.1 or later). See the COPYING file in this distribution.
  */
 
-public class Geary.MockCredentialsMediator :
+public class Mock.CredentialsMediator :
     GLib.Object,
-    CredentialsMediator,
+    Geary.CredentialsMediator,
     ValaUnit.TestAssertions,
     ValaUnit.MockObject {
 
@@ -16,8 +16,8 @@ public class Geary.MockCredentialsMediator :
         get; set; default = new Gee.LinkedList<ValaUnit.ExpectedCall>();
     }
 
-    public virtual async bool load_token(AccountInformation account,
-                                         ServiceInformation service,
+    public virtual async bool load_token(Geary.AccountInformation account,
+                                         Geary.ServiceInformation service,
                                          GLib.Cancellable? cancellable)
         throws GLib.Error {
         return object_call<bool>("load_token", { service, cancellable }, false);
@@ -31,8 +31,8 @@ public class Geary.MockCredentialsMediator :
      * are ignored).  Return false if the user tried to cancel the
      * interaction, or true if they tried to proceed.
      */
-    public virtual async bool prompt_token(AccountInformation account,
-                                           ServiceInformation service,
+    public virtual async bool prompt_token(Geary.AccountInformation account,
+                                           Geary.ServiceInformation service,
                                            GLib.Cancellable? cancellable)
         throws GLib.Error {
         return boolean_call(
diff --git a/test/engine/api/geary-email-identifier-mock.vala b/test/mock/mock-email-identifier.vala
similarity index 79%
rename from test/engine/api/geary-email-identifier-mock.vala
rename to test/mock/mock-email-identifier.vala
index 61b56bdcd..883d02896 100644
--- a/test/engine/api/geary-email-identifier-mock.vala
+++ b/test/mock/mock-email-identifier.vala
@@ -5,13 +5,13 @@
  * (version 2.1 or later). See the COPYING file in this distribution.
  */
 
-public class Geary.MockEmailIdentifer : EmailIdentifier {
+public class Mock.EmailIdentifer : Geary.EmailIdentifier {
 
 
     private int id;
 
 
-    public MockEmailIdentifer(int id) {
+    public EmailIdentifer(int id) {
         this.id = id;
     }
 
@@ -22,7 +22,7 @@ public class Geary.MockEmailIdentifer : EmailIdentifier {
     public override bool equal_to(Geary.EmailIdentifier other) {
         return (
             this.get_type() == other.get_type() &&
-            this.id == ((MockEmailIdentifer) other).id
+            this.id == ((EmailIdentifer) other).id
         );
     }
 
@@ -39,7 +39,7 @@ public class Geary.MockEmailIdentifer : EmailIdentifier {
     }
 
     public override int natural_sort_comparator(Geary.EmailIdentifier other) {
-        MockEmailIdentifer? other_mock = other as MockEmailIdentifer;
+        EmailIdentifer? other_mock = other as EmailIdentifer;
         return (other_mock == null) ? 1 : this.id - other_mock.id;
     }
 
diff --git a/test/engine/api/geary-email-properties-mock.vala b/test/mock/mock-email-properties.vala
similarity index 67%
rename from test/engine/api/geary-email-properties-mock.vala
rename to test/mock/mock-email-properties.vala
index 5f2d5a623..421719295 100644
--- a/test/engine/api/geary-email-properties-mock.vala
+++ b/test/mock/mock-email-properties.vala
@@ -5,15 +5,15 @@
  * (version 2.1 or later). See the COPYING file in this distribution.
  */
 
-public class Geary.MockEmailProperties : EmailProperties {
+public class Mock.EmailProperties : Geary.EmailProperties {
 
 
-    public MockEmailProperties(GLib.DateTime received) {
+    public EmailProperties(GLib.DateTime received) {
         base(received, 0);
     }
 
     public override string to_string() {
-        return "MockEmailProperties: %s/%lli".printf(
+        return "Mock.EmailProperties: %s/%lli".printf(
             this.date_received.to_string(), this.total_bytes
         );
     }
diff --git a/test/engine/api/geary-folder-properties-mock.vala b/test/mock/mock-folder-properties.vala
similarity index 61%
rename from test/engine/api/geary-folder-properties-mock.vala
rename to test/mock/mock-folder-properties.vala
index 5cefcada1..b87bfa335 100644
--- a/test/engine/api/geary-folder-properties-mock.vala
+++ b/test/mock/mock-folder-properties.vala
@@ -5,16 +5,16 @@
  * (version 2.1 or later). See the COPYING file in this distribution.
  */
 
-public class Geary.MockFolderPoperties : FolderProperties {
+public class Mock.FolderPoperties : Geary.FolderProperties {
 
 
-    public MockFolderPoperties() {
+    public FolderPoperties() {
         base(
             0,
             0,
-            Trillian.UNKNOWN,
-            Trillian.UNKNOWN,
-            Trillian.UNKNOWN,
+            Geary.Trillian.UNKNOWN,
+            Geary.Trillian.UNKNOWN,
+            Geary.Trillian.UNKNOWN,
             false,
             false,
             false
diff --git a/test/engine/api/geary-folder-mock.vala b/test/mock/mock-folder.vala
similarity index 54%
rename from test/engine/api/geary-folder-mock.vala
rename to test/mock/mock-folder.vala
index 44852c93d..52d100ba5 100644
--- a/test/engine/api/geary-folder-mock.vala
+++ b/test/mock/mock-folder.vala
@@ -5,28 +5,28 @@
  * (version 2.1 or later). See the COPYING file in this distribution.
  */
 
-public class Geary.MockFolder : Folder,
+public class Mock.Folder : Geary.Folder,
     ValaUnit.TestAssertions,
     ValaUnit.MockObject {
 
 
-    public override Account account {
+    public override Geary.Account account {
         get { return this._account; }
     }
 
-    public override FolderProperties properties {
+    public override Geary.FolderProperties properties {
         get { return this._properties; }
     }
 
-    public override FolderPath path {
+    public override Geary.FolderPath path {
         get { return this._path; }
     }
 
-    public override Folder.SpecialUse used_as {
+    public override Geary.Folder.SpecialUse used_as {
         get { return this._used_as; }
     }
 
-    public override ProgressMonitor opening_monitor {
+    public override Geary.ProgressMonitor opening_monitor {
         get { return this._opening_monitor; }
     }
 
@@ -35,31 +35,31 @@ public class Geary.MockFolder : Folder,
     }
 
 
-    private Account _account;
-    private FolderProperties _properties;
-    private FolderPath _path;
-    private Folder.SpecialUse _used_as;
-    private ProgressMonitor _opening_monitor;
+    private Geary.Account _account;
+    private Geary.FolderProperties _properties;
+    private Geary.FolderPath _path;
+    private Geary.Folder.SpecialUse _used_as;
+    private Geary.ProgressMonitor _opening_monitor;
 
 
-    public MockFolder(Account? account,
-                      FolderProperties? properties,
-                      FolderPath? path,
-                      Folder.SpecialUse used_as,
-                      ProgressMonitor? monitor) {
+    public Folder(Geary.Account? account,
+                  Geary.FolderProperties? properties,
+                  Geary.FolderPath? path,
+                  Geary.Folder.SpecialUse used_as,
+                  Geary.ProgressMonitor? monitor) {
         this._account = account;
-        this._properties = properties ?? new MockFolderPoperties();
+        this._properties = properties ?? new FolderPoperties();
         this._path = path;
         this._used_as = used_as;
         this._opening_monitor = monitor;
     }
 
-    public override Folder.OpenState get_open_state() {
-        return OpenState.CLOSED;
+    public override Geary.Folder.OpenState get_open_state() {
+        return Geary.Folder.OpenState.CLOSED;
     }
 
-    public override async bool open_async(Folder.OpenFlags open_flags,
-                                 Cancellable? cancellable = null)
+    public override async bool open_async(Geary.Folder.OpenFlags open_flags,
+                                          GLib.Cancellable? cancellable = null)
         throws GLib.Error {
         return yield boolean_call_async(
             "open_async",
@@ -68,16 +68,16 @@ public class Geary.MockFolder : Folder,
         );
     }
 
-    public override async bool close_async(Cancellable? cancellable = null)
+    public override async bool close_async(GLib.Cancellable? cancellable = null)
         throws GLib.Error {
         return yield boolean_call_async(
             "close_async", { cancellable }, false
         );
     }
 
-    public override async void wait_for_close_async(Cancellable? cancellable = null)
+    public override async void wait_for_close_async(GLib.Cancellable? cancellable = null)
     throws GLib.Error {
-        throw new EngineError.UNSUPPORTED("Mock method");
+        throw new Geary.EngineError.UNSUPPORTED("Mock method");
     }
 
     public override async void synchronise_remote(GLib.Cancellable? cancellable)
@@ -89,10 +89,10 @@ public class Geary.MockFolder : Folder,
         list_email_by_id_async(Geary.EmailIdentifier? initial_id,
                                int count,
                                Geary.Email.Field required_fields,
-                               Folder.ListFlags flags,
-                               Cancellable? cancellable = null)
+                               Geary.Folder.ListFlags flags,
+                               GLib.Cancellable? cancellable = null)
         throws GLib.Error {
-        return yield object_call_async<Gee.List<Email>?>(
+        return yield object_call_async<Gee.List<Geary.Email>?>(
             "list_email_by_id_async",
             {initial_id, int_arg(count), box_arg(required_fields), box_arg(flags), cancellable},
             null
@@ -102,10 +102,10 @@ public class Geary.MockFolder : Folder,
     public override async Gee.List<Geary.Email>?
         list_email_by_sparse_id_async(Gee.Collection<Geary.EmailIdentifier> ids,
                                       Geary.Email.Field required_fields,
-                                      Folder.ListFlags flags,
-                                      Cancellable? cancellable = null)
+                                      Geary.Folder.ListFlags flags,
+                                      GLib.Cancellable? cancellable = null)
         throws GLib.Error {
-        return yield object_call_async<Gee.List<Email>?>(
+        return yield object_call_async<Gee.List<Geary.Email>?>(
             "list_email_by_sparse_id_async",
             {ids, box_arg(required_fields), box_arg(flags), cancellable},
             null
@@ -115,15 +115,15 @@ public class Geary.MockFolder : Folder,
     public override async Geary.Email
         fetch_email_async(Geary.EmailIdentifier email_id,
                           Geary.Email.Field required_fields,
-                          Folder.ListFlags flags,
-                          Cancellable? cancellable = null)
+                          Geary.Folder.ListFlags flags,
+                          GLib.Cancellable? cancellable = null)
     throws GLib.Error {
-        throw new EngineError.UNSUPPORTED("Mock method");
+        throw new Geary.EngineError.UNSUPPORTED("Mock method");
     }
 
     public override void set_used_as_custom(bool enabled)
-        throws EngineError.UNSUPPORTED {
-        throw new EngineError.UNSUPPORTED("Mock method");
+        throws Geary.EngineError.UNSUPPORTED {
+        throw new Geary.EngineError.UNSUPPORTED("Mock method");
     }
 
 }
diff --git a/test/mock/mock-search-query.vala b/test/mock/mock-search-query.vala
new file mode 100644
index 000000000..6653f96de
--- /dev/null
+++ b/test/mock/mock-search-query.vala
@@ -0,0 +1,14 @@
+/*
+ * Copyright © 2017-2020 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.
+ */
+
+public class Mock.SearchQuery : Geary.SearchQuery {
+
+    internal SearchQuery(Geary.Account owner, string raw) {
+        base(owner, raw, Geary.SearchQuery.Strategy.EXACT);
+    }
+
+}



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