[folks/648811-dummy-backend-rebase1: 5/48] Create add persona test for dummy backend.
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks/648811-dummy-backend-rebase1: 5/48] Create add persona test for dummy backend.
- Date: Thu, 7 Nov 2013 10:23:03 +0000 (UTC)
commit 01e2656d483b70cdc98e033544bae47250f0f9d7
Author: Renato Araujo Oliveira Filho <renato filho canonical com>
Date: Sun Oct 27 19:38:01 2013 -0300
Create add persona test for dummy backend.
backends/dummy/lib/dummy-persona-store.vala | 212 +++++++++----
backends/dummy/lib/dummy-persona.vala | 2 +-
configure.ac | 1 +
folks/individual-aggregator.vala | 3 +
tests/Makefile.am | 2 +
tests/dummy/Makefile.am | 18 +-
tests/dummy/add-persona.vala | 481 +++++++++++++++++++++++++++
tests/dummy/individual-retrieval.vala | 220 ++++++++++++-
tests/key-file/individual-retrieval.vala | 1 +
tests/lib/dummy/test-case.vala | 56 ++--
tests/lib/test-case.vala | 1 +
11 files changed, 906 insertions(+), 91 deletions(-)
---
diff --git a/backends/dummy/lib/dummy-persona-store.vala b/backends/dummy/lib/dummy-persona-store.vala
index f9e9c6e..0dfc797 100644
--- a/backends/dummy/lib/dummy-persona-store.vala
+++ b/backends/dummy/lib/dummy-persona-store.vala
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 Philip Withnall
+ * 2013 Canonical 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
@@ -16,6 +17,7 @@
*
* Authors:
* Philip Withnall <philip tecnocode co uk>
+ * Renato Araujo Oliveira Filho <renato canonical com>
*/
using Folks;
@@ -42,6 +44,7 @@ public class Dummyf.PersonaStore : Folks.PersonaStore
private bool _prepare_pending = false;
private bool _is_quiescent = false;
private bool _quiescent_on_prepare = false;
+ private int _contact_id = 0;
/**
* The type of persona store this is.
@@ -302,7 +305,8 @@ public class Dummyf.PersonaStore : Folks.PersonaStore
}
/* Allow overriding the class used. */
- var contact_id = "TODO";
+ var contact_id = this._contact_id.to_string();
+ this._contact_id++;
var uid = Folks.Persona.build_uid (BACKEND_NAME, this.id, contact_id);
var iid = this.id + ":" + contact_id;
@@ -331,116 +335,210 @@ public class Dummyf.PersonaStore : Folks.PersonaStore
if (k == Folks.PersonaStore.detail_key (
PersonaDetail.FULL_NAME))
{
- string? full_name = v.get_string ();
- string _full_name = "";
- if (full_name != null)
+ var _persona = persona as NameDetails;
+ if (_persona != null)
{
- _full_name = (!) full_name;
+ string? full_name = v.get_string ();
+ string _full_name = "";
+ if (full_name != null)
+ {
+ _full_name = (!) full_name;
+ }
+ _persona.full_name = _full_name;
}
-
- var _persona = persona as NameDetails;
- assert (_persona != null);
- _persona.full_name = _full_name;
}
- /* TODO */
- /*else if (k == Folks.PersonaStore.detail_key (
+ else if (k == Folks.PersonaStore.detail_key (
PersonaDetail.EMAIL_ADDRESSES))
{
- Set<EmailFieldDetails> email_addresses =
- (Set<EmailFieldDetails>) v.get_object ();
- this._set_contact_attributes_string (contact,
- email_addresses,
- "EMAIL", E.ContactField.EMAIL);
+ var _persona = persona as EmailDetails;
+ if (_persona != null)
+ {
+ Set<EmailFieldDetails> email_addresses =
+ (Set<EmailFieldDetails>) v.get_object ();
+ if (email_addresses != null)
+ {
+ _persona.email_addresses = email_addresses;
+ }
+ }
}
else if (k == Folks.PersonaStore.detail_key (PersonaDetail.AVATAR))
{
- try
+ var _persona = persona as AvatarDetails;
+ if (_persona != null)
{
var avatar = (LoadableIcon?) v.get_object ();
- yield this._set_contact_avatar (contact, avatar);
- }
- catch (PropertyError e1)
- {
- warning ("Couldn't set avatar on the EContact: %s",
- e1.message);
+ if (avatar != null)
+ {
+ _persona.avatar = avatar;
+ }
}
}
else if (k == Folks.PersonaStore.detail_key (
PersonaDetail.IM_ADDRESSES))
{
- var im_fds = (MultiMap<string, ImFieldDetails>) v.get_object ();
- this._set_contact_im_fds (contact, im_fds);
+ var _persona = persona as ImDetails;
+ if (_persona != null)
+ {
+ MultiMap<string,ImFieldDetails> im_addresses =
+ (MultiMap<string,ImFieldDetails>) v.get_object ();
+ if (im_addresses != null)
+ {
+ _persona.im_addresses = im_addresses;
+ }
+ }
}
else if (k == Folks.PersonaStore.detail_key (
PersonaDetail.PHONE_NUMBERS))
{
- Set<PhoneFieldDetails> phone_numbers =
- (Set<PhoneFieldDetails>) v.get_object ();
- this._set_contact_attributes_string (contact,
- phone_numbers, "TEL",
- E.ContactField.TEL);
+ var _persona = persona as PhoneDetails;
+ if (_persona != null)
+ {
+ Set<PhoneFieldDetails> phone_numbers =
+ (Set<PhoneFieldDetails>) v.get_object ();
+ if (phone_numbers != null)
+ {
+ _persona.phone_numbers = phone_numbers;
+ }
+ }
}
else if (k == Folks.PersonaStore.detail_key (
PersonaDetail.POSTAL_ADDRESSES))
{
- Set<PostalAddressFieldDetails> postal_fds =
- (Set<PostalAddressFieldDetails>) v.get_object ();
- this._set_contact_postal_addresses (contact, postal_fds);
+ var _persona = persona as PostalAddressDetails;
+ if (_persona != null)
+ {
+ Set<PostalAddressFieldDetails> postal_fds =
+ (Set<PostalAddressFieldDetails>) v.get_object ();
+ if (postal_fds != null)
+ {
+ _persona.postal_addresses = postal_fds;
+ }
+ }
}
else if (k == Folks.PersonaStore.detail_key (
PersonaDetail.STRUCTURED_NAME))
{
- StructuredName sname = (StructuredName) v.get_object ();
- this._set_contact_name (contact, sname);
+ var _persona = persona as NameDetails;
+ if (_persona != null)
+ {
+ StructuredName sname = (StructuredName) v.get_object ();
+ if (sname != null)
+ {
+ _persona.structured_name = sname;
+ }
+ }
}
else if (k == Folks.PersonaStore.detail_key (PersonaDetail.LOCAL_IDS))
{
- Set<string> local_ids = (Set<string>) v.get_object ();
- this._set_contact_local_ids (contact, local_ids);
+ var _persona = persona as LocalIdDetails;
+ if (_persona != null)
+ {
+ Set<string> local_ids = (Set<string>) v.get_object ();
+ if (local_ids != null)
+ {
+ _persona.local_ids = local_ids;
+ }
+ }
}
else if (k == Folks.PersonaStore.detail_key
(PersonaDetail.WEB_SERVICE_ADDRESSES))
{
- HashMultiMap<string, WebServiceFieldDetails>
- web_service_addresses =
- (HashMultiMap<string, WebServiceFieldDetails>) v.get_object ();
- this._set_contact_web_service_addresses (contact,
- web_service_addresses);
+ var _persona = persona as WebServiceDetails;
+ if (_persona != null)
+ {
+ HashMultiMap<string, WebServiceFieldDetails>
+ web_service_addresses =
+ (HashMultiMap<string, WebServiceFieldDetails>) v.get_object ();
+ if (web_service_addresses != null)
+ {
+ _persona.web_service_addresses = web_service_addresses;
+ }
+ }
}
else if (k == Folks.PersonaStore.detail_key (PersonaDetail.NOTES))
{
- var notes = (Gee.HashSet<NoteFieldDetails>) v.get_object ();
- this._set_contact_notes (contact, notes);
+ var _persona = persona as NoteDetails;
+ if (_persona != null)
+ {
+ var notes = (Gee.HashSet<NoteFieldDetails>) v.get_object ();
+ if (notes != null)
+ {
+ _persona.notes = notes;
+ }
+ }
}
else if (k == Folks.PersonaStore.detail_key (PersonaDetail.GENDER))
{
- var gender = (Gender) v.get_enum ();
- this._set_contact_gender (contact, gender);
+ var _persona = persona as GenderDetails;
+ if (_persona != null)
+ {
+ var gender = (Gender) v.get_enum ();
+ _persona.gender = gender;
+ }
}
else if (k == Folks.PersonaStore.detail_key (PersonaDetail.URLS))
{
- Set<UrlFieldDetails> urls = (Set<UrlFieldDetails>) v.get_object ();
- this._set_contact_urls (contact, urls);
+ var _persona = persona as UrlDetails;
+ if (_persona != null)
+ {
+ Set<UrlFieldDetails> urls = (Set<UrlFieldDetails>) v.get_object ();
+ if (urls != null)
+ {
+ _persona.urls = urls;
+ }
+ }
}
else if (k == Folks.PersonaStore.detail_key (PersonaDetail.BIRTHDAY))
{
- var birthday = (DateTime?) v.get_boxed ();
- this._set_contact_birthday (contact, birthday);
+ var _persona = persona as BirthdayDetails;
+ if (_persona != null)
+ {
+ var birthday = (DateTime?) v.get_boxed ();
+ if (birthday != null)
+ {
+ _persona.birthday = birthday;
+ }
+ }
}
else if (k == Folks.PersonaStore.detail_key (PersonaDetail.ROLES))
{
- Set<RoleFieldDetails> roles =
- (Set<RoleFieldDetails>) v.get_object ();
- this._set_contact_roles (contact, roles);
+ var _persona = persona as RoleDetails;
+ if (_persona != null)
+ {
+ Set<RoleFieldDetails> roles =
+ (Set<RoleFieldDetails>) v.get_object ();
+ if (roles != null)
+ {
+ _persona.roles = roles;
+ }
+ }
}
else if (k == Folks.PersonaStore.detail_key (
PersonaDetail.IS_FAVOURITE))
{
- bool is_fav = v.get_boolean ();
- this._set_contact_is_favourite (contact, is_fav);
- }*/
+ var _persona = persona as FavouriteDetails;
+ if (_persona != null)
+ {
+ bool is_fav = v.get_boolean ();
+ _persona.is_favourite = is_fav;
+ }
+ }
+ else if (k == Folks.PersonaStore.detail_key (
+ PersonaDetail.NICKNAME))
+ {
+ var _persona = persona as NameDetails;
+ if (_persona != null)
+ {
+ string? nickname = v.get_string ();
+ string _nickname = "";
+ if (nickname != null)
+ {
+ _nickname = (!) nickname;
+ }
+ _persona.nickname = _nickname;
+ }
+ }
}
-
/* Allow the caller to inject failures into add_persona_from_details()
* by providing a mock function which can throw errors as appropriate. */
if (this.add_persona_from_details_mock != null)
diff --git a/backends/dummy/lib/dummy-persona.vala b/backends/dummy/lib/dummy-persona.vala
index 9634347..7d15288 100644
--- a/backends/dummy/lib/dummy-persona.vala
+++ b/backends/dummy/lib/dummy-persona.vala
@@ -23,7 +23,7 @@ using Gee;
using GLib;
/**
- * A persona subclass which represents a single EDS contact. TODO
+ * A persona subclass which represents a single contact. TODO
*
* Each { link Dummy.Persona} instance represents a single EDS { link E.Contact}.
* When the contact is modified (either by this folks client, or a different
diff --git a/configure.ac b/configure.ac
index 9e98dd1..a1acb92 100644
--- a/configure.ac
+++ b/configure.ac
@@ -693,6 +693,7 @@ AC_CONFIG_FILES([
tests/data/Makefile
tests/eds/Makefile
tests/folks/Makefile
+ tests/dummy/Makefile
tests/key-file/Makefile
tests/libsocialweb/Makefile
tests/telepathy/Makefile
diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala
index 1815145..2ae8b54 100644
--- a/folks/individual-aggregator.vala
+++ b/folks/individual-aggregator.vala
@@ -889,9 +889,12 @@ public class Folks.IndividualAggregator : Object
/* Handle the stores that have already been signaled. Since
* this might change while we are looping, get a copy first.
*/
+
var stores = backend.persona_stores.values.to_array ();
+ GLib.debug("new backend--------------------------------------%s:%d\n", backend.name,
stores.length);
foreach (var persona_store in stores)
{
+ GLib.debug("new backend--------------------------------------\n");
this._backend_persona_store_added_cb (backend, persona_store);
}
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 10c0f56..0fe630b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -3,6 +3,7 @@
SUBDIRS = \
data \
lib \
+ dummy \
key-file \
tools \
$(NULL)
@@ -30,6 +31,7 @@ DIST_SUBDIRS = \
lib \
tools \
folks \
+ dummy \
eds \
key-file \
telepathy \
diff --git a/tests/dummy/Makefile.am b/tests/dummy/Makefile.am
index 5f562c5..67c964f 100644
--- a/tests/dummy/Makefile.am
+++ b/tests/dummy/Makefile.am
@@ -7,37 +7,43 @@ AM_CPPFLAGS = \
$(GEE_CFLAGS) \
-I$(top_srcdir) \
-I$(top_srcdir)/folks \
+ -I$(top_srcdir)/backends/dummy/lib \
-I$(top_srcdir)/tests/lib \
- -I$(top_srcdir)/tests/lib/key-file \
+ -I$(top_srcdir)/tests/lib/dummy \
-include $(CONFIG_HEADER) \
$(NULL)
LDADD = \
- $(top_builddir)/tests/lib/key-file/libkf-test.la \
+ $(top_builddir)/tests/lib/dummy/libdummy-test.la \
$(top_builddir)/tests/lib/libfolks-test.la \
+ $(top_builddir)/backends/dummy/lib/libfolks-dummy.la \
$(top_builddir)/folks/libfolks.la \
$(GLIB_LIBS) \
$(GEE_LIBS) \
+ -L$(top_srcdir)/backends/dummy/lib \
$(NULL)
AM_VALAFLAGS += \
$(ERROR_VALAFLAGS) \
--vapidir=. \
--vapidir=$(top_srcdir)/folks \
+ --vapidir=$(top_srcdir)/backends/dummy/lib \
--vapidir=$(top_srcdir)/tests/lib \
- --vapidir=$(top_srcdir)/tests/lib/key-file \
+ --vapidir=$(top_srcdir)/tests/lib/dummy \
--pkg gobject-2.0 \
--pkg gio-2.0 \
--pkg gee-0.8 \
--pkg folks \
+ --pkg folks-dummy \
--pkg folks-test \
- --pkg kf-test \
+ --pkg dummy-test \
-g \
$(NULL)
# in order from least to most complex
noinst_PROGRAMS = \
individual-retrieval \
+ add-persona \
$(NULL)
TESTS = $(noinst_PROGRAMS)
@@ -46,6 +52,10 @@ individual_retrieval_SOURCES = \
individual-retrieval.vala \
$(NULL)
+add_persona_SOURCES = \
+ add-persona.vala \
+ $(NULL)
+
CLEANFILES = \
*.pid \
*.address \
diff --git a/tests/dummy/add-persona.vala b/tests/dummy/add-persona.vala
new file mode 100644
index 0000000..c204f6d
--- /dev/null
+++ b/tests/dummy/add-persona.vala
@@ -0,0 +1,481 @@
+/*
+ * Copyright (C) 2011 Collabora Ltd.
+ 2013 Canonical 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: Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
+ * Renato Araujo Oliveira Filho <renato canonical com>
+ *
+ */
+
+using Folks;
+using Gee;
+//using DummyTest;
+//using Dummy;
+
+public class AddPersonaTests : DummyTest.TestCase
+{
+ private GLib.MainLoop _main_loop;
+ private IndividualAggregator _aggregator;
+ private string _persona_fullname;
+ private string _persona_nickname;
+ private string _email_1;
+ private bool _added_persona = false;
+ private HashTable<string, bool> _properties_found;
+ private string _avatar_path;
+ private string _im_addr_1;
+ private string _im_addr_2;
+ private string _phone_1;
+ private string _phone_1_type;
+ private string _phone_2;
+ private string _phone_2_type;
+ private PostalAddressFieldDetails _address;
+ private string _po_box = "12345";
+ private string _locality = "locality";
+ private string _postal_code = "code";
+ private string _street = "some street";
+ private string _extension = "some extension";
+ private string _country = "some country";
+ private string _region = "some region";
+ private string _family_name;
+ private string _given_name;
+ private string _note = "This is a note.";
+ private Individual _individual_received;
+
+ public AddPersonaTests ()
+ {
+ base ("AddPersonaTests");
+
+ this.add_test ("test adding a persona to dummy ", this.test_add_persona);
+ }
+
+ public void test_add_persona ()
+ {
+ this._main_loop = new GLib.MainLoop (null, false);
+ this._persona_fullname = "persona #1";
+ this._persona_nickname = "Jo";
+ this._email_1 = "someone-1 example org";
+ this._avatar_path = Folks.TestUtils.get_source_test_data (
+ "data/avatar-01.jpg");
+ this._im_addr_1 = "someone-1 jabber example org";
+ this._im_addr_2 = "someone-2 jabber example org";
+ this._phone_1 = "12345";
+ this._phone_1_type = AbstractFieldDetails.PARAM_TYPE_HOME;
+ this._phone_2 = "54321";
+ this._phone_2_type = AbstractFieldDetails.PARAM_TYPE_OTHER;
+ this._family_name = "family";
+ this._given_name = "given";
+
+ var pa = new PostalAddress (this._po_box,
+ this._extension, this._street, this._locality, this._region,
+ this._postal_code, this._country, null, null);
+ this._address = new PostalAddressFieldDetails (pa);
+ this._address.add_parameter (AbstractFieldDetails.PARAM_TYPE,
+ AbstractFieldDetails.PARAM_TYPE_HOME);
+
+ this._properties_found = new HashTable<string, bool>
+ (str_hash, str_equal);
+ this._properties_found.insert ("full_name", false);
+ this._properties_found.insert ("nickname", false);
+ this._properties_found.insert ("email-1", false);
+ this._properties_found.insert ("avatar", false);
+ this._properties_found.insert ("im-addr-1", false);
+ this._properties_found.insert ("im-addr-2", false);
+ this._properties_found.insert ("phone-1", false);
+ this._properties_found.insert ("phone-2", false);
+ this._properties_found.insert ("postal-address-1", false);
+ this._properties_found.insert ("structured_name", false);
+ this._properties_found.insert ("note", false);
+ //FIXME: for some reason Birthday is not getting notified
+ //this._properties_found.insert ("birthday", false);
+ this._properties_found.insert ("role-1", false);
+ this._properties_found.insert ("is-favourite", false);
+
+ this._test_add_persona_async.begin ();
+
+ TestUtils.loop_run_with_timeout (this._main_loop);
+
+ foreach (var k in this._properties_found.get_values ())
+ {
+ assert (k);
+ }
+ }
+
+ private async void _test_add_persona_async ()
+ {
+ this._aggregator = new IndividualAggregator ();
+ this._aggregator.individuals_changed_detailed.connect (this._individuals_changed_cb);
+ try
+ {
+ yield this._aggregator.prepare ();
+ this._try_to_add ();
+ }
+ catch (GLib.Error e)
+ {
+ GLib.warning ("Error when calling prepare: %s\n", e.message);
+ }
+ }
+
+ private async void _add_persona ()
+ {
+ HashTable<string, Value?> details = new HashTable<string, Value?>
+ (str_hash, str_equal);
+
+ Value? v1 = Value (typeof (string));
+ v1.set_string (this._persona_fullname);
+ details.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME),
+ (owned) v1);
+
+ Value? v2 = Value (typeof (Set));
+ var emails = new HashSet<EmailFieldDetails> (
+ AbstractFieldDetails<string>.hash_static,
+ AbstractFieldDetails<string>.equal_static);
+ var email_1 = new EmailFieldDetails (this._email_1);
+ email_1.set_parameter (AbstractFieldDetails.PARAM_TYPE,
+ AbstractFieldDetails.PARAM_TYPE_HOME);
+ emails.add (email_1);
+ v2.set_object (emails);
+ details.insert (
+ Folks.PersonaStore.detail_key (PersonaDetail.EMAIL_ADDRESSES),
+ (owned) v2);
+
+ Value? v3 = Value (typeof (LoadableIcon));
+ var avatar = new FileIcon (File.new_for_path (this._avatar_path));
+ v3.set_object (avatar);
+ details.insert (Folks.PersonaStore.detail_key (PersonaDetail.AVATAR),
+ (owned) v3);
+
+ Value? v4 = Value (typeof (MultiMap));
+ var im_fds = new HashMultiMap<string, ImFieldDetails> ();
+ im_fds.set ("jabber", new ImFieldDetails (this._im_addr_1));
+ im_fds.set ("yahoo", new ImFieldDetails (this._im_addr_2));
+ v4.set_object (im_fds);
+ details.insert (
+ Folks.PersonaStore.detail_key (PersonaDetail.IM_ADDRESSES), v4);
+
+ Value? v5 = Value (typeof (Set));
+ var phones = new HashSet<PhoneFieldDetails> (
+ AbstractFieldDetails<string>.hash_static,
+ AbstractFieldDetails<string>.equal_static);
+
+ var phone_1 = new PhoneFieldDetails (this._phone_1);
+ phone_1.set_parameter (AbstractFieldDetails.PARAM_TYPE,
+ this._phone_1_type);
+ phones.add (phone_1);
+ var phone_2 = new PhoneFieldDetails (this._phone_2);
+ phone_2.set_parameter (AbstractFieldDetails.PARAM_TYPE,
+ this._phone_2_type);
+ phones.add (phone_2);
+ v5.set_object (phones);
+ details.insert (
+ Folks.PersonaStore.detail_key (PersonaDetail.PHONE_NUMBERS),
+ (owned) v5);
+
+ Value? v6 = Value (typeof (Set));
+ var pa_fds = new HashSet<PostalAddressFieldDetails> (
+ AbstractFieldDetails<PostalAddress>.hash_static,
+ AbstractFieldDetails<PostalAddress>.equal_static);
+
+ PostalAddress pa_a = new PostalAddress (this._po_box,
+ this._extension, this._street, this._locality, this._region,
+ this._postal_code, this._country, null, null);
+ var pa_fd_a = new PostalAddressFieldDetails (pa_a);
+ pa_fd_a.add_parameter (AbstractFieldDetails.PARAM_TYPE,
+ AbstractFieldDetails.PARAM_TYPE_HOME);
+ pa_fds.add (pa_fd_a);
+ v6.set_object (pa_fds);
+ details.insert (
+ Folks.PersonaStore.detail_key (PersonaDetail.POSTAL_ADDRESSES),
+ (owned) v6);
+
+ Value? v7 = Value (typeof (StructuredName));
+ StructuredName sname = new StructuredName (this._family_name,
+ this._given_name, null, null, null);
+ v7.set_object (sname);
+ details.insert (
+ Folks.PersonaStore.detail_key (PersonaDetail.STRUCTURED_NAME),
+ (owned) v7);
+
+ Value? v8 = Value (typeof (Set));
+ var notes = new HashSet<NoteFieldDetails> (
+ AbstractFieldDetails<string>.hash_static,
+ AbstractFieldDetails<string>.equal_static);
+ var note = new NoteFieldDetails (this._note);
+ notes.add (note);
+ v8.set_object (notes);
+ details.insert (
+ Folks.PersonaStore.detail_key (PersonaDetail.NOTES),
+ (owned) v8);
+
+ Value? v9 = Value (typeof (DateTime));
+ DateTime dobj = new DateTime.local (1980, 1, 1, 0, 0, 0.0).to_utc ();
+ v9.set_boxed (dobj);
+ details.insert (Folks.PersonaStore.detail_key (PersonaDetail.BIRTHDAY),
+ (owned) v9);
+
+ Value? v10 = Value (typeof (Set));
+ var role_fds = new HashSet<RoleFieldDetails> (
+ AbstractFieldDetails<Role>.hash_static,
+ AbstractFieldDetails<Role>.equal_static);
+ var r1 = new Role ("Dr.", "The Nut House Ltd");
+ r1.role = "The Manager";
+ var role_fd1 = new RoleFieldDetails (r1);
+ role_fds.add (role_fd1);
+ v10.set_object (role_fds);
+ details.insert (Folks.PersonaStore.detail_key (PersonaDetail.ROLES),
+ (owned) v10);
+
+ Value? v11 = Value (typeof (bool));
+ v11.set_boolean (true);
+ details.insert (
+ Folks.PersonaStore.detail_key (PersonaDetail.IS_FAVOURITE),
+ (owned) v11);
+
+ Value? v12 = Value (typeof (string));
+ v12.set_string (this._persona_nickname);
+ details.insert (Folks.PersonaStore.detail_key (PersonaDetail.NICKNAME),
+ (owned) v12);
+
+ try
+ {
+ yield this._aggregator.add_persona_from_details (null,
+ this.dummy_persona_store, details);
+ }
+ catch (Folks.IndividualAggregatorError e)
+ {
+ GLib.warning ("[AddPersonaError] add_persona_from_details: %s\n",
+ e.message);
+ }
+ }
+
+ private void _individuals_changed_cb (
+ MultiMap<Individual?, Individual?> changes)
+ {
+ var added = changes.get_values ();
+ var removed = changes.get_keys ();
+
+ uint num_replaces = 0;
+
+ foreach (var i in added)
+ {
+ if (i == null)
+ {
+ continue;
+ }
+
+ num_replaces = this._track_individual (i);
+ }
+
+ assert (removed.size <= num_replaces + 1);
+ }
+
+ private uint _track_individual (Individual i)
+ {
+ uint retval = 0;
+
+ if (i.is_user == false)
+ {
+ /* we assume that there will be exactly one (unique) individual
+ * received */
+ assert (this._individual_received == null ||
+ this._individual_received.id == i.id);
+
+ /* handle replacement */
+ if (this._individual_received != null)
+ {
+ i.notify["full-name"].disconnect (this._notify_cb);
+ i.notify["nickname"].disconnect (this._notify_cb);
+ i.notify["email-addresses"].disconnect (this._notify_cb);
+ i.notify["avatar"].disconnect (this._notify_cb);
+ i.notify["im-addresses"].disconnect (this._notify_cb);
+ i.notify["phone-numbers"].disconnect (this._notify_cb);
+ i.notify["postal-addresses"].disconnect (this._notify_cb);
+ i.notify["structured-name"].disconnect (this._notify_cb);
+ i.notify["notes"].disconnect (this._notify_cb);
+ i.notify["birthday"].disconnect (this._notify_cb);
+ i.notify["roles"].disconnect (this._notify_cb);
+ i.notify["is-favourite"].disconnect (this._notify_cb);
+
+ this._properties_found.remove_all ();
+ }
+
+ this._individual_received = i;
+ retval++;
+
+ i.notify["full-name"].connect (this._notify_cb);
+ i.notify["nickname"].connect (this._notify_cb);
+ i.notify["email-addresses"].connect (this._notify_cb);
+ i.notify["avatar"].connect (this._notify_cb);
+ i.notify["im-addresses"].connect (this._notify_cb);
+ i.notify["phone-numbers"].connect (this._notify_cb);
+ i.notify["postal-addresses"].connect (this._notify_cb);
+ i.notify["structured-name"].connect (this._notify_cb);
+ i.notify["notes"].connect (this._notify_cb);
+ i.notify["birthday"].connect (this._notify_cb);
+ i.notify["roles"].connect (this._notify_cb);
+ i.notify["is-favourite"].connect (this._notify_cb);
+
+ this._check_properties.begin (i);
+ }
+
+ return retval;
+ }
+
+ private void _notify_cb (Object individual_obj, ParamSpec ps)
+ {
+ Folks.Individual i = (Folks.Individual) individual_obj;
+ this._check_properties.begin (i);
+ }
+
+ private void _try_to_add ()
+ {
+ lock (this._added_persona)
+ {
+ this._add_persona.begin ();
+ }
+ }
+
+ private async void _check_properties (Individual i)
+ {
+ if (i.full_name == this._persona_fullname)
+ this._properties_found.replace ("full_name", true);
+
+ if (i.nickname == this._persona_nickname)
+ {
+ this._properties_found.replace ("nickname", true);
+ }
+
+ foreach (var e in i.email_addresses)
+ {
+ if (e.value == this._email_1)
+ {
+ this._properties_found.replace ("email-1", true);
+ }
+ }
+
+ foreach (var proto in i.im_addresses.get_keys ())
+ {
+ var im_fds = i.im_addresses.get (proto);
+ foreach (var im_fd in im_fds)
+ {
+ if (im_fd.value == this._im_addr_1)
+ this._properties_found.replace ("im-addr-1", true);
+ else if (im_fd.value == this._im_addr_2)
+ this._properties_found.replace ("im-addr-2", true);
+ }
+ }
+
+ foreach (var phone_fd in i.phone_numbers)
+ {
+ var phone_1 = new PhoneFieldDetails (this._phone_1);
+ phone_1.set_parameter (AbstractFieldDetails.PARAM_TYPE,
+ this._phone_1_type);
+ var phone_2 = new PhoneFieldDetails (this._phone_2);
+ phone_2.set_parameter (AbstractFieldDetails.PARAM_TYPE,
+ this._phone_2_type);
+
+ if (phone_fd.equal (phone_1))
+ {
+ this._properties_found.replace ("phone-1", true);
+ }
+ else if (phone_fd.equal (phone_2))
+ {
+ this._properties_found.replace ("phone-2", true);
+ }
+ }
+
+ foreach (var pa_fd in i.postal_addresses)
+ {
+ this._address.id = pa_fd.id;
+ if (pa_fd.equal (this._address))
+ this._properties_found.replace ("postal-address-1", true);
+ }
+
+ if (i.structured_name != null &&
+ i.structured_name.family_name == this._family_name &&
+ i.structured_name.given_name == this._given_name)
+ this._properties_found.replace ("structured_name", true);
+
+ foreach (var note in i.notes)
+ {
+ if (note.equal (new NoteFieldDetails (this._note)))
+ {
+ this._properties_found.replace ("note", true);
+ break;
+ }
+ }
+
+ if (i.avatar != null)
+ {
+ var b = new FileIcon (File.new_for_path (this._avatar_path));
+
+ var same = yield TestUtils.loadable_icons_content_equal (b, i.avatar,
+ -1);
+ if (same)
+ this._properties_found.replace ("avatar", true);
+ }
+
+ if (i.birthday != null)
+ {
+ DateTime dobj = new DateTime.local (1980, 1, 1, 0, 0, 0.0).to_utc ();
+ if (i.birthday.equal (dobj)) {
+ this._properties_found.replace ("birthday", true);
+ }
+ }
+
+ foreach (var role_fd in i.roles)
+ {
+ var r1 = new Role ("Dr.", "The Nut House Ltd");
+ r1.role = "The Manager";
+ var role_fd_expected = new RoleFieldDetails (r1);
+ if (role_fd.equal (role_fd_expected))
+ this._properties_found.replace ("role-1", true);
+ }
+
+ if (i.is_favourite)
+ {
+ this._properties_found.replace ("is-favourite", true);
+ }
+
+ this._exit_if_all_properties_found ();
+ }
+
+ private void _exit_if_all_properties_found ()
+ {
+ GLib.debug("_exit_if_all_properties_found>>>>>>>>>>>>>>>>>>>>>>>>>>>: BEGIN\n");
+ foreach (var k in this._properties_found.get_keys ())
+ {
+ var v = this._properties_found.lookup (k);
+ if (v == false) {
+ GLib.debug("_exit_if_all_properties_found>>>>>>>>>>>>>>>>>>>>>>>>>>>: [%s:%d] CONTINUE\n", k,
(int) v);
+ return;
+ }
+ }
+ GLib.debug("_exit_if_all_properties_found>>>>>>>>>>>>>>>>>>>>>>>>>>>: END\n");
+ this._main_loop.quit ();
+ }
+}
+
+public int main (string[] args)
+{
+ Test.init (ref args);
+
+ var tests = new AddPersonaTests ();
+ tests.register ();
+ Test.run ();
+ tests.final_tear_down ();
+
+ return 0;
+}
diff --git a/tests/dummy/individual-retrieval.vala b/tests/dummy/individual-retrieval.vala
index de78d78..3a3c088 100644
--- a/tests/dummy/individual-retrieval.vala
+++ b/tests/dummy/individual-retrieval.vala
@@ -20,6 +20,7 @@
using Gee;
using Folks;
using DummyTest;
+using Dummyf;
public class IndividualRetrievalTests : DummyTest.TestCase
{
@@ -27,20 +28,227 @@ public class IndividualRetrievalTests : DummyTest.TestCase
{
base ("IndividualRetrieval");
- this.add_test ("singleton individuals", this.test_singleton_individuals);
- this.add_test ("aliases", this.test_aliases);
+ this.add_test ("dummy individuals", this.test_aggregator);
}
- public void test_singleton_individuals ()
+ private Folks.Persona create_persona_rodrigo()
{
+ var rodrigo = new FatPersona(this.dummy_persona_store, "dummy 2");
var main_loop = new GLib.MainLoop (null, false);
- Dummy.PersonaStore dummy_persona_store = new Dummy.PersonaStore();
- dummy_persona_store.add_persona_from_details(details);
+ rodrigo.change_full_name.begin("Rodrigo Almeida", (s, r) =>
+ {
+ try
+ {
+ rodrigo.change_full_name.end(r);
+ }
+ catch (Folks.PropertyError e)
+ {
+ }
+ main_loop.quit();
+ });
+ TestUtils.loop_run_with_timeout (main_loop);
+
+ rodrigo.nickname = "kiko";
+ rodrigo.change_nickname.begin("kiko", (s, r) =>
+ {
+ try
+ {
+ rodrigo.change_nickname.end(r);
+ }
+ catch (Folks.PropertyError e)
+ {
+ }
+ main_loop.quit();
+ });
+ TestUtils.loop_run_with_timeout (main_loop);
+
+ // Emails
+ var emails = new HashSet<EmailFieldDetails> (
+ AbstractFieldDetails<string>.hash_static,
+ AbstractFieldDetails<string>.equal_static);
+
+ var email_1 = new EmailFieldDetails ("rodrigo gmail com");
+ email_1.set_parameter (AbstractFieldDetails.PARAM_TYPE,
+ AbstractFieldDetails.PARAM_TYPE_HOME);
+ emails.add (email_1);
+ rodrigo.change_email_addresses.begin(emails, (s, r) =>
+ {
+ try
+ {
+ rodrigo.change_email_addresses.end(r);
+ }
+ catch (Folks.PropertyError e)
+ {
+ }
+ main_loop.quit();
+ });
+ TestUtils.loop_run_with_timeout (main_loop);
+
+ //Ims
+ var im_fds = new HashMultiMap<string, ImFieldDetails> ();
+ im_fds.set ("jabber", new ImFieldDetails ("rodrigo jabber com"));
+ im_fds.set ("yahoo", new ImFieldDetails ("rodrigo yahoo com"));
+ rodrigo.change_im_addresses.begin(im_fds, (s, r) =>
+ {
+ try
+ {
+ rodrigo.change_im_addresses.end(r);
+ }
+ catch (Folks.PropertyError e)
+ {
+ }
+ main_loop.quit();
+ });
+ TestUtils.loop_run_with_timeout (main_loop);
+ return rodrigo;
+ }
+
+
+ private Folks.Persona create_persona_renato()
+ {
+ var renato = new FatPersona(this.dummy_persona_store, "dummy 1");
+ var main_loop = new GLib.MainLoop (null, false);
+
+ renato.change_full_name.begin("Renato Araujo Oliveira Filho", (s, r) =>
+ {
+ try
+ {
+ renato.change_full_name.end(r);
+ }
+ catch (Folks.PropertyError e)
+ {
+ assert_not_reached ();
+ }
+ main_loop.quit();
+ });
+ TestUtils.loop_run_with_timeout (main_loop);
+
+ renato.change_nickname.begin("renatofilho", (s, r) =>
+ {
+ try
+ {
+ renato.change_nickname.end(r);
+ }
+ catch (Folks.PropertyError e)
+ {
+ }
+ main_loop.quit();
+ });
+ TestUtils.loop_run_with_timeout (main_loop);
+
+ // Emails
+ var emails = new HashSet<EmailFieldDetails> (
+ AbstractFieldDetails<string>.hash_static,
+ AbstractFieldDetails<string>.equal_static);
+
+ var email_1 = new EmailFieldDetails ("renato canonical com");
+ email_1.set_parameter (AbstractFieldDetails.PARAM_TYPE,
+ AbstractFieldDetails.PARAM_TYPE_HOME);
+ emails.add (email_1);
+ renato.change_email_addresses.begin(emails, (s, r) =>
+ {
+ try
+ {
+ renato.change_email_addresses.end(r);
+ }
+ catch (Folks.PropertyError e)
+ {
+ }
+ main_loop.quit();
+ });
+ TestUtils.loop_run_with_timeout (main_loop);
+
+ //Ims
+ var im_fds = new HashMultiMap<string, ImFieldDetails> ();
+ im_fds.set ("jabber", new ImFieldDetails ("renato jabber com"));
+ im_fds.set ("yahoo", new ImFieldDetails ("renato yahoo com"));
+ renato.change_im_addresses.begin(im_fds, (s, r) =>
+ {
+ try
+ {
+ renato.change_im_addresses.end(r);
+ }
+ catch (Folks.PropertyError e)
+ {
+ }
+ main_loop.quit();
+ });
+ TestUtils.loop_run_with_timeout (main_loop);
+
+ return renato;
+ }
+
+ private void register_personas()
+ {
+ var personas = new HashSet<Folks.Persona>();
+ var kiko = create_persona_rodrigo();
+ GLib.debug("CREATED: %s\n", (kiko as NameDetails).nickname);
+ personas.add(create_persona_renato());
+ personas.add(create_persona_rodrigo());
+ this.dummy_persona_store.register_personas (personas);
}
- public void test_aliases ()
+ public void test_aggregator ()
{
+ var main_loop = new GLib.MainLoop (null, false);
+
+ HashSet<string> expected_individuals = new HashSet<string> ();
+ expected_individuals.add("Renato Araujo Oliveira Filho");
+ expected_individuals.add("Rodrigo Almeida");
+
+ /* Set up the aggregator */
+ var aggregator = new IndividualAggregator ();
+ aggregator.individuals_changed_detailed.connect ((changes) =>
+ {
+ var added = changes.get_values ();
+ var removed = changes.get_keys ();
+
+ assert (added.size == 2);
+
+ foreach (Individual i in added)
+ {
+ assert (i != null);
+ expected_individuals.remove (i.full_name);
+ }
+
+ assert (removed.size == 1);
+
+ main_loop.quit();
+ });
+
+ /* Kill the main loop after a few seconds. If there are still individuals
+ * in the set of expected individuals, the aggregator has either failed or
+ * been too slow (which we can consider to be failure). */
+
+ Idle.add (() =>
+ {
+ aggregator.prepare.begin ((s,r) =>
+ {
+ try
+ {
+ aggregator.prepare.end (r);
+ this.dummy_persona_store.reach_quiescence ();
+ register_personas();
+ }
+ catch (GLib.Error e1)
+ {
+ GLib.critical ("failed to prepare aggregator: %s",
+ e1.message);
+ assert_not_reached ();
+ }
+ });
+
+ return false;
+ });
+
+ TestUtils.loop_run_with_timeout (main_loop);
+
+ /* We should have enumerated exactly the individuals in the set */
+ assert (expected_individuals.size == 0);
+
+ /* necessary to reset the aggregator for the next test */
+ aggregator = null;
}
}
diff --git a/tests/key-file/individual-retrieval.vala b/tests/key-file/individual-retrieval.vala
index 42ca874..d1a1f51 100644
--- a/tests/key-file/individual-retrieval.vala
+++ b/tests/key-file/individual-retrieval.vala
@@ -155,3 +155,4 @@ public int main (string[] args)
return 0;
}
+
diff --git a/tests/lib/dummy/test-case.vala b/tests/lib/dummy/test-case.vala
index 28498a5..45e58e2 100644
--- a/tests/lib/dummy/test-case.vala
+++ b/tests/lib/dummy/test-case.vala
@@ -26,7 +26,7 @@ using Gee;
* A test case for the dummy backend, which is configured as the
* primary store and as the only backend allowed.
*/
-public class Dummy.TestCase : Folks.TestCase
+public class DummyTest.TestCase : Folks.TestCase
{
/**
* The dummy test backend.
@@ -38,50 +38,60 @@ public class Dummy.TestCase : Folks.TestCase
*/
public Dummyf.PersonaStore dummy_persona_store;
+ private BackendStore backend_store;
+
public TestCase (string name)
{
base (name);
Environment.set_variable ("FOLKS_BACKENDS_ALLOWED", "dummy", true);
+ Environment.set_variable ("FOLKS_PRIMARY_STORE", "dummy", true);
}
public override void set_up ()
{
base.set_up ();
- this.dummy_backend = new Dummyf.Backend ();
- this.dummy_backend.prepare.begin((obj, res) => {
- try {
- this.dummy_backend.prepare.end(res);
- } catch (GLib.Error error) {
- }
- });
+ var main_loop = new GLib.MainLoop (null, false);
+ this.backend_store = BackendStore.dup();
+ this.backend_store.load_backends.begin((obj, res) =>
+ {
+ try
+ {
+ this.backend_store.load_backends.end(res);
+ main_loop.quit ();
+ }
+ catch (GLib.Error error)
+ {
+ GLib.critical("Fail to initialized backend store.\n");
+ assert_not_reached ();
+ }
+ });
+ TestUtils.loop_run_with_timeout (main_loop);
+
+ this.dummy_backend = this.backend_store.dup_backend_by_name ("dummy") as Dummyf.Backend;
this.configure_primary_store ();
}
public virtual void configure_primary_store ()
{
var persona_stores = new HashSet<PersonaStore>();
- string[] writable_properties = {"birthday", "email-addresses", "full-name"};
- this.dummy_persona_store = new Dummyf.PersonaStore("dummy", "Dummy personas", writable_properties);
+ string[] writable_properties = { Folks.PersonaStore.detail_key (PersonaDetail.BIRTHDAY),
+ Folks.PersonaStore.detail_key (PersonaDetail.EMAIL_ADDRESSES),
+ Folks.PersonaStore.detail_key (PersonaDetail.PHONE_NUMBERS),
+ null };
- persona_stores.add(this.dummy_persona_store);
- this.dummy_backend.register_persona_stores(persona_stores);
+ this.dummy_persona_store = new Dummyf.PersonaStore ("dummy-store", "Dummy personas",
writable_properties);
+ this.dummy_persona_store.persona_type = typeof (Dummyf.FatPersona);
+
+ persona_stores.add (this.dummy_persona_store);
+ this.dummy_backend.register_persona_stores (persona_stores);
}
public override void tear_down ()
{
- if (this.dummy_backend != null)
- {
- this.dummy_backend.unprepare.begin((obj, res) => {
- try {
- this.dummy_backend.unprepare.end(res);
- } catch (GLib.Error error) {
- }
- });
- this.dummy_backend = null;
- }
-
+ this.dummy_persona_store = null;
+ this.dummy_backend = null;
base.tear_down ();
}
}
diff --git a/tests/lib/test-case.vala b/tests/lib/test-case.vala
index 838f69c..e739fbf 100644
--- a/tests/lib/test-case.vala
+++ b/tests/lib/test-case.vala
@@ -61,6 +61,7 @@ public abstract class Folks.TestCase : Object
{
string[] locations = {
Folks.BuildConf.ABS_TOP_BUILDDIR + "/backends/key-file/.libs/key-file.so",
+ Folks.BuildConf.ABS_TOP_BUILDDIR + "/backends/dummy/.libs/dummy.so",
};
if (Folks.BuildConf.HAVE_EDS)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]