Merge lp:~stolowski/libunity/video-props-in-extras into lp:libunity

Proposed by Paweł Stołowski
Status: Merged
Approved by: Michal Hruby
Approved revision: 208
Merged at revision: 201
Proposed branch: lp:~stolowski/libunity/video-props-in-extras
Merge into: lp:libunity
Diff against target: 555 lines (+418/-11)
6 files modified
extras/Makefile.am (+10/-1)
test/vala/Makefile.am (+30/-4)
test/vala/test-extras.vala (+52/-0)
test/vala/test-preview-player-iface.vala (+323/-0)
test/vala/test-utils.vala (+2/-2)
test/vala/test-vala.vala (+1/-4)
To merge this branch: bzr merge lp:~stolowski/libunity/video-props-in-extras
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michal Hruby (community) Approve
Review via email: mp+137534@code.launchpad.net

Commit message

Added tests for unity-extras (preview player interface).

Description of the change

Added tests for unity-extras (preview player interface), as requested in https://code.launchpad.net/~stolowski/libunity/video-props-in-extras/+merge/135904

To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

179 + [DBus (name = "com.canonical.Unity.Lens.Music.PreviewPlayer")]
180 + public class PreviewPlayerServiceMock : Object

Please, make the class implement the *Service interface from extras instead.

283 + service.reset ();

Would be nicer if each test created its own ServiceMock instance, the less global state, the better.

284 + service.test_loop = new MainLoop ();

Why is this part of the service instance? Should be a separate variable, no?

Otherwise looking good.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
205. By Paweł Stołowski

Generate unity-extras-internal{.vapi, .h}.

206. By Paweł Stołowski

Use Extras.PreviewPlayerService interface definition in the test.

207. By Paweł Stołowski

Made test_loop a global variable, not a membler of service mock.

208. By Paweł Stołowski

Create service mock instance in each test.

Revision history for this message
Michal Hruby (mhr3) wrote :

Nice! :)

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'extras/Makefile.am'
2--- extras/Makefile.am 2012-10-17 12:05:12 +0000
3+++ extras/Makefile.am 2012-12-03 12:55:31 +0000
4@@ -22,7 +22,10 @@
5 -H unity-extras.h \
6 --gir=UnityExtras-@GIR_VERSION@.gir \
7 --library unity-extras \
8+ --internal-vapi=unity-extras-internal.vapi \
9+ --internal-header=unity-extras-internal.h \
10 --thread \
11+ --use-header \
12 --vapidir $(top_srcdir)/vapi \
13 --vapidir $(top_builddir)/src \
14 --vapidir $(top_builddir)/protocol \
15@@ -68,7 +71,13 @@
16
17 libunity_extras_la_GENERATED = \
18 unity-extras.vapi \
19- UnityExtras-@GIR_VERSION@.gir
20+ UnityExtras-@GIR_VERSION@.gir \
21+ unity-extras-internal.h \
22+ unity-extras-internal.vapi \
23+ $(NULL)
24+
25+# Used by tests
26+noinst_DATA = unity-extras-internal.h unity-extras-internal.vapi
27
28 $(libunity_la_GENERATED): libunity_la_vala.stamp
29
30
31=== modified file 'test/vala/Makefile.am'
32--- test/vala/Makefile.am 2012-11-27 13:08:48 +0000
33+++ test/vala/Makefile.am 2012-12-03 12:55:31 +0000
34@@ -2,7 +2,7 @@
35
36 DISTCHECK_CONFIGURE_FLAGS = --enable-integration-tests=no
37
38-check_PROGRAMS = test-vala test-lens test-remote-scope test-blacklist-crash
39+check_PROGRAMS = test-vala test-lens test-remote-scope test-blacklist-crash test-extras
40
41 AM_CPPFLAGS = \
42 -I$(top_srcdir) \
43@@ -31,7 +31,17 @@
44 --vapidir=$(top_srcdir)/test/vala \
45 --pkg unity-protocol \
46 --pkg unity-internal \
47- --pkg unity-extras \
48+ --pkg config \
49+ $(LIBUNITY_PACKAGES) \
50+ $(MAINTAINER_VALAFLAGS) \
51+ $(NULL)
52+
53+test_extras_AM_VALAFLAGS = \
54+ --vapidir=$(top_builddir)/src \
55+ --vapidir=$(top_builddir)/extras \
56+ --vapidir=$(top_srcdir)/test/vala \
57+ --pkg unity \
58+ --pkg unity-extras-internal \
59 --pkg config \
60 $(LIBUNITY_PACKAGES) \
61 $(MAINTAINER_VALAFLAGS) \
62@@ -43,7 +53,7 @@
63 $(top_builddir)/extras/libunity-extras.la \
64 $(LIBUNITY_LIBS)
65
66-TEST_PROGS += test-vala test-lens test-blacklist-crash
67+TEST_PROGS += test-vala test-lens test-blacklist-crash test-extras
68
69 test_vala_LDADD = $(test_libs)
70
71@@ -57,7 +67,6 @@
72 test-previews.vala \
73 test-scope-signals.vala \
74 test-vala.vala \
75- test-utils.vala \
76 $(NULL)
77 nodist_test_vala_SOURCES = $(test_vala_VALASOURCES:.vala=.c)
78
79@@ -73,11 +82,22 @@
80 test_blacklist_crash_VALASOURCES = blacklist-crash-1029949-test-case.vala
81 nodist_test_blacklist_crash_SOURCES = $(test_blacklist_crash_VALASOURCES:.vala=.c)
82
83+test_extras_LDADD = $(test_libs)
84+test_extras_VALASOURCES = \
85+ test-preview-player-iface.vala \
86+ test-utils.vala \
87+ common.vala \
88+ test-extras.vala \
89+ $(NULL)
90+
91+nodist_test_extras_SOURCES = $(test_extras_VALASOURCES:.vala=.c)
92+
93 BUILT_SOURCES = \
94 test-vala.vala.stamp \
95 test-lens.vala.stamp \
96 test-remote-scope.vala.stamp \
97 test-blacklist-crash.vala.stamp \
98+ test-extras.vala.stamp \
99 $(NULL)
100
101 test-vala.vala.stamp: $(test_vala_VALASOURCES)
102@@ -96,6 +116,10 @@
103 $(AM_V_GEN)$(VALAC) -C $(AM_VALAFLAGS) $(VALAFLAGS) $^
104 @touch $@
105
106+test-extras.vala.stamp: $(test_extras_VALASOURCES)
107+ $(AM_V_GEN)$(VALAC) -C $(test_extras_AM_VALAFLAGS) $(VALAFLAGS) $^
108+ @touch $@
109+
110 include Makefile.integration_tests
111
112 EXTRA_DIST += \
113@@ -103,6 +127,7 @@
114 $(test_lens_VALASOURCES) \
115 $(test_remote_scope_VALASOURCES) \
116 $(test_blacklist_crash_VALASOURCES) \
117+ $(test_extras_VALASOURCES) \
118 config.vapi \
119 $(NULL)
120
121@@ -112,4 +137,5 @@
122 $(test_lens_VALASOURCES:.vala=.c) \
123 $(test_remote_scope_VALASOURCES:.vala=.c) \
124 $(test_blacklist_crash_VALASOURCES:.vala=.c) \
125+ $(test_extras_VALASOURCES:.vala=.c) \
126 $(NULL)
127
128=== added file 'test/vala/test-extras.vala'
129--- test/vala/test-extras.vala 1970-01-01 00:00:00 +0000
130+++ test/vala/test-extras.vala 2012-12-03 12:55:31 +0000
131@@ -0,0 +1,52 @@
132+/*
133+ * Copyright (C) 2010 Canonical Ltd
134+ *
135+ * This program is free software: you can redistribute it and/or modify
136+ * it under the terms of the GNU General Public License version 3 as
137+ * published by the Free Software Foundation.
138+ *
139+ * This program is distributed in the hope that it will be useful,
140+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
141+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
142+ * GNU General Public License for more details.
143+ *
144+ * You should have received a copy of the GNU General Public License
145+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
146+ *
147+ * Authored by Pawel Stolowski <pawel.stolowski@canonical.com>
148+ *
149+ */
150+
151+using Unity.Test;
152+
153+public class Main
154+{
155+ public static int main (string[] args)
156+ {
157+ UtilsTestSuite utils_suite;
158+ PreviewPlayerIfaceTestSuite preview_player_suite;
159+
160+ string gsettings_schema_dir = Config.BUILDDIR+"/data";
161+
162+ Environment.set_variable ("XDG_DATA_HOME", Config.TESTDIR+"/data", true);
163+ Environment.set_variable ("GSETTINGS_SCHEMA_DIR", gsettings_schema_dir, true);
164+ Environment.set_variable ("GSETTINGS_BACKEND", "memory", true);
165+ try {
166+ Process.spawn_command_line_sync ("glib-compile-schemas " + gsettings_schema_dir);
167+ } catch (SpawnError e) {
168+ stderr.printf ("%s\n", e.message);
169+ return 1;
170+ }
171+ Test.init (ref args);
172+
173+ /* Extra-utils test suite */
174+ utils_suite = new UtilsTestSuite ();
175+
176+ /* Preview player interface test suite */
177+ preview_player_suite = new PreviewPlayerIfaceTestSuite ();
178+
179+ Test.run ();
180+
181+ return 0;
182+ }
183+}
184
185=== added file 'test/vala/test-preview-player-iface.vala'
186--- test/vala/test-preview-player-iface.vala 1970-01-01 00:00:00 +0000
187+++ test/vala/test-preview-player-iface.vala 2012-12-03 12:55:31 +0000
188@@ -0,0 +1,323 @@
189+/*
190+ * Copyright (C) 2012 Canonical Ltd
191+ *
192+ * This program is free software: you can redistribute it and/or modify
193+ * it under the terms of the GNU General Public License version 3 as
194+ * published by the Free Software Foundation.
195+ *
196+ * This program is distributed in the hope that it will be useful,
197+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
198+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
199+ * GNU General Public License for more details.
200+ *
201+ * You should have received a copy of the GNU General Public License
202+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
203+ *
204+ * Authored by Pawel Stolowski <pawel.stolowski@canonical.com>
205+ *
206+ */
207+using Unity;
208+
209+namespace Unity.Test
210+{
211+ public GLib.MainLoop test_loop;
212+
213+ internal class PreviewPlayerServiceMock : Extras.PreviewPlayerService, GLib.Object
214+ {
215+ public string got_play_uri;
216+ public string got_video_properties_uri;
217+ public bool got_close;
218+ public bool got_stop;
219+ public bool got_pause;
220+ public bool got_resume;
221+ public bool got_pause_resume;
222+
223+ public PreviewPlayerServiceMock ()
224+ {
225+ reset ();
226+ }
227+
228+ public void reset ()
229+ {
230+ got_play_uri = "";
231+ got_video_properties_uri = "";
232+ got_close = false;
233+ got_stop = false;
234+ got_pause = false;
235+ got_pause_resume = false;
236+ got_resume = false;
237+ }
238+
239+ public async void play (string uri) throws Error
240+ {
241+ got_play_uri = uri;
242+ Unity.Test.test_loop.quit ();
243+ }
244+
245+ public async void pause () throws Error
246+ {
247+ got_pause = true;
248+ Unity.Test.test_loop.quit ();
249+ }
250+
251+ public async void resume () throws Error
252+ {
253+ got_resume = true;
254+ Unity.Test.test_loop.quit ();
255+ }
256+
257+ public async void pause_resume () throws Error
258+ {
259+ got_pause_resume = true;
260+ test_loop.quit ();
261+ }
262+
263+ public async void stop () throws Error
264+ {
265+ got_stop = true;
266+ test_loop.quit ();
267+ }
268+
269+ public async void close () throws Error
270+ {
271+ got_close = true;
272+ Unity.Test.test_loop.quit ();
273+ }
274+
275+ public async HashTable<string, Variant> video_properties (string uri) throws Error
276+ {
277+ got_video_properties_uri = uri;
278+ var res = new HashTable<string, Variant> (str_hash, str_equal);
279+ res.insert ("got_uri", new GLib.Variant.string (uri));
280+ return res;
281+ }
282+ }
283+
284+ public class PreviewPlayerIfaceTestSuite
285+ {
286+ private static Unity.Extras.PreviewPlayer preview_player;
287+ private static DBusConnection conn;
288+
289+ public PreviewPlayerIfaceTestSuite ()
290+ {
291+ // create fake preview player service that will get all test requests via DBus
292+ conn = GLib.Bus.get_sync (BusType.SESSION, null);
293+ GLib.Bus.own_name (BusType.SESSION, "com.canonical.Unity.Lens.Music.PreviewPlayer", 0);
294+
295+ // create preview player proxy object that interacts with fake player service
296+ preview_player = new Unity.Extras.PreviewPlayer ();
297+
298+ GLib.Test.add_data_func ("/Unit/Utils/PreviewPlayerPlay", PreviewPlayerIfaceTestSuite.test_preview_player_play);
299+ GLib.Test.add_data_func ("/Unit/Utils/PreviewPlayerPause", PreviewPlayerIfaceTestSuite.test_preview_player_pause);
300+ GLib.Test.add_data_func ("/Unit/Utils/PreviewPlayerResume", PreviewPlayerIfaceTestSuite.test_preview_player_resume);
301+ GLib.Test.add_data_func ("/Unit/Utils/PreviewPlayerPauseResume", PreviewPlayerIfaceTestSuite.test_preview_player_pause_resume);
302+ GLib.Test.add_data_func ("/Unit/Utils/PreviewPlayerStop", PreviewPlayerIfaceTestSuite.test_preview_player_stop);
303+ GLib.Test.add_data_func ("/Unit/Utils/PreviewPlayerClose", PreviewPlayerIfaceTestSuite.test_preview_player_close);
304+ GLib.Test.add_data_func ("/Unit/Utils/PreviewPlayerVideoProperties", PreviewPlayerIfaceTestSuite.test_preview_player_video_properties);
305+ GLib.Test.add_data_func ("/Unit/Utils/PreviewPlayerProgressSignal", PreviewPlayerIfaceTestSuite.test_preview_player_progress_signal);
306+ }
307+
308+ internal static PreviewPlayerServiceMock create_service_mock (out uint id)
309+ {
310+ PreviewPlayerServiceMock service = new PreviewPlayerServiceMock ();
311+ id = conn.register_object<Extras.PreviewPlayerService> ("/com/canonical/Unity/Lens/Music/PreviewPlayer", service);
312+ return service;
313+ }
314+
315+ internal static void unregister_service_mock (uint id)
316+ {
317+ conn.unregister_object (id);
318+ }
319+
320+ internal static void test_preview_player_play ()
321+ {
322+ uint id;
323+ var service = create_service_mock (out id);
324+ test_loop = new MainLoop ();
325+
326+ preview_player.play ("bar");
327+
328+ run_with_timeout (test_loop, 5000);
329+
330+ assert (service.got_play_uri == "bar");
331+ assert (service.got_pause == false);
332+ assert (service.got_resume == false);
333+ assert (service.got_pause_resume == false);
334+ assert (service.got_stop == false);
335+ assert (service.got_video_properties_uri == "");
336+ assert (service.got_close == false);
337+
338+ unregister_service_mock (id);
339+ }
340+
341+ internal static void test_preview_player_pause ()
342+ {
343+ uint id;
344+ var service = create_service_mock (out id);
345+ test_loop = new MainLoop ();
346+
347+ preview_player.pause ();
348+
349+ run_with_timeout (test_loop, 5000);
350+
351+ assert (service.got_play_uri == "");
352+ assert (service.got_pause == true);
353+ assert (service.got_resume == false);
354+ assert (service.got_pause_resume == false);
355+ assert (service.got_stop == false);
356+ assert (service.got_video_properties_uri == "");
357+ assert (service.got_close == false);
358+
359+ unregister_service_mock (id);
360+ }
361+
362+ internal static void test_preview_player_resume ()
363+ {
364+ uint id;
365+ var service = create_service_mock (out id);
366+ test_loop = new MainLoop ();
367+
368+ preview_player.resume ();
369+
370+ run_with_timeout (test_loop, 5000);
371+
372+ assert (service.got_play_uri == "");
373+ assert (service.got_pause == false);
374+ assert (service.got_resume == true);
375+ assert (service.got_pause_resume == false);
376+ assert (service.got_stop == false);
377+ assert (service.got_video_properties_uri == "");
378+ assert (service.got_close == false);
379+
380+ unregister_service_mock (id);
381+ }
382+
383+ internal static void test_preview_player_pause_resume ()
384+ {
385+ uint id;
386+ var service = create_service_mock (out id);
387+ test_loop = new MainLoop ();
388+
389+ preview_player.pause_resume ();
390+
391+ run_with_timeout (test_loop, 5000);
392+
393+ assert (service.got_play_uri == "");
394+ assert (service.got_pause == false);
395+ assert (service.got_resume == false);
396+ assert (service.got_pause_resume == true);
397+ assert (service.got_stop == false);
398+ assert (service.got_video_properties_uri == "");
399+ assert (service.got_close == false);
400+
401+ unregister_service_mock (id);
402+ }
403+
404+ internal static void test_preview_player_stop ()
405+ {
406+ uint id;
407+ var service = create_service_mock (out id);
408+ test_loop = new MainLoop ();
409+
410+ preview_player.stop ();
411+
412+ run_with_timeout (test_loop, 5000);
413+
414+ assert (service.got_play_uri == "");
415+ assert (service.got_pause == false);
416+ assert (service.got_resume == false);
417+ assert (service.got_pause_resume == false);
418+ assert (service.got_stop == true);
419+ assert (service.got_video_properties_uri == "");
420+ assert (service.got_close == false);
421+
422+ unregister_service_mock (id);
423+ }
424+
425+ internal static void test_preview_player_close ()
426+ {
427+ uint id;
428+ var service = create_service_mock (out id);
429+ test_loop = new MainLoop ();
430+
431+ preview_player.close ();
432+
433+ run_with_timeout (test_loop, 5000);
434+
435+ assert (service.got_play_uri == "");
436+ assert (service.got_pause == false);
437+ assert (service.got_resume == false);
438+ assert (service.got_pause_resume == false);
439+ assert (service.got_stop == false);
440+ assert (service.got_video_properties_uri == "");
441+ assert (service.got_close == true);
442+
443+ unregister_service_mock (id);
444+ }
445+
446+ internal static void test_preview_player_video_properties ()
447+ {
448+ uint id;
449+ var service = create_service_mock (out id);
450+ test_loop = new MainLoop ();
451+
452+ HashTable<string, Variant> props = null;
453+
454+ preview_player.video_properties.begin ("foo", (obj, res) =>
455+ {
456+ props = preview_player.video_properties.end (res);
457+ });
458+
459+ run_with_timeout (test_loop, 5000);
460+
461+ assert (props != null);
462+ assert (props["got_uri"].get_string () == "foo");
463+ assert (service.got_play_uri == "");
464+ assert (service.got_pause == false);
465+ assert (service.got_resume == false);
466+ assert (service.got_pause_resume == false);
467+ assert (service.got_stop == false);
468+ assert (service.got_video_properties_uri == "foo");
469+ assert (service.got_close == false);
470+
471+ unregister_service_mock (id);
472+ }
473+
474+ internal static void test_preview_player_progress_signal ()
475+ {
476+ uint id;
477+ var service = create_service_mock (out id);
478+ test_loop = new MainLoop ();
479+
480+ string got_progress_uri = "";
481+ Unity.MusicPreview.TrackState got_progress_state = Unity.MusicPreview.TrackState.STOPPED;
482+ double got_progress_value = 0.0f;
483+
484+ preview_player.progress.connect ((uri, state, value) =>
485+ {
486+ got_progress_uri = uri;
487+ got_progress_state = state;
488+ got_progress_value = value;
489+ test_loop.quit ();
490+ });
491+
492+ service.progress ("foouri", 1, 0.5f);
493+
494+ run_with_timeout (test_loop, 1000);
495+
496+ assert (got_progress_uri == "foouri");
497+ assert (got_progress_state == MusicPreview.TrackState.PLAYING);
498+ assert (got_progress_value == 0.5f);
499+
500+ assert (service.got_play_uri == "");
501+ assert (service.got_pause == false);
502+ assert (service.got_resume == false);
503+ assert (service.got_pause_resume == false);
504+ assert (service.got_stop == false);
505+ assert (service.got_video_properties_uri == "");
506+ assert (service.got_close == false);
507+
508+ unregister_service_mock (id);
509+ }
510+ }
511+}
512\ No newline at end of file
513
514=== modified file 'test/vala/test-utils.vala'
515--- test/vala/test-utils.vala 2012-11-27 13:40:58 +0000
516+++ test/vala/test-utils.vala 2012-12-03 12:55:31 +0000
517@@ -24,8 +24,8 @@
518 {
519 public UtilsTestSuite ()
520 {
521- GLib.Test.add_data_func ("/Unit/Utils/Allocation", UtilsTestSuite.test_dbus_name_has_owner);
522- GLib.Test.add_data_func ("/Unit/Utils/Allocation", UtilsTestSuite.test_dbus_own_name);
523+ GLib.Test.add_data_func ("/Unit/Utils/DbusNameHasOwner", UtilsTestSuite.test_dbus_name_has_owner);
524+ GLib.Test.add_data_func ("/Unit/Utils/DbusOwnName", UtilsTestSuite.test_dbus_own_name);
525 }
526
527 internal static void test_dbus_name_has_owner ()
528
529=== modified file 'test/vala/test-vala.vala'
530--- test/vala/test-vala.vala 2012-11-27 13:08:48 +0000
531+++ test/vala/test-vala.vala 2012-12-03 12:55:31 +0000
532@@ -25,12 +25,12 @@
533 {
534 IOSuite io;
535 AppInfoManagerSuite appinfo_manager;
536- UtilsTestSuite utils_suite;
537 LauncherSuite launcher;
538 FilterSuite filter_suite;
539 PreferencesSuite preferences_suite;
540 PreviewSuite preview_suite;
541 ScopeSuite scope_suite;
542+
543 string gsettings_schema_dir = Config.BUILDDIR+"/data";
544
545 Environment.set_variable ("XDG_DATA_HOME", Config.TESTDIR+"/data", true);
546@@ -62,9 +62,6 @@
547 /* Scope test suite */
548 scope_suite = new ScopeSuite ();
549
550- /* Extra-utils test suite */
551- utils_suite = new UtilsTestSuite ();
552-
553 Test.run ();
554
555 return 0;

Subscribers

People subscribed via source and target branches