Initial implementation of the tracker backend
[platform/upstream/folks.git] / tests / tracker / url-details-interface.vala
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 UrlDetailsInterfaceTests : Folks.TestCase
27 {
28   private GLib.MainLoop _main_loop;
29   private IndividualAggregator _aggregator;
30   private TrackerTest.Backend _tracker_backend;
31   private string _blog_url;
32   private string _website_url;
33   private string _urls;
34   private bool _found_blog;
35   private bool _found_website;
36
37   public UrlDetailsInterfaceTests ()
38     {
39       base ("UrlDetailsInterfaceTests");
40
41       this._tracker_backend = new TrackerTest.Backend ();
42       this._tracker_backend.debug = false;
43
44       this.add_test ("test url details interface",
45           this.test_url_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_url_details_interface ()
57     {
58       this._main_loop = new GLib.MainLoop (null, false);
59       Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
60       this._blog_url = "http://blog.example.org";
61       this._website_url = "http://www.example.org";
62       this._urls = "%s,%s".printf (this._blog_url, this._website_url);
63
64       c1.set (Trf.OntologyDefs.NCO_FULLNAME, "persona #1");
65       c1.set (TrackerTest.Backend.URLS, this._urls);
66       this._tracker_backend.add_contact (c1);
67
68       this._tracker_backend.set_up ();
69
70       this._found_blog = false;
71       this._found_website = false;
72
73       this._test_url_details_interface_async ();
74
75       Timeout.add_seconds (5, () =>
76         {
77           this._main_loop.quit ();
78           assert_not_reached ();
79         });
80
81       this._main_loop.run ();
82
83       assert (this._found_blog == true);
84       assert (this._found_website == true);
85
86       this._tracker_backend.tear_down ();
87     }
88
89   private async void _test_url_details_interface_async ()
90     {
91       var store = BackendStore.dup ();
92       yield store.prepare ();
93       this._aggregator = new IndividualAggregator ();
94       this._aggregator.individuals_changed.connect
95           (this._individuals_changed_cb);
96       try
97         {
98           yield this._aggregator.prepare ();
99         }
100       catch (GLib.Error e)
101         {
102           GLib.warning ("Error when calling prepare: %s\n", e.message);
103         }
104     }
105
106   private void _individuals_changed_cb
107       (GLib.List<Individual>? added,
108        GLib.List<Individual>? removed,
109        string? message,
110        Persona? actor,
111        GroupDetails.ChangeReason reason)
112     {
113       foreach (Individual i in added)
114         {
115           string full_name = i.full_name;
116           if (full_name != null)
117             {
118               foreach (var url in i.urls)
119                 {
120                   if (url.value == this._blog_url)
121                     {
122                       this._found_blog = true;
123                     }
124                   else if (url.value == this._website_url)
125                     {
126                       this._found_website = true;
127                     }
128                 }
129             }
130         }
131
132       assert (removed == null);
133
134       if (this._found_blog &&
135           this._found_website)
136         this._main_loop.quit ();
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 UrlDetailsInterfaceTests ().get_suite ());
146
147   Test.run ();
148
149   return 0;
150 }