[geary: 22/23] Fix conversation-related test warnings and occasionally failing test.



commit f0651803bbd41435fdf9fef7563aedf4485d38a3
Author: Michael James Gratton <mike vee net>
Date:   Thu Feb 8 18:25:32 2018 +1100

    Fix conversation-related test warnings and occasionally failing test.
    
    * test/engine/api/geary-email-properties-test.vala: Add new mock
      EmailProperties object.
    
    * test/engine/app/app-conversation-test.vala (ConversationTest): Set
      email sent and received dates to suppress warnings adding them to
      Conversation instances.
    
    * test/engine/app/app-conversation-set-test.vala (ConversationSetTest):
      Set email sent and received dates to suppress warnings adding them to
      Conversation instances, handle both casees when merging two
      conversations, that the first was merged to the second and vice versa.

 test/CMakeLists.txt                              |    1 +
 test/engine/api/geary-email-properties-test.vala |   21 ++++++++++
 test/engine/app/app-conversation-set-test.vala   |   45 +++++++++++++++++----
 test/engine/app/app-conversation-test.vala       |   41 ++++++++++++++-----
 test/meson.build                                 |    1 +
 5 files changed, 89 insertions(+), 20 deletions(-)
---
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 6f9ab8c..16efeb0 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -10,6 +10,7 @@ set(TEST_ENGINE_SRC
   engine/api/geary-attachment-test.vala
   engine/api/geary-engine-test.vala
   engine/api/geary-email-identifier-test.vala
+  engine/api/geary-email-properties-test.vala
   engine/api/geary-folder-test.vala
   engine/api/geary-folder-path-test.vala
   engine/app/app-conversation-test.vala
diff --git a/test/engine/api/geary-email-properties-test.vala 
b/test/engine/api/geary-email-properties-test.vala
new file mode 100644
index 0000000..5f2d5a6
--- /dev/null
+++ b/test/engine/api/geary-email-properties-test.vala
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+public class Geary.MockEmailProperties : EmailProperties {
+
+
+    public MockEmailProperties(GLib.DateTime received) {
+        base(received, 0);
+    }
+
+    public override string to_string() {
+        return "MockEmailProperties: %s/%lli".printf(
+            this.date_received.to_string(), this.total_bytes
+        );
+    }
+
+}
diff --git a/test/engine/app/app-conversation-set-test.vala b/test/engine/app/app-conversation-set-test.vala
index a2dc8c9..00849af 100644
--- a/test/engine/app/app-conversation-set-test.vala
+++ b/test/engine/app/app-conversation-set-test.vala
@@ -37,8 +37,8 @@ class Geary.App.ConversationSetTest : Gee.TestCase {
     }
 
     public void add_all_basic() {
-        Email e1 = new Email(new MockEmailIdentifer(1));
-        Email e2 = new Email(new MockEmailIdentifer(2));
+        Email e1 = setup_email(1);
+        Email e2 = setup_email(2);
 
         Gee.LinkedList<Email> emails = new Gee.LinkedList<Email>();
         emails.add(e1);
@@ -252,6 +252,13 @@ class Geary.App.ConversationSetTest : Gee.TestCase {
         assert(this.test.size == 2);
         assert(this.test.get_email_count() == 2);
 
+        Conversation? c1 = this.test.get_by_email_identifier(e1.id);
+        Conversation? c3 = this.test.get_by_email_identifier(e3.id);
+
+        assert(c1 != null);
+        assert(c3 != null);
+        assert(c1 != c3);
+
         Gee.LinkedList<Email> emails = new Gee.LinkedList<Email>();
         emails.add(e2);
 
@@ -270,18 +277,35 @@ class Geary.App.ConversationSetTest : Gee.TestCase {
         assert(this.test.size == 1);
         assert(this.test.get_email_count() == 3);
 
-        Conversation convo = this.test.get_by_email_identifier(e1.id);
-        assert(convo.get_email_by_id(e1.id) == e1);
-        assert(convo.get_email_by_id(e2.id) == e2);
-        assert(convo.get_email_by_id(e3.id) == e3);
+        Conversation? c2 = this.test.get_by_email_identifier(e2.id);
+        assert(c2 != null);
+        assert(c2.get_email_by_id(e1.id) == e1);
+        assert(c2.get_email_by_id(e2.id) == e2);
+        assert(c2.get_email_by_id(e3.id) == e3);
+
+        // e2 might have been appended to e1's convo with e3, or vice
+        // versa, depending on the gods of entropy.
+        assert(c1 == c2 || c3 == c2);
+        bool e1_won = (c1 == c2);
 
         assert(appended.size == 2);
-        assert(appended.get(convo) != null);
-        assert(appended.get(convo).contains(e2) == true);
-        assert(appended.get(convo).contains(e3) == true);
+        assert(appended.get(c2) != null);
+        assert(appended.get(c2).size == 2);
+        assert(appended.get(c2).contains(e2) == true);
+        if (e1_won) {
+            assert(appended.get(c2).contains(e3) == true);
+        } else {
+            assert(appended.get(c2).contains(e1) == true);
+        }
 
         assert(added.is_empty);
         assert(removed.size == 1);
+        if (e1_won) {
+            assert(removed.contains(c3) == true);
+        } else {
+            assert(removed.contains(c1) == true);
+        }
+
     }
 
     public void add_all_multi_path() {
@@ -434,6 +458,7 @@ class Geary.App.ConversationSetTest : Gee.TestCase {
 
     private Email setup_email(int id, Email? references = null) {
         Email email = new Email(new MockEmailIdentifer(id));
+        DateTime now = new DateTime.now_local();
         Geary.RFC822.MessageID mid = new Geary.RFC822.MessageID(
             "test%d@localhost".printf(id)
         );
@@ -444,6 +469,8 @@ class Geary.App.ConversationSetTest : Gee.TestCase {
                 references.message_id
             );
         }
+        email.set_send_date(new Geary.RFC822.Date.from_date_time(now));
+        email.set_email_properties(new MockEmailProperties(now));
         email.set_full_references(mid, null, refs_list);
         return email;
     }
diff --git a/test/engine/app/app-conversation-test.vala b/test/engine/app/app-conversation-test.vala
index 453ebeb..990408d 100644
--- a/test/engine/app/app-conversation-test.vala
+++ b/test/engine/app/app-conversation-test.vala
@@ -32,8 +32,8 @@ class Geary.App.ConversationTest : Gee.TestCase {
     }
 
     public void add_basic() {
-        Geary.Email e1 = new Email(new MockEmailIdentifer(1));
-        Geary.Email e2 = new Email(new MockEmailIdentifer(2));
+        Geary.Email e1 = setup_email(1);
+        Geary.Email e2 = setup_email(2);
         uint appended = 0;
         this.test.appended.connect(() => {
                 appended++;
@@ -53,7 +53,7 @@ class Geary.App.ConversationTest : Gee.TestCase {
     }
 
     public void add_duplicate() {
-        Geary.Email e1 = new Email(new MockEmailIdentifer(1));
+        Geary.Email e1 = setup_email(1);
         uint appended = 0;
         this.test.appended.connect(() => {
                 appended++;
@@ -69,10 +69,10 @@ class Geary.App.ConversationTest : Gee.TestCase {
     }
 
     public void add_multipath() {
-        Geary.Email e1 = new Email(new MockEmailIdentifer(1));
+        Geary.Email e1 = setup_email(1);
         this.test.add(e1, singleton(this.base_folder.path));
 
-        Geary.Email e2 = new Email(new MockEmailIdentifer(2));
+        Geary.Email e2 = setup_email(2);
         this.test.add(e2, singleton(this.base_folder.path));
 
         FolderRoot other_path = new MockFolderRoot("other");
@@ -92,10 +92,10 @@ class Geary.App.ConversationTest : Gee.TestCase {
     }
 
     public void remove_basic() {
-        Geary.Email e1 = new Email(new MockEmailIdentifer(1));
+        Geary.Email e1 = setup_email(1);
         this.test.add(e1, singleton(this.base_folder.path));
 
-        Geary.Email e2 = new Email(new MockEmailIdentifer(2));
+        Geary.Email e2 = setup_email(2);
         this.test.add(e2, singleton(this.base_folder.path));
 
         uint trimmed = 0;
@@ -103,18 +103,24 @@ class Geary.App.ConversationTest : Gee.TestCase {
                 trimmed++;
             });
 
-        assert(this.test.remove(e1) == null);
+        Gee.Set<RFC822.MessageID>? removed = this.test.remove(e1);
+        assert(removed != null);
+        assert(removed.size == 1);
+        assert(removed.contains(e1.message_id));
         assert(trimmed == 1);
         assert(this.test.get_count() == 1);
 
-        assert(this.test.remove(e2) == null);
+        removed = this.test.remove(e2);
+        assert(removed != null);
+        assert(removed.size == 1);
+        assert(removed.contains(e2.message_id));
         assert(trimmed == 2);
         assert(this.test.get_count() == 0);
     }
 
     public void remove_nonexistent() {
-        Geary.Email e1 = new Email(new MockEmailIdentifer(1));
-        Geary.Email e2 = new Email(new MockEmailIdentifer(2));
+        Geary.Email e1 = setup_email(1);
+        Geary.Email e2 = setup_email(2);
 
         uint trimmed = 0;
         this.test.trimmed.connect(() => {
@@ -138,4 +144,17 @@ class Geary.App.ConversationTest : Gee.TestCase {
         return collection;
     }
 
+
+    private Email setup_email(int id) {
+        Email email = new Email(new MockEmailIdentifer(id));
+        DateTime now = new DateTime.now_local();
+        Geary.RFC822.MessageID mid = new Geary.RFC822.MessageID(
+            "test%d@localhost".printf(id)
+        );
+        email.set_full_references(mid, null, null);
+        email.set_email_properties(new MockEmailProperties(now));
+        email.set_send_date(new Geary.RFC822.Date.from_date_time(now));
+        return email;
+    }
+
 }
diff --git a/test/meson.build b/test/meson.build
index 4afad25..964fc54 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -6,6 +6,7 @@ geary_test_engine_sources = [
   'engine/api/geary-attachment-test.vala',
   'engine/api/geary-engine-test.vala',
   'engine/api/geary-email-identifier-test.vala',
+  'engine/api/geary-email-properties-test.vala',
   'engine/api/geary-folder-test.vala',
   'engine/api/geary-folder-path-test.vala',
   'engine/app/app-conversation-test.vala',


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