Merge lp:~ken-vandine/content-hub/click_hook into lp:~content-hub-team/content-hub/trunk
- click_hook
- Merge into trunk
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 |
Related bugs: |
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}
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": {
}
},
And add content_exchange to the apparmor policy groups.
PS Jenkins bot (ps-jenkins) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:53
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 54. By Ken VanDine
-
Mock PeerRegistry instead of Registry, fixes test_hook when the gsettings
schema isn't installed.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:54
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Günter Schwann (schwann) wrote : | # |
code looks good
Preview Diff
1 | === modified file 'debian/content-hub.install' | |||
2 | --- debian/content-hub.install 2013-09-11 21:08:25 +0000 | |||
3 | +++ debian/content-hub.install 2013-09-25 03:15:44 +0000 | |||
4 | @@ -1,3 +1,5 @@ | |||
5 | 1 | usr/bin | 1 | usr/bin |
6 | 2 | usr/lib/*/content-hub/content-hub-peer-hook | ||
7 | 3 | usr/share/click/hooks | ||
8 | 2 | usr/share/dbus-1 | 4 | usr/share/dbus-1 |
9 | 3 | usr/share/glib-2.0/schemas | 5 | usr/share/glib-2.0/schemas |
10 | 4 | 6 | ||
11 | === modified file 'debian/control' | |||
12 | --- debian/control 2013-09-18 13:54:40 +0000 | |||
13 | +++ debian/control 2013-09-25 03:15:44 +0000 | |||
14 | @@ -2,6 +2,7 @@ | |||
15 | 2 | Priority: optional | 2 | Priority: optional |
16 | 3 | Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> | 3 | Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> |
17 | 4 | Build-Depends: cmake, | 4 | Build-Depends: cmake, |
18 | 5 | click-dev, | ||
19 | 5 | dbus-test-runner, | 6 | dbus-test-runner, |
20 | 6 | debhelper (>= 9), | 7 | debhelper (>= 9), |
21 | 7 | doxygen, | 8 | doxygen, |
22 | 8 | 9 | ||
23 | === modified file 'debian/rules' | |||
24 | --- debian/rules 2013-08-26 21:58:01 +0000 | |||
25 | +++ debian/rules 2013-09-25 03:15:44 +0000 | |||
26 | @@ -4,7 +4,7 @@ | |||
27 | 4 | export DPKG_GENSYMBOLS_CHECK_LEVEL=4 | 4 | export DPKG_GENSYMBOLS_CHECK_LEVEL=4 |
28 | 5 | 5 | ||
29 | 6 | %: | 6 | %: |
31 | 7 | dh $@ --fail-missing -- -B build | 7 | dh $@ --with click --fail-missing -- -B build |
32 | 8 | 8 | ||
33 | 9 | override_dh_auto_test: | 9 | override_dh_auto_test: |
35 | 10 | dbus-test-runner -t make -p "-C" -p "build" -p test | 10 | dbus-test-runner -t make -p "-C" -p "build/tests/acceptance-tests" -p test |
36 | 11 | 11 | ||
37 | === modified file 'src/com/ubuntu/content/detail/peer_registry.h' | |||
38 | --- src/com/ubuntu/content/detail/peer_registry.h 2013-07-15 12:05:47 +0000 | |||
39 | +++ src/com/ubuntu/content/detail/peer_registry.h 2013-09-25 03:15:44 +0000 | |||
40 | @@ -42,9 +42,13 @@ | |||
41 | 42 | 42 | ||
42 | 43 | virtual Peer default_peer_for_type(Type) = 0; | 43 | virtual Peer default_peer_for_type(Type) = 0; |
43 | 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; |
44 | 45 | virtual void enumerate_known_peers(const std::function<void(const Peer&)>& for_each) = 0; | ||
45 | 45 | 46 | ||
46 | 46 | virtual bool install_default_peer_for_type(Type, Peer) = 0; | 47 | virtual bool install_default_peer_for_type(Type, Peer) = 0; |
47 | 47 | virtual bool install_peer_for_type(Type, Peer) = 0; | 48 | virtual bool install_peer_for_type(Type, Peer) = 0; |
48 | 49 | virtual bool remove_peer(Peer peer) = 0; | ||
49 | 50 | |||
50 | 51 | |||
51 | 48 | }; | 52 | }; |
52 | 49 | } | 53 | } |
53 | 50 | } | 54 | } |
54 | 51 | 55 | ||
55 | === modified file 'src/com/ubuntu/content/service/CMakeLists.txt' | |||
56 | --- src/com/ubuntu/content/service/CMakeLists.txt 2013-09-11 21:08:25 +0000 | |||
57 | +++ src/com/ubuntu/content/service/CMakeLists.txt 2013-09-25 03:15:44 +0000 | |||
58 | @@ -76,13 +76,10 @@ | |||
59 | 76 | ${GSETTINGS_LDFLAGS} | 76 | ${GSETTINGS_LDFLAGS} |
60 | 77 | ) | 77 | ) |
61 | 78 | 78 | ||
69 | 79 | ########################## | 79 | install( |
70 | 80 | # Don't install hook yet # | 80 | TARGETS content-hub-peer-hook |
71 | 81 | ########################## | 81 | RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_LIBEXECDIR}/content-hub" |
72 | 82 | #install( | 82 | ) |
66 | 83 | # TARGETS content-hub-peer-hook | ||
67 | 84 | # RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_LIBEXECDIR}" | ||
68 | 85 | #) | ||
73 | 86 | 83 | ||
74 | 87 | set_target_properties( | 84 | set_target_properties( |
75 | 88 | content-hub-peer-hook | 85 | content-hub-peer-hook |
76 | @@ -100,13 +97,8 @@ | |||
77 | 100 | @ONLY | 97 | @ONLY |
78 | 101 | ) | 98 | ) |
79 | 102 | 99 | ||
90 | 103 | ########################## | 100 | install( |
91 | 104 | # Don't install hook yet # | 101 | FILES |
92 | 105 | ########################## | 102 | "${CLICK_HOOK}" |
93 | 106 | #install( | 103 | DESTINATION "/usr/share/click/hooks" |
94 | 107 | #FILES | 104 | ) |
85 | 108 | #"${CLICK_HOOK}" | ||
86 | 109 | #DESTINATION "/usr/share/click/hooks" | ||
87 | 110 | #) | ||
88 | 111 | |||
89 | 112 | |||
95 | 113 | 105 | ||
96 | === modified file 'src/com/ubuntu/content/service/content-hub.hook.in' | |||
97 | --- src/com/ubuntu/content/service/content-hub.hook.in 2013-09-11 21:01:56 +0000 | |||
98 | +++ src/com/ubuntu/content/service/content-hub.hook.in 2013-09-25 03:15:44 +0000 | |||
99 | @@ -1,4 +1,4 @@ | |||
102 | 1 | Pattern: ${home}/.cache/content-hub/${id}-content.json | 1 | Pattern: ${home}/.local/share/content-hub/${id} |
103 | 2 | Exec: @pkglibexecdir@/content-hub/content-hub-peer-hook ${id} | 2 | Exec: @pkglibexecdir@/content-hub/content-hub-peer-hook |
104 | 3 | User-Level: yes | 3 | User-Level: yes |
105 | 4 | Hook-Name: content-hub | 4 | Hook-Name: content-hub |
106 | 5 | 5 | ||
107 | === modified file 'src/com/ubuntu/content/service/helper.cpp' | |||
108 | --- src/com/ubuntu/content/service/helper.cpp 2013-09-11 16:45:23 +0000 | |||
109 | +++ src/com/ubuntu/content/service/helper.cpp 2013-09-25 03:15:44 +0000 | |||
110 | @@ -17,7 +17,6 @@ | |||
111 | 17 | */ | 17 | */ |
112 | 18 | 18 | ||
113 | 19 | #include <QCoreApplication> | 19 | #include <QCoreApplication> |
114 | 20 | #include <com/ubuntu/content/type.h> | ||
115 | 21 | 20 | ||
116 | 22 | #include "hook.h" | 21 | #include "hook.h" |
117 | 23 | 22 | ||
118 | @@ -27,12 +26,18 @@ | |||
119 | 27 | { | 26 | { |
120 | 28 | QCoreApplication app(argc, argv); | 27 | QCoreApplication app(argc, argv); |
121 | 29 | 28 | ||
123 | 30 | if (app.arguments().count() <= 1) | 29 | qDebug() << Q_FUNC_INFO; |
124 | 30 | |||
125 | 31 | if (app.arguments().count() > 1) | ||
126 | 31 | { | 32 | { |
129 | 32 | qWarning() << "USAGE:" << app.arguments().first() << "APP_ID"; | 33 | qWarning() << "Shouldn't have arguments"; |
130 | 33 | return 1; | 34 | return 1; |
131 | 34 | } | 35 | } |
132 | 35 | 36 | ||
135 | 36 | Hook hook(app.arguments().at(1)); | 37 | new Hook(); |
136 | 37 | return app.exec(); | 38 | |
137 | 39 | app.exec(); | ||
138 | 40 | |||
139 | 41 | /* We always want to return 0 */ | ||
140 | 42 | return 0; | ||
141 | 38 | } | 43 | } |
142 | 39 | 44 | ||
143 | === modified file 'src/com/ubuntu/content/service/hook.cpp' | |||
144 | --- src/com/ubuntu/content/service/hook.cpp 2013-09-11 16:45:23 +0000 | |||
145 | +++ src/com/ubuntu/content/service/hook.cpp 2013-09-25 03:15:44 +0000 | |||
146 | @@ -24,54 +24,95 @@ | |||
147 | 24 | #include <QStandardPaths> | 24 | #include <QStandardPaths> |
148 | 25 | #include <QDebug> | 25 | #include <QDebug> |
149 | 26 | #include <QTimer> | 26 | #include <QTimer> |
150 | 27 | #include <com/ubuntu/content/peer.h> | ||
151 | 27 | 28 | ||
152 | 28 | #include "hook.h" | 29 | #include "hook.h" |
153 | 29 | 30 | ||
155 | 30 | Hook::Hook(QString app_id, QObject *parent) : | 31 | Hook::Hook(QObject *parent) : |
156 | 31 | QObject(parent), | 32 | QObject(parent), |
157 | 32 | app_id(app_id), | ||
158 | 33 | registry(new Registry()) | 33 | registry(new Registry()) |
159 | 34 | { | 34 | { |
160 | 35 | qDebug() << Q_FUNC_INFO; | ||
161 | 36 | QTimer::singleShot(200, this, SLOT(run())); | 35 | QTimer::singleShot(200, this, SLOT(run())); |
162 | 37 | } | 36 | } |
163 | 38 | 37 | ||
164 | 38 | |||
165 | 39 | Hook::Hook(com::ubuntu::content::detail::PeerRegistry *registry, QObject *parent) : | ||
166 | 40 | QObject(parent), | ||
167 | 41 | registry(registry) | ||
168 | 42 | { | ||
169 | 43 | } | ||
170 | 44 | |||
171 | 39 | void Hook::run() | 45 | void Hook::run() |
172 | 40 | { | 46 | { |
173 | 41 | qDebug() << Q_FUNC_INFO; | 47 | qDebug() << Q_FUNC_INFO; |
177 | 42 | 48 | /* Looks for files in ${HOME}/.local/share/content-hub/${id} installed | |
178 | 43 | /* FIXME: we should do a sanity check on this before installing */ | 49 | * by click packages. These files are JSON, for example: |
179 | 44 | auto peer = cuc::Peer(app_id); | 50 | * |
180 | 51 | * { | ||
181 | 52 | * "source": [ | ||
182 | 53 | * "pictures", | ||
183 | 54 | * "music" | ||
184 | 55 | * ] | ||
185 | 56 | * } | ||
186 | 57 | * | ||
187 | 58 | * The hook also iterates known peers and removes them if there is | ||
188 | 59 | * no JSON file installed in this path. | ||
189 | 60 | */ | ||
190 | 45 | 61 | ||
191 | 46 | QDir contentDir( | 62 | QDir contentDir( |
193 | 47 | QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) | 63 | QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) |
194 | 48 | + QString("/") | 64 | + QString("/") |
195 | 49 | + QString("content-hub")); | 65 | + QString("content-hub")); |
196 | 50 | 66 | ||
197 | 51 | qDebug() << contentDir.absolutePath(); | ||
198 | 52 | if (not contentDir.exists()) | 67 | if (not contentDir.exists()) |
199 | 53 | return_error(); | 68 | return_error(); |
200 | 54 | 69 | ||
204 | 55 | const QString file = contentDir.filePath(peer.id() + QString("-content.json")); | 70 | QStringList all_peers; |
205 | 56 | 71 | registry->enumerate_known_peers([&all_peers](const com::ubuntu::content::Peer& peer) | |
206 | 57 | QFile contentJson(file); | 72 | { |
207 | 73 | all_peers.append(peer.id()); | ||
208 | 74 | }); | ||
209 | 75 | |||
210 | 76 | Q_FOREACH(QString p, all_peers) | ||
211 | 77 | { | ||
212 | 78 | qDebug() << Q_FUNC_INFO << "Looking for" << p; | ||
213 | 79 | QStringList pp = contentDir.entryList(QStringList("*"+ p)); | ||
214 | 80 | if (pp.isEmpty()) | ||
215 | 81 | registry->remove_peer(com::ubuntu::content::Peer{p}); | ||
216 | 82 | } | ||
217 | 83 | |||
218 | 84 | Q_FOREACH(QFileInfo f, contentDir.entryInfoList(QDir::Files)) | ||
219 | 85 | add_peer(f); | ||
220 | 86 | |||
221 | 87 | QCoreApplication::instance()->quit(); | ||
222 | 88 | } | ||
223 | 89 | |||
224 | 90 | bool Hook::add_peer(QFileInfo result) | ||
225 | 91 | { | ||
226 | 92 | qDebug() << Q_FUNC_INFO << "Hook:" << result.filePath(); | ||
227 | 93 | |||
228 | 94 | QString app_id = result.fileName(); | ||
229 | 95 | auto peer = cuc::Peer(app_id); | ||
230 | 96 | |||
231 | 97 | QFile contentJson(result.absoluteFilePath()); | ||
232 | 58 | if (!contentJson.open(QIODevice::ReadOnly | QIODevice::Text)) | 98 | if (!contentJson.open(QIODevice::ReadOnly | QIODevice::Text)) |
234 | 59 | return_error("couldn't open " + QString(file)); | 99 | return_error("couldn't open " + result.absoluteFilePath()); |
235 | 60 | 100 | ||
236 | 61 | QJsonParseError *e = new QJsonParseError(); | 101 | QJsonParseError *e = new QJsonParseError(); |
237 | 62 | QJsonDocument contentDoc = QJsonDocument::fromJson(contentJson.readAll(), e); | 102 | QJsonDocument contentDoc = QJsonDocument::fromJson(contentJson.readAll(), e); |
238 | 63 | 103 | ||
239 | 64 | if (e->error != 0) | 104 | if (e->error != 0) |
241 | 65 | return_error(e->errorString()); | 105 | return return_error(e->errorString()); |
242 | 66 | 106 | ||
243 | 67 | if (not contentDoc.isObject()) | 107 | if (not contentDoc.isObject()) |
246 | 68 | return_error("invalid JSON object"); | 108 | return return_error("invalid JSON object"); |
245 | 69 | |||
247 | 70 | 109 | ||
248 | 71 | QJsonObject contentObj = contentDoc.object(); | 110 | QJsonObject contentObj = contentDoc.object(); |
249 | 72 | QVariant sources = contentObj.toVariantMap()["source"]; | 111 | QVariant sources = contentObj.toVariantMap()["source"]; |
250 | 73 | Q_FOREACH(QString source, sources.toStringList()) | 112 | Q_FOREACH(QString source, sources.toStringList()) |
251 | 74 | { | 113 | { |
252 | 114 | /* FIXME: we should iterate known types, but there isn't | ||
253 | 115 | * really a good way to do that right now */ | ||
254 | 75 | if (source == "pictures") | 116 | if (source == "pictures") |
255 | 76 | { | 117 | { |
256 | 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)) |
257 | @@ -88,12 +129,11 @@ | |||
258 | 88 | qWarning() << "Failed to install peer for" << source; | 129 | qWarning() << "Failed to install peer for" << source; |
259 | 89 | } | 130 | } |
260 | 90 | } | 131 | } |
263 | 91 | 132 | return true; | |
262 | 92 | QCoreApplication::instance()->quit(); | ||
264 | 93 | } | 133 | } |
265 | 94 | 134 | ||
267 | 95 | void Hook::return_error(QString err) | 135 | bool Hook::return_error(QString err) |
268 | 96 | { | 136 | { |
269 | 97 | qWarning() << "Failed to install peer" << err; | 137 | qWarning() << "Failed to install peer" << err; |
271 | 98 | QCoreApplication::instance()->exit(1); | 138 | return false; |
272 | 99 | } | 139 | } |
273 | 100 | 140 | ||
274 | === modified file 'src/com/ubuntu/content/service/hook.h' | |||
275 | --- src/com/ubuntu/content/service/hook.h 2013-09-11 16:45:23 +0000 | |||
276 | +++ src/com/ubuntu/content/service/hook.h 2013-09-25 03:15:44 +0000 | |||
277 | @@ -20,6 +20,8 @@ | |||
278 | 20 | #define HOOK_H | 20 | #define HOOK_H |
279 | 21 | 21 | ||
280 | 22 | #include <QObject> | 22 | #include <QObject> |
281 | 23 | #include <QFileInfo> | ||
282 | 24 | #include <com/ubuntu/content/peer.h> | ||
283 | 23 | 25 | ||
284 | 24 | #include "registry.h" | 26 | #include "registry.h" |
285 | 25 | 27 | ||
286 | @@ -27,15 +29,16 @@ | |||
287 | 27 | { | 29 | { |
288 | 28 | Q_OBJECT | 30 | Q_OBJECT |
289 | 29 | public: | 31 | public: |
291 | 30 | explicit Hook(QString app_id, QObject *parent = 0); | 32 | explicit Hook(QObject *parent = 0); |
292 | 33 | Hook(com::ubuntu::content::detail::PeerRegistry *registry, QObject *parent = 0); | ||
293 | 31 | 34 | ||
294 | 32 | public slots: | 35 | public slots: |
296 | 33 | void return_error(QString err = ""); | 36 | bool return_error(QString err = ""); |
297 | 34 | void run(); | 37 | void run(); |
298 | 38 | bool add_peer(QFileInfo); | ||
299 | 35 | 39 | ||
300 | 36 | private: | 40 | private: |
303 | 37 | QString app_id; | 41 | com::ubuntu::content::detail::PeerRegistry* registry; |
302 | 38 | Registry* registry; | ||
304 | 39 | 42 | ||
305 | 40 | }; | 43 | }; |
306 | 41 | 44 | ||
307 | 42 | 45 | ||
308 | === modified file 'src/com/ubuntu/content/service/registry.cpp' | |||
309 | --- src/com/ubuntu/content/service/registry.cpp 2013-09-18 14:32:34 +0000 | |||
310 | +++ src/com/ubuntu/content/service/registry.cpp 2013-09-25 03:15:44 +0000 | |||
311 | @@ -48,6 +48,21 @@ | |||
312 | 48 | } | 48 | } |
313 | 49 | } | 49 | } |
314 | 50 | 50 | ||
315 | 51 | void Registry::enumerate_known_peers(const std::function<void(const cuc::Peer&)>&for_each) | ||
316 | 52 | { | ||
317 | 53 | qDebug() << Q_FUNC_INFO; | ||
318 | 54 | |||
319 | 55 | Q_FOREACH (QString type_id, m_peers->keys()) | ||
320 | 56 | { | ||
321 | 57 | qDebug() << Q_FUNC_INFO << type_id; | ||
322 | 58 | Q_FOREACH (QString k, m_peers->get(type_id).toStringList()) | ||
323 | 59 | { | ||
324 | 60 | qDebug() << Q_FUNC_INFO << k; | ||
325 | 61 | for_each(k); | ||
326 | 62 | } | ||
327 | 63 | } | ||
328 | 64 | } | ||
329 | 65 | |||
330 | 51 | bool Registry::install_default_peer_for_type(cuc::Type type, cuc::Peer peer) | 66 | bool Registry::install_default_peer_for_type(cuc::Type type, cuc::Peer peer) |
331 | 52 | { | 67 | { |
332 | 53 | qDebug() << Q_FUNC_INFO << "type:" << type.id() << "peer:" << peer.id(); | 68 | qDebug() << Q_FUNC_INFO << "type:" << type.id() << "peer:" << peer.id(); |
333 | @@ -72,3 +87,19 @@ | |||
334 | 72 | } | 87 | } |
335 | 73 | return false; | 88 | return false; |
336 | 74 | } | 89 | } |
337 | 90 | |||
338 | 91 | bool Registry::remove_peer(cuc::Peer peer) | ||
339 | 92 | { | ||
340 | 93 | qDebug() << Q_FUNC_INFO << "peer:" << peer.id(); | ||
341 | 94 | bool ret = false; | ||
342 | 95 | Q_FOREACH (QString type_id, m_peers->keys()) | ||
343 | 96 | { | ||
344 | 97 | QStringList l = m_peers->get(type_id).toStringList(); | ||
345 | 98 | if (l.contains(peer.id())) | ||
346 | 99 | { | ||
347 | 100 | l.removeAll(peer.id()); | ||
348 | 101 | ret = m_peers->trySet(type_id, QVariant(l)); | ||
349 | 102 | } | ||
350 | 103 | } | ||
351 | 104 | return ret; | ||
352 | 105 | } | ||
353 | 75 | 106 | ||
354 | === modified file 'src/com/ubuntu/content/service/registry.h' | |||
355 | --- src/com/ubuntu/content/service/registry.h 2013-09-18 14:32:50 +0000 | |||
356 | +++ src/com/ubuntu/content/service/registry.h 2013-09-25 03:15:44 +0000 | |||
357 | @@ -36,8 +36,10 @@ | |||
358 | 36 | ~Registry(); | 36 | ~Registry(); |
359 | 37 | cuc::Peer default_peer_for_type(cuc::Type type); | 37 | cuc::Peer default_peer_for_type(cuc::Type type); |
360 | 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); |
361 | 39 | void enumerate_known_peers(const std::function<void(const cuc::Peer&)>& for_each); | ||
362 | 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); |
363 | 40 | bool install_peer_for_type(cuc::Type type, cuc::Peer peer); | 41 | bool install_peer_for_type(cuc::Type type, cuc::Peer peer); |
364 | 42 | bool remove_peer(cuc::Peer peer); | ||
365 | 41 | 43 | ||
366 | 42 | private: | 44 | private: |
367 | 43 | QScopedPointer<QGSettings> m_defaultPeers; | 45 | QScopedPointer<QGSettings> m_defaultPeers; |
368 | 44 | 46 | ||
369 | === modified file 'tests/acceptance-tests/CMakeLists.txt' | |||
370 | --- tests/acceptance-tests/CMakeLists.txt 2013-09-20 16:20:06 +0000 | |||
371 | +++ tests/acceptance-tests/CMakeLists.txt 2013-09-25 03:15:44 +0000 | |||
372 | @@ -52,12 +52,24 @@ | |||
373 | 52 | test_utils.cpp | 52 | test_utils.cpp |
374 | 53 | ) | 53 | ) |
375 | 54 | 54 | ||
376 | 55 | add_executable( | ||
377 | 56 | test_hook | ||
378 | 57 | test_hook.cpp | ||
379 | 58 | ${MOCS} | ||
380 | 59 | ${CMAKE_SOURCE_DIR}/src/com/ubuntu/content/service/hook.cpp | ||
381 | 60 | ${CMAKE_SOURCE_DIR}/src/com/ubuntu/content/service/registry.cpp | ||
382 | 61 | good.json | ||
383 | 62 | bad.json | ||
384 | 63 | ) | ||
385 | 64 | |||
386 | 55 | qt5_use_modules(app_hub_communication_default_peer Core Test) | 65 | qt5_use_modules(app_hub_communication_default_peer Core Test) |
387 | 56 | qt5_use_modules(app_hub_communication_known_peers Core Test) | 66 | qt5_use_modules(app_hub_communication_known_peers Core Test) |
388 | 57 | qt5_use_modules(app_hub_communication_stores Core Test) | 67 | qt5_use_modules(app_hub_communication_stores Core Test) |
389 | 58 | qt5_use_modules(app_hub_communication_transfer Core Test) | 68 | qt5_use_modules(app_hub_communication_transfer Core Test) |
390 | 59 | qt5_use_modules(app_hub_communication_handler Core Test) | 69 | qt5_use_modules(app_hub_communication_handler Core Test) |
391 | 60 | qt5_use_modules(test_utils Core Test) | 70 | qt5_use_modules(test_utils Core Test) |
392 | 71 | qt5_use_modules(test_hook Core Test) | ||
393 | 72 | |||
394 | 61 | target_link_libraries(app_hub_communication_stores content-hub gmock gtest gtest_main) | 73 | target_link_libraries(app_hub_communication_stores content-hub gmock gtest gtest_main) |
395 | 62 | target_link_libraries(app_hub_communication_default_peer content-hub gmock gtest gtest_main) | 74 | target_link_libraries(app_hub_communication_default_peer content-hub gmock gtest gtest_main) |
396 | 63 | target_link_libraries(app_hub_communication_known_peers content-hub gmock gtest gtest_main) | 75 | target_link_libraries(app_hub_communication_known_peers content-hub gmock gtest gtest_main) |
397 | @@ -65,6 +77,7 @@ | |||
398 | 65 | target_link_libraries(app_hub_communication_transfer content-hub gmock gtest gtest_main) | 77 | target_link_libraries(app_hub_communication_transfer content-hub gmock gtest gtest_main) |
399 | 66 | target_link_libraries(app_hub_communication_handler content-hub gmock gtest gtest_main) | 78 | target_link_libraries(app_hub_communication_handler content-hub gmock gtest gtest_main) |
400 | 67 | target_link_libraries(test_utils content-hub gmock gtest gtest_main) | 79 | target_link_libraries(test_utils content-hub gmock gtest gtest_main) |
401 | 80 | target_link_libraries(test_hook content-hub gmock gtest gtest_main ${GSETTINGS_LDFLAGS}) | ||
402 | 68 | 81 | ||
403 | 69 | add_test(app_hub_communication_default_peer app_hub_communication_default_peer) | 82 | add_test(app_hub_communication_default_peer app_hub_communication_default_peer) |
404 | 70 | add_test(app_hub_communication_known_peers app_hub_communication_known_peers) | 83 | add_test(app_hub_communication_known_peers app_hub_communication_known_peers) |
405 | @@ -72,6 +85,15 @@ | |||
406 | 72 | add_test(app_hub_communication_transfer app_hub_communication_transfer) | 85 | add_test(app_hub_communication_transfer app_hub_communication_transfer) |
407 | 73 | add_test(app_hub_communication_handler app_hub_communication_handler) | 86 | add_test(app_hub_communication_handler app_hub_communication_handler) |
408 | 74 | add_test(test_utils test_utils) | 87 | add_test(test_utils test_utils) |
409 | 88 | add_test(test_hook test_hook) | ||
410 | 89 | |||
411 | 90 | set_target_properties( | ||
412 | 91 | test_hook | ||
413 | 92 | PROPERTIES | ||
414 | 93 | AUTOMOC TRUE | ||
415 | 94 | ) | ||
416 | 95 | |||
417 | 96 | file(COPY good.json bad.json DESTINATION .) | ||
418 | 75 | 97 | ||
419 | 76 | add_custom_command( | 98 | add_custom_command( |
420 | 77 | OUTPUT transfer_files | 99 | OUTPUT transfer_files |
421 | 78 | 100 | ||
422 | === modified file 'tests/acceptance-tests/app_hub_communication_default_peer.cpp' | |||
423 | --- tests/acceptance-tests/app_hub_communication_default_peer.cpp 2013-09-06 09:25:19 +0000 | |||
424 | +++ tests/acceptance-tests/app_hub_communication_default_peer.cpp 2013-09-25 03:15:44 +0000 | |||
425 | @@ -67,9 +67,10 @@ | |||
426 | 67 | 67 | ||
427 | 68 | MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t)); | 68 | MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t)); |
428 | 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&)>&)); |
430 | 70 | 70 | MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&)); | |
431 | 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)); |
432 | 72 | MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer)); | 72 | MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer)); |
433 | 73 | MOCK_METHOD1(remove_peer, bool(cuc::Peer)); | ||
434 | 73 | }; | 74 | }; |
435 | 74 | } | 75 | } |
436 | 75 | 76 | ||
437 | 76 | 77 | ||
438 | === modified file 'tests/acceptance-tests/app_hub_communication_handler.cpp' | |||
439 | --- tests/acceptance-tests/app_hub_communication_handler.cpp 2013-09-13 15:23:54 +0000 | |||
440 | +++ tests/acceptance-tests/app_hub_communication_handler.cpp 2013-09-25 03:15:44 +0000 | |||
441 | @@ -65,9 +65,10 @@ | |||
442 | 65 | 65 | ||
443 | 66 | MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t)); | 66 | MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t)); |
444 | 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&)>&)); |
446 | 68 | 68 | MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&)); | |
447 | 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)); |
448 | 70 | MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer)); | 70 | MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer)); |
449 | 71 | MOCK_METHOD1(remove_peer, bool(cuc::Peer)); | ||
450 | 71 | }; | 72 | }; |
451 | 72 | 73 | ||
452 | 73 | struct MockedHandler : public cuc::ImportExportHandler | 74 | struct MockedHandler : public cuc::ImportExportHandler |
453 | 74 | 75 | ||
454 | === modified file 'tests/acceptance-tests/app_hub_communication_known_peers.cpp' | |||
455 | --- tests/acceptance-tests/app_hub_communication_known_peers.cpp 2013-09-18 14:59:01 +0000 | |||
456 | +++ tests/acceptance-tests/app_hub_communication_known_peers.cpp 2013-09-25 03:15:44 +0000 | |||
457 | @@ -66,9 +66,10 @@ | |||
458 | 66 | 66 | ||
459 | 67 | MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t)); | 67 | MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t)); |
460 | 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&)>&)); |
462 | 69 | 69 | MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&)); | |
463 | 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)); |
464 | 71 | MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer)); | 71 | MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer)); |
465 | 72 | MOCK_METHOD1(remove_peer, bool(cuc::Peer)); | ||
466 | 72 | }; | 73 | }; |
467 | 73 | } | 74 | } |
468 | 74 | 75 | ||
469 | 75 | 76 | ||
470 | === modified file 'tests/acceptance-tests/app_hub_communication_stores.cpp' | |||
471 | --- tests/acceptance-tests/app_hub_communication_stores.cpp 2013-09-06 09:25:19 +0000 | |||
472 | +++ tests/acceptance-tests/app_hub_communication_stores.cpp 2013-09-25 03:15:44 +0000 | |||
473 | @@ -66,9 +66,10 @@ | |||
474 | 66 | 66 | ||
475 | 67 | MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t)); | 67 | MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t)); |
476 | 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&)>&)); |
478 | 69 | 69 | MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&)); | |
479 | 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)); |
480 | 71 | MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer)); | 71 | MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer)); |
481 | 72 | MOCK_METHOD1(remove_peer, bool(cuc::Peer)); | ||
482 | 72 | }; | 73 | }; |
483 | 73 | } | 74 | } |
484 | 74 | 75 | ||
485 | 75 | 76 | ||
486 | === modified file 'tests/acceptance-tests/app_hub_communication_transfer.cpp' | |||
487 | --- tests/acceptance-tests/app_hub_communication_transfer.cpp 2013-09-20 15:40:51 +0000 | |||
488 | +++ tests/acceptance-tests/app_hub_communication_transfer.cpp 2013-09-25 03:15:44 +0000 | |||
489 | @@ -68,9 +68,10 @@ | |||
490 | 68 | 68 | ||
491 | 69 | MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t)); | 69 | MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t)); |
492 | 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&)>&)); |
494 | 71 | 71 | MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&)); | |
495 | 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)); |
496 | 73 | MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer)); | 73 | MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer)); |
497 | 74 | MOCK_METHOD1(remove_peer, bool(cuc::Peer)); | ||
498 | 74 | }; | 75 | }; |
499 | 75 | } | 76 | } |
500 | 76 | 77 | ||
501 | 77 | 78 | ||
502 | === added file 'tests/acceptance-tests/bad.json' | |||
503 | --- tests/acceptance-tests/bad.json 1970-01-01 00:00:00 +0000 | |||
504 | +++ tests/acceptance-tests/bad.json 2013-09-25 03:15:44 +0000 | |||
505 | @@ -0,0 +1,6 @@ | |||
506 | 1 | { | ||
507 | 2 | "source": [ | ||
508 | 3 | "pictures", | ||
509 | 4 | "music", | ||
510 | 5 | ] | ||
511 | 6 | } | ||
512 | 0 | 7 | ||
513 | === added file 'tests/acceptance-tests/good.json' | |||
514 | --- tests/acceptance-tests/good.json 1970-01-01 00:00:00 +0000 | |||
515 | +++ tests/acceptance-tests/good.json 2013-09-25 03:15:44 +0000 | |||
516 | @@ -0,0 +1,6 @@ | |||
517 | 1 | { | ||
518 | 2 | "source": [ | ||
519 | 3 | "pictures", | ||
520 | 4 | "music" | ||
521 | 5 | ] | ||
522 | 6 | } | ||
523 | 0 | 7 | ||
524 | === added file 'tests/acceptance-tests/test_hook.cpp' | |||
525 | --- tests/acceptance-tests/test_hook.cpp 1970-01-01 00:00:00 +0000 | |||
526 | +++ tests/acceptance-tests/test_hook.cpp 2013-09-25 03:15:44 +0000 | |||
527 | @@ -0,0 +1,75 @@ | |||
528 | 1 | /* | ||
529 | 2 | * Copyright © 2013 Canonical Ltd. | ||
530 | 3 | * | ||
531 | 4 | * This program is free software: you can redistribute it and/or modify | ||
532 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
533 | 6 | * published by the Free Software Foundation. | ||
534 | 7 | * | ||
535 | 8 | * This program is distributed in the hope that it will be useful, | ||
536 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
537 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
538 | 11 | * GNU Lesser General Public License for more details. | ||
539 | 12 | * | ||
540 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
541 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
542 | 15 | * | ||
543 | 16 | * Authored by: Ken VanDine <ken.vandine@canonical.com> | ||
544 | 17 | */ | ||
545 | 18 | |||
546 | 19 | #include <com/ubuntu/content/peer.h> | ||
547 | 20 | #include <com/ubuntu/content/type.h> | ||
548 | 21 | #include "com/ubuntu/content/detail/peer_registry.h" | ||
549 | 22 | #include "com/ubuntu/content/service/hook.h" | ||
550 | 23 | |||
551 | 24 | #include <gmock/gmock.h> | ||
552 | 25 | #include <gtest/gtest.h> | ||
553 | 26 | |||
554 | 27 | #include <QtTest/QTest> | ||
555 | 28 | |||
556 | 29 | namespace cuc = com::ubuntu::content; | ||
557 | 30 | |||
558 | 31 | void PrintTo(const QString& s, ::std::ostream* os) { | ||
559 | 32 | *os << std::string(qPrintable(s)); | ||
560 | 33 | } | ||
561 | 34 | |||
562 | 35 | namespace | ||
563 | 36 | { | ||
564 | 37 | struct MockedRegistry : public cuc::detail::PeerRegistry | ||
565 | 38 | { | ||
566 | 39 | MockedRegistry() : PeerRegistry() | ||
567 | 40 | { | ||
568 | 41 | using namespace ::testing; | ||
569 | 42 | |||
570 | 43 | ON_CALL(*this, default_peer_for_type(_)).WillByDefault(Return(cuc::Peer::unknown())); | ||
571 | 44 | ON_CALL(*this, install_default_peer_for_type(_,_)).WillByDefault(Return(false)); | ||
572 | 45 | ON_CALL(*this, install_peer_for_type(_,_)).WillByDefault(Return(false)); | ||
573 | 46 | ON_CALL(*this, remove_peer(_)).WillByDefault(Return(false)); | ||
574 | 47 | } | ||
575 | 48 | |||
576 | 49 | MOCK_METHOD1(default_peer_for_type, cuc::Peer(cuc::Type t)); | ||
577 | 50 | MOCK_METHOD2(enumerate_known_peers_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&)); | ||
578 | 51 | |||
579 | 52 | MOCK_METHOD2(install_default_peer_for_type, bool(cuc::Type, cuc::Peer)); | ||
580 | 53 | MOCK_METHOD2(install_peer_for_type, bool(cuc::Type, cuc::Peer)); | ||
581 | 54 | MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&)); | ||
582 | 55 | MOCK_METHOD1(remove_peer, bool(cuc::Peer)); | ||
583 | 56 | }; | ||
584 | 57 | } | ||
585 | 58 | |||
586 | 59 | TEST(Hook, parse_json) | ||
587 | 60 | { | ||
588 | 61 | using namespace ::testing; | ||
589 | 62 | |||
590 | 63 | auto mock = new MockedRegistry{}; | ||
591 | 64 | EXPECT_CALL(*mock, install_peer_for_type(_,_)). | ||
592 | 65 | Times(Exactly(2)). | ||
593 | 66 | WillRepeatedly(Return(true)); | ||
594 | 67 | |||
595 | 68 | QFileInfo f("good.json"); | ||
596 | 69 | Hook *hook = new Hook(mock); | ||
597 | 70 | |||
598 | 71 | EXPECT_TRUE(hook->add_peer(f)); | ||
599 | 72 | f.setFile("bad.json"); | ||
600 | 73 | EXPECT_FALSE(hook->add_peer(f)); | ||
601 | 74 | delete mock; | ||
602 | 75 | } |
FAILED: Continuous integration, rev:53 /code.launchpad .net/~ken- vandine/ content- hub/click_ hook/+merge/ 187341/ +edit-commit- message
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:/
http:// jenkins. qa.ubuntu. com/job/ content- hub-ci/ 87/ jenkins. qa.ubuntu. com/job/ content- hub-saucy- amd64-ci/ 86/console jenkins. qa.ubuntu. com/job/ content- hub-saucy- armhf-ci/ 86/console jenkins. qa.ubuntu. com/job/ content- hub-saucy- i386-ci/ 86/console
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ content- hub-ci/ 87/rebuild
http://