[geary/mjog/955-special-use-unavailable-at-startup] Geary.Account.Information: Fix special use folder not correctly stored




commit 39f687fcd35ffdb3aad316716a59219439d5481b
Author: Michael Gratton <mike vee net>
Date:   Sun Aug 30 18:26:26 2020 +1000

    Geary.Account.Information: Fix special use folder not correctly stored
    
    The special use map needs custom hash and equality functions to
    work correctly. Add these and some unit tests.
    
    See #995

 src/engine/api/geary-account-information.vala      |  5 ++++-
 .../engine/api/geary-account-information-test.vala | 24 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)
---
diff --git a/src/engine/api/geary-account-information.vala b/src/engine/api/geary-account-information.vala
index c72bed683..242a3561a 100644
--- a/src/engine/api/geary-account-information.vala
+++ b/src/engine/api/geary-account-information.vala
@@ -182,7 +182,10 @@ public class Geary.AccountInformation : BaseObject {
     public File? data_dir { get; private set; default = null; }
 
     private Gee.Map<Folder.SpecialUse?,Gee.List<string>> special_use_paths =
-        new Gee.HashMap<Folder.SpecialUse?,Gee.List<string>>();
+        new Gee.HashMap<Folder.SpecialUse?,Gee.List<string>>(
+            (k) => GLib.int_hash(k),
+            (k1, k2) => (Folder.SpecialUse) k1 == (Folder.SpecialUse) k2
+        );
 
     private Gee.List<Geary.RFC822.MailboxAddress> mailboxes {
         get; private set;
diff --git a/test/engine/api/geary-account-information-test.vala 
b/test/engine/api/geary-account-information-test.vala
index 365ba92dc..447902738 100644
--- a/test/engine/api/geary-account-information-test.vala
+++ b/test/engine/api/geary-account-information-test.vala
@@ -13,6 +13,7 @@ class Geary.AccountInformationTest : TestCase {
         add_test("test_save_sent_defaults", test_save_sent_defaults);
         add_test("test_sender_mailboxes", test_sender_mailboxes);
         add_test("test_service_label", test_service_label);
+        add_test("folder_steps_accessors", folder_steps_accessors);
     }
 
     public void test_save_sent_defaults() throws GLib.Error {
@@ -119,6 +120,29 @@ class Geary.AccountInformationTest : TestCase {
         assert_equal(test.service_label, "other.com");
     }
 
+    public void folder_steps_accessors() throws GLib.Error {
+        AccountInformation test = new_information();
+
+        assert_collection(test.get_folder_steps_for_use(NONE)).is_empty();
+        assert_collection(test.get_folder_steps_for_use(ARCHIVE)).is_empty();
+        assert_collection(test.get_folder_steps_for_use(JUNK)).is_empty();
+
+        var archive = new Gee.ArrayList<string>.wrap({"Archive"});
+        test.set_folder_steps_for_use(ARCHIVE, archive);
+        assert_collection(test.get_folder_steps_for_use(ARCHIVE))
+        .is_non_empty()
+        .contains("Archive");
+
+        var junk = new Gee.ArrayList<string>.wrap({"Junk"});
+        test.set_folder_steps_for_use(JUNK, junk);
+        assert_collection(test.get_folder_steps_for_use(ARCHIVE))
+        .is_non_empty()
+        .contains("Archive");
+        assert_collection(test.get_folder_steps_for_use(JUNK))
+        .is_non_empty()
+        .contains("Junk");
+    }
+
     private AccountInformation new_information(ServiceProvider provider =
                                                ServiceProvider.OTHER) {
         return new AccountInformation(


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