2017-02-17 17:41:16 +11:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-03-09 11:58:02 +11:00
|
|
|
class Geary.EngineTest : TestCase {
|
2017-02-17 17:41:16 +11:00
|
|
|
|
2018-05-23 16:14:21 +10:00
|
|
|
|
2017-02-17 17:41:16 +11:00
|
|
|
private Engine? engine = null;
|
|
|
|
|
private File? tmp = null;
|
|
|
|
|
private File? res = null;
|
2018-12-08 13:53:37 +11:00
|
|
|
private Geary.AccountInformation? account = null;
|
2017-02-17 17:41:16 +11:00
|
|
|
|
2018-05-23 16:14:21 +10:00
|
|
|
|
2017-02-17 17:41:16 +11:00
|
|
|
public EngineTest() {
|
|
|
|
|
base("Geary.EngineTest");
|
2018-06-17 17:56:06 +10:00
|
|
|
add_test("add_account", add_account);
|
|
|
|
|
add_test("remove_account", remove_account);
|
|
|
|
|
add_test("re_add_account", re_add_account);
|
2017-02-17 17:41:16 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~EngineTest() {
|
|
|
|
|
// Need this in addition to the code in tear_down in case a
|
|
|
|
|
// test fails
|
|
|
|
|
if (this.tmp != null) {
|
|
|
|
|
try {
|
|
|
|
|
@delete(this.tmp);
|
|
|
|
|
} catch (Error err) {
|
|
|
|
|
print("\nError removing tmp files: %s\n", err.message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-24 15:50:13 +10:00
|
|
|
public override void set_up() throws GLib.Error {
|
2017-02-17 17:41:16 +11:00
|
|
|
// XXX this whole thing stinks. We need to be able to test the
|
|
|
|
|
// engine without creating all of these dirs.
|
|
|
|
|
|
2018-05-24 15:50:13 +10:00
|
|
|
this.tmp = GLib.File.new_for_path(
|
|
|
|
|
GLib.DirUtils.make_tmp("geary-engine-test-XXXXXX")
|
|
|
|
|
);
|
2017-02-17 17:41:16 +11:00
|
|
|
|
2018-05-24 15:50:13 +10:00
|
|
|
this.res = this.tmp.get_child("res");
|
|
|
|
|
this.res.make_directory();
|
2017-02-17 17:41:16 +11:00
|
|
|
|
2019-11-19 00:49:15 +11:00
|
|
|
this.engine = new Engine(res);
|
2018-12-08 13:53:37 +11:00
|
|
|
|
|
|
|
|
this.account = new AccountInformation(
|
|
|
|
|
"test",
|
|
|
|
|
ServiceProvider.OTHER,
|
2020-08-10 16:13:57 +10:00
|
|
|
new Mock.CredentialsMediator(),
|
2018-12-08 13:53:37 +11:00
|
|
|
new RFC822.MailboxAddress(null, "test1@example.com")
|
|
|
|
|
);
|
2019-11-14 14:44:30 +11:00
|
|
|
this.account.set_account_directories(this.tmp, this.tmp);
|
2017-02-17 17:41:16 +11:00
|
|
|
}
|
|
|
|
|
|
2020-05-09 16:04:22 +10:00
|
|
|
public override void tear_down() throws GLib.Error {
|
2018-12-08 13:53:37 +11:00
|
|
|
this.account = null;
|
2020-05-09 16:04:22 +10:00
|
|
|
this.res.delete();
|
|
|
|
|
this.tmp.delete();
|
|
|
|
|
this.tmp = null;
|
2019-02-27 19:18:31 +01:00
|
|
|
}
|
2017-02-17 17:41:16 +11:00
|
|
|
|
2018-06-17 17:56:06 +10:00
|
|
|
public void add_account() throws GLib.Error {
|
2019-11-14 14:44:30 +11:00
|
|
|
assert_false(this.engine.has_account(this.account));
|
2018-06-17 17:56:06 +10:00
|
|
|
|
2018-12-08 13:53:37 +11:00
|
|
|
this.engine.add_account(this.account);
|
2019-11-14 14:44:30 +11:00
|
|
|
assert_true(this.engine.has_account(this.account), "Account not added");
|
2018-06-17 17:56:06 +10:00
|
|
|
|
|
|
|
|
try {
|
2018-12-08 13:53:37 +11:00
|
|
|
this.engine.add_account(this.account);
|
2018-06-17 17:56:06 +10:00
|
|
|
assert_not_reached();
|
|
|
|
|
} catch (GLib.Error err) {
|
|
|
|
|
// expected
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void remove_account() throws GLib.Error {
|
2018-12-08 13:53:37 +11:00
|
|
|
this.engine.add_account(this.account);
|
2019-11-14 14:44:30 +11:00
|
|
|
assert_true(this.engine.has_account(this.account));
|
2018-06-17 17:56:06 +10:00
|
|
|
|
2018-12-08 13:53:37 +11:00
|
|
|
this.engine.remove_account(this.account);
|
2019-11-14 14:44:30 +11:00
|
|
|
assert_false(this.engine.has_account(this.account), "Account not removed");
|
2018-06-17 17:56:06 +10:00
|
|
|
|
2019-11-14 14:44:30 +11:00
|
|
|
try {
|
|
|
|
|
this.engine.remove_account(this.account);
|
|
|
|
|
assert_not_reached();
|
|
|
|
|
} catch (GLib.Error err) {
|
|
|
|
|
// expected
|
|
|
|
|
}
|
2018-06-17 17:56:06 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void re_add_account() throws GLib.Error {
|
2019-11-14 14:44:30 +11:00
|
|
|
assert_false(this.engine.has_account(this.account));
|
2018-06-17 17:56:06 +10:00
|
|
|
|
2018-12-08 13:53:37 +11:00
|
|
|
this.engine.add_account(this.account);
|
|
|
|
|
this.engine.remove_account(this.account);
|
|
|
|
|
this.engine.add_account(this.account);
|
2018-06-17 17:56:06 +10:00
|
|
|
|
2019-11-14 14:44:30 +11:00
|
|
|
assert_true(this.engine.has_account(this.account));
|
2018-06-17 17:56:06 +10:00
|
|
|
}
|
|
|
|
|
|
2018-07-23 13:28:58 +10:00
|
|
|
private void delete(File parent) throws Error {
|
2017-02-17 17:41:16 +11:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|