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

« back to all changes in this revision

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