Merge lp:~mikemc/unity-scope-click/add-cxx-scope into lp:unity-scope-click

Proposed by Mike McCracken
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
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
dobey (community) Approve
Review via email: mp+201494@code.launchpad.net

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_BUILD_TYPE=debug
make

-- that ought to get you to the point of linking the test binary, which currently fails.

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

32 +add_custom_target(check
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-credentials for exmaple).

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
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/$packagename" for example).

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

Revision history for this message
dobey (dobey) :
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
=== modified file '.bzrignore'
--- .bzrignore 2013-12-10 22:20:49 +0000
+++ .bzrignore 2014-01-13 22:01:11 +0000
@@ -17,7 +17,7 @@
17ltmain.sh17ltmain.sh
18missing18missing
19stamp-*19stamp-*
20*.[ch]20src/*.[ch]
21*.desktop21*.desktop
22*.gir22*.gir
23*.gmo23*.gmo
2424
=== added file 'CMakeLists.txt'
--- CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ CMakeLists.txt 2014-01-13 22:01:11 +0000
@@ -0,0 +1,38 @@
1project(clickscope CXX)
2cmake_minimum_required(VERSION 2.8.10)
3
4set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
5
6include(GNUInstallDirs)
7set(SCOPE_DATA_DIR share/unity/scopes) # FIXME, not correct.
8
9include(FindPkgConfig)
10pkg_check_modules(UNITY_SCOPES libunity-scopes REQUIRED)
11
12pkg_check_modules(LIBSIGNON REQUIRED libsignon-qt5 accounts-qt5)
13add_definitions(${LIBSIGNON_CFLAGS} ${LIBSIGNON_CFLAGS_OTHER})
14
15find_package (PkgConfig REQUIRED)
16pkg_check_modules(UBUNTUONE REQUIRED ubuntuoneauth-2.0)
17add_definitions(${UBUNTUONE_CFLAGS} ${UBUNTUONE_CFLAGS_OTHER})
18
19SET (SCOPE_LIB_VERSION 0.2.0)
20SET (SCOPE_LIB_SOVERSION 0)
21SET (SCOPE_LIB_API_VERSION 2.0)
22SET (SCOPE_LIB_UNVERSIONED clickscope)
23SET (SCOPE_LIB_NAME ${SCOPE_LIB_UNVERSIONED}-${SCOPE_LIB_API_VERSION})
24
25add_subdirectory(scope)
26add_subdirectory(data)
27
28add_custom_target(check
29 DEPENDS click-scope-tests
30)
31
32add_custom_target(check-valgrind
33 DEPENDS click-scope-tests-valgrind
34)
35
36add_custom_target(check-valgrind-leaks
37 DEPENDS click-scope-tests-valgrind-leaks
38)
039
=== added file 'data/CMakeLists.txt'
--- data/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ data/CMakeLists.txt 2014-01-13 22:01:11 +0000
@@ -0,0 +1,1 @@
1INSTALL(FILES clickscope.ini DESTINATION ${SCOPE_DATA_DIR})
02
=== added file 'data/clickscope.ini'
--- data/clickscope.ini 1970-01-01 00:00:00 +0000
+++ data/clickscope.ini 2014-01-13 22:01:11 +0000
@@ -0,0 +1,7 @@
1[ScopeConfig]
2DisplayName = Click Applications Scope
3Description = Scope for searching the click app store
4Art = clickscope.Art
5Icon = clickscope.Icon
6SearchHint = clickscope.SearchHint
7HotKey = clickscope.HotKey
08
=== added directory 'scope'
=== added file 'scope/CMakeLists.txt'
--- scope/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ scope/CMakeLists.txt 2014-01-13 22:01:11 +0000
@@ -0,0 +1,19 @@
1SET (CMAKE_INCLUDE_CURRENT_DIR ON)
2SET (CMAKE_AUTOMOC ON)
3find_package (Qt5Core REQUIRED)
4
5file (GLOB SCOPE_SOURCES *.cpp)
6file (GLOB SCOPE_HEADERS *.h)
7
8add_library (${SCOPE_LIB_NAME} SHARED ${SCOPE_SOURCES} )
9
10qt5_use_modules (${SCOPE_LIB_NAME} Network)
11
12target_link_libraries (${SCOPE_LIB_NAME}
13 ${UNITY_SCOPES_LDFLAGS}
14 ${UBUNTUONE_LDFLAGS})
15
16set_property (TARGET ${SCOPE_LIB_NAME} PROPERTY COMPILE_FLAGS ${UNITY_SCOPES_CFLAGS})
17
18
19add_subdirectory (tests)
020
=== added file 'scope/clickquery.cpp'
--- scope/clickquery.cpp 1970-01-01 00:00:00 +0000
+++ scope/clickquery.cpp 2014-01-13 22:01:11 +0000
@@ -0,0 +1,67 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * In addition, as a special exception, the copyright holders give
17 * permission to link the code of portions of this program with the
18 * OpenSSL library under certain conditions as described in each
19 * individual source file, and distribute linked combinations
20 * including the two.
21 * You must obey the GNU General Public License in all respects
22 * for all of the code used other than OpenSSL. If you modify
23 * file(s) with this exception, you may extend this exception to your
24 * version of the file(s), but you are not obligated to do so. If you
25 * do not wish to do so, delete this exception statement from your
26 * version. If you delete this exception statement from all source
27 * files in the program, then also delete it here.
28 */
29
30#include "clickquery.h"
31#include <scopes/Annotation.h>
32#include <scopes/CategoryRenderer.h>
33#include <scopes/CategorisedResult.h>
34#include <scopes/Query.h>
35#include <scopes/Reply.h>
36
37
38ClickQuery::ClickQuery(string const& query) :
39 query_(query)
40{
41}
42
43ClickQuery::~ClickQuery()
44{
45}
46
47void ClickQuery::cancelled()
48{
49}
50
51void ClickQuery::run(ReplyProxy const& reply)
52{
53 CategoryRenderer rdr;
54 auto cat = reply->register_category("cat1", "Category 1", "", rdr);
55 CategorisedResult res(cat);
56 res.set_uri("uri");
57 res.set_title("scope-A: result 1 for query \"" + query_ + "\"");
58 res.set_art("icon");
59 res.set_dnd_uri("dnd_uri");
60 reply->push(res);
61
62 Query q("scope-A", query_, "");
63 Annotation annotation(Annotation::Type::Link);
64 annotation.add_link("More...", q);
65 reply->push(annotation);
66
67}
068
=== added file 'scope/clickquery.h'
--- scope/clickquery.h 1970-01-01 00:00:00 +0000
+++ scope/clickquery.h 2014-01-13 22:01:11 +0000
@@ -0,0 +1,46 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * In addition, as a special exception, the copyright holders give
17 * permission to link the code of portions of this program with the
18 * OpenSSL library under certain conditions as described in each
19 * individual source file, and distribute linked combinations
20 * including the two.
21 * You must obey the GNU General Public License in all respects
22 * for all of the code used other than OpenSSL. If you modify
23 * file(s) with this exception, you may extend this exception to your
24 * version of the file(s), but you are not obligated to do so. If you
25 * do not wish to do so, delete this exception statement from your
26 * version. If you delete this exception statement from all source
27 * files in the program, then also delete it here.
28 */
29
30#include <scopes/QueryBase.h>
31
32using namespace std;
33using namespace unity::api::scopes;
34
35class ClickQuery : public QueryBase
36{
37public:
38 ClickQuery(std::string const& query);
39 ~ClickQuery();
40 virtual void cancelled() override;
41
42 virtual void run(ReplyProxy const& reply) override;
43
44private:
45 std::string query_;
46};
047
=== added file 'scope/clickscope.cpp'
--- scope/clickscope.cpp 1970-01-01 00:00:00 +0000
+++ scope/clickscope.cpp 2014-01-13 22:01:11 +0000
@@ -0,0 +1,48 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * In addition, as a special exception, the copyright holders give
17 * permission to link the code of portions of this program with the
18 * OpenSSL library under certain conditions as described in each
19 * individual source file, and distribute linked combinations
20 * including the two.
21 * You must obey the GNU General Public License in all respects
22 * for all of the code used other than OpenSSL. If you modify
23 * file(s) with this exception, you may extend this exception to your
24 * version of the file(s), but you are not obligated to do so. If you
25 * do not wish to do so, delete this exception statement from your
26 * version. If you delete this exception statement from all source
27 * files in the program, then also delete it here.
28 */
29
30#include "clickscope.h"
31#include "clickquery.h"
32
33
34int ClickScope::start(std::string const&, unity::api::scopes::RegistryProxy const&)
35{
36 return VERSION;
37}
38
39void ClickScope::stop()
40{
41}
42
43unity::api::scopes::QueryBase::UPtr create_query(std::string const& q,
44 unity::api::scopes::VariantMap const&)
45{
46 unity::api::scopes::QueryBase::UPtr query(new ClickQuery(q));
47 return query;
48}
049
=== added file 'scope/clickscope.h'
--- scope/clickscope.h 1970-01-01 00:00:00 +0000
+++ scope/clickscope.h 2014-01-13 22:01:11 +0000
@@ -0,0 +1,47 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * In addition, as a special exception, the copyright holders give
17 * permission to link the code of portions of this program with the
18 * OpenSSL library under certain conditions as described in each
19 * individual source file, and distribute linked combinations
20 * including the two.
21 * You must obey the GNU General Public License in all respects
22 * for all of the code used other than OpenSSL. If you modify
23 * file(s) with this exception, you may extend this exception to your
24 * version of the file(s), but you are not obligated to do so. If you
25 * do not wish to do so, delete this exception statement from your
26 * version. If you delete this exception statement from all source
27 * files in the program, then also delete it here.
28 */
29
30#ifndef CLICKSCOPE_H
31#define CLICKSCOPE_H
32
33#include <scopes/ScopeBase.h>
34#include <scopes/QueryBase.h>
35
36class ClickScope : public unity::api::scopes::ScopeBase
37{
38public:
39 virtual int start(std::string const&, unity::api::scopes::RegistryProxy const&) override;
40
41 virtual void stop() override;
42
43 virtual unity::api::scopes::QueryBase::UPtr create_query(std::string const& q,
44 unity::api::scopes::VariantMap const&) override;
45};
46
47#endif
048
=== added file 'scope/download-manager.cpp'
--- scope/download-manager.cpp 1970-01-01 00:00:00 +0000
+++ scope/download-manager.cpp 2014-01-13 22:01:11 +0000
@@ -0,0 +1,107 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * In addition, as a special exception, the copyright holders give
17 * permission to link the code of portions of this program with the
18 * OpenSSL library under certain conditions as described in each
19 * individual source file, and distribute linked combinations
20 * including the two.
21 * You must obey the GNU General Public License in all respects
22 * for all of the code used other than OpenSSL. If you modify
23 * file(s) with this exception, you may extend this exception to your
24 * version of the file(s), but you are not obligated to do so. If you
25 * do not wish to do so, delete this exception statement from your
26 * version. If you delete this exception statement from all source
27 * files in the program, then also delete it here.
28 */
29
30#include <QDebug>
31#include <QObject>
32#include <QString>
33#include <QTimer>
34
35#include "ssoservice.h"
36#include "token.h"
37
38#include "download-manager.h"
39
40namespace ClickScope {
41
42
43DownloadManager::DownloadManager(QObject *parent) :
44 QObject(parent)
45{
46 QObject::connect(&service, SIGNAL(credentialsFound(const Token&)),
47 this, SLOT(handleCredentialsFound(Token)));
48 QObject::connect(&service, SIGNAL(credentialsNotFound()),
49 this, SLOT(handleCredentialsNotFound()));
50 QObject::connect(&nam, SIGNAL(finished(QNetworkReply*)),
51 this, SLOT(handleNetworkFinished(QNetworkReply*)));
52
53}
54
55DownloadManager::~DownloadManager(){
56}
57
58void DownloadManager::fetchClickToken(QString downloadUrl)
59{
60 service.getCredentials();
61 _downloadUrl = downloadUrl;
62}
63
64void DownloadManager::handleCredentialsFound(UbuntuOne::Token token)
65{
66 qDebug() << "Credentials found, signing url " << _downloadUrl;
67
68 QString authHeader = token.signUrl(_downloadUrl, QStringLiteral("HEAD"));
69
70 qDebug() << "URL Signed, authHeader is:" << authHeader; // TODO: remove this log
71
72 QNetworkRequest req;
73 req.setRawHeader(QStringLiteral("Authorization").toUtf8(),
74 authHeader.toUtf8());
75 req.setUrl(_downloadUrl);
76 nam.get(req);
77}
78
79void DownloadManager::handleCredentialsNotFound()
80{
81 qDebug() << "No credentials were found.";
82 emit clickTokenFetchError(QString("No creds found"));
83}
84
85void DownloadManager::handleNetworkFinished(QNetworkReply *reply)
86{
87 // TODO: actually get the header
88 QString clickTokenHeader;
89 QVariant statusAttr = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
90 if(!statusAttr.isValid()) {
91 qDebug() << "Invalid HTTP response.";
92 return;
93 }
94
95 int status = statusAttr.toInt();
96 qDebug() << "HTTP Status " << status;
97
98 if (status != 200){
99 qDebug() << reply->rawHeaderPairs();
100 }
101
102 qDebug() << reply->readAll();
103
104 emit clickTokenFetched(clickTokenHeader);
105}
106
107} // namespace ClickScope
0108
=== added file 'scope/download-manager.h'
--- scope/download-manager.h 1970-01-01 00:00:00 +0000
+++ scope/download-manager.h 2014-01-13 22:01:11 +0000
@@ -0,0 +1,79 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * In addition, as a special exception, the copyright holders give
17 * permission to link the code of portions of this program with the
18 * OpenSSL library under certain conditions as described in each
19 * individual source file, and distribute linked combinations
20 * including the two.
21 * You must obey the GNU General Public License in all respects
22 * for all of the code used other than OpenSSL. If you modify
23 * file(s) with this exception, you may extend this exception to your
24 * version of the file(s), but you are not obligated to do so. If you
25 * do not wish to do so, delete this exception statement from your
26 * version. If you delete this exception statement from all source
27 * files in the program, then also delete it here.
28 */
29
30#ifndef _DOWNLOAD_MANAGER_H_
31#define _DOWNLOAD_MANAGER_H_
32
33#include <QDebug>
34#include <QNetworkReply>
35#include <QObject>
36#include <QString>
37
38#include "ssoservice.h"
39#include "token.h"
40#include "requests.h"
41#include "errormessages.h"
42
43namespace ClickScope {
44
45class DownloadManager : public QObject
46{
47 Q_OBJECT
48
49public:
50
51 explicit DownloadManager(QObject *parent = 0);
52 ~DownloadManager();
53
54public slots:
55
56 void fetchClickToken(QString downloadUrl);
57
58signals:
59
60 void clickTokenFetched(QString clickToken);
61 void clickTokenFetchError(QString errorMessage);
62
63private slots:
64
65 void handleCredentialsFound(UbuntuOne::Token token);
66 void handleCredentialsNotFound();
67 void handleNetworkFinished(QNetworkReply *reply);
68
69private:
70
71 UbuntuOne::SSOService service;
72 QNetworkAccessManager nam;
73 QString _downloadUrl;
74
75};
76
77} // namespace ClickScope
78
79#endif /* _DOWNLOAD_MANAGER_H_ */
080
=== added directory 'scope/tests'
=== added file 'scope/tests/CMakeLists.txt'
--- scope/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ scope/tests/CMakeLists.txt 2014-01-13 22:01:11 +0000
@@ -0,0 +1,42 @@
1SET (TESTS_TARGET test-click-scope)
2
3# Qt5 bits
4SET (CMAKE_INCLUDE_CURRENT_DIR ON)
5SET (CMAKE_AUTOMOC ON)
6find_package(Qt5Core REQUIRED)
7
8FILE (GLOB TEST_SOURCES *.cpp)
9FILE (GLOB TEST_HEADERS *.h)
10
11add_executable (${TESTS_TARGET}
12 ${TEST_SOURCES}
13 ${TEST_HEADERS}
14)
15
16qt5_use_modules (${TESTS_TARGET} Core DBus Network Test)
17
18target_include_directories ( ${TESTS_TARGET} PUBLIC ${CMAKE_SOURCE_DIR}/scope )
19target_link_libraries ( ${TESTS_TARGET}
20 ${UNITY_SCOPES_LDFLAGS}
21 ${UBUNTUONE_LDFLAGS}
22 )
23target_link_libraries ( ${TESTS_TARGET}
24 -Wl,-rpath,${CMAKE_BINARY_DIR}/src
25 -L${CMAKE_BINARY_DIR}/src
26 ${SCOPE_LIB_NAME}
27 )
28
29add_custom_target(click-scope-tests
30 COMMAND ${TESTS_TARGET}
31 DEPENDS ${TESTS_TARGET}
32)
33
34add_custom_target(click-scope-tests-valgrind
35 COMMAND "valgrind --tool=memcheck ${CMAKE_CURRENT_BINARY_DIR}/${TESTS_TARGET}"
36 DEPENDS ${TESTS_TARGET}
37)
38
39add_custom_target(click-scope-tests-valgrind-leaks
40 COMMAND "valgrind --tool=memcheck --track-origins=yes --num-callers=40 --leak-resolution=high --leak-check=full ${CMAKE_CURRENT_BINARY_DIR}/${TESTS_TARGET}"
41 DEPENDS ${TESTS_TARGET}
42)
043
=== added file 'scope/tests/main.cpp'
--- scope/tests/main.cpp 1970-01-01 00:00:00 +0000
+++ scope/tests/main.cpp 2014-01-13 22:01:11 +0000
@@ -0,0 +1,36 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * In addition, as a special exception, the copyright holders give
17 * permission to link the code of portions of this program with the
18 * OpenSSL library under certain conditions as described in each
19 * individual source file, and distribute linked combinations
20 * including the two.
21 * You must obey the GNU General Public License in all respects
22 * for all of the code used other than OpenSSL. If you modify
23 * file(s) with this exception, you may extend this exception to your
24 * version of the file(s), but you are not obligated to do so. If you
25 * do not wish to do so, delete this exception statement from your
26 * version. If you delete this exception statement from all source
27 * files in the program, then also delete it here.
28 */
29
30#include <QCoreApplication>
31#include "./test_runner.h"
32
33int main(int argc, char *argv[]) {
34 QCoreApplication a(argc, argv);
35 return RUN_ALL_QTESTS(argc, argv);
36}
037
=== added file 'scope/tests/test_download_manager.cpp'
--- scope/tests/test_download_manager.cpp 1970-01-01 00:00:00 +0000
+++ scope/tests/test_download_manager.cpp 2014-01-13 22:01:11 +0000
@@ -0,0 +1,40 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * In addition, as a special exception, the copyright holders give
17 * permission to link the code of portions of this program with the
18 * OpenSSL library under certain conditions as described in each
19 * individual source file, and distribute linked combinations
20 * including the two.
21 * You must obey the GNU General Public License in all respects
22 * for all of the code used other than OpenSSL. If you modify
23 * file(s) with this exception, you may extend this exception to your
24 * version of the file(s), but you are not obligated to do so. If you
25 * do not wish to do so, delete this exception statement from your
26 * version. If you delete this exception statement from all source
27 * files in the program, then also delete it here.
28 */
29
30#include "test_download_manager.h"
31
32using namespace ClickScope;
33
34void TestDownloadManager::testFetchClickTokenCredentialsFound()
35{
36 DownloadManager dm;
37 QSignalSpy spy(&dm, SIGNAL(clickTokenFetchError()));
38 dm.fetchClickToken(QString(""));
39 QTRY_COMPARE(spy.count(), 1);
40}
041
=== added file 'scope/tests/test_download_manager.h'
--- scope/tests/test_download_manager.h 1970-01-01 00:00:00 +0000
+++ scope/tests/test_download_manager.h 2014-01-13 22:01:11 +0000
@@ -0,0 +1,55 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * In addition, as a special exception, the copyright holders give
17 * permission to link the code of portions of this program with the
18 * OpenSSL library under certain conditions as described in each
19 * individual source file, and distribute linked combinations
20 * including the two.
21 * You must obey the GNU General Public License in all respects
22 * for all of the code used other than OpenSSL. If you modify
23 * file(s) with this exception, you may extend this exception to your
24 * version of the file(s), but you are not obligated to do so. If you
25 * do not wish to do so, delete this exception statement from your
26 * version. If you delete this exception statement from all source
27 * files in the program, then also delete it here.
28 */
29
30#ifndef _TEST_DOWNLOAD_MANAGER_H_
31#define _TEST_DOWNLOAD_MANAGER_H_
32
33#include <QObject>
34#include <QDebug>
35#include <QString>
36#include <QTest>
37#include <QSignalSpy>
38
39#include "test_runner.h"
40#include "download-manager.h"
41
42using namespace ClickScope;
43
44class TestDownloadManager : public QObject
45{
46 Q_OBJECT
47
48private slots:
49 void testFetchClickTokenCredentialsFound();
50// void testFetchClickTokenCredentialsNotFound();
51};
52
53DECLARE_TEST(TestDownloadManager)
54
55#endif /* _TEST_DOWNLOAD_MANAGER_H_ */
056
=== added file 'scope/tests/test_runner.h'
--- scope/tests/test_runner.h 1970-01-01 00:00:00 +0000
+++ scope/tests/test_runner.h 2014-01-13 22:01:11 +0000
@@ -0,0 +1,98 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * In addition, as a special exception, the copyright holders give
17 * permission to link the code of portions of this program with the
18 * OpenSSL library under certain conditions as described in each
19 * individual source file, and distribute linked combinations
20 * including the two.
21 * You must obey the GNU General Public License in all respects
22 * for all of the code used other than OpenSSL. If you modify
23 * file(s) with this exception, you may extend this exception to your
24 * version of the file(s), but you are not obligated to do so. If you
25 * do not wish to do so, delete this exception statement from your
26 * version. If you delete this exception statement from all source
27 * files in the program, then also delete it here.
28 */
29
30#ifndef TEST_RUNNER_H
31#define TEST_RUNNER_H
32
33#include <QDir>
34#include <QList>
35#include <QTest>
36#include <QSharedPointer>
37#include <iostream>
38
39class TestRunner {
40 public:
41
42 static TestRunner& Instance() {
43 static TestRunner instance;
44 return instance;
45 }
46
47 template <typename T>
48 char RegisterTest(char* name) {
49 if(!_tests.contains(name)) {
50 QSharedPointer<QObject> test(new T());
51 _tests.insert(name, QSharedPointer<QObject>(test));
52 }
53 return char(1);
54 }
55
56 int RunAll(int argc, char *argv[]) {
57 // provide command line to run a single test case
58 QCoreApplication* app = QCoreApplication::instance();
59 QStringList args = app->arguments();
60
61 if (args.contains("-testcase")) {
62 int index = args.indexOf("-testcase");
63 if (args.count() > index + 1) {
64 QString testcase = args[index + 1];
65 if (_tests.contains(testcase)) {
66 args.removeAt(index + 1);
67 args.removeAt(index);
68 return QTest::qExec(_tests[testcase].data(), args);
69 } else {
70 return -1;
71 }
72 } else {
73 return -1;
74 }
75 } else {
76 int errorCode = 0;
77 foreach (QString const &testName, _tests.keys()) {
78 errorCode |= QTest::qExec(_tests[testName].data(), argc, argv);
79 std::cout << std::endl;
80 }
81 return errorCode;
82 }
83 }
84
85 private:
86 QMap<QString, QSharedPointer<QObject> > _tests;
87};
88
89
90// Use this macro after your test declaration
91#define DECLARE_TEST(className)\
92 static char test_##className = TestRunner::Instance().RegisterTest<className>(const_cast<char *>(#className));
93
94// Use this macro to execute all tests
95#define RUN_ALL_QTESTS(argc, argv)\
96 TestRunner::Instance().RunAll(argc, argv);
97
98#endif // TEST_RUNNER_H

Subscribers

People subscribed via source and target branches

to all changes: