Merge lp:~alecu/unity-scope-click/send-click-frameworks into lp:unity-scope-click

Proposed by Alejandro J. Cura
Status: Merged
Approved by: dobey
Approved revision: 172
Merged at revision: 180
Proposed branch: lp:~alecu/unity-scope-click/send-click-frameworks
Merge into: lp:unity-scope-click
Diff against target: 166 lines (+102/-5)
4 files modified
scope/click/interface.cpp (+23/-3)
scope/click/interface.h (+12/-0)
scope/click/query.cpp (+15/-2)
scope/tests/test_interface.cpp (+52/-0)
To merge this branch: bzr merge lp:~alecu/unity-scope-click/send-click-frameworks
Reviewer Review Type Date Requested Status
dobey (community) Approve
PS Jenkins bot continuous-integration Approve
Mike McCracken (community) Approve
Review via email: mp+208207@code.launchpad.net

Commit message

Include supported frameworks in click search

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
171. By Alejandro J. Cura

improved comment

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

+1. I only have nitpicky style comments:

This is something I did recently (in my case it broke something, since my file wasn't including Qt), so it stuck out to me:
In FrameworkLocator::get_available_frameworks, this func looks like
It's trying to be all c++11, but it's using the qt foreach macro:
https://qt-project.org/doc/qt-5.0/qtcore/containers.html#the-foreach-keyword

the c++11 equivalent is the ranged for loop:
http://www.cprogramming.com/c++11/c++11-ranged-for-loop.html

So you probably want 'for (auto f : list_folder(FRAMEWORKS_FOLDER, FRAMEWORKS_PATTERN)) {...}'
(Although I haven't tried it, so it occurs to me that you might not be able to stick the call to list_folder inline like I did there...)

In queryUri (line 95 of the diff), you're using
QString::fromUtf8(ststring.c_str()) where fromStdString() is
shorter. You use fromStdString elsewhere, might as well change it here
now to be consistent.

review: Approve
Revision history for this message
Alejandro J. Cura (alecu) wrote :

> +1. I only have nitpicky style comments:
>
>
> This is something I did recently (in my case it broke something, since my file
> wasn't including Qt), so it stuck out to me:
> In FrameworkLocator::get_available_frameworks, this func looks like
> It's trying to be all c++11, but it's using the qt foreach macro:
> https://qt-project.org/doc/qt-5.0/qtcore/containers.html#the-foreach-keyword
>
> the c++11 equivalent is the ranged for loop:
> http://www.cprogramming.com/c++11/c++11-ranged-for-loop.html
>
> So you probably want 'for (auto f : list_folder(FRAMEWORKS_FOLDER,
> FRAMEWORKS_PATTERN)) {...}'

Good catch! TIL foreach vs ranged for.

> In queryUri (line 95 of the diff), you're using
> QString::fromUtf8(ststring.c_str()) where fromStdString() is
> shorter. You use fromStdString elsewhere, might as well change it here
> now to be consistent.

I'm getting rid of all the QNetwork mess in query.cpp in my next branch (replacing it with calls to Index.search), so I aimed for the smaller change there. For that reason, I rather keep it as is.

172. By Alejandro J. Cura

Replacing Qt's foreach with c++11's ranged for

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
dobey (dobey) :
review: Approve
173. By Alejandro J. Cura

merged with trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scope/click/interface.cpp'
2--- scope/click/interface.cpp 2014-02-24 14:10:10 +0000
3+++ scope/click/interface.cpp 2014-03-05 13:11:23 +0000
4@@ -237,6 +237,29 @@
5 }
6 }
7
8+std::vector<std::string> FrameworkLocator::list_folder(const std::string& folder, const std::string& pattern)
9+{
10+ std::vector<std::string> result;
11+
12+ QDir dir(QString::fromStdString(folder), QString::fromStdString(pattern),
13+ QDir::Unsorted, QDir::Readable | QDir::Files);
14+ QStringList entries = dir.entryList();
15+ for (int i = 0; i < entries.size(); ++i) {
16+ QString filename = entries.at(i);
17+ result.push_back(filename.toStdString());
18+ }
19+
20+ return result;
21+}
22+
23+std::vector<std::string> FrameworkLocator::get_available_frameworks()
24+{
25+ std::vector<std::string> result;
26+ for (auto f: list_folder(FRAMEWORKS_FOLDER, FRAMEWORKS_PATTERN)) {
27+ result.push_back(f.substr(0, f.size()-FRAMEWORKS_EXTENSION_LENGTH));
28+ }
29+ return result;
30+}
31
32 ManifestList manifest_list_from_json(const std::string& json)
33 {
34@@ -386,7 +409,4 @@
35 });
36 }
37
38-
39-
40-
41 } // namespace click
42
43=== modified file 'scope/click/interface.h'
44--- scope/click/interface.h 2014-02-24 14:04:59 +0000
45+++ scope/click/interface.h 2014-03-05 13:11:23 +0000
46@@ -89,6 +89,18 @@
47 QSharedPointer<KeyFileLocator> keyFileLocator;
48 };
49
50+class FrameworkLocator
51+{
52+public:
53+ constexpr static const char* FRAMEWORKS_FOLDER {"/usr/share/click/frameworks/"};
54+ constexpr static const char* FRAMEWORKS_PATTERN {"*.framework"};
55+ constexpr static const int FRAMEWORKS_EXTENSION_LENGTH = 10; // strlen(".framework")
56+
57+ virtual std::vector<std::string> get_available_frameworks();
58+protected:
59+ virtual std::vector<std::string> list_folder(const std::string &folder, const std::string &pattern);
60+};
61+
62 } // namespace click
63
64 #endif // CLICK_INTERFACE_H
65
66=== modified file 'scope/click/query.cpp'
67--- scope/click/query.cpp 2014-02-26 20:15:57 +0000
68+++ scope/click/query.cpp 2014-03-05 13:11:23 +0000
69@@ -56,6 +56,7 @@
70 #include<QUrl>
71 #include<vector>
72 #include<set>
73+#include<sstream>
74
75 namespace
76 {
77@@ -311,6 +312,16 @@
78
79 return iface;
80 }
81+
82+QString frameworks_arg()
83+{
84+ std::stringstream frameworks;
85+ for (auto f: click::FrameworkLocator().get_available_frameworks()) {
86+ frameworks << ",framework:" << f;
87+ }
88+ return QString::fromStdString(frameworks.str());
89+}
90+
91 }
92 void click::Query::run(scopes::SearchReplyProxy const& searchReply)
93 {
94@@ -335,8 +346,10 @@
95 {
96 static const QString queryPattern(
97 "https://search.apps.ubuntu.com/api/v1/search?q=%1"
98- ",framework:ubuntu-sdk-13.10,architecture:%2");
99- QString queryUri = queryPattern.arg(QString::fromUtf8(impl->query.c_str())).arg(architecture());
100+ "%2,architecture:%3");
101+
102+ QString queryUri = queryPattern.arg(QString::fromUtf8(impl->query.c_str()))
103+ .arg(frameworks_arg()).arg(architecture());
104
105 auto nam = getNetworkAccessManager(env);
106 auto networkReply = nam->get(QNetworkRequest(QUrl(queryUri)));
107
108=== modified file 'scope/tests/test_interface.cpp'
109--- scope/tests/test_interface.cpp 2014-02-18 07:05:58 +0000
110+++ scope/tests/test_interface.cpp 2014-03-05 13:11:23 +0000
111@@ -182,3 +182,55 @@
112
113 EXPECT_EQ(result.end(), std::find(result.begin(), result.end(), mustNotBePartOfResult));
114 }
115+
116+class FakeFrameworkLocator : public click::FrameworkLocator
117+{
118+public:
119+ MOCK_METHOD2(list_folder, std::vector<std::string>(
120+ const std::string& folder, const std::string& pattern));
121+};
122+
123+TEST(FrameworkLocator, getAvailableFrameworksUsesRightFolder)
124+{
125+ using namespace ::testing;
126+ FakeFrameworkLocator locator;
127+ EXPECT_CALL(locator, list_folder(FrameworkLocator::FRAMEWORKS_FOLDER, _))
128+ .Times(1).WillOnce(Return(std::vector<std::string>()));
129+ locator.get_available_frameworks();
130+}
131+
132+TEST(FrameworkLocator, getAvailableFrameworksUsesRightPattern)
133+{
134+ using namespace ::testing;
135+ FakeFrameworkLocator locator;
136+ EXPECT_CALL(locator, list_folder(_, FrameworkLocator::FRAMEWORKS_PATTERN))
137+ .Times(1).WillOnce(Return(std::vector<std::string>()));
138+ locator.get_available_frameworks();
139+}
140+
141+TEST(FrameworkLocator, getAvailableFrameworksTwoResults)
142+{
143+ using namespace ::testing;
144+
145+ FakeFrameworkLocator locator;
146+ std::vector<std::string> response = {"abc.framework", "def.framework"};
147+ EXPECT_CALL(locator, list_folder(_, _))
148+ .Times(1)
149+ .WillOnce(Return(response));
150+ auto frameworks = locator.get_available_frameworks();
151+ std::vector<std::string> expected = {"abc", "def"};
152+ EXPECT_EQ(expected, frameworks);
153+}
154+
155+TEST(FrameworkLocator, getAvailableFrameworksNoResults)
156+{
157+ using namespace ::testing;
158+
159+ FakeFrameworkLocator locator;
160+ std::vector<std::string> response = {};
161+ EXPECT_CALL(locator, list_folder(_, _))
162+ .Times(1)
163+ .WillOnce(Return(response));
164+ auto frameworks = locator.get_available_frameworks();
165+ EXPECT_EQ(0, frameworks.size());
166+}

Subscribers

People subscribed via source and target branches