diff options
author | Philip Withnall <philip.withnall@collabora.co.uk> | 2015-06-17 17:16:33 +0100 |
---|---|---|
committer | Philip Withnall <philip.withnall@collabora.co.uk> | 2015-06-17 17:19:34 +0100 |
commit | 790cd8e507f6e0d7febb0e7ba13b1c5f19c2e4ac (patch) | |
tree | dd1ed378b4b5a4c39819ba100d17f3311eea9bfb | |
parent | 023a56394101738c57d9b3aa3698bc58f62b66a9 (diff) | |
download | folks-790cd8e507f6e0d7febb0e7ba13b1c5f19c2e4ac.tar.gz |
tests: Combine and update EDS property setter tests
Combine all the simple set-* tests into a single set-properties test,
eliminating a lot of redundant code.
Fix the remaining code to correctly avoid race conditions, as in commit
023a563.
-rw-r--r-- | tests/eds/Makefile.am | 56 | ||||
-rw-r--r-- | tests/eds/set-avatar.vala | 301 | ||||
-rw-r--r-- | tests/eds/set-birthday.vala | 141 | ||||
-rw-r--r-- | tests/eds/set-gender.vala | 141 | ||||
-rw-r--r-- | tests/eds/set-is-favourite.vala | 141 | ||||
-rw-r--r-- | tests/eds/set-names.vala | 181 | ||||
-rw-r--r-- | tests/eds/set-notes.vala | 143 | ||||
-rw-r--r-- | tests/eds/set-phones.vala | 163 | ||||
-rw-r--r-- | tests/eds/set-postal-addresses.vala | 156 | ||||
-rw-r--r-- | tests/eds/set-properties.vala | 426 | ||||
-rw-r--r-- | tests/eds/set-roles.vala | 140 | ||||
-rw-r--r-- | tests/eds/set-structured-name.vala | 139 | ||||
-rw-r--r-- | tests/eds/set-urls.vala | 187 |
13 files changed, 429 insertions, 1886 deletions
diff --git a/tests/eds/Makefile.am b/tests/eds/Makefile.am index d809fbe7..f1c091de 100644 --- a/tests/eds/Makefile.am +++ b/tests/eds/Makefile.am @@ -54,27 +54,17 @@ all_test_programs = \ im-details \ postal-address-details \ remove-persona \ - set-avatar \ set-emails \ set-im-addresses \ - set-names \ - set-structured-name \ - set-phones \ - set-postal-addresses \ link-personas \ - set-notes \ add-contacts-stress-test \ - set-gender \ - set-urls \ + set-properties \ set-properties-race \ - set-birthday \ - set-roles \ linkable-properties \ link-personas-diff-stores \ store-removed \ anti-linking \ enable-disable-stores \ - set-is-favourite \ perf \ extended-info \ $(NULL) @@ -141,10 +131,6 @@ remove_persona_SOURCES = \ remove-persona.vala \ $(NULL) -set_avatar_SOURCES = \ - set-avatar.vala \ - $(NULL) - linkable_properties_SOURCES = \ linkable-properties.vala \ $(NULL) @@ -157,20 +143,8 @@ set_im_addresses_SOURCES = \ set-im-addresses.vala \ $(NULL) -set_names_SOURCES = \ - set-names.vala \ - $(NULL) - -set_structured_name_SOURCES = \ - set-structured-name.vala \ - $(NULL) - -set_phones_SOURCES = \ - set-phones.vala \ - $(NULL) - -set_postal_addresses_SOURCES = \ - set-postal-addresses.vala \ +set_properties_SOURCES = \ + set-properties.vala \ $(NULL) set_properties_race_SOURCES = \ @@ -181,30 +155,10 @@ link_personas_SOURCES = \ link-personas.vala \ $(NULL) -set_notes_SOURCES = \ - set-notes.vala \ - $(NULL) - add_contacts_stress_test_SOURCES = \ add-contacts-stress-test.vala \ $(NULL) -set_gender_SOURCES = \ - set-gender.vala \ - $(NULL) - -set_urls_SOURCES = \ - set-urls.vala \ - $(NULL) - -set_birthday_SOURCES = \ - set-birthday.vala \ - $(NULL) - -set_roles_SOURCES = \ - set-roles.vala \ - $(NULL) - link_personas_diff_stores_SOURCES = \ link-personas-diff-stores.vala \ $(NULL) @@ -213,10 +167,6 @@ enable_disable_stores_SOURCES = \ enable-disable-stores.vala \ $(NULL) -set_is_favourite_SOURCES = \ - set-is-favourite.vala \ - $(NULL) - store_removed_SOURCES = \ store-removed.vala \ $(NULL) diff --git a/tests/eds/set-avatar.vala b/tests/eds/set-avatar.vala deleted file mode 100644 index e317e2f5..00000000 --- a/tests/eds/set-avatar.vala +++ /dev/null @@ -1,301 +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 EdsTest; -using Folks; -using Gee; - -public class SetAvatarTests : EdsTest.TestCase -{ - private IndividualAggregator _aggregator; - private GLib.MainLoop _main_loop; - private bool _found_before_update; - private bool _found_after_update; - private LoadableIcon _avatar; - - public SetAvatarTests () - { - base ("SetAvatar"); - - this.add_test ("setting avatar on e-d-s persona", this.test_set_avatar); - this.add_test ("setting avatar on e-d-s individual", - this.test_set_individual_avatar); - } - - void test_set_avatar () - { - Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> (); - this._main_loop = new GLib.MainLoop (null, false); - var avatar_path = Folks.TestUtils.get_source_test_data ( - "data/avatar-01.jpg"); - this._avatar = new FileIcon (File.new_for_path (avatar_path)); - Value? v; - - this._found_before_update = false; - this._found_after_update = false; - - this.eds_backend.reset (); - - v = Value (typeof (string)); - v.set_string ("bernie h. innocenti"); - c1.set ("full_name", (owned) v); - this.eds_backend.add_contact (c1); - - this._test_set_avatar_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._found_before_update); - assert (this._found_after_update); - - this._aggregator = null; - this._main_loop = null; - } - - private async void _test_set_avatar_async () - { - yield this.eds_backend.commit_contacts_to_addressbook (); - - 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 (Individual i in added) - { - assert (i != null); - - var name = (Folks.NameDetails) i; - - if (name.full_name == "bernie h. innocenti") - { - i.notify["avatar"].connect (this._notify_avatar_cb); - this._found_before_update = true; - - 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; - var name = (Folks.NameDetails) i; - if (name.full_name == "bernie h. innocenti") - { - TestUtils.loadable_icons_content_equal.begin (i.avatar, - this._avatar, -1, - (obj, result) => - { - if (TestUtils.loadable_icons_content_equal.end (result)) - { - this._found_after_update = true; - - /* we can reach this point multiple times, so we need to make - * sure the main loop is still valid */ - if (this._main_loop != null) - this._main_loop.quit (); - } - }); - } - } - - void test_set_individual_avatar () - { - var c1 = new Gee.HashMap<string, Value?> (); - this._main_loop = new GLib.MainLoop (null, false); - var avatar_path = Folks.TestUtils.get_source_test_data ( - "data/avatar-01.jpg"); - this._avatar = new FileIcon (File.new_for_path (avatar_path)); - Value? v; - - this._found_before_update = false; - this._found_after_update = false; - - this.eds_backend.reset (); - - v = Value (typeof (string)); - v.set_string ("John McClane"); - c1.set ("full_name", (owned) v); - this.eds_backend.add_contact (c1); - - this._test_set_individual_avatar_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._found_before_update); - assert (this._found_after_update); - - this._aggregator = null; - this._main_loop = null; - } - - private async void _test_set_individual_avatar_async () - { - yield this.eds_backend.commit_contacts_to_addressbook (); - - var store = BackendStore.dup (); - yield store.prepare (); - - this._aggregator = IndividualAggregator.dup (); - this._aggregator.individuals_changed_detailed.connect ((changes) => - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (Individual i in added) - { - assert (i != null); - - var name = (Folks.NameDetails) i; - - if (name.full_name == "John McClane") - { - i.notify["avatar"].connect ( - this._notify_individual_avatar_cb); - this._found_before_update = true; - - /* Just set the avatar on the individual */ - i.change_avatar.begin (this._avatar, (obj, res) => - { - try - { - i.change_avatar.end (res); - - assert (this._found_before_update == true); - assert (this._found_after_update == true); - - this._check_individual_has_avatar.begin (i, - (obj, res) => - { - assert ( - this._check_individual_has_avatar.end (res) - == true); - - /* we can reach this point multiple times, so we - * need to make sure the main loop is still valid - */ - if (this._main_loop != null) - this._main_loop.quit (); - }); - } - catch (PropertyError e) - { - critical ("Unexpected error changing avatar: %s", - e.message); - } - }); - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - }); - - try - { - yield this._aggregator.prepare (); - } - catch (GLib.Error e) - { - GLib.warning ("Error when calling prepare: %s\n", e.message); - } - } - - private void _notify_individual_avatar_cb (Object individual_obj, - ParamSpec ps) - { - /* Note: we can't check whether the avatar's correct here, as that's an - * async operation, and if we start that operation in this signal - * callback it'll probably end up finishing after the rest of the code in - * _test_set_individual_avatar_async() has already failed. */ - this._found_after_update = true; - } - - private async bool _check_individual_has_avatar (Individual i) - { - var name = (Folks.NameDetails) i; - - if (name.full_name == "John McClane") - { - var individual_equal = yield TestUtils.loadable_icons_content_equal ( - i.avatar, this._avatar, -1); - - if (individual_equal == true) - { - foreach (var p in i.personas) - { - var persona_equal = - yield TestUtils.loadable_icons_content_equal ( - (p as AvatarDetails).avatar, this._avatar, -1); - - if (p.store.type_id == "eds" && persona_equal == true) - { - return true; - } - } - } - } - - return false; - } -} - -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/eds/set-birthday.vala b/tests/eds/set-birthday.vala deleted file mode 100644 index cb5021c7..00000000 --- a/tests/eds/set-birthday.vala +++ /dev/null @@ -1,141 +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 EdsTest; -using Folks; -using Gee; - -public class SetBirthdayTests : EdsTest.TestCase -{ - private IndividualAggregator _aggregator; - private GLib.MainLoop _main_loop; - private bool _found_before_update; - private bool _found_after_update; - - public SetBirthdayTests () - { - base ("SetBirthday"); - - this.add_test ("setting birthday on an e-d-s persona", - this.test_set_birthday); - } - - void test_set_birthday () - { - Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> (); - this._main_loop = new GLib.MainLoop (null, false); - Value? v; - - this._found_before_update = false; - this._found_after_update = false; - - this.eds_backend.reset (); - - v = Value (typeof (string)); - v.set_string ("John McClane"); - c1.set ("full_name", (owned) v); - this.eds_backend.add_contact (c1); - - this._test_set_birthday_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._found_before_update); - assert (this._found_after_update); - } - - private async void _test_set_birthday_async () - { - yield this.eds_backend.commit_contacts_to_addressbook (); - - 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 (Individual i in added) - { - assert (i != null); - - var name = (Folks.NameDetails) i; - - if (name.full_name == "John McClane") - { - i.notify["birthday"].connect (this._notify_birthday_cb); - this._found_before_update = true; - - var dobj = new DateTime.local (1980, 1, 1, 0, 0, 0.0).to_utc (); - foreach (var p in i.personas) - { - ((BirthdayDetails) p).birthday = dobj; - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_birthday_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - var name = (Folks.NameDetails) i; - var dobj = new DateTime.local (1980, 1, 1, 0, 0, 0.0).to_utc (); - if (name.full_name == "John McClane" && - i.birthday != null && - i.birthday.equal (dobj)) - { - this._found_after_update = 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/eds/set-gender.vala b/tests/eds/set-gender.vala deleted file mode 100644 index cf6e742f..00000000 --- a/tests/eds/set-gender.vala +++ /dev/null @@ -1,141 +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 EdsTest; -using Folks; -using Gee; - -public class SetGenderTests : EdsTest.TestCase -{ - private IndividualAggregator _aggregator; - private GLib.MainLoop _main_loop; - private bool _gender_before_update; - private bool _gender_after_update; - - public SetGenderTests () - { - base ("SetGender"); - - this.add_test ("setting gender on e-d-s persona", - this.test_set_gender); - } - - void test_set_gender () - { - Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> (); - this._main_loop = new GLib.MainLoop (null, false); - Value? v; - - this._gender_before_update = false; - this._gender_after_update = false; - - this.eds_backend.reset (); - - v = Value (typeof (string)); - v.set_string ("jimmy neutron"); - c1.set ("full_name", (owned) v); - this.eds_backend.add_contact (c1); - - this._test_set_gender_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._gender_before_update); - assert (this._gender_after_update); - } - - private async void _test_set_gender_async () - { - yield this.eds_backend.commit_contacts_to_addressbook (); - - 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", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (Individual i in added) - { - assert (i != null); - - var name = (Folks.NameDetails) i; - - if (name.full_name == "jimmy neutron") - { - i.notify["gender"].connect (this._gender_changed_cb); - if (i.gender == Gender.UNSPECIFIED) - { - this._gender_before_update = true; - } - - 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 _gender_changed_cb ( - Object individual_obj, - ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - if (i.gender == Gender.MALE) - { - this._gender_after_update = 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/eds/set-is-favourite.vala b/tests/eds/set-is-favourite.vala deleted file mode 100644 index 3a936de5..00000000 --- a/tests/eds/set-is-favourite.vala +++ /dev/null @@ -1,141 +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 EdsTest; -using Folks; -using Gee; - -public class SetIsFavouriteTests : EdsTest.TestCase -{ - private IndividualAggregator _aggregator; - private GLib.MainLoop _main_loop; - private bool _is_favourite_before_update; - private bool _is_favourite_after_update; - - public SetIsFavouriteTests () - { - base ("SetIsFavourite"); - - this.add_test ("setting is favourite on e-d-s persona", - this.test_set_favourite); - } - - void test_set_favourite () - { - Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> (); - this._main_loop = new GLib.MainLoop (null, false); - Value? v; - - this._is_favourite_before_update = true; - this._is_favourite_after_update = false; - - this.eds_backend.reset (); - - v = Value (typeof (string)); - v.set_string ("juanito from mallorca"); - c1.set ("full_name", (owned) v); - this.eds_backend.add_contact (c1); - - this._test_set_is_favourite_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (!this._is_favourite_before_update); - assert (this._is_favourite_after_update); - } - - private async void _test_set_is_favourite_async () - { - yield this.eds_backend.commit_contacts_to_addressbook (); - - 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", e.message); - } - } - - private void _individuals_changed_cb ( - MultiMap<Individual?, Individual?> changes) - { - var added = changes.get_values (); - var removed = changes.get_keys (); - - foreach (Individual i in added) - { - assert (i != null); - - var name = (Folks.NameDetails) i; - - if (name.full_name == "juanito from mallorca") - { - i.notify["is-favourite"].connect (this._is_favourite_changed_cb); - if (!i.is_favourite) - { - this._is_favourite_before_update = false; - } - - foreach (var p in i.personas) - { - ((FavouriteDetails) p).is_favourite = true; - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _is_favourite_changed_cb ( - Object individual_obj, - ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - if (i.is_favourite) - { - this._is_favourite_after_update = true; - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetIsFavouriteTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/eds/set-names.vala b/tests/eds/set-names.vala deleted file mode 100644 index 0e24f282..00000000 --- a/tests/eds/set-names.vala +++ /dev/null @@ -1,181 +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 EdsTest; -using Folks; -using Gee; - -public class SetNamesTests : EdsTest.TestCase -{ - private IndividualAggregator _aggregator; - private GLib.MainLoop _main_loop; - private bool _full_name_found_before_update; - private bool _full_name_found_after_update; - private bool _nickname_found_before_update; - private bool _nickname_found_after_update; - - public SetNamesTests () - { - base ("SetNames"); - - this.add_test ("setting full name on e-d-s persona", - this.test_set_names); - } - - void test_set_names () - { - Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> (); - this._main_loop = new GLib.MainLoop (null, false); - Value? v; - - this._full_name_found_before_update = false; - this._full_name_found_after_update = false; - this._nickname_found_before_update = false; - this._nickname_found_after_update = false; - - this.eds_backend.reset (); - - v = Value (typeof (string)); - v.set_string ("bernie h. innocenti"); - c1.set ("full_name", (owned) v); - v = Value (typeof (string)); - v.set_string ("foo bar"); - c1.set ("nickname", (owned) v); - this.eds_backend.add_contact (c1); - - this._test_set_names_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._full_name_found_before_update); - assert (this._full_name_found_after_update); - assert (this._nickname_found_before_update); - assert (this._nickname_found_after_update); - } - - private async void _test_set_names_async () - { - yield this.eds_backend.commit_contacts_to_addressbook (); - - 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 (Individual i in added) - { - assert (i != null); - - var name = (Folks.NameDetails) i; - - if (name.full_name == "bernie h. innocenti") - { - i.notify["full-name"].connect ( - this._set_names_notify_full_name_cb); - this._full_name_found_before_update = true; - foreach (var p in i.personas) - { - ((NameDetails) p).full_name = "bernie"; - } - } - - if (name.nickname == "foo bar") - { - i.notify["nickname"].connect ( - this._set_names_notify_nickname_cb); - this._nickname_found_before_update = true; - foreach (var p in i.personas) - { - ((NameDetails) p).nickname = "bar baz"; - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _set_names_notify_full_name_cb ( - Object individual_obj, - ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - var name = (Folks.NameDetails) i; - if (name.full_name == "bernie") - { - this._full_name_found_after_update = true; - this._quit_if_complete (); - } - } - - private void _set_names_notify_nickname_cb ( - Object individual_obj, - ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - var name = (Folks.NameDetails) i; - if (name.nickname == "bar baz") - { - this._nickname_found_after_update = true; - this._quit_if_complete (); - } - } - - private void _quit_if_complete () - { - if (this._full_name_found_after_update && - this._nickname_found_after_update) - { - this._main_loop.quit (); - } - } -} - -public int main (string[] args) -{ - Test.init (ref args); - - var tests = new SetNamesTests (); - tests.register (); - Test.run (); - tests.final_tear_down (); - - return 0; -} diff --git a/tests/eds/set-notes.vala b/tests/eds/set-notes.vala deleted file mode 100644 index 8baa5d27..00000000 --- a/tests/eds/set-notes.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 EdsTest; -using Folks; -using Gee; - -public class SetNotesTests : EdsTest.TestCase -{ - private IndividualAggregator _aggregator; - private GLib.MainLoop _main_loop; - private bool _found_before_update; - private bool _found_after_update; - private string _note = "This is a note."; - - public SetNotesTests () - { - base ("SetNotes"); - - this.add_test ("setting notes name on e-d-s persona", - this.test_set_notes); - } - - void test_set_notes () - { - Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> (); - this._main_loop = new GLib.MainLoop (null, false); - Value? v; - - this._found_before_update = false; - this._found_after_update = false; - - this.eds_backend.reset (); - - v = Value (typeof (string)); - v.set_string ("bernie h. innocenti"); - c1.set ("full_name", (owned) v); - this.eds_backend.add_contact (c1); - - this._test_set_full_name_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._found_before_update); - assert (this._found_after_update); - } - - private async void _test_set_full_name_async () - { - yield this.eds_backend.commit_contacts_to_addressbook (); - - 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 (Individual i in added) - { - assert (i != null); - - var name = (Folks.NameDetails) i; - - if (name.full_name == "bernie h. innocenti") - { - i.notify["notes"].connect (this._notify_notes_cb); - this._found_before_update = true; - - foreach (var p in i.personas) - { - var notes = new HashSet<NoteFieldDetails> (); - var note = new NoteFieldDetails (this._note); - notes.add (note); - ((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; - foreach (var note in i.notes) - { - if (note.equal (new NoteFieldDetails (this._note))) - { - this._found_after_update = 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/eds/set-phones.vala b/tests/eds/set-phones.vala deleted file mode 100644 index ea1dcb5a..00000000 --- a/tests/eds/set-phones.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 EdsTest; -using Folks; -using Gee; - -public class SetPhonesTests : EdsTest.TestCase -{ - private IndividualAggregator _aggregator; - private GLib.MainLoop _main_loop; - private bool _found_before_update; - private Collection<string>? _found_phone_type_after_update; - - public SetPhonesTests () - { - base ("SetPhones"); - - this.add_test ("setting phones on e-d-s persona", this.test_set_phones); - } - - void test_set_phones () - { - Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> (); - this._main_loop = new GLib.MainLoop (null, false); - Value? v; - - this._found_before_update = false; - this._found_phone_type_after_update = null; - - this.eds_backend.reset (); - - v = Value (typeof (string)); - v.set_string ("bernie h. innocenti"); - c1.set ("full_name", (owned) v); - this.eds_backend.add_contact (c1); - - this._test_set_phones_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._found_before_update); - assert (this._found_phone_type_after_update != null); - assert (this._found_phone_type_after_update.size == 1); - assert (this._found_phone_type_after_update.contains (AbstractFieldDetails.PARAM_TYPE_HOME)); - } - - private async void _test_set_phones_async () - { - yield this.eds_backend.commit_contacts_to_addressbook (); - - 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 (Individual i in added) - { - assert (i != null); - - var name = (Folks.NameDetails) i; - - if (name.full_name == "bernie h. innocenti") - { - i.notify["phone-numbers"].connect (this._notify_phones_cb); - this._found_before_update = true; - - foreach (var p in i.personas) - { - var phones = new HashSet<PhoneFieldDetails> ( - AbstractFieldDetails<string>.hash_static, - AbstractFieldDetails<string>.equal_static); - var phone_1 = new PhoneFieldDetails ("1234"); - phone_1.set_parameter (AbstractFieldDetails.PARAM_TYPE, - AbstractFieldDetails.PARAM_TYPE_HOME); - phones.add (phone_1); - ((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; - foreach (var phone_fd in i.phone_numbers) - { - /* - * If EDS is compiled with libphonenumber support, it will - * add an X-EVOLUTION-E164 parameter with the normalized - * phone number. We do not know how EDS is compiled and besides, - * the normalized value also depends on the current locale - * (the 1 in 1234 is a dialing prefix in the US and gets removed - * there, but not elsewhere). - * - * Therefore we cannot do a full comparison against a - * PhoneNumberDetails instance with the expected result, - * because we do not know what that is. - * - * Instead just wait for the phone number to show up, - * then remember the actual type and check that against the expected - * type after returning from the event loop. - */ - if (phone_fd.value == "1234") - { - this._found_phone_type_after_update = phone_fd.get_parameter_values (AbstractFieldDetails.PARAM_TYPE); - 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/eds/set-postal-addresses.vala b/tests/eds/set-postal-addresses.vala deleted file mode 100644 index b1ce391f..00000000 --- a/tests/eds/set-postal-addresses.vala +++ /dev/null @@ -1,156 +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 EdsTest; -using Folks; -using Gee; - -public class SetPostalAddressesTests : EdsTest.TestCase -{ - private IndividualAggregator _aggregator; - private GLib.MainLoop _main_loop; - private bool _found_before_update; - private bool _found_after_update; - private PostalAddressFieldDetails _pa_fd; - - public SetPostalAddressesTests () - { - base ("SetPostalAddresses"); - - this.add_test ("setting postal addresss on e-d-s persona", - this.test_set_postal_addresses); - } - - void test_set_postal_addresses () - { - Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> (); - this._main_loop = new GLib.MainLoop (null, false); - Value? v; - var pa = new PostalAddress ("123", "extension", "street", - "locality", "region", "postal code", "country", "", - "123"); - this._pa_fd = new PostalAddressFieldDetails (pa); - this._pa_fd.add_parameter (AbstractFieldDetails.PARAM_TYPE, - AbstractFieldDetails.PARAM_TYPE_OTHER); - - this._found_before_update = false; - this._found_after_update = false; - - this.eds_backend.reset (); - - v = Value (typeof (string)); - v.set_string ("bernie h. innocenti"); - c1.set ("full_name", (owned) v); - this.eds_backend.add_contact (c1); - - this._test_set_postal_addresses_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop); - - assert (this._found_before_update); - assert (this._found_after_update); - } - - private async void _test_set_postal_addresses_async () - { - yield this.eds_backend.commit_contacts_to_addressbook (); - - 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 (Individual i in added) - { - assert (i != null); - - var name = (Folks.NameDetails) i; - - if (name.full_name == "bernie h. innocenti") - { - i.notify["postal-addresses"].connect ( - this._notify_postal_addresses_cb); - this._found_before_update = true; - - foreach (var p in i.personas) - { - var pa_fds = new HashSet<PostalAddressFieldDetails> (); - var pa_1 = new PostalAddress ("123", "extension", "street", - "locality", "region", "postal code", "country", "format", - "123"); - var pa_fd_1 = new PostalAddressFieldDetails (pa_1); - pa_fd_1.add_parameter (AbstractFieldDetails.PARAM_TYPE, - AbstractFieldDetails.PARAM_TYPE_OTHER); - pa_fds.add (pa_fd_1); - ((PostalAddressDetails) p).postal_addresses = pa_fds; - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_postal_addresses_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - foreach (var pa_fd in i.postal_addresses) - { - pa_fd.id = this._pa_fd.id; - if (pa_fd.equal (this._pa_fd)) - { - this._found_after_update = 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/eds/set-properties.vala b/tests/eds/set-properties.vala new file mode 100644 index 00000000..33802ed2 --- /dev/null +++ b/tests/eds/set-properties.vala @@ -0,0 +1,426 @@ +/* + * Copyright (C) 2011, 2015 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> + * Philip Withnall <philip.withnall@collabora.co.uk> + * + */ + +using EdsTest; +using Folks; +using Gee; + +public class SetPropertiesTests : EdsTest.TestCase +{ + private delegate void PreCheck (Individual i); + private delegate void SetProperty (Persona p); + private delegate void PostCheck (Individual i); + private struct TestDetails + { + string prop_name; + unowned PreCheck pre_check; + unowned SetProperty set_property; + unowned PostCheck post_check; + } + + public SetPropertiesTests () + { + base ("SetProperties"); + + /* TODO: Docs; don't forget to add tests below */ + TestDetails birthday_details = + { + "birthday", (i) => + { + assert (i.birthday == null); + }, + (p) => + { + var dobj = new DateTime.local (1980, 1, 1, 0, 0, 0.0).to_utc (); + ((BirthdayDetails) p).birthday = dobj; + }, + (i) => + { + var dobj = new DateTime.local (1980, 1, 1, 0, 0, 0.0).to_utc (); + assert (i.birthday != null && i.birthday.equal (dobj)); + } + }; + + TestDetails full_name_details = + { + "full-name", (i) => + { + assert (i.full_name == "bernie h. innocenti"); + }, + (p) => + { + ((NameDetails) p).full_name = "bernie"; + }, + (i) => + { + assert (i.full_name == "bernie"); + } + }; + + TestDetails gender_details = + { + "gender", (i) => + { + assert (i.gender == Gender.UNSPECIFIED); + }, + (p) => + { + ((GenderDetails) p).gender = Gender.MALE; + }, + (i) => + { + assert (i.gender == Gender.MALE); + } + }; + + TestDetails is_favourite_details = + { + "is-favourite", (i) => + { + assert (!i.is_favourite); + }, + (p) => + { + ((FavouriteDetails) p).is_favourite = true; + }, + (i) => + { + assert (i.is_favourite); + } + }; + + TestDetails nickname_details = + { + "nickname", (i) => + { + assert (i.nickname == ""); + }, + (p) => + { + ((NameDetails) p).nickname = "bernster"; + }, + (i) => + { + assert (i.nickname == "bernster"); + } + }; + + TestDetails notes_details = + { + "notes", (i) => + { + assert (i.notes.size == 0); + }, + (p) => + { + var notes = new HashSet<NoteFieldDetails> (); + var note = new NoteFieldDetails ("This is a note."); + notes.add (note); + ((NoteDetails) p).notes = notes; + }, + (i) => + { + foreach (var note in i.notes) + { + assert (note.equal ( + new NoteFieldDetails ("This is a note."))); + } + } + }; + + TestDetails phone_numbers_details = + { + "phone-numbers", (i) => + { + assert (i.phone_numbers.size == 0); + }, + (p) => + { + var phones = new HashSet<PhoneFieldDetails> ( + AbstractFieldDetails<string>.hash_static, + AbstractFieldDetails<string>.equal_static); + var phone_1 = new PhoneFieldDetails ("1234"); + phone_1.set_parameter (AbstractFieldDetails.PARAM_TYPE, + AbstractFieldDetails.PARAM_TYPE_HOME); + phones.add (phone_1); + ((PhoneDetails) p).phone_numbers = phones; + }, + (i) => + { + var found = false; + + foreach (var phone_fd in i.phone_numbers) + { + /* + * If EDS is compiled with libphonenumber support, it will + * add an X-EVOLUTION-E164 parameter with the normalized + * phone number. We do not know how EDS is compiled and besides, + * the normalized value also depends on the current locale + * (the 1 in 1234 is a dialing prefix in the US and gets removed + * there, but not elsewhere). + * + * Therefore we cannot do a full comparison against a + * PhoneNumberDetails instance with the expected result, + * because we do not know what that is. + * + * Instead just wait for the phone number to show up, + * then remember the actual type and check that against the expected + * type after returning from the event loop. + */ + if (phone_fd.value == "1234") + { + found = true; + var vals = phone_fd.get_parameter_values (AbstractFieldDetails.PARAM_TYPE); + assert (vals != null); + assert (vals.size == 1); + assert (vals.contains (AbstractFieldDetails.PARAM_TYPE_HOME)); + } + } + + assert (found); + } + }; + + TestDetails postal_addresses_details = + { + "postal-addresses", (i) => + { + assert (i.postal_addresses.size == 0); + }, + (p) => + { + var pa_fds = new HashSet<PostalAddressFieldDetails> (); + var pa_1 = new PostalAddress ("123", "extension", "street", + "locality", "region", "postal code", "country", "format", + "123"); + var pa_fd_1 = new PostalAddressFieldDetails (pa_1); + pa_fd_1.add_parameter (AbstractFieldDetails.PARAM_TYPE, + AbstractFieldDetails.PARAM_TYPE_OTHER); + pa_fds.add (pa_fd_1); + ((PostalAddressDetails) p).postal_addresses = pa_fds; + }, + (i) => + { + var pa = new PostalAddress ("123", "extension", "street", + "locality", "region", "postal code", "country", "", + "123"); + var expected_pa_fd = new PostalAddressFieldDetails (pa); + expected_pa_fd.add_parameter (AbstractFieldDetails.PARAM_TYPE, + AbstractFieldDetails.PARAM_TYPE_OTHER); + + foreach (var pa_fd in i.postal_addresses) + { + pa_fd.id = expected_pa_fd.id; + assert (pa_fd.equal (expected_pa_fd)); + } + } + }; + + TestDetails roles_details = + { + "roles", (i) => + { + assert (i.roles.size == 0); + }, + (p) => + { + var role_fds = new HashSet<RoleFieldDetails> ( + AbstractFieldDetails<Role>.hash_static, + AbstractFieldDetails<Role>.equal_static); + var r1 = new Role ("Dr.", "The Nut House Ltd"); + r1.role = "The Manager"; + var role_fd1 = new RoleFieldDetails (r1); + role_fds.add (role_fd1); + ((RoleDetails) p).roles = role_fds; + }, + (i) => + { + foreach (var role_fd in i.roles) + { + var r1 = new Role ("Dr.", "The Nut House Ltd"); + r1.role = "The Manager"; + var role_fd_expected = new RoleFieldDetails (r1); + assert (role_fd.equal (role_fd_expected)); + } + } + }; + + TestDetails structured_name_details = + { + "structured-name", (i) => + { + assert (i.structured_name != null); + }, + (p) => + { + ((NameDetails) p).structured_name = + new StructuredName.simple ("Neutron", "Jimmy"); + }, + (i) => + { + assert (i.structured_name.equal ( + new StructuredName.simple ("Neutron", "Jimmy"))); + } + }; + + TestDetails urls_details = + { + "urls", (i) => + { + assert (i.urls.size == 0); + }, + (p) => + { + var urls = new HashSet<UrlFieldDetails> (); + + var p1 = new UrlFieldDetails ("http://example.org"); + urls.add (p1); + var p2 = new UrlFieldDetails ("http://extra.example.org"); + urls.add (p2); + var p3 = new UrlFieldDetails ("http://home.example.org"); + p3.set_parameter(AbstractFieldDetails.PARAM_TYPE, + UrlFieldDetails.PARAM_TYPE_HOME_PAGE); + urls.add (p3); + var p4 = new UrlFieldDetails ("http://blog.example.org"); + p4.set_parameter(AbstractFieldDetails.PARAM_TYPE, + UrlFieldDetails.PARAM_TYPE_BLOG); + urls.add (p4); + + ((UrlDetails) p).urls = urls; + }, + (i) => + { + var found_url_extra_1 = false; + var found_url_extra_2 = false; + var found_url_home = false; + var found_url_blog = false; + + foreach (var url in i.urls) + { + if (url.value == "http://example.org") + found_url_extra_1 = true; + else if (url.value == "http://extra.example.org") + found_url_extra_2 = true; + else if (url.value == "http://home.example.org") + found_url_home = true; + else if (url.value == "http://blog.example.org") + found_url_blog = true; + } + + assert (found_url_extra_1); + assert (found_url_extra_2); + assert (found_url_home); + assert (found_url_blog); + } + }; + + /* NOTE: im-addresses and email-addresses are not tested here because + * they are linkable properties, and hence cause re-linking in the + * aggregator, which is too complex for this test suite. They are tested + * in the set-emails and set-im-addresses test suites. */ + TestDetails[] properties = + { + birthday_details, + full_name_details, + gender_details, + is_favourite_details, + nickname_details, + notes_details, + phone_numbers_details, + postal_addresses_details, + roles_details, + structured_name_details, + urls_details, + +/* TODO + AntiLinkable, + AvatarDetails, + ExtendedInfo, + GroupDetails, + LocalIdDetails, + LocationDetails, + WebServiceDetails */ + }; + + foreach (var _details in properties) + { + var details = _details; /* bind the value for the closure below */ + this.add_test (details.prop_name, () => + { + this._test_set_property (details.prop_name, + details.pre_check, details.set_property, details.post_check); + }); + } + } + + private void _test_set_property (string prop_name, + PreCheck pre_check, SetProperty set_property, PostCheck post_check) + { + /* Set up the backend. */ + var c1 = new Gee.HashMap<string, Value?> (); + Value? v; + + v = Value (typeof (string)); + v.set_string ("bernie h. innocenti"); + c1.set ("full_name", (owned) v); + + this.eds_backend.add_contact (c1); + this.eds_backend.commit_contacts_to_addressbook_sync (); + + /* Set up the aggregator and wait until either the expected personas are + * seen, or the test times out and fails. */ + var aggregator = IndividualAggregator.dup (); + TestUtils.aggregator_prepare_and_wait_for_individuals_sync_with_timeout ( + aggregator, {"bernie h. innocenti"}); + + /* Test, change, and test again the properties of the individual. */ + var i = TestUtils.get_individual_by_name (aggregator, + "bernie h. innocenti"); + var main_loop = new MainLoop (); + var handler = i.notify[prop_name].connect ((o, pspec) => + { + Folks.Individual ind = (Folks.Individual) o; + post_check (ind); + main_loop.quit (); + }); + + pre_check (i); + + foreach (var p in i.personas) + set_property (p); + + TestUtils.loop_run_with_timeout (main_loop); + + i.disconnect (handler); + } +} + +public int main (string[] args) +{ + Test.init (ref args); + + var tests = new SetPropertiesTests (); + tests.register (); + Test.run (); + tests.final_tear_down (); + + return 0; +} diff --git a/tests/eds/set-roles.vala b/tests/eds/set-roles.vala deleted file mode 100644 index c0c064e4..00000000 --- a/tests/eds/set-roles.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 EdsTest; -using Folks; -using Gee; - -public class SetRolesTests : EdsTest.TestCase -{ - private IndividualAggregator _aggregator; - private GLib.MainLoop _main_loop; - private bool _found_before_update; - private bool _found_after_update; - - - public SetRolesTests () - { - base ("SetRoles"); - - this.add_test ("setting roles on e-d-s persona", - this.test_set_roles); - } - - void test_set_roles () - { - Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> (); - this._main_loop = new GLib.MainLoop (null, false); - Value? v; - - this._found_before_update = false; - this._found_after_update = false; - - this.eds_backend.reset (); - - v = Value (typeof (string)); - v.set_string ("The Guard"); - c1.set ("full_name", (owned) v); - this.eds_backend.add_contact (c1); - - this._test_set_roles_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop, 5); - - assert (this._found_before_update); - assert (this._found_after_update); - } - - private async void _test_set_roles_async () - { - yield this.eds_backend.commit_contacts_to_addressbook (); - - 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 (Individual i in added) - { - var name = (Folks.NameDetails) i; - - if (name.full_name == "The Guard") - { - i.notify["roles"].connect (this._notify_roles_cb); - this._found_before_update = true; - - foreach (var p in i.personas) - { - var role_fds = new HashSet<RoleFieldDetails> ( - AbstractFieldDetails<Role>.hash_static, - AbstractFieldDetails<Role>.equal_static); - var r1 = new Role ("Dr.", "The Nut House Ltd"); - r1.role = "The Manager"; - var role_fd1 = new RoleFieldDetails (r1); - role_fds.add (role_fd1); - ((RoleDetails) p).roles = role_fds; - } - } - } - } - - private void _notify_roles_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - foreach (var role_fd in i.roles) - { - var r1 = new Role ("Dr.", "The Nut House Ltd"); - r1.role = "The Manager"; - var role_fd_expected = new RoleFieldDetails (r1); - if (role_fd.equal (role_fd_expected)) - { - this._found_after_update = 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/eds/set-structured-name.vala b/tests/eds/set-structured-name.vala deleted file mode 100644 index fd5053cf..00000000 --- a/tests/eds/set-structured-name.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 EdsTest; -using Folks; -using Gee; - -public class SetStructuredNameTests : EdsTest.TestCase -{ - private IndividualAggregator _aggregator; - private GLib.MainLoop _main_loop; - private bool _found_before_update; - private bool _found_after_update; - private StructuredName _sname; - - public SetStructuredNameTests () - { - base ("SetStructuredName"); - - this.add_test ("setting structured name on e-d-s persona", - this.test_set_structured_name); - } - - void test_set_structured_name () - { - Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> (); - this._main_loop = new GLib.MainLoop (null, false); - this._sname = new StructuredName.simple ("Innocenti", "Bernie"); - Value? v; - - this._found_before_update = false; - this._found_after_update = false; - - this.eds_backend.reset (); - - v = Value (typeof (string)); - v.set_string ("bernie h. innocenti"); - c1.set ("full_name", (owned) v); - this.eds_backend.add_contact (c1); - - this._test_set_structured_name_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop, 5); - - assert (this._found_before_update); - assert (this._found_after_update); - } - - private async void _test_set_structured_name_async () - { - yield this.eds_backend.commit_contacts_to_addressbook (); - - 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 (Individual i in added) - { - assert (i != null); - - var name = (Folks.NameDetails) i; - - if (name.full_name == "bernie h. innocenti") - { - i.notify["structured-name"].connect ( - this._notify_structured_name_cb); - this._found_before_update = true; - - foreach (var p in i.personas) - { - ((NameDetails) p).structured_name = this._sname; - } - } - } - - assert (removed.size == 1); - - foreach (var i in removed) - { - assert (i == null); - } - } - - private void _notify_structured_name_cb (Object individual_obj, ParamSpec ps) - { - Folks.Individual i = (Folks.Individual) individual_obj; - if (i.structured_name.equal (this._sname)) - { - this._found_after_update = 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/eds/set-urls.vala b/tests/eds/set-urls.vala deleted file mode 100644 index d828f768..00000000 --- a/tests/eds/set-urls.vala +++ /dev/null @@ -1,187 +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 EdsTest; -using Folks; -using Gee; - -public class SetUrlsTests : EdsTest.TestCase -{ - private IndividualAggregator _aggregator; - private GLib.MainLoop _main_loop; - private bool _found_before_update; - private bool _found_url_extra_1; - private bool _found_url_extra_2; - private bool _found_url_home; - private bool _found_url_blog; - private string _url_extra_1 = "http://example.org"; - private string _url_extra_2 = "http://extra.example.org"; - private string _url_home = "http://home.example.org"; - private string _url_blog = "http://blog.example.org"; - - - public SetUrlsTests () - { - base ("SetUrls"); - - this.add_test ("setting urls on e-d-s persona", - this.test_set_urls); - } - - void test_set_urls () - { - Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> (); - this._main_loop = new GLib.MainLoop (null, false); - Value? v; - - this._found_before_update = false; - this._found_url_extra_1 = false; - this._found_url_extra_2 = false; - this._found_url_home = false; - this._found_url_blog = false; - - this.eds_backend.reset (); - - v = Value (typeof (string)); - v.set_string ("Albus Percival Wulfric Brian Dumbledore"); - c1.set ("full_name", (owned) v); - this.eds_backend.add_contact (c1); - - this._test_set_urls_async.begin (); - - TestUtils.loop_run_with_timeout (this._main_loop, 5); - - assert (this._found_before_update); - assert (this._found_url_extra_1); - assert (this._found_url_extra_2); - assert (this._found_url_home); - assert (this._found_url_blog); - } - - private async void _test_set_urls_async () - { - yield this.eds_backend.commit_contacts_to_addressbook (); - - 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 (Individual i in added) - { - assert (i != null); - - var name = (Folks.NameDetails) i; - - if (name.full_name == "Albus Percival Wulfric Brian Dumbledore") - { - i.notify["urls"].connect (this._notify_urls_cb); - this._found_before_update = true; - - foreach (var p in i.personas) - { - var urls = new HashSet<UrlFieldDetails> (); - - var p1 = new UrlFieldDetails (this._url_extra_1); - urls.add (p1); - var p2 = new UrlFieldDetails (this._url_extra_2); - urls.add (p2); - var p3 = new UrlFieldDetails (this._url_home); - p3.set_parameter(AbstractFieldDetails.PARAM_TYPE, - UrlFieldDetails.PARAM_TYPE_HOME_PAGE); - urls.add (p3); - var p4 = new UrlFieldDetails (this._url_blog); - p4.set_parameter(AbstractFieldDetails.PARAM_TYPE, - UrlFieldDetails.PARAM_TYPE_BLOG); - urls.add (p4); - - ((UrlDetails) p).urls = urls; - } - } - } - - 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; - foreach (var url in i.urls) - { - if (url.value == this._url_extra_1) - { - this._found_url_extra_1 = true; - } - else if (url.value == this._url_extra_2) - { - this._found_url_extra_2 = true; - } - else if (url.value == this._url_home) - { - this._found_url_home = true; - } - else if (url.value == this._url_blog) - { - this._found_url_blog = true; - } - } - - if (this._found_url_extra_1 && - this._found_url_extra_2 && - this._found_url_home && - this._found_url_blog) - { - 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; -} |