2018-07-02 19:03:42 +10:00
|
|
|
/*
|
|
|
|
|
* 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 Geary.AccountInformationTest : TestCase {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public AccountInformationTest() {
|
|
|
|
|
base("Geary.AccountInformationTest");
|
2019-02-20 13:51:26 +11:00
|
|
|
add_test("test_save_sent_defaults", test_save_sent_defaults);
|
2018-12-02 12:43:38 +11:00
|
|
|
add_test("test_sender_mailboxes", test_sender_mailboxes);
|
2019-02-22 16:56:32 +11:00
|
|
|
add_test("test_service_label", test_service_label);
|
2018-07-02 19:03:42 +10:00
|
|
|
}
|
|
|
|
|
|
2019-02-20 13:51:26 +11:00
|
|
|
public void test_save_sent_defaults() throws GLib.Error {
|
|
|
|
|
assert_true(
|
|
|
|
|
new AccountInformation(
|
|
|
|
|
"test",
|
|
|
|
|
ServiceProvider.OTHER,
|
|
|
|
|
new MockCredentialsMediator(),
|
|
|
|
|
new RFC822.MailboxAddress(null, "test1@example.com")
|
|
|
|
|
).save_sent
|
|
|
|
|
);
|
|
|
|
|
assert_false(
|
|
|
|
|
new AccountInformation(
|
|
|
|
|
"test",
|
|
|
|
|
ServiceProvider.GMAIL,
|
|
|
|
|
new MockCredentialsMediator(),
|
|
|
|
|
new RFC822.MailboxAddress(null, "test1@example.com")
|
|
|
|
|
).save_sent
|
|
|
|
|
);
|
2019-02-20 14:06:02 +11:00
|
|
|
assert_false(
|
2019-02-20 13:51:26 +11:00
|
|
|
new AccountInformation(
|
|
|
|
|
"test",
|
|
|
|
|
ServiceProvider.OUTLOOK,
|
|
|
|
|
new MockCredentialsMediator(),
|
|
|
|
|
new RFC822.MailboxAddress(null, "test1@example.com")
|
|
|
|
|
).save_sent
|
|
|
|
|
);
|
|
|
|
|
assert_true(
|
|
|
|
|
new AccountInformation(
|
|
|
|
|
"test",
|
|
|
|
|
ServiceProvider.YAHOO,
|
|
|
|
|
new MockCredentialsMediator(),
|
|
|
|
|
new RFC822.MailboxAddress(null, "test1@example.com")
|
|
|
|
|
).save_sent
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-02 12:43:38 +11:00
|
|
|
public void test_sender_mailboxes() throws GLib.Error {
|
2018-07-02 19:03:42 +10:00
|
|
|
AccountInformation test = new AccountInformation(
|
2018-07-23 13:28:58 +10:00
|
|
|
"test",
|
|
|
|
|
ServiceProvider.OTHER,
|
2018-12-08 13:53:37 +11:00
|
|
|
new MockCredentialsMediator(),
|
2018-12-07 10:12:02 +11:00
|
|
|
new RFC822.MailboxAddress(null, "test1@example.com")
|
2018-07-02 19:03:42 +10:00
|
|
|
);
|
|
|
|
|
|
2018-12-07 10:12:02 +11:00
|
|
|
assert_true(test.primary_mailbox.equal_to(
|
|
|
|
|
new RFC822.MailboxAddress(null, "test1@example.com")));
|
2018-12-02 12:43:38 +11:00
|
|
|
assert_false(test.has_sender_aliases);
|
2018-07-02 19:03:42 +10:00
|
|
|
|
2018-12-02 12:43:38 +11:00
|
|
|
test.append_sender(new RFC822.MailboxAddress(null, "test2@example.com"));
|
2018-12-07 10:12:02 +11:00
|
|
|
assert_true(test.has_sender_aliases);
|
|
|
|
|
|
2018-12-02 12:43:38 +11:00
|
|
|
test.append_sender(new RFC822.MailboxAddress(null, "test3@example.com"));
|
|
|
|
|
assert_true(test.has_sender_aliases);
|
|
|
|
|
|
2018-07-02 19:03:42 +10:00
|
|
|
assert_true(
|
2018-12-02 12:43:38 +11:00
|
|
|
test.has_sender_mailbox(new RFC822.MailboxAddress(null, "test1@example.com")),
|
2018-07-02 19:03:42 +10:00
|
|
|
"Primary address not found"
|
|
|
|
|
);
|
|
|
|
|
assert_true(
|
2018-12-02 12:43:38 +11:00
|
|
|
test.has_sender_mailbox(new RFC822.MailboxAddress(null, "test2@example.com")),
|
2018-07-02 19:03:42 +10:00
|
|
|
"First alt address not found"
|
|
|
|
|
);
|
|
|
|
|
assert_true(
|
2018-12-02 12:43:38 +11:00
|
|
|
test.has_sender_mailbox(new RFC822.MailboxAddress(null, "test3@example.com")),
|
2018-07-02 19:03:42 +10:00
|
|
|
"Second alt address not found"
|
|
|
|
|
);
|
|
|
|
|
assert_false(
|
2018-12-02 12:43:38 +11:00
|
|
|
test.has_sender_mailbox(new RFC822.MailboxAddress(null, "unknowne@example.com")),
|
2018-07-02 19:03:42 +10:00
|
|
|
"Unknown address found"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-22 16:56:32 +11:00
|
|
|
public void test_service_label() throws GLib.Error {
|
|
|
|
|
AccountInformation test = new_information();
|
2020-05-09 16:04:22 +10:00
|
|
|
assert_equal(test.service_label, "");
|
2019-02-22 16:56:32 +11:00
|
|
|
|
|
|
|
|
test = new_information();
|
|
|
|
|
test.incoming.host = "example.com";
|
2020-05-09 16:04:22 +10:00
|
|
|
assert_equal(test.service_label, "example.com");
|
2019-02-22 16:56:32 +11:00
|
|
|
|
|
|
|
|
test = new_information();
|
|
|
|
|
test.incoming.host = "test.example.com";
|
2020-05-09 16:04:22 +10:00
|
|
|
assert_equal(test.service_label, "example.com");
|
2019-02-22 16:56:32 +11:00
|
|
|
|
|
|
|
|
test = new_information();
|
|
|
|
|
test.incoming.host = "other.com";
|
|
|
|
|
test.outgoing.host = "other.com";
|
2020-05-09 16:04:22 +10:00
|
|
|
assert_equal(test.service_label, "other.com");
|
2019-02-22 16:56:32 +11:00
|
|
|
|
|
|
|
|
test = new_information();
|
|
|
|
|
test.incoming.host = "mail.other.com";
|
|
|
|
|
test.outgoing.host = "mail.other.com";
|
2020-05-09 16:04:22 +10:00
|
|
|
assert_equal(test.service_label, "other.com");
|
2019-02-22 16:56:32 +11:00
|
|
|
|
|
|
|
|
test = new_information();
|
|
|
|
|
test.incoming.host = "imap.other.com";
|
|
|
|
|
test.outgoing.host = "smtp.other.com";
|
2020-05-09 16:04:22 +10:00
|
|
|
assert_equal(test.service_label, "other.com");
|
2019-02-22 16:56:32 +11:00
|
|
|
|
|
|
|
|
test = new_information();
|
|
|
|
|
test.incoming.host = "not-mail.other.com";
|
|
|
|
|
test.outgoing.host = "not-mail.other.com";
|
2020-05-09 16:04:22 +10:00
|
|
|
assert_equal(test.service_label, "other.com");
|
2019-02-22 16:56:32 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AccountInformation new_information(ServiceProvider provider =
|
|
|
|
|
ServiceProvider.OTHER) {
|
|
|
|
|
return new AccountInformation(
|
|
|
|
|
"test",
|
|
|
|
|
provider,
|
|
|
|
|
new MockCredentialsMediator(),
|
|
|
|
|
new RFC822.MailboxAddress(null, "test1@example.com")
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-02 19:03:42 +10:00
|
|
|
}
|