Merge lp:~stolowski/libunity/async-preview-with-null into lp:libunity

Proposed by Paweł Stołowski
Status: Merged
Approved by: Michal Hruby
Approved revision: 185
Merged at revision: 183
Proposed branch: lp:~stolowski/libunity/async-preview-with-null
Merge into: lp:libunity
Diff against target: 88 lines (+59/-1)
2 files modified
src/unity-previews.vala (+1/-1)
test/vala/test-lens.vala (+58/-0)
To merge this branch: bzr merge lp:~stolowski/libunity/async-preview-with-null
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Review via email: mp+127519@code.launchpad.net

Commit message

Allow null preview argument in preview_ready signal by declaring it with "?"; this results in an empty GenericPreview. Without the fix null argument is rejected with critical error by vala-generated code at runtime. Added test case for null preview.

Description of the change

Allow null preview argument in preview_ready signal by declaring it with "?"; this results in an empty GenericPreview. Without the fix null argument is rejected with critical error by vala-generated code at runtime. Added test case for null preview.

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

58 + Timeout.add (100, () =>

Can we change this to Idle.add()? The faster the tests run, the better ;)

review: Needs Fixing
185. By Paweł Stołowski

Use Idle.add instead of Timeout.add so that it runs a bit faster.

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

Thanks! +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity-previews.vala'
2--- src/unity-previews.vala 2012-10-01 14:10:26 +0000
3+++ src/unity-previews.vala 2012-10-02 16:18:43 +0000
4@@ -688,7 +688,7 @@
5
6 public Cancellable cancellable { get; construct set; }
7
8- public signal void preview_ready (Preview preview);
9+ public signal void preview_ready (Preview? preview);
10
11 // simple emit method, so it's easy to use in C/Python
12 [CCode (name = "unity_async_preview_preview_ready")]
13
14=== modified file 'test/vala/test-lens.vala'
15--- test/vala/test-lens.vala 2012-09-04 11:40:42 +0000
16+++ test/vala/test-lens.vala 2012-10-02 16:18:43 +0000
17@@ -56,6 +56,7 @@
18 Test.add_data_func ("/Unit/Lens/Activation", test_lens_activation);
19 Test.add_data_func ("/Unit/Lens/Preview", test_lens_preview);
20 Test.add_data_func ("/Unit/Lens/Preview/Async", test_lens_preview_async);
21+ Test.add_data_func ("/Unit/Lens/Preview/AsyncWithNull", test_lens_preview_async_with_null);
22 Test.add_data_func ("/Unit/Lens/Preview/Signal", test_lens_preview_signal);
23 Test.add_data_func ("/Unit/Lens/Preview/ClosedSignal", test_lens_preview_closed_signal);
24 Test.add_data_func ("/Unit/Lens/Preview/ActionWithHints", test_lens_preview_action_with_hint);
25@@ -905,6 +906,63 @@
26 assert (got_action_activated_signal);
27 }
28
29+ public static void test_lens_preview_async_with_null ()
30+ {
31+ SignalWrapper[] signals = null;
32+ assert (local_scope != null);
33+
34+ var ml = new MainLoop ();
35+
36+ var lens_results_model =
37+ exported_lens.get_model_internal (0) as Dee.SharedModel;
38+ var iter = lens_results_model.get_first_iter ();
39+ var mangled_uri = lens_results_model.get_string (iter, 0);
40+
41+ bool got_preview_uri_signal = false;
42+ bool got_activate_uri_signal = false;
43+
44+ signals += new SignalWrapper (local_scope,
45+ local_scope.activate_uri.connect ((uri) =>
46+ {
47+ got_activate_uri_signal = true;
48+ return null;
49+ }));
50+
51+ signals += new SignalWrapper (local_scope,
52+ local_scope.preview_uri.connect ((uri) =>
53+ {
54+ assert (uri == "scheme://local/");
55+ got_preview_uri_signal = true;
56+ var async_preview = new Unity.AsyncPreview ();
57+
58+ Idle.add (() =>
59+ {
60+ async_preview.preview_ready (null);
61+ return false;
62+ });
63+ return async_preview;
64+ }));
65+
66+ ml = new MainLoop ();
67+ Unity.Protocol.Preview? reconstructed = null;
68+ call_lens_activate (mangled_uri, 1, (reply) =>
69+ {
70+ var v = reply.get_child_value (0);
71+ Unity.Protocol.ActivationReplyRaw reply_struct =
72+ (Unity.Protocol.ActivationReplyRaw) v;
73+ reconstructed = Unity.Protocol.Preview.parse (reply_struct.hints["preview"]);
74+ ml.quit ();
75+ });
76+ run_with_timeout (ml, 5000);
77+
78+ assert (reconstructed != null);
79+ assert (reconstructed is Unity.Protocol.GenericPreview);
80+ assert (reconstructed.title == "");
81+ assert (reconstructed.description == "");
82+ assert (got_preview_uri_signal);
83+ assert (!got_activate_uri_signal);
84+ }
85+
86 public static void test_lens_preview_signal ()
87 {
88 SignalWrapper[] signals = null;

Subscribers

People subscribed via source and target branches