diff --git a/test/client/accounts/accounts-manager-test.vala b/test/client/accounts/accounts-manager-test.vala index f4d89636..4c3072f2 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 a7161146..fb3c365f 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 3157fd4b..365ba92d 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-account-mock.vala b/test/engine/api/geary-account-mock.vala deleted file mode 100644 index d7fb167e..00000000 --- a/test/engine/api/geary-account-mock.vala +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright 2017 Michael Gratton - * - * 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 Geary.MockAccount : Account, - ValaUnit.TestAssertions, - ValaUnit.MockObject { - - - public class MockSearchQuery : SearchQuery { - - internal MockSearchQuery(Account owner, - string raw) { - base(owner, raw, SearchQuery.Strategy.EXACT); - } - - } - - - public class MockClientService : ClientService { - - public MockClientService(AccountInformation account, - ServiceInformation configuration, - Endpoint remote) { - base(account, configuration, remote); - } - - public override async void start(GLib.Cancellable? cancellable = null) - throws GLib.Error { - throw new EngineError.UNSUPPORTED("Mock method"); - } - - public override async void stop(GLib.Cancellable? cancellable = null) - throws GLib.Error { - throw new EngineError.UNSUPPORTED("Mock method"); - } - - public override void became_reachable() { - - } - - public override void became_unreachable() { - - } - - } - - - protected Gee.Queue expected { - get; set; default = new Gee.LinkedList(); - } - - - public MockAccount(AccountInformation config) { - base(config, - new MockClientService( - config, - config.incoming, - new Endpoint( - new GLib.NetworkAddress( - config.incoming.host, config.incoming.port - ), - 0, 0 - ) - ), - new MockClientService( - config, - config.outgoing, - new Endpoint( - new GLib.NetworkAddress( - config.outgoing.host, config.outgoing.port - ), - 0, 0 - ) - ) - ); - } - - public override async void open_async(Cancellable? cancellable = null) throws Error { - void_call("open_async", { cancellable }); - } - - public override async void close_async(Cancellable? cancellable = null) throws Error { - void_call("close_async", { cancellable }); - } - - public override bool is_open() { - try { - return boolean_call("is_open", {}, false); - } catch (Error err) { - return false; - } - } - - public override async void rebuild_async(Cancellable? cancellable = null) throws Error { - void_call("rebuild_async", { cancellable }); - } - - public override Gee.Collection list_matching_folders(FolderPath? parent) { - try { - return object_call>( - "get_containing_folders_async", {parent}, Gee.List.empty() - ); - } catch (GLib.Error err) { - return Gee.Collection.empty(); - } - } - - public override async Folder create_personal_folder( - string name, - Folder.SpecialUse use = NONE, - GLib.Cancellable? cancellable = null - ) throws GLib.Error { - return object_call( - "create_personal_folder", - { box_arg(name), box_arg(use), cancellable }, - new MockFolder(null, null, null, use, null) - ); - } - - public override EmailIdentifier to_email_identifier(GLib.Variant serialised) - throws EngineError.BAD_PARAMETERS { - try { - return object_or_throw_call( - "to_email_identifier", - { box_arg(serialised) }, - new EngineError.BAD_PARAMETERS("Mock error") - ); - } catch (EngineError.BAD_PARAMETERS err) { - throw err; - } catch (GLib.Error err) { - return new MockEmailIdentifer(0); - } - } - - public override FolderPath to_folder_path(GLib.Variant serialised) - throws EngineError.BAD_PARAMETERS { - try { - return object_or_throw_call( - "to_folder_path", - { box_arg(serialised) }, - new EngineError.BAD_PARAMETERS("Mock error") - ); - } catch (EngineError.BAD_PARAMETERS err) { - throw err; - } catch (GLib.Error err) { - return new FolderRoot("#mock", false); - } - } - - public override Folder get_folder(FolderPath path) - throws EngineError.NOT_FOUND { - try { - return object_or_throw_call( - "get_folder", - { path }, - new EngineError.NOT_FOUND("Mock error") - ); - } catch (EngineError.NOT_FOUND err) { - throw err; - } catch (GLib.Error err) { - return new MockFolder(null, null, null, NONE, null); - } - } - - public override Gee.Collection list_folders() { - try { - return object_call>( - "list_folders", {}, Gee.List.empty() - ); - } catch (GLib.Error err) { - return Gee.List.empty(); - } - } - - public override Folder? get_special_folder(Folder.SpecialUse special) { - try { - return object_call( - "get_special_folder", {box_arg(special)}, null - ); - } catch (GLib.Error err) { - return null; - } - } - - public override async Folder get_required_special_folder_async(Folder.SpecialUse special, - Cancellable? cancellable = null) - throws Error { - return object_or_throw_call( - "get_required_special_folder_async", - {box_arg(special), cancellable}, - new EngineError.NOT_FOUND("Mock call") - ); - } - - public override async Gee.MultiMap? - local_search_message_id_async(RFC822.MessageID message_id, - Email.Field requested_fields, - bool partial_ok, - Gee.Collection? folder_blacklist, - EmailFlags? flag_blacklist, - Cancellable? cancellable = null) - throws Error { - return object_call?>( - "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 list_local_email_async( - Gee.Collection ids, - Email.Field required_fields, - GLib.Cancellable? cancellable = null - ) throws GLib.Error { - return object_or_throw_call>( - "list_local_email_async", - {ids, box_arg(required_fields), cancellable}, - new EngineError.NOT_FOUND("Mock call") - ); - } - - public override async Email local_fetch_email_async(EmailIdentifier email_id, - Email.Field required_fields, - Cancellable? cancellable = null) - throws Error { - return object_or_throw_call( - "local_fetch_email_async", - {email_id, box_arg(required_fields), cancellable}, - new EngineError.NOT_FOUND("Mock call") - ); - } - - public override async SearchQuery new_search_query(string raw, - SearchQuery.Strategy strategy, - GLib.Cancellable? cancellable) - throws GLib.Error { - return new MockSearchQuery(this, raw); - } - - public override async Gee.Collection? - local_search_async(SearchQuery query, - int limit = 100, - int offset = 0, - Gee.Collection? folder_blacklist = null, - Gee.Collection? search_ids = null, - Cancellable? cancellable = null) - throws Error { - return object_call?>( - "local_search_async", - { - query, - box_arg(limit), - box_arg(offset), - folder_blacklist, - search_ids, - cancellable - }, - null - ); - } - - public override async Gee.Set? - get_search_matches_async(SearchQuery query, - Gee.Collection ids, - Cancellable? cancellable = null) - throws Error { - return object_call?>( - "get_search_matches_async", {query, ids, cancellable}, null - ); - } - - public override async Gee.MultiMap? - get_containing_folders_async(Gee.Collection ids, - Cancellable? cancellable) throws Error { - return object_call?>( - "get_containing_folders_async", {ids, cancellable}, null - ); - } - - public override async void cleanup_storage(GLib.Cancellable? cancellable) { - - } -} diff --git a/test/engine/api/geary-email-test.vala b/test/engine/api/geary-email-test.vala index d52f929d..8a80a94a 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 a671ee0d..f103186f 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 2d813d31..ca8dd347 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 37801b9b..30149bc1 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 98a519fd..014aa4d2 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 c4901b55..75ea85f8 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 49234c6b..9d699fc3 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 23da4669..be02bcb5 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 37456ff3..f51ed00c 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 6225970f..6bc8246a 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 4ccfbd0f..b529ab46 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 00000000..7d598a0a --- /dev/null +++ b/test/mock/mock-account.vala @@ -0,0 +1,270 @@ +/* + * Copyright © 2017-2020 Michael Gratton + * + * 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 expected { + get; set; default = new Gee.LinkedList(); + } + + + 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 + list_matching_folders(Geary.FolderPath? parent) { + try { + return object_call>( + "get_containing_folders_async", + {parent}, + Gee.List.empty() + ); + } catch (GLib.Error err) { + return Gee.Collection.empty(); + } + } + + 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( + "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( + "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( + "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( + "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 list_folders() { + try { + return object_call>( + "list_folders", {}, Gee.List.empty() + ); + } catch (GLib.Error err) { + return Gee.List.empty(); + } + } + + public override Geary.Folder? get_special_folder(Geary.Folder.SpecialUse special) { + try { + return object_call( + "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( + "get_required_special_folder_async", + { box_arg(special), cancellable }, + new Geary.EngineError.NOT_FOUND("Mock call") + ); + } + + public override async Gee.MultiMap? + local_search_message_id_async(Geary.RFC822.MessageID message_id, + Geary.Email.Field requested_fields, + bool partial_ok, + Gee.Collection? folder_blacklist, + Geary.EmailFlags? flag_blacklist, + GLib.Cancellable? cancellable = null) + throws GLib.Error { + return object_call?>( + "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 list_local_email_async( + Gee.Collection ids, + Geary.Email.Field required_fields, + GLib.Cancellable? cancellable = null + ) throws GLib.Error { + return object_or_throw_call>( + "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( + "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? + local_search_async(Geary.SearchQuery query, + int limit = 100, + int offset = 0, + Gee.Collection? folder_blacklist = null, + Gee.Collection? search_ids = null, + GLib.Cancellable? cancellable = null) + throws GLib.Error { + return object_call?>( + "local_search_async", + { + query, + box_arg(limit), + box_arg(offset), + folder_blacklist, + search_ids, + cancellable + }, + null + ); + } + + public override async Gee.Set? + get_search_matches_async(Geary.SearchQuery query, + Gee.Collection ids, + GLib.Cancellable? cancellable = null) + throws GLib.Error { + return object_call?>( + "get_search_matches_async", {query, ids, cancellable}, null + ); + } + + public override async Gee.MultiMap? + get_containing_folders_async(Gee.Collection ids, + GLib.Cancellable? cancellable) + throws GLib.Error { + return object_call?>( + "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 00000000..e7737cfe --- /dev/null +++ b/test/mock/mock-client-service.vala @@ -0,0 +1,35 @@ +/* + * Copyright © 2017-2020 Michael Gratton + * + * 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 2dbf4271..c2c57979 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 expected { get; set; default = new Gee.LinkedList(); } - 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( + return object_call( "get_by_rfc822", { address, cancellable }, null ); } - public async Gee.Collection search(string query, - uint min_importance, - uint limit, - GLib.Cancellable? cancellable) + public async Gee.Collection search(string query, + uint min_importance, + uint limit, + GLib.Cancellable? cancellable) throws GLib.Error { - return object_call>( + return object_call>( "search", { box_arg(query), @@ -33,11 +33,11 @@ internal class Geary.ContactStoreMock : GLib.Object, uint_arg(limit), cancellable }, - Gee.Collection.empty() + Gee.Collection.empty() ); } - public async void update_contacts(Gee.Collection updated, + public async void update_contacts(Gee.Collection 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 0604ea77..08e43bd1 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(); } - 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("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 61b56bdc..883d0289 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 5f2d5a62..42171929 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 5cefcada..b87bfa33 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 44852c93..52d100ba 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?>( + return yield object_call_async?>( "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? list_email_by_sparse_id_async(Gee.Collection 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?>( + return yield object_call_async?>( "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 00000000..6653f96d --- /dev/null +++ b/test/mock/mock-search-query.vala @@ -0,0 +1,14 @@ +/* + * Copyright © 2017-2020 Michael Gratton + * + * 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); + } + +}