Commit 5ab0462e authored by Michael Gratton's avatar Michael Gratton 🤞

Fix AccountInformation.has_email_address, add tests.

parent 5be8e3e5
......@@ -389,9 +389,9 @@ public class Geary.AccountInformation : BaseObject {
return (
this.primary_mailbox.equal_to(email) ||
(this.alternate_mailboxes != null &&
this.alternate_mailboxes.fold<bool>((alt) => {
this.alternate_mailboxes.any_match((alt) => {
return alt.equal_to(email);
}, false))
}))
);
}
......
......@@ -398,7 +398,7 @@ public class Geary.RFC822.MailboxAddress :
* Equality is defined as a case-insensitive comparison of the {@link address}.
*/
public bool equal_to(MailboxAddress other) {
return this != other ? String.stri_equal(address, other.address) : true;
return this == other || String.stri_equal(address, other.address);
}
public bool equal_normalized(string address) {
......
/*
* 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");
add_test("has_email_address", has_email_address);
}
public void has_email_address() throws GLib.Error {
AccountInformation test = new AccountInformation(
"test", new MockServiceInformation(), new MockServiceInformation()
);
test.primary_mailbox = (new RFC822.MailboxAddress(null, "test1@example.com"));
test.add_alternate_mailbox(new RFC822.MailboxAddress(null, "test2@example.com"));
test.add_alternate_mailbox(new RFC822.MailboxAddress(null, "test3@example.com"));
assert_true(
test.has_email_address(new RFC822.MailboxAddress(null, "test1@example.com")),
"Primary address not found"
);
assert_true(
test.has_email_address(new RFC822.MailboxAddress(null, "test2@example.com")),
"First alt address not found"
);
assert_true(
test.has_email_address(new RFC822.MailboxAddress(null, "test3@example.com")),
"Second alt address not found"
);
assert_false(
test.has_email_address(new RFC822.MailboxAddress(null, "unknowne@example.com")),
"Unknown address found"
);
}
}
......@@ -19,6 +19,7 @@ class Geary.RFC822.MailboxAddressTest : TestCase {
// latter depends on the former, so test that first
add_test("to_rfc822_address", to_rfc822_address);
add_test("to_rfc822_string", to_rfc822_string);
add_test("equal_to", equal_to);
}
public void is_valid_address() throws Error {
......@@ -245,4 +246,24 @@ class Geary.RFC822.MailboxAddressTest : TestCase {
"=?UTF-8?b?8J+YuA==?= <example@example.com>");
}
public void equal_to() throws GLib.Error {
MailboxAddress test = new MailboxAddress("test", "example@example.com");
assert_true(
test.equal_to(test),
"Object identity equality"
);
assert_true(
test.equal_to(new MailboxAddress("test", "example@example.com")),
"Mailbox identity equality"
);
assert_true(
test.equal_to(new MailboxAddress(null, "example@example.com")),
"Address equality"
);
assert_false(
test.equal_to(new MailboxAddress(null, "blarg@example.com")),
"Address inequality"
);
}
}
......@@ -21,6 +21,7 @@ geary_test_engine_sources = [
'engine/api/geary-folder-path-mock.vala',
'engine/api/geary-service-information-mock.vala',
'engine/api/geary-account-information-test.vala',
'engine/api/geary-attachment-test.vala',
'engine/api/geary-engine-test.vala',
'engine/app/app-conversation-test.vala',
......
......@@ -22,6 +22,7 @@ int main(string[] args) {
TestSuite engine = new TestSuite("engine");
engine.add_suite(new Geary.AccountInformationTest().get_suite());
engine.add_suite(new Geary.AttachmentTest().get_suite());
engine.add_suite(new Geary.EngineTest().get_suite());
engine.add_suite(new Geary.IdleManagerTest().get_suite());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment