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

« back to all changes in this revision

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