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

« back to all changes in this revision

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