From: Travis Reitter Date: Tue, 5 Oct 2010 16:10:41 +0000 (-0700) Subject: Add a test for Tpf.Persona alias changing (through the Tp backend itself) X-Git-Tag: FOLKS_0_3_1~29 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=07e5575567b3bbe54f6bc7142e3daa2d672a5731;p=platform%2Fupstream%2Ffolks.git Add a test for Tpf.Persona alias changing (through the Tp backend itself) --- diff --git a/tests/telepathy/Makefile.am b/tests/telepathy/Makefile.am index 57b37a6..60f2750 100644 --- a/tests/telepathy/Makefile.am +++ b/tests/telepathy/Makefile.am @@ -34,38 +34,56 @@ VALAFLAGS += \ --pkg tp-test-contactlist \ $(NULL) +# in order from least to most complex TESTS = \ test-contact-retrieval \ + test-contact-properties \ $(NULL) noinst_PROGRAMS = \ contact-retrieval \ + contact-properties \ $(NULL) +# FIXME: make this the general LDADD if possible +common_ldadd = \ + $(top_builddir)/tests/lib/telepathy/contactlist/libtp-test-contactlist.la \ + $(top_builddir)/backends/telepathy/lib/libfolks-telepathy.la \ + $(top_builddir)/folks/libfolks.la + +# FIXME: turn test-case into a library that the tests use or push it into the +# existing library contact_retrieval_SOURCES = \ test-case.vala \ contact-retrieval.vala \ $(NULL) -contact_retrieval_LDADD = \ - $(top_builddir)/tests/lib/telepathy/contactlist/libtp-test-contactlist.la \ - $(top_builddir)/backends/telepathy/lib/libfolks-telepathy.la \ - $(top_builddir)/folks/libfolks.la +contact_retrieval_LDADD = $(common_ldadd) + +contact_properties_SOURCES = \ + test-case.vala \ + contact-properties.vala \ + $(NULL) + +contact_properties_LDADD = $(common_ldadd) CLEANFILES = \ $(TESTS) \ $(NULL) -test-contact-retrieval: contact-retrieval +test-%: % { echo "#!/bin/sh" && \ echo -n "$(RUN_WITH_PRIVATE_BUS) " && \ echo "--config-file=$(top_builddir)/tests/lib/telepathy/contactlist/session.conf -- ./$<"; } \ > $@ chmod +x $@ +#FIXME: simplify if possible GITIGNOREFILES = \ $(contact_retrieval_SOURCES:.vala=.c) \ contact_retrieval_vala.stamp \ + $(contact_properties_SOURCES:.vala=.c) \ + contact_properties_vala.stamp \ $(NULL) -include $(top_srcdir)/git.mk diff --git a/tests/telepathy/contact-properties.vala b/tests/telepathy/contact-properties.vala new file mode 100644 index 0000000..0eee786 --- /dev/null +++ b/tests/telepathy/contact-properties.vala @@ -0,0 +1,269 @@ +using DBus; +using TelepathyGLib; +using TpTest; +using Tpf; +using Folks; +using Gee; + +public class ContactPropertiesTests : Folks.TestCase +{ + private DBusDaemon daemon; + private TpTest.Account account; + private TpTest.AccountManager account_manager; + private TpTest.ContactListConnection conn; + private MainLoop main_loop; + private string bus_name; + private string object_path; + private string individual_id_prefix = "telepathy:protocol:"; + + public ContactPropertiesTests () + { + base ("ContactProperties"); + + this.add_test ("individual properties", + this.test_individual_properties); + this.add_test ("individual properties:change alias through tp backend", + this.test_individual_properties_change_alias_through_tp_backend); + } + + public override void set_up () + { + this.main_loop = new GLib.MainLoop (null, false); + + try + { + this.daemon = DBusDaemon.dup (); + } + catch (GLib.Error e) + { + error ("Couldn't get D-Bus daemon: %s", e.message); + } + + /* Set up a contact list connection */ + this.conn = new TpTest.ContactListConnection ("me@example.com", + "protocol"); + + try + { + this.conn.register ("cm", out this.bus_name, out this.object_path); + } + catch (GLib.Error e) + { + error ("Failed to register connection %p.", this.conn); + } + + var handle_repo = this.conn.get_handles (HandleType.CONTACT); + Handle self_handle = 0; + try + { + self_handle = TelepathyGLib.handle_ensure (handle_repo, + "me@example.com", null); + } + catch (GLib.Error e) + { + error ("Couldn't ensure self handle '%s': %s", "me@example.com", + e.message); + } + + this.conn.set_self_handle (self_handle); + this.conn.change_status (ConnectionStatus.CONNECTED, + ConnectionStatusReason.REQUESTED); + + /* Create an account */ + this.account = new TpTest.Account (this.object_path); + this.daemon.register_object ( + TelepathyGLib.ACCOUNT_OBJECT_PATH_BASE + "cm/protocol/account", + this.account); + + /* Create an account manager */ + try + { + this.daemon.request_name (TelepathyGLib.ACCOUNT_MANAGER_BUS_NAME, + false); + } + catch (GLib.Error e) + { + error ("Couldn't request account manager bus name '%s': %s", + TelepathyGLib.ACCOUNT_MANAGER_BUS_NAME, e.message); + } + + this.account_manager = new TpTest.AccountManager (); + this.daemon.register_object (TelepathyGLib.ACCOUNT_MANAGER_OBJECT_PATH, + this.account_manager); + } + + public override void tear_down () + { + this.conn.change_status (ConnectionStatus.DISCONNECTED, + ConnectionStatusReason.REQUESTED); + + this.daemon.unregister_object (this.account_manager); + this.account_manager = null; + + try + { + this.daemon.release_name (TelepathyGLib.ACCOUNT_MANAGER_BUS_NAME); + } + catch (GLib.Error e) + { + error ("Couldn't release account manager bus name '%s': %s", + TelepathyGLib.ACCOUNT_MANAGER_BUS_NAME, e.message); + } + + this.daemon.unregister_object (this.account); + this.account = null; + + this.conn = null; + this.daemon = null; + this.bus_name = null; + this.object_path = null; + + Timeout.add_seconds (5, () => + { + this.main_loop.quit (); + this.main_loop = null; + return false; + }); + + /* Run the main loop to process the carnage and destruction */ + this.main_loop.run (); + } + + public void test_individual_properties () + { + var main_loop = new GLib.MainLoop (null, false); + + /* Ignore the error caused by not running the logger */ + Test.log_set_fatal_handler ((d, l, m) => + { + return !m.has_suffix ("couldn't get list of favourite contacts: " + + "The name org.freedesktop.Telepathy.Logger was not provided by " + + "any .service files"); + }); + + /* Set up the aggregator */ + var aggregator = new IndividualAggregator (); + aggregator.individuals_changed.connect ((added, removed, m, a, r) => + { + foreach (Individual i in added) + { + /* We only check one */ + if (i.id != (this.individual_id_prefix + "olivier@example.com")) + { + continue; + } + + /* Check properties */ + assert (i.alias == "Olivier"); + assert (i.presence_message == ""); + assert (i.presence_type == PresenceType.AWAY); + assert (i.is_online () == true); + + /* Check groups */ + assert (i.groups.size () == 2); + assert (i.groups.lookup ("Montreal") == true); + assert (i.groups.lookup ("Francophones") == true); + } + + assert (removed == null); + }); + aggregator.prepare (); + + /* Kill the main loop after a few seconds. If there are still individuals + * in the set of expected individuals, the aggregator has either failed + * or been too slow (which we can consider to be failure). */ + Timeout.add_seconds (3, () => + { + main_loop.quit (); + return false; + }); + + main_loop.run (); + + /* necessary to reset the aggregator for the next test */ + aggregator = null; + } + + public void test_individual_properties_change_alias_through_tp_backend () + { + var main_loop = new GLib.MainLoop (null, false); + var alias_notified = false; + + /* Ignore the error caused by not running the logger */ + Test.log_set_fatal_handler ((d, l, m) => + { + return !m.has_suffix ("couldn't get list of favourite contacts: " + + "The name org.freedesktop.Telepathy.Logger was not provided by " + + "any .service files"); + }); + + /* Set up the aggregator */ + var aggregator = new IndividualAggregator (); + aggregator.individuals_changed.connect ((added, removed, m, a, r) => + { + var new_alias = "New Alias"; + + foreach (Individual i in added) + { + /* We only check one */ + if (i.id != (this.individual_id_prefix + "olivier@example.com")) + { + continue; + } + + /* Check properties */ + assert (i.alias != new_alias); + + i.notify["alias"].connect ((s, p) => + { + /* we can't re-use i here due to Vala's implementation */ + var ind = (Individual) s; + + if (ind.alias == new_alias) + alias_notified = true; + }); + + /* the contact list this aggregator is based upon has exactly 1 + * Tpf.Persona per Individual */ + var persona = i.personas.data; + assert (persona is Tpf.Persona); + + /* set the alias through Telepathy and wait for it to hit our + * alias notification callback above */ + + ((Tpf.Persona) persona).alias = new_alias; + } + + assert (removed == null); + }); + aggregator.prepare (); + + /* Kill the main loop after a few seconds. If the alias hasn't been + * notified, something along the way failed or been too slow (which we can + * consider to be failure). */ + Timeout.add_seconds (3, () => + { + main_loop.quit (); + return false; + }); + + main_loop.run (); + + assert (alias_notified); + + /* necessary to reset the aggregator for the next test */ + aggregator = null; + } +} + +public int main (string[] args) +{ + Test.init (ref args); + + TestSuite root = TestSuite.get_root (); + root.add_suite (new ContactPropertiesTests ().get_suite ()); + + Test.run (); + + return 0; +} diff --git a/tests/telepathy/contact-retrieval.vala b/tests/telepathy/contact-retrieval.vala index c6b668e..43b55f3 100644 --- a/tests/telepathy/contact-retrieval.vala +++ b/tests/telepathy/contact-retrieval.vala @@ -36,8 +36,6 @@ public class ContactRetrievalTests : Folks.TestCase this.add_test ("aggregator", this.test_aggregator); this.add_test ("aggregator:add", this.test_aggregator_add); - this.add_test ("individual properties", - this.test_individual_properties); } public override void set_up () @@ -386,61 +384,6 @@ public class ContactRetrievalTests : Folks.TestCase assert_not_reached (); } } - - public void test_individual_properties () - { - var main_loop = new GLib.MainLoop (null, false); - - /* Ignore the error caused by not running the logger */ - Test.log_set_fatal_handler ((d, l, m) => - { - return !m.has_suffix ("couldn't get list of favourite contacts: " + - "The name org.freedesktop.Telepathy.Logger was not provided by " + - "any .service files"); - }); - - /* Set up the aggregator */ - var aggregator = new IndividualAggregator (); - aggregator.individuals_changed.connect ((added, removed, m, a, r) => - { - foreach (Individual i in added) - { - /* We only check one */ - if (i.id != (this.individual_id_prefix + "olivier@example.com")) - { - continue; - } - - /* Check properties */ - assert (i.alias == "Olivier"); - assert (i.presence_message == ""); - assert (i.presence_type == PresenceType.AWAY); - assert (i.is_online () == true); - - /* Check groups */ - assert (i.groups.size () == 2); - assert (i.groups.lookup ("Montreal") == true); - assert (i.groups.lookup ("Francophones") == true); - } - - assert (removed == null); - }); - aggregator.prepare (); - - /* Kill the main loop after a few seconds. If there are still individuals - * in the set of expected individuals, the aggregator has either failed - * or been too slow (which we can consider to be failure). */ - Timeout.add_seconds (3, () => - { - main_loop.quit (); - return false; - }); - - main_loop.run (); - - /* necessary to reset the aggregator for the next test */ - aggregator = null; - } } public int main (string[] args)