~ubuntu-branches/ubuntu/precise/folks/precise

« back to all changes in this revision

Viewing changes to tests/tracker/fullname-updates.vala

  • Committer: Bazaar Package Importer
  • Author(s): Ken VanDine
  • Date: 2011-06-10 11:28:11 UTC
  • mfrom: (1.2.11 upstream) (4.2.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20110610112811-whyeodbo9mjezxfp
Tags: 0.5.2-1ubuntu1
* Merge with Debian experimental, remaining Ubuntu changes:
  - debian/control:
    + Add Vcs-Bzr link

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011 Collabora Ltd.
 
3
 *
 
4
 * This library is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License as published by
 
6
 * the Free Software Foundation, either version 2.1 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public License
 
15
 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
16
 *
 
17
 * Authors: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk>
 
18
 *
 
19
 */
 
20
 
 
21
using Tracker.Sparql;
 
22
using TrackerTest;
 
23
using Folks;
 
24
using Gee;
 
25
 
 
26
public class FullnameUpdatesTests : Folks.TestCase
 
27
{
 
28
  private GLib.MainLoop _main_loop;
 
29
  private TrackerTest.Backend _tracker_backend;
 
30
  private IndividualAggregator _aggregator;
 
31
  private bool _updated_name_found;
 
32
  private bool _deleted_name_found;
 
33
  private string _updated_fullname;
 
34
  private string _individual_id;
 
35
  private string _initial_fullname;
 
36
  private string _contact_urn;
 
37
  private bool _initial_name_found;
 
38
 
 
39
  public FullnameUpdatesTests ()
 
40
    {
 
41
      base ("FullnameUpdates");
 
42
 
 
43
      this._tracker_backend = new TrackerTest.Backend ();
 
44
      this._tracker_backend.debug = false;
 
45
 
 
46
      this.add_test ("fullname updates", this.test_fullname_updates);
 
47
    }
 
48
 
 
49
  public override void set_up ()
 
50
    {
 
51
    }
 
52
 
 
53
  public override void tear_down ()
 
54
    {
 
55
    }
 
56
 
 
57
  public void test_fullname_updates ()
 
58
    {
 
59
      this._main_loop = new GLib.MainLoop (null, false);
 
60
      this._initial_fullname = "persona #1";
 
61
      this._updated_fullname = "updated persona #1";
 
62
      this._contact_urn = "<urn:contact001>";
 
63
      Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
 
64
 
 
65
      c1.set (TrackerTest.Backend.URN, this._contact_urn);
 
66
      c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname);
 
67
      this._tracker_backend.add_contact (c1);
 
68
 
 
69
      this._tracker_backend.set_up ();
 
70
 
 
71
      this._initial_name_found = false;
 
72
      this._updated_name_found = false;
 
73
      this._deleted_name_found = false;
 
74
      this._individual_id = "";
 
75
 
 
76
      this._test_fullname_updates_async ();
 
77
 
 
78
      Timeout.add_seconds (5, () =>
 
79
        {
 
80
          this._main_loop.quit ();
 
81
          assert_not_reached ();
 
82
        });
 
83
 
 
84
      this._main_loop.run ();
 
85
 
 
86
      assert (this._initial_name_found == true);
 
87
      assert (this._updated_name_found == true);
 
88
 
 
89
      this._tracker_backend.tear_down ();
 
90
    }
 
91
 
 
92
  private async void _test_fullname_updates_async ()
 
93
    {
 
94
      var store = BackendStore.dup ();
 
95
      yield store.prepare ();
 
96
      this._aggregator = new IndividualAggregator ();
 
97
      this._aggregator.individuals_changed.connect
 
98
          (this._individuals_changed_cb);
 
99
      try
 
100
        {
 
101
          yield this._aggregator.prepare ();
 
102
        }
 
103
      catch (GLib.Error e)
 
104
        {
 
105
          GLib.warning ("Error when calling prepare: %s\n", e.message);
 
106
        }
 
107
    }
 
108
 
 
109
  private void _individuals_changed_cb
 
110
      (Set<Individual> added,
 
111
       Set<Individual> removed,
 
112
       string? message,
 
113
       Persona? actor,
 
114
       GroupDetails.ChangeReason reason)
 
115
    {
 
116
      foreach (var i in added)
 
117
        {
 
118
          if (i.full_name == this._initial_fullname)
 
119
            {
 
120
              i.notify["full-name"].connect (this._notify_full_name_cb);
 
121
              this._individual_id = i.id;
 
122
              this._initial_name_found = true;
 
123
              this._tracker_backend.update_contact (this._contact_urn,
 
124
                  Trf.OntologyDefs.NCO_FULLNAME, this._updated_fullname);
 
125
            }
 
126
        }
 
127
 
 
128
        assert (removed.size == 0);
 
129
    }
 
130
 
 
131
  private void _notify_full_name_cb (Object individual_obj, ParamSpec ps)
 
132
    {
 
133
      Folks.Individual i = (Folks.Individual) individual_obj;
 
134
 
 
135
      if (i.full_name == this._updated_fullname)
 
136
        {
 
137
          this._updated_name_found = true;
 
138
          this._main_loop.quit ();
 
139
        }
 
140
    }
 
141
}
 
142
 
 
143
public int main (string[] args)
 
144
{
 
145
  Test.init (ref args);
 
146
 
 
147
  TestSuite root = TestSuite.get_root ();
 
148
  root.add_suite (new FullnameUpdatesTests ().get_suite ());
 
149
 
 
150
  Test.run ();
 
151
 
 
152
  return 0;
 
153
}