[folks] libsocialweb: fix: update and delete contacts
- From: Alban Crequy <albanc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] libsocialweb: fix: update and delete contacts
- Date: Thu, 7 Apr 2011 16:38:52 +0000 (UTC)
commit 351e41a65365f33715bbd4756fa17d1c1cf62c0d
Author: Alban Crequy <alban crequy collabora co uk>
Date: Wed Apr 6 19:11:32 2011 +0100
libsocialweb: fix: update and delete contacts
Unit test updated
https://bugzilla.gnome.org/show_bug.cgi?id=646944
backends/libsocialweb/lib/swf-persona-store.vala | 14 +++-
tests/libsocialweb/dummy-lsw.vala | 106 +++++++++++++++++++++-
2 files changed, 114 insertions(+), 6 deletions(-)
---
diff --git a/backends/libsocialweb/lib/swf-persona-store.vala b/backends/libsocialweb/lib/swf-persona-store.vala
index c03816e..f5f73c7 100644
--- a/backends/libsocialweb/lib/swf-persona-store.vala
+++ b/backends/libsocialweb/lib/swf-persona-store.vala
@@ -229,7 +229,12 @@ public class Swf.PersonaStore : Folks.PersonaStore
{
foreach (var contact in contacts)
{
- var persona = _personas.lookup(Persona.get_contact_id (contact));
+ if (this._service.get_name () != contact.service)
+ {
+ continue;
+ }
+ var iid = Swf.Persona._build_iid(contact.service, Persona.get_contact_id (contact));
+ var persona = _personas.lookup(iid);
if (persona != null)
persona.update (contact);
}
@@ -240,7 +245,12 @@ public class Swf.PersonaStore : Folks.PersonaStore
var removed_personas = new Queue<Persona> ();
foreach (var contact in contacts)
{
- var persona = _personas.lookup(Persona.get_contact_id (contact));
+ if (this._service.get_name () != contact.service)
+ {
+ continue;
+ }
+ var iid = Swf.Persona._build_iid(contact.service, Persona.get_contact_id (contact));
+ var persona = _personas.lookup(iid);
if (persona != null)
{
removed_personas.push_tail(persona);
diff --git a/tests/libsocialweb/dummy-lsw.vala b/tests/libsocialweb/dummy-lsw.vala
index 0560ed5..2b6de39 100644
--- a/tests/libsocialweb/dummy-lsw.vala
+++ b/tests/libsocialweb/dummy-lsw.vala
@@ -97,12 +97,13 @@ public class DummyLswTests : Folks.TestCase
main_loop.run ();
Source.remove (timer_id);
- /* Ok, real test now */
- debug ("Ok, real test now");
+ /* Test adding two contacts */
+ string view_path = "";
mysocialnetwork.OpenViewCalled.connect((query, p, path) =>
{
debug ("mysocialnetwork.OpenViewCalled.connect");
+ view_path = path;
mysocialnetwork.contact_views[path].StartCalled.connect ( (path) =>
{
debug ("OpenViewCalled.connect");
@@ -134,13 +135,21 @@ public class DummyLswTests : Folks.TestCase
});
var aggregator = new IndividualAggregator ();
- aggregator.individuals_changed.connect ((added, removed, m, a, r) =>
+ Individual? i1 = null;
+ Individual? i2 = null;
+ var handler_id = aggregator.individuals_changed.connect (
+ (added, removed, m, a, r) =>
{
debug ("Aggregator got some data!");
+ assert (added.length () == 2);
+ assert (removed.length () == 0);
foreach (Individual i in added)
{
string nickname = ((Folks.NameDetails) i).nickname;
- debug ("nickname: %s", nickname);
+ if (nickname == "Gargantua")
+ i1 = i;
+ if (nickname == "Pantagruel")
+ i2 = i;
}
main_loop.quit ();
});
@@ -152,6 +161,95 @@ public class DummyLswTests : Folks.TestCase
});
main_loop.run ();
Source.remove (timer_id);
+ aggregator.disconnect (handler_id);
+ assert (i1 != null);
+ assert (i2 != null);
+
+ /* Test changing a contact */
+ Idle.add (() =>
+ {
+ string text = "([('mysocialnetwork', 'id01', %x, "
+ + "{'id': ['id01'], 'name': ['Rabelais']})],)";
+ Variant v = new Variant.parsed (text, 1300792581);
+ try
+ {
+ var conn = Bus.get_sync (BusType.SESSION);
+ conn.emit_signal (null, view_path,
+ "com.meego.libsocialweb.ContactView",
+ "ContactsChanged", v);
+ }
+ catch (GLib.IOError e)
+ {
+ assert_not_reached ();
+ }
+ catch (GLib.Error e)
+ {
+ assert_not_reached ();
+ }
+ return false;
+ });
+ handler_id = i1.notify["nickname"].connect (
+ () =>
+ {
+ debug ("Aggregator changed some data!");
+ string nickname = ((Folks.NameDetails) i1).nickname;
+ assert (nickname == "Rabelais");
+ main_loop.quit ();
+ });
+
+ timer_id = Timeout.add_seconds (5, () =>
+ {
+ assert_not_reached ();
+ });
+ main_loop.run ();
+ Source.remove (timer_id);
+ i1.disconnect (handler_id);
+
+ /* Test deleting two contacts */
+ Idle.add (() =>
+ {
+ string text = "([('mysocialnetwork', 'id01'), "
+ + "('mysocialnetwork', 'id02')],)";
+ Variant v = new Variant.parsed (text);
+ try
+ {
+ var conn = Bus.get_sync (BusType.SESSION);
+ conn.emit_signal (null, view_path,
+ "com.meego.libsocialweb.ContactView",
+ "ContactsRemoved", v);
+ }
+ catch (GLib.IOError e)
+ {
+ assert_not_reached ();
+ }
+ catch (GLib.Error e)
+ {
+ assert_not_reached ();
+ }
+ return false;
+ });
+
+ handler_id = aggregator.individuals_changed.connect (
+ (added, removed, m, a, r) =>
+ {
+ debug ("Aggregator deleted some data!");
+ assert (added.length () == 0);
+ assert (removed.length () == 2);
+ foreach (Individual i in removed)
+ {
+ string nickname = ((Folks.NameDetails) i).nickname;
+ debug ("deleted nickname: %s", nickname);
+ }
+ main_loop.quit ();
+ });
+
+ timer_id = Timeout.add_seconds (5, () =>
+ {
+ assert_not_reached ();
+ });
+ main_loop.run ();
+ Source.remove (timer_id);
+ aggregator.disconnect (handler_id);
this._lsw_backend.tear_down ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]