Merge lp:~mhr3/libunity/few-more-tests into lp:libunity

Proposed by Michal Hruby
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 248
Merged at revision: 248
Proposed branch: lp:~mhr3/libunity/few-more-tests
Merge into: lp:libunity
Diff against target: 295 lines (+206/-39)
4 files modified
test/vala/Makefile.am (+1/-1)
test/vala/common.vala (+38/-0)
test/vala/test-scope-base.vala (+167/-0)
test/vala/test-scope.vala (+0/-38)
To merge this branch: bzr merge lp:~mhr3/libunity/few-more-tests
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+171763@code.launchpad.net

Commit message

Add a few more Scope tests that don't focus on DBus communication.

Description of the change

Add a few more Scope tests that don't focus on DBus communication.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Paweł Stołowski (stolowski) wrote :

LGTM. +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'test/vala/Makefile.am'
2--- test/vala/Makefile.am 2013-02-26 13:40:47 +0000
3+++ test/vala/Makefile.am 2013-06-27 10:41:28 +0000
4@@ -65,7 +65,7 @@
5 test-launcher.vala \
6 test-preferences.vala \
7 test-previews.vala \
8- test-scope-signals.vala \
9+ test-scope-base.vala \
10 test-scope-discovery.vala \
11 test-vala.vala \
12 test-results-synchronizer.vala \
13
14=== modified file 'test/vala/common.vala'
15--- test/vala/common.vala 2013-06-04 16:52:24 +0000
16+++ test/vala/common.vala 2013-06-27 10:41:28 +0000
17@@ -19,6 +19,44 @@
18
19 namespace Unity.Test
20 {
21+ /* A bit of magic to get proper-ish fixture support */
22+ public interface Fixture : Object
23+ {
24+ class DelegateWrapper
25+ {
26+ TestDataFunc func;
27+ public DelegateWrapper (owned TestDataFunc f) { func = (owned) f; }
28+ }
29+
30+ public virtual void setup () {}
31+ public virtual void teardown () {}
32+
33+ [CCode (has_target = false)]
34+ public delegate void Callback<T> (T ptr);
35+
36+ private static List<DelegateWrapper> _tests;
37+
38+ public static unowned TestDataFunc create<F> (Callback<void*> cb)
39+ requires (typeof (F).is_a (typeof (Fixture)))
40+ {
41+ TestDataFunc functor = () =>
42+ {
43+ var type = typeof (F);
44+ var instance = Object.new (type) as Fixture;
45+ instance.setup ();
46+ cb (instance);
47+ instance.teardown ();
48+ };
49+ unowned TestDataFunc copy = functor;
50+ _tests.append (new DelegateWrapper ((owned) functor));
51+ return copy;
52+ }
53+ public static unowned TestDataFunc create_static<F> (Callback<F> cb)
54+ {
55+ return create<F> ((Callback<void*>) cb);
56+ }
57+ }
58+
59 public static bool run_with_timeout (MainLoop ml, uint timeout_ms = 5000)
60 {
61 bool timeout_reached = false;
62
63=== renamed file 'test/vala/test-scope-signals.vala' => 'test/vala/test-scope-base.vala'
64--- test/vala/test-scope-signals.vala 2013-02-01 09:57:48 +0000
65+++ test/vala/test-scope-base.vala 2013-06-27 10:41:28 +0000
66@@ -26,6 +26,10 @@
67 {
68 public ScopeSuite ()
69 {
70+ GLib.Test.add_data_func ("/Unit/AbstractScope/AddResult",
71+ Fixture.create<AbstractScopeTester> (AbstractScopeTester.test_add_result));
72+ GLib.Test.add_data_func ("/Unit/AbstractScope/AddResultFromVariant",
73+ Fixture.create<AbstractScopeTester> (AbstractScopeTester.test_add_variant_result));
74 /* disabled for now
75 GLib.Test.add_data_func ("/Unit/Scope/Signal/NoSearchChanged",
76 test_no_search_changed);
77@@ -42,6 +46,169 @@
78 */
79 }
80
81+ class AbstractScopeTester: Object, Fixture
82+ {
83+ delegate void RunFunc (SearchContext search);
84+
85+ private AbstractScopeTestImpl scope;
86+
87+ class ScopeSearchTestImpl: ScopeSearchBase
88+ {
89+ private unowned RunFunc runner;
90+ public ScopeSearchTestImpl (RunFunc run_func)
91+ {
92+ runner = run_func;
93+ }
94+ protected override void run ()
95+ {
96+ runner (search_context);
97+ }
98+ }
99+
100+ class AbstractScopeTestImpl : AbstractScope
101+ {
102+ public RunFunc run_func;
103+
104+ public AbstractScopeTestImpl ()
105+ {
106+ }
107+
108+ protected override ScopeSearchBase create_search_for_query (SearchContext search_context)
109+ {
110+ var search_runner = new ScopeSearchTestImpl (run_func);
111+ search_runner.set_search_context (search_context);
112+ return search_runner;
113+ }
114+
115+ protected override ResultPreviewer create_previewer (ScopeResult result, SearchMetadata metadata)
116+ {
117+ return null;
118+ }
119+
120+ protected override CategorySet get_categories ()
121+ {
122+ return new CategorySet ();
123+ }
124+
125+ protected override FilterSet get_filters ()
126+ {
127+ return new FilterSet ();
128+ }
129+
130+ protected override Schema get_schema ()
131+ {
132+ return new Schema ();
133+ }
134+
135+ protected override string get_group_name ()
136+ {
137+ return "com.canonical.example.Scope.Test";
138+ }
139+
140+ protected override string get_unique_name ()
141+ {
142+ return "/com/canonical/example/Scope/Test";
143+ }
144+ }
145+
146+ private void setup ()
147+ {
148+ scope = new AbstractScopeTestImpl ();
149+ }
150+
151+ private void teardown ()
152+ {
153+ }
154+
155+ class ResultSetTestImpl: ResultSet
156+ {
157+ public GenericArray<ScopeResult?> results;
158+
159+ construct
160+ {
161+ results = new GenericArray<ScopeResult?> ();
162+ }
163+ protected override void add_result (ScopeResult result)
164+ {
165+ results.add (result);
166+ }
167+ }
168+
169+ public void test_add_result ()
170+ {
171+ bool runner_invoked = false;
172+ scope.run_func = (context) =>
173+ {
174+ runner_invoked = true;
175+ var result = ScopeResult ();
176+ result.uri = "test://";
177+ result.icon_hint = "unknown";
178+ result.category = 0;
179+ result.mimetype = "text/html";
180+ result.title = "Test";
181+ result.comment = "comment";
182+ result.dnd_uri = result.uri;
183+
184+ context.result_set.add_result (result);
185+ };
186+
187+ var result_set = new ResultSetTestImpl ();
188+ var search = scope.create_search_for_query (
189+ SearchContext.create ("foo", SearchType.DEFAULT,
190+ new FilterSet (), null,
191+ result_set, null));
192+ search.run ();
193+
194+ assert (runner_invoked);
195+ assert (result_set.results.length == 1);
196+
197+ var test_result = result_set.results[0];
198+ assert (test_result.uri == "test://");
199+ assert (test_result.title == "Test");
200+ }
201+
202+ public void test_add_variant_result ()
203+ {
204+ bool runner_invoked = false;
205+ scope.run_func = (context) =>
206+ {
207+ runner_invoked = true;
208+ var result = ScopeResult ();
209+ result.uri = "test://";
210+ result.icon_hint = "unknown";
211+ result.category = 0;
212+ result.mimetype = "text/html";
213+ result.title = "Test";
214+ result.comment = "comment";
215+ result.dnd_uri = result.uri;
216+
217+ var metadata = new Variant.array (VariantType.VARDICT.element (), {});
218+ var variant = new Variant ("(ssuussss@a{sv})",
219+ result.uri, result.icon_hint,
220+ result.category, result.result_type,
221+ result.mimetype, result.title,
222+ result.comment, result.dnd_uri,
223+ metadata);
224+
225+ context.result_set.add_result_from_variant (variant);
226+ };
227+
228+ var result_set = new ResultSetTestImpl ();
229+ var search = scope.create_search_for_query (
230+ SearchContext.create ("foo", SearchType.DEFAULT,
231+ new FilterSet (), null,
232+ result_set, null));
233+ search.run ();
234+
235+ assert (runner_invoked);
236+ assert (result_set.results.length == 1);
237+
238+ var test_result = result_set.results[0];
239+ assert (test_result.uri == "test://");
240+ assert (test_result.title == "Test");
241+ }
242+ }
243+
244 /* disabled for now
245 static void test_no_search_changed ()
246 {
247
248=== modified file 'test/vala/test-scope.vala'
249--- test/vala/test-scope.vala 2013-06-19 01:31:25 +0000
250+++ test/vala/test-scope.vala 2013-06-27 10:41:28 +0000
251@@ -20,44 +20,6 @@
252 using Unity.Protocol;
253 using Unity.Test;
254
255-/* A bit of magic to get proper-ish fixture support */
256-public interface Fixture : Object
257-{
258- class DelegateWrapper
259- {
260- TestDataFunc func;
261- public DelegateWrapper (owned TestDataFunc f) { func = (owned) f; }
262- }
263-
264- public virtual void setup () {}
265- public virtual void teardown () {}
266-
267- [CCode (has_target = false)]
268- public delegate void Callback<T> (T ptr);
269-
270- private static List<DelegateWrapper> _tests;
271-
272- public static unowned TestDataFunc create<F> (Callback<void*> cb)
273- requires (typeof (F).is_a (typeof (Fixture)))
274- {
275- TestDataFunc functor = () =>
276- {
277- var type = typeof (F);
278- var instance = Object.new (type) as Fixture;
279- instance.setup ();
280- cb (instance);
281- instance.teardown ();
282- };
283- unowned TestDataFunc copy = functor;
284- _tests.append (new DelegateWrapper ((owned) functor));
285- return copy;
286- }
287- public static unowned TestDataFunc create_static<F> (Callback<F> cb)
288- {
289- return create<F> ((Callback<void*>) cb);
290- }
291-}
292-
293 public class Main
294 {
295 const string DBUS_NAME = "com.canonical.Unity.Scope.Test";

Subscribers

People subscribed via source and target branches