Commit 7313ef0f authored by Jeremy Whiting's avatar Jeremy Whiting

eds: Add test for disabling and enabling persona stores.

parent 1ec09812
......@@ -341,9 +341,10 @@ public class Folks.Backends.Eds.Backend : Folks.Backend
{
debug ("Removing address book '%s'.", store.id);
this._persona_stores.unset (store.id);
this.persona_store_removed (store);
this._persona_stores.unset (store.id);
if (notify)
{
this.notify_property ("persona-stores");
......
......@@ -76,6 +76,7 @@ noinst_PROGRAMS = \
set-birthday \
set-roles \
link-personas-diff-stores \
enable-disable-stores \
set-is-favourite \
$(NULL)
......@@ -216,6 +217,10 @@ link_personas_diff_stores_SOURCES = \
link-personas-diff-stores.vala \
$(NULL)
enable_disable_stores_SOURCES = \
enable-disable-stores.vala \
$(NULL)
set_is_favourite_SOURCES = \
set-is-favourite.vala \
$(NULL)
......
/*
* Copyright (C) 2012 Collabora Ltd.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Jeremy Whiting <jeremy.whiting@collabora.com>
*
*/
using Folks;
using Gee;
public class EnableDisableStoresTests : Folks.TestCase
{
private GLib.MainLoop _main_loop;
private EdsTest.Backend? _eds_backend;
private EdsTest.Backend? _eds_backend_other;
private IndividualAggregator _aggregator;
private HashMap<PersonaStore, bool> _store_removed;
private HashMap<PersonaStore, bool> _store_added;
private BackendStore? _backend_store;
public EnableDisableStoresTests ()
{
base ("EnableDisableStoresTests");
this.add_test ("test enabling and disabling of PersonaStores",
this.test_disabling_stores);
}
public override void set_up ()
{
this._eds_backend = new EdsTest.Backend ();
this._eds_backend_other = new EdsTest.Backend ();
this._store_removed = new HashMap<PersonaStore, bool> ();
this._store_added = new HashMap<PersonaStore, bool> ();
this._backend_store = BackendStore.dup();
this._eds_backend.set_up ();
this._eds_backend_other.set_up (false, "other");
/* We configure eds as the primary store */
var config_val = "eds:%s".printf (this._eds_backend.address_book_uid);
Environment.set_variable ("FOLKS_PRIMARY_STORE", config_val, true);
Environment.set_variable ("FOLKS_BACKEND_EDS_USE_ADDRESS_BOOKS",
"test:other", true);
}
public override void tear_down ()
{
this._eds_backend.tear_down ();
this._eds_backend_other.tear_down ();
Environment.unset_variable ("FOLKS_PRIMARY_STORE");
this._eds_backend = null;
this._eds_backend_other = null;
}
public void test_disabling_stores ()
{
this._main_loop = new GLib.MainLoop (null, false);
this._test_disabling_stores_async.begin ();
var timer_id = Timeout.add_seconds (8, () =>
{
this._main_loop.quit ();
assert_not_reached ();
});
this._main_loop.run ();
assert (this._store_removed.size > 0);
foreach (bool removed in this._store_removed.values)
{
assert (removed == true);
}
GLib.Source.remove (timer_id);
this._aggregator = null;
this._main_loop = null;
}
private async void _test_disabling_stores_async ()
{
yield this._backend_store.prepare ();
this._aggregator = new IndividualAggregator ();
try
{
yield this._backend_store.load_backends ();
var backend = this._backend_store.enabled_backends.get ("eds");
assert (backend != null);
yield this._aggregator.prepare ();
assert (this._aggregator.is_prepared);
backend.persona_store_removed.connect (this._store_removed_cb);
backend.persona_store_added.connect (this._store_added_cb);
var pstore = this._get_store (this._backend_store,
this._eds_backend.address_book_uid);
assert (pstore != null);
this._store_removed[pstore] = false;
this._store_added[pstore] = false;
var pstore2 = this._get_store (this._backend_store,
this._eds_backend_other.address_book_uid);
assert (pstore2 != null);
this._store_removed[pstore2] = false;
this._store_added[pstore2] = false;
backend.disable_persona_store (pstore);
backend.disable_persona_store (pstore2);
}
catch (GLib.Error e)
{
GLib.warning ("Error when calling prepare: %s\n", e.message);
}
}
private PersonaStore? _get_store (BackendStore store, string store_id)
{
PersonaStore? pstore = null;
foreach (var backend in store.enabled_backends.values)
{
pstore = backend.persona_stores.get (store_id);
if (pstore != null)
break;
}
return pstore;
}
private void _store_removed_cb (
PersonaStore store)
{
assert (store != null);
debug ("store removed %s", store.id);
this._store_removed[store] = true;
var backend = this._backend_store.enabled_backends.get ("eds");
assert (backend != null);
debug ("enabling store %s", store.id);
backend.enable_persona_store (store);
}
private void _store_added_cb (PersonaStore store)
{
debug ("store added %s", store.id);
this._store_added[store] = true;
int added_count = 0;
foreach (bool added in this._store_added.values)
{
if (added)
{
++added_count;
}
}
if (added_count == this._store_added.size)
{
this._main_loop.quit ();
}
}
}
public int main (string[] args)
{
Test.init (ref args);
TestSuite root = TestSuite.get_root ();
root.add_suite (new EnableDisableStoresTests ().get_suite ());
Test.run ();
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment