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

« back to all changes in this revision

Viewing changes to tests/tracker/suffix-name-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 SuffixNameUpdatesTests : Folks.TestCase
 
27
{
 
28
  private GLib.MainLoop _main_loop;
 
29
  private TrackerTest.Backend _tracker_backend;
 
30
  private IndividualAggregator _aggregator;
 
31
  private bool _updated_suffix_name_found;
 
32
  private bool _deleted_suffix_name_found;
 
33
  private bool _initial_suffix_name_found;
 
34
  private string _updated_suffix_name;
 
35
  private string _individual_id;
 
36
  private string _initial_fullname;
 
37
  private string _initial_suffix_name;
 
38
  private string _contact_urn;
 
39
 
 
40
  public SuffixNameUpdatesTests ()
 
41
    {
 
42
      base ("SuffixNameUpdates");
 
43
 
 
44
      this._tracker_backend = new TrackerTest.Backend ();
 
45
      this._tracker_backend.debug = false;
 
46
 
 
47
      this.add_test ("suffix name updates", this.test_suffix_name_updates);
 
48
    }
 
49
 
 
50
  public override void set_up ()
 
51
    {
 
52
    }
 
53
 
 
54
  public override void tear_down ()
 
55
    {
 
56
    }
 
57
 
 
58
  public void test_suffix_name_updates ()
 
59
    {
 
60
      this._main_loop = new GLib.MainLoop (null, false);
 
61
      Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
 
62
      this._initial_fullname = "persona #1";
 
63
      this._initial_suffix_name = "suffix name #1";
 
64
      this._updated_suffix_name = "updated suffix #1";
 
65
      this._contact_urn = "<urn:contact001>";
 
66
 
 
67
      c1.set (TrackerTest.Backend.URN, this._contact_urn);
 
68
      c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname);
 
69
      c1.set (Trf.OntologyDefs.NCO_SUFFIX, this._initial_suffix_name);
 
70
      this._tracker_backend.add_contact (c1);
 
71
 
 
72
      this._tracker_backend.set_up ();
 
73
 
 
74
      this._initial_suffix_name_found = false;
 
75
      this._updated_suffix_name_found = false;
 
76
      this._deleted_suffix_name_found = false;
 
77
      this._individual_id = "";
 
78
 
 
79
      this._test_suffix_name_updates_async ();
 
80
 
 
81
      Timeout.add_seconds (5, () =>
 
82
        {
 
83
          this._main_loop.quit ();
 
84
          assert_not_reached ();
 
85
        });
 
86
 
 
87
      this._main_loop.run ();
 
88
 
 
89
      assert (this._initial_suffix_name_found == true);
 
90
      assert (this._updated_suffix_name_found == true);
 
91
 
 
92
      this._tracker_backend.tear_down ();
 
93
    }
 
94
 
 
95
  private async void _test_suffix_name_updates_async ()
 
96
    {
 
97
      var store = BackendStore.dup ();
 
98
      yield store.prepare ();
 
99
      this._aggregator = new IndividualAggregator ();
 
100
      this._aggregator.individuals_changed.connect
 
101
          (this._individuals_changed_cb);
 
102
      try
 
103
        {
 
104
          yield this._aggregator.prepare ();
 
105
        }
 
106
      catch (GLib.Error e)
 
107
        {
 
108
          GLib.warning ("Error when calling prepare: %s\n", e.message);
 
109
        }
 
110
    }
 
111
 
 
112
  private void _individuals_changed_cb
 
113
      (Set<Individual> added,
 
114
       Set<Individual> removed,
 
115
       string? message,
 
116
       Persona? actor,
 
117
       GroupDetails.ChangeReason reason)
 
118
    {
 
119
      foreach (var i in added)
 
120
        {
 
121
          if (this._initial_fullname == i.full_name)
 
122
            {
 
123
              var suffix_name = i.structured_name.suffixes;
 
124
              if (suffix_name == this._initial_suffix_name)
 
125
                {
 
126
                  i.structured_name.notify["suffixes"].connect
 
127
                      (this._notify_suffix_name_cb);
 
128
                  this._individual_id = i.id;
 
129
                  this._initial_suffix_name_found = true;
 
130
                  this._tracker_backend.update_contact (this._contact_urn,
 
131
                      Trf.OntologyDefs.NCO_SUFFIX, this._updated_suffix_name);
 
132
                }
 
133
            }
 
134
        }
 
135
 
 
136
      assert (removed.size == 0);
 
137
    }
 
138
 
 
139
  private void _notify_suffix_name_cb (Object individual_obj, ParamSpec ps)
 
140
    {
 
141
      Folks.StructuredName sname = (Folks.StructuredName) individual_obj;
 
142
      var suffix_name = sname.suffixes;
 
143
      if (suffix_name == this._updated_suffix_name)
 
144
        {
 
145
          this._updated_suffix_name_found = true;
 
146
          this._main_loop.quit ();
 
147
        }
 
148
    }
 
149
}
 
150
 
 
151
public int main (string[] args)
 
152
{
 
153
  Test.init (ref args);
 
154
 
 
155
  TestSuite root = TestSuite.get_root ();
 
156
  root.add_suite (new SuffixNameUpdatesTests ().get_suite ());
 
157
 
 
158
  Test.run ();
 
159
 
 
160
  return 0;
 
161
}