[geary] Fix AccountInformation.has_email_address, add tests.



commit 0e6d499808fe3a0968bfc9ac693d65a889df1d04
Author: Michael James Gratton <mike vee net>
Date:   Mon Jul 2 19:03:42 2018 +1000

    Fix AccountInformation.has_email_address, add tests.

 src/engine/api/geary-account-information.vala      |  4 +-
 src/engine/rfc822/rfc822-mailbox-address.vala      |  2 +-
 .../engine/api/geary-account-information-test.vala | 43 ++++++++++++++++++++++
 test/engine/rfc822-mailbox-address-test.vala       | 21 +++++++++++
 test/meson.build                                   |  1 +
 test/test-engine.vala                              |  1 +
 6 files changed, 69 insertions(+), 3 deletions(-)
---
diff --git a/src/engine/api/geary-account-information.vala b/src/engine/api/geary-account-information.vala
index 6629771b..ce0d3140 100644
--- a/src/engine/api/geary-account-information.vala
+++ b/src/engine/api/geary-account-information.vala
@@ -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))
+                 }))
         );
     }
 
diff --git a/src/engine/rfc822/rfc822-mailbox-address.vala b/src/engine/rfc822/rfc822-mailbox-address.vala
index ff5174a5..51f38aca 100644
--- a/src/engine/rfc822/rfc822-mailbox-address.vala
+++ b/src/engine/rfc822/rfc822-mailbox-address.vala
@@ -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) {
diff --git a/test/engine/api/geary-account-information-test.vala 
b/test/engine/api/geary-account-information-test.vala
new file mode 100644
index 00000000..7cab7bd4
--- /dev/null
+++ b/test/engine/api/geary-account-information-test.vala
@@ -0,0 +1,43 @@
+/*
+ * 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"
+        );
+    }
+
+}
diff --git a/test/engine/rfc822-mailbox-address-test.vala b/test/engine/rfc822-mailbox-address-test.vala
index 2502cde2..293edcda 100644
--- a/test/engine/rfc822-mailbox-address-test.vala
+++ b/test/engine/rfc822-mailbox-address-test.vala
@@ -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"
+        );
+    }
 }
diff --git a/test/meson.build b/test/meson.build
index 60337cf9..4eb874a0 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -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',
diff --git a/test/test-engine.vala b/test/test-engine.vala
index e5887fa9..c9839138 100644
--- a/test/test-engine.vala
+++ b/test/test-engine.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());


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]