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

« back to all changes in this revision

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