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.
This commit is contained in:
parent
64b3eee6b4
commit
f0651803bb
5 changed files with 89 additions and 20 deletions
|
|
@ -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
|
||||
|
|
|
|||
21
test/engine/api/geary-email-properties-test.vala
Normal file
21
test/engine/api/geary-email-properties-test.vala
Normal file
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue