[folks] Add a test of backend disabling.



commit ba5b502380b2fec8e1c4f3989769c9db8fcf66a7
Author: Travis Reitter <travis reitter collabora co uk>
Date:   Mon Nov 1 19:08:43 2010 -0700

    Add a test of backend disabling.
    
    Helps bgo#629081.

 tests/folks/backend-loading.vala |   55 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 55 insertions(+), 0 deletions(-)
---
diff --git a/tests/folks/backend-loading.vala b/tests/folks/backend-loading.vala
index 10bed97..bcea573 100644
--- a/tests/folks/backend-loading.vala
+++ b/tests/folks/backend-loading.vala
@@ -3,6 +3,9 @@ using Folks;
 
 public class BackendLoadingTests : Folks.TestCase
 {
+  private MainLoop main_loop;
+  private static const string STORE_FILE_PATH = "folks-test-backend-store.ini";
+
   public BackendLoadingTests ()
     {
       base ("BackendLoading");
@@ -16,14 +19,24 @@ public class BackendLoadingTests : Folks.TestCase
         });
 
       this.add_test ("load and prep", this.test_load_and_prep);
+      this.add_test ("disabling", this.test_disabling);
     }
 
   public override void set_up ()
     {
+      FileUtils.remove (Path.build_filename (Environment.get_tmp_dir (),
+          this.STORE_FILE_PATH, null));
+
+      /* Use a temporary key file for the BackendStore */
+      Environment.set_variable ("FOLKS_BACKEND_STORE_KEY_FILE_PATH",
+          Path.build_filename (Environment.get_tmp_dir (),
+              this.STORE_FILE_PATH, null), true);
     }
 
   public override void tear_down ()
     {
+      FileUtils.remove (Path.build_filename (Environment.get_tmp_dir (),
+          this.STORE_FILE_PATH, null));
     }
 
   public void test_load_and_prep ()
@@ -64,6 +77,48 @@ public class BackendLoadingTests : Folks.TestCase
 
       main_loop.run ();
     }
+
+  public void test_disabling ()
+    {
+      this.main_loop = new GLib.MainLoop (null, false);
+
+      var store = BackendStore.dup ();
+      this.test_disabling_async (store, (o, r) =>
+        {
+          this.test_disabling_async.end (r);
+        });
+
+      this.main_loop.run ();
+    }
+
+  private async void test_disabling_async (BackendStore store)
+    {
+      var backends_expected = new HashSet<string> (str_hash, str_equal);
+      backends_expected.add ("key-file");
+
+      /* Disable some backends */
+      yield store.prepare ();
+      yield store.disable_backend ("telepathy");
+
+      try
+        {
+          yield store.load_backends ();
+
+          store.enabled_backends.foreach ((i) =>
+            {
+              var backend = (Backend) i;
+              assert (backends_expected.contains (backend.name));
+              backends_expected.remove (backend.name);
+            });
+
+          assert (backends_expected.size == 0);
+          this.main_loop.quit ();
+        }
+      catch (GLib.Error e)
+        {
+          GLib.error ("Failed to load backends: %s", e.message);
+        }
+    }
 }
 
 public int main (string[] args)



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