[geary: 42/66] Test case for detach_emails_before_timestamp
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary: 42/66] Test case for detach_emails_before_timestamp
- Date: Tue, 30 Jun 2020 07:11:10 +0000 (UTC)
commit 150417727e6abf77c94fda20e00c6bdf099fc3f9
Author: Chris Heywood <15127-creywood users noreply gitlab gnome org>
Date: Wed Jan 22 10:23:13 2020 +0100
Test case for detach_emails_before_timestamp
ie. ImapDB.Folder::detach_emails_before_timestamp.
test/engine/imap-db/imap-db-folder-test.vala | 65 ++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
---
diff --git a/test/engine/imap-db/imap-db-folder-test.vala b/test/engine/imap-db/imap-db-folder-test.vala
index 496afd104..11035cb81 100644
--- a/test/engine/imap-db/imap-db-folder-test.vala
+++ b/test/engine/imap-db/imap-db-folder-test.vala
@@ -26,6 +26,7 @@ class Geary.ImapDB.FolderTest : TestCase {
//add_test("merge_existing_preview", merge_existing_preview);
add_test("set_flags", set_flags);
add_test("set_flags_on_deleted", set_flags_on_deleted);
+ add_test("detach_emails_before_timestamp", detach_emails_before_timestamp);
}
public override void set_up() throws GLib.Error {
@@ -323,6 +324,70 @@ class Geary.ImapDB.FolderTest : TestCase {
assert_flags(test, test_flags);
}
+ public void detach_emails_before_timestamp() throws GLib.Error {
+ // Ensures that messages outside the folder and within the epoch aren't
+ // removed, and that messages meeting the criteria are removed.
+
+ this.account.db.exec(
+ "INSERT INTO FolderTable (id, name) VALUES (2, 'other');"
+ );
+
+ GLib.DateTime threshold = new GLib.DateTime.local(2020, 1, 1, 0, 0, 0);
+ GLib.DateTime beyond_threshold = new GLib.DateTime.local(2019, 1, 1, 0, 0, 0);
+ GLib.DateTime within_threshold = new GLib.DateTime.local(2021, 1, 1, 0, 0, 0);
+
+ Email.Field fixture_fields = Email.Field.RECEIVERS;
+ string fixture_to = "test1 example com";
+ this.account.db.exec(
+ "INSERT INTO MessageTable (id, fields, to_field, internaldate_time_t) " +
+ "VALUES (1, %d, '%s', %s);".printf(fixture_fields,
+ fixture_to,
+ within_threshold.to_unix().to_string())
+ );
+ this.account.db.exec(
+ "INSERT INTO MessageTable (id, fields, to_field, internaldate_time_t) " +
+ "VALUES (2, %d, '%s', %s);".printf(fixture_fields,
+ fixture_to,
+ within_threshold.to_unix().to_string())
+ );
+ this.account.db.exec(
+ "INSERT INTO MessageTable (id, fields, to_field, internaldate_time_t) " +
+ "VALUES (3, %d, '%s', %s);".printf(fixture_fields,
+ fixture_to,
+ beyond_threshold.to_unix().to_string())
+ );
+
+ this.account.db.exec("""
+ INSERT INTO MessageLocationTable
+ (id, message_id, folder_id, ordering, remove_marker)
+ VALUES
+ (1, 1, 1, 1, 1),
+ (2, 2, 2, 1, 1),
+ (3, 3, 1, 2, 1);
+ """);
+
+ this.folder.detach_emails_before_timestamp.begin(
+ threshold,
+ null,
+ (obj, ret) => { async_complete(ret); }
+ );
+ this.folder.detach_emails_before_timestamp.end(async_result());
+
+ int64[] expected = { 2, 3 };
+ Db.Result result = this.account.db.query(
+ "SELECT id FROM MessageLocationTable"
+ );
+
+ int i = 0;
+ while (!result.finished) {
+ assert_true(i < expected.length, "Too many rows");
+ assert_int64(expected[i], result.int64_at(0));
+ i++;
+ result.next();
+ }
+ assert_true(i == expected.length, "Not enough rows");
+ }
+
private Email new_mock_remote_email(int64 uid,
string? subject = null,
Geary.EmailFlags? flags = null) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]