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.
This commit is contained in:
Michael Gratton 2020-08-10 16:13:57 +10:00 committed by Michael James Gratton
parent 3e156525ae
commit 2030b2dec7
24 changed files with 436 additions and 414 deletions

View file

@ -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,

View file

@ -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))

View file

@ -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")
);
}

View file

@ -1,294 +0,0 @@
/*
* Copyright 2017 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 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<ValaUnit.ExpectedCall> expected {
get; set; default = new Gee.LinkedList<ValaUnit.ExpectedCall>();
}
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<Folder> list_matching_folders(FolderPath? parent) {
try {
return object_call<Gee.Collection<Folder>>(
"get_containing_folders_async", {parent}, Gee.List.empty<Folder>()
);
} catch (GLib.Error err) {
return Gee.Collection.empty<Folder>();
}
}
public override async Folder create_personal_folder(
string name,
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 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<EmailIdentifier>(
"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<FolderPath>(
"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<Folder>(
"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<Folder> list_folders() {
try {
return object_call<Gee.Collection<Folder>>(
"list_folders", {}, Gee.List.empty<Folder>()
);
} catch (GLib.Error err) {
return Gee.List.empty<Folder>();
}
}
public override Folder? get_special_folder(Folder.SpecialUse special) {
try {
return object_call<Folder?>(
"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<Folder>(
"get_required_special_folder_async",
{box_arg(special), cancellable},
new EngineError.NOT_FOUND("Mock call")
);
}
public override async Gee.MultiMap<Email,FolderPath?>?
local_search_message_id_async(RFC822.MessageID message_id,
Email.Field requested_fields,
bool partial_ok,
Gee.Collection<FolderPath?>? folder_blacklist,
EmailFlags? flag_blacklist,
Cancellable? cancellable = null)
throws Error {
return object_call<Gee.MultiMap<Email,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<Email> list_local_email_async(
Gee.Collection<EmailIdentifier> ids,
Email.Field required_fields,
GLib.Cancellable? cancellable = null
) throws GLib.Error {
return object_or_throw_call<Gee.List<Email>>(
"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<Email>(
"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<EmailIdentifier>?
local_search_async(SearchQuery query,
int limit = 100,
int offset = 0,
Gee.Collection<FolderPath?>? folder_blacklist = null,
Gee.Collection<EmailIdentifier>? search_ids = null,
Cancellable? cancellable = null)
throws Error {
return object_call<Gee.Collection<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(SearchQuery query,
Gee.Collection<EmailIdentifier> ids,
Cancellable? cancellable = null)
throws Error {
return object_call<Gee.Set<string>?>(
"get_search_matches_async", {query, ids, cancellable}, null
);
}
public override async Gee.MultiMap<EmailIdentifier, FolderPath>?
get_containing_folders_async(Gee.Collection<EmailIdentifier> ids,
Cancellable? cancellable) throws Error {
return object_call<Gee.MultiMap<EmailIdentifier, FolderPath>?>(
"get_containing_folders_async", {ids, cancellable}, null
);
}
public override async void cleanup_storage(GLib.Cancellable? cancellable) {
}
}

View file

@ -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);

View file

@ -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);

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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))
);

View file

@ -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")
);

View file

@ -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")
);

View file

@ -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;

View file

@ -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")
);

View file

@ -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,

270
test/mock/mock-account.vala Normal file
View file

@ -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
}
}
}

View file

@ -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() {
}
}

View file

@ -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 });

View file

@ -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(

View file

@ -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;
}

View file

@ -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
);
}

View file

@ -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

View file

@ -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");
}
}

View file

@ -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);
}
}