Commit e0e76750 authored by Philip Withnall's avatar Philip Withnall
Browse files

tests: Add a standalone-individuals test program

This contains a few test cases which check folks’ behaviour when
manually creating Individuals *outside* an IndividualAggregator. These
should catch the problems found in the following two bugs:
 • https://bugzilla.redhat.com/show_bug.cgi?id=1031252https://bugzilla.gnome.org/show_bug.cgi?id=712839
and hopefully fixed by commits:
 • f00534291ec050ef

https://bugzilla.gnome.org/show_bug.cgi?id=648811
parent 3a63de91
......@@ -46,6 +46,7 @@ noinst_PROGRAMS = \
utils \
backend-loading \
aggregation \
standalone-individuals \
avatar-cache \
object-cache \
phone-field-details \
......@@ -67,6 +68,10 @@ aggregation_SOURCES = \
aggregation.vala \
$(NULL)
standalone_individuals_SOURCES = \
standalone-individuals.vala \
$(NULL)
abstract_field_details_SOURCES = \
abstract-field-details.vala \
$(NULL)
......
/*
* Copyright (C) 2013 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: Philip Withnall <philip.withnall@collabora.co.uk>
*/
using Gee;
using Folks;
public class StandaloneIndividualsTests : Folks.TestCase
{
public StandaloneIndividualsTests ()
{
base ("StandaloneIndividuals");
/* Set up the tests */
this.add_test ("create empty individual",
this.test_create_empty_individual);
this.add_test ("create singleton individual",
this.test_create_singleton_individual);
this.add_test ("create multi individual",
this.test_create_multi_individual);
this.add_test ("persona transferral", this.test_persona_transferral);
}
/* Test that manually creating an empty individual works. */
public void test_create_empty_individual ()
{
var individual = new Individual (null);
assert (individual.personas.size == 0);
/* Check its properties. */
assert (individual.trust_level == TrustLevel.NONE);
assert (individual.avatar == null);
assert (individual.presence_type == PresenceType.UNSET);
assert (individual.presence_status == "");
assert (individual.presence_message == "");
assert (individual.client_types.length == 0);
assert (individual.is_user == false);
assert (individual.id == "");
assert (individual.display_name == "");
assert (individual.alias == "");
assert (individual.structured_name == null);
assert (individual.full_name == "");
assert (individual.nickname == "");
assert (individual.gender == Gender.UNSPECIFIED);
assert (individual.urls.size == 0);
assert (individual.phone_numbers.size == 0);
assert (individual.email_addresses.size == 0);
assert (individual.roles.size == 0);
assert (individual.local_ids.size == 0);
assert (individual.location ==null);
assert (individual.birthday == null);
assert (individual.calendar_event_id == null);
assert (individual.notes.size == 0);
assert (individual.postal_addresses.size == 0);
assert (individual.is_favourite == false);
assert (individual.groups.size == 0);
assert (individual.im_addresses.size == 0);
assert (individual.web_service_addresses.size == 0);
assert (individual.im_interaction_count == 0);
assert (individual.last_im_interaction_datetime == null);
assert (individual.call_interaction_count == 0);
assert (individual.last_call_interaction_datetime == null);
assert (individual.personas.size == 0);
}
/* Test that manually creating an individual containing a single persona,
* without using an IndividualAggregator, works. */
public void test_create_singleton_individual ()
{
var persona_store = new FolksDummy.PersonaStore ("store0", "Store 0", {});
var persona = new FolksDummy.Persona (persona_store, "persona0");
var personas = new HashSet<Persona> ();
personas.add (persona);
var individual = new Individual (personas);
assert (individual.personas.size == 1);
foreach (var p in individual.personas)
assert (p.individual == individual);
}
/* Test that manually creating an individual containing multiple personas,
* without using an IndividualAggregator, works. */
public void test_create_multi_individual ()
{
var persona_store = new FolksDummy.PersonaStore ("store0", "Store 0", {});
var persona1 = new FolksDummy.Persona (persona_store, "persona0");
var persona2 = new FolksDummy.Persona (persona_store, "persona1");
var personas = new HashSet<Persona> ();
personas.add (persona1);
personas.add (persona2);
var individual = new Individual (personas);
assert (individual.personas.size == 2);
foreach (var p in individual.personas)
assert (p.individual == individual);
}
/* Test that adding a persona to one Individual, then adding it to a second
* individual successfully moves the persona between the two. */
public void test_persona_transferral ()
{
var persona_store = new FolksDummy.PersonaStore ("store0", "Store 0", {});
var persona = new FolksDummy.Persona (persona_store, "persona0");
var personas = new HashSet<Persona> ();
personas.add (persona);
/* Add the persona to the first individual. */
var individual1 = new Individual (personas);
assert (individual1.personas.size == 1);
foreach (var p in individual1.personas)
assert (p.individual == individual1);
/* Now add the persona to a second individual. Have the persona’s
* properties been updated? */
var individual2 = new Individual (personas);
assert (individual2.personas.size == 1);
foreach (var p in individual2.personas)
assert (p.individual == individual2);
/* Has the persona been removed from individual1? */
assert (individual1.personas.size == 0);
}
}
public int main (string[] args)
{
Test.init (ref args);
var tests = new StandaloneIndividualsTests ();
tests.register ();
Test.run ();
tests.final_tear_down ();
return 0;
}
......@@ -27,8 +27,11 @@ test_valaflags = \
--vapidir=$(top_srcdir)/folks \
--vapidir=$(top_builddir)/folks \
--vapidir=$(top_srcdir)/tests/lib \
--vapidir=$(top_srcdir)/backends/dummy/lib \
--vapidir=$(top_builddir)/backends/dummy/lib \
--pkg folks \
--pkg folks-test \
--pkg folks-dummy \
--pkg gee-0.8 \
--pkg gio-2.0 \
--pkg gobject-2.0 \
......@@ -39,6 +42,7 @@ test_cppflags = \
-I$(top_srcdir) \
-I$(top_srcdir)/folks \
-I$(top_srcdir)/tests/lib \
-I$(top_srcdir)/backends/dummy/lib \
-include $(CONFIG_HEADER) \
-include $(top_srcdir)/folks/warnings.h \
$(NULL)
......@@ -53,6 +57,7 @@ test_cflags = \
test_ldadd = \
$(top_builddir)/folks/libfolks.la \
$(top_builddir)/tests/lib/libfolks-test.la \
$(top_builddir)/backends/dummy/lib/libfolks-dummy.la \
$(GIO_LIBS) \
$(GLIB_LIBS) \
$(GEE_LIBS) \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment