Merge lp:~mikemc/unity-scope-click/add-cxx-scope into lp:unity-scope-click
- add-cxx-scope
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | dobey |
Approved revision: | 110 |
Merged at revision: | 105 |
Proposed branch: | lp:~mikemc/unity-scope-click/add-cxx-scope |
Merge into: | lp:unity-scope-click |
Diff against target: |
819 lines (+731/-1) 16 files modified
.bzrignore (+1/-1) CMakeLists.txt (+38/-0) data/CMakeLists.txt (+1/-0) data/clickscope.ini (+7/-0) scope/CMakeLists.txt (+19/-0) scope/clickquery.cpp (+67/-0) scope/clickquery.h (+46/-0) scope/clickscope.cpp (+48/-0) scope/clickscope.h (+47/-0) scope/download-manager.cpp (+107/-0) scope/download-manager.h (+79/-0) scope/tests/CMakeLists.txt (+42/-0) scope/tests/main.cpp (+36/-0) scope/tests/test_download_manager.cpp (+40/-0) scope/tests/test_download_manager.h (+55/-0) scope/tests/test_runner.h (+98/-0) |
To merge this branch: | bzr merge lp:~mikemc/unity-scope-click/add-cxx-scope |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
dobey (community) | Approve | ||
Review via email:
|
Commit message
- Add initial c++ scope code in scope/, using CMake
Description of the change
- Add initial c++ scope code in scope/, using CMake
because it's cmake, the existing autotools build structure is untouched and still works as before. tests pass as before.
NOTE: the new cmake does support out of tree builds. (as far as it gets)
mkdir build && cd build
cmake .. -DCMAKE_
make
-- that ought to get you to the point of linking the test binary, which currently fails.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
dobey (dobey) wrote : | # |
32 +add_custom_
33 + DEPENDS click-scope-tests
34 +)
35 +
271 +SET (TESTS_TARGET click-scope-tests)
281 +add_executable (${TESTS_TARGET}
This will only build the test program when 'make check' is run, but not run the resulting program. I'd suggest changing TESTS_TARGET to be 'test-click-scope' (it's generally good to start test command names with test-), and add a custom target for click-scope-tests that runs the resulting program without valgrind (see the tests in ubuntuone-
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:106
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:108
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
dobey (dobey) wrote : | # |
24 +set(DATADIR share/unity/scopes) # FIXME, not correct.
This should be SCOPES_DATA_DIR or something. DATADIR is a generic name, and generic variables should get generic paths (DATADIR would just be "share" typically, and PKGDATADIR would be "share/
Also, several of the added source files are missing the copyright/license header. Please add them.
- 109. By Mike McCracken
-
rename DATADIR to be more specific
- 110. By Mike McCracken
-
Use GPL+SSL license for all new c++ files
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
dobey (dobey) : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:110
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file '.bzrignore' |
2 | --- .bzrignore 2013-12-10 22:20:49 +0000 |
3 | +++ .bzrignore 2014-01-13 22:01:11 +0000 |
4 | @@ -17,7 +17,7 @@ |
5 | ltmain.sh |
6 | missing |
7 | stamp-* |
8 | -*.[ch] |
9 | +src/*.[ch] |
10 | *.desktop |
11 | *.gir |
12 | *.gmo |
13 | |
14 | === added file 'CMakeLists.txt' |
15 | --- CMakeLists.txt 1970-01-01 00:00:00 +0000 |
16 | +++ CMakeLists.txt 2014-01-13 22:01:11 +0000 |
17 | @@ -0,0 +1,38 @@ |
18 | +project(clickscope CXX) |
19 | +cmake_minimum_required(VERSION 2.8.10) |
20 | + |
21 | +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra") |
22 | + |
23 | +include(GNUInstallDirs) |
24 | +set(SCOPE_DATA_DIR share/unity/scopes) # FIXME, not correct. |
25 | + |
26 | +include(FindPkgConfig) |
27 | +pkg_check_modules(UNITY_SCOPES libunity-scopes REQUIRED) |
28 | + |
29 | +pkg_check_modules(LIBSIGNON REQUIRED libsignon-qt5 accounts-qt5) |
30 | +add_definitions(${LIBSIGNON_CFLAGS} ${LIBSIGNON_CFLAGS_OTHER}) |
31 | + |
32 | +find_package (PkgConfig REQUIRED) |
33 | +pkg_check_modules(UBUNTUONE REQUIRED ubuntuoneauth-2.0) |
34 | +add_definitions(${UBUNTUONE_CFLAGS} ${UBUNTUONE_CFLAGS_OTHER}) |
35 | + |
36 | +SET (SCOPE_LIB_VERSION 0.2.0) |
37 | +SET (SCOPE_LIB_SOVERSION 0) |
38 | +SET (SCOPE_LIB_API_VERSION 2.0) |
39 | +SET (SCOPE_LIB_UNVERSIONED clickscope) |
40 | +SET (SCOPE_LIB_NAME ${SCOPE_LIB_UNVERSIONED}-${SCOPE_LIB_API_VERSION}) |
41 | + |
42 | +add_subdirectory(scope) |
43 | +add_subdirectory(data) |
44 | + |
45 | +add_custom_target(check |
46 | + DEPENDS click-scope-tests |
47 | +) |
48 | + |
49 | +add_custom_target(check-valgrind |
50 | + DEPENDS click-scope-tests-valgrind |
51 | +) |
52 | + |
53 | +add_custom_target(check-valgrind-leaks |
54 | + DEPENDS click-scope-tests-valgrind-leaks |
55 | +) |
56 | |
57 | === added file 'data/CMakeLists.txt' |
58 | --- data/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
59 | +++ data/CMakeLists.txt 2014-01-13 22:01:11 +0000 |
60 | @@ -0,0 +1,1 @@ |
61 | +INSTALL(FILES clickscope.ini DESTINATION ${SCOPE_DATA_DIR}) |
62 | |
63 | === added file 'data/clickscope.ini' |
64 | --- data/clickscope.ini 1970-01-01 00:00:00 +0000 |
65 | +++ data/clickscope.ini 2014-01-13 22:01:11 +0000 |
66 | @@ -0,0 +1,7 @@ |
67 | +[ScopeConfig] |
68 | +DisplayName = Click Applications Scope |
69 | +Description = Scope for searching the click app store |
70 | +Art = clickscope.Art |
71 | +Icon = clickscope.Icon |
72 | +SearchHint = clickscope.SearchHint |
73 | +HotKey = clickscope.HotKey |
74 | |
75 | === added directory 'scope' |
76 | === added file 'scope/CMakeLists.txt' |
77 | --- scope/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
78 | +++ scope/CMakeLists.txt 2014-01-13 22:01:11 +0000 |
79 | @@ -0,0 +1,19 @@ |
80 | +SET (CMAKE_INCLUDE_CURRENT_DIR ON) |
81 | +SET (CMAKE_AUTOMOC ON) |
82 | +find_package (Qt5Core REQUIRED) |
83 | + |
84 | +file (GLOB SCOPE_SOURCES *.cpp) |
85 | +file (GLOB SCOPE_HEADERS *.h) |
86 | + |
87 | +add_library (${SCOPE_LIB_NAME} SHARED ${SCOPE_SOURCES} ) |
88 | + |
89 | +qt5_use_modules (${SCOPE_LIB_NAME} Network) |
90 | + |
91 | +target_link_libraries (${SCOPE_LIB_NAME} |
92 | + ${UNITY_SCOPES_LDFLAGS} |
93 | + ${UBUNTUONE_LDFLAGS}) |
94 | + |
95 | +set_property (TARGET ${SCOPE_LIB_NAME} PROPERTY COMPILE_FLAGS ${UNITY_SCOPES_CFLAGS}) |
96 | + |
97 | + |
98 | +add_subdirectory (tests) |
99 | |
100 | === added file 'scope/clickquery.cpp' |
101 | --- scope/clickquery.cpp 1970-01-01 00:00:00 +0000 |
102 | +++ scope/clickquery.cpp 2014-01-13 22:01:11 +0000 |
103 | @@ -0,0 +1,67 @@ |
104 | +/* |
105 | + * Copyright (C) 2014 Canonical Ltd. |
106 | + * |
107 | + * This program is free software: you can redistribute it and/or modify it |
108 | + * under the terms of the GNU General Public License version 3, as published |
109 | + * by the Free Software Foundation. |
110 | + * |
111 | + * This program is distributed in the hope that it will be useful, but |
112 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
113 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
114 | + * PURPOSE. See the GNU General Public License for more details. |
115 | + * |
116 | + * You should have received a copy of the GNU General Public License along |
117 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
118 | + * |
119 | + * In addition, as a special exception, the copyright holders give |
120 | + * permission to link the code of portions of this program with the |
121 | + * OpenSSL library under certain conditions as described in each |
122 | + * individual source file, and distribute linked combinations |
123 | + * including the two. |
124 | + * You must obey the GNU General Public License in all respects |
125 | + * for all of the code used other than OpenSSL. If you modify |
126 | + * file(s) with this exception, you may extend this exception to your |
127 | + * version of the file(s), but you are not obligated to do so. If you |
128 | + * do not wish to do so, delete this exception statement from your |
129 | + * version. If you delete this exception statement from all source |
130 | + * files in the program, then also delete it here. |
131 | + */ |
132 | + |
133 | +#include "clickquery.h" |
134 | +#include <scopes/Annotation.h> |
135 | +#include <scopes/CategoryRenderer.h> |
136 | +#include <scopes/CategorisedResult.h> |
137 | +#include <scopes/Query.h> |
138 | +#include <scopes/Reply.h> |
139 | + |
140 | + |
141 | +ClickQuery::ClickQuery(string const& query) : |
142 | + query_(query) |
143 | +{ |
144 | +} |
145 | + |
146 | +ClickQuery::~ClickQuery() |
147 | +{ |
148 | +} |
149 | + |
150 | +void ClickQuery::cancelled() |
151 | +{ |
152 | +} |
153 | + |
154 | +void ClickQuery::run(ReplyProxy const& reply) |
155 | +{ |
156 | + CategoryRenderer rdr; |
157 | + auto cat = reply->register_category("cat1", "Category 1", "", rdr); |
158 | + CategorisedResult res(cat); |
159 | + res.set_uri("uri"); |
160 | + res.set_title("scope-A: result 1 for query \"" + query_ + "\""); |
161 | + res.set_art("icon"); |
162 | + res.set_dnd_uri("dnd_uri"); |
163 | + reply->push(res); |
164 | + |
165 | + Query q("scope-A", query_, ""); |
166 | + Annotation annotation(Annotation::Type::Link); |
167 | + annotation.add_link("More...", q); |
168 | + reply->push(annotation); |
169 | + |
170 | +} |
171 | |
172 | === added file 'scope/clickquery.h' |
173 | --- scope/clickquery.h 1970-01-01 00:00:00 +0000 |
174 | +++ scope/clickquery.h 2014-01-13 22:01:11 +0000 |
175 | @@ -0,0 +1,46 @@ |
176 | +/* |
177 | + * Copyright (C) 2014 Canonical Ltd. |
178 | + * |
179 | + * This program is free software: you can redistribute it and/or modify it |
180 | + * under the terms of the GNU General Public License version 3, as published |
181 | + * by the Free Software Foundation. |
182 | + * |
183 | + * This program is distributed in the hope that it will be useful, but |
184 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
185 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
186 | + * PURPOSE. See the GNU General Public License for more details. |
187 | + * |
188 | + * You should have received a copy of the GNU General Public License along |
189 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
190 | + * |
191 | + * In addition, as a special exception, the copyright holders give |
192 | + * permission to link the code of portions of this program with the |
193 | + * OpenSSL library under certain conditions as described in each |
194 | + * individual source file, and distribute linked combinations |
195 | + * including the two. |
196 | + * You must obey the GNU General Public License in all respects |
197 | + * for all of the code used other than OpenSSL. If you modify |
198 | + * file(s) with this exception, you may extend this exception to your |
199 | + * version of the file(s), but you are not obligated to do so. If you |
200 | + * do not wish to do so, delete this exception statement from your |
201 | + * version. If you delete this exception statement from all source |
202 | + * files in the program, then also delete it here. |
203 | + */ |
204 | + |
205 | +#include <scopes/QueryBase.h> |
206 | + |
207 | +using namespace std; |
208 | +using namespace unity::api::scopes; |
209 | + |
210 | +class ClickQuery : public QueryBase |
211 | +{ |
212 | +public: |
213 | + ClickQuery(std::string const& query); |
214 | + ~ClickQuery(); |
215 | + virtual void cancelled() override; |
216 | + |
217 | + virtual void run(ReplyProxy const& reply) override; |
218 | + |
219 | +private: |
220 | + std::string query_; |
221 | +}; |
222 | |
223 | === added file 'scope/clickscope.cpp' |
224 | --- scope/clickscope.cpp 1970-01-01 00:00:00 +0000 |
225 | +++ scope/clickscope.cpp 2014-01-13 22:01:11 +0000 |
226 | @@ -0,0 +1,48 @@ |
227 | +/* |
228 | + * Copyright (C) 2014 Canonical Ltd. |
229 | + * |
230 | + * This program is free software: you can redistribute it and/or modify it |
231 | + * under the terms of the GNU General Public License version 3, as published |
232 | + * by the Free Software Foundation. |
233 | + * |
234 | + * This program is distributed in the hope that it will be useful, but |
235 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
236 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
237 | + * PURPOSE. See the GNU General Public License for more details. |
238 | + * |
239 | + * You should have received a copy of the GNU General Public License along |
240 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
241 | + * |
242 | + * In addition, as a special exception, the copyright holders give |
243 | + * permission to link the code of portions of this program with the |
244 | + * OpenSSL library under certain conditions as described in each |
245 | + * individual source file, and distribute linked combinations |
246 | + * including the two. |
247 | + * You must obey the GNU General Public License in all respects |
248 | + * for all of the code used other than OpenSSL. If you modify |
249 | + * file(s) with this exception, you may extend this exception to your |
250 | + * version of the file(s), but you are not obligated to do so. If you |
251 | + * do not wish to do so, delete this exception statement from your |
252 | + * version. If you delete this exception statement from all source |
253 | + * files in the program, then also delete it here. |
254 | + */ |
255 | + |
256 | +#include "clickscope.h" |
257 | +#include "clickquery.h" |
258 | + |
259 | + |
260 | +int ClickScope::start(std::string const&, unity::api::scopes::RegistryProxy const&) |
261 | +{ |
262 | + return VERSION; |
263 | +} |
264 | + |
265 | +void ClickScope::stop() |
266 | +{ |
267 | +} |
268 | + |
269 | +unity::api::scopes::QueryBase::UPtr create_query(std::string const& q, |
270 | + unity::api::scopes::VariantMap const&) |
271 | +{ |
272 | + unity::api::scopes::QueryBase::UPtr query(new ClickQuery(q)); |
273 | + return query; |
274 | +} |
275 | |
276 | === added file 'scope/clickscope.h' |
277 | --- scope/clickscope.h 1970-01-01 00:00:00 +0000 |
278 | +++ scope/clickscope.h 2014-01-13 22:01:11 +0000 |
279 | @@ -0,0 +1,47 @@ |
280 | +/* |
281 | + * Copyright (C) 2014 Canonical Ltd. |
282 | + * |
283 | + * This program is free software: you can redistribute it and/or modify it |
284 | + * under the terms of the GNU General Public License version 3, as published |
285 | + * by the Free Software Foundation. |
286 | + * |
287 | + * This program is distributed in the hope that it will be useful, but |
288 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
289 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
290 | + * PURPOSE. See the GNU General Public License for more details. |
291 | + * |
292 | + * You should have received a copy of the GNU General Public License along |
293 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
294 | + * |
295 | + * In addition, as a special exception, the copyright holders give |
296 | + * permission to link the code of portions of this program with the |
297 | + * OpenSSL library under certain conditions as described in each |
298 | + * individual source file, and distribute linked combinations |
299 | + * including the two. |
300 | + * You must obey the GNU General Public License in all respects |
301 | + * for all of the code used other than OpenSSL. If you modify |
302 | + * file(s) with this exception, you may extend this exception to your |
303 | + * version of the file(s), but you are not obligated to do so. If you |
304 | + * do not wish to do so, delete this exception statement from your |
305 | + * version. If you delete this exception statement from all source |
306 | + * files in the program, then also delete it here. |
307 | + */ |
308 | + |
309 | +#ifndef CLICKSCOPE_H |
310 | +#define CLICKSCOPE_H |
311 | + |
312 | +#include <scopes/ScopeBase.h> |
313 | +#include <scopes/QueryBase.h> |
314 | + |
315 | +class ClickScope : public unity::api::scopes::ScopeBase |
316 | +{ |
317 | +public: |
318 | + virtual int start(std::string const&, unity::api::scopes::RegistryProxy const&) override; |
319 | + |
320 | + virtual void stop() override; |
321 | + |
322 | + virtual unity::api::scopes::QueryBase::UPtr create_query(std::string const& q, |
323 | + unity::api::scopes::VariantMap const&) override; |
324 | +}; |
325 | + |
326 | +#endif |
327 | |
328 | === added file 'scope/download-manager.cpp' |
329 | --- scope/download-manager.cpp 1970-01-01 00:00:00 +0000 |
330 | +++ scope/download-manager.cpp 2014-01-13 22:01:11 +0000 |
331 | @@ -0,0 +1,107 @@ |
332 | +/* |
333 | + * Copyright (C) 2014 Canonical Ltd. |
334 | + * |
335 | + * This program is free software: you can redistribute it and/or modify it |
336 | + * under the terms of the GNU General Public License version 3, as published |
337 | + * by the Free Software Foundation. |
338 | + * |
339 | + * This program is distributed in the hope that it will be useful, but |
340 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
341 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
342 | + * PURPOSE. See the GNU General Public License for more details. |
343 | + * |
344 | + * You should have received a copy of the GNU General Public License along |
345 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
346 | + * |
347 | + * In addition, as a special exception, the copyright holders give |
348 | + * permission to link the code of portions of this program with the |
349 | + * OpenSSL library under certain conditions as described in each |
350 | + * individual source file, and distribute linked combinations |
351 | + * including the two. |
352 | + * You must obey the GNU General Public License in all respects |
353 | + * for all of the code used other than OpenSSL. If you modify |
354 | + * file(s) with this exception, you may extend this exception to your |
355 | + * version of the file(s), but you are not obligated to do so. If you |
356 | + * do not wish to do so, delete this exception statement from your |
357 | + * version. If you delete this exception statement from all source |
358 | + * files in the program, then also delete it here. |
359 | + */ |
360 | + |
361 | +#include <QDebug> |
362 | +#include <QObject> |
363 | +#include <QString> |
364 | +#include <QTimer> |
365 | + |
366 | +#include "ssoservice.h" |
367 | +#include "token.h" |
368 | + |
369 | +#include "download-manager.h" |
370 | + |
371 | +namespace ClickScope { |
372 | + |
373 | + |
374 | +DownloadManager::DownloadManager(QObject *parent) : |
375 | + QObject(parent) |
376 | +{ |
377 | + QObject::connect(&service, SIGNAL(credentialsFound(const Token&)), |
378 | + this, SLOT(handleCredentialsFound(Token))); |
379 | + QObject::connect(&service, SIGNAL(credentialsNotFound()), |
380 | + this, SLOT(handleCredentialsNotFound())); |
381 | + QObject::connect(&nam, SIGNAL(finished(QNetworkReply*)), |
382 | + this, SLOT(handleNetworkFinished(QNetworkReply*))); |
383 | + |
384 | +} |
385 | + |
386 | +DownloadManager::~DownloadManager(){ |
387 | +} |
388 | + |
389 | +void DownloadManager::fetchClickToken(QString downloadUrl) |
390 | +{ |
391 | + service.getCredentials(); |
392 | + _downloadUrl = downloadUrl; |
393 | +} |
394 | + |
395 | +void DownloadManager::handleCredentialsFound(UbuntuOne::Token token) |
396 | +{ |
397 | + qDebug() << "Credentials found, signing url " << _downloadUrl; |
398 | + |
399 | + QString authHeader = token.signUrl(_downloadUrl, QStringLiteral("HEAD")); |
400 | + |
401 | + qDebug() << "URL Signed, authHeader is:" << authHeader; // TODO: remove this log |
402 | + |
403 | + QNetworkRequest req; |
404 | + req.setRawHeader(QStringLiteral("Authorization").toUtf8(), |
405 | + authHeader.toUtf8()); |
406 | + req.setUrl(_downloadUrl); |
407 | + nam.get(req); |
408 | +} |
409 | + |
410 | +void DownloadManager::handleCredentialsNotFound() |
411 | +{ |
412 | + qDebug() << "No credentials were found."; |
413 | + emit clickTokenFetchError(QString("No creds found")); |
414 | +} |
415 | + |
416 | +void DownloadManager::handleNetworkFinished(QNetworkReply *reply) |
417 | +{ |
418 | + // TODO: actually get the header |
419 | + QString clickTokenHeader; |
420 | + QVariant statusAttr = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); |
421 | + if(!statusAttr.isValid()) { |
422 | + qDebug() << "Invalid HTTP response."; |
423 | + return; |
424 | + } |
425 | + |
426 | + int status = statusAttr.toInt(); |
427 | + qDebug() << "HTTP Status " << status; |
428 | + |
429 | + if (status != 200){ |
430 | + qDebug() << reply->rawHeaderPairs(); |
431 | + } |
432 | + |
433 | + qDebug() << reply->readAll(); |
434 | + |
435 | + emit clickTokenFetched(clickTokenHeader); |
436 | +} |
437 | + |
438 | +} // namespace ClickScope |
439 | |
440 | === added file 'scope/download-manager.h' |
441 | --- scope/download-manager.h 1970-01-01 00:00:00 +0000 |
442 | +++ scope/download-manager.h 2014-01-13 22:01:11 +0000 |
443 | @@ -0,0 +1,79 @@ |
444 | +/* |
445 | + * Copyright (C) 2014 Canonical Ltd. |
446 | + * |
447 | + * This program is free software: you can redistribute it and/or modify it |
448 | + * under the terms of the GNU General Public License version 3, as published |
449 | + * by the Free Software Foundation. |
450 | + * |
451 | + * This program is distributed in the hope that it will be useful, but |
452 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
453 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
454 | + * PURPOSE. See the GNU General Public License for more details. |
455 | + * |
456 | + * You should have received a copy of the GNU General Public License along |
457 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
458 | + * |
459 | + * In addition, as a special exception, the copyright holders give |
460 | + * permission to link the code of portions of this program with the |
461 | + * OpenSSL library under certain conditions as described in each |
462 | + * individual source file, and distribute linked combinations |
463 | + * including the two. |
464 | + * You must obey the GNU General Public License in all respects |
465 | + * for all of the code used other than OpenSSL. If you modify |
466 | + * file(s) with this exception, you may extend this exception to your |
467 | + * version of the file(s), but you are not obligated to do so. If you |
468 | + * do not wish to do so, delete this exception statement from your |
469 | + * version. If you delete this exception statement from all source |
470 | + * files in the program, then also delete it here. |
471 | + */ |
472 | + |
473 | +#ifndef _DOWNLOAD_MANAGER_H_ |
474 | +#define _DOWNLOAD_MANAGER_H_ |
475 | + |
476 | +#include <QDebug> |
477 | +#include <QNetworkReply> |
478 | +#include <QObject> |
479 | +#include <QString> |
480 | + |
481 | +#include "ssoservice.h" |
482 | +#include "token.h" |
483 | +#include "requests.h" |
484 | +#include "errormessages.h" |
485 | + |
486 | +namespace ClickScope { |
487 | + |
488 | +class DownloadManager : public QObject |
489 | +{ |
490 | + Q_OBJECT |
491 | + |
492 | +public: |
493 | + |
494 | + explicit DownloadManager(QObject *parent = 0); |
495 | + ~DownloadManager(); |
496 | + |
497 | +public slots: |
498 | + |
499 | + void fetchClickToken(QString downloadUrl); |
500 | + |
501 | +signals: |
502 | + |
503 | + void clickTokenFetched(QString clickToken); |
504 | + void clickTokenFetchError(QString errorMessage); |
505 | + |
506 | +private slots: |
507 | + |
508 | + void handleCredentialsFound(UbuntuOne::Token token); |
509 | + void handleCredentialsNotFound(); |
510 | + void handleNetworkFinished(QNetworkReply *reply); |
511 | + |
512 | +private: |
513 | + |
514 | + UbuntuOne::SSOService service; |
515 | + QNetworkAccessManager nam; |
516 | + QString _downloadUrl; |
517 | + |
518 | +}; |
519 | + |
520 | +} // namespace ClickScope |
521 | + |
522 | +#endif /* _DOWNLOAD_MANAGER_H_ */ |
523 | |
524 | === added directory 'scope/tests' |
525 | === added file 'scope/tests/CMakeLists.txt' |
526 | --- scope/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
527 | +++ scope/tests/CMakeLists.txt 2014-01-13 22:01:11 +0000 |
528 | @@ -0,0 +1,42 @@ |
529 | +SET (TESTS_TARGET test-click-scope) |
530 | + |
531 | +# Qt5 bits |
532 | +SET (CMAKE_INCLUDE_CURRENT_DIR ON) |
533 | +SET (CMAKE_AUTOMOC ON) |
534 | +find_package(Qt5Core REQUIRED) |
535 | + |
536 | +FILE (GLOB TEST_SOURCES *.cpp) |
537 | +FILE (GLOB TEST_HEADERS *.h) |
538 | + |
539 | +add_executable (${TESTS_TARGET} |
540 | + ${TEST_SOURCES} |
541 | + ${TEST_HEADERS} |
542 | +) |
543 | + |
544 | +qt5_use_modules (${TESTS_TARGET} Core DBus Network Test) |
545 | + |
546 | +target_include_directories ( ${TESTS_TARGET} PUBLIC ${CMAKE_SOURCE_DIR}/scope ) |
547 | +target_link_libraries ( ${TESTS_TARGET} |
548 | + ${UNITY_SCOPES_LDFLAGS} |
549 | + ${UBUNTUONE_LDFLAGS} |
550 | + ) |
551 | +target_link_libraries ( ${TESTS_TARGET} |
552 | + -Wl,-rpath,${CMAKE_BINARY_DIR}/src |
553 | + -L${CMAKE_BINARY_DIR}/src |
554 | + ${SCOPE_LIB_NAME} |
555 | + ) |
556 | + |
557 | +add_custom_target(click-scope-tests |
558 | + COMMAND ${TESTS_TARGET} |
559 | + DEPENDS ${TESTS_TARGET} |
560 | +) |
561 | + |
562 | +add_custom_target(click-scope-tests-valgrind |
563 | + COMMAND "valgrind --tool=memcheck ${CMAKE_CURRENT_BINARY_DIR}/${TESTS_TARGET}" |
564 | + DEPENDS ${TESTS_TARGET} |
565 | +) |
566 | + |
567 | +add_custom_target(click-scope-tests-valgrind-leaks |
568 | + COMMAND "valgrind --tool=memcheck --track-origins=yes --num-callers=40 --leak-resolution=high --leak-check=full ${CMAKE_CURRENT_BINARY_DIR}/${TESTS_TARGET}" |
569 | + DEPENDS ${TESTS_TARGET} |
570 | +) |
571 | |
572 | === added file 'scope/tests/main.cpp' |
573 | --- scope/tests/main.cpp 1970-01-01 00:00:00 +0000 |
574 | +++ scope/tests/main.cpp 2014-01-13 22:01:11 +0000 |
575 | @@ -0,0 +1,36 @@ |
576 | +/* |
577 | + * Copyright (C) 2014 Canonical Ltd. |
578 | + * |
579 | + * This program is free software: you can redistribute it and/or modify it |
580 | + * under the terms of the GNU General Public License version 3, as published |
581 | + * by the Free Software Foundation. |
582 | + * |
583 | + * This program is distributed in the hope that it will be useful, but |
584 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
585 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
586 | + * PURPOSE. See the GNU General Public License for more details. |
587 | + * |
588 | + * You should have received a copy of the GNU General Public License along |
589 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
590 | + * |
591 | + * In addition, as a special exception, the copyright holders give |
592 | + * permission to link the code of portions of this program with the |
593 | + * OpenSSL library under certain conditions as described in each |
594 | + * individual source file, and distribute linked combinations |
595 | + * including the two. |
596 | + * You must obey the GNU General Public License in all respects |
597 | + * for all of the code used other than OpenSSL. If you modify |
598 | + * file(s) with this exception, you may extend this exception to your |
599 | + * version of the file(s), but you are not obligated to do so. If you |
600 | + * do not wish to do so, delete this exception statement from your |
601 | + * version. If you delete this exception statement from all source |
602 | + * files in the program, then also delete it here. |
603 | + */ |
604 | + |
605 | +#include <QCoreApplication> |
606 | +#include "./test_runner.h" |
607 | + |
608 | +int main(int argc, char *argv[]) { |
609 | + QCoreApplication a(argc, argv); |
610 | + return RUN_ALL_QTESTS(argc, argv); |
611 | +} |
612 | |
613 | === added file 'scope/tests/test_download_manager.cpp' |
614 | --- scope/tests/test_download_manager.cpp 1970-01-01 00:00:00 +0000 |
615 | +++ scope/tests/test_download_manager.cpp 2014-01-13 22:01:11 +0000 |
616 | @@ -0,0 +1,40 @@ |
617 | +/* |
618 | + * Copyright (C) 2014 Canonical Ltd. |
619 | + * |
620 | + * This program is free software: you can redistribute it and/or modify it |
621 | + * under the terms of the GNU General Public License version 3, as published |
622 | + * by the Free Software Foundation. |
623 | + * |
624 | + * This program is distributed in the hope that it will be useful, but |
625 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
626 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
627 | + * PURPOSE. See the GNU General Public License for more details. |
628 | + * |
629 | + * You should have received a copy of the GNU General Public License along |
630 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
631 | + * |
632 | + * In addition, as a special exception, the copyright holders give |
633 | + * permission to link the code of portions of this program with the |
634 | + * OpenSSL library under certain conditions as described in each |
635 | + * individual source file, and distribute linked combinations |
636 | + * including the two. |
637 | + * You must obey the GNU General Public License in all respects |
638 | + * for all of the code used other than OpenSSL. If you modify |
639 | + * file(s) with this exception, you may extend this exception to your |
640 | + * version of the file(s), but you are not obligated to do so. If you |
641 | + * do not wish to do so, delete this exception statement from your |
642 | + * version. If you delete this exception statement from all source |
643 | + * files in the program, then also delete it here. |
644 | + */ |
645 | + |
646 | +#include "test_download_manager.h" |
647 | + |
648 | +using namespace ClickScope; |
649 | + |
650 | +void TestDownloadManager::testFetchClickTokenCredentialsFound() |
651 | +{ |
652 | + DownloadManager dm; |
653 | + QSignalSpy spy(&dm, SIGNAL(clickTokenFetchError())); |
654 | + dm.fetchClickToken(QString("")); |
655 | + QTRY_COMPARE(spy.count(), 1); |
656 | +} |
657 | |
658 | === added file 'scope/tests/test_download_manager.h' |
659 | --- scope/tests/test_download_manager.h 1970-01-01 00:00:00 +0000 |
660 | +++ scope/tests/test_download_manager.h 2014-01-13 22:01:11 +0000 |
661 | @@ -0,0 +1,55 @@ |
662 | +/* |
663 | + * Copyright (C) 2014 Canonical Ltd. |
664 | + * |
665 | + * This program is free software: you can redistribute it and/or modify it |
666 | + * under the terms of the GNU General Public License version 3, as published |
667 | + * by the Free Software Foundation. |
668 | + * |
669 | + * This program is distributed in the hope that it will be useful, but |
670 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
671 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
672 | + * PURPOSE. See the GNU General Public License for more details. |
673 | + * |
674 | + * You should have received a copy of the GNU General Public License along |
675 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
676 | + * |
677 | + * In addition, as a special exception, the copyright holders give |
678 | + * permission to link the code of portions of this program with the |
679 | + * OpenSSL library under certain conditions as described in each |
680 | + * individual source file, and distribute linked combinations |
681 | + * including the two. |
682 | + * You must obey the GNU General Public License in all respects |
683 | + * for all of the code used other than OpenSSL. If you modify |
684 | + * file(s) with this exception, you may extend this exception to your |
685 | + * version of the file(s), but you are not obligated to do so. If you |
686 | + * do not wish to do so, delete this exception statement from your |
687 | + * version. If you delete this exception statement from all source |
688 | + * files in the program, then also delete it here. |
689 | + */ |
690 | + |
691 | +#ifndef _TEST_DOWNLOAD_MANAGER_H_ |
692 | +#define _TEST_DOWNLOAD_MANAGER_H_ |
693 | + |
694 | +#include <QObject> |
695 | +#include <QDebug> |
696 | +#include <QString> |
697 | +#include <QTest> |
698 | +#include <QSignalSpy> |
699 | + |
700 | +#include "test_runner.h" |
701 | +#include "download-manager.h" |
702 | + |
703 | +using namespace ClickScope; |
704 | + |
705 | +class TestDownloadManager : public QObject |
706 | +{ |
707 | + Q_OBJECT |
708 | + |
709 | +private slots: |
710 | + void testFetchClickTokenCredentialsFound(); |
711 | +// void testFetchClickTokenCredentialsNotFound(); |
712 | +}; |
713 | + |
714 | +DECLARE_TEST(TestDownloadManager) |
715 | + |
716 | +#endif /* _TEST_DOWNLOAD_MANAGER_H_ */ |
717 | |
718 | === added file 'scope/tests/test_runner.h' |
719 | --- scope/tests/test_runner.h 1970-01-01 00:00:00 +0000 |
720 | +++ scope/tests/test_runner.h 2014-01-13 22:01:11 +0000 |
721 | @@ -0,0 +1,98 @@ |
722 | +/* |
723 | + * Copyright (C) 2014 Canonical Ltd. |
724 | + * |
725 | + * This program is free software: you can redistribute it and/or modify it |
726 | + * under the terms of the GNU General Public License version 3, as published |
727 | + * by the Free Software Foundation. |
728 | + * |
729 | + * This program is distributed in the hope that it will be useful, but |
730 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
731 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
732 | + * PURPOSE. See the GNU General Public License for more details. |
733 | + * |
734 | + * You should have received a copy of the GNU General Public License along |
735 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
736 | + * |
737 | + * In addition, as a special exception, the copyright holders give |
738 | + * permission to link the code of portions of this program with the |
739 | + * OpenSSL library under certain conditions as described in each |
740 | + * individual source file, and distribute linked combinations |
741 | + * including the two. |
742 | + * You must obey the GNU General Public License in all respects |
743 | + * for all of the code used other than OpenSSL. If you modify |
744 | + * file(s) with this exception, you may extend this exception to your |
745 | + * version of the file(s), but you are not obligated to do so. If you |
746 | + * do not wish to do so, delete this exception statement from your |
747 | + * version. If you delete this exception statement from all source |
748 | + * files in the program, then also delete it here. |
749 | + */ |
750 | + |
751 | +#ifndef TEST_RUNNER_H |
752 | +#define TEST_RUNNER_H |
753 | + |
754 | +#include <QDir> |
755 | +#include <QList> |
756 | +#include <QTest> |
757 | +#include <QSharedPointer> |
758 | +#include <iostream> |
759 | + |
760 | +class TestRunner { |
761 | + public: |
762 | + |
763 | + static TestRunner& Instance() { |
764 | + static TestRunner instance; |
765 | + return instance; |
766 | + } |
767 | + |
768 | + template <typename T> |
769 | + char RegisterTest(char* name) { |
770 | + if(!_tests.contains(name)) { |
771 | + QSharedPointer<QObject> test(new T()); |
772 | + _tests.insert(name, QSharedPointer<QObject>(test)); |
773 | + } |
774 | + return char(1); |
775 | + } |
776 | + |
777 | + int RunAll(int argc, char *argv[]) { |
778 | + // provide command line to run a single test case |
779 | + QCoreApplication* app = QCoreApplication::instance(); |
780 | + QStringList args = app->arguments(); |
781 | + |
782 | + if (args.contains("-testcase")) { |
783 | + int index = args.indexOf("-testcase"); |
784 | + if (args.count() > index + 1) { |
785 | + QString testcase = args[index + 1]; |
786 | + if (_tests.contains(testcase)) { |
787 | + args.removeAt(index + 1); |
788 | + args.removeAt(index); |
789 | + return QTest::qExec(_tests[testcase].data(), args); |
790 | + } else { |
791 | + return -1; |
792 | + } |
793 | + } else { |
794 | + return -1; |
795 | + } |
796 | + } else { |
797 | + int errorCode = 0; |
798 | + foreach (QString const &testName, _tests.keys()) { |
799 | + errorCode |= QTest::qExec(_tests[testName].data(), argc, argv); |
800 | + std::cout << std::endl; |
801 | + } |
802 | + return errorCode; |
803 | + } |
804 | + } |
805 | + |
806 | + private: |
807 | + QMap<QString, QSharedPointer<QObject> > _tests; |
808 | +}; |
809 | + |
810 | + |
811 | +// Use this macro after your test declaration |
812 | +#define DECLARE_TEST(className)\ |
813 | + static char test_##className = TestRunner::Instance().RegisterTest<className>(const_cast<char *>(#className)); |
814 | + |
815 | +// Use this macro to execute all tests |
816 | +#define RUN_ALL_QTESTS(argc, argv)\ |
817 | + TestRunner::Instance().RunAll(argc, argv); |
818 | + |
819 | +#endif // TEST_RUNNER_H |
PASSED: Continuous integration, rev:105 jenkins. qa.ubuntu. com/job/ unity-scope- click-ci/ 157/ jenkins. qa.ubuntu. com/job/ unity-scope- click-trusty- amd64-ci/ 55 jenkins. qa.ubuntu. com/job/ unity-scope- click-trusty- armhf-ci/ 55
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- scope-click- ci/157/ rebuild
http://