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

Subscribers

People subscribed via source and target branches