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

« back to all changes in this revision

Viewing changes to tests/tracker/set-avatar.vala

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-10-13 21:02:50 UTC
  • mfrom: (4.2.5 experimental)
  • mto: (4.2.6 experimental)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20111013210250-pgwuxw7z1cunhhhx
Tags: 0.6.3.2-2
* debian/rules: Call dh_strip for folks-tools package
* debian/gbp.conf: Switch to unstable branch
* debian/control:
  - Add libncurses5-dev build-dependency
  - Fix duplicate description
* debian/watch: Switch to .xz tarball

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 SetAvatarTests : 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 LoadableIcon _avatar;
 
33
  private bool _avatar_found;
 
34
 
 
35
  public SetAvatarTests ()
 
36
    {
 
37
      base ("SetAvatarTests");
 
38
 
 
39
      this._tracker_backend = new TrackerTest.Backend ();
 
40
 
 
41
      this.add_test ("test setting avatar ", this.test_set_avatar);
 
42
    }
 
43
 
 
44
  public override void set_up ()
 
45
    {
 
46
    }
 
47
 
 
48
  public override void tear_down ()
 
49
    {
 
50
    }
 
51
 
 
52
  public void test_set_avatar ()
 
53
    {
 
54
      this._main_loop = new GLib.MainLoop (null, false);
 
55
      Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
 
56
      this._persona_fullname = "persona #1";
 
57
      var _avatar_path = Environment.get_variable ("AVATAR_FILE_PATH");
 
58
      this._avatar = new FileIcon (File.new_for_path (_avatar_path));
 
59
 
 
60
      c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname);
 
61
      this._tracker_backend.add_contact (c1);
 
62
 
 
63
      this._tracker_backend.set_up ();
 
64
 
 
65
      this._avatar_found = false;
 
66
 
 
67
      this._test_set_avatar_async ();
 
68
 
 
69
      Timeout.add_seconds (5, () =>
 
70
        {
 
71
          this._main_loop.quit ();
 
72
          assert_not_reached ();
 
73
        });
 
74
 
 
75
      this._main_loop.run ();
 
76
 
 
77
      assert (this._avatar_found);
 
78
 
 
79
     this._tracker_backend.tear_down ();
 
80
    }
 
81
 
 
82
  private async void _test_set_avatar_async ()
 
83
    {
 
84
      var store = BackendStore.dup ();
 
85
      yield store.prepare ();
 
86
      this._aggregator = new IndividualAggregator ();
 
87
      this._aggregator.individuals_changed_detailed.connect
 
88
          (this._individuals_changed_cb);
 
89
      try
 
90
        {
 
91
          yield this._aggregator.prepare ();
 
92
        }
 
93
      catch (GLib.Error e)
 
94
        {
 
95
          GLib.warning ("Error when calling prepare: %s\n", e.message);
 
96
        }
 
97
    }
 
98
 
 
99
  private void _individuals_changed_cb (
 
100
       MultiMap<Individual?, Individual?> changes)
 
101
    {
 
102
      var added = changes.get_values ();
 
103
      var removed = changes.get_keys ();
 
104
 
 
105
      foreach (var i in added)
 
106
        {
 
107
          assert (i != null);
 
108
 
 
109
          if (i.full_name == this._persona_fullname)
 
110
            {
 
111
              i.notify["avatar"].connect (this._notify_avatar_cb);
 
112
 
 
113
              foreach (var p in i.personas)
 
114
                {
 
115
                  ((AvatarDetails) p).avatar = this._avatar;
 
116
                }
 
117
            }
 
118
        }
 
119
 
 
120
      assert (removed.size == 1);
 
121
 
 
122
      foreach (var i in removed)
 
123
        {
 
124
          assert (i == null);
 
125
        }
 
126
    }
 
127
 
 
128
  private void _notify_avatar_cb (Object individual_obj, ParamSpec ps)
 
129
    {
 
130
      Folks.Individual i = (Folks.Individual) individual_obj;
 
131
      if (i.full_name == this._persona_fullname)
 
132
        {
 
133
          /* arbitrary icon size, but it might as well be on the small side */
 
134
          TestUtils.loadable_icons_content_equal.begin (i.avatar,
 
135
              this._avatar, 100,
 
136
              (obj, result) =>
 
137
            {
 
138
              if (TestUtils.loadable_icons_content_equal.end (result))
 
139
                {
 
140
                  this._avatar_found = true;
 
141
                  this._main_loop.quit ();
 
142
                }
 
143
            });
 
144
        }
 
145
   }
 
146
}
 
147
 
 
148
public int main (string[] args)
 
149
{
 
150
  Test.init (ref args);
 
151
 
 
152
  TestSuite root = TestSuite.get_root ();
 
153
  root.add_suite (new SetAvatarTests ().get_suite ());
 
154
 
 
155
  Test.run ();
 
156
 
 
157
  return 0;
 
158
}