diff options
84 files changed, 3 insertions, 15841 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fa75eacb..4ca978f5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -183,7 +183,7 @@ but then running it against an older version with a different API. EDS exposes its API version in its D-Bus interface, so if the wrong version of EDS is running, folks can’t find it on the bus, which cripples folks’ EDS backend. The same principle applies to other D-Bus services which folks relies on, such -as Telepathy and Tracker. +as Telepathy. There are two ways to fix this: • If you wish to use your desktop’s session bus, re-compile folks against the diff --git a/backends/meson.build b/backends/meson.build index f975ed15..f3557257 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -27,10 +27,6 @@ if telepathy_backend_enabled subdir('telepathy') endif -if tracker_backend_enabled - subdir('tracker') -endif - if eds_backend_enabled subdir('eds') endif diff --git a/backends/tracker/lib/folks-tracker.deps.in b/backends/tracker/lib/folks-tracker.deps.in deleted file mode 100644 index 02948c3b..00000000 --- a/backends/tracker/lib/folks-tracker.deps.in +++ /dev/null @@ -1,4 +0,0 @@ -glib-2.0 -gobject-2.0 -folks -tracker-sparql-@TRACKER_SPARQL_MAJOR@ diff --git a/backends/tracker/lib/folks-tracker.map b/backends/tracker/lib/folks-tracker.map deleted file mode 100644 index 2e20a0f0..00000000 --- a/backends/tracker/lib/folks-tracker.map +++ /dev/null @@ -1,7 +0,0 @@ -{ -global: - TRF_*; - trf_*; -local: - *; -}; diff --git a/backends/tracker/lib/meson.build b/backends/tracker/lib/meson.build deleted file mode 100644 index c0b5f136..00000000 --- a/backends/tracker/lib/meson.build +++ /dev/null @@ -1,96 +0,0 @@ -tracker_backendlib_gir_name = 'FolksTracker-@0@'.format(folks_api_version) - -tracker_backendlib_sources = files( - 'trf-persona-store.vala', - 'trf-persona.vala', - 'trf-util.vala', -) - -tracker_backendlib_sources += configure_file( - input: namespace_vala_in, - output: 'namespace.vala', - configuration: { - 'BACKENDLIB_GIR_NAME': tracker_backendlib_gir_name.split('-')[0], - 'BACKENDLIB_GIR_VERSION': folks_api_version, - 'BACKENDLIB_NAMESPACE': 'Trf', - }, -) - -tracker_backendlib_deps = [ - backend_deps, - tracker_sparql_dep, -] - -# FIXME: we need to set these manually for the valadoc target as long as meson -# doesn't have native support (https://github.com/mesonbuild/meson/issues/894) -tracker_backendlib_doc_deps = [ - '--pkg', tracker_sparql_dep.name(), - '--pkg', 'folks', -] - -tracker_backendlib_vala_flags = [ - common_backendlib_vala_flags, -] - -tracker_backendlib_c_flags = [ - '-include', 'config.h', - '-DBACKEND_NAME="@0@"'.format(tracker_backend_name), - '-DG_LOG_DOMAIN="@0@"'.format(tracker_backend_name), -] - -tracker_backendlib_symbolmap = meson.current_source_dir() / 'folks-@0@.map'.format(tracker_backend_name) -tracker_backendlib_link_flags = cc.get_supported_link_arguments( - '-Wl,--version-script,@0@'.format(tracker_backendlib_symbolmap), -) - -tracker_backendlib = shared_library('folks-@0@'.format(tracker_backend_name), - tracker_backendlib_sources, - dependencies: tracker_backendlib_deps, - vala_args: tracker_backendlib_vala_flags, - c_args: tracker_backendlib_c_flags, - link_args: tracker_backendlib_link_flags, - link_depends: tracker_backendlib_symbolmap, - version: folks_tracker_lib_version, - vala_header: 'folks/folks-@0@.h'.format(dummy_backend_name), - vala_gir: tracker_backendlib_gir_name + '.gir', - install: true, - install_dir: [ true, folks_headers_install_dir, true, true ], -) - -# Also make sure to install the VAPI's .deps file -configure_file( - output: 'folks-tracker.deps', - input: 'folks-tracker.deps.in', - configuration: { 'TRACKER_SPARQL_MAJOR': tracker_sparql_version }, - install_dir: get_option('datadir') / 'vala' / 'vapi', -) - -# FIXME: This comes straight from the Meson docs on how to create/install a -# typelib file for your Vala shared library. However, as mentioned in -# https://github.com/mesonbuild/meson/issues/4481, this is not ideal. -custom_target(tracker_backendlib_gir_name + ' typelib', - command: [ g_ir_compiler, - '--output', '@OUTPUT@', - '--includedir', folks_build_dir, - meson.current_build_dir() / (tracker_backendlib_gir_name + '.gir') - ], - output: tracker_backendlib_gir_name + '.typelib', - depends: tracker_backendlib, - install: true, - install_dir: folks_typelibdir, -) - -tracker_backendlib_dep = declare_dependency( - link_with: tracker_backendlib, - include_directories: include_directories('.'), - dependencies: tracker_sparql_dep, -) - -# Pkg-config file -pkgconfig.generate(tracker_backendlib, - name: 'Folks tracker support library', - description: 'Tracker support library for the Folks meta-contacts library', - filebase: 'folks-@0@'.format(tracker_backend_name), - requires: [ 'folks', glib_dep, gobject_dep, gee_dep, tracker_sparql_dep ], - variables: common_pkgconf_variables, -) diff --git a/backends/tracker/lib/trf-persona-store.vala b/backends/tracker/lib/trf-persona-store.vala deleted file mode 100644 index e099242f..00000000 --- a/backends/tracker/lib/trf-persona-store.vala +++ /dev/null @@ -1,2789 +0,0 @@ -/* - * Copyright (C) 2011 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: - * Travis Reitter <travis.reitter@collabora.co.uk> - * Philip Withnall <philip.withnall@collabora.co.uk> - * Marco Barisione <marco.barisione@collabora.co.uk> - * Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - */ - -using Folks; -using Gee; -using GLib; -using Tracker; -using Tracker.Sparql; - -extern const string BACKEND_NAME; - -internal enum Trf.Fields -{ - TRACKER_ID, - FULL_NAME, - FAMILY_NAME, - GIVEN_NAME, - ADDITIONAL_NAMES, - PREFIXES, - SUFFIXES, - NICKNAME, - BIRTHDAY, - AVATAR_URL, - IM_ADDRESSES, - PHONES, - EMAILS, - URLS, - FAVOURITE, - CONTACT_URN, - ROLES, - NOTE, - GENDER, - POSTAL_ADDRESS, - LOCAL_IDS_PROPERTY -} - -internal enum Trf.AfflInfoFields -{ - IM_TRACKER_ID, - IM_PROTOCOL, - IM_ACCOUNT_ID, - AFFL_TRACKER_ID, - AFFL_ROLE, - AFFL_ORG, - AFFL_TITLE, - AFFL_POBOX, - AFFL_DISTRICT, - AFFL_COUNTY, - AFFL_LOCALITY, - AFFL_POSTALCODE, - AFFL_STREET_ADDRESS, - AFFL_ADDRESS_LOCATION, - AFFL_EXTENDED_ADDRESS, - AFFL_COUNTRY, - AFFL_REGION, - AFFL_EMAIL, - AFFL_PHONE, - AFFL_WEBSITE, - AFFL_BLOG, - AFFL_URL, - IM_NICKNAME -} - -internal enum Trf.PostalAddressFields -{ - TRACKER_ID, - POBOX, - DISTRICT, - COUNTY, - LOCALITY, - POSTALCODE, - STREET_ADDRESS, - ADDRESS_LOCATION, - EXTENDED_ADDRESS, - COUNTRY, - REGION -} - -internal enum Trf.UrlsFields -{ - TRACKER_ID, - BLOG, - WEBSITE, - URL -} - -internal enum Trf.RoleFields -{ - TRACKER_ID, - ROLE, - DEPARTMENT, - TITLE -} - -internal enum Trf.IMFields -{ - TRACKER_ID, - PROTO, - ID, - IM_NICKNAME -} - -internal enum Trf.PhoneFields -{ - TRACKER_ID, - PHONE -} - -internal enum Trf.EmailFields -{ - TRACKER_ID, - EMAIL -} - -internal enum Trf.TagFields -{ - TRACKER_ID -} - -private enum Trf.Attrib -{ - EMAILS, - PHONES, - URLS, - IM_ADDRESSES, - POSTAL_ADDRESSES -} - -private const char _REMOVE_ALL_ATTRIBS = 0x01; -private const char _REMOVE_PHONES = 0x02; -private const char _REMOVE_POSTALS = 0x04; -private const char _REMOVE_IM_ADDRS = 0x08; -private const char _REMOVE_EMAILS = 0x10; - -/** - * A persona store. - * It will create {@link Persona}s for each contacts on the main addressbook. - */ -public class Trf.PersonaStore : Folks.PersonaStore -{ - private const string _LOCAL_ID_PROPERTY_NAME = "folks-linking-ids"; - private const string _WSD_PROPERTY_NAME = "folks-linking-ws-addrs"; - private const string _OBJECT_NAME = "org.freedesktop.Tracker1"; - private const string _OBJECT_IFACE = "org.freedesktop.Tracker1.Resources"; - private const string _OBJECT_PATH = "/org/freedesktop/Tracker1/Resources"; - private HashMap<string, Persona> _personas; - private Map<string, Persona> _personas_ro; - private bool _is_prepared = false; - private bool _prepare_pending = false; - private bool _is_quiescent = false; - private const int _default_timeout = 100; - private Resources _resources_object; - private Tracker.Sparql.Connection _connection; - private static Gee.TreeMap<string, string> _urn_prefix = null; - private static Gee.TreeMap<string, int> _prefix_tracker_id = null; - private const string _INITIAL_QUERY = - "SELECT " + - "tracker:id(?_contact) " + - "nco:fullname(?_contact) " + - "nco:nameFamily(?_contact) " + - "nco:nameGiven(?_contact) " + - "nco:nameAdditional(?_contact) " + - "nco:nameHonorificPrefix(?_contact) " + - "nco:nameHonorificSuffix(?_contact) " + - "nco:nickname(?_contact) " + - "nco:birthDate(?_contact) " + - "nie:url(nco:photo(?_contact)) " + - - /* keep synced with Trf.IMFields */ - "(SELECT " + - "GROUP_CONCAT ( " + - " fn:concat(tracker:id(?affl),'\t'," + - " tracker:coalesce(nco:imProtocol(?a),''), " + - "'\t', tracker:coalesce(nco:imID(?a),''), '\t'," + - " tracker:coalesce(nco:imNickname(?a),'')), '\\n') " + - "WHERE { ?_contact nco:hasAffiliation ?affl. " + - " ?affl nco:hasIMAddress ?a } ) " + - - /* keep synced with Trf.PhoneFields */ - "(SELECT " + - "GROUP_CONCAT " + - " (fn:concat(tracker:id(?affl),'\t', " + - " nco:phoneNumber(?aff_number)), " + - "'\\n') " + - "WHERE { ?_contact nco:hasAffiliation ?affl . " + - " ?affl nco:hasPhoneNumber ?aff_number } ) " + - - /* keep synced with Trf.EmailFields */ - "(SELECT " + - "GROUP_CONCAT " + - " (fn:concat(tracker:id(?affl), '\t', " + - " nco:emailAddress(?emailaddress)), " + - "',') " + - "WHERE { ?_contact nco:hasAffiliation ?affl . " + - " ?affl nco:hasEmailAddress ?emailaddress }) " + - - /* keep synced with Trf.UrlsFields */ - " (SELECT " + - "GROUP_CONCAT " + - " (fn:concat(tracker:id(?affl), '\t'," + - " tracker:coalesce(nco:blogUrl(?affl),'')," + - " '\t'," + - " tracker:coalesce(nco:websiteUrl(?affl),'')" + - " , '\t'," + - " tracker:coalesce(nco:url(?affl),''))," + - " '\\n') " + - "WHERE { ?_contact nco:hasAffiliation ?affl } )" + - - /* keep synced with Trf.TagFields */ - "(SELECT " + - "GROUP_CONCAT(tracker:id(?_tag), " + - "',') " + - "WHERE { ?_contact nao:hasTag " + - "?_tag }) " + - - "?_contact " + - - /* keep synced with Trf.RoleFields */ - "(SELECT " + - "GROUP_CONCAT " + - " (fn:concat(tracker:id(?affl), '\t', " + - " tracker:coalesce(nco:role(?affl),''), '\t', " + - " tracker:coalesce(nco:department(?affl),''), '\t', " + - " tracker:coalesce(nco:title(?affl),'')), " + - "'\\n') " + - "WHERE { ?_contact nco:hasAffiliation " + - "?affl }) " + - - "nco:note(?_contact) " + - "tracker:id(nco:gender(?_contact)) " + - - /* keep synced with Trf.PostalAddressFields*/ - "(SELECT " + - "GROUP_CONCAT " + - " (fn:concat(tracker:id(?affl), '\t', " + - " tracker:coalesce(nco:pobox(?postal),'')" + - " , '\t', " + - " tracker:coalesce(nco:district(?postal),'')" + - " , '\t', " + - " tracker:coalesce(nco:county(?postal),'')" + - " , '\t', " + - " tracker:coalesce(nco:locality(?postal),'')" + - " , '\t', " + - " tracker:coalesce(nco:postalcode(?postal),'')" + - " , '\t', " + - " tracker:coalesce(nco:streetAddress(?postal)" + - " ,''), '\t', " + - " tracker:coalesce(nco:addressLocation(?postal)" + - " ,''), '\t', " + - " tracker:coalesce(nco:extendedAddress(?postal)" + - " ,''), '\t', " + - " tracker:coalesce(nco:country(?postal),'')" + - " , '\t', " + - " tracker:coalesce(nco:region(?postal),'')), " + - "'\\n') " + - "WHERE { ?_contact nco:hasAffiliation " + - "?affl . ?affl nco:hasPostalAddress ?postal }) " + - - /* Linking between Trf.Personas */ - "(SELECT " + - "GROUP_CONCAT " + - " (?prop_value, " + - "',') " + - "WHERE { ?_contact nao:hasProperty ?prop . " + - " ?prop nao:propertyName ?prop_name . " + - " ?prop nao:propertyValue ?prop_value . " + - " FILTER (?prop_name = 'folks-linking-ids') } ) " + - - "{ ?_contact a nco:PersonContact . %s } " + - "ORDER BY tracker:id(?_contact) "; - - private const string[] _always_writeable_properties = - { - "alias", - "phone-numbers", - "email-addresses", - "avatar", - "structured-name", - "full-name", - "gender", - "birthday", - "roles", - "notes", - "urls", - "im-addresses", - "is-favourite", - "local-ids", - "web-service-addresses", - null /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */ - }; - - /** - * The type of persona store this is. - * - * See {@link Folks.PersonaStore.type_id}. - */ - public override string type_id { get { return BACKEND_NAME; } } - - /** - * Whether this PersonaStore can add {@link Folks.Persona}s. - * - * See {@link Folks.PersonaStore.can_add_personas}. - * - * @since 0.5.0 - */ - public override MaybeBool can_add_personas - { - get { return MaybeBool.TRUE; } - } - - /** - * Whether this PersonaStore can set the alias of {@link Folks.Persona}s. - * - * See {@link Folks.PersonaStore.can_alias_personas}. - * - * @since 0.5.0 - */ - public override MaybeBool can_alias_personas - { - get { return MaybeBool.FALSE; } - } - - /** - * Whether this PersonaStore can set the groups of {@link Folks.Persona}s. - * - * See {@link Folks.PersonaStore.can_group_personas}. - * - * @since 0.5.0 - */ - public override MaybeBool can_group_personas - { - get { return MaybeBool.FALSE; } - } - - /** - * Whether this PersonaStore can remove {@link Folks.Persona}s. - * - * See {@link Folks.PersonaStore.can_remove_personas}. - * - * @since 0.5.0 - */ - public override MaybeBool can_remove_personas - { - get { return MaybeBool.TRUE; } - } - - /** - * Whether this PersonaStore has been prepared. - * - * See {@link Folks.PersonaStore.is_prepared}. - * - * @since 0.5.0 - */ - public override bool is_prepared - { - get { return this._is_prepared; } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public override string[] always_writeable_properties - { - get { return Trf.PersonaStore._always_writeable_properties; } - } - - /* - * Whether this PersonaStore has reached a quiescent state. - * - * See {@link Folks.PersonaStore.is_quiescent}. - * - * @since 0.6.2 - */ - public override bool is_quiescent - { - get { return this._is_quiescent; } - } - - /** - * The {@link Persona}s exposed by this PersonaStore. - * - * See {@link Folks.PersonaStore.personas}. - */ - public override Map<string, Folks.Persona> personas - { - get { return this._personas_ro; } - } - - /** - * Create a new PersonaStore. - * - * Create a new persona store to store the {@link Persona}s for the contacts - */ - public PersonaStore () - { - Object (id: BACKEND_NAME, - display_name: BACKEND_NAME); - } - - construct - { - this._personas = new HashMap<string, Persona> (); - this._personas_ro = this._personas.read_only_view; - debug ("Initial query : \n%s\n", PersonaStore._INITIAL_QUERY); - this.trust_level = PersonaStoreTrust.FULL; - } - - /** - * Add a new {@link Persona} to the PersonaStore. - * - * Accepted keys for ``details`` are: - * - PersonaStore.detail_key (PersonaDetail.IM_ADDRESSES) - * - PersonaStore.detail_key (PersonaDetail.NICKNAME) - * - PersonaStore.detail_key (PersonaDetail.FULL_NAME) - * - PersonaStore.detail_key (PersonaDetail.IS_FAVOURITE) - * - PersonaStore.detail_key (PersonaDetail.STRUCTURED_NAME) - * - PersonaStore.detail_key (PersonaDetail.AVATAR) - * - PersonaStore.detail_key (PersonaDetail.BIRTHDAY) - * - PersonaStore.detail_key (PersonaDetail.GENDER) - * - PersonaStore.detail_key (PersonaDetail.EMAIL_ADDRESSES) - * - PersonaStore.detail_key (PersonaDetail.IM_ADDRESSES) - * - PersonaStore.detail_key (PersonaDetail.NOTES) - * - PersonaStore.detail_key (PersonaDetail.PHONE_NUMBERS) - * - PersonaStore.detail_key (PersonaDetail.POSTAL_ADDRESSES) - * - PersonaStore.detail_key (PersonaDetail.ROLES) - * - PersonaStore.detail_key (PersonaDetail.URL) - * - PersonaStore.detail_key (PersonaDetail.WEB_SERVICE_ADDRESSES) - * - * See {@link Folks.PersonaStore.add_persona_from_details}. - * - * @throws Folks.PersonaStoreError.INVALID_ARGUMENT if an unrecognised detail - * key was passed in ``details`` - */ - public override async Folks.Persona? add_persona_from_details ( - HashTable<string, Value?> details) throws Folks.PersonaStoreError - { - /* We have to set the avatar after pushing the new persona to Tracker, - * as we need a UID so that we can cache the avatar. */ - LoadableIcon? avatar = null; - - var builder = new Tracker.Sparql.Builder.update (); - builder.insert_open (null); - builder.subject ("_:p"); - builder.predicate ("a"); - builder.object ("nco:PersonContact"); - - foreach (var k in details.get_keys ()) - { - Value? v = details.lookup (k); - if (k == Folks.PersonaStore.detail_key (PersonaDetail.NICKNAME)) - { - builder.subject ("_:p"); - builder.predicate (Trf.OntologyDefs.NCO_NICKNAME); - builder.object_string (v.get_string ()); - } - else if (k == Folks.PersonaStore.detail_key ( - PersonaDetail.FULL_NAME)) - { - builder.subject ("_:p"); - builder.predicate (Trf.OntologyDefs.NCO_FULLNAME); - builder.object_string (v.get_string ()); - } - else if (k == Folks.PersonaStore.detail_key ( - PersonaDetail.STRUCTURED_NAME)) - { - StructuredName sname = (StructuredName) v.get_object (); - builder.subject ("_:p"); - builder.predicate (Trf.OntologyDefs.NCO_FAMILY); - builder.object_string (sname.family_name); - builder.predicate (Trf.OntologyDefs.NCO_GIVEN); - builder.object_string (sname.given_name); - builder.predicate (Trf.OntologyDefs.NCO_ADDITIONAL); - builder.object_string (sname.additional_names); - builder.predicate (Trf.OntologyDefs.NCO_SUFFIX); - builder.object_string (sname.suffixes); - builder.predicate (Trf.OntologyDefs.NCO_PREFIX); - builder.object_string (sname.prefixes); - } - else if (k == Folks.PersonaStore.detail_key ( - PersonaDetail.IS_FAVOURITE)) - { - if (v.get_boolean ()) - { - builder.subject ("_:p"); - builder.predicate (Trf.OntologyDefs.NAO_TAG); - builder.object (Trf.OntologyDefs.NAO_FAVORITE); - } - } - else if (k == Folks.PersonaStore.detail_key (PersonaDetail.AVATAR)) - { - /* Update the avatar which we'll set later (once we have the - * persona's UID) */ - var new_avatar = (LoadableIcon) v.get_object (); - if (new_avatar != null) - { - avatar = new_avatar; - } - } - else if (k == Folks.PersonaStore.detail_key (PersonaDetail.BIRTHDAY)) - { - var birthday = (DateTime) v.get_boxed (); - builder.subject ("_:p"); - builder.predicate (Trf.OntologyDefs.NCO_BIRTHDAY); - TimeVal tv; - birthday.to_timeval (out tv); - builder.object_string (tv.to_iso8601 ()); - } - else if (k == Folks.PersonaStore.detail_key (PersonaDetail.GENDER)) - { - var gender = (Gender) v.get_enum (); - if (gender != Gender.UNSPECIFIED) - { - builder.subject ("_:p"); - builder.predicate (Trf.OntologyDefs.NCO_GENDER); - if (gender == Gender.MALE) - builder.object (Trf.OntologyDefs.NCO_MALE); - else - builder.object (Trf.OntologyDefs.NCO_FEMALE); - } - } - else if (k == Folks.PersonaStore.detail_key ( - PersonaDetail.EMAIL_ADDRESSES)) - { - Set<EmailFieldDetails> email_addresses = - (Set<EmailFieldDetails>) v.get_object (); - yield this._build_update_query_set (builder, email_addresses, - "_:p", Trf.Attrib.EMAILS); - } - else if (k == Folks.PersonaStore.detail_key ( - PersonaDetail.IM_ADDRESSES)) - { - var im_addresses = - (MultiMap<string, ImFieldDetails>) v.get_object (); - - int im_cnt = 0; - foreach (var proto in im_addresses.get_keys ()) - { - var addrs_a = im_addresses.get (proto); - - foreach (var im_fd in addrs_a) - { - var im_affl = "_:im_affl%d".printf (im_cnt); - var im = "_:im%d".printf (im_cnt); - - builder.subject (im); - builder.predicate ("a"); - builder.object (Trf.OntologyDefs.NCO_IMADDRESS); - builder.predicate (Trf.OntologyDefs.NCO_IMID); - builder.object_string (im_fd.value); - builder.predicate (Trf.OntologyDefs.NCO_IMPROTOCOL); - builder.object_string (proto); - - builder.subject (im_affl); - builder.predicate ("a"); - builder.object (Trf.OntologyDefs.NCO_AFFILIATION); - builder.predicate (Trf.OntologyDefs.NCO_HAS_IMADDRESS); - builder.object (im); - - builder.subject ("_:p"); - builder.predicate (Trf.OntologyDefs.NCO_HAS_AFFILIATION); - builder.object (im_affl); - - im_cnt++; - } - } - } - else if (k == Folks.PersonaStore.detail_key (PersonaDetail.NOTES)) - { - var notes = (Gee.Set<NoteFieldDetails>) v.get_object (); - foreach (var n in notes) - { - builder.subject ("_:p"); - builder.predicate (Trf.OntologyDefs.NCO_NOTE); - builder.object_string (n.value); - } - } - else if (k == Folks.PersonaStore.detail_key ( - PersonaDetail.PHONE_NUMBERS)) - { - Set<PhoneFieldDetails> phone_numbers = - (Set<PhoneFieldDetails>) v.get_object (); - yield this._build_update_query_set (builder, phone_numbers, - "_:p", Trf.Attrib.PHONES); - } - else if (k == Folks.PersonaStore.detail_key (PersonaDetail.ROLES)) - { - var roles = (Gee.Set<RoleFieldDetails>) v.get_object (); - - int roles_cnt = 0; - foreach (var role_fd in roles) - { - var role_affl = "_:role_affl%d".printf (roles_cnt); - - builder.subject (role_affl); - builder.predicate ("a"); - builder.object (Trf.OntologyDefs.NCO_AFFILIATION); - builder.predicate (Trf.OntologyDefs.NCO_ROLE); - builder.object_string (role_fd.value.role); - builder.predicate (Trf.OntologyDefs.NCO_TITLE); - builder.object_string (role_fd.value.title); - builder.predicate (Trf.OntologyDefs.NCO_ORG); - builder.object_string (role_fd.value.organisation_name); - - builder.subject ("_:p"); - builder.predicate (Trf.OntologyDefs.NCO_HAS_AFFILIATION); - builder.object (role_affl); - - roles_cnt++; - } - } - else if (k == Folks.PersonaStore.detail_key ( - PersonaDetail.POSTAL_ADDRESSES)) - { - Set<PostalAddressFieldDetails> postal_addresses = - (Set<PostalAddressFieldDetails>) v.get_object (); - - int postal_cnt = 0; - foreach (var pafd in postal_addresses) - { - var pa = pafd.value; - var postal_affl = "_:postal_affl%d".printf (postal_cnt); - var postal = "_:postal%d".printf (postal_cnt); - builder.subject (postal); - builder.predicate ("a"); - builder.object (Trf.OntologyDefs.NCO_POSTAL_ADDRESS); - builder.predicate (Trf.OntologyDefs.NCO_POBOX); - builder.object_string (pa.po_box); - builder.predicate (Trf.OntologyDefs.NCO_LOCALITY); - builder.object_string (pa.locality); - builder.predicate (Trf.OntologyDefs.NCO_POSTALCODE); - builder.object_string (pa.postal_code); - builder.predicate (Trf.OntologyDefs.NCO_STREET_ADDRESS); - builder.object_string (pa.street); - builder.predicate (Trf.OntologyDefs.NCO_EXTENDED_ADDRESS); - builder.object_string (pa.extension); - builder.predicate (Trf.OntologyDefs.NCO_COUNTRY); - builder.object_string (pa.country); - builder.predicate (Trf.OntologyDefs.NCO_REGION); - builder.object_string (pa.region); - - builder.subject (postal_affl); - builder.predicate ("a"); - builder.object (Trf.OntologyDefs.NCO_AFFILIATION); - builder.predicate (Trf.OntologyDefs.NCO_HAS_POSTAL_ADDRESS); - builder.object (postal); - - builder.subject ("_:p"); - builder.predicate (Trf.OntologyDefs.NCO_HAS_AFFILIATION); - builder.object (postal_affl); - - postal_cnt++; - } - } - else if (k == Folks.PersonaStore.detail_key (PersonaDetail.URLS)) - { - Set<UrlFieldDetails> url_fds = - (Set<UrlFieldDetails>) v.get_object (); - - int url_cnt = 0; - foreach (var url_fd in url_fds) - { - var url_affl = "_:url_affl%d".printf (url_cnt); - - builder.subject (url_affl); - builder.predicate ("a"); - builder.object (Trf.OntologyDefs.NCO_AFFILIATION); - builder.predicate (Trf.OntologyDefs.NCO_URL); - builder.object_string (url_fd.value); - - builder.subject ("_:p"); - builder.predicate (Trf.OntologyDefs.NCO_HAS_AFFILIATION); - builder.object (url_affl); - - url_cnt++; - } - } - else if (k == Folks.PersonaStore.detail_key (PersonaDetail.LOCAL_IDS)) - { - var local_ids = (Gee.Set<string>) v.get_object (); - string ids = Trf.PersonaStore.serialize_local_ids (local_ids); - - builder.subject ("_:folks_ids"); - builder.predicate ("a"); - builder.object (Trf.OntologyDefs.NAO_PROPERTY); - builder.predicate (Trf.OntologyDefs.NAO_PROPERTY_NAME); - builder.object_string (Trf.PersonaStore._LOCAL_ID_PROPERTY_NAME); - builder.predicate (Trf.OntologyDefs.NAO_PROPERTY_VALUE); - builder.object_string (ids); - - builder.subject ("_:p"); - builder.predicate (Trf.OntologyDefs.NAO_HAS_PROPERTY); - builder.object ("_:folks_ids"); - } - else if (k == - Folks.PersonaStore.detail_key ( - PersonaDetail.WEB_SERVICE_ADDRESSES)) - { - var ws_obj = - (MultiMap<string, WebServiceFieldDetails>) v.get_object (); - - var ws_addrs = Trf.PersonaStore.serialize_web_services (ws_obj); - - builder.subject ("_:folks_ws_ids"); - builder.predicate ("a"); - builder.object (Trf.OntologyDefs.NAO_PROPERTY); - builder.predicate (Trf.OntologyDefs.NAO_PROPERTY_NAME); - builder.object_string (Trf.PersonaStore._WSD_PROPERTY_NAME); - builder.predicate (Trf.OntologyDefs.NAO_PROPERTY_VALUE); - builder.object_string (ws_addrs); - - builder.subject ("_:p"); - builder.predicate (Trf.OntologyDefs.NAO_HAS_PROPERTY); - builder.object ("_:folks_ws_ids"); - } - else - { - throw new PersonaStoreError.INVALID_ARGUMENT ( - /* Translators: the first parameter is the unknown key that - * was received with the details params, and the second - * identifies the persona store. */ - _("Unrecognized parameter ‘%s’ passed to persona store ‘%s’."), - k, this.id); - } - } - builder.insert_close (); - - Trf.Persona ret = null; - string? contact_urn = yield this._insert_persona (builder.result, - "p"); - if (contact_urn != null) - { - string filter = " FILTER(?_contact = <%s>) ".printf (contact_urn); - string query = PersonaStore._INITIAL_QUERY.printf (filter); - var ret_personas = yield this._do_add_contacts (query); - - /* Return the first persona we find in the set */ - foreach (var p in ret_personas) - { - ret = p; - break; - } - } - else - { - debug ("Failed to inserting the new persona into Tracker."); - } - - // Set the avatar on the persona now that we know the persona's UID - if (ret != null && avatar != null) - { - yield this._set_avatar (ret, avatar); - } - - return ret; - } - - /** - * Returns "service1:addr1,addr2;service2:addr3,.." - * - * @since 0.5.1 - */ - public static string serialize_web_services ( - MultiMap<string, WebServiceFieldDetails> ws_obj) - { - var str = ""; - - foreach (var service in ws_obj.get_keys ()) - { - if (str != "") - { - str += ";"; - } - - str += service + ":"; - - var ws_fds = ws_obj.get (service); - bool first = true; - foreach (var ws_fd in ws_fds) - { - if (first == false) - { - str += ","; - } - - str += ws_fd.value; - first = false; - } - } - - return str; - } - - /** - * Transforms "service1:addr1,addr2;service2:addr3,.." to - * into a HashMultiMap<string, string> - * - * @since 0.5.1 - */ - public static - MultiMap<string, WebServiceFieldDetails> unserialize_web_services ( - string ws_addrs) - { - var ret = new HashMultiMap<string, WebServiceFieldDetails> ( - null, null, AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - - var services = ws_addrs.split (";"); - foreach (var service_line in services) - { - var service_t = service_line.split (":"); - var service_name = service_t[0]; - var addrs = service_t[1].split (","); - - foreach (var a in addrs) - { - ret.set (service_name, new WebServiceFieldDetails (a)); - } - } - - return ret; - } - - /** - * Transform Set<string> to "id1,id2,.." - * - * @since 0.5.1 - */ - public static string serialize_local_ids (Set<string> local_ids) - { - var str = ""; - - foreach (var id in local_ids) - { - if (str != "") - { - str += ","; - } - str += id; - } - - return str; - } - - /** - * Transform from id1,id2,.. to HashSet<string> - * - * @since 0.5.1 - */ - public static Set<string> unserialize_local_ids (string local_ids) - { - /* The documentation explicitly says this is a HashSet, so we shouldn't - * switch it to SmallSet. Add a parallel API and update callers if - * this turns out to be a hot path. */ - var ids = new HashSet<string> (); - - if (local_ids != "") - { - string[] ids_a = local_ids.split (","); - foreach (var id in ids_a) - { - ids.add (id); - } - } - - return ids; - } - - /** - * Remove a {@link Persona} from the PersonaStore. - * - * See {@link Folks.PersonaStore.remove_persona}. This method is not safe to - * call multiple times concurrently on the same persona. - * - * @throws Folks.PersonaStoreError currently unused - */ - public override async void remove_persona (Folks.Persona persona) - throws Folks.PersonaStoreError - { - var urn = yield this._remove_attributes_from_persona (persona, - _REMOVE_ALL_ATTRIBS); - - /* Finally: remove literal properties */ - var q = " DELETE { " + - " %s ?p ?o " + - "} " + - "WHERE { " + - " %s ?p ?o " + - "} "; - yield this._tracker_update (q.printf (urn, urn), "remove_persona"); - } - - /* This method is not safe to call multiple times concurrently, since one call - * could be part-way through removing attributes of the URN while a subsequent - * call is attempting to retrieve the URN. */ - private async string _remove_attributes_from_persona (Folks.Persona persona, - char remove_flag) - { - var urn = yield this._urn_from_persona (persona); - yield this._remove_attributes (urn, remove_flag); - return urn; - } - - /* This method is safe to call multiple times concurrently. */ - private async void _build_update_query_set ( - Tracker.Sparql.Builder builder, - Set<AbstractFieldDetails<string>> properties, - string contact_var, - Trf.Attrib attrib) - { - string? affl_var = null; - string? obj_var = null; - unowned string? related_attrib = null; - unowned string? related_prop = null; - unowned string? related_connection = null; - - switch (attrib) - { - case Trf.Attrib.PHONES: - related_attrib = Trf.OntologyDefs.NCO_PHONE; - related_prop = Trf.OntologyDefs.NCO_PHONE_PROP; - related_connection = Trf.OntologyDefs.NCO_HAS_PHONE; - affl_var = "_:phone_affl%d"; - obj_var = "_:phone%d"; - break; - case Trf.Attrib.EMAILS: - related_attrib = Trf.OntologyDefs.NCO_EMAIL; - related_prop = Trf.OntologyDefs.NCO_EMAIL_PROP; - related_connection = Trf.OntologyDefs.NCO_HAS_EMAIL; - affl_var = "_:email_affl%d"; - obj_var = "_:email%d"; - break; - } - - int cnt = 0; - foreach (var p in properties) - { - var affl = affl_var.printf (cnt); - var obj = yield this._urn_from_property ( - related_attrib, related_prop, p.value); - - if (obj == "") - { - obj = obj_var.printf (cnt); - builder.subject (obj); - builder.predicate ("a"); - builder.object (related_attrib); - builder.predicate (related_prop); - builder.object_string (p.value); - } - - builder.subject (affl); - builder.predicate ("a"); - builder.object (Trf.OntologyDefs.NCO_AFFILIATION); - builder.predicate (related_connection); - builder.object (obj); - - builder.subject (contact_var); - builder.predicate (Trf.OntologyDefs.NCO_HAS_AFFILIATION); - builder.object (affl); - - cnt++; - } - } - - /* - * Garbage collecting related resources: - * - for each related resource we (recursively) - * check to if the deleted nco:Person - * is the only one holding a link, if so we - * remove the resource. - * - * This method is not safe to call multiple times concurrently, since the - * deletions will race. - */ - private async void _remove_attributes (string urn, char remove_flag) - { - SmallSet<string> affiliations = - yield this._affiliations_from_persona (urn); - - foreach (var affl in affiliations) - { - bool got_attrib = false; - - if ((remove_flag & _REMOVE_ALL_ATTRIBS) == - _REMOVE_ALL_ATTRIBS || - (remove_flag & _REMOVE_PHONES) == _REMOVE_PHONES) - { - SmallSet<string> phones = - yield this._phones_from_affiliation (affl); - - foreach (var phone in phones) - { - got_attrib = true; - yield this._delete_resource (phone); - } - } - - if ((remove_flag & _REMOVE_ALL_ATTRIBS) == - _REMOVE_ALL_ATTRIBS || - (remove_flag & _REMOVE_POSTALS) == _REMOVE_POSTALS) - { - SmallSet<string> postals = - yield this._postals_from_affiliation (affl); - foreach (var postal in postals) - { - got_attrib = true; - yield this._delete_resource (postal); - } - } - - if ((remove_flag & _REMOVE_ALL_ATTRIBS) == - _REMOVE_ALL_ATTRIBS || - (remove_flag & _REMOVE_IM_ADDRS) == _REMOVE_IM_ADDRS) - { - SmallSet<string> im_addrs = - yield this._imaddrs_from_affiliation (affl); - foreach (var im_addr in im_addrs) - { - got_attrib = true; - yield this._delete_resource (im_addr); - } - } - - if ((remove_flag & _REMOVE_ALL_ATTRIBS) == - _REMOVE_ALL_ATTRIBS || - (remove_flag & _REMOVE_EMAILS) == _REMOVE_EMAILS) - { - SmallSet<string> emails = - yield this._emails_from_affiliation (affl); - foreach (var email in emails) - { - got_attrib = true; - yield yield this._delete_resource (email); - } - } - - if (got_attrib || - (remove_flag & _REMOVE_ALL_ATTRIBS) == _REMOVE_ALL_ATTRIBS) - yield this._delete_resource (affl); - } - } - - /** - * Prepare the PersonaStore for use. - * - * TODO: we should throw different errors depending on what went wrong - * when we were trying to setup the PersonaStore. - * - * See {@link Folks.PersonaStore.prepare}. - * - * @throws Folks.PersonaStoreError.INVALID_ARGUMENT if connecting to D-Bus - * failed - */ - public override async void prepare () throws GLib.Error - { - Internal.profiling_start ("preparing Trf.PersonaStore (ID: %s)", this.id); - - if (this._is_prepared || this._prepare_pending) - { - return; - } - - try - { - this._prepare_pending = true; - - try - { - this._connection = - yield Tracker.Sparql.Connection.get_async (); - - Internal.profiling_point ("got connection in " + - "Trf.PersonaStore (ID: %s)", this.id); - - yield this._build_predicates_table (); - - Internal.profiling_point ("build predicates table in " + - "Trf.PersonaStore (ID: %s)", this.id); - - yield this._do_add_contacts (PersonaStore._INITIAL_QUERY.printf ("")); - - Internal.profiling_point ("added contacts in " + - "Trf.PersonaStore (ID: %s)", this.id); - - /* Don't add a match rule for all signals from Tracker but - * only for GraphUpdated with the specific class we need. We - * don't want to be woken up for irrelevant updates on the - * graph. - */ - this._resources_object = yield GLib.Bus.get_proxy<Resources> ( - BusType.SESSION, - PersonaStore._OBJECT_NAME, - PersonaStore._OBJECT_PATH, - DBusProxyFlags.DO_NOT_CONNECT_SIGNALS | - DBusProxyFlags.DO_NOT_LOAD_PROPERTIES); - this._resources_object.g_connection.signal_subscribe - (PersonaStore._OBJECT_NAME, PersonaStore._OBJECT_IFACE, - "GraphUpdated", PersonaStore._OBJECT_PATH, - Trf.OntologyDefs.PERSON_CLASS, GLib.DBusSignalFlags.NONE, - this._graph_updated_cb); - - Internal.profiling_point ("got resources proxy in " + - "Trf.PersonaStore (ID: %s)", this.id); - - this._is_prepared = true; - this.notify_property ("is-prepared"); - - /* By this time (due to having done the INITIAL_QUERY above) - * we have already reached a quiescent state. */ - this._is_quiescent = true; - this.notify_property ("is-quiescent"); - } - catch (GLib.IOError e1) - { - /* Ignore errors from the bus disappearing. */ - if (!(e1 is IOError.CLOSED)) - { - warning ("Could not connect to D-Bus service: %s", - e1.message); - } - - this.removed (); - throw new PersonaStoreError.INVALID_ARGUMENT (e1.message); - } - catch (Tracker.Sparql.Error e2) - { - warning ("Error fetching SPARQL connection handler: %s", - e2.message); - this.removed (); - throw new PersonaStoreError.INVALID_ARGUMENT (e2.message); - } - catch (GLib.DBusError e3) - { - warning ("Could not connect to D-Bus service: %s", - e3.message); - this.removed (); - throw new PersonaStoreError.INVALID_ARGUMENT (e3.message); - } - } - finally - { - this._prepare_pending = false; - } - - Internal.profiling_end ("preparing Trf.PersonaStore (ID: %s)", this.id); - } - - public int get_favorite_id () - { - return PersonaStore._prefix_tracker_id.get - (Trf.OntologyDefs.NAO_FAVORITE); - } - - public int get_gender_male_id () - { - return PersonaStore._prefix_tracker_id.get - (Trf.OntologyDefs.NCO_MALE); - } - - public int get_gender_female_id () - { - return PersonaStore._prefix_tracker_id.get - (Trf.OntologyDefs.NCO_FEMALE); - } - - /* This is safe to call multiple times concurrently. */ - private async void _build_predicates_table () - { - if (PersonaStore._prefix_tracker_id != null) - { - return; - } - - this._build_urn_prefix_table (); - - PersonaStore._prefix_tracker_id = new Gee.TreeMap<string, int> (); - - string query = "SELECT "; - foreach (var urn_t in PersonaStore._urn_prefix.keys) - { - query += " tracker:id(" + urn_t + ")"; - } - query += " WHERE {} "; - - try - { - Sparql.Cursor cursor = yield this._connection.query_async (query); - - while (cursor.next ()) - { - int i=0; - foreach (var urn in PersonaStore._urn_prefix.keys) - { - var tracker_id = (int) cursor.get_integer (i); - var prefix = PersonaStore._urn_prefix.get (urn).dup (); - PersonaStore._prefix_tracker_id.set (prefix, tracker_id); - i++; - } - } - } - catch (Tracker.Sparql.Error e1) - { - warning ("Couldn't build predicates table: %s %s", query, e1.message); - } - catch (GLib.Error e2) - { - warning ("Couldn't build predicates table: %s %s", query, e2.message); - } - } - - private void _build_urn_prefix_table () - { - if (PersonaStore._urn_prefix != null) - { - return; - } - PersonaStore._urn_prefix = new Gee.TreeMap<string, string> (); - PersonaStore._urn_prefix.set (Trf.OntologyDefs.NCO_URL_PREFIX + "nco#fullname>", - Trf.OntologyDefs.NCO_FULLNAME); - PersonaStore._urn_prefix.set (Trf.OntologyDefs.NCO_URL_PREFIX + "nco#nameFamily>", - Trf.OntologyDefs.NCO_FAMILY); - PersonaStore._urn_prefix.set (Trf.OntologyDefs.NCO_URL_PREFIX + "nco#nameGiven>", - Trf.OntologyDefs.NCO_GIVEN); - PersonaStore._urn_prefix.set ( - Trf.OntologyDefs.NCO_URL_PREFIX + "nco#nameAdditional>", - Trf.OntologyDefs.NCO_ADDITIONAL); - PersonaStore._urn_prefix.set ( - Trf.OntologyDefs.NCO_URL_PREFIX + "nco#nameHonorificSuffix>", - Trf.OntologyDefs.NCO_SUFFIX); - PersonaStore._urn_prefix.set ( - Trf.OntologyDefs.NCO_URL_PREFIX + "nco#nameHonorificPrefix>", - Trf.OntologyDefs.NCO_PREFIX); - PersonaStore._urn_prefix.set (Trf.OntologyDefs.NCO_URL_PREFIX + "nco#nickname>", - Trf.OntologyDefs.NCO_NICKNAME); - PersonaStore._urn_prefix.set ( - Trf.OntologyDefs.RDF_URL_PREFIX + "22-rdf-syntax-ns#type>", - Trf.OntologyDefs.RDF_TYPE); - PersonaStore._urn_prefix.set ( - Trf.OntologyDefs.NCO_URL_PREFIX + "nco#PersonContact>", - Trf.OntologyDefs.NCO_PERSON); - PersonaStore._urn_prefix.set (Trf.OntologyDefs.NCO_URL_PREFIX + "nco#websiteUrl>", - Trf.OntologyDefs.NCO_WEBSITE); - PersonaStore._urn_prefix.set (Trf.OntologyDefs.NCO_URL_PREFIX + "nco#blogUrl>", - Trf.OntologyDefs.NCO_BLOG); - PersonaStore._urn_prefix.set (Trf.OntologyDefs.NCO_URL_PREFIX + "nco#url>", - Trf.OntologyDefs.NCO_URL); - PersonaStore._urn_prefix.set ( - Trf.OntologyDefs.NAO_URL_PREFIX + "nao#predefined-tag-favorite>", - Trf.OntologyDefs.NAO_FAVORITE); - PersonaStore._urn_prefix.set (Trf.OntologyDefs.NAO_URL_PREFIX + "nao#hasTag>", - Trf.OntologyDefs.NAO_TAG); - PersonaStore._urn_prefix.set ( - Trf.OntologyDefs.NCO_URL_PREFIX + "nco#hasEmailAddress>", - Trf.OntologyDefs.NCO_HAS_EMAIL); - PersonaStore._urn_prefix.set ( - Trf.OntologyDefs.NCO_URL_PREFIX + "nco#hasPhoneNumber>", - Trf.OntologyDefs.NCO_HAS_PHONE); - PersonaStore._urn_prefix.set ( - Trf.OntologyDefs.NCO_URL_PREFIX + "nco#hasAffiliation>", - Trf.OntologyDefs.NCO_HAS_AFFILIATION); - PersonaStore._urn_prefix.set (Trf.OntologyDefs.NCO_URL_PREFIX + "nco#birthDate>", - Trf.OntologyDefs.NCO_BIRTHDAY); - PersonaStore._urn_prefix.set (Trf.OntologyDefs.NCO_URL_PREFIX + "nco#note>", - Trf.OntologyDefs.NCO_NOTE); - PersonaStore._urn_prefix.set (Trf.OntologyDefs.NCO_URL_PREFIX + "nco#gender>", - Trf.OntologyDefs.NCO_GENDER); - PersonaStore._urn_prefix.set ( - Trf.OntologyDefs.NCO_URL_PREFIX + "nco#gender-male>", - Trf.OntologyDefs.NCO_MALE); - PersonaStore._urn_prefix.set ( - Trf.OntologyDefs.NCO_URL_PREFIX + "nco#gender-female>", - Trf.OntologyDefs.NCO_FEMALE); - PersonaStore._urn_prefix.set (Trf.OntologyDefs.NCO_URL_PREFIX + "nco#photo>", - Trf.OntologyDefs.NCO_PHOTO); - PersonaStore._urn_prefix.set ( - Trf.OntologyDefs.NAO_URL_PREFIX + "nao#hasProperty>", - Trf.OntologyDefs.NAO_PROPERTY); - } - - private void _graph_updated_cb (DBusConnection connection, - string sender_name, string object_path, string interface_name, - string signal_name, Variant parameters) - { - string class_name = ""; - VariantIter iter_del = null; - VariantIter iter_ins = null; - - parameters.get("(sa(iiii)a(iiii))", &class_name, &iter_del, &iter_ins); - - if (class_name != Trf.OntologyDefs.PERSON_CLASS) - { - return; - } - - this._handle_events.begin ((owned) iter_del, (owned) iter_ins); - } - - private async void _handle_events - (owned VariantIter iter_del, owned VariantIter iter_ins) - { - yield this._handle_delete_events ((owned) iter_del); - yield this._handle_insert_events ((owned) iter_ins); - } - - private async void _handle_delete_events (owned VariantIter iter_del) - { - var removed_personas = new HashSet<Persona> (); - var nco_person_id = - PersonaStore._prefix_tracker_id.get (Trf.OntologyDefs.NCO_PERSON); - var rdf_type_id = PersonaStore._prefix_tracker_id.get (Trf.OntologyDefs.RDF_TYPE); - Event e = Event (); - - while (iter_del.next - ("(iiii)", &e.graph_id, &e.subject_id, &e.pred_id, &e.object_id)) - { - var p_id = Trf.Persona.build_iid (this.id, e.subject_id.to_string ()); - if (e.pred_id == rdf_type_id && - e.object_id == nco_person_id) - { - var removed_p = this._personas.get (p_id); - if (removed_p != null) - { - removed_personas.add (removed_p); - _personas.unset (removed_p.iid); - } - } - else - { - var persona = this._personas.get (p_id); - if (persona != null) - { - yield this._do_update (persona, e, false); - } - } - } - - if (removed_personas.size > 0) - { - this._emit_personas_changed (null, removed_personas); - } - } - - private async void _handle_insert_events (owned VariantIter iter_ins) - { - var added_personas = new HashSet<Persona> (); - Event e = Event (); - - while (iter_ins.next - ("(iiii)", &e.graph_id, &e.subject_id, &e.pred_id, &e.object_id)) - { - var subject_tracker_id = e.subject_id.to_string (); - var p_id = Trf.Persona.build_iid (this.id, subject_tracker_id); - Trf.Persona persona; - persona = this._personas.get (p_id); - if (persona == null) - { - persona = new Trf.Persona (this, subject_tracker_id); - this._personas.set (persona.iid, persona); - added_personas.add (persona); - } - yield this._do_update (persona, e); - } - - if (added_personas.size > 0) - { - this._emit_personas_changed (added_personas, null); - } - } - - private async HashSet<Persona> _do_add_contacts (string query) - { - var added_personas = new HashSet<Persona> (); - - try { - Sparql.Cursor cursor = yield this._connection.query_async (query); - - while (cursor.next ()) - { - int tracker_id = - (int) cursor.get_integer (Trf.Fields.TRACKER_ID); - var p_id = - Trf.Persona.build_iid (this.id, tracker_id.to_string ()); - if (this._personas.get (p_id) == null) - { - var persona = new Trf.Persona (this, - tracker_id.to_string (), cursor); - this._personas.set (persona.iid, persona); - added_personas.add (persona); - } - } - - if (added_personas.size > 0) - { - this._emit_personas_changed (added_personas, null); - } - } catch (GLib.Error e) { - warning ("Couldn't perform queries: %s %s", query, e.message); - } - - return added_personas; - } - - /* This method is not safe to call multiple times concurrently on the same - * persona, since the queries and updates will race. */ - private async void _do_update (Persona p, Event e, bool adding = true) - { - if (e.pred_id == - PersonaStore._prefix_tracker_id.get (Trf.OntologyDefs.NCO_FULLNAME)) - { - string fullname = ""; - if (adding) - { - fullname = - yield this._get_property (e.subject_id, - Trf.OntologyDefs.NCO_FULLNAME); - } - p._update_full_name (fullname); - } - else if (e.pred_id == - PersonaStore._prefix_tracker_id.get (Trf.OntologyDefs.NCO_NICKNAME)) - { - string nickname = ""; - if (adding) - { - nickname = - yield this._get_property ( - e.subject_id, Trf.OntologyDefs.NCO_NICKNAME); - } - p._update_nickname (nickname); - } - else if (e.pred_id == - PersonaStore._prefix_tracker_id.get (Trf.OntologyDefs.NCO_FAMILY)) - { - string family_name = ""; - if (adding) - { - family_name = yield this._get_property (e.subject_id, - Trf.OntologyDefs.NCO_FAMILY); - } - p._update_family_name (family_name); - } - else if (e.pred_id == - PersonaStore._prefix_tracker_id.get (Trf.OntologyDefs.NCO_GIVEN)) - { - string given_name = ""; - if (adding) - { - given_name = yield this._get_property ( - e.subject_id, Trf.OntologyDefs.NCO_GIVEN); - } - p._update_given_name (given_name); - } - else if (e.pred_id == - PersonaStore._prefix_tracker_id.get (Trf.OntologyDefs.NCO_ADDITIONAL)) - { - string additional_name = ""; - if (adding) - { - additional_name = yield this._get_property - (e.subject_id, Trf.OntologyDefs.NCO_ADDITIONAL); - } - p._update_additional_names (additional_name); - } - else if (e.pred_id == PersonaStore._prefix_tracker_id.get - (Trf.OntologyDefs.NCO_SUFFIX)) - { - string suffix_name = ""; - if (adding) - { - suffix_name = yield this._get_property - (e.subject_id, Trf.OntologyDefs.NCO_SUFFIX); - } - p._update_suffixes (suffix_name); - } - else if (e.pred_id == PersonaStore._prefix_tracker_id.get - (Trf.OntologyDefs.NCO_PREFIX)) - { - string prefix_name = ""; - if (adding) - { - prefix_name = yield this._get_property - (e.subject_id, Trf.OntologyDefs.NCO_PREFIX); - } - p._update_prefixes (prefix_name); - } - else if (e.pred_id == PersonaStore._prefix_tracker_id.get - (Trf.OntologyDefs.NAO_TAG)) - { - if (e.object_id == this.get_favorite_id ()) - { - if (adding) - { - p._set_favourite (true); - } - else - { - p._set_favourite (false); - } - } - } - else if (e.pred_id == PersonaStore._prefix_tracker_id.get - (Trf.OntologyDefs.NCO_HAS_EMAIL)) - { - if (adding) - { - var email = yield this._get_property ( - e.object_id, - Trf.OntologyDefs.NCO_EMAIL_PROP, - Trf.OntologyDefs.NCO_EMAIL); - p._add_email (email, e.object_id.to_string ()); - } - else - { - p._remove_email (e.object_id.to_string ()); - } - } - else if (e.pred_id == PersonaStore._prefix_tracker_id.get - (Trf.OntologyDefs.NCO_HAS_PHONE)) - { - if (adding) - { - var phone = yield this._get_property ( - e.object_id, Trf.OntologyDefs.NCO_PHONE_PROP, - Trf.OntologyDefs.NCO_PHONE); - p._add_phone (phone, e.object_id.to_string ()); - } - else - { - p._remove_phone (e.object_id.to_string ()); - } - } - else if (e.pred_id == PersonaStore._prefix_tracker_id.get - (Trf.OntologyDefs.NCO_HAS_AFFILIATION)) - { - if (adding) - { - var affl_info = - yield this._get_affl_info (e.subject_id.to_string (), - e.object_id.to_string ()); - - debug ("affl_info : %s", affl_info.to_string ()); - - if (affl_info.im_tracker_id != null) - { - p._update_nickname (affl_info.im_nickname); - if (affl_info.im_proto != null) - p._add_im_address (affl_info.affl_tracker_id, - affl_info.im_proto, affl_info.im_account_id); - } - - if (affl_info.affl_tracker_id != null) - { - if (affl_info.title != null || - affl_info.org != null) - { - p._add_role (affl_info.affl_tracker_id, affl_info.role, - affl_info.title, affl_info.org); - } - } - - if (affl_info.postal_address_fd != null) - p._add_postal_address (affl_info.postal_address_fd); - - if (affl_info.phone != null) - p._add_phone (affl_info.phone, e.object_id.to_string ()); - - if (affl_info.email != null) - p._add_email (affl_info.email, e.object_id.to_string ()); - - if (affl_info.website != null) - p._add_url (affl_info.website, - affl_info.affl_tracker_id, - UrlFieldDetails.PARAM_TYPE_HOME_PAGE); - - if (affl_info.blog != null) - p._add_url (affl_info.blog, - affl_info.affl_tracker_id, UrlFieldDetails.PARAM_TYPE_BLOG); - - if (affl_info.url != null) - p._add_url (affl_info.url, - affl_info.affl_tracker_id, null); - } - else - { - p._remove_im_address (e.object_id.to_string ()); - p._remove_role (e.object_id.to_string ()); - p._remove_postal_address (e.object_id.to_string ()); - p._remove_phone (e.object_id.to_string ()); - p._remove_email (e.object_id.to_string ()); - p._remove_url (e.object_id.to_string ()); - } - } - else if (e.pred_id == PersonaStore._prefix_tracker_id.get - (Trf.OntologyDefs.NCO_BIRTHDAY)) - { - string bday = ""; - if (adding) - { - bday = yield this._get_property ( - e.subject_id, Trf.OntologyDefs.NCO_BIRTHDAY); - } - p._set_birthday (bday); - } - else if (e.pred_id == PersonaStore._prefix_tracker_id.get - (Trf.OntologyDefs.NCO_NOTE)) - { - string note = ""; - if (adding) - { - note = yield this._get_property ( - e.subject_id, Trf.OntologyDefs.NCO_NOTE); - } - p._set_note (note); - } - else if (e.pred_id == PersonaStore._prefix_tracker_id.get - (Trf.OntologyDefs.NCO_GENDER)) - { - if (adding) - { - p._set_gender (e.object_id); - } - else - { - p._set_gender (0); - } - } - else if (e.pred_id == PersonaStore._prefix_tracker_id.get - (Trf.OntologyDefs.NCO_PHOTO)) - { - string avatar_url = ""; - if (adding) - { - avatar_url = yield this._get_property (e.object_id, - Trf.OntologyDefs.NIE_URL, Trf.OntologyDefs.NFO_IMAGE); - } - p._set_avatar_from_uri (avatar_url); - } - else if (e.pred_id == PersonaStore._prefix_tracker_id.get - (Trf.OntologyDefs.NAO_PROPERTY)) - { - /* WARNING: - * nao:Properties shouldn't be abused since we have to reset - * them all when there is a DELETE. Plus, the Tracker devs - * say nao:Property is by nature slow. */ - if (adding) - { - string[] prop_info = yield this._get_nao_property_by_prop_id ( - e.object_id); - if (prop_info[0] == Trf.PersonaStore._LOCAL_ID_PROPERTY_NAME) - { - p._set_local_ids (prop_info[1]); - } - else if (prop_info[0] == Trf.PersonaStore._WSD_PROPERTY_NAME) - { - p._set_web_service_addrs (prop_info[1]); - } - } - else - { - string local_ids = yield this._get_nao_property_by_person_id ( - e.subject_id, - Trf.PersonaStore._LOCAL_ID_PROPERTY_NAME); - string ws_addrs = yield this._get_nao_property_by_person_id ( - e.subject_id, - Trf.PersonaStore._WSD_PROPERTY_NAME); - - p._set_local_ids (local_ids); - p._set_web_service_addrs (ws_addrs); - } - } - } - - /* This method is safe to call multiple times concurrently. */ - private async string _get_property - (int subject_tracker_id, string property, - string subject_type = Trf.OntologyDefs.NCO_PERSON) - { - const string query_template = - "SELECT ?property WHERE" + - " { ?p a %s ; " + - " %s ?property " + - " . FILTER(tracker:id(?p) = %d ) }"; - - string query = query_template.printf (subject_type, - property, subject_tracker_id); - return yield this._single_value_query (query); - } - - /* This method is safe to call multiple times concurrently. */ - private async string _get_nao_property_by_person_id (int nco_person_id, - string prop_name) - { - const string query_t = "SELECT " + - " ?prop_value " + - "WHERE { " + - " ?p a " + Trf.OntologyDefs.NCO_PERSON + " ; " + - Trf.OntologyDefs.NAO_HAS_PROPERTY + " ?prop . " + - " ?prop " + Trf.OntologyDefs.NAO_PROPERTY_NAME + " ?prop_name . " + - " ?prop " + Trf.OntologyDefs.NAO_PROPERTY_VALUE + " ?prop_value . " + - " FILTER (tracker:id(?p) = %d && ?prop_name = '%s') } "; - - string query = query_t.printf(nco_person_id, prop_name); - return yield this._single_value_query (query); - } - - /* This method is safe to call multiple times concurrently. */ - private async string[] _get_nao_property_by_prop_id (int nao_prop_id) - { - const string query_t = "SELECT " + - " fn:concat(?prop_name, '\t', ?prop_value)" + - "WHERE { " + - " ?p a " + Trf.OntologyDefs.NCO_PERSON + " ; " + - Trf.OntologyDefs.NAO_HAS_PROPERTY + " ?prop . " + - " ?prop " + Trf.OntologyDefs.NAO_PROPERTY_NAME + " ?prop_name . " + - " ?prop " + Trf.OntologyDefs.NAO_PROPERTY_VALUE + " ?prop_value . " + - " FILTER (tracker:id(?prop) = %d) } "; - - string query = query_t.printf(nao_prop_id); - var ret = yield this._single_value_query (query); - return ret.split ("\t"); - } - - /* - * This should be kept in sync with Trf.AfflInfoFields - * - * This method is safe to call multiple times concurrently. - */ - private async Trf.AfflInfo _get_affl_info ( - string person_id, string affiliation_id) - { - Trf.AfflInfo affl_info = new Trf.AfflInfo (); - const string query_template = - "SELECT " + - "tracker:id(?i) " + - Trf.OntologyDefs.NCO_IMPROTOCOL + "(?i) " + - Trf.OntologyDefs.NCO_IMID + "(?i) " + - "tracker:id(?a) " + - Trf.OntologyDefs.NCO_ROLE + "(?a) " + - Trf.OntologyDefs.NCO_ORG + "(?a) " + - Trf.OntologyDefs.NCO_TITLE + "(?a) " + - Trf.OntologyDefs.NCO_POBOX + "(?postal) " + - Trf.OntologyDefs.NCO_DISTRICT + "(?postal) " + - Trf.OntologyDefs.NCO_COUNTY + "(?postal) " + - Trf.OntologyDefs.NCO_LOCALITY + "(?postal) " + - Trf.OntologyDefs.NCO_POSTALCODE + "(?postal) " + - Trf.OntologyDefs.NCO_STREET_ADDRESS + "(?postal) " + - Trf.OntologyDefs.NCO_ADDRESS_LOCATION + "(?postal) " + - Trf.OntologyDefs.NCO_EXTENDED_ADDRESS + "(?postal) " + - Trf.OntologyDefs.NCO_COUNTRY + "(?postal) " + - Trf.OntologyDefs.NCO_REGION + "(?postal) " + - Trf.OntologyDefs.NCO_EMAIL_PROP + "(?e) " + - Trf.OntologyDefs.NCO_PHONE_PROP + "(?number) " + - Trf.OntologyDefs.NCO_WEBSITE + "(?a) " + - Trf.OntologyDefs.NCO_BLOG + "(?a) " + - Trf.OntologyDefs.NCO_URL + "(?a) " + - Trf.OntologyDefs.NCO_IM_NICKNAME + "(?i) " + - "WHERE { "+ - " ?p a " + Trf.OntologyDefs.NCO_PERSON + " ; " + - Trf.OntologyDefs.NCO_HAS_AFFILIATION + " ?a . " + - " OPTIONAL { ?a " + Trf.OntologyDefs.NCO_HAS_IMADDRESS + " ?i } . " + - " OPTIONAL { ?a " + Trf.OntologyDefs.NCO_HAS_POSTAL_ADDRESS + - " ?postal } . " + - " OPTIONAL { ?a " + Trf.OntologyDefs.NCO_HAS_EMAIL + " ?e } . " + - " OPTIONAL { ?a " + Trf.OntologyDefs.NCO_HAS_PHONE + " ?number } " + - " FILTER(tracker:id(?p) = %s" + - " && tracker:id(?a) = %s" + - " ) } "; - - string query = query_template.printf (person_id, affiliation_id); - - debug ("_get_affl_info: %s", query); - - try - { - Sparql.Cursor cursor = yield this._connection.query_async (query); - while (yield cursor.next_async ()) - { - affl_info.im_tracker_id = cursor.get_string - (Trf.AfflInfoFields.IM_TRACKER_ID).dup (); - affl_info.im_proto = cursor.get_string - (Trf.AfflInfoFields.IM_PROTOCOL).dup (); - affl_info.im_account_id = cursor.get_string - (Trf.AfflInfoFields.IM_ACCOUNT_ID).dup (); - affl_info.im_nickname = cursor.get_string - (Trf.AfflInfoFields.IM_NICKNAME).dup (); - - affl_info.affl_tracker_id = cursor.get_string - (Trf.AfflInfoFields.AFFL_TRACKER_ID).dup (); - affl_info.role = cursor.get_string - (Trf.AfflInfoFields.AFFL_ROLE).dup (); - affl_info.org = cursor.get_string - (Trf.AfflInfoFields.AFFL_ORG).dup (); - affl_info.title = cursor.get_string - (Trf.AfflInfoFields.AFFL_TITLE).dup (); - - var po_box = cursor.get_string - (Trf.AfflInfoFields.AFFL_POBOX).dup (); - var extension = cursor.get_string - (Trf.AfflInfoFields.AFFL_EXTENDED_ADDRESS).dup (); - var street = cursor.get_string - (Trf.AfflInfoFields.AFFL_STREET_ADDRESS).dup (); - var locality = cursor.get_string - (Trf.AfflInfoFields.AFFL_LOCALITY).dup (); - var region = cursor.get_string - (Trf.AfflInfoFields.AFFL_REGION).dup (); - var postal_code = cursor.get_string - (Trf.AfflInfoFields.AFFL_POSTALCODE).dup (); - var country = cursor.get_string - (Trf.AfflInfoFields.AFFL_COUNTRY).dup (); - - var postal_address = new Folks.PostalAddress ( - po_box, extension, street, locality, region, postal_code, - country, null, affl_info.affl_tracker_id); - if (!postal_address.is_empty ()) - { - affl_info.postal_address_fd = - new Folks.PostalAddressFieldDetails (postal_address); - } - - affl_info.email = cursor.get_string - (Trf.AfflInfoFields.AFFL_EMAIL).dup (); - affl_info.phone = cursor.get_string - (Trf.AfflInfoFields.AFFL_PHONE).dup (); - - affl_info.website = cursor.get_string - (Trf.AfflInfoFields.AFFL_WEBSITE).dup (); - affl_info.blog = cursor.get_string - (Trf.AfflInfoFields.AFFL_BLOG).dup (); - affl_info.url = cursor.get_string - (Trf.AfflInfoFields.AFFL_URL).dup (); - } - } - catch (Tracker.Sparql.Error e1) - { - warning ("Couldn't fetch affiliation info: %s %s", - query, e1.message); - } - catch (GLib.Error e2) - { - warning ("Couldn't fetch affiliation info: %s %s", - query, e2.message); - } - - return affl_info; - } - - /* This method is safe to call multiple times concurrently. */ - private async string? _insert_persona (string query, string persona_var) - throws PersonaStoreError - { - GLib.Variant variant; - string contact_urn = null; - - if (!this.is_prepared) - { - throw new PersonaStoreError.CREATE_FAILED("Cannot insert persona before store is prepared"); - } - - try - { - debug ("_insert_persona: %s", query); - debug ("_connection is %p", this._connection); - variant = yield this._connection.update_blank_async (query); - - VariantIter iter1, iter2, iter3; - string anon_var = null; - iter1 = variant.iterator (); - - while (iter1.next ("aa{ss}", out iter2)) - { - if (iter2 == null) - continue; - - while (iter2.next ("a{ss}", out iter3)) - { - if (iter3 == null) - continue; - - while (iter3.next ("{ss}", out anon_var, out contact_urn)) - { - /* The dictionary mapping blank node names to - * IRIs doesn't have a fixed order so we need - * check for the anon var corresponding to - * nco:PersonContact. - */ - if (anon_var == persona_var) - return contact_urn; - } - } - } - } - catch (GLib.Error e) - { - contact_urn = null; - warning ("Couldn't insert nco:PersonContact: %s", e.message); - } - - return null; - } - - /* This method is safe to call multiple times concurrently. */ - private async string _single_value_query (string query) - { - SmallSet<string> rows = yield this._multi_value_query (query); - foreach (var r in rows) - { - return r; - } - return ""; - } - - /* This method is safe to call multiple times concurrently. */ - private async SmallSet<string> _multi_value_query (string query) - { - SmallSet<string> ret = new SmallSet<string> (); - - debug ("[_multi_value_query] %s", query); - - try - { - Sparql.Cursor cursor = yield this._connection.query_async (query); - while (cursor.next ()) - { - var prop = cursor.get_string (0); - if (prop != null) - ret.add (prop); - } - } - catch (Tracker.Sparql.Error e1) - { - warning ("Couldn't run query: %s %s", query, e1.message); - } - catch (GLib.Error e2) - { - warning ("Couldn't run query: %s %s", query, e2.message); - } - - return ret; - } - - /* This method is safe to call multiple times concurrently. */ - private async string _urn_from_tracker_id (string tracker_id) - { - const string query = "SELECT fn:concat('<', tracker:uri(%s), '>') " + - "WHERE {}"; - return yield this._single_value_query (query.printf (tracker_id)); - } - - /* This method is safe to call multiple times concurrently. */ - internal async void _set_nickname (Trf.Persona persona, string nickname) - { - const string query_t = "DELETE { "+ - " ?p " + Trf.OntologyDefs.NCO_NICKNAME + " ?n " + - "} " + - "WHERE { " + - " ?p a " + Trf.OntologyDefs.NCO_PERSON + " ; " + - Trf.OntologyDefs.NCO_NICKNAME + " ?n . " + - " FILTER(tracker:id(?p) = %s) " + - "} " + - "INSERT { " + - " ?p " + Trf.OntologyDefs.NCO_NICKNAME + " '%s' " + - "} " + - "WHERE { "+ - " ?p a " + Trf.OntologyDefs.NCO_PERSON + " . " + - "FILTER (tracker:id(?p) = %s) " + - "} "; - - string query = query_t.printf (persona.tracker_id, nickname, - persona.tracker_id); - - yield this._tracker_update (query, "change_nickname"); - } - - /* This method is safe to call multiple times concurrently. */ - internal async void _set_local_ids (Trf.Persona persona, - Set<string> local_ids) - { - string ids = Trf.PersonaStore.serialize_local_ids (local_ids); - yield this._set_tracker_property (persona, - Trf.PersonaStore._LOCAL_ID_PROPERTY_NAME, ids, - "_set_local_ids"); - } - - /* This method is safe to call multiple times concurrently. */ - internal async void _set_web_service_addrs (Trf.Persona persona, - MultiMap<string, WebServiceFieldDetails> ws_obj) - { - var ws_addrs = Trf.PersonaStore.serialize_web_services (ws_obj); - yield this._set_tracker_property (persona, - Trf.PersonaStore._WSD_PROPERTY_NAME, ws_addrs, - "_set_web_service_addrs"); - } - - /* This method is safe to call multiple times concurrently. */ - private async void _set_tracker_property(Trf.Persona persona, - string prop_name, string prop_value, string callers_name) - { - const string query_t = "DELETE " + - " { ?p " + Trf.OntologyDefs.NAO_HAS_PROPERTY + " ?prop } " + - "WHERE { " + - " ?p a " + Trf.OntologyDefs.NCO_PERSON + " ; " + - Trf.OntologyDefs.NAO_HAS_PROPERTY + " ?prop . " + - " ?prop " + Trf.OntologyDefs.NAO_PROPERTY_NAME + " ?prop_name . " + - " FILTER (tracker:id(?p) = %s && ?name = '%s' ) } " + - "INSERT { " + - " _:prop a " + Trf.OntologyDefs.NAO_PROPERTY + " ; " + - Trf.OntologyDefs.NAO_PROPERTY_NAME + - " '%s' ; " + - Trf.OntologyDefs.NAO_PROPERTY_VALUE + " '%s' . " + - " ?p " + Trf.OntologyDefs.NAO_HAS_PROPERTY + " _:prop " + - "} " + - "WHERE { " + - " ?p a nco:PersonContact . " + - "FILTER (tracker:id(?p) = %s) } "; - - string query = query_t.printf (persona.tracker_id, prop_name, - prop_name, prop_value, persona.tracker_id); - yield this._tracker_update (query, callers_name); - } - - /* This method is safe to call multiple times concurrently. */ - internal async void _set_is_favourite (Folks.Persona persona, - bool is_favourite) - { - const string ins_q = "INSERT { " + - " ?p " + Trf.OntologyDefs.NAO_TAG + " " + - Trf.OntologyDefs.NAO_FAVORITE + - "} " + - "WHERE { " + - " ?p a " + Trf.OntologyDefs.NCO_PERSON + - " FILTER (tracker:id(?p) = %s) " + - "} "; - const string del_q = "DELETE { " + - " ?p " + Trf.OntologyDefs.NAO_TAG + " " + - Trf.OntologyDefs.NAO_FAVORITE + " " + - "} " + - "WHERE { " + - " ?p a " + Trf.OntologyDefs.NCO_PERSON + - " FILTER (tracker:id(?p) = %s) " + - "} "; - string query; - - if (is_favourite) - { - query = ins_q.printf (((Trf.Persona) persona).tracker_id); - } - else - { - query = del_q.printf (((Trf.Persona) persona).tracker_id); - } - - yield this._tracker_update (query, "change_is_favourite"); - } - - /* This method may not be safe to call multiple times concurrently. */ - internal async void _set_emails (Folks.Persona persona, - Set<EmailFieldDetails> emails) - { - yield this._set_unique_attrib_set (persona, emails, - Trf.Attrib.EMAILS); - } - - /* This method may not be safe to call multiple times concurrently. */ - internal async void _set_phones (Folks.Persona persona, - Set<PhoneFieldDetails> phone_numbers) - { - yield this._set_unique_attrib_set (persona, phone_numbers, - Trf.Attrib.PHONES); - } - - /* This method may not be safe to call multiple times concurrently. */ - internal async void _set_unique_attrib_set (Folks.Persona persona, - Set<AbstractFieldDetails<string>> properties, Trf.Attrib attrib) - { - string? query_name = null; - var p_id = ((Trf.Persona) persona).tracker_id; - var builder = new Tracker.Sparql.Builder.update (); - builder.insert_open (null); - - switch (attrib) - { - case Trf.Attrib.PHONES: - query_name = "_set_phones"; - yield this._remove_attributes_from_persona (persona, - _REMOVE_PHONES); - yield this._build_update_query_set (builder, properties, - "?contact", Trf.Attrib.PHONES); - break; - case Trf.Attrib.EMAILS: - query_name = "_set_emailss"; - yield this._remove_attributes_from_persona (persona, - _REMOVE_EMAILS); - yield this._build_update_query_set (builder, properties, - "?contact", Trf.Attrib.EMAILS); - break; - } - builder.insert_close (); - builder.where_open (); - builder.subject ("?contact"); - builder.predicate ("a"); - builder.object (Trf.OntologyDefs.NCO_PERSON); - string filter = " FILTER(tracker:id(?contact) = %s) ".printf (p_id); - builder.append (filter); - builder.where_close (); - - yield this._tracker_update (builder.result, query_name); - } - - /* This method is probably not safe to call multiple times concurrently. */ - internal async void _set_urls (Folks.Persona persona, - Set<UrlFieldDetails> urls) - { - yield this._set_attrib_set (persona, urls, - Trf.Attrib.URLS); - } - - /* This method is probably not safe to call multiple times concurrently. */ - internal async void _set_im_addresses (Folks.Persona persona, - MultiMap<string, ImFieldDetails> im_addresses) - { - var ims = new SmallSet<ImFieldDetails> (); - foreach (var proto in im_addresses.get_keys ()) - { - var addrs = im_addresses.get (proto); - foreach (var im_fd in addrs) - { - var new_im_fd = new ImFieldDetails (im_fd.value); - new_im_fd.set_parameter ("proto", proto); - ims.add (new_im_fd); - } - } - - yield this._set_attrib_set (persona, ims, Trf.Attrib.IM_ADDRESSES); - } - - /* This method is probably not safe to call multiple times concurrently. */ - internal async void _set_postal_addresses (Folks.Persona persona, - Set<PostalAddressFieldDetails> postal_addresses) - { - yield this._set_attrib_set (persona, postal_addresses, - Trf.Attrib.POSTAL_ADDRESSES); - } - - /* This method is safe to call multiple times concurrently. */ - internal async void _set_roles (Folks.Persona persona, - Set<RoleFieldDetails> roles) - { - const string del_t = "DELETE { " + - " ?p " + Trf.OntologyDefs.NCO_HAS_AFFILIATION + " ?a " + - "} " + - "WHERE { " + - " ?p a " + Trf.OntologyDefs.NCO_PERSON + "; " + - " " + Trf.OntologyDefs.NCO_HAS_AFFILIATION + " ?a . " + - " OPTIONAL { ?a " + Trf.OntologyDefs.NCO_ORG + " ?o } . " + - " OPTIONAL { ?a " + Trf.OntologyDefs.NCO_ROLE + " ?r } . " + - " OPTIONAL { ?a " + Trf.OntologyDefs.NCO_TITLE + " ?t } . " + - " FILTER(tracker:id(?p) = %s) " + - "} "; - - var p_id = ((Trf.Persona) persona).tracker_id; - string del_q = del_t.printf (p_id); - - var builder = new Tracker.Sparql.Builder.update (); - builder.insert_open (null); - - int i = 0; - foreach (var role_fd in roles) - { - string affl = "_:a%d".printf (i); - - builder.subject (affl); - builder.predicate ("a"); - builder.object (Trf.OntologyDefs.NCO_AFFILIATION); - builder.predicate (Trf.OntologyDefs.NCO_ROLE); - builder.object_string (role_fd.value.role); - builder.predicate (Trf.OntologyDefs.NCO_TITLE); - builder.object_string (role_fd.value.title); - builder.predicate (Trf.OntologyDefs.NCO_ORG); - builder.object_string (role_fd.value.organisation_name); - builder.subject ("?contact"); - builder.predicate (Trf.OntologyDefs.NCO_HAS_AFFILIATION); - builder.object (affl); - } - - builder.insert_close (); - builder.where_open (); - builder.subject ("?contact"); - builder.predicate ("a"); - builder.object (Trf.OntologyDefs.NCO_PERSON); - string filter = " FILTER(tracker:id(?contact) = %s) ".printf (p_id); - builder.append (filter); - builder.where_close (); - - yield this._tracker_update (del_q + builder.result, "_set_roles"); - } - - /* This method is safe to call multiple times concurrently. */ - internal async void _set_notes (Folks.Persona persona, - Set<NoteFieldDetails> notes) - { - const string del_t = "DELETE { " + - "?p " + Trf.OntologyDefs.NCO_NOTE + " ?n " + - "} " + - "WHERE {" + - " ?p a nco:PersonContact ; " + - Trf.OntologyDefs.NCO_NOTE + " ?n . " + - " FILTER(tracker:id(?p) = %s)" + - "}"; - - var p_id = ((Trf.Persona) persona).tracker_id; - string del_q = del_t.printf (p_id); - - var builder = new Tracker.Sparql.Builder.update (); - builder.insert_open (null); - - foreach (var n in notes) - { - builder.subject ("?contact"); - builder.predicate (Trf.OntologyDefs.NCO_NOTE); - builder.object_string (n.value); - } - - builder.insert_close (); - builder.where_open (); - builder.subject ("?contact"); - builder.predicate ("a"); - builder.object (Trf.OntologyDefs.NCO_PERSON); - string filter = " FILTER(tracker:id(?contact) = %s) ".printf (p_id); - builder.append (filter); - builder.where_close (); - - yield this._tracker_update (del_q + builder.result, "_set_notes"); - } - - /* This method is safe to call multiple times concurrently. */ - internal async void _set_birthday (Folks.Persona persona, - owned DateTime bday) - { - const string q_t = "DELETE { " + - " ?p " + Trf.OntologyDefs.NCO_BIRTHDAY + " ?b " + - "} " + - "WHERE { " + - " ?p a " + Trf.OntologyDefs.NCO_PERSON + "; " + - Trf.OntologyDefs.NCO_BIRTHDAY + " ?b . " + - " FILTER (tracker:id(?p) = %s ) " + - "} " + - "INSERT { " + - " ?p " + Trf.OntologyDefs.NCO_BIRTHDAY + " '%s' " + - "} " + - "WHERE { " + - " ?p a " + Trf.OntologyDefs.NCO_PERSON + " . " + - " FILTER (tracker:id(?p) = %s) " + - "} "; - - var p_id = ((Trf.Persona) persona).tracker_id; - TimeVal tv; - bday.to_timeval (out tv); - string query = q_t.printf (p_id, tv.to_iso8601 (), p_id); - - yield this._tracker_update (query, "_set_birthday"); - } - - /* This method is safe to call multiple times concurrently. */ - internal async void _set_gender (Folks.Persona persona, - owned Gender gender) - { - const string del_t = "DELETE { " + - " ?p " + Trf.OntologyDefs.NCO_GENDER + " ?g " + - "} " + - "WHERE { " + - " ?p a " + Trf.OntologyDefs.NCO_PERSON + " ; " + - Trf.OntologyDefs.NCO_GENDER + " ?g . " + - " FILTER (tracker:id(?p) = %s) " + - "} "; - const string ins_t = "INSERT { " + - " ?p " + Trf.OntologyDefs.NCO_GENDER + " %s " + - "} " + - "WHERE { " + - " ?p a " + Trf.OntologyDefs.NCO_PERSON + " . " + - " FILTER (tracker:id(?p) = %s) " + - "} "; - - var p_id = ((Trf.Persona) persona).tracker_id; - string query; - - if (gender == Gender.UNSPECIFIED) - { - query = del_t.printf (p_id); - } - else - { - string gender_urn; - - if (gender == Gender.MALE) - gender_urn = Trf.OntologyDefs.NCO_URL_PREFIX + "nco#gender-male>"; - else - gender_urn = Trf.OntologyDefs.NCO_URL_PREFIX + "nco#gender-female>"; - - query = del_t.printf (p_id) + ins_t.printf (gender_urn, p_id); - } - - yield this._tracker_update (query, "_set_gender"); - } - - /* This method is not safe to call multiple times concurrently. */ - internal async void _set_avatar (Folks.Persona persona, - LoadableIcon? avatar) - { - const string query_d = "DELETE {" + - " ?c " + Trf.OntologyDefs.NCO_PHOTO + " ?p " + - " } " + - "WHERE { " + - " ?c a " + Trf.OntologyDefs.NCO_PERSON + " ; " + - Trf.OntologyDefs.NCO_PHOTO + " ?p . " + - " FILTER(tracker:id(?c) = %s) " + - "} "; - - const string query_i = "INSERT { " + - " _:i a " + Trf.OntologyDefs.NFO_IMAGE + ", " + - Trf.OntologyDefs.NIE_DATAOBJECT + " ; " + - Trf.OntologyDefs.NIE_URL + " '%s' . " + - " ?c " + Trf.OntologyDefs.NCO_PHOTO + " _:i " + - "} " + - "WHERE { " + - " ?c a nco:PersonContact . " + - " FILTER(tracker:id(?c) = %s) " + - "}"; - - var p_id = ((Trf.Persona) persona).tracker_id; - - var image_urn = yield this._get_property (int.parse (p_id), - Trf.OntologyDefs.NCO_PHOTO); - if (image_urn != "") - this._delete_resource.begin ("<%s>".printf (image_urn)); - - string query = query_d.printf (p_id); - - var cache = AvatarCache.dup (); - if (avatar != null) - { - try - { - // Cache the avatar so that it has a URI - var uri = yield cache.store_avatar (persona.uid, avatar); - - // Add the avatar to the query - query += query_i.printf (uri , p_id); - } - catch (GLib.Error e1) - { - warning ("Couldn't cache avatar for Trf.Persona '%s': %s", - persona.uid, e1.message); - } - } - else - { - // Delete any old avatar from the cache, ignoring errors - try - { - yield cache.remove_avatar (persona.uid); - } - catch (GLib.Error e2) {} - } - - yield this._tracker_update (query, "_set_avatar"); - } - - /* This method is safe to call multiple times concurrently. */ - internal async void _set_structured_name (Folks.Persona persona, - StructuredName? sname) - { - const string query_d = "DELETE { " + - " ?p " + Trf.OntologyDefs.NCO_FAMILY + " ?family . " + - " ?p " + Trf.OntologyDefs.NCO_GIVEN + " ?given . " + - " ?p " + Trf.OntologyDefs.NCO_ADDITIONAL + " ?adi . " + - " ?p " + Trf.OntologyDefs.NCO_PREFIX + " ?prefix . " + - " ?p " + Trf.OntologyDefs.NCO_SUFFIX + " ?suffix " + - "} " + - "WHERE { " + - " ?p a " + Trf.OntologyDefs.NCO_PERSON + " . " + - " OPTIONAL { ?p " + Trf.OntologyDefs.NCO_FAMILY + " ?family } . " + - " OPTIONAL { ?p " + Trf.OntologyDefs.NCO_GIVEN + " ?given } . " + - " OPTIONAL { ?p " + Trf.OntologyDefs.NCO_ADDITIONAL + " ?adi } . " + - " OPTIONAL { ?p " + Trf.OntologyDefs.NCO_PREFIX + " ?prefix } . " + - " OPTIONAL { ?p " + Trf.OntologyDefs.NCO_SUFFIX + " ?suffix } . " + - " FILTER (tracker:id(?p) = %s) " + - "} "; - const string query_i = "INSERT { " + - " ?p " + Trf.OntologyDefs.NCO_FAMILY + " '%s'; " + - " " + Trf.OntologyDefs.NCO_GIVEN + " '%s'; " + - " " + Trf.OntologyDefs.NCO_ADDITIONAL + " '%s'; " + - " " + Trf.OntologyDefs.NCO_PREFIX + " '%s'; " + - " " + Trf.OntologyDefs.NCO_SUFFIX + " '%s' " + - " } " + - "WHERE { " + - " ?p a " + Trf.OntologyDefs.NCO_PERSON + " . " + - " FILTER (tracker:id(?p) = %s) " + - "} "; - - var p_id = ((Trf.Persona) persona).tracker_id; - - string query = query_d.printf (p_id); - if (sname != null) - { - query = query_i.printf (sname.family_name, sname.given_name, - sname.additional_names, sname.prefixes, sname.suffixes, p_id); - } - - yield this._tracker_update (query, "_set_structured_name"); - } - - /* This method is safe to call multiple times concurrently. */ - internal async void _set_full_name (Folks.Persona persona, - string full_name) - { - const string query_t = "DELETE { " + - " ?p " + Trf.OntologyDefs.NCO_FULLNAME + " ?fn " + - "} " + - "WHERE { " + - " ?p a " + Trf.OntologyDefs.NCO_PERSON + " . " + - " OPTIONAL { ?p " + Trf.OntologyDefs.NCO_FULLNAME + " ?fn } . " + - " FILTER (tracker:id(?p) = %s) " + - "} " + - "INSERT { " + - " ?p " + Trf.OntologyDefs.NCO_FULLNAME + " '%s' " + - "} " + - "WHERE { " + - " ?p a " + Trf.OntologyDefs.NCO_PERSON + " . " + - " FILTER (tracker:id(?p) = %s) " + - "} "; - - var p_id = ((Trf.Persona) persona).tracker_id; - string query = query_t.printf (p_id, full_name, p_id); - yield this._tracker_update (query, "_set_full_name"); - } - - /* NOTE: - * - first we nuke old attribs - * - we create new affls with the new attribs - * - * This method is probably not safe to call multiple times concurrently. - */ - private async void _set_attrib_set (Folks.Persona persona, - Set<Object> attribs, Trf.Attrib what) - { - var p_id = ((Trf.Persona) persona).tracker_id; - - unowned string? related_attrib = null; - unowned string? related_prop = null; - unowned string? related_prop_2 = null; - unowned string? related_connection = null; - - switch (what) - { - case Trf.Attrib.IM_ADDRESSES: - related_attrib = Trf.OntologyDefs.NCO_IMADDRESS; - related_prop = Trf.OntologyDefs.NCO_IMID; - related_prop_2 = Trf.OntologyDefs.NCO_IMPROTOCOL; - related_connection = Trf.OntologyDefs.NCO_HAS_IMADDRESS; - yield this._remove_attributes_from_persona (persona, - _REMOVE_IM_ADDRS); - break; - case Trf.Attrib.POSTAL_ADDRESSES: - related_attrib = Trf.OntologyDefs.NCO_POSTAL_ADDRESS; - related_connection = Trf.OntologyDefs.NCO_HAS_POSTAL_ADDRESS; - yield this._remove_attributes_from_persona (persona, - _REMOVE_POSTALS); - break; - case Trf.Attrib.URLS: - related_attrib = Trf.OntologyDefs.NCO_URL; - related_connection = Trf.OntologyDefs.NCO_URL; - break; - } - - var builder = new Tracker.Sparql.Builder.update (); - builder.insert_open (null); - int i = 0; - foreach (var p in attribs) - { - AbstractFieldDetails fd = null; - PostalAddressFieldDetails pafd = null; - PostalAddress pa = null; - - string affl = "_:a%d".printf (i); - string attr = null; - - switch (what) - { - case Trf.Attrib.POSTAL_ADDRESSES: - pafd = (PostalAddressFieldDetails) p; - pa = pafd.value; - attr = "_:p%d".printf (i); - builder.subject (attr); - builder.predicate ("a"); - builder.object (related_attrib); - builder.predicate (Trf.OntologyDefs.NCO_POBOX); - builder.object_string (pa.po_box); - builder.predicate (Trf.OntologyDefs.NCO_LOCALITY); - builder.object_string (pa.locality); - builder.predicate (Trf.OntologyDefs.NCO_POSTALCODE); - builder.object_string (pa.postal_code); - builder.predicate (Trf.OntologyDefs.NCO_STREET_ADDRESS); - builder.object_string (pa.street); - builder.predicate (Trf.OntologyDefs.NCO_EXTENDED_ADDRESS); - builder.object_string (pa.extension); - builder.predicate (Trf.OntologyDefs.NCO_COUNTRY); - builder.object_string (pa.country); - builder.predicate (Trf.OntologyDefs.NCO_REGION); - builder.object_string (pa.region); - break; - case Trf.Attrib.URLS: - fd = (UrlFieldDetails) p; - var type_p = fd.get_parameter_values (AbstractFieldDetails.PARAM_TYPE); - - if (type_p != null && - type_p.contains (UrlFieldDetails.PARAM_TYPE_BLOG)) - { - related_connection = Trf.OntologyDefs.NCO_BLOG; - } - else if (type_p != null && - type_p.contains (UrlFieldDetails.PARAM_TYPE_HOME_PAGE)) - { - related_connection = Trf.OntologyDefs.NCO_WEBSITE; - } - else - { - related_connection = Trf.OntologyDefs.NCO_URL; - } - - attr = "'%s'".printf (((UrlFieldDetails) fd).value); - break; - case Trf.Attrib.IM_ADDRESSES: - default: - fd = (ImFieldDetails) p; - attr = "_:p%d".printf (i); - builder.subject (attr); - builder.predicate ("a"); - builder.object (related_attrib); - builder.predicate (related_prop); - builder.object_string (((ImFieldDetails) fd).value); - - if (what == Trf.Attrib.IM_ADDRESSES) - { - builder.predicate (related_prop_2); - var im_params = - fd.get_parameter_values ("proto").to_array (); - builder.object_string (im_params[0]); - } - - break; - } - - builder.subject (affl); - builder.predicate ("a"); - builder.object (Trf.OntologyDefs.NCO_AFFILIATION); - builder.predicate (related_connection); - builder.object (attr); - builder.subject ("?contact"); - builder.predicate (Trf.OntologyDefs.NCO_HAS_AFFILIATION); - builder.object (affl); - - i++; - } - builder.insert_close (); - builder.where_open (); - builder.subject ("?contact"); - builder.predicate ("a"); - builder.object (Trf.OntologyDefs.NCO_PERSON); - string filter = " FILTER(tracker:id(?contact) = %s) ".printf (p_id); - builder.append (filter); - builder.where_close (); - - yield this._tracker_update (builder.result, "set_attrib"); - } - - /* This method is safe to call multiple times concurrently. */ - private async bool _tracker_update (string query, string caller) - { - bool ret = false; - - debug ("%s: %s", caller, query); - - try - { - yield this._connection.update_async (query); - ret = true; - } - catch (Tracker.Sparql.Error e1) - { - warning ("[%s] SPARQL syntax error: %s. Query: %s", - caller, e1.message, query); - } - catch (GLib.IOError e2) - { - warning ("[%s] IO error: %s", - caller, e2.message); - } - catch (GLib.DBusError e3) - { - warning ("[%s] DBus error: %s", - caller, e3.message); - } - catch (GLib.Error e4) - { - warning ("[%s] GLib error: %s", - caller, e4.message); - } - - return ret; - } - - /* This method is safe to call multiple times concurrently. */ - private async SmallSet<string> _affiliations_from_persona (string urn) - { - return yield this._linked_resources (urn, Trf.OntologyDefs.NCO_PERSON, - Trf.OntologyDefs.NCO_HAS_AFFILIATION); - } - - /* This method is safe to call multiple times concurrently. */ - private async SmallSet<string> _phones_from_affiliation (string affl) - { - return yield this._linked_resources (affl, - Trf.OntologyDefs.NCO_AFFILIATION, - Trf.OntologyDefs.NCO_HAS_PHONE); - } - - /* This method is safe to call multiple times concurrently. */ - private async SmallSet<string> _postals_from_affiliation (string affl) - { - return yield this._linked_resources (affl, - Trf.OntologyDefs.NCO_AFFILIATION, - Trf.OntologyDefs.NCO_HAS_POSTAL_ADDRESS); - } - - /* This method is safe to call multiple times concurrently. */ - private async SmallSet<string> _imaddrs_from_affiliation (string affl) - { - return yield this._linked_resources (affl, - Trf.OntologyDefs.NCO_AFFILIATION, - Trf.OntologyDefs.NCO_HAS_IMADDRESS); - } - - /* This method is safe to call multiple times concurrently. */ - private async SmallSet<string> _emails_from_affiliation (string affl) - { - return yield this._linked_resources (affl, - Trf.OntologyDefs.NCO_AFFILIATION, - Trf.OntologyDefs.NCO_HAS_EMAIL); - } - - /** - * Retrieve the list of linked resources of a given subject - * - * This method is safe to call multiple times concurrently. - * - * @param resource the urn of the resource in <urn> format - * @return number of resources linking to this resource - */ - private async int _resource_usage_count (string resource) - { - const string query_t = "SELECT " + - " count(?s) " + - "WHERE { " + - " %s a rdfs:Resource . " + - " ?s ?p %s } "; - - var query = query_t.printf (resource, resource); - var result = yield this._single_value_query (query); - return int.parse (result); - } - - /* - * NOTE: - * - * We assume that the caller is holding a link to the resource, - * so if _resource_usage_count () == 1 it means no one else - * (beside the caller) is linking to the resource. - * - * This means that _delete_resource should be called before - * removing the resources that hold a link to it (which also - * makes sense from the signaling perspective). - * - * This method is not safe to call multiple times concurrently, as the - * resource count check races with deletion. - */ - private async bool _delete_resource (string resource_urn, - bool check_count = true) - { - bool deleted = false; - var query_t = " DELETE { " + - " %s a rdfs:Resource " + - "} " + - "WHERE { " + - " %s a rdfs:Resource " + - "} "; - - var query = query_t.printf (resource_urn, resource_urn); - if (check_count) - { - int count = yield this._resource_usage_count (resource_urn); - if (count == 1) - { - deleted = yield this._tracker_update (query, "_delete_resource"); - } - } - else - { - deleted = yield this._tracker_update (query, "_delete_resource"); - } - - return deleted; - } - - /** - * Retrieve the list of linked resources of a given subject - * - * This method is safe to call multiple times concurrently. - * - * @param urn the urn of the subject in <urn> format - * @param subject_type i.e: nco:Person, nco:Affiliation, etc - * @param linking_predicate i.e.: nco:hasAffiliation - * @return a list of linked resources (in <urn> format) - */ - private async SmallSet<string> _linked_resources (string urn, - string subject_type, string linking_predicate) - { - string query_t = "SELECT " + - " fn:concat('<',?linkedr,'>') " + - "WHERE { " + - " %s a %s; " + - " %s ?linkedr " + - "} "; - - var query = query_t.printf (urn, subject_type, linking_predicate); - return yield this._multi_value_query (query); - } - - /* This method is safe to call multiple times concurrently. */ - private async string _urn_from_persona (Folks.Persona persona) - { - var id = ((Trf.Persona) persona).tracker_id; - return yield this._urn_from_tracker_id (id); - } - - /** - * Helper method to figure out if a constrained property - * already exists. - * - * This method is safe to call multiple times concurrently. - */ - private async string _urn_from_property (string class_name, - string property_name, - string property_value) - { - const string query_template = "SELECT " + - " fn:concat('<', ?o, '>') " + - "WHERE { " + - " ?o a %s ; " + - " %s ?prop_val . " + - "FILTER (?prop_val = '%s') " + - "}"; - - string query = query_template.printf (class_name, - property_name, property_value); - return yield this._single_value_query (query); - } -} diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala deleted file mode 100644 index 5c0a1713..00000000 --- a/backends/tracker/lib/trf-persona.vala +++ /dev/null @@ -1,1516 +0,0 @@ -/* - * Copyright (C) 2011 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: - * Travis Reitter <travis.reitter@collabora.co.uk> - * Marco Barisione <marco.barisione@collabora.co.uk> - * Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - */ - -using Gee; -using GLib; -using Folks; -using Tracker; -using Tracker.Sparql; - -/** - * A persona subclass which represents a single nco:Contact. - */ -public class Trf.Persona : Folks.Persona, - AvatarDetails, - BirthdayDetails, - EmailDetails, - FavouriteDetails, - GenderDetails, - ImDetails, - LocalIdDetails, - NameDetails, - NoteDetails, - PhoneDetails, - PostalAddressDetails, - RoleDetails, - UrlDetails, - WebServiceDetails -{ - private string _nickname; /* must never be null */ - private bool _is_favourite; - private const string[] _linkable_properties = - { - "im-addresses", - "local-ids", - "web-service-addresses", - null /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */ - }; - private SmallSet<PhoneFieldDetails> _phone_numbers; - private Set<PhoneFieldDetails> _phone_numbers_ro; - private SmallSet<EmailFieldDetails> _email_addresses; - private Set<EmailFieldDetails> _email_addresses_ro; - private weak Sparql.Cursor _cursor; - private string _tracker_id; - private const string[] _writeable_properties = - { - "phone-numbers", - "email-addresses", - "avatar", - "structured-name", - "full-name", - "gender", - "birthday", - "roles", - "notes", - "urls", - "im-addresses", - "is-favourite", - "local-ids", - "web-service-addresses", - null /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */ - }; - - /** - * A nickname for the Persona. - * - * See {@link Folks.NameDetails.nickname}. - */ - [CCode (notify = false)] - public string nickname - { - get { return this._nickname; } - set { this.change_nickname.begin (value); } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public async void change_nickname (string nickname) throws PropertyError - { - yield ((Trf.PersonaStore) this.store)._set_nickname (this, nickname); - } - - /** - * {@inheritDoc} - */ - [CCode (notify = false)] - public Set<PhoneFieldDetails> phone_numbers - { - get { return this._phone_numbers_ro; } - set { this.change_phone_numbers.begin (value); } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public async void change_phone_numbers (Set<PhoneFieldDetails> phone_numbers) - throws PropertyError - { - yield ((Trf.PersonaStore) this.store)._set_phones (this, phone_numbers); - } - - /** - * {@inheritDoc} - */ - [CCode (notify = false)] - public Set<EmailFieldDetails> email_addresses - { - get { return this._email_addresses_ro; } - set { this.change_email_addresses.begin (value); } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public async void change_email_addresses ( - Set<EmailFieldDetails> email_addresses) throws PropertyError - { - yield ((Trf.PersonaStore) this.store)._set_emails (this, email_addresses); - } - - /** - * {@inheritDoc} - */ - public override string[] linkable_properties - { - get { return Trf.Persona._linkable_properties; } - } - - /** - * {@inheritDoc} - * - * @since 0.6.0 - */ - public override string[] writeable_properties - { - get { return Trf.Persona._writeable_properties; } - } - - private LoadableIcon? _avatar = null; - /** - * An avatar for the Persona. - * - * See {@link Folks.AvatarDetails.avatar}. - * - * @since 0.6.0 - */ - [CCode (notify = false)] - public LoadableIcon? avatar - { - get { return this._avatar; } - set { this.change_avatar.begin (value); } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public async void change_avatar (LoadableIcon? avatar) throws PropertyError - { - yield ((Trf.PersonaStore) this.store)._set_avatar (this, avatar); - } - - private StructuredName? _structured_name = null; - /** - * {@inheritDoc} - */ - [CCode (notify = false)] - public StructuredName? structured_name - { - get { return this._structured_name; } - set { this.change_structured_name.begin (value); } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public async void change_structured_name (StructuredName? structured_name) - throws PropertyError - { - yield ((Trf.PersonaStore) this.store)._set_structured_name (this, - structured_name); - } - - private string _full_name = ""; - /** - * {@inheritDoc} - */ - [CCode (notify = false)] - public string full_name - { - get { return this._full_name; } - set { this.change_full_name.begin (value); } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public async void change_full_name (string full_name) throws PropertyError - { - yield ((Trf.PersonaStore) this.store)._set_full_name (this, full_name); - } - - private Gender _gender; - /** - * {@inheritDoc} - */ - [CCode (notify = false)] - public Gender gender - { - get { return this._gender; } - set { this.change_gender.begin (value); } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public async void change_gender (Gender gender) throws PropertyError - { - yield ((Trf.PersonaStore) this.store)._set_gender (this, gender); - } - - private DateTime? _birthday = null; - /** - * {@inheritDoc} - */ - [CCode (notify = false)] - public DateTime? birthday - { - get { return this._birthday; } - set { this.change_birthday.begin (value); } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public async void change_birthday (DateTime? birthday) throws PropertyError - { - yield ((Trf.PersonaStore) this.store)._set_birthday (this, birthday); - } - - /** - * {@inheritDoc} - */ - [CCode (notify = false)] - public string? calendar_event_id - { - /* Unsupported */ - get { return null; } - set { this.change_calendar_event_id.begin (value); } /* not writeable */ - } - - private SmallSet<RoleFieldDetails> _roles; - private Set<RoleFieldDetails> _roles_ro; - - /** - * {@inheritDoc} - */ - [CCode (notify = false)] - public Set<RoleFieldDetails> roles - { - get { return this._roles_ro; } - set { this.change_roles.begin (value); } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public async void change_roles (Set<RoleFieldDetails> roles) - throws PropertyError - { - yield ((Trf.PersonaStore) this.store)._set_roles (this, roles); - } - - private SmallSet<NoteFieldDetails> _notes; - private Set<NoteFieldDetails> _notes_ro; - - /** - * {@inheritDoc} - */ - [CCode (notify = false)] - public Set<NoteFieldDetails> notes - { - get { return this._notes_ro; } - set { this.change_notes.begin (value); } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public async void change_notes (Set<NoteFieldDetails> notes) - throws PropertyError - { - yield ((Trf.PersonaStore) this.store)._set_notes (this, notes); - } - - private SmallSet<UrlFieldDetails> _urls; - private Set<UrlFieldDetails> _urls_ro; - - /** - * {@inheritDoc} - */ - [CCode (notify = false)] - public Set<UrlFieldDetails> urls - { - get { return this._urls_ro; } - set { this.change_urls.begin (value); } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public async void change_urls (Set<UrlFieldDetails> urls) throws PropertyError - { - yield ((Trf.PersonaStore) this.store)._set_urls (this, urls); - } - - private SmallSet<PostalAddressFieldDetails> _postal_addresses; - private Set<PostalAddressFieldDetails> _postal_addresses_ro; - - /** - * {@inheritDoc} - */ - [CCode (notify = false)] - public Set<PostalAddressFieldDetails> postal_addresses - { - get { return this._postal_addresses_ro; } - set { this.change_postal_addresses.begin (value); } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public async void change_postal_addresses ( - Set<PostalAddressFieldDetails> postal_addresses) throws PropertyError - { - yield ((Trf.PersonaStore) this.store)._set_postal_addresses (this, - postal_addresses); - } - - private HashMap<string, HashMap<string, string>> _tracker_ids_ims = - new HashMap<string, HashMap<string, string>> (); - - private HashMultiMap<string, ImFieldDetails> _im_addresses = - new HashMultiMap<string, ImFieldDetails> (null, null, - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - - /** - * {@inheritDoc} - */ - [CCode (notify = false)] - public MultiMap<string, ImFieldDetails> im_addresses - { - get { return this._im_addresses; } - set { this.change_im_addresses.begin (value); } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public async void change_im_addresses ( - MultiMap<string, ImFieldDetails> im_addresses) throws PropertyError - { - yield ((Trf.PersonaStore) this.store)._set_im_addresses (this, - im_addresses); - } - - /** - * Whether this contact is a user-defined favourite. - */ - [CCode (notify = false)] - public bool is_favourite - { - get { return this._is_favourite; } - set { this.change_is_favourite.begin (value); } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public async void change_is_favourite (bool is_favourite) throws PropertyError - { - if (this._is_favourite == is_favourite) - { - return; - } - - yield ((Trf.PersonaStore) this.store)._set_is_favourite (this, - is_favourite); - } - - private HashSet<string> _local_ids; - private Set<string> _local_ids_ro; - - /** - * IDs used to link {@link Trf.Persona}s. - */ - [CCode (notify = false)] - public Set<string> local_ids - { - get - { - if (this._local_ids.contains (this.iid) == false) - { - this._local_ids.add (this.iid); - } - return this._local_ids_ro; - } - set { this.change_local_ids.begin (value); } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public async void change_local_ids (Set<string> local_ids) - throws PropertyError - { - if (local_ids.contains (this.uid) == false) - { - local_ids.add (this.uid); - } - - yield ((Trf.PersonaStore) this.store)._set_local_ids (this, local_ids); - } - - private HashMultiMap<string, WebServiceFieldDetails> _web_service_addresses = - new HashMultiMap<string, WebServiceFieldDetails> ( - null, null, AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - - /** - * {@inheritDoc} - */ - [CCode (notify = false)] - public MultiMap<string, WebServiceFieldDetails> web_service_addresses - { - get { return this._web_service_addresses; } - set { this.change_web_service_addresses.begin (value); } - } - - /** - * {@inheritDoc} - * - * @since 0.6.2 - */ - public async void change_web_service_addresses ( - MultiMap<string, WebServiceFieldDetails> web_service_addresses) - throws PropertyError - { - yield ((Trf.PersonaStore) this.store)._set_web_service_addrs (this, - web_service_addresses); - } - - /** - * Build a IID. - * - * @param store_id the {@link PersonaStore.id} - * @param tracker_id the tracker id belonging to nco:PersonContact - * @return a valid IID - * - * @since 0.5.0 - */ - internal static string build_iid (string store_id, string tracker_id) - { - return "%s:%s".printf (store_id, tracker_id); - } - - /** - * Create a new persona. - * - * Create a new persona for the {@link PersonaStore} ``store``, representing - * the nco:Contact whose details are stored in the cursor. - */ - public Persona (PersonaStore store, string tracker_id, - Sparql.Cursor? cursor = null) - { - string uid = Folks.Persona.build_uid (BACKEND_NAME, store.id, tracker_id); - string iid = Trf.Persona.build_iid (store.id, tracker_id); - bool is_user = false; - - if (cursor != null) - { - var contact_urn = cursor.get_string (Trf.Fields.CONTACT_URN); - if (contact_urn == Trf.OntologyDefs.DEFAULT_CONTACT_URN) - { - is_user = true; - } - } - - /* Use the IID as the display ID since no other suitable identifier is - * available which we can guarantee is unique within the store. */ - Object (display_id: iid, - uid: uid, - iid: iid, - store: store, - is_user: is_user, - tracker_id: tracker_id, - /* Ideally we wouldn't have to do this, since passing iterators - * around is ugly. However, we can't fix the Tracker backend to - * not pass Cursors from PersonaStore to Personas without breaking - * API. */ - cursor: cursor); - } - - construct - { - debug ("Creating new Trf.Persona with iid '%s'", this.iid); - - this._gender = Gender.UNSPECIFIED; - this._full_name = ""; - this._structured_name = null; - this._nickname = ""; - this._is_favourite = false; - this._phone_numbers = new SmallSet<PhoneFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - this._phone_numbers_ro = this._phone_numbers.read_only_view; - this._email_addresses = new SmallSet<EmailFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - this._email_addresses_ro = this._email_addresses.read_only_view; - this._roles = new SmallSet<RoleFieldDetails> ( - AbstractFieldDetails<Role>.hash_static, - AbstractFieldDetails<Role>.equal_static); - this._roles_ro = this._roles.read_only_view; - this._notes = new SmallSet<NoteFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - this._notes_ro = this._notes.read_only_view; - this._urls = new SmallSet<UrlFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - this._urls_ro = this._urls.read_only_view; - this._postal_addresses = new SmallSet<PostalAddressFieldDetails> ( - AbstractFieldDetails<PostalAddress>.hash_static, - AbstractFieldDetails<PostalAddress>.equal_static); - this._postal_addresses_ro = this._postal_addresses.read_only_view; - this._local_ids = new HashSet<string> (); - this._local_ids_ro = this._local_ids.read_only_view; - - /* Set the initial property values if we have a results cursor. */ - if (this._cursor != null) - { - this._update_names (); - this._update_avatar (); - this._update_im_addresses (); - this._update_phones (); - this._update_email_addresses (); - this._update_urls (); - this._update_favourite (); - this._update_roles (); - this._update_bday (); - this._update_note (); - this._update_gender (); - this._update_postal_addresses (); - this._update_local_ids (); - } - } - - /** - * ID of the {@link Trf.Persona} in Tracker. - * - * @since 0.6.6 - */ - public string tracker_id - { - get { return this._tracker_id; } - construct { this._tracker_id = value; } - } - - /** - * A {@link Sparql.Cursor} representing the persona in a set of query results. - * - * This is an internal (read: horrible) API which shouldn't be used by client - * code. It's only exposed publicly due to the design of libfolks’ Tracker - * backend. - * - * @since 0.6.6 - */ - public Sparql.Cursor? cursor - { - get { return this._cursor; } - construct { this._cursor = value; } - } - - /** - * {@inheritDoc} - */ - public override void linkable_property_to_links (string prop_name, - Folks.Persona.LinkablePropertyCallback callback) - { - if (prop_name == "im-addresses") - { - foreach (var protocol in this._im_addresses.get_keys ()) - { - var im_fds = this._im_addresses.get (protocol); - - foreach (var im_fd in im_fds) - callback (protocol + ":" + im_fd.value); - } - } - else if (prop_name == "local-ids") - { - foreach (var id in this._local_ids) - { - callback (id); - } - } - else if (prop_name == "web-service-addresses") - { - foreach (var web_service in this._web_service_addresses.get_keys ()) - { - var web_service_addresses = - this._web_service_addresses.get (web_service); - - foreach (var ws_fd in web_service_addresses) - callback (web_service + ":" + ws_fd.value); - } - } - else - { - /* Chain up */ - base.linkable_property_to_links (prop_name, callback); - } - } - - ~Persona () - { - debug ("Destroying Trf.Persona '%s': %p", this.uid, this); - } - - internal void _update_full_name (string? fn) - { - if (fn == null) - { - fn = ""; - } - - if (this._full_name != fn) - { - this._full_name = fn; - this.notify_property ("full-name"); - } - } - - internal void _update_nickname (string? nickname) - { - if (nickname == null) - { - nickname = ""; - } - - if (this._nickname != nickname) - { - this._nickname = nickname; - this.notify_property ("nickname"); - } - } - - internal void _update_family_name (string? family_name) - { - if (family_name != null) - { - if (this._structured_name == null) - { - this._structured_name = - new StructuredName (family_name, null, null, null, null); - } - else - { - this._structured_name.family_name = family_name; - } - - this.notify_property ("structured-name"); - } - } - - internal void _update_given_name (string? given_name) - { - if (given_name != null) - { - if (this._structured_name == null) - { - this._structured_name = - new StructuredName (null, given_name, null, null, null); - } - else - { - this._structured_name.given_name = given_name; - } - - this.notify_property ("structured-name"); - } - } - - internal void _update_additional_names (string? additional_names) - { - if (additional_names != null) - { - if (this._structured_name == null) - { - this._structured_name = - new StructuredName (null, null, additional_names, null, null); - } - else - { - this._structured_name.additional_names = additional_names; - } - - this.notify_property ("structured-name"); - } - } - - internal void _update_prefixes (string? prefixes) - { - if (prefixes != null) - { - if (this._structured_name == null) - { - this._structured_name = - new StructuredName (null, null, null, prefixes, null); - } - else - { - this._structured_name.prefixes = prefixes; - } - - this.notify_property ("structured-name"); - } - } - - internal void _update_suffixes (string? suffixes) - { - if (suffixes != null) - { - if (this._structured_name == null) - { - this._structured_name = - new StructuredName (null, null, null, null, suffixes); - } - else - { - this._structured_name.suffixes = suffixes; - } - - this.notify_property ("structured-name"); - } - } - - private void _update_postal_addresses () - { - string postal_field = this._cursor.get_string - (Trf.Fields.POSTAL_ADDRESS).dup (); - - if (postal_field == null) - { - return; - } - - var postal_addresses = new SmallSet<PostalAddressFieldDetails> ( - AbstractFieldDetails<PostalAddress>.hash_static, - AbstractFieldDetails<PostalAddress>.equal_static); - - string[] addresses_a = postal_field.split ("\n"); - - foreach (var a in addresses_a) - { - bool address_empty = true; - string[] a_info = a.split ("\t"); - for (int i = 0; i < a_info.length; i++) - { - if (a_info[i] != null && a_info[i] != "") - { - address_empty = false; - break; - } - } - - if (address_empty) - continue; - - var pa = new PostalAddress (a_info[Trf.PostalAddressFields.POBOX], - a_info[Trf.PostalAddressFields.EXTENDED_ADDRESS], - a_info[Trf.PostalAddressFields.STREET_ADDRESS], - a_info[Trf.PostalAddressFields.LOCALITY], - a_info[Trf.PostalAddressFields.REGION], - a_info[Trf.PostalAddressFields.POSTALCODE], - a_info[Trf.PostalAddressFields.COUNTRY], - null, - null); - if (!pa.is_empty ()) - { - var pafd = new PostalAddressFieldDetails (pa); - pafd.id = a_info[Trf.PostalAddressFields.TRACKER_ID]; - - postal_addresses.add (pafd); - } - } - - this._postal_addresses = postal_addresses; - this._postal_addresses_ro = this._postal_addresses.read_only_view; - - this.notify_property ("postal-addresses"); - } - - private void _update_local_ids () - { - string local_ids = this._cursor.get_string - (Trf.Fields.LOCAL_IDS_PROPERTY).dup (); - - if (local_ids == null) - { - return; - } - - this._set_local_ids (local_ids); - } - - internal bool _add_postal_address ( - PostalAddressFieldDetails postal_address_fd) - { - foreach (var pafd_cur in this._postal_addresses) - { - if (postal_address_fd.value.equal (pafd_cur.value)) - { - return false; - } - } - - this._postal_addresses.add (postal_address_fd); - this.notify_property ("postal-addresses"); - return true; - } - - internal bool _remove_postal_address (string tracker_id) - { - foreach (var pafd in this._postal_addresses) - { - if (pafd.id == tracker_id) - { - this._postal_addresses.remove (pafd); - this.notify_property ("postal-addresses"); - return true; - } - } - return false; - } - - private void _update_gender () - { - string gender = this._cursor.get_string (Trf.Fields.GENDER).dup (); - int gender_id = 0; - - if (gender != null) - { - gender_id = int.parse (gender); - } - - this._set_gender (gender_id); - } - - internal void _set_gender (int gender_id) - { - if (gender_id == 0) - { - this._gender = Gender.UNSPECIFIED; - } - else - { - var trf_store = (Trf.PersonaStore) this.store; - - if (gender_id == trf_store.get_gender_male_id ()) - { - this._gender = Gender.MALE; - } - else if (gender_id == trf_store.get_gender_female_id ()) - { - this._gender = Gender.FEMALE; - } - } - - this.notify_property ("gender"); - } - - private void _update_note () - { - string note = this._cursor.get_string (Trf.Fields.NOTE).dup (); - this._set_note (note); - } - - internal void _set_note (string? note_content) - { - if (note_content != null) - { - var note = new NoteFieldDetails (note_content); - this._notes.add ((owned) note); - } - else - { - this._notes.clear (); - } - this.notify_property ("notes"); - } - - private void _update_bday () - { - string bday = this._cursor.get_string (Trf.Fields.BIRTHDAY).dup (); - this._set_birthday (bday); - } - - internal void _set_birthday (string? birthday) - { - if (birthday != null && birthday != "") - { - TimeVal t = TimeVal (); - if (t.from_iso8601 (birthday)) - { - /* Note: This could return null if the timeval is invalid - * (e.g. out of range). That's OK. */ - this._birthday = new DateTime.from_timeval_utc (t); - this.notify_property ("birthday"); - } - } - else - { - if (this._birthday != null) - { - this._birthday = null; - this.notify_property ("birthday"); - } - } - } - - private void _update_roles () - { - string roles_field = this._cursor.get_string ( - Trf.Fields.ROLES).dup (); - - if (roles_field == null) - { - return; - } - - SmallSet<RoleFieldDetails> role_fds = new SmallSet<RoleFieldDetails> ( - AbstractFieldDetails<Role>.hash_static, - AbstractFieldDetails<Role>.equal_static); - - string[] roles_a = roles_field.split ("\n"); - - foreach (var r in roles_a) - { - string[] r_info = r.split ("\t"); - var tracker_id = r_info[Trf.RoleFields.TRACKER_ID]; - var role = r_info[Trf.RoleFields.ROLE]; - var title = r_info[Trf.RoleFields.TITLE]; - var organisation = r_info[Trf.RoleFields.DEPARTMENT]; - - var new_role = new Role (title, organisation, null); - new_role.role = role; - if (!new_role.is_empty ()) - { - var role_fd = new RoleFieldDetails (new_role); - role_fd.id = tracker_id; - role_fds.add (role_fd); - } - } - - this._roles = role_fds; - this._roles_ro = this._roles.read_only_view; - - this.notify_property ("roles"); - } - - internal bool _add_role (string tracker_id, string? role, string? title, string? org) - { - var new_role = new Role (title, org, null); - new_role.role = role; - if (!new_role.is_empty ()) - { - var role_fd = new RoleFieldDetails (new_role); - role_fd.id = tracker_id; - if (this._roles.add (role_fd)) - { - this.notify_property ("roles"); - return true; - } - } - return false; - } - - internal bool _remove_role (string tracker_id) - { - foreach (var role_fd in this._roles) - { - if (role_fd.id == tracker_id) - { - this._roles.remove (role_fd); - this.notify_property ("roles"); - return true; - } - } - - return false; - } - - private void _update_names () - { - string fullname = this._cursor.get_string (Trf.Fields.FULL_NAME).dup (); - this._update_full_name (fullname); - - string nickname = this._cursor.get_string (Trf.Fields.NICKNAME).dup (); - this._update_nickname (nickname); - - string family_name = this._cursor.get_string ( - Trf.Fields.FAMILY_NAME).dup (); - this._update_family_name (family_name); - - string given_name = this._cursor.get_string ( - Trf.Fields.GIVEN_NAME).dup (); - this._update_given_name (given_name); - - string additional_names = this._cursor.get_string ( - Trf.Fields.ADDITIONAL_NAMES).dup (); - this._update_additional_names (additional_names); - - string prefixes = this._cursor.get_string (Trf.Fields.PREFIXES).dup (); - this._update_prefixes (prefixes); - - string suffixes = this._cursor.get_string (Trf.Fields.SUFFIXES).dup (); - this._update_suffixes (suffixes); - } - - private void _update_avatar () - { - string avatar_url = this._cursor.get_string ( - Trf.Fields.AVATAR_URL).dup (); - this._set_avatar_from_uri (avatar_url); - } - - internal bool _set_avatar_from_uri (string? avatar_url) - { - LoadableIcon _avatar = null; - if (avatar_url != null && avatar_url != "") - { - _avatar = new FileIcon (File.new_for_uri (avatar_url)); - } - - this._set_avatar (_avatar); - - return true; - } - - internal bool _set_avatar (LoadableIcon? avatar) - { - this._avatar = avatar; - this.notify_property ("avatar"); - return true; - } - - internal bool _set_local_ids (string local_ids) - { - this._local_ids = - (HashSet<string>) Trf.PersonaStore.unserialize_local_ids (local_ids); - this._local_ids_ro = this._local_ids.read_only_view; - this.notify_property ("local-ids"); - return true; - } - - internal bool _set_web_service_addrs (string ws_addrs) - { - this._web_service_addresses = - (HashMultiMap<string, WebServiceFieldDetails>) - Trf.PersonaStore.unserialize_web_services (ws_addrs); - this.notify_property ("web-service-addresses"); - return true; - } - - private void _update_im_addresses () - { - string addresses = this._cursor.get_string ( - Trf.Fields.IM_ADDRESSES).dup (); - - if (addresses == null) - { - return; - } - - this._im_addresses.clear (); - - string[] addresses_a = addresses.split ("\n"); - - foreach (var addr in addresses_a) - { - string[] addr_info = addr.split ("\t"); - var tracker_id = addr_info[Trf.IMFields.TRACKER_ID]; - var proto = addr_info[Trf.IMFields.PROTO]; - var account_id = addr_info[Trf.IMFields.ID]; - var nickname = addr_info[Trf.IMFields.IM_NICKNAME]; - if (nickname == null) - nickname = ""; - - this._update_nickname (nickname); - this._add_im_address (tracker_id, proto, account_id, false); - } - - this.notify_property ("im-addresses"); - } - - internal bool _add_im_address (string tracker_id, string im_proto, - string account_id, bool notify = true) - { - try - { - var normalised_addr = ImDetails.normalise_im_address - (account_id, im_proto); - var im_fd = new ImFieldDetails (normalised_addr); - - this._im_addresses.set (im_proto, im_fd); - - var im_proto_map = new HashMap<string, string> (); - im_proto_map.set (im_proto, account_id); - this._tracker_ids_ims.set (tracker_id, im_proto_map); - - if (notify) - { - this.notify_property ("im-addresses"); - } - } - catch (Folks.ImDetailsError e) - { - GLib.warning ( - "Problem when trying to normalise address: %s\n", - e.message); - } - - return true; - } - - internal bool _remove_im_address (string tracker_id, bool notify = true) - { - var proto_im = this._tracker_ids_ims.get (tracker_id); - - if (proto_im == null) - return false; - - string proto = null; - string im_addr = null; - foreach (var pr in proto_im.keys) - { - proto = pr; - im_addr = proto_im[proto]; - break; - } - - var im_fd = new ImFieldDetails (im_addr); - if (proto != null && im_addr != null && - this._im_addresses.remove (proto, im_fd)) - { - this._tracker_ids_ims.unset (tracker_id); - if (notify) - { - this.notify_property ("im-addresses"); - } - - return true; - } - - return false; - } - - private void _update_phones () - { - string phones_field = this._cursor.get_string (Trf.Fields.PHONES).dup (); - - if (phones_field == null) - { - return; - } - - var phones = new SmallSet<PhoneFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - string[] phones_a = phones_field.split ("\n"); - - foreach (var p in phones_a) - { - if (p != null && p != "") - { - string[] p_info = p.split ("\t"); - var phone_fd = - new PhoneFieldDetails (p_info[Trf.PhoneFields.PHONE]); - phone_fd.id = p_info[Trf.PhoneFields.TRACKER_ID]; - phones.add (phone_fd); - } - } - - this._phone_numbers = phones; - this._phone_numbers_ro = this._phone_numbers.read_only_view; - - this.notify_property ("phone-numbers"); - } - - internal bool _add_phone (string phone, string tracker_id) - { - bool found = false; - - foreach (var p in this._phone_numbers) - { - if (p.id == tracker_id) - { - found = true; - break; - } - } - - if (!found) - { - var phone_fd = new PhoneFieldDetails (phone); - phone_fd.id = tracker_id; - this._phone_numbers.add (phone_fd); - this.notify_property ("phone-numbers"); - } - - return !found; - } - - internal bool _remove_phone (string tracker_id) - { - bool found = false; - - foreach (var p in this._phone_numbers) - { - if (p.id == tracker_id) - { - this._phone_numbers.remove (p); - found = true; - break; - } - } - - if (found) - { - this.notify_property ("phone-numbers"); - } - - return found; - } - - internal bool _add_email (string addr, string tracker_id) - { - bool found = false; - - foreach (var email_fd in this._email_addresses) - { - if (email_fd.get_parameter_values ("tracker_id").contains ( - tracker_id)) - { - found = true; - break; - } - } - - if (!found) - { - var email_fd = new EmailFieldDetails (addr); - email_fd.set_parameter ("tracker_id", tracker_id); - this._email_addresses.add (email_fd); - this.notify_property ("email-addresses"); - } - - return !found; - } - - internal bool _remove_email (string tracker_id) - { - bool found = false; - - foreach (var email_fd in this._email_addresses) - { - if (email_fd.get_parameter_values ("tracker_id").contains ( - tracker_id)) - { - this._email_addresses.remove (email_fd); - found = true; - break; - } - } - - if (found) - { - this.notify_property ("email-addresses"); - } - - return found; - } - - private void _update_email_addresses () - { - string emails_field = this._cursor.get_string (Trf.Fields.EMAILS).dup (); - - if (emails_field == null) - { - return; - } - - var email_addresses = new SmallSet<EmailFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - string[] emails_a = emails_field.split (","); - - foreach (var e in emails_a) - { - if (e != null && e != "") - { - string[] id_addr = e.split ("\t"); - var fd = new EmailFieldDetails (id_addr[Trf.EmailFields.EMAIL]); - fd.set_parameter ("tracker_id", - id_addr[Trf.EmailFields.TRACKER_ID]); - email_addresses.add (fd); - } - } - - this._email_addresses = email_addresses; - this._email_addresses_ro = this._email_addresses.read_only_view; - - this.notify_property ("email-addresses"); - } - - private void _update_urls () - { - var url_fds = new SmallSet<UrlFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var _urls_field = this._cursor.get_string (Trf.Fields.URLS).dup (); - - if (_urls_field == null) - return; - - string[] urls_table = _urls_field.split ("\n"); - - foreach (var row in urls_table) - { - string[] u = row.split ("\t"); - var tracker_id = u[Trf.UrlsFields.TRACKER_ID]; - - for (int i=1; i< u.length; i++) - { - if (u[i] == null || u[i] == "") - continue; - - string? type = null; - switch (i) - { - case Trf.UrlsFields.BLOG: - type = UrlFieldDetails.PARAM_TYPE_BLOG; - break; - case Trf.UrlsFields.WEBSITE: - type = UrlFieldDetails.PARAM_TYPE_HOME_PAGE; - break; - case Trf.UrlsFields.URL: - /* No specific type is appropriate. */ - break; - } - - var url_fd = new UrlFieldDetails (u[i]); - url_fd.set_parameter ("tracker_id", tracker_id); - - if (type != null) - { - url_fd.set_parameter (AbstractFieldDetails.PARAM_TYPE, type); - } - - url_fds.add (url_fd); - } - } - - this._urls = url_fds; - this._urls_ro = this._urls.read_only_view; - - this.notify_property ("urls"); - } - - internal bool _add_url (string url, string tracker_id, string? type = null) - { - bool found = false; - - foreach (var url_fd in this._urls) - { - if (url_fd.get_parameter_values ("tracker_id").contains (tracker_id)) - { - found = true; - break; - } - } - - if (!found) - { - var url_fd = new UrlFieldDetails (url); - url_fd.set_parameter ("tracker_id", tracker_id); - - if (type != null) - { - url_fd.set_parameter (AbstractFieldDetails.PARAM_TYPE, type); - } - - this._urls.add (url_fd); - this.notify_property ("urls"); - } - - return !found; - } - - internal bool _remove_url (string tracker_id) - { - bool found = false; - - foreach (var url_fd in this._urls) - { - if (url_fd.get_parameter_values ("tracker_id").contains (tracker_id)) - { - this._urls.remove (url_fd); - found = true; - } - } - - if (found) - this.notify_property ("urls"); - - return found; - } - - private void _update_favourite () - { - var favourite = this._cursor.get_string (Trf.Fields.FAVOURITE).dup (); - var is_favourite = false; - - if (favourite != null) - { - var trf_store = (Trf.PersonaStore) this.store; - int favorite_tracker_id = trf_store.get_favorite_id (); - foreach (var tag in favourite.split (",")) - { - if (int.parse (tag) == favorite_tracker_id) - { - is_favourite = true; - } - } - } - - if (is_favourite != this._is_favourite) - { - this._is_favourite = is_favourite; - this.notify_property ("is-favourite"); - } - } - - /** - * This method sets the is_favourite attribute internally. - * That is, it should be used as a result of an event fired by - * Tracker since this method doesn't propagate changes back - * to Tracker again. - */ - internal void _set_favourite (bool is_fav) - { - this._is_favourite = is_fav; - this.notify_property ("is-favourite"); - } -} diff --git a/backends/tracker/lib/trf-util.vala b/backends/tracker/lib/trf-util.vala deleted file mode 100644 index 9b10cb34..00000000 --- a/backends/tracker/lib/trf-util.vala +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (C) 2011 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: - * Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - */ - - -using Gee; -using Tracker; -using Tracker.Sparql; - -public struct Event -{ - int graph_id; - int subject_id; - int pred_id; - int object_id; -} - -[DBus (name = "org.freedesktop.Tracker1.Resources")] -private interface Resources : DBusProxy { - [DBus (name = "GraphUpdated")] - public signal void graph_updated - (string class_name, Event[] deletes, Event[] inserts); -} - -internal class Trf.AfflInfo : Object -{ - public string im_tracker_id { get; set; } - - public string im_proto { get; set; } - - public string im_account_id { get; set; } - - public string im_nickname { get; set; } - - public string affl_tracker_id { get; set; } - - public string title { get; set; } - - public string org { get; set; } - - public string role { get; set; } - - public Folks.PostalAddressFieldDetails postal_address_fd; - - public string email { get; set; } - - public string phone { get; set; } - - public string website { get; set; } - - public string blog { get; set; } - - public string url { get; set; } - - public string to_string () - { - string ret = " { "; - bool first = true; - var properties = this.get_class ().list_properties (); - - foreach (unowned ParamSpec pspec in properties) - { - var property = pspec.get_name (); - var prop_value = Value (pspec.value_type); - this.get_property (property, ref prop_value); - string value = prop_value.get_string (); - - if (first == false) - ret += ", "; - - ret += "%s : %s".printf (property, value); - first = false; - } - - ret += " } "; - - return ret; - } -} - -public class Trf.OntologyDefs : Object -{ - public const string DEFAULT_CONTACT_URN = - "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#default-contact-me"; - public const string PERSON_CLASS = - "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#PersonContact"; - public const string NCO_FULLNAME = "nco:fullname"; - public const string NCO_FAMILY = "nco:nameFamily"; - public const string NCO_GIVEN = "nco:nameGiven"; - public const string NCO_ADDITIONAL = "nco:nameAdditional"; - public const string NCO_SUFFIX = "nco:nameHonorificSuffix"; - public const string NCO_PREFIX = "nco:nameHonorificPrefix"; - public const string NCO_NICKNAME = "nco:nickname"; - public const string RDF_TYPE = "ns:type"; - public const string NCO_PERSON = "nco:PersonContact"; - public const string NCO_URL = "nco:url"; - public const string NCO_WEBSITE = "nco:websiteUrl"; - public const string NCO_BLOG = "nco:blogUrl"; - public const string NAO_FAVORITE = "nao:predefined-tag-favorite"; - public const string NAO_TAG = "nao:hasTag"; - public const string NAO_PROPERTY = "nao:Property"; - public const string NAO_HAS_PROPERTY = "nao:hasProperty"; - public const string NAO_PROPERTY_NAME = "nao:propertyName"; - public const string NAO_PROPERTY_VALUE = "nao:propertyValue"; - public const string NCO_HAS_EMAIL = "nco:hasEmailAddress"; - public const string NCO_EMAIL = "nco:EmailAddress"; - public const string NCO_EMAIL_PROP = "nco:emailAddress"; - public const string NCO_HAS_PHONE = "nco:hasPhoneNumber"; - public const string NCO_PHONE = "nco:PhoneNumber"; - public const string NCO_PHONE_PROP = "nco:phoneNumber"; - public const string NCO_HAS_AFFILIATION = "nco:hasAffiliation"; - public const string NCO_AFFILIATION = "nco:Affiliation"; - public const string NCO_BIRTHDAY = "nco:birthDate"; - public const string NCO_NOTE = "nco:note"; - public const string NCO_GENDER = "nco:gender"; - public const string NCO_MALE = "nco:gender-male"; - public const string NCO_FEMALE = "nco:gender-female"; - public const string NCO_PHOTO = "nco:photo"; - public const string NIE_URL = "nie:url"; - public const string NFO_IMAGE = "nfo:Image"; - public const string NIE_DATAOBJECT = "nie:DataObject"; - public const string NCO_IMADDRESS = "nco:IMAddress"; - public const string NCO_HAS_IMADDRESS = "nco:hasIMAddress"; - public const string NCO_IMPROTOCOL = "nco:imProtocol"; - public const string NCO_IMID = "nco:imID"; - public const string NCO_IM_NICKNAME = "nco:imNickname"; - public const string NCO_POSTAL_ADDRESS = "nco:PostalAddress"; - public const string NCO_HAS_POSTAL_ADDRESS = "nco:hasPostalAddress"; - public const string NCO_POBOX = "nco:pobox"; - public const string NCO_DISTRICT = "nco:district"; - public const string NCO_COUNTY = "nco:county"; - public const string NCO_LOCALITY = "nco:locality"; - public const string NCO_POSTALCODE = "nco:postalcode"; - public const string NCO_STREET_ADDRESS = "nco:streetAddress"; - public const string NCO_ADDRESS_LOCATION = "nco:addressLocation"; - public const string NCO_EXTENDED_ADDRESS = "nco:extendedAddress"; - public const string NCO_COUNTRY = "nco:country"; - public const string NCO_REGION = "nco:region"; - public const string NCO_ROLE = "nco:role"; - public const string NCO_TITLE = "nco:title"; - public const string NCO_ORG = "nco:org"; - public const string NCO_URL_PREFIX = - "<http://www.semanticdesktop.org/ontologies/2007/03/22/"; - public const string NAO_URL_PREFIX = - "<http://www.semanticdesktop.org/ontologies/2007/08/15/"; - public const string RDF_URL_PREFIX = - "<http://www.w3.org/1999/02/"; -} diff --git a/backends/tracker/meson.build b/backends/tracker/meson.build deleted file mode 100644 index 2c22237e..00000000 --- a/backends/tracker/meson.build +++ /dev/null @@ -1,37 +0,0 @@ -# The tracker backend -tracker_backend_name = 'tracker' - -# Backend library -subdir('lib') - -tracker_backend_sources = [ - 'tr-backend-factory.vala', - 'tr-backend.vala', -] - -tracker_backend_deps = [ - backend_deps, - tracker_sparql_dep, - tracker_backendlib_dep, -] - -tracker_backend_vala_flags = [ -] - -tracker_backend_c_flags = [ - '-include', 'config.h', - '-DBACKEND_NAME="@0@"'.format(tracker_backend_name), - '-DG_LOG_DOMAIN="@0@"'.format(tracker_backend_name), -] - -tracker_backend = shared_library(tracker_backend_name, - tracker_backend_sources, - dependencies: tracker_backend_deps, - vala_args: tracker_backend_vala_flags, - c_args: tracker_backend_c_flags, - name_prefix: '', - install_dir: folks_backend_dir / tracker_backend_name, - install: true, -) - -folks_backends += tracker_backend diff --git a/backends/tracker/tr-backend-factory.vala b/backends/tracker/tr-backend-factory.vala deleted file mode 100644 index 1ff07af5..00000000 --- a/backends/tracker/tr-backend-factory.vala +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2009 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>. - * Copyright (C) 2009 Nokia Corporation. - * Copyright (C) 2010 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: Zeeshan Ali (Khattak) <zeeshanak@gnome.org> - * Travis Reitter <travis.reitter@collabora.co.uk> - * Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - * This file was originally part of Rygel. - */ - -using Folks; - -/** - * The Tracker backend module entry point. - * - * @backend_store a store to add the Tracker backends to - */ -public void module_init (BackendStore backend_store) -{ - backend_store.add_backend (new Folks.Backends.Tr.Backend ()); -} - -/** - * The tracker backend module exit point. - * - * @param backend_store the store to remove the backends from - */ -public void module_finalize (BackendStore backend_store) -{ - /* FIXME: No way to remove backends from the store. */ -} diff --git a/backends/tracker/tr-backend.vala b/backends/tracker/tr-backend.vala deleted file mode 100644 index bd239985..00000000 --- a/backends/tracker/tr-backend.vala +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (C) 2011 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: - * Travis Reitter <travis.reitter@collabora.co.uk> - * Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - */ - -using Folks; -using Folks.Backends.Tr; -using GLib; -using Gee; - -extern const string BACKEND_NAME; - -/** - * A backend which connects to Tracker and creates a {@link PersonaStore} - * for each service. - */ -public class Folks.Backends.Tr.Backend : Folks.Backend -{ - private bool _is_prepared = false; - private bool _prepare_pending = false; /* used by unprepare() too */ - private bool _is_quiescent = false; - private HashMap<string, PersonaStore> _persona_stores; - private Map<string, PersonaStore> _persona_stores_ro; - - /** - * {@inheritDoc} - */ - public override string name { get { return BACKEND_NAME; } } - - /** - * {@inheritDoc} - */ - public override Map<string, PersonaStore> persona_stores - { - get { return this._persona_stores_ro; } - } - - /** - * {@inheritDoc} - */ - public override void enable_persona_store (Folks.PersonaStore store) - { - if (this._persona_stores.has_key (store.id) == false) - { - this._add_store ((Trf.PersonaStore) store); - } - } - - /** - * {@inheritDoc} - */ - public override void disable_persona_store (Folks.PersonaStore store) - { - if (this._persona_stores.has_key (store.id)) - { - this._store_removed_cb (store); - } - } - - /** - * {@inheritDoc} - */ - public override void set_persona_stores (Set<string>? storeids) - { - if (storeids != null) - { - if (storeids.size == 0) - { - this.disable_persona_store (this._persona_stores.get (BACKEND_NAME)); - } - else - { - this._add_default_persona_store (); - } - } - else - { - this._add_default_persona_store (); - } - } - - /** - * {@inheritDoc} - */ - public Backend () - { - Object (); - } - - construct - { - this._persona_stores = new HashMap<string, PersonaStore> (); - this._persona_stores_ro = this._persona_stores.read_only_view; - } - - /** - * Whether this Backend has been prepared. - * - * See {@link Folks.Backend.is_prepared}. - */ - public override bool is_prepared - { - get { return this._is_prepared; } - } - - /** - * Whether this Backend has reached a quiescent state. - * - * See {@link Folks.Backend.is_quiescent}. - * - * @since 0.6.2 - */ - public override bool is_quiescent - { - get { return this._is_quiescent; } - } - - /** - * {@inheritDoc} - * - */ - public override async void prepare () throws GLib.Error - { - Internal.profiling_start ("preparing Tr.Backend"); - - if (this._is_prepared || this._prepare_pending) - { - return; - } - - try - { - this._prepare_pending = true; - this.freeze_notify (); - - this._add_default_persona_store (); - - this._is_prepared = true; - this.notify_property ("is-prepared"); - - this._is_quiescent = true; - this.notify_property ("is-quiescent"); - } - finally - { - this.thaw_notify (); - this._prepare_pending = false; - } - - Internal.profiling_end ("preparing Tr.Backend"); - } - - /** - * {@inheritDoc} - */ - public override async void unprepare () throws GLib.Error - { - if (!this._is_prepared || this._prepare_pending) - { - return; - } - - try - { - this._prepare_pending = true; - this.freeze_notify (); - - foreach (var persona_store in this._persona_stores.values) - { - this.persona_store_removed (persona_store); - } - - this._persona_stores.clear (); - this.notify_property ("persona-stores"); - - this._is_quiescent = false; - this.notify_property ("is-quiescent"); - - this._is_prepared = false; - this.notify_property ("is-prepared"); - } - finally - { - this.thaw_notify (); - this._prepare_pending = false; - } - } - - /** - * Add a the default Persona Store. - */ - private void _add_default_persona_store () - { - if (this._persona_stores.has_key (BACKEND_NAME) == false) - { - var store = new Trf.PersonaStore (); - this._add_store (store); - } - } - - /** - * Utility function to add a persona store. - * - * @param store the store to add. - * @param notify whether or not to emit notification signals. - */ - private void _add_store (PersonaStore store, bool notify = true) - { - this._persona_stores.set (store.id, store); - store.removed.connect (this._store_removed_cb); - this.persona_store_added (store); - if (notify) - { - this.notify_property ("persona-stores"); - } - } - - private void _store_removed_cb (Folks.PersonaStore store) - { - store.removed.disconnect (this._store_removed_cb); - this.persona_store_removed (store); - this._persona_stores.unset (store.id); - } -} diff --git a/docs/meson.build b/docs/meson.build index 4d5ae34b..7ace84bd 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -52,15 +52,6 @@ if telepathy_backend_enabled } endif -if tracker_backend_enabled - valadoc_targets += { - 'name': 'folks-tracker', - 'source_files': tracker_backendlib_sources, - 'library': tracker_backendlib, - 'dependencies': tracker_backendlib_doc_deps, - } -endif - # First, the devhelp modules subdir('devhelp') diff --git a/docs/wiki/debugging.valadoc b/docs/wiki/debugging.valadoc index c7bd6b9b..5100932f 100644 --- a/docs/wiki/debugging.valadoc +++ b/docs/wiki/debugging.valadoc @@ -10,7 +10,6 @@ Available values for folks for the ''G_MESSAGES_DEBUG'' environment variable are * ''eds'' (for the evolution-data-server backend) * ''key-file'' (for the key file backend) * ''telepathy'' (for the Telepathy backend) - * ''tracker'' (for the Tracker backend) Multiple values can be specified using commas, e.g.: ''G_MESSAGES_DEBUG=folks,eds,key-file''. diff --git a/folks/build-conf.vapi b/folks/build-conf.vapi index 6567436f..36853a2a 100644 --- a/folks/build-conf.vapi +++ b/folks/build-conf.vapi @@ -63,12 +63,6 @@ public class Folks.BuildConf [CCode (cname = "HAVE_TELEPATHY")] public static bool HAVE_TELEPATHY; - [CCode (cname = "HAVE_TRACKER")] - public static bool HAVE_TRACKER; - - [CCode (cname = "TRACKER_SPARQL_MAJOR")] - public const string TRACKER_SPARQL_MAJOR; - [CCode (cname = "ABS_TOP_BUILDDIR")] public const string ABS_TOP_BUILDDIR; diff --git a/meson.build b/meson.build index 123edb5c..5dc066ee 100644 --- a/meson.build +++ b/meson.build @@ -30,7 +30,6 @@ folks_lib_version = '25.21.0' # incompatible changes are made in the backend library APIs themselves. folks_eds_lib_version = '25.21.0' folks_telepathy_lib_version = '25.21.0' -folks_tracker_lib_version = '25.21.0' folks_dummy_lib_version = '25.21.0' # The module version is used to set the shared object versions @@ -58,7 +57,6 @@ tests_enabled = get_option('tests') installed_tests_enabled = get_option('installed_tests') ofono_backend_enabled = get_option('ofono_backend') telepathy_backend_enabled = get_option('telepathy_backend') -tracker_backend_enabled = get_option('tracker_backend') zeitgeist_enabled = get_option('zeitgeist') import_tool_enabled = get_option('import_tool') inspect_tool_enabled = get_option('inspect_tool') @@ -93,24 +91,6 @@ if telepathy_backend_enabled endif endif -if tracker_backend_enabled - tracker_sparql_accepted_versions = [ '0.16', '0.18', '1.0', '2.0' ] - foreach version : tracker_sparql_accepted_versions - tracker_sparql_dep = dependency('tracker-sparql-@0@'.format(version), - version: '>= 0.15.2', - required: false, - ) - if tracker_sparql_dep.found() - tracker_sparql_version = version - break - endif - endforeach - - if not tracker_sparql_dep.found() - error('Tracker backend enabld, but couldn\'t find tracker-sparql package') - endif -endif - if eds_backend_enabled libebook_dep = dependency('libebook-1.2', version: '>=' + min_eds_version) libebook_contacts_dep = dependency('libebook-contacts-1.2', version: '>=' + min_eds_version) @@ -172,14 +152,10 @@ conf.set10('HAVE_BLUEZ', bluez_backend_enabled) conf.set10('HAVE_EDS', eds_backend_enabled) conf.set10('HAVE_OFONO', ofono_backend_enabled) conf.set10('HAVE_TELEPATHY', telepathy_backend_enabled) -conf.set10('HAVE_TRACKER', tracker_backend_enabled) if eds_backend_enabled conf.set_quoted('EDS_SOURCES_SERVICE_NAME', eds_sources_service_name) conf.set_quoted('EDS_ADDRESS_BOOK_SERVICE_NAME', eds_address_book_service_name) endif -if tracker_backend_enabled - conf.set_quoted('TRACKER_SPARQL_MAJOR', tracker_sparql_version) -endif configure_file(output: 'config.h', configuration: conf) config_h_dir = include_directories('.') diff --git a/meson_options.txt b/meson_options.txt index 62a9603c..f631e6bd 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -3,7 +3,6 @@ option('bluez_backend', type: 'boolean', value: true, description: 'build the Bl option('eds_backend', type: 'boolean', value: true, description: 'build the E-D-S backend') option('ofono_backend', type: 'boolean', value: true, description: 'build the oFono backend') option('telepathy_backend', type: 'boolean', value: true, description: 'build the Telepathy backend') -option('tracker_backend', type: 'boolean', value: false, description: 'build the Tracker backend') option('zeitgeist', type: 'boolean', value: false, description: 'build Zeitgeist support in the Telepathy backend') # Tools option('import_tool', type: 'boolean', value: true, description: 'Enable building the meta-contact import tool') diff --git a/po/POTFILES.in b/po/POTFILES.in index eb3537f0..8b869edc 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -8,7 +8,6 @@ backends/ofono/ofono-backend.vala backends/telepathy/lib/tp-lowlevel.c backends/telepathy/lib/tpf-persona-store.vala backends/telepathy/lib/tpf-persona.vala -backends/tracker/lib/trf-persona-store.vala folks/alias-details.vala folks/anti-linkable.vala folks/avatar-details.vala diff --git a/po/POTFILES.skip b/po/POTFILES.skip index 62769ac3..9e26b88b 100644 --- a/po/POTFILES.skip +++ b/po/POTFILES.skip @@ -7,7 +7,6 @@ backends/key-file/kf-persona.c backends/ofono/ofono-backend.c backends/telepathy/lib/tpf-persona-store.c backends/telepathy/lib/tpf-persona.c -backends/tracker/lib/trf-persona-store.c docs/gtk-doc/folks-telepathy/ccomments/tp-lowlevel.c folks/alias-details.c folks/anti-linkable.c diff --git a/tests/lib/meson.build b/tests/lib/meson.build index b61c7db7..c6fb7c38 100644 --- a/tests/lib/meson.build +++ b/tests/lib/meson.build @@ -61,6 +61,3 @@ if eds_backend_enabled subdir('eds') endif -if tracker_backend_enabled - subdir('tracker') -endif diff --git a/tests/lib/test-case.vala b/tests/lib/test-case.vala index 838ba8dd..afb98c76 100644 --- a/tests/lib/test-case.vala +++ b/tests/lib/test-case.vala @@ -160,8 +160,7 @@ public abstract class Folks.TestCase : Object error ("unable to create '%s': %s", local, GLib.strerror (GLib.errno)); - /* Unset some things we don't want to inherit. In particular, - * Tracker might try to index XDG_*_DIR, which we don't want. */ + /* Unset some things we don't want to inherit. */ Environment.unset_variable ("XDG_DESKTOP_DIR"); Environment.unset_variable ("XDG_DOCUMENTS_DIR"); Environment.unset_variable ("XDG_DOWNLOAD_DIR"); diff --git a/tests/lib/tracker/backend.vala b/tests/lib/tracker/backend.vala deleted file mode 100644 index 25cafa0a..00000000 --- a/tests/lib/tracker/backend.vala +++ /dev/null @@ -1,558 +0,0 @@ -/* - * Copyright (C) 2011 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 :Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker; -using Tracker.Sparql; - -errordomain TrackerTest.BackendSetupError -{ - ADD_CONTACT_FAILED, -} - -public class TrackerTest.Backend -{ - public const string URN = "urn:contact"; - public const string URLS = "nco:urls"; - public bool debug { get; set; } - private GLib.List<Gee.HashMap<string, string>> _contacts; - private Tracker.Sparql.Connection? _connection; - - - public Backend () - { - this.debug = false; - this._contacts = new GLib.List<Gee.HashMap<string, string>> (); - } - - public void add_contact (Gee.HashMap<string, string> c) - { - var contact = this._copy_hash_map (c); - this._contacts.prepend (contact); - } - - /* Remove contacts */ - public void tear_down () - { - this.reset (); - this._connection = null; - } - - public void reset () - { - this._contacts = new GLib.List<Gee.HashMap<string, string>> (); - } - - /* Insert contacts */ - public void set_up () - { - try - { - this._setup_connection (); - this._add_contacts (); - } - catch (BackendSetupError e) - { - GLib.warning ("unable to create test data: %s\n", e.message); - } - } - - public bool update_contact (string contact_urn, string predicate, - string literal_subject) - { - const string delete_query_t = "DELETE { %s %s ?a } WHERE " + - "{ ?p a nco:PersonContact " + - " ; %s ?a . FILTER(?p = %s ) } "; - const string update_query_t = "INSERT { %s %s '%s' } "; - - string delete_query = delete_query_t.printf (contact_urn, predicate, - predicate, contact_urn); - if (this._do_update_query (delete_query) == false) - { - GLib.warning ("Couldn't delete the old triplet"); - return false; - } - - string update_query = update_query_t.printf (contact_urn, predicate, - literal_subject); - if (this._do_update_query (update_query) == false) - { - GLib.warning ("Couldn't insert the triplet"); - return false; - } - - return true; - } - - public bool update_favourite (string contact_urn, bool is_favourite) - { - string q = ""; - - if (is_favourite) - { - q += "INSERT { "; - } - else - { - q += "DELETE { "; - } - q += contact_urn + " nao:hasTag nao:predefined-tag-favorite } "; - - if (this._do_update_query (q) == false) - { - GLib.warning ("Couldn't change favourite status"); - return false; - } - - return true; - } - - public bool remove_contact (string tracker_id) - { - string delete_query = "DELETE { ?p a nco:PersonContact } "; - delete_query += "WHERE { ?p a nco:PersonContact . FILTER(tracker:id(?p) "; - delete_query += "= " + tracker_id + ") } "; - - if (this._do_update_query (delete_query) == false) - { - GLib.warning ("Couldn't delete the contact"); - return false; - } - - return true; - } - - public bool remove_triplet (string subject_urn, string pred, - string object_urn) - { - var builder = new Tracker.Sparql.Builder.update (); - builder.delete_open (null); - builder.subject (subject_urn); - builder.predicate (pred); - builder.object (object_urn); - builder.delete_close (); - - if (this._do_update_query (builder.result) == false) - { - GLib.warning ("Couldn't delete triplet with query: %s\n", - builder.result); - return false; - } - - return true; - } - - public bool insert_triplet (string subject_iri, string pred, - string object_iri, - string? pred_b = null, string? obj_literal_b = null, - string? pred_c = null, string? obj_literal_c = null) - { - var builder = new Tracker.Sparql.Builder.update (); - builder.insert_open (null); - builder.subject (subject_iri); - builder.predicate (pred); - builder.object (object_iri); - - if (pred_b != null) - { - builder.predicate (pred_b); - builder.object_string (obj_literal_b); - } - - if (pred_c != null) - { - builder.predicate (pred_c); - builder.object_string (obj_literal_c); - } - - builder.insert_close (); - - if (this._do_update_query (builder.result) == false) - { - GLib.warning ("Couldn't insert triplet with query: %s\n", - builder.result); - return false; - } - - return true; - } - - private bool _do_update_query (string query) - { - bool ret = false; - - if (this.debug) - { - GLib.stdout.printf ("_do_update_query : %s\n", query); - } - - try - { - this._connection.update (query); - ret = true; - } - catch (Tracker.Sparql.Error e1) - { - GLib.warning ("Problem getting connection : %s\n", e1.message); - } - catch (GLib.IOError e2) - { - GLib.warning ("Problem saving data : %s\n", e2.message); - } - catch (GLib.DBusError e3) - { - GLib.warning ("Problem with the D-Bus connection : %s\n", e3.message); - } - catch (GLib.Error e4) - { - GLib.warning ("Problem in general: %s", e4.message); - } - - return ret; - } - - private Gee.HashMap<string, string> _copy_hash_map ( - Gee.HashMap<string, string> orig) - { - Gee.HashMap<string, string> copy = new Gee.HashMap<string, string> (); - foreach (var k in orig.keys) - { - var v = orig.get (k); - copy.set (k.dup (), v.dup ()); - } - return copy; - } - - private void _setup_connection () throws BackendSetupError - { - try - { - this._connection = Tracker.Sparql.Connection.get (); - } - catch (GLib.IOError e1) - { - throw new BackendSetupError.ADD_CONTACT_FAILED - ("Could not connect to D-Bus service : %s\n", e1.message); - } - catch (Tracker.Sparql.Error e2) - { - throw new BackendSetupError.ADD_CONTACT_FAILED - ("Error fetching SPARQL connection handler : %s\n", e2.message); - } - catch (GLib.DBusError e3) - { - throw new BackendSetupError.ADD_CONTACT_FAILED - ("Error fetching SPARQL connection handler : %s\n", e3.message); - } - catch (GLib.SpawnError e4) - { - throw new BackendSetupError.ADD_CONTACT_FAILED - ("Error fetching SPARQL connection handler : %s\n", e4.message); - } - } - - private void _add_contacts () throws BackendSetupError - { - string query = ""; - - this._contacts.reverse (); - foreach (var c in this._contacts) - { - query = query + "\n" + this._get_insert_query (c); - } - - try - { - this._connection.update (query); - } - catch (Tracker.Sparql.Error e1) - { - throw new BackendSetupError.ADD_CONTACT_FAILED - ("Problem getting connection : %s\n", e1.message); - } - catch (GLib.IOError e2) - { - throw new BackendSetupError.ADD_CONTACT_FAILED - ("Error fetching SPARQL connection handler : %s\n", e2.message); - } - catch (GLib.DBusError e3) - { - throw new BackendSetupError.ADD_CONTACT_FAILED - ("Could not connect to D-Bus service : %s\n", e3.message); - } - catch (GLib.Error e4) - { - GLib.warning ("Problem in general: %s", e4.message); - } - } - - private string _get_insert_query (Gee.HashMap<string, string> contact) - { - const string q_photo_uri_t = " . <%s> a nfo:Image, " + - "nie:DataObject ; nie:url '%s' ; nie:title '%s' "; - const string im_addr_t = " . <%s> a nco:IMAddress, " + - "nie:InformationElement; nco:imProtocol " + - "'%s' ; nco:imID '%s'; " + - "nco:imNickname '%s'; " + - "nco:imPresence nco:presence-status-available " + - " . <%smyimaccount> a nco:IMAccount; " + - "nco:imDisplayName '%s'; nco:hasIMContact " + - "<%s> "; - const string affl_t = " . <%smyaffiliation> a nco:Affiliation " + - " . <%smyaffiliation> nco:hasIMAddress " + - " <%s> "; - const string af_t = " . <affl:001> a nco:Affiliation; " + - "nco:title '%s'; nco:department '%s'; nco:role '%s' "; - const string postal_t = " . <affl:001> a nco:Affiliation ; " + - "nco:hasPostalAddress <postal:001> . " + - " <postal:001> a nco:PostalAddress ; " + - "nco:pobox '%s'; " + - "nco:district '%s'; " + - "nco:county '%s'; " + - "nco:locality '%s'; " + - "nco:postalcode '%s'; " + - "nco:streetAddress '%s'; " + - "nco:addressLocation '%s'; " + - "nco:extendedAddress '%s'; " + - "nco:country '%s'; " + - "nco:region '%s' "; - - string urn_contact; - if (contact.unset (TrackerTest.Backend.URN, out urn_contact) == false) - { - urn_contact = "_:x"; - } - - string photo_uri = ""; - string q = "INSERT { " + urn_contact + " a nco:PersonContact "; - Gee.HashMap<string, string> addresses = null; - string[] phones = null; - string[] emails = null; - string[] urls = null; - string affiliation = ""; - string postal_address = ""; - - foreach (var k in contact.keys) - { - string v = contact.get (k); - if (k == Trf.OntologyDefs.NCO_PHOTO) - { - photo_uri = v; - v = "<" + v + ">"; - } - else if (k == Trf.OntologyDefs.NCO_IMADDRESS) - { - addresses = this._parse_addrs (v); - k = ""; - v = ""; - foreach (var addr in addresses.keys) - { - string vtemp; - vtemp = " nco:hasAffiliation [ a nco:Affiliation ; "; - vtemp += "nco:hasIMAddress <" + addr + "> ] "; - if (v != "") - { - v += "; "; - } - v += vtemp; - } - } - else if (k == Trf.OntologyDefs.NCO_PHONE_PROP) - { - phones = v.split (","); - k = ""; - v = this._build_relation (Trf.OntologyDefs.NCO_HAS_AFFILIATION, - phones); - } - else if (k == Trf.OntologyDefs.NCO_EMAIL_PROP) - { - emails = v.split (","); - k = ""; - v = this._build_relation (Trf.OntologyDefs.NCO_HAS_AFFILIATION, - emails); - } - else if (k == TrackerTest.Backend.URLS) - { - urls = v.split (","); - k = ""; - v = this._build_relation (Trf.OntologyDefs.NCO_HAS_AFFILIATION, - urls); - } - else if (k == Trf.OntologyDefs.NAO_TAG) - { - v = Trf.OntologyDefs.NAO_FAVORITE; - } - else if (k == Trf.OntologyDefs.NCO_HAS_AFFILIATION) - { - affiliation = v; - v = "<affl:001>"; - } - else if (k == Trf.OntologyDefs.NCO_GENDER) - { - - } - else if (k == Trf.OntologyDefs.NCO_POSTAL_ADDRESS) - { - postal_address = v; - k = Trf.OntologyDefs.NCO_HAS_AFFILIATION; - v = "<affl:001>"; - } - else - { - v = "'" + v + "'"; - } - - q += "; "; - string s = k + " " + v; - q += s; - } - - if (photo_uri != "") - { - q += q_photo_uri_t.printf (photo_uri, photo_uri, photo_uri); - } - - if (addresses != null && addresses.size > 0) - { - foreach (var addr in addresses.keys) - { - string proto = addresses.get (addr); - string q1 = im_addr_t.printf (addr, proto, addr, addr, addr, - addr, addr); - - string q2 = affl_t.printf (addr, addr, addr); - - q += "%s%s".printf (q1, q2); - } - } - - if (phones != null && phones.length > 0) - { - foreach (var p in phones) - { - var phone_urn = "<phone:%s>".printf (p); - var affl = "<%s>".printf (p); - this.insert_triplet (phone_urn, "a", Trf.OntologyDefs.NCO_PHONE, - Trf.OntologyDefs.NCO_PHONE_PROP, p); - this.insert_triplet (affl, "a", Trf.OntologyDefs.NCO_AFFILIATION); - this.insert_triplet (affl, - Trf.OntologyDefs.NCO_HAS_PHONE, phone_urn); - } - } - - if (emails != null && emails.length > 0) - { - foreach (var p in emails) - { - var email_urn = "<email:%s>".printf (p); - var affl = "<%s>".printf (p); - this.insert_triplet (email_urn, "a", Trf.OntologyDefs.NCO_EMAIL, - Trf.OntologyDefs.NCO_EMAIL_PROP, p); - this.insert_triplet (affl, "a", Trf.OntologyDefs.NCO_AFFILIATION); - this.insert_triplet (affl, - Trf.OntologyDefs.NCO_HAS_EMAIL, email_urn); - } - } - - if (urls != null && urls.length > 0) - { - int i = 0; - foreach (var p in urls) - { - string website_type = ""; - var affl = "<%s>".printf (p); - switch (i % 3) - { - case 0: - website_type = Trf.OntologyDefs.NCO_WEBSITE; - break; - case 1: - website_type = Trf.OntologyDefs.NCO_BLOG; - break; - case 2: - website_type = "nco:url"; - break; - } - - this.insert_triplet (affl, "a", Trf.OntologyDefs.NCO_AFFILIATION, - website_type, p); - i++; - } - } - - if (affiliation != "") - { - string[] role_info = affiliation.split (","); - q += af_t.printf (role_info[0], role_info[1], role_info[2]); - } - - if (postal_address != "") - { - string[] postal_info = postal_address.split (":"); - q += postal_t.printf (postal_info[0], postal_info[1], - postal_info[2], postal_info[3], postal_info[4], - postal_info[5], postal_info[6], postal_info[7], - postal_info[8], postal_info[9]); - } - - q += " . }"; - - if (this.debug) - { - GLib.stdout.printf ("_get_insert_query : %s\n", q); - } - - return q; - } - - private Gee.HashMap<string, string> _parse_addrs (string addr_s) - { - Gee.HashMap<string, string> ret = new Gee.HashMap<string, string> (); - string[] im_addrs = addr_s.split (","); - - foreach (var a in im_addrs) - { - string[] info = a.split ("#"); - string proto = info[0]; - string addr = info[1]; - - ret.set ((owned) addr, (owned) proto); - } - - return ret; - } - - private string _build_relation (string predicate, string[] objects) - { - string ret = ""; - - foreach (var obj in objects) - { - string vtemp1; - vtemp1 = " " + predicate + " <" + obj + "> "; - if (ret != "") - { - ret += "; "; - } - ret += vtemp1; - } - - return ret; - } -} diff --git a/tests/lib/tracker/meson.build b/tests/lib/tracker/meson.build deleted file mode 100644 index 91628a16..00000000 --- a/tests/lib/tracker/meson.build +++ /dev/null @@ -1,22 +0,0 @@ -tracker_test_lib_sources = [ - 'test-case.vala', - 'backend.vala', -] - -tracker_test_lib_deps = [ - build_conf_dep, - common_test_lib_deps, - tracker_backendlib_dep, -] - -tracker_test_lib = library('tracker-test-lib', - tracker_test_lib_sources, - dependencies: tracker_test_lib_deps, - vala_args: common_test_lib_flags, -) - -tracker_test_lib_dep = declare_dependency( - link_with: tracker_test_lib, - include_directories: include_directories('.'), - dependencies: tracker_sparql_dep, -) diff --git a/tests/lib/tracker/test-case.vala b/tests/lib/tracker/test-case.vala deleted file mode 100644 index 6b51e675..00000000 --- a/tests/lib/tracker/test-case.vala +++ /dev/null @@ -1,158 +0,0 @@ -/* test-case.vala - * - * Copyright © 2013 Intel Corporation - * - * 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, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: - * Simon McVittie <simon.mcvittie@collabora.co.uk> - */ - -/** - * A test case for the Tracker backend. - * - * Folks is configured to use the Tracker backend as primary store, - * and no other backends. - * - * This uses tracker-control to start and stop Tracker services on a private - * D-Bus bus. - */ -public class TrackerTest.TestCase : Folks.TestCase -{ - /** - * The Tracker backend. - * - * The subclass is expected to have called its set_up() method at - * some point before tear_down() is reached. - */ - public TrackerTest.Backend? tracker_backend = null; - - /** - * Set environment variables and create the tracker backend. - * - * FIXME: maybe it shouldn't be created until set_up()? (Tests - * will need to be checked to make sure that's OK.) - */ - public TestCase (string name) - { - base (name); - - Environment.set_variable ("FOLKS_BACKENDS_ALLOWED", "tracker", true); - Environment.set_variable ("FOLKS_PRIMARY_STORE", "tracker", true); - } - - private string _get_tracker_libexecdir () - { - /* Try the environment variable first, since when running installed - * tests we can’t depend on pkg-config being available. */ - var env = Environment.get_variable ("FOLKS_TEST_TRACKER_LIBEXECDIR"); - - if (env != null && env != "") - { - return env; - } - - /* Find out the libexec directory to use. */ - int exit_status = -1; - string capture_stdout = null; - - try - { - Process.spawn_sync (null /* cwd */, - { "pkg-config", "--variable=prefix", - "tracker-miner-%s".printf(Folks.BuildConf.TRACKER_SPARQL_MAJOR)}, - null /* envp */, - SpawnFlags.SEARCH_PATH /* flags */, - null /* child setup */, - out capture_stdout, - null /* do not capture stderr */, - out exit_status); - - Process.check_exit_status (exit_status); - } - catch (GLib.Error e1) - { - error ("Error getting libexecdir from pkg-config: %s", e1.message); - } - - /* FIXME: There really should be a libexec variable in the pkg-config - * file. */ - return capture_stdout.strip () + "/libexec"; - } - - public override void private_bus_up () - { - base.private_bus_up (); - - /* Find out the libexec directory to use. */ - var libexec = this._get_tracker_libexecdir (); - - /* Create service files for the Tracker binaries. */ - var service_file_name = - Path.build_filename (this.transient_dir, "dbus-1", "services", - "org.freedesktop.Tracker1.service"); - var service_file = ("[D-BUS Service]\n" + - "Name=org.freedesktop.Tracker1\n" + - "Exec=%s/tracker-store\n").printf (libexec); - - try - { - FileUtils.set_contents (service_file_name, service_file); - } - catch (FileError e2) - { - error ("Error creating D-Bus service file ‘%s’: %s", - service_file_name, e2.message); - } - } - - public override void set_up () - { - base.set_up (); - this.create_backend (); - } - - /** - * Virtual method to create and set up the Tracker backend. - * Called from set_up(); may be overridden to not create the backend, - * or to create it but not set it up. - * - * Subclasses may chain up, but are not required to so. - */ - public virtual void create_backend () - { - this.tracker_backend = new TrackerTest.Backend (); - ((!) this.tracker_backend).set_up (); - } - - public override void tear_down () - { - if (this.tracker_backend != null) - { - ((!) this.tracker_backend).tear_down (); - } - - /* Ensure that all pending BlueZ operations are complete. - * - * FIXME: This should be eliminated and unprepare() should guarantee there - * are no more pending Backend/PersonaStore events. - * - * https://bugzilla.gnome.org/show_bug.cgi?id=727700 */ - var context = MainContext.default (); - while (context.iteration (false)); - - base.tear_down (); - } -} diff --git a/tests/meson.build b/tests/meson.build index 6a7fa29c..20afd7a6 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -44,6 +44,3 @@ if eds_backend_enabled subdir('eds') endif -if tracker_backend_enabled - subdir('tracker') -endif diff --git a/tests/template.test.in b/tests/template.test.in index 28421b81..8b9eee8d 100644 --- a/tests/template.test.in +++ b/tests/template.test.in @@ -1,3 +1,3 @@ [Test] Type=session -Exec=env G_ENABLE_DIAGNOSTIC=0 FOLKS_TESTS_INSTALLED=1 G_MESSAGES_DEBUG= FOLKS_TEST_EDS_LIBEXECDIR=@libexecdir@ FOLKS_TEST_TRACKER_LIBEXECDIR=@libexecdir@ @installed_tests_dir@/@program@ +Exec=env G_ENABLE_DIAGNOSTIC=0 FOLKS_TESTS_INSTALLED=1 G_MESSAGES_DEBUG= FOLKS_TEST_EDS_LIBEXECDIR=@libexecdir@ @installed_tests_dir@/@program@ diff --git a/tests/tracker/add-contact.vala b/tests/tracker/add-contact.vala deleted file mode 100644 index 8f0fe9d5..00000000 --- a/tests/tracker/add-contact.vala +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class AddContactTests : TrackerTest.TestCase -{ - private bool _contact_added; - private IndividualAggregator _aggregator; - private string _persona_fullname; - private GLib.MainLoop _main_loop; - - public AddContactTests () - { - base ("AddContactTests"); - - this.add_test ("test adding contacts ", this.test_add_contact); - } - - public void test_add_contact () - { - this._main_loop = new GLib.MainLoop (null, false); - this._persona_fullname = "persona #1"; - this._contact_added = false; - - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname); - var tracker_backend = (!) this.tracker_backend; - tracker_backend.add_contact (c1); - tracker_backend.set_up (); - - this._test_add_contact_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - assert (this._contact_added == true); - } - - private async void _test_add_contact_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - string full_name = i.full_name; - i.notify["full-name"].connect (this._notify_full_name_cb); - if (full_name != null) - { - if (full_name == this._persona_fullname) - { - this._contact_added = true; - this._main_loop.quit (); - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_full_name_cb () - { - var individuals = this._aggregator.individuals.values; - foreach (var i in individuals) - { - if (i.full_name == this._persona_fullname) - { - this._contact_added = true; - this._main_loop.quit (); - } - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new AddContactTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/add-persona.vala b/tests/tracker/add-persona.vala deleted file mode 100644 index 13a4ff95..00000000 --- a/tests/tracker/add-persona.vala +++ /dev/null @@ -1,521 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class AddPersonaTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname; - private string _persona_nickname; - private string _family_name; - private string _given_name; - private HashTable<string, bool> _properties_found; - private string _persona_iid; - private LoadableIcon _avatar; - private string _birthday; - private DateTime _bday; - private string _email_1; - private string _email_2; - private string _im_addr_1; - private string _im_addr_2; - private string _note_1; - private string _phone_1; - private string _phone_2; - private string _title_1; - private string _organisation_1; - private string _role_1; - private PostalAddressFieldDetails _postal_address_fd; - 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 _url_1 = "http://www-1.example.org"; - private string _url_2 = "http://www-1.example.org"; - private Trf.PersonaStore _pstore; - private bool _added_persona = false; - - public AddPersonaTests () - { - base ("AddPersonaTests"); - - this.add_test ("test adding personas to Tracker ", 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 = "nickname"; - this._family_name = "family"; - this._given_name = "given"; - this._persona_iid = ""; - var _avatar_path = Folks.TestUtils.get_source_test_data ( - "data/avatar-01.jpg"); - this._avatar = new FileIcon (File.new_for_path (_avatar_path)); - this._birthday = "2001-10-26T20:32:52Z"; - this._email_1 = "someone-1@example.org"; - this._email_2 = "someone-2@example.org"; - this._im_addr_1 = "someone-1@jabber.example.org"; - this._im_addr_2 = "someone-2@jabber.example.org"; - this._note_1 = "this is a note"; - this._phone_1 = "12345"; - this._phone_2 = "54321"; - this._title_1 = "CFO"; - this._organisation_1 = "Example Inc."; - this._role_1 = "Role"; - - var address = new PostalAddress (this._po_box, - this._extension, this._street, this._locality, this._region, - this._postal_code, this._country, null, null); - this._postal_address_fd = new PostalAddressFieldDetails (address); - - TimeVal t = TimeVal (); - t.from_iso8601 (this._birthday); - this._bday = new DateTime.from_timeval_utc (t); - - 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 ("is_favourite", false); - this._properties_found.insert ("structured_name", false); - this._properties_found.insert ("avatar", false); - this._properties_found.insert ("birthday", false); - this._properties_found.insert ("gender", false); - this._properties_found.insert ("email-1", false); - this._properties_found.insert ("email-2", false); - this._properties_found.insert ("im-addr-1", false); - this._properties_found.insert ("im-addr-2", false); - this._properties_found.insert ("note-1", false); - this._properties_found.insert ("phone-1", false); - this._properties_found.insert ("phone-2", false); - this._properties_found.insert ("role-1", false); - this._properties_found.insert ("postal-address-1", false); - this._properties_found.insert ("url-1", false); - this._properties_found.insert ("url-2", 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 () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - - this._pstore = null; - foreach (var backend in store.enabled_backends.values) - { - this._pstore = - (Trf.PersonaStore) backend.persona_stores.get ("tracker"); - if (this._pstore != null) - break; - } - assert (this._pstore != null); - this._pstore.notify["is-prepared"].connect (this._notify_pstore_cb); - 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 (string)); - v2.set_string (this._persona_nickname); - details.insert (Folks.PersonaStore.detail_key (PersonaDetail.NICKNAME), - (owned) v2); - - Value? v3 = Value (typeof (bool)); - v3.set_boolean (true); - details.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.IS_FAVOURITE), - (owned) v3); - - Value? v4 = Value (typeof (StructuredName)); - StructuredName sname = new StructuredName (this._family_name, - this._given_name, null, null, null); - v4.set_object (sname); - details.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.STRUCTURED_NAME), - (owned) v4); - - Value? v5 = Value (typeof (LoadableIcon)); - v5.set_object (this._avatar); - details.insert (Folks.PersonaStore.detail_key (PersonaDetail.AVATAR), - (owned) v5); - - Value? v6 = Value (typeof (DateTime)); - TimeVal t = TimeVal (); - t.from_iso8601 (this._birthday); - DateTime dobj = new DateTime.from_timeval_utc (t); - v6.set_boxed (dobj); - details.insert (Folks.PersonaStore.detail_key (PersonaDetail.BIRTHDAY), - (owned) v6); - - Value? v7 = Value (typeof (Folks.Gender)); - v7.set_enum (Folks.Gender.MALE); - details.insert (Folks.PersonaStore.detail_key (PersonaDetail.GENDER), - (owned) v7); - - Value? v8 = Value (typeof (Set)); - var emails = new HashSet<EmailFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var email_1 = new EmailFieldDetails (this._email_1); - emails.add (email_1); - var email_2 = new EmailFieldDetails (this._email_2); - emails.add (email_2); - v8.set_object (emails); - details.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.EMAIL_ADDRESSES), - (owned) v8); - - Value? v9 = Value (typeof (MultiMap)); - var im_addrs = new HashMultiMap<string, ImFieldDetails> (null, null, - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - im_addrs.set ("jabber", new ImFieldDetails (this._im_addr_1)); - im_addrs.set ("yahoo", new ImFieldDetails (this._im_addr_2)); - v9.set_object (im_addrs); - details.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.IM_ADDRESSES), v9); - - Value? v10 = Value (typeof (Set)); - var notes = new HashSet<NoteFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - NoteFieldDetails note_fd_1 = new NoteFieldDetails (this._note_1); - notes.add (note_fd_1); - v10.set_object (notes); - details.insert (Folks.PersonaStore.detail_key (PersonaDetail.NOTES), - (owned) v10); - - Value? v11 = Value (typeof (Set)); - var phones = new HashSet<PhoneFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - - var phone_1 = new PhoneFieldDetails (this._phone_1); - phones.add (phone_1); - var phone_2 = new PhoneFieldDetails (this._phone_2); - phones.add (phone_2); - v11.set_object (phones); - details.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.PHONE_NUMBERS), - (owned) v11); - - Value? v12 = Value (typeof (Set)); - var role_fds = new HashSet<RoleFieldDetails> ( - AbstractFieldDetails<Role>.hash_static, - AbstractFieldDetails<Role>.equal_static); - var r1 = new Role (this._title_1, this._organisation_1); - r1.role = this._role_1; - var role_fd1 = new RoleFieldDetails (r1); - role_fds.add (role_fd1); - v12.set_object (role_fds); - details.insert (Folks.PersonaStore.detail_key (PersonaDetail.ROLES), - (owned) v12); - - Value? v13 = Value (typeof (Set)); - var postal_addresses = new HashSet<PostalAddressFieldDetails> ( - AbstractFieldDetails<PostalAddress>.hash_static, - AbstractFieldDetails<PostalAddress>.equal_static); - - var postal_a = new PostalAddress (this._po_box, - this._extension, this._street, this._locality, this._region, - this._postal_code, this._country, null, null); - var postal_a_fd = new PostalAddressFieldDetails (postal_a); - postal_addresses.add (postal_a_fd); - v13.set_object (postal_addresses); - details.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.POSTAL_ADDRESSES), - (owned) v13); - - Value? v14 = Value (typeof (Set)); - var urls = new HashSet<UrlFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var url_1 = new UrlFieldDetails (this._url_1); - urls.add (url_1); - var url_2 = new UrlFieldDetails (this._url_2); - urls.add (url_2); - v14.set_object (urls); - details.insert (Folks.PersonaStore.detail_key (PersonaDetail.URLS), - (owned) v14); - - try - { - Trf.Persona persona = (Trf. Persona) - yield this._aggregator.add_persona_from_details - (null, this._pstore, details); - this._persona_iid = persona.iid; - } - 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 (); - - foreach (var i in added) - { - assert (i != null); - - if (i.is_user == false) - { - /* NOTE: - * we also listen to the Trf.Persona's structured-name - * because if only one of its property is updated - * Individual won't fire a notification. - */ - foreach (var p in i.personas) - { - if (p is NameDetails && - ((NameDetails) p).structured_name != null) - { - p.notify["structured-name"].connect - (this._notify_persona_sname); - } - } - - i.notify["full-name"].connect (this._notify_cb); - i.notify["nickname"].connect (this._notify_cb); - i.notify["avatar"].connect (this._notify_cb); - i.notify["is-favourite"].connect (this._notify_cb); - i.notify["structured-name"].connect (this._notify_cb); - i.notify["family-name"].connect (this._notify_cb); - i.notify["given-name"].connect (this._notify_cb); - i.notify["avatar"].connect (this._notify_cb); - i.notify["birthday"].connect (this._notify_cb); - i.notify["gender"].connect (this._notify_cb); - i.notify["email-addresses"].connect (this._notify_cb); - i.notify["im-addresses"].connect (this._notify_cb); - i.notify["notes"].connect (this._notify_cb); - i.notify["phone-numbers"].connect (this._notify_cb); - i.notify["roles"].connect (this._notify_cb); - i.notify["postal-addresses"].connect (this._notify_cb); - i.notify["urls"].connect (this._notify_cb); - - this._check_properties (i); - } - } - } - - private void _notify_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - this._check_properties (i); - } - - private void _notify_persona_sname (Object persona_p, ParamSpec ps) - { - Trf.Persona persona = (Trf.Persona) persona_p; - this._check_sname (persona.structured_name); - this._exit_if_all_properties_found (); - } - - private void _notify_pstore_cb (Object _pstore, ParamSpec ps) - { - this._try_to_add (); - } - - private void _try_to_add () - { - if (this._pstore.is_prepared && this._added_persona == false) - { - this._added_persona = true; - this._add_persona.begin (); - } - } - - private 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); - - if (i.is_favourite) - this._properties_found.replace ("is_favourite", true); - - if (i.structured_name != null) - { - this._check_sname (i.structured_name); - } - - if (i.birthday != null && - i.birthday.compare (this._bday) == 0) - this._properties_found.replace ("birthday", true); - - if (i.gender == Gender.MALE) - this._properties_found.replace ("gender", true); - - foreach (var e in i.email_addresses) - { - if (e.value == this._email_1) - { - this._properties_found.replace ("email-1", true); - } - else if (e.value == this._email_2) - { - this._properties_found.replace ("email-2", true); - } - } - - foreach (var proto in i.im_addresses.get_keys ()) - { - var addrs = i.im_addresses.get (proto); - foreach (var a in addrs) - { - if (a.value == this._im_addr_1) - this._properties_found.replace ("im-addr-1", true); - else if (a.value == this._im_addr_2) - this._properties_found.replace ("im-addr-2", true); - } - } - - foreach (var n in i.notes) - { - if (n.equal (new NoteFieldDetails (this._note_1))) - { - this._properties_found.replace ("note-1", true); - } - } - - foreach (var phone_fd in i.phone_numbers) - { - if (phone_fd.equal (new PhoneFieldDetails (this._phone_1))) - { - this._properties_found.replace ("phone-1", true); - } - else if (phone_fd.equal (new PhoneFieldDetails (this._phone_2))) - { - this._properties_found.replace ("phone-2", true); - } - } - - foreach (var role_fd in i.roles) - { - var role_expected = new Role (this._title_1, this._organisation_1); - role_expected.role = this._role_1; - var role_fd_expected = new RoleFieldDetails (role_expected); - if (role_fd.equal (role_fd_expected)) - this._properties_found.replace ("role-1", true); - } - - foreach (var pafd in i.postal_addresses) - { - this._postal_address_fd.id = pafd.id; - if (pafd.equal (this._postal_address_fd)) - this._properties_found.replace ("postal-address-1", true); - } - - foreach (var u in i.urls) - { - if (u.value == this._url_1) - this._properties_found.replace ("url-1", true); - if (u.value == this._url_2) - this._properties_found.replace ("url-2", true); - } - - if (i.avatar != null) - { - /* arbitrary icon size, but it might as well be on the small side */ - TestUtils.loadable_icons_content_equal.begin (i.avatar, - this._avatar, 100, - (obj, result) => - { - if (TestUtils.loadable_icons_content_equal.end (result)) - this._properties_found.replace ("avatar", true); - - this._exit_if_all_properties_found (); - }); - } - - this._exit_if_all_properties_found (); - } - - private void _exit_if_all_properties_found () - { - foreach (var k in this._properties_found.get_keys ()) - { - var v = this._properties_found.lookup (k); - if (v == false) - return; - } - this._main_loop.quit (); - } - - private void _check_sname (StructuredName sname) - { - if (sname.family_name == this._family_name && - sname.given_name == this._given_name) - this._properties_found.replace ("structured_name", true); - } -} - -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/tracker/additional-names-updates.vala b/tests/tracker/additional-names-updates.vala deleted file mode 100644 index f9728711..00000000 --- a/tests/tracker/additional-names-updates.vala +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class AdditionalNamesUpdatesTests : TrackerTest.TestCase -{ - private IndividualAggregator _aggregator; - private bool _updated_additional_names_found; - private string _updated_additional_names; - private string _individual_id; - private GLib.MainLoop _main_loop; - private bool _initial_additional_names_found; - private string _contact_urn; - private string _initial_additional_names; - private string _initial_fullname; - - public AdditionalNamesUpdatesTests () - { - base ("AdditionalNamesUpdates"); - - this.add_test ("additional names updates", - this.test_additional_names_updates); - } - - public void test_additional_names_updates () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._initial_fullname = "persona #1"; - this._initial_additional_names = "additional name #1"; - this._updated_additional_names = "updated additional name #1"; - this._contact_urn = "<urn:contact001>"; - - c1.set (TrackerTest.Backend.URN, this._contact_urn); - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname); - c1.set (Trf.OntologyDefs.NCO_ADDITIONAL, - this._initial_additional_names); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._initial_additional_names_found = false; - this._updated_additional_names_found = false; - this._individual_id = ""; - - var store = BackendStore.dup (); - _test_additional_names_updates_async.begin (store); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._initial_additional_names_found == true); - assert (this._updated_additional_names_found == true); - } - - private async void _test_additional_names_updates_async (BackendStore store) - { - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (this._initial_fullname == i.full_name) - { - var additional_names = i.structured_name.additional_names; - if (additional_names == this._initial_additional_names) - { - i.structured_name.notify["additional-names"].connect - (this._notify_additional_names_cb); - this._individual_id = i.id; - this._initial_additional_names_found = true; - ((!) this.tracker_backend).update_contact (this._contact_urn, - Trf.OntologyDefs.NCO_ADDITIONAL, - this._updated_additional_names); - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_additional_names_cb (Object sname_obj, ParamSpec ps) - { - Folks.StructuredName sname = (Folks.StructuredName) sname_obj; - var additional_names = sname.additional_names; - - if (additional_names == this._updated_additional_names) - { - this._updated_additional_names_found = true; - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new AdditionalNamesUpdatesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/avatar-details-interface.vala b/tests/tracker/avatar-details-interface.vala deleted file mode 100644 index 26a0f58e..00000000 --- a/tests/tracker/avatar-details-interface.vala +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class AvatarDetailsInterfaceTests : TrackerTest.TestCase -{ - private string _avatar_uri; - private bool _avatars_are_equal; - private GLib.MainLoop _main_loop; - IndividualAggregator _aggregator; - - public AvatarDetailsInterfaceTests () - { - base ("AvatarDetailsInterfaceTests"); - - this.add_test ("test avatar details interface", - this.test_avatar_details_interface); - } - - public void test_avatar_details_interface () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - var avatar_path = Folks.TestUtils.get_source_test_data ( - "data/avatar-01.jpg"); - var temp_file = GLib.File.new_for_path (avatar_path); - var full_avatar_path = temp_file.get_path (); - this._avatar_uri = "file://" + full_avatar_path; - this._avatars_are_equal = false; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, "persona #1"); - c1.set (Trf.OntologyDefs.NCO_PHOTO, this._avatar_uri); - ((!) this.tracker_backend).add_contact (c1); - ((!) this.tracker_backend).set_up (); - - test_avatar_details_interface_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - assert (this._avatars_are_equal); - } - - private async void test_avatar_details_interface_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - - /* Set up the aggregator */ - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - string full_name = ((Folks.NameDetails) i).full_name; - if (full_name != null) - { - i.notify["avatar"].connect (this._notify_avatar_cb); - if (i.avatar != null) - { - var src_avatar = File.new_for_uri (this._avatar_uri); - var src_icon = new FileIcon (src_avatar); - this._avatars_are_equal = src_icon.equal (i.avatar); - this._main_loop.quit (); - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_avatar_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual individual = (Folks.Individual) individual_obj; - var src_avatar = File.new_for_uri (this._avatar_uri); - var src_icon = new FileIcon (src_avatar); - this._avatars_are_equal = src_icon.equal (individual.avatar); - this._main_loop.quit (); - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new AvatarDetailsInterfaceTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/avatar-updates.vala b/tests/tracker/avatar-updates.vala deleted file mode 100644 index 367c33f9..00000000 --- a/tests/tracker/avatar-updates.vala +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class AvatarUpdatesTests : TrackerTest.TestCase -{ - private IndividualAggregator _aggregator; - private bool _updated_avatar_found; - private string _updated_avatar_uri; - private LoadableIcon _updated_avatar; - private string _individual_id; - private GLib.MainLoop _main_loop; - private bool _initial_avatar_found; - private string _initial_fullname; - private string _initial_avatar_uri; - private string _contact_urn; - private string _photo_urn; - - public AvatarUpdatesTests () - { - base ("AvatarUpdates"); - - this.add_test ("avatar updates", this.test_avatar_updates); - } - - public void test_avatar_updates () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._initial_fullname = "persona #1"; - this._initial_avatar_uri = "file:///tmp/avatar-01"; - this._contact_urn = "<urn:contact001>"; - this._photo_urn = "<" + this._initial_avatar_uri + ">"; - this._updated_avatar_uri = "file:///tmp/avatar-02"; - this._updated_avatar = - new FileIcon (File.new_for_uri (this._updated_avatar_uri)); - - c1.set (TrackerTest.Backend.URN, this._contact_urn); - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname); - c1.set (Trf.OntologyDefs.NCO_PHOTO, this._initial_avatar_uri); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._initial_avatar_found = false; - this._updated_avatar_found = false; - this._individual_id = ""; - - test_avatar_updates_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._initial_avatar_found == true); - assert (this._updated_avatar_found == true); - } - - private async void test_avatar_updates_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._initial_fullname) - { - i.notify["avatar"].connect (this._notify_avatar_cb); - this._individual_id = i.id; - - var initial_avatar = - new FileIcon (File.new_for_uri (this._initial_avatar_uri)); - - if (i.avatar != null && i.avatar.equal (initial_avatar) == true) - { - this._initial_avatar_found = true; - - ((!) this.tracker_backend).remove_triplet (this._contact_urn, - Trf.OntologyDefs.NCO_PHOTO, this._photo_urn); - - string photo_urn_2 = "<" + this._updated_avatar_uri; - photo_urn_2 += ">"; - ((!) this.tracker_backend).insert_triplet (photo_urn_2, - "a", "nfo:Image, nie:DataObject", - Trf.OntologyDefs.NIE_URL, - this._updated_avatar_uri); - - ((!) this.tracker_backend).insert_triplet - (this._contact_urn, - Trf.OntologyDefs.NCO_PHOTO, photo_urn_2); - - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_avatar_cb () - { - var i = this._aggregator.individuals.get (this._individual_id); - if (i == null) - return; - - if (i.avatar != null && - i.avatar.equal (this._updated_avatar)) - { - this._main_loop.quit (); - this._updated_avatar_found = true; - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new AvatarUpdatesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/birthday-details-interface.vala b/tests/tracker/birthday-details-interface.vala deleted file mode 100644 index 71e4062d..00000000 --- a/tests/tracker/birthday-details-interface.vala +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class BirthdayDetailsInterfaceTests : TrackerTest.TestCase -{ - private bool _found_birthday; - private DateTime _dobj; - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _fullname; - - public BirthdayDetailsInterfaceTests () - { - base ("BirthdayDetailsInterfaceTests"); - - this.add_test ("test birthday details interface", - this.test_birthay_details_interface); - } - - public void test_birthay_details_interface () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._fullname = "persona #1"; - string birthday = "2001-10-26T20:32:52Z"; - TimeVal t = TimeVal (); - t.from_iso8601 (birthday); - this._dobj = new DateTime.from_timeval_utc (t); - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._fullname); - c1.set (Trf.OntologyDefs.NCO_BIRTHDAY, birthday); - ((!) this.tracker_backend).add_contact (c1); - ((!) this.tracker_backend).set_up (); - - this._found_birthday = false; - - this._test_birthay_details_interface.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._found_birthday == true); - } - - private async void _test_birthay_details_interface () - { - var store = BackendStore.dup (); - yield store.prepare (); - - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._fullname) - { - i.notify["birthday"].connect (this._notify_birthday_cb); - if (i.birthday != null) - { - if (i.birthday.compare (this._dobj) == 0) - { - this._found_birthday = true; - this._main_loop.quit (); - } - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - void _notify_birthday_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual individual = (Folks.Individual) individual_obj; - if (individual.birthday != null && - individual.birthday.compare (this._dobj) == 0) - { - this._found_birthday = true; - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new BirthdayDetailsInterfaceTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/birthday-updates.vala b/tests/tracker/birthday-updates.vala deleted file mode 100644 index 7f66af2c..00000000 --- a/tests/tracker/birthday-updates.vala +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class BirthdayUpdatesTests : TrackerTest.TestCase -{ - private IndividualAggregator _aggregator; - private string _initial_birthday; - private string _updated_birthday; - private string _individual_id; - private bool _initial_birthday_found; - private bool _updated_birthday_found; - private string _contact_urn; - private DateTime _initial_bday_obj; - private DateTime _updated_bday_obj; - private string _initial_fullname; - private GLib.MainLoop _main_loop; - - public BirthdayUpdatesTests () - { - base ("BirthdayUpdates"); - - this.add_test ("birthday updates", this.test_birthday_updates); - } - - public void test_birthday_updates () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._initial_fullname = "persona #1"; - this._initial_birthday = "2001-10-26T20:32:52Z"; - this._updated_birthday = "1991-10-26T20:32:52Z"; - this._contact_urn = "<urn:contact001>"; - - TimeVal t1 = TimeVal (); - t1.from_iso8601 (this._initial_birthday); - this._initial_bday_obj = new DateTime.from_timeval_utc (t1); - - TimeVal t2 = TimeVal (); - t2.from_iso8601 (this._updated_birthday); - this._updated_bday_obj = new DateTime.from_timeval_utc (t2); - - c1.set (TrackerTest.Backend.URN, this._contact_urn); - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname); - c1.set (Trf.OntologyDefs.NCO_BIRTHDAY, this._initial_birthday); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._initial_birthday_found = false; - this._updated_birthday_found = false; - this._individual_id = ""; - - test_birthday_updates_async.begin (); - - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._initial_birthday_found == true); - assert (this._updated_birthday_found == true); - } - - private async void test_birthday_updates_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - /* Set up the aggregator */ - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._initial_fullname) - { - i.notify["birthday"].connect (this._notify_birthday_cb); - if (i.birthday != null && - i.birthday.compare (this._initial_bday_obj) == 0) - { - this._individual_id = i.id; - this._initial_birthday_found = true; - ((!) this.tracker_backend).update_contact (this._contact_urn, - Trf.OntologyDefs.NCO_BIRTHDAY, this._updated_birthday); - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - void _notify_birthday_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - - if (i.birthday == null) - { - return; - } - - if (i.birthday.compare (this._initial_bday_obj) == 0) - { - this._individual_id = i.id; - this._initial_birthday_found = true; - ((!) this.tracker_backend).update_contact (this._contact_urn, - Trf.OntologyDefs.NCO_BIRTHDAY, this._updated_birthday); - } - else if (i.birthday.compare (this._updated_bday_obj) == 0) - { - this._updated_birthday_found = true; - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new BirthdayUpdatesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/default-contact.vala b/tests/tracker/default-contact.vala deleted file mode 100644 index b690c25e..00000000 --- a/tests/tracker/default-contact.vala +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class DefaultContactTests : TrackerTest.TestCase -{ - private bool _found_default_user; - private bool _found_not_user; - private bool _found_unknown_user; - private GLib.MainLoop _main_loop; - private string _fullname_persona; - private IndividualAggregator _aggregator; - public DefaultContactTests () - { - base ("DefaultContactTests"); - - this.add_test ("test default contact", this.test_default_contact); - } - - public void test_default_contact () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._fullname_persona = "persona #1"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._fullname_persona); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._found_default_user = false; - this._found_not_user = false; - this._found_unknown_user = false; - - _test_default_contact_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._found_default_user == true); - assert (this._found_not_user == true); - assert (this._found_unknown_user == false); - } - - private async void _test_default_contact_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - string full_name = i.full_name; - if (full_name != null && full_name == this._fullname_persona - && i.is_user == false) - { - this._found_not_user = true; - } - else if (i.is_user == true) - { - this._found_default_user = true; - } - else - { - this._found_unknown_user = true; - } - } - - if (this._found_not_user && - this._found_default_user) - this._main_loop.quit (); - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new DefaultContactTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/duplicated-emails.vala b/tests/tracker/duplicated-emails.vala deleted file mode 100644 index 4e67d36a..00000000 --- a/tests/tracker/duplicated-emails.vala +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class DuplicatedEmailsTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname_1 = "persona #1"; - private string _persona_fullname_2 = "persona #2"; - private string _email_1 = "some-address@example.org"; - private bool _added_personas = false; - private string _individual_id_1 = ""; - private string _individual_id_2 = ""; - private Trf.PersonaStore _pstore; - - public DuplicatedEmailsTests () - { - base ("DuplicatedEmailsTests"); - - this.add_test ("test adding 2 personas with the same email address ", - this.test_duplicated_emails); - } - - public void test_duplicated_emails () - { - this._main_loop = new GLib.MainLoop (null, false); - - this._test_duplicated_emails_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - assert (this._individual_id_1 != ""); - assert (this._individual_id_2 != ""); - } - - private async void _test_duplicated_emails_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - this._pstore = null; - foreach (var backend in store.enabled_backends.values) - { - this._pstore = - (Trf.PersonaStore) backend.persona_stores.get ("tracker"); - if (this._pstore != null) - break; - } - assert (this._pstore != null); - this._pstore.notify["is-prepared"].connect (this._notify_pstore_cb); - this._try_to_add.begin (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname_1) - { - this._individual_id_1 = i.id; - } - else if (i.full_name == this._persona_fullname_2) - { - this._individual_id_2 = i.id; - } - } - - if (this._individual_id_1 != "" && - this._individual_id_2 != "") - { - this._main_loop.quit (); - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_pstore_cb (Object _pstore, ParamSpec ps) - { - this._try_to_add.begin (); - } - - private async void _try_to_add () - { - if (this._pstore.is_prepared && this._added_personas == false) - { - this._added_personas = true; - yield this._add_personas (); - } - } - - /** - * Add 2 personas with the same e-mail address. Although - * Tracker forbids inserting 2 duplicated nco:EmailAddresses, - * our Trf.PersonaStore should be able to detect the existence - * of an e-mail address and re-use that instead of trying to - * create a new one. - */ - private async void _add_personas () - { - HashTable<string, Value?> details1 = new HashTable<string, Value?> - (str_hash, str_equal); - HashTable<string, Value?> details2 = new HashTable<string, Value?> - (str_hash, str_equal); - Value? val; - - val = Value (typeof (string)); - val.set_string (this._persona_fullname_1); - details1.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME), - (owned) val); - - val = Value (typeof (Set)); - var emails1 = new HashSet<EmailFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var email_1 = new EmailFieldDetails (this._email_1); - emails1.add (email_1); - val.set_object (emails1); - details1.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.EMAIL_ADDRESSES), - (owned) val); - - val = Value (typeof (string)); - val.set_string (this._persona_fullname_2); - details2.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME), - (owned) val); - - val = Value (typeof (Set)); - var emails2 = new HashSet<EmailFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var email_2 = new EmailFieldDetails (this._email_1); - emails2.add (email_2); - val.set_object (emails2); - details2.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.EMAIL_ADDRESSES), - (owned) val); - - try - { - yield this._aggregator.add_persona_from_details (null, - this._pstore, details1); - - yield this._aggregator.add_persona_from_details (null, - this._pstore, details2); - } - catch (Folks.IndividualAggregatorError e) - { - GLib.warning ("[AddPersonaError] add_persona_from_details: %s\n", - e.message); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new DuplicatedEmailsTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/duplicated-phones.vala b/tests/tracker/duplicated-phones.vala deleted file mode 100644 index b7a049bf..00000000 --- a/tests/tracker/duplicated-phones.vala +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class DuplicatedPhonesTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname_1 = "persona #1"; - private string _persona_fullname_2 = "persona #2"; - private string _phone_1 = "1-800-123-456"; - private bool _added_personas = false; - private string _individual_id_1 = ""; - private string _individual_id_2 = ""; - private Trf.PersonaStore _pstore; - - public DuplicatedPhonesTests () - { - base ("DuplicatedPhonesTests"); - - this.add_test ("test adding 2 personas with the same phone number ", - this.test_duplicated_phones); - } - - public void test_duplicated_phones () - { - this._main_loop = new GLib.MainLoop (null, false); - - this._test_duplicated_phones_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - assert (this._individual_id_1 != ""); - assert (this._individual_id_2 != ""); - } - - private async void _test_duplicated_phones_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - this._pstore = null; - foreach (var backend in store.enabled_backends.values) - { - this._pstore = - (Trf.PersonaStore) backend.persona_stores.get ("tracker"); - if (this._pstore != null) - break; - } - assert (this._pstore != null); - this._pstore.notify["is-prepared"].connect (this._notify_pstore_cb); - this._try_to_add.begin (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname_1) - { - this._individual_id_1 = i.id; - } - else if (i.full_name == this._persona_fullname_2) - { - this._individual_id_2 = i.id; - } - } - - if (this._individual_id_1 != "" && - this._individual_id_2 != "") - { - this._main_loop.quit (); - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_pstore_cb (Object _pstore, ParamSpec ps) - { - this._try_to_add.begin (); - } - - private async void _try_to_add () - { - if (this._pstore.is_prepared && this._added_personas == false) - { - this._added_personas = true; - yield this._add_personas (); - } - } - - /** - * Add 2 personas with the same phone number. Although - * Tracker forbids creating inserting 2 nco:PhoneNumber, - * using the same nco:phoneNumber, our Trf.PersonaStore should - * be able to detect the existence of a given Phone Number and - * re-use that instead of trying to create a new one. - */ - private async void _add_personas () - { - HashTable<string, Value?> details1 = new HashTable<string, Value?> - (str_hash, str_equal); - HashTable<string, Value?> details2 = new HashTable<string, Value?> - (str_hash, str_equal); - Value? val; - - val = Value (typeof (string)); - val.set_string (this._persona_fullname_1); - details1.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME), - (owned) val); - - val = Value (typeof (Set)); - var phones1 = new HashSet<PhoneFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var phone_1 = new PhoneFieldDetails (this._phone_1); - phones1.add (phone_1); - val.set_object (phones1); - details1.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.PHONE_NUMBERS), - (owned) val); - - val = Value (typeof (string)); - val.set_string (this._persona_fullname_2); - details2.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME), - (owned) val); - - val = Value (typeof (Set)); - var phones2 = new HashSet<PhoneFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var phone_2 = new PhoneFieldDetails (this._phone_1); - phones2.add (phone_2); - val.set_object (phones2); - details2.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.PHONE_NUMBERS), - (owned) val); - - try - { - yield this._aggregator.add_persona_from_details (null, - this._pstore, details1); - - yield this._aggregator.add_persona_from_details (null, - this._pstore, details2); - } - catch (Folks.IndividualAggregatorError e) - { - GLib.warning ("[AddPersonaError] add_persona_from_details: %s\n", - e.message); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new DuplicatedPhonesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/email-details-interface.vala b/tests/tracker/email-details-interface.vala deleted file mode 100644 index 3102770b..00000000 --- a/tests/tracker/email-details-interface.vala +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class EmailDetailsInterfaceTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private int _num_emails; - private bool _found_email_1; - private bool _found_email_2; - - public EmailDetailsInterfaceTests () - { - base ("EmailDetailsInterfaceTests"); - - this.add_test ("test email details interface", - this.test_email_details_interface); - } - - public void test_email_details_interface () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, "persona #1"); - c1.set (Trf.OntologyDefs.NCO_EMAIL_PROP, - "test1@example.org,test2@example.org"); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._num_emails = 0; - this._found_email_1 = false; - this._found_email_2 = false; - - this._test_email_details_interface_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._num_emails == 2); - assert (this._found_email_1 == true); - assert (this._found_email_2 == true); - } - - private async void _test_email_details_interface_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - string full_name = i.full_name; - if (full_name != null) - { - foreach (var email in i.email_addresses) - { - if (email.value == "test1@example.org") - { - this._found_email_1 = true; - this._num_emails++; - } - else if (email.value == "test2@example.org") - { - this._found_email_2 = true; - this._num_emails++; - } - } - } - } - - if (this._found_email_1 && - this._found_email_2 && - this._num_emails == 2) - this._main_loop.quit (); - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new EmailDetailsInterfaceTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/emails-updates.vala b/tests/tracker/emails-updates.vala deleted file mode 100644 index 777560ae..00000000 --- a/tests/tracker/emails-updates.vala +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class EmailsUpdatesTests : TrackerTest.TestCase -{ - private IndividualAggregator _aggregator; - private GLib.MainLoop _main_loop; - private string _individual_id; - private bool _initial_email_found; - private string _initial_fullname_1; - private bool _updated_email_found; - private string _email_1; - private string _email_2; - private string _contact_urn_1; - - public EmailsUpdatesTests () - { - base ("EmailsUpdates"); - - this.add_test ("emails updates", this.test_emails_updates); - } - - public void test_emails_updates () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._initial_fullname_1 = "persona #1"; - this._contact_urn_1 = "<urn:contact001>"; - this._email_1 = "persona-addr-1@example.org"; - this._email_2 = "persona-addr-2@example.org"; - - c1.set (TrackerTest.Backend.URN, this._contact_urn_1); - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname_1); - c1.set (Trf.OntologyDefs.NCO_EMAIL_PROP, this._email_1); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._individual_id = ""; - this._initial_email_found = false; - this._updated_email_found = false; - - this._test_emails_updates_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._initial_email_found == true); - - bool initial_email_found_again = false; - - var i = this._aggregator.individuals.get (this._individual_id); - if (i != null) - { - foreach (var fd in i.email_addresses) - { - var email = fd.value; - if (email == this._email_1) - { - initial_email_found_again = true; - } - } - } - - assert (initial_email_found_again == false); - assert (this._updated_email_found == true); - } - - private async void _test_emails_updates_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._initial_fullname_1) - { - this._individual_id = i.id; - i.notify["email-addresses"].connect (this._notify_email_cb); - - foreach (var fd in i.email_addresses) - { - var email = fd.value; - if (email == this._email_1) - { - this._initial_email_found = true; - - var urn_email_1 = "<" + this._email_1 + ">"; - ((!) this.tracker_backend).remove_triplet ( - this._contact_urn_1, - Trf.OntologyDefs.NCO_HAS_AFFILIATION, urn_email_1); - - var urn_email_2 = "<email:" + this._email_2 + ">"; - ((!) this.tracker_backend).insert_triplet (urn_email_2, - "a", Trf.OntologyDefs.NCO_EMAIL, - Trf.OntologyDefs.NCO_EMAIL_PROP, - this._email_2); - - var affl_2 = "<" + this._email_2 + ">"; - ((!) this.tracker_backend).insert_triplet - (affl_2, - "a", Trf.OntologyDefs.NCO_AFFILIATION); - - ((!) this.tracker_backend).insert_triplet - (affl_2, - Trf.OntologyDefs.NCO_HAS_EMAIL, urn_email_2); - - ((!) this.tracker_backend).insert_triplet - (this._contact_urn_1, - Trf.OntologyDefs.NCO_HAS_AFFILIATION, affl_2); - } - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_email_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual individual = (Folks.Individual) individual_obj; - - if (this._individual_id != individual.id) - return; - - foreach (var fd in individual.email_addresses) - { - var email = fd.value; - if (email == this._email_2) - { - this._updated_email_found = true; - this._main_loop.quit (); - } - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new EmailsUpdatesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/family-name-updates.vala b/tests/tracker/family-name-updates.vala deleted file mode 100644 index 2840a3dc..00000000 --- a/tests/tracker/family-name-updates.vala +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class FamilyNameUpdatesTests : TrackerTest.TestCase -{ - private IndividualAggregator _aggregator; - private GLib.MainLoop _main_loop; - private bool _initial_family_name_found; - private bool _updated_family_name_found; - private string _updated_family_name; - private string _individual_id; - private string _initial_fullname; - private string _initial_family_name; - private string _contact_urn; - - - public FamilyNameUpdatesTests () - { - base ("FamilyNameUpdates"); - - this.add_test ("family name updates", this.test_family_name_updates); - } - - public void test_family_name_updates () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._initial_fullname = "persona #1"; - this._initial_family_name = "family name #1"; - this._updated_family_name = "updated family #1"; - this._contact_urn = "<urn:contact001>"; - - c1.set (TrackerTest.Backend.URN, this._contact_urn); - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname); - c1.set (Trf.OntologyDefs.NCO_FAMILY, this._initial_family_name); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._initial_family_name_found = false; - this._updated_family_name_found = false; - this._individual_id = ""; - - this._test_family_name_updates_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._initial_family_name_found == true); - assert (this._updated_family_name_found == true); - } - - private async void _test_family_name_updates_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (this._initial_fullname == i.full_name) - { - i.structured_name.notify["family-name"].connect - (this._notify_family_name_cb); - var family_name = i.structured_name.family_name; - if (family_name == this._initial_family_name) - { - this._individual_id = i.id; - this._initial_family_name_found = true; - ((!) this.tracker_backend).update_contact (this._contact_urn, - Trf.OntologyDefs.NCO_FAMILY, this._updated_family_name); - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_family_name_cb (Object individual_obj, ParamSpec ps) - { - Folks.StructuredName sname = (Folks.StructuredName) individual_obj; - var family_name = sname.family_name; - if (family_name == this._updated_family_name) - { - this._updated_family_name_found = true; - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new FamilyNameUpdatesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/favourite-details-interface.vala b/tests/tracker/favourite-details-interface.vala deleted file mode 100644 index 369e316d..00000000 --- a/tests/tracker/favourite-details-interface.vala +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class FavouriteDetailsInterfaceTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private string _fullname_p1; - private string _fullname_p2; - private string _fullname_p3; - private bool _found_p1; - private bool _found_p2; - private bool _found_p3; - private IndividualAggregator _aggregator; - - public FavouriteDetailsInterfaceTests () - { - base ("FavouriteDetailsInterfaceTests"); - - this.add_test ("test favourite details interface", - this.test_favourite_details_interface); - } - - public void test_favourite_details_interface () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - Gee.HashMap<string, string> c2 = new Gee.HashMap<string, string> (); - Gee.HashMap<string, string> c3 = new Gee.HashMap<string, string> (); - this._fullname_p1 = "favourite persona #1"; - this._fullname_p2 = "favourite persona #2"; - this._fullname_p3 = "favourite persona #3"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._fullname_p1); - c1.set (Trf.OntologyDefs.NAO_TAG, ""); - ((!) this.tracker_backend).add_contact (c1); - - c2.set (Trf.OntologyDefs.NCO_FULLNAME, this._fullname_p2); - c2.set (Trf.OntologyDefs.NAO_TAG, ""); - ((!) this.tracker_backend).add_contact (c2); - - c3.set (Trf.OntologyDefs.NCO_FULLNAME, this._fullname_p3); - ((!) this.tracker_backend).add_contact (c3); - - ((!) this.tracker_backend).set_up (); - - this._found_p1 = false; - this._found_p2 = false; - this._found_p3 = false; - - this._test_favourite_details_interface_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._found_p1 == true); - assert (this._found_p2 == true); - assert (this._found_p3 == true); - } - - private async void _test_favourite_details_interface_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - string full_name = i.full_name; - if (full_name != null) - { - if (full_name == this._fullname_p1) - { - assert (i.is_favourite == true); - this._found_p1 = true; - } - else if (full_name == this._fullname_p2) - { - assert (i.is_favourite == true); - this._found_p2 = true; - } - else if (full_name == this._fullname_p3) - { - assert (i.is_favourite == false); - this._found_p3 = true; - } - } - } - - if (this._found_p1 && - this._found_p2 && - this._found_p3) - this._main_loop.quit (); - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new FavouriteDetailsInterfaceTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/favourite-updates.vala b/tests/tracker/favourite-updates.vala deleted file mode 100644 index cf270fd0..00000000 --- a/tests/tracker/favourite-updates.vala +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class FavouriteUpdatesTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private bool _is_favourite_1; - private string _individual_id_1; - private bool _is_favourite_2; - private string _individual_id_2; - private string _initial_fullname_1; - private string _contact_urn_1; - private string _initial_fullname_2; - private string _contact_urn_2; - - public FavouriteUpdatesTests () - { - base ("FavouriteUpdates"); - - this.add_test ("favourite update", this.test_favourite_update); - } - - public void test_favourite_update () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - Gee.HashMap<string, string> c2 = new Gee.HashMap<string, string> (); - this._initial_fullname_1 = "persona #1"; - this._contact_urn_1 = "<urn:contact001>"; - this._initial_fullname_2 = "persona #2"; - this._contact_urn_2 = "<urn:contact002>"; - - c1.set (TrackerTest.Backend.URN, this._contact_urn_1); - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname_1); - ((!) this.tracker_backend).add_contact (c1); - - c2.set (TrackerTest.Backend.URN, this._contact_urn_2); - c2.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname_2); - c2.set (Trf.OntologyDefs.NAO_TAG, ""); - ((!) this.tracker_backend).add_contact (c2); - - ((!) this.tracker_backend).set_up (); - - this._is_favourite_1 = false; - this._individual_id_1 = ""; - this._is_favourite_2 = true; - this._individual_id_2 = ""; - - this._test_favourite_update_async.begin (); - - // this timer is slightly higher than usual because sleep - // to ensure a (usually delayed) INSERT event has happened - TestUtils.loop_run_with_timeout (this._main_loop, 15); - - assert (this._is_favourite_1 == true); - assert (this._is_favourite_2 == false); - } - - private async void _test_favourite_update_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._initial_fullname_1) - { - i.notify["is-favourite"].connect - (this._notify_favourite_cb); - this._individual_id_1 = i.id; - ((!) this.tracker_backend).update_favourite (this._contact_urn_1, - true); - } - else if (i.full_name == this._initial_fullname_2) - { - i.notify["is-favourite"].connect - (this._notify_favourite_cb); - this._individual_id_2 = i.id; - // HACK: we need to make sure the INSERT event was delivered - Timeout.add_seconds (1, () => - { - ((!) this.tracker_backend).update_favourite - (this._contact_urn_2, false); - return false; - }); - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_favourite_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - if (i.id == this._individual_id_1) - { - this._is_favourite_1 = i.is_favourite; - } - else if (i.id == this._individual_id_2) - { - this._is_favourite_2 = i.is_favourite; - } - - if (this._is_favourite_1 == true && - this._is_favourite_2 == false) - this._main_loop.quit (); - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new FavouriteUpdatesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/fullname-updates.vala b/tests/tracker/fullname-updates.vala deleted file mode 100644 index 4c00592a..00000000 --- a/tests/tracker/fullname-updates.vala +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class FullnameUpdatesTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private bool _updated_name_found; - private bool _deleted_name_found; - private string _updated_fullname; - private string _individual_id; - private string _initial_fullname; - private string _contact_urn; - private bool _initial_name_found; - - public FullnameUpdatesTests () - { - base ("FullnameUpdates"); - - this.add_test ("fullname updates", this.test_fullname_updates); - } - - public void test_fullname_updates () - { - this._main_loop = new GLib.MainLoop (null, false); - this._initial_fullname = "persona #1"; - this._updated_fullname = "updated persona #1"; - this._contact_urn = "<urn:contact001>"; - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - - c1.set (TrackerTest.Backend.URN, this._contact_urn); - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._initial_name_found = false; - this._updated_name_found = false; - this._deleted_name_found = false; - this._individual_id = ""; - - this._test_fullname_updates_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._initial_name_found == true); - assert (this._updated_name_found == true); - } - - private async void _test_fullname_updates_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._initial_fullname) - { - i.notify["full-name"].connect (this._notify_full_name_cb); - this._individual_id = i.id; - this._initial_name_found = true; - ((!) this.tracker_backend).update_contact (this._contact_urn, - Trf.OntologyDefs.NCO_FULLNAME, this._updated_fullname); - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_full_name_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - - if (i.full_name == this._updated_fullname) - { - this._updated_name_found = true; - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new FullnameUpdatesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/gender-details-interface.vala b/tests/tracker/gender-details-interface.vala deleted file mode 100644 index 99aa0d12..00000000 --- a/tests/tracker/gender-details-interface.vala +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class GenderDetailsInterfaceTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private bool _found_gender; - private string _gender; - private string _fullname; - - public GenderDetailsInterfaceTests () - { - base ("GenderDetailsInterfaceTests"); - - this.add_test ("test gender details interface", - this.test_gender_details_interface); - } - - public void test_gender_details_interface () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._fullname = "persona #1"; - this._gender = Trf.OntologyDefs.NCO_MALE; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._fullname); - c1.set (Trf.OntologyDefs.NCO_GENDER, this._gender); - ((!) this.tracker_backend).add_contact (c1); - ((!) this.tracker_backend).set_up (); - - this._found_gender = false; - - this._test_gender_details_interface_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._found_gender == true); - } - - private async void _test_gender_details_interface_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._fullname) - { - i.notify["gender"].connect (this._notify_gender_cb); - if (i.gender == Gender.MALE) - { - this._found_gender = true; - this._main_loop.quit (); - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - void _notify_gender_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual individual = (Folks.Individual) individual_obj; - if (individual.gender == Gender.MALE) - { - this._found_gender = true; - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new GenderDetailsInterfaceTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/given-name-updates.vala b/tests/tracker/given-name-updates.vala deleted file mode 100644 index 593dc207..00000000 --- a/tests/tracker/given-name-updates.vala +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class GivenNameUpdatesTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private bool _updated_given_name_found; - private string _updated_given_name; - private string _individual_id; - private string _initial_fullname; - private string _initial_given_name; - private string _contact_urn; - private bool _initial_given_name_found; - - public GivenNameUpdatesTests () - { - base ("GivenNameUpdates"); - - this.add_test ("given name updates", this.test_given_name_updates); - } - - public void test_given_name_updates () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._initial_fullname = "persona #1"; - this._initial_given_name = "given name #1"; - this._updated_given_name = "updated given #1"; - this._contact_urn = "<urn:contact001>"; - - c1.set (TrackerTest.Backend.URN, this._contact_urn); - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname); - c1.set (Trf.OntologyDefs.NCO_GIVEN, this._initial_given_name); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._initial_given_name_found = false; - this._updated_given_name_found = false; - this._individual_id = ""; - - this._test_given_name_updates_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._initial_given_name_found == true); - assert (this._updated_given_name_found == true); - } - - private async void _test_given_name_updates_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (this._initial_fullname == i.full_name) - { - i.structured_name.notify["given-name"].connect - (this._notify_given_name_cb); - var given_name = i.structured_name.given_name; - if (given_name == this._initial_given_name) - { - this._individual_id = i.id; - this._initial_given_name_found = true; - ((!) this.tracker_backend).update_contact (this._contact_urn, - Trf.OntologyDefs.NCO_GIVEN, this._updated_given_name); - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_given_name_cb (Object individual_obj, ParamSpec ps) - { - Folks.StructuredName structured_name = - (Folks.StructuredName) individual_obj; - - var given_name = structured_name.given_name; - if (given_name == this._updated_given_name) - { - this._updated_given_name_found = true; - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new GivenNameUpdatesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/im-details-interface.vala b/tests/tracker/im-details-interface.vala deleted file mode 100644 index a835e193..00000000 --- a/tests/tracker/im-details-interface.vala +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class ImDetailsInterfaceTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private int _num_addrs; - private bool _found_addr_1; - private bool _found_addr_2; - private string _fullname; - - public ImDetailsInterfaceTests () - { - base ("ImDetailsInterfaceTests"); - - this.add_test ("test im details interface", - this.test_im_details_interface); - } - - public void test_im_details_interface () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._fullname = "persona #1"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._fullname); - c1.set (Trf.OntologyDefs.NCO_IMADDRESS, - "jabber#test1@example.org,aim#test2@example.org"); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._num_addrs = 0; - this._found_addr_1 = false; - this._found_addr_2 = false; - - this._test_im_details_interface_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._num_addrs == 2); - assert (this._found_addr_1 == true); - assert (this._found_addr_2 == true); - } - - private async void _test_im_details_interface_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - string full_name = i.full_name; - if (full_name == this._fullname) - { - foreach (var proto in i.im_addresses.get_keys ()) - { - var addrs = i.im_addresses.get (proto); - - if (proto == "jabber") - { - foreach (var im_fd in addrs) - { - if (im_fd.value == "test1@example.org") - { - this._found_addr_1 = true; - this._num_addrs++; - break; - } - } - } - else if (proto == "aim") - { - foreach (var im_fd in addrs) - { - if (im_fd.value == "test2@example.org") - { - this._found_addr_2 = true; - this._num_addrs++; - break; - } - } - } - } - } - } - - if (this._num_addrs == 2 && - this._found_addr_1 == true && - this._found_addr_2 == true) - this._main_loop.quit (); - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new ImDetailsInterfaceTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/imaddresses-updates.vala b/tests/tracker/imaddresses-updates.vala deleted file mode 100644 index c4b2a66e..00000000 --- a/tests/tracker/imaddresses-updates.vala +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class IMAddressesUpdatesTests : TrackerTest.TestCase -{ - private IndividualAggregator _aggregator; - private GLib.MainLoop _main_loop; - private string _initial_fullname_1; - private string _contact_urn_1; - private string _imaddress_proto_1; - private string _imaddress_1; - private string _imaddress_2; - private string _proto_2; - private string _individual_id; - private bool _initial_imaddress_found; - private bool _updated_imaddr_found; - - public IMAddressesUpdatesTests () - { - base ("IMAddressesUpdates"); - - this.add_test ("im addresses updates", this.test_imaddresses_updates); - } - - public void test_imaddresses_updates () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._initial_fullname_1 = "persona #1"; - this._contact_urn_1 = "<urn:contact001>"; - this._imaddress_proto_1 = "jabber#test1@example.org"; - this._imaddress_1 = "test1@example.org"; - this._imaddress_2 = "test2@example.org"; - this._proto_2 = "aim"; - - c1.set (TrackerTest.Backend.URN, this._contact_urn_1); - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname_1); - c1.set (Trf.OntologyDefs.NCO_IMADDRESS, this._imaddress_proto_1); - ((!) this.tracker_backend).add_contact (c1); - ((!) this.tracker_backend).set_up (); - - this._individual_id = ""; - this._initial_imaddress_found = false; - this._updated_imaddr_found = false; - - this._test_imaddresses_updates_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._initial_imaddress_found == true); - assert (this._updated_imaddr_found == true); - } - - private async void _test_imaddresses_updates_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name != this._initial_fullname_1) - continue; - - if (!this._initial_imaddress_found) - { - this._individual_id = i.id; - - foreach (var proto in i.im_addresses.get_keys ()) - { - var addrs = i.im_addresses.get (proto); - bool contains_addr_1 = false; - foreach (var im_fd in addrs) - { - if (im_fd.value == this._imaddress_1) - { - contains_addr_1 = true; - break; - } - } - - if (addrs.size == 1 && contains_addr_1) - { - this._initial_imaddress_found = true; - this._do_im_addr_update (); - } - } - } - else - { - foreach (var proto in i.im_addresses.get_keys ()) - { - var addrs = i.im_addresses.get (proto); - bool contains_addr_2 = false; - foreach (var im_fd in addrs) - { - if (im_fd.value == this._imaddress_2) - { - contains_addr_2 = true; - break; - } - } - - if (addrs.size == 1 && contains_addr_2) - { - this._updated_imaddr_found = true; - this._main_loop.quit (); - } - } - } - } - } - - private void _do_im_addr_update () - { - var urn_affil_1 = "<" + this._imaddress_1 + "myaffiliation>"; - ((!) this.tracker_backend).remove_triplet (this._contact_urn_1, - Trf.OntologyDefs.NCO_HAS_AFFILIATION, urn_affil_1); - - var urn_imaddr_2 = "<" + this._imaddress_2 + ">"; - ((!) this.tracker_backend).insert_triplet - (urn_imaddr_2, - "a", Trf.OntologyDefs.NCO_IMADDRESS, - Trf.OntologyDefs.NCO_IMPROTOCOL, this._proto_2, - Trf.OntologyDefs.NCO_IMID, this._imaddress_2); - - var urn_affil_2 = "<" + this._imaddress_2; - urn_affil_2 += "myaffiliation>"; - ((!) this.tracker_backend).insert_triplet - (urn_affil_2, - "a", Trf.OntologyDefs.NCO_AFFILIATION); - - ((!) this.tracker_backend).insert_triplet - (urn_affil_2, - Trf.OntologyDefs.NCO_HAS_IMADDRESS, urn_imaddr_2); - - ((!) this.tracker_backend).insert_triplet - (this._contact_urn_1, - Trf.OntologyDefs.NCO_HAS_AFFILIATION, urn_affil_2); - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new IMAddressesUpdatesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/individual-retrieval.vala b/tests/tracker/individual-retrieval.vala deleted file mode 100644 index dc28a51a..00000000 --- a/tests/tracker/individual-retrieval.vala +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class IndividualRetrievalTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private Gee.HashMap<string, string> _c1; - private Gee.HashMap<string, string> _c2; - - public IndividualRetrievalTests () - { - base ("IndividualRetrieval"); - - this.add_test ("singleton individuals", this.test_singleton_individuals); - } - - public void test_singleton_individuals () - { - this._main_loop = new GLib.MainLoop (null, false); - this._c1 = new Gee.HashMap<string, string> (); - this._c2 = new Gee.HashMap<string, string> (); - - this._c1.set (Trf.OntologyDefs.NCO_FULLNAME, "persona #1"); - ((!) this.tracker_backend).add_contact (this._c1); - this._c2.set (Trf.OntologyDefs.NCO_FULLNAME, "persona #2"); - ((!) this.tracker_backend).add_contact (this._c2); - ((!) this.tracker_backend).set_up (); - - this._test_singleton_individuals_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._c1.size == 0); - assert (this._c2.size == 0); - } - - private async void _test_singleton_individuals_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - string full_name = ((Folks.NameDetails) i).full_name; - if (full_name != null) - { - if (this._c1.get (Trf.OntologyDefs.NCO_FULLNAME) == full_name) - { - this._c1.unset (Trf.OntologyDefs.NCO_FULLNAME); - } - - if (this._c2.get (Trf.OntologyDefs.NCO_FULLNAME) == full_name) - { - this._c2.unset (Trf.OntologyDefs.NCO_FULLNAME); - } - } - } - - if (this._c1.size == 0 && - this._c2.size == 0) - this._main_loop.quit (); - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new IndividualRetrievalTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/link-personas-via-local-ids.vala b/tests/tracker/link-personas-via-local-ids.vala deleted file mode 100644 index 6689ae5a..00000000 --- a/tests/tracker/link-personas-via-local-ids.vala +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class LinkPersonasViaLocalIDsTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname_1; - private string _persona_fullname_2; - private bool _linking_fired; - private bool _persona_found_1; - private bool _persona_found_2; - private string _persona_iid_1 = ""; - private string _persona_iid_2 = ""; - private HashSet<Persona> _personas; - private int _removed_individuals = 0; - private Gee.HashSet<string> _local_ids; - - public LinkPersonasViaLocalIDsTests () - { - base ("LinkPersonasViaLocalIDsTests"); - - this.add_test ("test linking personas", - this.test_linking_personas_via_local_ids); - } - - public override void set_up () - { - base.set_up (); - - Environment.set_variable ("FOLKS_PRIMARY_STORE", "tracker", true); - - /* FIXME: this set_up method takes care both of setting - * the connection with Tracker and adding the contacts - * needed for the tests. We might need to trigger those - * actions at separate points so we should decouple them. */ - ((!) this.tracker_backend).set_up (); - } - - public override void tear_down () - { - Environment.unset_variable ("FOLKS_PRIMARY_STORE"); - base.tear_down (); - } - - public void test_linking_personas_via_local_ids () - { - this._main_loop = new GLib.MainLoop (null, false); - this._persona_fullname_1 = "persona #1"; - this._persona_fullname_2 = "persona #2"; - this._personas = new HashSet<Persona> (); - - this._persona_found_1 = false; - this._persona_found_2 = false; - this._linking_fired = false; - - this._local_ids = new Gee.HashSet <string> (); - - this._test_linking_personas_via_local_ids_async.begin (); - - /* Kill the main loop after 8 seconds: if the linked individual hasn't - * show up at this point then we've either seen an error or we've been - * too slow (which we can consider to be failure). */ - TestUtils.loop_run_with_timeout (this._main_loop, 8); - - /* Check we get the new individual (containing the linked - * personas) and that the previous ones were removed. */ - assert (this._local_ids.size == 0); - assert (this._removed_individuals == 2); - } - - private async void _test_linking_personas_via_local_ids_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - - PersonaStore pstore = null; - foreach (var backend in store.enabled_backends.values) - { - pstore = backend.persona_stores.get ("tracker"); - if (pstore != null) - break; - } - assert (pstore != null); - pstore.notify["is-prepared"].connect (this._persona_store_prepared_cb); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _persona_store_prepared_cb (Object obj, ParamSpec params) - { - PersonaStore pstore = (!)(obj as PersonaStore); - - _add_personas.begin (pstore); - } - - /* Here is how this test is expected to work: - * - we start by adding 2 personas - * - this should trigger individuals-changed with 2 new individuals - * - we ask the IndividualAggregator to link the 2 personas coming - * from those individuals - * - we wait for a new Individual which contains the linkable - * attributes of these 2 personas - */ - private async void _add_personas (PersonaStore pstore) - { - HashTable<string, Value?> details1 = new HashTable<string, Value?> - (str_hash, str_equal); - Value? v1 = Value (typeof (string)); - v1.set_string (this._persona_fullname_1); - details1.insert ("full-name", (owned) v1); - - HashTable<string, Value?> details2 = new HashTable<string, Value?> - (str_hash, str_equal); - Value? v2 = Value (typeof (string)); - v2.set_string (this._persona_fullname_2); - details2.insert ("full-name", (owned)v2); - - try - { - yield this._aggregator.add_persona_from_details (null, - pstore, details1); - - yield this._aggregator.add_persona_from_details (null, - pstore, details2); - } - 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 (); - - foreach (var i in added) - { - if (i == null) - { - continue; - } - - /* Lets listen to notifications from those individuals - * which aren't the default (Tracker) user */ - if (!i.is_user) - { - i.notify["full-name"].connect (this._notify_cb); - i.notify["local-ids"].connect (this._notify_cb); - this._check_personas (i); - } - } - - foreach (var i in removed) - { - if (i == null) - { - continue; - } - - this._removed_individuals++; - } - } - - private void _notify_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - this._check_personas (i); - } - - /* As mentioned in _add_personas here we actually check - * for the following events - * - * - spot the 2 individuals corresponding to the 2 personas we've added - * - when we've spotted these 2, we pack them in a list and feed that to - * IndividualAggregator#link_personas - * - this should fire a new individuals-changed event with a new individual - * which should be the linked individual if it contains the linking - * properties of the 2 linked personas. - */ - private void _check_personas (Individual i) - { - Persona first_persona = null; - foreach (var p in i.personas) - { - first_persona = p; - break; - } - - if (i.full_name == this._persona_fullname_1 && - this._persona_iid_1 == "") - { - this._persona_iid_1 = first_persona.iid; - this._personas.add (first_persona); - this._local_ids.add (this._persona_iid_1); - } - else if (i.full_name == this._persona_fullname_2 && - this._persona_iid_2 == "") - { - this._persona_iid_2 = first_persona.iid; - this._personas.add (first_persona); - this._local_ids.add (this._persona_iid_2); - } - else if (i.personas.size > 1) - { - /* Lets check if it contains all the linking properties */ - foreach (var id in i.local_ids) - { - if (this._local_ids.contains (id)) - { - this._local_ids.remove (id); - } - } - - if (this._local_ids.size == 0) - { - this._main_loop.quit (); - } - } - - /* We can try linking the personas only once we've got the - * 2 initially created personas. */ - if (this._personas.size == 2 && - this._linking_fired == false) - { - this._linking_fired = true; - - /* FIXME: we need a way to sync with Tracker - * delayed events. */ - Timeout.add_seconds (2, () => - { - this._aggregator.link_personas.begin (this._personas); - return false; - }); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new LinkPersonasViaLocalIDsTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/link-personas.vala b/tests/tracker/link-personas.vala deleted file mode 100644 index 1d481f6d..00000000 --- a/tests/tracker/link-personas.vala +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class LinkPersonasTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname_1; - private string _persona_fullname_2; - private string _proto = "jabber"; - private string _im_address_1 = "someone-1@jabber.example.org"; - private string _im_address_2 = "someone-2@jabber.example.org"; - private bool _linking_fired; - private bool _persona_found_1; - private bool _persona_found_2; - private string _persona_iid_1 = ""; - private string _persona_iid_2 = ""; - private HashSet<Persona> _personas; - private Gee.HashMap<string, string> _linking_props; - - public LinkPersonasTests () - { - base ("LinkPersonasTests"); - - this.add_test ("test linking personas", this.test_linking_personas); - } - - public override void set_up () - { - base.set_up (); - - Environment.set_variable ("FOLKS_PRIMARY_STORE", "tracker", true); - - /* FIXME: this set_up method takes care both of setting - * the connection with Tracker and adding the contacts - * needed for the tests. We might need to trigger those - * actions at separate points so we should decouple them. */ - ((!) this.tracker_backend).set_up (); - } - - public override void tear_down () - { - Environment.unset_variable ("FOLKS_PRIMARY_STORE"); - base.tear_down (); - } - - public void test_linking_personas () - { - this._main_loop = new GLib.MainLoop (null, false); - this._persona_fullname_1 = "persona #1"; - this._persona_fullname_2 = "persona #2"; - this._personas = new HashSet<Persona> (); - - this._persona_found_1 = false; - this._persona_found_2 = false; - this._linking_fired = false; - - this._linking_props = new Gee.HashMap<string, string> (); - this._linking_props.set ("prop1", this._im_address_1); - this._linking_props.set ("prop2", this._im_address_2); - - this._test_linking_personas_async.begin (); - - /* Kill the main loop after 5 seconds: if the linked individual hasn't - * show up at this point then we've either seen an error or we've been - * too slow (which we can consider to be failure). */ - TestUtils.loop_run_with_timeout (this._main_loop); - - /* Check we get the new individual (containing the linked - * personas) and that the previous ones were removed. */ - assert (this._linking_props.size == 0); - } - - private async void _test_linking_personas_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - - PersonaStore pstore = null; - foreach (var backend in store.enabled_backends.values) - { - pstore = backend.persona_stores.get ("tracker"); - if (pstore != null) - break; - } - assert (pstore != null); - pstore.notify["is-prepared"].connect (this._persona_store_prepared_cb); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _persona_store_prepared_cb (Object obj, ParamSpec params) - { - PersonaStore pstore = (!)(obj as PersonaStore); - - _add_personas.begin (pstore); - } - - /* Here is how this test is expected to work: - * - we start by adding 2 personas - * - this should trigger individuals-changed with 2 new individuals - * - we ask the IndividualAggregator to link the 2 personas coming - * from those individuals - * - we wait for a new Individual which contains the linkable - * attributes of these 2 personas - */ - private async void _add_personas (PersonaStore pstore) - { - HashTable<string, Value?> details1 = new HashTable<string, Value?> - (str_hash, str_equal); - Value? v1 = Value (typeof (MultiMap)); - var im_addrs1 = new HashMultiMap<string, ImFieldDetails> (null, null, - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - im_addrs1.set (this._proto, new ImFieldDetails (this._im_address_1)); - v1.set_object (im_addrs1); - details1.insert ("im-addresses", (owned) v1); - - Value? v2 = Value (typeof (string)); - v2.set_string (this._persona_fullname_1); - details1.insert ("full-name", (owned) v2); - - HashTable<string, Value?> details2 = new HashTable<string, Value?> - (str_hash, str_equal); - Value? v3 = Value (typeof (MultiMap)); - var im_addrs2 = new HashMultiMap<string, ImFieldDetails> (null, null, - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - im_addrs2.set (this._proto, new ImFieldDetails (this._im_address_2)); - v3.set_object (im_addrs2); - details2.insert ("im-addresses", (owned) v3); - - Value? v4 = Value (typeof (string)); - v4.set_string (this._persona_fullname_2); - details2.insert ("full-name", (owned)v4); - - try - { - yield this._aggregator.add_persona_from_details (null, - pstore, details1); - - yield this._aggregator.add_persona_from_details (null, - pstore, details2); - } - 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 (); - - foreach (var i in added) - { - if (i == null) - { - continue; - } - - /* Lets listen to notifications from those individuals - * which aren't the default (Tracker) user */ - if (!i.is_user) - { - this._check_personas (i); - i.notify["full-name"].connect (this._notify_cb); - i.notify["im-addresses"].connect (this._notify_cb); - } - } - } - - private void _notify_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - this._check_personas (i); - } - - /* As mentioned in _add_personas here we actually check - * for the following events - * - * - spot the 2 individuals corresponding to the 2 personas we've added - * - when we've spotted these 2, we pack them in a list and feed that to - * IndividualAggregator#link_personas - * - this should fire a new individuals-changed event with a new individual - * which should be the linked individual if it contains the linking - * properties of the 2 linked personas. - */ - private void _check_personas (Individual i) - { - Persona first_persona = null; - foreach (var p in i.personas) - { - first_persona = p; - break; - } - - if (i.full_name == this._persona_fullname_1 && - this._persona_iid_1 == "") - { - this._persona_iid_1 = first_persona.iid; - this._personas.add (first_persona); - } - else if (i.full_name == this._persona_fullname_2 && - this._persona_iid_2 == "") - { - this._persona_iid_2 = first_persona.iid; - this._personas.add (first_persona); - } - else if (i.personas.size > 1) - { - /* Lets check if it contains all the linking properties */ - foreach (var proto in i.im_addresses.get_keys ()) - { - var addrs = i.im_addresses.get (proto); - foreach (var a in addrs) - { - if (a.value == this._linking_props.get ("prop1")) - { - this._linking_props.unset ("prop1"); - } - else if (a.value == this._linking_props.get ("prop2")) - { - this._linking_props.unset ("prop2"); - } - } - } - - if (this._linking_props.size == 0) - { - this._main_loop.quit (); - } - } - - /* We can try linking the personas only once we've got the - * 2 initially created personas. */ - if (this._personas.size == 2 && - this._linking_fired == false) - { - this._linking_fired = true; - - /* FIXME: we need a way to sync with Tracker - * delayed events. */ - Timeout.add_seconds (2, () => - { - this._aggregator.link_personas.begin (this._personas); - return false; - }); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new LinkPersonasTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/match-all.vala b/tests/tracker/match-all.vala deleted file mode 100644 index f1ec8f03..00000000 --- a/tests/tracker/match-all.vala +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class MatchAllTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator = null; - private string _persona_fullname_1 = "Bernie Innocenti"; - private string _persona_fullname_2 = "Bernardo H. Innocenti"; - private string _persona_fullname_3 = "Travis R."; - private string _persona_fullname_4 = "Travis Reitter"; - private bool _added_personas = false; - private string _individual_id_1 = ""; - private string _individual_id_2 = ""; - private string _individual_id_3 = ""; - private string _individual_id_4 = ""; - private Trf.PersonaStore _pstore; - private GLib.List<int> _matches_all = new GLib.List<int> (); - private int _matches_1 = 0; - - public MatchAllTests () - { - base ("MatchAllTests"); - - this.add_test ("test potential match all ", - this.test_match_all); - } - - public void test_match_all () - { - this._main_loop = new GLib.MainLoop (null, false); - - this._test_match_all_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - /* Expected outcome: - * - * We call IndividualAggregator.get_potential_matches () for - * the Individual with name "Bernie Innocenti" with a threshold - * of MatchResult.MEDIUM so we expect only one match - * ("Bernardo H. Innocenti"). - * - * Then we call IndividualAggregator.get_all_potential_matches () - * and we expect one match (>= MatchResult.MEDIUM) for each Individual - * (not counting the user Individual). - */ - assert (this._matches_1 == 1); - assert (this._matches_all.length () == 4); - foreach (var size in this._matches_all) - { - assert (size == 1); - } - } - - private async void _test_match_all_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - - if (this._aggregator == null) - { - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - } - - try - { - yield this._aggregator.prepare (); - this._pstore = null; - foreach (var backend in store.enabled_backends.values) - { - this._pstore = - (Trf.PersonaStore) backend.persona_stores.get ("tracker"); - if (this._pstore != null) - break; - } - assert (this._pstore != null); - this._pstore.notify["is-prepared"].connect (this._notify_pstore_cb); - this._try_to_add.begin (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname_1) - { - this._individual_id_1 = i.id; - } - else if (i.full_name == this._persona_fullname_2) - { - this._individual_id_2 = i.id; - } - else if (i.full_name == this._persona_fullname_3) - { - this._individual_id_3 = i.id; - } - else if (i.full_name == this._persona_fullname_4) - { - this._individual_id_4 = i.id; - } - } - - if (this._individual_id_1 != "" && - this._individual_id_2 != "" && - this._individual_id_3 != "" && - this._individual_id_4 != "") - { - this._try_match_all (); - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _try_match_all () - { - var ind1 = this._aggregator.individuals.get (this._individual_id_1); - var matches_1 = this._aggregator.get_potential_matches (ind1, - MatchResult.MEDIUM); - this._matches_1 = matches_1.size; - - var all_matches = this._aggregator.get_all_potential_matches ( - MatchResult.MEDIUM); - - foreach (var i in all_matches.keys) - { - if (i.is_user) - continue; - var matches = all_matches.get (i); - this._matches_all.prepend (matches.size); - } - - this._main_loop.quit (); - } - - private void _notify_pstore_cb (Object _pstore, ParamSpec ps) - { - this._try_to_add.begin (); - } - - private async void _try_to_add () - { - if (this._pstore.is_prepared && this._added_personas == false) - { - this._added_personas = true; - yield this._add_personas (); - } - } - - private async void _add_personas () - { - yield this._do_add_persona (this._persona_fullname_1); - yield this._do_add_persona (this._persona_fullname_2); - yield this._do_add_persona (this._persona_fullname_3); - yield this._do_add_persona (this._persona_fullname_4); - } - - private async void _do_add_persona (string fn) - { - HashTable<string, Value?> details = new HashTable<string, Value?> - (str_hash, str_equal); - Value? val; - - val = Value (typeof (string)); - val.set_string (fn); - details.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME), - (owned) val); - - try - { - yield this._aggregator.add_persona_from_details (null, - this._pstore, details); - } - catch (Folks.IndividualAggregatorError e) - { - GLib.warning ("[AddPersonaError] add_persona_from_details: %s\n", - e.message); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new MatchAllTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/match-email-addresses.vala b/tests/tracker/match-email-addresses.vala deleted file mode 100644 index c9499c2c..00000000 --- a/tests/tracker/match-email-addresses.vala +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class MatchEmailAddressesTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname_1 = "aaa"; - private string _persona_fullname_2 = "bbb"; - private string _email_1 = "some-address@jabber.example.org"; - private bool _added_personas = false; - private string _individual_id_1 = ""; - private string _individual_id_2 = ""; - private Folks.MatchResult _match; - private Trf.PersonaStore _pstore; - - public MatchEmailAddressesTests () - { - base ("MatchEmailAddressesTests"); - - this.add_test ("test potential match with same email addresses ", - this.test_match_email_addresses); - } - - public void test_match_email_addresses () - { - this._main_loop = new GLib.MainLoop (null, false); - - this._test_match_email_addresses_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._match >= Folks.MatchResult.HIGH); - } - - private async void _test_match_email_addresses_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - this._pstore = null; - foreach (var backend in store.enabled_backends.values) - { - this._pstore = - (Trf.PersonaStore) backend.persona_stores.get ("tracker"); - if (this._pstore != null) - break; - } - assert (this._pstore != null); - this._pstore.notify["is-prepared"].connect (this._notify_pstore_cb); - this._try_to_add.begin (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname_1) - { - this._individual_id_1 = i.id; - } - else if (i.full_name == this._persona_fullname_2) - { - this._individual_id_2 = i.id; - } - } - - if (this._individual_id_1 != "" && - this._individual_id_2 != "") - { - this._try_potential_match (); - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _try_potential_match () - { - var ind1 = this._aggregator.individuals.get (this._individual_id_1); - var ind2 = this._aggregator.individuals.get (this._individual_id_2); - - Folks.PotentialMatch matchObj = new Folks.PotentialMatch (); - this._match = matchObj.potential_match (ind1, ind2); - - this._main_loop.quit (); - } - - private void _notify_pstore_cb (Object _pstore, ParamSpec ps) - { - this._try_to_add.begin (); - } - - private async void _try_to_add () - { - if (this._pstore.is_prepared && this._added_personas == false) - { - this._added_personas = true; - yield this._add_personas (); - } - } - - private async void _add_personas () - { - HashTable<string, Value?> details1 = new HashTable<string, Value?> - (str_hash, str_equal); - HashTable<string, Value?> details2 = new HashTable<string, Value?> - (str_hash, str_equal); - Value? val; - - val = Value (typeof (string)); - val.set_string (this._persona_fullname_1); - details1.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME), - (owned) val); - - val = Value (typeof (Set)); - var emails1 = new HashSet<EmailFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var email_1 = new EmailFieldDetails (this._email_1); - emails1.add (email_1); - val.set_object (emails1); - details1.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.EMAIL_ADDRESSES), - (owned) val); - - val = Value (typeof (string)); - val.set_string (this._persona_fullname_2); - details2.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME), - (owned) val); - - val = Value (typeof (Set)); - var emails2 = new HashSet<EmailFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var email_2 = new EmailFieldDetails (this._email_1); - emails2.add (email_2); - val.set_object (emails2); - details2.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.EMAIL_ADDRESSES), - (owned) val); - - try - { - yield this._aggregator.add_persona_from_details (null, - this._pstore, details1); - - yield this._aggregator.add_persona_from_details (null, - this._pstore, details2); - } - catch (Folks.IndividualAggregatorError e) - { - GLib.warning ("[AddPersonaError] add_persona_from_details: %s\n", - e.message); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new MatchEmailAddressesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/match-im-addresses.vala b/tests/tracker/match-im-addresses.vala deleted file mode 100644 index c7fad9b6..00000000 --- a/tests/tracker/match-im-addresses.vala +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class MatchIMAddressesTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname_1 = "aaa"; - private string _persona_fullname_2 = "bbb"; - private string _im_addr_1 = "some-address@jabber.example.org"; - private string _im_addr_2 = "some-other-address@jabber.example.org"; - private bool _added_personas = false; - private string _individual_id_1 = ""; - private string _individual_id_2 = ""; - private Folks.MatchResult _match; - private Trf.PersonaStore _pstore; - - public MatchIMAddressesTests () - { - base ("MatchIMAddressesTests"); - - this.add_test ("test potential match by IM addresses ", - this.test_match_im_addresses); - } - - public void test_match_im_addresses () - { - this._main_loop = new GLib.MainLoop (null, false); - - this._test_match_im_addresses_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - assert (this._match >= Folks.MatchResult.HIGH); - } - - private async void _test_match_im_addresses_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - this._pstore = null; - foreach (var backend in store.enabled_backends.values) - { - this._pstore = - (Trf.PersonaStore) backend.persona_stores.get ("tracker"); - if (this._pstore != null) - break; - } - assert (this._pstore != null); - this._pstore.notify["is-prepared"].connect (this._notify_pstore_cb); - this._try_to_add.begin (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname_1) - { - this._individual_id_1 = i.id; - } - else if (i.full_name == this._persona_fullname_2) - { - this._individual_id_2 = i.id; - } - } - - if (this._individual_id_1 != "" && - this._individual_id_2 != "") - { - this._try_potential_match (); - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _try_potential_match () - { - var ind1 = this._aggregator.individuals.get (this._individual_id_1); - var ind2 = this._aggregator.individuals.get (this._individual_id_2); - - Folks.PotentialMatch matchObj = new Folks.PotentialMatch (); - this._match = matchObj.potential_match (ind1, ind2); - - this._main_loop.quit (); - } - - private void _notify_pstore_cb (Object _pstore, ParamSpec ps) - { - this._try_to_add.begin (); - } - - private async void _try_to_add () - { - if (this._pstore.is_prepared && this._added_personas == false) - { - this._added_personas = true; - yield this._add_personas (); - } - } - - private async void _add_personas () - { - HashTable<string, Value?> details1 = new HashTable<string, Value?> - (str_hash, str_equal); - HashTable<string, Value?> details2 = new HashTable<string, Value?> - (str_hash, str_equal); - Value? val; - HashMultiMap<string, ImFieldDetails> im_addrs; - - val = Value (typeof (string)); - val.set_string (this._persona_fullname_1); - details1.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME), - (owned) val); - - val = Value (typeof (MultiMap)); - im_addrs = new HashMultiMap<string, ImFieldDetails> (null, null, - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - im_addrs.set ("jabber", new ImFieldDetails (this._im_addr_1)); - im_addrs.set ("yahoo", new ImFieldDetails (this._im_addr_2)); - val.set_object (im_addrs); - details1.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.IM_ADDRESSES), - (owned) val); - - val = Value (typeof (string)); - val.set_string (this._persona_fullname_2); - details2.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME), - (owned) val); - - val = Value (typeof (MultiMap)); - im_addrs = new HashMultiMap<string, ImFieldDetails> (null, null, - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - im_addrs.set ("jabber", new ImFieldDetails (this._im_addr_2)); - val.set_object (im_addrs); - details2.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.IM_ADDRESSES), - (owned) val); - - try - { - yield this._aggregator.add_persona_from_details (null, - this._pstore, details1); - - yield this._aggregator.add_persona_from_details (null, - this._pstore, details2); - } - catch (Folks.IndividualAggregatorError e) - { - GLib.warning ("[AddPersonaError] add_persona_from_details: %s\n", - e.message); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new MatchIMAddressesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/match-known-emails.vala b/tests/tracker/match-known-emails.vala deleted file mode 100644 index 94f33c17..00000000 --- a/tests/tracker/match-known-emails.vala +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class MatchKnownEmailsTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - - /* Make sure the names are completely different so - * we don't end up accidentally matching by names */ - private string _persona_fullname_1 = "aaa"; - private string _persona_fullname_2 = "bbb"; - - private string _email_1 = "admin@jabber.example.org"; - private bool _added_personas = false; - private string _individual_id_1 = ""; - private string _individual_id_2 = ""; - private Folks.MatchResult _match; - private Trf.PersonaStore _pstore; - - public MatchKnownEmailsTests () - { - base ("MatchKnownEmailsTests"); - - this.add_test ("test potential match with same email addresses ", - this.test_match_email_addresses); - } - - public void test_match_email_addresses () - { - this._main_loop = new GLib.MainLoop (null, false); - - this._test_match_email_addresses_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - /* Some e-mail addresses (namely admin, webmaster, etc.) - * are considered common alias so they shouldn't - * be used to match individuals. - * Hence, we should get a LOW.*/ - assert (this._match <= Folks.MatchResult.LOW); - } - - private async void _test_match_email_addresses_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - this._pstore = null; - foreach (var backend in store.enabled_backends.values) - { - this._pstore = - (Trf.PersonaStore) backend.persona_stores.get ("tracker"); - if (this._pstore != null) - break; - } - assert (this._pstore != null); - this._pstore.notify["is-prepared"].connect (this._notify_pstore_cb); - this._try_to_add.begin (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname_1) - { - this._individual_id_1 = i.id; - } - else if (i.full_name == this._persona_fullname_2) - { - this._individual_id_2 = i.id; - } - } - - if (this._individual_id_1 != "" && - this._individual_id_2 != "") - { - this._try_potential_match (); - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _try_potential_match () - { - var ind1 = this._aggregator.individuals.get (this._individual_id_1); - var ind2 = this._aggregator.individuals.get (this._individual_id_2); - - Folks.PotentialMatch matchObj = new Folks.PotentialMatch (); - this._match = matchObj.potential_match (ind1, ind2); - - this._main_loop.quit (); - } - - private void _notify_pstore_cb (Object _pstore, ParamSpec ps) - { - this._try_to_add.begin (); - } - - private async void _try_to_add () - { - if (this._pstore.is_prepared && this._added_personas == false) - { - this._added_personas = true; - yield this._add_personas (); - } - } - - private async void _add_personas () - { - HashTable<string, Value?> details1 = new HashTable<string, Value?> - (str_hash, str_equal); - HashTable<string, Value?> details2 = new HashTable<string, Value?> - (str_hash, str_equal); - Value? val; - - val = Value (typeof (string)); - val.set_string (this._persona_fullname_1); - details1.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME), - (owned) val); - - val = Value (typeof (Set)); - var emails1 = new HashSet<EmailFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var email_1 = new EmailFieldDetails (this._email_1); - emails1.add (email_1); - val.set_object (emails1); - details1.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.EMAIL_ADDRESSES), - (owned) val); - - val = Value (typeof (string)); - val.set_string (this._persona_fullname_2); - details2.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME), - (owned) val); - - val = Value (typeof (Set)); - var emails2 = new HashSet<EmailFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var email_2 = new EmailFieldDetails (this._email_1); - emails2.add (email_2); - val.set_object (emails2); - details2.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.EMAIL_ADDRESSES), - (owned) val); - - try - { - yield this._aggregator.add_persona_from_details (null, - this._pstore, details1); - - yield this._aggregator.add_persona_from_details (null, - this._pstore, details2); - } - catch (Folks.IndividualAggregatorError e) - { - GLib.warning ("[AddPersonaError] add_persona_from_details: %s\n", - e.message); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new MatchKnownEmailsTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/match-name.vala b/tests/tracker/match-name.vala deleted file mode 100644 index 88ee7f65..00000000 --- a/tests/tracker/match-name.vala +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class MatchNameTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator = null; - private string _persona_fullname_1 = "Bernie Innocenti"; - private string _persona_fullname_2 = "Bernardo H. Innocenti"; - private bool _added_personas; - private string _individual_id_1 = ""; - private string _individual_id_2 = ""; - private Folks.MatchResult _match; - private Trf.PersonaStore _pstore; - - public MatchNameTests () - { - base ("MatchNameTests"); - - this.add_test ("test potential match by name #1 ", - this.test_match_name_1); - this.add_test ("test potential match by name #2 ", - this.test_match_name_2); - this.add_test ("test potential match by name #3 ", - this.test_match_name_3); - this.add_test ("test potential match by name #4 ", - this.test_match_name_4); - this.add_test ("test potential match by name #5 ", - this.test_match_name_5); - this.add_test ("test potential match by name #6 ", - this.test_match_name_6); - } - - private void _test_match_name (string full_name1, string full_name2) - { - this._main_loop = new GLib.MainLoop (null, false); - - this._match = Folks.MatchResult.MIN; - this._added_personas = false; - this._persona_fullname_1 = full_name1; - this._persona_fullname_2 = full_name2; - this._individual_id_1 = ""; - this._individual_id_2 = ""; - - this._test_match_name_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - } - - public void test_match_name_1 () - { - this._test_match_name ("Bernie Innocenti", "Bernardo H. Innocenti"); - assert (this._match >= Folks.MatchResult.MEDIUM); - } - - public void test_match_name_2 () - { - this._test_match_name ("AAAA BBBBB", "CCCCC DDDDD"); - assert (this._match <= Folks.MatchResult.LOW); - } - - public void test_match_name_3 () - { - this._test_match_name ("Travis Reitter", "Travis R."); - assert (this._match >= Folks.MatchResult.MEDIUM); - } - - public void test_match_name_4 () - { - /* Chosen to test the accent- and case-invariance of the matching - * algorithm. The string's repeated so the string lengths get us up to - * a MEDIUM result. */ - this._test_match_name ("PâtéPâtéPâté", "patepatepate"); - assert (this._match >= Folks.MatchResult.MEDIUM); - } - - public void test_match_name_5 () - { - /* bgo#678474 */ - this._test_match_name ("Frédéric Peters", "Frederic Peters"); - assert (this._match >= Folks.MatchResult.HIGH); - } - - public void test_match_name_6 () - { - /* Another one from bgo#678474, testing random punctuation in names */ - this._test_match_name ("Alice Badger", "alice.badger"); - assert (this._match >= Folks.MatchResult.HIGH); - } - - private async void _test_match_name_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - - if (this._aggregator == null) - { - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - } - - try - { - yield this._aggregator.prepare (); - this._pstore = null; - foreach (var backend in store.enabled_backends.values) - { - this._pstore = - (Trf.PersonaStore) backend.persona_stores.get ("tracker"); - if (this._pstore != null) - break; - } - assert (this._pstore != null); - this._pstore.notify["is-prepared"].connect (this._notify_pstore_cb); - this._try_to_add.begin (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname_1) - { - this._individual_id_1 = i.id; - } - else if (i.full_name == this._persona_fullname_2) - { - this._individual_id_2 = i.id; - } - } - - if (this._individual_id_1 != "" && - this._individual_id_2 != "") - { - this._try_potential_match (); - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _try_potential_match () - { - var ind1 = this._aggregator.individuals.get (this._individual_id_1); - var ind2 = this._aggregator.individuals.get (this._individual_id_2); - - Folks.PotentialMatch matchObj = new Folks.PotentialMatch (); - this._match = matchObj.potential_match (ind1, ind2); - - this._main_loop.quit (); - } - - private void _notify_pstore_cb (Object _pstore, ParamSpec ps) - { - this._try_to_add.begin (); - } - - private async void _try_to_add () - { - if (this._pstore.is_prepared && this._added_personas == false) - { - this._added_personas = true; - yield this._add_personas (); - } - } - - private async void _add_personas () - { - HashTable<string, Value?> details1 = new HashTable<string, Value?> - (str_hash, str_equal); - HashTable<string, Value?> details2 = new HashTable<string, Value?> - (str_hash, str_equal); - Value? val; - - val = Value (typeof (string)); - val.set_string (this._persona_fullname_1); - details1.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME), - (owned) val); - - val = Value (typeof (string)); - val.set_string (this._persona_fullname_2); - details2.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME), - (owned) val); - - try - { - yield this._aggregator.add_persona_from_details (null, - this._pstore, details1); - - yield this._aggregator.add_persona_from_details (null, - this._pstore, details2); - } - catch (Folks.IndividualAggregatorError e) - { - GLib.warning ("[AddPersonaError] add_persona_from_details: %s\n", - e.message); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new MatchNameTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/match-phone-number.vala b/tests/tracker/match-phone-number.vala deleted file mode 100644 index 9ad36d36..00000000 --- a/tests/tracker/match-phone-number.vala +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class MatchPhoneNumberTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname_1 = "aaa"; - private string _persona_fullname_2 = "bbb"; - private string _phone_1 = "+1-800-123-4567"; - private string _phone_2 = "123-4567"; - private bool _added_personas = false; - private string _individual_id_1 = ""; - private string _individual_id_2 = ""; - private Folks.MatchResult _match; - private Trf.PersonaStore _pstore; - - public MatchPhoneNumberTests () - { - base ("MatchPhoneNumberTests"); - - this.add_test ("test potential match with phone numbers ", - this.test_match_phone_number); - } - - public void test_match_phone_number () - { - this._main_loop = new GLib.MainLoop (null, false); - - this._test_match_phone_number_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - /* Phone number match is very decisive */ - assert (this._match == Folks.MatchResult.HIGH); - } - - private async void _test_match_phone_number_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - this._pstore = null; - foreach (var backend in store.enabled_backends.values) - { - this._pstore = - (Trf.PersonaStore) backend.persona_stores.get ("tracker"); - if (this._pstore != null) - break; - } - assert (this._pstore != null); - this._pstore.notify["is-prepared"].connect (this._notify_pstore_cb); - this._try_to_add.begin (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname_1) - { - this._individual_id_1 = i.id; - } - else if (i.full_name == this._persona_fullname_2) - { - this._individual_id_2 = i.id; - } - } - - if (this._individual_id_1 != "" && - this._individual_id_2 != "") - { - this._try_potential_match (); - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _try_potential_match () - { - var ind1 = this._aggregator.individuals.get (this._individual_id_1); - var ind2 = this._aggregator.individuals.get (this._individual_id_2); - - Folks.PotentialMatch matchObj = new Folks.PotentialMatch (); - this._match = matchObj.potential_match (ind1, ind2); - - this._main_loop.quit (); - } - - private void _notify_pstore_cb (Object _pstore, ParamSpec ps) - { - this._try_to_add.begin (); - } - - private async void _try_to_add () - { - if (this._pstore.is_prepared && this._added_personas == false) - { - this._added_personas = true; - yield this._add_personas (); - } - } - - private async void _add_personas () - { - HashTable<string, Value?> details1 = new HashTable<string, Value?> - (str_hash, str_equal); - HashTable<string, Value?> details2 = new HashTable<string, Value?> - (str_hash, str_equal); - Value? val; - - val = Value (typeof (string)); - val.set_string (this._persona_fullname_1); - details1.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME), - (owned) val); - - val = Value (typeof (Set)); - var phone_numbers1 = new HashSet<PhoneFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var phone_number_1 = new PhoneFieldDetails (this._phone_1); - phone_numbers1.add (phone_number_1); - val.set_object (phone_numbers1); - details1.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.PHONE_NUMBERS), - (owned) val); - - val = Value (typeof (string)); - val.set_string (this._persona_fullname_2); - details2.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME), - (owned) val); - - val = Value (typeof (Set)); - var phone_numbers2 = new HashSet<PhoneFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var phone_number_2 = new PhoneFieldDetails (this._phone_2); - phone_numbers2.add (phone_number_2); - val.set_object (phone_numbers2); - details2.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.PHONE_NUMBERS), - (owned) val); - - try - { - yield this._aggregator.add_persona_from_details (null, - this._pstore, details1); - - yield this._aggregator.add_persona_from_details (null, - this._pstore, details2); - } - catch (Folks.IndividualAggregatorError e) - { - GLib.warning ("[AddPersonaError] add_persona_from_details: %s\n", - e.message); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new MatchPhoneNumberTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/meson.build b/tests/tracker/meson.build deleted file mode 100644 index 10f7984e..00000000 --- a/tests/tracker/meson.build +++ /dev/null @@ -1,99 +0,0 @@ -# in order from least to most complex -tracker_tests = [ - 'individual-retrieval', - 'name-details-interface', - 'avatar-details-interface', - 'im-details-interface', - 'phone-details-interface', - 'email-details-interface', - 'url-details-interface', - 'favourite-details-interface', - 'fullname-updates', - 'add-contact', - 'default-contact', - 'remove-contact', - 'nickname-updates', - 'family-name-updates', - 'given-name-updates', - 'additional-names-updates', - 'prefix-name-updates', - 'suffix-name-updates', - 'website-updates', - 'favourite-updates', - 'emails-updates', - 'phones-updates', - 'imaddresses-updates', - 'role-details-interface', - 'birthday-details-interface', - 'birthday-updates', - 'note-details-interface', - 'gender-details-interface', - 'postal-address-details-interface', - 'avatar-updates', - 'add-persona', - 'remove-persona', - 'set-nickname', - 'set-favourite', - 'set-phones', - 'set-emails', - 'set-avatar', - 'set-structured-name', - 'set-full-name', - 'set-urls', - 'set-im-addresses', - 'set-postal-addresses', - 'set-roles', - 'set-notes', - 'set-birthday', - 'set-gender', - 'link-personas', - 'duplicated-emails', - 'duplicated-phones', - 'link-personas-via-local-ids', - 'match-im-addresses', - 'match-email-addresses', - 'match-known-emails', - 'match-phone-number', - 'match-name', - 'match-all', - 'set-duplicate-email', - 'set-null-avatar', -] - -tracker_tests_deps = [ - common_test_deps, - tracker_test_lib_dep, - tracker_backendlib_dep, -] - - -foreach _test: tracker_tests - test_install_dir = installed_tests_dir / tracker_backend_name - - test_executable = executable('tracker-'+_test, - '@0@.vala'.format(_test), - dependencies: tracker_tests_deps, - vala_args: common_test_vala_flags, - install: installed_tests_enabled, - install_dir: test_install_dir, - ) - - test(_test, test_executable, - suite: 'TrackerBackend', - is_parallel: false, # FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=709120 - env: common_test_environment, - ) - - if installed_tests_enabled - configure_file( - input: installed_test_template_in, - output: _test + '.test', - configuration: { - 'libexecdir': folks_libexecdir, - 'installed_tests_dir': test_install_dir, - 'program': _test, - }, - install_dir: installed_tests_meta_dir / tracker_backend_name - ) - endif -endforeach diff --git a/tests/tracker/name-details-interface.vala b/tests/tracker/name-details-interface.vala deleted file mode 100644 index 429fb0eb..00000000 --- a/tests/tracker/name-details-interface.vala +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class NameDetailsInterfaceTests : TrackerTest.TestCase -{ - private IndividualAggregator _aggregator; - private GLib.MainLoop _main_loop; - private Gee.HashMap<string, string> _c1; - private Gee.HashMap<string, string> _c2; - - public NameDetailsInterfaceTests () - { - base ("NameDetailsInterfaceTests"); - - this.add_test ("test name details interface", - this.test_name_details_interface); - } - - public void test_name_details_interface () - { - this._main_loop = new GLib.MainLoop (null, false); - this._c1 = new Gee.HashMap<string, string> (); - this._c2 = new Gee.HashMap<string, string> (); - - this._c1.set (Trf.OntologyDefs.NCO_FULLNAME, "persona #1"); - this._c1.set (Trf.OntologyDefs.NCO_FAMILY, "p #1 Family"); - this._c1.set (Trf.OntologyDefs.NCO_GIVEN, "p #1 Given"); - this._c1.set (Trf.OntologyDefs.NCO_ADDITIONAL, "p #1 Additional"); - this._c1.set (Trf.OntologyDefs.NCO_PREFIX, "Mr"); - this._c1.set (Trf.OntologyDefs.NCO_SUFFIX, "Jr"); - ((!) this.tracker_backend).add_contact (this._c1); - - this._c2.set (Trf.OntologyDefs.NCO_FULLNAME, "persona #2"); - ((!) this.tracker_backend).add_contact (this._c2); - - ((!) this.tracker_backend).set_up (); - - this._test_name_details_interface_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._c1.size == 0); - assert (this._c2.size == 0); - } - - private async void _test_name_details_interface_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - string full_name = ((Folks.NameDetails) i).full_name; - if (full_name != null) - { - StructuredName sname = - ((Folks.NameDetails) i).structured_name; - - if (full_name == "persona #1") - { - this._c1.unset (Trf.OntologyDefs.NCO_FULLNAME); - - string family = sname.family_name ; - assert (this._c1.get (Trf.OntologyDefs.NCO_FAMILY) == - family); - this._c1.unset (Trf.OntologyDefs.NCO_FAMILY); - - string given = sname.given_name; - assert (this._c1.get (Trf.OntologyDefs.NCO_GIVEN) == given); - this._c1.unset (Trf.OntologyDefs.NCO_GIVEN); - - string additional = sname.additional_names; - assert (this._c1.get (Trf.OntologyDefs.NCO_ADDITIONAL) == - additional); - this._c1.unset (Trf.OntologyDefs.NCO_ADDITIONAL); - - string prefix = sname.prefixes; - assert (this._c1.get (Trf.OntologyDefs.NCO_PREFIX) == - prefix); - this._c1.unset (Trf.OntologyDefs.NCO_PREFIX); - - string suffix = sname.suffixes; - assert (this._c1.get (Trf.OntologyDefs.NCO_SUFFIX) == - suffix); - this._c1.unset (Trf.OntologyDefs.NCO_SUFFIX); - - assert (sname.is_empty () == false); - } - else if (full_name == "persona #2") - { - this._c2.unset (Trf.OntologyDefs.NCO_FULLNAME); - - assert (sname == null || sname.is_empty () == true); - } - } - } - - if (this._c1.size == 0 && - this._c2.size == 0) - this._main_loop.quit (); - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new NameDetailsInterfaceTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/nickname-updates.vala b/tests/tracker/nickname-updates.vala deleted file mode 100644 index 6943ec01..00000000 --- a/tests/tracker/nickname-updates.vala +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class NicknameUpdatesTests : TrackerTest.TestCase -{ - private IndividualAggregator _aggregator; - private bool _updated_nickname_found; - private string _updated_nickname; - private string _individual_id; - private GLib.MainLoop _main_loop; - private string _initial_fullname; - private string _contact_urn; - - public NicknameUpdatesTests () - { - base ("NicknameUpdates"); - - this.add_test ("nickname updates", this.test_nickname_updates); - } - - public void test_nickname_updates () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._initial_fullname = "persona #1"; - this._updated_nickname = "updated nickname #1"; - this._contact_urn = "<urn:contact001>"; - - c1.set (TrackerTest.Backend.URN, this._contact_urn); - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._updated_nickname_found = false; - this._individual_id = ""; - - this._test_nickname_updates_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._updated_nickname_found == true); - } - - private async void _test_nickname_updates_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._initial_fullname) - { - i.notify["nickname"].connect (this._notify_nickname_cb); - this._individual_id = i.id; - - var im_addr = "<urn:im-address>"; - ((!) this.tracker_backend).insert_triplet (im_addr, - "a", Trf.OntologyDefs.NCO_IMADDRESS, - Trf.OntologyDefs.NCO_IM_NICKNAME, this._updated_nickname); - - var affl = "<urn:im-affl>"; - ((!) this.tracker_backend).insert_triplet (affl, - "a", Trf.OntologyDefs.NCO_AFFILIATION); - - ((!) this.tracker_backend).insert_triplet (affl, - Trf.OntologyDefs.NCO_HAS_IMADDRESS, im_addr); - - ((!) this.tracker_backend).insert_triplet (this._contact_urn, - Trf.OntologyDefs.NCO_HAS_AFFILIATION, affl); - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_nickname_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - if (i.nickname == this._updated_nickname) - { - this._updated_nickname_found = true; - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new NicknameUpdatesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/note-details-interface.vala b/tests/tracker/note-details-interface.vala deleted file mode 100644 index 4f405d07..00000000 --- a/tests/tracker/note-details-interface.vala +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class NoteDetailsInterfaceTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private bool _found_note; - private string _note; - private string _fullname = "persona #1"; - - public NoteDetailsInterfaceTests () - { - base ("NoteDetailsInterfaceTests"); - - this.add_test ("test note details interface", - this.test_note_details_interface); - } - - public void test_note_details_interface () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._fullname = "persona #1"; - this._note = "this is a note"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._fullname); - c1.set (Trf.OntologyDefs.NCO_NOTE, this._note); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._found_note = false; - - this._test_note_details_interface_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._found_note == true); - } - - private async void _test_note_details_interface_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._fullname) - { - i.notify["notes"].connect (this._notify_note_cb); - foreach (var note_fd in i.notes) - { - var note_fd_expected = new NoteFieldDetails (this._note, null, - null); - - /* We copy the tracker_id - we don't know it. - * We could get it from the 1st personas iid but there is no - * real need. */ - note_fd_expected.id = note_fd.id; - - if (note_fd.equal (note_fd_expected)) - { - /* Ensure that setting the Note uid directly (which is - * deprecated) is equivalent to setting the id on a - * NoteFieldDetails directly */ - var note_fd_2 = new NoteFieldDetails ( - note_fd_expected.value, null, note_fd.id); - assert (note_fd.equal (note_fd_2)); - assert (note_fd.id == note_fd_2.id); - - this._found_note = true; - this._main_loop.quit (); - } - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - void _notify_note_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual individual = (Folks.Individual) individual_obj; - foreach (var n in individual.notes) - { - if (n.equal (new NoteFieldDetails (this._note))) - { - this._found_note = true; - this._main_loop.quit (); - } - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new NoteDetailsInterfaceTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/phone-details-interface.vala b/tests/tracker/phone-details-interface.vala deleted file mode 100644 index 3340217b..00000000 --- a/tests/tracker/phone-details-interface.vala +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class PhoneDetailsInterfaceTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private int _num_phones = 0; - private bool _found_phone_1 = false; - private bool _found_phone_2 = false; - - public PhoneDetailsInterfaceTests () - { - base ("PhoneDetailsInterfaceTests"); - - this.add_test ("test phone details interface", - this.test_phone_details_interface); - } - - public void test_phone_details_interface () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, "persona #1"); - c1.set (Trf.OntologyDefs.NCO_PHONE_PROP, "12345,54321"); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._num_phones = 0; - this._found_phone_1 = false; - this._found_phone_2 = false; - - this._test_phone_details_interface_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._num_phones == 2); - assert (this._found_phone_1 == true); - assert (this._found_phone_2 == true); - } - - private async void _test_phone_details_interface_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - string full_name = i.full_name; - if (full_name != null) - { - foreach (var phone in i.phone_numbers) - { - if (phone.equal (new PhoneFieldDetails ("12345"))) - { - this._found_phone_1 = true; - this._num_phones++; - } - else if (phone.equal (new PhoneFieldDetails ("54321"))) - { - this._found_phone_2 = true; - this._num_phones++; - } - } - } - } - - if (this._num_phones == 2 && - this._found_phone_1 == true && - this._found_phone_2 == true) - this._main_loop.quit (); - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new PhoneDetailsInterfaceTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/phones-updates.vala b/tests/tracker/phones-updates.vala deleted file mode 100644 index d704b76a..00000000 --- a/tests/tracker/phones-updates.vala +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class PhonesUpdatesTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _initial_fullname_1; - private string _contact_urn_1; - private string _phone_1; - private string _phone_2; - private string _individual_id; - private bool _initial_phone_found; - private bool _initial_phone_found_again; - private bool _updated_phone_found; - - public PhonesUpdatesTests () - { - base ("PhonesUpdates"); - - this.add_test ("phones updates", this.test_phones_updates); - } - - public void test_phones_updates () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._initial_fullname_1 = "persona #1"; - this._contact_urn_1 = "<urn:contact001>"; - this._phone_1 = "12345"; - this._phone_2 = "54321"; - - c1.set (TrackerTest.Backend.URN, this._contact_urn_1); - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname_1); - c1.set (Trf.OntologyDefs.NCO_PHONE_PROP, this._phone_1); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._individual_id = ""; - this._initial_phone_found = false; - this._initial_phone_found_again = false; - this._updated_phone_found = false; - - this._test_phones_updates_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._initial_phone_found == true); - assert (this._initial_phone_found_again == false); - assert (this._updated_phone_found == true); - } - - private async void _test_phones_updates_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._initial_fullname_1) - { - this._individual_id = i.id; - - i.notify["phone-numbers"].connect (this._notify_phones_cb); - - foreach (var fd in i.phone_numbers) - { - var phone = fd.value; - if (phone == this._phone_1) - { - this._initial_phone_found = true; - this._update_phone (); - } - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_phones_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - foreach (var fd in i.phone_numbers) - { - var phone = fd.value; - if (phone == this._phone_1) - { - this._initial_phone_found_again = true; - } - if (phone == this._phone_2) - { - this._updated_phone_found = true; - this._main_loop.quit (); - } - } - } - - private void _update_phone () - { - var urn_phone_1 = "<" + this._phone_1 + ">"; - ((!) this.tracker_backend).remove_triplet (this._contact_urn_1, - Trf.OntologyDefs.NCO_HAS_AFFILIATION, urn_phone_1); - - var urn_phone_2 = "<phone:" + this._phone_2 + ">"; - ((!) this.tracker_backend).insert_triplet (urn_phone_2, - "a", Trf.OntologyDefs.NCO_PHONE, - Trf.OntologyDefs.NCO_PHONE_PROP, - this._phone_2); - - var affl_2 = "<" + this._phone_2 + ">"; - ((!) this.tracker_backend).insert_triplet - (affl_2, - "a", Trf.OntologyDefs.NCO_AFFILIATION); - ((!) this.tracker_backend).insert_triplet - (affl_2, - Trf.OntologyDefs.NCO_HAS_PHONE, urn_phone_2); - - ((!) this.tracker_backend).insert_triplet - (this._contact_urn_1, - Trf.OntologyDefs.NCO_HAS_AFFILIATION, affl_2); - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new PhonesUpdatesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/postal-address-details-interface.vala b/tests/tracker/postal-address-details-interface.vala deleted file mode 100644 index c14d6bbe..00000000 --- a/tests/tracker/postal-address-details-interface.vala +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class PostalAddressDetailsInterfaceTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _pobox = "12345"; - private string _district = "example district"; - private string _county = "example country"; - private string _locality = "example locality"; - private string _postalcode = "example postalcode"; - private string _street = "example street"; - private string _address = "example address"; - private string _extended = "example extended address"; - private string _country = "example country"; - private string _region = "example region"; - private PostalAddressFieldDetails _postal_address_fd; - private bool _found_postal_address; - private string _fullname; - - public PostalAddressDetailsInterfaceTests () - { - base ("PostalAddressDetailsInterfaceTests"); - - this.add_test ("test postal address details interface", - this.test_postal_address_details_interface); - } - - public void test_postal_address_details_interface () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._fullname = "persona #1"; - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._fullname); - - var pa = new PostalAddress ( - this._pobox, - this._extended, - this._street, - this._locality, - this._region, - this._postalcode, - this._country, - null, "tracker_id"); - this._postal_address_fd = new PostalAddressFieldDetails (pa); - - // nco:pobox, nco:district, nco:county, nco:locality, nco:postalcode, - // nco:streetAddress - // nco:addressLocation, nco:extendedAddress, nco:country, nco:region - string postal_info = this._pobox + ":"; - postal_info += this._district + ":"; - postal_info += this._county + ":"; - postal_info += this._locality + ":"; - postal_info += this._postalcode + ":"; - postal_info += this._street + ":"; - postal_info += this._address + ":"; - postal_info += this._extended + ":"; - postal_info += this._country + ":"; - postal_info += this._region; - - c1.set (Trf.OntologyDefs.NCO_POSTAL_ADDRESS, postal_info); - ((!) this.tracker_backend).add_contact (c1); - ((!) this.tracker_backend).set_up (); - - this._found_postal_address = false; - - this._test_postal_address_details_interface_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._found_postal_address == true); - } - - private async void _test_postal_address_details_interface_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._fullname) - { - foreach (var pafd in i.postal_addresses) - { - /* We copy the tracker_id - we don't know it. - * Although we could get it from the 1st - * personas iid; there is no real need. - */ - this._postal_address_fd.id = pafd.id; - - if (pafd.value.equal (this._postal_address_fd.value)) - { - /* Ensure that setting the postal address uid directly - * (which is deprecated) is equivalent to setting the id on - * a PostalAddressFieldDetails directly */ - var pa_2 = new PostalAddress ( - this._postal_address_fd.value.po_box, - this._postal_address_fd.value.extension, - this._postal_address_fd.value.street, - this._postal_address_fd.value.locality, - this._postal_address_fd.value.region, - this._postal_address_fd.value.postal_code, - this._postal_address_fd.value.country, - null, - pafd.id); - var pa_fd_2 = new PostalAddressFieldDetails (pa_2); - assert (pafd.equal (pa_fd_2)); - assert (pafd.id == pa_fd_2.id); - - this._found_postal_address = true; - this._main_loop.quit (); - } - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new PostalAddressDetailsInterfaceTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/prefix-name-updates.vala b/tests/tracker/prefix-name-updates.vala deleted file mode 100644 index 5207340e..00000000 --- a/tests/tracker/prefix-name-updates.vala +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class PrefixNameUpdatesTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private bool _updated_prefix_name_found; - private bool _initial_prefix_name_found; - private string _updated_prefix_name; - private string _individual_id; - private string _initial_fullname; - private string _initial_prefix_name; - private string _contact_urn; - - public PrefixNameUpdatesTests () - { - base ("PrefixNameUpdates"); - - this.add_test ("prefix name updates", this.test_prefix_name_updates); - } - - public void test_prefix_name_updates () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._initial_fullname = "persona #1"; - this._initial_prefix_name = "prefix name #1"; - this._updated_prefix_name = "updated prefix #1"; - this._contact_urn = "<urn:contact001>"; - - c1.set (TrackerTest.Backend.URN, this._contact_urn); - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname); - c1.set (Trf.OntologyDefs.NCO_PREFIX, this._initial_prefix_name); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._initial_prefix_name_found = false; - this._updated_prefix_name_found = false; - this._individual_id = ""; - - this._test_prefix_name_updates_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._initial_prefix_name_found == true); - assert (this._updated_prefix_name_found == true); - } - - private async void _test_prefix_name_updates_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (this._initial_fullname == i.full_name) - { - var prefix_name = i.structured_name.prefixes; - if (prefix_name == this._initial_prefix_name) - { - i.structured_name.notify["prefixes"].connect - (this._notify_prefix_name_cb); - this._individual_id = i.id; - this._initial_prefix_name_found = true; - ((!) this.tracker_backend).update_contact (this._contact_urn, - Trf.OntologyDefs.NCO_PREFIX, this._updated_prefix_name); - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_prefix_name_cb (Object individual_obj, ParamSpec ps) - { - Folks.StructuredName sname = (Folks.StructuredName) individual_obj; - var prefix_name = sname.prefixes; - if (prefix_name == this._updated_prefix_name) - { - this._updated_prefix_name_found = true; - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new PrefixNameUpdatesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/remove-contact.vala b/tests/tracker/remove-contact.vala deleted file mode 100644 index 7e8a9e34..00000000 --- a/tests/tracker/remove-contact.vala +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class RemoveContactTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private bool _contact_added; - private bool _contact_removed; - private string _individual_id; - private string _persona_fullname; - - public RemoveContactTests () - { - base ("RemoveContactTests"); - - this.add_test ("test removing contacts ", this.test_remove_contact); - } - - public void test_remove_contact () - { - this._main_loop = new GLib.MainLoop (null, false); - this._persona_fullname = "persona #1"; - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname); - ((!) this.tracker_backend).add_contact (c1); - ((!) this.tracker_backend).set_up (); - - this._contact_added = false; - this._contact_removed = false; - this._individual_id = ""; - - this._test_remove_contact_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._contact_added == true); - assert (this._contact_removed == true); - } - - private async void _test_remove_contact_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - if (i == null) - { - continue; - } - - string full_name = i.full_name; - if (full_name == this._persona_fullname) - { - this._contact_added = true; - this._individual_id = i.id; - foreach (var persona in i.personas) - { - var contact_id = persona.iid.split (":")[1]; - ((!) this.tracker_backend).remove_contact (contact_id); - } - } - } - - foreach (var i in removed) - { - if (i == null) - { - continue; - } - - if (i.id == this._individual_id) - { - this._contact_removed = true; - this._main_loop.quit (); - } - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new RemoveContactTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/remove-persona.vala b/tests/tracker/remove-persona.vala deleted file mode 100644 index 657a670a..00000000 --- a/tests/tracker/remove-persona.vala +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class RemovePersonaTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname; - private bool _persona_removed; - private bool _individual_removed; - private string _individual_id; - private PersonaStore _pstore; - private string _persona_id; - private Individual _individual; - private bool _added_persona = false; - - public RemovePersonaTests () - { - base ("RemovePersonaTests"); - - this.add_test ("test adding personas to Tracker ", this.test_remove_persona); - } - - public void test_remove_persona () - { - this._main_loop = new GLib.MainLoop (null, false); - this._persona_fullname = "persona #1"; - - this._persona_removed = false; - this._individual_removed = false; - - this._test_remove_persona_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._persona_removed == true); - assert (this._individual_removed == true); - } - - private async void _test_remove_persona_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - - this._pstore = null; - foreach (var backend in store.enabled_backends.values) - { - this._pstore = backend.persona_stores.get ("tracker"); - if (this._pstore != null) - break; - } - assert (this._pstore != null); - - this._pstore.notify["is-prepared"].connect (this._notify_pstore_cb); - this._try_to_add (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _notify_pstore_cb (Object _pstore, ParamSpec ps) - { - this._try_to_add (); - } - - private void _try_to_add () - { - if (this._pstore.is_prepared && - this._added_persona == false) - { - this._added_persona = true; - this._add_persona.begin (); - } - } - - 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 ("test-1@example.org"); - emails.add (email_1); - var email_2 = new EmailFieldDetails ("test-2@example.org"); - emails.add (email_2); - v2.set_object (emails); - details.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.EMAIL_ADDRESSES), - (owned) v2); - - try - { - yield this._aggregator.add_persona_from_details - (null, this._pstore, details); - } - catch (Folks.IndividualAggregatorError e) - { - GLib.warning ("[RemovePersonaError] 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 (); - - foreach (var i in added) - { - if (i == null) - { - continue; - } - - if (i.full_name == this._persona_fullname) - { - this._individual_id = i.id; - - /* Only examine the first persona */ - foreach (var p in i.personas) - { - this._persona_id = p.iid; - break; - } - - this._individual = i; - if (this._pstore.personas.has_key (this._persona_id) == true) - { - this._pstore.personas_changed.connect (this._personas_cb); - this._aggregator.remove_individual.begin (this._individual); - } - } - } - - foreach (var i in removed) - { - if (i == null) - { - continue; - } - - if (i.id == this._individual_id) - { - this._individual_removed = true; - } - } - } - - private void _personas_cb () - { - if (this._pstore.personas.has_key (this._persona_id) == false) - { - this._persona_removed = true; - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new RemovePersonaTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/role-details-interface.vala b/tests/tracker/role-details-interface.vala deleted file mode 100644 index e7b7318e..00000000 --- a/tests/tracker/role-details-interface.vala +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class RoleDetailsInterfaceTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private bool _found_role; - private string _fullname; - private string _affiliaton; - - public RoleDetailsInterfaceTests () - { - base ("RoleDetailsInterfaceTests"); - - this.add_test ("test role details interface", - this.test_role_details_interface); - } - - public void test_role_details_interface () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._fullname = "persona #1"; - this._affiliaton = "boss,Company,Role"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._fullname); - c1.set (Trf.OntologyDefs.NCO_HAS_AFFILIATION, this._affiliaton); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._found_role = false; - - this._test_role_details_interface_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._found_role == true); - } - - private async void _test_role_details_interface_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._fullname) - { - foreach (var role_fd in i.roles) - { - var role_expected = new Role ("boss", "Company"); - role_expected.role = "Role"; - var role_fd_expected = new RoleFieldDetails (role_expected); - - /* We copy the tracker_id - we don't know it. - * We could get it from the 1st personas iid but there is no - * real need. */ - role_fd_expected.id = role_fd.id; - - if (role_fd.equal (role_fd_expected)) - { - /* Ensure that setting the Role uid directly (which is - * deprecated) is equivalent to setting the id on a - * RoleFieldDetails directly */ - var role_2 = new Role ( - role_expected.title, - role_expected.organisation_name, - role_fd.id); - role_2.role = role_expected.role; - var role_fd_2 = new RoleFieldDetails (role_2); - assert (role_fd.equal (role_fd_2)); - assert (role_fd.id == role_fd_2.id); - - this._found_role = true; - this._main_loop.quit (); - } - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new RoleDetailsInterfaceTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/set-avatar.vala b/tests/tracker/set-avatar.vala deleted file mode 100644 index bad6f336..00000000 --- a/tests/tracker/set-avatar.vala +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SetAvatarTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname; - private LoadableIcon _avatar; - private bool _avatar_found; - - public SetAvatarTests () - { - base ("SetAvatarTests"); - - this.add_test ("test setting avatar ", this.test_set_avatar); - } - - public void test_set_avatar () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._persona_fullname = "persona #1"; - var _avatar_path = Folks.TestUtils.get_source_test_data ( - "data/avatar-01.jpg"); - this._avatar = new FileIcon (File.new_for_path (_avatar_path)); - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._avatar_found = false; - - this._test_set_avatar_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._avatar_found); - } - - private async void _test_set_avatar_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname) - { - i.notify["avatar"].connect (this._notify_avatar_cb); - - foreach (var p in i.personas) - { - ((AvatarDetails) p).avatar = this._avatar; - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_avatar_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - if (i.full_name == this._persona_fullname) - { - /* arbitrary icon size, but it might as well be on the small side */ - TestUtils.loadable_icons_content_equal.begin (i.avatar, - this._avatar, 100, - (obj, result) => - { - if (TestUtils.loadable_icons_content_equal.end (result)) - { - this._avatar_found = true; - this._main_loop.quit (); - } - }); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetAvatarTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/set-birthday.vala b/tests/tracker/set-birthday.vala deleted file mode 100644 index 8a5df059..00000000 --- a/tests/tracker/set-birthday.vala +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SetBirthdayTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname; - private bool _bday_found; - private DateTime _bday; - private string _birthday; - - public SetBirthdayTests () - { - base ("SetBirthdayTests"); - - this.add_test ("test setting bithday ", - this.test_set_bday); - } - - public void test_set_bday () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._persona_fullname = "persona #1"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname); - ((!) this.tracker_backend).add_contact (c1); - - this._birthday = "2001-10-26T20:32:52Z"; - TimeVal t = TimeVal (); - t.from_iso8601 (this._birthday); - this._bday = new DateTime.from_timeval_utc (t); - - ((!) this.tracker_backend).set_up (); - - this._bday_found = false; - - this._test_set_bday_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._bday_found); - } - - private async void _test_set_bday_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname) - { - i.notify["birthday"].connect (this._notify_bday_cb); - - TimeVal t = TimeVal (); - t.from_iso8601 (this._birthday); - DateTime bday = new DateTime.from_timeval_utc (t); - - foreach (var p in i.personas) - { - ((BirthdayDetails) p).birthday = bday; - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_bday_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - if (i.full_name == this._persona_fullname) - { - if (i.birthday != null && - i.birthday.compare (this._bday) == 0) - { - this._bday_found = true; - this._main_loop.quit (); - } - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetBirthdayTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/set-duplicate-email.vala b/tests/tracker/set-duplicate-email.vala deleted file mode 100644 index 95452142..00000000 --- a/tests/tracker/set-duplicate-email.vala +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SetDuplicateEmailTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname_1 = "persona #1"; - private string _email_1 = "some-address@example.org"; - private bool _added_personas = false; - private Trf.PersonaStore _pstore; - private bool _email_found; - - public SetDuplicateEmailTests () - { - base ("SetDuplicateEmailTests"); - - this.add_test ("test re-setting an existing e-mail address", - this.test_set_duplicate_email); - } - - public void test_set_duplicate_email () - { - this._main_loop = new GLib.MainLoop (null, false); - - this._email_found = false; - this._test_set_duplicate_email_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - /* we should see the e-mail address twice: - * 1) when we create the Persona - * 2) when we re-set the address */ - assert (this._email_found == true); - } - - private async void _test_set_duplicate_email_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - this._pstore = null; - foreach (var backend in store.enabled_backends.values) - { - this._pstore = - (Trf.PersonaStore) backend.persona_stores.get ("tracker"); - if (this._pstore != null) - break; - } - assert (this._pstore != null); - this._pstore.notify["is-prepared"].connect (this._notify_pstore_cb); - this._try_to_add.begin (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname_1) - { - this._reset_email_address (i); - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _reset_email_address (Individual i) - { - foreach (var p in i.personas) - { - if (this._has_email ((Trf.Persona) p, this._email_1)) - { - var emails1 = new HashSet<EmailFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var email_1 = new EmailFieldDetails (this._email_1); - emails1.add (email_1); - ((EmailDetails) p).email_addresses = emails1; - p.notify["email-addresses"].connect (this._email_addresses_cb); - } - } - } - - private void _email_addresses_cb (Object p, ParamSpec ps) - { - var persona = (Trf.Persona) p; - if (this._has_email (persona, this._email_1)) - { - this._email_found = true; - this._main_loop.quit (); - } - } - - private bool _has_email (Trf.Persona persona, string email) - { - if (persona.email_addresses != null) - { - foreach (var fd in persona.email_addresses) - { - if (fd.value == email) - { - return true; - } - } - } - - return false; - } - - private void _notify_pstore_cb (Object _pstore, ParamSpec ps) - { - this._try_to_add.begin (); - } - - private async void _try_to_add () - { - if (this._pstore.is_prepared && this._added_personas == false) - { - this._added_personas = true; - yield this._add_personas (); - } - } - - /** - * Add 1 persona and once we've seen it try to re-set it's - * e-mail address (the Tracker backend should figure it already - * exist so we don't bump into a constraint error). - * See https://bugzilla.gnome.org/show_bug.cgi?id=647331 */ - private async void _add_personas () - { - HashTable<string, Value?> details1 = new HashTable<string, Value?> - (str_hash, str_equal); - Value? val; - - val = Value (typeof (string)); - val.set_string (this._persona_fullname_1); - details1.insert (Folks.PersonaStore.detail_key (PersonaDetail.FULL_NAME), - (owned) val); - - val = Value (typeof (Set)); - var emails1 = new HashSet<EmailFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var email_1 = new EmailFieldDetails (this._email_1); - emails1.add (email_1); - val.set_object (emails1); - details1.insert ( - Folks.PersonaStore.detail_key (PersonaDetail.EMAIL_ADDRESSES), - (owned) val); - - try - { - yield this._aggregator.add_persona_from_details (null, - this._pstore, details1); - } - catch (Folks.IndividualAggregatorError e) - { - GLib.warning ("[AddPersonaError] add_persona_from_details: %s\n", - e.message); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetDuplicateEmailTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/set-emails.vala b/tests/tracker/set-emails.vala deleted file mode 100644 index b7e1dade..00000000 --- a/tests/tracker/set-emails.vala +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SetEmailsTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname; - private string _email_1; - private string _email_2; - private bool _email_1_found; - private bool _email_2_found; - - public SetEmailsTests () - { - base ("SetEmailsTests"); - - this.add_test ("test setting emails ", this.test_set_emails); - } - - public void test_set_emails () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._persona_fullname = "persona #1"; - this._email_1 = "email-1@example.org"; - this._email_2 = "email-2@example.org"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._email_1_found = false; - this._email_2_found = false; - - this._test_set_emails_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._email_1_found); - assert (this._email_2_found); - } - - private async void _test_set_emails_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname) - { - i.notify["email-addresses"].connect (this._notify_emails_cb); - - var emails = new HashSet<EmailFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var p1 = new EmailFieldDetails (this._email_1); - emails.add (p1); - var p2 = new EmailFieldDetails (this._email_2); - emails.add (p2); - - foreach (var p in i.personas) - { - ((EmailDetails) p).email_addresses = emails; - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_emails_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - if (i.full_name == this._persona_fullname) - { - foreach (var p in i.email_addresses) - { - if (p.value == this._email_1) - this._email_1_found = true; - else if (p.value == this._email_2) - this._email_2_found = true; - } - } - - if (this._email_1_found && this._email_2_found) - { - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetEmailsTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/set-favourite.vala b/tests/tracker/set-favourite.vala deleted file mode 100644 index 8eb2797c..00000000 --- a/tests/tracker/set-favourite.vala +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SetFavouriteTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _initial_fullname_1 = "persona #1"; - private string _initial_fullname_2 = "persona #2"; - private bool _c1_initially_not_favourite; - private bool _c1_finally_favourite; - private bool _c2_initially_favourite; - private bool _c2_finally_not_favourite; - - public SetFavouriteTests () - { - base ("SetFavouriteTests"); - - this.add_test ("test setting favourite ", this.test_set_alias); - } - - public void test_set_alias () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - Gee.HashMap<string, string> c2 = new Gee.HashMap<string, string> (); - this._initial_fullname_1 = "persona #1"; - this._initial_fullname_2 = "persona #2"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname_1); - ((!) this.tracker_backend).add_contact (c1); - - c2.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname_2); - c2.set (Trf.OntologyDefs.NAO_TAG, ""); - ((!) this.tracker_backend).add_contact (c2); - - ((!) this.tracker_backend).set_up (); - - this._c1_initially_not_favourite = false; - this._c1_finally_favourite = false; - this._c2_initially_favourite = false; - this._c2_finally_not_favourite = false; - - this._test_set_alias_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - /* Note: - * the is-favourite property is notified as a - * consequence of a value changed event fired by - * Tracker - */ - assert (this._c1_initially_not_favourite); - assert (this._c1_finally_favourite); - assert (this._c2_initially_favourite); - assert (this._c2_finally_not_favourite); - } - - private async void _test_set_alias_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - i.notify["is-favourite"].connect (this._notify_favourite_cb); - if (i.full_name == this._initial_fullname_1) - { - if (i.is_favourite == false) - { - this._c1_initially_not_favourite = true; - - foreach (var p in i.personas) - { - ((FavouriteDetails) p).is_favourite = true; - } - } - } - else if (i.full_name == this._initial_fullname_2) - { - if (i.is_favourite == true) - { - this._c2_initially_favourite = true; - - foreach (var p in i.personas) - { - ((FavouriteDetails) p).is_favourite = false; - } - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_favourite_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - if (i.full_name == this._initial_fullname_1) - { - if (i.is_favourite == true) - this._c1_finally_favourite = true; - } - else if (i.full_name == this._initial_fullname_2) - { - if (i.is_favourite == false) - this._c2_finally_not_favourite = true; - } - - if (this._c1_finally_favourite && - this._c2_finally_not_favourite) - this._main_loop.quit (); - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetFavouriteTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/set-full-name.vala b/tests/tracker/set-full-name.vala deleted file mode 100644 index 28a10d02..00000000 --- a/tests/tracker/set-full-name.vala +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SetFullNameTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname; - private bool _found_changed_full_name ; - private string _individual_id; - private string _modified_fullname; - - public SetFullNameTests () - { - base ("SetFullNameTests"); - - this.add_test ("test setting structured name ", - this.test_set_full_name); - } - - public void test_set_full_name () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._persona_fullname = "persona #1"; - this._individual_id = ""; - this._modified_fullname = "modified - persona #1"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._found_changed_full_name = false; - - this._test_set_full_name_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._found_changed_full_name); - } - - private async void _test_set_full_name_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname) - { - this._individual_id = i.id; - i.notify["full-name"].connect (this._notify_full_name_cb); - - foreach (var p in i.personas) - { - ((NameDetails) p).full_name = this._modified_fullname; - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_full_name_cb (Object individual, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual; - if (i.id == this._individual_id && - i.full_name == this._modified_fullname) - { - this._found_changed_full_name = true; - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetFullNameTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/set-gender.vala b/tests/tracker/set-gender.vala deleted file mode 100644 index 7212177a..00000000 --- a/tests/tracker/set-gender.vala +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SetGenderTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname; - private bool _gender_found; - - public SetGenderTests () - { - base ("SetGenderTests"); - - this.add_test ("test setting gender ", - this.test_set_gender); - } - - public void test_set_gender () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._persona_fullname = "persona #1"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._gender_found = false; - - this._test_set_gender_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._gender_found); - } - - private async void _test_set_gender_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname) - { - i.notify["gender"].connect (this._notify_gender_cb); - - foreach (var p in i.personas) - { - ((GenderDetails) p).gender = Gender.MALE; - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_gender_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - if (i.full_name == this._persona_fullname) - { - if (i.gender == Gender.MALE) - { - this._gender_found = true; - this._main_loop.quit (); - } - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetGenderTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/set-im-addresses.vala b/tests/tracker/set-im-addresses.vala deleted file mode 100644 index 7b00e0ab..00000000 --- a/tests/tracker/set-im-addresses.vala +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SetIMAddressesTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname; - private GLib.List<string> _addresses = - new GLib.List<string> (); - private bool _initial_individual_found; - - public SetIMAddressesTests () - { - base ("SetIMAddressesTests"); - - this.add_test ("test setting im_addresses ", this.test_set_im_addresses); - } - - public void test_set_im_addresses () - { - this._initial_individual_found = false; - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = - new Gee.HashMap<string, string> (); - this._persona_fullname = "persona #1"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname); - ((!) this.tracker_backend).add_contact (c1); - - this._addresses.prepend ("one@example.org"); - this._addresses.prepend ("two@example.org"); - this._addresses.prepend ("three@example.org"); - this._addresses.prepend ("four@example.org"); - - ((!) this.tracker_backend).set_up (); - - this._test_set_im_addresses_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._initial_individual_found); - assert (this._addresses.length () == 0); - } - - private async void _test_set_im_addresses_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name != this._persona_fullname) - continue; - - if (!this._initial_individual_found) - { - this._initial_individual_found = true; - i.notify["im-addresses"].connect (this._notify_im_addresses_cb); - - var im_addresses = new HashMultiMap<string, ImFieldDetails> ( - null, null, AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - - im_addresses.set ("aim", new ImFieldDetails ("one@example.org")); - im_addresses.set ("aim", new ImFieldDetails ("two@example.org")); - - im_addresses.set ("yahoo", - new ImFieldDetails ("three@example.org")); - im_addresses.set ("yahoo", - new ImFieldDetails ("four@example.org")); - - foreach (var p in i.personas) - { - ((ImDetails) p).im_addresses = im_addresses; - } - } - else - { - i.notify["im-addresses"].connect (this._notify_im_addresses_cb); - this._check_im_addresses (i); - } - } - } - - private void _notify_im_addresses_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - this._check_im_addresses (i); - } - - private void _check_im_addresses (Individual i) - { - foreach (var proto in i.im_addresses.get_keys ()) - { - var im_fds = i.im_addresses.get (proto); - foreach (var im_fd in im_fds) - { - foreach (unowned string my_a in this._addresses) - { - if (my_a == im_fd.value) - { - this._addresses.remove (my_a); - break; - } - } - } - } - - if (this._addresses.length () == 0) - { - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetIMAddressesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/set-nickname.vala b/tests/tracker/set-nickname.vala deleted file mode 100644 index 1f9e9627..00000000 --- a/tests/tracker/set-nickname.vala +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SetNicknameTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname; - private string _initial_nickname; - private string _modified_nickname; - private bool _initial_nickname_found; - private bool _modified_nickname_found; - - public SetNicknameTests () - { - base ("SetNicknameTests"); - - this.add_test ("test setting nickname ", this.test_set_nickname); - } - - public void test_set_nickname () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._persona_fullname = "persona #1"; - this._initial_nickname = "initial nickname"; - this._modified_nickname = "modified nickname"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname); - c1.set (Trf.OntologyDefs.NCO_NICKNAME, this._initial_nickname); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._initial_nickname_found = false; - this._modified_nickname_found = false; - - this._test_set_nickname_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._initial_nickname_found == true); - assert (this._modified_nickname_found == true); - } - - private async void _test_set_nickname_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname) - { - if (i.nickname == this._initial_nickname) - { - this._initial_nickname_found = true; - - foreach (var p in i.personas) - { - - /* - * We connect to the Persona's handler because - * Individual won't forward the notification to us - * unless it comes from a writeable store. - */ - p.notify["nickname"].connect (this._notify_nickname_cb); - - /* FIXME: - * it would be nice if we could just do: - * i.nickname = "foobar" - * but we depend on: - * https://bugzilla.gnome.org/show_bug.cgi?id=645441 */ - if (p is NameDetails) - { - ((NameDetails) p).nickname = this._modified_nickname; - } - } - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_nickname_cb (Object persona, ParamSpec ps) - { - Trf.Persona p = (Trf.Persona) persona; - if (p.nickname == this._modified_nickname) - { - this._modified_nickname_found = true; - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetNicknameTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/set-notes.vala b/tests/tracker/set-notes.vala deleted file mode 100644 index d5e3876a..00000000 --- a/tests/tracker/set-notes.vala +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SetNotesTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname; - private bool _note_found; - private NoteFieldDetails _note; - - public SetNotesTests () - { - base ("SetNotesTests"); - - this.add_test ("test setting notes ", - this.test_set_notes); - } - - public void test_set_notes () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._persona_fullname = "persona #1"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname); - ((!) this.tracker_backend).add_contact (c1); - - this._note = new NoteFieldDetails ("some note"); - - ((!) this.tracker_backend).set_up (); - - this._note_found = false; - - this._test_set_notes_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._note_found); - } - - private async void _test_set_notes_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname) - { - i.notify["notes"].connect (this._notify_notes_cb); - - Gee.HashSet<NoteFieldDetails> notes = - new HashSet<NoteFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var n = new NoteFieldDetails ("some note"); - notes.add ((owned) n); - - foreach (var p in i.personas) - { - ((NoteDetails) p).notes = notes; - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_notes_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - if (i.full_name == this._persona_fullname) - { - foreach (var n in i.notes) - { - if (n.equal (this._note)) - { - this._note_found = true; - this._main_loop.quit (); - } - } - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetNotesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/set-null-avatar.vala b/tests/tracker/set-null-avatar.vala deleted file mode 100644 index e6671fe0..00000000 --- a/tests/tracker/set-null-avatar.vala +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SetNullAvatarTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname; - private bool _null_avatar_set; - - public SetNullAvatarTests () - { - base ("SetNullAvatarTests"); - - this.add_test ("test setting null avatar ", this.test_set_null_avatar); - } - - public void test_set_null_avatar () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._persona_fullname = "persona #1"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._null_avatar_set = false; - - this._test_set_null_avatar_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._null_avatar_set); - } - - private async void _test_set_null_avatar_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname) - { - foreach (var p in i.personas) - { - ((AvatarDetails) p).avatar = null; - this._set_null_avatar_async.begin (); - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private async void _set_null_avatar_async () - { - yield _do_set_null_avatar_async (); - this._main_loop.quit (); - } - - private async void _do_set_null_avatar_async () - { - this._null_avatar_set = true; - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetNullAvatarTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/set-phones.vala b/tests/tracker/set-phones.vala deleted file mode 100644 index 49a5123e..00000000 --- a/tests/tracker/set-phones.vala +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SetPhonesTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname; - private string _phone_1; - private string _phone_2; - private bool _phone_1_found; - private bool _phone_2_found; - - public SetPhonesTests () - { - base ("SetPhonesTests"); - - this.add_test ("test setting phones ", this.test_set_phones); - } - - public void test_set_phones () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._persona_fullname = "persona #1"; - this._phone_1 = "12345"; - this._phone_2 = "54321"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._phone_1_found = false; - this._phone_2_found = false; - - this._test_set_phones_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._phone_1_found); - assert (this._phone_2_found); - } - - private async void _test_set_phones_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname) - { - i.notify["phone-numbers"].connect (this._notify_phones_cb); - - var phones = new HashSet<PhoneFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - - var p1 = new PhoneFieldDetails (this._phone_1); - phones.add (p1); - var p2 = new PhoneFieldDetails (this._phone_2); - phones.add (p2); - - foreach (var p in i.personas) - { - ((PhoneDetails) p).phone_numbers = phones; - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_phones_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - if (i.full_name == this._persona_fullname) - { - foreach (var p in i.phone_numbers) - { - if (p.equal (new PhoneFieldDetails (this._phone_1))) - this._phone_1_found = true; - else if (p.equal (new PhoneFieldDetails (this._phone_2))) - this._phone_2_found = true; - } - } - - if (this._phone_1_found && this._phone_2_found) - { - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetPhonesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/set-postal-addresses.vala b/tests/tracker/set-postal-addresses.vala deleted file mode 100644 index 94471dd7..00000000 --- a/tests/tracker/set-postal-addresses.vala +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SetPostalAddressesTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname; - private bool _postal_address_found; - private PostalAddressFieldDetails _postal_address_fd; - - public SetPostalAddressesTests () - { - base ("SetPostalAddressesTests"); - - this.add_test ("test setting postal addresses ", - this.test_set_postal_addresses); - } - - public void test_set_postal_addresses () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._persona_fullname = "persona #1"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname); - ((!) this.tracker_backend).add_contact (c1); - - var pa = new PostalAddress (null, null, null, null, null, - null, null, null, null); - pa.po_box = "12345"; - pa.locality = "locality"; - pa.postal_code = "code"; - pa.street = "some street"; - pa.extension = "some extension"; - pa.country = "some country"; - pa.region = "some region"; - this._postal_address_fd = new PostalAddressFieldDetails (pa); - - ((!) this.tracker_backend).set_up (); - - this._postal_address_found = false; - - this._test_set_postal_addresses_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._postal_address_found); - } - - private async void _test_set_postal_addresses_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname) - { - i.notify["postal-addresses"].connect (this._notify_postal_cb); - - var addresses = new HashSet<PostalAddressFieldDetails> ( - AbstractFieldDetails<PostalAddress>.hash_static, - AbstractFieldDetails<PostalAddress>.equal_static); - var pa = new PostalAddress (null, null, null, null, null, - null, null, null, null); - pa.po_box = this._postal_address_fd.value.po_box; - pa.locality = this._postal_address_fd.value.locality; - pa.postal_code = this._postal_address_fd.value.postal_code; - pa.street = this._postal_address_fd.value.street; - pa.extension = this._postal_address_fd.value.extension; - pa.country = this._postal_address_fd.value.country; - pa.region = this._postal_address_fd.value.region; - var pafd = new PostalAddressFieldDetails (pa); - - addresses.add (pafd); - - foreach (var p in i.personas) - { - ((PostalAddressDetails) p).postal_addresses = addresses; - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_postal_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - if (i.full_name == this._persona_fullname) - { - foreach (var pafd in i.postal_addresses) - { - /* we don't care if UIDs differ for this test */ - this._postal_address_fd.id = pafd.id; - if (pafd.equal (this._postal_address_fd)) - { - this._postal_address_found = true; - this._main_loop.quit (); - } - } - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetPostalAddressesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/set-roles.vala b/tests/tracker/set-roles.vala deleted file mode 100644 index 08501670..00000000 --- a/tests/tracker/set-roles.vala +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SetRolesTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname; - private bool _role_found; - private RoleFieldDetails _role_fd; - - public SetRolesTests () - { - base ("SetRolesTests"); - - this.add_test ("test setting roles ", - this.test_set_roles); - } - - public void test_set_roles () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._persona_fullname = "persona #1"; - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname); - ((!) this.tracker_backend).add_contact (c1); - - var role = new Role ("some title", "some organisation"); - role.role = "some role"; - this._role_fd = new RoleFieldDetails (role); - - ((!) this.tracker_backend).set_up (); - - this._role_found = false; - - this._test_set_roles_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._role_found); - } - - private async void _test_set_roles_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname) - { - i.notify["roles"].connect (this._notify_roles_cb); - - Gee.HashSet<RoleFieldDetails> role_fds = - new HashSet<RoleFieldDetails> ( - AbstractFieldDetails<Role>.hash_static, - AbstractFieldDetails<Role>.equal_static); - var role = new Role ("some title", "some organisation"); - role.role = "some role"; - var role_fd = new RoleFieldDetails (role); - role_fds.add ((owned) role_fd); - - foreach (var p in i.personas) - { - ((RoleDetails) p).roles = role_fds; - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_roles_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - if (i.full_name == this._persona_fullname) - { - foreach (var role_fd in i.roles) - { - if (role_fd.equal (this._role_fd)) - { - this._role_found = true; - this._main_loop.quit (); - } - } - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetRolesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/set-structured-name.vala b/tests/tracker/set-structured-name.vala deleted file mode 100644 index f39526f4..00000000 --- a/tests/tracker/set-structured-name.vala +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SetStructuredNameTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname; - private bool _sname_found; - private StructuredName _sname; - private string _family_name; - private string _given_name; - private string _additional_names; - private string _prefixes; - private string _suffixes; - - public SetStructuredNameTests () - { - base ("SetStructuredNameTests"); - - this.add_test ("test setting structured name ", - this.test_set_structured_name); - } - - public void test_set_structured_name () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._persona_fullname = "persona #1"; - this._family_name = "family name"; - this._given_name = "given name"; - this._additional_names = "additional name"; - this._prefixes = "prefixes"; - this._suffixes = "suffixes"; - - this._sname = new StructuredName (this._family_name, this._given_name, - this._additional_names, this._prefixes, this._suffixes); - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._sname_found = false; - - this._test_set_structured_name_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._sname_found); - } - - private async void _test_set_structured_name_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname) - { - foreach (var p in i.personas) - { - p.notify["structured-name"].connect (this._notify_sname_cb); - ((NameDetails) p).structured_name = this._sname; - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_sname_cb (Object persona, ParamSpec ps) - { - Trf.Persona p = (Trf.Persona) persona; - if (p.full_name == this._persona_fullname) - { - if (p.structured_name.is_empty () == false && - p.structured_name.equal (this._sname) == true) - { - this._sname_found = true; - this._main_loop.quit (); - } - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetStructuredNameTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/set-urls.vala b/tests/tracker/set-urls.vala deleted file mode 100644 index 922087c9..00000000 --- a/tests/tracker/set-urls.vala +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SetURLsTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _persona_fullname; - Gee.HashMap<string, string> _urls; - - public SetURLsTests () - { - base ("SetURLsTests"); - - this.add_test ("test setting urls ", this.test_set_urls); - } - - public void test_set_urls () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._persona_fullname = "persona #1"; - this._urls = new Gee.HashMap<string, string> (); - this._urls.set (UrlFieldDetails.PARAM_TYPE_BLOG, - "http://one.example.org"); - this._urls.set (UrlFieldDetails.PARAM_TYPE_HOME_PAGE, - "http://two.example.org"); - this._urls.set (AbstractFieldDetails.PARAM_TYPE_OTHER, - "http://three.example.org"); - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._test_set_urls_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._urls.size == 0); - } - - private async void _test_set_urls_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._persona_fullname) - { - i.notify["urls"].connect (this._notify_urls_cb); - - var url_fds = new HashSet<UrlFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var p1 = new UrlFieldDetails ( - this._urls.get (UrlFieldDetails.PARAM_TYPE_BLOG)); - p1.set_parameter (AbstractFieldDetails.PARAM_TYPE, UrlFieldDetails.PARAM_TYPE_BLOG); - url_fds.add (p1); - var p2 = new UrlFieldDetails ( - this._urls.get (UrlFieldDetails.PARAM_TYPE_HOME_PAGE)); - p2.set_parameter (AbstractFieldDetails.PARAM_TYPE, UrlFieldDetails.PARAM_TYPE_HOME_PAGE); - url_fds.add (p2); - var p3 = new UrlFieldDetails ( - this._urls.get (AbstractFieldDetails.PARAM_TYPE_OTHER)); - url_fds.add (p3); - - foreach (var p in i.personas) - { - ((UrlDetails) p).urls = url_fds; - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_urls_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - if (i.full_name == this._persona_fullname) - { - foreach (var p in i.urls) - { - var type_p = p.get_parameter_values (AbstractFieldDetails.PARAM_TYPE); - - if (type_p != null && - type_p.contains (UrlFieldDetails.PARAM_TYPE_BLOG) && - p.value == this._urls.get (UrlFieldDetails.PARAM_TYPE_BLOG)) - { - this._urls.unset (UrlFieldDetails.PARAM_TYPE_BLOG); - } - else if (type_p != null && - type_p.contains (UrlFieldDetails.PARAM_TYPE_HOME_PAGE) && - p.value == this._urls.get (UrlFieldDetails.PARAM_TYPE_HOME_PAGE)) - { - this._urls.unset (UrlFieldDetails.PARAM_TYPE_HOME_PAGE); - } - else if (type_p == null && - p.value == this._urls.get (AbstractFieldDetails.PARAM_TYPE_OTHER)) - { - this._urls.unset (AbstractFieldDetails.PARAM_TYPE_OTHER); - } - } - } - - if (this._urls.size == 0) - this._main_loop.quit (); - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetURLsTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/suffix-name-updates.vala b/tests/tracker/suffix-name-updates.vala deleted file mode 100644 index 5aa479d1..00000000 --- a/tests/tracker/suffix-name-updates.vala +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class SuffixNameUpdatesTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private bool _updated_suffix_name_found; - private bool _deleted_suffix_name_found; - private bool _initial_suffix_name_found; - private string _updated_suffix_name; - private string _individual_id; - private string _initial_fullname; - private string _initial_suffix_name; - private string _contact_urn; - - public SuffixNameUpdatesTests () - { - base ("SuffixNameUpdates"); - - this.add_test ("suffix name updates", this.test_suffix_name_updates); - } - - public void test_suffix_name_updates () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._initial_fullname = "persona #1"; - this._initial_suffix_name = "suffix name #1"; - this._updated_suffix_name = "updated suffix #1"; - this._contact_urn = "<urn:contact001>"; - - c1.set (TrackerTest.Backend.URN, this._contact_urn); - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname); - c1.set (Trf.OntologyDefs.NCO_SUFFIX, this._initial_suffix_name); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._initial_suffix_name_found = false; - this._updated_suffix_name_found = false; - this._deleted_suffix_name_found = false; - this._individual_id = ""; - - this._test_suffix_name_updates_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._initial_suffix_name_found == true); - assert (this._updated_suffix_name_found == true); - } - - private async void _test_suffix_name_updates_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (this._initial_fullname == i.full_name) - { - var suffix_name = i.structured_name.suffixes; - if (suffix_name == this._initial_suffix_name) - { - i.structured_name.notify["suffixes"].connect - (this._notify_suffix_name_cb); - this._individual_id = i.id; - this._initial_suffix_name_found = true; - ((!) this.tracker_backend).update_contact (this._contact_urn, - Trf.OntologyDefs.NCO_SUFFIX, this._updated_suffix_name); - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_suffix_name_cb (Object individual_obj, ParamSpec ps) - { - Folks.StructuredName sname = (Folks.StructuredName) individual_obj; - var suffix_name = sname.suffixes; - if (suffix_name == this._updated_suffix_name) - { - this._updated_suffix_name_found = true; - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SuffixNameUpdatesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/url-details-interface.vala b/tests/tracker/url-details-interface.vala deleted file mode 100644 index cdfa5d94..00000000 --- a/tests/tracker/url-details-interface.vala +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class UrlDetailsInterfaceTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private string _blog_url; - private string _website_url; - private string _urls; - private bool _found_blog; - private bool _found_website; - - public UrlDetailsInterfaceTests () - { - base ("UrlDetailsInterfaceTests"); - - this.add_test ("test url details interface", - this.test_url_details_interface); - } - - public void test_url_details_interface () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._blog_url = "http://blog.example.org"; - this._website_url = "http://www.example.org"; - this._urls = "%s,%s".printf (this._blog_url, this._website_url); - - c1.set (Trf.OntologyDefs.NCO_FULLNAME, "persona #1"); - c1.set (TrackerTest.Backend.URLS, this._urls); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._found_blog = false; - this._found_website = false; - - this._test_url_details_interface_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._found_blog == true); - assert (this._found_website == true); - } - - private async void _test_url_details_interface_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - string full_name = i.full_name; - if (full_name != null) - { - foreach (var url in i.urls) - { - if (url.value == this._blog_url) - { - this._found_blog = true; - } - else if (url.value == this._website_url) - { - this._found_website = true; - } - } - } - } - - if (this._found_blog && - this._found_website) - this._main_loop.quit (); - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new UrlDetailsInterfaceTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/tracker/website-updates.vala b/tests/tracker/website-updates.vala deleted file mode 100644 index 64a446a5..00000000 --- a/tests/tracker/website-updates.vala +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (C) 2011 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: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk> - * - */ - -using Tracker.Sparql; -using TrackerTest; -using Folks; -using Gee; - -public class WebsiteUpdatesTests : TrackerTest.TestCase -{ - private GLib.MainLoop _main_loop; - private IndividualAggregator _aggregator; - private bool _updated_website_found; - private bool _deleted_website_found; - private bool _initial_website_found; - private string _updated_website; - private string _individual_id; - private string _initial_fullname; - private string _initial_website; - private string _contact_urn; - - public WebsiteUpdatesTests () - { - base ("WebsiteUpdates"); - - this.add_test ("websites updates", this.test_website_updates); - } - - public void test_website_updates () - { - this._main_loop = new GLib.MainLoop (null, false); - Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> (); - this._initial_fullname = "persona #1"; - this._initial_website = "www.example1.org"; - this._updated_website = "www.example2.org"; - this._contact_urn = "<urn:contact001>"; - - c1.set (TrackerTest.Backend.URN, this._contact_urn); - c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname); - c1.set (TrackerTest.Backend.URLS, this._initial_website); - ((!) this.tracker_backend).add_contact (c1); - - ((!) this.tracker_backend).set_up (); - - this._initial_website_found = false; - this._updated_website_found = false; - this._deleted_website_found = false; - this._individual_id = ""; - - this._test_website_updates_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._initial_website_found == true); - assert (this._updated_website_found == true); - } - - private async void _test_website_updates_async () - { - var store = BackendStore.dup (); - yield store.prepare (); - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect - (this._individuals_changed_cb); - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (var i in added) - { - assert (i != null); - - if (i.full_name == this._initial_fullname) - { - i.notify["urls"].connect - (this._notify_website_cb); - - this._individual_id = i.id; - - foreach (var fd in i.urls) - { - var website = fd.value; - if (website == this._initial_website) - { - this._initial_website_found = true; - string affl = "<affl:website>"; - ((!) this.tracker_backend).insert_triplet (affl, - "a", Trf.OntologyDefs.NCO_AFFILIATION, - Trf.OntologyDefs.NCO_WEBSITE, this._updated_website); - ((!) this.tracker_backend).insert_triplet ( - this._contact_urn, - Trf.OntologyDefs.NCO_HAS_AFFILIATION, - affl); - } - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_website_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - - foreach (var fd in i.urls) - { - var website = fd.value; - if (website == this._updated_website) - { - this._updated_website_found = true; - this._main_loop.quit (); - } - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new WebsiteUpdatesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} |