Merge lp:~ken-vandine/content-hub/click_hook into lp:~content-hub-team/content-hub/trunk

Proposed by Ken VanDine
Status: Merged
Approved by: Ken VanDine
Approved revision: 54
Merged at revision: 59
Proposed branch: lp:~ken-vandine/content-hub/click_hook
Merge into: lp:~content-hub-team/content-hub/trunk
Diff against target: 602 lines (+249/-55)
20 files modified
debian/content-hub.install (+2/-0)
debian/control (+1/-0)
debian/rules (+2/-2)
src/com/ubuntu/content/detail/peer_registry.h (+4/-0)
src/com/ubuntu/content/service/CMakeLists.txt (+9/-17)
src/com/ubuntu/content/service/content-hub.hook.in (+2/-2)
src/com/ubuntu/content/service/helper.cpp (+11/-6)
src/com/ubuntu/content/service/hook.cpp (+59/-19)
src/com/ubuntu/content/service/hook.h (+7/-4)
src/com/ubuntu/content/service/registry.cpp (+31/-0)
src/com/ubuntu/content/service/registry.h (+2/-0)
tests/acceptance-tests/CMakeLists.txt (+22/-0)
tests/acceptance-tests/app_hub_communication_default_peer.cpp (+2/-1)
tests/acceptance-tests/app_hub_communication_handler.cpp (+2/-1)
tests/acceptance-tests/app_hub_communication_known_peers.cpp (+2/-1)
tests/acceptance-tests/app_hub_communication_stores.cpp (+2/-1)
tests/acceptance-tests/app_hub_communication_transfer.cpp (+2/-1)
tests/acceptance-tests/bad.json (+6/-0)
tests/acceptance-tests/good.json (+6/-0)
tests/acceptance-tests/test_hook.cpp (+75/-0)
To merge this branch: bzr merge lp:~ken-vandine/content-hub/click_hook
Reviewer Review Type Date Requested Status
Günter Schwann (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+187341@code.launchpad.net

Commit message

Added a click hook, which iterates installed known peers, removing them when they are no longer installed and adding peers when needed.

Description of the change

Added a click hook, which iterates installed known peers, removing them when they are no longer installed and adding peers when needed. This looks for JSON files installed as part of a click package in ${HOME}/.local/share/content-hub/${id}

Example syntax:
{
    "source": [
        "pictures",
        "music"
    ]
}

Peers that provide an export handler for a type, should add this file to their click package and define it in their manifest with the content-hub click hook. Example from a manifest file:

    "hooks": {
        "untitled2": {
            "apparmor": "apparmor/untitled2.json",
            "content-hub": "content-hub/untitled2.json",
            "desktop": "untitled2.desktop"
        }
    },

And add content_exchange to the apparmor policy groups.

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

FAILED: Continuous integration, rev:53
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~ken-vandine/content-hub/click_hook/+merge/187341/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/content-hub-ci/87/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/content-hub-saucy-amd64-ci/86/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/content-hub-saucy-armhf-ci/86/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/content-hub-saucy-i386-ci/86/console

Click here to trigger a rebuild:
http://s-jenkins:8080/job/content-hub-ci/87/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
54. By Ken VanDine

Mock PeerRegistry instead of Registry, fixes test_hook when the gsettings
schema isn't installed.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Günter Schwann (schwann) wrote :

code looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/content-hub.install'
--- debian/content-hub.install 2013-09-11 21:08:25 +0000
+++ debian/content-hub.install 2013-09-25 03:15:44 +0000
@@ -1,3 +1,5 @@
1usr/bin1usr/bin
2usr/lib/*/content-hub/content-hub-peer-hook
3usr/share/click/hooks
2usr/share/dbus-14usr/share/dbus-1
3usr/share/glib-2.0/schemas5usr/share/glib-2.0/schemas
46
=== modified file 'debian/control'
--- debian/control 2013-09-18 13:54:40 +0000
+++ debian/control 2013-09-25 03:15:44 +0000
@@ -2,6 +2,7 @@
2Priority: optional2Priority: optional
3Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>3Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
4Build-Depends: cmake,4Build-Depends: cmake,
5 click-dev,
5 dbus-test-runner,6 dbus-test-runner,
6 debhelper (>= 9),7 debhelper (>= 9),
7 doxygen,8 doxygen,
89
=== modified file 'debian/rules'
--- debian/rules 2013-08-26 21:58:01 +0000
+++ debian/rules 2013-09-25 03:15:44 +0000
@@ -4,7 +4,7 @@
4export DPKG_GENSYMBOLS_CHECK_LEVEL=44export DPKG_GENSYMBOLS_CHECK_LEVEL=4
55
6%:6%:
7 dh $@ --fail-missing -- -B build7 dh $@ --with click --fail-missing -- -B build
88
9override_dh_auto_test:9override_dh_auto_test:
10 dbus-test-runner -t make -p "-C" -p "build" -p test10 dbus-test-runner -t make -p "-C" -p "build/tests/acceptance-tests" -p test
1111
=== modified file 'src/com/ubuntu/content/detail/peer_registry.h'
--- src/com/ubuntu/content/detail/peer_registry.h 2013-07-15 12:05:47 +0000
+++ src/com/ubuntu/content/detail/peer_registry.h 2013-09-25 03:15:44 +0000
@@ -42,9 +42,13 @@
4242
43 virtual Peer default_peer_for_type(Type) = 0;43 virtual Peer default_peer_for_type(Type) = 0;
44 virtual void enumerate_known_peers_for_type(Type, const std::function<void(const Peer&)>& for_each) = 0;44 virtual void enumerate_known_peers_for_type(Type, const std::function<void(const Peer&)>& for_each) = 0;
45 virtual void enumerate_known_peers(const std::function<void(const Peer&)>& for_each) = 0;
4546
46 virtual bool install_default_peer_for_type(Type, Peer) = 0;47 virtual bool install_default_peer_for_type(Type, Peer) = 0;
47 virtual bool install_peer_for_type(Type, Peer) = 0;48 virtual bool install_peer_for_type(Type, Peer) = 0;
49 virtual bool remove_peer(Peer peer) = 0;
50
51
48};52};
49}53}
50}54}
5155
=== modified file 'src/com/ubuntu/content/service/CMakeLists.txt'
--- src/com/ubuntu/content/service/CMakeLists.txt 2013-09-11 21:08:25 +0000
+++ src/com/ubuntu/content/service/CMakeLists.txt 2013-09-25 03:15:44 +0000
@@ -76,13 +76,10 @@
76 ${GSETTINGS_LDFLAGS}76 ${GSETTINGS_LDFLAGS}
77)77)
7878
79##########################79install(
80# Don't install hook yet #80 TARGETS content-hub-peer-hook
81##########################81 RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_LIBEXECDIR}/content-hub"
82#install(82)
83# TARGETS content-hub-peer-hook
84# RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_LIBEXECDIR}"
85#)
8683
87set_target_properties(84set_target_properties(
88 content-hub-peer-hook85 content-hub-peer-hook
@@ -100,13 +97,8 @@
100 @ONLY97 @ONLY
101)98)
10299
103##########################100install(
104# Don't install hook yet #101FILES
105##########################102"${CLICK_HOOK}"
106#install(103DESTINATION "/usr/share/click/hooks"
107#FILES104)
108#"${CLICK_HOOK}"
109#DESTINATION "/usr/share/click/hooks"
110#)
111
112
113105
=== modified file 'src/com/ubuntu/content/service/content-hub.hook.in'
--- src/com/ubuntu/content/service/content-hub.hook.in 2013-09-11 21:01:56 +0000
+++ src/com/ubuntu/content/service/content-hub.hook.in 2013-09-25 03:15:44 +0000
@@ -1,4 +1,4 @@
1Pattern: ${home}/.cache/content-hub/${id}-content.json1Pattern: ${home}/.local/share/content-hub/${id}
2Exec: @pkglibexecdir@/content-hub/content-hub-peer-hook ${id}2Exec: @pkglibexecdir@/content-hub/content-hub-peer-hook
3User-Level: yes3User-Level: yes
4Hook-Name: content-hub4Hook-Name: content-hub
55
=== modified file 'src/com/ubuntu/content/service/helper.cpp'
--- src/com/ubuntu/content/service/helper.cpp 2013-09-11 16:45:23 +0000
+++ src/com/ubuntu/content/service/helper.cpp 2013-09-25 03:15:44 +0000
@@ -17,7 +17,6 @@
17 */17 */
1818
19#include <QCoreApplication>19#include <QCoreApplication>
20#include <com/ubuntu/content/type.h>
2120
22#include "hook.h"21#include "hook.h"
2322
@@ -27,12 +26,18 @@
27{26{
28 QCoreApplication app(argc, argv);27 QCoreApplication app(argc, argv);
2928
30 if (app.arguments().count() <= 1)29 qDebug() << Q_FUNC_INFO;
30
31 if (app.arguments().count() > 1)
31 {32 {
32 qWarning() << "USAGE:" << app.arguments().first() << "APP_ID";33 qWarning() << "Shouldn't have arguments";
33 return 1;34 return 1;
34 }35 }
3536
36 Hook hook(app.arguments().at(1));37 new Hook();
37 return app.exec();38
39 app.exec();
40
41 /* We always want to return 0 */
42 return 0;
38}43}
3944
=== modified file 'src/com/ubuntu/content/service/hook.cpp'
--- src/com/ubuntu/content/service/hook.cpp 2013-09-11 16:45:23 +0000
+++ src/com/ubuntu/content/service/hook.cpp 2013-09-25 03:15:44 +0000
@@ -24,54 +24,95 @@
24#include <QStandardPaths>24#include <QStandardPaths>
25#include <QDebug>25#include <QDebug>
26#include <QTimer>26#include <QTimer>
27#include <com/ubuntu/content/peer.h>
2728
28#include "hook.h"29#include "hook.h"
2930
30Hook::Hook(QString app_id, QObject *parent) :31Hook::Hook(QObject *parent) :
31 QObject(parent),32 QObject(parent),
32 app_id(app_id),
33 registry(new Registry())33 registry(new Registry())
34{34{
35 qDebug() << Q_FUNC_INFO;
36 QTimer::singleShot(200, this, SLOT(run()));35 QTimer::singleShot(200, this, SLOT(run()));
37}36}
3837
38
39Hook::Hook(com::ubuntu::content::detail::PeerRegistry *registry, QObject *parent) :
40 QObject(parent),
41 registry(registry)
42{
43}
44
39void Hook::run()45void Hook::run()
40{46{
41 qDebug() << Q_FUNC_INFO;47 qDebug() << Q_FUNC_INFO;
4248 /* Looks for files in ${HOME}/.local/share/content-hub/${id} installed
43 /* FIXME: we should do a sanity check on this before installing */49 * by click packages. These files are JSON, for example:
44 auto peer = cuc::Peer(app_id);50 *
51 * {
52 * "source": [
53 * "pictures",
54 * "music"
55 * ]
56 * }
57 *
58 * The hook also iterates known peers and removes them if there is
59 * no JSON file installed in this path.
60 */
4561
46 QDir contentDir(62 QDir contentDir(
47 QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)63 QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)
48 + QString("/")64 + QString("/")
49 + QString("content-hub"));65 + QString("content-hub"));
5066
51 qDebug() << contentDir.absolutePath();
52 if (not contentDir.exists())67 if (not contentDir.exists())
53 return_error();68 return_error();
5469
55 const QString file = contentDir.filePath(peer.id() + QString("-content.json"));70 QStringList all_peers;
5671 registry->enumerate_known_peers([&all_peers](const com::ubuntu::content::Peer& peer)
57 QFile contentJson(file);72 {
73 all_peers.append(peer.id());
74 });
75
76 Q_FOREACH(QString p, all_peers)
77 {
78 qDebug() << Q_FUNC_INFO << "Looking for" << p;
79 QStringList pp = contentDir.entryList(QStringList("*"+ p));
80 if (pp.isEmpty())
81 registry->remove_peer(com::ubuntu::content::Peer{p});
82 }
83
84 Q_FOREACH(QFileInfo f, contentDir.entryInfoList(QDir::Files))
85 add_peer(f);
86
87 QCoreApplication::instance()->quit();
88}
89
90bool Hook::add_peer(QFileInfo result)
91{
92 qDebug() << Q_FUNC_INFO << "Hook:" << result.filePath();
93
94 QString app_id = result.fileName();
95 auto peer = cuc::Peer(app_id);
96
97 QFile contentJson(result.absoluteFilePath());
58 if (!contentJson.open(QIODevice::ReadOnly | QIODevice::Text))98 if (!contentJson.open(QIODevice::ReadOnly | QIODevice::Text))
59 return_error("couldn't open " + QString(file));99 return_error("couldn't open " + result.absoluteFilePath());
60100
61 QJsonParseError *e = new QJsonParseError();101 QJsonParseError *e = new QJsonParseError();
62 QJsonDocument contentDoc = QJsonDocument::fromJson(contentJson.readAll(), e);102 QJsonDocument contentDoc = QJsonDocument::fromJson(contentJson.readAll(), e);
63103
64 if (e->error != 0)104 if (e->error != 0)
65 return_error(e->errorString());105 return return_error(e->errorString());
66106
67 if (not contentDoc.isObject())107 if (not contentDoc.isObject())
68 return_error("invalid JSON object");108 return return_error("invalid JSON object");
69
70109
71 QJsonObject contentObj = contentDoc.object();110 QJsonObject contentObj = contentDoc.object();
72 QVariant sources = contentObj.toVariantMap()["source"];111 QVariant sources = contentObj.toVariantMap()["source"];
73 Q_FOREACH(QString source, sources.toStringList())112 Q_FOREACH(QString source, sources.toStringList())
74 {113 {
114 /* FIXME: we should iterate known types, but there isn't
115 * really a good way to do that right now */
75 if (source == "pictures")116 if (source == "pictures")
76 {117 {
77 if (not registry->install_peer_for_type(cuc::Type::Known::pictures(), peer))118 if (not registry->install_peer_for_type(cuc::Type::Known::pictures(), peer))
@@ -88,12 +129,11 @@
88 qWarning() << "Failed to install peer for" << source;129 qWarning() << "Failed to install peer for" << source;
89 }130 }
90 }131 }
91132 return true;
92 QCoreApplication::instance()->quit();
93}133}
94134
95void Hook::return_error(QString err)135bool Hook::return_error(QString err)
96{136{
97 qWarning() << "Failed to install peer" << err;137 qWarning() << "Failed to install peer" << err;
98 QCoreApplication::instance()->exit(1);138 return false;
99}139}
100140
=== modified file 'src/com/ubuntu/content/service/hook.h'
--- src/com/ubuntu/content/service/hook.h 2013-09-11 16:45:23 +0000
+++ src/com/ubuntu/content/service/hook.h 2013-09-25 03:15:44 +0000
@@ -20,6 +20,8 @@
20#define HOOK_H20#define HOOK_H
2121
22#include <QObject>22#include <QObject>
23#include <QFileInfo>
24#include <com/ubuntu/content/peer.h>
2325
24#include "registry.h"26#include "registry.h"
2527
@@ -27,15 +29,16 @@
27{29{
28 Q_OBJECT30 Q_OBJECT
29public:31public:
30 explicit Hook(QString app_id, QObject *parent = 0);32 explicit Hook(QObject *parent = 0);
33 Hook(com::ubuntu::content::detail::PeerRegistry *registry, QObject *parent = 0);
3134
32public slots:35public slots:
33 void return_error(QString err = "");36 bool return_error(QString err = "");
34 void run();37 void run();
38 bool add_peer(QFileInfo);
3539
36private:40private:
37 QString app_id;41 com::ubuntu::content::detail::PeerRegistry* registry;
38 Registry* registry;
39 42
40};43};
4144
4245
=== modified file 'src/com/ubuntu/content/service/registry.cpp'
--- src/com/ubuntu/content/service/registry.cpp 2013-09-18 14:32:34 +0000
+++ src/com/ubuntu/content/service/registry.cpp 2013-09-25 03:15:44 +0000
@@ -48,6 +48,21 @@
48 }48 }
49}49}
5050
51void Registry::enumerate_known_peers(const std::function<void(const cuc::Peer&)>&for_each)
52{
53 qDebug() << Q_FUNC_INFO;
54
55 Q_FOREACH (QString type_id, m_peers->keys())
56 {
57 qDebug() << Q_FUNC_INFO << type_id;
58 Q_FOREACH (QString k, m_peers->get(type_id).toStringList())
59 {
60 qDebug() << Q_FUNC_INFO << k;
61 for_each(k);
62 }
63 }
64}
65
51bool Registry::install_default_peer_for_type(cuc::Type type, cuc::Peer peer)66bool Registry::install_default_peer_for_type(cuc::Type type, cuc::Peer peer)
52{67{
53 qDebug() << Q_FUNC_INFO << "type:" << type.id() << "peer:" << peer.id();68 qDebug() << Q_FUNC_INFO << "type:" << type.id() << "peer:" << peer.id();
@@ -72,3 +87,19 @@
72 }87 }
73 return false;88 return false;
74}89}
90
91bool Registry::remove_peer(cuc::Peer peer)
92{
93 qDebug() << Q_FUNC_INFO << "peer:" << peer.id();
94 bool ret = false;
95 Q_FOREACH (QString type_id, m_peers->keys())
96 {
97 QStringList l = m_peers->get(type_id).toStringList();
98 if (l.contains(peer.id()))
99 {
100 l.removeAll(peer.id());
101 ret = m_peers->trySet(type_id, QVariant(l));
102 }
103 }
104 return ret;
105}
75106
=== modified file 'src/com/ubuntu/content/service/registry.h'
--- src/com/ubuntu/content/service/registry.h 2013-09-18 14:32:50 +0000
+++ src/com/ubuntu/content/service/registry.h 2013-09-25 03:15:44 +0000
@@ -36,8 +36,10 @@
36 ~Registry();36 ~Registry();
37 cuc::Peer default_peer_for_type(cuc::Type type);37 cuc::Peer default_peer_for_type(cuc::Type type);
38 void enumerate_known_peers_for_type(cuc::Type type, const std::function<void(const cuc::Peer&)>& for_each);38 void enumerate_known_peers_for_type(cuc::Type type, const std::function<void(const cuc::Peer&)>& for_each);
39 void enumerate_known_peers(const std::function<void(const cuc::Peer&)>& for_each);
39 bool install_default_peer_for_type(cuc::Type type, cuc::Peer peer);40 bool install_default_peer_for_type(cuc::Type type, cuc::Peer peer);
40 bool install_peer_for_type(cuc::Type type, cuc::Peer peer); 41 bool install_peer_for_type(cuc::Type type, cuc::Peer peer);
42 bool remove_peer(cuc::Peer peer);
4143
42private:44private:
43 QScopedPointer<QGSettings> m_defaultPeers;45 QScopedPointer<QGSettings> m_defaultPeers;
4446
=== modified file 'tests/acceptance-tests/CMakeLists.txt'
--- tests/acceptance-tests/CMakeLists.txt 2013-09-20 16:20:06 +0000
+++ tests/acceptance-tests/CMakeLists.txt 2013-09-25 03:15:44 +0000
@@ -52,12 +52,24 @@
52 test_utils.cpp52 test_utils.cpp
53)53)
5454
55add_executable(
56 test_hook
57 test_hook.cpp
58 ${MOCS}
59 ${CMAKE_SOURCE_DIR}/src/com/ubuntu/content/service/hook.cpp
60 ${CMAKE_SOURCE_DIR}/src/com/ubuntu/content/service/registry.cpp
61 good.json
62 bad.json
63)
64
55qt5_use_modules(app_hub_communication_default_peer Core Test)65qt5_use_modules(app_hub_communication_default_peer Core Test)
56qt5_use_modules(app_hub_communication_known_peers Core Test)66qt5_use_modules(app_hub_communication_known_peers Core Test)
57qt5_use_modules(app_hub_communication_stores Core Test)67qt5_use_modules(app_hub_communication_stores Core Test)
58qt5_use_modules(app_hub_communication_transfer Core Test)68qt5_use_modules(app_hub_communication_transfer Core Test)
59qt5_use_modules(app_hub_communication_handler Core Test)69qt5_use_modules(app_hub_communication_handler Core Test)
60qt5_use_modules(test_utils Core Test)70qt5_use_modules(test_utils Core Test)
71qt5_use_modules(test_hook Core Test)
72
61target_link_libraries(app_hub_communication_stores content-hub gmock gtest gtest_main)73target_link_libraries(app_hub_communication_stores content-hub gmock gtest gtest_main)
62target_link_libraries(app_hub_communication_default_peer content-hub gmock gtest gtest_main)74target_link_libraries(app_hub_communication_default_peer content-hub gmock gtest gtest_main)
63target_link_libraries(app_hub_communication_known_peers content-hub gmock gtest gtest_main)75target_link_libraries(app_hub_communication_known_peers content-hub gmock gtest gtest_main)
@@ -65,6 +77,7 @@
65target_link_libraries(app_hub_communication_transfer content-hub gmock gtest gtest_main)77target_link_libraries(app_hub_communication_transfer content-hub gmock gtest gtest_main)
66target_link_libraries(app_hub_communication_handler content-hub gmock gtest gtest_main)78target_link_libraries(app_hub_communication_handler content-hub gmock gtest gtest_main)
67target_link_libraries(test_utils content-hub gmock gtest gtest_main)79target_link_libraries(test_utils content-hub gmock gtest gtest_main)
80target_link_libraries(test_hook content-hub gmock gtest gtest_main ${GSETTINGS_LDFLAGS})
6881
69add_test(app_hub_communication_default_peer app_hub_communication_default_peer)82add_test(app_hub_communication_default_peer app_hub_communication_default_peer)
70add_test(app_hub_communication_known_peers app_hub_communication_known_peers)83add_test(app_hub_communication_known_peers app_hub_communication_known_peers)
@@ -72,6 +85,15 @@
72add_test(app_hub_communication_transfer app_hub_communication_transfer)85add_test(app_hub_communication_transfer app_hub_communication_transfer)
73add_test(app_hub_communication_handler app_hub_communication_handler)86add_test(app_hub_communication_handler app_hub_communication_handler)
74add_test(test_utils test_utils)87add_test(test_utils test_utils)
88add_test(test_hook test_hook)
89
90set_target_properties(
91 test_hook
92 PROPERTIES
93 AUTOMOC TRUE
94)
95
96file(COPY good.json bad.json DESTINATION .)
7597
76add_custom_command(98add_custom_command(
77 OUTPUT transfer_files99 OUTPUT transfer_files
78100
=== modified file 'tests/acceptance-tests/app_hub_communication_default_peer.cpp'
--- tests/acceptance-tests/app_hub_communication_default_peer.cpp 2013-09-06 09:25:19 +0000
+++ tests/acceptance-tests/app_hub_communication_default_peer.cpp 2013-09-25 03:15:44 +0000
@@ -67,9 +67,10 @@
6767
68 MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t));68 MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t));
69 MOCK_METHOD2(enumerate_known_peers_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));69 MOCK_METHOD2(enumerate_known_peers_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));
70 70 MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&));
71 MOCK_METHOD2(install_default_peer_for_type, bool(cuc::Type, cuc::Peer));71 MOCK_METHOD2(install_default_peer_for_type, bool(cuc::Type, cuc::Peer));
72 MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer));72 MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer));
73 MOCK_METHOD1(remove_peer, bool(cuc::Peer));
73};74};
74}75}
7576
7677
=== modified file 'tests/acceptance-tests/app_hub_communication_handler.cpp'
--- tests/acceptance-tests/app_hub_communication_handler.cpp 2013-09-13 15:23:54 +0000
+++ tests/acceptance-tests/app_hub_communication_handler.cpp 2013-09-25 03:15:44 +0000
@@ -65,9 +65,10 @@
6565
66 MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t));66 MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t));
67 MOCK_METHOD2(enumerate_known_peers_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));67 MOCK_METHOD2(enumerate_known_peers_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));
6868 MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&));
69 MOCK_METHOD2(install_default_peer_for_type, bool(cuc::Type, cuc::Peer));69 MOCK_METHOD2(install_default_peer_for_type, bool(cuc::Type, cuc::Peer));
70 MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer));70 MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer));
71 MOCK_METHOD1(remove_peer, bool(cuc::Peer));
71};72};
7273
73struct MockedHandler : public cuc::ImportExportHandler74struct MockedHandler : public cuc::ImportExportHandler
7475
=== modified file 'tests/acceptance-tests/app_hub_communication_known_peers.cpp'
--- tests/acceptance-tests/app_hub_communication_known_peers.cpp 2013-09-18 14:59:01 +0000
+++ tests/acceptance-tests/app_hub_communication_known_peers.cpp 2013-09-25 03:15:44 +0000
@@ -66,9 +66,10 @@
6666
67 MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t));67 MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t));
68 MOCK_METHOD2(enumerate_known_peers_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));68 MOCK_METHOD2(enumerate_known_peers_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));
69 69 MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&));
70 MOCK_METHOD2(install_default_peer_for_type, bool(cuc::Type, cuc::Peer));70 MOCK_METHOD2(install_default_peer_for_type, bool(cuc::Type, cuc::Peer));
71 MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer));71 MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer));
72 MOCK_METHOD1(remove_peer, bool(cuc::Peer));
72};73};
73}74}
7475
7576
=== modified file 'tests/acceptance-tests/app_hub_communication_stores.cpp'
--- tests/acceptance-tests/app_hub_communication_stores.cpp 2013-09-06 09:25:19 +0000
+++ tests/acceptance-tests/app_hub_communication_stores.cpp 2013-09-25 03:15:44 +0000
@@ -66,9 +66,10 @@
6666
67 MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t));67 MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t));
68 MOCK_METHOD2(enumerate_known_peers_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));68 MOCK_METHOD2(enumerate_known_peers_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));
69 69 MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&));
70 MOCK_METHOD2(install_default_peer_for_type, bool(cuc::Type, cuc::Peer));70 MOCK_METHOD2(install_default_peer_for_type, bool(cuc::Type, cuc::Peer));
71 MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer));71 MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer));
72 MOCK_METHOD1(remove_peer, bool(cuc::Peer));
72};73};
73}74}
7475
7576
=== modified file 'tests/acceptance-tests/app_hub_communication_transfer.cpp'
--- tests/acceptance-tests/app_hub_communication_transfer.cpp 2013-09-20 15:40:51 +0000
+++ tests/acceptance-tests/app_hub_communication_transfer.cpp 2013-09-25 03:15:44 +0000
@@ -68,9 +68,10 @@
6868
69 MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t));69 MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t));
70 MOCK_METHOD2(enumerate_known_peers_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));70 MOCK_METHOD2(enumerate_known_peers_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));
71 71 MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&));
72 MOCK_METHOD2(install_default_peer_for_type, bool(cuc::Type, cuc::Peer));72 MOCK_METHOD2(install_default_peer_for_type, bool(cuc::Type, cuc::Peer));
73 MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer));73 MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer));
74 MOCK_METHOD1(remove_peer, bool(cuc::Peer));
74};75};
75}76}
7677
7778
=== added file 'tests/acceptance-tests/bad.json'
--- tests/acceptance-tests/bad.json 1970-01-01 00:00:00 +0000
+++ tests/acceptance-tests/bad.json 2013-09-25 03:15:44 +0000
@@ -0,0 +1,6 @@
1{
2 "source": [
3 "pictures",
4 "music",
5 ]
6}
07
=== added file 'tests/acceptance-tests/good.json'
--- tests/acceptance-tests/good.json 1970-01-01 00:00:00 +0000
+++ tests/acceptance-tests/good.json 2013-09-25 03:15:44 +0000
@@ -0,0 +1,6 @@
1{
2 "source": [
3 "pictures",
4 "music"
5 ]
6}
07
=== added file 'tests/acceptance-tests/test_hook.cpp'
--- tests/acceptance-tests/test_hook.cpp 1970-01-01 00:00:00 +0000
+++ tests/acceptance-tests/test_hook.cpp 2013-09-25 03:15:44 +0000
@@ -0,0 +1,75 @@
1/*
2 * Copyright © 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Ken VanDine <ken.vandine@canonical.com>
17 */
18
19#include <com/ubuntu/content/peer.h>
20#include <com/ubuntu/content/type.h>
21#include "com/ubuntu/content/detail/peer_registry.h"
22#include "com/ubuntu/content/service/hook.h"
23
24#include <gmock/gmock.h>
25#include <gtest/gtest.h>
26
27#include <QtTest/QTest>
28
29namespace cuc = com::ubuntu::content;
30
31void PrintTo(const QString& s, ::std::ostream* os) {
32 *os << std::string(qPrintable(s));
33}
34
35namespace
36{
37struct MockedRegistry : public cuc::detail::PeerRegistry
38{
39 MockedRegistry() : PeerRegistry()
40 {
41 using namespace ::testing;
42
43 ON_CALL(*this, default_peer_for_type(_)).WillByDefault(Return(cuc::Peer::unknown()));
44 ON_CALL(*this, install_default_peer_for_type(_,_)).WillByDefault(Return(false));
45 ON_CALL(*this, install_peer_for_type(_,_)).WillByDefault(Return(false));
46 ON_CALL(*this, remove_peer(_)).WillByDefault(Return(false));
47 }
48
49 MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t));
50 MOCK_METHOD2(enumerate_known_peers_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));
51
52 MOCK_METHOD2(install_default_peer_for_type, bool(cuc::Type, cuc::Peer));
53 MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer));
54 MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&));
55 MOCK_METHOD1(remove_peer, bool(cuc::Peer));
56};
57}
58
59TEST(Hook, parse_json)
60{
61 using namespace ::testing;
62
63 auto mock = new MockedRegistry{};
64 EXPECT_CALL(*mock, install_peer_for_type(_,_)).
65 Times(Exactly(2)).
66 WillRepeatedly(Return(true));
67
68 QFileInfo f("good.json");
69 Hook *hook = new Hook(mock);
70
71 EXPECT_TRUE(hook->add_peer(f));
72 f.setFile("bad.json");
73 EXPECT_FALSE(hook->add_peer(f));
74 delete mock;
75}

Subscribers

People subscribed via source and target branches