Tidy up Geary.AccountInformation creation.
Pass service provider to ctor so we can make the service provider property immutable. Fill in service label in ctor so it's always set to something useful. Move creating orphans from Engine to AccountManager since it exists only to assign an internal id for new accounts, so it should handled by the account manager anyway.
This commit is contained in:
parent
9c8990d18d
commit
74fa29b73f
11 changed files with 251 additions and 164 deletions
151
test/client/accounts/account-manager-test.vala
Normal file
151
test/client/accounts/account-manager-test.vala
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
* Copyright 2018 Michael Gratton <mike@vee.net>
|
||||
*
|
||||
* This software is licensed under the GNU Lesser General Public License
|
||||
* (version 2.1 or later). See the COPYING file in this distribution.
|
||||
*/
|
||||
|
||||
class AccountManagerTest : TestCase {
|
||||
|
||||
|
||||
private AccountManager? test = null;
|
||||
private File? tmp = null;
|
||||
|
||||
|
||||
public AccountManagerTest() {
|
||||
base("AccountManagerTest");
|
||||
add_test("create_account", create_account);
|
||||
add_test("create_orphan_account", create_orphan_account);
|
||||
add_test("create_orphan_account_with_legacy", create_orphan_account_with_legacy);
|
||||
}
|
||||
|
||||
public override void set_up() throws GLib.Error {
|
||||
// XXX this whole thing stinks. We need to be able to test the
|
||||
// engine without creating all of these dirs.
|
||||
|
||||
this.tmp = GLib.File.new_for_path(
|
||||
GLib.DirUtils.make_tmp("geary-engine-test-XXXXXX")
|
||||
);
|
||||
|
||||
GLib.File config = this.tmp.get_child("config");
|
||||
config.make_directory();
|
||||
|
||||
GLib.File data = this.tmp.get_child("data");
|
||||
data.make_directory();
|
||||
|
||||
this.test = new AccountManager(new GearyApplication(), config, data);
|
||||
}
|
||||
|
||||
public override void tear_down() throws GLib.Error {
|
||||
this.test = null;
|
||||
@delete(this.tmp);
|
||||
}
|
||||
|
||||
public void create_account() throws GLib.Error {
|
||||
const string ID = "test";
|
||||
Geary.AccountInformation account = new Geary.AccountInformation(
|
||||
ID,
|
||||
Geary.ServiceProvider.OTHER,
|
||||
new Geary.MockServiceInformation(),
|
||||
new Geary.MockServiceInformation()
|
||||
);
|
||||
bool was_added = false;
|
||||
bool was_enabled = false;
|
||||
|
||||
this.test.account_added.connect((added, status) => {
|
||||
was_added = (added == account);
|
||||
was_enabled = (status == AccountManager.Status.ENABLED);
|
||||
});
|
||||
|
||||
this.test.create_account.begin(
|
||||
account, new GLib.Cancellable(),
|
||||
(obj, res) => { async_complete(res); }
|
||||
);
|
||||
this.test.create_account.end(async_result());
|
||||
|
||||
assert_int(1, this.test.size, "Account manager size");
|
||||
assert_equal(account, this.test.get_account(ID), "Is not contained");
|
||||
assert_true(was_added, "Was not added");
|
||||
assert_true(was_enabled, "Was not enabled");
|
||||
}
|
||||
|
||||
public void create_orphan_account() throws GLib.Error {
|
||||
Geary.AccountInformation account1 = this.test.new_orphan_account(
|
||||
Geary.ServiceProvider.OTHER,
|
||||
new Geary.MockServiceInformation(),
|
||||
new Geary.MockServiceInformation()
|
||||
);
|
||||
assert(account1.id == "account_01");
|
||||
|
||||
this.test.create_account.begin(
|
||||
account1, new GLib.Cancellable(),
|
||||
(obj, res) => { async_complete(res); }
|
||||
);
|
||||
this.test.create_account.end(async_result());
|
||||
|
||||
Geary.AccountInformation account2 = this.test.new_orphan_account(
|
||||
Geary.ServiceProvider.OTHER,
|
||||
new Geary.MockServiceInformation(),
|
||||
new Geary.MockServiceInformation()
|
||||
);
|
||||
assert(account2.id == "account_02");
|
||||
}
|
||||
|
||||
public void create_orphan_account_with_legacy() throws GLib.Error {
|
||||
const string ID = "test";
|
||||
Geary.AccountInformation account = new Geary.AccountInformation(
|
||||
ID,
|
||||
Geary.ServiceProvider.OTHER,
|
||||
new Geary.MockServiceInformation(),
|
||||
new Geary.MockServiceInformation()
|
||||
);
|
||||
|
||||
this.test.create_account.begin(
|
||||
account, new GLib.Cancellable(),
|
||||
(obj, res) => { async_complete(res); }
|
||||
);
|
||||
this.test.create_account.end(async_result());
|
||||
|
||||
Geary.AccountInformation account1 = this.test.new_orphan_account(
|
||||
Geary.ServiceProvider.OTHER,
|
||||
new Geary.MockServiceInformation(),
|
||||
new Geary.MockServiceInformation()
|
||||
);
|
||||
assert(account1.id == "account_01");
|
||||
|
||||
this.test.create_account.begin(
|
||||
account1, new GLib.Cancellable(),
|
||||
(obj, res) => { async_complete(res); }
|
||||
);
|
||||
this.test.create_account.end(async_result());
|
||||
|
||||
Geary.AccountInformation account2 = this.test.new_orphan_account(
|
||||
Geary.ServiceProvider.OTHER,
|
||||
new Geary.MockServiceInformation(),
|
||||
new Geary.MockServiceInformation()
|
||||
);
|
||||
assert(account2.id == "account_02");
|
||||
}
|
||||
|
||||
private void delete(File parent) throws Error {
|
||||
FileInfo info = parent.query_info(
|
||||
"standard::*",
|
||||
FileQueryInfoFlags.NOFOLLOW_SYMLINKS
|
||||
);
|
||||
|
||||
if (info.get_file_type () == FileType.DIRECTORY) {
|
||||
FileEnumerator enumerator = parent.enumerate_children(
|
||||
"standard::*",
|
||||
FileQueryInfoFlags.NOFOLLOW_SYMLINKS
|
||||
);
|
||||
|
||||
info = null;
|
||||
while (((info = enumerator.next_file()) != null)) {
|
||||
@delete(parent.get_child(info.get_name()));
|
||||
}
|
||||
}
|
||||
|
||||
parent.delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -15,7 +15,10 @@ class Geary.AccountInformationTest : TestCase {
|
|||
|
||||
public void has_email_address() throws GLib.Error {
|
||||
AccountInformation test = new AccountInformation(
|
||||
"test", new MockServiceInformation(), new MockServiceInformation()
|
||||
"test",
|
||||
ServiceProvider.OTHER,
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
);
|
||||
|
||||
test.primary_mailbox = (new RFC822.MailboxAddress(null, "test1@example.com"));
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ class Geary.EngineTest : TestCase {
|
|||
add_test("add_account", add_account);
|
||||
add_test("remove_account", remove_account);
|
||||
add_test("re_add_account", re_add_account);
|
||||
add_test("create_orphan_account_with_legacy", create_orphan_account_with_legacy);
|
||||
add_test("create_orphan_account", create_orphan_account);
|
||||
}
|
||||
|
||||
~EngineTest() {
|
||||
|
|
@ -65,7 +63,9 @@ class Geary.EngineTest : TestCase {
|
|||
}
|
||||
|
||||
public void add_account() throws GLib.Error {
|
||||
AccountInformation info = this.engine.create_orphan_account(
|
||||
AccountInformation info = new AccountInformation(
|
||||
"test",
|
||||
ServiceProvider.OTHER,
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
);
|
||||
|
|
@ -83,7 +83,9 @@ class Geary.EngineTest : TestCase {
|
|||
}
|
||||
|
||||
public void remove_account() throws GLib.Error {
|
||||
AccountInformation info = this.engine.create_orphan_account(
|
||||
AccountInformation info = new AccountInformation(
|
||||
"test",
|
||||
ServiceProvider.OTHER,
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
);
|
||||
|
|
@ -98,7 +100,9 @@ class Geary.EngineTest : TestCase {
|
|||
}
|
||||
|
||||
public void re_add_account() throws GLib.Error {
|
||||
AccountInformation info = this.engine.create_orphan_account(
|
||||
AccountInformation info = new AccountInformation(
|
||||
"test",
|
||||
ServiceProvider.OTHER,
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
);
|
||||
|
|
@ -111,78 +115,7 @@ class Geary.EngineTest : TestCase {
|
|||
assert_true(this.engine.has_account(info.id));
|
||||
}
|
||||
|
||||
public void create_orphan_account() throws Error {
|
||||
try {
|
||||
AccountInformation info = this.engine.create_orphan_account(
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
);
|
||||
assert(info.id == "account_01");
|
||||
this.engine.add_account(info);
|
||||
|
||||
info = this.engine.create_orphan_account(
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
);
|
||||
assert(info.id == "account_02");
|
||||
this.engine.add_account(info);
|
||||
|
||||
info = this.engine.create_orphan_account(
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
);
|
||||
assert(info.id == "account_03");
|
||||
this.engine.add_account(info);
|
||||
|
||||
info = this.engine.create_orphan_account(
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
);
|
||||
assert(info.id == "account_04");
|
||||
} catch (Error err) {
|
||||
print("\nerr: %s\n", err.message);
|
||||
assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
public void create_orphan_account_with_legacy() throws Error {
|
||||
this.engine.add_account(
|
||||
new AccountInformation(
|
||||
"foo",
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
)
|
||||
);
|
||||
|
||||
AccountInformation info = this.engine.create_orphan_account(
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
);
|
||||
assert(info.id == "account_01");
|
||||
this.engine.add_account(info);
|
||||
|
||||
info = this.engine.create_orphan_account(
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
);
|
||||
assert(info.id == "account_02");
|
||||
|
||||
this.engine.add_account(
|
||||
new AccountInformation(
|
||||
"bar",
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
)
|
||||
);
|
||||
|
||||
info = this.engine.create_orphan_account(
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
);
|
||||
assert(info.id == "account_02");
|
||||
}
|
||||
|
||||
private void delete(File parent) throws Error {
|
||||
private void delete(File parent) throws Error {
|
||||
FileInfo info = parent.query_info(
|
||||
"standard::*",
|
||||
FileQueryInfoFlags.NOFOLLOW_SYMLINKS
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ class Geary.App.ConversationMonitorTest : TestCase {
|
|||
public override void set_up() {
|
||||
this.account_info = new AccountInformation(
|
||||
"account_01",
|
||||
ServiceProvider.OTHER,
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
);
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ public class Geary.ImapEngine.AccountProcessorTest : TestCase {
|
|||
public override void set_up() {
|
||||
this.info = new Geary.AccountInformation(
|
||||
"test-info",
|
||||
ServiceProvider.OTHER,
|
||||
new MockServiceInformation(),
|
||||
new MockServiceInformation()
|
||||
);
|
||||
|
|
|
|||
|
|
@ -61,6 +61,15 @@ geary_test_engine_sources = [
|
|||
geary_test_client_sources = [
|
||||
'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-credentials-mediator-mock.vala',
|
||||
'engine/api/geary-service-information-mock.vala',
|
||||
|
||||
'client/accounts/account-manager-test.vala',
|
||||
'client/application/geary-configuration-test.vala',
|
||||
'client/components/client-web-view-test.vala',
|
||||
'client/components/client-web-view-test-case.vala',
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ int main(string[] args) {
|
|||
|
||||
// Keep this before other ClientWebView based tests since it tests
|
||||
// WebContext init
|
||||
client.add_suite(new AccountManagerTest().get_suite());
|
||||
client.add_suite(new ClientWebViewTest().get_suite());
|
||||
client.add_suite(new ComposerWebViewTest().get_suite());
|
||||
client.add_suite(new ConfigurationTest().get_suite());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue