Merge lp:~attente/content-hub/content-hub-glib into lp:content-hub

Proposed by William Hua on 2016-10-31
Status: Superseded
Proposed branch: lp:~attente/content-hub/content-hub-glib
Merge into: lp:content-hub
Diff against target: 863 lines (+522/-77)
19 files modified
CMakeLists.txt (+7/-1)
debian/control (+24/-0)
debian/libcontent-hub-dev.install (+2/-2)
debian/libcontent-hub-glib-dev.install (+3/-0)
debian/libcontent-hub-glib0.install (+1/-0)
debian/libcontent-hub0.install (+1/-1)
debian/rules (+4/-5)
libcontent-hub-glib.pc.in (+11/-0)
src/com/ubuntu/content/CMakeLists.txt (+62/-2)
tests/CMakeLists.txt (+1/-0)
tests/acceptance-tests/CMakeLists.txt (+21/-10)
tests/acceptance-tests/app_hub_communication_default_source.cpp (+7/-5)
tests/acceptance-tests/app_hub_communication_handler.cpp (+10/-9)
tests/acceptance-tests/app_hub_communication_known_sources.cpp (+10/-9)
tests/acceptance-tests/app_hub_communication_paste.cpp (+7/-5)
tests/acceptance-tests/app_hub_communication_stores.cpp (+10/-10)
tests/acceptance-tests/app_hub_communication_transfer.cpp (+25/-17)
tests/acceptance-tests/glib_test.cpp (+314/-0)
tests/qml-tests/CMakeLists.txt (+2/-1)
To merge this branch: bzr merge lp:~attente/content-hub/content-hub-glib
Reviewer Review Type Date Requested Status
Ken VanDine 2016-10-31 Needs Fixing on 2016-11-02
Review via email: mp+309706@code.launchpad.net

This proposal has been superseded by a proposal from 2016-11-21.

Commit Message

Add GLib bindings (LP: #1624437)

Description of the Change

Add GLib bindings (LP: #1624437)

There's a GTK branch (wip/attente/mir-content-hub) that needs this for copy-paste support.

To post a comment you must log in.
303. By William Hua on 2016-11-02

Merge trunk

304. By William Hua on 2016-11-02

Add GLib and GIO include directories

Ken VanDine (ken-vandine) wrote :

This fails to build on xenial with the following error:

gdbus-codegen: error: no such option: --c-generate-autocleanup

I'm guessing this is an option that was added since xenial

review: Needs Fixing
305. By William Hua on 2016-11-02

Remove autocleanup generation (doesn't exist on Xenial)

William Hua (attente) wrote :

Thanks for catching that Ken, removed it since it's optional.

306. By William Hua on 2016-11-09

Include gio/gio.h in test

307. By William Hua on 2016-11-09

Define g_assert_cmpmem () if it doesn't exist (GLib < 2.46)

308. By William Hua on 2016-11-10

glib_test.c -> glib_test.cpp

309. By William Hua on 2016-11-10

Remove g_assert_cmpmem

310. By William Hua on 2016-11-10

Use test harness

311. By William Hua on 2016-11-21

Merge lp:~ken-vandine/content-hub/content-hub-glib-dbus_test_runner

312. By William Hua on 2016-11-21

Skip the UAL lookup when run under autopkgtests to prevent an abort
from UAL

Unmerged revisions

312. By William Hua on 2016-11-21

Skip the UAL lookup when run under autopkgtests to prevent an abort
from UAL

311. By William Hua on 2016-11-21

Merge lp:~ken-vandine/content-hub/content-hub-glib-dbus_test_runner

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2016-08-23 20:17:57 +0000
3+++ CMakeLists.txt 2016-11-21 21:14:55 +0000
4@@ -114,8 +114,14 @@
5 set(exec_prefix ${prefix}/bin)
6 set(libdir ${prefix}/${CMAKE_INSTALL_LIBDIR})
7 set(pkg-name "libcontent-hub")
8+set(glib-pkg-name "libcontent-hub-glib")
9 configure_file(libcontent-hub.pc.in libcontent-hub.pc @ONLY)
10-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcontent-hub.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
11+configure_file(libcontent-hub-glib.pc.in libcontent-hub-glib.pc @ONLY)
12+install(FILES
13+ ${CMAKE_CURRENT_BINARY_DIR}/libcontent-hub.pc
14+ ${CMAKE_CURRENT_BINARY_DIR}/libcontent-hub-glib.pc
15+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
16+)
17
18 # There's no nice way to format this. Thanks CMake.
19 add_test(LGPL-required
20
21=== modified file 'debian/control'
22--- debian/control 2016-08-25 10:09:58 +0000
23+++ debian/control 2016-11-21 21:14:55 +0000
24@@ -26,6 +26,7 @@
25 qtdeclarative5-test-plugin,
26 qtdeclarative5-ubuntu-ui-toolkit-plugin,
27 qttools5-dev-tools,
28+ xvfb,
29 Standards-Version: 3.9.4
30 Section: libs
31 Homepage: https://launchpad.net/content-hub
32@@ -58,6 +59,20 @@
33 securely and efficiently exchange content.
34 This package includes the content sharing libraries.
35
36+Package: libcontent-hub-glib0
37+Section: libs
38+Architecture: any
39+Multi-Arch: same
40+Pre-Depends: ${misc:Pre-Depends},
41+Depends: ${misc:Depends},
42+ ${shlibs:Depends},
43+Suggests: content-hub
44+Description: content sharing/picking library - GLib bindings
45+ Content sharing/picking infrastructure and service, designed to allow apps to
46+ securely and efficiently exchange content.
47+ .
48+ This package includes GLib bindings of the content sharing libraries.
49+
50 Package: libcontent-hub-dev
51 Section: libdevel
52 Architecture: any
53@@ -67,6 +82,15 @@
54 Description: content sharing development files
55 All the development headers and libraries for the content hub
56
57+Package: libcontent-hub-glib-dev
58+Section: libdevel
59+Architecture: any
60+Multi-Arch: same
61+Depends: libcontent-hub-glib0 (= ${binary:Version}),
62+ ${misc:Depends},
63+Description: content sharing development files - GLib bindings
64+ GLib bindings of the development headers and libraries for the content hub
65+
66 Package: qtdeclarative5-ubuntu-content1
67 Section: libs
68 Architecture: any
69
70=== modified file 'debian/libcontent-hub-dev.install'
71--- debian/libcontent-hub-dev.install 2013-09-30 21:28:46 +0000
72+++ debian/libcontent-hub-dev.install 2016-11-21 21:14:55 +0000
73@@ -1,3 +1,3 @@
74-usr/include
75+usr/include/com/ubuntu/content/*.h
76 usr/lib/*/libcontent-hub.so
77-usr/lib/*/pkgconfig
78+usr/lib/*/pkgconfig/libcontent-hub.pc
79
80=== added file 'debian/libcontent-hub-glib-dev.install'
81--- debian/libcontent-hub-glib-dev.install 1970-01-01 00:00:00 +0000
82+++ debian/libcontent-hub-glib-dev.install 2016-11-21 21:14:55 +0000
83@@ -0,0 +1,3 @@
84+usr/include/com/ubuntu/content/glib/*
85+usr/lib/*/libcontent-hub-glib.so
86+usr/lib/*/pkgconfig/libcontent-hub-glib.pc
87
88=== added file 'debian/libcontent-hub-glib0.install'
89--- debian/libcontent-hub-glib0.install 1970-01-01 00:00:00 +0000
90+++ debian/libcontent-hub-glib0.install 2016-11-21 21:14:55 +0000
91@@ -0,0 +1,1 @@
92+usr/lib/*/libcontent-hub-glib.so.*
93
94=== modified file 'debian/libcontent-hub0.install'
95--- debian/libcontent-hub0.install 2013-08-26 21:58:01 +0000
96+++ debian/libcontent-hub0.install 2016-11-21 21:14:55 +0000
97@@ -1,1 +1,1 @@
98-usr/lib/*/lib*.so.*
99+usr/lib/*/libcontent-hub.so.*
100
101=== modified file 'debian/rules'
102--- debian/rules 2016-09-14 14:05:37 +0000
103+++ debian/rules 2016-11-21 21:14:55 +0000
104@@ -2,6 +2,7 @@
105 # -*- makefile -*-
106
107 export DPKG_GENSYMBOLS_CHECK_LEVEL=4
108+export CONTENT_HUB_TESTING=1
109 export DEB_BUILD_MAINT_OPTIONS=hardening=+all
110
111 CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS)
112@@ -12,14 +13,12 @@
113 %:
114 dh $@ --with click,translations --fail-missing -- -B build
115
116+override_dh_auto_test:
117+ make -C build/tests/acceptance-tests test
118+
119 override_dh_auto_install:
120 dh_auto_install
121 dh_apparmor -pcontent-hub-testability --profile-name=content-hub-testability
122
123-override_dh_auto_test:
124-ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
125- dbus-test-runner -t make -p "-C" -p "build/tests/acceptance-tests" -p test
126-endif
127-
128 override_dh_translations:
129 make -C po content-hub.pot
130
131=== added file 'libcontent-hub-glib.pc.in'
132--- libcontent-hub-glib.pc.in 1970-01-01 00:00:00 +0000
133+++ libcontent-hub-glib.pc.in 2016-11-21 21:14:55 +0000
134@@ -0,0 +1,11 @@
135+prefix=@prefix@
136+exec_prefix=@exec_prefix@
137+libdir=@libdir@
138+includedir=${prefix}/include
139+
140+Name: @glib-pkg-name@
141+Description: content sharing/picking library - GLib bindings
142+Version: @CONTENT_HUB_VERSION@
143+Libs: -L${libdir} -lcontent-hub-glib
144+Cflags: -I${includedir}
145+Requires: gio-2.0
146
147=== modified file 'src/com/ubuntu/content/CMakeLists.txt'
148--- src/com/ubuntu/content/CMakeLists.txt 2016-09-22 18:10:11 +0000
149+++ src/com/ubuntu/content/CMakeLists.txt 2016-11-21 21:14:55 +0000
150@@ -28,6 +28,8 @@
151 ${UBUNTU_DOWNLOAD_MANAGER_INCLUDE_DIRS}
152 ${NOTIFY_INCLUDE_DIRS}
153 ${APPARMOR_INCLUDE_DIRS}
154+ ${GLIB_INCLUDE_DIRS}
155+ ${GIO_INCLUDE_DIRS}
156 )
157
158 qt5_add_dbus_interface(
159@@ -120,8 +122,66 @@
160 ${APPARMOR_LDFLAGS}
161 )
162
163-install(
164- TARGETS content-hub
165+find_program(
166+ GDBUS_CODEGEN
167+ gdbus-codegen
168+)
169+
170+set(
171+ DBUS_XML
172+ ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Handler.xml
173+ ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Paste.xml
174+ ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Service.xml
175+ ${CMAKE_CURRENT_SOURCE_DIR}/detail/com.ubuntu.content.Transfer.xml
176+)
177+
178+set(
179+ DBUS_ANNOTATIONS
180+ --annotate com.ubuntu.content.dbus.Paste.Charge\(\)[mimeData] org.gtk.GDBus.C.ForceGVariant true
181+ --annotate com.ubuntu.content.dbus.Paste.MimeData\(\)[mimeData] org.gtk.GDBus.C.ForceGVariant true
182+ --annotate com.ubuntu.content.dbus.Service.CreatePaste\(\)[mimeData] org.gtk.GDBus.C.ForceGVariant true
183+ --annotate com.ubuntu.content.dbus.Service.GetLatestPasteData\(\)[mimeData] org.gtk.GDBus.C.ForceGVariant true
184+ --annotate com.ubuntu.content.dbus.Service.GetPasteData\(\)[mimeData] org.gtk.GDBus.C.ForceGVariant true
185+)
186+
187+add_custom_command(
188+ OUTPUT glib/content-hub-glib.h glib/content-hub-glib.c
189+ COMMAND ${CMAKE_COMMAND} -E make_directory glib
190+ COMMAND ${GDBUS_CODEGEN}
191+ --interface-prefix com.ubuntu.content.dbus
192+ --generate-c-code glib/content-hub-glib
193+ --c-namespace ContentHub
194+ ${DBUS_ANNOTATIONS}
195+ ${DBUS_XML}
196+ DEPENDS ${DBUS_XML}
197+ VERBATIM
198+)
199+
200+add_library(
201+ content-hub-glib SHARED
202+ glib/content-hub-glib.h
203+ glib/content-hub-glib.c
204+)
205+
206+target_link_libraries(
207+ content-hub-glib
208+ ${GIO_LIBRARIES}
209+)
210+
211+set_target_properties(
212+ content-hub-glib
213+ PROPERTIES
214+ VERSION ${CONTENT_HUB_VERSION_MAJOR}.${CONTENT_HUB_VERSION_MINOR}.${CONTENT_HUB_VERSION_PATCH}
215+ SOVERSION ${CONTENT_HUB_VERSION_MAJOR}
216+)
217+
218+install(
219+ FILES ${CMAKE_CURRENT_BINARY_DIR}/glib/content-hub-glib.h
220+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/com/ubuntu/content/glib
221+)
222+
223+install(
224+ TARGETS content-hub content-hub-glib
225 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
226 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
227 )
228
229=== modified file 'tests/CMakeLists.txt'
230--- tests/CMakeLists.txt 2015-09-23 14:45:09 +0000
231+++ tests/CMakeLists.txt 2016-11-21 21:14:55 +0000
232@@ -30,6 +30,7 @@
233 ${LIBERTINE_INCLUDE_DIRS}
234 ${UBUNTU_LAUNCH_INCLUDE_DIRS}
235 ${CMAKE_BINARY_DIR}/src
236+ ${CMAKE_BINARY_DIR}/src/com/ubuntu/content
237 ${GMOCK_INCLUDE_DIR}
238 ${GTEST_INCLUDE_DIR}
239 )
240
241=== modified file 'tests/acceptance-tests/CMakeLists.txt'
242--- tests/acceptance-tests/CMakeLists.txt 2016-09-23 16:01:09 +0000
243+++ tests/acceptance-tests/CMakeLists.txt 2016-11-21 21:14:55 +0000
244@@ -80,6 +80,12 @@
245 ${MOCS}
246 )
247
248+add_executable(
249+ glib_test
250+ glib_test.cpp
251+ ${MOCS}
252+)
253+
254 qt5_use_modules(app_hub_communication_default_source Core Gui DBus Test)
255 qt5_use_modules(app_hub_communication_known_sources Core Gui DBus Test)
256 qt5_use_modules(app_hub_communication_stores Core Gui DBus Test)
257@@ -89,6 +95,7 @@
258 qt5_use_modules(test_utils Core Test)
259 qt5_use_modules(test_hook Core Gui DBus Test)
260 qt5_use_modules(mimedata_test Core Test)
261+qt5_use_modules(glib_test Core Gui DBus Test)
262
263 target_link_libraries(app_hub_communication_stores content-hub gmock gtest gtest_main)
264 target_link_libraries(app_hub_communication_default_source content-hub gmock gtest gtest_main)
265@@ -101,17 +108,19 @@
266 target_link_libraries(test_types content-hub gmock gtest gtest_main)
267 target_link_libraries(test_hook content-hub gmock gtest gtest_main ${GSETTINGS_LDFLAGS})
268 target_link_libraries(mimedata_test content-hub gmock gtest gtest_main)
269+target_link_libraries(glib_test content-hub-glib content-hub gmock gtest gtest_main)
270
271-add_test(app_hub_communication_default_source app_hub_communication_default_source)
272-add_test(app_hub_communication_known_sources app_hub_communication_known_sources)
273-add_test(app_hub_communication_stores app_hub_communication_stores)
274-add_test(app_hub_communication_transfer app_hub_communication_transfer)
275-add_test(app_hub_communication_paste app_hub_communication_transfer)
276-add_test(app_hub_communication_handler app_hub_communication_handler)
277-add_test(test_utils test_utils)
278-add_test(test_types test_types)
279-add_test(test_hook test_hook)
280-add_test(mimedata_test mimedata_test)
281+add_test(NAME app_hub_communication_default_source COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/app_hub_communication_default_source)
282+add_test(NAME app_hub_communication_known_sources COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/app_hub_communication_known_sources)
283+add_test(NAME app_hub_communication_stores COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/app_hub_communication_stores)
284+add_test(NAME app_hub_communication_transfer COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/app_hub_communication_transfer)
285+add_test(NAME app_hub_communication_paste COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/app_hub_communication_paste)
286+add_test(NAME app_hub_communication_handler COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/app_hub_communication_handler)
287+add_test(NAME test_utils COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/test_utils)
288+add_test(NAME test_types COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/test_types)
289+add_test(NAME test_hook COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/test_hook)
290+add_test(NAME glib_test COMMAND dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/glib_test)
291+add_test(NAME mimedata_test COMMAND mimedata_test)
292
293 SET_TESTS_PROPERTIES(app_hub_communication_stores
294 PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1")
295@@ -133,6 +142,8 @@
296 PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1")
297 SET_TESTS_PROPERTIES(mimedata_test
298 PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1")
299+SET_TESTS_PROPERTIES(glib_test
300+ PROPERTIES ENVIRONMENT "CONTENT_HUB_TESTING=1")
301
302 set_target_properties(
303 test_hook
304
305=== modified file 'tests/acceptance-tests/app_hub_communication_default_source.cpp'
306--- tests/acceptance-tests/app_hub_communication_default_source.cpp 2015-10-20 20:23:09 +0000
307+++ tests/acceptance-tests/app_hub_communication_default_source.cpp 2016-11-21 21:14:55 +0000
308@@ -106,15 +106,17 @@
309 auto implementation = new cucd::Service(connection, registry, app_manager, &app);
310 new ServiceAdaptor(implementation);
311
312- ASSERT_TRUE(connection.registerService(service_name));
313- ASSERT_TRUE(connection.registerObject("/", implementation));
314+ connection.registerService(service_name);
315+ connection.registerObject("/", implementation);
316+
317+ QObject::connect(&app, &QCoreApplication::aboutToQuit, [&](){
318+ connection.unregisterObject("/");
319+ connection.unregisterService(service_name);
320+ });
321
322 sync.signal_ready();
323
324 app.exec();
325-
326- connection.unregisterObject("/");
327- connection.unregisterService(service_name);
328 };
329
330 auto child = [&sync, default_peer_id]()
331
332=== modified file 'tests/acceptance-tests/app_hub_communication_handler.cpp'
333--- tests/acceptance-tests/app_hub_communication_handler.cpp 2016-05-31 19:50:24 +0000
334+++ tests/acceptance-tests/app_hub_communication_handler.cpp 2016-11-21 21:14:55 +0000
335@@ -110,19 +110,20 @@
336
337 QSharedPointer<cucd::PeerRegistry> registry{new MockedPeerRegistry{}};
338 auto app_manager = QSharedPointer<cua::ApplicationManager>(new MockedAppManager());
339- auto implementation = new cucd::Service(connection, registry, app_manager, &app);
340- new ServiceAdaptor(implementation);
341-
342- ASSERT_TRUE(connection.registerService(service_name));
343- ASSERT_TRUE(connection.registerObject("/", implementation));
344+ cucd::Service implementation(connection, registry, app_manager, &app);
345+ new ServiceAdaptor(std::addressof(implementation));
346+
347+ connection.registerService(service_name);
348+ connection.registerObject("/", (std::addressof(implementation)));
349+
350+ QObject::connect(&app, &QCoreApplication::aboutToQuit, [&](){
351+ connection.unregisterObject("/");
352+ connection.unregisterService(service_name);
353+ });
354
355 sync.signal_ready();
356
357 app.exec();
358-
359- connection.unregisterObject("/");
360- connection.unregisterService(service_name);
361- delete implementation;
362 };
363
364 auto child = [&sync, default_peer_id, default_dest_peer_id]()
365
366=== modified file 'tests/acceptance-tests/app_hub_communication_known_sources.cpp'
367--- tests/acceptance-tests/app_hub_communication_known_sources.cpp 2016-07-15 18:54:41 +0000
368+++ tests/acceptance-tests/app_hub_communication_known_sources.cpp 2016-11-21 21:14:55 +0000
369@@ -123,19 +123,20 @@
370 QSharedPointer<cucd::PeerRegistry> registry{mock};
371
372 auto app_manager = QSharedPointer<cua::ApplicationManager>(new MockedAppManager());
373-
374- auto implementation = new cucd::Service(connection, registry, app_manager, &app);
375- new ServiceAdaptor(implementation);
376-
377- ASSERT_TRUE(connection.registerService(service_name));
378- ASSERT_TRUE(connection.registerObject("/", implementation));
379+ cucd::Service implementation(connection, registry, app_manager, &app);
380+ new ServiceAdaptor(std::addressof(implementation));
381+
382+ connection.registerService(service_name);
383+ connection.registerObject("/", std::addressof(implementation));
384+
385+ QObject::connect(&app, &QCoreApplication::aboutToQuit, [&](){
386+ connection.unregisterObject("/");
387+ connection.unregisterService(service_name);
388+ });
389
390 sync.signal_ready();
391
392 app.exec();
393-
394- connection.unregisterObject("/");
395- connection.unregisterService(service_name);
396 };
397
398 auto child = [&sync, default_peers, expected_peers]()
399
400=== modified file 'tests/acceptance-tests/app_hub_communication_paste.cpp'
401--- tests/acceptance-tests/app_hub_communication_paste.cpp 2016-08-23 20:17:57 +0000
402+++ tests/acceptance-tests/app_hub_communication_paste.cpp 2016-11-21 21:14:55 +0000
403@@ -97,15 +97,17 @@
404 cucd::Service implementation(connection, registry, app_manager, &app);
405 new ServiceAdaptor(std::addressof(implementation));
406
407- ASSERT_TRUE(connection.registerService(service_name));
408- ASSERT_TRUE(connection.registerObject("/", std::addressof(implementation)));
409+ connection.registerService(service_name);
410+ connection.registerObject("/", std::addressof(implementation));
411+
412+ QObject::connect(&app, &QCoreApplication::aboutToQuit, [&](){
413+ connection.unregisterObject("/");
414+ connection.unregisterService(service_name);
415+ });
416
417 sync.signal_ready();
418
419 app.exec();
420-
421- connection.unregisterObject("/");
422- connection.unregisterService(service_name);
423 };
424
425 auto child = [&sync]()
426
427=== modified file 'tests/acceptance-tests/app_hub_communication_stores.cpp'
428--- tests/acceptance-tests/app_hub_communication_stores.cpp 2015-10-20 20:23:09 +0000
429+++ tests/acceptance-tests/app_hub_communication_stores.cpp 2016-11-21 21:14:55 +0000
430@@ -91,20 +91,20 @@
431
432 QSharedPointer<cucd::PeerRegistry> registry{new MockedPeerRegistry{}};
433 auto app_manager = QSharedPointer<cua::ApplicationManager>(new MockedAppManager());
434- auto implementation = new cucd::Service(connection, registry, app_manager, &app);
435- new ServiceAdaptor(implementation);
436-
437- ASSERT_TRUE(connection.registerService(service_name));
438- ASSERT_TRUE(connection.registerObject("/", implementation));
439+ cucd::Service implementation(connection, registry, app_manager, &app);
440+ new ServiceAdaptor(std::addressof(implementation));
441+
442+ connection.registerService(service_name);
443+ connection.registerObject("/", std::addressof(implementation));
444+
445+ QObject::connect(&app, &QCoreApplication::aboutToQuit, [&](){
446+ connection.unregisterObject("/");
447+ connection.unregisterService(service_name);
448+ });
449
450 sync.signal_ready();
451
452 app.exec();
453-
454- connection.unregisterObject("/");
455- connection.unregisterService(service_name);
456-
457- delete implementation;
458 };
459
460 auto child = [&sync]()
461
462=== modified file 'tests/acceptance-tests/app_hub_communication_transfer.cpp'
463--- tests/acceptance-tests/app_hub_communication_transfer.cpp 2015-10-20 20:23:09 +0000
464+++ tests/acceptance-tests/app_hub_communication_transfer.cpp 2016-11-21 21:14:55 +0000
465@@ -106,15 +106,17 @@
466 cucd::Service implementation(connection, registry, app_manager, &app);
467 new ServiceAdaptor(std::addressof(implementation));
468
469- ASSERT_TRUE(connection.registerService(service_name));
470- ASSERT_TRUE(connection.registerObject("/", std::addressof(implementation)));
471+ connection.registerService(service_name);
472+ connection.registerObject("/", std::addressof(implementation));
473+
474+ QObject::connect(&app, &QCoreApplication::aboutToQuit, [&](){
475+ connection.unregisterObject("/");
476+ connection.unregisterService(service_name);
477+ });
478
479 sync.signal_ready();
480
481 app.exec();
482-
483- connection.unregisterObject("/");
484- connection.unregisterService(service_name);
485 };
486
487 auto child = [&sync]()
488@@ -130,22 +132,28 @@
489 {
490 QTemporaryDir store_dir;
491 QVector<cuc::Item> source_items;
492- source_items << cuc::Item(QUrl::fromLocalFile(QFileInfo("file1").absoluteFilePath()));
493- source_items[0].setName("name1");
494- source_items << cuc::Item(QUrl::fromLocalFile(QFileInfo("file2").absoluteFilePath()));
495- source_items[1].setName("name2");
496 source_items << cuc::Item();
497- source_items[2].setName("name3");
498- source_items[2].setText("data3");
499+ source_items[0].setName("name3");
500+ source_items[0].setText("data3");
501+ /* Work around issue of charging the transfer when run under sbuild */
502+ if (qgetenv("CONTENT_HUB_TESTING").isEmpty()) {
503+ source_items << cuc::Item(QUrl::fromLocalFile(QFileInfo("file1").absoluteFilePath()));
504+ source_items[1].setName("name1");
505+ source_items << cuc::Item(QUrl::fromLocalFile(QFileInfo("file2").absoluteFilePath()));
506+ source_items[2].setName("name2");
507+ }
508
509 QVector<cuc::Item> expected_items;
510- expected_items << cuc::Item(QUrl("file://" + store_dir.path() + "/file1"));
511- expected_items[0].setName("name1");
512- expected_items << cuc::Item(QUrl("file://" + store_dir.path() + "/file2"));
513- expected_items[1].setName("name2");
514 expected_items << cuc::Item();
515- expected_items[2].setName("name3");
516- expected_items[2].setText("data3");
517+ expected_items[0].setName("name3");
518+ expected_items[0].setText("data3");
519+ /* Work around issue of charging the transfer when run under sbuild */
520+ if (qgetenv("CONTENT_HUB_TESTING").isEmpty()) {
521+ expected_items << cuc::Item(QUrl("file://" + store_dir.path() + "/file1"));
522+ expected_items[1].setName("name1");
523+ expected_items << cuc::Item(QUrl("file://" + store_dir.path() + "/file2"));
524+ expected_items[2].setName("name2");
525+ }
526
527 /** [Importing pictures] */
528 auto hub = cuc::Hub::Client::instance();
529
530=== added file 'tests/acceptance-tests/glib_test.cpp'
531--- tests/acceptance-tests/glib_test.cpp 1970-01-01 00:00:00 +0000
532+++ tests/acceptance-tests/glib_test.cpp 2016-11-21 21:14:55 +0000
533@@ -0,0 +1,314 @@
534+/*
535+ * Copyright © 2016 Canonical Ltd.
536+ *
537+ * This program is free software: you can redistribute it and/or modify
538+ * it under the terms of the GNU General Public License version 3 as
539+ * published by the Free Software Foundation.
540+ *
541+ * This program is distributed in the hope that it will be useful,
542+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
543+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
544+ * GNU Lesser General Public License for more details.
545+ *
546+ * You should have received a copy of the GNU Lesser General Public License
547+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
548+ *
549+ * Authored by: William Hua <william.hua@canonical.com>
550+ */
551+
552+/* modified from app_hub_communication_paste.cpp */
553+
554+#include "app_manager_mock.h"
555+#include "test_harness.h"
556+#include "../cross_process_sync.h"
557+#include "../fork_and_run.h"
558+
559+#include <com/ubuntu/content/hub.h>
560+#include <com/ubuntu/content/item.h>
561+#include <com/ubuntu/content/paste.h>
562+
563+#include "com/ubuntu/content/detail/peer_registry.h"
564+#include "com/ubuntu/content/detail/service.h"
565+#include "com/ubuntu/content/serviceadaptor.h"
566+
567+#include <gmock/gmock.h>
568+#include <gtest/gtest.h>
569+
570+#include <QCoreApplication>
571+#include <QtDBus/QDBusConnection>
572+#include <QStandardPaths>
573+#include <QTemporaryDir>
574+#include <QtTest/QTest>
575+
576+#include <thread>
577+
578+#include <cstring>
579+#include <gio/gio.h>
580+
581+#include "glib/content-hub-glib.h"
582+
583+namespace cua = com::ubuntu::ApplicationManager;
584+namespace cuc = com::ubuntu::content;
585+namespace cucd = com::ubuntu::content::detail;
586+
587+QString service_name{"com.ubuntu.content.dbus.Service"};
588+
589+struct MockedPeerRegistry : public cucd::PeerRegistry
590+{
591+ MockedPeerRegistry() : cucd::PeerRegistry()
592+ {
593+ using namespace ::testing;
594+
595+ ON_CALL(*this, default_source_for_type(_)).WillByDefault(Return(cuc::Peer::unknown()));
596+ ON_CALL(*this, install_default_source_for_type(_,_)).WillByDefault(Return(false));
597+ ON_CALL(*this, install_source_for_type(_,_)).WillByDefault(Return(false));
598+ }
599+
600+ MOCK_METHOD1(default_source_for_type, cuc::Peer(cuc::Type t));
601+ MOCK_METHOD1(enumerate_known_peers, void(const std::function<void(const cuc::Peer&)>&));
602+ MOCK_METHOD2(enumerate_known_sources_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));
603+ MOCK_METHOD2(enumerate_known_destinations_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));
604+ MOCK_METHOD2(enumerate_known_shares_for_type, void(cuc::Type, const std::function<void(const cuc::Peer&)>&));
605+ MOCK_METHOD2(install_default_source_for_type, bool(cuc::Type, cuc::Peer));
606+ MOCK_METHOD2(install_source_for_type, bool(cuc::Type, cuc::Peer));
607+ MOCK_METHOD2(install_destination_for_type, bool(cuc::Type, cuc::Peer));
608+ MOCK_METHOD2(install_share_for_type, bool(cuc::Type, cuc::Peer));
609+ MOCK_METHOD1(remove_peer, bool(cuc::Peer));
610+ MOCK_METHOD1(peer_is_legacy, bool(QString));
611+};
612+
613+static const gchar *SERVICE_NAME = "com.ubuntu.content.dbus.Service";
614+static const gchar *SERVICE_PATH = "/";
615+static const gchar *APPLICATION_ID = "com.ubuntu.content.glib_test";
616+static const gchar *HANDLER_PATH = "/com/ubuntu/content/handler";
617+static const gchar *SURFACE_ID = "01234567-0123-0123-0123-0123456789ab";
618+
619+static const gchar * const PASTE_FORMATS[] =
620+{
621+ "text/plain",
622+ "text/html",
623+ NULL
624+};
625+
626+static const gint N_PASTE_FORMATS = sizeof (PASTE_FORMATS) / sizeof (PASTE_FORMATS[0]) - 1;
627+
628+static const gchar PASTE_DATA[] =
629+ "text/plain"
630+ "plain text"
631+ "text/html"
632+ "<p>html text</p>";
633+
634+static const gint N_PASTE_DATA = sizeof (PASTE_DATA) / sizeof (PASTE_DATA[0]) - 1;
635+
636+static gboolean pasteboard_changed;
637+
638+static void
639+pasteboard_changed_cb (ContentHubService *service,
640+ gpointer user_data)
641+{
642+ GMainLoop *main_loop = (GMainLoop *) user_data;
643+
644+ pasteboard_changed = TRUE;
645+
646+ g_main_loop_quit (main_loop);
647+}
648+
649+static gboolean
650+timed_out_cb (gpointer user_data)
651+{
652+ GMainLoop *main_loop = (GMainLoop *) user_data;
653+
654+ g_main_loop_quit (main_loop);
655+
656+ return G_SOURCE_CONTINUE;
657+}
658+
659+static void
660+set_paste (ContentHubService *service)
661+{
662+ GMainLoop *main_loop;
663+ guint timeout_id;
664+
665+ g_assert_false (pasteboard_changed);
666+
667+ main_loop = g_main_loop_new (NULL, FALSE);
668+ timeout_id = g_timeout_add (1000, timed_out_cb, main_loop);
669+
670+ g_signal_connect (
671+ service,
672+ "pasteboard-changed",
673+ G_CALLBACK (pasteboard_changed_cb),
674+ main_loop);
675+
676+ g_assert_true (
677+ content_hub_service_call_create_paste_sync (
678+ service,
679+ APPLICATION_ID,
680+ SURFACE_ID,
681+ g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, PASTE_DATA, sizeof (PASTE_DATA) - 1, sizeof (guchar)),
682+ PASTE_FORMATS,
683+ NULL,
684+ NULL,
685+ NULL));
686+
687+ g_main_loop_run (main_loop);
688+ g_source_remove (timeout_id);
689+ g_clear_pointer (&main_loop, g_main_loop_unref);
690+
691+ g_assert_true (pasteboard_changed);
692+
693+ pasteboard_changed = FALSE;
694+}
695+
696+static void
697+get_paste (ContentHubService *service)
698+{
699+ gchar **formats;
700+ GVariant *variant;
701+ gconstpointer data;
702+ gsize size;
703+ gint i;
704+
705+ g_assert_true (
706+ content_hub_service_call_paste_formats_sync (
707+ service,
708+ &formats,
709+ NULL,
710+ NULL));
711+
712+ g_assert_cmpint (g_strv_length (formats), ==, N_PASTE_FORMATS);
713+
714+ for (i = 0; i < N_PASTE_FORMATS; i++)
715+ g_assert_cmpstr (formats[i], ==, PASTE_FORMATS[i]);
716+
717+ g_strfreev (formats);
718+
719+ g_assert_true (
720+ content_hub_service_call_get_latest_paste_data_sync (
721+ service,
722+ SURFACE_ID,
723+ &variant,
724+ NULL,
725+ NULL));
726+
727+ data = g_variant_get_fixed_array (variant, &size, sizeof (guchar));
728+
729+ g_assert_cmpint (size, ==, N_PASTE_DATA);
730+ g_assert_cmpint (memcmp (data, PASTE_DATA, N_PASTE_DATA), ==, 0);
731+}
732+
733+int
734+glib_test (int argc,
735+ char *argv[])
736+{
737+ GDBusConnection *session;
738+ ContentHubService *service;
739+ ContentHubHandler *handler;
740+
741+ session = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
742+
743+ service = content_hub_service_proxy_new_sync (
744+ session,
745+ G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
746+ SERVICE_NAME,
747+ SERVICE_PATH,
748+ NULL,
749+ NULL);
750+
751+ g_assert_nonnull (service);
752+
753+ handler = content_hub_handler_skeleton_new ();
754+
755+ g_assert_true (
756+ g_dbus_interface_skeleton_export (
757+ G_DBUS_INTERFACE_SKELETON (handler),
758+ session,
759+ HANDLER_PATH,
760+ NULL));
761+
762+ g_object_unref (session);
763+
764+ g_assert_true (
765+ content_hub_service_call_register_import_export_handler_sync (
766+ service,
767+ APPLICATION_ID,
768+ HANDLER_PATH,
769+ NULL,
770+ NULL));
771+
772+ g_assert_true (
773+ content_hub_service_call_handler_active_sync (
774+ service,
775+ APPLICATION_ID,
776+ NULL,
777+ NULL));
778+
779+ set_paste (service);
780+ get_paste (service);
781+
782+ g_assert_true (
783+ content_hub_service_call_quit_sync (
784+ service,
785+ NULL,
786+ NULL));
787+
788+ g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (handler));
789+ g_object_unref (handler);
790+ g_object_unref (service);
791+
792+ return 0;
793+}
794+
795+/* modified from app_hub_communication_paste.cpp */
796+
797+TEST(GLib, glib_test)
798+{
799+ using namespace ::testing;
800+
801+ test::CrossProcessSync sync;
802+
803+ auto parent = [&sync]()
804+ {
805+ int argc = 0;
806+ QCoreApplication app{argc, nullptr};
807+
808+ QDBusConnection connection = QDBusConnection::sessionBus();
809+
810+ auto mock = new ::testing::NiceMock<MockedPeerRegistry>{};
811+
812+ QSharedPointer<cucd::PeerRegistry> registry{mock};
813+ auto app_manager = QSharedPointer<cua::ApplicationManager>(new MockedAppManager());
814+ cucd::Service implementation(connection, registry, app_manager, &app);
815+ new ServiceAdaptor(std::addressof(implementation));
816+
817+ ASSERT_TRUE(connection.registerService(service_name));
818+ ASSERT_TRUE(connection.registerObject("/", std::addressof(implementation)));
819+
820+ sync.signal_ready();
821+
822+ app.exec();
823+
824+ connection.unregisterObject("/");
825+ connection.unregisterService(service_name);
826+ };
827+
828+ auto child = [&sync]()
829+ {
830+ int argc = 0;
831+ QCoreApplication app(argc, nullptr);
832+
833+ sync.wait_for_signal_ready();
834+
835+ test::TestHarness harness;
836+ harness.add_test_case([]()
837+ {
838+ char arg0[] = "glib_test";
839+ char *argv[] = { arg0 };
840+
841+ EXPECT_EQ(0, glib_test(1, argv));
842+ });
843+ EXPECT_EQ(0, QTest::qExec(std::addressof(harness)));
844+ };
845+
846+ EXPECT_EQ(EXIT_SUCCESS, test::fork_and_run(child, parent));
847+}
848
849=== modified file 'tests/qml-tests/CMakeLists.txt'
850--- tests/qml-tests/CMakeLists.txt 2013-09-13 16:00:41 +0000
851+++ tests/qml-tests/CMakeLists.txt 2016-11-21 21:14:55 +0000
852@@ -13,9 +13,10 @@
853 # along with this program. If not, see <http://www.gnu.org/licenses/>.
854
855 set(TEST tst_QmlTests)
856+set(XVFB_CMD xvfb-run -a -s "-screen 0 640x480x24")
857 add_executable(${TEST} tst_QmlTests.cpp)
858 qt5_use_modules(${TEST} Core Qml Quick Test QuickTest)
859-add_test(${TEST} ${CMAKE_CURRENT_BINARY_DIR}/${TEST})
860+add_test(NAME ${TEST} COMMAND ${XVFB_CMD} ${CMAKE_CURRENT_BINARY_DIR}/${TEST})
861 set_tests_properties(${TEST} PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=minimal;QML2_IMPORT_PATH=${CMAKE_BINARY_DIR}/import;APP_ID=com.some.app.for.testing")
862
863 # copy qml files under test to build dir

Subscribers

People subscribed via source and target branches