[folks/edsunittests: 2/2] Port test eds backend to eds api changes. Add test.source keyfile for unit tests.



commit 8636e7f3af47ee5155e44a14741e161e67dcf6bb
Author: Jeremy Whiting <jpwhiting kde org>
Date:   Tue Jun 19 11:54:05 2012 -0600

    Port test eds backend to eds api changes.
    Add test.source keyfile for unit tests.

 tests/lib/eds/backend.vala |   41 ++++++++++++-----------------------------
 tests/tools/eds.sh         |    5 +++++
 tests/tools/test.source    |    6 ++++++
 3 files changed, 23 insertions(+), 29 deletions(-)
---
diff --git a/tests/lib/eds/backend.vala b/tests/lib/eds/backend.vala
index b004973..0ddee4e 100644
--- a/tests/lib/eds/backend.vala
+++ b/tests/lib/eds/backend.vala
@@ -36,7 +36,7 @@ public class EdsTest.Backend
   private E.BookClient _addressbook;
   private GLib.List<string> _e_contacts;
   private GLib.List<Gee.HashMap<string, Value?>> _contacts;
-  E.SourceGroup _source_group;
+  E.SourceRegistry _source_registry;
   E.Source _source;
 
   public string address_book_uri
@@ -46,7 +46,7 @@ public class EdsTest.Backend
 
   public string address_book_uid
     {
-      get { return this._addressbook.get_source ().peek_uid (); }
+      get { return this._addressbook.get_source ().get_uid (); }
     }
 
   public Backend ()
@@ -107,7 +107,7 @@ public class EdsTest.Backend
           this._addressbook = new BookClient (this._source);
           this._addressbook.open_sync (false, null);
           this._addressbook_name =
-            this._addressbook.get_source ().peek_name ();
+            this._source.get_display_name ();
           Environment.set_variable ("FOLKS_BACKEND_EDS_USE_ADDRESS_BOOKS",
                                     this._addressbook_name, true);
         }
@@ -119,41 +119,24 @@ public class EdsTest.Backend
 
   public void set_as_default ()
     {
+      this._source_registry.set_default_address_book(this._source);
+    }
+
+  private void _prepare_source (bool is_default)
+    {
       try
         {
-          this._addressbook.set_default ();
+          this._source_registry = new SourceRegistry.sync (null);
         }
       catch (GLib.Error e)
         {
-          GLib.warning ("Unable to set address book as default: %s",
-              e.message);
+          GLib.critical (e.message);
         }
-    }
 
-  private void _prepare_source (bool is_default)
-    {
-      var base_uri = "local:";
-      this._source_group = new E.SourceGroup ("Test", base_uri);
-
-      this._source = new E.Source ("Test", this.address_book_uri);
+      this._source = this._source_registry.ref_source("test");
 
       if (is_default)
-        this._source.set_property ("default", "true");
-
-      if (this._source_group.add_source (this._source, -1))
-        {
-          try
-            {
-              SourceList sl;
-              BookClient.get_sources (out sl);
-              sl.add_group (this._source_group, 0);
-              sl.sync ();
-            }
-          catch (GLib.Error e)
-            {
-              // XXX
-            }
-        }
+        set_as_default();
     }
 
   public async void commit_contacts_to_addressbook ()
diff --git a/tests/tools/eds.sh b/tests/tools/eds.sh
index 852ba2b..f0ab63f 100644
--- a/tests/tools/eds.sh
+++ b/tests/tools/eds.sh
@@ -11,10 +11,15 @@
 
 eds_tmpdir=$(mktemp -d)
 
+cur_dir=`dirname $0`
+
 eds_init_settings () {
     export XDG_DATA_HOME=$eds_tmpdir/.local
     export XDG_CACHE_HOME=$eds_tmpdir/.cache
     export XDG_CONFIG_HOME=$eds_tmpdir/.config
+    mkdir -p $XDG_CONFIG_HOME/evolution/sources
+    echo "copying test.source from $cur_dir to temp folder"
+    cp $cur_dir/test.source $XDG_CONFIG_HOME/evolution/sources/
 }
 
 # This should be called on INT TERM and EXIT
diff --git a/tests/tools/test.source b/tests/tools/test.source
new file mode 100644
index 0000000..2ad3dfb
--- /dev/null
+++ b/tests/tools/test.source
@@ -0,0 +1,6 @@
+[Data Source]
+DisplayName=Test Address Book
+Parent=local-stub
+
+[Address Book]
+BackendName=local



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