Merge lp:~stolowski/unity-scope-home/fix-1220630 into lp:unity-scope-home

Proposed by Paweł Stołowski
Status: Merged
Approved by: Michal Hruby
Approved revision: 166
Merged at revision: 164
Proposed branch: lp:~stolowski/unity-scope-home/fix-1220630
Merge into: lp:unity-scope-home
Diff against target: 65 lines (+35/-3)
2 files modified
src/smart-scopes-default-parser.vala (+7/-3)
tests/unit/test-home-scope.vala (+28/-0)
To merge this branch: bzr merge lp:~stolowski/unity-scope-home/fix-1220630
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michal Hruby (community) Approve
Review via email: mp+186524@code.launchpad.net

Commit message

Check if "images" member exists in metadata column to avoid assertion warnings.

Description of the change

Check if "images" member exists in metadata column to avoid assertion warnings; the results from searchin-scopes.scope have empty metadata.

To post a comment you must log in.
165. By Paweł Stołowski

Added a comment.

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

Added test cases.

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

Great. +1

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 'src/smart-scopes-default-parser.vala'
2--- src/smart-scopes-default-parser.vala 2013-09-11 15:36:37 +0000
3+++ src/smart-scopes-default-parser.vala 2013-09-19 13:40:46 +0000
4@@ -46,9 +46,13 @@
5 Variant? metadata_var = null;
6 try
7 {
8- var image_obj = metadata.get_object_member ("images");
9- if (image_obj == null)
10- metadata_node.get_object ().remove_member ("images");
11+ if (metadata.has_member("images"))
12+ {
13+ var image_obj = metadata.get_object_member ("images");
14+ // protect against "images":null
15+ if (image_obj == null)
16+ metadata_node.get_object ().remove_member ("images");
17+ }
18 // the binding is wrong, deserialize returns floating variant
19 metadata_var = json_gvariant_deserialize (metadata_node, "a{sv}");
20 }
21
22=== modified file 'tests/unit/test-home-scope.vala'
23--- tests/unit/test-home-scope.vala 2013-09-04 10:28:06 +0000
24+++ tests/unit/test-home-scope.vala 2013-09-19 13:40:46 +0000
25@@ -96,6 +96,7 @@
26
27 Test.add_data_func ("/Unit/SmartScopes/Parse", Fixture.create<SmartScopesUtilTester> (SmartScopesUtilTester.test_smart_scopes_parse));
28 Test.add_data_func ("/Unit/SmartScopes/ParseErrors", Fixture.create<SmartScopesUtilTester> (SmartScopesUtilTester.test_smart_scopes_parse_errors));
29+ Test.add_data_func ("/Unit/SmartScopes/ParseMissingOptionalFields", Fixture.create<SmartScopesUtilTester> (SmartScopesUtilTester.test_smart_scopes_parse_missing_optional_fields));
30 Test.add_data_func ("/Unit/SmartScopes/SearchString", Fixture.create<SmartScopesUtilTester> (SmartScopesUtilTester.test_smart_scopes_search_string));
31 Test.add_data_func ("/Unit/SmartScopes/OnChunkData", Fixture.create<SmartScopesUtilTester> (SmartScopesUtilTester.test_smart_scopes_on_chunk_data));
32 Test.add_data_func ("/Unit/SmartScopes/Metrics", Fixture.create<SmartScopesUtilTester> (SmartScopesUtilTester.test_smart_scopes_metrics));
33@@ -702,6 +703,33 @@
34 catch (SmartScopes.ParseError e) { got_excp = true; }
35 }
36
37+ internal void test_smart_scopes_parse_missing_optional_fields ()
38+ {
39+ int row_count = 0;
40+ var search_handler = new SmartScopes.SearchResponseHandler ();
41+
42+ // missing or null 'images' in the metadata
43+ search_handler.parse_results_line ("""{"info": {"searchin-scope.scope": [{"title": "search in foursquare...", "icon_hint": "file:///usr/share/icons/unity-icon-theme/places/svg/group-info.svg", "uri": "scopes-query://foursquare:drink", "metadata": {"images":null}}, {"title": "search in recipepuppy...", "icon_hint": "file:///usr/share/icons/unity-icon-theme/places/svg/group-recipes.svg", "uri": "scopes-query://recipepuppy:drink", "metadata": {}}, {"title": "search in grooveshark...", "icon_hint": "file:///usr/share/icons/unity-icon-theme/places/svg/service-grooveshark.svg", "uri": "scopes-query://grooveshark:drink", "metadata": {}}, {"title": "search in ebay...", "icon_hint": "file:///usr/share/icons/unity-icon-theme/places/svg/service-ebay.svg", "uri": "scopes-query://ebay:drink", "metadata": {}}, {"title": "search in songkick...", "icon_hint": "file:///usr/share/icons/unity-icon-theme/places/svg/group-music.svg", "uri": "scopes-query://songkick:drink", "metadata": {}}]}, "type": "results"}""",
44+ (scope_id, row) => {
45+ assert (scope_id == "searchin-scope.scope");
46+ if (row_count == 0) {
47+ assert (row[0].get_string () == "x-unity-no-preview-scopes-query://foursquare:drink"); // uri
48+ assert (row[1].get_string () == "file:///usr/share/icons/unity-icon-theme/places/svg/group-info.svg"); // icon hint
49+ assert (row[2].get_uint32 () == 0); // category
50+ assert (row[3].get_uint32 () == Unity.ResultType.DEFAULT); // result type
51+ assert (row[4].get_string () == "text/html"); // mimetype
52+ assert (row[5].get_string () == "search in foursquare..."); // title
53+ assert (row[6].get_string () == ""); // comment
54+ assert (row[7].get_string () == "x-unity-no-preview-scopes-query://foursquare:drink"); // dnd uri
55+ assert (row[8].is_of_type (new VariantType ("a{sv}")) && row[8].n_children () == 0); // metadata
56+ }
57+ row_count++;
58+ },
59+ (recommend) => { assert_not_reached (); });
60+
61+ assert (row_count == 5);
62+ }
63+
64 const string SERVER_URI = "https://foobar.ubuntu.com";
65 const string SEARCH_URI_PREFIX = SERVER_URI + "/smartscopes/v1/search";
66

Subscribers

People subscribed via source and target branches

to all changes: